/* ============================================================
   Flowdeeper — visual design language
   Dark, minimal, premium, calm. Near-black ground, glass
   surfaces, one accent that re-tints per mode.
   ============================================================ */

/* --- Accent as a registered property so gradients, strokes and
       shadows all cross-fade smoothly when the mode changes. --- */
@property --accent {
  syntax: "<color>";
  inherits: true;
  initial-value: #e88ab6;
}

:root {
  color-scheme: dark;

  /* ground + ink */
  --bg: #0a0c10;
  --ink: #e8eaf0;
  --ink-dim: rgba(232, 234, 240, 0.55);
  --ink-faint: rgba(232, 234, 240, 0.28);

  /* accent (mode-themed on <body>) */
  --accent: #e88ab6;

  /* glass surfaces */
  --glass-bg: rgba(232, 234, 240, 0.045);
  --glass-bg-strong: rgba(232, 234, 240, 0.09);
  --glass-border: rgba(232, 234, 240, 0.1);
  --glass-border-strong: rgba(232, 234, 240, 0.18);
  --blur: 18px;

  /* radii */
  --r-pill: 999px;
  --r-md: 18px;

  /* spacing rhythm */
  --sp-1: 0.375rem;
  --sp-2: 0.75rem;
  --sp-3: 1.25rem;
  --sp-4: 2rem;
  --sp-5: 3.25rem;

  /* motion */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --t-fast: 300ms;
  --t-slow: 600ms;

  /* type details */
  --track-wide: 0.22em;
  --track-hair: 0.06em;

  /* progress ring geometry: 2 * pi * 45 */
  --ring-circ: 282.743;
}

/* ------------------------------------------------------------
   Reset / ground
   ------------------------------------------------------------ */

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
  /* The page must not be draggable: no rubber-band, no sideways slack. */
  overscroll-behavior: none;
  overflow-x: clip;
}

