/* Каркас сайта: шапка, подвал, статьи теории, справочник, главная.
   Стили лаборатории (схема передачи, таблицы, деревья) — в style.css. */

:root {
    --bg: #f2f2f2;
    --surface: #ffffff;
    --surface-muted: #f7f7f5;
    --text: #222222;
    --text-muted: #5f6368;
    --border: #dadce0;
    --dark: #1f1f1f;
    --accent: #1a5fa8;
    --accent-soft: #e8f0fa;
    --ok: #0a6b2e;
    --ok-soft: #e6f4ea;
    --warn: #8a5300;
    --warn-soft: #fff4e0;
    --math-font: "Cambria Math", "Cambria", "STIX Two Math", "Times New Roman", serif;
    --radius: 10px;
}

* {
    box-sizing: border-box;
}

html {
    scroll-padding-top: 80px;
}

body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;

    font-family: Arial, "Helvetica Neue", sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

#content {
    flex: 1;
}

a {
    color: var(--accent);
}

a:hover {
    text-decoration-thickness: 2px;
}

:focus-visible {
    outline: 3px solid #7aa7e0;
    outline-offset: 2px;
}

.skip-link {
    position: absolute;
    left: -9999px;
    top: 0;
    z-index: 100;
    padding: 10px 16px;
    background: var(--surface);
}

.skip-link:focus {
    left: 10px;
    top: 10px;
}


/* --- Шапка --- */

.site-header {
    position: sticky;
    top: 0;
    z-index: 50;
    background: var(--dark);
    color: white;
}

.site-header-inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;

    display: flex;
    align-items: center;
    gap: 24px;
    min-height: 60px;
}

.site-brand {
    display: flex;
    align-items: center;
    gap: 10px;

    color: white;
    font-weight: bold;
    text-decoration: none;
}

.site-brand-mark {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;

    border-radius: 8px;
    background: white;
    color: var(--dark);
    font-family: var(--math-font);
    font-size: 20px;
}

.site-nav {
    display: flex;
    gap: 4px;
    margin-left: auto;
}

.site-nav a {
    padding: 8px 12px;
    border-radius: 6px;

    color: #e8eaed;
    text-decoration: none;
    font-size: 15px;
}

.site-nav a:hover {
    background: rgba(255, 255, 255, 0.1);
}

.site-nav a[aria-current="page"] {
    background: rgba(255, 255, 255, 0.16);
    color: white;
}

.nav-toggle {
    display: none;
    margin-left: auto;
    padding: 8px 14px;

    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: 6px;
    background: transparent;
    color: white;
    font-size: 15px;
    cursor: pointer;
}

@media (max-width: 860px) {
    .nav-toggle {
        display: block;
    }

    .site-header-inner {
        flex-wrap: wrap;
    }

    .site-nav {
        display: none;
        flex-basis: 100%;
        flex-direction: column;
        padding-bottom: 12px;
    }

    .site-nav.open {
        display: flex;
    }
}


/* --- Подвал --- */

.site-footer {
    margin-top: 60px;
    background: var(--dark);
    color: #c4c7c5;
    font-size: 14px;
}

.site-footer-inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 28px 20px;

    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 20px;
}

.site-footer b {
    color: white;
}

.site-footer a {
    color: #c4c7c5;
}

.footer-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 18px;
}


/* --- Общая сетка страниц --- */

.page {
    max-width: 1200px;
    margin: 0 auto;
    padding: 36px 20px 0;
}

.page-head {
    margin-bottom: 28px;
}

.page-head h1 {
    margin: 0 0 8px;
    font-size: 34px;
    line-height: 1.2;
}

.page-head .lead {
    margin: 0;
    max-width: 760px;
    color: var(--text-muted);
    font-size: 18px;
}

.breadcrumbs {
    margin-bottom: 14px;
    font-size: 14px;
    color: var(--text-muted);
}

.breadcrumbs a {
    color: var(--text-muted);
}


/* --- Главная --- */

.hero {
    padding: 56px 20px 48px;
    background: linear-gradient(135deg, #2b2b2b, #111);
    color: white;
}

.hero-inner {
    max-width: 1200px;
    margin: 0 auto;
}

.hero h1 {
    margin: 0 0 14px;
    font-size: 42px;
    line-height: 1.15;
}

.hero p {
    max-width: 720px;
    margin: 0 0 26px;
    color: #dadce0;
    font-size: 19px;
}

.hero-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.button-link {
    display: inline-block;
    padding: 12px 22px;

    border-radius: 8px;
    background: white;
    color: var(--dark);
    font-weight: bold;
    text-decoration: none;
}

.button-link.secondary {
    border: 1px solid rgba(255, 255, 255, 0.5);
    background: transparent;
    color: white;
}

.scheme {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin-top: 34px;

    font-size: 15px;
}

.scheme span {
    padding: 8px 14px;
    border: 1px solid rgba(255, 255, 255, 0.35);
    border-radius: 8px;
}

.scheme .scheme-arrow {
    padding: 0;
    border: none;
    color: #9aa0a6;
}

.scheme .scheme-noise {
    border-style: dashed;
    color: #fbbc04;
}

.section-title {
    margin: 44px 0 16px;
    font-size: 24px;
}

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 16px;
}

