/* ───────────────────────── Gloaming ─────────────────────────
   Atmospheric / nocturnal. Twilight gradient ground, glow as state,
   one functional accent (glow-gold). Build matches design.md. */

:root {
  /* twilight sky */
  --zenith:  #1A1033;
  --dusk:    #2E1A47;
  --horizon: #5B2A4A;
  --ember:   #E8956B;

  /* the single functional accent */
  --gold:      #F4B860;
  --gold-soft: rgba(244, 184, 96, 0.20);
  --gold-glow: rgba(244, 184, 96, 0.45);
  --rose:      #E0789B;

  /* veils + type */
  --veil:        rgba(255, 253, 250, 0.06);
  --veil-strong: rgba(255, 253, 250, 0.10);
  --veil-border: rgba(255, 253, 250, 0.12);
  --bone:        #F5F0EA;
  --bone-muted:  rgba(245, 240, 234, 0.62);
  --bone-faint:  rgba(245, 240, 234, 0.38);

  /* spacing — a loose breathing rhythm */
  --s1: 4px;  --s2: 8px;  --s3: 12px; --s4: 20px;
  --s5: 32px; --s6: 52px; --s7: 84px;

  --ease-breath: cubic-bezier(0.37, 0, 0.63, 1); /* sine-like */
  --ease-out:    cubic-bezier(0.16, 1, 0.3, 1);
  --radius:      26px;
}

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

/* the [hidden] attribute must always win over component display rules
   (e.g. .btn{display:inline-flex}) */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  font-family: "Hanken Grotesk", system-ui, sans-serif;
  font-weight: 400;
  color: var(--bone);
  background: var(--zenith);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

button { font: inherit; color: inherit; cursor: pointer; }

/* ───────── living twilight sky ───────── */
.sky { position: fixed; inset: 0; z-index: -2; overflow: hidden; }
.sky__drift {
  position: absolute; inset: -25%;
  background:
    radial-gradient(120% 90% at 50% 118%, var(--horizon) 0%, transparent 55%),
    linear-gradient(177deg, var(--zenith) 0%, var(--dusk) 52%, var(--horizon) 100%);
  animation: drift 64s var(--ease-breath) infinite alternate;
}
.sky__ember {
  position: absolute; left: 50%; bottom: -22%;
  width: 130vmax; height: 70vmax; transform: translateX(-50%);
  background: radial-gradient(closest-side, rgba(232,149,107,0.30), rgba(232,149,107,0.06) 55%, transparent 75%);
  filter: blur(8px);
  animation: emberPulse 12s ease-in-out infinite alternate;
}
.sky__stars {
  position: absolute; inset: 0; opacity: 0.5;
  background-image:
    radial-gradient(1px 1px at 18% 22%, rgba(255,255,255,0.7), transparent),
    radial-gradient(1px 1px at 72% 14%, rgba(255,255,255,0.5), transparent),
    radial-gradient(1.4px 1.4px at 44% 9%,  rgba(255,255,255,0.6), transparent),
    radial-gradient(1px 1px at 88% 30%, rgba(255,255,255,0.45), transparent),
    radial-gradient(1px 1px at 28% 6%,  rgba(255,255,255,0.5), transparent),
    radial-gradient(1.2px 1.2px at 60% 24%, rgba(255,255,255,0.5), transparent);
  animation: twinkle 9s ease-in-out infinite alternate;
}
@keyframes drift { from { transform: translateY(0) rotate(0deg); } to { transform: translateY(-3%) rotate(1.2deg); } }
@keyframes emberPulse { from { opacity: 0.7; } to { opacity: 1; } }
@keyframes twinkle { from { opacity: 0.35; } to { opacity: 0.6; } }

/* ───────── stage / views ───────── */
.stage {
  position: relative;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: max(var(--s5), env(safe-area-inset-top)) var(--s4) 132px;
}
.view {
  width: min(100%, 32rem);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s5);
  animation: viewIn 360ms var(--ease-out) both;
}
.view[hidden] { display: none; }
@keyframes viewIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

.view__head { text-align: center; }
.eyebrow {
  margin: 0 0 var(--s1);
  font-size: 0.72rem; font-weight: 500;
  letter-spacing: 0.42em; text-transform: uppercase;
  color: var(--gold);
}
.view__title {
  margin: 0;
  font-family: "Fraunces", serif;
  font-weight: 300; font-size: clamp(2.6rem, 11vw, 3.8rem);
  line-height: 1; letter-spacing: -0.01em;
}

