/* ── Design tokens ──────────────────────────────────────────────────── */
:root {
  --bg:         #fbfbfa;
  --surface:    #f4f4f2;
  --surface-2:  #eaeae7;
  --surface-3:  #dededa;
  --border:     #e3e3df;
  --border-2:   #cfcfc9;
  --text:       #18181b;
  --text-2:     #52525b;
  --text-3:     #8a8a95;
  --accent:     #b45309;
  --accent-dim: rgba(180, 83, 9, 0.10);
  --ds-color:   #1d4ed8;
  --ds-bg:      rgba(29, 78, 216, 0.10);
  --alg-color:  #c2410c;
  --alg-bg:     rgba(194, 65, 12, 0.10);
  --conc-color: #0f766e;
  --conc-bg:    rgba(15, 118, 110, 0.10);
  --std-color:  #7c3aed;
  --std-bg:     rgba(124, 58, 237, 0.10);
  --mark-bg:    rgba(180, 83, 9, 0.20);
  --font-sans:  -apple-system, 'Helvetica Neue', Arial, sans-serif;
  --font-mono:  ui-monospace, 'Cascadia Code', 'JetBrains Mono', 'Fira Code', 'Menlo', monospace;
  --panel-w:    360px;
  --radius:     4px;
}

:root[data-theme="dark"] {
  --bg:         #0c0c0f;
  --surface:    #111116;
  --surface-2:  #1a1a22;
  --surface-3:  #222230;
  --border:     #252530;
  --border-2:   #32324a;
  --text:       #e6e4e0;
  --text-2:     #9a98a8;
  --text-3:     #6a6878;
  --accent:     #e8a049;
  --accent-dim: rgba(232, 160, 73, 0.12);
  --ds-color:   #4d9fff;
  --ds-bg:      rgba(77, 159, 255, 0.1);
  --alg-color:  #ff7b3f;
  --alg-bg:     rgba(255, 123, 63, 0.1);
  --conc-color: #2dd4bf;
  --conc-bg:    rgba(45, 212, 191, 0.12);
  --std-color:  #a78bfa;
  --std-bg:     rgba(167, 139, 250, 0.12);
  --mark-bg:    rgba(232, 160, 73, 0.22);
}

/* ── Reset ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── App grid ───────────────────────────────────────────────────────── */
#app {
  display: grid;
  grid-template-columns: var(--panel-w) 1fr;
  height: 100vh;
  overflow: hidden;
}

/* ── Search panel ───────────────────────────────────────────────────── */
#search-panel {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow: hidden;
}

#site-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 20px 20px 16px;
  flex-shrink: 0;
}

.site-brand {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.15em;
  color: var(--accent);
  text-transform: uppercase;
}

.site-subtitle {
  font-size: 10px;
  letter-spacing: 0.1em;
  color: var(--text-3);
  text-transform: uppercase;
}

.theme-toggle {
  margin-left: auto;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  color: var(--text-2);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
  transition: color 0.1s, border-color 0.1s, background 0.1s;
}

.theme-toggle:hover { color: var(--text); border-color: var(--accent); }
.theme-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Search input */
.search-wrap {
  position: relative;
  margin: 0 12px 10px;
  flex-shrink: 0;
}

.search-icon {
  position: absolute;
  left: 9px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-3);
  font-size: 15px;
  pointer-events: none;
  user-select: none;
  line-height: 1;
}

#search {
  width: 100%;
  padding: 8px 10px 8px 30px;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 13px;
  outline: none;
  transition: border-color 0.12s, box-shadow 0.12s;
  -webkit-appearance: none;
  appearance: none;
}

#search::-webkit-search-cancel-button,
#search::-webkit-search-decoration { display: none; }

#search::placeholder { color: var(--text-3); }

#search:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

/* Results list */
#results-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
  padding-bottom: 8px;
  min-height: 0;
}

#results-list::-webkit-scrollbar { width: 3px; }
#results-list::-webkit-scrollbar-track { background: transparent; }
#results-list::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 2px; }

/* List section label */
.results-label {
  padding: 10px 16px 4px;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-3);
  user-select: none;
}

/* Result item */
.result-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 16px;
  cursor: pointer;
  border-left: 1px solid transparent;
  transition: background 0.07s;
  outline: none;
}

