:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --wash-1: rgba(42, 120, 214, 0.10);
  --good: #0ca30c;
  --good-text: #006300;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --accent: #2a78d6;
  --radius: 12px;
  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;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --wash-1: rgba(57, 135, 229, 0.12);
    --good-text: #0ca30c;
    --accent: #3987e5;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --wash-1: rgba(57, 135, 229, 0.12);
  --good-text: #0ca30c;
  --accent: #3987e5;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--page); color: var(--ink); line-height: 1.45; font-size: 15px; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 4px; font-weight: 650; }
h2 { font-size: 15px; margin: 0 0 12px; font-weight: 600; }
h3 { font-size: 14px; margin: 16px 0 8px; }
.sub { color: var(--ink-2); margin: 0 0 20px; font-size: 14px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

header.top {
  position: sticky; top: 0; z-index: 1000; background: var(--surface);
  border-bottom: 1px solid var(--border);
}
header.top .in {
  max-width: 1180px; margin: 0 auto; padding: 0 16px; display: flex; align-items: center;
  gap: 18px; height: 54px;
}
.brand { font-weight: 700; color: var(--ink); white-space: nowrap; }
nav.main { display: flex; gap: 4px; overflow-x: auto; flex: 1; scrollbar-width: none; }
nav.main a {
  color: var(--ink-2); padding: 6px 10px; border-radius: 8px; white-space: nowrap; font-size: 14px;
}
nav.main a.on, nav.main a:hover { background: var(--page); color: var(--ink); text-decoration: none; }
.syncbox { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); white-space: nowrap; }
@media (max-width: 720px) { .syncbox .when { display: none; } }

main { max-width: 1180px; margin: 0 auto; padding: 20px 16px 60px; }
.banner {
  border: 1px solid var(--serious); background: color-mix(in srgb, var(--serious) 12%, var(--surface));
  border-radius: var(--radius); padding: 12px 14px; margin-bottom: 18px; font-size: 14px;
}
.banner.ok { border-color: var(--good); background: color-mix(in srgb, var(--good) 10%, var(--surface)); }

.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.tiles { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
@media (max-width: 860px) { .g2, .g3 { grid-template-columns: minmax(0, 1fr); } }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; min-width: 0;
}
.card + .card, .grid + .card, .card + .grid, .grid + .grid { margin-top: 16px; }

.tile .label { font-size: 13px; color: var(--ink-2); }
.tile .value { font-size: 26px; font-weight: 650; margin-top: 2px; }
.tile .value .unit { font-size: 14px; font-weight: 500; color: var(--ink-2); margin-left: 2px; }
.tile .delta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.hero .value { font-size: 48px; line-height: 1.1; }
.delta.good { color: var(--good-text); }
.delta.bad { color: var(--critical); }

.chart { position: relative; height: 220px; }
.chart.tall { height: 280px; }
.chart.short { height: 150px; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--ink-2); margin: -4px 0 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.empty { color: var(--muted); font-size: 14px; padding: 30px 0; text-align: center; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12px; padding: 6px 8px; border-bottom: 1px solid var(--grid); }
td { padding: 8px; border-bottom: 1px solid var(--grid); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tablewrap { overflow-x: auto; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--page); }

.pill {
  display: inline-flex; align-items: center; gap: 5px; font-size: 12px; padding: 2px 8px;
  border-radius: 999px; border: 1px solid var(--border); white-space: nowrap; color: var(--ink-2);
}
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.pill.done::before { background: var(--good); }
.pill.missed::before { background: var(--critical); }
.pill.today::before { background: var(--accent); }
.pill.skipped::before { background: var(--warning); }
.pill.modified::before { background: var(--serious); }

