:root {
    color-scheme: light;
    --page: #f9f9f7;
    --surface-1: #fcfcfb;
    --surface-2: #f2f1ed;
    --text-primary: #0b0b0b;
    --text-secondary: #52514e;
    --text-muted: #898781;
    --grid: #e1e0d9;
    --axis: #c3c2b7;
    --border: rgba(11, 11, 11, 0.1);
    --track: #e7e6e0;
    --series-1: #2a78d6;
    --series-2: #eb6834;
    --series-3: #1baf7a;
    /* one hue per channel (reference categorical palette); ref lap is a neutral */
    --c-speed: #2a78d6;
    --c-throttle: #1baf7a;
    --c-brakeF: #e34948;
    --c-brakeR: #eb6834;
    --c-lean: #4a3aa7;
    --c-rpm: #eda100;
    --c-gear: #e87ba4;
    --c-extra: #008300;
    --c-ref: #c8c7c0;
    /* channels that share a palette slot never appear in the same view */
    --c-valve: var(--c-extra);
    --c-tcCut: var(--c-brakeR);
    --c-slip: var(--c-rpm);
    --c-wheelie: var(--c-gear);
    --c-abs: var(--c-brakeF);
    --c-suspF: var(--c-lean);
    --c-suspR: var(--c-brakeR);
    --c-suspSpeedF: var(--c-throttle);
    --gain-text: #006300;
    --loss-text: #d03b3b;
    --accent: #256abf;
    --accent-ink: #ffffff;
    --good: #0ca30c;
    --warning: #fab219;
    --serious: #ec835a;
    --critical: #d03b3b;
    --radius: 10px;
    --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;
        --page: #0d0d0d;
        --surface-1: #1a1a19;
        --surface-2: #232321;
        --text-primary: #ffffff;
        --text-secondary: #c3c2b7;
        --text-muted: #898781;
        --grid: #2c2c2a;
        --axis: #383835;
        --border: rgba(255, 255, 255, 0.1);
        --track: #2c2c2a;
        --series-1: #3987e5;
        --series-2: #d95926;
        --series-3: #199e70;
    --c-speed: #3987e5;
    --c-throttle: #199e70;
    --c-brakeF: #e66767;
    --c-brakeR: #d95926;
    --c-lean: #9085e9;
    --c-rpm: #c98500;
    --c-gear: #d55181;
    --c-extra: #008300;
    --c-ref: #55544f;
    --gain-text: #0ca30c;
    --loss-text: #e66767;
        --c-speed: #3987e5;
        --c-throttle: #199e70;
        --c-brakeF: #e66767;
        --c-brakeR: #d95926;
        --c-lean: #9085e9;
        --c-rpm: #c98500;
        --c-gear: #d55181;
        --c-extra: #008300;
        --c-ref: #55544f;
        --gain-text: #0ca30c;
        --loss-text: #e66767;
        --accent: #3987e5;
    }
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface-1: #1a1a19;
    --surface-2: #232321;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --track: #2c2c2a;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --accent: #3987e5;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
    margin: 0;
    background: var(--page);
    color: var(--text-primary);
    font: 13px/1.4 var(--font);
    display: flex;
    flex-direction: column;
}

h2 { font-size: 12px; font-weight: 600; margin: 0; letter-spacing: 0.02em; }
code { font-size: 11px; background: var(--surface-2); padding: 1px 4px; border-radius: 4px; }
.muted { color: var(--text-muted); font-weight: 400; }
.small { font-size: 11px; }
.spacer { flex: 1; }
.hint { color: var(--text-muted); font-size: 11px; margin: 8px 0 0; }

/* top bar ---------------------------------------------------------------- */
.topbar {
    display: flex; align-items: center; gap: 16px;
    padding: 8px 16px;
    background: var(--surface-1);
    border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 15px; }
