@font-face { font-family: Michroma; src: url(fonts/Michroma-Regular.ttf); font-display: block; }
@font-face { font-family: ShareMono; src: url(fonts/ShareTechMono-Regular.ttf); font-display: block; }
:root {
  --bg: #070709; --panel: #0f0f12; --line: #2e2e36; --line-hi: #6e6e7a;
  --text: #f0f0f2; --dim: #84848e; --faint: #44444c;
  --accent: #ff263e; --warn: #ffa824; --crit: #ff263e; --ok: #46dc8c;
  --disp: Michroma, 'Arial Black', sans-serif; --mono: ShareMono, ui-monospace, Menlo, monospace;
  --ease: cubic-bezier(.2, .7, .2, 1);
}
body.night { --text: #9a9a9d; --dim: #505056; --line: #1c1c21; --panel: #050506; --bg: #000; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--mono); overflow: hidden;
  -webkit-user-select: none; user-select: none; touch-action: manipulation; }
body { display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr) auto; height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
/* Labels are only as wide as their text, so values beside them never sit "under" them. */
label { font-size: 10px; letter-spacing: .18em; color: var(--dim); text-transform: uppercase; display: block; width: fit-content; max-width: 100%;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dim { color: var(--dim); font-size: 11px; letter-spacing: .08em; }
/* Numbers use tabular width so changing digits don't shove their neighbours around. */
.big, .mid, .huge, .val, .rpmv, .stat b, .kv b, .clock, .btn b { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* boot */
.boot { position: fixed; inset: 0; z-index: 9; background: var(--bg); display: grid; place-content: center; text-align: center; gap: 14px; transition: opacity .5s var(--ease); }
.boot.done { opacity: 0; pointer-events: none; }
.boot-mark { font: 34px var(--disp); letter-spacing: .12em; text-shadow: 0 0 18px rgba(255,255,255,.35); }
.boot-sub { font-size: 10px; letter-spacing: .2em; color: var(--dim); text-transform: uppercase; }
.boot-bar { width: 220px; height: 2px; background: var(--line); margin: 6px auto 0; overflow: hidden; }
.boot-bar i { display: block; height: 100%; width: 100%; background: var(--text); transform-origin: left; transform: scaleX(0); animation: load 2.2s var(--ease) forwards; }
@keyframes load { to { transform: scaleX(1); } }

/* header */
.bar { display: flex; align-items: center; gap: 6px; min-width: 0; padding: 6px 10px; border-bottom: 1px solid var(--line); min-height: 34px; }
.logo { font: 18px var(--disp); color: var(--accent); text-shadow: 0 0 12px var(--accent); flex: none; }
.brand { font-size: 11px; letter-spacing: .3em; flex: none; }
.hub { flex: 0 1 auto; min-width: 0; display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); padding: 3px 8px; font-size: 9px; letter-spacing: .14em; color: var(--dim); }
.hub b { flex: none; width: 5px; height: 5px; background: var(--faint); transition: background .3s; } .hub.live b { background: var(--ok); }
#hubText { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.spacer { flex: 1 1 0; min-width: 4px; }
.clock { font: 15px var(--disp); flex: none; }
.bar .chip { flex: none; }
.chip { border: 1px solid var(--line); color: var(--dim); font-size: 10px; letter-spacing: .14em; padding: 3px 8px; text-align: center; text-transform: uppercase;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transition: background-color .18s var(--ease), color .18s var(--ease), border-color .18s var(--ease); }
.chip.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.chip.accent { background: var(--accent); color: var(--bg); border-color: var(--accent); }
.chip.warn { background: var(--warn); color: var(--bg); border-color: var(--warn); }
.chip.crit, .rec { background: var(--crit); color: #fff; border-color: var(--crit); }

/* tabs */
.tabs { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 5px; padding: 6px 8px; border-top: 1px solid var(--line); }
.tabs button { font: 9px var(--mono); letter-spacing: .08em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 11px 0; background: none; color: var(--dim);
  border: 1px solid var(--line); text-transform: uppercase; transition: background-color .18s var(--ease), color .18s var(--ease), border-color .18s var(--ease); }
.tabs button.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.tabs button:active, .views button:active, .btn:active, .tile:active { transform: scale(.97); }

/* frame */
.app { display: grid; gap: 8px; padding: 8px; min-height: 0; min-width: 0; overflow: hidden; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
.driver { display: grid; gap: 6px; align-content: start; min-height: 0; min-width: 0; overflow: hidden; }
main { min-height: 0; min-width: 0; position: relative; overflow: hidden; }
.panel { background: var(--panel); border: 1px solid var(--line); padding: 8px 10px; position: relative; min-width: 0; min-height: 0; }
.panel::before, .panel::after { content: ''; position: absolute; width: 9px; height: 9px; border: 0 solid var(--line-hi); pointer-events: none; }
.panel::before { left: -1px; top: -1px; border-left-width: 1px; border-top-width: 1px; }
.panel::after { right: -1px; bottom: -1px; border-right-width: 1px; border-bottom-width: 1px; }
.big { font: 34px var(--disp); text-align: center; margin-top: 4px; text-shadow: 0 0 14px rgba(255,255,255,.35); }
.mid { font: 22px var(--disp); margin-top: 6px; text-shadow: 0 0 10px rgba(255,255,255,.25); overflow: hidden; text-overflow: ellipsis; }
.huge { font: clamp(34px, 13vw, 54px) var(--disp); margin: 8px 0 4px; text-shadow: 0 0 22px currentColor; transition: color .25s var(--ease); white-space: nowrap; overflow: hidden; }
.crit { color: var(--crit); }

/* driver column */
.pair { display: grid; grid-template-columns: minmax(0, 1fr) 96px; gap: 6px; }
.gear { border: 2px solid var(--text); }
.rpm { padding-bottom: 10px; display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; column-gap: 8px; }
.rpmv { font: 15px var(--disp); }
.rpm .seg { flex-basis: 100%; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 2px; height: 11px; margin-top: 8px; }
.seg i { background: var(--line); transition: background-color 90ms linear; }
.seg i.on { background: var(--text); } .seg i.hot { background: rgba(255,38,62,.3); } .seg i.on.hot { background: var(--crit); }
.seg.small { height: 8px; } .seg.amber i.on { background: var(--warn); }
.chips { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 5px; }
.rows { display: none; gap: 6px; }
.kv { display: flex; justify-content: space-between; align-items: center; border: 1px solid var(--line); background: var(--panel); padding: 8px 10px; gap: 8px; min-width: 0; }
.kv label { flex: none; }
.kv b { font: 16px var(--disp); font-weight: normal; transition: color .2s; } .kv u { text-decoration: none; font-size: 11px; color: var(--dim); }
.kv .lbar { flex: 1 1 auto; min-width: 12px; height: 4px; background: var(--line); overflow: hidden; }
.kv .lbar i { display: block; height: 100%; width: 100%; background: var(--text); transform-origin: left; transform: scaleX(0); }
.kv > span:last-child { flex: none; }

/* screens: fade in when switched */
.screen { display: none; height: 100%; min-height: 0; } .screen.on { display: grid; gap: 8px; animation: fadein .18s var(--ease); }
@keyframes fadein { from { opacity: 0; transform: translateY(4px); } }
button.chip { font-family: var(--mono); background: none; cursor: pointer; transition: transform .12s var(--ease), background-color .18s, color .18s; }
button.chip:active { transform: scale(.96); } button.chip:disabled { opacity: .4; cursor: default; }
.tabs { grid-template-columns: repeat(9, minmax(0, 1fr)); }
.ok { color: var(--ok); } .warn { color: var(--warn); }

/* shared headings */
.shifthead { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; min-width: 0; }
.shifthead h2 { margin: 0; font: 400 13px var(--mono); letter-spacing: .2em; white-space: nowrap; flex: none; }
.shifthead span { font-size: 10px; letter-spacing: .12em; color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.thead { display: flex; justify-content: space-between; align-items: center; gap: 8px; min-width: 0; }
.thead .chip { flex: none; }
.mid small, .val small { font: 10px var(--mono); color: var(--dim); margin-left: 4px; text-shadow: none; }
.stat { background: var(--panel); border: 1px solid var(--line); padding: 6px 8px; min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: baseline; column-gap: 4px; }
.stat label { grid-column: 1 / -1; }
.stat b { font: 16px var(--disp); font-weight: normal; overflow: hidden; text-overflow: ellipsis; }
.stat u { text-decoration: none; font-size: 10px; color: var(--dim); }
.btnrow { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.btnrow .chip { padding: 7px 10px; }
canvas { display: block; }
* { scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
::-webkit-scrollbar { width: 4px; height: 4px; } ::-webkit-scrollbar-thumb { background: var(--line); }

/* HOME: the car + launch / drift column */
#s-home { grid-template-rows: minmax(0, 1fr) auto; }
.car { padding: 0; overflow: hidden; min-height: 150px; container-type: size; }
.car > label { position: absolute; left: 10px; top: 8px; z-index: 2; max-width: 55%; }
.viewname { position: absolute; right: 10px; top: 7px; font-size: 11px; letter-spacing: .16em; z-index: 2; white-space: nowrap; }
#wire { position: absolute; inset: 0; width: 100%; height: 100%; }
.call { position: absolute; left: 0; top: 0; border: 1px solid var(--text); background: rgba(7,7,9,.86); font-size: 10px; letter-spacing: .12em; padding: 4px 7px;
  white-space: nowrap; z-index: 3; will-change: transform; pointer-events: none; }
.credit { position: absolute; left: 10px; right: 10px; bottom: 36px; font-size: 8px; line-height: 1.35; color: var(--faint); letter-spacing: .04em; z-index: 2; }   /* CC BY credit: wraps, never cut */
.views { position: absolute; left: 8px; right: 8px; bottom: 8px; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 3px; z-index: 4; }
.views button { font: 9px var(--mono); letter-spacing: .06em; padding: 6px 0; background: var(--bg); color: var(--dim); border: 1px solid var(--line); transition: background-color .18s, color .18s; }
.views button.on { background: var(--text); color: var(--bg); }
.launch { display: grid; gap: 6px; grid-template-columns: repeat(3, minmax(0, 1fr)); align-content: start; min-height: 0; }
.launch > .panel { container-type: inline-size; }
.launch .mid { font-size: clamp(15px, 16cqi, 24px); margin-top: 4px; }
.launch .dim { font-size: 9px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.launch .btnrow { grid-column: 1 / -1; }
.driftrow { display: flex; justify-content: space-between; align-items: baseline; gap: 6px; }
.mid.small { font-size: clamp(12px, 10cqi, 16px); color: var(--dim); }
.mult { display: flex; gap: 3px; margin: 5px 0 3px; } .mult .chip { flex: 1; padding: 2px 0; font-size: 9px; letter-spacing: 0; }

/* HANDLING */
#s-handling { grid-template-rows: auto minmax(0, 1fr); }
.hbody { display: grid; gap: 8px; min-height: 0; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) minmax(0, 1fr); }
.gbox, .traces { padding: 0; min-height: 0; } .gbox canvas, .traces canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.hstats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; align-content: start; min-height: 0; overflow: hidden; }
.hstats .chip { padding: 8px 4px; }
.traces { grid-column: 1 / -1; }

/* SHIFT */
#s-shift { grid-template-rows: auto minmax(0, 1fr); }
.shiftbody { display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); gap: 8px; min-height: 0; }
.shiftside { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.shiftside .panel { container-type: inline-size; }
.shiftside .mid { font-size: clamp(14px, 13cqi, 22px); }
.revm .dim { font-size: 9px; }
canvas.blip { width: 100%; height: 28px; margin-top: 4px; }
.rmhist { display: flex; gap: 3px; flex-wrap: wrap; margin-top: 4px; } .rmhist .chip { font-size: 8px; padding: 2px 4px; letter-spacing: .04em; }
.graph { padding: 0; min-height: 120px; } .graph canvas { position: absolute; inset: 0; width: 100%; height: 100%; }

/* ENGINE: six sparkline cards */
.egrid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); grid-template-rows: repeat(3, minmax(0, 1fr)); gap: 8px; height: 100%; min-height: 0; }
.ecard { display: grid; grid-template-rows: auto auto minmax(0, 1fr); container-type: inline-size; overflow: hidden; }
.ecard label { max-width: 55%; grid-row: 1; grid-column: 1; }
.ecard .pk { grid-row: 1; grid-column: 1; justify-self: end; font-size: 9px; letter-spacing: .1em; color: var(--dim); max-width: 42%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ecard .val { font: clamp(15px, 13cqi, 26px) var(--disp); text-shadow: 0 0 12px currentColor; overflow: hidden; transition: color .2s; }
.ecard canvas { width: 100%; height: 100%; min-height: 18px; }

/* DYNO */
#s-dyno { grid-template-rows: auto minmax(0, 1fr); }
.dynobody { display: grid; gap: 8px; min-height: 0; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
.dynoside { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; align-content: start; min-height: 0; }
.dynoside .panel { container-type: inline-size; } .dynoside .mid { font-size: clamp(15px, 15cqi, 24px); }
.dynoside .dim { font-size: 9px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dynoside .note, #dynonote { display: none; }
.dynoside > .chip { grid-column: 1 / -1; justify-self: end; padding: 7px 10px; }
.wrow { display: flex; align-items: baseline; gap: 6px; margin-top: 6px; } .wrow b { font: 16px var(--disp); font-weight: normal; } .wrow u { text-decoration: none; font-size: 10px; color: var(--dim); flex: 1; }
.wrow .chip { padding: 4px 10px; font-size: 13px; }

/* DIAG */
#s-diag { grid-template-rows: auto auto minmax(0, 1fr); }
.diagbtns { display: flex; gap: 6px; } .diagbtns .chip { padding: 8px 12px; } .diagbtns .chip.on { background: var(--text); color: var(--bg); }
.diagbody { display: grid; gap: 8px; min-height: 0; grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; }
.codes { overflow-y: auto; }
.codelist { display: grid; gap: 5px; margin-top: 6px; }
.code { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 10px; align-items: center; border: 1px solid var(--line); border-left-width: 3px; padding: 7px 9px; background: var(--bg); }
.code b { font: 14px var(--disp); font-weight: normal; } .code span { font-size: 11px; letter-spacing: .04em; overflow: hidden; text-overflow: ellipsis; }
.code em { font-style: normal; font-size: 9px; letter-spacing: .12em; color: var(--dim); }
.code.crit { border-left-color: var(--crit); color: var(--text); } .code.warn { border-left-color: var(--warn); } .code.perm { border-left-color: var(--line-hi); }
.codelist p { font-size: 12px; letter-spacing: .1em; margin: 8px 0; }
.diagside { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; min-height: 0; }
.diagside .panel { overflow-y: auto; }
.monlist { display: grid; gap: 3px; margin-top: 6px; }
.mon { display: flex; justify-content: space-between; gap: 8px; font-size: 10px; letter-spacing: .06em; border-bottom: 1px solid var(--line); padding: 3px 0; }
.mon span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; } .mon b { font-weight: normal; flex: none; }
.monlist p { margin: 4px 0; }

/* DRIVES */
#s-drives { grid-template-rows: auto minmax(0, 1fr); }
.drivebody { display: grid; gap: 8px; min-height: 0; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
.drivelist { display: flex; gap: 6px; overflow-x: auto; padding: 6px; }
.drive { flex: none; display: grid; gap: 2px; text-align: left; background: var(--bg); border: 1px solid var(--line); color: var(--text); font: 10px var(--mono); letter-spacing: .06em; padding: 7px 9px; cursor: pointer; position: relative; }
.drive b { font-weight: normal; font-size: 11px; } .drive span { color: var(--dim); font-size: 9px; }
.drive.on { border-color: var(--accent); } .drive em { position: absolute; right: 6px; top: 6px; font-style: normal; font-size: 8px; color: var(--accent); }
.drivelist p { margin: 4px; }
.mapbox { padding: 0; display: grid; grid-template-rows: minmax(0, 1fr) auto auto; min-height: 0; }
.mapbox canvas { width: 100%; height: 100%; min-height: 80px; }
.replay { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-top: 1px solid var(--line); }
.replay .chip { padding: 6px 10px; min-width: 58px; } .replay input { flex: 1; min-width: 0; accent-color: var(--accent); height: 24px; }
.replay span { flex: none; font-size: 10px; }
.replaydata { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 4px; padding: 0 8px 8px; }
.replaydata .stat b { font-size: 13px; }

/* BUS */
#s-bus { grid-template-rows: auto auto minmax(0, 1fr); }
#busfast { margin: 0; }
#tpmsNote { margin: 6px 0 0; }
#tpmsNote:empty { display: none; }
.buslog { overflow: hidden; font-size: 11px; line-height: 1.55; padding: 8px 10px; white-space: pre; display: flex; flex-direction: column; justify-content: flex-end; }
.buslog .l { overflow: hidden; text-overflow: ellipsis; } .buslog .l span { color: var(--dim); }

/* SETTINGS */
#s-settings { align-content: start; overflow-y: auto; }
.btns { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.btn { text-align: left; font: inherit; color: var(--text); cursor: pointer; padding: 10px 12px; min-height: 62px; display: flex; flex-direction: column; justify-content: space-between;
  container-type: inline-size; transition: transform .12s var(--ease), background-color .18s; }
.btn b { font: clamp(11px, 9cqi, 15px) var(--disp); font-weight: normal; overflow: hidden; text-overflow: ellipsis; }
.btn.on { background: var(--crit); color: #fff; border-color: var(--crit); } .btn.on label { color: #fff; }
.tripgrid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; margin-top: 6px; }
.tripgrid .stat b { font-size: 14px; }
.note { font-size: 10px; letter-spacing: .06em; line-height: 1.7; color: var(--dim); margin: 10px 2px; }

/* confirm + adapter picker dialogs */
.picker { position: fixed; inset: 0; z-index: 8; background: rgba(0,0,0,.72); display: grid; place-items: center; padding: 16px; animation: fadein .18s var(--ease); }
.picker[hidden] { display: none; }
.pick { width: min(420px, 100%); max-height: 80dvh; display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto; gap: 8px; }
#confirm .pick { grid-template-rows: auto auto auto; }
#confirm p { line-height: 1.6; margin: 0; }
.picklist { overflow-y: auto; display: grid; gap: 6px; align-content: start; min-height: 60px; }
.dev { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 12px; background: var(--bg); border: 1px solid var(--line);
  color: var(--text); font: 12px var(--mono); letter-spacing: .06em; text-align: left; cursor: pointer; transition: border-color .15s, transform .12s; }
.dev:active { transform: scale(.98); } .dev.likely { border-color: var(--accent); }
.dev.ecutek { cursor: default; opacity: .6; border-style: dashed; } .dev.ecutek small { color: var(--warn); }
.dev span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; } .dev small { color: var(--dim); flex: none; }
.pick > .chip { justify-self: end; padding: 8px 14px; }
.btnrow .chip.crit { background: var(--crit); color: #fff; }

/* speed and gear always fit their boxes, even at 3 digits */
.mph, .gear { container-type: inline-size; }
.pair .big { font-size: clamp(16px, 30cqi, 38px) !important; }

/* small phones (portrait): tighter */
@media (max-height: 700px) and (orientation: portrait) {
  .panel { padding: 6px 8px; }
  .seg { margin-top: 6px; height: 9px; }
  .tabs button { padding: 9px 0; }
  .launch .dim:last-child { display: none; }
}
@media (max-width: 430px) and (orientation: portrait) { .tabs { gap: 2px; padding: 6px 4px; } .tabs button { font-size: 7.5px; letter-spacing: 0; } }
@media (max-width: 340px) { .brand { display: none; } .hub { display: none; } #imuChip, #gpsChip { display: none; } }

/* wide / landscape: the car-screen layout, driver column on the left */
@media (min-width: 760px), (orientation: landscape) and (min-height: 300px) {
  .app { grid-template-columns: minmax(180px, 24%) minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); }
  .rows { display: grid; }
  .big { font-size: 38px; }
  #s-home { grid-template-columns: minmax(0, 1fr) minmax(150px, 25%); grid-template-rows: minmax(0, 1fr); }
  .launch { grid-template-columns: minmax(0, 1fr); }
  .hbody { grid-template-columns: minmax(0, 1fr) minmax(150px, 30%) minmax(0, 1.3fr); grid-template-rows: minmax(0, 1fr); }
  .traces { grid-column: auto; }
  .hstats { grid-template-columns: minmax(0, 1fr); }
  .egrid { grid-template-columns: repeat(3, minmax(0, 1fr)); grid-template-rows: repeat(2, minmax(0, 1fr)); }
  .shiftbody, .dynobody { grid-template-columns: 180px minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); }
  .shiftside, .dynoside { grid-template-columns: minmax(0, 1fr); align-content: start; overflow: hidden; }
  .diagbody { grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); }
  .diagside { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; }
  .drivebody { grid-template-columns: 170px minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); }
  .drivelist { flex-direction: column; overflow-x: hidden; overflow-y: auto; }
}
@media (min-width: 1000px) and (min-height: 600px) { .dynoside .note, #dynonote { display: block; margin: 2px; } }
/* short landscape phones: drop the row list and shrink so every panel fits */
@media (max-height: 480px) and (orientation: landscape) {
  .rows { display: none; }
  .big { font-size: 26px; margin-top: 0; }
  .panel { padding: 5px 8px; }
  .chips .chip { font-size: 8px; letter-spacing: .04em; padding: 3px 2px; }
  .tabs { padding: 4px 8px; } .tabs button { padding: 7px 0; font-size: 8px; letter-spacing: .02em; }
  .launch { gap: 4px; } .launch .mid { font-size: 17px; margin-top: 1px; } .launch .dim:last-child { display: none; }
  .launch .btnrow .chip { padding: 4px 6px; font-size: 8px; }
  .mult { margin: 2px 0; }
  .stat { padding: 3px 7px; } .stat b { font-size: 13px; }
  .shiftside .panel:last-child { display: none; } .dynoside { gap: 4px; } .dynoside .dim { display: none; }
  .btn { min-height: 52px; padding: 7px 10px; }
  .hstats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px; } .hstats .chip { padding: 5px 2px; font-size: 8px; letter-spacing: .04em; }
  .ecard .val { font-size: 15px; }
  .code { padding: 4px 7px; } .code b { font-size: 12px; }
  .replaydata { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .screen.on { animation: none; }
  .chip, .tabs button, .views button, .seg i, .btn, .boot { transition: none; }
}

/* ---- reel look: particle background behind translucent panels */
#fx { position: fixed; inset: 0; width: 100vw; height: 100vh; z-index: 0; pointer-events: none; opacity: .9; }
.bar, .app, .tabs { position: relative; z-index: 1; }
:root { --panel: rgba(15, 15, 19, .78); }
body.night { --panel: rgba(5, 5, 6, .82); }
.kv, .stat, .views button, .tabs button { background-color: rgba(10, 10, 13, .72); }
.tabs { grid-template-columns: repeat(12, minmax(0, 1fr)); }
@media (max-width: 700px) and (orientation: portrait) {
  .tabs { display: flex; overflow-x: auto; scrollbar-width: none; } .tabs::-webkit-scrollbar { display: none; }
  .tabs button { flex: none; padding: 10px 12px; font-size: 9px; letter-spacing: .06em; }
}

/* boot: modules heard on the CAN bus */
.boot-nodes { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; max-width: 560px; min-height: 22px; }
.boot-nodes span { border: 1px solid var(--line); padding: 4px 8px; font-size: 10px; letter-spacing: .1em; color: var(--dim); display: inline-flex; gap: 8px; animation: fadein .3s var(--ease); }
.boot-nodes b { color: var(--accent); font-weight: normal; }

/* shift animation: gear box pulse + banner */
.pair { position: relative; }
.gear.pulse { animation: gearpulse .45s var(--ease); }
.gear.pulse .big { animation: gearflip .45s var(--ease); }
@keyframes gearpulse { 0% { border-color: var(--accent); box-shadow: 0 0 0 0 var(--accent), inset 0 0 24px var(--accent); } 100% { box-shadow: 0 0 0 10px transparent, inset 0 0 0 transparent; } }
@keyframes gearflip { 0% { transform: translateY(40%) scale(.7); opacity: 0; filter: blur(3px); } 60% { transform: translateY(-4%) scale(1.06); opacity: 1; filter: none; } 100% { transform: none; } }
.shiftpop { position: absolute; left: 0; right: 0; top: 0; bottom: 0; z-index: 5; display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "s e" "b b";
  align-content: center; column-gap: 8px; row-gap: 2px; padding: 0 10px; border: 1px solid var(--warn); background: rgba(20, 14, 4, .92); color: var(--warn); pointer-events: none;
  opacity: 0; transform: scale(.9) translateY(-6px); transition: opacity .25s var(--ease), transform .35s var(--ease); }
.shiftpop.in { opacity: 1; transform: none; transition: opacity .12s var(--ease), transform .4s cubic-bezier(.2, 1.4, .3, 1); }
.shiftpop { container-type: inline-size; }
.shiftpop small { grid-area: s; font: 13px var(--mono); letter-spacing: .1em; color: var(--text); align-self: end; }
.shiftpop b { grid-area: b; font: clamp(12px, 11cqi, 24px) var(--disp); font-weight: normal; text-shadow: 0 0 12px currentColor; white-space: nowrap; overflow: hidden; }
.shiftpop em { grid-area: e; font: clamp(14px, 10cqi, 22px) var(--disp); font-style: normal; align-self: end; }
.shiftpop.good { border-color: var(--ok); color: var(--ok); background: rgba(4, 20, 12, .92); }
.shiftpop.bad { border-color: var(--crit); color: var(--crit); background: rgba(24, 4, 8, .92); }
.shiftpop.up { border-color: var(--accent); color: var(--accent); }

/* header: turn signals blink, lock / belt */
.chip.turn { background: var(--ok); color: #000; border-color: var(--ok); animation: blink .76s steps(1) infinite; }
@keyframes blink { 50% { opacity: .25; } }
.kv .lbar.mid { position: relative; } .kv .lbar.mid::after { content: ''; position: absolute; left: 50%; top: -2px; bottom: -2px; width: 1px; background: var(--dim); }
.kv .lbar.mid i { width: 50%; }

/* BODY */
#s-body { grid-template-rows: auto minmax(0, 1fr); }
.bodybody { display: grid; gap: 8px; min-height: 0; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto; overflow-y: auto; }
.bodygrid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 5px; align-content: start; }
.btile b { font-size: 13px; }
.stat.alert { border-color: var(--crit); } .stat.alert b { color: var(--crit); text-shadow: 0 0 10px rgba(255, 38, 62, .5); }
.bodyside { display: grid; gap: 8px; align-content: start; }
.tiregrid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 5px; margin-top: 6px; }

/* DIFF + CLUTCH */
#s-diff, #s-clutch { grid-template-rows: auto minmax(0, 1fr); }
.diffbody, .clutchbody { display: grid; gap: 8px; min-height: 0; grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; }
.wheels, .disc { padding: 0; min-height: 140px; } .wheels canvas, .disc canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.diffside, .clutchside { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; align-content: start; }

/* SETTINGS: CAN */
.canset { display: grid; gap: 6px; margin-bottom: 8px; }
.canrow { display: flex; gap: 6px; align-items: center; min-width: 0; }
.canrow input { flex: 1; min-width: 0; background: var(--bg); border: 1px solid var(--line); color: var(--text); font: 13px var(--mono); padding: 8px 10px; }
.canrow .dim { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.canrow .chip { padding: 8px 10px; flex: none; }
.filebtn { position: relative; overflow: hidden; cursor: pointer; display: inline-block; width: auto; } .filebtn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.canset p { margin: 0; line-height: 1.6; font-size: 9px; }

@media (min-width: 760px), (orientation: landscape) and (min-height: 300px) {
  .bodybody { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); }
  .bodygrid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .diffbody, .clutchbody { grid-template-columns: minmax(0, 1fr) minmax(150px, 30%); grid-template-rows: minmax(0, 1fr); }
  .diffside, .clutchside { grid-template-columns: minmax(0, 1fr); }
}
@media (max-height: 480px) and (orientation: landscape) {
  .btile { padding: 2px 6px; } .btile b { font-size: 11px; } .btile label { font-size: 8px; }
  .bodygrid { gap: 3px; }
  .diffside .stat b, .clutchside .stat b { font-size: 12px; }
  .clutchside { gap: 3px; } .clutchside .stat { padding: 2px 7px; }
  .shiftpop small { font-size: 10px; }
}
@media (prefers-reduced-motion: reduce) { .gear.pulse, .gear.pulse .big, .chip.turn { animation: none; } .shiftpop, .shiftpop.in { transition: opacity .2s; transform: none; } }
/* narrow portrait: keep the header on one line and long words inside their tiles */
@media (max-width: 500px) and (orientation: portrait) {
  .brand, #imuChip, #gpsChip { display: none; }
  .bar { gap: 4px; } .bar .chip { padding: 3px 5px; font-size: 9px; letter-spacing: .06em; }
  .btile b { font-size: 11px; } .bodygrid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .launch .thead .chip { display: none; }
  .tripgrid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #bodysub { display: none; }
}
/* scrolling screens: rows keep their content height instead of squeezing */
#s-settings { grid-auto-rows: max-content; }
@media (max-width: 759px) and (orientation: portrait) { .bodybody { grid-template-rows: none; grid-auto-rows: max-content; } }
/* dialogs sit on a solid panel above everything (panels elsewhere are see-through) */
.picker { z-index: 20; background: rgba(0, 0, 0, .86); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); }
.pick { background: #0d0d10; }
.feature-page.on { display: flex; flex-direction: column; overflow: auto; gap: 12px; }
.feature-grid { display: grid; grid-template-columns: repeat(auto-fit,minmax(135px,1fr)); gap: 8px; }
.feature-grid .stat { min-width: 0; padding: 14px; }
.feature-grid .stat b { font-size: clamp(18px,3vw,30px); overflow-wrap: anywhere; }
.feature-grid small { color: var(--dim); }
.feature-chart { width: 100%; min-height: 160px; max-height: 240px; }
.feature-options, .feature-export { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.feature-settings { padding: 12px; }
.feature-options { margin: 10px 0; }
.feature-options select { background: #141419; color: #eee; padding: 8px; }
.feature-order-row { display:flex; gap:12px; align-items:center; padding:5px; }
.feature-order-row span { flex:1; }
.feature-order-row button { padding: 6px 14px; }
#s-drives { grid-template-rows: auto minmax(0,1fr) auto; }
:root[data-font='mono'] body { font-family: ShareMono,monospace; }
:root[data-font='system'] body { font-family: system-ui,sans-serif; }
:root[data-theme='clean'] { --panel:#14181d; --dim:#9eaab8; }
:root[data-theme='amber'] { --panel:#1e190f; --dim:#b7a786; }
.feature-page b { color: var(--feature-accent,var(--text)); }
.drift-scene { position: relative; flex: 0 0 260px; min-height: 260px; overflow: hidden; background: radial-gradient(ellipse at center, #27111d, #080a10 75%); }
.drift-scene canvas { display: block; width: 100%; height: 260px; }
#drift-live-note { position: absolute; left: 12px; bottom: 12px; color: #bcbcca; font: 10px monospace; pointer-events: none; }
.drift-scene .chip { position: absolute; right: 12px; top: 12px; }

/* 18 tabs: one scrolling row at every size (the grid wrapped to two rows and squeezed the screens) */
.tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; scroll-snap-type: x proximity; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { flex: 1 0 auto; padding: 11px 12px; font-size: 9px; letter-spacing: .08em; white-space: nowrap; scroll-snap-align: center; }
.tabs button[hidden] { display: none; }
@media (max-height: 480px) and (orientation: landscape) { .tabs button { padding: 7px 10px; } }

/* extra pages (DRIFT, THROTTLE, VDC, IMU, MAP, SYSTEMS): compact header like the other tabs, cards that fit */
.feature-page h2 { margin: 0; font: 400 13px var(--mono); letter-spacing: .2em; }
.feature-page .note { margin: 0; line-height: 1.5; }
.feature-page.on { gap: 8px; padding-bottom: 6px; }
.feature-grid { grid-template-columns: repeat(auto-fit, minmax(118px, 1fr)); gap: 6px; }
.feature-grid .stat { padding: 7px 9px; }
.feature-grid .stat label { white-space: normal; overflow: visible; font-size: 9px; letter-spacing: .1em; line-height: 1.3; }
.feature-grid .stat b { font-size: clamp(15px, 2.2vw, 22px); white-space: normal; overflow: visible; text-overflow: clip; }
.feature-export { padding: 0 2px; } .feature-export .chip { padding: 7px 10px; }
#s-drives { grid-template-rows: auto minmax(0, 1fr) auto; }
@media (max-height: 480px) and (orientation: landscape) {
  .drift-scene { flex-basis: 150px; min-height: 150px; } .drift-scene canvas { height: 150px; }
  .feature-chart { min-height: 110px; max-height: 150px; }
}

/* POWER: two BMW-style sport gauges */
#s-power { grid-template-rows: auto minmax(0, 1fr) auto; }
.powerbody { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; min-height: 0; }
.pgauge { padding: 0; min-height: 140px; } .pgauge canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.powerfoot { display: flex; gap: 8px; align-items: center; min-width: 0; }
.powerfoot .dim { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.powerfoot button.chip { padding: 6px 10px; flex: none; }
@media (max-width: 500px) and (orientation: portrait) { .powerbody { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) minmax(0, 1fr); } }

/* Dock-style tab bar: room above the buttons for the swell, a floating label over the aimed tab */
.tabs { padding-top: 12px; touch-action: none; overscroll-behavior: contain; }
.tabs button { transform-origin: 50% 100%; transition: transform .16s cubic-bezier(.2, .8, .2, 1), background-color .18s, color .18s; will-change: transform; position: relative; }
.tabs.docking button { transition: transform .06s linear; }
.tabs button.aim { background: var(--accent); color: #fff; border-color: var(--accent); }
.docklabel { position: fixed; left: 0; top: 0; z-index: 30; pointer-events: none; padding: 7px 12px; border: 1px solid var(--accent);
  background: rgba(10, 10, 13, .92); color: var(--text); font: 12px var(--disp); letter-spacing: .12em; white-space: nowrap;
  box-shadow: 0 0 18px rgba(0, 0, 0, .6), 0 0 12px var(--accent); opacity: 0; transition: opacity .12s; }
.docklabel.on { opacity: 1; }
@media (max-height: 480px) and (orientation: landscape) { .tabs { padding-top: 10px; } }
@media (prefers-reduced-motion: reduce) { .tabs button { transition: none; } }

/* Lite mode (CarTV / CarPlay mirroring, or ?lite): no particle layer, no blur, minimal transitions */
.lite #fx { display: none; }
.lite .picker { -webkit-backdrop-filter: none; backdrop-filter: none; }
.lite .screen.on { animation: none; }
.lite .tabs button, .lite .chip, .lite .seg i { transition: none; }

/* Compact menu: a slim bar; the dock-style magnifier makes the small labels easy to hit */
.tabs { gap: 2px; padding: 9px 6px 4px; }
.tabs button { padding: 6px 9px; font-size: 8px; letter-spacing: .06em; min-height: 26px; }
.tabs button.on { box-shadow: 0 -2px 0 var(--accent) inset; }
@media (max-height: 480px) and (orientation: landscape) { .tabs { padding: 8px 4px 3px; } .tabs button { padding: 5px 8px; min-height: 22px; } }
@media (max-width: 700px) and (orientation: portrait) { .tabs button { padding: 8px 9px; font-size: 8px; } }
.lite .tabs button { min-height: 30px; font-size: 9px; }   /* CarPlay touch screens: a little bigger target */

/* POWER: 2 or 4 selectable gauges; tap one to change what it shows */
.pgauge { font: inherit; color: inherit; cursor: pointer; text-align: left; transition: transform .12s var(--ease); }
.pgauge:active { transform: scale(.985); }
.pgauge[hidden] { display: none; }
.pgauge .gname { position: absolute; left: 8px; top: 6px; font-size: 9px; letter-spacing: .14em; color: var(--dim); pointer-events: none; }
.powerbody.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 760px) { .powerbody.four { grid-template-columns: repeat(2, minmax(0, 1fr)); grid-template-rows: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 500px) and (orientation: portrait) { .powerbody.four { grid-template-rows: repeat(2, minmax(0, 1fr)); } }
