:root {
  --bg: #0b0c0f;
  --panel: #121318;
  --panel2: #17181e;
  --line: #25272e;
  --text: #dde1e8;
  --dim: #82878f;
  --accent: #22d3ee;   /* player / lap A */
  --ref: #fb923c;      /* reference / lap B */
  --green: #34d399;
  --red: #f87171;
  --yellow: #fbbf24;
  --f1red: #e10600;    /* chrome accent, never a data color */
  --card: linear-gradient(180deg, rgba(25,26,32,.92), rgba(14,15,18,.9));
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.45 "Titillium Web", -apple-system, "Segoe UI", Roboto, sans-serif;
  /* Titillium has no 900-italic face; never synthesize (it clips glyphs) */
  font-synthesis: none;
  display: flex; flex-direction: column; overflow: hidden;
}

/* ---------- header ---------- */
header {
  display: flex; align-items: center; gap: 14px;
  padding: 9px 16px; border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #16171c, #101114);
}
.brand {
  font-weight: 700; font-style: italic; font-size: 19px;
  letter-spacing: .5px; display: flex; align-items: center; gap: 6px;
}
.brand b {
  background: var(--f1red); color: #fff; font-weight: 700;
  padding: 0 7px 1px 6px; border-radius: 5px;
  transform: skewX(-8deg); display: inline-block;
}
.brand span { color: var(--text); letter-spacing: 2px; }
.spacer { flex: 1; }
.chip {
  font-size: 11px; font-weight: 700; letter-spacing: 1px;
  padding: 3px 10px; border-radius: 999px;
}
.chip.live { background: #052e1f; color: var(--green); }
.chip.live::before { content: "● "; animation: blink 1.2s infinite; }
.chip.idle { background: #1d2230; color: var(--dim); }
.chip.warn { background: #3a2410; color: var(--yellow); }
.chip.driver-chip {
  background: var(--card); border: 1px solid var(--line); color: var(--accent);
  font-family: inherit; font-size: 10px; font-weight: 800; font-style: italic;
  cursor: pointer; display: inline-flex; align-items: center; gap: 4px;
  transition: all 0.15s ease;
}
.chip.driver-chip:hover { border-color: var(--accent); background: #123a44; }
@keyframes blink { 50% { opacity: .3; } }
#status-detail { color: var(--dim); font-size: 12px; }
/* ---------- themed dropdowns (native select stays hidden inside) ---------- */
.dd { position: relative; display: inline-block; }
.dd select { display: none; }
.dd-btn {
  display: flex; align-items: center; gap: 10px; max-width: 360px;
  background: var(--panel2); color: var(--text);
  border: 1px solid var(--line); border-radius: 6px; padding: 6px 11px;
  font-family: inherit; font-size: 12px; font-weight: 600; cursor: pointer;
}
.dd-btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dd-btn:hover { border-color: var(--accent); }
.dd-arr {
  color: var(--f1red); font-style: normal; font-size: 9px;
  transition: transform .15s;
}
.dd.open .dd-arr { transform: rotate(180deg); }
.dd-menu {
  display: none; position: absolute; top: calc(100% + 6px); right: 0;
  min-width: 100%; z-index: 60; padding: 5px;
  background:
    repeating-linear-gradient(45deg, rgba(255,255,255,.022) 0 2px, transparent 2px 5px),
    linear-gradient(168deg, rgba(40,48,64,.97), rgba(10,12,17,.99) 58%);
  border: 1px solid #2c3444;
  border-radius: 3px 12px 3px 12px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.06), 0 14px 34px rgba(0,0,0,.6);
  white-space: nowrap;
}
.dd-menu::before {
  content: ""; position: absolute; left: 0; top: 0; height: 2px; width: 62%;
  background: linear-gradient(90deg, var(--f1red), rgba(225,6,0,0));
}
.dd.open .dd-menu { display: block; }
.dd-item {
  padding: 6px 12px; font-size: 12px; color: var(--text);
  border-radius: 4px; cursor: pointer;
}
.dd-item:hover { background: #1b2330; color: var(--accent); }
.dd-item.sel {
  color: var(--accent); font-weight: 700;
  border-left: 3px solid var(--f1red); border-radius: 0 4px 4px 0;
}

/* ---------- layout ---------- */
#layout { flex: 1; display: flex; min-height: 0; }
#sidebar {
  width: 310px; flex: none; border-right: 1px solid var(--line);
  background: var(--panel); display: flex; flex-direction: column; min-height: 0;
}
.side-head {
  display: flex; justify-content: space-between; align-items: baseline;
  gap: 8px;
  padding: 10px 12px 6px; font-size: 11px; font-weight: 700;
  letter-spacing: 1px; color: var(--dim);
}
.hint { font-weight: 400; letter-spacing: 0; font-size: 10px; flex: 1; }
#side-toggle {
  background: #14202b; border: 1px solid #2c4a56; color: var(--accent);
  font-family: inherit; font-size: 13px; font-weight: 700;
  border-radius: 5px; padding: 1px 10px; cursor: pointer; line-height: 1.4;
}
#side-toggle:hover { border-color: var(--accent); background: #123a44; }
#side-rail {
  display: none; cursor: pointer; align-items: center;
  flex-direction: column; gap: 10px; padding-top: 10px; height: 100%;
}
#side-rail .rail-arrow {
  font-size: 13px; font-weight: 700; color: var(--dim);
  border: 1px solid var(--line); border-radius: 5px; padding: 0 6px 2px;
}
#side-rail b {
  writing-mode: vertical-rl; font-size: 10px; font-weight: 700;
  font-style: italic; letter-spacing: 2px; color: var(--dim);
}
#side-rail:hover .rail-arrow, #side-rail:hover b { color: var(--accent); }
#sidebar.collapsed { width: 32px; }
#sidebar.collapsed > :not(#side-rail) { display: none; }
#sidebar.collapsed #side-rail { display: flex; }
#lap-controls {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 0 10px 8px;
  border-bottom: 1px solid var(--line);
}
.lap-ctrl-row {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
}
.seg.small button { padding: 4px 7px; font-size: 9px; letter-spacing: 1px; }
.toggle {
  background: none; border: 1px solid var(--line); color: var(--dim);
  font-family: inherit; font-size: 9px; font-weight: 700; font-style: italic;
  letter-spacing: .5px; border-radius: 7px; padding: 4px 8px; cursor: pointer;
  white-space: nowrap; text-align: center;
}
.toggle:hover { border-color: var(--dim); }
.toggle.on { background: #123a44; border-color: var(--accent); color: var(--accent); }
.driver-filter-sel, .session-filter-sel {
  flex: 1; min-width: 0;
  background: var(--card); border: 1px solid var(--line); color: var(--accent);
  font-family: inherit; font-size: 9px; font-weight: 700; font-style: italic;
  letter-spacing: .5px; border-radius: 7px; padding: 4px 6px; cursor: pointer;
  text-overflow: ellipsis; outline: none; text-align: left;
}
.driver-filter-sel:focus, .session-filter-sel:focus { border-color: var(--accent); }
.multi-select-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
  display: flex;
}
#driver-multi-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}
#driver-btn-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ms-arrow {
  margin-left: 4px;
  font-size: 8px;
  opacity: 0.7;
}
.multi-select-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  width: 170px;
  max-width: 220px;
  background: #111622;
  border: 1px solid var(--line);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.75);
  border-radius: 8px;
  z-index: 1000;
  padding: 6px 0;
  font-size: 10px;
}
.ms-menu-header {
  border-bottom: 1px solid var(--line);
  padding-bottom: 4px;
  margin-bottom: 4px;
}
.ms-check-list {
  max-height: 180px;
  overflow-y: auto;
}
.ms-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px;
  cursor: pointer;
  color: var(--text);
  font-family: inherit;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .5px;
  user-select: none;
  transition: background 0.15s;
}
.ms-item:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--accent);
}
.ms-item input[type="checkbox"] {
  accent-color: var(--accent);
  cursor: pointer;
  width: 13px;
  height: 13px;
}
.ms-item.select-all {
  color: var(--accent);
}
#sort-seg { flex: 1; }
#sort-seg button { flex: 1; padding: 4px 6px; }
#weather-seg { flex: 1.1; }
#weather-seg button { flex: 1; padding: 4px 5px; }
#valid-toggle { flex: 1; }
#asst-toggle { flex: 1; }
.live-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.18) 0%, rgba(18, 22, 32, 0.85) 100%);
  border-bottom: 1px solid rgba(239, 68, 68, 0.4);
  padding: 8px 12px;
  position: relative;
  overflow: hidden;
}
.live-pulse-ring {
  width: 10px;
  height: 10px;
  background: #ef4444;
  border-radius: 50%;
  box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7);
  animation: pulse-red 1.5s infinite;
  flex-shrink: 0;
}
@keyframes pulse-red {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.8); }
  70% { transform: scale(1.1); box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}
