:root {
  --bg: #0b1120;
  --surface: #111827;
  --surface-2: #1e293b;
  --border: #263248;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --red: #f87171;
  --yellow: #fbbf24;
  --green: #34d399;
}

[data-theme="light"] {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --border: #cbd5e1;
  --text: #0f172a;
  --muted: #475569;
  --accent: #0284c7;
  --red: #dc2626;
  --yellow: #d97706;
  --green: #059669;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Noto Sans TC", "Microsoft JhengHei", system-ui, -apple-system, sans-serif;
  font-size: 16px;
  line-height: 1.6;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.brand-badge {
  background: linear-gradient(135deg, #0ea5e9, #6366f1);
  color: #fff;
  font-weight: 700;
  padding: 0.35rem 0.75rem;
  border-radius: 0.5rem;
  letter-spacing: 0.03em;
  font-size: 0.95rem;
}

.brand h1 {
  margin: 0;
  font-size: 1.2rem;
}

.subtitle {
  margin: 0.15rem 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.top-actions {
  display: flex;
  gap: 0.6rem;
  align-items: center;
}

.chip-link, .chip-btn {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.45rem 0.85rem;
  border-radius: 0.5rem;
  font-size: 0.875rem;
  text-decoration: none;
  cursor: pointer;
}

.chip-link:hover, .chip-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.container {
  width: 100%;
  padding: 1.25rem 1.5rem 2.5rem;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.85rem;
  margin-bottom: 1.25rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 0.85rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.stat-label {
  color: var(--muted);
  font-size: 0.85rem;
}

.stat-card strong {
  font-size: 1.45rem;
}

.accent-red strong { color: var(--red); }
.accent-yellow strong { color: var(--yellow); }

.controls {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  margin-bottom: 1rem;
}

.control-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  justify-content: space-between;
}

.pill-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.pill {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.4rem 0.9rem;
  font-size: 0.875rem;
  cursor: pointer;
}

.pill.active {
  background: var(--accent);
  color: #0b1120;
  border-color: var(--accent);
  font-weight: 700;
}

.search-row {
  justify-content: flex-start;
}

.search-row input {
  flex: 1 1 320px;
  min-width: 220px;
  padding: 0.55rem 0.9rem;
  border-radius: 0.5rem;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.95rem;
}

.search-row select {
  padding: 0.55rem 0.85rem;
  border-radius: 0.5rem;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.9rem;
}

.meta-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.5rem;
  color: var(--muted);
  font-size: 0.875rem;
  margin-bottom: 1rem;
}

.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 1rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.85rem;
  padding: 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.card.score-5 { border-left: 4px solid var(--red); }
.card.score-4 { border-left: 4px solid var(--yellow); }
.card.score-3 { border-left: 4px solid var(--green); }

.card-head {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
  font-size: 0.825rem;
}

.badge {
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
}

.badge.red { color: var(--red); border-color: var(--red); font-weight: 700; }
.badge.yellow { color: var(--yellow); border-color: var(--yellow); font-weight: 700; }
.badge.origin { color: var(--accent); }

.card h2 {
  margin: 0;
  font-size: 1.05rem;
  line-height: 1.45;
}

.card h2 a {
  color: var(--text);
  text-decoration: none;
}

.card h2 a:hover {
  color: var(--accent);
  text-decoration: underline;
}

.card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.925rem;
  flex: 1;
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.tag {
  font-size: 0.82rem;
  padding: 0.12rem 0.5rem;
  border-radius: 0.35rem;
  background: var(--surface-2);
  color: var(--muted);
}

.card-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.825rem;
  color: var(--muted);
  border-top: 1px solid var(--border);
  padding-top: 0.55rem;
}

.card-foot a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

.empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 3rem 1rem;
  color: var(--muted);
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: 0.85rem;
}

.footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.85rem;
  background: var(--surface);
}

.toast {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--accent);
  padding: 0.65rem 1rem;
  border-radius: 0.5rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  font-size: 0.875rem;
}

.toast.show { opacity: 1; }

@media (max-width: 640px) {
  .topbar, .container, .footer { padding-left: 1rem; padding-right: 1rem; }
  .cards-grid { grid-template-columns: 1fr; }
}
