/* ==========================================================================
   CYPHER ANIME - CLEAN LIGHT DESIGN SYSTEM (MINIMALIST & PROFESSIONAL UI/UX)
   Diseño de Alta Gama | Agradable a la Vista | Tipografía de Altura
   Paleta Slate-Indigo | Sombras Suaves | Badges Pastel Profesionales
   ========================================================================== */

/* Variables del Sistema de Diseño (Clean Light UX) */
:root {
  /* Paleta Light Premium */
  --bg-primary: #f8fafc;        /* Slate 50 (Fondo ultra limpio y suave) */
  --bg-secondary: #ffffff;      /* Blanco Puro (Tarjetas y Paneles) */
  --bg-tertiary: #f1f5f9;       /* Slate 100 (Inputs y Estados Inactivos) */
  
  --text-main: #0f172a;         /* Slate 900 (Texto Principal de Alta Legibilidad) */
  --text-muted: #475569;        /* Slate 600: Contraste de 4.64:1 (Cumple WCAG AA) */
  --border-color: #e2e8f0;      /* Slate 200 (Bordes Finos y Limpios) */
  
  /* Paleta de Acentos Coherente y Profesional */
  --accent-indigo: #4f46e5;     /* Indigo 600 (Acento Principal) */
  --accent-indigo-light: #e0e7ff; /* Indigo 100 */
  --accent-blue: #0ea5e9;       /* Sky 500 (Acento Secundario) */
  --accent-blue-light: #e0f2fe; /* Sky 100 */
  --accent-purple: #7c3aed;     /* Violeta (estados vacíos e íconos informativos) */

  --border-hover: #cbd5e1;      /* Slate 300 (Bordes en hover) */
  --skeleton-base: #f1f5f9;     /* Slate 100 (Base del shimmer de carga) */
  --skeleton-sheen: #e2e8f0;    /* Slate 200 (Brillo del shimmer de carga) */
  --gradient-overlay: linear-gradient(135deg, #4f46e5 0%, #0ea5e9 100%);

  /* Sombras UI/UX Suaves y Naturales */
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.03), 0 1px 2px rgba(15, 23, 42, 0.02);
  --shadow-md: 0 4px 6px -1px rgba(15, 23, 42, 0.04), 0 2px 4px -2px rgba(15, 23, 42, 0.03), 0 10px 15px -3px rgba(15, 23, 42, 0.03);
  --shadow-lg: 0 20px 25px -5px rgba(15, 23, 42, 0.06), 0 10px 10px -5px rgba(15, 23, 42, 0.04);
  
  /* Bordes & Transiciones */
  --radius-sm: 6px;             /* Bordes Modernos */
  --radius-md: 12px;            /* Contenedores y Tarjetas */
  --radius-lg: 16px;
  
  --transition-fast: color 0.2s ease, background-color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease, opacity 0.2s ease;
  --transition-smooth: all 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  
  /* Fuentes */
  --font-header: 'Space Grotesk', sans-serif;
  --font-body: 'Outfit', sans-serif;
  
  --scrollbar-thumb: #cbd5e1;
}

[data-theme="dark"] {
  --bg-primary: #0b0f19;          /* Slate 950 */
  --bg-secondary: #161e2e;        /* Slate 900 */
  --bg-tertiary: #1f2937;         /* Slate 800 */
  
  --text-main: #f8fafc;           /* Slate 50 */
  --text-muted: #94a3b8;          /* Slate 400 */
  --border-color: #374151;        /* Slate 700 */
  
  --accent-indigo: #6366f1;       /* Indigo 500 */
  --accent-indigo-light: #202740; /* Indigo oscuro translúcido */
  --accent-blue: #38bdf8;         /* Sky 400 */
  --accent-blue-light: #152c4a;   /* Sky oscuro translúcido */
  --accent-purple: #a78bfa;       /* Violeta claro para fondos oscuros */

  --border-hover: #4b5563;        /* Slate 600 */
  --skeleton-base: #1f2937;       /* Slate 800 */
  --skeleton-sheen: #2b3648;      /* Slate 750 aprox */

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4), 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -2px rgba(0, 0, 0, 0.2);
  --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.4), 0 10px 10px -5px rgba(0, 0, 0, 0.2);
  
  --scrollbar-thumb: #475569;     /* Slate 600 */
}

/* Reset de Estilos Básicos */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

