/* ==========================================================================
   Intuitive Reinforcement Learning — 3Blue1Brown-Inspired Visual Book
   Pure static CSS, zero external dependencies required.
   ========================================================================== */

:root {
  --bg: #0b0f17;
  --bg-elevated: #111827;
  --surface: #151e2e;
  --surface-hover: #1c283d;
  --border: rgba(148, 163, 184, 0.16);
  --border-strong: rgba(88, 196, 221, 0.35);

  /* Signature Manim / 3B1B luminous palette */
  --blue: #58c4dd;
  --blue-dim: rgba(88, 196, 221, 0.16);
  --gold: #f4d03f;
  --gold-dim: rgba(244, 208, 63, 0.16);
  --green: #6ee7b7;
  --green-dim: rgba(110, 231, 183, 0.16);
  --coral: #ff6b6b;
  --coral-dim: rgba(255, 107, 107, 0.16);
  --purple: #c084fc;
  --purple-dim: rgba(192, 132, 252, 0.16);
  --orange: #fb923c;

  --text: #e6edf7;
  --text-secondary: #a3b3c9;
  --text-muted: #6e8098;

  --font-serif: "Charter", "Iowan Old Style", "Palatino Linotype", "Georgia", serif;
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "Cascadia Code", "Fira Code", Consolas, monospace;

  --sidebar-w: 290px;
  --content-max: 820px;
  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.45);
}

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

html {
  scroll-behavior: smooth;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  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);
  color: var(--text);
}

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

a:hover {
  color: #8be0f4;
}

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

/* ---------- Top Mobile / Compact Header ---------- */
.top-bar {
  position: sticky;
  top: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 20px;
  background: rgba(11, 15, 23, 0.86);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.top-bar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.menu-toggle {
  display: none;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 11px;
  font-size: 0.9rem;
  cursor: pointer;
}

.brand-link {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
}

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

.top-bar-chapter {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* ---------- App Shell (Sidebar + Main) ---------- */
.book-shell {
  display: flex;
  min-height: calc(100vh - 53px);
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: rgba(17, 24, 39, 0.72);
  border-right: 1px solid var(--border);
  padding: 24px 16px 40px;
  position: sticky;
  top: 53px;
  height: calc(100vh - 53px);
  overflow-y: auto;
}

.sidebar-heading {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-muted);
  margin: 18px 10px 8px;
  font-weight: 700;
}

.sidebar-heading:first-child {
  margin-top: 0;
}

.toc-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.toc-item a {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.88rem;
  line-height: 1.35;
  border: 1px solid transparent;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.toc-item a:hover {
  background: var(--surface);
  color: var(--text);
}

.toc-item a.active {
  background: var(--blue-dim);
  color: var(--text);
  border-color: var(--border-strong);
  font-weight: 600;
}

.toc-num {
  font-family: var(--font-mono);
  font-size: 0.76rem;
  color: var(--blue);
  min-width: 22px;
  padding-top: 2px;
}

.toc-check {
  margin-left: auto;
  color: var(--green);
  font-size: 0.82rem;
  opacity: 0;
}

.toc-item.completed .toc-check {
  opacity: 1;
}

.sidebar-progress {
  margin-top: 24px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.progress-track {
  height: 6px;
  background: rgba(148, 163, 184, 0.15);
  border-radius: 99px;
  overflow: hidden;
  margin-top: 8px;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--blue), var(--green));
  border-radius: 99px;
  transition: width 0.35s ease;
}

/* ---------- Main Chapter Content ---------- */
.chapter-main {
  flex: 1;
  min-width: 0;
  padding: 44px 32px 96px;
}

.chapter-content {
  max-width: var(--content-max);
  margin: 0 auto;
}

.chapter-kicker {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--blue);
  margin-bottom: 12px;
}

.chapter-title {
  font-family: var(--font-serif);
  font-size: clamp(2.1rem, 4vw, 3rem);
  line-height: 1.15;
  letter-spacing: -0.02em;
  margin: 0 0 14px;
  color: #ffffff;
}

.chapter-subtitle {
  font-size: 1.18rem;
  color: var(--text-secondary);
  margin: 0 0 36px;
  line-height: 1.55;
}

.chapter-content h2 {
  font-family: var(--font-serif);
  font-size: 1.65rem;
  color: #ffffff;
  margin: 52px 0 16px;
  letter-spacing: -0.015em;
  line-height: 1.25;
}

.chapter-content h3 {
  font-size: 1.15rem;
  color: var(--blue);
  margin: 30px 0 10px;
}

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

.chapter-content strong {
  color: #ffffff;
  font-weight: 650;
}

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

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

/* Color accent highlights for inline concepts */
.c-blue { color: var(--blue); font-weight: 600; }
.c-gold { color: var(--gold); font-weight: 600; }
.c-green { color: var(--green); font-weight: 600; }
.c-coral { color: var(--coral); font-weight: 600; }
.c-purple { color: var(--purple); font-weight: 600; }

/* ---------- Callout Boxes ---------- */
.callout {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--blue);
  border-radius: var(--radius-sm);
  padding: 18px 22px;
  margin: 28px 0;
}

.callout.gold { border-left-color: var(--gold); }
.callout.green { border-left-color: var(--green); }
.callout.coral { border-left-color: var(--coral); }
.callout.purple { border-left-color: var(--purple); }

.callout-title {
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  font-weight: 700;
  color: var(--blue);
  margin-bottom: 6px;
}

.callout.gold .callout-title { color: var(--gold); }
.callout.green .callout-title { color: var(--green); }
.callout.coral .callout-title { color: var(--coral); }
.callout.purple .callout-title { color: var(--purple); }

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

