/* LitSynth — royal red on warm paper. Fluid from 320px phones to wide monitors. */

:root {
  --paper: #F8F6F6;
  --surface: #FFFFFF;
  --surface-2: #F3EEEF;
  --ink: #241B1D;
  --muted: #6E6264;
  --faint: #9C9193;
  --rule: #ECE5E6;
  --rule-strong: #DCD1D3;
  --accent: #AB2330;          /* royal red: text, focus, active states */
  --accent-fill: #AB2330;     /* button backgrounds */
  --accent-hover: #8F1D28;
  --accent-soft: rgba(171, 35, 48, 0.07);
  --accent-tint: rgba(171, 35, 48, 0.14);
  --accent-strong-tint: rgba(171, 35, 48, 0.26);
  --on-accent: #FFFFFF;
  --ok: #1D7A52;
  --ok-soft: rgba(29, 122, 82, 0.1);
  --warn: #9A5B00;
  --warn-soft: rgba(154, 91, 0, 0.1);
  --danger: #B42318;
  --danger-soft: rgba(180, 35, 24, 0.08);
  --bar: #241B1D;
  --on-bar: #FFFFFF;

  --serif: "Source Serif 4", Georgia, "Times New Roman", serif;
  --sans: "Figtree", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
  --shadow-pop: 0 12px 32px rgba(36, 27, 29, 0.16), 0 2px 6px rgba(36, 27, 29, 0.08);
  --topbar-h: 60px;
  --gutter: clamp(12px, 3vw, 32px);
  --control-h: 36px;
  --page-max: 1280px;
}

[data-theme="dark"] {
  --paper: #141011;
  --surface: #1D1718;
  --surface-2: #282022;
  --ink: #F2ECEC;
  --muted: #B8ACAE;
  --faint: #887C7E;
  --rule: #33292B;
  --rule-strong: #463A3C;
  --accent: #EC7A84;
  --accent-fill: #C0303D;
  --accent-hover: #D23F4C;
  --accent-soft: rgba(236, 122, 132, 0.1);
  --accent-tint: rgba(236, 122, 132, 0.18);
  --accent-strong-tint: rgba(236, 122, 132, 0.34);
  --ok: #5CC99A;
  --ok-soft: rgba(92, 201, 154, 0.12);
  --warn: #E3B35B;
  --warn-soft: rgba(227, 179, 91, 0.12);
  --danger: #F2877D;
  --danger-soft: rgba(242, 135, 125, 0.12);
  --bar: #F2ECEC;
  --on-bar: #1D1718;
  --shadow-pop: 0 12px 32px rgba(0, 0, 0, 0.55);
  color-scheme: dark;
}

@media (min-width: 1600px) { :root { --page-max: 1440px; } }

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  min-width: 320px;
  background: var(--paper);
  color: var(--ink);
  font: 400 15px/1.55 var(--sans);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
