.scene-atmosphere {
  --atmosphere-play: paused;
  position: absolute;
  pointer-events: none;
  overflow: clip;
}

.scene-atmosphere[data-atmosphere-running] { --atmosphere-play: running; }

.scene-atmosphere::before, .scene-atmosphere::after {
  content: '';
  position: absolute;
  pointer-events: none;
}

.atmosphere-site {
  position: fixed;
  inset: -20px 0;
  contain: paint;
}

.atmosphere-site::before {
  inset: -5% -12%;
  background:
    radial-gradient(ellipse 33% 14% at 12% 68%, #c5221b57, transparent 96%),
    radial-gradient(ellipse 28% 13% at 86% 29%, #a70f1b4a, transparent 94%),
    radial-gradient(ellipse 32% 18% at 89% 84%, #82141958, transparent 97%);
  animation: atmosphere-haze 17s ease-in-out -5s infinite alternate;
  animation-play-state: var(--atmosphere-play);
  translate: 0 var(--ambient-travel, 0);
}

.atmosphere-site::after {
  inset: 0;
  background:
    radial-gradient(ellipse 42% 49% at 100% 37%, #ad1f213f, transparent 90%),
    radial-gradient(ellipse 31% 37% at 0 76%, #a2181b32, transparent 92%);
  animation: atmosphere-light 12s ease-in-out -3s infinite alternate;
  animation-play-state: var(--atmosphere-play);
}

.atmosphere-site .atmosphere-mote {
  translate: 0 calc(var(--ambient-travel, 0px) * -.6);
  background: #fa7454;
  box-shadow: 0 0 6px #d82c24;
}

.atmosphere-hero {
  inset: 0;
  mask-image: linear-gradient(90deg, #000 45%, transparent 98%);
  perspective: 360px;
}

.hero__wing--right .atmosphere-hero { transform: scaleX(-1); }

.atmosphere-hero::before {
  inset: 22% 2% 3% -25%;
  background:
    radial-gradient(ellipse 64% 20% at 27% 71%, #a1231e32, transparent 88%),
    radial-gradient(ellipse 55% 16% at 49% 51%, #71121134, transparent 90%),
    radial-gradient(ellipse 39% 24% at 9% 42%, #7b2b1d4b, transparent 88%);
  animation: atmosphere-haze 14s ease-in-out -4s infinite alternate;
  animation-play-state: var(--atmosphere-play);
}

.atmosphere-hero::after {
  inset: 0;
  background: radial-gradient(ellipse 80% 35% at 9% 12%, #b62d1d35, transparent 85%);
  animation: atmosphere-light 11s ease-in-out -4s infinite alternate;
  animation-play-state: var(--atmosphere-play);
}

.atmosphere-mote {
  position: absolute;
  left: var(--mote-x);
  top: var(--mote-y);
  width: var(--mote-size);
  height: var(--mote-size);
  border-radius: 50%;
  background: #e27153;
  opacity: .25;
  box-shadow: 0 0 5px #b42f24;
  animation: atmosphere-dust 9s ease-in-out infinite alternate;
  animation-play-state: var(--atmosphere-play);
}

.atmosphere-wire {
  position: absolute;
  width: 16px;
  height: 63%;
  top: -5%;
  left: 44%;
  opacity: .59;
  border-right: 1px solid #983523;
  border-radius: 0 58% 55% 0;
  transform-origin: top right;
  box-shadow: 1px 0 2px #761c16;
  mask-image: linear-gradient(transparent, #000 16%, #000 63%, transparent 98%);
  animation: atmosphere-wire 10s ease-in-out infinite alternate;
  animation-play-state: var(--atmosphere-play);
}

.atmosphere-wire:last-child {
  left: 25%;
  width: 10px;
  height: 44%;
  opacity: .37;
  animation-duration: 13s;
  animation-delay: -8s;
}

.chapter--key { isolation: isolate; }

.atmosphere-key-band {
  position: absolute;
  inset: 0 0 auto;
  height: min(76svh, 610px);
  z-index: -1;
  pointer-events: none;
}

.atmosphere-key-band--lower { inset-block-start: min(66%, 1350px); }

.atmosphere-key {
  inset: 0 auto 0 0;
  width: min(18vw, 235px);
  perspective: 340px;
  mask-image: linear-gradient(to right, #000 58%, transparent);
}

.atmosphere-key--right { inset-inline: auto 0; transform: scaleX(-1); }
.atmosphere-key-band--lower .atmosphere-key { opacity: .63; }

.atmosphere-key::before {
  inset: 13% 0 13% -65%;
  background:
    radial-gradient(ellipse 64% 22% at 34% 69%, #8b1d263d, transparent 87%),
    radial-gradient(ellipse 51% 18% at 46% 44%, #6b101738, transparent 91%);
  animation: atmosphere-haze 16s ease-in-out -6s infinite alternate;
  animation-play-state: var(--atmosphere-play);
}

.atmosphere-key::after {
  inset: 9% 0 0;
  background: radial-gradient(ellipse 95% 52% at 0 37%, #a6322631, transparent 92%);
  animation: atmosphere-light 13s ease-in-out -5s infinite alternate;
  animation-play-state: var(--atmosphere-play);
}

.atmosphere-key .atmosphere-mote { left: calc(var(--mote-x) * .66); }

/* Each fragment has two separate metal faces and two narrow bevels. */
.atmosphere-shard {
  position: absolute;
  top: 34%;
  left: 14%;
  width: 6px;
  height: 12px;
  opacity: .7;
  transform-style: preserve-3d;
  animation: atmosphere-shard 13s ease-in-out -9s infinite alternate;
  animation-play-state: var(--atmosphere-play);
}

.atmosphere-shard:last-child {
  top: 65%;
  left: 10%;
  width: 4px;
  height: 7px;
  opacity: .49;
  animation-duration: 10s;
  animation-delay: -3s;
}

.atmosphere-shard b {
  position: absolute;
  inset: 0;
  clip-path: polygon(66% 0, 100% 35%, 61% 100%, 0 76%);
  background: linear-gradient(138deg, #bb5741, #562927 39%, #201317 86%);
  transform: translateZ(1px);
}

.atmosphere-shard b:nth-child(2) { transform: rotateY(180deg) translateZ(1px); background: linear-gradient(125deg, #603c33, #251817); }
.atmosphere-shard b:nth-child(3) { inset-inline: 1px auto; width: 3px; transform: rotateY(72deg); background: #773226; }
.atmosphere-shard b:nth-child(4) { inset-inline: auto 0; width: 3px; transform: rotateY(-79deg); background: #3b2220; }

.atmosphere-footer {
  inset: 0 0 auto;
  z-index: -1;
  height: min(80%, 440px);
  opacity: var(--footer-haze-opacity, 0);
  background:
    radial-gradient(ellipse 53% 70% at 51% 0, #3f11177a, transparent 78%),
    radial-gradient(ellipse 32% 16% at 77% 42%, #6112192e, transparent 89%);
  mask-image: linear-gradient(transparent, #000 clamp(65px, 11vw, 140px));
}

#end .footer-thread-loop {
  opacity: var(--footer-wire-opacity, .46);
  transform: translateY(var(--footer-wire-drop, 0));
}

@keyframes atmosphere-dust {
  0% { transform: translate(0, 18px); opacity: .09; }
  45% { opacity: .64; }
  100% { transform: translate(11px, -27px); opacity: .17; }
}

@keyframes atmosphere-haze {
  from { transform: translate(-5%, 4%); opacity: .41; }
  to { transform: translate(8%, -6%); opacity: .88; }
}

@keyframes atmosphere-light { from { opacity: .32; } to { opacity: .81; } }

@keyframes atmosphere-wire {
  from { transform: rotateZ(-4deg) rotateY(-14deg); }
  to { transform: rotateZ(3deg) rotateY(18deg); }
}

@keyframes atmosphere-shard {
  from { transform: translate3d(-2px, 9px, -17px) rotateX(18deg) rotateY(-28deg) rotateZ(17deg); }
  to { transform: translate3d(9px, -13px, 27px) rotateX(-33deg) rotateY(59deg) rotateZ(-22deg); }
}

@media (max-width: 900px), (pointer: coarse) {
  .atmosphere-shard, .atmosphere-wire, .atmosphere-mote:nth-of-type(n+4) { display: none; }
  .atmosphere-key { width: 13vw; }
  .atmosphere-key-band--lower { display: none; }
}

:where(html:not([data-motion="full"])) .scene-atmosphere { display: none; }
:where(html:not([data-motion="full"])) #end .footer-thread-loop { opacity: .46; transform: none; }