.result-item:hover { background: var(--surface-2); }

.result-item.active {
  background: var(--accent-dim);
  border-left-color: var(--accent);
}

.result-item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.result-name {
  flex: 1;
  font-size: 14px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}

.result-name mark {
  background: var(--mark-bg);
  color: var(--accent);
  border-radius: 2px;
  padding: 0 1px;
}

/* Badge */
.badge {
  flex-shrink: 0;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 2px;
  white-space: nowrap;
}

.badge-ds   { color: var(--ds-color);   background: var(--ds-bg); }
.badge-alg  { color: var(--alg-color);  background: var(--alg-bg); }
.badge-conc { color: var(--conc-color); background: var(--conc-bg); }
.badge-std  { color: var(--std-color);  background: var(--std-bg); }

/* Empty / no-result states */
.state-message {
  padding: 24px 16px;
  font-size: 12px;
  color: var(--text-2);
  line-height: 1.6;
}

.state-message strong {
  color: var(--text);
  font-weight: 500;
}

/* ── Entry panel ────────────────────────────────────────────────────── */
#entry-panel {
  overflow-y: auto;
  background: var(--bg);
  min-height: 0;
}

#entry-panel::-webkit-scrollbar { width: 5px; }
#entry-panel::-webkit-scrollbar-track { background: transparent; }
#entry-panel::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.entry-inner {
  max-width: 1340px;
  margin: 0 auto;
  padding: 44px 40px 96px;
}

/* Entry header */
.entry-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 28px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--border);
}

.entry-title-group { flex: 1; min-width: 0; }

.entry-title {
  font-size: 26px;
  font-weight: 600;
  line-height: 1.25;
  color: var(--text);
  margin-bottom: 10px;
  letter-spacing: -0.02em;
  word-break: break-word;
}

.entry-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.entry-source {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-3);
  text-decoration: none;
  letter-spacing: 0.02em;
}

.entry-source:hover { color: var(--text-2); }

.entry-source:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Back button */
.btn-back {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  color: var(--text-2);
  font-family: var(--font-sans);
  font-size: 11px;
  cursor: pointer;
  letter-spacing: 0.03em;
  transition: background 0.1s, color 0.1s;
  line-height: 1.4;
}

.btn-back:hover { background: var(--surface-3); color: var(--text); }

.btn-back:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Entry sections */
.entry-description {
  font-size: 16px;
  line-height: 1.75;
  color: var(--text-2);
  margin-bottom: 32px;
}

.entry-description p { margin-bottom: 10px; }
.entry-description p:last-child { margin-bottom: 0; }

.entry-description code {
  font-family: var(--font-mono);
  font-size: 14px;
  background: var(--surface-2);
  padding: 1px 5px;
  border-radius: 3px;
  color: var(--text);
}

.entry-section { margin-bottom: 32px; overflow-x: auto; }

.entry-section-heading {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-3);
  margin-bottom: 12px;
}

/* Tables */
.entry-section table {
  width: 100%;
  border-collapse: collapse;
  font-size: 15px;
}

.entry-section th {
  padding: 5px 14px 5px 0;
  text-align: left;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-3);
  border-bottom: 1px solid var(--border);
}

.entry-section td {
  padding: 8px 14px 8px 0;
  color: var(--text-2);
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  line-height: 1.5;
}

.entry-section td:first-child { color: var(--text); }

.entry-section td code,
.entry-section th code {
  font-family: var(--font-mono);
  font-size: 14px;
  background: var(--surface-2);
  padding: 1px 5px;
  border-radius: 3px;
  color: var(--accent);
}

/* Lists */
.entry-section ul,
.entry-section ol {
  padding-left: 18px;
  color: var(--text-2);
  font-size: 16px;
  line-height: 1.7;
}

.entry-section li { margin-bottom: 5px; }

.entry-section p {
  color: var(--text-2);
  font-size: 16px;
  line-height: 1.7;
  margin-bottom: 8px;
}

.entry-section p:last-child { margin-bottom: 0; }

.entry-section p code,
.entry-section li code {
  font-family: var(--font-mono);
  font-size: 14px;
  background: var(--surface-2);
  padding: 1px 5px;
  border-radius: 3px;
  color: var(--text);
}

