:root {
  --bg: #0f1115;
  --panel: #141820;
  --panel-2: #171c25;
  --ink: #e7eaf0;
  --muted: #a3adbc;
  --line: #2a303b;
  --accent: #71d0b3;
  --accent-2: #7ea2ff;
  --link-hover-bg: #202530;
  --link-hover-border: #353d4b;
  --link-active-bg: #1f2e32;
  --link-active-border: #2f6f61;
  --link-active-ink: #b4f3de;
  --code-bg: #0f131a;
  --code-ink: #d9dfeb;
  --code-border: #2b3340;
  --code-scroll-thumb: #3a4353;
  --code-scroll-thumb-hover: #4b576b;
  --code-inline-bg: #232a36;
  --code-inline-border: #344051;
  --blockquote-border: #486089;
  --blockquote-bg: #151b25;
  --blockquote-ink: #c4d0e6;
}

body.light-theme {
  --bg: #f5f7fb;
  --panel: #eef2f8;
  --panel-2: #e5ebf5;
  --ink: #1e2530;
  --muted: #566276;
  --line: #c9d2e2;
  --accent: #0f7461;
  --accent-2: #365ecf;
  --link-hover-bg: #e7edf8;
  --link-hover-border: #bcc8de;
  --link-active-bg: #d9efe9;
  --link-active-border: #84b8ab;
  --link-active-ink: #0d564a;
  --code-bg: #f0f4fb;
  --code-ink: #233046;
  --code-border: #c6d2e9;
  --code-scroll-thumb: #95a7c8;
  --code-scroll-thumb-hover: #7f95bc;
  --code-inline-bg: #e3ebf9;
  --code-inline-border: #bed0ef;
  --blockquote-border: #738fc6;
  --blockquote-bg: #eaf0fb;
  --blockquote-ink: #334c7a;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Inter", "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
  min-height: 100vh;
}

.bg-shapes {
  display: none;
}

.shape {
  display: none;
}

.shape-a {
  width: 320px;
  height: 320px;
  top: -120px;
  right: -80px;
  background: #c8f1e7;
}

.shape-b {
  width: 220px;
  height: 220px;
  left: -100px;
  top: 45%;
  background: #ffe0bb;
  animation-delay: 2.5s;
}

.shape-c {
  width: 280px;
  height: 280px;
  bottom: -130px;
  right: 35%;
  background: #d0e3ff;
  animation-delay: 1s;
}

.menu-toggle {
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--ink);
  font-family: inherit;
  font-size: 1rem;
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 0;
  cursor: pointer;
}

.theme-toggle {
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--ink);
  font-family: inherit;
  font-size: 1rem;
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 0;
  cursor: pointer;
}

.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 30;
  height: 52px;
  display: grid;
  grid-template-columns: 52px 1fr 52px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}

.topbar .menu-toggle {
  justify-self: center;
}

.topbar .theme-toggle {
  justify-self: center;
}

.top-lesson-title {
  margin: 0;
  text-align: center;
  font-size: 0.95rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0 12px;
}

.layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 0;
  min-height: 100vh;
  padding-top: 52px;
}

.sidebar {
  position: sticky;
  top: 52px;
  align-self: start;
  height: calc(100vh - 52px);
  overflow: auto;
  border-right: 1px solid var(--line);
  background: var(--panel);
  transition: transform 0.2s ease;
  scrollbar-color: var(--code-scroll-thumb) var(--panel);
  scrollbar-width: thin;
}

.sidebar::-webkit-scrollbar {
  width: 10px;
}

.sidebar::-webkit-scrollbar-track {
  background: var(--panel);
}

.sidebar::-webkit-scrollbar-thumb {
  background: var(--code-scroll-thumb);
  border: 2px solid var(--panel);
}

.sidebar::-webkit-scrollbar-thumb:hover {
  background: var(--code-scroll-thumb-hover);
}

.sidebar-inner {
  padding: 18px;
}

.sidebar h2 {
  margin: 0 0 8px;
  font-size: 1.1rem;
}

.sidebar-note {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 0.9rem;
}

.section-block {
  margin-bottom: 18px;
}