/* While a sheet is open the page behind it stays put. */
html:has(dialog[open]),
html:has(dialog[open]) body,
html:has(#lab:not([hidden])),
html:has(#lab:not([hidden])) body {
  overflow: hidden;
}

body {
  min-height: 100dvh;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, "SF Pro Text", Inter, "Segoe UI", Roboto, sans-serif;
  font-size: 1rem;
  line-height: 1.5;
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  /* mode accent cross-fade */
  transition: --accent 900ms var(--ease);
}

/* Mode theming — every accent-colored thing reads var(--accent). */
body[data-mode="orbit"]   { --accent: #e88ab6; }
body[data-mode="focus"]   { --accent: #e8a15c; }
body[data-mode="relax"]   { --accent: #8f9fe8; }
body[data-mode="breathe"] { --accent: #5cc8b8; }
/* Flowtito takes its accent from the scene that is playing. */
body[data-mode="flowtito"]                        { --accent: #6fdccb; }
body[data-mode="flowtito"][data-scene="garden"]   { --accent: #e8cd73; }
body[data-mode="flowtito"][data-scene="ascent"]   { --accent: #e873b0; }
body[data-mode="flowtito"][data-scene="band"]     { --accent: #e8a873; }
body[data-mode="flowtito"][data-scene="gamelan"]  { --accent: #e8c773; }
body[data-mode="flowtito"][data-scene="train"]    { --accent: #73aae8; }
body[data-mode="flowtito"][data-scene="cave"]     { --accent: #73dae8; }
body[data-mode="flowtito"][data-scene="create"]   { --accent: #73dce8; }
body[data-mode="flowtito"][data-scene="sleep"]    { --accent: #7375e8; }
body[data-mode="flowtito"][data-scene="adhd"]     { --accent: #73e8d6; }
body[data-mode="flowtito"][data-scene="tones"]    { --accent: #73e8d6; }
body[data-mode="flowtito"][data-scene="hum"]      { --accent: #73e8d6; }
body[data-mode="flowtito"][data-scene="gamma"]    { --accent: #73e8d6; }
body[data-mode="flowtito"][data-scene="noise"]    { --accent: #73e8d6; }
body[data-mode="flowtito"][data-scene="momentum"] { --accent: #f0b95a; }
body[data-mode="flowtito"][data-scene="lofi"]     { --accent: #d59be0; }
body[data-mode="flowtito"][data-scene="focus"]    { --accent: #a493f2; }
body[data-mode="flowtito"][data-scene="deep"]     { --accent: #7f95f0; }
body[data-mode="flowtito"][data-scene="calm"]     { --accent: #86e0a8; }

::selection {
  background: color-mix(in srgb, var(--accent) 30%, transparent);
  color: var(--ink);
}

.hidden {
  display: none !important;
}

/* Shared focus treatment — visible, calm, accent-tinted. */
:focus {
  outline: none;
}
:focus-visible {
  outline: 1.5px solid color-mix(in srgb, var(--accent) 75%, transparent);
  outline-offset: 3px;
  border-radius: var(--r-pill);
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

/* ------------------------------------------------------------
   Canvas atmosphere
   ------------------------------------------------------------ */

#canvas-bg {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  z-index: 0;
  pointer-events: none;
}

/* ------------------------------------------------------------
   App column
   ------------------------------------------------------------ */

#app {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100dvh;
  width: 100%;
  max-width: 42rem;
  margin: 0 auto;
  padding-top: calc(var(--sp-4) + env(safe-area-inset-top));
  padding-bottom: calc(var(--sp-3) + env(safe-area-inset-bottom));
  padding-left: calc(var(--sp-3) + env(safe-area-inset-left));
  padding-right: calc(var(--sp-3) + env(safe-area-inset-right));
}

/* ------------------------------------------------------------
   Header — wordmark + status line
   ------------------------------------------------------------ */

#app header {
  text-align: center;
  transition: opacity var(--t-slow) var(--ease);
}

#app header h1 {
  font-size: 0.95rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5em;
  /* re-centre optically: trailing tracking space */
  margin-right: -0.5em;
  color: var(--ink);
}

#status-text {
  margin-top: var(--sp-1);
  font-size: 0.6875rem;
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: var(--track-wide);
  margin-right: calc(-1 * var(--track-wide));
  color: var(--ink-dim);
  transition: color var(--t-slow) var(--ease);
}

/* ------------------------------------------------------------
   Mode switch — glass segmented pill
   ------------------------------------------------------------ */

#mode-switch {
  display: flex;
  gap: var(--sp-1);
  margin-top: var(--sp-4);
  padding: var(--sp-1);
  border-radius: var(--r-pill);
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(var(--blur));
  -webkit-backdrop-filter: blur(var(--blur));
  transition: opacity var(--t-slow) var(--ease);
}

.mode-btn {
  flex: 1 1 auto;
  min-height: 44px;
  padding: 0.55rem 0.95rem;
  border-radius: var(--r-pill);
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: var(--track-hair);
  color: var(--ink-dim);
  border: 1px solid transparent;
  transition:
    color var(--t-fast) var(--ease),
    background-color var(--t-fast) var(--ease),
    border-color var(--t-fast) var(--ease),
    box-shadow var(--t-slow) var(--ease);
}

.mode-btn[aria-pressed="true"] {
  color: var(--ink);
  background: var(--glass-bg-strong);
  border-color: color-mix(in srgb, var(--accent) 45%, transparent);
  box-shadow:
    0 0 18px color-mix(in srgb, var(--accent) 22%, transparent),
    inset 0 0 12px color-mix(in srgb, var(--accent) 8%, transparent);
}

@media (hover: hover) {
  .mode-btn:hover {
    color: var(--ink);
  }
}

/* One quiet line describing the selected mode (and, for orbit, the
   headphone nudge — HRTF spatialisation needs them). Fixed height so the
   stage never shifts when the text changes. */
#mode-tagline {
  min-height: 1.5em;
  margin-top: var(--sp-2);
  padding: 0 var(--sp-2);
  text-align: center;
  font-size: 0.625rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: var(--track-wide);
  margin-right: calc(-1 * var(--track-wide));
  color: var(--ink-faint);
  transition: color var(--t-slow) var(--ease), opacity var(--t-slow) var(--ease);
}

body[data-mode="orbit"] #mode-tagline,
body[data-mode="flowtito"] #mode-tagline {
  color: color-mix(in srgb, var(--accent) 55%, var(--ink-dim));
}

/* ------------------------------------------------------------
   Flowtito scenes — a quiet row of chips under the tagline
   ------------------------------------------------------------ */

#flow-scenes {
  display: none;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--sp-1);
  margin-top: var(--sp-2);
  transition: opacity var(--t-slow) var(--ease);
}

body[data-mode="flowtito"] #flow-scenes {
  display: flex;
}

.scene-btn {
  min-height: 32px;
  padding: 0.3rem 0.7rem;
  border-radius: var(--r-pill);
  font-size: 0.625rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: var(--track-hair);
  color: var(--ink-dim);
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  transition:
    color var(--t-fast) var(--ease),
    background-color var(--t-fast) var(--ease),
    border-color var(--t-fast) var(--ease),
    box-shadow var(--t-slow) var(--ease);
}

.scene-btn[aria-pressed="true"] {
  color: var(--ink);
  background: var(--glass-bg-strong);
  border-color: color-mix(in srgb, var(--accent) 45%, transparent);
  box-shadow: 0 0 14px color-mix(in srgb, var(--accent) 18%, transparent);
}

@media (hover: hover) {
  .scene-btn:hover {
    color: var(--ink);
  }
}

/* ------------------------------------------------------------
   Stage — ring, play button, timer
   ------------------------------------------------------------ */

#stage {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1 1 auto;
  width: 100%;
  padding: var(--sp-4) 0;
}

/* Soft radial glow breathing behind the ring. */
#stage::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: min(140vw, 640px);
  aspect-ratio: 1;
  translate: -50% -50%;
  border-radius: 50%;
  background: radial-gradient(
    circle,
    color-mix(in srgb, var(--accent) 11%, transparent) 0%,
    color-mix(in srgb, var(--accent) 4%, transparent) 38%,
    transparent 68%
  );
  pointer-events: none;
  z-index: -1;
  animation: stage-glow 9s var(--ease) infinite alternate;
}

@keyframes stage-glow {
  from { opacity: 0.7; scale: 0.96; }
  to   { opacity: 1;   scale: 1.04; }
}

/* Positioning context for the play button — shrink-wraps to the ring,
   so the button centers on the ring, not the whole stage. */
.ring-wrap {
  position: relative;
}

/* Flowtito's wobbling rings, just outside the progress ring (rings.js). */
#flow-rings {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 130%;
  height: 130%;
  translate: -50% -50%;
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--t-slow) var(--ease);
}

body[data-mode="flowtito"] #flow-rings {
  opacity: 1;
}

#progress-ring {
  position: relative;
  width: min(62vw, 320px);
  height: min(62vw, 320px);
  display: block;
  overflow: visible;
}

.ring-track {
  fill: none;
  stroke: rgba(232, 234, 240, 0.08);
  stroke-width: 1.6;
}

#ring-fill {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-dasharray: var(--ring-circ);
  stroke-dashoffset: var(--ring-circ);
  transform: rotate(-90deg);
  transform-box: fill-box;
  transform-origin: center;
  transition: stroke 900ms var(--ease);
  filter: drop-shadow(0 0 6px color-mix(in srgb, var(--accent) 55%, transparent));
}

/* Play / pause — large circular glass button centered in the ring
   (absolute within .ring-wrap). */
#play-btn {
  position: absolute;
  top: 50%;
  left: 50%;
  translate: -50% -50%;
  width: 88px;
  height: 88px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--glass-bg-strong);
  border: 1px solid var(--glass-border-strong);
  backdrop-filter: blur(var(--blur));
  -webkit-backdrop-filter: blur(var(--blur));
  color: var(--ink);
  box-shadow:
    0 10px 40px rgba(0, 0, 0, 0.45),
    inset 0 1px 0 rgba(232, 234, 240, 0.09),
    0 0 0 0 color-mix(in srgb, var(--accent) 0%, transparent);
  transition:
    transform var(--t-fast) var(--ease),
    box-shadow var(--t-slow) var(--ease),
    border-color var(--t-slow) var(--ease);
}

#play-btn svg {
  width: 30px;
  height: 30px;
  display: block;
  fill: currentColor;
  stroke: none;
  /* optical centering for the play triangle */
  translate: 1px 0;
}

#play-btn svg path {
  fill: currentColor;
}

@media (hover: hover) {
  #play-btn:hover {
    transform: scale(1.045);
    border-color: color-mix(in srgb, var(--accent) 40%, var(--glass-border-strong));
    box-shadow:
      0 12px 46px rgba(0, 0, 0, 0.5),
      inset 0 1px 0 rgba(232, 234, 240, 0.11),
      0 0 34px color-mix(in srgb, var(--accent) 22%, transparent);
  }
}

#play-btn:active {
  transform: scale(0.965);
  transition-duration: 120ms;
}

body.playing #play-btn {
  border-color: color-mix(in srgb, var(--accent) 35%, var(--glass-border-strong));
  box-shadow:
    0 10px 40px rgba(0, 0, 0, 0.45),
    inset 0 1px 0 rgba(232, 234, 240, 0.09),
    0 0 30px color-mix(in srgb, var(--accent) 18%, transparent);
}

