/* ---------- Shared visualizer pieces ---------- */
.stage-canvas {
  background-color: var(--surface-2);
  background-image:
    linear-gradient(var(--bg-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--bg-grid) 1px, transparent 1px);
  background-size: 22px 22px;
  border-top: 1px solid var(--line-soft);
  border-bottom: 1px solid var(--line-soft);
}
.viz { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; padding: 18px; }

.viz-label {
  min-height: 38px; display: block; line-height: 22px; text-align: center;
  padding: 7px 14px; border-radius: 999px; border: 1.5px solid var(--line); background: var(--surface); box-shadow: var(--shadow);
  font-family: var(--font-mono); font-size: 14px; font-weight: 500; max-width: 100%;
}
.viz-label:empty { visibility: hidden; }
.viz-label, .viz-aux { flex-shrink: 0; }
.viz-label span { margin-left: 0.3em; }
.viz-label .ok { color: var(--c-ok); font-weight: 700; }
.viz-label .bad { color: var(--c-bad); font-weight: 700; }
.viz-label .hot { color: var(--c-l); font-weight: 700; }
.viz-label .r { color: var(--c-r); font-weight: 700; }

.viz-aux { display: flex; align-items: center; gap: 10px; min-height: 34px; flex-wrap: wrap; justify-content: center; }
.viz-aux:empty { visibility: hidden; }
.aux-title { font-family: var(--font-mono); font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-3); }
.aux-box { display: flex; gap: 6px; min-height: 34px; min-width: 60px; padding: 4px 8px; border: 1.5px dashed var(--ink-3); border-radius: 9px; align-items: center; flex-wrap: wrap; }
.aux-chip {
  font-family: var(--font-mono); font-size: 13px; font-weight: 700; min-width: 26px; text-align: center;
  padding: 2px 7px; border-radius: 6px; background: var(--c-w-soft); border: 1.5px solid var(--c-w); color: var(--ink);
}
.aux-chip.is-hot { background: var(--c-bad-soft); border-color: var(--c-bad); }
.aux-empty { font-family: var(--font-mono); font-size: 12px; color: var(--ink-3); }
.aux-result { font-family: var(--font-mono); font-size: 13px; padding: 4px 10px; border-radius: 8px; background: var(--accent-soft); border: 1.5px solid var(--line); color: var(--accent-ink); font-weight: 700; }

/* Pointer tags (shared by array + list) */
.ptr { position: absolute; left: 0; top: 0; display: flex; flex-direction: column; align-items: center; pointer-events: none; will-change: transform; }
.ptr-caret { width: 0; height: 0; border-left: 6px solid transparent; border-right: 6px solid transparent; border-bottom: 8px solid var(--pc); }
.ptr-name {
  font-family: var(--font-mono); font-size: 12px; font-weight: 700; line-height: 1; white-space: nowrap;
  padding: 4px 7px; border-radius: 6px; background: var(--pc); color: #fff; border: 1.5px solid var(--line);
}
.ptr.is-up { flex-direction: column-reverse; }
.ptr.no-caret .ptr-caret { display: none; }
.ptr.is-up .ptr-caret { border-bottom: 0; border-top: 8px solid var(--pc); }
.ptr[data-color="l"] { --pc: var(--c-l); }
.ptr[data-color="r"] { --pc: var(--c-r); }
.ptr[data-color="f"] { --pc: var(--c-f); }
.ptr[data-color="w"] { --pc: var(--c-w); }
.ptr[data-color="ink"] { --pc: var(--ink-2); }

/* ---------- Array ---------- */
.arr-block { display: flex; align-items: flex-start; gap: 12px; flex: none; max-width: 100%; }
.arr-title { font-family: var(--font-mono); font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); padding-top: 32px; white-space: nowrap; }
.arr-row { position: relative; flex: none; margin-top: 14px; }
.arr-cell.is-w { background: var(--c-w-soft); border-color: var(--c-w); }
.arr-cell {
  position: absolute; top: 0; display: grid; place-items: center;
  border: 1.5px solid var(--line); border-radius: 9px; background: var(--surface); box-shadow: var(--shadow);
  font-family: var(--font-mono); font-weight: 700; transition: background .25s, opacity .25s, border-color .25s, color .25s;
}
.arr-idx { position: absolute; text-align: center; font-family: var(--font-mono); font-size: 11px; color: var(--ink-3); }
.arr-cell.is-dim { opacity: var(--c-dim); }
.arr-cell.is-hot { background: var(--c-hot-soft); border-color: var(--c-hot); }
.arr-cell.is-ok { background: var(--c-ok-soft); border-color: var(--c-ok); color: var(--accent-ink); }
.arr-cell.is-bad { background: var(--c-bad-soft); border-color: var(--c-bad); }
.arr-cell.is-l { background: var(--c-l-soft); }
.arr-cell.is-r { background: var(--c-r-soft); }
.arr-band {
  position: absolute; border-radius: 13px; background: var(--c-w-soft); border: 2px solid var(--c-w);
  pointer-events: none; opacity: 0;
}
.arr-band-label { position: absolute; top: -21px; left: 6px; font-family: var(--font-mono); font-size: 11px; font-weight: 700; color: var(--c-w); white-space: nowrap; }
.arr-band.is-bad { border-color: var(--c-bad); background: var(--c-bad-soft); }
.arr-band.is-bad .arr-band-label { color: var(--c-bad); }

