body.workbench.linear-lesson #teaching-scene {
  overflow: auto;
  padding: 12px;
  overscroll-behavior: contain;
}
body.workbench.linear-lesson[data-structure="array"] .workbench-view-controls .memory-toggle { display: none; }
body.workbench.linear-lesson #problem-inputs { flex-wrap: wrap; }
body.workbench.linear-lesson #problem-inputs label[hidden] { display: none; }
body.workbench.linear-lesson #problem-inputs input:not([type="number"]) { width: min(230px, 65vw); }
.dashboard-catalog .catalog-filters { flex-wrap: wrap; }

.linear-diagram {
  --linear-surface: oklch(98% .013 294);
  --linear-edge: oklch(65% .080 286);
  --linear-ink: oklch(31% .077 284);
  --linear-accent: oklch(43% .17 285);
  --linear-current: oklch(91% .057 293);
  display: grid;
  justify-items: center;
  gap: 9px;
  max-width: 680px;
  margin-inline: auto;
  color: var(--linear-ink);
}
:root[data-theme="dark"] .linear-diagram {
  --linear-surface: oklch(27% .037 271);
  --linear-edge: oklch(63% .090 286);
  --linear-ink: var(--aura-text);
  --linear-accent: var(--aura-violet);
  --linear-current: oklch(35% .087 286);
}
.linear-diagram p { margin: 0; font-size: 13px; }
.linear-stack .linear-slots { display:grid;gap:4px; }
.linear-slot { min-width:0; }
.linear-stack :is(.linear-slot, .linear-tray) {
  display: grid;
  align-items: center;
  grid-template-columns: minmax(4.5rem,auto) minmax(5rem,8rem);
  gap: 6px;
}
.linear-queue {
  width: max-content;
  min-width: 100%;
  max-width: none;
}
.linear-queue-track {
  display: grid;
  grid-template-columns: 54px auto 54px;
  align-items: end;
  gap: 5px;
}
.linear-queue .linear-slots {
  display: flex;
  gap: 6px;
}
.linear-queue .linear-slot { display:flex; flex-direction:column; justify-content:flex-end; width:clamp(37px, 9vw, 60px); }
.linear-slot-label {
  min-height: 20px;
  font: 600 11px/1.3 ui-monospace,monospace;
  text-align: center;
}
.linear-slot-label b { display:inline-block; color: var(--linear-accent); }
.linear-cell {
  display: grid;
  min-height: 42px;
  place-items: center;
  border: 1px solid var(--linear-edge);
  border-radius: 8px;
  background: var(--linear-surface);
  font: 750 22px/1 ui-monospace,monospace;
}
.linear-empty { border-style: dashed; }
.linear-current .linear-cell, .linear-tokens .linear-current { background: var(--linear-current); }
.linear-tokens { display:flex; flex-wrap:wrap; gap:4px; justify-content:center; }
.linear-tokens span, .linear-tray strong {
  display: inline-grid;
  place-items: center;
  min-width: 30px;
  padding: 4px 6px;
  border: 1px solid var(--linear-edge);
  border-radius: 6px;
  background: var(--linear-surface);
  font-family: ui-monospace,monospace;
}
.linear-tray { min-height: 38px; }
.linear-tray span { font-size: 11px; }
.linear-stack .linear-tray span { text-align: end; }
.linear-stack .linear-tray strong { justify-self: center; }
.linear-queue .linear-tray { display: grid; justify-items: center; }
.linear-queue .linear-tray strong { height: 42px; }
body.workbench #teaching-scene.linear-linked-queue .ll-logical-strip {
  flex-wrap: nowrap;
  justify-content: safe center;
  overflow-x: auto;
}
body.workbench #teaching-scene.linear-linked-queue .ll-chain-piece { flex: 0 0 auto; }
body.workbench #teaching-scene.linear-linked-stack .ll-logical-strip {
  flex-direction: column;
  flex-wrap: nowrap;
  align-items: center;
  gap: 4px;
}
body.workbench #teaching-scene.linear-linked-stack .ll-chain-piece {
  flex-direction: column;
  align-items: center;
  gap: 3px;
}
body.workbench #teaching-scene.linear-linked-stack .ll-logical-link {
  rotate: 90deg;
  line-height: 1;
}