.card {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 20px;

    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}

.card h3 {
    margin: 0;
    font-size: 18px;
}

.card p {
    margin: 0;
    flex: 1;
    color: var(--text-muted);
    font-size: 15px;
}

.card-links {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    margin-top: 6px;
    font-size: 15px;
}

.card-group {
    color: var(--text-muted);
    font-size: 12px;
    font-weight: bold;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.steps-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 16px;
    margin: 0;
    padding: 0;
    list-style: none;
    counter-reset: step;
}

.steps-list li {
    padding: 18px 20px;
    border-radius: var(--radius);
    background: var(--surface);
    border: 1px solid var(--border);
    counter-increment: step;
}

.steps-list li::before {
    content: counter(step);
    display: grid;
    place-items: center;
    width: 28px;
    height: 28px;
    margin-bottom: 8px;

    border-radius: 50%;
    background: var(--dark);
    color: white;
    font-weight: bold;
}


/* --- Теория: оглавление + статья --- */

.theory-layout {
    display: grid;
    grid-template-columns: 260px minmax(0, 1fr);
    gap: 36px;
    align-items: start;
}

.theory-toc {
    position: sticky;
    top: 80px;
    max-height: calc(100vh - 100px);
    overflow-y: auto;

    padding: 18px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    font-size: 14px;
}

.theory-toc h2 {
    margin: 0 0 4px;
    font-size: 15px;
}

.theory-toc h3 {
    margin: 14px 0 6px;
    color: var(--text-muted);
    font-size: 12px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.theory-toc ul {
    margin: 0;
    padding: 0;
    list-style: none;
}

.theory-toc li a {
    display: block;
    padding: 4px 8px;
    border-radius: 6px;
    color: var(--text);
    text-decoration: none;
}

.theory-toc li a:hover {
    background: var(--surface-muted);
}

.theory-toc li a[aria-current="page"] {
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: bold;
}

@media (max-width: 960px) {
    .theory-layout {
        grid-template-columns: minmax(0, 1fr);
    }

    .theory-toc {
        position: static;
        max-height: none;
        order: 2;
    }
}

.article {
    max-width: 820px;
    padding: 32px 40px 40px;

    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);

    font-size: 17px;
    line-height: 1.7;
}

@media (max-width: 600px) {
    .article {
        padding: 22px 18px 28px;
    }

    .page-head h1,
    .article h1 {
        font-size: 27px;
    }

    .hero h1 {
        font-size: 31px;
    }
}

.article h1 {
    margin: 0 0 10px;
    font-size: 32px;
    line-height: 1.2;
}

.article > :first-child {
    margin-top: 0;
}

.article h2 {
    margin: 36px 0 12px;
    padding-top: 8px;
    font-size: 23px;
    line-height: 1.3;
}

.article h3 {
    margin: 26px 0 8px;
    font-size: 19px;
}

.article p,
.article ul,
.article ol {
    margin: 0 0 14px;
}

.article li + li {
    margin-top: 4px;
}

.article .lead {
    color: var(--text-muted);
    font-size: 19px;
}

.article-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin: 0 0 24px;
}

.chip {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 999px;
    background: var(--surface-muted);
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 13px;
    text-decoration: none;
}

a.chip {
    background: var(--accent-soft);
    border-color: #c6d9f0;
    color: var(--accent);
    font-weight: bold;
}

.article-contents {
    margin: 0 0 26px;
    padding: 14px 20px;
    border-radius: 8px;
    background: var(--surface-muted);
    font-size: 15px;
}

.article-contents b {
    display: block;
    margin-bottom: 4px;
}

.article-contents ol {
    margin: 0;
    padding-left: 22px;
}


/* --- Смысловые блоки статьи --- */

.box {
    margin: 20px 0;
    padding: 14px 18px;

    border-left: 4px solid var(--border);
    border-radius: 0 8px 8px 0;
    background: var(--surface-muted);
}

.box > :last-child {
    margin-bottom: 0;
}

