:root {
  --bg: #ffffff;
  --bg-alt: #f5f6f8;
  --border: #e2e4e9;
  --text: #1c1e21;
  --text-dim: #6b7280;
  --accent: #2563eb;
  --accent-soft: #e8efff;
  --badge-bg: #d3d7de;
  --badge-text: #33373d;
  --danger: #c0392b;
  /* In rem so the sidebar widens with the text — at a fixed px width, larger
     feed titles would just wrap or clip. Collapses to full width on mobile. */
  --sidebar-w: 16.875rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181c;
    --bg-alt: #1d2026;
    --border: #2c3038;
    --text: #e6e8eb;
    --text-dim: #9099a6;
    --accent: #5b8cff;
    --accent-soft: #22304d;
    --badge-bg: #333944;
    --badge-text: #cdd3db;
    --danger: #ef6a5c;
  }
}

* { box-sizing: border-box; }

/* The `hidden` attribute is only a UA-stylesheet `display: none`, so any author
   rule that sets display beats it — `.main-head { display: flex }` was keeping
   the settings header on screen permanently. Make hidden mean hidden. */
[hidden] { display: none !important; }

/* One dial for the whole interface. Every font size below is in rem, so this
   percentage scales all of them together. 100% is the browser's own default
   (usually 16px) — using a percentage rather than a px value means anyone who
   has raised their browser's default font size still gets the benefit of it.
   Raise this to make everything bigger. */
html {
  font-size: 112.5%;
}

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
}

/* Kept off `html`: setting the shorthand there would overwrite the root size
   above, and rem units would stop scaling with it. */
body {
  font: 0.9375rem/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ---------- Sidebar ---------- */

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--bg-alt);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-head h1 {
  margin: 0;
  font-size: 0.9375rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.icon-btn {
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 1.0625rem;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 6px;
  line-height: 1;
}

.icon-btn:hover { background: var(--border); color: var(--text); }
.icon-btn.spinning { animation: spin 0.8s linear infinite; }

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

.feed-tree {
  overflow-y: auto;
  padding: 8px 0 24px;
  flex: 1;
}

.tree-row {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 6px 14px;
  border: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  border-left: 3px solid transparent;
}

.tree-row:hover { background: var(--border); }

.tree-row.active {
  background: var(--accent-soft);
  border-left-color: var(--accent);
}

.tree-row .label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tree-row.has-unread .label { font-weight: 600; }

.tree-row.group-row { font-size: 0.75rem; letter-spacing: 0.05em; text-transform: uppercase; color: var(--text-dim); margin-top: 10px; }
.tree-row.feed-row.nested { padding-left: 30px; }

.twisty {
  width: 0.75rem;
  flex: 0 0 0.75rem;
  font-size: 0.5625rem;
  color: var(--text-dim);
  transition: transform 0.15s;
}

.twisty.collapsed { transform: rotate(-90deg); }

.badge {
  background: var(--badge-bg);
  color: var(--badge-text);
  border-radius: 0.5625rem;
  padding: 1px 7px;
  font-size: 0.6875rem;
  font-weight: 600;
  min-width: 1.25rem;
  text-align: center;
}

.badge.hidden { display: none; }

.feed-error {
  color: var(--danger);
  font-size: 0.75rem;
  flex: 0 0 auto;
}

/* ---------- Main pane ---------- */

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.main-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.main-title h2 { margin: 0; font-size: 1.0625rem; }
.scope-sub { font-size: 0.75rem; color: var(--text-dim); }

.controls { display: flex; align-items: center; gap: 12px; }

.filter-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 7px;
  overflow: hidden;
}

.filter-toggle button {
  border: none;
  background: var(--bg);
  color: var(--text-dim);
  font: inherit;
  font-size: 0.8125rem;
  padding: 5px 14px;
  cursor: pointer;
}

.filter-toggle button.active { background: var(--accent); color: #fff; }

.text-btn {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-dim);
  font: inherit;
  font-size: 0.8125rem;
  padding: 5px 12px;
  border-radius: 7px;
  cursor: pointer;
}

.text-btn:hover { color: var(--text); border-color: var(--text-dim); }

.item-list {
  flex: 1;
  overflow-y: auto;
  /* Breathing room so the last items can still scroll up past the top edge and
     be marked read individually; whatever is left over is caught by the
     bottom-of-list rule in app.js. */
  padding-bottom: 40vh;
}

/* Wrapper so the read/unread toggle can be a real button beside the row
   rather than nested inside it. The separator lives here now, so the row and
   the toggle share one line. */
.item-row {
  display: flex;
  align-items: stretch;
  border-bottom: 1px solid var(--border);
}

.item-row:hover { background: var(--bg-alt); }

.item {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  flex: 1;
  min-width: 0;
  text-align: left;
  border: none;
  background: transparent;
  color: inherit;
  font: inherit;
  padding: 12px 8px 12px 20px;
  cursor: pointer;
}

.item-toggle {
  flex: 0 0 auto;
  border: none;
  background: transparent;
  color: var(--accent);
  font-size: 0.8125rem;
  line-height: 1;
  cursor: pointer;
  /* Tall, narrow hit area: easy to hit with a thumb without crowding the
     text, and the whole height of the row is tappable. */
  padding: 0 18px 0 10px;
}

.item-toggle:hover { color: var(--text); }
.item.read + .item-toggle { color: var(--text-dim); }

/* Text column; min-width:0 lets the teaser ellipsis instead of stretching the row. */
.item-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.item-title {
  display: block;
  font-weight: 600;
}

.item-teaser {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-size: 0.84375rem;
  color: var(--text-dim);
}