@media (max-width:760px) {
  body.workbench.linear-lesson .teaching-top { flex-wrap:wrap; }
  body.workbench.linear-lesson #problem-inputs { flex:1 1 100%; }
  body.workbench.linear-lesson #problem-inputs input:not([type="number"]) { width:min(210px,58vw); }
  body.workbench #teaching-scene.linear-linked-queue .ll-logical-node { width: 68px; min-width: 68px; }
  body.workbench #teaching-scene.linear-linked-queue .ll-logical-fields strong { font-size: 20px; padding-inline: 2px; }
  body.workbench #teaching-scene.linear-linked-queue .ll-logical-fields > span { font-size: 9px; padding-inline: 2px; }
  body.workbench #teaching-scene.linear-linked-queue .ll-logical-link { font-size: 14px; min-width: 12px; }
  body.workbench #teaching-scene.linear-linked-queue .ll-chain-piece .ll-head-chip { font-size: 0; min-width: 16px; }
  body.workbench #teaching-scene.linear-linked-queue .ll-chain-piece .ll-head-chip b { font-size: 16px; }
  body.workbench #teaching-scene.linear-linked-queue .ll-chain-piece :is(.ll-head-chip, .ll-null) small { display: none; }
  body.workbench #teaching-scene.linear-linked-queue .ll-chain-piece .ll-null { min-width: 0; font-size: 10px; }
}

.advanced-linear {
  --lane-surface: var(--aura-raised, #f7f5fc);
  --lane-border: var(--hub-card-edge, #dcd5ea);
  --lane-accent: #573692;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: start;
  gap: 12px;
  max-width: 640px;
  margin-inline: auto;
}
:root[data-theme="dark"] .advanced-linear {
  --lane-border: var(--aura-hairline);
  --lane-accent: var(--aura-violet);
}
.advanced-lane {
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--lane-border);
  border-radius: 10px;
  background: var(--lane-surface);
}
.advanced-lane h3 {
  margin: 0 0 7px;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.3;
  color: var(--lane-accent);
}
.advanced-lane.advanced-input,
.advanced-lane[data-linear-lane="returned"],
.advanced-lane.advanced-queue { grid-column: 1 / -1; }
.advanced-cells { display: flex; flex-wrap: wrap; gap: 5px; }
.advanced-lane.advanced-stack .advanced-cells { flex-direction: column-reverse; flex-wrap: nowrap; align-items: center; gap: 4px; }
.advanced-lane.advanced-queue .advanced-cells { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; }
.advanced-slot { position: relative; flex: 0 0 auto; max-width: 100%; }
.advanced-linear .linear-cell {
  min-width: 34px;
  min-height: 34px;
  padding-inline: 6px;
  border-color: var(--lane-border);
  background: var(--aura-rail, #fff);
  font-size: 14px;
  overflow-wrap: anywhere;
}
.advanced-linear .linear-current {
  border-color: var(--lane-accent);
  outline: 2px solid var(--lane-accent);
  outline-offset: -2px;
}
.advanced-linear .linear-empty { opacity: .45; }
.advanced-stack .linear-cell { width: 56px; }
.advanced-pointer {
  display: block;
  color: var(--lane-accent);
  font: 700 9px/1.2 ui-monospace, monospace;
}
.advanced-stack .advanced-pointer { position: absolute; top: 11px; right: calc(100% + 4px); }
.advanced-queue .advanced-pointer { min-height: 11px; margin-bottom: 3px; white-space: nowrap; }
.advanced-slots .advanced-slot:nth-child(4) { margin-inline-start: 4px; }
.advanced-slots .advanced-slot:nth-child(4) .linear-cell { border-color: var(--lane-accent); }
.advanced-transfer { font: 750 14px/1 ui-monospace, monospace; }

body.workbench .teaching-canvas:has(.advanced-linear) #teaching-result-cost { order: 3; }
body.workbench .teaching-canvas:has(.advanced-linear) #teaching-review { order: 4; }

@media (max-width: 760px) {
  body.workbench[data-structure] #teaching-scene:has(.advanced-linear) {
    height: auto;
    min-height: 170px;
    max-height: min(350px, 46dvh);
  }
}

@media (max-width: 520px) {
  .advanced-linear { gap: 7px; }
  .advanced-lane { padding: 7px; }
  .advanced-linear .linear-cell { min-width: 26px; min-height: 29px; font-size: 12px; padding-inline: 4px; }
  .advanced-stack .linear-cell { width: 46px; }
}
