/* ==========================================================================
   DevStudioRBX – Правила проекта (правила игры + правила фракций)
   Требует design-system.css (токены и базовые компоненты).
   Язык страницы: editorial-строки с hairline-разделителями, номер пункта
   в левой колонке-гаттере, наказания – цветные чипы, без карточек-«коробок».
   ========================================================================== */

:root {
  /* Основной текст статьи: ярче secondary для долгого чтения */
  --article-text: #b9c2d0;
  --header-h: 60px;
  --controls-h: 66px;
  --tocbar-h: 45px;
  /* Смещение якорей под липкие панели */
  --anchor-off: calc(var(--header-h) + var(--controls-h) + 20px);
  /* Высота экранной клавиатуры (ставится из JS через visualViewport) */
  --kb: 0px;

  /* Палитра наказаний */
  --pen-warn: #ffc857;
  --pen-warn-bg: rgba(255, 193, 7, 0.11);
  --pen-morgan: #a78bfa;
  --pen-morgan-bg: rgba(139, 92, 246, 0.14);
  --pen-mute: #5ecfe0;
  --pen-mute-bg: rgba(45, 190, 220, 0.12);
  --pen-ban: #ff8a80;
  --pen-ban-bg: rgba(255, 69, 58, 0.12);
  --pen-perm: #ff6b60;
  --pen-perm-bg: rgba(255, 69, 58, 0.18);
}

/* Страховка от горизонтального переполнения: clip не создаёт скролл-контейнер,
   поэтому position: sticky у шапки продолжает работать. Без этого случайный
   широкий элемент на телефоне заставляет браузер расширить вьюпорт и отдать
   «десктопную» вёрстку с зумом. */
html {
  overflow-x: clip;
}

/* --- Header (как на главной, всегда с фоном) --- */
header {
  position: sticky;
  top: env(safe-area-inset-top, 0);
  z-index: 40;
  background: rgba(10, 11, 14, 0.72);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid var(--border);
}
.nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
  min-height: var(--header-h);
}
.brand {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  min-width: 0;
}
.brand .logo {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  overflow: hidden;
  flex: 0 0 auto;
}
.brand h1 {
  margin: 0;
  font-size: 0.98rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
}
.brand .pill {
  padding: 0.22rem 0.65rem;
  font-size: 0.78rem;
}
.menu {
  display: flex;
  align-items: center;
  gap: var(--sp-5);
}
.menu a:not(.btn) {
  color: var(--text-secondary);
  font-size: 0.93rem;
  font-weight: 500;
  white-space: nowrap;
  transition: color 0.18s ease;
}
.menu a:not(.btn):hover {
  color: var(--text);
}
.menu .btn {
  min-height: 38px;
  padding: 0.45rem 1.05rem;
  font-size: 0.9rem;
}

/* Переключатель языка */
.langtoggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 0.3rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  background: var(--surface);
  color: var(--text-secondary);
  font-family: var(--font);
  font-size: 0.84rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: color 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}
.langtoggle:hover {
  color: var(--text);
  background: var(--surface-2);
  border-color: var(--border-strong);
}
.langtoggle svg {
  flex: 0 0 auto;
  opacity: 0.8;
}

/* --- Page head --- */
.page-head {
  padding: clamp(36px, 6vw, 64px) 0 var(--sp-5);
}
.page-head .lead {
  margin-top: var(--sp-3);
  max-width: 620px;
}
.head-meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  margin-top: var(--sp-5);
}
.head-meta .pill {
  font-size: 0.82rem;
  padding: 0.3rem 0.8rem;
}

