:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f0f2f7;
  --ink: #101828;
  --ink-2: #475467;
  --muted: #8a94a6;
  --line: #e3e7ef;
  --thesis: #e8336b;
  --thesis-soft: #ffe1ea;
  --paper: #3b82f6;
  --tool: #0f9f8f;
  --kernel: #d99206;
  --ov-negligible: #16a34a;
  --ov-low: #0d9488;
  --ov-medium: #d97706;
  --ov-high: #dc2626;
  --ov-na: #98a2b3;
  --dim: 0.12;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 16px rgba(16, 24, 40, .06);
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0f17; --surface: #121826; --surface-2: #1a2132; --ink: #e8ecf4; --ink-2: #b3bccb;
    --muted: #7c879b; --line: #252e42; --thesis: #ff5d8f; --thesis-soft: #3b1424; --paper: #60a5fa;
    --tool: #2dd4bf; --kernel: #fbbf24; --ov-negligible: #4ade80; --ov-low: #2dd4bf; --ov-medium: #fbbf24;
    --ov-high: #f87171; --ov-na: #667085; --dim: 0.14; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 24px rgba(0,0,0,.35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b0f17; --surface: #121826; --surface-2: #1a2132; --ink: #e8ecf4; --ink-2: #b3bccb;
  --muted: #7c879b; --line: #252e42; --thesis: #ff5d8f; --thesis-soft: #3b1424; --paper: #60a5fa;
  --tool: #2dd4bf; --kernel: #fbbf24; --ov-negligible: #4ade80; --ov-low: #2dd4bf; --ov-medium: #fbbf24;
  --ov-high: #f87171; --ov-na: #667085; --dim: 0.14; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--ink);
  font: 14px/1.5 Inter, system-ui, -apple-system, Segoe UI, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--paper); }
h1, h2, h3 { margin: 0; letter-spacing: -0.01em; }
.muted { color: var(--muted); font-weight: 400; }
code, pre { font-family: "JetBrains Mono", ui-monospace, monospace; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 20px; padding: 12px 20px;
  background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; flex: 1; }