/* Code samples */
.code-sample { margin-bottom: 28px; }

.code-sample:last-child { margin-bottom: 0; }

.code-sample-heading {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-3);
  margin-bottom: 8px;
}

/* Visually hidden -- screen readers only */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* Code block wrapper -- relative container so copy button can anchor top-right */
.code-block-wrap { position: relative; }

/* Copy button */
.copy-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 6px;
  background: var(--surface-3);
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  color: var(--text-3);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s, background 0.1s, color 0.1s, border-color 0.1s;
  z-index: 1;
  line-height: 1;
}

.code-block-wrap:hover .copy-btn,
.copy-btn:focus-visible { opacity: 1; }

.copy-btn:hover {
  background: var(--surface-2);
  color: var(--text-2);
  border-color: var(--accent);
}

.copy-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.copy-btn.copied {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-dim);
  opacity: 1;
}

/* Related entries section */
.entry-related { margin-bottom: 32px; }

.related-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.related-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: 13px;
  color: var(--text);
  line-height: 1.3;
  transition: background 0.1s, border-color 0.1s, color 0.1s;
  text-align: left;
}

.related-chip:hover {
  background: var(--surface-3);
  border-color: var(--accent);
  color: var(--text);
}

.related-chip:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.related-chip-name {
  font-weight: 500;
}

/* Code hero block -- sits immediately after the entry header */
.code-samples-hero {
  margin-bottom: 36px;
}

/* Chroma pre override -- inline styles from catppuccin-mocha */
#entry-panel pre {
  overflow-x: auto !important;
  border-radius: var(--radius) !important;
  border: 1px solid var(--border) !important;
  font-family: var(--font-mono) !important;
  font-size: 15px !important;
  line-height: 1.75 !important;
  padding: 20px 22px !important;
  margin: 0 !important;
  tab-size: 4;
}

#entry-panel code {
  font-family: var(--font-mono);
  tab-size: 4;
}

/* ── Global focus visible ───────────────────────────────────────────── */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ── Responsive: single column at 640px ────────────────────────────── */
@media (max-width: 640px) {
  #app {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    height: 100dvh;
    height: 100vh; /* fallback */
  }

  #search-panel {
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 45vh;
  }

  #entry-panel {
    overflow-y: auto;
  }

  .entry-inner { padding: 24px 20px 56px; }

  .entry-title { font-size: 20px; }

  .entry-header { flex-direction: column; gap: 12px; }

  /* Larger touch targets on mobile */
  .result-item { padding: 11px 16px; }
}

@media (max-width: 400px) {
  .entry-inner { padding: 16px 14px 40px; }
}

/* ── Visualizer tokens (reference existing theme vars) ──────────────── */
:root {
  --viz-cell-bg:            var(--surface-2);
  --viz-cell-border:        var(--border-2);
  --viz-cell-active-bg:     var(--surface-3);
  --viz-cell-hl-bg:         var(--accent-dim);
  --viz-cell-hl-border:     var(--accent);
  --viz-cell-inactive-bg:   var(--surface);
  --viz-cell-inactive-opacity: 0.45;
  --viz-ptr-color:          var(--accent);
  --viz-line-active-bg:     var(--accent-dim);
  --viz-line-active-border: var(--accent);
}

/* ── Visualizer layout ──────────────────────────────────────────────── */

.viz-section {
  margin-bottom: 36px;
}

.viz-section-heading {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-3);
  margin-bottom: 14px;
}

/* Debugger split: code left, structure right */
.viz-split {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(220px, 1fr);
  gap: 12px;
  align-items: start;
  margin-bottom: 10px;
}

/* Code panel */
.viz-code-panel {
  position: relative;          /* offsetParent for active-line scroll tracking */
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow-y: auto;
  overflow-x: auto;            /* long code+note scrolls horizontally, never wraps */
  max-height: 640px;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.65;
}

.viz-code-pre {
  padding: 14px 0;
}

.viz-code-line {
  display: flex;
  /* nowrap keeps the step note inline, trailing the code on the same row */
  flex-wrap: nowrap;
  align-items: baseline;
  padding: 0 14px 0 0;
  border-left: 2px solid transparent;
  transition: background 0.12s, border-color 0.12s;
  width: max-content;        /* grow to content so the panel scrolls horizontally */
  min-width: 100%;           /* but fill the panel so the active highlight spans it */
}