.brand svg { width: 20px; height: 20px; }
.brand rect { fill: var(--accent); }
.brand path { stroke: #fff; stroke-width: 1.8; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.tabs { display: flex; gap: 2px; background: var(--surface-2); padding: 3px; border-radius: 8px; }
.tabs button {
    border: 0; background: transparent; color: var(--text-secondary);
    padding: 5px 14px; border-radius: 6px; font: inherit; font-weight: 600; cursor: pointer;
}
.tabs button[aria-selected="true"] { background: var(--surface-1); color: var(--text-primary); box-shadow: 0 0 0 1px var(--border); }
.session-select { max-width: 440px; min-width: 0; font-weight: 600; text-overflow: ellipsis; }
#resetLayout { white-space: nowrap; }
/* view tabs get their own row unless the window is really wide */
@media (max-width: 1750px) {
    .topbar { flex-wrap: wrap; row-gap: 8px; }
    .session-select { order: 9; }
    .subtabs { order: 10; flex: 1 1 400px; }
}
.session-select[hidden] { display: none; }
.badge { white-space: nowrap; background: var(--surface-2); padding: 3px 8px; border-radius: 999px; font-size: 11px; color: var(--text-secondary); }

/* buttons & inputs ------------------------------------------------------- */
.btn, select, .ghost {
    font: inherit; color: var(--text-primary);
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: 7px; padding: 5px 10px; cursor: pointer;
}
.btn:hover:not(:disabled), .ghost:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 600; }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); background: var(--accent); }
.btn.recording { background: var(--critical); color: #fff; border-color: transparent; }
.ghost { background: transparent; }
.ghost.small, select { padding: 3px 8px; font-size: 12px; }
.file-btn { display: block; text-align: center; }
.check { display: inline-flex; align-items: center; gap: 4px; color: var(--text-secondary); }

/* layout ----------------------------------------------------------------- */
main { flex: 1; min-height: 0; display: flex; }
.view { flex: 1; min-width: 0; display: flex; }
.view[hidden] { display: none; }

#view-analysis { padding: 12px; }
.sidebar { width: var(--sidebar-w, 460px); flex: none; display: flex; flex-direction: column; min-height: 0; }
.sidebar > .panel:first-child { margin-bottom: 12px; }
.panel {
    background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 12px;
}
.panel h2 { margin-bottom: 8px; }
.panel.grow { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.content { flex: 1; min-width: 0; display: flex; flex-direction: column; min-height: 0; }
.row { display: flex; height: var(--row-h, 42%); flex: none; min-height: 180px; }

/* splitters (also act as the gap between panels) */
.splitter { flex: none; position: relative; touch-action: none; outline: none; }
.splitter[data-axis="x"] { width: 12px; cursor: col-resize; }
.splitter[data-axis="y"] { height: 12px; cursor: row-resize; }
.splitter::after {
    content: ""; position: absolute; border-radius: 2px; background: transparent; transition: background 120ms;
}
.splitter[data-axis="x"]::after { left: 5px; width: 2px; top: 8px; bottom: 8px; }
.splitter[data-axis="y"]::after { top: 5px; height: 2px; left: 8px; right: 8px; }
.splitter:hover::after, .splitter:focus-visible::after { background: var(--axis); }
.splitter.active::after { background: var(--accent); }
body.resizing-x, body.resizing-x * { cursor: col-resize !important; user-select: none; }
body.resizing-y, body.resizing-y * { cursor: row-resize !important; user-select: none; }

.card {
    background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 10px 12px; display: flex; flex-direction: column; min-width: 0; min-height: 0;
}
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; flex-wrap: wrap; }
.card canvas { flex: 1; width: 100%; min-height: 0; display: block; }

.map-card { flex: 0 0 var(--map-w, 55%); }
.summary { flex: 1; overflow: auto; }
.traces { flex: 1; min-height: 200px; }
.chart-hint { margin-top: 4px; }

/* lists & tables --------------------------------------------------------- */
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; max-height: 180px; overflow: auto; }
.list li { padding: 6px 8px; border-radius: 6px; cursor: pointer; display: flex; justify-content: space-between; gap: 8px; }
.list li:hover { background: var(--surface-2); }
.list li.active { background: var(--surface-2); box-shadow: inset 3px 0 0 var(--accent); }
.list li .muted { font-size: 11px; }
.list li.empty, td.empty { color: var(--text-muted); cursor: default; }

