:root {
  --bg: #fdf1f3;
  --bg-2: #f9dfe5;
  --ink: #3d2a30;
  --muted: #8a6b73;
  --accent: #c2185b;
  --heart: #e88aa4;

  --paper: #fffaf0;
  --paper-ink: #3a2a2e;
  --paper-accent: #b0174f;

  --script: "Dancing Script", "Brush Script MT", cursive;
  --serif: "Lora", Georgia, serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #23161b;
    --bg-2: #341f27;
    --ink: #f6e6ea;
    --muted: #c9a8b1;
    --accent: #f06292;
    --heart: #8e3b55;
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--serif);
  color: var(--ink);
  background: radial-gradient(circle at 20% 0%, var(--bg-2), var(--bg) 60%) fixed;
  line-height: 1.6;
}

main {
  position: relative;
  z-index: 1;
  max-width: 720px;
  min-height: 100vh;
  margin: 0 auto;
  padding: 3rem 16px 4rem;
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 1.75rem;
}

/* ---------- Corazones flotantes ---------- */

.hearts {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 0;
}

.hearts span {
  position: absolute;
  bottom: -40px;
  color: var(--heart);
  opacity: 0;
  animation: float linear infinite;
}

@keyframes float {
  0%   { transform: translateY(0) rotate(0deg); opacity: 0; }
  10%  { opacity: 0.6; }
  100% { transform: translateY(-110vh) rotate(25deg); opacity: 0; }
}

/* ---------- Sobre ---------- */

.intro {
  display: grid;
  justify-items: center;
  gap: 1.25rem;
  transition: opacity 0.4s, transform 0.4s;
}

.intro.gone {
  opacity: 0;
  transform: translateY(20px);
}

.envelope {
  position: relative;
  width: min(380px, calc(100vw - 32px));
  aspect-ratio: 3 / 2;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: #f6d5dd;
  font: inherit;
  cursor: pointer;
  perspective: 900px;
  box-shadow: 0 24px 50px -20px rgba(120, 30, 60, 0.55);
  animation: bob 3s ease-in-out infinite;
}

.envelope::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background:
    linear-gradient(to top right, #efc3ce 50%, transparent 50.5%) left / 50% 100% no-repeat,
    linear-gradient(to top left,  #efc3ce 50%, transparent 50.5%) right / 50% 100% no-repeat;
}

.envelope:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 50%, transparent);
  outline-offset: 6px;
}

.flap {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 58%;
  background: #eab0bf;
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  border-radius: 8px 8px 0 0;
  transform-origin: top;
  transition: transform 0.7s ease;
  z-index: 2;
}

.seal {
  position: absolute;
  top: 58%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 3;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 1.6rem;
  color: #fff;
  background: radial-gradient(circle at 35% 30%, #e0457b, #a3134c);
  box-shadow: 0 3px 8px rgba(80, 10, 30, 0.35);
  transition: opacity 0.3s;
}

.envelope-to {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 12%;
  z-index: 1;
  text-align: center;
  font-family: var(--script);
  font-size: 1.7rem;
  font-weight: 700;
  color: #7a1f3d;
}

.envelope.open { animation: none; }
.envelope.open .flap { transform: rotateX(180deg); }
.envelope.open .seal { opacity: 0; }

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

.hint {
  margin: 0;
  color: var(--muted);
  font-style: italic;
}

/* ---------- La carta ---------- */

.letter {
  position: relative;
  width: 100%;
  background: var(--paper);
  color: var(--paper-ink);
  border-radius: 6px;
  padding: clamp(2rem, 6vw, 3.5rem);
  box-shadow:
    0 1px 2px rgba(60, 20, 30, 0.08),
    0 18px 40px -18px rgba(120, 30, 60, 0.35);
  animation: rise 0.8s ease-out both;
}

.letter:focus { outline: none; }

.letter::after {
  content: "";
  position: absolute;
  inset: 10px;
  border: 1px solid rgba(194, 24, 91, 0.15);
  border-radius: 3px;
  pointer-events: none;
}

.letter p { margin: 0; }

.letter-date {
  text-align: right;
  font-style: italic;
  font-size: 0.9rem;
  color: #8a6b73;
}

.letter-to {
  font-family: var(--script);
  font-size: 2.2rem;
  font-weight: 700;
  line-height: 1.2;
  color: var(--paper-accent);
  margin: 1.25rem 0 1.25rem;
}

.letter-body {
  display: grid;
  gap: 1.1rem;
  font-size: 1.08rem;
  line-height: 1.9;
  overflow-wrap: anywhere;
}

.letter-closing {
  margin-top: 1.25rem !important;
  text-align: center;
  font-family: var(--script);
  font-size: 1.7rem;
  line-height: 1.4;
  color: var(--paper-accent);
}

.letter-sign {
  margin-top: 2.25rem !important;
  font-style: italic;
  text-align: right;
}

.letter-from {
  font-family: var(--script);
  font-size: 2rem;
  font-weight: 700;
  text-align: right;
  color: var(--paper-accent);
}

/* Los párrafos aparecen uno tras otro al abrir la carta. */
.letter .reveal {
  animation: fade-up 0.7s ease-out both;
  animation-delay: calc(min(var(--i, 0), 8) * 0.2s + 0.4s);
}

@keyframes rise {
  from { opacity: 0; transform: translateY(40px) scale(0.97); }
  to   { opacity: 1; transform: none; }
}

@keyframes fade-up {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

.close {
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  border-radius: 999px;
  padding: 0.6rem 1.3rem;
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--accent);
  transition: background 0.2s;
}

.close:hover { background: color-mix(in srgb, var(--accent) 10%, transparent); }

.close:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 40%, transparent);
  outline-offset: 2px;
}

/* ---------- Accesibilidad e impresión ---------- */

@media (prefers-reduced-motion: reduce) {
  .hearts { display: none; }
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}

@media print {
  body { background: none; }
  .hearts, .intro, .close { display: none !important; }
  main { display: block; min-height: 0; padding: 0; }
  .letter {
    display: block !important;
    box-shadow: none;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .letter, .letter .reveal { animation: none; }
}
