/* Each note makes one flight. The runtime supplies a percentage --note-x,
   lengths --note-width and --note-drift, times --note-fall and --note-delay,
   and angles --note-tilt, --note-turn and --note-flip. */
.money-rain {
  position: absolute;
  z-index: 0;
  inset: 0;
  overflow: hidden;
  contain: strict;
  container-type: size;
  pointer-events: none;
  user-select: none;
}

#book > .money-rain {
  mask-image: linear-gradient(105deg, #0005 12%, #0006 32%, #000c 58%, #000 72%);
}

/* The final photo normally paints inside .final-grid's isolated stack.
   Give the photograph, notes, and opaque purchase sheet one shared stack. */
#purchase:has(> .money-rain) {
  isolation: isolate;
}
#purchase:has(> .money-rain) > .final-grid {
  isolation: auto;
}
#purchase:has(> .money-rain) .order-copy {
  z-index: 1;
}

.money-note {
  position: absolute;
  top: 0;
  left: var(--note-x, 67%);
  width: var(--note-width, 98px);
  aspect-ratio: 235 / 100;
  opacity: 0;
  animation: money-note-fall var(--note-fall, 2600ms) linear var(--note-delay, 0ms) 1 both;
}
.money-note-face {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transform-origin: 48% 55%;
  animation: money-note-tumble var(--note-fall, 2600ms) linear var(--note-delay, 0ms) 1 both;
}
.money-note-face::before,
.money-note-face::after {
  content: "";
  position: absolute;
  inset: 0;
  background: center / 100% 100% no-repeat;
  box-shadow: 0 1px 3px #16190fab;
  backface-visibility: hidden;
}
.money-note-face::before {
  background-image: url("/assets/us-dollar-front.webp");
  transform: translateZ(.1px);
}
.money-note-face::after {
  background-image: url("/assets/us-dollar-back.webp");
  transform: rotateY(180deg) translateZ(.1px);
}
.money-note:nth-child(3n) {
  --note-opacity: 0.86;
}

@keyframes money-note-fall {
  0% {
    transform: translate3d(-50%, calc(-120% - 4px), 0);
    opacity: 0;
  }
  12% {
    opacity: var(--note-opacity, 0.95);
  }
  34% {
    transform: translate3d(calc(-50% + var(--note-drift, 55px) * 0.78), 26cqh, 0);
  }
  61% {
    transform: translate3d(calc(-50% + var(--note-drift, 55px) * 0.29), 54cqh, 0);
  }
  83% {
    opacity: var(--note-opacity, 0.95);
  }
  100% {
    transform: translate3d(calc(-50% + var(--note-drift, 55px)), calc(100cqh + 130%), 0);
    opacity: 0;
  }
}
@keyframes money-note-tumble {
  0% {
    transform: perspective(460px) rotateZ(var(--note-tilt, -14deg)) rotateX(-9deg) rotateY(-8deg);
  }
  28% {
    transform: perspective(460px)
      rotateZ(calc(var(--note-tilt, -14deg) * .73 + var(--note-turn, 66deg) * .27))
      rotateX(11deg) rotateY(calc(var(--note-flip, 180deg) * .09));
  }
  69% {
    transform: perspective(460px)
      rotateZ(calc(var(--note-tilt, -14deg) * .29 + var(--note-turn, 66deg) * .71))
      rotateX(17deg) rotateY(calc(var(--note-flip, 180deg) * .91));
  }
  100% {
    transform: perspective(460px) rotateZ(var(--note-turn, 66deg)) rotateX(-8deg)
      rotateY(var(--note-flip, 180deg));
  }
}

#film-stage #book .cover-options-panel .money-rain-replay {
  display: block;
  width: 100%;
  min-height: 44px;
  padding: 7px 9px;
  border: 1px solid #7e747c;
  border-radius: 0;
  color: var(--film-bone);
  background: var(--film-ink);
  font: 550 13px/1.2 var(--sans);
  text-align: left;
  cursor: pointer;
}
#film-stage #book .money-rain-replay:is(:hover, :focus-visible) {
  color: var(--film-ink);
  background: var(--film-lilac);
}
#film-stage #book .money-rain-replay[hidden],
.money-rain[hidden] {
  display: none;
}

@media (max-width: 700px), (max-aspect-ratio: 1/1) {
  #book > .money-rain {
    mask-image: radial-gradient(ellipse 117% 55% at 79% 48%, #000 28%, #000c 59%, transparent 100%);
  }
  .money-note {
    max-width: 25vw;
  }
}
@media (prefers-reduced-motion: reduce), print {
  .money-rain,
  #film-stage #book .cover-options-panel .money-rain-replay {
    display: none;
  }
  .money-note,
  .money-note-face {
    animation: none;
  }
}