*,
button,
input,
select,
textarea {
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5, h6, .view-title, .logo-area h1, .section-title h2 {
  font-family: var(--font-header) !important;
  color: var(--text-main);
}

body {
  background-color: var(--bg-primary);
  color: var(--text-main);
  overflow-x: hidden;
  height: 100vh;
  height: 100dvh; /* Evita saltos con barras dinámicas de navegadores móviles */
}

/* Scrollbar Personalizado Limpio */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) transparent;
}

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--accent-indigo);
}

/* ==========================================================================
   DISEÑO DE CONTENEDORES PRINCIPALES (GRID & LAYOUT)
   ========================================================================== */

.app-container {
  display: grid;
  grid-template-columns: 260px 1fr;
  height: 100vh;
  height: 100dvh;
  width: 100vw;
  overflow: hidden;
}

/* Sidebar con Minimalismo Blanco */
.sidebar {
  background-color: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  padding: 44px 24px;
  height: 100%;
  z-index: 100;
}

.logo-area {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 48px;
  padding-left: 8px;
}

.logo-icon {
  font-size: 1.5rem;
  color: var(--accent-indigo);
}

.logo-area h1 {
  font-size: 1.375rem;
  font-weight: 700;
  letter-spacing: -0.8px;
  color: var(--text-main);
}

.logo-area h1 span {
  color: var(--accent-blue);
  font-weight: 400;
}

.nav-links {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.9375rem;
  transition: var(--transition-fast);
}

/* Reset para nav-items que son <button> (ej. cambio de tema) */
button.nav-item {
  background: none;
  border: none;
  width: 100%;
  text-align: left;
  font-family: var(--font-body);
  cursor: pointer;
}

.nav-item i {
  font-size: 1rem;
  transition: var(--transition-fast);
}

.nav-item:hover {
  color: var(--text-main);
  background-color: var(--bg-primary);
}

.nav-item.active {
  color: var(--accent-indigo);
  background-color: var(--accent-indigo-light);
}

.nav-item.active i {
  color: var(--accent-indigo);
}

.provider-selector-container {
  margin-top: 24px;
  padding-top: 24px;
  border-top: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.provider-selector-container label {
  font-family: var(--font-header);
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
}

.provider-selector-container select {
  padding: 10px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background-color: var(--bg-tertiary);
  color: var(--text-main);
  font-family: var(--font-body);
  font-size: 0.875rem;
  font-weight: 600;
  outline: none;
  cursor: pointer;
  transition: var(--transition-fast);
  width: 100%;
}

.provider-selector-container select:focus {
  border-color: var(--accent-indigo);
}

.sidebar-footer {
  font-size: 0.6875rem;
  color: var(--text-muted);
  text-align: center;
  border-top: 1px solid var(--border-color);
  padding-top: 20px;
  font-weight: 500;
}

/* Área de Contenido Principal */
.main-content {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow-y: auto;
  padding: 44px 54px;
  position: relative;
}

/* ==========================================================================
   BARRA SUPERIOR (BÚSQUEDA INTEGRADA Y SLICK)
   ========================================================================== */

.top-bar {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 24px;
  margin-bottom: 40px;
  width: 100%;
  z-index: 10;
}

.search-box {
  position: relative;
  display: flex;
  align-items: center;
  flex: 1;
  max-width: 760px;
}

.search-icon {
  position: absolute;
  left: 22px;
  color: var(--text-muted);
  font-size: 1.125rem;
  transition: var(--transition-fast);
}

#search-input {
  width: 100%;
  padding: 16px 68px 16px 54px;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-main);
  font-size: 0.9375rem;
  font-weight: 500;
  transition: var(--transition-fast);
  box-shadow: var(--shadow-sm);
}

#search-input::placeholder {
  color: var(--text-muted);
  opacity: 0.6;
}

#search-input:focus {
  outline: none;
  border-color: var(--accent-indigo);
  box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.1);
}

#search-input:focus + .search-icon {
  color: var(--accent-indigo);
}

#search-btn {
  position: absolute;
  right: 8px;
  width: 44px; /* Touch target ampliado a 44px */
  height: 44px;
  border-radius: 8px;
  background: var(--accent-indigo);
  border: none;
  color: #fff;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition-fast);
  box-shadow: 0 2px 8px rgba(79, 70, 229, 0.2);
}

#search-btn:hover {
  background-color: #4338ca;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.35);
  transform: translateY(-1px);
}

