/* ==========================================================================
   Seeing Geometry — 3Blue1Brown-Inspired Visual Book Theme
   ========================================================================== */

:root {
  --bg: #0b0f14;
  --bg-elevated: #111822;
  --bg-card: #151e2b;
  --bg-canvas: #090d12;
  --border: #233044;
  --border-soft: rgba(88, 196, 221, 0.16);

  --text: #e6edf3;
  --text-muted: #9aa7b8;
  --text-dim: #6e7d91;

  /* 3Blue1Brown / Manim signature palette */
  --blue: #58c4dd;
  --blue-glow: rgba(88, 196, 221, 0.25);
  --gold: #f7c948;
  --gold-glow: rgba(247, 201, 72, 0.25);
  --coral: #fc6255;
  --coral-glow: rgba(252, 98, 85, 0.25);
  --green: #83c167;
  --green-glow: rgba(131, 193, 103, 0.25);
  --purple: #a78bfa;
  --teal: #45c4b0;
  --orange: #ff944d;

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-serif: 'Newsreader', 'Georgia', 'Times New Roman', serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', ui-monospace, monospace;

  --sidebar-width: 290px;
  --content-max: 860px;
  --radius: 14px;
  --radius-sm: 8px;
}

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

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

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(ellipse 80% 50% at 60% -10%, rgba(88, 196, 221, 0.08), transparent 60%),
    radial-gradient(ellipse 60% 40% at 15% 90%, rgba(247, 201, 72, 0.05), transparent 60%),
    var(--bg);
  color: var(--text);
}

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

a:hover {
  color: var(--gold);
}

/* ---------- Top 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;
}

/* ---------- Mobile Header ---------- */
.mobile-topbar {
  display: none;
  position: sticky;
  top: 0;
  z-index: 90;
  background: rgba(11, 15, 20, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1.1rem;
  align-items: center;
  justify-content: space-between;
}

.mobile-menu-btn {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.75rem;
  font-size: 0.9rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}

.mobile-brand {
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
  font-size: 0.98rem;
}

/* ---------- Main Two-Column Book Layout ---------- */
.book-layout {
  display: flex;
  min-height: 100vh;
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  padding: 1.5rem 1.15rem 2.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  z-index: 95;
}

.sidebar::-webkit-scrollbar {
  width: 6px;
}
.sidebar::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 99px;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.35rem 0.4rem 0.9rem;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}

.sidebar-brand:hover {
  color: var(--blue);
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: linear-gradient(135deg, rgba(88, 196, 221, 0.22), rgba(247, 201, 72, 0.22));
  border: 1px solid rgba(88, 196, 221, 0.45);
  display: grid;
  place-items: center;
  font-size: 1.15rem;
  flex-shrink: 0;
}

.brand-title {
  font-weight: 750;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.brand-sub {
  font-size: 0.72rem;
  color: var(--text-muted);
  display: block;
  margin-top: 2px;
}

.course-progress-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.7rem 0.85rem;
}

.course-progress-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.76rem;
  color: var(--text-muted);
  margin-bottom: 0.45rem;
}

.course-progress-track {
  height: 6px;
  background: rgba(255, 255, 255, 0.07);
  border-radius: 99px;
  overflow: hidden;
}

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

.toc-part-title {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  font-weight: 700;
  margin: 0.9rem 0 0.35rem 0.45rem;
}

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

.toc-link {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.46rem 0.6rem;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 0.86rem;
  line-height: 1.3;
  transition: background 0.15s ease, color 0.15s ease;
}

.toc-link:hover {
  background: rgba(88, 196, 221, 0.08);
  color: var(--text);
}

.toc-link.active {
  background: rgba(88, 196, 221, 0.15);
  color: var(--blue);
  font-weight: 600;
}

.toc-num {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-dim);
  width: 1.35rem;
  flex-shrink: 0;
}

.toc-link.active .toc-num {
  color: var(--blue);
}

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

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

/* ---------- Chapter Content Area ---------- */
.chapter-content {
  flex: 1;
  min-width: 0;
  padding: 2.75rem clamp(1.25rem, 4vw, 3.75rem) 5rem;
  max-width: calc(var(--content-max) + 7.5rem);
  margin: 0 auto;
}

