/* Lit Review Finder — production UI.
   Warm-paper editorial theme: serif display type, teal + amber accents,
   dense scannable result rows. No frameworks, no external assets. */

:root {
  --font-ui: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
    Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: "Iowan Old Style", "Palatino Linotype", Palatino,
    Charter, Georgia, serif;

  --bg: #f6f3ea;
  --surface: #fffdf7;
  --surface-2: #efeadd;
  --ink: #1c1917;
  --muted: #78716c;
  --faint: #a8a29e;
  --line: #e5ddcb;
  --accent: #0f766e;
  --accent-deep: #0b5b56;
  --accent-soft: rgba(15, 118, 110, 0.10);
  --on-accent: #ffffff;
  --gold: #b45309;
  --gold-soft: rgba(180, 83, 9, 0.12);
  --danger: #b91c1c;
  --danger-bg: rgba(185, 28, 28, 0.07);
  --shadow: 0 2px 14px rgba(28, 25, 23, 0.07);
  --shadow-lg: 0 10px 34px rgba(28, 25, 23, 0.12);
  --header-bg: rgba(246, 243, 234, 0.86);
  --radius: 12px;
  --ease: 180ms ease;
}

/* Dark theme: follows the OS, unless the user picks light/dark explicitly
   via the header toggle (html[data-theme]). */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #100e0c;
    --surface: #1a1714;
    --surface-2: #26211b;
    --ink: #f2ede3;
    --muted: #a8a094;
    --faint: #6f6a60;
    --line: #2e2a23;
    --accent: #2dd4bf;
    --accent-deep: #5eead4;
    --accent-soft: rgba(45, 212, 191, 0.12);
    --on-accent: #0b1514;
    --gold: #fbbf24;
    --gold-soft: rgba(251, 191, 36, 0.13);
    --danger: #f87171;
    --danger-bg: rgba(248, 113, 113, 0.09);
    --shadow: 0 2px 14px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 34px rgba(0, 0, 0, 0.55);
    --header-bg: rgba(16, 14, 12, 0.86);
  }
}

/* Explicit user choice wins over the OS setting. */
:root[data-theme="dark"] {
  --bg: #100e0c;
  --surface: #1a1714;
  --surface-2: #26211b;
  --ink: #f2ede3;
  --muted: #a8a094;
  --faint: #6f6a60;
  --line: #2e2a23;
  --accent: #2dd4bf;
  --accent-deep: #5eead4;
  --accent-soft: rgba(45, 212, 191, 0.12);
  --on-accent: #0b1514;
  --gold: #fbbf24;
  --gold-soft: rgba(251, 191, 36, 0.13);
  --danger: #f87171;
  --danger-bg: rgba(248, 113, 113, 0.09);
  --shadow: 0 2px 14px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 34px rgba(0, 0, 0, 0.55);
  --header-bg: rgba(16, 14, 12, 0.86);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  transition: background var(--ease), color var(--ease);
}

.wrap { max-width: 960px; margin: 0 auto; padding: 0 22px; }
.hidden { display: none !important; }

.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;
}

/* ---------- slim sticky bar ----------
   The ONLY sticky element: one compact row (title left, theme toggle
   right). The hero masthead below scrolls away, so results get the
   viewport while scrolling. */
