* {
  box-sizing: border-box;
}

:root {
  --bg: #090b16;
  --text: #f7f3f4;
  --muted: #b9b1b8;
  --line: rgba(255,255,255,.13);
  --glass: rgba(18,20,34,.72);
  --accent: #e8c6d4;
}

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, sans-serif;
}

body {
  min-height: 100vh;
  overflow: hidden;
  position: relative;
}

main {
  min-height: 100vh;
  position: relative;
  z-index: 2;
}

.screen {
  min-height: 100vh;
  width: 100%;
  display: none;
  place-items: center;
  padding: 28px 22px;
  text-align: center;
}

.screen.active {
  display: grid;
  animation: fadeIn .75s ease both;
}

#home, #ending {
  align-content: center;
}

.heart {
  font-family: Georgia, serif;
  font-size: 46px;
  color: var(--accent);
  margin-bottom: 12px;
  animation: float 3.5s ease-in-out infinite;
}

.heart.big {
  font-size: 64px;
}

.eyebrow {
  text-transform: lowercase;
  letter-spacing: .12em;
  font-size: 11px;
  color: var(--muted);
  margin: 0 0 16px;
}

h1, h2 {
  font-family: Caveat, cursive;
  font-weight: 500;
  line-height: .95;
  margin: 0;
}

h1 {
  font-size: clamp(48px, 13vw, 82px);
}

h2 {
  font-size: clamp(48px, 13vw, 78px);
}

.sub {
  color: var(--muted);
  font-size: 14px;
  margin: 24px 0 30px;
}

.main-btn, .ghost-btn {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 13px 22px;
  font: inherit;
  cursor: pointer;
  transition: transform .2s ease, background .2s ease, border-color .2s ease;
}

.main-btn {
  color: #17131a;
  background: var(--accent);
  border-color: transparent;
}

.main-btn:hover, .ghost-btn:hover {
  transform: translateY(-2px);
}

.main-btn:active, .ghost-btn:active {
  transform: scale(.97);
}

.ghost-btn {
  color: var(--text);
  background: rgba(255,255,255,.04);
}

.hint, .swipe-hint {
  color: #777581;
  font-size: 10px;
  margin-top: 24px;
}

#letter {
  display: none;
  grid-template-rows: auto auto 1fr auto auto;
  align-content: center;
  justify-items: center;
  gap: 12px;
}

#letter.active {
  display: grid;
}

.progress {
  width: min(360px, 78vw);
  height: 2px;
  background: rgba(255,255,255,.1);
  border-radius: 99px;
  overflow: hidden;
}

.progress span {
  display: block;
  height: 100%;
  width: 14.28%;
  background: var(--accent);
  transition: width .45s ease;
}

.page-number {
  color: #777581;
  font-size: 10px;
  margin: 0;
}

.letter-card {
  width: min(680px, 90vw);
  min-height: 330px;
  display: grid;
  place-items: center;
  align-content: center;
  padding: 34px 28px;
  background: linear-gradient(145deg, rgba(255,255,255,.055), rgba(255,255,255,.018));
  border: 1px solid var(--line);
  border-radius: 24px;
  backdrop-filter: blur(12px);
  box-shadow: 0 25px 70px rgba(0,0,0,.35);
}

.mini-heart {
  color: var(--accent);
  font-size: 22px;
  margin-bottom: 18px;
}

.letter-text {
  max-width: 590px;
  margin: 0;
  font-family: Caveat, cursive;
  font-size: clamp(29px, 6vw, 43px);
  line-height: 1.08;
}

.letter-text.typing {
  animation: textIn .45s ease both;
}

.controls {
  display: flex;
  gap: 10px;
  align-items: center;
}

.controls .ghost-btn {
  width: 46px;
  height: 46px;
  padding: 0;
}

.ending-text {
  max-width: 500px;
  color: var(--muted);
  line-height: 1.65;
  font-size: 14px;
  margin: 22px auto;
}

.signature {
  font-family: Caveat, cursive;
  font-size: 31px;
  color: var(--accent);
  margin: 0 0 25px;
}

.restart {
  font-size: 12px;
}

.stars, .stars::before, .stars::after {
  position: fixed;
  inset: 0;
  content: "";
  pointer-events: none;
}

