:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --hairline: #e1e0d9;
  --border: rgba(11, 11, 11, 0.10);
  --team: #eb6834;       /* focus team */
  --compare: #2a78d6;    /* comparison track */
  --good-text: #006300;
  --bad-text: #d03b3b;
  --warn: #fab219;
  --accent-wash: rgba(235, 104, 52, 0.10);
  --shadow: 0 1px 3px rgba(0,0,0,.12);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #262624;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --hairline: #2c2c2a;
    --border: rgba(255, 255, 255, 0.10);
    --team: #d95926;
    --compare: #3987e5;
    --good-text: #0ca30c;
    --bad-text: #e66767;
    --accent-wash: rgba(217, 89, 38, 0.16);
    --shadow: 0 1px 3px rgba(0,0,0,.5);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --surface-2: #262624; --ink: #ffffff; --ink-2: #c3c2b7;
  --muted: #898781; --hairline: #2c2c2a; --border: rgba(255,255,255,.10); --team: #d95926;
  --compare: #3987e5; --good-text: #0ca30c; --bad-text: #e66767; --accent-wash: rgba(217,89,38,.16);
  --shadow: 0 1px 3px rgba(0,0,0,.5);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--page); color: var(--ink); font-size: 14px; line-height: 1.4; display: flex; flex-direction: column; }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.eyebrow { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.row { display: flex; align-items: center; flex-wrap: wrap; }
.gap { gap: 8px; }
code { font-size: 12px; background: var(--surface-2); padding: 1px 4px; border-radius: 4px; }

/* ---------- top bar */
.topbar { display: flex; align-items: center; gap: 16px; padding: 8px 16px; background: var(--surface); border-bottom: 1px solid var(--hairline); flex-wrap: wrap; }
.team-picker { display: flex; flex-direction: column; min-width: 0; }
.team-picker select { font-size: 16px; font-weight: 600; border: 0; background: transparent; padding: 0; max-width: 260px; cursor: pointer; }
.stats { display: flex; gap: 6px 20px; flex-wrap: wrap; flex: 1; }
.stat { display: flex; flex-direction: column; min-width: 0; }
.stat .v { font-size: 15px; font-weight: 600; white-space: nowrap; }
.stat .s { font-size: 12px; color: var(--ink-2); white-space: nowrap; }
.data-status { display: flex; align-items: center; gap: 8px; margin-left: auto; font-size: 12px; }
.data-status .warn { color: var(--bad-text); }

.btn { color: var(--ink); border: 1px solid var(--border); background: var(--surface); border-radius: 6px; padding: 5px 10px; cursor: pointer; }
.btn:hover { background: var(--surface-2); }
.btn.tiny { padding: 2px 7px; font-size: 12px; }

.ahead { color: var(--good-text); font-weight: 600; }
.behind { color: var(--bad-text); font-weight: 600; }

/* ---------- layout */
.layout { flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) 440px; min-height: 0; }
.map-wrap { position: relative; min-height: 0; }
#map { position: absolute; inset: 0 0 var(--elev-h, 34px) 0; background: var(--surface-2); }
.map-wrap.elev-open { --elev-h: 250px; }
.map-tools { position: absolute; top: 10px; left: 54px; z-index: 500; display: flex; gap: 6px; }
.map-btn { box-shadow: var(--shadow); font-weight: 500; }

.sidebar { display: flex; flex-direction: column; min-height: 0; background: var(--surface); border-left: 1px solid var(--hairline); }
.tabs { display: flex; border-bottom: 1px solid var(--hairline); padding: 0 8px; }
.tabs button { border: 0; background: none; padding: 10px 10px 8px; cursor: pointer; color: var(--ink-2); border-bottom: 2px solid transparent; font-weight: 500; }
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--team); }
.panel { overflow: auto; flex: 1; padding: 12px; }

.menu-btn, .drawer-close, .scrim { display: none; }

/* Small screens: a slim bar with just the team picker; the side panel is a drawer over the map. */
@media (max-width: 900px) {
  body { height: 100dvh; }
  .topbar { flex-wrap: nowrap; gap: 8px; padding: 4px 6px 4px 12px; }
  .topbar .stats, .team-picker .eyebrow { display: none; }
  .team-picker { flex: 1; }
  .team-picker select { max-width: none; width: 100%; font-size: 15px; padding: 6px 0; }
  .data-status { font-size: 11px; white-space: nowrap; }
  .data-status .wide { display: none; }
  .menu-btn { display: block; flex: none; font-size: 18px; line-height: 1; padding: 7px 11px; }
  .layout { display: block; position: relative; overflow: hidden; }
  .map-wrap { position: absolute; inset: 0; }
  .sidebar { position: absolute; top: 0; right: 0; bottom: 0; width: min(440px, 92vw); z-index: 1100; border-left: 1px solid var(--hairline); box-shadow: -4px 0 16px rgba(0,0,0,.18);
    transform: translateX(100%); visibility: hidden; transition: transform .2s ease, visibility 0s .2s; }
  body.drawer-open .sidebar { transform: none; visibility: visible; transition: transform .2s ease; }
  .tabs { align-items: center; }
  .drawer-close { display: block; margin-left: auto; border: 0; background: none; padding: 8px 10px; font-size: 16px; color: var(--ink-2); cursor: pointer; }
  .scrim { display: block; position: absolute; inset: 0; z-index: 1050; background: rgba(0,0,0,.3); }
  .scrim[hidden] { display: none; }
}
@media (max-width: 900px) and (prefers-reduced-motion: reduce) { .sidebar, body.drawer-open .sidebar { transition: none; } }

