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

/* ── Theme Variables ─────────────────────────────────────── */
:root {
  --bg:           #ffffff;
  --bg-sidebar:   #f8f9fa;
  --bg-code:      #f4f5f7;
  --bg-hover:     #eef0f3;
  --border:       #e0e3e8;
  --text:         #1a1a2e;
  --text-dim:     #555b6e;
  --text-link:    #1a6dd4;
  --accent:       #2563eb;
  --sidebar-w:    220px;
  --topbar-h:     52px;
  --radius:       6px;
}

[data-theme="dark"] {
  --bg:           #16161e;
  --bg-sidebar:   #1c1c28;
  --bg-code:      #1e1e2e;
  --bg-hover:     #24243a;
  --border:       #2a2a3e;
  --text:         #e2e8f0;
  --text-dim:     #94a3b8;
  --text-link:    #60a5fa;
  --accent:       #60a5fa;
}

html { scroll-behavior: smooth; }

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

code, pre, .mono {
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
}

a {
  color: var(--text-link);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

/* ── Top Bar ─────────────────────────────────────────────── */
.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--topbar-h);
  background: var(--bg-sidebar);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  z-index: 100;
}

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

.topbar-brand:hover {
  text-decoration: none;
}

.topbar-brand span {
  font-weight: 400;
  color: var(--text-dim);
  font-size: 0.9rem;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.topbar-link {
  color: var(--text-dim);
  font-size: 0.85rem;
  font-weight: 500;
}
.topbar-link:hover {
  color: var(--text);
}

/* Theme toggle */
.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 34px;
  height: 34px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  font-size: 1rem;
  transition: background 0.15s, color 0.15s;
}
.theme-toggle:hover {
  background: var(--bg-hover);
  color: var(--text);
}

/* Mobile menu button */
.menu-toggle {
  display: none;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 34px;
  height: 34px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  font-size: 1.1rem;
}

/* ── Layout ──────────────────────────────────────────────── */
.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
  padding-top: var(--topbar-h);
}

/* ── Sidebar ─────────────────────────────────────────────── */
.sidebar {
  position: fixed;
  top: var(--topbar-h);
  left: 0;
  bottom: 0;
  width: var(--sidebar-w);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  padding: 24px 0;
  overflow-y: auto;
}

.sidebar-nav {
  list-style: none;
}

.sidebar-nav li a {
  display: block;
  padding: 6px 24px;
  font-size: 0.88rem;
  color: var(--text-dim);
  font-weight: 500;
  text-decoration: none;
  border-left: 3px solid transparent;
  transition: color 0.1s, border-color 0.1s, background 0.1s;
}

.sidebar-nav li a:hover {
  color: var(--text);
  background: var(--bg-hover);
  text-decoration: none;
}

.sidebar-nav li a.active {
  color: var(--accent);
  border-left-color: var(--accent);
  background: var(--bg-hover);
}

/* ── Main Content ────────────────────────────────────────── */
.main {
  grid-column: 2;
  max-width: 960px;
  width: 100%;
  margin: 0 auto;
  padding: 48px 60px 80px;
}

/* ── Highlight Box (Impact Statement) ────────────────────── */
.highlight-box {
  margin-top: 24px;
  padding: 16px 20px;
  border-left: 4px solid var(--accent);
  background: var(--bg-code);
  border-radius: 0 var(--radius) var(--radius) 0;
  font-size: 1.1rem;
  font-weight: 500;
  line-height: 1.6;
  color: var(--text);
}

/* ── Title Block ─────────────────────────────────────────── */
.title-block {
  margin-bottom: 48px;
  padding-bottom: 32px;
  border-bottom: 1px solid var(--border);
}

.title-block h1 {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1.3;
  margin-bottom: 16px;
}

.authors {
  margin-bottom: 8px;
}

.authors a,
.authors span {
  font-size: 0.95rem;
  color: var(--text);
  font-weight: 500;
}

.authors .sep {
  color: var(--text-dim);
  margin: 0 2px;
}

.affiliation {
  font-size: 0.88rem;
  color: var(--text-dim);
  margin-bottom: 20px;
}

.quick-links {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.quick-links a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  font-size: 0.85rem;
  font-weight: 500;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-dim);
  transition: border-color 0.15s, color 0.15s;
}

.quick-links a:hover {
  border-color: var(--accent);
  color: var(--accent);
  text-decoration: none;
}

.quick-links .coming-soon,
.tool-link .coming-soon {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  font-size: 0.85rem;
  font-weight: 500;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--text-dim);
  opacity: 0.6;
  cursor: default;
}

/* ── Sections ────────────────────────────────────────────── */
.content-section {
  margin-bottom: 48px;
  scroll-margin-top: calc(var(--topbar-h) + 24px);
}

