:root {
  /* ===== ライトテーマ・パレット ===== */
  --bg-0: #e6ecf4;
  --bg-1: #eef3f9;
  --panel: #ffffff;
  --panel-2: #f4f7fb;
  --panel-3: #dde5ef;
  --text: #16233b;
  --muted: #54637c;
  --line: #c0ccdd;
  --accent: #0277bd;
  --accent-2: #c2740a;
  --accent-3: #7c3aed;
  --good: #15885a;
  --bad: #d6322b;
  --left: #2563eb;
  --mid: #f0a020;
  --right: #9333ea;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans",
    "Yu Gothic UI", "Segoe UI", sans-serif;
  background: radial-gradient(ellipse at top, #ffffff 0%, var(--bg-0) 70%);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
  font-size: 17px;
}

header {
  text-align: center;
  padding: 24px 16px 4px;
  position: relative;
}
header h1 {
  margin: 0;
  font-size: 34px;
  letter-spacing: 0.04em;
  background: linear-gradient(90deg, #0277bd, #c2740a);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
header .sub {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 15px;
}
.proj-toggle {
  position: absolute;
  top: 22px;
  right: 22px;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--muted);
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 15px;
}
.proj-toggle:hover { border-color: var(--accent); color: var(--text); }
body.presentation .proj-toggle {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
  font-weight: 700;
}

/* コード表示トグル（投影モードのときだけ表示） */
.code-toggle {
  position: absolute;
  top: 22px;
  right: 158px;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--muted);
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 15px;
  display: none;
}
.code-toggle:hover { border-color: var(--accent-2); color: var(--text); }
body.presentation .code-toggle { display: inline-block; }
body.presentation.show-code .code-toggle {
  background: var(--accent-2);
  color: #ffffff;
  border-color: var(--accent-2);
  font-weight: 700;
}

kbd {
  display: inline-block;
  padding: 2px 7px;
  background: #eef2f7;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 13px;
  color: var(--text);
}

/* ===== Tabs ===== */
.tabs {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin: 18px auto 0;
  max-width: 1400px;
  padding: 0 16px;
}
.tab {
  flex: 1;
  max-width: 280px;
  background: var(--panel-2);
  color: var(--muted);
  border: 1px solid var(--line);
  border-bottom: none;
  border-radius: 10px 10px 0 0;
  padding: 13px 14px;
  font-size: 18px;
  cursor: pointer;
  transition: all .15s;
}
.tab:hover { color: var(--text); }
.tab.active {
  background: var(--panel);
  color: var(--accent);
  border-color: var(--accent);
  font-weight: 700;
}

.panel {
  display: none;
  max-width: 1400px;
  margin: 0 auto 40px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 0 0 14px 14px;
  padding: 20px 22px 24px;
  box-shadow: 0 6px 24px rgba(22, 35, 59, 0.06);
}
.panel.active { display: block; }

code { font-family: ui-monospace, "SF Mono", Menlo, monospace; }

/* ===== Controls ===== */
.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
  padding: 12px 14px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  margin-bottom: 12px;
}
.controls label {
  font-size: 15px;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.controls input[type=number],
.controls input[type=text],
.controls select {
  padding: 7px 9px;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 6px;
  font-size: 16px;
  font-family: inherit;
}
.controls input[type=number] { width: 76px; }
.controls input[type=range] { width: 140px; }

button {
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 16px;
  cursor: pointer;
  transition: all .12s;
  font-family: inherit;
}
button:hover { border-color: var(--accent); background: var(--panel-3); }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
button.primary {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
  font-weight: 700;
}
button.primary:hover { background: #015e95; color: #ffffff; }

/* ===== Step bar ===== */
.step-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  margin-bottom: 16px;
}
.step-bar button { min-width: 72px; }
.progress-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: 6px;
}
.progress {
  flex: 1;
  height: 7px;
  background: var(--panel-3);
  border-radius: 4px;
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width .15s ease;
}
.step-counter {
  font-family: ui-monospace, monospace;
  font-size: 16px;
  color: var(--muted);
  min-width: 80px;
  text-align: right;
}

/* ===== Recursion stage ===== */
.rec-stage {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 14px;
  margin-bottom: 12px;
}
@media (max-width: 760px) {
  .rec-stage { grid-template-columns: 1fr; }
}

.stack-panel {
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  min-height: 280px;
  display: flex;
  flex-direction: column;
}
.stack-title {
  font-size: 13px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 8px;
}
.stack {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}
.stack-item {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 12px;
  font-family: ui-monospace, monospace;
  font-size: 16px;
  color: var(--text);
  animation: pushIn .25s ease-out;
  transition: all .2s;
}
.stack-item.top {
  background: rgba(2, 119, 189, 0.12);
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: 0 0 0 1px rgba(2, 119, 189, 0.3);
  font-weight: 700;
}
.stack-empty {
  color: var(--muted);
  font-size: 14px;
  text-align: center;
  padding: 20px 0;
  font-style: italic;
}
.stack-hint {
  font-size: 12px;
  color: var(--muted);
  text-align: right;
  margin-top: 6px;
  opacity: 0.8;
}
@keyframes pushIn {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: none; }
}

.tree-wrap {
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  position: relative;
  overflow: hidden;
}
#rec-svg {
  width: 100%;
  height: auto;
  min-height: 520px;
  display: block;
}

/* Tree nodes (rec viz 専用に #rec-svg でスコープ — BST viz と衝突させない) */
#rec-svg .node circle {
  fill: var(--panel);
  stroke: var(--line);
  stroke-width: 2;
  transition: all .25s;
}
#rec-svg .node text {
  fill: var(--muted);
  text-anchor: middle;
  dominant-baseline: middle;
  pointer-events: none;
  font-family: ui-monospace, monospace;
  font-size: 16px;
  font-weight: 700;
  transition: fill .2s;
}
#rec-svg .node.pending circle {
  fill: var(--bg-1);
  stroke: var(--line);
  stroke-dasharray: 3 3;
  opacity: 0.55;
}
#rec-svg .node.pending text { opacity: 0.5; }
#rec-svg .node.active circle {
  fill: rgba(2, 119, 189, 0.16);
  stroke: var(--accent);
  stroke-width: 2.5;
}
#rec-svg .node.active text { fill: var(--text); }
#rec-svg .node.returned circle {
  fill: rgba(21, 136, 90, 0.16);
  stroke: var(--good);
}
#rec-svg .node.returned text { fill: var(--text); }
#rec-svg .node.current circle {
  stroke-width: 4;
  filter: drop-shadow(0 0 6px var(--accent));
}
#rec-svg .node.current.returned circle {
  filter: drop-shadow(0 0 6px var(--good));
}
#rec-svg .node .ret {
  fill: var(--accent-2);
  font-size: 18px;
  font-weight: 800;
}
#rec-svg .node.returned .ret { fill: var(--good); }

