/* ---------- Reset & Base ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow-x: hidden; }
body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  color: #fff;
  background: #0b0420;
  min-height: 100vh;
  position: relative;
  -webkit-tap-highlight-color: transparent;
  line-height: 1.6;
  font-size: 16px;
}

/* ---------- Animated Background ---------- */
.bg-gradient {
  position: fixed; inset: 0; z-index: -2;
  background: linear-gradient(135deg, #1a0533 0%, #3b0764 35%, #831843 70%, #be185d 100%);
  background-size: 400% 400%;
  animation: gradientShift 18s ease infinite;
}
@keyframes gradientShift {
  0%,100% { background-position: 0% 50%; }
  50%     { background-position: 100% 50%; }
}

.bg-stars {
  position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background-image:
    radial-gradient(1px 1px at 20% 30%, #fff, transparent),
    radial-gradient(1px 1px at 70% 80%, #fff, transparent),
    radial-gradient(2px 2px at 40% 60%, #fff, transparent),
    radial-gradient(1px 1px at 85% 15%, #fff, transparent),
    radial-gradient(1.5px 1.5px at 10% 75%, #fff, transparent),
    radial-gradient(1px 1px at 55% 40%, #fff, transparent);
  background-size: 100% 100%;
  animation: twinkle 4s ease-in-out infinite alternate;
}
@keyframes twinkle { from { opacity: .4; } to { opacity: 1; } }

/* ---------- Floating Hearts ---------- */
.hearts-layer {
  position: fixed; inset: 0; pointer-events: none; z-index: 1; overflow: hidden;
}
.heart {
  position: absolute; bottom: -40px; font-size: 20px;
  animation: floatUp linear forwards;
  opacity: .8;
}
@keyframes floatUp {
  0%   { transform: translateY(0) rotate(0deg); opacity: 0; }
  10%  { opacity: .9; }
  100% { transform: translateY(-110vh) rotate(360deg); opacity: 0; }
}

/* ---------- Music Toggle ---------- */
.music-toggle {
  position: fixed; top: 18px; right: 18px; z-index: 100;
  width: 48px; height: 48px; border-radius: 50%;
  background: rgba(255,255,255,.12);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255,255,255,.25);
  color: #fff; font-size: 20px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: transform .2s, background .2s;
}
.music-toggle:hover { transform: scale(1.1); background: rgba(255,255,255,.2); }
.music-toggle.playing .icon { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.2); } }

/* ---------- Sections ---------- */
.app { position: relative; z-index: 2; min-height: 100vh; }
.section {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  opacity: 0; visibility: hidden;
  transition: opacity .8s ease, visibility .8s;
}
.section.active { opacity: 1; visibility: visible; }

/* ---------- Cards (shared) ---------- */
.intro-card, .story-card, .cake-card, .letter-card, .gallery-card {
  text-align: center;
  max-width: 640px; width: 100%;
  padding: 36px 24px;
  background: rgba(255,255,255,.08);
  backdrop-filter: blur(14px);
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 24px;
  box-shadow: 0 20px 60px rgba(0,0,0,.4);
  animation: floatIn .9s ease both;
}
@keyframes floatIn {
  from { transform: translateY(30px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}

/* ---------- Intro / Gift ---------- */
.glow-title {
  font-size: clamp(2rem, 6vw, 3.5rem);
  font-weight: 800;
  background: linear-gradient(90deg, #ff8ab8, #ffd1e3, #ff8ab8);
  background-size: 200% auto;
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: shimmer 3s linear infinite;
  margin-bottom: 12px;
  line-height: 1.2;
}
@keyframes shimmer { to { background-position: 200% center; } }

.subtitle { color: #ffd1e3; font-size: clamp(1rem, 2.5vw, 1.15rem); margin-bottom: 32px; }
.hint { margin-top: 24px; color: #ffb3d1; font-size: .95rem; animation: bob 2s ease-in-out infinite; }
@keyframes bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }

/* Gift box */
.gift-wrap {
  cursor: pointer; outline: none;
  display: inline-block; margin: 20px 0;
  transition: transform .3s;
}
.gift-wrap:hover, .gift-wrap:focus-visible { transform: scale(1.05); }
.gift { position: relative; width: 160px; height: 160px; margin: 0 auto; }
.gift-body {
  position: absolute; bottom: 0; width: 160px; height: 120px;
  background: linear-gradient(135deg, #ff4d88, #c2185b);
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(255,77,136,.4);
}
.ribbon-vert {
  position: absolute; left: 50%; top: 0; bottom: 0; width: 20px;
  transform: translateX(-50%);
  background: linear-gradient(180deg, #ffd700, #ffaa00);
}
.ribbon-horiz {
  position: absolute; top: 50%; left: 0; right: 0; height: 20px;
  transform: translateY(-50%);
  background: linear-gradient(90deg, #ffd700, #ffaa00);
}
.gift-lid {
  position: absolute; top: 0; left: -6px; width: 172px; height: 40px;
  background: linear-gradient(135deg, #ff4d88, #c2185b);
  border-radius: 8px;
  transition: transform .8s cubic-bezier(.5,-.5,.5,1.5);
  transform-origin: center bottom;
  z-index: 2;
}
.ribbon-top {
  position: absolute; left: 50%; top: 50%;
  width: 20px; height: 40px; transform: translate(-50%,-50%);
  background: linear-gradient(180deg, #ffd700, #ffaa00);
}
.gift-wrap.opened .gift-lid {
  transform: translateY(-120px) rotate(-25deg);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-block;
  padding: 14px 32px;
  margin-top: 24px;
  border: none; border-radius: 999px;
  font-size: clamp(.95rem, 2.2vw, 1rem);
  font-weight: 600;
  cursor: pointer;
  transition: transform .2s, box-shadow .2s;
  font-family: inherit;
  min-height: 48px;
}
.btn-primary {
  background: linear-gradient(135deg, #ff4d88, #ff8ab8);
  color: #fff;
  box-shadow: 0 8px 24px rgba(255,77,136,.4);
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 12px 30px rgba(255,77,136,.55); }
.btn-ghost {
  background: rgba(255,255,255,.1);
  color: #fff;
  border: 1px solid rgba(255,255,255,.3);
}
.btn-ghost:hover { background: rgba(255,255,255,.2); }
.hidden { display: none !important; }

/* ---------- Story ---------- */
.story-title {
  font-size: clamp(1.6rem, 4.5vw, 2.4rem);
  margin-bottom: 20px;
  color: #ffd1e3;
  line-height: 1.2;
}
.story-text {
  font-size: clamp(1rem, 2.5vw, 1.15rem);
  color: #fff;
  min-height: 100px;
  text-align: left;
  padding: 0 8px;
  line-height: 1.7;
}
.story-text::after {
  content: '|'; animation: blink 1s infinite; color: #ff8ab8;
}
@keyframes blink { 50% { opacity: 0; } }

/* ---------- Cake ---------- */
.cake-stage {
  position: relative;
  height: 220px;
  display: flex; align-items: flex-end; justify-content: center;
  margin: 12px 0;
}
.cake { position: relative; width: 220px; height: 220px; }
.plate {
  position: absolute; bottom: 0; left: -20px;
  width: 260px; height: 16px;
  background: linear-gradient(180deg, #e0e0e0, #9e9e9e);
  border-radius: 50%;
  box-shadow: 0 6px 12px rgba(0,0,0,.3);
}
.layer {
  position: absolute; left: 50%; transform: translateX(-50%);
  border-radius: 10px;
}
.layer-1 { bottom: 14px; width: 200px; height: 50px; background: linear-gradient(180deg, #ff9ec7, #ff6fa8); }
.layer-2 { bottom: 64px; width: 170px; height: 45px; background: linear-gradient(180deg, #ffb8d9, #ff85b8); }
.layer-3 { bottom: 109px; width: 140px; height: 40px; background: linear-gradient(180deg, #ffd1e3, #ffa8cc); }
.frosting {
  position: absolute; bottom: 149px; left: 50%; transform: translateX(-50%);
  width: 140px; height: 10px;
  background: #fff;
  border-radius: 6px 6px 0 0;
  box-shadow: 0 -2px 6px rgba(255,255,255,.5);
}
.candle {
  position: absolute; bottom: 158px; left: 50%; transform: translateX(-50%);
  width: 14px; height: 40px;
  background: linear-gradient(180deg, #fff, #ffd1e3);
  border-radius: 3px;
  cursor: pointer;
}
.wick {
  position: absolute; top: -6px; left: 50%; transform: translateX(-50%);
  width: 2px; height: 6px; background: #333;
}
.flame {
  position: absolute; top: -26px; left: 50%; transform: translateX(-50%);
  width: 14px; height: 22px;
  background: radial-gradient(circle at 50% 70%, #fff7a8 0%, #ffb347 40%, #ff4d4d 80%);
  border-radius: 50% 50% 20% 20%;
  box-shadow: 0 0 20px #ffb347, 0 0 40px #ff8c42;
  animation: flicker .15s infinite alternate;
  transform-origin: bottom center;
}
@keyframes flicker {
  from { transform: translateX(-50%) scale(1) rotate(-2deg); }
  to   { transform: translateX(-50%) scale(1.05) rotate(2deg); }
}
.flame.out { animation: blowOut .6s forwards; }
@keyframes blowOut {
  0%   { opacity: 1; transform: translateX(-50%) scale(1); }
  100% { opacity: 0; transform: translateX(-50%) scale(.2) translateY(-20px); }
}
.cake-hint { color: #ffb3d1; margin-bottom: 8px; font-size: clamp(.9rem, 2.2vw, 1rem); }
.cake-message {
  color: #ffd1e3; font-size: clamp(1rem, 2.5vw, 1.15rem);
  margin-top: 16px;
  animation: floatIn .8s ease both;
}

/* ---------- Letter ---------- */
.letter {
  background: linear-gradient(180deg, #fff8e7, #ffe8d6);
  color: #4a2c1a;
  padding: 28px 22px;
  border-radius: 12px;
  text-align: left;
  box-shadow: 0 10px 30px rgba(0,0,0,.3);
  font-family: 'Georgia', serif;
  transform-origin: top center;
  animation: unfold 1.2s ease both;
}
@keyframes unfold {
  from { transform: scaleY(0); opacity: 0; }
  to   { transform: scaleY(1); opacity: 1; }
}
.letter-header { font-style: italic; font-size: clamp(1rem, 2.5vw, 1.1rem); margin-bottom: 14px; color: #8b3a62; }
.letter-body { font-size: clamp(.95rem, 2.3vw, 1rem); line-height: 1.7; white-space: pre-wrap; }
.letter-sign { margin-top: 20px; text-align: right; font-style: italic; color: #8b3a62; }

/* ---------- Gallery ---------- */
.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
  margin: 20px 0;
}
.gallery-item {
  aspect-ratio: 1;
  border-radius: 12px;
  overflow: hidden;
  background: linear-gradient(135deg, #ff8ab8, #c2185b);
  display: flex; align-items: center; justify-content: center;
  font-size: 2.5rem;
  cursor: pointer;
  transition: transform .3s;
  box-shadow: 0 6px 18px rgba(0,0,0,.3);
  animation: popIn .6s ease both;
}
.gallery-item:hover { transform: scale(1.05) rotate(-2deg); }
.gallery-item img { width: 100%; height: 100%; object-fit: cover; }
@keyframes popIn {
  from { transform: scale(0); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}

/* ---------- Finale / Fireworks ---------- */
.fireworks-canvas {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  z-index: 1;
}
.finale-content {
  position: relative; z-index: 2;
  text-align: center; padding: 20px;
  max-width: 90%;
}
.finale-title {
  font-size: clamp(2rem, 7vw, 4rem);
  font-weight: 800;
  background: linear-gradient(90deg, #ffd700, #ff8ab8, #ffd700);
  background-size: 200% auto;
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: shimmer 2.5s linear infinite, floatIn 1s ease both;
  margin-bottom: 16px;
  line-height: 1.2;
  word-break: break-word;
}
.finale-sub {
  font-size: clamp(1rem, 3vw, 1.25rem);
  color: #ffd1e3;
  animation: floatIn 1.4s ease both;
}

/* ---------- Responsive ---------- */

/* Small phones (< 400px) */
@media (max-width: 400px) {
  .intro-card, .story-card, .cake-card, .letter-card, .gallery-card {
    padding: 24px 16px;
    border-radius: 20px;
  }
  .gift { transform: scale(.78); }
  .cake-stage { height: 200px; }
  .cake { transform: scale(.78); }
  .btn { padding: 12px 24px; }
  
  /* ✨ Mobile gallery: exactly 2 columns ✨ */
  .gallery {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }
}

/* Mobile (401px - 600px) */
@media (min-width: 401px) and (max-width: 600px) {
  .intro-card, .story-card, .cake-card, .letter-card, .gallery-card {
    padding: 28px 20px;
  }
  .gift { transform: scale(.88); }
  .cake { transform: scale(.9); }
  
  /* ✨ Mobile gallery: 2 columns ✨ */
  .gallery {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }
}

/* Tablet (601px - 900px) */
@media (min-width: 601px) and (max-width: 900px) {
  .intro-card, .story-card, .cake-card, .letter-card, .gallery-card {
    max-width: 560px;
  }
}

/* Large screens (1200px+) */
@media (min-width: 1200px) {
  .intro-card, .story-card, .cake-card, .letter-card, .gallery-card {
    max-width: 720px;
    padding: 48px 36px;
  }
}

/* Landscape on short screens */
@media (orientation: landscape) and (max-height: 500px) {
  .section { align-items: flex-start; padding-top: 16px; }
  .intro-card, .story-card, .cake-card, .letter-card, .gallery-card {
    padding: 16px;
    max-height: calc(100vh - 40px);
    overflow-y: auto;
  }
  .cake-stage { height: 180px; }
  .cake { transform: scale(.75); }
  .gift { transform: scale(.7); }
}

/* Very short landscape */
@media (orientation: landscape) and (max-height: 400px) {
  .glow-title { font-size: 1.8rem; }
  .story-title { font-size: 1.4rem; }
  .cake-stage { height: 160px; }
  .cake { transform: scale(.65); }
}

/* ---------- Accessibility ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
:focus-visible { outline: 3px solid #ffd700; outline-offset: 3px; }