/* When paused, the pause glyph is centered — undo the play nudge. */
body.playing #play-btn svg {
  translate: 0 0;
}

#timer-display {
  margin-top: var(--sp-3);
  font-size: 1.5rem;
  font-weight: 300;
  letter-spacing: 0.12em;
  margin-right: -0.12em;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
  color: var(--ink-dim);
  transition: color var(--t-slow) var(--ease);
}

body.playing #timer-display {
  color: var(--ink);
}

/* ------------------------------------------------------------
   Breath overlay — full-screen veil + guided circle
   ------------------------------------------------------------ */

#breath-overlay {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-4);
  background: color-mix(in srgb, var(--bg) 62%, transparent);
  backdrop-filter: blur(26px);
  -webkit-backdrop-filter: blur(26px);
  padding: var(--sp-4);
  padding-bottom: calc(var(--sp-4) + env(safe-area-inset-bottom));
  animation: veil-in 700ms var(--ease) both;
  /* purely presentational — let taps reach the controls beneath */
  pointer-events: none;
}

@keyframes veil-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

#breath-circle {
  --breath-scale: 0.6;
  width: min(56vw, 280px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(
    circle at 50% 42%,
    color-mix(in srgb, var(--accent) 26%, transparent) 0%,
    color-mix(in srgb, var(--accent) 9%, transparent) 55%,
    transparent 74%
  );
  border: 1px solid color-mix(in srgb, var(--accent) 42%, transparent);
  box-shadow:
    0 0 60px color-mix(in srgb, var(--accent) 26%, transparent),
    0 0 140px color-mix(in srgb, var(--accent) 12%, transparent),
    inset 0 0 44px color-mix(in srgb, var(--accent) 14%, transparent);
  transform: scale(var(--breath-scale, 0.6));
  transition: transform var(--breath-dur, 4s) cubic-bezier(0.4, 0, 0.2, 1);
  will-change: transform;
}

