:root {
  --bg: #0f1115;
  --panel: #181b22;
  --panel-2: #1f2430;
  --line: #2a3040;
  --text: #e8eaf0;
  --muted: #8b93a7;
  --accent: #fc5200;        /* Strava orange */
  --gold: #f4c542;
  --climb: #e8623a;
  --flat: #5b9bd5;
  --descent: #57c98a;
  --hl: #3a2a12;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
.wrap { max-width: 1100px; margin: 0 auto; padding: 0 20px; }
header {
  background: linear-gradient(160deg, #1d2129, #12141a);
  border-bottom: 1px solid var(--line); padding: 26px 0 20px;
}
header .wrap { text-align: center; }
h1 { margin: 0; font-size: 38px; letter-spacing: -0.5px; }
.crown { color: var(--gold); letter-spacing: 2px; margin: 0 6px; }
.sub { margin: 6px 0 18px; color: var(--muted); }
.discipline-switch { justify-content: center; }
.controls { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.generated { color: var(--muted); font-size: 13px; }
main { padding: 28px 0 60px; }
section { margin-bottom: 40px; }
h2 { font-size: 19px; margin: 0 0 4px; }
.hint { color: var(--muted); margin: 0 0 16px; font-size: 13.5px; }
.muted { color: var(--muted); font-weight: normal; }

table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: 0.4px;
  color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line);
  cursor: pointer; user-select: none; white-space: nowrap;
}
thead th.sorted::after { content: " ▾"; color: var(--accent); }
thead th.sorted.asc::after { content: " ▴"; }
tbody td { padding: 9px 10px; border-bottom: 1px solid #21262f; }
tbody td a { color: var(--accent); text-decoration: none; }
tbody td a:hover { text-decoration: underline; }
tbody tr { transition: background 0.1s; }
.clickable tbody tr { cursor: pointer; }
.clickable tbody tr:hover { background: var(--panel-2); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.name-cell { display: flex; align-items: center; gap: 9px; }
.avatar { width: 26px; height: 26px; border-radius: 50%; background: var(--panel-2); object-fit: cover; flex: none; }

.king-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.king-1 td { background: rgba(244,197,66,0.08); }
.rankbadge { display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; border-radius: 50%; font-size: 13px; font-weight: 700;
  background: var(--panel-2); color: var(--muted); }
.king-1 .rankbadge { background: var(--gold); color: #2a1d00; }
.king-2 .rankbadge { background: #c8ccd6; color: #1a1d24; }
.king-3 .rankbadge { background: #cd7f4b; color: #1a1d24; }
.pts { font-weight: 700; color: var(--gold); }

/* Legends completion bar */
.clickable-row { cursor: pointer; }
.clickable-row:hover { background: var(--panel-2); }
.pct-cell { width: 40%; }
.pct-bar { position: relative; height: 8px; border-radius: 5px; background: var(--panel-2); overflow: hidden; }
.pct-bar span { position: absolute; left: 0; top: 0; bottom: 0; background: var(--accent); border-radius: 5px; }
.king-1 .pct-bar span { background: var(--gold); }
.cov { white-space: nowrap; font-variant-numeric: tabular-nums; font-size: 13px; }
.cov-weak { color: var(--climb); }
.expand-btn { display: block; width: 100%; margin-top: 10px; padding: 10px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  color: var(--accent); font-size: 14px; font-weight: 600; cursor: pointer; }
.expand-btn:hover { border-color: var(--accent); background: var(--panel-2); }

.seg-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.pill { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 11.5px; font-weight: 600; }
.pill.climb { background: rgba(232,98,58,0.18); color: var(--climb); }
.pill.flat { background: rgba(91,155,213,0.18); color: var(--flat); }
.pill.descent { background: rgba(87,201,138,0.18); color: var(--descent); }
.pill.out { background: rgba(139,147,167,0.18); color: var(--muted); }
.pill.cat-cimacoppi { background: rgba(244,197,66,0.20); color: var(--gold); }
.pill.cat-cat1 { background: rgba(252,82,0,0.20); color: var(--accent); }
.pill.cat-cat2 { background: rgba(232,98,58,0.16); color: var(--climb); }
.pill.cat-cat3 { background: rgba(91,155,213,0.16); color: var(--flat); }
.pill.cat-cat4 { background: rgba(139,147,167,0.16); color: var(--muted); }
.pill.sub { background: rgba(244,197,66,0.16); color: var(--gold); text-decoration: none; }
.subseg-badge { color: var(--muted); font-size: 11.5px; font-weight: 600; }
.diff { font-weight: 700; }

/* z-index above Leaflet's panes/controls (which go up to ~1000) so the main
   map never pokes through the modal. */
#detail-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px;
  overflow-y: auto; z-index: 1100; }
#detail-overlay.hidden { display: none; }
#detail-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  width: 100%; max-width: 760px; position: relative; padding: 24px; }
#detail-close { position: absolute; top: 12px; right: 14px; background: none; border: none;
  color: var(--muted); font-size: 28px; line-height: 1; cursor: pointer; }
#detail-close:hover { color: var(--text); }
.detail-head { display: flex; flex-wrap: wrap; gap: 8px 18px; align-items: baseline; margin: 0 0 14px; }
.detail-head h3 { margin: 0; font-size: 22px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
  gap: 10px; margin: 16px 0; }
.stat { background: var(--panel-2); border-radius: 9px; padding: 10px 12px; }
.stat .k { color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.4px; }
.stat .v { font-size: 17px; font-weight: 700; margin-top: 2px; }
.profile { width: 100%; height: 130px; background: var(--panel-2); border-radius: 9px; margin: 6px 0 16px; }
.seg-map { width: 100%; border-radius: 9px; border: 1px solid var(--line); display: block; margin-bottom: 16px; }
#detail-map.seg-map { height: 340px; background: #0a0c10; }
/* start / finish pins on the segment-detail map */
.seg-pin { display: flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; border-radius: 50%; font-size: 12px; font-weight: 700;
  color: #fff; border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,0.5); }
.seg-pin.start { background: var(--descent); }
.seg-pin.finish { background: var(--accent); }
/* featured athlete chips */
.chips { display: flex; flex-wrap: wrap; gap: 10px; }
.athlete-chip { display: inline-flex; align-items: center; gap: 9px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 24px;
  padding: 6px 14px 6px 6px; color: var(--text); text-decoration: none; font-size: 14px; }
.athlete-chip:hover { border-color: var(--accent); }

/* map page */
.map-page, .map-page body { height: 100%; }
.map-controls { display: flex; flex-wrap: wrap; gap: 16px 24px; align-items: center; margin-top: 12px; }
.metric-switch { display: flex; align-items: center; gap: 8px; }
.metric-switch button { background: var(--panel-2); border: 1px solid var(--line);
  color: var(--text); padding: 6px 12px; border-radius: 8px; cursor: pointer; font-size: 13px; }
.metric-switch button.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.discipline-switch { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.discipline-switch button { background: var(--panel-2); border: 1px solid var(--line);
  color: var(--text); padding: 6px 12px; border-radius: 8px; cursor: pointer; font-size: 13px; }
.discipline-switch button.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.toggle { color: var(--muted); font-size: 13px; display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.footnote-ref { color: var(--accent); text-decoration: none; }
.footnote-ref:hover { text-decoration: underline; }
.view-toggles { display: flex; justify-content: center; margin-top: 10px; }
#map { height: 70vh; width: 100%; background: #0a0c10; }
.leaflet-popup-content { font: 13px -apple-system, system-ui, sans-serif; }
.legend { max-width: 1100px; margin: 14px auto; padding: 0 20px; color: var(--muted); }
.legend-title { font-size: 12px; text-transform: uppercase; letter-spacing: 0.4px; margin-bottom: 6px; color: var(--text); }
.legend .bar { height: 12px; border-radius: 6px; max-width: 340px; }
.legend .ends { display: flex; justify-content: space-between; max-width: 340px; font-size: 12px; margin-top: 3px; }
.legend-note { margin-top: 8px; font-size: 12px; display: flex; align-items: center; gap: 7px; }
.swatch.filtered { display: inline-block; width: 22px; height: 0; border-top: 2px dashed #8b93a7; }
.legend-swatches { display: flex; flex-wrap: wrap; gap: 10px 16px; margin-bottom: 4px; }
.legend-swatch-item { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; }
.swatch-dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; flex: none; }
.nav-link { color: var(--accent); text-decoration: none; font-size: 14px; font-weight: 600; }
.nav-link:hover { text-decoration: underline; }

.site-nav { display: flex; justify-content: center; gap: 8px; margin-bottom: 14px; }
.site-nav-item { display: inline-block; padding: 5px 14px; border-radius: 8px; font-size: 13px;
  font-weight: 600; border: 1px solid var(--line); background: var(--panel-2); color: var(--muted);
  text-decoration: none; }
.site-nav-item.active { background: var(--accent); border-color: var(--accent); color: #fff; cursor: default; }
.site-nav-item:not(.active):hover { border-color: var(--accent); color: var(--text); }

/* athlete page */
.back-link { color: var(--muted); text-decoration: none; font-size: 14px; }
.back-link:hover { color: var(--text); }
.athlete-head { display: flex; align-items: center; gap: 14px; margin-top: 14px; }
.athlete-head .avatar { width: 56px; height: 56px; }
.athlete-head h1 { font-size: 26px; }
.athlete-head .sub { margin: 2px 0 0; }
tr.todo td { opacity: 0.6; }
.kom { color: var(--gold); font-weight: 700; }

/* methodology — narrow, centered text; tables keep the fuller width */
#methodology h2, #methodology p { max-width: 66ch; margin-left: auto; margin-right: auto; }
#methodology p { margin-bottom: 12px; }
.formula code { font-size: 14px; padding: 8px 12px; display: inline-block; }
.method-table { width: auto; margin: 4px auto 16px; border: 1px solid var(--line);
  border-radius: 8px; overflow: hidden; }
.method-table th, .method-table td { padding: 7px 18px; text-align: left;
  border-bottom: 1px solid #21262f; }
.method-table th { color: var(--muted); font-size: 12px; text-transform: uppercase;
  letter-spacing: 0.4px; cursor: default; }
.method-table td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.method-table tr:last-child td { border-bottom: none; }
.points-grid { width: 100%; margin: 4px 0 8px; border: 1px solid var(--line);
  border-radius: 8px; border-collapse: collapse; overflow: hidden; }
.points-grid th, .points-grid td { padding: 6px 6px; text-align: center;
  border-bottom: 1px solid #21262f; font-variant-numeric: tabular-nums; font-size: 13px; }
.points-grid th { color: var(--muted); font-size: 11px; text-transform: uppercase; }
.points-grid th:first-child, .points-grid td:first-child { text-align: left; white-space: nowrap; }
.points-grid tr:last-child td { border-bottom: none; }

footer { border-top: 1px solid var(--line); padding: 20px 0 40px; }
code { background: var(--panel-2); padding: 1px 6px; border-radius: 5px; font-size: 13px; }
.err { background: #2a1416; border: 1px solid #5a2a2e; color: #f0b8bc; padding: 16px; border-radius: 10px; }
