/* ---------- Colours ---------- */
:root {
  --bg: #1a1220;
  --surface: #261b2f;
  --surface-2: #33253f;
  --text: #f4ecf7;
  --muted: #c4b5cc;
  --line: #4a3858;
  --accent: #b78cff;
  --accent-strong: #9b6bf2;
  --on-accent: #1a1022;
  --rest: #5fc9b8;
  --on-rest: #0e2622;

  --font-body: "Atkinson Hyperlegible", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-head: "Bricolage Grotesque", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);

  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f1f8;
    --surface: #ffffff;
    --surface-2: #ece3f1;
    --text: #22162b;
    --muted: #5c4a68;
    --line: #d6c7df;
    --accent: #7a3fe0;
    --accent-strong: #6a2fd0;
    --on-accent: #ffffff;
    --rest: #1c8a7c;
    --on-rest: #ffffff;
    color-scheme: light;
  }
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 1.2rem;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}

h1, h2 { font-family: var(--font-head); margin: 0; line-height: 1.1; }

a { color: var(--accent); }

[hidden] { display: none !important; }

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

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

.screen {
  max-width: 40rem;
  margin: 0 auto;
  padding:
    calc(1.25rem + var(--safe-t))
    calc(1.25rem + var(--safe-r))
    calc(1.25rem + var(--safe-b))
    calc(1.25rem + var(--safe-l));
}

/* ---------- Buttons ---------- */
.btn {
  font: inherit;
  font-weight: 700;
  font-size: 1.25rem;
  min-height: 3.75rem;
  padding: 0.75rem 1.25rem;
  border-radius: 1rem;
  border: 2px solid transparent;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.1s ease, background-color 0.15s ease;
}
.btn:active { transform: scale(0.97); }

.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-strong); }
@media (prefers-color-scheme: light) {
  .btn-primary:hover { background: var(--accent-strong); }
}

.btn-ghost { background: transparent; color: var(--text); border-color: var(--line); }

.btn-start { width: 100%; min-height: 4.5rem; font-size: 1.6rem; font-family: var(--font-head); }

/* ---------- Home ---------- */
#home { display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; }

.home-head h1 { font-size: 2.6rem; font-weight: 800; letter-spacing: -0.02em; }
.tagline { color: var(--muted); margin: 0.5rem 0 1.25rem; }

.tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.6rem; }

.tab {
  font: inherit;
  background: var(--surface);
  color: var(--text);
  border: 2px solid var(--line);
  border-radius: 1rem;
  padding: 0.75rem 0.5rem;
  min-height: 6rem;
  cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.25rem;
  text-align: center;
  touch-action: manipulation;
}
.tab-letter { font-family: var(--font-head); font-weight: 800; font-size: 2rem; line-height: 1; }
.tab-label { font-size: 0.95rem; line-height: 1.2; color: var(--muted); }
.tab[aria-selected="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.tab[aria-selected="true"] .tab-label { color: var(--on-accent); }

.panel { flex: 1; padding-top: 1rem; }
.equipment { color: var(--muted); margin: 0 0 0.75rem; font-size: 1rem; }

.moves { list-style: none; margin: 0; padding: 0; counter-reset: move; }
.moves li {
  counter-increment: move;
  position: relative;
  background: var(--surface);
  border-radius: 1rem;
  padding: 1rem 1rem 1rem 3.75rem;
  margin-bottom: 0.6rem;
}
.moves li::before {
  content: counter(move);
  position: absolute; left: 1rem; top: 1rem;
  width: 2rem; height: 2rem; border-radius: 50%;
  background: var(--surface-2);
  color: var(--accent);
  font-family: var(--font-head); font-weight: 800;
  display: grid; place-items: center;
}
.note {
  margin: 0 0 0.75rem;
  padding: 0.75rem 1rem;
  border-left: 4px solid var(--rest);
  background: var(--surface);
  border-radius: 0.5rem;
  font-size: 1rem;
}

.move-title { font-weight: 700; font-size: 1.3rem; margin: 0 0 0.2rem; }

/* Setup pictures (drawn by poses.js) */
.setup {
  flex: none;
  border-radius: 0.75rem;
  background: var(--surface-2);
  color: var(--text);
  line-height: 0;
}
.setup svg { width: 100%; height: auto; }
.setup polyline, .setup line {
  fill: none; stroke-linecap: round; stroke-linejoin: round;
}
.pz-body { stroke: currentColor; stroke-width: 3.5; }
.pz-far { stroke: currentColor; stroke-width: 3.5; opacity: 0.4; }
.pz-head { fill: currentColor; }
.pz-band { stroke: var(--accent); stroke-width: 3; }
.pz-prop { stroke: var(--line); stroke-width: 2; fill: none; }
.pz-arrow { stroke: var(--muted); stroke-width: 1.75; opacity: 0.8; }
.moves .setup {
  float: right;
  width: 6.5rem;
  margin: 0 0 0.4rem 0.75rem;
}

/* Loop | Long band toggle */
.band-toggle {
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  margin: 0.35rem 0 0.5rem;
  padding: 0.2rem;
  border-radius: 0.8rem;
  background: var(--surface-2);
}
.band-toggle label {
  position: relative;
  display: grid; place-items: center;
  min-height: 2.75rem;
  padding: 0 1rem;
  border-radius: 0.6rem;
  font-weight: 700; font-size: 1rem;
  color: var(--muted);
  cursor: pointer;
  touch-action: manipulation;
}
.band-toggle input {
  position: absolute; inset: 0;
  margin: 0; opacity: 0; cursor: pointer;
}
.band-toggle label:has(input:checked) { background: var(--accent); color: var(--on-accent); }
.band-toggle label:has(input:focus-visible) { outline: 3px solid var(--accent); outline-offset: 2px; }
.move-cue-small { margin: 0 0 0.4rem; color: var(--muted); font-size: 1.05rem; }
.demo-link { display: inline-block; padding: 0.35rem 0; font-weight: 700; font-size: 1.05rem; }

.start-wrap {
  position: sticky;
  bottom: 0;
  padding: 0.75rem 0 calc(0.25rem);
  margin-top: 0.5rem;
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}

/* ---------- Timer ---------- */
#timer {
  display: flex; flex-direction: column;
  min-height: 100vh; min-height: 100dvh;
  max-width: 44rem;
  text-align: center;
  --phase-color: var(--accent);
}
#timer.is-rest { --phase-color: var(--rest); }
#timer.is-ready { --phase-color: var(--muted); }

