[hidden] { display: none !important; }

/* Layout: одна колонка для чтения с телефона, липкая шапка с прогрессом и выезжающим оглавлением.
   Тёмная тема по умолчанию (как шпаргалка ЛР1): графит + тёмно-жёлтый маркер. */
:root {
  --bg: #15161a;
  --surface: #1d1f25;
  --surface-2: #252830;
  --line: #33363f;
  --fg: #e9e6dc;
  --muted: #a3a093;
  --accent: #e0b03c;
  --accent-soft: rgba(224, 176, 60, .12);
  --accent-ink: #15161a;
  --trap: #e2735a;
  --trap-soft: rgba(226, 115, 90, .12);
  --ok: #7cc48a;
  --code-bg: #101114;
  --font-display: "Unbounded", "Golos Text", system-ui, sans-serif;
  --font-body: "Golos Text", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, Consolas, monospace;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f6f4ee; --surface: #ffffff; --surface-2: #efece3; --line: #dcd7ca;
    --fg: #1d1e22; --muted: #5f5c52; --accent: #9a6c00; --accent-soft: rgba(176, 124, 0, .1);
    --accent-ink: #ffffff; --trap: #b4432b; --trap-soft: rgba(180, 67, 43, .08); --ok: #2f7d43;
    --code-bg: #1b1c20; color-scheme: light;
  }
}
:root[data-theme="light"] {
  --bg: #f6f4ee; --surface: #ffffff; --surface-2: #efece3; --line: #dcd7ca;
  --fg: #1d1e22; --muted: #5f5c52; --accent: #9a6c00; --accent-soft: rgba(176, 124, 0, .1);
  --accent-ink: #ffffff; --trap: #b4432b; --trap-soft: rgba(180, 67, 43, .08); --ok: #2f7d43;
  --code-bg: #1b1c20; color-scheme: light;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 72px; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
body {
  margin: 0;
  background: var(--bg); color: var(--fg);
  font-family: var(--font-body); font-size: 17px; line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

/* шапка */
.bar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 10;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.bar-inner {
  max-width: 760px; margin: 0 auto; padding: 10px 16px;
  display: flex; align-items: center; gap: 12px;
}
.bar-title { font-family: var(--font-display); font-size: 14px; font-weight: 700; letter-spacing: .02em; }
.bar-title span { color: var(--accent); }
.bar-now { flex: 1; min-width: 0; color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.btn {
  font: 600 14px var(--font-body); color: var(--fg); background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 12px; cursor: pointer;
}
.btn:focus-visible, summary:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.progress { height: 3px; background: var(--accent); width: 0; transition: width .1s linear; }

/* оглавление */
.toc-sheet { position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,.5); display: flex; justify-content: flex-end; }
.toc-panel {
  width: min(360px, 88vw); height: 100%; overflow-y: auto; background: var(--surface);
  border-left: 1px solid var(--line);
  padding: calc(16px + env(safe-area-inset-top, 0px)) 16px calc(24px + env(safe-area-inset-bottom, 0px));
  display: flex; flex-direction: column; gap: 6px;
}
.toc-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.toc-head b { font-family: var(--font-display); font-size: 15px; }
.toc-link {
  display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center;
  padding: 12px; border-radius: 10px; color: var(--fg); text-decoration: none; background: var(--surface-2);
}
.toc-link small { display: block; color: var(--muted); font-size: 12px; }
.toc-link .mark { color: var(--ok); font-weight: 700; font-size: 13px; }

/* основная колонка */
main { max-width: 760px; margin: 0 auto; padding-inline: 16px; padding-block: 8px 64px; }

.hero { padding-block: 36px 12px; display: flex; flex-direction: column; gap: 14px; }
.hero .eyebrow { margin: 0; }
.hero h1 {
  font-family: var(--font-display); font-weight: 700; margin: 0;
  font-size: clamp(30px, 8vw, 46px); line-height: 1.1; text-wrap: balance;
}
.hero h1 em { font-style: normal; color: var(--accent); }
.hero p { margin: 0; color: var(--muted); max-width: 60ch; }
.score {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; margin-top: 8px;
}
.score a {
  display: flex; flex-direction: column; gap: 2px; padding: 12px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--line); color: var(--fg); text-decoration: none;
}
.score a b { font-family: var(--font-display); font-size: 20px; color: var(--accent); font-variant-numeric: tabular-nums; }
.score a span { font-size: 13px; color: var(--muted); line-height: 1.35; }
.howto { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; font-size: 15px; }
.howto ul { margin: 6px 0 0; padding-left: 20px; }

/* разделы */
.part { padding-top: 40px; margin-top: 32px; border-top: 1px solid var(--line); }
.eyebrow {
  font: 600 12px var(--font-mono); letter-spacing: .12em; text-transform: uppercase;
  color: var(--accent); margin: 0 0 6px;
}
.part h2 { font-family: var(--font-display); font-weight: 700; font-size: clamp(23px, 5.6vw, 30px); line-height: 1.2; margin: 0 0 12px; text-wrap: balance; }
.part h3 { font-family: var(--font-display); font-weight: 500; font-size: 18px; line-height: 1.3; margin: 34px 0 10px; text-wrap: balance; }
.part h4 { font-size: 16px; margin: 20px 0 6px; }
.lead { font-size: 18px; color: var(--fg); opacity: .9; }
.part p, .part li { max-width: 68ch; }
.part ul, .part ol { padding-left: 22px; }
.part li + li { margin-top: 4px; }
.part a { color: var(--accent); }
strong, b { font-weight: 600; }

code { font-family: var(--font-mono); font-size: .86em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; overflow-wrap: anywhere; }
pre {
  background: var(--code-bg); color: #e6e3d8; border-radius: 10px; padding: 14px;
  overflow-x: auto; font-size: 13.5px; line-height: 1.55; margin: 14px 0 8px; border: 1px solid var(--line);
}
pre code { background: none; padding: 0; font-size: inherit; color: inherit; overflow-wrap: normal; }
pre .k { color: #e0b03c; } pre .s { color: #9fd08b; } pre .c { color: #8a877c; font-style: italic; } pre .n { color: #8fc1e3; }

ol.lines { list-style: none; padding: 0; margin: 4px 0 18px; display: flex; flex-direction: column; gap: 6px; counter-reset: ln; }
ol.lines li {
  max-width: none; background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px 8px 38px; position: relative; font-size: 15px; line-height: 1.5;
}
ol.lines li::before {
  counter-increment: ln; content: counter(ln); position: absolute; left: 10px; top: 9px;
  font: 600 12px var(--font-mono); color: var(--accent);
}
ol.lines li + li { margin-top: 0; }

.analogy, .trap, .phrase, .formula { border-radius: 10px; padding: 12px 14px; margin: 16px 0; max-width: 68ch; }
.analogy { background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent); }
.analogy b:first-child { color: var(--accent); }
.trap { background: var(--trap-soft); border: 1px solid color-mix(in srgb, var(--trap) 40%, transparent); }
.trap b:first-child { color: var(--trap); }
.formula {
  font-family: var(--font-mono); font-size: 15px; background: var(--surface); border: 1px dashed var(--accent);
  overflow-x: auto; white-space: pre-wrap;
}
.phrase { background: var(--accent); color: var(--accent-ink); font-weight: 500; margin-top: 22px; }
.phrase b:first-child { display: block; font: 600 11px var(--font-mono); letter-spacing: .12em; text-transform: uppercase; opacity: .75; margin-bottom: 4px; }
.phrase code { background: rgba(0,0,0,.12); color: inherit; }

dl.terms { display: grid; grid-template-columns: 1fr; gap: 0; margin: 14px 0; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
dl.terms dt { font-weight: 600; padding: 10px 12px 0; background: var(--surface); color: var(--accent); }
dl.terms dd { margin: 0; padding: 2px 12px 10px; background: var(--surface); border-bottom: 1px solid var(--line); font-size: 15px; }
dl.terms dd:last-child { border-bottom: 0; }
@media (min-width: 640px) {
  dl.terms { grid-template-columns: minmax(150px, 30%) 1fr; }
  dl.terms dt { padding: 10px 12px; border-bottom: 1px solid var(--line); }
  dl.terms dd { padding: 10px 12px; }
  dl.terms dt:nth-last-of-type(1) { border-bottom: 0; }
}

.table-wrap { overflow-x: auto; margin: 14px 0; border: 1px solid var(--line); border-radius: 10px; }
table { border-collapse: collapse; width: 100%; font-size: 14.5px; font-variant-numeric: tabular-nums; }
th, td { padding: 9px 11px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
thead th { background: var(--accent-soft); color: var(--accent); font-weight: 600; white-space: nowrap; }
tbody tr:last-child td, tbody tr:last-child th { border-bottom: 0; }
tbody tr:nth-child(even) { background: var(--surface); }

figure { margin: 18px 0; }
figure img { display: block; width: 100%; height: auto; border-radius: 10px; background: #fff; border: 1px solid var(--line); }
figcaption { font-size: 14px; color: var(--muted); margin-top: 8px; max-width: 68ch; }
.zoom-hint { font-size: 12px; color: var(--muted); }

details.qa { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; margin: 8px 0; max-width: 68ch; }
details.qa summary { cursor: pointer; padding: 12px 14px; font-weight: 600; list-style: none; display: flex; gap: 10px; }
details.qa summary::-webkit-details-marker { display: none; }
details.qa summary::before { content: "?"; flex: none; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font: 700 12px var(--font-mono); background: var(--accent-soft); color: var(--accent); margin-top: 2px; }
details.qa[open] summary::before { content: "!"; background: var(--accent); color: var(--accent-ink); }
details.qa > :not(summary) { padding: 0 14px 12px 46px; margin: 0; }

.done-row { margin-top: 24px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.done-btn[aria-pressed="true"] { background: var(--ok); color: #10140f; border-color: var(--ok); }
.done-row small { color: var(--muted); }

footer { max-width: 760px; margin: 0 auto; padding: 24px 16px 48px; color: var(--muted); font-size: 13px; border-top: 1px solid var(--line); }

img { max-width: 100%; }
.demo { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin: 16px 0; display: flex; flex-direction: column; gap: 10px; }
.demo canvas { width: 100%; height: auto; display: block; border-radius: 8px; background: var(--bg); }
.demo-controls { display: flex; gap: 8px; flex-wrap: wrap; }
.demo-status { margin: 0; font: 13px var(--font-mono); color: var(--muted); font-variant-numeric: tabular-nums; }
.part:first-child { border-top: 0; margin-top: 0; padding-top: 24px; }
.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 28px; }
.pager a { display: flex; flex-direction: column; gap: 2px; padding: 12px; border-radius: 10px; background: var(--surface); border: 1px solid var(--line); color: var(--fg); text-decoration: none; min-width: 0; }
.pager a.next { text-align: right; grid-column: 2; }
.pager small { color: var(--muted); font-size: 12px; }
.pager span { color: var(--accent); font-weight: 600; }
.topics { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.topic { display: grid; grid-template-columns: 1fr auto; row-gap: 4px; padding: 14px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); color: var(--fg); text-decoration: none; }
.topic b { grid-row: 1; grid-column: 1; font: 600 12px var(--font-mono); letter-spacing: .1em; text-transform: uppercase; color: var(--accent); }
.topic .mark { grid-row: 1; grid-column: 2; color: var(--ok); font-weight: 700; font-size: 13px; }
.topic .tt { grid-row: 2; grid-column: 1 / -1; min-width: 0; font-family: var(--font-display); font-weight: 500; font-size: 17px; line-height: 1.3; }
.topic small { display: block; margin-top: 4px; font-family: var(--font-body); font-weight: 400; color: var(--muted); font-size: 14px; line-height: 1.45; }
a.home { color: var(--fg); text-decoration: none; }
