/* Tokens follow the shared buddy-site system (workout-buddy-site/site/style.css):
   system fonts only, Workout Buddy orange as the one accent. Colour never
   carries meaning alone — every state also differs in lightness, position,
   shape or a text label. */
:root {
  color-scheme: light dark;
  --accent: #ad5210;
  --accent-ink: #ffffff;
  --accent-soft: rgba(173, 82, 16, .10);
  --bg: #fcfcfd;
  --surface: #f2f3f6;
  --surface-2: #e6e8ee;
  --fg: #15161a;
  --muted: #676a74;
  --faint: #a3a6ae;
  --rule: rgba(18, 20, 28, .10);
  --font-display: ui-rounded, "SF Pro Rounded", "Hiragino Maru Gothic ProN", system-ui, sans-serif;
  --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-data: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --measure: 40rem;
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --accent: #f0913f;
    --accent-ink: #1a0d02;
    --accent-soft: rgba(240, 145, 63, .14);
    --bg: #0f1013;
    --surface: #191a1f;
    --surface-2: #24262d;
    --fg: #e8e9ee;
    --muted: #93959f;
    --faint: #5c5f68;
    --rule: rgba(255, 255, 255, .12);
  }
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button, select { font: inherit; color: inherit; }
button { cursor: pointer; }
canvas.fig { display: block; color: var(--fg); }

.muted { color: var(--muted); }
.loading { padding: 3rem 1rem; text-align: center; color: var(--muted); }

/* ── Header + wordmark ─────────────────────────────────────── */

.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: .75rem;
  padding: .55rem max(16px, calc((100vw - var(--measure)) / 2));
  padding-top: max(.55rem, env(safe-area-inset-top));
  background: var(--bg);
  border-bottom: 1px solid var(--rule);
}

/* The house wordmark: name in ink, "buddy" in the product accent. */
.wordmark {
  font-family: var(--font-data);
  font-size: .9375rem;
  font-weight: 600;
  letter-spacing: -.025em;
  color: var(--fg);
  text-decoration: none;
  white-space: nowrap;
}
.wordmark span { color: var(--accent); }

.top nav { display: flex; gap: .1rem; margin-left: auto; }
.top nav a {
  padding: .3rem .55rem;
  border-radius: 999px;
  color: var(--muted);
  text-decoration: none;
  font-size: .9rem;
  font-weight: 550;
}
/* Current tab: darker text on a filled pill, not just a hue change. */
.top nav a[aria-current="page"] { background: var(--surface-2); color: var(--fg); }

main {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 1rem 16px calc(6rem + env(safe-area-inset-bottom));
}

h1 {
  font-family: var(--font-display);
  font-size: 1.6rem;
  letter-spacing: -.02em;
  margin: .4rem 0 1rem;
}

.label {
  font-size: .75rem;
  font-weight: 650;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 1.6rem 0 .6rem;
}

/* ── Buttons ───────────────────────────────────────────────── */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  border: 1px solid var(--rule);
  background: var(--surface);
  border-radius: 12px;
  padding: .55rem .9rem;
  font-weight: 600;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.wide { width: 100%; padding: .85rem; font-size: 1.05rem; }
.btn.ghost { background: none; border-color: transparent; color: var(--muted); padding: .4rem .5rem; }
.btn:focus-visible, .chip:focus-visible, .toggle:focus-within, select:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.icon { width: 1.15em; height: 1.15em; flex: none; }

/* ── Home ──────────────────────────────────────────────────── */

.hero { text-align: center; }
.hero .fig { width: 100%; height: 110px; color: var(--accent); }
.hero p { color: var(--muted); margin: .4rem 0 0; }

.toggle {
  display: flex; align-items: center; gap: .8rem;
  padding: .8rem 1rem;
  background: var(--surface);
  border-radius: var(--radius);
  margin-bottom: .5rem;
  cursor: pointer;
}
.toggle .text { flex: 1; display: flex; flex-direction: column; }
.toggle small { color: var(--muted); font-size: .8rem; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
/* Switch: on = knob right on a solid fill; off = knob left on a pale track. */
.switch {
  width: 46px; height: 28px; flex: none;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--rule);
  position: relative;
  transition: background .15s;
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 22px; height: 22px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.3);
  transition: transform .15s;
}
.toggle input:checked + .switch { background: var(--accent); border-color: transparent; }
.toggle input:checked + .switch::after { transform: translateX(18px); }

