/* K.I.T.T. Test-Client – Dashboard im Stil von 1982 */
:root {
  --lit: #ff2a1a;
  --off: #2a0503;
  --amber: #ffb000;
  --fg: #e8e2dc;
  --muted: #8a7f78;
  --line: #2a1d1b;
  --panel: #0b0807;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: #000;
  color: var(--fg);
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow-x: hidden;
}

/* ---------- Kopfzeile ---------- */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
}
.brand {
  color: var(--lit);
  font-weight: 700;
  letter-spacing: .35em;
  text-shadow: 0 0 10px rgba(255, 42, 26, .45);
}
.brand span {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 400;
  letter-spacing: .22em;
  text-shadow: none;
}
.icon-btn {
  padding: 8px;
  line-height: 0;
  color: var(--muted);
}
.icon-btn:hover { color: var(--fg); }

/* ---------- Konsole mit Voice Modulator ---------- */
.console {
  flex: 1 0 auto;  /* nie unter die Inhaltshöhe schrumpfen (sonst überlappen Status und Knopf) */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 4px 16px 12px;
}
.voicebox {
  display: flex;
  align-items: center;
  gap: clamp(8px, 3vw, 24px);
  padding: clamp(10px, 3vw, 22px);
  border: 1px solid #1d1311;
  border-radius: 14px;
  background: linear-gradient(#090606, #000);
  box-shadow: inset 0 0 40px #000, 0 0 0 4px #050303, 0 0 0 5px #1a100e;
}
.screen {
  width: clamp(140px, 46vw, 300px);
  height: clamp(150px, 32vh, 400px);
  background: #000;
  border-radius: 6px;
}
.screen canvas { display: block; width: 100%; height: 100%; }

/* Anzeigelampen */
.lamps { display: flex; flex-direction: column; gap: 10px; }
.lamps span {
  min-width: 44px;
  padding: 4px 7px;
  border: 1px solid #2e0b07;
  border-radius: 3px;
  color: #4d1610;
  font-size: 11px;
  letter-spacing: .12em;
  text-align: center;
  white-space: nowrap;
  transition: background .15s, color .15s, box-shadow .15s;
}
.lamps span.on {
  border-color: var(--lit);
  background: #a3170c;
  color: #fff1ee;
  box-shadow: 0 0 12px rgba(255, 42, 26, .6);
}
.lamps-bottom { flex-direction: row; flex-wrap: wrap; justify-content: center; gap: 8px; }
.lamps-bottom span { border-color: #3a2800; color: #4d3600; }
.lamps-bottom span.on {
  border-color: var(--amber);
  background: var(--amber);
  color: #1a1000;
  box-shadow: 0 0 12px rgba(255, 176, 0, .5);
}

.status {
  color: var(--muted);
  font-size: 13px;
  letter-spacing: .28em;
  text-transform: uppercase;
}
.status[data-state="off"] { color: #6b2a22; }
.status[data-state="rec"], .status[data-state="speak"] { color: var(--lit); }
.status[data-state="busy"] { color: var(--amber); }

/* ---------- Bedienelemente ---------- */
.controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: 0 16px 10px;
}
.row { display: flex; gap: 10px; }
.row > * { flex: 1; min-width: 0; }
.row.end { justify-content: flex-end; }
.row.end > * { flex: 0 0 auto; }
.text-row input { flex: 3; }

button, input, select {
  font: inherit;
  color: var(--fg);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}
button { padding: 10px 14px; cursor: pointer; }
button:hover { border-color: #5c1c13; }
button:disabled { opacity: .5; cursor: default; }
input, select { padding: 10px 12px; }
input[type="file"] { padding: 7px 8px; font-size: 13px; }
:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }

.talk {
  height: 72px;
  border: 2px solid #5a0f08;
  border-radius: 12px;
  background: radial-gradient(ellipse at center, #3a0905 0%, #160302 75%);
  color: #ffd9d4;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: .35em;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
.talk.active {
  border-color: var(--lit);
  background: radial-gradient(ellipse at center, #e0281a 0%, #8c140b 80%);
  color: #fff;
  box-shadow: 0 0 26px rgba(255, 42, 26, .65);
}

/* ---------- Gesprächsverlauf ---------- */
.transcript {
  width: 100%;
  max-width: 560px;
  margin: 0 auto 10px;
  padding: 0 16px;
}
.transcript summary {
  padding: 6px 0;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: .2em;
  text-transform: uppercase;
  cursor: pointer;
}
#transcript {
  max-height: 26vh;
  overflow-y: auto;
  padding-top: 6px;
  border-top: 1px solid var(--line);
  font-size: 14px;
}
#transcript:empty::before { content: "Noch keine Nachrichten."; color: var(--muted); }
.line { margin: 4px 0; overflow-wrap: anywhere; }
.line b { margin-right: 6px; color: var(--muted); font-weight: 600; }
.line.kitt b { color: var(--lit); }

/* ---------- Einstellungen ---------- */
dialog {
  width: min(92vw, 460px);
  padding: 0;
  border: 1px solid #3a1510;
  border-radius: 12px;
  background: #0a0606;
  color: var(--fg);
}
dialog::backdrop { background: rgba(0, 0, 0, .7); }
.dlg { display: flex; flex-direction: column; gap: 10px; padding: 18px; }
.dlg h2 { margin: 0 0 4px; color: var(--lit); font-size: 16px; letter-spacing: .2em; text-transform: uppercase; }
.dlg h3 { margin: 10px 0 0; color: var(--amber); font-size: 13px; letter-spacing: .15em; text-transform: uppercase; }
.dlg label { color: var(--muted); font-size: 13px; }
.hint { margin: 0; color: var(--muted); font-size: 12px; }
dialog { max-height: 92dvh; overflow-y: auto; }
.slider { display: grid; grid-template-columns: 11em 1fr 3em; align-items: center; gap: 10px; }
.slider input { width: 100%; accent-color: var(--lit); }
.slider output { color: var(--fg); font-size: 13px; text-align: right; font-variant-numeric: tabular-nums; }
#prompt-text, #pron-text {
  width: 100%;
  min-height: 12em;
  padding: 8px 10px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #000;
  color: var(--fg);
  font: 13px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

/* ---------- Meldungen ---------- */
#toasts {
  position: fixed;
  top: calc(12px + env(safe-area-inset-top));
  left: 50%;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(92vw, 420px);
  transform: translateX(-50%);
  pointer-events: none;
}
.toast {
  padding: 10px 14px;
  border: 1px solid #6b150c;
  border-radius: 8px;
  background: #1a0907;
  color: #ffd8d2;
  font-size: 14px;
  box-shadow: 0 4px 18px rgba(0, 0, 0, .6);
  transition: opacity .5s, transform .5s;
}
.toast.info { border-color: #4d3a10; background: #140f05; color: #ffe6b0; }
.toast.out { opacity: 0; transform: translateY(-6px); }

/* ---------- Kleine Bildschirme ---------- */
@media (max-width: 420px) {
  .lamps span { min-width: 34px; padding: 3px 4px; font-size: 9px; }
  .lamps-bottom { gap: 6px; }
  .screen { width: 50vw; }
  .talk { height: 64px; font-size: 18px; }
}
@media (max-height: 640px) {
  .screen { height: clamp(150px, 32vh, 400px); }
  .console { gap: 8px; }
}

/* ---------- Aktivitätsanzeige der Modelle (Lauflicht wie K.I.T.T.s Scanner) ---------- */
.activity {
  width: 100%;
  max-width: 560px;
  margin: auto auto 0;
  padding: 8px 16px 12px;
  display: grid;
  gap: 5px;
}
.lane {
  display: grid;
  grid-template-columns: 6.5em 1fr 10em;
  align-items: center;
  gap: 10px;
  font-size: 11px;
  letter-spacing: .08em;
  color: var(--muted);
  opacity: .55;
  transition: opacity .2s;
}
.lane.on { opacity: 1; color: var(--fg); }
.lane-name { text-transform: uppercase; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lane-info { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lane-track {
  position: relative;
  height: 6px;
  border-radius: 3px;
  background: var(--off);
  overflow: hidden;
}
.lane-track::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 22%;
  height: 100%;
  border-radius: 3px;
  background: linear-gradient(90deg, transparent, var(--lit) 55%, #ffb3a6 70%, var(--lit) 80%, transparent);
  box-shadow: 0 0 8px var(--lit);
  opacity: 0;
}
.lane.on .lane-track::after {
  opacity: 1;
  animation: kitt-scan 1.1s ease-in-out infinite alternate;
}
@keyframes kitt-scan { from { left: 0; } to { left: 78%; } }
@media (prefers-reduced-motion: reduce) {
  .lane.on .lane-track::after { animation: none; left: 0; width: 100%; opacity: .7; }
}

/* Speicherstatus neben den Überschriften im Einstellungsdialog */
.dlg h3 { display: flex; align-items: center; gap: 10px; }
.save-state {
  font-size: 11px;
  letter-spacing: .05em;
  text-transform: none;
  font-weight: 600;
  opacity: 0;
  transition: opacity .4s;
}
.save-state.show { opacity: 1; transition: none; }
.save-state.busy { color: var(--muted); }
.save-state.ok { color: #3ddc84; }
.save-state.err { color: var(--lit); }
#voice-select { width: 100%; }
.file-btn {
  position: relative;
  display: block;
  padding: 10px 14px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--fg);
  text-align: center;
  cursor: pointer;
}
.file-btn:hover, .file-btn:focus-within { border-color: var(--lit); }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

/* PURSUIT lässt sich per Klick dauerhaft einschalten */
#lamp-pursuit { cursor: pointer; user-select: none; }
#lamp-pursuit:hover { border-color: var(--amber); }
