:root {
  --bg: #211b18;
  --bg-2: #3a2f29;
  --ink: #f4ede4;
  --ink-soft: rgba(244, 237, 228, .72);
  --accent: #c8743a;
  --brand: #a8642f;
  --panel: rgba(30, 24, 21, .94);
  --ctl-bg: rgba(255, 255, 255, .10);
  --ctl-bg-hover: rgba(255, 255, 255, .18);
  --ctl-border: rgba(255, 255, 255, .16);
  --banner-h: 32px;
  --bar-h: 0px;                 /* alto de la barra inferior (solo celular) */
  --ease: cubic-bezier(.2, .7, .2, 1);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(ellipse at 50% 40%, var(--bg-2) 0%, var(--bg) 70%);
  background-color: var(--bg);
  color: var(--ink);
  font-family: Georgia, "Times New Roman", serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

body.layout-single { --bar-h: calc(68px + env(safe-area-inset-bottom)); }

/* ---------- Banner superior ---------- */
.banner {
  position: fixed;
  inset: 0 0 auto 0;
  height: var(--banner-h);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .3em;
  padding: 0 16px;
  background: var(--brand);
  color: #fff;
  font: 500 13px/1 system-ui, -apple-system, "Segoe UI", sans-serif;
  letter-spacing: .02em;
  text-decoration: none;
  z-index: 20;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.banner:hover { background: #b9703a; }
body.no-banner { --banner-h: 0px; }
body.no-banner .banner { display: none; }

/* ---------- Escenario del libro ---------- */
#stage {
  position: fixed;
  top: var(--banner-h);
  left: 0;
  right: 0;
  bottom: var(--bar-h);
  overflow: hidden;
  touch-action: none;           /* todos los gestos los maneja la app */
  user-select: none;
  -webkit-user-select: none;
}

.zoom-layer {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transform-origin: 0 0;
}
.zoom-layer.anim { transition: transform .3s var(--ease); }
body.zoomed #stage { cursor: grab; }
body.zoomed.dragging #stage { cursor: grabbing; }

.book { margin: 0 auto; }
.book.animate { transition: transform .7s cubic-bezier(.3, .7, .2, 1); }

.page {
  background: #efe8dd;
  overflow: hidden;
}
.page img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
  -webkit-user-drag: none;
  opacity: 0;
  transition: opacity .3s ease;
}
.page img.loaded { opacity: 1; }

.stf__parent { filter: drop-shadow(0 18px 40px rgba(0, 0, 0, .45)); }

/* ---------- Controles (base) ---------- */
.ctl {
  display: inline-grid;
  place-items: center;
  width: 52px;
  height: 52px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--ctl-border);
  background: var(--ctl-bg);
  color: var(--ink);
  cursor: pointer;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: background .2s, opacity .2s, transform .15s;
  z-index: 16;
}
.ctl svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.ctl:hover { background: var(--ctl-bg-hover); }
.ctl:active { transform: scale(.94); }
.ctl:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.ctl:disabled { opacity: .28; cursor: default; }
.ctl:disabled:active { transform: none; }

