:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f0f2f8;
  --text: #1d2233;
  --muted: #6b7288;
  --border: #e2e5ef;
  --accent: #0c8a5f;
  --accent-2: #0a6f4c;
  --accent-soft: #e3f5ee;
  --warn: #c9861a;
  --bad: #c43d3d;
  --bad-soft: #fbeaea;
  --ok-soft: #e5f6ec;
  --code-bg: #f4f5f9;
  --info: #2f6fd1;
  --violet: #7a4fd6;
  --violet-soft: #f1ecfc;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 30, 60, .06), 0 4px 16px rgba(20, 30, 60, .05);
  --mono: ui-monospace, "JetBrains Mono", "Fira Code", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11141c;
    --surface: #191d28;
    --surface-2: #212634;
    --text: #e6e8ef;
    --muted: #9198ad;
    --border: #2b3142;
    --accent: #35c48f;
    --accent-2: #5ad6a6;
    --accent-soft: #173a2e;
    --bad: #ef6b6b;
    --bad-soft: #3a1d22;
    --ok-soft: #173a2a;
    --code-bg: #272822;
    --info: #6ea2f2;
    --violet: #b195f2;
    --violet-soft: #251f38;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex; flex-direction: column; min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; }
code { font-family: var(--mono); font-size: .9em; background: var(--code-bg); padding: .1em .35em; border-radius: 5px; }
.container { width: 100%; max-width: 1180px; margin: 0 auto; padding: 0 16px; }
.page { padding-top: 28px; padding-bottom: 48px; flex: 1; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.inline { display: inline; }
.accent { color: var(--accent); }
.success-text { color: var(--accent); font-weight: 600; }

/* Header */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.topbar__inner { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 60px; flex-wrap: wrap; }
.logo { font-weight: 800; font-size: 1.2rem; color: var(--text); }
.logo:hover { text-decoration: none; }
.logo__mark { color: var(--accent); }
.nav { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.nav a { color: var(--text); }
.link-btn { background: none; border: 0; padding: 0; color: var(--muted); cursor: pointer; font: inherit; }
.link-btn:hover { color: var(--text); text-decoration: underline; }
.footer { color: var(--muted); font-size: .875rem; padding: 24px 0; border-top: 1px solid var(--border); }

/* Buttons & inputs */
.btn {
  display: inline-block; background: var(--accent); color: #fff; border: 0; border-radius: 10px;
  padding: 10px 18px; font: inherit; font-weight: 600; cursor: pointer; transition: background .15s;
}
@media (prefers-color-scheme: dark) { .btn { color: #0d1a14; } }
.btn:hover { background: var(--accent-2); text-decoration: none; }
.btn:disabled { opacity: .6; cursor: wait; }
.btn--small { padding: 6px 12px; font-size: .9rem; }
.btn--ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn--ghost:hover { background: var(--surface-2); }
.btn--wide { width: 100%; }
.icon-btn { border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 6px; cursor: pointer; padding: 2px 8px; }
.input, .field input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text); font: inherit;
}
.input:focus, .field input:focus, .code-input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow); }
.alert { background: var(--accent-soft); border-radius: 10px; padding: 12px 16px; margin-bottom: 16px; }
.alert--error { background: var(--bad-soft); color: var(--bad); }

/* Progress */
.progress { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin: 12px 0 6px; }
.progress--big { height: 12px; }
.progress__bar { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); border-radius: 99px; transition: width .4s; }
.ring {
  --p: 0; width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center;
  background: conic-gradient(var(--accent) calc(var(--p) * 1%), var(--surface-2) 0);
}
.ring span { background: var(--surface); width: 50px; height: 50px; border-radius: 50%; display: grid; place-items: center; font-size: .8rem; font-weight: 700; }

.status { display: inline-block; width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--border); flex: none; }
.status--done { background: var(--accent); border-color: var(--accent); }
.status--started { border-color: var(--warn); background: linear-gradient(90deg, var(--warn) 50%, transparent 50%); }
.status--draft { border-style: dashed; opacity: .6; }

/* Course list */
.hero { padding: 24px 0 32px; max-width: 760px; }
.hero h1 { font-size: clamp(1.8rem, 4vw, 2.6rem); margin: 0 0 12px; }
.hero p { font-size: 1.1rem; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px; }
.course-card { color: var(--text); display: block; transition: transform .15s, border-color .15s; }
.course-card:hover { text-decoration: none; transform: translateY(-2px); border-color: var(--accent); }
.course-card__icon { font-size: 2.4rem; }
.course-card h2 { margin: 8px 0; }
.course-card__meta { font-weight: 600; font-size: .9rem; }