.slim-bar {
  position: sticky; top: 0; z-index: 50;
  background: var(--header-bg);
  -webkit-backdrop-filter: blur(18px) saturate(160%);
  backdrop-filter: blur(18px) saturate(160%);
  border-bottom: 1px solid var(--line);
}
.slim-inner {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  min-height: 52px; padding-top: 6px; padding-bottom: 6px;
}
.slim-title {
  display: inline-flex; align-items: center; gap: 9px;
  margin: 0; min-width: 0;
  font-family: var(--font-display);
  font-size: 16.5px; font-weight: 700; letter-spacing: -0.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.slim-title em { font-style: italic; font-weight: 400; color: var(--muted); }
.slim-mark { width: 24px; height: 24px; flex: 0 0 auto; color: var(--accent); }
/* Mobile-only tagline row inside the slim bar; hidden on desktop. */
.slim-tagline { display: none; }

/* ---------- hero masthead (scrolls away, not sticky) ---------- */

.site-header {
  background: var(--header-bg);
  border-bottom: 1px solid var(--line);
}

.header-inner {
  display: flex; flex-direction: column; align-items: center; text-align: center;
  gap: 8px;
  padding-top: 26px; padding-bottom: 8px;
}

.wordmark {
  display: inline-flex; align-items: center; gap: 12px;
  margin: 0;
  font-family: var(--font-display);
  font-size: 27px; font-weight: 700; letter-spacing: -0.01em;
}

.wordmark-mark { width: 34px; height: 34px; flex: 0 0 auto; color: var(--accent); }
.wordmark em { font-style: italic; font-weight: 400; color: var(--muted); }

.site-header .subtitle {
  margin: 0; max-width: 36em;
  font-family: var(--font-display);
  font-size: 16.5px; line-height: 1.5;
  color: var(--muted);
}

/* Theme toggle: always visible in the header, persists to localStorage. */
.theme-toggle {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 14px;
  font-family: inherit; font-size: 12.5px; font-weight: 600;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--line); border-radius: 999px;
  cursor: pointer; white-space: nowrap;
  transition: color var(--ease), border-color var(--ease), background var(--ease);
}
.theme-toggle:hover { color: var(--ink); border-color: var(--accent); }
.tt-icons { display: inline-flex; width: 15px; height: 15px; color: var(--accent); }
.tt-ic { display: none; width: 15px; height: 15px; }
.theme-toggle[data-active="system"] .tt-ic-system { display: block; }
.theme-toggle[data-active="light"] .tt-ic-sun { display: block; }
.theme-toggle[data-active="dark"] .tt-ic-moon { display: block; }

/* ---------- search panel ---------- */

.search-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  margin: 30px 0 26px;
  padding: 26px 26px 22px;
}

.search-row { display: flex; gap: 12px; align-items: stretch; }

#query {
  flex: 1 1 auto; min-width: 0;
  padding: 14px 18px;
  font-size: 17px; font-family: var(--font-display);
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  transition: border-color var(--ease), box-shadow var(--ease), background var(--ease);
}

#query::placeholder { color: var(--faint); font-style: italic; }
#query:focus {
  outline: none; border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.btn-primary {
  padding: 0 34px;
  font-size: 16px; font-weight: 700; font-family: var(--font-ui);
  color: var(--on-accent); background: var(--accent);
  border: none; border-radius: 999px; cursor: pointer; white-space: nowrap;
  transition: background var(--ease), transform 150ms ease, opacity var(--ease);
}
.btn-primary:hover { background: var(--accent-deep); }
.btn-primary:active { transform: scale(0.97); }
.btn-primary:disabled { opacity: 0.55; cursor: default; transform: none; }

.search-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-top: 18px;
}

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field span {
  font-size: 12.5px; font-weight: 600; color: var(--muted);
}
.field input {
  padding: 9px 12px;
  font-size: 14.5px; font-family: inherit; color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px;
  transition: border-color var(--ease), box-shadow var(--ease);
}
.field input:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.field input::placeholder { color: var(--faint); }

.toggles {
  display: flex; gap: 24px; flex-wrap: wrap;
  margin-top: 18px; padding-top: 16px;
  border-top: 1px solid var(--line);
  font-size: 14.5px; color: var(--muted);
}

