/* === CSS Variables === */
:root {
  --bg-primary: #0a0e17;
  --bg-secondary: #111827;
  --bg-tertiary: #1a2236;
  --bg-card: #151d2e;
  --bg-code: #1e293b;
  --text-primary: #e2e8f0;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent: #3b82f6;
  --accent-light: #60a5fa;
  --accent-dark: #2563eb;
  --green: #22c55e;
  --red: #ef4444;
  --yellow: #eab308;
  --purple: #a855f7;
  --border: #1e293b;
  --sidebar-w: 280px;
  --header-h: 56px;
  --radius: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,0.3);
  --transition: 0.2s ease;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* === Reset === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }
body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.7;
  overflow-x: hidden;
  min-height: 100vh;
}
a { color: var(--accent-light); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
code { font-family: var(--font-mono); }

/* === Header === */
.header {
  position: fixed; top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: rgba(10, 14, 23, 0.95);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 16px;
  padding: 0 20px;
  z-index: 1000;
}
.header__logo {
  display: flex; align-items: center; gap: 10px;
  font-weight: 700; font-size: 1.1rem;
  cursor: pointer; white-space: nowrap;
  color: var(--text-primary);
}
.header__logo:hover { text-decoration: none; }
.header__logo-icon {
  width: 32px; height: 32px;
  background: linear-gradient(135deg, var(--accent), var(--purple));
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 900; font-size: 1rem; color: #fff;
}
.header__nav {
  display: flex; gap: 4px; margin-left: 16px;
}
.header__nav-link {
  padding: 6px 14px; border-radius: 6px;
  font-size: 0.875rem; font-weight: 500;
  color: var(--text-secondary);
  transition: var(--transition);
}
.header__nav-link:hover,
.header__nav-link.active {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  text-decoration: none;
}
.header__search {
  margin-left: auto;
  position: relative;
}
.header__search-icon {
  position: absolute; left: 10px; top: 50%;
  transform: translateY(-50%);
  font-size: 0.8rem; pointer-events: none;
}
.header__search-input {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 6px 12px 6px 32px;
  border-radius: 6px;
  font-size: 0.85rem;
  width: 220px;
  transition: var(--transition);
  outline: none;
}
.header__search-input:focus {
  border-color: var(--accent);
  width: 300px;
}
.header__hamburger {
  display: none;
  background: none; border: none;
  color: var(--text-primary);
  font-size: 1.5rem; cursor: pointer;
  padding: 4px 8px;
}

/* === Layout === */
.layout {
  display: flex;
  padding-top: var(--header-h);
  min-height: 100vh;
}

/* === Sidebar === */
.sidebar {
  position: fixed;
  top: var(--header-h);
  left: 0;
  width: var(--sidebar-w);
  height: calc(100vh - var(--header-h));
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 16px 0;
  z-index: 100;
  transition: transform 0.3s ease;
}
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.sidebar__overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 99;
}
.sidebar__section { margin-bottom: 8px; }
.sidebar__heading {
  padding: 8px 20px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  cursor: pointer;
  display: flex; align-items: center; justify-content: space-between;
  user-select: none;
}
.sidebar__heading:hover { color: var(--text-secondary); }
.sidebar__heading::after {
  content: '▸';
  font-size: 0.6rem;
  transition: transform 0.2s;
}
.sidebar__heading.open::after {
  transform: rotate(90deg);
}
.sidebar__links { display: none; }
.sidebar__links.open { display: block; }
.sidebar__link {
  display: block;
  padding: 5px 20px 5px 28px;
  font-size: 0.82rem;
  color: var(--text-secondary);
  transition: var(--transition);
  border-left: 2px solid transparent;
}
.sidebar__link:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  text-decoration: none;
}
.sidebar__link.active {
  color: var(--accent-light);
  border-left-color: var(--accent);
  background: rgba(59, 130, 246, 0.08);
}

