:root {
  --ink: #6b4453;
  --ink-dark: #4a2f3c;
  --paper: #fffdf6;
  --butter: #ffe98a;
  --night: #241b2f;
  --font: "Mali", "Comic Sans MS", system-ui, sans-serif;
  /* One scene unit on screen. The SVG viewBox is 400 by 640. */
  --u: min(100vw / 400, 100vh / 640);
}
@supports (height: 100dvh) {
  :root { --u: min(100vw / 400, 100dvh / 640); }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--night);
  font-family: var(--font);
  color: var(--ink-dark);
  overscroll-behavior: none;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}

#stage {
  position: fixed;
  inset: 0;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

#scene {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}

/* Sticker style: every shape shares one soft outline. */
.line, .line > * {
  stroke: var(--ink);
  stroke-width: 4;
  stroke-linejoin: round;
}
.stroke {
  fill: none;
  stroke: var(--ink-dark);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.stroke.bold { stroke-width: 5; }
.stroke.thin { stroke-width: 2.6; }

#cake-name {
  font-family: var(--font);
  font-weight: 700;
  font-size: 28px;
}

/* Room light */
#night-full, #night-pool { transition: opacity 0.45s ease; }
#night-full { opacity: 0; pointer-events: none; }
#night-pool { opacity: 0; pointer-events: none; }
.room-off #night-full { opacity: 0.97; }
.room-candle #night-pool { opacity: 1; }
.room-on #night-full, .room-on #night-pool { opacity: 0; transition-duration: 0.9s; }

/* Candle body */
#hero { cursor: pointer; }
#hero-jump { transform-origin: 200px 400px; }
#hero-breath {
  transform-origin: 200px 400px;
  animation: breath 2.6s ease-in-out infinite;
}
#hero-lean {
  transform-origin: 200px 400px;
  transform: skewX(calc(var(--lean, 0) * -9deg));
}
@keyframes breath {
  0%, 100% { transform: scale(1, 1); }
  50% { transform: scale(1.018, 0.982); }
}

.eyes, .mouth { display: none; }
.eyes.on, .mouth.on { display: inline; }
#eyes-open, #eyes-puppy { transform-origin: 200px 316px; transition: transform 0.07s; }
#eyes-open.blink, #eyes-puppy.blink { transform: scaleY(0.08); }
.look { transform: translate(var(--look-x, 0), var(--look-y, 0)); transition: transform 0.12s; }
#eyes-puppy { animation: tremble 0.32s ease-in-out infinite; }
@keyframes tremble {
  50% { translate: 0 1px; }
}

.arm { transition: transform 0.25s cubic-bezier(0.3, 1.7, 0.5, 1); }
.arm-l { transform-origin: 160px 338px; }
.arm-r { transform-origin: 240px 338px; }
.arms-up .arm-l { transform: rotate(75deg); }
.arms-up .arm-r { transform: rotate(-75deg); }
.holding .arm-r { transform: none; }

/* Flame */
#flame-lean {
  transform-origin: 200px 258px;
  transform: skewX(calc(var(--lean, 0) * -30deg)) scale(var(--flame-scale, 1));
}
#flame-pop {
  transform-origin: 200px 258px;
  transition: transform 0.32s cubic-bezier(0.3, 1.9, 0.5, 1);
}
.flame-out #flame-pop {
  transform: scale(0);
  transition: transform 0.16s ease-in;
}
#flame-flicker {
  transform-origin: 200px 258px;
  animation: flicker 1.15s ease-in-out infinite;
}
@keyframes flicker {
  0%, 100% { transform: rotate(-2deg) scale(1, 1); }
  30% { transform: rotate(2.5deg) scale(0.97, 1.05); }
  60% { transform: rotate(-1deg) scale(1.03, 0.97); }
}
#glow { transition: opacity 0.2s; animation: glow 2.3s ease-in-out infinite; transform-origin: 200px 225px; }
.flame-out #glow { opacity: 0; }
@keyframes glow {
  50% { transform: scale(1.12); }
}

