:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f3f2ee;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #6f6e69;
  --hairline: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.12);
  --accent: #2a78d6;
  --accent-ink: #1c5cab;
  --accent-wash: rgba(42, 120, 214, 0.10);
  --match: #b4460f;
  --match-wash: rgba(235, 104, 52, 0.14);
  --error: #b42d2d;
  --error-wash: rgba(208, 59, 59, 0.08);
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  /* the monospace fonts of the 2015 interface (CodeMirror); Consolas on Windows */
  --mono: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono",
          "Bitstream Vera Sans Mono", "Courier New", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", sans-serif;
  --radius: 8px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #232321;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --muted: #9a9890;
    --hairline: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.12);
    --accent: #3987e5;
    --accent-ink: #86b6ef;
    --accent-wash: rgba(57, 135, 229, 0.16);
    --match: #f08a5d;
    --match-wash: rgba(217, 89, 38, 0.22);
    --error: #e66767;
    --error-wash: rgba(230, 103, 103, 0.12);
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #232321;
  --ink: #f0efec;
  --ink-2: #c3c2b7;
  --muted: #9a9890;
  --hairline: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.12);
  --accent: #3987e5;
  --accent-ink: #86b6ef;
  --accent-wash: rgba(57, 135, 229, 0.16);
  --match: #f08a5d;
  --match-wash: rgba(217, 89, 38, 0.22);
  --error: #e66767;
  --error-wash: rgba(230, 103, 103, 0.12);
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--page);
  color: var(--ink);
  font: 15px/1.5 var(--sans);
}
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 16px; }

header.top {
  border-bottom: 1px solid var(--hairline);
  background: var(--surface);
}
header.top .wrap {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px 20px;
  min-height: 56px; padding-top: 8px; padding-bottom: 8px;
}
.brand { font-weight: 650; font-size: 17px; letter-spacing: -0.01em; margin-right: auto; }
.brand small { font-weight: 400; color: var(--muted); margin-left: 8px; font-size: 13px; }
label.inline { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); font-size: 14px; }

select, button, textarea, input { font: inherit; color: inherit; }
select {
  background: var(--surface); border: 1px solid var(--border); border-radius: 6px;
  padding: 5px 8px; max-width: 100%;
}
button {
  background: var(--surface); border: 1px solid var(--border); border-radius: 6px;
  padding: 6px 14px; cursor: pointer;
}
button:hover:not(:disabled) { background: var(--surface-2); }
button:disabled { opacity: 0.5; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover:not(:disabled) { filter: brightness(1.08); background: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

main { padding: 20px 0 64px; }
.panel {
  background: var(--surface); border: 1px solid var(--hairline); border-radius: var(--radius);
  padding: 16px;
}
.editor-head {
  display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; margin-bottom: 10px;
}
.editor-head h2 { font-size: 14px; font-weight: 600; margin: 0 auto 0 0; color: var(--ink-2); }
/* The query editor: a transparent textarea over a <pre> that shows the same
   text with relation names colored. Both must have identical metrics. */
.editor { position: relative; background: var(--page); border-radius: 6px; }
textarea#query, .editor pre.hl {
  font: 14px/20px var(--mono); tab-size: 4; letter-spacing: normal;   /* as in 2015 */
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 6px;
  white-space: pre; overflow-wrap: normal; margin: 0;
}
textarea#query {
  position: relative; z-index: 1; display: block;
  width: 100%; min-height: 130px; resize: vertical; overflow: auto;
  background: transparent; color: transparent; caret-color: var(--ink);
}
textarea#query::selection { color: transparent; background: var(--accent-wash); }
.editor pre.hl {
  position: absolute; inset: 0; overflow: hidden; pointer-events: none;
  color: var(--ink); border-color: transparent;
}
.editor pre.hl .rel { color: var(--accent-ink); }
.editor-foot { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 10px; }
.hint { color: var(--muted); font-size: 13px; }
.status { margin-left: auto; color: var(--ink-2); font-size: 14px; font-variant-numeric: tabular-nums; }

.progress { height: 6px; background: var(--hairline); border-radius: 3px; overflow: hidden; margin-top: 12px; visibility: hidden; }
.progress.on { visibility: visible; }
.progress > div { height: 100%; width: 0; background: var(--accent); transition: width 0.3s; }
.status.busy { color: var(--ink); font-weight: 600; }

