/* =========================================
   ASTERIZER - AI Lab ("How AI Works")
   Beginner-friendly animated explainers. Blends with the site's
   dark + platinum theme. All demos scoped under .ai-lab / .ai-*.
   Reduced-motion safe (see block at the very bottom).
   ========================================= */

.ai-lab {
  --ai-mono: 'JetBrains Mono', ui-monospace, 'SFMono-Regular', Menlo, monospace;
  --ai-line: rgba(199, 200, 193, 0.14);
  --ai-line-soft: rgba(199, 200, 193, 0.08);
  --ai-good: #6fe0a8;       /* match / success */
  --ai-good-glow: rgba(111, 224, 168, 0.35);
  --ai-warn: #f5cf6b;       /* candidate / heat */
  --ai-cool: #8fb7ff;       /* vectors / cool data */
  --ai-surface: rgba(255, 255, 255, 0.02);
  position: relative;
}

.ai-hero .page-title em,
.ai-lab em { font-style: normal; color: var(--accent-primary); }

/* === Section scaffolding === */
.ai-section { position: relative; overflow: hidden; }
.ai-section-alt { background: rgba(0, 0, 0, 0.14); }
/* tighter vertical rhythm so the page isn't a stack of huge boxes */
.ai-lab .section { padding: 44px 0; }

.ai-head {
  max-width: 720px;
  margin: 0 auto 20px;
  text-align: center;
}

.ai-kicker {
  display: inline-block;
  font-family: var(--ai-mono);
  font-size: 0.72rem;
  letter-spacing: 2.5px;
  text-transform: uppercase;
  color: var(--accent-primary);
  background: rgba(199, 200, 193, 0.08);
  border: 1px solid var(--ai-line);
  padding: 6px 14px;
  border-radius: 6px;
  margin-bottom: 18px;
}

.ai-title {
  font-family: var(--font-display);
  font-size: clamp(1.8rem, 3.6vw, 2.6rem);
  font-weight: 800;
  line-height: 1.15;
  margin-bottom: 14px;
}
.ai-title-sub {
  font-weight: 400;
  color: var(--text-muted);
  font-size: 0.62em;
}

.ai-lead {
  color: var(--text-secondary);
  font-size: 0.98rem;
  line-height: 1.6;
}
.ai-lead strong { color: var(--text-primary); }

/* === Demo shell === */
.ai-demo {
  max-width: 720px;
  margin: 0 auto;
}

.ai-stage,
.ai-rag, .ai-embed, .ai-next, .ai-temp, .ai-sampling, .ai-mcts {
  position: relative;
  background: 
    radial-gradient(120% 130% at 50% -20%, rgba(199, 200, 193, 0.06), transparent 60%),
    var(--bg-card);
  border: 1px solid rgba(199, 200, 193, 0.22);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: var(--shadow-md), inset 0 0 0 1px rgba(255, 255, 255, 0.02);
  overflow: hidden;
  transition: border-color 0.35s ease, box-shadow 0.35s ease;
}

/* Clear, graspable outline: each demo reads as its own module, and the
   outline brightens with a soft accent on hover. */
.ai-neural:hover,
.ai-stage:hover, .ai-rag:hover, .ai-embed:hover, .ai-next:hover,
.ai-temp:hover, .ai-sampling:hover, .ai-mcts:hover {
  border-color: rgba(199, 200, 193, 0.45);
  box-shadow: var(--shadow-lg), 0 0 34px rgba(199, 200, 193, 0.12);
}

/* corner accents - a light "frame" so the eye locks onto each concept */
.ai-stage::after, .ai-rag::after, .ai-embed::after, .ai-next::after,
.ai-temp::after, .ai-sampling::after, .ai-mcts::after {
  content: "";
  position: absolute;
  top: 12px; left: 12px; right: 12px; bottom: 12px;
  border-radius: calc(var(--radius-lg) - 8px);
  pointer-events: none;
  background: 
    linear-gradient(var(--accent-primary), var(--accent-primary)) top left / 18px 2px no-repeat,
    linear-gradient(var(--accent-primary), var(--accent-primary)) top left / 2px 18px no-repeat,
    linear-gradient(var(--accent-primary), var(--accent-primary)) top right / 18px 2px no-repeat,
    linear-gradient(var(--accent-primary), var(--accent-primary)) top right / 2px 18px no-repeat,
    linear-gradient(var(--accent-primary), var(--accent-primary)) bottom left / 18px 2px no-repeat,
    linear-gradient(var(--accent-primary), var(--accent-primary)) bottom left / 2px 18px no-repeat,
    linear-gradient(var(--accent-primary), var(--accent-primary)) bottom right / 18px 2px no-repeat,
    linear-gradient(var(--accent-primary), var(--accent-primary)) bottom right / 2px 18px no-repeat;
  opacity: 0.18;
  transition: opacity 0.35s ease;
}
.ai-stage:hover::after, .ai-rag:hover::after, .ai-embed:hover::after,
.ai-next:hover::after, .ai-temp:hover::after, .ai-sampling:hover::after,
.ai-mcts:hover::after {
  opacity: 0.5;
}

