/* ==========================================================
   Matemáticas con raíces · Biblioteca y lector tipo libro
   ========================================================== */

:root {
  --brown-950: #170e07;
  --brown-900: #24160c;
  --brown-800: #3b2414;
  --brown-700: #5a3016;
  --brown-600: #6e3d1e;
  --terra: #b5532a;
  --terra-dark: #8e3d1c;
  --green: #2f5d2a;
  --green-dark: #1f4320;
  --ochre: #d9a441;
  --cream: #fbf4ea;
  --cream-2: #f4e7d5;
  --cream-3: #ead8bf;
  --ink: #2b1d14;
  --muted: #7a6656;
  --page-bg: #fbf4ea;

  --ff-title: "Bitter", Georgia, "Times New Roman", serif;
  --ff-ui: "Nunito Sans", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;

  --ease-out: cubic-bezier(.2, .8, .2, 1);
  --radius: 14px;

  --weave: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='44' height='22' viewBox='0 0 44 22'%3E%3Crect width='44' height='22' fill='%235a3016'/%3E%3Cpath d='M0 22L11 7l11 15z' fill='%23b5532a'/%3E%3Cpath d='M22 22L33 7l11 15z' fill='%232f5d2a'/%3E%3Cpath d='M11 0l11 13L33 0z' fill='%23ead2a4'/%3E%3Cpath d='M-11 0L0 13 11 0zM33 0l11 13L55 0z' fill='%23ead2a4'/%3E%3Cpath d='M22 9.5l3.5 3.5-3.5 3.5-3.5-3.5z' fill='%235a3016'/%3E%3Cpath d='M0 9.5l3.5 3.5L0 16.5-3.5 13zM44 9.5l3.5 3.5-3.5 3.5-3.5-3.5z' fill='%23d9a441'/%3E%3C/svg%3E");
}

*,
*::before,
*::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--ff-ui);
  color: var(--ink);
  background: var(--cream);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

body.is-reading { overflow: hidden; }

button { font: inherit; color: inherit; }
img { display: block; max-width: 100%; }
[hidden] { display: none !important; }

:focus-visible {
  outline: 3px solid var(--ochre);
  outline-offset: 3px;
  border-radius: 8px;
}

/* Franja de tejido */
.weave {
  height: 22px;
  background: var(--weave) repeat-x center / 44px 22px;
  box-shadow: 0 1px 0 rgba(0, 0, 0, .15), 0 -1px 0 rgba(0, 0, 0, .15);
}

/* ==========================================================
   BIBLIOTECA
   ========================================================== */

.home {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(1100px 520px at 12% -8%, rgba(217, 164, 65, .20), transparent 62%),
    radial-gradient(900px 520px at 100% 0%, rgba(47, 93, 42, .10), transparent 60%),
    radial-gradient(1000px 600px at 50% 115%, rgba(181, 83, 42, .12), transparent 60%),
    var(--cream);
}

.home__header,
.home__main,
.home__footer { width: min(1280px, 100% - 48px); margin-left: auto; margin-right: auto; }

.home__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 18px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand__mark { width: 42px; height: 42px; color: var(--terra); flex: none; }
.brand__text { display: flex; flex-direction: column; line-height: 1.2; font-size: .84rem; color: var(--muted); }
.brand__text strong { color: var(--brown-700); font-size: .93rem; font-weight: 800; }
.home__place {
  font-size: .76rem;
  font-weight: 800;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--brown-600);
  padding: 8px 14px;
  border: 1px solid rgba(110, 61, 30, .2);
  border-radius: 999px;
  white-space: nowrap;
}

.home__main { flex: 1; display: flex; flex-direction: column; }

/* Encabezado */
.hero { text-align: center; padding: clamp(18px, 3.5vh, 44px) 0 clamp(22px, 4vh, 40px); }
.hero__kicker {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 14px;
  padding: 6px 15px;
  border: 1px solid rgba(181, 83, 42, .2);
  border-radius: 999px;
  background: rgba(181, 83, 42, .07);
  color: var(--terra);
  font-size: .74rem;
  font-weight: 800;
  letter-spacing: .15em;
  text-transform: uppercase;
}
.hero__kicker i { width: 4px; height: 4px; border-radius: 50%; background: currentColor; opacity: .55; }
.hero__title {
  margin: 0;
  font-family: var(--ff-title);
  font-weight: 800;
  font-size: clamp(2.3rem, 5vw, 3.9rem);
  line-height: 1.02;
  letter-spacing: -.015em;
  color: var(--brown-700);
}
.hero__title span { color: var(--green); white-space: nowrap; }
.hero__lead {
  margin: 12px auto 0;
  max-width: 560px;
  text-wrap: balance;
  font-size: clamp(1rem, 1.5vw, 1.12rem);
  line-height: 1.55;
  color: var(--muted);
}

