:root {
  --bg: #0b0e14;
  --surface: #151a24;
  --surface-2: #1f2633;
  --border: #2a3244;
  --text: #e8e9ec;
  --muted: #8b90a0;
  --muted-2: #656a7a;
  --accent: #60a5fa;
  --accent-2: #fbbf24;
  --ok: #34d399;
  --warn: #f59e0b;
  --danger: #f87171;
  --purple: #a78bfa;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font-family: -apple-system, 'Inter', 'Segoe UI', sans-serif; font-size: 15.5px; line-height: 1.6; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre, .mono { font-family: ui-monospace, 'SF Mono', 'Menlo', monospace; }

nav {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 13px 24px;
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  gap: 20px;
  align-items: center;
}
nav .brand { font-weight: 700; color: var(--accent); font-family: ui-monospace, monospace; margin-right: 8px; }
nav a { color: var(--muted); font-size: 14px; padding: 6px 10px; border-radius: 6px; }
nav a:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }
nav a.active { color: var(--text); background: var(--surface-2); }

main { max-width: 880px; margin: 0 auto; padding: 28px 22px 80px; }

h1 { font-size: 28px; margin: 0 0 10px; letter-spacing: -0.02em; }
h2 { font-size: 22px; margin: 36px 0 12px; letter-spacing: -0.01em; color: var(--accent-2); }
h3 { font-size: 17px; margin: 22px 0 8px; color: var(--text); }
h4 { font-size: 15px; margin: 16px 0 6px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.subtitle { color: var(--muted); margin: 0 0 24px; font-size: 15px; }

.hero { background: linear-gradient(135deg, var(--surface) 0%, var(--surface-2) 100%); border: 1px solid var(--border); border-radius: 16px; padding: 32px; margin-bottom: 28px; }
.hero h1 { color: var(--accent); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-top: 20px; }
.stat { background: rgba(255,255,255,0.02); border: 1px solid var(--border); border-radius: 10px; padding: 14px; }
.stat .value { font-size: 26px; font-weight: 700; color: var(--accent-2); font-family: ui-monospace, monospace; }
.stat .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; margin-top: 2px; }

.chapter-list { display: grid; gap: 14px; }
.ch-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 20px;
  cursor: pointer;
  transition: border-color 0.15s;
}
.ch-card:hover { border-color: var(--accent); }
.ch-card h3 { margin-top: 0; color: var(--text); }
.ch-card .brief { color: var(--muted); font-size: 14px; }

.concept { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; margin: 10px 0; }
.concept .name { font-weight: 600; color: var(--accent-2); margin-bottom: 4px; }
.concept .body { font-size: 14.5px; }

.eq-card { background: var(--surface); border-left: 3px solid var(--accent); border-radius: 6px; padding: 12px 14px; margin: 10px 0; overflow-x: auto; }
.eq-card .eq { font-size: 17px; padding: 6px 0; }
.eq-card .eq-desc { color: var(--muted); font-size: 13px; margin-top: 4px; }

.gotcha {
  background: rgba(248, 113, 113, 0.06);
  border-left: 3px solid var(--danger);
  border-radius: 6px;
  padding: 10px 14px;
  margin: 8px 0;
  font-size: 14px;
  color: var(--text);
}
.gotcha::before { content: "⚠️ "; margin-right: 4px; }

.worked-ref { color: var(--muted); font-size: 13px; margin: 4px 0; }

/* Practice Qs */
.filter-bar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 18px;
  position: sticky;
  top: 54px;
  z-index: 10;
}
.filter-bar input[type="text"] { width: 100%; background: var(--surface-2); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 9px 11px; font-size: 14px; font-family: inherit; }
.filter-bar input[type="text"]:focus { outline: none; border-color: var(--accent); }
.filter-row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.chip {
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 11px;
  font-size: 12px;
  cursor: pointer;
  font-family: ui-monospace, monospace;
  user-select: none;
}
.chip:hover { color: var(--text); border-color: var(--muted-2); }
.chip.on { background: var(--accent); color: #0a1526; border-color: var(--accent); font-weight: 600; }

.q-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 20px;
  margin: 12px 0;
}
.q-meta { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.badge {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--border);
  font-family: ui-monospace, monospace;
}
.badge.diff-easy { color: var(--ok); border-color: rgba(52, 211, 153, 0.3); }
.badge.diff-medium { color: var(--accent-2); border-color: rgba(251, 191, 36, 0.3); }
.badge.diff-hard { color: var(--danger); border-color: rgba(248, 113, 113, 0.3); }
.badge.type-conceptual { color: var(--accent); }
.badge.type-computation { color: var(--purple); }
.badge.type-derivation { color: var(--warn); }