.ai-caption {
  margin-top: 18px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.95rem;
  line-height: 1.7;
}
.ai-caption i { color: var(--accent-primary); margin-right: 6px; }
.ai-caption strong { color: var(--text-secondary); }

/* mini number-vector cells shared helper */
.vcell {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 30px;
  height: 24px;
  padding: 0 4px;
  font-family: var(--ai-mono);
  font-size: 0.66rem;
  color: var(--ai-cool);
  background: rgba(143, 183, 255, 0.08);
  border: 1px solid rgba(143, 183, 255, 0.2);
  border-radius: 5px;
  opacity: 0;
  transform: translateY(6px) scale(0.9);
  transition: opacity 0.4s ease, transform 0.4s cubic-bezier(0.22, 1, 0.36, 1);
}
.vcell.on { opacity: 1; transform: translateY(0) scale(1); }

/* =========================================
   1) RAG
   ========================================= */
.rag-steps {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-bottom: 30px;
}
.rag-step {
  font-family: var(--ai-mono);
  font-size: 0.68rem;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 6px 14px;
  border: 1px solid var(--ai-line);
  border-radius: 20px;
  transition: all 0.4s ease;
}
.rag-step.active {
  color: var(--bg-dark);
  background: var(--accent-gradient);
  border-color: transparent;
  box-shadow: 0 0 18px var(--accent-glow);
}

.rag-flow {
  display: grid;
  grid-template-columns: 1fr auto 1.2fr auto 1fr;
  align-items: center;
  gap: 14px;
}

.rag-col { min-width: 0; }
.rag-col-label {
  display: flex;
  align-items: center;
  gap: 7px;
  font-family: var(--ai-mono);
  font-size: 0.66rem;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 14px;
}
.rag-col-label i { color: var(--accent-primary); }

.rag-question {
  background: rgba(199, 200, 193, 0.08);
  border: 1px solid var(--ai-line);
  border-radius: 12px;
  padding: 16px 18px;
  font-weight: 600;
  color: var(--text-primary);
  min-height: 58px;
  display: flex;
  align-items: center;
  transition: border-color 0.4s ease, box-shadow 0.4s ease;
}
.rag-question.pulse {
  border-color: var(--accent-primary);
  box-shadow: 0 0 22px var(--accent-glow);
}

.rag-vec {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 12px;
}

.rag-arrow {
  color: var(--text-muted);
  font-size: 1.1rem;
  text-align: center;
  opacity: 0.4;
  transition: color 0.4s ease, opacity 0.4s ease, transform 0.4s ease;
}
.rag-arrow.flow { color: var(--accent-primary); opacity: 1; transform: translateX(3px); }

.rag-doc {
  position: relative;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--ai-line);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 12px;
  transition: all 0.45s cubic-bezier(0.22, 1, 0.36, 1);
}
.rag-doc:last-child { margin-bottom: 0; }
.rag-doc-text { display: block; font-size: 0.92rem; color: var(--text-secondary); font-weight: 500; }
.rag-doc .rag-vec { margin-top: 10px; }

