/* ------------------------------------------------------------------ */
/* Base                                                                */
/* ------------------------------------------------------------------ */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--ink);
  font: var(--fs-md) / 1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; line-height: 1.25; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: var(--fs-2xl); }
h2 { font-size: var(--fs-xl); }
h3 { font-size: var(--fs-lg); }
h4 { font-size: var(--fs-md); }
p { margin: 0; }

a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
img, svg { display: block; }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: 4px;
}

.num, .tnum { font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-3); }
.ink-2 { color: var(--ink-2); }
.nowrap { white-space: nowrap; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute; left: var(--s3); top: -48px; z-index: 100;
  background: var(--surface); padding: var(--s2) var(--s3); border-radius: var(--radius);
  box-shadow: var(--shadow-2);
}
.skip-link:focus { top: var(--s2); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ------------------------------------------------------------------ */
/* Top bar                                                             */
/* ------------------------------------------------------------------ */

.topbar {
  position: sticky; top: 0; z-index: 40;
  background: var(--overlay);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: var(--page-max); margin: 0 auto; height: var(--topbar-h);
  padding: 0 var(--s5);
  display: flex; align-items: center; gap: var(--s5);
}
.brand {
  display: flex; align-items: center; gap: 10px;
  color: var(--ink); font-weight: 650; font-size: 15px; white-space: nowrap;
}
.brand:hover { text-decoration: none; }
.brand svg { width: 26px; height: 26px; color: #0b0b0b; }
.brand .brand-bg { fill: var(--accent-ink); }

.primary-nav { display: flex; gap: 2px; }
.primary-nav a {
  padding: 6px 12px; border-radius: var(--radius-sm);
  color: var(--ink-2); font-weight: 500;
}
.primary-nav a:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.primary-nav a[aria-current="page"] { color: var(--ink); background: var(--surface-3); }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 34px; height: 34px; border-radius: var(--radius-sm);
  border: 1px solid transparent; background: transparent; color: var(--ink-2);
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn svg { width: 18px; height: 18px; }
.nav-toggle { display: none; }

/* ------------------------------------------------------------------ */
/* Page layout                                                         */
/* ------------------------------------------------------------------ */

main { flex: 1; width: 100%; max-width: var(--page-max); margin: 0 auto; padding: var(--s5) var(--s5) var(--s7); outline: none; }
main.loading-route { opacity: 0.55; transition: opacity 0.15s; }

.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: var(--fs-sm); color: var(--ink-3); margin-bottom: var(--s2); }
.crumbs a { color: var(--ink-2); }
.crumbs .sep { color: var(--border-strong); }
.crumbs [aria-current] { color: var(--ink-3); }

.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--s3) var(--s5); margin-bottom: var(--s5); }
.page-head .titles { min-width: 0; }
.page-head h1 { overflow-wrap: anywhere; }
.page-head .sub { margin-top: 6px; color: var(--ink-2); display: flex; flex-wrap: wrap; gap: 4px 14px; }
.page-head .sub > * { white-space: nowrap; }
.page-head .actions { margin-left: auto; display: flex; flex-wrap: wrap; gap: var(--s2); align-items: center; }

.section { margin-top: var(--s6); }
.section:first-child { margin-top: 0; }
.section-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--s2) var(--s4); margin-bottom: var(--s3); }
.section-head p { color: var(--ink-3); font-size: var(--fs-sm); }
.section-head .actions { margin-left: auto; display: flex; gap: var(--s2); flex-wrap: wrap; align-items: center; }

.grid { display: grid; gap: var(--s4); }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.auto { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.stack { display: flex; flex-direction: column; gap: var(--s4); }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
}
.card-pad { padding: var(--s4); }
.card-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--s2) var(--s3); padding: var(--s3) var(--s4) 0; }
.card-head h3 { font-size: 15px; }
.card-head p { color: var(--ink-3); font-size: var(--fs-sm); }
.card-head .actions { margin-left: auto; display: flex; gap: var(--s2); align-items: center; flex-wrap: wrap; }
.card-body { padding: var(--s3) var(--s4) var(--s4); }

