/* LitSynth: risograph. Two inks, red and blue, overprinting on cream stock:
   the look of two sources overlapping into one reading. Square corners,
   2px ink rules, hard offset shadows. Fluid from 320px phones to wide monitors. */

:root {
  --paper: #F4EFE3;
  --surface: #F8F4EA;
  --surface-2: #EBE4D4;
  --ink: #1E1B18;
  --muted: #6B6459;
  --faint: #6B6459;
  --rule: #CFC6B5;
  --rule-strong: #1E1B18;
  --riso-red: #C8321F;
  --riso-blue: #2C4E9E;
  --red-tint: #FAEEEA;
  --blue-tint: #D5DCEB;
  --accent: #C8321F;
  --accent-fill: #C8321F;
  --accent-hover: #A92816;
  --accent-soft: #FAEEEA;
  --accent-tint: #E9BDB2;
  --accent-strong-tint: #E2A597;
  --on-accent: #FFFFFF;
  --on-blue: #FFFFFF;
  --ok: #2C4E9E;
  --ok-soft: #D5DCEB;
  --warn: #8A5300;
  --warn-soft: #F2E1C2;
  --danger: #B42A1E;
  --danger-soft: #FAEEEA;
  --bar: #1E1B18;
  --on-bar: #F4EFE3;
  --sl-gold: #C8321F;
  --sl-gold-tint: #FAEEEA;

  /* Depth is ink, not blur: a hard offset shadow under a 2px ink box. */
  --shadow-xs: none;
  --shadow-sm: 2px 2px 0 var(--shade);
  --shadow-md: 3px 3px 0 var(--shade);
  --shadow-pop: 4px 4px 0 var(--shade);
  --shadow-blue: none;   /* the blue offset shadow was dropped as distracting */
  --glass-surface: var(--surface);
  --glass-border: var(--ink);

  --transition-fast: 120ms cubic-bezier(.2, .7, .2, 1);
  --transition: 180ms cubic-bezier(.2, .7, .2, 1);

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

  color-scheme: light;

  --r-sm: 0;
  --r-md: 0;
  --r-lg: 0;
  --topbar-h: 72px;
  --gutter: clamp(14px, 3vw, 40px);
  --control-h: 38px;
  --page-max: 1320px;
  --line: 1.5px solid var(--ink);
  --shade: color-mix(in srgb, var(--ink) 72%, transparent);

  /* Former glass tokens, kept by name so every page adopts the riso stock. */
  --glass-fill: var(--surface);
  --glass-fill-strong: var(--surface);
  --glass-soft: transparent;
  --glass-soft-hover: var(--surface-2);
  --glass-edge: transparent;
  --glass-line: var(--ink);
  --glass-divider: var(--rule);
  --glass-shade: var(--shadow-pop);
  --glass-blur: none;
  --field-fill: #FBF8F1;
  --grain-opacity: 0.16;
}

[data-theme="dark"] {
  --paper: #1A1815;
  --surface: #211E1A;
  --surface-2: #2C2823;
  --ink: #EFE8DA;
  --muted: #B3AA9C;
  --faint: #B3AA9C;
  --rule: #3A352E;
  --rule-strong: #EFE8DA;
  --riso-red: #FF6A58;
  --riso-blue: #7C9CF0;
  --red-tint: #4A2620;
  --blue-tint: #26304A;
  --accent: #FF6A58;
  --accent-fill: #FF6A58;
  --accent-hover: #FF8575;
  --accent-soft: #4A2620;
  --accent-tint: #5C2C24;
  --accent-strong-tint: #74372D;
  --on-accent: #1A1815;
  --on-blue: #1A1815;
  --ok: #7C9CF0;
  --ok-soft: #26304A;
  --warn: #E3B35B;
  --warn-soft: #3D3120;
  --danger: #FF8575;
  --danger-soft: #4A2620;
  --bar: #EFE8DA;
  --on-bar: #1A1815;
  --sl-gold: #FF6A58;
  --sl-gold-tint: #4A2620;
  --field-fill: #1E1B17;
  --grain-opacity: 0.12;
  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: none; text-decoration-thickness: 1px; text-underline-offset: 2px; transition: color var(--transition-fast); }
a:hover { text-decoration: underline; }
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; }

/* ---------- 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(--field-fill); color: var(--ink); box-shadow: var(--shadow-xs);
  font-weight: 600; font-size: 14px; white-space: nowrap; cursor: pointer; text-decoration: none;
  transition: background var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast), box-shadow var(--transition-fast), transform var(--transition-fast);
  touch-action: manipulation;
}
.btn:hover { background: var(--glass-soft-hover); box-shadow: var(--shadow-sm); transform: translateY(-1px); text-decoration: none; }
.btn:active { transform: translateY(0); box-shadow: var(--shadow-xs); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; pointer-events: none; transform: none; box-shadow: none; }
.btn.is-loading { opacity: .85; cursor: wait; pointer-events: none; transform: none; }
.btn.is-loading .spinner { margin-right: 7px; vertical-align: -1px; }
.btn.is-success {
  opacity: 1; pointer-events: none; transform: none; color: var(--ok);
  background: var(--ok-soft); border-color: transparent; box-shadow: none;
  animation: btn-pop .3s ease;
}
.btn.is-success .icon { color: var(--ok); margin-right: 4px; }
@keyframes btn-pop { 0% { transform: scale(1); } 45% { transform: scale(1.045); } 100% { transform: scale(1); } }
.btn-primary { background-color: var(--accent-fill); background-image: linear-gradient(180deg, var(--accent-fill), var(--accent-hover)); border-color: var(--accent-fill); color: var(--on-accent); }
/* Keep the red fill on hover: the generic .btn:hover background is more
   specific than .btn-primary, and would leave white text on a light fill. */
.btn-primary:hover { background-color: var(--accent-fill); background-image: linear-gradient(180deg, var(--accent-fill), var(--accent-hover)); border-color: var(--accent-fill); color: var(--on-accent); filter: brightness(1.06); }
.btn-primary:active { filter: brightness(0.97); }
.btn-quiet { border-color: var(--rule); background: transparent; color: var(--muted); box-shadow: none; }
.btn-quiet:hover { background: var(--surface-2); color: var(--ink); border-color: var(--rule-strong); box-shadow: none; transform: none; }
.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: 1px solid transparent; border-radius: var(--r-md); background: transparent; color: var(--muted); cursor: pointer; flex-shrink: 0;
  transition: background var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast);
}
.icon-btn:hover { background: var(--glass-soft-hover); border-color: var(--rule); color: var(--ink); }
.link-btn { border: 0; background: none; padding: 0; color: var(--accent); font-weight: 600; font-size: 13px; cursor: pointer; transition: color var(--transition-fast); }
.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(--field-fill);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.select { padding-right: 26px; cursor: pointer; text-overflow: ellipsis; }
.select option, .select optgroup { background-color: var(--surface); color: var(--ink); }
.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); }

/* ---------- 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;
  border-bottom: 1px solid var(--glass-line);
}
.topbar::before {
  content: ""; position: absolute; inset: 0; z-index: -1; pointer-events: none;
  background: var(--glass-fill-strong);
  -webkit-backdrop-filter: var(--glass-blur); backdrop-filter: var(--glass-blur);
}
.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 {
  display: flex; align-items: center; gap: 8px; height: var(--control-h); padding: 0 12px;
  border-radius: 99px; color: var(--muted); font-weight: 600; font-size: 14px; text-decoration: none; white-space: nowrap;
  transition: background var(--transition-fast), color var(--transition-fast);
}
.step:hover { color: var(--ink); background: var(--surface-2); }
.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;
  transition: background var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast);
}
.step[aria-current="page"] { color: var(--accent); background: var(--accent-soft); }
.step[aria-current="page"]:hover { background: var(--accent-soft); }
.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); }
.step-icon { display: none; }

.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(--glass-surface); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border); 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; transition: background var(--transition-fast); }
.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(--glass-fill); border: 1px solid var(--glass-line); border-radius: 18px;
  box-shadow: inset 0 1px 0 var(--glass-edge), var(--glass-shade);
  -webkit-backdrop-filter: var(--glass-blur); backdrop-filter: var(--glass-blur);
}

.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: 7px 7px 7px 18px;
  background: var(--glass-fill-strong); border: 1px solid var(--glass-line); border-radius: 22px;
  box-shadow: inset 0 1px 0 var(--glass-edge), 0 34px 70px -34px rgba(171, 35, 48, 0.5), var(--glass-shade);
  -webkit-backdrop-filter: var(--glass-blur); backdrop-filter: var(--glass-blur);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.searchbar .btn { border-radius: 15px; }
.searchbar:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft), inset 0 1px 0 var(--glass-edge), 0 34px 70px -34px rgba(171, 35, 48, 0.5), var(--glass-shade);
}
.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; }
.searchbar .filters-toggle { padding: 0 16px; border-color: transparent; background: transparent; color: var(--muted); box-shadow: none; }
.searchbar .filters-toggle:hover { background: var(--glass-soft-hover); color: var(--ink); box-shadow: none; transform: none; }
.searchbar .filters-toggle .icon { width: 16px; height: 16px; }

.source-toggles { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px 20px; margin-top: 12px; }
.source-pick {
  display: inline-flex; align-items: center; gap: 8px; height: 34px; padding: 0 12px;
  border: 1px solid var(--rule-strong); border-radius: 99px; background: var(--surface);
  color: var(--ink); font-size: 13.5px; font-weight: 600; cursor: pointer;
  transition: border-color var(--transition-fast), background var(--transition-fast);
}
.source-pick .icon { width: 15px; height: 15px; color: var(--accent); }
.source-pick .icon:last-child { width: 14px; height: 14px; color: var(--muted); transition: transform var(--transition-fast); }
.source-pick:hover:not(:disabled), .source-pick[aria-expanded="true"] { border-color: var(--accent); }
.source-pick:disabled { cursor: default; color: var(--muted); }
.source-pick:disabled .icon:last-child { display: none; }
.filter-hint { margin: 6px 0 0; font-size: 12.5px; line-height: 1.45; color: var(--muted); }
.source-pick[aria-expanded="true"] .icon:last-child { transform: rotate(180deg); }
.source-menu { left: 0; right: auto; min-width: 250px; }
.source-menu-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 4px 10px 8px; margin-bottom: 4px; border-bottom: 1px solid var(--rule); font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.source-menu-head .link-btn { text-transform: none; letter-spacing: 0; }
.source-option { display: flex; align-items: center; gap: 10px; min-height: 38px; padding: 6px 10px; border-radius: var(--r-sm); font-size: 14px; color: var(--ink); cursor: pointer; }
.source-option:hover { background: var(--surface-2); }
.source-option input { width: 16px; height: 16px; margin: 0; accent-color: var(--accent-fill); cursor: pointer; }
.source-option.is-off { opacity: .5; cursor: not-allowed; }
.source-collection { justify-content: flex-start; font-size: 13.5px; font-weight: 500; color: var(--muted); }
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 11px; flex-shrink: 0;
  border: 1px solid var(--glass-line); border-radius: 99px; background: var(--glass-soft);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  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 { height: auto; min-height: 30px; padding: 5px 12px; white-space: normal; text-align: left; line-height: 1.35; flex-shrink: 1; max-width: 100%; }

/* Filters live in a modal triggered from the search bar at every width, so
   results always get the page's full measure instead of sharing it with a
   permanent sidebar. Small screens get the same modal anchored to the
   bottom edge instead (see the phone/tablet media query below). */
.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 .2s;
}
.filters.is-open .sheet-backdrop { opacity: 1; pointer-events: auto; }
.filters-panel {
  position: fixed; left: 50%; top: 50%; z-index: 70; width: min(440px, calc(100vw - 32px)); max-height: 82dvh;
  display: flex; flex-direction: column; padding: 18px;
  background: var(--glass-surface); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border); border-radius: var(--r-lg); box-shadow: var(--shadow-pop);
  transform: translate(-50%, -50%) scale(.97); opacity: 0; visibility: hidden;
  transition: transform .18s ease, opacity .18s ease, visibility 0s linear .18s;
}
.filters.is-open .filters-panel { transform: translate(-50%, -50%) scale(1); opacity: 1; visibility: visible; transition: transform .18s ease, opacity .18s ease; }
.filters-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 14px; flex-shrink: 0; }
.filters-head h2 { font-size: 15px; font-weight: 700; }
.filters-head-actions { display: flex; align-items: center; gap: 8px; }
.filters-body { min-height: 0; overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain; margin: 0 -18px; padding: 0 18px; }
.filter-group { padding-bottom: 12px; }
.filter-group + .filter-group { padding-top: 12px; border-top: 1px solid var(--rule); }
.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); }

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