#breath-label {
  min-height: 1.5em;
  font-size: 0.8125rem;
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 0.34em;
  margin-right: -0.34em;
  text-align: center;
  color: var(--ink-dim);
}

/* ------------------------------------------------------------
   Footer controls — duration + texture
   ------------------------------------------------------------ */

#controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-3);
  width: 100%;
  max-width: 22rem;
  margin-top: auto;
  transition: opacity var(--t-slow) var(--ease);
}

#timer-select {
  display: flex;
  gap: var(--sp-1);
  padding: var(--sp-1);
  border-radius: var(--r-pill);
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(var(--blur));
  -webkit-backdrop-filter: blur(var(--blur));
}

.timer-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  min-width: 56px;
  min-height: 48px;
  padding: 0.4rem 0.8rem;
  border-radius: var(--r-pill);
  border: 1px solid transparent;
  color: var(--ink-dim);
  font-size: 1.0625rem;
  font-weight: 400;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
  transition:
    color var(--t-fast) var(--ease),
    background-color var(--t-fast) var(--ease),
    border-color var(--t-fast) var(--ease),
    box-shadow var(--t-slow) var(--ease);
}

/* the small "min" caption inside each duration button */
.timer-btn small,
.timer-btn span {
  font-size: 0.5625rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: var(--track-wide);
  margin-right: calc(-1 * var(--track-wide));
  color: var(--ink-faint);
  transition: color var(--t-fast) var(--ease);
}

.timer-btn[aria-pressed="true"] {
  color: var(--ink);
  background: var(--glass-bg-strong);
  border-color: color-mix(in srgb, var(--accent) 45%, transparent);
  box-shadow: 0 0 16px color-mix(in srgb, var(--accent) 18%, transparent);
}

.timer-btn[aria-pressed="true"] small,
.timer-btn[aria-pressed="true"] span {
  color: color-mix(in srgb, var(--accent) 80%, var(--ink));
}

@media (hover: hover) {
  .timer-btn:hover {
    color: var(--ink);
  }
}

/* Sliders — texture (all modes; "energy" in flowtito) and motion (orbit, flowtito) */
.intensity-label {
  flex: 0 0 4.2em;
}