.live-badge-info {
  flex: 1;
  min-width: 0;
}
.live-tag-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .5px;
}
.live-pill {
  color: #ef4444;
  text-transform: uppercase;
}
.live-driver-name {
  color: #ffffff;
  font-weight: 900;
  font-style: italic;
  font-size: 11px;
}
.live-tele-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 10px;
  color: var(--dim);
  font-weight: 700;
  margin-top: 2px;
}
.live-timer {
  color: var(--accent);
  font-family: monospace;
  font-size: 11px;
}
.live-speed {
  color: #fbbf24;
  font-size: 9px;
}
.live-watch-btn {
  background: #ef4444;
  color: #fff;
  border: none;
  font-family: inherit;
  font-size: 10px;
  font-weight: 900;
  font-style: italic;
  letter-spacing: 1px;
  padding: 5px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
}
.live-watch-btn:hover {
  background: #dc2626;
  box-shadow: 0 0 10px rgba(239, 68, 68, 0.6);
}
.live-watch-btn.watching {
  background: transparent;
  border: 1px solid var(--accent);
  color: var(--accent);
  box-shadow: 0 0 8px rgba(34, 211, 238, 0.4);
}
.driver-leaderboard {
  border-bottom: 1px solid var(--line); background: rgba(18, 22, 32, 0.7);
  padding: 6px 10px; font-size: 11px;
}
.dl-head {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 9px; font-weight: 800; letter-spacing: 1px; color: var(--dim);
  margin-bottom: 5px; text-transform: uppercase;
}
.dl-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 3px 6px; border-radius: 4px; cursor: pointer; font-size: 11px;
}
.dl-row:hover { background: var(--panel2); }
.dl-left { display: flex; align-items: center; gap: 6px; min-width: 0; }
.dl-pos { font-size: 10px; font-weight: 800; color: var(--dim); width: 14px; text-align: right; }
.dl-name { font-weight: 700; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dl-row.rec .dl-name { color: #d8b4fe; }
.dl-right { display: flex; align-items: center; gap: 8px; font-variant-numeric: tabular-nums; }
.dl-time { font-weight: 700; color: var(--text); }
.dl-gap { font-size: 10px; color: var(--dim); font-weight: 600; width: 44px; text-align: right; }
.lap-row .pb {
  color: var(--green); font-size: 9px; font-weight: 800; letter-spacing: 1px;
  margin-left: 3px;
}
.lap-row .rec {
  color: #c084fc; font-size: 9px; font-weight: 800; letter-spacing: 1px;
  margin-left: 3px; text-shadow: 0 0 6px rgba(192, 132, 252, 0.4);
}
#lap-list { overflow-y: auto; flex: 1; }
#list-foot {
  flex: none; border-top: 1px solid var(--line); padding: 5px 12px;
  text-align: right;
}
#list-foot button {
  background: none; border: none; color: #58627a; cursor: pointer;
  font-family: inherit; font-size: 10px; letter-spacing: .4px;
}
#list-foot button:hover { color: #f87171; }
.lap-row .rank {
  flex: none; width: 16px; text-align: right; font-size: 10px;
  font-weight: 800; font-style: italic; color: var(--dim);
}
.lap-row .gap { font-size: 10px; font-weight: 600; color: var(--dim); }
.sess-head {
  position: sticky; top: 0; z-index: 1;
  padding: 6px 12px 4px; font-size: 10px; font-weight: 700;
  letter-spacing: .8px; color: var(--dim); text-transform: uppercase;
  background: var(--panel); border-bottom: 1px solid var(--line);
  cursor: pointer; user-select: none;
}
.sess-head:hover { color: var(--text); }
.sess-head .tri { margin-right: 5px; color: #4d5a70; }
.lap-row {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px; cursor: pointer; border-bottom: 1px solid #161b26;
}
.lap-row:hover { background: var(--panel2); }
.lap-row.sel { background: #0c2b33; box-shadow: inset 3px 0 0 var(--accent); }
.lap-row.ref-sel { box-shadow: inset -3px 0 0 var(--ref); }
.lap-row.sel.ref-sel { box-shadow: inset 3px 0 0 var(--accent), inset -3px 0 0 var(--ref); }
.badge.player { background: #123a44; color: var(--accent); }
.badge.rival  { background: #3a2410; color: var(--ref); }
.badge.pb_ghost { background: #262c3a; color: #9aa7bd; }
.badge.guest { background: #2a2140; color: #b7a4f5; }   /* imported lap */

/* F1 TV Broadcast Graphics */
.f1-driver-badge {
  display: flex; align-items: center; gap: 5px; flex: none;
  background: #141722; border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 4px; padding: 2px 5px 2px 0; height: 22px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}
.f1-team-bar {
  width: 4px; height: 100%; border-radius: 3px 0 0 3px; flex: none;
}
.f1-team-bar.small {
  width: 3px; height: 12px; border-radius: 2px;
}
.f1-code {
  font-family: 'Titillium Web', sans-serif; font-size: 11px;
  font-weight: 900; font-style: italic; letter-spacing: 1px;
  color: #f8fafc; padding: 0 1px; line-height: 1;
}
.f1-tyre {
  display: inline-flex; align-items: center; justify-content: center;
  width: 15px; height: 15px; border-radius: 50%;
  border: 1.5px solid currentColor; background: #0b0d13;
  flex: none; box-sizing: border-box;
}
.f1-tyre .tyre-inner {
  font-family: 'Titillium Web', sans-serif;
  font-size: 8px; font-weight: 900; font-style: normal;
  line-height: 1; text-align: center;
}
.lap-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.lap-top { display: flex; align-items: center; gap: 6px; }
.lap-time { font-weight: 700; font-variant-numeric: tabular-nums; display: flex; align-items: center; gap: 5px; font-size: 13px; }
.lap-actions { display: flex; align-items: center; gap: 4px; flex: none; }
.lap-sub {
  font-size: 10px; color: var(--dim); font-variant-numeric: tabular-nums;
  display: flex; align-items: center; gap: 8px;
}
.sec-item { display: inline-flex; align-items: center; gap: 3px; font-weight: 600; }
.sec-item .s1 { color: #f87171; font-size: 9px; }
.sec-item .s2 { color: #60a5fa; font-size: 9px; }
.sec-item .s3 { color: #fbbf24; font-size: 9px; }
.lap-row .inv { color: var(--red); font-size: 10px; font-weight: 700; }
.refbtn {
  background: rgba(255, 255, 255, 0.04); border: 1px solid #3b4254; color: #94a3b8;
  font-family: 'Titillium Web', sans-serif; font-size: 11px; font-weight: 900; font-style: italic;
  letter-spacing: 1px; border-radius: 5px; padding: 6px 12px; cursor: pointer;
  line-height: 1.2; flex: none; transition: all 0.15s ease;
}
.refbtn:hover {
  border-color: var(--ref); color: var(--ref);
  background: rgba(251, 146, 60, 0.18); transform: scale(1.04);
}
.refbtn.on {
  background: var(--ref); border-color: var(--ref); color: #1b0f02; font-weight: 900;
  box-shadow: 0 0 10px rgba(251, 146, 60, 0.35);
}
.del {
  background: none; border: none; color: #3d4657; font-size: 13px;
  cursor: pointer; padding: 2px 4px; visibility: hidden; line-height: 1;
}
.lap-row:hover .del { visibility: visible; }
.del:hover { color: var(--red); }
.empty-list { padding: 18px 14px; color: var(--dim); font-size: 12px; }

/* full-window target shown while a file is dragged over the app */
#drop-veil {
  position: fixed; inset: 0; z-index: 60;
  display: flex; align-items: center; justify-content: center;
  background: rgba(11, 12, 15, .78);
  pointer-events: none;   /* keep drag events flowing to the window */
}
#drop-veil div {
  border: 2px dashed var(--accent); color: var(--accent);
  border-radius: 12px; padding: 26px 48px;
  font-size: 18px; font-weight: 700; font-style: italic; letter-spacing: 3px;
}

/* ---------- main / stage ---------- */
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
#stage {
  position: relative; flex: 1; min-height: 220px;
  /* faint carbon-fibre weave */
  background:
    repeating-linear-gradient(45deg, rgba(255,255,255,.015) 0 2px, transparent 2px 5px),
    repeating-linear-gradient(-45deg, rgba(255,255,255,.015) 0 2px, transparent 2px 5px);
}
#map { position: absolute; inset: 0; width: 100%; height: 100%; }
#map-legend {
  position: absolute; left: 12px; top: 10px; font-size: 11px;
  color: var(--dim); display: flex; gap: 14px;
}
#map-legend .k::before {
  content: "●"; margin-right: 4px;
}
#map-legend .kA::before { color: var(--accent); }
#map-legend .kB::before { color: var(--ref); }

/* ---------- map toolbar ---------- */
#map-toolbar {
  position: absolute; left: 12px; right: 12px; bottom: 12px; display: flex;
  align-items: center; gap: 12px; pointer-events: none;
}
#map-toolbar > * { pointer-events: auto; }
.seg {
  display: flex; background: var(--card); border: 1px solid var(--line);
  border-radius: 7px; overflow: hidden;
}
.seg button {
  background: none; border: none; color: var(--dim); cursor: pointer;
  font-family: inherit; font-size: 10px; font-weight: 700; font-style: italic;
  letter-spacing: 1.5px; padding: 6px 14px;
}
.seg button.on { background: var(--f1red); color: #fff; }
.seg button:disabled { opacity: .35; cursor: default; }
#color-legend {
  display: flex; align-items: center; gap: 7px;
  background: var(--card); border: 1px solid var(--line); border-radius: 7px;
  padding: 5px 10px;
  font-size: 10px; color: var(--dim); font-variant-numeric: tabular-nums;
}
#leg-title {
  font-size: 9px; font-weight: 700; font-style: italic; letter-spacing: 1.5px;
  color: var(--text); border-left: 3px solid var(--f1red);
  padding-left: 6px; margin-right: 3px;
}
#leg-lo, #leg-hi { font-weight: 700; letter-spacing: .5px; }
#leg-bar {
  width: 84px; height: 7px; border-radius: 4px;
  outline: 1px solid rgba(219,226,238,.18);
}
#zoom-chip {
  display: flex; align-items: center; gap: 8px;
  background: var(--card); border: 1px solid var(--line); border-radius: 7px;
  padding: 5px 10px; font-size: 10px; font-weight: 700;
  color: var(--accent); font-variant-numeric: tabular-nums;
}
#zoom-chip button {
  background: none; border: 1px solid #333947; color: var(--dim);
  font-family: inherit; font-size: 9px; font-weight: 800; font-style: italic;
  letter-spacing: 1px; border-radius: 4px; padding: 2px 7px; cursor: pointer;
}
#zoom-chip button:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- broadcast cards (telemetry / timing / setup) ----------
   Shared look: carbon weave over a steep dark gradient, asymmetric
   corners, a red racing stripe fading out along the top edge. */
