:root {
  color-scheme: light;
  --paper: #f7f8f4;
  --panel: #ffffff;
  --soft: #eef2e9;
  --ink: #24392c;
  --muted: #465b49;
  --line: #cdd8ca;
  --accent: #315740;
  --error: #8a3527;
  --error-bg: #fbefeb;
  font: 16px/1.55 system-ui, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; color: var(--ink); background: var(--paper); }
[hidden] { display: none !important; }
button, input, textarea, select { font: inherit; color: inherit; }
button, summary, select { cursor: pointer; }
button:disabled { opacity: .55; cursor: not-allowed; }
:focus-visible { outline: 3px solid #3a8461; outline-offset: 3px; }
button, select, input[type="number"] { min-height: 44px; }
a { color: #2f6748; }
h1, h2, h3 { line-height: 1.2; overflow-wrap: anywhere; }
h1 { font-size: clamp(2rem, 4vw, 3rem); margin: 0 0 .65rem; }
h2 { font-size: 1.45rem; margin: 0 0 .7rem; }
h3 { font-size: 1.05rem; margin: 0 0 .6rem; }
p { margin: 0 0 .85rem; }
svg { display: block; max-width: 100%; }
.skip { position: fixed; z-index: 10; left: 1rem; top: 1rem; padding: .65rem; background: var(--panel); transform: translateY(-150%); }
.skip:focus { transform: none; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.noscript { margin: 1rem; }

.sidebar { position: fixed; inset: 0 auto 0 0; width: 250px; padding: 22px 16px; border-right: 1px solid var(--line); background: var(--soft); display: flex; flex-direction: column; gap: 12px; }
.brand { display: flex; align-items: center; gap: .7rem; font-weight: 700; color: var(--ink); text-decoration: none; line-height: 1.15; }
.brand-title { font-size: 1.05rem; }
.brand-dot { color: #5a7b50; }
.progress-label { display: flex; justify-content: space-between; gap: .5rem; font-size: .88rem; }
.progress-track { height: 5px; border-radius: 8px; background: #dae4d5; overflow: hidden; }
#progress-bar { height: 100%; background: #4c815d; }
.course-search input { width: 100%; padding: .5rem; border: 1px solid var(--line); border-radius: 5px; background: var(--panel); }
#lessons { overflow: auto; min-height: 0; }
#lessons a { display: grid; min-height: 44px; grid-template-columns: 1.65rem minmax(0,1fr) 1rem; align-items: center; gap: .2rem; padding: .35rem; border-radius: 6px; color: var(--ink); text-decoration: none; font-size: .875rem; line-height: 1.25; }
#lessons a:hover, #lessons a.active { background: #dceadc; }
.lesson-number, .completion { color: var(--muted); }
.nav-group-title { font-size: .85rem; font-weight: 650; margin: .9rem .3rem .3rem; }
.mobile-lesson-picker { display: none; }
.workspace { margin-left: 250px; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: .75rem; padding: .5rem clamp(1rem,4vw,3rem); border-bottom: 1px solid var(--line); font-size: .96rem; color: var(--muted); }
main { width: min(100%, 1120px); margin: auto; padding: clamp(1rem,4vw,2.75rem); min-width: 0; }
.intro, .lesson-path { max-width: 75ch; }
.lesson-path { margin-bottom: 1.65rem; font-size: .94rem; color: var(--muted); }
.reference-button, .text-button, .footer-export { border: 0; background: none; color: #2f6748; padding: .45rem .3rem; text-decoration: underline; text-underline-offset: 3px; }
.primary-button, .subtle-button { padding: .45rem .7rem; border-radius: 6px; overflow-wrap: anywhere; white-space: normal; }
.primary-button { background: var(--accent); color: #fff; border: 1px solid var(--accent); font-weight: 600; }
.primary-button:hover { background: #23432f; }
.subtle-button { border: 1px solid var(--line); background: var(--panel); }
.subtle-button:hover { background: var(--soft); }
.experiment-head { display: flex; gap: .75rem; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; }
.reset-actions, .question-actions, .lab-actions, .python-actions, .lesson-navigation { display: flex; align-items: center; gap: .65rem; flex-wrap: wrap; }
.experiment-guide, .comparison { max-width: 75ch; }
#resume-settings { background: var(--soft); padding: .6rem .7rem; border-radius: 5px; }
.experiment { display: grid; grid-template-columns: minmax(0,1fr) minmax(250px, 320px); border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
.graph-wrap { min-width: 0; display: flex; flex-direction: column; }
.graph-toolbar, .graph-legend { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .65rem; padding: .6rem .85rem; font-size: .9rem; color: var(--muted); }
.graph-legend { justify-content: flex-start; }
.legend-item { display: inline-flex; align-items: center; gap: .3rem; }
.legend-line { width: .9rem; height: 3px; background: currentColor; border-radius: 5px; }
#graph { width: 100%; height: auto; }
.controls { border-left: 1px solid var(--line); padding: 1rem; background: var(--soft); min-width: 0; border-radius: 0 8px 8px 0; }
.controls h3 { margin: 0 0 .5rem; }
#controls-body { display: grid; gap: .7rem; }
.control-help { font-size: .9rem; margin: 0; }
.matrix-grid, .lab-vector, .lab-matrix, .observation-fields { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: .45rem; }
.vector-label, .coefficient label { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: .35rem; }
.vector-pair { display: flex; gap: .2rem; align-items: center; }
.vector-pair input { width: min(4.1rem,21vw); }
.lab-fieldset { border: 1px solid var(--line); padding: .5rem; margin: 0; min-width: 0; }
.lab-field, .lab-select, .preset-label { display: block; font-size: .9rem; }
.lab-field input, .lab-select select, #preset, #row-factor, #lesson-select { width: 100%; }
input[type="number"], #row-factor, select { border: 1px solid #a6b7a6; border-radius: 5px; background: var(--panel); padding: .25rem .4rem; }
input[type="range"] { width: 100%; min-height: 36px; margin: 0; accent-color: var(--accent); }
.range-ticks { display: flex; justify-content: space-between; color: var(--muted); font-size: .8rem; }
.result-box { border-top: 1px solid var(--line); padding-top: .85rem; margin-top: .85rem; }
#result-equation { font-size: 1.1rem; font-weight: 650; overflow-wrap: anywhere; }
.result-box p { font-size: .94rem; color: var(--muted); margin: .4rem 0 0; }
.graph-details { margin: .55rem 0 .8rem; }
.graph-details p { margin-top: .5rem; }
#input-message, #python-error { background: var(--error-bg); color: var(--error); padding: .6rem; border-radius: 5px; margin: .8rem 0 0; overflow-wrap: anywhere; }

.lesson-section, .experiment-mission, .python-section, .lesson-navigation { margin-top: 1.65rem; }
#panel-notes, #panel-practice { border-top: 1px solid var(--line); padding-top: 1.2rem; }
.notes-body { max-width: 76ch; }
.notes-body h3 { margin-top: 1.2rem; }
.math { background: var(--soft); padding: .85rem; border-radius: 5px; margin: .85rem 0; font: 1rem/1.7 ui-monospace, monospace; overflow-wrap: anywhere; }
.experiment-mission, .question, .course-complete { border: 1px solid var(--line); border-radius: 7px; background: var(--panel); padding: clamp(.8rem, 3vw, 1.2rem); }
.course-complete, .question { margin-bottom: .75rem; }
.answer-options { display: grid; gap: .3rem; }
.answer-options label { display: flex; align-items: center; gap: .5rem; min-height: 44px; cursor: pointer; }
.feedback { margin-top: .7rem; padding: .65rem; background: #eaf3e6; color: #2e533b; border-radius: 5px; overflow-wrap: anywhere; }
.feedback.incorrect { background: #f6f0e6; color: #674b24; }
#practice-status { margin: .85rem 0 0; color: var(--muted); }

.python-section { background: var(--panel); border: 1px solid var(--line); border-radius: 7px; }
.python-toggle { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 1rem; text-align: left; border: 0; background: transparent; padding: .55rem .8rem; }
#python-panel { padding: .8rem; border-top: 1px solid var(--line); }
#python-code { display: block; width: 100%; min-height: 215px; resize: vertical; padding: .55rem; margin: .35rem 0 .75rem; border: 1px solid #a6b7a6; border-radius: 5px; font: .95rem/1.55 ui-monospace, monospace; }
#python-status { margin-top: .6rem; }
#python-output { max-height: 24rem; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; padding: .8rem; background: #26392d; color: #f4f9ef; border-radius: 5px; font: .95rem/1.55 ui-monospace, monospace; }
#python-result { margin-top: .8rem; }
.lesson-navigation { justify-content: space-between; }
.page-footer { margin-top: 1.4rem; padding-top: 1rem; border-top: 1px solid var(--line); font-size: .91rem; color: var(--muted); }
.progress-tools { margin-bottom: .8rem; }
.progress-tools p { margin-top: .45rem; }
#save-state:empty, #import-status:empty { margin: 0; }
#reference-dialog { color: var(--ink); background: var(--panel); width: min(90vw,760px); max-height: 85vh; padding: 1.1rem; border: 1px solid var(--line); border-radius: 8px; }
#reference-dialog::backdrop { background: #17281db0; }
.reference-header { display: flex; justify-content: space-between; gap: .75rem; align-items: start; }
.reference-table { border-collapse: collapse; width: 100%; table-layout: fixed; margin-bottom: .85rem; }
.reference-table th, .reference-table td { padding: .35rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; overflow-wrap: anywhere; }
.reference-table th:first-child { width: 34%; }
@media(max-width: 1040px) {
  .experiment { grid-template-columns: minmax(0,1fr); }
  .controls { border-left: 0; border-top: 1px solid var(--line); border-radius: 0 0 8px 8px; }
  #graph { max-height: 440px; }
}
@media(max-width: 760px) {
  .sidebar { position: static; width: 100%; border-right: 0; padding: .8rem 1rem; gap: .45rem; }
  .workspace { margin-left: 0; }
  .sidebar #lessons, .course-search, .progress-track, .progress-label { display: none; }
  .mobile-lesson-picker { display: grid; grid-template-columns: max-content minmax(0,1fr); align-items: center; gap: .6rem; }
  .experiment-head { display: block; }
  .reset-actions { margin: 0 0 .7rem; }
}
