:root {
  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;
  --sidebar-width: 260px;
  --toc-width: 220px;
  --content-max: 800px;
  --color-bg: #ffffff;
  --color-bg-secondary: #f8f9fa;
  --color-bg-code: #f6f8fa;
  --color-text: #1a1a2e;
  --color-text-secondary: #555;
  --color-text-muted: #888;
  --color-border: #e5e7eb;
  --color-link: #2563eb;
  --color-link-hover: #1d4ed8;
  --color-nav-active: #2563eb;
  --color-nav-active-bg: #eff6ff;
  --color-toc-active: #2563eb;
  --color-blockquote-border: #3b82f6;
  --color-blockquote-bg: #eff6ff;
  --color-table-stripe: #f8f9fa;
  --color-table-border: #e5e7eb;
  --color-details-bg: #f8f9fa;
  --color-details-border: #e5e7eb;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #0f111a;
    --color-bg-secondary: #181b2a;
    --color-bg-code: #1a1d2e;
    --color-text: #e0e0e8;
    --color-text-secondary: #aaa;
    --color-text-muted: #777;
    --color-border: #2a2d3e;
    --color-link: #60a5fa;
    --color-link-hover: #93bbfd;
    --color-nav-active: #60a5fa;
    --color-nav-active-bg: #1e293b;
    --color-toc-active: #60a5fa;
    --color-blockquote-border: #3b82f6;
    --color-blockquote-bg: #1e293b;
    --color-table-stripe: #181b2a;
    --color-table-border: #2a2d3e;
    --color-details-bg: #181b2a;
    --color-details-border: #2a2d3e;
  }
}

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

html {
  scroll-behavior: smooth;
  scroll-padding-top: 80px;
}

body {
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.7;
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
}

/* Layout */
.layout {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr var(--toc-width);
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  border-right: 1px solid var(--color-border);
  background: var(--color-bg-secondary);
  padding: 24px 0;
  z-index: 10;
}

.sidebar-header {
  padding: 0 20px 16px;
  border-bottom: 1px solid var(--color-border);
  margin-bottom: 12px;
}

.site-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 16px;
  color: var(--color-text);
  text-decoration: none;
}

.site-logo {
  flex-shrink: 0;
  border-radius: 4px;
}

.site-title-docs {
  font-weight: 400;
  color: var(--color-text-muted);
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 8px;
}

.sidebar-nav a {
  display: block;
  padding: 7px 12px;
  border-radius: 6px;
  color: var(--color-text-secondary);
  text-decoration: none;
  font-size: 14px;
  font-weight: 450;
  transition: background 0.15s, color 0.15s;
}

.sidebar-nav a:hover {
  background: var(--color-nav-active-bg);
  color: var(--color-text);
}

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

.sidebar-nav .nav-section {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
  padding: 16px 12px 4px;
  margin-top: 4px;
}

.sidebar-nav a.nav-child {
  padding-left: 24px;
  font-size: 13px;
}

/* Content */
.content {
  max-width: var(--content-max);
  width: 100%;
  margin: 0 auto;
  padding: 40px 48px 80px;
}

/* Table of Contents */
.toc {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  padding: 40px 16px 40px 0;
  border-left: 1px solid var(--color-border);
}

.toc-header {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
  padding: 0 12px 8px;
}

.toc-nav {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.toc-nav a {
  display: block;
  padding: 4px 12px;
  font-size: 13px;
  color: var(--color-text-muted);
  text-decoration: none;
  border-left: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}

.toc-nav a:hover {
  color: var(--color-text);
}

.toc-nav a.active {
  color: var(--color-toc-active);
  border-left-color: var(--color-toc-active);
}

.toc-nav a.toc-h3 {
  padding-left: 24px;
}

/* Heading anchors */
.heading-anchor {
  color: inherit;
  text-decoration: none;
}

.heading-anchor:hover {
  text-decoration: none;
  color: inherit;
}

.heading-anchor::after {
  content: "";
  margin-left: 0.3em;
  opacity: 0;
  font-weight: 400;
  color: var(--color-text-muted);
  transition: opacity 0.15s;
}

h1:hover .heading-anchor::after,
h2:hover .heading-anchor::after,
h3:hover .heading-anchor::after,
h4:hover .heading-anchor::after {
  content: "#";
  opacity: 1;
}

/* Prose */
.prose h1 {
  font-size: 2em;
  font-weight: 700;
  margin-bottom: 16px;
  line-height: 1.25;
  letter-spacing: -0.02em;
}

.prose h2 {
  font-size: 1.5em;
  font-weight: 650;
  margin-top: 48px;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--color-border);
  line-height: 1.3;
}

