:root {
  --burgundy: #7a1f2b;
  --burgundy-dark: #56141d;
  --gold: #d2b48c;
  --ink: #252525;
  --muted: #6b6b6b;
  --paper: #fffefb;
  --line: rgba(37, 37, 37, 0.16);
  --header-height: 76px;
  color-scheme: light;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body { margin: 0; background: #e9e6e2; color: var(--ink); }
button, a { font: inherit; }
button { color: inherit; }

.app { min-height: 100dvh; display: flex; flex-direction: column; }
.site-header {
  min-height: var(--header-height);
  padding: 12px clamp(16px, 3vw, 36px);
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--burgundy);
  color: white;
  border-bottom: 4px solid var(--gold);
  box-shadow: 0 4px 16px rgba(0, 0, 0, .16);
  position: relative;
  z-index: 30;
}
.brand-mark {
  width: 46px;
  height: 46px;
  flex: 0 0 auto;
  border: 2px solid var(--gold);
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--gold);
  font-weight: 800;
  letter-spacing: .04em;
}
.brand-copy { min-width: 0; }
.eyebrow {
  margin: 0 0 2px;
  color: var(--gold);
  font-size: .75rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
}
h1 {
  margin: 0;
  font-size: clamp(1.05rem, 2vw, 1.45rem);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.viewer-shell {
  min-height: calc(100dvh - var(--header-height));
  position: relative;
  overflow: hidden;
}
.viewer {
  min-width: 0;
  min-height: calc(100dvh - var(--header-height));
  height: calc(100dvh - var(--header-height));
  position: relative;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  background:
    radial-gradient(circle at 50% 18%, rgba(255,255,255,.8), transparent 46%),
    linear-gradient(150deg, #d9d5d0, #f3f1ee 49%, #d4d0cb);
}

.book-stage {
  min-width: 0;
  min-height: 0;
  padding: clamp(8px, 1.6vw, 22px);
  display: grid;
  place-items: center;
  overflow: hidden;
  touch-action: pan-y;
}

.book {
  width: 700px;
  height: 480px;
  position: relative;
  perspective: 2600px;
  -webkit-perspective: 2600px;
  transform-style: preserve-3d;
  -webkit-transform-style: preserve-3d;
  --book-cover-offset: 0%;
  transform: translateX(var(--book-cover-offset));
  transform-origin: center center;
  transition: transform 650ms cubic-bezier(.22,.68,.24,1);
  outline: none;
  user-select: none;
  -webkit-user-select: none;
}
.book:focus-visible { outline: 3px solid rgba(210,180,140,.9); outline-offset: 7px; }

.book-base,
.sheet {
  position: absolute;
  top: 0;
  width: 50%;
  height: 100%;
}
.book-base {
  background: #fff;
  border: 1px solid rgba(0,0,0,.12);
  box-shadow: inset 0 0 24px rgba(0,0,0,.035), 0 20px 28px rgba(0,0,0,.20);
}
.base-left { left: 0; border-radius: 6px 0 0 6px; }
.base-right { right: 0; border-radius: 0 6px 6px 0; }

.sheets { position: absolute; inset: 0; transform-style: preserve-3d; -webkit-transform-style: preserve-3d; }
.sheet {
  right: 0;
  transform-origin: left center;
  -webkit-transform-origin: left center;
  transform-style: preserve-3d;
  -webkit-transform-style: preserve-3d;
  transform: rotateY(0deg);
  -webkit-transform: rotateY(0deg);
  transition: transform 520ms cubic-bezier(.22,.68,.24,1);
  -webkit-transition: -webkit-transform 520ms cubic-bezier(.22,.68,.24,1);
}
.sheet.cover-sheet { transition-duration: 700ms; -webkit-transition-duration: 700ms; }
.sheet.turning,
.sheet.turning-back { will-change: transform; }
.sheet.is-dormant { visibility: hidden; }
.sheet.flipped { transform: rotateY(-180deg); -webkit-transform: rotateY(-180deg); }
.sheet.turning .page-front,
.sheet.turning .page-back { box-shadow: -10px 8px 16px rgba(0,0,0,.25); }
.sheet.turning-back .page-front,
.sheet.turning-back .page-back { box-shadow: 10px 8px 16px rgba(0,0,0,.25); }

.page-face {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: white;
  border: 1px solid rgba(0,0,0,.11);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  transform-style: preserve-3d;
  -webkit-transform-style: preserve-3d;
}
.page-front { transform: rotateY(0deg) translateZ(.6px); -webkit-transform: rotateY(0deg) translateZ(.6px); border-radius: 0 6px 6px 0; }
.page-back { transform: rotateY(180deg) translateZ(.6px); -webkit-transform: rotateY(180deg) translateZ(.6px); border-radius: 6px 0 0 6px; }
.page-face::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: .12;
}
.page-front::after { background: linear-gradient(90deg, rgba(0,0,0,.18), transparent 7%, transparent 93%, rgba(255,255,255,.25)); }
.page-back::after { background: linear-gradient(270deg, rgba(0,0,0,.18), transparent 7%, transparent 93%, rgba(255,255,255,.25)); }

.page-image {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  background: white;
  opacity: 0;
  -webkit-user-drag: none;
}
.page-face.ready .page-image { opacity: 1; }
.page-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: .8rem;
  background: linear-gradient(110deg, #f1f1f1 18%, #fafafa 38%, #f1f1f1 58%);
  background-size: 200% 100%;
  animation: shimmer 1.35s linear infinite;
}
.page-face.ready .page-placeholder { display: none; }
@keyframes shimmer { to { background-position-x: -200%; } }

.book.is-front-cover { --book-cover-offset: -25%; }
.book.is-back-cover { --book-cover-offset: 25%; }

.book-base {
  transition: opacity 220ms ease, visibility 220ms ease;
}
.book.is-front-cover .base-left,
.book.is-back-cover .base-right {
  opacity: 0;
  visibility: hidden;
}

.book-spine {
  position: absolute;
  z-index: 5000;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 18px;
  transform: translateX(-50%);
  pointer-events: none;
  background: linear-gradient(90deg, transparent, rgba(0,0,0,.14) 46%, rgba(255,255,255,.42) 50%, rgba(0,0,0,.12) 54%, transparent);
  opacity: .72;
  transition: opacity 220ms ease;
}
.book.is-front-cover .book-spine,
.book.is-back-cover .book-spine { opacity: 0; }

.toolbar {
  min-height: 68px;
  padding: 10px clamp(12px, 2vw, 24px) calc(10px + env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: minmax(130px, 1fr) auto minmax(190px, 1fr);
  align-items: center;
  gap: 12px;
  background: rgba(255,255,255,.95);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(10px);
  position: relative;
  z-index: 20;
}
.toolbar-actions { justify-self: end; display: flex; gap: 8px; flex-wrap: wrap; }
.page-navigation { display: flex; align-items: center; justify-content: center; gap: 10px; }
.page-counter { min-width: 140px; text-align: center; font-weight: 750; font-variant-numeric: tabular-nums; }

.tool-button,
.icon-button {
  border: 1px solid var(--line);
  background: white;
  border-radius: 10px;
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 12px;
  text-decoration: none;
  color: var(--ink);
  cursor: pointer;
  transition: background-color .18s ease, border-color .18s ease, transform .18s ease;
}
.icon-button { width: 42px; padding: 8px; }
.tool-button:hover, .icon-button:hover { background: #f5efea; border-color: rgba(122,31,43,.45); }
.tool-button:active, .icon-button:active { transform: translateY(1px); }
.tool-button[aria-pressed="true"] { background: #f7efe7; border-color: rgba(122,31,43,.45); }
.tool-button:focus-visible, .icon-button:focus-visible, .thumbnail-button:focus-visible { outline: 3px solid rgba(210,180,140,.9); outline-offset: 2px; }
button:disabled { opacity: .38; cursor: not-allowed; transform: none; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; flex: 0 0 auto; }

.thumbnails-panel {
  width: min(300px, 88vw);
  min-height: 0;
  background: #fff;
  border-right: 1px solid var(--line);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  transform: translateX(-102%);
  transition: transform .22s ease;
  position: absolute;
  inset: 0 auto 0 0;
  z-index: 50;
  box-shadow: 12px 0 30px rgba(0,0,0,.22);
}
.thumbnails-panel.is-open { transform: translateX(0); }
.panel-header { min-height: 58px; padding: 8px 12px 8px 18px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); }
.thumbnails-list { min-height: 0; overflow: auto; padding: 12px; }
.thumbnail-button {
  width: 100%;
  border: 0;
  background: transparent;
  padding: 8px;
  border-radius: 10px;
  cursor: pointer;
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 12px;
  align-items: center;
  text-align: left;
  color: var(--ink);
}
.thumbnail-button:hover { background: #f4f1ee; }
.thumbnail-button.is-active { background: #f1e6e1; color: var(--burgundy-dark); }
.thumbnail-frame { width: 72px; aspect-ratio: 612 / 841; background: #eee; border: 1px solid var(--line); box-shadow: 0 4px 10px rgba(0,0,0,.12); overflow: hidden; }
.thumbnail-frame img { width: 100%; height: 100%; display: block; object-fit: contain; background: white; }
.thumbnail-label { font-size: .9rem; font-weight: 700; }

.status-overlay {
  position: absolute;
  inset: 0 0 68px;
  z-index: 60;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 12px;
  padding: 24px;
  background: rgba(245,243,240,.97);
  text-align: center;
}
.status-overlay[hidden] { display: none; }
.spinner { width: 42px; height: 42px; border-radius: 50%; border: 4px solid rgba(122,31,43,.18); border-top-color: var(--burgundy); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.progress-track { width: min(320px, 72vw); height: 7px; border-radius: 999px; overflow: hidden; background: rgba(122,31,43,.13); }
.progress-track span { display: block; width: 8%; height: 100%; background: var(--burgundy); transition: width .2s ease; }
.noscript-message { margin: 20px; padding: 16px; background: white; border-left: 5px solid var(--burgundy); }

.app:fullscreen,
.app:-webkit-full-screen { width: 100vw; height: 100vh; min-height: 100vh; background: #e9e6e2; }
.app:fullscreen .viewer-shell,
.app:-webkit-full-screen .viewer-shell { min-height: 0; height: calc(100vh - var(--header-height)); }
.app:fullscreen .viewer,
.app:-webkit-full-screen .viewer { min-height: 0; height: 100%; }

@media (max-width: 860px) {
  :root { --header-height: 68px; }
  .site-header { padding: 9px 14px; }
  .brand-mark { width: 42px; height: 42px; }
  .eyebrow { font-size: .64rem; }
  .toolbar { grid-template-columns: auto 1fr auto; min-height: 62px; padding-inline: 8px; }
  .tool-button span { display: none; }
  .tool-button { width: 42px; padding: 8px; }
  .toolbar-actions { gap: 5px; }
  .page-counter { min-width: 104px; font-size: .84rem; }
  .book-stage { padding: 5px; }
  .status-overlay { bottom: 62px; }
  .book-spine { width: 12px; }
}

@media (max-width: 460px) {
  .brand-mark { display: none; }
  .site-header { min-height: 62px; }
  .eyebrow { display: none; }
  h1 { font-size: 1rem; }
  .page-counter { min-width: 84px; font-size: .76rem; }
  .page-navigation { gap: 3px; }
  .toolbar { gap: 3px; }
}

@media (prefers-reduced-motion: reduce) {
  .sheet { transition-duration: 250ms !important; }
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}

/* Visor móvil: una página legible, desplazamiento horizontal y zoom táctil. */
.mobile-reader {
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  outline: none;
}

.mobile-reader:focus-visible {
  outline: 3px solid rgba(210,180,140,.9);
  outline-offset: -3px;
}

.mobile-page-viewport {
  width: 320px;
  height: 440px;
  max-width: 100%;
  max-height: 100%;
  position: relative;
  flex: 0 0 auto;
  overflow: hidden;
  border-radius: 5px;
  background: #fff;
  border: 1px solid rgba(0,0,0,.13);
  box-shadow: 0 14px 28px rgba(0,0,0,.22);
  touch-action: none;
  overscroll-behavior: contain;
}

.mobile-page-layer {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: #fff;
  transform: translate3d(0,0,0);
  opacity: 1;
  will-change: transform, opacity;
}

.mobile-page-current { z-index: 2; }
.mobile-page-incoming {
  z-index: 3;
  opacity: 0;
  pointer-events: none;
}

.mobile-page-viewport.is-animating .mobile-page-layer {
  transition: transform 285ms cubic-bezier(.22,.68,.24,1), opacity 245ms ease;
}

.mobile-page-content {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  transform: translate3d(0,0,0) scale(1);
  transform-origin: center center;
  will-change: transform;
}

.mobile-page-content img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  background: #fff;
  -webkit-user-drag: none;
  pointer-events: none;
}

.mobile-page-loader {
  position: absolute;
  z-index: 8;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: .84rem;
  background: rgba(247,245,242,.94);
}
.mobile-page-loader[hidden] { display: none; }

.mobile-help {
  margin: 0;
  min-height: 18px;
  padding: 0 8px;
  color: #5e5e5e;
  font-size: .72rem;
  line-height: 1.25;
  text-align: center;
  transition: opacity .25s ease;
}
.mobile-help.is-hidden { opacity: 0; }

.mobile-only-control { display: none; }
html.mobile-mode .book { display: none; }
html.mobile-mode .mobile-reader { display: flex; }
html.mobile-mode .mobile-only-control { display: inline-flex; }
html.mobile-mode .book-stage {
  padding: 5px;
  touch-action: none;
}

html.mobile-mode .page-counter { min-width: 76px; }

@media (max-width: 900px) {
  :root { --header-height: 58px; }
  .site-header {
    min-height: var(--header-height);
    padding: 7px 10px;
  }
  .brand-mark {
    width: 38px;
    height: 38px;
    font-size: .88rem;
  }
  .eyebrow { font-size: .58rem; }
  h1 { font-size: .92rem; }

  .toolbar {
    min-height: 54px;
    grid-template-columns: 36px minmax(116px, 1fr) auto;
    gap: 4px;
    padding: 6px 5px calc(6px + env(safe-area-inset-bottom));
  }
  .tool-button,
  .icon-button {
    width: 36px;
    min-width: 36px;
    min-height: 36px;
    height: 36px;
    padding: 6px;
    border-radius: 8px;
  }
  .tool-button span { display: none; }
  .toolbar-actions {
    gap: 3px;
    flex-wrap: nowrap;
  }
  .page-navigation { gap: 2px; }
  .page-counter {
    min-width: 70px;
    font-size: .76rem;
  }
  .status-overlay { bottom: 54px; }
  svg { width: 18px; height: 18px; }
}

@media (max-width: 380px) {
  .toolbar {
    grid-template-columns: 34px minmax(102px, 1fr) auto;
    gap: 2px;
    padding-inline: 3px;
  }
  .tool-button,
  .icon-button {
    width: 34px;
    min-width: 34px;
    height: 34px;
    min-height: 34px;
    padding: 5px;
  }
  .toolbar-actions { gap: 2px; }
  .page-counter { min-width: 58px; font-size: .7rem; }
  .brand-mark { display: none; }
  .eyebrow { display: none; }
}

html.mobile-mode .app:fullscreen,
html.mobile-mode .app:-webkit-full-screen {
  --header-height: 0px;
}
html.mobile-mode .app:fullscreen .site-header,
html.mobile-mode .app:-webkit-full-screen .site-header {
  display: none;
}

/* --------------------------------------------------------------------------
   Versión 8: giro real de hoja en móvil y lectura horizontal a pantalla completa
   -------------------------------------------------------------------------- */

.mobile-page-viewport {
  perspective: 1800px;
  -webkit-perspective: 1800px;
  transform-style: preserve-3d;
  -webkit-transform-style: preserve-3d;
}

.mobile-page-base,
.mobile-turn-sheet {
  position: absolute;
  inset: 0;
}

.mobile-page-base {
  z-index: 1;
  overflow: hidden;
  background: #fff;
}

.mobile-page-base img,
.mobile-turn-face img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  background: #fff;
  pointer-events: none;
  -webkit-user-drag: none;
}

.mobile-page-current {
  z-index: 2;
  visibility: visible;
}

.mobile-turn-sheet {
  z-index: 5;
  transform-origin: left center;
  -webkit-transform-origin: left center;
  transform-style: preserve-3d;
  -webkit-transform-style: preserve-3d;
  will-change: transform;
  pointer-events: none;
}

.mobile-turn-sheet[hidden] {
  display: none;
}

.mobile-turn-face {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: #fff;
  border: 1px solid rgba(0,0,0,.12);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  transform-style: preserve-3d;
  -webkit-transform-style: preserve-3d;
}

.mobile-turn-front {
  transform: rotateY(0deg) translateZ(.5px);
  -webkit-transform: rotateY(0deg) translateZ(.5px);
}

.mobile-turn-back {
  transform: rotateY(180deg) translateZ(.5px);
  -webkit-transform: rotateY(180deg) translateZ(.5px);
}

.mobile-turn-face::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 240ms ease;
}

.mobile-turn-front::after {
  background: linear-gradient(90deg, rgba(0,0,0,.30), transparent 18%, transparent 82%, rgba(255,255,255,.22));
}

.mobile-turn-back::after {
  background: linear-gradient(270deg, rgba(0,0,0,.30), transparent 18%, transparent 82%, rgba(255,255,255,.22));
}

.mobile-page-viewport.is-page-turning .mobile-turn-face::after {
  opacity: .55;
}

.mobile-page-viewport.is-page-turning .mobile-page-current {
  visibility: hidden;
}

.mobile-page-viewport.is-turning-forward .mobile-turn-sheet {
  transition: transform 540ms cubic-bezier(.24,.62,.22,1);
  -webkit-transition: -webkit-transform 540ms cubic-bezier(.24,.62,.22,1);
  box-shadow: -14px 8px 22px rgba(0,0,0,.28);
}

.mobile-page-viewport.is-turning-back .mobile-turn-sheet {
  transition: transform 540ms cubic-bezier(.24,.62,.22,1);
  -webkit-transition: -webkit-transform 540ms cubic-bezier(.24,.62,.22,1);
  box-shadow: 14px 8px 22px rgba(0,0,0,.28);
}

.fullscreen-exit-button {
  position: absolute;
  z-index: 10000;
  top: max(10px, env(safe-area-inset-top));
  right: max(10px, env(safe-area-inset-right));
  width: 42px;
  height: 42px;
  padding: 9px;
  border: 1px solid rgba(255,255,255,.38);
  border-radius: 999px;
  background: rgba(0,0,0,.38);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  opacity: .62;
  backdrop-filter: blur(8px);
  transition: opacity .18s ease, background-color .18s ease;
}

.fullscreen-exit-button:hover,
.fullscreen-exit-button:focus-visible {
  opacity: 1;
  background: rgba(0,0,0,.68);
}

.fullscreen-exit-button[hidden] {
  display: none !important;
}

html.reading-fullscreen,
html.reading-fullscreen body {
  overflow: hidden !important;
  overscroll-behavior: none;
  background: #111;
}

.book-stage:fullscreen,
.book-stage:-webkit-full-screen,
.book-stage.immersive-fallback {
  width: 100vw;
  width: 100dvw;
  height: 100vh;
  height: 100dvh;
  min-width: 0;
  min-height: 0;
  padding: 0 !important;
  margin: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: #111;
  touch-action: none;
}

.book-stage.immersive-fallback {
  position: fixed !important;
  inset: 0 !important;
  z-index: 99999;
}

html.reading-fullscreen .book-stage .mobile-reader {
  display: none !important;
}

html.reading-fullscreen .book-stage .book {
  display: block !important;
}

html.reading-fullscreen .book-stage.force-landscape-rotation {
  position: fixed !important;
  inset: auto !important;
  left: 50% !important;
  top: 50% !important;
  width: 100vh !important;
  width: 100dvh !important;
  height: 100vw !important;
  height: 100dvw !important;
  transform: translate(-50%, -50%) rotate(90deg);
  transform-origin: center center;
}

html.reading-fullscreen .book-stage .book {
  filter: drop-shadow(0 18px 30px rgba(0,0,0,.48));
}


html.reading-fullscreen .book-stage .book {
  touch-action: none;
  cursor: grab;
}

html.reading-fullscreen .book-stage .book.is-fullscreen-zoomed {
  cursor: grabbing;
}

html.reading-fullscreen .book-stage .book.fullscreen-gesture-active {
  transition: none !important;
}

html.reading-fullscreen .book-stage .book.animate-fullscreen-transform {
  transition: transform 220ms ease !important;
}

html.reading-fullscreen .book-stage .book-base {
  box-shadow: inset 0 0 24px rgba(0,0,0,.035), 0 15px 26px rgba(0,0,0,.42);
}

@media (max-width: 900px) {
  .mobile-page-viewport {
    border-radius: 4px;
  }
}

html.reading-fullscreen .book-stage.force-landscape-rotation .fullscreen-exit-button {
  transform: rotate(-90deg);
}

/* La cara posterior se distingue del contenido que queda debajo; al final se
   desvanece para revelar la página nueva sin una pantalla blanca. */
.mobile-page-viewport.is-turning-forward .mobile-turn-sheet {
  opacity: 0;
  transition:
    transform 540ms cubic-bezier(.24,.62,.22,1),
    opacity 100ms linear 440ms;
  -webkit-transition:
    -webkit-transform 540ms cubic-bezier(.24,.62,.22,1),
    opacity 100ms linear 440ms;
}

.mobile-page-viewport.is-turning-forward .mobile-turn-back img {
  filter: brightness(.72) saturate(.72);
  opacity: .9;
}

.mobile-page-viewport.is-turning-forward .mobile-turn-back::after {
  opacity: .72;
  background:
    linear-gradient(270deg, rgba(0,0,0,.36), rgba(255,248,232,.28) 30%, rgba(255,255,255,.08) 72%, rgba(0,0,0,.12));
}

/* --------------------------------------------------------------------------
   Versión 13: zoom estable en pantalla completa
   El zoom se aplica a una copia 2D del pliego visible. De esta forma el
   navegador no tiene que escalar simultáneamente todas las capas 3D del libro,
   evitando el parpadeo negro de algunos teléfonos.
   -------------------------------------------------------------------------- */

.book-stage {
  position: relative;
}

.fullscreen-zoom-surface {
  --fullscreen-pan-x: 0px;
  --fullscreen-pan-y: 0px;
  --fullscreen-zoom: 1;
  width: 700px;
  height: 480px;
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 7;
  overflow: visible;
  transform:
    translate3d(
      calc(-50% + var(--fullscreen-pan-x)),
      calc(-50% + var(--fullscreen-pan-y)),
      0
    )
    scale3d(var(--fullscreen-zoom), var(--fullscreen-zoom), 1);
  -webkit-transform:
    translate3d(
      calc(-50% + var(--fullscreen-pan-x)),
      calc(-50% + var(--fullscreen-pan-y)),
      0
    )
    scale3d(var(--fullscreen-zoom), var(--fullscreen-zoom), 1);
  transform-origin: center center;
  -webkit-transform-origin: center center;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  isolation: isolate;
  contain: layout paint;
  touch-action: none;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
}

.fullscreen-zoom-surface[hidden] {
  display: none !important;
}

.fullscreen-zoom-surface.is-active {
  display: block;
}

.fullscreen-zoom-surface.is-fullscreen-zoomed {
  cursor: grabbing;
}

.fullscreen-zoom-surface.fullscreen-gesture-active {
  transition: none !important;
  -webkit-transition: none !important;
  will-change: transform;
}

.fullscreen-zoom-surface.animate-fullscreen-transform {
  transition: transform 220ms ease !important;
  -webkit-transition: -webkit-transform 220ms ease !important;
  will-change: transform;
}

.fullscreen-static-spread {
  --static-cover-offset: 0%;
  position: absolute;
  inset: 0;
  transform: translate3d(var(--static-cover-offset), 0, 0);
  -webkit-transform: translate3d(var(--static-cover-offset), 0, 0);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.fullscreen-static-spread.is-front-cover {
  --static-cover-offset: -25%;
}

.fullscreen-static-spread.is-back-cover {
  --static-cover-offset: 25%;
}

.fullscreen-static-page {
  position: absolute;
  top: 0;
  width: 50%;
  height: 100%;
  overflow: hidden;
  background: #fff;
  border: 1px solid rgba(0,0,0,.12);
  box-shadow: 0 15px 26px rgba(0,0,0,.42), inset 0 0 20px rgba(0,0,0,.035);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.fullscreen-static-left {
  left: 0;
  border-radius: 6px 0 0 6px;
}

.fullscreen-static-right {
  right: 0;
  border-radius: 0 6px 6px 0;
}

.fullscreen-static-page img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  background: #fff;
  pointer-events: none;
  -webkit-user-drag: none;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.fullscreen-static-page.is-empty {
  opacity: 0;
  visibility: hidden;
}

.fullscreen-static-spine {
  position: absolute;
  z-index: 3;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 18px;
  transform: translateX(-50%);
  pointer-events: none;
  background: linear-gradient(90deg, transparent, rgba(0,0,0,.14) 46%, rgba(255,255,255,.42) 50%, rgba(0,0,0,.12) 54%, transparent);
  opacity: .72;
}

.fullscreen-static-spread.is-front-cover .fullscreen-static-left,
.fullscreen-static-spread.is-back-cover .fullscreen-static-right {
  opacity: 0;
  visibility: hidden;
}

.fullscreen-static-spread.is-front-cover .fullscreen-static-spine,
.fullscreen-static-spread.is-back-cover .fullscreen-static-spine {
  opacity: 0;
}

html.mobile-mode .fullscreen-zoom-surface {
  display: none;
}

html.reading-fullscreen .book-stage .book {
  filter: none !important;
}

html.reading-fullscreen .book-stage .book.is-fullscreen-source-hidden {
  opacity: 0;
  pointer-events: none;
}

/* ==========================================================================
   V14 — INTERFAZ MODERNA COLEGIO SAINT THOMAS
   Rediseño de la página del visor. El contenido del anuario no se modifica.
   ========================================================================== */

:root {
  --stc-burgundy: #861f32;
  --stc-burgundy-dark: #681526;
  --stc-gold: #bb9955;
  --stc-gold-soft: #d6c28f;
  --stc-cream: #fbfaf7;
  --stc-surface: #ffffff;
  --stc-ink: #282525;
  --stc-muted: #746f6b;
  --header-height: 104px;
  --modern-toolbar-height: 72px;
  --burgundy: var(--stc-burgundy);
  --burgundy-dark: var(--stc-burgundy-dark);
  --gold: var(--stc-gold);
  --ink: var(--stc-ink);
  --muted: var(--stc-muted);
}

body {
  background: var(--stc-cream);
}

/* Cabecera clara, inspirada en la propuesta moderna aprobada. */
.site-header {
  min-height: var(--header-height);
  height: var(--header-height);
  padding: 10px clamp(18px, 3vw, 46px);
  display: grid;
  grid-template-columns: minmax(235px, 1fr) minmax(300px, 1.3fr) minmax(390px, 1fr);
  align-items: center;
  gap: 18px;
  background: rgba(255,255,255,.98);
  color: var(--stc-ink);
  border: 0;
  border-bottom: 3px solid var(--stc-gold);
  box-shadow: 0 6px 24px rgba(75,52,43,.08);
}

.header-brand {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 16px;
}

.institution-logo {
  width: 82px;
  height: 76px;
  flex: 0 0 auto;
  object-fit: contain;
  display: block;
}

.brand-copy {
  min-width: 0;
  padding-left: 15px;
  border-left: 1px solid rgba(134,31,50,.14);
  line-height: 1.02;
}

.brand-copy strong {
  display: block;
  color: #393333;
  font-size: clamp(1rem, 1.35vw, 1.28rem);
  font-weight: 520;
  letter-spacing: .005em;
}

.brand-copy span {
  display: block;
  margin-top: 7px;
  color: var(--stc-gold);
  font-size: .72rem;
  font-weight: 750;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.header-title {
  position: relative;
  min-width: 0;
  text-align: center;
  padding-inline: 16px;
}

.header-title::before,
.header-title::after {
  content: "";
  position: absolute;
  top: 54%;
  width: clamp(34px, 4vw, 68px);
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--stc-gold));
}
.header-title::before { left: 0; }
.header-title::after { right: 0; transform: scaleX(-1); }

.header-title p {
  margin: 0;
  color: var(--stc-burgundy);
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.1rem, 1.75vw, 1.7rem);
  font-weight: 400;
  letter-spacing: .055em;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-title h1 {
  margin: 2px 0 0;
  color: var(--stc-gold);
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.2rem, 1.75vw, 1.7rem);
  font-weight: 500;
  letter-spacing: .05em;
}

.header-actions {
  justify-self: end;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: clamp(5px, .75vw, 10px);
}

.header-tool {
  width: clamp(62px, 5.2vw, 78px);
  min-width: 0;
  height: 76px;
  padding: 7px 3px 4px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: #4e4643;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  text-decoration: none;
  cursor: pointer;
  transition: background-color .18s ease, color .18s ease, transform .18s ease;
}

.header-tool:hover,
.header-tool:focus-visible {
  background: #f7f1ed;
  color: var(--stc-burgundy);
}

.header-tool:active { transform: translateY(1px); }
.header-tool[aria-pressed="true"] .header-tool-icon {
  border-color: rgba(134,31,50,.28);
  background: #fbf5f2;
  color: var(--stc-burgundy);
}

.header-tool-icon {
  width: 38px;
  height: 38px;
  border: 1px solid rgba(134,31,50,.12);
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: #fff;
  color: #9c756d;
  box-shadow: 0 4px 12px rgba(80,50,40,.05);
}

.header-tool-icon svg {
  width: 21px;
  height: 21px;
  stroke-width: 1.65;
}

.header-tool-label {
  max-width: 78px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: inherit;
  font-size: .68rem;
  line-height: 1;
  text-align: center;
}

/* Área principal */
.viewer-shell {
  min-height: calc(100dvh - var(--header-height));
  background: var(--stc-cream);
}

.viewer {
  min-height: calc(100dvh - var(--header-height));
  height: calc(100dvh - var(--header-height));
  grid-template-rows: minmax(0, 1fr) var(--modern-toolbar-height);
  background:
    radial-gradient(circle at 50% 12%, rgba(255,255,255,.96), rgba(255,255,255,.52) 42%, transparent 69%),
    linear-gradient(180deg, #fdfcf9 0%, #f6f3ef 100%);
  isolation: isolate;
}

.viewer::before {
  content: "";
  position: absolute;
  z-index: 0;
  left: -8vw;
  bottom: -29vw;
  width: 42vw;
  height: 42vw;
  border-radius: 50%;
  background: rgba(134,31,50,.035);
  pointer-events: none;
}

.viewer::after {
  content: "";
  position: absolute;
  z-index: 0;
  right: -17vw;
  bottom: -18vw;
  width: 37vw;
  height: 37vw;
  border-radius: 50%;
  background: var(--stc-burgundy);
  pointer-events: none;
}

.book-stage {
  position: relative;
  z-index: 1;
  padding: clamp(14px, 1.6vw, 25px) clamp(66px, 7vw, 118px);
  overflow: hidden;
}

.book {
  filter: drop-shadow(0 20px 22px rgba(43,32,29,.25));
}

.book-base {
  border-color: rgba(78,55,48,.15);
  box-shadow: inset 0 0 24px rgba(0,0,0,.026), 0 20px 30px rgba(55,39,34,.17);
}

.decor-dots {
  position: absolute;
  z-index: -1;
  width: 104px;
  height: 104px;
  opacity: .55;
  background-image: radial-gradient(circle, var(--stc-gold) 1.25px, transparent 1.4px);
  background-size: 14px 14px;
  pointer-events: none;
}
.decor-dots-left { left: 2.2vw; top: 18%; }
.decor-dots-right { right: 2.2vw; top: 9%; }

.stage-arrow {
  position: absolute;
  z-index: 12;
  top: 50%;
  width: 52px;
  height: 52px;
  margin-top: -26px;
  padding: 0;
  display: grid;
  place-items: center;
  border: 1px solid rgba(80,60,54,.08);
  border-radius: 50%;
  background: rgba(255,255,255,.96);
  color: var(--stc-burgundy);
  box-shadow: 0 8px 24px rgba(61,45,41,.13);
  cursor: pointer;
  transition: transform .18s ease, box-shadow .18s ease, background-color .18s ease;
}
.stage-arrow:hover:not(:disabled) {
  transform: scale(1.06);
  background: #fff;
  box-shadow: 0 10px 28px rgba(61,45,41,.2);
}
.stage-arrow:disabled { opacity: .3; }
.stage-arrow svg { width: 25px; height: 25px; stroke-width: 1.8; }
.stage-arrow-left { left: clamp(14px, 3vw, 50px); }
.stage-arrow-right { right: clamp(14px, 3vw, 50px); }

/* Barra inferior moderna */
.toolbar {
  min-height: var(--modern-toolbar-height);
  height: var(--modern-toolbar-height);
  padding: 8px clamp(18px, 3.5vw, 58px) calc(8px + env(safe-area-inset-bottom));
  grid-template-columns: minmax(170px, 1fr) auto minmax(230px, 1fr);
  gap: 14px;
  background: linear-gradient(100deg, #73172a, #8b2035 54%, #76182c);
  border: 0;
  border-top: 2px solid var(--stc-gold);
  color: #fff;
  backdrop-filter: none;
  box-shadow: 0 -8px 30px rgba(89,34,43,.11);
}

.home-button,
.nav-button {
  border: 0;
  color: #fff;
  background: transparent;
  cursor: pointer;
}

.home-button {
  justify-self: start;
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 5px 8px;
  border-radius: 9px;
  font-size: .8rem;
}
.home-button:hover { background: rgba(255,255,255,.09); }
.home-button svg { width: 21px; height: 21px; }

.page-navigation {
  gap: 11px;
}

.nav-button {
  width: 40px;
  height: 40px;
  padding: 8px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  transition: background-color .18s ease, opacity .18s ease;
}
.nav-button:hover:not(:disabled) { background: rgba(255,255,255,.11); }
.nav-button svg { width: 24px; height: 24px; stroke-width: 1.7; }

.page-counter {
  min-width: 170px;
  height: 42px;
  padding: 0 18px;
  border-radius: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  color: var(--stc-burgundy);
  box-shadow: 0 5px 15px rgba(45,13,22,.18);
  font-size: .86rem;
  font-weight: 750;
}

.navigation-help {
  justify-self: end;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 9px;
  color: rgba(255,255,255,.87);
  font-size: .72rem;
}
.navigation-help svg { width: 24px; height: 24px; }

/* Miniaturas como bandeja horizontal, no como panel lateral. */
.thumbnails-panel {
  width: auto;
  height: 184px;
  min-height: 0;
  left: clamp(12px, 3vw, 48px);
  right: clamp(12px, 3vw, 48px);
  top: auto;
  bottom: calc(var(--modern-toolbar-height) + 10px);
  inset-block-start: auto;
  background: rgba(255,255,255,.98);
  border: 1px solid rgba(81,59,52,.09);
  border-radius: 20px;
  grid-template-rows: 48px minmax(0, 1fr);
  transform: translateY(calc(100% + var(--modern-toolbar-height) + 32px));
  transition: transform .3s cubic-bezier(.22,.68,.24,1), opacity .2s ease;
  opacity: 0;
  box-shadow: 0 20px 50px rgba(56,38,34,.18);
  overflow: hidden;
}
.thumbnails-panel.is-open {
  transform: translateY(0);
  opacity: 1;
}

.panel-header {
  min-height: 48px;
  padding: 7px 10px 7px 18px;
  border-bottom: 1px solid rgba(81,59,52,.08);
  background: #fff;
}
.panel-header > div {
  display: flex;
  align-items: baseline;
  gap: 12px;
  min-width: 0;
}
.panel-header strong {
  color: var(--stc-burgundy);
  font-size: .84rem;
}
.panel-header span {
  color: var(--stc-muted);
  font-size: .7rem;
}
.panel-close {
  border: 0;
  background: transparent;
  color: var(--stc-burgundy);
}

.thumbnails-list {
  display: flex;
  align-items: stretch;
  gap: 6px;
  padding: 8px 14px 12px;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x proximity;
}

.thumbnail-button {
  width: 92px;
  min-width: 92px;
  padding: 5px;
  border-radius: 9px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  align-items: center;
  justify-content: flex-start;
  text-align: center;
  scroll-snap-align: start;
}
.thumbnail-button:hover { background: #faf5f2; }
.thumbnail-button.is-active {
  background: #fff;
  box-shadow: inset 0 0 0 2px var(--stc-burgundy);
  color: var(--stc-burgundy);
}
.thumbnail-frame {
  width: 51px;
  height: 70px;
  flex: 0 0 auto;
  border-radius: 2px;
  border-color: rgba(83,58,50,.13);
  box-shadow: 0 3px 9px rgba(59,43,38,.12);
}
.thumbnail-label {
  max-width: 80px;
  font-size: .62rem;
  line-height: 1.1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Pantalla de carga institucional */
.status-overlay {
  inset: 0 0 var(--modern-toolbar-height);
  background: rgba(252,250,247,.98);
  gap: 10px;
}
.loading-logo {
  width: 98px;
  height: 86px;
  object-fit: contain;
  animation: logoPulse 1.6s ease-in-out infinite;
}
@keyframes logoPulse { 50% { transform: scale(1.025); opacity: .82; } }
.status-overlay p {
  margin: 0;
  color: var(--stc-burgundy);
  font-size: .83rem;
  font-weight: 650;
}
.progress-track { background: rgba(134,31,50,.10); }
.progress-track span { background: linear-gradient(90deg, var(--stc-burgundy), var(--stc-gold)); }

/* Accesibilidad */
.header-tool:focus-visible,
.home-button:focus-visible,
.nav-button:focus-visible,
.stage-arrow:focus-visible {
  outline: 3px solid rgba(187,153,85,.65);
  outline-offset: 2px;
}

/* Adaptación para notebooks más estrechos */
@media (max-width: 1180px) {
  .site-header {
    grid-template-columns: minmax(190px, .9fr) minmax(260px, 1.1fr) minmax(330px, 1fr);
    padding-inline: 18px;
  }
  .institution-logo { width: 70px; height: 66px; }
  .brand-copy { padding-left: 10px; }
  .brand-copy strong { font-size: 1rem; }
  .header-tool { width: 62px; }
  .header-tool-label { font-size: .61rem; }
  .book-stage { padding-inline: 62px; }
}

/* Móvil: se mantiene el visor funcional aprobado, con una cabecera moderna compacta. */
@media (max-width: 900px) {
  :root {
    --header-height: 66px;
    --modern-toolbar-height: 58px;
  }

  .site-header {
    min-height: var(--header-height);
    height: var(--header-height);
    padding: 5px 7px 5px 9px;
    grid-template-columns: 52px minmax(110px, 1fr) auto;
    gap: 5px;
    border-bottom-width: 2px;
  }

  .header-brand { gap: 0; }
  .institution-logo { width: 48px; height: 52px; }
  .brand-copy { display: none; }

  .header-title {
    text-align: left;
    padding: 0 4px;
  }
  .header-title::before,
  .header-title::after { display: none; }
  .header-title p {
    font-family: Inter, "Segoe UI", Arial, sans-serif;
    font-size: .72rem;
    font-weight: 700;
    letter-spacing: .02em;
    text-transform: none;
  }
  .header-title h1 {
    margin-top: 1px;
    font-family: Inter, "Segoe UI", Arial, sans-serif;
    font-size: .72rem;
    font-weight: 750;
  }

  .header-actions { gap: 1px; }
  .header-tool {
    width: 36px;
    height: 50px;
    padding: 4px 1px;
    gap: 1px;
    border-radius: 7px;
  }
  .header-tool-icon {
    width: 31px;
    height: 31px;
    border: 0;
    box-shadow: none;
    background: transparent;
  }
  .header-tool-icon svg { width: 19px; height: 19px; }
  .header-tool-label { display: none; }

  .viewer {
    grid-template-rows: minmax(0, 1fr) var(--modern-toolbar-height);
  }
  .book-stage {
    padding: 5px;
  }
  .decor-dots,
  .stage-arrow,
  .viewer::before,
  .viewer::after {
    display: none;
  }

  .toolbar {
    min-height: var(--modern-toolbar-height);
    height: var(--modern-toolbar-height);
    padding: 5px 7px calc(5px + env(safe-area-inset-bottom));
    grid-template-columns: 38px 1fr 38px;
    gap: 3px;
  }
  .home-button {
    width: 36px;
    height: 36px;
    padding: 7px;
    justify-content: center;
  }
  .home-button span { display: none; }
  .home-button svg { width: 20px; height: 20px; }

  .page-navigation { gap: 3px; }
  .nav-button {
    width: 34px;
    height: 34px;
    padding: 6px;
  }
  .page-counter {
    min-width: 84px;
    height: 36px;
    padding: 0 8px;
    font-size: .69rem;
  }
  .navigation-help {
    width: 36px;
    justify-content: center;
  }
  .navigation-help span { display: none; }
  .navigation-help svg { width: 20px; height: 20px; }

  .thumbnails-panel {
    height: 160px;
    left: 6px;
    right: 6px;
    bottom: calc(var(--modern-toolbar-height) + 5px);
    border-radius: 14px;
    grid-template-rows: 42px minmax(0, 1fr);
  }
  .panel-header { min-height: 42px; padding-left: 12px; }
  .panel-header span { display: none; }
  .thumbnails-list { padding: 6px 9px 9px; }
  .thumbnail-button { width: 72px; min-width: 72px; padding: 4px; }
  .thumbnail-frame { width: 42px; height: 58px; }
  .thumbnail-label { max-width: 64px; font-size: .56rem; }

  .status-overlay { bottom: var(--modern-toolbar-height); }
  .loading-logo { width: 76px; height: 68px; }

  html.mobile-mode .mobile-reader {
    padding-top: 2px;
  }
}

@media (max-width: 430px) {
  .site-header {
    grid-template-columns: 46px minmax(76px, 1fr) auto;
    padding-inline: 5px;
  }
  .institution-logo { width: 43px; height: 47px; }
  .header-title p { font-size: .62rem; }
  .header-title h1 { font-size: .64rem; }
  .header-tool { width: 32px; }
  .header-tool-icon { width: 29px; height: 29px; }
  .header-tool-icon svg { width: 17px; height: 17px; }
}

/* En lectura inmersiva solo se ve el anuario, como en las versiones funcionales anteriores. */
html.reading-fullscreen .site-header,
html.reading-fullscreen .toolbar,
html.reading-fullscreen .thumbnails-panel {
  display: none !important;
}

html.reading-fullscreen .book-stage::before,
html.reading-fullscreen .book-stage::after,
html.reading-fullscreen .decor-dots,
html.reading-fullscreen .stage-arrow {
  display: none !important;
}

/* El botón de restablecer zoom solo aparece en el modo móvil. */
.header-tool.mobile-only-control { display: none; }
html.mobile-mode .header-tool.mobile-only-control { display: flex; }

/* ==========================================================================
   VERSIÓN MAESTRA — BIBLIOTECA DE ANUARIOS
   ========================================================================== */

[hidden] { display: none !important; }

.header-brand {
  color: inherit;
  text-decoration: none;
}

.library-home {
  min-height: 100dvh;
  background:
    radial-gradient(circle at 16% 9%, rgba(187,153,85,.10), transparent 24rem),
    radial-gradient(circle at 88% 84%, rgba(134,31,50,.07), transparent 30rem),
    var(--stc-cream);
  color: var(--stc-ink);
  display: flex;
  flex-direction: column;
}

.library-header {
  min-height: 94px;
  padding: 10px clamp(20px, 4vw, 58px);
  display: flex;
  align-items: center;
  background: rgba(255,255,255,.96);
  border-bottom: 3px solid var(--stc-gold);
  box-shadow: 0 6px 24px rgba(75,52,43,.07);
}

.library-brand {
  display: inline-flex;
  align-items: center;
  gap: 15px;
  color: inherit;
  text-decoration: none;
}

.library-brand img {
  width: 78px;
  height: 70px;
  object-fit: contain;
}

.library-brand span {
  display: grid;
  gap: 3px;
  padding-left: 15px;
  border-left: 1px solid rgba(134,31,50,.15);
}

.library-brand strong {
  font-size: 1.12rem;
  font-weight: 580;
}

.library-brand small {
  color: var(--stc-gold);
  font-size: .72rem;
  font-weight: 760;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.library-main {
  width: min(1180px, calc(100% - 36px));
  margin: 0 auto;
  padding: clamp(46px, 7vw, 84px) 0 70px;
  flex: 1;
}

.library-intro {
  max-width: 720px;
  margin-bottom: 38px;
}

.library-kicker {
  display: inline-block;
  margin-bottom: 9px;
  color: var(--stc-gold);
  font-size: .74rem;
  font-weight: 800;
  letter-spacing: .15em;
  text-transform: uppercase;
}

.library-intro h1 {
  margin: 0;
  color: var(--stc-burgundy);
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2rem, 5vw, 4rem);
  font-weight: 500;
  line-height: 1;
  white-space: normal;
  overflow: visible;
}

.library-intro p {
  margin: 15px 0 0;
  color: var(--stc-muted);
  font-size: clamp(1rem, 1.4vw, 1.16rem);
  line-height: 1.6;
}

.library-message {
  margin: 0 0 28px;
  padding: 13px 16px;
  border-left: 4px solid var(--stc-gold);
  border-radius: 0 10px 10px 0;
  background: #fff;
  box-shadow: 0 7px 20px rgba(75,52,43,.06);
  color: var(--stc-burgundy-dark);
}

.library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: clamp(20px, 3vw, 34px);
}

.library-card {
  min-width: 0;
  display: grid;
  grid-template-rows: auto 1fr;
  color: inherit;
  text-decoration: none;
  border-radius: 18px;
  background: rgba(255,255,255,.88);
  border: 1px solid rgba(134,31,50,.08);
  box-shadow: 0 15px 36px rgba(73,50,42,.09);
  overflow: hidden;
  transition: transform .2s ease, box-shadow .2s ease, border-color .2s ease;
}

.library-card:hover,
.library-card:focus-visible {
  transform: translateY(-5px);
  border-color: rgba(187,153,85,.55);
  box-shadow: 0 22px 44px rgba(73,50,42,.14);
  outline: none;
}

.library-card-cover {
  min-height: 330px;
  padding: 22px 22px 0;
  display: grid;
  place-items: end center;
  background:
    linear-gradient(145deg, rgba(255,255,255,.9), rgba(246,241,235,.9));
  overflow: hidden;
}

.library-card-cover img {
  width: min(100%, 210px);
  max-height: 310px;
  object-fit: contain;
  display: block;
  filter: drop-shadow(0 14px 16px rgba(38,27,24,.20));
  transition: transform .25s ease;
}

.library-card:hover .library-card-cover img,
.library-card:focus-visible .library-card-cover img {
  transform: translateY(-4px) scale(1.015);
}

.library-card-copy {
  padding: 18px 20px 21px;
  display: grid;
  gap: 5px;
  border-top: 1px solid rgba(134,31,50,.07);
  background: #fff;
}

.library-card-copy strong {
  color: var(--stc-burgundy);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.65rem;
  font-weight: 500;
}

.library-card-copy span {
  color: var(--stc-muted);
  font-size: .91rem;
  line-height: 1.35;
}

.library-card-copy em {
  margin-top: 9px;
  color: var(--stc-gold);
  font-size: .8rem;
  font-style: normal;
  font-weight: 800;
  letter-spacing: .06em;
  text-transform: uppercase;
}

.library-footer {
  padding: 20px;
  text-align: center;
  color: rgba(255,255,255,.78);
  background: var(--stc-burgundy-dark);
  border-top: 3px solid var(--stc-gold);
  font-size: .82rem;
  letter-spacing: .03em;
}

@media (max-width: 600px) {
  .library-header { min-height: 78px; padding: 8px 16px; }
  .library-brand img { width: 60px; height: 58px; }
  .library-brand span { padding-left: 12px; }
  .library-brand strong { font-size: .97rem; }
  .library-brand small { font-size: .62rem; }
  .library-main { width: min(100% - 28px, 1180px); padding-top: 36px; }
  .library-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
  .library-card { border-radius: 14px; }
  .library-card-cover { min-height: 220px; padding: 14px 10px 0; }
  .library-card-cover img { max-height: 205px; }
  .library-card-copy { padding: 13px 13px 15px; }
  .library-card-copy strong { font-size: 1.35rem; }
  .library-card-copy span { font-size: .78rem; }
  .library-card-copy em { font-size: .68rem; }
}

@media (max-width: 390px) {
  .library-grid { grid-template-columns: 1fr; }
  .library-card-cover { min-height: 300px; }
  .library-card-cover img { max-height: 285px; }
}

/* Soporte para publicaciones con cantidad impar de páginas.
   La última página real se muestra a la derecha del último pliego,
   sin insertar una hoja blanca artificial. */
.book-base { overflow: hidden; }
.base-right .odd-final-page {
  inset: 0;
  border: 0;
  border-radius: 0 6px 6px 0;
  transform: none;
  -webkit-transform: none;
}
.book.is-odd-final-spread { --book-cover-offset: 0%; }
.book.is-odd-final-spread .base-right {
  opacity: 1;
  visibility: visible;
}
.book.is-odd-final-spread .book-spine { opacity: .72; }
