* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: radial-gradient(ellipse at center, color-mix(in srgb, var(--fondo) 75%, #fff 25%) 0%, var(--fondo) 70%);
  background-color: var(--fondo);
  color: #fff;
  display: flex; flex-direction: column;
  user-select: none; -webkit-user-select: none;
}
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.barra-sup, .barra-inf {
  display: flex; align-items: center; gap: 6px; padding: 8px 14px;
  background: rgba(0,0,0,.35); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  z-index: 20; flex-shrink: 0;
}
.barra-sup { justify-content: space-between; }
.marca { display: flex; align-items: center; gap: 10px; min-width: 0; }
.marca img { height: 34px; max-width: 140px; object-fit: contain; }
.titulo { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.acciones-sup { display: flex; gap: 4px; }
.barra-inf { justify-content: center; }
.sep { width: 1px; height: 22px; background: rgba(255,255,255,.25); margin: 0 6px; }
#indicador { font-size: 14px; min-width: 90px; text-align: center; font-variant-numeric: tabular-nums; }

.ico {
  background: transparent; border: 0; color: #fff; cursor: pointer;
  width: 40px; height: 40px; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center;
  text-decoration: none; transition: background .15s;
}
.ico:hover { background: rgba(255,255,255,.15); }
.ico.activo { background: rgba(255,255,255,.22); }
#bSonido.mudo .ondas { display: none; }

#escenario { flex: 1; position: relative; overflow: auto; min-height: 0; }
#zoom { width: 100%; height: 100%; padding: 24px 70px; margin: 0 auto; transition: width .25s, height .25s; }
#libro { width: 100%; height: 100%; transition: transform .75s cubic-bezier(.45,.05,.3,1); will-change: transform; }
#libro .pagina { background: #fff; overflow: hidden; }
#libro .pagina img { width: 100%; height: 100%; display: block; object-fit: var(--ajuste, contain); background: #fff; pointer-events: none; }
#libro .pagina .vacia { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; color: #bbb; font-size: 13px; }
#libro .stf__item { box-shadow: 0 0 0 rgba(0,0,0,0); }
#libro .stf__block { filter: drop-shadow(0 18px 30px rgba(0,0,0,.45)); }

.flecha {
  position: absolute; top: 50%; transform: translateY(-50%); z-index: 10;
  width: 48px; height: 72px; border: 0; border-radius: 12px; cursor: pointer;
  background: rgba(0,0,0,.25); color: #fff; display: flex; align-items: center; justify-content: center;
  transition: background .15s, opacity .15s;
}
.flecha:hover { background: rgba(0,0,0,.5); }
.flecha svg { width: 28px; height: 28px; }
.flecha.izq { left: 12px; } .flecha.der { right: 12px; }
.flecha:disabled { opacity: 0; pointer-events: none; }

#miniaturas {
  position: fixed; left: 0; right: 0; bottom: 56px; z-index: 15;
  display: flex; gap: 10px; overflow-x: auto; padding: 14px;
  background: rgba(0,0,0,.65); backdrop-filter: blur(8px);
  transform: translateY(calc(100% + 60px)); transition: transform .25s;
}
#miniaturas.abierto { transform: none; }
#miniaturas button {
  flex: 0 0 auto; border: 2px solid transparent; padding: 0; background: #fff; cursor: pointer; border-radius: 3px;
  height: 120px; display: flex; flex-direction: column; overflow: hidden;
}
#miniaturas button.actual { border-color: var(--marca); }
#miniaturas img { height: 100%; display: block; }
#miniaturas span { display: block; font-size: 11px; color: #ccc; text-align: center; }
#miniaturas .mini { display: flex; flex-direction: column; gap: 4px; align-items: center; }