body:not([data-mode="orbit"]):not([data-mode="flowtito"]) #motion-control {
  display: none;
}

#sliders {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  width: 100%;
}

#controls label {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  width: 100%;
  min-width: 0;
  font-size: 0.625rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: var(--track-wide);
  color: var(--ink-dim);
  cursor: pointer;
}

.range {
  -webkit-appearance: none;
  appearance: none;
  touch-action: none;       /* a drag on a slider moves the slider, never the page */
  flex: 1 1 auto;
  height: 28px;             /* generous touch target */
  background: transparent;
  cursor: pointer;
}

.range:focus-visible {
  outline: 1.5px solid color-mix(in srgb, var(--accent) 75%, transparent);
  outline-offset: 4px;
  border-radius: var(--r-pill);
}

/* track */
.range::-webkit-slider-runnable-track {
  height: 2px;
  border-radius: 1px;
  background: rgba(232, 234, 240, 0.14);
}
.range::-moz-range-track {
  height: 2px;
  border-radius: 1px;
  background: rgba(232, 234, 240, 0.14);
}
.range::-moz-range-progress {
  height: 2px;
  border-radius: 1px;
  background: color-mix(in srgb, var(--accent) 70%, transparent);
}

/* thumb */
.range::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  margin-top: -8px;         /* (thumb - track) / 2 */
  border-radius: 50%;
  background: var(--ink);
  border: 1px solid rgba(10, 12, 16, 0.6);
  box-shadow: 0 0 12px color-mix(in srgb, var(--accent) 45%, transparent);
  transition: transform var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}
.range::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--ink);
  border: 1px solid rgba(10, 12, 16, 0.6);
  box-shadow: 0 0 12px color-mix(in srgb, var(--accent) 45%, transparent);
  transition: transform var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}

@media (hover: hover) {
  .range:hover::-webkit-slider-thumb {
    transform: scale(1.15);
    box-shadow: 0 0 18px color-mix(in srgb, var(--accent) 65%, transparent);
  }
  .range:hover::-moz-range-thumb {
    transform: scale(1.15);
    box-shadow: 0 0 18px color-mix(in srgb, var(--accent) 65%, transparent);
  }
}

.range:active::-webkit-slider-thumb { transform: scale(1.25); }
.range:active::-moz-range-thumb     { transform: scale(1.25); }

/* ------------------------------------------------------------
   Tap hint
   ------------------------------------------------------------ */

#tap-hint {
  margin-top: var(--sp-2);
  text-align: center;
  font-size: 0.6875rem;
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: var(--track-wide);
  color: var(--ink-faint);
  pointer-events: none;
  animation: hint-pulse 3.6s var(--ease) infinite;
}

@keyframes hint-pulse {
  0%, 100% { opacity: 0.45; }
  50%      { opacity: 0.95; }
}

/* The hint sits in the stage flow; keep its box when hidden so
   the ring doesn't shift at session start. */
#tap-hint.hidden {
  display: block !important;
  opacity: 0;
  animation: none;
  transition: opacity var(--t-slow) var(--ease);
}

/* ------------------------------------------------------------
   Disclaimer — quiet legal line below the stage
   ------------------------------------------------------------ */

/* ------------------------------------------------------------
   Flowtito tune panel — a bottom sheet on phones, a card on desktop
   ------------------------------------------------------------ */

/* The "tune" chip leads the scene row; a dot marks a customised scene. */
.tune-btn {
  border-color: color-mix(in srgb, var(--accent) 40%, var(--glass-border));
  color: color-mix(in srgb, var(--accent) 70%, var(--ink));
}

.tune-btn.tuned::after {
  content: "";
  display: inline-block;
  width: 5px;
  height: 5px;
  margin-left: 0.45em;
  border-radius: 50%;
  background: var(--accent);
  vertical-align: middle;
}

#tune-panel {
  width: min(100vw, 30rem);
  max-width: 100vw;
  max-height: min(82dvh, 44rem);
  margin: auto auto 0;
  padding: 0;
  border: 1px solid var(--glass-border-strong);
  border-bottom: 0;
  border-radius: 1.25rem 1.25rem 0 0;
  background: rgba(14, 17, 23, 0.94);
  color: var(--ink);
  backdrop-filter: blur(var(--blur));
  -webkit-backdrop-filter: blur(var(--blur));
  overflow: hidden;
}

