/* ============================================
   Codex TypeScript SDK 教程 — Developer Docs 风格
   灵感：Stripe Docs / Vercel Docs / Linear
   配色：深色背景 + 青绿 accent
   ============================================ */

/* --- CSS Variables (Dark) --- */
:root {
  --bg-body: #0a0a0f;
  --bg-surface: #12121a;
  --bg-elevated: #1a1a26;
  --bg-code: #0d1117;
  --bg-code-inline: rgba(56, 189, 248, 0.08);
  --bg-nav: rgba(10, 10, 15, 0.92);
  --bg-sidebar: #0e0e16;
  --bg-hover: rgba(56, 189, 248, 0.06);
  --bg-active: rgba(56, 189, 248, 0.10);

  --text-primary: #e4e4ed;
  --text-secondary: #9b9bb0;
  --text-muted: #5e5e75;
  --text-code: #e2e8f0;

  --accent: #38bdf8;
  --accent-dim: #0ea5e9;
  --accent-glow: rgba(56, 189, 248, 0.2);
  --accent-bg: rgba(56, 189, 248, 0.08);
  --green: #4ade80;
  --amber: #fbbf24;
  --red: #f87171;
  --purple: #a78bfa;

  --border: rgba(255, 255, 255, 0.06);
  --border-strong: rgba(255, 255, 255, 0.10);
  --border-accent: rgba(56, 189, 248, 0.25);

  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 16px;
  --shadow: 0 2px 16px rgba(0, 0, 0, 0.4);
  --shadow-hover: 0 4px 28px rgba(56, 189, 248, 0.08);
  --transition: 0.2s ease;

  --content-max: 780px;
  --sidebar-width: 260px;
  --nav-height: 56px;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
}

/* --- Light Mode --- */
:root[data-theme="light"] {
  --bg-body: #fafafa;
  --bg-surface: #ffffff;
  --bg-elevated: #f5f5f7;
  --bg-code: #1b1b2f;
  --bg-code-inline: rgba(14, 165, 233, 0.08);
  --bg-nav: rgba(255, 255, 255, 0.92);
  --bg-sidebar: #f8f8fa;
  --bg-hover: rgba(14, 165, 233, 0.04);
  --bg-active: rgba(14, 165, 233, 0.08);

  --text-primary: #18181b;
  --text-secondary: #52525b;
  --text-muted: #a1a1aa;

  --border: rgba(0, 0, 0, 0.06);
  --border-strong: rgba(0, 0, 0, 0.10);
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
  --shadow-hover: 0 4px 24px rgba(14, 165, 233, 0.06);
}

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

html { scroll-behavior: smooth; scroll-padding-top: calc(var(--nav-height) + 24px); }

body {
  font-family: var(--font-sans);
  background: var(--bg-body);
  color: var(--text-primary);
  font-size: 15px;
  line-height: 1.75;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ========================
   Top Navigation Bar
   ======================== */
.topnav {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 200;
  height: var(--nav-height);
  background: var(--bg-nav);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
}

.topnav-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text-primary);
  font-weight: 700;
  font-size: 15px;
}

.topnav-brand .brand-icon {
  width: 26px; height: 26px;
  background: linear-gradient(135deg, var(--accent), var(--green));
  border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 800; color: #0a0a0f;
}

.topnav-brand .brand-tag {
  font-size: 11px;
  font-weight: 500;
  color: var(--accent);
  background: var(--accent-bg);
  padding: 2px 7px;
  border-radius: 4px;
  margin-left: 4px;
}

.topnav-right {
  display: flex; align-items: center; gap: 8px;
}

.topnav-select {
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 5px 10px;
  font-size: 13px;
  font-family: var(--font-sans);
  cursor: pointer;
  max-width: 220px;
}

.topnav-btn {
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
  transition: var(--transition);
}
.topnav-btn:hover { background: var(--bg-hover); color: var(--accent); }

/* ========================
   Sidebar (章节目录)
   ======================== */
.sidebar {
  position: fixed;
  top: var(--nav-height);
  left: 0;
  width: var(--sidebar-width);
  height: calc(100vh - var(--nav-height));
  overflow-y: auto;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  padding: 20px 0;
  z-index: 100;
}

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

.sidebar-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  padding: 8px 12px 6px;
}