/* --- Панель управления: переключатель книг + поиск --- */
.controls {
  position: sticky;
  top: calc(var(--header-h) - 1px);
  z-index: 35;
  background: rgba(10, 11, 14, 0.82);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  backdrop-filter: saturate(160%) blur(14px);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.controls-row {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  min-height: var(--controls-h);
  padding: var(--sp-2) 0;
}

/* Сегментированный переключатель */
.switch {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  flex: 0 0 auto;
}
.switch button {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 38px;
  padding: 0.4rem 1.05rem;
  border: none;
  border-radius: var(--r-full);
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font);
  font-size: 0.92rem;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease;
}
.switch button:hover {
  color: var(--text);
}
/* Короткие подписи для узких экранов (см. медиазапрос ≤640) */
.lbl-min {
  display: none;
}
.switch button[aria-selected="true"] {
  background: var(--accent);
  color: #fff;
}
.switch .badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: var(--r-full);
  background: var(--accent-soft);
  color: var(--accent-text);
  font-size: 0.72rem;
  font-weight: 700;
}
.switch button[aria-selected="true"] .badge {
  background: rgba(255, 255, 255, 0.22);
  color: #fff;
}

/* Поиск */
.search {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  max-width: 420px;
  margin-left: auto;
}
/* Иконка/кнопки лежат поверх input: у поля в доке есть backdrop-filter,
   из-за которого оно образует стек-контекст и перекрывает соседей */
.search-ico,
.search-hint,
.search-clear {
  z-index: 2;
}
.search-ico {
  position: absolute;
  left: 13px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-tertiary);
  pointer-events: none;
}
.search input {
  width: 100%;
  min-height: 42px;
  padding: 0.5rem 40px 0.5rem 38px;
  border-radius: var(--r-full);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font);
  /* 16px – не меньше, иначе мобильные браузеры зумят страницу при фокусе */
  font-size: 16px;
  transition: border-color 0.18s ease, background 0.18s ease,
    box-shadow 0.18s ease;
}
.search input::placeholder {
  color: var(--text-tertiary);
}
.search input:focus {
  outline: none;
  background: var(--surface-2);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(53, 111, 238, 0.18);
}
.search input::-webkit-search-decoration,
.search input::-webkit-search-cancel-button {
  -webkit-appearance: none;
}
.search-clear {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-tertiary);
  cursor: pointer;
  transition: color 0.15s ease, background 0.15s ease;
}
.search-clear:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
}
/* Подсказка «/» – только когда поле пустое и не в фокусе */
.search input:focus + .search-hint,
.search input:not(:placeholder-shown) + .search-hint {
  display: none;
}
.search-hint {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-tertiary);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1px 6px;
  pointer-events: none;
}

/* --- Навигация по совпадениям (стрелки + счётчик) --- */
.searchnav {
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
}
.searchnav-pill {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  background: var(--surface);
}
.searchnav button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: color 0.15s ease, background 0.15s ease;
}
.searchnav button:hover:not(:disabled) {
  color: var(--text);
  background: rgba(255, 255, 255, 0.07);
}
.searchnav button:disabled {
  opacity: 0.35;
  cursor: default;
}
.searchnav .pos {
  padding: 0 8px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* --- Подсветка совпадений --- */
mark {
  background: rgba(255, 193, 7, 0.26);
  color: inherit;
  border-radius: 3px;
  padding: 0 1px;
}
.is-current mark {
  background: var(--accent);
  color: #fff;
}

/* --- Мобильная панель оглавления (sticky под шапкой) --- */
.tocbar {
  display: none;
  position: sticky;
  top: var(--header-h);
  z-index: 30;
  background: rgba(10, 11, 14, 0.85);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid var(--border);
}
.tocbar-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  min-height: 44px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--text);
  font-family: var(--font);
  font-size: 0.92rem;
  font-weight: 500;
  cursor: pointer;
}
.tocbar-btn svg {
  flex: 0 0 auto;
}
#tocLabel {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.tocbar-btn svg:first-child {
  color: var(--accent-text);
}
.tocbar-chev {
  color: var(--text-tertiary);
  transition: transform 0.2s ease;
}
.toc-open .tocbar-chev {
  transform: rotate(180deg);
}

/* --- Layout: книга + оглавление --- */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 248px;
  gap: clamp(40px, 5vw, 72px);
  align-items: start;
  margin-top: var(--sp-6);
}
.books {
  max-width: 760px;
  min-width: 0;
}
/* [hidden] должен побеждать display:grid/flex у компонентов ниже */
.book[hidden],
.chapter[hidden],
.sub[hidden],
.rule[hidden],
.gloss-item[hidden],
.cmd[hidden],
.book-head[hidden],
.legend[hidden],
.switch .badge[hidden],
.search-clear[hidden],
.searchnav[hidden] {
  display: none !important;
}