/* === Main Content === */
.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-height: calc(100vh - var(--header-h));
  padding: 32px 40px;
  max-width: 900px;
}
.main__content { animation: fadeIn 0.25s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* === Markdown Content === */
.doc-content h1 { font-size: 2rem; margin: 0 0 16px; border-bottom: 1px solid var(--border); padding-bottom: 12px; }
.doc-content h2 { font-size: 1.5rem; margin: 40px 0 12px; color: var(--accent-light); }
.doc-content h3 { font-size: 1.2rem; margin: 28px 0 8px; color: var(--purple); }
.doc-content h4 { font-size: 1rem; margin: 20px 0 6px; }
.doc-content p { margin: 0 0 16px; }
.doc-content ul, .doc-content ol { margin: 0 0 16px; padding-left: 24px; }
.doc-content li { margin-bottom: 4px; }
.doc-content blockquote {
  border-left: 3px solid var(--accent);
  padding: 8px 16px;
  margin: 0 0 16px;
  background: rgba(59,130,246,0.06);
  border-radius: 0 var(--radius) var(--radius) 0;
  color: var(--text-secondary);
}
.doc-content img { border-radius: var(--radius); margin: 8px 0; }
.doc-content hr { border: none; border-top: 1px solid var(--border); margin: 32px 0; }
.doc-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 0 0 16px;
  font-size: 0.9rem;
}
.doc-content th, .doc-content td {
  padding: 8px 12px;
  border: 1px solid var(--border);
  text-align: left;
}
.doc-content th { background: var(--bg-tertiary); font-weight: 600; }
.doc-content tr:nth-child(even) { background: rgba(255,255,255,0.02); }

/* === Code Blocks === */
.doc-content pre {
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  overflow-x: auto;
  margin: 0 0 16px;
  position: relative;
}
.doc-content pre code {
  font-size: 0.85rem;
  line-height: 1.6;
  background: none;
  padding: 0;
  border-radius: 0;
}
.doc-content code {
  font-family: var(--font-mono);
  background: var(--bg-tertiary);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.85em;
  color: var(--accent-light);
}
.doc-content pre code { color: var(--text-primary); }

/* === Hero Section === */
.hero {
  position: relative;
  padding: 80px 0 60px;
  text-align: center;
  overflow: hidden;
}
.hero__canvas {
  position: absolute;
  top: 0; left: -40px; right: -40px;
  height: 100%;
  opacity: 0.15;
  pointer-events: none;
}
.hero__title {
  font-size: 3rem;
  font-weight: 800;
  background: linear-gradient(135deg, #60a5fa, #a78bfa, #f472b6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 16px;
  position: relative;
}
.hero__subtitle {
  font-size: 1.15rem;
  color: var(--text-secondary);
  max-width: 600px;
  margin: 0 auto 32px;
  line-height: 1.7;
}
.hero__buttons {
  display: flex; gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 24px;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: var(--transition);
}
.btn--primary {
  background: var(--accent);
  color: #fff;
}
.btn--primary:hover { background: var(--accent-dark); text-decoration: none; }
.btn--secondary {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border);
}
.btn--secondary:hover { border-color: var(--accent); text-decoration: none; }

