:root {
  /* Light theme (default). Coral = primary, mint = secondary. Fills use the bright shades
     with dark text; text and lines use the deep shades, which keep readable contrast. */
  --bg: #fbfaf8;
  --surface: #ffffff;
  --text: #1f1d1c;
  --muted: #67625e;
  --border: #e4dfda;
  --primary: #ff7f66;          /* coral fill */
  --primary-text: #2b1410;     /* text on coral */
  --accent: #c2412d;           /* coral for links, focus, lines */
  --secondary: #98e2c6;        /* mint fill */
  --secondary-strong: #1f7a5a; /* mint for text and lines */
  --secondary-soft: #e3f6ee;   /* mint background (tags, selected filters) */
  --mark: #ffd9cf;             /* search-term highlight */
  --quote: #fff4f1;
  --danger: #b42318;
  --radius: 0;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: Georgia, "Times New Roman", serif;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #161514;
  --surface: #1f1e1d;
  --text: #ece8e4;
  --muted: #a8a19b;
  --border: #34312e;
  --primary: #ff8a73;
  --primary-text: #2b1410;
  --accent: #ff9b87;
  --secondary: #6fd3ae;
  --secondary-strong: #7fe0bd;
  --secondary-soft: #1d3a30;
  --mark: #6b3226;
  --quote: #26211f;
  --danger: #f2877a;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--font);
}

a { color: var(--accent); }
button, input, select { font: inherit; color: inherit; }

/* -- header ------------------------------------------------------------------------------ */

.top {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 16px max(16px, calc((100vw - 1200px) / 2));
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
}
.brand { display: flex; align-items: baseline; gap: 12px; }
.logo { font: 700 22px/1 var(--serif); text-decoration: none; color: var(--text); }
.tagline { color: var(--muted); font-size: 14px; }

.search { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
.modes { display: flex; gap: 4px; flex-wrap: wrap; }
.modes button {
  border: 1px solid var(--border);
  background: transparent;
  padding: 4px 14px;
  border-radius: 0;
  cursor: pointer;
  font-size: 14px;
}
.modes button[aria-selected="true"] {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-text);
  font-weight: 600;
}
.modes button:disabled { opacity: .45; cursor: not-allowed; }

.search-row { display: flex; gap: 8px; }
.search-row input {
  flex: 1;
  min-width: 0;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 0;
  background: var(--bg);
  font-size: 17px;
}
.search-row input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.primary:hover, .modes button:hover:not(:disabled) { filter: brightness(0.95); }
.primary {
  padding: 10px 18px;
  border: 0;
  border-radius: 0;
  background: var(--primary);
  color: var(--primary-text);
  cursor: pointer;
  font-weight: 600;
}
.hint { margin: 0; color: var(--muted); font-size: 13px; }

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

