/* Дизайн сайта документации (PLAN.md, раздел 5).
   Светлая тема по умолчанию; тёмная — только по переключателю в шапке
   (html[data-theme="dark"]), настройка ОС не влияет. Без фреймворков,
   системные шрифты. Ширины:
     ≥ 75rem — сайдбар | статья | оглавление;
     60–75rem — сайдбар | статья (оглавление — блок «Contents» в статье);
     < 60rem — статья, сайдбар выдвигается кнопкой «☰» (без JS — после статьи). */

/* ------------------------------------------------------------------
   Цвета и размеры
   ------------------------------------------------------------------ */
:root {
  color-scheme: light;
  --bg: #ffffff;
  --bg-soft: #f6f7f9;
  --bg-hover: #eef1f5;
  --surface: #ffffff;
  --text: #1c2128;
  --text-2: #3d4652;
  --muted: #5f6b7a;
  --border: #e1e5ea;
  --border-strong: #c9d0d8;
  --accent: #0b63c5;
  --accent-hover: #084f9e;
  --accent-soft: #e8f1fc;
  --selected-bg: #e1edfb;   /* выбранный пункт списка (результаты поиска) */
  --header-bg: rgba(252, 252, 253, .94);
  --shadow: 0 12px 32px rgba(15, 23, 42, .14), 0 2px 6px rgba(15, 23, 42, .06);
  --mark: #fff0a0;
  --img-border: #e1e5ea;

  --note: #0b63c5;      --note-bg: #eff6fe;      --note-border: #c9def6;
  --tip: #1a7f37;       --tip-bg: #eff8f1;       --tip-border: #c4e4cc;
  --warning: #9a6700;   --warning-bg: #fff8e5;   --warning-border: #efd79c;
  --important: #c42b2b; --important-bg: #fdf1f1; --important-border: #f1c6c6;

  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace;
  --header-h: 3.5rem;
  /* шапка вместе с нижней рамкой (1px): отсюда начинаются колонки, сюда же
     они прилипают — иначе при первом пикселе прокрутки прыгают на 1px вверх */
  --sticky-top: calc(var(--header-h) + 1px);
  --sidebar-w: 17rem;
  --content-w: 47rem;
  --toc-w: 13.5rem;
  --radius: 10px;
  /* сайдбар + статья + оглавление + 2 промежутка + поля */
  --page-w: calc(var(--sidebar-w) + var(--content-w) + var(--toc-w) + 6rem + 3rem);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1217;
  --bg-soft: #161b22;
  --bg-hover: #1f2630;
  --surface: #1a2029;
  --text: #e6eaf0;
  --text-2: #c3cbd5;
  --muted: #98a3b3;
  --border: #29303a;
  --border-strong: #3a4350;
  --accent: #6cb0ff;
  --accent-hover: #9ccaff;
  --accent-soft: rgba(108, 176, 255, .14);
  --selected-bg: rgba(108, 176, 255, .22);
  --header-bg: rgba(10, 12, 16, .94);
  --shadow: 0 12px 32px rgba(0, 0, 0, .5), 0 2px 6px rgba(0, 0, 0, .3);
  --mark: rgba(250, 205, 50, .32);
  --img-border: #2c333d;

  --note: #6cb0ff;      --note-bg: rgba(108, 176, 255, .08);  --note-border: rgba(108, 176, 255, .3);
  --tip: #4cc26e;       --tip-bg: rgba(76, 194, 110, .08);    --tip-border: rgba(76, 194, 110, .3);
  --warning: #d9ad3c;   --warning-bg: rgba(217, 173, 60, .08); --warning-border: rgba(217, 173, 60, .32);
  --important: #ff7b72; --important-bg: rgba(255, 123, 114, .08); --important-border: rgba(255, 123, 114, .32);
}

/* ------------------------------------------------------------------
   Основа
   ------------------------------------------------------------------ */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; background: var(--bg); }
