@import url('./tokens.css');

*,
*::before,
*::after { box-sizing: border-box; }

/* A class rule that sets `display` outranks the UA stylesheet's
   `[hidden] { display: none }`. Without this, hiding an element by setting the
   `hidden` property silently does nothing. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overscroll-behavior-y: none;
}

body {
  font-family: var(--font-ui);
  font-size: var(--t-body);
  line-height: 1.45;
  color: var(--ink);
  background: var(--bg);
  background-image: var(--bg-grad);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* Numerals are the signature: tabular, tight, confident. */
.num {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  font-weight: 700;
}

h1, h2, h3 { margin: 0; font-weight: 640; letter-spacing: -0.015em; }
h1 { font-size: var(--t-display); line-height: 1.05; letter-spacing: -0.03em; }
h2 { font-size: var(--t-title); }
h3 { font-size: var(--t-head); }
p { margin: 0 0 var(--s3); }
p:last-child { margin-bottom: 0; }

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}

.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip-link {
  /* Anchored to the top of the viewport and moved fully above it, rather than
     offset from the safe-area inset. A percentage translate resolves against
     the element's own height, so an inset-based offset leaves it peeking into
     the status bar on notched devices. */
  position: fixed; left: 50%; top: 0;
  transform: translate(-50%, -150%);
  background: var(--accent); color: var(--accent-ink);
  padding: var(--s2) var(--s4); border-radius: var(--r-chip);
  z-index: 100; font-weight: 600; white-space: nowrap;
  transition: transform var(--dur) var(--ease);
}
.skip-link:focus,
.skip-link:focus-visible {
  transform: translate(-50%, calc(var(--safe-t) + var(--s2)));
}

/* ------------------------------------------------------------- app shell -- */
#app { min-height: 100%; }

.screen {
  max-width: var(--page-max);
  margin: 0 auto;
  padding:
    calc(var(--safe-t) + var(--s4))
    calc(var(--safe-r) + var(--s4))
    calc(var(--safe-b) + var(--nav-h) + var(--s7))
    calc(var(--safe-l) + var(--s4));
}
.screen[data-chrome='none'] { padding-bottom: var(--s4); }

.screen-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: var(--s3); margin-bottom: var(--s5);
}
.screen-head .eyebrow {
  color: var(--ink-3); font-size: var(--t-small); margin-bottom: 2px;
}

/* Scrolling content passes under the status bar on a full-bleed layout. This
   sits in the inset area so the clock and Dynamic Island stay legible. It
   collapses to zero height wherever there is no inset. */
.statusbar-scrim {
  position: fixed;
  inset: 0 0 auto 0;
  height: var(--safe-t);
  z-index: 45;
  pointer-events: none;
  background: var(--nav-bg);
  backdrop-filter: saturate(1.6) blur(14px);
  -webkit-backdrop-filter: saturate(1.6) blur(14px);
}

/* --------------------------------------------------------------- bottom nav */
.nav {
  position: fixed; inset: auto 0 0 0; z-index: 40;
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding-bottom: var(--safe-b);
  background: var(--nav-bg);
  backdrop-filter: saturate(1.7) blur(18px);
  -webkit-backdrop-filter: saturate(1.7) blur(18px);
  border-top: 1px solid var(--hairline);
  box-shadow: var(--shadow-lift);
}
.nav button {
  min-height: var(--nav-h);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; background: none; border: 0; color: var(--ink-3);
  font-size: var(--t-micro); font-weight: 550;
  padding: var(--s1) 2px;
  transition: color var(--dur-fast) var(--ease);
}
.nav button svg { width: 22px; height: 22px; }
.nav button[aria-current='page'] { color: var(--ink); }
.nav button[aria-current='page'] svg { color: var(--accent); }

/* ------------------------------------------------------------------ panels */
.panel {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--r-panel);
  box-shadow: var(--sheen);
  padding: var(--s4);
}
.panel + .panel { margin-top: var(--s3); }
.panel-flush { padding: 0; overflow: hidden; }

/* The primary session panel earns more weight than everything around it. */
.panel-hero {
  border-radius: 22px;
  padding: var(--s5);
  border-color: var(--hairline-strong);
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--accent) 8%, transparent), transparent 42%),
    var(--surface);
}

.stack { display: flex; flex-direction: column; gap: var(--s3); }
.row { display: flex; align-items: center; gap: var(--s3); }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); }
.grow { flex: 1 1 auto; min-width: 0; }
.muted { color: var(--ink-2); }
.dim { color: var(--ink-3); }
.small { font-size: var(--t-small); }
.micro { font-size: var(--t-micro); }
.center { text-align: center; }
.wrap { flex-wrap: wrap; }

