/* ============================================================
   Track Splits — mobile-first, touch-native.
   rgraf system: IBM Plex, hairlines, zero radius, mono labels.
   ============================================================ */

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
[hidden] { display: none !important; }   /* must beat display:grid/flex */

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: var(--fs-body);
  line-height: var(--lh-base);
  -webkit-font-smoothing: antialiased;
  transition: background-color var(--motion-base) var(--ease),
              color var(--motion-base) var(--ease);
}
html[data-mode="dark"] body::before {
  content: '';
  position: fixed; inset: 0;
  pointer-events: none;
  background-image: repeating-linear-gradient(
    0deg, transparent 0 2px, rgba(255,255,255,0.012) 2px 3px);
  z-index: 200;
}
::selection { background: var(--primary); color: var(--bg); }

main {
  max-width: 760px;
  margin: 0 auto;
  padding: var(--s-6) clamp(14px, 4vw, 32px) calc(var(--s-8) + env(safe-area-inset-bottom));
}

/* Mode toggle (fixed) */
.mode-toggle {
  position: fixed;
  top: 12px; right: 12px;
  z-index: 60;
  display: flex;
  background: var(--bg-elevated);
  border: 1px solid var(--rule);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 1.5px;
  font-weight: 600;
}
.mode-toggle button {
  background: transparent; border: none;
  padding: 9px 13px;
  color: var(--ink-3);
  font: inherit; letter-spacing: inherit;
  cursor: pointer;
  transition: background var(--motion-fast) var(--ease), color var(--motion-fast) var(--ease);
}
.mode-toggle button.active { background: var(--ink); color: var(--bg); }
.mode-toggle button:hover:not(.active) { color: var(--ink); }

/* Masthead */
.masthead {
  border-top: 2px solid var(--ink);
  border-bottom: 0.5px solid var(--rule);
  padding: 28px 0 24px;
  margin-bottom: var(--s-6);
}
.masthead-title {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: clamp(34px, 11vw, 56px);
  letter-spacing: -1.5px;
  line-height: 0.95;
  margin: 0 0 var(--s-4);
  color: var(--ink);
}
.lede {
  font-family: var(--font-serif);
  font-size: var(--fs-serif);
  color: var(--ink-2);
  line-height: 1.5;
  margin: 0;
  max-width: 60ch;
}

/* Card */
.card {
  background: var(--bg-elevated);
  border: 1px solid var(--rule);
  padding: var(--s-5);
  margin-bottom: var(--s-5);
  position: relative;      /* containing block + stacking context for the backdrop */
  z-index: 0;
  overflow: hidden;        /* clip the oversized parallax numeral */
}

/* Depth-parallax backdrop: a ghosted section numeral that drifts slower than
   the card. Painted above the card's own background (layer 1) but behind all
   in-flow content via z-index:-1. JS owns the transform; the CSS value here is
   the static fallback (and what shows under prefers-reduced-motion). */
.card-backdrop {
  position: absolute;
  z-index: -1;
  top: 50%;
  right: -0.06em;
  transform: translateY(-50%);
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: clamp(140px, 34vw, 280px);
  line-height: 0.8;
  letter-spacing: -0.05em;
  color: var(--ink);
  opacity: 0.045;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
  white-space: nowrap;
}
@media (prefers-reduced-motion: reduce) {
  /* JS no-ops under reduced motion; numeral stays put at the static transform. */
  .card-backdrop { transition: none; }
}
.card h2,
.explain h2 {
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: var(--fs-h2);
  letter-spacing: var(--tr-h2);
  text-transform: uppercase;
  margin: 0 0 var(--s-4);
  color: var(--ink);
  line-height: 1.2;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--s-4); flex-wrap: wrap; margin-bottom: var(--s-5);
}
.card-head h2 { margin: 0; }
.card-head-pad { padding: var(--s-5) var(--s-5) 0; }
.card-pad-h { padding: var(--s-5) var(--s-5) 0; }

/* Segmented toggle (race / pace) */
.seg {
  display: flex;
  border: 1px solid var(--rule-strong);
  font-family: var(--font-mono);
  font-size: 11px; font-weight: 600; letter-spacing: 1.5px;
}
.seg button {
  background: transparent; border: none;
  padding: 9px 16px; min-height: 38px;
  color: var(--ink-3);
  font: inherit; letter-spacing: inherit; cursor: pointer;
  transition: background var(--motion-fast) var(--ease), color var(--motion-fast) var(--ease);
}
.seg button + button { border-left: 1px solid var(--rule-strong); }
.seg button.active { background: var(--primary); color: var(--bg); }
html[data-mode="dark"] .seg button.active { color: var(--bg-sunk); }
.seg button:hover:not(.active) { color: var(--ink); }

