/* ---- Dark theme (default) ---- */
:root, [data-theme="dark"] {
  --bg: #050505;
  --surface: #0c0c0c;
  --surface2: #111113;
  --border: #1a1a1e;
  --border-hi: #2a2a30;
  --text: #c8c8d0;
  --text-dim: #5a5a66;
  --text-muted: #3a3a44;
  --accent: #f97316;
  --accent-glow: rgba(249, 115, 22, 0.15);
  --accent2: #ea580c;
  --accent2-glow: rgba(234, 88, 12, 0.12);
  --green: #22c55e;
  --font: 'Space Grotesk', -apple-system, sans-serif;
  --mono: 'JetBrains Mono', monospace;
  --logo-color: #fff;
  --hero-bg: linear-gradient(135deg, #1a0f05 0%, #120a03 40%, var(--surface) 100%);
  --hero-border: #4a2a10;
  --hero-line: linear-gradient(90deg, #f97316, #fb923c 40%, transparent 80%);
  --feat-bg: linear-gradient(135deg, #140d05 0%, #100a03 40%, var(--surface) 100%);
  --feat-border: #3d2510;
  --feat-line: linear-gradient(90deg, #ea580c, transparent);
  --compact-border: #151518;
  --source-tag-bg: #141418;
  --card-shadow: rgba(0,0,0,0.5);
  --pill-active-text: #fff;
  --noise-opacity: 0.025;
}

/* ---- Light theme (white + orange) ---- */
[data-theme="light"] {
  --bg: #fafafa;
  --surface: #ffffff;
  --surface2: #f5f5f5;
  --border: #e5e5e5;
  --border-hi: #d0d0d0;
  --text: #1a1a1a;
  --text-dim: #666666;
  --text-muted: #999999;
  --accent: #f97316;
  --accent-glow: rgba(249, 115, 22, 0.15);
  --accent2: #ea580c;
  --accent2-glow: rgba(234, 88, 12, 0.12);
  --green: #16a34a;
  --logo-color: #1a1a1a;
  --hero-bg: linear-gradient(135deg, #fff7ed 0%, #ffedd5 40%, var(--surface) 100%);
  --hero-border: #fdba74;
  --hero-line: linear-gradient(90deg, #f97316, #fb923c 40%, transparent 80%);
  --feat-bg: linear-gradient(135deg, #fff7ed 0%, #fef3c7 40%, var(--surface) 100%);
  --feat-border: #fcd34d;
  --feat-line: linear-gradient(90deg, #ea580c, transparent);
  --compact-border: #e5e5e5;
  --source-tag-bg: #f5f5f5;
  --card-shadow: rgba(0,0,0,0.08);
  --pill-active-text: #fff;
  --noise-opacity: 0.015;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.4;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  opacity: var(--noise-opacity);
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 9999;
}

.wrapper {
  width: 100%;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 0.6rem;
  gap: 0.5rem;
}

/* ---- Top bar: logo + filters inline ---- */
.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-shrink: 0;
  padding: 0 0.3rem;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
  cursor: pointer;
}

.logo:hover h1 { opacity: 0.8; }

h1 {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--logo-color);
  letter-spacing: -0.04em;
  line-height: 1;
  transition: opacity 0.2s;
}

h1 .accent { color: #f97316; }

.logo-dot {
  width: 6px;
  height: 6px;
  background: var(--accent);
  border-radius: 50%;
  box-shadow: 0 0 10px var(--accent);
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.85); }
}

.live-indicator {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-family: var(--mono);
  font-size: 0.6rem;
  color: var(--text-muted);
}

.live-indicator .dot {
  width: 5px;
  height: 5px;
  background: var(--green);
  border-radius: 50%;
  box-shadow: 0 0 6px rgba(34, 197, 94, 0.5);
  animation: pulse 2s ease-in-out infinite;
}

.topbar-meta {
  font-family: var(--mono);
  font-size: 0.6rem;
  color: var(--text-muted);
}

.topbar-meta strong { color: var(--text-dim); }

.filters { display: flex; gap: 0.25rem; flex-wrap: wrap; }

.pill {
  font-family: var(--mono);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 0.2rem 0.55rem;
  border-radius: 20px;
  cursor: pointer;
  font-size: 0.6rem;
  transition: all 0.2s;
}

.pill:hover { border-color: var(--border-hi); color: var(--text); background: var(--surface2); }
.pill.active { background: var(--accent); border-color: var(--accent); color: var(--pill-active-text); font-weight: 500; }

.sort-pills { display: flex; gap: 0.25rem; margin-left: auto; flex-shrink: 0; }

.theme-toggle {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-dim);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  transition: all 0.2s;
  flex-shrink: 0;
  padding: 0;
  line-height: 1;
}

.theme-toggle:hover {
  border-color: var(--border-hi);
  color: var(--text);
  background: var(--surface2);
}

.about-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-dim);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
  font-family: var(--mono);
  transition: all 0.2s;
  flex-shrink: 0;
  padding: 0;
  line-height: 1;
}

.about-btn:hover {
  border-color: var(--border-hi);
  color: var(--text);
  background: var(--surface2);
}

.about-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  z-index: 10000;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.about-overlay.active { display: flex; }

.about-modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2rem 2.5rem;
  max-width: 640px;
  width: 100%;
  position: relative;
  max-height: 90vh;
  overflow-y: auto;
}

.about-modal h2 {
  font-size: 1.6rem;
  color: var(--text);
  margin-bottom: 1.2rem;
  letter-spacing: -0.04em;
}

.about-modal p {
  color: var(--text-dim);
  font-size: 0.85rem;
  line-height: 1.6;
  margin-bottom: 0.8rem;
}

.about-modal strong { color: var(--text); }

.about-diagram {
  width: 100%;
  border-radius: 8px;
  border: 1px solid var(--border);
  margin: 1rem 0;
}

.about-links {
  display: flex;
  gap: 1rem;
  margin-top: 1.2rem;
}

.about-links a {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--accent);
  text-decoration: none;
  padding: 0.3rem 0.7rem;
  border: 1px solid var(--accent);
  border-radius: 6px;
  transition: all 0.2s;
}