#hud, #sector-card, #setup-card {
  background:
    repeating-linear-gradient(45deg, rgba(255,255,255,.022) 0 2px, transparent 2px 5px),
    linear-gradient(168deg, rgba(40,48,64,.88), rgba(10,12,17,.95) 58%);
  border: 1px solid #2c3444;
  border-radius: 3px 14px 3px 14px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.06), 0 10px 32px rgba(0,0,0,.55);
}
#hud::before, #sector-card::before, #setup-card::before {
  content: ""; position: absolute; left: 0; top: 0; height: 2px; width: 62%;
  background: linear-gradient(90deg, var(--f1red), rgba(225,6,0,0));
  border-radius: 3px 0 0 0;
}

/* ---------- broadcast card tags ---------- */
.card-tag {
  position: absolute; top: -8px; left: 12px;
  background: var(--f1red); color: #fff;
  font-size: 8px; font-weight: 700; font-style: italic;
  letter-spacing: 1.5px; padding: 2px 9px; border-radius: 3px;
  transform: skewX(-12deg);
}

/* ---------- sector card ---------- */
#sector-card {
  position: absolute; right: 14px; top: 10px;
  padding: 8px 12px;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  font-size: 12px; font-variant-numeric: tabular-nums;
}
/* every red card tag is clickable: TIMING and TELEMETRY fold in place
   (▾/▸), SETUP closes (it reopens from the toolbar button) */
