:root {
  --bg: #0f1113;
  --panel: #171a1d;
  --line: #2a2f34;
  --text: #d9dde1;
  --muted: #8a939c;
  --accent: #4fa3d9;
  --osd: #f4f4f0;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 Inter, system-ui, sans-serif;
}

#app {
  display: grid;
  grid-template-columns: 1fr 360px;
  height: 100vh;
}

#views {
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: minmax(0, 1fr);
  height: 100vh;
  min-width: 0;
}
#views.split { grid-template-columns: 1fr 1fr; }
#scene { position: relative; display: none; height: 100%; min-width: 0; border-left: 1px solid var(--line); }
#views.split #scene, #views.pip #scene { display: block; }

/* Bild-in-Bild: beide Ansichten in derselben Zelle, die kleine schwebt unten rechts */
#views.pip > section { grid-area: 1 / 1; }
#views.pip #scene, #views.pip.swap #view {
  z-index: 5;
  justify-self: end;
  align-self: end;
  width: 36%;
  height: 38%;
  margin: 16px;
  border: 2px solid #3a434b;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.55);
}
#views.pip.swap #scene {
  z-index: 0;
  justify-self: stretch;
  align-self: stretch;
  width: auto;
  height: 100%;
  margin: 0;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}
#views.pip.swap #osd { font-size: 10px; }
/* OSD-Angaben unten rechts und Befundbanner nicht vom Inset verdecken lassen */
#views.pip:not(.swap) #osd .br { bottom: calc(38% + 40px); }
#views.pip:not(.swap) #osd-befund { left: 3%; transform: none; bottom: 16%; }
#btn-swap { display: none; }
.pip-mode #btn-swap { display: inline-block; }
#scene-view { position: absolute; inset: 0; }
#scene-status {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  pointer-events: none;
}

.toggles { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 13px; }
.toggles input { accent-color: var(--accent); }
.toggles select { width: auto; flex: 1; }
#btn-sync { flex-basis: 100%; }

#view {
  position: relative;
  min-width: 0;
  overflow: hidden;
  background: #000;
  cursor: grab;
  touch-action: none;
}
#view:active { cursor: grabbing; }
#view > canvas { display: block; width: 100%; height: 100%; }

#loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: 'Share Tech Mono', monospace;
  color: var(--muted);
}

/* On-Screen-Display wie bei einer Inspektionskamera */
#osd {
  position: absolute;
  inset: 0;
  pointer-events: none;
  font-family: 'Share Tech Mono', monospace;
  color: var(--osd);
  font-size: clamp(12px, 1.35vw, 18px);
  text-shadow: 1px 1px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000;
  letter-spacing: 0.04em;
}
#osd > div { position: absolute; }
#osd .tl { top: 3%; left: 3%; }
#osd .tr { top: 3%; right: 3%; text-align: right; }
#osd .bl { bottom: 4%; left: 3%; }
#osd .br { bottom: 4%; right: 3%; text-align: right; }
#osd-station { font-size: 1.7em; }
#osd-befund {
  left: 50%;
  bottom: 13%;
  transform: translateX(-50%);
  padding: 0.25em 0.8em;
  background: rgba(0, 0, 0, 0.45);
  border-left: 4px solid currentColor;
  white-space: nowrap;
  display: none;
}

#panel {
  overflow-y: auto;
  background: var(--panel);
  border-left: 1px solid var(--line);
  padding: 16px 18px 24px;
}
#panel header { margin-bottom: 14px; }
#panel h1 { font-size: 17px; font-weight: 600; margin: 0; }
#panel h2 {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 20px 0 8px;
}
.src { color: var(--muted); font-size: 12px; }

.field { display: grid; gap: 4px; }
.field span { font-size: 12px; color: var(--muted); }
select, button {
  font: inherit;
  color: var(--text);
  background: #22262a;
  border: 1px solid var(--line);
  border-radius: 6px;
}
select { padding: 7px 8px; width: 100%; }
button { padding: 6px 10px; cursor: pointer; }
button:hover, select:hover { border-color: #3c444b; }
button.active { border-color: var(--accent); color: #fff; }

#pipe-info {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 3px 12px;
  margin: 12px 0;
  font-size: 13px;
}
#pipe-info dt { color: var(--muted); }
#pipe-info dd { margin: 0; }

.drive { display: flex; gap: 6px; align-items: center; }
.drive #speed { margin-left: auto; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }

#befunde { list-style: none; margin: 0; padding: 0; }
#befunde li {
  display: grid;
  grid-template-columns: 58px 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 7px 8px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}
#befunde li:hover { background: #1f2327; }
#befunde li.current { background: #23303a; }
#befunde .st { font-variant-numeric: tabular-nums; color: var(--muted); }
#befunde .code { font-weight: 600; margin-right: 4px; }
#befunde .meta { display: block; color: var(--muted); font-size: 12px; }
#befunde .zk {
  min-width: 28px;
  text-align: center;
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 12px;
  font-weight: 600;
  color: #111;
}
#befunde .empty { color: var(--muted); cursor: default; }

#map {
  width: 100%;
  background: #0c0e10;
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: crosshair;
}

