:root {
  --bg: #0b0f19;
  --card: rgba(30, 41, 59, 0.6);
  --text: #f1f5f9;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent-2: #818cf8;
  --success: #22d3ee;
  --danger: #f87171;
  --glass-border: rgba(255, 255, 255, 0.08);
  --shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.6);
  --radius: 16px;
  --quiet-panel: rgba(15, 23, 42, 0.28);
  --quiet-circle: rgba(56, 189, 248, 0.16);
  --quiet-circle-border: rgba(56, 189, 248, 0.55);
  --quiet-glow: rgba(56, 189, 248, 0.18);
  --quiet-dot: rgba(148, 163, 184, 0.35);
  --quiet-dot-active: rgba(56, 189, 248, 0.25);
  --quiet-input: rgba(15, 23, 42, 0.35);
  --phase-7: #1f5673;
  --phase-6: #256580;
  --phase-5: #2c758f;
  --phase-4: #34869f;
  --phase-3: #3f98ae;
  --phase-2: #52abbc;
  --phase-1: #6cbec9;
  --phase-0: #8ed2d5;
  --radiant-1: 56, 189, 248;
  --radiant-2: 129, 140, 248;
  --radiant-3: 244, 114, 182;
  --radiant-1-alpha: 0.5;
  --radiant-2-alpha: 0.44;
  --radiant-3-alpha: 0.22;
  --radiant-radius: 36%;
  --pulse-low: 0.2;
  --pulse-high: 0.6;
}

[data-theme="light"] {
  --bg: #eaf1f6;
  --card: rgba(255, 255, 255, 0.2);
  --text: #17293a;
  --muted: #536b80;
  --accent: #236f92;
  --accent-2: #6b73b8;
  --success: #2b9c9c;
  --danger: #c4707a;
  --glass-border: rgba(23, 41, 58, 0.09);
  --shadow: 0 20px 45px -18px rgba(23, 52, 74, 0.28);
  --quiet-panel: rgba(255, 255, 255, 0.2);
  --quiet-circle: rgba(35, 111, 146, 0.12);
  --quiet-circle-border: rgba(35, 111, 146, 0.5);
  --quiet-glow: rgba(35, 111, 146, 0.15);
  --quiet-dot: rgba(83, 107, 128, 0.30);
  --quiet-dot-active: rgba(35, 111, 146, 0.22);
  --quiet-input: rgba(255, 255, 255, 0.8);
  /* The countdown reads as a rise in contrast as each phase runs down. The
     start must still be a visible outline against the pale background, so the
     ramp lifts from #7eaac5 (~1.72:1 composited) to the deep teal end. */
  --phase-7: #7eaac5;
  --phase-6: #71a2be;
  --phase-5: #6499b6;
  --phase-4: #5791af;
  --phase-3: #4a88a8;
  --phase-2: #3d80a1;
  --phase-1: #307799;
  --phase-0: #236f92;
  /* Deeper, more saturated lobes: the bright dark-theme colours wash into one
     low-contrast haze against the pale background. */
  --radiant-1: 12, 96, 145;
  --radiant-2: 72, 61, 160;
  --radiant-3: 158, 45, 110;
  --radiant-1-alpha: 0.55;
  --radiant-2-alpha: 0.5;
  --radiant-3-alpha: 0.5;
  --radiant-radius: 24%;
  --pulse-high: 0.8;
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  line-height: 1.5;
  overflow-x: hidden;
}

/* Contain the background layer inside body's own stacking context. Without
   this, a negative-z layer participates in the root context and Safari paints
   it behind body's opaque background, hiding the glow entirely. */
body { isolation: isolate; }

/* The glow is a real element rather than body::before: Safari does not visually
   update a transform animation on the pseudo-element (prefixed keyframes and
   layer hints did not help), while a real element animates reliably. The glow
   lobes orbit the centre on a centred square larger than the viewport diagonal
   (150vmax), so the background stays covered at every rotation angle — no edge
   gaps at 90/270 degrees. Pure CSS, compositor-only, behind all content; the
   global reduced-motion reset below switches it off. */
.ambient-bg {
  position: fixed;
  top: 50%;
  left: 50%;
  width: 150vmax;
  height: 150vmax;
  margin: -75vmax 0 0 -75vmax;
  z-index: -1;
  pointer-events: none;
  -webkit-transform: rotate(0deg);
  transform: rotate(0deg);
  -webkit-animation: ambientDrift 45s linear infinite;
  animation: ambientDrift 45s linear infinite;
}