/* Estante */
.shelf {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: clamp(20px, 2.2vw, 32px);
}

.book-card {
  --accent: var(--green);
  --cover: clamp(170px, 14.5vw, 236px);
  position: relative;
  display: grid;
  grid-template-columns: var(--cover) minmax(0, 1fr);
  align-items: center;
  gap: clamp(26px, 2.6vw, 42px);
  padding: clamp(28px, 2.6vw, 40px) clamp(26px, 2.6vw, 40px) clamp(34px, 3vw, 46px);
  overflow: hidden;
  border: 1px solid rgba(110, 61, 30, .12);
  border-radius: 28px;
  background-color: #fffdf8;
  background-image:
    radial-gradient(110% 85% at 0% 0%, color-mix(in srgb, var(--accent) 13%, transparent), transparent 62%),
    linear-gradient(#fffdf8, #fffaf2);
  box-shadow: 0 1px 2px rgba(59, 36, 20, .06), 0 30px 50px -32px rgba(59, 36, 20, .55);
  cursor: pointer;
  opacity: 0;
  transform: translateY(22px);
  animation: rise .9s var(--ease-out) forwards;
  transition: translate .45s var(--ease-out), box-shadow .45s var(--ease-out), border-color .45s;
}
.book-card:nth-child(2) { animation-delay: .12s; }
.book-card::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 12px;
  background: var(--weave) repeat-x left center / auto 100%;
}
.book-card:hover {
  translate: 0 -4px;
  border-color: color-mix(in srgb, var(--accent) 28%, transparent);
  box-shadow: 0 1px 2px rgba(59, 36, 20, .06), 0 40px 60px -34px rgba(59, 36, 20, .6);
}
@keyframes rise { to { opacity: 1; transform: none; } }

/* Libro 3D */
.book3d {
  --w: var(--cover, 220px);
  --t: calc(var(--w) * var(--thick, .1));
  position: relative;
  width: var(--w);
  aspect-ratio: 596 / 842;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  perspective: 1600px;
}
.book3d::after {
  content: "";
  position: absolute;
  left: 6%;
  right: -8%;
  bottom: -6%;
  height: 10%;
  border-radius: 50%;
  background: radial-gradient(ellipse at center, rgba(59, 36, 20, .45), rgba(59, 36, 20, 0) 70%);
  filter: blur(6px);
  z-index: -1;
  transition: transform .7s var(--ease-out), opacity .7s;
}
.book3d__inner {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transform: rotateY(-24deg) rotateX(2deg);
  transition: transform .8s var(--ease-out);
}
.book3d__face,
.book3d__hinge,
.book3d__shine,
.book3d__back {
  position: absolute;
  inset: 0;
  border-radius: 3px 8px 8px 3px;
}
.book3d__face {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: translateZ(calc(var(--t) / 2));
  background: var(--cream-3);
}
.book3d__hinge {
  transform: translateZ(calc(var(--t) / 2 + .5px));
  background: linear-gradient(90deg,
      rgba(0, 0, 0, .35) 0%, rgba(255, 255, 255, .25) 1.4%, rgba(0, 0, 0, .22) 3%,
      rgba(0, 0, 0, 0) 6%, rgba(0, 0, 0, 0) 94%, rgba(255, 255, 255, .12) 100%);
  pointer-events: none;
}
.book3d__shine {
  transform: translateZ(calc(var(--t) / 2 + 1px));
  background: linear-gradient(115deg, transparent 30%, rgba(255, 255, 255, .38) 45%, transparent 60%);
  background-size: 250% 100%;
  background-position: 120% 0;
  pointer-events: none;
  transition: background-position 1.1s var(--ease-out);
}
.book3d__pages {
  position: absolute;
  top: 1.6%;
  bottom: 1.6%;
  right: calc(var(--t) / -2 + 3px);
  width: var(--t);
  transform: rotateY(90deg);
  background:
    linear-gradient(90deg, rgba(0, 0, 0, .18), transparent 25%, transparent 75%, rgba(0, 0, 0, .12)),
    repeating-linear-gradient(90deg, #fffaf1 0 1.5px, #e6d8c2 1.5px 2.5px);
}
.book3d__back {
  transform: translateZ(calc(var(--t) / -2));
  background: var(--brown-800);
}
.book-card:hover .book3d__inner,
.book3d:focus-visible .book3d__inner { transform: rotateY(-8deg) rotateX(1deg) translateY(-6px); }
.book-card:hover .book3d__shine,
.book3d:focus-visible .book3d__shine { background-position: -40% 0; }
.book-card:hover .book3d::after { transform: scale(.92) translateY(6px); opacity: .75; }
.book3d:focus-visible { outline: none; }
.book3d:focus-visible .book3d__face { outline: 3px solid var(--ochre); outline-offset: 4px; }

/* Datos del libro */
.book-card__info { display: flex; flex-direction: column; align-items: flex-start; min-width: 0; }
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 14px;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: .7rem;
  font-weight: 800;
  letter-spacing: .13em;
  text-transform: uppercase;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .7; }