.viz-code-line.viz-line-active {
  background: var(--viz-line-active-bg);
  border-left-color: var(--viz-line-active-border);
}

.viz-line-num {
  flex-shrink: 0;
  width: 38px;
  padding: 0 10px;
  text-align: right;
  color: var(--text-3);
  user-select: none;
  font-size: 11px;
  line-height: inherit;
}

.viz-line-code {
  flex: 0 0 auto;            /* size to content so the note sits right after it */
  white-space: pre;
  color: var(--text);
  line-height: inherit;
}

/* Inline step note: an italic trailing comment on the SAME row as the active
   code, immediately after the code text (like `d.grow() // buf is nil`). Never
   wraps to its own line; long code+note scrolls horizontally via the panel.
   --text-3 is #8a8a95 (light) / #6a6878 (dark); both pass WCAG AA at 13px
   against the --surface panel background. */
.viz-line-note {
  flex: 0 0 auto;
  margin-left: 1.5em;       /* gap between code and the trailing comment */
  color: var(--text-3);
  font-style: italic;
  white-space: pre;         /* stay on one line, trailing the code */
  line-height: inherit;
  pointer-events: none;
  user-select: none;
  opacity: 0;
  transition: opacity 0.12s;
}

.viz-code-line.viz-line-active .viz-line-note { opacity: 1; }

/* Structure panel */
.viz-struct-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 20px;
  overflow: auto;
  min-height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.viz-svg {
  display: block;
  overflow: visible;
  max-width: 100%;
  /* Per-render JS sets fixed px width/height attrs equal to the viewBox extent.
     max-width:100% shrinks the width on narrow containers, but without height:auto
     the box keeps its fixed px height -> letterboxing + tiny cells. height:auto
     lets the height track the scaled width via the intrinsic viewBox aspect ratio.
     On desktop (container wider than intrinsic width) nothing changes: width stays
     at the attr value, height:auto resolves to the intrinsic height. */
  height: auto;
}

/* ── SVG cell groups: glide via CSS transform ───────────────────────── */
.viz-cell-g {
  transition: transform 0.32s ease;
}

.viz-ptr-g {
  transition: transform 0.32s ease;
}

/* SVG cell elements (positioned inside .viz-cell-g) */
.viz-cell-rect {
  fill: var(--viz-cell-bg);
  stroke: var(--viz-cell-border);
  stroke-width: 1.5;
  transition: fill 0.18s ease, stroke 0.18s ease, opacity 0.18s ease;
}

.viz-cell-rect.viz-cell-active {
  fill: var(--viz-cell-active-bg);
}

.viz-cell-rect.viz-cell-highlight {
  fill: var(--viz-cell-hl-bg);
  stroke: var(--viz-cell-hl-border);
  stroke-width: 2;
}

.viz-cell-rect.viz-cell-inactive {
  fill: var(--viz-cell-inactive-bg);
  stroke: var(--viz-cell-border);
  opacity: var(--viz-cell-inactive-opacity);
}

.viz-cell-text {
  fill: var(--text);
  font-family: var(--font-mono);
  font-size: 13px;
  dominant-baseline: middle;
  text-anchor: middle;
  pointer-events: none;
  transition: fill 0.18s ease;
}

.viz-cell-text.viz-cell-text-inactive {
  fill: var(--text-3);
}

.viz-idx-label {
  fill: var(--text-3);
  font-family: var(--font-mono);
  font-size: 10px;
  dominant-baseline: middle;
  text-anchor: middle;
  pointer-events: none;
}

/* Empty state label */
.viz-empty-label {
  fill: var(--text-3);
  font-family: var(--font-mono);
  font-size: 12px;
  dominant-baseline: middle;
  text-anchor: middle;
}

/* Pointer arrows and labels */
.viz-ptr-line {
  stroke: var(--viz-ptr-color);
  stroke-width: 1.5;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.viz-ptr-label {
  fill: var(--viz-ptr-color);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  dominant-baseline: middle;
  text-anchor: middle;
  pointer-events: none;
}

/* Transport controls */
.viz-transport {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-top: 4px;
}

.viz-transport-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  color: var(--text-2);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  transition: background 0.1s, color 0.1s, border-color 0.1s;
  flex-shrink: 0;
}

