:root {
  color-scheme: light;
  --bg: #f4f4f2;
  --surface-1: #fcfcfb;
  --surface-2: #efeeea;
  --line: #dcdbd6;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #7a7974;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --hl: #fff4d6;
  --fav: #eda100;
  --good: #0ca30c;
  --critical: #d03b3b;
  --warning: #fab219;
  --series-1: #2a78d6; --series-2: #eb6834; --series-3: #1baf7a; --series-4: #eda100;
  --series-5: #e87ba4; --series-6: #008300; --series-7: #6250d6; --series-8: #e34948;
  --mark-red: #ffb3b3; --mark-yellow: #fff08a; --mark-green: #b8f0b8; --mark-orange: #ffd59a; --mark-gold: #ffe27a;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --bg: #111110; --surface-1: #1a1a19; --surface-2: #242422; --line: #34342f;
    --text-primary: #f0efec; --text-secondary: #c3c2b7; --text-muted: #8f8e86;
    --accent: #3987e5; --hl: #3a3215; --fav: #f0b429;
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
    --series-5: #d55181; --series-6: #008300; --series-7: #9085e9; --series-8: #e66767;
    --mark-red: #6b2a2a; --mark-yellow: #5e5418; --mark-green: #1f4f22; --mark-orange: #5f4114; --mark-gold: #5e4f12;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111110; --surface-1: #1a1a19; --surface-2: #242422; --line: #34342f;
  --text-primary: #f0efec; --text-secondary: #c3c2b7; --text-muted: #8f8e86;
  --accent: #3987e5; --hl: #3a3215; --fav: #f0b429;
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
  --series-5: #d55181; --series-6: #008300; --series-7: #9085e9; --series-8: #e66767;
  --mark-red: #6b2a2a; --mark-yellow: #5e5418; --mark-green: #1f4f22; --mark-orange: #5f4114; --mark-gold: #5e4f12;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text-primary); font: 15px/1.4 var(--font); -webkit-text-size-adjust: 100%; }
a { color: var(--accent); text-decoration: none; }
button, select, input { font: inherit; color: inherit; }
.num, .t { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--text-muted); }
.sec { color: var(--text-secondary); }
.small { font-size: 12.5px; }
.hidden { display: none !important; }

