:root {
  /* Light palette (bare :root). Every colour is defined here; dark blocks only swap values. */
  --bg: #f6f7f9;
  --bg2: #ffffff;
  --card: #ffffff;
  --ink: #16181d;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #2563eb;
  --good: #16a34a;
  --warn: #d97706;
  --bad: #dc2626;
  --bar: #93b4f5;
  --bar-partial: #cbd5e1;
  --load-end: #3f83f0;
  --load-str: #d9548c;
  --violet: #7c5cff;
  --teal: #0d9488;
  --hatch-ink: rgba(0, 0, 0, 0.10);
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.10);
}
/* Dark = a lighter "dim" slate (comfortable grey, not heavy black). Follows the system theme by
   default (unless the toggle forced light) and applies whenever the toggle sets data-theme=dark. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #232832; --bg2: #2b313d; --card: #2e3542; --ink: #eceef3; --muted: #a7b0be;
    --line: #3e4655; --accent: #74a8f6; --bar: #46536a; --bar-partial: #343b47;
    --load-end: #5f99f2; --load-str: #e879a8; --violet: #9a83ff; --teal: #2dd4bf;
    --hatch-ink: rgba(255, 255, 255, 0.12);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.30), 0 6px 18px rgba(0, 0, 0, 0.22);
  }
}
:root[data-theme="dark"] {
  --bg: #232832; --bg2: #2b313d; --card: #2e3542; --ink: #eceef3; --muted: #a7b0be;
  --line: #3e4655; --accent: #74a8f6; --bar: #46536a; --bar-partial: #343b47;
  --load-end: #5f99f2; --load-str: #e879a8; --violet: #9a83ff; --teal: #2dd4bf;
  --hatch-ink: rgba(255, 255, 255, 0.12);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.30), 0 6px 18px rgba(0, 0, 0, 0.22);
}
* { box-sizing: border-box; }
body {
  margin: 0; min-height: 100vh; color: var(--ink);
  background: var(--bg);
  /* A whisper of a gradient — top slightly lighter — so the page has depth, not a flat void. */
  background-image: linear-gradient(180deg, var(--bg2) 0%, var(--bg) 360px);
  background-repeat: no-repeat;
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
#app { max-width: 960px; margin: 0 auto; padding: 24px 20px 64px; }

