/* One stylesheet, no framework. Light and dark come from tokens, so every
   component is defined once and the theme swaps underneath it. */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #dde1e7;
  --text: #16191d;
  --muted: #626b78;
  --accent: #1f6feb;
  --accent-text: #ffffff;
  --good: #1a7f4b;
  --fair: #b06f00;
  --poor: #c0392b;
  --fitness: #1f6feb;
  --fatigue: #c0392b;
  --form: #1a7f4b;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --surface: #171b21;
    --surface-2: #1f242c;
    --border: #2b323b;
    --text: #e7ebf0;
    --muted: #98a2b3;
    --accent: #4c8dff;
    --accent-text: #0f1216;
    --good: #3ecf8e;
    --fair: #e0a11b;
    --poor: #f0685f;
    --fitness: #4c8dff;
    --fatigue: #f0685f;
    --form: #3ecf8e;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial,
    sans-serif;
}

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

/* --- shell --------------------------------------------------------------- */

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-inner {
  max-width: 980px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 22px;
  min-height: 56px;
  flex-wrap: wrap;
}
.brand { font-weight: 650; letter-spacing: -0.01em; color: var(--text); }
.topbar nav { display: flex; gap: 18px; flex: 1; }
.topbar nav a { color: var(--muted); font-weight: 500; }
.topbar nav a.active, .topbar nav a:hover { color: var(--text); text-decoration: none; }
.whoami { color: var(--muted); font-size: 13px; }

main { max-width: 980px; margin: 0 auto; padding: 26px 20px 60px; }

h1 { font-size: 24px; margin: 0 0 4px; letter-spacing: -0.02em; }
h2 { font-size: 16px; margin: 0 0 12px; letter-spacing: -0.01em; }
h3 { font-size: 14px; margin: 0 0 6px; }
.page-intro { color: var(--muted); margin: 0 0 22px; }

/* --- cards --------------------------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 18px;
}
.grid { display: grid; gap: 18px; }
@media (min-width: 760px) {
  .grid-2 { grid-template-columns: 260px 1fr; align-items: start; }
}

.muted { color: var(--muted); }
.small { font-size: 13px; }

/* --- readiness ----------------------------------------------------------- */

.readiness { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; }
.dial { width: 132px; height: 132px; flex: none; }
.dial-track { stroke: var(--surface-2); }
.dial-value { stroke: var(--muted); }
.dial-good .dial-value { stroke: var(--good); }
.dial-fair .dial-value { stroke: var(--fair); }
.dial-poor .dial-value { stroke: var(--poor); }
.dial-number { font-size: 30px; font-weight: 650; fill: var(--text); }
.dial-caption { font-size: 10px; fill: var(--muted); text-transform: uppercase;
  letter-spacing: 0.09em; }

.drivers { list-style: none; margin: 10px 0 0; padding: 0; }
.drivers li { color: var(--muted); font-size: 13px; padding: 2px 0 2px 14px; position: relative; }
.drivers li::before { content: "·"; position: absolute; left: 2px; }

.advice { margin: 0; font-size: 15px; font-weight: 500; }

/* --- stats --------------------------------------------------------------- */

.stats { display: flex; gap: 26px; flex-wrap: wrap; }
.stat-label { color: var(--muted); font-size: 12px; text-transform: uppercase;
  letter-spacing: 0.06em; }
.stat-value { font-size: 21px; font-weight: 620; }

/* --- charts -------------------------------------------------------------- */

.chart { width: 100%; height: auto; display: block; }
.axis { stroke: var(--border); stroke-width: 1; }
.tick { font-size: 10px; fill: var(--muted); }
.line { fill: none; stroke-width: 2; stroke-linejoin: round; }
.line-fitness { stroke: var(--fitness); }
.line-fatigue { stroke: var(--fatigue); }
.line-form { stroke: var(--form); stroke-dasharray: 3 3; }
.bar { fill: var(--accent); opacity: 0.75; }
.legend { color: var(--muted); font-size: 12px; margin: 6px 0 0; }
.key { display: inline-block; width: 10px; height: 3px; border-radius: 2px; margin: 0 5px 0 12px; }
.legend .key:first-child { margin-left: 0; }
.key-fitness { background: var(--fitness); }
.key-fatigue { background: var(--fatigue); }
.key-form { background: var(--form); }

