/* J-Lens Visualizer — warm daylight light theme (palette borrowed from idhant.xyz:
   day #fffdfa / dusk #db7a2a) + warm charcoal dark theme.
   One warm accent (the lens light); everything else is ink and grey. */

@font-face {
  font-family: "Satoshi";
  src: url("fonts/Satoshi-Variable.woff2") format("woff2");
  font-weight: 300 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Satoshi";
  src: url("fonts/Satoshi-VariableItalic.woff2") format("woff2");
  font-weight: 300 900;
  font-style: italic;
  font-display: swap;
}

:root,
:root[data-theme="light"] {
  --bg: #fffdfa;
  --panel: #ffffff;
  --panel-2: #f8f3ea;
  --line: #e7e0d1;
  --line-soft: #f0eadd;
  --ink: #1f2937;
  --muted: #4b5563;
  --faint: #9ca3af;
  --accent: #b3561b;            /* dusk orange, darkened to read on paper */
  --accent-soft: rgba(219, 122, 42, 0.12);
  --btn-bg: #1f2937;
  --btn-ink: #fffdfa;
  --ok: #3d7a44;
  --bad: #a33a32;
  --bad-bg: rgba(163, 58, 50, 0.07);
  --band-workspace: rgba(219, 122, 42, 0.07);
  --band-motor: rgba(45, 94, 157, 0.07);
  --motor-ink: #2d5e9d;
  --r1: rgba(219, 122, 42, 0.95);
  --r10: rgba(219, 122, 42, 0.55);
  --r100: rgba(219, 122, 42, 0.30);
  --r1k: rgba(219, 122, 42, 0.14);
  --r10k: rgba(120, 112, 96, 0.07);
  --shadow: 0 1px 2px rgba(26, 25, 23, 0.05);
}

:root[data-theme="dark"] {
  --bg: #181613;
  --panel: #1f1d19;
  --panel-2: #282520;
  --line: #363228;
  --line-soft: #2c2922;
  --ink: #e9e4d8;
  --muted: #a29b8a;
  --faint: #6f695c;
  --accent: #d9a441;
  --accent-soft: rgba(217, 164, 65, 0.14);
  --btn-bg: #e9e4d8;
  --btn-ink: #26241f;
  --ok: #7fb886;
  --bad: #d98079;
  --bad-bg: rgba(217, 128, 121, 0.08);
  --band-workspace: rgba(217, 164, 65, 0.07);
  --band-motor: rgba(125, 145, 175, 0.08);
  --motor-ink: #93a7c4;
  --r1: rgba(228, 172, 56, 0.92);
  --r10: rgba(228, 172, 56, 0.50);
  --r100: rgba(228, 172, 56, 0.28);
  --r1k: rgba(228, 172, 56, 0.13);
  --r10k: rgba(160, 150, 130, 0.07);
  --shadow: none;
}

:root {
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --sans: "Satoshi", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", "JetBrains Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  padding: 26px clamp(16px, 4vw, 48px) 40px;
  max-width: 1360px;
  margin: 0 auto;
}
.hidden { display: none !important; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; cursor: pointer; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---- header ---- */
header {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 20px; margin-bottom: 26px; padding-bottom: 22px;
  border-bottom: 1px solid var(--line-soft); flex-wrap: wrap;
}
.title-block { max-width: 720px; }
h1 {
  font-family: var(--serif); font-size: clamp(27px, 3.6vw, 36px); font-weight: 600;
  letter-spacing: -0.025em; line-height: 1.12; margin: 0;
}
.title-mark { color: var(--accent); }
.subtitle-row {
  display: flex; align-items: baseline; flex-wrap: wrap; gap: 10px; margin-top: 9px;
}
.subtitle {
  margin: 0; color: var(--muted); font-size: 15px; font-family: var(--serif);
  font-style: italic; line-height: 1.45; max-width: 34em;
}
.model-badge {
  font-family: var(--mono); font-size: 10.5px; font-weight: 500; letter-spacing: 0.02em;
  padding: 3px 9px; border-radius: 999px; border: 1px solid var(--line);
  color: var(--muted); background: var(--panel); white-space: nowrap;
}
.header-side { display: flex; align-items: center; gap: 10px; padding-top: 8px; flex: none; }

.status {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 13px; color: var(--muted); white-space: nowrap;
}
.status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--faint); flex: none;
}
.status.is-warming .status-dot { background: var(--accent); animation: breathe 1.8s ease-in-out infinite; }
.status.is-ready .status-dot { background: var(--ok); }
.status.is-error .status-dot { background: var(--bad); }
@keyframes breathe { 50% { opacity: 0.35; } }
@media (prefers-reduced-motion: reduce) { .status-dot { animation: none !important; } }

