/* Variables para modo Oscuro (Predeterminado) */
:root {
  --bg-color: #0f172a;
  --header-bg: #1e293b;
  --card-bg: #1e293b;
  --accent-color: #6366f1;
  --accent-hover: #4f46e5;
  --text-color: #f8fafc;
  --text-muted: #94a3b8;
  --border-color: #334155;
  --input-bg: #0f172a;
  --shadow-color: rgba(0, 0, 0, 0.4);
}

/* Variables para modo Claro */
[data-theme="light"] {
  --bg-color: #f1f5f9;
  --header-bg: #ffffff;
  --card-bg: #ffffff;
  --accent-color: #4f46e5;
  --accent-hover: #4338ca;
  --text-color: #0f172a;
  --text-muted: #64748b;
  --border-color: #cbd5e1;
  --input-bg: #f8fafc;
  --shadow-color: rgba(0, 0, 0, 0.08);
}

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  max-width: 100vw;
  overflow-x: hidden;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-color);
}

/* ==========================================
   DISEÑO BASE (ESCRITORIO / PC)
   ========================================== */

header {
  background: var(--header-bg);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 10px var(--shadow-color);
  width: 100%;
}

.header-container {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.8rem 1.5rem;
  width: 100%;
}

.logo { 
  font-size: 1.6rem; 
  font-weight: 800; 
  letter-spacing: -0.5px;
}
.logo span { color: var(--accent-color); }

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.8rem;
}

.small-select {
  padding: 0.4rem 0.6rem;
  font-size: 0.85rem;
}

.btn-theme {
  background: transparent;
  border: 1px solid var(--border-color);
  font-size: 1.2rem;
  padding: 0.35rem 0.6rem;
  cursor: pointer;
  border-radius: 8px;
}

#auth-container {
  display: flex;
  align-items: center;
}

#user-profile {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

#user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

#user-name {
  font-size: 0.85rem;
  font-weight: 600;
  max-width: 150px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Visibilidad de texto e icono en PC */
.desktop-text {
  display: inline !important;
}

.mobile-icon {
  display: none !important;
}

/* Principal */
.main-content {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1.5rem;
  width: 100%;
}

.controls-section {
  display: flex;
  gap: 0.8rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  justify-content: center;
}

input, select, button, textarea {
  padding: 0.65rem 1rem;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  background-color: var(--input-bg);
  color: var(--text-color);
  outline: none;
  font-size: 0.95rem;
  font-family: inherit;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--accent-color);
}

.btn-primary { 
  background-color: var(--accent-color); 
  color: white; 
  border: none; 
  cursor: pointer; 
  font-weight: 600;
  white-space: nowrap;
}
.btn-primary:hover { background-color: var(--accent-hover); }

.btn-secondary { 
  background-color: #ef4444; 
  color: white; 
  border: none; 
  cursor: pointer; 
  white-space: nowrap;
}

/* Grid PC (6 columnas) */
.grid-container {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0.8rem;
  width: 100%;
}

.anime-card {
  background-color: var(--card-bg);
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  position: relative;
  transition: transform 0.2s, box-shadow 0.2s;
  border: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  width: 100%;
}

.anime-card img { 
  width: 100%; 
  height: 220px; 
  object-fit: cover; 
}

.anime-card-info { 
  padding: 0.8rem; 
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.anime-card-title { 
  font-weight: 700; 
  font-size: 0.95rem; 
  margin-bottom: 0.4rem; 
  white-space: nowrap; 
  overflow: hidden; 
  text-overflow: ellipsis; 
}

.fav-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  background: rgba(0, 0, 0, 0.6);
  border: none;
  font-size: 1.1rem;
  cursor: pointer;
  border-radius: 50%;
  padding: 6px;
  backdrop-filter: blur(4px);
}

.progress-bar-container {
  width: 100%;
  background-color: var(--border-color);
  border-radius: 6px;
  height: 8px;
  overflow: hidden;
  margin-top: 8px;
}

.progress-bar-fill {
  height: 100%;
  background-color: var(--accent-color);
  width: 0%;
}

/* Modal */
.modal {
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 200;
  backdrop-filter: blur(4px);
}

.hidden { display: none !important; }

.modal-content {
  background: var(--card-bg);
  padding: 2rem;
  border-radius: 16px;
  max-width: 650px;
  width: 90%;
  max-height: 85vh;
  overflow-y: auto;
  position: relative;
  border: 1px solid var(--border-color);
}

.close-modal { 
  position: absolute; 
  top: 1rem; 
  right: 1.5rem; 
  font-size: 1.8rem; 
  cursor: pointer; 
  color: var(--text-muted);
}


/* =========================================================
   REGLAS PARA MÓVIL Y ORIENTACIÓN VERTICAL (PORTRAIT)
   ========================================================= */

@media screen and (max-width: 900px), screen and (orientation: portrait) {
  .header-container {
    padding: 0.4rem 0.5rem !important;
    gap: 0.2rem !important;
  }

  .logo {
    font-size: 1.1rem !important;
  }

  .header-actions {
    gap: 0.3rem !important;
  }

  /* Ocultar nombre y texto de botones en vertical */
  #user-name {
    display: none !important;
  }

  .desktop-text {
    display: none !important;
  }

  .mobile-icon {
    display: inline-block !important;
    font-size: 1.1rem !important;
  }

  .btn-primary, .btn-secondary {
    padding: 0.4rem 0.5rem !important;
    border-radius: 8px !important;
    min-width: auto !important;
  }

  #user-avatar {
    width: 28px !important;
    height: 28px !important;
  }

  .small-select {
    padding: 0.3rem !important;
    font-size: 0.75rem !important;
    max-width: 55px !important;
  }

  .btn-theme {
    padding: 0.3rem 0.4rem !important;
    font-size: 0.9rem !important;
  }

  .main-content {
    padding: 0.4rem !important;
  }

  .controls-section {
    flex-direction: column !important;
    gap: 0.4rem !important;
    width: 100% !important;
  }

  .controls-section input,
  .controls-section select {
    width: 100% !important;
    padding: 0.45rem !important;
    font-size: 0.85rem !important;
  }

  /* FORZAR 2 COLUMNAS PERFECTAS EN VERTICAL */
  .grid-container {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 0.5rem !important;
    width: 100% !important;
  }

  .anime-card img {
    height: 150px !important;
  }

  .anime-card-title {
    font-size: 0.78rem !important;
  }

  .anime-card-info {
    padding: 0.4rem !important;
  }
}