.sheet-foot { flex-shrink: 0; padding-top: 14px; margin-top: 4px; border-top: 1px solid var(--rule); }

.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 { position: relative; height: 3px; border-radius: 99px; background: var(--glass-soft); overflow: hidden; margin-bottom: 10px; }
/* Scaled, not resized: animating width relayouts the bar on every frame. */
.progress-fill { position: absolute; inset: 0; background: var(--accent-fill); border-radius: inherit; transform: scaleX(0); transform-origin: left center; transition: transform .4s ease; }

/* Search progress: one segment per real stage of a search, so the wait while
   ranking finishes reads as work rather than as a frozen page. Deliberately
   the same bar, shuttle and settle as the synthesis loader's track, so the
   app's two waits look like one design. Only the active segment animates. */
.track { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; margin: 0 0 10px; padding: 0; list-style: none; }
.track-seg { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.track-bar { position: relative; display: block; height: 4px; border-radius: 99px; background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--rule); overflow: hidden; }
/* The fill spans the bar and is scaled down, so progress moves on the
   compositor. Animating width instead would relayout the bar every frame. */
.track-fill { position: absolute; inset: 0; border-radius: inherit; background: var(--accent-fill); transform: scaleX(0); transform-origin: left center; transition: transform .5s ease; }
.track-seg.is-done .track-fill { transform: scaleX(1); }

/* Both long stages report a real fraction, so the bar shows actual progress.
   Only "Merging duplicates" is unmeasurable, and it is brief: it gets a short
   fill that breathes, rather than a shuttle pretending to be progress. */
.track-seg.is-current:not(.is-measured) .track-fill { transform: scaleX(.18); animation: track-waiting 1.6s ease-in-out infinite; }
@keyframes track-waiting { 0%, 100% { opacity: .4; } 50% { opacity: 1; } }

.track-label { font-size: 12px; font-weight: 500; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transition: color .3s; }
.track-seg.is-done .track-label { color: var(--muted); }
.track-seg.is-current .track-label { color: var(--accent); font-weight: 600; }
.track.is-settled .track-fill { background: var(--ok); }
.track.is-settled .track-label { color: var(--muted); }

/* A saved card settles into place instead of being rebuilt underneath you. */
.paper.is-saved .saved-mark { animation: saved-settle .35s cubic-bezier(.2, .8, .2, 1) both; }
@keyframes saved-settle { from { opacity: 0; transform: scale(.85); } to { opacity: 1; transform: scale(1); } }

@media (prefers-reduced-motion: reduce) {
  .track-seg.is-current:not(.is-measured) .track-fill { transform: scaleX(.5); animation: none; }
  .track-fill, .track-label { transition: none; }
  .paper.is-saved .saved-mark { animation: none; }
}

.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(--glass-soft); 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; overflow: hidden;
  background: var(--glass-fill); border: 1px solid var(--glass-line); border-radius: 18px;
  box-shadow: inset 0 1px 0 var(--glass-edge), var(--glass-shade);
  -webkit-backdrop-filter: var(--glass-blur); backdrop-filter: var(--glass-blur);
}
.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(--glass-divider); transition: background .15s; }
.paper:first-child { border-top: 0; }
.paper.is-selected { background: var(--accent-soft); box-shadow: inset 0 0 0 1.5px 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-check input:disabled { cursor: not-allowed; }
.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; }
/* Why the ranker placed a paper where it did: its 0-100 score and the model's
   own one-line reason. Full border, no single-sided rule. */
.paper-relevance { display: flex; align-items: baseline; gap: 7px; margin: 7px 0 0; font-size: 12.5px; line-height: 1.5; color: var(--muted); }
.relevance-score { flex: none; min-width: 30px; padding: 1px 7px; border: 1px solid var(--rule-strong); border-radius: 99px; background: var(--surface-2); color: var(--ink); font-size: 11px; font-weight: 700; text-align: center; }
.paper.is-provisional .paper-relevance { display: none; }

.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(--glass-soft-hover); border-color: var(--glass-line); 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(--glass-divider); }
.skeleton:first-child { border-top: 0; }
.skeleton i { display: block; height: 12px; margin-top: 10px; border-radius: 4px; background: linear-gradient(90deg, var(--glass-soft), var(--glass-soft-hover), var(--glass-soft)); 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: color-mix(in srgb, var(--bar) 84%, transparent); color: var(--on-bar); border-radius: 16px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12), var(--shadow-pop);
  -webkit-backdrop-filter: blur(18px) saturate(160%); backdrop-filter: blur(18px) saturate(160%);
  animation: rise .2s ease-out;
}
.action-bar-text { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.action-bar-hint { display: block; font-size: 12px; opacity: .72; overflow: hidden; text-overflow: ellipsis; }
.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 { max-width: 1040px; margin: 0 auto; }

/* Your searches: a button by the title that opens a list, rather than a sidebar.
   Names wrap to two lines instead of being cut off; the count is a small
   badge; the current one is tinted, not ringed. */
.collection-head-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.collection-head-actions .btn .icon { width: 15px; height: 15px; color: var(--accent); }
.query-total:not(:empty) { min-width: 20px; padding: 0 6px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); font-size: 12px; line-height: 18px; text-align: center; }
.query-chevron { transition: transform var(--transition-fast); }
#queries-toggle[aria-expanded="true"] .query-chevron { transform: rotate(180deg); }
.queries-menu { width: min(340px, calc(100vw - 32px)); max-height: min(60dvh, 460px); overflow-y: auto; padding: 6px; }
/* When the header wraps, the button sits at the left edge: open the list from there. */
@media (max-width: 700px) { .queries-menu { left: 0; right: auto; } }
.query-list { display: flex; flex-direction: column; gap: 2px; }
.query-item {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; width: 100%; min-height: 40px;
  padding: 9px 10px; border: 0; border-radius: var(--r-md); background: transparent; color: var(--ink);
  text-align: left; cursor: pointer; transition: background var(--transition-fast), color var(--transition-fast);
}
.query-item:hover { background: var(--surface-2); }
.query-item:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.query-item[aria-current="true"] { background: var(--accent-soft); color: var(--accent); }
.query-name {
  min-width: 0; font-size: 14px; font-weight: 500; line-height: 1.35; overflow-wrap: anywhere;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.query-item.is-all .query-name, .query-item[aria-current="true"] .query-name { font-weight: 650; }
.query-count {
  flex: none; min-width: 24px; margin-top: 1px; padding: 1px 7px; border-radius: 99px; background: var(--surface-2);
  color: var(--muted); font-size: 12px; font-weight: 600; text-align: center; font-variant-numeric: tabular-nums;
}
.query-item[aria-current="true"] .query-count { background: var(--accent-fill); color: var(--on-accent); }
.query-divider { height: 1px; margin: 6px 10px; background: var(--rule); }
.query-new {
  display: flex; align-items: center; gap: 8px; margin-top: 6px; padding: 10px; border-top: 1px solid var(--rule);
  border-radius: 0 0 var(--r-sm) var(--r-sm); color: var(--accent); font-size: 14px; font-weight: 600; text-decoration: none;
}
.query-new .icon { width: 16px; height: 16px; }
.query-new:hover { background: var(--accent-soft); text-decoration: none; }

/* Add your own papers: a small button by the title, the form in a modal. */
.collection-head { align-items: center; }
.upload-open .icon { width: 15px; height: 15px; color: var(--accent); }
dialog.dialog.upload-dialog { width: min(640px, calc(100vw - 24px)); max-height: min(88dvh, 820px); overflow: auto; }
.upload-dialog-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 20px 20px 0; }
.upload-dialog-head h2 { margin: 0 0 4px; font: 600 20px/1.3 var(--serif); }
.upload-dialog-head p { margin: 0; font-size: 14px; color: var(--muted); }
.upload-dialog .upload-form { padding: 16px 20px 20px; }
.upload-dialog .input { margin-top: 0; }   /* the shared dialog style spaces a lone input; this form lays out its own */

.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: 14px; background: var(--glass-soft);
  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); }

.dropzone-hint { font-size: 12.5px; color: var(--faint); }
.upload-topic { margin-bottom: 14px; }

/* One card per file, each with the same Title / Authors / Year fields. */
.upload-list { display: grid; gap: 10px; margin: 14px 0 0; padding: 0; list-style: none; }
.upload-item { padding: 12px 14px 14px; border: 1px solid var(--glass-line); border-radius: 14px; background: var(--glass-soft); animation: upload-in 180ms ease; }
@keyframes upload-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.upload-item-head { display: flex; align-items: center; gap: 8px; min-width: 0; margin-bottom: 10px; font-size: 14px; }
.upload-item-head > .icon { flex: none; color: var(--accent); }
.upload-item-name { min-width: 0; font-weight: 600; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-item-size { flex: none; font-size: 12.5px; color: var(--faint); }
.upload-item-remove { flex: none; margin-left: auto; }
.upload-fields { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1.4fr) minmax(0, .6fr); gap: 10px 12px; }
.upload-item-error { margin: 10px 0 0; font-size: 13px; color: var(--danger); }
.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); }
.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; }

/* Collection actions: one visible button style for all of them, grouped by what
   they do; only Remove carries colour, and only on its icon until hovered. */
.list-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; margin: 0 0 16px; }
.list-actions-group { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.list-actions .btn { height: 34px; padding: 0 12px; }
.list-actions .btn .icon { width: 15px; height: 15px; color: var(--accent); flex: none; }
.list-actions .btn:hover { border-color: var(--accent); }
.list-actions .btn-remove .icon { color: var(--danger); }
.list-actions .btn-remove:hover { border-color: var(--danger); background: var(--danger-soft); color: var(--danger); }
.list-actions-divider { width: 1px; height: 22px; background: var(--rule-strong); }
@media (max-width: 560px) {
  .list-actions, .list-actions-group { width: 100%; }
  .list-actions-group .btn { flex: 1 1 auto; }
  .list-actions-divider { display: none; }
}

/* ---------- 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; border: 1px solid var(--glass-line); border-radius: 12px; background: var(--glass-soft);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
}
.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; transition: background var(--transition-fast), color var(--transition-fast), box-shadow var(--transition-fast); }
.segmented button[aria-selected="true"] { background: var(--glass-fill-strong); color: var(--ink); box-shadow: var(--shadow-xs); }

.synth-layout { display: grid; grid-template-columns: minmax(0, 1fr) clamp(290px, 26vw, 370px); gap: clamp(18px, 2.2vw, 28px); align-items: start; }
.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(--glass-divider); font-size: 13px; color: var(--muted); }
.report-section { scroll-margin-top: calc(var(--topbar-h) + 16px); border-bottom: 1px solid var(--glass-divider); }
.report-section:last-child { border-bottom: 0; }
.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: 82ch; overflow-wrap: anywhere; }
.cite-run { white-space: nowrap; }

/* What to check before citing, collapsed under the report's date line. */
.report-notes { margin: 12px 0 4px; border: 1px solid color-mix(in srgb, var(--warn) 35%, transparent); border-radius: var(--r-md); background: var(--warn-soft); }
.report-notes > summary { display: flex; align-items: center; gap: 8px; padding: 9px 12px; list-style: none; cursor: pointer; font-size: 13.5px; font-weight: 600; color: var(--warn); }
.report-notes > summary::-webkit-details-marker { display: none; }
.report-notes > summary span { flex: 1; }
.report-notes > summary .icon { width: 16px; height: 16px; flex: none; }
.report-notes > summary .icon:last-child { transition: transform var(--transition-fast); }
.report-notes[open] > summary .icon:last-child { transform: rotate(180deg); }
.report-notes ul { margin: 0; padding: 0 14px 12px 36px; font-size: 13.5px; line-height: 1.55; color: var(--ink); }
.report-notes li + li { margin-top: 6px; }
.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; }
.synth-cancel { display: flex; justify-content: center; margin-top: 18px; }
.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-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 0 0 0 1.5px var(--accent-fill); }