/* --- Оглавление (desktop sidebar) --- */
#toc {
  position: sticky;
  top: calc(var(--header-h) + var(--controls-h) + 24px);
  max-height: calc(100vh - var(--header-h) - var(--controls-h) - 48px);
  overflow-y: auto;
  overscroll-behavior: contain;
  font-size: 0.9rem;
}
.toc-title {
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  margin-bottom: var(--sp-3);
}
#toc ul {
  list-style: none;
  margin: 0;
  padding: 0;
  border-left: 1px solid var(--border);
}
#toc a {
  display: block;
  padding: 6px 0 6px 14px;
  margin-left: -1px;
  color: var(--text-secondary);
  border-left: 2px solid transparent;
  line-height: 1.35;
  transition: color 0.15s ease, border-color 0.15s ease;
}
#toc a:hover {
  color: var(--text);
}
#toc a.active {
  color: var(--accent-text);
  border-left-color: var(--accent);
}
#toc .toc-h1 a {
  font-weight: 600;
  color: var(--text);
}
#toc .toc-h1 a.active {
  color: var(--accent-text);
}
#toc .toc-h2 a {
  padding-left: 26px;
  font-size: 0.86rem;
}

/* --- Типографика книги --- */
.book h1,
.book h2,
.book h3,
.chapter,
.sub {
  scroll-margin-top: var(--anchor-off);
}
.book h1 {
  font-size: clamp(1.5rem, 2.6vw, 1.85rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
  margin: var(--sp-8) 0 var(--sp-4);
  padding-top: var(--sp-6);
  border-top: 1px solid var(--border);
}
.book section.chapter:first-of-type h1,
.book .chapter.is-first h1 {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
}
.book h2 {
  font-size: 1.16rem;
  font-weight: 600;
  letter-spacing: -0.014em;
  line-height: 1.3;
  margin: var(--sp-6) 0 var(--sp-2);
  color: var(--text);
}
.book h3 {
  font-size: 1.02rem;
  font-weight: 600;
  margin: 0 0 var(--sp-2);
}
.book p {
  margin: 0 0 var(--sp-3);
  color: var(--article-text);
  line-height: 1.7;
}
.book p:last-child {
  margin-bottom: 0;
}
.book a {
  color: var(--accent-text);
}
.book a:hover {
  text-decoration: underline;
}
.book ul,
.book ol {
  margin: var(--sp-2) 0 var(--sp-3);
  padding-left: 1.25rem;
  color: var(--article-text);
  line-height: 1.7;
}
.book li {
  margin: 5px 0;
}
.book li::marker {
  color: var(--text-tertiary);
}
.book code {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
    monospace;
  font-size: 0.88em;
  padding: 0.12rem 0.4rem;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.06);
  color: #dbe2ee;
  white-space: nowrap;
}

/* Шапка книги */
.book-head {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0 var(--sp-3);
  margin-bottom: var(--sp-6);
  padding-bottom: var(--sp-4);
  border-bottom: 1px solid var(--border);
  font-size: 0.88rem;
  color: var(--text-tertiary);
}
.book-head strong {
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 600;
}
.book-head .dot {
  color: var(--border-strong);
}

/* Вступление раздела */
.chapter-intro {
  border-left: 2px solid var(--accent);
  padding-left: var(--sp-4);
  margin-bottom: var(--sp-4) !important;
}
.chapter-intro .term-lead {
  display: block;
  color: var(--text);
  font-weight: 600;
  margin-bottom: 4px;
}