.book-card__title {
  margin: 0;
  font-family: var(--ff-title);
  font-weight: 800;
  font-size: clamp(1.4rem, 1.85vw, 1.8rem);
  line-height: 1.12;
  letter-spacing: -.01em;
  color: var(--brown-800);
}
.book-card__role { margin: 6px 0 0; font-weight: 700; font-size: 1rem; color: var(--accent); }
.book-card__blurb { margin: 12px 0 0; font-size: .95rem; line-height: 1.55; color: var(--muted); }
.book-card__facts { display: flex; flex-wrap: wrap; gap: 6px; margin: 16px 0 0; padding: 0; list-style: none; }
.book-card__facts li {
  padding: 5px 11px;
  border-radius: 999px;
  background: rgba(110, 61, 30, .065);
  color: var(--brown-600);
  font-size: .8rem;
  font-weight: 600;
  white-space: nowrap;
}
.book-card__facts strong { color: var(--brown-800); font-weight: 800; }

.book-card__progress { width: 100%; max-width: 340px; margin-top: 16px; }
.book-card__progress-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 7px;
  font-size: .82rem;
  color: var(--muted);
}
.book-card__progress-row strong { color: var(--brown-800); }
.book-card__progress-row span:last-child { font-weight: 800; color: var(--accent); }
.book-card__bar { height: 6px; border-radius: 99px; background: rgba(110, 61, 30, .12); overflow: hidden; }
.book-card__bar i { display: block; height: 100%; border-radius: inherit; background: var(--accent); }

.book-card__actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 20px; }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 46px;
  padding: 0 22px;
  border: 0;
  border-radius: 999px;
  font-weight: 800;
  font-size: .96rem;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: transform .2s, box-shadow .2s, background-color .2s;
}
.btn svg { width: 19px; height: 19px; transition: transform .25s var(--ease-out); }
.btn--primary { background: var(--accent); color: #fff; box-shadow: 0 10px 22px -12px var(--accent); }
.btn--primary:hover { transform: translateY(-1px); box-shadow: 0 14px 26px -12px var(--accent); }
.btn--primary:hover svg,
.book-card:hover .btn--primary svg { transform: translateX(3px); }
.btn--ghost { background: transparent; color: var(--accent); box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--accent) 55%, transparent); }
.btn--ghost:hover { background: color-mix(in srgb, var(--accent) 7%, transparent); }

.book-card__links { display: flex; flex-wrap: wrap; gap: 6px 20px; margin-top: 14px; }
.book-card__link {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 2px 0;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: .85rem;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  transition: color .2s;
}
.book-card__link svg { width: 16px; height: 16px; }
.book-card__link:hover { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }

/* Beneficios */
.features {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px 28px;
  padding: clamp(26px, 4.5vh, 44px) 8px clamp(30px, 5vh, 52px);
}
.feature { display: flex; align-items: flex-start; gap: 14px; }
.feature__icon {
  display: grid;
  place-items: center;
  flex: none;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: rgba(181, 83, 42, .09);
  color: var(--terra);
}
.feature__icon svg { width: 22px; height: 22px; }
.feature strong { font-family: var(--ff-title); font-size: .98rem; color: var(--brown-800); }
.feature p { margin: 3px 0 0; font-size: .88rem; line-height: 1.45; color: var(--muted); }

.home__footer {
  padding: 20px 0 26px;
  border-top: 1px solid rgba(110, 61, 30, .16);
  text-align: center;
  color: var(--muted);
  font-size: .88rem;
  line-height: 1.5;
}
.home__footer p { margin: 0; }
.home__footer strong { color: var(--brown-700); }
.home__footer-small { margin-top: 6px !important; font-size: .78rem; opacity: .85; }
.home__credit {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 14px !important;
  padding: 6px 14px;
  border: 1px solid rgba(110, 61, 30, .16);
  border-radius: 999px;
  background: rgba(255, 255, 255, .5);
  font-size: .8rem;
  color: var(--muted);
}
.home__credit svg { width: 16px; height: 16px; color: var(--terra); flex: none; }
.home__credit strong { color: var(--brown-800); font-weight: 800; }