body.no-scroll { overflow: hidden; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
p { margin: 0; }
a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }
button, input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
::selection { background: var(--accent-strong-tint); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.icon { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.only-mobile { display: none !important; }

/* ---------- Buttons & controls ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: var(--control-h); padding: 0 14px;
  border: 1px solid var(--rule-strong); border-radius: var(--r-md);
  background: var(--surface); color: var(--ink);
  font-weight: 600; font-size: 14px; white-space: nowrap; cursor: pointer; text-decoration: none;
  transition: background .15s, border-color .15s, color .15s;
  touch-action: manipulation;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; pointer-events: none; }
.btn-primary { background: var(--accent-fill); border-color: var(--accent-fill); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-quiet { border-color: transparent; background: transparent; color: var(--muted); }
.btn-quiet:hover { background: var(--surface-2); color: var(--ink); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-sm { height: 30px; padding: 0 10px; font-size: 13px; border-radius: var(--r-sm); }
.btn-block { width: 100%; }
.icon-btn {
  display: inline-grid; place-items: center; width: var(--control-h); height: var(--control-h);
  border: 0; border-radius: var(--r-md); background: transparent; color: var(--muted); cursor: pointer; flex-shrink: 0;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.link-btn { border: 0; background: none; padding: 0; color: var(--accent); font-weight: 600; font-size: 13px; cursor: pointer; }
.link-btn:hover { text-decoration: underline; }

.input, .select {
  height: var(--control-h); width: 100%; min-width: 0; padding: 0 10px;
  border: 1px solid var(--rule-strong); border-radius: var(--r-md); background: var(--surface);
}
.select { padding-right: 26px; cursor: pointer; text-overflow: ellipsis; }
.input:focus, .select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field-label { display: block; margin-bottom: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }

.check { display: flex; align-items: center; gap: 10px; padding: 4px 0; font-size: 14px; cursor: pointer; }
.check input { width: 16px; height: 16px; margin: 0; accent-color: var(--accent-fill); cursor: pointer; flex-shrink: 0; }

.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 14px; cursor: pointer; }
.switch input { appearance: none; width: 36px; height: 22px; margin: 0; border-radius: 99px; background: var(--rule-strong); position: relative; cursor: pointer; transition: background .15s; flex-shrink: 0; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch input:checked { background: var(--accent-fill); }
.switch input:checked::after { transform: translateX(14px); }

/* Horizontal swipe rows used on narrow screens */
.scroll-x { display: flex; gap: 8px; overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.scroll-x::-webkit-scrollbar { display: none; }

/* ---------- Top bar ---------- */

.topbar {
  position: sticky; top: 0; z-index: 40; height: var(--topbar-h);
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px;
  padding: 0 var(--gutter); padding-top: env(safe-area-inset-top);
  box-sizing: content-box;
  background: var(--surface); border-bottom: 1px solid var(--rule);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; color: var(--ink); text-decoration: none; justify-self: start; }
.brand img { height: 30px; width: auto; }
[data-theme="dark"] .brand img, [data-theme="dark"] .login-brand img { filter: invert(1) brightness(1.4); }
.brand span { font: 600 21px/1 var(--serif); letter-spacing: -0.01em; }

.steps { display: flex; align-items: center; gap: 2px; height: 100%; }
.step {
  position: relative; display: flex; align-items: center; gap: 8px; height: 100%; padding: 0 12px;
  color: var(--muted); font-weight: 600; font-size: 14px; text-decoration: none; white-space: nowrap;
}
.step:hover { color: var(--ink); }
.step-n {
  display: grid; place-items: center; width: 22px; height: 22px; border-radius: 50%;
  border: 1.5px solid currentColor; font-size: 12px; font-weight: 700;
}
.step[aria-current="page"] { color: var(--accent); }
.step[aria-current="page"]::after { content: ""; position: absolute; left: 12px; right: 12px; bottom: -1px; height: 2px; border-radius: 2px; background: var(--accent-fill); }
.step[aria-current="page"] .step-n { background: var(--accent-fill); border-color: var(--accent-fill); color: #fff; }
.step-count { min-width: 20px; padding: 1px 6px; border-radius: 99px; background: var(--surface-2); color: var(--muted); font-size: 12px; text-align: center; }
.step[aria-current="page"] .step-count { background: var(--accent-tint); color: var(--accent); }
.step-sep { width: 18px; height: 1px; background: var(--rule-strong); }

.topbar-end { display: flex; align-items: center; gap: 4px; justify-self: end; }
.account { position: relative; }
.account-btn { display: flex; align-items: center; gap: 6px; height: var(--control-h); padding: 0 6px 0 4px; border: 0; border-radius: 99px; background: transparent; cursor: pointer; color: var(--muted); }
.account-btn:hover { background: var(--surface-2); }
.avatar { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--accent-tint); color: var(--accent); font-size: 12px; font-weight: 700; }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 200px; padding: 6px; z-index: 50;
  background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-md); box-shadow: var(--shadow-pop);
}
.menu-label { padding: 6px 10px 8px; margin-bottom: 4px; font-size: 13px; color: var(--muted); border-bottom: 1px solid var(--rule); overflow-wrap: anywhere; }
.menu-item { display: flex; align-items: center; gap: 8px; width: 100%; min-height: 36px; padding: 8px 10px; border: 0; border-radius: var(--r-sm); background: none; font-size: 14px; text-align: left; cursor: pointer; }
.menu-item:hover { background: var(--surface-2); }
.menu-theme { display: none; }

/* ---------- Page scaffolding ---------- */

.page { max-width: var(--page-max); margin: 0 auto; padding: clamp(18px, 3vw, 32px) var(--gutter) calc(110px + env(safe-area-inset-bottom)); }
.page-title { font: 600 clamp(23px, 1.4vw + 17px, 31px)/1.2 var(--serif); letter-spacing: -0.015em; overflow-wrap: anywhere; }
.page-sub { margin-top: 4px; color: var(--muted); }
.panel { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-lg); }

.empty { padding: clamp(32px, 6vw, 56px) 20px; text-align: center; color: var(--muted); }
.empty h2 { margin-bottom: 6px; font: 600 clamp(18px, 1vw + 14px, 20px)/1.3 var(--serif); color: var(--ink); }
.empty p { max-width: 42ch; margin: 0 auto; }
.empty .btn { margin-top: 16px; }
.empty-examples { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 14px; }

/* ---------- Search ---------- */