/* --- Пункт правила --- */
.rule {
  display: grid;
  grid-template-columns: 62px minmax(0, 1fr);
  gap: 0 16px;
  padding: 15px 0;
  border-top: 1px solid var(--border);
  scroll-margin-top: var(--anchor-off);
  border-radius: 4px;
  transition: background 0.3s ease;
}
.rule-n {
  padding-top: 2px;
  font-size: 0.82rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text-tertiary);
  letter-spacing: 0.01em;
  transition: color 0.15s ease;
}
a.rule-n:hover {
  color: var(--accent-text);
}
.rule-body > *:last-child {
  margin-bottom: 0;
}
/* Подсветка активного пункта/цели/результата поиска.
   Акцентная полоса и фон «выезжают» на 15px влево от контента (в гаттер),
   поэтому они больше не перекрывают номер 01, 07 и т.д. */
.rule:target,
.rule.is-flash,
.is-current {
  background: linear-gradient(
    90deg,
    rgba(53, 111, 238, 0.14),
    rgba(53, 111, 238, 0) 72%
  );
  box-shadow: inset 3px 0 0 var(--accent);
  padding-left: 15px;
  margin-left: -15px;
  border-radius: 0 5px 5px 0;
}
.rule:target .rule-n,
.rule.is-flash .rule-n,
.rule.is-current .rule-n {
  color: var(--accent-text);
}
/* Упразднённый пункт */
.rule--void .rule-body {
  color: var(--text-tertiary);
  font-style: italic;
  font-size: 0.94rem;
}
.rule--void .rule-body p {
  color: inherit;
}

/* --- Чипы наказаний --- */
.pens {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}
.pen {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.62rem;
  border-radius: var(--r-full);
  border: 1px solid transparent;
  font-size: 0.76rem;
  font-weight: 600;
  letter-spacing: 0.005em;
  white-space: nowrap;
}
.pen--warn {
  background: var(--pen-warn-bg);
  border-color: rgba(255, 193, 7, 0.22);
  color: var(--pen-warn);
}
.pen--morgan {
  background: var(--pen-morgan-bg);
  border-color: rgba(139, 92, 246, 0.26);
  color: var(--pen-morgan);
}
.pen--mute {
  background: var(--pen-mute-bg);
  border-color: rgba(45, 190, 220, 0.24);
  color: var(--pen-mute);
}
.pen--kick {
  background: rgba(255, 255, 255, 0.055);
  border-color: var(--border);
  color: var(--text-secondary);
}
.pen--ban {
  background: var(--pen-ban-bg);
  border-color: rgba(255, 69, 58, 0.24);
  color: var(--pen-ban);
}
.pen--perm {
  background: var(--pen-perm-bg);
  border-color: rgba(255, 69, 58, 0.45);
  color: var(--pen-perm);
}

/* Название нарушения */
.viol {
  display: inline-block;
  padding: 0.06rem 0.42rem;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent-text);
  font-size: 0.92em;
  font-weight: 600;
  white-space: nowrap;
}

/* Сторона конфликта: гос. / крим. */
.side {
  display: inline-block;
  padding: 0.08rem 0.5rem;
  margin-right: 6px;
  border-radius: 6px;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  vertical-align: 1px;
}
.side--gov {
  background: var(--accent-soft);
  color: var(--accent-text);
}
.side--crim {
  background: rgba(255, 69, 58, 0.14);
  color: #ff8a80;
}

/* --- Заметки: примечание / исключение / пример --- */
.note {
  margin-top: 10px;
  padding-left: 13px;
  border-left: 2px solid var(--border-strong);
  color: var(--text-secondary);
  font-size: 0.93rem;
  line-height: 1.62;
}
.note + .note {
  margin-top: 8px;
}
.note p {
  color: inherit;
  font-size: inherit;
  margin: 0;
}
.note-label {
  display: block;
  font-size: 0.71rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  margin-bottom: 3px;
}
.note--ex {
  border-left-color: var(--accent);
}
.note--ex .note-label {
  color: var(--accent-text);
}
.note--warn {
  border-left-color: rgba(255, 193, 7, 0.5);
}
.note--warn .note-label {
  color: var(--pen-warn);
}

/* --- Блок кода / шаблона --- */
.code {
  margin: 10px 0 0;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: #0d0f14;
  color: #c8d1e0;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
    monospace;
  font-size: 0.83rem;
  line-height: 1.7;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  tab-size: 2;
}
.code .ok {
  color: #7ee2a0;
}
.code .bad {
  color: #ff8a80;
}
.code .cm {
  color: var(--text-tertiary);
}

