:root {
  --bg: #fbfbfa;
  --surface: #ffffff;
  --surface-2: #f4f4f2;
  --border: #e3e2de;
  --border-strong: #cdccc6;
  --text: #1a1a19;
  --text-2: #55544f;
  /* Was #8a8983 — 3.39:1, below the 4.5:1 threshold, on text that carries the
     byline, the match explanation and every count. */
  --text-3: #6f6e69;
  --accent: #1d5c8f;
  --accent-soft: #e8f0f7;
  --good: #1f7a4d;
  --good-soft: #e6f2eb;
  --bad: #a33a2c;
  --bad-soft: #f8eae7;
  --warn: #8a6a1f;
  --warn-soft: #f6f0e0;
  --radius: 6px;
  --hdr: 53px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17171a; --surface: #1e1e22; --surface-2: #26262b;
    --border: #33333a; --border-strong: #46464f;
    --text: #e8e8e6; --text-2: #adaca7; --text-3: #8d8d86;
    --accent: #6aa9dc; --accent-soft: #1b2c3a;
    --good: #5cc28d; --good-soft: #172a20;
    --bad: #e08373; --bad-soft: #2e1d19;
    --warn: #d6b25e; --warn-soft: #2b2518;
  }
}
:root[data-theme="dark"] {
  --bg: #17171a; --surface: #1e1e22; --surface-2: #26262b;
  --border: #33333a; --border-strong: #46464f;
  --text: #e8e8e6; --text-2: #adaca7; --text-3: #8d8d86;
  --accent: #6aa9dc; --accent-soft: #1b2c3a;
  --good: #5cc28d; --good-soft: #172a20;
  --bad: #e08373; --bad-soft: #2e1d19;
  --warn: #d6b25e; --warn-soft: #2b2518;
}

* { box-sizing: border-box; }
/* min-height, not height: `height: 100%` caps the sticky containing block at one
   viewport, so the sticky toolbar stops sticking after the first screen. */
html, body { min-height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.primary:focus-visible { outline-color: var(--text); outline-offset: 3px; }

.skip {
  position: absolute; left: -9999px; top: 0; z-index: 100;
  background: var(--accent); color: #fff; padding: 10px 16px; border-radius: 0 0 var(--radius) 0;
}
.skip:focus { left: 0; }

/* ------------------------------- header ------------------------------- */
header {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 16px; background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.brand { font-weight: 650; letter-spacing: -0.01em; white-space: nowrap; }

.who { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.who > span { font-size: 12px; color: var(--text-3); }
.who select {
  padding: 4px 8px; border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: var(--surface); font-weight: 600; max-width: 170px;
}

/* The one-line interest, inline rather than in its own 39px strip. */
.interest {
  flex: 1; min-width: 0; font-size: 12.5px; color: var(--text-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.interest .learned-chip {
  font-size: 11px; background: var(--surface-2); border: 1px solid var(--border);
  padding: 1px 7px; border-radius: 100px; color: var(--text-2); margin-left: 8px;
}

.meta { font-size: 12px; color: var(--text-3); white-space: nowrap; font-variant-numeric: tabular-nums; }

.icon-btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--text-2);
  border-radius: var(--radius); padding: 5px 10px; cursor: pointer; font-size: 12px;
  white-space: nowrap;
}
.icon-btn:hover { border-color: var(--border-strong); color: var(--text); }
a.icon-btn { display: inline-block; text-decoration: none; }
/* An author `display` beats the UA rule for [hidden], so say it explicitly. */
a.icon-btn[hidden], [hidden] { display: none !important; }

.toggle {
  border: 1px solid var(--border); background: var(--surface); color: var(--text-2);
  border-radius: 100px; padding: 5px 12px; cursor: pointer; font-size: 12px; white-space: nowrap;
}
.toggle:hover { border-color: var(--border-strong); color: var(--text); }
.toggle[aria-pressed="true"] {
  background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 550;
}
.toggle[disabled] { opacity: .45; cursor: default; }

/* ------------------------------- layout ------------------------------- */
.shell { display: grid; grid-template-columns: 236px 1fr; align-items: start; }

/* -------------------------------- rail -------------------------------- */
.rail {
  border-right: 1px solid var(--border); padding: 12px 12px 40px;
  position: sticky; top: var(--hdr); max-height: calc(100vh - var(--hdr)); overflow-y: auto;
}
#railBody h3 {
  font-size: 11px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--text-3); margin: 14px 0 6px; font-weight: 600;
}
#railBody h3:first-child { margin-top: 0; }

/* Facet groups collapse: the rail held 1,865px of content in a 767px column, so
   five of seven groups began below the fold. */
.fgroup { border-bottom: 1px solid var(--border); padding: 2px 0; }
.fgroup > summary {
  cursor: pointer; list-style: none; padding: 7px 2px;
  font-size: 12px; font-weight: 600; color: var(--text-2);
  display: flex; align-items: center; gap: 6px;
}
.fgroup > summary::-webkit-details-marker { display: none; }
.fgroup > summary::before { content: "▸"; color: var(--text-3); font-size: 10px; }
.fgroup[open] > summary::before { content: "▾"; }
.fgroup > summary:hover { color: var(--text); }
.fgroup .n-sel {
  margin-left: auto; font-size: 11px; background: var(--accent); color: #fff;
  border-radius: 100px; padding: 0 6px; font-variant-numeric: tabular-nums;
}
.fgroup .n-sel:empty { display: none; }
.fgroup-body { padding: 2px 0 8px; }

#railBody .facet, .facet {
  display: flex; align-items: center; gap: 7px; padding: 3px 4px;
  border-radius: 4px; cursor: pointer; font-size: 13px; color: var(--text-2);
  margin: 0; font-weight: 400;
}
.facet:hover { background: var(--surface-2); color: var(--text); }
.facet input { margin: 0; accent-color: var(--accent); cursor: pointer; }
.facet .n { margin-left: auto; font-size: 11px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.facet.off { color: var(--text-3); }

/* The common publication windows, one click each. They wrap to two rows in the
   236px rail, which is why the gap is tight and the padding asymmetric. */
.spans { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 7px; }
.span {
  flex: 1 1 auto; padding: 4px 8px; font-size: 11.5px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text-2);
  border-radius: 100px; white-space: nowrap;
}
.span:hover { border-color: var(--border-strong); color: var(--text); }
.span[aria-pressed="true"] {
  background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 550;
}

