:root {
  --bg: #ffffff;
  --bg-alt: #f8f9fa;
  --surface: #ffffff;
  --border: #e8eaed;
  --text: #202124;
  --text-muted: #5f6368;
  --accent: #1a73e8;
  --accent-dark: #174ea6;
  --danger: #d93025;
  --chip-bg: #f1f3f4;
  --chip-bg-active: #e8f0fe;
  --chip-text-active: #1967d2;
  --shadow: 0 1px 2px rgba(60,64,67,0.15), 0 1px 3px 1px rgba(60,64,67,0.10);
  --shadow-hover: 0 1px 3px rgba(60,64,67,0.20), 0 4px 8px 3px rgba(60,64,67,0.12);
  font-family: 'Roboto', -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #202124;
    --bg-alt: #131314;
    --surface: #292a2d;
    --border: #3c4043;
    --text: #e8eaed;
    --text-muted: #9aa0a6;
    --accent: #8ab4f8;
    --accent-dark: #aecbfa;
    --danger: #f28b82;
    --chip-bg: #3c4043;
    --chip-bg-active: #37393b;
    --chip-text-active: #8ab4f8;
    --shadow: 0 1px 2px rgba(0,0,0,0.4), 0 1px 3px 1px rgba(0,0,0,0.3);
    --shadow-hover: 0 1px 3px rgba(0,0,0,0.5), 0 4px 8px 3px rgba(0,0,0,0.35);
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg-alt);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
h1, h2 { font-family: inherit; }

/* --- sign-in --- */
.signin {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-alt);
}
.signin-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2.5rem;
  text-align: center;
  max-width: 320px;
  box-shadow: var(--shadow);
}
.signin-mark {
  width: 48px; height: 48px;
  margin: 0 auto 0.75rem;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  color: white;
  font-weight: 700;
  font-size: 1.5rem;
  display: flex; align-items: center; justify-content: center;
}
.signin-card h1 { margin: 0 0 0.25rem; font-size: 1.4rem; }
.signin-card p { color: var(--text-muted); margin-top: 0; }
.signin-error { color: var(--danger); font-size: 0.9rem; }

/* --- app shell --- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0.7rem 1.5rem;
  max-width: 1080px;
  margin: 0 auto;
}
.brand {
  font-family: 'Merriweather', serif;
  font-weight: 700;
  font-size: 1.3rem;
  letter-spacing: -0.01em;
}
.tabs { display: flex; gap: 0.25rem; flex: 1; }
.tab-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 0.5rem 0.9rem;
  border-radius: 20px;
  cursor: pointer;
  font-size: 0.9rem;
  font-family: inherit;
  font-weight: 500;
  transition: background 0.15s ease, color 0.15s ease;
}
.tab-btn:hover { background: var(--chip-bg); }
.tab-btn.active { color: var(--accent); background: var(--chip-bg-active); }
.icon-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 0.25rem;
  border-radius: 50%;
}
.icon-btn:hover { background: var(--chip-bg); }

.chip-row {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  padding: 0.6rem 1.5rem;
  max-width: 1080px;
  margin: 0 auto;
  scrollbar-width: none;
}
.chip-row::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  background: var(--chip-bg);
  color: var(--text);
  border: none;
  border-radius: 16px;
  padding: 0.4rem 0.9rem;
  font-size: 0.85rem;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
}
.chip.active { background: var(--chip-bg-active); color: var(--chip-text-active); font-weight: 500; }

.main { max-width: 1080px; margin: 0 auto; padding: 1.5rem; }
.tab-panel.hidden { display: none; }
.tab-help { color: var(--text-muted); font-size: 0.9rem; margin-top: 0; max-width: 640px; }
.section-title {
  font-size: 1rem;
  font-weight: 700;
  margin: 1.75rem 0 0.75rem;
}
.section-title:first-of-type { margin-top: 0.5rem; }

.empty-state { color: var(--text-muted); text-align: center; padding: 4rem 1rem; }
.empty-state-icon { font-size: 2.5rem; margin-bottom: 0.5rem; opacity: 0.5; }

/* --- article grid (Google News-ish cards) --- */
.article-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}
.article-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: box-shadow 0.15s ease, transform 0.15s ease;
  display: flex;
  flex-direction: column;
}
.article-card:hover { box-shadow: var(--shadow-hover); }
.article-card.is-read { opacity: 0.6; }
.article-card.is-hero {
  grid-column: 1 / -1;
  flex-direction: row;
}
@media (max-width: 640px) {
  .article-card.is-hero { flex-direction: column; }
}
.article-thumb {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  background: var(--chip-bg);
  display: block;
}
.article-card.is-hero .article-thumb {
  width: 42%;
  aspect-ratio: auto;
  height: auto;
  flex: 0 0 auto;
}
.article-thumb-placeholder {
  width: 100%;
  aspect-ratio: 16 / 9;
  background: linear-gradient(135deg, var(--chip-bg), var(--bg-alt));
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted);
  font-size: 1.8rem;
  font-weight: 700;
}
.article-card.is-hero .article-thumb-placeholder { width: 42%; aspect-ratio: auto; }

