:root {
  --rojo: #c1121f;
  --rojo-suave: #e63946;
  --crema: #fff8ee;
  --papel: #fffaf2;
  --noche: #5b7aa8;
  --azul: #3d5a80;
  --dorado: #7a3a58;
  --tinta: #2c2048;
  --tinta-suave: #4a3a68;
  --tinta-muted: #5c4d78;
  --naranja: #ffc4a8;
  --ocaso: #e8a0c0;
  --sombra: rgba(70, 80, 140, 0.28);
  --fuente-ui: "Nunito", system-ui, sans-serif;
  --fuente-titulo: "Cormorant Garamond", Georgia, serif;
  --fuente-ninos: "Fredoka", "Nunito", sans-serif;
}

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

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: var(--fuente-ui);
  color: var(--crema);
  background: var(--noche);
  overflow-x: hidden;
}

img {
  max-width: 100%;
  display: block;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font-family: inherit;
  cursor: pointer;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.fondo-hilos {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
}

.fondo-hilos.suave {
  opacity: 0.55;
}

.velo {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background:
    radial-gradient(1100px 720px at 50% -8%, rgba(255, 246, 210, 0.7), transparent 52%),
    radial-gradient(900px 560px at 12% 18%, rgba(255, 196, 214, 0.38), transparent 55%),
    radial-gradient(860px 520px at 90% 12%, rgba(186, 214, 255, 0.45), transparent 52%),
    radial-gradient(700px 420px at 50% 100%, rgba(168, 186, 230, 0.28), transparent 58%);
}

.polvo {
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)' opacity='.35'/%3E%3C/svg%3E");
  opacity: 0.07;
  mix-blend-mode: overlay;
}

.vista-inicio,
.vista-estante,
.vista-libro {
  position: relative;
  min-height: 100vh;
  color: var(--tinta);
}

