/* =========================================================
   数据结构与算法 · 动画演示  |  app.css

   视觉语言对齐 yangyi 个人主站（personal-site/web/src/styles/base.css）：
   暖奶油纸底 + 琥珀渐变 + 胶囊按钮 + 大圆角卡片 + 柔光阴影 + 大字号粗标题。

   ⚠️ 这不是"随手抄几个颜色"。两边的令牌取同一套值：
      --brand-1/--brand-2/--grad、--ink/--sub/--mut、--cream/--cream-2/--line/--card、
      --shadow/--glow、--radius/--r-sm、--font/--mono、--ease
   主站的规矩是：底色不暗、强调色干净、不用光斑和玻璃拟态、动效克制。
   这一页将来要作为作品放进主站，所以不放任它自己长成另一种风格。

   语义色（比较 / 移动 / 已就位）另外一组，因为演示需要区分状态；
   用的是主站体系里本来就有的暖琥珀 + 产品页那个蓝，不引入第三种陌生色。
   ========================================================= */

:root {
  /* —— 与主站同源的令牌 —— */
  --brand-1: #E0912F;
  --brand-2: #B45309;
  --brand: #C96A10;
  --grad: linear-gradient(120deg, var(--brand-1), var(--brand-2));

  --ink: #1F2329;
  --sub: #646A73;
  --mut: #8F959E;

  --cream: #FEFDFB;
  --cream-2: #F8F5F0;
  --line: #E9E3DA;
  --card: #FFFFFF;

  --shadow: 0 16px 40px rgba(62, 52, 42, .07);
  --shadow-lg: 0 30px 70px rgba(62, 52, 42, .11);
  --glow: 0 8px 18px rgba(180, 83, 9, .16);

  --radius: 24px;
  --r-sm: 9px;

  --font: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --ease: cubic-bezier(.2, .8, .2, 1);

  /* —— 视图里用到的旧变量名，映射到上面这套 ——
     视图文件（views/*.js）通过 var(--ink-2) 之类取色，改这里就整体生效，
     不用去五个视图里逐个替换，也避免漏改。 */
  --bg: var(--cream);
  --panel: var(--card);
  --ink-2: var(--sub);
  --ink-3: var(--mut);

  /* —— 演示语义色 —— */
  /* 静默态用暖灰，动作态用琥珀，比较态用那个蓝（高考产品页同色），已就位压暗一档 */
  --viz-idle: #F1E9DC;
  --viz-idle-edge: #DFD2BC;
  --viz-done: #C9B79B;
  --viz-done-edge: #B3A184;
  --viz-compare: #E4EDFA;
  --viz-compare-edge: #3E7FD9;
  --viz-move: #FBE2C8;
  --viz-move-edge: #C96A10;
  --viz-focus: #B45309;

  /* —— 补上被引用却从没定义过的三个变量 ——
     var() 解析失败不会报错，直接回落到默认黑；
     亮色下是"黑字"，看着正常，夜灯下就成了隐形字。 */
  --accent: var(--brand-2);   /* 图上的距离、链表上的标记数字 */
  --swap: #C2410C;            /* 失衡 / 需要交换这类警示 */
  --sans: var(--font);

  /* —— 结构色：这些原本散在样式里写死，深色模式一来就全露馅 ——
     提成令牌之后，只改这一组就能整体换肤。 */
  --topbar-bg: rgba(254, 253, 251, .82);
  --sun-layer: linear-gradient(180deg, rgba(245, 165, 36, .06), rgba(254, 253, 251, 0));
  --btn-shadow: 0 8px 18px rgba(62, 52, 42, .10);
  --btn-shadow-hot: 0 20px 36px rgba(240, 135, 10, .38);
  --knob-shadow: 0 3px 8px rgba(180, 83, 9, .3);
  --on-brand: #FFFFFF;
  --code-lineno: #C9BFB0;
  --code-line-bg: #FBEFD9;
  --axis: #DDD1BC;
  --axis-strong: #CBBFA9;
  --node-idle-fill: #F1EADC;
  --cell-bg: #FCFAF6;
  --cell-line: #EFE9E0;
  --cell-compare-fill: #F1F6FC;
  --cell-compare-line: #A7C4E8;
  --frontier-fill: #FAF3E7;
  --frontier-line: #D3BD97;
  --edge-rejected: #E2D8C6;
  --board-line: #E7E0D5;
  --water-fill: #E6DDCC;
  --water-line: #DCD1BC;
  --peg-fill: #D9CEB8;
  --disk-fill: #F6E7CE;

  color-scheme: light;
}

