/* ── Reset & base ─────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { width: 100%; overflow-x: clip; }

body {
  font-family: "Manrope", system-ui, -apple-system, sans-serif;
  background: radial-gradient(circle at 0% 0%, var(--glow-1) 0%, transparent 38%),
              radial-gradient(circle at 92% 15%, var(--glow-2) 0%, transparent 38%),
              var(--bg);
  color: var(--ink);
  min-height: 100vh;
  transition: color 0.22s ease, background-color 0.22s ease;
  overflow-x: hidden;
}

/* ── Background decorative shapes ────────────────────── */
.bg-shape {
  position: fixed; border-radius: 999px;
  filter: blur(80px); z-index: -1; opacity: 0.45; pointer-events: none;
}
.bg-shape-1 { width: 280px; height: 280px; background: var(--shape-1); top: -60px; left: -50px; }
.bg-shape-2 { width: 240px; height: 240px; background: var(--shape-2); right: -70px; top: 18%; }

/* ── Top navigation bar ───────────────────────────────── */
.topnav {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  height: var(--nav-height);
  background: var(--nav-bg);
  border-bottom: 1px solid var(--nav-border);
  backdrop-filter: blur(20px) saturate(130%);
  -webkit-backdrop-filter: blur(20px) saturate(130%);
  display: flex; align-items: center;
  padding: 0 1.25rem;
  gap: 1rem;
}

.topnav__brand {
  display: flex; align-items: center; gap: 0.5rem;
  text-decoration: none; color: var(--ink); font-weight: 700; font-size: 1.05rem;
  white-space: nowrap;
}
.topnav__brand-dot { color: var(--accent); }

.topnav__sep {
  width: 1px; height: 18px;
  background: var(--line); flex-shrink: 0;
}

.topnav__title {
  font-size: 0.9rem; color: var(--muted); font-weight: 500;
}

.topnav__spacer { flex: 1; }

/* Language switcher */
.lang-switcher {
  display: flex; gap: 4px;
}
.lang-btn {
  background: none; border: 1px solid transparent;
  border-radius: var(--radius-xs); padding: 3px 8px;
  font-size: 0.78rem; font-weight: 600; cursor: pointer;
  color: var(--muted); font-family: inherit;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.lang-btn:hover { color: var(--ink); border-color: var(--line); }
.lang-btn.active {
  color: var(--accent); border-color: var(--accent);
  background: var(--chip-bg);
}

/* Theme toggle */
.theme-toggle {
  background: none; border: 1px solid var(--line);
  border-radius: var(--radius-xs); width: 32px; height: 28px;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 0.9rem; transition: color 0.15s, border-color 0.15s;
}
.theme-toggle:hover { color: var(--ink); border-color: var(--accent); }

/* Hamburger (mobile) */
.nav-hamburger {
  display: none; background: none; border: none;
  cursor: pointer; padding: 4px; color: var(--ink);
}
.nav-hamburger svg { display: block; }

/* ── Layout ───────────────────────────────────────────── */
.wiki-layout {
  display: flex;
  padding-top: var(--nav-height);
  min-height: 100vh;
}

/* ── Sidebar ──────────────────────────────────────────── */
.sidebar {
  position: fixed;
  top: var(--nav-height); bottom: 0; left: 0;
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  backdrop-filter: blur(18px) saturate(130%);
  -webkit-backdrop-filter: blur(18px) saturate(130%);
  overflow-y: auto;
  padding: 1.25rem 0;
  z-index: 50;
  transition: transform 0.28s ease;
}

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

.sidebar__section-label {
  font-size: 0.68rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--muted);
  padding: 0.9rem 1.2rem 0.3rem;
}

.sidebar__nav { list-style: none; margin: 0; padding: 0; }

/* ── Expandable sub-nav ──────────────────────────────── */
.sidebar__expandable > .sidebar__expand-btn {
  display: flex; align-items: center; gap: 0.55rem;
  padding: 0.48rem 1.2rem;
  font-size: 0.875rem; font-weight: 500;
  color: var(--muted); text-decoration: none;
  border: none; border-left: 2px solid transparent;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  margin-right: 0.75rem;
  cursor: pointer; background: none;
  width: calc(100% - 0.75rem); text-align: left; font-family: inherit;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
}
.sidebar__expandable > .sidebar__expand-btn:hover { color: var(--ink); background: var(--chip-bg); }
.sidebar__expandable.open > .sidebar__expand-btn {
  color: var(--accent); border-left-color: var(--accent);
  background: var(--chip-bg); font-weight: 600;
}

.sidebar__expand-btn .chevron {
  margin-left: auto; font-size: 0.55rem; opacity: 0.45;
  transition: transform 0.2s ease;
}
.sidebar__expandable.open .chevron { transform: rotate(90deg); opacity: 0.7; }

