/* ==========================================================================
   Вики «Русь Мобайл» — оформление справочника
   ========================================================================== */

:root {
  --bg: #faf8f5;
  --surface: #ffffff;
  --surface-2: #f4f0ea;
  --text: #1b1613;
  --text-muted: #6d635b;
  --text-soft: #8c817a;
  --border: #e7e0d7;
  --border-strong: #d6cdc1;
  --accent: #b3312d;
  --accent-hover: #8f2723;
  --accent-weak: #fdf1ef;
  --accent-contrast: #ffffff;
  --note-bg: #f2f6fb;
  --note-border: #b9d0e8;
  --note-text: #23415e;
  --warn-bg: #fdf5e8;
  --warn-border: #e8c98d;
  --warn-text: #6b4c14;
  --shadow-sm: 0 1px 2px rgba(27, 22, 19, .06), 0 1px 3px rgba(27, 22, 19, .05);
  --shadow-md: 0 4px 12px rgba(27, 22, 19, .08), 0 2px 4px rgba(27, 22, 19, .04);
  --radius: 12px;
  --radius-sm: 8px;
  --topbar-h: 60px;
  --maxw: 1240px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14110f;
    --surface: #1c1917;
    --surface-2: #241f1c;
    --text: #f2ede8;
    --text-muted: #a79d95;
    --text-soft: #8b817a;
    --border: #2d2724;
    --border-strong: #3d3531;
    --accent: #e26b66;
    --accent-hover: #ef8681;
    --accent-weak: #2c1c1a;
    --accent-contrast: #17110f;
    --note-bg: #16202b;
    --note-border: #2c4864;
    --note-text: #b8d4ef;
    --warn-bg: #251d10;
    --warn-border: #5a441d;
    --warn-text: #e9c98b;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-md: 0 4px 14px rgba(0, 0, 0, .45);
  }
}

:root[data-theme="dark"] {
  --bg: #14110f;
  --surface: #1c1917;
  --surface-2: #241f1c;
  --text: #f2ede8;
  --text-muted: #a79d95;
  --text-soft: #8b817a;
  --border: #2d2724;
  --border-strong: #3d3531;
  --accent: #e26b66;
  --accent-hover: #ef8681;
  --accent-weak: #2c1c1a;
  --accent-contrast: #17110f;
  --note-bg: #16202b;
  --note-border: #2c4864;
  --note-text: #b8d4ef;
  --warn-bg: #251d10;
  --warn-border: #5a441d;
  --warn-text: #e9c98b;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, .45);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }

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

.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 100;
  background: var(--accent); color: var(--accent-contrast);
  padding: 10px 16px; border-radius: 0 0 var(--radius-sm) 0;
}
.skip-link:focus { left: 0; }

/* ---------------------------------------------------------------- topbar */

