:root {
  --bg: #f5f7f2;
  --surface: #ffffff;
  --surface-soft: #f0f4ee;
  --sidebar: #eef2eb;
  --text: #18231e;
  --text-soft: #4f5f56;
  --muted: #718077;
  --border: #d6ddd4;
  --border-strong: #9eaba2;
  --primary: #087b55;
  --primary-dark: #075d42;
  --primary-soft: #d9f0e6;
  --accent: #e65f32;
  --accent-soft: #fee3d9;
  --yellow: #d7a91f;
  --yellow-soft: #fff0b8;
  --success: #087b55;
  --success-soft: #d9f0e6;
  --red: #c33d49;
  --red-soft: #fde4e7;
  --header-height: 64px;
  --sidebar-width: 248px;
  --content-width: 1280px;
}

* { box-sizing: border-box; }
html { background: var(--bg); color: var(--text); scroll-behavior: smooth; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.65 "Manrope", sans-serif; text-rendering: optimizeLegibility; }
button, input, select { font: inherit; }
button { cursor: pointer; }
a { color: inherit; text-underline-offset: 3px; }
svg { display: block; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.skip-link { position: fixed; top: -60px; left: 12px; z-index: 100; background: var(--text); padding: 8px 12px; color: #fff; }
.skip-link:focus { top: 10px; }

.topbar { position: sticky; top: 0; z-index: 50; height: var(--header-height); display: grid; grid-template-columns: auto minmax(260px, 520px) auto; justify-content: space-between; align-items: center; gap: 28px; border-bottom: 1px solid var(--border); background: #fff; padding: 0 22px; }
.brand { display: flex; align-items: center; gap: 9px; color: var(--text); font-size: 21px; font-weight: 700; letter-spacing: -.045em; text-decoration: none; }
.brand-mark { width: 31px; height: 31px; overflow: visible; }
.brand-route { fill: none; stroke: var(--primary); stroke-width: 3.2; stroke-linecap: round; stroke-linejoin: round; }
.brand-node-start { fill: var(--accent); }
.brand-node-turn { fill: var(--yellow); }
.brand-node-end { fill: var(--primary); }
.mobile-menu { display: none; width: 36px; height: 36px; place-items: center; border: 1px solid var(--border); border-radius: 7px; background: var(--surface); padding: 0; }
.mobile-menu svg { width: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.search-wrap { position: relative; width: 100%; }
.search-wrap > svg { position: absolute; top: 12px; left: 12px; width: 16px; height: 16px; fill: none; stroke: var(--muted); stroke-width: 1.8; }
.search-wrap input { width: 100%; height: 40px; border: 1px solid var(--border); border-radius: 7px; background: var(--bg); padding: 0 38px; outline: 0; color: var(--text); }
.search-wrap input:focus { border-color: var(--primary); background: var(--surface); box-shadow: 0 0 0 3px rgb(22 139 98 / 12%); }
.search-wrap kbd { position: absolute; top: 9px; right: 10px; border: 1px solid var(--border-strong); border-radius: 3px; background: var(--surface); padding: 1px 5px; color: var(--muted); font: 10px "IBM Plex Mono", monospace; }
.search-results { position: absolute; top: 46px; right: 0; left: 0; z-index: 70; overflow: hidden; border: 1px solid var(--border-strong); border-radius: 8px; background: var(--surface); box-shadow: 0 4px 8px rgb(28 41 34 / 10%); }
.search-results a { display: block; border-bottom: 1px solid var(--border); padding: 10px 12px; text-decoration: none; }
.search-results a:last-child { border-bottom: 0; }
.search-results a:hover { background: var(--surface-soft); }
.search-results strong { display: block; font-size: 13px; }
.search-results span, .search-results p { color: var(--muted); font-size: 11px; }
.search-results p { margin: 0; padding: 14px; }
.header-progress { display: flex; align-items: center; gap: 11px; border-left: 1px solid var(--border); padding-left: 20px; white-space: nowrap; }
.header-progress span { color: var(--text-soft); font-size: 12px; }
.header-progress strong { color: var(--primary-dark); font: 600 11px "IBM Plex Mono", monospace; }
.legal-topbar { grid-template-columns: auto auto; }
.topnav { display: flex; align-items: center; justify-content: flex-end; gap: 18px; }
.topnav a { color: var(--text-soft); font-size: 12px; font-weight: 500; text-decoration: none; }
.topnav a:hover { color: var(--primary-dark); }

.app-shell { display: grid; grid-template-columns: var(--sidebar-width) minmax(0, 1fr); min-height: calc(100vh - var(--header-height)); }
.sidebar { position: sticky; top: var(--header-height); align-self: start; height: calc(100vh - var(--header-height)); overflow-y: auto; border-right: 1px solid var(--border); background: var(--sidebar); scrollbar-width: thin; }
.sidebar-progress { border-bottom: 1px solid var(--border); padding: 18px 17px 16px; }
.sidebar-progress > div:first-child { display: flex; justify-content: space-between; align-items: baseline; }
.sidebar-progress strong { font-size: 13px; }
.sidebar-progress span { color: var(--primary); font: 600 10px "IBM Plex Mono", monospace; }
.sidebar-progress p { margin: 0; color: var(--muted); font-size: 10px; }
.progress-track { overflow: hidden; height: 5px; margin: 9px 0 7px; background: #dbe3da; }
.progress-track span { display: block; width: 0; height: 100%; background: var(--primary); transition: width 180ms ease; }
.course-level { border-bottom: 1px solid var(--border); }
.course-level-toggle { width: 100%; display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 8px; border: 0; background: transparent; padding: 13px 17px; color: var(--text); text-align: left; }
.course-level-toggle:hover { background: rgb(255 255 255 / 62%); }
.course-level-toggle strong { font-size: 12px; }
.course-level-toggle span { color: var(--muted); font: 10px "IBM Plex Mono", monospace; }
.course-level-toggle svg { width: 13px; fill: none; stroke: var(--muted); stroke-width: 1.8; transition: transform 150ms ease; }
.course-level.is-open .course-level-toggle svg { transform: rotate(90deg); }
.course-level-lessons { display: none; padding: 0 8px 9px; }
.course-level.is-open .course-level-lessons { display: block; }
.course-level-lessons a { display: grid; grid-template-columns: 17px minmax(0, 1fr); gap: 8px; align-items: start; border-radius: 6px; padding: 8px 9px; color: var(--text-soft); text-decoration: none; }
.course-level-lessons a:hover { background: var(--surface); }
.course-level-lessons a.is-current { background: var(--primary-soft); color: var(--primary-dark); }
.course-level-lessons a > span:last-child { min-width: 0; }
.course-level-lessons a strong { display: block; overflow: hidden; font-size: 11px; font-weight: 600; line-height: 1.35; text-overflow: ellipsis; white-space: nowrap; }
.course-level-lessons a em { display: block; overflow: hidden; margin-top: 2px; color: var(--muted); font-size: 9px; font-style: normal; text-overflow: ellipsis; white-space: nowrap; }
.lesson-check { width: 15px; height: 15px; display: grid; place-items: center; border: 1px solid var(--border-strong); border-radius: 50%; margin-top: 1px; color: transparent; font-size: 9px; }
.lesson-check.is-complete { border-color: var(--success); background: var(--success); color: #fff; }
.sidebar-footer { display: grid; gap: 7px; padding: 18px 17px 30px; }
.sidebar-footer button { width: max-content; border: 0; background: transparent; padding: 0; color: var(--text-soft); font-size: 11px; text-decoration: underline; text-underline-offset: 3px; }
.sidebar-footer a { color: var(--text-soft); font-size: 11px; }
.sidebar-footer p { margin: 8px 0 0; color: var(--muted); font-size: 9px; }
.sidebar-backdrop { position: fixed; inset: var(--header-height) 0 0; z-index: 39; background: rgb(28 41 34 / 38%); }

.main-content { min-width: 0; width: min(100%, calc(var(--content-width) + 56px)); margin: 0 auto; padding: 0 28px 70px; }
.module-header { display: flex; justify-content: space-between; align-items: flex-end; gap: 28px; padding: 28px 0 24px; }
.module-header > div:first-child { max-width: 790px; }
.module-header > div > p:first-child { margin: 0 0 5px; color: var(--primary-dark); font-size: 11px; font-weight: 700; }
.module-header h1 { margin: 0 0 7px; font-size: clamp(29px, 3.5vw, 38px); line-height: 1.14; letter-spacing: -.04em; }
.module-header #module-summary { margin: 0; color: var(--text-soft); font-size: 15px; }
.complexity-list { display: flex; align-self: flex-end; gap: 22px; margin: 0; }
.complexity-list div { min-width: 92px; border-left: 2px solid var(--primary); padding-left: 10px; }
.complexity-list dt { color: var(--muted); font-size: 10px; }
.complexity-list dd { margin: 2px 0 0; font: 600 11px "IBM Plex Mono", monospace; }

.lesson-guide { border: 1px solid var(--border); background: var(--surface); }
.lesson-guide-heading { display: flex; justify-content: space-between; align-items: baseline; gap: 20px; border-bottom: 1px solid var(--border); padding: 17px 20px; }
.lesson-guide-heading h2 { margin: 0; font-size: 17px; letter-spacing: -.02em; }
.lesson-guide-heading p { margin: 2px 0 0; color: var(--muted); font-size: 11px; }
.guide-tabs { display: none; }
.concept-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; }
.concept-grid article { min-width: 0; border-right: 1px solid var(--border); padding: 20px; }
.concept-grid article:last-child { border-right: 0; }
.concept-grid h3, .lesson-guide-lower h3 { margin: 0 0 7px; font-size: 12px; }
.concept-grid p { margin: 0; color: var(--text-soft); font-size: 13px; line-height: 1.7; }
.concept-grid .mental-model { background: #fff8e8; }
.lesson-guide-lower { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(260px, .5fr); border-top: 1px solid var(--border); }
.lesson-guide-lower > div { padding: 19px 20px 21px; }
.lesson-guide-lower > div:first-child { border-right: 1px solid var(--border); }
.operation-walkthrough { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0; margin: 12px 0 0; padding: 0; list-style: none; }
.operation-walkthrough li { position: relative; min-height: 76px; border-top: 2px solid var(--border-strong); padding: 12px 13px 0 0; color: var(--text-soft); font-size: 11px; line-height: 1.5; }
.operation-walkthrough li:not(:last-child) { margin-right: 12px; }
.operation-walkthrough li b { display: block; margin-bottom: 4px; color: var(--muted); font: 600 10px "IBM Plex Mono", monospace; }
.operation-walkthrough li.is-current { border-color: var(--accent); color: var(--text); }
.operation-walkthrough li.is-current b { color: var(--accent); }
.operation-walkthrough li.is-complete { border-color: var(--primary); }
.use-list { display: grid; gap: 8px; margin: 10px 0 0; padding-left: 18px; color: var(--text-soft); font-size: 12px; }
.use-list li::marker { color: var(--primary); }

.lab { overflow: hidden; border: 1px solid var(--border); background: var(--surface); margin-top: 24px; }
.lab-heading { display: flex; justify-content: space-between; align-items: baseline; gap: 24px; border-bottom: 1px solid var(--border); padding: 18px 20px; }
.lab-heading h2 { margin: 0; font-size: 17px; letter-spacing: -.02em; }
.lab-heading p { max-width: 720px; margin: 0; color: var(--text-soft); font-size: 12px; text-align: right; }
.control-dock { display: flex; flex-wrap: wrap; align-items: end; gap: 14px; border-bottom: 1px solid var(--border); background: var(--sidebar); padding: 14px 16px; }
.control-field { min-width: 150px; flex: 1 1 190px; }
.control-field label { display: block; margin-bottom: 5px; color: var(--text-soft); font-size: 10px; font-weight: 600; }
.control-field input, .control-field select { width: 100%; height: 38px; border: 1px solid var(--border-strong); border-radius: 6px; background: var(--surface); padding: 0 9px; outline: 0; color: var(--text); }
.control-field input:focus, .control-field select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgb(22 139 98 / 12%); }
.control-field p { margin: 4px 0 0; color: var(--muted); font-size: 9px; line-height: 1.35; }
.speed-field { max-width: 150px; }
.speed-field > div { display: flex; justify-content: space-between; align-items: baseline; }
.speed-field output { color: var(--muted); font: 10px "IBM Plex Mono", monospace; }
.speed-field input { width: 100%; height: auto; padding: 0; accent-color: var(--primary); box-shadow: none !important; }
.playback-controls { display: flex; flex: 0 0 auto; gap: 7px; }
.playback-controls button { min-height: 38px; border: 1px solid var(--border-strong); border-radius: 6px; background: var(--surface); padding: 0 12px; color: var(--text); font-size: 11px; font-weight: 600; }
.playback-controls button:hover { border-color: var(--primary); color: var(--primary-dark); }
.playback-controls button:disabled { cursor: not-allowed; opacity: .45; }
.playback-controls .primary-action { min-width: 78px; display: inline-flex; justify-content: center; align-items: center; gap: 6px; border-color: var(--primary); background: var(--primary); color: #fff; }
.primary-action svg { width: 12px; fill: currentColor; }
.lab-workspace { display: grid; grid-template-columns: minmax(0, 1fr) 350px; min-height: 570px; }
.canvas-column { min-width: 0; background: #f8faf6; }
.canvas-heading { min-height: 58px; display: flex; justify-content: space-between; align-items: center; gap: 20px; border-bottom: 1px solid var(--border); background: var(--surface); padding: 11px 16px; }
.canvas-heading strong { display: block; font-size: 12px; }
.canvas-heading > div:first-child span { display: block; color: var(--muted); font-size: 9px; }
.visual-legend { display: flex; gap: 13px; color: var(--muted); font-size: 9px; white-space: nowrap; }
.visual-legend span { display: flex; align-items: center; gap: 5px; }
.visual-legend i { width: 9px; height: 9px; border: 1px solid var(--border-strong); }
.visual-legend .legend-focus { border-color: var(--accent); background: var(--accent-soft); }
.visual-legend .legend-work { border-color: var(--yellow); background: var(--yellow-soft); }
.visual-legend .legend-done { border-color: var(--primary); background: var(--primary-soft); }
.visual-legend .legend-red { border-color: #a92f25; background: #ef6255; }
.visual-legend .legend-black { border-color: #111815; background: #27312c; }
.visual-legend .legend-repair { border-color: #a57a00; background: var(--yellow-soft); }
.stage-wrap { padding: 0 18px; }
.stage { min-height: 450px; display: grid; place-items: center; overflow: auto; border: 1px solid #d9e1d8; border-top: 0; background: #eef3ec; padding: 28px; }
.status-line { min-height: 61px; display: flex; justify-content: space-between; align-items: center; gap: 16px; border-inline: 1px solid #e0e6de; background: var(--surface); padding: 10px 13px; }
.status-line p { margin: 0; color: var(--text); font-size: 12px; font-weight: 600; }
.status-line strong { flex: 0 0 auto; color: var(--muted); font: 400 10px "IBM Plex Mono", monospace; }
.lab-inspector { min-width: 0; border-left: 1px solid var(--border); background: var(--surface); }
.step-meaning, .code-panel, .trace-panel { padding: 18px 19px; }
.step-meaning { min-height: 150px; border-bottom: 1px solid var(--border); background: #fff8e8; }
.step-meaning p { margin: 0; color: var(--text-soft); font-size: 13px; line-height: 1.7; }
.trace-panel { border-bottom: 1px solid var(--border); }
.panel-heading { display: flex; justify-content: space-between; gap: 16px; margin-bottom: 11px; }
.panel-heading h3 { margin: 0; font-size: 12px; }
.panel-heading span { color: var(--muted); font-size: 9px; }
.pseudocode { margin: 0; padding: 0; list-style-position: inside; color: var(--muted); font: 10px/1.75 "IBM Plex Mono", monospace; }
.pseudocode li { padding: 2px 7px; white-space: pre-wrap; }
.pseudocode li::marker { color: var(--border-strong); }
.pseudocode li.is-current { background: var(--primary-soft); color: var(--primary-dark); }
.trace-panel dl { margin: 0; }
.trace-panel dl div { display: flex; justify-content: space-between; border-top: 1px solid var(--border); padding: 8px 0; }
.trace-panel dt { color: var(--muted); font-size: 10px; }
.trace-panel dd { margin: 0; font: 600 10px "IBM Plex Mono", monospace; }

.array-visual { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px; }
.array-cell { position: relative; min-width: 60px; height: 60px; display: grid; place-items: center; border: 1px solid var(--border-strong); background: var(--surface); font: 600 13px "IBM Plex Mono", monospace; transition: background-color 160ms ease, border-color 160ms ease, opacity 160ms ease; }
.array-cell em { position: absolute; bottom: -23px; color: var(--muted); font: 9px "IBM Plex Mono", monospace; }
.array-cell.is-active, .array-cell.is-pivot, .array-cell.is-active-range { border-color: var(--accent); background: var(--accent-soft); color: #80341c; }
.array-cell.is-compared { border-color: var(--yellow); background: var(--yellow-soft); }
.array-cell.is-found, .array-cell.is-sorted { border-color: var(--success); background: var(--success-soft); color: var(--primary-dark); }
.array-cell.is-outside { opacity: .25; }
.bar-visual { width: min(100%, 720px); height: 300px; display: flex; justify-content: center; align-items: end; gap: clamp(6px, 1.2vw, 12px); padding: 30px 12px; }
.bar-item { position: relative; width: min(58px, 10%); min-width: 30px; display: flex; justify-content: center; align-items: end; border: 1px solid #7bb29d; border-bottom: 4px solid var(--primary-dark); background: #bde7d5; transition: height 240ms ease, background-color 160ms ease, opacity 160ms ease; }
.bar-item span { position: absolute; bottom: -27px; font: 600 10px "IBM Plex Mono", monospace; }
.bar-item em { position: absolute; top: -22px; color: var(--muted); font: 9px "IBM Plex Mono", monospace; }
.bar-item.is-compared { border-color: var(--yellow); background: var(--yellow-soft); }
.bar-item.is-active, .bar-item.is-pivot, .bar-item.is-active-range { border-color: var(--accent); background: var(--accent); }
.bar-item.is-found, .bar-item.is-sorted { border-color: var(--success); background: #63c49d; }
.bar-item.is-outside { opacity: .25; }

.linked-visual { min-width: max-content; display: flex; align-items: center; justify-content: center; gap: 9px; }
.linked-node { display: grid; grid-template-columns: 58px 38px; border: 1px solid var(--border-strong); background: var(--surface); }
.linked-node span, .linked-node em { min-height: 52px; display: grid; place-items: center; }
.linked-node span { font: 600 12px "IBM Plex Mono", monospace; }
.linked-node em { border-left: 1px solid var(--border); color: var(--muted); font-size: 8px; font-style: normal; }
.linked-node.is-active { border-color: var(--accent); background: var(--accent-soft); }
.linked-node.is-found { border-color: var(--success); background: var(--success-soft); }
.linked-visual > b { color: var(--muted); font-weight: 400; }
.stack-visual { width: 180px; display: grid; gap: 4px; text-align: center; }
.stack-visual p { margin: 0 0 4px; color: var(--muted); font: 9px "IBM Plex Mono", monospace; }
.stack-visual > span { color: var(--muted); font-size: 12px; }
.stack-cell { min-height: 44px; display: grid; place-items: center; border: 1px solid var(--border-strong); background: var(--surface-soft); font: 600 12px "IBM Plex Mono", monospace; }
.stack-cell.is-active { border-color: var(--accent); background: var(--accent-soft); }
.queue-wrap { min-width: 360px; }
.queue-labels { display: flex; justify-content: space-between; margin-bottom: 7px; color: var(--muted); font: 9px "IBM Plex Mono", monospace; }
.queue-visual { min-height: 62px; display: flex; align-items: stretch; border-block: 2px solid var(--primary-dark); padding: 6px 0; }
.queue-cell { min-width: 64px; display: grid; place-items: center; border-right: 1px solid var(--border); background: var(--surface-soft); font: 600 12px "IBM Plex Mono", monospace; }
.queue-cell.is-active { background: var(--accent-soft); color: #80341c; }
.queue-visual > span { margin: auto; color: var(--muted); }
.hash-visual { width: min(100%, 620px); display: grid; gap: 7px; }
.hash-row { display: grid; grid-template-columns: 42px minmax(0, 1fr); min-height: 42px; border: 1px solid var(--border); background: var(--surface); }
.hash-row > strong { display: grid; place-items: center; border-right: 1px solid var(--border); background: var(--sidebar); font: 600 10px "IBM Plex Mono", monospace; }
.hash-row > div { display: flex; align-items: center; gap: 7px; padding: 6px 9px; }
.hash-row span, .hash-row i { min-width: 42px; min-height: 28px; display: grid; place-items: center; border: 1px solid var(--border-strong); background: var(--surface-soft); font: 600 10px "IBM Plex Mono", monospace; font-style: normal; }
.hash-row i { border-color: var(--accent); background: var(--accent-soft); }
.hash-row em { color: var(--muted); font-size: 10px; }
.hash-row b { color: var(--muted); font-weight: 400; }
.hash-row.is-active { border-color: var(--accent); }

.tree-svg, .graph-svg { width: min(100%, 820px); height: 340px; overflow: visible; }
.tree-svg line { stroke: var(--border-strong); stroke-width: 2; }
.tree-node circle { fill: var(--surface); stroke: var(--primary); stroke-width: 2; transition: fill 160ms ease, stroke 160ms ease; }
.tree-node text { fill: var(--text); font: 600 11px "IBM Plex Mono", monospace; text-anchor: middle; dominant-baseline: middle; }
.tree-node .node-range { fill: var(--muted); font-size: 7px; }
.tree-node.is-active circle { fill: var(--accent-soft); stroke: var(--accent); stroke-width: 3; }
.tree-node.is-found circle { fill: var(--success-soft); stroke: var(--success); stroke-width: 3; }
.tree-node.is-black circle { fill: #303833; stroke: #111; }
.tree-node.is-black text { fill: #fff; }
.tree-node.is-red circle { fill: #ee6b5c; stroke: #9d2f25; }
.tree-node.is-red text { fill: #fff; }
.tree-node.is-red.is-active circle, .tree-node.is-black.is-active circle { stroke: var(--yellow); stroke-width: 5; }
.trie-svg .tree-node.is-word circle { stroke-width: 5; }
.heap-visual { width: 100%; }
.heap-svg { height: 280px; }
.heap-array, .segment-array { display: flex; justify-content: center; gap: 4px; }
.heap-array span, .segment-array span { position: relative; min-width: 48px; min-height: 42px; display: grid; place-items: center; border: 1px solid var(--border-strong); background: var(--surface-soft); }
.heap-array span.is-active { border-color: var(--accent); background: var(--accent-soft); }
.heap-array b, .segment-array b { font: 600 10px "IBM Plex Mono", monospace; }
.heap-array em, .segment-array em { position: absolute; bottom: -17px; color: var(--muted); font: 8px "IBM Plex Mono", monospace; }
.forest-visual { width: min(100%, 760px); display: flex; flex-wrap: wrap; justify-content: center; align-items: flex-start; gap: 26px; }
.forest-group { min-width: 110px; text-align: center; }
.forest-group > strong { width: 44px; height: 44px; display: grid; place-items: center; border: 2px solid var(--primary); border-radius: 50%; margin: 0 auto 24px; background: var(--surface); font: 600 11px "IBM Plex Mono", monospace; }
.forest-group > div { display: flex; justify-content: center; gap: 5px; border-top: 1px solid var(--border-strong); padding-top: 10px; }
.forest-group span { width: 34px; height: 34px; display: grid; place-items: center; border: 1px solid var(--border-strong); background: var(--surface-soft); font: 600 10px "IBM Plex Mono", monospace; }
.forest-group .is-active { border-color: var(--accent); background: var(--accent-soft); }
.forest-group em { color: var(--muted); font-size: 9px; }

.graph-edge { stroke: var(--border-strong); stroke-width: 2; transition: stroke 160ms ease, opacity 160ms ease; }
.graph-edge.is-traversed, .graph-edge.is-selected { stroke: var(--primary); stroke-width: 4; }
.graph-edge.is-candidate { stroke: var(--accent); stroke-width: 4; }
.graph-edge.is-rejected { stroke: var(--red); stroke-dasharray: 5 5; opacity: .45; }
.graph-edge.is-removed { opacity: .15; }
.graph-svg marker path { fill: var(--border-strong); }
.graph-node circle { fill: var(--surface); stroke: var(--text); stroke-width: 2; }
.graph-node > text:not(.graph-distance) { fill: var(--text); font: 600 13px "IBM Plex Mono", monospace; text-anchor: middle; dominant-baseline: middle; }
.graph-node.is-queued circle { fill: var(--yellow-soft); stroke: var(--yellow); }
.graph-node.is-visited circle { fill: var(--primary-soft); stroke: var(--primary); }
.graph-node.is-current circle { fill: var(--accent); stroke: #a93b17; }
.graph-node.is-current text { fill: #fff; }
.graph-distance { fill: var(--text-soft); font: 600 9px "IBM Plex Mono", monospace; text-anchor: middle; }
.graph-weight { fill: var(--accent); font: 600 10px "IBM Plex Mono", monospace; text-anchor: middle; paint-order: stroke; stroke: var(--surface); stroke-width: 4px; }
.graph-queue-label { fill: var(--muted); font: 600 9px "IBM Plex Mono", monospace; }
.graph-queue-box { fill: var(--surface); stroke: var(--border-strong); }
.graph-queue-text { fill: var(--text); font: 600 10px "IBM Plex Mono", monospace; text-anchor: middle; dominant-baseline: middle; }

.segment-visual { width: 100%; }
.segment-visual .tree-svg { height: 300px; }
.fenwick-visual { width: min-content; display: grid; gap: 28px; }
.fenwick-row { display: grid; grid-template-columns: 46px repeat(var(--count, 8), 58px); gap: 4px; align-items: center; }
.fenwick-row strong { color: var(--muted); font-size: 10px; }
.fenwick-row span { position: relative; width: 58px; min-height: 48px; display: grid; place-items: center; border: 1px solid var(--border-strong); background: var(--surface); }
.fenwick-row span b { font: 600 10px "IBM Plex Mono", monospace; }
.fenwick-row span em { position: absolute; bottom: -17px; color: var(--muted); font: 7px "IBM Plex Mono", monospace; }
.fenwick-row span.is-active { border-color: var(--primary); background: var(--primary-soft); }
.fenwick-row span.is-current { border-color: var(--accent); background: var(--accent-soft); }
.string-visual { min-width: max-content; }
.string-row { display: flex; align-items: center; gap: 3px; }
.string-row + .string-row { margin-top: 26px; }
.string-row > strong { width: 58px; color: var(--muted); font-size: 9px; }
.string-row span { position: relative; width: 32px; height: 38px; display: grid; place-items: center; border: 1px solid var(--border); background: var(--surface); font: 600 10px "IBM Plex Mono", monospace; }
.string-row span em { position: absolute; bottom: -17px; color: var(--muted); font: 7px "IBM Plex Mono", monospace; }
.string-row span.is-active { border-color: var(--accent); background: var(--accent-soft); }
.string-row span.is-matched { border-color: var(--success); background: var(--success-soft); }
.pattern-row > div { display: flex; gap: 3px; margin-left: calc(var(--offset) * 35px); }
.string-visual > p { margin: 28px 0 0 61px; color: var(--muted); font-size: 9px; }

.quiz-card { overflow: hidden; border: 1px solid var(--border); border-radius: 9px; background: var(--surface); margin-top: 24px; }
.quiz-header { display: flex; justify-content: space-between; align-items: center; gap: 24px; border-bottom: 1px solid #cbe6d8; background: var(--primary-soft); padding: 18px 20px; }
.quiz-header h2 { margin: 0 0 3px; font-size: 18px; }
.quiz-header p { margin: 0; color: var(--text-soft); font-size: 11px; }
.quiz-progress { width: 96px; flex: 0 0 auto; }
.quiz-progress strong { display: block; margin-bottom: 6px; color: var(--primary-dark); font: 600 10px "IBM Plex Mono", monospace; text-align: right; }
.quiz-progress > span { display: block; overflow: hidden; height: 5px; background: #bcdccb; }
.quiz-progress i { display: block; width: 50%; height: 100%; background: var(--primary); transition: width 180ms ease; }
.quiz-form { padding: 20px; }
.quiz-question { border: 0; margin: 0; padding: 0; }
.quiz-question legend { width: 100%; margin: 0 0 15px; padding: 0; font-size: 16px; font-weight: 600; }
.quiz-question legend > span { display: block; margin-bottom: 4px; color: var(--primary-dark); font: 600 9px "IBM Plex Mono", monospace; }
.quiz-options { display: grid; gap: 8px; }
.quiz-option { position: relative; min-height: 52px; display: grid; grid-template-columns: 32px minmax(0, 1fr); align-items: center; gap: 10px; border: 1px solid var(--border); border-radius: 7px; padding: 8px 11px; cursor: pointer; }
.quiz-option:hover { border-color: var(--border-strong); background: var(--bg); }
.quiz-option:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.quiz-option:has(input:focus-visible) { outline: 2px solid var(--primary); outline-offset: 2px; }
.quiz-option input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.option-letter { width: 28px; height: 28px; display: grid; place-items: center; border: 1px solid var(--border-strong); border-radius: 5px; background: var(--surface-soft); font: 600 10px "IBM Plex Mono", monospace; }
.quiz-option:has(input:checked) .option-letter { border-color: var(--primary); background: var(--primary); color: #fff; }
.quiz-option.is-correct { border-color: var(--success); background: var(--success-soft); }
.quiz-option.is-correct .option-letter { border-color: var(--success); background: var(--success); color: #fff; }
.quiz-option.is-wrong { border-color: var(--red); background: var(--red-soft); }
.quiz-option.is-wrong .option-letter { border-color: var(--red); background: var(--red); color: #fff; }
.quiz-explanation { border-left: 3px solid var(--accent); margin: 14px 0 0; background: var(--accent-soft); padding: 10px 12px; color: #743019; font-size: 11px; }
.quiz-submit-row { display: flex; justify-content: space-between; align-items: center; gap: 18px; border-top: 1px solid var(--border); margin-top: 18px; padding-top: 16px; }
.quiz-submit-row p { margin: 0; color: var(--muted); font-size: 10px; }
.primary-button { min-height: 36px; border: 1px solid var(--primary); border-radius: 6px; background: var(--primary); padding: 0 13px; color: #fff; font-size: 11px; font-weight: 600; }
.quiz-result { border-radius: 6px; margin-top: 13px; padding: 11px 13px; font-size: 12px; font-weight: 600; }
.quiz-result.is-pass { background: var(--success-soft); color: var(--primary-dark); }
.quiz-result.is-retry { background: var(--accent-soft); color: #743019; }

.ad-placement { min-height: 100px; margin-top: 24px; overflow: hidden; }
.ad-unit, .adsbygoogle { width: 100%; min-height: 100px; }
.module-navigation { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 24px; }
.module-navigation a { border: 1px solid var(--border); border-radius: 7px; background: var(--surface); padding: 12px 14px; text-decoration: none; }
.module-navigation a:last-child { text-align: right; }
.module-navigation span { display: block; color: var(--muted); font-size: 9px; }
.module-navigation strong { font-size: 11px; }
.keyboard-help { display: flex; justify-content: flex-end; gap: 7px; margin: 9px 0 0; color: var(--muted); font-size: 9px; }
kbd { border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 3px; background: var(--surface); padding: 1px 5px; font: 9px "IBM Plex Mono", monospace; }
.toast { position: fixed; right: 20px; bottom: 20px; z-index: 90; max-width: 320px; border: 1px solid var(--primary); border-radius: 6px; background: var(--primary-dark); padding: 11px 14px; color: #fff; font-size: 11px; box-shadow: 0 2px 8px rgb(28 41 34 / 14%); }
dialog { width: min(calc(100% - 28px), 440px); border: 1px solid var(--border-strong); border-radius: 8px; background: var(--surface); color: var(--text); padding: 0; }
dialog::backdrop { background: rgb(28 41 34 / 45%); }
dialog form { padding: 21px; }
dialog h2 { margin: 0 0 7px; font-size: 18px; }
dialog p { margin: 0; color: var(--text-soft); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.dialog-actions button { min-height: 36px; border: 1px solid var(--border-strong); border-radius: 6px; background: var(--surface); padding: 0 12px; font-size: 11px; font-weight: 600; }
.dialog-actions .danger-button { border-color: var(--red); color: var(--red); }

.legal-shell { min-height: calc(100vh - var(--header-height)); }
.legal-main { width: min(calc(100% - 32px), 760px); margin: 0 auto; padding: 52px 0 80px; }
.legal-main h1 { margin: 0 0 9px; font-size: clamp(32px, 6vw, 48px); letter-spacing: -.045em; }
.legal-main .standfirst { margin: 0 0 34px; color: var(--text-soft); font-size: 17px; }
.legal-main h2 { margin: 32px 0 7px; font-size: 18px; }
.legal-main p, .legal-main li { color: var(--text-soft); line-height: 1.75; }
.policy-date { color: var(--muted) !important; font-size: 10px; }
.legal-footer { border-top: 1px solid var(--border); background: var(--surface); padding: 20px; color: var(--muted); font-size: 10px; text-align: center; }

@media (max-width: 1100px) {
  .topbar { grid-template-columns: auto minmax(220px, 1fr) auto; gap: 16px; }
  .control-field { flex-basis: 160px; }
  .module-header { align-items: flex-start; }
  .concept-grid { grid-template-columns: 1fr 1fr; }
  .concept-grid .mental-model { grid-column: 1 / -1; border-top: 1px solid var(--border); }
  .lab-workspace { grid-template-columns: 1fr; }
  .lab-inspector { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); border-top: 1px solid var(--border); border-left: 0; }
  .step-meaning { grid-column: 1 / -1; min-height: 0; }
  .trace-panel { border-right: 1px solid var(--border); border-bottom: 0; }
}

@media (max-width: 900px) {
  .topbar { grid-template-columns: auto auto minmax(180px, 1fr) auto; }
  .mobile-menu { display: grid; }
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; top: var(--header-height); bottom: 0; left: 0; z-index: 40; width: var(--sidebar-width); height: auto; transform: translateX(-100%); transition: transform 170ms ease; }
  .sidebar.is-open { transform: translateX(0); }
  .main-content { padding-inline: 22px; }
}

@media (max-width: 700px) {
  :root { --header-height: 58px; }
  .topbar { grid-template-columns: auto 1fr auto; gap: 9px; padding-inline: 11px; }
  .legal-topbar { grid-template-columns: 1fr auto; }
  .topnav { gap: 11px; }
  .topnav a { font-size: 10px; }
  .search-wrap { display: none; }
  .header-progress { border-left: 0; padding-left: 0; }
  .header-progress span { display: none; }
  .brand { font-size: 19px; }
  .brand-mark { width: 27px; height: 27px; }
  .main-content { padding: 0 13px 52px; }
  .module-header { display: block; padding-top: 24px; }
  .module-header h1 { font-size: 31px; }
  .module-header #module-summary { font-size: 13px; }
  .complexity-list { margin-top: 17px; }
  .complexity-list div { min-width: 0; }
  .lesson-guide-heading, .lab-heading { display: block; }
  .lesson-guide-heading p, .lab-heading p { margin-top: 5px; text-align: left; }
  .guide-tabs { display: flex; border-top: 1px solid var(--border); margin: 14px -20px -17px; padding-inline: 9px; }
  .guide-tabs button { flex: 1; border: 0; border-bottom: 2px solid transparent; background: transparent; padding: 10px 4px 8px; color: var(--muted); font-size: 10px; font-weight: 700; }
  .guide-tabs button[aria-selected="true"] { border-color: var(--primary); color: var(--primary-dark); }
  .concept-grid { grid-template-columns: 1fr; }
  .concept-grid article { display: none; min-height: 194px; border-right: 0; border-bottom: 0; }
  .concept-grid article.is-active { display: block; }
  .concept-grid .mental-model { grid-column: auto; border-top: 0; }
  .lesson-guide-lower { grid-template-columns: 1fr; }
  .lesson-guide-lower > div:first-child { border-right: 0; border-bottom: 1px solid var(--border); }
  .operation-walkthrough { grid-template-columns: 1fr; }
  .operation-walkthrough li { min-height: 0; border-top: 0; border-left: 2px solid var(--border-strong); padding: 4px 0 12px 12px; }
  .operation-walkthrough li:not(:last-child) { margin: 0; }
  .control-dock { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 13px; }
  .control-field { min-width: 0; }
  .speed-field { max-width: none; }
  .playback-controls { grid-column: 1 / -1; }
  .canvas-heading { display: block; }
  .visual-legend { margin-top: 9px; }
  .stage-wrap { padding-inline: 10px; }
  .stage { min-height: 360px; padding-inline: 10px; }
  .status-line { align-items: flex-start; flex-direction: column; gap: 4px; }
  .lab-inspector { grid-template-columns: 1fr; }
  .step-meaning { grid-column: auto; }
  .trace-panel { border-right: 0; border-bottom: 1px solid var(--border); }
  .array-cell { min-width: 46px; height: 50px; }
  .linked-node { grid-template-columns: 46px 28px; }
  .linked-node span, .linked-node em { min-height: 46px; }
  .tree-svg, .graph-svg { min-width: 630px; }
  .stage:has(.tree-svg), .stage:has(.graph-svg), .stage:has(.string-visual), .stage:has(.fenwick-visual) { place-items: center start; }
  .quiz-form { padding-inline: 14px; }
  .quiz-submit-row { align-items: flex-start; flex-direction: column; }
  .module-navigation { grid-template-columns: 1fr; }
  .module-navigation a:last-child { text-align: left; }
}

@media (max-width: 430px) {
  .control-dock { grid-template-columns: 1fr; }
  .playback-controls { grid-column: auto; flex-wrap: wrap; }
  .playback-controls button { flex: 1; }
  .visual-legend { display: grid; grid-template-columns: repeat(3, auto); gap: 7px; }
  .quiz-header { align-items: flex-start; }
  .quiz-progress { width: 72px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