.metric { font-size: var(--t-metric); line-height: 1.1; }
.metric-lg { font-size: var(--t-display); line-height: 1; }
.unit { font-size: 0.5em; font-weight: 600; color: var(--ink-3); margin-left: 2px; }

/* ----------------------------------------------------------------- buttons */
.btn {
  min-height: var(--tap);
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  padding: 0 var(--s5);
  border-radius: var(--r-control);
  border: 1px solid var(--hairline-strong);
  background: var(--raised); color: var(--ink);
  font-weight: 600; letter-spacing: -0.005em;
  transition: transform var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
.btn:active { transform: scale(0.975); }
.btn[disabled] { opacity: 0.42; pointer-events: none; }
.btn-primary {
  background: var(--accent); color: var(--accent-ink);
  border-color: transparent; font-weight: 680;
}
.btn-ghost { background: transparent; border-color: var(--hairline); }
.btn-quiet { background: transparent; border-color: transparent; color: var(--ink-2); padding: 0 var(--s3); }
.btn-danger { background: var(--danger-soft); border-color: transparent; color: var(--danger); }
.btn-block { width: 100%; }
.btn-lg { min-height: 54px; font-size: 1.0625rem; border-radius: 14px; }
.btn-icon { width: var(--tap); padding: 0; }

.chip {
  min-height: 36px; padding: 0 var(--s3);
  display: inline-flex; align-items: center; gap: 6px;
  border-radius: var(--r-chip);
  border: 1px solid var(--hairline);
  background: transparent; color: var(--ink-2);
  font-size: var(--t-small); font-weight: 560;
}
.chip[aria-pressed='true'], .chip.on {
  background: var(--accent-soft); border-color: var(--accent-line); color: var(--ink);
}
.chip-tap { min-height: var(--tap); }

.tag {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: var(--r-chip);
  font-size: var(--t-micro); font-weight: 600;
  background: var(--accent-soft); color: var(--ink);
}
.tag-warn { background: var(--warn-soft); color: var(--warn); }
.tag-danger { background: var(--danger-soft); color: var(--danger); }
.tag-flat { background: transparent; border: 1px solid var(--hairline); color: var(--ink-3); }

/* ------------------------------------------------------------------ inputs */
.field { display: block; margin-bottom: var(--s4); }
.field > .label {
  display: block; font-size: var(--t-small); font-weight: 600;
  color: var(--ink-2); margin-bottom: 6px;
}
.field > .hint { display: block; font-size: var(--t-micro); color: var(--ink-3); margin-top: 6px; }
.field .err { display: block; font-size: var(--t-micro); color: var(--danger); margin-top: 6px; font-weight: 600; }

.input, select.input, textarea.input {
  width: 100%; min-height: var(--tap);
  padding: 10px var(--s3);
  background: var(--raised);
  border: 1px solid var(--hairline-strong);
  border-radius: var(--r-control);
  color: var(--ink);
  appearance: none;
}
textarea.input { min-height: 88px; resize: vertical; line-height: 1.45; }
.input:focus { border-color: var(--accent); }
.input[aria-invalid='true'] { border-color: var(--danger); }
select.input {
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-3) 50%),
    linear-gradient(135deg, var(--ink-3) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 12px) 50%;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  padding-right: var(--s7);
}

.switch { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); min-height: var(--tap); }
.switch input { appearance: none; width: 50px; height: 30px; border-radius: 999px; background: var(--hairline-strong); position: relative; transition: background var(--dur-fast); flex: none; }
.switch input::after { content: ''; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: transform var(--dur-fast) var(--ease); }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(20px); }

/* Segmented control */
.seg { display: flex; gap: 2px; padding: 3px; background: var(--raised); border: 1px solid var(--hairline); border-radius: 12px; }
.seg button {
  flex: 1; min-height: 38px; border: 0; border-radius: 9px; background: transparent;
  color: var(--ink-2); font-size: var(--t-small); font-weight: 600;
}
.seg button[aria-checked='true'] { background: var(--accent); color: var(--accent-ink); }

/* Large single-choice cards */
.option-card {
  display: flex; flex-direction: column; gap: 4px;
  width: 100%; min-height: var(--tap);
  padding: var(--s4);
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--r-panel);
  box-shadow: var(--sheen);
  transition: border-color var(--dur-fast) var(--ease),
    background var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.option-card:active { transform: scale(0.99); }