.layout {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 28px;
  padding: 24px max(16px, calc((100vw - 1200px) / 2));
}
@media (max-width: 800px) {
  .layout { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .filters details:not([open]) section { display: none; }
}

.filters details > summary { font-weight: 600; cursor: pointer; margin-bottom: 8px; }
@media (min-width: 801px) { .filters details > summary { pointer-events: none; list-style: none; } }
.filters section { margin: 14px 0; }
.filters h3 {
  margin: 0 0 6px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
}
.filters input, .filters select {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 0;
  background: var(--surface);
}
.years { display: flex; align-items: center; gap: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 0;
  padding: 2px 10px;
  font-size: 13px;
  cursor: pointer;
  text-align: left;
}
.chip .n { color: var(--muted); margin-left: 4px; font-variant-numeric: tabular-nums; }
.chip[aria-pressed="true"] { background: var(--secondary-soft); border-color: var(--secondary-strong); color: var(--text); }
.link { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; }
.chips .link { font-size: 13px; }
.chips .chip[hidden] { display: none; }
.note-empty { color: var(--muted); font-size: 13px; margin: 0; }
@media (max-width: 480px) {
  .primary:hover, .modes button:hover:not(:disabled) { filter: brightness(0.95); }
.primary { padding: 10px 12px; }
  .brand { flex-wrap: wrap; row-gap: 2px; }
}

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

.summary { color: var(--muted); font-size: 14px; margin-bottom: 12px; min-height: 1.5em; }
.summary.error { color: var(--danger); }

.hit, .extract {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 16px 18px;
  margin-bottom: 12px;
}
.hit h2 { margin: 0 0 4px; font: 600 18px/1.35 var(--serif); }
.hit h2 button {
  background: none; border: 0; padding: 0; text-align: left; cursor: pointer;
  font: inherit; color: var(--text);
}
.hit h2 button:hover { color: var(--accent); text-decoration: underline; }
.meta { color: var(--muted); font-size: 13px; display: flex; flex-wrap: wrap; gap: 4px 10px; }
.cat {
  display: inline-block;
  background: var(--secondary-soft);
  color: var(--secondary-strong);
  border: 1px solid var(--secondary);
  border-radius: 0;
  padding: 0 6px;
  font-size: 12px;
}
.authors { font-size: 13px; margin-top: 2px; }
.pages { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 6px; }
.pages li { font-size: 14px; display: grid; grid-template-columns: 64px minmax(0, 1fr); gap: 8px; }
.pages a.page { font-size: 13px; white-space: nowrap; font-variant-numeric: tabular-nums; }
mark { background: var(--mark); color: inherit; padding: 0 1px; border-radius: 0; }

.extract blockquote {
  margin: 0 0 10px;
  padding: 12px 14px;
  background: var(--quote);
  border-left: 4px solid var(--primary);
  border-radius: 0;
  font: 16px/1.55 var(--serif);
}
.extract blockquote { margin-top: 8px; }
.extract blockquote.clamp {
  display: -webkit-box; -webkit-line-clamp: 8; line-clamp: 8; -webkit-box-orient: vertical;
  overflow: hidden;
}
.extract .more { font-size: 13px; margin-bottom: 6px; }
.plan ol { margin: 4px 0 0; padding-left: 20px; }
.plan {
  font-size: 13px; color: var(--muted); margin-bottom: 14px;
  background: var(--surface); border: 1px dashed var(--border); border-radius: 0;
  padding: 10px 14px;
}
.plan code { font-size: 12px; }

.pager { display: flex; gap: 6px; flex-wrap: wrap; margin: 16px 0 40px; }
.pager button {
  border: 1px solid var(--border); background: var(--surface); border-radius: 0;
  padding: 4px 10px; cursor: pointer; font-variant-numeric: tabular-nums;
}
.pager button[aria-current="page"] { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }

.spinner {
  display: inline-block; width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--border); border-top-color: var(--primary);
  animation: spin .8s linear infinite; vertical-align: -2px; margin-right: 6px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty { color: var(--muted); padding: 24px 0; }

/* -- drawer ------------------------------------------------------------------------------ */

.drawer {
  position: fixed; inset: 0 0 0 auto; width: min(520px, 100vw);
  background: var(--surface); border-left: 1px solid var(--border);
  box-shadow: -8px 0 24px rgba(0, 0, 0, .12);
  overflow-y: auto; padding: 20px 22px 40px; z-index: 10;
}
.drawer h2 { font: 600 20px/1.3 var(--serif); margin: 0 30px 8px 0; }
.drawer .close {
  position: absolute; top: 12px; right: 14px; border: 0; background: none;
  font-size: 26px; cursor: pointer; color: var(--muted);
}
.drawer dl { display: grid; grid-template-columns: 110px minmax(0, 1fr); gap: 6px 10px; font-size: 14px; }
.drawer dt { color: var(--muted); }
.drawer dd { margin: 0; }
.bar { display: grid; grid-template-columns: minmax(0, 1fr) 46px; gap: 8px; font-size: 13px; margin: 4px 0; }
.bar .track { grid-column: 1 / -1; height: 6px; background: var(--border); border-radius: 0; overflow: hidden; }
.bar .fill { height: 100%; background: var(--muted); opacity: .5; }
.bar.kept .fill { background: var(--secondary-strong); opacity: 1; }
.bar.kept > span:first-child { font-weight: 600; }
.bar .p { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
.files a { display: inline-block; margin: 0 10px 4px 0; font-size: 14px; }

/* -- navigation and about page ----------------------------------------------------------- */

.nav { margin-left: auto; display: flex; gap: 14px; font-size: 14px; }
.nav a { color: var(--muted); text-decoration: none; }
.nav a[aria-current="page"], .nav a:hover { color: var(--text); text-decoration: underline; }

.about { max-width: 860px; margin: 0 auto; padding: 24px 16px 60px; }
.about h1 { font: 700 30px/1.2 var(--serif); margin: 8px 0 12px; }
.about h2 { font: 600 21px/1.3 var(--serif); margin: 36px 0 10px; }
.about .lead { font-size: 18px; }
.about .byline { color: var(--muted); }
.about .mermaid {
  background: var(--surface); border: 1px solid var(--border); border-radius: 0;
  padding: 16px; overflow-x: auto; text-align: center;
}
.about .steps li, .about ul li { margin: 6px 0; }
.about .modes-list dt { font-weight: 600; margin-top: 10px; }
.about .modes-list dd { margin: 2px 0 0; }
.sources { width: 100%; border-collapse: collapse; font-size: 14px; }
.sources th, .sources td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border); }
.sources .num { text-align: right; font-variant-numeric: tabular-nums; }

/* -- theme toggle ------------------------------------------------------------------------- */

.theme-toggle {
  border: 1px solid var(--border); background: var(--surface); color: var(--muted);
  font-size: 13px; padding: 2px 8px; cursor: pointer;
}
.theme-toggle:hover { color: var(--text); border-color: var(--secondary-strong); }
.top { border-bottom: 3px solid var(--primary); }