/* =========================================================
   夜灯模式
   ---------------------------------------------------------
   配色照搬主站 personal-site/web/src/styles/base.css 的深色令牌：
   底色用**深蓝**而不是纯黑（纯黑显浑，蓝调有空气感），
   琥珀在夜里提亮一档，因为它要和蓝底形成互补的"一盏暖灯"。

   这里额外多一层：演示用的语义色（静默 / 比较 / 移动 / 已就位）
   在深色底下必须整组重配，直接沿用白天的浅色会把柱子糊成一片。
   ========================================================= */
html[data-theme="dark"] {
  /* 底色再压深一档，把面板和画布拉开层次。
     上一版页面 #0D1424、卡片 #18223A —— 两层只差 3% 亮度，
     柱子又用 #24304A，等于深蓝压深蓝，整页糊成一片。 */
  --cream: #080E1B;
  --cream-2: #121A2C;
  --card: #172032;
  --line: #33415F;

  --ink: #F5F8FC;
  --sub: #D2DBEA;          /* 正文：11px 等宽字在深底上必须更亮 */
  --mut: #A2AFC6;          /* 次要文字：原来 #74829C 基本看不见 */

  --brand-1: #FFC478;
  --brand-2: #FF9A2E;
  --brand: #FFAE47;
  --grad: linear-gradient(120deg, var(--brand-1), var(--brand-2));

  --shadow: 0 16px 40px rgba(0, 0, 0, .55);
  --shadow-lg: 0 30px 70px rgba(0, 0, 0, .65);
  --glow: 0 8px 26px rgba(255, 154, 46, .3);

  /* —— 演示语义色：这一组是"看不见"的元凶，必须整体抬亮 ——
     静默柱要能一眼看出形状，比较态要跳出来，已就位要退后但不消失。 */
  --viz-idle: #4A6295;
  --viz-idle-edge: #6680B8;
  --viz-done: #6B7FA8;
  --viz-done-edge: #8FA2C8;
  --viz-compare: #2B4E80;
  --viz-compare-edge: #9CC6FA;
  --viz-move: rgba(255, 174, 71, .4);
  --viz-move-edge: #FFC478;
  --viz-focus: #FFC478;
  --accent: var(--brand-1);
  --swap: #FF9E7A;            /* 夜灯下用暖橙红，压得住深蓝底 */

  --topbar-bg: rgba(10, 16, 32, .88);
  --sun-layer: linear-gradient(180deg, rgba(255, 174, 71, .10), rgba(10, 16, 32, 0));
  --btn-shadow: 0 8px 18px rgba(0, 0, 0, .5);
  --btn-shadow-hot: 0 20px 36px rgba(255, 154, 46, .3);
  --knob-shadow: 0 3px 8px rgba(0, 0, 0, .55);
  --on-brand: #0A1020;
  --code-lineno: #7A89A8;
  --code-line-bg: rgba(255, 174, 71, .18);
  --axis: #3A4A6E;
  --axis-strong: #4E6088;
  --node-idle-fill: #33425F;
  --cell-bg: #212D45;
  --cell-line: #3A4967;
  --cell-compare-fill: #21406B;
  --cell-compare-line: #5A88C4;
  --frontier-fill: #3A2E18;
  --frontier-line: #8A6D3A;
  --edge-rejected: #3A4763;
  --board-line: #35435F;
  --water-fill: #0F1728;
  --water-line: #2A3A58;
  --peg-fill: #4C5C7C;
  --disk-fill: #33405E;

  color-scheme: dark;
}

