/* ==========================================================================
   THE SHAPE OF CHANCE — A Visual, Number-Free Interactive Book on Probability
   Shared Editorial Design System
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Fraunces:ital,opsz,wght@0,9..144,400;0,9..144,600;0,9..144,700;1,9..144,400&family=Plus+Jakarta+Sans:wght@400;500;600;700&display=swap');

:root {
  /* Warm Editorial Light Palette */
  --bg: #FAF7F2;
  --bg-subtle: #F2ECE1;
  --surface: #FFFFFF;
  --surface-elevated: #FFFDF9;
  --ink: #1F1D1A;
  --ink-soft: #4A463F;
  --muted: #7A7368;
  --border: #E5DDD0;
  --border-strong: #CFC4B2;

  /* Semantic Visual Palette (for interactive figures & callouts) */
  --terracotta: #D15A3B;
  --terracotta-soft: rgba(209, 90, 59, 0.14);
  --teal: #1E6B7B;
  --teal-soft: rgba(30, 107, 123, 0.14);
  --ochre: #C98A1C;
  --ochre-soft: rgba(201, 138, 28, 0.16);
  --sage: #447A57;
  --sage-soft: rgba(68, 122, 87, 0.14);
  --plum: #7A4B7B;
  --plum-soft: rgba(122, 75, 123, 0.14);

  /* Typography */
  --font-serif: 'Fraunces', Georgia, 'Times New Roman', serif;
  --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

  /* Layout */
  --sidebar-width: 280px;
  --content-max: 740px;
  --widget-max: 860px;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --shadow-sm: 0 2px 8px rgba(31, 29, 26, 0.05);
  --shadow-md: 0 10px 30px rgba(31, 29, 26, 0.08);
  --transition: 0.22s cubic-bezier(0.25, 0.8, 0.25, 1);
}

[data-theme="dark"] {
  --bg: #141517;
  --bg-subtle: #1B1D21;
  --surface: #1F2227;
  --surface-elevated: #262A31;
  --ink: #F2EFE9;
  --ink-soft: #C9C3B8;
  --muted: #8E897F;
  --border: #2E323A;
  --border-strong: #414752;

  --terracotta: #EA7A5C;
  --terracotta-soft: rgba(234, 122, 92, 0.2);
  --teal: #49A8BC;
  --teal-soft: rgba(73, 168, 188, 0.2);
  --ochre: #E6AE45;
  --ochre-soft: rgba(230, 174, 69, 0.2);
  --sage: #6BB384;
  --sage-soft: rgba(107, 179, 132, 0.2);
  --plum: #B884BA;
  --plum-soft: rgba(184, 132, 186, 0.2);

  --shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.28);
  --shadow-md: 0 12px 36px rgba(0, 0, 0, 0.42);
}

/* Reset & Base */
*, *::before, *::after {
  box-sizing: border-box;
}

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

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

a {
  color: var(--teal);
  text-decoration: none;
  transition: color var(--transition);
}

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

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

/* Shell Layout (Chapters) */
.book-shell {
  display: flex;
  min-height: 100vh;
}

/* Sidebar Navigation */
.book-sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--bg-subtle);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 200;
  transition: transform var(--transition), background-color var(--transition), border-color var(--transition);
}

.sidebar-brand {
  padding: 1.5rem 1.4rem 1.1rem;
  border-bottom: 1px solid var(--border);
}

.sidebar-brand a {
  display: block;
  color: var(--ink);
}

.sidebar-brand .book-kicker {
  font-size: 0.7rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--terracotta);
  font-weight: 700;
  display: block;
  margin-bottom: 0.25rem;
}

.sidebar-brand .book-title {
  font-family: var(--font-serif);
  font-size: 1.2rem;
  font-weight: 700;
  line-height: 1.2;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 0.9rem 0.75rem;
}

.sidebar-nav ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.58rem 0.75rem;
  border-radius: var(--radius-sm);
  color: var(--ink-soft);
  font-size: 0.88rem;
  font-weight: 500;
  line-height: 1.3;
  transition: background-color var(--transition), color var(--transition);
}

.sidebar-link:hover {
  background: var(--surface);
  color: var(--ink);
}

.sidebar-link.active {
  background: var(--surface);
  color: var(--ink);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
  border-left: 3px solid var(--terracotta);
}

.sidebar-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  flex-shrink: 0;
  transition: all var(--transition);
}

.sidebar-link.active .sidebar-dot {
  border-color: var(--terracotta);
  background: var(--terracotta);
}

.sidebar-link.completed .sidebar-dot {
  border-color: var(--sage);
  background: var(--sage);
}