.brand h1 { font-size: 17px; font-weight: 700; }
.tagline { margin: 0; color: var(--ink-2); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tabs { display: flex; gap: 2px; background: var(--surface-2); padding: 3px; border-radius: 10px; }
.tabs button {
  border: 0; background: transparent; color: var(--ink-2); font: inherit; font-weight: 500;
  padding: 6px 14px; border-radius: 8px; cursor: pointer;
}
.tabs button.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

.btn {
  font: inherit; font-weight: 500; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: 9px; padding: 7px 12px; cursor: pointer; transition: background .15s, border-color .15s, transform .1s;
}
.btn:hover { border-color: var(--muted); }
.btn:active { transform: translateY(1px); }
.btn.small { padding: 4px 10px; font-size: 12.5px; }
.btn.ghost { background: transparent; }
.btn.primary { background: var(--thesis); border-color: var(--thesis); color: #fff; display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.primary.on { box-shadow: 0 0 0 3px var(--thesis-soft); }
.pulse-dot { width: 8px; height: 8px; border-radius: 50%; background: #fff; animation: dotpulse 1.6s infinite; }
@keyframes dotpulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: 270px minmax(0, 1fr) 340px; height: calc(100vh - 61px); }
.filters, .detail-pane { background: var(--surface); overflow-y: auto; }
.filters { border-right: 1px solid var(--line); padding: 16px; }
.detail-pane { border-left: 1px solid var(--line); }
.stage { position: relative; overflow: hidden; display: flex; flex-direction: column; min-width: 0; }

/* ---------- filters ---------- */
.filters-toggle { display: none; width: 100%; }
.preset { display: grid; gap: 6px; margin-bottom: 8px; }
.preset-btn {
  text-align: left; border: 1px dashed var(--thesis); background: var(--thesis-soft); color: var(--ink);
  padding: 10px 12px; line-height: 1.35; font-weight: 600;
}
.preset-btn.on { border-style: solid; box-shadow: 0 0 0 3px var(--thesis-soft); }
.eyebrow { display: block; font-size: 10.5px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--thesis); margin-bottom: 2px; }
.match-count { margin: 4px 0 12px; color: var(--ink-2); font-size: 12.5px; min-height: 19px; }
.match-count b { color: var(--ink); }
fieldset { border: 0; padding: 0; margin: 0 0 14px; }
legend, .field > span { font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-2); margin-bottom: 6px; padding: 0; }
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field input, .field select {
  font: inherit; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); color: var(--ink);
}
.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip {
  display: inline-flex; align-items: center; gap: 5px; font-size: 12px; padding: 3px 9px; border-radius: 99px;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--ink-2); cursor: default; user-select: none;
}
button.chip { cursor: pointer; font: inherit; font-size: 12px; }
button.chip:hover { border-color: var(--muted); }
button.chip.on { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.check { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; cursor: pointer; }
.range2 { position: relative; height: 26px; }
.range2 input { position: absolute; inset: 0; width: 100%; pointer-events: none; background: none; -webkit-appearance: none; appearance: none; }
.range2 input::-webkit-slider-thumb { pointer-events: auto; -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%; background: var(--ink); border: 2px solid var(--surface); cursor: pointer; }
.range2 input::-moz-range-thumb { pointer-events: auto; width: 14px; height: 14px; border-radius: 50%; background: var(--ink); border: 2px solid var(--surface); cursor: pointer; }
.range2::before { content: ""; position: absolute; left: 0; right: 0; top: 12px; height: 3px; background: var(--line); border-radius: 3px; }

/* ---------- dots & pills ---------- */
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; vertical-align: 0; }
.kind-thesis.dot { background: var(--thesis); }
.kind-tool.dot { background: var(--tool); }
.kind-paper.dot { background: var(--paper); }
.kind-kernel.dot { background: var(--kernel); border-radius: 2px; transform: rotate(45deg) scale(.85); }
.pill { font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 99px; color: #fff; white-space: nowrap; }
.ov-negligible { background: var(--ov-negligible); } .ov-low { background: var(--ov-low); }
.ov-medium { background: var(--ov-medium); } .ov-high { background: var(--ov-high); } .ov-na { background: var(--ov-na); }
:root .pill.ov-medium, :root .pill.ov-negligible, :root .pill.ov-low { color: #fff; }

/* ---------- views ---------- */
.view { display: none; flex: 1; min-height: 0; position: relative; }
.view.active { display: flex; flex-direction: column; }
.view-head { padding: 16px 20px 8px; }
.view-head h2 { font-size: 16px; }
.view-head p { margin: 4px 0 0; font-size: 12.5px; max-width: 760px; }
.loading { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); background: var(--bg); z-index: 5; }
.loading.error { color: var(--ov-high); }

/* graph */
#graph { flex: 1; width: 100%; height: 100%; cursor: grab; display: block; }
#graph:active { cursor: grabbing; }
.legend { position: absolute; top: 12px; left: 14px; display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--ink-2); background: color-mix(in srgb, var(--surface) 85%, transparent); padding: 6px 10px; border-radius: 9px; border: 1px solid var(--line); z-index: 2; }
.legend .ln { display: inline-block; width: 18px; height: 0; border-top: 1.5px solid var(--muted); vertical-align: middle; margin-right: 5px; }
.legend .ln.dash { border-top-style: dashed; }
.graph-hint { position: absolute; bottom: 10px; left: 14px; font-size: 11.5px; color: var(--muted); pointer-events: none; }
.node { cursor: pointer; transition: opacity .35s; }
.node text { font-size: 10.5px; fill: var(--ink-2); paint-order: stroke; stroke: var(--bg); stroke-width: 3px; stroke-linejoin: round; pointer-events: none; }
.node.kind-thesis text { font-size: 12.5px; font-weight: 700; fill: var(--thesis); }
.node .shape { stroke: var(--bg); stroke-width: 1.5px; }
.node.kind-thesis .shape { fill: var(--thesis); }
.node.kind-tool .shape { fill: var(--tool); }
.node.kind-paper .shape { fill: var(--paper); }
.node.kind-kernel .shape { fill: var(--kernel); }
.node.selected .shape { stroke: var(--ink); stroke-width: 2.5px; }
.node.dim { opacity: var(--dim); }
.link { stroke: var(--muted); stroke-opacity: .35; fill: none; transition: opacity .35s, stroke-opacity .2s; }
.link.requires { stroke-dasharray: 3 3; stroke: var(--kernel); stroke-opacity: .35; }
.link.dim { opacity: .08; }
.link.hl { stroke-opacity: .9; stroke-width: 1.6px; }
.pulse-ring { fill: none; stroke: var(--thesis); stroke-width: 2px; pointer-events: none; opacity: 0; }
.fits .pulse-ring, .node.kind-thesis.pulsing .pulse-ring { animation: ring 1.8s ease-out infinite; }
.pulse-ring.r2 { animation-delay: .6s !important; }
.pulse-ring.r3 { animation-delay: 1.2s !important; }
@keyframes ring { 0% { opacity: .9; transform: scale(1); } 100% { opacity: 0; transform: scale(3.2); } }
.node.kind-thesis .pulse-ring { transform-box: fill-box; transform-origin: center; }

