/* ── Design tokens ─────────────────────────────────────────── */
:root {
  --bg:            #0a0e1a;
  --bg-surface:    #111827;
  --bg-raised:     #1a2235;
  --bg-code:       #0d1117;
  --fg:            #d4d8e0;
  --fg-muted:      #8a9ab5;
  --fg-dim:        #556070;
  --accent:        #7a9ec7;
  --accent-hover:  #9ab8d8;
  --accent-glow:   rgba(122, 158, 199, 0.12);
  --border:        rgba(255, 255, 255, 0.07);
  --border-accent: rgba(122, 158, 199, 0.25);
  --shadow-sm:     0 1px 4px rgba(0,0,0,0.4);
  --shadow-md:     0 4px 20px rgba(0,0,0,0.5);
  --topbar-h:      60px;
  --radius-sm:     4px;
  --radius:        8px;
  --radius-lg:     14px;
  --font:          'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono:     'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
  --toc-w:         18%;
  --guide-w:       30%;
  --content-w:     52%;
  --transition:    160ms ease;
}

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

html {
  height: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.7;
  color: var(--fg);
  background: var(--bg);
  height: 100%;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── Topbar ─────────────────────────────────────────────────── */
.topbar {
  height: var(--topbar-h);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(8px);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.topbar-logo {
  flex-shrink: 0;
  opacity: 0.9;
}

.topbar-title {
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--fg);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.powered-by {
  font-size: 0.75rem;
  color: var(--fg-dim);
  text-decoration: none;
  transition: color var(--transition);
  white-space: nowrap;
}
.powered-by:hover { color: var(--accent); }

.toc-toggle {
  display: none;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--fg-muted);
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.75rem;
  cursor: pointer;
  transition: color var(--transition), border-color var(--transition);
  font-family: var(--font);
}
.toc-toggle:hover { color: var(--fg); border-color: var(--border-accent); }

/* ── Mobile TOC dropdown ────────────────────────────────────── */
.toc-dropdown {
  display: none;
  position: fixed;
  top: var(--topbar-h);
  left: 0;
  right: 0;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  max-height: 60vh;
  overflow-y: auto;
  z-index: 90;
  padding: 0.75rem 1.25rem 1rem;
  box-shadow: var(--shadow-md);
  transform: translateY(-8px);
  opacity: 0;
  pointer-events: none;
  transition: transform var(--transition), opacity var(--transition);
}
.toc-dropdown.open {
  transform: translateY(0);
  opacity: 1;
  pointer-events: auto;
}

/* ── Layout ─────────────────────────────────────────────────── */
.layout {
  display: flex;
  height: calc(100vh - var(--topbar-h));
  overflow: hidden;
}

/* ── TOC sidebar ────────────────────────────────────────────── */
.toc-sidebar {
  width: var(--toc-w);
  min-width: 160px;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 1.5rem 0;
  flex-shrink: 0;
}

.toc-sidebar nav ul,
.toc-dropdown nav ul {
  list-style: none;
  padding-left: 0;
}

.toc-sidebar nav > ul > li > ul,
.toc-dropdown nav > ul > li > ul {
  padding-left: 0.9rem;
  margin-top: 0.1rem;
}

.toc-sidebar nav a,
.toc-dropdown nav a {
  display: block;
  padding: 0.35rem 1.25rem;
  font-size: 0.8rem;
  line-height: 1.4;
  color: var(--fg-muted);
  text-decoration: none;
  border-left: 2px solid transparent;
  transition: color var(--transition), border-color var(--transition), background var(--transition);
  word-break: break-word;
}

.toc-sidebar nav > ul > li > a {
  font-weight: 500;
  font-size: 0.82rem;
  color: var(--fg-muted);
}

.toc-sidebar nav a:hover,
.toc-dropdown nav a:hover {
  color: var(--fg);
  background: var(--accent-glow);
}

.toc-sidebar nav a.active,
.toc-dropdown nav a.active {
  color: var(--accent);
  border-left-color: var(--accent);
  background: var(--accent-glow);
}

/* Nested h3 links */
.toc-sidebar nav li li a,
.toc-dropdown nav li li a {
  padding-left: 1.75rem;
  font-size: 0.78rem;
  font-weight: 400;
}

/* ── Main content ───────────────────────────────────────────── */
.content {
  flex: 1;
  overflow-y: auto;
  padding: 2.5rem 3rem;
  min-width: 0;
}

/* ── Doc body ───────────────────────────────────────────────── */
.doc-body {
  max-width: 760px;
  margin: 0 auto;
}

.doc-body h1 {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.2;
  margin-bottom: 0.75rem;
  color: var(--fg);
}

.doc-body h2 {
  font-size: 1.35rem;
  font-weight: 650;
  letter-spacing: -0.02em;
  margin-top: 2.75rem;
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
  color: var(--fg);
}

.doc-body h3 {
  font-size: 1.05rem;
  font-weight: 600;
  margin-top: 1.75rem;
  margin-bottom: 0.5rem;
  color: var(--fg);
}

.doc-body h4 {
  font-size: 0.95rem;
  font-weight: 600;
  margin-top: 1.25rem;
  margin-bottom: 0.35rem;
  color: var(--fg-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 0.78rem;
}

.doc-body p {
  margin-bottom: 1rem;
  color: var(--fg);
}

.doc-body a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-color: rgba(122, 158, 199, 0.4);
  text-underline-offset: 2px;
  transition: color var(--transition), text-decoration-color var(--transition);
}
.doc-body a:hover {
  color: var(--accent-hover);
  text-decoration-color: var(--accent-hover);
}

.doc-body ul,
.doc-body ol {
  margin-bottom: 1rem;
  padding-left: 1.5rem;
}

.doc-body li {
  margin-bottom: 0.3rem;
}

.doc-body li > ul,
.doc-body li > ol {
  margin-top: 0.3rem;
  margin-bottom: 0;
}

.doc-body blockquote {
  border-left: 3px solid var(--accent);
  margin: 1.5rem 0;
  padding: 0.75rem 1.25rem;
  background: var(--accent-glow);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--fg-muted);
}
.doc-body blockquote p { margin: 0; color: inherit; }

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

