/* Правила Rainbow — сводный читатель.
   Тёмная тема как единственная: свод читают ночью, в альт-табе из игры. */

:root {
  /* грунт: near-black со сдвигом в индиго, не нейтральный серый */
  --bg:        #0b0d12;
  --bg-sunk:   #080a0e;
  --surface:   #121620;
  --surface-2: #171c28;
  --line:      #1e2430;
  --line-soft: #171c26;

  --ink:       #dfe4ed;
  --ink-dim:   #a9b2c1;
  --muted:     #788294;
  --faint:     #545d6d;

  /* два происхождения — равновесные, не иерархия.
     Эти два цвета не используются больше НИГДЕ: цвет свода означает
     только свод, иначе получается второй смысл у того же оттенка. */
  --project:     #f37934;
  --project-dim: #5e341e;
  --project-wash:#241a12;
  --server:      #2ecc71;
  --server-dim:  #1a5238;
  --server-wash: #101f18;

  /* нейтральный акцент интерфейса: фокус, активный пункт, подсветка поиска */
  --focus:       #6f9dff;
  --focus-dim:   #2b3d63;
  --focus-wash:  #131a2b;

  --sanction:    #e2647a;
  --sanction-wash:#231118;

  --mono: ui-monospace, "JetBrains Mono", "SFMono-Regular", "Cascadia Mono", Menlo, Consolas, monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  --rail-w: 17rem;
  --toc-w: 15rem;
  --top-h: 3.5rem;
  --gutter: 5rem;

  --r-sm: 4px;
  --r-md: 7px;
}

*, *::before, *::after { box-sizing: border-box; }

html { scrollbar-color: #2a3140 var(--bg); }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 15px/1.62 var(--sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

.skip {
  position: absolute; left: -9999px; top: 0; z-index: 100;
  background: var(--focus); color: #08131f; padding: .6rem 1rem;
  font-weight: 600; border-radius: 0 0 var(--r-md) 0;
}
.skip:focus { left: 0; }

/* ─────────────────────────────────────────────── шапка */

.top {
  position: sticky; top: 0; z-index: 40;
  height: var(--top-h);
  display: flex; align-items: center; gap: 1rem;
  padding: 0 1rem;
  background: color-mix(in srgb, var(--bg-sunk) 88%, transparent);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}

.top__burger {
  display: none;
  flex-direction: column; gap: 4px; justify-content: center;
  width: 34px; height: 34px; padding: 0 7px;
  background: none; border: 1px solid var(--line); border-radius: var(--r-sm);
  cursor: pointer;
}
.top__burger span { display: block; height: 1.5px; background: var(--ink-dim); }

.brand {
  display: flex; align-items: center; gap: .6rem;
  text-decoration: none; color: inherit; flex: none;
}
.brand__mark { display: flex; gap: 3px; }
.brand__mark i { display: block; width: 3px; height: 19px; border-radius: 1px; }
.brand__mark i:first-child { background: var(--project); }
.brand__mark i:last-child  { background: var(--server); }
.brand__text { display: flex; flex-direction: column; line-height: 1.15; }
.brand__text b  { font-size: .9rem; font-weight: 600; letter-spacing: -.01em; }
.brand__text em {
  font: 400 .68rem/1.3 var(--mono); font-style: normal;
  color: var(--faint); letter-spacing: .02em;
}

.find {
  position: relative; flex: 1 1 auto; max-width: 30rem; margin-left: auto;
}
.find__icon {
  position: absolute; left: .65rem; top: 50%; transform: translateY(-50%);
  width: 15px; height: 15px; fill: none; stroke: var(--faint); stroke-width: 1.6;
  stroke-linecap: round; pointer-events: none;
}
#q {
  width: 100%; height: 2.15rem;
  padding: 0 2.2rem 0 2.1rem;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--r-md);
  font: 400 .85rem var(--sans);
}
#q::placeholder { color: var(--faint); }
#q:focus { border-color: var(--focus-dim); background: var(--surface-2); }
#q::-webkit-search-cancel-button { filter: invert(.6); }
.find__hint {
  position: absolute; right: .5rem; top: 50%; transform: translateY(-50%);
  font: 400 .7rem var(--mono); color: var(--faint);
  border: 1px solid var(--line); border-radius: 3px; padding: 1px 5px;
  pointer-events: none;
}
.find:focus-within .find__hint { display: none; }