.check { display: inline-flex; align-items: center; gap: 9px; cursor: pointer; user-select: none; }
.check:hover { color: var(--ink); }
.check input[type="checkbox"],
.fcheck input[type="checkbox"] {
  -webkit-appearance: none; appearance: none;
  width: 18px; height: 18px; margin: 0; padding: 0; flex: 0 0 auto;
  display: inline-grid; place-content: center;
  background: var(--surface);
  border: 1.5px solid var(--faint); border-radius: 5px;
  cursor: pointer; vertical-align: -3px;
  transition: background var(--ease), border-color var(--ease);
}
.check input[type="checkbox"]::before,
.fcheck input[type="checkbox"]::before {
  content: "";
  width: 10px; height: 10px;
  transform: scale(0);
  transition: transform 120ms ease;
  background: var(--on-accent);
  clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0%, 43% 62%);
}
.check input[type="checkbox"]:checked,
.fcheck input[type="checkbox"]:checked {
  background: var(--accent);
  border-color: var(--accent);
}
.check input[type="checkbox"]:checked::before,
.fcheck input[type="checkbox"]:checked::before {
  transform: scale(1);
}
.check input[type="checkbox"]:focus-visible,
.fcheck input[type="checkbox"]:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

/* ---------- states ---------- */

.empty-state {
  text-align: center;
  padding: 40px 28px; margin: 0 0 40px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  color: var(--muted);
}
.empty-state .glyph { width: 44px; height: 44px; margin: 0 auto 14px; color: var(--accent); opacity: 0.85; }
.empty-state p { margin: 6px 0; font-size: 15px; }
.empty-state .big {
  font-family: var(--font-display);
  font-size: 26px; font-weight: 700; letter-spacing: -0.01em; color: var(--ink);
}
.empty-state kbd {
  display: inline-block; padding: 1px 8px;
  font-size: 13px; font-family: inherit;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 6px; color: var(--ink);
}

.loading-state { margin: 0 0 64px; }
.loading-label {
  display: flex; align-items: center; gap: 10px;
  margin: 4px 2px 14px; font-size: 15px; color: var(--muted);
}
.spinner {
  width: 18px; height: 18px; flex: 0 0 auto;
  border: 2.5px solid var(--line); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.skel {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 22px; margin-bottom: 12px; overflow: hidden;
}
.skel-line {
  height: 13px; border-radius: 7px; margin-bottom: 11px;
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--line) 50%, var(--surface-2) 75%);
  background-size: 200% 100%; animation: shimmer 1.4s ease infinite;
}
.skel-line:last-child { margin-bottom: 0; }
.skel-line.w60 { width: 60%; } .skel-line.w40 { width: 40%; } .skel-line.w85 { width: 85%; }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

@media (prefers-reduced-motion: reduce) {
  .skel-line, .spinner { animation: none; }
  * { transition-duration: 0.01ms !important; }
}

.error-box {
  background: var(--danger-bg); color: var(--danger);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 20px; margin: 0 0 26px;
  font-size: 15px; line-height: 1.5;
}

/* ---------- results toolbar ---------- */

#results { margin-bottom: 80px; }

/* Snowball context banner: always clear which paper these results belong
   to, and how to get back. */