/* Tree edges (rec viz 専用) */
#rec-svg .edge {
  stroke: var(--line);
  stroke-width: 2;
  fill: none;
  transition: all .25s;
  stroke-dasharray: 3 4;
  opacity: 0.6;
}
#rec-svg .edge.call {
  stroke: var(--accent);
  stroke-dasharray: none;
  opacity: 1;
  stroke-width: 2.5;
}
#rec-svg .edge.return {
  stroke: var(--good);
  stroke-dasharray: none;
  opacity: 1;
  stroke-width: 3;
}

/* Duplicate call counter (fib) */
.dup-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 6px 0 12px;
  min-height: 28px;
}
.dup-chip {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 4px 12px;
  font-family: ui-monospace, monospace;
  font-size: 15px;
  color: var(--muted);
  transition: all .2s;
}
.dup-chip.dup {
  background: rgba(214, 50, 43, 0.12);
  border-color: var(--bad);
  color: var(--bad);
}
.dup-chip.bump {
  transform: scale(1.15);
  background: rgba(194, 116, 10, 0.18);
  border-color: var(--accent-2);
  color: var(--accent-2);
}

/* ===== Binary search ===== */
.bs-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}
@media (max-width: 660px) {
  .bs-stats { grid-template-columns: repeat(2, 1fr); }
}
.stat {
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  text-align: center;
}
.stat .lbl {
  font-size: 13px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}
.stat .val {
  font-family: ui-monospace, monospace;
  font-size: 24px;
  font-weight: 700;
  color: var(--accent);
}

.bs-stage {
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 38px 16px 22px;
  margin-bottom: 12px;
  overflow-x: auto;
}
.array {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: 6px;
  flex-wrap: nowrap;
  min-width: fit-content;
}
.cell {
  position: relative;
  width: 54px;
  height: 62px;
  border-radius: 8px;
  background: var(--panel);
  border: 2px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: ui-monospace, monospace;
  font-size: 20px;
  font-weight: 700;
  transition: all .3s cubic-bezier(.5,.2,.3,1.2);
  flex-shrink: 0;
}
.cell .idx {
  position: absolute;
  bottom: -24px;
  font-size: 13px;
  color: var(--muted);
  font-weight: 400;
}
.cell.out {
  opacity: 0.25;
  filter: grayscale(0.7);
}
.cell.in-range {
  background: rgba(37, 99, 235, 0.10);
  border-color: var(--left);
  color: var(--text);
}
.cell.mid {
  background: var(--mid);
  color: #1a1304;
  border-color: var(--mid);
  transform: translateY(-10px) scale(1.08);
  box-shadow: 0 6px 18px rgba(240, 160, 32, 0.45);
  font-weight: 800;
}
.cell.found {
  background: var(--good);
  color: #ffffff;
  border-color: var(--good);
  transform: translateY(-12px) scale(1.18);
  box-shadow: 0 10px 30px rgba(21, 136, 90, 0.45);
  animation: foundPulse 0.9s ease-out;
}
@keyframes foundPulse {
  0% { transform: translateY(-12px) scale(1); }
  50% { transform: translateY(-12px) scale(1.3); }
  100% { transform: translateY(-12px) scale(1.18); }
}
.cell.notfound {
  background: rgba(214, 50, 43, 0.18);
  border-color: var(--bad);
  color: var(--bad);
}

.cell .pointers {
  position: absolute;
  top: -30px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 13px;
  font-weight: 800;
  width: 100%;
  pointer-events: none;
}
.cell .pointer-row {
  display: flex;
  gap: 3px;
}
.cell .p {
  padding: 2px 7px;
  border-radius: 4px;
  color: #ffffff;
  animation: dropDown .25s ease-out;
}
.cell .p.L { background: var(--left); }
.cell .p.M { background: var(--mid); color: #1a1304; }
.cell .p.R { background: var(--right); }
.cell .arrow {
  font-size: 12px;
  line-height: 1;
  color: var(--muted);
}
@keyframes dropDown {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: none; }
}

.calc {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px 16px;
  font-family: ui-monospace, monospace;
  font-size: 19px;
  text-align: center;
  margin-bottom: 8px;
  min-height: 1.6em;
  color: var(--accent-2);
  font-weight: 700;
}

/* ===== Status / message ===== */
.status {
  padding: 14px 18px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 18px;
  color: var(--text);
  min-height: 2.4em;
  margin-bottom: 12px;
  line-height: 1.5;
}
.status .ok { color: var(--good); font-weight: 700; }
.status .ng { color: var(--bad); font-weight: 700; }
.status .hi { color: var(--accent-2); font-weight: 700; }

/* ===================================================
 *  分割統治（マージソート）
 * ================================================= */
:root {
  --ms-cell-w: 50px;
  --ms-cell-h: 48px;
  --ms-gap: 4px;
  --ms-level-h: 80px;
  --ms-node-pad: 5px;
}
body.presentation {
  --ms-cell-w: 64px;
  --ms-cell-h: 60px;
  --ms-gap: 6px;
  --ms-level-h: 100px;
}

.ms-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  justify-content: center;
  padding: 10px 14px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  margin-bottom: 12px;
  font-size: 15px;
  color: var(--muted);
}
.ms-legend .lg-box {
  display: inline-block;
  width: 15px;
  height: 15px;
  border-radius: 3px;
  margin-right: 5px;
  vertical-align: -2px;
  border: 1.5px solid var(--line);
}
.ms-legend .lg-box.pending { border-style: dashed; opacity: 0.55; }
.ms-legend .lg-box.unsorted { border-color: var(--accent); background: rgba(2,119,189,0.18); }
.ms-legend .lg-box.sorted { border-color: var(--good); background: rgba(21,136,90,0.18); }
.ms-legend .lg-box.active { border-color: var(--accent-2); background: rgba(194,116,10,0.3); box-shadow: 0 0 0 2px rgba(194,116,10,0.3); }
.ms-legend .sep { color: var(--line); margin: 0 4px; }
.ms-legend .lg-cell {
  display: inline-block;
  width: 15px;
  height: 15px;
  border-radius: 3px;
  margin-right: 5px;
  vertical-align: -2px;
  border: 1px solid var(--line);
}
.ms-legend .lg-cell.cmp { background: var(--accent); border-color: var(--accent); }
.ms-legend .lg-cell.consumed { background: var(--panel-2); opacity: 0.45; text-decoration: line-through; }
.ms-legend .lg-cell.just-placed { background: var(--good); border-color: var(--good); }
.ms-legend .lg-cell.placed { background: rgba(21,136,90,0.28); border-color: var(--good); }