.rag-doc-sim {
  display: block;
  height: 5px;
  margin-top: 12px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 3px;
  overflow: hidden;
}
.rag-doc-bar { display: block; height: 100%; }
.rag-doc-bar i {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--ai-cool), var(--accent-primary));
  border-radius: 3px;
  transition: width 0.9s cubic-bezier(0.22, 1, 0.36, 1);
}
.rag-doc.win {
  border-color: var(--ai-good);
  background: rgba(111, 224, 168, 0.08);
  box-shadow: 0 0 26px var(--ai-good-glow);
  transform: translateY(-2px);
}
.rag-doc.win .rag-doc-bar i { background: linear-gradient(90deg, var(--ai-good), #b8ffe0); }
.rag-doc.dim { opacity: 0.4; filter: grayscale(0.3); }

.rag-llm {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--ai-mono);
  font-size: 0.8rem;
  color: var(--accent-primary);
  background: rgba(199, 200, 193, 0.08);
  border: 1px solid var(--ai-line);
  border-radius: 10px;
  padding: 10px 16px;
  transition: all 0.4s ease;
}
.rag-llm.active {
  border-color: var(--accent-primary);
  box-shadow: 0 0 22px var(--accent-glow);
}
.rag-llm.active i { animation: ai-spin 1.2s linear infinite; }

.rag-answer {
  margin-top: 14px;
  background: rgba(111, 224, 168, 0.06);
  border: 1px solid rgba(111, 224, 168, 0.25);
  border-radius: 12px;
  padding: 16px 18px;
  color: var(--text-primary);
  font-weight: 600;
  min-height: 58px;
  display: flex;
  align-items: center;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.5s ease, transform 0.5s cubic-bezier(0.22, 1, 0.36, 1);
}
.rag-answer.show { opacity: 1; transform: translateY(0); }

@keyframes ai-spin { to { transform: rotate(360deg); } }

/* =========================================
   2) EMBEDDINGS
   ========================================= */
.ai-embed { text-align: center; }
.embed-sentence {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin-bottom: 8px;
}
.embed-token {
  font-family: var(--ai-mono);
  font-size: 1rem;
  color: var(--text-secondary);
  background: rgba(199, 200, 193, 0.07);
  border: 1px solid var(--ai-line);
  border-radius: 8px;
  padding: 8px 14px;
  transition: all 0.4s ease;
}
.embed-token.active {
  color: var(--bg-dark);
  background: var(--accent-gradient);
  border-color: transparent;
  transform: translateY(-3px);
  box-shadow: 0 0 18px var(--accent-glow);
}
.embed-arrow {
  color: var(--text-muted);
  font-family: var(--ai-mono);
  font-size: 0.72rem;
  letter-spacing: 1px;
  text-transform: uppercase;
  margin: 18px 0;
}
.embed-arrow i { color: var(--accent-primary); margin-right: 4px; }
.embed-vectors {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  justify-content: center;
}
.embed-vcol {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
}
.embed-vcol .vcell { min-width: 44px; height: 26px; }
.embed-vcol-label {
  font-family: var(--ai-mono);
  font-size: 0.64rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* =========================================
   3) NEXT-TOKEN
   ========================================= */
.ai-next { }
.next-context {
  font-family: var(--ai-mono);
  font-size: 1.1rem;
  color: var(--text-primary);
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid var(--ai-line);
  border-radius: 12px;
  padding: 18px 20px;
  margin-bottom: 22px;
  line-height: 1.6;
  min-height: 60px;
}
.next-prompt .picked { color: var(--ai-good); }
.next-cursor {
  display: inline-block;
  width: 9px;
  height: 1.1em;
  background: var(--accent-primary);
  margin-left: 3px;
  vertical-align: text-bottom;
  animation: next-blink 1s steps(2) infinite;
}
@keyframes next-blink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }

.next-candidates { display: flex; flex-direction: column; gap: 10px; }
.next-cand {
  display: grid;
  grid-template-columns: 110px 1fr 52px;
  align-items: center;
  gap: 12px;
}
.next-cand-word {
  font-family: var(--ai-mono);
  font-size: 0.9rem;
  color: var(--text-secondary);
  text-align: right;
}
.next-cand-track {
  height: 14px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 7px;
  overflow: hidden;
}
.next-cand-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--ai-cool), var(--accent-primary));
  border-radius: 7px;
  transition: width 0.38s cubic-bezier(0.22, 1, 0.36, 1), background 0.28s ease;
}
.next-cand-pct {
  font-family: var(--ai-mono);
  font-size: 0.76rem;
  color: var(--text-muted);
}
.next-cand.win .next-cand-word { color: var(--ai-good); }
.next-cand.win .next-cand-fill { background: linear-gradient(90deg, var(--ai-good), #b8ffe0); }

/* =========================================
   4) TEMPERATURE (interactive)
   ========================================= */
.temp-control {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 26px;
}
.temp-control label {
  font-family: var(--ai-mono);
  font-size: 0.74rem;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-muted);
}
#temp-slider {
  flex: 1;
  min-width: 180px;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--ai-cool), var(--accent-primary), var(--ai-warn));
  outline: none;
  cursor: pointer;
}
#temp-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--accent-primary);
  box-shadow: 0 0 12px var(--accent-glow);
  cursor: pointer;
}
#temp-slider::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--accent-primary);
  cursor: pointer;
}
.temp-value {
  font-family: var(--ai-mono);
  font-size: 1rem;
  color: var(--accent-primary);
  min-width: 46px;
  text-align: center;
}
.temp-mode {
  font-family: var(--ai-mono);
  font-size: 0.7rem;
  letter-spacing: 1px;
  text-transform: uppercase;
  padding: 5px 12px;
  border-radius: 20px;
  border: 1px solid var(--ai-line);
  color: var(--text-secondary);
  transition: all 0.3s ease;
}

