:root {
  color-scheme: light;
  --bg: #fff;
  --fg: #000;
  --fg-strong: #111;
  --fg-muted: #555;
  --fg-secondary: #666;
  --fg-separator: #999;
  --link: #0060a0;
  --link-underline: rgba(0, 96, 160, 0.15);
  --link-visited: #70a0b0;
  --link-visited-underline: rgba(112, 160, 176, 0.15);
  --link-accent: #0062bc;
  --link-accent-hover: #004080;
  --link-accent-underline: #e3f0f8;
  --link-accent-underline-thin: rgba(0, 98, 188, 0.35);
  --link-text: #003366;
  --link-text-hover: #002244;
  --link-text-underline: rgba(0, 51, 102, 0.35);
  --rule: rgba(0, 0, 0, 0.15);
  --max-width: 1500px;
  --margin-top: 48px;
  --margin-x: 9%;
  --margin-x-compact: 4%;
  --text-max: 1020px;
  background: var(--bg);
}

:root.dark {
  color-scheme: dark;
  --bg: rgb(32, 32, 32);
  --fg: rgb(192, 192, 192);
  --fg-strong: rgb(210, 210, 210);
  --fg-muted: rgb(140, 140, 140);
  --fg-secondary: rgb(145, 145, 145);
  --fg-separator: rgb(90, 90, 90);
  --link: rgb(50, 160, 230);
  --link-underline: rgba(50, 160, 230, 0.3);
  --link-visited: rgb(110, 140, 185);
  --link-visited-underline: rgba(110, 140, 185, 0.3);
  --link-accent: rgb(50, 160, 230);
  --link-accent-hover: rgb(192, 192, 192);
  --link-accent-underline: rgba(50, 160, 230, 0.3);
  --link-accent-underline-thin: rgba(50, 160, 230, 0.3);
  --link-text: rgb(90, 170, 225);
  --link-text-hover: rgb(192, 192, 192);
  --link-text-underline: rgba(90, 170, 225, 0.3);
  --rule: rgba(192, 192, 192, 0.25);
}

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

.no-transitions *,
.no-transitions *::before,
.no-transitions *::after {
  transition: none !important;
}

body,
h1,
h2,
p {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--fg);
  font: 14px/22px system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell,
    "Fira Sans", "Droid Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

a {
  color: var(--link);
  text-decoration: none;
  border-bottom: 1px solid var(--link-underline);
  transition: border-color 0.2s ease-out, color 0.2s ease-out;
  -webkit-tap-highlight-color: transparent;
}

a:visited {
  color: var(--link-visited);
  border-color: var(--link-visited-underline);
}

a:hover {
  color: var(--fg);
  border-color: var(--rule);
  transition: none;
}

a:focus-visible,
button:focus-visible {
  outline: 2px solid var(--link-accent);
  outline-offset: 2px;
  border-radius: 2px;
}

#top:focus {
  outline: none;
}

.wrap {
  max-width: var(--max-width);
  margin: 0 auto;
}

.header {
  padding: var(--margin-top) 0 40px;
  margin: 0 var(--margin-x);
}

.article-title {
  font: bold 45px/1 "Helvetica Neue", Helvetica, Arial, sans-serif;
  color: var(--fg);
  max-width: var(--text-max);
  margin-bottom: 0.45em;
  overflow-wrap: break-word;
}

.article-desc {
  font: 18px/1.6 Georgia, "Times New Roman", Times, serif;
  max-width: var(--text-max);
}

.article-desc:empty {
  display: none;
}

.content {
  margin: 0 var(--margin-x) 60px;
}

.note {
  margin-bottom: 0;
}

.note-title {
  font: bold 30px/1.2 "Helvetica Neue", Helvetica, Arial, sans-serif;
  color: var(--fg);
  max-width: 720px;
  margin-bottom: 23px;
  -webkit-hyphens: auto;
  hyphens: auto;
  overflow-wrap: break-word;
}

.note-title:empty {
  display: none;
}

.note-title a,
.note-title a:visited {
  color: var(--fg);
  border-color: var(--rule);
}

.note-text {
  font: 18px/1.6 Georgia, "Times New Roman", Times, serif;
  margin-bottom: 16px;
}

