/* ============================================================
   Учебник по кодификатору: оформление страниц теории

   Слой поверх style.css и встроенных стилей страниц. Подключается
   последним в <head> страниц учебника (body.with-sidebar) и страницы
   оглавления /firstchap/theory.html. Меняет только вид: разметку и
   текст страниц не трогает.

   Что даёт:
     • типографика для долгого чтения — Inter, 17 px, выключка влево
       вместо «по ширине» (она рвала строки дырами), ширина строки
       около 75 знаков, спокойная иерархия заголовков;
     • каркас «оглавление + лист»: оглавление липнет под меню и
       прокручивается само, лист — одна чистая карточка;
     • единый язык компонентов: выноски, определения, исключения,
       таблицы свойств, карточки задач, навигация по частям темы;
     • индикатор прогресса чтения — на чистом CSS (scroll-timeline),
       где браузер его не умеет, полосы просто нет.

   Работает и на экране, и в печати (@media screen, print): учебник
   в PDF (tools/build_textbook_pdf.js) печатается в том же оформлении,
   что и на сайте, — раньше слой был только для экрана, и PDF выходил
   в старом виде. Каркас экрана (оглавление, «лист» с тенью, индикатор
   прокрутки) в печати выключен — блок @media print в конце файла.
   ============================================================ */