.box-title {
    display: block;
    margin-bottom: 4px;
    font-size: 13px;
    font-weight: bold;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.box.definition {
    border-color: var(--accent);
    background: var(--accent-soft);
}

.box.definition .box-title {
    color: var(--accent);
}

.box.theorem {
    border-color: #6b3fa0;
    background: #f3eefa;
}

.box.theorem .box-title {
    color: #6b3fa0;
}

.box.example {
    border-color: var(--ok);
    background: var(--ok-soft);
}

.box.example .box-title {
    color: var(--ok);
}

.box.warning {
    border-color: #c77800;
    background: var(--warn-soft);
}

.box.warning .box-title {
    color: var(--warn);
}

.box.lab {
    border-color: var(--dark);
    background: #f1f3f4;
}

.questions li {
    margin-bottom: 6px;
}

details.answer {
    margin: 6px 0 14px;
    padding: 8px 14px;
    border-radius: 8px;
    background: var(--surface-muted);
}

details.answer summary {
    cursor: pointer;
    color: var(--accent);
    font-size: 15px;
}


/* --- Формулы --- */

.f,
.f-block {
    font-family: var(--math-font);
    white-space: nowrap;
}

.f {
    font-size: 1.06em;
}

.f-block {
    display: block;
    margin: 14px 0;
    padding: 12px 16px;
    overflow-x: auto;

    border-radius: 8px;
    background: var(--surface-muted);
    font-size: 1.15em;
    text-align: center;
}

.box .f-block {
    background: rgba(255, 255, 255, 0.7);
}

.math-var {
    font-family: var(--math-font);
    font-style: italic;
    padding: 0 0.04em;
}

.math-sup,
.math-sub {
    font-size: 0.72em;
    line-height: 0;
}

.math-sup {
    vertical-align: 0.55em;
}

.math-sub {
    vertical-align: -0.25em;
}


/* --- Таблицы в статьях --- */

.table-scroll {
    margin: 16px 0;
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 15px;
    line-height: 1.45;
}

.data-table th,
.data-table td {
    padding: 8px 12px;
    border: 1px solid var(--border);
    text-align: left;
    vertical-align: top;
}

.data-table th {
    background: #333;
    color: white;
    font-weight: bold;
}

.data-table.center td,
.data-table.center th {
    text-align: center;
}

.data-table td.mono,
.mono {
    font-family: "Courier New", monospace;
}

.bits {
    font-family: "Courier New", monospace;
    letter-spacing: 1px;
}

.bits .hl {
    padding: 0 2px;
    border-radius: 3px;
    background: #fbe3e3;
    color: #b00020;
    font-weight: bold;
}

.bits .parity {
    color: var(--accent);
    font-weight: bold;
}


/* --- Переходы между статьями --- */

.prev-next {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    margin-top: 36px;
}

.prev-next a {
    display: block;
    padding: 14px 18px;
    border: 1px solid var(--border);
    border-radius: 8px;
    text-decoration: none;
}

.prev-next a:hover {
    border-color: var(--accent);
}

.prev-next small {
    display: block;
    color: var(--text-muted);
}

.prev-next .next {
    grid-column: 2;
    text-align: right;
}


/* --- Справочник --- */

.reference-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 26px;
}

.glossary {
    margin: 0;
}

.glossary dt {
    margin-top: 16px;
    font-weight: bold;
}

.glossary dd {
    margin: 4px 0 0;
}

.glossary dd a {
    font-size: 14px;
    white-space: nowrap;
}

.letter-index {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 0 0 8px;
}

.letter-index a {
    display: inline-grid;
    place-items: center;
    min-width: 30px;
    height: 30px;
    border-radius: 6px;
    background: var(--surface-muted);
    text-decoration: none;
    font-weight: bold;
}

.literature li {
    margin-bottom: 8px;
}

.glossary-filter {
    width: 100%;
    max-width: 420px;
    margin: 4px 0 8px;
    padding: 10px 12px;
    border: 1px solid #aaa;
    border-radius: 6px;
    font-size: 16px;
}


/* --- Лаборатория: ссылки на теорию у выбранного алгоритма --- */

.theory-links {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 8px 14px;
    margin: -24px 0 30px;
    font-size: 15px;
}

.theory-links[hidden] {
    display: none;
}

.theory-links-label {
    color: var(--text-muted);
}


/* --- 404 --- */

.not-found {
    max-width: 640px;
    margin: 60px auto;
    text-align: center;
}

.not-found .code {
    font-family: var(--math-font);
    font-size: 72px;
    line-height: 1;
}


/* --- Печать: статьи удобно распечатывать как методичку --- */

@media print {
    .site-header,
    .site-footer,
    .theory-toc,
    .prev-next,
    .skip-link,
    .article-meta a.chip {
        display: none !important;
    }

    body {
        background: white;
    }

    .theory-layout {
        display: block;
    }

    .article {
        max-width: none;
        padding: 0;
        border: none;
    }

    details.answer {
        display: block;
    }
}
