/* El libro como objeto: una caja de seis caras con luz, que se agarra, se gira y se hojea (inc/libro.php). */

.grl { --grl-ancho: 300px; --grl-papel: #f1ede2; --grl-tinta: #0a0a0a; overflow: hidden; }
.grl-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: clamp(24px, 5vw, 80px); align-items: center; padding-block: clamp(56px, 8vw, 110px); }
.grl-texto h2 { font-size: clamp(46px, 6.2vw, 96px); line-height: .85; margin-top: 12px; }
.grl-texto p { max-width: 46ch; }

/* ── la escena ── */
.grl-objeto { display: flex; flex-direction: column; align-items: center; gap: 14px; min-width: 0; }
.grl-escena { position: relative; width: 100%; display: flex; justify-content: center; align-items: center; perspective: 1600px; height: calc(var(--grl-ancho) * 1.5764 + 70px); cursor: grab; touch-action: pan-y; user-select: none; -webkit-user-select: none; }
.grl--arrastrando .grl-escena { cursor: grabbing; }
.grl--abierto .grl-escena { cursor: default; }
.grl-sombra { position: absolute; left: 50%; bottom: 10px; width: var(--grl-ancho); height: 30px; border-radius: 50%; background: radial-gradient(closest-side, rgba(0, 0, 0, .42), rgba(0, 0, 0, .18) 55%, transparent); filter: blur(6px); pointer-events: none; transform: translateX(-50%); }