#sector-card .card-tag, #hud .card-tag, #setup-card .card-tag { cursor: pointer; }
#sector-card .card-tag:hover, #hud .card-tag:hover,
#setup-card .card-tag:hover { filter: brightness(1.25); }
/* folded: the card reduces to its floating TIMING tag, same spot */
#sector-card.closed {
  width: 96px; height: 8px; padding: 0;
  background: none; border: none; box-shadow: none;
  backdrop-filter: none; -webkit-backdrop-filter: none;
}
#sector-card.closed::before { display: none; }
#sector-card table { border-collapse: collapse; }
#sector-card th {
  font-size: 9px; font-weight: 800; letter-spacing: 1px; color: var(--dim);
  padding: 2px 10px 3px 0; text-align: right;
}
#sector-card th.s1 { color: #f87171; }
#sector-card th.s2 { color: #60a5fa; }
#sector-card th.s3 { color: #fbbf24; }
#sector-card td {
  padding: 2px 10px 2px 0; text-align: right; color: var(--text);
}
#sector-card td.rowlbl {
  font-size: 9px; font-weight: 800; letter-spacing: 1px; color: var(--dim);
  text-align: left; padding-right: 8px;
}
#sector-card td.neg { color: var(--green); }
#sector-card td.pos { color: var(--red); }
#sector-card td.laptime { font-weight: 700; }