.crumb {
  display: flex; align-items: center; gap: 14px;
  margin: 2px 0 14px; padding: 12px 16px;
  font-size: 14px; color: var(--muted);
  background: var(--accent-soft);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.crumb-main {
  flex: 1 1 auto; min-width: 0;
  display: flex; flex-direction: column; gap: 3px;
}
.crumb-kicker {
  font-size: 11px; font-weight: 700; letter-spacing: 0.07em; text-transform: uppercase;
  color: var(--accent); white-space: nowrap;
}
.crumb-title {
  color: var(--ink); font-weight: 600; font-size: 13.5px; line-height: 1.45;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.crumb-back { flex: 0 0 auto; background: var(--surface); }

.toolbar {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
  /* No overflow:hidden: the tap-to-reveal info popovers must escape. */
}

.tb-top {
  display: flex; justify-content: space-between; align-items: center;
  gap: 14px; flex-wrap: wrap;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}

.summary { margin: 0; font-size: 14.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.summary strong { color: var(--ink); font-weight: 700; font-size: 16px; }
.sum-sub { color: var(--faint); }

.tb-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.seg {
  display: inline-flex; background: var(--surface-2);
  border-radius: 999px; padding: 3px; gap: 2px;
}
.seg button {
  border: none; background: transparent; color: var(--muted);
  font-family: inherit; font-size: 13px; font-weight: 600;
  padding: 7px 13px; border-radius: 999px; cursor: pointer; white-space: nowrap;
  transition: background var(--ease), color var(--ease), box-shadow var(--ease);
}
.seg button:hover { color: var(--ink); }
.seg button.active {
  background: var(--surface); color: var(--ink);
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.14);
}

/* Sort control wrapper. On desktop it disappears into the layout (the
   toolbar card already bounds it); on mobile it becomes a labeled band so
   the strip never feels adrift. */
.sort-band { display: contents; }
.sort-label { display: none; }
.seg-scroll { min-width: 0; }

.btn-ghost {
  padding: 8px 16px;
  font-size: 13.5px; font-weight: 600; font-family: inherit;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--line); border-radius: 999px;
  cursor: pointer; white-space: nowrap;
  transition: border-color var(--ease), background var(--ease);
}
.btn-ghost:hover { border-color: var(--accent); background: var(--accent-soft); }
.btn-ghost:active { transform: scale(0.97); }

.tb-filters {
  display: flex; align-items: center; gap: 20px; flex-wrap: wrap;
  padding: 12px 18px;
  font-size: 13.5px; color: var(--muted);
}
.fcheck { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.fcheck:hover { color: var(--ink); }

.ffield { display: inline-flex; align-items: center; gap: 8px; }
.ffield input {
  padding: 7px 11px; font-size: 13.5px; font-family: inherit; color: var(--ink);
  background: var(--bg); border: 1px solid var(--line); border-radius: 9px;
  transition: border-color var(--ease), box-shadow var(--ease);
}
.ffield input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.ffield input[type="number"] { width: 84px; }
.ffield input[type="text"] { width: 170px; }
.ffield input::placeholder { color: var(--faint); }
.ffield select {
  padding: 7px 10px; font-size: 13.5px; font-family: inherit; color: var(--ink);
  background: var(--bg); border: 1px solid var(--line); border-radius: 9px;
  cursor: pointer; max-width: 100%;
  transition: border-color var(--ease), box-shadow var(--ease);
}
.ffield select:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.sources-note { margin-left: auto; font-size: 12.5px; color: var(--faint); font-style: italic; }

.topic-chips {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 0 18px 14px; font-size: 13px; color: var(--muted);
}
.topic-label { font-weight: 600; font-size: 12.5px; flex: 0 0 auto; }
.topic-chip {
  padding: 3px 11px;
  background: var(--surface-2); color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px; font-size: 11.5px; font-weight: 600; white-space: nowrap;
}

/* ---------- result rows ---------- */

#results-list { display: flex; flex-direction: column; gap: 10px; }

.result {
  display: flex; gap: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 20px;
  transition: border-color var(--ease), box-shadow var(--ease), transform var(--ease);
  animation: rowIn 200ms ease backwards;
}
.result:hover { border-color: var(--accent); box-shadow: var(--shadow); }

@keyframes rowIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.r-body { flex: 1 1 auto; min-width: 0; }

.r-title {
  margin: 0 0 5px;
  font-family: var(--font-display);
  font-size: 17.5px; font-weight: 700; letter-spacing: -0.005em; line-height: 1.4;
}
.r-title a { color: var(--ink); text-decoration: none; transition: color var(--ease); }
.r-title a:hover { color: var(--accent); text-decoration: underline; text-decoration-thickness: 1.5px; text-underline-offset: 3px; }

.r-meta {
  margin: 0; font-size: 13.5px; color: var(--muted); line-height: 1.5;
}

.r-signals {
  margin: 7px 0 0; font-size: 12.5px; color: var(--muted);
  display: flex; align-items: center; flex-wrap: wrap; gap: 7px;
  font-variant-numeric: tabular-nums;
}
.r-signals .sep { color: var(--faint); }
.sig { white-space: nowrap; }
span.sig[title] { cursor: help; border-bottom: 1px dotted var(--faint); }

.badge {
  display: inline-block; padding: 2px 10px;
  font-size: 11px; font-weight: 700; letter-spacing: 0.04em;
  color: var(--accent); background: var(--accent-soft);
  border-radius: 999px; white-space: nowrap;
}
.badge-oa { color: var(--gold); background: var(--gold-soft); }

/* Tappable Scopus badge (title="" is hover-only, unreachable on touch). */
.badge-wrap { position: relative; display: inline-block; }
button.badge {
  font-family: inherit; border: none; cursor: pointer;
  transition: box-shadow var(--ease), transform 120ms ease;
}
button.badge-info:hover { box-shadow: 0 0 0 3px var(--accent-soft); }
button.badge-info:active { transform: scale(0.95); }

/* Tap-to-reveal info popovers: the touch-friendly replacement for
   hover-only title="" explanations. */
.info-wrap { position: relative; display: inline-flex; align-items: center; }
.fcheck-wrap { gap: 0; }
.info-dot {
  display: inline-flex; align-items: center; justify-content: center;
  width: 19px; height: 19px; margin-left: 7px; padding: 0;
  font-family: var(--font-display); font-style: italic;
  font-size: 11.5px; font-weight: 700; line-height: 1;
  color: var(--accent); background: var(--accent-soft);
  border: 1px solid var(--line); border-radius: 50%;
  cursor: pointer; flex: 0 0 auto;
  transition: border-color var(--ease), transform 120ms ease;
}
.info-dot:hover { border-color: var(--accent); }
.info-dot:active { transform: scale(0.9); }
.info-pop {
  display: none;
  position: absolute; z-index: 60;
  top: calc(100% + 9px); left: 0;
  width: max-content; max-width: min(250px, 72vw);
  padding: 11px 14px;
  font-size: 12.5px; font-weight: 400; font-style: normal; line-height: 1.55;
  letter-spacing: normal; text-transform: none; white-space: normal;
  text-align: left;
  color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 11px;
  box-shadow: var(--shadow-lg);
}
.info-wrap.open .info-pop,
.badge-wrap.open .info-pop { display: block; animation: fadeIn 160ms ease; }

/* Quiet per-row publication-type label ("Journal article", "Preprint", …). */
.ptype {
  font-size: 11px; font-weight: 700; letter-spacing: 0.05em;
  text-transform: uppercase; color: var(--faint); white-space: nowrap;
}
.tag {
  display: inline-block; padding: 2px 10px;
  font-size: 11px; font-weight: 600;
  color: var(--muted); border: 1px dashed var(--line);
  border-radius: 999px; white-space: nowrap;
}

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

/* Real button treatment: the actions must read as clickable at a glance,
   in both light and dark mode. */
.r-act {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 7px;
  font-family: inherit; font-size: 13px; font-weight: 600;
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--line);
  padding: 9px 15px;
  border-radius: 999px; cursor: pointer; white-space: nowrap;
  transition: background var(--ease), border-color var(--ease),
    color var(--ease), box-shadow var(--ease), transform 120ms ease;
}
.r-act:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-deep);
  box-shadow: 0 2px 8px rgba(15, 118, 110, 0.16);
}
.r-act:active { transform: scale(0.96); }
.r-act.on {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-deep);
}
.r-act:disabled { opacity: 0.5; cursor: default; box-shadow: none; }

