#confetti > p {
  position: sticky;
  top: 50vh;
}

#confetti {
  display: grid;
  place-content: center;
  text-align: center;
  color: white;
  font-size: min(20vh, 13vw);

  /* sibling-index() is less hacky but extremely new (support added in
   * late 2025, still unsupported in Firefox). */
  :nth-child(1)  { --index: 1;  }
  :nth-child(2)  { --index: 2;  }
  :nth-child(3)  { --index: 3;  }
  :nth-child(4)  { --index: 4;  }
  :nth-child(5)  { --index: 5;  }
  :nth-child(6)  { --index: 6;  }
  :nth-child(7)  { --index: 7;  }
  :nth-child(8)  { --index: 8;  }
  :nth-child(9)  { --index: 9;  }
  :nth-child(10) { --index: 10; }
  :nth-child(11) { --index: 11; }
  :nth-child(12) { --index: 12; }
  :nth-child(13) { --index: 13; }
  :nth-child(14) { --index: 14; }
  :nth-child(15) { --index: 15; }
  :nth-child(16) { --index: 16; }
  :nth-child(17) { --index: 17; }
  :nth-child(18) { --index: 18; }
  :nth-child(19) { --index: 19; }
  :nth-child(20) { --index: 20; }

  --seed: 8123;
  --mod: 2999;
}

#confetti > .f {
  position: fixed;
  top: 0;
  left: 0;

  /* PRNG width [8px, 20px] and height [4px, 10px] */
  width:  calc(8px  + 12px * mod(var(--seed) * var(--index) * 3,  var(--mod)) / var(--mod));
  height: calc(4px  +  6px * mod(var(--seed) * var(--index) * 7,  var(--mod)) / var(--mod));

  /* PRNG hue [0, 360] */
  --hue: calc(360 * mod(var(--seed) * var(--index) * 37, var(--mod)) / var(--mod));
  background: hsl(var(--hue) 85% 60%);

  /* PRNG horizontal start position [0vw, 100vw], offset by half the particle
   * width to avoid edge bias — approximated as 10px (midpoint of width range). */
  --start-x: calc(-10px + 100vw * mod(var(--seed) * var(--index) * 11, var(--mod)) / var(--mod));

  /* Small horizontal drift [-8vw, +8vw] so fall isn't perfectly vertical. */
  --drift: calc(-8vw + 16vw * mod(var(--seed) * var(--index) * 13, var(--mod)) / var(--mod));
  --end-x: calc(var(--start-x) + var(--drift));

  /* PRNG rotations [1, 5] full turns. */
  --spins: calc(1 + 4 * mod(var(--seed) * var(--index) * 17, var(--mod)) / var(--mod));

  /* Stagger entry: each piece enters between 0% and 30% into the scroll range. */
  --entry-start: calc(30% * mod(var(--seed) * var(--index) * 19, var(--mod)) / var(--mod));
  --entry-end:   calc(var(--entry-start) + 60%);

  translate: var(--start-x) calc(-100% - 10vh);

  animation: confetti-fall ease-in, confetti-rotate linear;
  animation-fill-mode: forwards;
  animation-range:
    contain var(--entry-start) cover var(--entry-end),
    contain var(--entry-start) cover var(--entry-end);
  animation-timeline: --confetti;
}

@keyframes confetti-fall {
  from { translate: var(--start-x) calc(-100% - 10vh); }
  to   { translate: var(--end-x)   110vh; }
}

@keyframes confetti-rotate {
  to { rotate: calc(360deg * var(--spins)); }
}

#confetti-drop {
  position: fixed;
  bottom: 100%;
  left: 50%;

  animation: confetti-drop ease-in both;
  animation-range: cover 10% cover 80%;
  animation-timeline: --confetti;
}

@keyframes confetti-drop {
  0%   { transform: translateX(-50%) translateY(-10vh); }
  25%  { transform: translateX(-50%) translateY(-10vh); }
  40%  { transform: translateX(-50%) translateY(90%); }
  50%  { transform: translateX(-50%) translateY(120%) scale(2); }
  80%  { transform: translateX(-50%) translateY(120%) scale(2); }
  100% { transform: translateX(-50%) translateY(-10vh); }
}
