:root {
  color-scheme: dark;
  --night: #101018;
  --surface: #1a1926;
  --edge: #353343;
  --soft: #b1adbf;
  --type: #f3f2f9;
  --iris: #baabff;
  --mint: #96f4d6;
  --mono: "Cascadia Code", Consolas, monospace;
  font:
    16px/1.5 "Inter",
    "Segoe UI",
    sans-serif;
  background: var(--night);
  color: var(--type);
}
.brand[href] { color:inherit; text-decoration:none; }
.algorithmIntro p { white-space: pre-line; }
.graphView :is(#scroll,#overviewBox,.sizeControl,.field .tools,.gestureHint) { display:none !important; }
.graphView .sceneInputs:empty { display:none; }
#graphScene { display:flex; flex-direction:column; min-height:0; flex:1; gap:6px; }
#graphTools { flex-wrap:wrap; margin:0; }
#graphTools button { min-height:36px; }
#graphCanvas {
  display:flex; flex-direction:column; width:100%; min-height:0; flex:1 1 auto; height:clamp(210px,28vw,355px);
}
.inspectEdgeHit { fill:transparent; pointer-events:all; cursor:pointer; }
#graphMap :is(.inspectEdgeHit,.bfsEdgeHit,.graphWeight):focus { outline:none; }
.inspectedLine { stroke:var(--iris); stroke-opacity:.38; stroke-width:8; pointer-events:none; }
.inspectionCorners { display:none; fill:none; stroke:#c3f2ff; stroke-width:2; stroke-linecap:round; pointer-events:none; }
.bfsNode[data-probe]:focus { outline:none; }
.bfsNode:is([aria-pressed="true"],:focus-visible) .inspectionCorners { display:inline; }
.bfsNode[aria-pressed="true"] .nodeDisk { filter:drop-shadow(0 0 5px #87d9ff); }
.bfsNode[aria-pressed="false"]:focus-visible .inspectionCorners { stroke-dasharray:2 3; }
.graphEdge:has(.inspectEdgeHit:focus-visible) :is(.bfsEdge,.graphArrow,.bfsDirection) { filter:brightness(1.8); }
#graphMap .graphWeight[data-probe] { cursor:pointer; }
.graphWeight[data-probe]:is(:hover,:focus-visible,[aria-pressed="true"]) rect { fill:#352d46; stroke:var(--iris); }
#overflowWeights [aria-pressed="true"] { outline:1px solid var(--iris); outline-offset:-1px; }
#graphInspection:not([hidden]) {
  display:flex; align-items:flex-start; gap:10px; justify-content:space-between;
  flex:0 1 auto; min-height:0; max-height:32%; overflow:auto; overscroll-behavior:contain;
  padding:8px 10px 8px 13px; border-inline-start:3px solid var(--iris);
  border-radius:6px; background:#302a3e; color:var(--type); font-size:.89rem; line-height:1.4;
}
#graphInspection strong { color:#dacfff; }
.inspectionNumber { color:var(--mint); font-weight:700; font-variant-numeric:tabular-nums; }
#graphInspection p { margin:3px 0 0; white-space:pre-line; }
@media (max-width:600px) {
  #graphInspection:not([hidden]) { max-height:52%; }
}
#closeInspection { flex:none; display:grid; place-items:center; width:32px; height:32px; padding:0; }
#graphMap {
  width:100%; min-height:0; flex:1 1 0; 
  border-radius:12px; touch-action:none;
  background:radial-gradient(ellipse at center,#30284044,transparent 75%),radial-gradient(circle,#81709e3b 1px,transparent 1px);
  background-size:auto,16px 16px;
}
.bfsEdge, .graphArrow, .bfsDirection { stroke:var(--edge-stroke,#756b8b); }
.bfsEdge { stroke-width:2; }
.bfsEdgeHit { stroke:transparent; stroke-width:26px; vector-effect:non-scaling-stroke; pointer-events:stroke; cursor:pointer; }
.graphEdge:has(> .bfsEdgeHit:is(:hover,:focus-visible)) { --edge-stroke:#ffa2ad; }
.graphEdge:has(> .bfsEdgeHit:is(:hover,:focus-visible)) .bfsEdge { stroke-width:4; }
.bfsEdgePreview { stroke:#ffce9d; stroke-width:3; stroke-dasharray:6 4; pointer-events:none; }
#graphMap:is([data-tool="start"],[data-tool="add"]) .bfsNode { cursor:grab; }
#graphMap[data-tool="link"] { cursor:crosshair; }
#graphMap[data-tool="link"] .bfsNode { cursor:crosshair; }
.graphEdge.active { --edge-stroke:#ffce9d; }
.graphEdge.active .bfsEdge { stroke-width:4; stroke-dasharray:7 4; }
.graphEdge.resultEdge { --edge-stroke:var(--mint); }
.graphEdge.resultEdge .bfsEdge { stroke-width:4; }
.graphEdge.conflict { --edge-stroke:#ff839b; }
.goalRing { fill:none; stroke:#ffce9d; stroke-width:2; stroke-dasharray:4 3; }
.graphArrow { fill:none; stroke-width:2.5; pointer-events:none; }
.graphWeight rect { fill:transparent; stroke:none; }
.graphWeight text { fill:#dbd1e8; stroke:none; font:500 13px var(--mono); font-variant-numeric:tabular-nums; }
.graphWeight:is(:focus-visible,[data-weight]:hover) rect { fill:#342d46; stroke:var(--iris); }
.graphWeight[data-weight] { cursor:pointer; }
#overflowWeights:not([hidden]) { display:flex; align-items:center; gap:6px; flex:none; overflow-x:auto; padding:3px 2px; scrollbar-width:thin; }
#overflowWeights > * { flex:none; display:inline-flex; align-items:center; gap:6px; padding:3px 6px; color:var(--soft); font:12px var(--mono); }
#overflowWeights svg { width:auto; height:20px; }
.legendSample svg:has(.graphWeight) { width:auto; max-width:100%; }
#graphWeightEditor { display:flex; align-items:center; gap:8px; color:var(--soft); }
#graphWeightEditor input { width:70px; background:var(--surface); }
.matrixScroll { max-height:clamp(76px,18vh,190px); overflow:auto; }
.graphMatrix { border-collapse:collapse; font:12px var(--mono); }
.graphMatrix td { padding:2px 6px; text-align:center; border:1px solid var(--edge); }
.graphMatrix .matrixAxis { color:var(--iris); }
.graphMatrix .matrixFocus { background:var(--mint); color:#193029; }
.bfsDirection { fill:none; stroke-width:3; stroke-linecap:round; stroke-linejoin:round; }
.bfsNode { cursor:pointer; }
.nodeDisk { fill:#292438; stroke:#998aad; stroke-width:2; }
.bfsNode text { fill:#f4eefc; font:600 15px var(--mono); }
.startRing { fill:none; stroke:#bba7ff; stroke-width:2; }
.bfsNode.seen .nodeDisk { fill:#645683; stroke:#cbbaed; }
#legendToggle, #legendClose {
  display: inline-grid; place-items: center; flex: none;
  width: 36px; height: 36px; padding: 0; border: 0; border-radius: 50%;
  color: var(--iris); background: transparent;
}
#legendToggle:hover, #legendClose:hover { color: var(--type); background: #373045; }
#legendToggle svg { width: 20px; height: 20px; }
#sceneLegend {
  width: min(430px, calc(100% - 24px)); max-height: calc(100dvh - 32px);
  box-sizing: border-box; margin: auto; padding: 0; overflow: auto; overscroll-behavior: contain;
  color: var(--type); background: var(--surface); border: 1px solid #675a81;
  border-radius: 16px; box-shadow: 0 16px 60px #09081099;
}
#sceneLegend::backdrop { background: #090810aa; }
#sceneLegend header {
  position: sticky; top: 0; z-index: 1; padding: 10px 14px 10px 20px;
  display: flex; align-items: center; justify-content: space-between;
  background: #201e2c; border-bottom: 1px solid var(--edge);
}
#legendItems { list-style: none; margin: 0; padding: 4px 18px 10px; }
#legendItems li {
  display: grid; grid-template-columns: 48px 1fr; align-items: center;
  gap: 12px; padding: 8px 0; font-size: .92rem; line-height: 1.4;
}
#legendItems li + li { border-top: 1px solid var(--edge); }
.legendSample { display: grid; place-items: center; color: var(--soft); font: 600 .82rem var(--mono); }
.legendSample svg { display: block; width: 44px; pointer-events: none; }
.legendSample .visitMark { width: 14px; }
.legendSample [data-symbol] { text-align: center; }
.legendSample :is([data-symbol="edge"],[data-symbol="swap"]) { font: 28px/1 var(--mono); }
.legendSample [data-symbol="swap"] { color: #ffce9d; }
.legendSample :is([data-symbol="weight"],[data-symbol="cost"],[data-symbol="flow"],[data-symbol="cell"],[data-symbol="held"],[data-symbol="faded"],[data-symbol="picked"]) {
  min-width: 25px; padding: 2px 4px; border: 1px solid #766989; border-radius: 5px; background: #30293e; color: var(--type);
}
.legendSample [data-symbol="picked"] { color: #143a32; background: var(--mint); }
.legendSample [data-symbol="held"] { color: #352315; background: #ffcc9c; }
.legendSample [data-symbol="faded"] { opacity: .44; }
.legendSample :is([data-symbol="bar"],[data-symbol="activeBar"],[data-symbol="wrong"])::before {
  content: "4"; display: block; margin-bottom: 2px; padding: 3px 4px; color: #191523;
  border-radius: 2px 2px 0 0; background: #aa96f5; border-right: 3px solid #5846a6;
}
.legendSample [data-symbol="activeBar"]::before { background: var(--mint); border-color: #368f83; }
.legendSample [data-symbol="wrong"]::before { background: #ce7789; border-color: #984e62; }
@media (pointer: coarse) {
  #legendToggle, #legendClose { width: 44px; height: 44px; }
}
.visitHatch {fill:none;stroke:#d0c1e6;stroke-width:6.5;pointer-events:none}
.bfsNode.current .visitHatch {stroke:#427565}
.visitMark {pointer-events:none;flex:none}
.visitMark circle {fill:#d4c6ef;stroke:var(--night)}
.visitMark path {fill:none;stroke:#30213e;stroke-width:2;stroke-linecap:round;stroke-linejoin:round}
.visitKey {display:inline-flex;align-items:center;gap:4px;margin-inline-start:auto;white-space:nowrap;color:var(--soft);font-family:var(--mono)}
.bfsNode.taken .nodeDisk { fill:#355049; stroke:#87b3a5; }
.bfsNode.current .nodeDisk { fill:#abf5d8; stroke:#dbfff0; }
.bfsNode.current text { fill:#18332c; }
.bfsNode text.bfsRole { font:600 12px var(--mono); fill:#f4eefc; stroke:#211d2d; stroke-width:3; paint-order:stroke; }
.bfsNode:is(.neighbor,.endpoint,:not([data-probe]):focus-visible) .nodeDisk { stroke:#ffce9d; stroke-width:4; }
#graphHelp { font-size:.84rem; color:var(--soft); margin:4px 0; }
#graphStats { flex:none; display:grid; gap:4px; }
[data-mode="run"] #graphStats {max-height:45%;overflow:auto;scrollbar-width:thin}
.bfsNode.current .nodeDisk[style] ~ text:not(.bfsRole) {fill:white}
.bfsNode.current .nodeDisk[style] ~ .visitHatch {stroke:#d0c1e6}
.graphRow { display:flex; gap:6px; align-items:center; font: .79rem var(--mono); }
.graphRow > button { min-width:74px; text-align:left; border:0; background:none; color:var(--soft); padding:4px; }
.graphChips { min-width:0; display:flex; gap:4px; align-items:center; overflow:auto; scrollbar-width:thin; color:var(--soft); }
.graphChips button { padding:3px 6px; background:#352e45; color:#d4c4ee; }
[data-list="queue"] button:first-child { background:var(--mint); color:#14332a; }
.bfsLayer { margin-left:auto; flex:none; color:var(--mint); }
@media (max-width:920px) {
  .graphView .sceneInputs { justify-content:flex-end; }
  #graphTools button { padding:5px 8px; }
  #graphCanvas { height:100px; }
  #graphStats { gap:1px; }
}
.algorithmIntro p:empty { display: none; }
#algorithm { min-width: 0; text-overflow: ellipsis; }
.rowPicker { display: flex; align-items: center; gap: 3px; padding: 3px; margin: 0 0 6px; align-self: flex-start; width: fit-content; border: 1px solid var(--edge); border-radius: 10px; }
.rowPicker button { padding: 5px 12px; border: 0; background: transparent; color: var(--soft); }
.rowPicker button[aria-pressed="true"] { color: #181521; background: var(--iris); }
.bandCaption { font: 600 12px var(--mono); fill: var(--mint); }
#bars .gapBar :is(.front,.side,.lid,.num,.barVariable) { opacity: .12; }
#bars .gapBar .front { stroke: var(--mint); stroke-dasharray: 4 3; }
.mergeView :is(#scroll,#overviewBox,#sceneVars) { display: none !important; }
#arrayLanes { min-height: 0; overflow: auto; scrollbar-width: thin; }
.mergeLanes { display: flex; flex: 1; flex-direction: column; justify-content: safe center; gap: clamp(4px,2vh,20px); }
.arrayLane { display: flex; align-items: center; gap: 8px; padding: 5px 4px; border-top: 1px solid var(--edge); }
.mergeLanes .arrayLane { align-items: flex-start; flex-direction: column; }
.laneName { padding: 2px 6px; border: 0; background: transparent; color: var(--soft); font-size: .77rem; white-space: nowrap; }
.laneTrack { display: flex; align-items: flex-start; gap: 4px; min-width: 0; max-width: 100%; overflow-x: auto; scrollbar-width: thin; }
.laneCell { display: inline-flex; align-items: center; flex-direction: column; gap: 1px; }
.laneNumber, .transferNumber { min-width: 34px; padding: 4px 7px; border: 1px solid #695a95; border-radius: 6px; background: #3a3152; color: #ece6ff; text-align: center; font: 600 .87rem var(--mono); }
.mergeLanes .laneNumber { min-width: clamp(32px,4vw,58px); padding-block: clamp(4px,1.2vh,14px); }
.taken .laneNumber { opacity: .44; }
.current .laneNumber, .newCell .laneNumber, .transferNumber { background: var(--mint); color: #143a32; border-color: var(--mint); }
[data-row="saved"] .laneNumber { background: #ffcc9c; border-color: #ffcc9c; color: #352315; }
.lanePointer { background: transparent; color: var(--mint); border: 0; padding: 1px; font: .71rem var(--mono); }
.emptyLane { padding: 1px 7px; font: 1rem var(--mono); color: var(--soft); }
.transferNumber { position: fixed; z-index: 20; pointer-events: none; }
@media (max-width: 920px) {
  .mergeLanes { gap: 2px; }
  .mergeLanes .arrayLane { flex-direction: row; align-items: center; padding-block: 3px; }
  .mergeLanes .laneName { width: 65px; white-space: normal; flex: none; }
  .extraLanes { flex-shrink: 0; max-height: 35%; }
  .extraLanes .arrayLane { padding-block: 1px; }
  .extraLanes .laneNumber { padding-block: 2px; }
}
* {
  box-sizing: border-box;
}
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(ellipse at 82% 45%, #211c331c, transparent 65%),
    var(--night);
}
[hidden] {
  display: none !important;
}
body[data-mode="setup"] [data-for="run"],
body[data-mode="run"] [data-for="setup"],
body[data-mode="setup"] .hintSlot,
body[data-mode="run"] .grip {
  display: none !important;
}
body[data-mode="setup"] .instruction .codeVar:disabled {
  opacity: 1;
  cursor: text;
}
body[data-mode="run"] #chart,
body[data-mode="run"] #bars g,
body[data-mode="run"] .capHit,
body[data-mode="run"] .bodyHit {
  touch-action: pan-x pan-y;
  cursor: auto;
}
#editArray {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: none;
  min-height: 44px;
  padding: 0 12px;
  font: 600 0.84rem "Segoe UI", sans-serif;
}
.panel.pinned {
  position: sticky;
  top: var(--pin-gap);
}
.program.pinned {
  top: calc(var(--pin-gap) + var(--code-offset));
}
.stage.pinned {
  z-index: 1;
}
button,
input,
select {
  font: inherit;
  color: inherit;
}
button,
select {
  cursor: pointer;
}
button {
  border: 1px solid var(--edge);
  border-radius: 9px;
  background: #282635;
  font-weight: 600;
  line-height: 1.2;
}
button:disabled {
  opacity: 0.38;
  cursor: default;
}
button:hover:not(:disabled),
select:hover {
  border-color: #827692;
  background: #322e42;
}
:focus-visible {
  outline: 2px solid var(--mint);
  outline-offset: 3px;
}
::selection {
  background: #bcabff;
  color: #211834;
}
button svg,
[data-icon] svg {
  display: block;
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.65;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.wrap {
  width: min(1436px, 94%);
  margin: auto;
}
.mast {
  border-bottom: 1px solid #2e2a39;
}
.nav,
.brand,
#languages,
.panelhead,
.tools,
.controls,
.timeline,
.gestureHint,
.annotationHead,
.bindings {
  display: flex;
  align-items: center;
}
.nav {
  min-height: 66px;
  gap: 20px;
}
#algorithm, #target {
  min-width: 0;
  border: 1px solid var(--edge);
  border-radius: 8px;
  padding: 6px 8px;
  background: var(--surface);
  color: var(--type);
}
#algorithm { max-width: 100%; }
#targetControl, #searchStatus {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 4px 8px;
  font-size: .85rem;
}
#target { width: 6.5em; }
#sortNotice { margin: 0 8px 5px; font-size: .8rem; color: var(--soft); }
#sortNotice.orderWarning, #bars .outOfOrder .num { color: #ffb5bc; fill: #ffb5bc; }
#bars .outOfOrder .front { fill: #ce7789; }
#bars .outOfOrder .lid { fill: #ffc0c7; }
#bars .outOfOrder .side { fill: #984e62; }
#inspectTarget { padding: 4px 9px; color: var(--mint); }
#searchMessage { font-weight: 600; }
.searchBand { fill: #93f4cf0b; }
.searchBracket { fill: none; stroke: var(--mint); stroke-width: 2; }
#bars .excludedBar { opacity: .32; }
#bars .foundBar .front { fill: #b0ef77; }
@media (max-width: 480px) {
  #algorithm { flex: 1; width: 0; font-size: .78rem; }
}
.brand {
  font:
    700 1.35rem/1 "Bahnschrift",
    "Segoe UI",
    sans-serif;
  letter-spacing: -0.035em;
  gap: 9px;
}
.brand svg {
  width: 34px;
  height: 34px;
}
.lab {
  border-left: 1px solid #4b4657;
  padding-left: 20px;
  color: #bbb6c8;
  font-size: 0.87rem;
}
#languages {
  margin-left: auto;
  padding: 3px;
  border: 1px solid var(--edge);
  border-radius: 8px;
  gap: 2px;
}
#languages button {
  border: 0;
  background: none;
  padding: 7px 11px;
  border-radius: 5px;
  font-size: 0.75rem;
  color: var(--soft);
}
#languages [aria-pressed="true"] {
  background: #393446;
  color: #f3edff;
}
main {
  padding: clamp(26px, 4vw, 58px) 0 40px;
}
h1,
h2,
p {
  margin: 0;
}
h1 {
  font:
    650 clamp(2.25rem, 4.35vw, 4.32rem)/1.06 "Bahnschrift",
    "Inter",
    "Segoe UI",
    sans-serif;
  letter-spacing: -0.04em;
}
.algorithmIntro {
  max-width: 74ch;
  color: #bcb8c8;
  margin: 10px 0 clamp(23px, 2.5vw, 38px);
  font-size: clamp(0.92rem, 1.1vw, 1.07rem);
}
.algorithmIntro p + p { margin-top: 0.55em; }
.workspace {
  display: grid;
  --split-size: 18px;
  --stage-size: calc((100% - var(--split-size)) * var(--stage-share, 0.512));
  grid-template-columns: minmax(0, var(--stage-size)) var(--split-size) minmax(0, 1fr);
  align-items: start;
}
#splitter {
  display: grid;
  place-items: center;
  align-self: stretch;
  position: relative;
  z-index: 2;
  cursor: col-resize;
  touch-action: none;
  user-select: none;
}
#splitter::before {
  content: "";
  position: absolute;
  inset: 0 -4px;
}
#splitter::after {
  content: "";
  width: 4px;
  height: 44px;
  border-radius: 4px;
  background: #796a92;
}
#splitter:hover::after, #splitter:focus-visible::after,
.workspace[data-resizing] #splitter::after { background: var(--iris); }
.workspace[data-resizing] { user-select: none; }
.workspace[data-resizing] #bars > g { transition: none; }
.panel {
  background: var(--surface);
  border: 1px solid var(--edge);
  border-radius: 16px;
  overflow: hidden;
  min-width: 0;
}
.panelhead {
  min-height: 60px;
  padding: 12px 19px;
  gap: 10px;
  border-bottom: 1px solid #383446;
  background: #201e2c;
}
.panelIcon {
  color: var(--iris);
  display: grid;
  place-items: center;
}
.panelIcon svg {
  width: 21px;
  height: 21px;
}
h2 {
  font-size: 1.05rem;
  font-weight: 625;
}
.codeNav {
  display: none;
  gap: 5px;
}
#launch {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 44px;
  padding: 0 15px;
  border: 0;
  background: #c3fa7c;
  color: #182510;
  font-weight: 700;
}
#launch:hover {
  background: #d7ffa5;
}
#launch svg {
  width: 15px;
  fill: currentColor;
}
body[data-mode="setup"] .program .panelhead {
  flex-wrap: wrap;
}
.codeNav button {
  min-width: 40px;
  min-height: 40px;
  display: grid;
  place-items: center;
}
#count,
#implementation,
#runningLanguage {
  margin-left: auto;
  color: #d1cbdc;
  font: 0.78rem var(--mono);
}
#implementation {
  min-height: 40px;
  max-width: 100%;
  padding: 0 8px;
  color: var(--iris);
  border: 1px solid var(--edge);
  border-radius: 8px;
  background: #282635;
}
.field {
  position: relative;
  padding: 14px 13px 10px;
  background:
    radial-gradient(ellipse at 45% 95%, #342650 0, transparent 67%), #1c192b;
}
#scroll {
  overflow-x: auto;
  scrollbar-color: #675988 #211c30;
  scrollbar-width: thin;
}
#chart {
  display: block;
  user-select: none;
  touch-action: none;
  overflow: visible;
  font-family: var(--mono);
}
#grid .axis {
  stroke: #70657f;
  stroke-width: 1;
}
#grid .guide {
  stroke: #51475e;
  stroke-dasharray: 2 5;
  stroke-width: 0.8;
}
.tick,
.index {
  fill: #b0a4c2;
  font-size: 11px;
}
.num {
  font-size: 16px;
  font-weight: 650;
  fill: #f7f4ff;
}
.empty {
  font:
    14px "Segoe UI",
    sans-serif;
  fill: #c7bed7;
}
#bars > g {
  transition: transform 0.24s cubic-bezier(0.16, 1, 0.3, 1);
  outline: none;
}
.front {
  fill: url(#front);
}
.lid {
  fill: #c6b8ff;
}
.side {
  fill: #5846a6;
}
.grip {
  stroke: #e5dcff;
  stroke-width: 2;
  stroke-linecap: round;
  pointer-events: none;
}
.activeBar .front,
.selectedBar .front {
  fill: url(#hot);
}
.activeBar .lid,
.selectedBar .lid {
  fill: #d1ffec;
}
.activeBar .side,
.selectedBar .side {
  fill: #368f83;
}
.activeBar .num,
.selectedBar .num {
  fill: var(--mint);
}
#bars g:hover .lid,
#bars g:focus-visible .lid {
  stroke: white;
  stroke-width: 1.8;
}
.bodyHit,
.capHit {
  fill: transparent;
  touch-action: none;
  cursor: grab;
}
.capHit {
  cursor: ns-resize;
}
#bars g {
  touch-action: none;
}
.dropLine {
  stroke: #b6ffe0;
  stroke-width: 3;
  stroke-dasharray: 5 4;
}
.tools {
  padding: 10px 5px 0;
  justify-content: space-between;
  gap: 10px;
}
.tool {
  min-height: 42px;
  display: inline-flex;
  gap: 8px;
  align-items: center;
  padding: 6px 12px;
  font-size: 0.84rem;
}
#add {
  background: #322844;
  border: 1px dashed #8a77aa;
  color: #e1d2ff;
  touch-action: none;
  cursor: grab;
}
#bin {
  border: 1px dashed #62566e;
  background: #272132;
  color: #d3c8dc;
}
#bin.target {
  background: #5c344a;
  border-color: #ffa8bd;
  color: #fff;
}
.gestureHint {
  align-items: flex-start;
  gap: 10px;
  padding: 12px 19px;
  border-block: 1px solid #353040;
  color: #c0b9cc;
  font-size: 0.8rem;
  line-height: 1.45;
}
.gestureHint [data-icon] {
  color: #b7a6db;
  flex: none;
  margin-top: 2px;
}
.gestureHint svg {
  width: 16px;
  height: 16px;
}
.player {
  padding: 17px 19px 19px;
}
.timeline {
  gap: 13px;
  color: #cdc7d9;
  font: 0.78rem var(--mono);
  font-variant-numeric: tabular-nums;
}
#seek {
  min-width: 0;
  flex: 1;
  appearance: none;
  height: 22px;
  margin: 0;
  cursor: pointer;
  background: transparent;
}
#seek::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 5px;
  background: linear-gradient(
    to right,
    var(--iris) var(--pct),
    #494252 var(--pct)
  );
}
#seek::-webkit-slider-thumb {
  appearance: none;
  background: var(--iris);
  border: 2px solid #211c2c;
  width: 14px;
  height: 14px;
  margin-top: -5px;
  border-radius: 50%;
}
#seek::-moz-range-track {
  height: 4px;
  background: #494252;
}
#seek::-moz-range-progress {
  background: var(--iris);
}
#seek::-moz-range-thumb {
  background: var(--iris);
}
.controls {
  margin-top: 12px;
  gap: 7px;
  flex-wrap: wrap;
}
.controls button,
.controls select {
  height: 43px;
}
.controls button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 13px;
}
.controls .primary {
  gap: 8px;
  background: var(--iris);
  border-color: transparent;
  color: #211931;
  min-width: 108px;
}
.controls .primary:hover {
  background: #cbbfff;
}
#play svg {
  fill: currentColor;
  stroke-width: 1.4;
  width: 15px;
}
.controls select {
  margin-left: auto;
  border: 1px solid var(--edge);
  border-radius: 8px;
  background: #262431;
  padding: 0 9px;
  font: 0.83rem var(--mono);
}
#source {
  container-type: inline-size;
  overflow: auto;
  padding: 13px 0 17px;
  background: #171620;
}
#listing {
  width: max-content;
  min-width: 100%;
}
.instruction {
  display: grid;
  grid-template-columns: 35px minmax(0, 1fr);
  align-items: baseline;
  gap: 4px;
  padding: 6px 16px 6px 5px;
}
.lineno {
  text-align: center;
  font: 0.7rem var(--mono);
  color: #928b9f;
}
.instructionContent {
  display: flex;
  align-items: baseline;
  gap: 10px;
  width: max-content;
}
.pinnedValue {
  display: inline-flex;
  align-items: center;
  padding-left: 7px;
  border: 1px solid #71618e;
  border-radius: 6px;
  background: #342b46;
  color: #e6dcff;
}
.pinnedValue samp {
  max-width: min(40ch, 57cqi);
  overflow-x: auto;
  white-space: nowrap;
  scrollbar-width: thin;
  font: 0.76rem/1.5 var(--mono);
}
.pinnedValue .unpin {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
}
.unpin svg { width: 12px; height: 12px; }
.codeVar[aria-pressed="true"] { text-decoration: underline dotted; }
.instruction code {
  color: #e0d8ea;
  font: clamp(0.79rem, 0.95vw, 0.94rem)/1.65 var(--mono);
  white-space: pre;
  tab-size: 2;
}
#source :is(code, samp) {
  font-variant-ligatures: none;
}
.keyword {
  color: #c6a1ff;
}
.fn {
  color: #a4dfed;
}
.literal {
  color: #f6c396;
}
.active .instruction {
  background: #322b45;
}
.active .lineno {
  color: #e0d0ff;
}
mark {
  background: #c3acff;
  color: #201930;
  border-radius: 3px;
  box-shadow: 0 0 0 2px #c3acff;
  font-weight: 650;
}
.hintSlot {
  position: sticky;
  left: 0;
  width: 100cqi;
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 170ms ease-in-out;
}
.hintSlot.open {
  grid-template-rows: 1fr;
}
.hintClip {
  min-height: 0;
  overflow: hidden;
}
.annotation {
  padding: 14px clamp(14px, 3%, 24px);
  background: #b9efdc;
  color: #16392e;
}
.annotationHead {
  gap: 8px;
  flex-wrap: wrap;
  justify-content: space-between;
}
.annotationHead strong {
  font-size: 0.9rem;
  color: #133b2e;
}
.result {
  font: 0.77rem/1.45 var(--mono);
  color: #154532;
}
.annotation p {
  margin: 6px 0 10px;
  font-size: 0.88rem;
  line-height: 1.52;
}
.bindings {
  align-items: baseline;
  gap: 6px;
  flex-wrap: wrap;
}
.binding {
  font: 0.74rem/1.5 var(--mono);
  color: #34594c;
  max-width: 100%;
  white-space: nowrap;
  overflow-x: auto;
  scrollbar-width: thin;
  background: #d8f7e9;
  border: 1px solid #8ecbb2;
  border-radius: 5px;
  padding: 3px 7px;
  overflow-wrap: anywhere;
}
.binding b {
  color: #1f4c3b;
  font-weight: 600;
}
.binding samp {
  font: inherit;
  color: #123628;
}
#valueEditor {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px;
  background: #302b40;
  border: 1px solid #8d7fa5;
  border-radius: 10px;
  box-shadow: 0 9px 22px #0a071766;
}
#valueEditor label {
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 0.8rem;
}
#exact {
  width: 6ch;
  font: 1rem var(--mono);
  background: #151220;
  border: 1px solid #716381;
  border-radius: 4px;
  padding: 5px;
}
#valueEditor button {
  min-height: 36px;
  padding: 5px 8px;
  font-size: 0.8rem;
}
#ghost {
  position: fixed;
  pointer-events: none;
  z-index: 10;
  transform: translate(-50%, -125%);
  background: var(--mint);
  border-radius: 6px;
  color: #162d24;
  font: 600 1rem var(--mono);
  padding: 6px 12px;
}
@media (min-width: 1550px) {
  .wrap {
    width: 90%;
  }
}
@media (max-width: 920px) {
  .workspace {
    --split-size: 22px;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, var(--stage-size)) var(--split-size) minmax(0, 1fr);
    align-items: stretch;
  }
  body[data-mode="setup"] .workspace { height: max(900px, 100svh); }
  body[data-mode="setup"] :is(.panel, .field) {
    display: flex;
    flex-direction: column;
    min-height: 0;
  }
  body[data-mode="setup"] :is(.field, #scroll, #source) { flex: 1; min-height: 0; }
  body[data-mode="setup"] #source { overflow: auto; }
  body[data-mode="setup"] #scroll { overflow-y: hidden; }
  #splitter { cursor: row-resize; }
  #splitter::before { inset: -5px 0; }
  #splitter::after { width: 44px; height: 4px; }
  .program :is(button, input, select, summary, [data-code-part]) {
    scroll-margin-top: calc(var(--code-offset) + var(--pin-gap));
  }
  .wrap {
    width: min(94%, 740px);
  }
  main {
    padding-top: 29px;
  }
  .instruction code {
    font-size: 0.89rem;
  }
  .field {
    padding-top: 8px;
  }
  .nav {
    min-height: 58px;
  }
}
@media (max-width: 480px) {
  .wrap {
    width: 94%;
  }
  .nav {
    gap: 10px;
  }
  .lab {
    font-size: 0.72rem;
    padding-left: 10px;
  }
  .brand {
    font-size: 1.12rem;
    gap: 5px;
  }
  .brand svg {
    width: 26px;
  }
  h1 {
    font-size: clamp(1.95rem, 8.65vw, 2.6rem);
  }
  .panelhead {
    min-height: 50px;
    padding: 10px 13px;
  }
  .field {
    padding-inline: 4px;
  }
  .tools {
    padding-inline: 8px;
  }
  .player,
  .gestureHint {
    padding-inline: 12px;
  }
  .instruction {
    grid-template-columns: 25px minmax(0, 1fr);
    padding-right: 16px;
  }
  .instruction code {
    font-size: 0.78rem;
  }
}
@media (prefers-reduced-motion: reduce) {
  #bars > g,
  .hintSlot {
    transition: none;
  }
}
@media (max-width: 920px) {
  .codeNav {
    display: flex;
  }
}

