/* ==========================================================================
   ARQUITECTURA VISUAL INTEGRAL: REVISTA 3D, 7 ATMÓSFERAS, UI Y HERRAMIENTAS
   VERDAD ETERNA — RODOLFO JOSÉ DELGADO COLMENARES (1999–2000 / 2010)
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. GALERÍA DE 7 ATMÓSFERAS DE LECTURA (THEMES)
   -------------------------------------------------------------------------- */
/* 1. Obsidiana Imperial (Base) */
[data-theme="dark"] {
  --bg-primary: #0a0b0e;
  --bg-secondary: #11131a;
  --bg-card: #161922;
  --bg-elevated: #1e2230;
  --text-primary: #f2efe9;
  --text-secondary: #c5bfb3;
  --text-muted: #8a8478;
  --gold-primary: #d4af37;
  --gold-light: #f3e5ab;
  --gold-dark: #997a15;
  --accent-crimson: #8b1e24;
  --border-subtle: rgba(212, 175, 55, 0.22);
  --border-strong: rgba(212, 175, 55, 0.55);
  --desk-wood: #0f1118;
}

/* 2. Pergamino de Oxford */
[data-theme="parchment"] {
  --bg-primary: #f7f3e8;
  --bg-secondary: #efe9d8;
  --bg-card: #fcfaf2;
  --bg-elevated: #e6dec8;
  --text-primary: #1b1814;
  --text-secondary: #3d372e;
  --text-muted: #6e6559;
  --gold-primary: #8c6611;
  --gold-light: #5c4106;
  --gold-dark: #6b4c08;
  --accent-crimson: #7a161b;
  --border-subtle: rgba(140, 102, 17, 0.25);
  --border-strong: rgba(140, 102, 17, 0.6);
  --desk-wood: #3a2b1c;
}

/* 3. Sepia de Biblioteca Antigua */
[data-theme="sepia"] {
  --bg-primary: #1a1510;
  --bg-secondary: #241d16;
  --bg-card: #2c241b;
  --bg-elevated: #382e22;
  --text-primary: #eadbc8;
  --text-secondary: #c9b69c;
  --text-muted: #948169;
  --gold-primary: #dfb15b;
  --gold-light: #f6dca8;
  --gold-dark: #a67c2e;
  --accent-crimson: #9e2a2b;
  --border-subtle: rgba(223, 177, 91, 0.22);
  --border-strong: rgba(223, 177, 91, 0.55);
  --desk-wood: #2c1e13;
}

/* 4. Noche Abisal OLED (Negro Puro) */
[data-theme="oled"] {
  --bg-primary: #000000;
  --bg-secondary: #080808;
  --bg-card: #101010;
  --bg-elevated: #181818;
  --text-primary: #e0ded8;
  --text-secondary: #a8a49c;
  --text-muted: #66635c;
  --gold-primary: #c5a028;
  --gold-light: #e6c86e;
  --gold-dark: #82660f;
  --accent-crimson: #a31d24;
  --border-subtle: rgba(197, 160, 40, 0.25);
  --border-strong: rgba(197, 160, 40, 0.6);
  --desk-wood: #000000;
}

/* 5. Esmeralda de Claustro Universitario */
[data-theme="emerald"] {
  --bg-primary: #051410;
  --bg-secondary: #0a1f1a;
  --bg-card: #102d26;
  --bg-elevated: #183e35;
  --text-primary: #f2f7f4;
  --text-secondary: #b8d4cb;
  --text-muted: #78998f;
  --gold-primary: #d4af37;
  --gold-light: #faeab8;
  --gold-dark: #9e801b;
  --accent-crimson: #9e2a2b;
  --border-subtle: rgba(212, 175, 55, 0.25);
  --border-strong: rgba(212, 175, 55, 0.55);
  --desk-wood: #04100d;
}

/* 6. Códice Púrpura Bizantino */
[data-theme="byzantine"] {
  --bg-primary: #15081b;
  --bg-secondary: #1e0e26;
  --bg-card: #2a1436;
  --bg-elevated: #3b1d4c;
  --text-primary: #f8effb;
  --text-secondary: #d8c2e0;
  --text-muted: #9f84a8;
  --gold-primary: #e6b830;
  --gold-light: #fbe68b;
  --gold-dark: #a17c14;
  --accent-crimson: #c2185b;
  --border-subtle: rgba(230, 184, 48, 0.28);
  --border-strong: rgba(230, 184, 48, 0.65);
  --desk-wood: #100514;
}

