/* Trackside, design brief v2 ("boards and lines"): see docs/DESIGN.md.
   Colours come only from these tokens. Red = fast (PBs, records). Blue = tappable. */
:root {
  color-scheme: light dark;
  --paper: #F4F1EA;
  --surface: #FFFFFF;
  --surface-2: #FAF8F3;
  --ink: #16171A;
  --ink-2: #3C3F45;
  --muted: #63676E;
  --line: #E0DBD0;
  --line-soft: #EEEAE2;
  --blue: #2347C5;
  --blue-ink: #17318F;
  --blue-soft: #EAF0FF;
  --blue-fill: #2347C5;
  --red: #C81E36;
  --red-soft: #FDEDEF;
  --red-ink: #8A1222;
  --red-line: #F3BAC3;
  --red-row: #FFF7F8;
  --panel: #16171A;
  --panel-ink: #E9E5DD;
  --panel-accent: #FF8A98;
  --gold: #E3B341; --silver: #B8BEC6; --bronze: #C7834A;
  --gold-ink: #8A6000; --silver-ink: #5F6670; --bronze-ink: #8A4F1C;
  --shadow: 0 10px 28px rgba(22, 23, 26, .16);
  --display: 'Barlow Condensed', 'Arial Narrow', sans-serif;
  --lines: linear-gradient(to bottom, var(--ink) 0 2px, transparent 2px 4px, var(--red) 4px 6px, transparent 6px 8px, var(--blue) 8px 10px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0F1012;
    --surface: #18191D;
    --surface-2: #1E2025;
    --ink: #F2EFE9;
    --ink-2: #CFCBC3;
    --muted: #9A9DA3;
    --line: #2C2E34;
    --line-soft: #23252A;
    --blue: #8AA8FF;
    --blue-ink: #B3C6FF;
    --blue-soft: #1C2647;
    --blue-fill: #3B5FD9;
    --red: #FF6B7C;
    --red-soft: #3A1A20;
    --red-ink: #FFB3BD;
    --red-line: #6B2A35;
    --red-row: #221417;
    --panel: #1E2025;
    --panel-ink: #E9E5DD;
    --gold-ink: #E3B341; --silver-ink: #C3C8CF; --bronze-ink: #DE9A63;
    --shadow: 0 10px 28px rgba(0, 0, 0, .5);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 16px/1.45 Inter, system-ui, -apple-system, sans-serif; }
a { color: var(--blue); text-underline-offset: 2px; }
a:hover { color: var(--blue-ink); }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; border-radius: 4px; }
h1, h2, h3 { font-family: var(--display); font-weight: 700; margin: 0; line-height: 1; }
.wrap { max-width: 1200px; margin: 0 auto; padding: 0 16px; }
@media (min-width: 720px) { .wrap { padding: 0 24px; } }

/* header: wordmark + nav on one row, search under it on phones, all one row on desktop */
.top { background: var(--surface); color: var(--ink); position: relative; }
.top::after { content: ""; display: block; height: 10px; background: var(--lines); }
.top .wrap { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; padding-top: 8px; padding-bottom: 12px; }
.brand { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; font-family: var(--display); font-weight: 700; font-size: 22px;
  letter-spacing: .03em; color: var(--ink); text-decoration: none; }
.brand::before { content: ""; flex: 0 0 auto; width: 18px; height: 10px; background: var(--lines); transform: skewX(-24deg); }
.brand:hover { color: var(--ink); }
.top nav { display: flex; gap: 12px; margin-left: auto; font-weight: 600; font-size: 14px; }
.top nav a { display: inline-flex; align-items: center; min-height: 44px; color: var(--ink); text-decoration: none; }
.top nav a:hover { color: var(--blue); }
.search { position: relative; flex: 1 1 100%; display: flex; }
.search input { width: 100%; height: 44px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--ink); font: inherit; font-size: 16px; }
.search input::placeholder { color: var(--muted); }
.search input:focus { border-color: var(--blue); outline: none; box-shadow: 0 0 0 3px var(--blue-soft); }
.search ul { position: absolute; top: 50px; right: 0; width: 100%; margin: 0; padding: 4px 0; list-style: none;
  background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); z-index: 10; }