/* Reserved even when empty — that's what keeps the text aligned on rows whose
   feed supplies no image. Deliberately has no background of its own, so an
   empty slot is invisible rather than a grey hole. */
.item-thumb-slot {
  flex: 0 0 6rem;
  /* Stretch to the row's full height instead of a fixed box. The text block
     sets the row height, and that moves with the root font size and with
     whether the feed supplies a teaser — a fixed height left a gap under the
     image the moment the text grew. `.item` sets align-items: flex-start, so
     this has to override it per-slot. */
  align-self: stretch;
  min-height: 4.25rem;
  /* Capped, or a headline wrapping to four or five lines stretches the image
     into a tall narrow sliver — very visible on a phone, where the slot is
     only ~4rem wide. Past this the image stays put and the text runs on. */
  max-height: 6.5rem;
  display: flex; /* makes the image fill the slot's stretched height */
}

.item-thumb {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 6px;
  background: var(--bg-alt);
}

.item.read .item-title { font-weight: 400; color: var(--text-dim); }
.item.read .item-thumb { opacity: 0.55; }

.item-meta {
  font-size: 0.75rem;
  color: var(--text-dim);
  display: flex;
  gap: 8px;
}

/* ---------- Settings ---------- */

.head-actions { display: flex; align-items: center; gap: 2px; }

.settings {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px 40px;
}

.settings-block { margin-bottom: 26px; }

.settings-block h3 {
  margin: 0 0 10px;
  font-size: 0.75rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.settings-block-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.settings-block-head h3 { margin: 0; }

.settings-note { margin: 8px 0 0; font-size: 0.8125rem; color: var(--text-dim); }
.settings-error { margin: 8px 0 0; font-size: 0.8125rem; color: var(--danger); }

.add-row { display: flex; gap: 8px; }

.add-row input,
.feed-title-input {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 6px 10px;
  min-width: 0;
}

.add-row input { flex: 1; }
.add-row input:focus,
.feed-title-input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.feed-card {
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 10px 12px;
  margin-bottom: 10px;
  background: var(--bg);
}

/* Paused feeds stay legible but visibly inactive — they're still listed
   because their articles are still readable. */
.feed-card.disabled { opacity: 0.6; }

.feed-card-top { display: flex; align-items: center; gap: 8px; }
.feed-card-top .feed-title-input { flex: 1; font-weight: 600; }

.feed-arrows { display: flex; align-items: center; gap: 2px; flex: 0 0 auto; }
.feed-arrows .icon-btn:disabled { opacity: 0.3; cursor: default; }
.feed-arrows .icon-btn:disabled:hover { background: transparent; color: var(--text-dim); }

.feed-card-meta { font-size: 0.75rem; color: var(--text-dim); margin-top: 6px; }

.feed-card-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.feed-card-actions select {
  font: inherit;
  font-size: 0.8125rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 5px 8px;
  max-width: 12rem;
}

.text-btn.danger { color: var(--danger); }
.text-btn.danger:hover { color: var(--danger); border-color: var(--danger); }

.empty, .loading {
  padding: 40px 20px;
  color: var(--text-dim);
  text-align: center;
}

/* ---------- Login ---------- */

.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
}

.login-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 280px;
  padding: 28px;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.login-card h1 { margin: 0 0 4px; font-size: 1.125rem; text-align: center; }

.login-card input {
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

.login-card button {
  padding: 9px;
  border: none;
  border-radius: 7px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.login-error { margin: 0; color: var(--danger); font-size: 0.8125rem; text-align: center; }

/* ---------- Narrow screens ---------- */

@media (max-width: 640px) {
  .app { flex-direction: column; }
  .item { padding: 10px 6px 10px 14px; gap: 10px; }
  .item-toggle { padding: 0 14px 0 8px; }
  /* No thumbnails on a phone: the screen is narrow enough that the picture
     costs more in text width than it gives back. Hiding the slot rather than
     just the image reclaims the reserved space too — the alignment it exists
     to protect doesn't matter here, since no row has an image. */
  .item-thumb-slot { display: none; }
  .sidebar {
    width: 100%;
    flex: 0 0 auto;
    /* Was 42vh, then 28vh — a third less gave the news the space but left only
       ~5 feed rows on a phone. 32vh is the compromise. The tree scrolls, so
       nothing becomes unreachable at any of these. */
    max-height: 32vh;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  /* Tighten the feed list: less padding per row and a closer line-height fit
     noticeably more feeds into the smaller pane. */
  .sidebar-head { padding: 8px 14px; }
  .feed-tree { padding: 4px 0 8px; }
  .tree-row { padding: 3px 14px; line-height: 1.35; }
  .tree-row.group-row { margin-top: 6px; }

  /* Controls sit top-right on the same line as the title rather than wrapping
     onto a row of their own, which cost ~40px of vertical space. */
  .main-head {
    flex-wrap: nowrap;
    align-items: flex-start;
    gap: 10px;
    padding: 8px 14px;
  }
  .main-title h2 { font-size: 0.9375rem; }
  .controls { gap: 6px; margin-left: auto; flex: 0 0 auto; }
  .filter-toggle button,
  .text-btn { font-size: 0.6875rem; padding: 3px 8px; }

  /* Settings takes the whole screen on a phone: the sidebar sits above the
     main column here, so leaving it visible would waste a third of the space
     on a feed list you're in the middle of editing. */
  .app.settings-open .sidebar { display: none; }
  .settings { padding: 12px 14px 32px; }
  .feed-card-actions .text-btn { font-size: 0.75rem; padding: 4px 9px; }
  .feed-card-actions select { font-size: 0.75rem; }
}