/* --- tables -------------------------------------------------------------- */

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 550; font-size: 12px; text-transform: uppercase;
  letter-spacing: 0.05em; }
tbody tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* --- workouts ------------------------------------------------------------ */

.workout { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px;
  margin-bottom: 12px; background: var(--surface); }
.workout-head { display: flex; justify-content: space-between; gap: 12px; align-items: baseline;
  flex-wrap: wrap; }
.workout-title { font-weight: 600; }
.blocks { list-style: none; margin: 10px 0 0; padding: 0; font-size: 13px;
  font-variant-numeric: tabular-nums; }
.blocks li { padding: 3px 0; border-top: 1px dashed var(--border); }
.blocks li.indent { padding-left: 22px; }

.tag { display: inline-block; font-size: 11px; padding: 2px 8px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); text-transform: uppercase;
  letter-spacing: 0.05em; font-weight: 600; }
.tag-recovery, .tag-easy { color: var(--good); }
.tag-tempo { color: var(--fair); }
.tag-threshold, .tag-vo2 { color: var(--poor); }
.tag-adjusted { background: var(--fair); color: var(--accent-text); }
.tag-event { background: var(--poor); color: var(--accent-text); letter-spacing: 0.08em; }

/* --- forms and buttons --------------------------------------------------- */

label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=email], input[type=password], input[type=number], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); color: var(--text); font: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent);
  outline-offset: -1px; }
.field { margin-bottom: 14px; }
.field-row { display: flex; gap: 12px; flex-wrap: wrap; }
.field-row .field { flex: 1 1 150px; }

