:root {
  --bg: #000000;
  --panel: #0a0a0a;
  --line: #333333;
  --text: #e4e4e4;
  --mute: #858585;
  --white: #ffffff;
  --mono: Menlo, "DejaVu Sans Mono", Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.45 var(--mono);
  overflow: hidden;
}

#app {
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  height: 100dvh;
}

header {
  display: flex;
  gap: 18px;
  align-items: baseline;
  padding: 8px 14px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  overflow: hidden;
}
/* Der Kopf bleibt über den Dialogen, damit der AI-Knopf immer erreichbar ist. */
header { position: relative; z-index: 20; background: var(--bg); }
.logo { color: var(--white); font-weight: 700; letter-spacing: 0.35em; }
#chapter { color: var(--white); }
#place { color: var(--mute); overflow: hidden; text-overflow: ellipsis; flex: 1; min-width: 0; }
.ai { display: flex; gap: 8px; align-items: baseline; flex-shrink: 0; }
#credits { color: var(--mute); }
#ai { font-weight: 700; letter-spacing: 0.15em; padding: 2px 12px; }
#speed, #lang { padding: 2px 8px; min-width: 38px; }
#ai.on { background: var(--white); border-color: var(--white); color: var(--bg); animation: ai-pulse 1.4s ease-in-out infinite; }
@keyframes ai-pulse { 50% { opacity: 0.6; } }
@media (prefers-reduced-motion: reduce) { #ai.on { animation: none; } }

main {
  display: grid;
  grid-template-columns: 1fr 290px;
  min-height: 0;
}

#screen { position: relative; min-width: 0; min-height: 0; overflow: hidden; }
#cv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
/* Röhrenmonitor: feine Zeilen über dem Bild */
#screen::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(to bottom, transparent 0 2px, rgba(0, 0, 0, 0.16) 2px 3px);
}

#side {
  border-left: 1px solid var(--line);
  background: var(--panel);
  padding: 4px 14px 12px;
  overflow-y: auto;
}
#side section { padding: 10px 0; border-bottom: 1px solid var(--line); }
#side section:last-child { border-bottom: 0; }
h3 {
  margin: 0 0 6px;
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--mute);
}

.stat { display: grid; grid-template-columns: 76px 1fr 46px; gap: 8px; align-items: center; margin: 3px 0; }
.stat .num { text-align: right; color: var(--mute); }
.bar { height: 8px; background: #1e1e1e; }
.bar i { display: block; height: 100%; background: var(--white); }
.bar.stress i { background: #9a9a9a; }
.bar.sus i { background: repeating-linear-gradient(90deg, #fff 0 2px, #000 2px 4px); }
.bar.alarm i { background: var(--white); animation: ai-pulse 0.5s steps(2) infinite; }
.bar.fuel i { background: repeating-linear-gradient(90deg, #fff 0 6px, #000 6px 7px); }
.counts { margin-top: 6px; color: var(--mute); }
.counts b { color: var(--text); font-weight: 400; }

#where span + span::before { content: " › "; color: var(--mute); }
#goal .nav { margin-top: 6px; color: var(--white); font-weight: 700; }
/* Das aktuelle Ziel: weißer Balken links, alle 10 Sekunden ein weiches Aufleuchten; bei neuem Ziel sofort (.new). */
#goal { border-left: 2px solid var(--white); margin-left: -10px; padding: 4px 8px; animation: goal-glow 10s ease-in-out infinite; }
#goal.new { animation: goal-new 1.8s ease-out, goal-glow 10s ease-in-out 1.8s infinite; }
@keyframes goal-glow {
  0%, 82%, 100% { background: transparent; color: inherit; }
  91% { background: rgba(255, 255, 255, 0.16); color: var(--white); }
}
@keyframes goal-new { 0%, 30% { background: rgba(255, 255, 255, 0.34); color: var(--white); } 100% { background: transparent; } }
@media (prefers-reduced-motion: reduce) { #goal, #goal.new { animation: none; } }
#inv { list-style: none; margin: 0; padding: 0; }
#inv li::before { content: "– "; color: var(--mute); }
#inv .none { color: var(--mute); }
.keys div { color: var(--mute); }
.meta { display: flex; justify-content: space-between; align-items: center; color: var(--mute); }

button {
  font: inherit;
  color: var(--text);
  background: transparent;
  border: 1px solid var(--line);
  padding: 4px 10px;
  cursor: pointer;
}
button:hover { border-color: var(--white); color: var(--white); }

#log {
  border-top: 1px solid var(--line);
  padding: 6px 14px;
  height: 104px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}
#log div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#log div:nth-last-child(n+2) { opacity: 0.7; }
#log div:nth-last-child(n+4) { opacity: 0.4; }
#log .bad { color: var(--white); font-weight: 700; }
#log .bad::before { content: "! "; }
#log .warn { color: var(--white); }
#log .good { color: #c4c4c4; }
#log .hl { color: var(--white); text-decoration: underline; text-underline-offset: 3px; }

#touch { display: none; }

#modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.85);
  padding: 16px;
}
#modal[hidden] { display: none; }
.box {
  width: min(620px, 100%);
  max-height: 90dvh;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-top: 2px solid var(--white);
  padding: 20px 24px;
}
.box h2 { margin: 0 0 12px; font-size: 15px; font-weight: 700; letter-spacing: 0.12em; color: var(--white); }
.box p { margin: 0 0 10px; }
.box em { color: var(--mute); font-style: normal; }
.box pre { margin: 0 0 14px; color: var(--white); font: inherit; line-height: 1.15; overflow: hidden; }
.box.card { text-align: center; padding: 44px 28px 32px; border-top-color: var(--white); }
.box.card h2 { font-size: 22px; letter-spacing: 0.3em; margin-bottom: 22px; }
.box.finale {
  width: min(780px, 100%);
  text-align: center;
  padding: 40px 24px 30px;
  border-color: var(--white);
  border-top-width: 2px;
  box-shadow: 0 0 90px rgba(255, 255, 255, 0.22);
}
.box.finale h2 { display: none; }
.box.finale pre {
  display: inline-block;
  text-align: left;
  margin-bottom: 30px;
  color: var(--white);
  font-size: clamp(7px, 2.5vw, 21px);
  line-height: 1.02;
  text-shadow: 0 0 14px rgba(255, 255, 255, 0.6);
  animation: finale-in 1.6s ease-out both;
}
.box.finale p { font-size: 14px; }
@keyframes finale-in { from { opacity: 0; letter-spacing: 0.5em; } }
@media (prefers-reduced-motion: reduce) { .box.finale pre { animation: none; } }
.box .opts { display: flex; flex-direction: column; gap: 8px; margin: 6px 0 4px; }
.box .opts button { text-align: left; padding: 8px 12px; font-size: 15px; }
.box .hint { margin-top: 12px; color: var(--mute); font-size: 12px; }

@media (max-width: 820px) {
  main { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  #side {
    border-left: 0;
    border-top: 1px solid var(--line);
    padding: 0 14px;
    max-height: 30dvh;
  }
  #side section { padding: 6px 0; }
  #side .keys, #side h3 { display: none; }
  #place, #credits { display: none; }
  header { justify-content: space-between; }
  #log { height: 62px; }
  #log div:nth-last-child(n+4) { display: none; }
  #touch { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; padding: 6px 14px calc(6px + env(safe-area-inset-bottom)); }
  #touch button { padding: 10px 0; }
}