/* --- Глоссарий --- */
.gloss {
  margin: var(--sp-2) 0 0;
}
.gloss-item {
  display: grid;
  grid-template-columns: 132px minmax(0, 1fr);
  gap: 0 16px;
  padding: 13px 0;
  border-top: 1px solid var(--border);
}
.gloss-item dt {
  font-weight: 600;
  color: var(--text);
  font-size: 0.94rem;
}
.gloss-item dd {
  margin: 0;
  color: var(--article-text);
  line-height: 1.65;
  font-size: 0.97rem;
}

/* --- Команды --- */
.cmd {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  gap: 0 16px;
  padding: 14px 0;
  border-top: 1px solid var(--border);
}
.cmd .cmd-name {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
    monospace;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--accent-text);
  background: var(--accent-soft);
  border-radius: 7px;
  padding: 3px 9px;
  justify-self: start;
  align-self: start;
  white-space: nowrap;
}
.cmd-body p {
  margin: 0;
}
.cmd-ex {
  margin-top: 4px !important;
  color: var(--text-tertiary) !important;
  font-size: 0.9rem;
}

/* --- Зоны территорий --- */
.zone {
  margin-top: 12px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-left-width: 3px;
  border-radius: var(--r-sm);
  background: rgba(255, 255, 255, 0.018);
}
.zone-head {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  color: var(--text);
  font-size: 0.97rem;
  margin-bottom: 5px;
}
.zone-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex: 0 0 auto;
}
.zone--red {
  border-left-color: #ff453a;
}
.zone--red .zone-dot {
  background: #ff453a;
  box-shadow: 0 0 0 3px rgba(255, 69, 58, 0.16);
}
.zone--yellow {
  border-left-color: #ffcc00;
}
.zone--yellow .zone-dot {
  background: #ffcc00;
  box-shadow: 0 0 0 3px rgba(255, 204, 0, 0.16);
}
.zone--gray {
  border-left-color: #8a93a5;
}
.zone--gray .zone-dot {
  background: #8a93a5;
  box-shadow: 0 0 0 3px rgba(138, 147, 165, 0.16);
}
.zone p {
  font-size: 0.95rem;
  margin-bottom: 0;
}
.zone .note {
  font-size: 0.9rem;
}

/* Заглушка для изображения из Discord */
.imgstub {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
  margin-top: 10px;
  padding: 14px 16px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--r-sm);
  color: var(--text-tertiary);
  font-size: 0.92rem;
}

.imgstub img {
  width: 100%;
  /* max-width: 600px; */
  height: auto;
  border-radius: var(--r-sm);
}

.imgstub svg {
  flex: 0 0 auto;
  color: var(--text-tertiary);
}

.imgstub b {
  display: block;
  color: var(--text-secondary);
  font-weight: 600;
}

/* --- Легенда наказаний --- */
.legend {
  margin: 0 0 var(--sp-5);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
  overflow: hidden;
}
.legend > summary {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 500;
  list-style: none;
}
.legend > summary::-webkit-details-marker {
  display: none;
}
.legend > summary .chev {
  margin-left: auto;
  color: var(--text-tertiary);
  transition: transform 0.2s ease;
}
.legend[open] > summary .chev {
  transform: rotate(180deg);
}
.legend-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 10px 20px;
  padding: 4px 16px 16px;
  border-top: 1px solid var(--border);
  padding-top: 14px;
}
.legend-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  font-size: 0.88rem;
  color: var(--text-secondary);
  line-height: 1.5;
}
.legend-row .pen {
  flex: 0 0 auto;
}

/* --- Статус поиска / пустое состояние --- */
.search-status {
  margin-bottom: var(--sp-5);
  font-size: 0.9rem;
  color: var(--text-tertiary);
}
.search-status b {
  color: var(--text);
  font-weight: 600;
}
.search-status .link {
  color: var(--accent-text);
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.empty {
  padding: var(--sp-8) 0;
  text-align: center;
  color: var(--text-secondary);
}
.empty h3 {
  margin: 0 0 6px;
  color: var(--text);
  font-size: 1.05rem;
  font-weight: 600;
}
.empty p {
  margin: 0 0 var(--sp-4);
  color: var(--text-tertiary);
}
.empty-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}
.empty-actions .btn[hidden] {
  display: none !important;
}