.search-hero { max-width: 1010px; margin: 4px auto clamp(18px, 3vw, 28px); }
.search-hero .page-title { text-align: center; margin-bottom: clamp(12px, 2vw, 18px); }
.searchbar {
  display: flex; align-items: center; gap: 8px; padding: 5px 5px 5px 14px;
  background: var(--surface); border: 1px solid var(--rule-strong); border-radius: 14px;
  box-shadow: 0 1px 2px rgba(36, 27, 29, 0.05);
}
.searchbar:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.searchbar > .icon { width: 20px; height: 20px; color: var(--faint); }
.searchbar input { flex: 1; min-width: 0; height: 44px; border: 0; background: transparent; font-size: 17px; outline: none; }
.searchbar input::placeholder { color: var(--faint); }
.searchbar .btn { height: 44px; padding: 0 22px; font-size: 15px; }

.source-toggles { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px; margin-top: 12px; }
.source-toggles-label { font-size: 13px; color: var(--muted); margin-right: 2px; white-space: nowrap; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 11px; flex-shrink: 0;
  border: 1px solid var(--rule-strong); border-radius: 99px; background: var(--surface);
  color: var(--muted); font-size: 13px; font-weight: 600; white-space: nowrap; cursor: pointer; transition: all .15s;
  touch-action: manipulation;
}
.chip .icon { width: 13px; height: 13px; display: none; }
.chip:hover { border-color: var(--accent); color: var(--ink); }
.chip[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent-tint); color: var(--accent); }
.chip[aria-pressed="true"] .icon { display: block; }
.chip:disabled { opacity: .45; cursor: not-allowed; text-decoration: line-through; }
.chip:disabled:hover { border-color: var(--rule-strong); color: var(--muted); }
.empty-examples .chip, .ask-examples .chip { height: auto; min-height: 30px; padding: 5px 12px; white-space: normal; text-align: left; line-height: 1.35; flex-shrink: 1; max-width: 100%; }
.chip-divider { width: 1px; height: 18px; background: var(--rule-strong); margin: 0 4px; flex-shrink: 0; }

.search-body { display: grid; grid-template-columns: clamp(210px, 19vw, 260px) minmax(0, 1fr); gap: clamp(20px, 2.5vw, 36px); align-items: start; }

.filters { position: sticky; top: calc(var(--topbar-h) + 20px); }
.filters-panel { display: flex; flex-direction: column; }
.filters-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.filters-head h2 { font-size: 15px; font-weight: 700; }
.filters-head-actions { display: flex; align-items: center; gap: 8px; }
.filters-body { min-height: 0; }
.filter-group { padding: 12px 0; border-top: 1px solid var(--rule); }
.filter-group:first-child { border-top: 0; padding-top: 0; }
.filter-group > summary { display: flex; align-items: center; justify-content: space-between; min-height: 24px; list-style: none; cursor: pointer; font-size: 13px; font-weight: 600; color: var(--muted); }
.filter-group > summary::-webkit-details-marker { display: none; }
.filter-group > summary .icon { transition: transform .15s; }
.filter-group[open] > summary { margin-bottom: 6px; }
.filter-group[open] > summary .icon { transform: rotate(180deg); }
.filter-count { margin-left: 6px; color: var(--accent); }
.year-row { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 6px; }
.year-row span { color: var(--faint); font-size: 13px; }
.scroll-list { max-height: 210px; overflow: auto; margin-right: -6px; padding-right: 6px; }
.sheet-foot, .filters-toggle, .sheet-backdrop { display: none; }

.results-toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; min-height: 36px; margin-bottom: 10px; }
.results-status { color: var(--muted); font-size: 14px; min-width: 0; }
.results-status strong { color: var(--ink); }
.results-controls { display: flex; align-items: center; gap: 8px; }
.results-controls label { font-size: 13px; color: var(--muted); }
.results-controls .select { width: auto; height: 32px; font-size: 13px; }

.progress { height: 3px; border-radius: 99px; background: var(--surface-2); overflow: hidden; margin-bottom: 10px; }
.progress-fill { height: 100%; width: 0; background: var(--accent-fill); border-radius: inherit; transition: width .4s ease; }

