/* Paper-and-ink reading layout. Hairline rules and tonal panels do the structuring
   that soft shadows and rounded cards used to do. */
:root {
  --bg: #f5f5f4;          /* page */
  --shade: #e7e7e5;       /* tonal panel: masthead, vote rail, hover, reader */
  --card: #fafafa;        /* lifted surface: article page, auth dialog */
  --text: #1c1c1e;
  --muted: #5c5c60;       /* 6.6:1 on --bg */
  --line: #c9c9cc;        /* hairline rules */
  --rule: #1c1c1e;        /* heavy rules: masthead and active states */
  --accent: #2f4a63;      /* slate: links, focus */
  --accent-soft: #dde4ec;
  --up: #2f6b2f;
  --down: #9a2a22;
  --warn-bg: #e4e4e6;
  --shadow: none;
  --radius: 2px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161618;
    --shade: #202023;
    --card: #1c1c1f;
    --text: #e8e8ea;
    --muted: #a0a0a6;
    --line: #3a3a3f;
    --rule: #e8e8ea;
    --accent: #9fb8cf;
    --accent-soft: #26313c;
    --up: #8dce8d;
    --down: #f0a097;
    --warn-bg: #2a2a2d;
  }
}

:root[data-theme="dark"] {
  --bg: #161618;
  --shade: #202023;
  --card: #1c1c1f;
  --text: #e8e8ea;
  --muted: #a0a0a6;
  --line: #3a3a3f;
  --rule: #e8e8ea;
  --accent: #9fb8cf;
  --accent-soft: #26313c;
  --up: #8dce8d;
  --down: #f0a097;
  --warn-bg: #2a2a2d;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
}
::selection { background: var(--accent-soft); color: var(--text); }
html { scrollbar-color: var(--line) var(--bg); }

/* Masthead: a shaded band over a heavy rule, the newspaper's nameplate. */
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 24px;
  position: sticky;
  top: 0;
  background: var(--shade);
  border-bottom: 3px solid var(--rule);
  z-index: 2;
}
.top h1 {
  margin: 0;
  font: 700 1.5rem/1 Georgia, "Iowan Old Style", "Palatino Linotype", serif;
  letter-spacing: -0.02em;
}
.account { display: flex; align-items: center; gap: 10px; min-width: 0; }
.who { color: var(--muted); font-size: 0.86rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 46vw; }

/* Category tabs: a row of section names with an ink underline on the current one. */
.tabs {
  display: flex;
  gap: 4px;
  padding: 0 24px;
  overflow-x: auto;
  scrollbar-width: none;
  max-width: 880px;
  margin: 0 auto;
  border-bottom: 1px solid var(--line);
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 0 0 auto;
  border: 0;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: var(--muted);
  padding: 12px 10px 9px;
  margin-bottom: -1px;
  font: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
}
.tab:hover { color: var(--text); background: var(--shade); }
.tab.is-active { color: var(--text); border-bottom-color: var(--rule); }