.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 { color: var(--muted); }
.source-where .uncited { color: var(--warn); font-weight: 600; }
.source-item.source-paper { display: block; }
.page-chips { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 7px; }
.page-chip { display: inline-flex; align-items: center; gap: 5px; height: 24px; padding: 0 8px 0 3px; border: 1px solid var(--rule); border-radius: 99px; background: var(--surface); color: var(--ink); font-size: 12px; font-weight: 600; text-decoration: none; white-space: nowrap; transition: border-color var(--transition-fast), background var(--transition-fast); }
.page-chip b { display: grid; place-items: center; min-width: 18px; height: 18px; padding: 0 4px; border-radius: 99px; background: var(--accent-tint); color: var(--accent); font-size: 11px; }
a.page-chip:hover { border-color: var(--accent); color: var(--ink); text-decoration: none; }
.page-chip.is-active { border-color: var(--accent-fill); background: var(--accent-soft); }
.page-chip.is-active b { background: var(--accent-fill); color: var(--on-accent); }
.page-chip-section { color: var(--muted); font-weight: 500; }
/* Cited from the abstract of a paper whose full text was read. */
.page-chip.is-abstract { border-style: dashed; border-color: var(--warn); }
.page-chip.is-abstract .page-chip-section { color: var(--warn); }

/* Traced citations. Each cited page can show the claim the report makes, the
   sentence of that page which supports it, and how well the two matched.
   Every state keeps a full border on all four sides; the state itself is
   carried by the badge word and its tinted fill, never by colour alone. */
.evidence { margin-top: 6px; }
.evidence + .evidence { margin-top: 2px; }
.evidence > summary { display: flex; align-items: center; gap: 8px; padding: 4px 0; list-style: none; cursor: pointer; font-size: 12px; font-weight: 600; color: var(--muted); }
.evidence[open] { padding-bottom: 4px; }
.evidence > summary::-webkit-details-marker { display: none; }
.evidence > summary:hover { color: var(--ink); }
.evidence > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--r-md); }
.evidence-where { flex: 1; min-width: 0; }
.evidence > summary .icon { flex: none; width: 14px; height: 14px; color: var(--faint); transition: transform var(--transition-fast); }
.evidence[open] > summary .icon { transform: rotate(180deg); }
.evidence[open] > summary { border-bottom: 1px solid var(--rule); }

.evidence-badge { flex: none; padding: 1px 7px; border: 1px solid var(--rule-strong); border-radius: 99px; background: var(--surface-2); color: var(--muted); font-size: 11px; font-weight: 600; white-space: nowrap; }
.evidence.is-strong .evidence-badge { background: var(--ok-soft); color: var(--ok); border-color: color-mix(in srgb, currentColor 40%, transparent); }
.evidence.is-partial .evidence-badge { background: var(--warn-soft); color: var(--warn); border-color: color-mix(in srgb, currentColor 40%, transparent); }
.evidence.is-weak .evidence-badge, .evidence.is-untraced .evidence-badge { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, currentColor 40%, transparent); }

.evidence-body { padding: 8px 0 4px; }
.evidence-label { display: block; margin-bottom: 3px; font: 600 11.5px/1.3 var(--sans); color: var(--faint); }
.evidence-claim { margin: 0 0 8px; font-size: 12.5px; line-height: 1.5; color: var(--muted); }
.evidence-quote { margin: 0; padding: 8px 10px; border: 1px solid var(--rule); border-radius: var(--r-sm); background: var(--surface-2); font: 13px/1.55 var(--serif); color: var(--ink); overflow-wrap: anywhere; }
.evidence-quote mark { padding: 0 2px; border-radius: 3px; background: var(--accent-tint); color: inherit; }
.evidence-note { margin: 8px 0 0; font-size: 12px; line-height: 1.5; color: var(--warn); }
.evidence.is-weak .evidence-note, .evidence.is-untraced .evidence-note { color: var(--danger); }

.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-answer { margin-top: 20px; padding-top: 20px; border-top: 1px solid var(--glass-divider); }
.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%); display: flex; align-items: center; gap: 10px; padding: 10px 14px;
  border-radius: var(--r-md); background: var(--glass-surface); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border); box-shadow: var(--shadow-pop); font-size: 14px; animation: slide .2s ease-out;
}
.toast::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); flex-shrink: 0; }
.toast.is-error::before { background: var(--danger); }
.toast > span { flex: 1; min-width: 0; }
.toast-action { flex: none; min-height: 32px; padding: 0 10px; border: 1px solid var(--rule-strong); border-radius: var(--r-sm); background: var(--surface); color: var(--accent); font: 600 13px/1 var(--sans); cursor: pointer; }
.toast-action:hover { border-color: var(--accent); }
.tag-fetching { display: inline-flex; align-items: center; gap: 6px; }
.tag-fetching .spinner { width: 10px; height: 10px; border-width: 1.5px; }
@keyframes slide { from { opacity: 0; transform: translateY(8px); } }

dialog.dialog { width: min(440px, calc(100vw - 24px)); padding: 0; border: 1px solid var(--glass-border); border-radius: var(--r-lg); background: var(--glass-surface); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); 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; position: relative; overflow: hidden; background: var(--paper); }

.login-card { position: relative; z-index: 1; width: min(380px, 100%); padding: clamp(26px, 5vw, 36px) clamp(20px, 5vw, 32px); background: var(--surface); border: 1px solid var(--rule); border-radius: 18px; box-shadow: 0 30px 70px rgba(36, 27, 29, 0.2), 0 2px 8px rgba(36, 27, 29, 0.06); }
.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(--muted); }

/* River + glass variant — login.html only. Light is the default; dark
   follows the same data-theme attribute the rest of the app uses, so the
   in-page toggle (below) drives both the shader and this CSS together. */
.login-body.login-river {
  background:
    radial-gradient(ellipse 90% 60% at 22% 18%, rgba(171, 35, 48, 0.08), transparent 60%),
    radial-gradient(ellipse 80% 55% at 82% 88%, rgba(217, 138, 61, 0.14), transparent 58%),
    linear-gradient(160deg, #FBF8F6, #F1E4E1 55%, #FBF8F6);
  --rule-strong: rgba(36, 27, 29, 0.16);
}
[data-theme="dark"] .login-body.login-river {
  background:
    radial-gradient(ellipse 90% 60% at 22% 18%, rgba(171, 35, 48, 0.22), transparent 60%),
    radial-gradient(ellipse 80% 55% at 82% 88%, rgba(231, 166, 92, 0.14), transparent 58%),
    linear-gradient(160deg, #12151b, #1f2530 55%, #12151b);
  --rule: rgba(255, 255, 255, 0.14);
  --rule-strong: rgba(255, 255, 255, 0.24);
}
.login-river .login-card {
  background: linear-gradient(165deg, rgba(255, 255, 255, 0.55), rgba(255, 255, 255, 0.28));
  backdrop-filter: blur(20px) saturate(140%);
  -webkit-backdrop-filter: blur(20px) saturate(140%);
  border: 1px solid rgba(255, 255, 255, 0.6);
  border-top: 1px solid rgba(255, 255, 255, 0.85);
  box-shadow: 0 30px 70px rgba(36, 27, 29, 0.16), 0 1px 0 rgba(255, 255, 255, 0.5) inset;
}
[data-theme="dark"] .login-river .login-card {
  background: linear-gradient(165deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.04));
  backdrop-filter: blur(22px) saturate(140%);
  -webkit-backdrop-filter: blur(22px) saturate(140%);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-top: 1px solid rgba(255, 255, 255, 0.32);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45), 0 1px 0 rgba(255, 255, 255, 0.08) inset;
}
[data-theme="dark"] .login-river .login-brand img { filter: invert(1) brightness(1.5); }
.login-river .input { backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.login-river .input::placeholder { color: var(--faint); }
.login-river .btn-primary { box-shadow: 0 10px 24px rgba(171, 35, 48, 0.35); }

.theme-toggle {
  position: fixed; top: max(16px, env(safe-area-inset-top));
  right: max(16px, env(safe-area-inset-right)); z-index: 2;
  display: inline-grid; place-items: center; width: 38px; height: 38px;
  border-radius: 50%; border: 1px solid var(--rule-strong); background: var(--surface);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  color: var(--ink); cursor: pointer; transition: background .15s, border-color .15s;
}
.theme-toggle:hover { border-color: var(--accent); }
.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(--glass-fill); border: 1px solid var(--glass-line); border-radius: 16px;
  box-shadow: inset 0 1px 0 var(--glass-edge), var(--glass-shade);
  -webkit-backdrop-filter: var(--glass-blur); backdrop-filter: var(--glass-blur);
}
.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); }

.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(--glass-divider); }
.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; }
}

/* ---------- Admin: tabs, analytics, models ---------- */

.admin-tabs { margin-bottom: 16px; }
.stat-sub { margin-top: 2px; font-size: 12px; color: var(--faint); }
.admin-filter { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; margin-bottom: 14px; }
.admin-filter .segmented { margin-bottom: 0; }
.admin-notice { margin: 0 0 14px; }
.admin-view.is-refreshing .stat-row, .admin-view.is-refreshing .admin-panel { opacity: .55; transition: opacity .2s; }
.analytics-stats { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.admin-panel { margin-bottom: 14px; padding: clamp(16px, 2vw, 22px); }
.admin-panel-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 6px 16px; margin-bottom: 12px; }
.admin-panel-head h2 { font: 600 17px/1.3 var(--serif); }
.admin-panel-head p { margin-top: 2px; font-size: 13px; color: var(--muted); max-width: 70ch; }

/* Chart. Series colours are the validated categorical slots, stepped per theme. */
.admin-view {
  --series-1: #2a78d6; --series-2: #eb6834; --series-3: #1baf7a; --series-4: #eda100;
}
[data-theme="dark"] .admin-view {
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
}
.viz { position: relative; }
.viz-svg { display: block; max-width: 100%; height: auto; overflow: visible; }
.viz-grid { stroke: var(--glass-divider); stroke-width: 1; }
.viz-tick { fill: var(--muted); font: 500 11px/1 var(--sans); font-variant-numeric: tabular-nums; }
.viz-bar { transition: opacity .12s; }
.viz-column.is-active .viz-bar { opacity: .82; }
.viz-hit { fill: transparent; cursor: default; outline: none; }
.viz-hit:focus-visible { fill: var(--accent-soft); }
.viz-empty { position: absolute; inset: 0 0 26px 54px; display: grid; place-items: center; padding: 0 12px; text-align: center; font-size: 13.5px; color: var(--muted); pointer-events: none; }
.viz-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 0 0 10px; padding: 0; list-style: none; font-size: 12.5px; color: var(--muted); }
.viz-legend li { display: inline-flex; align-items: center; gap: 6px; }
.viz-swatch { width: 10px; height: 10px; border-radius: 3px; }
.viz-tooltip {
  position: absolute; z-index: 5; min-width: 150px; padding: 10px 12px; pointer-events: none;
  background: var(--glass-surface); border: 1px solid var(--glass-border); border-radius: 12px; box-shadow: var(--shadow-pop);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px); font-size: 12.5px;
}
.viz-tip-head { color: var(--muted); }
.viz-tip-total { margin: 1px 0 6px; font-size: 17px; font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums; }
.viz-tip-row { display: grid; grid-template-columns: 12px auto 1fr; align-items: center; gap: 6px; padding: 1px 0; color: var(--muted); }
.viz-tip-row strong { color: var(--ink); font-variant-numeric: tabular-nums; }
.viz-key { width: 12px; height: 3px; border-radius: 2px; }

/* Tables */
.table-wrap { overflow-x: auto; margin: 0 calc(clamp(16px, 2vw, 22px) * -1); padding: 0 clamp(16px, 2vw, 22px); }
.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.data-table th, .data-table td { padding: 9px 10px; border-top: 1px solid var(--glass-divider); text-align: left; vertical-align: top; white-space: nowrap; }
.data-table thead th { border-top: 0; padding-top: 4px; font-size: 12px; font-weight: 600; color: var(--muted); }
.data-table tbody th { font-weight: 600; color: var(--ink); }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table .strong { font-weight: 700; color: var(--ink); }
.data-table td { color: var(--muted); }
.table-sub { display: block; margin-top: 1px; font-size: 12px; font-weight: 400; color: var(--faint); }
.table-warn { color: var(--warn); font-weight: 600; }
.table-muted { color: var(--faint); }
.table-empty { padding: 18px 10px !important; text-align: center !important; color: var(--muted); white-space: normal !important; }