.table-wrap { overflow: auto; flex: 1; min-height: 0; }
table.laps { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: 12px; }
table.laps th {
    position: sticky; top: 0; background: var(--surface-1);
    text-align: right; font-weight: 600; color: var(--text-muted); font-size: 11px;
    padding: 4px 6px; border-bottom: 1px solid var(--grid);
}
table.laps td { text-align: right; padding: 4px 5px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
table.laps th:first-child, table.laps td:first-child { text-align: center; }
table.laps tbody tr { cursor: pointer; }
table.laps tbody tr:hover { background: var(--surface-2); }
table.laps tr.selected { background: var(--surface-2); }
table.laps tr.selected td.lapno { box-shadow: inset 3px 0 0 var(--text-primary); }
table.laps tr.ref td.lapno { box-shadow: inset 3px 0 0 var(--c-ref); }
table.laps tr.dim td { color: var(--text-muted); }
table.laps td.best { font-weight: 700; }
table.laps td.sector-best { color: var(--good); font-weight: 600; }
table.laps tr.ideal td { color: var(--text-secondary); font-style: italic; border-top: 2px solid var(--grid); }
.kind { font-size: 10px; color: var(--text-muted); text-transform: uppercase; margin-left: 4px; }

/* stat tiles ------------------------------------------------------------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.tile { background: var(--surface-2); border-radius: 8px; padding: 8px 10px; }
.tile .label { color: var(--text-secondary); font-size: 11px; }
.tile .value { font-size: 22px; font-weight: 600; margin-top: 2px; }
.tile .value small { font-size: 12px; font-weight: 400; color: var(--text-secondary); margin-left: 3px; }
.tile .note { font-size: 11px; color: var(--text-muted); }
.meta { margin-top: 10px; color: var(--text-muted); font-size: 11px; display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; }

/* legends & chips -------------------------------------------------------- */
.legend { display: flex; gap: 12px; font-size: 11px; color: var(--text-secondary); }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend i { width: 14px; height: 3px; border-radius: 2px; display: inline-block; }
.chips { display: flex; gap: 4px; flex-wrap: wrap; }
.chip {
    border: 1px solid var(--border); background: transparent; color: var(--text-secondary);
    border-radius: 999px; padding: 2px 9px; font: inherit; font-size: 11px; cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--surface-2); color: var(--text-primary); border-color: var(--axis); }
.chip .x { margin-left: 4px; color: var(--text-muted); }
.chip .dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 5px; vertical-align: 0; opacity: 0.35; }
.chip[aria-pressed="true"] .dot { opacity: 1; }
.legend-ramp { display: flex; align-items: center; gap: 8px; font-size: 11px; color: var(--text-muted); margin-top: 6px; font-variant-numeric: tabular-nums; }
.legend-ramp i { flex: 1; height: 6px; border-radius: 3px; max-width: 220px; }

/* live ------------------------------------------------------------------- */
#view-live { flex-direction: column; padding: 12px; min-height: 0; }
.toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar .group { display: flex; align-items: center; gap: 6px; padding-right: 12px; border-right: 1px solid var(--grid); }
.pill { padding: 3px 10px; border-radius: 999px; background: var(--surface-2); font-size: 11px; font-weight: 600; color: var(--text-secondary); }
.pill::before { content: "●"; margin-right: 5px; color: var(--text-muted); }
.pill.ok::before { color: var(--good); }
.pill.warn::before { color: var(--warning); }
.pill.bad::before { color: var(--critical); }

