/* =========================================================================
   Un regalo que no entra en una caja
   -------------------------------------------------------------------------
   Los textos y las fotos NO se tocan acá: están todos en CONFIG (script.js).
   Este archivo es solamente el diseño.
   ========================================================================= */

/* ---------- Paleta y tokens ---------- */
:root {
  --crema:       #FBF6F0;
  --crema-hueco: #F4EAE0;
  --papel:       #FFFCF8;

  --tinta:       #2E2723;
  --tinta-media: #6B5C53;
  --tinta-suave: #9C8B80;

  --terracota:   #C4715A;
  --rose:        #E0A78F;
  --dorado:      #C4A053;
  --vino:        #7A3B4E;

  --noche:       #1C1411;
  --noche-2:     #2A1A1C;

  --linea:       rgba(46, 39, 35, .12);
  --sombra-suave: 0 10px 30px -18px rgba(46, 39, 35, .45);
  --sombra-media: 0 24px 60px -30px rgba(46, 39, 35, .55);

  --serif: "Fraunces", "Iowan Old Style", Georgia, "Times New Roman", serif;
  --sans:  "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  --ease:     cubic-bezier(.22, .61, .36, 1);
  --ease-out: cubic-bezier(.16, 1, .3, 1);
  --bounce:   cubic-bezier(.34, 1.56, .64, 1);

  --gutter: 26px;
  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;              /* el scroll vive dentro de cada capítulo */
  overscroll-behavior: none;
}

body {
  background: var(--crema);
  color: var(--tinta);
  font-family: var(--sans);
  font-weight: 300;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  text-rendering: optimizeLegibility;
}

/* Fondo cálido con dos luces muy tenues.
   Va dentro de un contenedor con overflow:hidden porque el elemento es más
   grande que la pantalla para poder derivar sin mostrar los bordes. */
.bg {
  position: fixed;
  inset: 0;
  z-index: -2;
  overflow: hidden;
}

.bg::before {
  content: "";
  position: absolute;
  inset: -20%;
  background:
    radial-gradient(48% 38% at 18% 8%,  rgba(224, 167, 143, .30), transparent 70%),
    radial-gradient(52% 42% at 88% 92%, rgba(196, 160, 83, .22),  transparent 72%),
    linear-gradient(170deg, #FDF9F5 0%, var(--crema) 45%, var(--crema-hueco) 100%);
  animation: drift 26s ease-in-out infinite alternate;
}

@keyframes drift {
  from { transform: translate3d(0, 0, 0) scale(1); }
  to   { transform: translate3d(-2.5%, 2%, 0) scale(1.06); }
}

/* Grano de papel */
.grain {
  position: fixed;
  inset: 0;
  z-index: 9;
  pointer-events: none;
  opacity: .5;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.28'/%3E%3C/svg%3E");
}

/* Canvas de confeti / destellos */
#fx {
  position: fixed;
  inset: 0;
  z-index: 60;
  pointer-events: none;
}

svg { width: 100%; height: 100%; display: block; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

.noscript {
  position: fixed; inset: 0; display: grid; place-items: center;
  padding: 40px; text-align: center; font-family: var(--serif); font-size: 20px;
  background: var(--crema); z-index: 999;
}

/* =========================================================================
   CAPÍTULOS
   ========================================================================= */
.chapter {
  position: fixed;
  inset: 0;
  z-index: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translate3d(0, 34px, 0) scale(.985);
  filter: blur(12px);
  transition:
    opacity .5s var(--ease),
    transform .7s var(--ease-out),
    filter .5s var(--ease),
    visibility 0s linear .7s;
}

.chapter.is-active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: none;
  filter: none;
  z-index: 2;
  transition-delay: 0s, 0s, 0s, 0s;
}

/* El capítulo que ya pasó se va hacia arriba, no hacia abajo */
.chapter.is-past { transform: translate3d(0, -34px, 0) scale(.985); }

.chapter__inner {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  /* "safe center": centra cuando entra en pantalla y, cuando no entra,
     arranca desde arriba en vez de dejar el principio fuera de alcance. */
  justify-content: safe center;
  gap: 18px;
  max-width: 720px;
  margin: 0 auto;
  padding:
    calc(var(--safe-top) + 74px)
    var(--gutter)
    calc(var(--safe-bottom) + 56px);
}

