:root {
  --bg: #241713;
  --bg-deep: #1b100d;
  --lilac: #f3dcf3;
  --pink: #f48fb1;
  --pink-soft: #f7a9c4;
  --muted: #d9c3cf;
  --pill: rgba(20, 12, 10, 0.72);
  --red: #a3080c;
  --red-deep: #6f0306;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
}

body {
  background:
    radial-gradient(120% 60% at 50% 105%, rgba(110, 10, 20, 0.45), transparent 60%),
    radial-gradient(90% 50% at 50% 40%, #2c1c17, transparent 70%),
    var(--bg);
  color: var(--lilac);
  font-family: "Roboto", system-ui, sans-serif;
  overflow-x: hidden;
}

#confetti {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
}

.card {
  position: relative;
  z-index: 1;
  max-width: 460px;
  margin: 0 auto;
  padding: 18px 16px 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

/* Fecha */
.date-pill {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 10px 26px;
  border-radius: 999px;
  background: var(--pill);
  border: 1px solid rgba(255, 255, 255, 0.06);
  color: var(--pink-soft);
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}
.date-pill svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: var(--pink);
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.date-pill .heart { fill: var(--pink); stroke: none; }

/* Títulos */
.title {
  margin: 14px 0 0;
  font-family: "Abril Fatface", Georgia, serif;
  font-weight: 400;
  font-size: clamp(32px, 9.4vw, 44px);
  line-height: 1.08;
  color: var(--lilac);
}
.title .name { color: var(--pink); }

.subtitle {
  margin: 10px 0 0;
  font-family: "Shadows Into Light Two", cursive;
  font-size: clamp(21px, 6.6vw, 32px);
  letter-spacing: 0.02em;
  white-space: nowrap;
  color: #f6eef6;
}
.subtitle span { color: var(--pink); }

/* Escenario de la tarta */
.stage {
  position: relative;
  width: 100%;
  max-width: 400px;
  margin-top: 6px;
  aspect-ratio: 400 / 450;
}

#cake {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
  z-index: 2;
}
#cake.dragging { cursor: grabbing; }

.balloons {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
}
.balloon {
  position: absolute;
  top: 2%;
  display: flex;
  flex-direction: column;
  align-items: center;
  animation: float 4.5s ease-in-out infinite;
}
.balloon.right { animation-delay: -2.2s; }
.balloon .digit {
  font-family: "Baloo 2", "Arial Rounded MT Bold", sans-serif;
  font-weight: 800;
  font-size: clamp(88px, 27vw, 120px);
  line-height: 0.95;
  background:
    linear-gradient(160deg, #fbe3ee 0%, #e9a9c2 28%, #c890b4 48%, #f6d3e2 62%, #b98aa9 82%, #e7b9cf 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-stroke: 2px rgba(255, 220, 235, 0.55);
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.45)) drop-shadow(0 0 1px rgba(255, 255, 255, 0.4));
}
.balloon svg {
  width: 18px;
  height: 64px;
  margin-top: -6px;
  overflow: visible;
}
.balloon svg path {
  fill: none;
  stroke: rgba(230, 170, 195, 0.75);
  stroke-width: 1.4;
}
@keyframes float {
  0%, 100% { transform: translateY(0) rotate(-3deg); }
  50% { transform: translateY(-10px) rotate(3deg); }
}

.hint {
  position: absolute;
  left: 50%;
  bottom: 2%;
  transform: translateX(-50%);
  z-index: 3;
  white-space: nowrap;
  padding: 11px 24px;
  border-radius: 999px;
  background: rgba(32, 22, 22, 0.88);
  backdrop-filter: blur(6px);
  font-size: 15px;
  font-weight: 500;
  color: var(--lilac);
  pointer-events: none;
  transition: opacity 0.6s ease;
}
.hint .chev { color: var(--pink); letter-spacing: 0.3em; margin-right: 8px; }
.hint.hidden { opacity: 0; }

