/* ---------- Tokens ---------- */
:root {
  color-scheme: light;
  --bg: #fdfdfb;
  --ink: #1b1b1a;
  --ink-2: #444441;
  --muted: #74736d;
  --rule: #dcdbd5;
  --grid: #ebeae5;
  --axis: #b9b8b0;
  --tint: #f3f2ee;
  --link: #1f5fa8;

  --accent: #2a78d6;        /* Pulsar */
  --accent-ink: #1c5cab;
  --accent-tint: #dce9fa;
  --star: #eb6834;          /* Star Attention */
  --dense: #1baf7a;         /* Full attention */
  --other: #9a9992;         /* other baselines */
  --sink: #4a3aa7;
  --block: #d6d5cf;

  --serif: "Source Serif 4", Charter, "Iowan Old Style", Georgia, serif;
  --sans: "Source Sans 3", -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #161718;
    --ink: #e8e6e1;
    --ink-2: #c2c0ba;
    --muted: #8f8d87;
    --rule: #34353a;
    --grid: #26272b;
    --axis: #45464c;
    --tint: #1f2023;
    --link: #86b6ef;
    --accent: #3987e5;
    --accent-ink: #86b6ef;
    --accent-tint: #1b2b40;
    --star: #d95926;
    --dense: #199e70;
    --other: #6f7077;
    --sink: #9085e9;
    --block: #45464c;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #161718;
  --ink: #e8e6e1;
  --ink-2: #c2c0ba;
  --muted: #8f8d87;
  --rule: #34353a;
  --grid: #26272b;
  --axis: #45464c;
  --tint: #1f2023;
  --link: #86b6ef;
  --accent: #3987e5;
  --accent-ink: #86b6ef;
  --accent-tint: #1b2b40;
  --star: #d95926;
  --dense: #199e70;
  --other: #6f7077;
  --sink: #9085e9;
  --block: #45464c;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 19px;
  line-height: 1.6;
  overflow-x: hidden;
  font-optical-sizing: auto;
}
@media (max-width: 600px) { body { font-size: 17.5px; } }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
code { font-family: var(--mono); font-size: .8em; }
p { margin: 0 0 1em; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.l-body, .l-page { margin-left: auto; margin-right: auto; padding-left: 20px; padding-right: 20px; }
.l-body { max-width: 744px; }
.l-page { max-width: 1024px; }

/* ---------- Title & byline ---------- */
.d-title { padding-top: 56px; }
.title-row { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; }
.kicker { font-family: var(--sans); font-size: 14px; color: var(--muted); margin: 0 0 14px; letter-spacing: .01em; }
.theme-toggle {
  flex: none; font-family: var(--sans); font-size: 13px; color: var(--muted);
  background: none; border: 0; padding: 0; cursor: pointer; text-decoration: underline; text-underline-offset: 3px;
}
.theme-toggle:hover { color: var(--ink); }
h1 {
  font-size: clamp(30px, 4.6vw, 46px); line-height: 1.12; font-weight: 700; letter-spacing: -0.012em;
  margin: 0 0 32px; max-width: 900px;
}
.d-byline { font-family: var(--sans); font-size: 15px; line-height: 1.5; }
.byline-grid {
  display: grid; grid-template-columns: 1.1fr 1fr 1.2fr 1.4fr; gap: 16px 28px;
  border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); padding: 16px 0 14px;
}
.byline-grid h3 { font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin: 0 0 6px; }
.byline-grid p { margin: 0; }
@media (max-width: 760px) { .byline-grid { grid-template-columns: 1fr 1fr; } }

/* ---------- Article ---------- */
.d-article { padding-top: 44px; }
h2 { font-size: 27px; line-height: 1.25; font-weight: 600; margin: 52px 0 14px; letter-spacing: -0.005em; }
h2 .sec { color: var(--muted); font-weight: 400; margin-right: .6em; }
h3 { font-size: 20px; font-weight: 600; margin: 32px 0 10px; }
#abstract h2 { margin-top: 44px; }
#abstract p { color: var(--ink-2); }
.math { overflow-x: auto; overflow-y: hidden; margin: 6px 0 18px; padding: 4px 0; }
.math .katex-display { margin: 0; }
.katex { font-size: 1.05em; }
.note { font-size: 16px; color: var(--ink-2); }