/* --- Кнопка «наверх» --- */
.totop {
  position: fixed;
  right: max(20px, env(safe-area-inset-right));
  bottom: max(20px, env(safe-area-inset-bottom));
  z-index: 45;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: rgba(17, 19, 24, 0.9);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  color: var(--text-secondary);
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  transform: translateY(8px);
  transition: opacity 0.22s ease, transform 0.22s ease, visibility 0.22s,
    color 0.18s ease, border-color 0.18s ease;
}
.totop.is-on {
  opacity: 1;
  visibility: visible;
  transform: none;
}
.totop:hover {
  color: var(--text);
  border-color: var(--border-strong);
}

/* --- Тост «ссылка скопирована» --- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translate(-50%, 12px);
  z-index: 60;
  padding: 0.6rem 1.1rem;
  border-radius: var(--r-full);
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-md);
  color: var(--text);
  font-size: 0.88rem;
  font-weight: 500;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s;
}
.toast.is-on {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, 0);
}

/* --- Footer --- */
footer {
  margin-top: var(--sp-9);
  padding: var(--sp-6) 0 var(--sp-7);
  border-top: 1px solid var(--border);
  color: var(--text-tertiary);
  font-size: 0.9rem;
}
.footer-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--sp-4);
  flex-wrap: wrap;
}
.footer-links {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  flex-wrap: wrap;
}
.footer-links a {
  color: var(--text-tertiary);
  transition: color 0.18s ease;
}
.footer-links a:hover {
  color: var(--text);
}

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 900px) {
  :root {
    --anchor-off: calc(var(--header-h) + var(--tocbar-h) + 16px);
  }
  .layout {
    grid-template-columns: 1fr;
    margin-top: var(--sp-5);
  }
  .books {
    max-width: none;
  }

  /* Панель управления перестаёт быть липкой – сверху липнет оглавление */
  .controls {
    position: static;
    background: transparent;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    border-top: none;
    border-bottom: none;
  }
  .controls-row {
    flex-direction: column;
    align-items: stretch;
    gap: var(--sp-3);
    min-height: 0;
    padding: 0;
  }
  .switch {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }
  .switch button {
    justify-content: center;
    min-width: 0;
    padding: 0.4rem 0.6rem;
    font-size: 0.88rem;
  }
  .search {
    max-width: none;
    margin-left: 0;
  }
  .search-hint {
    display: none;
  }

  /* Оглавление: выпадающая панель под sticky-баром */
  .tocbar {
    display: block;
  }
  #toc {
    display: none;
  }
  .toc-open #toc {
    display: block;
    position: fixed;
    top: calc(var(--header-h) + var(--tocbar-h));
    left: 0;
    right: 0;
    z-index: 29;
    max-height: calc(100vh - var(--header-h) - var(--tocbar-h) - 18vh);
    overflow-y: auto;
    background: #0d0f13;
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-md);
    padding: var(--sp-4) 24px var(--sp-5);
    animation: tocDrop 0.22s ease;
  }
  .toc-open #toc .toc-title {
    display: none;
  }

  /* ======================================================================
     Плавающий док (Apple-style): единственное место с разделами и поиском
     ====================================================================== */
  .controls-row {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: calc(14px + env(safe-area-inset-bottom, 0px) + var(--kb, 0px));
    width: auto;
    max-width: 520px;
    margin: 0 auto;
    z-index: 46;
    flex-direction: row;
    /* wrap-reverse: если лупа не влезает рядом с разделами, она переносится
       НАД ними, а не под (перенос идёт вверх). justify-end держит одинокую
       лупу у правого края – там же, где она обычно стоит. */
    flex-wrap: wrap-reverse;
    justify-content: flex-end;
    align-items: center;
    gap: 8px;
    padding: 0;
    animation: dockIn 0.3s cubic-bezier(0.2, 0.8, 0.3, 1);
    transition: opacity 0.2s ease;
  }
  body.toc-open .controls-row {
    opacity: 0;
    pointer-events: none;
  }
  body {
    padding-bottom: 92px;
  }
  /* Панель в потоке места не занимает */
  .controls {
    height: 0;
  }

  /* Навигация по совпадениям – компактной плашкой справа над доком.
     order:1 + wrap-reverse держит её самой верхней строкой дока. */
  .searchnav {
    order: 1;
    flex: 1 0 100%;
    justify-content: flex-end;
  }
  .searchnav-pill {
    border-color: rgba(255, 255, 255, 0.14);
    background: rgba(18, 21, 27, 0.94);
    box-shadow: 0 14px 34px rgba(0, 0, 0, 0.5), 0 2px 6px rgba(0, 0, 0, 0.3);
    -webkit-backdrop-filter: saturate(180%) blur(22px);
    backdrop-filter: saturate(180%) blur(22px);
  }
  .searchnav button {
    width: 34px;
    height: 34px;
  }
  .searchnav .pos {
    padding: 0 6px;
    font-size: 0.8rem;
  }

  /* Пузырёк с разделами */
  .switch {
    flex: 1 1 auto;
    min-width: 0;
    padding: 4px;
    gap: 4px;
    background: rgba(18, 21, 27, 0.94);
    border-color: rgba(255, 255, 255, 0.14);
    box-shadow: 0 14px 34px rgba(0, 0, 0, 0.5), 0 2px 6px rgba(0, 0, 0, 0.3);
    -webkit-backdrop-filter: saturate(180%) blur(22px);
    backdrop-filter: saturate(180%) blur(22px);
    transition: flex-basis 0.32s cubic-bezier(0.2, 0.8, 0.3, 1),
      width 0.32s cubic-bezier(0.2, 0.8, 0.3, 1), opacity 0.2s ease,
      transform 0.32s cubic-bezier(0.2, 0.8, 0.3, 1), padding 0.32s ease;
  }
  .switch button {
    min-height: 40px;
  }

  /* Кнопка-кружок поиска */
  .search {
    flex: 0 0 48px;
    width: 48px;
    max-width: none;
    margin: 0;
    transition: flex-basis 0.32s cubic-bezier(0.2, 0.8, 0.3, 1),
      width 0.32s cubic-bezier(0.2, 0.8, 0.3, 1);
  }
  .search input {
    min-height: 48px;
    height: 48px;
    /* 16px – чтобы iOS не зумил при фокусе */
    font-size: 16px;
    padding-left: 42px;
    padding-right: 42px;
    background: rgba(18, 21, 27, 0.94);
    border-color: rgba(255, 255, 255, 0.14);
    box-shadow: 0 14px 34px rgba(0, 0, 0, 0.5), 0 2px 6px rgba(0, 0, 0, 0.3);
    -webkit-backdrop-filter: saturate(180%) blur(22px);
    backdrop-filter: saturate(180%) blur(22px);
  }
  body:not(.search-open) .search input {
    padding: 0;
    color: transparent;
  }
  body:not(.search-open) .search input::placeholder {
    opacity: 0;
  }
  body:not(.search-open) .search-ico {
    left: 50%;
    transform: translate(-50%, -50%);
  }
  /* Свёрнутый кружок с активным запросом */
  body.has-query:not(.search-open) .search input {
    border-color: var(--accent);
  }
  body.has-query:not(.search-open) .search-ico {
    color: var(--accent-text);
  }
  /* В свёрнутом кружке крестику не место – он налезал на лупу */
  body:not(.search-open) .search-clear {
    display: none !important;
  }

  /* Раскрытый поиск: уезжает влево, закрывая разделы */
  body.search-open .switch {
    flex: 0 0 0px;
    width: 0;
    padding-left: 0;
    padding-right: 0;
    border-width: 0;
    opacity: 0;
    transform: translateX(-14px);
    overflow: hidden;
    pointer-events: none;
  }
  body.search-open .search {
    flex: 1 1 auto;
    width: auto;
  }
  body.search-open .search input:focus {
    box-shadow: 0 14px 34px rgba(0, 0, 0, 0.5), 0 0 0 3px rgba(53, 111, 238, 0.2);
  }
  .search-clear {
    right: 9px;
    width: 32px;
    height: 32px;
  }
  /* Кнопка «наверх» – над доком, чтобы не перекрывались */
  .totop {
    bottom: calc(76px + env(safe-area-inset-bottom, 0px) + var(--kb, 0px));
  }
  /* Во время поиска стрелки «N из M» занимают тот же угол – прячем «наверх»,
     навигация по совпадениям и так есть в доке */
  body.search-open .totop,
  body.has-query .totop {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
  }
}

