:root {
  --sidebar-width: 270px;
  --topbar-height: 52px;
  --accent: #2f6fed;
  --accent-dark: #1c4fc2;
  --text: #1f2328;
  --text-muted: #57606a;
  --border: #d8dee4;
  --bg: #ffffff;
  --bg-sidebar: #f6f8fa;
  --code-bg: #f0f2f5;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  font-size: 16px;
  line-height: 1.6;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Sidebar ---------- */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 20;
  transition: transform 0.2s ease;
}

.sidebar-brand {
  display: block;
  font-weight: 700;
  font-size: 1.05rem;
  padding: 14px 16px 14px 54px;
  border-bottom: 1px solid var(--border);
  color: var(--text) !important;
  text-decoration: none !important;
}

.sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0 16px;
}

.sidebar-section {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 14px 16px 6px;
}

.sidebar-nav {
  list-style: none;
  margin: 0;
  padding: 0;
}

.sidebar-nav li a {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 16px;
  color: var(--text) !important;
  font-size: 0.92rem;
  border-left: 3px solid transparent;
  text-decoration: none !important;
}

.sidebar-nav li a:hover {
  background: rgba(47, 111, 237, 0.08);
}

.sidebar-nav li a.active {
  background: rgba(47, 111, 237, 0.12);
  border-left-color: var(--accent);
  color: var(--accent-dark) !important;
  font-weight: 600;
}

.lab-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 4px;
  border-radius: 5px;
  background: #e4e8ee;
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 700;
  flex-shrink: 0;
}

.sidebar-nav li a.active .lab-num {
  background: var(--accent);
  color: #fff;
}

.sidebar-footer {
  display: block;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  font-size: 0.82rem;
  color: var(--text-muted) !important;
}

/* ---------- Topbar + content ---------- */
.page {
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  transition: margin-left 0.2s ease;
}

.topbar {
  position: sticky;
  top: 0;
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  padding: 0 20px 0 56px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}

.topbar-title {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.content {
  max-width: 860px;
  padding: 28px 32px 64px;
}

.back-link {
  display: inline-block;
  margin-bottom: 18px;
  font-size: 0.88rem;
  font-weight: 600;
}

/* Sidebar toggle button (always visible, fixed) */
.sidebar-toggle {
  position: fixed;
  top: 10px;
  left: 14px;
  z-index: 30;
  width: 32px;
  height: 32px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  cursor: pointer;
}

.sidebar-toggle span {
  display: block;
  width: 16px;
  height: 2px;
  background: var(--text);
  border-radius: 1px;
}

.sidebar-scrim {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  z-index: 15;
}

/* Collapsed state */
body.sidebar-collapsed .sidebar {
  transform: translateX(-100%);
}

body.sidebar-collapsed .page {
  margin-left: 0;
}

/* ---------- Prose ---------- */
.content h1, .content h2, .content h3 {
  line-height: 1.25;
}

.content h1 { font-size: 1.85rem; margin-top: 0; }
.content h2 { font-size: 1.4rem; margin-top: 2em; border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.content h3 { font-size: 1.1rem; }

.content table {
  border-collapse: collapse;
  width: 100%;
  margin: 1em 0;
  font-size: 0.92rem;
}

.content th, .content td {
  border: 1px solid var(--border);
  padding: 8px 10px;
  text-align: left;
  vertical-align: top;
}

.content th {
  background: var(--bg-sidebar);
}

.content code {
  background: var(--code-bg);
  padding: 2px 5px;
  border-radius: 4px;
  font-size: 0.88em;
}

.content pre {
  background: var(--code-bg);
  padding: 14px 16px;
  border-radius: 8px;
  overflow-x: auto;
}

.content pre code {
  background: none;
  padding: 0;
}

.content blockquote {
  border-left: 3px solid var(--accent);
  margin: 1em 0;
  padding: 2px 16px;
  color: var(--text-muted);
  background: var(--bg-sidebar);
}

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .sidebar {
    box-shadow: 2px 0 12px rgba(0,0,0,0.15);
  }

  .page {
    margin-left: 0;
  }

  .content {
    padding: 24px 18px 48px;
  }

  /* On small screens, an open sidebar overlays the content and dims it. */
  body:not(.sidebar-collapsed) .sidebar-scrim {
    display: block;
  }
}