.sidebar__subnav {
  list-style: none; margin: 0; padding: 0;
  max-height: 0; overflow: hidden;
  transition: max-height 0.28s ease;
}
.sidebar__expandable.open .sidebar__subnav { max-height: 800px; }

.sidebar__subnav a {
  display: flex; align-items: center; gap: 0.4rem;
  padding: 0.32rem 1.2rem 0.32rem 2.6rem;
  font-size: 0.8rem; font-weight: 500;
  color: var(--muted); text-decoration: none;
  border-left: 2px solid transparent;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  margin-right: 0.75rem;
}
.sidebar__subnav a:hover { color: var(--ink); background: var(--chip-bg); }
.sidebar__subnav a.active {
  color: var(--accent); border-left-color: var(--accent);
  background: var(--chip-bg); font-weight: 600;
}

.sidebar__nav a {
  display: flex; align-items: center; gap: 0.55rem;
  padding: 0.48rem 1.2rem;
  font-size: 0.875rem; font-weight: 500;
  color: var(--muted); text-decoration: none;
  border-left: 2px solid transparent;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  margin-right: 0.75rem;
}
.sidebar__nav a:hover {
  color: var(--ink); background: var(--chip-bg);
}
.sidebar__nav a.active {
  color: var(--accent); border-left-color: var(--accent);
  background: var(--chip-bg); font-weight: 600;
}

.sidebar__nav .icon {
  font-size: 0.95rem; width: 1.1em; text-align: center; flex-shrink: 0;
}

/* ── Main content area ────────────────────────────────── */
.wiki-main {
  flex: 1;
  margin-left: var(--sidebar-width);
  min-width: 0;
}

.wiki-content {
  max-width: 1100px;
  margin: 0 auto;
  padding: 2.5rem 2.5rem 5rem;
}

/* ── Article typography ───────────────────────────────── */
.article h1 {
  font-size: 2rem; font-weight: 800; line-height: 1.2;
  margin: 0 0 0.5rem;
  color: var(--ink);
}

.article__lead {
  font-size: 1.1rem; color: var(--muted); margin: 0 0 2rem;
  line-height: 1.6;
}

.article h2 {
  font-size: 1.3rem; font-weight: 700;
  margin: 2.5rem 0 0.75rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
}

.article h3 {
  font-size: 1.05rem; font-weight: 700;
  margin: 1.8rem 0 0.5rem;
  color: var(--ink);
}

.article h4 {
  font-size: 0.95rem; font-weight: 700;
  margin: 1.4rem 0 0.4rem;
  color: var(--text-soft);
}

.article p {
  line-height: 1.75; margin: 0 0 1rem;
  color: var(--ink);
}

.article ul, .article ol {
  margin: 0 0 1rem; padding-left: 1.6rem;
  line-height: 1.7;
}

.article li { margin-bottom: 0.35rem; }

.article a {
  color: var(--accent); text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 0.15s;
}
.article a:hover { border-bottom-color: var(--accent); }

/* Inline code */
.article code {
  font-family: "JetBrains Mono", "Fira Code", "Cascadia Code", ui-monospace, monospace;
  font-size: 0.83em;
  background: var(--code-bg); color: var(--code-ink);
  padding: 0.12em 0.4em; border-radius: var(--radius-xs);
  border: 1px solid var(--code-border);
}

/* Code blocks */
.article pre {
  background: var(--pre-bg);
  border-radius: var(--radius-sm);
  padding: 1.1rem 1.25rem;
  overflow-x: auto;
  margin: 1.25rem 0;
  position: relative;
  border: 1px solid var(--pre-border);
}
.article pre code {
  background: none; border: none; padding: 0;
  color: var(--pre-ink); font-size: 0.86rem;
  line-height: 1.65;
}

/* Language label on code blocks */
.article pre[data-lang]::before {
  content: attr(data-lang);
  position: absolute; top: 0.5rem; right: 0.75rem;
  font-size: 0.68rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--muted); opacity: 0.5;
  font-family: inherit;
}

/* Blockquote / Note */
.article blockquote, .article .note {
  border-left: 3px solid var(--accent);
  background: var(--chip-bg);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 0.75rem 1rem;
  margin: 1.25rem 0;
  color: var(--text-soft);
  font-size: 0.93rem;
}
.article blockquote p, .article .note p { margin: 0; color: inherit; }

/* Warning callout */
.article .warning {
  border-left: 3px solid var(--accent-2);
  background: rgba(246, 185, 65, 0.08);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 0.75rem 1rem;
  margin: 1.25rem 0;
  font-size: 0.93rem;
}

