/* ─── Diagrams Page ──────────────────────────────────────────────────────── */

/* ── Chapter color variables ── */
:root {
  --ch1:  #2563eb; --ch1-bg:  #eff6ff; --ch1-border:  #bfdbfe;
  --ch2:  #7c3aed; --ch2-bg:  #f5f3ff; --ch2-border:  #ddd6fe;
  --ch3:  #0891b2; --ch3-bg:  #ecfeff; --ch3-border:  #a5f3fc;
  --ch4:  #059669; --ch4-bg:  #ecfdf5; --ch4-border:  #a7f3d0;
  --ch5:  #dc2626; --ch5-bg:  #fef2f2; --ch5-border:  #fca5a5;
  --ch6:  #ea580c; --ch6-bg:  #fff7ed; --ch6-border:  #fed7aa;
  --ch7:  #d97706; --ch7-bg:  #fffbeb; --ch7-border:  #fde68a;
  --ch9:  #0f766e; --ch9-bg:  #f0fdfa; --ch9-border:  #99f6e4;
  --ch10: #4338ca; --ch10-bg: #eef2ff; --ch10-border: #c7d2fe;
  --ch11: #be185d; --ch11-bg: #fdf2f8; --ch11-border: #f9a8d4;
  --ch12: #b45309; --ch12-bg: #fffbeb; --ch12-border: #fcd34d;
  --ch13: #15803d; --ch13-bg: #f0fdf4; --ch13-border: #86efac;
  --ch14: #9333ea; --ch14-bg: #faf5ff; --ch14-border: #d8b4fe;
}

/* ── Hero ── */
.hero {
  text-align: center;
  padding: 2.5rem 1rem 2rem;
  border-bottom: 1px solid var(--sand-200);
  margin-bottom: 0;
}
.hero .badge {
  display: inline-block;
  background: var(--sand-100);
  border: 1px solid var(--sand-200);
  border-radius: 999px;
  padding: 0.25rem 0.85rem;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin-bottom: 0.85rem;
}
.hero h1 {
  font-family: 'Newsreader', serif;
  font-size: clamp(1.4rem, 3vw, 2rem);
  font-weight: 700;
  color: var(--ink);
  line-height: 1.2;
  margin-bottom: 0.5rem;
}
.hero .sub {
  font-size: 0.84rem;
  color: var(--ink-3);
  max-width: 540px;
  margin: 0 auto 1.25rem;
  line-height: 1.6;
}

/* ── Mode toggle ── */
.mode-toggle {
  display: inline-flex;
  gap: 0;
  border: 1.5px solid var(--sand-300);
  border-radius: 10px;
  overflow: hidden;
  margin-top: 0.5rem;
}
.mode-toggle button {
  padding: 0.45rem 1rem;
  font-size: 0.8rem;
  font-weight: 700;
  font-family: 'Lato', sans-serif;
  background: #fff;
  color: var(--ink-3);
  border: none;
  cursor: pointer;
  transition: all 0.2s;
}
.mode-toggle button.active { background: var(--sand-900); color: #fff; }
.mode-toggle button:not(.active):hover { background: var(--sand-100); }

/* ── Sticky chapter nav ── */
.chapter-nav {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(253, 252, 250, 0.95);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--sand-200);
  padding: 0.5rem 0;
}
.chapter-nav-inner {
  max-width: 80%;
  margin: 0 auto;
  padding: 0 1.25rem;
  display: flex;
  gap: 0.4rem;
  overflow-x: auto;
  scrollbar-width: none;
}
.chapter-nav-inner::-webkit-scrollbar { display: none; }
.chapter-nav-inner a {
  display: inline-block;
  padding: 0.3rem 0.7rem;
  font-size: 0.72rem;
  font-weight: 700;
  border-radius: 7px;
  border: 1.5px solid transparent;
  text-decoration: none;
  white-space: nowrap;
  transition: all 0.15s;
}
.chapter-nav-inner a:hover { filter: brightness(0.92); }

/* ── Chapter section ── */
.chapter-section { padding: 2rem 0 1rem; }
.chapter-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--sand-200);
}
.chapter-num {
  width: 36px; height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  font-weight: 900;
  color: #fff;
  flex-shrink: 0;
}
.chapter-title {
  font-family: 'Newsreader', serif;
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--ink);
}

/* ── Diagram grid — slightly larger ── */
.diagram-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 1.5rem;
}

/* ── Diagram card ── */
.diagram-card {
  background: #fff;
  border: 1px solid var(--sand-200);
  border-radius: 12px;
  overflow: hidden;
  transition: box-shadow 0.2s;
  position: relative;
}
.diagram-card:hover { box-shadow: 0 4px 18px rgba(0,0,0,0.07); }
.svg-wrap {
  padding: 1rem;
  background: var(--sand-50);
  border-bottom: 1px solid var(--sand-200);
}
.svg-wrap svg {
  width: 100%;
  height: auto;
  display: block;
}
.caption { padding: 0.85rem 1rem; }
.fig-num {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 0.2rem;
}
.fig-title {
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--ink);
  line-height: 1.4;
}

/* ── Per-card 3D toggle button ── */
.toggle-3d-btn {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 0.2rem 0.6rem;
  border-radius: 6px;
  border: 1.5px solid var(--sand-300);
  background: rgba(255,255,255,0.9);
  color: var(--ink-3);
  cursor: pointer;
  font-family: 'Lato', sans-serif;
  z-index: 20;
  transition: all 0.15s;
  backdrop-filter: blur(4px);
}
.toggle-3d-btn:hover { background: var(--sand-900); color: #fff; border-color: var(--sand-900); }
.diagram-card.card-3d .toggle-3d-btn {
  background: var(--sand-900);
  color: #fff;
  border-color: var(--sand-900);
}

/* ── 3D overlay ── */
.view-3d { display: none; }
.diagram-card.card-3d .view-3d {
  display: block;
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 10;
  border-radius: 12px;
  overflow: hidden;
  background: #0f0c1a;
}
.diagram-card.card-3d .svg-wrap { visibility: hidden; }

/* ── Canvas & 3D hint ── */
.canvas-3d {
  width: 100%;
  display: block;
  cursor: grab;
}
.canvas-3d:active { cursor: grabbing; }
.anim-hint {
  position: absolute;
  bottom: 0.6rem;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.62rem;
  font-weight: 700;
  color: rgba(255,255,255,0.45);
  letter-spacing: 0.05em;
  white-space: nowrap;
  pointer-events: none;
}

@media (max-width: 640px) {
  .diagram-grid { grid-template-columns: 1fr; }
  .chapter-nav-inner { max-width: 100%; }
}