.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: .5rem; }

/* Intensity: the chosen box is filled and carries a check; the rest are pale. */
.chip {
  display: flex; flex-direction: column; align-items: center; gap: .1rem;
  padding: .7rem .2rem;
  border-radius: var(--radius);
  border: 1px solid var(--rule);
  background: var(--surface);
  min-width: 0;
}
.chip b { font-size: .9rem; }
.chip small { font-size: .72rem; color: var(--muted); white-space: nowrap; }
.chip .tick { height: 1rem; font-size: .8rem; line-height: 1rem; }
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.chip[aria-pressed="true"] small { color: inherit; opacity: .85; }

.duration {
  display: flex; flex-direction: column; align-items: center;
  padding: .75rem 0;
  border: 0; border-radius: 12px;
  background: var(--accent); color: var(--accent-ink);
}
.duration b { font-size: 1.3rem; line-height: 1.1; }
.duration small { font-size: .72rem; }
.hint { text-align: center; color: var(--faint); font-size: .8rem; margin: .5rem 0 0; }

.repeat { margin-top: 1.6rem; }

/* ── Lists (plan, catalog, history) ───────────────────────── */

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(0, 1fr)); text-align: center; margin: .5rem 0 1rem; }
.stats b { display: block; font-size: 1.3rem; font-family: var(--font-display); }
.stats small { color: var(--muted); font-size: .78rem; }

.list { list-style: none; margin: 0; padding: 0; border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.list > li { display: flex; align-items: center; gap: .75rem; padding: .55rem .8rem; border-top: 1px solid var(--rule); }
.list > li:first-child { border-top: 0; }
.list .num { width: 1.6rem; text-align: center; font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; }
.list .fig { width: 54px; height: 54px; flex: none; }
.list .body { flex: 1; min-width: 0; }
.list .name { font-weight: 560; }
.list .meta { color: var(--muted); font-size: .8rem; }
.list .open { all: unset; cursor: pointer; display: flex; align-items: center; gap: .75rem; flex: 1; min-width: 0; }
.list .open:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 8px; }

/* A muted ("Never") exercise is drawn lighter, not in another colour. */
.list li.never .fig, .list li.never .name, .list li.never .meta { opacity: .4; }

select.freq {
  border: 1px solid var(--rule);
  background: var(--bg);
  border-radius: 999px;
  padding: .25rem .6rem;
  font-size: .8rem;
}