.source-status { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.source-pill {
  display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 10px; flex-shrink: 0;
  border-radius: 99px; background: var(--surface-2); color: var(--muted); font-size: 12.5px; font-weight: 500; white-space: nowrap;
}
.source-pill b { font-weight: 700; }
.source-pill.is-done { background: var(--ok-soft); color: var(--ok); }
.source-pill.is-failed { background: var(--warn-soft); color: var(--warn); cursor: help; }
.source-pill .icon { width: 12px; height: 12px; }
/* Pills for sources that returned papers double as result filters. */
button.source-pill { border: 0; cursor: pointer; transition: background .15s, color .15s, box-shadow .15s; }
button.source-pill:hover { box-shadow: inset 0 0 0 1px currentColor; }
button.source-pill[aria-pressed="true"] { background: var(--accent-fill); color: var(--on-accent); box-shadow: none; }
.spinner { display: inline-block; width: 11px; height: 11px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin .7s linear infinite; flex-shrink: 0; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Paper list */

.paper-list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-lg); overflow: hidden; }
.paper { display: grid; grid-template-columns: 20px minmax(0, 1fr) auto; gap: 8px 14px; padding: clamp(14px, 1.6vw, 18px) clamp(14px, 1.8vw, 20px); border-top: 1px solid var(--rule); transition: background .15s; }
.paper:first-child { border-top: 0; }
.paper.is-selected { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent-fill); }
.paper.is-provisional { opacity: .8; }
.paper.is-excluded .paper-body { opacity: .6; }
.paper-check { padding-top: 3px; }
.paper-check input { width: 18px; height: 18px; margin: 0; accent-color: var(--accent-fill); cursor: pointer; }
.paper-body { min-width: 0; }
.paper-title { font: 600 clamp(16px, 0.4vw + 14.5px, 18px)/1.35 var(--serif); letter-spacing: -0.005em; overflow-wrap: anywhere; }
.paper-title a { color: var(--ink); text-decoration: none; }
.paper-title a:hover { color: var(--accent); text-decoration: underline; }
.paper-byline { display: flex; flex-wrap: wrap; column-gap: 12px; row-gap: 2px; margin-top: 4px; font-size: 13.5px; color: var(--muted); }
.paper-byline .authors { color: var(--ink); }
.paper-abstract { margin-top: 8px; font-size: 14px; color: var(--muted); max-width: 78ch; overflow-wrap: anywhere; }
.paper-abstract .link-btn { margin-left: 4px; }
.paper-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; margin-top: 10px; font-size: 12.5px; color: var(--muted); }
.tag { display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: var(--r-sm); background: var(--surface-2); color: var(--muted); font-weight: 600; white-space: nowrap; }
.tag-query { display: inline-block; max-width: min(34ch, 100%); overflow: hidden; text-overflow: ellipsis; line-height: 20px; background: transparent; border: 1px dashed var(--rule-strong); }
.paper-foot a { display: inline-flex; align-items: center; gap: 4px; font-weight: 600; text-decoration: none; white-space: nowrap; }
.paper-foot a:hover { text-decoration: underline; }
.paper-foot .icon { width: 13px; height: 13px; }
.paper-action { display: flex; align-items: flex-start; gap: 4px; }
.saved-mark { display: inline-flex; align-items: center; gap: 5px; height: 30px; padding: 0 10px; border-radius: var(--r-sm); background: var(--accent-soft); color: var(--accent); font-size: 13px; font-weight: 600; white-space: nowrap; }

