:root {
  --bg: #f7f5f0;
  --panel: #ffffff;
  --fg: #1f1d19;
  --muted: #6d675c;
  --border: #e2ddd2;
  --accent: #3d5bd9;
  --accent-fg: #ffffff;
  --surprise: 0;
  --heat: 222 70% 52%;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14130f;
    --panel: #1d1c17;
    --fg: #ece8de;
    --muted: #a39d90;
    --border: #36332b;
    --accent: #7d95f2;
    --accent-fg: #10121c;
    --heat: 222 85% 68%;
    color-scheme: dark;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

header,
main {
  max-width: 820px;
  margin: 0 auto;
  padding: 0 16px;
}

header {
  padding-top: 40px;
  padding-bottom: 8px;
}

h1 {
  margin: 0;
  font-size: 2rem;
  letter-spacing: -0.02em;
}

.lede {
  margin: 4px 0 0;
  color: var(--muted);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  margin: 16px 0;
}

.field-label {
  display: block;
  font-weight: 600;
  margin-bottom: 6px;
}

textarea,
input[type="number"] {
  width: 100%;
  font: inherit;
  color: inherit;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}

textarea {
  resize: vertical;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.05rem;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 10px 0 4px;
}

button {
  font: inherit;
  cursor: pointer;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: inherit;
  padding: 8px 14px;
}

button:disabled {
  cursor: progress;
  opacity: 0.6;
}

.chip {
  font-size: 0.85rem;
  padding: 4px 10px;
  border-radius: 999px;
  color: var(--muted);
}

.chip:hover,
button:not(.primary):hover {
  border-color: var(--accent);
}

.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-fg);
  font-weight: 600;
  min-width: 140px;
}

.sliders {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px 20px;
  margin: 16px 0;
}

.sliders label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.9rem;
  color: var(--muted);
}

.sliders output {
  color: var(--fg);
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.seed {
  display: flex;
  gap: 6px;
}

.seed input {
  padding: 6px 10px;
}

.seed button {
  padding: 4px 12px;
}

.actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  cursor: pointer;
}

progress {
  width: 100%;
  margin-top: 14px;
  accent-color: var(--accent);
}

#status {
  margin: 8px 0 0;
  font-size: 0.85rem;
  color: var(--muted);
}

#status.error {
  color: #c0392b;
}

.story {
  min-height: 8em;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.1rem;
  line-height: 1.7;
}

.story .prompt {
  color: var(--muted);
}

.story .end {
  display: inline-block;
  margin-left: 6px;
  font: 0.75rem system-ui, sans-serif;
  color: var(--muted);
  border: 1px dashed var(--border);
  border-radius: 6px;
  padding: 0 6px;
}

.story.show-tokens .tok {
  border-radius: 3px;
  box-shadow: inset 0 0 0 1px hsl(var(--heat) / 0.35);
  background: hsl(var(--heat) / calc(var(--surprise) * 0.55));
}

.story.show-tokens .tok:hover {
  box-shadow: inset 0 0 0 2px var(--accent);
}

#stats {
  margin: 12px 0 0;
  font-size: 0.85rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.legend,
.notes {
  font-size: 0.85rem;
  color: var(--muted);
}

.notes {
  padding: 0 4px 40px;
}

.notes a {
  color: var(--accent);
}

/* ---------- navigation ---------- */

.nav {
  display: flex;
  gap: 16px;
  margin-bottom: 12px;
  font-size: 0.9rem;
}

.nav a {
  color: var(--muted);
  text-decoration: none;
}

.nav a[aria-current="page"] {
  color: var(--fg);
  font-weight: 600;
}

/* ---------- microscope ---------- */

h2 {
  font-size: 1.05rem;
  margin: 0 0 12px;
}

h3 {
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 600;
  margin: 16px 0 6px;
}

.hint {
  font-size: 0.85rem;
  color: var(--muted);
}

input[type="search"] {
  width: 100%;
  font: inherit;
  color: inherit;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
}

.token-strip {
  margin-top: 16px;
}