/* 7. Edición Blanca de Alto Contraste Clínico */
[data-theme="clinical-white"] {
  --bg-primary: #ffffff;
  --bg-secondary: #f4f5f7;
  --bg-card: #ffffff;
  --bg-elevated: #e8ebf0;
  --text-primary: #000000;
  --text-secondary: #222222;
  --text-muted: #555555;
  --gold-primary: #8a6a12;
  --gold-light: #523e06;
  --gold-dark: #423204;
  --accent-crimson: #b71c1c;
  --border-subtle: rgba(0, 0, 0, 0.18);
  --border-strong: rgba(0, 0, 0, 0.5);
  --desk-wood: #d5d8de;
}

/* --------------------------------------------------------------------------
   2. TIPOGRAFÍAS, INTERLINEADO Y CAJA TIPOGRÁFICA
   -------------------------------------------------------------------------- */
:root {
  --active-font-family: 'Cormorant Garamond', 'Times New Roman', serif;
  --codex-sheet-max-width: 920px;
  --codex-line-height: 1.88;
  --desk-tilt: 0deg;
}

.book-viewport .prose, .book-sheet p {
  font-family: var(--active-font-family) !important;
  line-height: var(--codex-line-height) !important;
}

.book-sheet {
  max-width: var(--codex-sheet-max-width) !important;
  transition: max-width 0.3s ease;
}

/* --------------------------------------------------------------------------
   3. GAVETA MÓVIL RESPONSIVA (MOBILE DRAWER) PARA EL ÍNDICE
   -------------------------------------------------------------------------- */
.mobile-toc-toggle {
  display: none;
}

@media (max-width: 1100px) {
  .mobile-toc-toggle {
    display: inline-flex !important;
  }

  .codex-sidebar {
    position: fixed !important;
    top: 60px !important;
    left: 0 !important;
    bottom: 0 !important;
    width: 320px !important;
    max-width: 85vw !important;
    z-index: 99999 !important;
    transform: translateX(-100%);
    transition: transform 0.32s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: 10px 0 40px rgba(0,0,0,0.85);
    display: block !important;
  }

  .codex-sidebar.drawer-open {
    transform: translateX(0) !important;
  }

  .drawer-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    backdrop-filter: blur(4px);
    z-index: 99998;
    display: none;
  }

  .drawer-overlay.active {
    display: block;
  }
}

/* --------------------------------------------------------------------------
   4. REGLA LUMINOSA DE LECTURA & MODO TAMEION (CLAUSURA DE DISTRACCIONES)
   -------------------------------------------------------------------------- */
#reading-ruler-guide {
  position: fixed;
  left: 0;
  right: 0;
  height: 38px;
  background: linear-gradient(180deg, rgba(212, 175, 55, 0.03), rgba(212, 175, 55, 0.16), rgba(212, 175, 55, 0.03));
  border-top: 1px dashed rgba(212, 175, 55, 0.35);
  border-bottom: 1px dashed rgba(212, 175, 55, 0.35);
  pointer-events: none;
  z-index: 9990;
  display: none;
  mix-blend-mode: screen;
}

/* Modo Tameion (Aposento Cerrado) */
body.tameion-active .top-command-bar,
body.tameion-active .codex-sidebar,
body.tameion-active #reading-progress,
body.tameion-active .tts-floating-dock {
  opacity: 0 !important;
  pointer-events: none !important;
  transform: translateY(-20px);
  transition: opacity 0.4s ease, transform 0.4s ease;
}

body.tameion-active .book-sheet {
  box-shadow: 0 0 100px rgba(0, 0, 0, 0.95);
  border-color: rgba(212, 175, 55, 0.4);
}

.tameion-exit-btn {
  position: fixed;
  top: 20px;
  right: 24px;
  z-index: 100000;
  background: var(--bg-card);
  border: 1px solid var(--gold-primary);
  color: var(--gold-primary);
  padding: 8px 18px;
  border-radius: 99px;
  font-family: var(--font-ui);
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 8px 30px rgba(0,0,0,0.8);
  display: none;
}

