:root {
  --bg: #0b0d10;
  --panel: #13171c;
  --panel-2: #1a1f26;
  --line: #262d36;
  --text: #e8ecf1;
  --muted: #8b95a3;
  --accent: #ff5a1f;
  --accent-2: #ffb020;
  --ok: #35c46a;
  --warn: #f5b83d;
  --err: #ff5d5d;
  --blue: #4aa3ff;
  --radius: 14px;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
code { font-family: var(--mono); font-size: 0.9em; background: var(--panel-2); padding: 1px 5px; border-radius: 5px; }
kbd { font-family: var(--mono); font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; margin-left: 6px; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 16px;
  padding: 12px max(16px, env(safe-area-inset-left));
  background: rgba(11, 13, 16, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; letter-spacing: 0.2px; display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.brand-mark { width: 22px; height: 12px; border: 3px solid var(--accent); border-bottom: 0; border-radius: 22px 22px 0 0; }
.mode-tabs { display: flex; background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 3px; margin-left: auto; }
.mode-tabs button { border: 0; background: none; padding: 6px 14px; border-radius: 999px; color: var(--muted); font-weight: 600; }
.mode-tabs button[aria-selected="true"] { background: var(--text); color: var(--bg); }
.chip { font-size: 12px; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px; white-space: nowrap; }
.chip.on { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 50%, transparent); }

/* Layout */
.layout {
  display: grid;
  grid-template-columns: minmax(340px, 1.05fr) minmax(320px, 1fr);
  gap: 16px;
  padding: 16px;
  max-width: 1280px;
  margin: 0 auto;
  align-items: start;
}
.side { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; min-width: 0; }
.panel h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.8px; color: var(--muted); margin: 0 0 12px; display: flex; align-items: center; gap: 10px; }
.panel h3 { font-size: 14px; margin: 18px 0 8px; }
.dash { display: flex; flex-direction: column; gap: 14px; }
/* Pinned only when the whole dashboard fits on screen. */
@media (min-width: 861px) and (min-height: 860px) { .dash { position: sticky; top: 72px; } }
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; padding: 12px 16px; }
  .dash { position: static; }
  .brand { font-size: 14px; }
  .topbar { gap: 10px; padding: 10px 16px; }
  .chip { display: none; }
}