/* Pantallas medianas: tarjetas una debajo de otra */
@media (max-width: 1099px) {
  .shelf { grid-template-columns: minmax(0, 1fr); width: 100%; max-width: 760px; margin: 0 auto; }
  .book-card { --cover: clamp(150px, 24vw, 210px); }
  .features { max-width: 760px; margin: 0 auto; width: 100%; }
}
@media (max-width: 760px) {
  .features { grid-template-columns: minmax(0, 1fr); gap: 16px; padding-left: 4px; padding-right: 4px; }
}
/* Celular */
@media (max-width: 600px) {
  .home__header,
  .home__main,
  .home__footer { width: calc(100% - 28px); }
  .home__header { margin-top: 14px; }
  .home__place { display: none; }
  .brand__mark { width: 38px; height: 38px; }
  .brand__text { font-size: .8rem; }
  .brand__text strong { font-size: .88rem; }
  .hero { padding: 24px 0 22px; }
  .hero__kicker { font-size: .66rem; letter-spacing: .12em; padding: 5px 12px; }
  .hero__lead { font-size: .97rem; }
  .shelf { gap: 16px; }
  .book-card {
    --cover: min(33vw, 150px);
    align-items: start;
    gap: 18px;
    padding: 20px 18px 26px;
    border-radius: 22px;
  }
  .book-card::after { height: 9px; }
  .book3d__inner { transform: rotateY(-16deg) rotateX(1deg); }
  .badge { margin-bottom: 10px; font-size: .64rem; }
  .book-card__title { font-size: 1.18rem; }
  .book-card__role { font-size: .9rem; }
  .book-card__blurb { display: none; }
  .book-card__facts { margin-top: 10px; }
  .book-card__facts li { padding: 4px 9px; font-size: .74rem; }
  .book-card__facts li:nth-child(3) { display: none; }
  .book-card__progress { margin-top: 12px; }
  .book-card__progress-row { font-size: .76rem; }
  .book-card__actions { width: 100%; margin-top: 14px; gap: 8px; }
  .book-card__actions .btn { width: 100%; min-height: 42px; padding: 0 14px; font-size: .9rem; }
  .book-card__links { margin-top: 10px; gap: 6px 14px; }
  .book-card__link { font-size: .78rem; }
  .feature p { font-size: .85rem; }
}
@media (max-width: 360px) {
  .book-card { --cover: 30vw; gap: 14px; padding-left: 14px; padding-right: 14px; }
  .book-card__title { font-size: 1.08rem; }
}

/* ==========================================================
   LECTOR
   ========================================================== */

.reader {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-columns: minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  color: #f6ead9;
  background:
    radial-gradient(ellipse 70% 60% at 50% 45%, #4a3020 0%, #2a1a0f 55%, #140c06 100%);
  overflow: hidden;
  opacity: 0;
  transition: opacity .45s ease;
  user-select: none;
  -webkit-user-select: none;
}
.reader::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: .5;
  background:
    repeating-linear-gradient(0deg, rgba(255, 255, 255, .012) 0 2px, transparent 2px 4px),
    repeating-linear-gradient(90deg, rgba(0, 0, 0, .03) 0 1px, transparent 1px 3px);
}
.reader.is-visible { opacity: 1; }

.r-btn {
  position: relative;
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: inherit;
  cursor: pointer;
  text-decoration: none;
  transition: background-color .2s, color .2s, transform .15s;
}
.r-btn svg { width: 22px; height: 22px; }
.r-btn:hover { background: rgba(255, 255, 255, .1); }
.r-btn:active { transform: scale(.94); }
.r-btn[disabled] { opacity: .3; pointer-events: none; }
.r-btn[aria-pressed="false"] { color: rgba(246, 234, 217, .5); }
.r-btn--light { color: var(--ink); }
.r-btn--light:hover { background: rgba(0, 0, 0, .06); }

/* Barra superior */
.r-top {
  position: relative;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: max(env(safe-area-inset-top), 8px) max(env(safe-area-inset-right), 12px) 8px max(env(safe-area-inset-left), 12px);
  background: linear-gradient(rgba(10, 6, 3, .55), rgba(10, 6, 3, 0));
}
.r-back { width: auto; padding: 0 14px 0 8px; gap: 4px; display: inline-flex; font-weight: 700; font-size: .95rem; }
.r-title {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  white-space: nowrap;
}
.r-title strong {
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: var(--ff-title);
  font-weight: 700;
  font-size: 1.02rem;
  letter-spacing: .01em;
}
.r-badge {
  flex: none;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--accent, var(--green));
  color: #fff;
  font-size: .68rem;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
}
.r-tools { display: flex; align-items: center; gap: 2px; }

.r-menu {
  position: absolute;
  top: calc(100% - 4px);
  right: 10px;
  min-width: 230px;
  padding: 8px;
  border-radius: 16px;
  background: var(--cream);
  color: var(--ink);
  box-shadow: 0 20px 50px -12px rgba(0, 0, 0, .6);
  transform-origin: top right;
  animation: pop .18s var(--ease-out);
}
.r-menu button,
.r-menu a {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 12px;
  border: 0;
  border-radius: 10px;
  background: none;
  color: inherit;
  font-weight: 700;
  font-size: .95rem;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}
