:root {
  color-scheme: dark;
  --ground: #101110;
  --surface: #1a1c19;
  --raised: #242722;
  --line: #373b35;
  --ink: #e8eeec;
  --muted: #a6aaa0;
  --signal: #76cfdd;
  --reference: #e2bc74;
  --range: #83979d;
  --complete: #9db89a;
  --paper: #e1e6dc;
  --paper-ink: #1c2520;
  font-family: "IBM Plex Sans", system-ui, sans-serif;
}

* { box-sizing: border-box; }
body { min-width: 320px; margin: 0; background: var(--ground); color: var(--ink); }
button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .42; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--signal); outline-offset: 3px; }

.navbar { display: grid; grid-template-columns: 1fr auto; align-items: center; height: 66px; padding: 0 max(32px, calc((100vw - 1560px) / 2)); border-bottom: 1px solid var(--line); }
.brand { display: inline-flex; align-items: center; gap: 10px; width: fit-content; color: var(--ink); text-decoration: none; font: 600 15px "IBM Plex Mono", monospace; letter-spacing: -.035em; }
.brand-symbol { display: grid; place-items: center; width: 30px; height: 30px; background: var(--ink); color: var(--ground); font-size: 14px; }
.navbar ul { display: flex; justify-content: flex-end; gap: 30px; height: 100%; margin: 0; padding: 0; list-style: none; }
.navbar li { display: flex; align-items: center; }
.navbar a:not(.brand) { color: var(--muted); text-decoration: none; font-size: 13px; }
.navbar a:not(.brand):hover, .navbar a[aria-current] { color: var(--ink); }
.navbar a[aria-current] { font-weight: 600; }

.app-shell { max-width: 1560px; margin: 0 auto; padding: 26px 32px 54px; }
.page-heading { display: flex; justify-content: space-between; align-items: end; gap: 20px; margin-bottom: 24px; }
.chapter-label { color: var(--signal); font: 12px "IBM Plex Sans", sans-serif; }
.page-heading h1 { margin: 9px 0 7px; font-size: clamp(26px, 2.5vw, 32px); font-weight: 500; letter-spacing: -.045em; line-height: 1.1; }
.page-heading p { margin: 0; color: var(--muted); font-size: 14px; }
.heading-aside { display: flex; align-items: center; gap: 13px; padding-bottom: 3px; }
.heading-aside strong { color: var(--ink); font: 400 34px "IBM Plex Mono", monospace; line-height: 1; }
.heading-aside span { color: var(--muted); font-size: 12px; line-height: 1.4; }

.study-layout { display: grid; grid-template-columns: 205px minmax(0, 1fr); gap: 24px; }
.algorithm-selector { border-top: 1px solid var(--line); }
.selector-heading { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; padding: 17px 0 18px; }
.selector-heading h2 { margin: 0; font-size: 15px; font-weight: 600; }
.selector-heading span { color: var(--muted); font: 12px "IBM Plex Sans", sans-serif; white-space: nowrap; }
.btns-container { display: flex; flex-direction: column; }
.algorithm-btn { display: flex; align-items: flex-start; gap: 12px; min-height: 72px; width: 100%; padding: 14px 10px 11px 8px; border: 0; border-top: 1px solid var(--line); background: transparent; color: var(--muted); text-align: left; }
.algorithm-btn:last-child { border-bottom: 1px solid var(--line); }
.algorithm-btn:hover { background: var(--raised); color: var(--ink); }
.algorithm-btn[aria-pressed="true"] { background: var(--raised); color: var(--ink); border-left: 2px solid var(--signal); padding-left: 6px; }
.algorithm-number { padding-top: 2px; color: var(--signal); font: 11px "IBM Plex Mono", monospace; }
.algorithm-name { display: block; font-size: 14px; font-weight: 600; line-height: 1.35; }
.algorithm-name small { display: block; margin-top: 3px; color: var(--muted); font-size: 12px; font-weight: 400; }
.selector-note { margin: 18px 0 0; color: var(--muted); font-size: 12px; line-height: 1.6; }