#cargando {
  position: fixed; inset: 0; z-index: 50; display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: var(--fondo); transition: opacity .4s;
}
#cargando.oculto { opacity: 0; pointer-events: none; }
.spinner { width: 46px; height: 46px; border: 4px solid rgba(255,255,255,.2); border-top-color: #fff; border-radius: 50%; animation: gira 0.9s linear infinite; }
@keyframes gira { to { transform: rotate(360deg); } }

.modal { position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal[hidden] { display: none; }
.modal-caja { background: #fff; color: #111; border-radius: 14px; padding: 22px; width: min(460px, 100%); user-select: text; }
.modal-caja h3 { margin: 0 0 14px; }
.modal-caja label { display: block; font-size: 13px; font-weight: 600; margin: 14px 0 6px; }
.redes { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.redes a { text-align: center; padding: 10px 4px; border-radius: 8px; background: #f2f2f0; color: #111; text-decoration: none; font-size: 13px; font-weight: 600; cursor: pointer; }
.redes a:hover { background: var(--marca); color: var(--txtmarca); }
.copiar { display: flex; gap: 6px; }
.copiar input { flex: 1; padding: 9px 10px; border: 1px solid #ddd; border-radius: 8px; font-size: 13px; min-width: 0; }
.copiar button, .cerrar { border: 0; background: var(--marca); color: var(--txtmarca); font-weight: 700; padding: 0 14px; border-radius: 8px; cursor: pointer; }
.cerrar { margin-top: 18px; padding: 10px; width: 100%; background: #222; color: #fff; }

/* Modo incrustado (iframe) y celulares */
@media (max-width: 700px) {
  #zoom { padding: 12px 8px; }
  .flecha { display: none; }
  #indicador { min-width: 70px; }
  .barra-inf { gap: 0; padding: 6px; }
  .sep { display: none; }
  #bPrimera, #bUltima { display: none; }
}

/* Sombra del lomo (centro del libro) */
#libro .pagina.--left::after, #libro .pagina.--right::after {
  content: ""; position: absolute; top: 0; bottom: 0; width: 8%; pointer-events: none;
}
#libro .pagina.--left::after { right: 0; background: linear-gradient(to left, rgba(0,0,0,.22), rgba(0,0,0,0)); }
#libro .pagina.--right::after { left: 0; background: linear-gradient(to right, rgba(0,0,0,.22), rgba(0,0,0,0)); }

/* Botones con enlace */
.acciones-sup { align-items: center; }
.boton-enlace {
  display: inline-flex; align-items: center; height: 36px; padding: 0 16px; border-radius: 18px;
  background: var(--marca); color: var(--txtmarca); text-decoration: none; font-weight: 700; font-size: 14px;
  white-space: nowrap; box-shadow: 0 2px 8px rgba(0,0,0,.25); transition: transform .15s, filter .15s;
}
.boton-enlace:hover { transform: translateY(-1px); filter: brightness(1.1); }
#botonesPagina { position: absolute; left: 0; top: 0; width: 0; height: 0; z-index: 12; transition: opacity .2s; }
.grupo-botones {
  position: absolute; transform: translate(-50%, -100%);
  display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; width: max-content;
}
#botonesPagina .boton-enlace { pointer-events: auto; height: 44px; padding: 0 22px; font-size: 15px; animation: aparecer .3s ease; }
@keyframes aparecer { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@media (max-width: 700px) {
  .acciones-sup .boton-enlace { height: 32px; padding: 0 12px; font-size: 13px; max-width: 46vw; overflow: hidden; text-overflow: ellipsis; }
}

/* Botones incrustados dentro de una página (mismo tamaño relativo que en el editor) */
#libro .pagina { container-type: inline-size; }
.boton-pag {
  position: absolute; transform: translate(-50%, -50%); z-index: 3;
  display: inline-flex; align-items: center; justify-content: center; white-space: nowrap;
  font-weight: 700; font-size: calc(3.6cqw * var(--tam, 1)); padding: 0.55em 1.2em; border-radius: 999px;
  color: #fff; text-decoration: none; box-shadow: 0 0.25em 0.8em rgba(0,0,0,.3); cursor: pointer;
  transition: filter .15s;
}
.boton-pag:hover { filter: brightness(1.12); }