.pager { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 4px; margin-top: 18px; }
.pager button { display: inline-grid; place-items: center; min-width: 36px; height: 36px; padding: 0 8px; border: 1px solid transparent; border-radius: var(--r-sm); background: transparent; color: var(--muted); font-weight: 600; cursor: pointer; }
.pager button:hover:not(:disabled) { background: var(--surface); border-color: var(--rule); color: var(--ink); }
.pager button[aria-current="page"] { background: var(--accent-fill); color: #fff; }
.pager button:disabled { opacity: .35; cursor: default; }
.pager-gap { color: var(--faint); padding: 0 2px; }

.list-sentinel { height: 1px; }
.skeleton { padding: 18px 20px; border-top: 1px solid var(--rule); }
.skeleton:first-child { border-top: 0; }
.skeleton i { display: block; height: 12px; margin-top: 10px; border-radius: 4px; background: linear-gradient(90deg, var(--surface-2), var(--rule), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.4s infinite; }
.skeleton i:first-child { height: 16px; width: 70%; margin-top: 0; }
.skeleton i:nth-child(2) { width: 40%; }
.skeleton i:last-child { width: 85%; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* Bottom action bar */

.action-bar {
  position: fixed; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 30;
  transform: translateX(-50%); max-width: calc(100vw - 24px);
  display: flex; align-items: center; gap: 12px; padding: 8px 8px 8px 16px;
  background: var(--bar); color: var(--on-bar); border-radius: 14px; box-shadow: var(--shadow-pop);
  animation: rise .2s ease-out;
}
.action-bar-text { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.action-bar .btn-quiet { color: inherit; opacity: .7; }
.action-bar .btn-quiet:hover { opacity: 1; background: rgba(128, 128, 128, 0.2); }
.action-bar .btn-primary { flex-shrink: 0; }
@keyframes rise { from { opacity: 0; transform: translate(-50%, 8px); } }

/* ---------- Collection ---------- */

.collection-layout { display: grid; grid-template-columns: clamp(210px, 19vw, 260px) minmax(0, 1fr); gap: clamp(20px, 2.5vw, 36px); align-items: start; }
.query-rail { position: sticky; top: calc(var(--topbar-h) + 20px); min-width: 0; }
.query-rail h2 { font-size: 13px; font-weight: 600; color: var(--muted); margin: 0 0 8px 10px; }
.query-list { display: flex; flex-direction: column; gap: 2px; margin-bottom: 14px; }
.query-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; width: 100%; min-height: 38px;
  padding: 8px 10px; border: 0; border-radius: var(--r-md); background: transparent; text-align: left; cursor: pointer;
}
.query-item:hover { background: var(--surface-2); }
.query-item[aria-current="true"] { background: var(--surface); box-shadow: inset 0 0 0 1px var(--rule), inset 3px 0 0 var(--accent-fill); }
.query-item[aria-current="true"] .query-name { color: var(--accent); }
.query-name { min-width: 0; font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.query-meta { font-size: 12px; color: var(--muted); white-space: nowrap; }

.upload { margin-bottom: 12px; }
.upload > summary {
  display: flex; align-items: center; gap: 10px; padding: 12px 16px; cursor: pointer; list-style: none;
  font-size: 14px; color: var(--muted);
}
.upload > summary::-webkit-details-marker { display: none; }
.upload > summary:hover { color: var(--ink); }
.upload > summary > .icon:first-child { color: var(--accent); }
.upload-title { font-weight: 600; color: var(--ink); white-space: nowrap; }
.upload-hint { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-chevron { margin-left: auto; color: var(--faint); transition: transform .15s; }
.upload[open] > summary { border-bottom: 1px solid var(--rule); }
.upload[open] .upload-chevron { transform: rotate(180deg); }
.upload-form { padding: 16px; }

.dropzone {
  position: relative; display: grid; place-items: center; gap: 6px; padding: 20px 16px; text-align: center; cursor: pointer;
  border: 1.5px dashed var(--rule-strong); border-radius: var(--r-md); background: var(--surface-2);
  font-size: 14px; color: var(--muted); transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.is-over { border-color: var(--accent); background: var(--accent-soft); }
/* The input covers the whole zone so it handles both the click and the drop. */
.dropzone input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.dropzone-link { color: var(--accent); font-weight: 600; text-decoration: underline; }
.dropzone.has-files { border-style: solid; border-color: var(--accent-tint); background: var(--accent-soft); color: var(--ink); }

.upload-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 14px; margin-top: 14px; }
.upload-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 10px 14px; margin-top: 14px; }
.upload-status { flex: 1 1 200px; min-width: 0; font-size: 13.5px; color: var(--muted); }
.upload-status.is-error { color: var(--danger); }
.upload-form .progress { margin: 14px 0 0; }

.collection-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 8px 16px; margin-bottom: 14px; }
.collection-head > div:first-child { min-width: 0; flex: 1 1 320px; }
.collection-head .page-title { display: flex; align-items: center; gap: 4px; font-size: clamp(21px, 1vw + 16px, 27px); }
.collection-head-actions { display: flex; flex-wrap: wrap; gap: 2px; }
.toolbar { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 8px; margin-bottom: 12px; }
.search-mini { position: relative; min-width: 0; }
.search-mini .icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--faint); pointer-events: none; }
.search-mini .input { padding-left: 32px; }
.toolbar .select { width: auto; max-width: 190px; }

/* ---------- Synthesis ---------- */

.synth-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px 16px; margin-bottom: 16px; }
.synth-head > div:first-child { min-width: 0; }
.synth-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.dropdown { position: relative; }

.segmented { display: inline-flex; padding: 3px; margin-bottom: 16px; background: var(--surface-2); border-radius: var(--r-md); }
.segmented button { height: 32px; padding: 0 16px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); font-weight: 600; font-size: 14px; white-space: nowrap; cursor: pointer; }
.segmented button[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(36, 27, 29, 0.12); }