.theme-toggle {
  background: none; border: 1px solid var(--line); border-radius: 6px;
  color: var(--muted); padding: 4px; display: inline-flex; align-items: center;
}
.theme-toggle:hover { color: var(--ink); border-color: var(--faint); }
.theme-toggle svg { width: 16px; height: 16px; display: block; }
/* show the sun while dark (click → light), the moon while light */
.theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

/* ---- prompt row ---- */
.prompt-row { display: flex; gap: 10px; align-items: stretch; flex-wrap: wrap; }
#prompt {
  flex: 1 1 420px; background: var(--panel); color: var(--ink); border: 1px solid var(--line);
  border-radius: 8px; padding: 11px 13px; font-family: var(--serif); font-size: 15px;
  resize: vertical; box-shadow: var(--shadow);
}
#prompt::placeholder { color: var(--faint); }
#prompt:focus { border-color: var(--accent); outline: none; }
.prompt-controls { display: flex; flex-direction: column; gap: 8px; }
#analyze-btn {
  background: var(--btn-bg); color: var(--btn-ink); border: none; border-radius: 8px;
  padding: 10px 26px; font-weight: 600; font-size: 14px;
}
#analyze-btn:hover { opacity: 0.88; }
#analyze-btn:disabled { opacity: 0.55; cursor: wait; }
#analyze-btn .key-hint {
  font-family: var(--mono); font-size: 11px; font-weight: 400;
  margin-left: 6px; padding: 0 5px; border-radius: 4px;
  border: 1px solid color-mix(in srgb, currentColor 35%, transparent);
  background: color-mix(in srgb, currentColor 12%, transparent);
}

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--panel); }
.seg-btn { background: transparent; color: var(--muted); border: none; padding: 6px 12px; font-size: 13px; }
.seg-btn + .seg-btn { border-left: 1px solid var(--line); }
.seg-btn.active { background: var(--panel-2); color: var(--ink); font-weight: 600; }
.seg-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.seg.small .seg-btn { padding: 4px 10px; font-size: 12px; }

/* ---- run config + advanced options ---- */
.run-config {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 10px;
}
.run-config #advanced-toggle { margin-left: auto; }
.cfg-label {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--muted); font-size: 12.5px; white-space: nowrap;
}
.cfg-label select, .iv-num {
  background: var(--panel); color: var(--ink); border: 1px solid var(--line);
  border-radius: 6px; padding: 3px 6px; font: inherit; font-size: 12.5px;
}
.iv-num { width: 52px; font-family: var(--mono); }
.mono-val { font-family: var(--mono); font-size: 12px; color: var(--ink); min-width: 40px; }
.advanced {
  margin: 0 0 10px; display: flex; flex-wrap: wrap; gap: 14px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px 15px;
}
.advanced:not(.hidden) {
  margin-bottom: 0;
  border-bottom-left-radius: 0; border-bottom-right-radius: 0;
  border-bottom-color: var(--line-soft);
}
.advanced:not(.hidden) + .prompt-row #prompt {
  border-top-left-radius: 0; border-top-right-radius: 0; border-top-color: var(--line-soft);
}
.advanced:not(.hidden) + .prompt-row #prompt:focus { border-top-color: var(--accent); }
.adv-field {
  display: flex; flex-direction: column; gap: 4px; flex: 1 1 300px;
  font-size: 12px; color: var(--muted);
}
.adv-hint { color: var(--faint); }
.adv-field input {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--ink);
  border-radius: 6px; padding: 6px 9px; font-family: var(--mono); font-size: 13px;
}
.adv-field input::placeholder { color: var(--faint); }
body:not(.chat-mode) .adv-field { opacity: 0.7; }
body.chat-mode .adv-field { opacity: 1; }