#tune-panel::backdrop {
  background: rgba(4, 5, 8, 0.55);
}

@media (min-width: 720px) {
  #tune-panel {
    margin: auto;
    border-bottom: 1px solid var(--glass-border-strong);
    border-radius: 1.25rem;
  }
}

.tune-sheet {
  display: flex;
  flex-direction: column;
  max-height: inherit;
}

.tune-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-2) var(--sp-3);
  border-bottom: 1px solid var(--glass-border);
}

.tune-title {
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: var(--track-wide);
  color: color-mix(in srgb, var(--accent) 70%, var(--ink));
}

.tune-done {
  min-height: 40px;
  padding: 0 0.9rem;
  border-radius: var(--r-pill);
  font-size: 0.6875rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: var(--track-hair);
  color: var(--ink);
  background: var(--glass-bg-strong);
  border: 1px solid var(--glass-border-strong);
}

.tune-body {
  padding: 0 var(--sp-3) calc(var(--sp-3) + env(safe-area-inset-bottom));
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.tune-group {
  border-bottom: 1px solid var(--glass-border);
  padding-bottom: var(--sp-1);
}

.tune-row {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  min-height: 44px;
}

/* Chip rows stack: the label sits above its chips. */
.tune-row.is-seg {
  flex-direction: column;
  align-items: flex-start;
  gap: 0;
  padding-top: var(--sp-1);
}

.tune-label {
  flex: 0 0 auto;
  min-width: 6.5em;
  white-space: nowrap;
  font-size: 0.6875rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: var(--track-hair);
  color: var(--ink-dim);
}

.tune-seg {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  padding: 0.3rem 0;
}

.tune-chip,
.tune-toggle,
.tune-action {
  min-height: 36px;
  padding: 0.3rem 0.7rem;
  border-radius: var(--r-pill);
  font-size: 0.6875rem;
  font-weight: 500;
  color: var(--ink-dim);
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  transition:
    color var(--t-fast) var(--ease),
    background-color var(--t-fast) var(--ease),
    border-color var(--t-fast) var(--ease);
}

.tune-chip {
  min-width: 2.6em;
}

.tune-chip[aria-pressed="true"],
.tune-toggle[aria-checked="true"] {
  color: var(--ink);
  background: var(--glass-bg-strong);
  border-color: color-mix(in srgb, var(--accent) 55%, transparent);
  box-shadow: 0 0 12px color-mix(in srgb, var(--accent) 16%, transparent);
}

.tune-toggle {
  min-width: 3.6em;
  text-transform: uppercase;
  letter-spacing: var(--track-hair);
}

.tune-action {
  display: inline-block;
  margin: 0.35rem 0.4rem 0.35rem 0;
  text-transform: uppercase;
  letter-spacing: var(--track-hair);
}

.tune-reset {
  margin: var(--sp-4) auto 0;
}

.tune-value {
  flex: 0 0 3.4em;
  text-align: right;
  font-size: 0.6875rem;
  font-variant-numeric: tabular-nums;
  color: var(--ink-dim);
}

.tune-hint {
  margin: 0 0 var(--sp-1);
  font-size: 0.6875rem;
  line-height: 1.5;
  color: var(--ink-faint);
}

/* Install — one quiet pill above the disclaimer, with a how-to line for
   browsers (Safari) that have no install prompt of their own. */
#install {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-1);
  margin-top: var(--sp-3);
  transition: opacity var(--t-slow) var(--ease);
}

#install[hidden],
#install-hint[hidden] {
  display: none;
}

#install-btn {
  min-height: 40px;
  padding: 0.4rem 1rem;
  border-radius: var(--r-pill);
  font-size: 0.625rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: var(--track-wide);
  color: var(--ink-dim);
  background: var(--glass-bg);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, var(--glass-border));
  transition: color var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease);
}

@media (hover: hover) {
  #install-btn:hover {
    color: var(--ink);
  }
}

#install-hint {
  max-width: 22rem;
  text-align: center;
  font-size: 0.75rem;
  line-height: 1.5;
  color: var(--ink-dim);
}

body.playing #install {
  opacity: 0.45;
}

#disclaimer {
  max-width: 34rem;
  margin-top: var(--sp-2);
  text-align: center;
  font-size: 0.625rem;
  line-height: 1.6;
  color: var(--ink-faint);
}

