:root {
  --bg: #fbf7f4;
  --surface: #ffffff;
  --text: #241c1a;
  --muted: #8a7f7b;
  --line: #ece4df;
  --tomato: #e5483a;
  --tomato-ink: #ffffff;
  --leaf: #2f9e6b;
  --radius: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171312;
    --surface: #221c1b;
    --text: #f4ece8;
    --muted: #9c908b;
    --line: #342b29;
    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-tap-highlight-color: transparent;
}
a { color: inherit; }
button { font: inherit; color: inherit; cursor: pointer; }

.view {
  max-width: 560px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px calc(110px + env(safe-area-inset-bottom));
}

/* ---------- header ---------- */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.top h1 { font-size: 1.6rem; margin: 0; letter-spacing: -0.02em; }
.backlink { text-decoration: none; color: var(--muted); padding: 8px 0; }
.lang { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.lang button { border: 0; background: transparent; padding: 6px 12px; font-size: 0.85rem; color: var(--muted); }
.lang button[aria-pressed="true"] { background: var(--tomato); color: var(--tomato-ink); }
.tagline { color: var(--muted); margin: 0 0 24px; }
.error { color: var(--tomato); padding: 24px 0; }

/* ---------- home ---------- */
.cat { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 24px 0 8px; }
.cards { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.card {
  display: flex; flex-direction: column; gap: 2px;
  padding: 16px 18px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line);
  text-decoration: none; border-left: 5px solid var(--tomato);
}
.card:active { transform: scale(0.99); }
.card-title { font-weight: 650; font-size: 1.1rem; }
.card-meta { color: var(--muted); font-size: 0.9rem; }

/* ---------- overview ---------- */
.overview h1 { font-size: 1.8rem; margin: 12px 0 4px; letter-spacing: -0.02em; }
.meta { color: var(--muted); margin: 0 0 20px; font-size: 0.95rem; }
.settings { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 20px; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.row small { color: var(--muted); font-weight: 400; }
#total { font-variant-numeric: tabular-nums; font-weight: 650; }
input[type="range"] { width: 100%; margin: 12px 0 16px; accent-color: var(--tomato); }
.toggle { border-top: 1px solid var(--line); padding-top: 12px; }
.toggle.disabled { color: var(--muted); }
.toggle input { width: 22px; height: 22px; accent-color: var(--tomato); }
.steps { margin: 0; padding: 0; list-style: none; counter-reset: s; }
.steps li {
  counter-increment: s; display: flex; justify-content: space-between; gap: 12px;
  padding: 10px 2px; border-bottom: 1px solid var(--line);
}
.steps li span:first-child::before { content: counter(s) "."; color: var(--muted); display: inline-block; min-width: 2em; }
.dur { color: var(--muted); font-variant-numeric: tabular-nums; }
.start-bar {
  position: fixed; left: 0; right: 0; bottom: 0;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(transparent, var(--bg) 35%);
  display: flex; justify-content: center;
}
.btn-start {
  width: 100%; max-width: 528px; border: 0; border-radius: 999px;
  padding: 18px; font-size: 1.2rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase;
  background: var(--tomato); color: var(--tomato-ink);
  box-shadow: 0 6px 20px color-mix(in srgb, var(--tomato) 40%, transparent);
}
.btn-start:active { transform: scale(0.98); }

/* ---------- player ---------- */
body.playing { overflow: hidden; }
.player {
  --ex-accent: var(--tomato);
  height: 100dvh; max-width: 640px;
  padding: max(12px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  display: flex; flex-direction: column;
}
.ptop { display: flex; align-items: center; justify-content: space-between; gap: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.ptop .total { font-weight: 600; color: var(--text); min-width: 4.5em; text-align: right; }
.pmain { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 0; }
.ready-label { margin: 0; color: var(--muted); min-height: 1.4em; text-align: center; }
.ex-name {
  margin: 4px 0 20px; text-align: center; font-size: clamp(1.5rem, 6.5vw, 2.4rem);
  line-height: 1.15; letter-spacing: -0.02em; color: var(--ex-accent); transition: color 0.3s;
}
.ring-wrap {
  position: relative;
  width: min(84vw, 52dvh, 440px);
  aspect-ratio: 1;
}
.ring { position: absolute; inset: 0; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 4.5; }
.ring-track { stroke: var(--line); }
.ring-bar { stroke: var(--ex-accent); stroke-linecap: round; transition: stroke 0.3s; }
.media {
  position: absolute; inset: 8%; border-radius: 50%; overflow: hidden;
  background: var(--surface); display: grid; place-items: center;
}
.media img, .media video { width: 100%; height: 100%; object-fit: contain; background: #fff; }
.placeholder {
  width: 100%; height: 100%; display: grid; place-items: center; padding: 16%;
  text-align: center; color: var(--muted); font-size: clamp(0.95rem, 3.6vw, 1.2rem);
}
.secs {
  position: absolute; left: 50%; bottom: -4px; transform: translate(-50%, 0);
  min-width: 3.2em; padding: 2px 14px; border-radius: 999px;
  background: var(--ex-accent); color: #fff; text-align: center;
  font-size: clamp(1.8rem, 8vw, 2.6rem); font-weight: 750; font-variant-numeric: tabular-nums;
  box-shadow: 0 0 0 6px var(--bg); transition: background 0.3s;
}
.paused-label { visibility: hidden; margin: 20px 0 0; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.player.is-paused .paused-label { visibility: visible; animation: blink 1.4s infinite; }
.player.is-paused .ring-bar { opacity: 0.45; }
@keyframes blink { 50% { opacity: 0.3; } }

.controls { display: flex; justify-content: center; align-items: center; gap: 28px; padding-top: 8px; }
.icon {
  width: 56px; height: 56px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--surface);
  font-size: 1.3rem; display: grid; place-items: center; line-height: 1;
}
.icon.big { width: 76px; height: 76px; font-size: 1.8rem; background: var(--ex-accent); border-color: transparent; color: #fff; }
.ptop .icon { width: 44px; height: 44px; font-size: 1rem; }

/* full-screen color flash on every exercise change */
.player.flash::after {
  content: ""; position: fixed; inset: 0; pointer-events: none;
  background: var(--ex-accent); animation: flash 0.7s ease-out forwards;
}
@keyframes flash { from { opacity: 0.55; } to { opacity: 0; } }

/* ---------- done ---------- */
.done { display: grid; place-items: center; min-height: 100dvh; padding-bottom: 16px; }
.done-box { text-align: center; }
.big-tomato { font-size: 5rem; animation: pop 0.6s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes pop { from { transform: scale(0.2); } to { transform: scale(1); } }
.done h1 { font-size: 2.2rem; margin: 8px 0; }
.done p { color: var(--muted); }
.done-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 24px; }
.btn-secondary {
  text-decoration: none; padding: 12px 22px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
}

@media (prefers-reduced-motion: reduce) {
  .player.flash::after, .big-tomato, .player.is-paused .paused-label { animation: none; }
}
