:root {
  --pink: #ff5fa8;
  --pink-soft: #ffb3d4;
  --pink-deep: #d81b72;
  --night: #06020a;
  --paper: #fff8ef;
  --ink: #4a2338;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--night);
  color: #fff;
  font-family: "Quicksand", system-ui, sans-serif;
  overscroll-behavior: none;
}

button { font-family: inherit; cursor: pointer; }

/* ---------- Pantallas ---------- */
.screen {
  position: fixed;
  inset: 0;
  opacity: 0;
  visibility: hidden;
  transition: opacity .9s ease, visibility 0s linear .9s;
}
.screen.active {
  opacity: 1;
  visibility: visible;
  transition: opacity .9s ease;
}

/* ================= CLAVE ================= */
#gate {
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(ellipse at 50% 110%, #5a0f3c 0%, transparent 60%),
    radial-gradient(ellipse at 20% 0%, #2a0a3a 0%, transparent 55%),
    var(--night);
}

.gate-hearts { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.gate-hearts span {
  position: absolute;
  bottom: -60px;
  opacity: 0;
  animation: floatUp linear infinite;
}
@keyframes floatUp {
  0%   { transform: translateY(0) rotate(-10deg); opacity: 0; }
  10%  { opacity: .75; }
  90%  { opacity: .75; }
  100% { transform: translateY(-115vh) rotate(20deg); opacity: 0; }
}

.gate-card {
  position: relative;
  width: min(100%, 360px);
  padding: 34px 26px 28px;
  text-align: center;
  border-radius: 28px;
  background: rgba(255, 255, 255, .07);
  border: 1px solid rgba(255, 179, 212, .35);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 20px 60px rgba(216, 27, 114, .35), inset 0 0 40px rgba(255, 95, 168, .08);
}

.gate-emoji { font-size: 72px; line-height: 1; margin-bottom: 8px; }

.gate-card h1 {
  margin: 0 0 6px;
  font-family: "Caveat", cursive;
  font-size: 2.6rem;
  font-weight: 700;
  color: var(--pink-soft);
}

.gate-msg { margin: 0 0 20px; min-height: 2.8em; font-size: 1rem; line-height: 1.4; color: #fbe3ee; }
.gate-msg.bad  { color: #ff8a8a; font-weight: 700; }
.gate-msg.good { color: #9dffcf; font-weight: 700; }

#gate-input {
  width: 100%;
  padding: 14px 10px;
  font: 700 1.5rem "Quicksand", sans-serif;
  letter-spacing: .35em;
  text-align: center;
  color: #fff;
  background: rgba(0, 0, 0, .35);
  border: 2px solid rgba(255, 179, 212, .45);
  border-radius: 16px;
  outline: none;
  transition: border-color .2s, box-shadow .2s;
}
#gate-input::placeholder { color: rgba(255, 255, 255, .3); letter-spacing: .2em; font-size: 1.1rem; }
#gate-input:focus { border-color: var(--pink); box-shadow: 0 0 0 4px rgba(255, 95, 168, .25); }

.gate-card button, .letter-btn, .close-letter {
  border: 0;
  border-radius: 999px;
  color: #fff;
  font-weight: 700;
  background: linear-gradient(135deg, var(--pink), var(--pink-deep));
  box-shadow: 0 8px 24px rgba(216, 27, 114, .5);
  transition: transform .15s;
}
.gate-card button:active, .letter-btn:active, .close-letter:active { transform: scale(.95); }
.gate-card button { margin-top: 16px; width: 100%; padding: 14px; font-size: 1.1rem; }

/* ================= GALAXIA ================= */
#scene { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

.ransom {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 5vh);
  left: 0; right: 0;
  margin: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 5px;
  pointer-events: none;
}
.ransom .scrap {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: clamp(44px, 12.5vw, 76px);
  height: clamp(58px, 16vw, 98px);
  font-size: clamp(42px, 12vw, 74px);
  line-height: 1;
  color: #121212;
  background: linear-gradient(160deg, #fbfbf7, #dedcd4);
  box-shadow: 0 6px 14px rgba(0, 0, 0, .6);
}
.ransom .gap { width: clamp(12px, 4vw, 26px); }
.ransom .deco {
  position: absolute;
  font-size: clamp(16px, 4.5vw, 26px);
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, .5));
}

.hud {
  position: absolute;
  left: 0; right: 0;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 18px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 0 16px;
  pointer-events: none;
  text-align: center;
}
.days {
  margin: 0;
  font-family: "Caveat", cursive;
  font-size: 1.5rem;
  color: var(--pink-soft);
  text-shadow: 0 0 12px rgba(255, 95, 168, .8);
}
.letter-btn {
  pointer-events: auto;
  padding: 14px 26px;
  font-size: 1.05rem;
  animation: pulse 2.2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 8px 24px rgba(216, 27, 114, .5), 0 0 0 0 rgba(255, 95, 168, .55); }
  50%      { box-shadow: 0 8px 24px rgba(216, 27, 114, .5), 0 0 0 14px rgba(255, 95, 168, 0); }
}
.hint { margin: 0; font-size: .75rem; color: rgba(255, 255, 255, .5); }

/* ================= CAPAS (carta / foto) ================= */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(10, 2, 14, .82);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  opacity: 0;
  visibility: hidden;
  transition: opacity .4s ease, visibility 0s linear .4s;
}
.overlay.open { opacity: 1; visibility: visible; transition: opacity .4s ease; }

