:root {
  /* Pastel birthday palette */
  --bg-1: #ffe4f1;
  --bg-2: #e0f3ff;
  --bg-3: #fff7d6;
  --pink: #ff8fb8;
  --pink-deep: #ff5e9c;
  --peach: #ffd3b4;
  --cream: #fff3df;
  --mint: #b6ecd6;
  --sky: #b8e0ff;
  --lemon: #ffe27a;
  --plate: #f3f3fb;
  --plate-shadow: #d9d9ec;
  --frosting: #fff0f6;
  --frosting-deep: #ffc8dd;
  --cake-1: #f7b7a3;
  --cake-2: #f9d29d;
  --cake-3: #f6a6c1;
  --candle-1: #f7c8e0;
  --candle-2: #b5e8d5;
  --candle-3: #ffd28a;
  --candle-4: #b8d6ff;
  --candle-5: #d8c1ff;
  --flame-out: #ffb347;
  --flame-in: #fff3b0;
  --text: #5b3a55;
  --text-soft: #8a6f86;
  --shadow: 0 10px 24px rgba(190, 110, 160, 0.25);
  --font: 'Comic Sans MS', 'Chalkboard SE', 'Baloo 2', 'Nunito', system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(circle at 20% 10%, var(--bg-1), transparent 55%),
    radial-gradient(circle at 80% 20%, var(--bg-2), transparent 55%),
    radial-gradient(circle at 50% 90%, var(--bg-3), transparent 60%),
    linear-gradient(180deg, #fff4fb, #fef9ff);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

#app {
  position: relative;
  width: 100%;
  height: 100%;
}

/* Confetti background */
.confetti {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    radial-gradient(circle, var(--pink) 2px, transparent 3px),
    radial-gradient(circle, var(--sky) 2px, transparent 3px),
    radial-gradient(circle, var(--lemon) 2px, transparent 3px),
    radial-gradient(circle, var(--mint) 2px, transparent 3px);
  background-size: 120px 120px, 140px 140px, 160px 160px, 180px 180px;
  background-position: 0 0, 40px 60px, 80px 20px, 20px 100px;
  opacity: 0.5;
  animation: floatBg 18s linear infinite;
}
@keyframes floatBg {
  from { background-position: 0 0, 40px 60px, 80px 20px, 20px 100px; }
  to   { background-position: 120px 120px, 160px 200px, 240px 180px, 200px 280px; }
}

/* View management */
.view {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.5s ease;
}
.view.active { display: flex; }
@keyframes fadeIn {
  from { opacity: 0; transform: scale(0.98); }
  to   { opacity: 1; transform: scale(1); }
}

/* Buttons */
.btn {
  font-family: var(--font);
  font-weight: 700;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.2s;
  outline: none;
}
.btn:focus-visible {
  box-shadow: 0 0 0 4px rgba(255, 94, 156, 0.4);
}
.btn-primary {
  font-size: 1.4rem;
  padding: 18px 42px;
  color: white;
  background: linear-gradient(135deg, var(--pink), var(--pink-deep));
  box-shadow: var(--shadow), inset 0 -4px 0 rgba(0, 0, 0, 0.12);
  letter-spacing: 0.5px;
}
.btn-primary:hover { transform: translateY(-2px) scale(1.03); }
.btn-primary:active { transform: translateY(1px) scale(0.98); }
.btn-ghost {
  background: rgba(255, 255, 255, 0.7);
  color: var(--text);
  padding: 10px 14px;
  font-size: 1.1rem;
  border-radius: 999px;
  box-shadow: 0 4px 10px rgba(160, 110, 150, 0.15);
}

/* Landing */
.landing-card {
  text-align: center;
  background: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(8px);
  padding: 50px 40px;
  border-radius: 32px;
  box-shadow: var(--shadow);
  max-width: 420px;
  animation: bob 4s ease-in-out infinite;
}
@keyframes bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}
.landing-emoji {
  font-size: 5rem;
  animation: wiggle 2s ease-in-out infinite;
}
@keyframes wiggle {
  0%, 100% { transform: rotate(-4deg); }
  50% { transform: rotate(4deg); }
}
.title {
  font-size: 2.2rem;
  margin: 10px 0 8px;
  color: var(--pink-deep);
  text-shadow: 2px 2px 0 #fff;
}
.subtitle {
  font-size: 1.05rem;
  color: var(--text-soft);
  margin: 0 0 28px;
}

