/* ============================================================
   Социокультурное пространство v.3.02 — academic reading style
   ============================================================ */

:root {
  --bg: #faf8f3;
  --bg-elev: #f2efe6;
  --bg-code: #ede9dd;
  --text: #2d2d2d;
  --text-muted: #5a5750;
  --text-faint: #8a8680;
  --border: #e2ddce;
  --accent: #8a3324;
  --accent-hover: #b0452f;
  --link: #1a5e8c;
  --link-visited: #6a3d8a;
  --shadow: 0 1px 3px rgba(0,0,0,.06);
  --shadow-lg: 0 10px 40px rgba(0,0,0,.18);
  --maxw: 720px;
  --sidebar-w: 300px;
  --font-serif: "Merriweather", "PT Serif", Georgia, "Times New Roman", serif;
  --font-sans: "Inter", "PT Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

[data-theme="dark"] {
  --bg: #1b1b1e;
  --bg-elev: #25252a;
  --bg-code: #2c2c31;
  --text: #d9d6cf;
  --text-muted: #a6a39b;
  --text-faint: #77746e;
  --border: #35353b;
  --accent: #d9886e;
  --accent-hover: #eaa88e;
  --link: #82b8de;
  --link-visited: #b79bd8;
  --shadow: 0 1px 3px rgba(0,0,0,.45);
  --shadow-lg: 0 12px 48px rgba(0,0,0,.6);
}

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

html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-serif);
  font-size: clamp(16px, 1.05vw + 13.5px, 19px);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* ---------- Progress bar ---------- */
.read-progress {
  position: fixed; top: 0; left: 0; right: 0; height: 3px;
  background: transparent; z-index: 200; pointer-events: none;
}
.read-progress > span {
  display: block; height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-hover));
  transition: width .08s linear;
}

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 150;
  display: flex; align-items: center; gap: .75rem;
  padding: .6rem clamp(1rem, 3vw, 2rem);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(140%) blur(8px);
  -webkit-backdrop-filter: saturate(140%) blur(8px);
  border-bottom: 1px solid var(--border);
  font-family: var(--font-sans);
  font-size: .92rem;
}
.topbar a.home {
  display: inline-flex; align-items: center; gap: .35rem;
  color: var(--text); text-decoration: none; font-weight: 600;
  padding: .35rem .55rem; border-radius: 6px;
}
.topbar a.home:hover { background: var(--bg-elev); color: var(--accent); }
.topbar .brand { color: var(--text-muted); font-weight: 500; }
.topbar .spacer { flex: 1; }

.btn {
  font-family: var(--font-sans); font-size: .88rem; font-weight: 500;
  background: var(--bg-elev); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: .45rem .8rem; cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; gap: .4rem;
  transition: background .15s, border-color .15s, color .15s;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn-ghost { background: transparent; }
.icon-btn { width: 2.2rem; height: 2.2rem; padding: 0; justify-content: center; }

/* ---------- Layout ---------- */
.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  max-width: 1280px; margin: 0 auto;
  gap: 2.5rem;
  padding: 0 clamp(1rem, 3vw, 2rem);
}

/* ---------- Sidebar ---------- */
.sidebar {
  position: sticky; top: 64px;
  align-self: start;
  max-height: calc(100vh - 80px);
  overflow-y: auto;
  padding: 1.5rem .25rem 3rem 0;
  font-family: var(--font-sans);
  font-size: .86rem;
  border-right: 1px solid var(--border);
  scrollbar-width: thin;
}
.sidebar h2 {
  font-size: .72rem; letter-spacing: .08em; text-transform: uppercase;
  color: var(--text-faint); margin: 1.4rem 0 .5rem;
}
.sidebar nav ul { list-style: none; margin: 0; padding: 0; }
.sidebar nav li { margin: 0; }
.sidebar nav a {
  display: block; padding: .32rem .6rem .32rem .9rem;
  color: var(--text-muted); text-decoration: none;
  border-left: 2px solid transparent; border-radius: 0 4px 4px 0;
  line-height: 1.35;
}
.sidebar nav a:hover { color: var(--text); background: var(--bg-elev); }
.sidebar nav a.active {
  color: var(--accent); border-left-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  font-weight: 600;
}
.sidebar nav ul ul a { padding-left: 1.6rem; font-size: .82rem; }
.sidebar nav ul ul ul a { padding-left: 2.3rem; }

