/* ============================================================
   aurora.css: "Milky Way" deep-space background
   Layer order (back → front), all decorative, pointer-events: none
     #aurora-bg  z0   base gradient (also the static fallback for eco tier)
       .aur-space z0  milky way, galaxy, nebula, mist, dust, glow stars, grain
       .stars-*   z1  box-shadow star layers (JS fills --sa / --sb)
       .meteors   z3  shooting stars
     #fx        z4  click / tap explosion canvas
     page content z2+ (see "content stacking" below)
   ============================================================ */

/* ---------- palette / tokens ---------- */
#aurora-bg {
  --aur-void:   #020617;               /* deep midnight navy */
  --aur-violet: 120, 70, 220;
  --aur-blue:   60, 110, 255;
  --aur-cyan:   40, 200, 255;
  --aur-pink:   255, 100, 180;
}

/* Explosion colours read by aurora.js (site themes may override these) */
:where(html) {
  --fx-rgb-1: 120, 180, 255;
  --fx-rgb-2: 167, 139, 250;
}

/* ---------- base canvas of the sky ---------- */
#aurora-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
  background:
    radial-gradient(120% 80% at 16% 6%,  rgba(var(--aur-violet), .30), transparent 60%),
    radial-gradient(90% 70%  at 88% 94%, rgba(0, 110, 170, .20),       transparent 62%),
    radial-gradient(70% 55%  at 72% 22%, rgba(var(--aur-pink), .07),   transparent 65%),
    linear-gradient(180deg, #03051a 0%, var(--aur-void) 48%, #080618 100%);
}

/* Dark-first: night is the designed look. Day gets a soft, pale variant. */
html[data-theme="day"] #aurora-bg {
  background:
    radial-gradient(120% 80% at 16% 6%,  rgba(150, 130, 255, .22), transparent 60%),
    radial-gradient(90% 70%  at 88% 94%, rgba(90, 190, 255, .18),  transparent 62%),
    linear-gradient(180deg, #f3f5ff 0%, #eaeefc 100%);
}

/* ---------- generated space container (built by aurora.js) ---------- */
#aurora-bg .aur-space {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 2.2s ease;            /* gentle fade-in on load */
}
html[data-aurora="ready"] #aurora-bg .aur-space { opacity: 1; }
html[data-aurora="ready"][data-theme="day"] #aurora-bg .aur-space { opacity: .4; }

#aurora-bg .aur-space * { pointer-events: none; }

/* parallax wrappers (JS sets inline translate on scroll) — taller than the
   viewport so scrolling never reveals an empty bottom edge */
#aurora-bg .aur-par {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 116vh;
  will-change: transform;
}

/* ---------- MILKY WAY band ---------- */
#aurora-bg .aur-milkyway,
#aurora-bg .aur-milkydust {
  position: absolute;
  left: 50%; top: 50%;
  width: 140vmax; height: 40vmax;
  margin: -20vmax 0 0 -70vmax;
  transform: rotate(-28deg);               /* keep in sync with BAND_TAN in JS */
  -webkit-mask-image: radial-gradient(closest-side, #000 25%, transparent 100%);
          mask-image: radial-gradient(closest-side, #000 25%, transparent 100%);
}

#aurora-bg .aur-milkyway {
  background:
    radial-gradient(closest-side, rgba(196, 210, 255, .20), rgba(120, 100, 230, .13) 38%, rgba(40, 60, 160, .06) 66%, transparent 100%),
    conic-gradient(from 90deg at 50% 50%,
      rgba(var(--aur-blue), .10), rgba(var(--aur-violet), .13),
      rgba(var(--aur-cyan), .08), rgba(var(--aur-pink), .06),
      rgba(var(--aur-blue), .10));
  animation: aur-band-breathe 70s ease-in-out infinite alternate;
}

/* dark dust lane through the middle of the band (the "rift") */
#aurora-bg .aur-milkyway::after {
  content: "";
  position: absolute;
  left: 6%; right: 6%; top: 40%; bottom: 38%;
  background: radial-gradient(closest-side, rgba(2, 4, 16, .55), transparent 100%);
}

/* fine star-dust texture along the band: 4 tiles with coprime sizes so the
   pattern never visibly repeats */
#aurora-bg .aur-milkydust {
  opacity: .6;
  background-image:
    radial-gradient(1px   1px   at 12px 18px,  rgba(255, 255, 255, .55), transparent 100%),
    radial-gradient(1px   1px   at 63px 71px,  rgba(190, 210, 255, .50), transparent 100%),
    radial-gradient(1.2px 1.2px at 118px 40px, rgba(255, 255, 255, .40), transparent 100%),
    radial-gradient(1px   1px   at 41px 103px, rgba(220, 200, 255, .45), transparent 100%);
  background-size: 137px 113px, 89px 127px, 173px 149px, 211px 97px;
}