/* Course detail */
.course-head { display: flex; gap: 24px; margin-bottom: 20px; }
.course-head__icon { font-size: 3.5rem; line-height: 1; }
.course-head h1 { margin-top: 0; }
.stats { display: flex; gap: 28px; flex-wrap: wrap; margin: 12px 0; }
.stats b { display: block; font-size: 1.5rem; }
.stats span { color: var(--muted); font-size: .85rem; }
.stats--cards { gap: 16px; }
.stats--cards .card { min-width: 180px; padding: 16px 20px; }
.legend { display: flex; gap: 18px; flex-wrap: wrap; margin: 0 0 16px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.module { margin-bottom: 18px; }
.module__head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; }
.module__head h2 { margin: 2px 0 4px; }
.module__head p { margin: 0 0 8px; }
.module__num { color: var(--accent); font-weight: 700; font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; }
.lesson-list { list-style: none; padding: 0; margin: 8px 0 0; }
.lesson-list__item { display: flex; align-items: center; gap: 12px; padding: 10px 6px; border-top: 1px solid var(--border); }
.lesson-list__item a { flex: 1; color: var(--text); }
.lesson-list__item--draft a { color: var(--muted); }
.lesson-list__item--done a { color: var(--muted); }
.lesson-list__meta { color: var(--muted); font-size: .8rem; white-space: nowrap; }
.reset-form { text-align: right; }