.sizeControl {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-inline: 6px;
  font-size: 0.79rem;
  color: var(--soft);
}
#size {
  flex: 1;
  min-width: 0;
  height: 32px;
  cursor: pointer;
  accent-color: var(--iris);
  margin: 0;
}
#count {
  min-width: 3ch;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.tools {
  flex-wrap: wrap;
  justify-content: flex-start;
}
#bin {
  margin-left: auto;
}
.swapArc {
  fill: none;
  stroke: #ffcc9c;
  stroke-width: 2.25;
  stroke-linecap: round;
}
.actionGuide {
  stroke: #ffcc9c;
  stroke-opacity: 0.55;
  stroke-dasharray: 2 4;
}
#chart [data-code-name] {
  pointer-events: all;
  pointer-events: bounding-box;
  cursor: pointer;
}
#chart [data-code-name]:hover,
#chart [data-code-name]:focus-visible {
  text-decoration: underline;
}
.actionCaption {
  font:
    600 12px "Segoe UI",
    sans-serif;
  fill: #ffce9d;
  paint-order: stroke;
  stroke: #211b30;
  stroke-width: 4px;
  stroke-linejoin: round;
}
.indexRole {
  font: 600 11px var(--mono);
  fill: #d4c8fb;
  pointer-events: none;
}
.barVariable {
  font: 600 10.5px var(--mono);
  fill: #191828;
  pointer-events: none;
}
.barVariable.outside {
  fill: #dbd3f1;
}
.annotation p:last-child { margin-bottom: 0; }
.stage .panelhead {
  flex-wrap: wrap;
}
@media (max-width: 480px) {
  .controls button {
    padding-inline: 9px;
  }
  .controls .primary {
    min-width: 86px;
  }
}
@media (max-width: 365px) {
  .controls {
    display: grid;
    grid-template-columns: auto 1fr auto;
  }
  .controls #next {
    grid-column: span 2;
  }
  .controls #play {
    grid-column: span 2;
  }
}
#sceneVars {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 3px 8px 7px;
}
#sceneVars [data-scalar] {
  background: #332b45;
  color: #e6ddff;
  border-radius: 5px;
  padding: 3px 8px;
  font: 0.78rem var(--mono);
}
.instruction .codeVar {
  display: inline;
  padding: 0;
  margin: 0;
  border: none;
  border-radius: 2px;
  background: transparent;
  font: inherit;
  letter-spacing: inherit;
  color: inherit;
  line-height: inherit;
  cursor: pointer;
}
.instruction .codeVar:hover,
.instruction .codeVar:focus-visible {
  text-decoration: underline dotted;
  text-underline-offset: 3px;
  background: #b997f733;
}
mark .keyword,
mark .fn,
mark .literal {
  color: inherit;
}
.hintSettings {
  border-bottom: 1px solid var(--edge);
  background: #211e2d;
}
#hintSettings, #share {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: none;
  color: #d7caee;
}
.program .panelhead { position: relative; }
#shareStatus:not(:empty) {
  position: absolute;
  z-index: 5;
  right: 10px;
  top: calc(100% + 4px);
  padding: 5px 10px;
  border-radius: 6px;
  color: #182510;
  background: #c3fa7c;
  pointer-events: none;
}
#shareStatus:empty { position: absolute; }
#hintSettings[aria-expanded="true"] {
  color: var(--iris);
  border-color: currentColor;
}
.settingsBody {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 9px 18px;
  padding: 10px 17px;
  font-size: 0.84rem;
}
.settingsBody label {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 32px;
}
.settingsBody select {
  font: inherit;
  background: #332e41;
  color: var(--type);
  border: 1px solid var(--edge);
  border-radius: 6px;
  padding: 5px;
}
.settingsBody input {
  width: 17px;
  height: 17px;
  accent-color: var(--iris);
}
.functionNote {
  margin-top: 9px;
  border-top: 1px solid #8ccbb3;
  padding-top: 7px;
  color: #1d4538;
  font-size: 0.84rem;
}
.functionNote code {
  font: 600 0.84rem var(--mono);
  margin-right: 4px;
}
.annotationHead + .bindings {
  margin-top: 7px;
}
#overviewBox {
  margin: 4px 6px;
  background: #201c2d;
  border: 1px solid #524960;
  border-radius: 5px;
}
#overview {
  display: block;
  width: 100%;
  height: 32px;
  cursor: ew-resize;
  touch-action: none;
}
#miniBars {
  fill: #9c8dc7;
}
#viewWindow {
  fill: #c5bcff24;
  stroke: #d8cfff;
  stroke-width: 1.4;
  vector-effect: non-scaling-stroke;
}
@media (max-width: 480px) {
  .tools {
    gap: 5px;
  }
  .tool {
    padding-inline: 8px;
    gap: 4px;
    font-size: 0.76rem;
  }
}