/* Models */
.lock-panel { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 24px; }
.lock-panel.is-locked { box-shadow: inset 0 0 0 1.5px var(--warn), inset 0 1px 0 var(--glass-edge), var(--glass-shade); }
.lock-copy { flex: 1 1 320px; min-width: 0; }
.lock-copy h2 { font: 600 17px/1.3 var(--serif); }
.lock-copy p { margin-top: 3px; font-size: 13.5px; color: var(--muted); max-width: 70ch; }
.lock-switch { gap: 12px; font-weight: 600; }
.limit-form { display: flex; align-items: center; gap: 8px; }
.limit-input { width: 88px; text-align: center; font-weight: 600; }
.model-options { display: grid; gap: 8px; }
.model-option {
  display: grid; grid-template-columns: 18px minmax(0, 1fr) auto; align-items: start; gap: 4px 12px; padding: 12px 14px;
  border: 1px solid var(--glass-line); border-radius: 14px; background: var(--glass-soft); cursor: pointer;
  transition: border-color var(--transition-fast), background var(--transition-fast);
}
.model-option:hover { background: var(--glass-soft-hover); }
.model-option.is-current { border-color: var(--accent-tint); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent-tint); }
.model-option input { width: 16px; height: 16px; margin: 3px 0 0; accent-color: var(--accent-fill); cursor: pointer; }
.model-main { display: grid; gap: 2px; min-width: 0; }
.model-name { font-weight: 700; color: var(--ink); }
.model-maker { margin-left: 4px; font-size: 12.5px; font-weight: 500; color: var(--muted); }
.model-current { height: 20px; margin-left: 6px; background: var(--accent-fill); color: #fff; font-size: 11.5px; }
.model-note { font-size: 13px; color: var(--muted); }
.model-id { font-size: 12px; color: var(--faint); overflow-wrap: anywhere; }
.model-price { display: grid; justify-items: end; gap: 1px; text-align: right; font-size: 12px; color: var(--muted); }
.model-price strong { font-size: 16px; color: var(--ink); font-variant-numeric: tabular-nums; }
.model-changed { margin-top: 10px; font-size: 12.5px; color: var(--faint); }

@media (max-width: 640px) {
  .admin-tabs { display: flex; }
  .admin-tabs button { flex: 1; }
  .admin-filter .range-picker { display: flex; width: 100%; }
  .admin-filter .range-picker button { flex: 1; padding: 0 6px; }
  .admin-filter > .btn { margin-left: auto; }
  .analytics-stats { grid-template-columns: 1fr 1fr; }
  .model-option { grid-template-columns: 18px minmax(0, 1fr); }
  .model-price { grid-column: 2; justify-items: start; text-align: left; grid-auto-flow: column; justify-content: start; align-items: baseline; gap: 8px; }
}

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

/* Tablet landscape / small laptop */
@media (max-width: 1100px) {
  .step-sep { width: 10px; }
  .step { padding: 0 10px; }
}

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

/* Tablet portrait and phones: single column */
@media (max-width: 860px) {
  :root { --topbar-h: 56px; }
  .brand span, .step-sep { display: none; }

  /* Source toggles become one swipeable row */
  .source-toggles { justify-content: space-between; }
  .source-status { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .source-status::-webkit-scrollbar { display: none; }

  /* Below tablet width the same filters modal anchors to the bottom edge
     as a sheet instead of floating centered — easier to reach one-handed. */
  .filters-panel {
    left: 0; right: 0; top: auto; bottom: 0; width: auto;
    max-height: 86dvh; padding: 0 var(--gutter) calc(12px + env(safe-area-inset-bottom));
    border-bottom: 0; border-radius: 18px 18px 0 0;
    transform: translateY(105%) scale(1); visibility: hidden; transition: transform .25s ease, opacity .25s ease, visibility 0s linear .25s;
  }
  .filters.is-open .filters-panel { transform: translateY(0) scale(1); visibility: visible; transition: transform .25s ease, opacity .25s ease; }
  .filters-head { position: sticky; top: 0; padding: 16px var(--gutter) 12px; margin: 0 calc(var(--gutter) * -1); background: var(--glass-surface); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); 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 { margin: 0; padding: 12px 0 0; }
  
  

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

  .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; }
  #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: 5px 5px 5px 14px; border-radius: 18px; }
  .searchbar .btn { border-radius: 13px; }
  .searchbar > .icon { display: none; }
  .searchbar input { height: 42px; font-size: 16px; }
  .searchbar .btn { height: 42px; padding: 0 14px; }
  .searchbar .filters-toggle { padding: 0 10px; }
  .searchbar .filters-toggle .btn-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) 96px; }
  .upload-field-title { grid-column: 1 / -1; }
  .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; }
}

/* ---------- Recent searches (reuses the Filters modal / bottom sheet) ---------- */
.recent-note { margin: -6px 0 12px; font-size: 13px; color: var(--muted); }
.recent-list { display: grid; gap: 6px; margin: 0; padding: 0 0 2px; list-style: none; }
.recent-item {
  display: flex; align-items: center; gap: 4px; padding-right: 4px;
  border: 1px solid var(--rule); border-radius: var(--r-md); background: var(--surface);
  transition: border-color var(--transition-fast), background var(--transition-fast);
}
.recent-item:hover { border-color: var(--rule-strong); }
.recent-item.is-current { border-color: var(--accent-tint); background: var(--accent-soft); }
.recent-item.is-loading { opacity: .6; pointer-events: none; }
.recent-open { display: grid; gap: 2px; flex: 1; min-width: 0; padding: 10px 12px; border: 0; background: none; text-align: left; cursor: pointer; }
.recent-question { font-size: 14.5px; font-weight: 600; color: var(--ink); overflow-wrap: anywhere; }
.recent-open:hover .recent-question { color: var(--accent); }
.recent-meta { font-size: 12.5px; color: var(--muted); }
.recent-meta strong { color: var(--accent); font-weight: 600; }
.recent-remove { flex: none; color: var(--faint); }
.recent-empty { display: flex; align-items: center; gap: 8px; padding: 18px 4px; font-size: 14px; color: var(--muted); }

/* ---------- Cite panel (reuses the Recent searches modal / bottom sheet) ---------- */
@media (min-width: 861px) { .cite-panel .filters-panel { width: min(680px, calc(100vw - 32px)); } }
.cite-styles { align-self: flex-start; max-width: 100%; overflow-x: auto; margin-bottom: 12px; flex-shrink: 0; }
.cite-styles button { padding: 0 12px; }
.cite-note { margin: 0 0 12px; font-weight: 400; }
.cite-list { display: grid; gap: 10px; margin: 0; padding: 0 0 4px; list-style: none; font-weight: 400; }
.cite-item { padding: 12px 14px; border: 1px solid var(--rule); border-radius: var(--r-md, 10px); background: var(--surface); }
.cite-ref { margin: 0; padding-left: 1.6em; text-indent: -1.6em; font-family: var(--serif); font-size: 15px; line-height: 1.55; color: var(--ink); overflow-wrap: anywhere; }
.cite-list.is-numbered .cite-ref { padding-left: 0; text-indent: 0; }
.cite-panel .filters-head h2 { color: var(--ink); }
.cite-note.is-warning { padding: 9px 12px; border-radius: var(--r-md); background: var(--warn-soft); color: var(--ink); }
.cite-item.is-incomplete { border-color: color-mix(in srgb, var(--warn) 45%, var(--rule)); }
.cite-check { display: flex; align-items: flex-start; gap: 6px; margin: 8px 0 0; font-size: 12.5px; line-height: 1.45; color: var(--warn); }
.cite-check .icon { flex: none; width: 14px; height: 14px; margin-top: 1px; }
.cite-foot { display: flex; justify-content: flex-end; gap: 8px; }

/* ---------------------------------------------------------------------------
   Phones: an app layout rather than a squeezed desktop one. The workflow
   steps leave the top bar and become a glass tab bar at the bottom, in thumb
   reach, so the top bar only carries the brand and the account. The search
   field gets a full row of its own, with its actions on a second row.
   --------------------------------------------------------------------------- */
@media (max-width: 640px) {
  :root { --tabbar-h: 64px; --tabbar-gap: calc(10px + env(safe-area-inset-bottom)); }

  .topbar { grid-template-columns: minmax(0, 1fr) auto; }
  .brand span { display: inline; font-size: 19px; }

  .steps {
    position: fixed; left: 10px; right: 10px; bottom: var(--tabbar-gap); z-index: 45;
    justify-self: stretch; width: auto;   /* a centred grid item would shrink to fit */
    height: var(--tabbar-h); justify-content: space-around; gap: 2px; padding: 6px;
    background: var(--glass-fill-strong); border: 1px solid var(--glass-line); border-radius: 24px;
    box-shadow: inset 0 1px 0 var(--glass-edge), 0 18px 40px -18px rgba(60, 12, 22, 0.45), var(--glass-shade);
    -webkit-backdrop-filter: var(--glass-blur); backdrop-filter: var(--glass-blur);
  }
  .step, .step-admin {
    position: relative; flex: 1 1 0; min-width: 0; flex-direction: column; justify-content: center; gap: 3px;
    height: 100%; padding: 0 4px; border-radius: 18px; font-size: 11.5px; letter-spacing: 0.01em;
  }
  .step-n, .step-sep { display: none; }
  .step-icon { display: grid; place-items: center; }
  .step .icon, .step-admin .icon { width: 21px; height: 21px; }
  .step-admin .step-label { display: inline; }
  .step-label { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
  .step[aria-current="page"] { background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent-tint); }
  .step-count {
    display: block; position: absolute; top: 5px; left: calc(50% + 7px); min-width: 17px; padding: 0 4px;
    font-size: 10.5px; line-height: 16px; background: var(--accent-fill); color: #fff;
  }
  .step[aria-current="page"] .step-count { background: var(--accent-fill); color: #fff; }

  /* Everything that sits at the bottom edge moves up above the tab bar. */
  .page { padding-bottom: calc(var(--tabbar-h) + 120px + env(safe-area-inset-bottom)); }
  .action-bar { bottom: calc(var(--tabbar-h) + var(--tabbar-gap) + 10px); }
  .toasts { bottom: calc(var(--tabbar-h) + var(--tabbar-gap) + 72px); }

  /* Search field on its own row; Recent, Filters and Search below it. */
  .search-hero { margin-top: 0; }
  .searchbar { flex-wrap: wrap; gap: 2px 4px; padding: 6px; border-radius: 22px; }
  .searchbar > .icon { display: block; margin-left: 10px; }
  .searchbar input { flex: 1 1 calc(100% - 40px); height: 46px; padding-right: 8px; font-size: 16px; }
  .searchbar .filters-toggle { height: 40px; padding: 0 12px; border-radius: 14px; }
  .searchbar .filters-toggle .btn-label { display: inline; }
  .searchbar #search-btn { height: 40px; margin-left: auto; padding: 0 24px; }

  /* Result and paper cards: actions tuck to the right under the text. */
  .paper { padding: 16px 14px; gap: 6px 12px; }
  .paper-action { justify-content: flex-end; margin-top: 2px; }
  .paper-foot { margin-top: 8px; }

  /* Collection: bulk actions as an even two-by-two block. */
  .collection-head-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; width: 100%; margin: 4px 0 0; }
  .collection-head-actions .btn { width: 100%; height: 36px; background: var(--glass-soft); border-color: var(--glass-line); }

  /* Synthesis: the report panel uses the full width. */
  .report { padding: 18px 16px 8px; }
  .report-body { font-size: 15.5px; }
}

/* ---------------------------------------------------------------------------
   Riso stock (formerly the glass backdrop): cream paper and fine grain.
   Earlier notes: soft pools of the brand's reds and golds, a mulberry and a
   single cool dusk blue, fixed behind the app pages so every pane has colour
   to frost. Static on purpose: moving light under dozens of blurred panes
   would cost smooth scrolling and pull the eye from the reading. A fine grain
   on top keeps the gradients from banding, as frosted glass does. The sign-in
   pages have their own animated scene and are left alone.
   --------------------------------------------------------------------------- */
body:not(.login-body)::before, body:not(.login-body)::after { content: ""; position: fixed; pointer-events: none; }
body:not(.login-body)::before { inset: 0; z-index: -2; background: var(--paper); }
body:not(.login-body)::after {
  inset: 0; z-index: -1; opacity: var(--grain-opacity);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .5 0 0 0 0 .5 0 0 0 0 .5 0 0 0 1 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23g)'/%3E%3C/svg%3E");
}
/* Browsers without backdrop-filter get a near-solid pane instead of a see-through one. */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  :root { --glass-fill: rgba(255, 255, 255, 0.9); --glass-fill-strong: rgba(255, 255, 255, 0.95); }
  [data-theme="dark"] { --glass-fill: rgba(30, 20, 25, 0.92); --glass-fill-strong: rgba(34, 23, 28, 0.95); }
}