/* HUD */
.hud {
  position: absolute;
  top: 16px;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 18px;
  z-index: 10;
}
.hud-pill {
  background: rgba(255, 255, 255, 0.8);
  padding: 8px 16px;
  border-radius: 999px;
  box-shadow: 0 4px 10px rgba(160, 110, 150, 0.15);
  font-weight: 700;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.1;
}
.hud-label {
  font-size: 0.7rem;
  color: var(--text-soft);
  letter-spacing: 0.5px;
  text-transform: uppercase;
}
.hud-count {
  font-size: 1.1rem;
  color: var(--pink-deep);
}
#btn-sound .sound-off { display: none; }
#btn-sound.muted .sound-on { display: none; }
#btn-sound.muted .sound-off { display: inline; }

/* Game stage */
.stage {
  position: relative;
  width: min(460px, 90vw);
  height: min(520px, 78vh);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

/* Cake */
.cake {
  position: relative;
  width: 100%;
  height: 100%;
}
.cake-plate {
  position: absolute;
  bottom: 6%;
  left: 50%;
  transform: translateX(-50%);
  width: 74%;
  height: 26px;
  background: radial-gradient(ellipse at 50% 40%, var(--plate), var(--plate-shadow));
  border-radius: 50%;
  box-shadow: 0 10px 18px rgba(120, 90, 130, 0.2);
  z-index: 1;
}
.cake-body {
  position: absolute;
  bottom: 10%;
  left: 50%;
  transform: translateX(-50%);
  width: 62%;
  height: 50%;
  z-index: 2;
  transition: transform 0.8s cubic-bezier(.7,-0.2,.3,1.4), opacity 0.6s ease;
}
.cake-layer {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  box-shadow: inset 0 -10px 14px rgba(0, 0, 0, 0.12),
              inset 14px 0 18px -10px rgba(0, 0, 0, 0.15),
              inset -14px 0 18px -10px rgba(0, 0, 0, 0.15),
              0 6px 14px rgba(180, 120, 150, 0.25);
}
/* Top ellipse (the visible top surface from ~30 degrees) */
.cake-layer::before {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  width: 100%;
  aspect-ratio: 4 / 1;
  transform: translateY(-50%);
  border-radius: 50%;
  background: radial-gradient(ellipse at 50% 35%, #ffffff 0%, var(--top-color, var(--frosting)) 55%, var(--top-shade, var(--frosting-deep)) 100%);
  box-shadow: inset 0 -3px 6px rgba(0, 0, 0, 0.08);
  z-index: 2;
}
/* Bottom ellipse (curves where layer sits on next tier / plate) */
.cake-layer::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  aspect-ratio: 5 / 1;
  transform: translateY(50%);
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.18);
  filter: blur(3px);
  z-index: -1;
}
.layer-bottom {
  bottom: 0;
  width: 100%;
  height: 42%;
  background: var(--cake-1);
  --top-color: var(--frosting);
  --top-shade: #fbd6e3;
}
.layer-middle {
  bottom: 40%;
  width: 84%;
  height: 32%;
  background: var(--cake-2);
  --top-color: var(--frosting-deep);
  --top-shade: #f7b8ce;
}
.layer-top {
  bottom: 70%;
  width: 66%;
  height: 30%;
  background: var(--cake-3);
  --top-color: var(--frosting);
  --top-shade: var(--frosting-deep);
}

/* Frosting drips hanging from front rim of each top ellipse */
.drip {
  position: absolute;
  top: 6%;
  width: 14px;
  height: 18px;
  background: var(--frosting);
  border-radius: 0 0 50% 50%;
  z-index: 3;
}
.layer-bottom .drip:nth-child(1) { left: 6%; height: 20px; }
.layer-bottom .drip:nth-child(2) { left: 20%; height: 28px; top: 10%; }
.layer-bottom .drip:nth-child(3) { left: 34%; height: 22px; top: 12%; }
.layer-bottom .drip:nth-child(4) { left: 48%; height: 30px; top: 14%; }
.layer-bottom .drip:nth-child(5) { left: 62%; height: 24px; top: 12%; }
.layer-bottom .drip:nth-child(6) { left: 76%; height: 26px; top: 10%; }
.layer-bottom .drip:nth-child(7) { left: 90%; height: 18px; }
.layer-top .drip.d2 {
  top: 8%;
  background: var(--frosting);
  width: 12px;
  height: 16px;
}
.layer-top .drip.d2:nth-child(1) { left: 8%; }
.layer-top .drip.d2:nth-child(2) { left: 26%; height: 22px; top: 14%; }
.layer-top .drip.d2:nth-child(3) { left: 46%; height: 24px; top: 16%; }
.layer-top .drip.d2:nth-child(4) { left: 66%; height: 22px; top: 14%; }
.layer-top .drip.d2:nth-child(5) { left: 84%; }

