/* ==========================================================================
   VARIABLES Y CONFIGURACIÓN GLOBAL (NEGRO, GRIS Y ROJO)
   ========================================================================== */
:root {
  --bg-main: #0a0a0c;
  --bg-surface: #121216;
  --bg-card: #18181f;
  --bg-card-hover: #1f1f28;
  --border-color: #2a2a35;
  --border-glow: rgba(229, 9, 20, 0.4);
  
  --primary: #e50914;
  --primary-hover: #ff1e2b;
  --primary-glow: rgba(229, 9, 20, 0.25);
  
  --text-main: #f1f1f3;
  --text-muted: #9ba1a6;
  --text-subtle: #6c7278;
  
  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --container-max: 1280px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
  font-size: 16px;
}

body {
  background-color: var(--bg-main);
  color: var(--text-main);
  font-family: var(--font-sans);
  line-height: 1.6;
  overflow-x: hidden;
}

.layout {
  width: 100%;
  max-width: var(--container-max);
  margin: 0 auto;
  padding: 0 1.5rem;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* ==========================================================================
   BOTONES Y COMPONENTES GLOBALES
   ========================================================================== */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background-color: var(--primary);
  color: #fff;
  font-weight: 600;
  padding: 0.7rem 1.4rem;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  text-decoration: none;
  transition: var(--transition);
  box-shadow: 0 4px 14px var(--primary-glow);
}

.button:hover {
  background-color: var(--primary-hover);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(229, 9, 20, 0.4);
}

.button--small {
  padding: 0.45rem 0.9rem;
  font-size: 0.875rem;
}

.button--outline {
  background-color: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-main);
  box-shadow: none;
}

.button--outline:hover {
  border-color: var(--primary);
  background-color: rgba(229, 9, 20, 0.08);
}

.link-button {
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  font-weight: 500;
  font-size: inherit;
  text-decoration: underline;
}

.eyebrow {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--primary);
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.empty-state {
  color: var(--text-muted);
  font-style: italic;
  padding: 2rem 0;
}

/* ==========================================================================
   CABECERA Y NAVEGACIÓN
   ========================================================================== */
.site-header {
  position: sticky;
  top: 0;
  z-index: 1000;
  background-color: rgba(10, 10, 12, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
  padding: 1rem 0;
}

.nav-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--text-main);
  text-decoration: none;
  letter-spacing: -0.03em;
}

.brand span {
  color: var(--primary);
}

.main-nav {
  display: flex;
  align-items: center;
  gap: 2rem;
}

.main-nav a {
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 500;
  transition: var(--transition);
}

.main-nav a:hover {
  color: var(--text-main);
}

.genre-menu {
  position: relative;
  cursor: pointer;
}

.genre-menu summary {
  list-style: none;
  color: var(--text-muted);
  font-weight: 500;
}

.genre-menu summary:hover {
  color: var(--text-main);
}

.genre-menu__list {
  position: absolute;
  top: 150%;
  left: 0;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0;
  min-width: 180px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
  display: flex;
  flex-direction: column;
}

.genre-menu__list a {
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  white-space: nowrap;
}

.genre-menu__list a:hover {
  background-color: rgba(229, 9, 20, 0.1);
  color: var(--primary);
}

.nav-account {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.reader-name {
  font-size: 0.9rem;
  color: var(--text-muted);
}

.nav-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  flex-direction: column;
  gap: 5px;
}

.nav-toggle span {
  display: block;
  width: 25px;
  height: 2px;
  background-color: var(--text-main);
}

/* ==========================================================================
   4.5 CARRUSEL DE PERSONAJES (FORMATO CARTA / CARD)
   ========================================================================== */
.characters-banner-section {
  padding: 3rem 0;
  background: linear-gradient(180deg, var(--bg-main) 0%, var(--bg-surface) 100%);
  border-bottom: 1px solid var(--border-color);
}

.characters-banner-header {
  margin-bottom: 1.5rem;
}

.characters-carousel-container {
  overflow-x: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--primary) var(--border-color);
  padding-bottom: 1rem;
}

.characters-carousel-container::-webkit-scrollbar {
  height: 6px;
}