.synth-layout { display: grid; grid-template-columns: minmax(0, 1fr) clamp(270px, 24vw, 340px); gap: clamp(18px, 2.2vw, 28px); align-items: start; }
.synth-layout.is-single { grid-template-columns: minmax(0, 1fr); }
.report { padding: clamp(20px, 3.2vw, 40px) clamp(18px, 3.6vw, 48px); }
.report-meta { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 12px; padding-bottom: 14px; margin-bottom: 4px; border-bottom: 1px solid var(--rule); font-size: 13px; color: var(--muted); }
.report-section { scroll-margin-top: calc(var(--topbar-h) + 16px); border-bottom: 1px solid var(--rule); }
.report-section:last-child { border-bottom: 0; }
.report-section > summary {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 16px 0; cursor: pointer; list-style: none;
  font: 600 clamp(19px, 0.6vw + 16px, 22px)/1.3 var(--serif); color: var(--ink);
}
.report-section > summary::-webkit-details-marker { display: none; }
.report-section > summary .icon { transition: transform .15s; color: var(--faint); }
.report-section[open] > summary .icon { transform: rotate(180deg); }
.report-section > summary:hover { color: var(--accent); }
.report-section > .report-body { padding-bottom: 20px; }
.report-body { font: 400 clamp(15.5px, 0.2vw + 15px, 16.5px)/1.7 var(--serif); max-width: 70ch; overflow-wrap: anywhere; }
.report-body ul { margin: 0; padding-left: 20px; }
.report-body li { margin: 0 0 10px; padding-left: 2px; }
.report-body li::marker { color: var(--faint); }
.report-body p { margin: 0 0 12px; }
.cite {
  display: inline-block; min-width: 18px; margin: 0 1px; padding: 0 4px; border: 0; border-radius: 3px;
  background: var(--accent-tint); color: var(--accent);
  font: 700 12px/1.55 var(--sans); vertical-align: 1px; cursor: pointer; transition: background .15s, color .15s;
}
.cite:hover, .cite.is-active { background: var(--accent-fill); color: #fff; }
.cite.is-invalid { background: transparent; color: var(--faint); text-decoration: line-through; cursor: help; }

.status-box { padding: clamp(20px, 3vw, 28px) clamp(18px, 3.6vw, 44px); }
.status-box .progress { margin: 12px 0 0; }
.status-msg { color: var(--muted); }
.status-msg strong { color: var(--ink); }
.status-msg .spinner { vertical-align: -1px; margin-right: 8px; }
.notice { margin-top: 12px; padding: 10px 14px; border-radius: var(--r-md); background: var(--surface-2); font-size: 14px; color: var(--muted); }
.notice.is-error { background: var(--danger-soft); color: var(--danger); }

.source-rail { position: sticky; top: calc(var(--topbar-h) + 20px); max-height: calc(100dvh - var(--topbar-h) - 40px); overflow: auto; padding: 16px 14px; }
.source-rail h2 { font-size: 15px; font-weight: 700; }
.coverage { margin: 2px 0 12px; font-size: 13px; color: var(--muted); }
.source-list { list-style: none; margin: 0; padding: 0; }
.source-item { display: grid; grid-template-columns: 26px minmax(0, 1fr); gap: 4px; padding: 10px 8px; border-radius: var(--r-md); transition: background .2s, box-shadow .2s; scroll-margin: 20px; }
.source-item.is-active { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent-fill); }
.source-n { font: 700 13px/1.5 var(--sans); color: var(--accent); }
.source-title { font: 600 14px/1.4 var(--serif); overflow-wrap: anywhere; }
.source-title a { color: var(--ink); text-decoration: none; }
.source-title a:hover { text-decoration: underline; }
.source-where { margin-top: 2px; font-size: 12px; color: var(--muted); }
.source-item.is-uncited .source-title, .source-item.is-uncited .source-n { color: var(--muted); }
.source-where .uncited { color: var(--warn); font-weight: 600; }