/* ---------------------------------------------------------------------------
   Page loader: covers each page with the logo until its first content is
   drawn, and fades back in before leaving, so switching tabs never shows a
   blank page, a top bar popping in, or content jumping into place.
   --------------------------------------------------------------------------- */
@view-transition { navigation: auto; }
.page-loader {
  position: fixed; inset: 0; z-index: 1000; display: grid; place-items: center;
  background: color-mix(in srgb, var(--paper) 70%, transparent); opacity: 1; visibility: visible;
  -webkit-backdrop-filter: blur(30px) saturate(150%); backdrop-filter: blur(30px) saturate(150%);
  transition: opacity 160ms ease;
}
.page-loader.is-done { opacity: 0; visibility: hidden; transition: opacity 240ms ease, visibility 0s linear 240ms; }
.page-loader-mark { display: grid; justify-items: center; gap: 14px; }
.page-loader-mark img { width: 64px; height: 64px; object-fit: contain; animation: loader-breathe 1.2s ease-in-out infinite alternate; }
.page-loader-bar { position: relative; width: 72px; height: 3px; overflow: hidden; border-radius: 3px; background: var(--accent-soft); }
.page-loader-bar::after {
  content: ""; position: absolute; inset: 0; border-radius: inherit; background: var(--accent);
  transform: scaleX(.4); transform-origin: left center;
  animation: loader-waiting 1.4s ease-in-out infinite;
}
@keyframes loader-waiting { 0%, 100% { opacity: .35; } 50% { opacity: 1; } }
/* A page that loads quickly never shows the mark at all; only the paper
   colour, which is what the page is about to show anyway. Coming from
   another tab the mark is already on screen, so it stays without a blink. */
.page-loader:not(.is-leaving) .page-loader-mark { opacity: 0; animation: loader-appear 200ms ease 180ms forwards; }
.from-nav .page-loader .page-loader-mark { opacity: 1; animation: none; }
@keyframes loader-appear { to { opacity: 1; } }
@keyframes loader-breathe { from { transform: scale(.94); opacity: .82; } to { transform: scale(1); opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  @view-transition { navigation: none; }
  .page-loader, .page-loader.is-done { transition: none; }
  .page-loader-mark img, .page-loader-bar::after { animation: none; }
}

/* Thematic synthesis */
.theme-name-input { max-width: 28rem; }
.theme-ask { margin-top: 16px; }
.theme-answer-question { margin: 16px 0 0; font-size: 13px; font-weight: 600; color: var(--muted); }
.theme-answer-saved { margin: 10px 0 0; font-size: 12.5px; color: var(--muted); }

/* Abstract-only tag and the save summary window */
.tag-abstract { display: inline-flex; align-items: center; gap: 4px; }
.tag-abstract .icon { width: 13px; height: 13px; }

/* ---------------------------------------------------------------------------
   Synthesis: calm page, navigator + one view
   --------------------------------------------------------------------------- */
.synth-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px 20px; margin-bottom: 22px; }
.synth-actions { display: flex; align-items: center; gap: 8px; }


.synth-layout { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 28px; align-items: start; }
.synth-layout.is-plain { grid-template-columns: minmax(0, 1fr); }
.synth-nav { position: sticky; top: calc(var(--topbar-h) + 16px); max-height: calc(100vh - var(--topbar-h) - 32px); overflow-y: auto; }
.nav-picker { display: none; }
.nav-heading { margin: 0 0 6px; padding: 0 10px; font: 600 12.5px/1.4 var(--sans); color: var(--muted); }
.nav-item { display: flex; flex-direction: column; gap: 2px; width: 100%; padding: 8px 10px; border: 0; border-radius: var(--r-md); background: transparent; color: var(--ink); text-align: left; cursor: pointer; }
.nav-item:hover:not(:disabled) { background: var(--surface-2); }
.nav-item:disabled { cursor: default; opacity: .6; }
.nav-item.is-current { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.nav-name { font: 500 14px/1.35 var(--sans); overflow-wrap: anywhere; }
.nav-item.is-current .nav-name { font-weight: 600; color: var(--accent); }
.nav-meta { font: 400 12.5px/1.3 var(--sans); color: var(--muted); }

.synth-nav .report-notes { margin: 14px 0 0; }

.synth-main { min-width: 0; padding: clamp(20px, 3vw, 36px); border: 1px solid var(--rule); border-radius: var(--r-lg); background: var(--surface); box-shadow: var(--shadow-xs); }
.synth-main.is-entering { animation: view-in .18s ease-out; }
@keyframes view-in { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .synth-main.is-entering { animation: none; } }
.view-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.view-title { margin: 0; font: 600 clamp(20px, 0.8vw + 16px, 25px)/1.3 var(--serif); color: var(--ink); outline: none; }
.view-lede { margin: 0 0 18px; font-size: 14px; color: var(--muted); }
.view-notice { margin: 0 0 12px; }
.report-meta { margin: 0 0 14px; font-size: 13px; color: var(--muted); }
.part-title { margin: 22px 0 6px; font: 600 14px/1.4 var(--sans); color: var(--muted); }
.synth-main .report-body { max-width: 68ch; }
.theme-paragraph { font-size: 17px; line-height: 1.75; }

.paper-chip { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; min-height: 32px; padding: 4px 12px; border: 1px solid var(--rule-strong); border-radius: 99px; background: var(--surface); color: var(--ink); font: 500 13px/1.3 var(--sans); text-align: left; cursor: pointer; }
.paper-chip:hover { border-color: var(--accent-tint); background: var(--accent-soft); }
.paper-chip b { color: var(--accent); font-weight: 700; }
.paper-chip-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.paper-chip-year { color: var(--muted); }
.theme-questions { margin-top: 28px; padding-top: 20px; border-top: 1px solid var(--rule); }
.theme-questions .theme-ask { margin-top: 10px; }
.theme-answer-item { margin-top: 16px; }
.theme-answer-question { margin: 0 0 4px; font: 600 14px/1.45 var(--sans); color: var(--ink); }
.theme-answer-saved { margin: 6px 0 0; font-size: 12.5px; color: var(--muted); }
.view-pager { display: flex; justify-content: space-between; gap: 12px; margin-top: 28px; padding-top: 16px; border-top: 1px solid var(--rule); }
.pager-link { display: inline-flex; align-items: center; gap: 6px; border: 0; background: none; color: var(--accent); font: 600 14px/1.4 var(--sans); cursor: pointer; }
.gap-rows { list-style: none; margin: 0; padding: 0; }
.gap-row { padding: 14px 0; border-bottom: 1px solid var(--rule); }
.gap-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 8px; }
.tag-warn { border-color: transparent; background: var(--warn-soft); color: var(--warn); }
.intro-papers { margin: 16px auto 0; max-width: 52ch; padding-left: 1.2em; text-align: left; font: 400 15px/1.5 var(--serif); color: var(--muted); }
.theme-name-input { max-width: 32rem; font: 600 20px/1.3 var(--serif); }

.source-panel { width: min(440px, 100vw); max-width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0 0 0 auto; padding: 0; border: 0; border-left: 1px solid var(--rule); background: var(--surface); color: var(--ink); box-shadow: var(--shadow-pop); }
.source-panel::backdrop { background: rgba(20, 16, 17, 0.35); }
.source-panel-head { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--rule); background: var(--surface); }
.source-panel-head h2 { margin: 0; font: 600 17px/1.3 var(--serif); }
#source-panel-list { margin: 0; padding: 8px 18px 24px; }

/* ===========================================================================
   Risograph layer. Two inks on cream stock: square corners, 2px ink rules,
   hard offset shadows, Space Grotesk caps for everything you operate,
   Source Serif 4 for everything you read. Loaded last so it wins.
   =========================================================================== */

::selection { background: var(--riso-red); color: var(--on-accent); }
html { caret-color: var(--riso-red); scrollbar-color: var(--ink) var(--surface-2); }
:focus-visible { outline: 2px solid var(--riso-blue); outline-offset: 3px; border-radius: 0; }
body { font: 400 16px/1.55 var(--sans); }
a { color: var(--ink); text-decoration: underline; text-decoration-color: var(--riso-red); text-decoration-thickness: 2px; text-underline-offset: 3px; }
a:hover { color: var(--riso-red); }

/* Caps label: the riso voice for every small heading and tag. */
.riso-label, .field-label, .nav-heading, .part-title, .menu-label {
  font: 700 12px/1.3 var(--sans); letter-spacing: .14em; text-transform: uppercase;
}
.field-label, .nav-heading, .menu-label { color: var(--muted); }

/* Wordmark */
.brand { text-decoration: none; }
.wordmark, .brand .wordmark { font: 700 28px/1 var(--sans); letter-spacing: -0.03em; color: var(--ink); }
.wordmark b { font-weight: 700; color: var(--riso-red); }

/* Top bar: paper, one heavy rule. */
.topbar { border-bottom: var(--line); background: var(--paper); }
.topbar::before { background: var(--paper); -webkit-backdrop-filter: none; backdrop-filter: none; }
.steps { gap: 12px; }
.step-sep { display: none; }
.step {
  height: 40px; padding: 0 16px; gap: 8px; border: var(--line); border-radius: 0;
  background: transparent; color: var(--ink); font: 500 14px/1 var(--sans); letter-spacing: .08em; text-transform: uppercase;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast), background var(--transition-fast);
}
.step:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.step-n { width: auto; height: auto; border: 0; border-radius: 0; font: inherit; }
.step[aria-current="page"], .step[aria-current="page"]:hover { background: var(--riso-red); border-color: var(--riso-red); color: var(--on-accent); }
.step[aria-current="page"] .step-n { background: none; border: 0; color: inherit; }
.step-count { border-radius: 0; background: transparent; border: 1.5px solid currentColor; color: inherit; font-weight: 700; }
.step[aria-current="page"] .step-count { background: transparent; color: inherit; }

/* Buttons: ink boxes with a hard shadow that collapses on press. */
.btn {
  height: 40px; padding: 0 16px; border: var(--line); border-radius: 0;
  background: var(--surface); color: var(--ink); box-shadow: 3px 3px 0 var(--shade);
  font: 600 12.5px/1 var(--sans); letter-spacing: .08em; text-transform: uppercase;
}
.btn:hover { background: var(--surface); box-shadow: 4px 4px 0 var(--shade); transform: translate(-1px, -1px); }
.btn:active { box-shadow: 0 0 0 var(--ink); transform: translate(3px, 3px); }
.btn-primary, .btn-primary:hover { background: var(--riso-red); background-image: none; border-color: var(--ink); color: var(--on-accent); filter: none; }
.btn-blue, .btn-blue:hover { background: var(--riso-blue); border-color: var(--ink); color: var(--on-blue); }
.btn-quiet { border: var(--line); background: transparent; color: var(--ink); box-shadow: none; }
.btn-quiet:hover { background: var(--surface-2); box-shadow: 2px 2px 0 var(--shade); transform: none; }
.btn-danger { color: var(--danger); }
.btn-sm { height: 34px; padding: 0 12px; font-size: 12px; box-shadow: 2px 2px 0 var(--shade); }
.btn.is-success { background: var(--blue-tint); color: var(--riso-blue); box-shadow: none; border-color: var(--riso-blue); }
.icon-btn { border-radius: 0; color: var(--ink); }
.icon-btn:hover { background: var(--surface-2); border-color: var(--ink); }
.link-btn { color: var(--riso-red); font: 700 12px/1.3 var(--sans); letter-spacing: .1em; text-transform: uppercase; text-decoration: underline; text-underline-offset: 3px; }

/* Fields */
.input, .select { height: 42px; border: var(--line); border-radius: 0; background: var(--field-fill); }
.input:focus, .select:focus { border-color: var(--riso-blue); box-shadow: none; }
.check input, .switch input:checked { accent-color: var(--riso-red); }
.switch input { border-radius: 0; border: var(--line); background: var(--surface); }
.switch input::after { border-radius: 0; top: 2px; left: 2px; background: var(--ink); }
.switch input:checked { background: var(--riso-red); }
.switch input:checked::after { background: var(--paper); }