/* ---------- Article ---------- */
main { min-width: 0; padding: 2rem 0 6rem; }
.article {
  max-width: var(--maxw);
  margin: 0 auto;
}

/* Title block */
.article-header { margin: 2rem 0 3rem; padding-bottom: 2rem; border-bottom: 1px solid var(--border); }
.article-header .kicker {
  font-family: var(--font-sans); font-size: .82rem; letter-spacing: .08em;
  text-transform: uppercase; color: var(--accent); font-weight: 600; margin-bottom: .6rem;
}
.article-header h1 {
  font-family: var(--font-sans); font-weight: 700;
  font-size: clamp(1.5rem, 2.4vw + 1rem, 2.3rem);
  line-height: 1.2; margin: 0 0 .9rem; color: var(--text);
  letter-spacing: -.01em;
}
.article-header .meta {
  font-family: var(--font-sans); font-size: .9rem; color: var(--text-muted);
  line-height: 1.6;
}
.article-header .meta strong { color: var(--text); font-weight: 600; }

/* DOI / citation */
.doi-line {
  font-family: var(--font-sans); font-size: .88rem; color: var(--text-muted);
  margin-top: .6rem;
}
.doi-line a { color: var(--link); word-break: break-all; }

/* Citation tool */
.citation {
  margin: 1.5rem 0; padding: 1rem 1.15rem;
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: 10px;
  font-family: var(--font-sans); font-size: .88rem; color: var(--text-muted);
}
.citation summary {
  cursor: pointer; font-weight: 600; color: var(--text); list-style: none;
  display: flex; align-items: center; gap: .5rem;
}
.citation summary::-webkit-details-marker { display: none; }
.citation summary::before { content: "▸"; color: var(--accent); transition: transform .15s; }
.citation[open] summary::before { transform: rotate(90deg); }
.citation-body { margin-top: .8rem; line-height: 1.6; color: var(--text); }
.citation-body code {
  display: block; padding: .7rem .8rem; background: var(--bg-code);
  border-radius: 6px; font-size: .84rem; font-family: ui-monospace, "SF Mono", Menlo, monospace;
  white-space: pre-wrap; word-break: break-word; color: var(--text);
  margin: .6rem 0;
}
.copy-btn { margin-top: .4rem; }

/* Abstract / keywords */
.abstract {
  font-size: .95em; line-height: 1.7;
  padding: 1.2rem 1.4rem; margin: 1.5rem 0 2rem;
  background: var(--bg-elev); border-left: 3px solid var(--accent); border-radius: 0 8px 8px 0;
}
.abstract h2 {
  font-family: var(--font-sans); font-size: .82rem; letter-spacing: .08em;
  text-transform: uppercase; color: var(--text-faint); margin: 0 0 .6rem;
}
.keywords { font-size: .9em; color: var(--text-muted); margin-top: .8rem; }
.keywords strong { color: var(--text); }

/* Headings */
h1, h2, h3, h4, h5, h6 { font-family: var(--font-sans); color: var(--text); scroll-margin-top: 80px; }
.article h2 {
  font-size: clamp(1.3rem, 1.5vw + 1rem, 1.7rem); font-weight: 700;
  line-height: 1.25; margin: 3rem 0 1rem; letter-spacing: -.005em;
  padding-bottom: .4rem; border-bottom: 1px solid var(--border);
}
.article h3 {
  font-size: clamp(1.12rem, .8vw + 1rem, 1.3rem); font-weight: 600;
  line-height: 1.3; margin: 2.2rem 0 .8rem;
}
.article h4 {
  font-size: 1.05rem; font-weight: 600; margin: 1.8rem 0 .6rem;
}
.article h5 { font-size: .98rem; font-weight: 600; margin: 1.4rem 0 .4rem; color: var(--text-muted); }

/* Paragraphs, lists */
.article p { margin: 0 0 1.1em; hyphens: auto; -webkit-hyphens: auto; overflow-wrap: break-word; }
.article ul, .article ol { margin: 0 0 1.2em; padding-left: 1.6em; }
.article li { margin: .35em 0; }
.article li > p { margin: 0 0 .5em; }
.article strong { font-weight: 700; }
.article em { font-style: italic; }

