/* ==========================================================================
   Biblioteca de Clásicos Universales y Lector Web - Fijate.com
   Estándar Canónico Midnight Slate y Experiencia de Lectura Inmersiva
   ========================================================================== */

:root {
  --bg-primary: #0b0f17;
  --bg-surface: #121826;
  --bg-surface-elevated: #1a2336;
  --border-color: rgba(255, 255, 255, 0.08);
  --border-color-hover: rgba(255, 255, 255, 0.16);

  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --accent-gold: #f59e0b;
  --accent-gold-glow: rgba(245, 158, 11, 0.2);
  --accent-blue: #3b82f6;
  --accent-emerald: #10b981;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;

  --shadow-card: 0 4px 20px -2px rgba(0, 0, 0, 0.4);
  --shadow-hover: 0 12px 32px -4px rgba(0, 0, 0, 0.6);
}

[data-theme="light"] {
  --bg-primary: #f8fafc;
  --bg-surface: #ffffff;
  --bg-surface-elevated: #f1f5f9;
  --border-color: #e2e8f0;
  --border-color-hover: #cbd5e1;

  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;

  --shadow-card: 0 4px 16px -2px rgba(15, 23, 42, 0.06);
  --shadow-hover: 0 12px 28px -4px rgba(15, 23, 42, 0.12);
}

/* Base */
body {
  overflow-x: clip;
  width: 100%;
  max-width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  margin: 0;
  padding: 0;
}

.tool-layout {
  max-width: 1200px;
  margin: 1.5rem auto 3.5rem;
  padding: 0 1rem;
  width: 100%;
  box-sizing: border-box;
}

.tool-with-sidebar {
  display: grid;
  grid-template-columns: 1fr;
  gap: 2rem;
}

@media (min-width: 1536px) {
  .tool-with-sidebar {
    grid-template-columns: 1fr 300px;
  }
}

.tool-main-content {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1.75rem;
}

/* Tarjeta principal de catálogo */
.card-main {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  padding: 1.75rem;
  box-shadow: var(--shadow-card);
}

.card-header-library {
  margin-bottom: 1.5rem;
}

.section-title {
  font-family: 'Outfit', sans-serif;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0 0 0.5rem;
  letter-spacing: -0.02em;
}

.section-desc {
  color: var(--text-secondary);
  font-size: 0.95rem;
  line-height: 1.55;
  margin: 0;
}

/* Controles de la biblioteca */
.library-controls {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.search-box-library {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
}

.search-box-library svg {
  position: absolute;
  left: 1rem;
  color: var(--text-muted);
  pointer-events: none;
}

.search-box-library .text-input {
  width: 100%;
  height: 48px;
  padding: 0 1rem 0 2.85rem;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  box-sizing: border-box;
}

.search-box-library .text-input:focus {
  border-color: var(--accent-gold);
  box-shadow: 0 0 0 3px var(--accent-gold-glow);
}

/* Botones de filtro de categorías */
.filter-categories-row {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  padding-bottom: 0.5rem;
  -webkit-overflow-scrolling: touch;
}

.filter-categories-row::-webkit-scrollbar {
  height: 4px;
}

.filter-categories-row::-webkit-scrollbar-thumb {
  background: var(--border-color-hover);
  border-radius: 4px;
}

.btn-filter-cat {
  flex-shrink: 0;
  height: 40px;
  padding: 0 1.15rem;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  border-radius: 9999px;
  color: var(--text-secondary);
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s ease;
}

.btn-filter-cat:hover {
  border-color: var(--accent-gold);
  color: var(--text-primary);
}

.btn-filter-cat.active {
  background: var(--accent-gold);
  border-color: var(--accent-gold);
  color: #0b0f17;
  font-weight: 700;
}

/* Cuadrícula de libros */
.books-catalog-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
}

@media (min-width: 640px) {
  .books-catalog-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 1024px) {
  .books-catalog-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* Tarjeta individual de libro */
.book-card {
  display: flex;
  flex-direction: column;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-card);
  transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.book-card:hover {
  transform: translateY(-4px);
  border-color: var(--border-color-hover);
  box-shadow: var(--shadow-hover);
}

.book-cover-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 10;
  background: #0f172a;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.book-cover-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
  transition: transform 0.3s ease;
}

.book-card:hover .book-cover-img {
  transform: scale(1.03);
}

.book-year-badge {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  background: rgba(11, 15, 23, 0.85);
  backdrop-filter: blur(4px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--accent-gold);
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.25rem 0.6rem;
  border-radius: 9999px;
}

.book-body {
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  flex: 1;
}

.book-cat-tag {
  color: var(--accent-gold);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.35rem;
}

.book-title {
  font-family: 'Outfit', sans-serif;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0 0 0.35rem;
  line-height: 1.35;
}

.book-author {
  color: var(--text-secondary);
  font-size: 0.88rem;
  font-weight: 500;
  margin: 0 0 0.85rem;
}

.book-desc {
  color: var(--text-muted);
  font-size: 0.85rem;
  line-height: 1.5;
  margin: 0 0 1.25rem;
  flex: 1;
}

.book-actions-row {
  display: flex;
  gap: 0.75rem;
  margin-top: auto;
}