.viz-transport-btn:hover {
  background: var(--surface-3);
  color: var(--text);
  border-color: var(--accent);
}

.viz-transport-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.viz-transport-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

.viz-transport-btn.viz-playing {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-dim);
}

.viz-speed-group {
  display: inline-flex;
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  overflow: hidden;
  flex-shrink: 0;
}

.viz-speed-btn {
  padding: 4px 8px;
  background: var(--surface-2);
  border: none;
  border-right: 1px solid var(--border-2);
  color: var(--text-3);
  font-family: var(--font-mono);
  font-size: 11px;
  cursor: pointer;
  transition: background 0.1s, color 0.1s;
  line-height: 1.4;
}

.viz-speed-btn:last-child { border-right: none; }

.viz-speed-btn:hover { background: var(--surface-3); color: var(--text-2); }

.viz-speed-btn.viz-speed-active {
  background: var(--accent-dim);
  color: var(--accent);
}

.viz-speed-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.viz-step-counter {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-3);
  white-space: nowrap;
  margin-left: 4px;
}


/* ── Right column: call-stack panel stacked above struct panel ─────── */
.viz-right-col {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

/* ── Call-stack breadcrumb panel ─────────────────────────────────────── */
.viz-callstack-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--accent-dim);
  padding: 6px 12px;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-2);
  min-height: 46px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.viz-callstack-panel::before {
  content: 'CALL STACK';
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-3);
  user-select: none;
  flex-shrink: 0;
}

.viz-callstack-breadcrumb {
  display: flex;
  align-items: center;
  gap: 2px;
  white-space: nowrap;
  overflow-x: auto;
  min-height: 16px;
}

.viz-callstack-frame {
  color: var(--text-2);
}

.viz-callstack-frame.viz-callstack-active {
  color: var(--text);
  font-weight: 600;
}

.viz-callstack-sep {
  color: var(--text-3);
  user-select: none;
}

/* ── Locals panel ────────────────────────────────────────────────────── */
.viz-locals-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 6px 12px;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-2);
  max-height: 200px;
  overflow-y: auto;
}

.viz-locals-panel::before {
  content: 'LOCALS';
  display: block;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-3);
  user-select: none;
  margin-bottom: 4px;
}