.topbar {
  position: sticky; top: 0; z-index: 40;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar__inner {
  max-width: var(--maxw);
  margin: 0 auto;
  height: var(--topbar-h);
  padding: 0 16px;
  display: flex; align-items: center; gap: 12px;
}

.topbar__burger {
  display: none;
  width: 40px; height: 40px;
  flex: 0 0 40px;
  background: none; border: 0; padding: 9px 8px;
  flex-direction: column; justify-content: space-between;
  cursor: pointer; border-radius: var(--radius-sm);
}
.topbar__burger span {
  display: block; height: 2px; width: 100%;
  background: var(--text); border-radius: 2px;
  transition: transform .18s ease, opacity .18s ease;
}
.topbar__burger[aria-expanded="true"] span:nth-child(1) { transform: translateY(9px) rotate(45deg); }
.topbar__burger[aria-expanded="true"] span:nth-child(2) { opacity: 0; }
.topbar__burger[aria-expanded="true"] span:nth-child(3) { transform: translateY(-9px) rotate(-45deg); }

.brand { display: flex; align-items: center; gap: 10px; flex: 0 0 auto; }
.brand:hover { text-decoration: none; }

.brand__mark {
  width: auto; height: 30px; flex: 0 0 auto;
  display: block;
  /* Логотип светлый и на светлом фоне теряется — подкладываем тёмную плашку. */
  padding: 5px 9px;
  background: #221c17;
  border-radius: 9px;
  box-sizing: content-box;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .brand__mark { background: transparent; padding: 5px 0; }
}
:root[data-theme="dark"] .brand__mark { background: transparent; padding: 5px 0; }

.brand__text { display: flex; flex-direction: column; line-height: 1.2; }
.brand__title { color: var(--text); font-weight: 650; font-size: 15px; }
.brand__sub { color: var(--text-soft); font-size: 12px; }

.search {
  position: relative;
  margin-left: auto;
  flex: 1 1 420px;
  max-width: 460px;
}

.search__icon {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  width: 17px; height: 17px; pointer-events: none;
  fill: none; stroke: var(--text-soft); stroke-width: 2; stroke-linecap: round;
}

.search__input {
  width: 100%; height: 40px;
  padding: 0 36px 0 36px;
  font: inherit; font-size: 15px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: 20px;
  transition: border-color .15s ease, background .15s ease;
}
.search__input::placeholder { color: var(--text-soft); }
.search__input:focus {
  background: var(--surface);
  border-color: var(--accent);
  outline: none;
}

.search__clear {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  width: 28px; height: 28px;
  border: 0; border-radius: 50%;
  background: none; color: var(--text-muted);
  font-size: 20px; line-height: 1; cursor: pointer;
}
.search__clear:hover { background: var(--surface-2); color: var(--text); }

/* ---------------------------------------------------------------- layout */

.layout {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 16px;
  display: grid;
  grid-template-columns: 244px minmax(0, 1fr);
  gap: 36px;
  align-items: start;
}

.sidenav {
  position: sticky;
  top: calc(var(--topbar-h) + 20px);
  max-height: calc(100vh - var(--topbar-h) - 40px);
  padding: 24px 0;
}
.sidenav__scroll { overflow-y: auto; max-height: calc(100vh - var(--topbar-h) - 64px); }
.sidenav__backdrop { display: none; }

.sidenav__title {
  font-size: 11px; font-weight: 700;
  letter-spacing: .09em; text-transform: uppercase;
  color: var(--text-soft);
  margin: 0 0 10px 12px;
}

.sidenav__list { list-style: none; margin: 0 0 22px; padding: 0; }

.sidenav__link {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 14.5px;
  line-height: 1.35;
}
.sidenav__link:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.sidenav__link[aria-current="page"] {
  background: var(--accent-weak); color: var(--accent); font-weight: 600;
}
.sidenav__emoji { font-size: 15px; width: 20px; text-align: center; flex: 0 0 20px; }

.main { padding: 28px 0 64px; min-width: 0; }

/* ---------------------------------------------------------------- shared */

.crumbs {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  font-size: 13.5px; color: var(--text-soft);
  margin-bottom: 14px;
}
.crumbs a { color: var(--text-muted); }
.crumbs span[aria-hidden] { color: var(--border-strong); }

.page-title {
  margin: 0 0 10px;
  font-size: 32px; line-height: 1.2; font-weight: 700;
  letter-spacing: -.015em;
}

.page-lead {
  margin: 0 0 28px;
  font-size: 17px; color: var(--text-muted); max-width: 68ch;
}

.section-title {
  margin: 40px 0 16px;
  font-size: 13px; font-weight: 700;
  letter-spacing: .08em; text-transform: uppercase;
  color: var(--text-soft);
}
.section-title:first-child { margin-top: 0; }

/* ------------------------------------------------------------------ home */

.hero {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  margin-bottom: 40px;
  box-shadow: var(--shadow-sm);
}
.hero h1 { margin: 0 0 10px; font-size: 30px; line-height: 1.2; letter-spacing: -.015em; }
.hero p { margin: 0; color: var(--text-muted); max-width: 66ch; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 22px; }
.chip {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 7px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 14px; color: var(--text);
}
.chip:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }

.cat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(248px, 1fr));
  gap: 14px;
}

.cat-card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  color: var(--text);
  transition: border-color .15s ease, transform .15s ease, box-shadow .15s ease;
}
.cat-card:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
  text-decoration: none;
}
.cat-card__emoji { font-size: 22px; line-height: 1; display: block; margin-bottom: 10px; }
.cat-card__title { font-weight: 650; font-size: 16px; margin-bottom: 4px; }
.cat-card__desc { font-size: 13.5px; color: var(--text-muted); line-height: 1.5; }
.cat-card__count { font-size: 12.5px; color: var(--text-soft); margin-top: 10px; }

/* --------------------------------------------------------- article lists */

.art-list { list-style: none; margin: 0; padding: 0; }

.art-list__item + .art-list__item { border-top: 1px solid var(--border); }

.art-list__link {
  display: block;
  padding: 15px 4px;
  color: var(--text);
}
.art-list__link:hover { text-decoration: none; }
.art-list__link:hover .art-list__title { color: var(--accent); }

.art-list__title { font-weight: 600; font-size: 16px; margin-bottom: 3px; }
.art-list__summary { font-size: 14px; color: var(--text-muted); line-height: 1.5; }
.art-list__cat { font-size: 12.5px; color: var(--text-soft); margin-top: 5px; }

/* ------------------------------------------------------------- article */

.article { max-width: 74ch; }

.article h2 {
  margin: 38px 0 12px;
  font-size: 21px; line-height: 1.3; font-weight: 670;
  letter-spacing: -.01em;
  scroll-margin-top: calc(var(--topbar-h) + 16px);
}
.article h2:first-of-type { margin-top: 30px; }

.article p { margin: 0 0 14px; }