/* ---------- setup / assists card ---------- */
#setup-card {
  position: absolute; left: 14px; top: 34px; z-index: 6;
  /* no inner scroll and no backdrop-filter: Chromium paints a composited
     scrollable overlay above the canvas with a white backing store */
  padding: 10px 12px 8px;
  font-size: 11px; font-variant-numeric: tabular-nums;
}
#setup-card table { border-collapse: collapse; }
#setup-card th {
  font-size: 9px; font-weight: 800; letter-spacing: 1px;
  padding: 2px 10px 3px 0; text-align: right;
}
#setup-card th.cA { color: var(--accent); }
#setup-card th.cB { color: var(--ref); }
#setup-card td { padding: 1px 10px 1px 0; text-align: right; color: var(--text); }
#setup-card td.rowlbl {
  color: var(--dim); text-align: left; padding-right: 12px; font-size: 10px;
}
#setup-card td.grp {
  font-size: 9px; font-weight: 800; letter-spacing: 1px; color: #5b6576;
  text-align: left; text-transform: uppercase; padding-top: 7px; max-width: 240px;
}
#setup-card td.asst-cell {
  max-width: 150px; white-space: normal; font-size: 10px; line-height: 1.5;
}

/* ---------- halo hud (floating card, wheel above the dial) ---------- */
#hud {
  position: absolute; right: 14px; bottom: 12px; width: 255px;
  cursor: grab;
  padding: 12px 14px 8px;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  touch-action: none; user-select: none;
}
#hud.drag { cursor: grabbing; }
#hud-drag {
  position: absolute; top: -8px; right: 64px; z-index: 1;
  background: var(--card); border: 1px solid var(--line); color: var(--dim);
  font-size: 8px; font-weight: 700; font-style: italic;
  letter-spacing: 1.5px; padding: 2px 9px; border-radius: 3px;
  transform: skewX(-12deg); cursor: grab;
}
#hud:hover #hud-drag, #hud.drag #hud-drag {
  border-color: var(--accent); color: var(--accent);
}
#hud.drag #hud-drag { cursor: grabbing; }
#hud-steer-btn {
  position: absolute; top: -8px; right: 12px; z-index: 1;
  background: var(--card); border: 1px solid var(--line); color: var(--dim);
  font-family: inherit; font-size: 8px; font-weight: 700; font-style: italic;
  letter-spacing: 1.5px; padding: 2px 9px; border-radius: 3px;
  transform: skewX(-12deg); cursor: pointer;
}
#hud-steer-btn.on { border-color: var(--accent); color: var(--accent); }
/* folded: like the TIMING card, only the floating tag remains */
#hud.closed {
  width: 122px; height: 8px; padding: 0;
  background: none; border: none; box-shadow: none;
  backdrop-filter: none; -webkit-backdrop-filter: none;
  cursor: default;
}
#hud.closed::before { display: none; }
#hud.closed #halo, #hud.closed #hud-delta,
#hud.closed #hud-drag, #hud.closed #hud-steer-btn { display: none; }
#halo { width: 100%; display: block; }
.arc-bg { fill: none; stroke: #222a39; stroke-width: 11; stroke-linecap: round; }
.arc { fill: none; stroke-width: 11; stroke-linecap: round; }
.arc.thr { stroke: var(--green); filter: drop-shadow(0 0 4px rgba(52,211,153,.5)); }
.arc.brk { stroke: var(--red); filter: drop-shadow(0 0 4px rgba(248,113,113,.5)); }
.arc-tick { stroke: #2e3748; stroke-width: 2; }
.pill.on-x { fill: #064e3b; stroke: #10b981; }
.speed {
  /* upright face + skewX on the element (see index.html): font-level italic
     ink overhangs its tabular advance box and some rasterizers clip it,
     shaving the right edge of the last digit */
  fill: var(--text); font-size: 56px; font-weight: 700;
  font-family: "Titillium Web", sans-serif;
  text-anchor: middle; font-variant-numeric: tabular-nums;
}
.unit { fill: var(--dim); font-size: 10px; text-anchor: middle; letter-spacing: 3px; }
.gear-badge { fill: #171d29; stroke: #2a3242; }
.gear { fill: var(--yellow); font-size: 19px; font-weight: 800; text-anchor: middle; }
.lbl { fill: #5b6576; font-size: 9px; text-anchor: middle; letter-spacing: 2px; font-weight: 700; }
.pill { fill: #171d29; stroke: #2a3242; }
.pill.on-ot { fill: #3b0764; stroke: #a855f7; }
.pill-txt { fill: #5b6576; font-size: 10px; font-weight: 800; text-anchor: middle; letter-spacing: 1px; }
.wheel-grip {
  fill: none; stroke: #3d4452; stroke-width: 17; stroke-linecap: round;
}
.wheel-gripline line { stroke: #2b3039; stroke-width: 2; stroke-linecap: round; }
.wheel-arm line { stroke: #333947; stroke-width: 9; stroke-linecap: round; }
.wheel-plate { fill: #282d38; stroke: #191d25; stroke-width: 1.5; }
.wheel-screen { fill: #0c0f14; stroke: #454d5c; stroke-width: 1.5; }
.wheel-led circle { fill: #3a4150; }
.wheel-rotary circle { fill: #3d4452; stroke: #1d2129; stroke-width: 1.5; }
.wheel-rotary line { stroke: #b7bfcc; stroke-width: 1.8; stroke-linecap: round; }
.wheel-marker { fill: var(--accent); }
.steer-val {
  fill: var(--text); font-size: 15px; font-weight: 700;
  text-anchor: middle; font-variant-numeric: tabular-nums;
}
.rev-seg { fill: #1c2331; }
.hud-delta {
  text-align: center; font-size: 19px; font-weight: 800;
  font-variant-numeric: tabular-nums; margin-top: 2px;
}
.hud-delta.pos { color: var(--red); }
.hud-delta.neg { color: var(--green); }

/* ---------- transport ---------- */
#transport {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 14px; border-top: 1px solid var(--line); background: var(--panel);
}
#btn-play {
  width: 34px; height: 30px; border-radius: 6px; border: 1px solid var(--line);
  background: var(--panel2); color: var(--text); font-size: 14px; cursor: pointer;
}
#btn-play:hover { border-color: var(--accent); }
#transport .dd { width: 58px; flex: none; }
#transport .dd-btn {
  width: 100%; padding: 6px 7px; gap: 3px; justify-content: space-between;
}
#scrub {
  flex: 1; -webkit-appearance: none; appearance: none;
  height: 7px; border-radius: 4px; background: #1c2331; outline: none;
}
#scrub::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 15px; height: 15px; border-radius: 50%;
  background: var(--text); border: 3px solid var(--accent);
  cursor: pointer; box-shadow: 0 1px 6px rgba(0,0,0,.6);
}
#time-display {
  flex: none; width: 70px; text-align: right;
  font-variant-numeric: tabular-nums; font-weight: 700; font-style: italic;
  font-size: 15px;
}

/* ---------- charts ---------- */
#splitter {
  flex: none; height: 8px; cursor: row-resize; position: relative;
  background: var(--panel); border-top: 1px solid var(--line);
  touch-action: none;
}
#splitter::after {
  content: ""; position: absolute; left: 50%; top: 3px;
  width: 46px; height: 3px; transform: translateX(-50%);
  border-radius: 2px; background: #2a3242;
}
#splitter:hover::after, #splitter.drag::after { background: var(--accent); }
#charts {
  flex: none; height: 40%; min-height: 130px;
  display: flex; flex-direction: column;
  padding: 2px 14px 10px; background: var(--panel);
}
.chart-row {
  flex: 1; min-height: 0;
  display: flex; align-items: stretch; gap: 8px; margin-top: 4px;
}
.chart-row.tall { flex: 1.5; }
/* the chart canvases and the scrub bar share the same x range:
   label width + row gap (8px) = play btn + speed select + gaps on the
   left, and the value cell + row gap = time display + gaps on the right */
.chart-row label {
  width: 104px; flex: none; font-size: 9px; font-weight: 700;
  letter-spacing: 1px; color: var(--dim); padding-top: 4px; text-align: right;
}
/* value of each trace at the playhead, at the right end of its row:
   lap A always in its channel color, the reference lap in the same
   neutral grey-white as its ghost line */
.cv {
  width: 72px; flex: none; align-self: center;
  display: flex; flex-direction: column; gap: 1px;
  font-size: 12px; font-weight: 700; font-style: italic;
  font-variant-numeric: tabular-nums; color: var(--text); line-height: 1.25;
}
.cv .vB { color: #b9c2d0; }
#cv-delta.pos { color: var(--red); }
#cv-delta.neg { color: var(--green); }
#cvA-speed { color: #22d3ee; }
#cvA-thr   { color: #34d399; }
#cvA-brk   { color: #f87171; }
#cvA-steer { color: #a78bfa; }
#cvA-gear  { color: #38bdf8; }
#cvA-ersstore { color: #f59e0b; }
#cvA-ers   { font-size: 10px; }
canvas.chart { flex: 1; min-width: 0; min-height: 0; cursor: crosshair; }

/* ---------- empty ---------- */
#empty-hint {
  position: absolute; inset: 0; pointer-events: none;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 10px;
  text-align: center; color: var(--dim); padding: 30px; z-index: 5;
}
#empty-hint h2 { color: var(--text); font-size: 20px; }
#empty-hint p { max-width: 480px; font-size: 13px; }

/* ================================================================
   RESPONSIVE DESIGN (Tablets & Mobile Devices)
   ================================================================ */

.mobile-laps-btn { display: none; }
.sidebar-backdrop { display: none; }

@media (max-width: 900px) {
  #sector-card {
    font-size: 11px;
    padding: 6px 10px;
  }
  #status-detail {
    display: none;
  }
}

@media (max-width: 768px) {
  /* Header */
  header {
    padding: 8px 10px;
    gap: 8px;
  }
  .brand {
    font-size: 14px;
    letter-spacing: 1px;
  }
  .mobile-laps-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: #14202b;
    border: 1px solid #2c4a56;
    color: var(--accent);
    font-family: inherit;
    font-size: 11px;
    font-weight: 800;
    font-style: italic;
    letter-spacing: 1px;
    border-radius: 6px;
    padding: 5px 9px;
    cursor: pointer;
    line-height: 1;
    transition: all 0.15s ease;
  }
  .mobile-laps-btn:active {
    background: #123a44;
    border-color: var(--accent);
  }
  #status-chip, #pace-chip {
    font-size: 9px;
    padding: 3px 6px;
    letter-spacing: 1px;
  }
  #track-select {
    max-width: 155px;
    font-size: 11px;
  }

  /* Backdrop for off-canvas drawer */
  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    z-index: 90;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
  }
  .sidebar-backdrop.active {
    opacity: 1;
    pointer-events: auto;
  }

  /* Off-canvas mobile sidebar drawer */
  #sidebar {
    position: fixed;
    top: 48px;
    bottom: 0;
    left: 0;
    width: 320px;
    max-width: 85vw;
    z-index: 100;
    box-shadow: 6px 0 24px rgba(0, 0, 0, 0.8);
    transform: translateX(-100%);
    transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    background: var(--panel);
  }
  #sidebar.mobile-open {
    transform: translateX(0);
  }
  #side-rail {
    display: none !important;
  }
  #sidebar.collapsed {
    width: 320px;
  }
  #sidebar.collapsed > :not(#side-rail) {
    display: flex !important;
  }

  /* Stage & Floating HUD */
  #stage {
    min-height: 180px;
  }
  #hud {
    width: 220px;
    right: 8px;
    bottom: 8px;
    padding: 10px 12px 6px;
  }
  #hud.closed {
    width: 110px;
  }
  #sector-card {
    right: 8px;
    top: 8px;
    max-width: calc(100vw - 16px);
  }
  #map-toolbar {
    left: 8px;
    right: 8px;
    bottom: 8px;
    flex-wrap: wrap;
    gap: 6px;
  }
  #color-legend {
    padding: 4px 7px;
  }
  #leg-bar {
    width: 60px;
  }

  /* Splitter & Charts */
  #splitter {
    height: 12px;
  }
  #splitter::after {
    height: 4px;
    width: 50px;
    top: 4px;
  }
  #charts {
    padding: 2px 8px 8px;
  }
  .chart-row {
    gap: 5px;
    margin-top: 3px;
  }
  .chart-row label {
    width: 55px;
    font-size: 8px;
    letter-spacing: 0.5px;
    padding-top: 2px;
  }
  .cv {
    width: 52px;
    font-size: 10px;
    gap: 0;
  }

  /* Transport bar */
  #transport {
    padding: 6px 8px;
    gap: 6px;
  }
  #btn-play {
    width: 36px;
    height: 32px;
    font-size: 15px;
  }
  #time-display {
    width: 58px;
    font-size: 13px;
  }
}

