/* ---------- Tokens ---------- */
:root {
  color-scheme: light;
  --navy: #13294b;
  --red: #c8102e;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --border: #dde2e9;
  --text: #0f1726;
  --text-2: #4a5568;
  --text-3: #6b7686;
  --accent: #13294b;
  --accent-ink: #ffffff;
  --link: #1f5fbf;
  --highlight: #c8102e;
  --good: #137a3a;
  --good-bg: #e3f4e9;
  --sb: #8a5a00;
  --sb-bg: #fdf1d8;
  /* Chart series: validated categorical slots 1 & 2 (boys, girls). */
  --series-boys: #2a78d6;
  --series-girls: #eb6834;
  --grid: #e6e9ee;
  --shadow: 0 1px 2px rgb(15 23 38 / .06), 0 4px 16px rgb(15 23 38 / .06);
  --radius: 14px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0d1117;
    --surface: #161b22;
    --surface-2: #1f2630;
    --border: #2b3440;
    --text: #eef1f5;
    --text-2: #b8c0cc;
    --text-3: #8b95a3;
    --accent: #3a64b0;
    --link: #7fb0ff;
    --highlight: #ff6b7d;
    --good: #5fd08a;
    --good-bg: #173524;
    --sb: #f2c36b;
    --sb-bg: #3a2e14;
    --series-boys: #3987e5;
    --series-girls: #d95926;
    --grid: #262e39;
    --shadow: 0 1px 2px rgb(0 0 0 / .4);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d1117;
  --surface: #161b22;
  --surface-2: #1f2630;
  --border: #2b3440;
  --text: #eef1f5;
  --text-2: #b8c0cc;
  --text-3: #8b95a3;
  --accent: #3a64b0;
  --link: #7fb0ff;
  --highlight: #ff6b7d;
  --good: #5fd08a;
  --good-bg: #173524;
  --sb: #f2c36b;
  --sb-bg: #3a2e14;
  --series-boys: #3987e5;
  --series-girls: #d95926;
  --grid: #262e39;
  --shadow: 0 1px 2px rgb(0 0 0 / .4);
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.5 var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; letter-spacing: -.01em; }
h1 { font-size: clamp(1.6rem, 4vw, 2.3rem); }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 .75rem; }
.wrap { width: 100%; max-width: 1120px; margin: 0 auto; padding: 0 16px; }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 16px; top: 8px; background: var(--surface); padding: 8px 12px; z-index: 100; }
:focus-visible { outline: 3px solid var(--link); outline-offset: 2px; border-radius: 4px; }
.muted { color: var(--text-3); }
.num { font-variant-numeric: tabular-nums; }