/* 深色下画布比卡片再暗一档，柱子才立得起来 */
html[data-theme="dark"] .canvas-wrap {
  background: #0F1626;
}

/* 深色下给面板补一圈描边：光靠填充区分不开"页面"和"卡片" */
html[data-theme="dark"] .canvas-wrap,
html[data-theme="dark"] #code,
html[data-theme="dark"] .stat,
html[data-theme="dark"] .note,
html[data-theme="dark"] .algo-card {
  border-color: var(--line);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--cream);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
}

/* 一层常驻日光：极淡的暖色光晕压在最上面，模拟纸面被打亮的层次。
   不用 blur 光斑（主站明确否过"雾霾感"），这里只是一段线性渐变。 */
body::before {
  content: "";
  position: fixed;
  inset: 0 0 auto 0;
  height: 420px;
  background: var(--sun-layer);
  pointer-events: none;
  z-index: 0;
}

/* ── 顶栏 ───────────────────────────────────────────────── */

.topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  width: 100%;
}

.topbar-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
}

/* 圆形图标按钮：GitHub 链接和日夜切换同款，别让它们在顶栏里各长各的 */
.icon-btn,
.icon-link {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 1.5px solid var(--line);
  border-radius: 50%;
  background: var(--card);
  color: var(--sub);
  cursor: pointer;
  text-decoration: none;
  transition: color .22s var(--ease), border-color .22s var(--ease),
    transform .22s var(--ease), box-shadow .22s var(--ease);
}

.icon-btn:hover,
.icon-link:hover {
  color: var(--brand-2);
  border-color: var(--brand-1);
  transform: translateY(-1px);
  box-shadow: var(--btn-shadow);
}

.icon-btn svg,
.icon-link svg {
  width: 19px;
  height: 19px;
}

.topbar {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  padding: 20px 34px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--topbar-bg);
  backdrop-filter: saturate(1.1) blur(6px);
}

.back-home {
  display: inline-block;
  margin-bottom: 6px;
  font-size: 13px;
  color: var(--mut);
  text-decoration: none;
  transition: color .2s var(--ease), transform .2s var(--ease);
}

.back-home:hover {
  color: var(--brand-2);
  transform: translateX(-2px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* 标志：纸 + 灯，取自主站 SiteNav 的 mark。
   尺寸给到 26px——20px 时灯和纸的边界会糊在一起。 */
.brand .mark {
  width: 26px;
  height: 26px;
  flex: none;
  overflow: visible;
  color: var(--ink);
}

/* 悬停时那盏灯亮一下，和主站一致 */
.brand .mark circle {
  transition: r .22s var(--ease);
}

.brand:hover .mark circle {
  r: 4.6;
}

.brand h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: -.01em;
}

.badge {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--brand-2);
  border: 1.5px solid var(--line);
  border-radius: 999px;
  padding: 2px 12px;
  background: var(--card);
}

.lede {
  margin: 0;
  max-width: 74ch;
  color: var(--sub);
  font-size: 13.5px;
}

.lede code {
  font-family: var(--mono);
  font-size: 12.5px;
  background: var(--cream-2);
  padding: 1px 6px;
  border-radius: 6px;
  color: var(--brand-2);
}

/* ── 三栏布局 ───────────────────────────────────────────── */

.layout {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 214px minmax(0, 1fr) 420px;
  align-items: stretch;
  min-height: calc(100vh - 132px);
}

/* 目录 */