.svodfilter { display: flex; gap: 0; flex: none; border: 1px solid var(--line); border-radius: var(--r-md); overflow: hidden; }
.svodfilter button {
  background: none; border: 0; cursor: pointer;
  padding: .42rem .7rem;
  font: 500 .74rem var(--mono); color: var(--muted);
  border-right: 1px solid var(--line);
}
.svodfilter button:last-child { border-right: 0; }
.svodfilter button:hover { color: var(--ink-dim); background: var(--surface); }
.svodfilter button.is-on { color: var(--ink); background: var(--surface-2); }
.svodfilter button[data-svod="project"].is-on { color: var(--project); }
.svodfilter button[data-svod="server"].is-on  { color: var(--server); }

/* ─────────────────────────────────────────────── каркас */

.shell {
  display: grid;
  grid-template-columns: var(--rail-w) minmax(0, 1fr) var(--toc-w);
  align-items: start;
}

/* ─────────────────────────────────────────────── каталог */

.rail {
  position: sticky; top: var(--top-h);
  height: calc(100vh - var(--top-h));
  overflow-y: auto; overscroll-behavior: contain;
  padding: 1.4rem .75rem 3rem 1.1rem;
  border-right: 1px solid var(--line);
}
.rail__cat {
  margin: 1.5rem 0 .4rem;
  font: 500 .66rem var(--mono); letter-spacing: .09em; text-transform: uppercase;
  color: var(--faint);
}
.rail__cat:first-child { margin-top: 0; }

.rail a {
  display: flex; align-items: baseline; gap: .5rem;
  padding: .3rem .55rem; margin-left: -.55rem;
  border-radius: var(--r-sm);
  color: var(--ink-dim); text-decoration: none;
  font-size: .845rem; line-height: 1.4;
}
.rail a:hover { background: var(--surface); color: var(--ink); }
.rail a[aria-current="page"] {
  background: var(--surface-2); color: var(--ink); font-weight: 500;
  box-shadow: inset 2px 0 0 var(--focus);
}
.rail a span { flex: 1 1 auto; }
.rail__flags { flex: none; display: flex; gap: 2px; padding-top: .35em; }
.rail__flags i { width: 3px; height: 3px; border-radius: 50%; display: block; }
.rail__flags i.p { background: var(--project); }
.rail__flags i.s { background: var(--server); }

.rail__scrim { display: none; }

/* ─────────────────────────────────────────────── основное поле */

main {
  min-width: 0;
  padding: 2.2rem 2.6rem 6rem;
}
main:focus { outline: none; }

.page-head { margin-bottom: 2.2rem; }
.page-head__eyebrow {
  font: 500 .66rem var(--mono); letter-spacing: .09em; text-transform: uppercase;
  color: var(--faint); margin-bottom: .5rem;
}
.page-head h1 {
  margin: 0 0 .7rem;
  font-size: 1.62rem; font-weight: 600; letter-spacing: -.02em;
  text-wrap: balance;
}
.page-head__meta {
  display: flex; flex-wrap: wrap; gap: .4rem .5rem; align-items: center;
  font: 400 .72rem var(--mono); color: var(--muted);
}

.srcpill {
  display: inline-flex; align-items: center; gap: .38rem;
  padding: .16rem .5rem; border-radius: 20px;
  border: 1px solid var(--line); background: var(--surface);
  font: 500 .69rem var(--mono); color: var(--ink-dim);
}
.srcpill::before { content: ""; width: 5px; height: 5px; border-radius: 50%; }
.srcpill--p::before { background: var(--project); }
.srcpill--s::before { background: var(--server); }
.srcpill--missing { color: var(--faint); border-style: dashed; }
.srcpill--missing::before { background: var(--faint); }