.characters-carousel-container::-webkit-scrollbar-thumb {
  background-color: var(--primary);
  border-radius: 4px;
}

.characters-track {
  display: flex;
  gap: 1.25rem;
  padding: 0.5rem 0;
}

/* Diseño de Carta Coleccionable */
.character-mini-card {
  flex: 0 0 170px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: var(--transition);
  position: relative;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
}

.character-mini-card:hover {
  transform: translateY(-6px);
  border-color: var(--primary);
  box-shadow: 0 12px 30px var(--border-glow);
}

.character-mini-avatar {
  width: 100%;
  height: 200px;
  background-color: #000;
  overflow: hidden;
  position: relative;
}

.character-mini-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.5s ease;
}

.character-mini-card:hover .character-mini-avatar img {
  transform: scale(1.08);
}

/* Marco decorativo interno estilo carta */
.character-mini-avatar::after {
  content: '';
  position: absolute;
  inset: 0;
  border: 1px solid rgba(255, 255, 255, 0.08);
  pointer-events: none;
}

.character-mini-info {
  padding: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  background: linear-gradient(180deg, var(--bg-card) 0%, #141419 100%);
}

.character-mini-info strong {
  font-size: 0.95rem;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.character-mini-info small {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ==========================================================================
   5. CONTENIDO PRINCIPAL (HERO Y DESTACADAS)
   ========================================================================== */
.hero {
  padding: 5rem 0;
  background: radial-gradient(circle at 50% 20%, rgba(229, 9, 20, 0.12) 0%, transparent 60%);
  text-align: center;
}

.hero__content {
  max-width: 750px;
  margin: 0 auto;
}

.hero h1 {
  font-size: clamp(2.2rem, 4vw, 3.5rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  margin-bottom: 1rem;
  color: var(--text-main);
}

.hero p {
  color: var(--text-muted);
  font-size: 1.1rem;
  margin-bottom: 2rem;
}

/* Sección de Historias Destacadas */
.popular-section {
  padding: 4rem 0;
}

.section-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 2rem;
}

.section-heading h2 {
  font-size: 1.8rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.carousel-controls {
  display: flex;
  gap: 0.5rem;
}

.carousel-controls button {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
}

.carousel-controls button:hover {
  background: var(--primary);
  border-color: var(--primary);
}

.popular-carousel {
  display: flex;
  gap: 1.5rem;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  padding-bottom: 1rem;
}

.popular-carousel::-webkit-scrollbar {
  display: none;
}

/* Tarjeta de Historial / Portada Destacada */
.featured-card {
  flex: 0 0 240px;
  height: 350px;
  border-radius: var(--radius-md);
  overflow: hidden;
  position: relative;
  scroll-snap-align: start;
  border: 1px solid var(--border-color);
  text-decoration: none;
  transition: var(--transition);
}

.featured-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.5s ease;
}

.featured-card:hover {
  transform: translateY(-8px);
  border-color: var(--primary);
}

.featured-card:hover img {
  transform: scale(1.05);
}

.featured-card__shade {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, transparent 40%, rgba(10, 10, 12, 0.9) 100%);
}

.featured-card__content {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  z-index: 2;
}

.featured-card__content small {
  color: var(--primary);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
}

.featured-card__content strong {
  color: var(--text-main);
  font-size: 1.1rem;
  line-height: 1.2;
}

.featured-card__content em {
  color: var(--text-muted);
  font-style: normal;
  font-size: 0.85rem;
}

/* ==========================================================================
   5.3 CATÁLOGO GENERAL Y BÚSQUEDA
   ========================================================================== */
.catalog-section {
  padding: 4rem 0;
  background-color: var(--bg-surface);
  border-top: 1px solid var(--border-color);
}

.section-heading--catalog {
  flex-wrap: wrap;
  gap: 1.5rem;
  margin-bottom: 3rem;
}

.search-form {
  display: flex;
  gap: 0.5rem;
  width: 100%;
  max-width: 450px;
}

.search-form input {
  flex: 1;
  background-color: var(--bg-main);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.7rem 1rem;
  color: var(--text-main);
  outline: none;
  transition: var(--transition);
}

.search-form input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.search-form button {
  background-color: var(--primary);
  color: #fff;
  border: none;
  padding: 0 1.25rem;
  border-radius: var(--radius-sm);
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.search-form button:hover {
  background-color: var(--primary-hover);
}

.genre-row {
  margin-bottom: 3rem;
}

.genre-row h3 {
  font-size: 1.4rem;
  font-weight: 600;
  margin-bottom: 1.25rem;
  border-left: 3px solid var(--primary);
  padding-left: 0.75rem;
}

.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1.5rem;
}

.book-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: var(--transition);
}

.book-card:hover {
  transform: translateY(-5px);
  border-color: var(--primary);
  box-shadow: 0 8px 25px rgba(0,0,0,0.5);
}

.book-card a {
  position: relative;
  height: 260px;
  display: block;
  text-decoration: none;
  overflow: hidden;
}

.book-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.4s ease;
}

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