.sidebar a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 450;
  transition: var(--transition);
  line-height: 1.4;
}
.sidebar a:hover { background: var(--bg-hover); color: var(--text-primary); }
.sidebar a.active { background: var(--bg-active); color: var(--accent); font-weight: 550; }

.sidebar .ch-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px; height: 22px;
  border-radius: 5px;
  font-size: 11px;
  font-weight: 700;
  background: var(--bg-elevated);
  color: var(--text-muted);
  flex-shrink: 0;
}
.sidebar a.active .ch-num { background: var(--accent-bg); color: var(--accent); }

/* ========================
   Page Layout
   ======================== */
.layout {
  margin-left: var(--sidebar-width);
  padding-top: var(--nav-height);
  min-height: 100vh;
}

.page-content {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 40px 40px 80px;
}

/* ========================
   Index / Hero
   ======================== */
.hero {
  padding: 56px 0 32px;
  text-align: center;
}

.hero h1 {
  font-size: 2.8rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.15;
  background: linear-gradient(135deg, var(--accent), var(--green), var(--accent));
  background-size: 200% auto;
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: gradient-shift 6s linear infinite;
  margin-bottom: 16px;
}

@keyframes gradient-shift {
  0% { background-position: 0% center; }
  100% { background-position: 200% center; }
}

.hero-subtitle {
  font-size: 1.1rem;
  color: var(--text-secondary);
  max-width: 480px;
  margin: 0 auto 12px;
}

.hero-badge {
  display: inline-block;
  background: var(--accent-bg);
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: 20px;
  border: 1px solid var(--border-accent);
  margin-bottom: 24px;
}

/* Index card grid */
.card-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-top: 32px;
}

.card-link {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 16px 18px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text-primary);
  transition: var(--transition);
}
.card-link:hover {
  border-color: var(--border-accent);
  box-shadow: var(--shadow-hover);
  transform: translateY(-1px);
}
.card-link .card-icon {
  width: 36px; height: 36px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 800; color: #fff;
  flex-shrink: 0;
}
.card-link .card-body h3 { font-size: 14px; font-weight: 600; margin-bottom: 2px; }
.card-link .card-body p { font-size: 12px; color: var(--text-muted); margin: 0; line-height: 1.5; }