/* a running query: spinner on Run, old results dimmed, a note above them */
.spinner {
  display: inline-block; width: 14px; height: 14px; flex: none; vertical-align: -2px;
  border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
button.primary .spinner { margin-right: 6px; }
.loading {
  display: flex; align-items: center; gap: 10px; margin: 4px 0 12px; padding: 12px 14px;
  border-radius: 6px; background: var(--accent-wash); color: var(--accent-ink); font-size: 14px;
}
.loading[hidden] { display: none; }
#results.stale { opacity: 0.35; pointer-events: none; transition: opacity 0.2s; }
#results.stale > .empty { display: none; }
.progress.indeterminate > div { width: 30%; animation: slide 1.1s infinite ease-in-out; }
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(340%); } }

.error {
  margin-top: 12px; padding: 10px 12px; border-radius: 6px;
  background: var(--error-wash); color: var(--error); font-size: 14px; white-space: pre-wrap;
}

nav.tabs { display: flex; gap: 4px; margin: 24px 0 12px; border-bottom: 1px solid var(--hairline); flex-wrap: wrap; }
nav.tabs button {
  border: none; border-bottom: 2px solid transparent; border-radius: 0; background: none;
  padding: 8px 12px; color: var(--ink-2); margin-bottom: -1px;
}
nav.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }
nav.tabs .spacer { flex: 1; }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: center; margin-bottom: 12px; }
.toolbar .count { font-weight: 600; font-variant-numeric: tabular-nums; margin-right: auto; }
a.button {
  display: inline-block; text-decoration: none; color: inherit;
  border: 1px solid var(--border); border-radius: 6px; padding: 5px 12px; background: var(--surface);
}
a.button:hover { background: var(--surface-2); }

.result { background: var(--surface); border: 1px solid var(--hairline); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 10px; }
.result .where { color: var(--muted); font-size: 13px; display: flex; flex-wrap: wrap; gap: 4px 12px; }
.result .where b { color: var(--ink-2); font-weight: 600; font-variant-numeric: tabular-nums; }
.result .text { margin: 6px 0 8px; }
.result .text mark { background: var(--accent-wash); color: inherit; border-radius: 3px; padding: 0 1px; }
.meta { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.meta span { font-size: 12.5px; background: var(--surface-2); border-radius: 4px; padding: 1px 7px; color: var(--ink-2); }
.meta span b { color: var(--ink); font-weight: 600; }
pre.tree {
  margin: 0; font: 13px/1.5 var(--mono); overflow-x: auto; padding: 8px 10px;
  background: var(--page); border-radius: 6px; color: var(--ink-2);
}
pre.tree .lab { color: var(--ink); }
pre.tree .m { color: var(--match); background: var(--match-wash); border-radius: 3px; font-weight: 600; }
pre.tree .a { outline: 1.5px solid var(--match); outline-offset: 0; }
pre.tree .ec { color: var(--muted); }
pre.tree .lem { color: var(--muted); }
.more { text-align: center; margin: 16px 0; }

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

/* summary */
.sum-controls { display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: center; margin-bottom: 14px; }
.chart-card { background: var(--surface); border: 1px solid var(--hairline); border-radius: var(--radius); padding: 14px 16px 10px; margin-bottom: 16px; }
.chart-card h3 { margin: 0; font-size: 15px; font-weight: 600; }
.chart-card .sub { color: var(--muted); font-size: 13px; margin: 2px 0 8px; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 13px; color: var(--ink-2); margin-bottom: 4px; }
.legend i { display: inline-block; width: 14px; height: 2px; border-radius: 1px; vertical-align: middle; margin-right: 6px; }
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid line { stroke: var(--hairline); stroke-width: 1; }
.chart .axis line { stroke: var(--axis); stroke-width: 1; }
.chart text { fill: var(--muted); font: 12px var(--sans); font-variant-numeric: tabular-nums; }
.chart text.dl { fill: var(--ink-2); }
.chart .xhair { stroke: var(--axis); stroke-width: 1; }
.tip {
  position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--border);
  border-radius: 6px; padding: 6px 9px; font-size: 13px; box-shadow: 0 4px 14px rgba(0,0,0,0.12);
  white-space: nowrap; display: none; z-index: 2;
}
.tip .h { color: var(--muted); margin-bottom: 2px; }
.tip .row { display: flex; align-items: center; gap: 8px; }
.tip .row i { width: 12px; height: 2px; border-radius: 1px; }
.tip .row b { font-variant-numeric: tabular-nums; }
.tip .row span { color: var(--ink-2); }