.q-prompt { font-size: 15.5px; color: var(--text); margin: 4px 0 12px; }
.q-actions { display: flex; gap: 8px; margin-top: 10px; }
.btn { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); border-radius: 6px; padding: 6px 12px; font-size: 13px; font-family: inherit; cursor: pointer; }
.btn:hover { color: var(--text); border-color: var(--accent); }
.btn.primary { background: var(--accent); color: #0a1526; border-color: var(--accent); }
.q-reveal { margin-top: 10px; padding: 12px 14px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; display: none; }
.q-reveal.open { display: block; }
.q-reveal h5 { margin: 0 0 6px; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; }
.q-reveal .answer { color: var(--accent-2); font-weight: 500; margin-top: 8px; }

details.hint { margin-top: 8px; }
details.hint summary { color: var(--muted); font-size: 13px; cursor: pointer; user-select: none; }
details.hint summary:hover { color: var(--text); }

.count { color: var(--muted); font-size: 13px; margin-bottom: 10px; }

.formula-section { margin: 18px 0; }
.formula-section h3 { color: var(--accent-2); border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.formula-item { display: flex; justify-content: space-between; gap: 20px; padding: 6px 0; border-bottom: 1px dashed var(--border); }
.formula-item:last-child { border-bottom: none; }
.formula-item .latex { font-size: 15px; }
.formula-item .desc { color: var(--muted); font-size: 13px; text-align: right; max-width: 40%; }

.q-source { color: var(--muted-2); font-size: 12px; font-family: ui-monospace, monospace; }

footer {
  max-width: 880px; margin: 40px auto 0; padding: 24px;
  color: var(--muted-2); font-size: 12px; text-align: center; border-top: 1px solid var(--border);
}

/* KaTeX overrides for dark theme */
.katex { color: var(--text) !important; }

/* Chapter navigation sidebar */
.layout { display: grid; grid-template-columns: 200px 1fr; gap: 28px; align-items: start; }
@media (max-width: 860px) { .layout { grid-template-columns: 1fr; } .sidebar { position: static; } }
.sidebar {
  position: sticky;
  top: 80px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  font-size: 13.5px;
}
.sidebar h5 { margin: 0 0 8px; color: var(--muted); text-transform: uppercase; font-size: 11px; letter-spacing: 0.05em; }
.sidebar ul { margin: 0; padding-left: 0; list-style: none; }
.sidebar li { margin: 2px 0; }
.sidebar a { color: var(--muted); display: block; padding: 4px 6px; border-radius: 4px; }
.sidebar a:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }
.sidebar a.active-nav { color: var(--accent-2); background: var(--surface-2); }

.chapter-section { scroll-margin-top: 80px; }
.chapter-summary { margin: 16px 0 28px; color: var(--text); max-width: 680px; }
.chapter-summary p { margin: 0 0 12px; line-height: 1.7; color: #d8d9dd; font-size: 15px; }
.chapter-summary p:last-child { margin-bottom: 0; }

.chapter-nav-buttons {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin: 32px 0 16px;
  padding: 16px 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.chapter-nav-buttons a {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--text);
  font-size: 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 140px;
}
.chapter-nav-buttons a:hover { border-color: var(--accent); text-decoration: none; }
.chapter-nav-buttons a.disabled { opacity: 0.3; pointer-events: none; }
.chapter-nav-buttons .dir { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; }
.chapter-nav-buttons .next { text-align: right; align-items: flex-end; margin-left: auto; }

.chapter-picker { display: grid; grid-template-columns: 1fr; gap: 12px; margin: 20px 0; }
.chapter-picker-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--text);
}
.chapter-picker-card:hover { border-color: var(--accent); text-decoration: none; }
.chapter-picker-card h3 { margin: 0 0 4px; color: var(--accent-2); }
.chapter-picker-card .meta { color: var(--muted); font-size: 13px; }
.chapter-picker-card .arrow { color: var(--accent); font-size: 22px; }

.diagrams { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; margin: 12px 0 20px; }
.diagram {
  margin: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  cursor: zoom-in;
  position: relative;
  transition: border-color 0.15s, transform 0.15s;
}
.diagram:hover { border-color: var(--accent); transform: translateY(-2px); }
.diagram:focus { outline: 2px solid var(--accent); }
.diagram img { width: 100%; height: auto; border-radius: 6px; background: var(--bg); pointer-events: none; }
.diagram figcaption { font-size: 12.5px; color: var(--muted); margin-top: 8px; line-height: 1.4; text-align: center; }
.expand-hint {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(0,0,0,0.7);
  color: var(--muted);
  font-size: 10.5px;
  padding: 3px 7px;
  border-radius: 4px;
  opacity: 0;
  transition: opacity 0.15s;
  pointer-events: none;
  font-family: ui-monospace, monospace;
}
.diagram:hover .expand-hint, .diagram:focus .expand-hint { opacity: 1; }

/* Lightbox */
#lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.9);
  display: none;
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
}
#lightbox.open { display: flex; }
.lb-inner {
  max-width: 90vw;
  max-height: 90vh;
  background: var(--surface);
  border-radius: 12px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  box-shadow: 0 25px 80px rgba(0, 0, 0, 0.6);
}
.lb-img {
  max-width: 100%;
  max-height: 75vh;
  width: auto;
  height: auto;
  background: var(--bg);
  border-radius: 8px;
}
.lb-caption { color: var(--text); font-size: 14.5px; text-align: center; max-width: 700px; line-height: 1.5; }
.lb-close {
  position: fixed;
  top: 20px;
  right: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  width: 40px;
  height: 40px;
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
}
.lb-close:hover { border-color: var(--accent); }

.ch-card { text-decoration: none; color: var(--text); display: block; }
.ch-card:hover { text-decoration: none; }