.sidebar {
  padding: 22px 14px 40px;
  overflow-y: auto;
  max-height: calc(100vh - 132px);
  position: sticky;
  top: 0;
  align-self: start;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.navlist {
  display: flex;
  flex-direction: column;
}

.nav-filter-wrap {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 0 6px 10px;
  background: var(--cream);
}

#nav-filter {
  width: 100%;
  box-sizing: border-box;
  font: inherit;
  font-size: 13px;
  padding: 8px 11px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  color: var(--ink);
  outline: none;
  transition: border-color .2s var(--ease), box-shadow .2s var(--ease);
}

#nav-filter::placeholder {
  color: var(--mut);
}

#nav-filter:focus {
  border-color: var(--brand-1);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand-1) 22%, transparent);
}

.nav-count {
  margin: 6px 2px 0;
  font-size: 11.5px;
  color: var(--mut);
  min-height: 1.2em;
}

.nav-group {
  margin-bottom: 14px;
}

/* 组头是按钮：整行可点，右边小三角表示折叠状态 */
.nav-group-head {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  margin: 0 0 6px;
  padding: 6px 10px;
  font: inherit;
  font-size: 12.5px;
  font-weight: 800;
  color: var(--brand-2);
  letter-spacing: .02em;
  background: none;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  text-align: left;
  transition: background .18s var(--ease);
}

.nav-group-head:hover {
  background: var(--cream-2);
}

.nav-group-name { flex: 1; }

/* 组里有多少条：收起来时也知道这组多大 */
.nav-group-n {
  font-size: 11px;
  font-weight: 600;
  color: var(--mut);
  font-variant-numeric: tabular-nums;
}

.nav-caret {
  font-size: 11px;
  color: var(--sub);
  line-height: 1;
  transition: transform .22s var(--ease);
}

.nav-group.is-collapsed .nav-caret {
  transform: rotate(-90deg);
}

/* 用 !important 挡住窄屏那条 .nav-group{margin-bottom:0} 之外的可能覆盖；
   实际只需要这一条 display */
.nav-group.is-collapsed .nav-group-body {
  display: none;
}

.nav-item {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: none;
  font: inherit;
  font-size: 13.5px;
  color: var(--sub);
  padding: 7px 10px;
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: background .2s var(--ease), color .2s var(--ease), transform .2s var(--ease);
}

.nav-item:hover {
  background: var(--cream-2);
  color: var(--ink);
}

.nav-item[aria-current="true"] {
  background: var(--card);
  color: var(--brand-2);
  font-weight: 700;
  box-shadow: var(--shadow);
  transform: translateX(2px);
}

/* 主区 */

.stage {
  padding: 26px 30px 48px;
  min-width: 0;
  animation: rise .45s var(--ease) both;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: none;
  }
}

.stage-head h2 {
  margin: 0;
  font-size: 21px;
  font-weight: 800;
  letter-spacing: -.015em;
}

#brief {
  margin: 8px 0 0;
  color: var(--sub);
  font-size: 14px;
  max-width: 66ch;
}

.facts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 14px 0 0;
  font-size: 12.5px;
}

.facts div {
  display: flex;
  gap: 6px;
  align-items: baseline;
  background: var(--cream-2);
  border-radius: 999px;
  padding: 3px 12px;
}

.facts dt {
  color: var(--mut);
}

.facts dd {
  margin: 0;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 600;
  color: var(--brand-2);
}

.canvas-wrap {
  margin-top: 18px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 10px;
}

#view {
  display: block;
  width: 100%;
  height: auto;
}

/* 控件 */

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px 22px;
  margin-top: 16px;
}

.transport {
  display: flex;
  gap: 6px;
}

.transport button {
  font: inherit;
  font-size: 13px;
  line-height: 1;
  min-width: 38px;
  height: 36px;
  padding: 0 12px;
  border: 1.5px solid var(--line);
  background: var(--card);
  color: var(--sub);
  border-radius: 999px;
  cursor: pointer;
  transition: transform .2s var(--ease), box-shadow .2s var(--ease), color .2s;
}