.temp-bars {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 16px;
  height: 156px;
  padding-top: 10px;
}
.temp-bar { display: flex; flex-direction: column; align-items: center; gap: 8px; height: 100%; justify-content: flex-end; flex: 1; max-width: 90px; }
.temp-bar-fill {
  width: 100%;
  border-radius: 8px 8px 0 0;
  background: linear-gradient(to top, var(--ai-cool), var(--accent-primary));
  transition: height 0.45s cubic-bezier(0.22, 1, 0.36, 1), background 0.45s ease;
  min-height: 2px;
}
.temp-bar-word { font-family: var(--ai-mono); font-size: 0.78rem; color: var(--text-secondary); }
.temp-bar-pct { font-family: var(--ai-mono); font-size: 0.68rem; color: var(--text-muted); }
.temp-scale {
  display: flex;
  justify-content: space-between;
  margin-top: 18px;
  font-family: var(--ai-mono);
  font-size: 0.68rem;
  color: var(--text-muted);
}
.temp-scale i { color: var(--accent-primary); }

/* =========================================
   5) SAMPLING
   ========================================= */
.samp-tabs { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin-bottom: 24px; }
.samp-tab {
  font-family: var(--ai-mono);
  font-size: 0.76rem;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--ai-line);
  padding: 9px 18px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
}
.samp-tab:hover { color: var(--text-secondary); border-color: rgba(199, 200, 193, 0.3); }
.samp-tab.active {
  color: var(--bg-dark);
  background: var(--accent-gradient);
  border-color: transparent;
  box-shadow: 0 0 18px var(--accent-glow);
}
.samp-bars { display: flex; flex-direction: column; gap: 9px; }
.samp-row {
  display: grid;
  grid-template-columns: 90px 1fr 46px;
  align-items: center;
  gap: 12px;
  transition: opacity 0.25s ease, transform 0.25s ease;
}
.samp-word { font-family: var(--ai-mono); font-size: 0.86rem; color: var(--text-secondary); text-align: right; }
.samp-track { height: 16px; background: rgba(255, 255, 255, 0.05); border-radius: 8px; overflow: hidden; }
.samp-fill {
  height: 100%;
  border-radius: 8px;
  background: rgba(143, 183, 255, 0.25);
  transition: width 0.6s ease, background 0.4s ease, opacity 0.4s ease;
}
.samp-pct { font-family: var(--ai-mono); font-size: 0.74rem; color: var(--text-muted); }
.samp-row.in .samp-fill { background: linear-gradient(90deg, var(--ai-cool), var(--accent-primary)); }
.samp-row.out { opacity: 0.32; }
.samp-row.chosen { transform: translateX(6px); }
.samp-row.chosen .samp-fill {
  background: linear-gradient(90deg, var(--ai-good), #b8ffe0);
  box-shadow: 0 0 18px rgba(111, 224, 168, 0.28);
}
.samp-row.chosen .samp-word { color: var(--ai-good); }
.samp-explain {
  margin-top: 20px;
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.95rem;
  min-height: 44px;
  line-height: 1.6;
}
.samp-explain b { color: var(--accent-primary); }

/* =========================================
   6) MCTS
   ========================================= */
.mcts-phases { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-bottom: 26px; }
.mcts-phase {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-family: var(--ai-mono);
  font-size: 0.7rem;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 6px 13px;
  border: 1px solid var(--ai-line);
  border-radius: 20px;
  transition: all 0.4s ease;
}
.mcts-phase b {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 17px; height: 17px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
  font-size: 0.64rem;
}
.mcts-phase.active {
  color: var(--bg-dark);
  background: var(--accent-gradient);
  border-color: transparent;
  box-shadow: 0 0 16px var(--accent-glow);
}
.mcts-phase.active b { background: rgba(0,0,0,0.2); color: var(--bg-dark); }
.mcts-phase { cursor: pointer; }
.mcts-phase:hover { color: var(--text-primary); border-color: rgba(199, 200, 193, 0.5); }
.ai-mcts.paused, .ai-next.paused { border-color: rgba(199, 200, 193, 0.5); box-shadow: var(--shadow-lg), 0 0 26px rgba(199, 200, 193, 0.14); }
.rag-step { cursor: pointer; }
.rag-step:hover { color: var(--text-primary); }
.next-cand { cursor: pointer; border-radius: 8px; transition: background 0.25s ease; }
.next-cand:hover { background: rgba(199, 200, 193, 0.06); }
.next-cand.dim { opacity: 0.4; }

.mcts-stage { position: relative; width: 100%; aspect-ratio: 2 / 1; max-width: 520px; margin: 0 auto; }
.mcts-edges { position: absolute; inset: 0; width: 100%; height: 100%; }
.mcts-edge { stroke: var(--ai-line); stroke-width: 2; fill: none; transition: stroke 0.4s ease, stroke-width 0.4s ease; }
.mcts-edge.path { stroke: var(--accent-primary); stroke-width: 3; }
.mcts-nodes { position: absolute; inset: 0; }
.mcts-node {
  position: absolute;
  width: 46px; height: 46px;
  margin: -23px 0 0 -23px;
  border-radius: 50%;
  background: var(--bg-card-hover);
  border: 2px solid var(--ai-line);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  font-family: var(--ai-mono);
  will-change: transform, opacity;
  transition:
    opacity 0.28s ease,
    transform 0.32s cubic-bezier(0.22, 1, 0.36, 1),
    border-color 0.24s ease,
    box-shadow 0.24s ease,
    background 0.24s ease;
  opacity: 0;
  transform: scale(0.4);
}
.mcts-node.show { opacity: 1; transform: scale(1); }
.mcts-node.path { border-color: var(--accent-primary); box-shadow: 0 0 18px var(--accent-glow); }
.mcts-node.pulse { animation: mcts-pulse 0.36s ease; }
@keyframes mcts-pulse {
  0% { box-shadow: 0 0 14px var(--accent-glow); }
  45% { box-shadow: 0 0 30px var(--accent-primary); }
  100% { box-shadow: 0 0 18px var(--accent-glow); }
}
.mcts-node.best { border-color: var(--ai-good); background: rgba(111, 224, 168, 0.12); box-shadow: 0 0 22px var(--ai-good-glow); }
.mcts-node.sim { border-color: var(--ai-warn); box-shadow: 0 0 18px rgba(245, 207, 107, 0.4); }
.mcts-node-val { font-size: 0.72rem; font-weight: 700; color: var(--text-primary); line-height: 1; }
.mcts-node-vis { font-size: 0.54rem; color: var(--text-muted); line-height: 1; margin-top: 2px; }
.mcts-node.best .mcts-node-val { color: var(--ai-good); }

.mcts-rollout {
  position: absolute;
  width: 14px; height: 14px;
  margin: -7px 0 0 -7px;
  border-radius: 50%;
  background: var(--ai-warn);
  box-shadow: 0 0 14px rgba(245, 207, 107, 0.7);
  opacity: 0;
  will-change: left, top, opacity;
  transition: opacity 0.18s ease, left 0.16s ease, top 0.16s ease;
}
.mcts-rollout.show { opacity: 1; }

/* live plain-English explainer of the current step */
.mcts-status {
  margin: 20px auto 0;
  max-width: 540px;
  text-align: center;
  font-size: 0.92rem;
  line-height: 1.55;
  color: var(--text-secondary);
  min-height: 2.6em;
}
.mcts-status b { color: var(--text-primary); }

/* legend explaining what the node numbers mean */
.mcts-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
  justify-content: center;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--ai-line);
  font-size: 0.78rem;
  color: var(--text-muted);
}
.mcts-legend span { display: inline-flex; align-items: center; gap: 7px; }
.mcts-legend b {
  font-family: var(--ai-mono);
  font-size: 0.74rem;
  color: var(--accent-primary);
  background: rgba(199, 200, 193, 0.08);
  border: 1px solid var(--ai-line);
  border-radius: 5px;
  padding: 2px 6px;
}
.mcts-key-best {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--ai-good);
  background: rgba(111, 224, 168, 0.12);
  box-shadow: 0 0 10px var(--ai-good-glow);
}

