/* ═══════════════════════════════════════════════════════════
   style.css — Chapter 02: Feedback Loops
   nishtobehonest design tokens + chapter-specific components
═══════════════════════════════════════════════════════════ */

/* ── Tokens ── */
:root {
  --bg:      #0A0A0F;
  --surface: #12121A;
  --border:  #1E1E2E;
  --text:    #E2E8F0;
  --muted:   #64748B;
  --blue:    #4F8EF7;
  --teal:    #2DD4BF;
  --amber:   #F59E0B;
  --green:   #22C55E;
  --red:     #EF4444;

  --blue-dim:  rgba(79, 142, 247, 0.10);
  --teal-dim:  rgba(45, 212, 191, 0.10);
  --amber-dim: rgba(245, 158, 11, 0.10);
  --green-dim: rgba(34, 197, 94, 0.10);
  --red-dim:   rgba(239, 68, 68, 0.10);

  --radius: 8px;
  --font-display: 'Bricolage Grotesque', system-ui, sans-serif;
  --font-mono:    'JetBrains Mono', monospace;
  --font-body:    'Inter', system-ui, sans-serif;
  --max-w: 860px;
}

[data-theme="light"] {
  --bg:      #F8FAFC;
  --surface: #FFFFFF;
  --border:  #E2E8F0;
  --text:    #0F172A;
  --muted:   #64748B;
  --blue:    #2563EB;
  --teal:    #0D9488;
  --amber:   #D97706;
  --green:   #16A34A;
  --red:     #DC2626;
  --blue-dim:  rgba(37, 99, 235, 0.08);
  --teal-dim:  rgba(13, 148, 136, 0.08);
  --amber-dim: rgba(217, 119, 6, 0.08);
  --green-dim: rgba(22, 163, 74, 0.08);
  --red-dim:   rgba(220, 38, 38, 0.08);
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  transition: background 0.2s ease, color 0.2s ease;
  min-height: 100vh;
}

a { color: inherit; text-decoration: none; }

.container {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 0 24px;
}

/* ── Theme toggle ── */
.theme-toggle {
  position: fixed;
  top: 16px;
  right: 20px;
  z-index: 200;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.2s ease;
}
.theme-toggle:hover { color: var(--text); border-color: var(--muted); }

/* ── Top nav ── */
.top-nav { border-bottom: 1px solid var(--border); }
.top-nav-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.05em;
}
.top-nav a { color: var(--muted); text-decoration: none; transition: color 0.15s ease; }
.top-nav a:hover { color: var(--text); }

/* ── Header ── */
.site-header {
  padding: 56px 0 40px;
  border-bottom: 1px solid var(--border);
}

.back-link {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 20px;
  transition: color 0.15s ease;
}
.back-link:hover { color: var(--blue); }

.site-title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(28px, 5vw, 44px);
  letter-spacing: -0.02em;
  line-height: 1.1;
  color: var(--text);
  margin-bottom: 12px;
}

.site-attribution {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.04em;
}

/* ── Intro ── */
.intro-section {
  padding: 40px 0 32px;
  border-bottom: 1px solid var(--border);
}

.intro-text {
  font-size: 16px;
  line-height: 1.7;
  color: var(--text);
  max-width: 680px;
  margin-bottom: 16px;
}

.intro-sub {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.04em;
}

/* ── Main ── */
.main-content { padding-bottom: 80px; }

.concept-section { padding: 56px 0 48px; }

.section-header {
  display: flex;
  align-items: baseline;
  gap: 16px;
  margin-bottom: 20px;
}

.section-number {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0.08em;
  flex-shrink: 0;
}

.section-title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(20px, 3vw, 28px);
  letter-spacing: -0.01em;
  line-height: 1.15;
  color: var(--text);
  text-transform: uppercase;
}

.section-quote {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--muted);
  border-left: 2px solid var(--border);
  padding-left: 16px;
  margin-bottom: 20px;
  line-height: 1.6;
  font-style: normal;
}

.section-body {
  font-size: 15px;
  line-height: 1.7;
  color: var(--text);
  margin-bottom: 28px;
  max-width: 680px;
}

.section-body strong { font-weight: 500; color: var(--text); }
.section-body em { color: var(--muted); font-style: italic; }

.section-divider {
  height: 1px;
  background: var(--border);
}

/* ── Component card ── */
.component-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  overflow: hidden;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 18px;
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s ease;
  user-select: none;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-primary {
  background: var(--blue);
  color: var(--bg);
  border-color: var(--blue);
}
.btn-primary:hover:not(:disabled) { opacity: 0.88; }