.transport button:hover:not(:disabled) {
  color: var(--brand-2);
  transform: translateY(-2px);
  box-shadow: var(--btn-shadow);
}

.transport button.primary {
  background: var(--grad);
  border: none;
  color: var(--on-brand);
  min-width: 54px;
  box-shadow: var(--glow);
}

.transport button.primary:hover {
  box-shadow: var(--btn-shadow-hot);
}

.transport button:disabled {
  opacity: .4;
  cursor: default;
}

.scrub {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1 1 240px;
  min-width: 200px;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  height: 5px;
  border-radius: 3px;
  background: var(--line);
  outline: none;
  flex: 1;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--brand);
  box-shadow: var(--knob-shadow);
  cursor: pointer;
}

output {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--mut);
  min-width: 64px;
  text-align: right;
}

.speed {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12.5px;
  color: var(--mut);
}

.speed input[type="range"] {
  width: 92px;
  flex: none;
}

.note {
  margin: 16px 0 0;
  min-height: 46px;
  padding: 12px 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  box-shadow: var(--shadow);
  font-size: 14px;
  color: var(--ink);
}

.note:empty {
  display: none;
}

/* 输入切换 */

.inputs {
  margin-top: 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.inputs-label {
  font-size: 12.5px;
  color: var(--mut);
}

#input-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

#input-buttons button {
  font: inherit;
  font-size: 12.5px;
  padding: 6px 15px;
  border: 1.5px solid var(--line);
  background: var(--card);
  color: var(--sub);
  border-radius: 999px;
  cursor: pointer;
  transition: transform .2s var(--ease), box-shadow .2s var(--ease), color .2s;
}

#input-buttons button:hover {
  color: var(--brand-2);
  transform: translateY(-2px);
  box-shadow: var(--btn-shadow);
}

#input-buttons button[aria-pressed="true"] {
  background: var(--grad);
  border-color: transparent;
  color: var(--on-brand);
  box-shadow: var(--glow);
}

/* ── 代码栏 ─────────────────────────────────────────────── */

.code-pane {
  background: transparent;
  border-left: 1px solid var(--line);
  padding: 22px 20px 32px;
  font-size: 12.5px;
  overflow-y: auto;
  max-height: calc(100vh - 132px);
  position: sticky;
  top: 0;
  align-self: start;
}

.code-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 12.5px;
  font-weight: 800;
  color: var(--brand-2);
  margin-bottom: 10px;
}

.line-no {
  font-family: var(--mono);
  font-weight: 600;
  color: var(--mut);
}

#code {
  margin: 0;
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.8;
  color: var(--sub);
  background: var(--card);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  border-radius: 12px;
  padding: 12px 0;
  overflow-x: auto;
  counter-reset: ln;
}

#code .ln {
  display: block;
  white-space: pre;
  padding: 0 12px 0 0;
  counter-increment: ln;
}

#code .ln::before {
  content: counter(ln);
  display: inline-block;
  width: 26px;
  padding-right: 10px;
  text-align: right;
  color: var(--code-lineno);
  user-select: none;
}

/* 当前行：琥珀底色 + 左侧实心竖条。主站里琥珀只用在会发光的东西上，高亮行正合适。 */
#code .ln.on {
  background: var(--code-line-bg);
  box-shadow: inset 3px 0 0 var(--brand);
  color: var(--ink);
}

/* 计数器 */

.counters {
  margin-top: 18px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(84px, 1fr));
  gap: 10px;
}

.counter {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 9px 12px;
}

.counter .k {
  display: block;
  font-size: 11.5px;
  color: var(--mut);
}

.counter .v {
  font-family: var(--mono);
  font-size: 17px;
  font-weight: 700;
  color: var(--brand-2);
}

/* 图例 */

.legend {
  margin-top: 20px;
  font-size: 12.5px;
  color: var(--sub);
}

.legend summary {
  cursor: pointer;
  font-size: 12.5px;
  font-weight: 800;
  color: var(--brand-2);
}