#railBody input[type="range"] { width: 100%; accent-color: var(--accent); }
#railBody input[type="date"], #railBody select {
  width: 100%; padding: 5px 7px; border: 1px solid var(--border);
  border-radius: 4px; background: var(--surface); margin-bottom: 5px;
}
.reset {
  width: 100%; margin-top: 14px; padding: 7px; cursor: pointer;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text-2);
}
.reset:hover { border-color: var(--border-strong); color: var(--text); }
.rail-note { font-size: 11.5px; color: var(--text-3); margin: 6px 0 0; line-height: 1.5; }

/* ------------------------------- results ------------------------------ */
.results { padding: 0 0 60px; min-width: 0; }
.toolbar {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  padding: 8px 16px; border-bottom: 1px solid var(--border);
  position: sticky; top: var(--hdr); background: var(--bg); z-index: 11;
}
.toolbar input[type="search"] {
  flex: 1; min-width: 150px; padding: 6px 10px;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
}
.toolbar select { padding: 6px 8px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.count { font-size: 12px; color: var(--text-3); font-variant-numeric: tabular-nums; white-space: nowrap; }

.active-filters {
  display: flex; gap: 6px; flex-wrap: wrap; align-items: center;
  padding: 8px 16px; border-bottom: 1px solid var(--border); background: var(--surface);
}
.active-filters[hidden] { display: none; }
.active-filters .lbl { font-size: 11.5px; color: var(--text-3); }
.pill {
  font-size: 11.5px; padding: 3px 8px; border-radius: 100px; cursor: pointer;
  background: var(--accent-soft); border: 1px solid var(--accent); color: var(--accent);
}
.pill::after { content: " ✕"; opacity: .6; }
.pill:hover { background: var(--accent); color: #fff; }

/* ------------------------------- a paper ------------------------------ */
#list { list-style: none; margin: 0; padding: 0; }

.paper {
  display: grid; grid-template-columns: 22px 38px 1fr; gap: 10px;
  align-items: start;                    /* was stretching the checkbox down the row */
  padding: 10px 16px; border-bottom: 1px solid var(--border);
}
.paper:hover { background: var(--surface); }
.paper.labeled-relevant { box-shadow: inset 3px 0 0 var(--good); }
.paper.labeled-not { box-shadow: inset 3px 0 0 var(--bad); background: var(--surface-2); }
.paper.labeled-not .title a, .paper.labeled-not .byline { color: var(--text-3); }
.paper.labeled-unsure { box-shadow: inset 3px 0 0 var(--warn); }
.paper.is-new { box-shadow: inset 3px 0 0 var(--accent); }
.paper input[type="checkbox"] { margin-top: 3px; accent-color: var(--accent); cursor: pointer; }

/* The list is already sorted by this number, and the second decimal decides
   nothing, so it no longer needs to be the loudest mark in the row. */
.score {
  font: 500 12px/1.3 var(--mono); text-align: right; padding-top: 2px;
  color: var(--text-3); font-variant-numeric: tabular-nums;
}

.title { font-weight: 550; line-height: 1.32; margin: 0 0 2px; font-size: 14px; }
.title a { color: var(--text); }
.title a:hover { color: var(--accent); }
.title .newdot {
  font-size: 10px; color: var(--accent); font-weight: 600;
  border: 1px solid var(--accent); border-radius: 100px; padding: 0 5px; margin-left: 6px;
  vertical-align: 1px;
}

/* Promoted directly under the title: it is the only per-person text in the row
   and the only answer to "why is this in my feed?". */
.why { font-size: 12.5px; color: var(--text-2); line-height: 1.45; margin-bottom: 3px; }

.byline { font-size: 12.5px; color: var(--text-3); margin-bottom: 5px; }
.byline em { font-style: normal; color: var(--text-2); font-weight: 550; }

.chips { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 5px; }
.chip {
  font-size: 11px; padding: 1.5px 7px; border-radius: 100px;
  background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border);
  cursor: pointer; white-space: nowrap;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
/* Colour belongs to the member's own review state, not to topic decoration. */
.chip.is-preprint { border-style: dashed; }

.abstract {
  font-size: 12.5px; color: var(--text-2); line-height: 1.5;
  margin: 4px 0 6px; padding-left: 10px; border-left: 2px solid var(--border);
}
.abstract.clamped {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}

.labels { display: flex; gap: 5px; align-items: center; flex-wrap: wrap; }
.lab {
  padding: 3px 11px; font-size: 12px; cursor: pointer;
  border: 1px solid var(--border); border-radius: 100px;
  background: var(--surface); color: var(--text-2);
}
.lab:hover { border-color: var(--border-strong); color: var(--text); }
.lab:disabled { opacity: .5; cursor: progress; }
.lab[aria-pressed="true"].yes { background: var(--good-soft); border-color: var(--good); color: var(--good); font-weight: 550; }
.lab[aria-pressed="true"].no  { background: var(--bad-soft);  border-color: var(--bad);  color: var(--bad);  font-weight: 550; }
.lab[aria-pressed="true"].maybe { background: var(--warn-soft); border-color: var(--warn); color: var(--warn); font-weight: 550; }

.links { margin-left: auto; display: flex; gap: 10px; align-items: center; }
.links a, .expand {
  font-size: 11.5px; color: var(--text-3); background: none; border: none;
  cursor: pointer; padding: 0;
}
.links a:hover, .expand:hover { color: var(--accent); }

.empty { padding: 60px 20px; text-align: center; color: var(--text-3); }
.empty code {
  font-family: var(--mono); font-size: 12px; background: var(--surface-2);
  padding: 2px 6px; border-radius: 4px; border: 1px solid var(--border);
}

/* ------------------------------- dialogs ------------------------------ */
dialog {
  border: 1px solid var(--border-strong); border-radius: 10px; padding: 0;
  background: var(--surface); color: var(--text);
  max-width: 640px; width: calc(100% - 32px);
}
dialog::backdrop { background: rgba(0,0,0,.45); }
.dlg-head {
  padding: 14px 18px; border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
}
.dlg-head h2 { margin: 0; font-size: 15px; }
.dlg-body { padding: 16px 18px; max-height: 68vh; overflow-y: auto; }
.dlg-body label { display: block; font-size: 12px; color: var(--text-2); margin: 12px 0 4px; font-weight: 550; }
.dlg-body textarea, .dlg-body input[type="text"], .dlg-body input[type="password"] {
  width: 100%; padding: 8px; border: 1px solid var(--border);
  border-radius: var(--radius); background: var(--bg); line-height: 1.6;
}
.dlg-body textarea { min-height: 88px; resize: vertical; }
.hint { font-size: 11.5px; color: var(--text-3); margin-top: 4px; line-height: 1.5; }
.dlg-foot {
  padding: 12px 18px; border-top: 1px solid var(--border);
  display: flex; gap: 8px; justify-content: flex-end;
}
.dlg-warn {
  background: var(--bad-soft); border: 1px solid var(--bad); color: var(--bad);
  padding: 9px 12px; border-radius: var(--radius); font-size: 12.5px; margin-bottom: 12px;
}
.dlg-warn[hidden] { display: none; }

.who-list { display: flex; flex-wrap: wrap; gap: 8px; }
.who-list button {
  padding: 9px 16px; border: 1px solid var(--border); background: var(--surface);
  border-radius: 100px; cursor: pointer; font-size: 14px;
}
.who-list button:hover { border-color: var(--accent); color: var(--accent); }

.primary {
  padding: 8px 14px; background: var(--accent); color: #fff; border: none;
  border-radius: var(--radius); cursor: pointer; font-weight: 550;
}
.primary:disabled { opacity: .45; cursor: not-allowed; }

.presets { display: flex; gap: 5px; flex-wrap: wrap; margin-bottom: 10px; }
.preset {
  font-size: 11.5px; padding: 4px 9px; border: 1px solid var(--border);
  background: var(--surface); border-radius: 100px; cursor: pointer; color: var(--text-2);
}
.preset:hover { border-color: var(--accent); color: var(--accent); }
.ai-sub { font-size: 12.5px; color: var(--text-3); margin: 0 0 10px; }
.keynote { font-size: 11px; color: var(--text-3); line-height: 1.5; margin: 4px 0 12px; }
.answer {
  font-size: 13px; line-height: 1.6; white-space: pre-wrap; word-wrap: break-word;
  margin-top: 12px;
}
.answer:not(:empty) { border-top: 1px solid var(--border); padding-top: 10px; }
.answer .tag {
  font: 600 11px var(--mono); color: var(--accent);
  background: var(--accent-soft); padding: 1px 4px; border-radius: 3px;
}

.sched-h {
  font-size: 11px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--text-3); margin: 18px 0 8px; font-weight: 600;
}
.sched-row {
  display: grid; grid-template-columns: 96px 1fr; gap: 10px;
  padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13px;
}
.sched-row:last-child { border-bottom: none; }
.sched-row.is-next { background: var(--accent-soft); margin: 0 -8px; padding: 8px; border-radius: 4px; }
.sched-date { color: var(--text-3); font-variant-numeric: tabular-nums; font-size: 12px; }
.sched-who { font-weight: 550; }
.sched-paper { color: var(--text-2); font-size: 12.5px; margin-top: 2px; line-height: 1.45; }
.sched-off { color: var(--text-3); font-style: italic; }
.sched-buckets { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; }

.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  padding: 10px 18px; border-radius: 100px; font-size: 13px;
  box-shadow: 0 4px 18px rgba(0,0,0,.25); z-index: 100; max-width: calc(100% - 32px);
}
.toast[hidden] { display: none; }