.token-strip .tok {
  cursor: pointer;
  border-radius: 3px;
  box-shadow: inset 0 0 0 1px var(--border);
}

.token-strip .tok:hover,
.token-strip .tok.selected {
  box-shadow: inset 0 0 0 2px var(--accent);
}

.token-strip.feature-view .tok,
.examples .tok {
  background: hsl(var(--heat) / calc(var(--heat-alpha, 0) * 0.7));
}

.columns {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 0 16px;
}

.columns .panel {
  margin: 0 0 16px;
}

.feature-list {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  max-height: 420px;
  overflow-y: auto;
}

.feature-list li {
  margin: 0;
  font-size: 0.9rem;
  color: var(--muted);
}

.feature-row {
  display: grid;
  grid-template-columns: 4.2em 1fr auto;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
  border: 0;
  border-radius: 6px;
  padding: 5px 6px;
  background: transparent;
}

.feature-row:hover {
  background: var(--bg);
}

.fid {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 0.85rem;
}

.flabel {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 0.85rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.fmeta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.bar {
  display: inline-block;
  width: 60px;
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(to right, var(--accent) calc(var(--w) * 100%), var(--border) 0);
}

.dist-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0 16px;
}

.dist {
  margin: 0;
  padding-left: 1.4em;
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 0.85rem;
}

.examples {
  margin: 0;
  padding-left: 1.6em;
  font-family: Georgia, "Times New Roman", serif;
  line-height: 1.8;
}

.examples li {
  margin-bottom: 8px;
  overflow-wrap: anywhere;
}

.examples .tok {
  border-radius: 3px;
  white-space: pre-wrap;
}

.examples .tok.eot {
  color: var(--muted);
  font: 0.8em system-ui, sans-serif;
}

.examples .tok.peak {
  box-shadow: inset 0 0 0 2px var(--accent);
}

code {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 0.9em;
}

/* ---------- steering ---------- */

.steer {
  margin: 4px 0 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
}

.steer summary {
  cursor: pointer;
  font-weight: 600;
}

.steer select {
  font: inherit;
  color: inherit;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 8px;
}

/* ---------- circuit graph ---------- */

.circuit-graph svg {
  width: 100%;
  height: auto;
  display: block;
}

.circuit text {
  fill: var(--fg);
  font: 13px ui-monospace, "Cascadia Mono", Consolas, monospace;
}

.circuit .node-effect {
  fill: var(--muted);
}

.circuit .node-feature rect {
  fill: var(--bg);
  stroke: var(--border);
}

.circuit .node-feature {
  cursor: pointer;
}

.circuit .node-feature:hover rect,
.circuit .node-feature:focus rect {
  stroke: var(--accent);
}

.circuit .node-target rect {
  fill: var(--bg);
  stroke: var(--accent);
  stroke-width: 2;
}

.circuit .edge-active {
  stroke: var(--border);
  stroke-width: 1.5;
}

.circuit .edge-plus {
  stroke: var(--accent);
  stroke-opacity: 0.75;
}

.circuit .edge-minus {
  stroke: #d9534f;
  stroke-opacity: 0.75;
}

/* ---------- replay charts (palette validated with the dataviz validator) ---------- */

.viz-root {
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --tick: #6d675c;
  --chart-surface: var(--panel);
}

@media (prefers-color-scheme: dark) {
  .viz-root {
    --series-1: #3987e5;
    --series-2: #d95926;
    --grid: #2c2c2a;
    --axis: #383835;
    --tick: #a39d90;
  }
}

.chart svg {
  width: 100%;
  height: auto;
  display: block;
  overflow: visible;
}

.chart .grid {
  stroke: var(--grid);
  stroke-width: 1;
}

.chart .axis {
  stroke: var(--axis);
  stroke-width: 1;
}

.chart .tick {
  fill: var(--tick);
  font: 11px system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
}

.chart .band {
  fill: var(--fg);
  fill-opacity: 0.06;
}