.article-body {
  padding: 0.9rem 1rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  flex: 1;
}
.article-card.is-hero .article-body { padding: 1.2rem 1.4rem; justify-content: center; }
.article-source-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.78rem;
  color: var(--text-muted);
}
.article-source-dot {
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  font-size: 0.6rem;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.article-title {
  font-weight: 500;
  font-size: 0.98rem;
  line-height: 1.35;
  text-decoration: none;
  color: var(--text);
}
.article-card.is-hero .article-title {
  font-family: 'Merriweather', serif;
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.3;
}
.article-title:hover { text-decoration: underline; }
.article-snippet {
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.article-pills { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.pill {
  font-size: 0.7rem;
  padding: 0.15rem 0.55rem;
  border-radius: 10px;
  background: var(--chip-bg);
  color: var(--text-muted);
}
.article-actions { margin-top: auto; padding-top: 0.3rem; }
.article-actions button {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 0.78rem;
  font-family: inherit;
  cursor: pointer;
  padding: 0.2rem 0;
}

/* --- preset topic checkboxes --- */
.preset-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.5rem;
}
.preset-item {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.65rem 0.8rem;
  cursor: pointer;
}
.preset-item input { margin-top: 0.15rem; }
.preset-item-name { font-weight: 500; font-size: 0.9rem; }
.preset-item-desc { font-size: 0.78rem; color: var(--text-muted); margin-top: 0.15rem; }

/* --- entity list (custom topics/feeds) --- */
.entity-list { list-style: none; margin: 0 0 1rem; padding: 0; }
.entity-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem 0.9rem;
  margin-bottom: 0.6rem;
}
.entity-item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}
.entity-name { font-weight: 500; }
.entity-sub { color: var(--text-muted); font-size: 0.85rem; margin-top: 0.25rem; }
.delete-btn {
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 1rem;
}

/* --- preload row --- */
.preload-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.9rem 1rem;
  margin-bottom: 1.25rem;
}
.preload-row .tab-help { margin: 0; }

/* --- preferences --- */
.toggle-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.9rem;
  cursor: pointer;
}
.toggle-row input { width: 16px; height: 16px; }
.prefs-saved { color: var(--accent); font-size: 0.85rem; margin-top: 0.75rem; }

/* --- forms --- */
.add-form {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.add-form-block { flex-direction: column; align-items: flex-start; }
.add-form input, .add-form select, .add-form textarea {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 0.55rem 0.75rem;
  font-size: 0.9rem;
  font-family: inherit;
}
.add-form-block input, .add-form-block textarea { width: 100%; }
.add-form input:focus, .add-form select:focus, .add-form textarea:focus {
  outline: none;
  border-color: var(--accent);
}
.btn-primary {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 20px;
  padding: 0.55rem 1.2rem;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  align-self: flex-start;
}
.btn-primary:hover { background: var(--accent-dark); }
.btn-secondary {
  background: none;
  border: 1px solid var(--accent);
  color: var(--accent);
  border-radius: 20px;
  padding: 0.5rem 1.1rem;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}
.btn-secondary:hover { background: var(--chip-bg-active); }