.sidebar-footer {
  padding: 0.9rem 1.2rem;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.42rem 0.8rem;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
}

.theme-toggle:hover {
  border-color: var(--terracotta);
  color: var(--terracotta);
}

/* Mobile Header Bar */
.mobile-topbar {
  display: none;
  position: sticky;
  top: 0;
  z-index: 150;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1.1rem;
  align-items: center;
  justify-content: space-between;
}

.menu-btn {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--ink);
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.75rem;
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

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

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

/* Main Content Area */
.book-main {
  flex: 1;
  margin-left: var(--sidebar-width);
  padding: 3.5rem 2.2rem 5rem;
  min-width: 0;
}

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

/* Prose Column */
.prose {
  max-width: var(--content-max);
  margin-left: auto;
  margin-right: auto;
}

.chapter-header {
  max-width: var(--content-max);
  margin: 0 auto 2.8rem;
  padding-bottom: 1.8rem;
  border-bottom: 1px solid var(--border);
}

.chapter-label {
  display: inline-block;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--terracotta);
  margin-bottom: 0.6rem;
}

.chapter-header h1 {
  font-family: var(--font-serif);
  font-size: clamp(2.1rem, 4.5vw, 3.1rem);
  font-weight: 700;
  line-height: 1.12;
  margin: 0 0 1rem;
  letter-spacing: -0.02em;
}

.chapter-lead {
  font-family: var(--font-serif);
  font-size: 1.24rem;
  font-style: italic;
  color: var(--ink-soft);
  margin: 0;
  line-height: 1.55;
}

h2 {
  font-family: var(--font-serif);
  font-size: 1.72rem;
  font-weight: 600;
  line-height: 1.25;
  margin: 2.8rem 0 0.9rem;
  letter-spacing: -0.015em;
  color: var(--ink);
}

h3 {
  font-family: var(--font-serif);
  font-size: 1.25rem;
  font-weight: 600;
  margin: 2rem 0 0.6rem;
  color: var(--ink);
}

p {
  margin: 0 0 1.2rem;
  color: var(--ink-soft);
}

strong {
  color: var(--ink);
  font-weight: 600;
}

/* Principle & Intuition Callout Boxes */
.principle-box {
  max-width: var(--content-max);
  margin: 2rem auto;
  padding: 1.35rem 1.55rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--terracotta);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  box-shadow: var(--shadow-sm);
}

.principle-box.teal {
  border-left-color: var(--teal);
}

.principle-box.sage {
  border-left-color: var(--sage);
}

.principle-box.ochre {
  border-left-color: var(--ochre);
}

.principle-box .box-title {
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--terracotta);
  margin-bottom: 0.45rem;
  display: block;
}

.principle-box.teal .box-title { color: var(--teal); }
.principle-box.sage .box-title { color: var(--sage); }
.principle-box.ochre .box-title { color: var(--ochre); }

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

/* Interactive Widget Card */
.widget-card {
  margin: 2.4rem auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  transition: background-color var(--transition), border-color var(--transition);
}

.widget-header {
  padding: 1.15rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-subtle);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.widget-title-group {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.widget-kicker {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--teal);
}

.widget-title {
  font-family: var(--font-serif);
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--ink);
  margin: 0;
}

.widget-canvas-wrap {
  position: relative;
  width: 100%;
  background: var(--surface-elevated);
  padding: 1rem;
}

.widget-canvas-wrap canvas,
.widget-canvas-wrap svg {
  display: block;
  width: 100%;
  border-radius: var(--radius-sm);
}

.widget-controls {
  padding: 1.15rem 1.5rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem 1.5rem;
  background: var(--surface);
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 170px;
  flex: 1;
}

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

.control-poles {
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
  color: var(--muted);
}

.widget-caption {
  padding: 0.85rem 1.5rem 1.1rem;
  font-size: 0.88rem;
  color: var(--ink-soft);
  border-top: 1px dashed var(--border);
  background: var(--bg-subtle);
}

.widget-caption strong {
  color: var(--ink);
}

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

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--terracotta);
  border: 2.5px solid var(--surface);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.22);
  cursor: pointer;
  transition: transform 0.12s ease;
}

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

input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--terracotta);
  border: 2.5px solid var(--surface);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.22);
  cursor: pointer;
}

/* Buttons & Pills */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.52rem 1.05rem;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
}

.btn:hover {
  border-color: var(--ink);
  transform: translateY(-1px);
}

.btn.primary {
  background: var(--terracotta);
  border-color: var(--terracotta);
  color: #FFFFFF;
}

.btn.primary:hover {
  filter: brightness(1.06);
}