@media screen, print {

/* ——— Токены ——— */
body.with-sidebar,
.th-main {
    --tp-font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    --tp-mono: 'JetBrains Mono', 'SFMono-Regular', Menlo, Consolas, monospace;

    --tp-ink: #111A2C;
    --tp-text: #273244;
    --tp-mute: #677386;
    --tp-faint: #97A1B0;
    --tp-line: #E8E5DF;
    --tp-line-2: #F1EEE9;
    --tp-bg: #F5F4F0;
    --tp-paper: #FFFFFF;
    --tp-tint: #FAF9F6;

    --tp-accent: #E8850A;
    --tp-accent-2: #F5A623;
    --tp-accent-ink: #B45F06;
    --tp-accent-soft: #FFF4E3;
    --tp-accent-line: #F7D9AA;

    --tp-radius: 14px;
    --tp-radius-lg: 22px;
    --tp-shadow-1: 0 1px 2px rgba(17, 26, 44, 0.04);
    --tp-shadow-2: 0 1px 2px rgba(17, 26, 44, 0.04), 0 8px 24px -12px rgba(17, 26, 44, 0.12);
    --tp-shadow-3: 0 2px 4px rgba(17, 26, 44, 0.04), 0 18px 40px -16px rgba(17, 26, 44, 0.18);
    --tp-ease: cubic-bezier(0.2, 0.7, 0.2, 1);

    /* Переменные style.css — тем же значениям, чтобы компоненты,
       которые на них опираются, выглядели в одном ключе. */
    --font-body: var(--tp-font);
    --font-heading: var(--tp-font);
    --bg-body: var(--tp-bg);
    --text-primary: var(--tp-ink);
    --text-secondary: var(--tp-mute);
    --border-color: var(--tp-line);
}

/* ——— Шрифт ———
   Встроенные стили страниц ставят Open Sans с !important почти на
   всё подряд. Перебиваем тем же способом, но весом селектора выше.
   Формулы MathJax и моноширинный код не трогаем. */
body.with-sidebar,
body.with-sidebar :is(p, li, dt, dd, td, th, caption, h1, h2, h3, h4, h5, h6, a, span, div, strong, em, b, i, u, small,
    label, button, figcaption, blockquote, summary, sup, sub, table, section, article, aside, main, footer, nav) {
    font-family: var(--tp-font) !important;
}
body.with-sidebar :is(code, kbd, pre, samp) { font-family: var(--tp-mono) !important; }

body.with-sidebar {
    background:
        radial-gradient(1200px 520px at 50% -180px, rgba(245, 166, 35, 0.07), transparent 70%),
        var(--tp-bg);
    color: var(--tp-text);
    font-size: 16px;
    line-height: 1.7;
    text-rendering: optimizeLegibility;
    font-feature-settings: 'cv11', 'ss01', 'ss03';
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}
body.with-sidebar ::selection { background: rgba(245, 166, 35, 0.28); color: var(--tp-ink); }

/* ——— Индикатор прогресса чтения ——— */
@supports (animation-timeline: scroll()) {
    body.with-sidebar::after {
        content: "";
        position: fixed; left: 0; right: 0; top: 0; z-index: 9700;
        height: 3px; pointer-events: none;
        background: linear-gradient(90deg, #F5A623, #E8850A 60%, #D9630B);
        transform-origin: 0 50%;
        transform: scaleX(0);
        animation: tp-read-progress linear both;
        animation-timeline: scroll(root block);
    }
    @keyframes tp-read-progress { to { transform: scaleX(1); } }
}

/* ——— Каркас: оглавление + лист ——— */
body.with-sidebar > .container {
    max-width: 1248px;
    padding: 28px 24px 72px;
    gap: 28px;
    align-items: flex-start;
}

body.with-sidebar > .container > aside {
    width: 256px;
    min-width: 256px;
    padding: 20px 12px 16px 16px;
    top: calc(var(--hp-bar-h, 62px) + var(--hp-bar-gap, 12px) * 2 + 12px);
    max-height: calc(100vh - var(--hp-bar-h, 62px) - var(--hp-bar-gap, 12px) * 2 - 36px);
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: #DAD5CC transparent;
    background: rgba(255, 255, 255, 0.72);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(17, 26, 44, 0.06);
    border-radius: 18px;
    box-shadow: var(--tp-shadow-1);
}
body.with-sidebar > .container > aside:hover { box-shadow: var(--tp-shadow-2); }

body.with-sidebar aside h3 {
    margin: 0 0 10px;
    padding: 0 8px 12px;
    border-bottom: 1px solid var(--tp-line);
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    color: var(--tp-faint);
}
body.with-sidebar aside h3::before {
    width: 6px; height: 6px; border-radius: 50%;
    background: var(--tp-accent-2);
    box-shadow: 0 0 0 3px rgba(245, 166, 35, 0.18);
}

/* Пункты оглавления на общей «рейке»: активный подсвечен отрезком на ней. */
body.with-sidebar aside ul {
    position: relative;
    margin: 0;
    padding: 2px 0 2px 0;
}
body.with-sidebar aside ul::before {
    content: "";
    position: absolute; left: 8px; top: 6px; bottom: 6px;
    width: 1px; background: var(--tp-line);
}
body.with-sidebar aside li { margin: 0; }
body.with-sidebar aside a {
    position: relative;
    margin: 1px 0;
    padding: 7px 10px 7px 22px;
    border: 0;
    border-radius: 10px;
    font-size: 0.86rem;
    font-weight: 500;
    line-height: 1.4;
    color: var(--tp-mute);
    transition: color 0.16s ease, background-color 0.16s ease;
}
body.with-sidebar aside a::before {
    content: "";
    position: absolute; left: 7px; top: 50%;
    width: 3px; height: 0; border-radius: 3px;
    transform: translateY(-50%);
    background: var(--tp-accent);
    transition: height 0.22s var(--tp-ease);
}
body.with-sidebar aside a:hover {
    color: var(--tp-ink);
    background: rgba(17, 26, 44, 0.035);
    border: 0;
    transform: none;
}
body.with-sidebar aside a.active {
    color: var(--tp-accent-ink);
    background: var(--tp-accent-soft);
    font-weight: 650;
    border: 0;
}
body.with-sidebar aside a.active::before { height: 60%; }
body.with-sidebar aside a:focus-visible { outline: 2px solid var(--tp-accent-2); outline-offset: 1px; }

/* Лист */
body.with-sidebar > .container > main {
    padding: 52px clamp(22px, 5vw, 64px) 56px;
    border-radius: var(--tp-radius-lg);
    border: 1px solid rgba(17, 26, 44, 0.06);
    background: var(--tp-paper);
    box-shadow: var(--tp-shadow-2);
    min-width: 0;
}

/* ——— Типографика ——— */
body.with-sidebar main :is(p, li) {
    font-size: 1.0625rem;
    line-height: 1.72;
    color: var(--tp-text);
    text-align: left;
    hyphens: manual;
    -webkit-hyphens: manual;
    letter-spacing: -0.003em;
}
body.with-sidebar main p { margin: 0 0 1.05em; }
body.with-sidebar main p:empty { display: none; }

/* Жирное в тексте. Тёмные плашки и навигационные карточки держат
   свои цвета и начертания — их не трогаем. */
body.with-sidebar main :is(strong, b):not(:is(.hp-endtasks, .oly-teaser, .mt-cards, .mt-pager, .chapter-nav-container, .task-card-header, .test-block) *) {
    font-weight: 650;
    color: var(--tp-ink);
}
body.with-sidebar main sub, body.with-sidebar main sup { font-size: 0.72em; line-height: 0; }

/* Ссылки в тексте. Навигационные блоки (части темы, соседние
   страницы, крошки) оформлены отдельно и подчёркивания не получают. */
body.with-sidebar main a:not([class]):not(:is(nav, .mt-nav, .mt-pager, .mt-cards, .breadcrumbs, .chapter-nav-container, .hp-endtasks) a) {
    color: var(--tp-accent-ink);
    font-weight: 550;
    text-decoration: underline;
    text-decoration-color: rgba(232, 133, 10, 0.35);
    text-decoration-thickness: 1.5px;
    text-underline-offset: 3px;
    transition: color 0.15s ease, text-decoration-color 0.15s ease;
}
body.with-sidebar main a:not([class]):not(:is(nav, .mt-nav, .mt-pager, .mt-cards, .breadcrumbs, .chapter-nav-container, .hp-endtasks) a):hover { color: #8F4A03; text-decoration-color: currentColor; }
body.with-sidebar main :is(.mt-nav, .mt-pager, .mt-cards, .chapter-nav-container) a { text-decoration: none; }

body.with-sidebar main :is(h1, h2, h3, h4) {
    color: var(--tp-ink);
    text-wrap: balance;
    hyphens: manual;
}

body.with-sidebar main h1 {
    margin: 0 0 22px;
    padding: 0 0 26px;
    font-size: clamp(1.85rem, 1.25rem + 1.9vw, 2.55rem);
    font-weight: 800;
    line-height: 1.12;
    letter-spacing: -0.03em;
    border-bottom: 1px solid var(--tp-line);
}
body.with-sidebar main h1::after {
    bottom: -2px; width: 56px; height: 3px; border-radius: 3px;
    background: linear-gradient(90deg, #F5A623, #E8850A);
}

body.with-sidebar main h2 {
    margin: 3.1rem 0 1.1rem;
    padding-left: 18px;
    font-size: clamp(1.38rem, 1.15rem + 0.7vw, 1.66rem);
    font-weight: 750;
    line-height: 1.25;
    letter-spacing: -0.022em;
}
body.with-sidebar main h2::before {
    top: 0.18em; width: 4px; height: 1.02em; border-radius: 4px;
    background: linear-gradient(180deg, #F5A623, #E8850A);
    box-shadow: 0 0 0 3px rgba(245, 166, 35, 0.12);
}
body.with-sidebar main h3 {
    margin: 2.1rem 0 0.7rem;
    font-size: 1.24rem;
    font-weight: 700;
    line-height: 1.32;
    letter-spacing: -0.014em;
}
body.with-sidebar main h4 {
    margin: 1.6rem 0 0.55rem;
    font-size: 1.07rem;
    font-weight: 700;
    line-height: 1.4;
    letter-spacing: -0.008em;
}
body.with-sidebar main :is(h1, h2, h3, h4) + :is(h2, h3, h4) { margin-top: 0.9rem; }

/* Вводный абзац под заголовком */
body.with-sidebar main p.lead {
    font-size: 1.2rem;
    line-height: 1.6;
    color: #3E4A5C;
    letter-spacing: -0.01em;
    margin-bottom: 1.4rem;
}

/* Списки: свои маркеры вместо системных */
body.with-sidebar main :is(ul, ol):not([class]) {
    margin: 0.2rem 0 1.3rem;
    padding-left: 1.55rem;
}
body.with-sidebar main :is(ul, ol):not([class]) > li { margin: 0 0 0.45rem; padding-left: 0.25rem; }
body.with-sidebar main ul:not([class]) > li::marker { color: var(--tp-accent-2); font-size: 1.05em; }
body.with-sidebar main ol:not([class]) > li::marker { color: var(--tp-accent); font-weight: 700; font-variant-numeric: tabular-nums; }
body.with-sidebar main li > :is(ul, ol) { margin-top: 0.45rem; margin-bottom: 0.3rem; }

body.with-sidebar main hr { border: 0; height: 1px; background: var(--tp-line); margin: 2.4rem 0; }

body.with-sidebar main blockquote {
    margin: 1.6rem 0; padding: 0.4rem 0 0.4rem 1.2rem;
    border-left: 3px solid var(--tp-accent-line);
    color: #3E4A5C; font-style: italic;
}

body.with-sidebar main code:not([class]) {
    padding: 0.12em 0.4em; border-radius: 6px;
    background: #F4F2EE; border: 1px solid var(--tp-line-2);
    font-size: 0.88em; color: var(--tp-ink);
}

/* Картинки и подписи */
body.with-sidebar main img {
    border-radius: 12px;
}
body.with-sidebar main figure { margin: 1.8rem 0; }
body.with-sidebar main figcaption {
    margin-top: 0.65rem; font-size: 0.86rem; line-height: 1.5;
    color: var(--tp-mute); text-align: center; font-style: normal;
}

/* ——— Хлебные крошки и ссылка «наверх» к теме ——— */
body.with-sidebar main .breadcrumbs {
    margin: 0 0 18px;
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--tp-faint);
}
body.with-sidebar main .breadcrumbs a {
    color: var(--tp-mute);
    text-decoration: none;
    font-weight: 500;
}
body.with-sidebar main .breadcrumbs a:hover { color: var(--tp-accent-ink); }
body.with-sidebar main .breadcrumbs span { color: #C7CDD6; margin: 0 0.35rem; }

body.with-sidebar main .mt-up {
    display: inline-flex; align-items: center; gap: 6px;
    margin: 0 0 16px; padding: 5px 11px 5px 9px;
    border-radius: 999px;
    font-size: 0.8rem; font-weight: 600; letter-spacing: 0.005em;
    color: var(--tp-accent-ink);
    background: var(--tp-accent-soft);
    border: 1px solid var(--tp-accent-line);
    text-decoration: none;
    transition: background-color 0.15s ease, border-color 0.15s ease;
}
body.with-sidebar main .mt-up:hover { background: #FFEBCC; border-color: #F2C47E; }

/* ——— Навигация по частям темы: сегменты ——— */
body.with-sidebar main .mt-nav {
    gap: 6px;
    margin: 4px 0 30px;
    padding: 6px;
    border: 1px solid var(--tp-line);
    border-radius: 14px;
    background: var(--tp-tint);
}
body.with-sidebar main .mt-nav :is(a, span) {
    padding: 7px 13px;
    border: 1px solid transparent;
    border-radius: 10px;
    font-size: 0.82rem;
    font-weight: 600;
    line-height: 1.3;
    color: var(--tp-mute);
    background: transparent;
    transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
body.with-sidebar main .mt-nav a:hover { background: #fff; border-color: var(--tp-line); color: var(--tp-ink); }
body.with-sidebar main .mt-nav span {
    background: #fff;
    color: var(--tp-ink);
    border-color: var(--tp-line);
    box-shadow: 0 1px 2px rgba(17, 26, 44, 0.06), inset 0 -2px 0 var(--tp-accent-2);
}

/* Карточки частей темы */
body.with-sidebar main .mt-cards { gap: 12px; margin: 1.4rem 0 2.4rem; }
body.with-sidebar main .mt-cards a {
    padding: 18px 18px 16px;
    border-radius: 16px;
    border-color: var(--tp-line);
    box-shadow: var(--tp-shadow-1);
    transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s var(--tp-ease);
}
body.with-sidebar main .mt-cards a::after { display: none; }
body.with-sidebar main .mt-cards a::before {
    border-radius: 11px;
    font-weight: 750;
    font-variant-numeric: tabular-nums;
}
body.with-sidebar main .mt-cards a:hover {
    border-color: var(--tp-accent-line);
    box-shadow: var(--tp-shadow-3);
    transform: translateY(-2px);
}
body.with-sidebar main .mt-cards b { font-size: 1rem; font-weight: 700; letter-spacing: -0.01em; }
body.with-sidebar main .mt-cards span { font-size: 0.86rem; color: var(--tp-mute); }
body.with-sidebar main .mt-cards em { font-weight: 700; color: var(--tp-faint); letter-spacing: 0.06em; }

/* Соседние части: «Назад» / «Дальше» */
body.with-sidebar main .mt-pager { gap: 12px; margin: 2.8rem 0 1.4rem; }
body.with-sidebar main .mt-pager a {
    position: relative;
    padding: 16px 20px;
    border-radius: 16px;
    border: 1px solid var(--tp-line);
    background: var(--tp-paper);
    box-shadow: var(--tp-shadow-1);
    transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s var(--tp-ease);
}
body.with-sidebar main .mt-pager a:hover {
    border-color: var(--tp-accent-line);
    box-shadow: var(--tp-shadow-3);
    transform: translateY(-2px);
}
body.with-sidebar main .mt-pager small {
    margin-bottom: 4px;
    font-size: 0.72rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
    color: var(--tp-faint);
}
body.with-sidebar main .mt-pager b { font-size: 0.98rem; font-weight: 700; color: var(--tp-ink); letter-spacing: -0.01em; }
body.with-sidebar main .mt-pager a:hover b { color: var(--tp-accent-ink); }

/* Соседние темы (chapter-nav) — в том же ключе */
body.with-sidebar main .chapter-nav-container { gap: 12px; margin-top: 2.8rem; }
body.with-sidebar main .chapter-nav-btn {
    border-radius: 16px;
    border: 1px solid var(--tp-line);
    background: var(--tp-paper);
    box-shadow: var(--tp-shadow-1);
    transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s var(--tp-ease);
}
body.with-sidebar main .chapter-nav-btn:hover {
    border-color: var(--tp-accent-line);
    box-shadow: var(--tp-shadow-3);
    transform: translateY(-2px);
}
body.with-sidebar main .chapter-nav-icon {
    border-radius: 12px;
    background: var(--tp-accent-soft);
    color: var(--tp-accent-ink);
}
body.with-sidebar main .chapter-nav-label {
    font-size: 0.72rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
    color: var(--tp-faint);
}
body.with-sidebar main .chapter-nav-title { font-weight: 700; color: var(--tp-ink); letter-spacing: -0.01em; }

/* ——— Выноски ———
   Один язык для всех: светлый фон своего цвета, тонкая рамка,
   акцентная полоса слева, заголовок-«ярлык». Вместо разнобоя из
   клетчатых фонов, толстых рамок, штриховок и прыжков при наведении. */
body.with-sidebar main :is(.chem-note, .chem-def, .chem-exception, .info-box, .definition, .definition-card,
    .warning-box, .exception-box, .example-solution, .clarification-frame) {
    --c: #D98A0B; --c-bg: #FFFAF1; --c-line: #F6E2BF; --c-ink: #8A4B06;
    position: relative;
    margin: 1.8rem 0;
    padding: 18px 22px 18px 24px;
    border: 1px solid var(--c-line);
    border-radius: var(--tp-radius);
    background: var(--c-bg);
    box-shadow: none;
    overflow: hidden;
    transform: none;
}
body.with-sidebar main :is(.chem-note, .chem-def, .chem-exception, .info-box, .definition, .definition-card,
    .warning-box, .exception-box, .example-solution, .clarification-frame):hover { transform: none; box-shadow: none; }
body.with-sidebar main :is(.chem-note, .chem-def, .chem-exception, .info-box, .definition, .definition-card,
    .warning-box, .exception-box, .example-solution, .clarification-frame)::before {
    content: "";
    position: absolute; left: 0; top: 0; bottom: 0;
    width: 4px; border-radius: 0;
    background: var(--c);
}
/* Клетчатый фон определений больше не нужен. */
body.with-sidebar main .chem-def::after { display: none; }

body.with-sidebar main :is(.chem-def, .definition, .definition-card) {
    --c: #E8850A; --c-bg: #FFF7EC; --c-line: #F7D9AA; --c-ink: #9A4F04;
}
body.with-sidebar main :is(.chem-exception, .warning-box, .exception-box) {
    --c: #E0454B; --c-bg: #FFF5F5; --c-line: #F8D4D5; --c-ink: #A61B22;
}
body.with-sidebar main :is(.info-box, .clarification-frame) {
    --c: #2F80ED; --c-bg: #F4F8FF; --c-line: #D6E4FB; --c-ink: #1D4F9E;
}
body.with-sidebar main .example-solution {
    --c: #12A36B; --c-bg: #F2FBF6; --c-line: #CBEBDB; --c-ink: #0B6B46;
}

body.with-sidebar main :is(.chem-note-title, .chem-def-title, .chem-exception-title) {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0 0 8px;
    padding: 0;
    background: none;
    border-radius: 0;
    font-size: 0.78rem;
    font-weight: 750;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--c-ink);
}
body.with-sidebar main :is(.chem-note-text, .chem-def-text, .chem-exception-text),
body.with-sidebar main :is(.chem-note, .chem-def, .chem-exception, .info-box, .definition, .warning-box, .exception-box, .example-solution) :is(p, li) {
    font-size: 1rem;
    line-height: 1.65;
    color: #2F3A4C;
    margin-bottom: 0.5em;
}
body.with-sidebar main :is(.chem-note, .chem-def, .chem-exception, .info-box, .definition, .warning-box, .exception-box, .example-solution) > :last-child,
body.with-sidebar main :is(.chem-note-text, .chem-def-text, .chem-exception-text):last-child { margin-bottom: 0; }
body.with-sidebar main :is(.chem-def-text, .chem-note-text, .chem-exception-text) strong { color: var(--c-ink); }
body.with-sidebar main .chem-def-content { position: static; }

/* Короткие примечания в таблицах */
body.with-sidebar main .prop-note { color: var(--tp-mute); font-size: 0.94em; }

/* ——— Карточки понятий ——— */
body.with-sidebar main .chem-card {
    border-radius: 16px;
    box-shadow: var(--tp-shadow-1);
    transition: box-shadow 0.2s ease, transform 0.2s var(--tp-ease);
}
body.with-sidebar main .chem-card:hover { box-shadow: var(--tp-shadow-3); transform: translateY(-2px); }

/* ——— Таблицы ———
   Мягкая рамка вместо двухпиксельной цветной, скруглённые углы,
   цвет таблицы остаётся в шапке — по нему узнаётся тип (получение,
   свойства, примеры), но он больше не кричит со всех линий сразу. */
body.with-sidebar main .chem-table-wrap {
    margin: 1.4rem 0 1.8rem;
    padding-bottom: 4px;
    border-radius: 16px;
    scrollbar-width: thin;
    scrollbar-color: #D8D2C8 transparent;
}
body.with-sidebar main :is(.chem-table, .table-properties, .table-properties-blue, .table-properties-orange, .styled-table, .minimalist-table, .calc-table) {
    --t: #8B5CF6; --t-head: #F7F4FF; --t-ink: #4C2A9E; --t-first: #FCFBFF;
    border-collapse: separate;
    border-spacing: 0;
    border: 1px solid #E4E1EA;
    border-radius: 16px;
    overflow: hidden;
    background: #fff;
    box-shadow: var(--tp-shadow-1);
    font-size: 0.97rem;
}
body.with-sidebar main .table-properties-blue { --t: #2F80ED; --t-head: #F3F7FE; --t-ink: #1D4F9E; --t-first: #FAFCFF; border-color: #DCE5F3; }
body.with-sidebar main .table-properties-orange { --t: #E8850A; --t-head: #FFF7EC; --t-ink: #8F4A03; --t-first: #FFFCF6; border-color: #EFE3D1; }
body.with-sidebar main :is(.chem-table, .styled-table, .minimalist-table, .calc-table) { --t: #94A3B8; --t-head: #F7F8FA; --t-ink: #1F2A3C; --t-first: #FFFFFF; border-color: #E3E6EB; }

body.with-sidebar main :is(.chem-table, .table-properties, .table-properties-blue, .table-properties-orange, .styled-table, .minimalist-table, .calc-table) :is(th, td) {
    border: 0;
    border-bottom: 1px solid #EEECEF;
    border-right: 1px solid #F1EFF2;
    padding: 12px 16px;
    line-height: 1.55;
    color: var(--tp-text);
    vertical-align: top;
}
body.with-sidebar main :is(.chem-table, .table-properties, .table-properties-blue, .table-properties-orange, .styled-table, .minimalist-table, .calc-table) :is(th, td):last-child { border-right: 0; }
body.with-sidebar main :is(.chem-table, .table-properties, .table-properties-blue, .table-properties-orange, .styled-table, .minimalist-table, .calc-table) tr:last-child > td { border-bottom: 0; }

body.with-sidebar main :is(.chem-table, .table-properties, .table-properties-blue, .table-properties-orange, .styled-table, .minimalist-table, .calc-table) th {
    background: var(--t-head);
    color: var(--t-ink);
    font-size: 0.8rem;
    font-weight: 750;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    vertical-align: middle;
    border-bottom: 1px solid color-mix(in srgb, var(--t) 22%, #fff);
    box-shadow: inset 0 3px 0 var(--t);
}
body.with-sidebar main :is(.chem-table, .table-properties, .table-properties-blue, .table-properties-orange, .styled-table, .minimalist-table, .calc-table) th ~ th { box-shadow: inset 0 3px 0 var(--t); }
body.with-sidebar main :is(.table-properties, .table-properties-blue, .table-properties-orange) td:first-child {
    background: var(--t-first);
    color: var(--tp-ink);
    font-weight: 650;
    vertical-align: middle;
}
body.with-sidebar main :is(.chem-table, .styled-table) tbody tr { transition: background-color 0.12s ease; }
body.with-sidebar main :is(.chem-table, .styled-table) tbody tr:hover > td { background: #FAFAF8; }
body.with-sidebar main .chem-table.striped tbody tr:nth-child(even) > td { background: #FBFAF8; }
body.with-sidebar main :is(.table-section-header, .table-section-header-blue, .table-section-header-orange) {
    background: color-mix(in srgb, var(--t) 9%, #fff) !important;
    color: var(--t-ink) !important;
    font-size: 0.78rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}
body.with-sidebar main :is(th, td) p { margin-bottom: 0.4em; }
body.with-sidebar main :is(th, td) p:last-child { margin-bottom: 0; }

/* Уравнения реакций: цифры одной ширины, стрелки аккуратнее */
body.with-sidebar main :is(.reaction, .reaction-mini, .reaction-box, .formula-bubble, .ion-equation, .equation-box) {
    font-variant-numeric: tabular-nums;
    letter-spacing: 0;
}
body.with-sidebar main .reaction-box {
    border-radius: 14px;
    border-color: var(--tp-line);
    background: var(--tp-tint);
    box-shadow: none;
    font-size: 1.08rem;
}
body.with-sidebar main .reaction-mini {
    border-radius: 12px;
    border-color: var(--tp-line);
    background: #fff;
    box-shadow: var(--tp-shadow-1);
}
body.with-sidebar main .reaction-mini:hover { box-shadow: var(--tp-shadow-2); }
body.with-sidebar main .ra-condition { font-weight: 600; }

/* ——— Карточки задач «Проверь себя» ——— */
body.with-sidebar main .task-card {
    margin: 0 0 12px;
    border-radius: 16px;
    border: 1px solid var(--tp-line);
    background: #fff;
    box-shadow: var(--tp-shadow-1);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
body.with-sidebar main .task-card:hover { box-shadow: var(--tp-shadow-2); border-color: #E0DBD2; }
body.with-sidebar main .task-card.open { border-color: var(--tp-accent-line); box-shadow: var(--tp-shadow-3); }
body.with-sidebar main .task-card-header { padding: 16px 20px; gap: 14px; }
body.with-sidebar main .task-card-header:hover { background: var(--tp-tint); }
body.with-sidebar main .task-card-header h4 {
    margin: 0;
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--tp-ink);
}
body.with-sidebar main .task-card-header .task-badge {
    padding: 4px 10px;
    border-radius: 999px;
    background: var(--tp-accent-soft);
    color: var(--tp-accent-ink);
    border: 1px solid var(--tp-accent-line);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.02em;
}
body.with-sidebar main .task-card-chevron {
    width: 30px; height: 30px; padding: 6px;
    border-radius: 10px;
    background: #F4F2EE;
    stroke: var(--tp-mute);
    stroke-width: 2.4;
}
body.with-sidebar main .task-card.open .task-card-chevron { background: var(--tp-accent-soft); stroke: var(--tp-accent); }
body.with-sidebar main .task-card-condition {
    padding: 0 20px 16px;
    border-bottom-color: var(--tp-line-2);
    font-size: 1rem;
    color: var(--tp-text);
}
body.with-sidebar main .task-card.open .task-card-body {
    padding: 18px 20px 20px;
    background: linear-gradient(180deg, #FCFBF8, #fff 40%);
}

/* Вкладки внутри тем (типы, элементы, структуры) */
body.with-sidebar main :is(.type-tabs, .element-tabs) { gap: 6px; }
body.with-sidebar main :is(.type-tab, .element-tab, .nm-tab, .struct-tab) {
    border-radius: 10px;
    font-weight: 600;
    transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

/* Видео опытов */
body.with-sidebar main :is(.video-container, .video-widget) iframe,
body.with-sidebar main :is(.video-container, .video-widget) video { border-radius: 14px; }

/* Картинки реакций */
body.with-sidebar main .rxn-img-wrap { border-radius: 12px; }

/* Переход к заданиям в конце темы */
body.with-sidebar main div.hp-endtasks {
    margin-top: 2.6rem;
    border-radius: 20px;
}

/* ——— Подвал ——— */
body.with-sidebar > footer,
body.with-sidebar footer.th-footer {
    margin-top: 8px;
    border-top: 1px solid var(--tp-line);
    background: transparent;
    color: var(--tp-faint);
    font-size: 0.84rem;
}
body.with-sidebar > footer a,
body.with-sidebar footer.th-footer a { color: var(--tp-mute) !important; text-decoration: none; }
body.with-sidebar > footer a:hover,
body.with-sidebar footer.th-footer a:hover { color: var(--tp-accent-ink) !important; }
body.with-sidebar > footer p { text-align: center; color: var(--tp-faint); font-size: 0.8rem; }

/* ——— Фокус с клавиатуры ——— */
body.with-sidebar main :is(a, button, [tabindex]):focus-visible {
    outline: 2px solid var(--tp-accent-2);
    outline-offset: 2px;
    border-radius: 6px;
}

/* ——— Планшет и телефон ——— */
@media (max-width: 1024px) {
    body.with-sidebar > .container { padding: 16px 16px 56px; }
    body.with-sidebar > .container > main {
        padding: 34px clamp(18px, 5vw, 40px) 40px;
        /* Колонка выровнена по левому краю, и лист без класса .content
           подстраивался под самую широкую таблицу или формулу и вылезал
           за экран. Лист всегда во всю ширину, широкое листается внутри. */
        align-self: stretch;
        max-width: 100%;
        box-sizing: border-box;
    }
    body.with-sidebar main :is(.chem-table-wrap, .hp-table-scroll) { max-width: 100%; overflow-x: auto; }
}
@media (max-width: 640px) {
    body.with-sidebar { font-size: 15px; }
    body.with-sidebar > .container { padding: 8px 0 40px; }
    body.with-sidebar > .container > main {
        padding: 26px 18px 30px;
        border-radius: 20px;
        border-left: 0; border-right: 0;
        box-shadow: 0 1px 2px rgba(17, 26, 44, 0.05);
    }
    body.with-sidebar main :is(p, li) { font-size: 1.03rem; line-height: 1.7; }
    body.with-sidebar main p.lead { font-size: 1.1rem; }
    body.with-sidebar main h1 { padding-bottom: 20px; margin-bottom: 18px; letter-spacing: -0.025em; }
    body.with-sidebar main h2 { margin-top: 2.4rem; padding-left: 14px; }
    body.with-sidebar main :is(.chem-note, .chem-def, .chem-exception, .info-box, .definition, .definition-card,
        .warning-box, .exception-box, .example-solution, .clarification-frame) { padding: 15px 16px 15px 19px; margin: 1.4rem 0; }
    body.with-sidebar main .mt-nav { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin-left: -4px; margin-right: -4px; }
    body.with-sidebar main .mt-nav::-webkit-scrollbar { display: none; }
    body.with-sidebar main .mt-nav :is(a, span) { flex: none; white-space: nowrap; }
    body.with-sidebar main .task-card-header { padding: 14px 14px; }
    body.with-sidebar main .task-card-condition { padding: 0 14px 14px; }
    body.with-sidebar main .task-card.open .task-card-body { padding: 14px; }
    body.with-sidebar main :is(.chem-table, .table-properties, .table-properties-blue, .table-properties-orange, .styled-table, .minimalist-table, .calc-table) :is(th, td) { padding: 10px 12px; }
}

@media (prefers-reduced-motion: reduce) {
    body.with-sidebar *, body.with-sidebar *::before, body.with-sidebar *::after { transition: none !important; }
    body.with-sidebar::after { display: none; }
}


/* ============================================================
   Оглавление учебника: /firstchap/theory.html (.th-main)
   ============================================================ */
.th-main { font-family: var(--tp-font); }
.th-main > h1 {
    font-size: clamp(1.5rem, 1.1rem + 1.4vw, 2rem) !important;
    font-weight: 800 !important;
    letter-spacing: -0.025em;
    color: var(--tp-ink) !important;
}
.th-main > p { color: var(--tp-mute); }
.th-main .section-block {
    border-radius: 18px !important;
    border: 1px solid var(--tp-line) !important;
    background: #fff !important;
    box-shadow: var(--tp-shadow-1) !important;
    overflow: hidden;
    transition: box-shadow 0.2s ease, border-color 0.2s ease;
}
.th-main .section-block:hover { box-shadow: var(--tp-shadow-2) !important; border-color: #E1DCD3 !important; }
.th-main .section-header {
    background: linear-gradient(180deg, #FFFBF4, #FFF6E9) !important;
    border-bottom: 1px solid #F3E6D0 !important;
}
.th-main .section-header h2 {
    font-weight: 750 !important;
    letter-spacing: -0.015em;
    color: var(--tp-ink) !important;
}
.th-main .topic-row {
    transition: background-color 0.15s ease;
    border-bottom-color: var(--tp-line-2) !important;
}
.th-main .topic-row:hover { background: var(--tp-tint) !important; }
.th-main .tr-number {
    font-variant-numeric: tabular-nums;
    font-weight: 700 !important;
    color: var(--tp-faint) !important;
}
.th-main .tr-link {
    color: var(--tp-ink) !important;
    font-weight: 550 !important;
    text-decoration: none;
    transition: color 0.15s ease;
}
.th-main .tr-link:hover { color: var(--tp-accent-ink) !important; }
.th-main .tr-test {
    border-radius: 999px !important;
    border: 1px solid var(--tp-accent-line) !important;
    background: var(--tp-accent-soft) !important;
    color: var(--tp-accent-ink) !important;
    font-weight: 650 !important;
    transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}
.th-main .tr-test:hover { background: #FFEBCC !important; border-color: #F2C47E !important; transform: translateY(-1px); }

} /* @media screen, print */

/* ——— Печать (и PDF учебника): только содержимое листа ——— */
@media print {
    body.with-sidebar::after { display: none !important; }
    body.with-sidebar > .container { max-width: none; padding: 0; gap: 0; }
    body.with-sidebar > .container > main {
        padding: 0; border: 0; border-radius: 0; box-shadow: none; background: transparent;
    }
    body.with-sidebar main :is(p, li) { font-size: 1rem; line-height: 1.6; }
    /* Лист PDF раскладывается шириной ~756 px, и срабатывает мобильное правило
       style.css: таблица свойств становится блоком с прокруткой и ужимается
       до ширины содержимого. На бумаге прокрутки нет — обычная таблица на всю ширину. */
    body.with-sidebar main :is(.table-properties, .table-properties-blue, .table-properties-orange) {
        display: table !important; width: 100% !important; max-width: none !important; min-width: 0 !important; overflow: visible !important;
    }
    body.with-sidebar main :is(.chem-table-wrap, .hp-table-scroll) { overflow: visible !important; }
    /* Выноски не рвём между листами; таблицы свойств бывают длиннее листа — их можно */
    body.with-sidebar main :is(.definition-box, .warning-box, .exception-box, .example-solution) { break-inside: avoid; }
}


/* ——— Тест после подглавы (js/topic-quiz.js) ———
   Одна карточка на подглаву: вопрос за вопросом, разбор после
   ответа, итог в конце. Вид — как у интерактива «Угадайте элемент»
   в уроках ЕГЭ: тёмная плашка с вопросом, варианты с буквами. */
.tq__print { display: none; }
.tq__sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

@media screen {
body.with-sidebar main .tq {
    position: relative;
    margin: 28px 0 32px;
    border-radius: 22px;
    border: 1px solid var(--tp-line);
    background: #fff;
    box-shadow: var(--tp-shadow-2);
    overflow: hidden;
}
body.with-sidebar main .tq:not([data-tq-ready]) { display: none; }
body.with-sidebar main .tq__head {
    display: flex; align-items: flex-start; gap: 12px;
    padding: 14px 18px;
    border-bottom: 1px solid var(--tp-line-2);
    background: var(--tp-tint);
}
body.with-sidebar main .tq__icon {
    flex: none; display: grid; place-items: center;
    width: 36px; height: 36px; border-radius: 11px;
    background: var(--tp-accent-soft); border: 1px solid var(--tp-accent-line);
}
body.with-sidebar main .tq__icon svg { width: 18px; height: 18px; fill: none; stroke: var(--tp-accent); stroke-width: 2; stroke-linejoin: round; }
body.with-sidebar main .tq__htext { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
body.with-sidebar main .tq__kicker {
    font-size: 0.72rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--tp-accent-ink);
}
body.with-sidebar main .tq__title { font-size: 1rem; font-weight: 700; line-height: 1.3; color: var(--tp-ink); }
body.with-sidebar main .tq__best {
    align-self: flex-start; margin-top: 5px; padding: 3px 9px; border-radius: 999px;
    background: #EAF7EF; color: #17703F; border: 1px solid #BFE6CD;
    font-size: 0.75rem; font-weight: 700; font-variant-numeric: tabular-nums;
}
body.with-sidebar main .tq__best[hidden] { display: none; }
body.with-sidebar main .tq__body { padding: 16px 18px 18px; }
body.with-sidebar main .tq__meta {
    display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
    font-size: 0.86rem; font-weight: 600; color: var(--tp-mute);
}
body.with-sidebar main .tq__score { font-family: var(--tp-mono) !important; font-size: 0.8rem; font-variant-numeric: tabular-nums; }
body.with-sidebar main .tq__bar { height: 4px; margin: 8px 0 14px; border-radius: 99px; background: var(--tp-line-2); overflow: hidden; }
body.with-sidebar main .tq__bar i { display: block; height: 100%; border-radius: inherit; background: var(--tp-accent); transition: width 0.35s var(--tp-ease); }
body.with-sidebar main .tq__panel {
    padding: 22px 20px;
    border-radius: 16px;
    background: linear-gradient(135deg, #0B1220, #1E293B);
    border: 2px solid #0B1220;
    text-align: center;
}
body.with-sidebar main .tq__panel--long { text-align: left; padding: 18px 18px; }
body.with-sidebar main .tq__q {
    margin: 0; color: #fff; font-size: 1.12rem; font-weight: 650; line-height: 1.5; letter-spacing: -0.005em;
    overflow-wrap: anywhere;
}
body.with-sidebar main .tq__opts { display: grid; gap: 8px; margin-top: 12px; }
@media (min-width: 640px) {
    body.with-sidebar main .tq__opts--grid { grid-template-columns: 1fr 1fr; }
}
body.with-sidebar main .tq__opt {
    display: flex; align-items: center; gap: 12px;
    width: 100%; min-height: 48px; margin: 0;
    padding: 10px 12px;
    border-radius: 14px;
    border: 2px solid var(--tp-line);
    background: #fff;
    color: var(--tp-ink);
    font-size: 1rem; font-weight: 600; line-height: 1.35; text-align: left;
    cursor: pointer;
    transition: border-color 0.15s ease, background-color 0.15s ease, opacity 0.15s ease, transform 0.15s ease;
    -webkit-tap-highlight-color: transparent;
}
body.with-sidebar main .tq__opt:not(:disabled):hover { border-color: var(--tp-ink); transform: translateY(-1px); }
body.with-sidebar main .tq__opt:focus-visible { outline: 3px solid var(--tp-accent-line); outline-offset: 2px; }
body.with-sidebar main .tq__opt:disabled { cursor: default; }
body.with-sidebar main .tq__letter {
    flex: none; display: grid; place-items: center;
    width: 30px; height: 30px; border-radius: 9px;
    background: #F1EFEA; color: var(--tp-mute);
    font-size: 0.85rem; font-weight: 800;
}
body.with-sidebar main .tq__label { flex: 1; min-width: 0; overflow-wrap: anywhere; }
body.with-sidebar main .tq__mark { flex: none; width: 22px; height: 22px; }
body.with-sidebar main .tq__mark svg { width: 22px; height: 22px; fill: none; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
body.with-sidebar main .tq__opt.is-right { border-color: #22A05A; background: #EDF9F1; }
body.with-sidebar main .tq__opt.is-right .tq__letter { background: #22A05A; color: #fff; }
body.with-sidebar main .tq__opt.is-right .tq__mark svg { stroke: #17803F; }
body.with-sidebar main .tq__opt.is-wrong { border-color: #F2A9A9; background: #FFF1F1; }
body.with-sidebar main .tq__opt.is-wrong .tq__letter { background: #E5484D; color: #fff; }
body.with-sidebar main .tq__opt.is-wrong .tq__mark svg { stroke: #D23A3F; }
body.with-sidebar main .tq__opt.is-dim { opacity: 0.55; }
body.with-sidebar main .tq__why {
    margin-top: 12px; padding: 14px 16px;
    border-radius: 16px; border: 1px solid var(--tp-line); background: var(--tp-tint);
    animation: tq-in 0.3s var(--tp-ease);
}
body.with-sidebar main .tq__verdict { display: block; margin-bottom: 4px; font-size: 1rem; font-weight: 750; }
body.with-sidebar main .tq__why.is-right .tq__verdict { color: #17803F; }
body.with-sidebar main .tq__why.is-wrong .tq__verdict { color: #C2353A; }
body.with-sidebar main .tq__why p { margin: 0; font-size: 0.97rem; line-height: 1.6; color: var(--tp-text); }
body.with-sidebar main :is(.tq__next, .tq__again) {
    display: inline-flex; align-items: center; gap: 8px;
    height: 44px; margin-top: 12px; padding: 0 18px;
    border: 0; border-radius: 12px;
    background: var(--tp-ink); color: #fff;
    font-size: 0.97rem; font-weight: 700;
    cursor: pointer;
    transition: background-color 0.15s ease, transform 0.15s ease;
}
body.with-sidebar main :is(.tq__next, .tq__again):hover { background: #26324A; transform: translateY(-1px); }
body.with-sidebar main :is(.tq__next, .tq__again):focus-visible { outline: 3px solid var(--tp-accent-line); outline-offset: 2px; }
body.with-sidebar main :is(.tq__next, .tq__again) svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
body.with-sidebar main .tq__result { padding: 14px 4px 6px; text-align: center; }
body.with-sidebar main .tq__total {
    font-size: 2.6rem; font-weight: 800; line-height: 1.1; letter-spacing: -0.03em; color: var(--tp-faint);
    font-variant-numeric: tabular-nums;
}
body.with-sidebar main .tq__total b {
    font-weight: 800;
    background: linear-gradient(135deg, var(--tp-accent), #D9480F);
    -webkit-background-clip: text; background-clip: text; color: transparent;
}
body.with-sidebar main .tq__resmsg { margin: 8px auto 0; max-width: 34em; font-size: 1rem; color: var(--tp-text); }
@keyframes tq-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) {
    body.with-sidebar main .tq__why { animation: none; }
    body.with-sidebar main .tq__bar i { transition: none; }
}
@media (max-width: 480px) {
    body.with-sidebar main .tq { margin-left: -4px; margin-right: -4px; border-radius: 18px; }
    body.with-sidebar main .tq__head { padding: 12px 14px; }
    body.with-sidebar main .tq__body { padding: 14px 12px 14px; }
    body.with-sidebar main .tq__panel { padding: 18px 14px; border-radius: 14px; }
    body.with-sidebar main .tq__q { font-size: 1.04rem; }
    body.with-sidebar main .tq__opt { gap: 10px; padding: 9px 10px; font-size: 0.97rem; }
}
}

@media print {
    body.with-sidebar main .tq { margin: 18px 0; break-inside: auto; }
    body.with-sidebar main .tq :is(.tq__head, .tq__body) { display: none; }
    body.with-sidebar main .tq::before {
        content: "Проверьте себя: " attr(data-title);
        display: block; margin-bottom: 8px; font-weight: 700; color: var(--tp-ink);
    }
    body.with-sidebar main .tq__print { display: block; margin: 0; padding-left: 1.4em; }
    body.with-sidebar main .tq__print li { margin: 0 0 8px; break-inside: avoid; }
    body.with-sidebar main .tq__print p { margin: 0; }
    body.with-sidebar main .tq__print-a { color: var(--tp-mute); font-size: 0.92rem; }
}