.prose h3 {
  font-size: 1.2em;
  font-weight: 600;
  margin-top: 32px;
  margin-bottom: 12px;
  line-height: 1.35;
}

.prose h4 {
  font-size: 1em;
  font-weight: 600;
  margin-top: 24px;
  margin-bottom: 8px;
}

.prose p {
  margin-bottom: 16px;
}

.prose a {
  color: var(--color-link);
  text-decoration: none;
  font-weight: 450;
}

.prose a:hover {
  text-decoration: underline;
  color: var(--color-link-hover);
}

.prose strong {
  font-weight: 600;
}

.prose ul,
.prose ol {
  margin-bottom: 16px;
  padding-left: 24px;
}

.prose li {
  margin-bottom: 4px;
}

.prose li > ul,
.prose li > ol {
  margin-top: 4px;
  margin-bottom: 4px;
}

.prose code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: var(--color-bg-code);
  padding: 2px 6px;
  border-radius: 4px;
}

.prose pre {
  margin-bottom: 20px;
  border-radius: 8px;
  overflow-x: auto;
  background: var(--color-bg-code);
  border: 1px solid var(--color-border);
}

.prose pre code {
  display: block;
  padding: 16px 20px;
  background: none;
  font-size: 13.5px;
  line-height: 1.6;
}

.prose pre.mermaid {
  background: transparent;
  border: none;
  text-align: center;
  padding: 20px 0;
}

.prose blockquote {
  margin-bottom: 16px;
  padding: 12px 16px;
  border-left: 3px solid var(--color-blockquote-border);
  background: var(--color-blockquote-bg);
  border-radius: 0 6px 6px 0;
  color: var(--color-text-secondary);
}

.prose blockquote p:last-child {
  margin-bottom: 0;
}

.prose table {
  width: 100%;
  margin-bottom: 20px;
  border-collapse: collapse;
  font-size: 14px;
}

.prose th {
  text-align: left;
  font-weight: 600;
  padding: 10px 14px;
  border-bottom: 2px solid var(--color-table-border);
}

.prose td {
  padding: 8px 14px;
  border-bottom: 1px solid var(--color-table-border);
}

.prose tr:nth-child(even) {
  background: var(--color-table-stripe);
}

.prose hr {
  margin: 32px 0;
  border: none;
  border-top: 1px solid var(--color-border);
}

.prose img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
}

.prose details {
  margin-bottom: 16px;
  border: 1px solid var(--color-details-border);
  border-radius: 8px;
  background: var(--color-details-bg);
}

.prose details summary {
  padding: 12px 16px;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
}

.prose details[open] summary {
  border-bottom: 1px solid var(--color-details-border);
}

.prose details > *:not(summary) {
  padding: 0 16px;
}

.prose details > p:first-of-type {
  padding-top: 12px;
}

.prose .task-list-item {
  list-style: none;
  margin-left: -24px;
}

.prose .task-list-item input[type="checkbox"] {
  margin-right: 8px;
}

/* Footer */
.content-footer {
  margin-top: 48px;
  padding-top: 24px;
  border-top: 1px solid var(--color-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.content-footer a,
.content-footer .last-updated {
  color: var(--color-text-muted);
  text-decoration: none;
  font-size: 13px;
}

.content-footer a:hover {
  color: var(--color-link);
}

/* Mobile toggle */
.sidebar-toggle-btn {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 20;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: var(--color-bg-secondary);
  border: 1px solid var(--color-border);
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--color-text);
}

/* Responsive */
@media (max-width: 1100px) {
  .toc {
    display: none;
  }
  .layout {
    grid-template-columns: var(--sidebar-width) 1fr;
  }
}

@media (max-width: 768px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .sidebar-toggle-btn {
    display: flex;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: none;
  }

  #sidebar-toggle:checked ~ .sidebar {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.15);
  }

  .content {
    padding: 60px 20px 80px;
  }
}
