/* ---------- The walk-in and the cake ---------- */
/* the #cake section is only the text on top; the cake itself is a layer in the world below */
#cake {
  justify-content: space-between; gap: 0; min-height: 100vh; min-height: 100dvh;
  padding-top: calc(env(safe-area-inset-top, 0px) + 1.3rem); padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 1.5rem);
}
main:has(> #cake.active) { pointer-events: none; }
#cake, #cake * { pointer-events: none; }
#cake { max-width: 56rem; }
#cake .nw { white-space: nowrap; }
/* a soft night scrim behind the title, so it reads over the busy room */
#cake::before {
  content: ""; position: fixed; left: 0; right: 0; top: 0; height: 30vh; z-index: -1; pointer-events: none; opacity: 0;
  background: linear-gradient(rgba(20, 12, 28, .55), rgba(20, 12, 28, .25) 55%, rgba(20, 12, 28, 0));
}
#cake.ready::before, #cake.party::before { opacity: 1; animation: ckIn 1s ease both; }
#cake.fading::before { opacity: 0; animation: ckOut .6s ease both; }
.cake-top, .cake-bottom { display: flex; flex-direction: column; align-items: center; gap: .45rem; width: 100%; }
#cake .title { opacity: 0; text-shadow: 0 2px 0 #1d1327, 0 0 22px rgba(29, 19, 39, .95); }
#cake .lede { text-shadow: 0 1px 8px #1d1327, 0 0 2px #1d1327; color: var(--cream); }
#cake-hint { opacity: 0; }
#cake.ready .title, #cake.ready #cake-hint { opacity: 1; animation: ckIn .8s ease both; }
#cake.party .title { opacity: 1; font-size: clamp(2rem, 8.2vw, 3.4rem); line-height: 1.08; animation: titlepop .9s cubic-bezier(.3, 1.6, .5, 1) both; }
#cake.fading .cake-top, #cake.fading .cake-bottom { animation: ckOut .6s ease forwards; }
@keyframes ckIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes ckOut { to { opacity: 0; transform: translateY(-10px); } }
@keyframes titlepop { from { transform: scale(.6); opacity: 0; } to { transform: none; opacity: 1; } }
.after { display: flex; flex-direction: column; align-items: center; gap: 1rem; animation: ckIn .8s ease .3s both; }
.meter { width: 9rem; height: .5rem; border-radius: 999px; background: rgba(251, 239, 228, .2); overflow: hidden; box-shadow: 0 0 0 1px rgba(29, 19, 39, .5); }
#birthday-line { text-wrap: balance; max-width: 22ch; }
.meter span { display: block; height: 100%; width: 100%; background: var(--flame); transform: scaleX(var(--level, 0)); transform-origin: 0 50%; }

/* the cake stage (a world layer, 520 x 468 world px; 1em = 1/21 of the stage, as 1rem was) */
.cake-layer { overflow: visible; }
.cake-art, .cake-art > svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.smoke-cv { position: absolute; left: -25%; width: 150%; bottom: 55%; height: 140%; pointer-events: none; z-index: 3; }

/* characters on the cake: always gently alive. Sway, hop and hello move HTML wrappers (composited);
   only the tail moves inside the little SVG, and it rests while the camera walks. Blinks are a class
   flip from room.js (.eyes.shut), so nothing repaints between blinks. */
.ck-ch { position: absolute; }
.ck-ch, .ck-ch .ck-sw, .ck-char .ck-sw, .ck-char .ck-hopw { transform-origin: var(--ox, 50%) var(--oy, 100%); }
.ck-sw { width: 100%; height: 100%; }
.ck-ch svg { display: block; width: 100%; height: 100%; overflow: visible; }
.ck-ch .ck-sw { animation: sway 3.2s ease-in-out infinite; }
.ck-ch.c-top .ck-sw { animation-duration: 4.6s; animation-delay: -1.7s; }
.cake-layer.hello .ck-ch { animation: ckHello .7s cubic-bezier(.3, 1.7, .5, 1) .15s; }
.cake-layer.hello .ck-ch.c-top { animation-delay: .3s; }
@keyframes ckHello { 40% { transform: translateY(-9px) scale(1.05, .96); } }
@keyframes sway { 0%, 100% { transform: rotate(-3deg); } 50% { transform: rotate(3deg); } }
/* tails: room.js gives one character at a time a few quick swishes (.tail.flick), so a tail only
   re-lays-out its SVG while it is actually moving */