/* ---------- Interactive Lab Frame ---------- */
.lab {
  background: linear-gradient(180deg, #131c2c 0%, #0e1522 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin: 32px 0;
  box-shadow: var(--shadow);
}

.lab-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.lab-title {
  font-weight: 700;
  font-size: 1rem;
  color: #ffffff;
  display: flex;
  align-items: center;
  gap: 8px;
}

.lab-badge {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 3px 8px;
  border-radius: 99px;
  background: var(--blue-dim);
  color: var(--blue);
  border: 1px solid rgba(88, 196, 221, 0.3);
}

.lab-caption {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin: 0 0 14px;
}

.lab-canvas-wrap {
  position: relative;
  width: 100%;
  background: #090d14;
  border: 1px solid rgba(148, 163, 184, 0.14);
  border-radius: 10px;
  overflow: hidden;
}

.lab-canvas-wrap canvas,
.lab-canvas-wrap svg {
  display: block;
  width: 100%;
  height: auto;
}

.lab-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 18px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--surface-hover);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s ease, background 0.15s ease, border-color 0.15s ease;
}

.btn:hover {
  background: #24334d;
  border-color: rgba(148, 163, 184, 0.35);
}

.btn:active {
  transform: translateY(1px);
}

.btn.primary {
  background: rgba(88, 196, 221, 0.18);
  border-color: rgba(88, 196, 221, 0.55);
  color: #bceeff;
}

.btn.primary:hover {
  background: rgba(88, 196, 221, 0.28);
}

.btn.gold {
  background: rgba(244, 208, 63, 0.16);
  border-color: rgba(244, 208, 63, 0.5);
  color: #fde68a;
}

.btn.active {
  background: var(--blue);
  color: #081018;
  border-color: var(--blue);
}

.slider-group {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.86rem;
  color: var(--text-secondary);
}

.slider-group label {
  white-space: nowrap;
}

.slider-group input[type="range"] {
  accent-color: var(--blue);
  width: 130px;
  cursor: pointer;
}

.slider-val {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--gold);
  min-width: 44px;
}

.lab-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-top: 12px;
}

.stat-pill {
  background: rgba(11, 15, 23, 0.75);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.stat-pill strong {
  font-family: var(--font-mono);
  color: var(--blue);
  margin-left: 6px;
}

/* ---------- Key Takeaways & Chapter Footer ---------- */
.takeaway-box {
  background: radial-gradient(circle at top right, rgba(110, 231, 183, 0.08), transparent 60%), var(--surface);
  border: 1px solid rgba(110, 231, 183, 0.28);
  border-radius: var(--radius);
  padding: 24px 26px;
  margin: 48px 0 36px;
}

.takeaway-box h3 {
  margin-top: 0;
  color: var(--green);
}

.chapter-footer {
  margin-top: 52px;
  padding-top: 28px;
  border-top: 1px solid var(--border);
}

.complete-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 24px;
}

.chapter-nav-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.nav-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 18px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  transition: border-color 0.18s ease, transform 0.18s ease, background 0.18s ease;
}

.nav-card:hover {
  border-color: var(--border-strong);
  background: var(--surface-hover);
  transform: translateY(-2px);
  color: #ffffff;
}

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

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

.nav-card-title {
  font-family: var(--font-serif);
  font-size: 1.12rem;
  color: var(--blue);
}

/* ---------- Landing Page Styles ---------- */
.landing-wrap {
  max-width: 1100px;
  margin: 0 auto;
  padding: 56px 24px 96px;
}

.hero {
  text-align: center;
  max-width: 780px;
  margin: 0 auto 48px;
}

.hero-badge {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 6px 14px;
  border-radius: 99px;
  background: var(--blue-dim);
  color: var(--blue);
  border: 1px solid rgba(88, 196, 221, 0.35);
  margin-bottom: 20px;
}

.hero h1 {
  font-family: var(--font-serif);
  font-size: clamp(2.4rem, 5.4vw, 3.9rem);
  line-height: 1.1;
  letter-spacing: -0.025em;
  margin: 0 0 18px;
  color: #ffffff;
}

.hero h1 span {
  background: linear-gradient(90deg, var(--blue), var(--gold));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.hero p {
  font-size: 1.15rem;
  color: var(--text-secondary);
  margin: 0 0 28px;
}

.hero-actions {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 14px;
}

.hero-btn {
  padding: 12px 24px;
  font-size: 1rem;
  border-radius: 10px;
}

.principles-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 18px;
  margin: 44px 0 56px;
}

.principle-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
}

.principle-card h3 {
  margin: 0 0 8px;
  font-size: 1.05rem;
  color: #ffffff;
}

.principle-card p {
  margin: 0;
  font-size: 0.92rem;
  color: var(--text-secondary);
}

.chapter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 18px;
  margin-top: 22px;
}

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

.chapter-card:hover {
  transform: translateY(-3px);
  border-color: var(--border-strong);
  background: var(--surface-hover);
  color: #ffffff;
}

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

.chapter-card-num {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--blue);
}

.chapter-card-part {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.chapter-card h3 {
  font-family: var(--font-serif);
  font-size: 1.25rem;
  margin: 4px 0 2px;
  color: #ffffff;
}

.chapter-card p {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.chapter-card-status {
  margin-top: auto;
  padding-top: 10px;
  font-size: 0.8rem;
  color: var(--green);
  font-weight: 600;
}

/* ---------- Responsive ---------- */
@media (max-width: 960px) {
  .menu-toggle {
    display: inline-flex;
  }

  .sidebar {
    position: fixed;
    left: 0;
    top: 53px;
    bottom: 0;
    z-index: 95;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    background: #0f1624;
    box-shadow: var(--shadow);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .chapter-main {
    padding: 28px 18px 72px;
  }

  .chapter-nav-grid {
    grid-template-columns: 1fr;
  }
}

