:root {
  --ink: #152033;
  --ink-soft: #536176;
  --paper: #f5f7fa;
  --surface: #ffffff;
  --line: #d9e0ea;
  --blue: #155eef;
  --cyan: #10b9b0;
  --orange: #f76707;
  --yellow: #f4b740;
  --green: #24a66b;
  --red: #db4e5c;
  --navy: #111827;
  --violet: #8a55d7;
  --studio-bg: #10231f;
  --studio-ink: #e9f2e8;
  --studio-strong: #fffdf2;
  --studio-muted: #a9beb5;
  --studio-copy: #d2ded8;
  --studio-sky: #75d9ca;
  --studio-panel: #18332d;
  --studio-panel-line: #3d655b;
  --studio-node-line: #66877e;
  --studio-edge: #607d74;
  --studio-label: #b6c7c0;
  --studio-control: rgba(255, 255, 255, 0.1);
  --studio-control-hover: rgba(255, 255, 255, 0.18);
  --studio-rule: rgba(217, 224, 234, 0.18);
  --studio-panel-soft: rgba(24, 51, 45, 0.76);
  --studio-panel-hover: rgba(61, 101, 91, 0.52);
  --studio-yellow-soft: rgba(244, 183, 64, 0.16);
  --studio-red-soft: rgba(219, 78, 92, 0.2);
  --studio-green-soft: rgba(36, 166, 107, 0.2);
  --font-display: "STSong", "Songti SC", "Noto Serif CJK SC", serif;
  --font-ui: "Avenir Next", "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-code: "SFMono-Regular", "Cascadia Code", "Liberation Mono", monospace;
  --shadow: 0 18px 50px rgba(21, 32, 51, 0.09);
}

* {
  box-sizing: border-box;
}

html {
  background: var(--paper);
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: var(--font-ui);
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.library-view {
  width: min(1240px, calc(100% - 48px));
  margin: 0 auto;
  padding: 28px 0 64px;
}

.library-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 26px;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  gap: 12px;
  align-items: center;
  color: var(--ink);
  text-decoration: none;
  font-size: 14px;
  font-weight: 800;
}

.brand__mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  color: var(--surface);
  background: var(--navy);
  border-radius: 8px;
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 900;
}

.algorithm-count {
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 700;
}

.library-intro {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(240px, 0.45fr);
  gap: 56px;
  align-items: end;
  padding: 72px 0 48px;
}

.kicker {
  margin: 0;
  color: var(--blue);
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.12em;
}

.library-intro h1 {
  max-width: 760px;
  margin: 12px 0 0;
  font-family: var(--font-display);
  font-size: clamp(42px, 6vw, 82px);
  font-weight: 700;
  letter-spacing: 0;
  line-height: 1.08;
}

.library-intro > p {
  max-width: 290px;
  margin: 0 0 6px auto;
  color: var(--ink-soft);
  font-size: 16px;
  line-height: 1.85;
}

.category-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 28px;
  overflow-x: auto;
  scrollbar-width: none;
}

.category-tabs::-webkit-scrollbar {
  display: none;
}

.category-tab {
  flex: 0 0 auto;
  min-height: 36px;
  padding: 0 13px;
  color: var(--ink-soft);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 800;
}

.category-tab:hover,
.category-tab.is-active {
  color: var(--surface);
  background: var(--navy);
  border-color: var(--navy);
}

.algorithm-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border-top: 1px solid var(--line);
  border-left: 1px solid var(--line);
}