.ms-stage {
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px 12px;
  margin-bottom: 12px;
  overflow-x: auto;
}
.ms-tree-outer {
  display: flex;
  justify-content: center;
  min-width: fit-content;
}
.ms-tree-inner {
  position: relative;
  padding: 22px 4px 8px;
  --n: 8;
  width: calc(var(--n) * (var(--ms-cell-w) + var(--ms-gap)) - var(--ms-gap) + var(--ms-node-pad) * 2);
}

.ms-level {
  position: relative;
  height: var(--ms-level-h);
  margin-bottom: 4px;
}

.ms-node {
  position: absolute;
  --pos: 0;
  --span: 1;
  top: 18px;
  left: calc(var(--pos) * (var(--ms-cell-w) + var(--ms-gap)));
  width: calc(var(--span) * (var(--ms-cell-w) + var(--ms-gap)) - var(--ms-gap) + var(--ms-node-pad) * 2);
  height: calc(var(--ms-cell-h) + var(--ms-node-pad) * 2);
  padding: var(--ms-node-pad);
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 8px;
  transition: all .28s ease;
  box-sizing: border-box;
}
.ms-node.pending {
  opacity: 0.5;
  border-style: dashed;
  background: transparent;
}
.ms-node.unsorted {
  border-color: var(--accent);
  background: rgba(2, 119, 189, 0.07);
}
.ms-node.sorted {
  border-color: var(--good);
  background: rgba(21, 136, 90, 0.09);
}
.ms-node.active {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 3px rgba(194, 116, 10, 0.22), 0 8px 20px rgba(194, 116, 10, 0.22);
  transform: translateY(-2px);
  z-index: 5;
}
.ms-node.merge-source {
  border-color: var(--accent-3);
  background: rgba(124, 58, 237, 0.08);
}
.ms-node.merging {
  border-color: var(--accent-2);
  background: rgba(194, 116, 10, 0.07);
}

.ms-label {
  position: absolute;
  top: -19px;
  left: 2px;
  font-size: 13px;
  color: var(--muted);
  font-family: ui-monospace, monospace;
  white-space: nowrap;
}
body.presentation .ms-label { font-size: 15px; top: -21px; }

.ms-cell {
  position: absolute;
  --pos: 0;
  top: var(--ms-node-pad);
  left: calc(var(--pos) * (var(--ms-cell-w) + var(--ms-gap)) + var(--ms-node-pad));
  width: var(--ms-cell-w);
  height: var(--ms-cell-h);
  background: var(--panel-2);
  border-radius: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: ui-monospace, monospace;
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  transition: all .28s ease;
}
body.presentation .ms-cell { font-size: 22px; }
.ms-cell.empty {
  background: transparent;
  border: 1px dashed var(--line);
  opacity: 0.4;
  color: transparent;
}
.ms-node.sorted .ms-cell {
  background: rgba(21, 136, 90, 0.16);
  color: #0b5138;
}
.ms-node.active .ms-cell {
  background: rgba(194, 116, 10, 0.16);
  color: #8a5207;
}

/* マージ中のセル個別ハイライト */
.ms-cell.cmp {
  background: var(--accent) !important;
  color: #ffffff !important;
  transform: translateY(-3px) scale(1.06);
  box-shadow: 0 4px 12px rgba(2, 119, 189, 0.4);
  z-index: 2;
}
.ms-cell.pick {
  background: var(--accent-2) !important;
  color: #ffffff !important;
  transform: translateY(-4px) scale(1.08);
  box-shadow: 0 6px 16px rgba(194, 116, 10, 0.45);
  z-index: 3;
}
.ms-cell.consumed {
  opacity: 0.35;
  text-decoration: line-through;
  text-decoration-color: var(--bad);
  text-decoration-thickness: 2px;
  filter: grayscale(0.5);
}
.ms-cell.placed {
  background: rgba(21, 136, 90, 0.22) !important;
  color: #0b5138 !important;
}
.ms-cell.just-placed {
  background: var(--good) !important;
  color: #ffffff !important;
  transform: scale(1.1);
  box-shadow: 0 6px 16px rgba(21, 136, 90, 0.45);
  z-index: 3;
  animation: pulsePlaced 0.45s ease-out;
}
@keyframes pulsePlaced {
  0%   { transform: scale(1.25); }
  60%  { transform: scale(1.08); }
  100% { transform: scale(1.1); }
}

/* ===================================================
 *  分割統治（クイックソート）— マージソートの ms-* 系を再利用
 *  追加のセル状態：pivot / less / more / fixed
 * ================================================= */
.ms-legend .lg-cell.pivot { background: var(--accent-2); border-color: var(--accent-2); }
.ms-legend .lg-cell.less  { background: rgba(2,119,189,0.45); border-color: var(--accent); }
.ms-legend .lg-cell.more  { background: rgba(124,58,237,0.45); border-color: var(--accent-3); }
.ms-legend .lg-cell.fixed { background: var(--good); border-color: var(--good); }

.ms-cell.pivot {
  background: var(--accent-2) !important;
  color: #ffffff !important;
  transform: translateY(-3px) scale(1.06);
  box-shadow: 0 4px 14px rgba(194, 116, 10, 0.5);
  z-index: 3;
}
.ms-cell.less {
  background: rgba(2, 119, 189, 0.32) !important;
  color: #0a3f63 !important;
  border: 1.5px solid var(--accent);
}
.ms-cell.more {
  background: rgba(124, 58, 237, 0.28) !important;
  color: #3b1d7a !important;
  border: 1.5px solid var(--accent-3);
}
.ms-cell.fixed {
  background: var(--good) !important;
  color: #ffffff !important;
  box-shadow: 0 0 0 2px rgba(21, 136, 90, 0.35), 0 4px 12px rgba(21, 136, 90, 0.4);
}
/* split 状態：分割が終わり、ピボットが定位置についた親ノード */
.ms-node.partitioning {
  border-color: var(--accent-2);
  background: rgba(194, 116, 10, 0.07);
}
.ms-node.split {
  border-color: var(--accent-3);
  background: rgba(124, 58, 237, 0.06);
}

/* ===================================================
 *  ソート図鑑
 * ================================================= */
.sz-card {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 16px;
  margin-bottom: 14px;
}
.sz-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}
.sz-name {
  font-size: 22px;
  font-weight: 700;
  color: var(--accent);
}
.sz-tag {
  font-size: 14px;
  font-family: ui-monospace, monospace;
  color: var(--muted);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 12px;
}
.sz-desc {
  margin: 0;
  font-size: 17px;
  color: var(--text);
  line-height: 1.7;
}
body.presentation .sz-name { font-size: 26px; }
body.presentation .sz-tag { font-size: 16px; }
body.presentation .sz-desc { font-size: 19px; }