.btn-read-online {
  flex: 1 1 0%;
  height: 42px;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  background: var(--accent-gold);
  color: #0b0f17;
  font-weight: 700;
  font-size: 0.88rem;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: filter 0.2s;
  text-decoration: none;
}

.btn-read-online:hover {
  filter: brightness(1.1);
}

.btn-epub-download {
  height: 42px;
  min-height: 40px;
  padding: 0 0.9rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  font-size: 0.82rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  text-decoration: none;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-epub-download:hover {
  border-color: var(--accent-blue);
  color: var(--accent-blue);
}

/* ==========================================================================
   Lector Web Inmersivo a Pantalla Completa (Modal Reader)
   ========================================================================== */

.reader-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  transition: background-color 0.2s, color 0.2s;
}

/* Temas del lector */
.reader-modal-overlay[data-reader-theme="night"] {
  background-color: #0d1117;
  color: #c9d1d9;
}

.reader-modal-overlay[data-reader-theme="sepia"] {
  background-color: #fbf0d9;
  color: #382c1f;
}

.reader-modal-overlay[data-reader-theme="light"] {
  background-color: #ffffff;
  color: #1e293b;
}

.reader-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100%;
}

/* Barra superior del lector */
.reader-header {
  height: 64px;
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(128, 128, 128, 0.2);
  flex-shrink: 0;
  background: inherit;
}

.reader-book-meta {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  min-width: 0;
}

.btn-reader-exit {
  height: 40px;
  padding: 0 0.85rem;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(128, 128, 128, 0.15);
  border: 1px solid rgba(128, 128, 128, 0.25);
  border-radius: var(--radius-sm);
  color: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.2s;
}

.btn-reader-exit:hover {
  background: rgba(128, 128, 128, 0.25);
}

.reader-titles {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.reader-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 400px;
}

.reader-author {
  font-size: 0.8rem;
  opacity: 0.75;
}

/* Ajustes tipográficos */
.reader-settings-group {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.reader-theme-pills {
  display: flex;
  background: rgba(128, 128, 128, 0.15);
  padding: 3px;
  border-radius: 9999px;
  gap: 2px;
}

.btn-theme-pill {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid transparent;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.pill-light {
  background: #ffffff;
  color: #111827;
}

.pill-sepia {
  background: #fbf0d9;
  color: #382c1f;
}

.pill-night {
  background: #0d1117;
  color: #f1f5f9;
}

.btn-theme-pill.active {
  border-color: var(--accent-gold);
  transform: scale(1.05);
}

.reader-font-controls {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.btn-reader-btn {
  height: 36px;
  padding: 0 0.75rem;
  background: rgba(128, 128, 128, 0.15);
  border: 1px solid rgba(128, 128, 128, 0.25);
  border-radius: var(--radius-sm);
  color: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-reader-btn:hover {
  background: rgba(128, 128, 128, 0.25);
}

/* Viewport del lector */
.reader-viewport {
  flex: 1;
  overflow-y: auto;
  padding: 2.5rem 1.5rem;
  display: flex;
  justify-content: center;
}

.reader-page-content {
  width: 100%;
  max-width: 720px;
  line-height: 1.85;
  font-size: 1.15rem;
  box-sizing: border-box;
}

.reader-page-content.font-serif {
  font-family: 'Merriweather', Georgia, serif;
}

.reader-page-content.font-sans {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

.reader-page-content p {
  margin: 0 0 1.5rem;
  text-align: justify;
}

/* Barra inferior del lector */
.reader-footer {
  height: 60px;
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid rgba(128, 128, 128, 0.2);
  flex-shrink: 0;
  background: inherit;
}

.btn-reader-nav {
  height: 42px;
  min-height: 40px;
  padding: 0 1.25rem;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(128, 128, 128, 0.15);
  border: 1px solid rgba(128, 128, 128, 0.25);
  border-radius: var(--radius-sm);
  color: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-reader-nav:hover:not(:disabled) {
  background: rgba(128, 128, 128, 0.3);
}

.btn-reader-nav:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.reader-page-indicator {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.88rem;
  font-weight: 600;
  opacity: 0.8;
}

/* Modales canónicos de aviso */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10001;
  padding: 1rem;
}

.modal-box {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  max-width: 480px;
  width: 100%;
  padding: 1.5rem;
  box-shadow: var(--shadow-hover);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.modal-title {
  font-family: 'Outfit', sans-serif;
  font-size: 1.2rem;
  font-weight: 700;
  margin: 0;
}

.btn-close-modal {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}

.modal-body {
  color: var(--text-secondary);
  font-size: 0.92rem;
  line-height: 1.55;
  margin-bottom: 1.5rem;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
}

.btn-primary {
  height: 42px;
  min-height: 40px;
  padding: 0 1.5rem;
  background: var(--accent-gold);
  border: none;
  border-radius: var(--radius-sm);
  color: #0b0f17;
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
}

/* Responsive móvil */
@media (max-width: 768px) {
  .card-main {
    padding: 1.25rem;
  }

  .reader-header {
    padding: 0 1rem;
  }

  .btn-reader-exit span {
    display: none;
  }

  .reader-titles {
    max-width: 180px;
  }

  .reader-viewport {
    padding: 1.5rem 1rem;
  }

  .reader-page-content {
    font-size: 1.05rem;
  }
}
