/*
VOICE    calm, instrument-cluster precise
IDEA     a truck's centre display: camera feed first, voice controls beside it
PICTURE  the live camera canvas plus a top-down truck you can tap
COLOUR   near-black cockpit, signal green for "heard you", amber for the LLM
TYPE     Barlow / Barlow Semi Condensed, as on automotive displays
*/
:root {
  color-scheme: dark;
  --bg: #0b0f13; --panel: #121920; --panel2: #18212a; --line: #253140;
  --ink: #e6edf3; --dim: #8b9aa8; --go: #5be0a4; --amber: #f2b84b; --blue: #6cc4ff; --red: #ff6b6b;
  --r: 14px;
}
* { box-sizing: border-box; min-width: 0; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font: 16px/1.5 Barlow, system-ui, sans-serif; overflow-x: clip; min-height: 100dvh; }
button, input, select { font: inherit; color: inherit; }
q { color: var(--ink); }

.top { display: flex; align-items: center; gap: 12px; padding: 12px max(4vw, 14px); border-bottom: 1px solid var(--line); position: sticky; top: 0; background: rgba(11,15,19,.92); backdrop-filter: blur(8px); z-index: 5; }
.brand { display: flex; align-items: center; gap: 10px; font: 600 18px/1 "Barlow Semi Condensed", Barlow, sans-serif; letter-spacing: .01em; margin-right: auto; }
.brand svg { width: 26px; height: 26px; color: var(--go); }
.status { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--dim); padding: 6px 12px; border: 1px solid var(--line); border-radius: 99px; white-space: nowrap; }
.status i { width: 8px; height: 8px; border-radius: 50%; background: var(--dim); }
.status[data-kind=ready] i { background: var(--go); }
.status[data-kind=listening] i { background: var(--go); box-shadow: 0 0 0 4px rgba(91,224,164,.2); }
.status[data-kind=hearing] i { background: var(--blue); box-shadow: 0 0 0 5px rgba(108,196,255,.25); }
.status[data-kind=thinking] i { background: var(--amber); }
.status[data-kind=error] i { background: var(--red); }
.status[data-kind=loading] i { animation: pulse 1s infinite alternate; }
.icon-btn { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); cursor: pointer; }
.icon-btn svg { width: 22px; height: 22px; }

.layout { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 20px; padding: 20px max(4vw, 14px) 40px; max-width: 1320px; margin: 0 auto; }
@media (max-width: 900px) { .layout { grid-template-columns: minmax(0, 1fr); gap: 16px; } }

.screen { position: relative; aspect-ratio: 16 / 9; border-radius: var(--r); overflow: hidden; background: #000; border: 1px solid var(--line); }
.screen canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.cam-label { position: absolute; left: 14px; top: 12px; display: flex; flex-direction: column; padding: 6px 12px; border-radius: 10px; background: rgba(8,12,16,.6); backdrop-filter: blur(4px); }
.cam-label span { font: 600 clamp(17px, 2.4vw, 22px)/1.15 "Barlow Semi Condensed", sans-serif; }
.cam-label small { font-size: 13px; color: var(--dim); }
.toast { position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); max-width: calc(100% - 140px); padding: 8px 14px; border-radius: 12px; background: rgba(8,12,16,.78); font-size: 15px; text-align: center; border: 1px solid rgba(91,224,164,.35); }
.toast b { color: var(--go); font-weight: 600; }
.listen-ring { position: absolute; inset: 0; border: 3px solid var(--blue); border-radius: var(--r); pointer-events: none; animation: pulse .9s infinite alternate; }