@keyframes dockIn {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes tocDrop {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@media (max-width: 640px) {
  .brand .pill,
  .m-hide,
  .lbl-full {
    display: none;
  }
  .lbl-min {
    display: inline;
  }
  .switch {
    padding: 3px;
    gap: 3px;
  }
  .switch button {
    padding: 0.4rem 0.5rem;
  }
  .menu {
    gap: 10px;
  }
  .langtoggle {
    padding: 0.3rem 0.55rem;
    font-size: 0.8rem;
  }
  .langtoggle svg {
    display: none;
  }
  .page-head {
    padding-bottom: var(--sp-4);
  }

  /* Мета-строка вместо трёх «пилюль» */
  .head-meta {
    gap: 0 9px;
    margin-top: var(--sp-4);
    font-size: 0.86rem;
    line-height: 1.5;
  }
  .head-meta .pill {
    padding: 0;
    border: none;
    background: none;
    font-size: inherit;
    color: var(--text-tertiary);
  }
  .head-meta .pill:first-child {
    color: var(--accent-text);
    font-weight: 600;
  }
  .head-meta .pill + .pill::before {
    content: "·";
    margin-right: 9px;
    color: var(--border-strong);
  }

  /* Номер пункта – чипом над текстом */
  .rule {
    grid-template-columns: 1fr;
    gap: 6px;
    padding: 14px 0;
  }
  .rule-n {
    padding-top: 0;
    font-size: 0.78rem;
    color: var(--accent-text);
  }
  .gloss-item,
  .cmd {
    grid-template-columns: 1fr;
    gap: 5px;
  }
  .book h1 {
    font-size: 1.35rem;
  }
  .book h2 {
    font-size: 1.08rem;
  }
  .code {
    font-size: 0.78rem;
  }
  .legend-grid {
    grid-template-columns: 1fr;
  }
  .footer-row {
    flex-direction: column;
    align-items: flex-start;
  }
  .totop {
    width: 42px;
    height: 42px;
  }
}

/* Телефоны: шапка со словесным логотипом + всеми ссылками не влезает в
   ~360–430px и вызывает горизонтальное переполнение. Оставляем значок-логотип
   и компактное меню – так шапка гарантированно помещается. */
@media (max-width: 480px) {
  .brand h1 {
    display: none;
  }
  .brand {
    gap: 0;
  }
  .nav {
    gap: 10px;
  }
  .menu {
    gap: 8px;
  }
  .menu a:not(.btn) {
    font-size: 0.9rem;
  }
  .langtoggle {
    gap: 0;
    padding: 0.3rem 0.5rem;
  }
  .menu .btn {
    padding: 0.4rem 0.85rem;
    min-height: 36px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .toc-open #toc,
  .tocbar-chev,
  .totop,
  .toast,
  .rule {
    animation: none;
    transition: none;
  }
}

/* --- Печать --- */
@media print {
  header,
  .tocbar,
  .controls,
  #toc,
  .totop,
  .toast,
  .legend {
    display: none !important;
  }
  body {
    background: #fff;
    color: #111;
  }
  .book[hidden] {
    display: block !important;
  }
  .book p,
  .book li,
  .gloss-item dd {
    color: #222;
  }
  .rule {
    break-inside: avoid;
    border-top: 1px solid #ddd;
  }
  .layout {
    display: block;
  }
}