/* Small candles */
.baby-inner {
  transform: translateY(116px);
  transition: transform 0.45s cubic-bezier(0.3, 1.5, 0.5, 1);
}
.baby.up .baby-inner { transform: none; }
.baby-flame {
  transform-origin: 0 -67px;
  transition: transform 0.28s cubic-bezier(0.3, 1.9, 0.5, 1);
  animation: none;
}
.baby.out .baby-flame { transform: scale(0); }
.baby-dizzy { display: none; }
.baby.out .baby-dizzy { display: inline; }
.baby.out .baby-awake { display: none; }

/* Props and effects */
#umbrella {
  transform: scale(0);
  transition: transform 0.35s cubic-bezier(0.3, 1.7, 0.5, 1);
}
.has-umbrella #umbrella { transform: scale(1); }
#smoke, #heart-smoke, #dark-eyes, #zzz, #wish-stars { opacity: 0; pointer-events: none; }
#heart-smoke { transform-origin: 200px 170px; }

#dark-eyes { transition: opacity 0.2s; transform-origin: 200px 316px; }
.show-dark-eyes #dark-eyes {
  opacity: 1;
  animation: dark-blink 1.1s steps(1) infinite;
}
@keyframes dark-blink {
  0%, 40%, 58%, 100% { transform: scaleY(1); }
  44%, 54% { transform: scaleY(0.08); }
}

.wishing #wish-stars { opacity: 1; }
.star {
  animation: twinkle 2s ease-in-out infinite;
  animation-delay: var(--d);
  transform-box: fill-box;
  transform-origin: center;
}
@keyframes twinkle {
  0%, 100% { opacity: 0.25; transform: scale(0.7); }
  50% { opacity: 1; transform: scale(1.1); }
}

.sleeping #zzz { opacity: 1; }
#zzz text {
  font-family: var(--font);
  font-weight: 700;
  font-size: 20px;
  animation: zzz 2.4s ease-in-out infinite;
  animation-delay: var(--d);
  opacity: 0;
}
@keyframes zzz {
  0% { opacity: 0; translate: 0 8px; }
  40% { opacity: 1; }
  100% { opacity: 0; translate: 8px -16px; }
}

/* The real candle clip, shown after the wish. */
#film {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #efc4ac;
  transform: scale(1.02) translate(var(--wobble-x, 0), var(--wobble-y, 0));
}
/* On wide screens, show the whole frame instead of cropping off the cake. */
@media (min-aspect-ratio: 3/4) {
  #film { object-fit: contain; }
}
.film-on #scene { visibility: hidden; }

#film-flash {
  position: absolute;
  inset: 0;
  background: var(--paper);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s ease;
}
#film-flash.on { opacity: 1; transition-duration: 0.36s; }

#film-heart {
  position: absolute;
  width: 110px;
  height: 94px;
  opacity: 0;
  pointer-events: none;
  fill: #fffdf6;
  filter: blur(1.5px);
  overflow: visible;
}

#film-zzz {
  position: absolute;
  display: flex;
  gap: 6px;
  align-items: flex-end;
  pointer-events: none;
  color: #8b6577;
  font-size: 22px;
  font-weight: 700;
}
#film-zzz span {
  opacity: 0;
  animation: zzz 2.4s ease-in-out infinite;
  animation-delay: var(--d);
}

/* Speech bubble sits just above the flame tip at any screen size. */
#bubble {
  position: absolute;
  left: 50%;
  bottom: calc(50% + 152 * var(--u));
  width: min(88vw, 400px);
  padding: 13px 18px;
  transform: translateX(-50%);
  background: var(--paper);
  border: 3.5px solid var(--ink);
  border-radius: 22px;
  font-size: 20px;
  font-weight: 600;
  line-height: 1.38;
  text-align: center;
}
/* In the clip the flame sits higher, so the bubble moves up. It clears the sound button. */
.film-on #bubble {
  top: max(64px, calc(env(safe-area-inset-top) + 56px));
  bottom: auto;
}
#bubble::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -11px;
  width: 18px;
  height: 18px;
  background: inherit;
  border-right: 3.5px solid var(--ink);
  border-bottom: 3.5px solid var(--ink);
  transform: translateX(-50%) rotate(45deg);
  border-bottom-right-radius: 4px;
}
#bubble[data-who="baby"] { background: #fff0b8; font-size: 18px; }
#bubble[data-who="baby"]::after { left: 78%; }
#bubble.pop { animation: pop 0.24s cubic-bezier(0.3, 1.7, 0.5, 1); }
@keyframes pop {
  from { transform: translateX(-50%) scale(0.75); opacity: 0; }
}
#bubble p { margin: 0; }
#bubble-rest { visibility: hidden; }

