:root {
  --bg: #15181d;
  --panel: #1c2027;
  --face: #101317;
  --line: #2b3039;
  --ink: #ece6d6;      /* warm gauge-lettering white */
  --dim: #8f96a1;
  --faint: #2a2f37;
  --lamp: #f0a43a;     /* sodium lamp */
  --red: #e4463a;
  --cool: #59c1b4;
  --r-lg: 22px;
  --r-sm: 12px;
  --tap: 64px;         /* minimum touch target for a car screen */
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 400 17px/1.45 "Barlow", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  user-select: none;
}
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--lamp); outline-offset: 2px; }

/* ---------- top bar ---------- */
.bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px clamp(16px, 3vw, 32px); }
.brand { display: flex; align-items: center; gap: 10px; font: 700 28px/1 "Barlow Condensed", sans-serif; }
.brand svg { width: 28px; height: 28px; color: var(--lamp); }
.bar-right { display: flex; gap: 12px; align-items: center; }

.chip {
  white-space: nowrap;
  font: 600 17px/1 "Barlow Condensed", sans-serif;
  padding: 12px 14px; border-radius: 999px; border: 1px solid var(--line); color: var(--dim);
  display: inline-flex; align-items: center; gap: 8px;
}
.chip::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--dim); }
.chip[data-state="ok"] { color: var(--ink); }
.chip[data-state="ok"]::before { background: var(--cool); }
.chip[data-state="waiting"]::before { background: var(--lamp); animation: blink 1s steps(2) infinite; }
.chip[data-state="denied"], .chip[data-state="error"], .chip[data-state="unavailable"] { color: var(--red); border-color: color-mix(in srgb, var(--red) 50%, transparent); }
.chip[data-state="denied"]::before, .chip[data-state="error"]::before, .chip[data-state="unavailable"]::before { background: var(--red); }
@keyframes blink { 50% { opacity: 0.2; } }

.ghost {
  background: transparent; border: 1px solid var(--line); border-radius: var(--r-sm);
  min-height: 52px; padding: 0 18px; cursor: pointer; color: var(--ink); font-weight: 600;
}
.ghost:active { background: var(--faint); }

/* ---------- layout ---------- */
.cockpit {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(360px, 1fr);
  gap: clamp(16px, 2vw, 28px);
  padding: 0 clamp(16px, 3vw, 32px) 20px;
  height: calc(100dvh - 82px);
}

.cluster { position: relative; display: grid; grid-template-rows: 1fr auto auto auto; min-height: 0; }
#tach { width: 100%; height: 100%; min-height: 300px; display: block; touch-action: none; cursor: pointer; }

.readout { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; border-top: 1px solid var(--line); padding: 14px 4px 0; }
.readout div { display: flex; flex-direction: column; gap: 4px; }
.readout .k { color: var(--dim); font-size: 15px; }
.readout .v { font: 600 24px/1.1 "Barlow Condensed", sans-serif; }
.meter { display: block; height: 12px; margin-top: 7px; background: var(--faint); border-radius: 6px; overflow: hidden; }
.meter span { display: block; height: 100%; width: 0; background: var(--lamp); transition: width 80ms linear; }