/* The PDF download reads as the primary action: filled accent button
   with a download arrow. */
.r-act.pdf-btn {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}
.r-act.pdf-btn::before { content: "\2193"; font-weight: 700; }
.r-act.pdf-btn:hover {
  background: var(--accent-deep);
  border-color: var(--accent-deep);
  color: var(--on-accent);
  box-shadow: 0 2px 10px rgba(15, 118, 110, 0.32);
}

.r-act-static {
  font-size: 13px; color: var(--faint); padding: 9px 4px;
  white-space: nowrap;
}

.r-side {
  flex: 0 0 auto; display: flex; flex-direction: column; align-items: flex-end;
  padding-top: 2px; min-width: 74px;
}
.r-num {
  font-size: 19px; font-weight: 700; color: var(--gold);
  font-variant-numeric: tabular-nums; letter-spacing: -0.01em;
}
.r-lbl { font-size: 11px; color: var(--faint); text-transform: lowercase; }

/* Compact inline citation count: shown on mobile where .r-side is hidden. */
.r-cites-inline { display: none; }

.abstract {
  display: none;
  margin-top: 12px; padding: 14px 16px;
  font-size: 14.5px; line-height: 1.65; color: var(--ink);
  background: var(--surface-2);
  border-left: 3px solid var(--accent);
  border-radius: 0 10px 10px 0;
}
.abstract.open { display: block; animation: fadeIn 200ms ease; }
.abstract em { color: var(--muted); }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.no-results {
  text-align: center; padding: 44px 24px; color: var(--muted);
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); font-size: 15px;
}
.nr-big {
  font-family: var(--font-display);
  font-size: 20px; font-weight: 700; color: var(--ink);
  margin: 0 0 10px;
}
.nr-sub { margin: 0 0 16px; }
.nr-tips { text-align: left; display: inline-block; margin: 6px 0 0; padding-left: 22px; }
.nr-tips li { margin: 7px 0; }