@media (max-width: 480px) {
  .brand b {
    padding: 1px 4px;
  }
  .brand span {
    display: none;
  }
  #track-select {
    max-width: 130px;
    font-size: 10px;
  }
  .chart-row label {
    width: 44px;
    font-size: 7.5px;
    letter-spacing: 0;
  }
  .cv {
    width: 44px;
    font-size: 9px;
  }
  #time-display {
    width: 52px;
    font-size: 12px;
  }
  #transport .dd {
    width: 48px;
  }
  #transport .dd-btn {
    padding: 5px 4px;
    font-size: 10px;
  }
}

/* ---------- driver registration modal ---------- */
.driver-modal {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(7, 9, 13, 0.88);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.driver-modal-card {
  position: relative;
  background:
    repeating-linear-gradient(45deg, rgba(255,255,255,.022) 0 2px, transparent 2px 5px),
    linear-gradient(168deg, rgba(32,40,56,.96), rgba(11,14,20,.99) 60%);
  border: 1px solid #2e384b;
  border-radius: 4px 16px 4px 16px;
  padding: 34px 28px 24px;
  max-width: 400px; width: 100%;
  text-align: center;
  box-shadow: 0 16px 48px rgba(0,0,0,0.8), inset 0 1px 0 rgba(255,255,255,0.08);
}
.driver-modal-card::before {
  content: ""; position: absolute; left: 0; top: 0; height: 3px; width: 70%;
  background: linear-gradient(90deg, var(--f1red), transparent);
  border-radius: 4px 0 0 0;
}
.driver-modal-card h2 {
  font-family: 'Titillium Web', sans-serif;
  font-size: 19px; font-weight: 900; font-style: italic;
  letter-spacing: 1.5px; color: #fff; margin: 0 0 8px;
}
.driver-modal-card p {
  font-size: 12px; color: var(--dim); margin-bottom: 20px; line-height: 1.5;
}
#modal-driver-input {
  width: 100%; box-sizing: border-box;
  background: var(--card); border: 1.5px solid var(--line);
  color: var(--accent); font-family: 'Titillium Web', sans-serif;
  font-size: 16px; font-weight: 700; font-style: italic;
  letter-spacing: 1.5px; border-radius: 8px; padding: 11px 14px;
  text-transform: uppercase; text-align: center; outline: none;
  margin-bottom: 14px;
  transition: all 0.2s ease;
}
#modal-driver-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 14px rgba(34, 211, 238, 0.25);
}
.driver-submit-btn {
  width: 100%; box-sizing: border-box;
  background: var(--f1red); border: none; color: #fff;
  font-family: 'Titillium Web', sans-serif;
  font-size: 14px; font-weight: 900; font-style: italic;
  letter-spacing: 2px; border-radius: 8px; padding: 12px 18px;
  cursor: pointer; transition: all 0.15s ease;
}
.driver-submit-btn:hover {
  background: #ff1a1a;
  box-shadow: 0 0 16px rgba(225, 6, 0, 0.45);
  transform: translateY(-1px);
}
.modal-hint {
  font-size: 10px; color: #64748b; margin-top: 16px; line-height: 1.4;
}