.sz-stage {
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px 16px 36px;
  margin-bottom: 12px;
  height: 340px;
  overflow-x: auto;
}
body.presentation .sz-stage { height: 58vh; }

.sz-bars {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 4px;
  height: 100%;
  min-width: fit-content;
}
.sz-bar {
  flex: 1 1 0;
  min-width: 12px;
  max-width: 68px;
  background: var(--panel-3);
  border-radius: 4px 4px 0 0;
  position: relative;
  transition: height .14s ease, background .14s ease;
}
.sz-bar .v {
  position: absolute;
  bottom: -24px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 14px;
  color: var(--muted);
  font-family: ui-monospace, monospace;
}
body.presentation .sz-bar .v { font-size: 17px; bottom: -28px; }
.sz-bar.range  { background: #9db8d6; }
.sz-bar.cmp    { background: var(--accent); }
.sz-bar.swap   { background: var(--bad); }
.sz-bar.key    { background: var(--accent-2); }
.sz-bar.pivot  { background: #db2777; }
.sz-bar.min    { background: var(--accent-3); }
.sz-bar.sorted { background: var(--good); }
.sz-bar.cmp .v,
.sz-bar.swap .v,
.sz-bar.key .v,
.sz-bar.pivot .v,
.sz-bar.min .v,
.sz-bar.sorted .v { color: var(--text); font-weight: 700; }

.sz-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  justify-content: center;
  padding: 10px 14px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  margin-bottom: 12px;
  font-size: 15px;
  color: var(--muted);
}
.sz-legend .lg-bar {
  display: inline-block;
  width: 15px;
  height: 15px;
  border-radius: 3px;
  margin-right: 5px;
  vertical-align: -2px;
}
.sz-legend .lg-bar.base   { background: var(--panel-3); }
.sz-legend .lg-bar.cmp    { background: var(--accent); }
.sz-legend .lg-bar.swap   { background: var(--bad); }
.sz-legend .lg-bar.key    { background: var(--accent-2); }
.sz-legend .lg-bar.min    { background: var(--accent-3); }
.sz-legend .lg-bar.sorted { background: var(--good); }
body.presentation .sz-legend { font-size: 17px; }

/* ===================================================
 *  計算量比較 (n² vs n log n)
 * ================================================= */
.cx-h {
  margin: 22px 0 10px;
  font-size: 20px;
  color: var(--accent);
  border-left: 4px solid var(--accent);
  padding-left: 10px;
  font-weight: 700;
}
body.presentation .cx-h { font-size: 24px; }

.cx-tree-wrap {
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px 14px;
  margin-bottom: 10px;
  overflow-x: auto;
}
#cx-svg {
  width: 100%;
  height: auto;
  min-height: 420px;
  display: block;
}
body.presentation #cx-svg { min-height: 58vh; }

.cx-node-rect {
  fill: var(--panel);
  stroke: var(--line);
  stroke-width: 1.5;
  transition: all .3s;
}
.cx-node-rect.dim {
  fill: transparent;
  stroke-dasharray: 3 4;
  opacity: 0.45;
}
.cx-node-rect.active {
  fill: rgba(2, 119, 189, 0.18);
  stroke: var(--accent);
  stroke-width: 2.5;
}
.cx-node-rect.merging {
  fill: rgba(21, 136, 90, 0.20);
  stroke: var(--good);
  stroke-width: 2.5;
}
.cx-node-label {
  fill: var(--text);
  font-family: ui-monospace, monospace;
  font-size: 14px;
  font-weight: 700;
  text-anchor: middle;
  dominant-baseline: middle;
  pointer-events: none;
}
body.presentation .cx-node-label { font-size: 17px; }

.cx-level-annot {
  fill: var(--muted);
  font-family: ui-monospace, monospace;
  font-size: 15px;
  dominant-baseline: middle;
  transition: all .3s;
}
.cx-level-annot.active {
  fill: var(--accent);
  font-size: 17px;
  font-weight: 700;
}
.cx-level-annot.merging {
  fill: var(--good);
  font-weight: 700;
}
body.presentation .cx-level-annot { font-size: 18px; }
body.presentation .cx-level-annot.active { font-size: 20px; }

.cx-merge-arrow {
  stroke: var(--good);
  stroke-width: 2.5;
  fill: none;
  marker-end: url(#cx-arrow);
  opacity: 0.85;
}

.cx-formula {
  background: var(--panel-2);
  border: 1.5px solid var(--accent-2);
  border-radius: 10px;
  padding: 16px 22px;
  font-family: ui-monospace, monospace;
  font-size: 22px;
  text-align: center;
  margin-bottom: 10px;
  color: var(--accent-2);
  font-weight: 800;
}
body.presentation .cx-formula { font-size: 28px; padding: 18px 26px; }

.cx-compare {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 8px;
}
@media (max-width: 760px) { .cx-compare { grid-template-columns: 1fr; } }

.cx-block {
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px 14px 16px;
}
.cx-block-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 10px;
}
.cx-block-name {
  font-weight: 700;
  font-size: 18px;
  color: var(--text);
}
.cx-block-name code { color: var(--accent); font-family: ui-monospace, monospace; }
.cx-block-formula {
  font-family: ui-monospace, monospace;
  font-size: 16px;
  color: var(--accent-2);
  font-weight: 700;
}
body.presentation .cx-block-name { font-size: 22px; }
body.presentation .cx-block-formula { font-size: 19px; }

.cx-grid {
  display: grid;
  gap: 2px;
  background: var(--panel-3);
  border-radius: 6px;
  padding: 4px;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
}
body.presentation .cx-grid { max-width: 620px; }
.cx-dot { border-radius: 1px; }
.cx-grid.bubble { aspect-ratio: 1 / 1; }
.cx-grid.bubble .cx-dot { background: var(--bad); opacity: 0.78; }
.cx-grid.merge   .cx-dot { background: var(--good); opacity: 0.88; }

.cx-note {
  margin: 0 0 16px;
  text-align: center;
  color: var(--muted);
  font-size: 15px;
}
body.presentation .cx-note { font-size: 17px; }