/* Tags: outlined caps; filled variants carry counts. */
.tag {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 8px; border: 1.5px solid var(--muted); border-radius: 0;
  background: transparent; color: var(--muted); font: 700 11px/1.3 var(--sans); letter-spacing: .1em; text-transform: uppercase;
}
.tag-red { background: var(--riso-red); border-color: var(--riso-red); color: var(--on-accent); }
.tag-blue { background: var(--riso-blue); border-color: var(--riso-blue); color: var(--on-blue); }
.tag-outline-blue { border-color: var(--riso-blue); color: var(--riso-blue); }
.tag-ink { border-color: var(--ink); color: var(--ink); }

/* Surfaces: panels, menus, dialogs, toasts, notices. */
.panel { background: var(--surface); border: var(--line); border-radius: 0; box-shadow: none; -webkit-backdrop-filter: none; backdrop-filter: none; }
.menu { border: var(--line); border-radius: 0; background: var(--surface); box-shadow: var(--shadow-pop); -webkit-backdrop-filter: none; backdrop-filter: none; }
.menu-item { border-radius: 0; font: 500 14px/1.3 var(--sans); }
.menu-item:hover { background: var(--surface-2); }
.dialog { border: var(--line); border-radius: 0; background: var(--surface); box-shadow: 4px 4px 0 var(--shade); color: var(--ink); }
.dialog h2 { font: 700 22px/1.2 var(--sans); letter-spacing: -0.01em; }
.dialog::backdrop { background: rgba(30, 27, 24, 0.45); }
.toast { border: var(--line); border-radius: 0; background: var(--surface); color: var(--ink); box-shadow: var(--shadow-pop); }
.notice { border: 2px dashed var(--riso-blue); border-radius: 0; background: transparent; color: var(--riso-blue); font: 500 14px/1.45 var(--sans); }
.notice.is-error { border-color: var(--danger); color: var(--danger); background: transparent; }

/* Headings: Grotesk display for titles you operate around; serif stays for reading. */
.page-title { font: 700 clamp(34px, 3vw + 18px, 56px)/1.02 var(--sans); letter-spacing: -0.035em; }
.page-sub { font: 500 15px/1.5 var(--sans); color: var(--muted); }
.empty h2 { font: 700 clamp(22px, 1.4vw + 16px, 28px)/1.15 var(--sans); letter-spacing: -0.02em; }

@media (prefers-reduced-motion: reduce) {
  .btn, .step { transition: none; }
  .btn:hover, .btn:active { transform: none; }
}

/* Auth pages: the same stock, one boxed form. */
.login-body, .login-body.login-river, [data-theme="dark"] .login-body.login-river {
  background: var(--paper);
}
.login-body > :not(.login-art) { position: relative; z-index: 1; }
.login-body > .theme-toggle { position: fixed; }
.login-card, .login-river .login-card, [data-theme="dark"] .login-river .login-card {
  width: min(420px, 100%); padding: clamp(28px, 5vw, 40px); border: var(--line); border-radius: 0;
  background: var(--surface); box-shadow: none; -webkit-backdrop-filter: none; backdrop-filter: none;
}
.login-brand { align-items: flex-start; text-align: left; gap: 18px; margin-bottom: 26px; padding-bottom: 18px; border-bottom: var(--line); }
.login-brand .wordmark { font-size: 34px; }
.login-brand h1 { font: 700 30px/1.05 var(--sans); letter-spacing: -0.03em; }
.login-card .input { height: 46px; }
.login-card .btn { height: 48px; margin-top: 10px; }
.login-river .input { -webkit-backdrop-filter: none; backdrop-filter: none; }
.login-river .btn-primary { box-shadow: 3px 3px 0 var(--shade); }
.login-hint { font: 500 14px/1.5 var(--sans); text-align: left; }
.login-error, .login-note { border-radius: 0; border: 2px solid currentColor; background: transparent; font: 500 14px/1.45 var(--sans); }
.login-note { color: var(--riso-blue); }
.theme-toggle { border: var(--line); border-radius: 0; background: var(--surface); color: var(--ink); box-shadow: 2px 2px 0 var(--shade); }
.page-loader-mark .wordmark { font-size: 34px; }

/* Search + Collection in riso: ruled ink rows, outlined controls. */
.search-hero .page-title { margin-bottom: clamp(16px, 2.4vw, 26px); }
.searchbar { border: var(--line); border-radius: 0; background: var(--surface); box-shadow: var(--shadow-blue); -webkit-backdrop-filter: none; backdrop-filter: none; padding: 8px 8px 8px 18px; }
.searchbar:focus-within { border-color: var(--ink); box-shadow: none; }
.searchbar input { font: 400 18px/1.4 var(--serif); }
.searchbar input::placeholder { color: var(--muted); }
.searchbar .btn { border-radius: 0; }
.searchbar .filters-toggle { border: 0; box-shadow: none; background: transparent; }
.searchbar .filters-toggle:hover { background: var(--surface-2); box-shadow: none; transform: none; }
.source-pick, .chip { border: var(--line); border-radius: 0; background: var(--surface); color: var(--ink); font: 500 13px/1.3 var(--sans); box-shadow: 2px 2px 0 var(--shade); }
.source-pick:hover:not(:disabled), .source-pick[aria-expanded="true"], .chip:hover { border-color: var(--ink); background: var(--surface-2); }
.source-pick .icon { color: var(--riso-red); }
.chip[aria-pressed="true"] { background: var(--riso-red); border-color: var(--ink); color: var(--on-accent); }
.source-option { border-radius: 0; }
.filters-panel { border: var(--line); border-radius: 0; background: var(--surface); box-shadow: none; -webkit-backdrop-filter: none; backdrop-filter: none; }
.filters-head h2 { font: 700 18px/1.2 var(--sans); letter-spacing: -0.01em; }
.filter-group + .filter-group, .sheet-foot { border-top: var(--line); }

.paper-list { border: var(--line); border-radius: 0; background: var(--surface); box-shadow: none; -webkit-backdrop-filter: none; backdrop-filter: none; }
.paper { border-top: 2px solid var(--ink); }
.paper.is-selected { background: var(--red-tint); box-shadow: none; }
.paper-title { font: 400 clamp(18px, 0.4vw + 16px, 21px)/1.35 var(--serif); letter-spacing: -0.005em; }
.paper-title a { text-decoration: none; }
.paper-title a:hover { color: var(--riso-red); text-decoration: underline; text-decoration-color: var(--riso-red); }
.paper-byline { font: 500 13.5px/1.45 var(--sans); color: var(--muted); }
.paper-abstract { font: 400 15.5px/1.6 var(--serif); color: var(--muted); }
.paper-foot { font: 500 13px/1.4 var(--sans); }
.paper-foot a { color: var(--riso-blue); text-decoration: none; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; font-size: 12px; }
.relevance-score { border: 2px solid var(--riso-blue); border-radius: 0; background: var(--riso-blue); color: var(--on-blue); font: 700 12px/1.4 var(--sans); }
.paper-check input { accent-color: var(--riso-red); }
.saved-mark { border-radius: 0; border: 2px solid var(--riso-blue); background: transparent; color: var(--riso-blue); font: 700 12px/1 var(--sans); letter-spacing: .1em; text-transform: uppercase; }
.pager button { border: var(--line); border-radius: 0; background: var(--surface); font: 700 14px/1 var(--sans); }
.pager button[aria-current="page"] { background: var(--riso-red); color: var(--on-accent); }
.progress, .track-bar { border-radius: 0; background: var(--surface-2); height: 6px; }
.progress-fill, .track-fill { border-radius: 0; background: var(--riso-red); }
.track.is-settled .track-fill { background: var(--riso-blue); }
.track-label { font: 700 11px/1.3 var(--sans); letter-spacing: .1em; text-transform: uppercase; }
.track-seg.is-current .track-label { color: var(--riso-red); }
.source-pill { border-radius: 0; border: 1.5px solid var(--muted); background: transparent; font: 700 11px/1.3 var(--sans); letter-spacing: .08em; text-transform: uppercase; }
.source-pill.is-done { border-color: var(--riso-blue); background: transparent; color: var(--riso-blue); }
.source-pill.is-failed { border-color: var(--warn); background: transparent; }
.skeleton { border-top: 2px solid var(--rule); }
.skeleton i { border-radius: 0; }
.action-bar { border: var(--line); border-radius: 0; background: var(--ink); color: var(--paper); box-shadow: 4px 4px 0 var(--riso-red); -webkit-backdrop-filter: none; backdrop-filter: none; }
.action-bar .btn-primary { box-shadow: none; border-color: var(--paper); }
.action-bar .btn-quiet { color: var(--paper); border-color: var(--paper); }
.results-status { font: 500 14px/1.45 var(--sans); }
.query-item { border-radius: 0; }
.query-item[aria-current="true"] { background: var(--riso-red); color: var(--on-accent); }
.query-total:not(:empty), .query-count { border-radius: 0; }
.query-item[aria-current="true"] .query-count { background: var(--paper); color: var(--riso-red); }
.upload-dialog-head h2 { font: 700 22px/1.2 var(--sans); letter-spacing: -0.01em; }
.collection-head-actions .btn .icon, .upload-open .icon { color: var(--riso-red); }

/* Synthesis in riso (matches the approved mockup). */
.synth-head { align-items: flex-start; margin-bottom: 28px; }
.synth-actions { gap: 14px; flex-wrap: wrap; }
.synth-history { width: 40px; height: 40px; border: var(--line); box-shadow: 2px 2px 0 var(--shade); }

.synth-layout { grid-template-columns: 200px minmax(0, 1fr); gap: clamp(24px, 3vw, 44px); }
.synth-layout.is-plain .synth-side { display: none; }
.synth-side { position: sticky; top: calc(var(--topbar-h) + 20px); display: flex; flex-direction: column; gap: 20px; align-self: start; }
.synth-nav { position: static; max-height: none; overflow: visible; }
.nav-list { display: flex; flex-direction: column; gap: 8px; }
.nav-heading { margin: 0 0 2px; padding: 0; }
.nav-item {
  gap: 2px; padding: 10px 12px; border: var(--line); border-radius: 0; background: var(--surface); box-shadow: none;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast), background var(--transition-fast);
}
.nav-item:hover:not(:disabled) { background: var(--surface-2); box-shadow: 2px 2px 0 var(--shade); }
.nav-item.is-current, .nav-item.is-current:hover { background: var(--riso-red); color: var(--on-accent); box-shadow: 3px 3px 0 var(--shade); }
.nav-name { font: 500 14px/1.3 var(--sans); }
.nav-item.is-current .nav-name { color: var(--on-accent); font-weight: 500; }
.nav-meta { font: 400 12px/1.3 var(--sans); color: var(--muted); }
.nav-item.is-current .nav-meta { color: var(--on-accent); opacity: .9; }

.notes-btn { position: relative; color: var(--riso-red); }
.notes-count { position: absolute; top: -8px; right: -8px; min-width: 18px; height: 18px; padding: 0 4px; background: var(--riso-red); color: var(--on-accent); font: 700 11px/18px var(--sans); text-align: center; }
dialog.notes-dialog { width: min(520px, calc(100vw - 24px)); padding: 24px; }
.notes-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; padding-bottom: 12px; border-bottom: var(--line); }
.notes-head h2 { margin: 0; }
.notes-list { margin: 0; padding-left: 18px; display: grid; gap: 10px; font: 400 16px/1.6 var(--serif); }
.notes-list li::marker { color: var(--riso-red); }

.synth-main { padding: clamp(24px, 4vw, 56px); border: var(--line); border-radius: 0; background: var(--surface); box-shadow: none; -webkit-backdrop-filter: none; backdrop-filter: none; }
.theme-kicker { color: var(--riso-red); margin-bottom: 14px; }
.view-head { margin-bottom: 20px; }
.view-title { font: 700 clamp(34px, 2.6vw + 18px, 52px)/1.04 var(--sans); letter-spacing: -0.035em; max-width: none; text-wrap: balance; }
.count-tags { display: flex; flex-wrap: wrap; gap: 10px; padding-bottom: 20px; margin-bottom: 26px; border-bottom: var(--line); }
.count-tags .tag { padding: 6px 12px; font-size: 12px; }
.theme-paragraph, .synth-main .report-body { max-width: 66ch; font: 400 19px/1.75 var(--serif); border-left: 0; padding-left: 0; }
.part-title { margin: 30px 0 10px; color: var(--riso-blue); font: 700 16px/1.3 var(--sans); letter-spacing: .04em; }
.report-body li::marker { color: var(--riso-red); }
.cite {
  display: inline-grid; place-items: center; min-width: 22px; height: 22px; padding: 0 5px; margin: 0 1px;
  border: 0; border-radius: 0; background: var(--riso-red); color: var(--on-accent);
  font: 700 12px/1 var(--sans); vertical-align: 3px; cursor: pointer; transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}