/* filter row: one row above what it scopes */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2) var(--s3); margin-bottom: var(--s3); }
.toolbar .spacer { flex: 1; }
.toolbar .hint { color: var(--ink-3); font-size: var(--fs-sm); }

/* ------------------------------------------------------------------ */
/* Controls                                                            */
/* ------------------------------------------------------------------ */

.btn {
  display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px;
  border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--ink); font-weight: 500; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--accent-ink); border-color: var(--accent-ink); color: var(--ink-inverse); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn.sm { height: 28px; padding: 0 10px; font-size: var(--fs-sm); }
.btn svg { width: 16px; height: 16px; }
.btn[disabled] { opacity: 0.45; cursor: default; }

.field { display: inline-flex; align-items: center; gap: 8px; color: var(--ink-2); font-size: var(--fs-sm); }
.select, .input {
  height: 32px; padding: 0 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--ink);
  font-size: var(--fs-md);
}
.select { padding-right: 28px; appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M3 4.5l3 3 3-3' fill='none' stroke='%23888' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 8px center; background-size: 12px; }
.input::placeholder { color: var(--ink-3); }
.select:focus, .input:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px var(--accent-soft-2); }

/* select-like dropdown whose options can carry flags (natSelect) */
.dropdown { position: relative; display: inline-block; }
.dropdown-btn { display: inline-flex; align-items: center; min-width: 120px; font: inherit; font-size: var(--fs-md); text-align: left; cursor: pointer; }
.dropdown-list {
  position: absolute; left: 0; top: calc(100% + 4px); z-index: 50; min-width: 100%; max-height: 320px; overflow: auto;
  padding: var(--s1); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-2); outline: none;
}
.dropdown-list[hidden] { display: none; }
.dropdown-opt { display: flex; align-items: center; padding: 6px 10px; border-radius: var(--radius-sm); white-space: nowrap; cursor: pointer; }
.dropdown-opt.active { background: var(--accent-soft); }
.dropdown-opt[aria-selected="true"] { font-weight: 600; }

/* segmented control (radio group) */
.seg { display: inline-flex; padding: 2px; border-radius: var(--radius); background: var(--surface-3); gap: 2px; }
.seg button {
  height: 28px; padding: 0 11px; border: 0; border-radius: var(--radius-sm);
  background: transparent; color: var(--ink-2); font-size: var(--fs-sm); font-weight: 500; white-space: nowrap;
}
.seg button:hover { color: var(--ink); }
.seg button[aria-checked="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-1); }

/* tabs */
.tabs {
  display: flex; gap: 2px; border-bottom: 1px solid var(--border);
  margin-bottom: var(--s4); overflow-x: auto; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs a, .tabs button {
  position: relative; padding: 10px 14px; border: 0; background: none;
  color: var(--ink-2); font-weight: 500; white-space: nowrap;
}
.tabs a:hover, .tabs button:hover { color: var(--ink); text-decoration: none; }
.tabs [aria-selected="true"] { color: var(--ink); }
.tabs [aria-disabled="true"] { color: var(--ink-3); opacity: 0.6; }
.tabs [aria-selected="true"]::after {
  content: ""; position: absolute; left: 10px; right: 10px; bottom: -1px; height: 2px;
  background: var(--accent); border-radius: 2px 2px 0 0;
}
.tabs .badge { margin-left: 6px; }

.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 6px 0 10px;
  border-radius: 999px; border: 1px solid var(--border); background: var(--surface);
  font-size: var(--fs-sm); white-space: nowrap;
}
.chip .x {
  display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 999px;
  border: 0; background: transparent; color: var(--ink-3); padding: 0;
}
.chip .x:hover { background: var(--surface-3); color: var(--ink); }
.chip .x svg { width: 12px; height: 12px; }
.chip.toggle { padding: 0 12px; cursor: pointer; color: var(--ink-2); }
.chip.toggle[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent-soft-2); color: var(--ink); }