/* ==========================================================================
   FILTROS DE GÉNERO (MINIMALIST SLATE CHIPS)
   ========================================================================== */

.genre-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 32px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border-color);
}

.genre-chip {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition-fast);
  white-space: nowrap;
}

.genre-chip:hover {
  color: var(--text-main);
  border-color: var(--border-hover);
  background-color: var(--bg-tertiary);
}

.genre-chip.active {
  background-color: var(--accent-indigo);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 4px 10px rgba(79, 70, 229, 0.2);
}

/* ==========================================================================
   VISTAS Y PANELES DINÁMICOS
   ========================================================================== */

.content-wrapper {
  position: relative;
  flex: 1;
}

.view-panel {
  display: none;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.view-panel.active {
  display: block;
  opacity: 1;
  transform: translateY(0);
}

.section-title {
  margin-bottom: 28px;
}

.section-title h2 {
  font-size: 1.875rem;
  font-weight: 700;
  margin-bottom: 6px;
  letter-spacing: -0.6px;
  color: var(--text-main);
}

.section-title p {
  color: var(--text-muted);
  font-size: 0.9375rem;
  font-weight: 500;
}

.back-btn {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 12px 18px;
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 28px;
  transition: var(--transition-fast);
  box-shadow: var(--shadow-sm);
}

.back-btn:hover {
  border-color: var(--accent-indigo);
  color: var(--accent-indigo);
  transform: translateX(-3px);
}

/* ==========================================================================
   TARJETAS Y CUADRÍCULA (CLEAN SLATE CARDS)
   ========================================================================== */

.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 28px;
  margin-bottom: 24px;
}

.anime-card {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
  cursor: pointer;
  transition: var(--transition-smooth);
  position: relative;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-sm);
}

.anime-card:hover {
  transform: translateY(-5px);
  border-color: rgba(79, 70, 229, 0.2);
  box-shadow: var(--shadow-lg);
}

.card-image-wrapper {
  position: relative;
  width: 100%;
  padding-top: 150%; /* 2:3 aspect ratio */
  background-color: var(--bg-tertiary);
  overflow: hidden;
}

.card-image {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: var(--transition-smooth);
}

.anime-card:hover .card-image {
  transform: scale(1.03);
}

/* Badges Dinámicos en Pastel Profesional */
.card-badge {
  position: absolute;
  top: 12px;
  right: 12px;
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  z-index: 5;
  font-family: var(--font-header);
  box-shadow: var(--shadow-sm);
  transition: var(--transition-fast);
}

/* Lógica de colores pastel y tipografías para cada proveedor */
.anime-card[data-url*="hentaila"] .card-badge {
  background-color: #fdf2f8;   /* Rosa Suave */
  color: #db2777;
  border: 1px solid #fbcfe8;
}

.anime-card[data-url*="jkanime"] .card-badge {
  background-color: #ecfeff;   /* Cian Suave */
  color: #0e7490; /* Cian 700: Contraste de 4.87:1 */
  border: 1px solid #c5f6fa;
}

.anime-card[data-url*="animeav1"] .card-badge {
  background-color: #e0e7ff;   /* Indigo Suave */
  color: #4f46e5;
  border: 1px solid #c7d2fe;
}

.card-content {
  padding: 14px;
  display: flex;
  flex-direction: column;
  flex: 1;
}

.card-title {
  font-size: 0.9375rem;
  font-weight: 700;
  margin-bottom: 8px;
  line-height: 1.35;
  color: var(--text-main);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  height: 2.5rem;
  transition: var(--transition-fast);
}

.anime-card:hover .card-title {
  color: var(--accent-indigo);
}

.card-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: auto;
  font-weight: 600;
  text-transform: uppercase;
}

/* Skeletons de Carga en Slate Shimmer */
.skeleton-card {
  border-radius: var(--radius-md);
  aspect-ratio: 2/3;
  background: linear-gradient(90deg, var(--skeleton-base) 25%, var(--skeleton-sheen) 50%, var(--skeleton-base) 75%);
  background-size: 200% 100%;
  animation: loading-shimmer 1.5s infinite;
  border: 1px solid var(--border-color);
}

@keyframes loading-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Sentinel de Scroll Infinito */
.scroll-sentinel {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 40px 0 50px;
}

.scroll-sentinel.visible {
  display: flex;
}

.scroll-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border-color);
  border-top-color: var(--accent-indigo);
  border-radius: 50%;
  animation: spinner-spin 0.8s linear infinite;
}