/* ------------------------------------------------------------
   Playing state — the chrome recedes, the stage breathes
   ------------------------------------------------------------ */

body.playing #app header,
body.playing #mode-switch,
body.playing #mode-tagline,
body.playing #flow-scenes,
body.playing #controls,
body.playing #disclaimer {
  opacity: 0.45;
}

@media (hover: hover) {
  body.playing #app header:hover,
  body.playing #mode-switch:hover,
  body.playing #flow-scenes:hover,
  body.playing #controls:hover {
    opacity: 1;
  }
}

body.playing #status-text {
  color: color-mix(in srgb, var(--accent) 70%, var(--ink-dim));
}

/* ------------------------------------------------------------
   Desktop refinements
   ------------------------------------------------------------ */

@media (min-width: 720px) {
  #app {
    padding-top: calc(var(--sp-4) + env(safe-area-inset-top));
    padding-bottom: calc(var(--sp-3) + env(safe-area-inset-bottom));
  }

  #stage {
    padding: var(--sp-3) 0;
  }

  /* Keep the whole column on one screen down to ~900px tall. */
  #progress-ring {
    width: min(62vw, 320px, 36vh);
    height: min(62vw, 320px, 36vh);
  }

  #app header h1 {
    font-size: 1.05rem;
  }

  #timer-display {
    font-size: 1.75rem;
    margin-top: var(--sp-4);
  }

  #controls {
    max-width: 24rem;
  }
}

/* Compact phones / small heights: keep the play target ~76px and
   tighten vertical rhythm so nothing scrolls. */
@media (max-width: 480px), (max-height: 640px) {
  #play-btn {
    width: 76px;
    height: 76px;
  }

  #play-btn svg {
    width: 26px;
    height: 26px;
  }

  #stage {
    padding: var(--sp-3) 0;
  }

  #mode-switch {
    margin-top: var(--sp-3);
  }

  /* Five modes must fit a 360px phone: tighter pills, hairline tracking. */
  .mode-btn {
    padding: 0.55rem 0.5rem;
    font-size: 0.625rem;
    letter-spacing: 0.03em;
  }


  #mode-tagline {
    font-size: 0.5625rem;
    min-height: 3em; /* orbit's line wraps to two on phones; reserve them */
  }
}

/* Phones: thumb-sized targets, and the whole instrument (modes, ring,
   timer, sliders) on one screen with Safari's toolbars showing. Only the
   disclaimer sits below the fold. */
@media (max-width: 480px) {
  #app {
    padding-top: calc(var(--sp-2) + env(safe-area-inset-top));
    padding-left: calc(var(--sp-2) + env(safe-area-inset-left));
    padding-right: calc(var(--sp-2) + env(safe-area-inset-right));
  }

  #mode-switch {
    width: 100%;
    margin-top: var(--sp-2);
  }

  .mode-btn {
    flex: 1 1 0;
    padding: 0.55rem 0.2rem;
    font-size: 0.6875rem;
    letter-spacing: 0.02em;
  }

  /* Orbit's and Flowtito's lines can wrap to two; the rest fit one. */
  body:not([data-mode="orbit"]):not([data-mode="flowtito"]) #mode-tagline {
    min-height: 1.5em;
  }

  /* Scenes: one sideways-scrolling row of full-size chips that runs to the
     screen edges, instead of six tiny ones squeezed to fit. */
  #flow-scenes {
    flex-wrap: nowrap;
    justify-content: flex-start;
    align-self: stretch;
    gap: 0.4rem;
    margin-left: calc(-1 * var(--sp-2));
    margin-right: calc(-1 * var(--sp-2));
    padding: 2px var(--sp-2);
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scroll-snap-type: x proximity;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    -webkit-mask-image: linear-gradient(90deg, transparent, #000 1rem, #000 calc(100% - 1.6rem), transparent);
    mask-image: linear-gradient(90deg, transparent, #000 1rem, #000 calc(100% - 1.6rem), transparent);
  }

  #flow-scenes::-webkit-scrollbar {
    display: none;
  }

  .scene-btn {
    flex: 0 0 auto;
    min-height: 40px;
    padding: 0.4rem 0.9rem;
    font-size: 0.6875rem;
    scroll-snap-align: center;
  }

  /* The ring gives way to the controls on short screens. */
  #progress-ring {
    width: min(62vw, 320px, 31dvh);
    height: min(62vw, 320px, 31dvh);
  }

  #stage {
    padding: var(--sp-2) 0;
  }

  #timer-display {
    margin-top: var(--sp-2);
  }

  #tap-hint {
    margin-top: var(--sp-1);
  }

  #controls {
    gap: var(--sp-2);
  }
}

