:root {
  color-scheme: light;
  --bg: #f4f4f2;
  --surface-1: #fcfcfb;
  --surface-2: #efeeeb;
  --border: #dddcd7;
  --grid: #e6e5e1;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #7a7974;
  --series-1: #2a78d6;   /* steer */
  --series-2: #eb6834;   /* brake */
  --series-3: #1baf7a;   /* gas */
  --band: rgba(42, 120, 214, 0.08);
  --countdown: rgba(120, 120, 110, 0.12);
  --good: #0ca30c;
  --serious: #ec835a;
  --critical: #d03b3b;
  --neutral: #8f8e88;
  --link: #1c5cab;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --bg: #121211;
    --surface-1: #1a1a19;
    --surface-2: #242422;
    --border: #34342f;
    --grid: #2a2a27;
    --text-primary: #f0efec;
    --text-secondary: #c3c2b7;
    --text-muted: #8d8c84;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --band: rgba(57, 135, 229, 0.12);
    --countdown: rgba(200, 200, 190, 0.08);
    --link: #86b6ef;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface-1: #1a1a19; --surface-2: #242422; --border: #34342f; --grid: #2a2a27;
  --text-primary: #f0efec; --text-secondary: #c3c2b7; --text-muted: #8d8c84;
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70;
  --band: rgba(57, 135, 229, 0.12); --countdown: rgba(200, 200, 190, 0.08); --link: #86b6ef;
}

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text-primary);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--text-muted); }
.mono, td.num, .num { font-variant-numeric: tabular-nums; }

.topbar {
  display: flex; align-items: center; gap: 16px; padding: 10px 24px;
  background: var(--surface-1); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 700; color: var(--text-primary); letter-spacing: .02em; }
.crumbs { color: var(--text-secondary); display: flex; gap: 8px; flex-wrap: wrap; }
.crumbs a { color: var(--text-secondary); }
.crumbs > span::before { content: "/"; margin-right: 8px; color: var(--text-muted); }

.page { max-width: 1280px; margin: 0 auto; padding: 24px 24px 64px; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 15px; margin: 0 0 12px; color: var(--text-secondary); font-weight: 600; }
.sub { color: var(--text-secondary); margin-bottom: 20px; }

.card {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px;
  padding: 16px 18px; margin-bottom: 18px;
}
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 860px) { .grid2 { grid-template-columns: 1fr; } }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.tile { background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.tile .label { color: var(--text-secondary); font-size: 12px; }
.tile .value { font-size: 26px; font-weight: 650; font-variant-numeric: tabular-nums; }
.tile .hint { color: var(--text-muted); font-size: 12px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
th { color: var(--text-secondary); font-weight: 600; font-size: 12px; cursor: pointer; user-select: none; }
th.sorted::after { content: " ▾"; }
th.sorted.asc::after { content: " ▴"; }
td.num, th.num { text-align: right; }
td.note { white-space: normal; color: var(--text-secondary); font-size: 12px; min-width: 200px; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--surface-2); }
.table-wrap { overflow-x: auto; }

.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 1px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 600; border: 1px solid currentColor; color: var(--text-primary);
}
.badge i { font-style: normal; display: inline-block; width: 9px; height: 9px; border-radius: 50%; }
.badge.OK i { background: var(--good); }
.badge.SLOW i { background: var(--serious); }
.badge.FAST i { background: var(--critical); }
.badge.NO_DATA i, .badge.ERROR i { background: var(--neutral); }
.badge.OK { border-color: var(--good); }
.badge.SLOW { border-color: var(--serious); }
.badge.FAST { border-color: var(--critical); }
.badge.NO_DATA, .badge.ERROR { border-color: var(--neutral); }

.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.chip {
  border: 1px solid var(--border); background: var(--surface-1); color: var(--text-secondary);
  border-radius: 999px; padding: 3px 11px; cursor: pointer; font: inherit; font-size: 12px;
}
.chip.on { background: var(--text-primary); color: var(--surface-1); border-color: var(--text-primary); }

