:root {
  color-scheme: light;
  --bg: #fcfcfb;
  --surface: #ffffff;
  --surface-2: #f3f2ef;
  --border: #e3e2dd;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #74736e;
  --link: #1c5cab;
  --accent: #2a78d6;
  --mark: #ffe58a;
  --s1: #2a78d6;   /* authored: categorical slot 1 */
  --s2: #eb6834;   /* other:    categorical slot 2 */
  --grid: #ebeae6;
  --err: #b42318;
  --focus: #2a78d6;
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #1a1a19;
    --surface: #222221;
    --surface-2: #2b2b29;
    --border: #3a3a37;
    --text: #f4f4f2;
    --text-2: #c3c2b7;
    --muted: #9b9a92;
    --link: #86b6ef;
    --accent: #3987e5;
    --mark: #6b5600;
    --s1: #3987e5;
    --s2: #d95926;
    --grid: #33332f;
    --err: #ff8a80;
    --focus: #86b6ef;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, system-ui, sans-serif;
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
h1 { font-size: 1.5rem; margin: .4rem 0 .8rem; line-height: 1.25; overflow-wrap: anywhere; }
h2 { font-size: 1rem; margin: 0 0 .6rem; color: var(--text-2); font-weight: 600; }
code, kbd, pre { font-family: var(--mono); font-size: .88em; }
kbd { border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 4px; padding: 0 .3em; background: var(--surface); }
mark { background: var(--mark); color: inherit; border-radius: 2px; padding: 0 1px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.err { color: var(--err); }
.nowrap { white-space: nowrap; }
.prewrap { white-space: pre-wrap; }
.wrap code { overflow-wrap: anywhere; font-size: .8em; }

/* header */
.top {
  position: sticky; top: 0; z-index: 5; display: flex; flex-wrap: wrap; gap: .4rem 1.2rem; align-items: center;
  padding: .55rem 16px; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; color: var(--text); letter-spacing: .02em; }
.top nav { display: flex; gap: .9rem; }
.top nav a { color: var(--text-2); }
.top nav a[aria-current] { color: var(--text); font-weight: 600; }
.quick { margin-left: auto; flex: 0 1 280px; }
.quick input { width: 100%; }
main { max-width: 1200px; margin: 0 auto; padding: 1rem 16px 2rem; }
.foot { max-width: 1200px; margin: 0 auto; padding: 1rem 16px 2rem; font-size: .8rem; border-top: 1px solid var(--border); }

input, select, button {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: .35rem .6rem;
}
button { cursor: pointer; background: var(--surface-2); }
input[type=checkbox] { padding: 0; }

.head-row { display: flex; flex-wrap: wrap; gap: .6rem 1rem; align-items: center; justify-content: space-between; }
.seg-toggle { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; flex-wrap: wrap; }
.seg-toggle a, .seg-toggle button { padding: .3rem .7rem; color: var(--text-2); border: 0; border-radius: 0; background: transparent; font-size: .9rem; }
.seg-toggle [aria-current=true], .seg-toggle [aria-pressed=true] { background: var(--surface-2); color: var(--text); font-weight: 600; }

/* overview */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .8rem; margin-bottom: 1rem; }
.tile, .card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: .8rem 1rem; }
.card { margin-bottom: 1rem; }
.tl { font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.tv { font-size: 1.6rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.tv.small { font-size: 1rem; padding: .4rem 0; }
.ts { font-size: .8rem; color: var(--text-2); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 760px) { .two { grid-template-columns: 1fr; } }

.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .axis { stroke: var(--border); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .s1 { fill: var(--s1); }
.chart .s2 { fill: var(--s2); }
.chart .hit { fill: transparent; }
.chart .col:hover .hit { fill: var(--surface-2); }
.legend { display: flex; flex-wrap: wrap; gap: .3rem 1rem; font-size: .82rem; color: var(--text-2); margin-bottom: .3rem; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: .35rem; vertical-align: -1px; }
.sw.s1 { background: var(--s1); } .sw.s2 { background: var(--s2); }
.tableview summary { font-size: .82rem; color: var(--muted); cursor: pointer; margin-top: .3rem; }

.hbars { width: 100%; border-collapse: collapse; font-size: .88rem; }
.hbars th { text-align: left; font-weight: 500; white-space: nowrap; padding: .12rem .6rem .12rem 0; width: 1%; }
.hbars td.bar { width: 100%; padding: .12rem 0; }
.hbars .seg { display: inline-block; height: 12px; vertical-align: middle; }
.hbars .seg.s1 { background: var(--s1); border-radius: 0 0 0 0; }
.hbars .seg.s2 { background: var(--s2); margin-left: 2px; border-radius: 0 3px 3px 0; }
.hbars .seg.s1:last-child { border-radius: 0 3px 3px 0; }
.hbars td.n { text-align: right; padding-left: .6rem; font-variant-numeric: tabular-nums; color: var(--text-2); }

table.data { border-collapse: collapse; font-size: .88rem; width: 100%; }
table.data th, table.data td { text-align: left; padding: .3rem .5rem; border-bottom: 1px solid var(--border); vertical-align: top; }
table.data td, table.data .n { font-variant-numeric: tabular-nums; }
table.data .n { text-align: right; }
table.data.compact { width: auto; }
table.kv th { width: 9rem; color: var(--text-2); font-weight: 500; white-space: nowrap; }
table.kv td { overflow-wrap: anywhere; }
.tablewrap { overflow-x: auto; }
table.sources tr.notes td { border-bottom: 1px solid var(--border); padding-top: 0; font-size: .82rem; color: var(--text-2); }
table.sources tr:has(+ tr.notes) > * { border-bottom: 0; }
table.sources dl { display: grid; grid-template-columns: max-content 1fr; gap: .2rem .8rem; margin: .4rem 0; }
table.sources dt { color: var(--muted); }
table.sources dd { margin: 0; }

.badge {
  display: inline-block; font-size: .75rem; line-height: 1.5; padding: 0 .45rem; border-radius: 999px;
  background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); white-space: nowrap;
}
.badge.src { color: var(--text); }
.au-authored { border-color: var(--s1); }
.au-received, .au-generated, .au-curated, .au-ocr, .au-transcribed, .au-co-authored { border-style: dashed; }
.st-active { border-color: var(--s1); color: var(--text); }
.st-blocked { border-color: var(--err); }

/* search */
.searchform { display: grid; gap: .5rem; margin-bottom: .6rem; }
.searchform #q { font-size: 1.1rem; padding: .55rem .8rem; width: 100%; }
.opts { display: flex; flex-wrap: wrap; gap: .4rem 1rem; align-items: center; font-size: .88rem; color: var(--text-2); }
.resline { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; margin: .4rem 0 .8rem; }
.chip { font-size: .8rem; padding: .05rem .5rem; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); color: var(--text); }
.chip.on { border-color: var(--accent); }
.searchgrid { display: grid; grid-template-columns: 220px 1fr; gap: 1.2rem; }
@media (max-width: 760px) {
  .searchgrid { grid-template-columns: 1fr; }
  .facets { order: 2; }
}
.facet summary { font-weight: 600; font-size: .85rem; color: var(--text-2); cursor: pointer; padding: .2rem 0; }
.facet ul { list-style: none; margin: 0 0 .6rem; padding: 0; font-size: .85rem; max-height: 22rem; overflow-y: auto; }
.facet li { display: flex; justify-content: space-between; gap: .5rem; padding: .05rem .3rem; border-radius: 6px; }
.facet li a { overflow-wrap: anywhere; }
.facet li.on { background: var(--surface-2); font-weight: 600; }
.facet .n { color: var(--muted); font-variant-numeric: tabular-nums; }

ol.hits { list-style: none; margin: 0; padding: 0; min-width: 0; }
.hit { padding: .55rem .7rem; border: 1px solid transparent; border-radius: 10px; margin-bottom: .2rem; min-width: 0; }
.hit:hover { background: var(--surface); border-color: var(--border); }
.hit.sel { background: var(--surface); border-color: var(--accent); }
.hit .meta, .record .meta { display: flex; flex-wrap: wrap; gap: .35rem .5rem; align-items: center; font-size: .8rem; color: var(--text-2); }
.hit .date { font-variant-numeric: tabular-nums; color: var(--muted); }
.hit .title { display: block; font-weight: 600; margin-top: .15rem; overflow-wrap: anywhere; }
.hit .title.untitled { font-weight: 400; color: var(--text); }
.snip { font-size: .9rem; color: var(--text-2); overflow-wrap: anywhere; margin-top: .1rem; }
.pager { display: flex; gap: 1rem; align-items: center; justify-content: center; margin: 1rem 0; flex-wrap: wrap; }
.daynav { justify-content: flex-start; margin: 0 0 .5rem; }
.dayjump { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; font-size: .9rem; }

/* record + thread */
.record h1 { margin-top: .5rem; }
.threadnav { display: flex; gap: 1rem; flex-wrap: wrap; align-items: center; margin: -.3rem 0 .8rem; font-size: .9rem; }
.body { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 1rem 1.2rem; margin-bottom: 1rem; }
pre.plain, pre.code { white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; font-size: .9rem; }
pre.plain { font-family: inherit; font-size: .95rem; }
.md { overflow-wrap: anywhere; }
.md pre { background: var(--surface-2); padding: .6rem .8rem; border-radius: 8px; overflow-x: auto; }
.md img { max-width: 100%; }
.md table { border-collapse: collapse; } .md td, .md th { border: 1px solid var(--border); padding: .2rem .4rem; }
.md blockquote { margin: 0; padding-left: .8rem; border-left: 3px solid var(--border); color: var(--text-2); }
.links { display: flex; gap: .6rem; flex-wrap: wrap; align-items: baseline; }
code.sel { user-select: all; overflow-wrap: anywhere; }
.people { margin: 0; padding-left: 1.2rem; }
.tree { display: inline-block; vertical-align: top; }
.tree summary { cursor: pointer; }
.tree ul, .tree ol { margin: .1rem 0 .1rem .3rem; padding-left: 1rem; border-left: 1px dotted var(--border); font-family: var(--mono); font-size: .82rem; }
.tree li { overflow-wrap: anywhere; }
.tk { color: var(--text-2); }
.tv-str { color: var(--text); } .tv-num, .tv-bool { color: var(--link); } .tv-null { color: var(--muted); font-style: italic; }
.thread .msg { border-color: var(--border); background: var(--surface); margin-bottom: .5rem; }
.thread .msg.me { border-left: 3px solid var(--s1); }
.thread .msg.target { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 30%, transparent); }
.people-inline { display: flex; flex-wrap: wrap; gap: .3rem; }

@media (max-width: 560px) {
  body { font-size: 14px; }
  .quick { flex-basis: 100%; }
  .tv { font-size: 1.3rem; }
  table.sources th:nth-child(3), table.sources td:nth-child(3),
  table.sources th:nth-child(6), table.sources td:nth-child(6),
  table.sources th:nth-child(9), table.sources td:nth-child(9) { display: none; }
}
.who { display: flex; gap: .5rem; align-items: center; margin-left: .6rem; }
.linkbtn { background: none; border: 0; padding: 0; color: var(--link); cursor: pointer; font: inherit; }