.cite.ink-blue { background: var(--riso-blue); color: var(--on-blue); }
.cite:hover, .cite:focus-visible, .cite.is-active { transform: translate(-1px, -1px); box-shadow: 2px 2px 0 var(--shade); }
.cite.is-invalid { background: transparent; color: var(--muted); outline: 2px dotted var(--muted); }
.overlap-note { display: block; width: max-content; margin: 6px 0 4px; font: 700 11px/1.4 var(--sans); letter-spacing: .12em; text-transform: uppercase; color: var(--ink); border-bottom: 2px solid var(--riso-red); }
.theme-actions { margin-top: 26px; }
.theme-questions { margin-top: 22px; padding-top: 0; border-top: 0; }
.theme-answer-question { font: 700 15px/1.4 var(--sans); }
.theme-answer-saved { font: 700 11px/1.4 var(--sans); letter-spacing: .1em; text-transform: uppercase; color: var(--riso-blue); }
.source-rows { list-style: none; margin: 32px 0 0; padding: 0; border-top: 3px solid var(--ink); }
.source-row {
  display: grid; grid-template-columns: 40px minmax(0, 1fr) auto auto; align-items: baseline; gap: 16px; width: 100%;
  padding: 16px 0; border: 0; border-bottom: 2px solid var(--rule); background: none; color: var(--ink); text-align: left; cursor: pointer;
}
.source-row:hover .source-row-title { color: var(--riso-red); }
.source-row-n { font: 700 24px/1 var(--sans); color: var(--riso-red); }
.source-row-title { font: 400 17px/1.4 var(--serif); }
.source-row-year { font: 500 13px/1 var(--sans); color: var(--muted); }
.source-row-tags { display: flex; gap: 6px; }
.view-pager { border-top: var(--line); }
.pager-link { color: var(--ink); font: 700 13px/1.3 var(--sans); letter-spacing: .1em; text-transform: uppercase; }
.pager-link:hover { color: var(--riso-red); }
.view-lede { font: 500 15px/1.5 var(--sans); }
.gap-row { border-bottom: 2px solid var(--rule); }
.report-meta { font: 700 11px/1.4 var(--sans); letter-spacing: .12em; text-transform: uppercase; }
.synth-main .report-section { border: 0; }

.source-panel { border: 0; border-left: var(--line); border-radius: 0; background: var(--surface); box-shadow: none; }
.source-panel-head { border-bottom: var(--line); }
.source-panel-head h2 { font: 700 18px/1.2 var(--sans); letter-spacing: -0.01em; }
.evidence-quote mark { background: var(--red-tint); color: var(--ink); }
.paper-chip { border: var(--line); border-radius: 0; background: var(--surface); font: 500 13px/1.3 var(--sans); }
.paper-chip b { color: var(--riso-red); }

@media (max-width: 900px) {
  .synth-layout { grid-template-columns: minmax(0, 1fr); }
  .synth-side { position: static; }
  .synth-main { padding: 22px 16px; box-shadow: none; }
  .synth-actions #ask-btn { flex: 1 1 100%; }
  .source-row { grid-template-columns: 32px minmax(0, 1fr); }
  .source-row-year, .source-row-tags { grid-column: 2; }
  .source-panel { border-left: 0; border-top: var(--line); box-shadow: none; }
}