.ask { padding: clamp(18px, 3vw, 28px) clamp(16px, 3vw, 32px); }
.ask-row { display: flex; gap: 8px; }
.ask-row .input { height: 44px; font-size: 16px; }
.ask-row .btn { height: 44px; }
.ask-examples { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.ask-answer { margin-top: 20px; padding-top: 20px; border-top: 1px solid var(--rule); }
.ask-answer h3 { font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 8px; }

/* ---------- Toasts & dialogs ---------- */

.toasts { position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 60; display: flex; flex-direction: column; gap: 8px; max-width: calc(100vw - 32px); }
.toast { width: min(380px, 100%); padding: 10px 14px; border-radius: var(--r-md); background: var(--surface); border: 1px solid var(--rule); border-left: 3px solid var(--ok); box-shadow: var(--shadow-pop); font-size: 14px; animation: slide .2s ease-out; }
.toast.is-error { border-left-color: var(--danger); }
@keyframes slide { from { opacity: 0; transform: translateY(8px); } }

dialog.dialog { width: min(440px, calc(100vw - 24px)); padding: 0; border: 1px solid var(--rule); border-radius: var(--r-lg); background: var(--surface); color: var(--ink); box-shadow: var(--shadow-pop); }
dialog.dialog::backdrop { background: rgba(20, 16, 17, 0.45); }
.dialog form { padding: 20px; }
.dialog h2 { font: 600 20px/1.3 var(--serif); margin-bottom: 6px; overflow-wrap: anywhere; }
.dialog p { color: var(--muted); }
.dialog .input { margin-top: 12px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

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

.login-body { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 20px; background: #EEE9EA url("bg.jpg") center / cover no-repeat; }
.login-card { width: min(380px, 100%); padding: clamp(26px, 5vw, 36px) clamp(20px, 5vw, 32px); background: var(--surface); border-radius: 18px; box-shadow: 0 30px 70px rgba(36, 27, 29, 0.2), 0 2px 8px rgba(36, 27, 29, 0.06); border-top: 4px solid var(--accent-fill); }
.login-brand { display: flex; flex-direction: column; align-items: center; gap: 8px; margin-bottom: 22px; text-align: center; }
.login-brand img { height: clamp(52px, 10vw, 64px); }
.login-brand h1 { font: 600 26px/1.2 var(--serif); }
.login-card .field { margin-bottom: 14px; }
.login-card .input { height: 44px; font-size: 16px; }
.login-card .btn { width: 100%; height: 44px; margin-top: 6px; }
.login-hint { margin-top: 16px; text-align: center; font-size: 12.5px; color: var(--faint); }
.login-error { margin-bottom: 14px; padding: 9px 12px; border-radius: var(--r-md); background: var(--danger-soft); color: var(--danger); font-size: 14px; }
.login-note { margin-bottom: 14px; padding: 9px 12px; border-radius: var(--r-md); background: var(--accent-soft); color: var(--accent); font-size: 14px; }
.field-row { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.field-hint { margin-top: 6px; font-size: 12.5px; color: var(--faint); }
.code-input { text-align: center; font-size: 22px; font-weight: 700; letter-spacing: 10px; text-indent: 10px; height: 52px; }

/* ---------- Accounts (admin) ---------- */

.step-admin .icon { width: 17px; height: 17px; }
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 14px; }
.stat { display: flex; flex-direction: column; gap: 2px; padding: 14px 16px; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-lg); }
.stat-value { font: 600 26px/1.1 var(--serif); }
.stat-label { font-size: 12.5px; color: var(--muted); }
.stat.is-warn { border-color: var(--warn); background: var(--warn-soft); }
.stat.is-warn .stat-value, .stat.is-warn .stat-label { color: var(--warn); }
.page-note { margin-top: 14px; font-size: 13px; color: var(--muted); }

.user-row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; align-items: center; gap: 10px 14px; padding: 14px clamp(14px, 1.8vw, 20px); border-top: 1px solid var(--rule); }
.user-row:first-child { border-top: 0; }
.user-row.is-waiting { background: var(--warn-soft); }
.user-avatar { width: 34px; height: 34px; font-size: 13px; }
.user-main { min-width: 0; }
.user-name { display: flex; align-items: center; gap: 8px; font-weight: 600; overflow-wrap: anywhere; }
.user-meta { margin-top: 2px; font-size: 12.5px; color: var(--muted); overflow-wrap: anywhere; }
.user-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag-waiting { background: transparent; border: 1px solid var(--warn); color: var(--warn); }
.user-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }

@media (max-width: 720px) {
  .user-row { grid-template-columns: auto minmax(0, 1fr); }
  .user-tags, .user-actions { grid-column: 2; }
}

/* =====================================================================
   Responsive
   ===================================================================== */

/* Tablet landscape / small laptop */
@media (max-width: 1100px) {
  .step-sep { width: 10px; }
  .step { padding: 0 10px; }
  .step[aria-current="page"]::after { left: 10px; right: 10px; }
}

/* Synthesis rail drops below the report */
@media (max-width: 960px) {
  .synth-layout { grid-template-columns: minmax(0, 1fr); }
  .source-rail { position: static; max-height: none; }
}

/* Tablet portrait and phones: single column */
@media (max-width: 860px) {
  :root { --topbar-h: 56px; }
  .brand span, .step-sep { display: none; }
  .search-body, .collection-layout { grid-template-columns: minmax(0, 1fr); gap: 12px; }

  /* Source toggles become one swipeable row */
  .source-toggles { flex-wrap: nowrap; justify-content: flex-start; overflow-x: auto; scrollbar-width: none; margin-inline: calc(var(--gutter) * -1); padding-inline: var(--gutter); }
  .source-toggles::-webkit-scrollbar { display: none; }
  .source-status { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .source-status::-webkit-scrollbar { display: none; }

  /* Filters open as a bottom sheet */
  .filters { position: static; }
  .filters-toggle { display: inline-flex; }
  .filters-panel {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 70;
    max-height: 86dvh; padding: 0 var(--gutter) calc(12px + env(safe-area-inset-bottom));
    background: var(--surface); border-radius: 18px 18px 0 0; box-shadow: var(--shadow-pop);
    transform: translateY(105%); visibility: hidden; transition: transform .25s ease, visibility 0s linear .25s;
  }
  .filters.is-open .filters-panel { transform: none; visibility: visible; transition: transform .25s ease; }
  .filters-head { position: sticky; top: 0; padding: 16px 0 12px; margin: 0; background: var(--surface); border-bottom: 1px solid var(--rule); }
  .filters-head::before { content: ""; position: absolute; top: 6px; left: 50%; width: 36px; height: 4px; margin-left: -18px; border-radius: 99px; background: var(--rule-strong); }
  .filters-body { overflow-y: auto; overscroll-behavior: contain; padding-top: 12px; }
  .sheet-foot { display: block; padding-top: 12px; border-top: 1px solid var(--rule); }
  .sheet-backdrop { display: block; position: fixed; inset: 0; z-index: 65; background: rgba(20, 16, 17, 0.45); opacity: 0; pointer-events: none; transition: opacity .25s; }
  .filters.is-open .sheet-backdrop { opacity: 1; pointer-events: auto; }
  .only-mobile { display: inline-grid !important; }
  .scroll-list { max-height: none; }

  .results-toolbar { align-items: flex-start; }
  .results-controls { width: 100%; }
  .results-controls .select { flex: 1; }

  /* Collection: saved searches become a swipeable row */
  .query-rail { position: static; }
  .query-rail h2, .query-rail > .btn { display: none; }
  .query-list { flex-direction: row; overflow-x: auto; scrollbar-width: none; margin: 0 calc(var(--gutter) * -1); padding: 2px var(--gutter); }
  .query-list::-webkit-scrollbar { display: none; }
  .query-item { width: auto; flex-shrink: 0; max-width: 72vw; min-height: 34px; padding: 6px 12px; border-radius: 99px; background: var(--surface); box-shadow: inset 0 0 0 1px var(--rule); }
  .query-item[aria-current="true"] { background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent-tint); }

  .action-bar { left: var(--gutter); right: var(--gutter); transform: none; max-width: none; justify-content: space-between; }
  @keyframes rise { from { opacity: 0; transform: translateY(8px); } }
}

