:root {
  --bg: #fbfaf7;
  --surface: #ffffff;
  --text: #1d232a;
  --muted: #5b6672;
  --line: #e3e0d8;
  --accent: #1f5f8b;
  --accent-soft: #e6f0f7;
  --warn: #9a5b00;
  --warn-soft: #fbf1e1;
  --ok: #2d6a3e;
  --ok-soft: #e7f3ea;
  --code-bg: #f2f0ea;
  --radius: 10px;
  --sidebar: 260px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14181d;
    --surface: #1b2027;
    --text: #e5e8ec;
    --muted: #9aa5b1;
    --line: #2c333c;
    --accent: #7db8e0;
    --accent-soft: #1d2d3a;
    --warn: #e7b25c;
    --warn-soft: #2e2618;
    --ok: #8fd0a0;
    --ok-soft: #1a2b20;
    --code-bg: #232931;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 72px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.65 var(--font);
}
a { color: var(--accent); text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 16px; top: 8px; background: var(--surface); padding: 6px 10px; z-index: 10; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  height: 56px; padding: 0 16px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--text); text-decoration: none; }
.logo {
  display: grid; place-items: center; width: 30px; height: 30px; border-radius: 8px;
  background: var(--accent); color: var(--bg); font-size: 18px;
}
.menu-btn { display: none; cursor: pointer; padding: 6px 12px; border: 1px solid var(--line); border-radius: 8px; font-size: 15px; }

.shell { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); max-width: 1180px; margin: 0 auto; }
.sidebar {
  position: sticky; top: 56px; align-self: start;
  max-height: calc(100vh - 56px); overflow-y: auto;
  padding: 24px 16px 40px; border-right: 1px solid var(--line);
  font-size: 15px;
}
.sidebar ul { list-style: none; margin: 0 0 18px; padding: 0; }
.sidebar li a { display: block; padding: 4px 10px; border-radius: 6px; color: var(--text); text-decoration: none; }
.sidebar li a:hover { background: var(--accent-soft); }
.sidebar a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-group { margin: 0 0 6px; padding: 0 10px; font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }

main { padding: 28px 40px 64px; min-width: 0; }
article { max-width: 760px; }
h1 { font-size: clamp(28px, 4vw, 38px); line-height: 1.2; margin: 8px 0 12px; letter-spacing: -.01em; }
h2 { font-size: 25px; line-height: 1.3; margin: 44px 0 12px; padding-top: 8px; border-top: 1px solid var(--line); }
h3 { font-size: 19px; margin: 28px 0 8px; }
.lead { font-size: 19px; color: var(--muted); margin-top: 0; }
p, ul, ol { margin: 0 0 14px; }
li { margin-bottom: 4px; }
strong { font-weight: 650; }

.crumbs { font-size: 14px; color: var(--muted); }
.crumbs a { color: var(--muted); }

.toc { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 18px; margin: 20px 0 8px; font-size: 15px; }
.toc p { margin: 0 0 6px; font-weight: 700; }
.toc ol { margin: 0; padding-left: 20px; }
.toc ul { margin: 0; padding: 0; list-style: none; }

.formula {
  font-family: var(--mono); font-size: 16px;
  background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--accent);
  border-radius: 6px; padding: 12px 16px; margin: 12px 0 16px; overflow-x: auto; white-space: pre;
}
code { font-family: var(--mono); font-size: .9em; background: var(--code-bg); padding: 1px 5px; border-radius: 4px; }
pre { background: var(--code-bg); border-radius: var(--radius); padding: 14px 16px; overflow-x: auto; font-size: 14.5px; line-height: 1.5; }
pre code { background: none; padding: 0; }

.box { border-radius: var(--radius); padding: 14px 18px; margin: 18px 0; border: 1px solid var(--line); background: var(--surface); }
.box > :last-child { margin-bottom: 0; }
.box-title { font-weight: 700; margin-bottom: 6px; }
.box.tip { background: var(--accent-soft); border-color: transparent; }
.box.trap { background: var(--warn-soft); border-color: transparent; }
.box.trap .box-title { color: var(--warn); }
.box.example { background: var(--ok-soft); border-color: transparent; }
.box.example .box-title { color: var(--ok); }