/* ---------- pagination ---------- */

.pager {
  display: flex; align-items: center; justify-content: center;
  flex-wrap: wrap; gap: 6px; margin: 16px 0;
}
.pager-top { margin: 0 0 12px; justify-content: flex-end; }
.pg-btn {
  padding: 6px 11px; font: inherit; font-size: 13px; font-weight: 600;
  color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px; cursor: pointer;
  transition: border-color var(--ease), color var(--ease);
}
.pg-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent-deep); }
.pg-btn.active { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.pg-btn:disabled { opacity: 0.35; cursor: default; }
.pg-info { font-size: 13px; color: var(--muted); padding: 0 6px; }
.pg-gap { color: var(--faint); padding: 0 2px; }

/* ---------- active filter chips ---------- */

.active-filters {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  margin-top: 10px; padding: 4px 6px;
}
.fchip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 11px; font: inherit; font-size: 12.5px; font-weight: 600;
  color: var(--accent-deep); background: var(--accent-soft);
  border: 1px solid var(--accent); border-radius: 999px; cursor: pointer;
}
.fchip:hover { background: rgba(15, 118, 110, 0.18); }
.fchip-clear {
  border: none; background: none; padding: 5px 8px;
  font: inherit; font-size: 12.5px; font-weight: 600;
  color: var(--danger); cursor: pointer;
}
.fchip-clear:hover { text-decoration: underline; }

/* ---------- enrich progress note ---------- */