.cx-table-wrap {
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow-x: auto;
}
.cx-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 15px;
}
body.presentation .cx-table { font-size: 17px; }
.cx-table th, .cx-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  font-family: ui-monospace, monospace;
  white-space: nowrap;
}
.cx-table th {
  background: var(--panel-2);
  color: var(--muted);
  font-weight: 700;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
body.presentation .cx-table th { font-size: 14px; }
.cx-table td:first-child {
  text-align: left;
  font-weight: 800;
  color: var(--accent);
}
.cx-table .ratio { color: var(--bad); font-weight: 800; }
.cx-table tbody tr:last-child td { border-bottom: none; }
.cx-table .slow { color: var(--bad); }
.cx-table .fast { color: var(--good); }

/* ===== Pseudocode ===== */
.code-wrap {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}
.pseudocode {
  flex: 1;
  min-width: 280px;
  position: relative;
  margin: 0;
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px 18px 14px;
  overflow-x: auto;
  font-size: 16px;
}
.pseudocode.hidden { display: none; }
.pseudocode .lbl {
  position: absolute;
  top: 8px;
  right: 12px;
  font-size: 13px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.pseudocode code {
  display: block;
  white-space: pre;
  font-family: ui-monospace, monospace;
  font-size: 16px;
  line-height: 1.7;
}
.pseudocode .line {
  display: block;
  padding: 2px 6px;
  margin: 0 -6px;
  border-radius: 4px;
  border-left: 3px solid transparent;
  transition: all .15s;
  color: var(--muted);
}
.pseudocode .line.active {
  background: rgba(2, 119, 189, 0.12);
  border-left-color: var(--accent);
  color: var(--text);
  font-weight: 700;
}

/* ===================================================
 *  二分探索木 (BST)  — #bst-svg にスコープし rec viz と衝突させない
 * ================================================= */
.bst-stage {
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px 12px;
  margin-bottom: 12px;
  position: relative;
  overflow: hidden;
}
#bst-svg {
  width: 100%;
  height: auto;
  min-height: 520px;
  display: block;
}
body.presentation #bst-svg { min-height: 40vh; max-height: 56vh; }
body.presentation .bst-stage { padding: 6px 8px; }

#bst-svg .node circle {
  fill: var(--panel);
  stroke: var(--line);
  stroke-width: 2;
  transition: fill .2s, stroke .2s, stroke-width .2s, filter .2s;
}
#bst-svg .node text {
  fill: var(--text);
  text-anchor: middle;
  dominant-baseline: middle;
  pointer-events: none;
  font-family: ui-monospace, monospace;
  font-size: 16px;
  font-weight: 700;
}
body.presentation #bst-svg .node text { font-size: 20px; }

#bst-svg .node.path circle {
  fill: rgba(124, 58, 237, 0.14);
  stroke: var(--accent-3);
  stroke-width: 2;
}
#bst-svg .node.cur circle {
  fill: rgba(2, 119, 189, 0.20);
  stroke: var(--accent);
  stroke-width: 3.5;
  filter: drop-shadow(0 0 6px rgba(2, 119, 189, 0.5));
}
#bst-svg .node.new circle {
  fill: rgba(21, 136, 90, 0.22);
  stroke: var(--good);
  stroke-width: 3;
  filter: drop-shadow(0 0 8px rgba(21, 136, 90, 0.5));
  animation: bstPopIn 0.5s ease-out;
}
#bst-svg .node.hit circle {
  fill: rgba(21, 136, 90, 0.40);
  stroke: var(--good);
  stroke-width: 4;
  filter: drop-shadow(0 0 10px var(--good));
}
@keyframes bstPopIn {
  0%   { transform: scale(0.1); opacity: 0; }
  60%  { transform: scale(1.25); opacity: 1; }
  100% { transform: scale(1); }
}

#bst-svg .edge {
  stroke: var(--line);
  stroke-width: 2;
  fill: none;
  transition: stroke .2s, stroke-width .2s, opacity .2s;
  opacity: 0.55;
}
#bst-svg .edge.visited {
  stroke: var(--accent-3);
  opacity: 1;
  stroke-width: 2.8;
}
#bst-svg .edge.ghost-edge {
  stroke: var(--bad);
  stroke-dasharray: 4 4;
  opacity: 0.85;
}

/* 部分木ハイライト（クリックで切替） */
#bst-svg .node.clickable { cursor: pointer; }
#bst-svg .node.subtree circle {
  stroke: var(--accent-2);
  stroke-width: 2.5;
  fill: rgba(194, 116, 10, 0.10);
}
#bst-svg .node.subtree-root circle {
  stroke-width: 4;
  filter: drop-shadow(0 0 8px rgba(194, 116, 10, 0.6));
}
#bst-svg .node.subtree text { font-weight: 800; }
#bst-svg .edge.subtree {
  stroke: var(--accent-2);
  opacity: 0.9;
  stroke-width: 2.5;
}

/* 深さラベル（ノードのテキストと色が同じだと埋もれるので、より高い詳細度で色を上書き） */
#bst-svg .node text.depth-label {
  fill: var(--accent-3);
  font-family: ui-monospace, monospace;
  font-size: 11px;
  text-anchor: middle;
  dominant-baseline: middle;
  font-weight: 700;
}
body.presentation #bst-svg .node text.depth-label { font-size: 14px; }

/* BSTのルールバナー（ツリー上に常設。ノード位置に依存せず見切れない） */
.bst-rule-banner {
  padding: 9px 14px;
  margin-bottom: 10px;
  background: rgba(194, 116, 10, 0.10);
  border: 1px solid var(--accent-2);
  border-radius: 8px;
  font-size: 14px;
  color: var(--text);
  text-align: center;
  line-height: 1.5;
}
.bst-rule-banner b  { color: var(--accent-2); font-family: ui-monospace, monospace; }
.bst-rule-banner .lt { color: var(--accent);   font-weight: 700; }
.bst-rule-banner .gt { color: var(--accent-3); font-weight: 700; }
body.presentation .bst-rule-banner { font-size: 18px; padding: 11px 16px; }

/* 中順走査ストリップ */
.bst-inorder-wrap {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  margin-bottom: 12px;
  font-size: 14px;
  color: var(--muted);
}
.bst-inorder-label { font-weight: 700; color: var(--text); }
.bst-inorder-tail  { color: var(--muted); flex-shrink: 0; }
.bst-inorder {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  flex: 1 1 auto;
  min-width: 200px;
}
.bst-inorder-pill {
  display: inline-block;
  padding: 3px 9px;
  background: rgba(21, 136, 90, 0.12);
  border: 1px solid var(--good);
  border-radius: 999px;
  color: #0b5138;
  font-family: ui-monospace, monospace;
  font-size: 14px;
  font-weight: 700;
}
.bst-inorder-empty {
  color: var(--muted);
  font-style: italic;
}
body.presentation .bst-inorder-wrap { font-size: 18px; }
body.presentation .bst-inorder-pill { font-size: 18px; padding: 5px 12px; }