.badge {
  display: inline-flex; align-items: center; height: 20px; padding: 0 7px; border-radius: 999px;
  font-size: var(--fs-xs); font-weight: 600; letter-spacing: 0.01em;
  background: var(--surface-3); color: var(--ink-2); white-space: nowrap;
}
.badge.accent { background: var(--accent-soft); color: var(--accent-ink); }
.badge.live { background: var(--accent-soft); color: var(--accent-ink); }
.badge.outline { background: transparent; border: 1px solid var(--border-strong); }

.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 999px; flex: none; }
.swatch.line { width: 14px; height: 3px; border-radius: 2px; }
.swatch.hollow { background: transparent; box-shadow: inset 0 0 0 2.5px var(--c); }

.nat {
  display: inline-block; min-width: 34px; font: 600 var(--fs-xs)/18px var(--font); letter-spacing: 0.04em;
  color: var(--ink-2); white-space: nowrap;
}
/* 4:3 flag before the code; the ring keeps white stripes visible on the surface */
.flag {
  display: inline-block; width: 16px; height: 12px; margin-right: 6px; vertical-align: -1px;
  border-radius: 2px; box-shadow: 0 0 0 1px var(--border);
}
.nat .flag { vertical-align: -2px; }

/* ------------------------------------------------------------------ */
/* States                                                              */
/* ------------------------------------------------------------------ */

.state { padding: var(--s7) var(--s4); text-align: center; color: var(--ink-2); }
.state h3 { color: var(--ink); margin-bottom: 6px; }
.state p { max-width: 520px; margin: 0 auto; }
.state .btn { margin-top: var(--s4); }
.state.compact { padding: var(--s5) var(--s4); }