.spinner {
  display: inline-block; width: 12px; height: 12px; vertical-align: -1px;
  border: 2px solid var(--border-strong); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2s; } }

/* -------------------- responsive, last so it wins --------------------- */

.narrow-only { display: none; }

@media (max-width: 980px) {
  header { flex-wrap: wrap; row-gap: 6px; }
  .interest { order: 10; flex-basis: 100%; white-space: normal; }
}

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  /* The rail is hidden here, so its controls move into a dialog rather than
     filtering invisibly with no way to reach them. */
  .rail { display: none; }
  .narrow-only { display: inline-block; }
  header .meta { display: none; }
  .paper { grid-template-columns: 22px 1fr; padding: 10px 12px; }
  .score { display: none; }
  .title .score-inline { display: inline; }
  /* Below the 44px touch guideline before. */
  .lab { min-height: 40px; padding: 9px 14px; font-size: 13px; }
  .chip { min-height: 30px; padding: 5px 10px; }
  .toolbar { padding: 8px 12px; }
}

.score-inline { display: none; font: 500 11px var(--mono); color: var(--text-3); }

.abstract[hidden] { display: none; }
.more-chips { cursor: default; color: var(--text-3); }
.more-chips:hover { border-color: var(--border); color: var(--text-3); }

/* A page needs a heading even when the design does not show one. */
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* The row the keyboard is on. Distinct from the review-state bars on the left. */
.paper.cursor { background: var(--accent-soft); outline: 2px solid var(--accent); outline-offset: -2px; }

.presented {
  font-size: 10.5px; padding: 1.5px 7px; border-radius: 100px; white-space: nowrap;
  background: var(--warn-soft); border: 1px solid var(--warn); color: var(--warn); font-weight: 550;
}

.keys { display: grid; grid-template-columns: 56px 1fr; gap: 6px 12px; margin: 14px 0 0; }
.keys dt {
  font: 600 12px var(--mono); background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 4px; padding: 2px 0; text-align: center;
}
.keys dd { margin: 0; font-size: 13px; color: var(--text-2); align-self: center; }

.facet .last-seen { font-size: 10.5px; color: var(--text-3); margin-left: 6px; }