.note-text p {
  max-width: var(--text-max);
  margin: 0 0 24px;
}

.note-text blockquote {
  max-width: var(--text-max);
  margin: 32px 0;
  padding: 0 0 0 40px;
  font-style: italic;
}

.note-text blockquote .quote-source {
  display: block;
  margin-top: 8px;
  font-style: normal;
  font-size: 15px;
  color: var(--fg-muted);
}

.note-text img,
.note-text video {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 24px 0;
}

.note-text iframe {
  max-width: 100%;
  width: 100%;
  aspect-ratio: 16 / 9;
  display: block;
  margin: 24px 0;
  border: none;
}

.note-text pre {
  max-width: 100%;
  overflow-x: auto;
}

.table-wrapper {
  max-width: 100%;
  overflow-x: auto;
  margin-bottom: 24px;
}

.note-text table {
  width: 100%;
  border-collapse: collapse;
}

.note-text ul,
.note-text ol {
  max-width: var(--text-max);
  margin: 0 0 24px;
  padding-left: 40px;
}

.note-text p + ul,
.note-text p + ol {
  margin-top: -10px;
}

.note-text li {
  margin-bottom: 8px;
}

.note-text li > ul,
.note-text li > ol {
  margin-bottom: 0;
}

.note-text p,
.note-text ul,
.note-text ol,
.note-text code {
  overflow-wrap: break-word;
}

.note-text .text-link,
.note-text .text-link:visited,
.note-text .text-link:link {
  color: var(--link-text);
  text-decoration: none;
  border-bottom: 0.5px solid var(--link-text-underline);
  transition: all 0.2s ease;
}

.note-text .text-link:hover {
  color: var(--link-text-hover);
  border-color: var(--link-text-hover);
}

.nav-toggle {
  display: none;
}

.nav-links {
  margin-bottom: 68px;
  font: 18px/1.6 Helvetica, Arial, sans-serif;
}

.nav-links a {
  color: var(--link-accent);
  text-decoration: underline;
  text-decoration-color: currentColor;
  text-underline-offset: 4px;
  text-decoration-thickness: 1px;
  border-bottom: none;
  transition: all 0.2s ease;
}

.nav-links a:hover {
  color: var(--link-accent-hover);
  text-decoration-color: var(--link-accent-hover);
}

.nav-links .nav-current {
  color: var(--fg);
  text-decoration: none;
  cursor: default;
  visibility: visible;
}

.nav-links span {
  color: var(--fg-separator);
  margin: 0 4px;
  visibility: hidden;
}

.nav-theme-toggle {
  color: var(--fg-muted);
  font: 18px/1.6 Helvetica, Arial, sans-serif;
  text-decoration: underline;
  text-decoration-color: currentColor;
  text-underline-offset: 4px;
  text-decoration-thickness: 1px;
}

.nav-links .nav-theme-toggle:hover {
  color: var(--fg-muted);
  text-decoration-color: currentColor;
  border-bottom: none;
}

.font-toggle {
  color: var(--fg-muted);
  background: none;
  border: none;
  font: inherit;
  cursor: pointer;
  padding: 0;
  transition: all 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}

.font-toggle:hover {
  border-bottom: 1px solid var(--fg-muted);
}

.font-toggle::after {
  content: "Arial";
}

:root.sans-serif .font-toggle::after {
  content: "Georgia";
}

.nav-font-toggle {
  color: var(--fg-muted);
  font: 18px/1.6 Helvetica, Arial, sans-serif;
  text-decoration: underline;
  text-decoration-color: currentColor;
  text-underline-offset: 4px;
  text-decoration-thickness: 1px;
}

.nav-links .nav-font-toggle:hover {
  color: var(--fg-muted);
  text-decoration-color: currentColor;
  border-bottom: none;
}

:root.sans-serif .note-text,
:root.sans-serif .article-desc,
:root.sans-serif .note-text blockquote {
  font-family: Arial, Helvetica, "Helvetica Neue", sans-serif;
}

.breadcrumbs {
  margin: 0 var(--margin-x) 30px;
  font: 15px/1.6 Helvetica, Arial, sans-serif;
  color: var(--fg-muted);
}