/* ツールバー（チェックボックス + 部分木解除） */
.bst-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 18px;
  padding: 8px 14px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  margin-bottom: 10px;
  font-size: 14px;
  color: var(--muted);
}
.bst-toolbar label { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.bst-toolbar input[type=checkbox] { accent-color: var(--accent); }
.bst-toolbar-hint { color: var(--accent-2); font-weight: 600; }
.bst-toolbar button {
  padding: 5px 12px;
  font-size: 14px;
}
body.presentation .bst-toolbar { font-size: 17px; }

/* 凡例の部分木ドット */
.bst-legend .lg-circle.subtree {
  border-color: var(--accent-2);
  background: rgba(194, 116, 10, 0.18);
}

/* ===================================================
 *  BST 並べて比較（タブ ⑧）
 * ================================================= */
.bstcmp-stage {
  display: flex;
  align-items: stretch;
  gap: 0;
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 12px;
  overflow: hidden;
}
.bstcmp-side {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.bstcmp-divider {
  width: 1px;
  background: var(--line);
  margin: 0 12px;
  flex-shrink: 0;
}
.bstcmp-title {
  text-align: center;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--text);
  font-size: 15px;
}
.bstcmp-title #bstcmp-titleL,
.bstcmp-title #bstcmp-titleR {
  color: var(--accent);
  font-family: ui-monospace, monospace;
}
#bstcmp-svgL, #bstcmp-svgR {
  width: 100%;
  height: auto;
  min-height: 380px;
  display: block;
}
body.presentation #bstcmp-svgL,
body.presentation #bstcmp-svgR { min-height: 36vh; max-height: 52vh; }

/* 投影モード：二次的な UI（凡例 / ストリップ / 注釈バー）は隠して画面を空ける */
body.presentation .bst-toolbar,
body.presentation .bst-inorder-wrap,
body.presentation .bst-legend,
body.presentation .bstcmp-note,
body.presentation .ms-legend,
body.presentation .sz-legend {
  display: none;
}

/* SVG 内のノード／エッジは BST viz の規則を流用 */
#bstcmp-svgL .node circle,
#bstcmp-svgR .node circle {
  fill: var(--panel);
  stroke: var(--line);
  stroke-width: 2;
  transition: fill .2s, stroke .2s, stroke-width .2s, filter .2s;
}
#bstcmp-svgL .node text,
#bstcmp-svgR .node text {
  fill: var(--text);
  text-anchor: middle;
  dominant-baseline: middle;
  pointer-events: none;
  font-family: ui-monospace, monospace;
  font-size: 14px;
  font-weight: 700;
}
body.presentation #bstcmp-svgL .node text,
body.presentation #bstcmp-svgR .node text { font-size: 17px; }
#bstcmp-svgL .node.path circle, #bstcmp-svgR .node.path circle {
  fill: rgba(124, 58, 237, 0.14);
  stroke: var(--accent-3);
}
#bstcmp-svgL .node.cur circle, #bstcmp-svgR .node.cur circle {
  fill: rgba(2, 119, 189, 0.20);
  stroke: var(--accent);
  stroke-width: 3;
  filter: drop-shadow(0 0 5px rgba(2, 119, 189, 0.5));
}
#bstcmp-svgL .node.new circle, #bstcmp-svgR .node.new circle {
  fill: rgba(21, 136, 90, 0.22);
  stroke: var(--good);
  stroke-width: 3;
  filter: drop-shadow(0 0 6px rgba(21, 136, 90, 0.5));
  animation: bstPopIn 0.5s ease-out;
}
#bstcmp-svgL .node.hit circle, #bstcmp-svgR .node.hit circle {
  fill: rgba(21, 136, 90, 0.40);
  stroke: var(--good);
  stroke-width: 3.5;
  filter: drop-shadow(0 0 8px var(--good));
}
#bstcmp-svgL .node.ghost circle, #bstcmp-svgR .node.ghost circle {
  fill: transparent;
  stroke: var(--bad);
  stroke-width: 2;
  stroke-dasharray: 4 3;
  opacity: 0.75;
}
#bstcmp-svgL .node.ghost text, #bstcmp-svgR .node.ghost text {
  fill: var(--bad);
  font-size: 12px;
}
#bstcmp-svgL .edge, #bstcmp-svgR .edge {
  stroke: var(--line);
  stroke-width: 2;
  fill: none;
  opacity: 0.55;
}
#bstcmp-svgL .edge.visited, #bstcmp-svgR .edge.visited {
  stroke: var(--accent-3);
  opacity: 1;
  stroke-width: 2.5;
}
#bstcmp-svgL .edge.ghost-edge, #bstcmp-svgR .edge.ghost-edge {
  stroke: var(--bad);
  stroke-dasharray: 4 4;
  opacity: 0.85;
}
#bstcmp-svgL .empty-hint, #bstcmp-svgR .empty-hint {
  font-family: system-ui, sans-serif;
  font-size: 16px;
  fill: var(--muted);
  text-anchor: middle;
  dominant-baseline: middle;
}

/* 統計を左右で色分け */
.bstcmp-stats .stat.L { border-left: 4px solid var(--accent); }
.bstcmp-stats .stat.R { border-left: 4px solid var(--accent-3); }
.bstcmp-msg-l { color: var(--accent);   font-weight: 600; }
.bstcmp-msg-r { color: var(--accent-3); font-weight: 600; }

.bstcmp-note {
  padding: 10px 14px;
  background: rgba(2, 119, 189, 0.06);
  border-left: 4px solid var(--accent);
  border-radius: 6px;
  font-size: 14px;
  color: var(--text);
  line-height: 1.6;
}
body.presentation .bstcmp-note { font-size: 17px; padding: 14px 18px; }

/* ===================================================
 *  回転 / AVL木 （#rot-svg, #avl-svg を共通スタイル）
 * ================================================= */
.tree-stage {
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px 12px;
  margin-bottom: 12px;
  overflow: hidden;
}
#rot-svg, #avl-svg { width: 100%; height: auto; min-height: 460px; display: block; }
body.presentation #rot-svg, body.presentation #avl-svg { min-height: 0; }

#rot-svg .node circle, #avl-svg .node circle {
  fill: var(--panel);
  stroke: var(--line);
  stroke-width: 2;
  transition: fill .25s, stroke .25s, stroke-width .25s, filter .25s;
}
#rot-svg .node text, #avl-svg .node text {
  fill: var(--text);
  text-anchor: middle;
  dominant-baseline: middle;
  pointer-events: none;
  font-family: ui-monospace, monospace;
  font-size: 16px;
  font-weight: 700;
}
body.presentation #rot-svg .node text, body.presentation #avl-svg .node text { font-size: 19px; }