.skeleton { display: grid; gap: 10px; }
.skeleton i {
  display: block; height: 14px; border-radius: 4px;
  background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2));
  background-size: 200% 100%; animation: shimmer 1.4s infinite linear;
}
.skeleton i:nth-child(3n) { width: 70%; }
.skeleton i:nth-child(4n) { width: 85%; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

.spinner {
  width: 16px; height: 16px; border-radius: 50%; display: inline-block; vertical-align: -3px;
  border: 2px solid var(--border-strong); border-top-color: var(--accent); animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.notice {
  display: flex; gap: var(--s3); align-items: flex-start;
  padding: var(--s3) var(--s4); border-radius: var(--radius);
  background: var(--surface-2); border: 1px solid var(--border); color: var(--ink-2);
  margin-bottom: var(--s4);
}
.notice strong { color: var(--ink); }

/* ------------------------------------------------------------------ */
/* Stat tiles                                                          */
/* ------------------------------------------------------------------ */

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: var(--s3); margin-bottom: var(--s5); }
.tile { padding: var(--s3) var(--s4); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); min-width: 0; }
.tile .label { color: var(--ink-2); font-size: var(--fs-sm); }
.tile .value { margin-top: 2px; font-size: 22px; font-weight: 600; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.tile .note { margin-top: 2px; color: var(--ink-3); font-size: var(--fs-sm); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ------------------------------------------------------------------ */
/* Data table                                                          */
/* ------------------------------------------------------------------ */

.table-wrap {
  position: relative; overflow: auto; max-width: 100%;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
}
.table-wrap.tall { max-height: min(78vh, 980px); }
table.data { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
table.data caption { text-align: left; padding: var(--s3) var(--s4); color: var(--ink-2); }
table.data th, table.data td {
  padding: 0 10px; height: 34px; border-bottom: 1px solid var(--border);
  text-align: left; white-space: nowrap; vertical-align: middle; background: var(--surface);
}
table.data tbody tr:last-child > * { border-bottom: 0; }
table.data thead th {
  position: sticky; top: 0; z-index: 2; height: 36px;
  background: var(--surface-2); color: var(--ink-2); font-weight: 600; font-size: var(--fs-sm);
  border-bottom: 1px solid var(--border-strong);
}
table.data thead tr.group th { height: 28px; font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: 0.05em; color: var(--ink-3); border-bottom: 1px solid var(--border); }
table.data thead tr.group + tr th { top: 28px; }
table.data th.sortable { cursor: pointer; user-select: none; }
table.data th.sortable:hover { color: var(--ink); }
table.data th .sort { display: inline-block; width: 10px; margin-left: 3px; color: var(--ink-3); font-size: 10px; }
table.data th[aria-sort="ascending"] .sort::after { content: "▲"; color: var(--accent-ink); }
table.data th[aria-sort="descending"] .sort::after { content: "▼"; color: var(--accent-ink); }
table.data .r { text-align: right; font-variant-numeric: tabular-nums; }
table.data .c { text-align: center; font-variant-numeric: tabular-nums; }
table.data td.strong { font-weight: 600; }
table.data td.name { max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
table.data td.name a { color: var(--ink); }
table.data td.name a:hover { color: var(--accent-ink); }
table.data td.dim { color: var(--ink-3); }
table.data tbody tr:hover > * { background: var(--surface-2); }
table.data tbody tr.clickable { cursor: pointer; }
table.data tbody tr.selected > td:first-child { box-shadow: inset 3px 0 0 var(--sel-color, var(--accent)); }
table.data tbody tr.sub > * { background: var(--surface); color: var(--ink-2); height: 30px; }
table.data tbody tr.sub td.name { padding-left: 34px; }
table.data .sticky-1, table.data .sticky-2, table.data .sticky-3 { position: sticky; z-index: 1; }
table.data thead .sticky-1, table.data thead .sticky-2, table.data thead .sticky-3 { z-index: 3; }
table.data .edge { box-shadow: 1px 0 0 var(--border); }
table.data td.heat { text-align: right; font-variant-numeric: tabular-nums; }
table.data td.heat[data-h] { background: var(--hb); color: var(--hi); }
table.data td.heat[data-h="1"] { --hb: var(--heat-1); --hi: var(--heat-ink-1); font-weight: 600; }
table.data td.heat[data-h="2"] { --hb: var(--heat-2); --hi: var(--heat-ink-2); }
table.data td.heat[data-h="3"] { --hb: var(--heat-3); --hi: var(--heat-ink-3); }
table.data td.heat[data-h="4"] { --hb: var(--heat-4); --hi: var(--heat-ink-4); }
table.data td.heat[data-h="5"] { --hb: var(--heat-5); --hi: var(--heat-ink-5); }
table.data tbody tr:hover > td.heat[data-h] { filter: brightness(0.96); }
table.data td.heat .sub { display: inline-block; min-width: 34px; margin-left: 6px; font-size: 11px; text-align: right; opacity: 0.75; }
/* rank over behind: a one-column grid stacks them into two lines */
table.data td.heat .meta { display: inline-grid; vertical-align: middle; min-width: 34px; margin-left: 6px; font-size: 11px; font-weight: 400; line-height: 1.2; text-align: right; opacity: 0.75; }
table.data td.tall, table.data th.tall { height: 42px; }
table.data .rank { font-weight: 600; }
table.data .medal-1 { color: #9a7400; }
table.data .sel-cell { width: 34px; padding: 0 4px 0 10px; }

/* results: a row opened on the athlete's splits */
table.data .open-cell { width: 40px; padding: 0 8px 0 0; text-align: right; }
.expand {
  display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: var(--radius-sm);
  border: 0; background: transparent; color: var(--ink-3); cursor: pointer;
}
.expand:hover { background: var(--surface-3); color: var(--ink); }
.expand svg { width: 14px; height: 14px; transition: transform 0.15s; }
.expand[aria-expanded="true"] { color: var(--ink); }
.expand[aria-expanded="true"] svg { transform: rotate(90deg); }
table.data tbody tr.detail > td, table.data tbody tr.detail:hover > td { background: var(--surface-2); padding: 0; height: auto; }
.splits-detail {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: var(--s3) var(--s5);
  padding: var(--s3) var(--s4) var(--s4) 48px; font-size: 12.5px; font-variant-numeric: tabular-nums;
}
.splits-detail .sd-head, .splits-detail .sd-row { display: grid; grid-template-columns: 30px minmax(0, 1fr) 64px 56px; gap: var(--s2); align-items: center; }
.splits-detail .sd-head { color: var(--ink-3); font-size: 11px; padding-bottom: 4px; margin-bottom: 2px; border-bottom: 1px solid var(--border); }
.splits-detail .sd-head > span { text-align: right; }
.splits-detail .sd-head > .sd-r { text-align: center; }
.splits-detail h4 { margin: 0; font-size: 12px; font-weight: 600; color: var(--ink-2); }
.splits-detail .sd-row { line-height: 22px; }
.splits-detail .sd-pt { color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.splits-detail .sd-t, .splits-detail .sd-b { text-align: right; }
.splits-detail .sd-b { color: var(--ink-3); }
.splits-detail .sd-r { text-align: center; color: var(--ink); font-weight: 600; }
table.data .group-start { border-left: 1px solid var(--border-strong); }
.table-foot { display: flex; gap: var(--s3); align-items: center; padding: var(--s2) 2px; color: var(--ink-3); font-size: var(--fs-sm); }

/* selection dot button inside tables */
.pick {
  width: 18px; height: 18px; border-radius: 999px; padding: 0;
  border: 1.5px solid var(--border-strong); background: var(--surface);
  display: inline-grid; place-items: center;
}
.pick:hover { border-color: var(--ink-3); }
.pick[aria-pressed="true"] { border-color: var(--pick-color); background: var(--pick-color); }
.pick.hollow[aria-pressed="true"] { background: var(--surface); box-shadow: inset 0 0 0 2px var(--pick-color); }
.pick[aria-pressed="true"]::after { content: ""; width: 6px; height: 6px; border-radius: 999px; background: var(--surface); }

/* heat legend */
.heat-legend { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-sm); color: var(--ink-3); }
.heat-legend .steps { display: inline-flex; gap: 2px; }
.heat-legend .steps span { width: 22px; height: 12px; border-radius: 2px; }

/* ------------------------------------------------------------------ */
/* Shooting marks                                                      */
/* ------------------------------------------------------------------ */

.shots { display: inline-flex; gap: 3px; vertical-align: -1px; }
.shots i { width: 9px; height: 9px; border-radius: 999px; background: var(--ink-2); }
.shots i.miss { background: transparent; box-shadow: inset 0 0 0 2px var(--bad); }
.shots i.spare { width: 7px; height: 7px; margin-top: 1px; opacity: 0.6; }
/* targets 1–5 in range order: number = shot that knocked it down, ring = left standing */
.targets { display: inline-flex; gap: 3px; vertical-align: middle; }
.targets i {
  width: 16px; height: 16px; border-radius: 999px; background: var(--ink-2); color: var(--surface);
  font: 600 10px/16px var(--font); font-style: normal; text-align: center; font-variant-numeric: tabular-nums;
}
.targets i.miss { background: transparent; box-shadow: inset 0 0 0 2px var(--bad); }
.targets i.spare { background: var(--ink-3); }
/* the live shot record disagrees with the official misses */
.rec-differs { margin-left: 4px; color: var(--warn-ink); font-weight: 600; cursor: help; }
.misses { font-variant-numeric: tabular-nums; }
.misses b { font-weight: 600; }
.misses .z { color: var(--ink-3); }

/* ------------------------------------------------------------------ */
/* Selection bar (race)                                                */
/* ------------------------------------------------------------------ */

.selbar {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: start; gap: var(--s2) var(--s4);
  padding: var(--s2) var(--s3); margin-bottom: var(--s4);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
}
.selbar .label { color: var(--ink-3); font-size: var(--fs-sm); margin-right: 2px; }
.selbar .chip .bib { color: var(--ink-3); font-variant-numeric: tabular-nums; }
.selbar .add { position: relative; }
.selbar .add .input { height: 28px; width: 190px; font-size: var(--fs-sm); border-radius: 999px; }
.selbar .picks { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); min-width: 0; }
.selbar .end { display: flex; gap: var(--s2); align-items: center; }

/* ------------------------------------------------------------------ */
/* Charts                                                              */
/* ------------------------------------------------------------------ */

.chart { position: relative; width: 100%; user-select: none; touch-action: pan-y; }
.chart svg { width: 100%; height: auto; overflow: visible; }
.chart .grid line { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.chart .axis line, .chart .axis path { stroke: var(--axis); stroke-width: 1; shape-rendering: crispEdges; }
.chart .tick { fill: var(--ink-3); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .axis-label { fill: var(--ink-3); font-size: 11px; }
.chart .band { fill: var(--surface-2); }
.chart .band-label { fill: var(--ink-3); font-size: 10.5px; }
.chart .series { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { stroke: var(--surface); stroke-width: 2; }
.chart .end-label { fill: var(--ink-2); font-size: 11.5px; font-weight: 500; }
.chart .clip-mark { stroke: var(--surface); stroke-width: 1; }
.chart .rec-label { fill: var(--ink-2); font-variant-numeric: normal; }
.chart .clip-label { fill: var(--ink-2); font-size: 10.5px; font-variant-numeric: tabular-nums; }
.chart.sector-chart .series { stroke-width: 1.5; }
.chart .crosshair { stroke: var(--ink-3); stroke-width: 1; shape-rendering: crispEdges; }
.chart .muted-dot { fill: var(--chart-muted); }
.chart .zero { stroke: var(--axis); stroke-width: 1; }
.chart .range { fill: var(--chart-muted); fill-opacity: 0.45; }
.chart .arrows path { fill: none; stroke: var(--ink-2); stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.chart .lane-mark { shape-rendering: crispEdges; }
.swatch.area { width: 14px; height: 10px; border-radius: 3px; opacity: 0.6; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: var(--fs-sm); color: var(--ink-2); margin-bottom: var(--s2); }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend .legend-more { border: 0; background: none; padding: 0; font: inherit; color: var(--accent-ink); cursor: pointer; }
.chart-legend .legend-more:hover { text-decoration: underline; }
.chart-empty { padding: var(--s6) var(--s4); text-align: center; color: var(--ink-3); }

.tooltip {
  position: fixed; z-index: 90; pointer-events: none; min-width: 140px; max-width: 320px;
  padding: 8px 10px; border-radius: var(--radius); background: var(--surface);
  border: 1px solid var(--border); box-shadow: var(--shadow-2); font-size: var(--fs-sm);
}
.tooltip[hidden] { display: none; }
.tooltip .tt-title { color: var(--ink-3); margin-bottom: 4px; font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: 0.04em; }
.tooltip .tt-row { display: flex; align-items: center; gap: 8px; line-height: 1.6; }
.tooltip .tt-row .v { font-weight: 600; font-variant-numeric: tabular-nums; color: var(--ink); }
.tooltip .tt-row .k { color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tooltip .tt-row .x { margin-left: auto; color: var(--ink-3); font-variant-numeric: tabular-nums; padding-left: 8px; }
.tooltip .tt-row.lead { border-bottom: 1px solid var(--border); padding-bottom: 2px; margin-bottom: 2px; }

/* course map */
.map-wrap { position: relative; border-radius: var(--radius); overflow: hidden; background: var(--surface-2); }
.map-wrap img { display: block; width: 100%; height: auto; }
.course-facts { display: flex; flex-wrap: wrap; gap: var(--s2) var(--s5); margin: var(--s3) 0 0; }
.course-facts dt { font-size: var(--fs-sm); color: var(--ink-3); }
.course-facts dd { margin: 0; font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------------ */
/* Lists (calendar, catalog)                                           */
/* ------------------------------------------------------------------ */

/* collapsed event panels: dates, place and series in the summary, the races below */
.events { overflow: hidden; } /* hover and focus tints keep to the card's rounded corners */
.event { --when-w: 112px; border-bottom: 1px solid var(--border); }
.event:last-child { border-bottom: 0; }
.event.focus { background: var(--accent-soft); }
.event > summary {
  display: grid; grid-template-columns: var(--when-w) minmax(0, 1fr) auto; gap: var(--s4); align-items: start;
  padding: var(--s4); list-style: none; cursor: pointer;
}
.event > summary::-webkit-details-marker { display: none; }
.event > summary:hover { background: color-mix(in srgb, var(--ink) 5%, transparent); }
.event > summary:focus-visible { outline-offset: -2px; }
/* expand_more chevron, flips when open */
.event > summary::after {
  content: ""; align-self: center; width: 8px; height: 8px; margin-right: 4px;
  border: solid var(--ink-3); border-width: 0 2px 2px 0;
  transform: translateY(-2px) rotate(45deg); transition: transform 0.2s;
}
.event[open] > summary { padding-bottom: var(--s2); }
.event[open] > summary::after { transform: translateY(2px) rotate(-135deg); }
.event .when { color: var(--ink-2); font-variant-numeric: tabular-nums; }
.event .when b { display: block; color: var(--ink); font-weight: 600; }
.event .where { display: flex; align-items: baseline; gap: var(--s2); flex-wrap: wrap; }
.event .where h3 { font-size: 15px; }
.event .series-name { color: var(--ink-3); font-size: var(--fs-sm); }
.event .series-name .emoji { margin-right: 6px; font-size: 15px; }
.event > .races { padding: 0 var(--s4) var(--s4) calc(var(--when-w) + 2 * var(--s4)); }
/* one race per row: date, start time, race; the hover band reaches past the text */
.race-list { list-style: none; margin: 0 -8px; padding: 0; }
.race-link {
  display: grid; grid-template-columns: 7em 3.5em minmax(0, 1fr); align-items: baseline;
  padding: 3px 8px; border-radius: var(--radius-sm);
  color: var(--ink); font-size: var(--fs-sm);
}
.race-link:hover { text-decoration: none; background: var(--accent-soft); }
.race-link.upcoming { color: var(--ink-2); }
.race-link .when { color: var(--ink-3); text-transform: uppercase; }
.race-link .when, .race-link .clock { font-variant-numeric: tabular-nums; }

.cat-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: var(--s3); }
.cat-item {
  display: block; padding: var(--s3) var(--s4); border-radius: var(--radius-lg);
  background: var(--surface); border: 1px solid var(--border); color: var(--ink);
}
.cat-item:hover { border-color: var(--accent); text-decoration: none; }
.cat-item h3 { font-size: 14.5px; }
.cat-item p { margin-top: 4px; color: var(--ink-3); font-size: var(--fs-sm); }
.cat-item .row { margin-top: var(--s2); }

/* athlete */
.profile { display: flex; gap: var(--s5); align-items: center; flex-wrap: wrap; }
.avatar {
  width: 112px; height: 112px; border-radius: 999px; overflow: hidden; flex: none;
  background: var(--surface-3); display: grid; place-items: center; color: var(--ink-3); font-weight: 600; font-size: 24px;
}
/* the IBU portraits are waist-up and landscape: zoom to head and shoulders */
.avatar img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 0; transform: scale(1.45); transform-origin: 50% 0; }
.facts { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 6px var(--s4); font-size: 13px; }
.facts dt { color: var(--ink-3); }
.facts dd { margin: 0; overflow-wrap: anywhere; }

.bar-cell { display: flex; align-items: center; gap: 8px; min-width: 160px; }
.bar-cell .bar { height: 6px; border-radius: 3px; background: var(--accent); }
.bar-cell .track { flex: 1; height: 6px; border-radius: 3px; background: var(--surface-3); overflow: hidden; }

.kv-row { display: grid; grid-template-columns: 110px minmax(0, 1fr) auto; gap: var(--s3); padding: 7px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.kv-row:last-child { border-bottom: 0; }

/* photo finish */
.lb-cap { display: flex; flex-direction: column; gap: 6px; min-width: 0; font-size: 13px; }
.pf-people { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.pf-people li { display: grid; grid-template-columns: 2.2em minmax(0, 1fr) auto auto; gap: var(--s2); align-items: center; }
.pf-people .rank { font-weight: 600; }
.pf-people .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pf-meta { font-size: var(--fs-sm); }
/* the mark hangs right of the rank so ranks stay centred in their column */
.rank-pf { position: relative; }
.pf-mark {
  position: absolute; left: 100%; top: 50%; transform: translateY(-50%); margin-left: 3px;
  display: grid; place-items: center; width: 20px; height: 20px;
  padding: 0; border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--accent-ink); cursor: pointer;
}
.pf-mark:hover { background: var(--accent-soft); }
.pf-mark svg { width: 15px; height: 15px; }

.lightbox {
  width: min(880px, calc(100vw - 32px)); max-height: calc(100vh - 32px); padding: 0;
  border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); color: var(--ink);
  box-shadow: var(--shadow-2);
}
.lightbox::backdrop { background: rgba(0, 0, 0, 0.6); }
.lb-head { display: flex; align-items: center; gap: var(--s3); padding: var(--s3) var(--s4); border-bottom: 1px solid var(--border); }
.lb-head h2 { font-size: var(--fs-lg); }
.lb-actions { margin-left: auto; display: flex; align-items: center; gap: var(--s2); }
.lb-body { display: flex; align-items: center; gap: var(--s2); padding: var(--s3); background: var(--surface-2); }
.lb-img { display: block; flex: 1; min-width: 0; max-height: calc(100vh - 260px); object-fit: contain; }
.lb-cap { padding: var(--s3) var(--s4) var(--s4); }
.lb-cap .pf-people li { grid-template-columns: 2.2em max-content auto auto; justify-content: start; }

/* ------------------------------------------------------------------ */
/* Responsive                                                          */
/* ------------------------------------------------------------------ */

@media (max-width: 1080px) {
  .grid.cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 860px) {
  .topbar-inner { gap: var(--s3); padding: 0 var(--s4); }
  .nav-toggle { display: inline-grid; order: -1; margin-left: -6px; }
  .primary-nav {
    display: none; position: absolute; left: 0; right: 0; top: var(--topbar-h);
    flex-direction: column; padding: var(--s2) var(--s4) var(--s3);
    background: var(--surface); border-bottom: 1px solid var(--border); box-shadow: var(--shadow-2);
  }
  .primary-nav.open { display: flex; }
  .primary-nav a { padding: 10px 12px; }
  .grid.cols-2, .grid.cols-3 { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 640px) {
  main { padding: var(--s4) var(--s4) var(--s6); }
  .brand span { display: none; }
  h1 { font-size: 22px; }
  .event > summary { grid-template-columns: minmax(0, 1fr) auto; gap: var(--s2); }
  .event > summary .where { grid-column: 1; }
  .event > summary::after { grid-column: 2; grid-row: 1 / span 2; }
  .event > .races { padding-left: var(--s4); }
  .event .when b { display: inline; margin-right: 6px; }
  .selbar .add .input { width: 150px; }
  .selbar { grid-template-columns: minmax(0, 1fr); }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .page-head .actions { margin-left: 0; }
}
