/* Neural Networks From First Principles — Styles */
.nn-hero {
  background: linear-gradient(135deg, #0c263d 0%, #154268 100%);
  color: #f0f7fd;
  color-scheme: dark;
  padding: 2.8rem max(4vw, 1.5rem);
  border-radius: 8px;
  margin-bottom: 2.2rem;
  box-shadow: 0 4px 20px rgba(12, 38, 61, 0.14);
}

.nn-hero h1 {
  color: #ffffff;
  font-size: clamp(2rem, 5vw, 3.6rem);
  max-width: 26ch;
  margin-bottom: 0.8rem;
}

.nn-hero .lead {
  color: #e0f2fe;
  font-size: 1.2rem;
  max-width: 68ch;
  margin-bottom: 1.6rem;
}

.nn-hero button.secondary {
  background: rgba(15, 23, 42, 0.78);
  color: #f8fafc;
  border: 1px solid #93c5fd;
}

.nn-hero button.secondary:hover {
  background: #1e3a5f;
  color: #ffffff;
}

.kernel-bar {
  background: rgba(12, 30, 50, 0.55);
  border: 1px solid rgba(186, 230, 253, 0.32);
  border-radius: 6px;
  padding: 1rem 1.2rem;
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
  justify-content: space-between;
}

.kernel-bar-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
}

.kernel-pill {
  background: #054a80;
  color: #ffffff;
  border: 1px solid #7dd3fc;
  font-size: 0.85rem;
  padding: 0.45rem 0.9rem;
  border-radius: 20px;
}

.kernel-pill[aria-pressed="true"] {
  background: #bae6fd;
  color: #082032;
  border-color: #ffffff;
  font-weight: 800;
}

.kernel-readout {
  font-family: ui-monospace, monospace;
  font-size: 0.88rem;
  color: #f0f9ff;
}

.era-timeline {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.9rem;
  margin: 1.5rem 0 2.5rem;
}

