/* ============================================
   Gratis en Internet — Estilos completos
   Stack: CSS3 con variables, Grid, Flexbox
   Mobile-first, responsive, modo oscuro/claro
   ============================================ */

/* --- Reset y base --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  /* Paleta oscura (por defecto) */
  --bg: #0f0f14;
  --surface: #1a1a24;
  --surface-hover: #24243a;
  --primary: #6c5ce7;
  --primary-light: #a29bfe;
  --accent: #00cec9;
  --text: #e8e8ed;
  --text-secondary: #a0a0b0;
  --text-muted: #6c6c80;
  --border: #2a2a3c;
  --shadow: rgba(0, 0, 0, 0.4);
  --card-bg: #1a1a24;
  --badge-bg: #2a2a3c;
  --search-bg: #1a1a24;
  --overlay: rgba(15, 15, 20, 0.95);

  /* Constantes */
  --radius: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --transition: 200ms ease;
  --font: system-ui, -apple-system, 'Segoe UI', sans-serif;
  --max-width: 1200px;
}

/* Tema claro */
[data-theme="light"] {
  --bg: #f8f9fa;
  --surface: #ffffff;
  --surface-hover: #f0f0f5;
  --text: #1a1a2e;
  --text-secondary: #555570;
  --text-muted: #8888a0;
  --border: #e0e0e8;
  --shadow: rgba(0, 0, 0, 0.08);
  --card-bg: #ffffff;
  --badge-bg: #eeeef5;
  --search-bg: #ffffff;
  --overlay: rgba(248, 249, 250, 0.95);
}

html {
  scroll-behavior: smooth;
  scroll-padding-top: 80px;
}

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

a {
  color: var(--accent);
  text-decoration: none;
  transition: color var(--transition);
}

a:hover {
  color: var(--primary-light);
}

a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}

/* --- Skip link accesibilidad --- */
.skip-link {
  position: absolute;
  top: -100%;
  left: 16px;
  background: var(--primary);
  color: #fff;
  padding: 8px 16px;
  border-radius: var(--radius);
  z-index: 10000;
  font-weight: 600;
}

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

/* --- Header --- */
.site-header {
  background: var(--overlay);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  padding: 16px 0;
}

.header-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 16px;
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.site-title {
  font-size: 1.5rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  line-height: 1.2;
}

.site-subtitle {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.counter-badge {
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
}

/* --- Botón toggle tema --- */
.theme-toggle {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px;
  cursor: pointer;
  font-size: 1.2rem;
  line-height: 1;
  color: var(--text);
  transition: background var(--transition), border-color var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
}

.theme-toggle:hover {
  background: var(--surface-hover);
  border-color: var(--primary);
}

.theme-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* --- Barra de búsqueda --- */
.search-container {
  max-width: var(--max-width);
  margin: 12px auto 0;
  padding: 0 16px;
}

.search-wrapper {
  position: relative;
  width: 100%;
}

.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1rem;
  color: var(--text-muted);
  pointer-events: none;
}

.search-input {
  width: 100%;
  padding: 12px 16px 12px 42px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--search-bg);
  color: var(--text);
  font-size: 1rem;
  font-family: var(--font);
  transition: border-color var(--transition), box-shadow var(--transition);
}

.search-input::placeholder {
  color: var(--text-muted);
}

.search-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(108, 92, 231, 0.2);
}

.search-clear {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
  display: none;
}

.search-clear.visible {
  display: block;
}

/* --- Navegación de categorías --- */
.category-nav {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 12px 16px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.category-nav::-webkit-scrollbar {
  height: 4px;
}

.category-nav::-webkit-scrollbar-track {
  background: transparent;
}

.category-nav::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

.category-nav-list {
  display: flex;
  gap: 8px;
  list-style: none;
  padding: 4px 0;
}

.category-nav-item {
  flex-shrink: 0;
}

.category-nav-link {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--surface);
  border: 1px solid var(--border);
  white-space: nowrap;
  transition: all var(--transition);
  cursor: pointer;
  text-decoration: none;
}

.category-nav-link:hover {
  background: var(--surface-hover);
  color: var(--text);
  border-color: var(--primary);
}

.category-nav-link.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.category-nav-link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* --- Slot de anuncios --- */
.ad-slot {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 50px;
  background: transparent;
  border-radius: var(--radius);
  overflow: hidden;
}

.ad-slot--header {
  max-width: var(--max-width);
  margin: 8px auto;
  padding: 0 16px;
}

.ad-slot--in-content {
  max-width: var(--max-width);
  margin: 24px auto;
  padding: 0 16px;
}