/* Dashboard */
.car-title { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.car-name { font-size: 22px; font-weight: 700; }
.car-tagline { color: var(--muted); font-size: 13px; }
.source-chip { font-size: 12px; color: var(--muted); white-space: nowrap; border: 1px solid var(--line); border-radius: 999px; padding: 3px 9px; }
.source-chip.live { color: var(--blue); border-color: color-mix(in srgb, var(--blue) 50%, transparent); }

.gauge-wrap { position: relative; width: min(100%, 380px); margin: 0 auto; aspect-ratio: 1; }
.tach { width: 100%; height: 100%; display: block; }
.tach .face { fill: var(--panel-2); stroke: var(--line); stroke-width: 1; }
.tach .track { fill: none; stroke: #222a33; stroke-width: 12; stroke-linecap: round; }
.tach .red { fill: none; stroke: var(--accent); stroke-width: 12; opacity: 0.85; }
.tach .fill { fill: none; stroke: var(--text); stroke-width: 12; stroke-linecap: round; opacity: 0.9; transition: stroke 0.15s; }
.tach .fill.hot { stroke: var(--accent-2); }
.tach .tick { stroke: var(--muted); stroke-width: 2; }
.tach .tick.minor { stroke-width: 1; opacity: 0.5; }
.tach .label { fill: var(--muted); font: 600 15px var(--mono); text-anchor: middle; dominant-baseline: middle; }
.tach .label.redzone { fill: var(--accent); }
.tach .needle { stroke: var(--accent); stroke-width: 4; stroke-linecap: round; }
.tach .hub { fill: var(--accent); }
.tach .x1000 { fill: var(--muted); font: 11px system-ui; text-anchor: middle; }
/* Readouts sit in the open bottom of the dial, clear of the needle and labels. */
.gauge-center { position: absolute; left: 50%; top: 57%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; pointer-events: none; }
.gear { font: 800 48px/1 var(--mono); }
.rpm { font: 600 16px var(--mono); color: var(--muted); font-variant-numeric: tabular-nums; margin-top: 4px; }
.speed { font: 700 24px/1.2 var(--mono); white-space: nowrap; font-variant-numeric: tabular-nums; margin-top: 6px; pointer-events: auto; }
.unit { border: 0; background: none; color: var(--muted); font: 600 13px system-ui; padding: 0; text-decoration: underline dotted; }

.meters { display: grid; gap: 8px; }
.meter { display: grid; grid-template-columns: 70px 1fr 48px; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); }
.meter b { font: 600 13px var(--mono); color: var(--text); text-align: right; font-variant-numeric: tabular-nums; }
.bar { height: 8px; background: #222a33; border-radius: 99px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--ok); border-radius: 99px; }
.bar.load i { background: var(--accent-2); }
.leds { display: flex; gap: 8px; margin-top: 2px; }
.led { font: 700 11px var(--mono); letter-spacing: 1px; padding: 3px 8px; border-radius: 6px; border: 1px solid var(--line); color: #4a5361; transition: all 0.08s; }
.led.on { color: var(--bg); background: var(--accent-2); border-color: var(--accent-2); }
#ledCut.on { background: var(--accent); border-color: var(--accent); }
#ledShift.on { background: var(--blue); border-color: var(--blue); }

.scope { width: 100%; height: 64px; display: block; background: var(--panel-2); border-radius: 10px; }

.start-btn {
  border: 0; border-radius: 999px; padding: 16px; font-weight: 800; font-size: 17px; letter-spacing: 1px; text-transform: uppercase;
  background: var(--accent); color: #fff; box-shadow: 0 8px 30px -10px var(--accent);
}
.start-btn.on { background: var(--panel-2); color: var(--text); box-shadow: none; border: 1px solid var(--line); }
.hint { margin: 0; color: var(--muted); font-size: 13px; text-align: center; min-height: 1.4em; }

/* Simulator */
.pedals { display: grid; grid-template-columns: 1fr 1.4fr; gap: 12px; }
.pedal {
  height: 120px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel-2);
  font-weight: 800; font-size: 18px; letter-spacing: 1px; text-transform: uppercase;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  user-select: none; -webkit-user-select: none; touch-action: none;
}
.pedal kbd { margin: 0; }
.pedal.gas.down { background: var(--ok); color: var(--bg); border-color: var(--ok); }
.pedal.brake.down { background: var(--err); color: var(--bg); border-color: var(--err); }
.pedal-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 12px; }
.pill-btn { border: 1px solid var(--line); background: var(--panel-2); border-radius: 999px; padding: 7px 14px; font-weight: 600; user-select: none; -webkit-user-select: none; touch-action: none; }
.pill-btn.down, .pill-btn[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }
.pill-btn.down kbd, .pill-btn[aria-pressed="true"] kbd { color: var(--bg); border-color: var(--bg); }
.inline-slider { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); margin-left: auto; }
.inline-slider output { font: 600 12px var(--mono); color: var(--text); min-width: 36px; }

/* Sliders */
.sliders { display: grid; gap: 10px; }
.sliders label { display: grid; grid-template-columns: 90px 1fr 44px; align-items: center; gap: 10px; font-size: 14px; color: var(--muted); }
.sliders output { font: 600 12px var(--mono); color: var(--text); text-align: right; }
input[type="range"] { accent-color: var(--accent); width: 100%; min-width: 80px; }

