/* =========================================================================
   space.css — the moving universe
   Four layers, back to front:
     1. .cosmos__wash     base vertical gradient (deep space falloff)
     2. .cosmos__nebula  four huge, blurred, slowly drifting colour clouds
     3. .cosmos__stars   <canvas> starfield w/ parallax, twinkle, shooting stars
     4. .cosmos__vignette + .cosmos__grain   framing and film grain
   ========================================================================= */

.cosmos {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  background: var(--void-800);
  contain: strict;
  pointer-events: none;
}

/* ── 1. Base wash ────────────────────────────────────────────────────── */
.cosmos__wash {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(120% 80% at 50% -10%, #131a3a 0%, transparent 60%),
    radial-gradient(90% 60% at 8% 105%, #0d1430 0%, transparent 65%),
    linear-gradient(180deg, var(--void-700) 0%, var(--void-800) 45%, var(--void-900) 100%);
}

/* ── 2. Nebulae ──────────────────────────────────────────────────────── */
.cosmos__nebula {
  position: absolute;
  inset: -18%;
  filter: blur(72px);
  opacity: 0.5;
}

.nebula {
  position: absolute;
  display: block;
  border-radius: 50%;
  mix-blend-mode: screen;
  will-change: transform, opacity;
}

.nebula--indigo {
  width: 46vmax;
  height: 46vmax;
  top: 4%;
  left: 8%;
  background: radial-gradient(circle, rgba(74, 116, 224, 0.5), transparent 68%);
  animation: drift-a 78s var(--ease-in-out) infinite;
}

.nebula--violet {
  width: 40vmax;
  height: 40vmax;
  top: 32%;
  right: 2%;
  background: radial-gradient(circle, rgba(150, 100, 232, 0.42), transparent 66%);
  animation: drift-b 96s var(--ease-in-out) infinite;
}

.nebula--aqua {
  width: 34vmax;
  height: 34vmax;
  bottom: 0%;
  left: 28%;
  background: radial-gradient(circle, rgba(58, 178, 172, 0.34), transparent 66%);
  animation: drift-c 112s var(--ease-in-out) infinite;
}

.nebula--rose {
  width: 26vmax;
  height: 26vmax;
  top: 58%;
  left: -6%;
  background: radial-gradient(circle, rgba(214, 96, 140, 0.24), transparent 64%);
  animation: drift-d 88s var(--ease-in-out) infinite;
}

@keyframes drift-a {
  0%,
  100% {
    transform: translate3d(0, 0, 0) scale(1);
  }
  33% {
    transform: translate3d(9%, 6%, 0) scale(1.16);
  }
  66% {
    transform: translate3d(-6%, 12%, 0) scale(0.92);
  }
}

@keyframes drift-b {
  0%,
  100% {
    transform: translate3d(0, 0, 0) scale(1.05);
  }
  40% {
    transform: translate3d(-12%, 9%, 0) scale(0.9);
  }
  70% {
    transform: translate3d(4%, -8%, 0) scale(1.2);
  }
}

@keyframes drift-c {
  0%,
  100% {
    transform: translate3d(0, 0, 0) scale(0.95);
  }
  45% {
    transform: translate3d(11%, -10%, 0) scale(1.18);
  }
  75% {
    transform: translate3d(-7%, -4%, 0) scale(1.02);
  }
}

@keyframes drift-d {
  0%,
  100% {
    transform: translate3d(0, 0, 0) scale(1.1);
  }
  50% {
    transform: translate3d(14%, -12%, 0) scale(0.88);
  }
}

/* ── 3. Starfield canvas ─────────────────────────────────────────────── */
.cosmos__stars {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  /* Fades in after paint so the page never flashes a flat rectangle */
  opacity: 0;
  transition: opacity 1.4s var(--ease-out);
}

.cosmos__stars.is-ready {
  opacity: 1;
}

/* ── 4. Vignette + grain ─────────────────────────────────────────────── */
.cosmos__vignette {
  position: absolute;
  inset: 0;
  background: radial-gradient(
    125% 100% at 50% 42%,
    transparent 42%,
    rgba(2, 3, 8, 0.42) 78%,
    rgba(2, 3, 8, 0.75) 100%
  );
}

.cosmos__grain {
  position: absolute;
  inset: -50%;
  opacity: 0.035;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E");
  animation: grain-shift 8s steps(6) infinite;
}

@keyframes grain-shift {
  0% {
    transform: translate3d(0, 0, 0);
  }
  20% {
    transform: translate3d(-3%, 2%, 0);
  }
  40% {
    transform: translate3d(2%, -3%, 0);
  }
  60% {
    transform: translate3d(-2%, -2%, 0);
  }
  80% {
    transform: translate3d(3%, 1%, 0);
  }
  100% {
    transform: translate3d(0, 0, 0);
  }
}

/* ── Timer page: a slow breath of light that swells while running ─────── */
.cosmos__pulse {
  position: absolute;
  left: 50%;
  top: 42%;
  width: 46vmax;
  height: 46vmax;
  translate: -50% -50%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.055), transparent 62%);
  opacity: 0;
  transition: opacity 1.6s var(--ease-out);
}

body.is-timer-running .cosmos__pulse {
  opacity: 1;
  animation: breathe 7.5s var(--ease-in-out) infinite;
}

body[data-mode='focus'] .cosmos__pulse {
  background: radial-gradient(circle, rgba(143, 180, 255, 0.09), transparent 62%);
}
body[data-mode='short'] .cosmos__pulse {
  background: radial-gradient(circle, rgba(111, 216, 207, 0.085), transparent 62%);
}
body[data-mode='long'] .cosmos__pulse {
  background: radial-gradient(circle, rgba(183, 140, 255, 0.09), transparent 62%);
}
body[data-mode='custom'] .cosmos__pulse {
  background: radial-gradient(circle, rgba(255, 157, 180, 0.075), transparent 62%);
}

@keyframes breathe {
  0%,
  100% {
    transform: scale(0.9);
    opacity: 0.55;
  }
  50% {
    transform: scale(1.14);
    opacity: 1;
  }
}

/* ── Reduced motion: keep the sky, drop the movement ─────────────────── */
@media (prefers-reduced-motion: reduce) {
  .cosmos__nebula,
  .cosmos__grain,
  .brand__mark,
  .empty__dot,
  .empty__orbit,
  .cosmos__pulse {
    animation: none !important;
  }

  .cosmos__nebula {
    opacity: 0.42;
  }

  .cosmos__pulse {
    display: none;
  }
}