.breadcrumbs a {
  color: var(--link-accent);
  text-decoration: underline;
  text-decoration-color: var(--link-accent-underline-thin);
  text-underline-offset: 4px;
  text-decoration-thickness: 1px;
  border-bottom: none;
  transition: all 0.2s ease;
}

.breadcrumbs a:hover {
  color: var(--link-accent-hover);
  text-decoration-color: var(--link-accent-hover);
}

.breadcrumbs span {
  color: var(--fg-muted);
  margin: 0 4px;
}

.breadcrumbs .breadcrumb-current,
.breadcrumbs .breadcrumb-current:visited,
.breadcrumbs .breadcrumb-current:link {
  color: var(--fg-muted);
  text-decoration: none;
  border-bottom: none;
}

.breadcrumbs .breadcrumb-current:hover {
  color: var(--fg-muted);
  border-bottom: 1px solid var(--fg-muted);
}

.footer {
  margin: 0 var(--margin-x) 40px;
  padding-top: 24px;
  font: 15px/1.6 Helvetica, Arial, sans-serif;
  color: var(--fg-muted);
}

.footer a {
  color: var(--fg-muted);
  text-decoration: none;
  border-bottom: none;
  transition: all 0.2s ease;
}

.footer a:hover {
  color: var(--fg-muted);
  border-bottom: 1px solid var(--fg-muted);
}

.footer-sep {
  color: var(--fg-separator);
  margin: 0 4px;
}

.theme-toggle {
  color: var(--fg-muted);
  background: none;
  border: none;
  font: inherit;
  cursor: pointer;
  padding: 0;
  transition: all 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}

.theme-toggle:hover {
  border-bottom: 1px solid var(--fg-muted);
}

.theme-toggle::after {
  content: "Тёмная тема";
}

:root.dark .theme-toggle::after {
  content: "Светлая тема";
}

:root:lang(en) .theme-toggle::after {
  content: "Dark theme";
}

:root:lang(en).dark .theme-toggle::after {
  content: "Light theme";
}

.theme-toggle-mobile {
  display: none;
}

.links {
  margin: 0 var(--margin-x) 40px;
  font: 18px/1.6 Helvetica, Arial, sans-serif;
  color: var(--fg);
}

.links-section {
  margin-bottom: 32px;
}

.links-section h2 {
  font-size: 21px;
  font-weight: 600;
  margin-bottom: 16px;
  margin-top: 32px;
  color: var(--fg-strong);
}

.links-section h2:first-child {
  margin-top: 0;
}

.links-section h3 {
  font-size: 17px;
  font-weight: 600;
  margin: 20px 0 8px;
  color: var(--fg-secondary);
}

.links-section ul {
  list-style: none;
  padding: 0;
}

.links-section li {
  margin-bottom: 8px;
}

.links-section a {
  color: var(--link-accent);
  text-decoration: underline;
  text-decoration-color: var(--link-accent-underline);
  text-underline-offset: 4px;
  text-decoration-thickness: 2px;
  border-bottom: none;
  transition: all 0.2s ease;
}

.links-section a:hover {
  color: var(--link-accent-hover);
  text-decoration: underline;
  text-decoration-color: var(--link-accent-hover);
}

.links-section .link-note {
  color: var(--fg-secondary);
  font-size: 15px;
}

/* Site tree (catalog) */
.site-tree {
  list-style: none;
  padding: 0;
  margin: 0;
  font-size: 17px;
  line-height: 1.7;
}

.site-tree ul {
  list-style: none;
  padding-left: 24px;
  margin: 0;
}

.site-tree li {
  position: relative;
  padding-left: 20px;
}

.site-tree li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--border);
}

.site-tree li::after {
  content: "";
  position: absolute;
  left: 0;
  top: 0.85em;
  width: 12px;
  height: 1px;
  background: var(--border);
}

.site-tree li:last-child::before {
  bottom: calc(100% - 0.85em);
}

.site-tree > li::before,
.site-tree > li::after {
  display: none;
}

.site-tree > li {
  padding-left: 0;
}

.site-tree a {
  color: var(--link-accent);
  text-decoration: underline;
  text-decoration-color: var(--link-underline);
}

