/* The tree lives between the distant atmosphere and the moving stars.
   Haze and fine branches are baked into the art; no live bitmap blur is needed. */
.celestial-tree {
  --tree-opacity: .57;
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  user-select: none;
  contain: strict;
}

.celestial-tree-art {
  position: absolute;
  inset: 0;
  display: block;
  /* Fade the artwork into the existing sky, without a rectangular edge. */
  -webkit-mask-image: radial-gradient(ellipse 78% 86% at 50% 47%, #000 24%, #000c 52%, transparent 83%);
  mask-image: radial-gradient(ellipse 78% 86% at 50% 47%, #000 24%, #000c 52%, transparent 83%);
}

/* Keep the base artwork subdued, but let the extracted gold emit above it.
   Applying opacity to their shared parent would also dim the pointer light. */
.celestial-tree-art picture {
  opacity: var(--tree-opacity);
  transition: opacity 3.6s cubic-bezier(.2,.65,.3,1);
}

/* Entry runs only on first style resolution. Resuming the scene or changing
   motion preferences must never restart the tree at a transparent frame.
   Browsers without starting-style simply show the finished composition. */
@starting-style {
  .celestial-tree-art picture { opacity: 0; }
}

.celestial-tree-art picture,
.celestial-tree-art img {
  display: block;
  width: 100%;
  height: 100%;
}
.celestial-tree-art img {
  object-fit: cover;
  object-position: 50% 48%;
}

/* Only extracted gold filaments emit light. Sky, mist and the dark bark stay
   transparent in this texture; the radial mask merely softens its reach. */
.celestial-tree-light {
  position: absolute;
  top: 0;
  left: 0;
  opacity: 0;
  pointer-events: none;
  mix-blend-mode: screen;
  -webkit-mask-image: radial-gradient(circle closest-side, #000 0%, #000d 22%, #0006 51%, #0001 74%, transparent 100%);
  mask-image: radial-gradient(circle closest-side, #000 0%, #000d 22%, #0006 51%, #0001 74%, transparent 100%);
}

@media (prefers-reduced-motion: reduce) {
  .celestial-tree-light { display: none; }
}

/* A faint warm heart illuminates the cool mist, leaving the header in shadow. */
.celestial-tree-aureole {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 23% 32% at 51% 43%, #e8be7424, transparent 80%),
    radial-gradient(ellipse 44% 27% at 50% 29%, #b89a5a0d, transparent 78%);
  opacity: .5;
  animation: celestial-tree-breathe 14s ease-in-out infinite alternate;
}

/* Sparse gold motes rise slowly through the branches. One small composited
   layer shares the existing scene's pause behavior; it needs no animation loop. */
.celestial-tree-dust {
  position: absolute;
  inset: 13% 12% 14%;
  opacity: .5;
  background:
    radial-gradient(ellipse 1px 2px at 24% 29%, #f2d79a, transparent 100%),
    radial-gradient(circle 1px at 33% 18%, #e7c785, transparent 100%),
    radial-gradient(circle 1.5px at 42% 37%, #f8e5b6b3, transparent 100%),
    radial-gradient(ellipse 1px 2px at 56% 21%, #f6d996, transparent 100%),
    radial-gradient(circle 1px at 72% 32%, #ffe4a4, transparent 100%),
    radial-gradient(circle 1px at 81% 45%, #e6c485, transparent 100%),
    radial-gradient(ellipse 1px 2px at 63% 55%, #f1d49aa6, transparent 100%),
    radial-gradient(circle 1px at 35% 61%, #f1d49ab3, transparent 100%),
    radial-gradient(circle 1.5px at 48% 72%, #f4d99d8c, transparent 100%),
    radial-gradient(circle 1px at 59% 85%, #e9c98499, transparent 100%),
    radial-gradient(circle 1px at 18% 52%, #f3d8a299, transparent 100%),
    radial-gradient(circle 1px at 76% 13%, #f9e6b999, transparent 100%);
  animation: celestial-tree-motes 18s ease-in-out infinite alternate;
}

.celestial-tree-veil {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, #080d17b8, #080d1738 14%, transparent 31%, transparent 70%, #080d177a),
    radial-gradient(ellipse 58% 26% at 50% 103%, #10233780, transparent 95%),
    radial-gradient(ellipse 27% 45% at 0 58%, #080d174d, transparent 100%),
    radial-gradient(ellipse 27% 45% at 100% 58%, #080d174d, transparent 100%);
}

/* Clear cool stars sit in front of the softer tree and retain their depth. */
.constellations .starfield-canvas { opacity: 1; }

@keyframes celestial-tree-breathe {
  from { opacity: .32; }
  to { opacity: .64; }
}
@keyframes celestial-tree-motes {
  from { opacity: .28; transform: translate3d(-3px, 9px, 0); }
  to { opacity: .64; transform: translate3d(4px, -12px, 0); }
}

/* Portrait artwork preserves the crown instead of cropping down to the trunk. */
@media (max-width: 600px) and (orientation: portrait) {
  .celestial-tree { --tree-opacity: .52; }
  .celestial-tree-art {
    -webkit-mask-image: radial-gradient(ellipse 95% 75% at 50% 49%, #000 30%, #000c 58%, transparent 90%);
    mask-image: radial-gradient(ellipse 95% 75% at 50% 49%, #000 30%, #000c 58%, transparent 90%);
  }
  .celestial-tree-art img { object-position: 50% 46%; }
  .celestial-tree-aureole {
    background: radial-gradient(ellipse 43% 30% at 50% 43%, #e8be741f, transparent 85%);
  }
  .celestial-tree-dust { inset: 20% 3% 14%; }
}

@media (max-height: 500px) and (orientation: landscape) {
  .celestial-tree { --tree-opacity: .44; }
  .celestial-tree-art img { object-position: 50% 40%; }
}

/* The dedicated 3:1 panorama keeps the tree and its spreading crown in view
   on both 21:9 and 32:9 displays, with nebulae filling the distant wings. */
@media (min-width: 1280px) and (min-aspect-ratio: 2/1) {
  .celestial-tree-art img { object-position: 50% 50%; }
}

:is(.scene-still, .is-dragging) .celestial-tree > * {
  animation-play-state: paused;
}
:is(.scene-still, .is-dragging) .celestial-tree-art picture { transition: none; }
@media (prefers-reduced-motion: reduce) {
  .celestial-tree > * { animation: none !important; transition: none !important; }
  .celestial-tree-art picture { transition: none !important; }
}