.live-top {
    display: grid; gap: 12px; flex: none;
    grid-template-columns: 1.2fr 1.2fr 0.8fr 1fr;
    height: var(--live-top-h, 190px); min-height: 140px;
}
.live-top > .card { container-type: size; overflow: hidden; }
.live-mid { display: flex; flex: none; height: var(--live-mid-h, 33%); min-height: 160px; }
.live-map { flex: 0 0 var(--live-map-w, 38%); }
.timing { flex: 0 0 var(--live-timing-w, 19%); container-type: inline-size; overflow: hidden; }
.live-sectors { flex: 0 0 var(--live-sectors-w, 27%); overflow: hidden; }
.live-sectors .table-wrap { flex: 1; }
.sector-live td:first-child, .sector-live th:first-child { text-align: left; font-weight: 600; }
.sector-live tr.running td { background: var(--surface-2); }
.sector-live tr.running td:first-child { box-shadow: inset 3px 0 0 var(--text-primary); }
.timing-delta { font-size: clamp(14px, 9cqw, 28px); font-weight: 700; font-variant-numeric: tabular-nums; min-height: 1.2em; }
.link { flex: 1; overflow: auto; }
.live-traces { flex: 1; min-height: 140px; }

.bars-card { flex-direction: row; justify-content: space-around; }
.hero { justify-content: center; }
.gauge-card { align-items: center; }
.label { color: var(--text-secondary); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }
.sub { color: var(--text-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.hero-value { font-size: clamp(32px, min(42cqh, 24cqw), 160px); font-weight: 700; line-height: 1; margin: 6px 0; font-variant-numeric: tabular-nums; }
.hero-value small { font-size: max(14px, 0.25em); font-weight: 400; color: var(--text-secondary); margin-left: 6px; }

#leanGauge { width: 100%; flex: 1; min-height: 0; }
.gauge-track { fill: none; stroke: var(--track); stroke-width: 12; stroke-linecap: round; }
.gauge-needle { stroke: var(--text-primary); stroke-width: 3; stroke-linecap: round; transition: transform 60ms linear; transform-origin: 100px 100px; }
.gauge-max { stroke: var(--c-lean); stroke-width: 2; stroke-dasharray: 3 3; transform-origin: 100px 100px; }
.gauge-hub { fill: var(--text-primary); }
#leanTicks line { stroke: var(--axis); stroke-width: 1.5; }
#leanTicks text { fill: var(--text-muted); font-size: 9px; text-anchor: middle; font-family: var(--font); }
.gauge-value { font-size: clamp(18px, 13cqh, 48px); font-weight: 700; font-variant-numeric: tabular-nums; margin-top: -6px; }

.bar-col { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.vbar { width: clamp(28px, 18cqw, 64px); flex: 1; min-height: 40px; background: var(--surface-2); border-radius: 6px; position: relative; overflow: hidden; }
.vbar i { position: absolute; left: 0; right: 0; bottom: 0; height: 0; border-radius: 4px 4px 0 0; }
.fill-throttle { background: var(--c-throttle); }
.fill-brake { background: var(--c-brakeF); }
.bar-val { font-weight: 600; font-variant-numeric: tabular-nums; }

.flags { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 8px; }
.flag {
    padding: 8px; border-radius: 7px; background: var(--surface-2); color: var(--text-muted);
    font-weight: 600; font-size: 12px; display: flex; align-items: center; gap: 6px;
}
.flag::before { content: "○"; }
.flag.on { color: #0b0b0b; }
.flag.on::before { content: "●"; }
.flag.on.tc, .flag.on.wheelie, .flag.on.launch { background: var(--warning); }
.flag.on.abs { background: var(--critical); color: #fff; }
.flag.on.gpsFix { background: var(--good); color: #fff; }

.timing-current { font-size: clamp(28px, 18cqw, 72px); font-weight: 700; font-variant-numeric: tabular-nums; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; margin: 6px 0 0; font-variant-numeric: tabular-nums; }
.kv dt { color: var(--text-secondary); }
.kv dd { margin: 0; text-align: right; font-weight: 600; }
.lap-history { margin: 8px 0 0; padding-left: 0; list-style: none; overflow: auto; font-variant-numeric: tabular-nums; font-size: 12px; color: var(--text-secondary); }
.lap-history li { display: flex; justify-content: space-between; border-top: 1px solid var(--grid); padding: 2px 0; }
.lap-history li.best { color: var(--good); font-weight: 600; }

/* view tabs + insight panel ------------------------------------------- */
.subtabs { overflow-x: auto; max-width: 100%; }
.subtabs[hidden] { display: none; }
.subtabs button { white-space: nowrap; padding: 5px 11px; }
.insight { display: flex; flex-direction: column; gap: 12px; min-height: 0; }
.insight-section h3 { font-size: 11px; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.05em; margin: 0 0 6px; }
.insight-note { margin: 0 0 6px; }
.insight-table { max-height: none; }
.insight-table table.laps td:first-child { text-align: left; font-weight: 600; }
.insight-table table.laps th:first-child { text-align: left; }
.gain { color: var(--gain-text); font-weight: 600; }
.loss { color: var(--loss-text); font-weight: 600; }
.sector-best-text { color: var(--gain-text); font-weight: 600; }
.shift-up { color: var(--text-primary); }
.shift-down { color: var(--text-secondary); }

.columns { display: flex; align-items: flex-end; gap: 2px; height: 120px; padding-top: 4px; }
.col { flex: 1; min-width: 0; height: 100%; display: flex; flex-direction: column; align-items: stretch; }
.col-bars { flex: 1; display: flex; align-items: flex-end; gap: 1px; border-bottom: 1px solid var(--axis); }
.col-bars i { flex: 1; border-radius: 3px 3px 0 0; min-height: 0; }
.col span { font-size: 10px; color: var(--text-muted); text-align: center; height: 14px; overflow: visible; white-space: nowrap; }
.col:hover .col-bars { background: var(--surface-2); }

.hbars { display: flex; flex-direction: column; gap: 4px; }
.hbar-row { display: grid; grid-template-columns: 52px 1fr 108px; align-items: center; gap: 8px; font-size: 12px; font-variant-numeric: tabular-nums; }
.hbar-label { color: var(--text-secondary); font-weight: 600; }
.hbar-track { display: flex; flex-direction: column; gap: 2px; }
.hbar-track i { display: block; height: 7px; border-radius: 0 3px 3px 0; min-width: 2px; }
.hbar-track i.ref { height: 4px; }
.hbar-value { text-align: right; }
.hbar-value small { color: var(--text-muted); }

.lap-evolution { display: flex; align-items: flex-end; gap: 3px; height: 90px; }
.evo-bar { flex: 1; min-width: 10px; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; border: 0; padding: 0; background: transparent; cursor: pointer; font: inherit; }
.evo-bar i { display: block; background: var(--c-ref); border-radius: 3px 3px 0 0; }
.evo-bar.best i { background: var(--good); }
.evo-bar.selected i { background: var(--text-primary); }
.evo-bar.ref i { outline: 2px solid var(--c-ref); outline-offset: 1px; background: var(--surface-2); }
.evo-bar span { font-size: 10px; color: var(--text-muted); text-align: center; margin-top: 2px; }
.evo-bar:hover i { filter: brightness(1.2); }

.row.wide > .map-card, .row.wide > .splitter { display: none; }
.row.wide > .summary { flex: 1; }
.segmented { display: inline-flex; gap: 2px; background: var(--surface-2); padding: 3px; border-radius: 8px; }
.segmented button { border: 0; background: transparent; color: var(--text-secondary); font: inherit; font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 6px; cursor: pointer; }
.segmented button[aria-checked="true"] { background: var(--surface-1); color: var(--text-primary); box-shadow: 0 0 0 1px var(--border); }
.sector-controls { display: flex; gap: 12px; flex-wrap: wrap; }
.sector-matrix table.laps th.sortable { cursor: pointer; user-select: none; }
.sector-matrix table.laps th.sortable:hover { color: var(--text-primary); }
.sector-matrix table.laps td { border-left: 1px solid var(--surface-1); }

.ghost.active { background: var(--accent); color: var(--accent-ink); border-color: transparent; }

/* 3D view ---------------------------------------------------------------- */
#view-3d { flex-direction: column; padding: 12px; gap: 12px; min-height: 0; }
#view-3d .toolbar { margin-bottom: 0; }
#view-3d .toolbar label { display: inline-flex; align-items: center; gap: 4px; }
.v3d-stage { flex: 1; min-height: 340px; position: relative; padding: 0; overflow: hidden; }
.v3d-stage canvas { width: 100%; height: 100%; cursor: grab; touch-action: none; }
.v3d-stage canvas:active { cursor: grabbing; }
.hud {
    position: absolute; top: 12px; left: 12px; width: 190px; padding: 10px 12px; border-radius: 10px;
    background: color-mix(in srgb, var(--surface-1) 88%, transparent); border: 1px solid var(--border);
    font-variant-numeric: tabular-nums; font-size: 12px; display: flex; flex-direction: column; gap: 4px;
    pointer-events: none;
}
.hud-speed { font-size: 34px; font-weight: 700; line-height: 1; margin-bottom: 4px; }
.hud-speed small { font-size: 12px; font-weight: 400; color: var(--text-secondary); margin-left: 4px; }
.hud-row { display: flex; justify-content: space-between; color: var(--text-secondary); }
.hud-row b { color: var(--text-primary); }
.hud-bar { display: grid; grid-template-columns: 54px 1fr; align-items: center; gap: 6px; color: var(--text-secondary); }
.hud-bar div { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.hud-bar i { display: block; height: 100%; width: 0; border-radius: 4px; }
.hud-delta { font-size: 18px; font-weight: 700; min-height: 1.2em; }
.v3d-legend { position: absolute; left: 12px; bottom: 30px; width: min(360px, 60%); }
.v3d-hint { position: absolute; left: 12px; bottom: 6px; margin: 0; }
.v3d-empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--text-muted); }
.v3d-empty[hidden] { display: none; }
.v3d-bottom { flex: none; }
.v3d-transport { display: flex; align-items: center; gap: 10px; }
.v3d-transport input[type=range] { flex: 1; accent-color: var(--accent); }
.v3d-time { font-variant-numeric: tabular-nums; font-weight: 600; min-width: 130px; text-align: right; }
.v3d-profile-head { display: flex; gap: 10px; align-items: baseline; margin: 8px 0 4px; }
.v3d-main { flex: 1; min-height: 340px; display: flex; gap: 12px; }
.v3d-main .v3d-stage { min-height: 0; }
.v3d-config { width: 190px; flex: none; gap: 6px; }
.v3d-config h2 { margin-bottom: 4px; }
.check-row { display: flex; align-items: center; gap: 6px; font-size: 12px; cursor: pointer; padding: 2px 0; }
.info-fields { border: 0; padding: 0; margin: 4px 0 0; display: flex; flex-direction: column; gap: 2px; }
.info-fields:disabled { opacity: 0.45; }
.info-fields legend { padding: 0; margin-bottom: 2px; }

.info-layer { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.bike-info {
    position: absolute; left: 0; top: 0; min-width: 126px; padding: 6px 8px; border-radius: 8px;
    background: color-mix(in srgb, var(--surface-1) 92%, transparent); border: 1px solid var(--border);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
    font-size: 11px; font-variant-numeric: tabular-nums; line-height: 1.35;
    transform: translate(-50%, calc(-100% - 8px)); will-change: left, top;
}
.bike-info::after {
    content: ""; position: absolute; left: 50%; bottom: -6px; width: 10px; height: 10px; margin-left: -5px;
    background: inherit; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); transform: rotate(45deg);
}
.bike-info .bi-head { display: flex; align-items: center; gap: 5px; font-weight: 700; margin-bottom: 2px; }
.bike-info .bi-head i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.bike-info.ghost { opacity: 0.85; }
.bike-info .bi-row { display: grid; grid-template-columns: 44px 1fr; align-items: center; gap: 6px; color: var(--text-secondary); }
.bike-info .bi-row b { color: var(--text-primary); font-weight: 600; text-align: right; }
.bike-info .bi-bar { display: grid; grid-template-columns: 1fr 44px; gap: 4px; align-items: center; }
.bike-info .bi-bar div { height: 5px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.bike-info .bi-bar span { display: block; height: 100%; width: 0; }
.bike-info .bi-bar b { font-size: 10px; }
.bike-info .bi-row[hidden] { display: none; }
.bike-info .fill-tc { background: var(--c-tcCut); }
.bike-info .fill-travel { background: var(--c-suspF); }
.cfg-head { margin-top: 10px; }
.cfg-buttons { display: flex; gap: 6px; flex-wrap: wrap; }
.btn.small-btn { padding: 3px 8px; font-size: 12px; }
#v3dModel { width: 100%; }
.check-row.dim { opacity: 0.45; cursor: default; }

#v3dProfile { flex: none; width: 100%; height: 110px; display: block; cursor: pointer; }
@media (max-width: 1000px) {
    .v3d-main { flex-direction: column; }
    .v3d-config { width: auto; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 4px 14px; }
    .v3d-config .info-fields { flex-direction: row; gap: 10px; margin: 0; }
    .v3d-config .hint { display: none; }
    .v3d-main .v3d-stage { min-height: 420px; }
}
@media (max-width: 560px) {
    .hud { width: 150px; }
    .hud-speed { font-size: 26px; }
}

/* accounts, dialogs ------------------------------------------------------- */
.account-box { position: relative; display: flex; align-items: center; }
.account-box[hidden] { display: none; }
.account-btn { font-weight: 600; display: inline-flex; align-items: center; gap: 6px; }
.role-chip { font-size: 10px; padding: 1px 6px; border-radius: 999px; background: var(--surface-2); color: var(--text-secondary); font-weight: 600; }
.menu { position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; min-width: 170px; display: flex; flex-direction: column;
    background: var(--surface-1); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,0.25); padding: 4px; }
.menu[hidden] { display: none; }
.menu button { text-align: left; border: 0; background: transparent; color: var(--text-primary); font: inherit; padding: 7px 10px; border-radius: 6px; cursor: pointer; }
.menu button:hover { background: var(--surface-2); }

dialog.modal { border: 1px solid var(--border); border-radius: 12px; padding: 0; width: min(440px, calc(100vw - 32px));
    background: var(--surface-1); color: var(--text-primary); box-shadow: 0 20px 60px rgba(0,0,0,0.35); }
dialog.modal.wide { width: min(980px, calc(100vw - 32px)); }
dialog.modal::backdrop { background: rgba(0, 0, 0, 0.45); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--grid); }
.modal-head h2 { font-size: 14px; }
.modal-body { padding: 16px; max-height: calc(100vh - 140px); overflow: auto; }
.modal-body h3 { font-size: 11px; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.05em; margin: 14px 0 6px; }
.modal-body h3:first-child { margin-top: 0; }
.form { display: flex; flex-direction: column; gap: 10px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-secondary); }
.field input, .link-input, .lib-search {
    font: inherit; color: var(--text-primary); background: var(--page); border: 1px solid var(--border); border-radius: 7px; padding: 7px 9px; }
.field input:focus, .link-input:focus, .lib-search:focus { outline: 2px solid var(--accent); outline-offset: 0; }
.form-error { color: var(--loss-text); font-size: 12px; margin: 0; min-height: 1em; }
.row-inline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.link-box { display: flex; gap: 6px; flex: 1; min-width: 0; }
.link-input { flex: 1; min-width: 0; font-size: 12px; }
.link-item { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }
.invite-out { margin-top: 8px; }
.admin-table td { vertical-align: middle; }
.admin-table td:first-child { text-align: left; font-weight: 600; }
.ghost.danger { color: var(--loss-text); }
.vis-options { display: flex; gap: 16px; flex-wrap: wrap; }
.user-checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 2px 12px; margin: 6px 0 10px; padding: 8px; border: 1px solid var(--grid); border-radius: 8px; }
.user-checks[hidden] { display: none; }
.share .row-inline { margin-top: 10px; }

/* library ----------------------------------------------------------------- */
#view-library { flex-direction: column; padding: 12px; gap: 12px; min-height: 0; }
#view-library.dragging { outline: 3px dashed var(--accent); outline-offset: -6px; }
.lib-upload { flex: none; }
.lib-list { flex: 1; min-height: 240px; }
.lib-search { min-width: 220px; padding: 4px 9px; font-size: 12px; }
.uploads { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.upload-row { border: 1px solid var(--grid); border-radius: 8px; padding: 8px 10px; }
.upload-title { display: flex; gap: 10px; align-items: center; font-size: 12px; }
.upload-title span { flex: 1; font-variant-numeric: tabular-nums; }
.upload-bar { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; margin-top: 6px; }
.upload-bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width 200ms; }
.upload-bar i.bad { background: var(--critical); }
.lib-table td:nth-child(2), .lib-table th:nth-child(2), .lib-table td:nth-child(3), .lib-table th:nth-child(3),
.lib-table td:nth-child(4), .lib-table th:nth-child(4) { text-align: left; }
.lib-table tr.selected td { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.lib-actions { white-space: nowrap; }
.lib-actions > * { margin-left: 4px; }
.share-chip { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--text-secondary); }
.share-chip.all, .share-chip.users { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--text-primary); }
.share-banner { position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 15; padding: 6px 14px; border-radius: 999px;
    background: var(--surface-1); border: 1px solid var(--border); box-shadow: 0 4px 16px rgba(0,0,0,0.2); font-size: 12px; font-weight: 600; }
.share-banner[hidden] { display: none; }

/* overlays --------------------------------------------------------------- */
.drop-overlay {
    position: fixed; inset: 0; display: grid; place-items: center; z-index: 10;
    background: color-mix(in srgb, var(--accent) 18%, transparent);
    border: 3px dashed var(--accent);
}
.drop-overlay[hidden] { display: none; }
.drop-overlay div { background: var(--surface-1); padding: 16px 24px; border-radius: var(--radius); font-weight: 600; }
.toast {
    position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); z-index: 11;
    background: var(--text-primary); color: var(--page); padding: 8px 14px; border-radius: 8px; font-size: 12px;
    max-width: calc(100vw - 32px);
}
.toast[hidden] { display: none; }