/* ---------- Linked list ---------- */
.ll-fit { position: relative; flex: none; }
.ll-wrap { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.ll-edges { position: absolute; left: 0; top: 0; overflow: visible; }
.ll-edge { fill: none; stroke: var(--ink-2); stroke-width: 2; }
.ll-head { fill: var(--ink-2); }
.ll-edge.is-back { stroke: var(--c-f); stroke-dasharray: 5 4; }
.ll-head.is-back { fill: var(--c-f); }
.ll-node {
  position: absolute; display: grid; place-items: center; border-radius: 50%;
  border: 2px solid var(--line); background: var(--surface); box-shadow: var(--shadow);
  font-family: var(--font-mono); font-weight: 700; font-size: 16px; transition: background .25s, border-color .25s, opacity .25s;
}
.ll-node.is-dim { opacity: var(--c-dim); }
.ll-node.is-hot { background: var(--c-hot-soft); border-color: var(--c-hot); }
.ll-node.is-ok { background: var(--c-ok-soft); border-color: var(--c-ok); }
.ll-node.is-bad { background: var(--c-bad-soft); border-color: var(--c-bad); }
.ll-node.is-seen { background: var(--c-r-soft); }
.ll-null {
  position: absolute; display: grid; place-items: center; font-family: var(--font-mono); font-size: 12px; font-weight: 700;
  color: var(--ink-3); border: 1.5px dashed var(--ink-3); border-radius: 8px; background: var(--surface-2);
}
.ll-null.is-hot { color: var(--c-bad); border-color: var(--c-bad); background: var(--c-bad-soft); }
.ll-tag { position: absolute; font-family: var(--font-mono); font-size: 10.5px; font-weight: 700; color: var(--ink-3); text-transform: uppercase; letter-spacing: .08em; white-space: nowrap; transform: translateX(-50%); }

/* ---------- Shared state colours for new visualizers ---------- */
.heap-node.is-hot, .heap-cell.is-hot, .stk-item.is-hot, .hm-entry.is-hot, .nl-bar.is-hot { background: var(--c-hot-soft); border-color: var(--c-hot); }
.heap-node.is-ok, .heap-cell.is-ok, .stk-item.is-ok, .hm-entry.is-ok, .nl-bar.is-ok { background: var(--c-ok-soft); border-color: var(--c-ok); }
.heap-node.is-bad, .heap-cell.is-bad, .stk-item.is-bad, .hm-entry.is-bad, .nl-bar.is-bad { background: var(--c-bad-soft); border-color: var(--c-bad); }
.heap-node.is-w, .heap-cell.is-w, .stk-item.is-w, .hm-entry.is-w, .nl-bar.is-w { background: var(--c-w-soft); border-color: var(--c-w); }
.heap-node.is-l, .heap-cell.is-l, .stk-item.is-l, .hm-entry.is-l, .nl-bar.is-l { background: var(--c-l-soft); border-color: var(--c-l); }
.heap-node.is-r, .heap-cell.is-r, .stk-item.is-r, .hm-entry.is-r, .nl-bar.is-r { background: var(--c-r-soft); border-color: var(--c-r); }
.heap-node.is-dim, .heap-cell.is-dim, .stk-item.is-dim, .hm-entry.is-dim, .nl-bar.is-dim { opacity: var(--c-dim); }

/* ---------- Heap ---------- */
.heap-box { display: flex; flex-direction: column; align-items: center; gap: 8px; flex: none; }
.heap-head { display: flex; gap: 10px; align-items: baseline; font-family: var(--font-mono); font-size: 11px; }
.heap-title { font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); }
.heap-top { color: var(--accent); font-weight: 700; }
.heap-tree { position: relative; flex: none; }
.heap-edges { position: absolute; inset: 0; overflow: visible; }
.heap-edge { stroke: var(--ink-3); stroke-width: 1.6; }
.heap-empty { position: absolute; inset: 0; display: grid; place-items: center; font-family: var(--font-mono); font-size: 12px; color: var(--ink-3); }
.heap-node {
  position: absolute; left: 0; top: 0; display: grid; place-items: center; border-radius: 50%;
  border: 2px solid var(--line); background: var(--surface); box-shadow: var(--shadow);
  font-family: var(--font-mono); font-weight: 700; transition: background .25s, border-color .25s, opacity .25s;
}
.heap-arr { position: relative; height: 30px; flex: none; }
.heap-cell {
  position: absolute; left: 0; top: 0; width: 30px; height: 28px; display: grid; place-items: center;
  border: 1.5px solid var(--line-soft); border-radius: 6px; background: var(--surface-2);
  font-family: var(--font-mono); font-size: 12px; font-weight: 700; transition: background .25s, border-color .25s;
}

