:root {
  --bg: #05080c;
  --panel: rgba(8, 16, 24, 0.78);
  --cyan: #39e7ff;
  --amber: #ffb000;
  --red: #ff4d4d;
  --ink: #d7f6ff;
  --muted: #7aa0ad;
  --line: rgba(57, 231, 255, 0.28);
  --font: "Segoe UI", "SF Pro Text", system-ui, sans-serif;
  --mono: "SF Mono", "Cascadia Mono", "IBM Plex Mono", ui-monospace, monospace;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
}
* { box-sizing: border-box; }
html {
  height: 100%;
  height: 100dvh;
  background: var(--bg);
}
body {
  margin: 0;
  min-height: 100%;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  overflow-x: hidden;
  overflow-y: auto;
  background-image:
    radial-gradient(1200px 600px at 50% -10%, rgba(57,231,255,.12), transparent 55%),
    repeating-linear-gradient(0deg, transparent, transparent 3px, rgba(0,0,0,.18) 4px);
}

.hidden { display: none !important; }

#boot, #login {
  position: fixed; inset: 0;
  padding: max(1rem, var(--safe-t)) max(1rem, var(--safe-r)) max(1rem, var(--safe-b)) max(1rem, var(--safe-l));
  display: grid; place-items: center; z-index: 40;
  background: #030507;
  overflow-y: auto;
}
.boot-ring {
  width: min(42vw, 280px); height: min(42vw, 280px); border-radius: 50%;
  border: 2px solid var(--cyan);
  box-shadow: 0 0 40px #39e7ff88, inset 0 0 40px #39e7ff33;
  animation: spin 6s linear infinite, pulse 1.6s ease-in-out infinite;
  position: absolute;
}
.boot-ring::after {
  content: ""; position: absolute; inset: 18%; border-radius: 50%;
  border: 1px dashed rgba(57,231,255,.5);
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { box-shadow: 0 0 70px #39e7ffcc, inset 0 0 50px #39e7ff55; } }
.boot-copy { position: relative; text-align: center; z-index: 1; max-width: 100%; }
.boot-mark, .brand strong {
  font-family: var(--mono); letter-spacing: .42em; font-weight: 700; font-size: 2.4rem;
  color: var(--cyan); text-shadow: 0 0 18px #39e7ff;
}
.boot-sub { font-family: var(--mono); font-size: .72rem; color: var(--muted); letter-spacing: .28em; margin: .6rem 0 1.4rem; }
#boot-log { list-style: none; padding: 0; margin: 0 auto; width: min(90vw, 420px); text-align: left; font-family: var(--mono); font-size: .78rem; color: var(--cyan); min-height: 7rem; }
#boot-log li { opacity: 0; animation: fade .3s forwards; }
@keyframes fade { to { opacity: 1; } }

.login-card {
  width: min(92vw, 380px); padding: 2rem; border: 1px solid var(--line);
  background: var(--panel); backdrop-filter: blur(12px);
  box-shadow: 0 0 40px #39e7ff22;
}
.login-card p { color: var(--muted); font-family: var(--mono); letter-spacing: .2em; text-transform: uppercase; font-size: .7rem; }
.login-card input, .modal-card input, textarea {
  width: 100%; background: #061018; border: 1px solid var(--line); color: var(--ink);
  padding: .7rem .8rem; font-family: var(--mono); font-size: 16px;
}
.login-card button, #btn-fahrt, #send, .modal-card button, #mic {
  background: transparent; color: var(--cyan); border: 1px solid var(--cyan);
  font-family: var(--mono); letter-spacing: .16em; padding: .75rem 1rem; cursor: pointer;
  min-height: 44px;
}
.login-card button:hover, #send:hover, #btn-fahrt:hover { background: rgba(57,231,255,.12); }
#login-err { color: var(--red); min-height: 1.2rem; font-size: .85rem; margin-top: .6rem; }

#hud {
  min-height: 100%;
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding-top: var(--safe-t);
  padding-left: var(--safe-l);
  padding-right: var(--safe-r);
  padding-bottom: var(--safe-b);
}
.top {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: .75rem 1rem; align-items: center;
  padding: .55rem 1rem; border-bottom: 1px solid var(--line);
  background: rgba(0,0,0,.35);
}
.brand { display: flex; align-items: center; gap: .6rem; min-width: 0; }
.brand em { font-style: normal; color: var(--muted); font-family: var(--mono); font-size: .7rem; }
.rings {
  width: 28px; height: 28px; border-radius: 50%; flex-shrink: 0;
  box-shadow: inset 0 0 0 2px var(--cyan), 0 0 12px #39e7ff;
  position: relative;
}
.rings::before, .rings::after {
  content: ""; position: absolute; inset: 6px; border-radius: 50%; border: 1px solid var(--amber);
}
#search-form { min-width: 0; }
#search-form input { width: 100%; }
.status-strip {
  display: flex; flex-wrap: wrap; gap: .4rem .55rem; align-items: center;
  font-family: var(--mono); font-size: .72rem; letter-spacing: .08em;
  justify-content: flex-end;
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: #334; display: inline-block; flex-shrink: 0; }
.dot.on { background: #3dff8a; box-shadow: 0 0 8px #3dff8a; }
.dot.warn { background: var(--amber); box-shadow: 0 0 8px var(--amber); }
.dot.off { background: var(--red); }
#voice-toggle {
  background: transparent; border: 1px solid var(--line); color: var(--cyan);
  padding: .15rem .4rem; cursor: pointer; font-size: .9rem; min-height: 36px;
}

.grid {
  display: grid; grid-template-columns: 1.05fr 1.35fr 1.05fr; gap: .7rem;
  padding: .7rem; min-height: 0;
}
.panel {
  border: 1px solid var(--line); background: var(--panel); padding: .8rem;
  display: flex; flex-direction: column; min-height: 0; overflow: hidden;
}
.panel h2 {
  margin: 0 0 .55rem; font-size: .72rem; letter-spacing: .28em; color: var(--amber);
  font-family: var(--mono); font-weight: 600;
}
.stat-row { display: grid; grid-template-columns: repeat(3,1fr); gap: .4rem; margin-bottom: .8rem; }
.stat-row div { border: 1px solid var(--line); padding: .45rem; text-align: center; }
.stat-row small { display: block; color: var(--muted); font-size: .65rem; letter-spacing: .12em; }
.stat-row b { font-size: 1.15rem; color: var(--cyan); font-family: var(--mono); }
.list { overflow: auto; flex: 1; display: flex; flex-direction: column; gap: .4rem; -webkit-overflow-scrolling: touch; }
.item {
  border: 1px solid var(--line); padding: .5rem .55rem; cursor: pointer; font-size: .85rem;
}
.item:hover, .item.active { border-color: var(--cyan); background: rgba(57,231,255,.06); }
.item .meta { color: var(--muted); font-family: var(--mono); font-size: .7rem; }
.badge { float: right; font-family: var(--mono); font-size: .65rem; letter-spacing: .1em; color: var(--amber); }
.badge.ok { color: #3dff8a; }

.center { position: relative; min-height: 0; }
.reactor-wrap { display: grid; place-items: center; padding: .3rem 0 .5rem; }
.reactor {
  width: 88px; height: 88px; border-radius: 50%;
  border: 2px solid var(--cyan);
  box-shadow: 0 0 24px #39e7ff88, inset 0 0 18px #39e7ff55;
  animation: pulse 2.4s ease-in-out infinite;
}
.reactor.busy { animation: spin 1.2s linear infinite, pulse .7s ease-in-out infinite; border-color: var(--amber); }
.reactor-label { font-family: var(--mono); font-size: .62rem; letter-spacing: .3em; color: var(--muted); margin-top: .25rem; }
.chat { flex: 1; overflow: auto; display: flex; flex-direction: column; gap: .55rem; padding: .2rem; -webkit-overflow-scrolling: touch; }
.bubble { max-width: 92%; padding: .55rem .7rem; font-size: .92rem; line-height: 1.4; }
.bubble.user { align-self: flex-end; border: 1px solid var(--amber); color: #ffe7b0; }
.bubble.audi { align-self: flex-start; border: 1px solid var(--line); }
.bubble.tool { align-self: flex-start; border-color: var(--amber); color: var(--amber); font-family: var(--mono); font-size: .75rem; }
.composer { display: grid; grid-template-columns: auto 1fr auto; gap: .4rem; margin-top: .5rem; }
.composer textarea { resize: none; min-height: 44px; }
#mic { min-width: 44px; font-size: 1.1rem; touch-action: manipulation; }
#mic.armed {
  border-color: var(--amber);
  color: var(--amber);
}
#mic.live {
  background: rgba(57,231,255,.2);
  box-shadow: 0 0 16px #39e7ff;
  color: #fff;
}
.reactor.armed {
  border-color: var(--amber);
  box-shadow: 0 0 28px #ffb00088, inset 0 0 18px #ffb00044;
}
.voice-hint {
  margin: .35rem 0 0;
  font-family: var(--mono);
  font-size: .68rem;
  letter-spacing: .06em;
  color: var(--muted);
  min-height: 1.1rem;
}
.bubble { position: relative; }
.bubble .speak-again {
  position: absolute;
  right: .25rem;
  bottom: .25rem;
  min-width: 36px;
  min-height: 36px;
  padding: 0;
  background: transparent;
  color: var(--cyan);
  border: 1px solid var(--line);
  font-size: .85rem;
  cursor: pointer;
}
.bubble.audi { padding-right: 2.4rem; }
.speak-again.needs-tap {
  border-color: var(--amber);
  color: var(--amber);
  box-shadow: 0 0 12px #ffb00088;
  animation: pulse 1s ease-in-out infinite;
}
#arm-gate {
  position: fixed; inset: 0; z-index: 45;
  display: grid; place-items: center;
  align-content: center; gap: 1rem;
  background: rgba(3, 5, 7, 0.94);
  padding: max(1rem, var(--safe-t)) max(1rem, var(--safe-r)) max(1rem, var(--safe-b)) max(1rem, var(--safe-l));
}
#arm-gate.hidden { display: none !important; }
#arm-gate button {
  background: transparent; color: var(--cyan); border: 1px solid var(--cyan);
  font-family: var(--mono); letter-spacing: .2em; padding: 1rem 1.4rem;
  min-height: 52px; font-size: 1rem; cursor: pointer;
}
#arm-gate p {
  color: var(--muted); font-family: var(--mono); font-size: .78rem;
  letter-spacing: .08em; text-align: center; max-width: 22rem;
}

