/* Exercise — high contrast, big targets, readable from across the room. */

:root {
  --bg: #0b0d10;
  --surface: #161a20;
  --surface-2: #20262e;
  --text: #f5f7fa;
  --muted: #b4bdc9;
  --accent: #c6f432;
  --accent-text: #0b0d10;
  --danger: #ff7a7a;
  --warn-bg: #3a2e05;
  --warn-text: #ffe28a;
  --line: #2e3640;
  --focus: #7cc4ff;
  --radius: 14px;
  --gap: 16px;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6f8;
    --surface: #ffffff;
    --surface-2: #e9edf1;
    --text: #0b0d10;
    --muted: #4a5562;
    --accent: #c6f432;
    --accent-text: #0b0d10;
    --danger: #b3261e;
    --warn-bg: #fff4cc;
    --warn-text: #4d3800;
    --line: #d5dbe1;
    --focus: #0b62c4;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 18px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
  -webkit-tap-highlight-color: transparent;
}

a { color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
main:focus-visible { outline: none; } /* focused only so screen readers start at the new page */
.sr-only, .skip-link:not(:focus) {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0);
}
.skip-link:focus { position: fixed; top: 8px; left: 8px; z-index: 10; background: var(--surface); padding: 8px 12px; }

.muted { color: var(--muted); }
.small { font-size: 0.9rem; }
.tiny { font-size: 0.8rem; }

/* ------------------------------------------------------------------ chrome */

.app-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; max-width: 760px; margin: 0 auto;
}
.brand { font-weight: 800; text-decoration: none; letter-spacing: 0.02em; }
.sync-badge {
  font-size: 0.85rem; padding: 4px 10px; border-radius: 999px;
  background: var(--warn-bg); color: var(--warn-text); text-decoration: none;
}
.banner {
  display: flex; gap: 12px; align-items: center; justify-content: space-between;
  max-width: 760px; margin: 0 auto 8px; padding: 10px 16px;
  background: var(--surface-2); border-radius: var(--radius);
}
.banner[hidden] { display: none; }

main {
  max-width: 760px; margin: 0 auto;
  padding: 0 16px calc(96px + env(safe-area-inset-bottom));
  outline: none;
}

.tabbar {
  position: fixed; inset: auto 0 0 0; display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  text-align: center; padding: 16px 4px; min-height: 56px; text-decoration: none;
  font-size: 0.95rem; color: var(--muted);
}
.tabbar a[aria-current] { color: var(--text); font-weight: 700; box-shadow: inset 0 3px 0 var(--accent); }
.tabbar[hidden] { display: none; }

body.playing .tabbar, body.playing .app-header, body.playing .banner { display: none; }
body.playing main { padding: 0; max-width: none; }

.page-title { font-size: 1.8rem; margin: 8px 0 16px; }

.card {
  display: block; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px; margin: 0 0 var(--gap); text-decoration: none;
}
.card h2 { margin: 0 0 6px; font-size: 1.25rem; }
.card p { margin: 4px 0; }
.empty { text-align: center; padding: 32px 16px; }
.notice { background: var(--warn-bg); color: var(--warn-text); border-radius: 10px; padding: 10px 12px; }
.error { color: var(--danger); font-weight: 600; }

.row { display: flex; flex-wrap: wrap; gap: 10px; margin: var(--gap) 0; }
.inline { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.plain-list, .routine-list { list-style: none; padding: 0; margin: 0; }
.routine-list li { position: relative; }
.arrange { position: absolute; top: 12px; right: 12px; display: flex; gap: 6px; }
.exercise-names { font-size: 0.95rem; }
.memory-cue { font-size: 1.2rem; font-weight: 700; }

.step-list { padding-left: 1.4em; margin: 0; }
.step-list li { margin: 8px 0; }

/* ----------------------------------------------------------------- buttons */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 52px; padding: 12px 20px; border-radius: 12px;
  border: 2px solid var(--line); background: var(--surface-2); color: var(--text);
  font: inherit; font-weight: 650; text-decoration: none; cursor: pointer;
  touch-action: manipulation; user-select: none;
}
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.ghost { background: transparent; }
.btn.small { min-height: 44px; padding: 8px 14px; font-size: 0.95rem; }
.btn.link { background: none; border: none; text-decoration: underline; min-height: 48px; padding: 8px; color: var(--text); }
.btn.round { width: 56px; height: 56px; padding: 0; border-radius: 50%; font-size: 1.6rem; }
.btn.huge { width: 100%; min-height: 84px; font-size: 1.5rem; }