/* ---- transcript (chat bubbles, neuronpedia-style) ---- */
#completion-card { margin-bottom: 12px; background: var(--panel-2); }
.transcript { display: flex; flex-direction: column; gap: 10px; padding: 4px 2px; }
.tr-bubble {
  max-width: 82%; background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 10px 14px;
  font-family: var(--serif); font-size: 15px; line-height: 1.75; box-shadow: var(--shadow);
}
.tr-user { align-self: flex-end; border-bottom-right-radius: 4px; }
.tr-assistant { align-self: flex-start; border-bottom-left-radius: 4px; }
.tr-system {
  align-self: stretch; max-width: none;
  background: color-mix(in srgb, var(--panel) 80%, var(--line-soft));
  border-style: dashed; border-radius: 8px;
}
.tr-tok {
  background: none; border: none; padding: 0 1px; margin: 0; border-radius: 3px;
  font: inherit; white-space: pre-wrap; cursor: pointer;
}
.tr-tok:hover { background: var(--accent-soft); }
.tr-tok.tr-special { font-family: var(--mono); font-size: 11px; color: var(--faint); }
.tr-tok.tr-gen { background: var(--band-motor); }
.tr-tok.tr-gen:hover { background: var(--accent-soft); }
.tr-tok.tr-sel { outline: 2px solid var(--accent); outline-offset: 0; }

/* ---- patience note (cold start) ---- */
.patience {
  margin: 12px 2px 0; color: var(--muted); font-size: 13.5px;
  font-family: var(--serif); font-style: italic;
}

/* ---- examples ---- */
.examples { margin-top: 12px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.examples-label { color: var(--faint); font-size: 13px; font-family: var(--serif); font-style: italic; }
.example {
  background: var(--panel); border: 1px solid var(--line); color: var(--muted);
  border-radius: 99px; padding: 4px 13px; font-size: 13px;
}
.example:hover { color: var(--ink); border-color: var(--faint); }

.error {
  margin-top: 14px; background: var(--bad-bg); border: 1px solid var(--bad);
  color: var(--bad); border-radius: 8px; padding: 10px 14px; font-size: 13px;
}

/* ---- summary row ---- */
#results { margin-top: 22px; }
.summary-row { display: grid; grid-template-columns: minmax(240px, 1fr) minmax(320px, 2fr); gap: 12px; }
@media (max-width: 900px) { .summary-row { grid-template-columns: 1fr; } }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 15px; box-shadow: var(--shadow);
}
.card-label {
  font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--faint); margin-bottom: 8px;
}
.card-label .hint { text-transform: none; letter-spacing: 0; }

.prediction-list { display: flex; flex-wrap: wrap; gap: 6px; }
.pred {
  font-family: var(--mono); font-size: 13px; background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 6px; padding: 4px 9px; display: inline-flex; gap: 7px; align-items: baseline; cursor: pointer;
}
.pred:hover { border-color: var(--accent); }
.pred:first-child { border-color: var(--accent); background: var(--accent-soft); }
.pred .p { color: var(--muted); font-size: 11px; }

.pins-line { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.pins { display: flex; flex-wrap: wrap; gap: 6px; }
.pin-chip {
  font-family: var(--mono); font-size: 12.5px; border-radius: 99px; padding: 3px 10px;
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid; background: transparent;
}
.pin-chip.loading { opacity: 0.5; }
.pin-chip .x { cursor: pointer; opacity: 0.7; font-size: 14px; line-height: 1; background: none; border: none; color: inherit; padding: 0; }
.pin-chip .x:hover { opacity: 1; }
.pin-chip.active-pin { box-shadow: 0 0 0 1px currentColor inset; }
#pin-form { display: flex; gap: 5px; }
#pin-input {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--ink); border-radius: 6px;
  padding: 4px 9px; font-family: var(--mono); font-size: 12.5px; width: 120px;
}
#pin-input::placeholder { color: var(--faint); }
.ghost-btn { background: none; border: 1px solid var(--line); color: var(--muted); border-radius: 6px; padding: 3px 10px; font-size: 12px; }
.ghost-btn:hover { color: var(--ink); }

.rank-legend { margin-top: 9px; display: flex; align-items: center; gap: 5px; font-size: 11px; color: var(--muted); font-family: var(--mono); }
.rank-legend i { width: 16px; height: 10px; border-radius: 2px; display: inline-block; margin-left: 7px; border: 1px solid var(--line-soft); }
.rank-legend .l-r1 { background: var(--r1); }
.rank-legend .l-r10 { background: var(--r10); }
.rank-legend .l-r100 { background: var(--r100); }
.rank-legend .l-r1k { background: var(--r1k); }
.rank-legend .l-r10k { background: var(--r10k); }