/* 役割ごとの強調 */
#rot-svg .node.new circle, #avl-svg .node.new circle {
  fill: rgba(21, 136, 90, 0.22); stroke: var(--good); stroke-width: 3;
  filter: drop-shadow(0 0 7px rgba(21, 136, 90, 0.5));
  animation: bstPopIn 0.5s ease-out;
}
#rot-svg .node.unbal circle, #avl-svg .node.unbal circle {
  fill: rgba(214, 50, 43, 0.16); stroke: var(--bad); stroke-width: 3.5;
  filter: drop-shadow(0 0 8px rgba(214, 50, 43, 0.45));
}
#rot-svg .node.pivot circle, #avl-svg .node.pivot circle {
  fill: rgba(194, 116, 10, 0.20); stroke: var(--accent-2); stroke-width: 3.5;
  filter: drop-shadow(0 0 9px rgba(194, 116, 10, 0.55));
}
/* 下ろされる親（回転で下がる節） */
#rot-svg .node.lower circle, #avl-svg .node.lower circle {
  fill: rgba(2, 119, 189, 0.16); stroke: var(--accent); stroke-width: 3;
}
/* 挿入の選択過程：比較中の節（cur）とたどった経路（path） */
#rot-svg .node.cur circle, #avl-svg .node.cur circle {
  fill: rgba(2, 119, 189, 0.20); stroke: var(--accent); stroke-width: 3.5;
  filter: drop-shadow(0 0 6px rgba(2, 119, 189, 0.5));
}
#rot-svg .node.path circle, #avl-svg .node.path circle {
  fill: rgba(124, 58, 237, 0.14); stroke: var(--accent-3); stroke-width: 2.5;
}
/* 持ち上げ中：少し大きく＆強い影で「浮いている」感 */
#rot-svg .node.rising circle, #avl-svg .node.rising circle {
  fill: rgba(194, 116, 10, 0.28); stroke: var(--accent-2); stroke-width: 4;
  filter: drop-shadow(0 8px 16px rgba(194, 116, 10, 0.6));
}
#rot-svg .node.done circle, #avl-svg .node.done circle {
  fill: rgba(21, 136, 90, 0.26); stroke: var(--good); stroke-width: 3.5;
  filter: drop-shadow(0 0 9px var(--good));
}

#rot-svg .edge, #avl-svg .edge {
  stroke: var(--line); stroke-width: 2; fill: none; opacity: 0.6;
}

/* BFラベル（節の下） */
#avl-svg .bf-label, #rot-svg .bf-label {
  fill: var(--accent-3);
  font-family: ui-monospace, monospace;
  font-size: 11px;
  font-weight: 700;
  text-anchor: middle;
  dominant-baseline: middle;
}
#avl-svg .bf-label.bad, #rot-svg .bf-label.bad { fill: var(--bad); }
body.presentation #avl-svg .bf-label, body.presentation #rot-svg .bf-label { font-size: 14px; }

#rot-svg .empty-hint, #avl-svg .empty-hint {
  font-family: system-ui, sans-serif; font-size: 18px; fill: var(--muted);
  text-anchor: middle; dominant-baseline: middle;
}

/* 回転/AVL の小さな凡例（bst-legend を流用） */
.tree-legend {
  display: flex; flex-wrap: wrap; gap: 16px; justify-content: center;
  padding: 9px 14px; background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 10px; margin-bottom: 12px; font-size: 14px; color: var(--muted);
}
.tree-legend .lg-circle {
  display: inline-block; width: 15px; height: 15px; border-radius: 50%;
  margin-right: 5px; vertical-align: -2px; border: 2px solid var(--line); background: var(--panel);
}
.tree-legend .lg-circle.unbal { border-color: var(--bad);      background: rgba(214, 50, 43, 0.16); }
.tree-legend .lg-circle.pivot { border-color: var(--accent-2); background: rgba(194, 116, 10, 0.20); }
.tree-legend .lg-circle.lower { border-color: var(--accent);   background: rgba(2, 119, 189, 0.16); }
.tree-legend .lg-circle.cur   { border-color: var(--accent);   background: rgba(2, 119, 189, 0.20); }
.tree-legend .lg-circle.path  { border-color: var(--accent-3); background: rgba(124, 58, 237, 0.14); }
.tree-legend .lg-circle.done  { border-color: var(--good);     background: rgba(21, 136, 90, 0.26); }
.tree-legend .lg-circle.new   { border-color: var(--good);     background: rgba(21, 136, 90, 0.22); }

#bst-svg .empty-hint {
  font-family: system-ui, sans-serif;
  font-size: 18px;
  fill: var(--muted);
  text-anchor: middle;
  dominant-baseline: middle;
}

/* 検索失敗時に「ここに無い」を示す点線円（仮想ノード） */
#bst-svg .ghost circle {
  fill: transparent;
  stroke: var(--bad);
  stroke-width: 2;
  stroke-dasharray: 4 3;
  opacity: 0.75;
}
#bst-svg .ghost text {
  fill: var(--bad);
  font-size: 14px;
  font-weight: 700;
}
body.presentation #bst-svg .ghost text { font-size: 17px; }

.bst-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  justify-content: center;
  padding: 10px 14px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  margin-bottom: 12px;
  font-size: 15px;
  color: var(--muted);
}
.bst-legend .lg-circle {
  display: inline-block;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  margin-right: 5px;
  vertical-align: -3px;
  border: 2px solid var(--line);
  background: var(--panel);
}
.bst-legend .lg-circle.cur  { border-color: var(--accent);   background: rgba(2, 119, 189, 0.20); }
.bst-legend .lg-circle.path { border-color: var(--accent-3); background: rgba(124, 58, 237, 0.18); }
.bst-legend .lg-circle.new  { border-color: var(--good);     background: rgba(21, 136, 90, 0.22); }
.bst-legend .lg-circle.hit  { border-color: var(--good);     background: rgba(21, 136, 90, 0.40); }
.bst-legend .lg-circle.miss { border-color: var(--bad);      background: rgba(198, 40, 40, 0.18); border-style: dashed; }

#bst-code-wrap .pseudocode.hidden { display: none; }

footer {
  text-align: center;
  padding: 18px;
  color: var(--muted);
  font-size: 14px;
}

/* ===================================================
 *  投影モード — 教室のスクリーンで奥の席まで見やすく
 *  方針：可視化を画面いっぱいに自動フィット（flex 列レイアウト）。
 *        統計は小さく1行で残し、説明文は大きく、擬似コードはトグル表示。
 * ================================================= */