.btn-secondary {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}
.btn-secondary:hover:not(:disabled) {
  border-color: var(--muted);
  background: rgba(255,255,255,0.04);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border-color: transparent;
  padding: 9px 12px;
}
.btn-ghost:hover:not(:disabled) {
  color: var(--text);
  background: rgba(255,255,255,0.04);
}

/* ── Labels ── */
.label {
  display: block;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 10px;
}

/* ── Mono text helpers ── */
.mono { font-family: var(--font-mono); }
.muted { color: var(--muted); }

/* ══════════════════════════════════════════════════
   COMPONENT 01 — One-shot trap
══════════════════════════════════════════════════ */

.pipeline-wrap {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.pipeline-toggle-row {
  display: flex;
  gap: 8px;
}

.toggle-btn {
  padding: 7px 16px;
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 12px;
  cursor: pointer;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  transition: all 0.15s ease;
}
.toggle-btn.active {
  background: var(--blue-dim);
  border-color: var(--blue);
  color: var(--blue);
}
.toggle-btn:hover:not(.active) { border-color: var(--muted); color: var(--text); }

.assumption-badge {
  font-family: var(--font-mono);
  font-size: 10px;
  padding: 4px 6px;
  border-radius: 4px;
  text-align: center;
  line-height: 1.4;
}
.assumption-badge.a1 { background: var(--amber-dim); color: var(--amber); border: 1px solid var(--amber); }
.assumption-badge.a2 { background: var(--red-dim); color: var(--red); border: 1px solid var(--red); }

/* ══════════════════════════════════════════════════
   COMPONENT 02 — Three types of feedback
══════════════════════════════════════════════════ */

.tabs-row {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0;
}

.tab-btn {
  padding: 8px 16px;
  font-family: var(--font-mono);
  font-size: 12px;
  cursor: pointer;
  border: none;
  background: transparent;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: all 0.15s ease;
  letter-spacing: 0.03em;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--blue); border-bottom-color: var(--blue); }

.tab-content {
  display: none;
  animation: fade-in 0.2s ease;
}
.tab-content.active { display: block; }

.feedback-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

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

.feedback-cell {
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
}

.feedback-cell-label {
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 6px;
}

.feedback-cell-value {
  font-size: 13.5px;
  color: var(--text);
  line-height: 1.5;
}

.feedback-verdict {
  margin-top: 16px;
  padding: 12px 16px;
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.5;
}
.feedback-verdict.retry   { background: var(--amber-dim); border: 1px solid var(--amber); color: var(--amber); }
.feedback-verdict.human   { background: var(--blue-dim);  border: 1px solid var(--blue);  color: var(--blue);  }
.feedback-verdict.eval    { background: var(--teal-dim);  border: 1px solid var(--teal);  color: var(--teal);  }

/* ══════════════════════════════════════════════════
   COMPONENT 03 — The iteration cycle (SVG)
══════════════════════════════════════════════════ */

.cycle-wrap {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  align-items: start;
}

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

.cycle-diagram-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

#cycle-svg {
  width: 100%;
  max-width: 320px;
  height: auto;
}