/* Tag chips: a shaded strip of plain labels, no pills. */
.tags {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
  padding: 10px 24px;
  max-width: 880px;
  margin: 0 auto;
  overflow-x: auto;
  scrollbar-width: none;
}
.tags::-webkit-scrollbar { display: none; }
.tags > .tag { flex: 0 0 auto; }
.tags:not(.is-at-end) {
  -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 36px), transparent);
          mask-image: linear-gradient(to right, #000 calc(100% - 36px), transparent);
}
.tags[hidden] { display: none; }
.tag {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  border-radius: var(--radius);
  padding: 3px 9px;
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
}
.tag::before { content: "#"; color: var(--accent); margin-right: 2px; }
.tag:hover { color: var(--text); border-color: var(--muted); }
.tag.is-active { background: var(--rule); color: var(--bg); border-color: var(--rule); }
.tag.is-active::before { color: var(--bg); }
.card-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.card-tags .tag { padding: 1px 7px; font-size: 0.74rem; }
.tab:focus-visible, .tag:focus-visible, .vote:focus-visible, .btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn {
  border: 1px solid var(--rule);
  background: var(--card);
  color: var(--text);
  border-radius: var(--radius);
  padding: 9px 14px;
  font: inherit;
  font-size: 0.93rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 42px;
  transition: background 0.15s ease;
}
.btn:hover { background: var(--shade); }
.btn.primary { background: var(--rule); border-color: var(--rule); color: var(--bg); }
.btn.primary:hover { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { background: transparent; border-color: var(--line); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Feed: stories are ruled rows, not floating cards. */
.feed {
  display: grid;
  gap: 0;
  padding: 0 24px 40px;
  max-width: 880px;
  margin: 0 auto;
}

.card {
  background: transparent;
  border: 0;
  border-top: 1px solid var(--line);
  border-radius: 0;
  box-shadow: none;
  padding: 18px 12px;
  margin: 0 -12px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 16px;
  transition: background 0.15s ease;
}
.card:first-child { border-top: 2px solid var(--rule); }
.card:hover { background: var(--shade); }
.card h2 {
  margin: 0;
  font: 700 1.14rem/1.3 Georgia, "Iowan Old Style", "Palatino Linotype", serif;
  letter-spacing: -0.005em;
  grid-column: 1;
}
.card h2 a { color: var(--text); text-decoration: none; }
.card h2 a:hover, .card h2 a:focus-visible { color: var(--accent); text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 3px; }
.card h2 a:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 2px; }
.meta {
  color: var(--muted);
  font-size: 0.8rem;
  font-variant-caps: all-small-caps;
  letter-spacing: 0.04em;
  grid-column: 1;
  display: flex;
  flex-wrap: wrap;
  gap: 0 6px;
}
.summary {
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.5;
  margin: 0;
  grid-column: 1;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.votes {
  grid-column: 2;
  grid-row: 1 / span 3;
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: center;
  justify-content: space-between;   /* up arrow to the top edge, down arrow to the bottom */
  background: var(--shade);
  padding: 4px;
  border: 1px solid var(--line);
}
.vote {
  width: 38px;
  height: 34px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  border-radius: var(--radius);
  font-size: 0.95rem;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.vote:hover { color: var(--text); border-color: var(--line); background: var(--bg); }
.vote[aria-pressed="true"].up { color: var(--up); border-color: var(--up); background: var(--bg); }
.vote[aria-pressed="true"].down { color: var(--down); border-color: var(--down); background: var(--bg); }
.vote:disabled { opacity: 0.4; cursor: not-allowed; }

.notice, .hint {
  margin: 12px 24px 0;
  padding: 10px 14px;
  border: 1px solid var(--line);
  max-width: 880px;
  margin-left: auto;
  margin-right: auto;
}
.notice { background: var(--warn-bg); }
.notice[hidden], .hint:empty { display: none; }
.hint { color: var(--muted); font-size: 0.9rem; }
.empty { color: var(--muted); text-align: center; padding: 48px 0; }

.auth {
  width: min(420px, calc(100vw - 32px));
  border: 2px solid var(--rule);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--text);
  padding: 22px;
  box-shadow: none;
}
.auth::backdrop { background: rgba(23, 21, 15, 0.6); }
.auth h2 { margin: 0 0 4px; font: 700 1.2rem Georgia, "Iowan Old Style", serif; }
.auth label { display: grid; gap: 6px; margin: 14px 0; font-size: 0.93rem; }
.auth input {
  font: inherit;
  padding: 11px 13px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  min-height: 44px;
}
.auth input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.muted { color: var(--muted); margin: 0; }
.error { color: var(--down); margin: 8px 0 0; }

/* Single-article summary page: a story with a ruled head and a shaded panel. */
.plain-link { color: inherit; text-decoration: none; }
.article-page { max-width: 680px; margin: 0 auto; padding: 24px 24px 48px; }
.back-link { margin: 0 0 18px; }
.back-link a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.88rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 0;
}
.back-link a:hover, .back-link a:focus-visible { color: var(--accent); text-decoration: underline; }
.article-card {
  display: block;
  padding: 24px 0 0;
  margin: 0 -12px;
  padding-left: 12px;
  padding-right: 12px;
  border-top: 3px solid var(--rule);
  background: transparent;
}
.article-card:hover { background: transparent; }
.article-title {
  font: 700 1.7rem/1.2 Georgia, "Iowan Old Style", "Palatino Linotype", serif;
  letter-spacing: -0.015em;
  margin: 0 0 10px;
}
.article-card .meta { margin-bottom: 4px; }
.article-summary {
  white-space: pre-line;   /* keep the paragraph breaks from the summary */
  font-size: 1.06rem;
  line-height: 1.7;
  margin: 18px 0 0;
  color: var(--text);
  -webkit-line-clamp: unset;
  display: block;
  overflow: visible;
}
.article-cta {
  margin-top: 26px;
  padding: 16px 12px;
  margin-left: -12px;
  margin-right: -12px;
  background: var(--shade);
  border-top: 1px solid var(--line);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}
.article-cta .btn { text-decoration: none; }
.article-cta .btn.primary { padding: 10px 18px; }
.offscreen { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }

/* Infinite scroll: a sentinel triggers the next page; the button is the fallback. */
.more-wrap { display: grid; justify-items: center; gap: 12px; padding: 8px 24px 40px; }
.sentinel { width: 1px; height: 1px; }
.more { min-width: 180px; }
.more:disabled { opacity: 0.6; }
.end-note { color: var(--muted); font-size: 0.9rem; margin: 0; font-style: italic; }

/* The article the reader came back from is marked with a heavy ink rule. */
.card.is-returned { animation: returned 1.6s ease-out; }
@keyframes returned { from { background: var(--accent-soft); } to { background: transparent; } }

/* Small screens: tighter, thumb-friendly. */
@media (max-width: 480px) {
  .top { padding: 10px 14px; }
  .tabs { padding: 0 8px; }
  .tags { padding: 8px 14px; }
  .feed { padding: 0 14px 32px; }
  .more-wrap { padding: 8px 14px 40px; }
  .card { padding: 14px 8px; margin: 0 -8px; gap: 8px 10px; }
  .card h2 { font-size: 1.06rem; }
  .vote { width: 36px; height: 32px; }
  .article-page { padding: 16px 14px 40px; }
  .article-card { padding-top: 20px; margin: 0 -8px; padding-left: 8px; padding-right: 8px; }
  .article-cta { margin-left: -8px; margin-right: -8px; }
  .article-title { font-size: 1.4rem; }
  .notice, .hint { margin-left: 14px; margin-right: 14px; }
}

/* ---------- Reading layout ---------- */

/* Expanded inline detail on mobile (and reused by the desktop reader). */
.detail {
  grid-column: 1 / -1;
  margin: 10px 0 0;
  padding-top: 12px;
  border-top: 1px dashed var(--line);
}
.detail-summary {
  margin: 0;
  font-size: 1rem;
  line-height: 1.65;
  color: var(--text);
  white-space: pre-line;
}
.detail-note { font-size: 0.85rem; margin: 10px 0 0; }
.detail-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.detail-actions .btn { text-decoration: none; }
.card.is-open { background: var(--shade); }
/* The card's own grid puts the title and meta in column 1, so the detail spans both columns. */
.card.is-open .summary { -webkit-line-clamp: unset; display: none; }

/* Desktop: the feed fills the width; opening an article splits it 40 / 60. */
.layout { width: 100%; }

@media (min-width: 900px) {
  .feed {
    max-width: 920px;
    width: 100%;
    padding: 0 28px 40px;
  }
  .card { padding: 20px 14px; margin: 0 -14px; }
  .card h2 { font-size: 1.24rem; line-height: 1.28; }
  .summary { font-size: 0.98rem; line-height: 1.55; }
  .layout.is-split {
    display: grid;
    grid-template-columns: 2fr 3fr;   /* 40% list, 60% article */
    align-items: start;
  }
  .layout.is-split .feed {
    max-width: none;
    padding-right: 12px;
    min-width: 0;
  }
  .layout.is-split .card { grid-template-columns: 1fr auto; }
  .reader {
    position: sticky;
    top: 72px;                         /* just below the sticky header */
    height: calc(100vh - 72px);        /* fill the column, not just the content */
    overflow-y: auto;
    background: var(--shade);
    border-left: 3px solid var(--rule);
    padding: 22px 30px 40px;
    min-width: 0;
    align-self: start;
  }
  .reader[hidden] { display: none; }
  .reader-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
  }
  .reader-close { min-height: 36px; padding: 4px 12px; font-size: 1.3rem; line-height: 1; }
  .reader-title { font: 700 1.55rem/1.22 Georgia, "Iowan Old Style", serif; letter-spacing: -0.015em; margin: 0 0 8px; }
  .reader .detail { border-top: 0; padding-top: 0; margin-top: 16px; }
  .reader .detail-summary { font-size: 1.04rem; line-height: 1.7; }
  .card.is-selected { background: var(--accent-soft); }
}

/* Mouse users get a thin scrollbar on the category and tag rows, so they can see and drag them. */
@media (hover: hover) and (pointer: fine) {
  .tabs, .tags { scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
  .tabs::-webkit-scrollbar, .tags::-webkit-scrollbar { display: block; height: 6px; }
  .tabs::-webkit-scrollbar-thumb, .tags::-webkit-scrollbar-thumb { background: var(--line); border-radius: 3px; }
  .tabs::-webkit-scrollbar-track, .tags::-webkit-scrollbar-track { background: transparent; }
}

/* Mobile: no reader pane, the reader element is never shown. */
@media (max-width: 899px) {
  .reader { display: none !important; }
}
