:root {
  --container-max: 1200px;
  --header-height: 72px;
  --bg: #ffffff;
  --bg-soft: #f8fafc;
  --text-strong: #0f172a;
  --text-body: #334155;
  --text-muted: #64748b;
  --line: #e2e8f0;
  --accent: #1d4ed8;
  --code-bg: #0f172a;
  --output-bg: #f1f5f9;
  --radius-sm: 8px;
  --radius-md: 12px;
  --shadow-soft: 0 12px 28px rgba(15, 23, 42, 0.08);
  --space-1: 8px;
  --space-2: 16px;
  --space-3: 24px;
  --space-4: 32px;
  --space-5: 40px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Manrope", sans-serif;
  color: var(--text-body);
  background: var(--bg);
  line-height: 1.7;
  height: 100vh;
  overflow: hidden;
}

.container {
  width: 100%;
  max-width: var(--container-max);
  margin: 0 auto;
  padding: 0 var(--space-3);
}

.docs-header {
  position: sticky;
  top: 0;
  z-index: 220;
  background: rgba(255, 255, 255, 0.96);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

.header-row {
  min-height: var(--header-height);
  display: grid;
  grid-template-columns: auto 1fr auto;
  grid-template-areas: "brand nav actions";
  align-items: center;
  gap: var(--space-2);
}

.brand {
  grid-area: brand;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text-strong);
  font-weight: 800;
  font-size: 20px;
}

.brand img {
  width: 34px;
  height: 34px;
}

.docs-nav {
  display: flex;
  gap: var(--space-3);
  align-items: center;
  flex-wrap: wrap;
}

.site-nav {
  grid-area: nav;
  display: flex;
  gap: var(--space-3);
  align-items: center;
  flex-wrap: wrap;
  justify-self: end;
}

.docs-nav a {
  text-decoration: none;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-body);
  padding-bottom: 4px;
  border-bottom: 2px solid transparent;
  transition: color 180ms ease, border-color 180ms ease;
}

.docs-nav a:hover,
.docs-nav a.is-active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.header-actions {
  grid-area: actions;
  display: none;
  align-items: center;
  justify-self: end;
}

.menu-btn {
  display: none;
  width: 52px;
  height: 52px;
  border: 1px solid #c4cad4;
  background: rgba(243, 245, 248, 0.96);
  border-radius: 12px;
  align-items: center;
  justify-content: center;
  gap: 5px;
  flex-direction: column;
  cursor: pointer;
  z-index: 160;
  transition: transform 200ms ease, box-shadow 200ms ease, background 200ms ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.menu-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 20px rgba(15, 23, 42, 0.12);
}

.menu-icon-line {
  width: 20px;
  height: 2px;
  border-radius: 999px;
  background: #111318;
  transition: transform 240ms ease, opacity 240ms ease;
}

.menu-btn.is-open .menu-icon-line:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}

.menu-btn.is-open .menu-icon-line:nth-child(2) {
  opacity: 0;
}

.menu-btn.is-open .menu-icon-line:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

.mobile-menu-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 200;
  background: linear-gradient(150deg, rgba(18, 27, 43, 0.97) 0%, rgba(13, 22, 35, 0.96) 52%, rgba(15, 30, 54, 0.95) 100%);
  opacity: 0;
  transform: translateY(-10px) scale(0.99);
  pointer-events: none;
  transition: transform 260ms cubic-bezier(0.22, 1, 0.36, 1), opacity 200ms ease;
  will-change: transform, opacity;
}

.mobile-menu-list {
  margin: 0;
  padding: clamp(86px, 14vh, 128px) clamp(24px, 6vw, 38px) 36px;
  list-style: none;
  display: grid;
  gap: 12px;
}

.mobile-menu-list a {
  position: relative;
  display: inline-flex;
  align-items: center;
  width: fit-content;
  color: #f8fafc;
  text-decoration: none;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: clamp(1.25rem, 6vw, 1.9rem);
  font-weight: 700;
  padding: 0.3rem 0;
  transition: color 200ms ease, transform 220ms ease;
}