.topbar { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 20px; }
.topbar h1 { font-size: 22px; font-weight: 650; margin: 0; letter-spacing: -0.01em; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.freshness { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.refresh-btn { display: inline-flex; align-items: center; gap: 6px; font: inherit; font-size: 12px;
  font-weight: 600; color: var(--muted); background: var(--card); border: 1px solid var(--line);
  border-radius: 8px; padding: 5px 11px; cursor: pointer; transition: color .15s, border-color .15s; }
.refresh-btn:hover { color: var(--ink); border-color: var(--accent); }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px;
  font-size: 14px; line-height: 1; background: var(--card); border: 1px solid var(--line);
  border-radius: 8px; cursor: pointer; transition: border-color .15s, transform .1s; }
.icon-btn:hover { border-color: var(--accent); }
.icon-btn:active { transform: scale(0.94); }
.refresh-btn:disabled { opacity: .6; cursor: default; }
.refresh-btn .rb-icon { display: inline-block; font-size: 14px; line-height: 1; }
.refresh-btn.spinning .rb-icon { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.dot.good { background: var(--good); } .dot.warn { background: var(--warn); } .dot.bad { background: var(--bad); }

.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }

/* ---- Mobile: single column, everything stacks, nothing overflows sideways ---------------- */
@media (max-width: 640px) {
  #app { padding: 18px 14px 56px; }
  /* minmax(0,1fr): the single column can't exceed the viewport, so a wide child (the weekly
     chart) no longer stretches the shared column and every card with it. */
  .grid { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  /* Cards use inline `grid-column: span N`; force each to the one column and let it shrink
     below its content's natural width (min-width:0) instead of overflowing. */
  .grid > * { grid-column: 1 / -1 !important; min-width: 0; }
  /* Let the chart chain compress to fit rather than force the card wide. */
  .chart, .plot, .bars, .bar-col { min-width: 0; }

  .topbar { flex-wrap: wrap; row-gap: 8px; }
  .topbar h1 { flex: 1 0 auto; }
  .plan-meta { overflow-wrap: anywhere; }

  .metric-val, .metric-base { white-space: nowrap; }
  .sd-grid { grid-template-columns: repeat(2, 1fr); }  /* 3 detail metrics -> 2 cols */

  /* Weekly chart: tighten spacing and thin out x-labels so 13 weeks fit a phone width. */
  .bars { gap: 3px; }
  .y-ticks { width: 22px; }
  .xlabel { font-size: 9px; }
  .xlabel:nth-child(even) { visibility: hidden; }
}

.card {
  --card-accent: var(--accent);
  position: relative; background-color: var(--card); border: 1px solid var(--line);
  border-top: 3px solid var(--card-accent); border-radius: var(--radius);
  /* A faint wash of the card's accent from the top edge (behind content) — colour differentiation. */
  background-image: linear-gradient(180deg, color-mix(in srgb, var(--card-accent) 8%, transparent), transparent 72px);
  padding: 15px 18px 16px; box-shadow: var(--shadow); min-height: 90px;
  transition: transform .13s ease, box-shadow .13s ease;
}
.card:hover { transform: translateY(-2px);
  box-shadow: 0 4px 10px rgba(16, 24, 40, .08), 0 12px 28px rgba(16, 24, 40, .10); }

/* Per-panel signature colours. */
.accent-endurance { --card-accent: var(--load-end); }
.accent-strength  { --card-accent: var(--load-str); }
.accent-plan      { --card-accent: var(--violet); }
.accent-weekly    { --card-accent: var(--teal); }
.card.traffic-rail-good  { --card-accent: var(--good); }
.card.traffic-rail-warn  { --card-accent: var(--warn); }
.card.traffic-rail-bad   { --card-accent: var(--bad); }
.card.traffic-rail-muted { --card-accent: var(--muted); }

.card h2 { display: flex; align-items: center; gap: 7px; font-size: 12px; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--muted); margin: 0 0 12px; font-weight: 600; }
.card h2::before { content: ""; width: 7px; height: 7px; border-radius: 2px; background: var(--card-accent);
  flex: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--card-accent) 18%, transparent); }
.card h2 .win { text-transform: none; letter-spacing: 0; color: var(--muted); font-weight: 500; opacity: .8; }

.status-line { display: flex; align-items: center; gap: 10px; }
.status-word { font-size: 26px; font-weight: 650; letter-spacing: -0.01em; text-transform: capitalize; }
.pill { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.status-line { flex-wrap: wrap; }
.pill.good { color: var(--good); border-color: color-mix(in srgb, var(--good) 40%, transparent); }
.pill.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }
.pill.bad  { color: var(--bad);  border-color: color-mix(in srgb, var(--bad) 40%, transparent); }

/* Traffic-light readiness: a lit dot + coloured status word, plus a coloured rail on the card. */
.light { width: 14px; height: 14px; border-radius: 50%; background: var(--muted); flex: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--muted) 22%, transparent); }
.traffic-good .light { background: var(--good); box-shadow: 0 0 0 3px color-mix(in srgb, var(--good) 25%, transparent); }
.traffic-warn .light { background: var(--warn); box-shadow: 0 0 0 3px color-mix(in srgb, var(--warn) 25%, transparent); }
.traffic-bad  .light { background: var(--bad);  box-shadow: 0 0 0 3px color-mix(in srgb, var(--bad) 25%, transparent); }
.traffic-good .status-word { color: var(--good); }
.traffic-warn .status-word { color: var(--warn); }
.traffic-bad  .status-word { color: var(--bad); }