.enrich-note {
  display: flex; align-items: center; gap: 9px;
  margin: 2px 0 12px; font-size: 13px; color: var(--muted);
}
.enrich-note::before {
  content: ""; width: 13px; height: 13px; flex: 0 0 auto;
  border-radius: 50%; border: 2px solid var(--line);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- toast ---------- */

.toast {
  position: fixed; left: 50%; bottom: 26px;
  transform: translate(-50%, 14px);
  max-width: calc(100vw - 48px);
  padding: 11px 18px; border-radius: 10px;
  background: var(--ink); color: var(--bg);
  font-size: 14px; font-weight: 600; text-align: center;
  box-shadow: var(--shadow-lg);
  opacity: 0; pointer-events: none;
  transition: opacity var(--ease), transform var(--ease);
  z-index: 80;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- crumb sub-line ---------- */

.crumb-sub { font-size: 12.5px; color: var(--muted); }

/* ---------- footer ---------- */

.site-footer { border-top: 1px solid var(--line); }
.foot-brand {
  margin: 0; padding: 26px 0 34px; text-align: center;
  font-size: 11px; font-weight: 700;
  letter-spacing: 0.34em; text-indent: 0.34em; text-transform: lowercase;
  color: var(--faint);
}

/* ---------- focus ---------- */

button:focus-visible, a:focus-visible, input:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

/* ---------- responsive ---------- */

@media (max-width: 640px) {
  .wrap { padding: 0 16px; }

  /* Mobile header: two compact rows — centered wordmark with the theme
     toggle pinned right and vertically centered (row 1), small centered
     tagline underneath (row 2). The hero masthead stays hidden on small
     screens; the slim bar + search panel is the whole header. */
  .slim-bar { padding-bottom: 7px; }
  .slim-inner {
    display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
    min-height: 46px; padding-top: 6px; padding-bottom: 2px;
  }
  .slim-title { grid-column: 2; justify-self: center; font-size: 16px; gap: 8px; }
  .slim-mark { width: 22px; height: 22px; }
  .slim-bar .theme-toggle { grid-column: 3; justify-self: end; }
  .slim-tagline {
    display: block; margin: 0; padding: 0 44px;
    text-align: center; font-family: var(--font-display);
    font-size: 12px; line-height: 1.3; color: var(--muted);
  }
  .site-header { display: none; }
  .theme-toggle { padding: 7px 10px; }
  .theme-toggle .tt-label { display: none; } /* icon-only on small screens */

  .search-panel { padding: 20px 18px; margin-top: 20px; }
  .search-row { flex-direction: column; }
  .btn-primary { padding: 13px 20px; width: 100%; }
  /* Breathing room for the year/citation fields; hide cramped spinners. */
  .search-grid { grid-template-columns: 1fr 1fr; gap: 14px; }
  .field { gap: 7px; }
  .field input { padding: 11px 12px; }
  .field input[type="number"]::-webkit-outer-spin-button,
  .field input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none; margin: 0;
  }
  .field input[type="number"] { -moz-appearance: textfield; appearance: textfield; }

  /* Sort control becomes a labeled, anchored band — the strip scrolls
     inside clear visual boundaries instead of floating. */
  .tb-top { flex-direction: column; align-items: stretch; }
  .tb-actions { width: 100%; }
  .sort-band {
    display: flex; align-items: center; gap: 10px;
    flex: 1 1 100%; min-width: 0;
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 7px 7px 7px 14px;
  }
  .sort-label {
    display: block; flex: 0 0 auto;
    font-size: 11px; font-weight: 700;
    letter-spacing: 0.08em; text-transform: uppercase;
    color: var(--muted);
  }
  .seg-scroll {
    flex: 1 1 auto; min-width: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -webkit-mask-image: linear-gradient(90deg, #000 86%, transparent 100%);
    mask-image: linear-gradient(90deg, #000 86%, transparent 100%);
  }
  .seg-scroll::-webkit-scrollbar { display: none; }
  .seg { display: inline-flex; }
  .sources-note { margin-left: 0; }

  /* Topic chips: one tidy scrollable row, never a wall of wraps. */
  .topic-chips {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 14px;
  }
  .topic-chips::-webkit-scrollbar { display: none; }
  .topic-chip {
    flex: 0 0 auto;
    max-width: 72vw;
    overflow: hidden; text-overflow: ellipsis;
  }

  /* Snowball banner stacks cleanly on narrow screens. */
  .crumb { flex-direction: column; align-items: stretch; gap: 10px; }
  .crumb-back { align-self: flex-start; }

  /* Tighter result rows; citation count stays visible inline. */
  #results-list { gap: 8px; }
  .result { padding: 12px 14px; gap: 12px; }
  .r-side { display: none; }
  .r-cites-inline {
    display: inline-block;
    margin-left: 9px;
    font-size: 12px; font-weight: 700; white-space: nowrap;
    color: var(--gold); font-variant-numeric: tabular-nums;
  }
  .r-title { font-size: 16px; }
  .r-meta { font-size: 13px; }
  .r-actions { margin-top: 8px; gap: 8px; }
  .ffield input[type="text"] { width: 130px; }
  /* 44px minimum touch targets for the row actions on mobile. */
  .r-act { min-height: 44px; padding: 10px 17px; }
  /* Pager stays compact on mobile: top pager centers, buttons shrink. */
  .pager-top { justify-content: center; }
  .pg-btn { padding: 7px 10px; font-size: 12.5px; }
  .pg-info { font-size: 12.5px; }
}