/* --- 全体を縦 flex にして、アクティブパネルが残り高さを全部使う --- */
body.presentation {
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-height: 0;
  overflow: hidden;
}
body.presentation header { flex: 0 0 auto; padding: 4px 16px 0; }
body.presentation header h1 { font-size: 20px; margin: 0; }
body.presentation header .sub { display: none; }
body.presentation .proj-toggle,
body.presentation .code-toggle { top: 8px; font-size: 13px; padding: 6px 12px; }
body.presentation .proj-toggle { right: 14px; }
body.presentation .code-toggle { right: 150px; }
body.presentation footer { display: none; }

body.presentation .tabs { flex: 0 0 auto; max-width: none; margin: 6px auto 0; padding: 0 16px; }
body.presentation .tab { font-size: 14px; padding: 6px 10px; max-width: 220px; }

/* アクティブパネル＝縦 flex コンテナ。非アクティブは display:none のまま */
body.presentation .panel.active {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  max-width: none;
  margin: 0 12px 8px;
  padding: 8px 14px 10px;
  gap: 7px;
  overflow: hidden;
}
/* パネル内の各行は自然高、ステージだけが伸びる */
body.presentation .panel.active > * { flex: 0 0 auto; }

/* --- 操作行はコンパクトに。複数項目は折り返して全部見せる --- */
body.presentation .controls {
  font-size: 13px;
  padding: 5px 10px;
  gap: 6px 14px;
  margin: 0;
  flex-wrap: wrap;
  align-items: center;
  row-gap: 4px;
}
body.presentation .step-bar { font-size: 14px; padding: 5px 10px; gap: 10px; margin: 0; }
body.presentation .controls label { font-size: 13px; }
body.presentation .controls input[type=number],
body.presentation .controls input[type=text],
body.presentation .controls select { font-size: 13px; padding: 4px 7px; }
body.presentation .controls input[type=number] { width: 66px; }
body.presentation .controls input[type=text] { max-width: 320px; }
body.presentation button { font-size: 14px; padding: 6px 12px; }
body.presentation .step-bar button { min-width: 64px; }
body.presentation .step-counter { font-size: 14px; min-width: 84px; }

/* --- 統計：小さく1行で残す --- */
body.presentation .bs-stats {
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  margin: 0;
  overflow-x: auto;
}
body.presentation .stat { flex: 1 1 0; min-width: 0; padding: 4px 10px; }
body.presentation .stat .lbl { font-size: 11px; white-space: nowrap; }
body.presentation .stat .val { font-size: 19px; }

/* --- 説明文（ナレーション）は大きく。ここが主役のテキスト（≈20pt） --- */
body.presentation .status { font-size: 25px; padding: 9px 18px; margin: 0; line-height: 1.4; font-weight: 600; }
body.presentation .calc { font-size: 23px; padding: 8px 16px; margin: 0; }

/* --- 凡例・二次的UIは隠す（画面を空ける） --- */
body.presentation .bst-legend,
body.presentation .ms-legend,
body.presentation .sz-legend,
body.presentation .tree-legend,
body.presentation .bst-toolbar,
body.presentation .bst-inorder-wrap,
body.presentation .bstcmp-note,
body.presentation .dup-row,
body.presentation .sz-card { display: none; }

/* --- ステージ＝残り高さを全部使う --- */
body.presentation .panel.active > .rec-stage,
body.presentation .panel.active > .bs-stage,
body.presentation .panel.active > .ms-stage,
body.presentation .panel.active > .sz-stage,
body.presentation .panel.active > .bst-stage,
body.presentation .panel.active > .bstcmp-stage,
body.presentation .panel.active > .tree-stage,
body.presentation .panel.active > .cx-tree-wrap {
  flex: 1 1 auto;
  min-height: 0;
  height: auto;
  margin: 0;
}
/* SVG はコンテナの高さいっぱいにレターボックス表示 */
body.presentation .panel.active #rec-svg,
body.presentation .panel.active #bst-svg,
body.presentation .panel.active #cx-svg,
body.presentation .panel.active #rot-svg,
body.presentation .panel.active #avl-svg,
body.presentation .panel.active #bstcmp-svgL,
body.presentation .panel.active #bstcmp-svgR {
  height: 100%;
  min-height: 0;
  max-height: none;
}
body.presentation .bst-stage,
body.presentation .sz-stage { padding: 8px 10px; height: auto; }
body.presentation .sz-stage { overflow: hidden; }

/* 再帰タブ：スタック＋ツリー */
body.presentation .rec-stage { grid-template-columns: 260px 1fr; gap: 14px; }
body.presentation .stack-panel { padding: 12px; min-height: 0; }
body.presentation .stack-title { font-size: 14px; }
body.presentation .stack-item { font-size: 18px; padding: 9px 13px; }
body.presentation .stack-empty { font-size: 16px; }
body.presentation #rec-svg .node text { font-size: 17px; }
body.presentation #rec-svg .node .ret { font-size: 18px; }

/* BST：ルールバナーは残す（核心）。中順ストリップ等は上で非表示 */
body.presentation .bst-rule-banner { font-size: 17px; padding: 8px 14px; margin: 0; }

/* 計算量タブ：表と面積比較は投影では省略し、再帰木に集中 */
body.presentation .cx-compare,
body.presentation .cx-table-wrap,
body.presentation .cx-note,
body.presentation .cx-h { display: none; }
body.presentation #cx-svg { min-height: 0; }
body.presentation .cx-formula { font-size: 22px; padding: 8px 16px; margin: 0; }

/* --- 擬似コード：投影中は既定で隠し、トグルでオーバーレイ表示 --- */
body.presentation .code-wrap { display: none; }
body.presentation.show-code .panel.active .code-wrap {
  display: flex;
  position: fixed;
  left: 3vw;
  right: 3vw;
  bottom: 2vh;
  max-height: 70vh;
  z-index: 50;
  background: rgba(238, 243, 249, 0.98);
  border: 2px solid var(--accent-2);
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(22, 35, 59, 0.35);
  padding: 14px;
  overflow: auto;
}
body.presentation.show-code .pseudocode { font-size: 19px; padding: 12px 16px; }
body.presentation.show-code .pseudocode code { font-size: 19px; line-height: 1.75; }
body.presentation.show-code .pseudocode .lbl { font-size: 13px; }

/* マージ／クイック：セル文字 */
body.presentation .ms-cell { font-size: 20px; }

/* 二分探索：配列セル */
body.presentation .bs-stage { padding: 40px 14px 26px; }
body.presentation .cell { width: 56px; height: 64px; font-size: 21px; }
body.presentation .cell .idx { font-size: 13px; bottom: -22px; }
body.presentation .cell .p { font-size: 14px; padding: 2px 7px; }