/* Wellness metric list inside the readiness card. */
.metrics { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); display: grid; gap: 9px; }
.metric { display: grid; grid-template-columns: auto 1fr auto; align-items: baseline; gap: 8px; }
.metric-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); align-self: center; }
.metric-dot.good { background: var(--good); } .metric-dot.warn { background: var(--warn); } .metric-dot.bad { background: var(--bad); }
.metric-label { font-size: 13px; color: var(--muted); }
.metric-val { font-size: 15px; font-weight: 650; letter-spacing: -0.01em; justify-self: end; }
.metric-base { grid-column: 2 / 4; font-size: 11px; color: var(--muted); opacity: .8; justify-self: end; margin-top: -4px; }

/* Endurance sport columns: Run | Ride, each with sessions / distance / time. */
.sports { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.sport-name { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted);
  font-weight: 600; margin-bottom: 10px; padding-bottom: 6px; border-bottom: 1px solid var(--line); }
.mini { margin-bottom: 11px; }
.mini:last-child { margin-bottom: 0; }
.mini-val { font-size: 21px; font-weight: 650; letter-spacing: -0.02em; }
.mini-val.na { color: var(--muted); font-weight: 500; }
.mini-val .unit { font-size: 12px; color: var(--muted); font-weight: 500; margin-left: 2px; }
.mini-lbl { display: block; font-size: 11px; color: var(--muted); margin-top: 1px; }

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 20px; }
.tile .num { font-size: 24px; font-weight: 650; letter-spacing: -0.02em; }
.tile .unit { font-size: 13px; color: var(--muted); font-weight: 500; margin-left: 3px; }
.tile .lbl { font-size: 12px; color: var(--muted); margin-top: 2px; }
.tile .num.na { color: var(--muted); font-weight: 500; }

/* Big-3 powerlifting rep breakdown inside the strength card. */
.big3 { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }
.big3-head { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; margin-bottom: 8px; }
.big3-row { display: grid; grid-template-columns: 1fr auto; align-items: baseline; gap: 10px; margin: 8px 0; }
.big3-name { font-size: 13px; }
.big3-val { text-align: right; }
.big3-reps { font-size: 17px; font-weight: 650; letter-spacing: -0.01em; }
.big3-reps.na { color: var(--muted); font-weight: 500; }
.big3-reps .unit { font-size: 11px; color: var(--muted); font-weight: 500; margin-left: 3px; }
.big3-sub { display: block; font-size: 11px; color: var(--muted); margin-top: 1px; }

.notes { margin: 12px 0 0; padding: 0; list-style: none; }
.notes li { font-size: 13px; color: var(--muted); padding-left: 14px; position: relative; margin: 4px 0; }
.notes li::before { content: "—"; position: absolute; left: 0; color: var(--line); }

.chart { display: flex; align-items: flex-start; gap: 6px; margin-top: 8px; }
.y-label { writing-mode: vertical-rl; transform: rotate(180deg); font-size: 10px; text-transform: uppercase;
  letter-spacing: .06em; color: var(--muted); height: 96px; display: flex; align-items: center; }
.y-ticks { position: relative; width: 26px; height: 96px; flex: none; }
.ytick { position: absolute; right: 2px; transform: translateY(50%); font-size: 10px; color: var(--muted);
  white-space: nowrap; line-height: 1; }
.plot { flex: 1; min-width: 0; }
.bars { position: relative; display: flex; align-items: flex-end; gap: 6px; height: 96px; }
.gridline { position: absolute; left: 0; right: 0; height: 1px; background: var(--line); opacity: .6; pointer-events: none; }
.bar-col { flex: 1; height: 96px; min-width: 0; }
.xlabels { display: flex; gap: 6px; margin-top: 6px; }
.xlabel { flex: 1; min-width: 0; text-align: center; font-size: 10px; color: var(--muted); white-space: nowrap; }
.bar-track { width: 100%; height: 96px; display: flex; align-items: flex-end; }
.bar { width: 100%; background: var(--bar); border-radius: 5px 5px 0 0; min-height: 2px; transition: height .3s ease; }
.bar.partial { background: var(--bar-partial); background-image: repeating-linear-gradient(45deg, transparent, transparent 3px, rgba(0,0,0,.06) 3px, rgba(0,0,0,.06) 6px); }
.bar.missing { background: transparent; border: 1px dashed var(--line); }