/* Inline code */
.doc-body :not(pre) > code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: var(--bg-raised);
  color: #e8c97a;
  padding: 0.15em 0.45em;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

/* Code blocks — override Prism tomorrow theme */
.doc-body pre[class*="language-"],
.doc-body pre.language-text {
  font-family: var(--font-mono);
  font-size: 0.84rem;
  line-height: 1.65;
  background: var(--bg-code) !important;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.4rem;
  margin: 1.25rem 0;
  overflow-x: auto;
}

.doc-body pre[class*="language-"] code {
  background: none !important;
  padding: 0 !important;
  border: none !important;
  font-size: inherit;
  color: inherit;
}

/* Tables */
.doc-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5rem 0;
  font-size: 0.88rem;
}
.doc-body th {
  background: var(--bg-raised);
  color: var(--fg-muted);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.6rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border-accent);
}
.doc-body td {
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.doc-body tr:last-child td { border-bottom: none; }
.doc-body tr:hover td { background: rgba(255,255,255,0.02); }

/* Details / Summary */
.doc-body details {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin: 1rem 0;
  padding: 0.5rem 1rem;
}
.doc-body summary {
  cursor: pointer;
  font-weight: 500;
  color: var(--fg-muted);
  user-select: none;
}

/* ── GUIDE panel (desktop) ──────────────────────────────────── */
.guide-panel {
  width: var(--guide-w);
  min-width: 220px;
  flex-shrink: 0;
  border-left: 1px solid var(--border);
  background: var(--bg-surface);
  display: flex;
  flex-direction: column;
}

.guide-header {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  flex-shrink: 0;
}

.guide-title {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--fg-muted);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.guide-sub {
  font-size: 0.72rem;
  color: var(--fg-dim);
}

.guide-iframe {
  flex: 1;
  width: 100%;
  border: none;
  background: var(--bg);
}

/* ── Skeleton loader ────────────────────────────────────────── */
@keyframes shimmer {
  0%   { background-position: -600px 0; }
  100% { background-position: 600px 0; }
}

.skeleton {
  max-width: 760px;
  margin: 0 auto;
  padding: 0.5rem 0;
}

.sk-line {
  height: 14px;
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg, var(--bg-raised) 25%, var(--bg-surface) 50%, var(--bg-raised) 75%);
  background-size: 1200px 100%;
  animation: shimmer 1.6s infinite linear;
  margin-bottom: 0.75rem;
}
.sk-title  { height: 28px; width: 60%; margin-bottom: 1.25rem; }
.sk-heading { height: 20px; width: 40%; margin-bottom: 0.75rem; }
.sk-long   { width: 100%; }
.sk-med    { width: 75%; }
.sk-short  { width: 45%; }
.sk-spacer { height: 1.5rem; }