.ad-slot--footer {
  max-width: var(--max-width);
  margin: 16px auto;
  padding: 0 16px;
}

/* --- Contenido principal --- */
.main-content {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 24px 16px 48px;
}

/* --- Secciones de categoría --- */
.category-section {
  margin-bottom: 48px;
}

.category-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.category-emoji {
  font-size: 1.8rem;
  line-height: 1;
}

.category-title {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text);
}

.category-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--primary);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 2px 10px;
  border-radius: 20px;
  min-width: 28px;
}

/* --- Grid de tarjetas --- */
.resources-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

/* --- Tarjeta de recurso --- */
.resource-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
  position: relative;
  /* Animación de entrada */
  opacity: 0;
  transform: translateY(20px);
}

.resource-card.visible {
  opacity: 1;
  transform: translateY(0);
  transition: opacity 0.4s ease, transform 0.4s ease, box-shadow var(--transition), border-color var(--transition);
}

.resource-card:hover {
  border-color: var(--primary);
  box-shadow: 0 4px 20px var(--shadow);
  transform: translateY(-2px);
}

.resource-card.visible:hover {
  transform: translateY(-2px);
}

.resource-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.resource-name {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  line-height: 1.3;
}

.resource-name:hover {
  color: var(--primary-light);
}

.resource-featured {
  font-size: 1rem;
  flex-shrink: 0;
}

.resource-desc {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 12px;
  line-height: 1.5;
}

.resource-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

/* Badges de idioma */
.badge--lang {
  background: var(--badge-bg);
  color: var(--text-secondary);
}