.chapter__inner.center { align-items: center; text-align: center; }
.chapter__inner.narrow { max-width: 560px; }

/* Aparición escalonada de los elementos del capítulo activo.
   Se usa animación (no transición) para no pisar las transiciones propias
   de cada componente: al terminar, cada elemento vuelve a sus reglas. */
[data-reveal],
[data-reveal-group] > * { opacity: 0; }

/* El estado final lo fija la clase, no la animación: si por lo que sea la
   animación no llegara a correr, el contenido igual se ve. */
[data-reveal].is-in,
[data-reveal-group] > .is-in {
  opacity: 1;
  animation: rise .85s var(--ease-out);
}

@keyframes rise {
  from { opacity: 0; transform: translate3d(0, 18px, 0); filter: blur(6px); }
  to   { opacity: 1; transform: none; filter: none; }
}

.is-booting .chapter { transition: none; }

/* =========================================================================
   TIPOGRAFÍA
   ========================================================================= */
.eyebrow {
  margin: 0;
  font-size: 11px;
  letter-spacing: .26em;
  text-transform: uppercase;
  color: var(--tinta-suave);
  font-weight: 400;
}
.eyebrow--light { color: rgba(255, 246, 238, .55); }

.title {
  margin: 0;
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(30px, 8.6vw, 44px);
  line-height: 1.12;
  letter-spacing: -.015em;
  font-variation-settings: "SOFT" 30, "opsz" 80;
}

.title--big { font-size: clamp(34px, 10vw, 54px); }

.title em { font-style: italic; color: var(--terracota); }

.lede {
  margin: 0;
  max-width: 44ch;
  color: var(--tinta-media);
  font-size: 15.5px;
  white-space: pre-line;   /* permite un salto de línea si el texto lo trae */
}

.prose { display: flex; flex-direction: column; gap: 16px; }

.prose p {
  margin: 0;
  font-size: 17px;
  line-height: 1.78;
  color: #40362F;
}

.prose p::first-letter { }

.sign {
  margin: 4px 0 0;
  font-family: var(--serif);
  font-style: italic;
  font-size: 19px;
  color: var(--terracota);
}

.hint {
  margin: 0;
  font-size: 12px;
  letter-spacing: .06em;
  color: var(--tinta-suave);
}

.fineprint {
  margin: 0;
  font-size: 11.5px;
  color: var(--tinta-suave);
  text-align: center;
  letter-spacing: .02em;
}

/* Portada */
.cover__hello {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(22px, 6.4vw, 30px);
  font-weight: 300;
  color: var(--tinta-media);
  letter-spacing: -.01em;
}

