/*
 * viewer.css — presentation for the read-only training plan viewer.
 *
 * Palette and type scale follow the dashboard index (Outfit / JetBrains Mono,
 * warm paper background) so the two surfaces read as one site.
 *
 * Phases are coloured by their *index* in the plan's `phases` array, never by
 * name, so this file contains no plan values.
 */

:root {
  --bg: #fbfaf8;
  --surface: #ffffff;
  --surface-sunk: #f5f2ed;
  --border: #e6e2db;
  --border-strong: #d4cec4;
  --ink: #1a1917;
  --ink-soft: #57534e;
  --ink-faint: #8a8378;
  --accent: #b4522a;
  --good: #4a7c59;
  --warn: #a8761f;
  --bad: #a63d40;
  --shadow: 0 1px 2px rgba(26, 25, 23, 0.04), 0 8px 24px -12px rgba(26, 25, 23, 0.14);

  /* Phase colour scale — assigned by array position, not by phase name. */
  --phase-0: #4a7c59;
  --phase-1: #2f6f8f;
  --phase-2: #b4522a;
  --phase-3: #a63d40;
  --phase-4: #6b5b95;
  --phase-5: #7a6a55;
  --phase: var(--ink-faint);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14130f;
    --surface: #1d1b17;
    --surface-sunk: #191713;
    --border: #2e2b25;
    --border-strong: #423e36;
    --ink: #f2efe9;
    --ink-soft: #b5aea2;
    --ink-faint: #837c70;
    --accent: #e07a4d;
    --good: #7bb08c;
    --warn: #d4a444;
    --bad: #d97377;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px -12px rgba(0, 0, 0, 0.6);

    --phase-0: #7bb08c;
    --phase-1: #6aa9c9;
    --phase-2: #e07a4d;
    --phase-3: #d97377;
    --phase-4: #a294c9;
    --phase-5: #b3a086;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Outfit', ui-sans-serif, system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  line-height: 1.55;
}

/* ── Load states ──────────────────────────────────────────────────────── */

.status {
  max-width: 44rem;
  margin: clamp(3rem, 12vw, 7rem) auto;
  padding: 0 1.25rem;
  color: var(--ink-faint);
  font-size: 0.95rem;
}

.status-error {
  color: var(--ink);
  border-left: 3px solid var(--bad);
  padding: 0.25rem 0 0.25rem 1.25rem;
}

.status-error h1 {
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 0 0 0.75rem;
}

.status-error p {
  margin: 0 0 0.75rem;
  color: var(--ink-soft);
}

.status-error code {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 0.85em;
  color: var(--ink);
  background: var(--surface-sunk);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0.1em 0.4em;
  word-break: break-all;
}

body:not([data-state='loading']) #loading,
body:not([data-state='ready']) .page {
  display: none;
}

/* ── Page frame ───────────────────────────────────────────────────────── */

.page {
  max-width: 60rem;
  margin: 0 auto;
  padding: clamp(2.5rem, 8vw, 5rem) clamp(1.1rem, 5vw, 2.5rem) 4rem;
}

.masthead {
  margin-bottom: 2rem;
}

.eyebrow {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin: 0 0 1.1rem;
}

.masthead h1 {
  font-size: clamp(2.1rem, 7vw, 3.5rem);
  line-height: 1.05;
  letter-spacing: -0.035em;
  font-weight: 600;
  margin: 0 0 1rem;
}

.masthead .lede {
  font-size: clamp(1rem, 2.4vw, 1.1rem);
  color: var(--ink-soft);
  font-weight: 300;
  max-width: 38rem;
  margin: 0;
}

/* ── Sticky section nav ───────────────────────────────────────────────── */

.sectionnav {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
  margin: 0 0 2.5rem;
  padding: 0.6rem 0;
  background: color-mix(in srgb, var(--bg) 97%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.sectionnav a {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--ink-soft);
  text-decoration: none;
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  border: 1px solid transparent;
}

.sectionnav a:hover,
.sectionnav a:focus-visible {
  color: var(--ink);
  background: var(--surface);
  border-color: var(--border);
}

.sectionnav a[aria-current='true'] {
  color: var(--accent);
  background: var(--surface);
  border-color: var(--border-strong);
}

/* ── Sections ─────────────────────────────────────────────────────────── */

section {
  margin-bottom: clamp(3rem, 8vw, 4.5rem);
  scroll-margin-top: 4rem;
}

.section-heading {
  font-size: 0.75rem;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-faint);
  font-weight: 500;
  margin: 0 0 1.25rem;
  padding-bottom: 0.6rem;
  border-bottom: 1px solid var(--border);
}

.block {
  margin-bottom: 1.75rem;
}

.block > h3 {
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: -0.015em;
  margin: 0 0 0.85rem;
}