.btn.teal {
  background: var(--teal);
  border-color: var(--teal);
  color: #FFFFFF;
}

.btn.active {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--bg);
}

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

/* Visual Legend Dots */
.legend-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  font-size: 0.82rem;
  color: var(--ink-soft);
  align-items: center;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.legend-swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  display: inline-block;
}

/* Interactive Intuition Check (Visual Quiz) */
.intuition-check {
  max-width: var(--content-max);
  margin: 2.6rem auto;
  padding: 1.5rem 1.65rem;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.intuition-check .check-kicker {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--sage);
  margin-bottom: 0.4rem;
  display: block;
}

.intuition-check h3 {
  margin-top: 0;
  margin-bottom: 0.75rem;
}

.check-options {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  margin-top: 1rem;
}

.check-option {
  text-align: left;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 0.92rem;
  cursor: pointer;
  transition: all var(--transition);
}

.check-option:hover {
  border-color: var(--teal);
}

.check-option.correct {
  border-color: var(--sage);
  background: var(--sage-soft);
  font-weight: 600;
}

.check-option.incorrect {
  border-color: var(--terracotta);
  background: var(--terracotta-soft);
}

.check-feedback {
  margin-top: 0.9rem;
  font-size: 0.9rem;
  color: var(--ink-soft);
  min-height: 1.2em;
}

/* Chapter Footer Navigation */
.chapter-footer-nav {
  max-width: var(--content-max);
  margin: 4rem auto 0;
  padding-top: 2rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.nav-card {
  flex: 1;
  min-width: 220px;
  padding: 1.1rem 1.3rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  transition: all var(--transition);
}

.nav-card:hover {
  border-color: var(--terracotta);
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
  color: var(--ink);
}

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

.nav-card-dir {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.nav-card-title {
  font-family: var(--font-serif);
  font-size: 1.08rem;
  font-weight: 600;
}

/* ==========================================================================
   COVER / LANDING PAGE (index.html)
   ========================================================================== */
.cover-page {
  min-height: 100vh;
}

.cover-topbar {
  max-width: 1120px;
  margin: 0 auto;
  padding: 1.4rem 1.8rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.cover-hero {
  max-width: 1120px;
  margin: 0 auto;
  padding: 1.5rem 1.8rem 3.5rem;
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 3rem;
  align-items: center;
}

.cover-kicker {
  display: inline-block;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--terracotta);
  margin-bottom: 0.9rem;
}

.cover-hero h1 {
  font-family: var(--font-serif);
  font-size: clamp(2.6rem, 5.4vw, 4.1rem);
  line-height: 1.06;
  margin: 0 0 1.25rem;
  letter-spacing: -0.025em;
}

.cover-subtitle {
  font-size: 1.12rem;
  color: var(--ink-soft);
  margin: 0 0 2rem;
  max-width: 540px;
}

.cover-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.85rem;
  align-items: center;
}

.cover-cta {
  padding: 0.85rem 1.7rem;
  font-size: 0.96rem;
}

.cover-canvas-frame {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem;
  box-shadow: var(--shadow-md);
}

.cover-canvas-caption {
  font-size: 0.78rem;
  color: var(--muted);
  text-align: center;
  margin-top: 0.65rem;
}

.toc-section {
  max-width: 1120px;
  margin: 0 auto;
  padding: 2rem 1.8rem 5rem;
}

.toc-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-end;
  gap: 1rem;
  margin-bottom: 2rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.toc-header h2 {
  margin: 0;
}

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

.toc-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1.4rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  color: var(--ink);
  transition: all var(--transition);
  position: relative;
}

.toc-card:hover {
  border-color: var(--terracotta);
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
  color: var(--ink);
}

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

.toc-chapter-word {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--terracotta);
}

.toc-status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
}

.toc-card.completed .toc-status-dot {
  background: var(--sage);
  border-color: var(--sage);
}

.toc-card h3 {
  margin: 0;
  font-size: 1.22rem;
}

.toc-card p {
  margin: 0;
  font-size: 0.88rem;
  color: var(--ink-soft);
  line-height: 1.55;
}

.toc-metaphor {
  margin-top: auto;
  padding-top: 0.7rem;
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--teal);
}

/* Responsive */
@media (max-width: 960px) {
  .book-sidebar {
    transform: translateX(-100%);
  }
  .book-sidebar.open {
    transform: translateX(0);
  }
  .mobile-topbar {
    display: flex;
  }
  .book-main {
    margin-left: 0;
    padding: 2rem 1.25rem 4rem;
  }
  .cover-hero {
    grid-template-columns: 1fr;
    gap: 2rem;
  }
}