.option-card-title { font-size: var(--t-head); font-weight: 640; }
.option-card-hint { font-size: var(--t-small); color: var(--ink-2); }
.option-card[aria-checked='true'] {
  border-color: var(--accent);
  background: linear-gradient(180deg, var(--accent-soft), transparent 60%), var(--surface);
}
/* Selection must not rest on colour alone. */
.option-card[aria-checked='true'] .option-card-title::after {
  content: '';
  display: inline-block; margin-left: 8px;
  width: 7px; height: 12px;
  border: solid var(--ink); border-width: 0 2px 2px 0;
  transform: translateY(-1px) rotate(45deg);
}

/* Scale 1..5 used by readiness and form quality */
.scale { display: grid; grid-template-columns: repeat(5, 1fr); gap: var(--s2); }
.scale button {
  min-height: 52px; border-radius: 12px; border: 1px solid var(--hairline);
  background: var(--raised); color: var(--ink-2); font-weight: 700;
}
.scale button[aria-pressed='true'] { background: var(--accent); color: var(--accent-ink); border-color: transparent; }

/* Stepper for reps / weight */
.stepper { display: flex; align-items: stretch; gap: var(--s2); }
.stepper button { width: 46px; border-radius: var(--r-control); border: 1px solid var(--hairline-strong); background: var(--raised); font-size: 1.25rem; font-weight: 700; }
.stepper .val { flex: 1; text-align: center; display: flex; align-items: center; justify-content: center; background: var(--raised); border: 1px solid var(--hairline-strong); border-radius: var(--r-control); min-width: 72px; }
.stepper input { width: 100%; text-align: center; background: none; border: 0; font-family: var(--font-num); font-variant-numeric: tabular-nums; font-weight: 700; font-size: 1.25rem; }
.stepper input::-webkit-outer-spin-button, .stepper input::-webkit-inner-spin-button { appearance: none; margin: 0; }

/* --------------------------------------------------------------- list rows */
.list { list-style: none; margin: 0; padding: 0; }
.list li + li { border-top: 1px solid var(--hairline); }
.list-row {
  display: flex; align-items: center; gap: var(--s3);
  width: 100%; min-height: 56px; padding: var(--s3) var(--s4);
  background: none; border: 0; text-align: left; color: inherit;
}
.list-row .chev { color: var(--ink-3); flex: none; }

/* --------------------------------------------------------------- workout   */
.workout-shell {
  min-height: 100dvh; display: flex; flex-direction: column;
  padding: var(--safe-t) var(--safe-r) 0 var(--safe-l);
}
.workout-top {
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s3) var(--s4);
  border-bottom: 1px solid var(--hairline);
}
.workout-body { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: var(--s4); padding-bottom: 190px; }
.workout-foot {
  position: fixed; inset: auto 0 0 0; z-index: 30;
  padding: var(--s3) var(--s4) calc(var(--safe-b) + var(--s3));
  background: var(--nav-bg);
  backdrop-filter: blur(18px) saturate(1.7);
  -webkit-backdrop-filter: blur(18px) saturate(1.7);
  border-top: 1px solid var(--hairline);
}

.progress-rail { height: 4px; border-radius: 3px; background: var(--hairline); overflow: hidden; }
.progress-rail > i { display: block; height: 100%; background: var(--accent); transition: width var(--dur) var(--ease); }

/* Set rows: the densest, most-used surface in the product. */
.setrow {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) minmax(0, 1fr) 52px;
  align-items: center; gap: var(--s2);
  padding: var(--s2) 0;
}
.setrow + .setrow { border-top: 1px solid var(--hairline); }
.setrow .idx { font-size: var(--t-small); color: var(--ink-3); font-weight: 700; }
.setrow.done .idx { color: var(--accent); }
.setrow input {
  width: 100%; min-height: var(--tap); text-align: center;
  background: var(--raised); border: 1px solid var(--hairline);
  border-radius: var(--r-control);
  font-family: var(--font-num); font-variant-numeric: tabular-nums; font-weight: 700;
}
.setrow.done input { background: var(--accent-soft); border-color: var(--accent-line); }
.setrow .tick {
  width: 46px; height: var(--tap); border-radius: var(--r-control);
  border: 1px solid var(--hairline-strong); background: var(--raised);
  display: inline-flex; align-items: center; justify-content: center; color: var(--ink-3);
}
.setrow.done .tick { background: var(--accent); border-color: transparent; color: var(--accent-ink); }
.setrow .tick svg { width: 20px; height: 20px; }
.setrow-head { grid-template-columns: 34px minmax(0,1fr) minmax(0,1fr) 52px; display: grid; gap: var(--s2); font-size: var(--t-micro); color: var(--ink-3); font-weight: 600; padding-bottom: 4px; }