/* ---------- Stack ---------- */
.stk-wrap { display: flex; flex-direction: column; align-items: center; gap: 6px; flex: none; }
.stk-title { font-family: var(--font-mono); font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); }
.stk-col {
  position: relative; width: 96px; border: 2px solid var(--line); border-top: 0; border-radius: 0 0 12px 12px;
  background: var(--surface); box-shadow: var(--shadow);
}
.stk-item {
  position: absolute; left: 6px; right: 6px; top: 0; text-align: center; border-radius: 7px;
  border: 1.5px solid var(--line); background: var(--surface-3); font-family: var(--font-mono); font-weight: 700; font-size: 14px;
  transition: background .25s, border-color .25s;
}
.stk-empty { position: absolute; inset: 0; display: grid; place-items: center; font-family: var(--font-mono); font-size: 12px; color: var(--ink-3); }
.stk-top { position: absolute; left: 100%; top: 0; margin-left: 8px; font-family: var(--font-mono); font-size: 11px; font-weight: 700; color: var(--accent); white-space: nowrap; }
.stk-top::before { content: "← "; }

/* ---------- Hash map ---------- */
.hm-box { display: flex; flex-direction: column; gap: 8px; align-items: center; max-width: 100%; flex: none; }
.hm-head { display: flex; gap: 10px; align-items: baseline; font-family: var(--font-mono); font-size: 11px; }
.hm-title { font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); }
.hm-cols { color: var(--ink-3); }
.hm-entries {
  display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; min-height: 40px; min-width: 120px; max-width: min(640px, 100%);
  padding: 8px; border: 1.5px dashed var(--ink-3); border-radius: 10px;
}
.hm-empty { align-self: center; font-family: var(--font-mono); font-size: 12px; color: var(--ink-3); }
.hm-entry {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 4px 3px 8px; border-radius: 8px;
  border: 1.5px solid var(--line); background: var(--surface); font-family: var(--font-mono); font-size: 13px; font-weight: 700;
  transition: background .25s, border-color .25s, opacity .25s;
}
.hm-arrow { color: var(--ink-3); font-weight: 400; }
.hm-v { display: inline-block; min-width: 22px; text-align: center; padding: 0 5px; border-radius: 5px; background: var(--surface-3); }

/* ---------- Number line ---------- */
.nl-box { position: relative; flex: none; }
.nl-row { position: absolute; left: 0; border-bottom: 1px dashed var(--line-soft); }
.nl-row-label { position: absolute; left: 0; top: 50%; transform: translateY(-50%); font-family: var(--font-mono); font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-3); }
.nl-axis { position: absolute; left: 0; right: 0; height: 26px; }
.nl-axis-line { position: absolute; top: 4px; height: 2px; background: var(--ink-3); }
.nl-tick { position: absolute; top: 8px; transform: translateX(-50%); font-family: var(--font-mono); font-size: 10.5px; color: var(--ink-3); }
.nl-tick::before { content: ""; position: absolute; left: 50%; top: -6px; width: 1px; height: 6px; background: var(--ink-3); }
.nl-bar {
  position: absolute; left: 0; top: 0; height: 28px; display: grid; place-items: center; overflow: hidden; white-space: nowrap;
  border: 1.5px solid var(--line); border-radius: 8px; background: var(--c-r-soft); box-shadow: var(--shadow);
  font-family: var(--font-mono); font-size: 11.5px; font-weight: 700; transition: background .25s, border-color .25s, opacity .25s;
}
.nl-marker { position: absolute; left: 0; top: 0; width: 0; border-left: 2px dashed var(--c-l); pointer-events: none; } /* painted under bars */
.nl-marker span { position: absolute; top: -18px; left: 0; transform: translateX(-50%); font-family: var(--font-mono); font-size: 10.5px; font-weight: 700; color: var(--c-l); white-space: nowrap; }

