/* ===== Intro: libro antiguo que se abre ===== */
/* Las texturas son filtros SVG definidos en src/components/Intro.astro. */

@font-face {
  font-family: 'UnifrakturMaguntia'; font-style: normal; font-weight: 400; font-display: block;
  src: url(/fonts/unifrakturmaguntia-latin-400-normal.woff2) format('woff2');
}

html.intro-activa { overflow: hidden; }

.intro {
  --tinta: #2b1708;
  /* El libro abierto mide 2 × --w: tiene que entrar en pantalla. */
  --w: min(46vw, 300px);
  --h: calc(var(--w) * 1.4);
  --desplazo: 50%;

  position: fixed; inset: 0; z-index: 1000;
  display: grid; place-items: center;
  background: #3a2414; /* mientras se dibuja la mesa */
  overflow: hidden;
  cursor: pointer;
  /* Secuencia (s): tapa 0.2–1.8 · mientras se abre, zoom desde 1.55 y fundido a la hoja del inicio · fin 2.1 */
  animation: intro-irse 0.45s 1.65s ease forwards;
  will-change: opacity;
}
@media (min-width: 700px) { .intro { --w: min(30vw, 310px); } }

.intro__defs { position: absolute; }
.gotica { font-family: 'UnifrakturMaguntia', 'Old English Text MT', serif; font-weight: 400; }

.textura { position: absolute; inset: 0; width: 100%; height: 100%; z-index: -1; display: block; object-fit: fill; }

/* ----- Mesa con polvo y diarios viejos ----- */
.intro__mesa { position: absolute; inset: 0; overflow: hidden; z-index: 0; }
/* madera con el polvo ya incluido (public/texturas/mesa.webp) */
.mesa__madera { position: absolute; inset: 0; width: 100%; height: 100%; display: block; object-fit: cover; filter: saturate(0.85); }
.intro__mesa::before {
  /* juntas entre tablones */
  content: ''; position: absolute; inset: 0;
  background: repeating-linear-gradient(180deg, transparent 0 calc(25vh - 2px), rgba(15, 7, 2, 0.55) calc(25vh - 2px) 25vh);
  box-shadow: inset 0 0 0 0;
}
.mesa__luz {
  /* luz cálida de lámpara sobre el libro y bordes en penumbra */
  position: absolute; inset: 0; z-index: 3; pointer-events: none;
  background:
    radial-gradient(ellipse 55% 50% at 50% 48%, rgba(255, 200, 130, 0.22), transparent 70%),
    radial-gradient(ellipse at 50% 48%, transparent 55%, rgba(8, 3, 0, 0.45) 100%);
}

