/* KC Neural Racing (phone and computer). Broadcast-style chrome; system font for text, Barlow Condensed for display.
   Phone-first; the wide-screen layout (≥ 1100 px) is at the end. */
@font-face { font-family: 'Barlow Condensed'; font-style: normal; font-weight: 700; font-display: swap; src: url(fonts/BarlowCondensed-8.woff2) format('woff2'); }
@font-face { font-family: 'Barlow Condensed'; font-style: italic; font-weight: 800; font-display: swap; src: url(fonts/BarlowCondensed-5.woff2) format('woff2'); }

:root {
  color-scheme: light;
  --font-display: "Barlow Condensed", "Arial Narrow", -apple-system, system-ui, sans-serif;
  --font-body: -apple-system, system-ui, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, Menlo, Consolas, monospace;

  --surface-0: #efeee9; --surface-1: #ffffff; --surface-2: #f4f3ef; --surface-3: #e9e7e1; --border: #e1dfd8;
  --text-primary: #101114; --text-secondary: #4d4f55; --text-muted: #6f7178;
  --grid: #ecebe6; --axis: #c9c7c0;
  --shadow: 0 1px 2px rgba(20, 20, 30, .06), 0 0 0 1px rgba(20, 20, 30, .05);
  --carbon: #111317; --carbon-2: #1b1e24; --carbon-3: #272b33; --carbon-line: #2e333c; --carbon-text: #f4f4f2; --carbon-muted: #9aa0aa;
  --brand: #e5322d; --brand-2: #ff5a3c;
  --series-1: #2a78d6; --series-2: #eb6834; --accent: #2a78d6;
  --good: #0f9d58; --warning: #f2a516; --critical: #d63a3a;
  --neg: #2a78d6; --pos: #e34948; --neutral: #e6e5e1;
  /* replay map: daytime, sun from the north-west */
  --map-bg: #e4e1d8; --map-building: #d8d5cc; --map-park: #bcd5a3; --map-water: #97c0de; --map-street: #a3a39f;
  --map-walk: #d3d0c7; --map-lane: rgba(255, 255, 255, .55); --map-road: #55585e; --map-curb: #f4f4f2;
  --map-center: rgba(255, 255, 255, .4); --map-kerb: #d8423a; --map-shadow: rgba(48, 52, 70, .28);
  --map-tree: #6f9f55; --map-tree-hi: #8dba6c; --map-tree-shadow: rgba(40, 60, 40, .24); --map-trunk: #7a6450;
  --map-window: transparent; --map-ray: #ffd84a; --map-night: 0;
  --ray-wall: #6f6e69; --ray-car: #d03b3b;
  --tabbar-h: 56px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --surface-0: #0a0c0f; --surface-1: #13161b; --surface-2: #1b1f26; --surface-3: #242932; --border: #262b33;
    --text-primary: #eef0f3; --text-secondary: #b6bcc5; --text-muted: #8a919b;
    --grid: #1f242b; --axis: #3a414b;
    --shadow: 0 0 0 1px #20252d;
    --carbon: #07080a; --carbon-2: #121418; --carbon-3: #1d2026; --carbon-line: #252931;
    --series-1: #3f8cea; --series-2: #f0763f; --accent: #3f8cea;
    --neg: #3f8cea; --pos: #e66767; --neutral: #343a43; --good: #2fbf71;
    --map-bg: #14171c; --map-building: #2a303a; --map-park: #17261b; --map-water: #10202f;
    --map-street: #2a2e35; --map-walk: #1f2329; --map-lane: rgba(255, 255, 255, .18); --map-road: #3a3f48;
    --map-curb: #c9ccd2; --map-center: rgba(255, 255, 255, .28); --map-kerb: #b8392f; --map-shadow: rgba(0, 0, 0, .38);
    --map-tree: #213a26; --map-tree-hi: #2b4a30; --map-tree-shadow: rgba(0, 0, 0, .32); --map-trunk: #2e2822;
    --map-window: rgba(255, 200, 120, .30); --map-ray: #ffd84a; --map-night: 1;
    --ray-wall: #b9bec6; --ray-car: #ff6b6b;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-0: #0a0c0f; --surface-1: #13161b; --surface-2: #1b1f26; --surface-3: #242932; --border: #262b33;
  --text-primary: #eef0f3; --text-secondary: #b6bcc5; --text-muted: #8a919b;
  --grid: #1f242b; --axis: #3a414b;
  --shadow: 0 0 0 1px #20252d;
  --carbon: #07080a; --carbon-2: #121418; --carbon-3: #1d2026; --carbon-line: #252931;
  --series-1: #3f8cea; --series-2: #f0763f; --accent: #3f8cea;
  --neg: #3f8cea; --pos: #e66767; --neutral: #343a43; --good: #2fbf71;
  --map-bg: #14171c; --map-building: #2a303a; --map-park: #17261b; --map-water: #10202f;
  --map-street: #2a2e35; --map-walk: #1f2329; --map-lane: rgba(255, 255, 255, .18); --map-road: #3a3f48;
  --map-curb: #c9ccd2; --map-center: rgba(255, 255, 255, .28); --map-kerb: #b8392f; --map-shadow: rgba(0, 0, 0, .38);
  --map-tree: #213a26; --map-tree-hi: #2b4a30; --map-tree-shadow: rgba(0, 0, 0, .32); --map-trunk: #2e2822;
  --map-window: rgba(255, 200, 120, .30); --map-ray: #ffd84a; --map-night: 1;
  --ray-wall: #b9bec6; --ray-car: #ff6b6b;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--surface-0); color: var(--text-primary);
  font: 15px/1.45 var(--font-body); -webkit-font-smoothing: antialiased;
  padding-bottom: calc(var(--tabbar-h) + var(--safe-b));
  overscroll-behavior-y: none;
}
h1, h2, h3 { font-family: var(--font-display); text-transform: uppercase; }
h1 { font-size: 21px; margin: 0; font-weight: 800; font-style: italic; letter-spacing: .01em; line-height: 1; white-space: nowrap; }
h2 { font-size: 19px; margin: 0; font-weight: 700; letter-spacing: .02em; line-height: 1.15; }
h3 { font-size: 15px; margin: 0; font-weight: 700; letter-spacing: .04em; }
.sub { color: var(--text-muted); font-size: 13px; font-weight: 400; margin: 3px 0 0; text-transform: none; letter-spacing: 0; font-family: var(--font-body); }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.grow { flex: 1; min-width: 0; }
button { font-family: inherit; }