.live-banner-list { flex-direction: column; }
.live-banner { cursor: pointer; }
.live-banner.watching { box-shadow: inset 3px 0 0 #ef4444; background: linear-gradient(135deg, rgba(239,68,68,0.32) 0%, rgba(18,22,32,0.9) 100%); }

/* ================================================================
   XENEON EDGE (2560×720, 32:9 touch bar)
   html.edge is set by app.js: automatically on very wide, short
   viewports, or forced with the EDGE chip in the header. One row:
   lap list | telemetry card docked beside the map | charts + transport.
   ================================================================ */
.edge-chip {
  background: var(--card); border: 1px solid var(--line); color: var(--dim);
  font-family: inherit; font-style: italic; cursor: pointer;
}
.edge-chip.on { border-color: var(--accent); color: var(--accent); }
html.edge { --edge-hud-w: clamp(220px, 44vh, 340px); }
html.edge header { padding: 5px 14px; gap: 12px; }
html.edge #sidebar { width: 280px; }
html.edge #sidebar.collapsed { width: 32px; }

html.edge #main {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) auto;
}
html.edge #stage {
  grid-column: 1; grid-row: 1 / 3; min-height: 0; overflow: hidden;
  border-right: 1px solid var(--line);
}
html.edge #splitter { display: none; }
html.edge #charts {
  grid-column: 2; grid-row: 1;
  height: auto !important; min-height: 0; padding-top: 6px;
}
html.edge #transport { grid-column: 2; grid-row: 2; }