/* Tables */
.article table {
  width: 100%; border-collapse: collapse;
  margin: 1.25rem 0; font-size: 0.9rem;
}
.article th {
  background: var(--chip-bg); color: var(--ink);
  font-weight: 700; text-align: left;
  padding: 0.55rem 0.85rem;
  border-bottom: 2px solid var(--line);
}
.article td {
  padding: 0.5rem 0.85rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top; line-height: 1.6;
}
.article tr:last-child td { border-bottom: none; }
.article tbody tr:hover td { background: var(--chip-bg); }

/* Chips / tags */
.chip {
  display: inline-flex; align-items: center;
  background: var(--chip-bg); color: var(--chip-ink);
  border: 1px solid var(--chip-line);
  border-radius: 999px; padding: 0.2em 0.65em;
  font-size: 0.78rem; font-weight: 600;
  white-space: nowrap;
}

/* Section divider */
.article hr {
  border: none; border-top: 1px solid var(--line);
  margin: 2.5rem 0;
}

/* ── Page header breadcrumb ───────────────────────────── */
.breadcrumb {
  display: flex; align-items: center; gap: 0.4rem;
  font-size: 0.8rem; color: var(--muted);
  margin-bottom: 1.25rem; flex-wrap: wrap;
}
.breadcrumb a { color: var(--muted); text-decoration: none; }
.breadcrumb a:hover { color: var(--accent); }
.breadcrumb__sep { opacity: 0.5; }

/* ── TOC (table of contents) ──────────────────────────── */
.toc {
  background: var(--article-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 1rem 1.25rem;
  margin-bottom: 2rem;
  font-size: 0.87rem;
}
.toc__title {
  font-weight: 700; color: var(--muted); margin-bottom: 0.5rem;
  font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.06em;
}
.toc__list { list-style: none; margin: 0; padding: 0; }
.toc__list li { margin: 0.2rem 0; }
.toc__list a { color: var(--muted); text-decoration: none; }
.toc__list a:hover { color: var(--accent); }
.toc__list--sub { padding-left: 1rem; }

/* ── "On this page" right column (desktop) ────────────── */
.page-toc {
  position: fixed;
  top: calc(var(--nav-height) + 2rem);
  right: 1.5rem;
  width: 200px;
  font-size: 0.8rem;
  display: none; /* shown via media query */
}
.page-toc__title {
  font-size: 0.7rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--muted); margin-bottom: 0.5rem;
}
.page-toc__list { list-style: none; margin: 0; padding: 0; }
.page-toc__list li { margin: 0.18rem 0; }
.page-toc__list a {
  color: var(--muted); text-decoration: none;
  display: block; padding: 0.1rem 0;
  border-left: 2px solid transparent;
  padding-left: 0.5rem;
  transition: color 0.15s, border-color 0.15s;
}
.page-toc__list a:hover, .page-toc__list a.active {
  color: var(--accent); border-left-color: var(--accent);
}

/* ── Home page grid ───────────────────────────────────── */
.doc-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem; margin-top: 1.5rem;
  padding: 2px;
}

.doc-card {
  background: var(--article-bg);
  border: none;
  outline: 1px solid var(--line);
  outline-offset: -1px;
  border-radius: var(--radius);
  padding: 1.25rem 1.25rem 1rem;
  cursor: pointer; text-decoration: none; color: inherit;
  transition: box-shadow 0.18s, outline-color 0.18s, transform 0.18s;
  display: block;
}
.doc-card:hover {
  box-shadow: var(--shadow-sm);
  outline-color: var(--accent);
  transform: translateY(-2px);
}
.doc-card__icon { font-size: 1.6rem; margin-bottom: 0.6rem; }
.doc-card__title { font-weight: 700; font-size: 0.95rem; margin-bottom: 0.3rem; }
.doc-card__desc { font-size: 0.82rem; color: var(--muted); line-height: 1.5; }

/* ── Sidebar overlay (mobile) ─────────────────────────── */
.sidebar-overlay {
  display: none; position: fixed; inset: 0; z-index: 40;
  background: rgba(0,0,0,0.35);
}

/* ── Footer ───────────────────────────────────────────── */
.wiki-footer {
  text-align: center; padding: 2rem 1rem 3rem;
  font-size: 0.8rem; color: var(--muted);
  border-top: 1px solid var(--line);
  margin-top: 3rem;
}
.wiki-footer a { color: var(--muted); text-decoration: none; }
.wiki-footer a:hover { color: var(--accent); }

