:root {
  --bg: #ffffff;
  --fg: #1f2328;
  --muted: #57606a;
  --border: #d0d7de;
  --accent: #0969da;
  --code-bg: #f6f8fa;
  --sidebar-bg: #f6f8fa;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1117;
    --fg: #e6edf3;
    --muted: #9198a1;
    --border: #30363d;
    --accent: #4493f8;
    --code-bg: #161b22;
    --sidebar-bg: #161b22;
  }
}
:root[data-theme="dark"] {
  --bg: #0d1117;
  --fg: #e6edf3;
  --muted: #9198a1;
  --border: #30363d;
  --accent: #4493f8;
  --code-bg: #161b22;
  --sidebar-bg: #161b22;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  color: var(--fg);
  background: var(--bg);
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}
.topbar h1 { font-size: 16px; margin: 0; }

.icon-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 16px;
  padding: 4px 10px;
  cursor: pointer;
  color: var(--fg);
}

.topbar h1 { flex: 1; }

#themeBtn {
  font-size: 14px;
  min-width: 40px;
}

.course-switch {
  font-size: 13px;
  text-decoration: none;
  white-space: nowrap;
}

.layout {
  display: flex;
  max-width: 1100px;
  margin: 0 auto;
}

.sidebar {
  width: 280px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  background: var(--sidebar-bg);
  height: calc(100vh - 49px);
  overflow-y: auto;
  position: sticky;
  top: 49px;
  padding: 12px;
}
.sidebar.collapsed { display: none; }

.toc-part {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin: 16px 0 6px;
  font-weight: 600;
}
.toc-part:first-child { margin-top: 4px; }

.toc-link {
  display: block;
  padding: 5px 8px;
  border-radius: 6px;
  color: var(--fg);
  text-decoration: none;
  font-size: 13px;
  line-height: 1.4;
}
.toc-link:hover { background: var(--code-bg); }
.toc-link.active {
  background: var(--accent);
  color: #fff;
}

.content {
  flex: 1;
  min-width: 0;
  padding: 24px 32px 60px;
}

article {
  max-width: 760px;
  line-height: 1.6;
}
article h1 { font-size: 28px; border-bottom: 1px solid var(--border); padding-bottom: 8px; }
article h2 { font-size: 21px; margin-top: 32px; border-bottom: 1px solid var(--border); padding-bottom: 6px; }
article h3 { font-size: 17px; margin-top: 24px; }
article p, article ul, article ol { color: var(--fg); }
article img {
  max-width: 100%;
  height: auto;
  display: block;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: zoom-in;
}
article code {
  background: var(--code-bg);
  padding: 2px 5px;
  border-radius: 4px;
  font-size: 0.9em;
}
article pre {
  background: var(--code-bg);
  padding: 12px;
  border-radius: 6px;
  overflow-x: auto;
}
article table {
  border-collapse: collapse;
  width: 100%;
  margin: 16px 0;
  font-size: 14px;
}
article th, article td {
  border: 1px solid var(--border);
  padding: 6px 10px;
  text-align: left;
}
article th { background: var(--code-bg); }
article blockquote {
  margin: 0;
  padding: 4px 16px;
  border-left: 3px solid var(--border);
  color: var(--muted);
}
article a { color: var(--accent); }

.nav-buttons {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 760px;
  margin-top: 40px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.nav-buttons button {
  padding: 8px 16px;
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
  cursor: pointer;
}
.nav-buttons button:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.nav-buttons button:disabled { opacity: 0.4; cursor: default; }
#progress { font-size: 13px; color: var(--muted); }

@media (max-width: 760px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 49px;
    height: calc(100vh - 49px);
    z-index: 9;
  }
  .content { padding: 16px; }
}