/* =========================================
   Responsive
   ========================================= */
@media (max-width: 760px) {
  .ai-stage, .ai-rag, .ai-embed, .ai-next, .ai-temp, .ai-sampling, .ai-mcts { padding: 22px; }
  .rag-flow { grid-template-columns: 1fr; gap: 18px; }
  .rag-arrow { transform: rotate(90deg); }
  .rag-arrow.flow { transform: rotate(90deg) translateX(3px); }
  .next-cand { grid-template-columns: 78px 1fr 44px; }
  .samp-row { grid-template-columns: 70px 1fr 42px; }
  .temp-bars { gap: 8px; height: 170px; }
}

/* =========================================
   Reduced motion - show meaningful end states, no looping
   ========================================= */
@media (prefers-reduced-motion: reduce) {
  .vcell { opacity: 1 !important; transform: none !important; }
  .rag-step, .rag-arrow, .rag-doc, .rag-llm, .rag-answer,
  .embed-token, .next-cand-fill, .temp-bar-fill, .samp-fill,
  .mcts-node, .mcts-edge, .mcts-rollout {
    transition: none !important;
    animation: none !important;
  }
  .rag-answer { opacity: 1 !important; transform: none !important; }
  .mcts-node { opacity: 1 !important; transform: scale(1) !important; }
  .next-cursor, .rag-llm.active i { animation: none !important; }
}

