:root {
  --bg: #fbfbfa;
  --surface: #ffffff;
  --border: #e4e4e1;
  --text: #1a1a18;
  --muted: #6b6b66;
  --accent: #2f5d50;
  --space: 1rem;
  --radius: 6px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16171a;
    --surface: #1d1e22;
    --border: #2e3037;
    --text: #e8e8e6;
    --muted: #9a9a95;
    --accent: #7fb8a4;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 0 var(--space) calc(var(--space) * 4);
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 system-ui, -apple-system, "Segoe UI", sans-serif;
}

.masthead {
  max-width: 46rem;
  margin: 0 auto;
  padding: calc(var(--space) * 2) 0 var(--space);
}

h1 {
  margin: 0 0 var(--space);
  font-size: 1.35rem;
  letter-spacing: -0.01em;
}

.topics {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.chip {
  padding: 0.25rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  text-decoration: none;
  font-size: 0.875rem;
  /* Border colour rather than width on the active state: a thicker border
     would reflow the row every time the selection changes. */
}

.chip:hover { color: var(--text); }

.chip--on {
  color: var(--accent);
  border-color: var(--accent);
}

main {
  max-width: 46rem;
  margin: 0 auto;
}

.topic { margin-top: calc(var(--space) * 2); }

.topic h2 {
  margin: 0 0 var(--space);
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.story {
  padding: var(--space);
  margin-bottom: 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.story h3 {
  margin: 0 0 0.4rem;
  font-size: 1.05rem;
  line-height: 1.35;
}

.story p {
  margin: 0 0 0.75rem;
  color: var(--text);
}

.sources {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.sources a {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  text-decoration: none;
  font-size: 0.8rem;
}

.sources a:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.empty { color: var(--muted); }

code {
  padding: 0.1rem 0.35rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.875em;
}

/* --- masthead ------------------------------------------------------- */

.masthead__row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space);
  margin-bottom: var(--space);
}

.masthead__actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

h1 a { color: inherit; text-decoration: none; }

.chip--button {
  background: none;
  font: inherit;
  cursor: pointer;
}

/* --- flash ---------------------------------------------------------- */

/* Fixed height: a message appearing must not push the page down. */
.flash-slot {
  min-height: 2.25rem;
  margin-bottom: 0.25rem;
}

.flash {
  margin: 0;
  padding: 0.35rem 0.7rem;
  border: 1px solid var(--border);
  border-left-width: 3px;
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 0.875rem;
}

.flash--error { border-left-color: #b3453c; }
.flash--ok    { border-left-color: var(--accent); }

/* --- login ---------------------------------------------------------- */

.login {
  max-width: 20rem;
  margin: 15vh auto 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.login h1 { margin-bottom: 0; font-size: 1.2rem; text-align: center; }
.login label { font-size: 0.8rem; color: var(--muted); }

/* --- forms ---------------------------------------------------------- */

input, textarea, button {
  font: inherit;
  color: var(--text);
}

input[type="text"], input[type="password"], input:not([type]), textarea {
  width: 100%;
  padding: 0.4rem 0.6rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

input:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
}

textarea { resize: vertical; }

button.chip {
  background: none;
  cursor: pointer;
  align-self: flex-start;
}

.linkish {
  padding: 0;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 0.8rem;
  cursor: pointer;
}

.linkish:hover { color: var(--text); }
.linkish--danger:hover { color: #b3453c; }

/* --- subscriptions -------------------------------------------------- */

.sub form { display: flex; flex-direction: column; gap: 0.4rem; }

.sub--paused { opacity: 0.55; }

.sub__head {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.sub__name { font-weight: 600; }

.sub__meta {
  flex: none;
  color: var(--muted);
  font-size: 0.8rem;
  white-space: nowrap;
}

.sub__label {
  color: var(--muted);
  font-size: 0.78rem;
}

.sub__sources {
  margin-top: 0.9rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

.sub__sources .sources {
  flex-direction: column;
  align-items: stretch;
  margin: 0.35rem 0 0.6rem;
}

.source-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.2rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 0.8rem;
  /* Keeps a long Google News URL from stretching the card. */
  overflow: hidden;
}

.source-row span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.row__or {
  flex: none;
  color: var(--muted);
  font-size: 0.8rem;
}

.sub__footer {
  display: flex;
  gap: 1rem;
  margin-top: 0.9rem;
  padding-top: 0.6rem;
  border-top: 1px solid var(--border);
}

/* --- primary nav ---------------------------------------------------- */

.nav {
  display: flex;
  gap: 1rem;
}

.nav__item {
  color: var(--muted);
  text-decoration: none;
  font-size: 1.05rem;
  font-weight: 600;
  /* Colour, never weight or border width — changing either would reflow
     the row every time you switch page. */
}

.nav__item:hover { color: var(--text); }
.nav__item--on { color: var(--text); }

/* --- chips ---------------------------------------------------------- */

.chip--small { font-size: 0.8rem; padding: 0.15rem 0.55rem; }

.chip--danger { color: #b3453c; border-color: #b3453c55; }
.chip--danger:hover { border-color: #b3453c; }

.chip--button[disabled] {
  opacity: 0.6;
  cursor: default;
}

.topics--range { margin-top: 0.5rem; }

.flash--busy { border-left-color: var(--muted); }

/* --- story head ----------------------------------------------------- */

.story__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
}

.story__head h3 { margin-bottom: 0.4rem; }

.story__age {
  flex: none;
  color: var(--muted);
  font-size: 0.78rem;
  white-space: nowrap;
}

/* --- story controls -------------------------------------------------- */

.story__controls {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex: none;
}

.story__controls form { display: flex; }

.icon {
  padding: 0 0.15rem;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  /* Both glyph states occupy the same box, so toggling a star never nudges
     the headline beside it. */
  width: 1.4rem;
  text-align: center;
}

.icon:hover { color: var(--text); }
.icon--on { color: #d8a230; }
.icon--quiet { font-size: 1.15rem; }

.story--dismissed { opacity: 0.6; }

.flash__undo { display: inline; margin-left: 0.5rem; }
.flash__undo .linkish { text-decoration: underline; }

.nav__count {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--muted);
}

.section-blurb { margin: -0.35rem 0 0.9rem; font-size: 0.85rem; }

.footnote {
  margin-top: calc(var(--space) * 2);
  font-size: 0.8rem;
}

.footnote a { color: var(--muted); }

/* Django message level tags: success/error/warning/info. */
.flash--success { border-left-color: var(--accent); }
.flash--warning { border-left-color: #b8860b; }
.flash--info    { border-left-color: var(--muted); }