.ck-blink .tail { transform-box: fill-box; transform-origin: 0 100%; }
.ck-blink .tail.flick { animation: swish .34s ease-in-out 4 alternate; }
@keyframes swish { from { transform: rotate(-9deg); } to { transform: rotate(11deg); } }
.ck-blink .eyes { transform-box: fill-box; transform-origin: 50% 50%; }
.ck-blink .eyes.shut { transform: scaleY(.1); }
.cake-layer.party .ck-ch .ck-sw { animation: hop .42s ease-in-out infinite alternate; }
.cake-layer.party .ck-ch.c-top .ck-sw { animation-delay: -.3s; }
@keyframes hop { from { transform: translateY(0) rotate(-4deg); } to { transform: translateY(-7px) rotate(4deg); } }
/* the black cat from the doorstep: hidden on the cake until it has leapt up there */
.cake-layer.cat-away .ck-ch.c-top { visibility: hidden; }
.cake-layer.cat-land .ck-ch.c-top { animation: ckLand .45s ease-out; }

/* candles */
.candles { position: absolute; inset: 0; z-index: 2; }
.candle {
  position: absolute; width: 2.4em; height: 7em; margin-left: -1.2em; margin-top: -7em;
  transform: scale(var(--s, 1)); transform-origin: 50% 100%;
  background: none; border: 0; padding: 0; cursor: pointer; font-size: inherit;
}
.candle .cbody { position: absolute; inset: 0; transform-origin: 50% 100%; transform: scaleY(0); }
.cake-layer.candle-in .candle .cbody { animation: grow .7s cubic-bezier(.3, 1.4, .5, 1) calc(var(--i, 0) * 90ms) both; }
@keyframes grow { from { transform: scaleY(0); } to { transform: none; } }
.stick {
  position: absolute; bottom: 0; left: 50%; width: .82em; height: 3.7em; margin-left: -.41em;
  border-radius: .12em .12em .2em .2em;
  background:
    linear-gradient(90deg, rgba(40, 20, 50, .35), rgba(0, 0, 0, 0) 30%, rgba(255, 255, 255, .45) 48%, rgba(0, 0, 0, 0) 62%, rgba(40, 20, 50, .4)),
    repeating-linear-gradient(-58deg, var(--cream) 0 .42em, var(--stripe, #7aa7e6) .42em .84em);
}
.stick::before { /* melted top */
  content: ""; position: absolute; top: -.18em; left: 0; right: 0; height: .36em; border-radius: 50%;
  background: radial-gradient(ellipse at 50% 40%, #fffaf2, #efe0d2);
}
.stick::after { /* a wax drip */
  content: ""; position: absolute; top: .02em; left: -.06em; width: .26em; height: 1em;
  border-radius: 0 0 .2em .2em; background: linear-gradient(90deg, #fffaf2, #eadccd);
}
.wick { position: absolute; left: 50%; bottom: 3.65em; width: 3px; height: .55em; margin-left: -1.5px; background: #2c1d1d; border-radius: 1px; }
.ember {
  position: absolute; top: -3px; left: -2px; width: 7px; height: 7px; border-radius: 50%;
  background: #ff8a3d; opacity: 0;
}
.candle.out .ember { animation: ember 2.8s ease-out forwards; }
@keyframes ember {
  0% { opacity: 1; box-shadow: 0 0 6px 3px rgba(255, 120, 40, .9); }
  100% { opacity: 0; box-shadow: 0 0 0 0 rgba(255, 120, 40, 0); }
}

.flame-wrap {
  position: absolute; left: 50%; bottom: 4.05em; width: 1.5em; height: 3em; margin-left: -.75em;
  transform-origin: 50% 92%;
  transform: rotate(calc(var(--lean, 0) * var(--dir, 1) * 38deg)) scale(calc(1 - var(--lean, 0) * .3), calc(1 + var(--lean, 0) * .3));
  transition: transform .14s ease-out;
  opacity: 0;
}
.candle.lit .flame-wrap { opacity: 1; }
.flame { position: absolute; inset: 0; transform-origin: 50% 92%; }
.candle.lit .flame { animation: ignite .8s cubic-bezier(.3, 1.6, .5, 1) both; }
@keyframes ignite { 0% { transform: scale(.1, .1); opacity: 0; } 40% { transform: scale(1.35, 1.5); opacity: 1; } 100% { transform: none; } }
.flame i {
  position: absolute; left: 0; right: 0; margin-inline: auto; bottom: 0;
  border-radius: 50% 50% 50% 50% / 62% 62% 38% 38%;
  transform-origin: 50% 90%;
  mix-blend-mode: screen;
}
.f-outer { width: 100%; height: 100%;
  background: radial-gradient(ellipse 62% 72% at 50% 72%, rgba(255, 160, 50, .95), rgba(255, 100, 30, .6) 50%, rgba(255, 70, 20, 0) 80%);
  animation: lick1 .82s ease-in-out infinite alternate; }
.f-mid { width: 72%; height: 80%;
  background: radial-gradient(ellipse 60% 70% at 50% 70%, #fff1b0, #ffcf5c 45%, rgba(255, 170, 60, .2) 80%);
  animation: lick2 .64s ease-in-out infinite alternate; }
.f-core { width: 40%; height: 46%; bottom: 7% !important;
  background: radial-gradient(ellipse at 50% 60%, #fffef6, #fff6cf 60%, rgba(255, 240, 190, 0) 100%);
  animation: lick2 .5s ease-in-out infinite alternate-reverse; }
.f-blue { width: 38%; height: 20%; bottom: 3% !important;
  background: radial-gradient(ellipse at 50% 70%, rgba(110, 150, 255, .9), rgba(80, 120, 255, 0) 70%); }
@keyframes lick1 {
  0% { transform: scale(1, 1) skewX(0deg); }
  30% { transform: scale(.94, 1.07) skewX(2.5deg); }
  55% { transform: scale(1.04, .95) skewX(-2deg); }
  80% { transform: scale(.97, 1.09) skewX(1.5deg); }
  100% { transform: scale(1.02, 1) skewX(-1deg); }
}
@keyframes lick2 {
  0% { transform: scale(1, 1) translateX(0); }
  40% { transform: scale(.93, 1.08) translateX(.5px); }
  100% { transform: scale(1.05, .96) translateX(-.5px); }
}
.halo {
  position: absolute; left: 50%; top: 45%; width: 10em; height: 10em; margin: -5em 0 0 -5em; border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 196, 100, .42), rgba(255, 170, 70, .12) 35%, rgba(255, 170, 70, 0) 62%);
  mix-blend-mode: screen; pointer-events: none;
  animation: halo 2.3s ease-in-out infinite;
}
.candle.lit .halo { animation: flare .9s ease-out, halo 2.3s ease-in-out .9s infinite; }
@keyframes halo { 0%, 100% { transform: scale(1); opacity: 1; } 40% { transform: scale(.92); opacity: .8; } 70% { transform: scale(1.05); opacity: .95; } }
@keyframes flare { 0% { transform: scale(.2); opacity: 0; } 30% { transform: scale(1.6); opacity: 1; } 100% { transform: scale(1); } }
.candle.out .flame-wrap { animation: snuff .4s ease-in forwards; }
@keyframes snuff {
  0% { opacity: 1; }
  40% { transform: rotate(calc(var(--dir, 1) * 50deg)) scale(.7, 1.3); opacity: .9; }
  100% { transform: rotate(calc(var(--dir, 1) * 60deg)) scale(.05, .2); opacity: 0; }
}

/* candlelight on the room: wall, table and floor flicker with the flame */
.ck-glow, .ck-glow-floor { opacity: 0; border-radius: 50%; }
.ck-glow-wall { background: radial-gradient(closest-side, rgba(255, 186, 96, .36), rgba(255, 160, 70, .13) 45%, rgba(255, 150, 60, 0)); }
.ck-glow-table { background: radial-gradient(closest-side, rgba(255, 200, 120, .5), rgba(255, 170, 80, .16) 50%, rgba(255, 150, 60, 0)); }
.ck-glow-floor { background: radial-gradient(closest-side, rgba(255, 186, 100, .3), rgba(255, 160, 70, .1) 55%, rgba(255, 150, 60, 0)); }
.cake-lit .ck-glow, .cake-lit .ck-glow-floor { animation: ckIn .9s ease-out both, ckFlicker 2.6s ease-in-out .9s infinite; }
@keyframes ckFlicker { 0%, 100% { opacity: 1; } 22% { opacity: .84; } 47% { opacity: .97; } 63% { opacity: .8; } 81% { opacity: .94; } }
.cake-party .ck-glow-wall { opacity: 1; animation: ckIn 1.6s ease both; background: radial-gradient(closest-side, rgba(238, 138, 164, .3), rgba(197, 138, 224, .12) 50%, rgba(197, 138, 224, 0)); }

/* the room's party pieces */
.ck-table svg, .ck-prop svg, .ck-char svg, .ck-star svg { display: block; overflow: visible; }
.ck-balloons svg, .ck-bunt svg, .ck-pennants svg { position: absolute; left: 0; top: 0; display: block; overflow: visible; }
.ck-bob { position: absolute; left: 0; top: 0; animation: ckBob var(--t, 4s) ease-in-out var(--d, 0s) infinite alternate; }
@keyframes ckBob { from { transform: rotate(-4deg); } to { transform: rotate(4deg) translateY(-6px); } }
/* only the pennants flutter: any moving transform above the HAPPY BIRTHDAY letters (SVG text) makes
   the browser re-style and re-lay-out them on every frame, so that bunting hangs still */
.bw-a, .pf-a { position: absolute; inset: 0; transform-origin: 50% 0; }
.pf-a { animation: ckFlutter 3.1s ease-in-out infinite alternate; }
/* the cake pick stands still (no sway or party hop) */
.ck-ch.c-pick .ck-sw, .cake-layer.party .ck-ch.c-pick .ck-sw { animation: none; }
@keyframes ckFlutter { from { transform: skewX(-4deg); } to { transform: skewX(4deg); } }
.ck-hang { transform-origin: 50% 0; animation: ckPend 4.4s ease-in-out infinite alternate; }
@keyframes ckPend { from { transform: rotate(-7deg); } to { transform: rotate(7deg); } }
/* room characters breathe (an HTML wrapper sways), blink and swish */
.ck-char .ck-kpaw { transform-box: fill-box; }
.ck-kpop, .ck-hopw { position: absolute; left: 0; top: 0; width: 100%; height: 100%; }
.ck-char svg { width: 100%; height: 100%; }
.ck-char .ck-sw { animation: sway 3.6s ease-in-out infinite; }
.ck-grey .ck-sw { animation-duration: 4.4s; animation-delay: -2s; }
/* Kuromi behind the gifts: tucked out of sight (clipped at the floor), then she pops up and waves */
.ck-kuro { clip-path: inset(-400px -60px 10px -60px); }
.ck-kpop { transform: translateY(66px); }
.ck-kpaw { opacity: 0; transform: translate(38px, -64px); }
.ck-kuro.peek .ck-kpop { animation: ckPeek .7s cubic-bezier(.3, 1.6, .5, 1) forwards; }
.ck-kuro.peek .ck-kpaw { opacity: 1; animation: ckWave .32s ease-in-out .5s 10 alternate; }
@keyframes ckPeek { from { transform: translateY(66px); } to { transform: translateY(-78px); } }
@keyframes ckWave { from { transform: translate(38px, -64px) rotate(-25deg); } to { transform: translate(44px, -84px) rotate(25deg); } }
.cake-party .ck-kuro .ck-kpop { animation: ckJump .46s ease-in-out infinite alternate; }
.cake-party .ck-kuro .ck-kpaw { animation: ckWave .3s ease-in-out 16 alternate; }
@keyframes ckJump { from { transform: translateY(-70px); } to { transform: translateY(-130px); } }
/* the orange tabby: trots, hops up, sits */
.ck-tabby .ck-tw { position: absolute; left: 0; top: 0; display: block; }
.ck-tabby .ck-ts { display: none; }
.ck-tabby.sit .ck-tw { display: none; }
.ck-tabby.sit .ck-ts { display: block; }
.ck-tabby:not(.trot) .cw-la, .ck-tabby:not(.trot) .cw-lb, .ck-tabby:not(.trot) .cw-bob, .ck-tabby.sit .cat-walk * { animation: none; }
.ck-tabby.landed .ck-hopw { animation: ckLand .45s ease-out; }
@keyframes ckLand { 30% { transform: scale(1.12, .86); } 65% { transform: scale(.96, 1.05); } }
/* the grey tabby looks up at the balloons */
.ck-grey.look .ck-hopw { animation: ckLook 1.2s ease-in-out; }
@keyframes ckLook { 30%, 70% { transform: translateY(-4px) rotate(-6deg); } }
.cake-party .ck-char .ck-hopw { animation: ckHop .44s ease-in-out infinite alternate; }
.cake-party .ck-grey .ck-hopw { animation-delay: -.2s; animation-name: ckHopS; }
@keyframes ckHopS { from { transform: translateY(0); } to { transform: translateY(-16px) rotate(-4deg); } }
@keyframes ckHop { from { transform: translateY(0); } to { transform: translateY(-26px) rotate(4deg); } }
