:root {
  --bg: #ffffff;
  --bg-soft: #f6f7f9;
  --card: #ffffff;
  --card-2: #eef0f3;
  --line: rgba(17, 24, 39, 0.08);
  --text: #1c1d21;
  --muted: #8a8f98;
  --muted-2: #aeb2ba;
  --accent: #14b8a6;
  --accent-2: #2dd4bf;
  --accent-deep: #0f766e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --ring-track: #ececee;
  --shadow-sm: 0 6px 18px -8px rgba(17, 24, 39, 0.18);
  --shadow: 0 18px 40px -22px rgba(17, 24, 39, 0.30);
  --radius: 22px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
}

#app {
  position: relative;
  max-width: 480px;
  margin: 0 auto;
  height: 100dvh;
  overflow: hidden;
  padding: calc(var(--safe-top) + 8px) clamp(16px, 5vw, 24px) calc(var(--safe-bottom) + 14px);
}

/* ---------- screens ---------- */
.screen {
  display: none;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  animation: fade-in 0.3s ease both;
}
.screen.is-active { display: flex; }

/* hide scrollbars but keep scrollability where content can overflow */
.screen,
.wk-instructions {
  -ms-overflow-style: none;
  scrollbar-width: none;
}
.screen::-webkit-scrollbar,
.wk-instructions::-webkit-scrollbar {
  width: 0;
  height: 0;
  display: none;
}

@keyframes fade-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- buttons ---------- */
.btn {
  border: none;
  border-radius: 16px;
  font-size: 17px;
  font-weight: 700;
  color: #04201c;
  padding: 16px 22px;
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.12s ease, box-shadow 0.2s ease, opacity 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.btn:active { transform: scale(0.97); }
.btn-primary {
  background: linear-gradient(135deg, var(--accent-2), var(--accent));
  box-shadow: 0 14px 30px -12px rgba(20, 184, 166, 0.8);
}
.btn-primary:disabled { opacity: 0.5; box-shadow: none; cursor: default; }
.btn-lg { width: 100%; padding: 19px; font-size: 19px; }
.btn-icon { font-size: 15px; }

.icon-btn {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  color: var(--text);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.12s ease, background 0.2s ease;
}
.icon-btn.ghost { background: transparent; border-color: transparent; color: var(--muted); font-size: 20px; }
.icon-btn:active { transform: scale(0.9); }

/* ================= START SCREEN ================= */
#screen-start {
  justify-content: space-between;
  gap: clamp(14px, 3vh, 24px);
  padding-top: max(4vh, 12px);
}
.start-hero { display: flex; flex-direction: column; }
.start-badge {
  align-self: flex-start;
  background: rgba(20, 184, 166, 0.12);
  color: var(--accent-deep);
  border: 1px solid rgba(20, 184, 166, 0.28);
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.3px;
}
#start-title {
  font-size: clamp(26px, 7.5vw, 34px);
  line-height: 1.12;
  margin: clamp(10px, 2vh, 18px) 0 clamp(8px, 1.5vh, 12px);
  letter-spacing: -0.5px;
}
.start-desc {
  color: var(--muted);
  font-size: clamp(13px, 3.6vw, 15px);
  line-height: 1.5;
  margin: 0 0 clamp(14px, 3vh, 24px);
}
.start-meta { display: flex; gap: 12px; }
.meta-chip {
  flex: 1;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px 10px;
  text-align: center;
}
.meta-num {
  display: block;
  font-size: clamp(22px, 6vw, 26px);
  font-weight: 800;
  color: var(--accent-deep);
  font-variant-numeric: tabular-nums;
}
.meta-label {
  display: block;
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
}
.start-hint {
  color: var(--muted-2);
  font-size: 13px;
  line-height: 1.5;
  text-align: center;
  margin: 14px 0 0;
}

/* ================= WORKOUT SCREEN ================= */
#screen-workout { padding-top: calc(var(--safe-top) + 4px); }

.wk-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex: none;
  padding-bottom: 4px;
}
.wk-count {
  font-size: 20px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.2px;
  font-variant-numeric: tabular-nums;
}

/* body fills the space and centres the circular timer */
.wk-body {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-evenly;
  gap: 0;
  padding: clamp(4px, 1vh, 10px) 0;
  text-align: center;
  overflow: hidden;
}

/* ---------- circular timer with embedded image ---------- */
.timer-stage {
  position: relative;
  flex: none;
  width: min(62vw, 34vh, 300px);
  aspect-ratio: 1;
}
.ring { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-track { fill: none; stroke: var(--ring-track); stroke-width: 6; }
.ring-progress {
  fill: none;
  stroke: var(--accent);
  stroke-width: 6;
  stroke-linecap: round;
  transition: stroke 0.3s ease;
}

.timer-media {
  position: absolute;
  inset: 6%;
  border-radius: 50%;
  overflow: hidden;
  background: var(--bg-soft);
  box-shadow: var(--shadow-sm);
}
.timer-media img.wk-frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  opacity: 0;
  transition: opacity var(--morph-fade, 900ms) ease-in-out;
  will-change: opacity;
}
.timer-media img.wk-frame.is-visible { opacity: 1; }
.timer-media img[hidden] { display: none; }
.wk-image-fallback {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: clamp(56px, 20vw, 96px);
  color: var(--muted-2);
  background: var(--bg-soft);
}
.wk-image-fallback.show { display: flex; }