.search li a { display: block; padding: 10px 14px; text-decoration: none; color: var(--ink); }
.search li a:hover, .search li a:focus { background: var(--surface-2); }
.search li small { color: var(--muted); display: block; font-size: 13px; }
@media (min-width: 760px) {
  .top .wrap { flex-wrap: nowrap; padding-top: 10px; padding-bottom: 10px; gap: 28px; }
  .brand { font-size: 28px; }
  .top nav { margin-left: 0; gap: 24px; font-size: 15px; }
  .search { flex: 0 1 360px; margin-left: auto; }
}
@media (max-width: 359px) { .top nav { gap: 10px; font-size: 13px; } .brand { font-size: 20px; } }
.notice { color: var(--muted); font-size: 12px; text-align: center; padding: 6px 16px; border-bottom: 1px solid var(--line); }

main.wrap { padding-top: 24px; padding-bottom: 56px; display: flex; flex-direction: column; gap: 24px; }
@media (min-width: 720px) { main.wrap { padding-top: 32px; } }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 20px; min-width: 0; }
@media (max-width: 479px) { .card { padding: 16px; } }
.card > h2 { font-size: 26px; margin-bottom: 14px; }
.sub { color: var(--muted); font-size: 14px; }
.eyebrow { font-size: 12px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }

/* rider header */
.rider-head { display: flex; gap: 16px; align-items: center; }
.avatar { flex: 0 0 72px; width: 72px; height: 72px; border-radius: 50%; background: var(--blue-fill); color: #fff; display: flex; align-items: center;
  justify-content: center; font-family: var(--display); font-weight: 700; font-size: 30px; }
.rider-head h1 { font-size: 40px; margin: 4px 0; }
@media (min-width: 720px) { .rider-head h1 { font-size: 64px; } .avatar { flex-basis: 96px; width: 96px; height: 96px; font-size: 40px; } }

/* PB tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; display: flex; flex-direction: column; gap: 4px; }
.tile .k { font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.tile .v { font-family: var(--display); font-weight: 700; font-size: 40px; line-height: 1; font-variant-numeric: tabular-nums; }
@media (min-width: 720px) { .tile .v { font-size: 44px; } }
.tile .d { font-size: 13px; color: var(--ink-2); }
.tile .gap { font-size: 13px; color: var(--muted); }
.tile .flag { align-self: flex-start; margin-top: 4px; }

.flag { display: inline-block; max-width: 100%; white-space: normal; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px;
  background: var(--red-soft); color: var(--red-ink); border: 1px solid var(--red-line); }
.pb { color: var(--red); font-weight: 700; }

/* charts (inline SVG from site.py) */
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.chart h3 { font-size: 22px; margin-bottom: 4px; }
.chart svg { width: 100%; height: auto; display: block; }
.ch-grid { stroke: var(--line-soft); }
.ch-axis { fill: var(--muted); }
.ch-line { stroke: var(--blue); }
.ch-dot { fill: var(--blue); }
.ch-best { fill: var(--red); }

/* tables */
.scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 15px; }
th { text-align: left; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; font-weight: 600;
  padding: 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 10px 8px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
tbody tr:hover td { background: var(--surface-2); }
td.n { white-space: nowrap; font-variant-numeric: tabular-nums; }
td.place { font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }
tr.flagged td, tbody tr.flagged:hover td { background: var(--red-row); }
details summary { cursor: pointer; font-weight: 600; color: var(--blue); padding: 10px 0; }

/* lists */
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 10px 0; border-bottom: 1px solid var(--line-soft); display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.list li:last-child { border-bottom: 0; }
.pills { display: flex; flex-wrap: wrap; gap: 8px; }
.pills a { display: inline-flex; align-items: center; min-height: 40px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); text-decoration: none; color: var(--ink); font-weight: 600; }
.pills a:hover { border-color: var(--ink-2); }
.pills a.on { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); gap: 24px; }
.hero { display: flex; flex-direction: column; gap: 6px; }
.hero h1 { font-size: 40px; }
@media (min-width: 720px) { .hero h1 { font-size: 64px; } }
footer { color: var(--muted); font-size: 13px; padding: 24px 16px 40px; border-top: 1px solid var(--line); }
@media (min-width: 720px) { footer { padding-left: 24px; padding-right: 24px; } }

/* meets */
.meets { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr)); gap: 12px; }
a.meet { display: flex; flex-direction: column; gap: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  padding: 16px; text-decoration: none; color: var(--ink); }
a.meet:hover { border-color: var(--ink-2); color: var(--ink); }
a.meet:hover .t { text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 3px; }
a.meet .t { font-family: var(--display); font-weight: 700; font-size: 24px; line-height: 1.05; }
a.meet[hidden] { display: none; }
.meet-title { font-size: 40px; }
@media (min-width: 720px) { .meet-title { font-size: 60px; } }

/* filter chips */
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; -webkit-overflow-scrolling: touch; scrollbar-width: thin; }
.chip { flex: 0 0 auto; min-height: 40px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface);
  color: var(--ink); font: inherit; font-weight: 600; font-size: 14px; cursor: pointer; }