/* matrix */
.table-wrap { overflow: auto; flex: 1; padding: 0 20px 20px; }
#matrix { border-collapse: separate; border-spacing: 0; font-size: 12.5px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
#matrix th, #matrix td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: center; white-space: nowrap; }
#matrix th { position: sticky; top: 0; background: var(--surface); z-index: 1; font-weight: 600; color: var(--ink-2); cursor: pointer; vertical-align: bottom; font-size: 11.5px; }
#matrix th:hover { color: var(--ink); }
#matrix th.sorted::after { content: " ↓"; } #matrix th.sorted.asc::after { content: " ↑"; }
#matrix th.metric { writing-mode: vertical-rl; transform: rotate(180deg); text-align: left; height: 168px; padding: 8px 4px; }
#matrix td.work, #matrix th.work { text-align: left; position: sticky; left: 0; background: var(--surface); z-index: 1; }
#matrix th.work { z-index: 2; }
#matrix td.work { font-weight: 500; min-width: 180px; }
#matrix td.work .yr { color: var(--muted); font-weight: 400; margin-left: 4px; }
#matrix tbody tr { cursor: pointer; transition: opacity .3s; }
#matrix tbody tr:hover td { background: var(--surface-2); }
#matrix tbody tr.dim { opacity: .22; }
#matrix tbody tr.selected td { background: var(--surface-2); }
#matrix tbody tr.is-thesis td { background: var(--thesis-soft); }
#matrix tbody tr.is-thesis td.work { color: var(--thesis); font-weight: 700; }
.tick { display: inline-block; width: 14px; height: 14px; border-radius: 4px; background: var(--ink); opacity: .85; }
.tick.thesis { background: var(--thesis); opacity: 1; }
.nsbar { display: inline-flex; align-items: center; gap: 6px; }
.nsbar i { display: inline-block; height: 6px; border-radius: 3px; background: var(--muted); }
#matrix tfoot td { font-size: 11px; color: var(--muted); background: var(--surface-2); border-bottom: 0; }
#matrix tfoot td.work { background: var(--surface-2); font-weight: 600; color: var(--ink-2); white-space: normal; }
#matrix th.gapcol { color: var(--thesis); }
.fits-banner[hidden] { display: none; }
#matrix tfoot td.gapcell { color: var(--thesis); font-weight: 700; }
.fits #matrix .gapcol { animation: gapglow 1.6s ease-in-out infinite; }
.fits #matrix tr.is-thesis td { animation: rowpulse 1.6s ease-in-out infinite; }
@keyframes gapglow { 0%,100% { background-color: transparent; } 50% { background-color: var(--thesis-soft); } }
@keyframes rowpulse { 0%,100% { background-color: var(--thesis-soft); } 50% { background-color: color-mix(in srgb, var(--thesis) 30%, var(--surface)); } }

/* timeline */
.timeline-wrap { flex: 1; overflow: auto; padding: 0 12px 16px; }
#timeline { display: block; }
#timeline .axis text { fill: var(--ink-2); font-size: 11px; }
#timeline .axis line, #timeline .axis path { stroke: var(--line); }
#timeline .grid line { stroke: var(--line); stroke-dasharray: 2 4; }
#timeline .lane-label { font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; fill: var(--muted); }
#timeline .lane-bg { fill: var(--surface); stroke: var(--line); }
#timeline .item { cursor: pointer; transition: opacity .3s; }
#timeline .item text { font-size: 11px; fill: var(--ink); }
#timeline .item .ver { fill: var(--muted); font-family: "JetBrains Mono", monospace; font-size: 10px; }
#timeline .item.dim { opacity: var(--dim); }
#timeline .item.kind-thesis text { fill: var(--thesis); font-weight: 700; }
#timeline .req-line { stroke: var(--kernel); stroke-width: 1.2px; stroke-dasharray: 3 3; fill: none; pointer-events: none; }
#timeline .stem { stroke: var(--line); }

