/* ============ AI Explainer — shared theme ============ */
:root {
  --bg: #0b0e14;
  --bg-soft: #12161f;
  --panel: #171c26;
  --panel-2: #1e2430;
  --border: #2a3140;
  --text: #e6e9ef;
  --text-dim: #9aa4b2;
  --accent: #4da3ff;
  --accent-2: #b07aff;
  --good: #3ddc84;
  --bad: #ff5d73;
  --warn: #ffc857;
  --q-color: #4da3ff;
  --k-color: #ff5d73;
  --v-color: #3ddc84;
  --radius: 12px;
  --mono: "JetBrains Mono", "Fira Code", ui-monospace, Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  line-height: 1.6;
}

/* ---------- Nav ---------- */
.site-nav {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.5rem 1rem;
  background: rgba(11, 14, 20, 0.85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  white-space: nowrap;
}
.site-nav .brand {
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
  margin-right: 0.75rem;
  font-size: 1.02rem;
}
.site-nav .brand .spark { color: var(--accent); }
.site-nav a.nav-link {
  color: var(--text-dim);
  text-decoration: none;
  padding: 0.3rem 0.65rem;
  border-radius: 8px;
  font-size: 0.9rem;
  transition: color 0.15s, background 0.15s;
}
.site-nav a.nav-link:hover { color: var(--text); background: var(--panel-2); }
.site-nav a.nav-link.active { color: var(--accent); background: rgba(77, 163, 255, 0.12); }

/* ---------- Layout ---------- */
.page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 4rem;
}
.page-header { margin: 1.5rem 0 0.5rem; }
.page-header h1 { font-size: 2rem; margin: 0 0 0.25rem; }
.page-header .subtitle { color: var(--text-dim); font-size: 1.05rem; margin: 0; }
.crumbs { font-size: 0.85rem; color: var(--text-dim); margin-top: 1rem; }
.crumbs a { color: var(--accent); text-decoration: none; }

section.explainer { margin-top: 2.25rem; }
section.explainer h2 {
  font-size: 1.35rem;
  border-left: 4px solid var(--accent);
  padding-left: 0.6rem;
  margin-bottom: 0.5rem;
}
section.explainer h3 { font-size: 1.05rem; color: var(--text); }
section.explainer p { color: var(--text-dim); max-width: 72ch; }
section.explainer p strong { color: var(--text); }

/* ---------- Panels / viz containers ---------- */
.viz-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin: 1rem 0;
}
.viz-panel canvas {
  display: block;
  width: 100%;
  border-radius: 8px;
  background: var(--bg-soft);
  touch-action: none;
}
.viz-caption {
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-top: 0.6rem;
  text-align: center;
}

/* ---------- Controls ---------- */
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
  align-items: center;
  margin-top: 0.85rem;
  padding-top: 0.85rem;
  border-top: 1px solid var(--border);
}
.control-group { display: flex; align-items: center; gap: 0.5rem; }
.control-group label { font-size: 0.85rem; color: var(--text-dim); }
.control-group .value {
  font-family: var(--mono);
  font-size: 0.85rem;
  color: var(--accent);
  min-width: 3.5ch;
  text-align: right;
}
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 140px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--accent);
  cursor: grab;
}
input[type="range"]::-moz-range-thumb {
  width: 15px; height: 15px; border-radius: 50%;
  background: var(--accent); border: none; cursor: grab;
}
button.btn {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.42rem 0.9rem;
  font-size: 0.88rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  font-family: var(--sans);
}
button.btn:hover { background: #252c3a; border-color: #3a4358; }
button.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #06121f;
  font-weight: 600;
}
button.btn.primary:hover { background: #6cb4ff; }
button.btn.danger-outline { color: var(--bad); }
button.btn.active { border-color: var(--accent); color: var(--accent); }
select, input[type="text"] {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.4rem 0.6rem;
  font-size: 0.88rem;
  font-family: var(--sans);
  outline: none;
}
select:focus, input[type="text"]:focus { border-color: var(--accent); }

/* ---------- Stats / readouts ---------- */
.stat-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  font-family: var(--mono);
  font-size: 0.85rem;
  margin-top: 0.6rem;
}
.stat-row .stat span.label { color: var(--text-dim); }
.stat-row .stat span.val { color: var(--good); }

/* ---------- Math / formula boxes ---------- */
.formula {
  font-family: var(--mono);
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.8rem 1rem;
  margin: 0.75rem 0;
  overflow-x: auto;
  font-size: 0.95rem;
  color: var(--text);
}
.formula .hl { color: var(--accent); }
.formula .hl2 { color: var(--accent-2); }

/* ---------- Cards (landing + glossary) ---------- */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1rem;
  margin-top: 1.25rem;
}
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
  text-decoration: none;
  color: var(--text);
  transition: transform 0.15s, border-color 0.15s;
  display: block;
}
.card:hover { transform: translateY(-3px); border-color: var(--accent); }
.card h3 { margin: 0 0 0.3rem; font-size: 1.05rem; }
.card p { margin: 0; font-size: 0.87rem; color: var(--text-dim); }
.card .tag {
  display: inline-block;
  font-size: 0.7rem;
  font-family: var(--mono);
  color: var(--accent);
  background: rgba(77, 163, 255, 0.1);
  border-radius: 6px;
  padding: 0.1rem 0.45rem;
  margin-bottom: 0.5rem;
}

/* ---------- Term chips (inline glossary links) ---------- */
a.term {
  color: var(--accent-2);
  text-decoration: none;
  border-bottom: 1px dashed rgba(176, 122, 255, 0.5);
}
a.term:hover { border-bottom-style: solid; }

/* ---------- Legend ---------- */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  font-size: 0.82rem;
  color: var(--text-dim);
  margin-top: 0.5rem;
  justify-content: center;
}
.legend .swatch {
  display: inline-block;
  width: 11px;
  height: 11px;
  border-radius: 3px;
  margin-right: 5px;
  vertical-align: -1px;
}

/* ---------- Footer nav (prev/next) ---------- */
.pager {
  display: flex;
  justify-content: space-between;
  margin-top: 3rem;
  gap: 1rem;
}
.pager a {
  color: var(--accent);
  text-decoration: none;
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 0.7rem 1.1rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  transition: border-color 0.15s;
}
.pager a:hover { border-color: var(--accent); }
.pager .spacer { flex: 1; }

@media (max-width: 640px) {
  .page-header h1 { font-size: 1.5rem; }
  input[type="range"] { width: 110px; }
}