#intro {
  position: absolute;
  inset: 0 0 auto;
  top: 34%;
  padding: 0 24px;
  text-align: center;
  color: #f4e6da;
  font-size: 21px;
  font-weight: 600;
  line-height: 1.45;
}
#intro p { margin: 0; }

/* Controls */
#controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: max(18px, calc(env(safe-area-inset-bottom) + 12px));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
}
.btn {
  font-family: var(--font);
  font-size: 19px;
  font-weight: 700;
  padding: 13px 28px;
  min-height: 52px;
  color: var(--ink-dark);
  background: var(--butter);
  border: 3.5px solid var(--ink);
  border-radius: 999px;
  box-shadow: 0 5px 0 var(--ink);
  cursor: pointer;
  transition: transform 0.06s, box-shadow 0.06s;
}
.btn:active, .btn.pressed {
  transform: translateY(4px);
  box-shadow: 0 1px 0 var(--ink);
}
.btn.soft { background: var(--paper); }
.btn:focus-visible, #sound-btn:focus-visible, #replay:focus-visible {
  outline: 3px solid #e0668a;
  outline-offset: 3px;
}
.btn.big { padding: 16px 34px; font-size: 21px; touch-action: none; }
.hint {
  margin: 0;
  padding: 3px 12px;
  font-size: 15px;
  font-weight: 600;
  text-align: center;
  color: #f7ebe0;
  background: rgba(36, 27, 47, 0.62);
  border-radius: 999px;
}

#sound-btn {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  right: 12px;
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  padding: 0;
  color: var(--ink-dark);
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 50%;
  cursor: pointer;
}
#sound-off-mark { display: none; }
#sound-btn[aria-pressed="true"] #sound-off-mark { display: inline; }
#sound-btn[aria-pressed="true"] #sound-on-mark { display: none; }

/* Final note */
/* The note sits at the bottom so the sleeping candle's face stays visible. */
#note {
  position: absolute;
  left: 50%;
  bottom: max(14px, calc(env(safe-area-inset-bottom) + 10px));
  width: min(92vw, 400px);
  max-height: calc(100% - 32px);
  overflow: auto;
  padding: 24px 20px 14px;
  background: var(--paper);
  border: 3.5px solid var(--ink);
  border-radius: 8px;
  box-shadow: 0 7px 0 rgba(107, 68, 83, 0.28);
  transform: translateX(-50%) rotate(-1.4deg);
  animation: note-in 0.6s cubic-bezier(0.3, 1.35, 0.5, 1);
  font-size: 16px;
  font-weight: 500;
  line-height: 1.38;
}
@keyframes note-in {
  from { transform: translate(-50%, 120%) rotate(6deg); }
}
#note::before {
  content: "";
  position: absolute;
  top: 7px;
  left: 50%;
  width: 96px;
  height: 14px;
  background: #ffb3c7;
  opacity: 0.75;
  transform: translateX(-50%) rotate(1.6deg);
}
#note-body p { margin: 0 0 8px; }
#note-body .ask { font-weight: 700; font-size: 18px; color: #c94f76; }
#note-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 8px;
  padding-bottom: 6px;
}
#note-actions .btn { font-size: 17px; padding: 9px 20px; min-height: 46px; }
#note-actions a { text-decoration: none; display: inline-block; }
#replay {
  display: block;
  margin: 6px auto 0;
  padding: 4px;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  background: none;
  border: 0;
  text-decoration: underline;
  cursor: pointer;
}

#mic-debug {
  position: absolute;
  left: 6px;
  top: 6px;
  z-index: 9;
  margin: 0;
  padding: 6px 8px;
  font: 12px/1.35 monospace;
  color: #fff;
  background: rgba(0, 0, 0, 0.72);
  border-radius: 6px;
  pointer-events: none;
}

.particle {
  position: absolute;
  z-index: 5;
  pointer-events: none;
  line-height: 1;
}

@media (prefers-reduced-motion: reduce) {
  #hero-breath, #flame-flicker, #glow, #eyes-puppy { animation: none; }
  #note { animation: none; }
}
