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

:root {
  --bg:        #0f172a;
  --surface:   #1e293b;
  --surface2:  #334155;
  --border:    #475569;
  --text:      #f8fafc;
  --muted:     #94a3b8;
  --run:       #4ade80;
  --run-dim:   rgba(74, 222, 128, .15);
  --walk:      #60a5fa;
  --walk-dim:  rgba(96, 165, 250, .15);
  --danger:    #f87171;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI',
               Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

/* ── Screens ─────────────────────────────────── */
.screen { display: none; flex-direction: column; min-height: 100dvh; min-height: 100vh; }
.screen.active { display: flex; }

/* ── Setup: header ───────────────────────────── */
#setupScreen .top {
  padding: 1.25rem 1.25rem 1rem;
  border-bottom: 1px solid var(--border);
}
#setupScreen h1 { font-size: 1.375rem; font-weight: 800; letter-spacing: -.03em; }
#setupScreen .subtitle { color: var(--muted); font-size: .8125rem; margin-top: .2rem; }

/* ── Setup: scrollable body ───────────────────── */
.scroll-body {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.25rem 1.5rem;
  -webkit-overflow-scrolling: touch;
}

.section-title {
  font-size: .6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .09em;
  color: var(--muted);
  margin-bottom: .625rem;
  margin-top: 1.25rem;
}
.section-title:first-child { margin-top: 0; }

/* ── Interval list ────────────────────────────── */
#intervalList { display: flex; flex-direction: column; gap: .5rem; margin-bottom: .625rem; }

.iv-row {
  display: flex;
  align-items: center;
  gap: .5rem;
  background: var(--surface);
  border-radius: .75rem;
  padding: .625rem .75rem;
  border: 1px solid var(--border);
}

.iv-badge {
  font-size: .6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  padding: .25rem .625rem;
  border-radius: 999px;
  flex-shrink: 0;
  min-width: 46px;
  text-align: center;
}
.iv-badge.run  { background: var(--run-dim);  color: var(--run); }
.iv-badge.walk { background: var(--walk-dim); color: var(--walk); }

.iv-time { display: flex; align-items: center; gap: .25rem; flex: 1; }

.time-input {
  width: 2.75rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: .5rem;
  color: var(--text);
  font-size: .9375rem;
  font-weight: 700;
  padding: .3125rem .25rem;
  text-align: center;
  -moz-appearance: textfield;
}
.time-input::-webkit-outer-spin-button,
.time-input::-webkit-inner-spin-button { -webkit-appearance: none; }
.time-input:focus { outline: none; border-color: var(--walk); }

.time-colon { color: var(--muted); font-weight: 700; font-size: 1rem; }
.time-unit  { font-size: .6875rem; color: var(--muted); margin-left: .125rem; }

.iv-btns { display: flex; gap: .25rem; }

.icon-btn {
  width: 1.875rem;
  height: 1.875rem;
  border-radius: .5rem;
  border: none;
  background: var(--surface2);
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .875rem;
  transition: background .12s, color .12s;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}
.icon-btn:active       { opacity: .7; }
.icon-btn.del:active   { background: rgba(248,113,113,.25); color: var(--danger); }
.icon-btn:disabled     { opacity: .28; pointer-events: none; }

/* ── Add buttons ──────────────────────────────── */
.add-row { display: flex; gap: .5rem; }

.add-btn {
  flex: 1;
  padding: .625rem;
  border-radius: .75rem;
  border: 2px dashed;
  background: transparent;
  cursor: pointer;
  font-size: .8125rem;
  font-weight: 700;
  transition: background .12s;
  -webkit-tap-highlight-color: transparent;
}
.add-btn.run  { color: var(--run);  border-color: var(--run); }
.add-btn.run:active  { background: var(--run-dim); }
.add-btn.walk { color: var(--walk); border-color: var(--walk); }
.add-btn.walk:active { background: var(--walk-dim); }

/* ── Cycles card ──────────────────────────────── */
.cycles-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border-radius: .75rem;
  padding: .75rem 1rem;
  border: 1px solid var(--border);
}
.cycles-label { color: var(--muted); font-size: .875rem; }
.cycles-ctrl  { display: flex; align-items: center; gap: .75rem; }
.cycles-val   { font-size: 1.375rem; font-weight: 800; min-width: 2rem; text-align: center; }

/* ── Volume card ──────────────────────────────── */
.volume-card {
  display: flex;
  align-items: center;
  gap: .75rem;
  background: var(--surface);
  border-radius: .75rem;
  padding: .75rem 1rem;
  border: 1px solid var(--border);
}

.volume-icon { font-size: 1.125rem; flex-shrink: 0; }

.volume-slider {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  border-radius: 999px;
  background: var(--surface2);
  outline: none;
  cursor: pointer;
}
/* Thumb — WebKit / Blink */
.volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--walk);
  cursor: pointer;
  box-shadow: 0 0 0 3px rgba(96,165,250,.25);
  transition: transform .1s;
}
.volume-slider:active::-webkit-slider-thumb { transform: scale(1.2); }
/* Thumb — Firefox */
.volume-slider::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: none;
  background: var(--walk);
  cursor: pointer;
}

.volume-pct {
  font-size: .875rem;
  font-weight: 700;
  min-width: 3rem;
  text-align: right;
  color: var(--walk);
}

.step-btn {
  width: 2rem;
  height: 2rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-size: 1.125rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}
