:root {
  color-scheme: light;
  --bg: #f6f6f4;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --border: #dddcd7;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #73726c;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --error: #b42318;
  --parity: #0b0b0b;
  /* Tokenizer identity: the reference categorical palette, fixed order. */
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --s8: #e34948;
  /* Token tints: only to tell neighbouring tokens apart. */
  --t0: #dbe9fb; --t1: #fde3d6; --t2: #d3f2e5; --t3: #fcefc7;
  --t4: #f9dde8; --t5: #e4def8; --t6: #d9f0d2;
  --t-ink: #0b0b0b;
  --ws: #9b9a93;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211; --surface: #1a1a19; --surface-2: #242422; --border: #363632;
    --text: #f0efec; --text-2: #c3c2b7; --muted: #9a998f;
    --accent: #3987e5; --accent-ink: #ffffff; --error: #f97066; --parity: #f0efec;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
    --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
    --t0: #1f3a5c; --t1: #4d2a1b; --t2: #173f31; --t3: #463818;
    --t4: #4a2234; --t5: #2f2a52; --t6: #23401f;
    --t-ink: #f0efec; --ws: #77766e;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface: #1a1a19; --surface-2: #242422; --border: #363632;
  --text: #f0efec; --text-2: #c3c2b7; --muted: #9a998f;
  --accent: #3987e5; --accent-ink: #ffffff; --error: #f97066; --parity: #f0efec;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  --t0: #1f3a5c; --t1: #4d2a1b; --t2: #173f31; --t3: #463818;
  --t4: #4a2234; --t5: #2f2a52; --t6: #23401f;
  --t-ink: #f0efec; --ws: #77766e;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
}
.wrap { max-width: 1180px; margin: 0 auto; padding: 0 16px; }
a { color: var(--accent); }
code { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 0.92em; }
h1 { font-size: 1.6rem; margin: 0 0 4px; letter-spacing: -0.01em; }
h2 { font-size: 1rem; margin: 0; }
.lede { margin: 0; color: var(--text-2); }
.muted { color: var(--muted); }
.small { font-size: 0.86rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.error { color: var(--error); margin: 8px 0 0; }

.site-header { padding: 28px 0 18px; }
.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 14px 16px; margin-bottom: 14px;
}
.panel-head { display: flex; gap: 12px; align-items: baseline; flex-wrap: wrap; margin-bottom: 10px; }
.hint { color: var(--muted); font-size: 0.86rem; }

/* Controls */
button, .button-like, select, input[type="text"], input[type="search"], input[type="number"] {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 7px; padding: 6px 10px; min-height: 34px;
}
button, .button-like { cursor: pointer; background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.secondary, .button-like { background: var(--surface); color: var(--text); border-color: var(--border); }
button:hover { filter: brightness(1.05); }
button:disabled { opacity: 0.5; cursor: default; }
#sn-prev, #sn-next { background: var(--surface); color: var(--text); border-color: var(--border); min-width: 34px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
select { max-width: 100%; }
input[type="number"] { width: 6em; }
.inline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 0.86rem; color: var(--text-2); min-width: 0; }
.field > span:first-child { font-weight: 500; }
.field.grow { flex: 1 1 260px; }
.field.grow input { flex: 1; min-width: 0; }
.check { display: inline-flex; gap: 6px; align-items: center; font-size: 0.9rem; color: var(--text-2); cursor: pointer; }
.add-row, .controls { display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap; }
.controls > button { margin-left: auto; }

/* Tokenizer chips */
.chips { list-style: none; margin: 0 0 12px; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 8px; padding: 4px 6px 4px 10px;
  border: 1px solid var(--border); border-radius: 999px; background: var(--surface-2); font-size: 0.9rem;
}
.swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; background: var(--c); }
.chip .meta { color: var(--muted); font-size: 0.8rem; }
.chip .meta.err { color: var(--error); }
.chip button {
  min-height: 0; padding: 0 6px; line-height: 1.4; background: transparent; color: var(--muted);
  border: none; font-size: 1.05rem;
}
.chip button:hover { color: var(--text); }
.spinner {
  width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--border);
  border-top-color: var(--accent); animation: spin 0.8s linear infinite; flex: none;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin: 6px 0 14px; overflow-x: auto; }
.tabs button {
  background: transparent; color: var(--text-2); border: none; border-bottom: 2px solid transparent;
  border-radius: 0; padding: 8px 12px; white-space: nowrap;
}
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