/* Stacked weekly bar: endurance vs strength time, filled from the bottom. */
.bar-stack { position: relative; width: 100%; height: 96px; display: flex; flex-direction: column-reverse;
  justify-content: flex-start; border-radius: 5px 5px 0 0; overflow: hidden; }
.wl-seg { width: 100%; }
.seg-end { background: var(--load-end); }
.seg-str { background: var(--load-str); }
.seg-none { height: 100%; background: transparent; border: 1px dashed var(--line); border-radius: 5px 5px 0 0; }
.bar-stack.partial::after { content: ""; position: absolute; inset: 0; pointer-events: none;
  background-image: repeating-linear-gradient(45deg, transparent, transparent 4px, var(--hatch-ink) 4px, var(--hatch-ink) 7px); }
.swatch.seg-end { background: var(--load-end); }
.swatch.seg-str { background: var(--load-str); }

/* Floating chart tooltip. */
.wl-tip { position: fixed; z-index: 60; pointer-events: none; max-width: 210px;
  background: var(--card); color: var(--ink); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; font-size: 12px; line-height: 1.45; box-shadow: 0 6px 20px rgba(0,0,0,.28); }
.wl-tip[hidden] { display: none; }
.wl-tip .tip-sub { color: var(--muted); }
.wl-tip .tip-k { font-weight: 600; }
.wl-tip .tip-k.end { color: var(--load-end); }
.wl-tip .tip-k.str { color: var(--load-str); }
.bar-x { font-size: 10px; color: var(--muted); white-space: nowrap; }

.coverage-row { display: flex; flex-wrap: wrap; gap: 8px; }
.cov { font-size: 12px; padding: 4px 10px; border-radius: 8px; border: 1px solid var(--line); color: var(--muted); }
.cov b { color: var(--ink); font-weight: 600; text-transform: capitalize; }
.cov.complete b { color: var(--good); } .cov.partial b { color: var(--warn); } .cov.missing b { color: var(--bad); }

.footer { margin-top: 22px; color: var(--muted); font-size: 12px; text-align: center; }
.footer .stale { color: var(--warn); }

.plan-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 8px; flex-wrap: wrap; }
.plan-title { font-size: 16px; font-weight: 600; letter-spacing: -0.01em; }
.plan-meta { font-size: 12px; color: var(--muted); }
.plan-list { list-style: none; margin: 0; padding: 0; }
.plan-item { display: grid; grid-template-columns: 96px 1fr; gap: 2px 12px; padding: 8px 10px; margin: 0 -10px;
  border-top: 1px solid var(--line); border-left: 3px solid transparent; border-radius: 6px; transition: opacity .2s; }
.plan-item:first-child { border-top: none; }
/* Past sessions recede; today is pulled forward with an accent rail and tint; future stays full. */
.plan-item.past { opacity: .48; }
.plan-item.today { border-left-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); border-top-color: transparent; }
.plan-item.today + .plan-item { border-top-color: transparent; }
.plan-when { display: flex; flex-direction: column; gap: 1px; color: var(--muted); align-self: start; }
.plan-dow { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--ink); opacity: .75; }
.plan-date { font-size: 12px; }
.plan-what { font-weight: 550; }
.plan-what.done { color: var(--good); }
.plan-what.none { font-weight: 500; font-style: italic; color: var(--muted); opacity: .8; }
.plan-item.empty { padding-top: 6px; padding-bottom: 6px; }
.plan-detail { grid-column: 2; font-size: 13px; color: var(--muted); }