.viz-locals-table {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.viz-locals-row {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0 12px;
  padding: 1px 4px;
  border-radius: var(--radius);
}

.viz-locals-row.viz-locals-changed {
  background: var(--accent-dim);
  border-left: 2px solid var(--accent);
  padding-left: 2px;
}

.viz-locals-row.viz-locals-changed .viz-locals-var,
.viz-locals-row.viz-locals-changed .viz-locals-val {
  font-weight: 600;
}

.viz-locals-var {
  color: var(--text);
}

.viz-locals-val {
  color: var(--accent);
}

/* ── Step-in / step-over / step-out button group ─────────────────────── */
.viz-step-group {
  display: inline-flex;
  gap: 2px;
  flex-shrink: 0;
}

/* ── Transport vertical divider ─────────────────────────────────────── */
.viz-transport-sep {
  width: 1px;
  height: 20px;
  background: var(--border-2);
  flex-shrink: 0;
  align-self: center;
}

/* ── Debug step buttons (icon + key-label) ──────────────────────────── */
.viz-debug-btn {
  width: auto;
  min-width: 36px;
  padding: 0 7px;
  gap: 3px;
}

.viz-debug-icon {
  font-size: 14px;
  line-height: 1;
}

.viz-debug-label {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.04em;
  color: inherit;
}

/* ── R2 tree renderer nodes and edges ───────────────────────────────── */
.viz-node-g {
  transition: transform 0.32s ease;
}
.viz-node-circle {
  fill: var(--viz-cell-bg);
  stroke: var(--viz-cell-border);
  stroke-width: 1.5px;
}
.viz-node-circle.viz-node-active {
  fill: var(--viz-cell-active-bg);
  stroke: var(--viz-ptr-color);
  stroke-width: 2px;
}
.viz-node-circle.viz-node-highlight {
  fill: var(--viz-cell-hl-bg);
  stroke: var(--viz-cell-hl-border);
  stroke-width: 2px;
}
.viz-node-text {
  fill: var(--text);
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  dominant-baseline: middle;
  text-anchor: middle;
  pointer-events: none;
}
.viz-edge-line {
  stroke: var(--viz-cell-border);
  stroke-width: 1.5px;
  transition: opacity 0.18s ease;
}

/* ── N-ary tree (trie) extras: character edge labels + end-of-word ring ─ */
.viz-tedge-label {
  fill: var(--viz-ptr-color);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  dominant-baseline: middle;
  text-anchor: middle;
  pointer-events: none;
  transition: opacity 0.18s ease;
}
.viz-node-end-ring {
  fill: none;
  stroke: var(--viz-cell-hl-border);
  stroke-width: 1.5px;
  pointer-events: none;
}

/* ── R3 linked-list renderer nodes and arrows ───────────────────────── */
.viz-ll-node-g {
  transition: transform 0.32s ease;
}
.viz-ll-node-rect {
  fill: var(--viz-cell-bg);
  stroke: var(--viz-cell-border);
  stroke-width: 1.5px;
  rx: 4px;
}
.viz-ll-node-rect.viz-ll-node-active {
  fill: var(--viz-cell-active-bg);
  stroke: var(--viz-ptr-color);
  stroke-width: 2px;
}
.viz-ll-node-rect.viz-ll-node-highlight {
  fill: var(--viz-cell-hl-bg);
  stroke: var(--viz-cell-hl-border);
  stroke-width: 2px;
}
.viz-ll-node-text {
  fill: var(--text);
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  dominant-baseline: middle;
  text-anchor: middle;
  pointer-events: none;
}
.viz-ll-arrow-next {
  stroke: var(--viz-ptr-color);
  stroke-width: 1.5px;
  marker-end: url(#viz-arrow-head);
  transition: opacity 0.18s ease;
}
.viz-ll-arrow-prev {
  stroke: var(--viz-ptr-color);
  stroke-width: 1.5px;
  marker-end: url(#viz-arrow-head);
  transition: opacity 0.18s ease;
  opacity: 0.6;
}
.viz-ll-head-label,
.viz-ll-tail-label {
  fill: var(--viz-ptr-color);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  dominant-baseline: auto;
  text-anchor: middle;
  pointer-events: none;
}

/* ── R4 graph renderer nodes and edges ──────────────────────────────── */
.viz-graph-node-g {
  transition: transform 0.32s ease;
}
.viz-graph-node {
  stroke-width: 1.5px;
  transition: fill 0.25s ease, stroke 0.25s ease, opacity 0.25s ease;
}
.viz-graph-node-unvisited {
  fill: var(--viz-cell-bg);
  stroke: var(--viz-cell-border);
}
/* frontier = discovered but not yet processed: dashed ring reads as "queued". */
.viz-graph-node-frontier {
  fill: var(--viz-cell-bg);
  stroke: var(--viz-cell-hl-border);
  stroke-dasharray: 3 2.5;
}
/* visited = processed: filled accent tint + solid ring. */
.viz-graph-node-visited {
  fill: var(--viz-cell-hl-bg);
  stroke: var(--viz-ptr-color);
}
/* settled = fully explored: faded back. */
.viz-graph-node-settled {
  fill: var(--viz-cell-inactive-bg);
  stroke: var(--viz-cell-border);
  opacity: var(--viz-cell-inactive-opacity);
}
.viz-graph-node.viz-graph-node-active {
  stroke: var(--viz-ptr-color);
  stroke-width: 3px;
}
.viz-graph-node.viz-graph-node-highlight {
  stroke: var(--viz-cell-hl-border);
  stroke-width: 2.5px;
}
.viz-graph-node-text {
  fill: var(--text);
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  dominant-baseline: middle;
  text-anchor: middle;
  pointer-events: none;
}
.viz-graph-dist {
  fill: var(--text-2);
  font-family: var(--font-mono);
  font-size: 10px;
  dominant-baseline: middle;
  text-anchor: middle;
  pointer-events: none;
}
.viz-graph-edge {
  stroke: var(--viz-cell-border);
  stroke-width: 1.5px;
  transition: stroke 0.2s ease, opacity 0.2s ease;
}
.viz-graph-edge.viz-graph-edge-active {
  stroke: var(--viz-ptr-color);
  stroke-width: 2.5px;
}
.viz-graph-arrow-poly {
  fill: none;
  stroke: var(--viz-cell-border);
  stroke-width: 1.2px;
}
.viz-graph-weight {
  fill: var(--text-2);
  font-family: var(--font-mono);
  font-size: 10px;
  text-anchor: middle;
  pointer-events: none;
}

/* ── R5 grid / DP-table cells ───────────────────────────────────────── */
/* Default = unfilled slot: muted, dashed border signals "not computed yet".
   filled = solid cell with a value. dep = dependency read this step (dashed
   accent outline, no fill change). current = cell written this step (the focal
   accent fill + bold border). Precedence in markup: current beats dep beats
   highlight beats active beats filled. */
.viz-grid-cell {
  fill: var(--viz-cell-bg);
  stroke: var(--viz-cell-border);
  stroke-width: 1px;
  stroke-dasharray: 3 3;          /* unfilled slots read as pending */
  transition: fill 0.2s ease, stroke 0.2s ease, opacity 0.2s ease;
}
.viz-grid-cell.viz-grid-cell-filled {
  stroke-dasharray: none;         /* a value landed here */
}
.viz-grid-cell.viz-grid-cell-active {
  fill: var(--viz-cell-active-bg);
  stroke: var(--viz-cell-border);
}
.viz-grid-cell.viz-grid-cell-highlight {
  fill: var(--viz-cell-hl-bg);
  stroke: var(--viz-cell-hl-border);
}
.viz-grid-cell.viz-grid-cell-dep {
  fill: var(--viz-cell-bg);
  stroke: var(--viz-ptr-color);
  stroke-width: 2px;
  stroke-dasharray: 4 2;          /* "being read" = dashed accent ring */
}
.viz-grid-cell.viz-grid-cell-current {
  fill: var(--viz-cell-hl-bg);
  stroke: var(--viz-cell-hl-border);
  stroke-width: 2.5px;
  stroke-dasharray: none;         /* "being written" = solid bold accent */
}
.viz-grid-cell-text {
  fill: var(--text);
  font-family: var(--font-mono);
  font-size: 16px;
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
  user-select: none;
}
.viz-grid-label {
  fill: var(--text-3);
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
  user-select: none;
}
.viz-grid-ptr-label {
  fill: var(--viz-ptr-color);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  text-anchor: middle;
  pointer-events: none;
  user-select: none;
}

/* ── R6 LRU cache: hash buckets + recency list + connectors ──────────── */
/* Region captions and bucket index labels read as muted scaffolding so the
   filled cells and live nodes stay the focus. */
.viz-lru-caption {
  fill: var(--text-3);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  dominant-baseline: hanging;
  text-anchor: start;
  pointer-events: none;
  user-select: none;
}
.viz-lru-bucket-idx {
  fill: var(--text-3);
  font-family: var(--font-mono);
  font-size: 10px;
  text-anchor: middle;
  dominant-baseline: auto;
  pointer-events: none;
  user-select: none;
}
/* Empty bucket = dashed border (pending slot). Filled = solid. Active = the
   bucket touched this step (accent fill + bold border). */
.viz-lru-bucket-rect {
  fill: var(--viz-cell-bg);
  stroke: var(--viz-cell-border);
  stroke-width: 1.5px;
  stroke-dasharray: 3 3;
  transition: fill 0.2s ease, stroke 0.2s ease;
}
.viz-lru-bucket-rect.viz-lru-bucket-filled {
  stroke-dasharray: none;
}
.viz-lru-bucket-rect.viz-lru-bucket-active {
  fill: var(--viz-cell-hl-bg);
  stroke: var(--viz-cell-hl-border);
  stroke-width: 2.5px;
}
.viz-lru-bucket-key {
  fill: var(--text);
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 600;
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
  user-select: none;
}
.viz-lru-node-g {
  transition: transform 0.32s ease;
}
.viz-lru-node-rect {
  fill: var(--viz-cell-bg);
  stroke: var(--viz-cell-border);
  stroke-width: 1.5px;
}
.viz-lru-node-rect.viz-lru-node-active {
  fill: var(--viz-cell-active-bg);
  stroke: var(--viz-ptr-color);
  stroke-width: 2.5px;
}
.viz-lru-node-text {
  fill: var(--text);
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
  user-select: none;
}
.viz-lru-next {
  stroke: var(--viz-ptr-color);
  stroke-width: 1.5px;
  marker-end: url(#viz-lru-arrow);
  transition: opacity 0.18s ease;
}
/* Connector from a bucket down to its node: dashed + muted so it reads as a
   reference, not part of the list spine. Active = its bucket or node is the
   focus this step. */
.viz-lru-conn {
  stroke: var(--viz-cell-border);
  stroke-width: 1.3px;
  stroke-dasharray: 4 3;
  marker-end: url(#viz-lru-arrow);
  opacity: 0.7;
  transition: stroke 0.2s ease, opacity 0.2s ease;
}
.viz-lru-conn.viz-lru-conn-active {
  stroke: var(--viz-ptr-color);
  opacity: 1;
}
.viz-lru-endlabel {
  fill: var(--viz-ptr-color);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  text-anchor: middle;
  dominant-baseline: auto;
  pointer-events: none;
  user-select: none;
}

/* ── prefers-reduced-motion: snap all viz motion ────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .viz-cell-g,
  .viz-ptr-g,
  .viz-cell-rect,
  .viz-cell-text,
  .viz-code-line,
  .viz-transport-btn,
  .viz-speed-btn,
  .viz-callstack-frame,
  .viz-line-note,
  .viz-node-g,
  .viz-edge-line,
  .viz-tedge-label,
  .viz-node-end-ring,
  .viz-ll-node-g,
  .viz-ll-arrow-next,
  .viz-ll-arrow-prev,
  .viz-graph-node-g,
  .viz-graph-node,
  .viz-graph-edge,
  .viz-grid-cell,
  .viz-lru-bucket-rect,
  .viz-lru-node-g,
  .viz-lru-next,
  .viz-lru-conn {
    transition: none !important;
    animation: none !important;
  }
}

/* ── Responsive: stack split on small screens ───────────────────────────
   Stack to a single column at 900px (not 640px). Between roughly 640px and
   1000px the two-column split squeezed the code panel down to a few dozen
   pixels, which forced both the code and the wrapped note to overflow.
   Stacking earlier keeps the code panel full width and prevents that. */
@media (max-width: 900px) {
  .viz-split {
    grid-template-columns: 1fr;
  }

  .viz-code-panel {
    max-height: 220px;
  }

  .viz-struct-panel {
    min-height: 160px;
  }
}

/* ── Touch targets: comfortable ≥44px hit areas on touch-class widths ─────
   Tablet + phone (≤768px) are touch-first. The desktop controls (transport
   32px, theme 30px, search/result rows ~31-36px tall) are mouse-sized; bump
   every interactive control to the ~44px minimum recommended for touch.
   Placed after the 900px block so it wins on the controls it shares.
   Desktop (>768px) is untouched, so the M0 1280 baseline is unaffected. */
@media (max-width: 768px) {
  .viz-transport-btn {
    width: 44px;
    height: 44px;
    font-size: 16px;
  }

  .viz-transport { gap: 10px; }

  .viz-speed-btn {
    min-height: 44px;
    padding: 0 14px;
  }

  .theme-toggle {
    width: 44px;
    height: 44px;
    font-size: 18px;
  }

  /* 16px font keeps iOS Safari from zooming the page on focus; min-height
     lifts the field to a full touch target. */
  #search {
    min-height: 44px;
    font-size: 16px;
  }

  .result-item { min-height: 44px; }
}

/* ── Phone widths: tighten chrome so the viz keeps maximum legible area ───
   The page shell already single-columns at 640 and the viz-split at 900, so
   nothing here re-stacks; these only trim padding to claw back horizontal
   room. The SVG (height:auto, above) scales to fit; the code panel keeps its
   intentional horizontal scroll so the inline active-line note never wraps. */
@media (max-width: 375px) {
  .viz-struct-panel { padding: 14px; }

  /* Trim the trailing pad so wide rows scroll a touch less. */
  .viz-code-line { padding-right: 10px; }
}

@media (max-width: 360px) {
  .entry-inner { padding: 14px 12px 36px; }

  .viz-struct-panel { padding: 10px; }
}