/* ---------------------------------------------------------- header (always dark) */
.top {
  position: sticky; top: 0; z-index: 10; background: var(--carbon); color: var(--carbon-text);
  padding-top: var(--safe-t);
}
.top-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 16px 4px; }
.brand { display: flex; align-items: center; gap: 9px; min-width: 0; }
.logo { display: inline-grid; place-items: center; width: 34px; height: 25px; color: #fff; background: var(--brand); transform: skewX(-14deg); border-radius: 3px; flex: none; }
.logo svg { transform: skewX(14deg); }
.brand h1 .b1 { color: var(--brand-2); }
.run {
  display: inline-flex; align-items: center; gap: 7px; flex: none;
  font: 700 15px/1 var(--font-display); text-transform: uppercase; letter-spacing: .06em;
  background: var(--brand); color: #fff; border: 0; border-radius: 20px; padding: 9px 16px 9px 13px; min-height: 38px; cursor: pointer;
}
.run:active { transform: scale(.97); }
.run:disabled { background: var(--carbon-3); color: var(--carbon-muted); }
.run .i-pause { display: none; }
.run.on { background: var(--carbon-3); color: var(--carbon-text); box-shadow: inset 0 0 0 1px var(--carbon-line); }
.run.on .i-pause { display: block; }
.run.on .i-play { display: none; }
.statusbar { display: flex; align-items: center; gap: 8px; padding: 2px 16px 9px; color: var(--carbon-muted); font-size: 13px; min-height: 26px; }
#statusText { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.statusbar .live {
  display: none; font: 800 11px/1 var(--font-display); font-style: italic; letter-spacing: .1em; text-transform: uppercase;
  background: var(--brand); color: #fff; padding: 3px 6px 2px; border-radius: 2px; flex: none;
}
.statusbar.running .live { display: inline-block; animation: livepulse 2s ease-in-out infinite; }
.statusbar.running .dot { display: none; }
.statusbar.running #statusText { color: var(--carbon-text); }
.statusbar .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--carbon-muted); flex: none; }
.statusbar.error .dot { background: var(--critical); }
@keyframes livepulse { 50% { opacity: .6; } }
@media (prefers-reduced-motion: reduce) { .statusbar.running .live { animation: none; } }
.genbar { height: 3px; background: var(--carbon-2); }
.genbar i { display: block; height: 100%; width: 0; background: var(--brand); transition: width .25s linear; }

/* ---------------------------------------------------------- bottom tab bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: color-mix(in srgb, var(--carbon) 94%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--carbon-line); padding-bottom: var(--safe-b);
}
.tab {
  height: var(--tabbar-h); border: 0; background: none; color: var(--carbon-muted); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font: 700 11.5px/1 var(--font-display); text-transform: uppercase; letter-spacing: .07em; position: relative;
}
.tab svg { width: 23px; height: 23px; }
.tab.active { color: var(--carbon-text); }
.tab.active::before { content: ""; position: absolute; top: 0; left: 30%; right: 30%; height: 3px; background: var(--brand); transform: skewX(-20deg); }

/* ---------------------------------------------------------- layout */
main { padding: 12px 12px 20px; max-width: 760px; margin: 0 auto; }
.tabpage { display: none; }
.tabpage.active { display: block; }
.error { margin: 10px 12px 0; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--critical); color: var(--critical); background: var(--surface-1); white-space: pre-wrap; font-size: 13px; }
.card { background: var(--surface-1); box-shadow: var(--shadow); border-radius: 12px; padding: 14px; margin-bottom: 12px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 10px; }
.card > .card-head h2, .section-head h2, .explain > h2, #tab-settings .card > h2 { display: flex; align-items: center; gap: 9px; }
.card > .card-head h2::before, .section-head h2::before, .explain > h2::before, #tab-settings .card > h2::before {
  content: ""; width: 5px; height: 16px; background: var(--brand); transform: skewX(-14deg); flex: none;
}
.section-head { margin: 4px 2px 12px; }
.fit-fields { display: grid; gap: 10px; margin-top: 12px; }
.fit-row { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 10px; }
.fit-row b { font-size: 14px; display: block; }
.fit-row .sub { margin: 1px 0 0; font-size: 12px; }
.fit-row.changed b::after { content: " \00B7  changed"; color: var(--accent); font-weight: 500; font-size: 12px; }
.stepper { display: inline-flex; align-items: center; background: var(--surface-2); border-radius: 9px; padding: 3px; }
.stepper button { border: 0; background: none; color: var(--text-primary); width: 34px; height: 34px; border-radius: 7px; font-size: 18px; line-height: 1; cursor: pointer; }
.stepper button:active { background: var(--surface-3); }
.stepper input { width: 58px; height: 34px; border: 0; background: var(--surface-1); color: var(--text-primary); border-radius: 6px; text-align: center;
  font: 600 15px/1 var(--font-mono); font-variant-numeric: tabular-nums; -moz-appearance: textfield; appearance: textfield; }
