:root {
    /* Только тёмная тема */
    --bg: #0f1218;
    --surface: #171b23;
    --surface-2: #1e232d;
    --text: #e4e7ee;
    --muted: #8b93a5;
    --border: #2a303c;
    --accent: #8b85ff;
    --accent-soft: #24233f;
    --good: #4ade80;
    --good-soft: #13271b;
    --bad: #fb923c;
    --bad-soft: #2d1a10;
    --warn: #fbbf24;
    --mastered: #34c172;
    --seen: #3b6ea8;
    --code-bg: #12161d;
    --shadow: none;
    color-scheme: dark;
    --radius: 12px;
    --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --mono: ui-monospace, "Cascadia Code", "JetBrains Mono", Consolas, monospace;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 16px/1.6 var(--font);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, kbd, pre { font-family: var(--mono); }
h1 { font-size: 1.7rem; line-height: 1.25; margin: .2rem 0 0; }
.h { font-size: 1.1rem; margin: 2rem 0 .8rem; }
.card .h:first-child { margin-top: 0; }
.muted { color: var(--muted); }
.inline { display: inline; margin: 0; }

.wrap { max-width: 980px; margin: 0 auto; padding: 0 20px 60px; }
.wrap--wide { max-width: 1320px; }

/* top bar */
.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; height: 56px; padding-bottom: 0; }
.brand { font-weight: 700; font-size: 1.1rem; color: var(--text); }
.brand span { color: var(--accent); }
.brand:hover { text-decoration: none; }
.topbar__nav { display: flex; gap: 18px; align-items: center; }
.topbar__nav a, .linkbtn { color: var(--muted); font: inherit; font-size: .95rem; }
.linkbtn { background: none; border: 0; padding: 0; cursor: pointer; }
.linkbtn:hover, .topbar__nav a:hover { color: var(--text); text-decoration: none; }

/* buttons */
.btn {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 8px 16px; border-radius: 9px; border: 1px solid var(--border);
    background: var(--surface); color: var(--text); font: inherit; font-size: .95rem;
    cursor: pointer; text-decoration: none; transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: .45; cursor: default; }
.btn--primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn--primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn--ghost { background: transparent; }
.btn--sm { padding: 3px 10px; font-size: .85rem; }
.btn kbd { font-size: .72rem; opacity: .7; border: 1px solid currentColor; border-radius: 4px; padding: 0 4px; }
.mini { background: none; border: 0; color: var(--muted); font: inherit; font-size: .75rem; cursor: pointer; padding: 0 4px; white-space: nowrap; }
.mini:hover { color: var(--accent); }
.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 18px; }

/* cards, notices */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px 22px; box-shadow: var(--shadow); }
.notice { background: var(--accent-soft); border-radius: 10px; padding: 10px 14px; margin: 18px 0; }
.grid2 { display: grid; grid-template-columns: 1.3fr 1fr; gap: 18px; margin-top: 18px; align-items: start; }
@media (max-width: 800px) { .grid2 { grid-template-columns: 1fr; } }

