:root {
  --bg: #101418;
  --surface: #182028;
  --surface-2: #212b35;
  --line: #2c3844;
  --text: #eef2f5;
  --muted: #8d9aa7;
  --accent: #ff7a1a;
  --accent-ink: #1a0d02;
  --lvl-easy: #3fb68b;
  --lvl-moderate: #f2b233;
  --lvl-hard: #ef4d4d;
  --danger: #ef4d4d;
  --radius: 16px;
  --tabbar-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(var(--tabbar-h) + var(--safe-b) + 16px);
}

body.running { overflow: hidden; }

button { font: inherit; color: inherit; cursor: pointer; }

svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Layout ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  padding: calc(12px + var(--safe-t)) 16px 12px;
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(10px);
}
.topbar h1 { margin: 0; font-size: 22px; letter-spacing: -0.02em; }
.topbar h1 span { color: var(--accent); }

main { max-width: 640px; margin: 0 auto; padding: 0 16px; }

.view { display: none; }
.view.active { display: block; }

.section-title {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 24px 4px 10px;
}

.card {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

.meta { color: var(--muted); font-size: 14px; margin: 0; }

/* ---------- Week summary ---------- */

.week-stats { display: grid; grid-template-columns: repeat(3, 1fr); text-align: center; }
.week-stats b { display: block; font-size: 26px; font-variant-numeric: tabular-nums; }
.week-stats small { color: var(--muted); }
.week-days { display: flex; justify-content: space-between; margin-top: 14px; gap: 4px; }
.week-days span {
  flex: 1;
  text-align: center;
  font-size: 12px;
  padding: 6px 0;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
}
.week-days span.today { outline: 1px solid var(--muted); }
.week-days span.done { background: var(--accent); color: var(--accent-ink); font-weight: 600; }

/* ---------- Program cards ---------- */

.program { transition: transform .1s; }
.program:active { transform: scale(0.98); }
.program-head { display: flex; justify-content: space-between; align-items: center; }
.program h3 { margin: 0; font-size: 18px; }
.program p { margin: 4px 0 12px; color: var(--muted); font-size: 14px; }
.program .go { font-size: 28px; color: var(--muted); line-height: 1; }

.mini-timeline, .timeline {
  display: flex;
  gap: 1px;
  height: 10px;
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 10px;
}
.mini-timeline i, .timeline i { display: block; min-width: 1px; }
.timeline.big { height: 16px; margin: 12px 0; }

.tip h3 { margin: 0 0 8px; font-size: 16px; }
.tip ul { margin: 0; padding-left: 20px; color: var(--muted); }
.tip b { color: var(--text); }

/* ---------- Buttons ---------- */

.btn {
  display: block;
  border: 0;
  border-radius: 14px;
  padding: 14px 18px;
  font-weight: 600;
  font-size: 17px;
  background: var(--surface-2);
}
.btn.full { width: 100%; margin-bottom: 12px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; border: 1px solid var(--line); }
.btn.danger { background: transparent; border: 1px solid color-mix(in srgb, var(--danger) 50%, transparent); color: var(--danger); }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 0;
  background: var(--surface-2);
  flex: none;
}
.icon-btn.small { width: 32px; height: 32px; background: transparent; color: var(--muted); }
.icon-btn.small svg { width: 18px; height: 18px; }

/* ---------- Tab bar ---------- */