/* Sprinkles */
.sprinkle {
  position: absolute;
  width: 8px;
  height: 3px;
  border-radius: 2px;
  transform: rotate(20deg);
}
.s1 { top: 60%; left: 10%; background: var(--pink-deep); transform: rotate(-25deg); }
.s2 { top: 70%; left: 25%; background: var(--sky); transform: rotate(40deg); }
.s3 { top: 65%; left: 40%; background: var(--lemon); }
.s4 { top: 75%; left: 55%; background: var(--mint); transform: rotate(-10deg); }
.s5 { top: 62%; left: 70%; background: var(--pink); transform: rotate(60deg); }
.s6 { top: 72%; left: 85%; background: var(--sky); transform: rotate(-40deg); }
.s7 { top: 80%; left: 15%; background: var(--lemon); transform: rotate(15deg); }
.s8 { top: 80%; left: 75%; background: var(--mint); transform: rotate(-50deg); }

/* Candle layer: an ellipse matching the top surface of the top cake tier.
   layer-top sits at bottom ~65%..75% of .cake;
   width = cake-body width (62%) * layer-top width (66%) = ~41%. */
.candle-layer {
  position: absolute;
  top: 40%;
  left: 50%;
  width: 41%;
  aspect-ratio: 4 / 1;
  transform: translate(-50%, -50%);
  z-index: 5;
  pointer-events: none;
}

/* Candle */
.candle {
  position: absolute;
  width: 36px;
  height: 104px;
  transform: translate(-50%, -100%) scale(var(--s, 1));
  transform-origin: 50% 100%;
  pointer-events: auto;
  animation: popIn 0.35s cubic-bezier(.5, 1.6, .5, 1);
}
@keyframes popIn {
  from { transform: translate(-50%, -100%) scale(calc(var(--s, 1) * 0.2)); opacity: 0; }
  to   { transform: translate(-50%, -100%) scale(var(--s, 1)); opacity: 1; }
}
.candle.out {
  animation: candleOut 0.35s ease forwards;
  pointer-events: none;
}
@keyframes candleOut {
  to { transform: translate(-50%, -90%) scale(calc(var(--s, 1) * 0.6)); opacity: 0; }
}
.candle-stick {
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 22px;
  height: 72px;
  border-radius: 5px;
  background: repeating-linear-gradient(
    180deg,
    var(--candle-color, var(--candle-1)) 0 12px,
    rgba(255, 255, 255, 0.55) 12px 18px
  );
  box-shadow: inset -4px 0 0 rgba(0, 0, 0, 0.12), 0 3px 5px rgba(120, 80, 110, 0.3);
}
.candle-stick::before {
  content: '';
  position: absolute;
  top: -3px; left: 50%;
  transform: translateX(-50%);
  width: 9px; height: 6px;
  background: #6b4a2e;
  border-radius: 2px;
}
.flame {
  position: absolute;
  bottom: 72px;
  left: 50%;
  transform: translateX(-50%);
  width: 36px;
  height: 48px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.flame::after {
  content: '';
  position: absolute;
  width: 26px;
  height: 38px;
  background: radial-gradient(ellipse at 50% 70%, var(--flame-in) 0%, var(--flame-out) 60%, transparent 80%);
  border-radius: 50% 50% 45% 45% / 60% 60% 40% 40%;
  filter: drop-shadow(0 0 10px rgba(255, 180, 80, 0.8));
  animation: flicker 0.7s ease-in-out infinite alternate;
  transform-origin: 50% 100%;
}
.flame::before {
  content: '';
  position: absolute;
  bottom: 0;
  width: 42px;
  height: 42px;
  background: radial-gradient(circle, rgba(255, 200, 100, 0.4), transparent 70%);
  border-radius: 50%;
  animation: glow 1.2s ease-in-out infinite alternate;
}
@keyframes flicker {
  0%   { transform: translateX(-1px) scaleY(1); }
  100% { transform: translateX(1px) scaleY(1.1); }
}
@keyframes glow {
  from { opacity: 0.6; transform: scale(1); }
  to   { opacity: 1; transform: scale(1.15); }
}
/* puff effect */
.puff {
  position: absolute;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255,255,255,0.9), rgba(255,255,255,0));
  pointer-events: none;
  animation: puff 0.5s ease forwards;
}
@keyframes puff {
  from { transform: translate(-50%, -50%) scale(0.4); opacity: 1; }
  to   { transform: translate(-50%, -120%) scale(2.2); opacity: 0; }
}