.note { border-top: 1px solid var(--grid); padding-top: 12px; margin-top: 12px; }
.note:first-of-type { border-top: 0; margin-top: 0; padding-top: 0; }
.note .meta { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.note .body > :first-child { margin-top: 0; }
.note .body > :last-child { margin-bottom: 0; }
.note .body { font-size: 14px; }
.note.me { border-left: 3px solid var(--series-2); padding-left: 10px; }

.bar { height: 8px; border-radius: 4px; background: var(--series-1); min-width: 2px; }
.bartrack { background: var(--grid); border-radius: 4px; }

button, .btn {
  font: inherit; font-size: 13px; border: 1px solid var(--border); background: var(--surface); color: var(--ink);
  padding: 6px 12px; border-radius: 8px; cursor: pointer;
}
button.primary, .btn.primary { background: var(--accent); color: #fff; border-color: transparent; }
button:hover, .btn:hover { filter: brightness(0.97); text-decoration: none; }
form.inline { display: inline; margin: 0; }
textarea, input[type=text], input[type=number] {
  font: inherit; width: 100%; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--page); color: var(--ink);
}
textarea { min-height: 90px; resize: vertical; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
#map { height: 320px; border-radius: 8px; }
/* Heatmap */
.hm-controls { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 12px; }
.seg { display: flex; flex-wrap: wrap; gap: 4px; }
.seg button { padding: 5px 10px; }
.seg button[aria-pressed="true"] { background: var(--accent); color: #fff; border-color: transparent; }
.hm-card { padding: 0; overflow: hidden; }
#heatmap { height: calc(100vh - 290px); min-height: 380px; background: var(--surface); }
#heatmap .leaflet-tile-pane { filter: grayscale(1) contrast(0.85) brightness(1.08); opacity: 0.55; }
.hm-canvas { pointer-events: none; }
.hm-legend { display: flex; align-items: center; gap: 8px; padding: 8px 12px; font-size: 12px; color: var(--ink-2); border-top: 1px solid var(--border); }
.hm-ramp { display: inline-block; height: 8px; width: 160px; border-radius: 4px;
  background: linear-gradient(90deg, #86b6ef, #3987e5, #1c5cab, #0d366b); }
.leaflet-popup-content { font-size: 13px; }
.leaflet-popup-content a { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) #heatmap .leaflet-tile-pane { filter: grayscale(1) invert(1) brightness(0.75) contrast(1.15); opacity: 0.7; }
  :root:not([data-theme="light"]) .hm-ramp { background: linear-gradient(90deg, #1c5cab, #3987e5, #86b6ef, #e8f1fd); }
}
:root[data-theme="dark"] #heatmap .leaflet-tile-pane { filter: grayscale(1) invert(1) brightness(0.75) contrast(1.15); opacity: 0.7; }
:root[data-theme="dark"] .hm-ramp { background: linear-gradient(90deg, #1c5cab, #3987e5, #86b6ef, #e8f1fd); }

.login { max-width: 380px; margin: 12vh auto; text-align: center; }
.login .card { padding: 32px 24px; }
code { font-size: 12px; background: var(--page); padding: 1px 5px; border-radius: 4px; word-break: break-all; }

/* Dashboard focus: the last run to comment on, or the next session with the coach's advice */
.focus { border-color: color-mix(in srgb, var(--accent) 35%, var(--border)); }
.eyebrow { font-size: 12px; font-weight: 600; letter-spacing: .02em; text-transform: uppercase; color: var(--accent); }
.focus-title { font-size: 22px; margin: 6px 0 4px; font-weight: 650; }
.focus-title a { color: var(--ink); }
.ink2 { color: var(--ink-2); }
.stats { display: flex; flex-wrap: wrap; gap: 8px 28px; margin: 14px 0; }
.stats > div { display: flex; flex-direction: column; font-size: 13px; color: var(--ink-2); }
.stats .label { font-size: 12px; color: var(--muted); }
.stats b { font-size: 20px; font-weight: 650; color: var(--ink); font-variant-numeric: tabular-nums; }
.stats b.good { color: var(--good-text); }
.stats b.bad { color: var(--critical); }
.focus .grid.g2 { margin: 4px 0 12px; }
.focus-map { height: 300px; border-radius: 8px; }
.splits { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 14px; font-size: 13px; font-variant-numeric: tabular-nums; }
.splits > span { padding: 3px 8px; border-radius: 6px; background: var(--page); border: 1px solid var(--grid); }
.focus .note { margin-top: 12px; }
.coach-box { background: var(--wash-1); border-radius: 8px; padding: 12px 14px; margin: 14px 0 4px; }
.coach-box .meta { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.coach-box .body { font-size: 14px; }
.coach-box .body > :first-child { margin-top: 0; }
.coach-box .body > :last-child { margin-bottom: 0; }
.focus-form { margin-top: 14px; }
a.card.next-mini { display: flex; flex-direction: column; gap: 2px; color: var(--ink); margin-top: 16px; }
a.card.next-mini:hover { text-decoration: none; border-color: var(--axis); }
.focus + .grid, .next-mini + .grid { margin-top: 16px; }
.plan-coach { margin-top: 6px; font-size: 13px; border-left: 3px solid var(--accent); padding-left: 8px; color: var(--ink-2); }
.plan-coach > :first-child { margin-top: 0; }
.plan-coach > :last-child { margin-bottom: 0; }

/* Race countdown */
a.card.race {
  display: flex; align-items: center; gap: 20px; margin: 4px 0 18px; color: var(--ink);
  border: 1px solid color-mix(in srgb, var(--series-2) 45%, var(--border));
  background: linear-gradient(100deg, color-mix(in srgb, var(--series-2) 14%, var(--surface)), var(--surface) 70%);
}
a.card.race:hover { text-decoration: none; border-color: var(--series-2); }
.race .eyebrow { color: var(--series-2); }
.race-count { display: flex; flex-direction: column; align-items: center; min-width: 84px; line-height: 1; }
.race-count b { font-size: 52px; font-weight: 700; color: var(--series-2); font-variant-numeric: tabular-nums; }
.race-count span { font-size: 13px; color: var(--ink-2); margin-top: 6px; white-space: nowrap; }
.race-info { min-width: 0; }
.race-title { font-size: 22px; font-weight: 650; margin: 4px 0 2px; }
@media (max-width: 520px) {
  a.card.race { gap: 14px; }
  .race-count { min-width: 64px; }
  .race-count b { font-size: 40px; }
  .race-title { font-size: 18px; }
}

/* Plan page: one Mon–Sun calendar per week */
.pill.partial::before { background: var(--warning); }
.weeks-h { margin: 24px 0 0; color: var(--ink-2); }
details.week { padding: 0; }
details.week + details.week, .weeks-h + details.week { margin-top: 16px; }
.week-head {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 16px;
  padding: 14px 16px; cursor: pointer; list-style: none;
}
.week-head::-webkit-details-marker { display: none; }
.week-head::before { content: "▸"; color: var(--muted); transition: transform .15s; }
details[open] > .week-head::before { transform: rotate(90deg); }
.week-title { flex: 1; display: flex; align-items: baseline; gap: 10px; }
.week-sum { display: flex; align-items: center; gap: 8px; font-size: 13px; font-variant-numeric: tabular-nums; }
.week-bar { display: inline-block; width: 90px; height: 6px; }
.week-bar .bar { display: block; height: 6px; }
details.week.current { border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); }
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border-top: 1px solid var(--grid); }
.cal-day { padding: 10px 8px 12px; min-height: 120px; border-right: 1px solid var(--grid); min-width: 0; font-size: 13px; }
.cal-day:last-child { border-right: 0; }
.cal-day.rest { background: color-mix(in srgb, var(--page) 60%, transparent); }
.cal-day.is-today { background: var(--wash-1); }
.cal-date { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.cal-date b { color: var(--ink); font-size: 14px; }
.cal-s { border-left: 3px solid var(--axis); padding-left: 7px; display: flex; flex-direction: column; gap: 4px; }
.cal-s + .cal-s { margin-top: 10px; }
.cal-s.done, .cal-s.modified { border-color: var(--good); }
.cal-s.partial, .cal-s.skipped { border-color: var(--warning); }
.cal-s.missed { border-color: var(--critical); }
.cal-s.today { border-color: var(--accent); }
.cal-s.race { border-color: var(--series-2); }
.cal-title { font-weight: 600; line-height: 1.3; overflow-wrap: anywhere; }
.cal-details { color: var(--ink-2); font-size: 12px; line-height: 1.35; }
.cal-actual { display: flex; flex-direction: column; gap: 2px; font-variant-numeric: tabular-nums; }
.cal-actual .bartrack { display: block; height: 5px; margin: 2px 0; }
.cal-actual .bar { display: block; height: 5px; }
.cal-s.partial .bar { background: var(--warning); }
.cal-s.done .bar { background: var(--good); }
.cal-runs { display: flex; flex-wrap: wrap; gap: 0 8px; font-size: 12px; }
.cal-foot { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.cal-coach summary { cursor: pointer; font-size: 12px; color: var(--accent); }
.cal-coach .plan-coach { font-size: 12px; }
.cal-note { font-size: 12px; color: var(--muted); }
.cal-extra { display: block; font-size: 12px; margin-top: 6px; color: var(--ink-2); }
@media (max-width: 760px) {
  .cal { grid-template-columns: minmax(0, 1fr); }
  .cal-day { border-right: 0; border-bottom: 1px solid var(--grid); min-height: 0; display: grid;
    grid-template-columns: 52px minmax(0, 1fr); gap: 0 10px; padding: 10px 16px; }
  .cal-day:last-child { border-bottom: 0; }
  .cal-day.rest { display: none; }
  .cal-date { grid-row: 1 / span 9; margin: 0; }
  .cal-date b { display: block; font-size: 18px; }
  .cal-day > :not(.cal-date) { grid-column: 2; }
  .week-head { padding: 12px 16px; }
}