/* Five glow lobes orbit together; each pulses on its own clock. Distances
   from the layer centre are 30 / 33 / 42 / 45vmax, with the fifth (temporary)
   lobe at roughly 49vmax. */
.ambient-radiant {
  position: absolute;
  inset: 0;
}
.ambient-radiant:nth-child(1) {
  background: radial-gradient(circle at 30% 50%, rgba(var(--radiant-1), var(--radiant-1-alpha)) 0%, transparent var(--radiant-radius));
  -webkit-animation: ambientPulse 12s ease-in-out 0s infinite;
  animation: ambientPulse 12s ease-in-out 0s infinite;
}
.ambient-radiant:nth-child(2) {
  background: radial-gradient(circle at 72% 50%, rgba(var(--radiant-2), var(--radiant-2-alpha)) 0%, transparent var(--radiant-radius));
  -webkit-animation: ambientPulse 9s ease-in-out -3s infinite;
  animation: ambientPulse 9s ease-in-out -3s infinite;
}
.ambient-radiant:nth-child(3) {
  background: radial-gradient(circle at 50% 22%, rgba(var(--radiant-1), var(--radiant-1-alpha)) 0%, transparent var(--radiant-radius));
  -webkit-animation: ambientPulse 15s ease-in-out -6s infinite;
  animation: ambientPulse 15s ease-in-out -6s infinite;
}
.ambient-radiant:nth-child(4) {
  background: radial-gradient(circle at 50% 80%, rgba(var(--radiant-2), var(--radiant-2-alpha)) 0%, transparent var(--radiant-radius));
  -webkit-animation: ambientPulse 11s ease-in-out -2s infinite;
  animation: ambientPulse 11s ease-in-out -2s infinite;
}
/* Temporary fifth lobe: a warm rosy accent, unusual against the cool field but
   an analogous neighbour of the sky/indigo family. Own position and pulse clock. */
.ambient-radiant:nth-child(5) {
  background: radial-gradient(circle at 28% 74%, rgba(var(--radiant-3), var(--radiant-3-alpha)) 0%, transparent var(--radiant-radius));
  -webkit-animation: ambientPulse 13s ease-in-out -5s infinite;
  animation: ambientPulse 13s ease-in-out -5s infinite;
}

@-webkit-keyframes ambientDrift {
  from { -webkit-transform: rotate(0deg); transform: rotate(0deg); }
  to   { -webkit-transform: rotate(360deg); transform: rotate(360deg); }
}