.toolbar { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.toolbar h1 { margin: .4rem 0; }

.start-bar {
  position: fixed; left: 0; right: 0; bottom: 0;
  padding: .75rem max(16px, calc((100vw - var(--measure)) / 2)) calc(.75rem + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-top: 1px solid var(--rule);
}
.note { color: var(--muted); font-size: .78rem; margin: .8rem 0 0; }

.empty { text-align: center; padding: 3rem 1rem; color: var(--muted); }
.empty b { display: block; color: var(--fg); font-size: 1.1rem; margin-bottom: .3rem; }

/* ── Dialogs ───────────────────────────────────────────────── */

dialog.sheet {
  border: 0; border-radius: 20px;
  padding: 1.25rem;
  width: min(32rem, calc(100vw - 32px));
  background: var(--bg); color: var(--fg);
  box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
dialog.sheet::backdrop { background: rgba(0,0,0,.45); }
dialog.small { width: min(22rem, calc(100vw - 32px)); text-align: center; }
.confirm-title { font-weight: 700; font-size: 1.15rem; margin: 0; }
.row { display: flex; gap: .5rem; justify-content: center; }
.row .btn { flex: 1; }
.detail h2 { margin: 0; font-family: var(--font-display); font-size: 1.35rem; text-align: center; }
.detail .meta { text-align: center; color: var(--muted); font-size: .9rem; margin: .2rem 0 1rem; }
.detail .views { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.detail figure { margin: 0; text-align: center; }
.detail figure .fig { width: 100%; aspect-ratio: 1; background: var(--surface); border-radius: 16px; }
.detail figcaption { font-size: .78rem; font-weight: 600; color: var(--muted); margin-top: .3rem; }
.detail .tip { text-align: center; color: var(--muted); margin: 1rem 0 0; }
.close { position: absolute; top: .6rem; right: .6rem; }

/* ── Player ────────────────────────────────────────────────── */

.player {
  position: fixed; inset: 0; z-index: 20;
  display: flex; flex-direction: column; align-items: center;
  padding: max(8px, env(safe-area-inset-top)) 16px max(12px, env(safe-area-inset-bottom));
  background: var(--bg);
  overflow-y: auto;
  height: 100dvh;
}
/* `display: flex` above would otherwise beat the hidden attribute and leave an
   invisible overlay swallowing every click. */
.player[hidden] { display: none; }
.player > * { width: 100%; max-width: var(--measure); }

/* Phases differ by label first, then by lightness: work is the full accent on
   a tinted page, rest is pale and dashed, ready is plain ink. */
.player[data-phase="work"] { background: linear-gradient(var(--accent-soft), var(--accent-soft)), var(--bg); }
.player[data-phase="work"] .phase { color: var(--accent); }
.player[data-phase="rest"] .phase, .player[data-phase="ready"] .phase { color: var(--muted); }

.player .bar { display: flex; align-items: center; gap: .25rem; }
.player .bar .count { flex: 1; text-align: center; color: var(--muted); font-weight: 560; font-size: .9rem; }
.toggle-btn[aria-pressed="false"] { opacity: .45; }

.progress { height: 5px; border-radius: 999px; background: var(--surface-2); margin: .4rem 0 0; overflow: hidden; }
.progress > div { height: 100%; background: var(--fg); transition: width .3s; }

.stage { flex: 1; min-height: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: .4rem; padding: .5rem 0; }
.phase { font-size: .78rem; font-weight: 800; letter-spacing: .16em; }
.exercise-name { font-family: var(--font-display); font-size: clamp(1.7rem, 7vw, 2.3rem); margin: 0; line-height: 1.15; }
.stage .fig { width: 100%; height: min(28dvh, 260px); }
.stage .tip { color: var(--muted); font-size: .88rem; max-width: 26rem; min-height: 2.6em; margin: 0; }

.ring { position: relative; width: 96px; height: 96px; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 8; }
.ring .track { stroke: var(--surface-2); }
.ring .arc { stroke: var(--fg); stroke-linecap: round; }
.player[data-phase="work"] .ring .arc { stroke: var(--accent); }
/* Rest: dashed track, pale arc. The dashes go on the track because the arc's
   own dasharray is what draws the progress. */
.player[data-phase="rest"] .ring .track { stroke-dasharray: 3 9; }
.player[data-phase="rest"] .ring .arc { stroke: var(--faint); }
.ring .secs {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-family: var(--font-display); font-size: 2.1rem; font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.paused-tag { font-size: .8rem; font-weight: 700; letter-spacing: .1em; color: var(--muted); min-height: 1.2em; }

.controls { display: flex; justify-content: center; gap: 2.5rem; padding: .5rem 0; }
.controls .round {
  width: 60px; height: 60px; border-radius: 50%; border: 0;
  display: grid; place-items: center;
  background: var(--fg); color: var(--bg);
}
.controls .round.secondary { background: var(--surface-2); color: var(--fg); }
.controls .round .icon { width: 28px; height: 28px; }

.next-up {
  align-self: flex-end;
  width: auto; max-width: 60%;
  text-align: right;
  background: var(--surface); border-radius: 10px;
  padding: .35rem .7rem;
  font-size: .8rem;
}
.next-up small { display: block; font-size: .62rem; font-weight: 800; letter-spacing: .1em; color: var(--muted); }
.next-up[hidden] { display: block; visibility: hidden; }

.finished { flex: 1; display: flex; flex-direction: column; justify-content: center; text-align: center; gap: 1rem; }
.finished .seal { width: 72px; height: 72px; margin: 0 auto; color: var(--accent); }
.finished h1 { font-size: 2rem; margin: 0; }