.chart .line {
  fill: none;
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.chart .line.s1 { stroke: var(--series-1); }
.chart .line.s2 { stroke: var(--series-2); }

.chart .dot {
  stroke: var(--chart-surface);
  stroke-width: 2;
}

.chart .dot.s1 { fill: var(--series-1); }
.chart .dot.s2 { fill: var(--series-2); }

.chart .selected {
  stroke: var(--fg);
  stroke-width: 1;
  stroke-opacity: 0.6;
}

.chart .crosshair {
  stroke: var(--tick);
  stroke-width: 1;
}

.chart .ref {
  stroke: var(--axis);
  stroke-width: 1;
}

.chart .ref-label {
  fill: var(--tick);
  font: 11px system-ui, sans-serif;
}

.chart .hit {
  fill: transparent;
  cursor: crosshair;
}

.chart .cell {
  fill: var(--series-1);
  fill-opacity: var(--a);
}

.chart .cell:hover {
  stroke: var(--fg);
}

.chart .target {
  fill: none;
  stroke: var(--series-2);
  stroke-width: 1.5;
}

.legend-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 14px;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 6px;
}

.key {
  display: inline-block;
  width: 16px;
  height: 2px;
  border-radius: 1px;
  vertical-align: middle;
  margin-right: 4px;
}

.key-1 { background: var(--series-1); }
.key-2 { background: var(--series-2); }

.key-band {
  height: 10px;
  background: var(--fg);
  opacity: 0.12;
}

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.tile {
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: var(--bg);
  border-radius: 8px;
  padding: 10px 12px;
}

.tile-label {
  font-size: 0.8rem;
  color: var(--muted);
}

.tile-value {
  font-size: 1.4rem;
  font-weight: 600;
}

.tile-note {
  font-size: 0.8rem;
  color: var(--muted);
}

.verdict {
  margin: 12px 0 0;
  font-size: 0.95rem;
}

.seg {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 10px;
}

.seg button {
  border: 0;
  border-radius: 0;
  font-size: 0.85rem;
  padding: 5px 10px;
  background: transparent;
}

.seg button.seg-on {
  background: var(--bg);
  font-weight: 600;
}

.heads {
  display: grid;
  grid-template-columns: 2.4em repeat(calc(var(--cols) - 1), 1fr);
  gap: 4px;
  align-items: center;
}

.head-axis {
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
}

.head-cell {
  padding: 10px 0;
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--series-1) calc(var(--a) * 85%), var(--panel));
}

.head-cell.on {
  outline: 2px solid var(--series-2);
  outline-offset: 1px;
}

.samples {
  overflow-wrap: anywhere; /* early checkpoints write very long "words" */
  padding-left: 1.4em;
  font-family: Georgia, "Times New Roman", serif;
  line-height: 1.6;
}

.samples li {
  margin-bottom: 8px;
}

.table-wrap {
  overflow-x: auto;
}

#table {
  border-collapse: collapse;
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
  margin-top: 10px;
}

#table th,
#table td {
  padding: 4px 10px;
  border-bottom: 1px solid var(--border);
  text-align: right;
}

.tooltip {
  position: fixed;
  z-index: 10;
  pointer-events: none;
  background: var(--panel);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.8rem;
  box-shadow: 0 4px 16px rgb(0 0 0 / 0.12);
  max-width: 320px;
}

.tip-row {
  display: flex;
  align-items: center;
  gap: 4px;
}

.tip-row span:last-child {
  color: var(--muted);
}

input[type="range"]#ckpt {
  margin: 4px 0;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

/* ---------- name guard ---------- */

.story .redacted {
  color: var(--muted);
  letter-spacing: -0.05em;
  cursor: help;
}

.inline-select {
  font: inherit;
  color: inherit;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 8px;
}

/* ---------- case study ---------- */

.kicker {
  margin: 0 0 6px;
  font-size: 0.85rem;
  color: var(--muted);
}

.article {
  padding-bottom: 56px;
}

.article h2 {
  font-size: 1.35rem;
  letter-spacing: -0.01em;
  margin: 44px 0 12px;
}