/* ------------------------------------------------------------------- forms */

.field { margin: 0 0 14px; }
.field label { display: block; font-weight: 600; margin-bottom: 6px; }
.field.toggle label { display: flex; align-items: center; gap: 10px; min-height: 48px; }
.field.toggle input { width: 28px; height: 28px; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--bg);
  border: 2px solid var(--line); border-radius: 10px; padding: 12px; min-height: 52px;
}
textarea { min-height: 110px; resize: vertical; }
fieldset { border: 1px dashed var(--line); border-radius: 10px; padding: 12px; margin: 0 0 14px; }
.step-edits { list-style: none; padding: 0; }
.sticky-actions {
  position: sticky; bottom: calc(64px + env(safe-area-inset-bottom)); background: var(--bg);
  padding: 10px 0; margin: 0;
}
.login { max-width: 420px; margin: 10vh auto; }

.stepper { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 8px; }
.stepper span { font-weight: 600; flex: 1 1 100%; }
.stepper-value { font-size: 2.2rem; font-weight: 800; min-width: 2ch; text-align: center; }

/* ----------------------------------------------------------------- history */

.history-row { padding: 0; }
.history-head {
  display: grid; gap: 4px; width: 100%; text-align: left; padding: 16px;
  background: none; border: none; color: inherit; font: inherit; cursor: pointer;
}
.history-when { color: var(--muted); font-size: 0.9rem; }
.history-detail { padding: 0 16px 16px; }
.tag {
  display: inline-block; font-size: 0.85rem; font-weight: 700; padding: 2px 8px;
  border-radius: 999px; border: 1px solid var(--line); margin-left: 6px;
}
.tag.completed { border-color: var(--accent); }
.tag.pending, .tag.failed { background: var(--warn-bg); color: var(--warn-text); border: none; }

.step-times { width: 100%; border-collapse: collapse; margin: 12px 0; font-size: 0.95rem; }
.step-times caption { text-align: left; font-weight: 700; padding-bottom: 6px; }
.step-times th, .step-times td { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--line); }
.step-times .num { text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; }
.step-times .is-rest { color: var(--muted); }

/* ------------------------------------------------------------------ player */

