/* ============================================
   1. CSS Custom Properties (Design Tokens)
   ============================================ */
:root {
  --bg: #FFFFFF;
  --bg-secondary: #F6F8FA;
  --bg-tertiary: #EEF1F4;
  --text: #1A1A2E;
  --text-secondary: #555B6E;
  --text-tertiary: #8B8FA3;
  --primary: #2563EB;
  --primary-dark: #1D4ED8;
  --primary-light: #DBEAFE;
  --border: #E2E5EA;
  --code-bg: #1E1E2E;
  --code-text: #CDD6F4;
  --success: #16A34A;
  --warning: #CA8A04;
  --muted: #6B7280;
  --content-width: 1200px;
  --docs-width: 820px;
  --sidebar-width: 260px;
  --toc-width: 220px;
  --section-padding: 5rem;
  --gutter: 2rem;
  --radius: 8px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
  --font-body: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', Consolas, monospace;
}

/* ============================================
   2. Reset & Base
   ============================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; scroll-padding-top: 80px; }
body {
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.7;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img, svg { display: block; max-width: 100%; }
ul, ol { list-style: none; }

/* ============================================
   3. Typography
   ============================================ */
h1, h2, h3, h4, h5, h6 { line-height: 1.3; font-weight: 700; color: var(--text); }
h1 { font-size: 3.5rem; letter-spacing: -0.02em; }
h2 { font-size: 2.25rem; letter-spacing: -0.01em; }
h3 { font-size: 1.5rem; font-weight: 600; }
h4 { font-size: 1.125rem; font-weight: 600; }
p { margin-bottom: 1rem; color: var(--text-secondary); }
code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background: var(--bg-tertiary);
  padding: 0.15em 0.4em;
  border-radius: 4px;
}
pre code { background: none; padding: 0; }

/* ============================================
   4. Layout Utilities
   ============================================ */
.container { max-width: var(--content-width); margin: 0 auto; padding: 0 var(--gutter); }
.container-narrow { max-width: var(--docs-width); margin: 0 auto; padding: 0 var(--gutter); }
.section { padding: var(--section-padding) 0; }
.section-alt { background: var(--bg-secondary); }
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 2rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2rem; }

/* ============================================
   5. Navigation
   ============================================ */
.navbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  height: 64px;
}
.navbar .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 100%;
}
.nav-logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  font-size: 1.125rem;
  color: var(--text);
  text-decoration: none;
}
.nav-logo:hover { text-decoration: none; }
.nav-logo svg { height: 28px; width: auto; }
.nav-links { display: flex; align-items: center; gap: 2rem; }
.nav-links a {
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-decoration: none;
  transition: color 0.2s;
}
.nav-links a:hover, .nav-links a.active { color: var(--primary); text-decoration: none; }
.hamburger {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.5rem;
}
.hamburger span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--text);
  margin: 5px 0;
  transition: 0.3s;
}

/* ============================================
   6. Homepage Sections
   ============================================ */
.hero {
  padding: 6rem 0 4rem;
  text-align: center;
}
.hero h1 {
  max-width: 800px;
  margin: 0 auto 1.5rem;
  background: linear-gradient(135deg, var(--text) 0%, var(--primary) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.hero-subtitle {
  font-size: 1.25rem;
  max-width: 640px;
  margin: 0 auto 2.5rem;
  color: var(--text-secondary);
  line-height: 1.7;
}
.hero-ctas { display: flex; gap: 1rem; justify-content: center; flex-wrap: wrap; margin-bottom: 2rem; }
.btn {
  display: inline-flex;
  align-items: center;
  padding: 0.75rem 1.75rem;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 1rem;
  text-decoration: none;
  transition: all 0.2s;
  border: none;
  cursor: pointer;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--bg-secondary); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--bg-tertiary); }
.install-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--code-bg);
  color: var(--code-text);
  padding: 0.6rem 1.25rem;
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 0.875rem;
}
.install-pill .copy-btn {
  background: none;
  border: none;
  color: var(--text-tertiary);
  cursor: pointer;
  padding: 0.25rem;
  font-size: 0.875rem;
}
.install-pill .copy-btn:hover { color: var(--code-text); }

