/* ==========================================================================
   THE ART OF STEERING — Visual Cybernetics Course
   3Blue1Brown / Manim-inspired Dark Visual Design System
   ========================================================================== */

:root {
  /* Core Palette (Manim / 3b1b inspired) */
  --bg-deep: #0b0d13;
  --bg-surface: #121621;
  --bg-elevated: #181e2c;
  --bg-canvas: #0d1018;
  --border-subtle: rgba(148, 163, 184, 0.14);
  --border-bright: rgba(88, 196, 221, 0.35);

  /* Text */
  --text-primary: #e8edf5;
  --text-secondary: #9aa7bd;
  --text-muted: #69778f;

  /* Semantic Visual Accents */
  --cyan: #58c4dd;       /* Signals, goals, primary flow */
  --cyan-dim: rgba(88, 196, 221, 0.16);
  --gold: #f4d35e;       /* Highlights, actuators, energy */
  --gold-dim: rgba(244, 211, 94, 0.16);
  --coral: #fc6255;      /* Disturbances, error, runaway */
  --coral-dim: rgba(252, 98, 85, 0.16);
  --emerald: #83c167;    /* Stability, homeostasis, balance */
  --emerald-dim: rgba(131, 193, 103, 0.16);
  --violet: #c792ea;     /* Models, observers, emergence */
  --violet-dim: rgba(199, 146, 234, 0.16);

  /* Typography */
  --font-display: 'Space Grotesk', system-ui, -apple-system, sans-serif;
  --font-body: 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, monospace;

  /* Layout */
  --max-prose: 760px;
  --max-wide: 1080px;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --nav-height: 62px;
}

*, *::before, *::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  background-color: var(--bg-deep);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.72;
  -webkit-font-smoothing: antialiased;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(ellipse 80% 50% at 50% -10%, rgba(88, 196, 221, 0.08), transparent 65%),
    var(--bg-deep);
}

a {
  color: var(--cyan);
  text-decoration: none;
  transition: color 0.18s ease, opacity 0.18s ease;
}

a:hover {
  color: #8be0f3;
}

/* Top Reading Progress Bar */
.reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  width: 0%;
  height: 3px;
  background: linear-gradient(90deg, var(--cyan), var(--gold), var(--emerald));
  z-index: 1000;
  transition: width 0.08s linear;
}

/* Navigation Bar */
.site-nav {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--nav-height);
  background: rgba(11, 13, 19, 0.86);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border-subtle);
}

.site-nav-inner {
  max-width: var(--max-wide);
  margin: 0 auto;
  height: 100%;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.02rem;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.brand-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--cyan);
  box-shadow: 0 0 12px var(--cyan);
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 18px;
  font-size: 0.9rem;
}

.nav-pill {
  padding: 6px 13px;
  border-radius: 999px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.18s ease;
}

.nav-pill:hover {
  border-color: var(--border-bright);
  color: var(--text-primary);
}

/* Chapter Drawer Menu */
.chapter-drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 7, 12, 0.72);
  backdrop-filter: blur(4px);
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.chapter-drawer-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.chapter-drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: min(390px, 92vw);
  height: 100vh;
  background: var(--bg-surface);
  border-left: 1px solid var(--border-subtle);
  z-index: 210;
  padding: 24px;
  overflow-y: auto;
  transform: translateX(100%);
  transition: transform 0.24s cubic-bezier(0.22, 1, 0.36, 1);
}

.chapter-drawer.open {
  transform: translateX(0);
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border-subtle);
}

.drawer-header h3 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.08rem;
}

.drawer-close {
  background: none;
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1.1rem;
}

.drawer-close:hover {
  color: var(--text-primary);
  border-color: var(--border-bright);
}

.drawer-part-label {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin: 18px 0 8px;
}

.drawer-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  margin-bottom: 4px;
  border: 1px solid transparent;
  transition: all 0.15s ease;
}

.drawer-item:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.drawer-item.active {
  background: var(--cyan-dim);
  border-color: var(--border-bright);
  color: var(--text-primary);
}

.drawer-num {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--cyan);
  min-width: 24px;
}

.drawer-check {
  margin-left: auto;
  font-size: 0.85rem;
  color: var(--emerald);
}

/* Main Content Containers */
.container-wide {
  max-width: var(--max-wide);
  margin: 0 auto;
  padding: 0 24px;
}

.chapter-main {
  max-width: var(--max-prose);
  margin: 0 auto;
  padding: 52px 24px 96px;
}

/* Chapter Header */
.chapter-hero {
  margin-bottom: 44px;
  padding-bottom: 32px;
  border-bottom: 1px solid var(--border-subtle);
}

