/* ---- Темы ---- */
:root,
[data-theme="dark"] {
  --bg:           #1a1a22;
  --bg-soft:     #1f1f29;
  --bg-elev:     #252532;
  --bg-hover:    #2c2c3a;
  --bg-code:     #15151c;

  --text:        #e4e4ec;
  --text-soft:   #a8a8b8;
  --text-muted:  #6a6a7a;

  --border:      #2e2e3c;
  --border-soft: #25252f;

  --accent:      #a78bfa;
  --accent-soft: rgba(167, 139, 250, 0.12);
  --accent-glow: rgba(167, 139, 250, 0.35);

  --warn:        #f4b860;
  --warn-soft:   rgba(244, 184, 96, 0.10);
  --danger:      #f87171;
  --danger-soft: rgba(248, 113, 113, 0.10);
  --info:        #60a5fa;
  --info-soft:   rgba(96, 165, 250, 0.10);
  --tip:         #6ee7b7;
  --tip-soft:    rgba(110, 231, 183, 0.10);

  --shadow-sm:   0 1px 2px rgba(0,0,0,0.3);
  --shadow:      0 8px 24px rgba(0,0,0,0.4);
  --shadow-lg:   0 24px 60px rgba(0,0,0,0.5);

  --radius:      12px;
  --radius-sm:   8px;
  --radius-lg:   16px;
}

[data-theme="light"] {
  --bg:           #fafaf7;
  --bg-soft:     #f4f3ee;
  --bg-elev:     #ffffff;
  --bg-hover:    #ebeae3;
  --bg-code:     #f0efe9;

  --text:        #1f1d2c;
  --text-soft:   #5a586b;
  --text-muted:  #8a8898;

  --border:      #e0ddd2;
  --border-soft: #ebe9df;

  --accent:      #7c5cff;
  --accent-soft: rgba(124, 92, 255, 0.10);
  --accent-glow: rgba(124, 92, 255, 0.25);

  --warn:        #c97d10;
  --warn-soft:   rgba(201, 125, 16, 0.10);
  --danger:      #d04848;
  --danger-soft: rgba(208, 72, 72, 0.10);
  --info:        #3b7adb;
  --info-soft:   rgba(59, 122, 219, 0.10);
  --tip:         #1f9a6e;
  --tip-soft:    rgba(31, 154, 110, 0.10);

  --shadow-sm:   0 1px 2px rgba(50,40,80,0.06);
  --shadow:      0 8px 24px rgba(50,40,80,0.10);
  --shadow-lg:   0 24px 60px rgba(50,40,80,0.18);
}

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

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: 'Manrope', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 16px;
  line-height: 1.65;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* мягкое декоративное свечение */
body::before {
  content: '';
  position: fixed;
  top: -40vh;
  left: -20vw;
  width: 60vw;
  height: 80vh;
  background: radial-gradient(circle at center, var(--accent-glow), transparent 60%);
  opacity: 0.4;
  pointer-events: none;
  z-index: 0;
  filter: blur(40px);
}

[data-theme="light"] body::before { opacity: 0.5; }

::selection {
  background: var(--accent-soft);
  color: var(--text);
}

/* ---- Боковая панель ---- */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: 300px;
  height: 100vh;
  background: var(--bg-soft);
  border-right: 1px solid var(--border-soft);
  z-index: 50;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), background-color 0.3s ease;
}

.sidebar-inner {
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.sidebar-inner::-webkit-scrollbar { width: 6px; }
.sidebar-inner::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

.sidebar-header {
  padding: 28px 24px 20px;
  border-bottom: 1px solid var(--border-soft);
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-mark {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-glow));
  display: grid;
  place-items: center;
  color: #fff;
  flex-shrink: 0;
  box-shadow: 0 4px 12px var(--accent-glow);
}

.logo-mark svg { width: 20px; height: 20px; }

.logo-title {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.01em;
  color: var(--text);
}

.logo-subtitle {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ---- Навигация ---- */
.nav {
  flex: 1;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-soft);
  text-decoration: none;
  font-weight: 500;
  font-size: 14px;
  transition: all 0.15s ease;
  position: relative;
  cursor: pointer;
}

.nav-item:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.nav-num {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  display: grid;
  place-items: center;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  font-size: 12px;
  font-weight: 700;
  font-family: 'JetBrains Mono', monospace;
  color: var(--text-soft);
  flex-shrink: 0;
  transition: all 0.15s ease;
}