/* ---- panels ---- */
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  margin-top: 14px; overflow: hidden; box-shadow: var(--shadow);
}
.panel-head {
  display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap;
  padding: 11px 15px 9px; border-bottom: 1px solid var(--line);
}
.panel-head h2 { font-size: 13.5px; font-weight: 600; margin: 0; font-family: var(--mono); }
.panel-hint { margin: 0; margin-left: auto; color: var(--faint); font-size: 12px; }
.panel-head-right {
  display: flex; align-items: baseline; gap: 14px; margin-left: auto; flex-wrap: wrap;
}
.panel-head-right .panel-hint { margin-left: 0; }
#grid-panel .panel-head h2 { flex: 1 1 200px; min-width: 0; }

/* ---- the grid (signature element) ---- */
.grid-scroll { overflow-x: auto; }
/* Fixed layout: the label column is pinned at 96px, token columns share the rest equally.
   JS sets a min-width on the table (~80px per token column) so long prompts scroll. */
#grid { border-collapse: collapse; font-family: var(--mono); font-size: 12px; width: 100%; table-layout: fixed; }
#grid th, #grid td { padding: 0; border: 1px solid var(--line-soft); }
#grid td.cell {
  height: 23px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  padding: 1px 6px; color: var(--ink); cursor: pointer; text-align: left;
}
#grid td.cell:hover { outline: 1px solid var(--accent); outline-offset: -1px; }
#grid th.layer-label {
  width: 96px; position: sticky; left: 0; z-index: 2; background: var(--panel-2); color: var(--muted);
  font-weight: 500; font-size: 11px; padding: 1px 9px; text-align: right; white-space: nowrap;
  overflow: hidden; border-right: 1px solid var(--line);
}
#grid tr.row-motor th.layer-label { color: var(--motor-ink); }
#grid tr.row-workspace th.layer-label { color: var(--accent); }
#grid tr.row-sensory td.cell { color: var(--faint); }
#grid tr.row-workspace td.cell { background: var(--band-workspace); }
#grid tr.row-motor td.cell { background: var(--band-motor); }
#grid tr.axis-row th.layer-label { color: var(--ink); }
#grid td.axis-tok {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  padding: 4px 6px; color: var(--ink); background: var(--panel-2); cursor: pointer; font-weight: 600;
  border-top: 2px solid var(--line); position: sticky; bottom: 0;
}
#grid td.axis-tok:hover { color: var(--accent); }
/* crosshair */
#grid td.cell.sel-col, #grid td.axis-tok.sel-col { background-color: var(--accent-soft); }
#grid tr.sel-row td.cell { background-color: var(--accent-soft); }
#grid td.cell.selected { outline: 2px solid var(--accent); outline-offset: -2px; }
/* rank heatmap mode */
#grid.rank-mode td.cell.rank-r1 { background-color: var(--r1); color: #1f2937; font-weight: 600; }
#grid.rank-mode td.cell.rank-r10 { background-color: var(--r10); font-weight: 600; }
#grid.rank-mode td.cell.rank-r100 { background-color: var(--r100); }
#grid.rank-mode td.cell.rank-r1k { background-color: var(--r1k); color: var(--muted); }
#grid.rank-mode td.cell.rank-r10k { background-color: var(--r10k); color: var(--faint); }

/* generated positions in the axis + stacks */
#grid td.axis-tok.is-gen { color: var(--motor-ink); font-style: italic; }
.stack-table tr.is-gen-row th.layer-label { color: var(--motor-ink); font-style: italic; }