/* Links */
.article a { color: var(--link); text-decoration: underline; text-underline-offset: 2px; text-decoration-thickness: 1px; }
.article a:visited { color: var(--link-visited); }
.article a:hover { color: var(--accent); }

/* Footnote / reference links */
.ref-link {
  font-family: var(--font-sans); font-size: .78em; vertical-align: super;
  line-height: 1; text-decoration: none; padding: 0 .1em;
}
.ref-link:hover { text-decoration: underline; }
.backref {
  font-family: var(--font-sans); font-size: .8em; text-decoration: none;
  margin-left: .4em; color: var(--text-faint);
}
.backref:hover { color: var(--accent); }

/* Blockquote */
.article blockquote {
  margin: 1.4em 0; padding: .3em 1.2em;
  border-left: 3px solid var(--border); color: var(--text-muted);
  font-style: italic;
}

/* Tables */
.article table {
  width: 100%; border-collapse: collapse; margin: 1.4em 0;
  font-family: var(--font-sans); font-size: .85em; line-height: 1.5;
  border: 1px solid var(--border);
}
.article th, .article td {
  padding: .6em .7em; text-align: left; vertical-align: top;
  border-bottom: 1px solid var(--border);
}
.article th { background: var(--bg-elev); font-weight: 600; }
.article tr:last-child td { border-bottom: none; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 1.4em 0; }
.table-wrap table { margin: 0; }

/* Code */
.article code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: .88em; background: var(--bg-code); padding: .1em .35em; border-radius: 4px;
}
.article pre {
  background: var(--bg-code); padding: 1em 1.2em; border-radius: 8px;
  overflow-x: auto; font-size: .85em; line-height: 1.5; margin: 1.4em 0;
}
.article pre code { background: none; padding: 0; }

/* Figures */
.figure {
  margin: 2.2rem 0; padding: 0;
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: 10px;
  overflow: hidden;
}
.figure picture, .figure img { display: block; width: 100%; height: auto; }
.figure img { cursor: zoom-in; }
.figure figcaption {
  font-family: var(--font-sans); font-size: .82em; line-height: 1.5;
  color: var(--text-muted); padding: .85rem 1.1rem;
  border-top: 1px solid var(--border); background: var(--bg);
}

/* Lightbox */
.lightbox {
  position: fixed; inset: 0; z-index: 500;
  background: rgba(0,0,0,.88); display: none;
  align-items: center; justify-content: center; padding: 2vmin;
  cursor: zoom-out;
}
.lightbox.open { display: flex; }
.lightbox img {
  max-width: 100%; max-height: 100%; object-fit: contain;
  box-shadow: var(--shadow-lg); background: #fff; border-radius: 4px;
}
.lightbox .close {
  position: absolute; top: 1rem; right: 1rem;
  width: 2.6rem; height: 2.6rem; border-radius: 50%;
  background: rgba(255,255,255,.15); color: #fff; border: none;
  font-size: 1.4rem; cursor: pointer; line-height: 1;
}
.lightbox .close:hover { background: rgba(255,255,255,.3); }

/* Glossary / references */
.glossary dt { font-weight: 700; margin-top: 1em; font-family: var(--font-sans); }
.glossary dd { margin: .2em 0 0 0; }
.ref-list { font-size: .9em; line-height: 1.55; }
.ref-list li { margin-bottom: .7em; scroll-margin-top: 90px; }
.ref-list li:target { background: color-mix(in srgb, var(--accent) 10%, transparent); border-radius: 4px; }

/* Footer */
.article-footer {
  margin-top: 4rem; padding-top: 2rem; border-top: 1px solid var(--border);
  font-family: var(--font-sans); font-size: .85rem; color: var(--text-faint); line-height: 1.6;
}

/* ---------- Mobile ---------- */
.hamburger { display: none; }