.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 10;
  display: flex;
  justify-content: space-around;
  height: calc(var(--tabbar-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 12px;
}
.tab.active { color: var(--accent); }

/* ---------- Sheet (program details) ---------- */

.sheet {
  width: 100%;
  max-width: 640px;
  max-height: 92vh;
  margin: auto auto 0;
  padding: 0;
  border: 0;
  border-radius: 22px 22px 0 0;
  background: var(--surface);
  color: var(--text);
}
.sheet::backdrop { background: rgb(0 0 0 / 0.6); }
.sheet[open] { animation: slide-up .22s ease-out; }
@keyframes slide-up { from { transform: translateY(40px); opacity: 0; } }

.sheet-inner { padding: 20px 16px calc(16px + var(--safe-b)); }
.sheet-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.sheet-head h2 { margin: 0; font-size: 22px; }
.sheet h4 { margin: 20px 0 8px; font-size: 15px; }
.sheet h4 small { color: var(--muted); font-weight: 400; }
.sheet .sticky { position: sticky; bottom: 0; margin-top: 20px; box-shadow: 0 -12px 20px var(--surface); }

.rows { list-style: none; margin: 0; padding: 0; }
.rows li { display: flex; gap: 10px; align-items: baseline; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 15px; }
.rows li:last-child { border-bottom: 0; }
.rows .when { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 88px; }
.rows.legend li { font-size: 14px; color: var(--muted); }
.rows.legend b { color: var(--text); }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; transform: translateY(1px); }

.steppers { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.stepper { background: var(--surface-2); border-radius: 12px; padding: 10px 6px; text-align: center; }
.stepper-label { font-size: 13px; color: var(--muted); }
.stepper-ctrl { display: flex; align-items: center; justify-content: center; gap: 4px; margin-top: 4px; }
.stepper-ctrl output { font-size: 20px; font-weight: 700; min-width: 28px; font-variant-numeric: tabular-nums; }
.stepper-ctrl small { color: var(--muted); font-size: 12px; margin-right: 2px; }
.stepper-ctrl button {
  width: 32px; height: 32px; border-radius: 50%; border: 0;
  background: var(--line); font-size: 20px; line-height: 1;
}

/* ---------- Exercises ---------- */

.chips { display: flex; gap: 8px; margin: 8px 0 16px; overflow-x: auto; }
.chip {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 14px;
  white-space: nowrap;
}
.chip.active { background: var(--text); color: var(--bg); border-color: var(--text); }

details.ex summary {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 8px;
  list-style: none;
  cursor: pointer;
  font-weight: 600;
}
details.ex summary::-webkit-details-marker { display: none; }
details.ex summary small { width: 100%; color: var(--muted); font-weight: 400; font-size: 13px; }
details.ex p { margin: 10px 0 0; font-size: 15px; }
details.ex .variant { color: var(--muted); font-size: 14px; margin-top: 6px; }
.sheet details.ex { padding: 10px 0; border-bottom: 1px solid var(--line); }

.badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
}
.badge.dumbbell { background: color-mix(in srgb, var(--accent) 20%, transparent); color: var(--accent); }
.badge.ok { background: color-mix(in srgb, var(--lvl-easy) 20%, transparent); color: var(--lvl-easy); }
.badge.partial { background: color-mix(in srgb, var(--lvl-moderate) 20%, transparent); color: var(--lvl-moderate); }

/* ---------- History ---------- */

.history-item { display: flex; align-items: center; gap: 12px; }
.history-item > div:first-child { flex: 1; min-width: 0; }
.history-item h3 { margin: 0 0 2px; font-size: 16px; }
.history-right { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; text-align: right; }
.empty { color: var(--muted); text-align: center; padding: 24px; }

/* ---------- Settings ---------- */

.settings { padding: 4px 16px; }
.settings .row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}
.settings .row:last-child { border-bottom: 0; }
.settings small { display: block; color: var(--muted); font-size: 13px; }
.settings input[type="number"] {
  width: 90px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  text-align: right;
}
.settings input[type="checkbox"] {
  appearance: none;
  width: 50px;
  height: 30px;
  border-radius: 999px;
  background: var(--line);
  position: relative;
  flex: none;
  cursor: pointer;
  transition: background .15s;
}
.settings input[type="checkbox"]::after {
  content: "";
  position: absolute;
  top: 3px; left: 3px;
  width: 24px; height: 24px;
  border-radius: 50%;
  background: #fff;
  transition: transform .15s;
}
.settings input[type="checkbox"]:checked { background: var(--accent); }
.settings input[type="checkbox"]:checked::after { transform: translateX(20px); }
.fineprint { color: var(--muted); font-size: 13px; }

/* ---------- Runner ---------- */

