/* The candle is a close-up: only the top half of it lives inside the frame,
   so `--cnd-rim` is where the wax surface sits and the rest runs off the
   bottom edge. Everything else is measured from those two numbers. */
.birthday { background: #070509; --cnd-h: 92vh; --cnd-rim: 70%; --cnd-lift: 53%; }
.birthday .film-grain { z-index: 4; }

/* The room: nothing is lit but the corner the candle will stand in. */
.cnd-room { position: absolute; z-index: 0; inset: 0; pointer-events: none; }
.cnd-air {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 76% 46% at 50% 78%, #2b1a12 0%, #1a0f0b 42%, #0a0709 78%, #060409 100%),
    linear-gradient(180deg, #0a070b 0%, #070509 100%);
}
.cnd-glow {
  position: absolute;
  inset: 0;
  opacity: 0;
  background:
    radial-gradient(circle 48vmax at var(--cnd-x, 50%) var(--cnd-y, 66%), rgb(255 206 146 / 34%) 0%, rgb(255 168 96 / 13%) 34%, transparent 64%),
    radial-gradient(circle 20vmax at var(--cnd-x, 50%) var(--cnd-y, 66%), rgb(255 226 178 / 34%) 0%, transparent 70%);
  will-change: opacity;
}

.cnd-stage { position: absolute; z-index: 2; inset: 0; pointer-events: none; }
.cnd-floor {
  position: absolute;
  left: 50%;
  bottom: 6%;
  width: min(66vw, 340px);
  height: min(19vw, 96px);
  transform: translate(-50%, 0);
  border-radius: 50%;
  background: radial-gradient(ellipse at 50% 50%, rgb(255 186 128 / 18%) 0%, rgb(255 150 90 / 6%) 45%, transparent 72%);
  filter: blur(9px);
  opacity: 0;
  will-change: opacity;
}

/* The candle box holds the candle and the air its flame lives in: the wax
   starts a third of the way down, exactly like the drawing's coordinates. */
.cnd-candle {
  position: absolute;
  left: 50%;
  top: calc(var(--cnd-rim) - 0.33 * var(--cnd-h));
  height: var(--cnd-h);
  aspect-ratio: 120 / 352;
  transform: translate(-50%, 33%);
  transform-origin: 50% 80%;
  opacity: 0;
  will-change: transform, opacity;
}
.cnd-svg { display: block; width: 100%; height: 100%; }
/* The base needs something to stand on, or the wax reads as cut off by the
   frame. The shadow is on the floor, so it does not rise with the candle's box. */
.cnd-candle::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -2%;
  width: 165%;
  height: 6.5%;
  transform: translateX(-50%);
  border-radius: 50%;
  background: radial-gradient(ellipse at 50% 50%, rgb(0 0 0 / 62%) 0%, rgb(0 0 0 / 26%) 46%, transparent 74%);
  filter: blur(5px);
  pointer-events: none;
}

/* Wax, when the flame has left it: dark, but still turning under the light. */
.cnd-wax-dim {
  position: absolute;
  left: 22%;
  right: 22%;
  top: 32.4%;
  bottom: 0;
  opacity: 0;
  border-radius: 34% 34% 6px 6px / 3% 3% 6px 6px;
  background:
    linear-gradient(180deg, rgb(9 7 11 / 44%) 0%, rgb(9 7 11 / 24%) 46%, rgb(7 6 10 / 44%) 100%),
    linear-gradient(90deg, rgb(9 7 11 / 54%) 0%, rgb(9 7 11 / 16%) 34%, rgb(9 7 11 / 3%) 54%, rgb(9 7 11 / 20%) 78%, rgb(9 7 11 / 54%) 100%);
  will-change: opacity;
}

/* The catch: one small star of light where the wick is about to take. */
.cnd-spark {
  position: absolute;
  left: 50%;
  top: 30.7%;
  width: 40px;
  height: 40px;
  transform: translate(-50%, -50%) scale(0.6);
  border-radius: 50%;
  opacity: 0;
  background: radial-gradient(circle, #fffdf0 0%, #ffe9ac 26%, rgb(255 168 80 / 42%) 52%, transparent 72%);
  filter: blur(0.4px);
}
.cnd-spark::after {
  content: "";
  position: absolute;
  inset: 34%;
  border-radius: 50%;
  background: radial-gradient(circle, #fffef9 0%, rgb(255 240 200 / 0%) 72%);
}

.cnd-smoke { position: absolute; left: 50%; top: 30.7%; width: 30px; height: 130px; transform: translate(-50%, -100%); opacity: 0; }
.cnd-smoke i {
  position: absolute;
  left: 50%;
  bottom: 0;
  width: 15px;
  height: 15px;
  margin-left: -7.5px;
  border-radius: 50%;
  opacity: 0;
  background: radial-gradient(circle, rgb(228 221 211 / 38%) 0%, rgb(228 221 211 / 12%) 45%, transparent 70%);
  filter: blur(2.4px);
  animation: cnd-puff 3.4s ease-out 3;
  animation-play-state: paused;
}
.cnd-smoke i:nth-child(2) { animation-delay: 0.85s; }
.cnd-smoke i:nth-child(3) { animation-delay: 1.7s; }
.cnd-smoke.is-live i { animation-play-state: running; }
@keyframes cnd-puff {
  0% { opacity: 0; transform: translate(0, 0) scale(0.45); }
  14% { opacity: 0.6; }
  58% { opacity: 0.3; transform: translate(7px, -58px) scale(1.25); }
  100% { opacity: 0; transform: translate(-5px, -116px) scale(1.85); }
}

/* A flame is never still. The slow sway lives here; the scene only scales and
   leans the group it sits in. */
.cnd-flicker { transform-box: fill-box; transform-origin: 50% 92%; animation: cnd-flicker 2.9s ease-in-out infinite; }
@keyframes cnd-flicker {
  0%, 100% { transform: translateY(0) scale(1, 1) rotate(-0.5deg); opacity: 1; }
  18% { transform: translateY(-0.6px) scale(0.982, 1.028) rotate(0.7deg); opacity: 0.95; }
  39% { transform: translateY(0.4px) scale(1.016, 0.986) rotate(-0.9deg); opacity: 0.99; }
  61% { transform: translateY(-0.4px) scale(0.99, 1.014) rotate(0.4deg); opacity: 0.96; }
  80% { transform: translateY(0.2px) scale(1.008, 0.994) rotate(-0.3deg); opacity: 1; }
}
.cnd-svg [data-cnd-flame] { filter: drop-shadow(0 0 7px rgb(255 170 92 / 50%)) drop-shadow(0 0 22px rgb(255 128 58 / 26%)); }

.cnd-scroll { position: absolute; z-index: 6; inset: 0; overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain; touch-action: pan-y pinch-zoom; scrollbar-width: none; }
.cnd-scroll::-webkit-scrollbar { display: none; }
.cnd-scroll:focus-visible { outline-offset: -10px; }
.cnd-track { height: var(--scene-track); }
.cnd-frame { position: sticky; top: 0; height: 100svh; pointer-events: none; }

/* The words hang just above the flame, so the two always read as one thing
   whatever the height of the screen is. */
.cnd-copy { position: absolute; inset-block-end: var(--cnd-lift); inset-inline: var(--page-gutter); text-align: center; }
.cnd-line { margin: 0; font-family: Sahel, sans-serif; font-weight: 700; color: #f3ead8; opacity: 0; will-change: opacity; }
.cnd-line-a { font-size: clamp(1.9rem, 8vw, 2.4rem); line-height: 1.65; text-wrap: balance; }
.cnd-line-b {
  margin-block-start: 1rem;
  font-size: clamp(0.95rem, 4vw, 1.1rem);
  line-height: 2;
  color: rgb(230 216 194 / 76%);
  text-wrap: balance;
}

@media (min-width: 601px) {
  .birthday { --cnd-h: 94vh; --cnd-rim: 69%; --cnd-lift: 52%; }
  .cnd-line-a { font-size: 2.5rem; }
  .cnd-line-b { margin-block-start: 1.1rem; font-size: 1.05rem; }
}
@media (max-height: 720px) and (max-width: 600px) {
  .birthday { --cnd-h: 96vh; --cnd-rim: 72%; --cnd-lift: 55%; }
  .cnd-line-a { font-size: 1.6rem; }
  .cnd-line-b { margin-block-start: 0.6rem; font-size: 0.9rem; }
}
@media (orientation: landscape) and (max-height: 500px) {
  .birthday { --cnd-h: 88vh; --cnd-rim: 66%; }
  .cnd-candle { left: 29%; }
  .cnd-copy { inset-block-start: 28%; inset-block-end: auto; inset-inline-start: 46%; inset-inline-end: 6%; text-align: start; }
  .cnd-line-a { font-size: 1.5rem; }
  .cnd-line-b { font-size: 0.9rem; }
}
@media (prefers-reduced-motion: reduce) {
  .cnd-flicker { animation: none; }
  .cnd-smoke i { animation: none; }
  .cnd-candle, .cnd-glow { will-change: auto; }
}
