/* ==========================================================================
   Athletics Calculators — shared design system
   Apple-inspired, mobile-first, feels like a native app in a browser.
   ========================================================================== */

:root {
  /* Color */
  --bg: #F5F5F7;
  --surface: #FFFFFF;
  --surface-sunken: #ECECEE;
  --text-primary: #1D1D1F;
  --text-secondary: #6E6E73;
  --text-tertiary: #98989D;
  --border: rgba(0, 0, 0, 0.08);
  --border-strong: rgba(0, 0, 0, 0.14);

  --accent: #FF5A1F;         /* track orange */
  --accent-press: #E64A11;
  --accent-tint: #FFEFE6;
  --accent-tint-strong: #FFDAC4;

  --danger: #E0301E;
  --danger-tint: #FDECEA;

  /* Benchmark scale — every gauge that rates a result against a population
     uses this same low->high direction and color pair: --scale-low (an
     untrained "average person" baseline) on the left/0% end, --scale-high
     (Olympic-level) on the right/100% end. Kept separate from --accent so
     "this is a benchmark" reads as its own visual language site-wide. */
  --scale-low: #8E93A6;
  --scale-high: #D8A400;

  /* Elevation */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.12);

  /* Radius */
  --radius-lg: 22px;
  --radius-md: 16px;
  --radius-sm: 12px;
  --radius-pill: 999px;

  /* Type */
  --font-display: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI",
    Roboto, Helvetica, Arial, sans-serif;
  --font-text: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
    Roboto, Helvetica, Arial, sans-serif;
  --font-mono: "SF Mono", SFMono-Regular, ui-monospace, Menlo, Consolas, monospace;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --surface: #17171A;
    --surface-sunken: #0D0D0F;
    --text-primary: #F5F5F7;
    --text-secondary: #98989D;
    --text-tertiary: #6E6E73;
    --border: rgba(255, 255, 255, 0.09);
    --border-strong: rgba(255, 255, 255, 0.16);
    --accent-tint: rgba(255, 90, 31, 0.16);
    --accent-tint-strong: rgba(255, 90, 31, 0.28);
    --danger-tint: rgba(224, 48, 30, 0.18);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.45);
    --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.55);
    color-scheme: dark;
  }
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text-primary);
  font-family: var(--font-text);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

.app-shell {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* Top bar ------------------------------------------------------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 14px 16px 10px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
}

.topbar-back {
  position: absolute;
  left: 8px;
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 6px 10px 6px 4px;
  color: var(--accent);
  font-size: 15px;
  font-weight: 590;
  text-decoration: none;
  border-radius: var(--radius-pill);
}

.topbar-back:active {
  background: var(--accent-tint);
}

.topbar-title {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

/* Spectrum strip — the site's signature: distance mapped to a warm-to-cool
   hue, short explosive sprints through to longer speed-endurance runs. ---- */

.spectrum-strip {
  height: 3px;
  margin: 0 0 4px;
}

/* Layout ---------------------------------------------------------------- */

main {
  flex: 1;
  padding: 4px 16px 40px;
  position: relative;
}

.hero {
  position: relative;
  padding-top: 6px;
}

.hero::before {
  content: "";
  position: absolute;
  top: -80px;
  left: -60px;
  width: 280px;
  height: 280px;
  background: radial-gradient(circle, color-mix(in srgb, var(--accent) 38%, transparent), transparent 72%);
  filter: blur(46px);
  z-index: -1;
  pointer-events: none;
}

.page-title {
  font-family: var(--font-display);
  font-size: 34px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 10px 2px 2px;
}

.page-subtitle {
  font-size: 15px;
  color: var(--text-secondary);
  margin: 0 2px 22px;
  line-height: 1.4;
  max-width: 34ch;
}

/* Card ------------------------------------------------------------------ */

.card {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0) 40%),
    var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm), inset 0 1px 0 rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  padding: 18px;
  margin-bottom: 16px;
}