.legend ul {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.legend li {
  display: flex;
  align-items: center;
  gap: 9px;
}

.legend .sw {
  width: 15px;
  height: 15px;
  border-radius: 4px;
  border: 1px solid var(--line);
  flex: none;
}

/* ── SVG 视图元素 ────────────────────────────────────────
   颜色只能写在 CSS 里：SVG 的 fill 属性写 var(--x) 在部分浏览器不生效。
   覆盖顺序不能乱——is-settled 在前，is-compare / is-move / is-pivot 在后，
   后写的规则优先级相同但位置靠后，才能盖住"已就位又被重新比较"的瞬时状态。 */

.bar {
  fill: var(--viz-idle);
  stroke: var(--viz-idle-edge);
  stroke-width: 1;
  transition: fill .15s linear, stroke .15s linear;
}

.bar.is-settled {
  fill: var(--viz-done);
  stroke: var(--viz-done-edge);
}

.bar.is-compare {
  fill: var(--viz-compare);
  stroke: var(--viz-compare-edge);
}

.bar.is-move {
  fill: var(--viz-move);
  stroke: var(--viz-move-edge);
}

.bar.is-pivot {
  fill: var(--viz-focus);
  stroke: var(--viz-focus);
}

.axis {
  stroke: var(--line);
}

.bracket {
  stroke: var(--axis);
}

.ptr-arrow {
  fill: var(--brand-2);
}

/* 链表 */

.node {
  fill: var(--card);
  stroke: var(--viz-idle-edge);
  stroke-width: 1.6;
}

.node.is-active {
  fill: var(--viz-compare);
  stroke: var(--viz-compare-edge);
  stroke-width: 2;
}

.node.is-moved {
  fill: var(--viz-move);
  stroke: var(--viz-move-edge);
  stroke-width: 2;
}

.node.is-removed {
  fill: var(--cream-2);
  stroke-dasharray: 4 3;
  opacity: .6;
}

.edge {
  stroke: var(--axis-strong);
  stroke-width: 1.5;
}

.edge.is-back {
  stroke: var(--viz-move-edge);
  stroke-width: 2;
}

.edge.is-tail {
  stroke: var(--axis);
}

.arrow-head {
  fill: var(--axis-strong);
}

.arrow-head-back {
  fill: var(--viz-move-edge);
}

.ptr-line {
  stroke: var(--brand-2);
  stroke-width: 1;
}

/* 树 */

.tnode {
  fill: var(--card);
  stroke: var(--viz-idle-edge);
  stroke-width: 1.7;
}

.tnode.is-active {
  fill: var(--viz-compare);
  stroke: var(--viz-compare-edge);
  stroke-width: 2.2;
}

.tnode.is-moving {
  fill: var(--viz-move);
  stroke: var(--viz-move-edge);
  stroke-width: 2.2;
}

.tnode.is-visited {
  fill: var(--node-idle-fill);
  stroke: var(--viz-done-edge);
}

.tree-edge {
  stroke: var(--axis-strong);
  stroke-width: 1.4;
}

.tree-edge.is-moving {
  stroke: var(--viz-move-edge);
  stroke-width: 2;
}

/* 堆的数组带：和树上节点共用同一套高亮语义，颜色才能对上 */

.cell {
  fill: var(--card);
  stroke: var(--viz-idle-edge);
  stroke-width: 1.3;
}

/* 未填的格子：淡底、无数字。必须写在 is-active / is-compare 之前，
   否则同权重下后面的规则会被它覆盖，正在算的格子反而显示成空白。 */
.cell.is-empty {
  fill: var(--cell-bg);
  stroke: var(--cell-line);
}

.cell.is-active {
  fill: var(--viz-compare);
  stroke: var(--viz-compare-edge);
  stroke-width: 1.9;
}

.cell.is-compare {
  fill: var(--cell-compare-fill);
  stroke: var(--cell-compare-line);
  stroke-width: 1.4;
}

.cell.is-settled {
  fill: var(--node-idle-fill);
  stroke: var(--viz-done-edge);
}

.tnode.is-compare {
  fill: var(--viz-compare);
  stroke: var(--viz-compare-edge);
  stroke-width: 2;
}

.tnode.is-settled {
  fill: var(--node-idle-fill);
  stroke: var(--viz-done-edge);
}

/* 图 */

.gnode {
  fill: var(--card);
  stroke: var(--viz-idle-edge);
  stroke-width: 1.7;
}

.gnode.is-frontier {
  fill: var(--frontier-fill);
  stroke: var(--frontier-line);
}

.gnode.is-current {
  fill: var(--viz-compare);
  stroke: var(--viz-compare-edge);
  stroke-width: 2.4;
}

.gnode.is-visited {
  fill: var(--node-idle-fill);
  stroke: var(--viz-done-edge);
}

.gedge {
  stroke: var(--axis-strong);
  stroke-width: 1.5;
}

.gedge.is-tree {
  stroke: var(--brand);
  stroke-width: 2.4;
}

.gedge.is-relax {
  stroke: var(--viz-move-edge);
  stroke-width: 2.2;
}

.gedge.is-rejected {
  stroke: var(--edge-rejected);
  stroke-dasharray: 3 3;
}

.arrow-head-on {
  fill: var(--brand);
}

.wbg {
  fill: var(--card);
}

/* ── 窄屏 ───────────────────────────────────────────────── */

@media (max-width: 1180px) {
  .layout {
    grid-template-columns: 184px minmax(0, 1fr);
  }

  .code-pane {
    grid-column: 1 / -1;
    border-left: 0;
    border-top: 1px solid var(--line);
    position: static;
    max-height: none;
  }
}

@media (max-width: 760px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    max-height: none;
    border-bottom: 1px solid var(--line);
    display: flex;
    gap: 20px;
    overflow-x: auto;
    padding: 14px 16px;
  }

  .nav-filter-wrap {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 0 6px 10px;
  background: var(--cream);
}

#nav-filter {
  width: 100%;
  box-sizing: border-box;
  font: inherit;
  font-size: 13px;
  padding: 8px 11px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  color: var(--ink);
  outline: none;
  transition: border-color .2s var(--ease), box-shadow .2s var(--ease);
}