@keyframes ambientDrift {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

/* Slow intensity pulse on the same layer — human-directed amendments 2026-11-23.
   Trough stays 0.2; the light theme raises the peak to 0.8 and uses deeper
   colours so the four lobes stay distinguishable against the pale background. */
@-webkit-keyframes ambientPulse {
  0%, 100% { opacity: var(--pulse-low); }
  50%      { opacity: var(--pulse-high); }
}

@keyframes ambientPulse {
  0%, 100% { opacity: var(--pulse-low); }
  50%      { opacity: var(--pulse-high); }
}

.wrap {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 72px 24px 48px;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

button {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border: none;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.2s, opacity 0.2s;
  font-family: inherit;
}

button:active { transform: translateY(1px); }
button:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-ghost {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  border: 1px solid var(--glass-border);
}
[data-theme="light"] .btn-ghost {
  background: rgba(0, 0, 0, 0.05);
  border-color: rgba(0, 0, 0, 0.12);
}
.btn-ghost:hover { background: rgba(255, 255, 255, 0.14); }

.btn-danger { background: var(--danger); color: #fff; }

/* Corner icon buttons */
.top-actions {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 50;
  display: flex;
  gap: 10px;
}
.icon-toggle {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--glass-border);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}
.icon-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.icon-toggle:disabled { opacity: 0.3; cursor: default; }

.locale-select {
  height: 40px;
  max-width: 132px;
  padding: 0 8px;
  border-radius: 10px;
  border: 1px solid var(--glass-border);
  background: var(--card);
  color: var(--text);
  font-family: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}
.locale-select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[data-theme="light"] .locale-select option { background: #fff; color: #17293a; }

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--card);
  border: 1px solid var(--glass-border);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 0.85rem;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: transform 0.25s, opacity 0.25s;
  z-index: 100;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }

/* ---------- The Quiet Corner ---------- */
.quiet {
  max-width: 900px;
  width: 100%;
  text-align: center;
  animation: fadeIn 0.6s ease-out 0.1s both;
}

.quiet-title {
  font-size: 2.4rem;
  letter-spacing: -0.01em;
  margin-bottom: 8px;
  color: var(--text);
}

.quiet-intro {
  color: var(--muted);
  font-size: 1.1rem;
  margin-bottom: 28px;
}

.quiet-block {
  background: var(--quiet-panel);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  border-radius: 22px;
  padding: 40px 36px;
  margin-top: 16px;
  min-height: 520px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.quiet-block h3 {
  font-size: 1.1rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--accent);
  margin-bottom: 18px;
}

/* Two-row panels: the heading IS the content row, so drop the label styling.
   Each utility keeps exactly one content row plus its button row. */
.quiet-block h3.breath-cue,
.quiet-block h3.quiet-prompt,
.quiet-block h3.one-line,
.quiet-block h3.timer-heading {
  text-transform: none;
  letter-spacing: normal;
  color: var(--text);
  font-size: 1.6rem;
  font-weight: 600;
  margin-top: 0;
  margin-bottom: 0;
}

.quiet-sep { color: var(--muted); }

.quiet-controls {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  margin-top: 14px;
}

/* The breathing buttons start hidden in the static HTML so the first paint is
   stable; the author `display: flex` rule above would otherwise beat the UA
   [hidden] rule. The no-JS sheet overrides this so every tool stays visible. */
.quiet-controls[hidden] {
  display: none;
}

/* Revealing the breathing buttons must not lift the circle. Their space is
   reserved from first paint and only their visibility changes, so the centred
   panel keeps an identical layout. `visibility` also keeps the hidden buttons
   out of the accessibility tree and the tab order. */
.quiet-breathe .quiet-controls[hidden] {
  display: flex;
  visibility: hidden;
}

.quiet-controls .quiet-check { margin-top: 0; }

.note-saved {
  font-size: 0.9rem;
  color: var(--muted);
}

.quiet-controls button {
  font-size: 0.98rem;
  padding: 12px 18px;
}

/* The speaker sits in the heading row, just after the time status. */
.timer-heading .sound-toggle {
  display: inline-flex;
  vertical-align: middle;
  width: 1.6em;
  height: 1.6em;
  margin-left: 8px;
  padding: 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.timer-heading .sound-toggle[aria-pressed="true"] { color: var(--accent); }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Breathing pacer */
.breath-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.breath-circle {
  width: 320px;
  height: 320px;
  box-sizing: border-box;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  text-align: center;
  --phase-color: var(--quiet-circle-border);
  background-color: color-mix(in srgb, var(--phase-color) 16%, transparent);
  border: 2px solid color-mix(in srgb, var(--phase-color) 72%, transparent);
  box-shadow: 0 0 34px color-mix(in srgb, var(--phase-color) 28%, transparent);
  transform: scale(var(--breath-scale, 0.9));
  transition: transform var(--breath-duration, 0.6s) ease-in-out,
              background-color 1s linear, border-color 1s linear, box-shadow 1s linear;
  /* The circle scales up to 1.14x; keep that overflow clear of the buttons. */
  margin-bottom: 28px;
  cursor: pointer;
}

/* The countdown, felt as color: the circle gently brightens as each phase runs
   down, then eases back to calm when the next one begins. No digits anywhere. */
.breath-circle[data-progress="7"] { --phase-color: var(--phase-7); }
.breath-circle[data-progress="6"] { --phase-color: var(--phase-6); }
.breath-circle[data-progress="5"] { --phase-color: var(--phase-5); }
.breath-circle[data-progress="4"] { --phase-color: var(--phase-4); }
.breath-circle[data-progress="3"] { --phase-color: var(--phase-3); }
.breath-circle[data-progress="2"] { --phase-color: var(--phase-2); }
.breath-circle[data-progress="1"] { --phase-color: var(--phase-1); }
.breath-circle[data-progress="0"] { --phase-color: var(--phase-0); }

.breath-circle[data-phase="inhale"],
.breath-circle[data-phase="hold-in"] { --breath-scale: 1.14; }
.breath-circle[data-phase="exhale"],
.breath-circle[data-phase="hold-out"] { --breath-scale: 0.82; }
.breath-circle[data-phase="idle"] { --breath-scale: 0.9; --breath-duration: 0.6s; }
.breath-circle[data-seconds="4"] { --breath-duration: 4s; }
.breath-circle[data-seconds="7"] { --breath-duration: 7s; }

/* The idle circle is the one-click start control, so it needs the same clear
   keyboard focus cue as the other controls. While a rhythm runs it drops out
   of the tab order and this cue no longer applies. */
.breath-circle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
}

/* While a rhythm runs the circle is only the phase indicator, not a control. */
.breath-circle[aria-disabled="true"] {
  cursor: default;
}

.breath-cue {
  font-size: 1.6rem;
  font-weight: 600;
  line-height: 1.25;
  color: var(--text);
}

/* Grounding */
.quiet-step {
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
}

.quiet-prompt {
  font-size: 1.6rem;
  font-weight: 600;
  margin-top: 4px;
}

.quiet-hint {
  font-size: 0.95rem;
  font-style: italic;
  color: var(--muted);
}

/* One thing */
.one-line {
  font-size: 1.6rem;
  font-style: italic;
  line-height: 1.6;
  padding: 6px 4px;
}

/* The reflection sits in the same content row as the daily line. It is static
   text, not a live region or a control: it adds nothing to announce or tap. */
.one-helper {
  margin: 2px 4px 0;
  font-size: 1rem;
  font-style: italic;
  color: var(--muted);
  line-height: 1.5;
}

/* Notepad */
#goodNotes {
  width: 100%;
  resize: vertical;
  border-radius: 10px;
  border: 1px solid var(--glass-border);
  background: var(--quiet-input);
  color: var(--text);
  padding: 12px;
  font: inherit;
  font-size: 1.25rem;
}