/* Full-width variant: tab switcher for the splits panel */
.seg-tabs { width: 100%; }
.seg-tabs button { flex: 1; text-align: center; }

/* Block label above a control group */
.chip-block { margin-bottom: var(--s-5); }
.chip-block-pad { padding: var(--s-5) var(--s-5) 0; margin-bottom: var(--s-4); }
.block-label {
  display: block;
  font-family: var(--font-mono);
  font-weight: 600; font-size: var(--fs-label);
  letter-spacing: var(--tr-label); text-transform: uppercase;
  color: var(--ink-2);
  margin-bottom: var(--s-3);
}

/* Chips — slide-able row of touch targets */
.chips { display: flex; flex-wrap: wrap; gap: var(--s-2); }
.chips-scroll {
  flex-wrap: nowrap;
  overflow-x: auto;
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding-bottom: 2px;
  margin: 0 calc(-1 * var(--s-2));
  padding-left: var(--s-2); padding-right: var(--s-2);
}
.chips-scroll::-webkit-scrollbar { display: none; }
.chips button {
  flex: 0 0 auto;
  scroll-snap-align: start;
  font-family: var(--font-mono);
  font-weight: 600; font-size: 14px; letter-spacing: 0.5px;
  text-transform: uppercase;
  min-height: 46px; padding: 0 18px;
  border: 1px solid var(--rule-strong);
  background: var(--bg); color: var(--ink-2);
  cursor: pointer;
  transition: background var(--motion-fast) var(--ease),
              color var(--motion-fast) var(--ease),
              border-color var(--motion-fast) var(--ease);
}
.chips button:hover { border-color: var(--ink); color: var(--ink); }
.chips button.active {
  background: var(--ink); border-color: var(--ink); color: var(--bg);
}
.chips button.chip-custom {
  color: var(--ink-3); border-style: dashed;
}
.chips button.chip-custom.active { color: var(--bg); border-style: solid; }

/* Custom distance — the only keyboard */
.custom-wrap { margin-bottom: var(--s-5); }
.field { display: flex; flex-direction: column; gap: var(--s-2); }
.field .label {
  font-family: var(--font-mono); font-weight: 600; font-size: var(--fs-label);
  letter-spacing: var(--tr-label); text-transform: uppercase; color: var(--ink-2);
}
input[type="text"] {
  font-family: var(--font-mono); font-size: 18px; font-weight: 500;
  background: var(--bg); color: var(--ink);
  border: 1px solid var(--rule-strong); border-radius: 0;
  padding: 12px; width: 100%;
  -webkit-appearance: none; appearance: none;
  transition: border-color var(--motion-fast) var(--ease);
}
input[type="text"]:focus { outline: none; border: 2px solid var(--primary); padding: 11px; }
input.num { font-variant-numeric: tabular-nums; }

/* ── THE DIAL ─────────────────────────────────────────────── */
.dial-wrap {
  position: relative;
  width: clamp(230px, 76vw, 320px);
  aspect-ratio: 1 / 1;
  margin: var(--s-4) auto var(--s-3);
  touch-action: none;
}
.dial {
  width: 100%; height: 100%;
  touch-action: none;
  cursor: grab;
  display: block;
}
.dial:active { cursor: grabbing; }
.dial:focus { outline: none; }
.dial:focus-visible .dial-track { stroke: var(--primary); }
.dial-track { fill: none; stroke: var(--rule); stroke-width: 1.5; }
.dial-tick { stroke: var(--rule-strong); stroke-width: 1.5; }
.dial-tick.major { stroke: var(--ink-3); stroke-width: 2.5; }
.dial-arc {
  fill: none; stroke: var(--primary); stroke-width: 5; stroke-linecap: round;
}
.dial-handle {
  fill: var(--primary); stroke: var(--bg); stroke-width: 3;
  transition: none;
}
.dial-readout {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  pointer-events: none; text-align: center;
}
.dial-time {
  font-family: var(--font-mono); font-variant-numeric: tabular-nums;
  font-weight: 700; font-size: clamp(38px, 14vw, 54px);
  letter-spacing: -1.5px; line-height: 1; color: var(--ink);
}
html[data-mode="dark"] .dial-time { color: var(--primary); }
.dial-sub {
  font-family: var(--font-mono); font-size: var(--fs-label);
  letter-spacing: var(--tr-label); text-transform: uppercase;
  color: var(--ink-2); font-weight: 600; margin-top: var(--s-2);
}
.dial-hint {
  font-family: var(--font-sans); font-size: var(--fs-caption);
  color: var(--ink-3); text-align: center; margin: 0 auto var(--s-5);
  max-width: 36ch;
}