/* ---- J-Space aggregate panel ---- */
.jspace { max-height: 380px; overflow-y: auto; padding: 4px 0 8px; }
.js-row, .js-strip-legend {
  display: flex; align-items: center; gap: 10px; padding: 6px 15px;
}
.js-row { border-bottom: 1px solid var(--line-soft); }
.js-row:last-child { border-bottom: none; }
.js-row:hover { background: var(--accent-soft); }
.js-tok { min-width: 108px; max-width: 140px; text-align: left; flex: none; }
.js-tok-ghost { visibility: hidden; min-width: 108px; max-width: 140px; flex: none; }
.js-count {
  font-family: var(--mono); font-size: 11.5px; color: var(--muted);
  min-width: 34px; text-align: right; flex: none; font-variant-numeric: tabular-nums;
}
.js-strip {
  display: inline-flex; gap: 2px; flex: 1; min-width: 160px; max-width: 520px;
  height: 16px; padding: 2px 3px; background: var(--panel-2);
  border: 1px solid var(--line-soft); border-radius: 4px; align-items: stretch;
}
.js-strip i.js-cell {
  flex: 1; min-width: 5px; border-radius: 2px; position: relative;
  background: var(--accent); opacity: var(--cell-op, 1);
}
.js-strip i.js-cell.is-zero {
  opacity: 1;
  background: color-mix(in srgb, var(--faint) 14%, var(--panel-2));
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--faint) 70%, var(--line));
  box-sizing: border-box;
}
.js-strip i.js-cell.is-label {
  background: transparent; border: none; opacity: 1; overflow: visible;
}
.js-strip i.js-cell.is-label span {
  position: absolute; bottom: calc(100% + 3px); left: 50%; transform: translateX(-50%);
  font-family: var(--mono); font-size: 8px; color: var(--faint); white-space: nowrap;
  pointer-events: none;
}
.js-strip-legend { padding-top: 2px; padding-bottom: 0; border-bottom: 1px solid var(--line); }
.js-strip-legend .js-strip { background: transparent; border-color: transparent; height: 18px; }
.js-actions { display: inline-flex; gap: 5px; visibility: hidden; min-width: 88px; flex: none; }
.js-row:hover .js-actions { visibility: visible; }
.mini-btn {
  background: none; border: 1px solid var(--line); color: var(--muted);
  border-radius: 5px; padding: 1px 8px; font-size: 11px;
}
.mini-btn:hover { color: var(--accent); border-color: var(--accent); }
.js-empty { padding: 10px 15px; }
.js-filter { font-size: 12px; }
.js-filter input { accent-color: var(--accent); margin: 0 2px 0 0; vertical-align: -2px; }

/* ---- intervention panel ---- */
.intervene-body { padding: 12px 15px; }
.intervene-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.iv-input {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--ink);
  border-radius: 6px; padding: 5px 9px; font-family: var(--mono); font-size: 13px; width: 130px;
}
.iv-input::placeholder { color: var(--faint); }
#iv-run {
  background: var(--btn-bg); color: var(--btn-ink); border: none; border-radius: 7px;
  padding: 7px 16px; font-weight: 600; font-size: 13px;
}
#iv-run:disabled { opacity: 0.55; cursor: wait; }
#intervene-panel .panel-head { justify-content: space-between; }
#iv-note { margin-top: 10px; max-width: 720px; }
.iv-results { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 14px; }
@media (max-width: 800px) { .iv-results { grid-template-columns: 1fr; } }
.iv-col { background: var(--panel-2); border: 1px solid var(--line-soft); border-radius: 8px; padding: 10px 13px; }
.iv-gen { font-family: var(--mono); font-size: 13.5px; margin: 0 0 8px; white-space: pre-wrap; }
.iv-top { display: flex; flex-wrap: wrap; gap: 4px; }
#iv-strength-wrap input[type="range"] { accent-color: var(--accent); }