.chip:hover { border-color: var(--ink-2); }
.chip.on { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.tools { display: flex; justify-content: flex-end; margin: -12px 0 -8px; }
.linkbtn { background: none; border: 0; color: var(--blue); font: inherit; font-weight: 600; cursor: pointer; padding: 8px 0; min-height: 40px; }

/* events */
.events { display: flex; flex-direction: column; gap: 8px; }
.session { font-size: 28px; margin: 16px 0 4px; }
details.event { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; }
details.event[hidden] { display: none; }
details.event > summary { list-style: none; display: flex; gap: 12px; align-items: baseline; padding: 14px 16px; cursor: pointer; color: var(--ink); font-weight: 400; }
details.event > summary::-webkit-details-marker { display: none; }
details.event > summary::after { content: "+"; margin-left: auto; color: var(--muted); font-weight: 600; font-size: 20px; line-height: 1; }
details.event[open] > summary::after { content: "–"; }
details.event[open] > summary { border-bottom: 1px solid var(--line-soft); }
.evno { flex: 0 0 auto; min-width: 2.6em; font-family: var(--display); font-weight: 700; font-size: 18px; color: var(--muted); font-variant-numeric: tabular-nums; }
.evt { display: flex; flex-direction: column; font-weight: 600; }
.evt .sub { font-weight: 400; }
.evsub { padding: 10px 16px 0; }
details.event .scroll { padding: 4px 8px 8px; }
details.event:target { border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-soft); }

/* cheat sheet */
.cheat-input { display: flex; flex-direction: column; gap: 12px; }
.cheat-input textarea { width: 100%; font: inherit; font-size: 15px; padding: 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface-2); color: var(--ink); }
.cheat-input .row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.cheat-input select { min-height: 44px; font: inherit; border: 1px solid var(--line); border-radius: 10px; padding: 0 10px;
  background: var(--surface-2); color: var(--ink); max-width: 100%; }
