/* Тёмная тема: графитовые поверхности, тёплый текст и приглушённый лиловый акцент.
   Переключатель работает и на входе; сохранённая тема применяется до отрисовки. */
:root { color-scheme: light; }
.theme-toggle { display: inline-flex; align-items: center; justify-content: center; gap: 7px; flex: 0 0 auto; min-width: 44px; min-height: 44px; padding: 7px 11px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); color: var(--ink); cursor: pointer; font-size: 13px; }
.theme-toggle[hidden] { display: none; }
.theme-toggle [data-theme-icon] { font-size: 23px; line-height: 1; }
.topbar > .theme-toggle { margin-left: auto; }
.topbar .account { margin-left: 0; }
@media (max-width: 1100px) { .theme-toggle .theme-label { display: none; } }
@media (max-width: 600px) {
  .topbar { flex-wrap: wrap; }
  .topbar .account { flex: 1 1 100%; justify-content: space-between; }
  .topbar .account-profile { max-width: calc(100% - 65px); }
}
html[data-theme="dark"] {
  color-scheme: dark;
  --paper: #191a1d; --surface: #232428; --ink: #e8e4de; --muted: #b9b5af;
  --line: #3c3d43; --accent: #c8b8ee; --accent-dark: #e0d4fc;
  --accent-soft: #2c2d33; --cyan: #b6acd3; --nav-ink: #1d1e22;
  --success: #a7cfb3; --danger: #efb2aa;
}
html[data-theme="dark"] :is(.topbar,.card,.log-table-wrap,.course-module,.lesson-section,.quiz-card,.quiz-option,.matching-task,.notebook-cell,.tm-lab,.micro-lesson,.concept-card,.intro-visual,.shift-journal,.theory-figure) {
  background: var(--surface); color: var(--ink); border-color: var(--line); box-shadow: none;
}
html[data-theme="dark"] :is(h1,h2,h3,h4,.brand,.section-heading h2,.info-panel h3,.course-tile .course-tile-copy h2,.course-module-head h2,.course-module .lesson-row h3,.micro-header h3,.theory-node h4,.concept-card-heading h3) { color: var(--ink); }
html[data-theme="dark"] :is(.muted,.helptext,small,.card p,.course-tile .course-tile-copy p,.info-panel p,.catalog-heading .lead,.overview-stats span,.overview-course-list,.cell-status,.notebook-libraries,.lesson-portrait-source,.lesson-portrait h3 span,.micro-counter,.micro-hint,.micro-route li,.micro-facts dt,.concept-explanation,.concept-legend,.intro-visual p,.intro-visual small) { color: var(--muted); }
html[data-theme="dark"] :is(.eyebrow,.count,.result-total,.overview-stats strong,.course-card .text-link,.course-tile-link,.micro-kicker,.micro-facts dd,.lesson2-control output,.lesson2-legend,.concept-eyebrow,.theory-figure-eyebrow,.intro-kicker,.intro-key) { color: var(--accent); }
html[data-theme="dark"] .button, html[data-theme="dark"] .explorer-steps button[aria-current] { background: #75628f; color: #fff; border-color: #9581af; }
html[data-theme="dark"] .button:hover { background: #85719e; }
html[data-theme="dark"] :is(.button.secondary,.micro-controls button,.lesson2-actions button,.lesson2-button,.concept-action,.concept-reset,.concept-animation-buttons button,.course-module-nav a) { background: var(--surface); color: var(--accent); border-color: #54505e; }
html[data-theme="dark"] :is(.button.secondary:hover,.micro-controls button:hover:not(:disabled),.lesson2-actions button:hover,.course-module-nav a:hover) { background: var(--accent-soft); }
html[data-theme="dark"] :is(input:not([type=checkbox]):not([type=radio]),textarea:not(.code-editor),select) { background: #1d1e22; color: var(--ink); border-color: #505158; }
html[data-theme="dark"] input::placeholder,html[data-theme="dark"] textarea::placeholder { color: #aaa69f; opacity: 1; }
html[data-theme="dark"] :is(.info-panel,.course-overview,.course-module-head,.course-module-index,.course-module .lesson-number,.badge,.count,.lesson-section>summary,.quiz-question,.homework-group-picker,.homework-group-options label,.group-connect,.notebook,.cell-heading,.notebook-data,.notebook-output-summary,.micro-header,.micro-route,.micro-controls,.micro-facts>div,.micro-option[open] summary,.micro-option summary:hover,.micro-reveal summary:hover,.concept-controls,.concept-display,.concept-details,.intro-concept,.intro-reveal,.intro-tag,.intro-model-badge,.lesson-portrait,.learning-comic,.shift-journal header,.shift-journal figcaption,.lesson2-flow span,.lesson2-result,.theory-figure-heading,.theory-figure-canvas,.theory-node,.theory-formulas>div,.theory-lane) { background: var(--accent-soft); color: var(--ink); border-color: var(--line); }
html[data-theme="dark"] :is(.feedback,.notice,.research-focus,.micro-feedback-correct,.micro-result,.concept-result,.intro-transfer-answer) { background: #293730; color: #c8dfcf; border-color: #526b5c; }
html[data-theme="dark"] :is(.error,.errorlist,.micro-feedback:not(.micro-feedback-correct)) { background: #3a2b2c; color: #ebc4ba; border-color: #795954; }
html[data-theme="dark"] :is(.error,.log-error,.cell-status[data-state=error]) { color: #efb2aa; }
html[data-theme="dark"] :is(.output,.cell-output) { background: #1d1e22; color: var(--ink); border-color: var(--line); }
html[data-theme="dark"] :is(.results-table,.log-table,.prose table) tbody tr:nth-child(even) { background: #28292e; }
html[data-theme="dark"] :is(.results-table,.log-table,.prose table) tbody tr:hover { background: #323138; }
html[data-theme="dark"] :is(th,td,.rubric-row,.course-tile-link,.micro-stage,.micro-route,.micro-option,.intro-reveal,.shift-journal-question) { border-color: var(--line); }
html[data-theme="dark"] :is(.micro-option summary,.micro-reveal summary,.micro-reveal summary>span,.micro-feedback strong,.notebook-data summary,.notebook-output-summary summary,.theory-node p,.theory-lane p,.theory-figure figcaption,.concept-control-label,.concept-question,.concept-metrics,.intro-reveal summary) { color: var(--ink); }
/* Графики и архивные изображения сохраняют исходную палитру и подписи. */
html[data-theme="dark"] :is(.concept-svg,.lesson2-chart,.shift-journal-chart svg,.theory-plot svg,.cell-plots img,.plots img) { background: #f0eee9; border-radius: 8px; color-scheme: light; }
html[data-theme="dark"] .sidebar a { color: #c9c5c0; }
html[data-theme="dark"] .sidebar nav a[aria-current] { background: #34303e; color: #e1d7f2; border-color: #665a7c; }
html[data-theme="dark"] .sidebar nav a[aria-current]>span { color: #c8b8ee; }
html[data-theme="dark"] .sidebar nav a:hover { background: #2b2931; color: #fff; }
@media print { .theme-toggle { display: none; } }

html[data-theme="dark"] .concept-lab { --cv-blue: #c8b8ee; --cv-cyan: #b6acd3; --cv-ink: #e8e4de; --cv-muted: #b9b5af; --cv-line: #3c3d43; --cv-soft: #2c2d33; --cv-orange: #d6b48b; }
html[data-theme="dark"] .intro-visual { --intro-ink: #e8e4de; --intro-accent: #b6acd3; }
html[data-theme="dark"] .micro-lesson { --micro-accent: #b6acd3; }
html[data-theme="dark"] :is(.lesson-header,.lesson-outline,.lesson-empty-practice,.lesson-section[open]>summary,.lesson-section-number,.lesson-jumps a,.lesson-reading-head button,.lesson-copy,.study-time>span,.daily-phrase-icon,.group-tabs a,.homework-tabs a,.intro-visual>header,.intro-visual>figcaption,.intro-three,.intro-two,.intro-mini,.intro-sample-strip>span,.intro-topic-tags>span,.theory-figure-mark,.theory-figure>figcaption,.theory-data-table,.theory-data-table th,.theory-data-table td,.concept-number,.concept-legend,.concept-metrics>div,.concept-control-label output,.concept-explanation,.concept-details>summary,.lesson2-new,.lesson2-probability,.lesson2-samples>span,.prose blockquote,.prose th) { background: var(--accent-soft); color: var(--ink); border-color: var(--line); }
html[data-theme="dark"] :is(.lesson-outline a,.lesson-jumps a,.group-tabs a,.homework-tabs a,.group-state-link,.group-education,.resource-download,.concept-explanation p,.concept-card-heading p,.concept-control-heading,.intro-visual h3,.intro-visual h4,.intro-visual p,.intro-visual dt,.intro-visual dd,.intro-visual figcaption,.theory-node-tag,.theory-loop,.theory-pipeline-link) { color: var(--ink); }
html[data-theme="dark"] :is(.group-tabs a[aria-current],.homework-tabs a[aria-current]) { background: #75628f; color: #fff; }
html[data-theme="dark"] .skip { background: var(--surface); color: var(--ink); }
html[data-theme="dark"] .theory-cell--correct { background: #293730; color: #c8dfcf; }
html[data-theme="dark"] .theory-cell--error { background: #3a2b2c; color: #ebc4ba; }
html[data-theme="dark"] :is(.profile-account dt,.study-time,.study-time small) { color: var(--muted); }
html[data-theme="dark"] .study-time strong { color: var(--accent); }
html[data-theme="dark"] :is(.education-tag,.homework-reactions label) { background: var(--surface); color: var(--ink); border-color: var(--line); }
html[data-theme="dark"] .homework-reactions label:has(input:checked) { background: var(--accent-soft); border-color: var(--cyan); }
html[data-theme="dark"] .button.secondary { background: var(--surface); color: var(--accent); border-color: #54505e; }
html[data-theme="dark"] .button.secondary:hover { background: var(--accent-soft); }

/* Разные уровни поверхности помогают читать страницу без ярких цветных плашек. */
html[data-theme="dark"] .topbar { background: #202125; border-bottom-color: #35363b; box-shadow: 0 2px 12px #00000014; }
html[data-theme="dark"] .sidebar { border-color: #35363b; }
html[data-theme="dark"] .sidebar :is(.nav-caption,.sidebar-foot a) { color: #aaa6a0; }
html[data-theme="dark"] .sidebar nav a>span { color: #aaa3b9; }
html[data-theme="dark"] .sidebar nav a[aria-current]::before { background: #b5a2d2; }
html[data-theme="dark"] .sidebar-foot { border-color: #39383e; }
html[data-theme="dark"] :is(.card,.lesson-section,.micro-lesson,.intro-visual,.concept-card) { box-shadow: 0 4px 16px #00000010; }
html[data-theme="dark"] :is(.prose,.prose p,.card>p:not(.muted):not(.helptext),.intro-visual p,.micro-stage p) { color: #d1cdc7; }
html[data-theme="dark"] .lesson-header { background: linear-gradient(120deg,#29282e,#242529); border-color: #424047; }
html[data-theme="dark"] .lesson-header::after { border-color: #9c8aaf12; }
html[data-theme="dark"] :is(.course-card,.task-card,.overview-stats .card,.overview-course) { border-top-color: #8e80a1; border-left-color: #8e80a1; }
html[data-theme="dark"] .course-tile-cover { background: linear-gradient(120deg,#37323f,#2c2d34); border-bottom-color: #91819f; }
html[data-theme="dark"] .course-tile-cover .badge { background: #484150; color: #e4dce9; }
html[data-theme="dark"] .course-tile-drawing { color: #b8a9c7; fill: #ded5e7; }
html[data-theme="dark"] :is(.results-table thead th,.log-table th) { background: #323039; border-color: #4b4654; color: #e8e4de; }
html[data-theme="dark"] .results-table thead th small { color: #c1b9c9; }
html[data-theme="dark"] :is(.score-pill,.course-tile-link>span) { background: #38323f; border-color: #564a63; color: #e1d7f2; }
html[data-theme="dark"] :is(.button,.theme-toggle):focus-visible { outline-color: #c8b8ee; }
/* «Мысль дня» имеет свою спокойную тёплую поверхность, без белого градиента. */
html[data-theme="dark"] .topbar .daily-phrase { background: #2b2925; border-color: #494237; box-shadow: none; }
html[data-theme="dark"] .topbar .daily-phrase .daily-phrase-icon { background: #373127; border-color: #554935; color: #d8ba86; }
html[data-theme="dark"] .daily-phrase-label { color: #d0b890; }
html[data-theme="dark"] .daily-phrase-text { color: #ded5c8; }
html[data-theme="dark"] .prose blockquote { background: #2c2925; border-color: #534736; border-left: 3px solid #b39a73; color: #ded5c8; }
html[data-theme="dark"] .prose blockquote p { color: inherit; }
/* Палитра кода сохраняет подсветку, но фон больше не отдаёт синим. */
html[data-theme="dark"] :is(pre.python-highlight,.micro-lesson pre.micro-code.python-highlight,.python-editor.CodeMirror) { background: #1c1d21; border-color: #414047; color: #dedbd6; }
html[data-theme="dark"] :is(code.python-highlight,code.task-code,.prose :not(pre)>code.python-highlight) { background: #343039; color: #e1dbe7; }
html[data-theme="dark"] pre.python-highlight code { background: transparent; }
