/* ========== RESET & BASE ========== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* ========== TEMAS CON VARIABLES CSS ========== */
body.theme-dark {
  --bg-page: #05070a;
  --bg-glass: rgba(10, 20, 40, 0.75);
  --text-primary: #eef5ff;
  --text-secondary: #b0c4e0;
  --accent: #3cbcff;
  --border: rgba(60, 188, 255, 0.35);
  --shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
  --stars-opacity: 0.6;
  background-color: var(--bg-page);
}

body.theme-light {
  --bg-page: #eef2f8;
  --bg-glass: rgba(240, 245, 255, 0.85);
  --text-primary: #0a1a2a;
  --text-secondary: #2c3e4e;
  --accent: #0077cc;
  --border: rgba(0, 100, 200, 0.3);
  --shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
  --stars-opacity: 0.15;
  background-color: var(--bg-page);
}

body.theme-amoled {
  --bg-page: #000000;
  --bg-glass: rgba(0, 0, 0, 0.92);
  --text-primary: #ffffff;
  --text-secondary: #cccccc;
  --accent: #3cbcff;
  --border: rgba(60, 188, 255, 0.5);
  --shadow: 0 20px 40px rgba(0, 0, 0, 0.8);
  --stars-opacity: 0.2;
  background-color: var(--bg-page);
}

/* Aplicar colores dinámicos */
body {
height: 100vh;
  overflow: hidden;
  font-family: 'Segoe UI', system-ui, 'Inter', sans-serif;
  display: flex;
  flex-direction: column;
  transition: background-color 0.2s ease, color 0.2s ease;
  color: var(--text-primary);
  background-color: var(--bg-page);
}

/* Fondo estelar animado (se adapta al tema) */
.stars-container {
position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: -1;
  transition: background 0.2s ease;
  background: radial-gradient(circle at 30% 10%, var(--bg-page), #030507);
}
.stars-container::before {
  content: "";
  position: absolute;
  width: 200%;
  height: 200%;
  top: -50%;
  left: -50%;
  background-image: radial-gradient(1px 1px at 20% 40%, white, transparent),
                    radial-gradient(1px 1px at 80% 70%, rgba(255,255,255,0.7), transparent),
                    radial-gradient(2px 2px at 10% 90%, var(--accent), transparent);
  background-size: 300px 300px, 200px 200px, 400px 400px;
  background-repeat: no-repeat;
  opacity: var(--stars-opacity);
  animation: drift 180s linear infinite;
}

@keyframes drift {
  from { transform: translate(0,0); }
  to { transform: translate(5%, 3%); }
}

/* ========== HEADER Y FOOTER FIJOS ========== */
.main-header, .main-footer {
  flex-shrink: 0;
  text-align: center;
  padding: 0.8rem;
  background: var(--bg-glass);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}
.main-footer {
  border-top: 1px solid var(--border);
  border-bottom: none;
  font-size: 0.75rem;
}
.main-header h1 {
  font-size: 1.5rem;
  letter-spacing: 2px;
  color: var(--accent);
}
.main-header p {
  font-size: 0.8rem;
  opacity: 0.8;
}

/* ========== CONTROLES (sticky pero dentro del scroll) ========== */
.controls {
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  background: rgba(5, 10, 20, 0.8);
  backdrop-filter: blur(12px);
  padding: 8px 16px;
  border-radius: 50px;
  width: fit-content;
  margin: 10px auto;
  border: 1px solid var(--border);
  z-index: 20;
  position: sticky;
  top: 10px;
}
.controls input, .controls select, .controls button {
  background: rgba(0,0,0,0.6);
  border: 1px solid var(--border);
  color: white;
  padding: 6px 14px;
  border-radius: 30px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
}
.controls button {
  background: var(--accent);
  color: #000;
  font-weight: bold;
  border: none;
}
.controls button:hover {
  transform: scale(0.96);
}

/* ========== CONTENIDO PRINCIPAL (scrollable) ========== */
#app {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  scroll-behavior: smooth;
}

/* Grid de tarjetas */
.wiki-view {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
  max-width: 1300px;
  margin: 0 auto;
}
.wiki-item {
  background: var(--bg-glass);
  backdrop-filter: blur(8px);
  border-radius: 1rem;
  padding: 0.8rem;
  border: 1px solid var(--border);
  transition: transform 0.2s, border-color 0.2s;
  cursor: pointer;
}
.wiki-item:hover {
  transform: translateY(-3px);
  border-color: var(--accent);
}
.wiki-item h3 {
  font-size: 1.1rem;
  color: var(--accent);
}
.wiki-item img {
  width: 100%;
  height: 130px;
  object-fit: cover;
  border-radius: 0.7rem;
  margin: 6px 0;
}
.wiki-item p {
  font-size: 0.8rem;
  line-height: 1.35;
  color: var(--text-secondary);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.wiki-item small {
  font-size: 0.7rem;
  color: var(--accent);
}

/* Vista detalle */
.layout {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 20px;
  background: var(--bg-glass);
  backdrop-filter: blur(12px);
  border-radius: 1.5rem;
  padding: 1.2rem;
  border: 1px solid var(--border);
  max-width: 1200px;
  margin: 0 auto;
}
.layout main h2 {
  font-size: 1.4rem;
  color: var(--accent);
}
.layout main img {
  width: 100%;
  max-height: 280px;
  object-fit: cover;
  border-radius: 1rem;
}
.sidebar {
  background: rgba(0,0,0,0.4);
  border-radius: 1rem;
  padding: 0.8rem;
}
.link {
  padding: 5px 10px;
  margin: 5px 0;
  background: rgba(255,255,255,0.05);
  border-radius: 20px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: background 0.2s, color 0.2s;
}
.link:hover {
  background: var(--accent);
  color: #000;
}
#backToList {
  text-align: center;
  background: rgba(60,188,255,0.2);
}
.section-block {
  background: rgba(0,0,0,0.2);
  border-radius: 0.7rem;
  padding: 0.5rem 0.8rem;
  margin: 8px 0;
  border-left: 2px solid var(--accent);
}
.wikipedia-info {
  margin-top: 15px;
  padding: 10px;
  background: rgba(0,0,0,0.2);
  border-radius: 0.8rem;
}
.wikipedia-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.wikipedia-thumb {
  width: 70px;
  height: 70px;
  object-fit: cover;
  border-radius: 8px;
  background: #000;
}
.loading-spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,0.3);
  border-radius: 50%;
  border-top-color: var(--accent);
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Iconos SVG inline (se usan en el render) */
.icon-wikipedia, .icon-theme {
  width: 18px;
  height: 18px;
  fill: currentColor;
  vertical-align: middle;
}

/* Responsive */
@media (max-width: 750px) {
  .layout { grid-template-columns: 1fr; }
  .wiki-view { grid-template-columns: 1fr; }
  .controls { width: 90%; flex-direction: column; border-radius: 1rem; }
  .main-header h1 { font-size: 1.2rem; }
}