/* ============================================
   Template bday: Birthday card
   3 pages horizontal, page-turn feel, cake + candles
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=Fredoka:wght@400;500;600;700&family=Pacifico&display=swap');

body {
  --bday-font: 'Fredoka', sans-serif;
  --bday-font-title: 'Pacifico', cursive;
  --bday-dark: #060b14;
  --bday-mid: #0c1424;
  --bday-accent: #ff9f43;
  --bday-gold: #ffd93d;
  --bday-candle: #f8b500;
  --bday-title-color: #f5e6c8;
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: var(--bday-font);
  color: #fff;
  -webkit-tap-highlight-color: transparent;
}

/* ---- Background: darker blue gradient ---- */
.bday-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}

.bday-bg-gradient {
  position: absolute;
  inset: 0;
  background: linear-gradient(165deg, #050a12 0%, #0a1220 25%, #0c1628 50%, #080e18 80%, #03070c 100%);
}

/* Birthday decorations in background - more items */
.bday-bg-deco {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.bday-float-item {
  position: absolute;
  font-size: clamp(1.4rem, 3.5vw, 2.2rem);
  opacity: 0.28;
  will-change: transform;
  /* initial positions set by JS; fallback for nth-child */
}

.bday-float-item:nth-child(1)  { left: 5%;   top: 12%; }
.bday-float-item:nth-child(2)  { left: 88%;  top: 18%; }
.bday-float-item:nth-child(3)  { left: 15%;  top: 75%; }
.bday-float-item:nth-child(4)  { left: 82%;  top: 68%; }
.bday-float-item:nth-child(5)  { left: 48%;  top: 8%;  }
.bday-float-item:nth-child(6)  { left: 72%;  top: 8%;  }
.bday-float-item:nth-child(7)  { left: 25%;  top: 85%; }
.bday-float-item:nth-child(8)  { left: 92%;  top: 42%; }
.bday-float-item:nth-child(9)  { left: 8%;   top: 42%; }
.bday-float-item:nth-child(10) { left: 94%;  top: 55%; }
.bday-float-item:nth-child(11) { left: 55%; top: 78%; }
.bday-float-item:nth-child(12) { left: 18%; top: 28%; }
.bday-float-item:nth-child(13) { left: 78%; top: 82%; }
.bday-float-item:nth-child(14) { left: 35%; top: 5%;  }
.bday-float-item:nth-child(15) { left: 65%; top: 72%; }
.bday-float-item:nth-child(16) { left: 42%; top: 92%; }
.bday-float-item:nth-child(17) { left: 22%; top: 55%; }

/* Dark overlay when cake scene is active – darker at edges, lighter in center (cake focused) */
.bday-overlay {
  position: fixed;
  inset: 0;
  z-index: 2;
  background: transparent;
  pointer-events: none;
  transition: opacity 0.8s ease;
}

.bday-overlay.bday-overlay-active {
  background: radial-gradient(
    ellipse 80% 70% at 50% 45%,
    rgba(0, 0, 0, 0.25) 0%,
    rgba(0, 0, 0, 0.5) 45%,
    rgba(0, 0, 0, 0.75) 100%
  );
  pointer-events: auto;
}

/* Small radial glow that follows the cursor */
.bday-cursor-glow {
  position: fixed;
  width: 100px;
  height: 100px;
  left: 0;
  top: 0;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(
    circle,
    rgba(74, 144, 217, 0.4) 0%,
    rgba(74, 144, 217, 0.18) 35%,
    rgba(74, 144, 217, 0.06) 60%,
    transparent 75%
  );
  pointer-events: none;
  z-index: 2;
  transition: opacity 0.2s ease;
}

.bday-cursor-glow.bday-cursor-glow-hidden {
  opacity: 0;
}

/* ---- Horizontal slider with page-turn feel ---- */
.bday-slider {
  position: relative;
  z-index: 1;
  width: 500vw;
  min-width: 500vw;
  height: 100vh;
  height: 100dvh;
  max-height: 100vh;
  max-height: 100dvh;
  overflow: visible;
  display: flex;
  transition: transform 0.7s cubic-bezier(0.33, 0.1, 0.2, 1);
  will-change: transform;
}

/* When cake is visible, slider must be above overlay so candle taps work */
.bday-slider.bday-cake-active,
.bday-slider:has(.bday-cake-visible) {
  z-index: 3;
}

.bday-slider.bday-slide-1 { transform: translateX(0); }
.bday-slider.bday-slide-2 { transform: translateX(-100vw); }
.bday-slider.bday-slide-3 { transform: translateX(-200vw); }
.bday-slider.bday-slide-4 { transform: translateX(-300vw); }
.bday-slider.bday-slide-5 { transform: translateX(-400vw); }

.bday-page {
  position: relative;
  flex: 0 0 100vw;
  width: 100vw;
  height: 100%;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  overflow: hidden;
}

.bday-page-inner {
  max-width: 90vw;
  width: 100%;
  margin: auto;
  text-align: center;
}

/* ---- Page 1: Cover (hidden when cake scene is visible) ---- */
.bday-cover {
  position: relative;
  z-index: 1;
  width: 100%;
  text-align: center;
  transition: opacity 0.5s ease, visibility 0.5s ease;
}

.bday-page-1.bday-cake-visible .bday-cover {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.bday-cake-scene {
  position: absolute;
  inset: 0;
  z-index: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.5s ease, visibility 0.5s ease, pointer-events 0s 0.5s;
}

.bday-page-1.bday-cake-visible .bday-cake-scene {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  z-index: 2;
}

/* GIF above title - try both path variants so it works with or without space in folder name */
.bday-cover-gif {
  margin-bottom: 1rem;
  min-height: 120px;
}

.bday-title-gif {
  display: block;
  margin: 0 auto;
  max-width: 200px;
  width: 100%;
  height: auto;
  min-height: 100px;
  border-radius: 12px;
  object-fit: contain;
  opacity: 0;
  animation: bday-gif-fade-in 0.9s ease-out 0.1s forwards;
}

@keyframes bday-gif-fade-in {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

.bday-title {
  font-family: var(--bday-font-title);
  font-size: clamp(2rem, 8vw, 3.5rem);
  font-weight: 400;
  color: var(--bday-title-color);
  text-shadow: 0 0 30px rgba(245, 230, 200, 0.35), 0 2px 8px rgba(0, 0, 0, 0.3);
  margin-bottom: 2rem;
  letter-spacing: 0.02em;
  opacity: 0;
  transform: translateX(80px);
  animation: bday-title-in 1.3s cubic-bezier(0.34, 1.4, 0.64, 1) 0.25s forwards,
             bday-title-sway 2.8s ease-in-out 1.4s infinite;
}

/* Title: fade + bounce in from right to left, then always swaying to both sides */
@keyframes bday-title-in {
  0% {
    opacity: 0;
    transform: translateX(80px);
  }
  70% {
    opacity: 1;
    transform: translateX(-8px);
  }
  85% {
    transform: translateX(4px);
  }
  100% {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes bday-title-sway {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-10px); }
  50% { transform: translateX(10px); }
  75% { transform: translateX(-6px); }
}

.bday-btn-begin {
  font-family: var(--bday-font);
  font-size: clamp(1rem, 3vw, 1.2rem);
  font-weight: 600;
  padding: 0.65rem 1.5rem;
  border: none;
  border-radius: 999px;
  background: linear-gradient(135deg, #e9c46a 0%, #d4a72a 50%, #b8860b 100%);
  color: #1a1a2e;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(212, 167, 42, 0.35), 0 0 0 1px rgba(255, 255, 255, 0.15) inset;
  opacity: 0;
  transform: translateY(20px);
  animation: bday-btn-in 0.8s ease-out 0.8s forwards;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}

.bday-btn-begin:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 24px rgba(212, 167, 42, 0.45), 0 0 0 1px rgba(255, 255, 255, 0.2) inset;
}

.bday-btn-begin:active {
  transform: scale(0.98);
}

@keyframes bday-btn-in {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ---- Nav: arrows on sides, vertically centered ---- */
.bday-nav {
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  z-index: 10;
  pointer-events: none;
}

.bday-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 64px;
  height: 64px;
  padding: 0;
  border: none;
  border-radius: 16px;
  background: transparent;
  color: rgba(255, 255, 255, 0.9);
  font-size: 3rem;
  line-height: 1;
  cursor: pointer;
  pointer-events: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s ease, transform 0.2s ease, opacity 0.25s ease, visibility 0.25s ease;
  -webkit-tap-highlight-color: transparent;
}

.bday-arrow:hover {
  color: #fff;
  transform: translateY(-50%) scale(1.1);
}

.bday-arrow-left {
  left: 1rem;
}

.bday-arrow-right {
  right: 1rem;
}

.bday-nav.bday-on-page-1 .bday-arrow-left {
  visibility: hidden;
  pointer-events: none;
  opacity: 0;
}

.bday-nav.bday-on-page-3 .bday-arrow-right,
.bday-nav.bday-on-page-4 .bday-arrow-right {
  visibility: hidden;
  pointer-events: none;
  opacity: 0;
}

/* ---- Mute button: top right (only visible after OK on volume popup) ---- */
.bday-mute-btn {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 15;
  width: 48px;
  height: 48px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
  font-size: 1.5rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease, transform 0.2s ease, opacity 0.25s ease, visibility 0.25s ease;
  -webkit-tap-highlight-color: transparent;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
  visibility: hidden;
  pointer-events: none;
  opacity: 0;
}

.bday-mute-btn.bday-mute-visible {
  visibility: visible;
  pointer-events: auto;
  opacity: 1;
}

.bday-mute-btn:hover {
  background: rgba(255, 255, 255, 0.35);
  transform: scale(1.08);
}

.bday-mute-btn .bday-mute-off {
  display: none;
}

.bday-mute-btn.bday-muted .bday-mute-on {
  display: none;
}

.bday-mute-btn.bday-muted .bday-mute-off {
  display: inline;
}

/* ---- Popper / confetti falling from above ---- */
.bday-popper-container {
  position: fixed;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.4s ease, visibility 0.4s ease;
}

.bday-popper-container.bday-popper-active {
  opacity: 1;
  visibility: visible;
}

.bday-popper-piece {
  position: absolute;
  top: -30px;
  left: 0;
  border-radius: 2px;
  --twist: 0deg;
  animation: bday-popper-fall linear forwards;
  transform-origin: center center;
}

@keyframes bday-popper-fall {
  0% {
    transform: translateY(0) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: translateY(100vh) rotate(var(--twist));
    opacity: 0.6;
  }
}

/* ---- Volume modal ---- */
.bday-modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  background: rgba(0, 0, 0, 0.6);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.bday-modal.bday-modal-open {
  opacity: 1;
  visibility: visible;
}

.bday-modal-inner {
  background: linear-gradient(180deg, #1e3250 0%, #162840 100%);
  border-radius: 20px;
  padding: 2rem;
  max-width: 320px;
  width: 100%;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.1);
  animation: bday-modal-pop 0.35s ease-out;
}

@keyframes bday-modal-pop {
  from {
    transform: scale(0.9);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

.bday-modal-text {
  font-family: var(--bday-font);
  font-size: 1.2rem;
  color: #fff;
  margin-bottom: 1.5rem;
  line-height: 1.5;
}

.bday-modal-ok {
  font-family: var(--bday-font);
  font-size: 1rem;
  font-weight: 600;
  padding: 0.65rem 1.5rem;
  border: none;
  border-radius: 999px;
  background: linear-gradient(135deg, #e9c46a 0%, #d4a72a 50%, #b8860b 100%);
  color: #1a1a2e;
  cursor: pointer;
  transition: transform 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}

.bday-modal-ok:hover {
  transform: scale(1.05);
}

.bday-cake-scene .bday-cake-wrap {
  position: relative;
  width: 200px;
  height: 200px;
  margin: 0 auto 1.5rem;
  perspective: 520px;
}

/* Single transform wrapper: enters then flips in place to show side */
.bday-cake-transform {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 200px;
  height: 200px;
  margin-left: -100px;
  margin-top: -100px;
  transform-style: preserve-3d;
  transform: translateY(-120px) scale(0.5);
  transition: transform 0.7s cubic-bezier(0.34, 1.2, 0.64, 1);
}

.bday-cake-transform.bday-cake-visible {
  transform: translateY(0) scale(1);
}

.bday-cake-transform.bday-cake-flipped {
  transform: translateY(0) scale(1) rotateY(180deg);
  transition-duration: 0.9s;
}

.bday-cake-face {
  position: absolute;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}

/* Top-down view (front face) – round cake with HBD + name on two lines */
.bday-cake-top {
  left: 50%;
  top: 50%;
  width: 140px;
  height: 140px;
  margin-left: -70px;
  margin-top: -70px;
  border-radius: 50%;
  background: linear-gradient(180deg, #ff9f43 0%, #e67e22 50%, #d35400 100%);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4), inset 0 2px 0 rgba(255,255,255,0.3);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
}

.bday-cake-hbd-line1,
.bday-cake-hbd-line2 {
  font-family: var(--bday-font-title);
  font-size: 1.5rem;
  font-weight: 400;
  color: #fff;
  text-shadow: 0 2px 6px rgba(0,0,0,0.35);
  line-height: 1.2;
  display: block;
}

.bday-cake-hbd-line2 {
  font-size: 1.25rem;
}

/* Side view (back face) – cake with candles + HBD text */
.bday-cake-side {
  left: 50%;
  top: 50%;
  width: 160px;
  height: 100px;
  margin-left: -80px;
  margin-top: -50px;
  transform: rotateY(180deg);
  pointer-events: auto;
}

.bday-side-hbd {
  position: absolute;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  font-family: 'Caveat', cursive;
  font-size: 1.85rem;
  font-weight: 600;
  color: #fff;
  text-shadow: 0 2px 6px rgba(0,0,0,0.4);
  z-index: 2;
}

.bday-cake-side .bday-cake-base {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 70px;
  background: linear-gradient(180deg, #e67e22 0%, #c0392b 100%);
  border-radius: 0 0 12px 12px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35), inset 0 2px 0 rgba(255,255,255,0.15);
}

/* Candles */
.bday-candles {
  position: absolute;
  left: 50%;
  bottom: 68px;
  transform: translateX(-50%);
  display: flex;
  gap: 18px;
  justify-content: center;
  align-items: flex-end;
}

.bday-candle {
  width: 12px;
  height: 28px;
  background: linear-gradient(90deg, #f8b500 0%, #e6a200 100%);
  border-radius: 2px;
  position: relative;
  box-shadow: 0 2px 6px rgba(0,0,0,0.25);
  transition: opacity 0.4s ease, transform 0.3s ease;
}

.bday-candle.bday-candle-blown {
  opacity: 0.4;
}

.bday-candle.bday-candle-blown .bday-flame {
  opacity: 0;
  transform: scale(0);
}

.bday-candle {
  cursor: pointer;
}

.bday-flame {
  position: absolute;
  left: 50%;
  top: -10px;
  width: 14px;
  height: 18px;
  margin-left: -7px;
  background: radial-gradient(ellipse 50% 100% at 50% 0%, #ffd93d 0%, #ff9f43 40%, #e67e22 100%);
  border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
  box-shadow: 0 0 12px rgba(255, 159, 67, 0.8);
  animation: bday-flicker 0.15s ease-in-out infinite alternate;
  transition: opacity 0.35s ease, transform 0.35s ease;
}

@keyframes bday-flicker {
  from { transform: scaleX(1) scaleY(1); }
  to { transform: scaleX(1.05) scaleY(0.95); }
}

/* Fire-out effect when candle is blown (positioned at flame) */
.bday-flame-out {
  position: absolute;
  left: 50%;
  top: -10px;
  width: 24px;
  height: 24px;
  margin-left: -12px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(200, 200, 200, 0.8) 0%, rgba(140, 140, 140, 0.4) 40%, transparent 70%);
  animation: bday-flame-out 0.6s ease-out forwards;
  pointer-events: none;
}

@keyframes bday-flame-out {
  0% {
    transform: scale(0.3);
    opacity: 1;
  }
  50% {
    opacity: 0.8;
  }
  100% {
    transform: scale(1.8) translateY(-8px);
    opacity: 0;
  }
}

.bday-cake-scene .bday-tap-hint {
  font-family: var(--bday-font);
  font-size: clamp(1rem, 2.8vw, 1.2rem);
  font-weight: 600;
  color: #ffd93d;
  text-shadow: 0 0 12px rgba(255, 217, 61, 0.6), 0 2px 8px rgba(0, 0, 0, 0.5);
  margin: 1rem 0 0;
  opacity: 0;
  animation: bday-fade-in 0.6s ease-out 1.8s forwards;
}

@keyframes bday-fade-in {
  to { opacity: 1; }
}

/* Cake hidden when pieces fly away */
.bday-cake-wrap.bday-cake-hidden {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.bday-cake-scene.bday-candles-done .bday-tap-hint {
  opacity: 0;
  visibility: hidden;
}

/* 8 cake pieces: start as circle, fly to edges and disappear */
.bday-cake-pieces {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 140px;
  height: 140px;
  margin-left: -70px;
  margin-top: -70px;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease;
}

.bday-cake-pieces.bday-cake-pieces-visible {
  opacity: 1;
  visibility: visible;
  z-index: 4;
}

.bday-cake-piece {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(180deg, #ff9f43 0%, #e67e22 50%, #d35400 100%);
  border-radius: 50%;
  transform: translate(0, 0);
  transition: transform 1s cubic-bezier(0.25, 0.46, 0.45, 0.94), opacity 1s ease;
}

.bday-cake-pieces-fly .bday-cake-piece {
  transform: translate(var(--fly-x, 0), var(--fly-y, 0)) scale(0.6);
  opacity: 0;
}

/* Final message (typewriter) – center of screen */
.bday-final-message {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  z-index: 5;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.5s ease, visibility 0.5s ease;
}

.bday-final-message.bday-final-message-visible {
  opacity: 1;
  visibility: visible;
}

.bday-final-text {
  font-family: var(--bday-font), 'Nunito', sans-serif;
  font-size: clamp(1.35rem, 4.2vw, 1.85rem);
  font-weight: 600;
  color: #e8d5c4;
  text-shadow: 0 2px 14px rgba(0, 0, 0, 0.45);
  text-align: center;
  line-height: 1.65;
  max-width: 90%;
  margin: 0;
  letter-spacing: 0.01em;
}

.bday-final-joe {
  color: #ffd93d;
  font-weight: 600;
  font-size: 1.08em;
  text-shadow: 0 0 18px rgba(255, 217, 61, 0.6), 0 2px 8px rgba(0, 0, 0, 0.35);
}

.bday-final-cursor {
  animation: bday-cursor-blink 0.8s step-end infinite;
  margin-left: 2px;
}

.bday-final-message-visible.bday-typewriter-done .bday-final-cursor {
  display: none;
}

@keyframes bday-cursor-blink {
  50% { opacity: 0; }
}

/* ---- Page 2: Calendar + balloons + scattered photos ---- */
.bday-page-2 {
  position: relative;
  overflow: hidden;
}

/* Large age number background */
.bday-p2-age-bg {
  position: absolute;
  top: 50%;
  left: 18%;
  transform: translateY(-50%);
  font-family: var(--bday-font);
  font-size: clamp(14rem, 40vw, 24rem);
  font-weight: 700;
  color: rgba(255, 255, 255, 0.1);
  line-height: 1;
  z-index: 0;
  pointer-events: none;
  -webkit-user-select: none;
  user-select: none;
  white-space: nowrap;
}

body[data-bday-hide-age="true"] .bday-p2-age-bg {
  display: none;
}

/* Top bar (navbar) balloons hang from */
.bday-p2-balloons-wrap {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  z-index: 2;
}

.bday-p2-balloons-bar {
  height: 6px;
  background: linear-gradient(180deg, rgba(230, 126, 34, 0.5) 0%, rgba(192, 57, 43, 0.35) 100%);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

/* Balloons: from top-left to top-right, inverted (knot up), string + balloon swing together */
.bday-p2-balloons {
  position: absolute;
  left: 0;
  right: 0;
  top: 6px;
  height: 72px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding-left: 1.5rem;
  padding-right: 1.5rem;
  gap: 1.5rem;
}

.bday-p2-balloon-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  transform-origin: top center;
  animation: bday-p2-balloon-swing 3s ease-in-out infinite;
}

.bday-p2-balloon-item:nth-child(1)  { animation-delay: 0s; }
.bday-p2-balloon-item:nth-child(2)  { animation-delay: 0.15s; }
.bday-p2-balloon-item:nth-child(3)  { animation-delay: 0.3s; }
.bday-p2-balloon-item:nth-child(4)  { animation-delay: 0.05s; }
.bday-p2-balloon-item:nth-child(5)  { animation-delay: 0.2s; }
.bday-p2-balloon-item:nth-child(6)  { animation-delay: 0.35s; }
.bday-p2-balloon-item:nth-child(7)  { animation-delay: 0.1s; }
.bday-p2-balloon-item:nth-child(8)  { animation-delay: 0.25s; }
.bday-p2-balloon-item:nth-child(9)  { animation-delay: 0.4s; }
.bday-p2-balloon-item:nth-child(10) { animation-delay: 0.08s; }
.bday-p2-balloon-item:nth-child(11) { animation-delay: 0.22s; }
.bday-p2-balloon-item:nth-child(12) { animation-delay: 0.38s; }
.bday-p2-balloon-item:nth-child(13) { animation-delay: 0.12s; }
.bday-p2-balloon-item:nth-child(14) { animation-delay: 0.28s; }
.bday-p2-balloon-item:nth-child(15) { animation-delay: 0.18s; }

@keyframes bday-p2-balloon-swing {
  0%, 100% { transform: rotate(-5deg); }
  50% { transform: rotate(5deg); }
}

/* Rope/string – moves with balloon */
.bday-p2-balloon-string {
  display: block;
  width: 2px;
  height: 28px;
  background: linear-gradient(180deg, rgba(120, 100, 80, 0.9) 0%, rgba(80, 65, 50, 0.85) 100%);
  border-radius: 1px;
}

/* Balloon: inverted so knot (oxidized part) is at top, round part hangs down */
.bday-p2-balloon {
  display: block;
  font-size: clamp(1.6rem, 4.5vw, 2.2rem);
  line-height: 1;
  transform: rotate(180deg);
  margin-top: -2px;
}

/* Cartoon calendar wrapper */
.bday-p2-calendar-wrap {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 3;
}

/* Cartoon calendar – 28 Feb */
.bday-p2-calendar {
  position: relative;
  width: 120px;
  padding: 1rem 1.25rem;
  margin: 0 auto;
  background: linear-gradient(180deg, #fff8f0 0%, #ffe8d8 50%, #ffd4b8 100%);
  border: 4px solid #e67e22;
  border-radius: 16px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25), inset 0 2px 0 rgba(255,255,255,0.6);
  text-align: center;
  z-index: 2;
}

/* Day: scrolling strip window (one number visible) */
.bday-p2-day-wrap {
  overflow: hidden;
  height: 2.75rem;
  line-height: 2.75rem;
}

.bday-p2-day-strip {
  font-family: var(--bday-font);
  font-size: 2.5rem;
  font-weight: 700;
  color: #c0392b;
  transition: transform 0.12s linear;
}

.bday-p2-day-cell {
  height: 2.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
}

.bday-p2-month {
  display: block;
  font-family: var(--bday-font);
  font-size: 1.35rem;
  font-weight: 600;
  color: #e67e22;
  letter-spacing: 0.05em;
  opacity: 0;
  transition: opacity 0.5s ease;
}

.bday-p2-month-visible {
  opacity: 1;
}

/* Quote wrapper - pinned to calendar, behind it */
.bday-p2-quote-wrap {
  position: relative;
  margin-top: -1.2rem;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.bday-p2-quote-pin {
  position: absolute;
  bottom: 0.2rem;
  left: 50%;
  transform: translateX(-50%);
  font-size: 1.1rem;
  line-height: 1;
  z-index: 3;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
  opacity: 0;
  transform: translateX(-50%) translateY(-10px) scale(0.8);
  transition: opacity 0.6s ease, transform 0.6s ease;
}

.bday-p2-calendar-pinned .bday-p2-quote-pin {
  opacity: 1;
  transform: translateX(-50%) translateY(0) scale(1);
}

/* Quote paper - torn paper style, behind calendar */
.bday-p2-quote {
  position: relative;
  padding: 0.65rem 1rem;
  padding-top: 1.5rem;
  padding-bottom: 0.85rem;
  background: linear-gradient(145deg, #faf6ef 0%, #ebe3d5 50%, #e5dcc8 100%);
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.15);
  clip-path: polygon(
    0 2%, 25% 0%, 50% 3%, 75% 0%, 100% 2%,
    98% 25%, 100% 50%, 97% 75%, 100% 100%,
    75% 98%, 50% 100%, 25% 97%, 0 100%,
    2% 75%, 0 50%, 3% 25%, 0 0
  );
  font-family: var(--bday-font);
  /* Fluid size so ~53ch quote stays on one line before page clips (see .bday-page-2 overflow) */
  font-size: clamp(0.58rem, 0.25rem + 2.85vw, 0.95rem);
  font-weight: 500;
  color: #5d4e37;
  text-align: center;
  white-space: nowrap;
  opacity: 0;
  transform: translateY(-10px) rotate(-1deg);
  transition: opacity 0.6s ease, transform 0.6s ease;
  max-width: min(94vw, calc(100vw - 24px));
}

.bday-p2-quote-visible {
  opacity: 1;
  transform: translateY(0) rotate(-1deg);
}

@media (max-width: 600px) {
  .bday-p2-quote-wrap {
    margin-top: -1.3rem;
  }

  .bday-p2-quote {
    /* Fits default quote on one line: ~52 chars × ~0.5em avg ≈ divisor 39 on usable width */
    font-size: clamp(10px, calc((100vw - 28px) / 42), 0.85rem);
    padding: 0.75rem 0.35rem;
    padding-top: 1.65rem;
    padding-bottom: 0.95rem;
    max-width: calc(100vw - 16px);
    min-height: 3.25rem;
  }
}

/* Scattered photos – torn edges on image only, no paper border */
.bday-p2-photos {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.bday-p2-frame {
  position: absolute;
  pointer-events: auto;
  opacity: 0;
  transition: opacity 0.9s ease;
  /* Fixed frame size so layout is identical regardless of image dimensions */
  width: 268px;
  height: 215px;
  overflow: hidden;
}

.bday-p2-photos-visible .bday-p2-frame-1 { opacity: 1; transition-delay: 0s; }
.bday-p2-photos-visible .bday-p2-frame-2 { opacity: 1; transition-delay: 0.45s; }
.bday-p2-photos-visible .bday-p2-frame-3 { opacity: 1; transition-delay: 0.9s; }
.bday-p2-photos-visible .bday-p2-frame-4 { opacity: 1; transition-delay: 1.35s; }
.bday-p2-photos-visible .bday-p2-frame-5 { opacity: 1; transition-delay: 1.8s; }
.bday-p2-photos-visible .bday-p2-frame-6 { opacity: 1; transition-delay: 2.25s; }

.bday-p2-frame img,
.bday-p2-frame video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  /* Torn edge on the image only – no border */
  clip-path: polygon(
    0 2%, 25% 0%, 50% 3%, 75% 0%, 100% 2%,
    98% 25%, 100% 50%, 97% 75%, 100% 100%,
    75% 98%, 50% 100%, 25% 97%, 0 100%,
    2% 75%, 0 50%, 3% 25%, 0 0
  );
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  animation: bday-p2-img-float 4s ease-in-out infinite;
}

.bday-p2-frame-1 img, .bday-p2-frame-1 video { animation-delay: 0s; }
.bday-p2-frame-2 img, .bday-p2-frame-2 video { animation-delay: 0.3s; }
.bday-p2-frame-3 img, .bday-p2-frame-3 video { animation-delay: 0.6s; }
.bday-p2-frame-4 img, .bday-p2-frame-4 video { animation-delay: 0.2s; }
.bday-p2-frame-5 img, .bday-p2-frame-5 video { animation-delay: 0.5s; }
.bday-p2-frame-6 img, .bday-p2-frame-6 video { animation-delay: 0.4s; }

@keyframes bday-p2-img-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

.bday-p2-frame-1 { left: 5%;   top: 20%;  transform: rotate(-6deg); }
.bday-p2-frame-2 { right: 6%;  top: 16%;  transform: rotate(5deg); }
.bday-p2-frame-3 { left: 3%;   bottom: 22%; transform: rotate(4deg); }
.bday-p2-frame-4 { right: 5%;  bottom: 18%; transform: rotate(-5deg); }
.bday-p2-frame-5 { left: 50%;  top: 64%;  transform: translateX(-50%) rotate(-2deg); }
.bday-p2-frame-6 { left: 50%;  top: 14%;  transform: translateX(-50%) rotate(3deg); }

@media (max-width: 600px) {
  .bday-p2-age-bg {
    left: 50%;
    top: 36%;
    transform: translate(-50%, -50%);
  }
  .bday-p2-frame { width: 155px; height: 120px; }
  .bday-p2-frame-1 { left: 2%; top: 18%; }
  .bday-p2-frame-2 { right: 2%; top: 16%; }
  .bday-p2-frame-3 { left: 2%; bottom: 18%; }
  .bday-p2-frame-4 { right: 2%; bottom: 16%; }
  .bday-p2-frame-5 { left: 50%; top: 62%; transform: translateX(-50%) rotate(-2deg); }
  .bday-p2-frame-6 { left: 50%; top: 12%; transform: translateX(-50%) rotate(3deg); }
}

/* Popper trigger buttons - bottom corners */
.bday-p2-popper-btn {
  position: absolute;
  bottom: 1.5rem;
  width: 3.5rem;
  height: 3.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.2rem;
  border: none;
  background: transparent;
  cursor: pointer;
  pointer-events: auto;
  opacity: 0.9;
  transition: transform 0.2s ease, opacity 0.2s ease;
  z-index: 4;
  -webkit-tap-highlight-color: transparent;
}

.bday-p2-popper-btn:hover,
.bday-p2-popper-btn:focus {
  opacity: 1;
}

.bday-p2-popper-left:hover,
.bday-p2-popper-left:focus {
  transform: scale(1.15);
}

.bday-p2-popper-left:active {
  transform: scale(0.95);
}

.bday-p2-popper-right:hover,
.bday-p2-popper-right:focus {
  transform: scaleX(-1) scale(1.15);
}

.bday-p2-popper-right:active {
  transform: scaleX(-1) scale(0.95);
}

.bday-p2-popper-left {
  left: 1.5rem;
}

.bday-p2-popper-right {
  right: 1.5rem;
  transform: scaleX(-1);
}

@media (max-width: 600px) {
  .bday-p2-popper-btn {
    width: 3rem;
    height: 3rem;
    font-size: 1.9rem;
    bottom: 1rem;
  }
  .bday-p2-popper-left { left: 1rem; }
  .bday-p2-popper-right { right: 1rem; }
}

/* Popper container for page 2 */
.bday-p2-popper-container {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  overflow: hidden;
}

.bday-p2-popper-piece {
  position: absolute;
  border-radius: 2px;
  --twist: 0deg;
  animation: bday-p2-popper-blast linear forwards;
  transform-origin: center center;
}

@keyframes bday-p2-popper-blast {
  0% {
    transform: translate(0, 0) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: translate(var(--end-x), var(--end-y)) rotate(var(--twist));
    opacity: 0;
  }
}

/* ---- Page 3: Gift box with CD player and letter ---- */
.bday-page-3 {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.bday-p3-title {
  font-family: var(--bday-font);
  font-size: clamp(1.5rem, 5vw, 2.2rem);
  font-weight: 600;
  color: var(--bday-gold);
  margin-bottom: 2rem;
  text-align: center;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

/* Gift box - only lid bounces (pressure cooker style) */
.bday-p3-gift-box {
  position: relative;
  width: 200px;
  height: 200px;
  cursor: pointer;
  margin-top: -1rem;
  z-index: 1;
}

.bday-p3-box-base {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 120px;
  background-image: 
    repeating-linear-gradient(90deg, transparent, transparent 20px, rgba(255, 255, 255, 0.1) 20px, rgba(255, 255, 255, 0.1) 22px),
    repeating-linear-gradient(0deg, transparent, transparent 15px, rgba(0, 0, 0, 0.05) 15px, rgba(0, 0, 0, 0.05) 16px),
    linear-gradient(180deg, #e74c3c 0%, #c0392b 50%, #a93226 100%);
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4), inset 0 2px 0 rgba(255, 255, 255, 0.2);
  border: 2px solid rgba(0, 0, 0, 0.1);
  z-index: 1;
}

.bday-p3-box-base::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 50%;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.25) 0%, transparent 100%);
  border-radius: 10px 10px 0 0;
}

.bday-p3-box-base::after {
  content: '🎀';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 3rem;
  filter: drop-shadow(0 3px 6px rgba(0, 0, 0, 0.4));
}

.bday-p3-box-lid {
  position: absolute;
  bottom: 120px;
  left: 0;
  right: 0;
  height: 50px;
  background: linear-gradient(180deg, #ff6b6b 0%, #e74c3c 50%, #c0392b 100%);
  border-radius: 10px 10px 0 0;
  box-shadow: 0 -6px 20px rgba(0, 0, 0, 0.3), inset 0 2px 0 rgba(255, 255, 255, 0.3);
  border: 2px solid rgba(0, 0, 0, 0.1);
  border-bottom: none;
  transform-origin: bottom center;
  z-index: 2;
  animation: bday-p3-lid-bounce 1.2s ease-in-out infinite;
  opacity: 1;
  visibility: visible;
}

.bday-p3-box-lid::before {
  content: '🎀';
  position: absolute;
  top: -15px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 2.2rem;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
  z-index: 3;
}

.bday-p3-box-lid::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 50%;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.25) 0%, transparent 100%);
  border-radius: 10px 10px 0 0;
}

/* Gift wrap decorations */
.bday-p3-box-lid {
  background-image: 
    repeating-linear-gradient(90deg, transparent, transparent 20px, rgba(255, 255, 255, 0.1) 20px, rgba(255, 255, 255, 0.1) 22px),
    repeating-linear-gradient(0deg, transparent, transparent 15px, rgba(0, 0, 0, 0.05) 15px, rgba(0, 0, 0, 0.05) 16px),
    linear-gradient(180deg, #ff6b6b 0%, #e74c3c 50%, #c0392b 100%);
}

@keyframes bday-p3-lid-bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(12px); }
}

.bday-p3-gift-box.bday-p3-box-open .bday-p3-box-lid {
  animation: bday-p3-lid-open 1.2s cubic-bezier(0.68, -0.55, 0.265, 1.55) forwards;
}

@keyframes bday-p3-lid-open {
  0% {
    transform: translateY(0);
    bottom: 120px;
    opacity: 1;
  }
  100% {
    transform: translateY(0) rotateX(90deg);
    bottom: 0;
    opacity: 1;
  }
}

/* Gifts pop out to opposite sides */
.bday-p3-gifts {
  position: absolute;
  top: 46%;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 900px;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 0 4rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease 0.5s;
  z-index: 2;
}

.bday-p3-gifts.bday-p3-gifts-visible {
  opacity: 1;
  pointer-events: auto;
}

.bday-p3-cd-player {
  position: relative;
  width: 160px;
  height: 160px;
  cursor: pointer;
  transform: translateX(-200px) scale(0) rotate(-180deg);
  animation: bday-p3-cd-pop-left 0.8s cubic-bezier(0.68, -0.55, 0.265, 1.55) 0.6s forwards;
  transition: transform 0.2s ease;
}

.bday-p3-gifts.bday-p3-gifts-visible .bday-p3-cd-player:not(.bday-p3-cd-playing):hover {
  transform: translateX(0) scale(1.1) rotate(0deg);
}

.bday-p3-cd-disc {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: linear-gradient(145deg, #2c3e50 0%, #34495e 50%, #1a252f 100%);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5), inset 0 2px 4px rgba(255, 255, 255, 0.1);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 3px solid rgba(0, 0, 0, 0.3);
}

.bday-p3-cd-text-curve {
  position: absolute;
  width: 130%;
  height: 130%;
  top: -10%;
  left: -15%;
  z-index: 1;
  pointer-events: none;
}

.bday-p3-cd-text {
  font-family: 'Caveat', cursive;
  font-size: 22px;
  fill: rgba(255, 255, 255, 0.75);
  font-weight: 500;
  text-transform: lowercase;
  letter-spacing: 0.05em;
}

.bday-p3-cd-center {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: linear-gradient(145deg, #1a252f 0%, #0f1419 100%);
  border: 3px solid rgba(255, 255, 255, 0.1);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.5);
  z-index: 2;
}

.bday-p3-cd-waves {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.bday-p3-cd-player.bday-p3-cd-playing .bday-p3-cd-waves {
  opacity: 1;
}

.bday-p3-cd-player.bday-p3-cd-playing .bday-p3-cd-disc {
  animation: bday-p3-cd-spin 3s linear infinite;
}

.bday-p3-wave {
  position: absolute;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.bday-p3-wave:nth-child(1) {
  width: 80px;
  height: 80px;
  animation: bday-p3-wave-pulse 1.5s ease-in-out infinite;
}

.bday-p3-wave:nth-child(2) {
  width: 100px;
  height: 100px;
  animation: bday-p3-wave-pulse 1.5s ease-in-out 0.3s infinite;
}

.bday-p3-wave:nth-child(3) {
  width: 120px;
  height: 120px;
  animation: bday-p3-wave-pulse 1.5s ease-in-out 0.6s infinite;
}

.bday-p3-wave:nth-child(4) {
  width: 140px;
  height: 140px;
  animation: bday-p3-wave-pulse 1.5s ease-in-out 0.9s infinite;
}

@keyframes bday-p3-wave-pulse {
  0%, 100% { opacity: 0; transform: translate(-50%, -50%) scale(0.8); }
  50% { opacity: 0.6; transform: translate(-50%, -50%) scale(1.1); }
}

@keyframes bday-p3-cd-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

@keyframes bday-p3-cd-pop-left {
  to {
    transform: translateX(0) scale(1) rotate(0deg);
  }
}

.bday-p3-cd-play {
  position: absolute;
  bottom: -20px;
  left: 50%;
  transform: translateX(-50%);
  width: 45px;
  height: 45px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(145deg, #e74c3c 0%, #c0392b 100%);
  color: white;
  font-size: 1rem;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  z-index: 3;
}

.bday-p3-cd-play:hover {
  transform: translateX(-50%) scale(1.15);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.5);
}

.bday-p3-cd-play:active {
  transform: translateX(-50%) scale(0.95);
}

/* Letter - postal style, folded initially */
.bday-p3-letter {
  width: 180px;
  cursor: pointer;
  transform: translateX(200px) scale(0) rotate(180deg);
  animation: bday-p3-letter-pop-right 0.8s cubic-bezier(0.68, -0.55, 0.265, 1.55) 0.7s forwards;
  transition: transform 0.2s ease;
}

.bday-p3-gifts.bday-p3-gifts-visible .bday-p3-letter:not(.bday-p3-letter-open):hover {
  transform: translateX(0) scale(1.05) rotate(0deg);
}

.bday-p3-letter-folded {
  width: 100%;
  height: 115px;
  position: relative;
  transition: transform 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55), opacity 0.4s ease;
}

.bday-p3-envelope-body {
  width: 100%;
  height: 100%;
  background: linear-gradient(145deg, #fffef9 0%, #f8f4ed 100%);
  border: 2px solid #d4c5b0;
  border-radius: 4px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  padding: 0.8rem;
}

.bday-p3-envelope-flap {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 40%;
  background: linear-gradient(180deg, #f8f4ed 0%, #ebe3d5 100%);
  border: 2px solid #d4c5b0;
  border-bottom: none;
  border-radius: 4px 4px 0 0;
  clip-path: polygon(0 0, 50% 100%, 100% 0);
  z-index: 2;
  box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.2);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 0.3rem;
}

.bday-p3-letter-label {
  font-family: 'Caveat', cursive;
  font-size: 0.95rem;
  font-weight: 500;
  color: #6b5d47;
  text-align: center;
  z-index: 1;
  text-transform: lowercase;
  letter-spacing: 0.02em;
  position: relative;
  text-shadow: 0 1px 2px rgba(255, 255, 255, 0.8);
  margin-top: 1.5rem;
}

.bday-p3-letter-seal {
  font-size: 1.5rem;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
  z-index: 3;
  transform: translateY(8px);
}

.bday-p3-letter.bday-p3-letter-open .bday-p3-letter-folded {
  transform: rotateY(180deg) scale(0);
  opacity: 0;
}

.bday-p3-letter-content {
  position: fixed;
  top: 50%;
  left: 130%;
  @media (max-width: 1400px) {
    left: 60%;
  }
  @media (max-width: 1300px) {
    left: 35%;
  }
   @media (max-width: 1200px) {
    left: 20%;
  }
 
  transform: translate(-50%, -50%) scale(0) rotateY(-180deg);
  width: 500px;
  min-height: 300px;
  max-height: calc(100vh - 3rem);
  background: linear-gradient(180deg, #fffef9 0%, #faf8f3 100%);
  border: 2px solid #d4c5b0;
  border-radius: 4px;
  padding: 2rem 2.5rem 2.5rem;
  padding-top: 3rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  opacity: 0;
  transition: transform 0.8s cubic-bezier(0.68, -0.55, 0.265, 1.55), opacity 0.6s ease;
  z-index: 9999;
  isolation: isolate;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.bday-p3-letter.bday-p3-letter-open .bday-p3-letter-content {
  transform: translate(-50%, -50%) scale(1) rotateY(0deg);
  opacity: 1;
  z-index: 9999;
}

.bday-p3-letter-close {
  position: absolute;
  top: 0.8rem;
  right: 0.8rem;
  width: 2rem;
  height: 2rem;
  border: none;
  background: transparent;
  color: #6b5d47;
  font-size: 1.8rem;
  font-weight: 300;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease;
  z-index: 10000;
  -webkit-tap-highlight-color: transparent;
}

.bday-p3-letter-close:hover {
  background: rgba(107, 93, 71, 0.1);
  color: #4a3f2f;
  transform: scale(1.1);
}

.bday-p3-letter-close:active {
  transform: scale(0.95);
}

.bday-p3-letter-text {
  font-family: 'Caveat', cursive;
  font-size: 1.15rem;
  line-height: 1.8;
  color: #3d2817;
  text-align: left;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 0.5rem;
  padding-bottom: 2rem;
  -webkit-overflow-scrolling: touch;
}

.bday-p3-letter-text p {
  margin: 0.8rem 0;
}

/* Plain sans for names (not Pacifico / Caveat on page 1 or in letter) */
.bday-plain-name,
.bday-p3-letter-text .bday-p3-letter-plain {
  font-family: 'Nunito', 'Source Sans 3', system-ui, sans-serif;
  font-style: normal;
  font-synthesis: none;
}

/* After-cake typewriter sender on mati-ji (page 1) */
.bday-mati-ji .bday-final-joe {
  font-family: 'Nunito', 'Source Sans 3', system-ui, sans-serif;
  font-style: normal;
  font-synthesis: none;
}

.bday-p3-letter-signature {
  margin-top: 1.5rem !important;
  text-align: right;
  font-weight: 600;
  font-size: 1.3rem;
}

@keyframes bday-p3-letter-pop-right {
  to {
    transform: translateX(0) scale(1) rotate(0deg);
  }
}

@media (max-width: 800px) {
  .bday-p3-letter-content {
    width: 90vw;
    max-width: 400px;
    max-height: calc(100vh - 3rem);
  }
}

/* Mute button for page 3 */
.bday-p3-mute-btn {
  position: absolute;
  top: 1.5rem;
  right: 1.5rem;
  width: 3rem;
  height: 3rem;
  border: none;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 50%;
  color: #fff;
  font-size: 1.3rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease, background 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}

.bday-p3-mute-btn.bday-p3-mute-visible {
  opacity: 1;
  visibility: visible;
}

.bday-p3-mute-btn:hover {
  background: rgba(0, 0, 0, 0.5);
}

.bday-p3-mute-icon {
  display: none;
}

.bday-p3-mute-btn .bday-p3-mute-on {
  display: inline;
}

.bday-p3-mute-btn.bday-p3-muted .bday-p3-mute-on {
  display: none;
}

.bday-p3-mute-btn.bday-p3-muted .bday-p3-mute-off {
  display: inline;
}

/* Page 2: Photo session mute button (client-specific: used in Afshana) */
.bday-p2-mute-btn {
  position: absolute;
  top: 1.5rem;
  right: 1.5rem;
  width: 3rem;
  height: 3rem;
  border: none;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 50%;
  color: #fff;
  font-size: 1.3rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease, background 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}

.bday-p2-mute-btn.bday-p2-mute-visible {
  opacity: 1;
  visibility: visible;
}

.bday-p2-mute-btn:hover {
  background: rgba(0, 0, 0, 0.5);
}

.bday-p2-mute-icon {
  display: none;
}

.bday-p2-mute-btn .bday-p2-mute-on {
  display: inline;
}

.bday-p2-mute-btn.bday-p2-muted .bday-p2-mute-on {
  display: none;
}

.bday-p2-mute-btn.bday-p2-muted .bday-p2-mute-off {
  display: inline;
}

@media (max-width: 600px) {
  /* Keep page centered always, allow scrolling when content extends */
  .bday-page-3 {
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    overflow-y: auto;
    padding-top: 2rem;
    padding-bottom: 2rem;
  }
  
  .bday-p3-title {
    margin-bottom: 2rem;
    flex-shrink: 0;
    transition: margin-bottom 0.5s ease 0.3s, transform 0.5s ease 0.3s;
  }
  
  /* Push title up when gifts appear - using :has() selector */
  .bday-page-3:has(.bday-p3-gifts.bday-p3-gifts-visible) .bday-p3-title {
    margin-bottom: 0.5rem;
    transform: translateY(-10rem);
  }
  
  /* Fallback for browsers that don't support :has() - add class via JS */
  .bday-page-3.bday-p3-gifts-opened .bday-p3-title {
    margin-bottom: 0.5rem;
    transform: translateY(-10rem);
  }
  
  /* Hide gift box after opening animation completes */
  .bday-p3-gift-box.bday-p3-box-open {
    animation: bday-p3-box-fade-out 0.3s ease 1.5s forwards;
  }
  
  @keyframes bday-p3-box-fade-out {
    to {
      opacity: 0;
      visibility: hidden;
      pointer-events: none;
    }
  }
  
  /* Keep gifts container absolutely positioned and centered even when visible */
  .bday-p3-gifts {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
    max-width: 100%;
    padding: 0 1rem;
  }
  
  /* Stack gifts vertically in center when visible - keep absolutely positioned */
  .bday-p3-gifts.bday-p3-gifts-visible {
    position: absolute;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2.5rem;
    padding-bottom: 3rem;
  }
  
  /* Reset CD player positioning for mobile - center and stack */
  .bday-p3-cd-player {
    position: relative;
    left: auto;
    transform: scale(0);
    animation: bday-p3-cd-mobile-appear 0.8s cubic-bezier(0.68, -0.55, 0.265, 1.55) 1.5s forwards;
    z-index: 10;
  }
  
  .bday-p3-gifts.bday-p3-gifts-visible .bday-p3-cd-player:not(.bday-p3-cd-playing):hover {
    transform: scale(1.1);
  }
  
  @keyframes bday-p3-cd-mobile-appear {
    0% {
      transform: scale(0) rotate(0deg);
    }
    50% {
      transform: scale(1.1) rotate(180deg);
    }
    100% {
      transform: scale(1) rotate(0deg);
    }
  }
  
  /* Reset letter positioning for mobile - center and stack */
  .bday-p3-letter {
    position: relative;
    left: auto;
    transform: scale(0);
    animation: bday-p3-letter-mobile-appear 0.8s cubic-bezier(0.68, -0.55, 0.265, 1.55) 1.7s forwards;
    z-index: 1;
    margin-bottom: 2rem;
  }
  
  .bday-p3-gifts.bday-p3-gifts-visible .bday-p3-letter:not(.bday-p3-letter-open):hover {
    transform: scale(1.05);
  }
  
  /* When letter is open, put it above CD player so letter content appears on top */
  .bday-p3-letter.bday-p3-letter-open {
    z-index: 20;
  }
  
  @keyframes bday-p3-letter-mobile-appear {
    0% {
      transform: scale(0);
    }
    30% {
      transform: scale(1.1) translateY(-20px);
    }
    60% {
      transform: scale(0.95) translateY(5px);
    }
    100% {
      transform: scale(1) translateY(0);
    }
  }
  
  /* Letter content - opens centered on screen in mobile, above all */
  .bday-p3-letter-content {
    position: fixed !important;
    top: 50% !important;
    left: 50% !important;
    transform: translate(-50%, -50%) scale(0) rotateY(-180deg) !important;
    transform-origin: center center !important;
    width: 85vw !important;
    max-width: 320px !important;
    min-height: 250px !important;
    max-height: calc(100vh - 3rem) !important;
    padding: 2.5rem 1.8rem 1.5rem !important;
    margin-bottom: 0 !important;
    z-index: 9999 !important;
    isolation: isolate !important;
  }
  
  .bday-p3-letter.bday-p3-letter-open .bday-p3-letter-content {
    transform: translate(-50%, -50%) scale(1) rotateY(0deg) !important;
  }
  
  .bday-p3-letter-text {
    font-size: 0.95rem !important;
    line-height: 1.6 !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
  }
  
}