.scroll-sentinel p {
  color: var(--text-muted);
  font-size: 0.875rem;
  font-weight: 600;
}

/* ==========================================================================
   PANTALLA DE DETALLE (CLEAN LIGHT BANNER CON PÓSTER)
   ========================================================================== */

.anime-hero {
  position: relative;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  margin-bottom: 48px;
  padding: 48px;
  min-height: 380px;
  display: flex;
  align-items: center;
  box-shadow: var(--shadow-md);
}

.hero-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--gradient-overlay);
  opacity: 0.03; /* Muy suave en light theme */
  z-index: 1;
}

.hero-content {
  position: relative;
  z-index: 2;
  display: flex;
  gap: 40px;
  align-items: center;
  width: 100%;
}

.hero-poster {
  width: 190px;
  height: 285px;
  border-radius: var(--radius-md);
  box-shadow: 0 10px 25px rgba(15, 23, 42, 0.08);
  background-size: cover;
  background-position: center;
  flex-shrink: 0;
  border: 1px solid var(--border-color);
}

.hero-info {
  display: flex;
  flex-direction: column;
  flex: 1;
}

.anime-badge {
  background-color: var(--accent-indigo-light);
  color: var(--accent-indigo);
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 700;
  width: fit-content;
  text-transform: uppercase;
  margin-bottom: 18px;
  letter-spacing: 0.5px;
}

#anime-title {
  font-size: 2.375rem;
  font-weight: 700;
  margin-bottom: 14px;
  line-height: 1.2;
  color: var(--text-main);
  letter-spacing: -0.6px;
}

.anime-genres {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 22px;
}

.genre-tag {
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  padding: 5px 14px;
  border-radius: 20px;
  font-size: 0.8125rem;
  font-weight: 600;
  transition: var(--transition-fast);
}

.genre-tag:hover {
  border-color: var(--accent-indigo);
  color: var(--accent-indigo);
  background-color: var(--bg-secondary);
}

.anime-synopsis {
  font-size: 0.9375rem;
  line-height: 1.65;
  color: var(--text-muted);
  max-width: 800px;
}

/* Grid de Episodios Estilo Minimalist Premium */
.episodes-container h3 {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 24px;
  display: flex;
  align-items: center;
  gap: 10px;
  letter-spacing: -0.5px;
  text-transform: uppercase;
}

.episodes-container h3 i {
  color: var(--accent-indigo);
}

.episodes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 14px;
  margin-bottom: 60px;
}

.episode-btn {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 14px;
  border-radius: var(--radius-md);
  font-size: 0.9375rem;
  font-weight: 700;
  cursor: pointer;
  text-align: center;
  transition: var(--transition-fast);
  box-shadow: var(--shadow-sm);
}

.episode-btn:hover {
  background-color: var(--accent-indigo);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.25);
  transform: translateY(-2px);
}

/* ==========================================================================
   PANTALLA DEL REPRODUCTOR (SALA DE VIDEO CLEAN)
   ========================================================================== */

.player-wrapper {
  max-width: 1040px;
  margin: 0 auto 60px auto;
}

.player-header {
  margin-bottom: 24px;
}

.player-header h2 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 6px;
  letter-spacing: -0.5px;
  text-transform: uppercase;
}

.player-header p {
  color: var(--accent-indigo);
  font-size: 0.875rem;
  font-weight: 700;
}

/* Video Stage */
.video-container {
  position: relative;
  width: 100%;
  padding-top: 56.25%; /* 16:9 aspect ratio */
  background-color: #000;
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-md);
  margin-bottom: 24px;
}

/* Botones de Control del Reproductor (Anterior, Siguiente, Catálogo) */
.player-controls-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 36px;
  width: 100%;
}

.player-control-btn {
  flex: 1;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 14px 20px;
  border-radius: var(--radius-md);
  font-size: 0.9375rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: var(--transition-fast);
  box-shadow: var(--shadow-sm);
}

.player-control-btn i {
  font-size: 0.875rem;
}

.player-control-btn:hover {
  background-color: var(--accent-indigo);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.25);
  transform: translateY(-2px);
}

.player-control-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
  background-color: var(--bg-tertiary);
  color: var(--text-muted);
  border-color: var(--border-color);
  box-shadow: none;
  transform: none;
}

#main-player {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  outline: none;
}