.article p,
.article li {
  line-height: 1.65;
}

.article ul {
  padding-left: 1.2em;
}

.article li {
  margin-bottom: 8px;
}

.article a {
  color: var(--accent);
}

.article .tile {
  background: var(--panel);
  border: 1px solid var(--border);
}

.cta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 20px 0 8px;
}

.button {
  display: inline-block;
  padding: 9px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  color: var(--fg);
  font-weight: 600;
  text-align: center;
  text-decoration: none;
}

.button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-fg);
}

.button:hover {
  border-color: var(--accent);
}

.tldr {
  margin: 24px 0;
  padding: 4px 20px 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: 12px;
}

.article .tldr h2 {
  margin: 16px 0 8px;
  font-size: 1.05rem;
}

.fig {
  margin: 20px 0;
  padding: 16px 20px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.fig figcaption {
  margin-bottom: 12px;
  font-size: 0.9rem;
  color: var(--muted);
}

.fig figcaption strong {
  color: var(--fg);
}

.fig.shot {
  padding: 0;
  overflow: hidden;
}

.fig.shot img {
  display: block;
  width: 100%;
  height: auto;
}

.fig.shot figcaption {
  margin: 0;
  padding: 10px 16px 12px;
  border-top: 1px solid var(--border);
}

.story-sample {
  margin: 0;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.02rem;
  line-height: 1.7;
}

.story-sample .prompt {
  color: var(--muted);
}

/* horizontal bars; values sit at the bar ends and in a table */

.hbars {
  display: grid;
  gap: 14px;
  margin: 10px 0 12px;
}

.hgroup {
  display: grid;
  grid-template-columns: 12rem 1fr;
  gap: 4px 12px;
  align-items: center;
}

.hlabel {
  font-size: 0.875rem;
}

.htracks {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.htrack {
  display: flex;
  align-items: center;
  gap: 8px;
}

.hbar {
  flex: none;
  width: calc(var(--v) * (100% - 3.25rem));
  min-width: 2px;
  height: 14px;
  border-radius: 0 4px 4px 0;
}

.hbar.s0 { background: var(--tick); }
.hbar.s1 { background: var(--series-1); }
.hbar.s2 { background: var(--series-2); }

.hval {
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}

.hnote {
  font-size: 0.8rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.key-bar {
  width: 10px;
  height: 10px;
  border-radius: 2px;
}

.key-0 { background: var(--tick); }

details summary {
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--muted);
}

table.data {
  border-collapse: collapse;
  margin-top: 8px;
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

table.data th,
table.data td {
  padding: 4px 10px;
  border-bottom: 1px solid var(--border);
  text-align: right;
}

table.data th:first-child,
table.data td:first-child {
  text-align: left;
}

.stack {
  font-size: 0.85rem;
  color: var(--muted);
}

.links {
  margin-top: 24px;
}

@media (max-width: 560px) {
  h1 {
    font-size: 1.6rem;
  }

  .hgroup {
    grid-template-columns: 1fr;
  }
}

/* ---------- first-visit guidance ---------- */

.intro h2 {
  margin-bottom: 12px;
}

.intro .hint {
  margin: 12px 0 0;
}

.intro a,
.steer .hint a {
  color: var(--accent);
}

.try-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.try {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding: 12px 14px;
  text-align: left;
  background: var(--bg);
  border-radius: 10px;
}

.try b {
  color: var(--accent);
}

.try span {
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.4;
}

.steps {
  margin: 0 0 14px;
  padding-left: 1.3em;
}

.steps li {
  margin-bottom: 6px;
  line-height: 1.5;
}

.story:empty::before {
  content: attr(data-placeholder);
  color: var(--muted);
  font: 0.95rem/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.replay-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.replay-head .field-label {
  margin: 0;
}

#ckpt-story {
  min-height: 5.1em;
}

@media (max-width: 640px) {
  .try-grid {
    grid-template-columns: 1fr;
  }
}
