/* ======================================================
   MIS XV AÑOS · LIBRO DIGITAL
   ------------------------------------------------------------
   Solo navegación. No toca colores, tipografías, flores,
   fotografía ni textos: reutiliza las hojas ya existentes.
   ====================================================== */

:root {
  /* Altura reservada para la barra de navegación, de modo que
     ningún botón tape el contenido de la hoja */
  --nav-h: 62px;
}

/* ======================================================
   1. ESTRUCTURA FIJA · la invitación ocupa la pantalla
   ====================================================== */
html,
body {
  height: 100%;
}

body {
  overflow: hidden;
  overscroll-behavior: none;
}

.invitation {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100svh;
  height: 100dvh;
  overflow: hidden;
}

.book {
  position: relative;
  width: 100%;
  height: 100%;
}

/* Escenario 3D: aporta la perspectiva de la hoja al girar */
.book__stage {
  position: absolute;
  inset: 0;
  perspective: 1500px;
  perspective-origin: 50% 46%;
  transform-style: preserve-3d;
  /* El gesto horizontal lo controla el JS; el vertical sigue
     desplazando el contenido de la hoja */
  touch-action: pan-y;
}

/* ======================================================
   2. HOJAS
   ====================================================== */
.page {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  /* Lomo a la izquierda: la hoja gira como en un libro */
  transform-origin: left center;
  transform-style: preserve-3d;
  background:
    radial-gradient(120% 58% at 50% 0%, rgba(150,80,112,.45) 0%, rgba(138,68,99,0) 62%),
    linear-gradient(180deg,
        rgba(155,81,115,.95) 0%,
        rgba(138,68,99,.93) 22%,
        rgba(138,68,99,.93) 78%,
        rgba(155,81,115,.95) 100%);
  transition: opacity .28s linear;
}

