:root {
  --bg: #f6f7fb; --bg-2: #ffffff; --ink: #0b1a33; --muted: #5b6b85; --line: #e3e7ef;
  --accent: #ff6a13; --accent-ink: #ffffff; --blue: #1856c9; --green: #1f9d55; --amber: #d98b0b; --red: #d33a2c;
  --course: #1856c9; --trail: #ff6a13; --ghost: #8a94a8; --spot: #d98b0b; --ly: #7c3aed;
  --shadow: 0 1px 2px rgba(11,26,51,.06), 0 8px 24px rgba(11,26,51,.06);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1222; --bg-2: #121b30; --ink: #eef2fa; --muted: #9aa8c2; --line: #233150;
    --course: #6f9cff; --ghost: #8a94a8; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
  }
}
:root[data-theme="dark"] {
  --bg: #0b1222; --bg-2: #121b30; --ink: #eef2fa; --muted: #9aa8c2; --line: #233150; --course: #6f9cff;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body { background: var(--bg); color: var(--ink); font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", Inter, Segoe UI, Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
main { max-width: 1100px; margin: 0 auto; padding: 0 16px 48px; display: grid; gap: 16px; }
h1 { font-size: 20px; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 0 0 6px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.top { max-width: 1100px; margin: 0 auto; padding: 14px 16px 10px; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.sub { color: var(--muted); font-size: 14px; }
.status { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 999px; background: var(--bg-2); box-shadow: var(--shadow); font-size: 14px; font-weight: 600; }
.status .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
.status.live .dot { background: var(--green); box-shadow: 0 0 0 0 rgba(31,157,85,.6); animation: ping 1.6s infinite; }
.status.stale .dot { background: var(--amber); }
.status.done .dot { background: var(--blue); }
.status.err .dot { background: var(--red); }
@keyframes ping { 0% { box-shadow: 0 0 0 0 rgba(31,157,85,.55); } 100% { box-shadow: 0 0 0 10px rgba(31,157,85,0); } }

.hero { display: grid; gap: 12px; }
.tiles { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; }
.tile { background: var(--bg-2); border-radius: 14px; padding: 12px 14px; box-shadow: var(--shadow); min-width: 0; }
.tile.big { grid-column: span 2; }
.tile.accent { background: var(--accent); color: var(--accent-ink); }
.tile.accent .label, .tile.accent .unit { color: rgba(255,255,255,.85); }
.tile .label { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.tile .value { font-size: clamp(22px, 2.6vw, 30px); font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; line-height: 1.15; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile.big .value { font-size: 40px; }
.tile .unit { font-size: 12px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 820px) { .tiles { grid-template-columns: repeat(3, 1fr); } .tile.big { grid-column: span 3; } .tile .value { font-size: clamp(20px, 6vw, 24px); } .tile.big .value { font-size: 40px; } }
@media (max-width: 420px) { .tiles { grid-template-columns: repeat(2, 1fr); } .tile.big { grid-column: span 2; } }

.progress { position: relative; padding-bottom: 20px; }
.bar { position: relative; height: 12px; border-radius: 999px; background: var(--line); overflow: visible; }
.fill { height: 100%; width: 0; border-radius: 999px; background: linear-gradient(90deg, var(--blue), var(--accent)); transition: width .8s ease; }
.ghost-mark { position: absolute; top: -3px; width: 2px; height: 18px; background: var(--ghost); left: 0; transition: left .8s ease; }
.runner-mark { position: absolute; top: -4px; width: 20px; height: 20px; margin-left: -10px; border-radius: 50%; background: var(--accent); border: 3px solid var(--bg-2); box-shadow: 0 0 0 2px var(--accent); left: 0; transition: left .8s ease; }
.boroughs { position: relative; height: 18px; margin-top: 6px; font-size: 11px; color: var(--muted); }
.boroughs span { position: absolute; transform: translateX(-50%); white-space: nowrap; }
.boroughs span::before { content: ""; position: absolute; left: 50%; top: -8px; height: 6px; border-left: 1px solid var(--line); }
@media (max-width: 600px) { .boroughs span.tight { display: none; } }
.banner { margin: 0; padding: 10px 14px; border-radius: 12px; background: var(--bg-2); box-shadow: var(--shadow); border-left: 4px solid var(--amber); font-size: 14px; }

.mapwrap { position: relative; }
#map { height: 56vh; min-height: 340px; border-radius: 16px; box-shadow: var(--shadow); background: var(--bg-2); }
.map-tools { position: absolute; top: 10px; right: 10px; z-index: 800; display: flex; gap: 8px; align-items: center; background: var(--bg-2); padding: 6px 10px; border-radius: 10px; box-shadow: var(--shadow); font-size: 13px; }
.follow { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.linkish { background: none; border: 0; color: var(--blue); font: inherit; font-size: 13px; cursor: pointer; padding: 0; }
.legend { position: absolute; left: 10px; bottom: 10px; z-index: 800; display: flex; gap: 12px; background: var(--bg-2); padding: 6px 10px; border-radius: 10px; box-shadow: var(--shadow); font-size: 12px; }
.legend .sw { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 5px; vertical-align: -1px; }
.sw.runner { background: var(--accent); } .sw.ghost { background: var(--ghost); } .sw.spot { background: var(--spot); border-radius: 2px; }
.runner-icon .runner-dot { width: 22px; height: 22px; border-radius: 50%; background: var(--accent); border: 3px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,.35); position: relative; }
.runner-icon .pulse { position: absolute; inset: -3px; border-radius: 50%; border: 2px solid var(--accent); animation: pulse 1.8s ease-out infinite; }
@keyframes pulse { 0% { transform: scale(1); opacity: .9; } 100% { transform: scale(2.4); opacity: 0; } }
.ghost-icon .ghost-dot { width: 14px; height: 14px; border-radius: 50%; background: var(--ghost); border: 2px solid #fff; opacity: .9; }
.spot-icon { font-size: 16px; line-height: 20px; text-align: center; filter: drop-shadow(0 1px 1px rgba(0,0,0,.4)); }
.spot-icon.passed { opacity: .45; }
.maplibregl-canvas-container, .maplibregl-canvas { border-radius: 16px; }
.maplibregl-popup-content { background: var(--bg-2); color: var(--ink); border-radius: 10px; font: inherit; font-size: 13px; line-height: 1.35; padding: 8px 10px; box-shadow: var(--shadow); }
.maplibregl-popup-anchor-bottom .maplibregl-popup-tip { border-top-color: var(--bg-2); }
.maplibregl-popup-anchor-top .maplibregl-popup-tip { border-bottom-color: var(--bg-2); }
.maplibregl-popup-anchor-left .maplibregl-popup-tip { border-right-color: var(--bg-2); }
.maplibregl-popup-anchor-right .maplibregl-popup-tip { border-left-color: var(--bg-2); }
.maplibregl-ctrl-top-left { top: 6px; left: 6px; }
#map .maplibregl-ctrl-attrib { font-size: 10px; }
.map-tools { top: 10px; right: 10px; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 820px) { .grid2 { grid-template-columns: 1fr; } }
.card { background: var(--bg-2); border-radius: 16px; padding: 16px; box-shadow: var(--shadow); min-width: 0; }
table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 7px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
td.num, th.num { text-align: right; }
tr.passed td { color: var(--muted); }
tr.next td { font-weight: 700; }
.spots td:first-child { width: 55%; }
.spots .mi { color: var(--muted); font-size: 12px; display: block; }
.eta { font-weight: 700; white-space: nowrap; }
.eta-sub { color: var(--muted); font-size: 12px; white-space: nowrap; display: block; }
.pos { color: var(--green); } .neg { color: var(--red); }
.splits { table-layout: fixed; }
.splits th:first-child, .splits td:first-child { width: 20%; }

form#cheer-form { display: grid; gap: 8px; margin: 8px 0; }
input, textarea { font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%; }
textarea { resize: vertical; }
button { font: inherit; font-weight: 600; color: var(--accent-ink); background: var(--accent); border: 0; border-radius: 10px; padding: 10px 14px; cursor: pointer; }
button:disabled { opacity: .55; cursor: default; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.note { font-size: 13px; color: var(--muted); }
.cheer-count { font-weight: 700; margin: 10px 0 4px; }
.feed { list-style: none; margin: 0; padding: 0; max-height: 260px; overflow: auto; font-size: 14px; }
.feed li { padding: 6px 0; border-bottom: 1px solid var(--line); }
.feed .who { font-weight: 700; }
.feed .meta { color: var(--muted); font-size: 12px; margin-left: 6px; }
.badge { display: inline-block; font-size: 10px; padding: 1px 6px; border-radius: 999px; background: var(--line); color: var(--muted); margin-left: 6px; vertical-align: 1px; }
.badge.ok { background: rgba(31,157,85,.15); color: var(--green); }

svg#profile, svg#hrchart { width: 100%; height: 170px; display: block; border-radius: 10px; }
.axis { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 2px; }
.prof-area { fill: var(--course); opacity: .18; }
.prof-line { fill: none; stroke: var(--course); stroke-width: 2; vector-effect: non-scaling-stroke; }
.prof-spot { stroke: var(--spot); stroke-width: 1; opacity: .7; vector-effect: non-scaling-stroke; }
.prof-runner { fill: var(--accent); stroke: #fff; stroke-width: 2; vector-effect: non-scaling-stroke; }
.prof-ghost { fill: var(--ghost); }
.prof-label { font-size: 11px; fill: var(--muted); }
.hr-line { fill: none; stroke: var(--red); stroke-width: 2; vector-effect: non-scaling-stroke; }
.hr-grid { stroke: var(--line); stroke-width: 1; vector-effect: non-scaling-stroke; }

footer { color: var(--muted); font-size: 13px; display: grid; gap: 4px; padding-top: 8px; }
footer a { color: inherit; }

/* Training run: hide the marathon-only widgets */
body.training .progress, body.training .spots-card, body.training .profile-card, body.training .splits-card { display: none; }
body.training .grid2 { grid-template-columns: 1fr; }

/* Last year's run overlay */
.ly-mark { position: absolute; top: -3px; width: 2px; height: 18px; background: var(--ly); left: 0; transition: left .8s ease; }
.compare { margin: 4px 0 0; font-size: 13px; color: var(--muted); }
.compare b { color: var(--ink); }
.sw.ly { background: var(--ly); }
.ly-icon .ly-dot { width: 16px; height: 16px; border-radius: 50%; background: var(--bg-2); border: 3px solid var(--ly); box-shadow: 0 1px 4px rgba(0,0,0,.3); }
body.training .ly-mark, body.training .compare { display: none; }

/* Spectator location */
.me-result { margin: 10px 0 0; font-size: 16px; }
.me-result b { font-size: 20px; }
.sw.me { background: var(--blue); }
.me-icon .me-dot { width: 18px; height: 18px; border-radius: 50%; background: var(--blue); border: 3px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.35); }
body.training .me-card { display: none; }
/* Runner photo marker */
.runner-icon.photo .runner-dot { width: 40px; height: 40px; border: 3px solid var(--accent); background: var(--bg-2) center/cover no-repeat; }
.runner-icon.photo .pulse { inset: -4px; }

/* How this works */
.how { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px 18px; font-size: 14px; }
.how > div { padding: 8px 0; border-top: 1px solid var(--line); }
@media (max-width: 820px) { .how { grid-template-columns: 1fr; } }
.how-card a { color: var(--blue); }
body.training .how-card { display: none; }

/* Race numbers */
.chips { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 14px; }
@media (max-width: 820px) { .chips { grid-template-columns: repeat(2, 1fr); } }
.chip { background: var(--bg); border-radius: 12px; padding: 10px 12px; min-width: 0; }
.chip .k { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.chip .v { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.01em; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip .d { font-size: 12px; color: var(--muted); margin-top: 2px; }
.sub-h { font-size: 13px; color: var(--muted); margin: 6px 0 4px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
svg#pacechart { width: 100%; height: 220px; display: block; }
.pace-bar { fill: var(--accent); opacity: .85; }
.pace-bar.slow { fill: var(--amber); }
.pace-ly { fill: none; stroke: var(--ly); stroke-width: 2; vector-effect: non-scaling-stroke; }
.pace-goal { fill: none; stroke: var(--green); stroke-width: 2; stroke-dasharray: 6 5; vector-effect: non-scaling-stroke; }
.pace-grid { stroke: var(--line); stroke-width: 1; vector-effect: non-scaling-stroke; }
.legend-inline { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 6px; }
.sw.you { background: var(--accent); } .sw.goal { background: var(--green); } .sw.mat { background: #fff; border: 2px solid var(--muted); box-sizing: border-box; }
body.training .numbers-card, body.practice .numbers-card, body.practice .compare, body.practice .ly-mark { display: none; }

/* Simulation controls */
.simbar { display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: center; background: var(--bg-2); border-radius: 14px; padding: 10px 14px; box-shadow: var(--shadow); font-size: 13px; border-left: 4px solid var(--amber); }
.simbar-title { font-weight: 700; }
.simbar label { display: inline-flex; align-items: center; gap: 6px; }
.simbar .sim-pace { flex: 1 1 260px; }
.simbar input[type=range] { flex: 1; min-width: 120px; accent-color: var(--accent); }
.simbar select { font: inherit; font-size: 13px; padding: 4px 6px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); }
.simbar button.small { padding: 6px 10px; font-size: 13px; }

/* Sources row */
.sources-row { display: flex; gap: 8px 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.src { display: inline-flex; align-items: center; gap: 6px; background: var(--bg-2); padding: 4px 10px; border-radius: 999px; box-shadow: var(--shadow); }
.src i { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); display: inline-block; }
.src.ok i { background: var(--green); } .src.warn i { background: var(--amber); } .src.off i { background: var(--line); }
.src b { color: var(--ink); font-weight: 600; }
body.training .sources-row { display: none; }