.about-links a:hover {
  background: var(--accent);
  color: #fff;
}

.about-close {
  position: absolute;
  top: 0.8rem;
  right: 1rem;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
  transition: color 0.2s;
}

.about-close:hover { color: var(--text); }

.country-select {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.25rem 0.4rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.95rem;
  transition: all 0.2s;
  flex-shrink: 0;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23666'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.4rem center;
  padding-right: 1.4rem;
}

.country-select:hover {
  border-color: var(--border-hi);
  background-color: var(--surface2);
}

.country-select:focus {
  border-color: var(--accent);
}

.sort-pill {
  font-family: var(--mono);
  background: none;
  border: 1px solid transparent;
  color: var(--text-muted);
  padding: 0.2rem 0.5rem;
  border-radius: 20px;
  cursor: pointer;
  font-size: 0.6rem;
  transition: all 0.2s;
}

.sort-pill:hover { color: var(--text-dim); }
.sort-pill.active { border-color: var(--border-hi); color: var(--text); }

/* ---- Collage Board ---- */
#content {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  scroll-behavior: smooth;
}

#content::-webkit-scrollbar { width: 4px; }
#content::-webkit-scrollbar-track { background: transparent; }
#content::-webkit-scrollbar-thumb { background: var(--border-hi); border-radius: 4px; }

.board {
  display: grid;
  gap: 5px;
  width: 100%;
  min-height: 100%;
  grid-template-columns: repeat(12, 1fr);
  grid-auto-rows: 1fr;
}

.board-extra {
  display: grid;
  gap: 5px;
  width: 100%;
  padding-top: 5px;
}

.board-extra--desktop { grid-template-columns: repeat(4, 1fr); }
.board-extra--tablet  { grid-template-columns: repeat(3, 1fr); }
.board-extra--mobile  { grid-template-columns: 1fr; }

