/* Regla de oro para que vaya fluido: solo se animan transform y opacity,
   nada de filter/backdrop-filter, y el fondo es estático. */

:root {
  --bg-top: #070b1c;
  --bg-bot: #101a3a;
  --yellow: #ffd23f;
  --yellow-deep: #f4a300;
  --ink: #fdf6e3;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }

body {
  font-family: "Cormorant Garamond", Georgia, serif;
  color: var(--ink);
  background: linear-gradient(180deg, var(--bg-top) 0%, var(--bg-bot) 100%);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

.screen {
  position: fixed; inset: 0;
  z-index: 2;
  transition: opacity 1.2s ease;
}
.screen.hidden { opacity: 0; pointer-events: none; }

/* ---------- Cielo ---------- */
#sky { position: fixed; inset: 0; z-index: 0; pointer-events: none; }
#stars-sm, #stars-lg {
  position: absolute; top: 0; left: 0;
  width: 1px; height: 1px;
  border-radius: 50%;
  background: #fff8e1;
  /* el box-shadow con todas las estrellas lo genera JS */
}
#stars-lg { width: 2px; height: 2px; }
#stars-sm { animation: twinkle 4s ease-in-out infinite alternate; }
#stars-lg { animation: twinkle 3s ease-in-out 1.5s infinite alternate; }
@keyframes twinkle { from { opacity: .45; } to { opacity: 1; } }

#shooting {
  position: absolute;
  top: 15%; left: 70%;
  width: 120px; height: 2px;
  border-radius: 2px;
  background: linear-gradient(90deg, rgba(255, 248, 225, 0), #fff8e1);
  transform: rotate(-25deg) translateX(0);
  opacity: 0;
  animation: shoot 9s ease-in 4s infinite;
}
@keyframes shoot {
  0%   { opacity: 0; transform: rotate(-25deg) translateX(0); }
  2%   { opacity: 1; }
  8%   { opacity: 0; transform: rotate(-25deg) translateX(-520px); }
  100% { opacity: 0; transform: rotate(-25deg) translateX(-520px); }
}

/* ---------- Luciérnagas (pocas) ---------- */
#fireflies { position: fixed; inset: 0; z-index: 1; pointer-events: none; }
.firefly {
  position: absolute;
  width: 5px; height: 5px;
  border-radius: 50%;
  background: #fff3a8;
  box-shadow: 0 0 10px 3px rgba(255, 220, 90, .7);
  opacity: 0;
  animation:
    drift var(--dur) ease-in-out var(--delay) infinite alternate,
    blink 3.5s ease-in-out var(--delay) infinite;
}
@keyframes drift { to { transform: translate(var(--dx), var(--dy)); } }
@keyframes blink { 0%, 100% { opacity: 0; } 45%, 55% { opacity: 1; } }

/* ---------- Pantalla de entrada ---------- */
#gate { display: grid; place-items: center; padding: 24px 16px; }
.gate-card {
  width: min(440px, 100%);
  text-align: center;
  padding: 40px 28px 32px;
  border-radius: 24px;
  background: rgba(16, 24, 56, .85);
  border: 1px solid rgba(255, 210, 63, .25);
  box-shadow: 0 30px 80px rgba(0, 0, 0, .45);
  animation: rise 1s cubic-bezier(.2, .8, .2, 1) both;
}
@keyframes rise {
  from { opacity: 0; transform: translateY(24px); }
  to   { opacity: 1; transform: none; }
}
.gate-heart { font-size: 56px; animation: float 3s ease-in-out infinite; }
@keyframes float {
  0%, 100% { transform: translateY(0) rotate(-4deg); }
  50%      { transform: translateY(-8px) rotate(4deg); }
}
.gate-card h1 {
  font-family: "Great Vibes", cursive;
  font-weight: 400;
  font-size: clamp(38px, 8vw, 52px);
  color: var(--yellow);
  margin-top: 8px;
}
.gate-sub { font-size: 20px; font-style: italic; opacity: .8; margin-top: 4px; }
.gate-question { font-size: 22px; margin: 26px 0 14px; }

#gate-form { display: flex; gap: 8px; }
#gate-input {
  flex: 1; min-width: 0;
  font: inherit; font-size: 19px;
  padding: 12px 16px;
  min-height: 50px;
  color: var(--ink);
  color-scheme: dark;
  background: rgba(0, 0, 0, .3);
  border: 1px solid rgba(255, 244, 214, .25);
  border-radius: 14px;
  outline: none;
}
#gate-input:focus { border-color: var(--yellow); }
#gate-form button, .pill {
  font: inherit; font-size: 18px; font-weight: 600;
  padding: 12px 20px;
  color: #3a2400;
  background: linear-gradient(180deg, #ffe27a, var(--yellow-deep));
  border: none; border-radius: 14px;
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(244, 163, 0, .35);
}
.gate-hint { min-height: 24px; margin-top: 16px; font-size: 17px; font-style: italic; color: #ffcf8a; opacity: 0; transition: opacity .4s; }
.gate-hint.show { opacity: .9; }
.gate-card.shake { animation: shake .5s; }
@keyframes shake {
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}

/* ---------- Escena de flores ---------- */
#garden { overflow: hidden; }

.title {
  position: absolute;
  top: calc(6vh + env(safe-area-inset-top));
  left: 0; right: 0;
  text-align: center;
  padding: 0 16px;
  z-index: 4;
  opacity: 0;
  transform: translateY(-12px);
  transition: opacity 1.4s ease, transform 1.4s ease;
}
.title.show { opacity: 1; transform: none; }
.title h1 {
  font-family: "Great Vibes", cursive;
  font-weight: 400;
  font-size: clamp(44px, 10vw, 76px);
  color: var(--yellow);
  line-height: 1.1;
}
.title p { font-size: clamp(18px, 2.5vw, 24px); font-style: italic; opacity: .85; margin-top: 4px; }

#glow {
  position: absolute;
  left: 50%; bottom: -10vh;
  width: 120vw; height: 40vh;
  transform: translateX(-50%);
  background: radial-gradient(ellipse at 50% 100%, rgba(255, 210, 63, .18), transparent 60%);
  z-index: 1;
}