/* -- footer, source credits, legal pages ---------------------------------------------- */

.site-footer {
  border-top: 1px solid var(--border); margin-top: 40px;
  padding: 16px max(16px, calc((100vw - 1200px) / 2)) 28px; color: var(--muted); font-size: 13px;
}
.site-footer nav { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-bottom: 6px; }
.site-footer a { color: var(--muted); }
.site-footer a:hover { color: var(--text); }
.site-footer p { margin: 0; max-width: 820px; }
.source { font-size: 12px; color: var(--muted); margin-top: 8px; }
.source a { color: var(--muted); }
.ai-note { text-transform: none; letter-spacing: 0; font-weight: 400; }
.legal section { margin-top: 8px; }
.legal td { vertical-align: top; }
.todo { color: var(--danger); font-weight: 600; }

/* -- counter-argument agent page ------------------------------------------------------- */

.agent-purpose {
  display: block; margin: 4px 0 16px; padding: 12px 16px;
  background: var(--secondary-soft); border-left: 4px solid var(--secondary-strong);
  font-size: 15px;
}
.agent-purpose strong { display: block; margin-bottom: 2px; }
.agent-form { display: grid; gap: 8px; margin: 20px 0 16px; }
.agent-form .label { font-weight: 600; }
.agent-form textarea {
  width: 100%; min-height: 200px; resize: vertical; padding: 10px 14px;
  border: 1px solid var(--border); border-radius: 0; background: var(--surface);
  font: 16px/1.5 var(--font); color: var(--text);
}
.agent-form textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.agent-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
.agent-row .primary { margin-left: auto; }
.agent-dialog {
  width: min(420px, calc(100vw - 32px)); padding: 20px; border: 1px solid var(--border);
  border-radius: var(--radius); background: var(--surface); color: var(--text);
}
.agent-dialog::backdrop { background: rgb(0 0 0 / 0.45); }
.agent-dialog form { display: grid; gap: 10px; }
.agent-dialog h2 { margin: 0; font-size: 18px; }
.agent-dialog input {
  font: inherit; padding: 8px 10px; border: 1px solid var(--border);
  border-radius: var(--radius); background: var(--bg); color: var(--text);
}
.agent-dialog input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.agent-dialog .error { margin: 0; color: var(--danger); font-size: 14px; }
.hint.over { color: var(--danger); font-weight: 600; }
.secondary {
  padding: 9px 16px; border: 1px solid var(--secondary-strong); border-radius: 0;
  background: var(--secondary-soft); color: var(--text); cursor: pointer;
}
.secondary:hover:not(:disabled) { background: var(--secondary); color: #10291f; }
.primary:disabled, .secondary:disabled { opacity: .5; cursor: not-allowed; }

.agent-report { border-top: 3px solid var(--secondary-strong); padding-top: 12px; }
.agent-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
.agent-report h2 { font: 700 26px/1.2 var(--serif); margin: 18px 0 8px; }
.agent-report h3 { font: 600 21px/1.3 var(--serif); margin: 28px 0 8px; }
.agent-report h4 { font: 600 17px/1.35 var(--serif); margin: 20px 0 6px; }
.agent-report blockquote {
  margin: 10px 0 16px; padding: 14px 18px; background: var(--quote);
  border-left: 4px solid var(--primary); font: 15px/1.55 var(--serif);
  overflow-wrap: anywhere;
}
.agent-report blockquote p { margin: 0 0 6px; }
.agent-report blockquote p:last-child { font: 13px/1.4 var(--font); color: var(--muted); margin: 0; }
.agent-report pre.code { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); padding: 10px; }
.agent-report .mermaid {
  background: var(--surface); border: 1px solid var(--border); padding: 16px;
  overflow-x: auto; text-align: center; font: 14px/1.4 var(--font); white-space: normal;
}
/* The graph fits the page width; a click shows it at full size (scroll to read it). */
.agent-report .mermaid svg { max-width: 100%; height: auto; cursor: zoom-in; }
.agent-report .mermaid.full svg { max-width: none; cursor: zoom-out; }
.agent-report .mermaid-hint { margin: 6px 0 0; font-size: 13px; color: var(--muted); text-align: right; }
.agent-example { margin-top: 28px; }
.agent-example summary {
  cursor: pointer; font: 700 22px/1.2 var(--serif); padding: 8px 0;
}
.agent-example-input {
  margin: 10px 0 16px; padding: 12px 16px; background: var(--quote);
  border-left: 4px solid var(--secondary-strong); font: 15px/1.55 var(--serif);
}
.agent-report a.ref { text-decoration: none; font-variant-numeric: tabular-nums; }
.agent-report li:target { background: var(--mark); }
.agent-report li { margin: 6px 0; overflow-wrap: anywhere; }
.table-wrap { overflow-x: auto; }
