:root {
  --bg: #f6f7f9; --surface: #ffffff; --text: #15181d; --muted: #6b7280;
  --border: #e5e7eb; --accent: #2563eb; --accent-weak: #dbeafe;
  --fin: #15803d; --fin-bg: #dcfce7; --dnf: #6b7280; --dnf-bg: #eceef1;
  --pin: #b45309; --pin-bg: #fef3c7;
  --hl: #7c3aed; --hl-bg: #ede9fe;
  --radius: 12px; --tap: 44px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0c0e12; --surface: #14171c; --text: #e7eaee; --muted: #9aa3af;
    --border: #232830; --accent: #60a5fa; --accent-weak: #1e293b;
    --fin: #4ade80; --fin-bg: #14321f; --dnf: #9aa3af; --dnf-bg: #20242b;
    --pin: #fbbf24; --pin-bg: #3a2e0c;
    --hl: #a78bfa; --hl-bg: #2e1065;
  }
}
:root[data-theme="dark"] {
  --bg: #0c0e12; --surface: #14171c; --text: #e7eaee; --muted: #9aa3af;
  --border: #232830; --accent: #60a5fa; --accent-weak: #1e293b;
  --fin: #4ade80; --fin-bg: #14321f; --dnf: #9aa3af; --dnf-bg: #20242b;
  --pin: #fbbf24; --pin-bg: #3a2e0c;
  --hl: #a78bfa; --hl-bg: #2e1065;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text); font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
#topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 10px 14px; background: var(--surface); border-bottom: 1px solid var(--border);
  padding-top: max(10px, env(safe-area-inset-top));
}
#topbar-actions { display: flex; gap: 6px; align-items: center; }
.link { background: none; border: none; color: var(--accent); font-weight: 700; font-size: 16px; cursor: pointer; }
main { padding: 14px; max-width: 760px; margin: 0 auto; }
button, input { font: inherit; }
.btn {
  min-height: var(--tap); padding: 0 14px; border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--surface); color: var(--text); cursor: pointer;
}
.btn.primary { background: var(--accent); color: #fff; border-color: transparent; }
.btn.icon { min-width: var(--tap); padding: 0; }
.field { width: 100%; min-height: var(--tap); padding: 0 12px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); color: var(--text); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin-bottom: 10px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.muted { color: var(--muted); }
.error { color: #b91c1c; margin-top: 8px; }
h1 { font-size: 20px; margin: 4px 0 14px; }
.race-card { display: flex; align-items: center; justify-content: space-between; }
.race-card .title { font-weight: 700; font-size: 17px; }
.add-form { display: flex; gap: 8px; margin-top: 6px; }
.add-form .field { flex: 1; }

/* Race view */
.race-head { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.dist-tabs { display: flex; gap: 6px; overflow-x: auto; }
.dist-tabs .tab { white-space: nowrap; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; }
.dist-tabs .tab.active { background: var(--accent); color: #fff; border-color: transparent; }
.meta { font-size: 13px; }

table.results { width: 100%; border-collapse: collapse; }
table.results th { text-align: left; font-size: 12px; color: var(--muted); padding: 6px 8px; position: sticky; top: 56px; background: var(--bg); }
table.results td { padding: 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
.r-rank { font-weight: 800; font-size: 16px; }
.r-gen { font-size: 11px; color: var(--muted); }
.r-name { font-weight: 600; }
.r-bib { font-size: 12px; color: var(--muted); }
.badge { display: inline-block; padding: 1px 7px; border-radius: 999px; font-size: 11px; font-weight: 700; border: 1px solid var(--border); }
.badge.cat { background: var(--accent-weak); color: var(--text); }
.r-time { font-variant-numeric: tabular-nums; white-space: nowrap; }
.r-gap { font-size: 12px; color: var(--muted); }
.prog { display: inline-block; min-width: 46px; text-align: center; padding: 1px 8px; border-radius: 6px; font-size: 12px; font-weight: 700; }
tr.runner { cursor: pointer; }
tr.runner > td { border-left: 4px solid transparent; }
tr.runner.highlighted { background: var(--hl-bg); }
tr.runner.pinned { background: var(--pin-bg); }
.expand td { background: var(--surface); }
.empty { text-align: center; color: var(--muted); padding: 24px; }

/* Splits expansion */
.splits { width: 100%; border-collapse: collapse; margin-top: 6px; }
.splits td, .splits th { padding: 4px 6px; font-size: 12px; border-bottom: 1px solid var(--border); }
.splits th { color: var(--muted); text-align: left; }
.exp-meta { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 4px; font-size: 13px; }
.exp-meta .badge { background: var(--accent-weak); }

/* Filter chips + search */
.controls { display: flex; flex-direction: column; gap: 8px; margin: 10px 0; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { padding: 5px 11px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: 13px; cursor: pointer; }
.chip.on { background: var(--accent); color: #fff; border-color: transparent; }
.chip-group { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.chip-label { font-size: 12px; color: var(--muted); margin-right: 2px; }

/* Top-bar controls (Task 16) */
.toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
.switch { min-height: 32px; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; }
.switch.on { background: var(--accent); color: #fff; border-color: transparent; }
#updated { font-size: 12px; color: var(--muted); }
.exp-actions { margin-left: auto; display: flex; gap: 6px; }
.hl-btn.on { background: var(--hl); color: #fff; border-color: transparent; }