#flowers {
  position: absolute; inset: 0;
  z-index: 2;
  pointer-events: none;
}

/* Cada flor nace del mismo punto (abajo, centro) y se abre en abanico con --a */
.flower {
  position: absolute;
  left: 50%;
  bottom: -6vh;
  height: var(--h);
  width: calc(var(--h) * 0.4);
  margin-left: calc(var(--h) * -0.2);
  transform-origin: 50% 100%;
  overflow: visible;
  will-change: transform;
  animation: sway var(--sway) ease-in-out var(--d) infinite alternate;
}
@keyframes sway {
  from { transform: rotate(calc(var(--a) - 1.5deg)); }
  to   { transform: rotate(calc(var(--a) + 1.5deg)); }
}

.stem {
  fill: none;
  stroke: url(#stemGrad);
  stroke-width: 8;
  stroke-linecap: round;
  animation: grow 2.2s cubic-bezier(.35, .1, .25, 1) var(--d) forwards;
}
@keyframes grow { to { stroke-dashoffset: 0; } }

.leaf {
  fill: url(#leafGrad);
  transform-box: fill-box;
  transform-origin: 0% 100%;
  transform: scale(0);
  animation: pop .9s cubic-bezier(.2, 1.4, .4, 1) var(--ld) forwards;
}
@keyframes pop { to { transform: scale(1); } }

.head {
  transform-box: fill-box;
  transform-origin: center;
  transform: scale(0) rotate(-90deg);
  animation: bloom 1.5s cubic-bezier(.2, 1.3, .4, 1) var(--hd) forwards;
}
@keyframes bloom { to { transform: scale(1) rotate(0deg); } }

.petal {
  transform-box: fill-box;
  transform-origin: 50% 100%;
  transform: scale(.15);
  opacity: 0;
  animation: petal .8s cubic-bezier(.2, 1.2, .4, 1) var(--pd) forwards;
}
@keyframes petal { to { transform: scale(1); opacity: 1; } }
.petal.outer { fill: url(#petalGrad); }
.petal.inner { fill: url(#petalInnerGrad); }
.core { fill: url(#coreGrad); }
.core-dot { fill: #f6d67a; opacity: .5; }

/* ---------- Pétalos cayendo ---------- */
#petals { position: absolute; inset: 0; z-index: 3; pointer-events: none; overflow: hidden; }
.fall {
  position: absolute; top: -30px;
  width: 12px; height: 18px;
  border-radius: 60% 60% 60% 60% / 80% 80% 40% 40%;
  background: linear-gradient(180deg, #ffe27a, var(--yellow-deep));
  will-change: transform;
  animation: fall var(--dur) linear var(--delay) infinite;
}
@keyframes fall {
  0%   { transform: translate(0, 0) rotate(0deg); opacity: 0; }
  10%  { opacity: .9; }
  100% { transform: translate(var(--dx), 110vh) rotate(var(--rot)); opacity: .2; }
}

/* ---------- Carta ---------- */
.letter {
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  width: min(560px, calc(100% - 32px));
  max-height: calc(100% - 150px);
  overflow-y: auto;
  padding: 36px 30px 30px;
  border-radius: 24px;
  background: rgba(10, 16, 40, .92);
  border: 1px solid rgba(255, 210, 63, .3);
  box-shadow: 0 30px 80px rgba(0, 0, 0, .55);
  z-index: 5;
  opacity: 0;
  transition: opacity .8s ease, transform .8s cubic-bezier(.2, .8, .2, 1);
}
.letter.hidden { opacity: 0; pointer-events: none; transform: translate(-50%, -46%); }
.letter.show { opacity: 1; transform: translate(-50%, -50%); pointer-events: auto; }
.letter h2 {
  font-family: "Great Vibes", cursive;
  font-weight: 400;
  font-size: clamp(40px, 9vw, 58px);
  color: var(--yellow);
  text-align: center;
  margin-bottom: 14px;
}
#letter-body p {
  font-size: clamp(19px, 2.4vw, 22px);
  line-height: 1.55;
  margin-bottom: 14px;
  min-height: 1em;
}
#letter-body p.typing::after { content: "|"; color: var(--yellow); animation: caret 1s steps(1) infinite; }
@keyframes caret { 50% { opacity: 0; } }
.sign {
  font-family: "Great Vibes", cursive;
  font-size: 34px;
  color: var(--yellow);
  text-align: right;
  margin-top: 6px;
  opacity: 0;
  transition: opacity 1s;
}
.sign.show { opacity: 1; }

.counter { margin-top: 22px; padding-top: 18px; border-top: 1px dashed rgba(255, 210, 63, .3); text-align: center; }
.counter.hidden { display: none; }
.counter p { font-size: 19px; font-style: italic; opacity: .85; margin-bottom: 10px; }
.counter-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.counter-grid div { padding: 10px 4px; border-radius: 14px; background: rgba(255, 210, 63, .08); }
.counter-grid b { display: block; font-size: clamp(22px, 5vw, 32px); color: var(--yellow); font-weight: 600; }
.counter-grid span { font-size: 14px; letter-spacing: .08em; text-transform: uppercase; opacity: .7; }

/* ---------- Botones flotantes ---------- */
.pill {
  position: absolute;
  left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  z-index: 6;
  border-radius: 999px;
  padding: 12px 24px;
  animation: pillrise .8s ease both;
}
@keyframes pillrise {
  from { opacity: 0; transform: translate(-50%, 20px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}
.pill.hidden { display: none; }

.music {
  position: absolute;
  top: calc(16px + env(safe-area-inset-top)); left: 16px;
  z-index: 6;
  width: 44px; height: 44px;
  border-radius: 50%;
  font-size: 22px;
  color: var(--yellow);
  background: rgba(10, 16, 40, .7);
  border: 1px solid rgba(255, 210, 63, .35);
  cursor: pointer;
}
.music.hidden { display: none; }
.music.muted { opacity: .5; text-decoration: line-through; }

@media (prefers-reduced-motion: reduce) {
  .flower, .firefly, .fall, #stars-sm, #stars-lg, #shooting { animation-iteration-count: 1 !important; }
}
