:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #273449;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --work: #22c55e;
  --rest: #f59e0b;
  --countdown: #38bdf8;
  --danger: #f87171;
  --inhale: #38bdf8;
  --hold: #a78bfa;
  --exhale: #2dd4bf;
  --radius: 20px;
  --phase: var(--countdown);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  cursor: pointer;
  touch-action: manipulation;
}

.screen {
  display: none;
  flex-direction: column;
  min-height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  padding:
    calc(env(safe-area-inset-top) + 20px)
    calc(env(safe-area-inset-right) + 16px)
    calc(env(safe-area-inset-bottom) + 20px)
    calc(env(safe-area-inset-left) + 16px);
}
.screen.active { display: flex; }

/* ---------- Instellingen ---------- */

.app-header { margin: 8px 0 24px; }
.app-header h1 {
  margin: 0;
  font-size: 1.9rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.app-sub { margin: 6px 0 0; color: var(--muted); font-size: 1.05rem; }

.with-back { display: flex; align-items: center; gap: 8px; margin-left: -8px; }
.back {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: transparent;
  font-size: 2.2rem;
  line-height: 1;
  padding-bottom: 4px;
  display: grid;
  place-items: center;
}
.back:active { background: var(--surface); }

/* ---------- Home ---------- */

.choices { display: flex; flex-direction: column; gap: 14px; }
.choice {
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  text-align: left;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 22px 18px;
}
.choice:active { transform: scale(0.98); background: var(--surface-2); }
.choice-icon { width: 48px; height: 48px; flex-shrink: 0; }
.choice-stretch .choice-icon { color: var(--work); }
.choice-breath .choice-icon { color: var(--inhale); }
.choice-text { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.choice-title { font-size: 1.3rem; font-weight: 700; }
.choice-hint { color: var(--muted); font-size: 0.95rem; margin-top: 3px; }
.choice-arrow { font-size: 2rem; color: var(--muted); line-height: 1; }

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--surface);
  border-radius: 999px;
  padding: 4px;
  margin-bottom: 16px;
}
.segmented button {
  background: transparent;
  border-radius: 999px;
  padding: 12px 8px;
  font-weight: 600;
  color: var(--muted);
}
.segmented button[aria-selected="true"] { background: var(--accent); color: var(--bg); }

.settings[hidden] { display: none; }
.settings-gap { margin-top: 12px; }

.settings {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.setting {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
}

.setting-label { display: flex; flex-direction: column; min-width: 0; }
.setting-title { font-size: 1.05rem; font-weight: 600; }
.setting-hint { font-size: 0.85rem; color: var(--muted); margin-top: 2px; }

.stepper {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.step {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--surface-2);
  font-size: 1.6rem;
  line-height: 1;
  display: grid;
  place-items: center;
}
.step:active { background: var(--accent); color: var(--bg); }

.value {
  min-width: 72px;
  text-align: center;
  font-size: 1.35rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.summary {
  text-align: center;
  color: var(--muted);
  margin: 24px 0;
  line-height: 1.5;
}
.summary strong { color: var(--text); }

.btn {
  border-radius: 999px;
  padding: 16px 24px;
  font-weight: 700;
  font-size: 1.1rem;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--accent); color: var(--bg); }
.btn-ghost { background: var(--surface); color: var(--text); }
.btn-big { width: 100%; padding: 20px; font-size: 1.3rem; margin-top: auto; }

/* ---------- Timer ---------- */

.run[data-phase="countdown"] { --phase: var(--countdown); }
.run[data-phase="work"]      { --phase: var(--work); }
.run[data-phase="rest"]      { --phase: var(--rest); }
.run[data-phase="inhale"]    { --phase: var(--inhale); }
.run[data-phase="holdIn"],
.run[data-phase="holdOut"]   { --phase: var(--hold); }
.run[data-phase="exhale"]    { --phase: var(--exhale); }

.run-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-top: 8px;
}
.phase-label {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--phase);
  transition: color 0.3s;
}
.rep-label {
  font-size: 1.1rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.ring-wrap {
  position: relative;
  width: min(84vw, 52dvh, 380px);
  aspect-ratio: 1;
  margin: auto;
}
.ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 12; }
.ring-bg { stroke: var(--surface); }
.ring-fg {
  stroke: var(--phase);
  stroke-linecap: round;
  transition: stroke 0.3s;
}
.ring-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.time-left {
  font-size: clamp(4rem, 22vw, 7rem);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.next-label {
  margin-top: 10px;
  color: var(--muted);
  font-size: 1rem;
  min-height: 1.2em;
}

.dots {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin: 8px 0 24px;
}
.dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--surface-2);
}
.dot.done { background: var(--work); }
.dot.current { background: var(--phase); box-shadow: 0 0 0 3px color-mix(in srgb, var(--phase) 35%, transparent); }

.controls {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 12px;
}
.controls .btn { padding: 20px; font-size: 1.2rem; }

.run.paused .time-left { opacity: 0.45; }

/* ---------- Ademhaling ---------- */

.breath-visual {
  width: min(84vw, 44dvh, 360px);
  margin: auto auto 8px;
}
.shape { width: 100%; height: auto; display: block; overflow: visible; }
.shape[hidden] { display: none; }
.shape line { stroke-linecap: round; }
.track line {
  stroke: var(--surface-2);
  stroke-width: 10;
  transition: stroke 0.3s;
}
.progress { stroke: var(--phase); stroke-width: 10; transition: stroke 0.3s; }
.dot-marker {
  fill: var(--text);
  stroke: var(--phase);
  stroke-width: 5;
  transition: stroke 0.3s;
}

.breath-count { text-align: center; margin-bottom: 24px; }
.breath-count .time-left { font-size: clamp(3.5rem, 18vw, 5.5rem); }

/* ---------- Klaar ---------- */

.done-inner {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 12px;
  flex: 1;
  text-align: center;
}
.done-check {
  margin: auto auto 16px;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: var(--work);
  color: var(--bg);
  font-size: 4rem;
  font-weight: 800;
  display: grid;
  place-items: center;
}
.done-inner h2 { margin: 0; font-size: 2rem; }
.done-inner .btn-big { margin-top: auto; }