.chapter-eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--cyan);
  margin-bottom: 14px;
}

.chapter-title {
  font-family: var(--font-display);
  font-size: clamp(2.1rem, 5vw, 3.1rem);
  line-height: 1.12;
  letter-spacing: -0.025em;
  margin: 0 0 16px;
  color: #ffffff;
}

.chapter-subtitle {
  font-size: 1.15rem;
  line-height: 1.6;
  color: var(--text-secondary);
  margin: 0;
}

/* Prose Typography */
.chapter-main h2 {
  font-family: var(--font-display);
  font-size: 1.62rem;
  letter-spacing: -0.02em;
  margin: 56px 0 16px;
  color: #ffffff;
}

.chapter-main h3 {
  font-family: var(--font-display);
  font-size: 1.22rem;
  margin: 34px 0 12px;
  color: var(--text-primary);
}

.chapter-main p {
  margin: 0 0 20px;
  color: var(--text-primary);
}

.chapter-main ul, .chapter-main ol {
  margin: 0 0 22px;
  padding-left: 24px;
}

.chapter-main li {
  margin-bottom: 8px;
}

/* Color-coded Concept Spans (3b1b style inline color coding) */
.c-cyan { color: var(--cyan); font-weight: 600; }
.c-gold { color: var(--gold); font-weight: 600; }
.c-coral { color: var(--coral); font-weight: 600; }
.c-emerald { color: var(--emerald); font-weight: 600; }
.c-violet { color: var(--violet); font-weight: 600; }

/* Callout / Principle Cards */
.principle-box {
  margin: 32px 0;
  padding: 22px 24px;
  background: linear-gradient(135deg, rgba(88, 196, 221, 0.09), rgba(18, 22, 33, 0.95));
  border: 1px solid var(--border-bright);
  border-left: 4px solid var(--cyan);
  border-radius: var(--radius-md);
}

.principle-box.gold {
  background: linear-gradient(135deg, rgba(244, 211, 94, 0.09), rgba(18, 22, 33, 0.95));
  border-color: rgba(244, 211, 94, 0.35);
  border-left-color: var(--gold);
}

.principle-box.emerald {
  background: linear-gradient(135deg, rgba(131, 193, 103, 0.09), rgba(18, 22, 33, 0.95));
  border-color: rgba(131, 193, 103, 0.35);
  border-left-color: var(--emerald);
}

.principle-box.violet {
  background: linear-gradient(135deg, rgba(199, 146, 234, 0.09), rgba(18, 22, 33, 0.95));
  border-color: rgba(199, 146, 234, 0.35);
  border-left-color: var(--violet);
}

.principle-label {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--cyan);
  margin-bottom: 8px;
  display: block;
}

.principle-box.gold .principle-label { color: var(--gold); }
.principle-box.emerald .principle-label { color: var(--emerald); }
.principle-box.violet .principle-label { color: var(--violet); }

.principle-box p:last-child {
  margin-bottom: 0;
}

/* Interactive Simulation Stage */
.sim-card {
  margin: 34px -28px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
}

@media (max-width: 840px) {
  .sim-card {
    margin: 28px 0;
  }
}

.sim-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  padding: 14px 20px;
  background: rgba(255, 255, 255, 0.02);
  border-bottom: 1px solid var(--border-subtle);
}

.sim-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.96rem;
  color: var(--text-primary);
}

.sim-badge {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--cyan-dim);
  color: var(--cyan);
}

.sim-stage {
  position: relative;
  background: var(--bg-canvas);
  width: 100%;
  overflow: hidden;
}

.sim-stage canvas {
  display: block;
  width: 100%;
  height: auto;
  touch-action: none;
}

.sim-controls {
  padding: 16px 20px;
  background: var(--bg-surface);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px 24px;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 160px;
  flex: 1 1 180px;
}

.control-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.control-value {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--cyan);
}

/* Custom Range Slider */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  background: var(--bg-elevated);
  border-radius: 999px;
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--cyan);
  border: 2px solid var(--bg-deep);
  box-shadow: 0 0 10px rgba(88, 196, 221, 0.6);
  cursor: pointer;
  transition: transform 0.12s ease;
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.18);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--border-subtle);
  background: var(--bg-elevated);
  color: var(--text-primary);
  transition: all 0.16s ease;
}

.btn:hover {
  border-color: var(--border-bright);
  background: #20283a;
}

.btn.active, .btn-primary {
  background: var(--cyan);
  color: #071018;
  border-color: var(--cyan);
}

.btn.active:hover, .btn-primary:hover {
  background: #77d4e9;
}