/* Rest timer */
.rest {
  position: fixed; inset: auto 0 calc(var(--safe-b) + 82px) 0; z-index: 35;
  margin: 0 var(--s4);
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s3);
  border-radius: 16px;
  background: var(--raised); border: 1px solid var(--accent-line);
  box-shadow: 0 10px 30px rgba(0,0,0,.35);
}
.ring { width: 46px; height: 46px; flex: none; }
.ring circle { fill: none; stroke-width: 5; }
.ring .track { stroke: var(--hairline-strong); }
.ring .head { stroke: var(--accent); stroke-linecap: round; transition: stroke-dashoffset 1s linear; }

/* ------------------------------------------------------------------ sheets */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(0,0,0,.5);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade var(--dur) var(--ease);
}
.sheet {
  width: 100%; max-width: var(--page-max);
  max-height: 88dvh; overflow-y: auto;
  background: var(--surface);
  border-radius: var(--r-sheet) var(--r-sheet) 0 0;
  border-top: 1px solid var(--hairline-strong);
  padding: var(--s3) var(--s4) calc(var(--safe-b) + var(--s5));
  animation: rise var(--dur-slow) var(--ease);
}
.sheet-grip { width: 38px; height: 4px; border-radius: 3px; background: var(--hairline-strong); margin: 0 auto var(--s4); }
@keyframes rise { from { transform: translateY(14px); opacity: .6; } }
@keyframes fade { from { opacity: 0; } }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-b) + var(--nav-h) + var(--s4));
  transform: translateX(-50%); z-index: 80;
  max-width: min(92vw, 460px);
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s3) var(--s4);
  background: var(--raised); color: var(--ink);
  border: 1px solid var(--hairline-strong); border-radius: 14px;
  box-shadow: 0 12px 32px rgba(0,0,0,.4);
  animation: rise var(--dur) var(--ease);
}
.toast button { background: none; border: 0; color: var(--accent); font-weight: 700; }

/* ------------------------------------------------------------------ charts */
.chart { width: 100%; display: block; touch-action: pan-y; }
.chart .grid-line { stroke: var(--grid); stroke-width: 1; }
.chart .axis-label { fill: var(--ink-3); font-size: 10px; font-family: var(--font-num); }
.chart .series { fill: none; stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.chart .area { opacity: 0.14; }
.chart .cursor { stroke: var(--ink-3); stroke-width: 1; stroke-dasharray: 3 3; }
.legend { display: flex; flex-wrap: wrap; gap: var(--s3); font-size: var(--t-micro); color: var(--ink-2); }
.legend i { width: 14px; height: 3px; border-radius: 2px; display: inline-block; vertical-align: middle; margin-right: 5px; }

.empty { text-align: center; padding: var(--s7) var(--s4); color: var(--ink-2); }
.empty h3 { margin-bottom: var(--s2); }

/* --------------------------------------------------------------- onboarding */
.ob-steps { display: flex; gap: 4px; margin-bottom: var(--s5); }
.ob-steps i { flex: 1; height: 3px; border-radius: 2px; background: var(--hairline-strong); }
.ob-steps i.on { background: var(--accent); }
.ob-foot { display: flex; gap: var(--s3); margin-top: var(--s6); }

/* On chrome-less screens the footer carries the only way forward, so it is
   pinned to the bottom of the scrollport rather than left at the end of a long
   form where the browser toolbar can sit on top of it. */
.screen[data-chrome='none'] .ob-foot {
  position: sticky;
  bottom: 0;
  z-index: 20;
  margin-top: var(--s6);
  padding: var(--s3) 0 calc(var(--safe-b) + var(--s4));
  background: linear-gradient(to top,
    var(--bg) 0%, var(--bg) 68%, transparent 100%);
}

/* Heat map */
.heat { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: var(--s2); }
.heat div { padding: var(--s2) var(--s3); border-radius: var(--r-control); border: 1px solid var(--hairline); font-size: var(--t-micro); }

/* Larger screens keep the phone feel but breathe */
@media (min-width: 768px) {
  .screen { padding-left: var(--s6); padding-right: var(--s6); }
  .nav { border-radius: 18px 18px 0 0; max-width: var(--page-max); left: 50%; transform: translateX(-50%); }
}

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