/* ── Stepper (reps, effort) ───────────────────────────────── */
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-4); }
.stepper {
  display: flex; align-items: stretch;
  border: 1px solid var(--rule-strong); background: var(--bg);
  height: 52px; touch-action: manipulation;
}
.stepper button {
  width: 52px; flex: 0 0 52px;
  background: transparent; border: none;
  font-family: var(--font-mono); font-size: 26px; font-weight: 500;
  color: var(--ink); cursor: pointer;
  transition: background var(--motion-fast) var(--ease), color var(--motion-fast) var(--ease);
}
.stepper button:first-child { border-right: 1px solid var(--rule); }
.stepper button:last-child  { border-left: 1px solid var(--rule); }
.stepper button:hover, .stepper button:active { background: var(--primary); color: var(--bg); }
html[data-mode="dark"] .stepper button:hover,
html[data-mode="dark"] .stepper button:active { color: var(--bg-sunk); }
.stepper-val {
  flex: 1 1 auto; display: flex; align-items: center; justify-content: center;
  text-align: center;
  font-family: var(--font-mono); font-size: 13px; font-weight: 500;
  letter-spacing: 0.3px; color: var(--ink-2);
  padding: 0 var(--s-2); font-variant-numeric: tabular-nums;
}
.stepper-val-lg { font-size: 22px; font-weight: 700; color: var(--ink); }
.stepper-val.is-fast { color: var(--series-2); }
.stepper-val.is-slow { color: var(--primary); }
html[data-mode="dark"] .stepper-val.is-slow { color: var(--primary-bright); }

/* ── Stats grids ──────────────────────────────────────────── */
.stats {
  display: grid; gap: 0; border: 1px solid var(--rule);
  grid-template-columns: repeat(2, 1fr);
  margin-top: var(--s-5);
}
.pace-strip .stat:last-child { grid-column: 1 / -1; }
.wk-stats { grid-template-columns: 1fr; }
.stat {
  padding: var(--s-4) var(--s-5);
  border-right: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  background: var(--bg);
}
.stat-num {
  font-family: var(--font-mono); font-variant-numeric: tabular-nums;
  font-weight: 700; font-size: 24px; letter-spacing: -0.5px;
  color: var(--ink); line-height: 1.1; margin-bottom: var(--s-2);
}
.stat-lbl {
  font-family: var(--font-mono); font-size: var(--fs-label);
  letter-spacing: var(--tr-label); text-transform: uppercase;
  color: var(--ink-2); font-weight: 600;
}
.stat-lbl .unit {
  display: block; color: var(--ink-3); font-weight: 400;
  letter-spacing: 1.5px; margin-top: 2px;
}
/* tidy the grid edges */
.pace-strip .stat:nth-child(2n) { border-right: none; }
.pace-strip .stat:nth-last-child(1) { border-bottom: none; border-right: none; }
.pace-strip .stat:nth-last-child(2) { border-bottom: none; }
.wk-stats .stat { border-right: none; }
.wk-stats .stat:last-child { border-bottom: none; }

/* ── Hero rep split ───────────────────────────────────────── */
.hero {
  margin-top: var(--s-5); padding: var(--s-5);
  border: 1px solid var(--rule-strong); background: var(--primary-bg);
  display: flex; flex-direction: column; align-items: center; text-align: center;
}
.hero-num {
  font-family: var(--font-mono); font-variant-numeric: tabular-nums;
  font-weight: 700; font-size: clamp(54px, 18vw, 82px);
  letter-spacing: -2px; line-height: 1; color: var(--ink);
}
html[data-mode="dark"] .hero-num { color: var(--primary); }
.hero-lbl {
  font-family: var(--font-mono); font-size: var(--fs-label);
  letter-spacing: var(--tr-label); text-transform: uppercase;
  color: var(--ink-2); font-weight: 600; margin-top: var(--s-3);
}

/* ── Switch (whole seconds) ───────────────────────────────── */
.switch {
  display: inline-flex; align-items: center; gap: var(--s-2); cursor: pointer;
  user-select: none;
}
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-track {
  width: 44px; height: 26px; flex: 0 0 44px;
  border: 1px solid var(--rule-strong); background: var(--bg);
  display: flex; align-items: center; padding: 2px;
  transition: background var(--motion-fast) var(--ease), border-color var(--motion-fast) var(--ease);
}
.switch-thumb {
  width: 18px; height: 18px; background: var(--ink-3);
  transition: transform var(--motion-fast) var(--ease), background var(--motion-fast) var(--ease);
}
.switch input:checked + .switch-track { border-color: var(--primary); background: var(--primary-bg); }
.switch input:checked + .switch-track .switch-thumb { transform: translateX(18px); background: var(--primary); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--primary); outline-offset: 2px; }
.switch-lbl {
  font-family: var(--font-mono); font-size: 11px; font-weight: 600;
  letter-spacing: 1px; text-transform: uppercase; color: var(--ink-2);
}

