/* ── Theme Variables ── */
:root {
  --bg-deep: #08090a;
  --bg-panel: #0f1011;
  --bg-surface: #191a1b;
  --bg-card: rgba(255,255,255,0.02);
  --bg-card-hover: rgba(255,255,255,0.04);
  --bg-code: rgba(255,255,255,0.03);
  --bg-code-inline: rgba(255,255,255,0.05);
  --text-primary: #f7f8f8;
  --text-secondary: #d0d6e0;
  --text-tertiary: #8a8f98;
  --text-muted: #62666d;
  --brand: #5e6ad2;
  --accent: #7170ff;
  --accent-hover: #828fff;
  --border: rgba(255,255,255,0.08);
  --border-subtle: rgba(255,255,255,0.05);
  --cursor-arrow: #fff;
  --cursor-outer: rgba(255,255,255,0.3);
  --green: #27a644;
  --emerald: #10b981;
  --badge-bg: rgba(94,106,210,0.1);
  --badge-border: rgba(94,106,210,0.2);
  --nav-bg: rgba(15,16,17,0.85);
  --sidebar-bg: rgba(15,16,17,0.5);
  --content-max: 740px;
  --sidebar-width: 240px;
}

[data-theme="light"] {
  --bg-deep: #f7f8f8;
  --bg-panel: #ffffff;
  --bg-surface: #f3f4f5;
  --bg-card: rgba(0,0,0,0.02);
  --bg-card-hover: rgba(0,0,0,0.04);
  --bg-code: rgba(0,0,0,0.03);
  --bg-code-inline: rgba(0,0,0,0.05);
  --text-primary: #171717;
  --text-secondary: #444;
  --text-tertiary: #666;
  --text-muted: #999;
  --brand: #5e6ad2;
  --accent: #5e6ad2;
  --accent-hover: #4a55c4;
  --border: rgba(0,0,0,0.1);
  --border-subtle: rgba(0,0,0,0.06);
  --badge-bg: rgba(94,106,210,0.08);
  --badge-border: rgba(94,106,210,0.2);
  --nav-bg: rgba(255,255,255,0.9);
  --sidebar-bg: rgba(255,255,255,0.6);
  --cursor-arrow: #1a1a2e;
  --cursor-outer: rgba(0,0,0,0.2);
}

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

html { scroll-behavior: smooth; }

body {
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-feature-settings: 'cv01', 'ss03';
  background: var(--bg-deep);
  color: var(--text-secondary);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  transition: background 0.3s, color 0.3s;
  cursor: none;
  position: relative;
}

/* Ensure content sits above starfield canvas (z-index:0) */
nav, .page-wrapper, footer, .back-to-top { position: relative; z-index: 1; }

/* ── Custom Cursor ── */
.cursor-inner {
  width: 0; height: 0;
  border-left: 8px solid var(--cursor-arrow);
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
  position: fixed;
  pointer-events: none;
  z-index: 10000;
  filter: drop-shadow(0 0 6px var(--accent)) drop-shadow(0 0 12px rgba(113,112,255,0.5));
  transition: border-left-color 0.2s;
}
.cursor-inner.hover {
  border-left-color: var(--accent);
}
.cursor-outer {
  width: 36px; height: 36px;
  border: 2px solid var(--cursor-outer);
  border-radius: 50%;
  position: fixed;
  pointer-events: none;
  z-index: 9999;
  transform: translate(-50%, -50%);
  transition: width 0.25s, height 0.25s, border-color 0.25s;
}
.cursor-outer.hover {
  width: 52px; height: 52px;
  border-color: var(--accent);
  background: rgba(113,112,255,0.06);
}
/* Restore default cursor on interactive elements */
a, button, input, textarea, select, .toggle-btn, .theme-toggle, .toc-link, code, pre {
  cursor: none;
}

/* ── Page Layout ── */
.page-wrapper {
  display: flex;
  max-width: 1180px;
  margin: 0 auto;
  position: relative;
}

