/* Pit Wall on top of /assets/style.css (Lap Coach mint/dark tokens).
 * One DOM for every window: body[data-size] (Material 3 width class, set by ResizeObserver), [data-tab],
 * [data-posture] and [data-watch] only move and hide panels, so folding, unfolding or resizing a DeX window
 * never rebuilds the page, the SSE stream or scroll positions. Touch gets 48 px targets, a mouse gets density. */
:root { --gap: 16px; --tabbar: 0px; }
body { min-height: 100dvh; }
header { padding: 10px 20px; gap: 16px; display: flex; align-items: center; flex-wrap: wrap; border-bottom-width: 1px; }
header .brand { font-size: 20px; }
.header-status { display: flex; align-items: center; gap: 14px; flex: 1; min-width: 0; flex-wrap: wrap; }
main { max-width: none; padding: 16px clamp(12px, 2vw, 28px) calc(32px + var(--tabbar)); }
h3 { font-size: 14px; margin: 0 0 10px; color: var(--mint); }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 10px; }
.panel-head h2 { margin: 0; }
.connection { margin: 4px 0 16px; }
/* The shared label margin (13px) lifted the key box above the buttons; one height for box and buttons. */
.connection label, .connected-bar, .session-bar label { margin-bottom: 0; }
.connection input, .connection button { height: 44px; min-height: 44px; }
.session-bar select, .session-bar .actions button { height: 44px; min-height: 44px; }
@media (pointer: coarse) {
  .connection input, .connection button, .session-bar select, .session-bar .actions button { height: 48px; min-height: 48px; }
}
.connected-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 0 0 12px; font-size: 13px; color: var(--muted); }
.connected-bar #status { flex: 1; min-width: 160px; }
body[data-connected] .connection { display: none; }
.session-bar { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: end; padding: 14px 16px; margin-bottom: 12px; }
.session-bar label { flex: 1 1 260px; margin: 0; }
.session-bar .actions { flex: 0 1 auto; }
.readiness.is-idle { color: var(--muted); }
.readiness.is-idle .status-light { background: var(--other-memory); box-shadow: 0 0 0 3px var(--surface-raised); }
label.inline { display: inline-flex; align-items: center; gap: 8px; margin: 0; }
label.inline select { margin: 0; width: auto; }
label.check { display: flex; align-items: center; }
.replay { padding: 14px 16px; margin-bottom: 12px; }
.replay input[type=range] { margin-top: 12px; accent-color: var(--mint); padding: 0; min-height: 28px; border: 0; background: transparent; }
.replay-time, .clock { font-variant-numeric: tabular-nums; font-size: 13px; color: var(--muted); }

/* Car chips: one row that scrolls sideways on narrow screens instead of wrapping into a wall of buttons. */
.car-chips { display: flex; gap: 8px; margin: 0 0 12px; overflow-x: auto; scrollbar-width: thin; padding-bottom: 2px; }
.car-chips button { flex: none; display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px; color: var(--muted); background: var(--surface); border: 1px solid var(--border); }
.car-chips button[aria-pressed=true] { color: var(--text); border-color: var(--mint); background: var(--surface-raised); }
.car-chips button.focus { box-shadow: inset 0 -3px 0 var(--mint); }
.car-chips i, .car-cell i, .car-head h2 i { width: 12px; height: 12px; border-radius: 50%; flex: none; display: inline-block; }

/* ---- the panel grid ---- */
.pit-grid { display: grid; gap: var(--gap); grid-template-columns: minmax(0, 1fr); align-items: start;
  grid-template-areas: "map" "overview" "laps" "can" "lines" "compare"; }