.btn-coral {
  background: var(--coral-dim);
  color: var(--coral);
  border-color: rgba(252, 98, 85, 0.4);
}

.btn-coral:hover {
  background: rgba(252, 98, 85, 0.25);
}

.btn-gold {
  background: var(--gold-dim);
  color: var(--gold);
  border-color: rgba(244, 211, 94, 0.4);
}

.btn-emerald {
  background: var(--emerald-dim);
  color: var(--emerald);
  border-color: rgba(131, 193, 103, 0.4);
}

.sim-caption {
  padding: 12px 20px;
  font-size: 0.88rem;
  color: var(--text-secondary);
  background: rgba(0, 0, 0, 0.18);
  border-top: 1px solid var(--border-subtle);
}

/* Legend Pills */
.sim-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
}

/* Intuition Check / Visual Quiz */
.intuition-card {
  margin: 48px 0 36px;
  padding: 24px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
}

.intuition-card h3 {
  margin-top: 0;
  color: var(--gold);
}

.quiz-options {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.quiz-option {
  text-align: left;
  padding: 13px 16px;
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  font-size: 0.94rem;
  cursor: pointer;
  transition: all 0.16s ease;
}

.quiz-option:hover {
  border-color: var(--border-bright);
  transform: translateX(3px);
}

.quiz-option.correct {
  background: var(--emerald-dim);
  border-color: var(--emerald);
  color: #ffffff;
}

.quiz-option.wrong {
  background: var(--coral-dim);
  border-color: var(--coral);
}

.quiz-feedback {
  margin-top: 14px;
  font-size: 0.92rem;
  color: var(--text-secondary);
  min-height: 22px;
}

/* Chapter Footer Navigation */
.chapter-footer {
  margin-top: 64px;
  padding-top: 32px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.complete-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  padding: 18px 22px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
}

.chapter-nav-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

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

.chapter-nav-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px 20px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  transition: all 0.18s ease;
}

.chapter-nav-card:hover {
  border-color: var(--border-bright);
  transform: translateY(-2px);
}

.chapter-nav-card.next {
  text-align: right;
  align-items: flex-end;
}

.nav-dir {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
}

.nav-chap-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.02rem;
  color: var(--cyan);
}

/* ==========================================================================
   HOMEPAGE STYLES
   ========================================================================== */
.home-hero {
  position: relative;
  padding: 72px 0 56px;
  overflow: hidden;
}

.hero-grid {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 40px;
  align-items: center;
}

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

.hero-kicker {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: 16px;
}

.home-hero h1 {
  font-family: var(--font-display);
  font-size: clamp(2.5rem, 5.5vw, 3.8rem);
  line-height: 1.08;
  letter-spacing: -0.03em;
  margin: 0 0 20px;
  color: #ffffff;
}

.home-hero p {
  font-size: 1.1rem;
  color: var(--text-secondary);
  margin: 0 0 28px;
  max-width: 540px;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.hero-canvas-wrap {
  background: var(--bg-canvas);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
}

.progress-banner {
  margin: 12px 0 42px;
  padding: 18px 22px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
}

.progress-bar-track {
  flex: 1 1 240px;
  height: 8px;
  background: var(--bg-elevated);
  border-radius: 999px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--cyan), var(--emerald));
  border-radius: 999px;
  transition: width 0.35s ease;
}

.part-section {
  margin-bottom: 52px;
}

.part-header {
  display: flex;
  align-items: baseline;
  gap: 14px;
  margin-bottom: 18px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-subtle);
}

.part-tag {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--cyan);
}

.part-header h2 {
  font-family: var(--font-display);
  font-size: 1.45rem;
  margin: 0;
  color: #ffffff;
}

.chapters-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 18px;
}

.chapter-card {
  position: relative;
  display: flex;
  flex-direction: column;
  padding: 22px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}

.chapter-card:hover {
  transform: translateY(-4px);
  border-color: var(--border-bright);
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.35);
}

.chapter-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.chapter-card-num {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--cyan);
  background: var(--cyan-dim);
  padding: 3px 9px;
  border-radius: 999px;
}

.chapter-card-status {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--emerald);
}

.chapter-card h3 {
  font-family: var(--font-display);
  font-size: 1.16rem;
  margin: 0 0 8px;
  color: #ffffff;
}

.chapter-card p {
  font-size: 0.9rem;
  line-height: 1.55;
  color: var(--text-secondary);
  margin: 0 0 16px;
  flex: 1;
}

.chapter-card-meta {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  color: var(--text-muted);
}

.site-footer {
  border-top: 1px solid var(--border-subtle);
  padding: 36px 24px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.88rem;
}