.table-wrap { overflow-x: auto; margin: 12px 0 18px; }
table { border-collapse: collapse; font-size: 15.5px; min-width: 100%; }
th, td { border: 1px solid var(--line); padding: 7px 12px; text-align: left; vertical-align: top; }
th { background: var(--surface); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

details { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 16px; margin: 10px 0; background: var(--surface); }
summary { cursor: pointer; font-weight: 600; }
details[open] summary { margin-bottom: 8px; }

.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; max-width: 760px; margin-top: 48px; }
.pager a { display: block; padding: 12px 16px; border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none; background: var(--surface); }
.pager a:hover { border-color: var(--accent); }
.pager span { display: block; font-size: 13px; color: var(--muted); }
.pager .next { text-align: right; }

.hero { max-width: 760px; }
.group h2 { border-top: none; margin-top: 32px; }
.cards { list-style: none; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.cards a {
  display: flex; flex-direction: column; gap: 4px; height: 100%;
  padding: 14px 16px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); color: var(--text); text-decoration: none;
}
.cards a:hover { border-color: var(--accent); }
.cards span { font-size: 14.5px; color: var(--muted); line-height: 1.45; }

.footer { border-top: 1px solid var(--line); padding: 20px 16px 32px; font-size: 14px; color: var(--muted); text-align: center; }
.footer p { max-width: 760px; margin: 0 auto; }

@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .menu-btn { display: inline-block; }
  .sidebar {
    display: none; position: fixed; inset: 56px 0 0 0; max-height: none; z-index: 4;
    background: var(--bg); border-right: none;
  }
  .menu-toggle:checked + .shell .sidebar { display: block; }
  main { padding: 20px 16px 48px; }
  body { font-size: 16.5px; }
  .pager { grid-template-columns: 1fr; }
  .pager .next { text-align: left; }
}

.figs { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin: 16px 0; }
figure { margin: 16px 0; }
.figs figure { margin: 0; padding: 8px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); text-align: center; }
figure svg { display: block; width: 100%; height: auto; }
figcaption { font-size: 14px; color: var(--muted); line-height: 1.4; margin-top: 6px; }
.fig-wide { padding: 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
kbd {
  font-family: var(--mono); font-size: .82em;
  padding: 1px 6px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px;
  background: var(--surface); white-space: nowrap;
}

/* Формулы: английские и русские */
.fswitch { display: flex; align-items: center; gap: 4px; margin: 0 12px 0 auto; font-size: 14px; }
.fswitch span { color: var(--muted); margin-right: 2px; }
.fswitch button {
  font: inherit; font-size: 14px; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px; cursor: pointer;
}
.fswitch button:hover { border-color: var(--accent); }
.fswitch button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--bg); }
.f-sep { color: var(--muted); }
code.f-ru { box-shadow: inset 0 0 0 1px var(--line); }
.formula.f-en, .formula.f-ru { position: relative; }
.formula.f-en + .formula.f-ru { margin-top: -8px; border-left-style: dashed; }
.fm-both .formula.f-en::after, .fm-both .formula.f-ru::after {
  position: absolute; top: 4px; right: 8px; font: 600 11px/1 var(--font); letter-spacing: .05em; color: var(--muted);
}
.fm-both .formula.f-en::after { content: "EN"; }
.fm-both .formula.f-ru::after { content: "RU"; }
.fm-en .f-ru, .fm-en .f-sep, .fm-ru .f-en, .fm-ru .f-sep { display: none; }
.fm-ru .formula.f-en + .formula.f-ru { margin-top: 12px; border-left-style: solid; }
@media (max-width: 420px) { .fswitch span { display: none; } .fswitch button { padding: 3px 8px; } .brand { font-size: 15px; } }