/* Car picker */
.cars { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.car {
  text-align: left; border: 1px solid var(--line); background: var(--panel-2); border-radius: 10px; padding: 10px 12px;
  display: flex; flex-direction: column; gap: 3px; min-width: 0;
}
.car b { font-size: 14px; }
.car small { color: var(--muted); font-size: 12px; line-height: 1.3; }
.car .cyl { font: 600 11px var(--mono); color: var(--accent-2); }
.car[aria-checked="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }

/* OBD */
.status { margin-left: auto; text-transform: none; letter-spacing: 0; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 999px; border: 1px solid var(--line); }
.status[data-state="live"] { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 50%, transparent); }
.status[data-state="connecting"] { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 50%, transparent); }
.status[data-state="error"] { color: var(--err); border-color: color-mix(in srgb, var(--err) 50%, transparent); }
.links { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
@media (max-width: 480px) { .links { grid-template-columns: 1fr; } }
.link { display: flex; gap: 10px; align-items: flex-start; border: 1px solid var(--line); background: var(--panel-2); border-radius: 10px; padding: 10px; cursor: pointer; }
.link input { margin-top: 3px; accent-color: var(--accent); }
.link span { display: flex; flex-direction: column; min-width: 0; }
.link small { color: var(--muted); font-size: 12px; line-height: 1.3; }
.link:has(input:checked) { border-color: var(--accent); }
.link.unsupported { opacity: 0.5; }
.link-opts { display: none; margin-top: 12px; }
.link-opts.show { display: block; }
.link-opts label, .field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); margin-top: 10px; }
.link-opts label { margin-top: 0; }
input:not([type]), input[type="number"], select {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; color: var(--text); min-width: 0;
}
input:focus-visible, select:focus-visible, button:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
.note { color: var(--muted); font-size: 12.5px; margin: 6px 0 0; }
.row { display: flex; align-items: center; gap: 12px; margin-top: 14px; flex-wrap: wrap; }
.btn { border: 1px solid var(--line); background: var(--panel-2); border-radius: 10px; padding: 9px 18px; font-weight: 700; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary.danger { background: var(--panel-2); border-color: var(--line); color: var(--text); }
.btn:disabled { opacity: 0.6; cursor: progress; }
.err { color: var(--err); font-size: 13px; flex: 1; min-width: 160px; }
.info { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin: 14px 0 0; }
@media (max-width: 560px) { .info { grid-template-columns: 1fr 1fr; } }
.info div { background: var(--panel-2); border-radius: 8px; padding: 8px 10px; min-width: 0; }
.info dt { font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--muted); }
.info dd { margin: 2px 0 0; font: 600 13px var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.readings { width: 100%; border-collapse: collapse; margin-top: 10px; font-size: 13px; }
.readings td { padding: 5px 4px; border-bottom: 1px solid var(--line); }
.readings td:first-child { color: var(--muted); }
.readings td.pid { font: 11px var(--mono); color: #5d6775; width: 34px; }
.readings td.v { text-align: right; font: 600 13px var(--mono); font-variant-numeric: tabular-nums; }
.seg { display: inline-flex; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.seg label { cursor: pointer; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; padding: 6px 14px; border-radius: 8px; font-weight: 600; font-size: 14px; color: var(--muted); }
.seg input:checked + span { background: var(--text); color: var(--bg); }
.seg input:focus-visible + span { outline: 2px solid var(--blue); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.grid2 label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.thr-learn { font: 12px var(--mono); color: var(--muted); margin-top: 6px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.link-btn { border: 0; background: none; color: var(--blue); padding: 0; font: 600 12px system-ui; }
.ecu { margin-top: 16px; padding: 12px; border: 1px dashed var(--line); border-radius: 10px; }
.ecu h3 { margin-top: 0; }
.ecu-readout { font: 600 14px var(--mono); margin: 0 0 8px; font-variant-numeric: tabular-nums; }
.ecu-manual { margin-top: 8px; }
.ecu-manual .inline-slider { margin-left: 0; }
.ecu-manual.disabled { opacity: 0.45; pointer-events: none; }
.check { display: flex; gap: 8px; align-items: center; font-size: 14px; }
.check input { accent-color: var(--accent); }
.log { margin-top: 16px; }
.log summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.log pre {
  max-height: 220px; overflow: auto; background: #07090b; border: 1px solid var(--line); border-radius: 8px;
  padding: 10px; font: 11.5px/1.5 var(--mono); white-space: pre-wrap; word-break: break-word; margin: 8px 0 0;
}
.log .warn { color: var(--warn); }
.log .error { color: var(--err); }
.mode-tabs button { white-space: nowrap; }
@media (max-width: 420px) {
  .brand { font-size: 0; gap: 0; } /* just the mark, so the tabs fit */
  .mode-tabs button { padding: 6px 12px; }
}