.badge--lang-es { background: #ffeaa7; color: #2d3436; }
.badge--lang-en { background: #74b9ff; color: #2d3436; }
.badge--lang-pt { background: #55efc4; color: #2d3436; }
.badge--lang-fr { background: #fd79a8; color: #fff; }
.badge--lang-de { background: #fab1a0; color: #2d3436; }
.badge--lang-it { background: #a29bfe; color: #fff; }
.badge--lang-multi { background: linear-gradient(135deg, var(--primary), var(--accent)); color: #fff; }

/* Badges de tipo de acceso */
.badge--access {
  background: var(--badge-bg);
  color: var(--text-muted);
}

.badge--gratis { background: #00b89422; color: #00b894; border: 1px solid #00b89444; }
.badge--freemium { background: #fdcb6e22; color: #fdcb6e; border: 1px solid #fdcb6e44; }
.badge--open-source { background: #6c5ce722; color: var(--primary-light); border: 1px solid #6c5ce744; }

.resource-notes {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 8px;
  font-style: italic;
}

/* Resaltado de búsqueda */
.search-highlight {
  background: rgba(108, 92, 231, 0.3);
  border-radius: 2px;
  padding: 0 2px;
}

/* --- Estado vacío --- */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}

.empty-state-icon {
  font-size: 3rem;
  margin-bottom: 12px;
}

.empty-state-text {
  font-size: 1rem;
}

/* --- Estado de error --- */
.error-state {
  text-align: center;
  padding: 80px 24px;
  color: var(--text-muted);
}

.error-state-icon {
  font-size: 4rem;
  margin-bottom: 16px;
}

.error-state-title {
  font-size: 1.3rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
}

.error-state-text {
  font-size: 0.95rem;
}

/* --- Resultados de búsqueda vacíos --- */
.no-results {
  text-align: center;
  padding: 60px 24px;
  color: var(--text-muted);
  display: none;
}

.no-results.visible {
  display: block;
}

.no-results-icon {
  font-size: 3rem;
  margin-bottom: 12px;
}

.no-results-text {
  font-size: 1.1rem;
  color: var(--text-secondary);
}

/* --- Botón scroll to top --- */
.scroll-top {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  border: none;
  cursor: pointer;
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(108, 92, 231, 0.4);
  opacity: 0;
  transform: translateY(20px);
  transition: opacity var(--transition), transform var(--transition), background var(--transition);
  z-index: 90;
  pointer-events: none;
}

.scroll-top.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.scroll-top:hover {
  background: var(--primary-light);
}

.scroll-top:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* --- Footer --- */
.site-footer {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 32px 16px;
  text-align: center;
}

.footer-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
}

.footer-update {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.footer-suggest {
  font-size: 0.9rem;
}

.footer-disclaimer {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.footer-legal {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: center;
  font-size: 0.85rem;
}

.footer-legal a {
  color: var(--text-secondary);
}

.footer-legal a:hover {
  color: var(--accent);
}

.footer-copyright {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.cookie-settings-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 0.85rem;
  font-family: var(--font);
  padding: 0;
  text-decoration: underline;
  text-decoration-style: dotted;
}

.cookie-settings-btn:hover {
  color: var(--accent);
}

/* --- Banner de cookies --- */
.cookie-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 20px 16px;
  z-index: 1000;
  box-shadow: 0 -4px 24px var(--shadow);
  transform: translateY(100%);
  transition: transform 0.3s ease;
}

.cookie-banner.visible {
  transform: translateY(0);
}

.cookie-banner-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.cookie-banner-text {
  font-size: 0.9rem;
  color: var(--text-secondary);
  flex: 1;
  min-width: 200px;
}

.cookie-banner-text a {
  color: var(--accent);
  text-decoration: underline;
}

.cookie-banner-actions {
  display: flex;
  gap: 10px;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.btn {
  padding: 10px 20px;
  border-radius: var(--radius);
  font-size: 0.85rem;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  border: 1px solid transparent;
  transition: all var(--transition);
}

.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn--primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.btn--primary:hover {
  background: var(--primary-light);
  border-color: var(--primary-light);
}

.btn--secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}

.btn--secondary:hover {
  background: var(--surface-hover);
  border-color: var(--primary);
}

/* --- Loader --- */
.loader {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 80px 24px;
  flex-direction: column;
  gap: 16px;
}

.loader-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

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

/* --- Páginas legales --- */
.legal-page {
  max-width: 800px;
  margin: 0 auto;
  padding: 40px 16px 60px;
}

.legal-page h1 {
  font-size: 1.8rem;
  font-weight: 800;
  margin-bottom: 8px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.legal-page .legal-date {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 32px;
}

.legal-page h2 {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text);
  margin-top: 32px;
  margin-bottom: 12px;
}

.legal-page h3 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
  margin-top: 24px;
  margin-bottom: 8px;
}

.legal-page p {
  margin-bottom: 12px;
  color: var(--text-secondary);
  line-height: 1.7;
}

.legal-page ul, .legal-page ol {
  margin-bottom: 12px;
  padding-left: 24px;
  color: var(--text-secondary);
}

.legal-page li {
  margin-bottom: 6px;
  line-height: 1.6;
}

.legal-page table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
  font-size: 0.85rem;
}

.legal-page th,
.legal-page td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
}

.legal-page th {
  font-weight: 600;
  color: var(--text);
  background: var(--surface);
}

.legal-page .placeholder {
  background: #fdcb6e22;
  color: #fdcb6e;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 600;
  font-size: 0.85rem;
}

.legal-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 24px;
  font-size: 0.9rem;
  color: var(--accent);
}

.legal-back:hover {
  color: var(--primary-light);
}

/* --- Responsive --- */

/* 480px+ */
@media (min-width: 480px) {
  .resources-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .site-title {
    font-size: 1.7rem;
  }
}

/* 768px+ */
@media (min-width: 768px) {
  .resources-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .site-title {
    font-size: 1.9rem;
  }

  .site-subtitle {
    font-size: 0.9rem;
  }

  .search-input {
    font-size: 1.05rem;
    padding: 14px 16px 14px 46px;
  }

  .category-section {
    margin-bottom: 56px;
  }

  .main-content {
    padding: 32px 24px 60px;
  }
}

/* 1024px+ */
@media (min-width: 1024px) {
  .resources-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .site-title {
    font-size: 2rem;
  }

  .header-inner {
    padding: 0 24px;
  }

  .search-container {
    padding: 0 24px;
  }

  .category-nav {
    padding: 12px 24px;
  }
}

/* 1200px+ */
@media (min-width: 1200px) {
  .resources-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* Prefiere modo oscuro del sistema */
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    --bg: #f8f9fa;
    --surface: #ffffff;
    --surface-hover: #f0f0f5;
    --text: #1a1a2e;
    --text-secondary: #555570;
    --text-muted: #8888a0;
    --border: #e0e0e8;
    --shadow: rgba(0, 0, 0, 0.08);
    --card-bg: #ffffff;
    --badge-bg: #eeeef5;
    --search-bg: #ffffff;
    --overlay: rgba(248, 249, 250, 0.95);
  }
}

/* Reducir animaciones si el usuario lo prefiere */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }

  html {
    scroll-behavior: auto;
  }

  .resource-card {
    opacity: 1;
    transform: none;
  }
}

/* Focus visible para accesibilidad */
:focus:not(:focus-visible) {
  outline: none;
}
