:root {
  --bg: #ffffff;
  --fg: #2a2a2a;
  --muted: #6a6a6a;
  --border: #e5e5e5;
  --accent: #0a66c2;
  --code-bg: #f6f6f6;
  --sidebar-width: 240px;
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f0f10;
    --fg: #e5e5e5;
    --muted: #a0a0a0;
    --border: #2a2a2a;
    --accent: #4aa3ff;
    --code-bg: #1a1a1b;
  }
}

html[data-theme="light"] {
  --bg: #ffffff;
  --fg: #2a2a2a;
  --muted: #6a6a6a;
  --border: #e5e5e5;
  --accent: #0a66c2;
  --code-bg: #f6f6f6;
}

html[data-theme="dark"] {
  --bg: #0f0f10;
  --fg: #e5e5e5;
  --muted: #a0a0a0;
  --border: #2a2a2a;
  --accent: #4aa3ff;
  --code-bg: #1a1a1b;
}

* { box-sizing: border-box; }

html { background: var(--bg); color: var(--fg); }

body {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.65;
}

.layout {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  min-height: 100vh;
  max-width: 1280px;
  margin: 0 auto;
}

.sidebar {
  border-right: 1px solid var(--border);
  padding: 1.5rem 1rem;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar .brand {
  display: block;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 1.1rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  text-decoration: none;
  color: var(--fg);
  margin-bottom: 1.5rem;
}

.sidebar h3 {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 1.25rem 0 0.25rem;
  font-weight: 500;
}

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

.sidebar nav li a {
  display: block;
  padding: 0.2rem 0;
  color: var(--fg);
  text-decoration: none;
  font-size: 0.95rem;
}

.sidebar nav li a:hover {
  color: var(--accent);
}

main {
  padding: 2rem 2.5rem 4rem;
  max-width: 860px;
  width: 100%;
}

main article h1,
main article h2,
main article h3,
main article h4 {
  font-family: var(--font-mono);
  font-weight: 700;
  letter-spacing: -0.01em;
}

main article h1 { font-size: 1.9rem; margin: 0 0 1.5rem; line-height: 1.2; }
main article h2 { margin-top: 2.5rem; font-size: 1.3rem; }
main article h3 { margin-top: 2rem; font-size: 1.05rem; }

main article img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 1.25rem 0;
  border-radius: 4px;
  cursor: zoom-in;
}

a { color: var(--accent); }

code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: var(--code-bg);
  padding: 0.1rem 0.3rem;
  border-radius: 3px;
}

pre {
  background: var(--code-bg);
  padding: 1rem;
  border-radius: 4px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.5;
}

pre code {
  background: transparent;
  padding: 0;
  font-size: inherit;
}

table {
  border-collapse: collapse;
  margin: 1rem 0;
  width: 100%;
  font-size: 0.95rem;
}

th, td {
  border: 1px solid var(--border);
  padding: 0.5rem 0.75rem;
  text-align: left;
  vertical-align: top;
}

th { background: var(--code-bg); font-weight: 600; }

blockquote {
  border-left: 3px solid var(--border);
  padding-left: 1rem;
  margin: 1rem 0;
  color: var(--muted);
}

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

footer {
  margin-top: 4rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
  color: var(--muted);
}

footer a { color: var(--muted); }

.mermaid {
  text-align: center;
  margin: 1.5rem 0;
  cursor: zoom-in;
}

.diagram-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.9);
  z-index: 9999;
  cursor: zoom-out;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.diagram-overlay.open {
  display: flex;
}

.diagram-overlay svg {
  max-width: 95vw;
  max-height: 95vh;
  width: auto;
  height: auto;
  background: var(--bg);
  border-radius: 6px;
  padding: 1.5rem;
}

.theme-toggle {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 100;
  background: var(--code-bg);
  border: 1px solid var(--border);
  color: var(--fg);
  cursor: pointer;
  padding: 0.35rem;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  transition: border-color 0.15s;
}

.theme-toggle:hover { border-color: var(--muted); }

.theme-toggle svg {
  width: 1rem;
  height: 1rem;
}

html[data-theme="light"] .icon-sun  { display: none; }
html[data-theme="light"] .icon-moon { display: block; }
html[data-theme="dark"]  .icon-sun  { display: block; }
html[data-theme="dark"]  .icon-moon { display: none; }

@media (max-width: 768px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  main { padding: 1.5rem; }
}