/* Touch: taller slider tracks to grab, no grey flash on tap. */
@media (pointer: coarse) {
  .range {
    height: 40px;
  }

  button,
  .range,
  label {
    -webkit-tap-highlight-color: transparent;
  }
}

/* Very short landscape phones: shrink the ring instead of scrolling. */
@media (max-height: 520px) {
  #progress-ring {
    width: min(46vh, 240px);
    height: min(46vh, 240px);
  }

  #timer-display {
    margin-top: var(--sp-2);
    font-size: 1.25rem;
  }
}

/* ------------------------------------------------------------
   Reduced motion — keep the breath guide (it is the content),
   drop everything decorative.
   ------------------------------------------------------------ */

@media (prefers-reduced-motion: reduce) {
  #stage::before,
  #tap-hint {
    animation: none;
  }

  #breath-overlay {
    animation: none;
  }

  #play-btn,
  .range::-webkit-slider-thumb,
  .range::-moz-range-thumb {
    transition: none;
  }

  @media (hover: hover) {
    #play-btn:hover { transform: none; }
  }
  #play-btn:active { transform: none; }

  /* The breath circle transition is the exercise itself — keep it,
     but linearize so it reads as a gentle cue, not a lunge. */
  #breath-circle {
    transition-timing-function: linear;
  }
}


/* ------------------------------------------------------------
   v14: full tune panel, "more" scenes, Focus Lab
   ------------------------------------------------------------ */

body {
  overflow-x: clip;
}

/* Extra presets hide behind the "more" chip. */
.scene-btn.is-more {
  display: none;
}

#flow-scenes.show-more .scene-btn.is-more {
  display: inline-block;
}

.more-btn {
  border-style: dashed;
}

#tune-panel {
  touch-action: pan-y;
  overscroll-behavior: contain;
}

/* In the sheet a slider still lets a vertical swipe scroll the list. */
#tune-panel .range {
  touch-action: pan-y;
}

details.tune-group > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 40px;
  cursor: pointer;
  list-style: none;
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: var(--track-wide);
  color: var(--ink-dim);
}

details.tune-group > summary::-webkit-details-marker {
  display: none;
}

details.tune-group > summary::after {
  content: "+";
  font-size: 1rem;
  font-weight: 400;
  color: var(--ink-faint);
}

details.tune-group[open] > summary::after {
  content: "-";
}

details.tune-group[open] > summary {
  color: color-mix(in srgb, var(--accent) 60%, var(--ink));
}

.tune-about:empty {
  display: none;
}

.tune-hint b {
  font-weight: 600;
  color: var(--ink-dim);
}

.tune-slot:empty {
  display: none;
}

.tune-slot {
  margin: 0.4rem 0;
  font-size: 0.75rem;
  color: var(--ink-dim);
}

.tune-slot a {
  color: var(--accent);
}

.mix-code {
  display: block;
  width: 100%;
  min-height: 4.2em;
  padding: 0.5rem 0.6rem;
  border-radius: 0.6rem;
  border: 1px solid var(--glass-border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--ink);
  font: 0.6875rem/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
  word-break: break-all;
  resize: none;
  user-select: text;
  -webkit-user-select: text;
}

.lab-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.6875rem;
}

.lab-table th,
.lab-table td {
  padding: 0.3rem 0.35rem;
  text-align: left;
  border-bottom: 1px solid var(--glass-border);
}

.lab-table th {
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: var(--track-hair);
  color: var(--ink-faint);
}

.lab-table tr.best td {
  color: var(--accent);
}

#lab {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  padding: 2rem 1.5rem calc(2rem + env(safe-area-inset-bottom));
  background: rgba(8, 10, 14, 0.97);
  text-align: center;
  touch-action: none;
}

#lab[hidden] {
  display: none;
}

#lab-stim {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 150px;
  font-size: 96px;
  font-weight: 300;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

#lab-msg {
  max-width: 28rem;
  min-height: 6em;
  font-size: 0.875rem;
  color: var(--ink-dim);
}

#lab-msg b {
  color: var(--ink);
  font-weight: 600;
}

.lab-btns [hidden] {
  display: none;
}