/* раздел */
.sec { margin: 2.6rem 0 0; }
.sec:first-of-type { margin-top: 0; }
.sec__head {
  display: flex; align-items: baseline; gap: .7rem;
  padding-bottom: .55rem; margin-bottom: 1.3rem;
  border-bottom: 1px solid var(--line);
}
.sec__head h2 {
  margin: 0; font-size: 1.02rem; font-weight: 600; letter-spacing: -.01em;
  text-wrap: balance;
}
.sec__only {
  font: 500 .64rem var(--mono); letter-spacing: .05em; text-transform: uppercase;
  padding: .1rem .4rem; border-radius: 3px; white-space: nowrap;
}
.sec__only--p { color: var(--project); background: var(--project-wash); }
.sec__only--s { color: var(--server);  background: var(--server-wash); }

.sec__pre {
  margin: 0 0 1.4rem var(--gutter);
  padding-left: 1.25rem;
  color: var(--ink-dim); font-size: .9rem;
}
.sec__pre p { margin: .35rem 0; }

/* ─────────────────────────────────────────────── пункт */

.rule {
  display: grid;
  grid-template-columns: var(--gutter) minmax(0, 1fr);
  column-gap: 1.25rem;
  padding: .55rem 0 .75rem;
  scroll-margin-top: calc(var(--top-h) + 1rem);
}
.rule + .rule { border-top: 1px solid var(--line-soft); }
.rule.is-flash .rule__body {
  background: var(--focus-wash);
  box-shadow: 0 0 0 6px var(--focus-wash);
  border-radius: var(--r-sm);
  transition: background .5s ease, box-shadow .5s ease;
}

/* жёлоб: номер на полях + «корешок» цвета свода */
.rule__gutter {
  display: flex; flex-direction: column; align-items: flex-end; gap: .3rem;
  padding-right: .8rem; border-right: 2px solid var(--line);
  text-align: right;
}
.rule--p .rule__gutter { border-right-color: var(--project-dim); }
.rule--s .rule__gutter { border-right-color: var(--server-dim); }

/* номер — кнопка: клик копирует цитату */
.rule__num {
  background: none; border: 0; padding: 0; cursor: pointer;
  font: 500 .86rem var(--mono); font-variant-numeric: tabular-nums;
  letter-spacing: -.01em;
}
.rule--p .rule__num { color: var(--project); }
.rule--s .rule__num { color: var(--server); }
.rule__num:hover { text-decoration: underline; text-underline-offset: 3px; }
.rule__num:active { opacity: .6; }

.rule__src {
  font: 400 .61rem/1.25 var(--mono); letter-spacing: .03em;
  color: var(--faint); text-transform: uppercase;
}

/* одна норма в двух сводах: проект сверху, сервер под ним, общая обводка */
.pair {
  margin: .6rem 0;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: color-mix(in srgb, var(--surface) 45%, transparent);
}
.pair .rule { padding: .6rem .9rem .7rem 0; }
.pair .rule + .rule { border-top: 1px dashed var(--line); }
.rule + .pair, .pair + .rule { border-top: 0; }

.rule__body { min-width: 0; }
.rule__text { margin: 0; }
.rule__text mark { background: color-mix(in srgb, var(--focus) 30%, transparent); color: var(--ink); border-radius: 2px; }

/* санкция — блок, а не инлайн: иначе прилипает к тексту в подпунктах */
.sanction {
  display: flex; align-items: flex-start; gap: .45rem;
  width: fit-content; max-width: 100%;
  margin: .6rem 0 .15rem; padding: .3rem .6rem .32rem;
  background: var(--sanction-wash); border-left: 2px solid var(--sanction);
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
  font: 400 .795rem/1.45 var(--mono); color: #f0a8b6;
}
.sanction::before {
  content: "нак."; flex: none;
  font-size: .61rem; letter-spacing: .06em; text-transform: uppercase;
  color: var(--sanction); padding-top: .18em;
}