/* Playground */
textarea {
  width: 100%; font: 16px/1.5 system-ui, sans-serif; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; resize: vertical;
}
.toolbar { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-top: 10px; }
.results { display: grid; gap: 12px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.card-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.card-head h3 { font-size: 0.98rem; margin: 0; }
.stats { display: flex; gap: 16px; flex-wrap: wrap; margin-left: auto; font-size: 0.86rem; color: var(--text-2); }
.stats b { color: var(--text); font-variant-numeric: tabular-nums; font-size: 1rem; }

.tokens { white-space: pre-wrap; word-break: break-word; line-height: 1.9; font-size: 1rem; }
.tok {
  border-radius: 3px; padding: 1px 0; color: var(--t-ink);
  box-decoration-break: clone; -webkit-box-decoration-break: clone;
}
.tok:hover { outline: 2px solid var(--text); outline-offset: 0; position: relative; z-index: 1; }
.tok.c0 { background: var(--t0); } .tok.c1 { background: var(--t1); } .tok.c2 { background: var(--t2); }
.tok.c3 { background: var(--t3); } .tok.c4 { background: var(--t4); } .tok.c5 { background: var(--t5); }
.tok.c6 { background: var(--t6); }
.tok.byte { color: var(--muted); font-size: 0.6em; padding: 1px 1px; vertical-align: 0.15em; }
.ws { color: var(--ws); }
.ids {
  margin-top: 10px; padding-top: 8px; border-top: 1px dashed var(--border);
  font: 0.84rem/1.6 ui-monospace, Menlo, Consolas, monospace; color: var(--text-2); word-break: break-word;
}
.empty { color: var(--muted); font-style: italic; }

/* Compare */
.progress { position: relative; height: 26px; background: var(--surface-2); border-radius: 6px; overflow: hidden; margin-bottom: 12px; }
.progress .bar { position: absolute; inset: 0 auto 0 0; background: var(--accent); opacity: 0.25; width: 0; transition: width 0.2s; }
.progress span { position: relative; padding: 0 10px; font-size: 0.85rem; line-height: 26px; color: var(--text-2); }
.summary { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; margin-bottom: 12px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.tile .name { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 0.92rem; margin-bottom: 6px; }
.tile dl { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; margin: 0; font-size: 0.85rem; }
.tile dt { color: var(--muted); }
.tile dd { margin: 0; font-variant-numeric: tabular-nums; color: var(--text); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 8px; font-size: 0.86rem; color: var(--text-2); }
.legend span { display: inline-flex; gap: 6px; align-items: center; }
.legend .parity-key { width: 0; height: 12px; border-left: 1.5px dashed var(--parity); }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; }
table.data { border-collapse: collapse; width: 100%; font-size: 0.88rem; }
table.data th, table.data td { padding: 5px 10px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
table.data th { position: sticky; top: 0; background: var(--surface-2); font-weight: 600; color: var(--text-2); cursor: pointer; user-select: none; }
table.data th[aria-sort="ascending"]::after { content: " ▲"; font-size: 0.7em; }
table.data th[aria-sort="descending"]::after { content: " ▼"; font-size: 0.7em; }
table.data td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data th.num { text-align: right; }
table.data tr.ref td { background: var(--surface-2); }
table.data td.lang .code { color: var(--muted); font-size: 0.8em; margin-left: 6px; }
/* Compare table: the Language column stays put while the rest scrolls sideways. Opaque
   backgrounds so scrolled cells don't show through; a shadow instead of a border, since
   collapsed borders scroll away from sticky cells. */
#cmp-table th:first-child, #cmp-table td:first-child {
  position: sticky; left: 0; z-index: 1; background: var(--surface);
  box-shadow: inset -1px 0 var(--border);
}
#cmp-table th:first-child { z-index: 2; background: var(--surface-2); }
#cmp-table tr.ref td:first-child { background: var(--surface-2); }
.badge { font-size: 0.7rem; color: var(--accent); border: 1px solid currentColor; border-radius: 4px; padding: 0 4px; margin-left: 6px; }
table.data th.num { white-space: normal; max-width: 9em; vertical-align: bottom; }
table.data th.chart-head { cursor: default; }
td.chart { width: 34%; min-width: 200px; padding-top: 4px; padding-bottom: 4px; padding-right: 18px; }
.bars { position: relative; display: flex; flex-direction: column; gap: 2px; }
.bars .b { height: 6px; border-radius: 0 4px 4px 0; background: var(--c); min-width: 1px; }
.bars .hit { position: absolute; left: 0; right: 0; }
.bars .parity { position: absolute; top: -3px; bottom: -3px; border-left: 1.5px dashed var(--parity); opacity: 0.6; pointer-events: none; }

/* One sentence */
.sn-opts { margin-bottom: 8px; }
.sentence-list { display: grid; gap: 8px; }
.srow { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px; }
.srow.ref { border-color: var(--accent); }
.srow-head { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; margin-bottom: 4px; font-size: 0.9rem; }
.srow-head .name { font-weight: 600; }
.srow-head .nums { margin-left: auto; color: var(--text-2); font-variant-numeric: tabular-nums; }
.srow-head .nums b { color: var(--text); }
.srow .tokens { font-size: 0.98rem; }

.tooltip {
  position: fixed; z-index: 10; pointer-events: none; max-width: 340px;
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 9px; font-size: 0.82rem; box-shadow: 0 4px 16px rgb(0 0 0 / 0.18);
}
.tooltip code { word-break: break-all; }
.footer { color: var(--muted); font-size: 0.84rem; padding-top: 18px; padding-bottom: 40px; }
.footer p { margin: 0 0 8px; max-width: 900px; }

@media (max-width: 640px) {
  .controls > button { margin-left: 0; }
  .stats { margin-left: 0; }
  td.chart { min-width: 140px; }
  .srow-head .nums { margin-left: 0; width: 100%; }
}

/* Merge trees (Playground) */
.tok.picked { outline: 2px solid var(--accent); outline-offset: 0; }
[data-bpe] .tok { cursor: pointer; }
.tree-panel { margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--border); }
.tree-head { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; margin-bottom: 6px; font-size: 0.9rem; }
.tree-head button { margin-left: auto; }
.small-btn { min-height: 0; padding: 2px 10px; font-size: 0.85rem; }
.tree { font-size: 0.92rem; overflow-x: auto; }
.trow { white-space: pre; line-height: 1.75; }
.tprefix { font-family: ui-monospace, Menlo, Consolas, monospace; color: var(--muted); }
.tsym { background: var(--t0); color: var(--t-ink); border-radius: 3px; padding: 1px 3px; white-space: pre; }
.trank { font-variant-numeric: tabular-nums; color: var(--text-2); font-size: 0.85rem; }