/* =========================================
   0) NEURAL-NETWORK HERO
   ========================================= */
.ai-neural-wrap { padding-top: 24px; }

.ai-neural {
  position: relative;
  background: 
    radial-gradient(130% 120% at 50% -10%, rgba(199, 200, 193, 0.09), transparent 55%),
    linear-gradient(180deg, var(--bg-card), var(--bg-tertiary));
  border: 1px solid rgba(199, 200, 193, 0.22);
  border-radius: var(--radius-xl);
  padding: 28px;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  transition: border-color 0.35s ease, box-shadow 0.35s ease;
}
.ai-neural::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image: 
    linear-gradient(rgba(199, 200, 193, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(199, 200, 193, 0.05) 1px, transparent 1px);
  background-size: 42px 42px;
  mask-image: radial-gradient(ellipse 80% 75% at 50% 42%, #000, transparent 82%);
  -webkit-mask-image: radial-gradient(ellipse 80% 75% at 50% 42%, #000, transparent 82%);
}

.nn-head {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  max-width: 720px;
  margin: 0 auto 18px;
  padding-inline: 8px;
  position: relative;
  z-index: 2;
}
.nn-badge {
  display: inline-flex; align-items: center; gap: 8px;
  font-family: var(--ai-mono); font-size: 0.68rem; letter-spacing: 2px; text-transform: uppercase;
  color: var(--accent-primary); border: 1px solid var(--ai-line);
  background: rgba(199, 200, 193, 0.06); padding: 6px 14px; border-radius: 20px; margin-bottom: 16px;
}
.nn-badge-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent-primary); box-shadow: 0 0 10px var(--accent-primary); animation: nn-blink 1.6s ease-in-out infinite; }
@keyframes nn-blink { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }
.nn-headline { font-family: var(--font-display); font-size: clamp(1.5rem, 3vw, 2.2rem); font-weight: 800; line-height: 1.2; margin-bottom: 10px; }
.nn-sub { color: var(--text-secondary); line-height: 1.7; max-width: 64ch; margin: 0 auto; }

.nn-stage { position: relative; z-index: 2; margin: 0px 0; }
.nn-canvas { width: 100%; max-width: 560px; height: auto; display: block; margin: 0 auto; overflow: visible; }