.mobile-menu-list a::before {
  content: "";
  position: absolute;
  left: -16px;
  top: 50%;
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: #38bdf8;
  transform: translateY(-50%) scale(0.2);
  opacity: 0;
  transition: transform 220ms ease, opacity 220ms ease;
}

.mobile-menu-list a:hover,
.mobile-menu-list a:focus-visible {
  color: #93c5fd;
  transform: translateX(6px);
}

.mobile-menu-list a:hover::before,
.mobile-menu-list a:focus-visible::before {
  transform: translateY(-50%) scale(1);
  opacity: 1;
}

body.mobile-menu-open {
  overflow: hidden !important;
}

body.mobile-menu-open .mobile-menu-overlay {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.docs-layout {
  display: grid;
  grid-template-columns: minmax(0, 260px) minmax(0, 1fr);
  gap: var(--space-5);
  padding: var(--space-5) 0 var(--space-5);
  height: calc(100vh - var(--header-height));
  min-height: 0;
}

.docs-sidebar {
  position: sticky;
  top: calc(var(--header-height) + var(--space-3));
  align-self: start;
  padding: var(--space-3);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  max-height: 100%;
  overflow-y: auto;
  scrollbar-gutter: stable;
}

.sidebar-title {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: var(--space-2);
}

.sidebar-search {
  margin-bottom: var(--space-2);
}

.sidebar-search input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #ffffff;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-strong);
}

.sidebar-search input::placeholder {
  color: #94a3b8;
}

.search-empty {
  margin-top: 8px;
  font-size: 13px;
  color: var(--text-muted);
}

.chapter-toggle {
  width: 100%;
  border: none;
  background: transparent;
  padding: var(--space-2) 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 16px;
  font-weight: 700;
  color: var(--text-strong);
  cursor: pointer;
}

.chev {
  width: 10px;
  height: 10px;
  border-right: 2px solid var(--text-muted);
  border-bottom: 2px solid var(--text-muted);
  transform: rotate(45deg);
  transition: transform 180ms ease;
}

.chapter-list {
  max-height: 0;
  overflow: hidden;
  transition: max-height 220ms ease;
}

.chapter-list.is-open {
  max-height: 680px;
}

.chapter-toggle.is-open .chev {
  transform: rotate(225deg);
}

.lesson-list {
  display: grid;
  gap: 4px;
  margin-bottom: var(--space-2);
}

.chapter-group + .chapter-group {
  margin-top: var(--space-2);
  padding-top: var(--space-2);
  border-top: 1px solid var(--line);
}

.lesson-link {
  border: none;
  background: transparent;
  text-align: left;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  color: var(--text-body);
  cursor: pointer;
  transition: background 160ms ease, color 160ms ease;
}

.lesson-link:hover {
  background: rgba(226, 232, 240, 0.7);
}

.lesson-link.is-active {
  background: #e2e8f0;
  color: var(--text-strong);
}

.chapter-soon {
  font-size: 13px;
  color: var(--text-muted);
  padding: 6px 4px 0;
}

.docs-content {
  min-width: 0;
  overflow-y: auto;
  max-height: 100%;
  padding-right: var(--space-1);
  scrollbar-gutter: stable;
}

.content-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}

.content-kicker {
  margin: 0 0 6px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--text-muted);
}

#lessonTitle {
  margin: 0;
  font-size: clamp(28px, 3vw, 36px);
  color: var(--text-strong);
  letter-spacing: -0.02em;
}

.lang-toggle {
  border: 1px solid var(--line);
  background: #ffffff;
  padding: 8px 14px;
  border-radius: 999px;
  font-weight: 700;
  color: var(--text-strong);
  cursor: pointer;
  transition: transform 160ms ease, border-color 160ms ease;
}