.page-label {
  font: 600 13px/1.1 system-ui, -apple-system, "Segoe UI", sans-serif;
  letter-spacing: .02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- Celular: barra inferior ---------- */
body.layout-single .bar-bg {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: var(--bar-h);
  background: rgba(18, 14, 12, .92);
  border-top: 1px solid rgba(255, 255, 255, .06);
  z-index: 15;
}
body.layout-single .ctl-prev,
body.layout-single .ctl-next,
body.layout-single .ctl-index {
  position: fixed;
  bottom: calc(8px + env(safe-area-inset-bottom));
}
body.layout-single .ctl-prev { left: 12px; }
body.layout-single .ctl-next { right: 12px; }
body.layout-single .ctl-index {
  left: 76px;
  right: 76px;
  width: auto;
  border-radius: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 0 16px;
}
body.layout-single .ctl-index svg { flex: none; width: 20px; height: 20px; }
body.layout-single .zoom-tools { display: none; }

/* ---------- PC: controles en los costados ---------- */
body.layout-double .bar-bg { display: none; }
body.layout-double .ctl-prev,
body.layout-double .ctl-next {
  position: fixed;
  top: calc(50% + var(--banner-h) / 2);
  transform: translateY(-50%);
  width: 56px;
  height: 56px;
}
body.layout-double .ctl-prev:active,
body.layout-double .ctl-next:active { transform: translateY(-50%) scale(.94); }
body.layout-double .ctl-prev { left: 12px; }
body.layout-double .ctl-next { right: 12px; }
body.layout-double .ctl-index {
  position: fixed;
  left: 12px;
  bottom: 16px;
  width: 56px;
  height: auto;
  min-height: 56px;
  border-radius: 28px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 4px 8px;
}
body.layout-double .ctl-index .page-label { font-size: 11px; max-width: 52px; }
body.layout-double .zoom-tools {
  position: fixed;
  right: 12px;
  bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 16;
}
body.layout-double .zoom-tools .ctl { width: 56px; height: 56px; }

/* ---------- Botón "Quitar zoom" ---------- */
.zoom-reset {
  position: fixed;
  left: 50%;
  bottom: calc(var(--bar-h) + 14px);
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 11px 18px 11px 14px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, .2);
  background: rgba(18, 14, 12, .82);
  color: var(--ink);
  font: 600 14px/1 system-ui, -apple-system, "Segoe UI", sans-serif;
  cursor: pointer;
  z-index: 17;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, .35);
}
.zoom-reset[hidden] { display: none; }
.zoom-reset svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; }

/* ---------- Pista inicial ---------- */
.hint {
  position: fixed;
  left: 50%;
  bottom: calc(var(--bar-h) + 20px);
  transform: translate(-50%, 8px);
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(20, 16, 14, .85);
  color: var(--ink);
  font: 14px/1.3 system-ui, -apple-system, "Segoe UI", sans-serif;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .5s var(--ease), transform .5s var(--ease);
  z-index: 18;
  width: max-content;
  max-width: calc(100vw - 32px);
}
.hint.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Panel del índice ---------- */
.index-panel {
  position: fixed;
  right: 0;
  top: var(--banner-h);
  bottom: 0;
  width: min(320px, 86vw);
  background: var(--panel);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 30;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform .35s var(--ease);
  box-shadow: -10px 0 40px rgba(0, 0, 0, .35);
}
.index-panel.open { transform: translateX(0); }
.index-panel[hidden] { display: flex; visibility: hidden; }
.index-panel.open[hidden] { visibility: visible; }

.index-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 16px 10px 22px;
  font-size: 22px;
  font-style: italic;
  color: var(--ink);
}
.index-close {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--ink);
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
}
.index-close:hover { background: rgba(255, 255, 255, .08); }

.index-panel ol {
  list-style: none;
  margin: 0;
  padding: 4px 0 calc(24px + env(safe-area-inset-bottom));
  overflow-y: auto;
  flex: 1;
}
.index-panel li button {
  width: 100%;
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 12px 22px;
  border: 0;
  background: transparent;
  color: var(--ink-soft);
  font: 17px/1.25 Georgia, "Times New Roman", serif;
  text-align: left;
  cursor: pointer;
}
.index-panel li button .n {
  font: 12px/1 system-ui, sans-serif;
  color: rgba(244, 237, 228, .4);
  min-width: 18px;
  text-align: right;
}
.index-panel li button:hover,
.index-panel li button:focus-visible { background: rgba(255, 255, 255, .06); color: var(--ink); outline: none; }
.index-panel li button.current { color: var(--ink); }
.index-panel li button.current .n { color: var(--accent); }

.scrim {
  position: fixed;
  inset: 0;
  z-index: 25;
  background: rgba(0, 0, 0, .3);
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s;
}
.scrim.show { opacity: 1; pointer-events: auto; }

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: .01ms !important; }
}