.nn-edge { stroke: rgba(199, 200, 193, 0.12); stroke-width: 1.2; fill: none; }
.nn-spark { stroke: var(--accent-primary); stroke-width: 3; fill: none; opacity: 0; stroke-linecap: round; filter: drop-shadow(0 0 6px var(--accent-primary)); }
.nn-node {
  fill: var(--bg-dark); stroke: rgba(199, 200, 193, 0.4); stroke-width: 1.5;
  transform-box: fill-box; transform-origin: center;
  transition: fill 0.3s ease, stroke 0.3s ease, filter 0.3s ease;
}
/* a neuron "fires": bright core, white rim, a glow pulse + tiny scale kick */
.nn-node.fire {
  fill: var(--accent-primary); stroke: #ffffff;
  filter: drop-shadow(0 0 10px var(--accent-glow));
  animation: nn-fire 0.62s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes nn-fire {
  0%   { filter: drop-shadow(0 0 2px var(--accent-glow));  transform: scale(0.82); }
  45%  { filter: drop-shadow(0 0 18px var(--accent-primary)); transform: scale(1.35); }
  100% { filter: drop-shadow(0 0 10px var(--accent-glow)); transform: scale(1); }
}
.nn-node.out { stroke: var(--ai-good); stroke-width: 2; }
.nn-node.out.fire {
  fill: var(--ai-good); stroke: #ffffff;
  filter: drop-shadow(0 0 18px var(--ai-good-glow));
  animation: nn-fire-out 0.7s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes nn-fire-out {
  0%   { filter: drop-shadow(0 0 4px var(--ai-good-glow));  transform: scale(0.85); }
  45%  { filter: drop-shadow(0 0 28px var(--ai-good)); transform: scale(1.28); }
  100% { filter: drop-shadow(0 0 18px var(--ai-good-glow)); transform: scale(1); }
}

.nn-chip {
  position: absolute; z-index: 3; max-width: 215px;
  background: rgba(10, 12, 16, 0.72); backdrop-filter: blur(7px); -webkit-backdrop-filter: blur(7px);
  border: 1px solid var(--ai-line); border-radius: 12px; padding: 12px 14px;
  box-shadow: var(--shadow-md);
}
.nn-chip-label { display: block; font-family: var(--ai-mono); font-size: 0.6rem; letter-spacing: 1.5px; text-transform: uppercase; color: var(--text-muted); margin-bottom: 5px; }
.nn-chip-label i { color: var(--accent-primary); margin-right: 4px; }
.nn-chip-text { font-size: 0.92rem; color: var(--text-primary); font-weight: 600; min-height: 1.2em; line-height: 1.4; }
.nn-chip-in { left: 0; top: 6px; }
.nn-chip-out { right: 0; bottom: 6px; border-color: rgba(111, 224, 168, 0.32); }
.nn-chip-out .nn-chip-label i { color: var(--ai-good); }
.nn-chip-out .nn-chip-text { color: #d6ffe9; }

.nn-phases { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 18px; position: relative; z-index: 2; }
.nn-phase { font-family: var(--ai-mono); font-size: 0.66rem; letter-spacing: 1px; text-transform: uppercase; color: var(--text-muted); padding: 5px 12px; border: 1px solid var(--ai-line); border-radius: 20px; cursor: pointer; transition: all 0.3s ease; }
.nn-phase:hover { color: var(--text-primary); border-color: rgba(199, 200, 193, 0.5); }
.nn-phase.active { color: var(--bg-dark); background: var(--accent-gradient); border-color: transparent; box-shadow: 0 0 14px var(--accent-glow); }
.ai-neural.paused { border-color: rgba(199, 200, 193, 0.5); box-shadow: var(--shadow-lg), 0 0 26px rgba(199, 200, 193, 0.14); }
.ai-neural::after { transition: opacity 0.35s ease; }
.ai-neural .nn-head::before {
  content: "Hover to pause \00b7 click a stage to freeze it";
  display: inline-block; font-family: var(--ai-mono); font-size: 0.6rem;
  letter-spacing: 1px; text-transform: uppercase;
  color: var(--text-muted); opacity: 0.7; margin-bottom: 8px;
}

@media (max-width: 820px) {
  .ai-neural { padding: 26px 18px; }
  .nn-head { padding-inline: 0; }
  .nn-stage { display: flex; flex-direction: column; gap: 12px; }
  .nn-chip { position: relative; left: auto; right: auto; top: auto; bottom: auto; max-width: none; }
  .nn-chip-out { order: 2; }
}

/* ===== Spontaneous ambient neuron firing (brain-like) ===== */
.nn-node.spark { animation: nn-spark 0.7s ease; }
@keyframes nn-spark {
  0%   { fill: var(--bg-dark); }
  40%  { fill: var(--accent-primary); filter: drop-shadow(0 0 9px var(--accent-glow)); }
  100% { fill: var(--bg-dark); filter: none; }
}

/* ===== RAG interactivity: hover-pause, click-to-test, cosine math ===== */
.ai-rag .rag-doc, .ai-rag .vcell { cursor: pointer; }
.ai-rag.paused { border-color: rgba(199, 200, 193, 0.45); box-shadow: var(--shadow-lg), 0 0 24px rgba(199, 200, 193, 0.12); }
.rag-doc { transition: border-color 0.3s ease, background 0.3s ease, box-shadow 0.3s ease, transform 0.3s ease; }
.rag-doc.wrong {
  border-color: #ff6b6b !important;
  background: rgba(255, 107, 107, 0.08);
  box-shadow: 0 0 18px rgba(255, 107, 107, 0.28);
}
.rag-doc.wrong .rag-doc-bar i { background: linear-gradient(90deg, #ff6b6b, #ffb3b3) !important; }
.rag-answer.correct { color: var(--ai-good); border-color: rgba(111, 224, 168, 0.42); }
.rag-answer.wrong { color: #ff8585; border-color: rgba(255, 107, 107, 0.42); }
.rag-interact { margin-top: 14px; }
.rag-hint {
  text-align: center; font-family: var(--ai-mono); font-size: 0.72rem; letter-spacing: 0.4px;
  color: var(--text-muted); line-height: 1.6; min-height: 1.2em;
}
.rag-hint i { color: var(--accent-primary); margin-right: 6px; }
.rag-math {
  margin-top: 12px; padding: 14px 16px;
  background: rgba(10, 12, 16, 0.6); border: 1px solid var(--ai-line); border-radius: 12px;
  font-family: var(--ai-mono); font-size: 0.78rem; line-height: 1.65; color: var(--text-secondary);
}
.rag-math-formula { color: var(--accent-primary); font-size: 0.86rem; margin-bottom: 8px; }
.rag-math-q { color: var(--text-muted); margin-bottom: 8px; }
.rag-math-row { padding: 3px 0; }
.rag-math-win { color: var(--ai-good); font-weight: 700; }
.rag-math-lose { color: var(--text-muted); }
.rag-math-note { margin-top: 8px; color: var(--text-muted); font-size: 0.72rem; }

/* ===== AI jargon glossary ===== */
.ai-glossary {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px;
}
.gl-card {
  padding: 14px 16px; background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--ai-line); border-radius: 12px;
  transition: border-color 0.3s ease, transform 0.3s ease;
}
.gl-card:hover { border-color: rgba(199, 200, 193, 0.4); transform: translateY(-3px); }
.gl-term { display: flex; align-items: center; gap: 8px; font-family: var(--font-display); font-weight: 700; color: var(--text-primary); font-size: 0.92rem; margin-bottom: 6px; }
.gl-term i { color: var(--accent-primary); }
.gl-def { display: block; font-size: 0.84rem; color: var(--text-muted); line-height: 1.55; }
.ai-demo-wide { max-width: 880px; }

@media (prefers-reduced-motion: reduce) {
  .nn-badge-dot { animation: none !important; }
  .nn-node { transition: none !important; }
  .nn-spark { display: none !important; }
}

/* Force-motion escape hatch for the AI Lab only.
   The reference notes in `animation flow/` call out reduced-motion as the main
   reason the page can render fully but stay static. When the site config opts
   into motion, restore the original AI Lab motion primitives even if the OS
   reports reduced motion. */
html.force-ai-lab-motion .ai-lab .vcell {
  opacity: 0 !important;
  transform: translateY(6px) scale(0.9) !important;
  transition: opacity 0.4s ease, transform 0.4s cubic-bezier(0.22, 1, 0.36, 1) !important;
}
html.force-ai-lab-motion .ai-lab .vcell.on {
  opacity: 1 !important;
  transform: translateY(0) scale(1) !important;
}
html.force-ai-lab-motion .ai-lab .rag-step,
html.force-ai-lab-motion .ai-lab .rag-arrow,
html.force-ai-lab-motion .ai-lab .rag-doc,
html.force-ai-lab-motion .ai-lab .rag-llm,
html.force-ai-lab-motion .ai-lab .embed-token,
html.force-ai-lab-motion .ai-lab .next-cand-fill,
html.force-ai-lab-motion .ai-lab .temp-bar-fill,
html.force-ai-lab-motion .ai-lab .samp-fill,
html.force-ai-lab-motion .ai-lab .mcts-edge,
html.force-ai-lab-motion .ai-lab .mcts-rollout {
  transition: revert !important;
  animation: revert !important;
}
html.force-ai-lab-motion .ai-lab .rag-answer {
  opacity: 0 !important;
  transform: translateY(10px) !important;
  transition: opacity 0.5s ease, transform 0.5s cubic-bezier(0.22, 1, 0.36, 1) !important;
}
html.force-ai-lab-motion .ai-lab .rag-answer.show {
  opacity: 1 !important;
  transform: translateY(0) !important;
}
html.force-ai-lab-motion .ai-lab .mcts-node {
  opacity: 0 !important;
  transform: scale(0.4) !important;
  transition:
    opacity 0.28s ease,
    transform 0.32s cubic-bezier(0.22, 1, 0.36, 1),
    border-color 0.24s ease,
    box-shadow 0.24s ease,
    background 0.24s ease !important;
}
html.force-ai-lab-motion .ai-lab .mcts-node.show {
  opacity: 1 !important;
  transform: scale(1) !important;
}
html.force-ai-lab-motion .ai-lab .next-cursor,
html.force-ai-lab-motion .ai-lab .rag-llm.active i,
html.force-ai-lab-motion .ai-neural .nn-badge-dot {
  animation: revert !important;
}
html.force-ai-lab-motion .ai-neural .nn-node {
  transition: fill 0.3s ease, stroke 0.3s ease, filter 0.3s ease !important;
}
html.force-ai-lab-motion .ai-neural .nn-spark {
  display: revert !important;
}
