/* ============ Tokens ============ */
:root {
  --bg: #ffffff;
  --ink: #0b1d13;
  --ink-2: #33463b;
  --muted: #627268;
  --line: #e2eae5;
  --soft: #f4f8f5;

  --green: #16a34a;
  --green-deep: #166534;
  --green-pale: #d3f5df;
  --green-wash: #effcf3;

  --red: #dc2626;
  --red-pale: #fde0e0;
  --red-wash: #fef3f3;

  /* Phase colours — swapped per phase below */
  --phase: var(--ink);
  --phase-pale: #e4ebe7;
  --phase-wash: var(--soft);

  --radius: 24px;
  --ring: min(72vw, 320px, 40vh);
  --ease-out: cubic-bezier(.23, 1, .32, 1);
  --ease-sheet: cubic-bezier(.32, .72, 0, 1);
  color-scheme: light;
}
@supports (height: 1dvh) {
  :root { --ring: min(72vw, 320px, 40dvh); }
}

body[data-phase="work"] { --phase: var(--green); --phase-pale: var(--green-pale); --phase-wash: var(--green-wash); }
body[data-phase="rest"] { --phase: var(--red);   --phase-pale: var(--red-pale);   --phase-wash: var(--red-wash); }
body[data-phase="done"] { --phase: var(--green-deep); --phase-pale: var(--green-pale); --phase-wash: var(--green-wash); }

/* ============ Base ============ */
*, *::before, *::after { box-sizing: border-box; margin: 0; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Inter, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
  overscroll-behavior-y: none;
}
body.sheet-open { overflow: hidden; }
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; -webkit-user-select: none; user-select: none; }
svg { stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
svg .fill { fill: currentColor; stroke: none; }
:focus-visible { outline: 3px solid rgba(22, 163, 74, .45); outline-offset: 2px; }

.app {
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  padding: 0 16px calc(100px + env(safe-area-inset-bottom));
}

/* ============ Top bar ============ */
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 10px 0 8px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 17px; letter-spacing: -.01em; }
.brand-mark { width: 28px; height: 28px; border-radius: 8px; display: block; }
.top-actions { display: flex; gap: 8px; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 50%;
  border: 1px solid var(--line); background: #fff;
  display: grid; place-items: center;
  transition: transform .12s var(--ease-out), background-color .2s;
}
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn:active { transform: scale(.94); }
.icon-btn .i-off { display: none; }
.icon-btn.is-muted .i-on { display: none; }
.icon-btn.is-muted .i-off { display: block; }
.icon-btn.is-muted { color: var(--red); border-color: var(--red-pale); background: var(--red-wash); }

/* ============ Cycle header ============ */
.cycle { text-align: center; padding: 6px 0 14px; }
.cycle-pill {
  display: inline-block;
  padding: 10px 22px;
  border-radius: 999px;
  background: var(--green-deep);
  color: #fff;
  font-size: clamp(20px, 5.6vw, 26px);
  font-weight: 800;
  letter-spacing: -.01em;
  font-variant-numeric: tabular-nums;
}
.cycle-bar { display: flex; gap: 6px; max-width: 260px; margin: 12px auto 0; }
.cyc { flex: 1; height: 6px; border-radius: 99px; background: var(--line); transition: background-color .3s ease; }
.cyc.done { background: var(--green); }
.cyc.current { background: var(--phase); }

