:root {
  --verde: #1b2f22;
  --verde-claro: #2a4433;
  --crema: #f6eddd;
  --oro: #b1a07c;
  --fondo: #ece6da;
  --tinta: #1b2f22;
  --barra-alto: 56px;
  --pie-alto: 52px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(ellipse at 50% 40%, #f7f3ec 0%, var(--fondo) 70%);
  color: var(--tinta);
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  overflow: hidden;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; color: inherit; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Barra superior ---------- */
.barra {
  height: var(--barra-alto);
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 max(16px, env(safe-area-inset-left)) 0 max(16px, env(safe-area-inset-left));
}
.marca {
  font-family: Georgia, "Times New Roman", serif;
  letter-spacing: .32em;
  font-size: 18px;
  color: var(--verde);
  text-decoration: none;
}
.acciones { display: flex; gap: 2px; }
.acciones button, .acciones .boton {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border: 0; background: transparent; border-radius: 50%;
  color: var(--verde); cursor: pointer;
  transition: background .2s;
}
.acciones button:hover, .acciones .boton:hover { background: rgba(27, 47, 34, .08); }
.acciones button:focus-visible, .flecha:focus-visible { outline: 2px solid var(--oro); outline-offset: 2px; }
[data-accion="sonido"] .mute { display: none; }
[data-accion="sonido"][aria-pressed="false"] .ondas { display: none; }
[data-accion="sonido"][aria-pressed="false"] .mute { display: inline; }

/* ---------- Escenario y libro ---------- */
.escenario {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px 64px;
}
.mesa {
  width: 100%;
  height: 100%;
  transition: transform .6s cubic-bezier(.3, .7, .3, 1);
  opacity: 0;
}
.mesa.listo { opacity: 1; transition: transform .6s cubic-bezier(.3, .7, .3, 1), opacity .4s; }
.libro { width: 100%; height: 100%; }
.pagina { background: #fff; overflow: hidden; }
.pagina img { width: 100%; height: 100%; display: block; object-fit: cover; user-select: none; -webkit-user-select: none; }
/* la librería pone un ancho mínimo que usamos solo para decidir 1 o 2 páginas */
.libro.stf__parent { width: 100%; height: 100%; min-width: 0 !important; min-height: 0 !important; }
.libro .stf__wrapper { width: 100%; height: 100%; }
.stf__block { filter: drop-shadow(0 18px 30px rgba(27, 47, 34, .22)); }

.zona-enlace {
  position: absolute;
  border-radius: 4px;
  transition: background .2s, box-shadow .2s;
}
.zona-enlace:hover { background: rgba(177, 160, 124, .18); box-shadow: inset 0 0 0 1px rgba(177, 160, 124, .6); }

.flecha {
  position: absolute; top: 50%; z-index: 5;
  width: 48px; height: 48px; margin-top: -24px;
  display: grid; place-items: center;
  border: 0; border-radius: 50%;
  background: rgba(255, 255, 255, .7);
  color: var(--verde);
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(27, 47, 34, .12);
  transition: opacity .25s, background .2s;
}
.flecha:hover { background: #fff; }
.flecha[disabled] { opacity: 0; pointer-events: none; }
.anterior { left: 12px; }
.siguiente { right: 12px; }

.cargando { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; transition: opacity .3s; }
.cargando span { width: 34px; height: 34px; border: 2px solid rgba(27, 47, 34, .15); border-top-color: var(--verde); border-radius: 50%; animation: girar 0.9s linear infinite; }
.cargando.oculto { opacity: 0; }
@keyframes girar { to { transform: rotate(360deg); } }

/* ---------- Pie con barra de progreso ---------- */
.pie {
  height: var(--pie-alto);
  flex: none;
  display: flex; align-items: center; justify-content: center; gap: 14px;
  padding: 0 16px max(0px, env(safe-area-inset-bottom));
}
#progreso {
  -webkit-appearance: none; appearance: none;
  width: min(520px, 60vw); height: 4px; border-radius: 4px;
  background: linear-gradient(var(--verde), var(--verde)) 0 / var(--avance, 0%) 100% no-repeat, rgba(27, 47, 34, .15);
  cursor: pointer;
}
#progreso::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; border-radius: 50%; background: var(--verde); border: 2px solid var(--crema); }
#progreso::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: var(--verde); border: 2px solid var(--crema); }
.contador { font-size: 13px; letter-spacing: .08em; min-width: 52px; font-variant-numeric: tabular-nums; }

/* ---------- Capas (miniaturas y zoom) ---------- */
.capa {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(27, 47, 34, .96);
  color: var(--crema);
  display: flex; flex-direction: column;
  animation: aparecer .25s ease;
}
.capa[hidden] { display: none; }
@keyframes aparecer { from { opacity: 0; } }
.capa-cabeza {
  flex: none; height: var(--barra-alto);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  font-size: 13px; letter-spacing: .12em; text-transform: uppercase;
}
.capa-cabeza button { width: 44px; height: 44px; border: 0; background: transparent; font-size: 30px; line-height: 1; cursor: pointer; color: var(--crema); }
.rejilla {
  flex: 1; overflow: auto;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 24px;
  padding: 16px 24px 40px;
  align-content: start;
}
.mini { border: 0; background: transparent; padding: 0; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.mini img { width: 100%; aspect-ratio: 4 / 5; object-fit: cover; border-radius: 2px; box-shadow: 0 6px 18px rgba(0, 0, 0, .35); transition: transform .2s; }
.mini:hover img { transform: translateY(-3px); }
.mini.activa img { outline: 2px solid var(--oro); outline-offset: 4px; }
.mini span { font-size: 12px; color: var(--crema); opacity: .8; }

.capa-zoom { background: rgba(20, 30, 24, .97); }
.zoom-lienzo { flex: 1; overflow: auto; cursor: zoom-out; -webkit-overflow-scrolling: touch; }
.zoom-lienzo .hoja { display: flex; justify-content: center; min-width: min-content; padding: 0 16px 24px; }
.zoom-lienzo img { width: min(1600px, 180vw); max-width: none; height: auto; display: block; }
.zoom-lienzo .doble img { width: min(1100px, 95vw); }

.aviso {
  position: fixed; left: 50%; bottom: 72px; z-index: 30;
  transform: translate(-50%, 20px); opacity: 0;
  background: var(--verde); color: var(--crema);
  padding: 10px 18px; border-radius: 999px; font-size: 14px;
  transition: opacity .25s, transform .25s; pointer-events: none;
}
.aviso.ver { opacity: 1; transform: translate(-50%, 0); }

.solo-lectores { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Celular ---------- */
@media (max-width: 700px) {
  :root { --barra-alto: 50px; }
  .escenario { padding: 4px 8px; }
  .flecha { width: 38px; height: 38px; margin-top: -19px; background: rgba(255, 255, 255, .85); }
  .anterior { left: 4px; }
  .siguiente { right: 4px; }
  .acciones button, .acciones .boton { width: 36px; height: 36px; }
  .rejilla { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 16px; padding: 12px 16px 32px; }
}
@media (prefers-reduced-motion: reduce) {
  .mesa, .mesa.listo { transition: none; }
}
