:root {
  --bg: hsl(0 0% 98%);
  --fg: hsl(0 0% 12%);
  --muted: hsl(0 0% 45%);
  --border: hsl(0 0% 85%);
  --link: hsl(217 60% 45%);
  --sidebar-width: 240px;
  --sidebar-active: hsl(0 0% 12%);
  --sidebar-hover-bg: hsl(0 0% 93%);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 1rem;
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
}

/* Layout */
.layout {
  display: flex;
  max-width: 960px;
  margin: 0 auto;
}

/* Sidebar */
#sidebar {
  position: sticky;
  top: 0;
  align-self: flex-start;
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  height: 100vh;
  overflow-y: auto;
  padding: 3rem 1.25rem 3rem 1.5rem;
  border-right: 1px solid var(--border);
}

#sidebar .sidebar-title {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 1.25rem;
}

#sidebar nav {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
}

#sidebar nav a {
  display: block;
  font-size: 0.8125rem;
  line-height: 1.4;
  color: var(--muted);
  text-decoration: none;
  padding: 0.375rem 0.625rem;
  border-radius: 0.375rem;
  transition: color 0.15s, background 0.15s;
}

#sidebar nav a:hover {
  color: var(--fg);
  background: var(--sidebar-hover-bg);
}

#sidebar nav a.active {
  color: var(--sidebar-active);
  font-weight: 600;
  background: var(--sidebar-hover-bg);
}

#sidebar nav a.depth-3 {
  padding-left: 1.25rem;
  font-size: 0.75rem;
  opacity: 0.75;
}

#sidebar nav a.depth-3:hover {
  padding-left: 1.25rem;
}

/* Content */
#content {
  flex: 1;
  min-width: 0;
  max-width: 640px;
  padding: 3rem 1.5rem 6rem 3rem;
}

#content h1 {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  line-height: 1.2;
  margin-bottom: 0.25em;
}

#content h1 + p {
  color: var(--muted);
  font-size: 1.125rem;
  margin-top: 0;
}

#content h2 {
  font-size: 1.375rem;
  font-weight: 600;
  letter-spacing: -0.015em;
  line-height: 1.3;
  margin-top: 2.5em;
  margin-bottom: 0.75em;
  scroll-margin-top: 1.5rem;
}

#content h3 {
  font-size: 1.1rem;
  font-weight: 600;
  line-height: 1.4;
  margin-top: 1.75em;
  margin-bottom: 0.5em;
  scroll-margin-top: 1.5rem;
}

#content p {
  margin-bottom: 1.25em;
}

#content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2em 0;
}

#content ul {
  list-style-type: disc;
  padding-left: 1.5em;
  margin-bottom: 1.25em;
}

#content li {
  margin-bottom: 0.5em;
}

#content strong {
  font-weight: 600;
}

#content a {
  color: var(--link);
  text-decoration: underline;
  text-underline-offset: 2px;
}

#content a:hover {
  opacity: 0.75;
}

#content code {
  font-size: 0.875em;
  background: hsl(0 0% 85% / 0.4);
  padding: 0.15em 0.35em;
  border-radius: 0.25em;
}

/* Mobile */
@media (max-width: 768px) {
  .layout {
    flex-direction: column;
  }

  #sidebar {
    position: relative;
    width: 100%;
    min-width: 100%;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 1.5rem 1.5rem 1.25rem;
  }

  #sidebar nav a.depth-3 {
    display: none;
  }

  #sidebar nav {
    display: flex;
    flex-wrap: wrap;
    gap: 0;
  }

  #sidebar nav a {
    padding: 0.25rem 0.5rem;
  }

  #sidebar nav a:hover {
    padding-left: 0.5rem;
  }

  #content {
    padding: 2rem 1.5rem 4rem;
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: hsl(0 0% 8%);
    --fg: hsl(0 0% 88%);
    --muted: hsl(0 0% 55%);
    --border: hsl(0 0% 22%);
    --link: hsl(217 60% 65%);
    --sidebar-active: hsl(0 0% 92%);
    --sidebar-hover-bg: hsl(0 0% 14%);
  }
}
