/* ATP dashboard — tokens per the validated reference palette.
   Light is the base; dark is a selected set of steps, not a flip. */

:root {
  color-scheme: light;
  --plane: #f9f9f7;          /* page */
  --surface: #fcfcfb;        /* cards / chart surface */
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);

  /* categorical slots (fixed order, never cycled) */
  --s1: #2a78d6;  /* Ride */
  --s2: #eb6834;  /* Run */
  --s3: #1baf7a;  /* Strength */
  --s4: #eda100;  /* Walk */
  --s5: #e87ba4;  /* Table tennis */
  --s6: #008300;  /* Yoga */
  --s7: #4a3aa7;  /* Other */

  /* sequential blue steps (ordinal season ramp, mode-invariant) */
  --b250: #86b6ef; --b300: #6da7ec; --b350: #5598e7; --b400: #3987e5;
  --b450: #2a78d6; --b500: #256abf; --b550: #1c5cab; --b600: #184f95;

  /* status — reserved, never a series */
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --delta-good: #006300;

  --accent: var(--s1);
  --wash: rgba(42, 120, 214, 0.10);
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.04);
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --plane: #0d0d0d;
    --surface: #1a1a19;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
    --s5: #d55181; --s6: #008300; --s7: #9085e9;
    --delta-good: #0ca30c;
    --accent: var(--s1);
    --wash: rgba(57, 135, 229, 0.12);
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --plane: #0d0d0d;
  --surface: #1a1a19;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --baseline: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --s5: #d55181; --s6: #008300; --s7: #9085e9;
  --delta-good: #0ca30c;
  --accent: var(--s1);
  --wash: rgba(57, 135, 229, 0.12);
  --shadow: none;
}

/* ---------- base ---------- */

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--plane);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.45;
}
.wrap { max-width: 1120px; margin: 0 auto; padding: clamp(14px, 3vw, 32px); }

a { color: var(--accent); }
code { font-size: 0.85em; background: color-mix(in srgb, var(--ink) 6%, transparent); padding: 1px 5px; border-radius: 4px; }

/* ---------- masthead ---------- */

.masthead {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; margin: 8px 0 26px;
}
.eyebrow {
  font-size: 11px; font-weight: 650; letter-spacing: 0.14em;
  text-transform: uppercase; color: var(--muted); margin-bottom: 4px;
}
h1 { font-size: clamp(24px, 4vw, 32px); font-weight: 800; letter-spacing: -0.02em; }
.stamp { font-size: 12.5px; color: var(--ink-2); margin-top: 6px; }
#themeToggle {
  flex: none; font: inherit; font-size: 12.5px; font-weight: 600;
  color: var(--ink-2); background: var(--surface);
  border: 1px solid var(--border); border-radius: 999px;
  padding: 6px 14px; cursor: pointer;
}
#themeToggle:hover { color: var(--ink); }

/* ---------- sections & cards ---------- */

.sec { margin-bottom: 22px; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: clamp(14px, 2.4vw, 22px);
  box-shadow: var(--shadow);
}
.sec-head { margin-bottom: 12px; }
.sec-head.bare { margin-bottom: 12px; }
h2 { font-size: 18px; font-weight: 750; letter-spacing: -0.01em; }
.sub { font-size: 12.5px; color: var(--ink-2); margin-top: 2px; }
h3 { font-size: 13.5px; font-weight: 650; margin-bottom: 8px; }
.unit { font-size: 11.5px; font-weight: 500; color: var(--muted); margin-left: 4px; }
.footnote { font-size: 12px; color: var(--ink-2); margin-top: 8px; }
.err { font-size: 13px; color: var(--ink-2); padding: 14px 0; }
.err strong { color: var(--ink); }

.cols-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.cols-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
@media (max-width: 860px) {
  .cols-3 { grid-template-columns: 1fr; }
  .cols-2 { grid-template-columns: 1fr; }
}

/* ---------- hero ---------- */

.hero-layout { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 14px; }
@media (max-width: 860px) { .hero-layout { grid-template-columns: 1fr; } }

.day-grid {
  display: grid; grid-template-columns: repeat(15, 1fr);
  gap: 5px; margin-top: 12px;
}
.day { aspect-ratio: 1; border-radius: 4px; min-width: 0; }
.day.done  { background: var(--s1); }
.day.today { background: var(--wash); box-shadow: inset 0 0 0 2px var(--accent); }
.day.todo  { box-shadow: inset 0 0 0 1px var(--border); }

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.tile {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 14px 16px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; justify-content: space-between; gap: 4px;
}
.tile .t-label { font-size: 11.5px; font-weight: 600; color: var(--ink-2); }
.tile .t-value { font-size: clamp(22px, 3vw, 28px); font-weight: 800; letter-spacing: -0.02em; }
.tile .t-value small { font-size: 0.55em; font-weight: 650; color: var(--ink-2); letter-spacing: 0; }
.tile .t-delta { font-size: 12px; color: var(--ink-2); }
.tile .t-delta .up-good { color: var(--delta-good); font-weight: 650; }
.tile .t-delta .down-bad { color: var(--critical); font-weight: 650; }

