/* ==========================================================================
   Carta nocturna que amanece
   La página empieza en la noche y termina en el amanecer: el fondo se va
   calentando a medida que avanza la historia.
   ✏️ Para cambiar la paleta, edita solo las variables de :root.
   ========================================================================== */

:root {
  /* Color */
  --night:   #17162b;   /* tinta de medianoche (portada)      */
  --plum:    #241f3d;   /* mitad de la carta                  */
  --dusk:    #3d2b4a;   /* final de la carta                  */
  --moon:    #f1e6e1;   /* texto principal                    */
  --moon-2:  #c9bcc4;   /* texto secundario                   */
  --rose:    #e7b7b1;   /* acento: rosa empolvado             */
  --candle:  #ebcb93;   /* acento cálido del final            */
  --dawn:    #f6dcd2;   /* fondo del amanecer                 */
  --ink:     #3a2433;   /* texto sobre el amanecer            */

  /* Tipografía */
  --display: "Bodoni Moda", "Didot", "Bodoni 72", Georgia, serif;
  --hand:    "Caveat", "Bradley Hand", "Segoe Print", cursive;
  --text:    "Newsreader", "Iowan Old Style", Georgia, serif;

  /* Escala (base 18px, razón ~1.25) */
  --fs-small: 0.889rem;
  --fs-body:  1.125rem;
  --fs-lead:  1.375rem;
  --fs-h2:    clamp(2rem, 8.5vw, 2.75rem);
  --fs-hero:  clamp(3.5rem, 19vw, 6.5rem);

  /* Espacio */
  --gutter: max(1.5rem, env(safe-area-inset-left), env(safe-area-inset-right));
  --measure: 34rem;

  /* Movimiento */
  --ease-out: cubic-bezier(0.22, 0.61, 0.36, 1);
  --reveal-time: 900ms;
}

/* ---------- Base ---------- */
*,
*::before,
*::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
  background: var(--night);
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;              /* sin scroll horizontal */
  color: var(--moon);
  font-family: var(--text);
  font-size: var(--fs-body);
  font-weight: 300;
  line-height: 1.7;
  font-optical-sizing: auto;
  -webkit-font-smoothing: antialiased;
  /* Degradado que recorre todo el documento: noche → ciruela → crepúsculo.
     Sin background-attachment: fixed (Safari iOS lo ignora y penaliza). */
  background: linear-gradient(180deg, var(--night) 0%, var(--plum) 45%, var(--dusk) 88%, #5a3a52 100%);
  -webkit-tap-highlight-color: transparent;
}

img { display: block; max-width: 100%; height: auto; }

h1, h2 { margin: 0; font-weight: 400; }
p { margin: 0; }

a { color: inherit; }

:focus-visible {
  outline: 2px solid var(--rose);
  outline-offset: 4px;
  border-radius: 2px;
}

.skip-link {
  position: absolute;
  left: var(--gutter);
  top: calc(env(safe-area-inset-top) + 0.75rem);
  z-index: 10;
  padding: 0.5rem 0.9rem;
  background: var(--moon);
  color: var(--night);
  font-size: var(--fs-small);
  text-decoration: none;
  transform: translateY(-200%);
}
.skip-link:focus { transform: none; }

/* ==========================================================================
   Portada
   ========================================================================== */
.hero {
  position: relative;
  display: grid;
  min-height: 100vh;
  min-height: 100svh;              /* alto real en Safari iOS con la barra visible */
  padding:
    calc(env(safe-area-inset-top) + 3rem)
    var(--gutter)
    calc(env(safe-area-inset-bottom) + 2rem);
  grid-template-rows: 1fr auto;
  isolation: isolate;
}