form.inv { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px 12px; align-items: end; }
form.inv label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-secondary); }
form.inv .wide { grid-column: 1 / -1; }
input, select, button {
  font: inherit; color: var(--text-primary); background: var(--surface-1);
  border: 1px solid var(--border); border-radius: 6px; padding: 6px 9px;
}
button { cursor: pointer; }
button.primary { background: var(--series-1); border-color: var(--series-1); color: #fff; font-weight: 600; }
button:disabled { opacity: .5; cursor: default; }
pre.log {
  background: var(--surface-2); border-radius: 8px; padding: 10px; max-height: 260px; overflow: auto;
  font-size: 12px; margin: 8px 0 0; white-space: pre-wrap;
}

.tooltip {
  position: fixed; pointer-events: none; z-index: 50; background: var(--surface-1); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; font-size: 12px;
  box-shadow: 0 4px 16px rgba(0,0,0,.15); max-width: 320px; font-variant-numeric: tabular-nums;
}
.tooltip b { font-weight: 600; }

svg text { fill: var(--text-muted); font-size: 11px; }
svg .axis line, svg .gridline { stroke: var(--grid); }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12px; color: var(--text-secondary); margin-top: 6px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }

/* run view */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; font-size: 13px; }
.kv dt { color: var(--text-secondary); }
.kv dd { margin: 0; font-variant-numeric: tabular-nums; }
.timingbar { display: flex; height: 22px; border-radius: 4px; overflow: hidden; margin: 10px 0 6px; gap: 2px; }
.timingbar div { height: 100%; }
.verdict-box { border-left: 4px solid var(--neutral); padding: 8px 12px; background: var(--surface-2); border-radius: 0 8px 8px 0; margin-top: 10px; }
.verdict-box.OK { border-color: var(--good); }
.verdict-box.SLOW { border-color: var(--serious); }
.verdict-box.FAST { border-color: var(--critical); }

.player-controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.player-controls input[type=range] { flex: 1; min-width: 200px; padding: 0; }
.timecode { font-size: 20px; font-weight: 650; font-variant-numeric: tabular-nums; min-width: 110px; }
.hud { display: grid; grid-template-columns: 2fr 1fr 1fr 2fr; gap: 12px; margin-bottom: 12px; }
@media (max-width: 860px) { .hud { grid-template-columns: 1fr 1fr; } }
.hud .box { background: var(--surface-2); border-radius: 8px; padding: 8px 12px; }
.hud .box .label { font-size: 11px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .05em; }
.steerbar { position: relative; height: 18px; background: var(--surface-1); border-radius: 4px; margin-top: 6px; overflow: hidden; }
.steerbar .mid { position: absolute; left: 50%; top: 0; bottom: 0; width: 1px; background: var(--text-muted); }
.steerbar .fill { position: absolute; top: 3px; bottom: 3px; background: var(--series-1); border-radius: 3px; }
.pedal { font-size: 18px; font-weight: 700; margin-top: 4px; color: var(--text-muted); }
.pedal.on.gas { color: var(--series-3); }
.pedal.on.brake { color: var(--series-2); }
canvas.timeline { width: 100%; height: 250px; display: block; cursor: crosshair; touch-action: none; }
.kbd { font-size: 11px; color: var(--text-muted); }

/* --- navigation ---------------------------------------------------------------- */
.topbar { flex-wrap: wrap; gap: 8px 20px; }
.mainnav { display: flex; gap: 4px; flex-wrap: wrap; }
.mainnav a { color: var(--text-secondary); padding: 5px 10px; border-radius: 6px; }
.mainnav a:hover { background: var(--surface-2); text-decoration: none; }
.mainnav a.on { color: var(--text-primary); background: var(--surface-2); font-weight: 600; }
#jobsbadge.busy { color: var(--series-1); font-weight: 600; }
.search { margin-left: auto; flex: 0 1 320px; }
.search input { width: 100%; }
.crumbbar { max-width: 1280px; margin: 0 auto; padding: 12px 24px 0; }
.crumbs { font-size: 13px; }
.crumbs > span:first-child::before { content: none; margin: 0; }
.page { padding-top: 12px; }