.nav-item:hover .nav-num {
  border-color: var(--accent);
  color: var(--accent);
}

.nav-item.is-active {
  background: var(--accent-soft);
  color: var(--accent);
}

.nav-item.is-active .nav-num {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.nav-item.is-active::before {
  content: '';
  position: absolute;
  left: -12px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 20px;
  background: var(--accent);
  border-radius: 0 2px 2px 0;
}

.nav-sub {
  display: flex;
  flex-direction: column;
  gap: 1px;
  margin: 2px 0 6px 36px;
  padding-left: 12px;
  border-left: 1px solid var(--border-soft);
}

.nav-subitem {
  padding: 6px 10px;
  font-size: 13px;
  color: var(--text-muted);
  text-decoration: none;
  border-radius: 6px;
  transition: all 0.15s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-subitem:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.nav-subitem.is-active {
  color: var(--accent);
  background: var(--accent-soft);
}

/* ---- Подвал сайдбара ---- */
.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--border-soft);
}

.theme-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text-soft);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.theme-toggle:hover {
  background: var(--bg-hover);
  color: var(--text);
  border-color: var(--accent);
}

.theme-toggle svg { width: 16px; height: 16px; flex-shrink: 0; }

[data-theme="dark"] .icon-sun { display: block; }
[data-theme="dark"] .icon-moon { display: none; }
[data-theme="light"] .icon-sun { display: none; }
[data-theme="light"] .icon-moon { display: block; }

.theme-label { flex: 1; text-align: left; }

/* ---- Кнопка-меню для мобильных ---- */
.menu-toggle {
  display: none;
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 60;
  width: 42px;
  height: 42px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-sm);
}

.menu-toggle svg { width: 20px; height: 20px; }

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(2px);
  z-index: 49;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.sidebar-overlay.is-visible {
  opacity: 1;
  display: block;
}

/* ---- Основной контент ---- */
.content {
  margin-left: 300px;
  padding: 64px 48px 96px;
  position: relative;
  z-index: 1;
}

.article {
  max-width: 780px;
  margin: 0 auto;
}

/* ---- Заголовок статьи ---- */
.article-header {
  margin-bottom: 56px;
  padding-bottom: 32px;
  border-bottom: 1px solid var(--border-soft);
}

.article-eyebrow {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  padding: 6px 12px;
  background: var(--accent-soft);
  border-radius: 999px;
  margin-bottom: 20px;
}

.article-title {
  font-size: 44px;
  line-height: 1.1;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin: 0 0 16px;
  color: var(--text);
}

.article-lead {
  font-size: 18px;
  line-height: 1.6;
  color: var(--text-soft);
  margin: 0;
  max-width: 620px;
}

/* ---- Секции ---- */
.section {
  margin-bottom: 64px;
  scroll-margin-top: 32px;
}

.section-head {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-soft);
}

.section-badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-radius: 6px;
  flex-shrink: 0;
  box-shadow: 0 2px 8px var(--accent-glow);
}

.section-title {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.015em;
  margin: 0;
  line-height: 1.25;
  color: var(--text);
}

.subsection {
  margin-bottom: 40px;
  scroll-margin-top: 32px;
}

.sub-title {
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0 0 14px;
  color: var(--text);
  position: relative;
  padding-left: 14px;
}

.sub-title::before {
  content: '';
  position: absolute;
  left: 0;
  top: 8px;
  bottom: 8px;
  width: 3px;
  border-radius: 2px;
  background: var(--accent);
}

/* ---- Текст ---- */
p {
  margin: 0 0 16px;
  color: var(--text-soft);
}

p strong { color: var(--text); font-weight: 600; }

ul {
  margin: 0 0 20px;
  padding-left: 20px;
  color: var(--text-soft);
}

ul li { margin-bottom: 8px; }
ul li strong { color: var(--text); font-weight: 600; }

code, .path {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.88em;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--bg-code);
  border: 1px solid var(--border-soft);
  color: var(--accent);
  word-break: break-all;
}

.path {
  white-space: nowrap;
  color: var(--text);
}

