* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: #fff;
  color: #111;
  font-family: -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
  display: flex;
  justify-content: center;
  padding: 64px 24px;
}

.lab {
  width: 100%;
  max-width: 760px;
  display: flex;
  flex-direction: column;
  gap: 34px;
  user-select: none;            /* stop double-click text highlighting on the UI */
  -webkit-user-select: none;
}
.lab pre, .lab textarea, .lab .notes, .lab .proof {
  user-select: text;            /* but keep code, notes, and the input copyable */
  -webkit-user-select: text;
}

/* visualization ------------------------------------------------------------ */
.bars {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  height: 240px;
}
.slot {
  flex: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
}
.val {
  font-family: "SF Mono", ui-monospace, Consolas, monospace;
  font-size: 12px;
  color: #111;
  margin-bottom: 6px;
}
.bar {
  width: 100%;
  background: #e6e6e6;                 /* idle  */
  transition: height .22s cubic-bezier(.4, 0, .2, 1), background .15s ease;
}
.bar.act  { background: #111; }        /* comparing / moving */
.bar.done { background: #b0b0b0; }     /* settled */

/* controls (buttons only) -------------------------------------------------- */
.ctrl { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ctrl .spacer { flex: 1; }

button {
  font: inherit;
  font-size: 13px;
  letter-spacing: .3px;
  color: #111;
  background: none;
  border: 1px solid #111;
  padding: 7px 14px;
  cursor: pointer;
  transition: background .12s, color .12s;
}
button:hover { background: #111; color: #fff; }
button.on    { background: #111; color: #fff; }   /* active algorithm */
button.t     { width: 42px; padding: 7px 0; font-size: 14px; }   /* transport */

input[type=range] {
  width: 100%;
  height: 1px;
  accent-color: #111;
  cursor: pointer;
}

/* code --------------------------------------------------------------------- */
pre {
  font-family: "SF Mono", ui-monospace, Consolas, monospace;
  font-size: 13.5px;
  line-height: 1.7;
}
pre .ln {
  display: block;
  padding: 0 6px 0 16px;
  border-left: 2px solid transparent;
  color: #9a9a9a;
  white-space: pre;
}
pre .ln.active {
  color: #111;
  border-left-color: #111;
  background: #f3f3f3;
  font-weight: 600;
}

/* index page --------------------------------------------------------------- */
.index { gap: 0; }
.index-head { margin-bottom: 34px; }
.index-head h1 {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: .3px;
  margin-bottom: 12px;
}
.index-head p {
  color: #555;
  font-size: 14px;
  line-height: 1.65;
  max-width: 520px;
}
.lab-list {
  display: flex;
  flex-direction: column;
  border-top: 1px solid #eee;
}
.lab-card {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 20px 6px;
  border-bottom: 1px solid #eee;
  text-decoration: none;
  color: #111;
  transition: padding-left .18s ease, background .18s ease;
}
.lab-card:hover { padding-left: 16px; background: #fafafa; }
.lab-card-title { font-size: 16px; font-weight: 600; letter-spacing: .2px; }
.lab-card-sub {
  font-size: 13px;
  color: #888;
  font-family: "SF Mono", ui-monospace, Consolas, monospace;
}
.lab-card.muted { cursor: default; }
.lab-card.muted:hover { padding-left: 6px; background: none; }
.lab-card.muted .lab-card-title { color: #bbb; }
.lab-card.muted .lab-card-sub { color: #ccc; }

/* graph visualization ------------------------------------------------------ */
.gviz { flex: 1 1 auto; min-width: 0; display: flex; justify-content: center; }
.gsvg {
  width: 100%;
  max-width: 600px;
  height: auto;
  overflow: visible;   /* let nodes dragged past the canvas still show */
}
.gnode {
  fill: #e6e6e6; stroke: #9ca3af; stroke-width: 2;
  transition: fill .25s ease, stroke .25s ease;
}
.gnode.frontier { fill: #fef9c3; stroke: #ca8a04; }
.gnode.current  { fill: #111; stroke: #111; }
.gnode.done     { fill: #dcfce7; stroke: #16a34a; }
.gname {
  fill: #111; font: 600 13px -apple-system, "Segoe UI", sans-serif;
  text-anchor: middle; dominant-baseline: central;
}
.gnode.current + .gname { fill: #fff; }
.gdist {
  fill: #555; font: 11px "SF Mono", ui-monospace, monospace; text-anchor: middle;
}
.gedge { stroke: #d1d5db; stroke-width: 2; transition: stroke .2s ease; }
.gedge.tree   { stroke: #111; stroke-width: 2.5; }
.gedge.active { stroke: #111; stroke-width: 3; }
.gedge.rejected { stroke: #ef9a9a; stroke-width: 2.5; stroke-dasharray: 5 4; }   /* cycle edge, skipped */
.ghit { stroke: transparent; stroke-width: 18; fill: none; pointer-events: stroke; }  /* wide grab area */
.gweight { fill: #6b7280; font: 600 13px "SF Mono", ui-monospace, monospace; text-anchor: middle; }
.gname, .gdist, .gweight { pointer-events: none; }

/* typed edge-list input */
.ginput { display: flex; flex-direction: column; gap: 8px; max-width: 320px; }
.ginput-hint { font-size: 12px; color: #9a9a9a; }
.ginput textarea {
  border: none;
  background: #f6f6f6;
  border-radius: 8px;
  padding: 12px 14px;
  min-height: 0;
  resize: none;
  font-family: "SF Mono", ui-monospace, Consolas, monospace;
  font-size: 13px;
  line-height: 1.7;
  color: #111;
}
.ginput textarea:focus { outline: none; box-shadow: inset 0 0 0 2px #e5e7eb; }
.ginput-bar { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.ginput-status { font-size: 11px; color: #9a9a9a; font-family: "SF Mono", ui-monospace, monospace; }
.gcheck { font-size: 12px; color: #555; display: flex; align-items: center; gap: 5px; cursor: pointer; }
.gcheck input { accent-color: #111; }

/* graph stage: a full-width clickable canvas with the structure panel floated top-right */
.gstage { position: relative; display: flex; align-items: flex-start; }
.gstruct {
  position: absolute;
  top: 6px;
  right: 0;
  width: 150px;
  max-height: 480px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding-top: 8px;
  min-height: 20px;
}
.struct-label {
  font-size: 10.5px;
  letter-spacing: .6px;
  text-transform: uppercase;
  color: #9a9a9a;
  margin-bottom: 9px;
}
.struct-cells { display: flex; flex-direction: column; gap: 5px; max-height: 360px; overflow-y: auto; }
.cell {
  width: 40px;
  height: 32px;
  border: 1px solid #d0d0d0;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "SF Mono", ui-monospace, Consolas, monospace;
  font-size: 14px;
  color: #111;
  background: #fff;
  flex-shrink: 0;
}
.cell.removed { border-color: #ededed; background: #fafafa; color: #c8c8c8; }   /* dequeued: stays as history */
.struct-empty { font-size: 12px; color: #c4c4c4; }

/* per-node arrays (dist, visited, key, indeg, parent, ...) — single cell, index in corner */
.arr { display: flex; flex-wrap: wrap; gap: 5px; }
.av {
  position: relative;
  width: 32px;
  height: 30px;
  border: 1px solid #e2e2e2;
  border-radius: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "SF Mono", ui-monospace, Consolas, monospace;
  font-size: 13px;
  color: #111;
  background: #fff;
  cursor: default;
}
.av .ai { position: absolute; top: 1px; left: 3px; font-size: 8px; line-height: 1; color: #bdbdbd; }
.av.off { color: #cfcfcf; }
.cell { cursor: default; }

/* hover-a-cell connector arrow + node ring */
.gconnect { position: fixed; left: 0; top: 0; pointer-events: none; z-index: 60; }
g[data-n].ping circle { stroke: #f59e0b !important; stroke-width: 4 !important; }
.gedge.ping-edge { stroke: #f59e0b !important; stroke-width: 4 !important; }
.cell.cell-hi, .av.cell-hi { border-color: #f59e0b; box-shadow: 0 0 0 1px #f59e0b; }
.struct-val { font-family: "SF Mono", ui-monospace, Consolas, monospace; font-size: 18px; color: #111; }
@media (max-width: 820px) {
  .gstage { flex-direction: column; }
  .gstruct { width: 100%; flex-direction: row; flex-wrap: wrap; gap: 28px; }
  .struct-cells { flex-direction: row; flex-wrap: wrap; }
}

/* editor */
.grubber { stroke: #111; stroke-width: 2; stroke-dasharray: 4 4; pointer-events: none; }
.gviz[data-mode=move] .gnode { cursor: grab; }
.gviz[data-mode=move] .gnode:active { cursor: grabbing; }
.gviz[data-mode=connect] .gnode { cursor: crosshair; }
.gviz[data-mode=connect] .gsvg { cursor: crosshair; }
.gviz[data-mode=add] .gsvg { cursor: copy; }
.gviz[data-mode=add] .ghit,
.gviz[data-mode=add] .gedge { pointer-events: none; }   /* don't let edges swallow add-node clicks */
.gviz[data-mode=delete] .gnode { cursor: pointer; }
.gviz[data-mode=move] .eg,
.gviz[data-mode=delete] .eg { cursor: pointer; }
.gviz[data-mode=move] .eg:hover .gedge,
.gviz[data-mode=delete] .eg:hover .gedge { stroke: #111; stroke-width: 4; }  /* grab feedback */
.weight-edit {
  position: fixed;
  z-index: 60;
  width: 56px;
  padding: 4px 6px;
  border: 1px solid #111;
  border-radius: 4px;
  font-family: "SF Mono", ui-monospace, Consolas, monospace;
  font-size: 13px;
  transform: translate(-50%, -50%);
}

/* right-click radial tool menu */
.gradial {
  position: fixed;
  z-index: 70;
  overflow: visible;
  filter: drop-shadow(0 10px 26px rgba(0, 0, 0, .10));
}
.gradial .wedge path {
  fill: #fcfcfc;
  stroke: #ececec;
  stroke-width: 1.5;
  stroke-linejoin: round;
  cursor: pointer;
  transition: fill .18s ease;
}
.gradial .wedge text {
  fill: #6b6b6b;
  font: 500 12px -apple-system, "Segoe UI", sans-serif;
  letter-spacing: .3px;
  pointer-events: none;
  transition: fill .18s ease;
}
.gradial .wedge:hover path { fill: #efefef; }
.gradial .wedge:hover text { fill: #111; }
.gradial .wedge.on path { fill: #f1f1f1; }
.gradial .wedge.on text { fill: #111; font-weight: 600; }

/* customization panel ------------------------------------------------------ */
.panel {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
  font-size: 13px;
  color: #111;
}
.panel .size { display: flex; align-items: center; gap: 8px; }
.panel .size input[type=range] { width: 140px; }
.panel .size b { font-family: "SF Mono", ui-monospace, Consolas, monospace; min-width: 18px; }
.panel .dist { display: flex; gap: 6px; flex-wrap: wrap; }
.panel .dist button { padding: 5px 10px; font-size: 12px; flex: 0 0 auto; }
/* start picker: a fixed-width horizontally-scrolling strip, so adding nodes never changes the toolbar
   size (which would reflow the layout and shift the graph under the cursor) */
#startwrap { flex: 0 0 300px; flex-wrap: nowrap; overflow-x: scroll; overflow-y: hidden; }
#startwrap::-webkit-scrollbar { height: 4px; }
#startwrap::-webkit-scrollbar-thumb { background: #d2d2d2; border-radius: 2px; }

/* two-column layout: code | analysis -------------------------------------- */
.lab.wide { max-width: 1180px; }
.cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 48px;
  align-items: start;
}
.col-code pre { margin: 0; }
@media (max-width: 820px) {
  .cols { grid-template-columns: 1fr; }
}

/* code line explainer caption */
.codeline {
  margin-top: 16px;
  padding: 11px 14px;
  background: #fafafa;
  border-left: 2px solid #111;
  font-size: 13px;
  line-height: 1.65;
  color: #333;
  min-height: 22px;
}
pre .ln { cursor: default; }
pre .ln:hover { background: #f3f3f3; }

/* big-o section ------------------------------------------------------------ */
.bigo { display: flex; flex-direction: column; gap: 20px; }
.bigo .cx-head {
  display: flex;
  align-items: stretch;
  width: max-content;
  border: 1px solid #ececec;
  border-radius: 10px;
  overflow: hidden;
}
.bigo .cx-hcell { padding: 13px 26px 14px; display: flex; flex-direction: column; gap: 5px; }
.bigo .cx-hsep { width: 1px; background: #ececec; }
.bigo .cx-hk { font-size: 10px; letter-spacing: .7px; text-transform: uppercase; color: #9a9a9a; }
.bigo .cx-hv { font-family: "SF Mono", ui-monospace, Consolas, monospace; font-size: 21px; color: #111; }
.bigo .cx {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-family: "SF Mono", ui-monospace, Consolas, monospace;
  font-size: 12.5px;
}
.bigo .cx-row {
  display: flex;
  gap: 18px;
  align-items: baseline;
  padding: 3px 6px;
  margin: 0 -6px;
  border-radius: 4px;
  cursor: help;
  width: max-content;
  transition: background .12s;
}
.bigo .cx-row:hover { background: #f4f4f4; }
.bigo .cx-row .k { color: #9a9a9a; min-width: 60px; }
.bigo .cx-row .v { color: #111; }

/* hover tooltip */
.tip {
  position: fixed;
  z-index: 50;
  max-width: 280px;
  background: #111;
  color: #fff;
  font-family: -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
  font-size: 12px;
  line-height: 1.55;
  padding: 9px 12px;
  border-radius: 6px;
  pointer-events: none;
  opacity: 0;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .18);
}
.bigo .proof {
  font-size: 13.5px;
  line-height: 1.8;
  color: #222;
}
.bigo .proof .katex { font-size: 1em; }
.bigo .caption { font-size: 11px; color: #9a9a9a; margin-bottom: 6px; }
.bigo svg { width: 100%; max-width: 560px; display: block; }

/* notes (prose from the markdown notes) ------------------------------------ */
.notes {
  border-top: 1px solid #eee;
  padding-top: 20px;
  max-width: 600px;
}
.notes .src {
  font-size: 10.5px;
  letter-spacing: .6px;
  text-transform: uppercase;
  color: #9a9a9a;
  margin-bottom: 12px;
}
.notes .src a { color: #555; }
.notes p {
  margin-bottom: 11px;
  line-height: 1.75;
  font-size: 14px;
  color: #222;
}
.notes.empty p { color: #9a9a9a; }

/* navigation --------------------------------------------------------------- */
.nav {
  display: flex;
  gap: 20px;
  align-items: baseline;
  padding-bottom: 14px;
  border-bottom: 1px solid #eee;
  font-size: 13px;
  letter-spacing: .3px;
}
.nav a { color: #9a9a9a; text-decoration: none; transition: color .12s; }
.nav a:hover { color: #111; }
.nav a.active { color: #111; font-weight: 600; }
.nav .soon { color: #cfcfcf; }

/* editor (playground) ------------------------------------------------------ */
textarea {
  width: 100%;
  min-height: 150px;
  border: 1px solid #111;
  padding: 12px 14px;
  font-family: "SF Mono", ui-monospace, Consolas, monospace;
  font-size: 13px;
  line-height: 1.6;
  color: #111;
  resize: vertical;
  tab-size: 2;
}
textarea:focus { outline: none; border-color: #111; box-shadow: inset 0 0 0 1px #111; }
.status {
  font-family: "SF Mono", ui-monospace, Consolas, monospace;
  font-size: 12px;
  color: #9a9a9a;            /* success / info: muted */
}
.status.warn { color: #111; font-weight: 600; }   /* error / warning: black bold */

/* ---- DP lab ------------------------------------------------------------- */
.dp-stage { display: flex; align-items: flex-start; justify-content: center; gap: 36px; margin: 8px 0 4px; flex-wrap: wrap; }
.dp-viz { flex: 0 0 auto; }
.dp-table { display: grid; gap: 4px; user-select: none; }
.dp-corner, .dp-clabel, .dp-rlabel {
  display: flex; align-items: center; justify-content: center; height: 38px;
  font: 700 14px "SF Mono", ui-monospace, Consolas, monospace; color: #9a9a9a;
}
.dp-hedit {
  width: 36px; height: 32px; padding: 0; text-align: center; text-transform: uppercase;
  border: 1px dashed transparent; border-radius: 5px; background: transparent; color: #6b7280;
  font: 700 14px "SF Mono", ui-monospace, Consolas, monospace; cursor: text;
}
.dp-hedit:hover { border-color: #d4d4d4; }
.dp-hedit:focus { outline: none; border-style: solid; border-color: #111; color: #111; }
.dp-cell {
  display: flex; align-items: center; justify-content: center; height: 38px;
  border: 1px solid #e5e7eb; border-radius: 6px; background: #fff; color: #cfcfcf;
  font: 600 14px "SF Mono", ui-monospace, Consolas, monospace; transition: background .15s, border-color .15s, color .15s;
}
.dp-cell.filled { color: #111; background: #fafafa; }
.dp-cell.from { border-color: #f59e0b; box-shadow: 0 0 0 1px #f59e0b; background: #fff8eb; color: #111; }
.dp-cell.cur { border-color: #111; background: #111; color: #fff; }
.dp-cell.path { background: #dcfce7; border-color: #4ade80; color: #111; }
.dp-cell.path.cur { background: #111; color: #fff; }
.dp-cell.trace { box-shadow: 0 0 0 2px #2563eb; z-index: 1; }     /* "why this value?" dependency chain */
.dp-cell.dead { opacity: 0.22; }                                   /* rolling array: a cell that can be discarded */
.dp-cell { cursor: pointer; }

.dp-side { flex: 0 0 240px; display: flex; flex-direction: column; gap: 18px; padding-top: 4px; }
.dp-block { display: flex; flex-direction: column; gap: 6px; }
.dp-h { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: #9a9a9a; }
.dp-rec { font: 600 13px "SF Mono", ui-monospace, Consolas, monospace; color: #111; line-height: 1.5; word-break: break-word; }
.dp-cx { font-size: 13px; color: #444; }
.dp-ans { font: 700 18px "SF Mono", ui-monospace, Consolas, monospace; color: #9a9a9a; }
.dp-ans.done { color: #111; }

.panel .dp-input { display: inline-flex; align-items: center; gap: 8px; margin-right: 18px; }
.panel .dp-input label { font-size: 13px; color: #555; }
.panel .dp-input input {
  border: 1px solid #d4d4d4; border-radius: 6px; padding: 5px 8px;
  font: 600 13px "SF Mono", ui-monospace, Consolas, monospace; color: #111; text-transform: uppercase;
}
.panel .dp-input input:focus { outline: none; border-color: #111; }

/* DP memoization: recursion tree + memo strip */
.dp-tree { display: flex; flex-direction: column; align-items: center; gap: 16px; }
.dp-tedge { stroke: #d4d4d4; stroke-width: 1.5; }
.dp-tnode rect { fill: #fff; stroke: #d4d4d4; stroke-width: 1.5; }
.dp-tnode .dp-tlabel { fill: #111; font: 600 12px "SF Mono", ui-monospace, Consolas, monospace; text-anchor: middle; }
.dp-tnode .dp-tval { fill: #111; font: 700 12px "SF Mono", ui-monospace, Consolas, monospace; text-anchor: middle; }
.dp-tnode.base rect { fill: #dcfce7; stroke: #4ade80; }
.dp-tnode.computed rect { fill: #f3f4f6; stroke: #9ca3af; }
.dp-tnode.cachehit rect { fill: #fef9c3; stroke: #ca8a04; }          /* a repeated subproblem, served from the cache */
.dp-tnode.cachehit .dp-tlabel, .dp-tnode.cachehit .dp-tval { fill: #713f12; }
.dp-tnode.active rect { fill: #fff; stroke: #111; stroke-dasharray: 3 2; }
.dp-tnode.dup rect { fill: #fee2e2; stroke: #dc2626; }              /* recomputed — the wasteful duplicate */
.dp-tnode.dup .dp-tlabel, .dp-tnode.dup .dp-tval { fill: #7f1d1d; }
.dp-tnode.cur rect { stroke: #111; stroke-width: 2.5; }
.dp-calls { font-weight: 700; }

.dp-work { display: flex; flex-direction: column; gap: 5px; }
.dp-work .dp-w { font-size: 13px; color: #555; }
.dp-work .dp-w b { font: 700 14px "SF Mono", ui-monospace, Consolas, monospace; margin-right: 5px; }
.dp-work .dp-w.naive b { color: #dc2626; }
.dp-work .dp-w.memo b { color: #ca8a04; }
.dp-work .dp-w.tab b { color: #16a34a; }

/* DP compare view: recursion tree next to the table */
.dp-compare { display: flex; flex-direction: column; align-items: center; gap: 18px; width: 100%; }
.dp-cmp-counts { display: flex; gap: 26px; }
.dp-cmp-counts .dp-w { font-size: 13px; color: #555; }
.dp-cmp-counts .dp-w b { font: 700 15px "SF Mono", ui-monospace, Consolas, monospace; margin-right: 5px; }
.dp-cmp-counts .dp-w.naive b { color: #dc2626; }
.dp-cmp-counts .dp-w.memo b { color: #ca8a04; }
.dp-cmp-counts .dp-w.tab b { color: #16a34a; }
.dp-cmp-body { display: flex; gap: 44px; align-items: flex-start; justify-content: center; flex-wrap: wrap; }
.dp-cmp-col { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.dp-cmp-lab { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: #9a9a9a; }

/* ---- bitwise lab -------------------------------------------------------- */
.bit-play { margin: 8px 0 4px; }
.bit-ops { display: flex; gap: 8px; align-items: center; margin-bottom: 22px; flex-wrap: wrap; }
.bit-ops button { padding: 6px 15px; border: 1px solid #d4d4d4; border-radius: 6px; background: #fff; color: #333; cursor: pointer; font-size: 13px; }
.bit-ops button.on { background: #111; color: #fff; border-color: #111; }
.bit-k { display: inline-flex; align-items: center; gap: 7px; margin-left: 12px; font-size: 13px; color: #666; }
.bit-k input { width: 50px; border: 1px solid #d4d4d4; border-radius: 5px; padding: 4px 6px; font: 600 13px "SF Mono", ui-monospace, Consolas, monospace; }
.bit-grid { display: flex; flex-direction: column; gap: 10px; }
.bit-row { display: flex; align-items: center; gap: 12px; }
.bit-rowlabel { width: 78px; text-align: right; font: 600 14px "SF Mono", ui-monospace, Consolas, monospace; color: #111; flex-shrink: 0; }
.bit-dec { width: 76px; border: 1px solid #d4d4d4; border-radius: 5px; padding: 6px 8px; font: 600 13px "SF Mono", ui-monospace, Consolas, monospace; text-align: right; color: #111; }
.bit-dec[readonly] { background: #fafafa; color: #111; }
.bit-dec:focus { outline: none; border-color: #111; }
.bit-cells { display: flex; gap: 3px; }
.bit {
  width: var(--bw, 28px); height: 32px; display: flex; align-items: center; justify-content: center;
  border: 1px solid #e5e7eb; border-radius: 5px; background: #fff; color: #cfcfcf;
  font: 700 14px "SF Mono", ui-monospace, Consolas, monospace; cursor: pointer; user-select: none;
  transition: background .12s, color .12s, border-color .12s; flex-shrink: 0;
}
.bit-width { display: inline-flex; align-items: center; gap: 5px; margin-left: 14px; font-size: 13px; color: #666; }
.bit-width button { padding: 4px 9px; border: 1px solid #d4d4d4; border-radius: 5px; background: #fff; color: #333; cursor: pointer; font-size: 12px; }
.bit-width button.on { background: #111; color: #fff; border-color: #111; }
.bit.set { background: #111; color: #fff; border-color: #111; }
.bit.nib { margin-left: 11px; }
.bit.col-hi { box-shadow: 0 0 0 2px #f59e0b; }
.bit-row[data-rid="r"] .bit { cursor: default; }
.bit-result { margin-top: 24px; font: 700 15px "SF Mono", ui-monospace, Consolas, monospace; color: #111; }
.bit-hint { margin-left: 18px; font: 600 13px "SF Mono", ui-monospace, Consolas, monospace; color: #f59e0b; }
.bit-section-h { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: #9a9a9a; margin: 34px 0 14px; }
.bit-tricks { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.bit-card { border: 1px solid #e5e7eb; border-radius: 8px; padding: 14px 16px; display: flex; flex-direction: column; cursor: pointer; }
.bit-card:hover { border-color: #cbd5e1; }
.bit-card.sel { border-color: #111; box-shadow: 0 0 0 1px #111; }
.bit-card-more { font-size: 11px; color: #9a9a9a; margin-top: 9px; }
.bit-card.sel .bit-card-more { color: #111; font-weight: 600; }
.bit-card-name { font-size: 14px; font-weight: 700; color: #111; }
.bit-card-expr { font: 600 13px "SF Mono", ui-monospace, Consolas, monospace; color: #6b7280; margin: 5px 0 8px; }
.bit-card-what { font-size: 13px; font-weight: 600; color: #111; margin-bottom: 5px; }
.bit-card-how { font-size: 12.5px; color: #666; line-height: 1.55; }
.bit-card-cp { font-size: 12px; color: #444; line-height: 1.5; margin-top: 9px; padding-top: 9px; border-top: 1px dashed #e5e7eb; }
.bit-card-res { font: 700 16px "SF Mono", ui-monospace, Consolas, monospace; color: #111; margin-top: 10px; }
.bit-expl-cp { margin-top: 12px; font-size: 13px; color: #333; line-height: 1.6; }
.bit-expl-cp code { font-family: "SF Mono", ui-monospace, Consolas, monospace; font-size: 12px; color: #111; background: #eef0f2; padding: 1px 5px; border-radius: 4px; }

.bit-proof:empty { display: none; }
.bit-proof { margin-top: 20px; padding: 18px 20px; background: #fafafa; border-radius: 10px; }
.bit-proof-head { font: 700 15px "SF Mono", ui-monospace, Consolas, monospace; color: #111; margin-bottom: 10px; }
.bit-proof-text { font-size: 14px; color: #333; line-height: 1.65; max-width: 860px; margin-bottom: 18px; }
.bit-proof-steps { display: flex; flex-direction: column; gap: 7px; overflow-x: auto; }
.bit-prow { display: flex; align-items: center; gap: 12px; }
.bit-plabel { width: 120px; text-align: right; font: 600 13px "SF Mono", ui-monospace, Consolas, monospace; color: #111; flex-shrink: 0; }
.bit-pnum { width: 84px; text-align: right; font: 600 12px "SF Mono", ui-monospace, Consolas, monospace; color: #9a9a9a; flex-shrink: 0; }
.bit-prow .bit { cursor: default; }

/* ---- auto-visualizer ---------------------------------------------------- */
.auto-examples { display: flex; gap: 8px; margin-bottom: 18px; flex-wrap: wrap; }
.auto-examples button { padding: 6px 14px; border: 1px solid #d4d4d4; border-radius: 6px; background: #fff; color: #333; cursor: pointer; font-size: 13px; }
.auto-examples button.on { background: #111; color: #fff; border-color: #111; }
.auto-io { display: flex; gap: 18px; align-items: stretch; flex-wrap: wrap; }
.auto-col { flex: 1 1 380px; display: flex; flex-direction: column; }
.auto-col-side { flex: 0 1 320px; }
.auto-lab { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: #9a9a9a; margin-bottom: 6px; }
.auto-code, .auto-input { border: 1px solid #d4d4d4; border-radius: 8px; padding: 12px 14px; font: 500 13px "SF Mono", ui-monospace, Consolas, monospace; color: #111; resize: vertical; line-height: 1.5; }
.auto-code { min-height: 268px; white-space: pre; overflow-x: auto; }
.auto-input { min-height: 132px; }
.auto-code:focus, .auto-input:focus { outline: none; border-color: #111; }
.auto-input::placeholder { color: #b8b8b8; }
.auto-opt { text-transform: none; letter-spacing: 0; color: #b8b8b8; font-weight: 400; }
.auto-viz-btn { margin-top: 12px; padding: 10px 20px; border: none; border-radius: 8px; background: #111; color: #fff; font-size: 14px; cursor: pointer; align-self: flex-start; }
.auto-viz-btn:hover { background: #333; }
.auto-viz-btn:disabled { background: #d4d4d4; color: #fafafa; cursor: not-allowed; }
.auto-lab-gap { margin-top: 20px; padding-top: 18px; border-top: 1px solid #eee; }
.auto-problem { border: 1px solid #d4d4d4; border-radius: 8px; padding: 12px 14px; font: 500 13px "SF Mono", ui-monospace, Consolas, monospace; color: #111; resize: vertical; line-height: 1.5; min-height: 92px; }
.auto-problem:focus { outline: none; border-color: #111; }
.auto-problem::placeholder { color: #b8b8b8; }
.auto-check-btn { background: #fff; color: #111; border: 1px solid #111; }
.auto-check-btn:hover { background: #111; color: #fff; }
.auto-check-btn:disabled { background: #fff; color: #cbcbcb; border: 1px solid #e0e0e0; cursor: not-allowed; }

.auto-review { margin: 10px 0 4px; max-width: 900px; }
.auto-review:not([hidden]) { border: 1px solid #ececec; border-radius: 10px; padding: 18px 20px; background: #fcfcfc; }
.rv-note { font-size: 13.5px; color: #666; }
.rv-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.rv-verdict { font: 700 12px "SF Mono", ui-monospace, Consolas, monospace; text-transform: uppercase; letter-spacing: .06em; padding: 4px 10px; border-radius: 6px; color: #fff; }
.rv-verdict.rv-ok { background: #16a34a; }
.rv-verdict.rv-warn { background: #d97706; }
.rv-verdict.rv-bad { background: #dc2626; }
.rv-meta { font-size: 13px; color: #555; }
.rv-fix { display: flex; align-items: baseline; gap: 10px; margin-bottom: 12px; padding: 10px 14px; background: #f0fdf4; border: 1px solid #bbf7d0; border-radius: 8px; font-size: 14px; color: #14532d; font-weight: 600; }
.rv-fix-lab { font: 700 10.5px "SF Mono", ui-monospace, Consolas, monospace; text-transform: uppercase; letter-spacing: .06em; color: #16a34a; flex: 0 0 auto; }
.rv-summary { font-size: 14px; color: #222; line-height: 1.6; margin-bottom: 14px; }
.rv-issues { display: flex; flex-direction: column; gap: 10px; }
.rv-issue { border: 1px solid #eee; border-left: 3px solid #cbd5e1; border-radius: 8px; padding: 10px 14px; background: #fff; }
.rv-issue.rv-sev-critical { border-left-color: #dc2626; }
.rv-issue.rv-sev-high { border-left-color: #ea580c; }
.rv-issue.rv-sev-medium { border-left-color: #d97706; }
.rv-issue.rv-sev-low { border-left-color: #9ca3af; }
.rv-issue-head { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.rv-sev { font: 700 10.5px "SF Mono", ui-monospace, Consolas, monospace; text-transform: uppercase; letter-spacing: .05em; color: #6b7280; }
.rv-where { font: 600 13px "SF Mono", ui-monospace, Consolas, monospace; color: #111; }
.rv-what { font-size: 14px; color: #111; font-weight: 600; margin-bottom: 3px; }
.rv-why { font-size: 13.5px; color: #555; line-height: 1.55; }
.rv-codewrap { position: relative; margin-left: auto; }
.rv-codechip { display: inline-block; border: 1px solid #d4d4d4; border-radius: 5px; background: #fff; padding: 2px 9px; font: 600 11px "SF Mono", ui-monospace, Consolas, monospace; color: #666; cursor: default; white-space: nowrap; }
.rv-codewrap:hover .rv-codechip { border-color: #111; color: #111; }
.rv-codepop { position: absolute; top: 100%; right: 0; z-index: 40; min-width: 300px; max-width: 620px; padding: 12px 14px; background: #fff; border: 1px solid #e0e0e0; border-radius: 10px; box-shadow: 0 10px 30px rgba(0, 0, 0, .13); opacity: 0; visibility: hidden; transform: translateY(-4px); transition: opacity .15s, transform .15s, visibility .15s; }
.rv-codewrap:hover .rv-codepop { opacity: 1; visibility: visible; transform: translateY(0); }
.rv-codepop pre { margin: 0; overflow-x: auto; }
.rv-codepop code, .rv-codepop code.hljs { padding: 0; background: transparent; font: 500 12.5px "SF Mono", ui-monospace, Consolas, monospace; line-height: 1.55; white-space: pre; display: block; }
.rvd { font: 500 12.5px "SF Mono", ui-monospace, Consolas, monospace; }
.rvd-line { display: flex; gap: 8px; padding: 1px 4px; border-radius: 3px; line-height: 1.6; }
.rvd-gutter { flex: 0 0 auto; width: 10px; text-align: center; color: #cbd5e1; user-select: none; }
.rvd-del { background: #fee9e9; }
.rvd-del .rvd-gutter { color: #dc2626; }
.rvd-add { background: #e7f7ec; }
.rvd-add .rvd-gutter { color: #16a34a; }
.rvd code, .rvd code.hljs { padding: 0; background: transparent; font: inherit; white-space: pre; display: inline; }
.rv-clean { font-size: 14px; color: #16a34a; font-weight: 600; }
.rv-ce { margin-top: 16px; }
.rv-ce-lab { font: 700 11px "SF Mono", ui-monospace, Consolas, monospace; text-transform: uppercase; letter-spacing: .06em; color: #9a9a9a; margin-bottom: 8px; }
.rv-ce-grid { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; align-items: start; }
.rv-ce-grid span { font: 600 12px "SF Mono", ui-monospace, Consolas, monospace; color: #6b7280; padding-top: 7px; }
.rv-ce-grid pre { margin: 0; padding: 7px 12px; background: #f5f5f5; border-radius: 6px; font: 600 13.5px "SF Mono", ui-monospace, Consolas, monospace; color: #111; white-space: pre-wrap; word-break: break-word; }
.rv-ce-grid pre.rv-got { background: #fef2f2; color: #b91c1c; }
.rv-vizbtn { margin-top: 14px; padding: 8px 16px; border: 1px solid #111; border-radius: 8px; background: #fff; color: #111; font: 600 13px "SF Mono", ui-monospace, Consolas, monospace; cursor: pointer; }
.rv-vizbtn:hover { background: #111; color: #fff; }
/* locked: dim + disable the whole AI area (code, input, problem, buttons); the unlock bar stays live */
.ai-locked .auto-io { opacity: .38; filter: grayscale(1); pointer-events: none; user-select: none; transition: opacity .2s, filter .2s; }
.auto-lock { display: flex; align-items: center; gap: 10px; margin: 16px 0 0; flex-wrap: wrap; }
.auto-lock-lab { font: 700 11px "SF Mono", ui-monospace, Consolas, monospace; text-transform: uppercase; letter-spacing: .08em; color: #b45309; }
.auto-lock-lab.auto-lock-ok { color: #16a34a; }
.auto-lock-input { border: 1px solid #d4d4d4; border-radius: 7px; padding: 7px 11px; font: 500 13px "SF Mono", ui-monospace, Consolas, monospace; width: 200px; color: #111; }
.auto-lock-input:focus { outline: none; border-color: #111; }
.auto-lock-btn { padding: 7px 16px; border: 1px solid #111; border-radius: 7px; background: #111; color: #fff; font-size: 13px; cursor: pointer; }
.auto-lock-btn:hover { background: #333; }
.auto-lock-btn.ghost { background: #fff; color: #666; border-color: #d4d4d4; }
.auto-lock-btn.ghost:hover { background: #f5f5f5; color: #111; }
.auto-lock-msg { font-size: 12.5px; color: #b91c1c; }
.auto-poc { margin: 18px 0 4px; font-size: 14px; color: #555; line-height: 1.6; max-width: 840px; }
.auto-stage { margin-top: 20px; }
.auto-title { font: 700 18px "SF Mono", ui-monospace, Consolas, monospace; color: #111; margin-bottom: 14px; }
.auto-viz-area { display: flex; justify-content: center; min-height: 200px; }
.auto-stage .codeline { font-size: 15px; }
.auto-stage .codeline.flagged { border-left-color: #dc2626; background: #fef2f2; color: #991b1b; font-weight: 600; }
.auto-flagnote { color: #b91c1c; font-weight: 600; }
.auto-scrub { width: 100%; margin: 10px 0; }
.auto-draghint { color: #9a9a9a; }
.agsvg [data-n], .attsvg [data-n] { cursor: grab; }
.agsvg [data-n]:active, .attsvg [data-n]:active { cursor: grabbing; }

.agsvg { width: 100%; max-width: 620px; height: auto; overflow: visible; }
.agnode { fill: #fff; stroke: #cbd5e1; stroke-width: 2; transition: fill .18s, stroke .18s; }
.agnode.front { fill: #fde68a; stroke: #f59e0b; }
.agnode.done { fill: #dcfce7; stroke: #4ade80; }
.agnode.cur { fill: #111; stroke: #111; }
.agname { text-anchor: middle; dominant-baseline: middle; font: 700 16px "SF Mono", ui-monospace, Consolas, monospace; fill: #111; }
.agnode.cur + .agname { fill: #fff; }
.agdist { text-anchor: middle; font: 700 14px "SF Mono", ui-monospace, Consolas, monospace; fill: #ea9008; }
.agedge { stroke: #c8c8c8; stroke-width: 2; transition: stroke .18s, stroke-width .18s; }
.agedge.active { stroke: #111; stroke-width: 3; }
.agedge.tree { stroke: #111; stroke-width: 2.5; }
.agweight { text-anchor: middle; font: 700 14px "SF Mono", ui-monospace, Consolas, monospace; fill: #3f3f46; }

.aarr-wrap { display: flex; flex-direction: column; align-items: center; width: 100%; }
.aarr { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.acell { display: flex; flex-direction: column; align-items: center; width: 50px; border: 1px solid #e5e7eb; border-radius: 6px; padding: 7px 0; background: #fff; transition: background .15s, border-color .15s; }
.acell-i { font-size: 12px; color: #94a3b8; }
.acell-v { font: 700 17px "SF Mono", ui-monospace, Consolas, monospace; color: #111; }
.acell.win { background: #eff6ff; border-color: #93c5fd; }
.acell.lptr { border-left: 3px solid #111; }
.acell.rptr { border-right: 3px solid #111; }
.aarr-info { width: 100%; text-align: center; margin-top: 16px; font: 600 15px "SF Mono", ui-monospace, Consolas, monospace; color: #111; }

.atable { display: grid; gap: 4px; }
.atcorner, .atlabel { display: flex; align-items: center; justify-content: center; height: 42px; padding: 0 12px; white-space: nowrap; font: 700 14px "SF Mono", ui-monospace, Consolas, monospace; color: #64748b; }
.atcell { display: flex; align-items: center; justify-content: center; height: 42px; padding: 0 14px; white-space: nowrap; border: 1px solid #e5e7eb; border-radius: 6px; background: #fff; color: #cbd5e1; font: 600 15px "SF Mono", ui-monospace, Consolas, monospace; transition: background .15s, border-color .15s, color .15s; }
.atcell.filled { color: #111; background: #fafafa; }
.atcell.from { border-color: #f59e0b; box-shadow: 0 0 0 1px #f59e0b; background: #fff8eb; color: #111; }
.atcell.cur { border-color: #111; background: #111; color: #fff; }

.attsvg { max-width: 100%; height: auto; }
.attedge { stroke: #d4d4d4; stroke-width: 1.5; }
.attnode rect { fill: #fff; stroke: #d4d4d4; stroke-width: 1.5; }
.attnode.base rect { fill: #dcfce7; stroke: #4ade80; }
.attnode.computed rect { fill: #f3f4f6; stroke: #9ca3af; }
.attnode.active rect { fill: #fff; stroke: #111; stroke-dasharray: 3 2; }
.attnode.cur rect { stroke: #111; stroke-width: 2.5; }
/* the element holding the wrong value at the divergence step — make it obvious */
.acell.wrong { border-color: #dc2626; background: #fef2f2; box-shadow: 0 0 0 2px #fecaca; }
.acell.wrong .acell-v { color: #dc2626; }
.acell.wrong .acell-i { color: #f87171; }
.atcell.wrong { border-color: #dc2626; background: #fee2e2; color: #dc2626; box-shadow: 0 0 0 2px #fecaca; }
.agnode.wrong { fill: #fee2e2; stroke: #dc2626; stroke-width: 3.5; }
.attnode.wrong rect { fill: #fee2e2; stroke: #dc2626; stroke-width: 3; }
.attlabel { text-anchor: middle; font: 700 13px "SF Mono", ui-monospace, Consolas, monospace; fill: #111; }
.attval { text-anchor: middle; font: 700 13px "SF Mono", ui-monospace, Consolas, monospace; fill: #111; }

.auto-spec { margin-top: 22px; }
.auto-spec summary { font-size: 13px; color: #6b7280; cursor: pointer; }
.auto-spec pre { margin-top: 10px; padding: 14px 16px; background: #0f172a; color: #e2e8f0; border-radius: 8px; font: 500 12px "SF Mono", ui-monospace, Consolas, monospace; overflow-x: auto; max-height: 340px; line-height: 1.5; }

.bit-expl { display: flex; gap: 32px; align-items: flex-start; margin-bottom: 20px; padding: 16px 20px; background: #fafafa; border-radius: 10px; flex-wrap: wrap; }
.bit-expl-text { flex: 1 1 340px; }
.bit-expl-name { font: 700 15px "SF Mono", ui-monospace, Consolas, monospace; color: #111; margin-bottom: 6px; }
.bit-expl-rule { font-size: 14px; font-weight: 600; color: #111; margin-bottom: 6px; }
.bit-expl-desc { font-size: 13px; color: #666; line-height: 1.6; }
.bit-expl-vis { flex: 0 0 auto; }
.bit-cases { display: flex; flex-direction: column; gap: 5px; }
.bit-case { font: 600 15px "SF Mono", ui-monospace, Consolas, monospace; color: #555; padding: 4px 12px; border-radius: 6px; background: #fff; border: 1px solid #eee; transition: background .12s, color .12s; }
.bit-case .bit-case-out { color: #111; font-weight: 700; }
.bit-case.tt-hi { background: #111; color: #fff; border-color: #111; }
.bit-case.tt-hi .bit-case-out { color: #fff; }
.bit-shiftrule { font: 700 18px "SF Mono", ui-monospace, Consolas, monospace; color: #111; text-align: center; }
.bit-shifthint { font: 600 13px "SF Mono", ui-monospace, Consolas, monospace; color: #9a9a9a; margin-top: 5px; }
.bit-tip { font-size: 13px; color: #9a9a9a; margin-bottom: 16px; }
.bit-tip code { font-family: "SF Mono", ui-monospace, Consolas, monospace; color: #666; }

.dp-memo { display: flex; align-items: center; justify-content: center; gap: 8px; flex-wrap: wrap; max-width: 600px; }
.dp-memo-h { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: #9a9a9a; }
.dp-memo-cell { border: 1px solid #e5e7eb; border-radius: 5px; padding: 3px 8px; background: #fafafa; font: 600 12px "SF Mono", ui-monospace, Consolas, monospace; color: #111; }
.dp-memo-empty { font-size: 12px; color: #cfcfcf; }

.panel .dp-tech { display: inline-flex; margin-left: 6px; border: 1px solid #d4d4d4; border-radius: 6px; overflow: hidden; }
.panel .dp-tech button { border: none; border-radius: 0; padding: 5px 12px; font-size: 12px; background: #fff; color: #555; cursor: pointer; }
.panel .dp-tech button.on { background: #111; color: #fff; }