.card-label {
  font-size: 13px;
  font-weight: 590;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-tertiary);
  margin: 0 0 12px 2px;
}

/* Segmented / pill selector ---------------------------------------------- */

.pill-row-wrap {
  position: relative;
}

.pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pill {
  --pill-color: var(--accent);
  padding: 9px 16px;
  border-radius: var(--radius-pill);
  border: 1.5px solid color-mix(in srgb, var(--pill-color) 45%, var(--border-strong));
  background: color-mix(in srgb, var(--pill-color) 12%, var(--surface-sunken));
  color: var(--text-primary);
  font-family: var(--font-text);
  font-size: 15px;
  font-weight: 560;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease, color 0.15s ease,
    border-color 0.15s ease, box-shadow 0.15s ease;
  -webkit-appearance: none;
  appearance: none;
}

.pill:active {
  transform: scale(0.96);
}

.pill[aria-pressed="true"] {
  background: var(--pill-color);
  border-color: var(--pill-color);
  color: #0B0B0C;
  box-shadow: 0 4px 14px color-mix(in srgb, var(--pill-color) 55%, transparent);
}

/* Time input -------------------------------------------------------------- */

.time-panel {
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px 16px 14px;
  margin-top: 16px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.time-panel:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-tint);
}

.time-input-row {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 8px;
}

.time-input {
  width: 100%;
  max-width: 220px;
  border: none;
  background: transparent;
  text-align: center;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 52px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text-primary);
  outline: none;
  caret-color: var(--accent);
}

.time-input::placeholder {
  color: var(--text-tertiary);
  opacity: 0.5;
  font-weight: 500;
}

.time-unit {
  font-size: 16px;
  font-weight: 500;
  color: var(--text-secondary);
}

/* Compact two-option toggle, used for the weight unit (kg/lb) — same idea
   as a pill but sized for sitting inline where a unit label normally goes. */

.unit-toggle {
  display: inline-flex;
  border-radius: var(--radius-pill);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  overflow: hidden;
}

.unit-toggle button {
  border: none;
  background: transparent;
  padding: 6px 13px;
  font-family: var(--font-text);
  font-size: 13px;
  font-weight: 650;
  color: var(--text-secondary);
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  transition: background 0.15s ease, color 0.15s ease;
}

.unit-toggle button[aria-pressed="true"] {
  background: var(--accent);
  color: #FFFFFF;
}

/* Jump trajectory arc — a genuine (if simplified) visualization of the
   flight path implied by the entered hang time, not just decoration. ------ */

.trajectory-svg {
  width: 100%;
  height: auto;
  display: block;
  margin-top: 2px;
}

.trajectory-ground {
  stroke: var(--border-strong);
  stroke-width: 2;
}

.trajectory-tick {
  stroke: var(--border-strong);
  stroke-width: 2;
}

.trajectory-fill {
  fill: color-mix(in srgb, #7C5CFF 16%, transparent);
  stroke: none;
}

.trajectory-arc {
  fill: none;
  stroke: #7C5CFF;
  stroke-width: 3;
  stroke-linecap: round;
}

.trajectory-apex-dot {
  fill: #7C5CFF;
  stroke: var(--surface);
  stroke-width: 3;
}

.field-hint {
  text-align: center;
  font-size: 13px;
  color: var(--text-tertiary);
  margin-top: 8px;
  min-height: 18px;
}

.field-hint.is-error {
  color: var(--danger);
  font-weight: 560;
}

/* Buttons ------------------------------------------------------------------ */
/* Kept for reuse by other calculators; this page is fully live/reactive
   and doesn't use a submit button. */

.btn-primary {
  display: block;
  width: 100%;
  padding: 16px;
  border: none;
  border-radius: var(--radius-md);
  background: var(--accent);
  color: #FFFFFF;
  font-family: var(--font-text);
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
  cursor: pointer;
  margin-top: 16px;
  transition: transform 0.12s ease, background 0.15s ease, opacity 0.15s ease;
  -webkit-appearance: none;
  appearance: none;
}

.btn-primary:active {
  transform: scale(0.98);
  background: var(--accent-press);
}

.btn-primary:disabled {
  opacity: 0.35;
  cursor: default;
}

.btn-primary:disabled:active {
  transform: none;
}

/* Live indicator — a quiet pulse next to a label to say "this updates as
   you type", instead of the results needing a button press. --------------- */

.live-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-left: 7px;
  border-radius: 50%;
  background: #34C759;
  animation: livePulse 1.8s ease-in-out infinite;
  vertical-align: middle;
}

