/* ==========================================================================
   Space in Motion — A Visual, Number-Free Book of Linear Algebra
   Shared Editorial Stylesheet
   ========================================================================== */

:root {
  /* Warm paper & deep ink palette */
  --bg: #faf8f4;
  --bg-elevated: #ffffff;
  --bg-subtle: #f2eee6;
  --bg-canvas: #131722;
  --bg-canvas-panel: #1a2030;

  --ink: #1b1f2a;
  --ink-muted: #52596b;
  --ink-faint: #848b9c;
  --border: #e4dfd4;
  --border-strong: #cfc8b8;

  /* Semantic geometric colors */
  --teal: #14b8a6;
  --teal-soft: rgba(20, 184, 166, 0.16);
  --amber: #f59e0b;
  --amber-soft: rgba(245, 158, 11, 0.16);
  --violet: #8b5cf6;
  --violet-soft: rgba(139, 92, 246, 0.18);
  --coral: #f43f5e;
  --coral-soft: rgba(244, 63, 94, 0.16);
  --gold: #fbbf24;
  --sky: #38bdf8;
  --emerald: #34d399;

  /* Typography */
  --font-serif: "Georgia", "Cambria", "Times New Roman", serif;
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  /* Layout */
  --content-width: 760px;
  --wide-width: 1020px;
  --radius: 14px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 3px rgba(18, 22, 33, 0.06);
  --shadow-md: 0 10px 30px rgba(18, 22, 33, 0.09);
  --shadow-canvas: 0 16px 40px rgba(13, 17, 28, 0.24);
}

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

html {
  scroll-behavior: smooth;
  font-size: 18px;
}

body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-serif);
  line-height: 1.72;
  -webkit-font-smoothing: antialiased;
}

a {
  color: #0f766e;
  text-decoration: none;
  border-bottom: 1px solid rgba(15, 118, 110, 0.3);
  transition: color 0.15s ease, border-color 0.15s ease;
}

a:hover {
  color: #0d9488;
  border-bottom-color: #0d9488;
}

/* ==========================================================================
   Top Navigation Bar
   ========================================================================== */

.book-nav {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(250, 248, 244, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  font-family: var(--font-sans);
}

.book-nav-inner {
  max-width: var(--wide-width);
  margin: 0 auto;
  padding: 0.7rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.book-brand {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 700;
  font-size: 0.9rem;
  letter-spacing: 0.01em;
  color: var(--ink);
  border-bottom: none;
}

.book-brand:hover {
  color: #0f766e;
}

.book-brand-mark {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  background: var(--bg-canvas);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.nav-chapter-label {
  font-size: 0.82rem;
  color: var(--ink-muted);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.nav-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.38rem 0.75rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ink);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.nav-btn:hover {
  border-color: var(--border-strong);
  background: var(--bg-subtle);
  color: var(--ink);
}

.nav-progress {
  height: 3px;
  background: var(--border);
  width: 100%;
  overflow: hidden;
}

.nav-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--teal), var(--amber), var(--violet));
  transition: width 0.3s ease;
}

/* ==========================================================================
   Chapter Layout & Editorial Typography
   ========================================================================== */

.chapter-wrapper {
  max-width: var(--content-width);
  margin: 0 auto;
  padding: 3rem 1.4rem 5rem;
}

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

.chapter-kicker {
  font-family: var(--font-sans);
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: #0f766e;
  margin-bottom: 0.6rem;
}

.chapter-title {
  font-family: var(--font-serif);
  font-size: clamp(2rem, 4vw, 2.75rem);
  line-height: 1.15;
  font-weight: 700;
  margin: 0 0 0.85rem;
  color: var(--ink);
  letter-spacing: -0.02em;
}

.chapter-subtitle {
  font-size: 1.15rem;
  color: var(--ink-muted);
  margin: 0;
  font-style: italic;
  line-height: 1.55;
}

h2 {
  font-family: var(--font-serif);
  font-size: 1.55rem;
  line-height: 1.28;
  margin: 2.75rem 0 0.85rem;
  color: var(--ink);
  letter-spacing: -0.01em;
}

h3 {
  font-family: var(--font-sans);
  font-size: 1.02rem;
  font-weight: 700;
  margin: 1.8rem 0 0.5rem;
  color: var(--ink);
}

p {
  margin: 0 0 1.25rem;
}

.lead {
  font-size: 1.12rem;
  color: var(--ink);
}

/* Inline color badges matching canvas vectors */
.tag {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-family: var(--font-sans);
  font-size: 0.82em;
  font-weight: 700;
  padding: 0.08rem 0.5rem;
  border-radius: 999px;
  vertical-align: baseline;
  white-space: nowrap;
}

