:root {
  --bg: #0b1020;
  --bg-glow: #1b2447;
  --text: #e8ecf8;
  --muted: #8f98b8;
  --card: rgba(255, 255, 255, 0.05);
  --card-hover: rgba(255, 255, 255, 0.08);
  --card-border: rgba(255, 255, 255, 0.1);
  --accent: #7dd3fc;
  --inhale: #67e8f9;
  --hold: #c4b5fd;
  --exhale: #f9a8d4;
  --done: #86efac;
  --phase: var(--accent);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { color-scheme: dark; }

body {
  margin: 0;
  min-height: 100dvh;
  font-family: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, system-ui, sans-serif;
  background: var(--bg) radial-gradient(1200px 800px at 50% -10%, var(--bg-glow) 0%, var(--bg) 60%) fixed;
  color: var(--text);
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

.app {
  max-width: 560px;
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(24px, env(safe-area-inset-top)) 20px max(28px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 28px;
}

/* Header */
.top h1 { margin: 0; font-size: 1.7rem; font-weight: 600; letter-spacing: 0.02em; }
.subtitle { margin: 4px 0 0; color: var(--muted); }

/* Setup */
.section-label {
  margin: 0 0 10px;
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
}
.section-label + .section-label, .custom-panel + .section-label, .techniques + .section-label { margin-top: 22px; }

.techniques {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.tech {
  appearance: none;
  font: inherit;
  color: inherit;
  text-align: left;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 16px;
  padding: 14px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 5px;
  transition: border-color 0.2s, background 0.2s, transform 0.1s;
}
.tech:hover { background: var(--card-hover); }
.tech:active { transform: scale(0.98); }
.tech[aria-checked="true"] {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  box-shadow: inset 0 0 0 1px var(--accent);
}
.tech-name { font-weight: 600; }
.tech-desc { font-size: 0.82rem; color: var(--muted); }

.pattern { display: flex; gap: 12px; margin-top: 6px; }
.seg { display: flex; flex-direction: column; align-items: center; min-width: 24px; }
.seg b { font-weight: 600; font-variant-numeric: tabular-nums; }
.seg small { font-size: 0.62rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }

.custom-panel {
  margin-top: 12px;
  display: grid;
  gap: 12px;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 16px;
  padding: 14px 16px;
}
.slider {
  display: grid;
  grid-template-columns: 92px 1fr 34px;
  align-items: center;
  gap: 12px;
  font-size: 0.9rem;
}
.slider output { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
input[type="range"] { width: 100%; accent-color: var(--accent); margin: 0; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  appearance: none;
  font: inherit;
  color: inherit;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 999px;
  padding: 8px 16px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  font-variant-numeric: tabular-nums;
}
.chip:hover { background: var(--card-hover); }
.chip[aria-checked="true"] {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

/* Stage */
.stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 26px;
  padding: 18px 0 6px;
}
.stage[data-phase="inhale"] { --phase: var(--inhale); }
.stage[data-phase="hold"]   { --phase: var(--hold); }
.stage[data-phase="exhale"] { --phase: var(--exhale); }
.stage[data-phase="done"]   { --phase: var(--done); }

.orb-wrap {
  position: relative;
  width: min(66vw, 300px);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
}

.ring {
  position: absolute;
  inset: -16px;
  width: calc(100% + 32px);
  height: calc(100% + 32px);
  transform: rotate(-90deg);
  overflow: visible;
}
.ring circle { fill: none; stroke-width: 2; }
.ring-track { stroke: rgba(255, 255, 255, 0.08); }
.ring-progress { stroke: var(--phase); stroke-linecap: round; transition: stroke 0.6s ease; }

.orb {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: radial-gradient(
    circle at 50% 45%,
    color-mix(in srgb, var(--phase) 30%, var(--bg)) 0%,
    color-mix(in srgb, var(--phase) 55%, var(--bg)) 55%,
    color-mix(in srgb, var(--phase) 92%, white) 100%
  );
  box-shadow:
    0 0 40px color-mix(in srgb, var(--phase) 45%, transparent),
    0 0 120px color-mix(in srgb, var(--phase) 25%, transparent);
  transform: scale(0.55);
  will-change: transform;
  transition: background 0.8s ease, box-shadow 0.8s ease, opacity 0.4s ease;
}
.stage.is-paused .orb { opacity: 0.55; }

.orb-text {
  position: relative;
  z-index: 1;
  text-align: center;
  pointer-events: none;
  text-shadow: 0 1px 10px rgba(0, 0, 0, 0.45);
}
.phase { font-size: 1.15rem; font-weight: 500; letter-spacing: 0.04em; }
.count {
  font-size: 2.8rem;
  font-weight: 600;
  line-height: 1.1;
  min-height: 1.1em;
  font-variant-numeric: tabular-nums;
}

.info {
  margin: 0;
  min-height: 1.4em;
  text-align: center;
  color: var(--muted);
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
}

/* Controls: the button row sticks to the bottom so Start is always reachable */
.controls {
  position: sticky;
  bottom: 0;
  z-index: 2;
  display: flex;
  justify-content: center;
  gap: 10px;
  margin: -8px -20px 0;
  padding: 16px 20px max(16px, env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 65%, transparent);
}
.cues { display: flex; flex-direction: column; align-items: center; gap: 12px; margin-top: -12px; }
.btn {
  appearance: none;
  font: inherit;
  font-size: 1.05rem;
  border-radius: 999px;
  padding: 14px 28px;
  cursor: pointer;
  transition: transform 0.1s, filter 0.2s, background 0.2s;
}
.btn:active { transform: scale(0.97); }
.primary {
  min-width: 180px;
  border: 0;
  font-weight: 700;
  color: #0b1020;
  background: linear-gradient(135deg, var(--accent), #a5b4fc);
  box-shadow: 0 8px 30px color-mix(in srgb, var(--accent) 30%, transparent);
}
.primary:hover { filter: brightness(1.06); }
.ghost { background: transparent; border: 1px solid var(--card-border); color: var(--text); }
.ghost:hover { background: var(--card-hover); }

.toggles { display: flex; gap: 20px; color: var(--muted); font-size: 0.9rem; }
.toggle { display: flex; align-items: center; gap: 7px; cursor: pointer; user-select: none; }
.toggle input { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); }

.hint { margin: 0; font-size: 0.75rem; color: var(--muted); opacity: 0.7; }
@media (hover: none) { .hint { display: none; } }

.foot { margin-top: auto; text-align: center; font-size: 0.75rem; color: var(--muted); opacity: 0.8; }

/* Active session: hide setup so only the guide remains */
.app.is-active .setup, .app.is-active .subtitle { display: none; }
.app.is-active .stage { padding-top: 6vh; }

@media (max-width: 380px) {
  .techniques { grid-template-columns: 1fr; }
  .slider { grid-template-columns: 80px 1fr 34px; }
}

@media (prefers-reduced-motion: reduce) {
  .orb, .ring-progress, .tech, .chip, .btn { transition: none; }
}