.btn {
  display: inline-block; padding: 9px 15px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); font: inherit; font-weight: 550;
  cursor: pointer;
}
.btn:hover { border-color: var(--muted); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-small { padding: 5px 10px; font-size: 13px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.flash { padding: 11px 14px; border-radius: 8px; margin-bottom: 18px; font-size: 14px; }
.flash-error { background: color-mix(in srgb, var(--poor) 14%, var(--surface));
  border: 1px solid var(--poor); }
.flash-ok { background: color-mix(in srgb, var(--good) 14%, var(--surface));
  border: 1px solid var(--good); }
.flash-warn { background: color-mix(in srgb, var(--fair) 14%, var(--surface));
  border: 1px solid var(--fair); }

code { background: var(--surface-2); padding: 2px 6px; border-radius: 5px; font-size: 13px;
  word-break: break-all; }

/* --- auth screens -------------------------------------------------------- */

.auth { max-width: 380px; margin: 9vh auto; padding: 0 20px; }
.auth .card { padding: 26px; }
.auth h1 { margin-bottom: 18px; }
.auth-alt { text-align: center; color: var(--muted); font-size: 14px; margin-top: 16px; }

/* --- sport colours -------------------------------------------------------
   One hue per discipline, used by the calendar chips and the session lists so
   a triathlete can read a week at a glance. */

:root {
  --sport-run: #e8590c;
  --sport-bike: #1f6feb;
  --sport-swim: #0c8599;
  --sport-row: #6741d9;
  --sport-walk: #2f9e44;
  --sport-strength: #868e96;
  --sport-other: #adb5bd;
}
@media (prefers-color-scheme: dark) {
  :root {
    --sport-run: #ff922b;
    --sport-bike: #4c8dff;
    --sport-swim: #22b8cf;
    --sport-row: #9775fa;
    --sport-walk: #51cf66;
    --sport-strength: #adb5bd;
    --sport-other: #868e96;
  }
}

.sport-dot {
  display: inline-block; width: 9px; height: 9px; border-radius: 50%;
  background: var(--chip, var(--sport-other)); margin-right: 6px; vertical-align: baseline;
}

/* --- page heading with an action on the right ---------------------------- */

.page-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 16px; flex-wrap: wrap; margin-bottom: 18px;
}
.page-head h1 { margin-bottom: 2px; }
.page-head .page-intro { margin: 0; }

/* --- goal banner and countdown ------------------------------------------- */

.goal-banner {
  display: flex; flex-direction: column; align-items: flex-end;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 14px; box-shadow: var(--shadow); color: var(--text);
}
.goal-banner:hover { border-color: var(--accent); text-decoration: none; }
.goal-banner-title { font-weight: 600; }
.goal-banner-count { color: var(--accent); font-size: 13px; font-weight: 600; }

.goal-card .goal-head { display: flex; justify-content: space-between; gap: 16px;
  align-items: flex-start; flex-wrap: wrap; }
.goal-card h2 { margin-bottom: 2px; }
.countdown { text-align: right; line-height: 1.1; }
.countdown-number { display: block; font-size: 34px; font-weight: 680; letter-spacing: -0.03em; }
.countdown-label { color: var(--muted); font-size: 12px; text-transform: uppercase;
  letter-spacing: 0.06em; }

.progress { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden;
  margin: 12px 0 6px; }
.progress-bar { height: 100%; background: var(--accent); border-radius: 999px; }

/* --- phase tags ----------------------------------------------------------- */

.tag-base { color: var(--good); }
.tag-build { color: var(--accent); }
.tag-peak { color: var(--poor); }
.tag-taper { color: var(--fair); }

/* --- calendar ------------------------------------------------------------- */

.calendar-card { padding: 12px; }
.calendar { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.cal-head { font-size: 11px; text-transform: uppercase; letter-spacing: 0.07em;
  color: var(--muted); text-align: center; padding: 4px 0 6px; font-weight: 600; }
.cal-cell {
  min-height: 92px; border: 1px solid var(--border); border-radius: 8px; padding: 5px 6px;
  display: flex; flex-direction: column; gap: 3px; background: var(--surface); color: var(--text);
  overflow: hidden;
}
.cal-cell:hover { border-color: var(--accent); text-decoration: none; }
.cal-cell.out { background: var(--surface-2); opacity: 0.55; }
.cal-cell.today { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.cal-day { font-size: 12px; color: var(--muted); font-weight: 600; }
.cal-cell.today .cal-day { color: var(--accent); }

.chip {
  font-size: 11px; line-height: 1.3; padding: 2px 5px; border-radius: 4px;
  border-left: 3px solid var(--chip, var(--sport-other));
  background: color-mix(in srgb, var(--chip, var(--sport-other)) 12%, transparent);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chip em { font-style: normal; color: var(--muted); }
.chip-planned { border-left-style: dashed; }
.chip-done { font-weight: 550; }
.key-planned { background: var(--muted); }
.key-done { background: var(--accent); }

@media (max-width: 700px) {
  .cal-cell { min-height: 62px; }
  .chip { font-size: 10px; }
}

/* --- sport picker --------------------------------------------------------- */

.sport-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 8px; }
.sport-pick {
  display: flex; align-items: center; gap: 4px; margin: 0; padding: 9px 11px;
  border: 1px solid var(--border); border-radius: 8px; cursor: pointer;
  font-size: 14px; color: var(--text);
}
.sport-pick:hover { border-color: var(--muted); }
.sport-pick.on { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%,
  var(--surface)); }
.sport-pick input { width: auto; margin-right: 4px; }

tr.zone-current { font-weight: 620; }

/* --- suggestion ----------------------------------------------------------- */

.suggestion { border-left: 3px solid var(--accent); }
.suggestion-main { display: flex; justify-content: space-between; align-items: center;
  gap: 14px; flex-wrap: wrap; margin-top: 10px; }
.btn-danger { color: var(--poor); }
.btn-danger:hover { border-color: var(--poor); }

/* --- wellness charts ------------------------------------------------------ */

.target-line { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 4 4; opacity: 0.6; }
.stage-deep { fill: var(--fitness); }
.stage-rem { fill: var(--sport-swim); }
.stage-light { fill: var(--sport-other); opacity: 0.7; }
.bar-over { fill: var(--good); opacity: 0.85; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 14px; }
.tile { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px;
  background: var(--surface); }
.tile-label { color: var(--muted); font-size: 12px; text-transform: uppercase;
  letter-spacing: 0.06em; }
.tile-value { font-size: 22px; font-weight: 640; letter-spacing: -0.02em; }
.tile-note { color: var(--muted); font-size: 12px; }
.trend-up { color: var(--poor); }
.trend-down { color: var(--good); }

/* --- map ------------------------------------------------------------------ */

.map { height: 460px; width: 100%; background: var(--surface-2); }
@media (max-width: 700px) { .map { height: 340px; } }

.map-bar {
  display: flex; justify-content: space-between; align-items: center; gap: 14px;
  padding: 12px 16px; border-top: 1px solid var(--border); flex-wrap: wrap;
}
.map-stats { display: flex; gap: 20px; font-size: 14px; align-items: baseline; }
.map-stats strong { font-size: 19px; font-variant-numeric: tabular-nums; }
.busy::after { content: ""; }

.waypoint { stroke: var(--accent); fill: var(--surface); fill-opacity: 1; }
.waypoint-end { stroke: var(--poor); fill: var(--surface); fill-opacity: 1; }
.leaflet-container { font: inherit; }

.tag-terrain-descent { color: var(--good); }
.tag-terrain-flat { color: var(--muted); }
.tag-terrain-gentle_climb { color: var(--fair); }
.tag-terrain-climb, .tag-terrain-steep_climb { color: var(--poor); }

/* --- zones ----------------------------------------------------------------
   One hue per zone, cool to hot. Used by the map, the table and the legend, so
   a colour means the same thing wherever it appears. */

:root {
  --zone-1: #6b9ac4;
  --zone-2: #2f9e44;
  --zone-3: #e8b021;
  --zone-4: #e8590c;
  --zone-5: #c0392b;
}
@media (prefers-color-scheme: dark) {
  :root {
    --zone-1: #74a9d8;
    --zone-2: #51cf66;
    --zone-3: #ffd43b;
    --zone-4: #ff922b;
    --zone-5: #ff6b6b;
  }
}

.zone-key { display: inline-flex; align-items: center; gap: 5px; margin-right: 14px;
  font-size: 12px; color: var(--muted); }
.zone-swatch { width: 14px; height: 5px; border-radius: 3px; background: var(--swatch); }
.zone-cell { border-left: 4px solid var(--swatch); padding-left: 8px; }

.block-editor input[type=number] { max-width: 110px; }
.block-editor select { max-width: 210px; }
.block-editor td { vertical-align: middle; }
.block-row-remove { color: var(--poor); background: none; border: none; cursor: pointer;
  font-size: 18px; line-height: 1; padding: 0 6px; }

.length-cell { display: flex; gap: 6px; align-items: center; }
.length-cell input { max-width: 84px; }
.length-cell select { max-width: 76px; }

/* --- the download choice ---------------------------------------------------
   A native <dialog>: it traps focus, closes on Escape and needs no library. */

.download-dialog {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 24px;
  max-width: 560px;
  width: calc(100% - 32px);
  background: var(--card);
  color: var(--text);
}
.download-dialog::backdrop { background: rgb(0 0 0 / 45%); }
.download-dialog h2 { margin: 0 0 16px; font-size: 20px; }
.download-dialog h3 { margin: 0 0 4px; font-size: 15px; }

.download-option { padding: 14px 0; border-top: 1px solid var(--line); }
.download-option:first-of-type { border-top: none; padding-top: 0; }
.download-option .btn-row { margin-top: 10px; }
.download-option.recommended h3 { display: flex; align-items: center; gap: 8px; }