/* ── la caja ── */
.grl-libro { --g: calc(var(--grl-ancho) * .092); position: relative; width: var(--grl-ancho); height: calc(var(--grl-ancho) * 1.5764); transform-style: preserve-3d; will-change: transform; }
.grl-cara, .grl-hoja, .grl-pag { position: absolute; display: block; }
.grl-cara, .grl-pag { backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.grl-cara { background-size: 100% 100%; }
/* La luz: cada cara se oscurece según hacia dónde mira (la calcula libro.js). */
[data-luz]::after { content: ""; position: absolute; inset: 0; background: #000; opacity: var(--osc, 0); pointer-events: none; z-index: 3; border-radius: inherit; }

.grl-lomo { top: -.5px; left: calc(var(--g) / -2 - 1.5px); width: calc(var(--g) + 3px); height: calc(100% + 1px); background-image: var(--grl-lomo); background-color: #0d1508; transform: rotateY(-90deg); border-radius: 2px; }
.grl-lomo-dentro { position: absolute; top: .3%; left: calc(var(--g) / -2 + 2.5px); width: var(--g); height: 99.4%; background: #0d1508; transform: rotateY(-90deg); } /* una pared oscura por dentro: si se abre una rendija entre el lomo y la tapa, no se ve la luz de atrás */
.grl-contra { inset: 0; background-image: var(--grl-contra); transform: translateZ(calc(var(--g) / -2)) rotateY(180deg); border-radius: 0 2px 2px 0; }
.grl-fondo { inset: .4% .6% .4% 4px; transform: translateZ(calc(var(--g) / -2 + .6px)); background: var(--grl-papel); }
/* El papel visto de canto: las hojas apretadas, cálidas, con su grano. */
.grl-canto { background-color: var(--grl-papel); }
.grl-canto--lado { top: .4%; right: calc(var(--g) / -2 + .6%); width: var(--g); height: 99.2%; transform: rotateY(90deg); background-image: repeating-linear-gradient(90deg, rgba(80, 60, 30, .10) 0 1px, transparent 1px 2.5px), linear-gradient(90deg, rgba(0, 0, 0, .12), transparent 18%, transparent 82%, rgba(0, 0, 0, .12)); }
.grl-canto--arriba, .grl-canto--abajo { left: 0; width: 99.4%; height: var(--g); background-image: repeating-linear-gradient(0deg, rgba(80, 60, 30, .10) 0 1px, transparent 1px 2.5px), linear-gradient(0deg, rgba(0, 0, 0, .12), transparent 18%, transparent 82%, rgba(0, 0, 0, .12)); }
.grl-canto--arriba { top: calc(var(--g) / -2 + .4%); transform: rotateX(90deg); }
.grl-canto--abajo { bottom: calc(var(--g) / -2 + .4%); transform: rotateX(-90deg); }

/* El grano de la impresión, sobre las dos tapas. */
.grl-pag--portada::before, .grl-contra::before { content: ""; position: absolute; inset: 0; pointer-events: none; z-index: 2; opacity: .35; mix-blend-mode: overlay; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .5 0 0 0 0 .5 0 0 0 0 .5 0 0 0 .9 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23g)'/%3E%3C/svg%3E"); }

.grl-hoja { inset: 0; transform-style: preserve-3d; transform-origin: left center; transition: transform .9s cubic-bezier(.3, .6, .2, 1); }
.grl-pag { inset: 0; overflow: hidden; background: var(--grl-papel); }
.grl-hoja:not([data-grl-hoja="0"]) .grl-pag { inset: .4% .6% .4% 4px; }
.grl-pag.grl-pag img { width: 100%; height: 100%; object-fit: cover; display: block; user-select: none; pointer-events: none; }
.grl-pag--dorso { transform: rotateY(180deg); }
.grl-pag--portada { background: var(--grl-portada) center / 100% 100%; border-radius: 0 2px 2px 0; }
/* El laminado: un reflejo suave que corre con el giro (lo mueve libro.js). */
.grl-brillo { position: absolute; inset: 0; z-index: 4; pointer-events: none; border-radius: inherit; background: linear-gradient(105deg, transparent 0 calc(var(--brillo, 50%) - 22%), rgba(255, 255, 255, .13) var(--brillo, 50%), transparent calc(var(--brillo, 50%) + 22%)); }
/* El pliegue: la página se oscurece hacia el lomo. */
.grl-pag--frente:not(.grl-pag--portada)::before, .grl-pag--dorso::before { content: ""; position: absolute; top: 0; bottom: 0; width: 12%; pointer-events: none; z-index: 1; }
.grl-pag--frente:not(.grl-pag--portada)::before { left: 0; background: linear-gradient(90deg, rgba(0, 0, 0, .20), transparent); }
.grl-pag--dorso::before { right: 0; background: linear-gradient(270deg, rgba(0, 0, 0, .20), transparent); }
.grl-guarda { position: absolute; inset: 0; background-color: #16240e; }
.grl-pag--fin { background: #0a0a0a; color: #e8e8e4; }
.grl-fin { position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; gap: 22px; padding: 12%; }
.grl-fin b { font-family: "Barlow Condensed", sans-serif; font-weight: 800; text-transform: uppercase; font-size: calc(var(--grl-ancho) * .11); line-height: .9; }
.grl-fin .gr-boton { background: transparent; color: #e8e8e4; border: 1px solid #e8e8e4; pointer-events: auto; transition: background .2s, border-color .2s, color .2s; }
.grl-fin .gr-boton:hover { background: #63cb01; border-color: #63cb01; color: #0a0a0a; }

/* ── mandos ── */
.grl-mandos { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: center; }
.grl-mandos [hidden] { display: none; }
.grl-btn { font: inherit; font-family: "Share Tech Mono", monospace; font-size: 14px; min-width: 44px; min-height: 44px; padding: 0 14px; background: transparent; color: inherit; border: 1px solid currentColor; cursor: pointer; text-transform: uppercase; letter-spacing: .06em; }
.grl-btn--chico { min-height: 32px; min-width: 0; padding: 0 10px; font-size: 11px; letter-spacing: .1em; opacity: .75; }
.grl-btn--chico:hover { opacity: 1; }
.grl-btn:hover:not(:disabled) { background: var(--grl-tinta); color: #e8e8e4; }
.grl-btn:disabled { opacity: .3; cursor: default; }
.grl-btn:focus-visible, .grl-escena:focus-visible { outline: 2px solid #63cb01; outline-offset: 4px; }
.grl-donde { min-width: 9ch; text-align: center; }

/* ── en grande: el mismo libro, a pantalla completa, y se sigue hojeando ── */
/* Empieza debajo de la cabecera del sitio (la mide tema.js en --gr-cab-alto): la barra de arriba, con el
   logo y los botones, sigue a la vista, y el botón Cerrar nunca queda detrás de la hora del celular. */
.grl-zoom { position: fixed; inset: var(--gr-cab-alto, calc(72px + env(safe-area-inset-top, 0px))) 0 0 0; z-index: 99999; background: #0a0a0a; color: #e8e8e4; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; padding: 56px 16px 24px; --grl-tinta: #e8e8e4; }
.grl-zoom[hidden] { display: none; }
/* Con el libro en grande, la cabecera siempre gris (en la portada flota transparente sobre la imagen). */
body:has(.grl-zoom:not([hidden])) .gr-cabecera { background: rgba(10, 10, 10, .96); border-color: var(--linea, rgba(232, 232, 228, .15)); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.grl-zoom .grl-escena { height: calc(var(--grl-ancho) * 1.5764 + 30px); }
.grl-zoom .grl-sombra { opacity: .5; }
.grl-zoom .grl-btn:hover:not(:disabled) { background: #e8e8e4; color: #0a0a0a; }
.grl-zoom__cerrar { position: absolute; top: 12px; right: 16px; }
/* En el celular, una página a la vez, que se pasa con el dedo. */
.grl-zoom__pagina { max-width: 100%; max-height: calc(100vh - var(--gr-cab-alto, 72px) - 150px); width: auto; height: auto; background: var(--grl-papel); }
.grl-zoom__suelta { display: flex; flex-direction: column; align-items: center; gap: 14px; width: 100%; }
.grl-zoom__nav { display: flex; align-items: center; gap: 10px; }

@media (max-width: 767px) {
	.grl-grid { grid-template-columns: 1fr; }
	.grl-texto { order: 2; }
}

@media (prefers-reduced-motion: reduce) {
	.grl-hoja { transition: none; }
}