.chapter-header {
  margin-bottom: 2.6rem;
  padding-bottom: 1.8rem;
  border-bottom: 1px solid var(--border);
}

.chapter-eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.78rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--blue);
  margin-bottom: 0.7rem;
}

.chapter-header h1 {
  font-family: var(--font-serif);
  font-size: clamp(2.1rem, 4.4vw, 3.15rem);
  line-height: 1.12;
  letter-spacing: -0.02em;
  margin: 0 0 0.85rem;
  color: #ffffff;
  font-weight: 600;
}

.chapter-subtitle {
  font-size: 1.15rem;
  color: var(--text-muted);
  margin: 0;
  max-width: 64ch;
  line-height: 1.6;
}

.chapter-content h2 {
  font-family: var(--font-serif);
  font-size: 1.75rem;
  color: #fff;
  margin: 2.8rem 0 0.9rem;
  letter-spacing: -0.015em;
  font-weight: 600;
}

.chapter-content h3 {
  font-size: 1.15rem;
  color: var(--blue);
  margin: 1.9rem 0 0.55rem;
  font-weight: 650;
}

.chapter-content p {
  margin: 0 0 1.2rem;
  color: #d6dfe9;
  font-size: 1.04rem;
  max-width: 70ch;
}

.chapter-content ul, .chapter-content ol {
  margin: 0 0 1.35rem;
  padding-left: 1.4rem;
  max-width: 68ch;
  color: #d6dfe9;
}

.chapter-content li {
  margin-bottom: 0.45rem;
}

/* Color accent spans for visual-to-text correspondence (3B1B signature!) */
.c-blue   { color: var(--blue); font-weight: 600; }
.c-gold   { color: var(--gold); font-weight: 600; }
.c-coral  { color: var(--coral); font-weight: 600; }
.c-green  { color: var(--green); font-weight: 600; }
.c-purple { color: var(--purple); font-weight: 600; }
.c-teal   { color: var(--teal); font-weight: 600; }
.c-orange { color: var(--orange); font-weight: 600; }

/* ---------- Callout Boxes (Intuition, Pause & Ponder, Big Idea) ---------- */
.callout {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 4px solid var(--blue);
  border-radius: var(--radius-sm);
  padding: 1.1rem 1.3rem;
  margin: 1.65rem 0;
  max-width: 70ch;
}

.callout.gold {
  border-left-color: var(--gold);
  background: linear-gradient(90deg, rgba(247, 201, 72, 0.06), var(--bg-card) 40%);
}

.callout.green {
  border-left-color: var(--green);
  background: linear-gradient(90deg, rgba(131, 193, 103, 0.06), var(--bg-card) 40%);
}

.callout.coral {
  border-left-color: var(--coral);
  background: linear-gradient(90deg, rgba(252, 98, 85, 0.06), var(--bg-card) 40%);
}

.callout-title {
  font-size: 0.78rem;
  font-weight: 750;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--blue);
  margin-bottom: 0.4rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

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

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

/* ---------- Interactive Figure Containers ---------- */
.interactive-figure {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin: 2rem 0 2.3rem;
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.38);
}

.figure-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 1.1rem;
  background: rgba(255, 255, 255, 0.02);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.figure-title {
  font-size: 0.88rem;
  font-weight: 650;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.figure-badge {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 0.16rem 0.5rem;
  border-radius: 99px;
  background: rgba(88, 196, 221, 0.15);
  color: var(--blue);
  font-weight: 700;
}

.figure-hint {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.canvas-wrap {
  position: relative;
  width: 100%;
  background: var(--bg-canvas);
  line-height: 0;
}

.canvas-wrap canvas {
  display: block;
  width: 100%;
  height: 390px;
  touch-action: none;
  user-select: none;
}

.canvas-wrap.tall canvas {
  height: 450px;
}

.canvas-wrap.short canvas {
  height: 310px;
}

.figure-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.85rem 1.25rem;
  padding: 0.85rem 1.1rem;
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
}

.control-group {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  font-size: 0.84rem;
  color: var(--text-muted);
}

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

.control-value {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--gold);
  min-width: 3.1rem;
  text-align: right;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 135px;
  height: 5px;
  border-radius: 99px;
  background: var(--border);
  outline: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--blue);
  box-shadow: 0 0 10px var(--blue-glow);
  cursor: pointer;
  transition: transform 0.12s ease;
}

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