.stepper input::-webkit-inner-spin-button, .stepper input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.stepper input:focus { outline: 2px solid var(--accent); outline-offset: 0; }
.fit-formula { font-size: 12px; color: var(--text-secondary); background: var(--surface-2); border-radius: 8px; padding: 9px 10px; margin: 12px 0 0; line-height: 1.5; }
.fit-examples { display: grid; gap: 6px; margin-top: 10px; }
.fit-ex { display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; font-size: 13px; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border); }
.fit-ex .v { font: 700 16px/1 var(--font-mono); font-variant-numeric: tabular-nums; text-align: right; align-self: center; grid-row: span 2; }
.fit-ex .bars { display: flex; height: 5px; border-radius: 3px; overflow: hidden; background: var(--surface-2); }
.fit-ex .bars i { display: block; height: 100%; }
.fit-legend { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 11.5px; color: var(--text-muted); margin-top: 2px; }
.fit-legend i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 4px; vertical-align: -0.5px; }
.fit-foot { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
.fit-foot .btn { flex: none; }
.note { font-size: 13px; color: var(--text-secondary); margin: 10px 0 0; }

.btn {
  font: 700 14px/1 var(--font-display); text-transform: uppercase; letter-spacing: .06em;
  padding: 10px 14px; border-radius: 8px; cursor: pointer; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text-primary); min-height: 40px;
}
.btn.small { padding: 8px 11px; min-height: 36px; font-size: 13px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.btn:disabled { opacity: .5; }
.btn.danger { color: var(--critical); border-color: color-mix(in srgb, var(--critical) 45%, var(--border)); background: transparent; margin-top: 12px; }

.tno {
  --tc: #888; --tt: #fff;
  display: inline-grid; place-items: center; min-width: 22px; height: 20px; padding: 0 4px;
  background: var(--tc); color: var(--tt); border-radius: 3px; flex: none;
  font: italic 800 13px/1 var(--font-display);
}
.tno.big { min-width: 42px; height: 38px; font-size: 24px; border-radius: 5px; transform: skewX(-8deg); }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; flex: none; }
.sw.neg { background: var(--neg); } .sw.zero { background: var(--neutral); } .sw.pos { background: var(--pos); }
.badge {
  font: 700 10.5px/1 var(--font-display); text-transform: uppercase; letter-spacing: .08em;
  padding: 3px 5px 2px; border-radius: 2px; background: var(--surface-3); color: var(--text-secondary); white-space: nowrap;
}
.badge.brand { background: var(--brand); color: #fff; }
.empty-note { color: var(--text-muted); font-size: 13px; padding: 8px 0; }

/* ---------------------------------------------------------- segmented */
.seg { display: inline-flex; background: var(--surface-2); border-radius: 9px; padding: 3px; gap: 2px; max-width: 100%; }
.seg.scroll { overflow-x: auto; scrollbar-width: none; }
.seg.scroll::-webkit-scrollbar { display: none; }
.seg.wide { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; width: 100%; margin-top: 10px; }
.seg button {
  font: 700 14px/1 var(--font-display); text-transform: uppercase; letter-spacing: .05em; white-space: nowrap;
  border: 0; background: none; color: var(--text-muted); padding: 9px 12px; border-radius: 7px; cursor: pointer; min-height: 36px;
}
.seg button.on { background: var(--carbon); color: var(--carbon-text); }
.seg.small button { font-size: 12.5px; padding: 6px 9px; min-height: 30px; }

/* ---------------------------------------------------------- hero */
.hero { background: var(--carbon); color: var(--carbon-text); border-radius: 12px; overflow: hidden; margin-bottom: 12px; }
.hero-gen { display: flex; gap: 16px; align-items: center; padding: 14px 16px; background: var(--carbon-2); }
.hero-gen .k, .hstat .k { font: 700 12px/1.1 var(--font-display); letter-spacing: .12em; text-transform: uppercase; color: var(--carbon-muted); }
.hero-gen .v { font: italic 800 54px/0.9 var(--font-display); margin-top: 4px; }
.hero-gen .n { font-size: 12px; color: var(--carbon-muted); margin-top: 5px; }
.hero-gen .now { display: flex; gap: 10px; align-items: center; padding-left: 14px; border-left: 1px solid var(--carbon-line); min-width: 0; }
.hero-gen .now svg { width: 54px; height: 54px; flex: none; }
.hero-gen .now svg path { fill: none; stroke: var(--brand-2); stroke-width: 6; stroke-linejoin: round; }
.hero-gen .now .t { font: 700 18px/1.05 var(--font-display); text-transform: uppercase; letter-spacing: .02em; }
.hero-gen .now .p { font-size: 12px; color: var(--carbon-muted); margin-top: 3px; }
.hero-stats { display: grid; grid-template-columns: 1fr 1fr; }
.hstat { padding: 12px 16px; border-top: 1px solid var(--carbon-line); min-width: 0; }
.hstat:nth-child(even) { border-left: 1px solid var(--carbon-line); }
.hstat.wide { grid-column: 1 / -1; }
.hstat .v { font: 800 30px/1 var(--font-display); margin-top: 6px; font-variant-numeric: tabular-nums; }
.hstat .v small { font-size: 16px; font-weight: 700; color: var(--carbon-muted); margin-left: 2px; }
.hstat .n { font-size: 12px; color: var(--carbon-muted); margin-top: 5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hstat.test .k { color: var(--brand-2); }
.hstat.link { cursor: pointer; }
.hstat.link:active { background: var(--carbon-2); }
.hstat .meter { height: 4px; background: var(--carbon-3); border-radius: 2px; margin-top: 8px; overflow: hidden; }
.hstat .meter i { display: block; height: 100%; background: var(--brand); border-radius: 2px; }

/* ---------------------------------------------------------- charts */
#metricSub { margin: 10px 0 8px; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12.5px; color: var(--text-secondary); margin-bottom: 10px; }
.legend .key { display: inline-flex; align-items: center; gap: 6px; }
.legend .line { width: 18px; height: 2px; border-radius: 1px; display: inline-block; }
.legend .line.dashed { background: none !important; border-top: 2px dashed var(--series-2); height: 0; }
.multiples { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 10px; }
.mini-top { grid-column: 1 / -1; display: grid; gap: 10px; }
.mini { border-radius: 9px; padding: 11px 11px 4px; background: var(--surface-2); position: relative; overflow: hidden; border-top: 3px solid var(--surface-3); }
.mini > * { position: relative; }
.mini .ghost { position: absolute; right: -6px; top: 4px; width: 100px; height: 100px; opacity: .55; pointer-events: none; }
.mini .ghost path { fill: none; stroke: var(--surface-3); stroke-width: 7; stroke-linejoin: round; }
.mini .t { display: flex; justify-content: space-between; align-items: flex-start; gap: 6px; }
.mini .name { font: 700 16px/1.1 var(--font-display); text-transform: uppercase; letter-spacing: .03em; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.mini .meta { font-size: 11.5px; color: var(--text-muted); margin-top: 2px; }
.mini .last { text-align: right; flex: none; }
.mini .last b { font: 800 21px/1 var(--font-display); font-variant-numeric: tabular-nums; display: block; }
.mini .last span { font-size: 11px; color: var(--text-muted); }
.mini.now { border-top-color: var(--brand); }
.mini.holdout { background: var(--carbon); color: var(--carbon-text); border-top-color: var(--brand-2); }
.mini.holdout .meta, .mini.holdout .last span { color: var(--carbon-muted); }
.mini.holdout .ghost path { stroke: var(--carbon-3); }
.mini.avg { border-top-color: var(--series-1); }
.mini svg.chart { display: block; width: 100%; height: 112px; overflow: visible; margin-top: 6px; }
.mini svg.chart text { font-family: var(--font-mono); }
.mini .empty { height: 112px; display: grid; place-items: center; color: var(--text-muted); font-size: 12.5px; margin-top: 6px; }
.tooltip {
  position: fixed; z-index: 20; pointer-events: none; background: var(--carbon); color: var(--carbon-text);
  border-radius: 8px; padding: 9px 11px; font-size: 12.5px; box-shadow: 0 6px 20px rgba(0,0,0,.3); min-width: 170px; max-width: calc(100vw - 16px);
}
.tooltip .row { display: flex; justify-content: space-between; gap: 12px; font-variant-numeric: tabular-nums; }
.tooltip .row span:first-child { color: var(--carbon-muted); display: inline-flex; align-items: center; gap: 5px; }
.tooltip .h { font: 700 14px/1.2 var(--font-display); text-transform: uppercase; letter-spacing: .03em; margin-bottom: 4px; }
.tooltip .click.off { color: var(--carbon-muted); }
.tooltip .click { margin-top: 6px; padding-top: 5px; border-top: 1px solid var(--carbon-line); color: var(--brand-2); font: 700 12.5px/1.2 var(--font-display); text-transform: uppercase; letter-spacing: .05em; }

/* ---------------------------------------------------------- milestones */
.milestones { list-style: none; margin: 0; padding: 0; }
.milestones li { display: grid; grid-template-columns: 58px minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--grid); }
.milestones li:last-child { border-bottom: 0; }
.milestones li.empty-note, .milestones li.ms-divider { display: block; }
.milestones .g { font: italic 800 14px/1 var(--font-display); text-transform: uppercase; background: var(--surface-2); padding: 6px 4px 5px; border-radius: 3px; text-align: center; }
.milestones .txt { font-weight: 600; font-size: 14px; }
.milestones .txt .sub { font-weight: 400; font-size: 12.5px; }
.milestones .who { color: var(--text-secondary); font-size: 12.5px; display: flex; gap: 7px; align-items: center; margin-top: 4px; font-weight: 400; flex-wrap: wrap; }
.milestones .watch { width: 38px; height: 38px; border-radius: 50%; border: 0; background: var(--surface-2); color: var(--text-primary); cursor: pointer; font-size: 12px; }
.milestones .watch:active { background: var(--carbon); color: var(--carbon-text); }
.milestones li.todo .g { font-size: 12px; color: var(--text-muted); background: transparent; border: 1px dashed var(--axis); }
.milestones li.todo .txt { color: var(--text-muted); font-weight: 500; }
.milestones .tag { font: 700 10.5px/1 var(--font-display); text-transform: uppercase; letter-spacing: .06em; color: var(--text-secondary); background: var(--surface-3); padding: 3px 5px; border-radius: 3px; margin-left: 4px; vertical-align: 1px; }
.milestones li.ms-divider { padding: 16px 0 6px; font: 700 12px/1 var(--font-display); text-transform: uppercase; letter-spacing: .08em; color: var(--text-muted); }
.ms-count { color: var(--text-muted); font-size: 13px; }

/* ---------------------------------------------------------- watch: one screen, no page scroll */
body.watching { overflow: hidden; }
body.watching main { padding: 8px 8px 0; max-width: none; }
.tabpage.watch.active { display: flex; flex-direction: column; gap: 6px; height: var(--watch-h, 70vh); }
select {
  font: 500 15px var(--font-body); padding: 6px 8px; border-radius: 9px; border: 1px solid var(--border);
  background: var(--surface-1); color: var(--text-primary); min-height: 36px;
}
.icon-btn {
  width: 40px; height: 44px; border: 0; border-radius: 10px; background: var(--surface-1); color: var(--text-primary);
  display: grid; place-items: center; flex: none; box-shadow: var(--shadow); cursor: pointer; padding: 0;
}
.icon-btn:disabled { opacity: .3; }
.icon-btn.small { width: 34px; height: 32px; box-shadow: none; background: var(--surface-2); border-radius: 8px; }
.icon-btn.busy { width: auto; padding: 0 8px; background: var(--carbon); color: var(--carbon-text); font: 700 12px/1 var(--font-display); font-variant-numeric: tabular-nums; }
.w-head { display: flex; align-items: center; gap: 6px; flex: none; }
.race-title {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 9px; height: 44px; padding: 0 10px 0 6px;
  border: 0; border-radius: 10px; background: var(--surface-1); box-shadow: var(--shadow); color: var(--text-primary);
  text-align: left; cursor: pointer; font-family: inherit;
}
.gen-tag { font: italic 800 15px/1 var(--font-display); text-transform: uppercase; white-space: nowrap; background: var(--brand); color: #fff; padding: 6px 8px 5px; border-radius: 3px; transform: skewX(-10deg); flex: none; }
.gen-tag.test { background: var(--carbon); }
:root[data-theme="dark"] .gen-tag.test { box-shadow: inset 0 0 0 1px var(--carbon-line); }
.race-title .rt { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.race-title .rt b { font: 700 16px/1.1 var(--font-display); text-transform: uppercase; letter-spacing: .02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.race-title .rt span { font-size: 11.5px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.live-pill { font: italic 800 11px/1 var(--font-display); letter-spacing: .08em; background: var(--brand); color: #fff; padding: 3px 5px 2px; border-radius: 2px; flex: none; }
.chev { color: var(--text-muted); flex: none; }

.w-body { flex: 1; min-height: 0; display: flex; gap: 6px; }
.w-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; position: relative; }
.w-map { flex: 0 0 43%; display: flex; flex-direction: column; min-height: 0; }
.canvas-wrap { position: relative; flex: 1; min-height: 0; border-radius: 10px; overflow: hidden; background: var(--map-bg); }
#raceCanvas { display: block; width: 100%; height: 100%; touch-action: none; }
.cam #btn3d { margin-left: 6px; }
.cam { position: absolute; left: 6px; top: 6px; background: color-mix(in srgb, var(--surface-1) 88%, transparent); box-shadow: var(--shadow); }
.ticker { position: absolute; left: 6px; bottom: 6px; display: flex; flex-direction: column; align-items: flex-start; gap: 3px; pointer-events: none; }
.ticker div { background: rgba(12, 14, 18, .88); color: #f4f4f2; border-radius: 3px; padding: 3px 8px 3px 0; font-size: 12px; display: flex; gap: 6px; align-items: center; overflow: hidden; }
.ticker div .bar { width: 4px; align-self: stretch; background: var(--tc); }
.ticker div b { font: italic 800 13px/1 var(--font-display); }
.transport { flex: none; display: flex; align-items: center; gap: 8px; padding-top: 6px; }
.btn.play { width: 36px; height: 36px; min-height: 0; padding: 0; border-radius: 50%; background: var(--carbon); color: var(--carbon-text); border: 0; font-size: 13px; display: grid; place-items: center; flex: none; }
.transport input[type=range] { flex: 1; min-width: 0; accent-color: var(--brand); height: 26px; margin: 0; }
#timeLabel { font-size: 12.5px; min-width: 44px; text-align: right; }
.transport select { min-height: 32px; padding: 4px 6px; font-size: 14px; }

.w-panel { flex: 1; min-height: 0; display: flex; flex-direction: column; background: var(--surface-1); border-radius: 10px; box-shadow: var(--shadow); padding: 6px 6px 4px 8px; position: relative; }
/* portrait: tabs + buttons on top, the driver on its own line below; landscape: one line */
.p-head { display: flex; align-items: center; gap: 6px; flex: none; flex-wrap: wrap; }
.p-head .drv { order: 5; flex: 1 1 100%; min-width: 0; display: flex; align-items: center; gap: 7px; padding: 2px 0 0 1px; }
.p-head .drv .tno { min-width: 22px; height: 19px; font-size: 13px; }
.p-head .drv b { font: 700 16px/1 var(--font-display); text-transform: uppercase; letter-spacing: .02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.p-head .drv .arch { font: 10.5px/1 var(--font-mono); color: var(--text-muted); white-space: nowrap; flex: none; }
.p-tabs { flex: none; margin-right: auto; }
@media (orientation: landscape) and (max-height: 600px) and (pointer: coarse) {
  .p-head { flex-wrap: nowrap; }
  .p-head .drv { order: 0; flex: 1 1 auto; padding: 0; }
  .p-tabs { margin-right: 0; }
}
.p-tabs button { padding: 6px 8px; min-height: 30px; font-size: 12.5px; }
.p-body { flex: 1; min-height: 0; position: relative; margin-top: 4px; }
.p-pane { position: absolute; inset: 0; display: none; }
.p-pane.on { display: block; }
.p-pane canvas { display: block; width: 100%; height: 100%; }
.p-pane[data-pane=pos] { overflow-y: auto; }
#btnExpand .i-shrink { display: none; }
.w-hint { display: none; }
.video-note { position: absolute; left: 8px; right: 8px; bottom: 6px; z-index: 4; font-size: 12.5px; color: var(--carbon-text); background: var(--carbon); border-radius: 8px; padding: 8px 10px; }
.video-note.err { background: var(--critical); color: #fff; }

.rail { flex: 0 0 58px; min-height: 0; }
.rail canvas { display: block; width: 100%; height: 100%; cursor: pointer; touch-action: manipulation; }

/* positions list (Pos tab) */
.standings { list-style: none; margin: 0; padding: 4px 0; background: var(--carbon); border-radius: 8px; color: #f4f4f2; }
.standings:empty { display: none; }
.standings li { display: grid; grid-template-columns: 18px 4px minmax(0, 1fr) auto; gap: 8px; align-items: center; padding: 0 10px; height: 32px; cursor: pointer; font: 700 15px/1 var(--font-display); }
.standings li.sel { background: rgba(255,255,255,.14); }
.standings li .pos { text-align: right; color: #c9cdd3; font-weight: 800; }
.standings li .bar { width: 4px; height: 17px; background: var(--tc); border-radius: 1px; }
.standings li .nm { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-transform: uppercase; letter-spacing: .02em; }
.standings li .nm b { font-style: italic; font-weight: 800; margin-right: 5px; color: var(--tc); filter: brightness(1.25); }
.standings li .val { font: 500 12px/1 var(--font-mono); color: #d9dce0; text-align: right; }
.standings li .flag { font: 800 11px/1 var(--font-display); letter-spacing: .05em; padding: 3px 5px 2px; border-radius: 2px; }
.standings li .flag.fin { background: #f4f4f2; color: #111; }
.standings li .flag.out { background: var(--critical); color: #fff; }
.standings li .flag.dnf { background: #4b5159; color: #fff; }
.standings li .flag.stall { background: var(--warning); color: #111; }
.standings li.gone { color: #8b9098; }

/* brain expanded: the map shrinks to a thumbnail in the corner (tap it to go back) */
.watch.brain-full .w-map { flex: none; }
.watch.brain-full .canvas-wrap {
  position: absolute; right: 8px; bottom: 8px; width: 112px; height: 112px; z-index: 3; flex: none;
  box-shadow: 0 4px 16px rgba(0,0,0,.35); border: 2px solid var(--axis);
}
.watch.brain-full .cam, .watch.brain-full .ticker { display: none; }
.watch.brain-full #btnExpand .i-grow { display: none; }
.watch.brain-full #btnExpand .i-shrink { display: block; }

/* landscape: full screen, map beside the brain */
@media (orientation: landscape) and (max-height: 600px) and (pointer: coarse) {
  body.watching .top, body.watching .tabbar { display: none; }
  body.watching { padding-bottom: 0; }
  body.watching main { padding: max(6px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) 6px max(8px, env(safe-area-inset-left)); }
  .w-head { display: none; }
  .w-main { flex-direction: row; }
  .w-map { flex: 1 1 44%; }
  .w-panel { flex: 1 1 56%; }
  .watch.brain-full .w-map { flex: 0 0 auto; width: 0; }
  .watch.brain-full .w-map .transport { position: absolute; left: 0; bottom: 0; width: 160px; z-index: 3; }
}

/* ---------------------------------------------------------- race list (bottom sheet) */
.sheet { position: fixed; inset: 0; z-index: 30; }
.sheet[hidden] { display: none; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .45); animation: fadein .18s ease-out; }
.sheet-panel {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 84vh; max-width: 640px; margin: 0 auto;
  background: var(--surface-1); border-radius: 16px 16px 0 0; display: flex; flex-direction: column;
  padding: 4px 12px calc(10px + var(--safe-b)); animation: sheetup .22s ease-out; box-shadow: 0 -8px 30px rgba(0,0,0,.25);
}
@keyframes fadein { from { opacity: 0; } }
@keyframes sheetup { from { transform: translateY(40%); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .sheet-backdrop, .sheet-panel { animation: none; } }
.sheet-grip { width: 40px; height: 5px; border-radius: 3px; background: var(--axis); margin: 6px auto 10px; cursor: pointer; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; gap: 10px; }
.live-toggle {
  display: inline-flex; align-items: center; gap: 7px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text-secondary);
  font: 700 13px/1 var(--font-display); text-transform: uppercase; letter-spacing: .06em; padding: 8px 12px; border-radius: 16px; cursor: pointer;
}
.live-toggle .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--axis); }
.live-toggle[aria-pressed="true"] { background: var(--brand); border-color: var(--brand); color: #fff; }
.live-toggle[aria-pressed="true"] .dot { background: #fff; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 10px; scrollbar-width: none; flex: none; }
.chips::-webkit-scrollbar { display: none; }
.chips button {
  font: 700 13px/1 var(--font-display); text-transform: uppercase; letter-spacing: .04em; white-space: nowrap;
  padding: 8px 11px; border-radius: 16px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text-secondary); cursor: pointer;
}
.chips button.on { background: var(--carbon); border-color: var(--carbon); color: var(--carbon-text); }
.race-list { list-style: none; margin: 0 -4px; padding: 0 4px; overflow-y: auto; flex: 1; min-height: 0; overscroll-behavior: contain; }
.race-list li { display: grid; grid-template-columns: 44px minmax(0, 1fr) auto; gap: 11px; align-items: center; padding: 8px 8px 8px 10px; border-radius: 10px; cursor: pointer; position: relative; }
.race-list li::before { content: ""; position: absolute; left: 2px; top: 10px; bottom: 10px; width: 3px; border-radius: 2px; background: var(--wc, transparent); }
.race-list li:active { background: var(--surface-2); }
.race-list li.on { background: var(--carbon); color: var(--carbon-text); }
.race-list li.on .l2, .race-list li.on .res span { color: var(--carbon-muted); }
.race-list .thumb { width: 44px; height: 44px; background: var(--surface-2); border-radius: 8px; padding: 5px; }
.race-list li.on .thumb { background: var(--carbon-3); }
.race-list .thumb path { fill: none; stroke: var(--text-secondary); stroke-width: 9; stroke-linejoin: round; }
.race-list li.on .thumb path { stroke: var(--carbon-text); }
.race-list .l1 { font: italic 800 16px/1.1 var(--font-display); text-transform: uppercase; display: flex; gap: 6px; align-items: center; }
.race-list .l2 { font-size: 12.5px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.race-list .res { text-align: right; font: 700 15px/1.1 var(--font-display); font-variant-numeric: tabular-nums; }
.race-list .res span { display: block; font: 400 11px/1.3 var(--font-body); color: var(--text-muted); }
.race-list .star { color: var(--warning); font-style: normal; }
.race-list .empty-note { display: block; padding: 18px 6px; cursor: default; }

/* ---------------------------------------------------------- teams */
/* team standings: one row per team */
.team-grid { display: grid; gap: 8px; margin-bottom: 12px; }
.teams-note { color: var(--text-muted); font-size: 13px; margin: 0 2px 2px; }
.trow { position: relative; background: var(--surface-1); box-shadow: var(--shadow); border-radius: 10px; overflow: hidden; }
.trow::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--tc); }
.trow {
  display: grid; grid-template-columns: 30px auto minmax(0, 1fr) auto auto;
  grid-template-areas: "pos tile who who pts" ". net net form form" ". stat stat stat stat" ". set set set set";
  align-items: center; column-gap: 10px; row-gap: 9px; padding: 10px 14px 12px 12px;
}
.trow .tpos { grid-area: pos; text-align: center; font: italic 800 26px/1 var(--font-display); font-variant-numeric: tabular-nums; }
.trow .tpos small { font-size: 15px; margin-right: 1px; color: var(--text-muted); }
.trow.unranked .tpos { color: var(--text-muted); }
.trow .tno { grid-area: tile; min-width: 26px; height: 23px; font-size: 15px; transform: skewX(-8deg); }
.trow .who { grid-area: who; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.trow .nm { font: italic 800 19px/1.05 var(--font-display); text-transform: uppercase; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.trow .who .sub { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.trow .who .badge { margin: 0 6px 0 0; vertical-align: 1px; }
/* the on/off switch next to a team's name: off = it sits out the races (keeping its drivers) */
.trow .nmrow { display: flex; align-items: center; gap: 10px; min-width: 0; }
.trow .nmrow .nm { min-width: 0; }
.trow .tsw { flex: none; display: flex; padding: 4px; margin: -4px -4px -4px auto; cursor: pointer; }
.trow .tsw input {
  appearance: none; -webkit-appearance: none; width: 36px; height: 21px; border-radius: 11px; margin: 0;
  background: var(--surface-3); position: relative; cursor: pointer; transition: background .15s;
}
.trow .tsw input::after { content: ""; position: absolute; left: 2px; top: 2px; width: 17px; height: 17px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.3); transition: transform .15s; }
.trow .tsw input:checked { background: var(--good); }
.trow .tsw input:checked::after { transform: translateX(15px); }
.trow .tsw input:disabled { cursor: not-allowed; opacity: .55; }
.trow .tsw input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.badge.offb { background: var(--surface-3); color: var(--text-secondary); }
.trow.off::before { background: var(--axis); }
.trow.off > :not(.who):not(.tfit), .trow.off .who .nm, .trow.off .who .sub > :not(.offb) { opacity: .45; }
.trow.off .who .sub { color: var(--text-muted); }
.trow .tedit {
  font: 700 11px/1 var(--font-display); text-transform: uppercase; letter-spacing: .06em; color: var(--accent);
  background: none; border: 0; padding: 4px 6px; margin: -4px 4px -4px -2px; cursor: pointer;
}
.trow .tpts { grid-area: pts; text-align: right; min-width: 42px; }
.trow .tpts b { display: block; font: 800 25px/1 var(--font-display); font-variant-numeric: tabular-nums; }
.trow .tpts span { font: 700 10.5px/1 var(--font-display); color: var(--text-muted); text-transform: uppercase; letter-spacing: .08em; }
/* form: the last 20 Grand Prix, oldest first; bar height = points scored */
.trow .form {
  grid-area: form; justify-self: end; display: grid; grid-template-columns: repeat(20, 6px); align-items: stretch;
  height: 28px; border-bottom: 1px solid var(--grid);
}
.trow .form .slot { display: flex; align-items: flex-end; justify-content: center; border-radius: 2px 2px 0 0; }
.trow .form .slot.hit { cursor: pointer; }
.trow .form .slot.on { background: color-mix(in srgb, var(--tc) 22%, transparent); }
.trow .form i { display: block; width: 4px; background: var(--tc); border-radius: 1px 1px 0 0; }
.trow .form i.none { height: 2px; background: var(--grid); border-radius: 1px; }
.trow .form i.dnf { height: 3px; background: var(--axis); border-radius: 1px; }
.trow .form .slot.on i.dnf { background: var(--text-muted); }
.trow.unranked .form { visibility: hidden; }
.trow .tnet { grid-area: net; display: flex; align-items: center; gap: 8px; min-width: 0; }
.trow .tnet .net { display: block; flex: none; width: 86px; height: 36px; background: var(--surface-2); border-radius: 5px; padding: 1px 0; }
.trow .tnet .arch { min-width: 0; font-size: 11px; line-height: 1.3; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.trow .tstat { grid-area: stat; display: grid; grid-template-columns: repeat(5, minmax(44px, auto)); gap: 2px 4px; justify-content: start; }
.trow .tstat > div { position: relative; isolation: isolate; padding: 4px 6px 3px; border-radius: 5px; }
/* shade: green, stronger the better this team's number is among all the teams' */
.trow .tstat > .sc::before {
  content: ""; position: absolute; inset: 0; z-index: -1; border-radius: inherit;
  background: var(--good); opacity: calc(0.05 + var(--g) * 0.42);
}
.trow .tstat .k { display: block; font: 700 10px/1 var(--font-display); text-transform: uppercase; letter-spacing: .07em; color: var(--text-muted); }
.trow .tstat b { display: block; font: 800 16px/1.15 var(--font-display); font-variant-numeric: tabular-nums; white-space: nowrap; margin-top: 2px; }
.trow .tset { grid-area: set; display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 1px 10px; font-size: 11.5px; line-height: 1.35; color: var(--text-secondary); }
.trow .tset > span:nth-child(odd) { color: var(--text-muted); }
.trow .tset > span:nth-child(even) { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* click a row: it opens to show the team's fitness score by generation */
.trow[data-team] { cursor: pointer; }
.trow[data-team]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.trow[data-team]::after {
  content: ""; position: absolute; left: 50%; bottom: 3px; width: 6px; height: 6px; margin-left: -3px;
  border: solid var(--text-muted); border-width: 0 1.5px 1.5px 0; transform: rotate(45deg); opacity: .55;
}
.trow.open::after { transform: rotate(225deg); bottom: 1px; }
@media (hover: hover) { .trow[data-team]:hover { background: color-mix(in srgb, var(--surface-1) 85%, var(--surface-2)); } }
.trow .tfit { grid-column: 1 / -1; cursor: default; border-top: 1px solid var(--grid); padding-top: 9px; margin-top: 2px; min-width: 0; }
.trow .tfit-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 14px; }
.trow .tfit-head .k { font: 700 11px/1 var(--font-display); text-transform: uppercase; letter-spacing: .07em; color: var(--text-muted); }
.trow .tfit-head .legend { margin: 0; font-size: 11.5px; }
.trow .tfit-note { font-size: 11.5px; color: var(--text-muted); margin: 4px 0 2px; }
.trow .tfit .empty { padding: 18px 0; font-size: 13px; color: var(--text-muted); }
/* the team editor's preview card */
.team-top { display: flex; gap: 11px; align-items: center; padding: 12px 14px 8px; }
.team-top h3 { font-size: 20px; line-height: 1.05; }
.team-top .arch { font-family: var(--font-mono); font-size: 11.5px; color: var(--text-muted); margin-top: 3px; }
.badge.yours { background: var(--tc); color: var(--tt); vertical-align: 2px; margin-left: 4px; font-style: normal; }
.teams-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.team-foot { display: flex; justify-content: flex-end; padding: 0 14px 12px; margin-top: -4px; }
.team-new {
  display: flex; align-items: center; gap: 14px; text-align: left; width: 100%;
  padding: 14px 16px; border-radius: 10px; border: 2px dashed var(--axis); background: transparent;
  color: var(--text-primary); cursor: pointer; font: inherit;
}
.team-new:active { background: var(--surface-1); }
.team-new:disabled { cursor: default; opacity: .65; }
.team-new .plus { display: grid; place-items: center; flex: none; width: 40px; height: 40px; border-radius: 50%; background: var(--brand); color: #fff; font: 700 28px/1 var(--font-display); }
.team-new:disabled .plus { background: var(--surface-3); color: var(--text-muted); }
.team-new .txt { display: flex; flex-direction: column; gap: 3px; }
.team-new b { font: 700 18px/1.1 var(--font-display); text-transform: uppercase; letter-spacing: .03em; }
.team-new .sub { font-size: 12.5px; color: var(--text-muted); }
@media (min-width: 700px) {
  .trow {
    grid-template-columns: 38px 30px minmax(110px, 1fr) 210px 120px 56px;
    grid-template-areas: "pos tile who net form pts" ". . stat stat stat stat" ". . set set set set";
    column-gap: 14px; padding: 10px 18px 12px 14px;
  }
  .trow .tpos { font-size: 30px; }
  .trow .form { height: 34px; }
  .trow .tnet .net { width: 110px; height: 40px; }
}
/* a smaller laptop: stats on the first line, the settings as one strip under it */
@media (min-width: 1100px) {
  .trow {
    grid-template-columns: 38px 30px minmax(150px, 1fr) 215px 285px 120px 56px;
    grid-template-areas: "pos tile who net stat form pts" ". . set set set set set"; row-gap: 6px;
  }
  .trow .tstat { grid-template-columns: repeat(5, 1fr); }
  .trow .tnet .net { width: 116px; height: 42px; }
  .trow .tset { display: flex; flex-wrap: wrap; gap: 0 6px; }
  .trow .tset > span:nth-child(even) { margin-right: 16px; }
}
/* a big screen: one line per team, every column a fixed width so they line up row to row */
@media (min-width: 1420px) {
  .trow {
    grid-template-columns: 40px 30px minmax(150px, 1fr) 225px 285px 290px 120px 56px;
    grid-template-areas: "pos tile who net stat set form pts"; column-gap: 18px; row-gap: 0; padding: 9px 18px 9px 14px;
  }
  .trow .tnet .net { width: 124px; height: 44px; }
  .trow .tstat { grid-template-columns: repeat(5, 1fr); }
  .trow .tset { display: grid; gap: 1px 10px; }
  .trow .tset > span:nth-child(even) { margin-right: 0; }
}

/* ---------------------------------------------------------- team editor (bottom sheet) */
.sheet-panel.team-editor { max-height: 92vh; max-height: 92dvh; }
.te-body { overflow-y: auto; flex: 1; min-height: 0; overscroll-behavior: contain; margin: 0 -12px; padding: 0 12px 6px; }
.te-preview { background: var(--surface-2); border-radius: 12px; overflow: hidden; border-top: 5px solid var(--tc); }
.te-preview .team-top { padding: 10px 12px 4px; }
.te-preview h3 { font-size: 20px; line-height: 1.05; overflow-wrap: anywhere; }
.te-preview .arch { font-family: var(--font-mono); font-size: 11.5px; color: var(--text-muted); margin-top: 3px; }
.te-preview .net { display: block; width: 100%; height: 66px; padding: 0 0 4px; }
.te-sec { padding: 14px 0 4px; border-bottom: 1px solid var(--grid); }
.te-sec:last-child { border-bottom: 0; }
.te-sec > h3 { font-size: 16px; display: flex; align-items: center; gap: 8px; }
.te-sec > h3::before { content: ""; width: 4px; height: 14px; background: var(--brand); transform: skewX(-14deg); }
.te-sec > .sub { margin: 4px 0 8px; }
.te-text {
  width: 100%; margin-top: 8px; padding: 10px 12px; border-radius: 9px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text-primary); font: 600 16px/1.2 var(--font-body);
}
.te-text:focus { outline: 2px solid var(--accent); outline-offset: 0; }
.te-colors { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 6px; }
.te-sw {
  --c: #888; width: 34px; height: 34px; border-radius: 50%; background: var(--c); border: 0; padding: 0; cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.12); position: relative;
}
.te-sw.on { box-shadow: 0 0 0 2px var(--surface-1), 0 0 0 4px var(--text-primary); }
.te-sw.pick { background: conic-gradient(#ef233c, #ffd60a, #06d6a0, #3a86ff, #8338ec, #ef233c); overflow: hidden; display: inline-block; }
.te-sw.pick.on { background: var(--c); }
.te-sw.pick input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; border: 0; padding: 0; }
.chips.wrap { flex-wrap: wrap; overflow: visible; padding-bottom: 4px; }
.chips button .dot { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 6px; vertical-align: 0; }
.te-row { display: grid; grid-template-columns: 1fr; gap: 6px; padding: 8px 0; }
.te-row:has(.stepper) { grid-template-columns: 1fr auto; align-items: center; gap: 12px; }
.te-lab { display: flex; flex-direction: column; min-width: 0; }
.te-lab b { font-size: 14px; display: flex; justify-content: space-between; gap: 8px; }
.te-lab .sub { margin: 1px 0 0; font-size: 12px; }
.te-val { font-weight: 700; color: var(--accent); }
.te-row input[type="range"] { width: 100%; accent-color: var(--accent); height: 28px; margin: 0; }
.te-layer { display: grid; grid-template-columns: 1fr auto auto; gap: 10px; align-items: center; padding: 6px 0; }
.te-del:disabled { visibility: hidden; }
.te-add { margin-top: 6px; }
.te-switch { padding: 8px 0; }
.te-switch b { font-size: 15px; }
#teFit { margin: 4px 0 8px; }
#teFit[hidden] { display: none; }
.te-note { margin: 8px 0 0; font-size: 12.5px; flex: none; }
.te-note:empty { display: none; }
.te-foot { display: flex; align-items: center; gap: 8px; padding-top: 10px; flex: none; }
.te-foot .btn.danger { margin-top: 0; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }

.rule { border-left: 3px solid var(--brand); padding: 2px 0 2px 12px; margin-top: 14px; }
.rule-k { font: 700 15px/1.1 var(--font-display); text-transform: uppercase; letter-spacing: .05em; }
.rule p { margin: 5px 0 0; font-size: 13.5px; color: var(--text-secondary); }

/* ---------------------------------------------------------- settings */
.switch-row { display: flex; gap: 14px; align-items: center; justify-content: space-between; cursor: pointer; }
.switch-row > span { display: flex; flex-direction: column; }
.switch-row b { font: 700 16px/1.2 var(--font-display); text-transform: uppercase; letter-spacing: .03em; }
.switch-row input {
  appearance: none; -webkit-appearance: none; flex: none; width: 50px; height: 30px; border-radius: 15px;
  background: var(--surface-3); position: relative; cursor: pointer; transition: background .15s; margin: 0;
}
.switch-row input::after { content: ""; position: absolute; left: 2px; top: 2px; width: 26px; height: 26px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: transform .15s; }
.switch-row input:checked { background: var(--good); }
.switch-row input:checked::after { transform: translateX(20px); }
.danger-zone h2::before { background: var(--critical) !important; }

@media (min-width: 700px) {
  main { padding: 16px 20px 24px; }
  .hero-stats { grid-template-columns: repeat(3, 1fr); }
  .hstat:nth-child(even) { border-left: 0; }
  .hstat:not(:nth-child(3n + 1)) { border-left: 1px solid var(--carbon-line); }
  .hstat.wide { grid-column: auto; }
}
@media (max-width: 360px) {
  h1 { font-size: 18px; }
  .hero-gen .v { font-size: 44px; }
}

/* ========================================================== wide screens (a computer) */
@media (min-width: 1100px) {
  body { padding-bottom: 0; }
  main { max-width: 1520px; padding: 16px 24px 28px; }

  /* the tabs sit in the header, between the name and the Start button */
  .top-row { min-height: 54px; padding: 8px 24px 2px; }
  .statusbar { padding: 0 24px 9px; }
  .tabbar {
    top: var(--safe-t); bottom: auto; left: 50%; right: auto; transform: translateX(-50%); z-index: 11;
    display: flex; gap: 4px; background: none; backdrop-filter: none; -webkit-backdrop-filter: none; border: 0; padding: 0;
  }
  .tab { height: 54px; flex-direction: row; gap: 8px; padding: 0 16px; font-size: 14.5px; letter-spacing: .08em; }
  .tab svg { width: 19px; height: 19px; }
  .tab:hover { color: var(--carbon-text); }
  .tab.active::before { top: auto; bottom: 4px; left: 16px; right: 16px; }

  /* progress: hero across the top, charts on the left, milestones on the right */
  #tab-progress.active { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 0 14px; align-items: start; }
  #tab-progress .hero { grid-column: 1 / -1; display: flex; }
  .hero-gen { flex: none; width: 400px; }
  .hero-stats { flex: 1; grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .hstat, .hstat:nth-child(even), .hstat:not(:nth-child(3n + 1)) { border-top: 0; border-left: 1px solid var(--carbon-line); }
  .hstat.link:hover { background: var(--carbon-2); }
  #tab-progress > .card:last-child {
    position: sticky; top: calc(var(--top-h, 90px) + 12px); max-height: calc(100vh - var(--top-h, 90px) - 28px);
    display: flex; flex-direction: column;
  }
  #tab-progress > .card:last-child .milestones { overflow-y: auto; min-height: 0; margin-right: -8px; padding-right: 8px; }
  .mini-top { grid-template-columns: 1fr 1fr; }
  .milestones .watch:hover { background: var(--carbon); color: var(--carbon-text); }

  /* teams and settings */
  .explain { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 28px; }
  .explain > h2 { grid-column: 1 / -1; }
  #tab-settings.active { columns: 2; column-gap: 12px; max-width: 1100px; margin: 0 auto; }
  #tab-settings .card { break-inside: avoid; }
  .team-new:hover { background: var(--surface-1); }

  /* sheets become centered dialogs */
  .sheet-panel { top: 7vh; bottom: auto; max-height: 86vh; border-radius: 16px; padding: 14px 16px 14px; animation-name: popin; }
  .sheet-panel.team-editor { max-height: 86vh; }
  .sheet-grip { display: none; }
  .race-list li:hover { background: var(--surface-2); }
  .race-list li.on:hover { background: var(--carbon); }

  /* watch: map (with a timing tower) | inspector with every panel | all the drivers' networks */
  body.watching main { padding: 10px 16px 0; max-width: none; }
  .w-body { gap: 10px; }
  .w-main { flex-direction: row; gap: 10px; }
  .w-map { flex: 1 1 auto; min-width: 0; }
  .w-panel { flex: 0 0 clamp(470px, 35vw, 640px); padding: 8px 8px 6px 10px; }
  .rail { flex: 0 0 66px; }
  .w-hint { display: block; flex: none; margin: 6px 2px 0; font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .p-head { flex-wrap: nowrap; }
  .p-head .drv { order: 0; flex: 1 1 auto; padding: 0; }
  .p-head .drv b { font-size: 18px; }
  .p-tabs { display: none; }
  .p-body { display: grid; grid-template-columns: 320px minmax(0, 1fr); grid-template-rows: 172px minmax(0, 1fr); gap: 8px 6px; margin-top: 6px; }
  .p-body .p-pane { position: relative; inset: auto; display: block; min-height: 0; }
  .p-pane[data-pane=gauges] { grid-area: 1 / 1; }
  .p-pane[data-pane=sensors] { grid-area: 1 / 2; }
  .p-pane[data-pane=nn] { grid-area: 2 / 1 / 3 / 3; border-top: 1px solid var(--grid); padding-top: 6px; }
  .tower { position: absolute; left: 8px; top: 48px; right: auto; bottom: auto; width: 222px; max-height: calc(100% - 140px); overflow-y: auto; z-index: 2; display: block; border-radius: 8px; box-shadow: 0 4px 14px rgba(0,0,0,.25); }
  .tower .standings li:hover { background: rgba(255,255,255,.08); }
  .tower .standings li.sel { background: rgba(255,255,255,.14); }
  .watch.brain-full .tower { display: none; }
  .watch.brain-full .w-map { flex: 0 0 auto; width: 0; }
  .watch.brain-full .w-map .transport { position: absolute; left: 0; bottom: 0; width: 240px; z-index: 3; }
  .watch.brain-full .w-hint { display: none; }
  .watch.brain-full .w-panel { flex: 1 1 auto; }
  .icon-btn:hover:not(:disabled) { background: var(--surface-2); }
  .race-title:hover { background: var(--surface-2); }
}
@keyframes popin { from { opacity: 0; transform: translateY(14px); } }

/* ---------------------------------------------------------- welcome popup (first visit; Settings -> About) */
.sheet.welcome { display: grid; place-items: center; padding: 16px; }
.sheet.welcome[hidden] { display: none; }
.sheet-panel.welcome-panel {
  position: relative; left: auto; right: auto; bottom: auto; width: 100%; max-width: 560px; max-height: 88vh; max-height: 88dvh;
  border-radius: 14px; padding: 14px 18px 14px; box-shadow: 0 12px 40px rgba(0,0,0,.35); animation: fadein .2s ease-out;
}
.welcome-panel .sheet-head h2 { margin: 0; font: italic 800 22px/1.1 var(--font-display); text-transform: uppercase; letter-spacing: .01em; }
.wc-body { overflow-y: auto; -webkit-overflow-scrolling: touch; padding-right: 4px; font-size: 14.5px; line-height: 1.5; color: var(--text-secondary); }
.wc-body h3 { margin: 14px 0 4px; font: 700 14px/1.2 var(--font-display); text-transform: uppercase; letter-spacing: .07em; color: var(--text-primary); }
.wc-body ul { margin: 0; padding-left: 18px; }
.wc-body li { margin: 5px 0; }
.wc-body b { color: var(--text-primary); }
.wc-lead { margin: 0 0 4px; font-size: 15.5px; color: var(--text-primary); }
.wc-tip { margin: 12px 0 0; padding: 9px 12px; border-left: 3px solid var(--brand); background: var(--surface-2); border-radius: 4px; }
.wc-tip:empty { display: none; }
.welcome-panel .te-foot { display: flex; gap: 8px; padding-top: 12px; }
.welcome-panel .grow { flex: 1; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
@media (prefers-reduced-motion: reduce) { .welcome-panel { animation: none; } }