/* Cake cut + slice transition */
.knife {
  position: absolute;
  top: -10%;
  left: 50%;
  width: 12px;
  height: 60%;
  transform: translateX(-50%) rotate(0deg);
  opacity: 0;
  z-index: 5;
  pointer-events: none;
}
.knife-blade {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 70%;
  background: linear-gradient(180deg, #f4f6fb, #c9cfdb);
  border-radius: 2px 2px 50% 0;
  box-shadow: 2px 0 4px rgba(0,0,0,0.15);
}
.knife-handle {
  position: absolute;
  top: 70%; left: -3px;
  width: 18px; height: 30%;
  background: linear-gradient(180deg, #8a5a3b, #5c3a23);
  border-radius: 4px;
}

.cake-slice {
  position: absolute;
  bottom: 4%;
  left: 50%;
  transform: translate(-50%, 40px) scale(0.4);
  opacity: 0;
  z-index: 2;
  width: 70%;
  height: 80%;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  transition: opacity 0.6s ease, transform 0.8s cubic-bezier(.4, 1.5, .4, 1);
  filter: drop-shadow(0 10px 14px rgba(180, 120, 150, 0.25));
}
.slice-svg {
  width: 100%;
  height: auto;
  max-height: 100%;
}

/* CUTTING state animation - 2.5s dramatic */
.cake.cutting .knife {
  animation: knifeDrop 7.5s cubic-bezier(.6, .1, .4, 1) forwards;
}
@keyframes knifeDrop {
  0%   { opacity: 0; transform: translateX(-50%) translateY(-40px) rotate(-20deg); }
  20%  { opacity: 1; transform: translateX(-50%) translateY(-20px) rotate(-15deg); }
  45%  { opacity: 1; transform: translateX(-50%) translateY(20px) rotate(-5deg); }
  70%  { opacity: 1; transform: translateX(-50%) translateY(60px) rotate(0deg); }
  100% { opacity: 0; transform: translateX(120%) translateY(40px) rotate(15deg); }
}
.cake.cutting .cake-body {
  animation: cakeSplit 7.5s ease forwards;
}
@keyframes cakeSplit {
  0%   { transform: translateX(-50%) scale(1); opacity: 1; filter: brightness(1); }
  40%  { transform: translateX(-50%) scale(1.02); filter: brightness(1.1); }
  60%  { transform: translateX(-52%) scale(1) rotate(-2deg); opacity: 1; }
  80%  { transform: translateX(-70%) scale(0.85) rotate(-8deg); opacity: 0.6; }
  100% { transform: translateX(-120%) scale(0.5) rotate(-20deg); opacity: 0; }
}
.cake.cutting .cake-slice {
  animation: sliceReveal 7.5s ease forwards;
}
@keyframes sliceReveal {
  0%, 60% { opacity: 0; transform: translate(-50%, 40px) scale(0.4); }
  80%     { opacity: 1; transform: translate(-50%, 0) scale(1.05); }
  100%    { opacity: 1; transform: translate(-50%, 0) scale(1); }
}

/* Celebration */
.celebrate-card {
  text-align: center;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(8px);
  padding: 50px 40px;
  border-radius: 32px;
  box-shadow: var(--shadow);
  max-width: 460px;
  animation: pop 0.6s cubic-bezier(.5, 1.6, .5, 1);
}
@keyframes pop {
  from { transform: scale(0.5); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}
.celebrate-emojis {
  font-size: 4rem;
  animation: bounce 1.6s ease-in-out infinite;
}
@keyframes bounce {
  0%, 100% { transform: translateY(0) rotate(-2deg); }
  50% { transform: translateY(-12px) rotate(2deg); }
}
.celebrate-title {
  font-size: 2.4rem;
  margin: 10px 0 6px;
  color: var(--pink-deep);
  text-shadow: 2px 2px 0 #fff;
  line-height: 1.15;
}
.celebrate-msg {
  font-size: 1.2rem;
  color: var(--text-soft);
  margin: 0 0 28px;
}

@media (max-width: 480px) {
  .title { font-size: 1.7rem; }
  .celebrate-title { font-size: 1.9rem; }
  .landing-card, .celebrate-card { padding: 36px 24px; }
  .btn-primary { font-size: 1.15rem; padding: 14px 32px; }
  .candle { width: 30px; height: 88px; }
  .candle-stick { width: 18px; height: 60px; }
  .flame { bottom: 60px; width: 30px; height: 40px; }
  .flame::after { width: 22px; height: 32px; }
  .flame::before { width: 34px; height: 34px; }
}
