/* Lecture 5 uses the common academic theme and compact, scrollable tree views. */
.lecture-five .source-emphasis { color: #9a3f25; font-weight: 600; }
.lecture-five .source-figure { text-align: center; margin: 15px 0; }
.lecture-five .source-figure > img { display: block; width: min(100%,540px); height: auto; margin: 8px auto; }
.lecture-five pre.python-code { padding: 12px 15px; overflow: auto; white-space: pre; font: 14px/1.55 Consolas, "Liberation Mono", monospace; }
.lecture-five .source-output { margin: 10px 0 18px; }
.lecture-five .source-output pre { background: #f4f6f8; }
.lecture-five .source-output .small-label { font-family: var(--ui); }
.source-steps { border-collapse: collapse; width: 100%; min-width: 580px; font: 14px/1.5 var(--ui); }
.source-steps th, .source-steps td { padding: 7px 10px; border: 1px solid var(--line); vertical-align: middle; }
.source-steps th { text-align: left; background: #edf2f8; }
.source-steps td:first-child { width: 100px; }
.source-steps td:last-child { width: 150px; text-align: center; }
.source-steps img { max-width: 128px; height: auto; }
.lecture-five .katex-display { overflow-x: auto; overflow-y: hidden; }
.lecture-five .demo-body { font-family: var(--ui); }
.tree-form { display: flex; flex-wrap: wrap; align-items: end; gap: 10px; font: 13px/1.5 var(--ui); }
.tree-form label { display: flex; flex-direction: column; gap: 4px; }
.tree-form label > code { display: contents; }
.tree-form .tree-wide { flex: 1; }
.tree-form input { min-height: 32px; width: 105px; border: 1px solid #bec5ce; padding: 6px 8px; font: 14px Consolas, monospace; color: var(--ink); background: white; }
.tree-form .tree-wide input { width: 100%; min-width: 200px; }
.tree-form button { min-height: 32px; padding: 6px 10px; color: var(--accent-dark); background: white; border: 1px solid #bec5ce; border-radius: 2px; }
.tree-form button:disabled, .tree-form input:disabled { opacity: .5; cursor: default; }
.tree-form output { min-height: 32px; padding: 5px 10px; background: #edf2fa; font: 14px/1.5 Consolas, monospace; }
.lecture-five .input-error { min-height: 20px; color: #9a362e; margin: 3px 0; font: 13px/1.5 var(--ui); }
.tree-heading { height: 64px; padding-top: 8px; }
.tree-heading h3 { font-size: 17px; margin: 0; }
.lecture-five .demo-explanation { height: 90px; margin-bottom: 12px; }
.tree-metrics { display: flex; flex-wrap: wrap; gap: 5px 22px; margin: 8px 0; font: 13px/1.6 var(--ui); }
.tree-metrics span { min-width: 0; max-width: 100%; overflow-wrap: anywhere; }
.tree-metrics strong { font-family: Consolas, monospace; font-size: 14px; }
.tree-tokens { display: flex; flex-wrap: wrap; gap: 5px; margin: 10px 0; min-height: 0; }
.tree-token { min-width: 27px; border: 1px solid #b9c9dc; background: white; text-align: center; padding: 3px 7px; font: 14px/1.5 Consolas, monospace; }
.tree-token small { display: block; color: var(--muted); font-size: 12px; }
.tree-token.processed { background: #e9f0fa; }
.tree-token.active { outline: 2px solid #ab641b; outline-offset: -2px; }
.tree-trace-layout { display: grid; grid-template-columns: minmax(0,1.05fr) minmax(0,1fr); gap: 20px; align-items: start; }
.tree-trace-layout > div { min-width: 0; }
.tree-canvas { height: 330px; overflow: auto; border-bottom: 1px solid var(--line); background: #fff; overscroll-behavior: contain; }
.tree-canvas svg { display: block; }
.tree-canvas .edge { stroke: #99abc2; stroke-width: 1.5; }
.tree-canvas .edge-label { fill: #5f6f81; font: 12px var(--ui); }
.tree-canvas .node-box { fill: white; stroke: #9eafc5; stroke-width: 1.5; }
.tree-canvas .node-key { fill: #263140; font: 14px Consolas, monospace; text-anchor: middle; }
.tree-canvas .node-meta { fill: #5f6f81; font: 12px var(--ui); text-anchor: middle; }
.tree-canvas .node-result { fill: #275b96; font: 12px Consolas, monospace; text-anchor: middle; }
.tree-canvas .on-path .node-box { fill: #e3edf9; stroke: #527eb2; }
.tree-canvas .rejected .node-box { fill: #f3f4f6; stroke: #b8bec8; stroke-dasharray: 4 3; }
.tree-canvas .active .node-box { stroke: #ae651b; stroke-width: 3; }
.tree-canvas [role=button] { cursor: pointer; }
.tree-canvas [role=button]:focus-visible .node-box { stroke: #1e70b7; stroke-width: 3; }
.tree-legend, .tree-stack { font: 12px/1.6 var(--ui); color: var(--muted); margin: 7px 0 !important; }
.tree-stack { min-height: 24px; overflow-wrap: anywhere; }
.tree-output { min-height: 58px; max-height: 115px; overflow: auto; padding: 8px 10px; background: #edf2f8; font: 14px/1.6 Consolas, monospace; overflow-wrap: anywhere; }
.tree-guide { padding-left: 24px !important; margin: 0 0 12px !important; font: 14px/1.6 var(--ui); }
.tree-guide li { padding: 4px 6px; margin: 0 0 5px; }
.tree-guide li.active { background: #e6ddf4; box-shadow: -3px 0 0 #80679c; }
.parser-guide { list-style: none; padding-left: 12px !important; }
.tree-details { font: 13px/1.7 var(--ui); overflow-wrap: anywhere; }
.tree-details p { margin: 6px 0; }
.lecture-five .trace-code-wrap pre { max-height: 360px; overflow: auto; font-size: 13px; }
.tree-shapes { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 14px; margin-top: 16px; }
.tree-shape { min-width: 0; }
.tree-shape h3 { font-size: 15px; margin: 0 0 8px; }
.tree-shape .tree-canvas { height: 315px; }
.tree-shape-order { height: 70px; overflow: auto; margin: 8px 0 !important; font: 13px/1.6 Consolas, monospace; overflow-wrap: anywhere; }
.tree-shape-summary { font: 13px/1.7 var(--ui); padding: 8px; background: #edf2fa; }
@media(max-width:900px) {
  .tree-trace-layout { grid-template-columns: minmax(0,1fr); }
  .tree-shapes { gap: 9px; }
  .lecture-five [data-tree="bst-insert"] .demo-controls { gap: 7px; }
  .lecture-five [data-tree="bst-insert"] .step-buttons { gap: 4px; }
  .lecture-five [data-tree="bst-insert"] .step-buttons button { padding-left: 6px; padding-right: 6px; }
}
