/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* Colors – light theme */
  --bg: #ffffff;
  --bg-sidebar: #f8f9fb;
  --bg-code: #f4f5f7;
  --bg-code-block: #1e1e2e;
  --bg-hero: linear-gradient(135deg, #1a56db 0%, #7c3aed 100%);
  --bg-card: #ffffff;
  --bg-hover: #eef1f6;

  --text: #1a1a2e;
  --text-secondary: #4a5568;
  --text-muted: #718096;
  --text-sidebar: #374151;
  --text-sidebar-active: #1a56db;
  --text-code: #e06c75;
  --text-on-dark: #f1f5f9;
  --text-on-hero: #ffffff;

  --border: #e2e8f0;
  --border-light: #f0f0f5;

  --accent: #1a56db;
  --accent-hover: #1648b8;
  --accent-light: #e8efff;

  --success: #10b981;
  --warning: #f59e0b;
  --error: #ef4444;
  --info: #3b82f6;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.07);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.1);

  --radius: 8px;
  --radius-lg: 12px;

  --sidebar-width: 280px;
  --header-height: 60px;
  --toc-width: 220px;

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
}

/* Dark theme */
[data-theme="dark"] {
  --bg: #0f1117;
  --bg-sidebar: #161822;
  --bg-code: #1e2030;
  --bg-code-block: #1e2030;
  --bg-card: #1a1c2a;
  --bg-hover: #252840;

  --text: #e2e8f0;
  --text-secondary: #a0aec0;
  --text-muted: #718096;
  --text-sidebar: #cbd5e0;
  --text-sidebar-active: #63b3ed;
  --text-code: #f78c6c;

  --border: #2d3148;
  --border-light: #252840;

  --accent: #63b3ed;
  --accent-hover: #4299e1;
  --accent-light: #1e2a4a;
}

/* ===== Skip link (accessibility) ===== */
.skip-link {
  position: absolute;
  top: -100%;
  left: 16px;
  background: var(--accent);
  color: white;
  padding: 8px 16px;
  border-radius: var(--radius);
  z-index: 9999;
  font-weight: 600;
  font-size: 0.9rem;
  text-decoration: none;
  transition: top 0.2s;
}
.skip-link:focus {
  top: 8px;
}

/* ===== Typography ===== */
html { font-size: 16px; scroll-behavior: smooth; }

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

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

/* ===== Header ===== */
.header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  z-index: 100;
  backdrop-filter: blur(12px);
  background: rgba(255,255,255,0.85);
}
[data-theme="dark"] .header {
  background: rgba(15,17,23,0.85);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: 1600px;
  margin: 0 auto;
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  font-weight: 700;
  font-size: 1.2rem;
  color: var(--text);
}
.header-logo svg {
  width: 28px;
  height: 28px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-search {
  position: relative;
}
.header-search input {
  width: 240px;
  padding: 8px 12px 8px 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: 0.875rem;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.header-search input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}
.header-search .search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  width: 16px;
  height: 16px;
}

.btn-icon {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px;
  cursor: pointer;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}
.btn-icon:hover {
  background: var(--bg-hover);
  color: var(--text);
}
.btn-icon svg { width: 18px; height: 18px; }

.github-link {
  text-decoration: none;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  padding: 8px;
  border-radius: var(--radius);
  transition: color 0.2s;
}
.github-link:hover { color: var(--text); }
.github-link svg { width: 22px; height: 22px; }

/* ===== Sidebar ===== */
.sidebar {
  position: fixed;
  top: var(--header-height);
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 20px 0;
  z-index: 50;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
  transition: transform 0.3s ease;
}

.sidebar-section {
  margin-bottom: 8px;
}

.sidebar-heading {
  padding: 8px 24px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  user-select: none;
}

.sidebar-link {
  display: flex;
  align-items: center;
  padding: 7px 24px 7px 28px;
  font-size: 0.875rem;
  color: var(--text-sidebar);
  text-decoration: none;
  transition: all 0.15s;
  border-left: 3px solid transparent;
  cursor: pointer;
}
.sidebar-link:hover {
  background: var(--bg-hover);
  color: var(--text);
}
.sidebar-link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
.sidebar-link.active {
  color: var(--text-sidebar-active);
  background: var(--accent-light);
  border-left-color: var(--accent);
  font-weight: 600;
}

/* Mobile sidebar toggle */
.sidebar-toggle {
  display: none;
  position: fixed;
  bottom: 20px;
  left: 20px;
  z-index: 200;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 50%;
  width: 48px;
  height: 48px;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  align-items: center;
  justify-content: center;
}
.sidebar-toggle svg { width: 24px; height: 24px; }

/* ===== Main Content ===== */
.main {
  margin-left: var(--sidebar-width);
  margin-top: var(--header-height);
  flex: 1;
  min-width: 0;
  position: relative;
}

.content {
  max-width: 820px;
  margin: 0 auto;
  padding: 40px 48px 80px;
}