body {
  margin: 0;
  font: 16px/1.6 var(--font);
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: var(--accent); text-underline-offset: .18em; text-decoration-thickness: 1px; }
a:hover { color: var(--accent-hover); text-decoration-thickness: 2px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }
[id] { scroll-margin-top: calc(var(--header-h) + 1rem); }
main:focus { outline: none; }
.icon { flex: none; display: block; }

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: fixed; left: 1rem; top: -4rem; z-index: 100;
  padding: .6rem 1rem; border-radius: 8px;
  background: var(--accent); color: #fff; font-weight: 600;
}
.skip-link:focus { top: .75rem; color: #fff; }

/* ------------------------------------------------------------------
   Шапка
   ------------------------------------------------------------------ */
.site-header {
  position: sticky; top: 0; z-index: 40;
  background: var(--header-bg);
  border-bottom: 1px solid var(--border);
  -webkit-backdrop-filter: saturate(1.6) blur(10px);
  backdrop-filter: saturate(1.6) blur(10px);
}
[data-theme="dark"] .site-header { border-bottom-color: #444e5d; }  /* --border (#29303a) почти сливается с фоном */
.header-inner {
  position: relative;
  display: flex; align-items: center; gap: .75rem;
  height: var(--header-h);
  max-width: var(--page-w);
  margin: 0 auto;
  padding: 0 1.5rem;
}
.brand {
  display: flex; align-items: center; gap: .6rem; min-width: 0;
  color: var(--text); text-decoration: none;
  font-weight: 650; font-size: 1.05rem; letter-spacing: -.01em;
}
.brand:hover { color: var(--text); }
.brand img { width: 32px; height: 32px; flex: none; }
.brand span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 2.25rem; height: 2.25rem; flex: none;
  padding: 0; border: 1px solid transparent; border-radius: 8px;
  background: transparent; color: var(--text-2); cursor: pointer;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.menu-btn, .search-btn { display: none; }
html:not(.js) .theme-btn, html:not(.js) .print-btn { display: none; }
.theme-btn .icon-sun, [data-theme="dark"] .theme-btn .icon-moon { display: none; }
[data-theme="dark"] .theme-btn .icon-sun { display: block; }

/* Переключатель версий и языков */
.version-menu { position: relative; flex: none; }
.version-menu summary {
  display: flex; align-items: center; gap: .3rem;
  padding: .2rem .45rem .2rem .7rem;
  border: 1px solid var(--border-strong); border-radius: 999px;
  font-size: .85rem; font-weight: 600; color: var(--text-2);
  cursor: pointer; list-style: none; user-select: none;
}
.version-menu summary::-webkit-details-marker { display: none; }
.version-menu summary:hover { background: var(--bg-hover); color: var(--text); }
.version-menu summary .icon { width: 16px; height: 16px; transition: transform .15s; }
.version-menu[open] summary .icon { transform: rotate(180deg); }
.lang-tag { font-size: .7rem; font-weight: 700; color: var(--muted); }
.menu-panel {
  position: absolute; left: 0; top: calc(100% + .4rem); z-index: 50;
  min-width: 11rem; padding: .35rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.menu-panel ul { list-style: none; margin: 0; padding: 0; }
.menu-panel a {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .4rem .65rem; border-radius: 6px;
  color: var(--text); text-decoration: none; font-size: .9rem;
}
.menu-panel a:hover { background: var(--bg-hover); }
.menu-panel a[aria-current] { color: var(--accent); font-weight: 600; }
.menu-panel a .icon { width: 16px; height: 16px; }
.menu-group {
  margin: .5rem .65rem .2rem; font-size: .7rem; font-weight: 700;
  letter-spacing: .06em; text-transform: uppercase; color: var(--muted);
}
.menu-group:first-child { margin-top: .25rem; }

/* Поиск */
.header-tools { display: flex; align-items: center; gap: .4rem; margin-left: auto; }
.search { position: relative; display: flex; align-items: center; }
.search > .icon {
  position: absolute; left: .65rem; width: 17px; height: 17px;
  color: var(--muted); pointer-events: none;
}
.search input[type="search"] {
  width: 15rem; height: 2.25rem;
  padding: 0 .75rem 0 2.1rem;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg-soft); color: var(--text);
  font: inherit; font-size: .9rem;
}
.search input[type="search"]::placeholder { color: var(--muted); }
.search input[type="search"]:hover { border-color: var(--border-strong); }
.search input[type="search"]:focus { outline: none; border-color: var(--accent); background: var(--bg); box-shadow: 0 0 0 3px var(--accent-soft); }

/* Результаты поиска (assets/js/search.js): выпадающий список под полем в шапке */
.search-panel {
  position: absolute; right: 0; top: calc(100% + .4rem); z-index: 50;
  width: min(34rem, calc(100vw - 1.5rem)); max-height: min(75vh, 40rem); overflow-y: auto;
  padding: .35rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.search-status { margin: .3rem .6rem .35rem; font-size: .8rem; color: var(--muted); }
.search .search-results { list-style: none; margin: 0; padding: 0; } /* не как списки статьи (404) */
.search .search-results li { margin: 0; }
.search-results:empty { display: none; }
.search-results a {
  display: block; padding: .5rem .6rem; border-radius: 6px;
  color: var(--text); text-decoration: none;
}
.search-results [aria-selected="true"] a { background: var(--selected-bg); box-shadow: inset 3px 0 0 var(--accent); }
.search-title { display: block; font-weight: 600; font-size: .92rem; line-height: 1.35; color: var(--accent); }
.search-path { display: block; margin-top: .1rem; font-size: .78rem; color: var(--muted); }
.search-snippet { display: block; margin-top: .2rem; font-size: .84rem; line-height: 1.45; color: var(--text-2); }
.search-panel mark { background: var(--mark); color: inherit; padding: 0 .1em; border-radius: 2px; }
.search-more { margin: .3rem .6rem .35rem; padding-top: .45rem; border-top: 1px solid var(--border); font-size: .82rem; }
.search-results:empty + .search-more { border-top: 0; padding-top: 0; }

/* ------------------------------------------------------------------
   Раскладка
   ------------------------------------------------------------------ */
.layout {
  flex: 1 0 auto;
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, var(--content-w)) var(--toc-w);
  /* Футер — в средней колонке под статьёй, сайдбар и оглавление занимают
     обе строки: их sticky-контейнер доходит до низа страницы, и футер
     не выталкивает их вверх под шапку. Строка статьи тянется (1fr), так что
     на короткой странице футер прижат к низу окна. */
  grid-template-rows: 1fr auto;
  grid-template-areas: "sidebar main toc" "sidebar footer toc";
  column-gap: 3rem;
  justify-content: center;
  width: 100%;
  max-width: var(--page-w);
  margin: 0 auto;
  padding: 0 1.5rem;
}
.layout.no-toc { grid-template-columns: var(--sidebar-w) minmax(0, var(--content-w)) var(--toc-w); }
.layout.no-sidebar { grid-template-columns: minmax(0, var(--content-w)); grid-template-areas: "main" "footer"; }
.layout.no-sidebar:not(.no-toc) { grid-template-columns: minmax(0, var(--content-w)) var(--toc-w); grid-template-areas: "main toc" "footer toc"; }
.article { grid-area: main; min-width: 0; }
.sidebar { grid-area: sidebar; }
.toc { grid-area: toc; }
.site-footer { grid-area: footer; }
/* Явный фон у колонок, а не только у body: Chrome выносит липкие сайдбар
   и оглавление (и статью под липкой шапкой с backdrop-filter) в отдельные
   слои и при смене темы не перерисовывает их прозрачный фон до перезагрузки.
   Собственный background меняется вместе с --bg — слой перерисовывается. */
.sidebar, .toc, .article, .site-footer { background: var(--bg); }

/* ------------------------------------------------------------------
   Сайдбар
   ------------------------------------------------------------------ */
.sidebar {
  position: sticky; top: var(--sticky-top); align-self: start;
  max-height: calc(100vh - var(--sticky-top));
  overflow-y: auto; overscroll-behavior: contain;
  padding: 1.5rem .5rem 2.5rem 0;
  font-size: .9rem;
  scrollbar-width: thin;
}
.sidebar ul { list-style: none; margin: 0; padding: 0; }
.sidebar ul ul { margin: .1rem 0 .3rem .7rem; padding-left: .5rem; border-left: 1px solid var(--border); }
.sidebar li { margin: 1px 0; }
.sidebar a, .sidebar summary > span {
  display: block; flex: 1; min-width: 0;
  padding: .32rem .6rem; border-radius: 6px;
  color: var(--text-2); text-decoration: none; line-height: 1.35;
}
.sidebar a:hover { background: var(--bg-hover); color: var(--text); }
.sidebar a[aria-current] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.sidebar summary {
  display: flex; align-items: flex-start;
  list-style: none; cursor: pointer; border-radius: 6px;
}
.sidebar summary::-webkit-details-marker { display: none; }
.sidebar summary::after {
  content: ""; flex: none;
  width: 1.75rem; height: 1.95rem;
  background: var(--muted);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m9 6 6 6-6 6'/%3E%3C/svg%3E") center / 15px no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m9 6 6 6-6 6'/%3E%3C/svg%3E") center / 15px no-repeat;
  transition: transform .15s;
}
.sidebar details[open] > summary::after { transform: rotate(90deg); }
.sidebar summary:hover::after { background: var(--text); }
.sidebar-close { display: none; }

/* ------------------------------------------------------------------
   Оглавление
   ------------------------------------------------------------------ */
.toc {
  position: sticky; top: var(--sticky-top); align-self: start;
  max-height: calc(100vh - var(--sticky-top));
  overflow-y: auto;
  padding: 2rem 0 2rem;
  font-size: .85rem;
  scrollbar-width: thin;
}
.toc h2 {
  margin: 0 0 .6rem; font-size: .72rem; font-weight: 700;
  letter-spacing: .07em; text-transform: uppercase; color: var(--muted);
}
.toc ul { list-style: none; margin: 0; padding: 0; }
.toc > ul { border-left: 1px solid var(--border); }
.toc ul ul a { padding-left: 1.6rem; }
.toc a {
  display: block; margin-left: -1px;
  padding: .25rem .5rem .25rem .85rem;
  border-left: 2px solid transparent;
  color: var(--muted); text-decoration: none; line-height: 1.4;
}
.toc a:hover { color: var(--text); }
.toc a.active { color: var(--accent); border-left-color: var(--accent); font-weight: 500; }

.toc-inline {
  display: none;
  margin: 0 0 1.75rem;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg-soft);
  font-size: .92rem;
}
.toc-inline summary {
  padding: .6rem 1rem; cursor: pointer; font-weight: 600;
}
.toc-inline ul { margin: 0; padding: 0 1rem .75rem 2.1rem; }
.toc-inline ul ul { padding: .2rem 0 0 1.1rem; }
.toc-inline li { margin: .2rem 0; }
.toc-inline a { text-decoration: none; }
.toc-inline a:hover { text-decoration: underline; }

/* ------------------------------------------------------------------
   Статья
   ------------------------------------------------------------------ */
.article {
  padding: 1.75rem 0 3rem;
  font-size: 1.0625rem; line-height: 1.7;
  overflow-wrap: break-word;
}
.article h1, .article h2, .article h3, .article h4 {
  line-height: 1.25; letter-spacing: -.015em; color: var(--text);
}
.article h1 { font-size: 2.15rem; font-weight: 700; margin: .25rem 0 1.5rem; letter-spacing: -.025em; }
.article h2 {
  font-size: 1.55rem; font-weight: 650; margin: 2.75rem 0 1rem;
  padding-top: 1.5rem; border-top: 1px solid var(--border);
}
.article h1 + h2, .article .toc-inline + h2 { border-top: 0; padding-top: 0; margin-top: 1.5rem; }
.article h3 { font-size: 1.22rem; font-weight: 650; margin: 2rem 0 .75rem; }
.article h4 { font-size: 1.05rem; font-weight: 650; margin: 1.75rem 0 .5rem; }
.article h2, .article h3, .article h4 { clear: both; }
.article p { margin: 0 0 1.1rem; }
.article ul, .article ol { margin: 0 0 1.1rem; padding-left: 1.6rem; }
.article li { margin: .3rem 0; }
.article li > ul, .article li > ol { margin: .3rem 0 0; }
.article li::marker { color: var(--muted); }
.article strong { font-weight: 650; }
.article hr { clear: both; border: 0; border-top: 1px solid var(--border); margin: 2.5rem 0; }
.article blockquote {
  margin: 0 0 1.1rem; padding: .1rem 0 .1rem 1.1rem;
  border-left: 3px solid var(--border-strong); color: var(--text-2);
}
.article code, .article kbd {
  font-family: var(--mono); font-size: .875em;
  padding: .12em .38em; border-radius: 5px;
  background: var(--bg-soft); border: 1px solid var(--border);
}
.article kbd { border-bottom-width: 2px; }
.article pre {
  margin: 0 0 1.25rem; padding: 1rem 1.15rem;
  overflow-x: auto; border-radius: var(--radius);
  background: var(--bg-soft); border: 1px solid var(--border);
  font-size: .875rem; line-height: 1.55;
}
.article pre code { padding: 0; border: 0; background: none; font-size: inherit; }
.article table {
  display: block; overflow-x: auto; max-width: 100%;
  margin: 0 0 1.25rem; border-collapse: collapse; font-size: .95rem;
}
.article th, .article td { padding: .5rem .75rem; border: 1px solid var(--border); text-align: left; vertical-align: top; }
.article th { background: var(--bg-soft); font-weight: 600; }

/* Хлебные крошки */
.breadcrumbs ol {
  display: flex; flex-wrap: wrap; gap: .2rem .45rem;
  list-style: none; margin: 0 0 1rem; padding: 0;
  font-size: .85rem; color: var(--muted); line-height: 1.5;
}
.breadcrumbs li + li::before {
  content: ">"; content: ">" / "";   /* вторая запись — пустая подпись для скринридеров */
  margin-right: .45rem; color: var(--border-strong);
}
[data-theme="dark"] .breadcrumbs li + li::before { color: var(--muted); }  /* в тёмной теме border-strong почти не виден */
.breadcrumbs a { color: var(--muted); text-decoration: none; }
.breadcrumbs a:hover { color: var(--accent); text-decoration: underline; }
.breadcrumbs [aria-current] { color: var(--text-2); }

/* Картинки: клик открывает оригинал (лайтбокс) */
.article img { max-width: 100%; height: auto; vertical-align: middle; }
.article a.zoom { cursor: zoom-in; }
.article a.zoom img, .article p > img {
  border: 1px solid var(--img-border);
}
.article img.align-center { display: block; margin: 1rem auto; }
.article img.align-left { float: left; margin: .3rem 1.5rem 1rem 0; }
.article img.align-right { float: right; margin: .3rem 0 1rem 1.5rem; }

/* Пометки в строке: [текст]{.hi} */
.article .hi { background: var(--mark); color: inherit; padding: 0 .15em; border-radius: 3px; }
.article span.important { color: var(--important); font-weight: 600; }
.article span.lo { color: var(--muted); font-size: .92em; }
.article span.em { font-weight: 600; font-style: italic; }

/* Инфо-блоки: ::: note | tip | warning | important | box */
.callout {
  line-height: 1.6;
  --c: var(--note); --c-bg: var(--note-bg); --c-border: var(--note-border);
  position: relative;
  margin: 1.5rem 0; padding: .85rem 1.15rem .85rem 2.95rem;
  background: var(--c-bg); border: 1px solid var(--c-border); border-radius: var(--radius);
  font-size: .98rem;
}
.callout::before {
  content: ""; position: absolute; left: 1rem; top: 1.08rem;
  width: 1.2rem; height: 1.2rem; background: var(--c);
  -webkit-mask: var(--c-icon) center / contain no-repeat;
  mask: var(--c-icon) center / contain no-repeat;
}
.callout > :first-child { margin-top: 0; }
.callout > :last-child { margin-bottom: 0; }
.callout-note {
  --c-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='12' cy='12' r='9.5'/%3E%3Cpath d='M12 11v6M12 7.5v.01'/%3E%3C/svg%3E");
}
.callout-tip {
  --c: var(--tip); --c-bg: var(--tip-bg); --c-border: var(--tip-border);
  --c-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M9 18h6M10 21.5h4M12 2.5a6.5 6.5 0 0 0-4 11.6c.6.5 1 1.2 1 2V16h6v-.9c0-.8.4-1.5 1-2A6.5 6.5 0 0 0 12 2.5Z'/%3E%3C/svg%3E");
}
.callout-warning {
  --c: var(--warning); --c-bg: var(--warning-bg); --c-border: var(--warning-border);
  --c-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M10.3 3.9 1.8 18.5A2 2 0 0 0 3.5 21.5h17a2 2 0 0 0 1.7-3L13.7 3.9a2 2 0 0 0-3.4 0Z'/%3E%3Cpath d='M12 9v4.5M12 17.5v.01'/%3E%3C/svg%3E");
}
.callout-important {
  --c: var(--important); --c-bg: var(--important-bg); --c-border: var(--important-border);
  --c-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M7.9 2.5h8.2l5.4 5.4v8.2l-5.4 5.4H7.9l-5.4-5.4V7.9Z'/%3E%3Cpath d='M12 7.5V13M12 16.5v.01'/%3E%3C/svg%3E");
}
.callout-box { padding-left: 1.15rem; background: var(--bg-soft); border-color: var(--border); }
.callout-box::before { content: none; }
.callout.align-right { float: right; margin: .3rem 0 1rem 1.5rem; max-width: 50%; }
.callout.align-left { float: left; margin: .3rem 1.5rem 1rem 0; max-width: 50%; }
.callout.align-center { margin-left: auto; margin-right: auto; }

/* Видео: превью + плеер по клику (site.js) */
.video {
  position: relative; aspect-ratio: 16 / 9; max-width: 40rem;
  margin: 1.5rem 0; overflow: hidden;
  border-radius: var(--radius); background: #0b0d10;
}
.video-link { position: absolute; inset: 0; display: block; }
.video-link img { width: 100%; height: 100%; object-fit: cover; border: 0; border-radius: 0; opacity: .92; transition: opacity .15s; }
.video-vimeo .video-link { background: radial-gradient(circle at 30% 20%, #23415c, #0b0d10 70%); }
.video-link::before, .video-link::after { content: ""; position: absolute; left: 50%; top: 50%; }
.video-link::before {
  width: 4.25rem; height: 4.25rem; margin: -2.125rem 0 0 -2.125rem;
  border-radius: 50%; background: rgba(10, 12, 16, .72);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, .85);
  transition: background .15s, transform .15s;
}
.video-link::after {
  margin: -.8rem 0 0 -.45rem;
  border-style: solid; border-width: .8rem 0 .8rem 1.35rem;
  border-color: transparent transparent transparent #fff;
}
.video-link:hover::before, .video-link:focus-visible::before { background: var(--accent); transform: scale(1.06); }
.video-link:hover img { opacity: 1; }
.video iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }

/* Подвал статьи: дата, «Наверх», «Предыдущая / Следующая» */
.article-footer { clear: both; margin-top: 3.5rem; }
.article-meta {
  display: flex; flex-wrap: wrap; justify-content: space-between; gap: .5rem 1.5rem;
  padding-top: 1rem; border-top: 1px solid var(--border);
  font-size: .85rem; color: var(--muted);
}
.article-meta p { margin: 0; }
.article-meta .to-top { margin-left: auto; }
.article-meta a { color: var(--muted); text-decoration: none; }
.article-meta a:hover { color: var(--accent); }
.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-top: 1.5rem; }
.pager a {
  display: block; padding: .85rem 1.1rem;
  border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--accent); text-decoration: none; font-weight: 600; line-height: 1.4;
  font-size: .98rem;
  transition: border-color .15s, background .15s;
}
.pager a:hover { border-color: var(--accent); background: var(--accent-soft); }
.pager span { display: block; margin-bottom: .15rem; font-size: .78rem; font-weight: 500; color: var(--muted); }
.pager .next { grid-column: 2; text-align: right; }