.btn {
  background: rgba(88, 196, 221, 0.12);
  color: var(--blue);
  border: 1px solid rgba(88, 196, 221, 0.35);
  border-radius: var(--radius-sm);
  padding: 0.42rem 0.85rem;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font-sans);
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.btn:hover {
  background: rgba(88, 196, 221, 0.24);
  border-color: var(--blue);
  color: #fff;
}

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

.btn.gold {
  background: rgba(247, 201, 72, 0.14);
  color: var(--gold);
  border-color: rgba(247, 201, 72, 0.4);
}

.btn.gold:hover, .btn.gold.active {
  background: var(--gold);
  color: #0b0f14;
}

.btn-group {
  display: inline-flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.figure-readout {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
  padding: 0.3rem 0.65rem;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.figure-caption {
  padding: 0.75rem 1.1rem;
  font-size: 0.86rem;
  color: var(--text-muted);
  border-top: 1px solid rgba(255, 255, 255, 0.04);
  line-height: 1.55;
}

/* ---------- Chapter Completion & Prev/Next Footer ---------- */
.chapter-footer {
  margin-top: 3.5rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border);
}

.complete-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.complete-bar p {
  margin: 0;
  font-size: 0.92rem;
  color: var(--text-muted);
}

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

.nav-card {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 1rem 1.2rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color 0.15s ease, transform 0.15s ease;
}

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

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

.nav-dir {
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-dim);
  font-weight: 700;
}

.nav-title {
  font-size: 1rem;
  font-weight: 650;
  color: var(--text);
}

/* ---------- Home / Cover Page ---------- */
.hero {
  padding: 2rem 0 2.5rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 2.5rem;
}

.hero-grid {
  display: grid;
  grid-template-columns: 1.15fr 1fr;
  gap: 2.2rem;
  align-items: center;
}

.hero h1 {
  font-family: var(--font-serif);
  font-size: clamp(2.5rem, 5vw, 3.65rem);
  line-height: 1.07;
  margin: 0.5rem 0 1rem;
  color: #fff;
  letter-spacing: -0.025em;
}

.hero-lead {
  font-size: 1.12rem;
  color: var(--text-muted);
  margin: 0 0 1.6rem;
  line-height: 1.65;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.85rem;
}

.btn-lg {
  padding: 0.72rem 1.35rem;
  font-size: 0.95rem;
  border-radius: 10px;
}

.hero-canvas-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
}

.hero-canvas-card canvas {
  display: block;
  width: 100%;
  height: 320px;
}

.parts-section {
  margin-bottom: 2.5rem;
}

.part-heading {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  margin: 2.2rem 0 1rem;
}

.part-badge {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--gold);
  background: rgba(247, 201, 72, 0.12);
  border: 1px solid rgba(247, 201, 72, 0.3);
  padding: 0.18rem 0.55rem;
  border-radius: 99px;
}

.part-heading h2 {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 1.5rem;
}

.chapter-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(255px, 1fr));
  gap: 1rem;
}

.chapter-card {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.15rem 1.25rem;
  transition: border-color 0.18s ease, transform 0.18s ease, box-shadow 0.18s ease;
  position: relative;
}

.chapter-card:hover {
  border-color: var(--blue);
  transform: translateY(-3px);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
}

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

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

.chapter-card-status {
  font-size: 0.72rem;
  color: var(--green);
  font-weight: 600;
}

.chapter-card h3 {
  margin: 0.1rem 0 0;
  font-size: 1.06rem;
  color: #fff;
  font-weight: 650;
}

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

/* ---------- Responsive ---------- */
@media (max-width: 960px) {
  .mobile-topbar {
    display: flex;
  }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: 12px 0 36px rgba(0, 0, 0, 0.6);
  }

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

  .sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 92;
  }

  .sidebar-backdrop.open {
    display: block;
  }

  .hero-grid {
    grid-template-columns: 1fr;
  }

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

  .figure-readout {
    margin-left: 0;
  }
}