/* ── Error state ────────────────────────────────────────────── */
.error-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  padding: 3rem 1rem;
  color: var(--fg-muted);
  text-align: center;
}
.error-icon { font-size: 2rem; }
.error-state button {
  font-family: var(--font);
  font-size: 0.85rem;
  padding: 0.5rem 1.25rem;
  background: var(--bg-raised);
  color: var(--fg);
  border: 1px solid var(--border-accent);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
}
.error-state button:hover { background: var(--accent-glow); border-color: var(--accent); }

/* ── Mobile FAB ─────────────────────────────────────────────── */
.chat-fab {
  display: none;
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 200;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--accent);
  color: #0a0e1a;
  border: none;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(122, 158, 199, 0.35);
  transition: transform var(--transition), box-shadow var(--transition);
}
.chat-fab:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 28px rgba(122, 158, 199, 0.5);
}
.chat-fab:active { transform: scale(0.96); }

/* ── Chat drawer (mobile) ───────────────────────────────────── */
.drawer-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 300;
  opacity: 0;
  transition: opacity var(--transition);
}
.drawer-overlay.show { opacity: 1; }

.chat-drawer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 85vh;
  background: var(--bg-surface);
  border-top: 1px solid var(--border-accent);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  z-index: 400;
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 260ms cubic-bezier(0.4, 0, 0.2, 1);
}
.chat-drawer.open { transform: translateY(0); }

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.drawer-title { font-size: 0.9rem; font-weight: 600; color: var(--fg); }
.drawer-close {
  background: none;
  border: none;
  color: var(--fg-muted);
  cursor: pointer;
  padding: 0.25rem;
  display: flex;
  align-items: center;
  border-radius: var(--radius-sm);
  transition: color var(--transition), background var(--transition);
}
.drawer-close:hover { color: var(--fg); background: var(--bg-raised); }

/* ── Scrollbar ──────────────────────────────────────────────── */
.content::-webkit-scrollbar,
.toc-sidebar::-webkit-scrollbar,
.toc-dropdown::-webkit-scrollbar { width: 5px; }
.content::-webkit-scrollbar-track,
.toc-sidebar::-webkit-scrollbar-track,
.toc-dropdown::-webkit-scrollbar-track { background: transparent; }
.content::-webkit-scrollbar-thumb,
.toc-sidebar::-webkit-scrollbar-thumb,
.toc-dropdown::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}
.content::-webkit-scrollbar-thumb:hover { background: var(--border-accent); }

/* ── Mobile (<900px) ────────────────────────────────────────── */
@media (max-width: 900px) {
  body { overflow: auto; }

  .layout {
    height: auto;
    flex-direction: column;
    overflow: visible;
  }

  .toc-sidebar  { display: none; }
  .guide-panel  { display: none; }

  .toc-toggle   { display: flex; }
  .toc-dropdown { display: block; }
  .chat-fab     { display: flex; }
  .drawer-overlay { display: block; }

  .content {
    overflow-y: visible;
    height: auto;
    padding: 1.5rem 1.25rem;
  }

  .doc-body h1 { font-size: 1.5rem; }
  .doc-body h2 { font-size: 1.15rem; }

  .doc-body table {
    font-size: 0.8rem;
    display: block;
    overflow-x: auto;
  }

  .doc-body pre[class*="language-"] {
    font-size: 0.78rem;
    padding: 0.85rem 1rem;
  }

  .skeleton { padding: 0; }
}

/* ── Focus visible ──────────────────────────────────────────── */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}