/* --- layout pieces ------------------------------------------------------------- */
.titlerow { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 4px; }
.grid4 { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
@media (max-width: 860px) { .grid3 { grid-template-columns: 1fr; } }
.linkcard { display: block; color: var(--text-primary); transition: border-color .15s; margin-bottom: 0; }
.linkcard:hover { border-color: var(--series-1); text-decoration: none; }
.linkcard .label { font-size: 12px; color: var(--text-secondary); }
.linkcard .big { font-size: 19px; font-weight: 650; margin: 2px 0; }
.linkcard.withthumb { position: relative; padding-right: 40%; overflow: hidden; }
.linkcard .thumb.side { position: absolute; right: 0; top: 0; bottom: 0; width: 38%; aspect-ratio: auto; }
.grid3 + .card, .grid4 + .pager { margin-top: 18px; }
.tag { font-weight: 600; }

.mapgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.mapcard { background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; color: var(--text-primary); display: block; }
.mapcard:hover { border-color: var(--series-1); text-decoration: none; }
.thumb { aspect-ratio: 16 / 9; background: var(--surface-2) center / cover no-repeat; position: relative; }
.mapcard .body { padding: 8px 10px; }
.mapcard .name, .cal .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mapcard .meta, .cal .meta { font-size: 12px; color: var(--text-secondary); display: flex; gap: 10px; }

.calendar { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; }
.calhead { font-size: 12px; color: var(--text-secondary); text-align: center; }
.cal { background: var(--surface-1); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; color: var(--text-primary); min-height: 60px; }
a.cal:hover { border-color: var(--series-1); text-decoration: none; }
.cal .name, .cal .meta { padding: 0 6px; font-size: 12px; }
.cal .meta { padding-bottom: 5px; }
.cal.empty { background: transparent; border: none; }
.cal.future { opacity: .45; position: relative; }
.daynum { position: absolute; top: 4px; left: 6px; font-size: 12px; font-weight: 700; background: var(--surface-1); color: var(--text-primary); padding: 0 5px; border-radius: 4px; }
@media (max-width: 700px) { .calendar { grid-template-columns: repeat(2, 1fr); } .calhead, .cal.empty { display: none; } }

.maphead { display: flex; gap: 18px; align-items: center; margin-bottom: 18px; flex-wrap: wrap; }
.thumb.big { width: 300px; border-radius: 10px; flex: none; }
.medals { display: flex; gap: 14px; margin: 6px 0; font-variant-numeric: tabular-nums; }
.medals span:nth-child(1) { color: var(--series-3); }
.medals span:nth-child(2) { color: #c9a227; }
.medals span:nth-child(3) { color: #9a9a9a; }
.medals span:nth-child(4) { color: #b0703c; }

.pager { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; gap: 16px; }
.pager.compact { justify-content: flex-end; }
.scanall { display: flex; gap: 10px; align-items: center; }
.progress { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; margin: 8px 0 4px; }
.progress div { height: 100%; background: var(--series-1); transition: width .3s; }
i.sw { width: 10px; height: 10px; display: inline-block; border-radius: 2px; }
details.card > summary { cursor: pointer; list-style: none; }
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary::before { content: "▸ "; color: var(--text-muted); }
details.card[open] > summary::before { content: "▾ "; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.filters input { min-width: 200px; }
form.inv [hidden] { display: none; }
.flagchip { display: inline-block; margin-left: 4px; padding: 0 7px; border-radius: 999px; font-size: 11px; font-weight: 600;
  border: 1px solid var(--critical); color: var(--text-primary); white-space: nowrap; }
.verdict-box + .verdict-box { margin-top: 6px; }
.brand { display: inline-flex; align-items: center; gap: 8px; }
.brand img { display: block; border-radius: 6px; }
.filters label { display: inline-flex; align-items: center; gap: 6px; }
.filters input[type=checkbox] { min-width: 0; width: auto; }
.flagchip.soft { border-color: var(--neutral); color: var(--text-secondary); font-weight: 500; }
.verdict-box.SOFT { border-color: var(--neutral); }
.updatebar { background: var(--series-1); color: #fff; text-align: center; padding: 6px 12px; font-weight: 600; }
.updatebar button { margin-left: 10px; background: #fff; color: #14243f; border: none; font-weight: 700; }