/* thesis page */
.thesis-page { overflow-y: auto; padding: 28px 32px 48px; max-width: 900px; }
.thesis-page .kicker { color: var(--thesis); font-weight: 600; font-size: 12px; letter-spacing: .06em; text-transform: uppercase; }
.thesis-page h2 { font-size: 26px; line-height: 1.2; margin: 6px 0 8px; }
.thesis-page .byline { color: var(--ink-2); margin-bottom: 18px; }
.thesis-page h3 { font-size: 15px; margin: 26px 0 8px; }
.thesis-page p { color: var(--ink-2); max-width: 70ch; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.downloads { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.download { display: block; text-decoration: none; color: var(--ink); }
.download:hover { border-color: var(--thesis); }
.download b { display: block; font-family: "JetBrains Mono", monospace; font-size: 13px; }
.download span { color: var(--ink-2); font-size: 12.5px; }
.contrib { padding-left: 18px; color: var(--ink-2); }
.contrib li { margin-bottom: 6px; }
.near-list { display: grid; gap: 8px; }
.near-list button { text-align: left; display: flex; justify-content: space-between; gap: 12px; }
.near-list .missing { color: var(--ov-high); font-size: 12px; }
pre.tex { background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 12px; font-size: 11px; max-height: 260px; overflow: auto; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 16px 0; }
.stat { padding: 12px 14px; }
.stat b { display: block; font-size: 22px; }
.stat span { color: var(--muted); font-size: 12px; }

/* fits banner */
.fits-banner {
  margin: 12px 16px 0; padding: 10px 14px; border-radius: 10px; background: var(--thesis-soft); border: 1px solid var(--thesis);
  display: flex; gap: 12px; align-items: center; justify-content: space-between; font-size: 13px; z-index: 3;
}
.fits-banner .near { display: block; color: var(--ink-2); font-size: 12px; margin-top: 2px; }
.fits-banner { font-size: 12.5px; line-height: 1.45; }
.fits-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* detail */
.detail-body { padding: 18px; }
.detail-empty h2 { font-size: 16px; margin-bottom: 6px; }
.detail-empty p { color: var(--ink-2); }
.legend-static { display: grid; gap: 4px; font-size: 12.5px; }
.detail-kind { font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; margin-bottom: 4px; }
.detail h2 { font-size: 19px; line-height: 1.25; }
.detail.kind-thesis h2 { color: var(--thesis); }
.detail-title { margin: 4px 0 0; color: var(--ink); font-weight: 500; }
.detail-authors { margin: 6px 0 0; color: var(--ink-2); font-size: 12.5px; }
.detail-venue { margin: 2px 0 0; color: var(--muted); font-size: 12.5px; font-style: italic; }
.detail h3 { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-2); margin: 16px 0 6px; }
.detail p { margin: 0; }
.facts { display: grid; grid-template-columns: 96px 1fr; gap: 6px 10px; margin: 16px 0 0; font-size: 13px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
.rel { list-style: none; padding: 0; margin: 0; display: grid; gap: 3px; font-size: 13px; }
.rel a { text-decoration: none; }
.rel a:hover { text-decoration: underline; }
.gap-callout, .near-callout { margin-top: 12px; padding: 10px 12px; border-radius: 9px; font-size: 13px; }
.gap-callout { background: var(--thesis-soft); border: 1px solid var(--thesis); }
.near-callout { background: var(--surface-2); border: 1px solid var(--line); }
.bib { margin-top: 16px; }
.bib summary { cursor: pointer; font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.bib pre { background: var(--surface-2); padding: 10px; border-radius: 8px; font-size: 11px; white-space: pre-wrap; word-break: break-word; }
.htmx-request.detail-body { opacity: .5; transition: opacity .2s; }

.tooltip { position: fixed; pointer-events: none; background: var(--ink); color: var(--surface); padding: 6px 9px; border-radius: 7px; font-size: 12px; max-width: 280px; z-index: 50; box-shadow: var(--shadow); }
.tooltip .tt-sub { opacity: .7; font-size: 11px; }

/* ---------- responsive ---------- */
@media (max-width: 1180px) {
  .layout { grid-template-columns: 240px minmax(0, 1fr); }
  .detail-pane { grid-column: 1 / -1; border-left: 0; border-top: 1px solid var(--line); max-height: none; }
  .layout { height: auto; }
  .stage { height: calc(100vh - 61px); }
  .tagline { display: none; }
}
@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; gap: 10px; padding: 10px 16px; }
  .brand { flex-basis: 100%; }
  .tabs { flex: 1; }
  .tabs button { padding: 6px 8px; flex: 1; }
  #fits-btn { flex-basis: 100%; justify-content: center; }
  .layout { grid-template-columns: 1fr; }
  .filters { border-right: 0; border-bottom: 1px solid var(--line); padding: 10px 16px; }
  .filters-toggle { display: block; }
  .filters-body { display: none; margin-top: 12px; }
  .filters.open .filters-body { display: block; }
  .stage { height: 70vh; }
  .thesis-page { padding: 20px 16px 40px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .fits-banner { flex-direction: column; align-items: flex-start; margin: 10px; }
  .table-wrap { padding: 0 16px 16px; }
}