body.tameion-active .tameion-exit-btn {
  display: inline-flex;
}

/* --------------------------------------------------------------------------
   5. ESCUDO DRM ÓPTICO: DESENFOQUE INSTANTÁNEO ANTI-SCREENSHOT
   -------------------------------------------------------------------------- */
.anti-capture-active {
  filter: none !important;
  user-select: none !important;
}

.anti-capture-curtain {
  position: fixed;
  inset: 0;
  background: rgba(10, 11, 14, 0.96);
  z-index: 999999;
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  color: var(--gold-primary);
  font-family: var(--font-display);
  text-align: center;
  padding: 2rem;
}

.anti-capture-curtain.active {
  display: flex;
}

/* Filigrana Forense Diagonal */
.forensic-watermark-stamp {
  position: fixed;
  bottom: 12px;
  left: 16px;
  font-family: var(--font-mono, monospace);
  font-size: 0.64rem;
  color: var(--gold-primary);
  opacity: 0.35;
  pointer-events: none;
  z-index: 9991;
  letter-spacing: 0.06em;
}

/* --------------------------------------------------------------------------
   6. VISTA BILINGÜE PARALELA (ESPEJO INTERLINEAL)
   -------------------------------------------------------------------------- */
.bilingual-mode-active .book-viewport {
  max-width: 1680px !important;
}

.bilingual-mode-active .book-sheet {
  max-width: 100% !important;
  display: grid !important;
  grid-template-columns: 1fr 1fr !important;
  gap: 2.5rem !important;
}

.bilingual-col-original {
  border-right: 1px solid var(--border-subtle);
  padding-right: 1.8rem;
}

.bilingual-col-translation {
  padding-left: 0.5rem;
}

@media (max-width: 900px) {
  .bilingual-mode-active .book-sheet {
    grid-template-columns: 1fr !important;
    gap: 1.5rem !important;
  }
  .bilingual-col-original {
    border-right: none;
    border-bottom: 1px solid var(--border-subtle);
    padding-bottom: 1.5rem;
  }
}

/* --------------------------------------------------------------------------
   7. ESCENARIO REVISTA 3D INTERACTIVA CON PERSPECTIVA CSS3D & ATRIL ORBITAL
   -------------------------------------------------------------------------- */
#magazine-3d-stage {
  display: none !important;
}

/* Contenedor del Libro 3D */
.magazine-3d-desk {
  width: 100%;
  height: calc(100% - 110px);
  display: flex;
  align-items: center;
  justify-content: center;
  transform-style: preserve-3d;
  transform: rotateX(var(--desk-tilt, 0deg));
  transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.magazine-3d-book {
  position: relative;
  width: 940px;
  height: 620px;
  max-width: 94vw;
  max-height: 80vh;
  transform-style: preserve-3d;
  box-shadow: 0 35px 80px rgba(0, 0, 0, 0.9), 0 0 45px rgba(212, 175, 55, 0.15);
  border-radius: 8px;
  display: flex;
}

/* Pliego Doble Página */
.magazine-page-left, .magazine-page-right {
  flex: 1;
  background: var(--bg-card);
  color: var(--text-primary);
  padding: 2.2rem 2.4rem;
  overflow-y: auto;
  box-sizing: border-box;
  position: relative;
  border: 1px solid var(--border-subtle);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.7;
}

.magazine-page-left {
  border-radius: 8px 0 0 8px;
  box-shadow: inset -25px 0 35px rgba(0,0,0,0.45);
}

.magazine-page-right {
  border-radius: 0 8px 8px 0;
  box-shadow: inset 25px 0 35px rgba(0,0,0,0.45);
}

/* Lomo Cosido Central */
.magazine-book-spine {
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 14px;
  transform: translateX(-50%);
  background: linear-gradient(90deg, rgba(0,0,0,0.7), rgba(212,175,55,0.4), rgba(0,0,0,0.7));
  z-index: 10;
  pointer-events: none;
  box-shadow: 0 0 10px rgba(0,0,0,0.8);
}

/* Botones flotantes de cambio de página */
.magazine-nav-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(14, 16, 22, 0.88);
  border: 1.5px solid var(--gold-primary);
  color: var(--gold-primary);
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 100;
  backdrop-filter: blur(10px);
  transition: all 0.22s ease;
  box-shadow: 0 6px 20px rgba(0,0,0,0.8);
}