/* Top bar: small end button, routine name, time left */
.t-bar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}
.icon-btn {
  width: 3rem; height: 3rem;
  display: grid; place-items: center;
  border-radius: 50%;
  border: 2px solid var(--line);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  touch-action: manipulation;
}
.icon-btn svg { width: 1.25rem; height: 1.25rem; stroke: currentColor; stroke-width: 2.5; stroke-linecap: round; fill: none; }
.t-routine {
  margin: 0; font-weight: 700; font-size: 1rem; color: var(--muted);
  text-align: left;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.t-left {
  margin: 0; padding: 0.3rem 0.7rem;
  border-radius: 1rem;
  background: var(--surface-2);
  font-size: 0.95rem; font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* Timeline of the whole workout */
.timeline { display: flex; gap: 3px; height: 0.6rem; }
.seg {
  --p: 0;
  position: relative;
  min-width: 3px;
  border-radius: 0.3rem;
  background: var(--surface-2);
  overflow: hidden;
}
.seg::after {
  content: "";
  position: absolute; inset: 0;
  background: var(--accent);
  transform-origin: left center;
  transform: scaleX(var(--p));
}
.seg-rest::after { background: var(--rest); }
.seg-ready::after { background: var(--muted); }
.seg-rest { opacity: 0.75; }
.seg.round-start { margin-left: 0.6rem; }
.seg.is-current { outline: 2px solid var(--phase-color); outline-offset: 1px; }

.position { margin: 0.5rem 0 0; color: var(--muted); font-size: 1rem; }

/* Countdown dial */
.dial {
  position: relative;
  width: min(62vw, 32vh, 18rem);
  aspect-ratio: 1;
  margin: 0.75rem auto 0.5rem;
}
.ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 8; }
.ring-track { stroke: var(--surface-2); }
.ring-fill { stroke: var(--phase-color); stroke-linecap: round; }
.dial-inner {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.phase {
  margin: 0;
  font-family: var(--font-head); font-weight: 800;
  font-size: clamp(0.95rem, 4vw, 1.2rem); color: var(--phase-color);
  max-width: 62%;
  line-height: 1.15;
}
.count {
  font-family: var(--font-head); font-weight: 800;
  font-size: clamp(3.5rem, min(20vw, 11vh), 7rem);
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
#timer.is-paused .ring-fill,
#timer.is-paused .count { opacity: 0.45; }
#timer.is-paused .phase { color: var(--text); }

/* Current move */
.move-info { flex: 1; }
.move-name { font-size: 1.75rem; font-weight: 800; margin-bottom: 0.35rem; }
.band-label {
  display: inline-block;
  margin: 0 0 0.6rem;
  padding: 0.2rem 0.75rem;
  border-radius: 1rem;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 1rem; font-weight: 700;
}
.move-cue { margin: 0 auto 0.2rem; max-width: 30rem; font-size: 1.15rem; }
.move-body { display: flex; align-items: flex-start; gap: 0.85rem; justify-content: center; }
#timer.has-pic .move-body { text-align: left; }
#timer.has-pic .move-cue { font-size: 1.05rem; line-height: 1.4; }
#timer .setup { width: 7rem; margin-top: 0.15rem; }
#timer.is-rest .pz-band { stroke: var(--rest); }
.demo { display: inline-block; padding: 0.3rem; font-weight: 700; }

/* Up next */
.next-card {
  display: flex; align-items: center; gap: 0.75rem;
  margin: 0.5rem 0 0.75rem;
  padding: 0.6rem 1rem;
  border-radius: 1rem;
  background: var(--surface);
  text-align: left;
}
.next-label {
  flex: none;
  font-size: 0.8rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--muted);
}
.next-name { font-weight: 700; font-size: 1.1rem; }

/* Back / Pause / Skip */
.controls {
  display: flex; justify-content: center; align-items: flex-start;
  gap: 1.75rem;
}
.ctrl {
  font: inherit;
  display: flex; flex-direction: column; align-items: center; gap: 0.3rem;
  background: none; border: 0; padding: 0;
  color: var(--text);
  cursor: pointer;
  touch-action: manipulation;
}
.ctrl svg {
  width: 4rem; height: 4rem; padding: 1.1rem;
  border-radius: 50%;
  background: var(--surface-2);
  transition: transform 0.1s ease;
}
.ctrl .solid { fill: currentColor; }
.ctrl span { font-size: 0.95rem; font-weight: 700; color: var(--muted); }
.ctrl-main svg {
  width: 5.5rem; height: 5.5rem; padding: 1.6rem;
  background: var(--phase-color);
  color: var(--on-accent);
}
#timer.is-rest .ctrl-main svg { color: var(--on-rest); }
.ctrl:active svg { transform: scale(0.94); }
.ctrl:focus-visible { outline: none; }
.ctrl:focus-visible svg { outline: 3px solid var(--accent); outline-offset: 3px; }

/* "Are you sure?" sheet */
.sheet {
  width: min(26rem, calc(100vw - 2rem));
  padding: 1.5rem;
  border: 0;
  border-radius: 1.25rem;
  background: var(--surface);
  color: var(--text);
  text-align: center;
}
.sheet::backdrop { background: rgb(10 5 15 / 0.65); }
.sheet h2 { font-size: 1.6rem; margin-bottom: 0.5rem; }
.sheet p { margin: 0 0 1.25rem; color: var(--muted); }
.sheet-actions { display: grid; gap: 0.6rem; }

/* ---------- Done ---------- */
#done {
  display: flex; flex-direction: column; justify-content: space-between;
  min-height: 100vh; min-height: 100dvh;
}
.done-body { flex: 1; display: flex; flex-direction: column; justify-content: center; text-align: center; }
.done-title { font-size: 2.6rem; font-weight: 800; color: var(--accent); }
.done-sub { font-size: 1.35rem; color: var(--muted); }

/* ---------- Most phones: keep the whole timer on one screen ---------- */
@media (max-height: 860px) {
  #timer { padding-top: calc(0.75rem + var(--safe-t)); padding-bottom: calc(0.75rem + var(--safe-b)); }
  .t-bar { margin-bottom: 0.5rem; }
  .icon-btn { width: 2.75rem; height: 2.75rem; }
  .position { margin-top: 0.35rem; font-size: 0.95rem; }
  .dial { width: min(62vw, 24vh, 18rem); margin: 0.5rem auto 0.35rem; }
  .count { font-size: clamp(3rem, 9vh, 7rem); }
  .move-name { font-size: 1.45rem; margin-bottom: 0.25rem; }
  .band-label { margin-bottom: 0.4rem; font-size: 0.9rem; }
  #timer .setup { width: 5.75rem; }
  #timer.has-pic .move-cue { font-size: 1rem; line-height: 1.35; }
  .next-card { margin: 0.4rem 0 0.5rem; padding: 0.45rem 0.9rem; }
  .ctrl svg { width: 3.5rem; height: 3.5rem; padding: 0.95rem; }
  .ctrl-main svg { width: 4.75rem; height: 4.75rem; padding: 1.35rem; }
}

/* ---------- Small / landscape ---------- */
@media (max-height: 600px) and (orientation: landscape) {
  .dial { width: min(40vh, 12rem); margin-top: 0.5rem; }
  .count { font-size: 3.5rem; }
  .move-name { font-size: 1.5rem; }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
  .btn:active { transform: none; }
}