.study-content { min-width: 0; }
.workspace { display: grid; grid-template-columns: minmax(0, 1.78fr) minmax(300px, .92fr); align-items: stretch; gap: 14px; }
.visual-panel { min-width: 0; padding: 22px; background: var(--surface); }
.panel-heading { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 20px; }
.panel-eyebrow { display: block; margin-bottom: 7px; color: var(--muted); font: 12px "IBM Plex Sans", sans-serif; }
.panel-heading h2 { margin: 0; font-size: 25px; font-weight: 500; letter-spacing: -.035em; }
.run-state { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font: 12px "IBM Plex Mono", monospace; white-space: nowrap; }
.state-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.run-state[data-state="running"] .state-dot, .run-state[data-state="finished"] .state-dot { background: var(--complete); }
.run-state[data-state="paused"] .state-dot { background: var(--reference); }

.control-panel { display: grid; grid-template-columns: 82px 138px minmax(120px, 1fr) 148px; align-items: end; gap: 12px; margin-bottom: 18px; padding: 14px 0 15px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.control-field label { display: block; margin-bottom: 7px; color: var(--muted); font-size: 12px; }
.control-field select { width: 100%; height: 36px; padding: 0 8px; border: 1px solid #565b52; border-radius: 0; background: var(--surface); color: var(--ink); font-size: 13px; }
.speed-field { min-width: 0; }
.speed-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 6px; }
.speed-heading output { color: var(--ink); font: 12px "IBM Plex Mono", monospace; white-space: nowrap; }
.speed-field input[type="range"] { display: block; width: 100%; height: 36px; margin: 0; appearance: none; -webkit-appearance: none; background: transparent; }
.speed-field input[type="range"]::-webkit-slider-runnable-track { height: 2px; background: #73796f; }
.speed-field input[type="range"]::-moz-range-track { height: 2px; background: #73796f; }
.speed-field input[type="range"]::-webkit-slider-thumb { width: 14px; height: 14px; margin-top: -6px; border: 2px solid var(--ground); border-radius: 50%; background: var(--ink); appearance: none; -webkit-appearance: none; }
.speed-field input[type="range"]::-moz-range-thumb { width: 12px; height: 12px; border: 2px solid var(--ground); border-radius: 50%; background: var(--ink); box-shadow: 0 0 0 1px var(--ink); }
.speed-ends { display: flex; justify-content: space-between; color: var(--muted); font: 11px "IBM Plex Sans", sans-serif; }
.start-btn { display: flex; justify-content: center; align-items: center; gap: 9px; min-height: 42px; padding: 0 12px; border: 0; border-radius: 0; background: var(--ink); color: var(--ground); font-size: 14px; font-weight: 600; white-space: nowrap; }
.start-btn:hover { background: #d6ded2; }
.start-btn > span:first-child { font-size: 11px; }

.canvas-frame { overflow: hidden; background: #111310; }
canvas { display: block; width: 100%; height: auto; aspect-ratio: 1000 / 420; }
.canvas-scale { display: flex; justify-content: space-between; padding: 8px 11px 10px; color: #b1b8aa; font: 11px "IBM Plex Sans", sans-serif; }
.stage-footer { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 14px 18px; padding: 18px 0; border-bottom: 1px solid var(--line); }
.visual-key { display: flex; flex-wrap: wrap; gap: 8px 14px; color: var(--muted); font-size: 11px; }
.visual-key span { display: inline-flex; align-items: center; gap: 6px; }
.visual-key span::before { width: 8px; height: 8px; content: ""; }
.key-active::before { background: var(--signal); }.key-reference::before { background: var(--reference); }.key-range::before { background: var(--range); }.key-complete::before { background: var(--complete); }
.playback-controls { display: flex; gap: 7px; }
.playback-controls button { min-height: 32px; padding: 0 10px; border: 1px solid #565b52; border-radius: 0; background: transparent; color: var(--ink); font-size: 12px; }
.playback-controls button:not(:disabled):hover { background: var(--raised); }
.metrics { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); margin-top: 15px; }
.metrics > div { display: flex; flex-direction: column; gap: 3px; padding: 0 14px; border-left: 1px solid var(--line); }
.metrics > div:first-child { padding-left: 0; border-left: 0; }
.metrics span { color: var(--muted); font-size: 11px; }
.metrics strong, .metrics output { color: var(--ink); font: 500 20px "IBM Plex Mono", monospace; font-variant-numeric: tabular-nums; }

.lesson-panel { min-width: 0; display: flex; flex-direction: column; padding: 22px 23px; background: var(--paper); color: var(--paper-ink); }
.lesson-header { padding-bottom: 17px; border-bottom: 1px solid #a9b2a5; }
.lesson-header > span { color: #4f5e52; font: 12px "IBM Plex Sans", sans-serif; }
.lesson-header h2 { margin: 9px 0 0; font-size: 24px; font-weight: 500; letter-spacing: -.04em; }
.lesson-section { padding: 21px 0; border-bottom: 1px solid #a9b2a5; }
.lesson-section h3 { margin: 0 0 10px; color: #586559; font: 500 11px "IBM Plex Mono", monospace; }
.lesson-section p { margin: 0; font-size: 14px; line-height: 1.55; }
.complexity { margin-top: 13px !important; color: #586559; font-size: 12px !important; }
.complexity strong { margin-left: 5px; color: var(--paper-ink); font: 600 12px "IBM Plex Mono", monospace; }
.step-label { display: flex; justify-content: space-between; gap: 10px; }
.step-label span { color: #4f5e52; font: 11px "IBM Plex Mono", monospace; text-align: right; }
.algorithm-status { min-height: 43px; color: var(--paper-ink); font-weight: 600; overflow-wrap: anywhere; }
.step-explanation { margin-top: 8px !important; color: #4c594f; font-size: 13px !important; }
#lesson-variables { margin: 0; }
#lesson-variables div { display: flex; justify-content: space-between; gap: 15px; padding: 8px 0; border-bottom: 1px solid #c1c9be; }
#lesson-variables div:last-child { border-bottom: 0; }
#lesson-variables dt { color: #4f5e52; font-size: 12px; }
#lesson-variables dd { margin: 0; color: var(--paper-ink); font: 500 12px "IBM Plex Mono", monospace; text-align: right; overflow-wrap: anywhere; }
.lesson-footnote { margin: auto 0 0; padding-top: 18px; color: #586559; font-size: 11px; line-height: 1.5; }

@media (max-width: 1220px) {
  .study-layout { grid-template-columns: 175px minmax(0, 1fr); gap: 18px; }
  .workspace { grid-template-columns: minmax(0, 1.5fr) minmax(270px, .9fr); }
  .control-panel { grid-template-columns: 68px 118px minmax(95px, 1fr); }
  .start-btn { grid-column: 1 / -1; }
}
@media (max-width: 960px) {
  .study-layout { grid-template-columns: 1fr; }
  .btns-container { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 10px; }
  .selector-note { margin: 10px 0 0; }
  .workspace { grid-template-columns: minmax(0, 1.45fr) minmax(265px, .9fr); }
  .control-panel { grid-template-columns: 68px 118px minmax(95px, 1fr); }
  .start-btn { grid-column: 1 / -1; }
}
@media (max-width: 720px) {
  .navbar { grid-template-columns: 1fr auto; height: 56px; padding: 0 16px; }
  .navbar ul { gap: 18px; }
  .app-shell { padding: 25px 16px 40px; }
  .page-heading { margin-bottom: 25px; }.page-heading h1 { font-size: 29px; }.heading-aside { display: none; }
  .btns-container { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 8px; }
  .algorithm-btn { min-height: 64px; padding: 10px 7px; }
  .algorithm-number { font-size: 10px; }.algorithm-name { font-size: 13px; }.algorithm-name small { font-size: 11px; }
  .selector-note { display: none; }
  .workspace { grid-template-columns: 1fr; }
  .visual-panel, .lesson-panel { padding: 16px; }
  .control-panel { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 13px; }
  .speed-field { grid-column: 1 / -1; }.start-btn { grid-column: 1 / -1; }
  .stage-footer { align-items: stretch; flex-direction: column; }
  .playback-controls { display: grid; grid-template-columns: repeat(3, 1fr); }.playback-controls button { padding: 0 4px; }
  .lesson-footnote { margin-top: 20px; }
}