.player-root { min-height: 100dvh; }
.player, .summary {
  display: flex; flex-direction: column; min-height: 100dvh;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  max-width: 900px; margin: 0 auto;
}
.player-top { display: flex; align-items: center; gap: 12px; }
.player-routine { flex: 1; color: var(--muted); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.elapsed { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 1.1rem; }

.player-main { flex: 1; display: flex; flex-direction: column; justify-content: center; text-align: center; }
.section-label { text-transform: uppercase; letter-spacing: 0.08em; font-weight: 700; color: var(--muted); margin: 0; }
/* In a workout, "Round 2 of 2 · Step 7 of 15" is the question you keep asking:
   full brightness, big enough to read from across the room. */
.player .section-label {
  text-transform: none; letter-spacing: 0; color: var(--text);
  font-size: clamp(1.25rem, 4.5vw, 1.7rem); font-weight: 800; font-variant-numeric: tabular-nums;
}
.overall { height: 8px; margin: 8px 0 4px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.overall-fill { height: 100%; background: var(--accent); }
.step-name { font-size: clamp(1.9rem, 7vw, 3.4rem); line-height: 1.1; margin: 8px 0; }
.big {
  font-size: clamp(6rem, 30vw, 14rem); font-weight: 900; line-height: 1;
  font-variant-numeric: tabular-nums; letter-spacing: -0.02em;
}
.kind-rest .big, .kind-getready .big { color: var(--accent); }
/* Prep: the exercise is on screen, its target dimmed until the hold starts. */
.big.is-waiting { opacity: 0.45; }
.prep-pill {
  align-self: center; margin: 4px 0 2px; padding: 6px 16px; border-radius: 999px;
  background: var(--accent); color: var(--accent-text); font-weight: 800; font-size: 1.15rem;
  font-variant-numeric: tabular-nums;
}
.prep-pill.is-off { visibility: hidden; } /* keeps its space, so nothing moves */
.unit { font-size: 1.4rem; font-weight: 700; margin: 4px 0; }
.cue { font-size: 1.25rem; margin: 8px auto; max-width: 32ch; }
.bar { height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin: 12px auto; width: min(100%, 520px); }
.bar-fill { height: 100%; background: var(--accent); }
.next { text-align: center; font-size: 1.15rem; margin: 6px 0 12px; }

/* Back / Pause / Done early / Skip: big enough to hit from a step away. */
.controls { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 10px; margin-bottom: 12px; }
.controls .btn { min-height: 84px; font-size: 1.2rem; }

/* The one button that matters when you're tired: the bottom of the screen. */
.player .btn.huge { min-height: max(96px, 18dvh); font-size: clamp(1.6rem, 6vw, 2.2rem); border-radius: 20px; }

.paused-banner {
  background: var(--surface-2); border: 2px solid var(--focus); border-radius: var(--radius);
  padding: 14px; margin-bottom: 12px; text-align: center;
}
.paused-title { font-size: 1.4rem; font-weight: 800; margin: 0 0 6px; }
.paused-actions { display: grid; gap: 10px; }
.is-paused .big { opacity: 0.55; }

.flash .player-main { animation: flash 600ms ease-out; }
@keyframes flash { from { background: color-mix(in srgb, var(--accent) 35%, transparent); } to { background: transparent; } }

.summary h1 { font-size: 2rem; margin: 8px 0 16px; }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin: 0 0 12px; }
.stats div { background: var(--surface); border-radius: var(--radius); padding: 14px; }
.stats dt { color: var(--muted); font-size: 0.9rem; }
.stats dd { margin: 0; font-size: 1.8rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.summary .btn.huge { margin-top: auto; min-height: 96px; }

@media (orientation: landscape) and (max-height: 520px) {
  .player { display: grid; grid-template-columns: 1.3fr 1fr; grid-template-rows: auto 1fr auto auto; column-gap: 20px; }
  .player-top { grid-column: 1 / -1; }
  .player-main { grid-column: 1; grid-row: 2 / 5; }
  .next, .paused-banner, .controls { grid-column: 2; }
  .player .btn.huge { grid-column: 2; min-height: 24dvh; }
  .big { font-size: clamp(4rem, 22vh, 9rem); }
}

/* ----------------------------------------------------------------- dialogs */

.dialog {
  border: none; border-radius: 18px; padding: 20px; max-width: min(520px, calc(100vw - 32px));
  width: 100%; background: var(--surface); color: var(--text);
}
.dialog::backdrop { background: rgb(0 0 0 / 0.6); }
.dialog h2 { margin-top: 0; }
.dialog-actions { display: grid; gap: 10px; margin-top: 16px; }
.dialog .btn { min-height: 60px; }
.sheet .instructions { white-space: pre-wrap; font-size: 1.1rem; }

.toast {
  position: fixed; left: 50%; bottom: calc(80px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 12px;
  max-width: calc(100vw - 32px); z-index: 20;
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
  .flash .player-main { box-shadow: inset 0 0 0 4px var(--accent); }
}

.copyable { display: inline-block; padding: 8px 12px; border-radius: 8px; background: var(--bg); border: 1px solid var(--line); user-select: all; word-break: break-all; }
.steps { padding-left: 1.3em; }

/* Undo after Back / Skip: sits above the big button, out of the way of the row. */
.undo-bar {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(max(96px, 18dvh) + 32px + env(safe-area-inset-bottom));
  display: flex; align-items: center; gap: 14px; z-index: 30;
  padding: 10px 10px 10px 18px; border-radius: 14px; max-width: calc(100vw - 32px);
  background: var(--text); color: var(--bg); font-weight: 600;
  box-shadow: 0 10px 30px rgb(0 0 0 / 0.35);
}
.undo-bar .btn { min-height: 48px; background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