/* Hoja en reposo (la que se está leyendo) */
.page.is-active {
  z-index: 2;
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

/* Hoja de debajo: se ve únicamente mientras la de encima gira */
.page.is-under {
  z-index: 1;
  opacity: 1;
  visibility: visible;
  pointer-events: none;
  transition: none;
}

/* Hoja que gira */
.page.is-turning {
  z-index: 6;
  opacity: 1;
  visibility: visible;
  will-change: transform;
  transition: none;
}

/* Contenido de la hoja. Al girar más de 90° se oculta y deja
   ver el reverso del papel: es lo que da la sensación de hoja. */
.page__inner {
  position: relative;
  z-index: 2;
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  /* Espacio libre para que la barra de páginas no tape nada */
  padding-bottom: calc(var(--nav-h) + 24px);
}

/* Reverso del papel: sólo se ve al pasar de 90° */
.page__back {
  position: absolute;
  inset: 0;
  z-index: 1;
  transform: rotateY(180deg);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  background:
    linear-gradient(90deg, rgba(0, 0, 0, .34) 0%, rgba(0, 0, 0, .06) 22%, rgba(0, 0, 0, 0) 46%),
    linear-gradient(180deg, #9B5173 0%, #8A4463 26%, #8A4463 74%, #9B5173 100%);
  box-shadow: inset 0 0 74px rgba(0, 0, 0, .44);
  pointer-events: none;
}

/* Sombra de la hoja que gira, apoyada en su canto de paso */
.page__shade {
  position: absolute;
  inset: 0;
  z-index: 4;
  opacity: 0;
  background: linear-gradient(90deg,
      rgba(0, 0, 0, 0) 0%,
      rgba(0, 0, 0, .12) 34%,
      rgba(0, 0, 0, .55) 100%);
  pointer-events: none;
}

/* Sombra que la hoja proyecta sobre la página de debajo */
.page__cast {
  position: absolute;
  inset: 0;
  z-index: 3;
  opacity: 0;
  background: linear-gradient(90deg,
      rgba(0, 0, 0, .55) 0%,
      rgba(0, 0, 0, .16) 18%,
      rgba(0, 0, 0, 0) 42%);
  pointer-events: none;
}

/* ======================================================
   3. LOMO · costura dorada del libro
   ====================================================== */
.book__gutter {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 8;
  width: 22px;
  background:
    linear-gradient(90deg,
        rgba(0, 0, 0, .45) 0%,
        rgba(212, 175, 55, .12) 46%,
        rgba(212, 175, 55, 0) 100%);
  box-shadow: inset 1px 0 0 rgba(212, 175, 55, .3);
  pointer-events: none;
}

/* ======================================================
   4. NAVEGACIÓN · ← PÁGINA ANTERIOR / PÁGINA SIGUIENTE →
   ====================================================== */
.pager {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(16px, 6vw, 30px);
  height: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: linear-gradient(0deg, rgba(126,58,88,.82) 0%, rgba(126,58,88,.36) 58%, rgba(138,68,99,0) 100%);
}

.pager__btn {
  position: relative;
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  color: var(--gold);
  border: 1px solid var(--gold-soft);
  border-radius: 50%;
  background: rgba(112,48,78,.55);
  box-shadow: 0 6px 18px rgba(0, 0, 0, .34), inset 0 0 12px rgba(212, 175, 55, .07);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  transition: transform .3s ease, box-shadow .35s ease, color .35s ease, border-color .35s ease;
}

.pager__btn svg {
  width: 19px;
  height: 19px;
}

.pager__btn:hover,
.pager__btn:focus-visible {
  color: var(--gold-light);
  border-color: var(--gold-light);
  transform: scale(1.08);
  box-shadow: 0 8px 22px rgba(0, 0, 0, .4), 0 0 26px var(--gold-glow), inset 0 0 16px rgba(212, 175, 55, .12);
}

.pager__btn:active {
  transform: scale(.94);
}

.pager__btn:disabled {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

/* Indicador 1 / 7 */
.pager__count {
  display: flex;
  flex: 0 0 auto;
  align-items: baseline;
  gap: .34em;
  min-width: 3.6em;
  color: var(--gold-light);
  font-family: var(--f-sans);
  font-size: .62rem;
  font-weight: 300;
  letter-spacing: .22em;
  font-variant-numeric: tabular-nums lining-nums;
  text-shadow: 0 0 14px var(--gold-glow);
}

.pager__sep {
  color: rgba(255, 255, 255, .38);
}

.pager__total {
  color: rgba(255, 255, 255, .55);
}

/* ======================================================
   5. DESTELLOS DORADOS POR ENCIMA DE LAS HOJAS
   ====================================================== */
.sparkles {
  position: fixed;
  inset: 0;
  z-index: 6;
  overflow: hidden;
  pointer-events: none;
}

.sparkles .ambience__canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* ======================================================
   6. AJUSTES DE LAS HOJAS
   ====================================================== */

/* ---------- 6a. Botón de música oculto ----------
   El control flotante de reproducir/pausar deja de mostrarse.
   La música sigue funcionando igual (js/app.js la mantiene),
   simplemente no hay ningún icono visible. Como era un elemento
   position: fixed, tampoco ocupaba sitio: no queda hueco. */
.music-btn {
  display: none;
}

/* ---------- 6b. Centrado vertical del contenido ----------
   Todas las hojas de texto se centran también en vertical, dentro
   del espacio que deja la barra de páginas.

   Se usa margin-block: auto en lugar de justify-content: center
   porque, si el contenido es más alto que la hoja, el margen
   automático vale 0 y la hoja se desplaza desde arriba sin
   recortar nada por el borde superior. */
.page:not(.page--cover) .page__inner > * {
  flex: 0 0 auto;
}

.page:not(.page--cover) .page__inner > *:first-child {
  margin-top: auto;
}

.page:not(.page--cover) .page__inner > *:last-child {
  margin-bottom: auto;
}

/* Aire IGUAL arriba y abajo: así el texto queda justo en el centro
   visual de la hoja. Sólo se equilibra el espacio: no cambian
   tamaños, colores ni tipografías. */
.page .chapter--airy > .chapter__body {
  padding-top: clamp(54px, 11vw, 80px);
  padding-bottom: clamp(54px, 11vw, 80px);
}

.page .chapter--tight > .chapter__body {
  padding-top: clamp(30px, 6vw, 44px);
  padding-bottom: clamp(30px, 6vw, 44px);
}

/* La portada gestiona su propio espacio: el botón y la flecha
   quedan por encima de la barra de páginas */
.page--cover .page__inner {
  padding-bottom: 0;
}

.page .cover {
  min-height: 100%;
  padding-bottom: calc(var(--nav-h) + 62px);
}

.page .scroll-cue {
  bottom: calc(var(--nav-h) + 6px);
}

.page .closing {
  padding-bottom: 0;
}

/* ======================================================
   7. ESCRITORIO · columna centrada tipo móvil
   ====================================================== */
@media (min-width: 1000px) {
  .invitation {
    width: var(--col-w);
    max-width: 100%;
    height: 100svh;
    height: 100dvh;
    overflow: hidden;
  }

  /* Los destellos siguen a la columna, no a toda la ventana */
  .sparkles {
    left: 50%;
    width: var(--col-w);
    max-width: 100%;
    transform: translateX(-50%);
  }

  :root {
    --nav-h: 58px;
  }

  .pager__btn {
    width: 40px;
    height: 40px;
  }

  /* El botón de música se ancla a la esquina de la columna */
  .music-btn {
    right: max(calc(50vw - (var(--col-w) / 2) + 14px), 14px);
    bottom: calc(var(--nav-h) + 4px);
  }
}

@media (max-width: 360px) {
  :root {
    --nav-h: 58px;
  }
}

/* Teléfono en horizontal: la hoja manda, no el adorno */
@media (max-height: 560px) and (orientation: landscape) {
  .book__gutter {
    width: 14px;
  }
}

/* ======================================================
   8. RESERVA · sin JavaScript se leen todas las hojas
   ====================================================== */
.no-js body {
  overflow: auto;
}

.no-js .invitation {
  height: auto;
  overflow: visible;
}

.no-js .book__stage {
  position: static;
  perspective: none;
}

.no-js .page {
  position: static;
  opacity: 1;
  visibility: visible;
  transform: none;
}

.no-js .page__inner {
  padding-bottom: 0;
}

.no-js .page .cover {
  padding-bottom: clamp(86px, 20vw, 104px);
}

.no-js .page .scroll-cue {
  bottom: clamp(20px, 5vw, 28px);
}

.no-js .pager {
  display: none;
}

/* ======================================================
   9. IMPRESIÓN · todas las hojas seguidas
   ====================================================== */
@media print {
  html,
  body {
    height: auto;
    overflow: visible;
  }

  .invitation,
  .book,
  .book__stage {
    height: auto;
    overflow: visible;
  }

  .book__stage {
    position: static;
    perspective: none;
  }

  .page {
    position: static;
    opacity: 1;
    visibility: visible;
    transform: none;
    background: transparent;
    page-break-inside: avoid;
    break-inside: avoid;
  }

  .page__inner {
    overflow: visible;
    padding-bottom: 0;
  }

  .pager,
  .book__gutter,
  .sparkles {
    display: none !important;
  }

  [data-reveal] {
    opacity: 1 !important;
    transform: none !important;
  }
}

/* ======================================================
   10. MOVIMIENTO REDUCIDO
   ====================================================== */
@media (prefers-reduced-motion: reduce) {
  .page {
    transition: none;
  }

  .book__stage {
    perspective: none;
  }
}