.r-menu button:hover,
.r-menu a:hover { background: var(--cream-2); }
.r-menu svg { width: 20px; height: 20px; color: var(--brown-600); }
@keyframes pop { from { opacity: 0; transform: scale(.92); } }

/* Escenario del libro */
.r-stage {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 0;
  min-width: 0;
  padding: 18px 76px;
}
.book-holder {
  position: relative;
  width: 300px;
  height: 420px;
}
.book-holder.is-jumping { animation: jump .45s var(--ease-out); }
@keyframes jump { 0% { opacity: .2; transform: scale(.985); } 100% { opacity: 1; transform: none; } }

.book-shift {
  position: absolute;
  inset: 0;
  transition: transform .75s cubic-bezier(.3, .7, .2, 1);
  will-change: transform;
}
.flip-root {
  width: 100% !important;
  min-width: 0 !important;
  max-width: none !important;
  min-height: 0 !important;
  margin: 0;
}

/* Grosor del libro a los lados (páginas leídas y por leer) */
.book-edge {
  position: absolute;
  top: 3px;
  bottom: 3px;
  width: 0;
  pointer-events: none;
  transition: width .4s, opacity .4s;
  background:
    linear-gradient(90deg, rgba(0, 0, 0, .25), rgba(0, 0, 0, 0) 40%),
    repeating-linear-gradient(90deg, #f5ecdf 0 1px, #cbb89c 1px 2px);
  box-shadow: 0 12px 30px rgba(0, 0, 0, .35);
}
.book-edge--left { right: 100%; border-radius: 3px 0 0 3px; transform: scaleX(-1); transform-origin: right; }
.book-edge--right { left: 100%; border-radius: 0 3px 3px 0; }

/* Páginas */
.page {
  background: var(--page-bg);
  overflow: hidden;
}
.page__img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity .35s ease;
  pointer-events: none;
  -webkit-user-drag: none;
  user-select: none;
}
.page__img.is-loaded { opacity: 1; }
.page__ph {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: var(--ff-title);
  font-weight: 700;
  font-size: clamp(1rem, 3vw, 1.6rem);
  color: #cdb79c;
  background: linear-gradient(100deg, transparent 30%, rgba(255, 255, 255, .55) 50%, transparent 70%) var(--page-bg);
  background-size: 250% 100%;
  animation: shimmer 1.4s linear infinite;
}
.page__img.is-loaded + .page__ph { display: none; }
@keyframes shimmer { from { background-position: 130% 0; } to { background-position: -30% 0; } }

/* Sombra del lomo */
.page::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.page.--left::after {
  background: linear-gradient(to left, rgba(0, 0, 0, .22) 0%, rgba(0, 0, 0, .08) 2.5%, rgba(0, 0, 0, 0) 8%, rgba(0, 0, 0, 0) 97%, rgba(0, 0, 0, .06));
}
.page.--right::after {
  background: linear-gradient(to right, rgba(0, 0, 0, .22) 0%, rgba(0, 0, 0, .08) 2.5%, rgba(0, 0, 0, 0) 8%, rgba(0, 0, 0, 0) 97%, rgba(0, 0, 0, .06));
}
.page--board.--right::after {
  background: linear-gradient(to right, rgba(0, 0, 0, .35) 0, rgba(255, 255, 255, .22) 1.2%, rgba(0, 0, 0, .18) 2.6%, rgba(0, 0, 0, 0) 5%);
}
.page--board.--left::after {
  background: linear-gradient(to left, rgba(0, 0, 0, .35) 0, rgba(255, 255, 255, .22) 1.2%, rgba(0, 0, 0, .18) 2.6%, rgba(0, 0, 0, 0) 5%);
}
.stf__item { box-shadow: 0 14px 40px -6px rgba(0, 0, 0, .45); }