/* Completed sessions with looked-up actuals: clickable, expandable. */
.plan-item.has-detail { cursor: pointer; }
.plan-item.has-detail:hover { background: color-mix(in srgb, var(--accent) 6%, transparent); }
.caret { display: inline-block; font-size: 10px; color: var(--muted); transition: transform .15s; }
.plan-item.open .caret { transform: rotate(90deg); }
.session-detail { grid-column: 1 / -1; margin-top: 8px; padding: 10px 12px; border-radius: 8px;
  background: color-mix(in srgb, var(--ink) 4%, transparent); border: 1px solid var(--line); }
.session-detail[hidden] { display: none; }
.sd-head { font-size: 11px; color: var(--muted); margin-bottom: 8px; display: flex; align-items: center; gap: 6px; }
.sd-title { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: 6px; }
.sd-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px 14px; }
.sd-cell { display: flex; flex-direction: column; gap: 1px; }
.sd-k { font-size: 11px; color: var(--muted); }
.sd-v { font-size: 15px; font-weight: 650; letter-spacing: -0.01em; }
.sd-lift { display: flex; justify-content: space-between; gap: 12px; padding: 4px 0; font-size: 13px; border-top: 1px solid var(--line); }
.sd-lift:first-of-type { border-top: none; }
.sd-lift-v { font-weight: 650; white-space: nowrap; }
.sd-empty { font-size: 13px; color: var(--muted); }

/* Intended workout structure (upcoming sessions). */
.wk { display: flex; flex-direction: column; gap: 4px; }
.wk-step { display: flex; align-items: baseline; gap: 8px; font-size: 13px; flex-wrap: wrap; }
.wk-role { font-size: 10px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted);
  min-width: 62px; }
.wk-interval { color: var(--load-str); }
.wk-dur { font-weight: 650; min-width: 44px; }
.wk-prompt { color: var(--ink); }
.wk-target { color: var(--muted); }
.wk-repeat { display: flex; gap: 8px; padding: 6px 0 6px 8px; margin: 2px 0;
  border-left: 2px solid color-mix(in srgb, var(--load-str) 55%, transparent); }
.wk-count { font-weight: 700; font-size: 13px; color: var(--load-str); min-width: 24px; }
.wk-reps { display: flex; flex-direction: column; gap: 4px; }

/* "key" priority marker. */
.key-pill { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 45%, transparent);
  text-transform: uppercase; letter-spacing: .04em; }
.today-tag { display: inline-block; margin-top: 3px; font-size: 10px; font-weight: 700; letter-spacing: .04em;
  text-transform: uppercase; color: var(--accent); }
.plan-findings { list-style: none; margin: 0 0 10px; padding: 8px 12px; border-radius: 8px;
  background: color-mix(in srgb, var(--warn) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--warn) 30%, transparent); }
.plan-findings li { font-size: 13px; color: var(--warn); }
.plan-findings li + li { margin-top: 4px; }

.legend { font-size: 11px; color: var(--muted); margin-top: 10px; display: flex; gap: 14px; flex-wrap: wrap; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.swatch { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.swatch.solid { background: var(--bar); }
.swatch.hatch { background: var(--bar-partial); background-image: repeating-linear-gradient(45deg, transparent, transparent 3px, var(--hatch-ink) 3px, var(--hatch-ink) 6px); }
.swatch.dash { background: transparent; border: 1px dashed var(--line); }

/* Skeleton */
.skeleton .sk-line { height: 14px; border-radius: 6px; background: var(--line); margin: 10px 0;
  animation: pulse 1.4s ease-in-out infinite; }
.sk-line.w30 { width: 30%; } .sk-line.w40 { width: 40%; } .sk-line.w60 { width: 60%; }
.sk-line.w70 { width: 70%; } .sk-line.w90 { width: 90%; }
@keyframes pulse { 0%,100% { opacity: .5; } 50% { opacity: 1; } }