/* Pantalla del Resolutor */
.video-loader {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: var(--bg-secondary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  z-index: 10;
  transition: opacity 0.3s ease;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 3px solid var(--bg-tertiary);
  border-top-color: var(--accent-indigo);
  border-radius: 50%;
  animation: spinner-spin 0.8s linear infinite;
}

@keyframes spinner-spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.video-loader p {
  color: var(--text-main);
  font-size: 0.9375rem;
  font-weight: 600;
  text-align: center;
  max-width: 80%;
  letter-spacing: 0.2px;
}

/* Server Selection (Clean Tech Capsules) */
.server-selection-panel h3 {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 20px;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 8px;
  text-transform: uppercase;
}

.server-selection-panel h3 i {
  color: var(--accent-indigo);
}

.servers-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.server-btn {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  padding: 12px 20px;
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  font-weight: 700;
  cursor: pointer;
  transition: var(--transition-fast);
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: var(--shadow-sm);
}

.server-btn i {
  font-size: 0.875rem;
}

.server-btn:hover {
  background-color: var(--bg-primary);
  color: var(--text-main);
  border-color: var(--border-hover);
}

.server-btn.active {
  background-color: var(--accent-indigo);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 4px 10px rgba(79, 70, 229, 0.2);
}

.server-btn.server-failed {
  opacity: 0.35;
  text-decoration: line-through;
  pointer-events: none;
}

.server-btn.server-trying {
  border-color: var(--accent-indigo);
  animation: server-pulse 1s ease-in-out infinite;
}

@keyframes server-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(79, 70, 229, 0.1); }
  50% { box-shadow: 0 0 12px 2px rgba(79, 70, 229, 0.2); }
}

/* Mobile Header Bar (Only visible on screens <= 992px) */
.mobile-header {
  display: none;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 12px 16px;
  background-color: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 100;
  margin-bottom: 20px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}

.menu-toggle-btn, .mobile-theme-toggle-btn {
  background: none;
  border: none;
  color: var(--text-main);
  font-size: 1.25rem;
  cursor: pointer;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  transition: var(--transition-fast);
}

.menu-toggle-btn:hover, .mobile-theme-toggle-btn:hover {
  background-color: var(--bg-tertiary);
}

.mobile-logo {
  display: flex;
  align-items: center;
  gap: 8px;
}

.mobile-logo .logo-icon {
  font-size: 1.125rem;
  color: var(--accent-indigo);
}

.mobile-logo-text {
  font-size: 1.125rem;
  font-weight: 700;
  letter-spacing: -0.6px;
  margin: 0;
  color: var(--text-main);
  font-family: var(--font-header) !important;
}

.mobile-logo-text span {
  color: var(--accent-blue);
  font-weight: 400;
}

/* Sidebar Overlay (Dark Backdrop) */
.menu-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(4px);
  z-index: 999;
  display: none;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.menu-overlay.active {
  display: block;
  opacity: 1;
}

/* ==========================================================================
   ESTILOS RESPONSIVOS (CELULAR & TABLET — MOBILE FIRST UX)
   ========================================================================== */

/* Ajustes para Tablets y Pantallas Medianas */
@media (max-width: 992px) {
  .app-container {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
  }

  .mobile-header {
    display: flex;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: -280px;
    width: 280px;
    height: 100vh;
    height: 100dvh;
    background-color: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    z-index: 1000;
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    display: flex;
    flex-direction: column;
    padding: 30px 20px;
  }

  .sidebar.open {
    transform: translateX(280px);
  }

  .logo-area {
    margin-bottom: 32px;
  }

  .nav-links {
    flex-direction: column;
    gap: 6px;
    flex: initial;
  }

  .nav-item {
    padding: 12px 16px;
    font-size: 15px;
  }

  .nav-item.active {
    background-color: var(--accent-indigo-light);
  }

  .sidebar-footer {
    display: block;
    margin-top: auto;
  }

  .main-content {
    padding: 16px;
  }

  .top-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    margin-bottom: 20px;
  }

  .genre-filters {
    gap: 8px;
    padding-bottom: 12px;
  }

  .genre-chip {
    padding: 8px 14px;
    font-size: 12px;
  }

  .anime-hero {
    padding: 32px 24px;
    min-height: auto;
  }

  .hero-content {
    flex-direction: column;
    text-align: center;
    gap: 24px;
  }

  .hero-poster {
    width: 150px;
    height: 225px;
  }

  .hero-info {
    align-items: center;
  }

  #anime-title {
    font-size: 1.75rem;
  }

  .anime-synopsis {
    font-size: 0.875rem;
  }
}