/* Reproductor */
.player {
  margin-top: 34px;
  padding-bottom: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.play-btn {
  position: relative;
  width: 84px;
  height: 84px;
  border: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: linear-gradient(160deg, #ffb3cc, #e2709a 55%, #b8507a);
  box-shadow: 0 10px 30px rgba(244, 143, 177, 0.35), inset 0 2px 0 rgba(255, 255, 255, 0.35);
  cursor: pointer;
  transition: transform 0.15s ease;
}
.play-btn::before {
  content: "";
  position: absolute;
  inset: -10px;
  border-radius: 50%;
  border: 2px solid rgba(244, 143, 177, 0.35);
  animation: ring 2.2s ease-out infinite;
}
.play-btn:active { transform: scale(0.94); }
.play-btn:focus-visible { outline: 3px solid var(--lilac); outline-offset: 6px; }
.play-btn svg { width: 36px; height: 36px; fill: #fff; margin-left: 4px; }
.play-label {
  margin: 0;
  color: var(--pink);
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}
@keyframes ring {
  from { transform: scale(0.9); opacity: 1; }
  to { transform: scale(1.35); opacity: 0; }
}

/* Spotify */
.spotify {
  width: 100%;
  max-width: 400px;
  margin-top: 28px;
  border-radius: 14px;
  overflow: hidden;
}
.spotify[hidden] { display: none; }
.spotify iframe { display: block; border: 0; }

/* Botón de sonido */
.sound-btn {
  position: fixed;
  top: 14px;
  right: 14px;
  z-index: 11;
  width: 44px;
  height: 44px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--pill);
  cursor: pointer;
}
.sound-btn[hidden] { display: none; }
.sound-btn svg { width: 22px; height: 22px; fill: var(--pink); stroke: var(--pink); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.sound-btn .wave { fill: none; }
.sound-btn .off, .sound-btn.muted .on { display: none; }
.sound-btn.muted .off { display: block; }

/* Carta */
.letter {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(10, 5, 4, 0.72);
  backdrop-filter: blur(4px);
  animation: fade 0.3s ease;
}
.letter[hidden] { display: none; }

.envelope {
  grid-area: 1 / 1;
  position: relative;
  width: min(320px, 84vw);
  aspect-ratio: 3 / 2;
  perspective: 900px;
  transition: opacity 0.4s ease, transform 0.4s ease;
}
.env-back, .env-front, .env-flap, .env-paper { position: absolute; }
.env-back {
  inset: 0;
  z-index: 1;
  border-radius: 10px;
  background: #7e0a14;
}
.env-paper {
  left: 7%;
  right: 7%;
  top: 8%;
  bottom: 6%;
  border-radius: 6px;
  z-index: 2;
  background: repeating-linear-gradient(180deg, #fff8ef 0 15px, #f1d9df 15px 16px);
  transition: transform 0.7s cubic-bezier(0.3, 1.2, 0.4, 1) 0.45s;
}
.env-front {
  inset: 0;
  border-radius: 10px;
  background: linear-gradient(180deg, #b3121f, #8e0b16);
  clip-path: polygon(0 0, 50% 56%, 100% 0, 100% 100%, 0 100%);
  z-index: 3;
}
.env-flap {
  left: 0;
  right: 0;
  top: 0;
  height: 62%;
  background: linear-gradient(180deg, #c8182a, #9e0d19);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  transform-origin: top;
  transition: transform 0.5s ease, z-index 0s linear 0.25s;
  z-index: 4;
  display: grid;
  place-items: end center;
}
.env-flap span {
  margin-bottom: 4%;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--pink);
  color: #8e0b16;
  font-size: 20px;
  transition: opacity 0.2s ease;
}
.envelope.open .env-flap { transform: rotateX(180deg); z-index: 1; }
.envelope.open .env-flap span { opacity: 0; }
.envelope.open .env-paper { transform: translateY(-55%); }
.letter.show-paper .envelope { opacity: 0; transform: scale(0.9); pointer-events: none; }

.paper {
  grid-area: 1 / 1;
  position: relative;
  width: min(400px, 100%);
  display: flex;
  flex-direction: column;
  padding: 50px 26px 16px;
  border-radius: 8px;
  background: #fff8ef;
  perspective: 1200px;
  color: #4a2a2a;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
  text-align: left;
  visibility: hidden;
  opacity: 0;
  transform: translateY(30px) scale(0.92);
  transition: opacity 0.45s ease, transform 0.45s cubic-bezier(0.2, 1.3, 0.4, 1), visibility 0s linear 0.45s;
}
.letter.show-paper .paper {
  visibility: visible;
  opacity: 1;
  transform: none;
  transition-delay: 0s;
}
.page {
  height: min(430px, calc(100dvh - 150px));
  overflow-y: auto;
  touch-action: pan-y;
  transform-style: preserve-3d;
  backface-visibility: hidden;
}
.page.out-next { transform-origin: left center; animation: page-out-next 0.32s ease-in forwards; }
.page.in-next { transform-origin: right center; animation: page-in-next 0.38s ease-out; }
.page.out-prev { transform-origin: right center; animation: page-out-prev 0.32s ease-in forwards; }
.page.in-prev { transform-origin: left center; animation: page-in-prev 0.38s ease-out; }
@keyframes page-out-next { to { transform: rotateY(-75deg) translateX(-10px); opacity: 0; } }
@keyframes page-in-next { from { transform: rotateY(75deg) translateX(10px); opacity: 0; } }
@keyframes page-out-prev { to { transform: rotateY(75deg) translateX(10px); opacity: 0; } }
@keyframes page-in-prev { from { transform: rotateY(-75deg) translateX(-10px); opacity: 0; } }

.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed rgba(208, 84, 127, 0.3);
}
.page-btn {
  width: 46px;
  height: 46px;
  border: 0;
  border-radius: 50%;
  background: #f9dbe6;
  color: #b23a64;
  font-size: 30px;
  line-height: 1;
  padding-bottom: 4px;
  cursor: pointer;
  transition: background 0.2s ease, opacity 0.2s ease, transform 0.15s ease;
}
.page-btn:hover:not(:disabled) { background: #f5c6d7; }
.page-btn:active:not(:disabled) { transform: scale(0.92); }
.page-btn:focus-visible { outline: 2px solid #d0547f; outline-offset: 3px; }
.page-btn:disabled { opacity: 0.25; cursor: default; }
.page-btn.nudge { animation: nudge 1.4s ease-in-out infinite; }
@keyframes nudge { 50% { transform: translateX(4px); } }
.dots { display: flex; gap: 8px; }
.dots span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #f0c3d3;
  transition: background 0.25s ease, width 0.25s ease;
}
.dots span.on { width: 22px; border-radius: 4px; background: #d0547f; }

.paper h2 {
  margin: 0 0 16px;
  font-family: "Abril Fatface", Georgia, serif;
  font-weight: 400;
  font-size: 30px;
  color: #6f1d2c;
}
.paper h2 span { color: #d0547f; }
.paper p {
  margin: 0;
  font-family: "Shadows Into Light Two", cursive;
  font-size: 22px;
  line-height: 32px;
  white-space: pre-line;
}
.paper strong { font-weight: 400; color: #c2416f; }
.paper .inv { display: inline-block; transform: rotate(180deg); }
.paper .closing {
  margin-top: 40px;
  text-align: center;
  font-size: 42px;
  line-height: 1.2;
  color: #c2416f;
}
.close {
  position: absolute;
  top: 8px;
  right: 10px;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: #8a6070;
  font-size: 30px;
  line-height: 1;
  cursor: pointer;
}
.close:hover { background: rgba(0, 0, 0, 0.05); }
@keyframes fade { from { opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  .balloon, .play-btn::before { animation: none; }
  .env-flap, .env-paper, .paper { transition: none; }
  .page-btn.nudge { animation: none; }
}