/* Admin, segmented tabs, status boxes and the loader in riso. */
.stat { border: var(--line); border-radius: 0; background: var(--surface); box-shadow: 3px 3px 0 var(--shade); -webkit-backdrop-filter: none; backdrop-filter: none; }
.stat-value { font: 700 36px/1 var(--sans); letter-spacing: -0.03em; }
.stat-label, .stat-sub { font: 700 11px/1.4 var(--sans); letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.stat.is-warn { border-color: var(--ink); background: var(--red-tint); }
.stat.is-warn .stat-value, .stat.is-warn .stat-label { color: var(--riso-red); }
.admin-panel-head h2 { font: 700 20px/1.2 var(--sans); letter-spacing: -0.01em; }
.user-row { border-top: 2px solid var(--rule); }
.user-row.is-waiting { background: var(--red-tint); }
.segmented { border: var(--line); border-radius: 0; background: var(--surface); padding: 0; gap: 0; box-shadow: 2px 2px 0 var(--shade); }
.segmented button { border-radius: 0; font: 700 12px/1 var(--sans); letter-spacing: .1em; text-transform: uppercase; }
.segmented button[aria-selected="true"], .segmented button[aria-pressed="true"] { background: var(--riso-red); color: var(--on-accent); box-shadow: none; }
.viz-grid { stroke: var(--rule); }
.page-loader { background: var(--paper); }
.page-loader-bar { border-radius: 0; background: var(--riso-red); }

/* A saved query is the student's own words, not a label: keep its case. */
.tag-query { text-transform: none; letter-spacing: 0; font-weight: 500; font-size: 12.5px; }
.segmented { padding: 3px; gap: 3px; }

/* Phones: the bottom tab bar in riso, square with a hard shadow, labels short enough to fit. */
@media (max-width: 640px) {
  .steps { gap: 6px; padding: 6px; border: var(--line); border-radius: 0; background: var(--paper); box-shadow: 3px 3px 0 var(--shade); -webkit-backdrop-filter: none; backdrop-filter: none; }
  .step, .step-admin { height: 100%; padding: 0 2px; border: 0; font: 700 10px/1 var(--sans); letter-spacing: .06em; }
  .step[aria-current="page"] { box-shadow: none; }
  .step-count { border-color: currentColor; background: var(--paper); color: var(--ink); }
  .step[aria-current="page"] .step-count { background: var(--paper); color: var(--riso-red); }
}

/* Components: formal finish. One focus ring everywhere, links that underline
   from the left, controls that settle rather than bounce. */
:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible { outline: 2px solid var(--riso-blue); outline-offset: 2px; }
.btn, .nav-item, .step, .icon-btn, .source-row, .cite { transition-timing-function: cubic-bezier(.2, .7, .2, 1); }
.link-btn, .login-hint a {
  text-decoration: none; background: linear-gradient(currentColor, currentColor) 0 100% / 100% 1.5px no-repeat;
  transition: background-size .25s cubic-bezier(.2, .7, .2, 1);
}
.link-btn:hover, .login-hint a:hover { background-size: 0 1.5px; background-position: 100% 100%; }

.input { transition: border-color .15s, box-shadow .2s cubic-bezier(.2, .7, .2, 1); }
.nav-item:hover:not(:disabled):not(.is-current) { transform: translateX(2px); }
.source-row { transition: background .2s; }
.source-row:hover { background: linear-gradient(90deg, var(--red-tint), transparent 70%); }
@media (prefers-reduced-motion: reduce) {
  .link-btn, .login-hint a, .input, .source-row { transition: none; }
  .nav-item:hover:not(:disabled):not(.is-current) { transform: none; }
}

/* ---------------------------------------------------------------------------
   Synthesis: theme tabs where the page title was; the side panel holds the
   current theme's sections.
   --------------------------------------------------------------------------- */
.synth-head { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 16px 28px; margin-bottom: 28px; }
.synth-head > .synth-actions { justify-content: flex-end; }
/* Its menus open over the panel below, which gets its own layer when it animates in. */
.synth-head { position: relative; z-index: 5; }
.theme-tabs { display: flex; gap: 12px; min-width: 0; padding: 2px 6px 8px 2px; overflow-x: auto; scroll-snap-type: x proximity; scrollbar-width: thin; }
.theme-tab {
  flex: 0 1 260px; min-width: 190px; display: grid; gap: 5px; align-content: start; padding: 12px 14px 13px;
  border: var(--line); background: var(--surface); color: var(--ink); text-align: left; cursor: pointer; scroll-snap-align: start;
  transition: transform .35s cubic-bezier(.32, .72, 0, 1), box-shadow .35s cubic-bezier(.32, .72, 0, 1), background .2s;
}
.theme-tab:hover:not(:disabled):not(.is-current) { transform: translateY(-2px); box-shadow: 2px 3px 0 var(--shade); }
.theme-tab:disabled { cursor: default; opacity: .6; }
.theme-tab-n { font: 700 11px/1 var(--sans); letter-spacing: .14em; color: var(--riso-red); }
.theme-tab-name { font: 600 15px/1.3 var(--sans); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.theme-tab-meta { font: 400 12px/1.2 var(--sans); color: var(--muted); }
.theme-tab.is-current { background: var(--riso-red); border-color: var(--riso-red); color: var(--on-accent); box-shadow: 3px 3px 0 var(--shade); }
.theme-tab.is-current .theme-tab-n, .theme-tab.is-current .theme-tab-meta { color: var(--on-accent); }
.nav-heading { color: var(--riso-red); }
.nav-item.is-current, .nav-item.is-current:hover { background: var(--ink); border-color: var(--ink); color: var(--paper); box-shadow: 2px 2px 0 var(--riso-red); }
.nav-item.is-current .nav-name, .nav-item.is-current .nav-meta { color: var(--paper); }
.side-link { align-self: flex-start; margin-top: 6px; font: 600 12px/1.3 var(--sans); letter-spacing: .08em; text-transform: uppercase; color: var(--ink); text-decoration: none;
  background: linear-gradient(var(--riso-red), var(--riso-red)) 0 100% / 100% 1.5px no-repeat; transition: background-size .25s cubic-bezier(.2, .7, .2, 1); }
.side-link:hover { background-size: 0 1.5px; background-position: 100% 100%; }
.gap-open { margin-bottom: 18px; }
@media (max-width: 900px) {
  .synth-head { grid-template-columns: minmax(0, 1fr); }
  .synth-head > .synth-actions { justify-content: flex-start; }
  .theme-tab { flex: 0 0 min(78vw, 260px); }
}
button.side-link { border: 0; padding: 0; cursor: pointer; color: var(--riso-red); }

/* ---------------------------------------------------------------------------
   Sign-in: the form centred, riso print pieces around it (js/login-field.js).
   --------------------------------------------------------------------------- */
.login-body::after {
  content: ""; position: fixed; inset: 0; z-index: 2; pointer-events: none; opacity: .05; mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
[data-theme="dark"] .login-body::after { mix-blend-mode: screen; opacity: .04; }
.login-logo { display: flex; align-items: center; gap: 12px; }
.login-logo img { width: 34px; height: auto; }
[data-theme="dark"] .login-logo img, [data-theme="dark"] .brand-logo { filter: invert(1) hue-rotate(180deg); }
.brand { display: inline-flex; align-items: center; gap: 10px; }
.brand-logo { width: 20px; height: auto; flex: none; }

/* The scenery (js/login-field.js) runs on one canvas; the form sits in a
   slightly darker oval of paper, sized from the card, so it reads first. */
.login-art { position: fixed; inset: 0; z-index: 0; overflow: hidden; pointer-events: none; }
.login-art canvas { display: block; }
.login-body { --login-mask: color-mix(in srgb, #000 8%, var(--paper)); }
[data-theme="dark"] .login-body { --login-mask: color-mix(in srgb, #000 38%, var(--paper)); }
.login-body.login-river, [data-theme="dark"] .login-body.login-river {
  background: radial-gradient(ellipse var(--clear-x, 400px) var(--clear-y, 420px) at 50% 50%, var(--login-mask) 45%, var(--paper) 100%) var(--paper);
}
/* Auth pages carry no offset shadows: the card, button and toggle sit flat on the paper. */
.login-body .login-card, .login-body .btn, .login-body .btn:hover, .login-body .theme-toggle { box-shadow: none; transform: none; }
.login-body .btn-primary:hover { background: color-mix(in srgb, var(--riso-red) 86%, var(--ink)); }
.login-body .btn:active { box-shadow: none; transform: translateY(1px); }
/* On a phone the scenery shrinks to one lane above the form and one sheet below it (login-field.js). */

/* Auth card head: the logo centred with the wordmark under it. */
.login-brand, .login-river .login-brand { align-items: center; text-align: center; gap: 14px; }
.login-logo { flex-direction: column; gap: 10px; }
.login-logo img { width: 46px; }
.login-logo .wordmark { font-size: 32px; }
.login-brand h1:not(.sr-only) { font-size: 22px; }

/* ---------------------------------------------------------------------------
   The synthesis wait (js/synth-loader.js): a sheet on the press, one pass per
   real step, and a numbered track under it.
   --------------------------------------------------------------------------- */
.sl { display: grid; justify-items: center; gap: 6px; padding: clamp(12px, 3vw, 28px) 0 4px; text-align: center; }
.sl-sheet {
  position: relative; width: min(300px, 78%); aspect-ratio: 4 / 3; overflow: hidden;
  border: var(--line); background: var(--surface);
}
.sl-tone {
  position: absolute; inset: 0 auto 0 0; width: 100%; opacity: .55;
  background: radial-gradient(circle, var(--riso-blue) 30%, transparent 34%) 0 0 / 9px 9px;
  clip-path: inset(0 calc((1 - var(--f, 1)) * 100%) 0 0);
  transition: clip-path .6s cubic-bezier(.16, 1, .3, 1), opacity .4s;
}
.sl:not(.is-measured)[data-step="0"] .sl-tone { animation: sl-roll 2.4s cubic-bezier(.65, 0, .35, 1) infinite; }
@keyframes sl-roll { 0% { clip-path: inset(0 100% 0 0); } 70% { clip-path: inset(0 0 0 0); } 100% { clip-path: inset(0 0 0 0); opacity: 0; } }
.sl:not([data-step="0"]) .sl-tone { opacity: .16; clip-path: none; }
.sl-lines { position: absolute; inset: 16% 12% 14%; display: grid; align-content: space-between; }
.sl-line { position: relative; display: block; width: var(--w); height: 5px; background: var(--ink); transform-origin: left; transform: scaleX(0); }
/* Writing: each line inks in during its own slot and stays; the lines fade
   briefly and at different moments, so the sheet is never blank. */
.sl[data-step="1"] .sl-line { animation: sl-ink 4.8s cubic-bezier(.16, 1, .3, 1) infinite; animation-delay: calc(var(--i) * .55s); }
@keyframes sl-ink { 0% { transform: scaleX(0); opacity: 1; } 14%, 90% { transform: scaleX(1); opacity: 1; } 100% { transform: scaleX(1); opacity: 0; } }
.sl[data-step="2"] .sl-line, .sl[data-step="3"] .sl-line, .sl[data-step="4"] .sl-line { transform: none; }
.sl-cite { position: absolute; left: calc(100% + 6px); top: 50%; width: 11px; height: 11px; background: var(--riso-red); transform: translateY(-50%) scale(0); }
.sl-cite.is-blue { background: var(--riso-blue); }
.sl[data-step="3"] .sl-cite { animation: sl-stamp 2.8s cubic-bezier(.16, 1, .3, 1) infinite; animation-delay: calc(var(--i) * .3s); }
.sl[data-step="4"] .sl-cite { transform: translateY(-50%) scale(1); }
@keyframes sl-stamp { 0%, 8% { transform: translateY(-50%) scale(0); } 22%, 90% { transform: translateY(-50%) scale(1); } 100% { transform: translateY(-50%) scale(1); opacity: 0; } }
.sl-reg { position: absolute; left: 50%; top: 0; width: 34px; margin-left: -17px; fill: none; stroke: var(--riso-red); stroke-width: 2; opacity: 0; }
/* Checking: the mark scans between fixed points of the sheet's own height. */
.sl[data-step="2"] .sl-reg { opacity: 1; animation: sl-scan 2.2s cubic-bezier(.65, 0, .35, 1) infinite alternate; }
@keyframes sl-scan { from { top: 6%; } to { top: calc(94% - 34px); } }

.sl-message { margin: 14px 0 0; font: 600 clamp(16px, .5vw + 14px, 18px)/1.35 var(--sans); color: var(--ink); }
.sl-detail { min-height: 1.4em; margin: 0 0 12px; font: 400 13px/1.4 var(--sans); color: var(--muted); font-variant-numeric: tabular-nums; }
.sl-d:not(:empty)::after { content: " · "; }
.sl-track { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; width: min(460px, 100%); margin: 0; padding: 0; list-style: none; text-align: left; }
.sl-seg { display: grid; grid-template-columns: auto 1fr; align-items: baseline; gap: 4px 6px; min-width: 0; }
.sl-n { font: 700 11px/1 var(--sans); letter-spacing: .08em; color: var(--muted); }
.sl-label { overflow: hidden; font: 600 11px/1 var(--sans); letter-spacing: .1em; text-transform: uppercase; color: var(--muted); white-space: nowrap; text-overflow: ellipsis; }
.sl-bar { grid-column: 1 / -1; position: relative; display: block; height: 6px; border: 1.5px solid var(--ink); background: var(--surface); overflow: hidden; }
.sl-bar i { position: absolute; inset: 0; background: var(--riso-red); transform: scaleX(0); transform-origin: left; transition: transform .5s cubic-bezier(.16, 1, .3, 1); }
.sl-seg.is-done .sl-bar i { transform: scaleX(1); background: var(--ink); }
.sl-seg.is-current .sl-n, .sl-seg.is-current .sl-label { color: var(--riso-red); }
/* A step with no measurable end breathes in place: a bar sliding edge to edge
   forever is motion that reports nothing. */
.sl:not(.is-measured) .sl-seg.is-current .sl-bar i { transform: scaleX(.35); animation: sl-waiting 1.6s cubic-bezier(.45, 0, .55, 1) infinite; }
@keyframes sl-waiting { 0%, 100% { opacity: .35; } 50% { opacity: 1; } }
.sl.is-settled .sl-bar i { transform: scaleX(1); background: var(--ink); animation: none; }

.sl.is-compact { padding: 6px 0 2px; }
.sl.is-compact .sl-sheet { width: 128px; }
.sl.is-compact .sl-line { height: 3px; }
.sl.is-compact .sl-cite { width: 7px; height: 7px; }
.sl.is-compact .sl-reg { width: 20px; margin-left: -10px; }
.sl.is-compact .sl-message { margin-top: 8px; font-size: 14.5px; }
.sl.is-compact .sl-label { display: none; }
.sl.is-compact .sl-track { width: min(220px, 100%); gap: 6px; }
@media (max-width: 480px) {
  .sl-track { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 14px; }
}
@media (prefers-reduced-motion: reduce) {
  .sl *, .sl-sheet { animation: none !important; transition: none !important; }
  .sl[data-step="1"] .sl-line { transform: none; }
  .sl[data-step="3"] .sl-cite { transform: translateY(-50%) scale(1); }
  .sl[data-step="2"] .sl-reg { opacity: 1; top: 40%; }
  .sl:not(.is-measured) .sl-seg.is-current .sl-bar i { transform: scaleX(.5); }
}

/* Shape lock: the riso system is square. Leftover pills from the glass theme. */
.step-count, .page-chip, .page-chip b, .evidence-badge, .relevance-score, .query-total, .progress, .track-bar { border-radius: 0; }

/* Phones: the Synthesis header actions on one row, each at its own width. */
@media (max-width: 560px) {
  .synth-actions { display: flex; flex-wrap: wrap; width: auto; gap: 10px; }
  .synth-actions .btn, .synth-actions .dropdown, .synth-actions .dropdown .btn { width: auto; }
  .synth-actions #run-btn { order: 0; height: 40px; }
  .synth-actions #ask-btn { flex: 1 1 100%; }
}

/* An empty results toolbar (before any search) takes no room. */
.results-toolbar:has(#results-status:empty):has(#results-controls[hidden]) { display: none; }

/* Theme tabs scroll sideways by touch; no scrollbar strip under them. */
.theme-tabs { scrollbar-width: none; }
.theme-tabs::-webkit-scrollbar { display: none; }

/* ---------------------------------------------------------------------------
   Phones: every row earns its height.
   --------------------------------------------------------------------------- */
@media (max-width: 640px) {
  /* Search: the field, then Recent, Filters and Search on one row. */
  .searchbar { padding: 8px 8px 8px 10px; gap: 6px; }
  .searchbar input { height: 44px; }
  .searchbar .filters-toggle { height: 44px; gap: 6px; padding: 0 10px; font-size: 12px; letter-spacing: .06em; }
  .searchbar #search-btn { height: 44px; padding: 0 18px; }
  .source-toggles { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; margin-top: 14px; }
  .source-toggles > * { width: 100%; }
  .source-toggles .switch { justify-content: space-between; min-height: 44px; }
  .search-hero { margin-bottom: 14px; }
  .empty { padding: 24px 16px; }
  .empty-examples { display: grid; gap: 10px; margin-top: 12px; }
  .empty-examples .chip { width: 100%; min-height: 44px; justify-content: flex-start; }

  /* Synthesis: the theme's four sections as a compact two-by-two grid. */
  .nav-list { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .nav-list .nav-heading, .nav-list .side-link { grid-column: 1 / -1; }
  .nav-item { padding: 9px 10px; min-height: 52px; }
  .nav-name { font-size: 14px; }
  .synth-side { gap: 12px; }
  .synth-layout { gap: 18px; }
}
@media (max-width: 640px) {
  .source-pick { width: 100%; min-height: 44px; }
  .source-pick .icon:last-child { margin-left: auto; }
  .nav-list .side-link { justify-self: start; }
  .view-title { font-size: clamp(26px, 7vw, 30px); }
}

/* Synthesis: papers that share no finding or topic, each with the reason. */
.no-connection-list { display: grid; gap: 10px; max-width: 620px; margin: 14px auto; padding: 0; list-style: none; text-align: left; }
.no-connection-list li { display: grid; gap: 4px; padding: 12px 14px; border: var(--line); background: var(--surface); }
.no-connection-list strong { font: 400 16px/1.4 var(--serif); color: var(--ink); }
.no-connection-list span { font: 400 14px/1.5 var(--sans); color: var(--muted); }

/* ---------------------------------------------------------------------------
   Synthesis layout: the themes as a compact list in the side column, the
   current theme's sections as a row of tabs along the top.
   --------------------------------------------------------------------------- */
.synth-head .nav-list { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px; }
.synth-head .nav-item { width: auto; flex-direction: row; align-items: baseline; gap: 8px; padding: 9px 14px; }
.synth-head .nav-item:hover:not(:disabled):not(.is-current) { transform: translateY(-1px); }
.synth-head .side-link { align-self: center; margin: 0 0 0 8px; }
.synth-side .theme-tabs { flex-direction: column; gap: 8px; padding: 0; overflow: visible; }
.synth-side .theme-tab { flex: none; min-width: 0; width: 100%; gap: 3px; padding: 9px 11px 10px; }
.synth-side .theme-tab:hover:not(:disabled):not(.is-current) { transform: translateX(2px); box-shadow: none; }
.synth-side .theme-tab-n { font-size: 10px; }
.synth-side .theme-tab-name { font-size: 13.5px; line-height: 1.3; }
.synth-side .theme-tab-meta { font-size: 11.5px; }
@media (max-width: 900px) {
  .synth-side .theme-tabs { flex-direction: row; overflow-x: auto; padding: 2px 6px 6px 2px; }
  .synth-side .theme-tab { flex: 0 0 min(64vw, 220px); }
}

/* The synthesis reads as set text: justified, hyphenated so the word gaps stay
   even, with clear space between its paragraphs. */
.theme-paragraph p, .synth-main .report-body p { text-align: justify; -webkit-hyphens: auto; hyphens: auto; }
.theme-paragraph p { margin: 0 0 18px; }
.theme-paragraph p:last-child { margin-bottom: 0; }

/* The 3D wait (js/synth-scene.js): its stage is held from the start, so the
   page doesn't jump, and the scene fades in once three.js has loaded. */
.sl-3d { position: relative; width: min(760px, 100%); aspect-ratio: 16 / 9; pointer-events: none; }
.sl-3d canvas { display: block; width: 100%; height: 100%; opacity: 0; transition: opacity .8s cubic-bezier(.16, 1, .3, 1); }
.sl.is-3d .sl-3d canvas { opacity: 1; }
@media (max-width: 560px) { .sl-3d { aspect-ratio: 4 / 3; } }
/* A cancelled run: the sheet tips and drops away, the track goes quiet. */
.sl.is-cancelled .sl-sheet { opacity: 0; transform: translateY(18px) rotate(-7deg); transition: transform .6s cubic-bezier(.55, 0, .75, .2), opacity .6s ease-in; }
.sl.is-cancelled .sl-message { color: var(--riso-red); }
.sl.is-cancelled .sl-bar i { background: var(--muted); animation: none; }
.sl.is-cancelled .sl-seg.is-current .sl-n, .sl.is-cancelled .sl-seg.is-current .sl-label { color: var(--muted); }
