:root {
  --bg: #080808;
  --surface: #101010;
  --surface2: #181818;
  --border: #252525;
  --text: #d4d4d4;
  --text-dim: #777;
  --accent: #e0e0e0;
  --accent2: #aaa;
  --accent3: #888;
  --red: #d95555;
  --yellow: #c9a84c;
  --green: #5db85d;
  --blue: #6a9fc4;
  --purple: #9475b2;
  --orange: #c78740;
  --radius: 6px;
}

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

body {
  font-family: 'Inter', -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.65;
  overflow-x: hidden;
}

/* ===== Sidebar ===== */
.sidebar {
  position: fixed;
  left: 0; top: 0;
  width: 260px;
  height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  z-index: 100;
  padding: 16px 0;
}
.sidebar h2 {
  padding: 0 18px 14px;
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 1px;
  text-transform: uppercase;
  border-bottom: 1px solid var(--border);
  margin-bottom: 6px;
}
.sidebar-search {
  padding: 0 18px 10px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 6px;
}
.sidebar-search input {
  width: 100%;
  padding: 7px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.85rem;
}
.sidebar-search input:focus {
  outline: none;
  border-color: var(--accent2);
}
.nav-heading {
  padding: 10px 18px 6px;
  font-size: 0.7rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1px;
  font-weight: 600;
}
.glossary-link {
  font-weight: 600;
  color: var(--accent) !important;
  border-bottom: 1px solid var(--border);
  padding-bottom: 10px !important;
  margin-bottom: 4px;
}
.sidebar a {
  display: block;
  padding: 5px 18px;
  color: var(--text-dim);
  text-decoration: none;
  font-size: 0.8rem;
  transition: all 0.15s;
  border-left: 2px solid transparent;
}
.sidebar a:hover, .sidebar a.active {
  color: var(--text);
  background: var(--surface2);
  border-left-color: var(--accent);
}

/* ===== Main ===== */
.main {
  margin-left: 260px;
  padding: 36px 48px 100px;
  max-width: 920px;
}
.main h1 {
  font-size: 2rem;
  color: var(--accent);
  font-weight: 700;
  margin-bottom: 4px;
  letter-spacing: -0.5px;
}
.main > .subtitle {
  color: var(--text-dim);
  font-size: 0.95rem;
  margin-bottom: 40px;
}

/* ===== Theorem Cards ===== */
.theorem {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 16px;
  position: relative;
  overflow: hidden;
  transition: border-color 0.2s;
}
.theorem:hover {
  border-color: #333;
}
.theorem::before {
  content: '';
  position: absolute;
  left: 0; top: 0;
  width: 3px;
  height: 100%;
  background: var(--accent2);
}
.theorem-header {
  padding: 14px 24px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  user-select: none;
}
.theorem-header:hover {
  background: rgba(255, 255, 255, 0.015);
}
.theorem-header h2 {
  font-size: 1.05rem;
  color: var(--accent);
  margin: 0;
  font-weight: 600;
}
.chevron {
  width: 16px;
  height: 16px;
  fill: var(--text-dim);
  transition: transform 0.25s;
  flex-shrink: 0;
}
.theorem.open .chevron {
  transform: rotate(180deg);
}
.theorem-content {
  padding: 0 24px;
  max-height: 0;
  opacity: 0;
  visibility: hidden;
  overflow: hidden;
  transition: all 0.25s ease;
}
.theorem.open .theorem-content {
  padding: 8px 24px 24px;
  max-height: 8000px;
  opacity: 1;
  visibility: visible;
}

/* Statement */
.theorem .statement {
  background: var(--surface2);
  border-radius: 4px;
  padding: 12px 16px;
  margin: 8px 0 12px;
  border-left: 3px solid var(--accent);
  text-align: center;
  font-size: 1.05rem;
}

/* Intuition */
.theorem .intuition {
  background: rgba(255, 255, 255, 0.02);
  border-left: 3px solid var(--accent2);
  border-radius: 4px;
  padding: 10px 14px;
  margin: 10px 0;
  font-size: 0.92rem;
}
.theorem .intuition::before {
  content: 'KEY IDEA';
  display: block;
  font-weight: 700;
  color: var(--accent2);
  margin-bottom: 4px;
  font-size: 0.75rem;
  letter-spacing: 0.5px;
}

/* Proof */
.theorem .proof {
  background: rgba(255, 255, 255, 0.015);
  border-left: 3px solid var(--text-dim);
  border-radius: 4px;
  padding: 10px 14px;
  margin: 10px 0;
  font-size: 0.88rem;
}
.theorem .proof::before {
  content: 'PROOF';
  display: block;
  font-weight: 700;
  color: var(--text-dim);
  margin-bottom: 4px;
  font-size: 0.75rem;
  letter-spacing: 0.5px;
}