/* Phones */
@media (max-width: 560px) {
  body { font-size: 15px; }
  .topbar { grid-template-columns: auto minmax(0, 1fr) auto; gap: 6px; }
  .brand img { height: 26px; }
  .steps { justify-self: center; }
  .step { gap: 5px; padding: 0 7px; font-size: 13.5px; }
  .step-n { display: none; }
  .step[aria-current="page"]::after { left: 6px; right: 6px; }
  #theme-btn { display: none; }
  .menu-theme { display: flex; }
  .step-admin .step-label { display: none; }   /* the icon carries it on phones */
  .account-btn .icon { display: none; }

  .search-hero .page-title { font-size: 22px; }
  .searchbar { padding: 4px 4px 4px 12px; border-radius: 12px; }
  .searchbar > .icon { display: none; }
  .searchbar input { height: 42px; font-size: 16px; }
  .searchbar .btn { height: 42px; padding: 0 14px; }
  .source-toggles-label { display: none; }

  .input, .select { font-size: 16px; }   /* stops iOS zooming into fields */
  .results-controls label { display: none; }

  .paper { grid-template-columns: 22px minmax(0, 1fr); }
  .paper-action { grid-column: 2; }
  .paper-action .btn { height: 34px; padding: 0 16px; }
  .paper-byline { font-size: 13px; }

  .toolbar { grid-template-columns: 1fr 1fr; }
  .toolbar .search-mini { grid-column: 1 / -1; }
  .upload-fields { grid-template-columns: minmax(0, 1fr); }
  .upload-hint { display: none; }
  .upload-foot .btn { width: 100%; }
  .toolbar .select { width: 100%; max-width: none; }
  .collection-head-actions { width: 100%; margin-left: -10px; }

  .synth-actions { width: 100%; display: grid; grid-template-columns: 1fr 1fr; }
  .synth-actions #run-btn { grid-column: 1 / -1; order: -1; height: 42px; }
  .synth-actions .btn, .synth-actions .dropdown, .synth-actions .dropdown .btn { width: 100%; }
  .segmented { display: flex; }
  .segmented button { flex: 1; }
  .ask-row .btn { padding: 0 16px; }

  .action-bar { padding: 6px 6px 6px 14px; gap: 8px; }
  .action-bar-text { font-size: 13.5px; }
  .toasts { left: 12px; right: 12px; bottom: calc(76px + env(safe-area-inset-bottom)); }
  .toast { width: 100%; }
  .dialog-actions .btn { flex: 1; }
}

/* Very small phones */
@media (max-width: 360px) {
  .step { padding: 0 5px; font-size: 12.5px; }
  .step-count { display: none; }
  #clear-selection { display: none; }
  .searchbar .btn { padding: 0 10px; }
}

/* Touch devices: larger hit areas */
@media (pointer: coarse) {
  :root { --control-h: 40px; }
  .btn-sm { height: 36px; }
  .chip { height: 34px; padding: 0 13px; }
  .check { padding: 7px 0; }
  .check input { width: 20px; height: 20px; }
  .paper-check input { width: 22px; height: 22px; }
  .paper { grid-template-columns: 24px minmax(0, 1fr) auto; }
  .cite { min-width: 22px; padding: 1px 6px; }
}
@media (pointer: coarse) and (max-width: 560px) {
  .paper { grid-template-columns: 24px minmax(0, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
