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

:root {
  --bg:        #070b14;
  --bg2:       #0d1220;
  --bg3:       #111827;
  --cyan:      #00d4ff;
  --cyan-dim:  rgba(0, 212, 255, 0.12);
  --cyan-glow: rgba(0, 212, 255, 0.25);
  --text:      #e2e8f0;
  --text-muted:#7a8fa6;
  --border:    rgba(0, 212, 255, 0.12);
  --font:      'Inter', sans-serif;
  --mono:      'JetBrains Mono', monospace;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
}

/* ── Hero ── */
.hero {
  position: relative;
  height: 100vh;
  overflow: hidden;
}

.hero canvas {
  position: absolute;
  inset: 0;
  z-index: 0;
}

.hero-overlay {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  pointer-events: none;
}

.hero-overlay h1 {
  font-size: clamp(2rem, 5vw, 3.5rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 0.5rem;
}

.hero-overlay h1 span {
  color: var(--cyan);
}

.hero-overlay p {
  font-size: clamp(0.95rem, 2vw, 1.15rem);
  color: var(--text-muted);
  max-width: 520px;
  line-height: 1.6;
}

.hero-overlay .subtitle {
  font-family: var(--mono);
  font-size: 0.85rem;
  color: var(--cyan);
  opacity: 0.7;
  margin-bottom: 1.5rem;
  letter-spacing: 0.05em;
}

.scroll-hint {
  position: absolute;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-family: var(--mono);
  opacity: 0.5;
  animation: pulse 2s ease-in-out infinite;
  pointer-events: none;
}

@keyframes pulse {
  0%, 100% { opacity: 0.3; transform: translateX(-50%) translateY(0); }
  50% { opacity: 0.7; transform: translateX(-50%) translateY(5px); }
}

/* ── Navigation ── */
.nav {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(7, 11, 20, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 2rem;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  overflow-x: auto;
  scrollbar-width: none;
}

.nav::-webkit-scrollbar { display: none; }

.nav-brand {
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--cyan);
  white-space: nowrap;
  flex-shrink: 0;
  text-decoration: none;
}

.nav-links {
  display: flex;
  gap: 0.25rem;
  list-style: none;
}

.nav-links a {
  font-size: 0.78rem;
  color: var(--text-muted);
  text-decoration: none;
  padding: 0.35rem 0.65rem;
  border-radius: 4px;
  white-space: nowrap;
  transition: color 0.2s, background 0.2s;
}

.nav-links a:hover,
.nav-links a.active {
  color: var(--cyan);
  background: var(--cyan-dim);
}

/* ── Chapters ── */
.chapter {
  max-width: 780px;
  margin: 0 auto;
  padding: 5rem 2rem;
  border-bottom: 1px solid var(--border);
}

.chapter:last-child {
  border-bottom: none;
}

.chapter-number {
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--cyan);
  opacity: 0.6;
  margin-bottom: 0.5rem;
  letter-spacing: 0.08em;
}

.chapter h2 {
  font-size: clamp(1.5rem, 3vw, 2.2rem);
  font-weight: 600;
  margin-bottom: 1rem;
  letter-spacing: -0.01em;
}

.chapter h2 span {
  color: var(--cyan);
}

.chapter-intro {
  color: var(--text-muted);
  font-size: 1.05rem;
  margin-bottom: 2rem;
  max-width: 600px;
}

.chapter-body h3 {
  font-size: 1.15rem;
  font-weight: 600;
  margin: 2rem 0 0.75rem;
  color: var(--text);
}

.chapter-body p {
  margin-bottom: 1rem;
  color: var(--text-muted);
}

.chapter-body .math-block {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.5rem;
  margin: 1.5rem 0;
  overflow-x: auto;
  text-align: center;
}

.chapter-body .definition {
  border-left: 3px solid var(--cyan);
  background: var(--bg2);
  padding: 1rem 1.25rem;
  border-radius: 0 8px 8px 0;
  margin: 1.5rem 0;
}

.chapter-body .definition-label {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--cyan);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.5rem;
}

/* ── Interactive canvas placeholders ── */
.viz-container {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin: 2rem 0;
  padding: 1rem;
  min-height: 300px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.viz-container canvas {
  width: 100%;
  max-width: 700px;
}

.viz-placeholder {
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: 0.85rem;
  opacity: 0.5;
}

/* ── Footer ── */
.footer {
  text-align: center;
  padding: 3rem 2rem;
  color: var(--text-muted);
  font-size: 0.85rem;
  border-top: 1px solid var(--border);
}

.footer a {
  color: var(--cyan);
  text-decoration: none;
}

/* ── Proof Card (modal overlay) ── */
.proof-trigger {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-family: var(--mono);
  font-size: 0.82rem;
  color: var(--cyan);
  background: var(--cyan-dim);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.45rem 0.9rem;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
  margin: 1rem 0;
}

.proof-trigger:hover {
  background: var(--cyan-glow);
  border-color: var(--cyan);
}

.proof-trigger::before {
  content: '▸';
  font-size: 0.7rem;
  transition: transform 0.2s;
}

.proof-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.proof-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.proof-card {
  position: relative;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  max-width: 720px;
  width: 90vw;
  max-height: 85vh;
  overflow-y: auto;
  padding: 2.5rem 2rem 2rem;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5), 0 0 60px rgba(0, 212, 255, 0.05);
}

.proof-card-title {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--cyan);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 1.25rem;
}

.proof-card h4 {
  font-size: 1.05rem;
  font-weight: 600;
  margin: 1.5rem 0 0.6rem;
  color: var(--text);
}

.proof-card p {
  margin-bottom: 0.9rem;
  color: var(--text-muted);
  line-height: 1.7;
}

.proof-card .math-block {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem;
  margin: 1.25rem 0;
  overflow-x: auto;
  text-align: center;
}

.proof-card-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s, background 0.2s;
}

.proof-card-close:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
}

/* scrollbar for proof card */
.proof-card::-webkit-scrollbar { width: 6px; }
.proof-card::-webkit-scrollbar-track { background: transparent; }
.proof-card::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── KaTeX overrides ── */
.katex { color: var(--text); }
.katex-display { margin: 0; }

/* ── Responsive ── */
@media (max-width: 640px) {
  .nav { padding: 0.5rem 1rem; gap: 0.75rem; }
  .chapter { padding: 3rem 1.25rem; }
}
