:root {
  color-scheme: dark;
  --bg-0: #04060d;
  --bg-1: #0c1430;
  --ink: #e9ecf5;
  --ink-soft: #aeb6cc;
  --ink-faint: #7b84a0;
  --line: rgba(233, 236, 245, 0.16);
  --line-strong: rgba(233, 236, 245, 0.34);
  --fill: rgba(233, 236, 245, 0.09);
  --sea: #8fd3d0;
  --dusk: #6b7fe0;
  --lilac: #a58ae0;
  --focus: #c3ccff;
  --serif: ui-serif, "New York", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --breath: 10s; /* in for 4 seconds, out for 6 */
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  min-height: 100vh;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  background: radial-gradient(120% 80% at 50% 28%, var(--bg-1) 0%, var(--bg-0) 72%) fixed, var(--bg-0);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  overflow-x: hidden;
}

/* ---- slow drifting light behind everything */

.sky { position: fixed; inset: 0; z-index: -1; overflow: hidden; pointer-events: none; }
.sky span {
  position: absolute;
  width: 70vmax;
  height: 70vmax;
  border-radius: 50%;
  opacity: 0.16;
  background: radial-gradient(circle, var(--c) 0%, transparent 65%);
  animation: drift 90s ease-in-out infinite alternate;
}
.sky span:nth-child(1) { --c: var(--dusk); left: -25vmax; top: -22vmax; }
.sky span:nth-child(2) { --c: var(--sea); right: -32vmax; bottom: -30vmax; opacity: 0.11; animation-duration: 120s; animation-delay: -40s; }
.sky span:nth-child(3) { --c: var(--lilac); left: 15vmax; bottom: -48vmax; opacity: 0.09; animation-duration: 150s; animation-delay: -80s; }

@keyframes drift {
  from { transform: translate(0, 0) scale(1); }
  to { transform: translate(8vmax, 6vmax) scale(1.15); }
}

/* ---- layout */

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 16px 8px;
  text-align: center;
}

h1 {
  margin: 0;
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(2.2rem, 9vw, 3.5rem);
  line-height: 1.08;
  letter-spacing: 0.01em;
}

.tagline {
  margin: 0.6rem 0 0;
  color: var(--ink-soft);
  font-size: clamp(1rem, 3.8vw, 1.15rem);
}

/* ---- the orb: play button and breathing guide */

.orb {
  --size: min(62vw, 44vh, 300px);
  position: relative;
  display: grid;
  place-items: center;
  width: var(--size);
  height: var(--size);
  margin: clamp(32px, 7vh, 64px) 0 clamp(24px, 5vh, 44px);
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  color: #fff;
  cursor: pointer;
}
.orb:focus-visible { outline: 2px solid var(--focus); outline-offset: 10px; }

.orb .halo,
.orb .core { position: absolute; border-radius: 50%; }

.orb .halo {
  inset: -26%;
  background: radial-gradient(circle, rgba(143, 211, 208, 0.34) 0%, rgba(107, 127, 224, 0.16) 42%, transparent 68%);
  opacity: 0.45;
  animation: glow var(--breath) ease-in-out infinite paused;
}

.orb .core {
  inset: 0;
  background:
    radial-gradient(circle at 34% 26%, rgba(255, 255, 255, 0.34), rgba(255, 255, 255, 0) 40%),
    radial-gradient(circle at 50% 56%, var(--sea) 0%, var(--dusk) 52%, var(--lilac) 100%);
  box-shadow: 0 0 70px 4px rgba(107, 127, 224, 0.3), inset 0 -22px 50px rgba(4, 6, 13, 0.3);
  filter: saturate(0.7) brightness(0.78);
  transform: scale(0.86);
  transition: filter 2s ease;
  animation: breathe var(--breath) ease-in-out infinite paused;
}

.orb .icon {
  position: relative;
  width: 22%;
  height: 22%;
  fill: currentColor;
  opacity: 0.9;
  transition: opacity 0.4s ease;
  filter: drop-shadow(0 1px 6px rgba(4, 6, 13, 0.35));
}
.orb .pause { display: none; }

[data-state="playing"] .orb .core { filter: none; }
[data-state="playing"] .orb .core,
[data-state="playing"] .orb .halo { animation-play-state: running; }

[data-state="playing"] .orb .play,
[data-state="loading"] .orb .play,
[data-state="retrying"] .orb .play { display: none; }
[data-state="playing"] .orb .pause,
[data-state="loading"] .orb .pause,
[data-state="retrying"] .orb .pause { display: block; opacity: 0.28; }
.orb:hover .pause,
.orb:focus-visible .pause { opacity: 0.75 !important; }

[data-state="loading"] .orb .halo,
[data-state="retrying"] .orb .halo { animation: shimmer 1.6s ease-in-out infinite; }

[data-state="missing"] .orb,
[data-state="unsupported"] .orb { cursor: default; opacity: 0.5; }

@keyframes breathe {
  0%, 100% { transform: scale(0.86); }
  40% { transform: scale(1); }
}
@keyframes glow {
  0%, 100% { opacity: 0.35; transform: scale(0.9); }
  40% { opacity: 0.9; transform: scale(1.04); }
}
@keyframes shimmer {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 0.7; }
}

/* ---- words under the orb */

.status {
  margin: 0;
  min-height: 1.5em;
  color: var(--ink-soft);
  font-size: 1.05rem;
}

.countdown {
  margin: 0.3rem 0 0;
  min-height: 1.4em;
  color: var(--ink-faint);
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
}

/* ---- sleep / meditation timer */

.timer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
  max-width: 420px;
  margin-top: clamp(16px, 4vh, 32px);
}

.timer-label {
  width: 100%;
  margin-bottom: 2px;
  color: var(--ink-faint);
  font-size: 0.75rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.timer button {
  min-height: 40px;
  padding: 0 15px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--ink-soft);
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease;
}
.timer button:hover { border-color: var(--line-strong); color: var(--ink); }
.timer button[aria-pressed="true"] { background: var(--fill); border-color: var(--line-strong); color: var(--ink); }
.timer button:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

footer {
  padding: 20px 16px 28px;
  color: var(--ink-faint);
  font-size: 0.85rem;
  text-align: center;
}

.debug {
  position: fixed;
  left: 8px;
  bottom: 8px;
  z-index: 10;
  margin: 0;
  padding: 8px 10px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.7);
  color: #cfe8e6;
  font: 11px/1.45 ui-monospace, Menlo, monospace;
  text-align: left;
  white-space: pre;
}

@media (prefers-reduced-motion: reduce) {
  .sky span { animation: none; }
  .orb .core { animation: none; transform: scale(0.94); }
  .orb .halo { animation-name: glow-still; }
}
@keyframes glow-still {
  0%, 100% { opacity: 0.3; }
  40% { opacity: 0.9; }
}
