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

:root {
  --bg: #0a0a0a;
  --bg-sidebar: #0f0f0f;
  --bg-card: #151515;
  --bg-card-hover: #1c1c1c;
  --bg-code: #141414;
  --bg-callout: #141414;
  --bg-diagram: #0e0e0e;
  --border: #222222;
  --border-light: #2e2e2e;
  --border-diagram: #333333;
  --text: #d4d4d4;
  --text-muted: #808080;
  --text-dim: #555555;
  --accent: #f0f0f0;
  --accent-muted: #c0c0c0;
  --link: #a0a0a0;
  --link-hover: #ffffff;
  --diagram-line: #606060;
  --diagram-label: #b0b0b0;
  --diagram-box-bg: #181818;
  --diagram-box-border: #3a3a3a;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'SF Mono', Consolas, monospace;
  --sidebar-w: 280px;
  --content-max: 860px;
}

html { font-size: 15px; }

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Layout */
.layout {
  display: flex;
  min-height: 100vh;
}

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

.sidebar-header {
  padding: 20px 20px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
}

.logo {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 2.5px;
  color: var(--accent);
  text-decoration: none;
}

.logo-dot { color: var(--text-dim); }

.sidebar-toggle {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  display: none;
}

.sidebar-toggle:hover { color: var(--accent); background: var(--bg-card); }

.sidebar-search {
  padding: 12px 16px;
}

.sidebar-search input {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  font-family: var(--font-body);
  outline: none;
  transition: border-color 0.15s;
}

.sidebar-search input::placeholder { color: var(--text-dim); }
.sidebar-search input:focus { border-color: var(--text-muted); }

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

.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-track { background: transparent; }
.sidebar-nav::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.sidebar-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
}

.sidebar-footer a {
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.1s;
}

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

.sidebar-license {
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.5px;
}

.nav-group { margin-bottom: 4px; }

.nav-group-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 20px;
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
  list-style: none;
}

.nav-group-title::-webkit-details-marker { display: none; }

.nav-group-title .nav-count {
  font-size: 10px;
  color: var(--text-dim);
  background: var(--bg);
  padding: 1px 6px;
  border-radius: 10px;
  font-family: var(--font-mono);
}

.nav-list {
  list-style: none;
  padding: 0 8px 8px;
}

.nav-list li a {
  display: block;
  padding: 5px 12px;
  font-size: 13px;
  color: var(--text-muted);
  text-decoration: none;
  border-radius: 4px;
  transition: all 0.1s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-list li a:hover {
  color: var(--text);
  background: var(--bg-card);
}

.nav-list li.active a {
  color: var(--accent);
  background: var(--bg-card);
  font-weight: 500;
}

/* Main content */
.content {
  flex: 1;
  margin-left: var(--sidebar-w);
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 48px 48px 0;
}

.article {
  max-width: var(--content-max);
  width: 100%;
}

/* Typography */
.article h1 {
  font-family: var(--font-body);
  font-size: 2rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 8px;
  line-height: 1.2;
  letter-spacing: -0.025em;
}

.article h2 {
  font-family: var(--font-body);
  font-size: 1.3rem;
  font-weight: 600;
  color: var(--accent-muted);
  margin-top: 48px;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  letter-spacing: -0.01em;
}

.article h3 {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
  margin-top: 32px;
  margin-bottom: 12px;
}

.article h4 {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  margin-top: 24px;
  margin-bottom: 8px;
}

.article p {
  margin-bottom: 16px;
  color: var(--text);
}

.article a {
  color: var(--link);
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-color: var(--border-light);
  transition: all 0.1s;
}

.article a:hover {
  color: var(--link-hover);
  text-decoration-color: var(--text-muted);
}

.article strong { color: var(--accent); font-weight: 600; }

.article em { color: var(--text-muted); font-style: italic; }

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

.article li {
  margin-bottom: 4px;
  color: var(--text);
}

.article li::marker { color: var(--text-dim); }

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

/* Tables */
.article table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0 24px;
  font-size: 13px;
  overflow-x: auto;
  display: block;
}

.article thead th {
  background: var(--bg-card);
  color: var(--accent-muted);
  font-weight: 600;
  text-align: left;
  padding: 10px 12px;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  font-family: var(--font-body);
}

.article tbody td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: top;
}

.article tbody tr:hover { background: var(--bg-card); }

/* Code */
.article code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: var(--bg-code);
  padding: 2px 6px;
  border-radius: 3px;
  color: var(--accent-muted);
  border: 1px solid var(--border);
}

.article pre {
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px 20px;
  overflow-x: auto;
  margin: 16px 0 24px;
  font-size: 13px;
  line-height: 1.55;
}