.legend-note { font-size: 12px; color: var(--muted); margin: 0 0 10px; }

/* ---------- cards */
.card { background: var(--surface); border: 1px solid var(--hairline); border-radius: 8px; padding: 12px; margin-bottom: 12px; }
.card h3 { margin: 0 0 4px; font-size: 15px; }
.card h4 { margin: 10px 0 4px; font-size: 13px; }
.rb-stats { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; color: var(--ink-2); margin: 6px 0; }
.rb-stats b { color: var(--ink); font-weight: 600; }
.rb-desc { margin: 6px 0; }
.rb-points { font-size: 12px; color: var(--ink-2); }
.rb-points a { color: inherit; }

/* ---------- teams */
.team-search { width: 100%; padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); margin-bottom: 8px; }
table.teams { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: 13px; }
table.teams th { font-size: 11px; font-weight: 500; color: var(--muted); text-align: left; padding: 4px; }
table.teams td { padding: 5px 4px; border-bottom: 1px solid var(--hairline); }
table.teams tr.focus td { background: var(--accent-wash); font-weight: 600; }
table.teams .nm { max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
table.teams td.r { text-align: right; white-space: nowrap; }

/* ---------- leaderboard */
.seg { display: inline-flex; margin-bottom: 10px; }
.seg .btn { border-radius: 0; }
.seg .btn:first-child { border-radius: 6px 0 0 6px; }
.seg .btn:last-child { border-radius: 0 6px 6px 0; margin-left: -1px; }
.seg .btn[aria-pressed="true"] { background: var(--team); border-color: var(--team); color: #fff; }
.board-ctl { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.board-ctl select { flex: 1; min-width: 0; padding: 5px 6px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--ink); }
.board-ctl.split { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 8px; }
.board-ctl[hidden] { display: none; }
.board-ctl.split label { display: flex; flex-direction: column; gap: 2px; font-size: 12px; color: var(--ink-2); min-width: 0; }
.board-ctl.split label:first-child, .board-ctl.split .check { grid-column: 1 / -1; }
.board-ctl.split .check { flex-direction: row; align-items: center; gap: 6px; }
.board-sum { font-size: 13px; margin: 4px 0 8px; color: var(--ink-2); }
.board-sum a { color: var(--ink); font-weight: 600; }
table.board { table-layout: fixed; }
table.board th:nth-child(1) { width: 30px; }
table.board th:nth-child(2) { width: 26px; }
table.board th:nth-child(4) { width: 34%; }
table.board th:nth-child(5) { width: 54px; }
table.board td { vertical-align: top; }
table.board .nm { max-width: none; }
table.board .sub { display: block; font-size: 11px; color: var(--muted); }
.link { border: 0; background: none; padding: 0; font: inherit; color: inherit; cursor: pointer; text-align: left; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link:hover { text-decoration: underline; }

/* ---------- map markers */
.cp-icon { display: flex; align-items: center; justify-content: center; font: 600 10px/1 system-ui, sans-serif; color: #0b0b0b; background: #fff; border: 2px solid #0b0b0b; box-shadow: 0 1px 2px rgba(0,0,0,.4); white-space: nowrap; }
.cp-icon.ta { border-radius: 4px; padding: 0 4px; height: 20px; }
.cp-icon.cp { border-radius: 10px; padding: 0 5px; height: 18px; }
.cp-icon.custom { border-radius: 3px; padding: 0 4px; height: 18px; border-style: dashed; }
.cp-icon.endpoint { border-radius: 4px; padding: 0 6px; height: 22px; background: #0b0b0b; color: #fff; }
.cp-icon.passed { background: var(--team); border-color: #fff; color: #fff; }
.cp-icon.next { outline: 3px solid var(--team); outline-offset: 1px; }
.team-icon { display: flex; align-items: center; justify-content: center; width: 30px; height: 30px; border-radius: 50%; background: var(--team); color: #fff; border: 2px solid #fff; font: 700 12px/1 system-ui, sans-serif; box-shadow: 0 1px 4px rgba(0,0,0,.5); }
.team-icon.lost { background: #898781; }
.other-icon { display: flex; align-items: center; justify-content: center; min-width: 20px; height: 16px; padding: 0 3px; border-radius: 8px; background: rgba(82,81,78,.85); color: #fff; border: 1px solid #fff; font: 600 9px/1 system-ui, sans-serif; }
.other-icon.compare { background: var(--compare); font-weight: 700; }
.jump { color: var(--bad-text); }
.swatch { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 4px; vertical-align: 0; }
.leaflet-popup-content { margin: 10px 12px; font-size: 13px; line-height: 1.4; min-width: 220px; }
.pop h4 { margin: 0 0 2px; font-size: 14px; }
.pop .kv { display: grid; grid-template-columns: auto 1fr; gap: 1px 10px; margin-top: 6px; font-variant-numeric: tabular-nums; }
.pop .kv span:nth-child(odd) { color: #6b6a66; }
.pop .rb { margin-top: 6px; max-height: 140px; overflow: auto; color: #333; }
.pop .actions { margin-top: 8px; display: flex; gap: 6px; }
.track-tip { font-variant-numeric: tabular-nums; }

.opacity-ctl { display: flex; align-items: center; gap: 6px; background: #fff; color: #0b0b0b; padding: 4px 8px; font-size: 12px; margin-bottom: 4px !important; }
.opacity-ctl input { width: 90px; }
.opacity-ctl[hidden] { display: none; }
.pop a.btn { text-decoration: none; color: inherit; }

/* ---------- elevation drawer */
.elev { position: absolute; left: 0; right: 0; bottom: 0; height: var(--elev-h, 34px); background: var(--surface); border-top: 1px solid var(--hairline); display: flex; flex-direction: column; z-index: 600; }
.elev-head { display: flex; align-items: center; height: 34px; flex: none; }
.elev-toggle { display: flex; align-items: center; gap: 4px; height: 34px; flex: 1; min-width: 0; border: 0; background: none; padding: 0 12px; cursor: pointer; text-align: left; color: var(--ink); }
.elev-toggle:hover { background: var(--surface-2); }
.elev-title { font-weight: 600; }
.elev-summary { color: var(--ink-2); font-size: 12px; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.elev-caret { color: var(--muted); transition: transform .15s; }
.elev-toggle[aria-expanded="true"] .elev-caret { transform: rotate(180deg); }
.elev-body { position: relative; flex: 1; min-height: 0; }
.elev-chart { position: absolute; inset: 0 0 4px 0; }
.elev-chart svg { display: block; font-family: inherit; }
.elev-chart { touch-action: none; user-select: none; }
.elev-chart.zoomed { cursor: grab; }
.elev-chart.dragging { cursor: grabbing !important; }
.elev-zoom { display: flex; align-items: center; gap: 3px; padding: 0 8px 0 4px; flex: none; }
.elev-zoom[hidden] { display: none; }
.elev-zoom .btn { min-width: 26px; }
.elev-zoom .btn:disabled { opacity: .4; cursor: default; background: var(--surface); }
.elev-range { font-size: 12px; color: var(--ink-2); font-variant-numeric: tabular-nums; margin-right: 4px; white-space: nowrap; }
.eb-label.k { font-weight: 500; fill: var(--ink-2); }
.eb-band { fill: var(--surface-2); opacity: .6; }
.eb-stage { font-size: 10px; fill: var(--muted); }
.eb-grid { stroke: var(--hairline); stroke-width: 1; }
.eb-base { stroke: var(--muted); stroke-width: 1; opacity: .6; }
.eb-axis { font-size: 10px; fill: var(--muted); font-variant-numeric: tabular-nums; }
.eb-area { fill: var(--ink-2); opacity: .10; }
.eb-area-done { fill: var(--team); opacity: .22; }
.eb-line { fill: none; stroke: var(--ink-2); stroke-width: 1.5; stroke-linejoin: round; opacity: .7; }
.eb-line.est { stroke-dasharray: 4 3; opacity: .55; }
.eb-line-done { fill: none; stroke: var(--team); stroke-width: 2; stroke-linejoin: round; }
.eb-ta { fill: var(--surface); stroke: var(--ink); stroke-width: 1.5; }
.eb-ta.done, .eb-cp.done { fill: var(--team); stroke: var(--surface); }
.eb-cp { fill: var(--surface); stroke: var(--ink-2); stroke-width: 1.5; }
.eb-k { fill: var(--ink-2); opacity: .7; }
.eb-k.done { fill: var(--team); opacity: 1; }
.eb-label { font-size: 10px; font-weight: 600; fill: var(--ink); paint-order: stroke; stroke: var(--surface); stroke-width: 3px; }
.eb-now { stroke: var(--team); stroke-width: 1; stroke-dasharray: 3 3; }
.eb-team { fill: var(--team); stroke: var(--surface); stroke-width: 2; }
.eb-team-label { font-size: 11px; font-weight: 700; fill: var(--ink); paint-order: stroke; stroke: var(--surface); stroke-width: 3px; }
.eb-cross { stroke: var(--muted); stroke-width: 1; }
.eb-hover { fill: none; stroke: var(--ink); stroke-width: 2; }
.elev-tip { position: absolute; pointer-events: none; background: var(--surface); color: var(--ink); border: 1px solid var(--border); box-shadow: var(--shadow); border-radius: 6px; padding: 5px 8px; font-size: 12px; line-height: 1.35; white-space: nowrap; font-variant-numeric: tabular-nums; z-index: 2; }
@media (max-width: 900px) { .map-wrap.elev-open { --elev-h: 210px; } }