.vista-inicio {
  background:
    radial-gradient(ellipse at 50% -12%, #fff7d2 0%, #ffd8c4 22%, #f5b8d0 48%, #9eb6e8 78%, #6a88c8 100%);
}

.vista-estante.tema-ninos {
  background:
    radial-gradient(ellipse at 18% -8%, #fff6d8 0%, #ffe0c8 26%, #ffc2d4 54%, #c8b8f0 82%, #8aa8e0 100%);
}

.vista-estante.tema-adolescentes {
  background:
    radial-gradient(ellipse at 82% -6%, #ffe9c8 0%, #f7c4c8 28%, #c8a8e0 56%, #7a96d0 82%, #4f6eaa 100%);
}

.vista-libro {
  background:
    radial-gradient(ellipse at 50% 0%, #fff4cc 0%, #ffdcc8 30%, #d4c4f0 58%, #8aa4d8 84%, #5c7ab8 100%);
  overflow-x: hidden;
}

.inicio,
.estante-wrap,
.escena-libro {
  position: relative;
  z-index: 3;
}

.hero,
.estante-hero {
  text-align: center;
  padding: 4.5rem 1.5rem 1.5rem;
}

.inicio .coleccion,
.inicio .lema,
.inicio .pregunta,
.inicio .hero h1 {
  color: #1a1228;
  text-shadow: none;
}

.coleccion {
  letter-spacing: 0.28em;
  text-transform: uppercase;
  font-size: 0.72rem;
  color: #3a2a52;
  font-weight: 800;
  text-shadow: none;
  margin: 0 0 0.8rem;
}

.hero h1,
.estante-hero h1,
.libro-titulos h1 {
  font-family: var(--fuente-titulo);
  font-weight: 700;
  font-size: clamp(2.6rem, 7vw, 5.4rem);
  line-height: 0.95;
  margin: 0;
  color: #1a1228;
  text-shadow: none;
}

.tema-ninos .estante-hero h1,
.tema-ninos .libro-titulos h1 {
  font-family: var(--fuente-ninos);
}

.lema {
  max-width: 36rem;
  margin: 1rem auto 0;
  font-size: 1.12rem;
  color: #2e2448;
  font-weight: 600;
}

.hilo-titulo {
  width: min(320px, 70vw);
  margin: 1.2rem auto 0;
}

.hilo-titulo path {
  fill: none;
  stroke: var(--rojo-suave);
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-dasharray: 420;
  stroke-dashoffset: 420;
  animation: dibujar 2.4s ease forwards;
  filter: drop-shadow(0 0 6px rgba(230, 57, 70, 0.8));
}

@keyframes dibujar {
  to { stroke-dashoffset: 0; }
}

.pregunta {
  text-align: center;
  font-family: var(--fuente-titulo);
  font-size: 1.7rem;
  margin: 1.5rem 0 1.2rem;
  color: #1a1228;
  font-weight: 600;
}

.portales {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1.5rem;
  width: min(980px, calc(100% - 2rem));
  margin: 0 auto 3rem;
}

.portal {
  position: relative;
  overflow: hidden;
  border-radius: 28px;
  min-height: 340px;
  padding: 2rem 1.8rem 1.6rem;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  isolation: isolate;
  color: #fff;
  box-shadow: 0 24px 50px var(--sombra);
  transform: translateY(0) scale(1);
  transition: transform 0.4s ease, box-shadow 0.4s ease;
}

.portal:hover,
.portal:focus-visible {
  transform: translateY(-8px) scale(1.015);
  box-shadow: 0 32px 70px rgba(0, 0, 0, 0.45);
}

.portal-ninos {
  background:
    linear-gradient(180deg, rgba(80, 70, 140, 0.08), rgba(70, 80, 150, 0.28)),
    radial-gradient(circle at 20% 20%, #ffe7b8, transparent 32%),
    radial-gradient(circle at 80% 10%, #c8e4ff, transparent 30%),
    linear-gradient(160deg, #9aa8ff, #ff9ec8 55%, #ffe08a);
}

.portal-adole {
  background:
    linear-gradient(180deg, rgba(40, 50, 90, 0.08), rgba(50, 60, 110, 0.32)),
    radial-gradient(circle at 80% 8%, #fff4c4, transparent 34%),
    linear-gradient(165deg, #f0b8c8, #8eb0e0 48%, #5a78b8);
}

.portal-ilustra {
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
}

.globo {
  position: absolute;
  width: 42px;
  height: 54px;
  border-radius: 50% 50% 50% 50% / 42% 42% 58% 58%;
  opacity: 0.85;
  animation: flotar 4.5s ease-in-out infinite;
}

.globo::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 100%;
  width: 1px;
  height: 28px;
  background: rgba(255, 255, 255, 0.55);
}

.g1 { background: #fff; left: 18%; top: 16%; animation-delay: 0s; }
.g2 { background: #ffd166; left: 58%; top: 8%; width: 32px; height: 42px; animation-delay: 0.6s; }
.g3 { background: #90e0ef; left: 78%; top: 22%; width: 28px; height: 36px; animation-delay: 1.1s; }

.estrella {
  position: absolute;
  color: #fff;
  animation: destello 2.8s ease-in-out infinite;
}
.s1 { left: 10%; top: 48%; }
.s2 { left: 46%; top: 18%; font-size: 1.4rem; animation-delay: 0.5s; }
.s3 { left: 86%; top: 48%; animation-delay: 1s; }

.ciudad {
  position: absolute;
  left: 8%;
  right: 8%;
  bottom: 38%;
  height: 70px;
  background:
    linear-gradient(#1d1a2a 0 0) 8% 100% / 18px 34px no-repeat,
    linear-gradient(#241c32 0 0) 22% 100% / 28px 54px no-repeat,
    linear-gradient(#1a1424 0 0) 40% 100% / 22px 40px no-repeat,
    linear-gradient(#2a2238 0 0) 58% 100% / 36px 62px no-repeat,
    linear-gradient(#1d1828 0 0) 78% 100% / 20px 36px no-repeat,
    linear-gradient(#261e34 0 0) 92% 100% / 26px 48px no-repeat;
  opacity: 0.55;
}

.sol {
  position: absolute;
  right: 14%;
  top: 14%;
  width: 86px;
  height: 86px;
  border-radius: 50%;
  background: radial-gradient(circle, #ffe08a 0%, #ff9f1c 45%, transparent 70%);
  filter: blur(1px);
  animation: pulso 3.8s ease-in-out infinite;
}

@keyframes flotar {
  50% { transform: translateY(-12px); }
}

@keyframes destello {
  50% { opacity: 0.25; transform: scale(0.7) rotate(20deg); }
}

@keyframes pulso {
  50% { transform: scale(1.08); opacity: 0.85; }
}

.portal-edad {
  font-size: 0.78rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.8);
}

.portal h2 {
  font-family: var(--fuente-titulo);
  font-size: 2.4rem;
  margin: 0.35rem 0 0.5rem;
}

.portal-ninos h2 {
  font-family: var(--fuente-ninos);
}

.portal p {
  margin: 0 0 1.1rem;
  max-width: 28rem;
  color: rgba(255, 255, 255, 0.9);
}

.portal-cta {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.16);
  border: 1px solid rgba(255, 255, 255, 0.28);
  backdrop-filter: blur(8px);
  padding: 0.55rem 1rem;
  border-radius: 999px;
  font-weight: 800;
}

.portal-meta {
  display: block;
  margin: 0 0 0.75rem;
  font-size: 0.88rem;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.88);
}

.pie-inicio {
  text-align: center;
  color: rgba(255, 247, 234, 0.55);
  padding: 0 1rem 2.5rem;
  font-size: 0.92rem;
}

code {
  color: var(--dorado);
}

.btn-sonido,
.icon-btn {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(70, 90, 150, 0.28);
  color: #fff;
  display: grid;
  place-items: center;
  backdrop-filter: blur(8px);
}

.btn-sonido {
  position: fixed;
  top: 1.1rem;
  right: 1.1rem;
  z-index: 8;
}

.icono-sonido,
.icono-voz,
.icono-pantalla {
  width: 16px;
  height: 16px;
  display: block;
  background: currentColor;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='black' d='M3 10v4h4l5 5V5L7 10H3zm13.5 2a4.5 4.5 0 0 0-2.3-3.9v7.8A4.5 4.5 0 0 0 16.5 12z'/%3E%3C/svg%3E") center / contain no-repeat;
}

.btn-sonido[aria-pressed="true"] .icono-sonido,
.icon-btn[aria-pressed="true"] .icono-sonido {
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='black' d='M3 10v4h4l5 5V5L7 10H3zm13.5 2a4.5 4.5 0 0 0-2.3-3.9v7.8A4.5 4.5 0 0 0 16.5 12zM14 3.2v2.1A7.5 7.5 0 0 1 19.5 12 7.5 7.5 0 0 1 14 18.7v2.1A9.5 9.5 0 0 0 21.5 12 9.5 9.5 0 0 0 14 3.2z'/%3E%3C/svg%3E");
}

.icono-voz {
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='black' d='M12 14a3 3 0 0 0 3-3V6a3 3 0 1 0-6 0v5a3 3 0 0 0 3 3zm5-3a5 5 0 0 1-10 0H5a7 7 0 0 0 6 6.9V21h2v-3.1A7 7 0 0 0 19 11h-2z'/%3E%3C/svg%3E");
}

.icono-pantalla {
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='black' d='M7 14H5v5h5v-2H7v-3zm12 0h-2v3h-3v2h5v-5zM7 7h3V5H5v5h2V7zm10 0v3h2V5h-5v2h3z'/%3E%3C/svg%3E");
}

.volver {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  color: #1a1228;
  font-weight: 800;
}

.volver-menu {
  position: relative;
  z-index: 6;
  margin: 1.1rem 0 0 1.2rem;
  padding: 0.55rem 1rem;
  border-radius: 999px;
  background: rgba(255, 248, 242, 0.75);
  border: 1px solid rgba(42, 18, 40, 0.14);
  box-shadow: 0 8px 20px rgba(42, 18, 40, 0.08);
}

.volver-menu:hover,
.volver-menu:focus-visible {
  background: #fff;
}

.galeria {
  width: min(1100px, calc(100% - 2rem));
  margin: 1rem auto 4rem;
  display: grid;
  gap: 1.6rem;
}

.carta-libro {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 1.6rem;
  padding: 1.4rem;
  border-radius: 28px;
  background: rgba(255, 248, 242, 0.62);
  border: 1px solid rgba(80, 60, 110, 0.12);
  backdrop-filter: blur(16px);
  align-items: center;
  color: var(--tinta);
}

.carta-proxima {
  opacity: 0.62;
}

.libro-3d {
  width: 168px;
  height: 236px;
  margin: 0 auto;
  position: relative;
  transform-style: preserve-3d;
  transform: perspective(700px) rotateY(-22deg) rotateX(4deg);
  transition: transform 0.45s ease;
  display: block;
}

.libro-3d:hover {
  transform: perspective(700px) rotateY(-8deg) rotateX(2deg) translateY(-8px);
}

.lomo,
.tapa,
.canto {
  position: absolute;
  inset: 0;
  border-radius: 3px 10px 10px 3px;
}

.lomo {
  width: 22px;
  left: -18px;
  right: auto;
  background: linear-gradient(90deg, #3a0d12, var(--libro-color, var(--rojo)), #3a0d12);
  transform: rotateY(75deg);
  transform-origin: right center;
  box-shadow: inset -4px 0 8px rgba(0, 0, 0, 0.35);
}

.tapa {
  background: #2b1810 center / cover no-repeat;
  box-shadow:
    18px 22px 30px rgba(0, 0, 0, 0.35),
    inset 0 0 0 1px rgba(255, 255, 255, 0.12);
}

.canto {
  width: 14px;
  left: auto;
  right: -10px;
  background: repeating-linear-gradient(180deg, #f3e6d0 0 2px, #e7d5b8 2px 3px);
  transform: rotateY(-60deg);
  transform-origin: left center;
  border-radius: 0 4px 4px 0;
}

.tapa-proxima {
  background:
    linear-gradient(180deg, rgba(255,255,255,.08), rgba(255,255,255,.02)),
    repeating-linear-gradient(45deg, rgba(255,255,255,.05) 0 12px, transparent 12px 24px),
    #2a2438;
}

.es-fantasma {
  filter: grayscale(0.3);
}

.carta-info h2 {
  font-family: var(--fuente-titulo);
  font-size: 2.1rem;
  margin: 0.15rem 0 0.2rem;
  color: var(--tinta);
}

.tema-ninos .carta-info h2 {
  font-family: var(--fuente-ninos);
}

.carta-coleccion,
.carta-autor,
.carta-meta {
  margin: 0;
  color: var(--dorado);
  font-size: 0.88rem;
}

.carta-autor {
  color: var(--tinta-muted);
}

.carta-resumen {
  color: var(--tinta-suave);
  line-height: 1.5;
}

.btn-abrir {
  display: inline-block;
  margin-top: 0.4rem;
  background: linear-gradient(180deg, var(--rojo-suave), var(--rojo));
  color: white;
  font-weight: 800;
  padding: 0.7rem 1.15rem;
  border-radius: 999px;
  box-shadow: 0 10px 24px rgba(193, 18, 31, 0.35);
}

.vacio {
  text-align: center;
  padding: 3rem 1.5rem 5rem;
  color: var(--tinta-suave);
}

.vacio h2 {
  color: var(--tinta);
}

.vacio-libro {
  width: 90px;
  height: 120px;
  margin: 0 auto 1rem;
  border-radius: 4px 10px 10px 4px;
  background: linear-gradient(90deg, #5a1c22, var(--rojo));
  box-shadow: 12px 16px 0 rgba(255, 255, 255, 0.06);
}

.mesa {
  position: fixed;
  inset: auto 0 0;
  height: 38vh;
  background:
    linear-gradient(180deg, transparent, rgba(180, 200, 235, 0.2) 12%, #c8b8a0 38%, #b09a82 62%, #8e7a68);
  z-index: 1;
}

.mesa::before {
  content: "";
  position: absolute;
  left: 10%;
  right: 10%;
  top: 22%;
  height: 28px;
  background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.45), transparent 70%);
  filter: blur(8px);
}

.lampara {
  position: fixed;
  top: -18%;
  left: 50%;
  width: 90vw;
  height: 82vh;
  transform: translateX(-50%);
  background: radial-gradient(ellipse at center, rgba(255, 248, 220, 0.62), rgba(255, 210, 230, 0.2) 42%, rgba(180, 210, 255, 0.12) 62%, transparent 74%);
  pointer-events: none;
  z-index: 2;
}

.libro-barra {
  position: relative;
  z-index: 6;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 1rem;
  align-items: center;
  padding: 0.9rem 1.2rem;
}

.libro-titulos {
  text-align: center;
}

.libro-titulos h1 {
  font-size: clamp(1.3rem, 3vw, 2.1rem);
}

.libro-titulos p {
  margin: 0.15rem 0 0;
  color: var(--tinta-suave);
  font-size: 0.9rem;
}

.libro-acciones {
  display: flex;
  gap: 0.45rem;
}

.escena-libro {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  min-height: calc(100vh - 150px);
  padding: 0 0.6rem 1rem;
}

.escenario {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 70vh;
  perspective: 2200px;
  perspective-origin: 50% 42%;
}

.pista-abrir {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  padding: 0.4rem 0.8rem;
  border-radius: 999px;
  color: #fff6e0;
  font-size: 0.86rem;
  z-index: 5;
  pointer-events: none;
  animation: pista 2.4s ease-in-out infinite;
}

.pista-abrir.oculto {
  display: none;
}

@keyframes pista {
  50% { transform: translateX(-50%) translateY(-4px); opacity: 0.65; }
}

.libro {
  position: relative;
  width: min(920px, 92vw);
  height: min(640px, 72vh);
  transform-style: preserve-3d;
  transform: rotateX(6deg);
  transition: transform 0.7s ease, width 0.7s ease;
  cursor: pointer;
  user-select: none;
  touch-action: none;
}

.libro::after {
  content: "";
  position: absolute;
  left: 10%;
  right: 10%;
  bottom: -26px;
  height: 36px;
  background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.5), transparent 70%);
  pointer-events: none;
  z-index: 0;
}

.libro.cerrado:not(.retrato) {
  width: min(460px, 48vw);
  transform: rotateX(8deg) rotateY(-16deg);
}

.libro.abierto {
  transform: rotateX(2deg);
  cursor: default;
}

.libro.retrato {
  width: min(430px, 86vw);
}

.pagina {
  position: absolute;
  top: 0;
  width: 50%;
  height: 100%;
  overflow: hidden;
  background: #f7efe3;
  z-index: 2;
}

.pagina.izq {
  left: 0;
  border-radius: 10px 0 0 10px;
  box-shadow: inset -18px 0 24px rgba(80, 40, 20, 0.08);
}

.pagina.der {
  left: 50%;
  border-radius: 0 10px 10px 0;
  box-shadow: inset 18px 0 24px rgba(80, 40, 20, 0.08);
}

.libro.cerrado:not(.retrato) .pagina.izq,
.libro.cerrado:not(.retrato) .contraportada,
.libro.cerrado:not(.retrato) .sombra-pliegue {
  display: none;
}

.libro.cerrado:not(.retrato) .pagina.der,
.libro.retrato .pagina.der {
  left: 0;
  width: 100%;
  border-radius: 4px 10px 10px 4px;
}

.libro.retrato .pagina.izq {
  display: none;
}

.pagina img,
.voltea img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
}

.guarda-pagina {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  padding: 2rem;
  background:
    radial-gradient(circle at 20% 20%, rgba(230, 57, 70, 0.12), transparent 40%),
    linear-gradient(180deg, #f3e6d4, #ead7bc);
  color: #6b2a28;
  text-align: center;
}

.guarda-pagina h3 {
  font-family: var(--fuente-titulo);
  font-size: 2rem;
  margin: 0 0 0.5rem;
}

.guarda-pagina p {
  max-width: 16rem;
  line-height: 1.45;
}

.hilo-dibujo {
  width: 180px;
  height: 40px;
  margin: 0 auto 1rem;
}

.voltea {
  position: absolute;
  top: 0;
  left: 50%;
  width: 50%;
  height: 100%;
  transform-origin: left center;
  transform-style: preserve-3d;
  z-index: 6;
  pointer-events: none;
  display: none;
}

.libro.retrato .voltea,
.libro.cerrado:not(.retrato) .voltea {
  left: 0;
  width: 100%;
}

.voltea.activo {
  display: block;
}

.voltea.adelante {
  animation: volar-adelante 0.85s cubic-bezier(0.645, 0.045, 0.355, 1) forwards;
}

.voltea.atras {
  animation: volar-atras 0.85s cubic-bezier(0.645, 0.045, 0.355, 1) forwards;
}

.voltea .cara {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  overflow: hidden;
  background: #f7efe3;
}

.voltea .frente {
  border-radius: 0 10px 10px 0;
}

.voltea .dorso {
  transform: rotateY(180deg);
  border-radius: 10px 0 0 10px;
}

@keyframes volar-adelante {
  from { transform: rotateY(0deg); }
  to { transform: rotateY(-180deg); }
}

@keyframes volar-atras {
  from { transform: rotateY(-180deg); }
  to { transform: rotateY(0deg); }
}

.tapa-dura {
  position: absolute;
  inset: -8px auto -8px 50%;
  width: calc(50% + 8px);
  background: linear-gradient(90deg, #4a1518, #2b0d10 18%, #5a1b20);
  border-radius: 0 14px 14px 0;
  z-index: 1;
  box-shadow: 8px 12px 18px rgba(0, 0, 0, 0.28);
  pointer-events: none;
}

.libro.retrato .tapa-dura,
.libro.cerrado:not(.retrato) .tapa-dura {
  left: 0;
  width: calc(100% + 8px);
}

.contraportada {
  position: absolute;
  inset: -8px 50% -8px auto;
  width: calc(50% + 8px);
  background: linear-gradient(270deg, #4a1518, #2b0d10 18%, #5a1b20);
  border-radius: 14px 0 0 14px;
  z-index: 1;
  pointer-events: none;
}

.libro.retrato .contraportada {
  display: none;
}

.lomo-libro {
  position: absolute;
  top: -8px;
  bottom: -8px;
  left: calc(50% - 9px);
  width: 18px;
  background: linear-gradient(90deg, #2a0c10, #7a2228, #2a0c10);
  z-index: 4;
  box-shadow: inset 0 0 8px rgba(0, 0, 0, 0.45);
  pointer-events: none;
}

.libro.retrato .lomo-libro,
.libro.cerrado:not(.retrato) .lomo-libro {
  left: -8px;
}

.grosor-der,
.grosor-izq {
  position: absolute;
  top: 2px;
  bottom: 2px;
  width: 10px;
  background: repeating-linear-gradient(180deg, #f4e7d2 0 2px, #deccb0 2px 3px);
  pointer-events: none;
  z-index: 3;
}

.grosor-der { left: calc(100% - 2px); }
.grosor-izq { right: calc(100% - 2px); opacity: 0; }

.sombra-pliegue {
  position: absolute;
  inset: 0 auto 0 50%;
  width: 40px;
  transform: translateX(-50%);
  background: linear-gradient(90deg, rgba(0,0,0,.16), transparent 70%);
  pointer-events: none;
  z-index: 5;
  opacity: 0;
}

.libro.abierto:not(.retrato) .sombra-pliegue {
  opacity: 1;
}

.esquina {
  position: absolute;
  width: 70px;
  height: 70px;
  z-index: 7;
  pointer-events: none;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, transparent 50%, rgba(193, 18, 31, 0.18) 50%);
  animation: doblez 2.2s ease-in-out infinite;
}

.libro.cerrado .esquina {
  display: none;
}

@keyframes doblez {
  50% { opacity: 0.35; }
}

.nav-hoja {
  width: 54px;
  height: 54px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 250, 242, 0.12);
  color: #fff;
  font-size: 2rem;
  line-height: 1;
  z-index: 6;
}

.nav-hoja:disabled {
  opacity: 0.25;
  cursor: default;
}

.libro-pie {
  position: relative;
  z-index: 6;
  padding: 0 1.5rem 1.2rem;
  text-align: center;
}

.hilo-progreso {
  position: relative;
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  overflow: visible;
  max-width: 420px;
  margin: 0 auto 0.7rem;
}

.hilo-lleno {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, #9d0208, #e63946);
  box-shadow: 0 0 12px rgba(230, 57, 70, 0.7);
  transition: width 0.4s ease;
}

.hilo-nudo {
  position: absolute;
  top: 50%;
  left: 0%;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--rojo-suave);
  transform: translate(-50%, -50%);
  box-shadow: 0 0 10px rgba(230, 57, 70, 0.9);
  transition: left 0.4s ease;
}

.contador {
  margin: 0;
  color: var(--tinta);
  font-weight: 700;
}

.atajos {
  display: flex;
  justify-content: center;
  gap: 1rem;
  color: var(--tinta-muted);
  font-size: 0.8rem;
  margin-top: 0.35rem;
}

.fin-fiesta {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 20;
}

@media (max-width: 860px) {
  .portales,
  .carta-libro {
    grid-template-columns: 1fr;
  }

  .libro-3d {
    margin-bottom: 0.4rem;
  }

  .libro-barra {
    grid-template-columns: 1fr auto;
  }

  .libro-titulos {
    display: none;
  }

  .escena-libro {
    grid-template-columns: 1fr;
    min-height: calc(100vh - 180px);
  }

  .nav-hoja {
    position: fixed;
    bottom: 1.1rem;
    z-index: 9;
  }

  .nav-hoja.prev { left: 1rem; }
  .nav-hoja.next { right: 1rem; }

  .atajos {
    display: none;
  }

  .libro {
    transform: rotateX(2deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