/* === Cards === */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  margin: 24px 0;
}
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  transition: var(--transition);
  cursor: pointer;
}
.card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}
.card__number {
  font-size: 0.75rem;
  color: var(--accent);
  font-weight: 700;
  margin-bottom: 4px;
}
.card__title {
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 8px;
}
.card__desc {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

/* === Stats === */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 16px;
  margin: 32px 0;
}
.stat {
  text-align: center;
  padding: 20px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.stat__number {
  font-size: 2rem;
  font-weight: 800;
  color: var(--accent-light);
}
.stat__label {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* === Shader Editor === */
.editor-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  height: calc(100vh - var(--header-h) - 64px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.editor-panel {
  display: flex; flex-direction: column;
  background: var(--bg-code);
  border-right: 1px solid var(--border);
}
.editor-panel__header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px;
  background: var(--bg-tertiary);
  border-bottom: 1px solid var(--border);
  min-height: 40px;
}
.editor-panel__title {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
}
.editor-panel__actions {
  display: flex; gap: 6px;
}
.editor-btn {
  padding: 4px 12px;
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  color: var(--text-primary);
  border-radius: 4px;
  font-size: 0.75rem;
  cursor: pointer;
  transition: var(--transition);
}
.editor-btn:hover { border-color: var(--accent); }
.editor-btn--run { background: var(--green); border-color: var(--green); color: #000; }
.editor-btn--run:hover { opacity: 0.9; }
.canvas-panel {
  display: flex; flex-direction: column;
  background: #000;
}
.canvas-panel__header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px;
  background: var(--bg-tertiary);
  border-bottom: 1px solid var(--border);
  min-height: 40px;
}
.shader-select {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 0.8rem;
  max-width: 200px;
}
.canvas-wrapper {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.canvas-wrapper canvas {
  width: 100%;
  height: 100%;
  display: block;
}
.fps-counter {
  position: absolute;
  top: 8px; right: 8px;
  background: rgba(0,0,0,0.7);
  color: var(--green);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-family: var(--font-mono);
}
.error-overlay {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  background: rgba(239, 68, 68, 0.95);
  color: #fff;
  padding: 12px 16px;
  font-size: 0.8rem;
  font-family: var(--font-mono);
  max-height: 120px;
  overflow-y: auto;
  display: none;
}
.error-overlay.visible { display: block; }
textarea.code-editor {
  flex: 1;
  background: var(--bg-code);
  color: var(--text-primary);
  border: none;
  padding: 16px;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.6;
  resize: none;
  outline: none;
  tab-size: 2;
}

/* === File Explorer === */
.file-tree {
  font-size: 0.85rem;
}
.file-tree__item {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 8px;
  cursor: pointer;
  border-radius: 4px;
  transition: var(--transition);
}
.file-tree__item:hover { background: var(--bg-tertiary); }
.file-tree__item--folder { font-weight: 600; }
.file-tree__children { padding-left: 16px; display: none; }
.file-tree__children.open { display: block; }
.file-tree__icon { font-size: 0.9rem; width: 18px; text-align: center; }
.file-viewer {
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-top: 16px;
  overflow: hidden;
}
.file-viewer__header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 16px;
  background: var(--bg-tertiary);
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}
.file-viewer__content {
  padding: 16px;
  overflow-x: auto;
  max-height: 600px;
  overflow-y: auto;
}
.file-viewer__content pre {
  margin: 0;
  background: none;
  border: none;
  padding: 0;
}

/* === Table of Contents === */
.toc {
  position: fixed;
  right: 20px;
  top: calc(var(--header-h) + 32px);
  width: 200px;
  font-size: 0.8rem;
  max-height: calc(100vh - var(--header-h) - 64px);
  overflow-y: auto;
  display: none;
}
.toc__title {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.toc__link {
  display: block;
  padding: 3px 0;
  color: var(--text-muted);
  border-left: 2px solid var(--border);
  padding-left: 10px;
  transition: var(--transition);
}
.toc__link:hover { color: var(--text-primary); text-decoration: none; }
.toc__link.active { color: var(--accent-light); border-left-color: var(--accent); }
.toc__link--h3 { padding-left: 22px; font-size: 0.75rem; }

/* === Loading & 404 === */
.loading-state {
  display: flex; align-items: center; justify-content: center;
  gap: 12px; padding: 60px;
  color: var(--text-muted);
}
.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.not-found {
  text-align: center;
  padding: 80px 20px;
}
.not-found__code {
  font-size: 6rem;
  font-weight: 900;
  color: var(--border);
}
.not-found__msg {
  font-size: 1.2rem;
  color: var(--text-secondary);
  margin: 16px 0;
}

/* === Toast === */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 10px 20px;
  border-radius: var(--radius);
  font-size: 0.85rem;
  box-shadow: var(--shadow);
  transition: opacity 0.3s;
}
.toast--success { border-left: 3px solid var(--green); }
.toast--error { border-left: 3px solid var(--red); }

/* === Search Results === */
.search-results { margin: 16px 0; }
.search-result {
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
  cursor: pointer;
  transition: var(--transition);
}
.search-result:hover { border-color: var(--accent); background: var(--bg-tertiary); }
.search-result__title { font-weight: 600; margin-bottom: 4px; }
.search-result__path { font-size: 0.8rem; color: var(--text-muted); }
.search-result__excerpt { font-size: 0.85rem; color: var(--text-secondary); margin-top: 4px; }

/* === Responsive === */
@media (max-width: 1100px) {
  .toc { display: none !important; }
}
@media (max-width: 900px) {
  .header__search-input { width: 140px; }
  .header__search-input:focus { width: 180px; }
  .header__nav { display: none; }
  .header__hamburger { display: block; }
  .sidebar {
    transform: translateX(-100%);
    z-index: 200;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar__overlay.open { display: block; }
  .main { margin-left: 0; padding: 20px 16px; }
  .editor-layout { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
  .hero__title { font-size: 2rem; }
  .cards { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 480px) {
  .header__search { display: none; }
  .hero__title { font-size: 1.6rem; }
  .hero__subtitle { font-size: 0.95rem; }
  .btn { padding: 8px 16px; font-size: 0.85rem; }
}