.diario {
  --dw: clamp(200px, 37vmin, 360px);
  position: absolute; z-index: 1;
  width: var(--dw); aspect-ratio: 0.72;
  padding: calc(var(--dw) * 0.05);
  color: rgba(35, 28, 20, 0.88);
  background:
    linear-gradient(90deg, transparent 49.6%, rgba(90, 70, 40, 0.18) 50%, transparent 50.4%),
    radial-gradient(ellipse at 30% 20%, rgba(255, 250, 230, 0.25), transparent 60%),
    radial-gradient(ellipse at 70% 85%, rgba(150, 110, 50, 0.25), transparent 55%),
    #d9cfb5;
  box-shadow:
    inset 0 0 calc(var(--dw) * 0.08) rgba(120, 90, 40, 0.45),
    0 2px 3px rgba(0, 0, 0, 0.35), 0 12px 24px -6px rgba(0, 0, 0, 0.55);
  display: flex; flex-direction: column; gap: calc(var(--dw) * 0.02);
  filter: sepia(0.15);
}
.diario__cabecera {
  text-align: center; font-size: calc(var(--dw) * 0.115); line-height: 1;
  padding-bottom: calc(var(--dw) * 0.015);
  border-bottom: 3px double rgba(35, 28, 20, 0.7);
}
.diario__fecha {
  text-align: center; text-transform: uppercase; letter-spacing: 0.18em;
  font: 700 calc(var(--dw) * 0.026) Georgia, serif;
  padding-bottom: calc(var(--dw) * 0.012); border-bottom: 1px solid rgba(35, 28, 20, 0.6);
}
.diario__titular {
  font-family: 'Fraunces Variable', Georgia, serif; font-weight: 800;
  font-size: calc(var(--dw) * 0.078); line-height: 1.02; letter-spacing: -0.01em;
  text-align: center; text-transform: uppercase;
  margin: calc(var(--dw) * 0.01) 0;
}
.diario__cuerpo { flex: 1; display: grid; grid-template-columns: 1fr 1fr; gap: calc(var(--dw) * 0.035); min-height: 0; }
.diario__foto {
  /* foto impresa en el diario: blanco y negro, gastada, con trama de puntos */
  position: relative; grid-column: 1 / -1; height: calc(var(--dw) * 0.56);
  overflow: hidden; background: #d9cfb5;
  box-shadow: 0 0 0 1px rgba(35, 28, 20, 0.5);
}
.diario__foto img {
  width: 100%; height: 100%; object-fit: cover; object-position: 50% 30%; display: block;
  filter: grayscale(1) sepia(0.25) contrast(1.1) brightness(1.08);
}
.diario__foto::after {
  content: ''; position: absolute; inset: 0;
  background: radial-gradient(circle, rgba(30, 24, 18, 0.18) 0.6px, transparent 1.1px) 0 0 / 3px 3px;
  mix-blend-mode: multiply;
}
.diario__texto {
  /* renglones de texto ilegible */
  background: repeating-linear-gradient(180deg, rgba(35, 28, 20, 0.55) 0 1.5px, transparent 1.5px 5px);
  -webkit-mask-image: linear-gradient(90deg, #000 85%, transparent);
          mask-image: linear-gradient(90deg, #000 85%, transparent);
  opacity: 0.8;
}
.diario--1 { top: -3%; left: -6%; transform: rotate(-14deg); }
.diario--2 { top: -5%; right: -8%; transform: rotate(11deg); }
.diario--3 { bottom: -5%; left: -4%; transform: rotate(8deg); }
.diario--4 { bottom: -3%; right: -5%; transform: rotate(-9deg); }
.diario--2::after {
  /* aro de café */
  content: ''; position: absolute; width: 34%; aspect-ratio: 1; left: 12%; bottom: 14%;
  border-radius: 50%;
  box-shadow: inset 0 0 0 calc(var(--dw) * 0.012) rgba(110, 65, 20, 0.35), 0 0 0 1px rgba(110, 65, 20, 0.15);
  transform: rotate(20deg) scaleX(1.05);
}
@media (max-width: 699px) {
  .diario--1 { top: 2%; left: -18%; }
  .diario--2 { top: 0%; right: -20%; }
  .diario--3 { bottom: 1%; left: -18%; }
  .diario--4 { bottom: 2%; right: -20%; }
}

.intro__escena {
  position: relative; z-index: 1; /* el libro siempre arriba de la mesa y los diarios */
  perspective: 2000px;
  animation: intro-aparecer 0.3s ease-out both, intro-acercar 0.55s 1.55s ease-in forwards;
  /* que el navegador mueva estas capas con la placa de video, sin redibujarlas en cada cuadro */
  will-change: transform, opacity;
}

.libro {
  position: relative; width: var(--w); height: var(--h);
  transform-style: preserve-3d; will-change: transform;
  animation: libro-centrar 1.6s 0.2s cubic-bezier(0.55, 0.05, 0.3, 1) forwards;
}

/* Bloque de hojas: canto amarillento y desparejo a la derecha y abajo */
.libro__bloque {
  position: absolute; inset: 2px 0 0 2px; border-radius: 1px 3px 3px 1px;
  background: #b89a66;
  box-shadow:
    1px 1px 0 #a88a58, 2px 2px 0 #c7aa75, 3px 2px 0 #9c7f4e, 4px 3px 0 #bfa06a,
    5px 4px 0 #8f7244, 6px 5px 0 #b29360, 7px 6px 0 #5c4022,
    16px 22px 40px rgba(10, 5, 0, 0.6), 4px 6px 10px rgba(10, 5, 0, 0.4);
}

/* Superficies con textura (contexto propio para que la textura quede detrás del texto).
   Ojo: nunca en elementos con preserve-3d (.libro__hoja, .libro__tapa): aplana el 3D. */
.libro__pagina, .libro__cara, .libro__tapa-frente, .libro__tapa-dorso, .libro__lomo {
  isolation: isolate;
}

/* Página de abajo (derecha) */
.libro__pagina {
  position: absolute; inset: 0;
  display: grid; place-items: center; padding: 10% 9% 10% 8%;
}
.libro__pagina::before, .libro__cara--dorso::before {
  /* sombra del lomo hacia adentro */
  content: ''; position: absolute; inset: 0; z-index: 0; pointer-events: none;
  background: linear-gradient(90deg, rgba(50, 25, 3, 0.5), rgba(50, 25, 3, 0.12) 8%, transparent 16%);
}
.libro__cara--dorso::before { transform: scaleX(-1); }
.libro__floritura { width: 52%; height: calc(var(--w) * 0.09); color: currentColor; opacity: 0.7; }

/* Hojas que pasan */
.libro__hoja {
  position: absolute; top: 3px; bottom: 3px; left: 0; right: 3px;
  transform-origin: left center; transform-style: preserve-3d;
  animation: 0.5s cubic-bezier(0.5, 0.05, 0.35, 1) both;
}
.libro__hoja--1 { animation-name: libro-hoja-1; animation-delay: 0.85s; } /* sin uso: hoy el libro no pasa hojas */
.libro__cara {
  position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  display: grid; place-items: center; padding: 10% 9% 10% 8%;
}
.libro__cara--dorso { transform: rotateY(180deg); }

/* Fotos pegadas en el álbum: borde de papel, esquineros, tono sepia.
   Sin uso por ahora (prueba con las fotos en los diarios); se deja para poder volver. */
.foto {
  position: relative; display: block; width: 80%;
  padding: 4% 4% 5%;
  background: #efe3c8;
  box-shadow: 0 1px 2px rgba(40, 20, 0, 0.5), 0 6px 14px -4px rgba(40, 20, 0, 0.55);
}
.foto--izq { transform: rotate(-2.5deg); }
.foto--der { transform: rotate(2deg); }
.foto img {
  display: block; width: 100%; height: auto;
  max-height: calc(var(--h) * 0.68); object-fit: cover;
  filter: sepia(0.45) saturate(0.85) contrast(0.95) brightness(0.97);
}
.foto::before, .foto::after {
  /* esquineros de papel oscuro */
  content: ''; position: absolute; width: 16%; aspect-ratio: 1;
  background: linear-gradient(135deg, #3a2414 50%, transparent 50%);
  opacity: 0.85;
}
.foto::before { top: -3%; left: -4%; }
.foto::after { bottom: -3%; right: -4%; transform: rotate(180deg); }

/* Tapa */
.libro__tapa {
  position: absolute; inset: 0;
  transform-origin: left center; transform-style: preserve-3d; will-change: transform;
  animation: libro-tapa 1.6s 0.2s cubic-bezier(0.6, 0.05, 0.3, 1) both;
}
.libro__tapa-frente, .libro__tapa-dorso {
  position: absolute; inset: -3px -5px -5px -3px;
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
}
.libro__tapa-frente {
  display: grid; place-items: center;
  padding-left: 15%;
  filter: drop-shadow(0 0 1px rgba(20, 8, 0, 0.8));
}
.libro__tapa-dorso { transform: rotateY(180deg); display: grid; place-items: center; padding: 12% 11% 12% 9%; }

/* Lomo de cuero rojo con bandas de bronce opaco */
.libro__lomo { position: absolute; left: 0; top: 0; bottom: 0; width: 15%; z-index: 1; }
.libro__lomo i {
  position: absolute; left: -2px; right: -5px; height: 4.2%;
  border-radius: 1px;
  background:
    linear-gradient(90deg, rgba(0, 0, 0, 0.35), transparent 30%, transparent 70%, rgba(0, 0, 0, 0.4)),
    linear-gradient(180deg, #8c7448, #5b4524 40%, #3a2b14 70%, #6e5732);
  box-shadow: 0 2px 2px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(230, 200, 140, 0.25);
}
.libro__lomo i:nth-child(2) { top: 9%; }
.libro__lomo i:nth-child(3) { top: 34%; }
.libro__lomo i:nth-child(4) { top: 61%; }
.libro__lomo i:nth-child(5) { top: 86%; }

/* Esquineros labrados en el cuero (hundidos, no metálicos) */
.libro__esq {
  position: absolute; width: 24%; height: 24%; z-index: 1;
  color: rgba(50, 26, 6, 0.75);
  filter: drop-shadow(0 1px 0 rgba(255, 225, 165, 0.3));
}
.libro__esq--1 { top: 4%; left: 19%; }
.libro__esq--2 { top: 4%; right: 4%; transform: scaleX(-1); }
.libro__esq--3 { bottom: 4%; left: 19%; transform: scaleY(-1); }
.libro__esq--4 { bottom: 4%; right: 4%; transform: scale(-1, -1); }

/* Rótulo grabado y gastado */
.libro__rotulo {
  position: relative; z-index: 1;
  display: flex; flex-direction: column; align-items: center; gap: calc(var(--w) * 0.012);
  color: rgba(40, 20, 4, 0.82);
  text-shadow: 0 1px 0 rgba(255, 225, 165, 0.35), 0 -1px 0 rgba(10, 4, 0, 0.45);
  filter: url(#gastado);
}
.libro__titulo { font-size: calc(var(--w) * 0.26); line-height: 1; }
.libro__anio { font-size: calc(var(--w) * 0.14); line-height: 1; letter-spacing: 0.04em; }
.libro__rotulo .libro__floritura { width: calc(var(--w) * 0.5); opacity: 0.75; }

/* Botón saltar */
.intro__saltar {
  position: absolute; right: 1rem; bottom: calc(1rem + env(safe-area-inset-bottom));
  background: rgba(30, 18, 8, 0.4); color: #f2e6cf;
  border: 1px solid rgba(242, 230, 207, 0.35); border-radius: 999px;
  font: 600 0.9rem 'Source Sans 3 Variable', system-ui, sans-serif;
  padding: 0.55rem 1rem; min-height: 44px; cursor: pointer;
}
.intro__saltar:hover { background: rgba(30, 18, 8, 0.6); }
.intro__saltar:focus-visible { outline: 3px solid #e6cfa4; outline-offset: 3px; }

.intro--saliendo { animation: intro-irse 0.4s ease forwards !important; }

@keyframes intro-aparecer { from { opacity: 0; transform: translateY(16px) scale(0.96); } }
@keyframes libro-centrar { to { transform: translateX(var(--desplazo)); } }
/* Profundidad: cerradas, la tapa queda arriba y la hoja 1 sobre la 2 y la 3; dadas vuelta,
   cada una queda un poco más cerca que la anterior (si no, se pisan). */
@keyframes libro-tapa { from { transform: rotateY(0deg) translateZ(5px); } to { transform: rotateY(-180deg) translateZ(1px); } }
@keyframes libro-hoja-1 { from { transform: rotateY(0deg) translateZ(2px); } to { transform: rotateY(-180deg) translateZ(-2px); } }
@keyframes intro-acercar { to { transform: scale(2.2); opacity: 0; } }
@keyframes intro-irse { to { opacity: 0; visibility: hidden; } }

@media (prefers-reduced-motion: reduce) { .intro { display: none; } }