#nav-filter::placeholder {
  color: var(--mut);
}

#nav-filter:focus {
  border-color: var(--brand-1);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand-1) 22%, transparent);
}

.nav-count {
  margin: 6px 2px 0;
  font-size: 11.5px;
  color: var(--mut);
  min-height: 1.2em;
}

.nav-group {
    margin-bottom: 0;
  }

  .nav-item {
    white-space: nowrap;
  }

  .stage {
    padding: 20px 16px 36px;
  }

  .topbar {
    padding: 18px 16px 16px;
  }
}

/* ── 嵌入模式 ?clean=1 ─────────────────────────────────── */

body.clean .topbar,
body.clean .sidebar,
body.clean .code-pane,
body.clean .inputs {
  display: none;
}

body.clean .layout {
  grid-template-columns: minmax(0, 1fr);
  min-height: auto;
}

body.clean .stage {
  padding: 20px 24px 24px;
}

body.clean .stage-head h2 {
  font-size: 18px;
}

body.clean .canvas-wrap {
  margin-top: 12px;
  padding: 6px;
}

/* ── 动效降级 ─────────────────────────────────────────────
   主站要求：所有动效在 reduce 下关闭。这一页只有进场浮现和悬停位移。 */

@media (prefers-reduced-motion: reduce) {

  .stage,
  .nav-item,
  .transport button,
  #input-buttons button,
  .bar {
    animation: none !important;
    transition: none !important;
  }

  .nav-item[aria-current="true"],
  .transport button:hover:not(:disabled),
  #input-buttons button:hover {
    transform: none;
  }
}