/* подпункты */
.subs { margin: .55rem 0 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: .34rem; }
.sub { font-size: .885rem; color: var(--ink-dim); }
.sub__kind {
  font: 500 .63rem var(--mono); letter-spacing: .05em; text-transform: uppercase;
  color: var(--muted); margin-right: .45rem;
}
.sub--bullet { padding-left: 1rem; position: relative; }
.sub--bullet::before {
  content: ""; position: absolute; left: .15rem; top: .68em;
  width: 4px; height: 1px; background: var(--faint);
}
/* Исключение выделено весом и рамкой, НЕ цветом: синий и охра заняты
   под происхождение пункта, и третий смысл у тех же оттенков путает. */
.sub--exc {
  padding: .3rem .7rem .32rem .75rem;
  border-left: 2px solid var(--faint);
  background: color-mix(in srgb, var(--surface) 65%, transparent);
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
  color: var(--ink);
}
.sub--exc .sub__kind { color: var(--ink); font-weight: 600; }

/* «Примечания:» перед перечнем — подзаголовок, а не пункт */
.sub--label {
  margin-top: .2rem;
  font: 600 .64rem var(--mono); letter-spacing: .06em; text-transform: uppercase;
  color: var(--muted);
}
.sub--label .sub__kind { margin: 0; color: inherit; font-size: inherit; font-weight: inherit; }

.sub--lvl2 { margin-left: 1.1rem; }
.sub--lvl3 { margin-left: 2.2rem; }
.sub .sanction { margin: .4rem 0 .15rem; font-size: .74rem; }

/* подтверждение копирования цитаты */
.toast {
  position: fixed; left: 50%; bottom: 1.5rem; z-index: 60;
  transform: translate(-50%, .6rem);
  max-width: min(90vw, 36rem);
  padding: .55rem .9rem;
  background: var(--surface-2); color: var(--ink);
  border: 1px solid #2a3141; border-radius: var(--r-md);
  box-shadow: 0 10px 30px #000a;
  font: 400 .78rem/1.4 var(--mono);
  opacity: 0; pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
}
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }

/* ─────────────────────────────────────────────── оглавление справа */

.toc {
  position: sticky; top: var(--top-h);
  height: calc(100vh - var(--top-h));
  overflow-y: auto; overscroll-behavior: contain;
  padding: 2.2rem 1.2rem 3rem .3rem;
}
.toc__title {
  font: 500 .66rem var(--mono); letter-spacing: .09em; text-transform: uppercase;
  color: var(--faint); margin-bottom: .7rem;
}
.toc a {
  display: block; padding: .22rem 0 .22rem .7rem;
  border-left: 1px solid var(--line);
  color: var(--muted); text-decoration: none; font-size: .78rem; line-height: 1.45;
}
.toc a:hover { color: var(--ink-dim); border-left-color: var(--faint); }
.toc a.is-here { color: var(--ink); border-left-color: var(--focus); }

/* ─────────────────────────────────────────────── стартовая */