/* Features */
.features-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2rem; }
.feature-card {
  padding: 2rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: box-shadow 0.2s;
}
.feature-card:hover { box-shadow: var(--shadow-md); }
.feature-icon {
  width: 48px;
  height: 48px;
  background: var(--primary-light);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  margin-bottom: 1rem;
}
.feature-card h4 { margin-bottom: 0.5rem; }
.feature-card p { font-size: 0.9375rem; margin-bottom: 0; }

/* Namespaces */
.namespace-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.5rem; }
.namespace-card {
  padding: 1.5rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.namespace-card code {
  font-size: 1rem;
  font-weight: 600;
  color: var(--primary);
  background: none;
  padding: 0;
}
.namespace-card p { font-size: 0.875rem; margin-bottom: 0.25rem; }
.namespace-examples { font-size: 0.8125rem; color: var(--text-tertiary); }

/* Operation Modes */
.modes-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.5rem; }
.mode-card {
  padding: 1.5rem;
  text-align: center;
  border-radius: var(--radius);
  background: var(--bg);
  border: 1px solid var(--border);
}
.mode-badge {
  display: inline-block;
  padding: 0.25rem 0.75rem;
  background: var(--primary-light);
  color: var(--primary);
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
}
.mode-card p { font-size: 0.875rem; margin-bottom: 0; }

/* Pine teaser */
.pine-teaser { text-align: center; }
.pine-teaser p { font-size: 1.125rem; max-width: 600px; margin: 0 auto 1.5rem; }

/* Section headers */
.section-header { text-align: center; margin-bottom: 3rem; }
.section-header h2 { margin-bottom: 1rem; }
.section-header p { max-width: 600px; margin: 0 auto; }

/* ============================================
   7. Code Blocks
   ============================================ */