/* Trie 与并查集 */

.trie-terminal {
  stroke: var(--brand);
  stroke-width: 1.4;
}

.uf-box {
  fill: var(--card);
  stroke: var(--viz-idle-edge);
  stroke-width: 1.7;
}

.uf-box.is-active {
  fill: var(--viz-compare);
  stroke: var(--viz-compare-edge);
  stroke-width: 2.2;
}

.uf-box.is-moved {
  fill: var(--viz-move);
  stroke: var(--viz-move-edge);
}

.uf-edge {
  stroke: var(--axis-strong);
  stroke-width: 1.5;
}

.uf-edge.is-hot {
  stroke: var(--viz-move-edge);
  stroke-width: 2.2;
}

.uf-root-ring {
  stroke: var(--brand);
  stroke-width: 1.6;
}

/* 表格（DP 填表） */

.cell.head {
  fill: var(--cream-2);
  stroke: var(--line);
}

/* 棋盘（N 皇后） */

.cell.board {
  fill: var(--cell-bg);
  stroke: var(--board-line);
}

/* 网格里的水 */
.cell.board.is-water {
  fill: var(--water-fill);
  stroke: var(--water-line);
}

/* 汉诺塔 */

.peg {
  fill: var(--peg-fill);
}

.peg-base {
  fill: var(--axis-strong);
}

.disk {
  fill: var(--disk-fill);
  stroke: var(--viz-idle-edge);
  stroke-width: 1.2;
}

.disk.is-moved {
  fill: var(--viz-move);
  stroke: var(--viz-move-edge);
  stroke-width: 2;
}

/* 代码栏的语言切换 */

.lang-switch {
  display: flex;
  gap: 4px;
}

.lang-switch button {
  font: inherit;
  font-size: 11.5px;
  font-weight: 700;
  padding: 2px 10px;
  border: 1.5px solid var(--line);
  background: var(--card);
  color: var(--mut);
  border-radius: 999px;
  cursor: pointer;
  transition: color .2s var(--ease), background .2s var(--ease);
}

.lang-switch button[aria-pressed="true"] {
  background: var(--grad);
  border-color: transparent;
  color: var(--on-brand);
  box-shadow: var(--glow);
}

.axis.zero {
  stroke: var(--axis-strong);
}

/* ── 散点视图（AI 算法用） ─────────────────────────────── */

.scatter-dot {
  fill: var(--viz-done);
  stroke: var(--viz-done-edge);
  stroke-width: 1.4;
}

.scatter-dot.is-class-1 {
  fill: var(--viz-compare);
  stroke: var(--viz-compare-edge);
}

.scatter-dot.is-class-2 {
  fill: var(--viz-move);
  stroke: var(--viz-move-edge);
}

/* 被选中的点（最近邻、本轮分到的样本）：放大 + 琥珀描边，一眼能挑出来 */
.scatter-dot.is-hot {
  fill: var(--viz-move);
  stroke: var(--viz-move-edge);
  stroke-width: 2.6;
}

/* 质心画成空心方块，和圆形的样本点区分开 */
.scatter-centroid {
  fill: var(--card);
  stroke: var(--brand-2);
  stroke-width: 2.4;
}

/* ── 网络图视图（前向 / 反向传播） ─────────────────────── */

.nnode {
  fill: var(--card);
  stroke: var(--axis-strong);
  stroke-width: 1.8;
}

.nnode.is-active {
  fill: var(--viz-move);
  stroke: var(--viz-move-edge);
  stroke-width: 2.8;
}

.nedge {
  stroke: var(--axis);
  stroke-width: 1.4;
}

.nedge.is-active {
  stroke: var(--brand-2);
  stroke-width: 2.6;
}

/* 反向传播用蓝（和"比较"同一个语义色）：一眼分得清数据往哪边走 */
.nedge.is-back {
  stroke: var(--viz-compare-edge);
}
