*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #ddddd9;
  --surface: #f0f0ee;
  --border: #d8d8d5;
  --text: #222;
  --muted: #666;
  --accent: #5b9fd6;
  --accent-light: #181e28;
  --read: #444;
  --bookmark: #f5a623;
  --radius: 4px;
  --nav-h: 48px;
  --nav-bg: #161a20;
  --title-font: Georgia, 'Bitstream Charter', 'Sitka Text', Cambria, serif;
}

body {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

/* ── Navbar ──────────────────────────────────────────────── */
.navbar {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--nav-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: var(--nav-bg);
  color: #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,.5);
  border-bottom: 1px solid var(--border);
}

.logo {
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  text-decoration: none;
  letter-spacing: .5px;
}

.nav-actions { display: flex; gap: 6px; align-items: center; }

.nav-btn {
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: #fff;
  cursor: pointer;
  font-size: 13px;
  padding: 4px 10px;
  text-decoration: none;
  transition: background .15s;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.nav-btn:hover, .nav-btn.active { background: rgba(255,255,255,.2); }
.nav-btn svg { width: 16px; height: 16px; display: block; fill: currentColor; stroke: currentColor; }

/* ── User menu ───────────────────────────────────────────── */
.nav-menu { position: relative; }
.nav-menu-summary { list-style: none; cursor: pointer; }
.nav-menu-summary::-webkit-details-marker { display: none; }
.nav-menu-summary::marker { display: none; }
.nav-menu-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 4px;
  min-width: 160px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 12px rgba(0,0,0,.25);
  display: flex;
  flex-direction: column;
  z-index: 200;
}
.nav-menu-item {
  background: none;
  border: none;
  text-align: left;
  padding: 8px 12px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  display: block;
}
.nav-menu-item:hover { background: var(--bg); }

/* ── Nav badge ───────────────────────────────────────────── */
.nav-badge {
  font-size: 12px;
  color: rgba(255,255,255,.75);
  padding: 2px 8px;
  border: 1px solid rgba(255,255,255,.3);
  border-radius: 999px;
  white-space: nowrap;
}

/* ── Search bar ──────────────────────────────────────────── */
.search-bar {
  display: flex;
  gap: 8px;
  padding: 8px 16px;
  background: var(--accent-light);
  border-bottom: 1px solid var(--border);
}
.search-bar input {
  flex: 1;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
}
.search-bar button {
  padding: 6px 16px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
}
.hidden { display: none !important; }

/* ── Article list ────────────────────────────────────────── */
.article-list {
  max-width: 860px;
  margin: 16px auto;
  padding: 0 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.article-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 12px;
  cursor: pointer;
  transition: opacity .2s, background .15s, border-color .15s;
}
.article-card:hover { background: #fafaf8; border-color: #c8c8c4; }
.article-card:hover .article-title { text-decoration: underline; }
.article-card.read { opacity: .65; }
.article-card.read .article-title { color: #888; }

.article-title {
  font-family: var(--title-font);
  font-size: 16px;
  font-weight: normal;
  color: #111;
  text-decoration: none;
  grid-column: 1;
  line-height: 1.35;
  letter-spacing: 0.04em;
}
.article-title:hover { text-decoration: underline; }

.article-meta {
  font-size: 12px;
  color: var(--muted);
  grid-column: 1;
}


.article-actions {
  grid-column: 2;
  grid-row: 1 / 3;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

.btn-bookmark {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 18px;
  color: var(--border);
  line-height: 1;
  transition: color .15s;
}
.btn-bookmark.active { color: var(--bookmark); }


/* ── Time dividers ───────────────────────────────────────── */
.time-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--muted);
  padding: 8px 2px 4px;
}
.time-divider::before, .time-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ── Cluster cards ───────────────────────────────────────── */
.cluster-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  overflow: hidden;
}

.cluster-card-header {
  padding: 8px 14px 6px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.cluster-summary {
  font-size: 13px;
  color: var(--accent);
  flex: 1;
}

.cluster-count {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  margin-left: auto;
}

.cluster-btn {
  background: none;
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  padding: 2px 6px;
  margin-left: 4px;
  opacity: .55;
  transition: opacity .15s, color .15s;
}
.cluster-btn:hover { opacity: 1; }
.cluster-btn.active { opacity: 1; color: var(--accent); }
.btn-minimize { font-weight: 700; }

/* Pin renders as a star, consistent with the article bookmark star:
   same size, same resting grey, and sits at the right edge of the header
   so it aligns horizontally with every article card's bookmark star. */
.cluster-btn.btn-pin {
  font-size: 18px;
  color: var(--border);
  opacity: 1;
  padding: 2px 0 2px 6px;
  margin-left: 0;
}
.btn-pin.active { color: var(--bookmark); opacity: 1; }

/* Pinned indicator on the card itself */
.cluster-card.pinned { border-left-color: var(--bookmark); }

/* Minimized: de-emphasize the whole card; dark grey rail, darker surface.
   Declared after .pinned so it wins when both classes are set. */
.cluster-card.minimized {
  border-left-color: #b4b4b0;
  background: #e9e9e6;
}
.cluster-card.minimized .cluster-card-header,
.cluster-card.minimized .cluster-articles .article-card {
  background: #e9e9e6;
}
.cluster-card.minimized .cluster-summary { color: var(--muted); }
.cluster-card.minimized .btn-pin.active { color: var(--border); }

/* Minimized: hide all articles but the first */
.cluster-card.minimized .cluster-articles .article-card:not(:first-child) {
  display: none;
}

.cluster-articles {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 0 0 8px 0;
}

.cluster-articles .article-card {
  border: none;
  border-radius: 0;
  margin: 0;
}

/* Subsequent (smaller) articles — single row: title then source inline */
.cluster-articles .article-card:not(:first-child) {
  display: flex;
  align-items: baseline;
  flex-wrap: nowrap;
  gap: 0 8px;
  padding: 3px 14px;
}

/* Faint separator between the lead article and the condensed list below it.
   Hung off the lead card's bottom so there is no ambiguity about which gap
   gets the rule. */
.cluster-articles .article-card:first-child {
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
  padding-bottom: 10px;
}

/* In minimized clusters only the lead article is visible, so suppress the
   separator — the card should look like a plain unclustered article. */
.cluster-card.minimized .cluster-articles .article-card:first-child {
  border-bottom: none;
  margin-bottom: 0;
}

.cluster-articles .article-card:not(:first-child) .article-title {
  font-size: 12px;
  letter-spacing: 0.02em;
  line-height: 1.3;
  grid-column: unset;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cluster-articles .article-card:not(:first-child) .article-meta {
  font-size: 10px;
  grid-column: unset;
  flex-shrink: 0;
  white-space: nowrap;
  order: 2;
}

.cluster-articles .article-card:not(:first-child) .article-actions {
  grid-column: unset;
  grid-row: unset;
  flex-shrink: 0;
  order: 3;
}

/* ── Load more ───────────────────────────────────────────── */
.scroll-sentinel {
  height: 80px;   /* trigger zone before true bottom */
}

.loading-more {
  text-align: center;
  color: var(--muted);
  padding: 16px;
  font-size: 13px;
}

.end-of-feed {
  text-align: center;
  color: var(--muted);
  padding: 24px;
  font-size: 12px;
  font-style: italic;
}

.loading { text-align: center; color: var(--muted); padding: 32px; }

/* ── Auth pages ──────────────────────────────────────────── */
.auth-wrap {
  max-width: 360px;
  margin: 80px auto;
  padding: 32px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-align: center;
}
.auth-wrap .logo { color: var(--accent); display: block; margin-bottom: 24px; }

.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-form input {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
}
.auth-form button {
  padding: 9px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  cursor: pointer;
}
.auth-error { color: #c00; font-size: 13px; min-height: 18px; }
.auth-switch { margin-top: 16px; font-size: 13px; color: var(--muted); }
.auth-switch a { color: var(--accent); }

/* ── Feeds page ──────────────────────────────────────────── */
.feeds-wrap {
  max-width: 700px;
  margin: 24px auto;
  padding: 0 12px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}
.feeds-wrap h2 { font-size: 15px; margin-bottom: 10px; }

.feed-add-row { display: flex; gap: 8px; }
.feed-add-row input {
  flex: 1;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
}
.feed-add-row button, #opml-form button {
  padding: 7px 16px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
}
#feed-msg, #opml-msg { font-size: 13px; color: var(--muted); margin-top: 6px; }

.feed-items { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.feed-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.feed-title { flex: 1; }
.feed-stats {
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  margin-right: 8px;
}
.feed-policy {
  padding: 3px 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  font-size: 12px;
  color: var(--text);
  margin-right: 8px;
}
.btn-remove {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  padding: 2px 8px;
}
.btn-remove:hover { border-color: #c00; color: #c00; }
.feed-empty { color: var(--muted); font-style: italic; }