/* Guarda y contraportada generadas */
.page--endpaper {
  background:
    radial-gradient(circle at 50% 50%, rgba(181, 83, 42, .08), transparent 60%),
    var(--cream-2);
}
.endpaper {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: rgba(110, 61, 30, .35);
}
.endpaper svg { width: 22%; height: auto; aspect-ratio: 1; }
.page--backcover { background: var(--brown-800); }
.backcover {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  color: var(--cream);
  text-align: center;
}
.backcover__bg {
  position: absolute;
  inset: -8%;
  background-size: cover;
  background-position: center 60%;
  filter: blur(10px) saturate(1.1);
  opacity: .32;
}
.backcover::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 50% 45%, rgba(59, 36, 20, .35), rgba(23, 14, 7, .85));
}
.backcover > :not(.backcover__bg) { position: relative; }
.backcover__body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .6em;
  padding: 10% 12%;
  font-size: 3.2cqw;
}
.page--backcover { container-type: inline-size; }
.backcover svg { width: 18%; height: auto; aspect-ratio: 1; color: var(--ochre); }
.backcover h3 { margin: .4em 0 0; font-family: var(--ff-title); font-weight: 800; font-size: 2.6em; line-height: 1.05; }
.backcover h3 span { color: #a9cf8f; display: block; }
.backcover p { margin: 0; line-height: 1.5; opacity: .9; }
.backcover .backcover__tag { font-weight: 800; letter-spacing: .14em; text-transform: uppercase; font-size: .78em; color: var(--ochre); }
.backcover__inst { margin-top: 1.4em !important; font-size: .9em; opacity: .8 !important; }
.backcover .weave { height: 6%; background-size: auto 100%; box-shadow: none; }

/* Flechas laterales */
.r-nav {
  position: absolute;
  top: 50%;
  z-index: 3;
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  margin-top: -27px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, .12);
  border-radius: 50%;
  background: rgba(255, 255, 255, .07);
  color: #f6ead9;
  cursor: pointer;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  transition: background-color .2s, transform .2s, opacity .2s;
}
.r-nav svg { width: 26px; height: 26px; }
.r-nav:hover { background: rgba(255, 255, 255, .16); transform: scale(1.06); }
.r-nav[disabled] { opacity: 0; pointer-events: none; }
.r-nav--prev { left: 14px; }
.r-nav--next { right: 14px; }

/* Barra inferior */
.r-bottom {
  position: relative;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px max(env(safe-area-inset-right), 14px) max(env(safe-area-inset-bottom), 10px) max(env(safe-area-inset-left), 14px);
  background: linear-gradient(rgba(10, 6, 3, 0), rgba(10, 6, 3, .6));
}
.r-progress { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; padding: 0 8px; }
.r-progress__row { display: flex; align-items: center; gap: 12px; min-height: 28px; }
.r-pagelabel {
  flex: none;
  padding: 3px 10px;
  border: 1px solid rgba(255, 255, 255, .18);
  border-radius: 999px;
  background: rgba(255, 255, 255, .06);
  font-weight: 800;
  font-size: .86rem;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}
.r-pagelabel:hover { background: rgba(255, 255, 255, .14); }
.r-section {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: .85rem;
  color: rgba(246, 234, 217, .7);
}
.r-goto { display: flex; align-items: center; gap: 6px; font-size: .86rem; font-weight: 700; }
.r-goto input {
  width: 72px;
  height: 30px;
  margin-left: 6px;
  padding: 0 8px;
  border: 0;
  border-radius: 8px;
  background: var(--cream);
  color: var(--ink);
  font: inherit;
  font-weight: 800;
}
.r-goto button {
  height: 30px;
  padding: 0 12px;
  border: 0;
  border-radius: 8px;
  background: var(--ochre);
  color: var(--brown-900);
  font-weight: 800;
  cursor: pointer;
}

.r-slider { position: relative; height: 22px; display: flex; align-items: center; }
.r-slider input {
  --pct: 0%;
  width: 100%;
  height: 22px;
  margin: 0;
  background: transparent;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}
.r-slider input::-webkit-slider-runnable-track {
  height: 5px;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--ochre) var(--pct), rgba(255, 255, 255, .18) var(--pct));
}
.r-slider input::-moz-range-track { height: 5px; border-radius: 99px; background: rgba(255, 255, 255, .18); }
.r-slider input::-moz-range-progress { height: 5px; border-radius: 99px; background: var(--ochre); }
.r-slider input::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  margin-top: -6.5px;
  border: 3px solid var(--brown-900);
  border-radius: 50%;
  background: var(--ochre);
  box-shadow: 0 0 0 2px var(--ochre);
}
.r-slider input::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border: 3px solid var(--brown-900);
  border-radius: 50%;
  background: var(--ochre);
  box-shadow: 0 0 0 2px var(--ochre);
}
.r-slider__tip {
  position: absolute;
  bottom: 30px;
  transform: translateX(-50%);
  padding: 6px;
  border-radius: 10px;
  background: var(--cream);
  color: var(--ink);
  text-align: center;
  font-size: .78rem;
  font-weight: 800;
  box-shadow: 0 14px 30px -10px rgba(0, 0, 0, .7);
  pointer-events: none;
}
.r-slider__tip img { width: 76px; aspect-ratio: 596 / 842; object-fit: cover; border-radius: 4px; background: var(--cream-2); margin-bottom: 4px; }