/* ---------- legends ---------- */

.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-bottom: 6px; }
.legend.mini { margin-bottom: 2px; }
.legend .li { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; color: var(--ink-2); }
.legend .k-line { width: 14px; height: 2px; border-radius: 1px; }
.legend .k-rect { width: 10px; height: 10px; border-radius: 3px; }
.legend .k-dot { width: 9px; height: 9px; border-radius: 50%; }

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

.fig { position: relative; }
.fig svg { display: block; width: 100%; height: auto; }
.fig .hover-overlay { cursor: crosshair; outline: none; }
.fig .hover-overlay:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.fig .bar-hit { outline: none; cursor: pointer; }
.fig .bar-hit:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.fig .lift { filter: brightness(1.09); }

svg .ax { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; font-family: inherit; }
svg .lbl { fill: var(--ink-2); font-size: 11px; font-weight: 600; font-family: inherit; }
svg .lbl-strong { fill: var(--ink); font-size: 11.5px; font-weight: 700; font-family: inherit; }
svg .note { fill: var(--muted); font-size: 11px; font-style: italic; font-family: inherit; }

/* ---------- tooltip ---------- */

#tooltip {
  position: fixed; z-index: 40; pointer-events: none;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.13);
  font-size: 12px; max-width: 260px;
  opacity: 0; transition: opacity 80ms linear;
}
#tooltip.show { opacity: 1; }
#tooltip .tt-title { font-weight: 650; color: var(--ink); margin-bottom: 4px; }
#tooltip .tt-row { display: flex; align-items: center; gap: 7px; padding: 1px 0; }
#tooltip .tt-key { width: 12px; height: 2px; border-radius: 1px; flex: none; }
#tooltip .tt-key.dot { width: 8px; height: 8px; border-radius: 50%; }
#tooltip .tt-val { font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums; }
#tooltip .tt-name { color: var(--ink-2); }

/* ---------- table views (relief rule: every chart has a table twin) ---------- */

.tv { margin-top: 10px; }
.tv details { border-top: 1px solid var(--grid); padding-top: 8px; }
.tv summary {
  cursor: pointer; font-size: 12px; font-weight: 600; color: var(--ink-2);
  list-style: none; display: inline-flex; align-items: center; gap: 6px;
}
.tv summary::before { content: "▸"; font-size: 10px; transition: transform 120ms; }
.tv details[open] summary::before { transform: rotate(90deg); }
.tv summary::-webkit-details-marker { display: none; }
.tv .t-scroll { overflow-x: auto; margin-top: 8px; }
.tv table { border-collapse: collapse; width: 100%; font-size: 12.5px; }
.tv th {
  text-align: left; font-weight: 650; color: var(--ink-2);
  border-bottom: 1px solid var(--baseline); padding: 5px 10px 5px 0; white-space: nowrap;
}
.tv td {
  border-bottom: 1px solid var(--grid); padding: 5px 10px 5px 0;
  font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--ink);
}
.tv td.dim { color: var(--ink-2); }

/* ---------- controls ---------- */

.controls { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.controls label { font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.controls select {
  font: inherit; font-size: 13px; color: var(--ink);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 10px; max-width: 100%;
}

/* ---------- this week ---------- */

.week-day { display: grid; grid-template-columns: 52px 1fr; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--grid); }
.week-day:last-child { border-bottom: none; }
.week-day.is-today .wd-name { color: var(--accent); }
.wd-name { font-size: 12px; font-weight: 700; padding-top: 2px; }
.wd-name span { display: block; font-weight: 500; color: var(--muted); font-variant-numeric: tabular-nums; }
.wd-items { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.wd-item { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; font-size: 13px; }
.wd-item .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; align-self: center; }
.wd-item .nm { font-weight: 600; }
.wd-item .at { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.wd-item .extra { color: var(--ink-2); font-size: 12.5px; }
.chip { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 650; color: var(--ink-2); margin-left: auto; }
.chip svg { flex: none; }
.rest { color: var(--muted); font-size: 12.5px; font-style: italic; }

/* ---------- season ---------- */

.scrollx { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.scrollx .fig { min-width: 860px; }
.phase-list { list-style: none; margin-top: 14px; display: grid; gap: 7px; }
.phase-list li { display: grid; grid-template-columns: 26px 1fr; gap: 10px; font-size: 13px; align-items: baseline; }
.phase-list .p-swatch {
  width: 18px; height: 12px; border-radius: 3px; align-self: center;
}
.phase-list .p-name { font-weight: 650; }
.phase-list .p-dates { color: var(--muted); font-size: 12px; margin-left: 8px; font-variant-numeric: tabular-nums; }
.phase-list .p-exit { color: var(--ink-2); font-size: 12.5px; display: block; }

/* ---------- footer ---------- */

.foot { margin: 30px 0 16px; font-size: 12px; color: var(--muted); display: grid; gap: 4px; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