.board-extra > div {
  min-width: 0;
}

.board-extra .span-2 { grid-column: span 2; }

.board-extra .card {
  height: 100%;
}

.load-more-sentinel {
  height: 1px;
}

/* ---- Cards ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.7rem 0.9rem;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--border-hi), transparent);
  opacity: 0;
  transition: opacity 0.3s;
}

.card:hover {
  border-color: var(--border-hi);
  transform: scale(1.01);
  box-shadow: 0 8px 30px var(--card-shadow);
  z-index: 10;
}

.card:hover::before { opacity: 1; }

/* -- Hero card -- */
.card.hero {
  padding: 1.2rem 1.8rem;
  background: var(--hero-bg);
  border-color: var(--hero-border);
}

.card.hero::after {
  content: '';
  position: absolute;
  top: -1px; left: 0; right: 0;
  height: 3px;
  background: var(--hero-line);
}

/* -- Feature card -- */
.card.feature {
  padding: 0.9rem 1.2rem;
  background: var(--feat-bg);
  border-color: var(--feat-border);
}

.card.feature::after {
  content: '';
  position: absolute;
  top: -1px; left: 0;
  width: 50%;
  height: 2px;
  background: var(--feat-line);
}

/* -- Compact card -- */
.card.compact {
  border-color: var(--compact-border);
}

/* ---- Card elements ---- */
.card-title {
  color: var(--text);
  text-decoration: none;
  display: block;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.3;
  word-break: break-word;
}

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

.card-footer {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
  margin-top: auto;
  padding-top: 0.4rem;
}

.source-tag {
  font-family: var(--mono);
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  background: var(--source-tag-bg);
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  font-size: 0.6rem;
  color: var(--text-dim);
  border: 1px solid var(--border);
}

.source-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
}

