:root {
  --bg: #0b0d10;
  --panel: #12161b;
  --panel-2: #181d24;
  --line: #232a33;
  --text: #e8ecf1;
  --muted: #8a94a3;
  --dim: #5a6472;
  --purple: #b36bff;
  --green: #2fd36b;
  --yellow: #f2c94c;
  --red: #ff4d4d;
  --blue: #3fa9f5;
  --orange: #ff9f2e;
  --soft: #ff4d4d;
  --medium: #f2c94c;
  --hard: #eef1f5;
  --inter: #2fd36b;
  --wet: #3f8ff5;
  --font: "Barlow", system-ui, sans-serif;
  --cond: "Barlow Condensed", "Arial Narrow", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Consolas, monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 14px; }
h2 { margin: 0; font: 600 13px/1 var(--cond); text-transform: uppercase; letter-spacing: .12em; color: var(--muted); }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
button, select, input { font: inherit; color: inherit; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: grid; grid-template-columns: minmax(0, 1fr) auto auto auto; gap: 20px; align-items: center;
  padding: 12px 20px; background: rgba(11, 13, 16, .92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.meeting { font: 700 22px/1.1 var(--cond); text-transform: uppercase; letter-spacing: .02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.session { color: var(--muted); font-size: 13px; margin-top: 2px; }
.status-strip { display: flex; align-items: center; gap: 12px; }
.track-status {
  font: 700 14px/1 var(--cond); text-transform: uppercase; letter-spacing: .08em;
  padding: 7px 12px; border-radius: 4px; background: var(--panel-2); color: var(--muted); min-width: 92px; text-align: center;
}
.track-status[data-s="1"] { background: rgba(47, 211, 107, .15); color: var(--green); }
.track-status[data-s="2"] { background: var(--yellow); color: #111; }
.track-status[data-s="4"], .track-status[data-s="6"], .track-status[data-s="7"] { background: var(--orange); color: #111; }
.track-status[data-s="5"] { background: var(--red); color: #fff; }
.lapclock { font: 600 20px/1 var(--mono); font-variant-numeric: tabular-nums; }
.lapclock small { font: 500 11px var(--cond); color: var(--muted); letter-spacing: .1em; margin-right: 6px; }
.weather { display: flex; gap: 14px; color: var(--muted); font-size: 12px; }
.weather b { color: var(--text); font: 600 14px var(--mono); margin-left: 3px; }
.weather .rain b { color: var(--blue); }
.source { display: flex; align-items: center; gap: 8px; }
.source select, .replaybar select {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 4px; padding: 6px 8px; max-width: 260px;
}
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--dim); }
.dot[data-s="live"] { background: var(--green); box-shadow: 0 0 0 3px rgba(47, 211, 107, .2); }
.dot[data-s="replay"] { background: var(--blue); }
.dot[data-s="reconnecting"], .dot[data-s="connecting"] { background: var(--yellow); }
.dot[data-s="offline"] { background: var(--red); }

.replaybar {
  display: flex; align-items: center; gap: 12px; padding: 8px 20px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.replaybar input[type=range] { flex: 1; accent-color: var(--blue); }
.btn { background: var(--panel-2); border: 1px solid var(--line); border-radius: 4px; padding: 6px 14px; cursor: pointer; min-width: 72px; }
.btn:hover { border-color: var(--muted); }

.banner { margin: 16px 20px 0; padding: 14px 18px; border: 1px solid var(--line); border-left: 3px solid var(--blue); background: var(--panel); border-radius: 6px; }
.banner b { font: 700 16px var(--cond); text-transform: uppercase; letter-spacing: .04em; }
.banner .count { font: 600 18px var(--mono); margin-left: 8px; color: var(--blue); }

/* ---------- layout ---------- */
.grid {
  display: grid; gap: 16px; padding: 16px 20px;
  grid-template-columns: minmax(0, 1fr) 360px;
  grid-template-areas: "tower side" "strategy side" "positions positions";
}
.tower-panel { grid-area: tower; }
.side { grid-area: side; display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.strategy-panel { grid-area: strategy; }
.positions-panel { grid-area: positions; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; min-width: 0; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.fastest { font-size: 12px; color: var(--muted); }
.fastest b { color: var(--purple); font-family: var(--mono); }

/* ---------- timing tower ---------- */
.tower-wrap { overflow-x: auto; }
.tower { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.tower th { font: 600 11px var(--cond); color: var(--dim); text-transform: uppercase; letter-spacing: .1em; text-align: right; padding: 8px 8px; white-space: nowrap; }
.tower th.c-drv, .tower th.c-pos { text-align: left; }
.tower th.c-sec, .tower th.c-tyre, .tower th.c-pit { text-align: center; }
.tower td { padding: 0 8px; height: 34px; border-top: 1px solid var(--line); white-space: nowrap; text-align: right; font-family: var(--mono); font-size: 13px; }
.tower tr { cursor: pointer; transition: background .3s; }
.tower tbody tr:hover { background: var(--panel-2); }
.tower tr.fav { background: rgba(63, 169, 245, .08); }
.tower tr.out { opacity: .45; }
.tower tr.flash { background: rgba(179, 107, 255, .12); }
td.c-pos { text-align: left; font: 700 16px var(--cond); width: 34px; }
td.c-drv { text-align: left; font-family: var(--font); }
.drv { display: flex; align-items: center; gap: 8px; }
.drv .bar { width: 4px; height: 20px; border-radius: 2px; }
.drv .tla { font: 700 16px var(--cond); letter-spacing: .04em; }
.drv .no { font: 500 11px var(--mono); color: var(--dim); width: 18px; }
.drv .tag { font: 700 10px var(--cond); letter-spacing: .08em; padding: 2px 5px; border-radius: 3px; }
.tag.pit { background: var(--blue); color: #fff; }
.tag.out { background: var(--panel-2); color: var(--blue); border: 1px solid var(--blue); }
.tag.ret { background: var(--red); color: #fff; }
.tag.ko { background: var(--panel-2); color: var(--muted); }
.t-purple { color: var(--purple); }
.t-green { color: var(--green); }
.t-yellow { color: var(--yellow); }
.t-dim { color: var(--dim); }
td.c-sec { text-align: center; width: 92px; }
.sec { display: flex; flex-direction: column; align-items: center; gap: 3px; }
.sec .v { font-size: 12px; line-height: 1; }
.segs { display: flex; gap: 2px; }
.segs i { width: 8px; height: 3px; border-radius: 1px; background: #2a313b; }
.segs i[data-s="2048"] { background: var(--yellow); }
.segs i[data-s="2049"] { background: var(--green); }
.segs i[data-s="2051"] { background: var(--purple); }
.segs i[data-s="2064"] { background: var(--blue); }
td.c-tyre { text-align: center; }
.tyre { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; }
.tyre-dot, .tyre .c {
  display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%;
  border: 3px solid var(--dim); font: 700 10px var(--cond); color: var(--text); background: #0b0d10;
}
.tyre-dot { width: 11px; height: 11px; border-width: 3px; vertical-align: -1px; margin-right: 5px; }
[data-c="SOFT"] { border-color: var(--soft) !important; }
[data-c="MEDIUM"] { border-color: var(--medium) !important; }
[data-c="HARD"] { border-color: var(--hard) !important; }
[data-c="INTERMEDIATE"] { border-color: var(--inter) !important; }
[data-c="WET"] { border-color: var(--wet) !important; }
.tyre .used { color: var(--dim); }
td.c-pit { text-align: center; color: var(--muted); }

/* ---------- race control ---------- */
.rc, .radio { list-style: none; margin: 0; padding: 4px 0; max-height: 420px; overflow-y: auto; }
.rc li { display: grid; grid-template-columns: 54px 1fr; gap: 10px; padding: 8px 14px; border-bottom: 1px solid var(--line); font-size: 13px; line-height: 1.35; }
.rc li:last-child, .radio li:last-child { border-bottom: 0; }
.rc .meta { font: 500 11px var(--mono); color: var(--dim); }
.rc .flag { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: 0; background: var(--dim); }
.flag[data-f="GREEN"], .flag[data-f="CLEAR"] { background: var(--green); }
.flag[data-f="YELLOW"], .flag[data-f="DOUBLE YELLOW"] { background: var(--yellow); }
.flag[data-f="RED"] { background: var(--red); }
.flag[data-f="BLUE"] { background: var(--blue); }
.flag[data-f="CHEQUERED"] { background: repeating-conic-gradient(#fff 0 25%, #111 0 50%) 0 0 / 5px 5px; }
.flag[data-f="BLACK AND WHITE"] { background: linear-gradient(135deg, #fff 50%, #111 50%); }
.flag[data-f="SC"] { background: var(--orange); }
.rc li.sc { background: rgba(255, 159, 46, .07); }
.rc li.red { background: rgba(255, 77, 77, .08); }
.empty { padding: 18px 14px; color: var(--dim); font-size: 13px; }

/* ---------- team radio ---------- */
.radio li { padding: 8px 14px; border-bottom: 1px solid var(--line); }
.radio .who { display: flex; justify-content: space-between; font-size: 12px; margin-bottom: 4px; }
.radio .who b { font: 700 14px var(--cond); letter-spacing: .04em; }
.radio .who span { color: var(--dim); font-family: var(--mono); }
.radio audio { width: 100%; height: 30px; }

/* ---------- strategy ---------- */
.strategy { padding: 10px 14px 14px; display: grid; gap: 4px; }
.srow { display: grid; grid-template-columns: 44px 1fr; align-items: center; gap: 8px; }
.srow .tla { font: 700 13px var(--cond); }
.stints { position: relative; height: 16px; background: #0e1115; border-radius: 3px; overflow: hidden; }
.stint {
  position: absolute; top: 2px; bottom: 2px; border-radius: 3px; background: #2a313b;
  font: 600 10px/12px var(--mono); color: #111; padding-left: 4px; overflow: hidden; white-space: nowrap;
}
.stint[data-c="SOFT"] { background: var(--soft); }
.stint[data-c="MEDIUM"] { background: var(--medium); }
.stint[data-c="HARD"] { background: var(--hard); }
.stint[data-c="INTERMEDIATE"] { background: var(--inter); }
.stint[data-c="WET"] { background: var(--wet); color: #fff; }
.stint.used { opacity: .72; }
.lapnow { position: absolute; top: 0; bottom: 0; width: 1px; background: var(--muted); }
.legend { display: flex; gap: 12px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }

/* ---------- positions chart ---------- */
.positions { padding: 8px 10px 12px; }
.positions svg { display: block; width: 100%; height: auto; }
.positions .grid-l { stroke: var(--line); stroke-width: 1; }
.positions .axis { fill: var(--dim); font: 10px var(--mono); }
.positions .lbl { font: 700 11px var(--cond); }
.positions path { fill: none; stroke-width: 2; stroke-linejoin: round; opacity: .85; }
.positions path.fav { stroke-width: 3.5; opacity: 1; }

.foot { padding: 4px 20px 24px; color: var(--dim); font-size: 12px; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .grid { grid-template-columns: minmax(0, 1fr); grid-template-areas: "tower" "side" "strategy" "positions"; }
  .side { display: grid; grid-template-columns: 1fr 1fr; }
  .topbar { grid-template-columns: minmax(0, 1fr) auto; }
  .weather { grid-column: 1 / -1; order: 5; }
}
@media (max-width: 720px) {
  .grid, .topbar, .replaybar { padding-left: 12px; padding-right: 12px; }
  .banner { margin: 12px 12px 0; }
  .topbar { grid-template-columns: minmax(0, 1fr); gap: 10px; }
  .status-strip { justify-content: space-between; }
  .side { display: flex; }
  .c-sec, .c-best { display: none; }
  .tower td { padding: 0 5px; font-size: 12px; }
  .tower th { padding: 8px 5px; }
  .drv .no { display: none; }
  .meeting { font-size: 19px; }
  .weather { flex-wrap: wrap; gap: 10px; }
}

/* phone notch / home-screen app */
.topbar { padding-top: max(12px, env(safe-area-inset-top)); padding-left: max(20px, env(safe-area-inset-left)); padding-right: max(20px, env(safe-area-inset-right)); }
.foot { padding-bottom: max(24px, env(safe-area-inset-bottom)); }
@media (max-width: 720px) {
  .topbar { padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); }
  .source select { max-width: none; flex: 1; }
  .tower-wrap { -webkit-overflow-scrolling: touch; }
}

/* ---------- navigation ---------- */
.tabs { display: flex; align-items: center; gap: 4px; }
.tabs .dot { margin-right: 8px; }
.tabs a {
  font: 600 14px var(--cond); text-transform: uppercase; letter-spacing: .08em; color: var(--muted);
  text-decoration: none; padding: 7px 12px; border-radius: 4px;
}
.tabs a:hover { color: var(--text); background: var(--panel-2); }
.tabs a.on { color: var(--text); background: var(--panel-2); box-shadow: inset 0 -2px 0 var(--red); }
a.btn { text-decoration: none; display: inline-block; text-align: center; color: var(--text); }
body:not([data-view="live"]) .status-strip, body:not([data-view="live"]) .weather { visibility: hidden; }

/* ---------- standings ---------- */
.view:not(.grid) { padding: 16px 20px; }
.standings-head { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; margin: 4px 0 16px; }
.standings-head h1 { margin: 0; font: 700 28px var(--cond); text-transform: uppercase; letter-spacing: .02em; }
.standings-head .sub { color: var(--muted); font-size: 13px; }
.standings-grid { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.live-note { font-size: 12px; color: var(--green); }
.stand { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.stand th { font: 600 11px var(--cond); color: var(--dim); text-transform: uppercase; letter-spacing: .1em; text-align: right; padding: 8px 10px; }
.stand th:nth-child(-n+2) { text-align: left; }
.stand td { padding: 0 10px; height: 38px; border-top: 1px solid var(--line); text-align: right; font-family: var(--mono); font-size: 13px; }
.stand td.pos { text-align: left; font: 700 16px var(--cond); width: 40px; }
.stand td.name { text-align: left; font-family: var(--font); }
.stand .nm { display: flex; align-items: center; gap: 10px; }
.stand .nm .bar { width: 4px; height: 22px; border-radius: 2px; flex: none; }
.stand .nm b { font: 600 15px var(--font); }
.stand .nm small { color: var(--dim); font-size: 12px; display: block; }
.stand td.pts { font-weight: 600; font-size: 15px; color: var(--text); }
.stand td.gap { color: var(--dim); }
.stand .delta { font-size: 11px; margin-left: 4px; }
.stand .up { color: var(--green); }
.stand .down { color: var(--red); }
.stand .gain { color: var(--green); font-size: 12px; }
.stand tr.fav { background: rgba(63, 169, 245, .08); }
.stand .barwrap { width: 120px; }
.stand .pbar { height: 6px; border-radius: 3px; background: var(--panel-2); overflow: hidden; }
.stand .pbar i { display: block; height: 100%; border-radius: 3px; }

/* ---------- replays list ---------- */
.rec-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; max-width: 760px; }
.rec-list a {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 16px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; color: var(--text); text-decoration: none;
}
.rec-list a:hover { border-color: var(--blue); }
.rec-list b { font: 700 17px var(--cond); text-transform: uppercase; letter-spacing: .03em; }
.rec-list span { color: var(--dim); font: 12px var(--mono); }

@media (max-width: 1100px) {
  .standings-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 720px) {
  .view:not(.grid) { padding: 12px; }
  .tabs { justify-content: space-between; }
  .tabs a { padding: 7px 8px; }
  .stand .barwrap, .stand th.barwrap { display: none; }
  .stand td, .stand th { padding-left: 6px; padding-right: 6px; }
  body:not([data-view="live"]) .status-strip, body:not([data-view="live"]) .weather { display: none; }
}