.home__lead {
  max-width: 34rem; color: var(--ink-dim); font-size: .95rem;
  margin: 0 0 2rem;
}
.stats { display: flex; flex-wrap: wrap; gap: 2rem; margin: 0 0 2.6rem; padding: 0; list-style: none; }
.stats div { display: flex; flex-direction: column; gap: .15rem; }
.stats b {
  font: 500 1.55rem/1 var(--mono); font-variant-numeric: tabular-nums;
  letter-spacing: -.02em; color: var(--ink);
}
.stats span { font: 400 .69rem var(--mono); letter-spacing: .05em; text-transform: uppercase; color: var(--faint); }
.stats div:nth-child(2) b { color: var(--project); }
.stats div:nth-child(3) b { color: var(--server); }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); gap: .55rem; }
.cards a {
  display: flex; flex-direction: column; gap: .3rem;
  padding: .8rem .9rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md);
  text-decoration: none; color: var(--ink);
}
.cards a:hover { background: var(--surface-2); border-color: #2a3141; }
.cards b { font-size: .875rem; font-weight: 500; line-height: 1.35; }
.cards em {
  font: 400 .67rem var(--mono); font-style: normal; color: var(--faint);
  letter-spacing: .03em;
}

/* ─────────────────────────────────────────────── поиск */

.results {
  position: fixed; inset: var(--top-h) 0 0; z-index: 35;
  background: color-mix(in srgb, var(--bg) 97%, transparent);
  overflow-y: auto; padding: 1.4rem clamp(1rem, 6vw, 5rem) 4rem;
}
.results__head {
  font: 400 .74rem var(--mono); color: var(--muted); margin-bottom: 1rem;
}
.results__list { display: flex; flex-direction: column; gap: .3rem; max-width: 58rem; }
.hit {
  display: grid; grid-template-columns: 8.5rem minmax(0, 1fr); gap: .9rem;
  padding: .6rem .8rem; border-radius: var(--r-md);
  border: 1px solid transparent;
  text-decoration: none; color: var(--ink);
}
.hit:hover, .hit:focus-visible { background: var(--surface); border-color: var(--line); }
.hit__meta { display: flex; flex-direction: column; gap: .15rem; text-align: right; }
.hit__num { font: 500 .8rem var(--mono); font-variant-numeric: tabular-nums; }
.hit--p .hit__num { color: var(--project); }
.hit--s .hit__num { color: var(--server); }
.hit__topic { font: 400 .65rem/1.3 var(--mono); color: var(--faint); }
.hit__text { font-size: .865rem; color: var(--ink-dim); }
.hit__text mark { background: color-mix(in srgb, var(--focus) 30%, transparent); color: var(--ink); border-radius: 2px; }
.results__empty { color: var(--muted); font-size: .9rem; }

/* ─────────────────────────────────────────────── адаптив */

@media (max-width: 1180px) {
  .shell { grid-template-columns: var(--rail-w) minmax(0, 1fr); }
  .toc { display: none; }
  main { padding: 2rem 2rem 5rem; }
}

@media (max-width: 860px) {
  :root { --gutter: 3.6rem; }
  .shell { grid-template-columns: minmax(0, 1fr); }
  .top__burger { display: flex; }
  .brand__text em { display: none; }
  .svodfilter button { padding: .42rem .55rem; font-size: .7rem; }

  .rail {
    position: fixed; top: var(--top-h); left: 0; z-index: 45;
    width: min(20rem, 84vw); height: calc(100vh - var(--top-h));
    background: var(--bg-sunk);
    transform: translateX(-102%); transition: transform .22s ease;
  }
  .rail.is-open { transform: none; }
  .rail__scrim { display: block; position: fixed; inset: var(--top-h) 0 0; z-index: 44; background: #000a; }
  .rail__scrim[hidden] { display: none; }

  main { padding: 1.5rem 1.1rem 5rem; }
  .hit { grid-template-columns: minmax(0, 1fr); gap: .25rem; }
  .hit__meta { flex-direction: row; gap: .6rem; text-align: left; align-items: baseline; }
}

@media (max-width: 560px) {
  .find__hint { display: none; }
  .rule { grid-template-columns: minmax(0, 1fr); row-gap: .3rem; }
  .rule__gutter {
    flex-direction: row; align-items: baseline; gap: .55rem;
    padding: 0 0 0 .7rem; text-align: left;
    border-right: 0; border-left: 2px solid var(--line);
  }
  .rule--p .rule__gutter { border-left-color: var(--project-dim); }
  .rule--s .rule__gutter { border-left-color: var(--server-dim); }
  .pair .rule { padding: .6rem .7rem .7rem .7rem; }
  .sec__pre { margin-left: 0; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

@media print {
  .top, .rail, .toc, .results, .skip { display: none !important; }
  .shell { grid-template-columns: 1fr; }
  body { background: #fff; color: #000; }
}