.article pre code {
  background: none;
  padding: 0;
  border-radius: 0;
  border: none;
  color: var(--text);
}

/* ========================================
   DIAGRAMS - Modal-inspired rendered style
   ======================================== */
.article pre.diagram {
  background: var(--bg-diagram);
  border: 1px solid var(--border-diagram);
  border-radius: 16px;
  padding: 32px 28px 28px;
  margin: 28px 0 36px;
  position: relative;
  overflow-x: auto;
  box-shadow:
    0 0 0 1px rgba(255,255,255,0.03),
    0 8px 32px rgba(0,0,0,0.5),
    0 2px 6px rgba(0,0,0,0.3);
}

.article pre.diagram code {
  color: var(--text);
  font-size: 13px;
  line-height: 1.5;
  letter-spacing: 0;
}

/* JS-injected spans for diagram elements */
.article pre.diagram .d-border {
  color: #3d3d3d;
}

.article pre.diagram .d-arrow {
  color: #707070;
}

.article pre.diagram .d-label {
  color: #e8e8e8;
  font-weight: 500;
}

.article pre.diagram .d-sublabel {
  color: #909090;
}

.article pre.diagram .d-bracket {
  color: #606060;
}

/* Rendered box nodes (JS-created) */
.dg-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  padding: 8px 0;
}

.dg-row {
  display: flex;
  align-items: stretch;
  justify-content: center;
  gap: 16px;
  flex-wrap: wrap;
}

.dg-node {
  background: #161616;
  border: 1px solid #333;
  border-radius: 10px;
  padding: 14px 18px;
  min-width: 180px;
  max-width: 320px;
  transition: border-color 0.15s;
}

.dg-node:hover {
  border-color: #505050;
}

.dg-node-title {
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 600;
  color: #e0e0e0;
  letter-spacing: 0.3px;
  margin-bottom: 6px;
  text-transform: uppercase;
}

.dg-node-items {
  font-family: var(--font-body);
  font-size: 12px;
  color: #787878;
  line-height: 1.5;
}

.dg-node-items span {
  display: block;
  padding-left: 10px;
  position: relative;
}

.dg-node-items span::before {
  content: '';
  position: absolute;
  left: 0;
  top: 8px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: #404040;
}

.dg-arrow {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px 0;
  color: #444;
}

.dg-arrow svg {
  width: 20px;
  height: 24px;
}

.dg-arrow-h {
  padding: 0 4px;
  display: flex;
  align-items: center;
}

.dg-arrow-h svg {
  width: 28px;
  height: 16px;
}

.dg-section {
  border: 1px solid #2a2a2a;
  border-radius: 12px;
  padding: 16px 14px 12px;
  position: relative;
  margin: 4px 0;
  background: rgba(255,255,255,0.01);
}

.dg-section-label {
  position: absolute;
  top: -9px;
  left: 16px;
  background: var(--bg-diagram);
  padding: 0 8px;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  color: #555;
  letter-spacing: 1px;
  text-transform: uppercase;
}

.dg-label {
  font-family: var(--font-body);
  font-size: 12px;
  color: #666;
  text-align: center;
  padding: 2px 0;
  font-style: italic;
}

/* Rendered diagram wrapper */
.diagram-rendered {
  background: var(--bg-diagram);
  border: 1px solid var(--border-diagram);
  border-radius: 16px;
  padding: 24px 20px;
  margin: 28px 0 4px;
  box-shadow:
    0 0 0 1px rgba(255,255,255,0.03),
    0 8px 32px rgba(0,0,0,0.5),
    0 2px 6px rgba(0,0,0,0.3);
  overflow-x: auto;
}

.diagram-toggle {
  display: block;
  margin: 0 0 32px auto;
  background: none;
  border: none;
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.5px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  transition: all 0.15s;
}

.diagram-toggle:hover {
  color: var(--text-muted);
  background: var(--bg-card);
}

/* Callouts */
.callout {
  border-left: 3px solid var(--border-light);
  background: var(--bg-callout);
  padding: 16px 20px;
  margin: 16px 0 24px;
  border-radius: 0 8px 8px 0;
}

.callout-important { border-left-color: var(--accent); }
.callout-info { border-left-color: var(--text-muted); }
.callout-success { border-left-color: var(--accent-muted); }

.callout p {
  margin-bottom: 8px;
  font-size: 14px;
}

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

/* Blockquotes */
.article blockquote {
  border-left: 3px solid var(--border-light);
  padding: 12px 20px;
  margin: 16px 0;
  color: var(--text-muted);
  background: var(--bg-callout);
  border-radius: 0 8px 8px 0;
}