.big-btn {
  min-height: var(--tap); border-radius: var(--r-lg); border: 1px solid var(--line); background: var(--panel);
  font: 700 24px/1 "Barlow Condensed", sans-serif; cursor: pointer; touch-action: none; padding: 0 22px;
}
.big-btn:active, .big-btn[data-down] { background: var(--lamp); color: #1a1406; border-color: var(--lamp); }
.big-btn:disabled { opacity: 0.35; cursor: default; background: var(--panel); color: var(--ink); border-color: var(--line); }
.big-btn.sq { width: var(--tap); padding: 0; font-size: 34px; }
.big-btn.wide { width: 100%; }

.actions { display: flex; gap: 14px; margin-top: 14px; }
.actions .rev { flex: 1; }
.paddles { display: flex; gap: 14px; }
.paddles[hidden] { display: none; }
.paddles .big-btn { width: 110px; font-size: 44px; }

.pedals { display: grid; grid-template-columns: 1fr 1.5fr; gap: 14px; margin-top: 14px; }
.pedals[hidden] { display: none; }
.pedal {
  height: 104px; border-radius: var(--r-lg); border: 1px solid var(--line); background: var(--panel);
  font: 700 30px/1 "Barlow Condensed", sans-serif; cursor: pointer; touch-action: none;
}
.pedal.gas[data-down] { background: var(--lamp); color: #1a1406; border-color: var(--lamp); }
.pedal.brake[data-down] { background: var(--red); color: #fff; border-color: var(--red); }

.toast {
  position: absolute; left: 50%; top: 10px; transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 12px 20px; border-radius: 999px;
  font: 600 19px/1 "Barlow Condensed", sans-serif; pointer-events: none; white-space: nowrap;
}

/* ---------- control panel ---------- */
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: 22px; overflow-y: auto; min-height: 0;
  display: flex; flex-direction: column; gap: 20px;
}

.start {
  position: relative; align-self: center; width: 160px; height: 160px; border-radius: 50%; flex: none;
  border: none; background: radial-gradient(circle at 50% 38%, #2b3039, #15181d 70%);
  box-shadow: inset 0 0 0 2px #3a404a, 0 10px 30px rgba(0, 0, 0, 0.45); cursor: pointer;
}
.start-ring { position: absolute; inset: 10px; border-radius: 50%; border: 3px solid var(--faint); transition: border-color 200ms, box-shadow 200ms; }
.start-label { position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.start-label b { font: 700 36px/1 "Barlow Condensed", sans-serif; }
.start-label small { color: var(--dim); font-size: 16px; }
.start[aria-pressed="true"] .start-ring { border-color: var(--lamp); box-shadow: 0 0 22px color-mix(in srgb, var(--lamp) 45%, transparent); }
.start[data-busy] .start-ring { border-color: var(--lamp); animation: blink 0.5s steps(2) infinite; }
.start:active { transform: scale(0.98); }

.car-card {
  display: grid; grid-template-columns: 1fr auto; grid-template-areas: "k change" "name change" "spec change";
  text-align: left; gap: 2px 12px; align-items: center;
  background: var(--face); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 16px 18px; cursor: pointer;
}
.car-card:active { border-color: var(--lamp); }
.car-k { grid-area: k; color: var(--dim); font-size: 15px; }
.car-name { grid-area: name; font: 700 32px/1.05 "Barlow Condensed", sans-serif; }
.car-spec { grid-area: spec; color: var(--dim); font-size: 15px; }
.car-change { grid-area: change; border: 1px solid var(--line); border-radius: 999px; padding: 12px 16px; font-weight: 600; white-space: nowrap; }

.group h2 { font: 600 21px/1 "Barlow Condensed", sans-serif; margin: 0 0 12px; }
.group h3 { font: 600 24px/1 "Barlow Condensed", sans-serif; margin: 0 0 14px; }
.hint { color: var(--dim); font-size: 15px; margin: 10px 0 0; }
.hint.warn { color: var(--lamp); }
.fine { color: var(--dim); font-size: 14px; margin: 0; }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--face); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 4px; gap: 4px; }
.seg button { border: none; background: transparent; min-height: 48px; padding: 0 14px; border-radius: 9px; cursor: pointer; color: var(--dim); font-weight: 600; }
.seg.big button { min-height: 58px; font: 600 22px/1 "Barlow Condensed", sans-serif; }
.seg button[aria-checked="true"] { background: var(--line); color: var(--ink); }
.seg [data-mode="track"][aria-checked="true"] { background: var(--red); color: #fff; }
.seg [data-mode="sport"][aria-checked="true"] { background: var(--lamp); color: #1a1406; }

.vol { display: grid; grid-template-columns: auto 1fr auto auto; align-items: center; gap: 12px; }
.vol-bar { height: 14px; background: var(--faint); border-radius: 7px; overflow: hidden; }
.vol-bar span { display: block; height: 100%; width: 80%; background: var(--ink); }
.vol output { font: 600 22px "Barlow Condensed", sans-serif; min-width: 52px; text-align: right; }

/* ---------- sheets ---------- */
dialog.sheet {
  background: var(--bg); color: var(--ink); border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: 0 24px 24px; width: min(1400px, calc(100vw - 32px)); max-height: calc(100dvh - 32px);
}
dialog.sheet.side { width: min(640px, calc(100vw - 32px)); margin-right: 16px; }
dialog::backdrop { background: rgba(5, 6, 8, 0.72); }
.sheet-head { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between; padding: 20px 0 14px; background: var(--bg); }
.sheet-head h2 { font: 700 32px/1 "Barlow Condensed", sans-serif; margin: 0; }
dialog .group { padding: 18px 0; border-top: 1px solid var(--line); }

.cats { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 16px; scrollbar-width: none; }
.cats button {
  flex: none; min-height: 52px; padding: 0 20px; border-radius: 999px; border: 1px solid var(--line);
  background: transparent; font-weight: 600; cursor: pointer; color: var(--dim);
}
.cats button[aria-selected="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }

.cars { list-style: none; margin: 0 0 18px; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.car {
  position: relative; display: flex; flex-direction: column; gap: 8px; height: 100%;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 18px; cursor: pointer;
}
.car[aria-checked="true"] { border-color: var(--lamp); box-shadow: inset 0 0 0 1px var(--lamp); }
.car .name { font: 700 28px/1.05 "Barlow Condensed", sans-serif; padding-right: 56px; }
.car .spec { color: var(--dim); font-size: 15px; }
.car .blurb { font-size: 15px; color: var(--ink); opacity: 0.85; flex: 1; }
.car .tags { display: flex; flex-wrap: wrap; gap: 6px; }
.car .tags span { font-size: 13px; border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px; color: var(--dim); }
.car .tags .whine { border-color: color-mix(in srgb, var(--lamp) 60%, transparent); color: var(--lamp); }
.car .btns { display: flex; gap: 10px; margin-top: 4px; }
.car .btns button { flex: 1; min-height: 54px; border-radius: var(--r-sm); border: 1px solid var(--line); background: var(--face); font-weight: 600; cursor: pointer; }
.car .btns .pick { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.car[aria-checked="true"] .btns .pick { background: var(--lamp); border-color: var(--lamp); color: #1a1406; }
.fav { position: absolute; top: 10px; right: 10px; width: 54px; height: 54px; border: none; background: transparent; cursor: pointer; color: var(--dim); font-size: 30px; line-height: 1; }
.fav[aria-pressed="true"] { color: var(--lamp); }
.empty { color: var(--dim); padding: 30px 0; grid-column: 1 / -1; }

.slider { display: grid; grid-template-columns: 190px 1fr auto; align-items: center; gap: 14px; margin: 4px 0; color: var(--dim); font-size: 16px; }
.slider output { font: 600 18px "Barlow Condensed", sans-serif; color: var(--ink); min-width: 64px; text-align: right; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-top: 14px; color: var(--dim); font-size: 16px; }
.row .seg { min-width: 300px; }

.toggle { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-top: 16px; cursor: pointer; }
.toggle span { display: flex; flex-direction: column; font-size: 17px; }
.toggle small { color: var(--dim); font-size: 14px; }
.toggle input { appearance: none; -webkit-appearance: none; flex: none; width: 66px; height: 38px; border-radius: 19px; background: var(--faint); position: relative; cursor: pointer; margin: 0; transition: background 150ms; }
.toggle input::after { content: ""; position: absolute; top: 4px; left: 4px; width: 30px; height: 30px; border-radius: 50%; background: var(--ink); transition: transform 150ms; }
.toggle input:checked { background: var(--lamp); }
.toggle input:checked::after { transform: translateX(28px); }

input[type="range"] { -webkit-appearance: none; appearance: none; width: 100%; height: 48px; background: transparent; }
input[type="range"]::-webkit-slider-runnable-track { height: 8px; border-radius: 4px; background: var(--faint); }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 32px; height: 32px; margin-top: -12px; border-radius: 50%; background: var(--ink); border: 5px solid var(--bg); box-shadow: 0 0 0 1px var(--line); }
input[type="range"]::-moz-range-track { height: 8px; border-radius: 4px; background: var(--faint); }
input[type="range"]::-moz-range-thumb { width: 24px; height: 24px; border-radius: 50%; background: var(--ink); border: 4px solid var(--bg); }

.checks { list-style: none; padding: 0; margin: 0 0 12px; display: flex; flex-direction: column; gap: 10px; }
.checks li { display: flex; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--line); padding-bottom: 10px; font-size: 16px; }
.checks .ok { color: var(--cool); }
.checks .bad { color: var(--red); }
.checks .meh { color: var(--lamp); }

/* ---------- phones / portrait ---------- */
@media (max-width: 900px), (orientation: portrait) {
  .cockpit { grid-template-columns: 1fr; height: auto; }
  #tach { height: min(92vw, 520px); }
  .panel { overflow: visible; }
  .brand span { display: none; }
  .bar-right { gap: 8px; }
  .bar .ghost { min-height: 44px; padding: 0 12px; font-size: 15px; }
  .chip { font-size: 14px; padding: 9px 11px; }
  .slider { grid-template-columns: 1fr; gap: 0; }
  .row { flex-direction: column; align-items: stretch; }
  .row .seg { min-width: 0; }
  .paddles .big-btn { width: 80px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