.runner {
  --lvl: var(--muted);
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  padding: calc(10px + var(--safe-t)) 16px calc(16px + var(--safe-b));
  background:
    radial-gradient(120% 60% at 50% 0%, color-mix(in srgb, var(--lvl) 35%, transparent), transparent 70%),
    var(--bg);
  transition: background .4s;
  overflow-y: auto;
}
.runner[hidden] { display: none; }
.runner[data-level="easy"], .runner[data-level="rest"] { --lvl: var(--lvl-easy); }
.runner[data-level="moderate"] { --lvl: var(--lvl-moderate); }
.runner[data-level="hard"], .runner[data-level="work"] { --lvl: var(--lvl-hard); }

.runner-top { display: flex; align-items: center; gap: 12px; }
.runner-title { flex: 1; text-align: center; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.runner .mute { display: none; }
.runner.muted .mute { display: inline; }
.runner.muted .wave { display: none; }

.runner .timeline { position: relative; height: 12px; margin: 16px 0 0; overflow: visible; }
.runner .timeline i { border-radius: 2px; opacity: .85; }
.playhead {
  position: absolute;
  top: -4px; bottom: -4px;
  width: 3px;
  margin-left: -1.5px;
  background: var(--text);
  border-radius: 2px;
  box-shadow: 0 0 0 2px var(--bg);
}

.runner-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 16px 0;
  min-height: 0;
}
.step-tag {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--lvl);
}
.step-label { font-size: clamp(26px, 7vw, 40px); font-weight: 800; margin: 4px 0 12px; letter-spacing: -0.02em; }

.ring { position: relative; width: min(72vw, 42vh, 320px); aspect-ratio: 1; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 8; }
.ring-bg { stroke: var(--surface-2); }
.ring-fg { stroke: var(--lvl); stroke-linecap: round; transition: stroke-dashoffset .2s linear, stroke .4s; }
.ring-time {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: clamp(56px, 17vw, 96px);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
}
.runner.paused .ring-time { animation: blink 1.2s steps(2) infinite; }
@keyframes blink { 50% { opacity: .35; } }

.step-hint { max-width: 420px; color: var(--muted); font-size: 15px; margin: 14px 0 0; min-height: 2.9em; }

.next-step {
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  font-size: 15px;
}
.next-step .lvl { font-weight: 600; }

.totals { display: grid; grid-template-columns: repeat(3, 1fr); text-align: center; margin: 14px 0; }
.totals small { display: block; color: var(--muted); font-size: 12px; }
.totals b { font-size: 20px; font-variant-numeric: tabular-nums; }

.controls { display: flex; align-items: center; justify-content: center; gap: 28px; }
.controls .icon-btn { width: 56px; height: 56px; }
.play-btn {
  width: 80px; height: 80px;
  border-radius: 50%;
  border: 0;
  background: var(--text);
  color: var(--bg);
  display: grid;
  place-items: center;
}
.play-btn svg { width: 32px; height: 32px; fill: currentColor; stroke: none; }
.play-btn .i-play { display: none; }
.runner.paused .play-btn .i-play { display: block; }
.runner.paused .play-btn .i-pause { display: none; }

.finish {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgb(0 0 0 / 0.7);
}
.finish[hidden] { display: none; }
.finish-card {
  width: 100%;
  max-width: 360px;
  text-align: center;
  background: var(--surface);
  border-radius: 22px;
  padding: 28px 20px 12px;
}
.finish-card h2 { margin: 12px 0 4px; }
.finish-card p { color: var(--muted); margin: 0 0 20px; }
.finish-badge {
  width: 64px; height: 64px;
  margin: 0 auto;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--lvl-easy);
  color: var(--bg);
}
.finish-badge svg { width: 34px; height: 34px; stroke-width: 3; }

@media (min-height: 760px) {
  .step-hint { font-size: 16px; }
}

.chips.duration { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin: 0 0 12px; overflow: visible; }
.chips.duration .chip { padding: 8px 0; text-align: center; }
.sheet .chips.duration { margin: 0; }