table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--hairline); border-radius: var(--radius); margin-bottom: 16px; }
table.data th, table.data td { padding: 6px 10px; text-align: right; border-bottom: 1px solid var(--hairline); white-space: nowrap; }
table.data th:first-child, table.data td:first-child { text-align: left; }
table.data th { color: var(--ink-2); font-weight: 600; background: var(--surface-2); position: sticky; top: 0; }
table.data tr:last-child td { border-bottom: none; }
details > summary { cursor: pointer; color: var(--ink-2); margin: 8px 0; }

/* help */
.help { max-width: 760px; }
.help h3 { font-size: 15px; margin: 22px 0 6px; }
.help code, .help pre { font-family: var(--mono); font-size: 13px; }
.help pre { background: var(--surface); border: 1px solid var(--hairline); border-radius: 6px; padding: 10px 12px; overflow-x: auto; }
.help table { border-collapse: collapse; font-size: 14px; }
.help td { padding: 3px 14px 3px 0; vertical-align: top; }
.help td:first-child { font-family: var(--mono); font-size: 13px; white-space: nowrap; }

.corpus-info { color: var(--muted); font-size: 13px; margin-top: 6px; }

@media (max-width: 640px) {
  .status { margin-left: 0; width: 100%; }
}
header.top label.inline { min-width: 0; max-width: 100%; }
header.top select { min-width: 0; width: 100%; max-width: 420px; text-overflow: ellipsis; }
@media (max-width: 640px) {
  header.top label.inline:has(#corpus) { width: 100%; }
}
[hidden] { display: none !important; }
.editor-head label.inline { min-width: 0; max-width: 100%; }
.editor-head select { min-width: 0; max-width: 100%; }
@media (max-width: 640px) {
  .editor-head label.inline { width: 100%; }
  .editor-head select { flex: 1; }
}
h3.table-title { font-size: 14px; font-weight: 600; color: var(--ink-2); margin: 20px 0 8px; }
table.data.by-text th:nth-child(2), table.data.by-text td:nth-child(2) { text-align: left; }

/* header links */
header.top nav.links a { color: var(--ink-2); text-decoration: none; font-size: 14px; }
header.top nav.links a:hover { color: var(--ink); text-decoration: underline; }

/* the selected corpus: who made it, its license, how to cite it.
   Slim (one line on wide screens) but set off by an accent edge. */
.corpus-card {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 16px;
  margin-bottom: 12px; padding: 8px 12px 8px 14px;
  background: var(--accent-wash); border-left: 3px solid var(--accent); border-radius: 6px;
  font-size: 14px;
}
.cc-text { flex: 1 1 360px; min-width: 0; display: flex; flex-wrap: wrap; gap: 2px 10px; align-items: baseline; }
.cc-title { font-weight: 600; }
.cc-by { color: var(--ink-2); }
.cc-meta { color: var(--muted); font-size: 13px; }
.cc-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.cc-actions .button, .cc-actions button { font-size: 13px; padding: 4px 10px; }

/* citation dialog */
dialog#cite-dialog {
  border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px;
  background: var(--surface); color: var(--ink); width: min(680px, calc(100vw - 32px));
  box-shadow: 0 12px 40px rgba(0,0,0,0.25);
}
dialog#cite-dialog::backdrop { background: rgba(0,0,0,0.35); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; }
.dlg-head h2 { font-size: 17px; margin: 0; }
dialog h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin: 16px 0 6px; }
button.close { border: none; background: none; font-size: 22px; line-height: 1; padding: 2px 8px; }
.cite-apa { margin: 0; line-height: 1.55; overflow-wrap: anywhere; }
.cite-bib { margin: 0; font: 12.5px/1.5 var(--mono); background: var(--page); border: 1px solid var(--hairline);
  border-radius: 6px; padding: 10px 12px; overflow-x: auto; white-space: pre; }
.dlg-row { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.copied { color: var(--muted); font-size: 13px; }
header.top nav.links { display: flex; gap: 16px; }

/* "↓ N results" after a query when the results are below the fold */
.results-pill {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 5;
  background: var(--accent); color: #fff; border: none; border-radius: 999px;
  padding: 9px 18px; font-weight: 600; box-shadow: 0 6px 20px rgba(0,0,0,0.22);
  animation: pill-in 0.25s ease-out;
}
/* as specific as the general button:hover rule, which would otherwise make it light */
button.results-pill:hover:not(:disabled) { filter: brightness(1.1); background: var(--accent); color: #fff; }
@keyframes pill-in { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }
@media (prefers-reduced-motion: reduce) { .results-pill { animation: none; } .spinner { animation-duration: 2.4s; } }