.algorithm-card {
  position: relative;
  display: grid;
  min-height: 250px;
  padding: 22px;
  overflow: hidden;
  text-align: left;
  background: var(--surface);
  border: 0;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.algorithm-card::after {
  position: absolute;
  right: 18px;
  bottom: 14px;
  color: var(--line);
  content: "↗";
  font-size: 22px;
  transition: transform 0.24s ease, color 0.24s ease;
}

.algorithm-card:hover,
.algorithm-card:focus-visible {
  z-index: 1;
  outline: none;
  box-shadow: inset 0 0 0 2px var(--card-color), var(--shadow);
}

.algorithm-card:hover::after,
.algorithm-card:focus-visible::after {
  color: var(--card-color);
  transform: translate(3px, -3px);
}

.algorithm-card__top,
.algorithm-card__bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.algorithm-card__top span,
.algorithm-card__bottom span {
  color: var(--ink-soft);
  font-size: 11px;
  font-weight: 800;
}

.algorithm-card__index {
  color: var(--card-color) !important;
}

.algorithm-card h2 {
  max-width: 210px;
  margin: 0;
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 700;
  line-height: 1.18;
}

.algorithm-card__bottom strong {
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 12px;
}

.mini-preview {
  display: flex;
  gap: 6px;
  align-items: end;
  height: 44px;
  margin: 12px 0;
}

.mini-preview i {
  display: block;
  width: 12px;
  height: var(--h);
  background: var(--card-color);
  border-radius: 2px 2px 0 0;
  opacity: 0.9;
}

.mini-preview--string {
  align-items: center;
}

.mini-preview--string i {
  width: 18px;
  height: 18px;
  border-radius: 3px;
}

.mini-preview--graph {
  position: relative;
  display: block;
}

.mini-preview--graph::before,
.mini-preview--graph::after {
  position: absolute;
  top: 19px;
  left: 22px;
  width: 80px;
  height: 1px;
  background: var(--line);
  content: "";
  transform-origin: left center;
}

.mini-preview--graph::after {
  transform: rotate(27deg);
}

.mini-preview--graph i {
  position: absolute;
  width: 16px;
  height: 16px;
  background: var(--card-color);
  border-radius: 50%;
}

.mini-preview--graph i:nth-child(1) { left: 14px; top: 12px; }
.mini-preview--graph i:nth-child(2) { left: 68px; top: 4px; }
.mini-preview--graph i:nth-child(3) { left: 102px; top: 27px; }
.mini-preview--graph i:nth-child(4) { left: 52px; top: 29px; }

.studio-view {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: none;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-height: 100dvh;
  color: var(--studio-ink);
  background: var(--studio-bg);
}

.studio-view.is-active {
  display: grid;
}

.studio-header {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 18px;
  align-items: center;
  padding: 20px 28px;
  border-bottom: 1px solid var(--studio-rule);
}

.back-button,
.control-button,
.play-button {
  display: grid;
  place-items: center;
  border: 0;
  transition: background 0.2s ease, transform 0.2s ease;
}

.back-button {
  width: 42px;
  height: 42px;
  color: var(--studio-ink);
  background: var(--studio-control);
  border-radius: 7px;
  font-size: 22px;
}

.back-button:hover,
.control-button:hover {
  background: var(--studio-control-hover);
}

.studio-title h2 {
  margin: 3px 0 0;
  color: var(--studio-strong);
  font-family: var(--font-display);
  font-size: clamp(22px, 3vw, 32px);
  font-weight: 700;
}

.studio-title .kicker {
  color: var(--studio-sky);
}

.studio-header__tools {
  display: flex;
  gap: 18px;
  align-items: center;
}

.try-data-button {
  min-height: 36px;
  padding: 0 12px;
  color: var(--navy);
  background: var(--yellow);
  border: 0;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 900;
  transition: transform 0.2s ease, background 0.2s ease, opacity 0.2s ease;
}

.try-data-button:hover:not(:disabled) {
  background: var(--studio-strong);
  transform: translateY(-1px);
}

.try-data-button:disabled {
  cursor: not-allowed;
  opacity: 0.38;
}

.complexity {
  display: flex;
  gap: 16px;
  color: var(--studio-muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.complexity span {
  display: grid;
  gap: 3px;
}

.complexity strong {
  color: var(--studio-strong);
  font-size: 12px;
  letter-spacing: 0;
}

.studio-body {
  min-height: 0;
}

.canvas-wrap {
  position: relative;
  display: grid;
  min-width: 0;
  min-height: 0;
  padding: 28px;
  isolation: isolate;
}

.canvas-wrap::before {
  position: absolute;
  inset: 0;
  z-index: -1;
  background-image: repeating-linear-gradient(0deg, transparent 0, transparent 31px, var(--studio-rule) 32px), repeating-linear-gradient(90deg, transparent 0, transparent 31px, var(--studio-rule) 32px);
  content: "";
  opacity: 0.16;
  pointer-events: none;
}

.canvas-meta {
  position: absolute;
  top: 28px;
  left: 28px;
  z-index: 2;
  display: grid;
  gap: 4px;
}

.canvas-meta span:first-child {
  color: var(--studio-sky);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.1em;
}

.canvas-meta span:last-child {
  color: var(--studio-strong);
  font-family: var(--font-display);
  font-size: 18px;
}

.visual-stage {
  position: relative;
  display: grid;
  min-height: 0;
  place-items: center;
  overflow: hidden;
}

.stage-hud {
  position: absolute;
  inset: 28px;
  z-index: 3;
  pointer-events: none;
}

.stage-hud > section {
  min-width: 0;
}

.code-panel {
  position: absolute;
  top: 0;
  left: 50%;
  width: min(430px, 40vw);
  text-align: center;
  transform: translateX(-50%);
}

.code-panel code {
  display: block;
  margin-top: 7px;
  overflow: hidden;
  color: var(--yellow);
  font-family: var(--font-code);
  font-size: clamp(12px, 1.15vw, 15px);
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.variables-panel {
  position: absolute;
  top: 0;
  right: 0;
  width: min(320px, 30vw);
}

.step-note {
  position: absolute;
  bottom: 0;
  left: 0;
  width: min(470px, 48%);
  padding: 15px 0 0;
  border-top: 1px solid var(--studio-rule);
}

.invariant-panel {
  position: absolute;
  right: 0;
  bottom: 0;
  width: min(360px, 36%);
  padding: 15px 0 0 18px;
  border-top: 1px solid var(--studio-rule);
  border-left: 1px solid var(--studio-rule);
}

.panel-eyebrow {
  display: block;
  color: var(--studio-sky);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.13em;
}

.invariant-panel p {
  margin: 7px 0 0;
  color: var(--studio-copy);
  font-family: var(--font-display);
  font-size: 14px;
  line-height: 1.5;
}

.variable-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 8px;
}

.variable-chip {
  display: grid;
  gap: 3px;
  min-width: 0;
  padding: 7px 8px;
  background: var(--studio-panel-soft);
  border: 1px solid var(--studio-panel-line);
  border-radius: 5px;
}

.variable-chip b {
  overflow: hidden;
  color: var(--studio-muted);
  font-size: 10px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.variable-chip strong {
  overflow: hidden;
  color: var(--studio-strong);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.step-note {
  display: block;
}

.step-note__index {
  color: var(--yellow);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.14em;
}

.step-note p {
  margin: 7px 0 0;
  color: var(--studio-strong);
  font-family: var(--font-display);
  font-size: clamp(16px, 1.45vw, 20px);
  line-height: 1.5;
}

.quiz-panel {
  position: absolute;
  top: 50%;
  left: 50%;
  display: grid;
  gap: 10px;
  width: min(390px, calc(100% - 48px));
  padding: 20px;
  pointer-events: auto;
  background: var(--studio-panel);
  border: 1px solid var(--yellow);
  border-radius: 7px;
  box-shadow: var(--shadow);
  transform: translate(-50%, -50%);
}

.quiz-panel[hidden] {
  display: none;
}

.quiz-question {
  margin: 0;
  color: var(--studio-strong);
  font-family: var(--font-display);
  font-size: 16px;
  line-height: 1.55;
}

.quiz-options {
  display: grid;
  gap: 7px;
}

.quiz-option {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  width: 100%;
  min-height: 38px;
  padding: 7px 9px;
  color: var(--studio-copy);
  text-align: left;
  background: var(--studio-control);
  border: 1px solid var(--studio-panel-line);
  border-radius: 5px;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.35;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.quiz-option:hover {
  background: var(--studio-panel-hover);
}

.quiz-option span {
  display: grid;
  width: 22px;
  height: 22px;
  place-items: center;
  color: var(--studio-sky);
  background: var(--studio-panel);
  border-radius: 50%;
  font-size: 10px;
  font-weight: 900;
}

.quiz-option.is-correct {
  color: var(--studio-strong);
  background: var(--studio-green-soft);
  border-color: var(--green);
}

.quiz-option.is-wrong {
  color: var(--studio-strong);
  background: var(--studio-red-soft);
  border-color: var(--red);
}

.quiz-feedback {
  min-height: 18px;
  margin: 0;
  color: var(--studio-muted);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.45;
}

.quiz-feedback.is-correct {
  color: var(--green);
}

.quiz-continue-button {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 42px;
  padding: 8px 12px;
  color: var(--navy);
  background: var(--yellow);
  border: 1px solid var(--yellow);
  border-radius: 5px;
  font-weight: 900;
}

.quiz-continue-button:hover {
  background: var(--studio-strong);
  border-color: var(--studio-strong);
}

.quiz-continue-button[hidden] {
  display: none;
}

.quiz-continue-button b {
  font-family: var(--font-code);
  font-size: 15px;
}

.quiz-option:disabled {
  cursor: default;
}

.custom-data-panel {
  position: absolute;
  right: 28px;
  bottom: 28px;
  z-index: 4;
  width: min(380px, calc(100% - 56px));
  padding: 18px;
  color: var(--studio-ink);
  background: var(--studio-panel);
  border: 1px solid var(--studio-panel-line);
  border-radius: 7px;
  box-shadow: var(--shadow);
}

.custom-data-panel[hidden] {
  display: none;
}

.custom-data-panel__header {
  display: flex;
  gap: 14px;
  align-items: start;
  justify-content: space-between;
}

.custom-data-panel__header strong {
  display: block;
  margin-top: 5px;
  color: var(--studio-strong);
  font-family: var(--font-display);
  font-size: 20px;
}

.panel-close-button {
  display: grid;
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  place-items: center;
  color: var(--studio-copy);
  background: transparent;
  border: 0;
  border-radius: 5px;
  font-size: 23px;
  line-height: 1;
}

.panel-close-button:hover {
  background: var(--studio-control-hover);
}

.custom-data-fields {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.custom-field {
  display: grid;
  gap: 6px;
}

.custom-field span {
  color: var(--studio-muted);
  font-size: 11px;
  font-weight: 800;
}

.custom-field input {
  width: 100%;
  min-height: 40px;
  padding: 0 10px;
  color: var(--studio-strong);
  background: var(--navy);
  border: 1px solid var(--studio-panel-line);
  border-radius: 5px;
  outline: none;
}

.custom-field input:focus {
  border-color: var(--studio-sky);
}

.custom-data-error {
  min-height: 18px;
  margin: 9px 0 0;
  color: var(--red);
  font-size: 12px;
  font-weight: 700;
}

.custom-data-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.drawer-primary-button,
.drawer-secondary-button {
  min-height: 36px;
  padding: 0 11px;
  border-radius: 5px;
  font-size: 12px;
  font-weight: 900;
}

.drawer-primary-button {
  color: var(--navy);
  background: var(--yellow);
  border: 1px solid var(--yellow);
}

.drawer-secondary-button {
  color: var(--studio-copy);
  background: transparent;
  border: 1px solid var(--studio-panel-line);
}

.drawer-primary-button:hover {
  background: var(--studio-strong);
  border-color: var(--studio-strong);
}

.drawer-secondary-button:hover {
  background: var(--studio-control-hover);
}

.studio-controls {
  padding: 16px 28px 22px;
  border-top: 1px solid var(--studio-rule);
}

.timeline {
  position: relative;
  height: 16px;
  margin-bottom: 14px;
}

.timeline::before {
  position: absolute;
  top: 7px;
  right: 0;
  left: 0;
  height: 2px;
  background: var(--studio-rule);
  content: "";
}

.timeline__bar {
  position: absolute;
  top: 7px;
  left: 0;
  z-index: 1;
  width: 0;
  height: 2px;
  background: var(--orange);
  transition: width 0.28s ease;
}

.timeline__dots {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.timeline__dot {
  width: 8px;
  height: 8px;
  background: var(--navy);
  border: 2px solid var(--ink-soft);
  border-radius: 50%;
  transition: transform 0.2s ease, background 0.2s ease, border-color 0.2s ease;
}

.timeline__dot.is-active {
  background: var(--orange);
  border-color: var(--orange);
  transform: scale(1.35);
}

.control-row {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: center;
}

.control-button,
.play-button {
  width: 46px;
  height: 46px;
  color: var(--studio-strong);
  background: var(--studio-control);
  border-radius: 7px;
  font-size: 20px;
}

.control-button--text {
  width: auto;
  padding: 0 14px;
  color: var(--studio-copy);
  font-size: 13px;
  font-weight: 800;
}

.play-button {
  width: 58px;
  height: 58px;
  color: var(--navy);
  background: var(--yellow);
  border-radius: 50%;
  font-size: 22px;
}

.play-button:hover {
  background: var(--yellow);
  transform: scale(1.05);
}

.speed-control {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-left: 12px;
  color: var(--studio-muted);
  font-size: 12px;
  font-weight: 800;
}

.speed-control input {
  width: 108px;
  accent-color: var(--yellow);
}

.linked-scene {
  position: relative;
  width: min(100%, 920px);
  min-width: min(calc(var(--linked-count) * 105px), 920px);
  height: 360px;
}

.linked-scene svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.linked-scene marker path {
  fill: var(--studio-strong);
}

.linked-edge {
  fill: none;
  stroke: var(--studio-edge);
  stroke-width: 1.4;
  transition: stroke 0.3s ease, stroke-width 0.3s ease;
}

.linked-edge.is-reversed {
  stroke: var(--yellow);
}

.linked-edge.is-active {
  stroke: var(--orange);
  stroke-width: 2.7;
  stroke-dasharray: 6 3;
  animation: pointer-flow 0.8s linear infinite;
}

.linked-node {
  position: absolute;
  top: 54%;
  display: grid;
  grid-template-columns: minmax(42px, 1fr) 28px;
  width: clamp(72px, 9vw, 104px);
  min-height: 58px;
  color: var(--studio-strong);
  background: var(--studio-panel);
  border: 2px solid var(--studio-node-line);
  border-radius: 4px;
  transform: translate(-50%, -50%);
  transition: border-color 0.3s ease, background 0.3s ease, box-shadow 0.3s ease;
}

.linked-node > b {
  display: grid;
  place-items: center;
  font-family: var(--font-code);
  font-size: 18px;
}

.linked-node__next {
  border-left: 1px solid var(--studio-node-line);
}

.linked-node__next::after {
  position: absolute;
  top: 50%;
  right: 8px;
  width: 7px;
  height: 7px;
  background: var(--studio-muted);
  border-radius: 50%;
  content: "";
  transform: translateY(-50%);
}

.linked-node.is-active {
  background: var(--studio-yellow-soft);
  border-color: var(--yellow);
  box-shadow: 0 0 0 8px var(--studio-yellow-soft);
}

.linked-node.is-done {
  border-color: var(--green);
}

.linked-pointer {
  position: absolute;
  top: calc(-40px - var(--pointer-order) * 23px);
  left: 50%;
  color: var(--studio-sky);
  font-size: 11px;
  font-weight: 900;
  transform: translateX(-50%);
  white-space: nowrap;
}

.linked-pointer i {
  display: block;
  margin-top: 2px;
  color: var(--studio-strong);
  font-style: normal;
  text-align: center;
}

.linked-null-label {
  position: absolute;
  right: -2px;
  bottom: -27px;
  color: var(--studio-muted);
  font-family: var(--font-code);
  font-size: 9px;
}

.linked-null-label::before {
  position: absolute;
  right: 13px;
  bottom: 14px;
  width: 18px;
  height: 1px;
  background: var(--studio-edge);
  content: "";
  transform: rotate(55deg);
  transform-origin: right center;
}

.linked-null-bank {
  position: absolute;
  bottom: 14px;
  left: 50%;
  display: flex;
  gap: 12px;
  transform: translateX(-50%);
}

.linked-null-bank span {
  padding: 5px 8px;
  color: var(--studio-muted);
  border-bottom: 1px solid var(--studio-rule);
  font-family: var(--font-code);
  font-size: 11px;
}

.linked-null-bank b {
  color: var(--studio-sky);
}

.stack-scene {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(290px, 0.85fr);
  gap: 50px;
  width: min(100%, 780px);
  min-height: 330px;
  align-items: center;
}

.stack-input {
  display: grid;
  gap: 14px;
}

.stack-input > span {
  color: var(--studio-muted);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.12em;
}

.stack-input > div {
  display: flex;
  gap: 8px;
}

.stack-input__cell {
  display: grid;
  width: 42px;
  height: 48px;
  place-items: center;
  color: var(--studio-muted);
  border-bottom: 2px solid var(--studio-panel-line);
  font-family: var(--font-code);
  font-size: 20px;
  font-weight: 900;
  transition: color 0.25s ease, background 0.25s ease, transform 0.25s ease;
}

.stack-input__cell.is-read {
  color: var(--green);
}

.stack-input__cell.is-current {
  color: var(--navy);
  background: var(--yellow);
  border-color: var(--yellow);
  border-radius: 4px 4px 0 0;
  transform: translateY(-8px);
}

.stack-workbench {
  display: grid;
  grid-template-columns: 86px 150px;
  gap: 20px;
  align-items: start;
  justify-content: center;
}

.stack-incoming {
  display: grid;
  gap: 8px;
  justify-items: center;
  padding-top: 28px;
}

.stack-incoming small {
  color: var(--studio-muted);
  font-size: 10px;
  font-weight: 900;
}

.stack-incoming strong {
  display: grid;
  width: 54px;
  height: 54px;
  place-items: center;
  color: var(--navy);
  background: var(--yellow);
  border-radius: 50%;
  font-family: var(--font-code);
  font-size: 22px;
  box-shadow: 0 0 0 10px var(--studio-yellow-soft);
}

.stack-vessel {
  position: relative;
  min-height: 230px;
  padding: 22px 12px 28px;
  border-right: 4px solid var(--studio-node-line);
  border-bottom: 4px solid var(--studio-node-line);
  border-left: 4px solid var(--studio-node-line);
  border-radius: 0 0 18px 18px;
}

.stack-vessel__mouth,
.stack-vessel__base {
  position: absolute;
  left: 50%;
  color: var(--studio-muted);
  font-size: 9px;
  font-weight: 900;
  letter-spacing: 0.1em;
  transform: translateX(-50%);
}

.stack-vessel__mouth { top: -18px; }
.stack-vessel__base { bottom: 7px; }

.stack-items {
  display: flex;
  min-height: 170px;
  flex-direction: column;
  justify-content: flex-end;
}

.stack-item {
  display: grid;
  height: 48px;
  place-items: center;
  color: var(--studio-strong);
  background: var(--studio-panel-soft);
  border: 1px solid var(--studio-panel-line);
  border-radius: 3px;
  font-family: var(--font-code);
  font-size: 19px;
  font-weight: 900;
}

.stack-item.is-top {
  color: var(--navy);
  background: var(--studio-sky);
  border-color: var(--studio-sky);
}

.stack-empty {
  margin: auto 0;
  color: var(--studio-muted);
  font-family: var(--font-code);
  font-size: 12px;
  text-align: center;
}

.stack-scene--push .stack-item.is-top { animation: stack-push 0.55s ease both; }
.stack-scene--pop .stack-incoming strong { animation: stack-pop 0.65s ease both; }
.stack-scene--compare .stack-incoming strong,
.stack-scene--compare .stack-item.is-top { animation: compare-pulse 0.8s ease both; }
.stack-scene--error .stack-incoming strong { color: var(--studio-strong); background: var(--red); }

@media (min-width: 901px) {
  .stack-scene {
    transform: translateX(-100px);
  }
}

.queue-scene {
  position: relative;
  width: min(76vw, 430px);
  aspect-ratio: 1;
}

.queue-ring {
  position: absolute;
  inset: 10%;
  border: 2px dashed var(--studio-edge);
  border-radius: 50%;
}

.queue-slot {
  position: absolute;
  display: grid;
  width: clamp(52px, 7vw, 66px);
  height: clamp(52px, 7vw, 66px);
  place-items: center;
  color: var(--studio-strong);
  background: var(--studio-panel);
  border: 2px solid var(--studio-node-line);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  transition: background 0.3s ease, border-color 0.3s ease, transform 0.3s ease;
}

.queue-slot small {
  position: absolute;
  top: 4px;
  color: var(--studio-muted);
  font-size: 8px;
}

.queue-slot strong {
  padding-top: 7px;
  font-family: var(--font-code);
  font-size: 17px;
}

.queue-slot > i {
  position: absolute;
  top: calc(100% + 5px);
  display: flex;
  gap: 4px;
  font-style: normal;
}

.queue-slot > i b {
  padding: 2px 5px;
  color: var(--navy);
  background: var(--studio-sky);
  border-radius: 3px;
  font-family: var(--font-code);
  font-size: 8px;
}

.queue-slot.is-active {
  border-color: var(--yellow);
  box-shadow: 0 0 0 9px var(--studio-yellow-soft);
  transform: translate(-50%, -50%) scale(1.08);
}

.queue-slot.is-done {
  color: var(--navy);
  background: var(--green);
  border-color: var(--green);
}

.queue-center {
  position: absolute;
  top: 50%;
  left: 50%;
  display: grid;
  width: 52%;
  gap: 8px;
  justify-items: center;
  color: var(--studio-copy);
  text-align: center;
  transform: translate(-50%, -50%);
}

.queue-center small {
  color: var(--studio-muted);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.1em;
}

.queue-center strong {
  font-family: var(--font-display);
  font-size: 18px;
}

.queue-center code {
  color: var(--yellow);
  font-family: var(--font-code);
  font-size: 10px;
}

.queue-incoming {
  position: absolute;
  top: 3%;
  right: 2%;
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  color: var(--navy);
  background: var(--orange);
  border-radius: 50%;
  font-family: var(--font-code);
  font-weight: 900;
}

.queue-scene--enqueue .queue-incoming { animation: queue-enter 0.7s ease both; }
.queue-scene--wrap .queue-slot.is-active { animation: queue-wrap 0.85s ease both; }

.array-scene {
  position: relative;
  display: flex;
  gap: clamp(8px, 1.5vw, 18px);
  align-items: end;
  justify-content: center;
  width: min(100%, 820px);
  min-height: 280px;
  padding: 58px 14px 34px;
}

.array-item {
  position: relative;
  display: grid;
  width: clamp(38px, 6vw, 72px);
  min-height: 48px;
  place-items: center;
  color: var(--studio-ink);
  background: var(--studio-panel);
  border: 1px solid var(--studio-panel-line);
  border-radius: 6px 6px 3px 3px;
  font-size: clamp(15px, 2vw, 20px);
  font-weight: 900;
  transition: transform 0.3s ease, background 0.3s ease, border-color 0.3s ease, opacity 0.3s ease;
  animation: stage-in 0.28s ease both;
  animation-delay: calc(var(--item-index) * 35ms);
}

.array-item b {
  position: relative;
  z-index: 1;
  transition: opacity 0.12s ease;
}

.array-pointer {
  position: absolute;
  top: calc(-37px - var(--pointer-order, 0) * 18px);
  left: 50%;
  z-index: 2;
  color: var(--studio-sky);
  font-size: 10px;
  font-weight: 900;
  line-height: 1;
  transform: translateX(-50%);
  white-space: nowrap;
}

.array-pointer i,
.string-pointer i {
  display: block;
  margin-top: 2px;
  font-style: normal;
  text-align: center;
}

.array-item.is-swap-landing b {
  opacity: 0;
}

.motion-tag {
  position: absolute;
  top: 14px;
  left: 14px;
  z-index: 3;
  padding: 5px 8px;
  color: var(--studio-sky);
  background: var(--studio-control);
  border: 1px solid var(--studio-panel-line);
  border-radius: 4px;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.08em;
}

.motion-tag--swap {
  color: var(--yellow);
}

.motion-tag--compare,
.motion-tag--probe {
  color: var(--orange);
}

.motion-tag--prepare,
.motion-tag--move,
.motion-tag--jump,
.motion-tag--relocate {
  color: var(--studio-sky);
}

.motion-tag--lift,
.motion-tag--place,
.motion-tag--merge,
.motion-tag--heap-swap,
.motion-tag--extract {
  color: var(--yellow);
}

.motion-tag--confirm,
.motion-tag--relax,
.motion-tag--match {
  color: var(--green);
}

.motion-tag--reject,
.motion-tag--mismatch {
  color: var(--red);
}

.array-pivot-token {
  position: absolute;
  top: 14px;
  right: auto;
  left: 150px;
  display: grid;
  grid-template-columns: auto auto;
  gap: 2px 8px;
  align-items: center;
  padding: 7px 10px;
  color: var(--navy);
  background: var(--yellow);
  border: 1px solid var(--yellow);
  border-radius: 5px;
  box-shadow: 0 8px 22px var(--studio-yellow-soft);
}

.array-pivot-token small,
.array-pivot-token i {
  font-size: 9px;
  font-style: normal;
  font-weight: 900;
}

.array-pivot-token b {
  grid-row: 1 / 3;
  grid-column: 2;
  font-family: var(--font-code);
  font-size: 20px;
}

.array-pivot-token i {
  opacity: 0.68;
}

.array-pivot-token.is-placed {
  color: var(--studio-strong);
  background: var(--green);
  border-color: var(--green);
}

.swap-motion-layer {
  position: absolute;
  inset: 0;
  z-index: 5;
  pointer-events: none;
}

.swap-ghost {
  position: absolute;
  top: var(--ghost-top);
  left: var(--ghost-left);
  display: grid;
  width: var(--ghost-width);
  height: var(--ghost-height);
  place-items: center;
  color: var(--navy);
  background: var(--yellow);
  border: 1px solid var(--yellow);
  border-radius: 6px 6px 3px 3px;
  font-size: clamp(15px, 2vw, 20px);
  font-weight: 900;
  box-shadow: 0 10px 24px var(--studio-yellow-soft);
  transform: translate3d(0, 0, 0);
  transition: transform 0.6s cubic-bezier(0.5, 0, 0.15, 1);
  will-change: transform;
}

.swap-ghost.is-moving {
  transform: translate3d(var(--swap-x), var(--swap-y), 0);
}

.array-item.is-bar {
  min-height: var(--bar-height);
}

.array-item::after {
  position: absolute;
  bottom: -22px;
  color: var(--studio-muted);
  content: attr(data-label);
  font-size: 10px;
  font-weight: 800;
}

.array-item.is-active {
  color: var(--navy);
  background: var(--yellow);
  border-color: var(--yellow);
  transform: translateY(-16px);
}

.array-item.is-compare {
  color: var(--studio-strong);
  background: var(--orange);
  border-color: var(--orange);
  transform: translateY(-9px);
}

.array-item.is-done {
  color: var(--studio-strong);
  background: var(--green);
  border-color: var(--green);
}

.array-item.is-faded {
  opacity: 0.28;
}

.array-item.is-found {
  color: var(--studio-strong);
  background: var(--blue);
  border-color: var(--studio-sky);
  transform: translateY(-12px) scale(1.08);
}

.array-item.is-hole {
  color: var(--yellow);
  background: transparent;
  border-color: var(--yellow);
  border-style: dashed;
  box-shadow: inset 0 0 0 2px var(--studio-yellow-soft);
}

.string-scene {
  position: relative;
  display: grid;
  gap: 24px;
  width: min(100%, 820px);
  padding: 62px 14px 20px;
}

.string-board {
  position: relative;
  z-index: 1;
  display: grid;
  gap: 30px;
  overflow: hidden;
  padding: 36px 10px 12px 58px;
  border-left: 2px solid var(--studio-rule);
}

.string-track {
  position: relative;
  display: flex;
  gap: clamp(4px, 1vw, 10px);
  align-items: center;
  justify-content: flex-start;
  width: max-content;
}

.string-track--pattern {
  transition: transform 0.72s cubic-bezier(0.5, 0, 0.15, 1);
}

.string-track-label {
  position: absolute;
  right: calc(100% + 14px);
  color: var(--studio-muted);
  font-size: 10px;
  font-weight: 900;
  white-space: nowrap;
}

.string-cell {
  position: relative;
  display: grid;
  width: clamp(28px, 5vw, 54px);
  height: clamp(38px, 6vw, 54px);
  place-items: center;
  color: var(--studio-ink);
  background: var(--studio-panel);
  border: 1px solid var(--studio-panel-line);
  border-radius: 5px;
  font-weight: 900;
  transition: transform 0.28s ease, background 0.28s ease;
}

.string-cell.is-active {
  color: var(--navy);
  background: var(--yellow);
  transform: translateY(-10px);
}

.string-cell.is-match {
  background: var(--green);
  border-color: var(--green);
}

.string-cell.is-gap {
  visibility: hidden;
}

.string-pointer {
  position: absolute;
  top: -27px;
  left: 50%;
  z-index: 2;
  color: var(--studio-sky);
  font-size: 10px;
  font-weight: 900;
  line-height: 1;
  transform: translateX(-50%);
}

.prefix-table {
  position: relative;
  z-index: 1;
  display: flex;
  gap: 5px;
  align-items: stretch;
  justify-content: center;
}

.prefix-table > span {
  display: grid;
  padding: 0 9px;
  place-items: center;
  color: var(--yellow);
  font-family: var(--font-code);
  font-size: 11px;
  font-weight: 900;
}

.prefix-table i {
  display: grid;
  width: 38px;
  min-height: 40px;
  place-items: center;
  color: var(--studio-strong);
  background: var(--studio-panel-soft);
  border-bottom: 2px solid var(--studio-sky);
  font-style: normal;
}

.prefix-table small {
  color: var(--studio-muted);
  font-size: 7px;
}

.prefix-table b {
  font-family: var(--font-code);
  font-size: 13px;
}

.prefix-table i.is-active {
  color: var(--navy);
  background: var(--yellow);
  border-color: var(--yellow);
  transform: translateY(-7px);
  animation: matrix-pulse 0.7s ease both;
}

.kmp-jump-path {
  position: relative;
  z-index: 1;
  display: flex;
  gap: 9px;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  color: var(--studio-copy);
  font-family: var(--font-code);
}

.kmp-jump-path span {
  padding: 6px 9px;
  background: var(--studio-panel-soft);
  border: 1px solid var(--studio-panel-line);
  border-radius: 4px;
  font-size: 11px;
  font-weight: 900;
}

.kmp-jump-path i {
  color: var(--studio-sky);
  font-size: 22px;
  font-style: normal;
  animation: kmp-jump 0.72s ease both;
}

.kmp-jump-path small {
  color: var(--yellow);
  font-size: 10px;
  font-weight: 900;
}

.comparison-beam {
  position: absolute;
  top: var(--beam-top);
  left: var(--beam-left);
  z-index: 0;
  width: var(--beam-width);
  height: 2px;
  background: var(--green);
  box-shadow: 0 0 10px var(--green);
  transform: rotate(var(--beam-angle));
  transform-origin: left center;
}

.comparison-beam.is-mismatch {
  background: var(--orange);
  box-shadow: 0 0 10px var(--orange);
  animation: mismatch-shake 0.45s ease both;
}

.matrix-scene {
  position: relative;
  display: grid;
  width: min(100%, 660px);
  min-height: 360px;
  padding: 64px 24px 18px;
  align-content: center;
  justify-items: center;
}

.matrix-formula {
  display: flex;
  gap: 18px;
  align-items: center;
  margin-bottom: 18px;
  color: var(--studio-copy);
}

.matrix-formula span {
  padding: 5px 8px;
  color: var(--navy);
  background: var(--studio-sky);
  border-radius: 4px;
  font-family: var(--font-code);
  font-size: 11px;
  font-weight: 900;
}

.matrix-formula code {
  color: var(--yellow);
  font-family: var(--font-code);
  font-size: 12px;
}

.matrix-grid {
  display: grid;
  grid-template-columns: 34px repeat(var(--matrix-size), minmax(48px, 62px));
  grid-template-rows: 30px repeat(var(--matrix-size), minmax(46px, 56px));
  gap: 5px;
  justify-content: center;
}

.matrix-corner,
.matrix-axis,
.matrix-cell {
  display: grid;
  place-items: center;
  font-family: var(--font-code);
  font-weight: 900;
}

.matrix-corner {
  grid-row: 1;
  grid-column: 1;
  color: var(--yellow);
  font-size: 13px;
}

.matrix-axis {
  grid-row: var(--matrix-row);
  grid-column: var(--matrix-column);
  color: var(--studio-sky);
  font-size: 11px;
}

.matrix-cell {
  grid-row: var(--matrix-row);
  grid-column: var(--matrix-column);
  color: var(--studio-strong);
  background: var(--studio-panel-soft);
  border: 1px solid var(--studio-panel-line);
  border-radius: 4px;
  font-size: 16px;
  transition: background 0.28s ease, border-color 0.28s ease, transform 0.28s ease, opacity 0.28s ease;
}

.matrix-cell.is-pivot-axis {
  border-color: var(--studio-sky);
}

.matrix-cell.is-route {
  color: var(--navy);
  background: var(--studio-sky);
}

.matrix-cell.is-update {
  color: var(--navy);
  background: var(--yellow);
  border-color: var(--yellow);
  animation: matrix-pulse 0.72s ease both;
}

.matrix-cell.is-focus {
  box-shadow: 0 0 0 6px var(--studio-yellow-soft);
  transform: scale(1.08);
}

.bucket-scene {
  position: relative;
  display: grid;
  gap: 14px;
  width: min(64vw, 620px);
  min-width: 620px;
  min-height: 300px;
  padding: 40px 10px 12px;
  align-content: center;
  transform: translateX(-110px);
}

.bucket-source {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
}

.bucket-source > span {
  color: var(--studio-muted);
  font-size: 10px;
  font-weight: 900;
}

.bucket-source > div {
  display: flex;
  gap: 6px;
}

.bucket-source > div span {
  display: grid;
  min-width: 42px;
  height: 34px;
  padding: 0 6px;
  place-items: center;
  color: var(--studio-strong);
  background: var(--studio-panel);
  border: 1px solid var(--studio-panel-line);
  border-radius: 4px;
  font-family: var(--font-code);
  font-size: 12px;
  font-weight: 900;
}

.bucket-source code {
  color: var(--yellow);
  font-family: var(--font-code);
  font-size: 11px;
}

.radix-buckets {
  display: grid;
  grid-template-columns: repeat(10, minmax(50px, 1fr));
  gap: 6px;
}

.radix-bucket {
  position: relative;
  display: grid;
  min-height: 150px;
  padding: 18px 5px 24px;
  border-right: 2px solid var(--studio-node-line);
  border-bottom: 2px solid var(--studio-node-line);
  border-left: 2px solid var(--studio-node-line);
  border-radius: 0 0 9px 9px;
}

.radix-bucket > span {
  position: absolute;
  right: 0;
  bottom: 3px;
  left: 0;
  color: var(--studio-muted);
  font-family: var(--font-code);
  font-size: 9px;
  font-weight: 900;
  text-align: center;
}

.radix-bucket > div {
  display: flex;
  flex-direction: column-reverse;
  gap: 5px;
  justify-content: flex-start;
}

.radix-bucket b {
  display: grid;
  min-height: 30px;
  place-items: center;
  color: var(--navy);
  background: var(--studio-sky);
  border-radius: 3px;
  font-family: var(--font-code);
  font-size: 10px;
  animation: bucket-drop 0.52s ease both;
  animation-delay: calc(var(--bucket-index) * 60ms);
}

.radix-bucket.has-values {
  border-color: var(--studio-sky);
}

.bucket-scene--collect .bucket-source > div span {
  color: var(--navy);
  background: var(--yellow);
  border-color: var(--yellow);
  animation: collect-rise 0.52s ease both;
  animation-delay: calc(var(--source-index) * 45ms);
}

.multiway-scene {
  position: relative;
  width: min(100%, 760px);
  height: 360px;
}

.multiway-scene svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.multiway-scene line {
  stroke: var(--studio-edge);
  stroke-width: 2px;
  vector-effect: non-scaling-stroke;
}

.multiway-node {
  position: absolute;
  display: flex;
  min-width: 62px;
  min-height: 50px;
  overflow: hidden;
  color: var(--studio-strong);
  background: var(--studio-panel);
  border: 2px solid var(--studio-node-line);
  border-radius: 4px;
  transform: translate(-50%, -50%);
  transition: transform 0.35s ease, border-color 0.35s ease, background 0.35s ease;
}

.multiway-node b {
  display: grid;
  min-width: 48px;
  padding: 0 8px;
  place-items: center;
  border-left: 1px solid var(--studio-panel-line);
  font-family: var(--font-code);
  font-size: 15px;
}

.multiway-node b:first-child {
  border-left: 0;
}

.multiway-node.is-active {
  border-color: var(--yellow);
  box-shadow: 0 0 0 8px var(--studio-yellow-soft);
}

.multiway-node.is-overflow {
  border-color: var(--red);
  box-shadow: 0 0 0 9px var(--studio-red-soft);
  animation: mismatch-shake 0.52s ease both;
}

.promoted-key {
  position: absolute;
  top: 38%;
  left: 50%;
  display: grid;
  gap: 3px;
  justify-items: center;
  transform: translateX(-50%);
  animation: promote-key 0.72s ease both;
}

.promoted-key small {
  color: var(--studio-muted);
  font-size: 9px;
  font-weight: 900;
}

.promoted-key b {
  display: grid;
  width: 42px;
  height: 36px;
  place-items: center;
  color: var(--navy);
  background: var(--yellow);
  border-radius: 4px;
  font-family: var(--font-code);
}

.heap-scene {
  position: relative;
  display: grid;
  grid-template-rows: minmax(290px, 1fr) auto;
  gap: 16px;
  width: min(100%, 860px);
  min-height: 430px;
  padding: 52px 10px 10px;
}

.heap-tree {
  position: relative;
  min-height: 290px;
}

.heap-tree svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.heap-tree line {
  stroke: var(--studio-edge);
  stroke-width: 1.4;
}

.heap-swap-path {
  fill: none;
  stroke: var(--yellow);
  stroke-width: 2.2;
  stroke-dasharray: 4 3;
  animation: pointer-flow 0.7s linear infinite;
}

.heap-node {
  position: absolute;
  display: grid;
  width: clamp(42px, 6vw, 58px);
  height: clamp(42px, 6vw, 58px);
  place-items: center;
  color: var(--studio-ink);
  background: var(--studio-panel);
  border: 2px solid var(--studio-node-line);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  transition: transform 0.3s ease, background 0.3s ease, border-color 0.3s ease;
}

.heap-node small {
  position: absolute;
  top: -16px;
  color: var(--studio-muted);
  font-family: var(--font-code);
  font-size: 9px;
}

.heap-node b {
  font-family: var(--font-code);
  font-size: 15px;
}

.heap-node.is-compare {
  color: var(--navy);
  background: var(--orange);
  border-color: var(--orange);
}

.heap-node.is-active {
  color: var(--navy);
  background: var(--yellow);
  border-color: var(--yellow);
  box-shadow: 0 0 0 10px var(--studio-yellow-soft);
  transform: translate(-50%, -50%) scale(1.1);
}

.heap-array {
  display: flex;
  gap: 6px;
  align-items: end;
  justify-content: center;
  min-width: 0;
  transform: translateX(35px);
}

.heap-array > span:first-child {
  display: none;
}

.heap-array-cell {
  position: relative;
  display: grid;
  width: clamp(38px, 6vw, 54px);
  height: 48px;
  place-items: center;
  color: var(--studio-ink);
  background: var(--studio-panel);
  border: 1px solid var(--studio-panel-line);
  border-radius: 4px;
  transition: transform 0.3s ease, background 0.3s ease, opacity 0.3s ease;
}

.heap-array-cell small {
  position: absolute;
  bottom: -17px;
  color: var(--studio-muted);
  font-family: var(--font-code);
  font-size: 9px;
}

.heap-array-cell b {
  font-family: var(--font-code);
  font-size: 14px;
}

.heap-array-cell.is-compare {
  color: var(--navy);
  background: var(--orange);
  border-color: var(--orange);
}

.heap-array-cell.is-active {
  color: var(--navy);
  background: var(--yellow);
  border-color: var(--yellow);
  transform: translateY(-8px);
}

.heap-array-cell.is-done {
  color: var(--studio-strong);
  background: var(--green);
  border-color: var(--green);
}

.heap-array-cell.is-outside {
  opacity: 0.3;
}

.heap-empty {
  position: absolute;
  top: 50%;
  left: 50%;
  color: var(--green);
  font-family: var(--font-display);
  transform: translate(-50%, -50%);
}

.graph-scene {
  position: relative;
  width: min(100%, 760px);
  height: min(60vh, 490px);
  min-height: 310px;
}

.graph-canvas {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 0;
}

.graph-canvas svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  color: var(--studio-edge);
}

.graph-scene.has-distance-table {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 180px;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 12px 18px;
  width: min(100%, 900px);
  height: min(63vh, 520px);
  min-height: 390px;
}

.graph-scene.has-distance-table .graph-canvas {
  grid-column: 1;
  grid-row: 1;
}

.distance-panel {
  display: grid;
  grid-column: 2;
  grid-row: 1;
  gap: 10px;
  align-self: center;
  transform: translateY(48px);
}

.distance-table {
  display: grid;
  overflow: hidden;
  background: var(--studio-panel-soft);
  border: 1px solid var(--studio-panel-line);
  border-radius: 5px;
}

.distance-table__head,
.distance-table__row {
  display: grid;
  grid-template-columns: 34px minmax(44px, 1fr) minmax(42px, 1fr);
  align-items: center;
  min-height: 30px;
  padding: 0 8px;
  text-align: center;
}

.distance-table__head {
  color: var(--studio-muted);
  background: var(--studio-control);
  font-size: 9px;
  font-weight: 900;
}

.distance-table__row {
  color: var(--studio-copy);
  border-top: 1px solid var(--studio-rule);
  font-family: var(--font-code);
  font-size: 11px;
  transition: background 0.3s ease, color 0.3s ease;
}

.distance-table__row strong {
  color: var(--studio-strong);
  font-size: 14px;
}

.distance-table__row.is-settled {
  background: var(--studio-green-soft);
}

.distance-table__row.is-current {
  color: var(--navy);
  background: var(--yellow);
}

.distance-table__row.is-current strong {
  color: var(--navy);
}

.distance-table__row.is-updated {
  color: var(--studio-strong);
  background: var(--green);
}

.distance-table__row.is-rejected {
  color: var(--studio-strong);
  background: var(--studio-red-soft);
  box-shadow: inset 3px 0 var(--red);
}

.relaxation-formula {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  min-height: 54px;
  padding: 8px 12px;
  color: var(--studio-copy);
  background: var(--studio-panel-soft);
  border-left: 3px solid var(--green);
  border-radius: 4px;
}

.relaxation-formula span,
.relaxation-formula b {
  grid-row: 2;
  font-size: 10px;
  font-weight: 900;
}

.relaxation-formula span {
  grid-column: 1;
}

.relaxation-formula b {
  grid-column: 2;
}

.relaxation-formula code {
  grid-row: 1;
  grid-column: 1 / -1;
  overflow: hidden;
  color: var(--yellow);
  font-family: var(--font-code);
  font-size: 13px;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.relaxation-formula.is-rejected {
  border-color: var(--red);
}

.relaxation-formula.is-rejected b {
  color: var(--red);
}

.relaxation-formula.is-updated b {
  color: var(--green);
}

.graph-edge {
  stroke: var(--studio-edge);
  stroke-width: 1.3;
  transition: stroke 0.28s ease, stroke-width 0.28s ease;
}

.graph-edge.is-active {
  stroke: var(--yellow);
  stroke-width: 3;
  animation: edge-flow 0.62s ease both;
}

.graph-edge.is-selected {
  stroke: var(--green);
  stroke-width: 2.4;
}

.graph-edge.is-rejected {
  stroke: var(--red);
  stroke-width: 2;
  stroke-dasharray: 4 4;
  opacity: 0.55;
}

.edge-label {
  fill: var(--studio-label);
  font-family: var(--font-ui);
  font-size: 4px;
  font-weight: 800;
}

.graph-node {
  position: absolute;
  display: grid;
  width: clamp(40px, 7vw, 62px);
  height: clamp(40px, 7vw, 62px);
  place-items: center;
  color: var(--studio-ink);
  background: var(--studio-panel);
  border: 2px solid var(--studio-node-line);
  border-radius: 50%;
  font-size: clamp(14px, 2vw, 18px);
  font-weight: 900;
  transform: translate(-50%, -50%);
  transition: background 0.3s ease, border-color 0.3s ease, transform 0.3s ease, color 0.3s ease;
}

.graph-node.is-current {
  color: var(--navy);
  background: var(--yellow);
  border-color: var(--yellow);
  transform: translate(-50%, -50%) scale(1.14);
  animation: node-pulse 0.68s ease both;
}

.graph-node.is-visited {
  color: var(--studio-strong);
  background: var(--blue);
  border-color: var(--studio-sky);
}

.graph-node.is-visited.is-current {
  color: var(--navy);
  background: var(--yellow);
  border-color: var(--yellow);
}

.graph-node.is-frontier {
  color: var(--navy);
  background: var(--cyan);
  border-color: var(--cyan);
}

.graph-node.is-muted {
  opacity: 0.35;
}

.graph-node.is-red {
  color: var(--studio-strong);
  background: var(--red);
  border-color: var(--red);
}

.graph-node.is-black {
  color: var(--studio-strong);
  background: var(--navy);
  border-color: var(--studio-muted);
}

.graph-node.is-current.is-red,
.graph-node.is-current.is-black {
  box-shadow: 0 0 0 10px var(--studio-yellow-soft);
}

.edge-traveler {
  fill: var(--yellow);
  filter: drop-shadow(0 0 3px var(--yellow));
}

.frontier-tray {
  position: absolute;
  right: auto;
  bottom: 0;
  left: 50%;
  display: flex;
  gap: 6px;
  align-items: center;
  max-width: calc(100% - 40px);
  padding: 8px 10px;
  background: var(--studio-panel-soft);
  border-bottom: 2px solid var(--studio-sky);
  transform: translateX(-50%);
}

.frontier-tray span {
  margin-right: 4px;
  color: var(--studio-muted);
  font-size: 9px;
  font-weight: 900;
}

.frontier-tray b {
  display: grid;
  width: 26px;
  height: 26px;
  place-items: center;
  color: var(--navy);
  background: var(--studio-sky);
  border-radius: 50%;
  font-family: var(--font-code);
  font-size: 11px;
}

.graph-node.is-motion-landing {
  opacity: 0;
}

.node-motion-layer {
  position: absolute;
  inset: 0;
  z-index: 6;
  pointer-events: none;
}

.node-ghost {
  position: absolute;
  top: var(--ghost-top);
  left: var(--ghost-left);
  display: grid;
  width: var(--ghost-width);
  height: var(--ghost-height);
  place-items: center;
  color: var(--navy);
  background: var(--yellow);
  border: 2px solid var(--yellow);
  border-radius: 50%;
  font-family: var(--font-code);
  font-weight: 900;
  box-shadow: 0 0 0 12px var(--studio-yellow-soft);
  transform: translate3d(0, 0, 0);
  transition: transform 0.7s cubic-bezier(0.5, 0, 0.15, 1);
}

.node-ghost.is-moving {
  transform: translate3d(var(--move-x), var(--move-y), 0);
}

@keyframes stage-in {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; }
}

@keyframes pointer-flow {
  to { stroke-dashoffset: -18; }
}

@keyframes stack-push {
  from { opacity: 0; transform: translateY(-80px) scale(0.8); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes stack-pop {
  0% { opacity: 0; transform: translate(90px, 120px); }
  55% { opacity: 1; transform: translate(0, 0); }
  100% { opacity: 0.75; transform: translateY(-25px); }
}

@keyframes compare-pulse {
  50% { box-shadow: 0 0 0 14px var(--studio-yellow-soft); transform: scale(1.08); }
}

@keyframes queue-enter {
  from { opacity: 0; transform: translate(40px, -35px) scale(0.6); }
  to { opacity: 1; transform: translate(0, 0) scale(1); }
}

@keyframes queue-wrap {
  0% { box-shadow: 0 0 0 0 var(--studio-yellow-soft); }
  50% { box-shadow: 0 0 0 18px var(--studio-yellow-soft); transform: translate(-50%, -50%) scale(1.18); }
  100% { box-shadow: 0 0 0 9px var(--studio-yellow-soft); }
}

@keyframes mismatch-shake {
  25% { transform: rotate(var(--beam-angle)) translateY(-3px); }
  75% { transform: rotate(var(--beam-angle)) translateY(3px); }
}

@keyframes kmp-jump {
  from { opacity: 0; transform: translateX(-12px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes edge-flow {
  from { stroke-dasharray: 2 4; stroke-dashoffset: 12; opacity: 0.3; }
  to { stroke-dasharray: 0; stroke-dashoffset: 0; opacity: 1; }
}

@keyframes node-pulse {
  50% { box-shadow: 0 0 0 12px var(--studio-yellow-soft); }
}

@keyframes matrix-pulse {
  50% { transform: scale(1.12); box-shadow: 0 0 0 9px var(--studio-yellow-soft); }
}

@keyframes bucket-drop {
  from { opacity: 0; transform: translateY(-70px) scale(0.75); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes collect-rise {
  from { opacity: 0; transform: translateY(45px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes promote-key {
  from { opacity: 0; transform: translate(-50%, 70px) scale(0.8); }
  to { opacity: 1; transform: translate(-50%, 0) scale(1); }
}

@media (max-width: 900px) {
  .library-intro {
    grid-template-columns: 1fr;
    gap: 20px;
  }

  .library-intro > p {
    max-width: 520px;
    margin: 0;
  }

  .algorithm-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .studio-body {
    min-height: 0;
  }

  .canvas-wrap {
    padding: 24px;
  }

  .stage-hud {
    inset: 24px;
  }

  .code-panel {
    width: min(340px, 42vw);
  }

  .variables-panel {
    width: min(280px, 34vw);
  }

  .step-note {
    width: min(420px, 52%);
  }

  .invariant-panel {
    width: min(320px, 38%);
  }
}

@media (max-width: 640px) {
  .studio-view > *,
  .studio-header,
  .studio-body,
  .canvas-wrap,
  .visual-stage,
  .studio-controls {
    width: 100%;
    min-width: 0;
  }

  .studio-body {
    overflow: hidden;
  }

  .library-view {
    width: min(100% - 32px, 1240px);
    padding-top: 16px;
  }

  .library-header {
    padding-bottom: 20px;
  }

  .library-intro {
    padding: 46px 0 32px;
  }

  .library-intro h1 {
    font-size: clamp(40px, 13vw, 60px);
  }

  .library-intro > p {
    font-size: 14px;
  }

  .algorithm-grid {
    grid-template-columns: 1fr;
  }

  .algorithm-card {
    min-height: 214px;
  }

  .studio-header {
    grid-template-columns: auto minmax(0, 1fr);
    gap: 12px;
    padding: 14px 16px;
  }

  .studio-header__tools {
    grid-column: 2;
    grid-row: 2;
    gap: 12px;
    justify-content: space-between;
    min-width: 0;
  }

  .try-data-button {
    min-height: 32px;
    padding: 0 10px;
  }

  .complexity {
    grid-column: auto;
    min-width: 0;
    flex-wrap: wrap;
    justify-content: flex-start;
    gap: 12px;
  }

  .canvas-wrap {
    display: block;
    height: 100%;
    max-height: 100%;
    min-height: 0;
    padding: 16px 16px 32px;
    overflow-y: auto;
    scroll-padding-bottom: 24px;
  }

  .visual-stage {
    min-height: 330px;
    overflow-x: auto;
  }

  .stage-hud {
    position: static;
    display: grid;
    gap: 14px;
    margin-top: 2px;
    pointer-events: auto;
  }

  .stage-hud > section,
  .variables-panel,
  .step-note,
  .invariant-panel,
  .quiz-panel {
    position: static;
    width: auto;
    padding: 14px 0 0;
    border-top: 1px solid var(--studio-rule);
    border-left: 0;
    transform: none;
  }

  .code-panel {
    width: auto;
    text-align: left;
  }

  .code-panel code {
    font-size: 12px;
  }

  .variable-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .canvas-meta {
    top: 16px;
    left: 16px;
  }

  .canvas-meta span:last-child {
    font-size: 16px;
  }

  .step-note {
    display: block;
  }

  .custom-data-panel {
    position: fixed;
    right: 12px;
    bottom: 12px;
    left: 12px;
    width: auto;
    max-height: min(520px, calc(100dvh - 24px));
    overflow-y: auto;
  }

  .step-note__index {
    display: block;
  }

  .step-note p {
    margin: 7px 0 0;
    font-size: 15px;
    line-height: 1.55;
  }

  .invariant-panel p {
    font-size: 14px;
  }

  .quiz-panel {
    padding: 16px;
  }

  .studio-controls {
    padding: 12px 16px max(16px, env(safe-area-inset-bottom));
  }

  .control-row {
    gap: 8px;
  }

  .speed-control {
    display: none;
  }

  .control-button {
    width: 48px;
    height: 48px;
  }

  .control-button--text {
    width: auto;
    padding: 0 12px;
  }

  .play-button {
    width: 62px;
    height: 62px;
  }

  .linked-scene {
    height: 290px;
    min-width: max(100%, calc(var(--linked-count) * 82px));
  }

  .linked-node {
    grid-template-columns: minmax(35px, 1fr) 23px;
    width: 66px;
    min-height: 50px;
  }

  .linked-pointer {
    top: calc(-34px - var(--pointer-order) * 20px);
    font-size: 9px;
  }

  .stack-scene {
    grid-template-columns: 1fr;
    gap: 28px;
    min-height: 560px;
    padding-top: 40px;
  }

  .stack-input {
    overflow-x: auto;
  }

  .stack-input > div {
    width: max-content;
  }

  .stack-workbench {
    grid-template-columns: 76px 132px;
  }

  .stack-vessel {
    min-height: 260px;
  }

  .stack-items {
    min-height: 200px;
  }

  .queue-scene {
    width: min(86vw, 330px);
  }

  .queue-slot {
    width: 50px;
    height: 50px;
  }

  .queue-center strong {
    font-size: 15px;
  }

  .queue-center code {
    font-size: 8px;
  }

  .array-scene {
    gap: 6px;
    min-height: 230px;
    padding-right: 4px;
    padding-left: 4px;
  }

  .array-item {
    width: clamp(30px, 10vw, 44px);
  }

  .array-pivot-token {
    top: 8px;
    right: 4px;
    left: auto;
    padding: 5px 7px;
  }

  .array-pivot-token b {
    font-size: 16px;
  }

  .string-scene {
    gap: 18px;
    min-width: 0;
    padding-right: 0;
    padding-left: 0;
  }

  .string-board {
    gap: 24px;
    padding-left: 38px;
  }

  .string-track {
    gap: 3px;
  }

  .string-cell {
    width: 26px;
    height: 38px;
  }

  .prefix-table i {
    width: 31px;
  }

  .kmp-jump-path {
    flex-wrap: wrap;
    gap: 6px;
  }

  .kmp-jump-path small {
    flex-basis: 100%;
    text-align: center;
  }

  .matrix-scene {
    width: 100%;
    min-height: 320px;
    padding: 48px 0 12px;
  }

  .matrix-formula {
    gap: 8px;
    align-items: flex-start;
    flex-direction: column;
    justify-self: start;
    padding-left: 4px;
  }

  .matrix-formula code {
    font-size: 9px;
  }

  .matrix-grid {
    grid-template-columns: 26px repeat(var(--matrix-size), minmax(42px, 52px));
    grid-template-rows: 26px repeat(var(--matrix-size), 44px);
    gap: 3px;
  }

  .matrix-cell {
    font-size: 13px;
  }

  .bucket-scene {
    width: 100%;
    min-width: 0;
    min-height: 300px;
    padding: 28px 0 10px;
    transform: none;
  }

  .bucket-source {
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 8px;
  }

  .bucket-source > div {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 4px;
  }

  .bucket-source > div span {
    min-width: 0;
    height: 28px;
    padding: 0 2px;
    font-size: 10px;
  }

  .radix-buckets {
    grid-template-columns: repeat(10, minmax(0, 1fr));
    gap: 3px;
  }

  .radix-bucket {
    min-height: 145px;
    padding: 12px 1px 20px;
  }

  .radix-bucket b {
    min-height: 26px;
    font-size: 9px;
  }

  .multiway-scene {
    width: 100%;
    min-width: 350px;
    height: 320px;
  }

  .multiway-node {
    min-width: 54px;
    min-height: 44px;
  }

  .multiway-node b {
    min-width: 42px;
    padding: 0 6px;
    font-size: 13px;
  }

  .frontier-tray {
    bottom: 4px;
    left: 50%;
  }

  .graph-scene {
    height: 42vh;
    min-height: 260px;
  }

  .graph-scene.has-distance-table {
    grid-template-columns: 1fr;
    grid-template-rows: 280px auto;
    gap: 10px;
    width: 100%;
    height: auto;
    min-height: 540px;
  }

  .graph-scene.has-distance-table .graph-canvas {
    grid-column: 1;
    grid-row: 1;
  }

  .graph-canvas > .motion-tag {
    right: 2px;
    left: auto;
  }

  .distance-panel {
    grid-column: 1;
    grid-row: 2;
    gap: 8px;
    width: 100%;
    transform: none;
  }

  .distance-table__head,
  .distance-table__row {
    min-height: 30px;
  }

  .relaxation-formula code { text-align: left; }

  .heap-scene {
    grid-template-rows: minmax(250px, 1fr) auto;
    gap: 10px;
    width: 100%;
    min-height: 400px;
    padding: 46px 0 24px;
  }

  .heap-tree {
    min-height: 250px;
  }

  .heap-scene > .motion-tag {
    top: 8px;
    right: 2px;
    left: auto;
  }

  .heap-node {
    width: 40px;
    height: 40px;
  }

  .heap-array {
    gap: 3px;
    transform: none;
  }

  .heap-array > span:first-child {
    display: none;
  }

  .heap-array-cell {
    width: min(13vw, 44px);
    height: 42px;
  }

  .motion-tag {
    top: 8px;
    left: 2px;
  }

  .array-pointer {
    top: calc(-33px - var(--pointer-order, 0) * 17px);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