.file { display: inline-flex; align-items: center; min-height: 44px; padding: 0 14px; border: 1px dashed var(--ink-2); border-radius: 10px; cursor: pointer; font-weight: 600; }
.file input { position: absolute; left: -9999px; }
.btn { min-height: 44px; padding: 0 18px; border-radius: 10px; border: 1px solid var(--ink); background: var(--ink); color: var(--paper); font: inherit; font-weight: 600; cursor: pointer; }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn.ghost:hover { border-color: var(--ink-2); }
.cs-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr)); gap: 12px; }
.cs-card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; break-inside: avoid; }
.cs-card header { display: flex; gap: 12px; align-items: flex-start; }
.cs-card .bib { flex: 0 0 auto; min-width: 2.2em; font-family: var(--display); font-weight: 700; font-size: 26px; color: var(--muted); line-height: 1; }
.cs-card h3 { font-size: 26px; }
.cs-card h3 a { color: var(--ink); text-decoration: none; }
.cs-card h3 a:hover { text-decoration: underline; }
.cs-head { margin-left: auto; text-align: right; }
.cs-head b { display: block; font-family: var(--display); font-size: 32px; line-height: 1; font-variant-numeric: tabular-nums; }
.cs-head .k, .cs-pb .k { font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.cs-pbs { display: flex; flex-wrap: wrap; gap: 6px; }
.cs-pb { display: flex; flex-direction: column; padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; min-width: 88px; }
.cs-pb.on { border-color: var(--blue); box-shadow: inset 0 0 0 1px var(--blue); }
.cs-pb b { font-family: var(--display); font-size: 22px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.cs-tp { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 4px; font-size: 15px; }
.cs-tp .tp-rec, .cs-tp .tp-pb { color: var(--red); font-weight: 600; }
.cs-card h4 { margin: 0; font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.cs-res { list-style: none; margin: 0; padding: 0; font-size: 14px; }
.cs-res li { display: flex; flex-direction: column; padding: 4px 0; border-top: 1px solid var(--line-soft); }

/* meet page: stats, categories, competitions */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 8px; margin-top: 16px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; }
.stat b { font-family: var(--display); font-size: 30px; line-height: 1; font-variant-numeric: tabular-nums; }
.stat span { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
.viewbar { display: flex; justify-content: flex-start; }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.seg button { min-height: 40px; padding: 0 16px; border: 0; border-radius: 8px; background: transparent; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: 0 0 0 1px var(--line), 0 1px 2px rgba(0,0,0,.08); }
[data-pane] { display: flex; flex-direction: column; gap: 20px; }
[data-pane][hidden] { display: none; }
.cat[hidden] { display: none; }
.cat > h2 { font-size: 30px; margin: 4px 0 12px; padding-bottom: 6px; border-bottom: 2px solid var(--ink); }
@media (min-width: 720px) { .cat > h2 { font-size: 34px; } }
.comps { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 420px), 1fr)); gap: 12px; align-items: start; }
.comp { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.comp > header { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; padding: 14px 16px 8px; }
.comp h3 { font-size: 24px; }
.podium { list-style: none; margin: 0; padding: 4px 16px 12px; display: flex; flex-direction: column; gap: 8px; }
.podium li { display: flex; gap: 10px; align-items: center; }
.podium li > span:last-child { display: flex; flex-direction: column; font-weight: 600; }
.podium .sub { font-weight: 400; }
.medal { flex: 0 0 auto; width: 22px; height: 22px; border-radius: 50%; box-shadow: inset 0 -2px 0 rgba(0,0,0,.18); }
.m1 .medal { background: var(--gold); } .m2 .medal { background: var(--silver); } .m3 .medal { background: var(--bronze); }
.rounds { border-top: 1px solid var(--line-soft); }
details.round > summary, details.early > summary { list-style: none; display: flex; justify-content: space-between; gap: 12px; align-items: baseline;
  padding: 11px 16px; min-height: 44px; cursor: pointer; border-bottom: 1px solid var(--line-soft); }
details.round > summary::-webkit-details-marker, details.early > summary::-webkit-details-marker { display: none; }
details.round > summary { color: var(--ink); font-weight: 400; }
details.round > summary:hover { background: var(--surface-2); }
details.round > summary .rl { font-weight: 600; }
details.round > summary .rl::before { content: "▸"; display: inline-block; width: 1em; color: var(--muted); transition: transform .15s; }
details.round[open] > summary .rl::before { transform: rotate(90deg); }
details.round > summary .sub { text-align: right; }
details.round .scroll { padding: 0 8px 8px; }
details.round:target > summary, details.round.hl > summary { background: var(--blue-soft); }
details.early > summary { display: block; color: var(--blue); font-weight: 600; }
details.early > summary::before { content: "+ "; }
details.early[open] > summary::before { content: "– "; }
details.early details.round > summary { padding-left: 28px; }
tr.p1 td.place { color: var(--gold-ink); } tr.p2 td.place { color: var(--silver-ink); } tr.p3 td.place { color: var(--bronze-ink); }
table.order td { padding: 8px; }
table.order tr.sess td { font-family: var(--display); font-weight: 700; font-size: 20px; padding-top: 16px; border-bottom: 2px solid var(--line); }
table.rec td { min-width: 9em; }
table.rec td:first-child { min-width: 7em; font-weight: 600; }
.search .tag { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--blue-ink);
  background: var(--blue-soft); border-radius: 4px; padding: 1px 5px; vertical-align: 1px; }

/* rider story */
.story { background: var(--panel); color: var(--panel-ink); border-radius: 10px; padding: 20px; position: relative; overflow: hidden; }
.story::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 6px;
  background: linear-gradient(to right, #F2EFE9 0 2px, var(--red) 2px 4px, var(--blue-fill) 4px 6px); }
.story h2 { font-size: 26px; margin-bottom: 12px; color: #fff; }
.story ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.story li { display: flex; gap: 14px; line-height: 1.45; font-size: 15px; }
.story .yr { flex: 0 0 48px; font-family: var(--display); font-weight: 700; font-size: 20px; color: var(--panel-accent); }
.story a { color: #fff; }

@media print {
  :root { --paper: #fff; --surface: #fff; --ink: #000; --ink-2: #222; --muted: #444; --line: #999; --line-soft: #ccc;
    --red: #000; --blue: #000; --red-ink: #000; --red-soft: #fff; }
  .top, .notice, footer, .no-print, .hero .sub { display: none !important; }
  body { background: #fff; color: #000; font-size: 11px; }
  main.wrap { padding: 0; gap: 8px; }
  .hero h1 { font-size: 22px; }
  .cs-grid { grid-template-columns: 1fr 1fr; gap: 6px; }
  .cs-card { padding: 8px; gap: 4px; border-color: #999; }
  .cs-card h3 { font-size: 18px; }
  .cs-head b { font-size: 22px; }
  .cs-pb b { font-size: 15px; }
  .cs-tp, .cs-res { font-size: 10px; }
  .cs-tp .tp-rec, .cs-tp .tp-pb { font-weight: 700; }
  a { color: inherit; text-decoration: none; }
}