/* Подвал сайта: копирайт под статьёй, в её колонке */
.site-footer {
  padding: 2.5rem 0 1.5rem;
  color: var(--muted); font-size: .85rem;
}

/* ------------------------------------------------------------------
   Страница 404
   ------------------------------------------------------------------ */
.not-found { padding-top: 3rem; }
.error-code {
  margin: 0; font-size: 4.5rem; font-weight: 800; line-height: 1;
  letter-spacing: -.04em; color: var(--accent); opacity: .35;
}
.search-large { gap: .5rem; margin: 0 0 1.5rem; max-width: 34rem; }
.search-large input[type="search"] { flex: 1; width: auto; height: 2.75rem; font-size: 1rem; }
.search-large > .icon { top: .8rem; }
/* На странице 404 результаты — обычный список под полем */
.search-large { flex-wrap: wrap; }
.search-large .search-panel {
  position: static; flex-basis: 100%; width: auto; max-height: none; overflow: visible;
  margin-top: .25rem; padding: 0; border: 0; box-shadow: none; background: none;
}
.search-large .search-status { margin-inline: 0; }
.search-large .search-results a { padding-inline: .6rem; margin-inline: -.6rem; }
.search-large .search-more { margin-inline: 0; }
.button {
  display: inline-flex; align-items: center; height: 2.75rem; padding: 0 1.15rem;
  border: 1px solid var(--accent); border-radius: 8px;
  background: var(--accent); color: #fff; font: inherit; font-size: .95rem; font-weight: 600;
  text-decoration: none; cursor: pointer;
}
.button:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: #fff; text-decoration: none; }
[data-theme="dark"] .button { color: #0f1217; }
.button-secondary { background: transparent; color: var(--accent); }
/* Тёмный текст тёмной темы — только для залитых кнопок; у прозрачной он сливался с фоном */
[data-theme="dark"] .button-secondary { color: var(--accent); }
.button-secondary:hover { background: var(--accent-soft); color: var(--accent); }
.not-found .sections { columns: 2 14rem; column-gap: 2rem; padding-left: 1.2rem; }
.not-found .sections li { margin: 0 0 .5rem; break-inside: avoid; }

/* ------------------------------------------------------------------
   Лайтбокс (site.js)
   ------------------------------------------------------------------ */
.lightbox {
  width: 100vw; height: 100vh; max-width: none; max-height: none;
  margin: 0; padding: 0; border: 0; background: transparent; color: #e8e8e8;
}
.lightbox[open] { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .75rem; }
.lightbox::backdrop { background: rgba(8, 10, 14, .9); }
.lightbox img {
  display: block; max-width: calc(100vw - 2rem); max-height: calc(100vh - 5.5rem);
  width: auto; height: auto; object-fit: contain;
  background: #fff; box-shadow: 0 20px 60px rgba(0, 0, 0, .5);
  cursor: zoom-out;
}
.lightbox p { margin: 0; max-width: 60rem; padding: 0 1rem; text-align: center; font-size: .95rem; }
.lightbox p:empty { display: none; }
.lightbox-close {
  position: absolute; top: .75rem; right: .75rem;
  width: 2.75rem; height: 2.75rem; padding: 0;
  border: 0; border-radius: 50%; background: rgba(255, 255, 255, .12);
  color: #fff; font-size: 1.75rem; line-height: 1; cursor: pointer;
}
.lightbox-close:hover { background: rgba(255, 255, 255, .25); }

/* ------------------------------------------------------------------
   Средние экраны: оглавление уходит в статью
   ------------------------------------------------------------------ */
@media (max-width: 74.99rem) {
  .layout, .layout.no-toc { grid-template-columns: var(--sidebar-w) minmax(0, var(--content-w)); grid-template-areas: "sidebar main" "sidebar footer"; column-gap: 2.5rem; }
  .layout.no-sidebar, .layout.no-sidebar:not(.no-toc) { grid-template-columns: minmax(0, var(--content-w)); grid-template-areas: "main" "footer"; }
  .toc { display: none; }
  .toc-inline { display: block; }
}

/* ------------------------------------------------------------------
   Узкие экраны: сайдбар выдвигается, поиск — по кнопке
   ------------------------------------------------------------------ */
@media (max-width: 59.99rem) {
  .layout, .layout.no-toc, .layout.no-sidebar { display: flex; flex-direction: column; padding: 0 1.25rem; }
  .site-footer { margin-top: auto; } /* на короткой странице — у низа окна */
  .header-inner { padding: 0 .75rem 0 .5rem; gap: .5rem; }
  .js .menu-btn { display: inline-flex; }
  .search input[type="search"] { width: 12rem; }

  /* Без JS сайдбар — обычный список после статьи */
  html:not(.js) .sidebar {
    position: static; max-height: none; overflow: visible;
    margin: 0 0 2rem; padding: 1.5rem 0 0; border-top: 1px solid var(--border);
  }
  .js .sidebar {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 70;
    align-self: auto; /* иначе start из сетки сжимает панель до содержимого */
    width: min(21rem, 86vw); max-height: none;
    padding: 0 .75rem 2rem;
    background: var(--bg); border-right: 1px solid var(--border);
    box-shadow: var(--shadow);
    transform: translateX(-105%); visibility: hidden;
    transition: transform .2s ease, visibility 0s linear .2s;
  }
  .js.nav-open .sidebar { transform: none; visibility: visible; transition: transform .2s ease; }
  .js.nav-open { overflow: hidden; }
  .sidebar-close {
    display: flex; position: sticky; top: 0; z-index: 1;
    justify-content: flex-end; margin: 0 -.75rem .25rem; padding: .6rem .6rem .25rem;
    background: var(--bg);
  }
  .sidebar-backdrop {
    position: fixed; inset: 0; z-index: 65;
    background: rgba(8, 10, 14, .45);
  }
}

@media (max-width: 40rem) {
  :root { --header-h: 3.25rem; }
  .article { padding-top: 1.25rem; font-size: 1rem; }
  .article h1 { font-size: 1.75rem; }
  .article h2 { font-size: 1.35rem; margin-top: 2.25rem; }
  .article h3 { font-size: 1.15rem; }
  .brand { font-size: 1rem; }
  .brand img { width: 28px; height: 28px; }

  .js .search-btn { display: inline-flex; }
  .print-btn { display: none; } /* на телефоне место нужнее названию; печать — из меню браузера */
  .js .site-header .search {
    display: none;
    position: absolute; left: 0; right: 0; top: 100%;
    padding: .6rem .75rem; background: var(--bg); border-bottom: 1px solid var(--border);
    box-shadow: 0 8px 16px rgba(15, 23, 42, .08);
  }
  .js.search-open .site-header .search { display: flex; }
  .js .site-header .search > .icon { left: 1.4rem; }
  .site-header .search input[type="search"] { width: 100%; }
  .site-header .search-panel { left: .75rem; right: .75rem; width: auto; max-height: calc(100vh - var(--header-h) - 5rem); }
  html:not(.js) .header-inner { height: auto; min-height: var(--header-h); flex-wrap: wrap; padding-block: .5rem; }
  html:not(.js) .header-tools { width: 100%; }
  html:not(.js) .site-header .search { flex: 1; }
  html:not(.js) .site-header { position: static; }

  /* Плавающие картинки и блоки на всю ширину */
  .article img.align-left, .article img.align-right { float: none; display: block; margin: 1rem 0; }
  .callout.align-left, .callout.align-right { float: none; width: auto !important; max-width: none; margin: 1.5rem 0; }
  .pager { grid-template-columns: 1fr; }
  .pager .next { grid-column: 1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; scroll-behavior: auto !important; }
}

/* ------------------------------------------------------------------
   Печать
   ------------------------------------------------------------------ */
@media print {
  :root { --text: #000; --muted: #444; --border: #bbb; --accent: #000; }
  html, body, .article { background: #fff; }
  body { display: block; font-size: 11pt; color: #000; }
  .site-header, .sidebar, .toc, .toc-inline, .pager, .to-top, .skip-link,
  .site-footer, .breadcrumbs, .sidebar-backdrop { display: none !important; }
  .layout { display: block; padding: 0; max-width: none; }
  .article { padding: 0; font-size: 11pt; }
  .article a { color: inherit; text-decoration: underline; }
  .article h2 { border-top: 0; padding-top: 0; break-after: avoid; }
  .article h3, .article h4 { break-after: avoid; }
  .article img, .callout, .video, pre { break-inside: avoid; }
  .video-link::before, .video-link::after { display: none; }
  .video::after { content: attr(data-video-id); position: absolute; left: .5rem; bottom: .5rem; color: #fff; font-size: 9pt; }
}