.card-icon.blue { background: linear-gradient(135deg, #0ea5e9, #38bdf8); }
.card-icon.green { background: linear-gradient(135deg, #22c55e, #4ade80); }
.card-icon.purple { background: linear-gradient(135deg, #8b5cf6, #a78bfa); }
.card-icon.amber { background: linear-gradient(135deg, #f59e0b, #fbbf24); }
.card-icon.red { background: linear-gradient(135deg, #ef4444, #f87171); }
.card-icon.cyan { background: linear-gradient(135deg, #06b6d4, #22d3ee); }
.card-icon.pink { background: linear-gradient(135deg, #ec4899, #f472b6); }
.card-icon.teal { background: linear-gradient(135deg, #14b8a6, #2dd4bf); }

/* ========================
   Article (chapter pages)
   ======================== */
.article {
  animation: fadeIn 0.35s ease;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.article-header {
  margin-bottom: 36px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.article-header .ch-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 10px;
}
.article-header .ch-label .dot {
  width: 6px; height: 6px;
  background: var(--accent);
  border-radius: 50%;
}

/* ========================
   Typography
   ======================== */
.article h1 {
  font-size: 2rem;
  font-weight: 750;
  letter-spacing: -0.02em;
  line-height: 1.2;
  margin-bottom: 8px;
}

.article h2 {
  font-size: 1.4rem;
  font-weight: 680;
  margin-top: 52px;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  letter-spacing: -0.01em;
}

.article h3 {
  font-size: 1.15rem;
  font-weight: 620;
  margin-top: 36px;
  margin-bottom: 12px;
  color: var(--text-primary);
}

.article h4 {
  font-size: 1rem;
  font-weight: 600;
  margin-top: 28px;
  margin-bottom: 8px;
}

.article p { margin-bottom: 16px; }

.article strong { color: var(--accent); font-weight: 600; }
:root[data-theme="light"] .article strong { color: var(--accent-dim); }

.article ul, .article ol { padding-left: 22px; margin-bottom: 16px; }
.article li { margin-bottom: 5px; }
.article li::marker { color: var(--accent-dim); }

.article a {
  color: var(--accent);
  text-decoration: none;
  text-underline-offset: 3px;
  transition: var(--transition);
}
.article a:hover { text-decoration: underline; }

.article hr {
  border: none;
  height: 1px;
  background: var(--border-strong);
  margin: 40px 0;
}

/* ========================
   Code blocks
   ======================== */
.article code {
  font-family: var(--font-mono);
  font-size: 0.87em;
  background: var(--bg-code-inline);
  color: var(--accent);
  padding: 2px 6px;
  border-radius: 4px;
}

.article pre {
  position: relative;
  background: var(--bg-code);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin: 14px 0 22px;
  overflow-x: auto;
  font-size: 13.5px;
  line-height: 1.7;
}
.article pre code {
  background: none;
  color: var(--text-code);
  padding: 0;
  font-size: inherit;
}

.code-lang {
  position: absolute;
  top: 8px; left: 14px;
  font-size: 10px;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
  opacity: 0.7;
}

.copy-btn {
  position: absolute;
  top: 8px; right: 10px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 5px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 12px;
  padding: 3px 9px;
  font-family: var(--font-sans);
  opacity: 0;
  transition: var(--transition);
}
.article pre:hover .copy-btn { opacity: 1; }
.copy-btn:hover { background: rgba(255,255,255,0.12); color: var(--text-primary); }
.copy-btn.copied { color: var(--green); border-color: var(--green); }

/* ========================
   Blockquotes (tips)
   ======================== */
.article blockquote {
  border-left: 3px solid var(--accent-dim);
  background: var(--accent-bg);
  padding: 12px 18px;
  margin: 18px 0;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 0.92rem;
  color: var(--text-secondary);
}
.article blockquote p { margin-bottom: 4px; }

/* ========================
   Tables
   ======================== */
.article table {
  width: 100%;
  border-collapse: collapse;
  margin: 14px 0 22px;
  font-size: 0.9rem;
}
.article th {
  background: var(--bg-elevated);
  font-weight: 600;
  text-align: left;
  padding: 9px 14px;
  border-bottom: 2px solid var(--border-strong);
  color: var(--text-primary);
  font-size: 0.85rem;
}
.article td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
}
.article tr:hover td { background: var(--bg-hover); }

/* ========================
   Floating TOC (right)
   ======================== */
.floating-toc {
  position: fixed;
  top: calc(var(--nav-height) + 24px);
  right: max(calc((100vw - var(--sidebar-width) - var(--content-max)) / 2 - 200px + var(--sidebar-width)), 20px);
  width: 190px;
  max-height: calc(100vh - var(--nav-height) - 48px);
  overflow-y: auto;
  font-size: 12px;
}
.floating-toc .toc-heading {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  margin-bottom: 10px;
}
.floating-toc a {
  display: block;
  padding: 3px 0 3px 12px;
  border-left: 1.5px solid var(--border);
  color: var(--text-muted);
  text-decoration: none;
  transition: var(--transition);
  line-height: 1.5;
}
.floating-toc a:hover,
.floating-toc a.active {
  color: var(--accent);
  border-left-color: var(--accent);
}
.floating-toc a.toc-h3 { padding-left: 24px; font-size: 11px; }

/* ========================
   Bottom nav
   ======================== */
.bottom-nav {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-top: 48px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}
.bottom-nav a {
  display: flex;
  flex-direction: column;
  padding: 14px 18px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 500;
  transition: var(--transition);
  max-width: 48%;
}
.bottom-nav a:hover { border-color: var(--border-accent); transform: translateY(-1px); }
.bottom-nav a .nav-label { font-size: 11px; color: var(--text-muted); margin-bottom: 4px; }
.bottom-nav a .nav-title { font-weight: 600; }
.bottom-nav a.nav-next { margin-left: auto; text-align: right; }

/* ========================
   Footer
   ======================== */
.site-footer {
  text-align: center;
  padding: 32px 24px;
  color: var(--text-muted);
  font-size: 12px;
}
.site-footer a { color: var(--accent); text-decoration: none; }

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

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

@media (max-width: 960px) {
  .sidebar { display: none; }
  .layout { margin-left: 0; }
}

@media (max-width: 640px) {
  .hero h1 { font-size: 2rem; }
  .page-content { padding: 24px 16px 60px; }
  .article h1 { font-size: 1.5rem; }
  .card-grid { grid-template-columns: 1fr; }
  .bottom-nav { flex-direction: column; }
  .bottom-nav a { max-width: 100%; }
  .topnav-select { display: none; }
}