.countdown-overlay {
  position: absolute;
  inset: 6%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(2px);
  border-radius: 50%;
}
.countdown-overlay[hidden] { display: none; }
#countdown-number {
  font-size: clamp(72px, 26vw, 120px);
  font-weight: 900;
  color: var(--accent-deep);
  animation: pop 0.9s ease;
}
@keyframes pop {
  0% { transform: scale(0.4); opacity: 0; }
  35% { transform: scale(1.1); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

.wk-section-name {
  color: var(--accent-deep);
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.9px;
  text-transform: uppercase;
}

.wk-title-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  max-width: 90%;
}
#wk-name {
  font-size: clamp(24px, 6.5vw, 30px);
  margin: 0;
  line-height: 1.15;
  letter-spacing: -0.4px;
  font-weight: 800;
}
.info-btn {
  flex: none;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1.5px solid var(--muted-2);
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-family: Georgia, "Times New Roman", serif;
  font-style: italic;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.12s ease, background 0.2s ease;
}
.info-btn:active { transform: scale(0.9); background: var(--bg-soft); }

.timer-value {
  font-size: clamp(52px, 15vw, 72px);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  letter-spacing: -1.5px;
  color: var(--muted);
}
.timer-value.low { color: var(--danger); animation: tick 1s ease infinite; }
@keyframes tick {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}
.timer-sub { font-size: 13px; color: var(--muted-2); margin-top: 2px; }

/* ---------- controls ---------- */
.wk-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(28px, 12vw, 56px);
  flex: none;
  padding: clamp(8px, 2vh, 18px) 0 0;
}
.ctrl-btn {
  width: 62px;
  height: 62px;
  border-radius: 50%;
  border: none;
  background: var(--card);
  color: var(--text);
  font-size: 24px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
  transition: transform 0.12s ease, box-shadow 0.2s ease;
  padding-left: 2px;
}
.ctrl-btn:active { transform: scale(0.92); }
.ctrl-main { width: 86px; height: 86px; font-size: 34px; }
.ctrl-main.running { padding-left: 0; }

/* ================= INSTRUCTIONS BOTTOM SHEET ================= */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, 0.32);
  opacity: 0;
  transition: opacity 0.28s ease;
  z-index: 20;
}
.sheet-backdrop.show { opacity: 1; }
.sheet-backdrop[hidden] { display: none; }

.instr-sheet {
  position: fixed;
  left: 50%;
  bottom: 0;
  width: 100%;
  max-width: 480px;
  transform: translate(-50%, 100%);
  background: var(--bg);
  border-radius: 26px 26px 0 0;
  box-shadow: 0 -18px 50px -22px rgba(17, 24, 39, 0.4);
  padding: 10px clamp(18px, 5vw, 26px) calc(var(--safe-bottom) + 24px);
  z-index: 21;
  transition: transform 0.34s cubic-bezier(0.22, 0.61, 0.36, 1);
  max-height: 80dvh;
  display: flex;
  flex-direction: column;
  touch-action: none;
}
.instr-sheet.open { transform: translate(-50%, 0); }

.sheet-handle {
  width: 42px;
  height: 5px;
  border-radius: 999px;
  background: var(--ring-track);
  margin: 4px auto 12px;
  flex: none;
}
.sheet-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex: none;
}
#sheet-title { font-size: 20px; margin: 0; font-weight: 800; letter-spacing: -0.3px; }
.wk-tag {
  flex: none;
  font-size: 11px;
  font-weight: 700;
  padding: 5px 11px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #04201c;
  background: var(--accent-2);
}
.wk-tag.mobility { background: #93c5fd; }
.wk-tag.stretch { background: #d8b4fe; }
.wk-tag.activation { background: #fcd34d; }
.wk-tag.strength { background: var(--accent-2); }
.wk-tag:empty { display: none; }

.wk-meta-line { color: var(--muted); font-size: 13px; margin: 6px 0 12px; }
.wk-meta-line:empty { margin: 0; }

.wk-instructions {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  flex: 1 1 auto;
  min-height: 0;
  counter-reset: step;
  -webkit-overflow-scrolling: touch;
}
.wk-instructions li {
  position: relative;
  padding: 12px 14px 12px 44px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.45;
  color: var(--text);
}
.wk-instructions li::before {
  counter-increment: step;
  content: counter(step);
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(20, 184, 166, 0.16);
  color: var(--accent-deep);
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ================= DONE SCREEN ================= */
#screen-done { justify-content: center; align-items: center; gap: 30px; text-align: center; }
.done-hero { display: flex; flex-direction: column; align-items: center; }
.done-check {
  width: 108px;
  height: 108px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-2), var(--accent));
  color: #ffffff;
  font-size: 58px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 20px 45px -18px rgba(20, 184, 166, 0.7);
  animation: pop 0.7s ease;
}
#screen-done h1 { font-size: 32px; margin: 22px 0 8px; }
.done-summary { color: var(--muted); font-size: 15px; max-width: 300px; line-height: 1.5; margin: 0; }
#btn-restart { width: 100%; max-width: 320px; }