.content-section h2 {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.content-section h3 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-top: 24px;
  margin-bottom: 8px;
}

.content-section p {
  margin-bottom: 12px;
  color: var(--text);
}

.content-section ul,
.content-section ol {
  padding-left: 24px;
  margin-bottom: 12px;
}

.content-section li {
  margin-bottom: 4px;
  color: var(--text);
}

.content-section li::marker {
  color: var(--text-dim);
}

/* ── Tool Subsections ────────────────────────────────────── */
.tool-item {
  margin-bottom: 24px;
  padding: 20px;
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.tool-item h3 {
  margin-top: 0;
  font-size: 1.05rem;
}

.tool-item .tool-tag {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  background: var(--bg-hover);
  padding: 2px 8px;
  border-radius: 4px;
  margin-bottom: 8px;
}

.tool-item p {
  font-size: 0.93rem;
}

.tool-item ul {
  padding-left: 20px;
  margin-top: 8px;
  margin-bottom: 8px;
}

.tool-item li {
  font-size: 0.93rem;
}

.tool-item .tool-link {
  margin-top: 8px;
  font-size: 0.88rem;
}

/* ── Loop Steps ──────────────────────────────────────────── */
.loop-steps {
  counter-reset: step;
}

.loop-step {
  display: flex;
  gap: 16px;
  margin-bottom: 16px;
  align-items: flex-start;
}

.loop-step-num {
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--bg-code);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--accent);
  margin-top: 2px;
}

.loop-step-content h4 {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 2px;
}

.loop-step-content p {
  font-size: 0.93rem;
  color: var(--text-dim);
  margin-bottom: 0;
}

/* ── Code / BibTeX Block ─────────────────────────────────── */
.code-block {
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  overflow-x: auto;
  position: relative;
}

.code-block pre {
  font-size: 0.82rem;
  line-height: 1.6;
  color: var(--text);
  white-space: pre;
}

.code-block .copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 10px;
  font-size: 0.75rem;
  color: var(--text-dim);
  cursor: pointer;
  font-family: inherit;
}

.code-block .copy-btn:hover {
  color: var(--text);
}

/* ── Placeholder Notice ──────────────────────────────────── */
.placeholder-notice {
  background: var(--bg-code);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  color: var(--text-dim);
  font-style: italic;
  font-size: 0.9rem;
}

/* ── Hero Chart ──────────────────────────────────────────── */
.hero-chart {
  margin-bottom: 48px;
}

.hero-chart a {
  display: block;
  text-decoration: none;
}

.hero-chart img {
  width: 100%;
  height: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.hero-caption {
  text-align: center;
  font-size: 0.82rem;
  color: var(--text-dim);
  margin-top: 8px;
}

.hero-caption a {
  display: inline;
}

/* ── Stats Grid (Experiment Results) ────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin: 20px 0 24px;
}

.stat-card {
  text-align: center;
  padding: 20px 12px;
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.stat-value {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.2;
}

.stat-label {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
  margin-top: 4px;
}

.stat-note {
  font-size: 0.78rem;
  color: var(--text-dim);
  margin-top: 2px;
}

.results-chart {
  margin: 24px 0;
}

.results-chart img {
  width: 100%;
  height: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

/* ── Footer ──────────────────────────────────────────────── */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 24px 0;
  margin-top: 24px;
  text-align: center;
}

.footer-links {
  display: flex;
  gap: 24px;
  justify-content: center;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.footer-links a {
  color: var(--text-dim);
  font-size: 0.85rem;
}

.footer-credit {
  color: var(--text-dim);
  font-size: 0.8rem;
}

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 768px) {
  .menu-toggle {
    display: flex;
  }

  .layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    top: var(--topbar-h);
    left: -260px;
    width: 260px;
    z-index: 90;
    transition: left 0.25s ease;
    box-shadow: none;
  }

  .sidebar.open {
    left: 0;
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.15);
  }

  [data-theme="dark"] .sidebar.open {
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.4);
  }

  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    top: var(--topbar-h);
    background: rgba(0, 0, 0, 0.3);
    z-index: 80;
  }

  .sidebar-overlay.visible {
    display: block;
  }

  .main {
    grid-column: 1;
    padding: 32px 20px 60px;
  }

  .title-block h1 {
    font-size: 1.6rem;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }

  .topbar-link.hide-mobile {
    display: none;
  }
}

@media (max-width: 480px) {
  .quick-links {
    flex-direction: column;
  }

  .quick-links a {
    width: fit-content;
  }
}

/* ── Accessibility: Reduced Motion ───────────────────────── */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }

  .sidebar {
    transition: none;
  }
}
