/* Decorative stage layer. Insert before the pets inside #companion-layer. */
.celestial-scene {
  display: none;
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  user-select: none;
  background: transparent;
}
.companion-stage .celestial-scene { display: block; }
body[data-view="landing"] .celestial-scene { display: none; }
.dream-moon-layer {
  position: absolute;
  left: calc(100% - 330px);
  top: 90px;
  width: 360px;
  height: auto;
  max-width: none;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  -webkit-mask-image: radial-gradient(ellipse 54% 65% at 50% 40%, #000 18%, #000d 48%, transparent 83%);
  mask-image: radial-gradient(ellipse 54% 65% at 50% 40%, #000 18%, #000d 48%, transparent 83%);
}
.has-dream-moon .celestial-moon { visibility: hidden; }
.has-dream-moon .moonlight-column { opacity: .4; }

.moonlight-column {
  position: absolute;
  left: 50%;
  top: 22px;
  width: 360px;
  height: 242px;
  transform: translateX(-50%);
  background:
    radial-gradient(ellipse at 50% 6%, #fffdf42e, transparent 52%),
    conic-gradient(from 158deg at 50% 0%, transparent 0deg, #f8f4ff08 8deg, #fffdf319 22deg, #f8f4ff08 36deg, transparent 44deg);
  -webkit-mask-image: linear-gradient(transparent, #000 20%, #000 65%, transparent);
  mask-image: linear-gradient(transparent, #000 20%, #000 65%, transparent);
  animation: moonlight-breathe 9s ease-in-out infinite;
}

.celestial-moon {
  position: absolute;
  left: calc(50% - 48px);
  top: 6px;
  width: 96px;
  height: 96px;
}
.celestial-moon::before {
  content: "";
  position: absolute;
  inset: 12px;
  border-radius: 50%;
  background: #fff9df;
  box-shadow:
    0 0 20px 9px #fffbe4a6,
    0 0 46px 21px #fff7d34f,
    0 0 78px 40px #fff8e01c;
  animation: moon-halo 8s ease-in-out infinite;
}
.celestial-moon img {
  display: block;
  position: relative;
  width: 100%;
  height: 100%;
  max-width: none;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  filter: none;
}

/* Four square wing lobes alternate between two fixed pixel poses. */
.pixel-butterfly {
  scale: .65;
  --wing-glow: #a5d4ff80;
  position: absolute;
  width: 22px;
  height: 16px;
  color: #f4fbff;
  filter: drop-shadow(0 0 2px #fff9) drop-shadow(0 0 6px var(--wing-glow));
  animation: celestial-butterfly-drift 8s steps(6, end) infinite;
}
.pixel-butterfly::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  width: 3px;
  height: 3px;
  background: transparent;
  box-shadow:
    0 0 currentColor, 3px 0 currentColor,
    15px 0 currentColor, 18px 0 currentColor,
    0 3px currentColor, 3px 3px currentColor,
    15px 3px currentColor, 18px 3px currentColor,
    3px 6px currentColor, 6px 6px currentColor,
    12px 6px currentColor, 15px 6px currentColor,
    3px 9px currentColor, 15px 9px currentColor;
  animation: celestial-wing-flutter .9s steps(1, end) infinite;
}
.pixel-butterfly::after {
  content: "";
  position: absolute;
  left: 9px;
  top: 3px;
  width: 3px;
  height: 10px;
  background: #ffffff;
}
.butterfly-one { left: calc(50% - 106px); top: 14px; }
.butterfly-two {
  --wing-glow: #c3bdff70;
  left: calc(50% + 88px);
  top: 34px;
  opacity: .85;
  animation-duration: 10s;
  animation-delay: -3s;
}
.butterfly-two::before { animation-duration: 1.1s; animation-delay: -.4s; }
.butterfly-three {
  display: none;
  left: calc(50% + 116px);
  top: 48px;
  opacity: .7;
  animation-duration: 12s;
  animation-delay: -7s;
}
.butterfly-three::before { animation-duration: .8s; animation-delay: -.6s; }

/* A few suspended square points, not a continuous rain of particles. */
.celestial-motes {
  display: none;
  position: absolute;
  left: calc(50% - 78px);
  top: 102px;
  width: 156px;
  height: 108px;
}
.celestial-motes::before,
.celestial-motes::after {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  width: 3px;
  height: 3px;
  color: #fffdf0;
  background: transparent;
  opacity: 0;
  filter: drop-shadow(0 0 2px #fffbea66);
  animation: celestial-mote-fall 7s steps(8, end) infinite;
}
.celestial-motes::before {
  box-shadow: 24px 4px currentColor, 72px 24px currentColor, 130px 42px currentColor, 56px 60px currentColor;
  animation-delay: -2s;
}
.celestial-motes::after {
  width: 2px;
  height: 2px;
  box-shadow: 115px 5px currentColor, 40px 46px currentColor, 140px 24px currentColor, 85px 72px currentColor;
  animation-delay: -6s;
}

@keyframes celestial-wing-flutter {
  0%, 49% {
    box-shadow:
      0 0 currentColor, 3px 0 currentColor,
      15px 0 currentColor, 18px 0 currentColor,
      0 3px currentColor, 3px 3px currentColor,
      15px 3px currentColor, 18px 3px currentColor,
      3px 6px currentColor, 6px 6px currentColor,
      12px 6px currentColor, 15px 6px currentColor,
      3px 9px currentColor, 15px 9px currentColor;
  }
  50%, 100% {
    box-shadow:
      6px 0 currentColor, 6px 0 currentColor,
      12px 0 currentColor, 12px 0 currentColor,
      6px 3px currentColor, 6px 3px currentColor,
      12px 3px currentColor, 12px 3px currentColor,
      6px 6px currentColor, 6px 6px currentColor,
      12px 6px currentColor, 12px 6px currentColor,
      6px 9px currentColor, 12px 9px currentColor;
  }
}
@keyframes celestial-butterfly-drift {
  0%, 100% { transform: translate(0, 0); }
  35% { transform: translate(10px, -14px); }
  70% { transform: translate(-8px, -6px); }
}
@keyframes celestial-mote-fall {
  0%, 18% { opacity: 0; transform: translateY(-3px); }
  30% { opacity: .9; transform: translateY(0); }
  62% { opacity: .6; transform: translateY(20px); }
  76%, 100% { opacity: 0; transform: translateY(34px); }
}

.companion-layer[data-phase="transform"] .moonlight-column { animation: transformation-moonbeam var(--transform-duration) ease-out 1 both; }
@keyframes moonlight-breathe { 0%,100%{opacity:.65} 50%{opacity:1} }
@keyframes moon-halo { 0%,100%{opacity:.72} 50%{opacity:1} }
@keyframes transformation-moonbeam { 0%{opacity:.6} 15%,65%{opacity:1;filter:brightness(1.8)} 100%{opacity:.75;filter:brightness(1)} }

.motion-paused .celestial-scene *,
.motion-paused .celestial-scene *::before,
.motion-paused .celestial-scene *::after,
.companion-layer.scene-paused .celestial-scene *,
.companion-layer.scene-paused .celestial-scene *::before,
.companion-layer.scene-paused .celestial-scene *::after {
  animation-play-state: paused !important;
}

@media (max-width: 600px) {
  .dream-moon-layer { width: 320px; left: calc(100% - 210px); top: 70px; opacity: .7; }
  .celestial-moon { left: calc(50% - 40px); top: 6px; width: 80px; height: 80px; }
  .celestial-moon::before {
    inset: 10px;
    box-shadow: 0 0 17px 7px #fffbe4a0, 0 0 42px 17px #fff7d33b;
  }
  .moonlight-column { width: 270px; height: 216px; }
  .butterfly-one { left: calc(50% - 92px); top: 12px; }
  .butterfly-two { left: calc(50% + 60px); top: 28px; }
  .butterfly-three { display: none; }
  .celestial-motes { left: calc(50% - 78px); top: 88px; }
  .celestial-scene { clip-path: inset(-80px -20px 0); }
}

@media (prefers-reduced-motion: reduce) {
  body:not(.motion-opt-in) .celestial-scene *,
  body:not(.motion-opt-in) .celestial-scene *::before,
  body:not(.motion-opt-in) .celestial-scene *::after { animation: none !important; }
  body:not(.motion-opt-in) .celestial-motes::before { opacity: .22; }
  body:not(.motion-opt-in) .celestial-motes::after { opacity: .15; }
}