/* small screens: stack everything, splitters off ------------------------ */
@media (max-width: 1000px) {
    .topbar { flex-wrap: wrap; row-gap: 8px; }
    .subtabs { order: 10; flex-basis: 100%; }
    .session-select { order: 9; flex-basis: 100%; max-width: none; }
    main { overflow: auto; }
    .splitter { display: none; }
    #view-analysis { flex-direction: column; gap: 12px; }
    .sidebar { width: auto; gap: 12px; }
    .sidebar > .panel:first-child { margin-bottom: 0; }
    .panel.grow { max-height: 420px; }
    .content { gap: 12px; }
    .row { flex-direction: column; height: auto; gap: 12px; }
    .map-card { flex: none; min-height: 300px; }
    .traces { min-height: 560px; }
    #view-live { gap: 12px; }
    .toolbar { margin-bottom: 0; }
    .live-top { grid-template-columns: 1fr 1fr; height: auto; grid-auto-rows: 180px; }
    .live-mid { flex-direction: column; height: auto; gap: 12px; }
    .live-map { flex: none; min-height: 300px; }
    .timing, .live-sectors { flex: none; }
    .live-traces { flex: none; min-height: 420px; }
}
@media (max-width: 560px) {
    .topbar { padding: 8px 16px; gap: 10px; }
    #resetLayout, #trackBadge { display: none; }
    #view-analysis, #view-live { padding: 12px 16px; }
    .live-top { grid-template-columns: 1fr; }
}