/* ===== Table of Contents (right sidebar) ===== */
.toc-aside {
  position: fixed;
  top: var(--header-height);
  right: 0;
  width: var(--toc-width);
  height: calc(100vh - var(--header-height));
  padding: 32px 16px 32px 0;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.toc-inner {
  border-left: 1px solid var(--border-light);
  padding-left: 16px;
}

.toc-title {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 12px;
}

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

.toc-link {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-decoration: none;
  padding: 4px 0;
  line-height: 1.4;
  transition: color 0.15s;
  border-left: 2px solid transparent;
  margin-left: -17px;
  padding-left: 15px;
}
.toc-link:hover {
  color: var(--text);
}
.toc-link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.toc-link.active {
  color: var(--accent);
  border-left-color: var(--accent);
}
.toc-link.toc-h3 {
  padding-left: 27px;
  font-size: 0.75rem;
}

/* When TOC is visible, adjust content max-width */
@media (min-width: 1280px) {
  .content {
    margin-left: 48px;
    margin-right: calc(var(--toc-width) + 48px);
  }
}

/* ===== Content Styles ===== */
.content h1 {
  font-size: 2.25rem;
  font-weight: 800;
  line-height: 1.2;
  margin-bottom: 12px;
  letter-spacing: -0.02em;
  color: var(--text);
}
.content h2 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-top: 48px;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-light);
  letter-spacing: -0.01em;
  scroll-margin-top: calc(var(--header-height) + 16px);
}
.content h3 {
  font-size: 1.2rem;
  font-weight: 600;
  margin-top: 32px;
  margin-bottom: 12px;
  scroll-margin-top: calc(var(--header-height) + 16px);
}
.content h4 {
  font-size: 1.05rem;
  font-weight: 600;
  margin-top: 24px;
  margin-bottom: 8px;
}

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

.content a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
  transition: color 0.15s;
}
.content a:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}
.content a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.content ul, .content ol {
  margin-bottom: 16px;
  padding-left: 24px;
}
.content li {
  margin-bottom: 6px;
  color: var(--text-secondary);
}
.content li strong {
  color: var(--text);
}

.content > .subtitle {
  font-size: 1.15rem;
  color: var(--text-muted);
  margin-bottom: 32px;
  line-height: 1.6;
}

/* Inline code */
.content code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background: var(--bg-code);
  color: var(--text-code);
  padding: 2px 6px;
  border-radius: 4px;
}

/* Code blocks */
.content pre {
  background: var(--bg-code-block);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 20px;
  overflow-x: auto;
  border: 1px solid var(--border);
  position: relative;
}
.content pre code {
  background: none;
  color: #abb2bf;
  padding: 0;
  font-size: 0.85rem;
  line-height: 1.6;
}
[data-theme="dark"] .content pre {
  border-color: var(--border);
}

/* Prism.js overrides */
.content pre[class*="language-"],
.content code[class*="language-"] {
  background: var(--bg-code-block);
  color: #abb2bf;
  text-shadow: none;
}


/* ===== Tables ===== */
.content table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 24px;
  font-size: 0.9rem;
}
.content th {
  text-align: left;
  padding: 10px 14px;
  background: var(--bg-code);
  border: 1px solid var(--border);
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--text);
}
.content td {
  padding: 10px 14px;
  border: 1px solid var(--border);
  color: var(--text-secondary);
}

/* ===== Callouts / Admonitions ===== */
.callout {
  padding: 16px 20px;
  border-radius: var(--radius);
  margin-bottom: 20px;
  border-left: 4px solid;
  font-size: 0.9rem;
}
.callout p { margin-bottom: 0; }
.callout-title {
  font-weight: 700;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}

.callout-info {
  background: #eff6ff;
  border-color: var(--info);
  color: #1e40af;
}
[data-theme="dark"] .callout-info {
  background: #172554;
  color: #93c5fd;
}

.callout-tip {
  background: #ecfdf5;
  border-color: var(--success);
  color: #065f46;
}
[data-theme="dark"] .callout-tip {
  background: #052e16;
  color: #6ee7b7;
}

.callout-warning {
  background: #fffbeb;
  border-color: var(--warning);
  color: #92400e;
}
[data-theme="dark"] .callout-warning {
  background: #451a03;
  color: #fcd34d;
}

/* ===== Cards Grid ===== */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  text-decoration: none;
  color: var(--text);
  transition: all 0.2s;
  cursor: pointer;
}
.card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
  text-decoration: none;
}
.card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.card-icon {
  font-size: 1.5rem;
  margin-bottom: 12px;
}
.card h3 {
  font-size: 1rem;
  margin-top: 0;
  margin-bottom: 8px;
  font-weight: 600;
}
.card p {
  font-size: 0.875rem;
  margin-bottom: 0;
  color: var(--text-muted);
}