.pit-grid > .card { margin: 0; min-width: 0; }
#panel-map { grid-area: map; } #panel-overview { grid-area: overview; } #panel-laps { grid-area: laps; }
#panel-can { grid-area: can; } #panel-lines { grid-area: lines; } #panel-compare { grid-area: compare; min-width: 0; }
#panel-compare > .card { margin: 0 0 var(--gap); }
body:not([data-size=large]) #panel-compare { display: none; }
body[data-size=large] :is(#panel-laps, #panel-can, #panel-lines) { display: none; }

/* Compact (< 600): one car, one panel at a time, bottom tabs. */
body[data-size=compact] { --tabbar: 64px; --gap: 12px; }
body[data-size=compact] main { padding-left: 12px; padding-right: 12px; }
body[data-size=compact][data-tab=map] .panel:not([data-tab=map]),
body[data-size=compact][data-tab=laps] .panel:not([data-tab=laps]),
body[data-size=compact][data-tab=can] .panel:not([data-tab=can]),
body[data-size=compact][data-tab=lines] .panel:not([data-tab=lines]) { display: none; }
body[data-size=compact] .card { padding: 14px; }
.tabbar { display: none; }
body[data-size=compact][data-connected] .tabbar { display: grid; position: fixed; z-index: 5; left: 0; right: 0; bottom: 0;
  grid-template-columns: repeat(4, minmax(0, 1fr)); background: var(--surface); border-top: 1px solid var(--border);
  padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); gap: 6px; }
.tabbar button { color: var(--muted); background: transparent; min-height: 48px; padding: 6px; font-weight: 650; }
.tabbar button[aria-pressed=true] { color: var(--background); background: var(--mint); }
body[data-size=compact] .lines { max-height: none; }

/* From Medium up the map owns the left column and stays in view (sticky) while the right side scrolls. */
body:not([data-size=compact]) #panel-map { position: sticky; top: 8px; align-self: start; }
body:not([data-size=compact]) .map-box { max-height: calc(100dvh - 150px); }
/* Medium (600-839): two columns, map left, tables and log right. */
body[data-size=medium] .pit-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  grid-template-areas: "map overview" "map laps" "map can" "map lines"; }
/* Expanded (840-1199): map with a side panel, the log across the bottom. */
body[data-size=expanded] .pit-grid { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
  grid-template-areas: "map overview" "map laps" "map can" "lines lines"; }
/* Large (>= 1200): map left, overview, comparison and every selected car's card on the right. */
body[data-size=large] .pit-grid { grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); grid-template-areas: "map overview" "map compare"; }

/* Fold half-opened (the app shell reports it through PitWall.setPosture): map above the hinge, panels below. */
body[data-posture=half-opened] .pit-grid { grid-template-columns: minmax(0, 1fr); grid-template-areas: "map" "overview" "laps" "can" "lines" "compare"; }
body[data-posture=half-opened] #panel-map { position: static; }
body[data-posture=half-opened] .map-box { height: calc(50dvh - 120px); aspect-ratio: auto; }

/* ---- map ---- */
.map-box { position: relative; width: 100%; aspect-ratio: 4 / 3; max-height: 70dvh; min-height: 220px; background: var(--background);
  border-radius: 9px; overflow: hidden; touch-action: none; cursor: grab; }
