:root {
  color-scheme: light;
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  color: #23322a;
  background: #e9e5d9;
}

* { box-sizing: border-box; }

body {
  display: grid;
  place-items: center;
  min-height: 100vh;
  min-height: 100svh;
  margin: 0;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background:
    url("./paper-grain.webp") 0 0 / 192px 192px repeat,
    radial-gradient(ellipse at 16% 14%, #fff8df 0%, #fff8df56 35%, transparent 65%),
    radial-gradient(ellipse at 51% 46%, #faf7ee, #e9e5d9 78%, #e2dbcf);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  background:
    url("./paper-grain.webp") 0 0 / 192px 192px repeat,
    radial-gradient(ellipse at 50% 33%, #fff7dd 0%, #fff1da85 31%, transparent 62%),
    radial-gradient(ellipse at 78% 85%, #f7ded4 0%, transparent 60%),
    #f0d7d0;
  transition: opacity .95s ease;
}

.is-celebrating::before { opacity: 1; }

.stage {
  position: relative;
  z-index: 0;
  --stage-width: min(
    calc(100vw - env(safe-area-inset-left) - env(safe-area-inset-right)),
    calc((100svh - env(safe-area-inset-top) - env(safe-area-inset-bottom)) * .5625)
  );
  width: min(100vw, 56.25vh);
  width: var(--stage-width);
  aspect-ratio: 9 / 16;
}

.stage::before {
  content: "";
  position: absolute;
  top: 64%;
  left: 12%;
  width: 76%;
  height: 12%;
  background: radial-gradient(ellipse, #72594a1b 3%, #72594a0b 39%, transparent 71%);
  pointer-events: none;
  transition: opacity .32s ease;
}

.stage.is-printing::before { opacity: 0; }

.viewport {
  position: absolute;
  inset: 0;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  outline-offset: -5px;
  cursor: grab;
}

.is-celebrating .viewport { visibility: hidden; }
.viewport:active { cursor: grabbing; }
.is-printing .viewport { cursor: default; }
.viewport:focus-visible { outline: 2px solid #426d53; }
.viewport canvas { display: block; width: 100%; height: 100%; }
.viewport canvas[hidden] { display: none; }

.fallback {
  display: grid;
  place-content: center;
  height: 100%;
  margin: 0;
  padding: 24px;
  text-align: center;
}

.fallback[hidden] { display: none; }

.camera-hint {
  position: absolute;
  bottom: 13%;
  inset-inline: 0;
  margin: 0;
  text-align: center;
  color: #485e50;
  font-size: .94rem;
  font-weight: 600;
  letter-spacing: .16em;
  pointer-events: none;
  animation: hint-pulse 3.3s ease-in-out infinite;
}

.is-printing .camera-hint { visibility: hidden; animation-play-state: paused; }
@keyframes hint-pulse {
  0%, 92%, 100% { opacity: 1; }
  42%, 54% { opacity: 0; }
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.flash-overlay {
  position: fixed;
  inset: 0;
  background: #fffaf1;
  opacity: 0;
  pointer-events: none;
}

.flash-overlay.flashing { animation: flash .38s ease-out; }
@keyframes flash { from { opacity: .43; } to { opacity: 0; } }

.confetti {
  position: fixed;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.birthday {
  position: absolute;
  inset: 0;
  color: #55302d;
  text-align: center;
}

.birthday-decoration {
  position: absolute;
  inset: 0;
  pointer-events: none;
  animation: reveal-decoration .95s .5s ease-out both;
}

.birthday-ribbon {
  position: absolute;
  width: clamp(68px, 26%, 128px);
  aspect-ratio: 450 / 255;
  background: url("./champagne-ribbon.webp") center / contain no-repeat;
  opacity: .72;
}

.ribbon-top { top: 4%; left: 4%; transform: rotate(-9deg); }
.ribbon-bottom { bottom: 6%; right: 4%; transform: rotate(168deg) scale(.88); }

.birthday-balloons {
  position: absolute;
  top: 3.5%;
  right: 4%;
  width: clamp(69px, 25%, 116px);
  height: auto;
  opacity: .91;
  transform: rotate(-5deg);
  transform-origin: 48% 87%;
  animation: balloon-sway 3.4s ease-in-out infinite alternate;
}

@keyframes balloon-sway {
  to { transform: translateY(-5px) rotate(5deg); }
}

.birthday-star {
  position: absolute;
  width: 11px;
  aspect-ratio: 1;
  background: #aa7747a8;
  clip-path: polygon(50% 0, 62% 38%, 100% 50%, 62% 62%, 50% 100%, 38% 62%, 0 50%, 38% 38%);
  animation: star-twinkle 2.8s ease-in-out infinite alternate;
}

.star-left { top: 29%; left: 7%; width: 8px; }
.star-right { top: 43%; right: 8%; animation-delay: -.9s; }
.star-lower { bottom: 14%; left: 15%; width: 7px; animation-delay: -1.65s; }

@keyframes star-twinkle {
  from { opacity: .45; transform: scale(.8); }
  to { opacity: .95; transform: scale(1.08); }
}

@keyframes reveal-decoration {
  from { opacity: 0; transform: translateY(5px); }
}

.birthday-photo {
  position: absolute;
  top: 33%;
  left: 50%;
  width: 63%;
  height: auto;
  transform: translate(-50%, -50%) rotate(-4deg);
  box-shadow: 0 14px 40px #6a3d3426, 0 2px 6px #6a3d341b;
  animation: arrange-photo .93s .08s cubic-bezier(.22, .71, .22, 1) both;
}

@keyframes arrange-photo {
  from {
    top: 50%;
    width: 86%;
    transform: translate(-50%, -50%);
    box-shadow: none;
  }
}

.birthday-message {
  position: absolute;
  top: 59%;
  left: 50%;
  width: min(87%, 25rem);
  transform: translateX(-50%);
  animation: reveal-wish .8s .53s ease-out both;
}

@keyframes reveal-wish {
  from { opacity: 0; transform: translate(-50%, 14px); }
}

.birthday-cake {
  position: relative;
  width: 82px;
  margin: 0 auto 7px;
}

.birthday-cake img {
  display: block;
  width: 100%;
  height: auto;
}

.cake-flame {
  position: absolute;
  width: 5px;
  height: 7px;
  border-radius: 60% 40% 55% 55%;
  transform: translate(-50%, -100%) rotate(10deg);
  transform-origin: 50% 100%;
  background: linear-gradient(#ffe8a9, #eb975c);
  box-shadow: 0 0 8px #f1b760aa;
  animation: candle-flame .9s ease-in-out infinite alternate;
}

.flame-left { left: 36.9%; top: 30%; }
.flame-center { left: 50.5%; top: 23%; animation-delay: -.32s; }
.flame-right { left: 64%; top: 32%; animation-delay: -.56s; }
@keyframes candle-flame { to { transform: translate(-50%, -100%) rotate(-9deg) scale(.9, 1.11); } }

.birthday h1 {
  margin: 0;
  color: #683b35;
  font-family: "Songti SC", "Noto Serif CJK SC", "SimSun", serif;
  font-size: clamp(1.8rem, calc(var(--stage-width) * .12), 3.75rem);
  font-weight: 650;
  line-height: 1.14;
  letter-spacing: .06em;
  text-indent: .06em;
  outline: none;
}

.birthday p {
  margin: 10px auto 0;
  max-width: 22em;
  color: #72514b;
  font-size: clamp(.94rem, calc(var(--stage-width) * .037), 1.1rem);
  line-height: 1.7;
  text-wrap: balance;
}

.birthday-sender {
  margin-top: 21px;
  color: #72514b;
  font-size: .85rem;
  letter-spacing: .09em;
}

.music-control {
  position: fixed;
  right: max(16px, calc(env(safe-area-inset-right) + 10px));
  bottom: max(14px, calc(env(safe-area-inset-bottom) + 8px));
  min-height: 44px;
  padding: 0 13px;
  border: 1px solid #74594a38;
  border-radius: 999px;
  background: #fffaf1aa;
  color: #644c42;
  font: inherit;
  font-size: .81rem;
  touch-action: manipulation;
  cursor: pointer;
}

.music-control:hover { background: #fffaf1; }
.music-control:focus-visible { outline: 2px solid #855b4b; outline-offset: 2px; }

@media (max-width: 600px) and (orientation: portrait) {
  .camera-hint { bottom: 16%; font-size: 1rem; }
  .birthday-photo { width: 67%; }
  .birthday-message { width: 88%; }
}

@media (max-height: 500px) {
  .birthday-cake { width: 66px; margin-bottom: 4px; }
  .birthday p { margin-top: 5px; font-size: .85rem; line-height: 1.45; }
  .birthday-sender { margin-top: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  body::before, .stage::before, .camera-hint, .birthday-decoration, .birthday-balloons,
  .birthday-star, .birthday-photo, .birthday-message, .cake-flame {
    animation: none;
    transition: none;
  }
}