.lang-toggle:hover {
  transform: translateY(-1px);
  border-color: #cbd5f5;
}

.lang-notice {
  margin-bottom: var(--space-2);
  font-size: 14px;
  color: #b45309;
  background: #fef3c7;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
}

.markdown h2,
.markdown h3,
.markdown h4 {
  color: var(--text-strong);
  margin-top: var(--space-4);
}

.markdown p {
  margin: var(--space-2) 0 0;
}

.markdown ul,
.markdown ol {
  padding-left: 20px;
  margin: var(--space-2) 0 0;
}

.markdown table {
  width: 100%;
  border-collapse: collapse;
  margin-top: var(--space-3);
}

.markdown th,
.markdown td {
  border: 1px solid var(--line);
  padding: 10px 12px;
  text-align: left;
}

.markdown th {
  background: var(--bg-soft);
}

.markdown code {
  background: rgba(15, 23, 42, 0.06);
  padding: 2px 6px;
  border-radius: 6px;
  font-size: 0.95em;
}

.code-block,
.code-output {
  margin: var(--space-3) 0 0;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  overflow-x: auto;
  font-family: "JetBrains Mono", "Fira Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 15px;
  line-height: 1.6;
}

.code-wrap {
  position: relative;
}

.code-wrap .code-block,
.code-wrap .code-output {
  padding-top: 46px;
}

.code-copy-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  height: 28px;
  min-width: 64px;
  padding: 0 10px;
  border: 1px solid rgba(148, 163, 184, 0.42);
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.85);
  color: #e2e8f0;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  transition: transform 140ms ease, border-color 140ms ease, color 140ms ease;
}

.code-copy-btn:hover {
  transform: translateY(-1px);
  border-color: rgba(96, 165, 250, 0.72);
}

.code-copy-btn.is-copied {
  color: #86efac;
  border-color: rgba(34, 197, 94, 0.72);
}

.code-block {
  background: var(--code-bg);
  color: #e2e8f0;
  box-shadow: inset 0 0 0 1px rgba(148, 163, 184, 0.12), inset 0 0 18px rgba(56, 189, 248, 0.08);
}

.code-output {
  background: var(--output-bg);
  color: #1e293b;
  border: 1px solid var(--line);
}

.elang-k { color: #fbbf24; }
.elang-fn { color: #60a5fa; }
.elang-s { color: #4ade80; }
.elang-n { color: #c084fc; }

.lesson-nav {
  margin-top: var(--space-4);
  display: flex;
  justify-content: space-between;
  gap: var(--space-2);
}

.nav-btn {
  border: 1px solid var(--line);
  background: #ffffff;
  padding: 10px 18px;
  border-radius: 999px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 160ms ease, border-color 160ms ease, color 160ms ease;
}

.nav-btn:hover {
  transform: translateY(-1px);
  border-color: #cbd5f5;
  color: var(--accent);
}

.nav-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

@media (max-width: 900px) {
  .header-row {
    grid-template-columns: 1fr auto;
    grid-template-areas: "brand actions";
  }

  .header-actions {
    display: flex;
    justify-self: end;
  }

  .brand {
    justify-self: start;
  }

  .site-nav {
    display: none !important;
  }

  .menu-btn {
    display: flex;
  }

  .mobile-menu-overlay {
    display: block;
  }

  .docs-layout {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 0;
  }

  .docs-sidebar {
    position: static;
    border-radius: var(--radius-md);
    max-height: none;
    overflow: visible;
  }
  .docs-content {
    overflow: visible;
    max-height: none;
    padding-right: 0;
  }
  body {
    height: auto;
    overflow: auto;
  }
}

@media (max-width: 640px) {
  .container {
    padding: 0 var(--space-2);
  }

  .header-row {
    min-height: var(--header-height);
  }

  .lesson-nav {
    flex-direction: column;
  }

  .nav-btn {
    width: 100%;
  }
}
@media (prefers-reduced-motion: reduce) {
  * {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