#radar { width: 100%; height: 140px; border: 1px solid var(--line); background: #031016; }
.detail { overflow: auto; flex: 1; font-size: .88rem; line-height: 1.45; -webkit-overflow-scrolling: touch; }
.detail dl { display: grid; grid-template-columns: minmax(5rem, 8rem) 1fr; gap: .25rem 0.6rem; font-family: var(--mono); font-size: .8rem; }
.detail dt { color: var(--muted); }
.muted { color: var(--muted); }

.ticker {
  font-family: var(--mono); font-size: .68rem; letter-spacing: .12em; color: var(--muted);
  border-top: 1px solid var(--line); padding: .35rem 1rem;
  white-space: nowrap; overflow-x: auto; overflow-y: hidden;
}

#modal {
  position: fixed; inset: 0; z-index: 30;
  background: rgba(0,0,0,.65);
  display: grid; place-items: safe center;
  overflow-y: auto;
  padding: max(1rem, var(--safe-t)) max(1rem, var(--safe-r)) max(1rem, var(--safe-b)) max(1rem, var(--safe-l));
  -webkit-overflow-scrolling: touch;
}
.modal-card {
  width: min(92vw, 440px); max-height: min(90dvh, 100%);
  overflow-y: auto;
  background: #071018; border: 1px solid var(--cyan); padding: 1.2rem;
  display: grid; gap: .55rem;
  margin: auto;
}
.modal-card .row { display: flex; gap: .5rem; justify-content: flex-end; flex-wrap: wrap; }
.modal-card label { font-size: .75rem; color: var(--muted); letter-spacing: .08em; text-transform: uppercase; font-family: var(--mono); }