.cover__name {
  margin: 0;
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(50px, 17vw, 96px);
  line-height: .98;
  letter-spacing: -.035em;
  background: linear-gradient(160deg, var(--terracota) 8%, #B4544A 48%, var(--dorado) 108%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.cover__name .ltr {
  display: inline-block;
  opacity: 0;
  transform: translate3d(0, 26px, 0) rotate(3deg);
  filter: blur(10px);
  transition: opacity .9s var(--ease-out), transform 1s var(--ease-out), filter .9s var(--ease-out);
  transition-delay: var(--ld, 0ms);
}
.cover__name.is-in .ltr { opacity: 1; transform: none; filter: none; }
.cover__name .ltr--space { width: .3em; }

.cover__line {
  margin: 0;
  max-width: 30ch;
  color: var(--tinta-media);
  font-size: 15.5px;
}

.rule {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 140px;
  color: var(--rose);
}
.rule span { flex: 1; height: 1px; background: linear-gradient(90deg, transparent, var(--rose), transparent); }
.rule__heart { width: 14px; height: 14px; fill: var(--rose); stroke: none; }

/* =========================================================================
   BOTONES
   ========================================================================= */
.btn {
  align-self: center;
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 10px;
  padding: 15px 30px;
  border: 1px solid rgba(196, 113, 90, .38);
  border-radius: 999px;
  background: transparent;
  color: var(--terracota);
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 500;
  letter-spacing: .07em;
  text-transform: uppercase;
  cursor: pointer;
  overflow: hidden;
  transition: transform .35s var(--bounce), background .35s var(--ease), color .35s var(--ease), border-color .35s var(--ease), opacity .3s var(--ease);
}

.btn:active { transform: scale(.96); }

.btn--solid {
  border-color: transparent;
  background: linear-gradient(135deg, var(--terracota), #AE5A4C);
  color: #FFF6F0;
  box-shadow: 0 16px 34px -18px rgba(174, 90, 76, .9);
}

.btn--ghost {
  border-color: var(--linea);
  color: var(--tinta-media);
  text-transform: none;
  letter-spacing: .02em;
  font-size: 13.5px;
  padding: 12px 24px;
}

.btn--light {
  border-color: rgba(255, 246, 238, .28);
  color: rgba(255, 246, 238, .78);
}

.btn[disabled] { opacity: .3; pointer-events: none; }

/* Brillo que recorre el botón principal */
.btn--solid::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(105deg, transparent 38%, rgba(255, 255, 255, .42) 50%, transparent 62%);
  transform: translateX(-120%);
  animation: sheen 4.6s var(--ease) 1.6s infinite;
}
@keyframes sheen { 0% { transform: translateX(-120%); } 55%, 100% { transform: translateX(120%); } }

.btn--glow { animation: glow 3.4s ease-in-out infinite; }
@keyframes glow {
  0%, 100% { box-shadow: 0 16px 34px -18px rgba(174, 90, 76, .9), 0 0 0 0 rgba(196, 160, 83, .35); }
  50%      { box-shadow: 0 16px 34px -18px rgba(174, 90, 76, .9), 0 0 0 16px rgba(196, 160, 83, 0); }
}

/* Progreso y volver */
.progress {
  position: fixed;
  top: calc(var(--safe-top) + 20px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 40;
  display: flex;
  gap: 9px;
  padding: 8px 12px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .6s var(--ease);
}
.progress.is-visible { opacity: 1; pointer-events: auto; }

.dot {
  width: 7px; height: 7px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(46, 39, 35, .18);
  cursor: default;
  transition: all .45s var(--ease);
}
.dot.is-done { background: var(--rose); cursor: pointer; }
.dot.is-current { width: 22px; border-radius: 999px; background: var(--terracota); }

.back {
  position: fixed;
  top: calc(var(--safe-top) + 14px);
  left: 14px;
  z-index: 40;
  width: 40px; height: 40px;
  display: grid; place-items: center;
  padding: 11px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--tinta-suave);
  opacity: 0;
  pointer-events: none;
  cursor: pointer;
  transition: opacity .5s var(--ease);
}
.back.is-visible { opacity: 1; pointer-events: auto; }
.back:active { transform: scale(.9); }

/* =========================================================================
   3 · LOS 5 REGALOS
   ========================================================================= */
.gifts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 8px;
}