/* Error */
.error {
  margin: var(--s-4) 0 0; padding: var(--s-3);
  border: 1px solid var(--alarm); border-left: 3px solid var(--alarm);
  font-family: var(--font-mono); font-size: 12px; color: var(--alarm); background: transparent;
}

/* ── Tables ───────────────────────────────────────────────── */
.table-card { padding: 0; }
.table-card .table-caption { padding: var(--s-3) var(--s-5) var(--s-5); margin: 0; }
.table-wrap { overflow-x: auto; }
.equiv-table { width: 100%; border-collapse: collapse; border-top: 0.5px solid var(--rule); }
.equiv-table th, .equiv-table td {
  padding: 12px var(--s-5); text-align: right; border-bottom: 0.5px solid var(--rule);
}
.equiv-table th {
  font-family: var(--font-mono); font-weight: 600; font-size: var(--fs-label);
  letter-spacing: var(--tr-label); text-transform: uppercase; color: var(--ink-2);
  background: var(--bg-sunk); border-bottom: 1px solid var(--rule-strong);
}
.equiv-table th:first-child, .equiv-table td:first-child { text-align: left; }
.equiv-table td {
  font-family: var(--font-mono); font-variant-numeric: tabular-nums;
  font-size: 15px; color: var(--ink);
}
.equiv-table td:first-child { font-weight: 500; }
.equiv-table .col-avg, .equiv-table td.col-avg {
  border-left: 0.5px solid var(--rule); color: var(--primary); font-weight: 600;
}
html[data-mode="dark"] .equiv-table td.col-avg { color: var(--primary); }
.equiv-table tr:hover td { background: var(--bg-elevated); }
.equiv-table tr.mark-row td { background: var(--primary-bg); font-weight: 600; color: var(--ink); }
.equiv-table tr.mark-row td:first-child::before { content: '▸ '; color: var(--primary); }
.equiv-table td.seg-cell { color: var(--ink-3); }

/* ── Explanations ─────────────────────────────────────────── */
.explain { border-top: 0.5px solid var(--rule); padding-top: var(--s-6); margin-bottom: var(--s-6); }
.explain h2 { margin: 0 0 var(--s-5); }
.methods { display: grid; gap: var(--s-5); margin: 0; }
.methods dt {
  font-family: var(--font-sans); font-weight: 600; font-size: var(--fs-h3);
  color: var(--ink); display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--s-3);
}
.methods .method-tag {
  font-family: var(--font-mono); font-weight: 600; font-size: var(--fs-label);
  letter-spacing: var(--tr-label); text-transform: uppercase;
  padding: 4px 8px; border: 1px solid var(--rule);
  color: var(--primary); background: var(--primary-bg);
}
.methods dd {
  font-family: var(--font-serif); font-size: var(--fs-serif); line-height: 1.55;
  color: var(--ink-2); margin: var(--s-2) 0 0; max-width: 70ch;
}
.methods dd code {
  font-family: var(--font-mono); font-size: 13px;
  background: var(--bg-elevated); border: 0.5px solid var(--rule);
  padding: 1px 6px; color: var(--ink);
}

/* Footer */
.site-footer { border-top: 0.5px solid var(--rule); padding-top: var(--s-5); }
.caption { font-family: var(--font-sans); font-size: var(--fs-caption); color: var(--ink-3); margin: var(--s-3) 0 0; }
.site-footer .caption { margin: 0; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* ── Wider screens: more columns, dial beside chips ───────── */
@media (min-width: 620px) {
  main { padding-top: var(--s-7); }
  .pace-strip { grid-template-columns: repeat(5, 1fr); margin-top: var(--s-6); }
  .pace-strip .stat,
  .pace-strip .stat:nth-child(2n) { border-right: 1px solid var(--rule); border-bottom: none; }
  .pace-strip .stat:last-child { grid-column: auto; border-right: none; }
  .wk-stats { grid-template-columns: repeat(3, 1fr); }
  .wk-stats .stat { border-right: 1px solid var(--rule); border-bottom: none; }
  .wk-stats .stat:last-child { border-right: none; }
  .card { padding: var(--s-6); }
}