/* Chile sources */
.source-dot.biobio { background: #e63946; box-shadow: 0 0 4px rgba(230,57,70,0.4); }
.source-dot.coop { background: #2196f3; box-shadow: 0 0 4px rgba(33,150,243,0.4); }
.source-dot.tercera { background: #ff9800; box-shadow: 0 0 4px rgba(255,152,0,0.4); }
.source-dot.ciper { background: #4caf50; box-shadow: 0 0 4px rgba(76,175,80,0.4); }
.source-dot.clinic { background: #9c27b0; box-shadow: 0 0 4px rgba(156,39,176,0.4); }
.source-dot.interf { background: #00bcd4; box-shadow: 0 0 4px rgba(0,188,212,0.4); }
.source-dot.descon { background: #ff5722; box-shadow: 0 0 4px rgba(255,87,34,0.4); }
.source-dot.t13 { background: #0d47a1; box-shadow: 0 0 4px rgba(13,71,161,0.4); }
.source-dot.cnncl { background: #c62828; box-shadow: 0 0 4px rgba(198,40,40,0.4); }
.source-dot.chv { background: #1565c0; box-shadow: 0 0 4px rgba(21,101,192,0.4); }
.source-dot.mega { background: #f57f17; box-shadow: 0 0 4px rgba(245,127,23,0.4); }
.source-dot.default { background: var(--text-muted); }

/* Ecuador sources */
.source-dot.comercio { background: #1a5276; box-shadow: 0 0 4px rgba(26,82,118,0.4); }
.source-dot.universo { background: #e74c3c; box-shadow: 0 0 4px rgba(231,76,60,0.4); }
.source-dot.metro { background: #2ecc71; box-shadow: 0 0 4px rgba(46,204,113,0.4); }
.source-dot.gk { background: #f39c12; box-shadow: 0 0 4px rgba(243,156,18,0.4); }
.source-dot.barra { background: #8e44ad; box-shadow: 0 0 4px rgba(142,68,173,0.4); }
.source-dot.planv { background: #e67e22; box-shadow: 0 0 4px rgba(230,126,34,0.4); }
.source-dot.confirm { background: #3498db; box-shadow: 0 0 4px rgba(52,152,219,0.4); }
.source-dot.ecuavisa { background: #d32f2f; box-shadow: 0 0 4px rgba(211,47,47,0.4); }
.source-dot.teleamaz { background: #1976d2; box-shadow: 0 0 4px rgba(25,118,210,0.4); }

.card-time {
  font-family: var(--mono);
  font-size: 0.6rem;
  color: var(--text-muted);
}

/* ---- Badges ---- */
.badge {
  font-family: var(--mono);
  display: inline-block;
  font-size: 0.55rem;
  font-weight: 700;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.3rem;
  width: fit-content;
}

.badge-hot {
  background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 80%, #000));
  color: #fff;
  box-shadow: 0 2px 12px var(--accent-glow);
  animation: badge-glow 2s ease-in-out infinite alternate;
}

@keyframes badge-glow {
  from { box-shadow: 0 2px 12px var(--accent-glow); }
  to { box-shadow: 0 2px 20px var(--accent-glow); }
}

.badge-multi {
  background: linear-gradient(135deg, var(--accent2), color-mix(in srgb, var(--accent2) 80%, #000));
  color: #fff;
  box-shadow: 0 2px 12px var(--accent2-glow);
}

.cluster-sources {
  display: flex;
  gap: 0.25rem;
  flex-wrap: wrap;
  margin-top: 0.3rem;
}

.cluster-sources .source-tag {
  opacity: 0.7;
  font-size: 0.55rem;
  padding: 0.1rem 0.35rem;
}

/* ---- States ---- */
.loading, .empty {
  text-align: center;
  padding: 3rem 2rem;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.loading::after {
  content: '';
  display: block;
  width: 24px;
  height: 24px;
  margin: 1rem auto 0;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ---- Video icon ---- */
.video-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 20px;
  background: #ff0000;
  color: #fff;
  border-radius: 6px;
  font-size: 11px;
  margin-right: 0.5em;
  vertical-align: middle;
  flex-shrink: 0;
  box-shadow: 0 0 8px rgba(255,0,0,0.4);
}

.card-video { cursor: pointer; }

/* ---- Video modal ---- */
.video-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.video-modal {
  position: relative;
  width: 100%;
  max-width: 900px;
  aspect-ratio: 16/9;
  background: #000;
  border-radius: 12px;
  overflow: hidden;
}

.video-modal iframe {
  width: 100%;
  height: 100%;
}

.video-modal-close {
  position: absolute;
  top: -36px;
  right: 0;
  background: none;
  border: none;
  color: #fff;
  font-size: 2rem;
  cursor: pointer;
  z-index: 1;
  line-height: 1;
  opacity: 0.7;
  transition: opacity 0.2s;
}

.video-modal-close:hover { opacity: 1; }

/* ---- Responsive ---- */
@media (max-width: 1100px) {
  .board {
    grid-template-columns: repeat(6, 1fr);
  }
  .card { max-width: 100%; }
}

@media (max-width: 768px) {
  html, body { overflow: auto; height: auto; }
  .wrapper { height: auto; overflow-y: auto; }
  #content { overflow: visible; }
  .board {
    grid-template-columns: 1fr;
    height: auto;
    min-height: auto;
    grid-auto-rows: auto;
    gap: 8px;
  }
  .board-extra {
    gap: 8px;
  }
  .topbar {
    flex-wrap: wrap;
    gap: 0.5rem;
  }
  .filters { order: 10; width: 100%; }
  .sort-pills { order: 5; }
  .card { padding: 0.8rem 1rem; }
  .card.hero { padding: 1.2rem 1rem; }
  .card.feature { padding: 0.9rem 1rem; }
  .card-title { line-height: 1.4; }
}

@media (max-width: 520px) {
  .board {
    grid-template-columns: 1fr;
    grid-auto-rows: auto;
  }
  .sort-pills { margin-left: 0; }
}