.gift {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1.04;
  padding: 16px;
  border: 0;
  border-radius: 18px;
  background:
    linear-gradient(150deg, var(--papel), #F6EDE4);
  box-shadow: var(--sombra-suave), inset 0 0 0 1px rgba(46, 39, 35, .06);
  cursor: pointer;
  overflow: hidden;
  text-align: left;
  font-family: var(--sans);
  transition: transform .5s var(--bounce), box-shadow .5s var(--ease);
}

.gift:active { transform: scale(.965); }

/* Cintas: la vertical es el span, la horizontal es el ::after de la caja */
.gift__ribbon {
  position: absolute;
  top: 0; bottom: 0;
  left: 50%;
  width: 16px;
  transform: translateX(-50%);
  background: linear-gradient(90deg, #B0604F, var(--terracota) 45%, #B0604F);
  opacity: .92;
  transform-origin: 50% 0;
  transition: opacity .5s var(--ease), transform .6s var(--ease);
}

.gift::after {
  content: "";
  position: absolute;
  left: 0; right: 0;
  top: 50%;
  height: 16px;
  transform: translateY(-50%);
  background: linear-gradient(180deg, #B0604F, var(--terracota) 45%, #B0604F);
  opacity: .92;
  transform-origin: 0 50%;
  transition: opacity .5s var(--ease), transform .6s var(--ease);
}

.gift__knot {
  position: absolute;
  top: 50%; left: 50%;
  width: 34px; height: 34px;
  transform: translate(-50%, -50%) rotate(45deg);
  border-radius: 10px;
  background: linear-gradient(135deg, var(--dorado), #A9863C);
  box-shadow: 0 4px 12px -4px rgba(46, 39, 35, .5);
  transition: transform .6s var(--bounce), opacity .5s var(--ease);
}

.gift__num {
  position: absolute;
  top: 12px; left: 14px;
  z-index: 2;
  font-family: var(--serif);
  font-size: 13px;
  letter-spacing: .12em;
  color: var(--tinta-suave);
}

.gift__label {
  position: absolute;
  inset: auto 14px 14px;
  z-index: 2;
  font-family: var(--serif);
  font-size: 15.5px;
  line-height: 1.25;
  color: var(--tinta);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .5s var(--ease) .1s, transform .5s var(--ease) .1s;
}

.gift__check {
  position: absolute;
  top: 10px; right: 12px;
  z-index: 2;
  width: 16px; height: 16px;
  fill: var(--rose);
  stroke: none;
  opacity: 0;
  transform: scale(.4);
  transition: opacity .4s var(--ease) .2s, transform .5s var(--bounce) .2s;
}

/* Estado abierto */
.gift.is-open { background: linear-gradient(150deg, #FFFDFB, #F1E4D8); }
.gift.is-open .gift__ribbon { opacity: 0; transform: translateX(-50%) scaleY(0); }
.gift.is-open::after { opacity: 0; transform: translateY(-50%) scaleX(0); }
.gift.is-open .gift__knot { opacity: 0; transform: translate(-50%, -140%) rotate(180deg) scale(.4); }
.gift.is-open .gift__label { opacity: 1; transform: none; }
.gift.is-open .gift__check { opacity: 1; transform: none; }

.gate { display: flex; flex-direction: column; align-items: center; gap: 2px; margin-top: 6px; }

.counter {
  margin: 0;
  font-size: 12px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--tinta-suave);
  transition: color .4s var(--ease);
}
.counter.is-complete { color: var(--terracota); }

/* Tarjeta modal del regalo */
.modal {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  place-items: center;
  padding: var(--gutter);
  visibility: hidden;
  opacity: 0;
  transition: opacity .35s var(--ease), visibility 0s linear .35s;
}
.modal.is-open { visibility: visible; opacity: 1; transition-delay: 0s; }

.modal__scrim {
  position: absolute;
  inset: 0;
  background: rgba(40, 30, 26, .46);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.modal__card {
  position: relative;
  width: 100%;
  max-width: 400px;
  max-height: 86vh;
  overflow-y: auto;
  padding: 30px 26px 26px;
  border-radius: 24px;
  background: linear-gradient(165deg, var(--papel), #F7EFE6);
  box-shadow: var(--sombra-media);
  text-align: center;
  transform: scale(.9) translateY(18px);
  opacity: 0;
  transition: transform .5s var(--bounce), opacity .35s var(--ease);
}
.modal.is-open .modal__card { transform: none; opacity: 1; }

.modal__close {
  position: absolute;
  top: 12px; right: 12px;
  width: 34px; height: 34px;
  display: grid; place-items: center;
  padding: 9px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--tinta-suave);
  cursor: pointer;
}

.modal__media {
  width: 100%;
  aspect-ratio: 4 / 3;
  margin-bottom: 20px;
  border-radius: 16px;
  overflow: hidden;
  background: linear-gradient(140deg, var(--rose), var(--dorado));
  display: none;
}
.modal__media.has-image { display: block; }
.modal__media img { width: 100%; height: 100%; object-fit: cover; display: block; }

.modal__index {
  margin: 0 0 8px;
  font-size: 11px;
  letter-spacing: .26em;
  text-transform: uppercase;
  color: var(--tinta-suave);
}

.modal__title {
  margin: 0 0 12px;
  font-family: var(--serif);
  font-weight: 400;
  font-size: 27px;
  line-height: 1.2;
  letter-spacing: -.01em;
}

.modal__text {
  margin: 0 0 6px;
  font-size: 16px;
  line-height: 1.75;
  color: #463B34;
}

/* =========================================================================
   4 · CUPONES
   ========================================================================= */
/* Con solo dos vales, van uno arriba del otro y más grandes: el doble de
   protagonismo que tenían cuando eran cuatro. */
.tickets { display: flex; flex-direction: column; gap: 20px; margin-top: 10px; }

.ticket {
  position: relative;
  display: flex;
  align-items: stretch;
  min-height: 140px;
  border-radius: 18px;
  background: var(--papel);
  box-shadow: var(--sombra-media), inset 0 0 0 1px rgba(46, 39, 35, .07);
  overflow: hidden;
  transition: transform .5s var(--ease), filter .6s var(--ease), opacity .6s var(--ease);
}

/* Troquel: los dos semicírculos del papel */
.ticket::before, .ticket::after {
  content: "";
  position: absolute;
  left: 91px;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--crema);
  box-shadow: inset 0 0 0 1px rgba(46, 39, 35, .07);
  z-index: 2;
}
.ticket::before { top: -11px; }
.ticket::after  { bottom: -11px; }

.ticket__stub {
  position: relative;
  flex: 0 0 102px;
  display: grid;
  place-items: center;
  border-right: 2px dashed rgba(46, 39, 35, .16);
  background: linear-gradient(160deg, rgba(224, 167, 143, .20), rgba(196, 160, 83, .14));
  color: var(--terracota);
}
.ticket__icon { width: 34px; height: 34px; }

.ticket__body {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 6px;
  padding: 20px 22px 20px 24px;
  min-width: 0;
}

.ticket__kicker {
  font-size: 11px;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--tinta-suave);
}

.ticket__title {
  margin: 0;
  font-family: var(--serif);
  font-weight: 400;
  font-size: 24px;
  line-height: 1.22;
  letter-spacing: -.01em;
}

.ticket__detail {
  margin: 0;
  font-size: 14.5px;
  color: var(--tinta-media);
}

.ticket__claim {
  align-self: flex-start;
  margin-top: 10px;
  padding: 9px 19px;
  border: 1px solid rgba(196, 113, 90, .35);
  border-radius: 999px;
  background: transparent;
  color: var(--terracota);
  font-family: var(--sans);
  font-size: 12.5px;
  font-weight: 500;
  letter-spacing: .08em;
  text-transform: uppercase;
  cursor: pointer;
  transition: transform .3s var(--bounce), opacity .3s var(--ease);
}
.ticket__claim:active { transform: scale(.94); }

/* Sello */
.ticket__stamp {
  position: absolute;
  top: 50%; right: 20px;
  z-index: 3;
  padding: 9px 16px;
  border: 2px solid var(--vino);
  border-radius: 7px;
  color: var(--vino);
  font-size: 12.5px;
  font-weight: 500;
  letter-spacing: .14em;
  text-transform: uppercase;
  white-space: nowrap;
  opacity: 0;
  transform: translateY(-50%) rotate(-13deg) scale(2.2);
  pointer-events: none;
}

.ticket.is-claimed { filter: saturate(.72); }
.ticket.is-claimed .ticket__claim { opacity: 0; pointer-events: none; }
.ticket.is-claimed .ticket__title { color: var(--tinta-media); }
.ticket.is-claimed .ticket__stamp { animation: stamp .55s var(--ease-out) forwards; }

@keyframes stamp {
  0%   { opacity: 0; transform: translateY(-50%) rotate(-13deg) scale(2.2); }
  60%  { opacity: 1; transform: translateY(-50%) rotate(-13deg) scale(.92); }
  100% { opacity: .9; transform: translateY(-50%) rotate(-13deg) scale(1); }
}

/* =========================================================================
   5 · MEMORIA (juego)
   ========================================================================= */
.memory {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin: 10px 0 2px;
}

.memory__card {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 3 / 4;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
}

/* Giro de la carta con transformaciones 2D (scaleX), no 3D: un giro real
   (perspective + transform-style: preserve-3d) se rompe en Safari/iOS
   cuando vive dentro de un ancestro que anima "filter" —como el blur de
   entrada de cada capítulo—, y las cartas quedan invisibles. Este truco
   se ve prácticamente igual y funciona en cualquier navegador. */
.memory__face {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: 12px;
  box-shadow: var(--sombra-suave), inset 0 0 0 1px rgba(46, 39, 35, .07);
  transition: transform .4s var(--ease-out), opacity .25s var(--ease);
}

.memory__face--back { background: linear-gradient(150deg, var(--papel), #F1E4D8); }

.memory__face--back::after {
  content: "";
  width: 22%;
  aspect-ratio: 1;
  border: 1.5px solid rgba(196, 113, 90, .32);
  border-radius: 50%;
}

.memory__face--front {
  background: linear-gradient(150deg, #FFFDFB, #F6EDE4);
  color: var(--terracota);
  opacity: 0;
  transform: scaleX(0);
}

.memory__card.is-flipped .memory__face--back,
.memory__card.is-matched .memory__face--back {
  opacity: 0;
  transform: scaleX(0);
  transition-delay: 0s;
}

.memory__card.is-flipped .memory__face--front,
.memory__card.is-matched .memory__face--front {
  opacity: 1;
  transform: scaleX(1);
  transition-delay: .18s;
}

.memory__icon { width: 32%; height: 32%; }

.memory__card.is-matched .memory__face--front { color: var(--dorado); }
.memory__card.is-matched { opacity: .85; }

@media (min-width: 700px) {
  /* .memory es hijo de un flex container en columna (.chapter__inner):
     con "margin: auto" para centrarlo, un ancho "auto" no se estira solo
     (el spec anula el stretch cuando hay márgenes auto en el eje cruzado)
     y colapsa a su contenido. Por eso acá va un ancho fijo, no max-width. */
  .memory { width: 380px; margin-left: auto; margin-right: auto; }
}

/* =========================================================================
   6 · FOTOS
   ========================================================================= */
/* Cuatro fotos en mosaico: la 1 alta a la izquierda, la 2 y la 3 apiladas a su
   derecha, la 4 ancha abajo. Compacto a propósito, para que el botón de
   "Seguir" entre en pantalla sin tener que buscarlo. */
.collage {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 6px;
}

.collage .photo:nth-child(1) { grid-row: span 2; }
.collage .photo:nth-child(4) { grid-column: 1 / -1; }

.photo {
  position: relative;
  display: block;
  width: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 14px;
  aspect-ratio: var(--ratio, 4 / 5);
  background: linear-gradient(140deg, var(--rose), #D9B98A);
  box-shadow: var(--sombra-suave);
  overflow: hidden;
  cursor: pointer;
  opacity: 0;
  transform: translate3d(0, 26px, 0) scale(.96);
  transition: opacity .8s var(--ease-out), transform .9s var(--ease-out);
  transition-delay: var(--d, 0ms);
}
.photo.is-in { opacity: 1; transform: rotate(var(--tilt, 0deg)); }
.photo:active { transform: rotate(var(--tilt, 0deg)) scale(.97); }

.photo img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.photo::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, transparent 58%, rgba(46, 39, 35, .22));
  opacity: 0;
  transition: opacity .4s var(--ease);
}

/* Placeholder cuando la foto todavía no existe en /assets */
.photo.is-empty { display: grid; place-items: center; }
.photo.is-empty::before {
  content: attr(data-empty);
  font-family: var(--serif);
  font-size: 13px;
  letter-spacing: .08em;
  color: rgba(255, 252, 248, .9);
}

/* Visor */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(24, 17, 14, .94);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  opacity: 0;
  visibility: hidden;
  transition: opacity .35s var(--ease), visibility 0s linear .35s;
}
.lightbox.is-open { opacity: 1; visibility: visible; transition-delay: 0s; }

.lightbox__figure {
  margin: 0;
  max-width: 100%;
  transform: scale(.94);
  opacity: 0;
  transition: transform .45s var(--ease-out), opacity .35s var(--ease);
}
.lightbox.is-open .lightbox__figure { transform: none; opacity: 1; }

.lightbox__figure img {
  display: block;
  max-width: 100%;
  max-height: 76vh;
  border-radius: 10px;
  object-fit: contain;
}

.lightbox__figure figcaption {
  margin-top: 14px;
  text-align: center;
  font-family: var(--serif);
  font-style: italic;
  font-size: 15px;
  color: rgba(255, 246, 238, .72);
}

.lightbox__close {
  position: absolute;
  top: calc(var(--safe-top) + 12px);
  right: 12px;
  width: 42px; height: 42px;
  display: grid; place-items: center;
  padding: 12px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 246, 238, .1);
  color: rgba(255, 246, 238, .85);
  cursor: pointer;
}

.lightbox__nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 44px; height: 44px;
  display: grid; place-items: center;
  padding: 13px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 246, 238, .08);
  color: rgba(255, 246, 238, .8);
  cursor: pointer;
}
.lightbox__nav--prev { left: 8px; }
.lightbox__nav--next { right: 8px; }

/* =========================================================================
   6 · REVELACIÓN FINAL
   ========================================================================= */
.chapter--last .title--big em { display: block; }

.finale {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  flex-direction: column;
  align-items: center;
  /* "safe center": si el texto final es largo, no se recorta el principio */
  justify-content: safe center;
  padding: calc(var(--safe-top) + 40px) var(--gutter) calc(var(--safe-bottom) + 40px);
  overflow-y: auto;
  background:
    radial-gradient(58% 44% at 50% 22%, rgba(122, 59, 78, .55), transparent 72%),
    linear-gradient(170deg, var(--noche-2), var(--noche) 62%);
  color: #FFF6EE;
  visibility: hidden;
  clip-path: circle(0% at var(--ox, 50%) var(--oy, 88%));
  transition: clip-path 1s var(--ease-out), visibility 0s linear 1s;
}
.finale.is-open { visibility: visible; clip-path: circle(150% at var(--ox, 50%) var(--oy, 88%)); transition-delay: 0s; }

.finale__glow {
  position: absolute;
  top: 50%; left: 50%;
  width: 420px; height: 420px;
  transform: translate(-50%, -50%) scale(.2);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(232, 195, 124, .55), rgba(232, 195, 124, .08) 46%, transparent 68%);
  opacity: 0;
  pointer-events: none;
  transition: opacity 1.1s var(--ease), transform 1.4s var(--ease-out);
}
.finale.is-lit .finale__glow { opacity: 1; transform: translate(-50%, -50%) scale(1); }

/* El corazón que se dibuja solo */
.finale__seal {
  width: 92px;
  height: 84px;
  margin-bottom: 16px;
  color: #E8C37C;
  filter: drop-shadow(0 0 14px rgba(232, 195, 124, .45));
}

.seal__path {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
}

.finale.is-lit .seal__path { animation: draw 1.6s var(--ease-out); }
.finale.is-revealed .seal__path { stroke-dashoffset: 0; }

@keyframes draw { from { stroke-dashoffset: 1; } to { stroke-dashoffset: 0; } }

.finale.is-revealed .finale__seal { animation: latir 3.6s var(--ease) 1.2s infinite; }
@keyframes latir {
  0%, 100% { transform: scale(1); }
  46%      { transform: scale(1.055); }
}

.finale__content {
  position: relative;
  z-index: 3;
  max-width: 440px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  opacity: 0;
  transition: opacity .8s var(--ease-out);
}
.finale.is-open .finale__content { opacity: 1; }

/* Las palabras llegan después del corazón */
.finale__words {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(22px);
  filter: blur(10px);
  transition: opacity 1s var(--ease-out), transform 1.1s var(--ease-out), filter 1s var(--ease-out);
}
.finale.is-revealed .finale__words { opacity: 1; transform: none; filter: none; pointer-events: auto; }

.finale__title {
  margin: 0;
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(30px, 8.6vw, 42px);
  line-height: 1.14;
  letter-spacing: -.02em;
  background: linear-gradient(150deg, #FFE9CF, var(--dorado) 92%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.finale__prose { display: flex; flex-direction: column; gap: 14px; }
.finale__prose p {
  margin: 0;
  font-size: 16.5px;
  line-height: 1.8;
  color: rgba(255, 246, 238, .86);
}

.finale__sign {
  margin: 0;
  font-family: var(--serif);
  font-style: italic;
  font-size: 18px;
  color: rgba(232, 195, 124, .9);
}

/* =========================================================================
   Pantallas grandes: el regalo sigue siendo el mismo, con más aire
   ========================================================================= */
@media (min-width: 700px) {
  :root { --gutter: 40px; }
  .gifts { grid-template-columns: repeat(3, 1fr); }
  .collage { gap: 14px; }
}

@media (min-height: 720px) {
  .chapter__inner { gap: 22px; }
}

/* ---------- Respeto por quien prefiere menos movimiento ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .18s !important;
    scroll-behavior: auto !important;
  }
  .chapter { filter: none; transform: none; }
  [data-reveal], .photo { filter: none; transform: none; }
  .finale { clip-path: none; }
}