/* ---- detail panels ---- */
.detail-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 1000px) { .detail-row { grid-template-columns: 1fr; } }
/* by-layer / by-position: same table language as the grid */
.stack { overflow: auto; height: 420px; }
.stack-table { border-collapse: collapse; font-family: var(--mono); font-size: 12px; width: max-content; min-width: 100%; }
.stack-table th, .stack-table td { padding: 0; border: 1px solid var(--line-soft); }
.stack-table td.tok-cell {
  min-width: 88px; max-width: 140px; height: 23px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  padding: 1px 6px; color: var(--ink); cursor: pointer; text-align: left;
}
.stack-table td.tok-cell:hover { outline: 1px solid var(--accent); outline-offset: -1px; }
.stack-table td.tok-cell .p { color: var(--faint); font-size: 10px; margin-left: 4px; }
.stack-table td.tok-cell.rank1 { font-weight: 600; }
.stack-table th.layer-label {
  width: 96px; position: sticky; left: 0; z-index: 2; background: var(--panel-2); color: var(--muted);
  font-weight: 500; font-size: 11px; padding: 1px 9px; text-align: right; white-space: nowrap;
  overflow: hidden; border-right: 1px solid var(--line); cursor: pointer;
}
.stack-table th.layer-label:hover { color: var(--accent); }
.stack-table tr.row-workspace th.layer-label { color: var(--accent); }
.stack-table tr.row-motor th.layer-label { color: var(--motor-ink); }
.stack-table tr.row-sensory td.tok-cell { color: var(--faint); }
.stack-table tr.row-workspace td.tok-cell { background: var(--band-workspace); }
.stack-table tr.row-motor td.tok-cell { background: var(--band-motor); }
.stack-table tr.is-selected td.tok-cell { background-color: var(--accent-soft); }
.stack-table tr.is-selected th.layer-label { color: var(--ink); }
/* by-position: separate sticky pos + token anchor columns */
.by-pos-table { --pos-col: 44px; --tok-col: 104px; }
.by-pos-table th.pos-label,
.by-pos-table th.tok-label {
  position: sticky; z-index: 2; font-weight: 500; height: 23px;
  font-size: 11px; padding: 1px 8px; white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; border-right: 1px solid var(--line); cursor: pointer;
  background: var(--panel-2);
}
.by-pos-table th.pos-label {
  left: 0; width: var(--pos-col); min-width: var(--pos-col); max-width: var(--pos-col);
  text-align: right; color: var(--faint); font-variant-numeric: tabular-nums;
}
.by-pos-table th.tok-label {
  left: var(--pos-col); width: var(--tok-col); min-width: var(--tok-col); max-width: var(--tok-col);
  text-align: left; color: var(--muted);
  box-shadow: 6px 0 8px -6px color-mix(in srgb, var(--ink) 18%, transparent);
}
.by-pos-table th.pos-label:hover,
.by-pos-table th.tok-label:hover { color: var(--accent); }
.by-pos-table tr.is-gen-row th.tok-label { color: var(--motor-ink); font-style: italic; }
.by-pos-table tr.is-selected th.pos-label,
.by-pos-table tr.is-selected th.tok-label {
  z-index: 3; color: var(--ink);
  background: color-mix(in srgb, var(--accent) 16%, var(--panel-2));
}
.by-pos-table tr.stack-head th {
  position: sticky; top: 0; z-index: 4; background: var(--panel);
  font-size: 10px; font-weight: 500; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--faint); padding: 5px 8px; cursor: default; border-bottom: 1px solid var(--line);
  height: auto;
}
.by-pos-table tr.stack-head th.pos-label { left: 0; z-index: 5; }
.by-pos-table tr.stack-head th.tok-label {
  left: var(--pos-col); z-index: 5;
  box-shadow: 6px 0 8px -6px color-mix(in srgb, var(--ink) 18%, transparent);
}
.by-pos-table tr.stack-head th.stack-head-rest { border-bottom: 1px solid var(--line); }
.tok {
  font-family: var(--mono); font-size: 12px; background: var(--panel-2); border: 1px solid transparent;
  border-radius: 4px; padding: 1px 6px; cursor: pointer; color: var(--ink); white-space: pre;
}
.tok:hover { border-color: var(--accent); }
.tok .p { color: var(--faint); font-size: 10px; margin-left: 4px; }
.tok.rank1 { background: var(--accent-soft); }

.chart { display: block; width: 100%; height: 170px; border-top: 1px solid var(--line); background: var(--panel); }
.chart text { font-family: var(--mono); font-size: 9px; fill: var(--faint); }
.chart .gridline { stroke: var(--line-soft); stroke-width: 1; }
.chart .bandrect { fill: var(--band-workspace); }
.chart .rankline { fill: none; stroke-width: 1.6; }
.chart .empty-note { font-size: 10px; fill: var(--faint); }

/* ---- footer ---- */
footer { margin-top: 36px; color: var(--muted); border-top: 1px solid var(--line); padding-top: 18px; }
footer summary { cursor: pointer; font-size: 14px; color: var(--muted); font-family: var(--serif); }
footer summary:hover { color: var(--ink); }
.about { max-width: 860px; font-size: 14px; font-family: var(--serif); line-height: 1.6; }
.about mjx-container { font-size: 105%; }

.references { margin-top: 22px; }
.references h3 {
  font-family: var(--serif); font-size: 15px; font-weight: 600; color: var(--ink); margin: 0 0 10px;
}
.references ul {
  margin: 0; padding-left: 20px; font-family: var(--serif); font-size: 13.5px; line-height: 1.65;
  column-count: 2; column-gap: 56px;
}
.references li { margin-bottom: 6px; break-inside: avoid; }
@media (max-width: 900px) { .references ul { column-count: 1; } }

.colophon {
  margin-top: 22px; font-family: var(--serif); font-size: 13.5px;
  color: var(--muted); font-style: italic;
}

.version-line {
  margin-top: 6px; font-family: var(--mono); font-size: 11px; color: var(--faint);
}