/* ---------- Multi-panel ---------- */
.viz-multi { gap: 10px; }
.multi-panels { position: relative; flex: 1; width: 100%; min-height: 0; display: flex; flex-direction: column; gap: 6px; }
.multi-panels[data-dir="row"] { flex-direction: row; }
@media (max-width: 640px) { .multi-panels[data-dir="row"] { flex-direction: column; } }
.multi-panel { position: relative; min-height: 96px; min-width: 0; }
.multi-panel + .multi-panel { border-top: 1px dashed var(--line-soft); }
.multi-panels[data-dir="row"] .multi-panel + .multi-panel { border-top: 0; border-left: 1px dashed var(--line-soft); }
.multi-panel .viz { padding: 6px 8px; gap: 6px; }
.multi-panel .viz-label:empty, .multi-panel .viz-aux:empty { display: none; }
.multi-panel .arr-row { margin-top: 18px; }
.multi-panel .arr-title { padding-top: 34px; }
/* Phones: array titles sit above the row so cells keep their width; multi scenes get a taller canvas. */
@media (max-width: 640px) {
  .arr-block { flex-direction: column; align-items: center; gap: 0; }
  .arr-title, .multi-panel .arr-title { padding-top: 0; }
}
@media (max-width: 900px) {
  .stage .stage-canvas:has(.viz-multi), .stage .stage-canvas:has(.viz-buckets) { min-height: 600px; }
}

/* Linked list: newly created links draw themselves in */
.ll-edge.is-new { stroke-dasharray: 100; stroke-dashoffset: 100; animation: ll-draw .55s ease-out forwards; }
.ll-head.is-new { opacity: 0; animation: ll-fade .2s .4s ease-out forwards; }
@keyframes ll-draw { to { stroke-dashoffset: 0; } }
@keyframes ll-fade { to { opacity: 1; } }

/* ---------- Hash-table buckets (separate chaining) ---------- */
.bk-box { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; flex: none; max-width: 100%; }
.bk-title { font-family: var(--font-mono); font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); }
.bk-rows { display: flex; flex-direction: column; gap: 5px; }
.bk-row { display: flex; align-items: center; gap: 8px; padding: 3px 6px 3px 3px; border-radius: 9px; border: 1.5px solid transparent; transition: background .25s, border-color .25s; }
.bk-row.is-hot { background: var(--c-hot-soft); border-color: var(--c-hot); }
.bk-idx { width: 30px; height: 30px; display: grid; place-items: center; flex: none; border: 1.5px solid var(--line); border-radius: 7px; background: var(--surface-3); font-family: var(--font-mono); font-size: 12px; font-weight: 700; }
.bk-chain { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.bk-chain > * + * { position: relative; margin-left: 16px; }
.bk-chain > * + *::before { content: "→"; position: absolute; left: -15px; top: 50%; transform: translateY(-50%); color: var(--ink-3); font-family: var(--font-mono); font-weight: 400; }
.bk-null { font-family: var(--font-mono); font-size: 12px; color: var(--ink-3); display: inline-flex; align-items: center; }
.bk-entry { display: inline-flex; align-items: center; gap: 0; border: 1.5px solid var(--line); border-radius: 7px; background: var(--surface); font-family: var(--font-mono); font-size: 12.5px; font-weight: 700; transition: background .25s, border-color .25s; }
.bk-k { padding: 2px 7px; }
.bk-v { padding: 2px 7px; border-radius: 0 5px 5px 0; background: var(--surface-3); border-left: 1.5px solid var(--line-soft); }
.bk-entry.is-hot { background: var(--c-hot-soft); border-color: var(--c-hot); }
.bk-entry.is-ok { background: var(--c-ok-soft); border-color: var(--c-ok); }
.bk-entry.is-bad { background: var(--c-bad-soft); border-color: var(--c-bad); }
.bk-entry.is-dim { opacity: var(--c-dim); }
.bk-entry.is-w { background: var(--c-w-soft); border-color: var(--c-w); }
.bk-entry.is-l { background: var(--c-l-soft); border-color: var(--c-l); }
.bk-entry.is-r { background: var(--c-r-soft); border-color: var(--c-r); }