/* Memory Hook */
.theorem .memory {
  background: rgba(201, 168, 76, 0.06);
  border-left: 3px solid var(--yellow);
  border-radius: 4px;
  padding: 10px 14px;
  margin: 10px 0;
  font-size: 0.88rem;
}
.theorem .memory::before {
  content: 'REMEMBER';
  display: block;
  font-weight: 700;
  color: var(--yellow);
  margin-bottom: 4px;
  font-size: 0.75rem;
  letter-spacing: 0.5px;
}

/* ELI5 — Plain English */
.theorem .eli5 {
  background: rgba(93, 184, 93, 0.06);
  border-left: 3px solid var(--green);
  border-radius: 4px;
  padding: 10px 14px;
  margin: 10px 0;
  font-size: 0.92rem;
  line-height: 1.7;
}
.theorem .eli5::before {
  content: 'PLAIN ENGLISH';
  display: block;
  font-weight: 700;
  color: var(--green);
  margin-bottom: 4px;
  font-size: 0.75rem;
  letter-spacing: 0.5px;
}

/* Simple Proof */
.theorem .proof-simple {
  background: rgba(106, 159, 196, 0.06);
  border-left: 3px solid var(--blue);
  border-radius: 4px;
  padding: 10px 14px;
  margin: 10px 0;
  font-size: 0.9rem;
  line-height: 1.7;
}
.theorem .proof-simple::before {
  content: 'PROOF IN SIMPLE TERMS';
  display: block;
  font-weight: 700;
  color: var(--blue);
  margin-bottom: 4px;
  font-size: 0.75rem;
  letter-spacing: 0.5px;
}

/* ===== Viz Canvas ===== */
.viz-container {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 12px;
  margin: 12px 0;
  position: relative;
}
.viz-container canvas {
  display: block;
  margin: 0 auto;
  cursor: pointer;
}
.viz-controls {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-top: 10px;
  flex-wrap: wrap;
}
.viz-controls button {
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: 4px;
  padding: 6px 14px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}
.viz-controls button:hover {
  opacity: 0.85;
}
.viz-controls button.secondary {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
}
.viz-controls button.secondary:hover {
  border-color: var(--accent2);
  color: var(--text);
}
.viz-label {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.8rem;
  margin-top: 6px;
}

/* ===== Section Headers ===== */
.section-header {
  font-size: 1.2rem;
  color: var(--accent);
  margin: 40px 0 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  letter-spacing: -0.3px;
}

/* ===== Quiz Split (side-by-side) ===== */
.quiz-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 10px;
}
.quiz-panel {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 10px;
}
.quiz-panel h3 {
  font-size: 0.85rem;
  color: var(--accent2);
  margin-bottom: 6px;
  text-align: center;
  font-weight: 600;
}
.quiz-panel canvas {
  display: block;
  width: 100%;
  max-width: 420px;
  height: auto;
  margin: 0 auto;
}

/* ===== Glossary ===== */
.glossary-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 32px;
  overflow: hidden;
}
.glossary-header {
  padding: 14px 24px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  user-select: none;
  background: var(--surface2);
}
.glossary-header h2 {
  margin: 0;
  font-size: 1.1rem;
  color: var(--accent);
  font-weight: 600;
}
.glossary-section.open .chevron {
  transform: rotate(180deg);
}
.glossary-wrapper {
  max-height: 0;
  opacity: 0;
  visibility: hidden;
  overflow: hidden;
  transition: all 0.25s ease;
  padding: 0 24px;
}
.glossary-section.open .glossary-wrapper {
  padding: 16px 24px 24px;
  max-height: 5000px;
  opacity: 1;
  visibility: visible;
}
.glossary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}
.glossary-item {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 12px;
  transition: border-color 0.15s;
}
.glossary-item:hover {
  border-color: var(--accent2);
}
.glossary-term {
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 4px;
  font-size: 0.95rem;
}
.glossary-def {
  font-size: 0.82rem;
  color: var(--text-dim);
  line-height: 1.5;
}

.hidden { display: none !important; }
.no-results {
  text-align: center;
  padding: 32px;
  color: var(--text-dim);
  font-style: italic;
  background: var(--surface);
  border-radius: 4px;
  border: 1px dashed var(--border);
}

/* ===== Responsive ===== */
@media (max-width: 900px) {
  .sidebar {
    position: relative;
    width: 100%;
    height: auto;
    max-height: 30vh;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 8px 0;
  }
  .main { margin-left: 0; padding: 16px; }
  .quiz-split { grid-template-columns: 1fr; }
}

/* ===== KaTeX ===== */
.katex { font-size: 1.05em; }
.statement .katex { font-size: 1.15em; }

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: #222; border-radius: 3px; }

html { scroll-behavior: smooth; }