@keyframes livePulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.35; transform: scale(0.8); }
}

/* Gauge (equivalent 100m pace) ---------------------------------------------- */

.gauge {
  margin-top: 4px;
  transition: opacity 0.25s ease;
}

.gauge.is-stale {
  opacity: 0.45;
}

.gauge-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 10px;
}

.gauge-value {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 22px;
  font-weight: 600;
  transition: color 0.2s ease;
}

.gauge-value.is-idle {
  color: var(--text-tertiary);
  font-weight: 500;
}

.gauge-track {
  position: relative;
  height: 6px;
  border-radius: var(--radius-pill);
  background: linear-gradient(90deg, var(--scale-low), var(--scale-high));
  opacity: 0.9;
  overflow: visible;
}

/* Shown in place of a gauge when a result can't be placed on the
   benchmark scale (e.g. RSImod for a CMJ) — an explicit, readable state
   instead of the gauge just vanishing with no explanation. */
.gauge-unavailable {
  margin: 0;
  padding: 10px 4px;
  text-align: center;
  font-size: 13px;
  line-height: 1.4;
  color: var(--text-tertiary);
}

.gauge-dot {
  position: absolute;
  top: 50%;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--text-primary);
  border: 3px solid var(--surface);
  box-shadow: var(--shadow-md);
  transform: translate(-50%, -50%);
  transition: left 0.55s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.25s ease;
}

.gauge-dot.is-idle {
  opacity: 0.4;
}

.gauge-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-tertiary);
}

.gauge-sub {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-top: 2px;
}

.gauge-sub.is-idle {
  color: var(--text-tertiary);
}

.tier-badge {
  display: inline-block;
  margin-left: 10px;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  font-size: 13px;
  font-weight: 650;
  color: #FFFFFF;
  background: var(--tier-color, var(--text-tertiary));
  vertical-align: middle;
}

.tier-badge:empty {
  display: none;
}

.card.is-stale {
  opacity: 0.5;
  transition: opacity 0.25s ease;
}

.gauge-value.flash-update,
.gauge-sub.flash-update {
  animation: flashUpdate 0.7s ease;
}

/* Results ------------------------------------------------------------------- */

.results-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: opacity 0.25s ease;
}

.results-list.is-stale {
  opacity: 0.45;
}

.result-row {
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 10px;
  border-radius: var(--radius-sm);
  background: var(--surface-sunken);
}

.result-row.is-source {
  background: color-mix(in srgb, var(--row-color, var(--accent)) 16%, var(--surface-sunken));
  box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--row-color, var(--accent)) 55%, transparent);
}

.result-bar {
  position: absolute;
  inset: 0;
  width: 0%;
  background: color-mix(in srgb, var(--row-color, var(--accent)) 22%, transparent);
  transition: width 0.6s cubic-bezier(0.22, 1, 0.36, 1);
  z-index: 0;
}

.result-left {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 10px;
}

.result-swatch {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--row-color, var(--accent));
  flex: 0 0 auto;
}

.result-distance {
  font-size: 16px;
  font-weight: 590;
}

.result-badge {
  font-size: 11px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-primary);
  background: var(--row-color, var(--accent));
  padding: 2px 7px;
  border-radius: var(--radius-pill);
}

.result-values {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 1px;
}