/* ---------- GALAXY (tilted spiral disc, very slow spin) ---------- */
#aurora-bg .aur-galaxy {
  position: absolute;
  right: -6vmax; top: 6vh;
  width: 40vmax; height: 40vmax;
  border-radius: 50%;
  opacity: .55;
  background:
    conic-gradient(from 0deg,
      transparent 0 8%, rgba(120, 150, 255, .22) 17%, transparent 30%,
      transparent 50%,  rgba(190, 110, 255, .18) 62%, transparent 75%, transparent 100%),
    radial-gradient(circle, rgba(255, 236, 214, .30) 0, rgba(170, 150, 255, .12) 14%, transparent 46%);
  -webkit-mask-image: radial-gradient(circle, #000 0, #000 30%, transparent 68%);
          mask-image: radial-gradient(circle, #000 0, #000 30%, transparent 68%);
  transform: rotate(-24deg) scaleY(.5) rotate(0deg);
  animation: aur-galaxy-spin 640s linear infinite;
}

/* ---------- NEBULA clouds ---------- */
#aurora-bg .aur-neb {
  position: absolute;
  border-radius: 50%;
  will-change: transform, opacity;
}
#aurora-bg .aur-neb-1 {                       /* violet, top-left */
  width: 90vmax; height: 66vmax;
  left: -34vmax; top: -26vmax;
  background: radial-gradient(closest-side, rgba(var(--aur-violet), .34), rgba(70, 50, 170, .15) 55%, transparent 100%);
  animation: aur-neb-drift 130s ease-in-out infinite alternate, aur-breathe 56s ease-in-out infinite alternate;
}
#aurora-bg .aur-neb-2 {                       /* blue / cyan, bottom-right */
  width: 84vmax; height: 60vmax;
  right: -30vmax; bottom: -14vmax;
  background: radial-gradient(closest-side, rgba(var(--aur-cyan), .20), rgba(var(--aur-blue), .15) 50%, transparent 100%);
  animation: aur-neb-drift 160s ease-in-out -40s infinite alternate-reverse, aur-breathe 64s ease-in-out -20s infinite alternate;
}
#aurora-bg .aur-neb-3 {                       /* faint pink accent, mid-right */
  width: 46vmax; height: 34vmax;
  right: 6vmax; top: 24vh;
  background: radial-gradient(closest-side, rgba(var(--aur-pink), .15), rgba(var(--aur-violet), .08) 60%, transparent 100%);
  animation: aur-neb-drift 110s ease-in-out -60s infinite alternate, aur-breathe 48s ease-in-out -10s infinite alternate;
}

/* thin light mist that fades in and out */
#aurora-bg .aur-mist {
  position: absolute;
  border-radius: 50%;
  opacity: 0;
  will-change: opacity;
}
#aurora-bg .aur-mist-1 {
  width: 70vmax; height: 20vmax;
  left: -8vmax; top: 42vh;
  background: radial-gradient(closest-side, rgba(150, 190, 255, .14), transparent 100%);
  transform: rotate(-18deg);
  animation: aur-fade 42s ease-in-out infinite;
}
#aurora-bg .aur-mist-2 {
  width: 60vmax; height: 18vmax;
  right: -10vmax; top: 8vh;
  background: radial-gradient(closest-side, rgba(180, 150, 255, .12), transparent 100%);
  transform: rotate(14deg);
  animation: aur-fade 58s ease-in-out -24s infinite;
}

/* ---------- COSMIC DUST (drift + fade in/out, relocated by JS) ---------- */
#aurora-bg .aur-dust {
  position: absolute;
  width: var(--s, 3px); height: var(--s, 3px);
  border-radius: 50%;
  background: radial-gradient(circle, var(--c, rgba(170, 200, 255, .9)), transparent 70%);
  opacity: 0;
  will-change: transform, opacity;
  animation: aur-dust var(--dur, 22s) ease-in-out var(--delay, 0s) infinite;
}