/* Optimización Extrema para Dispositivos Móviles (Mobile First) */
@media (max-width: 768px) {
  .main-content {
    padding: 20px 16px;
  }

  /* Desplazamiento Horizontal Suave para Filtros de Género */
  .genre-filters {
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    scroll-behavior: smooth !important;
    padding-bottom: 10px !important;
    border-bottom: none !important;
    -webkit-overflow-scrolling: touch !important;
    margin-bottom: 24px;
    gap: 8px;
  }

  .genre-filters::-webkit-scrollbar {
    display: none !important; /* Oculta barra para mantener look nativo */
  }

  .genre-chip {
    flex-shrink: 0 !important;
    padding: 12px 16px !important;
    font-size: 0.75rem !important;
    min-height: 48px; /* Tap target Lighthouse/WCAG en móvil */
    display: inline-flex;
    align-items: center;
  }

  /* Cuadrícula de 2 Columnas para Móviles (Crunchyroll Style) */
  .cards-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 16px !important;
  }

  .anime-card {
    border-radius: var(--radius-sm) !important;
  }

  .card-content {
    padding: 10px 8px !important;
  }

  .card-title {
    font-size: 0.75rem !important;
    height: 2rem !important;
    margin-bottom: 6px !important;
    font-weight: 700 !important;
  }

  .card-meta {
    font-size: 0.6875rem !important;
  }

  .card-badge {
    top: 8px !important;
    right: 8px !important;
    padding: 3px 6px !important;
    font-size: 0.5rem !important;
    border-radius: 4px !important;
  }

  /* Ajustes en Detalle de Anime */
  .anime-hero {
    padding: 24px 16px !important;
    border-radius: var(--radius-md) !important;
    margin-bottom: 32px;
  }

  .hero-poster {
    width: 120px !important;
    height: 180px !important;
    box-shadow: 0 8px 20px rgba(0,0,0,0.15) !important;
  }

  #anime-title {
    font-size: 1.5rem !important;
    line-height: 1.25 !important;
  }

  .anime-synopsis {
    font-size: 0.8125rem !important;
    line-height: 1.55 !important;
  }

  .episodes-grid {
    grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)) !important;
    gap: 10px !important;
  }

  .episode-btn {
    padding: 12px 10px !important;
    font-size: 0.875rem !important;
    border-radius: 8px !important;
  }

  /* Ajustes del Reproductor de Video en Pantallas Chicas */
  .player-wrapper {
    margin-bottom: 30px;
  }

  .player-header h2 {
    font-size: 1.25rem !important;
  }

  .video-container {
    border-radius: var(--radius-md) !important;
    margin-bottom: 20px !important;
    box-shadow: 0 10px 25px rgba(0,0,0,0.3) !important;
  }

  .player-controls-row {
    gap: 8px !important;
    margin-bottom: 24px !important;
  }

  .player-control-btn {
    padding: 10px 8px !important;
    font-size: 0.8125rem !important;
    border-radius: 8px !important;
    gap: 4px !important;
  }

  .server-btn {
    padding: 12px 16px !important; /* Altura efectiva ampliada a 44px */
    font-size: 0.8125rem !important;
    border-radius: 8px !important;
  }
}

/* Pantallas Extra Pequeñas */
@media (max-width: 480px) {
  .sidebar {
    padding: 14px 16px;
  }

  .logo-area h1 {
    font-size: 1.125rem !important;
  }

  .nav-item {
    padding: 8px 12px;
    font-size: 0.8125rem;
  }

  .nav-item i {
    font-size: 0.875rem;
  }

  .cards-grid {
    gap: 12px !important;
  }

  .card-title {
    font-size: 0.75rem !important;
    height: 2rem !important;
  }
}

/* Accesibilidad de Teclado (Focus Visible) */
button:focus-visible, 
input:focus-visible, 
select:focus-visible,
a:focus-visible,
.anime-card:focus-visible,
.episode-btn:focus-visible,
.server-btn:focus-visible,
.continue-card:focus-visible {
  outline: 3px solid var(--accent-indigo) !important;
  outline-offset: 2px !important;
}

/* Continuar Viendo Section */
.continue-watching-section {
  margin-top: 10px;
  margin-bottom: 36px;
  animation: fadeIn 0.4s ease;
}