.step-btn:active { opacity: .7; }

/* ── Summary card ─────────────────────────────── */
.summary-card {
  background: var(--surface);
  border-radius: .75rem;
  padding: .875rem 1rem;
  border: 1px solid var(--border);
}
.summary-grid  { display: flex; gap: 1.5rem; }
.summary-val   { font-size: 1.0625rem; font-weight: 700; }
.summary-lbl   { font-size: .625rem; text-transform: uppercase; letter-spacing: .09em; color: var(--muted); margin-top: .1rem; }

/* ── Empty state ──────────────────────────────── */
.empty       { text-align: center; padding: 1.5rem 1rem; color: var(--muted); }
.empty-icon  { font-size: 2rem; margin-bottom: .5rem; }
.empty-text  { font-size: .875rem; }

/* ── Setup: footer ────────────────────────────── */
#setupScreen .foot {
  padding: 1rem 1.25rem;
  padding-bottom: max(1rem, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
}

.start-btn {
  width: 100%;
  padding: .9375rem;
  border-radius: .875rem;
  border: none;
  background: var(--run);
  color: #0a1929;
  font-size: 1.0625rem;
  font-weight: 800;
  cursor: pointer;
  letter-spacing: -.02em;
  transition: opacity .12s, transform .1s;
  -webkit-tap-highlight-color: transparent;
}
.start-btn:active   { transform: scale(.98); opacity: .9; }
.start-btn:disabled { opacity: .35; cursor: not-allowed; transform: none; }

/* ── Workout: header ──────────────────────────── */
.wk-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .875rem 1.25rem;
  padding-top: max(.875rem, env(safe-area-inset-top));
}

.stop-btn {
  padding: .4375rem .875rem;
  border-radius: .625rem;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  font-size: .8125rem;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background .12s, color .12s, border-color .12s;
}
.stop-btn:active {
  background: rgba(248,113,113,.15);
  color: var(--danger);
  border-color: var(--danger);
}

.cycle-info { font-size: .8125rem; font-weight: 600; color: var(--muted); }

/* ── Workout: main ────────────────────────────── */
.wk-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  padding: 1.5rem;
}

.phase-pill {
  font-size: .875rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .12em;
  padding: .4375rem 1.375rem;
  border-radius: 999px;
}
.phase-pill.run  { background: var(--run-dim);  color: var(--run); }
.phase-pill.walk { background: var(--walk-dim); color: var(--walk); }

/* ── Ring timer ───────────────────────────────── */
.ring-wrap { position: relative; width: 240px; height: 240px; }
.ring-wrap svg { transform: rotate(-90deg); }

.ring-track { fill: none; stroke: var(--surface2); stroke-width: 14; }
.ring-bar   {
  fill: none;
  stroke-width: 14;
  stroke-linecap: round;
  /* No dashoffset transition — requestAnimationFrame handles smooth sweep */
  transition: stroke .3s ease;
}

.ring-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.ring-time {
  font-size: 3.5rem;
  font-weight: 800;
  letter-spacing: -.05em;
  line-height: 1;
}
.ring-lbl { font-size: .625rem; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); margin-top: .25rem; }

/* ── Workout: next up ─────────────────────────── */
.next-wrap { text-align: center; }
.next-lbl  { font-size: .625rem; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); margin-bottom: .1875rem; }
.next-val  { font-size: .9375rem; font-weight: 600; }

/* ── Progress dots ────────────────────────────── */
.dots-wrap {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: .3125rem;
  max-width: 280px;
}
.dot           { width: 9px; height: 9px; border-radius: 999px; background: var(--surface2); transition: background .3s; }
.dot.done      { background: var(--border); }
.dot.cur-run   { background: var(--run); }
.dot.cur-walk  { background: var(--walk); }

/* ── Workout: footer ──────────────────────────── */
.wk-foot {
  padding: 1rem 1.25rem;
  padding-bottom: max(1rem, env(safe-area-inset-bottom));
}

.pause-btn {
  width: 100%;
  padding: .9375rem;
  border-radius: .875rem;
  border: none;
  font-size: 1.0625rem;
  font-weight: 800;
  cursor: pointer;
  letter-spacing: -.02em;
  transition: background .15s, color .15s, transform .1s;
  -webkit-tap-highlight-color: transparent;
}
.pause-btn:active  { transform: scale(.98); }
.pause-btn.running { background: var(--surface2); color: var(--text); }
.pause-btn.paused  { background: var(--run);      color: #0a1929; }

/* ── Complete screen ──────────────────────────── */
#completeScreen {
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 1.5rem;
  padding: 2rem 1.5rem;
}

.done-icon  { font-size: 4rem; }
.done-title { font-size: 2.25rem; font-weight: 800; letter-spacing: -.05em; line-height: 1.1; }

.done-stats     { display: flex; gap: 2rem; }
.done-stat-val  { font-size: 1.625rem; font-weight: 800; letter-spacing: -.03em; }
.done-stat-lbl  { font-size: .625rem; text-transform: uppercase; letter-spacing: .09em; color: var(--muted); margin-top: .2rem; }

.again-btn {
  padding: .9375rem 2.5rem;
  border-radius: .875rem;
  border: none;
  background: var(--run);
  color: #0a1929;
  font-size: 1.0625rem;
  font-weight: 800;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: opacity .12s, transform .1s;
}
.again-btn:active { opacity: .85; transform: scale(.98); }