.code-block {
  position: relative;
  background: var(--code-bg);
  border-radius: var(--radius);
  margin: 1.5rem 0;
  overflow: hidden;
}
.code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 1rem;
  background: rgba(255,255,255,0.05);
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.code-lang {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-tertiary);
  text-transform: uppercase;
}
.code-copy-btn {
  background: none;
  border: 1px solid rgba(255,255,255,0.15);
  color: var(--text-tertiary);
  padding: 0.25rem 0.75rem;
  border-radius: 4px;
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.2s;
}
.code-copy-btn:hover { background: rgba(255,255,255,0.1); color: var(--code-text); }
.code-copy-btn.copied { color: var(--success); border-color: var(--success); }
.code-block pre {
  padding: 1.25rem;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.875rem;
  line-height: 1.6;
  color: var(--code-text);
}
/* Syntax tokens */
.token-keyword { color: #C678DD; }
.token-string { color: #98C379; }
.token-number { color: #D19A66; }
.token-comment { color: #5C6370; font-style: italic; }
.token-function { color: #61AFEF; }
.token-operator { color: #56B6C2; }
.token-punctuation { color: #ABB2BF; }
.token-property { color: #E06C75; }
.token-builtin { color: #E5C07B; }

/* Inline code run command */
.run-command {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1.25rem;
  margin-top: 1rem;
  font-family: var(--font-mono);
  font-size: 0.875rem;
  color: var(--text-secondary);
}
.run-command .label { color: var(--primary); font-weight: 600; }

/* ============================================
   8. Documentation Layout
   ============================================ */
.docs-layout {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr var(--toc-width);
  gap: 0;
  max-width: calc(var(--sidebar-width) + var(--docs-width) + var(--toc-width) + 4rem);
  margin: 0 auto;
  padding-top: 2rem;
}
.docs-sidebar {
  position: sticky;
  top: 80px;
  height: calc(100vh - 80px);
  overflow-y: auto;
  padding: 1.5rem 1rem 1.5rem 0;
  border-right: 1px solid var(--border);
}
.docs-sidebar-nav a {
  display: block;
  padding: 0.375rem 1rem;
  font-size: 0.875rem;
  color: var(--text-secondary);
  border-radius: 4px;
  text-decoration: none;
  transition: all 0.15s;
}
.docs-sidebar-nav a:hover { color: var(--primary); background: var(--bg-secondary); text-decoration: none; }
.docs-sidebar-nav a.active { color: var(--primary); background: var(--primary-light); font-weight: 600; }
.docs-sidebar-nav .sidebar-group { margin-bottom: 1.5rem; }
.docs-sidebar-nav .sidebar-group-title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-tertiary);
  padding: 0 1rem;
  margin-bottom: 0.5rem;
}
.docs-content {
  padding: 1.5rem 2.5rem;
  min-width: 0;
  max-width: var(--docs-width);
}
.docs-content h2 {
  margin-top: 3rem;
  margin-bottom: 1rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}
.docs-content h2:first-of-type { margin-top: 0; border-top: none; padding-top: 0; }
.docs-content h3 { margin-top: 2rem; margin-bottom: 0.75rem; }
.docs-content p { color: var(--text-secondary); }
.docs-content ul, .docs-content ol { margin: 0.5rem 0 1rem 1.5rem; color: var(--text-secondary); }
.docs-content ul { list-style: disc; }
.docs-content ol { list-style: decimal; }
.docs-content li { margin-bottom: 0.375rem; }
.docs-toc {
  position: sticky;
  top: 80px;
  height: calc(100vh - 80px);
  overflow-y: auto;
  padding: 1.5rem 0 1.5rem 1rem;
  border-left: 1px solid var(--border);
}
.docs-toc-title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-tertiary);
  margin-bottom: 0.75rem;
}
.docs-toc a {
  display: block;
  font-size: 0.8125rem;
  color: var(--text-tertiary);
  padding: 0.25rem 0;
  text-decoration: none;
  transition: color 0.15s;
}
.docs-toc a:hover, .docs-toc a.active { color: var(--primary); }
.docs-toc a.indent { padding-left: 0.75rem; }

/* Anchor links */
.anchor-link {
  color: var(--text-tertiary);
  text-decoration: none;
  margin-left: 0.5rem;
  opacity: 0;
  transition: opacity 0.2s;
  font-weight: 400;
}
h2:hover .anchor-link, h3:hover .anchor-link { opacity: 1; }
.anchor-link:hover { color: var(--primary); text-decoration: none; }

/* ============================================
   9. API Reference
   ============================================ */
.api-entry {
  padding: 1.5rem 0;
  border-bottom: 1px solid var(--border);
}
.api-entry:last-child { border-bottom: none; }
.api-signature {
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 600;
  color: var(--primary);
  margin-bottom: 0.5rem;
}
.api-desc { color: var(--text-secondary); margin-bottom: 0.75rem; }
.api-params { margin-bottom: 0.5rem; }
.api-params dt {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
  float: left;
  clear: left;
  width: 120px;
}
.api-params dd {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-left: 130px;
  margin-bottom: 0.25rem;
}
.api-returns {
  font-size: 0.875rem;
  color: var(--text-secondary);
}
.api-returns strong { color: var(--text); }

/* ============================================
   10. Tables and Badges
   ============================================ */
.doc-table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5rem 0;
  font-size: 0.9375rem;
}
.doc-table th {
  text-align: left;
  padding: 0.75rem 1rem;
  background: var(--bg-secondary);
  border-bottom: 2px solid var(--border);
  font-weight: 600;
  color: var(--text);
}
.doc-table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
}
.doc-table tr:hover td { background: var(--bg-secondary); }
.badge {
  display: inline-block;
  padding: 0.125rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}
.badge-success { background: #DCFCE7; color: var(--success); }
.badge-warning { background: #FEF9C3; color: var(--warning); }
.badge-muted { background: var(--bg-tertiary); color: var(--muted); }
.badge-beginner { background: #DCFCE7; color: var(--success); }
.badge-intermediate { background: #FEF9C3; color: var(--warning); }
.badge-advanced { background: #FEE2E2; color: #DC2626; }

/* ============================================
   11. Examples Page
   ============================================ */
.examples-grid { display: flex; flex-direction: column; gap: 2rem; }
.example-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.example-card-header {
  padding: 1.5rem;
  border-bottom: 1px solid var(--border);
}
.example-card-header h3 { margin-bottom: 0.5rem; }
.example-meta { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 0.75rem; }
.example-tag {
  font-size: 0.75rem;
  padding: 0.125rem 0.5rem;
  background: var(--bg-tertiary);
  color: var(--text-tertiary);
  border-radius: 4px;
  font-family: var(--font-mono);
}
.example-card-header p { margin-bottom: 0; }
.example-card .code-block { margin: 0; border-radius: 0; }
.example-code-toggle {
  display: block;
  width: 100%;
  padding: 0.75rem;
  background: var(--bg-secondary);
  border: none;
  border-top: 1px solid var(--border);
  cursor: pointer;
  font-size: 0.875rem;
  color: var(--primary);
  font-weight: 500;
}
.example-code-toggle:hover { background: var(--bg-tertiary); }
.example-code-wrapper { max-height: 300px; overflow: hidden; position: relative; }
.example-code-wrapper.expanded { max-height: none; }
.example-code-wrapper:not(.expanded)::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 60px;
  background: linear-gradient(transparent, var(--code-bg));
  pointer-events: none;
}

/* ============================================
   12. Pine Comparison Layout
   ============================================ */
.comparison-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin: 1.5rem 0;
}
.comparison-col h4 {
  margin-bottom: 0.5rem;
  font-size: 0.875rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-tertiary);
}
.comparison-col .code-block { margin: 0; }
.translation-notes {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin: 2rem 0;
}
.translation-notes h3 { margin-bottom: 1rem; font-size: 1.125rem; }
.translation-notes ol { margin-left: 1.5rem; list-style: decimal; }
.translation-notes li { margin-bottom: 0.5rem; color: var(--text-secondary); }

/* Code tabs (mobile) */
.code-tabs { display: none; margin-bottom: 0.5rem; }
.code-tab-btn {
  padding: 0.5rem 1rem;
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.875rem;
  cursor: pointer;
  color: var(--text-secondary);
}
.code-tab-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ============================================
   13. Footer
   ============================================ */
.footer {
  border-top: 1px solid var(--border);
  padding: 3rem 0;
  margin-top: 4rem;
}
.footer-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.footer-links { display: flex; gap: 1.5rem; }
.footer-links a { font-size: 0.875rem; color: var(--text-secondary); }
.footer-links a:hover { color: var(--primary); }
.footer-copy { font-size: 0.8125rem; color: var(--text-tertiary); }

/* Page header for non-homepage pages */
.page-header {
  padding: 3rem 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0;
}
.page-header h1 { font-size: 2.5rem; margin-bottom: 0.75rem; }
.page-header p { font-size: 1.125rem; max-width: 640px; margin-bottom: 0; }

/* ============================================
   14. Responsive Overrides
   ============================================ */
@media (max-width: 1024px) {
  .docs-layout { grid-template-columns: 1fr; }
  .docs-sidebar, .docs-toc { display: none; }
  .docs-content { padding: 1.5rem 0; max-width: 100%; }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
  .features-grid { grid-template-columns: repeat(2, 1fr); }
  .namespace-grid { grid-template-columns: repeat(2, 1fr); }
  .modes-grid { grid-template-columns: repeat(2, 1fr); }
  .comparison-grid { grid-template-columns: 1fr; }
  .code-tabs { display: flex; gap: 0.5rem; }
}
@media (max-width: 768px) {
  h1 { font-size: 2.25rem; }
  h2 { font-size: 1.75rem; }
  :root { --section-padding: 3rem; --gutter: 1.25rem; }
  .hero { padding: 3rem 0 2rem; }
  .hero-subtitle { font-size: 1.0625rem; }
  .grid-2, .grid-3, .features-grid, .namespace-grid, .modes-grid { grid-template-columns: 1fr; }
  .nav-links { display: none; }
  .nav-links.open {
    display: flex;
    flex-direction: column;
    position: absolute;
    top: 64px;
    left: 0;
    right: 0;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    padding: 1rem var(--gutter);
    gap: 0.5rem;
    box-shadow: var(--shadow-md);
  }
  .hamburger { display: block; }
  .footer-content { flex-direction: column; gap: 1rem; text-align: center; }
  .footer-links { flex-wrap: wrap; justify-content: center; }
  .comparison-grid { grid-template-columns: 1fr; }
}