.site-tree a:hover {
  color: var(--link-accent-hover);
}

.site-tree .tree-section {
  font-weight: 600;
}

.site-tree .tree-note {
  color: var(--fg-secondary);
  font-size: 15px;
}

/* --- Sitemap body links (nav-style, independently managed) --- */

.sitemap-body {
  font: 18px/1.6 Helvetica, Arial, sans-serif;
}

.sitemap-body a {
  color: var(--link-accent);
  text-decoration: underline;
  text-decoration-color: currentColor;
  text-underline-offset: 4px;
  text-decoration-thickness: 1px;
  border-bottom: none;
  transition: all 0.2s ease;
}

.sitemap-body a:visited {
  color: var(--link-accent);
  text-decoration-color: currentColor;
}

.sitemap-body a:hover {
  color: var(--link-accent-hover);
  text-decoration-color: var(--link-accent-hover);
}

.sitemap-body .tree-section {
  font-weight: normal;
}

@media screen and (max-width: 1023px) {
  .header {
    margin: 16px var(--margin-x-compact) 0;
    padding: 16px 0 32px;
  }

  .content {
    margin: 0 var(--margin-x-compact) 60px;
  }

  .links {
    margin: 0 var(--margin-x-compact) 40px;
  }

  .breadcrumbs {
    margin: 0 var(--margin-x-compact) 30px;
  }

  .footer {
    margin: 0 var(--margin-x-compact) 40px;
    text-align: center;
  }

  .footer a,
  .footer .footer-sep,
  .footer .theme-toggle:not(.theme-toggle-mobile) {
    display: none;
  }

  .footer .theme-toggle-mobile {
    display: block;
    margin: 0 auto 12px;
    min-height: 44px;
    line-height: 44px;
  }

  .footer-info {
    display: block;
  }

  .nav-toggle {
    display: block;
    background: none;
    border: none;
    color: var(--fg);
    font: bold 28px/1.2 "Helvetica Neue", Helvetica, Arial, sans-serif;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    padding: 8px 0;
    min-height: 44px;
    cursor: pointer;
    margin-bottom: 0;
    -webkit-tap-highlight-color: transparent;
  }

  .nav-links {
    display: none;
    margin-bottom: 0;
  }

  .nav.open .nav-links {
    display: block;
    margin-top: 16px;
    margin-bottom: 0;
  }

  .nav.open .nav-links span {
    display: none;
  }

  .nav.open .nav-links .nav-theme-toggle,
  .nav.open .nav-links .nav-font-toggle {
    display: none;
  }

  .nav.open .nav-links a {
    display: block;
    padding: 20px 0;
    font: bold 28px/1.2 "Helvetica Neue", Helvetica, Arial, sans-serif;
    color: var(--fg);
    text-decoration: none;
    border-bottom: 1px solid var(--rule);
    border-top: none;
  }

  .nav.open .nav-links a:first-child {
    border-top: 1px solid var(--rule);
  }

  .nav {
    margin-bottom: 32px;
  }

  .nav-links span {
    margin: 0 2px;
  }

  .article-title {
    font-size: 30px;
  }

  .note-title {
    font-size: 24px;
  }

  .note-text blockquote {
    padding-left: 16px;
    border-left: 2px solid var(--rule);
  }
}

/* --- Publications --- */

.publications-page .note-text .pub-meta {
  font: 15px/1.6 Helvetica, Arial, sans-serif;
  color: var(--fg-muted);
  margin-bottom: 4px;
}

.publications-page .note-text .pub-desc {
  font-size: 16px;
  line-height: 1.6;
  color: var(--fg-secondary);
  margin-bottom: 0;
}

/* --- End Publications --- */

@media print {
  :root.dark {
    color-scheme: light !important;
    --bg: #fff;
    --fg: #000;
    --fg-strong: #111;
    --fg-muted: #555;
    --fg-secondary: #666;
    --link: #0060a0;
    --link-text: #003366;
  }

  body {
    background: #fff !important;
  }

  .header nav,
  .nav-toggle,
  .links,
  .breadcrumbs,
  .footer {
    display: none !important;
  }

  .content {
    display: block;
    margin: 0;
  }
}