#goodNotes:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* Timer: heading and live status share one heading row. */
.quiet-block h3.timer-heading {
  font-size: 1.5rem;
  font-style: italic;
}

.timer-status {
  color: var(--success);
}

.quiet-footer {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 22px;
  line-height: 1.6;
}

/* One utility at a time, with a single large "next" button on the right */
.quiet-stage {
  display: flex;
  align-items: stretch;
  justify-content: center;
  gap: 18px;
  width: 100%;
  margin-top: 18px;
}
.quiet-panels { flex: 1 1 auto; min-width: 0; }
.quiet-next {
  flex: 0 0 130px;
  align-self: center;
  min-height: 240px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 18px 12px;
  border-radius: 22px;
  background: var(--quiet-panel);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  color: var(--text);
  font-size: 1rem;
  font-weight: 600;
  text-align: center;
}
.quiet-next:hover { border-color: var(--accent); background: var(--quiet-dot-active); }
.quiet-next-arrow { font-size: 3.4rem; line-height: 1; color: var(--accent); }
.quiet-next-name { font-size: 1rem; }
.quiet-block[hidden] { display: none; }

@media (max-width: 640px) {
  .quiet-stage { flex-direction: column; align-items: stretch; }
  .quiet-block { min-height: auto; padding: 30px 22px; }
  .breath-circle { width: 240px; height: 240px; }
  .quiet-title { font-size: 2rem; }
  .quiet-prompt, .one-line, .breath-cue { font-size: 1.3rem; }
  .quiet-next {
    flex: 0 0 auto;
    width: 100%;
    min-height: 64px;
    flex-direction: row;
    gap: 14px;
  }
  .quiet-next-arrow { font-size: 2rem; }
}

/* ---------- Reduced motion ----------
   Nothing moves under this setting: every animation and transition is switched
   off. Documented choice for the element that is not part of the five panels:
   the toast stays available, but appears and disappears INSTANTLY (static)
   instead of sliding/fading in. The breathing pacer keeps its colour
   progression as the time signal — colour changes are instant and the circle
   holds one fixed size — so the technique still works without any movement.
   Colours still come from custom properties, so this applies unchanged in both
   themes. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }

  /* One static scale. data-progress still drives --phase-color, so colour
     remains the (now instant) time signal; the shape never grows or shrinks. */
  .breath-circle,
  .breath-circle[data-phase] {
    --breath-scale: 0.9;
  }

  button:active { transform: none; }
}

/* Responsive */
@media (max-width: 480px) {
  button { width: 100%; justify-content: center; }
}