/* Step-by-step BPE */
.piece + .piece { margin-top: 12px; padding-top: 10px; border-top: 1px dashed var(--border); }
.piece-head { margin-bottom: 6px; }
.steps { display: grid; gap: 3px; overflow-x: auto; }
.step { display: flex; gap: 10px; align-items: center; }
.slabel { flex: none; width: 6.5em; text-align: right; font-variant-numeric: tabular-nums; font-size: 0.82rem; color: var(--text-2); }
.slabel[data-tip] { text-decoration: underline dotted; cursor: help; }
.symbols { display: flex; gap: 3px; flex-wrap: nowrap; }
.sym {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 4px; padding: 0 5px;
  white-space: pre; font-size: 0.92rem; line-height: 1.6;
}
.sym.new { background: var(--t0); border-color: var(--accent); color: var(--t-ink); }

/* Merge timelines */
.mg-section { margin-top: 14px; }
.chart-title { font-size: 0.95rem; margin: 18px 0 2px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.chart-title select { font-size: 0.85rem; min-height: 0; padding: 2px 6px; }
.facets { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; margin-top: 8px; }
.facet { margin: 0; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 6px 6px 2px; }
.facet figcaption { font-size: 0.82rem; font-weight: 600; color: var(--text-2); padding: 0 4px 2px; }
.facet svg, .sharing svg { width: 100%; height: auto; display: block; }
svg .grid { stroke: var(--border); stroke-width: 1; }
svg .axis { fill: var(--muted); font-size: 10px; font-family: system-ui, sans-serif; }
svg .series { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
svg .ref { stroke: var(--muted); stroke-width: 1.2; stroke-dasharray: 4 3; }
svg .cross { stroke: var(--text-2); stroke-width: 1; }
svg .hit { fill: transparent; cursor: crosshair; }
.sharing { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px; margin-top: 8px; }
.mg-list-controls { margin: 8px 0; }
.pager { margin-bottom: 8px; }
table.merges-table td.users { white-space: normal; color: var(--text-2); font-size: 0.82rem; }
/* Long merge rows scroll inside their card rather than widening it. */
.results > *, .piece, .steps { min-width: 0; }