.block > h4 {
  font-size: 0.95rem;
  font-weight: 600;
  margin: 1.25rem 0 0.6rem;
}

.note {
  color: var(--ink-soft);
  font-size: 0.92rem;
  font-weight: 300;
  margin: 0.5rem 0 0;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.15rem 1.25rem;
  box-shadow: var(--shadow);
}

/* Column flow rather than a grid: these cards vary wildly in height (four
   label/value rows vs. several paragraphs of coach prose), and grid rows would
   leave a large void beneath every short card. Columns pack them instead. */
.cards {
  columns: 2 18rem;
  column-gap: 0.85rem;
}

.cards > .card {
  break-inside: avoid;
  margin-bottom: 0.85rem;
}

/* ── Stat tiles ───────────────────────────────────────────────────────── */

.stats {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 8.5rem), 1fr));
  margin: 0 0 1.75rem;
  padding: 0;
  list-style: none;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.8rem 0.9rem;
}

.stat dt {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 0.63rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin: 0 0 0.35rem;
}

.stat dd {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.stat .stat-sub {
  display: block;
  font-size: 0.78rem;
  font-weight: 300;
  color: var(--ink-soft);
  letter-spacing: 0;
  margin-top: 0.15rem;
}

/* ── Definition rows (label / value prose) ────────────────────────────── */

.rows {
  margin: 0;
  display: grid;
  gap: 0.7rem;
}

/* Rows stack by default and only go two-column where their container is wide
   enough. A fixed label column inside a narrow card wraps prose values to one
   word per line, so this is measured against the card, not the viewport. */
.rows > div {
  display: grid;
  gap: 0.15rem 1rem;
  align-items: baseline;
}

.block,
.card,
.phase {
  container-type: inline-size;
}

@container (min-width: 26rem) {
  .rows > div {
    grid-template-columns: minmax(7.5rem, 11rem) 1fr;
  }
}

.rows dt {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-faint);
  padding-top: 0.2em;
}

.rows dd {
  margin: 0;
  font-size: 0.94rem;
  color: var(--ink);
  font-weight: 300;
  min-width: 0;
}

/* ── Lists ────────────────────────────────────────────────────────────── */

.bullets {
  margin: 0;
  padding-left: 1.1rem;
  color: var(--ink-soft);
  font-size: 0.92rem;
  font-weight: 300;
}

.bullets li {
  margin-bottom: 0.4rem;
}

.bullets li::marker {
  color: var(--ink-faint);
}

/* ── Tables ───────────────────────────────────────────────────────────── */

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th,
td {
  text-align: left;
  padding: 0.6rem 0.9rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

thead th {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 0.63rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-faint);
  font-weight: 500;
  white-space: nowrap;
}

tbody tr:last-child td {
  border-bottom: none;
}

td.num {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  white-space: nowrap;
}

/* ── Phase timeline ───────────────────────────────────────────────────── */

[data-phase='0'] { --phase: var(--phase-0); }
[data-phase='1'] { --phase: var(--phase-1); }
[data-phase='2'] { --phase: var(--phase-2); }
[data-phase='3'] { --phase: var(--phase-3); }
[data-phase='4'] { --phase: var(--phase-4); }
[data-phase='5'] { --phase: var(--phase-5); }

.phases {
  display: grid;
  gap: 0.85rem;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 15rem), 1fr));
  list-style: none;
  margin: 0 0 2.5rem;
  padding: 0;
}

.phase {
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 3px solid var(--phase);
  border-radius: 10px;
  padding: 0.95rem 1rem 1.1rem;
}

.phase h4 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.015em;
  color: var(--phase);
}

.phase .phase-span {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin: 0.3rem 0 0.7rem;
}

.phase .phase-focus {
  margin: 0 0 0.8rem;
  font-size: 0.92rem;
  color: var(--ink-soft);
  font-weight: 300;
}

.phase h5 {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 0.62rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-faint);
  font-weight: 500;
  margin: 0.9rem 0 0.35rem;
}

.phase .bullets {
  font-size: 0.85rem;
}

/* ── Week accordions ──────────────────────────────────────────────────── */

.weeks {
  display: grid;
  gap: 0.6rem;
}

.week {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--phase);
  border-radius: 10px;
}

.week[open] {
  box-shadow: var(--shadow);
}

.week-head {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  padding: 0.85rem 1rem;
  cursor: pointer;
  list-style: none;
}

.week-head::-webkit-details-marker {
  display: none;
}

.week-head:hover {
  background: var(--surface-sunk);
  border-radius: 7px;
}

.week-head:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  border-radius: 7px;
}

.week-no {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--phase);
  flex-shrink: 0;
  min-width: 2.4rem;
}

.week-dates {
  font-weight: 500;
  font-size: 0.94rem;
  flex-shrink: 0;
}