.magazine-nav-arrow:hover {
  background: var(--gold-primary);
  color: #0a0b0e;
  transform: translateY(-50%) scale(1.1);
}

.magazine-nav-arrow.prev { left: 24px; }
.magazine-nav-arrow.next { right: 24px; }

/* --------------------------------------------------------------------------
   8. CARRUSEL / SLIDER 3D TIPO COVERFLOW (INFERIOR)
   -------------------------------------------------------------------------- */
.magazine-coverflow-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 100px;
  background: rgba(10, 11, 14, 0.94);
  border-top: 1px solid var(--border-subtle);
  backdrop-filter: blur(14px);
  display: flex;
  align-items: center;
  gap: 1.2rem;
  padding: 0 1.5rem;
  overflow-x: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--gold-primary) transparent;
  z-index: 100;
}

.coverflow-card {
  flex: 0 0 64px;
  height: 82px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 4px;
  text-align: center;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: 0 4px 12px rgba(0,0,0,0.6);
}

.coverflow-card:hover, .coverflow-card.active {
  border-color: var(--gold-primary);
  transform: translateY(-6px) scale(1.08);
  box-shadow: 0 8px 25px rgba(212, 175, 55, 0.35);
}

.coverflow-card .cf-num {
  font-family: var(--font-display);
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--gold-primary);
}

.coverflow-card .cf-name {
  font-size: 0.58rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 58px;
  margin-top: 2px;
}

/* Barra de herramientas del modo 3D (Superior del stage) */
.magazine-3d-toolbar {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: rgba(14, 16, 22, 0.9);
  border: 1px solid var(--border-subtle);
  padding: 0.4rem 1.2rem;
  border-radius: 99px;
  backdrop-filter: blur(14px);
  z-index: 100;
}

/* --------------------------------------------------------------------------
   9. POPOVERS FILOLÓGICOS DEL GLOSARIO (TARJETAS IN-LINE)
   -------------------------------------------------------------------------- */
.glossary-term-link {
  color: var(--gold-primary);
  border-bottom: 1px dotted var(--gold-primary);
  cursor: pointer;
  font-weight: 500;
  position: relative;
  text-decoration: none;
  transition: color 0.18s;
}

.glossary-term-link:hover {
  color: var(--gold-light);
  border-bottom-style: solid;
}

#philological-popover {
  position: fixed;
  z-index: 100005;
  background: rgba(16, 19, 26, 0.97);
  border: 1.5px solid var(--gold-primary);
  border-radius: 12px;
  padding: 1.1rem 1.3rem;
  max-width: 340px;
  box-shadow: 0 16px 45px rgba(0, 0, 0, 0.9), 0 0 25px rgba(212, 175, 55, 0.2);
  backdrop-filter: blur(20px);
  font-family: var(--font-ui);
  display: none;
  pointer-events: auto;
  animation: popoverFadeIn 0.18s ease;
}

@keyframes popoverFadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

#philological-popover .pop-greek {
  font-family: var(--font-display);
  font-size: 1.1rem;
  color: var(--gold-light);
  font-weight: 700;
}

#philological-popover .pop-translit {
  font-size: 0.76rem;
  color: var(--text-muted);
  font-style: italic;
  margin-bottom: 0.5rem;
}

#philological-popover .pop-def {
  font-size: 0.84rem;
  line-height: 1.55;
  color: var(--text-primary);
  border-top: 1px solid rgba(212, 175, 55, 0.2);
  padding-top: 0.5rem;
}

/* --------------------------------------------------------------------------
   10. COMMAND PALETTE (CTRL + K)
   -------------------------------------------------------------------------- */
#command-palette-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(14px);
  z-index: 100010;
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding-top: 12vh;
}

#command-palette-backdrop.active {
  display: flex;
}