/* ---------- FAR STARS (individual twinkle / fade, own timing each) ---------- */
#aurora-bg .aur-tw {
  position: absolute;
  width: var(--s, 2px); height: var(--s, 2px);
  border-radius: 50%;
  background: var(--c, #fff);
  box-shadow: 0 0 calc(var(--s, 2px) * 3) calc(var(--s, 2px) * .5) var(--c, #fff);
  opacity: .15;
  will-change: opacity, transform;
  animation: aur-twinkle var(--dur, 6s) ease-in-out var(--delay, 0s) infinite;
}
/* the few brightest ones get a faint diffraction cross */
#aurora-bg .aur-tw.big::before,
#aurora-bg .aur-tw.big::after {
  content: "";
  position: absolute;
  left: 50%; top: 50%;
  width: calc(var(--s, 2px) * 9); height: 1px;
  background: linear-gradient(90deg, transparent, var(--c, #fff), transparent);
  opacity: .5;
  transform: translate(-50%, -50%);
}
#aurora-bg .aur-tw.big::after { transform: translate(-50%, -50%) rotate(90deg); }

/* ---------- GRAIN + VIGNETTE ---------- */
#aurora-bg .aur-grain {
  position: absolute;
  inset: 0;
  opacity: .07;
  background-size: 180px 180px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 1  0 0 0 0 1  0 0 0 0 1  0 0 0 .6 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
#aurora-bg .aur-vignette {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 50% 45%, transparent 55%, rgba(2, 3, 12, .55) 100%);
}
html[data-theme="day"] #aurora-bg .aur-vignette,
html[data-theme="day"] #aurora-bg .aur-grain { display: none; }

/* ---------- STAR LAYERS (box-shadow dots filled by JS) ---------- */
#aurora-bg .stars-back,
#aurora-bg .stars-mid,
#aurora-bg .stars-front {
  position: absolute;
  top: 0; left: 0;
  width: 1px; height: 1px;
  z-index: 1;
  pointer-events: none;
  will-change: transform;                  /* JS applies scroll parallax here */
}
#aurora-bg .stars-back::before,
#aurora-bg .stars-back::after,
#aurora-bg .stars-mid::before,
#aurora-bg .stars-mid::after,
#aurora-bg .stars-front::before,
#aurora-bg .stars-front::after {
  content: "";
  position: absolute;
  top: 0; left: 0;
  width: 1px; height: 1px;
  background: transparent;
  will-change: opacity, transform;
}
/* two groups per layer: slow "breathing" at different pace + slow drift */
#aurora-bg .stars-back::before,
#aurora-bg .stars-mid::before,
#aurora-bg .stars-front::before {
  box-shadow: var(--sa, none);
  animation: aur-star-breathe var(--dur-a, 11s) ease-in-out var(--delay-a, 0s) infinite alternate,
             aur-star-drift 300s linear infinite alternate;
}
#aurora-bg .stars-back::after,
#aurora-bg .stars-mid::after,
#aurora-bg .stars-front::after {
  box-shadow: var(--sb, none);
  animation: aur-star-breathe var(--dur-b, 14s) ease-in-out var(--delay-b, 0s) infinite alternate,
             aur-star-drift 380s linear infinite alternate-reverse;
}
#aurora-bg .stars-back  { opacity: .85; }
#aurora-bg .stars-mid   { opacity: .95; }

/* ---------- METEORS (JS adds .meteor; sets left/top/--dist/--dur) ----------
   NOTE: one animation only — aurora.js removes the node on `animationend`. */
#aurora-bg .meteors {
  position: absolute;
  inset: 0;
  z-index: 3;
  overflow: hidden;
  pointer-events: none;
}
.meteor {
  position: absolute;
  width: clamp(90px, 14vw, 170px);
  height: 1.5px;
  margin-top: -1px;
  border-radius: 2px;
  background: linear-gradient(90deg, transparent, rgba(150, 200, 255, .55) 70%, #fff);
  transform-origin: 100% 50%;               /* head = right end = pivot */
  transform: rotate(145deg);                /* travels down-left */
  opacity: 0;
  pointer-events: none;
  will-change: transform, opacity;
  animation: meteor-fly var(--dur, 1.5s) cubic-bezier(.25, .1, .4, 1) forwards;
}
.meteor::after {                            /* glowing head */
  content: "";
  position: absolute;
  right: -2px; top: 50%;
  width: 4px; height: 4px;
  margin-top: -2px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 8px 2px rgba(150, 200, 255, .8);
}

/* ---------- SPOTLIGHT (premium tier; JS moves it via transform) ---------- */
.spotlight {
  position: fixed;
  top: 0; left: 0;
  width: 520px; height: 520px;
  margin: -260px 0 0 -260px;                /* centre on the pointer */
  border-radius: 50%;
  z-index: 1;
  pointer-events: none;
  background: radial-gradient(circle, rgba(120, 170, 255, .10), transparent 65%);
  will-change: transform;
}

/* ---------- EXPLOSION CANVAS ---------- */
#fx {
  position: fixed;
  inset: 0;
  width: 100%; height: 100%;
  z-index: 1;
  pointer-events: none;
}
#aurora-bg #fx { z-index: 4; }              /* if the canvas lives inside the bg */

/* ---------- content stacking ----------
   Everything that is a direct child of <body> and not part of the effects
   sits above the background. :where() = zero specificity, so any position /
   z-index the site already sets on its own classes still wins. */