.era-card {
  background: var(--card, #151d2f);
  border: 1px solid var(--line, #64748b);
  border-top: 4px solid var(--accent, #38bdf8);
  border-radius: 6px;
  padding: 0.95rem 1.05rem;
  text-decoration: none;
  color: var(--ink, #f8fafc);
  display: flex;
  flex-direction: column;
  gap: 0.28rem;
}

.era-card:hover {
  background: #1e293b;
}

.era-year {
  font-size: 0.78rem;
  font-weight: 800;
  color: var(--accent, #38bdf8);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.era-title {
  font-weight: 750;
  font-size: 1rem;
  color: var(--ink, #f8fafc);
}

.era-sub {
  font-size: 0.82rem;
  color: var(--muted, #94a3b8);
}

.nn-section {
  background: var(--card, #151d2f);
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 8px;
  padding: 2rem;
  margin-bottom: 2.5rem;
  color: var(--ink, #f8fafc);
}

.nn-section h2, .nn-section h3, .nn-section h4 {
  color: var(--ink, #f8fafc);
}

.study-prose p, .study-prose li {
  color: #e2e8f0;
}

.study-prose code, p code, li code {
  background: #0b0f19;
  color: #38bdf8;
  border: 1px solid #334155;
  padding: 0.15rem 0.35rem;
  border-radius: 4px;
}

.nn-section h2 {
  margin-top: 0;
}

.nn-section button.secondary {
  background: rgba(15, 23, 42, 0.8);
  color: #f8fafc;
  border: 1px solid #38bdf8;
}

.nn-section button.secondary:hover {
  background: #0c4a6e;
  color: #ffffff;
}

.nn-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr);
  gap: 2rem;
  align-items: start;
  margin-top: 1.2rem;
}

.nn-panel {
  background: #111827;
  border: 1px solid var(--line, #64748b);
  border-radius: 6px;
  padding: 1.25rem;
  color: var(--ink, #f8fafc);
}

.nn-panel h3 {
  color: var(--ink, #f8fafc);
}

.nn-panel label {
  color: var(--muted, #94a3b8);
}

.nn-panel h3 {
  margin-top: 0;
}

.canvas-frame {
  background: #0f2338;
  color: #f0f9ff;
  color-scheme: dark;
  border: 1px solid #1e3a5f;
  border-radius: 6px;
  padding: 0.9rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.65rem;
}

.canvas-frame p,
.canvas-frame .small,
.canvas-frame .muted {
  color: #e0f2fe;
}

.decision-canvas {
  width: 100%;
  max-width: 380px;
  aspect-ratio: 1;
  border-radius: 4px;
  cursor: crosshair;
  background: #102a43;
  border: 1px solid #334e68;
}

.metrics-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0.75rem;
  margin: 1rem 0;
}

.metric-box {
  background: #0b0f19;
  border: 1px solid var(--line, #64748b);
  border-radius: 5px;
  padding: 0.65rem 0.8rem;
}

.metric-label {
  color: var(--muted, #94a3b8);
}

.metric-val {
  color: var(--ink, #f8fafc);
}

.metric-label {
  font-size: 0.76rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.metric-val {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.grad-bars {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.8rem;
}

.grad-row {
  display: grid;
  grid-template-columns: minmax(145px, 1.15fr) minmax(90px, 1.5fr) minmax(130px, auto);
  gap: 0.65rem;
  align-items: center;
  font-size: 0.84rem;
}

.grad-row > span:first-child {
  font-weight: 600;
  color: var(--ink);
}

.grad-row .number {
  text-align: right;
  white-space: nowrap;
  font-family: ui-monospace, monospace;
  font-size: 0.8rem;
  color: var(--ink);
}

/* CNN Pixel Draw Grid & Feature Maps */
.pixel-grid-8 {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 3px;
  max-width: 240px;
  margin: 0.8rem 0;
  background: #9fb3c8;
  padding: 4px;
  border-radius: 6px;
}

.pixel-btn {
  aspect-ratio: 1;
  min-height: 26px;
  padding: 0;
  border: 1px solid #334155;
  border-radius: 2px;
  background: #0b0f19;
  color: transparent;
}

.pixel-btn.lit {
  background: #38bdf8;
  border-color: #0284c7;
}

.feature-maps-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0.85rem;
  margin-top: 0.8rem;
}

.fmap-card {
  background: #111827;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.65rem;
  text-align: center;
  color: var(--ink);
}

.mini-grid-3,
.mini-grid-6 {
  display: grid;
  gap: 2px;
  margin: 0.4rem auto;
}

.mini-grid-3 {
  grid-template-columns: repeat(3, 1fr);
  width: 54px;
}

.mini-grid-6 {
  grid-template-columns: repeat(6, 1fr);
  width: 96px;
}

.mini-cell {
  aspect-ratio: 1;
  border-radius: 1px;
  background: #1e293b;
  color: #f8fafc;
  font-size: 0.62rem;
  display: grid;
  place-items: center;
}

.heat-0 { background: #1e293b; color: #94a3b8; }
.heat-1 { background: #0369a1; color: #f8fafc; }
.heat-2 { background: #0284c7; color: #f8fafc; }
.heat-3 { background: #38bdf8; color: #0b0f19; }
.heat-4 { background: #bae6fd; color: #0b0f19; }
.heat-neg { background: #881337; color: #fecdd3; }

/* Transformer Attention Matrix */
.attn-heads-wrap {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 1rem;
  margin-top: 0.8rem;
}

.attn-table {
  width: 100%;
  border-collapse: collapse;
  font-family: ui-monospace, monospace;
  font-size: 0.82rem;
}

.attn-table th,
.attn-table td {
  padding: 0.4rem;
  text-align: center;
  border: 1px solid var(--line);
}

/* Diffusion Grids & Tokens */
.diffusion-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(105px, 1fr));
  gap: 0.75rem;
  margin-top: 0.8rem;
}

.sprite-card {
  background: #111827;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.6rem;
  text-align: center;
  color: var(--ink);
}

.text-diff-steps {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  margin-top: 0.8rem;
}

.text-step-row {
  background: #111827;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.65rem 0.85rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  color: var(--ink);
}

.tok-chip {
  font-family: ui-monospace, monospace;
  font-size: 0.85rem;
  font-weight: 700;
  padding: 0.25rem 0.55rem;
  border-radius: 4px;
  background: #064e3b;
  color: #a7f3d0;
  border: 1px solid #059669;
}

.tok-chip.masked {
  background: #881337;
  color: #fecdd3;
  border-color: #be123c;
}

/* Block Builder Stack */
.builder-palette {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.block-stack {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.block-item {
  background: #111827;
  border: 1px solid var(--line);
  border-left: 5px solid var(--accent);
  border-radius: 6px;
  padding: 0.75rem 1rem;
  display: grid;
  grid-template-columns: minmax(170px, 1.4fr) repeat(4, minmax(75px, 1fr)) auto;
  gap: 0.6rem;
  align-items: center;
  font-size: 0.88rem;
  color: var(--ink);
}

.equation-box {
  background: #0b0f19;
  border: 1px solid #334155;
  border-left: 4px solid var(--accent, #38bdf8);
  color: var(--ink, #f8fafc);
  padding: 0.75rem 1rem;
  font-family: ui-monospace, monospace;
  font-size: 0.88rem;
  margin: 0.8rem 0;
  border-radius: 0 4px 4px 0;
}

/* Interactive Network Node Graph & Step-by-Step Debugger */
.nn-stepper-workbench {
  margin-top: 2rem;
  background: var(--wash);
  border: 1px solid var(--line);
  border-top: 4px solid var(--accent);
  border-radius: 8px;
  padding: 1.5rem;
}

.stepper-header {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: flex-start;
  justify-content: space-between;
}

.stepper-header > div:first-child {
  flex: 1 1 480px;
}

.stepper-header h3 {
  margin-top: 0;
  margin-bottom: 0.35rem;
}

.stepper-size-control {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 245px;
}

.stepper-size-control label {
  margin: 0;
  color: var(--ink);
}

.stepper-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: flex-end;
  justify-content: space-between;
  margin: 1rem 0;
}

.stepper-fields {
  flex: 1 1 240px;
  min-width: 0;
  margin: 0;
}

.stepper-actions {
  margin: 0;
}

.stepper-tape {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin: 0.9rem 0;
}

.stepper-pill {
  font-size: 0.8rem;
  font-family: ui-monospace, monospace;
  padding: 0.4rem 0.78rem;
  border-radius: 999px;
  background: #0b0f19;
  color: var(--ink, #f8fafc);
  border: 1px solid var(--line, #64748b);
}

.stepper-pill.done {
  background: #e0f2fe;
  border-color: #7dd3fc;
  color: #0c4a6e;
  font-weight: 600;
}

.stepper-pill.active {
  background: #0369a1;
  border-color: #075985;
  color: #ffffff;
  font-weight: 800;
  box-shadow: 0 0 0 2px rgba(3, 105, 161, 0.25);
}

.stepper-pill.phase-backward.active {
  background: #be123c;
  border-color: #9f1239;
}

.stepper-pill.phase-loss.active {
  background: #b45309;
  border-color: #92400e;
}

.stepper-pill.phase-update.active {
  background: #047857;
  border-color: #065f46;
}

.stepper-stage-banner {
  background: #0b0f19;
  border: 1px solid var(--line, #64748b);
  border-left: 4px solid var(--accent, #38bdf8);
  border-radius: 6px;
  padding: 0.9rem 1.05rem;
  margin-bottom: 1.15rem;
  color: var(--ink, #f8fafc);
}

.stepper-stage-top {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
  margin-bottom: 0.45rem;
}

.stepper-phase-badge {
  font-family: ui-monospace, monospace;
  font-size: 0.74rem;
  font-weight: 800;
  padding: 0.22rem 0.6rem;
  border-radius: 4px;
  background: #0369a1;
  color: #ffffff;
  letter-spacing: 0.05em;
}

.stepper-phase-badge.phase-backward {
  background: #be123c;
}

.stepper-phase-badge.phase-loss {
  background: #b45309;
}

.stepper-phase-badge.phase-update {
  background: #047857;
}

.stepper-pass-counter {
  margin-left: auto;
  font-family: ui-monospace, monospace;
  font-size: 0.82rem;
  color: var(--ink);
  font-weight: 600;
}

.stepper-stage-formula {
  font-family: ui-monospace, monospace;
  font-size: 0.88rem;
  background: #0b0f19;
  color: #38bdf8;
  border: 1px solid #334155;
  padding: 0.5rem 0.7rem;
  border-radius: 4px;
  margin-bottom: 0.38rem;
  overflow-x: auto;
}

.stepper-stage-summary {
  font-size: 0.9rem;
  color: var(--ink);
}

.stepper-body-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.25rem;
  align-items: start;
}

.stepper-graph-card,
.stepper-inspector-card {
  background: #111827;
  border: 1px solid var(--line, #64748b);
  border-radius: 6px;
  padding: 1.05rem;
  min-width: 0;
  color: var(--ink, #f8fafc);
}

.stepper-inspector-card h4 {
  margin-top: 0;
  margin-bottom: 0.65rem;
}

.stepper-svg-container {
  width: 100%;
  overflow-x: auto;
  border-radius: 8px;
  background: #0b192c;
  color: #f0f9ff;
  color-scheme: dark;
  border: 1px solid #1e3a5f;
  padding: 0.35rem;
}

.nn-stepper-svg {
  display: block;
  width: 100%;
  height: auto;
}

.stepper-svg-container.scale-large .nn-stepper-svg {
  min-height: 490px;
}

.stepper-svg-container.scale-theatre .nn-stepper-svg {
  min-height: 650px;
}

.stepper-svg-container.scale-compact .nn-stepper-svg {
  min-height: 360px;
}

.svg-node {
  cursor: pointer;
}

.stepper-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.85rem;
  margin-top: 0.75rem;
  font-size: 0.82rem;
  color: var(--ink);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.38rem;
}

.legend-swatch {
  display: inline-block;
  width: 13px;
  height: 13px;
  border-radius: 3px;
}

.swatch-pos { background: #38bdf8; }
.swatch-neg { background: #fb7185; }
.swatch-fwd { background: #0369a1; border: 1px dashed #ffffff; }
.swatch-bwd { background: #d97706; border: 1px dashed #ffffff; }
.swatch-upd { background: #059669; }

.stepper-node-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.85rem;
}

.node-select-pill {
  font-family: ui-monospace, monospace;
  font-size: 0.78rem;
  padding: 0.3rem 0.62rem;
  border-radius: 4px;
  background: #1e293b;
  color: #f8fafc;
  border: 1px solid #475569;
  cursor: pointer;
}

.node-select-pill.active {
  background: #0f172a;
  color: #facc15;
  border-color: #facc15;
  font-weight: 800;
  box-shadow: 0 0 8px rgba(250, 204, 21, 0.3);
}

.inspector-node-header {
  font-size: 0.92rem;
  margin-bottom: 0.75rem;
  padding-bottom: 0.45rem;
  border-bottom: 1px solid var(--line);
}

.inspector-detail-split {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(0, 1.35fr);
  gap: 1.25rem;
  align-items: start;
}

.inspector-kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(135px, 1fr));
  gap: 0.5rem;
  margin-bottom: 0;
}

.inspector-kpi {
  background: var(--wash);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0.45rem 0.6rem;
  display: flex;
  flex-direction: column;
}

.inspector-kpi-label {
  font-size: 0.72rem;
  color: var(--muted);
}

.inspector-kpi-val {
  font-family: ui-monospace, monospace;
  font-size: 0.86rem;
  font-weight: 700;
  color: var(--ink);
}

.synapse-table {
  font-size: 0.8rem;
}

/* ============================================================================
   Study Prose, Kernel Code Explorer & Hyperparameter Encyclopedia
   ============================================================================ */

.study-prose {
  margin-bottom: 1.15rem;
  line-height: 1.68;
}

.study-prose p {
  margin: 0 0 0.85rem;
  max-width: 92ch;
}

.study-prose ul {
  margin: 0.5rem 0 0.9rem 1.25rem;
  padding: 0;
}

.study-prose li {
  margin-bottom: 0.55rem;
  max-width: 90ch;
}

.kernel-code-explorer {
  margin-top: 1.15rem;
  background: #0b0f19;
  color: var(--ink, #f8fafc);
  color-scheme: dark;
  border: 1px solid var(--line, #64748b);
  border-radius: 6px;
  padding: 1rem 1.15rem;
  min-width: 0;
  box-shadow: 0 2px 8px rgba(12, 38, 61, 0.08);
}

.kernel-code-explorer label {
  color: var(--ink);
}

.kernel-code-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.85rem;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 0.65rem;
}

.kernel-code-toolbar > div:first-child {
  flex: 1 1 280px;
  min-width: 0;
}

.code-lang-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.code-lang-btn {
  font-size: 0.78rem;
  padding: 0.38rem 0.75rem;
  border-radius: 4px;
  background: #1e293b;
  color: #f8fafc;
  border: 1px solid #475569;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.code-lang-btn:hover {
  background: #334155;
  color: #ffffff;
  border-color: #64748b;
}

.code-lang-btn.active {
  background: #0284c7;
  color: #ffffff;
  border-color: #38bdf8;
  font-weight: 700;
  box-shadow: 0 0 10px rgba(56, 189, 248, 0.25);
}

.kernel-code-summary {
  margin: 0.35rem 0 0.65rem;
  color: var(--muted);
}

.kernel-code-pre {
  margin: 0;
  padding: 0.85rem 1rem;
  background: #0f172a;
  color: #f1f5f9;
  border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.79rem;
  line-height: 1.5;
  overflow-x: auto;
  max-height: 340px;
  overflow-y: auto;
}

.hyperparam-explainer {
  margin-top: 1.15rem;
  border-top: 1px solid var(--line);
  padding-top: 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.hyperparam-explainer h4 {
  margin: 0 0 0.25rem;
}

.hyperparam-card {
  background: #0b0f19;
  border: 1px solid var(--line, #64748b);
  border-radius: 5px;
  padding: 0.65rem 0.8rem;
  color: var(--ink, #f8fafc);
}

.hyperparam-card h4 {
  color: #38bdf8;
}

.hyperparam-card p {
  color: #cbd5e1;
}

.hyperparam-card-top {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: center;
  margin-bottom: 0.3rem;
  font-size: 0.84rem;
}

.hyperparam-badge {
  font-family: ui-monospace, monospace;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  background: #e0f2fe;
  color: #0c4a6e;
  padding: 0.14rem 0.48rem;
  border-radius: 3px;
}

.hyperparam-eq {
  display: block;
  font-size: 0.75rem;
  background: #0b0f19;
  color: #38bdf8;
  border: 1px solid #334155;
  border-radius: 3px;
  padding: 0.28rem 0.5rem;
  margin-bottom: 0.35rem;
  overflow-x: auto;
}

.hyperparam-card p.small {
  margin: 0;
  line-height: 1.48;
  color: var(--ink);
}

.section-code-widget {
  margin-top: 1.35rem;
}

.chapter-code-box {
  background: var(--card, #151d2f);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 1rem 1.25rem;
}

.chapter-code-box h4 {
  margin: 0 0 0.65rem;
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--ink, #f8fafc);
}

.chapter-code-body {
  margin-top: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

@media (max-width: 1020px) {
  .era-timeline {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 860px) {
  .nn-section {
    padding: 1.1rem;
  }
  .nn-panel,
  .nn-stepper-workbench {
    padding: 0.9rem;
    min-width: 0;
  }
  .nn-grid,
  .stepper-body-grid,
  .inspector-detail-split {
    grid-template-columns: 1fr;
  }
  .nn-grid > *,
  .stepper-body-grid > *,
  .inspector-detail-split > * {
    min-width: 0;
  }
  .stepper-header > div:first-child,
  .stepper-size-control {
    flex: 1 1 100%;
    min-width: 0;
  }
  .stepper-svg-container.scale-large .nn-stepper-svg,
  .stepper-svg-container.scale-theatre .nn-stepper-svg,
  .stepper-svg-container.scale-compact .nn-stepper-svg {
    min-height: 0;
  }
  .synapse-table {
    display: block;
    overflow-x: auto;
    max-width: 100%;
  }
  .block-item {
    grid-template-columns: 1fr 1fr;
  }
  .grad-row {
    grid-template-columns: minmax(85px, 1.1fr) minmax(50px, 1fr) auto;
    gap: 0.4rem;
    font-size: 0.72rem;
  }
  .grad-row .number {
    font-size: 0.72rem;
  }
}

@media (max-width: 600px) {
  .era-timeline {
    grid-template-columns: 1fr;
  }
}