/* ---------- Sobre ---------- */
.envelope-wrap { grid-area: 1 / 1; display: flex; flex-direction: column; align-items: center; gap: 26px; }
.envelope-tip {
  margin: 0;
  font-family: "Caveat", cursive;
  font-size: 1.7rem;
  color: var(--pink-soft);
  animation: bob 1.8s ease-in-out infinite;
}
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }

.envelope {
  position: relative;
  width: min(82vw, 340px);
  aspect-ratio: 3 / 2;
  perspective: 900px;
  filter: drop-shadow(0 18px 30px rgba(0, 0, 0, .55));
}
.env-back, .env-front, .env-flap { position: absolute; inset: 0; border-radius: 10px; }
.env-back { background: #c2185b; z-index: 1; }
.env-paper {
  position: absolute;
  left: 6%; right: 6%; top: 8%; bottom: 6%;
  z-index: 2;
  display: grid;
  place-items: start center;
  padding-top: 12%;
  border-radius: 6px;
  background: var(--paper);
  color: var(--pink-deep);
  font: 700 1.8rem "Caveat", cursive;
}
.env-front {
  z-index: 3;
  background: linear-gradient(180deg, #ff7eb6, #f0569a);
  clip-path: polygon(0 0, 50% 56%, 100% 0, 100% 100%, 0 100%);
}
.env-flap {
  z-index: 4;
  background: linear-gradient(180deg, #ff9cc6, #ff6dab);
  clip-path: polygon(0 0, 100% 0, 50% 60%);
  transform-origin: 50% 0;
  backface-visibility: visible;
}
.env-seal {
  position: absolute;
  left: 50%; top: 55%;
  z-index: 5;
  width: 64px; height: 64px;
  margin: -32px 0 0 -32px;
  border: 0;
  border-radius: 50%;
  font-size: 30px;
  color: #fff;
  background: radial-gradient(circle at 35% 30%, #ff4d6d, #a3003c);
  box-shadow: 0 4px 12px rgba(0, 0, 0, .45), 0 0 0 0 rgba(255, 77, 109, .7);
  animation: sealPulse 1.6s ease-in-out infinite;
}
@keyframes sealPulse {
  0%, 100% { box-shadow: 0 4px 12px rgba(0, 0, 0, .45), 0 0 0 0 rgba(255, 77, 109, .7); }
  50%      { box-shadow: 0 4px 12px rgba(0, 0, 0, .45), 0 0 0 16px rgba(255, 77, 109, 0); }
}

/* ---------- Carta abierta ---------- */
.letter-card {
  grid-area: 1 / 1;
  display: none;
  flex-direction: column;
  width: min(100%, 520px);
  max-height: min(86vh, 86dvh);
  border-radius: 14px;
  color: var(--ink);
  background:
    repeating-linear-gradient(transparent 0 2.05rem, rgba(216, 27, 114, .13) 2.05rem calc(2.05rem + 1px)),
    var(--paper);
  box-shadow: 0 24px 60px rgba(0, 0, 0, .6);
  overflow: hidden;
}
.letter-body {
  flex: 1;
  overflow-y: auto;
  padding: 30px 26px 10px;
  font: 500 1.5rem/2.05rem "Caveat", cursive;
  -webkit-overflow-scrolling: touch;
}
.letter-body p { margin: 0 0 2.05rem; }
.letter-body .saludo { font-weight: 700; font-size: 1.9rem; color: var(--pink-deep); }
.letter-body .despedida { margin-bottom: 0; text-align: right; }
.letter-body .firma { text-align: right; font-weight: 700; font-size: 2rem; color: var(--pink-deep); margin-bottom: 1rem; }
.close-letter { margin: 10px auto 18px; padding: 12px 22px; font-size: .95rem; flex: none; }

/* ---------- Foto en grande ---------- */
.lightbox { z-index: 30; cursor: zoom-out; }
.lightbox img {
  max-width: 100%;
  max-height: 86vh;
  border: 8px solid #fff;
  border-radius: 10px;
  box-shadow: 0 0 50px rgba(255, 95, 168, .6);
  transform: scale(.85);
  transition: transform .35s cubic-bezier(.2, 1.4, .4, 1);
}
.lightbox.open img { transform: scale(1); }