.help { margin-top: 18px; color: var(--muted); font-size: 12px; }
.help summary { cursor: pointer; }
.help td { padding: 2px 10px 2px 0; }
.help td:first-child { color: var(--text); white-space: nowrap; }

/* ---- Verstecktes Spiel (Konami-Code) ---- */
#doom-splash {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 16px;
  background: #fff;
  color: #25292c;
  font-family: 'Press Start 2P', monospace;
  text-align: center;
  cursor: pointer;
}
#doom-splash.show { display: flex; }
#doom-splash img { max-height: 72vh; max-width: 92vw; object-fit: contain; }
#doom-splash .msg { margin: 8px 0 0; font-size: clamp(14px, 2.2vw, 24px); color: #e45a32; animation: doom-blink 1.1s steps(2) infinite; }
#doom-splash .sub { margin: 0; font-size: 10px; line-height: 1.8; color: #5b6166; }
@keyframes doom-blink { 50% { opacity: 0.35; } }

#doom-hud { display: none; position: absolute; inset: 0; pointer-events: none; font-family: 'Press Start 2P', monospace; }
body.doom #doom-hud { display: block; }
body.doom #osd { display: none; }
body.doom #app { grid-template-columns: 1fr; }
body.doom #panel { display: none; }
body.doom #view { cursor: crosshair; }
/* Im Spiel ersetzt der Bewegungsmelder die Oberwelt: Kamerabild immer vollflächig, Szene nur versteckt */
body.doom #views { grid-template-columns: 1fr; }
body.doom #views #scene { display: none; }
body.doom #views.pip.swap #view {
  z-index: 0; justify-self: stretch; align-self: stretch; width: auto; height: 100%;
  margin: 0; border: 0; border-radius: 0; box-shadow: none;
}
#doom-hud .tracker {
  position: absolute; right: 16px; bottom: 68px; width: min(36%, 470px); aspect-ratio: 470 / 290;
  border: 2px solid #2a3a35; border-radius: 8px; background: #020b09; box-shadow: 0 8px 28px rgba(0, 0, 0, 0.55);
}
#doom-hud .hurt { position: absolute; inset: 0; background: radial-gradient(ellipse at center, transparent 35%, #a00 100%); opacity: 0; }
#doom-hud .crosshair {
  position: absolute; left: 50%; top: 50%; width: 6px; height: 6px; margin: -3px 0 0 -3px;
  border-radius: 50%; background: rgba(255, 220, 160, 0.8); box-shadow: 0 0 0 1px #000;
}
#doom-hud .bar {
  position: absolute; left: 0; right: 0; bottom: 0; height: 52px;
  display: flex; align-items: center; justify-content: space-around;
  background: #2f2a24; border-top: 4px solid #e45a32;
}
#doom-hud .bar > div { display: flex; flex-direction: column; align-items: center; gap: 6px; }
#doom-hud .lbl { font-size: 8px; color: #b3a68f; }
#doom-hud .bar span:not(.lbl) { font-size: clamp(12px, 1.6vw, 18px); color: #e45a32; text-shadow: 2px 2px 0 #000; }
#doom-hud .slots { position: absolute; left: 16px; bottom: 68px; font-size: 9px; line-height: 2.1; text-align: left; color: #b3a68f; text-shadow: 1px 1px 0 #000; }
#doom-hud .slots .on { color: #fff; }
#doom-hud .slots .on::before { content: '▶ '; color: #e45a32; }
/* Zielerfassungsrahmen der Smartgun (Eckwinkel) */
#doom-hud .lock { display: none; position: absolute; transform: translate(-50%, -50%); }
#doom-hud .lock.on { display: block; }
#doom-hud .lock::before, #doom-hud .lock::after {
  content: ''; position: absolute; inset: 0; border: 2px solid #ff4a2a;
  clip-path: polygon(0 0, 25% 0, 25% 3px, 3px 3px, 3px 30%, 0 30%, 0 0, 100% 0, 100% 30%, calc(100% - 3px) 30%, calc(100% - 3px) 3px, 75% 3px, 75% 0);
}
#doom-hud .lock::after { transform: rotate(180deg); }
#doom-hud .lock span { position: absolute; bottom: calc(100% + 4px); left: 0; font-size: 8px; color: #ff4a2a; white-space: nowrap; text-shadow: 1px 1px 0 #000; }
#doom-hud .pause {
  display: none; position: absolute; inset: 0; place-content: center; text-align: center;
  background: rgba(0, 0, 0, 0.6); color: #fff; font-size: 20px; line-height: 2;
}
#doom-hud .pause small { font-size: 9px; color: #b3a68f; }
#doom-hud.paused .pause { display: grid; }

@media (max-width: 900px) {
  #app { grid-template-columns: 1fr; grid-template-rows: auto auto; height: auto; }
  #views, #views.split { grid-template-columns: 1fr; grid-template-rows: none; grid-auto-rows: 50vh; height: auto; }
  #views.pip { height: 60vh; grid-template-rows: minmax(0, 1fr); }
  #scene { border-left: 0; border-top: 1px solid var(--line); }
  #panel { border-left: 0; border-top: 1px solid var(--line); }
}
