: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; }
.inspectionNumber { color:#185a4a; font-weight:700; font-variant-numeric:tabular-nums; }
#inspectionText { white-space:pre-line; }
#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,var(--edge-neutral,#978aa9)); }
.bfsEdge { stroke-width:2; }
.graphEdge.incident { --edge-neutral:#ded2fb; }
.graphEdge.incident:not(.active,.resultEdge) .bfsEdge { stroke-width:3; }
.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; }
#graphMap .graphEdge :is(.graphArrow,.bfsDirection) {
  fill:var(--edge-stroke,var(--edge-neutral,#978aa9)); stroke-width:1; stroke-linejoin:round; pointer-events:none;
}
.bfsNode { cursor:pointer; }
#graphMap { --node-surface:url(#graphNodeFace); }
.nodeDisk { fill:var(--node-surface,#292438); stroke:#ab9bbc; stroke-width:2; }
.bfsNode text { fill:#f4eefc; font:600 15px var(--mono); }
@media (max-width:600px) {
  #graphMap .bfsNode > text:not(.bfsRole) { font-size:18px; }
}
.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%; }
#stackStatus {
  margin: 3px 8px 0;
  color: var(--soft);
  font: 0.85rem var(--mono);
}
.numberListView :is(#scroll, .sizeControl, .field .tools, .gestureHint) {
  display: none !important;
}
.numberListView .sceneInputs:empty { display: none; }
#stackScene {
  container-type: size;
  position: relative;
  overflow: auto;
  scrollbar-color: #675988 #211c30;
  scrollbar-width: thin;
  height: clamp(280px, 48vh, 500px);
  min-height: 0;
  background: radial-gradient(ellipse at 50% 65%, #a985fd15, transparent 65%);
}
.stackView[data-mode="run"] #stackScene,
.stackView[data-mode="setup"] #stackScene { flex: 1; }
@media (min-width: 921px) {
  .stackView[data-mode="setup"] #stackScene { flex: none; }
}
body.lessonPreview.stackView #stackScene { flex: 1; }
#structureSetup { flex: none; padding: 4px 8px; }
#structureHelp { margin: 0 0 7px; color: var(--soft); font-size: .78rem; }
body.lessonPreview #structureHelp { display: none; }
#structureActions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px;
}
#structureSetup button { min-height: 38px; padding: 4px 9px; }
#structureSetup button b { color: var(--iris); }
.stack-cell[data-edit-index],
.ring-cell[data-edit-index] { cursor: pointer; }
.stack-cell[data-edit-index]:is(:hover, :focus-visible) .stack-face {
  border-color: #d8c7ff;
  box-shadow: inset 0 0 8px #a985fd35;
}
.ring-cell[data-edit-index]:is(:hover, :focus-visible) .ring-slot {
  fill: #51446a;
  stroke: #e4d4ff;
  stroke-width: 2;
}
#ringScene {
  display: grid;
  place-items: center;
  height: clamp(250px, 43vh, 420px);
  min-height: 0;
  background: radial-gradient(ellipse at center, #a985fd13, transparent 70%);
}
body.lessonPreview #ringScene,
body[data-mode="run"] #ringScene { flex: 1; }
#ringScene svg { display: block; width: 100%; height: 100%; min-height: 0; max-width: 490px; }
.ring-track { fill: none; stroke: #7867a3; stroke-dasharray: 2 5; }
.ring-slot { fill: #252036; stroke: #766690; }
.ring-occupied .ring-slot { fill: #393052; stroke: #b19bdc; }
.ring-active .ring-slot { fill: #554567; stroke: #ede2ff; stroke-width: 2; }
.ring-read-border, .ring-write-border { fill: none; stroke: transparent; stroke-width: 1.8; }
.ring-head .ring-read-border { stroke: #a2f9ed; }
.ring-tail .ring-write-border { stroke: #c9adff; stroke-dasharray: 4 3; }
.ring-head-arrow { color: #a2f9ed; pointer-events: none; }
.ring-arrow-editable { cursor: grab; pointer-events: auto; touch-action: none; outline: none; }
.ring-arrow-dragging { cursor: grabbing; }
.ring-arrow-hit, .ring-slot-index circle { fill: transparent; }
.ring-arrow-line, .ring-arrow-grip-lines {
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.ring-arrow-line { stroke-width: 2.6; }
.ring-arrow-grip { fill: #223638; stroke: currentColor; stroke-width: 1.3; }
.ring-arrow-grip-lines { stroke-width: 1.5; }
.ring-head-arrow:not(.ring-arrow-editable) :is(.ring-arrow-grip, .ring-arrow-grip-lines) { visibility: hidden; }
.ring-arrow-editable:is(:hover, :focus-visible, .ring-arrow-dragging) .ring-arrow-grip { fill: #395752; }
.ring-arrow-editable:focus-visible .ring-arrow-grip { stroke-width: 2.6; }
.ring-slot-index { pointer-events: none; }
.ring-index-editable { cursor: pointer; pointer-events: auto; }
.ring-index-editable:hover circle { fill: #a2f9ed22; }
.ring-legend, .ring-value, .ring-index {
  font-family: var(--mono);
  text-anchor: middle;
  dominant-baseline: central;
}
.ring-value { fill: #b3a5c7; font-size: 17px; }
.ring-occupied .ring-value { fill: #fff3ff; font-weight: 700; }
.ring-editing .ring-value { visibility: hidden; }
.ring-inline-input {
  display: block;
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  padding: 0 2px;
  border: 1px solid #a2f9ed;
  border-radius: 6px;
  outline: none;
  background: #211b32;
  color: #fff3ff;
  caret-color: #a2f9ed;
  text-align: center;
  font: 700 15px/1 var(--mono);
  appearance: textfield;
}
.ring-inline-input::-webkit-inner-spin-button,
.ring-inline-input::-webkit-outer-spin-button { appearance: none; margin: 0; }
.ring-inline-input:invalid { border-color: #ffb5bc; }
.ring-departing { fill: #a2f9ed; font-weight: 700; pointer-events: none; }
.ring-index { fill: #d3c7e5; font-size: 11px; }
.ring-legend { font-size: 14px; font-weight: 600; }
.ring-read { fill: #a2f9ed; }
.ring-write { fill: #c9adff; }
.ring-motion { fill: none; stroke-width: 2.4; stroke-linecap: round; stroke: #a2f9ed; }
.ring-motion[data-kind="write"] { stroke: #c9adff; }
#listScene {
  display: grid;
  place-items: center;
  height: clamp(220px, 42vh, 410px);
  min-height: 0;
  background: radial-gradient(ellipse at 50% 44%, #ad8afd15, transparent 70%);
}
body.lessonPreview #listScene,
body[data-mode="run"] #listScene { flex: 1; }
#listScene svg { display: block; width: 100%; height: 100%; max-width: 740px; }
.list-node-card { fill: #302745; stroke: #a690cb; stroke-width: 1.5; }
.list-divider { stroke: #766693; stroke-width: 1; }
.list-dot { fill: #b49edb; }
.list-link { fill: none; stroke: #9987be; stroke-width: 1.9; }
.list-link-active { stroke: #a2f9ed; stroke-width: 2.4; }
.list-current .list-node-card { fill: #273f42; stroke: #a2f9ed; stroke-width: 2.4; }
.list-previous .list-node-card { stroke: #dfbd8b; stroke-width: 2.2; }
.list-current.list-previous .list-node-card { stroke: #a2f9ed; }
.list-head, .list-value, .list-end { font-family: var(--mono); text-anchor: middle; dominant-baseline: central; }
.list-head { fill: #a2f9ed; font-size: 13px; font-weight: 700; }
.list-value { fill: #f4ecff; font-size: 16px; font-weight: 700; pointer-events: none; }
.list-end { fill: #baacd2; font-size: 21px; }
.list-departing { fill: #a2f9ed; }
.list-node[data-edit-index] { cursor: pointer; }
.list-node[data-edit-index]:focus-visible { outline: none; }
.list-node[data-edit-index]:is(:hover, :focus-visible) .list-node-card { stroke: #f2e8ff; stroke-width: 2.6; }
.list-editing .list-value { visibility: hidden; }
@media (max-width: 420px) {
  body.lessonPreview #listScene:not([hidden]) + #structureSetup button { padding-inline: 5px; font-size: .87rem; }
}

#heapScene {
  display: grid;
  place-items: center;
  height: clamp(245px, 46vh, 455px);
  min-height: 0;
  background: radial-gradient(ellipse at 50% 43%, #ad8afd13, transparent 68%);
}
body.lessonPreview #heapScene,
body[data-mode="run"] #heapScene { flex: 1; }
#heapScene svg { display: block; width: 100%; height: 100%; min-height: 0; max-width: 650px; }
@media (max-width: 420px) {
  body.lessonPreview #heapScene:not([hidden]) + #structureSetup button {
    padding-inline: 6px;
    font-size: .9rem;
  }
}
.heap-edge { stroke: #8e7aac; stroke-width: 2; }
.heap-link-active { stroke: #a2f9ed; stroke-width: 2.8; }
.heap-link-next { stroke: #756790; stroke-dasharray: 4 5; }
.heap-node-disc { fill: #302745; stroke: #a690cb; stroke-width: 1.5; }
.heap-min .heap-node-disc { fill: #243a3d; stroke: #a2f9ed; stroke-width: 2.4; }
.heap-next .heap-node-disc { fill: #262137; stroke: #a690cb; stroke-dasharray: 4 4; }
.heap-plus {
  display: none;
  fill: none;
  stroke: #d9c5f7;
  stroke-width: 2;
  stroke-linecap: round;
}
.heap-next .heap-plus { display: block; }
.heap-node[data-edit-index] { cursor: pointer; }
.heap-node[data-edit-index]:focus-visible { outline: none; }
.heap-node[data-edit-index]:is(:hover, :focus-visible) .heap-node-disc {
  stroke: #f2e8ff;
  stroke-width: 2.6;
}
.heap-active .heap-node-disc, .heap-slot.heap-active rect { fill: #304741; stroke: #a2f9ed; stroke-width: 2.5; }
.heap-slot rect { fill: #292237; stroke: #7f6c9b; }
.heap-value, .heap-array-label, .heap-empty { font-family: var(--mono); fill: #f4ecff; }
.heap-value, .heap-empty { text-anchor: middle; dominant-baseline: central; }
.heap-value { font-size: 15px; font-weight: 700; pointer-events: none; }
.heap-array-label, .heap-empty { fill: #c3b5d7; font-size: 13px; }
.heap-min .heap-value, .heap-departing { fill: #a2f9ed; }
.heap-editing :is(.heap-value, .heap-plus) { visibility: hidden; }
:is(.heap-inline-input, .list-inline-input) {
  display: block;
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  padding: 0 1px;
  border: 1px solid #a2f9ed;
  border-radius: 6px;
  outline: none;
  background: #211b32;
  color: #fff3ff;
  caret-color: #a2f9ed;
  text-align: center;
  font: 700 14px/1 var(--mono);
  appearance: textfield;
}
:is(.heap-inline-input, .list-inline-input)::-webkit-inner-spin-button,
:is(.heap-inline-input, .list-inline-input)::-webkit-outer-spin-button { appearance: none; margin: 0; }
:is(.heap-inline-input, .list-inline-input):invalid { border-color: #ffb5bc; }
.stack-book-illustration { height: clamp(210px, 32vh, 290px); margin-top: 12px; }
html:lang(ru) .stack-book-illustration:lang(en),
html:lang(en) .stack-book-illustration:lang(ru) { display: none; }
.stack-track {
  --stack-clearance: clamp(76px, 19cqh, 110px);
  --cube: clamp(32px, calc((100cqh - var(--stack-clearance)) / var(--levels)), 88px);
  display: grid;
  align-items: center;
  justify-items: center;
  min-height: 100%;
}
.stack-tower {
  position: relative;
  inline-size: var(--cube);
  block-size: calc(var(--levels) * var(--cube) + var(--stack-clearance));
}
.stack-world {
  position: absolute;
  inset: 0 0 30px;
  transform: rotateX(-19deg) rotateY(-29deg);
  transform-origin: center calc(100% - var(--levels, 4) * var(--cube));
  transform-style: preserve-3d;
}
.stack-floor {
  position: absolute;
  width: 150%;
  aspect-ratio: 1;
  left: -25%;
  bottom: 0;
  transform: translateY(50%) rotateX(90deg);
  border: 1px solid #9a83cc60;
  border-radius: 12%;
  background: radial-gradient(ellipse, #120e22b0 25%, #62528435 70%);
}
.stack-cell {
  --half: calc(var(--cube) / 2);
  --glass: #ac98f7;
  position: absolute;
  bottom: calc(var(--index) * var(--cube));
  width: var(--cube);
  height: var(--cube);
  transform-style: preserve-3d;
}
.stack-top, .stack-departing { --glass: #a2f9ed; }
.stack-face {
  position: absolute;
  inset: 0;
  border: 1px solid color-mix(in srgb, var(--glass) 60%, transparent);
  background: linear-gradient(135deg, color-mix(in srgb, var(--glass) 16%, transparent), transparent 54%, color-mix(in srgb, var(--glass) 9%, transparent));
}
.stack-face-front {
  transform: translateZ(var(--half));
  background:
    linear-gradient(126deg, transparent 16%, #f6eaff19 16% 24%, transparent 24% 30%, #f6eaff0d 30% 33%, transparent 33%),
    linear-gradient(160deg, #b7b8ff06, #d9c6ff13);
  box-shadow: inset 0 0 0 1px #e0daff22;
}
.stack-face-back { transform: rotateY(180deg) translateZ(var(--half)); }
.stack-face-left { transform: rotateY(-90deg) translateZ(var(--half)); }
.stack-face-right { transform: rotateY(90deg) translateZ(var(--half)); }
.stack-face-top { transform: rotateX(90deg) translateZ(var(--half)); }
.stack-face-bottom { transform: rotateX(-90deg) translateZ(var(--half)); }
.stack-peek .stack-face {
  border-color: #c8fff5;
  box-shadow: inset 0 0 9px #a7ffdf45;
}
.stack-value {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  transform: rotateY(29deg) rotateX(19deg);
  color: #faf6ff;
  text-shadow: 0 2px 6px #101020, 0 0 10px #171027;
  font: 700 calc(var(--cube) * .35)/1 var(--mono);
  user-select: none;
}
.stack-editing .stack-face { pointer-events: none; }
.stack-inline-input {
  box-sizing: border-box;
  width: 86%;
  min-width: 0;
  height: 55%;
  padding: 0 2px;
  border: 1px solid #cbb6ff;
  border-radius: 5px;
  color: #fff7ff;
  background: #26213a;
  font: 700 calc(var(--cube) * .30)/1 var(--mono);
  text-align: center;
  appearance: textfield;
}
.stack-inline-input::-webkit-inner-spin-button,
.stack-inline-input::-webkit-outer-spin-button { appearance: none; margin: 0; }
.stack-inline-input:focus { outline: 2px solid #a2f9ed; outline-offset: 1px; }
.stack-top .stack-value { color: #cdfff3; }
.stack-empty .stack-floor { border-style: dashed; }
.stack-action {
  /* Keep the indicator flat while following the projected height of the top face. */
  --surface: calc(var(--stack-clearance) - 30px + (var(--levels) - var(--shown-levels)) * var(--cube) * cos(19deg));
  position: absolute;
  z-index: 1;
  top: var(--surface);
  left: 50%;
  width: clamp(40px, calc(var(--cube) * .83), 64px);
  transform: translate(-50%, -94%);
  overflow: visible;
  pointer-events: none;
  color: #a2f9ed;
  filter: drop-shadow(0 0 5px color-mix(in srgb, currentColor 54%, transparent));
}
.stack-action path,
.stack-action circle {
  fill: none;
  stroke: currentColor;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.stack-action[data-action="pop"] { color: #ffcc95; }
.stack-action[data-action="pop"] .stack-action-vertical {
  transform-origin: 32px 25px;
  transform: rotate(180deg);
}
.stack-action[data-action="peek"] {
  top: calc(var(--surface) + .45 * var(--cube));
  left: calc(50% + .66 * var(--cube));
  transform: translateY(-72%);
  color: #dbc6ff;
}
.stack-empty .stack-action[data-action="peek"] {
  top: var(--surface);
}
.stack-action:not([data-action="peek"]) .stack-action-peek,
.stack-action[data-action="peek"] .stack-action-vertical {
  display: none;
}
.stack-action-peek circle {
  fill: #302247;
  stroke-width: 2;
}
.stack-action-peek text {
  fill: currentColor;
  font: 700 15px var(--sans, sans-serif);
}
@keyframes stack-lift-fade {
  0%, 45% { opacity: 1; }
  100% { opacity: 0; }
}
.stack-departing :is(.stack-face, .stack-value) { animation: stack-lift-fade .34s ease-in both; }
#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;
}
#descriptionToggle { flex:none; width:36px; min-height:36px; padding:0; border:0; background:transparent; color:var(--iris); }
#descriptionToggle:is(:hover,:focus-visible,[aria-pressed="true"]) { background:#393446; }
#sceneDescription { flex:1; min-height:0; overflow:auto; padding:18px 20px; line-height:1.55; }
#sceneDescription h3 { margin:0 0 12px; line-height:1.25; }
#sceneDescription p { max-width:66ch; margin:0 0 .75em; white-space:pre-line; }
#sceneDescription p:empty { display:none; }
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; }
  body[data-mode="setup"]:not(.lessonPreview) .stage .panelhead { display:flex; min-height:44px; padding:3px 10px; }
  .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 :is(.field,#sceneDescription) { 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; }
.stringView :is(#scroll,#overviewBox,.sizeControl,.field .tools,.gestureHint),
.lessonPreview.stringView .sceneInputs { display:none !important; }
#stringInputs { display:grid; gap:14px; padding:8px; }
#stringInputs label { display:grid; gap:6px; color:var(--soft); }
#stringInputs :is(input,textarea) {
  box-sizing:border-box; width:100%; min-width:0; padding:8px 10px;
  background:var(--surface); color:var(--type); border:1px solid var(--edge);
  border-radius:6px; font:15px/1.4 var(--mono);
}
#stringInputs textarea { resize:vertical; }
#stringRun { flex:1; min-width:0; min-height:0; overflow:auto; padding:6px 10px; }
.trieGoal { display:flex; align-items:baseline; gap:9px; margin:0 0 6px; font-size:.9rem; }
.trieGoal strong { flex:none; }
.trieGoal span { overflow:auto; white-space:pre; color:var(--mint); }
.trieRowLabel { display:flex; flex-wrap:wrap; align-items:baseline; gap:1px 9px; margin-bottom:3px; color:var(--soft); font-size:.84rem; font-weight:650; }
.trieRowLabel span { font-size:.78rem; font-weight:400; }
.stringStepRow { margin:6px 0 10px; min-width:0; }
.stringStepValues,.stringStepList { display:flex; flex-wrap:wrap; gap:4px; max-height:13rem; overflow:auto; align-content:start; }
.stringStepList { display:grid; grid-template-columns:minmax(0,1fr); }
.stringStepList .stringStepCell { text-align:start; white-space:pre-wrap; overflow-wrap:anywhere; }
.stringStepCell { min-width:28px; padding:3px 7px; font: .88rem/1.4 var(--mono); }
.stringStepCell.compared { color:#231c36; background:var(--iris); }
.stringStepCell.compared small { color:#42375d; }
.stringStepCell.inspectedCell { outline:2px solid #ffca98; outline-offset:-2px; }
.stringStructureMap { max-height:15rem; overflow:auto; background:#211d2c; border:1px solid var(--edge); border-radius:8px; }
.stringStructureMap svg { display:block; width:min(100%,360px); margin:auto; }
.stringMapEdge { cursor:pointer; }
.stringMapEdge:is(:hover,:focus-visible) rect { stroke:var(--iris); stroke-width:3; }
.stringMapTip { stroke:#aa9fbd; fill:none; }
details.stringStepRow > summary { display:list-item; cursor:pointer; }
.sceneInspector .stringStepJump { padding:5px 8px; justify-self:start; font:inherit; text-decoration:underline; }
.trieStages { display:flex; flex-wrap:wrap; gap:4px; margin:2px 0 12px; }
.trieStages button { font-size:.82rem; line-height:1.25; min-height:30px; padding:4px 9px; }
.trieStage[aria-current] { background:var(--iris); color:#21192e; }
.stringTape { display:flex; position:relative; overflow-x:auto; gap:3px; padding:2px 0; }
.stringCell { display:grid; flex:none; min-width:30px; padding:2px 4px; text-align:center; font:16px/1.25 var(--mono); background:#262232; }
.stringCell small { color:var(--soft); font-size:10px; }
.stringCell.matched { background:#324b46; }
.stringCell.palCenter { box-shadow:inset 0 -3px var(--mint); }
.stringCell.palGap { box-shadow:inset 3px 0 var(--mint); }
.stringCell.palMirror { border:2px dashed var(--iris); }
.stringCell.palPair { border:2px solid #ffca98; color:#fff1dd; }
.stringGoal { display:block; font-size:.95rem; }
.stringChoices { display:flex; flex-wrap:wrap; align-items:center; gap:6px; margin:5px 0; }
.stringChoices button,.stringWhy summary { min-height:36px; padding:6px 10px; cursor:pointer; }
.stringFeedback,.stringWhy { font-size:.88rem; line-height:1.4; }
#lessonHelp { flex:none; margin-top:4px; }
#lessonHelp > button { max-width:100%; padding:5px 10px; min-height:32px; text-align:start; color:var(--iris); line-height:1.25; }
#lessonExplanation .stringWhy summary { color:#504064; padding-left:0; }
#lessonExplanation .stringChoices button { width:auto; height:auto; min-height:36px; padding:6px 12px; font:inherit; border:1px solid #ae997b; border-radius:7px; }
.stringWhy summary { display:list-item; width:fit-content; color:var(--iris); }
.stringWhy p { margin:0 0 8px; padding:4px 10px; border-left:2px solid var(--iris); }
.stringCell[aria-current] { border-color:var(--mint); color:var(--mint); }
.trieCaption { margin:9px 0; font-size:.95rem; line-height:1.4; overflow-wrap:anywhere; }
.trieViewport { overflow:auto; max-height:clamp(180px,40vh,480px); background:#211d2c; border:1px solid var(--edge); border-radius:8px; }
.trieViewport svg { display:block; margin:auto; height:auto; }
.trieEdge,.trieSuffix { fill:none; }
.trieEdge { stroke:#9b91ae; stroke-width:1.5; }
.trieEdge.active { stroke:var(--mint); stroke-width:2.8; }
.trieLetter,.trieCheck { font:600 12px var(--mono); fill:#d3c8e1; stroke:#211d2c; stroke-width:4; paint-order:stroke; }
.trieLetter.active,.trieCheck { fill:var(--mint); }
.trieSuffix { stroke:#ffca98; stroke-width:2; stroke-dasharray:5 3; pointer-events:none; }
.trieNode { cursor:pointer; }
.trieNode rect { fill:#302a3e; stroke:#9b8aaa; stroke-width:1.5; }
.triePrefix { font:600 14px var(--mono); fill:#f5f0fb; }
.trieNode.current rect { fill:var(--mint); stroke:#ccffe8; }
.trieNode.current .triePrefix { fill:#14362b; }
.trieNode:is(:hover,:focus-visible,[aria-pressed="true"]) rect { stroke:var(--iris); stroke-width:3; }
.trieArrow { cursor:pointer; }
.trieArrowTarget { fill:none; stroke:transparent; stroke-width:24; pointer-events:stroke; }
.trieArrow[data-part="suffix"] .trieArrowTarget { stroke-width:14; }
.trieArrow:is(:hover,:focus-visible,[aria-pressed="true"]) :is(.trieEdge,.trieSuffix) { stroke:var(--iris); stroke-width:3; }
.trieArrow:is(:hover,:focus-visible,[aria-pressed="true"]) .trieLetter { fill:var(--iris); }
.trieArrow:focus,.trieNode:focus { outline:none; }
.inspectorDetails { grid-column:1/-1; display:grid; gap:7px; overflow:auto; padding:0 16px 14px; }
.trieExamples { display:flex; flex-wrap:wrap; gap:4px 8px; }
.trieExamples code { white-space:pre-wrap; }
.trieExamples b { color:#185a4a; text-decoration:underline; text-underline-offset:2px; }
.sceneInspector {
  position:fixed; z-index:12; display:grid; grid-template-columns:1fr 44px;
  grid-template-rows:40px minmax(0,auto); width:min(310px,calc(100vw - 20px));
  max-height:calc(100dvh - 20px); box-sizing:border-box; overflow:hidden;
  background:#f5e7cc; color:#382d23; border-radius:12px;
  box-shadow:0 7px 24px #100b1c55; font-size:.94rem; line-height:1.4; overflow-wrap:anywhere;
}
.inspectorGrip { cursor:grab; touch-action:none; user-select:none; display:grid; align-items:center; padding-left:16px; }
.inspectorGrip:active { cursor:grabbing; }
.inspectorGrip::before { content:""; width:32px; height:4px; border-radius:3px; background:#9f896c; }
.sceneInspector button {
  min-width:0; min-height:0; margin:0; padding:0; background:transparent; border:0;
  color:#544330; font-size:21px; box-shadow:none;
}
.sceneInspector button:is(:hover,:focus-visible) { background:#e7d4b6; color:#35291e; }
.stringMatches { display:flex; flex-wrap:wrap; gap:5px 10px; margin:8px 0 12px; max-height:6em; overflow:auto; }
.stringMatches { align-items:center; }
.trieHit { padding:3px 7px; font:13px var(--mono); overflow-wrap:anywhere; }
.trieHit[aria-current] { border-color:var(--mint); color:var(--mint); }
@media (max-width:600px) {
  .trieStages { margin-bottom:5px; }
  .trieStages button { font-size:.76rem; padding:3px 7px; }
  .trieCaption { margin:5px 0; font-size:.85rem; }
}