.selector { display: grid; grid-template-columns: minmax(0, 150px) minmax(0, 1fr); gap: 16px; align-items: center; margin-top: 14px; }
@media (max-width: 600px) { .selector { grid-template-columns: minmax(0, 120px) minmax(0, 1fr); gap: 12px; } }
#truck { width: 100%; height: auto; max-height: 240px; }
.truck-body { fill: #1a2430; stroke: #34465a; stroke-width: 1.5; }
.truck-cab { fill: #223041; } .truck-bed { fill: #141c25; stroke: #34465a; } .truck-tire { fill: #0a0d10; stroke: #3a4a5c; }
.hot { cursor: pointer; }
.hot circle { fill: #0b0f13; stroke: var(--dim); stroke-width: 2; transition: fill .2s, stroke .2s; }
.hot.on circle { fill: var(--go); stroke: var(--go); }
.hot:hover circle, .hot:focus-visible circle { stroke: var(--ink); }
.hot text { fill: var(--dim); font: 600 8px Barlow, sans-serif; text-anchor: middle; pointer-events: none; }
.hot.on text { fill: var(--ink); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { min-height: 40px; padding: 6px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); cursor: pointer; font-size: 14px; }
.chip[aria-pressed=true] { border-color: var(--go); color: var(--go); }

.panel { display: flex; flex-direction: column; gap: 14px; }
.talk { display: grid; gap: 10px; }
.mic { display: flex; align-items: center; justify-content: center; gap: 12px; min-height: 64px; border-radius: var(--r); border: 1px solid var(--line); background: var(--panel2); font: 600 19px "Barlow Semi Condensed", sans-serif; cursor: pointer; }
.mic svg { width: 26px; height: 26px; color: var(--dim); }
.mic[aria-pressed=true] { background: rgba(91,224,164,.12); border-color: var(--go); }
.mic[aria-pressed=true] svg { color: var(--go); }
.mic:disabled { opacity: .5; cursor: progress; }
.type-form { display: flex; gap: 8px; }
.type-form input { flex: 1; min-height: 48px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); font-size: 16px; }
.type-form button { min-width: 64px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel2); cursor: pointer; font-weight: 600; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

.levels { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.levels label { position: relative; }
.levels input { position: absolute; opacity: 0; }
.levels span { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 58px; padding: 6px 4px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); font: 600 17px "Barlow Semi Condensed", sans-serif; cursor: pointer; text-align: center; }
.levels small { font: 500 12px/1.2 Barlow, sans-serif; color: var(--dim); }
.levels input:checked + span { border-color: var(--go); background: rgba(91,224,164,.08); }
.levels input:focus-visible + span { outline: 2px solid var(--blue); }

.result { border-radius: var(--r); border: 1px solid var(--line); background: var(--panel); padding: 16px; }
.result .empty { margin: 0; color: var(--dim); }
.heard { font: 500 20px/1.3 "Barlow Semi Condensed", sans-serif; margin: 0 0 10px; }
.heard.none { color: var(--dim); }
.steps { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 12px; padding: 0; list-style: none; }
.steps li { padding: 4px 10px; border-radius: 8px; background: rgba(91,224,164,.12); color: var(--go); font-size: 14px; font-weight: 600; }
.steps li.nil { background: rgba(139,154,168,.12); color: var(--dim); }
.badge { display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: 12px; font-weight: 700; letter-spacing: .02em; margin-right: 6px; vertical-align: 2px; }
.badge.L0 { background: #2b3a4a; color: var(--blue); } .badge.L1 { background: #193a2d; color: var(--go); }
.badge.L1m { background: #23324a; color: #a9c7ff; } .badge.L2 { background: #3e3016; color: var(--amber); }
.why { color: var(--dim); font-size: 14px; }
.timing { display: grid; gap: 6px; margin-top: 12px; }
.trow { display: grid; grid-template-columns: 9.5em minmax(0, 1fr) 4.5em; gap: 8px; align-items: center; font-size: 14px; }
.trow .bar { height: 8px; border-radius: 4px; background: #0b1016; overflow: hidden; }
.trow .bar i { display: block; height: 100%; border-radius: 4px; background: var(--blue); }
.trow.total { font-weight: 600; } .trow.total .bar i { background: var(--go); }
.trow .ms { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

.tries { border-radius: var(--r); border: 1px solid var(--line); background: var(--panel); padding: 4px 16px; }
.tries summary { min-height: 44px; display: flex; align-items: center; cursor: pointer; font-weight: 600; }
.tries ul { margin: 0 0 12px; padding: 0; list-style: none; display: flex; flex-wrap: wrap; gap: 6px; }
.tries button { min-height: 36px; padding: 4px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel2); cursor: pointer; font-size: 14px; text-align: left; }

.history h2 { font: 600 15px "Barlow Semi Condensed", sans-serif; color: var(--dim); margin: 6px 0 8px; }
.history ol { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.history li { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 10px; padding: 10px 12px; border-radius: 10px; background: var(--panel); font-size: 14px; }
.history .h-text { overflow-wrap: anywhere; }
.history .h-ms { color: var(--dim); font-variant-numeric: tabular-nums; white-space: nowrap; }
.history .h-steps { grid-column: 1 / -1; color: var(--dim); }

dialog { border: 1px solid var(--line); border-radius: 18px; background: var(--panel); color: var(--ink); padding: 0; width: min(520px, calc(100vw - 24px)); }
dialog::backdrop { background: rgba(0,0,0,.6); }
.settings { display: grid; gap: 14px; padding: 20px; }
.settings h2 { margin: 0; font: 600 22px "Barlow Semi Condensed", sans-serif; }
.settings label { display: grid; gap: 6px; font-size: 15px; }
.settings label.row { display: flex; align-items: center; gap: 10px; min-height: 40px; }
.settings select, .settings input[type=url], .settings input[type=text] { min-height: 44px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); font-size: 16px; }
.settings fieldset { border: 1px solid var(--line); border-radius: 12px; display: grid; gap: 8px; padding: 10px 14px 14px; }
.settings legend { padding: 0 6px; color: var(--dim); }
.settings output { color: var(--go); font-variant-numeric: tabular-nums; }
.fine { margin: 0; color: var(--dim); font-size: 13px; }
.actions { display: flex; justify-content: flex-end; }
.actions button { min-height: 44px; padding: 0 22px; border-radius: 10px; border: 0; background: var(--go); color: #06281a; font-weight: 700; cursor: pointer; }

@keyframes pulse { from { opacity: .35; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* Phones/tablets: camera, then the mic and result, then the camera picker. */
@media (max-width: 900px) {
  .layout { display: flex; flex-direction: column; }
  .display, .panel { display: contents; }
  .screen { order: 1; } .talk { order: 2; } .levels { order: 3; } .result { order: 4; }
  .selector { order: 5; margin-top: 0; } .tries { order: 6; } .history { order: 7; }
}
@media (max-width: 600px) {
  .chips { display: none; }
  .selector { grid-template-columns: minmax(0, 1fr); justify-items: center; }
  #truck { max-height: 200px; width: auto; }
}