body[data-mode="run"] {
  min-height: 0;
  overflow: hidden;
}
body[data-mode="run"] :is(.mast, #title) {
  display: none;
}
body[data-mode="run"] main.wrap {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  padding: 0;
}
#runbar {
  display: flex;
  align-items: center;
  flex: none;
  gap: clamp(12px, 2.4vw, 40px);
  padding: 9px clamp(12px, 1.6vw, 28px);
  border-bottom: 1px solid var(--edge);
  background: #201e2c;
}
#runbar :is(#languages, .controls) {
  margin: 0;
  flex: none;
}
#runbar .player {
  display: flex;
  align-items: center;
  flex: 1;
  gap: clamp(12px, 2.4vw, 40px);
  padding: 0;
  min-width: 0;
}
#runbar .timeline {
  flex: 1;
  min-width: 0;
}
#step {
  white-space: nowrap;
}
body[data-mode="run"] .workspace {
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  align-items: stretch;
  flex: 1;
  min-height: 0;
  padding: 12px;
}
body[data-mode="run"] .panel,
body[data-mode="run"] .field {
  display: flex;
  flex-direction: column;
  position: relative;
  top: auto;
  min-height: 0;
}
body[data-mode="run"] :is(.field, #scroll, #source) {
  flex: 1;
  min-height: 0;
}
body[data-mode="run"] #scroll {
  overflow-y: hidden;
}
body[data-mode="run"] #source {
  overflow: auto;
  overflow-anchor: none;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  scrollbar-color: #675988 #171620;
  scrollbar-width: thin;
}
body[data-mode="run"] :is(.panelhead, .hintSettings, .stage .player) {
  flex: none;
}
body[data-mode="run"] .hintSettings {
  max-height: 38%;
  overflow-y: auto;
}
body[data-mode="run"] .program :is(button, input, select, summary, [data-code-part]) {
  scroll-margin-top: 6px;
}
@media (max-width: 920px) {
  #runbar { display: none; }
  .stage .panelhead, .program .panelhead :is(h2, .panelIcon) { display: none; }
  .sceneInputs { display: flex; align-items: center; gap: 8px; }
  .sceneInputs .sizeControl { flex: 1; min-width: 0; }
  .sceneInputs #launch { flex: none; }
  .program :is(#implementation, #runningLanguage) { margin-left: 0; }
  .program .codeNav { margin-left: auto; }
  body[data-mode="setup"] .program .panelhead { min-height: 0; padding-block: 6px; }
  body[data-mode="run"] .workspace {
    grid-template-rows: minmax(0, var(--stage-size)) var(--split-size) minmax(0, 1fr);
    padding: 6px;
  }
  body[data-mode="run"] .panelhead {
    min-height: 44px;
    padding: 4px 10px;
    gap: 6px;
  }
  body[data-mode="run"] .field { padding: 2px 4px; }
  .stage .player {
    padding: 4px 10px 8px;
    border-top: 1px solid var(--edge);
  }
  .stage .controls {
    display: flex;
    flex-wrap: nowrap;
    gap: 4px;
    margin-top: 2px;
  }
  .stage .controls button { padding: 0 9px; font-size: 0.87rem; }
  .stage .controls .primary { min-width: 0; }
  .stage .controls select { padding: 0 4px; }
}
@media (min-width: 600px) and (max-width: 920px) and (max-height: 520px) {
  body[data-mode="run"] .stage {
    display: grid;
    grid-template: auto minmax(0, 1fr) / minmax(0, 1fr) auto;
  }
  body[data-mode="run"] .stage .field { grid-area: 2 / 1 / 3 / -1; }
  .stage .player { display: contents; }
  .stage .timeline { grid-area: 1 / 1; padding: 4px 8px; min-width: 0; }
  .stage .controls { grid-area: 1 / 2; margin: 0; padding: 0 6px; }
}
@media (max-width: 480px) {
  body[data-mode="run"] .instruction { padding-block: 4px; }
}
@media (max-width: 600px) and (max-height: 660px) {
  body[data-mode="run"] #sceneVars { margin-block: 0; }
  body[data-mode="run"] #overview { height: 22px; }
}
@media (max-width: 365px) {
  body[data-mode="setup"] .workspace { height: max(1040px, 100svh); }
}
.treeSide {fill:#c4fadf;font:600 12px system-ui;paint-order:stroke;stroke:#201d2a;stroke-width:3px;pointer-events:none}
.graphEdge.residualArrow {--edge-stroke:#c695fd}
.graphEdge.residualArrow .bfsEdge {stroke-dasharray:5 4}
.condensation {margin:0;overflow:auto;max-width:100%;padding:4px}
.condensation figcaption {font-weight:600;margin-bottom:4px}
.condensation svg {display:block}
.condensation text {fill:white;font:600 12px monospace}
.componentLink {fill:none;stroke:#b1b2cb;stroke-width:1.8}
.partitionLine {stroke:#8d88a8;stroke-width:1;stroke-dasharray:4 7}
.rankHalo {fill:#7cf3c9;opacity:.42}
#graphCostEditor {display:flex;align-items:center;gap:8px;color:var(--soft)}
#graphCostEditor input {width:70px;background:var(--surface)}
.parentLink {fill:none;stroke:#f7bc7c;stroke-width:2.5;pointer-events:none}
#graphHelp.invalidGraph {color:#ffa9a8}

/* The catalog embeds the same setup scene and its controls in a bounded tile. */
body.lessonPreview { margin:0; min-height:0; background:#1b1927; }
.lessonPreview > .mast, .lessonPreview main > :is(h1,.algorithmIntro,#runbar),
.lessonPreview .workspace > :is(.program,#splitter), .lessonPreview .stage > :is(.panelhead,.gestureHint,.player),
.lessonPreview #legendToggle { display:none !important; }
.lessonPreview main.wrap { width:100%; max-width:none; margin:0; padding:0; height:100dvh; display:flex; flex-direction:column; }
body.lessonPreview .workspace { order:0; display:block; width:100%; height:auto; flex:1; min-height:0; margin:0; }
body.lessonPreview .stage { display:flex; flex-direction:column; position:static; height:100%; width:100%; border:0; border-radius:0; }
body.lessonPreview .field { display:flex; flex-direction:column; min-height:0; height:100%; overflow:auto; padding:6px 12px; }
.lessonPreview.graphView .sceneInputs { display:none; }
.lessonPreview #graphTools { margin:0; }
.lessonPreview #graphTools button { min-height:30px; padding:4px 9px; }
.lessonPreview #graphCanvas { min-height:90px; }
.lessonPreview #graphHelp { line-height:1.3; font-size:12px; }
.lessonPreview #tileActions { order:1; display:flex; align-items:center; justify-content:space-between; flex:none; gap:8px; padding:9px 15px; border-top:1px solid #383346; background:#211e2d; }
.lessonPreview #tileActions select { width:auto; margin:0; min-height:36px; }
.lessonPreview #launch { min-height:38px; color:#e1d9f5; background:#373142; border:1px solid #665974; font-weight:600; }
.lessonPreview #launch:hover:not(:disabled) { color:#fff; background:#463c53; border-color:#9985af; }
.lessonPreview #scroll { flex:1; min-height:65px; }
.lessonPreview .tools { flex:none; margin:0; padding:5px 0; }