.week-focus {
  color: var(--ink-soft);
  font-size: 0.88rem;
  font-weight: 300;
  flex: 1 1 12rem;
  min-width: 0;
}

.week-tags {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
  margin-left: auto;
}

.pill {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 0.62rem;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--ink-faint);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  padding: 0.15rem 0.5rem;
  white-space: nowrap;
}

.pill-phase {
  color: var(--phase);
  border-color: color-mix(in srgb, var(--phase) 45%, transparent);
}

.pill-recovery {
  color: var(--good);
  border-color: color-mix(in srgb, var(--good) 45%, transparent);
}

.pill-today {
  color: var(--accent);
  border-color: var(--accent);
}

.week-progress {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 0.7rem;
  color: var(--ink-faint);
  white-space: nowrap;
}

.bar {
  width: 3rem;
  height: 4px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}

.bar span {
  display: block;
  height: 100%;
  background: var(--good);
}

.week-body {
  padding: 0.25rem 1rem 1.1rem;
  border-top: 1px solid var(--border);
}

.coach-notes {
  background: var(--surface-sunk);
  border-radius: 8px;
  padding: 0.75rem 0.9rem;
  margin: 0.9rem 0 0.25rem;
  font-size: 0.9rem;
  font-weight: 300;
  color: var(--ink-soft);
  white-space: pre-line;
}

.coach-notes strong {
  display: block;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 0.62rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-faint);
  font-weight: 500;
  margin-bottom: 0.3rem;
}

/* ── Days and workouts ────────────────────────────────────────────────── */

.days {
  list-style: none;
  margin: 1rem 0 0;
  padding: 0;
}

.day {
  display: grid;
  gap: 0.15rem 1rem;
  grid-template-columns: 7.5rem 1fr;
  padding: 0.8rem 0;
  border-top: 1px dashed var(--border);
}

.day:first-child {
  border-top: none;
}

@media (max-width: 34rem) {
  .day {
    grid-template-columns: 1fr;
  }
}

.day-label {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 0.72rem;
  color: var(--ink-faint);
  padding-top: 0.15rem;
}

.day-label .day-name {
  display: block;
  color: var(--ink-soft);
  font-size: 0.75rem;
}

.day.is-today .day-label .day-name {
  color: var(--accent);
}

.workouts {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.7rem;
  min-width: 0;
}

.workout-head {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.workout-name {
  font-weight: 500;
  font-size: 0.95rem;
}

.workout.is-rest .workout-name {
  color: var(--ink-faint);
  font-weight: 400;
}

.done {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--good);
  white-space: nowrap;
}

.workout-meta {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  margin: 0.35rem 0 0;
  padding: 0;
  list-style: none;
}

.workout-meta li {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 0.68rem;
  color: var(--ink-soft);
  background: var(--surface-sunk);
  border-radius: 5px;
  padding: 0.1rem 0.45rem;
  white-space: nowrap;
}

.workout-desc {
  margin: 0.4rem 0 0;
  font-size: 0.9rem;
  font-weight: 300;
  color: var(--ink-soft);
}

/* `humanReadable` carries newlines; they render as line breaks here rather
   than by injecting markup into the string. */
.workout-guidance {
  margin: 0.45rem 0 0;
  padding: 0.6rem 0.8rem;
  border-left: 2px solid var(--border-strong);
  background: var(--surface-sunk);
  border-radius: 0 7px 7px 0;
  font-size: 0.88rem;
  font-weight: 300;
  color: var(--ink-soft);
  white-space: pre-line;
}

.workout.is-done .workout-guidance {
  border-left-color: var(--good);
}

/* ── Zones ────────────────────────────────────────────────────────────── */

.zone-swatch {
  display: inline-block;
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 3px;
  margin-right: 0.5rem;
  background: var(--zone, var(--ink-faint));
  vertical-align: baseline;
}

tr[data-zone='0'] { --zone: #8a8378; }
tr[data-zone='1'] { --zone: #4a7c59; }
tr[data-zone='2'] { --zone: #2f6f8f; }
tr[data-zone='3'] { --zone: #a8761f; }
tr[data-zone='4'] { --zone: #b4522a; }
tr[data-zone='5'] { --zone: #a63d40; }

/* ── Race day ─────────────────────────────────────────────────────────── */

.checklist {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.4rem;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 16rem), 1fr));
}

.checklist li {
  font-size: 0.9rem;
  font-weight: 300;
  color: var(--ink-soft);
  padding-left: 1.2rem;
  position: relative;
}

.checklist li::before {
  content: '□';
  position: absolute;
  left: 0;
  color: var(--ink-faint);
}

/* ── Footer ───────────────────────────────────────────────────────────── */

.page-foot {
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
  font-weight: 300;
  color: var(--ink-faint);
}

.page-foot p {
  margin: 0;
  max-width: 34rem;
}

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