/* ===== Hero section (home page) ===== */
.hero {
  background: var(--bg-hero);
  color: var(--text-on-hero);
  padding: 64px 48px;
  border-radius: var(--radius-lg);
  margin-bottom: 48px;
  text-align: center;
}
.hero h1 {
  font-size: 2.75rem;
  font-weight: 800;
  margin-bottom: 16px;
  color: white;
}
.hero p {
  font-size: 1.15rem;
  opacity: 0.9;
  max-width: 640px;
  margin: 0 auto 28px;
  color: rgba(255,255,255,0.9);
}
.hero-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 24px;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 0.95rem;
  text-decoration: none;
  transition: all 0.2s;
  cursor: pointer;
  border: none;
}
.btn-primary {
  background: white;
  color: #1a56db;
}
.btn-primary:hover {
  background: #f0f4ff;
  text-decoration: none;
  transform: translateY(-1px);
}
.btn-secondary {
  background: rgba(255,255,255,0.15);
  color: white;
  border: 1px solid rgba(255,255,255,0.3);
}
.btn-secondary:hover {
  background: rgba(255,255,255,0.25);
  text-decoration: none;
}

/* Feature pills on home */
.features-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
  margin-bottom: 40px;
}
.feature {
  padding: 28px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-card);
}
.feature-icon {
  font-size: 1.75rem;
  margin-bottom: 12px;
}
.feature h3 {
  font-size: 1.05rem;
  margin-top: 0;
  margin-bottom: 8px;
}
.feature p {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin: 0;
}

/* ===== Demo GIF ===== */
.demo-container {
  margin: 32px 0;
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
}
.demo-container img {
  width: 100%;
  height: auto;
  display: block;
}

/* ===== Page navigation (prev/next) ===== */
.page-nav {
  display: flex;
  justify-content: space-between;
  margin-top: 64px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
  gap: 16px;
}
.page-nav a {
  display: flex;
  flex-direction: column;
  padding: 16px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  transition: all 0.2s;
  flex: 1;
  max-width: 50%;
}
.page-nav a:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-sm);
  text-decoration: none;
}
.page-nav .nav-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}
.page-nav .nav-title {
  font-weight: 600;
  color: var(--accent);
}
.page-nav .next { text-align: right; margin-left: auto; }

/* ===== Search overlay ===== */
.search-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  align-items: flex-start;
  justify-content: center;
  padding-top: 100px;
}
.search-overlay.active { display: flex; }
.search-modal {
  background: var(--bg);
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 600px;
  max-height: 70vh;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
}
.search-modal input {
  width: 100%;
  padding: 16px 20px;
  border: none;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  outline: none;
}
.search-results {
  overflow-y: auto;
  max-height: calc(70vh - 60px);
  padding: 8px;
}
.search-result {
  padding: 12px 16px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s;
}
.search-result:hover,
.search-result:focus {
  background: var(--bg-hover);
  outline: none;
}
.search-result-title {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text);
}
.search-result-section {
  font-size: 0.8rem;
  color: var(--text-muted);
}
.search-result-match {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 2px;
  font-style: italic;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.search-empty {
  padding: 24px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* ===== Responsive ===== */
@media (max-width: 1280px) {
  .toc-aside { display: none; }
}

@media (max-width: 1024px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .sidebar-toggle {
    display: flex;
  }
  .main {
    margin-left: 0;
  }
  .content {
    padding: 32px 24px 80px;
  }
  .hero {
    padding: 40px 24px;
  }
  .hero h1 { font-size: 2rem; }
}

@media (max-width: 640px) {
  .header-search input { width: 160px; }
  .content h1 { font-size: 1.75rem; }
  .cards { grid-template-columns: 1fr; }
  .features-grid { grid-template-columns: 1fr; }
  .page-nav { flex-direction: column; }
  .page-nav a { max-width: 100%; }
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ===== Transitions ===== */
.content { animation: fadeIn 0.2s ease; }
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== Keyboard shortcut badge ===== */
kbd {
  display: inline-block;
  padding: 2px 6px;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-muted);
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: 4px;
  line-height: 1.4;
}

/* ===== Copy button on code blocks ===== */
.copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(255,255,255,0.1);
  border: none;
  border-radius: 4px;
  color: #718096;
  cursor: pointer;
  padding: 4px 8px;
  font-size: 0.75rem;
  font-family: var(--font-mono);
  opacity: 0;
  transition: opacity 0.2s;
}
pre:hover .copy-btn { opacity: 1; }
.copy-btn:hover { background: rgba(255,255,255,0.2); color: #a0aec0; }
.copy-btn.copied { color: var(--success); }

/* ===== Print stylesheet ===== */
@media print {
  .header, .sidebar, .sidebar-toggle, .toc-aside,
  .search-overlay, .page-nav, .copy-btn, .hero-buttons {
    display: none !important;
  }
  .main {
    margin-left: 0 !important;
    margin-top: 0 !important;
  }
  .content {
    max-width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
  }
  .content pre {
    border: 1px solid #ccc;
    background: #f8f8f8 !important;
  }
  .content pre code { color: #333 !important; }
  .callout { break-inside: avoid; }
  a[href]::after {
    content: " (" attr(href) ")";
    font-size: 0.8em;
    color: #666;
  }
  a[href^="#"]::after,
  a[href^="javascript:"]::after {
    content: "";
  }
}