#btn-fahrt { margin-top: .55rem; width: 100%; }

@media (min-width: 1101px) {
  html, body { overflow: hidden; height: 100%; height: 100dvh; }
  #hud { height: 100%; height: 100dvh; overflow: hidden; }
}

@media (max-width: 1100px) {
  .boot-mark, .brand strong { font-size: 1.45rem; letter-spacing: .22em; }
  .boot-sub { letter-spacing: .12em; font-size: .62rem; }
  .top {
    grid-template-columns: 1fr;
    gap: .5rem;
  }
  .status-strip { justify-content: flex-start; }
  #hud {
    height: auto;
    overflow: visible;
  }
  .grid {
    display: flex;
    flex-direction: column;
    overflow: visible;
    min-height: 0;
  }
  .center { order: -1; min-height: 55dvh; overflow: hidden; }
  .left, .right {
    max-height: none;
    min-height: 220px;
  }
  .panel { overflow: hidden; }
  .reactor { width: 64px; height: 64px; }
  .ticker { display: none; }
  .composer { position: sticky; bottom: 0; background: var(--panel); padding-bottom: .2rem; }
}

@media (max-width: 640px) {
  .grid { padding: .45rem; gap: .5rem; }
  .panel { padding: .65rem; }
  .center { min-height: 62dvh; }
  .brand strong { letter-spacing: .16em; }
}