.continue-watching-section h3 {
  font-size: 0.9375rem;
  font-weight: 750;
  margin-bottom: 16px;
  color: var(--text-main);
  text-transform: uppercase;
  display: flex;
  align-items: center;
  gap: 8px;
}

.continue-watching-section h3 i {
  color: var(--accent-indigo);
}

.continue-watching-grid {
  display: flex;
  gap: 16px;
  overflow-x: auto;
  padding-bottom: 12px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

.continue-watching-grid::-webkit-scrollbar {
  height: 6px;
}

.continue-watching-grid::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 10px;
}

.continue-card {
  flex-shrink: 0;
  width: 250px;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 10px;
  display: flex;
  gap: 12px;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: var(--transition-fast);
}

.continue-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--accent-indigo);
}

.continue-image-wrapper {
  position: relative;
  width: 60px;
  height: 85px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background-color: var(--bg-tertiary);
  flex-shrink: 0;
}

.continue-image-wrapper img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.continue-play-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(15, 23, 42, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: var(--transition-fast);
}

.continue-card:hover .continue-play-overlay {
  opacity: 1;
}

.continue-play-overlay i {
  color: #fff;
  font-size: 16px;
}

.continue-info {
  display: flex;
  flex-direction: column;
  justify-content: center;
  overflow: hidden;
}

.continue-info h4 {
  font-size: 0.8125rem;
  font-weight: 700;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-main);
}

.continue-info p {
  font-size: 0.6875rem;
  color: var(--accent-indigo);
  font-weight: 600;
  margin: 0;
}

/* Indicador de Episodios Vistos */
.episode-btn.episode-watched {
  border-color: var(--accent-indigo) !important;
  background-color: var(--accent-indigo-light) !important;
  color: var(--accent-indigo) !important;
}

[data-theme="dark"] .episode-btn.episode-watched {
  background-color: rgba(99, 102, 241, 0.15) !important;
  color: #a5b4fc !important;
}

/* Ocultación de Sidebar Cerrado en Móvil para Lectores de Pantalla */
@media (max-width: 992px) {
  .sidebar {
    visibility: hidden;
  }
  .sidebar.open {
    visibility: visible;
  }
}

/* Tarjetas Horizontales (Paisaje) para Episodios Recientes */
.anime-card.episode-card .card-image-wrapper {
  padding-top: 56.25%; /* Relación de aspecto 16:9 */
}

.skeleton-card.episode-card {
  aspect-ratio: 16/9;
}

.cards-grid.episode-grid-layout {
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
}

/* ==========================================================================
   ACCESIBILIDAD: SKIP LINK Y CONTENIDO SOLO PARA LECTORES DE PANTALLA
   ========================================================================== */

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

.skip-link {
  position: absolute;
  top: -100px;
  left: 16px;
  background: var(--accent-indigo);
  color: #fff;
  padding: 12px 20px;
  border-radius: var(--radius-md);
  font-weight: 700;
  font-size: 0.875rem;
  text-decoration: none;
  z-index: 10000;
  transition: top 0.2s ease;
}

.skip-link:focus {
  top: 16px;
}

/* Quitar outline al recibir foco programático en títulos (no es foco de teclado) */
h2[tabindex="-1"]:focus {
  outline: none;
}

/* ==========================================================================
   TOAST DE NOTIFICACIÓN (CLASE EN VEZ DE ESTILOS INLINE)
   ========================================================================== */

.toast-notification {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background-color: rgba(15, 23, 42, 0.9);
  backdrop-filter: blur(8px);
  color: #ffffff;
  padding: 12px 24px;
  border-radius: 30px;
  font-size: 0.875rem;
  font-weight: 600;
  z-index: 999999;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
  opacity: 0;
  transform: translateY(20px);
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  max-width: min(420px, calc(100vw - 48px));
}

.toast-notification.toast-visible {
  opacity: 1;
  transform: translateY(0);
}

[data-theme="dark"] .toast-notification {
  background-color: rgba(99, 102, 241, 0.92);
}

/* ==========================================================================
   CONTINUAR VIENDO: BARRA DE PROGRESO Y BOTÓN ELIMINAR
   ========================================================================== */

.continue-card {
  position: relative;
}

.continue-progress-track {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 4px;
  background-color: var(--bg-tertiary);
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  overflow: hidden;
}

.continue-progress-fill {
  height: 100%;
  background: var(--accent-indigo);
  border-radius: inherit;
  transition: width 0.3s ease;
}