/* Índice lateral */
.scrim {
  position: absolute;
  inset: 0;
  z-index: 20;
  background: rgba(8, 4, 2, .55);
  opacity: 0;
  transition: opacity .3s;
}
.scrim.is-open { opacity: 1; }
.drawer {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 21;
  display: flex;
  flex-direction: column;
  width: min(390px, 90vw);
  padding-top: env(safe-area-inset-top);
  background: var(--cream);
  color: var(--ink);
  box-shadow: 20px 0 60px -20px rgba(0, 0, 0, .7);
  transform: translateX(-102%);
  transition: transform .38s var(--ease-out);
  user-select: text;
}
.drawer.is-open { transform: none; }
.drawer__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 14px 14px 22px;
  border-bottom: 1px solid var(--cream-3);
  background: linear-gradient(var(--cream-2), var(--cream));
}
.drawer__kicker { font-size: .72rem; font-weight: 800; letter-spacing: .16em; text-transform: uppercase; color: var(--terra); }
.drawer__head h2 { margin: 4px 0 0; font-family: var(--ff-title); font-size: 1.2rem; line-height: 1.25; color: var(--brown-800); }
.toc { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 10px 10px max(env(safe-area-inset-bottom), 24px); }
.toc details { border-radius: 12px; margin: 4px 0; }
.toc details[open] { background: rgba(234, 216, 191, .45); }
.toc summary {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border-radius: 12px;
  cursor: pointer;
  list-style: none;
  font-family: var(--ff-title);
  font-weight: 700;
  color: var(--brown-700);
}
.toc summary::-webkit-details-marker { display: none; }
.toc summary::before {
  content: "";
  flex: none;
  width: 8px;
  height: 8px;
  border-right: 2.5px solid currentColor;
  border-bottom: 2.5px solid currentColor;
  transform: rotate(-45deg);
  transition: transform .2s;
  opacity: .6;
}
.toc details[open] > summary::before { transform: rotate(45deg); }
.toc summary span:first-child { flex: 1; }
.toc-item {
  display: flex;
  align-items: baseline;
  gap: 8px;
  width: 100%;
  padding: 10px 12px;
  border: 0;
  border-radius: 10px;
  background: none;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  font-size: .95rem;
  line-height: 1.35;
}
.toc details .toc-item { padding-left: 32px; font-size: .92rem; }
.toc-item span:first-child { flex: 1; }
.toc-item:hover,
.toc summary:hover { background: rgba(181, 83, 42, .09); }
.toc-pg { flex: none; font-size: .8rem; font-weight: 800; color: var(--muted); font-variant-numeric: tabular-nums; }
.toc-item.is-current { background: var(--accent, var(--green)); color: #fff; }
.toc-item.is-current .toc-pg { color: rgba(255, 255, 255, .8); }
.toc-item--top { font-family: var(--ff-title); font-weight: 700; color: var(--brown-700); }

/* Todas las páginas */
.sheet {
  position: absolute;
  inset: 0;
  z-index: 22;
  display: flex;
  flex-direction: column;
  background: rgba(20, 12, 6, .97);
  opacity: 0;
  transform: translateY(16px);
  transition: opacity .3s, transform .35s var(--ease-out);
}
.sheet.is-open { opacity: 1; transform: none; }
.sheet__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: max(env(safe-area-inset-top), 12px) 16px 12px 22px;
  border-bottom: 1px solid rgba(255, 255, 255, .08);
}
.sheet__head h2 { margin: 0; font-family: var(--ff-title); font-size: 1.15rem; }
.sheet__head .r-btn { color: #f6ead9; }
.sheet__head .r-btn:hover { background: rgba(255, 255, 255, .1); }
.thumbs {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(118px, 1fr));
  gap: 20px 16px;
  padding: 22px 22px max(env(safe-area-inset-bottom), 30px);
  align-content: start;
}
.thumb {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 0;
  border: 0;
  background: none;
  color: rgba(246, 234, 217, .75);
  cursor: pointer;
  font-size: .8rem;
  font-weight: 700;
}
.thumb img,
.thumb .thumb__gen {
  width: 100%;
  height: auto;
  aspect-ratio: 596 / 842;
  object-fit: cover;
  border-radius: 4px;
  background: #3a291c;
  box-shadow: 0 8px 20px -8px rgba(0, 0, 0, .8);
  transition: transform .2s, box-shadow .2s;
}
.thumb__gen { display: grid; place-items: center; background: var(--brown-800) !important; color: var(--ochre); }
.thumb__gen svg { width: 40%; height: 40%; }
.thumb:hover img,
.thumb:hover .thumb__gen { transform: translateY(-4px); }
.thumb.is-current img,
.thumb.is-current .thumb__gen { box-shadow: 0 0 0 3px var(--ochre), 0 10px 24px -8px rgba(0, 0, 0, .8); }
.thumb.is-current { color: var(--ochre); }