.article ul, .article ol { margin: 0 0 16px; padding-left: 22px; }
.article li { margin-bottom: 7px; }
.article li:last-child { margin-bottom: 0; }

.article code {
  font-family: var(--mono);
  font-size: .89em;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 5px;
  white-space: nowrap;
}

.steps { list-style: none; counter-reset: step; padding-left: 0; }
.steps li {
  counter-increment: step;
  position: relative;
  padding-left: 38px;
  margin-bottom: 12px;
}
.steps li::before {
  content: counter(step);
  position: absolute; left: 0; top: 1px;
  width: 25px; height: 25px;
  display: grid; place-items: center;
  background: var(--accent-weak); color: var(--accent);
  border-radius: 50%;
  font-size: 13px; font-weight: 700; line-height: 1;
}

.callout {
  margin: 0 0 18px;
  padding: 13px 16px;
  border-radius: var(--radius-sm);
  border-left: 3px solid;
  font-size: 15px;
}
.callout p:last-child { margin-bottom: 0; }
.callout--note { background: var(--note-bg); border-color: var(--note-border); color: var(--note-text); }
.callout--warn { background: var(--warn-bg); border-color: var(--warn-border); color: var(--warn-text); }
.callout__label { font-weight: 700; }

.table-wrap { overflow-x: auto; margin: 0 0 18px; -webkit-overflow-scrolling: touch; }

.article table {
  border-collapse: collapse;
  width: 100%;
  min-width: 380px;
  font-size: 14.5px;
}
.article th, .article td {
  text-align: left;
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.article th {
  background: var(--surface-2);
  font-weight: 650;
  font-size: 13px;
  letter-spacing: .01em;
  white-space: nowrap;
}
.article tbody tr:last-child td { border-bottom: 0; }
.article table { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }

.cmd-table td:first-child { white-space: nowrap; }
.cmd-table code { background: var(--accent-weak); border-color: transparent; color: var(--accent); font-weight: 600; }

.related {
  margin-top: 44px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}
.related h2 { margin: 0 0 12px; font-size: 15px; letter-spacing: .02em; }
.related__list { display: flex; flex-wrap: wrap; gap: 8px; list-style: none; margin: 0; padding: 0; }

/* --------------------------------------------------------------- search */

.search-meta { color: var(--text-muted); font-size: 14.5px; margin-bottom: 20px; }
mark { background: var(--accent-weak); color: inherit; padding: 0 2px; border-radius: 3px; font-weight: 600; }

.empty {
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 40px 24px;
  text-align: center;
  color: var(--text-muted);
}
.empty strong { display: block; color: var(--text); font-size: 17px; margin-bottom: 6px; }

/* --------------------------------------------------------------- footer */

.footer {
  border-top: 1px solid var(--border);
  background: var(--surface);
  margin-top: 40px;
}
.footer__inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 26px 16px;
  color: var(--text-soft);
  font-size: 13.5px;
}
.footer__inner p { margin: 0 0 6px; }

/* --------------------------------------------------------------- mobile */

@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); gap: 0; }

  .topbar__burger { display: flex; }

  .brand__sub { display: none; }

  .sidenav {
    position: fixed;
    top: var(--topbar-h); left: 0; bottom: 0;
    width: 286px; max-width: 84vw;
    max-height: none;
    z-index: 45;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 20px 12px calc(20px + env(safe-area-inset-bottom));
    transform: translateX(-100%);
    transition: transform .22s ease;
    overflow-y: auto;
  }
  .sidenav.is-open { transform: translateX(0); }
  .sidenav__scroll { max-height: none; overflow: visible; }

  .sidenav__backdrop {
    display: block;
    position: fixed; inset: var(--topbar-h) 0 0;
    background: rgba(0, 0, 0, .42);
    z-index: 44;
  }
  .sidenav__backdrop[hidden] { display: none; }

  .main { padding: 20px 0 48px; }
  .hero { padding: 22px; margin-bottom: 30px; }
  .hero h1 { font-size: 24px; }
  .page-title { font-size: 25px; }
  .page-lead { font-size: 16px; margin-bottom: 22px; }
  .article h2 { font-size: 19px; margin-top: 30px; }
  .cat-grid { grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; }
}

@media (max-width: 620px) {
  .topbar__inner { gap: 8px; padding: 0 12px; }
  .brand__text { display: none; }
  .layout, .footer__inner { padding-left: 12px; padding-right: 12px; }
  .search { flex-basis: auto; }
  .cat-grid { grid-template-columns: 1fr; }
  .page-title { font-size: 23px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ---------------------------------------------------------------- print */

@media print {
  .topbar, .sidenav, .footer, .crumbs, .related, .skip-link { display: none !important; }
  .layout { display: block; padding: 0; }
  .article { max-width: none; }
  body { background: #fff; color: #000; font-size: 12pt; }
  .callout { border: 1px solid #999; }
}