/* ───────── breath orb ───────── */
.orb-stage { display: flex; flex-direction: column; align-items: center; gap: var(--s5); }
.orb {
  position: relative;
  width: min(72vw, 320px); aspect-ratio: 1;
  display: grid; place-items: center;
  transform: scale(0.62);
  transition: transform 4s var(--ease-breath);
  will-change: transform;
}
.orb__body {
  width: 100%; height: 100%; border-radius: 50%;
  background: radial-gradient(circle at 50% 42%,
    #FBE6C4 0%, var(--gold) 26%, var(--rose) 62%, rgba(224,120,155,0.15) 84%, transparent 92%);
  box-shadow: 0 0 70px 12px var(--gold-glow), inset 0 0 50px rgba(255,240,220,0.35);
  transition: opacity 4s var(--ease-breath), box-shadow 1.2s var(--ease-out);
}
.orb__bloom {
  position: absolute; inset: -34%;
  border-radius: 50%;
  background: radial-gradient(circle, var(--gold-soft) 0%, transparent 62%);
  opacity: 0.7;
  transition: opacity 1.2s var(--ease-out);
  pointer-events: none;
}
.orb.is-pulsing .orb__bloom { animation: bloomPulse 1.6s var(--ease-out); }
@keyframes bloomPulse { 0% { opacity: 0.7; } 35% { opacity: 1; transform: scale(1.12); } 100% { opacity: 0.7; transform: scale(1); } }

.orb-caption { text-align: center; min-height: 3.4em; }
.phase {
  margin: 0;
  font-family: "Fraunces", serif; font-weight: 400;
  font-size: clamp(1.7rem, 6vw, 2.2rem); letter-spacing: -0.01em;
  transition: opacity 0.6s var(--ease-out);
}
.phase-sub { margin: var(--s2) 0 0; color: var(--bone-muted); font-size: 0.95rem; }

/* ───────── pattern / duration / scape pills ───────── */
.patterns, .durations { display: flex; flex-wrap: wrap; gap: var(--s2); justify-content: center; }
.pill {
  border: 1px solid var(--veil-border);
  background: var(--veil);
  color: var(--bone-muted);
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 0.9rem; font-weight: 500;
  line-height: 1.1; min-height: 44px;
  display: inline-flex; flex-direction: column; align-items: center; gap: 1px;
  backdrop-filter: blur(8px);
  transition: color 0.22s var(--ease-out), background 0.22s var(--ease-out),
              border-color 0.22s var(--ease-out), box-shadow 0.3s var(--ease-out), transform 0.16s var(--ease-out);
}
.pill small { font-size: 0.7rem; font-weight: 400; color: var(--bone-faint); letter-spacing: 0.02em; }
.pill:hover { color: var(--bone); border-color: var(--veil-strong); }
.pill:active { transform: scale(0.97); }
.pill.is-active {
  color: #1A1033; background: var(--gold);
  border-color: var(--gold);
  box-shadow: 0 0 28px var(--gold-glow);
}
.pill.is-active small { color: rgba(26,16,51,0.7); }

/* ───────── controls / buttons ───────── */
.controls { display: flex; flex-direction: column; align-items: center; gap: var(--s3); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  border: 1px solid transparent; border-radius: 999px;
  padding: 15px 34px; min-height: 52px;
  font-size: 1.02rem; font-weight: 600; letter-spacing: 0.01em;
  transition: transform 0.18s var(--ease-out), box-shadow 0.3s var(--ease-out),
              background 0.25s var(--ease-out), opacity 0.25s var(--ease-out);
}
.btn:active { transform: scale(0.97); }
.btn--primary {
  background: var(--gold); color: #1A1033;
  box-shadow: 0 0 32px var(--gold-glow);
}
.btn--primary:hover { box-shadow: 0 0 44px var(--gold-glow); }
.btn--primary.is-running { background: var(--veil-strong); color: var(--bone); box-shadow: none; border-color: var(--veil-border); backdrop-filter: blur(8px); }
.btn--ghost { background: transparent; color: var(--bone-muted); border-color: var(--veil-border); }
.btn--ghost:hover { color: var(--bone); }
.btn svg { width: 20px; height: 20px; fill: currentColor; }
.cycle-count { margin: 0; min-height: 1.2em; color: var(--bone-muted); font-size: 0.92rem; font-variant-numeric: tabular-nums; }

/* ───────── timer ring ───────── */
.timer-ring-stage { position: relative; width: min(72vw, 300px); aspect-ratio: 1; display: grid; place-items: center; }
.ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring__track { fill: none; stroke: var(--veil-strong); stroke-width: 6; }
.ring__fill {
  fill: none; stroke: var(--gold); stroke-width: 6; stroke-linecap: round;
  stroke-dasharray: 691.15; stroke-dashoffset: 691.15;
  filter: drop-shadow(0 0 8px var(--gold-glow));
  transition: stroke-dashoffset 0.95s linear;
}
.ring-center { position: absolute; text-align: center; }
.ring-time { margin: 0; font-family: "Fraunces", serif; font-weight: 300; font-size: clamp(2.6rem, 12vw, 3.6rem); font-variant-numeric: tabular-nums; line-height: 1; }
.ring-sub { margin: var(--s2) 0 0; color: var(--bone-muted); font-size: 0.85rem; letter-spacing: 0.18em; text-transform: uppercase; }

.timer-options { display: flex; gap: var(--s3); flex-wrap: wrap; justify-content: center; }
.opt { display: inline-flex; align-items: center; gap: var(--s3); color: var(--bone-muted); font-size: 0.9rem; }
.opt__select {
  background: var(--veil); color: var(--bone);
  border: 1px solid var(--veil-border); border-radius: 12px;
  padding: 9px 14px; min-height: 44px; backdrop-filter: blur(8px);
}
.opt__select:focus-visible { outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px var(--gold-soft); }

/* ───────── journey ───────── */
.streak-hero { text-align: center; }
.streak-num {
  margin: 0; font-family: "Fraunces", serif; font-weight: 300;
  font-size: clamp(4rem, 22vw, 6.5rem); line-height: 0.9;
  color: var(--gold); text-shadow: 0 0 40px var(--gold-glow);
  font-variant-numeric: tabular-nums;
}
.streak-label { margin: var(--s2) 0 0; color: var(--bone-muted); letter-spacing: 0.2em; text-transform: uppercase; font-size: 0.82rem; }

.last14 { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
.day-dot {
  width: 22px; height: 22px; border-radius: 7px;
  background: var(--veil); border: 1px solid var(--veil-border);
  position: relative;
}
.day-dot[data-on="1"] { background: var(--gold); border-color: var(--gold); box-shadow: 0 0 14px var(--gold-glow); }
.day-dot[data-today="1"]::after { content: ""; position: absolute; inset: -5px; border-radius: 11px; border: 1.5px solid var(--gold-glow); }

.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s3); width: 100%; }
.stat {
  background: var(--veil); border: 1px solid var(--veil-border);
  border-radius: var(--radius); padding: var(--s4) var(--s3);
  text-align: center; backdrop-filter: blur(10px);
  box-shadow: 0 20px 50px -28px rgba(0,0,0,0.6);
}
.stat__num { font-family: "Fraunces", serif; font-weight: 400; font-size: 1.8rem; font-variant-numeric: tabular-nums; line-height: 1; }
.stat__label { margin-top: var(--s2); color: var(--bone-muted); font-size: 0.74rem; letter-spacing: 0.08em; text-transform: uppercase; }