/* hero stats */
.hero { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 18px; margin-top: 24px; padding: 20px 22px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.hero__stats { display: flex; gap: 28px; flex-wrap: wrap; }
.hero__stats.compact { gap: 20px; margin-bottom: 14px; }
.hero__actions { display: flex; gap: 10px; flex-wrap: wrap; }
.stat b { display: block; font-size: 1.5rem; line-height: 1.2; }
.stat span { color: var(--muted); font-size: .82rem; }
.stat--good b { color: var(--good); }
.stat--bad b { color: var(--bad); }

/* topics grid */
.topics { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.topic { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; box-shadow: var(--shadow); }
.topic--empty { opacity: .7; }
.topic__link { display: flex; gap: 10px; color: var(--text); font-weight: 600; }
.topic__link:hover { text-decoration: none; color: var(--accent); }
.topic__num { color: var(--muted); font-variant-numeric: tabular-nums; font-weight: 400; }
.topic__meta { display: flex; gap: 12px; align-items: center; font-size: .85rem; flex-wrap: wrap; }
.topic__meta a.muted { margin-left: auto; }

.bar { display: flex; height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; min-width: 80px; }
.bar__mastered { background: var(--mastered); }
.bar__seen { background: var(--seen); }
.legend { font-size: .8rem; color: var(--muted); margin: 12px 0 0; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin: 0 4px 0 10px; }
.dot:first-child { margin-left: 0; }
.dot--mastered { background: var(--mastered); }
.dot--seen { background: var(--seen); }

.badge { background: var(--accent-soft); color: var(--accent); border-radius: 99px; padding: 1px 9px; font-size: .78rem; }
.acc { font-weight: 600; font-variant-numeric: tabular-nums; }
.acc--good { color: var(--good); }
.acc--mid { color: var(--warn); }
.acc--bad { color: var(--bad); }
.chip { display: inline-block; font-size: .75rem; border-radius: 6px; padding: 1px 8px; background: var(--surface-2); color: var(--muted); }
.chip--junior { background: var(--good-soft); color: var(--good); }
.chip--middle { background: var(--accent-soft); color: var(--accent); }
.chip--senior { background: var(--bad-soft); color: var(--bad); }

/* tables */
.table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; font-size: .93rem; }
.table th { text-align: left; font-weight: 500; color: var(--muted); font-size: .8rem; }
.table th, .table td { padding: 9px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.sections td:nth-child(3) { width: 160px; }
.sections tr.sub td:first-child { padding-left: 34px; font-size: .9rem; }
.res { width: 30px; text-align: center; font-weight: 700; }
.res--correct { color: var(--good); }
.res--wrong { color: var(--bad); }
.res--unknown { color: var(--warn); }

.pagehead { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-top: 22px; }

/* form controls */
.field { margin-bottom: 16px; }
.label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 6px; }
.seg { display: inline-flex; flex-wrap: wrap; border: 1px solid var(--border); border-radius: 9px; overflow: hidden; }
.seg label { cursor: pointer; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; padding: 5px 14px; font-size: .9rem; border-right: 1px solid var(--border); }
.seg label:last-child span { border-right: 0; }
.seg input:checked + span { background: var(--accent); color: #fff; }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: -2px; }
.sections-pick { max-height: 290px; overflow: auto; border: 1px solid var(--border); border-radius: 9px; padding: 6px 10px; }
.sections-pick label { display: flex; gap: 8px; align-items: baseline; padding: 3px 0; font-size: .9rem; cursor: pointer; }
.sections-pick label.sub { padding-left: 22px; }
.sections-pick small { margin-left: auto; }

/* quiz */
.quiz { margin-top: 18px; }
.quiz__head { display: flex; align-items: center; gap: 16px; margin-bottom: 14px; font-size: .9rem; }
.quiz__progress { display: flex; flex: 1; gap: 3px; flex-wrap: wrap; }
.pip { flex: 1; min-width: 6px; max-width: 28px; height: 6px; border-radius: 3px; background: var(--border); }
.pip--correct { background: var(--good); }
.pip--wrong { background: var(--bad); }
.pip--unknown { background: var(--warn); }
.pip--current { outline: 2px solid var(--accent); outline-offset: 1px; }
.question { padding: 24px 26px; }
.question__meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: .82rem; margin-bottom: 10px; }
.question__body { font-size: 1.08rem; }
.question__body > :first-child { margin-top: 0; }

.options { list-style: none; padding: 0; margin: 18px 0 0; display: flex; flex-direction: column; gap: 8px; }
.option { display: flex; gap: 12px; align-items: flex-start; padding: 11px 14px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); cursor: pointer; transition: border-color .12s, background .12s; }
label.option:hover { border-color: var(--accent); }
.option input { position: absolute; opacity: 0; pointer-events: none; }
.option__key { flex: 0 0 26px; height: 26px; border-radius: 7px; background: var(--surface-2); color: var(--muted); display: inline-flex; align-items: center; justify-content: center; font-size: .85rem; font-weight: 600; }
.option__text { flex: 1; padding-top: 1px; }
.option__text p { margin: 0 0 .4em; }
.option--checked { border-color: var(--accent); background: var(--accent-soft); }
.option--checked .option__key { background: var(--accent); color: #fff; }
.options--review .option { cursor: default; }
.option--correct { border-color: var(--good); background: var(--good-soft); }
.option--correct .option__key { background: var(--good); color: #fff; }
.option--wrong { border-color: var(--bad); background: var(--bad-soft); }
.option--wrong .option__key { background: var(--bad); color: #fff; }
.option__why { color: var(--muted); font-size: .9rem; margin-top: 4px; }
.option--correct .option__why, .option--wrong .option__why { color: var(--text); opacity: .85; }

.verdict { margin-top: 16px; font-weight: 700; font-size: 1.05rem; }
.verdict--correct { color: var(--good); }
.verdict--wrong { color: var(--bad); }
.verdict--unknown { color: var(--warn); }
.explanation { margin-top: 20px; padding: 14px 18px; border-left: 3px solid var(--accent); background: var(--surface-2); border-radius: 0 10px 10px 0; }
.explanation h3 { margin: 0 0 6px; font-size: .95rem; }
.explanation > :last-child { margin-bottom: 0; }
.next-review { font-size: .85rem; margin-left: auto; }
.qid { font-size: .72rem; margin-top: 14px; text-align: right; font-family: var(--mono); }

/* prose (markdown) */
.prose { overflow-wrap: break-word; }
.prose code { background: var(--code-bg); border: 1px solid var(--border); border-radius: 5px; padding: .05em .35em; font-size: .88em; }
.prose pre { background: var(--code-bg); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; overflow-x: auto; font-size: .86rem; line-height: 1.55; }
.prose pre code { background: none; border: 0; padding: 0; font-size: inherit; }
.prose table { border-collapse: collapse; margin: 1em 0; font-size: .92rem; display: block; overflow-x: auto; }
.prose th, .prose td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; vertical-align: top; }
.prose th { background: var(--surface-2); }
.prose blockquote { margin: 1em 0; padding: 4px 16px; border-left: 3px solid var(--border); color: var(--muted); }
.prose h1, .prose h2, .prose h3, .prose h4 { scroll-margin-top: 72px; line-height: 1.3; }
.prose h2 { margin-top: 2.2em; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.prose .anchor { opacity: 0; margin-left: 8px; font-weight: 400; color: var(--muted); }
.prose h2:hover .anchor, .prose h3:hover .anchor, .prose h4:hover .anchor { opacity: 1; }
.prose :target { background: var(--accent-soft); border-radius: 6px; }

/* theory reader */
.theory { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 32px; margin-top: 18px; }
.toc { position: sticky; top: 72px; align-self: start; max-height: calc(100vh - 90px); overflow: auto; font-size: .87rem; padding-right: 6px; }
.toc__switch { width: 100%; padding: 6px 8px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; margin-bottom: 8px; }
.toc__topic { margin-bottom: 12px; }
.toc__item { display: flex; justify-content: space-between; gap: 6px; padding: 3px 0; }
.toc__item a { color: var(--text); }
.toc__item.sub { padding-left: 14px; font-size: .82rem; }
.toc__item.sub a { color: var(--muted); }
.prose.prose { min-width: 0; }
article.prose { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 36px 40px; box-shadow: var(--shadow); }
@media (max-width: 900px) {
    .theory { grid-template-columns: 1fr; }
    .toc { position: static; max-height: 300px; }
    article.prose { padding: 6px 18px 30px; }
}

/* highlight.js theme (dark) */
.hljs-keyword, .hljs-selector-tag, .hljs-built_in, .hljs-type { color: #c4a7ff; }
.hljs-string, .hljs-attr-value, .hljs-template-tag, .hljs-regexp { color: #86efac; }
.hljs-number, .hljs-literal, .hljs-symbol { color: #fcd34d; }
.hljs-comment, .hljs-quote { color: #6b7385; }
.hljs-title, .hljs-title.function_, .hljs-section { color: #93c5fd; }
.hljs-title.class_, .hljs-class .hljs-title { color: #f9a8d4; }
.hljs-variable, .hljs-template-variable, .hljs-params { color: #fdba74; }
.hljs-attr, .hljs-attribute, .hljs-property { color: #67e8f9; }
.hljs-meta, .hljs-tag, .hljs-name { color: #94a3b8; }

/* PWA install button */
.install-btn { display: none; color: var(--accent) !important; font-size: 1.1rem !important; }
.can-install .install-btn { display: inline; }

/* mobile */
@media (max-width: 640px) {
    .wrap { padding: 0 12px 40px; }
    .topbar__inner { padding-bottom: 0; }
    .topbar__nav { gap: 12px; }
    .topbar__nav a, .linkbtn { font-size: .88rem; }
    .table { display: block; max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .table th, .table td { padding: 8px 8px; }
    .table .bar { min-width: 48px; }
    .table--recent td:nth-child(2) { display: none; }
    .sections th:nth-child(4), .sections td:nth-child(4) { display: none; }
    h1 { font-size: 1.4rem; }
}