/* header */
.top { position: sticky; top: 0; z-index: 20; background: var(--surface-1); border-bottom: 1px solid var(--line); padding: env(safe-area-inset-top) 0 0; }
.top-row { display: flex; align-items: center; gap: 8px; padding: 8px 12px; max-width: 1200px; margin: 0 auto; }
.top-row .back { font-size: 22px; line-height: 1; padding: 4px 8px 4px 0; color: var(--text-primary); }
.top-title { flex: 1; min-width: 0; }
.top-title h1 { font-size: 16px; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-title .sub { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.refresh { background: none; border: 0; font-size: 19px; line-height: 1; cursor: pointer; color: var(--text-secondary); padding: 4px 2px 4px 6px; flex: none; }
.refresh:active { color: var(--accent); }

/* pull to refresh */
#appWrap { transition: transform .2s ease; }
#ptr { position: fixed; top: 0; left: 0; right: 0; height: 0; display: flex; justify-content: center; z-index: 40; pointer-events: none; overflow: visible; }
#ptrPos { margin-top: -44px; transition: margin-top .2s ease; }
#ptrIcon { display: flex; align-items: center; justify-content: center; width: 34px; height: 34px; border-radius: 50%; background: var(--surface-1); border: 1px solid var(--line); box-shadow: 0 4px 16px rgba(0,0,0,.25); font-size: 17px; color: var(--text-secondary); transition: transform .15s, color .15s, border-color .15s; }
#ptr.armed #ptrIcon { color: var(--accent); border-color: var(--accent); }
#ptr.refreshing #ptrIcon { color: var(--accent); border-color: var(--accent); animation: ptrspin .7s linear infinite; }
@keyframes ptrspin { to { transform: rotate(360deg); } }
.pill { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--text-secondary); white-space: nowrap; }
.pill.live { background: var(--critical); color: #fff; }
.pill.live::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #fff; animation: blink 1.4s infinite; }
.pill.hot { background: var(--critical); color: #fff; }
.pill.completed { background: var(--good); color: #fff; }
@keyframes blink { 50% { opacity: .25; } }
.tabs-wrap { position: relative; }
.tabs-wrap::after { content: ""; position: absolute; top: 0; right: 0; bottom: 0; width: 24px; pointer-events: none; background: linear-gradient(to right, transparent, var(--surface-1)); }
.tabs { display: flex; gap: 2px; padding: 0 8px; max-width: 1200px; margin: 0 auto; overflow-x: auto; scrollbar-width: none; }
.tabs a { padding: 9px 12px; color: var(--text-secondary); border-bottom: 2px solid transparent; white-space: nowrap; font-weight: 500; }
.tabs a.on { color: var(--text-primary); border-color: var(--accent); }

main { max-width: 1200px; margin: 0 auto; padding: 12px 12px 96px; }
.card { background: var(--surface-1); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-bottom: 12px; }
.card h2, h2.h { font-size: 15px; margin: 0 0 8px; }
.card h3 { font-size: 13px; margin: 0 0 6px; color: var(--text-secondary); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.banner { background: var(--hl); border-radius: var(--radius); padding: 8px 12px; margin-bottom: 12px; font-size: 13.5px; }
.err { color: var(--critical); }

/* controls */
.controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; }
.controls select, .controls input[type=search], input.search { background: var(--surface-1); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; max-width: 100%; }
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.chip { flex: none; border: 1px solid var(--line); background: var(--surface-1); padding: 5px 11px; border-radius: 999px; font-size: 13px; cursor: pointer; color: var(--text-secondary); }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.chip .dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; vertical-align: 0; }
.chip .x { margin-left: 6px; opacity: .7; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--surface-1); padding: 6px 12px; cursor: pointer; color: var(--text-secondary); }
.seg button.on { background: var(--accent); color: var(--accent-ink); }
.filters-label { font-size: 11.5px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; margin: 4px 0; }
.btn { border: 1px solid var(--line); background: var(--surface-1); border-radius: 8px; padding: 7px 12px; cursor: pointer; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* standings list */
.list { background: var(--surface-1); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.row { display: grid; grid-template-columns: 34px 1fr auto 34px; gap: 4px 10px; align-items: center; padding: 9px 10px; border-top: 1px solid var(--line); color: inherit; }
.row:first-child { border-top: 0; }
.row.fav { background: var(--hl); }
.row .pos { font-family: var(--mono); font-weight: 700; font-size: 17px; text-align: center; }
.row .who { min-width: 0; }
.row .who .d { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .who .c, .row .who .m { font-size: 12.5px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .who .m { color: var(--text-muted); }
.carno { display: inline-block; min-width: 28px; text-align: center; font-family: var(--mono); font-weight: 700; font-size: 12px; background: var(--text-primary); color: var(--surface-1); border-radius: 4px; padding: 0 4px; margin-right: 6px; }
.cls { font-size: 11.5px; font-weight: 600; border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; color: var(--text-secondary); white-space: nowrap; }
.cat { font-size: 11px; color: var(--text-muted); }
.row .tm { text-align: right; }
.row .tm .total { font-family: var(--mono); font-weight: 600; }
.row .tm .gap { font-family: var(--mono); font-size: 12.5px; color: var(--text-secondary); }
.row .tm .cp { font-size: 12px; color: var(--text-muted); }
.pick { width: 30px; height: 30px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface-1); cursor: pointer; font-size: 16px; line-height: 1; color: var(--text-secondary); }
.pick.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.status-out .pos, .status-out .total { color: var(--critical); }
.status-pending .pos { color: var(--text-muted); }
.ret { font-size: 12px; color: var(--critical); }

/* tables */
.tw { overflow-x: auto; background: var(--surface-1); border: 1px solid var(--line); border-radius: var(--radius); }
table.t2 { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 13px; }
table.t2 th, table.t2 td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; background: var(--surface-1); }
table.t2 th { position: sticky; top: 0; z-index: 2; font-size: 11.5px; color: var(--text-secondary); font-weight: 600; text-align: right; }
table.t2 th.l, table.t2 td.l { text-align: left; }
table.t2 td.t, table.t2 td.num { font-family: var(--mono); }
table.t2 .stick { position: sticky; left: 0; z-index: 1; }
table.t2 th.stick { z-index: 3; }
table.t2 .stick2 { position: sticky; left: 38px; z-index: 1; box-shadow: 1px 0 0 var(--line); }
table.t2 th.stick2 { z-index: 3; }
table.t2 tr.fav td { background: var(--hl); }
table.t2 td .sp { display: block; font-size: 11px; color: var(--text-muted); }
table.t2 td.best { font-weight: 700; }
table.t2 td.best::after { content: " ●"; color: var(--accent); font-size: 9px; vertical-align: 2px; }
td.c-red { background: var(--mark-red) !important; }
td.c-yellow { background: var(--mark-yellow) !important; }
td.c-green { background: var(--mark-green) !important; }
td.c-orange { background: var(--mark-orange) !important; }
td.c-gold { background: var(--mark-gold) !important; }

/* person list (e.g. team registration status) -- stacked rows instead of a wide table, so it fits any screen */
.plist > div { padding: 10px 0; border-top: 1px solid var(--line); }
.plist > div:first-child { border-top: 0; }
.plist .role { font-size: 11.5px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 2px; }
.plist .name { font-weight: 600; }
.plist .ctry { font-size: 12.5px; color: var(--text-secondary); margin-left: 6px; }
.status { display: inline-flex; align-items: center; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px; margin: 6px 6px 0 0; }
.status.ok { background: var(--mark-green); }
.status.bad { background: var(--mark-red); }
.status.warn { background: var(--mark-yellow); }

/* stage cards */
.stages { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }
.stage { display: block; color: inherit; background: var(--surface-1); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
.stage .ss { font-family: var(--mono); font-weight: 700; color: var(--accent); }
.stage .nm { font-weight: 600; }
.stage .meta { font-size: 12.5px; color: var(--text-secondary); margin-top: 4px; }
.stage .fast { font-size: 12.5px; margin-top: 4px; }

/* stat tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; margin-bottom: 12px; }
.tile { background: var(--surface-1); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
.tile .k { font-size: 11.5px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.tile .v { font-size: 22px; font-weight: 700; font-family: var(--mono); margin-top: 2px; }
.tile .s { font-size: 12px; color: var(--text-secondary); }

.chart-box { position: relative; height: 260px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12.5px; margin: 0 0 8px; color: var(--text-secondary); }
.legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 3px; background: var(--c); margin-right: 6px; vertical-align: -1px; }

/* on stage now */
.onstage-wrap { position: relative; margin-bottom: 4px; }
.onstage-wrap::after { content: ""; position: absolute; top: 0; right: 0; bottom: 0; width: 28px; pointer-events: none; background: linear-gradient(to right, transparent, var(--bg)); }
.onstage { display: flex; gap: 8px; overflow-x: auto; scroll-snap-type: x proximity; scrollbar-width: none; }
.onstage .o { flex: none; scroll-snap-align: start; background: var(--surface-1); border: 1px solid var(--line); border-left: 3px solid var(--good); border-radius: 8px; padding: 6px 10px; font-size: 12.5px; }
.onstage .o .clock { font-family: var(--mono); font-weight: 700; font-size: 15px; }
.onstage-dots { display: flex; gap: 5px; justify-content: center; margin: 7px 0 12px; }
.onstage-dots .dot { width: 5px; height: 5px; border-radius: 50%; background: var(--line); transition: background .15s, transform .15s; }
.onstage-dots .dot.on { background: var(--accent); transform: scale(1.4); }

/* rally list on home */
.rl a { display: flex; gap: 10px; align-items: baseline; padding: 9px 0; border-top: 1px solid var(--line); color: inherit; }
.rl a:first-child { border-top: 0; }
.rl .dt { width: 64px; flex: none; font-size: 12.5px; color: var(--text-muted); font-family: var(--mono); }
.rl .tt { flex: 1; font-weight: 500; }
.rl .sn { font-size: 11.5px; color: var(--text-muted); }

/* compare tray */
.tray { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(14px + env(safe-area-inset-bottom)); z-index: 30; background: var(--text-primary); color: var(--surface-1); border-radius: 999px; padding: 8px 8px 8px 16px; display: flex; gap: 10px; align-items: center; box-shadow: 0 6px 24px rgba(0,0,0,.25); font-size: 14px; max-width: calc(100vw - 24px); white-space: nowrap; }
.tray span, .tray a, .tray button { white-space: nowrap; flex: none; }
.tray a { background: var(--accent); color: #fff; padding: 6px 14px; border-radius: 999px; font-weight: 600; }
.tray button { background: transparent; border: 0; color: inherit; opacity: .7; cursor: pointer; }

.split2 { display: grid; gap: 12px; }
.split2 > * { min-width: 0; }
@media (min-width: 900px) { .split2 { grid-template-columns: 1fr 1fr; } }
.spinner { padding: 30px; text-align: center; color: var(--text-muted); }
.star { background: none; border: 0; font-size: 22px; cursor: pointer; color: var(--text-muted); padding: 0 4px; }
.star.on { color: var(--fav); }
details summary { cursor: pointer; color: var(--text-secondary); font-size: 13px; }
.foot { text-align: center; font-size: 12px; color: var(--text-muted); margin-top: 24px; }