/* ---------- Header / footer ---------- */
.site-header {
  background: var(--navy);
  color: #fff;
  position: sticky; top: 0; z-index: 20;
  box-shadow: 0 2px 12px rgb(0 0 0 / .15);
}
.header-row { display: flex; align-items: center; gap: 16px; height: 60px; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; font-size: 1.15rem; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 32px; height: 32px; }
.brand-text strong { font-weight: 800; }
.nav { display: flex; gap: 4px; margin-left: auto; overflow-x: auto; scrollbar-width: none; }
.nav a { color: rgb(255 255 255 / .82); padding: 8px 12px; border-radius: 999px; font-weight: 600; font-size: .95rem; white-space: nowrap; }
.nav a:hover { color: #fff; background: rgb(255 255 255 / .1); text-decoration: none; }
.nav a[aria-current="page"] { color: var(--navy); background: #fff; }
.icon-btn { background: transparent; border: 0; color: #fff; padding: 8px; border-radius: 999px; cursor: pointer; display: grid; place-items: center; }
.icon-btn:hover { background: rgb(255 255 255 / .12); }
@media (max-width: 560px) {
  .brand-text { display: none; }
  .header-row { gap: 8px; }
  .nav { margin-left: 0; flex: 1; gap: 0; }
  .nav a { padding: 6px 8px; font-size: .85rem; }
  .icon-btn { padding: 6px; }
}
main.wrap { flex: 1; padding-top: 24px; padding-bottom: 48px; outline: none; }
.site-footer { border-top: 1px solid var(--border); color: var(--text-3); font-size: .9rem; padding: 20px 0; }
.footer-row { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px 24px; }
.footer-row p { margin: 0; }

/* ---------- Building blocks ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); min-width: 0; }
.card + .card, .section + .section { margin-top: 20px; }
.grid > .card, .grid > section { margin-top: 0; }
.section { margin-top: 32px; }
.section-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 8px 16px; margin-bottom: 12px; }
.section-head h2 { margin: 0; }
.grid { display: grid; gap: 20px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr)); }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px 24px; margin-bottom: 20px; }
.page-head p { margin: 4px 0 0; color: var(--text-2); }
.eyebrow { text-transform: uppercase; letter-spacing: .08em; font-size: .75rem; font-weight: 700; color: var(--text-3); margin-bottom: 4px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 8px 14px; border-radius: 10px; font: inherit; font-weight: 600; font-size: .92rem;
  cursor: pointer; white-space: nowrap;
}
.btn:hover { text-decoration: none; background: var(--surface-2); }
.btn-primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn-primary:hover { background: #a90d27; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.btn[disabled] { opacity: .6; cursor: progress; }
.ext::after { content: "↗"; font-size: .85em; opacity: .7; }

.badge { display: inline-block; font-size: .72rem; font-weight: 800; letter-spacing: .03em; padding: 2px 7px; border-radius: 999px; vertical-align: middle; }
.badge-pr { background: var(--good-bg); color: var(--good); }
.badge-sb { background: var(--sb-bg); color: var(--sb); }
.badge-up { background: color-mix(in srgb, var(--link) 15%, transparent); color: var(--link); }
.badge-muted { background: var(--surface-2); color: var(--text-3); }

/* Segmented control / pills */
.seg { display: inline-flex; flex-wrap: wrap; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 12px; }
.seg button { border: 0; background: transparent; color: var(--text-2); font: inherit; font-weight: 600; font-size: .9rem; padding: 6px 12px; border-radius: 9px; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.controls { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }
select, input[type="search"], input[type="text"], input[type="password"], input[type="date"], input[type="number"], textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 12px; min-width: 0;
}
input[type="search"] { flex: 1 1 220px; }
textarea { width: 100%; font-family: var(--mono); font-size: .85rem; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; font-weight: 600; color: var(--text-2); }

/* ---------- Home ---------- */
.hero {
  background: linear-gradient(135deg, var(--navy), #1f3d6d 60%, #2b4f86);
  color: #fff; border-radius: calc(var(--radius) + 4px); padding: clamp(20px, 4vw, 36px);
  display: grid; gap: 24px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr));
  position: relative; overflow: hidden;
}
.hero::after {
  content: ""; position: absolute; inset: auto -10% -60% auto; width: 60%; aspect-ratio: 1;
  background: radial-gradient(circle, rgb(200 16 46 / .35), transparent 65%); pointer-events: none;
}
.hero h1 { color: #fff; }
.hero .eyebrow { color: rgb(255 255 255 / .7); }
.hero p { color: rgb(255 255 255 / .85); }
.next-meet { background: rgb(255 255 255 / .1); border: 1px solid rgb(255 255 255 / .18); border-radius: var(--radius); padding: 18px; backdrop-filter: blur(4px); position: relative; z-index: 1; }
.next-meet h2 { color: #fff; font-size: 1.3rem; }
.next-meet a.title { color: #fff; }
.countdown { display: flex; align-items: baseline; gap: 8px; margin: 8px 0 12px; }
.countdown .big { font-size: 2.6rem; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.next-meet .btn { background: #fff; color: var(--navy); border-color: #fff; }
.next-meet .btn-ghost { background: transparent; color: #fff; border-color: rgb(255 255 255 / .4); }

.tiles { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.tile .label { font-size: .8rem; color: var(--text-3); font-weight: 600; }
.tile .value { font-size: 1.8rem; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.2; }
.tile .sub { font-size: .8rem; color: var(--text-3); }

/* ---------- Meet list ---------- */
.meet-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.meet {
  display: grid; grid-template-columns: 64px 1fr auto; gap: 14px; align-items: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px;
  transition: border-color .15s, transform .15s;
}
.meet:hover { border-color: color-mix(in srgb, var(--link) 50%, var(--border)); }
.meet.past { opacity: .92; }
.date-block { text-align: center; border-radius: 10px; background: var(--surface-2); padding: 6px 0; line-height: 1.1; }
.date-block .mon { font-size: .72rem; font-weight: 800; text-transform: uppercase; color: var(--highlight); letter-spacing: .05em; }
.date-block .day { font-size: 1.5rem; font-weight: 800; }
.date-block .dow { font-size: .72rem; color: var(--text-3); }
.meet-name { font-weight: 700; color: var(--text); }
.meet-meta { font-size: .88rem; color: var(--text-3); }
.meet-links { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.meet-links .btn { padding: 6px 10px; font-size: .85rem; }
@media (max-width: 640px) {
  .meet { grid-template-columns: 56px 1fr; }
  .meet-links { grid-column: 1 / -1; justify-content: flex-start; }
}
.month-label { font-size: .8rem; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; color: var(--text-3); margin: 18px 0 8px; }

/* ---------- Charts ---------- */
.chart-box { position: relative; height: 320px; }
.chart-box.short { height: 240px; }
@media (max-width: 560px) { .chart-box { height: 260px; } }
.legend { display: flex; gap: 16px; font-size: .85rem; color: var(--text-2); margin-bottom: 8px; }
.legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; background: var(--c); vertical-align: -1px; }
.chart-note { font-size: .8rem; color: var(--text-3); margin-top: 8px; }

/* ---------- Tabulator theme overrides ---------- */
.tabulator {
  background: transparent; border: 0; font-size: .92rem; color: var(--text);
}
.tabulator .tabulator-header { background: transparent; border-bottom: 1px solid var(--border); color: var(--text-3); font-weight: 700; }
.tabulator .tabulator-header .tabulator-col { background: transparent; border-right: 0; }
.tabulator .tabulator-header .tabulator-col .tabulator-col-content { padding: 8px 10px; }
.tabulator .tabulator-header .tabulator-col.tabulator-sortable:hover { background: var(--surface-2); }
.tabulator .tabulator-header .tabulator-col .tabulator-col-content .tabulator-col-sorter .tabulator-arrow { border-bottom-color: var(--text-3); }
.tabulator .tabulator-tableholder .tabulator-table { background: transparent; color: var(--text); }
.tabulator-row { background: transparent; border-bottom: 1px solid var(--grid); min-height: 40px; }
.tabulator-row.tabulator-row-even { background: transparent; }
.tabulator-row .tabulator-cell { padding: 9px 10px; border-right: 0; }
.tabulator-row.tabulator-selectable:hover, .tabulator-row.clickable:hover { background: var(--surface-2); cursor: pointer; }
.tabulator .tabulator-placeholder .tabulator-placeholder-contents { color: var(--text-3); font-size: .95rem; font-weight: 500; padding: 24px; }
.tabulator .tabulator-footer { background: transparent; border-top: 1px solid var(--border); color: var(--text-2); }
.tabulator .tabulator-footer .tabulator-page { background: var(--surface); color: var(--text); border-color: var(--border); border-radius: 8px; }
.tabulator .tabulator-footer .tabulator-page.active { color: var(--link); }
.tabulator-row .tabulator-responsive-collapse { border: 0; padding: 4px 10px 10px 34px; color: var(--text-2); }
.tabulator-row .tabulator-responsive-collapse table td { padding: 2px 8px 2px 0; }
.tabulator-row .tabulator-cell .tabulator-responsive-collapse-toggle { background: var(--surface-2); color: var(--text); border-radius: 999px; }
.tabulator .tabulator-tableholder { overflow-x: hidden; }
.cell-strong { font-weight: 700; }
.cell-link { color: var(--link); font-weight: 600; }

/* ---------- Athlete ---------- */
.pr-tiles .tile .value { font-size: 1.5rem; }
.athlete-head { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 20px; }
.avatar { width: 56px; height: 56px; border-radius: 16px; background: var(--navy); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 1.3rem; flex: none; }

/* ---------- Misc ---------- */
.loading, .empty { padding: 48px 0; text-align: center; color: var(--text-3); }
.empty.card { padding: 32px 20px; }
.error { background: color-mix(in srgb, var(--red) 12%, var(--surface)); border: 1px solid color-mix(in srgb, var(--red) 40%, var(--border)); padding: 14px 16px; border-radius: 12px; }
.notice { font-size: .9rem; padding: 10px 14px; border-radius: 10px; background: var(--surface-2); color: var(--text-2); }
.stack { display: grid; gap: 12px; }
.form-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr)); }
pre.log { font-family: var(--mono); font-size: .78rem; white-space: pre-wrap; word-break: break-word; background: var(--surface-2); padding: 10px; border-radius: 8px; max-height: 220px; overflow: auto; margin: 0; }