.map-box:active { cursor: grabbing; }
body[data-size=compact] .map-box { aspect-ratio: auto; height: max(260px, calc(100dvh - 330px)); max-height: none; }
#map { width: 100%; height: 100%; display: block; }
#map .road-edge { fill: none; stroke: var(--border); stroke-width: 16px; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
#map .road { fill: none; stroke: var(--surface-raised); stroke-width: 10px; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
#map .raw-trail { fill: none; stroke: var(--border); stroke-width: 3px; stroke-dasharray: 6 6; vector-effect: non-scaling-stroke; }
#map .trail { fill: none; stroke-width: 4px; stroke-linecap: round; stroke-linejoin: round; opacity: .55; vector-effect: non-scaling-stroke; }
#map .start { fill: var(--text); }
#map .start-label { fill: var(--muted); font-weight: 700; font-family: Inter, 'Segoe UI', sans-serif; }
#map .car circle { stroke: var(--background); stroke-width: 3px; vector-effect: non-scaling-stroke; }
#map .car-label { fill: var(--background); text-anchor: middle; dominant-baseline: central; font-weight: 750; font-family: Inter, 'Segoe UI', sans-serif; pointer-events: none; }
#map .car { cursor: pointer; }
#map .car.dim { opacity: .35; }
#map .car.focus circle { stroke: var(--text); }
#map .car.hl circle { stroke: var(--mint); stroke-width: 5px; }
.map-tools { display: flex; gap: 6px; }
.map-tools button { padding: 6px 12px; min-width: 40px; }
.map-tip { position: absolute; z-index: 2; pointer-events: none; transform: translate(-50%, calc(-100% - 22px)); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 12px; white-space: nowrap; box-shadow: 0 6px 18px #0008; }
.map-tip strong { display: block; color: var(--mint); font-size: 13px; }

/* ---- tables, CAN, log ---- */
.table-scroll { overflow-x: auto; max-width: 100%; }
.table-scroll table { min-width: 520px; }
.table-scroll.lap-table table, #compare table { min-width: 320px; }
.lap-table { max-height: 420px; overflow-y: auto; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.stale td { color: var(--other-memory); }
#overview tbody tr { cursor: pointer; }
#overview tbody tr.focus td { background: var(--surface-raised); }
#overview tbody tr:hover td { background: #203d4280; }
.car-cell { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; }
.pb { color: var(--mint); font-weight: 700; }
.lap-invalid td { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--border); }
.lap-current td { color: var(--muted); font-style: italic; }
.can-state[data-level=ok] { color: var(--ready); }
.can-state[data-level=bad] { color: var(--danger); }
.can-state[data-level=stale], .can-state[data-level=na] { color: var(--muted); }
.car-details { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 440px), 1fr)); gap: var(--gap); }
.car-details > .card { min-width: 0; margin: 0; }
.car-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 14px; margin-bottom: 12px; }
.car-head h2 { margin: 0; display: flex; align-items: center; gap: 10px; }
.car-meta { display: flex; flex-wrap: wrap; gap: 6px; }
/* Tiles keep one size while values change: fixed height, one line, fixed decimals, tabular digits. */
.can-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(108px, 1fr)); gap: 8px; margin: 8px 0 14px; }
.can-tile { background: var(--background); border-radius: 8px; padding: 8px 10px; min-width: 0; height: 58px; overflow: hidden; }
.can-tile span { display: block; font-size: 11px; line-height: 15px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.can-tile strong { display: block; font-size: 16px; line-height: 24px; margin-top: 3px; font-variant-numeric: tabular-nums;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.can-tile strong small { font-size: 11px; font-weight: 500; color: var(--muted); margin-left: 4px; }
.can-tile.stale { opacity: .4; }
.lines { list-style: none; margin: 6px 0 0; padding: 0; max-height: 340px; overflow-y: auto; font-size: 13px; }
.lines li { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 4px 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.lines .src { font-size: 10px; font-weight: 750; letter-spacing: .6px; padding: 3px 6px; border-radius: 5px; background: var(--surface-raised); align-self: start; text-align: center; min-width: 44px; }
.src[data-source=ai] { color: var(--mint); }
.src[data-source=auto] { color: var(--warning); }
.src[data-source=driver] { color: var(--text); }
.src[data-source=pit] { color: #ff9ecf; }
.lines p { margin: 0; line-height: 1.5; overflow-wrap: anywhere; }
.lines small { color: var(--muted); font-size: 11px; display: block; }
body[data-size=expanded] #panel-lines .lines { max-height: 260px; }

/* ---- highlights (new records, automatic announcements) ---- */
.highlights { display: grid; gap: 8px; margin: 0 0 12px; }
.highlight { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-radius: 10px; background: var(--surface-raised);
  border-left: 4px solid var(--mint); animation: highlight-in .25s ease-out; font-weight: 650; overflow-wrap: anywhere; }
.highlight[data-kind=announcement] { border-left-color: var(--warning); font-weight: 500; }
.highlight[data-kind=session_best] { background: #1f4a43; }
.highlight .tag { font-size: 11px; letter-spacing: .6px; color: var(--muted); flex: none; }
@keyframes highlight-in { from { opacity: 0; transform: translateY(-4px); } }
@media (prefers-reduced-motion: reduce) { .highlight { animation: none; } }

/* ---- admin ---- */
.admin-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 230px), 1fr)); gap: 18px; margin: 12px 0 18px; }
.admin-grid form { min-width: 0; }
.issued { border-left: 3px solid var(--mint); background: var(--background); padding: 12px; margin-bottom: 18px; }
.issued code { display: block; margin: 8px 0; font-size: 13px; overflow-wrap: anywhere; color: var(--mint); user-select: all; }
.end-session { margin-top: 18px; }
#keys button { padding: 7px 10px; font-size: 12px; }

/* ---- watch mode: a pit monitor or a remote viewer; controls hidden, same type sizes ---- */
.watch-only { display: none; }
body[data-watch] .watch-only { display: initial; }
body[data-watch] .control, body[data-watch] #message:empty { display: none !important; }
body[data-watch] { --tabbar: 0px; }
body[data-watch] header { padding: 8px 20px; }
/* Same type sizes as the managed view (user decision 2026-11-02); watch mode only hides controls. */
body[data-watch] #watch-title { font-weight: 700; }
body[data-watch] .clock { color: var(--text); }
.watch-exit { margin-left: auto; opacity: .45; padding: 8px 12px; }
.watch-exit:hover, .watch-exit:focus-visible { opacity: 1; }
/* Watch mode below Large shows the cycling car's panels together instead of tabs. */
body[data-watch][data-size=compact] .panel { display: block !important; }
body[data-watch][data-size=compact] #panel-compare { display: none !important; }
body[data-watch][data-size=compact] #panel-overview .hint { display: none; }
/* Large watch with a cycle (cycle > 0) follows one car: show its panels instead of the comparison. */
body[data-watch][data-size=large][data-cycling] .pit-grid { grid-template-areas: "map overview" "map laps" "map can" "map lines"; }
body[data-watch][data-size=large][data-cycling] :is(#panel-laps, #panel-can, #panel-lines) { display: block; }
body[data-watch][data-size=large][data-cycling] #panel-compare { display: none; }

/* ---- input type and height ---- */
@media (pointer: coarse) {
  button, select, input:not([type=checkbox]):not([type=range]), .car-chips button, .map-tools button { min-height: 48px; }
  .map-tools button { min-width: 48px; }
  .shortcut-hint { display: none; }
}
@media (pointer: fine) {
  .card { padding: 16px; }
  td, th { padding: 7px 6px; }
  .lines li { padding: 6px 0; }
  .car-chips button { padding: 6px 10px; }
}
body[data-height=compact] header { padding: 6px 14px; }
body[data-height=compact] header .brand small { display: none; }
body[data-height=compact] .map-box { max-height: calc(100dvh - 140px); }
body[data-height=compact] .session-bar { padding: 10px 12px; }

/* Compact keeps the chrome small: the car selector sticks to the top, the panel starts right under it. */
body[data-size=compact] .connected-bar { gap: 8px; }
body[data-size=compact] .connected-bar #status { flex: 1 1 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 12px; }
body[data-size=compact] .connected-bar button { flex: 1; padding: 8px; }
body[data-size=compact] .session-bar { padding: 10px 12px; gap: 8px; }
body[data-size=compact] .session-bar label { font-size: 0; }
body[data-size=compact] .session-bar label select { margin-top: 0; font-size: 15px; }
body[data-size=compact] .session-bar .actions button { flex: 1; padding: 8px; }
body[data-size=compact] .session-bar .actions { flex: 1 1 100%; flex-wrap: nowrap; }
body[data-size=compact] .car-chips { position: sticky; top: 0; z-index: 4; background: var(--background); padding: 8px 0; margin: 0; }
body[data-size=compact][data-watch] .car-chips { position: static; }
#message:empty { display: none; }
/* Short windows (phone landscape, a DeX window dragged low): one small banner, slimmer bars. */
body[data-height=compact] .highlight:not(:first-child) { display: none; }
body[data-height=compact] .highlight { padding: 6px 10px; font-size: 13px; }
body[data-height=compact] .connected-bar { margin-bottom: 6px; }
body[data-height=compact] .session-bar { padding: 8px 12px; }
body[data-height=compact] .session-bar label { font-size: 0; }
body[data-height=compact] .session-bar label select { margin-top: 0; font-size: 14px; }
.map-tip.below { transform: translate(-50%, 22px); }