.section-title {
  margin: 0 0 8px;
  font-size: 0.86rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.lesson-link {
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  background: transparent;
  padding: 8px 10px;
  border-radius: 0;
  color: var(--ink);
  font-family: inherit;
  font-size: 0.95rem;
  cursor: pointer;
}

.lesson-link:hover {
  background: var(--link-hover-bg);
  border-color: var(--link-hover-border);
}

.lesson-link.active {
  background: var(--link-active-bg);
  border-color: var(--link-active-border);
  color: var(--link-active-ink);
}

.content {
  min-width: 0;
  padding: 18px 28px 24px;
}

.lesson-header {
  border-bottom: 1px solid var(--line);
  padding-bottom: 14px;
  margin-bottom: 18px;
}

.breadcrumb {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.lesson-header h2 {
  margin: 6px 0 0;
  font-size: 1.6rem;
}

.lesson-actions {
  margin-top: 14px;
  display: flex;
  gap: 8px;
}

.ghost-btn {
  border: 1px solid var(--line);
  background: var(--panel-2);
  padding: 8px 10px;
  border-radius: 0;
  font-family: inherit;
  cursor: pointer;
  color: var(--ink);
}

.ghost-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.lesson-content {
  padding: 4px 0 30px;
  line-height: 1.72;
  font-size: 1.03rem;
  font-family: "Inter", "Segoe UI", sans-serif;
  word-break: normal;
  overflow-wrap: break-word;
}

.lesson-content h1,
.lesson-content h2,
.lesson-content h3 {
  font-family: "Inter", "Segoe UI", sans-serif;
  line-height: 1.25;
}

.lesson-content pre {
  overflow: auto;
  background: var(--code-bg);
  color: var(--code-ink);
  padding: 14px;
  border-radius: 10px;
  border: 1px solid var(--code-border);
  scrollbar-color: var(--code-scroll-thumb) var(--code-bg);
  scrollbar-width: thin;
}

.lesson-content pre::-webkit-scrollbar {
  height: 10px;
  width: 10px;
}

.lesson-content pre::-webkit-scrollbar-track {
  background: var(--code-bg);
}

.lesson-content pre::-webkit-scrollbar-thumb {
  background: var(--code-scroll-thumb);
  border: 2px solid var(--code-bg);
}

.lesson-content pre::-webkit-scrollbar-thumb:hover {
  background: var(--code-scroll-thumb-hover);
}

.lesson-content code {
  font-family: "Cascadia Code", "Fira Code", monospace;
}

body.sidebar-hidden .layout {
  grid-template-columns: 0 1fr;
}

body.sidebar-hidden .sidebar {
  transform: translateX(-100%);
}

.lesson-content p code,
.lesson-content li code {
  background: var(--code-inline-bg);
  border: 1px solid var(--code-inline-border);
  border-radius: 6px;
  padding: 1px 6px;
}

.lesson-content a {
  color: var(--accent);
}

.lesson-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
}

.lesson-content th,
.lesson-content td {
  border: 1px solid var(--line);
  padding: 10px;
}

.lesson-content blockquote {
  margin: 16px 0;
  padding: 8px 14px;
  border-left: 3px solid var(--blockquote-border);
  color: var(--blockquote-ink);
  background: var(--blockquote-bg);
}

.lesson-content img {
  max-width: 100%;
  border-radius: 10px;
}

@media (max-width: 980px) {
  body.sidebar-hidden .layout,
  body:not(.sidebar-hidden) .layout {
    grid-template-columns: 1fr;
  }

  .topbar {
    height: 48px;
    grid-template-columns: 48px 1fr 48px;
  }

  .top-lesson-title {
    font-size: 0.88rem;
    padding: 0 8px;
  }

  .menu-toggle,
  .theme-toggle {
    width: 32px;
    height: 32px;
    font-size: 0.95rem;
  }

  .layout {
    grid-template-columns: 1fr;
    min-height: auto;
    padding-top: 48px;
  }

  .sidebar {
    position: fixed;
    left: 0;
    top: 48px;
    bottom: 0;
    width: min(88vw, 340px);
    transform: translateX(-105%);
    transition: transform 0.22s ease;
    z-index: 31;
    border-right: 1px solid var(--line);
  }

  .sidebar-inner {
    padding: 14px;
  }

  .lesson-link {
    padding: 11px 10px;
    font-size: 0.98rem;
  }

  body:not(.sidebar-hidden) .sidebar {
    transform: translateX(0%);
  }

  body:not(.sidebar-hidden)::before {
    content: "";
    position: fixed;
    inset: 48px 0 0 0;
    background: rgba(0, 0, 0, 0.35);
    z-index: 30;
  }

  body.light-theme:not(.sidebar-hidden)::before {
    background: rgba(0, 0, 0, 0.2);
  }

  .content {
    padding: 14px 14px 18px;
    width: 100%;
    max-width: 100%;
  }

  .lesson-header {
    margin-bottom: 14px;
    padding-bottom: 10px;
  }

  .breadcrumb {
    font-size: 0.82rem;
  }

  .lesson-actions {
    flex-wrap: wrap;
    gap: 6px;
  }

  .ghost-btn {
    flex: 1 1 48%;
    min-height: 38px;
  }

  .lesson-content {
    font-size: 0.98rem;
    line-height: 1.66;
    padding-bottom: 24px;
    width: 100%;
    max-width: 100%;
  }

  .lesson-content h1 {
    font-size: 1.5rem;
  }

  .lesson-content h2 {
    font-size: 1.25rem;
  }

  .lesson-content h3 {
    font-size: 1.06rem;
  }

  .lesson-content pre {
    padding: 10px;
    border-radius: 6px;
    font-size: 0.9rem;
  }

  .lesson-content table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }

  .lesson-content th,
  .lesson-content td {
    padding: 8px;
  }

  .lesson-content blockquote {
    margin: 12px 0;
    padding: 8px 10px;
  }
}

@media (max-width: 640px) {
  body.sidebar-hidden .layout,
  body:not(.sidebar-hidden) .layout {
    grid-template-columns: 1fr;
  }

  .top-lesson-title {
    font-size: 0.82rem;
  }

  .sidebar {
    width: 92vw;
  }

  .content {
    padding: 12px 10px 16px;
    width: 100%;
  }

  .ghost-btn {
    flex: 1 1 100%;
  }

  .lesson-content {
    font-size: 0.95rem;
  }

  .lesson-content pre {
    font-size: 0.84rem;
  }
}