/* Cielo: unas pocas estrellas estáticas, hechas con gradientes (sin imágenes) */
.hero__sky {
  position: absolute;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(1px 1px at 12% 18%, #fff8 50%, transparent 51%),
    radial-gradient(1px 1px at 78% 12%, #fff9 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 64% 30%, #fffa 50%, transparent 51%),
    radial-gradient(1px 1px at 30% 42%, #fff6 50%, transparent 51%),
    radial-gradient(1px 1px at 88% 48%, #fff7 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 22% 70%, #fff8 50%, transparent 51%),
    radial-gradient(1px 1px at 52% 64%, #fff5 50%, transparent 51%),
    radial-gradient(1px 1px at 70% 82%, #fff6 50%, transparent 51%),
    radial-gradient(60% 40% at 80% 0%, #e7b7b11f, transparent 70%);
}

.hero__inner {
  align-self: center;
  max-width: var(--measure);
}

.hero__date {
  font-style: italic;
  color: var(--moon-2);
  letter-spacing: 0.02em;
}

.hero__title {
  margin: 1.25rem 0 1.75rem;
  font-family: var(--display);
  font-size: var(--fs-hero);
  font-style: italic;
  line-height: 0.95;
  letter-spacing: -0.02em;
}
.hero__line { display: block; }
.hero__name {
  padding-left: 0.9em;             /* desplazamiento de carta escrita a mano */
  color: var(--rose);
}

.hero__lead {
  max-width: 20rem;
  font-size: var(--fs-lead);
  line-height: 1.45;
  color: var(--moon);
}

.hero__cue {
  justify-self: start;
  display: inline-flex;
  align-items: center;
  gap: 0.9rem;
  min-height: 44px;                /* área táctil mínima */
  font-size: var(--fs-small);
  font-style: italic;
  color: var(--moon-2);
  text-decoration: none;
}
.hero__cue-line {
  position: relative;
  width: 3.5rem;
  height: 1px;
  overflow: hidden;
  background: #ffffff26;
}
.hero__cue-line::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--rose);
  transform: translateX(-100%);
  animation: cue 2.8s var(--ease-out) 1.8s 3 forwards; /* tres pasadas y se detiene */
}
@keyframes cue {
  0%   { transform: translateX(-100%); }
  60%  { transform: translateX(0); }
  100% { transform: translateX(100%); }
}

/* Secuencia de entrada de la portada (solo CSS: funciona sin JavaScript) */
.hero__date,
.hero__line,
.hero__lead,
.hero__cue {
  animation: hero-in 1.2s var(--ease-out) both;
}
.hero__date        { animation-delay: 0.15s; }
.hero__line        { animation-delay: 0.35s; }
.hero__name        { animation-delay: 0.6s; }
.hero__lead        { animation-delay: 0.95s; }
.hero__cue         { animation-delay: 1.3s; }

@keyframes hero-in {
  from { opacity: 0; transform: translate3d(0, 18px, 0); }
  to   { opacity: 1; transform: none; }
}

/* ==========================================================================
   Carta
   ========================================================================== */
.letter {
  padding: 0 var(--gutter);
  outline: none;
}

.chapter {
  margin: 0 auto;
  max-width: 40rem;
  padding-block: clamp(4rem, 16vw, 7rem) 0;
}

.opening {
  max-width: var(--measure);
  padding-top: 2rem;
  font-family: var(--display);
  font-size: var(--fs-lead);
  font-style: italic;
  line-height: 1.5;
}

.chapter__head {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  margin-bottom: 1.75rem;
}
.chapter__num {
  min-width: 2.2ch;
  font-family: var(--display);
  font-size: 1.25rem;
  font-style: italic;
  color: var(--rose);
}
.chapter__head h2 {
  font-family: var(--display);
  font-size: var(--fs-h2);
  line-height: 1.1;
  letter-spacing: -0.01em;
}

.prose {
  max-width: var(--measure);
  padding-left: calc(2.2ch + 1rem); /* alineado con el título, no con el número */
}
.prose p + p { margin-top: 1.1em; }
.prose--flush {
  margin-top: 1.5rem;
  padding-left: 0;
}

/* ---------- Fotografías y vídeos: marco tipo polaroid ----------
   La imagen nunca se recorta: conserva su proporción natural (width/height
   del HTML reservan el espacio y evitan saltos de diseño).
   Tres transformaciones independientes que no se pisan:
   · transform → aparición (reveal)   · rotate → inclinación del marco
   · translate → parallax (script.js) */
.photo {
  --paper: #f8f2ea;
  margin: clamp(3rem, 12vw, 5rem) 0 0;
  padding: 3.5% 3.5% 0;
  background: var(--paper);
  border-radius: 2px;
  box-shadow:
    0 1px 2px #0000004d,
    0 24px 48px -22px #000000b3;
  will-change: transform;
}
.photo img,
.photo__video {
  display: block;
  width: 100%;
  height: auto;
  background: #e9e0d6;             /* tono mientras carga */
}
/* Vídeo: object-fit solo por si el aspect-ratio no coincide exactamente */
.photo__video { object-fit: cover; }

/* Pie escrito a mano en el borde inferior ancho */
.photo figcaption {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 4.25rem;
  padding: 0.6rem 0.5rem 0.75rem;
  font-family: var(--hand);
  font-size: 1.375rem;
  font-weight: 500;
  line-height: 1.3;
  color: var(--ink);
  text-align: center;
  text-wrap: balance;
}

/* Verticales: no ocupan todo el ancho y se alternan a un lado y al otro */
.photo--left,
.photo--right { width: 80%; }
.photo--left  { rotate: -1.6deg; }
.photo--right { margin-left: auto; rotate: 1.4deg; }
.photo--wide  { rotate: -0.7deg; }

/* Cita */
.quote {
  margin: clamp(5rem, 20vw, 8rem) auto 0;
  max-width: 22rem;
  text-align: center;
}
.quote p {
  font-family: var(--display);
  font-size: clamp(1.6rem, 7vw, 2.1rem);
  font-style: italic;
  line-height: 1.3;
  color: var(--rose);
  text-wrap: balance;
}

/* ==========================================================================
   Final: el amanecer
   ========================================================================== */
.finale {
  margin-top: clamp(6rem, 24vw, 10rem);
  padding:
    clamp(6rem, 26vw, 9rem)
    var(--gutter)
    calc(env(safe-area-inset-bottom) + 4rem);
  color: var(--ink);
  background: linear-gradient(180deg, #5a3a5200 0%, #c4939a 16%, #e9c3b9 30%, var(--dawn) 46%);
  text-align: center;
}
.finale__inner {
  max-width: 24rem;
  margin: 0 auto;
}

.finale__heart {
  display: block;
  width: 5.5rem;
  margin: 0 auto 2.5rem;
  overflow: visible;
}
.finale__heart path {
  fill: none;
  stroke: var(--ink);
  stroke-width: 1.1;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.finale__text {
  margin-bottom: 2.5rem;
  text-align: left;
  line-height: 1.7;
}

.finale__title {
  font-family: var(--display);
  font-size: clamp(2rem, 9vw, 2.6rem);
  font-style: italic;
  line-height: 1.15;
  text-wrap: balance;
}
.finale__sign {
  margin-top: 1.75rem;
  font-style: italic;
}
.finale__sign span {
  display: block;
  margin-top: 0.25rem;
  font-family: var(--display);
  font-size: 1.5rem;
}

.finale__again {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  margin-top: 3.5rem;
  padding: 0 1.25rem;
  border: 1px solid #3a243359;
  border-radius: 999px;
  font-size: var(--fs-small);
  text-decoration: none;
  transition: background-color 0.3s ease;
}
.finale__again:hover,
.finale__again:active { background-color: #3a24330f; }
.finale :focus-visible { outline-color: var(--ink); }

/* ---------- Guardar en el celular ---------- */
.save {
  margin-top: 4rem;
  padding-top: 2.5rem;
  border-top: 1px solid #3a243326;
}
.save__title {
  margin: 0 0 1.25rem;
  font-family: var(--hand);
  font-size: 1.75rem;
  font-weight: 500;
  line-height: 1.3;
}
.save__button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 1.75rem;
  border: 0;
  border-radius: 999px;
  background: var(--ink);
  color: var(--dawn);
  font: 400 1.0625rem/1 var(--text);
  letter-spacing: 0.01em;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  transition: transform 0.2s var(--ease-out), background-color 0.2s ease;
}
.save__button:active { transform: scale(0.97); }
.save__button[aria-expanded="true"] { background: #4d3043; }

.save__help {
  margin: 1.25rem auto 0;
  padding: 1.1rem 1.25rem;
  max-width: 20rem;
  background: #fffaf6;
  border-radius: 4px;
  box-shadow: 0 10px 30px -18px #3a243380;
  text-align: left;
  font-size: 1rem;
  line-height: 1.55;
}
.save__steps { margin: 0; padding-left: 1.25rem; }
p.save__steps { padding-left: 0; }
.save__steps li + li { margin-top: 0.5rem; }
.save__icon {
  display: inline-block;
  width: 0.95em;
  height: 1.1em;
  margin: 0 0.15em;
  vertical-align: -0.15em;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.save__status {
  min-height: 1.5em;
  margin-top: 0.85rem;
  font-size: var(--fs-small);
  font-style: italic;
}
.save__download {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  margin-top: 0.5rem;
  font-size: 1rem;
  text-decoration: underline;
  text-underline-offset: 0.25em;
  text-decoration-thickness: 1px;
}
.save__note {
  max-width: 18rem;
  margin: 0.25rem auto 0;
  font-size: var(--fs-small);
  line-height: 1.5;
  color: var(--ink);
}

/* ==========================================================================
   Apariciones (solo si script.js cargó: sin JS todo queda visible)
   ========================================================================== */
.reveal-ready .reveal {
  opacity: 0;
  transform: translate3d(0, 28px, 0);
  transition:
    opacity var(--reveal-time) var(--ease-out),
    transform var(--reveal-time) var(--ease-out);
  transition-delay: var(--delay, 0ms);
}
.reveal-ready .reveal.is-visible {
  opacity: 1;
  transform: none;
}
/* Las fotos suben un poco más lento que el texto: se sienten más pesadas */
.reveal-ready .photo.reveal { --reveal-time: 1000ms; transform: translate3d(0, 40px, 0); }
.reveal-ready .photo.reveal.is-visible { transform: none; }

/* Corazón: se dibuja con una sola línea al llegar al final */
.reveal-ready .finale__heart path {
  stroke-dasharray: var(--len, 400);
  stroke-dashoffset: var(--len, 400);
}
.reveal-ready .finale.is-visible .finale__heart path {
  transition: stroke-dashoffset 2.6s cubic-bezier(0.65, 0, 0.35, 1) 0.2s;
  stroke-dashoffset: 0;
}

/* ==========================================================================
   Movimiento reducido: sin desplazamientos, solo un fundido breve
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }

  .hero__date, .hero__line, .hero__lead, .hero__cue { animation: none; }
  .hero__cue-line::after { animation: none; transform: none; }

  .reveal-ready .reveal,
  .reveal-ready .photo.reveal {
    transform: none;
    transition: opacity 400ms linear;
    transition-delay: 0ms;
  }
  .reveal-ready .finale__heart path { stroke-dashoffset: 0; transition: none; }
  .photo { will-change: auto; translate: none !important; }
}

/* Pantallas más anchas (tablet / escritorio): un poco más de aire */
@media (min-width: 768px) {
  :root { --fs-body: 1.1875rem; }
  .photo--left, .photo--right { width: 64%; }
}