.result-time {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 17px;
  font-weight: 600;
}

.result-time.is-idle {
  color: var(--text-tertiary);
  font-weight: 500;
}

.result-speed {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 11.5px;
  font-weight: 500;
  color: var(--text-secondary);
}

.result-speed.is-idle {
  color: var(--text-tertiary);
}

.result-pace {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 11.5px;
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
}

.result-pace .is-idle {
  color: var(--text-tertiary);
}

.result-pace .pace-sep {
  color: var(--text-tertiary);
}

.result-time.flash-update,
.result-speed.flash-update,
.pace-km.flash-update,
.pace-mile.flash-update {
  animation: flashUpdate 0.7s ease;
}

@keyframes flashUpdate {
  0% { color: var(--row-color, var(--accent)); }
  100% { color: var(--text-primary); }
}

.footnote {
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--text-tertiary);
  padding: 0 6px;
}

/* Home — category accordion ---------------------------------------------
   Each category is a disclosure group (button + grid-rows body) so the
   expand/collapse animates smoothly without JS measuring scrollHeight.
   A category's accent color is set once via --cat-color and inherited by
   every calc-box inside it, the same "color as data" convention as the
   sprint-predictor distance spectrum and the power-calculator trajectory. */

.category-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.category-group {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0) 40%),
    var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm), inset 0 1px 0 rgba(255, 255, 255, 0.05);
  overflow: hidden;
}

.category-header {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  min-height: 64px;
  border: none;
  background: transparent;
  color: inherit;
  font-family: var(--font-text);
  text-align: left;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

.category-header:active {
  background: var(--surface-sunken);
}

.category-icon {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--cat-color, var(--accent)) 16%, var(--surface-sunken));
  color: var(--cat-color, var(--accent));
}

.category-icon svg {
  width: 20px;
  height: 20px;
}

.category-text {
  flex: 1 1 auto;
  min-width: 0;
}

.category-title {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.category-count {
  font-size: 13px;
  color: var(--text-tertiary);
  margin-top: 1px;
}

.category-chevron {
  flex: 0 0 auto;
  display: flex;
  color: var(--text-tertiary);
  transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}

.category-chevron svg {
  width: 18px;
  height: 18px;
}

.category-group[data-open="true"] .category-chevron {
  transform: rotate(90deg);
}

.category-body-wrap {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}

.category-group[data-open="true"] .category-body-wrap {
  grid-template-rows: 1fr;
}

.category-body {
  overflow: hidden;
}

.category-body-inner {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 0 12px 12px;
}

/* Calculator link box — the tappable unit inside a category. Sized well
   past the 44px HIG minimum so it's comfortable to hit one-handed. ------- */

.calc-box {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 76px;
  padding: 14px;
  border-radius: var(--radius-md);
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  text-decoration: none;
  color: inherit;
  transition: transform 0.12s ease, background 0.15s ease;
}

.calc-box:active {
  transform: scale(0.97);
  background: color-mix(in srgb, var(--cat-color, var(--accent)) 10%, var(--surface-sunken));
}

.calc-box-icon {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border-radius: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--cat-color, var(--accent)) 18%, var(--surface));
  color: var(--cat-color, var(--accent));
}

.calc-box-icon svg {
  width: 22px;
  height: 22px;
}

.calc-box-copy {
  flex: 1 1 auto;
  min-width: 0;
}

.calc-box-copy h3 {
  margin: 0 0 2px;
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 620;
  letter-spacing: -0.01em;
}

.calc-box-copy p {
  margin: 0;
  font-size: 13px;
  line-height: 1.35;
  color: var(--text-secondary);
}

.calc-box-chevron {
  flex: 0 0 auto;
  display: flex;
  color: var(--text-tertiary);
}

.calc-box-chevron svg {
  width: 18px;
  height: 18px;
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition-duration: 0.001ms !important;
    animation-duration: 0.001ms !important;
  }
}