/* telemetry card: a full-height column at the left of the stage */
html.edge #hud {
  left: 0 !important; top: 0 !important; bottom: 0 !important; right: auto !important;
  width: var(--edge-hud-w);
  display: flex; flex-direction: column; justify-content: center;
  padding: 26px 12px 8px; cursor: default;
  border-width: 0 1px 0 0; border-radius: 0; box-shadow: none;
}
html.edge #halo { flex: none; height: auto; max-height: calc(100% - 30px); }
html.edge #hud-drag { display: none; }
html.edge #hud .card-tag, html.edge #hud-steer-btn { top: 6px; }
html.edge #hud.closed {
  bottom: auto !important; width: 122px; padding: 0; border: none;
}
html.edge #stage:has(#hud:not(.closed)) #map {
  left: var(--edge-hud-w); width: calc(100% - var(--edge-hud-w));
}
html.edge #stage:has(#hud:not(.closed)) :is(#map-legend, #map-toolbar, #setup-card) {
  left: calc(var(--edge-hud-w) + 12px);
}
html.edge #stage:has(#hud.closed) #map-legend { top: 26px; }

/* touch: bigger targets for fingers */
html.edge .seg button { padding: 8px 16px; font-size: 11px; }
html.edge .chip { padding: 5px 12px; }
html.edge #btn-play { height: 38px; }
html.edge #scrub { height: 10px; }
html.edge #scrub::-webkit-slider-thumb { width: 24px; height: 24px; }
html.edge .cv { font-size: 13px; }
html.edge .lap-row { min-height: 40px; }
html.edge #map-toolbar { flex-wrap: wrap-reverse; }
html.edge #map-toolbar > * { flex: none; white-space: nowrap; }

html:not(.edge) #fs-btn { display: none; }
html.edge header { padding: 3px 12px; }
html.edge .side-head .hint { display: none; }
html.edge #sidebar { width: 300px; }
html.edge .lap-sub { overflow: hidden; white-space: nowrap; }
/* empty state: centred on the map, beside the docked card, not over it */
html.edge #stage:has(#hud:not(.closed)) #empty-hint { left: var(--edge-hud-w); }
html.edge #empty-hint p { font-size: 12px; }
html.edge #sector-card { padding: 6px 10px; font-size: 11px; }
#race-link { text-decoration: none; }