.continue-remove-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: var(--bg-tertiary);
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition-fast);
  z-index: 2;
}
.continue-remove-btn::after {
  content: '';
  position: absolute;
  top: -8px;
  left: -8px;
  right: -8px;
  bottom: -8px; /* Área táctil de 44x44px sin modificar diseño */
}

.continue-remove-btn:hover {
  background: #ef4444;
  color: #fff;
}

/* ==========================================================================
   HERRAMIENTAS DE EPISODIOS (IR A EPISODIO + RANGOS)
   ========================================================================== */

.episodes-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 14px;
  margin-bottom: 24px;
}

.episodes-toolbar h3 {
  margin-bottom: 0 !important;
}

.episodes-tools {
  display: flex;
  align-items: center;
  gap: 10px;
}

.episode-range-select {
  padding: 10px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background-color: var(--bg-secondary);
  color: var(--text-main);
  font-family: var(--font-body);
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
}

.episode-jump {
  display: flex;
  align-items: center;
  gap: 6px;
}

.episode-jump input {
  width: 96px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background-color: var(--bg-secondary);
  color: var(--text-main);
  font-family: var(--font-body);
  font-size: 0.8125rem;
  font-weight: 600;
}

.episode-jump input:focus {
  outline: none;
  border-color: var(--accent-indigo);
}

.episode-jump button {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  border: none;
  background: var(--accent-indigo);
  color: #fff;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition-fast);
}

.episode-jump button:hover {
  background-color: #4338ca;
}

/* ==========================================================================
   REPRODUCTOR: HERRAMIENTAS EXTRA Y AYUDA DE ATAJOS
   ========================================================================== */

.player-tools-row {
  margin-top: -20px; /* Acercar a la fila principal */
}

.player-shortcuts-hint {
  margin-top: 28px;
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: center;
}

.player-shortcuts-hint kbd {
  display: inline-block;
  padding: 2px 7px;
  border: 1px solid var(--border-color);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--bg-secondary);
  font-family: var(--font-header);
  font-size: 0.6875rem;
  color: var(--text-main);
}

@media (max-width: 768px) {
  .player-shortcuts-hint {
    display: none; /* Atajos de teclado no aplican en táctil */
  }
}

/* ==========================================================================
   ESTADOS DE CATÁLOGO (FIN, ERROR, REINTENTO)
   ========================================================================== */

.catalog-end {
  text-align: center;
  padding: 32px 0 48px;
  color: var(--text-muted);
  font-size: 0.875rem;
  font-weight: 600;
}

.catalog-end i {
  color: var(--accent-indigo);
  margin-right: 6px;
}

.retry-btn {
  margin-top: 18px;
  background: var(--accent-indigo);
  color: #fff;
  border: none;
  padding: 12px 26px;
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  font-weight: 700;
  font-family: var(--font-body);
  cursor: pointer;
  transition: var(--transition-fast);
  box-shadow: 0 4px 10px rgba(79, 70, 229, 0.2);
}

.retry-btn:hover {
  background-color: #4338ca;
  transform: translateY(-1px);
}

/* Placeholder de imagen rota / sin imagen */
.card-image-fallback {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--bg-tertiary);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 0.8125rem;
  font-weight: 600;
  text-align: center;
  padding: 12px;
}

/* ==========================================================================
   MOVIMIENTO REDUCIDO (ACCESIBILIDAD VESTIBULAR)
   ========================================================================== */

/* ==========================================================================
   SELECCIÓN DE TEXTO (ACENTO INDIGO TRANSLÚCIDO)
   ========================================================================== */

::selection {
  background: rgba(79, 70, 229, 0.2);
  color: inherit;
}

[data-theme="dark"] ::selection {
  background: rgba(99, 102, 241, 0.3);
}

/* ==========================================================================
   ATMÓSFERA OSCURA (GRADIENTES SUTILES DE FONDO)
   ========================================================================== */

body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  pointer-events: none;
  z-index: -1;
  transition: opacity 0.6s ease;
  opacity: 0;
}

[data-theme="dark"] body::before {
  opacity: 1;
  background:
    radial-gradient(ellipse at 20% 50%, rgba(79, 70, 229, 0.07) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 20%, rgba(14, 165, 233, 0.05) 0%, transparent 50%);
}

/* ==========================================================================
   MOVIMIENTO REDUCIDO (ACCESIBILIDAD VESTIBULAR)
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

