:root {
  --bg: #f6efe7;
  --ink: #4b3a35;
  --muted: #8c7a72;
  --rose: #b0736b;
  --blush: #e9cdc6;
  --gold: #b8935a;
  --paper: #fffaf4;
  --serif: 'Cormorant Garamond', 'Times New Roman', Georgia, serif;
  --sans: 'Jost', system-ui, -apple-system, 'Segoe UI', sans-serif;
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overflow: hidden; }
body { font-family: var(--sans); color: var(--ink); background: var(--bg); user-select: none; -webkit-font-smoothing: antialiased; }
.hidden { display: none !important; }
.instant .scene { transition: none !important; }

/* ---------- background ---------- */
#bg { position: fixed; inset: 0; z-index: 0; overflow: hidden; background: radial-gradient(120% 80% at 50% 0%, #fcf8f3 0%, #f5ebe2 55%, #efe2d8 100%); }
.blob { position: absolute; border-radius: 50%; filter: blur(70px); opacity: .55; animation: drift 22s ease-in-out infinite alternate; }
.b1 { width: 60vmax; height: 60vmax; background: #efcac2; top: -22vmax; left: -18vmax; }
.b2 { width: 52vmax; height: 52vmax; background: #dde4d1; bottom: -20vmax; right: -18vmax; animation-duration: 28s; }
.b3 { width: 34vmax; height: 34vmax; background: #f3dcc2; top: 42%; left: 58%; animation-duration: 25s; }
@keyframes drift { to { transform: translate(6vmax, 4vmax) scale(1.12); } }
#ambient { position: fixed; inset: 0; z-index: 2; pointer-events: none; overflow: hidden; }
.grain {
  position: fixed; inset: 0; z-index: 3; pointer-events: none; opacity: .22; mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 .45  0 0 0 0 .38  0 0 0 0 .34  0 0 0 .5 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}
#fx { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 50; }
#butterflies { position: fixed; inset: 0; z-index: 55; pointer-events: none; overflow: hidden; }

/* ---------- butterflies ---------- */
.bf { position: absolute; left: 0; top: 0; will-change: transform, opacity; }
.bf svg { display: block; overflow: visible; filter: drop-shadow(0 6px 6px rgba(90, 60, 50, .18)); }
.wing { transform-box: view-box; transform-origin: 50% 50%; animation: flap var(--fs, .2s) ease-in-out infinite alternate; }
@keyframes flap { from { transform: scaleX(1); } to { transform: scaleX(.18); } }
.petal {
  position: absolute; top: -30px; width: 14px; height: 10px; border-radius: 80% 0 80% 0;
  background: linear-gradient(135deg, #f3d6cf, #d9a39b); opacity: .7; animation: fall linear forwards;
}
@keyframes fall { to { transform: translate(var(--dx), 112vh) rotate(var(--r)); } }

/* ---------- music ---------- */
#musicBtn {
  position: fixed; top: 16px; right: 16px; z-index: 60; width: 42px; height: 42px; border-radius: 50%;
  border: 1px solid rgba(75, 58, 53, .2); background: rgba(255, 250, 244, .6); backdrop-filter: blur(8px);
  color: var(--ink); font: 400 18px var(--serif); cursor: pointer;
}
#musicBtn.off { opacity: .45; }
#musicBtn.off::after { content: ''; position: absolute; left: 10px; right: 10px; top: 50%; height: 1px; background: var(--ink); transform: rotate(-45deg); }

/* ---------- scenes ---------- */
.scene {
  position: fixed; inset: 0; z-index: 10;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 24px 16px; text-align: center; gap: 12px;
  opacity: 0; visibility: hidden; transform: translateY(14px); filter: blur(6px);
  transition: opacity .9s ease, transform .9s ease, filter .9s ease, visibility 0s .9s;
}
.scene.active { opacity: 1; visibility: visible; transform: none; filter: none; transition: opacity .9s ease, transform .9s ease, filter .9s ease; }
.scene.leaving { opacity: 0; transform: translateY(-16px); filter: blur(8px); transition: opacity .6s ease, transform .6s ease, filter .6s ease; }

.eyebrow { font: 400 11px/1.4 var(--sans); letter-spacing: .38em; text-transform: uppercase; color: var(--muted); padding-left: .38em; }
.title { font: 400 clamp(32px, 8.5vw, 46px)/1.1 var(--serif); color: var(--ink); }
.hint { font: 300 14px/1.6 var(--sans); letter-spacing: .06em; color: var(--muted); }
.breathe { animation: breathe 2.6s ease-in-out infinite; }
@keyframes breathe { 50% { opacity: .35; } }
.link { background: none; border: 0; font: inherit; color: var(--rose); text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; cursor: pointer; letter-spacing: inherit; }
.fade { opacity: 0; }
.scene.active .fade { animation: rise 1.2s ease forwards; animation-delay: var(--d, 0s); }
@keyframes rise { from { opacity: 0; transform: translateY(14px); filter: blur(6px); } to { opacity: 1; transform: none; filter: none; } }

.next {
  margin-top: 18px; padding: 15px 34px; border-radius: 999px; cursor: pointer;
  font: 400 11px var(--sans); letter-spacing: .32em; text-transform: uppercase; color: var(--ink);
  background: rgba(255, 250, 244, .55); border: 1px solid rgba(75, 58, 53, .22); backdrop-filter: blur(8px);
  box-shadow: 0 10px 30px -12px rgba(90, 60, 50, .35); transition: background .3s, transform .2s;
}
.next::after { content: '  →'; letter-spacing: 0; }
.next:active { transform: scale(.97); background: rgba(255, 250, 244, .9); }
.next:not(.fade) { animation: rise 1s ease both; }

/* ---------- envelope ---------- */
.envelope { position: relative; width: 280px; height: 184px; margin: 40px 0 30px; cursor: pointer; perspective: 900px; animation: floaty 4s ease-in-out infinite; }
@keyframes floaty { 50% { transform: translateY(-8px); } }
.env-back { position: absolute; inset: 0; background: #e5cbc2; border-radius: 6px; box-shadow: 0 34px 60px -22px rgba(120, 80, 70, .5); }
.env-card {
  position: absolute; left: 16px; right: 16px; bottom: 8px; height: 160px; z-index: 2; border-radius: 4px;
  background: var(--paper); box-shadow: 0 2px 10px rgba(0, 0, 0, .06);
  display: flex; justify-content: center; padding-top: 22px;
  font: 400 24px var(--serif); color: var(--rose); letter-spacing: .04em;
  transition: transform 1s cubic-bezier(.3, .7, .3, 1) .45s;
}
.env-front { position: absolute; inset: 0; z-index: 3; background: linear-gradient(160deg, #f4e4dd, #ead2c9); clip-path: polygon(0 0, 50% 54%, 100% 0, 100% 100%, 0 100%); }
.env-flap { position: absolute; left: 0; right: 0; top: 0; height: 62%; z-index: 4; background: linear-gradient(#ead1c8, #dfbfb4); clip-path: polygon(0 0, 100% 0, 50% 100%); transform-origin: top; transition: transform .7s ease, z-index 0s .35s; }
.seal {
  position: absolute; left: 50%; top: 62%; width: 54px; height: 54px; margin: -27px 0 0 -27px; z-index: 5; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #c98a82, #a25e57 72%);
  box-shadow: 0 4px 10px rgba(110, 50, 45, .35), inset 0 0 0 5px rgba(255, 255, 255, .1), inset 0 0 0 6px rgba(80, 30, 25, .15);
  display: grid; place-items: center; font: 500 24px var(--serif); color: #f6e4dc; transition: transform .4s, opacity .4s;
}
.envelope.open { animation: none; }
.envelope.open .seal { transform: scale(.3); opacity: 0; }
.envelope.open .env-flap { transform: rotateX(180deg); z-index: 1; }
.envelope.open .env-card { transform: translateY(-92px); }

/* ---------- countdown ---------- */
.count { font: 300 34vmin/1 var(--serif); color: var(--ink); }
.count.pop { animation: countIn .95s ease-out; }
@keyframes countIn { from { opacity: 0; transform: scale(1.3); filter: blur(10px); } 35% { opacity: 1; filter: none; transform: none; } to { opacity: 0; transform: scale(.92); filter: blur(4px); } }

/* ---------- happy birthday ---------- */
.hb { font: 300 clamp(58px, 16.5vw, 124px)/.95 var(--serif); letter-spacing: -.01em; color: var(--ink); }
.hb.small { font-size: clamp(50px, 13vw, 96px); }
.hb span, .name span { display: inline-block; opacity: 0; animation: letterIn 1s ease forwards; }
@keyframes letterIn { from { opacity: 0; transform: translateY(16px); filter: blur(8px); } to { opacity: 1; transform: none; filter: none; } }
.divider { display: flex; align-items: center; gap: 14px; color: var(--gold); font-size: 13px; margin: 6px 0 2px; }
.divider::before, .divider::after { content: ''; width: 64px; height: 1px; background: currentColor; opacity: .55; }
.name { font: 500 clamp(26px, 7.6vw, 50px)/1.2 var(--serif); letter-spacing: .34em; padding-left: .34em; text-transform: uppercase; color: var(--rose); min-height: 1.2em; }
.sub { font: 300 clamp(15px, 4.2vw, 19px)/1.7 var(--sans); color: var(--muted); letter-spacing: .03em; max-width: 520px; }
.tap-next { cursor: pointer; }

/* ---------- cake ---------- */
.cake-wrap { display: flex; flex-direction: column; align-items: center; margin: 26px 0 10px; }
.candles { display: flex; gap: clamp(12px, 3.4vw, 18px); align-items: flex-end; height: 84px; margin-bottom: -6px; position: relative; z-index: 2; }
.candle { position: relative; width: 9px; height: 52px; cursor: pointer; border-radius: 2px; background: repeating-linear-gradient(-50deg, #fffaf3 0 6px, #e6cfa8 6px 8px); box-shadow: inset -2px 0 3px rgba(0, 0, 0, .06); }
.candle::before { content: ''; position: absolute; top: -7px; left: 4px; width: 1.5px; height: 7px; background: #4b3a35; }
.candle::after { content: ''; position: absolute; inset: -44px -10px -6px; }
.flame {
  position: absolute; left: 50%; top: -33px; width: 14px; height: 26px; margin-left: -7px;
  background: radial-gradient(ellipse at 50% 72%, #fff 0 18%, #ffe7a3 34%, #f2a65a 64%, transparent 71%);
  border-radius: 50% 50% 50% 50% / 62% 62% 38% 38%;
  filter: drop-shadow(0 0 10px rgba(242, 166, 90, .75));
  transform-origin: 50% 90%; animation: flicker .14s ease-in-out infinite alternate; transition: opacity .3s, transform .3s;
}
@keyframes flicker { from { transform: scale(1) rotate(-2deg); } to { transform: scale(.93, 1.07) rotate(2deg); } }
.smoke { position: absolute; left: 50%; top: -16px; width: 9px; height: 9px; margin-left: -4.5px; border-radius: 50%; background: rgba(140, 122, 114, .35); opacity: 0; }
.candle.out .flame { opacity: 0; transform: scale(.1); animation: none; }
.candle.out .smoke { animation: smoke 1.8s ease-out forwards; }
@keyframes smoke { 0% { opacity: .7; } to { opacity: 0; transform: translate(-8px, -70px) scale(4); } }

.tier { position: relative; border-radius: 10px 10px 4px 4px; overflow: hidden; box-shadow: inset 0 -8px 14px rgba(120, 80, 70, .06); }
.tier::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 22px;
  background:
    linear-gradient(var(--ic), var(--ic)) top / 100% 7px no-repeat,
    radial-gradient(circle at 10px 7px, var(--ic) 7px, transparent 7.5px) 0 0 / 20px 20px repeat-x;
}
.tier::after { content: ''; position: absolute; left: 0; right: 0; bottom: 6px; height: 8px; background: radial-gradient(circle, rgba(255, 255, 255, .9) 2.5px, transparent 3px) 0 0 / 14px 8px repeat-x; opacity: .8; }
.t1 { --ic: #fffaf4; width: min(140px, 40vw); height: 56px; background: linear-gradient(#f3d9d3, #e9c5bd); }
.t2 { --ic: #fffaf4; width: min(200px, 57vw); height: 64px; background: linear-gradient(#f7eee4, #ecdfd0); }
.t3 { --ic: #f7eee4; width: min(260px, 74vw); height: 74px; background: linear-gradient(#dfe4d4, #cbd3bf); }
.plate { width: min(300px, 86vw); height: 12px; margin-top: -3px; border-radius: 50%; background: linear-gradient(#efe5da, #cdbba8); box-shadow: 0 18px 30px -10px rgba(90, 60, 50, .45); }
.cake-wrap.done { animation: pulse .6s ease; }
@keyframes pulse { 50% { transform: scale(1.03); } }

/* ---------- gallery ---------- */
.gal-bg { position: absolute; inset: -60px; z-index: -1; background: center / cover no-repeat; filter: blur(46px) saturate(.85); opacity: .22; transition: background-image .8s; }
#galTitle.swap { animation: rise .9s ease; }
.stage { position: relative; width: min(92vw, 640px); height: min(58vh, 760px); height: min(58dvh, 760px); margin: 14px 0 4px; touch-action: pan-y; cursor: pointer; }
.polaroid {
  position: absolute; background: var(--paper); padding: 14px 14px 64px; border-radius: 3px;
  box-shadow: 0 26px 50px -18px rgba(90, 60, 50, .45), 0 2px 6px rgba(90, 60, 50, .08);
  opacity: 0; transform: translateX(70px) rotate(8deg) scale(.94); filter: blur(4px);
  transition: opacity .8s, transform .8s cubic-bezier(.2, .8, .2, 1), filter .8s;
}
.polaroid::before { content: ''; position: absolute; top: -12px; left: 50%; width: 96px; height: 26px; margin-left: -48px; background: rgba(233, 205, 198, .78); transform: rotate(-3deg); z-index: 2; box-shadow: 0 1px 2px rgba(0, 0, 0, .05); }
.polaroid.show { opacity: 1; transform: rotate(var(--rot)); filter: none; z-index: 2; }
.polaroid.prev { opacity: 0; transform: translateX(-70px) rotate(-10deg) scale(.94); filter: blur(4px); }
.pic { width: 100%; height: 100%; overflow: hidden; background: #e9dfd5; }
.pic img { width: 100%; height: 100%; object-fit: cover; display: block; }
.polaroid.show img { animation: kenburns 7s ease-out forwards; }
@keyframes kenburns { from { transform: scale(1.1); } to { transform: scale(1); } }
.ph { width: 100%; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; background: linear-gradient(135deg, var(--a), var(--b)); color: var(--ink); }
.ph b { font-size: 56px; }
.ph small { font-size: 12px; opacity: .8; }
.cap { position: absolute; left: 10px; right: 10px; bottom: 0; height: 64px; display: flex; align-items: center; justify-content: center; font: 500 clamp(17px, 4.6vw, 21px)/1.15 var(--serif); color: var(--ink); letter-spacing: .02em; overflow: hidden; }
.gal-meta { display: flex; align-items: center; gap: 14px; font: 400 11px var(--sans); letter-spacing: .25em; color: var(--muted); }
.gal-bar { width: 120px; height: 1px; background: rgba(75, 58, 53, .18); }
.gal-bar i { display: block; height: 100%; width: 0; background: var(--rose); transition: width .7s; }

/* ---------- letter ---------- */
.letter {
  width: min(460px, 100%); max-height: 68vh; overflow-y: auto; text-align: left; cursor: pointer;
  padding: 34px 30px 30px; border-radius: 4px; background: var(--paper); color: var(--ink);
  font: 400 clamp(19px, 5vw, 23px)/1.7 var(--serif);
  box-shadow: 0 34px 60px -24px rgba(90, 60, 50, .45); border: 1px solid rgba(176, 115, 107, .14);
}
.letter .eyebrow { margin-bottom: 18px; padding-left: 0; }
.scene.active .letter { animation: unfold 1s cubic-bezier(.2, .9, .3, 1) both; }
@keyframes unfold { from { transform: translateY(30px) scale(.97); opacity: 0; filter: blur(6px); } }
.letter p { margin-bottom: 12px; }
.caret { display: inline-block; width: 1px; height: 1em; background: var(--rose); vertical-align: -3px; margin-left: 1px; animation: breathe .8s infinite; }
.sign { text-align: right; color: var(--rose); opacity: 0; transition: opacity 1s; }
.sign.on { opacity: 1; }

/* ---------- final ---------- */
.big-bf { height: 110px; display: grid; place-items: center; animation: floaty 3.5s ease-in-out infinite; }
.big-bf .wing { --fs: .55s; }

/* ---------- Tablet (Lenovo Tab etc.) ---------- */
@media (min-width: 700px) and (min-height: 600px) {
  .scene { gap: 16px; }
  .eyebrow { font-size: 13px; }
  .title { font-size: 56px; }
  .hint { font-size: 17px; }
  .sub { font-size: 21px; }
  .next { font-size: 13px; padding: 18px 42px; margin-top: 26px; }
  #musicBtn { width: 52px; height: 52px; font-size: 22px; top: 22px; right: 22px; }
  .envelope { scale: 1.4; margin: 90px 0 60px; }
  .cake-wrap { scale: 1.35; margin: 80px 0 60px; }
  .candle::after { inset: -50px -12px -6px; }
  .letter { width: min(640px, 88vw); font-size: 27px; padding: 48px 50px 40px; }
  .big-bf { height: 150px; }
  .gal-meta { font-size: 13px; }
  .gal-bar { width: 200px; }
}
@media (min-width: 900px) and (max-height: 860px) and (orientation: landscape) {
  .stage { height: min(60vh, 640px); height: min(60dvh, 640px); }
  .envelope { scale: 1.2; margin: 50px 0 34px; }
  .cake-wrap { scale: 1.12; margin: 34px 0 24px; }
  .letter { max-height: 72vh; }
}
@media (max-height: 500px) and (orientation: landscape) {
  .scene { gap: 4px; padding: 10px 16px; }
  .hb { font-size: 20vh; }
  .envelope, .cake-wrap { scale: .7; margin: -10px 0; }
  .stage { height: 60vh; }
  .next { margin-top: 6px; padding: 10px 24px; }
}
@media (prefers-reduced-motion: reduce) {
  .envelope, .flame, .big-bf, .blob { animation: none; }
}