.article blockquote p { color: var(--text-muted); margin-bottom: 8px; }
.article blockquote p:last-child { margin-bottom: 0; }

.broken-link {
  color: var(--text-dim);
  text-decoration: line-through;
}

/* Index page */
.index-hero {
  margin-bottom: 48px;
  padding-bottom: 32px;
  border-bottom: 1px solid var(--border);
}

.index-hero h1 {
  font-size: 2.6rem;
  margin-bottom: 12px;
  letter-spacing: -0.035em;
  font-weight: 700;
}

.index-hero p {
  font-size: 1.05rem;
  color: var(--text-muted);
  max-width: 640px;
  line-height: 1.65;
}

.hero-meta {
  margin-top: 16px;
  font-size: 13px;
  font-family: var(--font-mono);
  color: var(--text-dim);
  letter-spacing: 0.02em;
}

.hero-meta a {
  color: var(--text-muted);
  text-decoration: none;
  border-bottom: 1px solid var(--border);
  transition: all 0.1s;
}

.hero-meta a:hover { color: var(--accent); border-bottom-color: var(--text-muted); }

.index-section {
  margin-bottom: 48px;
}

.index-section h2 {
  margin-top: 0;
  border-bottom: none;
  padding-bottom: 0;
  margin-bottom: 4px;
}

.section-desc {
  color: var(--text-dim);
  font-size: 14px;
  margin-bottom: 20px;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 10px;
}

.card {
  display: block;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px 18px;
  text-decoration: none;
  transition: all 0.15s;
}

.card:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-light);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.card h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
  margin: 0 0 6px;
}

.card p {
  font-size: 12px;
  color: var(--text-dim);
  margin: 0;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* About page */
.about-page h1 {
  font-size: 2rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 16px;
  letter-spacing: -0.025em;
}

.about-page > p {
  color: var(--text);
  margin-bottom: 12px;
  max-width: 640px;
  line-height: 1.7;
}

.about-section {
  margin-top: 40px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}

.about-section h2 {
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--accent-muted);
  margin-bottom: 12px;
  letter-spacing: -0.01em;
}

.author-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px 24px;
  display: inline-block;
}

.author-info h3 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 10px;
}

.author-links {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
}

.author-links a {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 1px;
  transition: all 0.1s;
}

.author-links a:hover { color: var(--accent); border-bottom-color: var(--text-muted); }

.bibtex {
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px 20px;
  overflow-x: auto;
  font-size: 12px;
  line-height: 1.5;
}

.bibtex code {
  font-family: var(--font-mono);
  color: var(--text);
  background: none;
  padding: 0;
  border: none;
}

.license-block {
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px 20px;
  font-size: 11.5px;
  line-height: 1.6;
  color: var(--text-muted);
  margin-top: 12px;
}

.license-block code {
  font-family: var(--font-mono);
  color: var(--text-muted);
  background: none;
  padding: 0;
  border: none;
}

.copy-btn {
  margin-top: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.5px;
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
}

.copy-btn:hover {
  background: var(--bg-card-hover);
  color: var(--accent);
  border-color: var(--border-light);
}

.copy-btn:active { transform: scale(0.97); }

/* Footer */
.site-footer {
  max-width: var(--content-max);
  width: 100%;
  margin-top: 64px;
  padding: 32px 0;
  border-top: 1px solid var(--border);
}

.footer-inner {
  display: grid;
  grid-template-columns: 1fr 1.4fr 1fr;
  gap: 32px;
}

.footer-heading {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-dim);
  margin-bottom: 10px;
}

.footer-col p {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: 6px;
}

.footer-col strong { color: var(--text); }

.footer-links {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 6px;
}

.footer-links a {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 12px;
  transition: color 0.1s;
}

.footer-links a:hover { color: var(--accent); }

.footer-col .bibtex {
  font-size: 10px;
  padding: 10px 12px;
  line-height: 1.4;
  margin: 0;
}

.footer-col .copy-btn {
  font-size: 10px;
  padding: 4px 10px;
}

.license-text {
  font-size: 11px !important;
  color: var(--text-dim) !important;
  line-height: 1.5 !important;
}

/* Mobile */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar-toggle { display: block; }

  body.sidebar-open .sidebar {
    transform: translateX(0);
  }

  .content {
    margin-left: 0;
    padding: 24px 20px 0;
  }

  .card-grid {
    grid-template-columns: 1fr;
  }

  .footer-inner {
    grid-template-columns: 1fr;
    gap: 24px;
  }

  .author-links { flex-direction: column; gap: 6px; }
}