.command-palette-box {
  background: linear-gradient(145deg, #161922, #0d0f14);
  border: 1.5px solid var(--gold-primary);
  border-radius: 16px;
  width: 620px;
  max-width: 92vw;
  box-shadow: 0 25px 70px rgba(0, 0, 0, 0.95), 0 0 35px rgba(212, 175, 55, 0.25);
  overflow: hidden;
  font-family: var(--font-ui);
}

.cmd-input-wrap {
  display: flex;
  align-items: center;
  padding: 1rem 1.4rem;
  border-bottom: 1px solid rgba(212, 175, 55, 0.2);
  gap: 0.75rem;
}

.cmd-input-wrap input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 1.05rem;
  font-family: var(--font-ui);
}

.cmd-results-list {
  max-height: 380px;
  overflow-y: auto;
  list-style: none;
  padding: 0.5rem 0;
}

.cmd-item {
  padding: 0.75rem 1.4rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  transition: background 0.15s;
  color: var(--text-primary);
  font-size: 0.88rem;
}

.cmd-item:hover, .cmd-item.selected {
  background: rgba(212, 175, 55, 0.15);
  color: var(--gold-primary);
}

.cmd-item .cmd-key-hint {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-muted);
  border: 1px solid var(--border-subtle);
  padding: 2px 6px;
  border-radius: 4px;
}

/* --------------------------------------------------------------------------
   11. RADAR SVG DE AUTOAUDITORÍA ÉTICA & INSPECTOR DE ENTROPÍA (ANEXO I)
   -------------------------------------------------------------------------- */
.audit-radar-container {
  margin: 2rem auto;
  max-width: 580px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  padding: 1.8rem;
  text-align: center;
}

.audit-slider-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.9rem;
  font-size: 0.84rem;
  gap: 1rem;
}

.audit-slider-row label {
  flex: 1;
  text-align: left;
}

.audit-slider-row input[type="range"] {
  flex: 1;
  accent-color: var(--gold-primary);
}

.audit-radar-svg {
  width: 260px;
  height: 260px;
  margin: 1.5rem auto 1rem;
}

/* --------------------------------------------------------------------------
   12. SELECTOR PERSONALIZABLE DE TAMAÑO DE HOJAS (ZOOM & ESCALA EDITORIAL)
   -------------------------------------------------------------------------- */
.sheet-size-dropdown {
  position: fixed;
  top: 52px;
  right: 180px;
  z-index: 100010;
  background: rgba(14, 16, 22, 0.97);
  border: 1px solid var(--gold-primary, #d4af37);
  border-radius: 12px;
  padding: 0.95rem 1.15rem;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.85), 0 0 25px rgba(212, 175, 55, 0.2);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  display: none;
  flex-direction: column;
  gap: 0.75rem;
  width: 290px;
  font-family: var(--font-ui, system-ui, sans-serif);
  animation: sizeDropdownIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.sheet-size-dropdown.active {
  display: flex !important;
}

@keyframes sizeDropdownIn {
  from { opacity: 0; transform: translateY(-8px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.sheet-size-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(212, 175, 55, 0.25);
  padding-bottom: 0.45rem;
  font-family: var(--font-display, 'Cinzel', serif);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--gold-primary, #d4af37);
}

.sheet-size-header .size-val {
  font-family: var(--font-mono, monospace);
  font-size: 0.82rem;
  color: var(--gold-light, #f3e5ab);
}

.sheet-size-presets {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem;
}

.size-preset-btn {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(212, 175, 55, 0.2);
  border-radius: 6px;
  color: var(--text-primary, #f2efe9);
  padding: 0.38rem 0.55rem;
  font-size: 0.73rem;
  cursor: pointer;
  text-align: center;
  transition: all 0.2s ease;
  font-family: var(--font-ui, sans-serif);
}

.size-preset-btn:hover,
.size-preset-btn.active {
  background: rgba(212, 175, 55, 0.2);
  border-color: var(--gold-primary, #d4af37);
  color: var(--gold-light, #f3e5ab);
  font-weight: 600;
}

.sheet-size-slider-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.2rem 0;
}

.sheet-size-slider-row input[type="range"] {
  flex: 1;
  accent-color: var(--gold-primary, #d4af37);
  height: 4px;
  cursor: pointer;
}

.sheet-size-slider-row span {
  font-family: var(--font-mono, monospace);
  font-size: 0.75rem;
  color: var(--text-muted, #8a8478);
}