.history { width: 100%; display: flex; flex-direction: column; gap: var(--s2); }
.history__row {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--s3) var(--s4);
  background: var(--veil); border: 1px solid var(--veil-border);
  border-radius: 16px; backdrop-filter: blur(8px);
}
.history__row .when { color: var(--bone-muted); font-size: 0.88rem; }
.history__row .what { display: flex; align-items: center; gap: var(--s2); font-weight: 500; }
.history__row .what::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--gold); box-shadow: 0 0 8px var(--gold-glow); }
.history__row.is-breathe .what::before { background: var(--rose); box-shadow: 0 0 8px rgba(224,120,155,0.5); }
.empty { text-align: center; color: var(--bone-muted); padding: var(--s5) 0; font-family: "Fraunces", serif; font-style: italic; font-size: 1.1rem; }

/* ───────── ambient sound control ───────── */
.ambient { position: fixed; top: max(var(--s4), env(safe-area-inset-top)); right: var(--s4); z-index: 30; }
.ambient__toggle {
  display: inline-flex; align-items: center; gap: var(--s2);
  background: var(--veil); border: 1px solid var(--veil-border);
  border-radius: 999px; padding: 9px 16px 9px 12px; min-height: 44px;
  color: var(--bone-muted); backdrop-filter: blur(12px);
  transition: color 0.22s var(--ease-out), border-color 0.22s var(--ease-out);
}
.ambient__toggle:hover { color: var(--bone); border-color: var(--veil-strong); }
.ambient__toggle.is-on { color: var(--gold); border-color: var(--gold-soft); }
.ambient__label { font-size: 0.86rem; font-weight: 500; }
.i-sound { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.i-sound path:first-child { fill: currentColor; stroke: none; }
.ambient__toggle:not(.is-on) .i-sound__wave,
.ambient__toggle:not(.is-on) .i-sound__wave2 { opacity: 0.3; }

.ambient__panel {
  position: absolute; top: calc(100% + 10px); right: 0;
  width: 248px; padding: var(--s4);
  background: rgba(28, 18, 48, 0.82);
  border: 1px solid var(--veil-border); border-radius: var(--radius);
  backdrop-filter: blur(20px);
  box-shadow: 0 30px 70px -24px rgba(0,0,0,0.7);
  display: none; flex-direction: column; gap: var(--s4);
}
.ambient.is-open .ambient__panel { display: flex; animation: viewIn 220ms var(--ease-out) both; }
.scape-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--s2); }
.scape {
  border: 1px solid var(--veil-border); background: var(--veil);
  border-radius: 14px; padding: 12px 10px; min-height: 44px;
  color: var(--bone-muted); font-size: 0.86rem; font-weight: 500;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  transition: all 0.2s var(--ease-out);
}
.scape:hover { color: var(--bone); }
.scape:active { transform: scale(0.97); }
.scape.is-active { color: #1A1033; background: var(--gold); border-color: var(--gold); box-shadow: 0 0 20px var(--gold-glow); }
.vol { display: flex; align-items: center; gap: var(--s3); }
.vol__icon svg { width: 18px; height: 18px; fill: var(--bone-muted); }
input[type="range"] {
  -webkit-appearance: none; appearance: none; flex: 1; height: 4px;
  border-radius: 2px; background: var(--veil-strong); outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 18px; height: 18px; border-radius: 50%;
  background: var(--gold); box-shadow: 0 0 12px var(--gold-glow); cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 18px; height: 18px; border: none; border-radius: 50%;
  background: var(--gold); box-shadow: 0 0 12px var(--gold-glow); cursor: pointer;
}

/* ───────── floating nav ───────── */
.nav {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: max(var(--s4), env(safe-area-inset-bottom)); z-index: 30;
  display: flex; gap: 4px; padding: 6px;
  background: rgba(28, 18, 48, 0.7);
  border: 1px solid var(--veil-border); border-radius: 999px;
  backdrop-filter: blur(20px);
  box-shadow: 0 24px 60px -22px rgba(0,0,0,0.7);
}
.nav__btn {
  display: inline-flex; flex-direction: column; align-items: center; gap: 3px;
  background: transparent; border: none; border-radius: 999px;
  padding: 10px 18px; min-width: 72px; min-height: 52px;
  color: var(--bone-faint); font-size: 0.72rem; font-weight: 500; letter-spacing: 0.02em;
  transition: color 0.22s var(--ease-out), background 0.22s var(--ease-out);
}
.nav__btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.nav__btn:hover { color: var(--bone-muted); }
.nav__btn.is-active { color: var(--gold); background: var(--gold-soft); }

/* ───────── focus + reduced motion ───────── */
:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--gold-glow); border-radius: 999px; }
.btn:focus-visible, .pill:focus-visible, .scape:focus-visible, .nav__btn:focus-visible, .ambient__toggle:focus-visible { box-shadow: 0 0 0 3px var(--gold-glow); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; }
  .sky__drift, .sky__ember, .sky__stars { animation: none; }
  .orb { transition: transform 0.4s var(--ease-out); }
  .orb__body { transition: opacity 0.4s var(--ease-out); }
  .ring__fill { transition: stroke-dashoffset 0.4s linear; }
}

/* desktop polish */
@media (min-width: 768px) {
  .view { gap: var(--s6); }
  .nav { bottom: var(--s5); }
}