@media (max-width: 960px) {
  .layout { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;
    width: min(88vw, 340px); max-height: 100vh;
    background: var(--bg); border-right: 1px solid var(--border);
    padding: 1.2rem 1rem 3rem; z-index: 300;
    transform: translateX(-102%); transition: transform .22s ease;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-close { display: block; margin-bottom: 1rem; }
  .hamburger { display: inline-flex; }
  .scrim {
    position: fixed; inset: 0; background: rgba(0,0,0,.4);
    z-index: 250; display: none;
  }
  .scrim.show { display: block; }
  main { padding-top: 1rem; }
  .article-header { margin-top: 1rem; }
  body { font-size: clamp(16px, 1.6vw + 12px, 18px); }
}
.sidebar-close { display: none; }

@media (max-width: 600px) {
  .topbar { padding: .5rem .8rem; gap: .4rem; }
  .topbar .brand { display: none; }
  .article h2 { margin-top: 2.4rem; }
  .abstract { padding: 1rem 1.1rem; }
}

/* ---------- DOI + PDF button row ---------- */
.meta-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .8rem 1.2rem;
  margin-top: .6rem;
}
.meta-actions .doi-line { margin: 0; }

.btn-pdf {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  font-weight: 600;
  white-space: nowrap;
}
.btn-pdf:hover,
.btn-pdf:focus-visible {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: #fff;
  outline: none;
}
.btn-pdf:focus-visible {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 35%, transparent);
}
.btn-pdf .icon-pdf { flex: 0 0 auto; }

[data-theme="dark"] .btn-pdf { color: #1b1b1e; }

/* ---------- Print ---------- */
@media print {
  .topbar, .sidebar, .read-progress, .hamburger, .scrim,
  .citation, .article-footer, .lightbox, .backref, .btn,
  .meta-actions .btn-pdf { display: none !important; }
  body, .layout, main, .article {
    background: #fff !important; color: #000 !important;
    display: block !important; max-width: 100% !important;
    margin: 0 !important; padding: 0 !important;
    font-size: 11pt; line-height: 1.45;
  }
  .article h1, .article h2, .article h3, .article h4 { color: #000 !important; page-break-after: avoid; page-break-inside: avoid; }
  .article a { color: #000 !important; text-decoration: underline; }
  .figure, .abstract, table, pre, blockquote { page-break-inside: avoid; }
  .figure { border: 1px solid #ccc; }
  .article p, .article li { orphans: 3; widows: 3; }
  .article h2 { border-bottom: 1px solid #000; }
}
/* ============================================================
   Формулы (KaTeX) — дополнение для dm-scs.html
   ============================================================ */

/* Inline-формулы: чуть увеличиваем базовый размер, чтобы совпадал
   с оптическим размером Merriweather */
.article .katex {
  font-size: 1.06em;
}
.article .katex-display > .katex {
  font-size: 1.08em;
}

/* Выносные формулы */
.article .math-block {
  margin: 1.4em 0;
  padding: 1.05rem 1.25rem;
  background: var(--bg-elev);
  border-left: 3px solid var(--accent);
  border-radius: 0 8px 8px 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  font-size: 1em;
  line-height: 1.5;
}
.article .math-block .katex-display {
  margin: 0;
}
.article .math-block .katex-display > .katex {
  text-align: left; /* левое выравнивание — иначе длинные формулы уползают */
  font-size: 1.08em;
}

/* Не разрывать формулу при печати / переносе */
.article .math-block,
.article .katex-display {
  break-inside: avoid;
  page-break-inside: avoid;
}

/* Печатная версия: убираем подложку, оставляем рамку */
@media print {
  .article .math-block {
    background: transparent;
    border-left: 2px solid #000;
    padding: .35em .6em;
  }
}
/* === Fix: PDF-кнопка внутри .article не должна наследовать
   цвета и подчёркивание общей ссылки .article a === */
.article .btn.btn-pdf,
.article .btn.btn-pdf:visited,
.article .btn.btn-pdf:hover,
.article .btn.btn-pdf:focus,
.article .btn.btn-pdf:focus-visible {
  color: #fff;
  text-decoration: none;
}

[data-theme="dark"] .article .btn.btn-pdf,
[data-theme="dark"] .article .btn.btn-pdf:visited,
[data-theme="dark"] .article .btn.btn-pdf:hover,
[data-theme="dark"] .article .btn.btn-pdf:focus,
[data-theme="dark"] .article .btn.btn-pdf:focus-visible {
  color: #1b1b1e;
}