:root {
  color-scheme: dark;
  --night: #0e040a;
  --paper: #ffeadf;
  --rose: #ffb0c2;
  --blush: #f4c9cf;
  --muted: #cfa0aa;
  --gold: #ffd9a0;
  --serif: 'Cormorant Garamond', Georgia, 'Times New Roman', serif;
  --script: 'Pinyon Script', 'Snell Roundhand', 'Apple Chancery', cursive;
  --ui: system-ui, -apple-system, 'Segoe UI', sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: var(--night);
  color: var(--paper);
  font-family: var(--serif);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}
button { font: inherit; cursor: pointer; }
button:focus-visible { outline: 2px solid #ffc7d9; outline-offset: 4px; }

.sky {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 70% 55% at 50% 45%, #3c1022 0%, transparent 72%),
    var(--night);
}

#stage, #fx {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
#stage { z-index: 1; filter: drop-shadow(0 0 10px #ff4f7d33); }
#fx { z-index: 3; }

/* ───────────── Opening: the candle ───────────── */
.wish {
  position: fixed;
  inset: 0;
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: max(9svh, 40px) 20px 0;
  pointer-events: none;
}
.wish-name {
  margin: 0;
  font-family: var(--script);
  font-weight: 400;
  font-size: clamp(3.6rem, 12vw, 6.5rem);
  line-height: 1.1;
  color: var(--rose);
  text-shadow: 0 0 30px #ff7a9a55;
  animation: rise 2.4s .6s cubic-bezier(.2,.8,.24,1) both;
}
.wish-line {
  margin: 6px 0 0;
  font-style: italic;
  font-size: clamp(1.25rem, 3.6vw, 1.75rem);
  color: var(--blush);
  animation: rise 2.4s 1.6s cubic-bezier(.2,.8,.24,1) both;
}
.hint {
  font: italic clamp(1rem, 2.6vw, 1.2rem) var(--serif);
  color: var(--muted);
  letter-spacing: .02em;
  margin: 0;
}
.wish .hint {
  position: absolute;
  left: 0;
  right: 0;
  bottom: max(7svh, 30px);
  animation: rise 2s 3.6s ease both, breathe 3s 5.6s ease-in-out infinite;
}
.wish.out > * { transition: opacity 1.4s ease, filter 1.4s ease; opacity: 0 !important; filter: blur(4px); animation: none; }
.flame-button {
  position: fixed;
  width: 120px;
  height: 170px;
  translate: -50% -50%;
  border: 0;
  border-radius: 50%;
  background: transparent;
  pointer-events: auto;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(14px); filter: blur(4px); }
  to { opacity: 1; transform: none; filter: none; }
}
@keyframes breathe { 0%, 100% { opacity: .55; } 50% { opacity: 1; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

/* ───────────── Scrapbook ───────────── */
.book {
  position: fixed;
  inset: 0;
  z-index: 2;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  justify-items: center;
  align-items: center;
  padding: max(3svh, 16px) 12px max(9svh, 64px);
}
.book-title {
  margin: 0;
  font-weight: 400;
  font-style: italic;
  font-size: clamp(1.8rem, 4.6vw, 3rem);
  color: var(--paper);
  text-shadow: 0 0 24px #ff86a455;
  opacity: 0;
  filter: blur(4px);
  transition: opacity 1.6s ease, filter 1.6s ease;
}
.book-title.on { opacity: 1; filter: none; }
.book.fading .book-title, .book.fading .caption { opacity: 0 !important; filter: blur(4px); transition: opacity 1.2s, filter 1.2s; }
.pages {
  position: relative;
  width: min(94vw, calc((100svh - 190px) * 1.15));
  aspect-ratio: 1.15;
}
.polaroid {
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: var(--w);
  margin: 0;
  /* % padding is relative to the collage, so scale it by the photo's width */
  padding: calc(var(--w) * .035) calc(var(--w) * .035) calc(var(--w) * .11);
  background: linear-gradient(170deg, #fdeee5, #f0d3c9);
  border-radius: 2px;
  box-shadow: 0 16px 36px #08020590, 0 2px 4px #0a020680;
  transform: translate(0px, 0px) rotate(var(--r)) scale(1);
  opacity: 0;
  overflow: hidden;
}
.polaroid.strip { padding: calc(var(--w) * .07) calc(var(--w) * .07) calc(var(--w) * .2); }
.polaroid img { display: block; width: 100%; height: auto; border-radius: 1px; }
/* a photo drifts down onto the page, then develops like a real Polaroid */
.polaroid.real {
  animation: land 1.7s cubic-bezier(.22,.9,.3,1) both, float 7s 1.7s ease-in-out infinite alternate;
}
.polaroid.real img { animation: develop 3.6s .2s ease-out both; }
.polaroid.real::after {
  content: '';
  position: absolute;
  inset: -20%;
  background: linear-gradient(105deg, transparent 40%, #fff6eaaa 50%, transparent 60%);
  transform: translateX(-120%);
  animation: shimmer 1.8s 1.4s ease-in-out both;
  pointer-events: none;
  mix-blend-mode: soft-light;
}
@keyframes land {
  0% { opacity: 0; transform: translate(-18px, -70px) rotate(calc(var(--r) - 9deg)) scale(1.06); }
  35% { opacity: 1; }
  70% { transform: translate(3px, 4px) rotate(calc(var(--r) + 1deg)) scale(1); }
  100% { opacity: 1; transform: translate(0px, 0px) rotate(var(--r)) scale(1); }
}
@keyframes develop {
  0% { filter: sepia(.6) brightness(.22) contrast(.55) saturate(.3) blur(1.5px); }
  45% { filter: sepia(.45) brightness(.7) contrast(.75) saturate(.6) blur(.4px); }
  100% { filter: none; }
}
@keyframes shimmer { to { transform: translateX(120%); } }
@keyframes float {
  from { translate: 0 0; }
  to { translate: var(--fx, 3px) var(--fy, -5px); }
}

/* the memories gather into a little stack… */
.polaroid.gather {
  animation: none;
  opacity: 1;
  transform: translate(var(--gx), var(--gy)) rotate(var(--gr)) scale(var(--gs));
  translate: 0 0;
  transition: transform 1.5s cubic-bezier(.55,0,.2,1), translate 1.5s cubic-bezier(.55,0,.2,1), filter .7s ease, opacity .8s ease;
}
/* …glow warmly… */
.polaroid.gather.glow {
  transition-delay: 0s !important;
  filter: brightness(1.45) saturate(1.2) drop-shadow(0 0 26px #ffcf9a);
}
/* …and come apart into petals */
.polaroid.gather.gone {
  transition-delay: 0s !important;
  opacity: 0;
  filter: brightness(2) blur(6px) drop-shadow(0 0 40px #ffcf9a);
}

/* landscape collage */
.polaroid[data-photo="booth"]  { --x: 1%;  --y: 4%;  --w: 46%; --r: -4deg; --fx: -3px; }
.polaroid[data-photo="selfie"] { --x: 49%; --y: 1%;  --w: 32%; --r: 4deg; }
.polaroid[data-photo="car"]    { --x: 5%;  --y: 47%; --w: 29%; --r: -3deg; --fy: 5px; }
.polaroid[data-photo="night"]  { --x: 36%; --y: 52%; --w: 48%; --r: 2.5deg; --fx: -4px; }
.polaroid[data-photo="strip"]  { --x: 83%; --y: 14%; --w: 15%; --r: 7deg; --fy: 6px; }

.caption {
  margin: 10px 0 0;
  min-height: 1.4em;
  text-align: center;
  font-style: italic;
  font-size: clamp(1.25rem, 3vw, 1.75rem);
  color: var(--blush);
  opacity: 0;
  filter: blur(4px);
  transition: opacity 1.4s, filter 1.4s;
}
.caption.on { opacity: 1; filter: none; }

.tap-hint {
  position: fixed;
  z-index: 6;
  left: 0;
  right: 0;
  bottom: max(3svh, 18px);
  text-align: center;
  pointer-events: none;
  animation: fade-in 1.5s ease both, breathe 3s 1.5s ease-in-out infinite;
}

/* ───────────── Finale ───────────── */
.finale {
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  z-index: 5;
  padding: max(3svh, 14px) 16px 0;
  text-align: center;
  pointer-events: none;
}
.finale-hb {
  margin: 0;
  font-weight: 400;
  font-style: italic;
  font-size: clamp(2.1rem, 6vw, 3.6rem);
  line-height: 1.05;
  color: #ffe6d4;
  text-shadow: 0 0 28px #ff6f9466, 0 1px 3px #1d0713;
  animation: rise 2.2s cubic-bezier(.2,.74,.22,1) both;
}
.finale-word {
  position: relative;
  margin: 0;
  height: 1.3em;
  font-family: var(--script);
  font-size: clamp(2.8rem, 8.5vw, 4.8rem);
  line-height: 1.3;
  color: var(--rose);
  text-shadow: 0 0 26px #ff6f9488;
  white-space: nowrap;
}
.finale-word .w { position: absolute; left: 0; right: 0; }
.finale-word .l {
  display: inline-block;
  white-space: pre;
  opacity: 0;
  animation: letter-in 1s cubic-bezier(.2,.8,.24,1) both;
  animation-delay: calc(var(--i) * 55ms);
}
.finale-word .w.leaving .l {
  opacity: 1;
  animation: letter-out .8s ease-in both;
  animation-delay: calc(var(--i) * 35ms);
}
.finale-word .heart {
  display: inline-block;
  font-family: var(--serif);
  font-size: .6em;
  margin-left: .2em;
  vertical-align: .2em;
  color: #ff5f86;
  text-shadow: 0 0 18px #ff3d6e;
  opacity: 0;
  animation: heart-in 1.2s 1s cubic-bezier(.2,1.4,.4,1) both, beat 1.4s 2.4s ease-in-out infinite;
}
@keyframes letter-in {
  from { opacity: 0; transform: translateY(.3em) scale(.8); filter: blur(8px); }
  to { opacity: 1; transform: none; filter: none; }
}
@keyframes letter-out {
  from { opacity: 1; }
  to { opacity: 0; transform: translateY(-.35em) scale(1.1); filter: blur(10px); }
}
@keyframes heart-in {
  from { opacity: 0; transform: scale(0); }
  to { opacity: 1; transform: scale(1); }
}
@keyframes beat {
  0%, 40%, 100% { opacity: 1; transform: scale(1); }
  15% { opacity: 1; transform: scale(1.22); }
  28% { opacity: 1; transform: scale(1.08); }
}

.signature {
  position: fixed;
  z-index: 5;
  left: 0;
  right: 0;
  bottom: max(8svh, 62px);
  margin: 0;
  text-align: center;
  font: italic clamp(1.05rem, 2.4vw, 1.3rem) var(--serif);
  color: var(--muted);
  pointer-events: none;
  animation: rise 2s ease both;
}
.again {
  position: fixed;
  z-index: 6;
  left: 50%;
  bottom: max(2.4svh, 14px);
  translate: -50% 0;
  min-height: 42px;
  padding: 0 20px;
  border-radius: 999px;
  border: 1px solid #ffb0c244;
  background: #1a07108c;
  color: var(--muted);
  font: italic 1.05rem var(--serif);
  backdrop-filter: blur(6px);
  animation: fade-in 2s ease both;
  transition: color .2s, border-color .2s;
}
.again:hover { color: var(--paper); border-color: var(--rose); }

/* ───────────── Portrait phones ───────────── */
@media (max-aspect-ratio: 4/5) {
  .pages { width: min(96vw, calc((100svh - 200px) * .62)); aspect-ratio: .62; }
  .polaroid[data-photo="booth"]  { --x: 2%;  --y: 1%;  --w: 66%; }
  .polaroid[data-photo="selfie"] { --x: 47%; --y: 15%; --w: 50%; --r: 5deg; }
  .polaroid[data-photo="car"]    { --x: 3%;  --y: 40%; --w: 44%; }
  .polaroid[data-photo="night"]  { --x: 28%; --y: 70%; --w: 68%; }
  .polaroid[data-photo="strip"]  { --x: 69%; --y: 39%; --w: 24%; }
  .signature { bottom: 70px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-delay: 0ms !important; transition-duration: .01ms !important; }
}