:where(body > *:not(#aurora-bg):not(#fx):not(.spotlight):not(script):not(style):not(link):not(template)) {
  position: relative;
  z-index: 2;
}

/* ---------- keyframes (transform / opacity only = compositor friendly) ---------- */
@keyframes aur-star-breathe { from { opacity: .55; } to { opacity: 1; } }
@keyframes aur-star-drift   { from { transform: translate3d(0, 0, 0); } to { transform: translate3d(-14px, -8px, 0); } }
@keyframes aur-twinkle {
  0%, 100% { opacity: .12; transform: scale(.8); }
  50%      { opacity: 1;   transform: scale(1.15); }
}
@keyframes aur-dust {
  0%   { opacity: 0; transform: translate3d(0, 0, 0); }
  50%  { opacity: var(--peak, .6); }
  100% { opacity: 0; transform: translate3d(var(--dx, 20px), var(--dy, -14px), 0); }
}
@keyframes aur-fade { 0%, 100% { opacity: 0; } 50% { opacity: 1; } }
@keyframes aur-breathe { from { opacity: .65; } to { opacity: 1; } }
@keyframes aur-band-breathe { from { opacity: .75; } to { opacity: 1; } }
@keyframes aur-neb-drift {
  from { transform: translate3d(-2vmax, 1vmax, 0) scale(1); }
  to   { transform: translate3d(3vmax, -2vmax, 0) scale(1.08); }
}
@keyframes aur-galaxy-spin {
  from { transform: rotate(-24deg) scaleY(.5) rotate(0deg); }
  to   { transform: rotate(-24deg) scaleY(.5) rotate(360deg); }
}
@keyframes meteor-fly {
  0%   { opacity: 0; transform: rotate(145deg) translateX(0); }
  12%  { opacity: 1; }
  70%  { opacity: 1; }
  100% { opacity: 0; transform: rotate(145deg) translateX(var(--dist, 600px)); }
}

/* ---------- responsive ---------- */
@media (max-width: 1024px) {                /* tablet */
  #aurora-bg .aur-milkyway,
  #aurora-bg .aur-milkydust { width: 150vmax; height: 44vmax; margin: -22vmax 0 0 -75vmax; }
  #aurora-bg .aur-galaxy { width: 34vmax; height: 34vmax; right: -8vmax; }
  #aurora-bg .aur-neb-1 { width: 100vmax; height: 74vmax; }
}
@media (max-width: 640px) {                 /* mobile: fewer / lighter layers */
  #aurora-bg .aur-milkydust,
  #aurora-bg .aur-mist-2,
  #aurora-bg .aur-neb-3 { display: none; }
  #aurora-bg .aur-milkyway { width: 170vmax; height: 52vmax; margin: -26vmax 0 0 -85vmax; }
  #aurora-bg .aur-galaxy { width: 52vmax; height: 52vmax; right: -16vmax; top: 4vh; opacity: .45; }
  #aurora-bg .aur-grain { opacity: .05; }
  #aurora-bg .aur-tw.big::before,
  #aurora-bg .aur-tw.big::after { display: none; }
  .spotlight { display: none; }
}

/* ---------- reduced motion: static sky, nothing moves ---------- */
@media (prefers-reduced-motion: reduce) {
  #aurora-bg .aur-space,
  #aurora-bg .aur-space *,
  #aurora-bg .stars-back::before,  #aurora-bg .stars-back::after,
  #aurora-bg .stars-mid::before,   #aurora-bg .stars-mid::after,
  #aurora-bg .stars-front::before, #aurora-bg .stars-front::after {
    animation: none !important;
    transition: none !important;
  }
  #aurora-bg .aur-tw   { opacity: .6; }
  #aurora-bg .aur-dust { opacity: .25; }
  #aurora-bg .aur-mist { opacity: .5; }
}

/* ---------- eco tier: JS stops early, only the static gradient stays ---------- */
html.aurora-lite #aurora-bg .aur-space { display: none; }

/* ---------- sections: transparent background only ----------
   Only the section wrapper is made transparent so the Milky Way shows through.
   Cards, buttons and other content keep their own styling. The .section class
   is used only on <section> elements in index.html (checked), so cards are not
   affected. */
html[data-aurora="ready"] section[id],
html[data-aurora="ready"] .section,
html[data-aurora="ready"] .section--soft,
html[data-aurora="ready"] .section--gradient,
html[data-aurora="ready"] .section--narrow,
html[data-aurora="ready"] #hero,
html[data-aurora="ready"][data-theme="day"] section[id],
html[data-aurora="ready"][data-theme="day"] .section,
html[data-aurora="ready"][data-theme="day"] #hero {
  background: transparent;
}

/* eco: aurora.js returns early, so hide every decorative layer it would have driven */
html[data-perf="eco"] .spotlight,
html[data-perf="eco"] #fx,
html[data-perf="eco"] .meteors,
html[data-perf="eco"] .stars { display: none !important; }
