/* ---- 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: #ff3333;
  --accent-glow: rgba(255, 51, 51, 0.15);
  --accent2: #6e56ff;
  --accent2-glow: rgba(110, 86, 255, 0.12);
  --green: #22c55e;
  --font: 'Space Grotesk', -apple-system, sans-serif;
  --mono: 'JetBrains Mono', monospace;
  --logo-color: #fff;
  --hero-bg: linear-gradient(135deg, #180808 0%, #100606 40%, var(--surface) 100%);
  --hero-border: #441111;
  --hero-line: linear-gradient(90deg, var(--accent), #ff6644 40%, transparent 80%);
  --feat-bg: linear-gradient(135deg, #0a0a18 0%, #080816 40%, var(--surface) 100%);
  --feat-border: #222244;
  --feat-line: linear-gradient(90deg, var(--accent2), 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%; overflow: hidden; }

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: var(--accent); }

.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);
}

.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: hidden;
}

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

/* ---- 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;
}

.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.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); }

.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); } }

/* ---- 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: repeat(4, 1fr);
    height: auto;
    grid-auto-rows: auto;
  }
  .topbar {
    flex-wrap: wrap;
    gap: 0.5rem;
  }
  .filters { order: 10; width: 100%; }
  .sort-pills { order: 5; }
  .card.hero { padding: 1rem 1.2rem; }
  .card.feature { padding: 0.7rem 0.9rem; }
}

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