/* ── Sidebar (TOC) ── */
.sidebar-toc {
  position: sticky;
  top: 70px;
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  height: calc(100vh - 100px);
  overflow-y: auto;
  padding: 24px 16px 24px 24px;
  font-size: 13px;
  border-right: 1px solid var(--border-subtle);
  background: var(--sidebar-bg);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.sidebar-toc::-webkit-scrollbar { width: 3px; }
.sidebar-toc::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.sidebar-toc .toc-title {
  font-size: 11px;
  font-weight: 590;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 16px;
}
.sidebar-toc .toc-link {
  display: block;
  padding: 5px 0;
  color: var(--text-tertiary);
  text-decoration: none;
  transition: all 0.2s;
  line-height: 1.45;
  border-left: 2px solid transparent;
  padding-left: 10px;
  margin-left: -12px;
}
.sidebar-toc .toc-link:hover {
  color: var(--text-primary);
}
.sidebar-toc .toc-link.active {
  color: var(--accent);
  border-left-color: var(--accent);
}
.sidebar-toc .toc-link.toc-h3 {
  padding-left: 24px;
  font-size: 12px;
  color: var(--text-muted);
}
.sidebar-toc .toc-link.toc-h3.active {
  color: var(--accent);
}

/* ── Main Content Area ── */
.main-content {
  flex: 1;
  min-width: 0;
}

/* ── Navigation ── */
nav {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--nav-bg);
  border-bottom: 1px solid var(--border-subtle);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
nav .nav-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 10px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.nav-logo { font-size: 14px; font-weight: 510; color: var(--text-primary); white-space: nowrap; }
.nav-right { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

/* ── Toggle Buttons ── */
.toggle-group {
  display: flex; gap: 4px;
  background: var(--bg-code-inline);
  border: 1px solid var(--border);
  border-radius: 6px; padding: 2px;
}
.toggle-btn {
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 12px; font-weight: 500; color: var(--text-muted);
  background: transparent; border: none; border-radius: 4px;
  padding: 5px 10px; cursor: none; transition: all 0.2s; white-space: nowrap;
}
.toggle-btn:hover { color: var(--text-primary); }
.toggle-btn.active { background: var(--bg-surface); color: var(--text-primary); box-shadow: 0 1px 3px rgba(0,0,0,0.1); }
.theme-toggle {
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 12px; font-weight: 500; color: var(--text-muted);
  background: var(--bg-code-inline); border: 1px solid var(--border);
  border-radius: 6px; padding: 5px 10px; cursor: none; transition: all 0.2s; white-space: nowrap;
}
.theme-toggle:hover { color: var(--text-primary); border-color: var(--text-tertiary); }

/* ── Hero ── */
.hero {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 80px 24px 56px;
  text-align: center;
}
.hero .badge {
  display: inline-block; font-size: 12px; font-weight: 510; color: var(--accent);
  background: var(--badge-bg); border: 1px solid var(--badge-border);
  border-radius: 9999px; padding: 4px 14px; margin-bottom: 24px; letter-spacing: -0.13px;
}
.hero h1 {
  font-size: 48px; font-weight: 510; line-height: 1.05;
  letter-spacing: -1.056px; color: var(--text-primary); margin-bottom: 20px;
}
.hero .subtitle {
  font-size: 18px; font-weight: 400; line-height: 1.6; letter-spacing: -0.165px;
  color: var(--text-tertiary); max-width: 560px; margin: 0 auto 32px;
}
.hero .meta {
  display: flex; gap: 16px; justify-content: center;
  font-size: 13px; font-weight: 400; color: var(--text-muted); letter-spacing: -0.13px;
}
.hero .meta span { display: flex; align-items: center; gap: 6px; }
.hero .meta .dot { width: 6px; height: 6px; background: var(--emerald); border-radius: 50%; }

/* ── Content ── */
.content {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 0 24px 80px;
}
.content h2 {
  font-size: 24px; font-weight: 510; line-height: 1.33; letter-spacing: -0.288px;
  color: var(--text-primary); margin: 56px 0 16px; padding-top: 8px;
  border-top: 1px solid var(--border-subtle);
}
.content h2:first-of-type { border-top: none; margin-top: 0; }
.content h3 {
  font-size: 18px; font-weight: 590; line-height: 1.33; letter-spacing: -0.165px;
  color: var(--text-primary); margin: 28px 0 10px;
}
.content p { font-size: 15px; font-weight: 400; line-height: 1.6; letter-spacing: -0.165px; margin-bottom: 14px; }
.content a { color: var(--accent); text-decoration: none; transition: color 0.15s; }
.content a:hover { color: var(--accent-hover); }
.content ul, .content ol { padding-left: 20px; margin-bottom: 14px; }
.content li { font-size: 15px; font-weight: 400; line-height: 1.6; letter-spacing: -0.165px; margin-bottom: 6px; }
.content li::marker { color: var(--text-muted); }

/* ── Scroll Reveal ── */
.reveal-on-scroll {
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.6s ease, transform 0.6s ease;
}
.reveal-on-scroll.revealed {
  opacity: 1;
  transform: translateY(0);
}

/* ── Fade-in animation for hero ── */
.hero {
  animation: fadeInUp 0.8s ease both;
}
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Code */
.content code {
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 13px; font-weight: 400; background: var(--bg-code-inline);
  padding: 2px 6px; border-radius: 4px; color: var(--text-primary);
}
.content pre {
  background: var(--bg-code); border: 1px solid var(--border);
  border-radius: 8px; padding: 16px 18px; overflow-x: auto; margin-bottom: 16px;
  transition: border-color 0.2s;
}
.content pre:hover { border-color: var(--accent); }
.content pre code {
  background: none; padding: 0; font-size: 13px;
  line-height: 1.65; color: var(--text-secondary);
}

/* Blockquote */
.content blockquote {
  border-left: 2px solid var(--brand); padding: 8px 0 8px 16px;
  margin-bottom: 14px; color: var(--text-tertiary); font-size: 14px; line-height: 1.55;
}

/* Tables */
.content table { width: 100%; border-collapse: collapse; margin-bottom: 16px; font-size: 14px; }
.content th {
  text-align: left; font-weight: 510; font-size: 13px;
  color: var(--text-primary); padding: 10px 12px; border-bottom: 1px solid var(--border);
}
.content td { padding: 10px 12px; border-bottom: 1px solid var(--border-subtle); }
.content tr { transition: background 0.15s; }
.content tbody tr:hover { background: var(--bg-card); }

/* Tips */
.content .tip {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 8px; padding: 14px 18px; margin-bottom: 14px;
  font-size: 14px; color: var(--text-tertiary);
  transition: border-color 0.2s, transform 0.2s;
}
.content .tip:hover { border-color: var(--accent); transform: translateX(4px); }
.content .tip strong { color: var(--text-primary); }
.content hr { border: none; border-top: 1px solid var(--border-subtle); margin: 40px 0; }

/* ── Back to Top ── */
.back-to-top {
  position: fixed; bottom: 32px; right: 32px;
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--bg-surface); border: 1px solid var(--border);
  color: var(--text-tertiary); font-size: 18px;
  display: flex; align-items: center; justify-content: center;
  cursor: none; opacity: 0; pointer-events: none;
  transition: all 0.3s; z-index: 90;
}
.back-to-top.visible { opacity: 1; pointer-events: auto; }
.back-to-top:hover { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ── Footer ── */
footer {
  border-top: 1px solid var(--border-subtle);
  padding: 40px 24px; text-align: center;
}
footer .footer-inner { max-width: var(--content-max); margin: 0 auto; }
footer p { font-size: 13px; font-weight: 400; letter-spacing: -0.13px; color: var(--text-muted); }
footer a { color: var(--accent); text-decoration: none; }

/* ── Language hiding ── */
body [lang] { display: none; }
body [lang].active { display: revert; }
body span[lang].active { display: inline; }
body li[lang].active { display: list-item; }
body tr[lang].active { display: table-row; }
body td[lang].active,
body th[lang].active { display: table-cell; }

/* ── Responsive ── */
@media (max-width: 1024px) {
  .sidebar-toc { display: none; }
}
@media (max-width: 768px) {
  .hero { padding: 56px 20px 40px; }
  .hero h1 { font-size: 32px; letter-spacing: -0.704px; }
  .hero .subtitle { font-size: 16px; }
  .content { padding: 0 20px 60px; }
  .content h2 { font-size: 20px; letter-spacing: -0.24px; margin-top: 40px; }
  .content pre { padding: 12px 14px; }
  .back-to-top { bottom: 20px; right: 20px; }
  .cursor-inner, .cursor-outer { display: none; }
  body { cursor: auto; }
  a, button, input, textarea, select, .toggle-btn, .theme-toggle, .toc-link, code, pre { cursor: pointer; }
}
@media (max-width: 480px) {
  .hero h1 { font-size: 26px; letter-spacing: -0.5px; }
  .nav-right { gap: 8px; }
  .toggle-btn { padding: 4px 8px; font-size: 11px; }
}