.tag-teal { background: var(--teal-soft); color: #0f766e; }
.tag-amber { background: var(--amber-soft); color: #b45309; }
.tag-violet { background: var(--violet-soft); color: #6d28d9; }
.tag-coral { background: var(--coral-soft); color: #be123c; }
.tag-gold { background: rgba(251, 191, 36, 0.22); color: #92400e; }
.tag-sky { background: rgba(56, 189, 248, 0.18); color: #0369a1; }

/* Callout / Principle Cards */
.principle-box {
  margin: 2rem 0;
  padding: 1.35rem 1.5rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-left: 4px solid var(--teal);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
}

.principle-box.amber { border-left-color: var(--amber); }
.principle-box.violet { border-left-color: var(--violet); }
.principle-box.coral { border-left-color: var(--coral); }

.principle-label {
  font-family: var(--font-sans);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.11em;
  color: var(--ink-muted);
  margin-bottom: 0.4rem;
}

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

/* ==========================================================================
   Interactive Lab Figure
   ========================================================================== */

.lab {
  margin: 2.25rem -2.5rem;
  background: var(--bg-canvas);
  color: #e6ebf5;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-canvas);
  font-family: var(--font-sans);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

@media (max-width: 900px) {
  .lab {
    margin: 2rem -0.5rem;
  }
}

.lab-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  padding: 0.9rem 1.2rem;
  background: var(--bg-canvas-panel);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.lab-title {
  font-size: 0.88rem;
  font-weight: 700;
  color: #f8fafc;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.lab-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--teal);
  box-shadow: 0 0 10px var(--teal);
}

.lab-hint {
  font-size: 0.78rem;
  color: #94a3b8;
}

.lab-canvas-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 10;
  min-height: 320px;
  max-height: 500px;
  background: radial-gradient(circle at 50% 50%, #192033 0%, #10141f 100%);
  touch-action: none;
  user-select: none;
}

.lab-canvas-wrap canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
}

.lab-canvas-wrap canvas:active {
  cursor: grabbing;
}

.lab-readout {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
  padding: 0.85rem 1.2rem;
  background: rgba(15, 20, 32, 0.85);
  border-top: 1px solid rgba(255, 255, 255, 0.07);
  font-size: 0.82rem;
  color: #cbd5e1;
  align-items: center;
}

.readout-item {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}

.readout-swatch {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex-shrink: 0;
}

.readout-value {
  font-weight: 700;
  color: #f8fafc;
}

.lab-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  padding: 0.9rem 1.2rem;
  background: var(--bg-canvas-panel);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.lab-btn {
  appearance: none;
  background: rgba(255, 255, 255, 0.07);
  color: #e2e8f0;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  padding: 0.4rem 0.85rem;
  font-family: var(--font-sans);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.lab-btn:hover {
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.28);
  color: #ffffff;
}

.lab-btn.active {
  background: var(--teal);
  color: #071917;
  border-color: var(--teal);
}

.lab-btn.amber.active {
  background: var(--amber);
  color: #1f1402;
  border-color: var(--amber);
}

.lab-btn.violet.active {
  background: var(--violet);
  color: #ffffff;
  border-color: var(--violet);
}

.lab-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.lab-slider-group {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  font-size: 0.78rem;
  color: #cbd5e1;
  background: rgba(255, 255, 255, 0.05);
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

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

.lab-spacer {
  flex: 1;
}

.lab-caption {
  padding: 0.75rem 1.2rem;
  background: #141926;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  font-size: 0.82rem;
  color: #94a3b8;
  line-height: 1.5;
}

/* ==========================================================================
   Intuition Check (Visual Self-Check Widget)
   ========================================================================== */

.intuition-check {
  margin: 2.5rem 0;
  padding: 1.4rem 1.5rem;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font-sans);
}

.intuition-check-kicker {
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #6d28d9;
  margin-bottom: 0.35rem;
}

.intuition-check-q {
  font-family: var(--font-serif);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--ink);
  margin: 0 0 1rem;
}

.intuition-options {
  display: grid;
  gap: 0.55rem;
}

.intuition-opt {
  text-align: left;
  padding: 0.75rem 1rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-size: 0.88rem;
  color: var(--ink);
  cursor: pointer;
  transition: all 0.15s ease;
}

.intuition-opt:hover {
  border-color: var(--violet);
  background: #fdfcff;
}

.intuition-opt.correct {
  border-color: #0d9488;
  background: #f0fdfa;
  color: #115e59;
  font-weight: 600;
}

.intuition-opt.wrong {
  border-color: #e11d48;
  background: #fff1f2;
  color: #9f1239;
}

.intuition-feedback {
  margin-top: 0.85rem;
  font-size: 0.88rem;
  line-height: 1.55;
  color: var(--ink-muted);
  display: none;
}

.intuition-feedback.visible {
  display: block;
}

/* ==========================================================================
   Chapter Footer Navigation
   ========================================================================== */

.chapter-footer {
  margin-top: 4rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  font-family: var(--font-sans);
}

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

.footer-card {
  display: flex;
  flex-direction: column;
  padding: 1.1rem 1.25rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--ink);
  transition: all 0.15s ease;
}

.footer-card:hover {
  border-color: var(--teal);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
  color: var(--ink);
}

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

.footer-card-dir {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-faint);
  font-weight: 700;
  margin-bottom: 0.25rem;
}

.footer-card-title {
  font-size: 0.96rem;
  font-weight: 700;
  color: var(--ink);
}

/* ==========================================================================
   Landing Page (index.html)
   ========================================================================== */

.hero {
  background: var(--bg-canvas);
  color: #f8fafc;
  position: relative;
  overflow: hidden;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.hero-inner {
  max-width: var(--wide-width);
  margin: 0 auto;
  padding: 3.5rem 1.4rem 4rem;
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 2.5rem;
  align-items: center;
}

@media (max-width: 820px) {
  .hero-inner {
    grid-template-columns: 1fr;
    padding: 2.5rem 1.25rem 3rem;
  }
}

.hero-kicker {
  font-family: var(--font-sans);
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--teal);
  margin-bottom: 0.8rem;
}

.hero-title {
  font-family: var(--font-serif);
  font-size: clamp(2.2rem, 4.5vw, 3.35rem);
  line-height: 1.1;
  margin: 0 0 1rem;
  letter-spacing: -0.02em;
}

.hero-desc {
  font-size: 1.05rem;
  color: #cbd5e1;
  line-height: 1.65;
  margin: 0 0 1.8rem;
}

.hero-cta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  font-family: var(--font-sans);
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--teal);
  color: #05221e;
  font-weight: 700;
  font-size: 0.92rem;
  padding: 0.75rem 1.35rem;
  border-radius: 999px;
  border: none;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease;
}

.btn-primary:hover {
  background: #2dd4bf;
  color: #05221e;
  transform: translateY(-1px);
  border-bottom: none;
}

.btn-ghost {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(255, 255, 255, 0.07);
  color: #e2e8f0;
  font-weight: 600;
  font-size: 0.9rem;
  padding: 0.75rem 1.25rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.18);
}