.stars {
  opacity: .55;
  background-image:
    radial-gradient(circle at 15% 20%, rgba(255,255,255,.8) 0 1px, transparent 1.5px),
    radial-gradient(circle at 75% 30%, rgba(255,255,255,.55) 0 1px, transparent 1.5px),
    radial-gradient(circle at 35% 78%, rgba(255,255,255,.6) 0 1px, transparent 1.5px),
    radial-gradient(circle at 90% 82%, rgba(255,255,255,.5) 0 1px, transparent 1.5px);
  background-size: 180px 180px, 230px 230px, 260px 260px, 210px 210px;
  animation: drift 22s linear infinite;
}

.glow {
  position: fixed;
  width: 38vw;
  height: 38vw;
  max-width: 420px;
  max-height: 420px;
  border-radius: 50%;
  filter: blur(80px);
  opacity: .12;
  pointer-events: none;
}

.glow-one {
  background: #9d6c87;
  top: -15%;
  left: -10%;
}

.glow-two {
  background: #596f9e;
  right: -15%;
  bottom: -15%;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes textIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

@keyframes drift {
  from { transform: translateY(0); }
  to { transform: translateY(-35px); }
}

@media (max-height: 650px) {
  .letter-card { min-height: 250px; }
  .letter-text { font-size: clamp(25px, 5vw, 35px); }
}


/* ===== FINAL CINEMÁTICO ===== */
#ending {
  position: relative;
  overflow: hidden;
}

.final-content {
  position: relative;
  z-index: 5;
  max-width: 620px;
}

.final-heart {
  font-family: Georgia, serif;
  font-size: 76px;
  line-height: 1;
  color: var(--accent);
  opacity: 0;
  transform: scale(.35);
  animation: finalHeart 1.5s cubic-bezier(.2,.8,.2,1) .15s forwards,
             heartbeat 2.6s ease-in-out 1.8s infinite;
  text-shadow: 0 0 35px rgba(232,198,212,.28);
}

#ending.active .eyebrow {
  animation: finalUp .8s ease .65s both;
}

#ending.active h2 {
  animation: finalUp .9s cubic-bezier(.2,.8,.2,1) .85s both;
}

#ending.active .final-line {
  animation: lineGrow .8s ease 1.35s both;
}

#ending.active .ending-text {
  animation: finalUp .9s ease 1.55s both;
}

#ending.active .signature {
  animation: finalUp .8s ease 1.85s both;
}

#ending.active .final-small {
  animation: finalUp .8s ease 2.15s both;
}

#ending.active .restart {
  animation: finalUp .8s ease 2.45s both;
}

.final-line {
  width: 0;
  height: 1px;
  margin: 18px auto 0;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
}

.final-small {
  color: #85818a;
  font-size: 11px;
  line-height: 1.65;
  margin: 0 0 20px;
  opacity: 0;
}

#finalParticles {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 1;
}

.final-particle {
  position: absolute;
  left: 50%;
  top: 54%;
  color: var(--accent);
  font-family: Georgia, serif;
  font-size: 16px;
  opacity: 0;
  animation: particleFly var(--duration) ease-out var(--delay) forwards;
}

.final-star {
  position: absolute;
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: rgba(255,255,255,.8);
  opacity: 0;
  animation: starAppear 2.2s ease var(--delay) forwards;
}

@keyframes finalHeart {
  0% { opacity: 0; transform: scale(.35) rotate(-12deg); }
  60% { opacity: 1; transform: scale(1.12) rotate(4deg); }
  100% { opacity: 1; transform: scale(1) rotate(0); }
}

@keyframes heartbeat {
  0%, 100% { transform: scale(1); }
  8% { transform: scale(1.08); }
  16% { transform: scale(1); }
  24% { transform: scale(1.05); }
  32% { transform: scale(1); }
}

@keyframes finalUp {
  from { opacity: 0; transform: translateY(18px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes lineGrow {
  from { width: 0; opacity: 0; }
  to { width: min(230px, 55vw); opacity: 1; }
}

@keyframes particleFly {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(.4) rotate(0deg);
  }
  12% { opacity: .9; }
  100% {
    opacity: 0;
    transform: translate(calc(-50% + var(--x)), calc(-50% + var(--y)))
               scale(1.15) rotate(var(--r));
  }
}

@keyframes starAppear {
  0% { opacity: 0; transform: scale(.2); }
  35% { opacity: .8; transform: scale(1); }
  100% { opacity: 0; transform: scale(.2); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
  }
}