/* Lesson */
.lesson-layout { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: 32px; align-items: start; }
.sidebar { position: sticky; top: 80px; max-height: calc(100vh - 100px); overflow: auto; font-size: .9rem; padding-right: 6px; }
.sidebar__course { display: block; font-weight: 700; color: var(--text); margin-bottom: 12px; }
.sidebar__module summary { cursor: pointer; font-weight: 600; padding: 6px 0; }
.sidebar__module ul { list-style: none; margin: 0 0 8px; padding: 0 0 0 4px; }
.sidebar__module li { display: flex; gap: 8px; align-items: center; padding: 4px 6px; border-radius: 8px; }
.sidebar__module li a { color: var(--text); }
.sidebar__module li.active { background: var(--accent-soft); font-weight: 600; }
.lesson { min-width: 0; }
.lesson h1 { margin: 6px 0; font-size: clamp(1.6rem, 3vw, 2.2rem); }
.badge { display: inline-block; padding: 2px 10px; border-radius: 99px; font-size: .8rem; margin-left: 8px; }
.badge--done { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.draft-note { margin: 24px 0; }

.prose { font-size: 1.02rem; }
.prose h2 { margin-top: 2em; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.prose h3 { margin-top: 1.6em; }
.prose img { max-width: 100%; }
.prose table { border-collapse: collapse; width: 100%; display: block; overflow-x: auto; margin: 1em 0; }
.prose th, .prose td { border: 1px solid var(--border); padding: 8px 12px; text-align: left; }
.prose th { background: var(--surface-2); }
.prose blockquote { margin: 1em 0; padding: 4px 16px; border-left: 4px solid var(--accent); background: var(--accent-soft); border-radius: 0 10px 10px 0; }
.prose .highlight { position: relative; border-radius: 10px; margin: 1em 0; background: var(--code-bg); }
.prose .highlight pre { margin: 0; padding: 14px 16px; overflow-x: auto; font-family: var(--mono); font-size: .88rem; line-height: 1.5; }
.prose pre code { background: none; padding: 0; }
.copy-btn { position: absolute; top: 6px; right: 6px; font-size: .75rem; border: 1px solid var(--border); background: var(--surface); color: var(--muted); border-radius: 6px; padding: 2px 8px; cursor: pointer; opacity: 0; transition: opacity .15s; }
.highlight:hover .copy-btn { opacity: 1; }
.admonition { --adm: var(--accent); border-radius: 10px; padding: 10px 16px; margin: 1.2em 0; background: var(--surface-2); border-left: 4px solid var(--adm); }
.admonition > p:last-child { margin-bottom: 4px; }
.admonition-title { font-weight: 700; margin: 0 0 4px; color: var(--adm); }
.admonition-title::before { margin-right: 6px; }
.admonition.note, .admonition.info { --adm: var(--info); }
.admonition.note > .admonition-title::before, .admonition.info > .admonition-title::before { content: "ℹ️"; }
.admonition.tip > .admonition-title::before { content: "💡"; }
.admonition.warning { --adm: var(--warn); }
.admonition.warning > .admonition-title::before { content: "⚠️"; }
.admonition.danger { --adm: var(--bad); }
.admonition.danger > .admonition-title::before { content: "⛔"; }
.admonition.example { --adm: var(--violet); }
.admonition.example > .admonition-title::before { content: "🔍"; }
.admonition.exam { --adm: var(--violet); background: var(--violet-soft); }
.admonition.exam > .admonition-title::before { content: "🎓"; }
.admonition.analogy { --adm: var(--info); }
.admonition.analogy > .admonition-title::before { content: "🧠"; }

/* Раскрывающиеся блоки: <details class="spoiler" markdown="1"> */
.prose details.spoiler { border: 1px solid var(--border); border-radius: 10px; margin: 1em 0; background: var(--surface); }
.prose details.spoiler > summary { cursor: pointer; padding: 10px 16px; font-weight: 600; list-style: none; }
.prose details.spoiler > summary::-webkit-details-marker { display: none; }
.prose details.spoiler > summary::before { content: "▸"; display: inline-block; margin-right: 8px; transition: transform .15s; color: var(--accent); }
.prose details.spoiler[open] > summary::before { transform: rotate(90deg); }
.prose details.spoiler > :not(summary) { margin-left: 16px; margin-right: 16px; }
.prose details.spoiler[open] { padding-bottom: 6px; }

/* Схемы: <div class="diagram"> с моноширинным текстом */
.prose .diagram { font-family: var(--mono); font-size: .85rem; line-height: 1.35; white-space: pre; overflow-x: auto; background: var(--surface-2); border-radius: 10px; padding: 14px 16px; margin: 1em 0; }

/* Ключевые определения */
.prose .key { border: 1px solid var(--accent); background: var(--accent-soft); border-radius: 10px; padding: 10px 16px; margin: 1em 0; }
.prose .key > p:first-child { margin-top: 0; }
.prose .key > p:last-child { margin-bottom: 0; }

/* Интерактивные симуляторы */
.widget { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); padding: 14px 16px; margin: 1.4em 0; box-shadow: var(--shadow); }
.widget__title { font-weight: 700; margin-bottom: 8px; }
.widget__title::before { content: "🧪 "; }
.widget__controls { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: flex-end; margin-bottom: 10px; }
.widget__controls label { display: flex; flex-direction: column; font-size: .8rem; color: var(--muted); gap: 2px; }
.widget__controls input, .widget__controls select { font: inherit; font-size: .9rem; padding: 4px 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); color: var(--text); min-width: 80px; }
.widget__out { font-family: var(--mono); font-size: .85rem; overflow-x: auto; }
.widget__out table { border-collapse: collapse; margin: 6px 0; }
.widget__out td, .widget__out th { border: 1px solid var(--border); padding: 3px 8px; text-align: center; white-space: nowrap; }
.widget__summary { margin-top: 8px; font-weight: 600; }
.bits { display: flex; flex-wrap: wrap; gap: 4px; margin: 8px 0; }
.bits__group { border-radius: 6px; padding: 4px 8px; text-align: center; font-family: var(--mono); font-size: .8rem; color: #fff; }
.bits__group small { display: block; opacity: .85; font-family: system-ui, sans-serif; }
.hit { color: var(--accent); font-weight: 700; }
.miss { color: var(--bad); font-weight: 700; }
.tree { font-family: var(--mono); font-size: .85rem; white-space: pre; line-height: 1.4; max-height: 360px; overflow: auto; }

/* Задание-таблица */
.matrix-wrap { overflow-x: auto; margin-bottom: 6px; }
.matrix { border-collapse: collapse; font-size: .85rem; }
.matrix th, .matrix td { border: 1px solid var(--border); padding: 6px 8px; text-align: center; }
.matrix thead th { background: var(--surface-2); font-weight: 600; vertical-align: bottom; min-width: 90px; max-width: 140px; }
.matrix tbody th { text-align: left; font-family: var(--mono); white-space: nowrap; background: var(--surface-2); }
.matrix__cell { display: inline-flex; cursor: pointer; }
.matrix__cell input { position: absolute; opacity: 0; pointer-events: none; }
.matrix__cell span { width: 30px; height: 30px; border: 1px solid var(--border); border-radius: 8px; display: inline-flex; align-items: center; justify-content: center; font-weight: 800; color: var(--muted); }
.matrix__cell span::after { content: "−"; }
.matrix__cell input:checked + span { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.matrix__cell input:checked + span::after { content: "+"; }
.matrix__cell input:focus-visible + span { outline: 2px solid var(--accent); }

/* Tasks */
.tasks { margin-top: 40px; }
.tasks > h2 { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.task { margin-bottom: 18px; border-left: 4px solid var(--border); }
.task--solved { border-left-color: var(--accent); }
.task__head { display: flex; gap: 12px; align-items: center; font-size: .85rem; }
.task__num { font-weight: 700; }
.task__type { color: var(--muted); background: var(--surface-2); padding: 1px 10px; border-radius: 99px; }
.task__status { margin-left: auto; color: var(--accent); font-weight: 700; }
.task__question { margin: 8px 0 12px; }
.task__question p:first-child { margin-top: 0; }
.choices { display: grid; gap: 8px; }
.choice { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; cursor: pointer; }
.choice:hover { background: var(--surface-2); }
.choice input { margin-top: 5px; accent-color: var(--accent); }
.choice:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.order-list { padding-left: 24px; margin: 0; display: grid; gap: 8px; }
.order-item { padding: 8px 10px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); cursor: grab; }
.order-item > * { vertical-align: middle; }
.order-item__text { display: inline-block; width: calc(100% - 90px); }
.order-item__btns { float: right; display: inline-flex; gap: 4px; }
.order-item.dragging { opacity: .5; }
.code-input {
  width: 100%; font-family: var(--mono); font-size: .9rem; line-height: 1.5; padding: 12px 14px; tab-size: 4;
  background: var(--code-bg); color: var(--text); border: 1px solid var(--border); border-radius: 10px; resize: vertical;
}
@media (prefers-color-scheme: dark) { .code-input { color: #f8f8f2; } }
.task__actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.task__hint { margin-top: 12px; padding: 10px 14px; background: var(--surface-2); border-radius: 10px; }
.task__hint p { display: inline; margin: 0; }
.task__solution { margin-top: 12px; }
.task__solution pre { background: var(--code-bg); padding: 12px 14px; border-radius: 10px; overflow-x: auto; font-family: var(--mono); font-size: .88rem; }
.task__solution pre code { background: none; padding: 0; }
.task__feedback:empty { display: none; }
.task__feedback { margin-top: 12px; padding: 10px 14px; border-radius: 10px; }
.task__feedback ul { margin: 6px 0 0; padding-left: 20px; }
.task__feedback--ok { background: var(--ok-soft); color: var(--accent); }
.task__feedback--bad { background: var(--bad-soft); color: var(--bad); }
.task__explanation:not([hidden]):not(:empty) { margin-top: 12px; padding: 10px 14px; border: 1px dashed var(--accent); border-radius: 10px; }
.shake { animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }

.finish { margin: 28px 0; text-align: center; }
.lesson-nav { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-top: 24px; }
.lesson-nav .btn { max-width: 48%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Dashboard & auth */
.dash-course { margin-bottom: 14px; }
.dash-course__head { display: flex; justify-content: space-between; align-items: center; }
.dash-course__head h3 { margin: 0; color: var(--text); }
.dash-course .btn { margin-top: 10px; }
.recent { list-style: none; padding: 8px 22px; }
.recent li { display: flex; gap: 10px; align-items: center; padding: 8px 0; border-top: 1px solid var(--border); flex-wrap: wrap; }
.recent li:first-child { border-top: 0; }
.auth { max-width: 420px; margin: 20px auto; }
.auth h1 { margin-top: 0; }
.field { margin-bottom: 14px; }
.field label { display: block; font-weight: 600; margin-bottom: 4px; }
.field__error { color: var(--bad); font-size: .85rem; }
.field__help { color: var(--muted); font-size: .8rem; }
.field__help ul { margin: 4px 0; padding-left: 18px; }

@media (max-width: 860px) {
  .topbar { position: static; }
  .lesson-layout { grid-template-columns: 1fr; }
  .sidebar { position: static; max-height: none; order: 2; border-top: 1px solid var(--border); padding-top: 16px; }
  .course-head { flex-direction: column; gap: 8px; }
  .lesson-nav .btn { max-width: 100%; }
}
.order-item code { white-space: pre; }
.matrix td { position: relative; }
.widget__controls input[type=number] { width: 7em; }

/* ---------- Python в браузере: запускаемые примеры, вывод, визуализатор ---------- */
.runbox { border: 1px solid var(--border); border-radius: 12px; margin: 1.2em 0; background: var(--surface); overflow: hidden; }
.runbox .highlight { margin: 0; border-radius: 0; }
.runbox__bar { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 6px 8px; border-bottom: 1px solid var(--border); background: var(--surface-2); }
.runbox__bar .btn { padding: 4px 10px; font-size: .85rem; }
.runbox__tag { margin-left: auto; font-size: .75rem; color: var(--muted); font-family: var(--mono); }
.runbox__editor { border: 0; border-radius: 0; margin: 0; display: block; }
.runbox__stdin { display: flex; flex-direction: column; gap: 4px; padding: 8px 10px; border-top: 1px solid var(--border); }
.runbox__stdin[hidden] { display: none; }
.runbox__stdin textarea { font-family: var(--mono); font-size: .85rem; border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px; background: var(--surface-2); color: var(--text); resize: vertical; }
.runbox .py-out { border-top: 1px solid var(--border); margin: 0; border-radius: 0; }
.runbox .viz { border-top: 1px solid var(--border); margin: 0; border-radius: 0; }
.py-out { background: var(--surface-2); border-radius: 10px; padding: 8px 12px; margin-top: 10px; }
.py-out__label { font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 2px 0 4px; }
.py-out pre, .viz__stdout { margin: 0; font-family: var(--mono); font-size: .85rem; white-space: pre-wrap; word-break: break-word; max-height: 320px; overflow: auto; }
.py-out__error { color: var(--bad); margin-top: 4px !important; }
.py-out__status { color: var(--muted); font-size: .9rem; }
.py-tests { margin-top: 8px; font-weight: 600; }
.py-tests--ok { color: var(--accent); }
.py-tests--bad { color: var(--bad); }
.py-tests__list { margin: 4px 0 0; padding-left: 20px; }
.py-tests__list code { white-space: pre-wrap; }
.py-testlist { margin-top: 8px; color: var(--muted); }
.py-testlist summary { cursor: pointer; }
.py-testlist pre { font-family: var(--mono); font-size: .8rem; background: var(--surface-2); padding: 8px 10px; border-radius: 8px; overflow-x: auto; margin: 6px 0 0; color: var(--text); }
.task__viz:empty { display: none; }

.viz { border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; margin-top: 10px; background: var(--surface); outline: none; }
.viz__bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; }
.viz__ctrl { display: inline-flex; gap: 4px; align-items: center; }
.viz__pos { font-size: .85rem; color: var(--muted); min-width: 92px; text-align: center; }
.viz__slider { width: 100%; margin: 8px 0; accent-color: var(--accent); }
.viz__grid { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 12px; }
@media (max-width: 760px) { .viz__grid { grid-template-columns: 1fr; } }
.viz__code { font-family: var(--mono); font-size: .82rem; background: var(--code-bg); border-radius: 8px; padding: 6px 0; overflow-x: auto; }
.viz__line { display: flex; gap: 6px; padding: 0 8px; white-space: pre; line-height: 1.55; }
.viz__line code { background: none; padding: 0; font-size: inherit; }
.viz__ln { color: var(--muted); width: 2em; text-align: right; flex: none; }
.viz__mark { width: 1.2em; flex: none; color: var(--accent); font-weight: 700; }
.viz__line--next { background: var(--accent-soft); }
.viz__line--prev .viz__mark { color: var(--muted); }
.viz__event { min-height: 1.4em; font-size: .9rem; margin-bottom: 6px; }
.viz__frame { border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px; margin-bottom: 8px; font-family: var(--mono); font-size: .82rem; opacity: .7; }
.viz__frame--top { opacity: 1; border-color: var(--accent); }
.viz__fname { font-family: system-ui, sans-serif; font-weight: 700; font-size: .8rem; color: var(--muted); margin-bottom: 4px; }
.viz__var { display: flex; justify-content: space-between; gap: 10px; padding: 2px 0; border-top: 1px dashed var(--border); }
.viz__var:first-of-type { border-top: 0; }
.viz__val { color: var(--text); word-break: break-all; text-align: right; }
.viz__ref { display: inline-block; font-family: var(--mono); font-size: .78rem; font-weight: 700; padding: 0 6px; border-radius: 6px;
  color: hsl(var(--h) 60% 35%); background: hsl(var(--h) 70% 92%); border: 1px solid hsl(var(--h) 50% 75%); cursor: default; }
.viz__obj { border: 1px solid hsl(var(--h) 45% 75%); border-radius: 8px; padding: 5px 8px; margin-bottom: 6px; font-family: var(--mono); font-size: .8rem; }
.viz__objhead { font-size: .78rem; color: var(--muted); margin-bottom: 4px; }
.viz__objbody--seq { display: flex; flex-wrap: wrap; gap: 3px; }
.viz__cell { display: inline-flex; flex-direction: column; align-items: center; min-width: 26px; border: 1px solid var(--border); border-radius: 5px; padding: 1px 4px; background: var(--surface-2); }
.viz__cell small { font-size: .62rem; color: var(--muted); line-height: 1; }
.viz__pair { display: flex; gap: 6px; align-items: center; padding: 1px 0; }
.viz__hl { outline: 2px solid hsl(var(--h) 70% 50%); outline-offset: 1px; }
.viz__legend { margin: 8px 0 4px; }
.viz__stdout { background: var(--surface-2); border-radius: 8px; padding: 6px 10px; min-height: 1.6em; }
@media (prefers-color-scheme: dark) {
  .viz__ref { color: hsl(var(--h) 80% 78%); background: hsl(var(--h) 35% 22%); border-color: hsl(var(--h) 35% 38%); }
  .viz__obj { border-color: hsl(var(--h) 30% 35%); }
}
[hidden] { display: none !important; }

/* Рисунки модуля vis (графики, тепловые карты, графы вычислений) */
.py-figs { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 8px; }
.py-fig { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 6px; max-width: 100%; overflow-x: auto; color: var(--text); }
.py-fig svg.vis { display: block; max-width: 100%; height: auto; }
.vis-grid { stroke: var(--border); stroke-width: 1; }
.vis-axis { stroke: var(--muted); stroke-width: 1.2; }
.vis-frame { fill: none; stroke: var(--border); }
.vis-tick { fill: var(--muted); font-size: 11px; }
.vis-label { fill: var(--muted); font-size: 12px; }
.vis-title { fill: var(--text); font-size: 13.5px; font-weight: 600; }
.widget svg.mlw { max-width: 100%; height: auto; color: var(--text); background: var(--surface-2); border-radius: 8px; }
.widget input[type="range"] { min-width: 130px; padding: 0; }
.widget__val { color: var(--text); font-family: var(--mono); }

/* Формулы (KaTeX) */
.math-display { margin: 1em 0; overflow-x: auto; overflow-y: hidden; text-align: center; }
.math-inline { white-space: nowrap; }
.math-display .katex { font-size: 1.15em; }
.digits-w { display: flex; flex-wrap: wrap; gap: 18px; align-items: flex-start; }
.digits-w__pad { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.digits-w__pad canvas { width: 224px; height: 224px; max-width: 100%; border: 1px solid var(--border); border-radius: 8px; touch-action: none; cursor: crosshair; background: #fff; }
.digits-w__side { display: flex; flex-direction: column; gap: 6px; }
.digits-w__label { font-size: .8rem; color: var(--muted); }
.digits-w__probs { font-family: var(--mono); font-size: .85rem; display: flex; flex-direction: column; gap: 3px; }
.digits-w__row { display: flex; align-items: center; gap: 8px; }
.digits-w__row span:first-child { width: 1em; font-weight: 700; }
.digits-w__bar { display: inline-block; height: 12px; background: var(--accent, #2f6fd1); border-radius: 3px; opacity: .45; }
.digits-w__row.is-best .digits-w__bar { opacity: 1; }
.digits-w__row.is-best { font-weight: 700; }
.formula-box { display: flex; flex-direction: column; gap: 8px; }
.formula-box .task__formula { font-family: var(--mono); max-width: 520px; }
.formula-preview { min-height: 2.4em; padding: 8px 12px; border: 1px dashed var(--border); border-radius: 8px; background: var(--surface-2); font-size: 1.15rem; overflow-x: auto; color: var(--text); max-width: 520px; }
.formula-preview--error { font-size: .85rem; color: var(--muted); }
.formula-help { margin-top: 6px; }
.formula-help code { font-size: .8rem; }

/* Рисунки к задачам (курс механики): SVG прямо в тексте урока, цвета следуют теме */
.mech-fig { margin: 1.2em 0; text-align: center; }
.mech-fig svg { max-width: 100%; height: auto; color: var(--text); background: var(--surface-2); border-radius: 10px; }
.mech-fig__cap { font-size: .85rem; color: var(--muted); margin-top: 4px; }
.formula-vars { margin: 4px 0 0; }