/* ── Syntax highlighting ──────────────────────────────── */
/* Light theme */
.token-keyword { color: #7c3aed; }
.token-string  { color: #0f766e; }
.token-comment { color: #9ca3af; font-style: italic; }
.token-number  { color: #c2410c; }
.token-op      { color: #0369a1; }
.token-type    { color: #1d4ed8; }
.token-fn      { color: #be185d; }

/* Dark theme */
:root[data-theme="dark"] .token-keyword { color: #cba6f7; }
:root[data-theme="dark"] .token-string  { color: #a6e3a1; }
:root[data-theme="dark"] .token-comment { color: #6c7086; }
:root[data-theme="dark"] .token-number  { color: #fab387; }
:root[data-theme="dark"] .token-op      { color: #89dceb; }
:root[data-theme="dark"] .token-type    { color: #89b4fa; }
:root[data-theme="dark"] .token-fn      { color: #f38ba8; }

/* ── Responsive ───────────────────────────────────────── */
@media (min-width: 1280px) {
  .wiki-content { padding-right: 3rem; }
}

@media (max-width: 900px) {
  :root { --sidebar-width: 240px; }

  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .sidebar-overlay.open { display: block; }

  .wiki-main { margin-left: 0; }

  .nav-hamburger { display: flex; }

  .wiki-content { padding: 1.75rem 1.25rem 4rem; }
}

@media (max-width: 560px) {
  .article h1 { font-size: 1.55rem; }
  .topnav__title { display: none; }
  .wiki-content { padding: 1.25rem 1rem 4rem; }
}

/* ── Search overlay & modal ───────────────────────────── */
.search-overlay {
  display: none; position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  justify-content: center; align-items: flex-start;
  padding-top: min(18vh, 120px);
}
.search-overlay.open { display: flex; }

.search-modal {
  width: min(620px, calc(100vw - 2rem));
  max-height: min(520px, 70vh);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 24px 80px rgba(0,0,0,0.25);
  display: flex; flex-direction: column;
  overflow: hidden;
  animation: searchIn 0.18s ease;
}
@keyframes searchIn {
  from { opacity: 0; transform: translateY(-12px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* Input */
.search-input-wrap {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--line);
}
.search-icon { color: var(--muted); flex-shrink: 0; display: flex; }
.search-input {
  flex: 1; background: none; border: none; outline: none;
  font-size: 1rem; font-family: inherit; color: var(--ink);
}
.search-input::placeholder { color: var(--muted); }
.search-kbd {
  font-size: 0.68rem; font-family: inherit; font-weight: 600;
  color: var(--muted); background: var(--chip-bg);
  border: 1px solid var(--line); border-radius: 4px;
  padding: 1px 6px; flex-shrink: 0;
}

/* Results */
.search-results {
  overflow-y: auto; flex: 1;
}
.search-results::-webkit-scrollbar { width: 4px; }
.search-results::-webkit-scrollbar-thumb { background: var(--line); border-radius: 2px; }

.search-result {
  display: block; padding: 0.65rem 1rem;
  border-bottom: 1px solid var(--line);
  cursor: pointer; text-decoration: none; color: inherit;
  transition: background 0.1s;
}
.search-result:last-child { border-bottom: none; }
.search-result:hover, .search-result.selected { background: var(--chip-bg); }
.search-result.selected { border-left: 3px solid var(--accent); padding-left: calc(1rem - 3px); }

.search-result__page {
  font-size: 0.68rem; font-weight: 600; color: var(--accent);
  text-transform: uppercase; letter-spacing: 0.04em;
  margin-bottom: 0.15rem;
}
.search-result__heading {
  font-size: 0.9rem; font-weight: 600; color: var(--ink);
  margin-bottom: 0.2rem;
}
.search-result__snippet {
  font-size: 0.8rem; color: var(--muted); line-height: 1.5;
}
.search-result__snippet mark, .search-result__heading mark {
  background: rgba(246, 185, 65, 0.25); color: inherit;
  border-radius: 2px; padding: 0 1px;
}
:root[data-theme="dark"] .search-result__snippet mark,
:root[data-theme="dark"] .search-result__heading mark {
  background: rgba(89, 214, 207, 0.2);
}

.search-empty {
  padding: 1.5rem 1rem; text-align: center;
  font-size: 0.88rem; color: var(--muted);
}

/* Search trigger button in topnav */
.search-trigger {
  display: flex; align-items: center; gap: 0.45rem;
  background: var(--chip-bg); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 0.3rem 0.7rem 0.3rem 0.55rem;
  cursor: pointer; color: var(--muted); font-size: 0.82rem;
  font-family: inherit; transition: border-color 0.15s, color 0.15s;
  white-space: nowrap;
}
.search-trigger:hover { border-color: var(--accent); color: var(--ink); }
.search-trigger svg { flex-shrink: 0; }
.search-trigger kbd {
  font-size: 0.65rem; font-weight: 600; font-family: inherit;
  background: var(--card); border: 1px solid var(--line);
  border-radius: 3px; padding: 0 4px; margin-left: 0.3rem;
}
@media (max-width: 560px) {
  .search-trigger span { display: none; }
  .search-trigger kbd { display: none; }
}