/* ---------- Figures ---------- */
figure { margin: 36px auto; }
figcaption {
  font-family: var(--sans); font-size: 14.5px; line-height: 1.5; color: var(--muted);
  margin-top: 14px; max-width: 744px;
}
.fig-num { color: var(--ink); font-weight: 600; margin-right: .25em; }
.fig { font-family: var(--sans); }

.fig-controls {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 14px;
  font-family: var(--sans); font-size: 14.5px; margin-bottom: 16px;
}
.ctl-label { color: var(--muted); font-size: 12px; letter-spacing: .06em; text-transform: uppercase; }
.opts { display: inline-flex; flex-wrap: wrap; gap: 2px 12px; margin-right: 14px; }
.opts button {
  font: inherit; background: none; border: 0; padding: 1px 0; cursor: pointer; color: var(--muted);
  border-bottom: 1.5px solid transparent;
}
.opts button:hover { color: var(--ink); }
.opts button[aria-checked="true"] { color: var(--ink); border-bottom-color: var(--ink); }
.ctl-note { color: var(--muted); margin-left: auto; }
.check { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); cursor: pointer; }
.check input { accent-color: var(--accent); margin: 0; }

/* ---------- Figure 1: method diagram ---------- */
.hosts { display: grid; gap: 10px; }
.host { display: grid; grid-template-columns: 70px 1fr 92px; align-items: center; gap: 12px; }
.host-name { font-size: 14px; color: var(--ink-2); line-height: 1.15; }
.host-name small { display: block; color: var(--muted); font-size: 11.5px; }
.bar { display: flex; height: 30px; min-width: 0; }
.seg-b {
  height: 100%; border-radius: 2px; min-width: 3px; margin-right: 2px;
  display: grid; place-items: center; overflow: hidden; white-space: nowrap;
  font-size: 12px; color: var(--ink);
  transition: flex-basis .5s cubic-bezier(.3,.7,.2,1), opacity .3s ease, margin .3s ease;
}
.seg-b.block { background: var(--block); }
.seg-b.anchor { background: var(--star); color: #fff; }
.seg-b.sink { background: var(--sink); }
.seg-b.summary { background: var(--accent); color: #fff; }
.seg-b.gone { flex-basis: 0 !important; min-width: 0; margin-right: 0; opacity: 0; }
.host-len { font-size: 13px; color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
@media (max-width: 560px) {
  .host { grid-template-columns: 1fr; gap: 3px; }
  .host-name small { display: inline; margin-left: 6px; }
  .host-len { text-align: left; }
  .seg-b { font-size: 0; }
}
.legend { display: flex; flex-wrap: wrap; gap: 4px 20px; margin-top: 16px; font-size: 13.5px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw { width: 11px; height: 11px; border-radius: 1px; display: inline-block; }
.sw-block { background: var(--block); } .sw-anchor { background: var(--star); }
.sw-sink { background: var(--sink); } .sw-summary { background: var(--accent); }
.readout { display: grid; grid-template-columns: repeat(3, 1fr); margin-top: 18px; border-top: 1px solid var(--rule); }
.metric { padding: 12px 16px 2px 0; }
.metric + .metric { padding-left: 16px; border-left: 1px solid var(--rule); }
.metric-label { font-size: 12.5px; color: var(--muted); }
.metric-value { font-family: var(--serif); font-size: 24px; font-variant-numeric: tabular-nums; line-height: 1.3; }
.metric-note { font-size: 13px; color: var(--ink-2); }
@media (max-width: 620px) {
  .readout { grid-template-columns: 1fr; }
  .metric + .metric { padding-left: 0; border-left: 0; border-top: 1px solid var(--rule); }
}

/* ---------- Figure 2: demo ---------- */
.blocks { display: grid; grid-template-columns: repeat(4, 1fr); border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); }
.blk { padding: 12px 12px 14px; min-width: 0; }
.blk + .blk { border-left: 1px solid var(--rule); }
.blk:first-child { padding-left: 0; }
.blk:last-child { padding-right: 0; }
@media (max-width: 900px) {
  .blocks { grid-template-columns: 1fr 1fr; }
  .blk:nth-child(3) { border-left: 0; padding-left: 0; }
  .blk:nth-child(2) { padding-right: 0; }
  .blk:nth-child(n+3) { border-top: 1px solid var(--rule); }
}
@media (max-width: 520px) {
  .blocks { grid-template-columns: 1fr; }
  .blk, .blk + .blk { border-left: 0; padding-left: 0; padding-right: 0; }
  .blk + .blk { border-top: 1px solid var(--rule); }
}
.blk-head { font-size: 13px; color: var(--muted); margin-bottom: 6px; display: flex; justify-content: space-between; }
.blk-head b { color: var(--ink); font-weight: 600; }
.chunk {
  display: grid; grid-template-columns: 1fr auto; gap: 6px; align-items: center;
  padding: 3px 5px; margin: 0 -5px 2px; border: 1px solid transparent; border-radius: 2px;
  font-family: var(--mono); font-size: 12.5px;
}
.chunk.sel { border-color: var(--accent); }
.chunk .toks { display: flex; flex-wrap: wrap; gap: 0 5px; min-width: 0; }
.chunk .score { font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.chunk.sel .score { color: var(--accent-ink); }
.tok { padding: 0 2px; border-radius: 2px; }
.tok[data-l="0"] { color: var(--muted); }
.tok[data-l="1"] { background: var(--accent-tint); color: var(--ink); }
.tok[data-l="2"] { background: var(--accent); color: #fff; }
.prefix { margin-top: 10px; font-size: 12.5px; color: var(--muted); }
.prefix-chips { margin-top: 2px; }
.chip { display: block; font-family: var(--mono); font-size: 12px; color: var(--ink-2); line-height: 1.55; }
.chip::before { content: "+ "; color: var(--muted); }
.chip.hit { color: var(--accent-ink); font-weight: 500; }
.chip.anchor { color: var(--star); }
.verdict { font-family: var(--serif); font-size: 17px; color: var(--ink-2); margin: 14px 0 0; max-width: 744px; }

/* ---------- Charts ---------- */
.chart { width: 100%; position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart text { font-family: var(--sans); }
.axis-label { fill: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.gridline { stroke: var(--grid); stroke-width: 1; }
.baseline { stroke: var(--axis); stroke-width: 1; }
.series-line { fill: none; stroke-linejoin: round; stroke-linecap: round; }
.series-dot { stroke: var(--bg); stroke-width: 1.5; }
.direct-label { font-size: 12.5px; fill: var(--ink-2); }
.crosshair { stroke: var(--axis); stroke-width: 1; stroke-dasharray: 3 3; }
.hit { fill: transparent; }
.bar-value { font-size: 12px; fill: var(--ink-2); font-variant-numeric: tabular-nums; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 4px 18px; font-family: var(--sans); font-size: 13.5px; color: var(--ink-2); margin: 0 0 8px; }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend i { width: 16px; height: 2px; display: inline-block; }
.chart-legend i.sq { width: 10px; height: 10px; border-radius: 1px; }
.chart-legend i.dash { background: repeating-linear-gradient(90deg, var(--other) 0 4px, transparent 4px 7px) !important; }
.chart-title { font-family: var(--sans); font-size: 14.5px; font-weight: 600; margin: 0 0 8px; color: var(--ink); }
.charts-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 40px; }
@media (max-width: 760px) { .charts-2 { grid-template-columns: 1fr; gap: 28px; } }

.tooltip {
  position: fixed; z-index: 80; pointer-events: none;
  background: var(--bg); color: var(--ink); border: 1px solid var(--rule);
  box-shadow: 0 2px 8px rgba(0,0,0,.08); border-radius: 3px; padding: 7px 10px;
  font-family: var(--sans); font-size: 13px; line-height: 1.45; min-width: 150px;
}
.tooltip .tt-title { font-weight: 600; margin-bottom: 3px; }
.tooltip .tt-row { display: flex; align-items: center; gap: 7px; font-variant-numeric: tabular-nums; }
.tooltip .tt-row i { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.tooltip .tt-row b { margin-left: auto; padding-left: 12px; font-weight: 600; }

/* dot plot */
.dotplot { display: grid; }
.dp-row { display: grid; grid-template-columns: minmax(120px, 180px) 1fr; gap: 14px; align-items: center; padding: 5px 0; }
.dp-name { font-size: 14.5px; color: var(--ink-2); }
.dp-track { position: relative; height: 20px; margin-right: 12px; }
.dp-track::before { content: ""; position: absolute; left: 0; right: 0; top: 50%; height: 1px; background: var(--grid); }
.dp-dot { position: absolute; top: 50%; width: 11px; height: 11px; margin: -5.5px 0 0 -5.5px; border-radius: 50%; border: 1.5px solid var(--bg); cursor: default; }
.dp-dot:hover, .dp-dot:focus-visible { transform: scale(1.3); z-index: 2; }
.dp-axis { display: grid; grid-template-columns: minmax(120px, 180px) 1fr; gap: 14px; border-top: 1px solid var(--axis); margin-top: 4px; }
.dp-ticks { position: relative; height: 20px; margin-right: 12px; font-size: 12px; color: var(--muted); }
.dp-ticks span { position: absolute; transform: translateX(-50%); top: 3px; }
@media (max-width: 520px) {
  .dp-row, .dp-axis { grid-template-columns: 1fr; gap: 0; }
  .dp-axis > div:first-child { display: none; }
}

/* ---------- Tables (booktabs) ---------- */
.tbl figcaption { margin: 0 0 10px; }
.tables-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 32px; }
.tables-2 figure { margin: 24px 0; }
@media (max-width: 700px) { .tables-2 { grid-template-columns: 1fr; gap: 0; } }
.tbl-wrap { overflow-x: auto; }
table.data {
  width: 100%; border-collapse: collapse; font-family: var(--sans); font-size: 14.5px; font-variant-numeric: tabular-nums;
  border-top: 1.5px solid var(--ink); border-bottom: 1.5px solid var(--ink);
}
table.data th, table.data td { padding: 4px 10px; text-align: right; white-space: nowrap; }
table.data th:first-child, table.data td:first-child { text-align: left; padding-left: 0; }
table.data th:last-child, table.data td:last-child { padding-right: 0; }
table.data thead tr:last-child th { border-bottom: 1px solid var(--ink); padding-bottom: 5px; }
table.data thead th { font-weight: 600; }
table.data tbody tr:first-child td { padding-top: 7px; }
table.data tbody tr:last-child td { padding-bottom: 7px; }
table.data td.best { font-weight: 700; }
table.data tr.sep td { border-top: 1px solid var(--rule); }
table.data .grp th { text-align: center; font-weight: 400; color: var(--muted); padding-bottom: 0; }
table.data .grp th span { display: block; border-bottom: 1px solid var(--rule); padding-bottom: 2px; }
.table-toggle { margin-top: 10px; font-family: var(--sans); font-size: 13.5px; }
.table-toggle summary { cursor: pointer; color: var(--muted); width: fit-content; }
.table-toggle summary:hover { color: var(--ink); }
.table-toggle[open] summary { margin-bottom: 8px; }

/* ---------- Code ---------- */
.codeblock { position: relative; margin: 0 0 1.1em; }
.codeblock pre {
  margin: 0; background: var(--tint); border-radius: 3px;
  padding: 14px 16px; overflow-x: auto; font-family: var(--mono); font-size: 13.5px; line-height: 1.6;
}
.codeblock pre code { font-size: inherit; }
.copy {
  position: absolute; top: 8px; right: 10px; font-family: var(--sans); font-size: 12.5px;
  background: none; border: 0; color: var(--muted); cursor: pointer; text-decoration: underline; text-underline-offset: 2px;
}
.copy:hover { color: var(--ink); }

.d-footer { margin-top: 72px; padding: 22px 0 40px; border-top: 1px solid var(--rule); font-family: var(--sans); font-size: 13.5px; color: var(--muted); }
.d-footer p { margin: 0; }