.btn-ghost:hover {
  background: rgba(255, 255, 255, 0.14);
  color: #ffffff;
  border-bottom-color: rgba(255, 255, 255, 0.25);
}

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

.hero-canvas-box {
  width: 100%;
  aspect-ratio: 4 / 3;
  position: relative;
}

.hero-canvas-box canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.hero-canvas-bar {
  padding: 0.65rem 1rem;
  background: var(--bg-canvas-panel);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  font-family: var(--font-sans);
  font-size: 0.75rem;
  color: #94a3b8;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* Table of Contents */
.toc-section {
  max-width: var(--wide-width);
  margin: 0 auto;
  padding: 3.5rem 1.4rem 5rem;
}

.manifesto-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 1.25rem;
  margin-bottom: 3.5rem;
}

.manifesto-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1.25rem 1.35rem;
  box-shadow: var(--shadow-sm);
}

.manifesto-card h3 {
  margin-top: 0;
  color: var(--ink);
}

.manifesto-card p {
  font-size: 0.92rem;
  color: var(--ink-muted);
  margin-bottom: 0;
  line-height: 1.55;
}

.part-group {
  margin-bottom: 2.75rem;
}

.part-heading {
  font-family: var(--font-sans);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: #0f766e;
  margin: 0 0 1rem;
  padding-bottom: 0.45rem;
  border-bottom: 1px solid var(--border);
}

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

.chapter-card {
  display: flex;
  flex-direction: column;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1.2rem 1.3rem;
  color: var(--ink);
  transition: all 0.18s ease;
  box-shadow: var(--shadow-sm);
}

.chapter-card:hover {
  border-color: var(--teal);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  color: var(--ink);
}

.chapter-card-kicker {
  font-family: var(--font-sans);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-faint);
  margin-bottom: 0.35rem;
}

.chapter-card-title {
  font-family: var(--font-serif);
  font-size: 1.15rem;
  font-weight: 700;
  margin: 0 0 0.45rem;
  line-height: 1.25;
}

.chapter-card-desc {
  font-family: var(--font-sans);
  font-size: 0.84rem;
  color: var(--ink-muted);
  line-height: 1.5;
  margin: 0;
}

.site-footer {
  border-top: 1px solid var(--border);
  padding: 2rem 1.4rem;
  text-align: center;
  font-family: var(--font-sans);
  font-size: 0.82rem;
  color: var(--ink-faint);
}