.book-card__overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, transparent 60%, rgba(0,0,0,0.8) 100%);
}

.book-card__title {
  position: absolute;
  bottom: 10px;
  left: 10px;
  right: 10px;
  color: #fff;
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.2;
  z-index: 2;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.book-card p {
  padding: 0.75rem 1rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  background-color: var(--bg-card);
}

/* ==========================================================================
   FOOTER, TOAST Y MODALES
   ========================================================================== */
.site-footer {
  padding: 3rem 0;
  background-color: var(--bg-main);
  border-top: 1px solid var(--border-color);
  text-align: center;
}

.site-footer .brand {
  display: inline-block;
  margin-bottom: 0.5rem;
}

.site-footer p {
  color: var(--text-subtle);
  font-size: 0.9rem;
}

/* Notificaciones Toast */
.toast {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  padding: 1rem 1.5rem;
  border-radius: var(--radius-sm);
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  box-shadow: 0 10px 30px rgba(0,0,0,0.6);
  z-index: 2000;
  animation: slideIn 0.3s ease;
}

.toast--success { border-left: 4px solid #22c55e; }
.toast--error { border-left: 4px solid var(--primary); }

@keyframes slideIn {
  from { transform: translateY(100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* Modales */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 3000;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal:target, .modal[aria-hidden="false"] {
  display: flex;
}

.modal__backdrop {
  position: absolute;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(5px);
}

.modal__dialog {
  position: relative;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 20px 40px rgba(0,0,0,0.8);
  z-index: 2;
}

.modal__close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
}

.modal__close:hover {
  color: var(--text-main);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-top: 1.5rem;
}

.auth-form label {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.auth-form input {
  background-color: var(--bg-main);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  color: var(--text-main);
  outline: none;
}

.auth-form input:focus {
  border-color: var(--primary);
}

.auth-form button[type="submit"] {
  margin-top: 0.5rem;
}

.auth-divider {
  text-align: center;
  border-bottom: 1px solid var(--border-color);
  line-height: 0.1em;
  margin: 1.5rem 0;
}

.auth-divider span {
  background: var(--bg-surface);
  padding: 0 10px;
  color: var(--text-subtle);
  font-size: 0.8rem;
}

.google-signin {
  display: flex;
  justify-content: center;
}

.modal__switch {
  text-align: center;
  margin-top: 1.5rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* ==========================================================================
   DISEÑO RESPONSIVO (MÓVILES Y TABLETS)
   ========================================================================== */
@media (max-width: 768px) {
  .main-nav {
    display: none; /* Se maneja con JS o tu script desplegable existente */
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background-color: var(--bg-surface);
    flex-direction: column;
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    box-shadow: 0 15px 30px rgba(0,0,0,0.6);
  }

  /* Si tu JS añade clases para mostrar el menú móvil */
  .main-nav.is-open {
    display: flex;
  }

  .nav-toggle {
    display: flex;
  }

  .section-heading {
    flex-direction: column;
    align-items: flex-start;
    gap: 1rem;
  }

  .book-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  }

  .character-mini-card {
    flex: 0 0 140px;
  }

  .character-mini-avatar {
    height: 160px;
  }
}