.cycle-node-circle {
  transition: fill 0.2s ease, stroke 0.2s ease;
}
.cycle-node-diamond {
  transition: fill 0.2s ease, stroke 0.2s ease;
}
.cycle-node-label {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  fill: var(--muted);
  transition: fill 0.2s ease;
  dominant-baseline: middle;
  text-anchor: middle;
}
.cycle-node-sublabel {
  font-family: 'JetBrains Mono', monospace;
  font-size: 9px;
  fill: var(--muted);
  dominant-baseline: middle;
  text-anchor: middle;
  opacity: 0;
  transition: opacity 0.2s ease;
}
.cycle-arrow {
  stroke: var(--border);
  stroke-width: 1.5;
  fill: none;
  transition: stroke 0.2s ease;
  marker-end: url(#arrowhead);
}
.cycle-arrow.active { stroke: var(--blue); }

/* Sub-agent branches — hidden until iteration 2 */
.subagent-branch {
  opacity: 0;
  transition: opacity 0.4s ease;
}
.subagent-branch.visible { opacity: 1; }

.cycle-controls {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.cycle-step-counter {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
}

/* Context panel */
.context-panel {
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}

.context-panel-header {
  padding: 10px 14px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.context-entries {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 180px;
}

.context-entry {
  padding: 8px 10px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  line-height: 1.5;
  animation: fade-in 0.25s ease;
}
.context-entry.task   { background: var(--teal-dim);  border: 1px solid rgba(45,212,191,0.2); color: var(--teal); }
.context-entry.eval   { background: var(--blue-dim);  border: 1px solid rgba(79,142,247,0.2); color: var(--blue); }
.context-entry.delta  { background: var(--amber-dim); border: 1px solid rgba(245,158,11,0.2); color: var(--amber); }
.context-entry.steer  { background: var(--green-dim); border: 1px solid rgba(34,197,94,0.2); color: var(--green); }

.context-empty {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
  font-style: italic;
}

.active-node-label {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  min-width: 120px;
  text-align: center;
}

/* ══════════════════════════════════════════════════
   COMPONENT 04 — Stopping problem
══════════════════════════════════════════════════ */

.stopping-wrap {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.threshold-row {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.threshold-label {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text);
  white-space: nowrap;
}

.threshold-slider {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  min-width: 120px;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  outline: none;
  cursor: pointer;
}
.threshold-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--blue);
  cursor: pointer;
  transition: background 0.15s ease;
}
.threshold-slider:hover::-webkit-slider-thumb { opacity: 0.88; }

.threshold-value {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--blue);
  min-width: 24px;
  text-align: right;
}

.loop-viz {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.loop-iter-row {
  display: flex;
  align-items: center;
  gap: 10px;
  animation: fade-in 0.2s ease;
}

.loop-iter-num {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
  min-width: 72px;
}

.loop-iter-bar {
  height: 8px;
  border-radius: 4px;
  background: var(--blue-dim);
  border: 1px solid var(--blue);
  transition: width 0.3s ease;
}

.loop-iter-score {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
}

.stopping-verdict {
  padding: 12px 16px;
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.5;
  transition: all 0.2s ease;
}
.stopping-verdict.converged   { background: var(--green-dim); border: 1px solid var(--green); color: var(--green); }
.stopping-verdict.diminishing { background: var(--amber-dim); border: 1px solid var(--amber); color: var(--amber); }
.stopping-verdict.runaway     { background: var(--red-dim);   border: 1px solid var(--red);   color: var(--red);   }

.cost-meter {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
}
.cost-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.cost-item-label {
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.cost-item-value {
  font-family: var(--font-mono);
  font-size: 18px;
  font-weight: 500;
  color: var(--text);
  transition: color 0.2s ease;
}

/* ══════════════════════════════════════════════════
   COMPONENT 05 — Zoom out
══════════════════════════════════════════════════ */

.zoom-wrap {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.zoom-panels {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  align-items: start;
}

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

.zoom-panel {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 16px;
  background: var(--bg);
  transition: border-color 0.2s ease;
}
.zoom-panel.highlighted { border-color: var(--teal); }

.zoom-panel-title {
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 12px;
}

.mini-cycle {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  justify-content: center;
}

.mini-node {
  padding: 6px 10px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 11px;
  border: 1px solid var(--border);
  color: var(--muted);
  transition: all 0.2s ease;
}
.mini-node.gen  { border-color: var(--teal);  color: var(--teal);  background: var(--teal-dim); }
.mini-node.eval { border-color: var(--blue);  color: var(--blue);  background: var(--blue-dim); }
.mini-node.delt { border-color: var(--amber); color: var(--amber); background: var(--amber-dim); }
.mini-node.steer{ border-color: var(--muted); color: var(--muted); }
.mini-arrow { font-size: 14px; color: var(--muted); }

.subagent-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  transition: all 0.3s ease;
}

.subagent-tile {
  padding: 8px 6px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--muted);
  text-align: center;
  background: var(--bg);
  transition: all 0.2s ease;
}
.subagent-tile.active { border-color: var(--teal); color: var(--teal); background: var(--teal-dim); }

.zoom-expanded-view {
  display: none;
  animation: fade-in 0.25s ease;
}
.zoom-expanded-view.visible { display: block; }

.zoom-note {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  margin-top: 8px;
  line-height: 1.5;
}
.zoom-note strong { color: var(--teal); }

/* ── Footer ── */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 32px 0 40px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.site-footer .container { display: flex; flex-direction: column; gap: 6px; }
.site-footer a { color: var(--muted); }
.site-footer a:hover { color: var(--blue); }

/* ── Keyframes ── */
@keyframes fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}