/* ---- Картинки ---- */
.figure {
  margin: 20px 0 24px;
  padding: 0;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  box-shadow: var(--shadow);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.figure:hover {
  box-shadow: var(--shadow-lg);
}

.figure img {
  display: block;
  width: 100%;
  height: auto;
  cursor: zoom-in;
  transition: transform 0.3s ease;
}

.figure:hover img {
  transform: scale(1.01);
}

/* Компактная версия — для вытянутых/высоких скриншотов */
.figure-compact {
  display: flex;
  justify-content: center;
  padding: 20px;
  background: var(--bg-elev);
}

.figure-compact img {
  max-height: 460px;
  width: auto;
  max-width: 100%;
  object-fit: contain;
  border-radius: 6px;
}

.figure-compact:hover img {
  transform: none;
}

/* ---- Колауты (предупреждения) ---- */
.callout {
  display: flex;
  gap: 14px;
  padding: 16px 18px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin: 20px 0;
  background: var(--bg-elev);
  position: relative;
  overflow: hidden;
}

.callout::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
}

.callout-icon {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  margin-top: 1px;
}

.callout-icon svg { width: 100%; height: 100%; }

.callout-body { flex: 1; color: var(--text-soft); }
.callout-body p { margin: 0 0 10px; color: var(--text-soft); }
.callout-body p:last-child { margin-bottom: 0; }
.callout-body strong { color: var(--text); }

.callout-warning { background: var(--warn-soft); border-color: transparent; }
.callout-warning::before { background: var(--warn); }
.callout-warning .callout-icon { color: var(--warn); }

.callout-danger { background: var(--danger-soft); border-color: transparent; }
.callout-danger::before { background: var(--danger); }
.callout-danger .callout-icon { color: var(--danger); }

.callout-info { background: var(--info-soft); border-color: transparent; }
.callout-info::before { background: var(--info); }
.callout-info .callout-icon { color: var(--info); }

.callout-tip { background: var(--tip-soft); border-color: transparent; }
.callout-tip::before { background: var(--tip); }
.callout-tip .callout-icon { color: var(--tip); }

/* ---- Подвал статьи ---- */
.article-footer {
  margin-top: 80px;
  padding-top: 32px;
  text-align: center;
}

.footer-line {
  width: 60px;
  height: 2px;
  background: var(--accent);
  margin: 0 auto 20px;
  border-radius: 2px;
}

.footer-text {
  color: var(--text-muted);
  font-size: 14px;
  margin: 0;
}

/* ---- Лайтбокс ---- */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(8, 8, 14, 0.92);
  backdrop-filter: blur(10px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease;
  cursor: zoom-out;
}

[data-theme="light"] .lightbox { background: rgba(20, 18, 30, 0.85); }

.lightbox.is-open {
  opacity: 1;
  visibility: visible;
}

.lightbox-img {
  max-width: min(1400px, 95%);
  max-height: 90vh;
  width: auto;
  height: auto;
  border-radius: 8px;
  box-shadow: 0 30px 80px rgba(0,0,0,0.6);
  transform: scale(0.95);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  cursor: default;
}

.lightbox.is-open .lightbox-img { transform: scale(1); }

.lightbox-close {
  position: fixed;
  top: 24px;
  right: 24px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.15);
  background: rgba(255,255,255,0.08);
  backdrop-filter: blur(8px);
  color: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: all 0.2s ease;
  z-index: 101;
}

.lightbox-close:hover {
  background: rgba(255,255,255,0.2);
  border-color: rgba(255,255,255,0.3);
  transform: rotate(90deg);
}

.lightbox-close svg { width: 20px; height: 20px; }

/* ---- Адаптив ---- */
@media (max-width: 1024px) {
  .menu-toggle { display: flex; }

  .sidebar {
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
  }

  .sidebar.is-open { transform: translateX(0); }

  .content {
    margin-left: 0;
    padding: 80px 32px 64px;
  }
}

@media (max-width: 640px) {
  .content { padding: 76px 20px 56px; }

  .article-title { font-size: 32px; }
  .article-lead { font-size: 16px; }
  .section-title { font-size: 22px; }
  .sub-title { font-size: 17px; }

  .section-head {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .callout { padding: 14px 16px; gap: 12px; }

  .sidebar { width: 86%; max-width: 320px; }

  .lightbox { padding: 16px; }
  .lightbox-close { top: 12px; right: 12px; width: 40px; height: 40px; }
}

/* ---- Появление при загрузке ---- */
.article > * {
  animation: fadeUp 0.5s ease backwards;
}

.article > *:nth-child(1) { animation-delay: 0.05s; }
.article > *:nth-child(2) { animation-delay: 0.12s; }
.article > *:nth-child(3) { animation-delay: 0.18s; }
.article > *:nth-child(4) { animation-delay: 0.24s; }
.article > *:nth-child(5) { animation-delay: 0.30s; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}