/* ============================================================
   Visor del Libro Vol.1 — CROMO DEL VISOR (marco)
   Estiliza SOLO el marco alrededor del iframe. NO toca la obra:
   cada pieza vive dentro del <iframe> con su propio styles.css.
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Bricolage+Grotesque:opsz,wght@10..48,500;10..48,600;10..48,700&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  --visor-bg: #1f2d33;        /* fondo neutro oscuro alrededor de la hoja */
  --visor-panel: #ffffff;
  --visor-ink: #2b2b2b;
  --visor-muted: #6b7a80;
  --visor-line: #e3e6e7;
  --visor-accent: #b8543a;    /* terra, acento sobrio */
  --topbar-h: 52px;
  --controls-h: 56px;
  --f-ui: 'Bricolage Grotesque', system-ui, sans-serif;
  --f-mono: 'JetBrains Mono', ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body { background: var(--visor-bg); font-family: var(--f-ui); }

#auth-check, #login-container { color: #fff; }

/* ---------- Shell: columna (topbar / body / controls / progress) ---------- */
.reader-shell {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  background: var(--visor-bg);
}

/* ---------- Barra superior (cromo mínimo, nunca sobre el iframe) ---------- */
.reader-topbar {
  height: var(--topbar-h);
  flex: 0 0 var(--topbar-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 14px; gap: 12px;
  background: var(--visor-panel);
  border-bottom: 1px solid var(--visor-line);
  z-index: 30;
}
.topbar-title {
  font-size: 12px; letter-spacing: 0.04em; color: var(--visor-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar-btn {
  font-family: var(--f-mono); font-size: 12px;
  border: 1px solid var(--visor-line); background: #fff; color: var(--visor-ink);
  padding: 7px 12px; border-radius: 6px; cursor: pointer; white-space: nowrap;
}
.topbar-btn:hover { background: #f5f5f5; }
.download-btn {
  text-decoration: none; color: #fff; background: var(--visor-accent);
  border-color: var(--visor-accent); display: inline-flex; align-items: center;
}
.download-btn:hover { background: #a4492f; }

/* ✓ de progreso en el índice */
.toc-check {
  display: inline-block; width: 1.1em; margin-right: 4px;
  color: #5c8a3a; font-weight: 700;
}

/* ---------- Cuerpo: índice + área del iframe ---------- */
.reader-body { flex: 1 1 auto; display: flex; position: relative; min-height: 0; }

.frame-wrap { flex: 1 1 auto; min-width: 0; display: flex; }
.piece-frame {
  flex: 1 1 auto; width: 100%; height: 100%; border: 0; background: var(--visor-bg);
  transition: opacity 0.15s ease;
}
.piece-frame.loading { opacity: 0; }   /* fundido on-demand */

/* ---------- Índice de piezas ---------- */
.toc-panel {
  background: var(--visor-panel);
  border-right: 1px solid var(--visor-line);
  overflow-y: auto;
  display: flex; flex-direction: column;
}
.toc-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--visor-line);
  position: sticky; top: 0; background: var(--visor-panel);
}
.toc-head h2 { margin: 0; font-size: 14px; letter-spacing: 0.02em; color: var(--visor-ink); }
.toc-close { display: none; border: 0; background: none; font-size: 18px; cursor: pointer; color: var(--visor-muted); }
.toc-list { padding: 8px 0 24px; }
.toc-group { padding: 4px 0; }
.toc-chapter {
  margin: 14px 16px 6px; font-size: 11px; text-transform: uppercase;
  letter-spacing: 0.12em; color: var(--visor-accent); font-family: var(--f-mono);
}
.toc-list ul { list-style: none; margin: 0; padding: 0; }
.toc-item a {
  display: block; padding: 8px 16px; font-size: 13px; line-height: 1.35;
  color: var(--visor-ink); text-decoration: none; border-left: 3px solid transparent;
}
.toc-item a:hover { background: #f5f3f0; }
.toc-item.active a { border-left-color: var(--visor-accent); background: #f5f3f0; font-weight: 600; }

.toc-backdrop { display: none; }

/* ---------- Controles de navegación ---------- */
.reader-controls {
  height: var(--controls-h); flex: 0 0 var(--controls-h);
  display: flex; align-items: center; justify-content: center; gap: 20px;
  background: var(--visor-panel); border-top: 1px solid var(--visor-line);
  z-index: 30;
}
.nav-btn {
  font-size: 18px; width: 44px; height: 36px; border-radius: 8px;
  border: 1px solid var(--visor-line); background: #fff; color: var(--visor-ink); cursor: pointer;
}
.nav-btn:hover { background: #f5f5f5; }
.piece-counter {
  font-family: var(--f-mono); font-size: 12px; color: var(--visor-muted);
  min-width: 120px; text-align: center;
}

/* ---------- Barra de progreso ---------- */
.progress-bar { height: 3px; flex: 0 0 3px; background: #d8dcdd; }
.progress-fill { height: 100%; width: 0; background: var(--visor-accent); transition: width 0.2s ease; }

/* ============================================================
   DESKTOP (≥768px): índice fijo como sidebar
   ============================================================ */
.reader-shell.is-desktop .toc-panel {
  flex: 0 0 280px; width: 280px;
}
.reader-shell.is-desktop #toc-toggle { display: none; }

/* ============================================================
   MÓVIL (<768px): índice como overlay deslizante
   ============================================================ */
.reader-shell.is-mobile .toc-panel {
  position: absolute; top: 0; bottom: 0; left: 0; width: 82%; max-width: 320px;
  transform: translateX(-100%); transition: transform 0.25s ease; z-index: 50;
}
.reader-shell.is-mobile .toc-close { display: block; }
.reader-shell.is-mobile.toc-open .toc-panel { transform: translateX(0); }
.reader-shell.is-mobile.toc-open .toc-backdrop {
  display: block; position: absolute; inset: 0; background: rgba(0,0,0,0.4); z-index: 40;
}
