.celebration {
  --sail-time: 6.6s;
  --boat-width: 208px;
  --water-height: 48px;
  position: fixed;
  inset: 0;
  z-index: 30;
  overflow: hidden;
  pointer-events: none;
}

.celebration__water {
  position: absolute;
  inset: auto 0 0;
  height: var(--water-height);
  background: url("/img/celebration-water.svg") repeat-x bottom left / 128px 100%;
  animation:
    celebration-tide var(--sail-time) ease-in-out both,
    celebration-waves 8s steps(64) infinite;
}

.celebration__crossing {
  position: absolute;
  left: 0;
  bottom: calc(var(--water-height) * .78);
  width: var(--boat-width);
  animation: celebration-cross var(--sail-time) linear both;
}

.celebration__boat {
  position: relative;
  animation: celebration-bob .9s steps(4, end) infinite alternate;
}

.celebration__boat svg { display: block; width: 100%; }

.celebration__boat::after {
  content: "";
  position: absolute;
  bottom: -3px;
  left: 12%;
  width: 24px;
  height: 2px;
  background: white;
  box-shadow: 32px 5px white, 103px 3px white, 126px -2px var(--wave);
  animation: celebration-wake .7s steps(4, end) infinite alternate;
}

.celebration__hand {
  transform-origin: 41px 33px;
  animation: celebration-hand .48s steps(2, end) infinite alternate;
}

.celebration__flag {
  transform-origin: 78px 11px;
  animation: celebration-flag .44s steps(3, end) infinite alternate;
}

.celebration__bubble {
  position: relative;
  width: max-content;
  max-width: 100%;
  margin: 0 auto 4px;
  padding: 6px 10px;
  color: var(--navy);
  background: var(--paper);
  border: 2px solid var(--navy);
  box-shadow: 3px 3px 0 var(--sun);
  font-size: .9375rem;
  font-weight: 800;
  line-height: 1.25;
  text-align: center;
  animation: celebration-message var(--sail-time) linear both;
}

.celebration__bubble::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  width: 12px;
  height: 10px;
  background: var(--navy);
  clip-path: polygon(0 0, 100% 0, 100% 30%, 75% 30%, 75% 60%, 50% 60%, 50% 100%, 25% 100%, 25% 60%, 0 60%);
}

@keyframes celebration-tide {
  0%, 100% { transform: translateY(100%); }
  13%, 89% { transform: translateY(0); }
}

@keyframes celebration-waves { to { background-position-x: -128px; } }

@keyframes celebration-cross {
  0%, 12% { transform: translateX(calc(-100% - 16px)); }
  32% { transform: translateX(max(10px, calc(30vw - 50%))); }
  72% { transform: translateX(min(calc(100vw - 100% - 10px), calc(70vw - 50%))); }
  89%, 100% { transform: translateX(calc(100vw + 16px)); }
}

@keyframes celebration-message {
  0%, 31%, 78%, 100% { opacity: 0; }
  33%, 73% { opacity: 1; }
}

@keyframes celebration-bob { to { transform: translateY(4px); } }
@keyframes celebration-wake { to { transform: translateX(-8px); opacity: .5; } }
@keyframes celebration-hand { from { transform: rotate(-10deg); } to { transform: rotate(13deg); } }
@keyframes celebration-flag { to { transform: skewY(6deg) scaleX(.9); } }

.celebration--donation {
  --sail-time: 7.5s;
  --boat-width: min(280px, 72vw);
}

.celebration--donation .celebration__boat svg { overflow: visible; }

.celebration__cheer {
  animation: celebration-jump 1.3s steps(5, end) infinite;
}

.celebration__cheer:nth-child(2) { animation-delay: -.32s; }
.celebration__cheer:nth-child(3) { animation-delay: -.64s; }
.celebration__cheer:nth-child(4) { animation-delay: -.96s; }

.celebration__raised-arm {
  transform-box: fill-box;
  transform-origin: 70% 90%;
  animation: celebration-hand .42s steps(3, end) infinite alternate;
}

.celebration__donation-flag {
  transform-box: fill-box;
  transform-origin: left center;
  animation: celebration-flag .44s steps(3, end) infinite alternate;
}

.celebration__confetti rect {
  --drift: -42px;
  --rise: -22px;
  transform-box: fill-box;
  transform-origin: center;
  opacity: 0;
  animation: celebration-confetti 2.6s infinite;
}

.celebration__confetti rect:nth-child(4n + 1) { fill: var(--lagoon); }
.celebration__confetti rect:nth-child(4n + 2) { fill: var(--green); }
.celebration__confetti rect:nth-child(4n + 3) { fill: var(--sun); }
.celebration__confetti rect:nth-child(4n) { fill: var(--wave); }
.celebration__confetti rect:nth-child(2) { --drift: -25px; --rise: -28px; animation-delay: .05s; }
.celebration__confetti rect:nth-child(3) { --drift: -10px; --rise: -25px; animation-delay: .12s; }
.celebration__confetti rect:nth-child(4) { --drift: 14px; --rise: -30px; }
.celebration__confetti rect:nth-child(5) { --drift: 31px; --rise: -27px; animation-delay: .08s; }
.celebration__confetti rect:nth-child(6) { --drift: 47px; --rise: -23px; animation-delay: .14s; }
.celebration__confetti rect:nth-child(7) { --drift: 63px; --rise: -20px; animation-delay: .03s; }
.celebration__confetti rect:nth-child(8) { --drift: 69px; --rise: -16px; animation-delay: .1s; }

@keyframes celebration-jump {
  0%, 62%, 100% { transform: translateY(0); }
  26% { transform: translateY(-9px); }
}

@keyframes celebration-confetti {
  0%, 74%, 100% { opacity: 0; }
  4%, 61% { opacity: 1; }
  0% { transform: translate(0, 0); animation-timing-function: ease-out; }
  28% {
    transform: translate(calc(var(--drift) * .42), var(--rise)) rotate(80deg);
    animation-timing-function: ease-in;
  }
  74%, 100% { transform: translate(var(--drift), 24px) rotate(250deg); }
}

@media (max-width: 600px) {
  .celebration { --boat-width: min(164px, 70vw); --water-height: 36px; }
  .celebration--donation { --boat-width: min(218px, 72vw); }
  .celebration__bubble { font-size: .875rem; }
}

@media (prefers-reduced-motion: reduce) {
  .celebration__water,
  .celebration__boat,
  .celebration__bubble::after { display: none; }

  .celebration__crossing {
    left: 12px;
    right: 12px;
    bottom: max(16px, env(safe-area-inset-bottom));
    width: auto;
    animation: none;
  }

  .celebration__bubble { animation: none; }
  .celebration--donation .celebration__boat * { animation: none; }
}