/* Lupa */
.zoom {
  position: absolute;
  inset: 0;
  z-index: 24;
  display: flex;
  flex-direction: column;
  background: #0f0905;
  opacity: 0;
  transition: opacity .25s;
}
.zoom.is-open { opacity: 1; }
.zoom__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: max(env(safe-area-inset-top), 8px) 12px 8px 20px;
  background: rgba(0, 0, 0, .4);
}
.zoom__label { font-weight: 800; font-size: .95rem; }
.zoom__ctrls { display: flex; align-items: center; gap: 4px; }
.zoom__pct { min-width: 52px; text-align: center; font-weight: 800; font-size: .88rem; font-variant-numeric: tabular-nums; }
.zoom__view {
  position: relative;
  flex: 1;
  overflow: auto;
  overscroll-behavior: contain;
  cursor: grab;
  touch-action: pan-x pan-y;
}
.zoom__view.is-dragging { cursor: grabbing; }
.zoom__canvas { display: flex; gap: 0; margin: 0 auto; padding: 20px; width: max-content; }
.zoom__canvas img {
  flex: none;
  height: auto;
  max-width: none;
  background: var(--page-bg);
  box-shadow: 0 20px 60px -20px rgba(0, 0, 0, .9);
  pointer-events: none;
  -webkit-user-drag: none;
}

/* Ayuda inicial */
.hint {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(10, 6, 3, .35);
  animation: fadein .4s ease;
}
.hint__card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  max-width: 320px;
  padding: 24px 26px 20px;
  border-radius: 20px;
  background: rgba(251, 244, 234, .97);
  color: var(--ink);
  text-align: center;
  box-shadow: 0 30px 60px -20px rgba(0, 0, 0, .8);
}
.hint__card p { margin: 0; line-height: 1.5; }
.hint__card strong { display: block; font-family: var(--ff-title); font-size: 1.15rem; color: var(--brown-700); }
.hint__hand { width: 54px; height: 54px; color: var(--terra); animation: swipe 1.6s var(--ease-out) infinite; }
.hint__ok {
  min-height: 42px;
  padding: 0 22px;
  border: 0;
  border-radius: 999px;
  background: var(--accent, var(--green));
  color: #fff;
  font-weight: 800;
  cursor: pointer;
}
@keyframes swipe {
  0% { transform: translateX(26px) rotate(8deg); opacity: 0; }
  20% { opacity: 1; }
  70% { transform: translateX(-26px) rotate(-10deg); opacity: 1; }
  100% { transform: translateX(-30px) rotate(-10deg); opacity: 0; }
}
@keyframes fadein { from { opacity: 0; } }

/* Aviso breve */
.toast {
  position: absolute;
  left: 50%;
  bottom: calc(max(env(safe-area-inset-bottom), 10px) + 86px);
  z-index: 30;
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(251, 244, 234, .96);
  color: var(--ink);
  font-weight: 700;
  font-size: .9rem;
  transform: translate(-50%, 20px);
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s, transform .3s var(--ease-out);
  box-shadow: 0 14px 30px -10px rgba(0, 0, 0, .6);
  white-space: nowrap;
}
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }

/* Animación de apertura */
.opening { position: fixed; inset: 0; z-index: 60; pointer-events: none; }
.opening img {
  position: absolute;
  border-radius: 3px 9px 9px 3px;
  box-shadow: 0 30px 70px -20px rgba(0, 0, 0, .7);
  transform-origin: 0 0;
}

/* Visibilidad según dispositivo */
.narrow-only { display: none !important; }
.hint__touch { display: none; }
@media (hover: none), (pointer: coarse) {
  .r-nav { display: none; }
  .hint__mouse { display: none; }
  .hint__touch { display: inline; }
}
@media (max-width: 760px) {
  .wide-only { display: none !important; }
  .narrow-only { display: inline-grid !important; }
  .r-back__label { display: none; }
  .r-back { padding: 0; width: 42px; }
  .r-title { justify-content: flex-start; gap: 8px; }
  .r-title strong { font-size: .95rem; }
  .r-stage { padding: 10px 10px; }
  .r-section { display: none; }
  .r-progress__row { justify-content: center; }
}
@media (max-width: 420px) {
  .r-badge { display: none; }
}
@media (max-height: 520px) and (orientation: landscape) {
  .r-top { padding-top: 4px; padding-bottom: 2px; }
  .r-bottom { padding-top: 2px; padding-bottom: max(env(safe-area-inset-bottom), 4px); }
  .r-stage { padding-top: 6px; padding-bottom: 6px; }
  .r-progress__row { min-height: 22px; }
  .r-section { display: none; }
}
@media (hover: hover) and (pointer: fine) and (min-width: 761px) {
  .r-stage { padding-left: 84px; padding-right: 84px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