/* ============ Interval card ============ */
.interval-card {
  background: var(--phase-wash);
  border: 2px solid var(--phase-pale);
  border-radius: var(--radius);
  padding: 20px 16px 18px;
  display: flex; flex-direction: column; align-items: center;
  transition: background-color .35s ease, border-color .35s ease;
}
.ring-wrap { position: relative; width: var(--ring); aspect-ratio: 1 / 1; container-type: inline-size; }
.ring { display: block; width: 100%; height: 100%; }
.ring circle { fill: none; stroke-width: 14; stroke-linecap: butt; }
.ring .track { stroke: #ebf0ed; }
.ring .track-work { stroke: var(--green-pale); }
.ring .track-rest { stroke: var(--red-pale); }
.ring .arc-work { stroke: var(--green); }
.ring .arc-rest { stroke: var(--red); }
.ring .arc-plain { stroke: var(--phase); }

.ring-center {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px;
}
.phase-label {
  font-size: 13px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase;
  color: #fff; background: var(--phase);
  padding: 6px 12px; border-radius: 99px;
  transition: background-color .35s ease;
}
.phase-time {
  font-size: 76px;
  font-size: 30cqi;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -.04em;
  font-variant-numeric: tabular-nums;
  color: var(--phase);
  margin-top: 6px;
  transition: color .35s ease;
}
.phase-sub { font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .12em; min-height: 1em; }
body[data-state="paused"] .phase-time { animation: blink 1.4s ease-in-out infinite; }
@keyframes blink { 50% { opacity: .35; } }

.exercise { text-align: center; margin-top: 14px; width: 100%; }
.ex-eyebrow { font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .1em; }
.ex-name {
  font-size: clamp(24px, 7vw, 32px); font-weight: 800; letter-spacing: -.02em;
  line-height: 1.15; margin-top: 3px; overflow-wrap: anywhere;
}
.ex-next { font-size: 15px; color: var(--ink-2); margin-top: 5px; min-height: 1.3em; }

.ex-dots { display: flex; flex-wrap: wrap; justify-content: center; gap: 2px; margin-top: 8px; }
/* Each dot is a 40px tap target with a small visible dot inside */
.dot {
  width: 40px; height: 40px; padding: 0; border: 0; border-radius: 50%;
  background: transparent; display: grid; place-items: center;
}
.dot::before {
  content: ""; width: 13px; height: 13px; border-radius: 50%;
  background: #d9e2dc;
  transition: background-color .3s, box-shadow .3s, transform .15s var(--ease-out);
}
.dot.done::before { background: var(--green); }
.dot.current::before { background: var(--phase); box-shadow: 0 0 0 4px var(--phase-pale); }
.dot.next::before { background: #fff; box-shadow: inset 0 0 0 2.5px var(--green); }
.dot:active::before { transform: scale(1.35); }
body[data-state="done"] .dot { pointer-events: none; }
@media (hover: hover) and (pointer: fine) {
  .dot:hover::before { transform: scale(1.25); }
}

/* ============ Session card ============ */
.session-card { margin-top: 14px; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 18px 16px; }
.session-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
.eyebrow { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .1em; }
.total-time { font-size: 40px; font-weight: 800; letter-spacing: -.03em; line-height: 1.05; font-variant-numeric: tabular-nums; margin-top: 2px; }
.session-meta { font-size: 15px; color: var(--muted); font-variant-numeric: tabular-nums; padding-bottom: 6px; }
.progress { height: 8px; border-radius: 99px; background: var(--line); overflow: hidden; margin-top: 12px; }
.progress-fill { height: 100%; background: var(--green); transform-origin: left center; transform: scaleX(0); }

/* ============ Controls ============ */
.controls {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  background: rgba(255, 255, 255, .94);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding: 12px max(16px, env(safe-area-inset-right)) calc(12px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
.controls-inner { max-width: 520px; margin: 0 auto; display: grid; grid-template-columns: 1.3fr 1fr 1fr; gap: 10px; }
.btn {
  height: 58px; border: 0; border-radius: 18px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-size: 17px; font-weight: 700;
  transition: transform .12s var(--ease-out), opacity .2s ease, background-color .2s ease;
}
.btn svg { width: 20px; height: 20px; flex: none; }
.btn:active:not(:disabled) { transform: scale(.97); }
.btn:disabled { opacity: .35; cursor: default; }
.btn-play { background: var(--green); color: #fff; }
.btn-pause { background: var(--ink); color: #fff; }
.btn-reset { background: #fff; color: var(--ink); box-shadow: inset 0 0 0 2px var(--line); }

@media (hover: hover) and (pointer: fine) {
  .btn-play:hover:not(:disabled) { background: #15903f; }
  .btn-pause:hover:not(:disabled) { background: #1c3326; }
  .btn-reset:hover:not(:disabled), .icon-btn:hover { background: var(--soft); }
}

/* ============ Setup sheet ============ */
.sheet {
  position: fixed; inset: 0; z-index: 20;
  background: #fff;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  transform: translateY(100%);
  visibility: hidden;
  transition: transform .34s var(--ease-sheet), visibility 0s linear .34s;
}
.sheet.open { transform: none; visibility: visible; transition: transform .34s var(--ease-sheet); }

.sheet-head {
  position: sticky; top: 0; z-index: 1;
  display: flex; align-items: center; justify-content: space-between;
  max-width: 520px; margin: 0 auto;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  background: rgba(255, 255, 255, .95);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
}
.sheet-head h1 { font-size: 22px; font-weight: 800; letter-spacing: -.02em; }
.btn-done {
  height: 40px; padding: 0 18px; border: 0; border-radius: 99px;
  background: var(--green); color: #fff; font-weight: 700; font-size: 16px;
  transition: transform .12s var(--ease-out);
}
.btn-done:active { transform: scale(.96); }

.sheet-body { max-width: 520px; margin: 0 auto; padding: 4px 16px calc(32px + env(safe-area-inset-bottom)); }
fieldset { border: 0; padding: 0; min-width: 0; }
fieldset:disabled { opacity: .45; }

.lock-note {
  background: var(--red-wash); color: #8f1d1d;
  border: 1px solid var(--red-pale); border-radius: 14px;
  padding: 12px 14px; font-size: 15px; margin-bottom: 14px;
}

.block { padding: 18px 0; border-top: 1px solid var(--line); }
.block:first-child { border-top: 0; padding-top: 6px; }
.block h2 {
  font-size: 13px; font-weight: 800; color: var(--muted);
  text-transform: uppercase; letter-spacing: .12em;
  display: flex; align-items: center; gap: 8px;
}
.count {
  display: inline-grid; place-items: center; min-width: 22px; height: 22px; padding: 0 6px;
  border-radius: 99px; background: var(--green-pale); color: var(--green-deep);
  font-size: 12px; letter-spacing: 0;
}
.hint { font-size: 14px; color: var(--muted); margin-top: 6px; line-height: 1.4; }

/* Steppers */
.steppers { margin-top: 8px; }
.stepper { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; }
.stepper + .stepper { border-top: 1px solid var(--line); }
.stepper-label { display: block; font-size: 17px; font-weight: 700; }
.stepper-hint { display: block; font-size: 13px; color: var(--muted); margin-top: 1px; }
.stepper-ctrl { display: flex; align-items: center; gap: 6px; flex: none; }
.step-btn {
  width: 44px; height: 44px; border-radius: 50%; border: 0;
  background: var(--soft); color: var(--green-deep);
  display: grid; place-items: center;
  transition: transform .12s var(--ease-out), background-color .2s;
}
.step-btn svg { width: 20px; height: 20px; stroke-width: 2.4; }
.step-btn:active:not(:disabled) { transform: scale(.92); background: var(--green-pale); }
.step-val { min-width: 78px; text-align: center; font-size: 17px; font-weight: 800; font-variant-numeric: tabular-nums; }
.total-line {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 10px; padding: 14px 16px; border-radius: 16px;
  background: var(--green-wash); color: var(--green-deep); font-weight: 700;
}
.total-line strong { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }

/* Session list */
.session-list, .library-list { list-style: none; padding: 0; margin-top: 12px; display: grid; gap: 8px; }
.s-item {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 8px 8px 12px; border-radius: 16px;
  background: #fff; border: 1px solid var(--line);
}
.s-num {
  flex: none; width: 28px; height: 28px; border-radius: 50%;
  background: var(--green); color: #fff; font-weight: 800; font-size: 14px;
  display: grid; place-items: center; font-variant-numeric: tabular-nums;
}
.s-name { flex: 1; min-width: 0; font-weight: 700; font-size: 16px; overflow-wrap: anywhere; }
.s-actions { display: flex; gap: 2px; flex: none; }
.icon-sm {
  width: 40px; height: 40px; border-radius: 12px; border: 0; background: transparent;
  display: grid; place-items: center; color: var(--ink-2);
  transition: background-color .15s, transform .12s var(--ease-out);
}
.icon-sm svg { width: 20px; height: 20px; }
.icon-sm:active:not(:disabled) { transform: scale(.92); background: var(--soft); }
.icon-sm:disabled { opacity: .25; }
.icon-sm.danger { color: var(--red); }
.empty { padding: 16px; border-radius: 16px; border: 1.5px dashed var(--line); color: var(--muted); font-size: 15px; text-align: center; }

/* Library */
.add-form { display: flex; gap: 8px; margin-top: 12px; }
.add-form input {
  flex: 1; min-width: 0; height: 48px; padding: 0 14px;
  border: 1.5px solid var(--line); border-radius: 14px;
  font: inherit; font-size: 16px; color: var(--ink); background: #fff;
}
.add-form input:focus { outline: none; border-color: var(--green); box-shadow: 0 0 0 3px var(--green-pale); }
.btn-add {
  height: 48px; padding: 0 20px; border: 0; border-radius: 14px;
  background: var(--ink); color: #fff; font-weight: 700; font-size: 16px;
  transition: transform .12s var(--ease-out);
}
.btn-add:active:not(:disabled) { transform: scale(.96); }

.lib-item { display: flex; align-items: center; gap: 4px; border-radius: 16px; border: 1px solid var(--line); background: #fff; transition: background-color .2s, border-color .2s; }
.lib-item.on { background: var(--green-wash); border-color: var(--green-pale); }
.lib-toggle {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px;
  padding: 12px; border: 0; background: transparent; text-align: left;
  font-size: 16px; font-weight: 600;
}
.lib-toggle .name { overflow-wrap: anywhere; }
.check {
  flex: none; width: 26px; height: 26px; border-radius: 50%;
  border: 2px solid #cfd9d3; display: grid; place-items: center; color: #fff;
  transition: background-color .2s, border-color .2s;
}
.check svg { width: 16px; height: 16px; stroke-width: 3; opacity: 0; transition: opacity .15s; }
.lib-item.on .check { background: var(--green); border-color: var(--green); }
.lib-item.on .check svg { opacity: 1; }
.lib-item .icon-sm { margin-right: 6px; }

/* Backup */
.backup-row { display: flex; gap: 10px; margin-top: 12px; }
.btn-ghost {
  flex: 1; height: 48px; border-radius: 14px; border: 0;
  background: #fff; box-shadow: inset 0 0 0 2px var(--line);
  font-weight: 700; font-size: 16px;
  transition: transform .12s var(--ease-out);
}
.btn-ghost:active:not(:disabled) { transform: scale(.97); }

/* ============ Back button, mode chip, difficulty ============ */
a.icon-btn { color: inherit; text-decoration: none; }
.brand .icon-btn { flex: none; }

.mode-chip {
  display: inline-block; margin-top: 10px;
  padding: 5px 12px; border-radius: 99px;
  background: var(--green-wash); color: var(--green-deep);
  border: 1px solid var(--green-pale);
  font-size: 13px; font-weight: 700;
}

.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.seg-btn {
  display: flex; flex-direction: column; align-items: flex-start; gap: 3px;
  padding: 14px; border-radius: 16px; text-align: left;
  background: #fff; border: 2px solid var(--line);
  transition: border-color .2s, background-color .2s, transform .12s var(--ease-out);
}
.seg-btn:active:not(:disabled) { transform: scale(.98); }
.seg-btn[aria-pressed="true"] { border-color: var(--green); background: var(--green-wash); }
.seg-title { font-size: 17px; font-weight: 800; }
.seg-desc { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.seg-btn[aria-pressed="true"] .seg-title { color: var(--green-deep); }

/* Plan presets (HIIT setup) */
.preset-group { margin-top: 14px; }
.preset-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.preset-group-title { font-size: 17px; font-weight: 800; }
.preset-group-sub { font-size: 13px; font-weight: 600; color: var(--muted); }
.preset-list { display: grid; gap: 8px; }
.preset-btn {
  display: flex; flex-direction: column; align-items: flex-start; gap: 3px;
  width: 100%; padding: 12px 14px; border-radius: 16px; text-align: left;
  background: #fff; border: 2px solid var(--line);
  transition: border-color .2s, background-color .2s, transform .12s var(--ease-out);
}
.preset-btn:active:not(:disabled) { transform: scale(.98); background: var(--green-wash); }
.preset-btn[aria-pressed="true"] { border-color: var(--green); background: var(--green-wash); }
.preset-title { font-size: 16px; font-weight: 800; }
.preset-btn[aria-pressed="true"] .preset-title { color: var(--green-deep); }
.preset-btn[aria-pressed="true"] .preset-title::after { content: "  ✓ active"; font-size: 13px; font-weight: 700; }
.preset-desc { font-size: 13.5px; color: var(--ink-2); line-height: 1.4; }

.resume-note {
  margin: 10px auto 0; max-width: 340px;
  padding: 10px 14px; border-radius: 14px;
  background: var(--green-wash); border: 1px solid var(--green-pale);
  color: var(--green-deep); font-size: 14px; line-height: 1.35;
}
.resume-note[hidden] { display: none; }

/* ============ Strength page ============ */
/* Exercise bar on top is tappable: bigger hit area, same 6px bar */
.cycle-bar.tappable { gap: 4px; margin-top: 6px; max-width: 300px; }
.cycle-bar.tappable .cyc {
  height: 26px; padding: 0; border: 0; background: transparent;
  display: flex; align-items: center;
}
.cycle-bar.tappable .cyc::before {
  content: ""; flex: 1; height: 6px; border-radius: 99px;
  background: var(--line); transition: background-color .3s ease;
}
.cycle-bar.tappable .cyc.done::before { background: var(--green); }
.cycle-bar.tappable .cyc.current::before { background: var(--phase); }
body[data-state="done"] .cycle-bar.tappable .cyc { pointer-events: none; }

.s-item-col { flex-direction: column; align-items: stretch; gap: 8px; padding: 10px 8px 10px 12px; }
.s-row { display: flex; align-items: center; gap: 12px; }
.s-dose { display: flex; gap: 8px; padding-left: 40px; }
.mini {
  flex: 1; display: flex; align-items: center; justify-content: space-between; gap: 2px;
  background: var(--soft); border-radius: 12px; padding: 4px 4px 4px 10px;
}
.mini-label { font-size: 13px; font-weight: 700; color: var(--muted); margin-right: auto; }
.mini .step-btn { width: 34px; height: 34px; background: #fff; }
.mini .step-btn svg { width: 16px; height: 16px; }
.mini output { min-width: 34px; text-align: center; font-weight: 800; font-size: 16px; font-variant-numeric: tabular-nums; }
.lib-meta { margin-left: auto; padding-left: 8px; color: var(--muted); font-size: 14px; font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }

/* ============ Home (entry page) ============ */
body.home { display: flex; }
.home-wrap {
  width: 100%; max-width: 520px; margin: auto;
  padding: 32px 16px calc(32px + env(safe-area-inset-bottom));
}
.home-head { text-align: center; margin-bottom: 28px; }
.home-logo { display: block; width: 72px; height: 72px; margin: 0 auto 16px; border-radius: 18px; }
.home-head h1 { font-size: clamp(30px, 8vw, 38px); font-weight: 800; letter-spacing: -.03em; }
.home-head p { margin-top: 6px; font-size: 17px; color: var(--muted); }

.choices { display: grid; gap: 14px; }
.choice {
  display: flex; align-items: center; gap: 16px;
  padding: 20px 18px; border-radius: var(--radius);
  background: #fff; border: 2px solid var(--line);
  color: inherit; text-decoration: none;
  -webkit-tap-highlight-color: transparent;
  transition: border-color .2s, background-color .2s, transform .12s var(--ease-out);
}
.choice:active { transform: scale(.98); background: var(--green-wash); border-color: var(--green-pale); }
.choice-icon {
  flex: none; width: 60px; height: 60px; border-radius: 18px;
  display: grid; place-items: center;
  background: var(--green); color: #fff;
}
.choice-icon svg { width: 32px; height: 32px; stroke-width: 2.4; }
.choice-icon svg.runner { stroke-width: 44; }
.choice-text { flex: 1; min-width: 0; }
.choice-title { display: block; font-size: 20px; font-weight: 800; letter-spacing: -.01em; }
.choice-desc { display: block; margin-top: 3px; font-size: 14px; color: var(--muted); line-height: 1.35; }
.choice-arrow { flex: none; width: 22px; height: 22px; color: var(--muted); }
@media (hover: hover) and (pointer: fine) {
  .choice:hover { border-color: var(--green-pale); background: var(--green-wash); }
}

/* ============ Larger screens ============ */
@media (min-width: 700px) {
  :root { --ring: min(340px, 46vh); }
  .app { padding-top: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0s !important; animation: none !important; }
}
