/* ============================================================
   A Map of Mathematics — shared stylesheet (map + 13 chapters)
   Union of the map's inline styles + categoryTheory chapter
   patterns, reconciled. Every code surface is LIGHT.
   ============================================================ */

/* === TOKENS === */
:root {
  --bg: #FAFAF8;
  --bg-card: #FFFFFF;
  --bg-sunken: #F4F3F9;
  --text: #1A1A2E;
  --text-muted: #5C5C7A;

  /* Neutral primary (header, wordmark, focus rings) */
  --accent:        #3D4252;   /* slate ink */
  --accent-light:  #ECEDF0;
  --accent-dark:   #2C3140;

  /* Secondary accent (terracotta) */
  --accent-secondary:       #B5775B;
  --accent-secondary-light: #F5E8DF;

  /* Five-theme palette */
  --theme-geometry:        #B5775B;   /* terracotta */
  --theme-geometry-light:  #F5E8DF;
  --theme-algebra:         #7C8A4A;   /* olive */
  --theme-algebra-light:   #EFF1DC;
  --theme-analysis:        #4C6B8A;   /* slate-blue */
  --theme-analysis-light:  #DBE5F0;
  --theme-logic:           #8A5B7C;   /* plum */
  --theme-logic-light:     #EDDCE5;
  --theme-applied:         #B89548;   /* ochre */
  --theme-applied-light:   #F5ECCC;

  /* Status tokens */
  --ok: #2D7D46;   --ok-light: #E8F5EC;
  --err: #DC2626;  --err-light: #FEE8E8;
  --warn: #D97706; --warn-light: #FDF1E0;

  /* LIGHT code theme — every code surface uses these */
  --code-bg: #EEF2F5;
  --code-bg-soft: #E1E7EC;
  --code-border: #D3DAE0;
  --code-fg: #1F2533;
  --code-cm: #7A8590;
  --code-kw: #9C2D6E;
  --code-ty: #2D6E78;
  --code-fn: #2F5FA3;
  --code-op: #B5552A;
  --code-st: #3B7A4B;

  --grid-line: rgba(60, 65, 80, 0.05);
  --border: #E5E3EC;
  --shadow: rgba(40, 30, 90, 0.07);
  --radius: 0.75rem;
  --mono: 'SF Mono', 'JetBrains Mono', 'Fira Code', ui-monospace, Menlo, Consolas, monospace;
}

/* === RESET === */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* === LAYOUT === */
.container { max-width: 1040px; margin: 0 auto; padding: 0 1.5rem; }
.wide { max-width: 1040px; }

/* === HEADER === */
header {
  position: sticky; top: 0; z-index: 100;
  background: rgba(250, 250, 248, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid transparent;
  transition: border-color 0.3s, box-shadow 0.3s;
}
header.scrolled {
  border-bottom-color: var(--border);
  box-shadow: 0 1px 8px var(--shadow);
}
header .container {
  display: flex; align-items: center; justify-content: space-between;
  height: 56px; max-width: 1040px;
}
.wordmark {
  display: flex; align-items: center; gap: 0.5rem;
  font-weight: 600; font-size: 0.95rem; color: var(--text);
}
.wordmark:hover { text-decoration: none; }
.wordmark .mk {
  width: 26px; height: 26px; border-radius: 7px;
  background: var(--accent); color: #fff;
  display: grid; place-items: center;
  font-family: var(--mono); font-weight: 700; font-size: 0.95rem;
}
.wordmark .mk svg { width: 16px; height: 16px; }
.wordmark span { opacity: 0.5; font-weight: 400; }
header nav { display: flex; gap: 1.2rem; }
header nav a {
  font-size: 0.85rem; color: var(--text-muted);
  transition: color 0.2s;
}
header nav a:hover { color: var(--accent); text-decoration: none; }
/* scroll progress */
.progress {
  position: absolute; left: 0; bottom: -1px; height: 2px;
  background: var(--accent); width: 0%;
  transition: width 0.1s linear;
}

/* === CHAPTER STRIP === */
.ch-strip {
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.ch-strip::-webkit-scrollbar { display: none; }
.ch-strip .container {
  display: flex; align-items: center; gap: 0.4rem;
  padding-top: 0.55rem; padding-bottom: 0.55rem;
  max-width: 1040px;
}
.ch-pill {
  flex-shrink: 0;
  display: inline-flex; align-items: center; gap: 0.45rem;
  font-size: 0.78rem; color: var(--text-muted);
  padding: 0.32rem 0.7rem; border-radius: 999px;
  border: 1px solid var(--border); background: var(--bg-card);
  transition: all 0.15s ease-out;
  text-decoration: none;
  white-space: nowrap;
}
.ch-pill:hover { color: var(--accent-dark); border-color: var(--accent); text-decoration: none; }
.ch-pill .ch-num {
  font-family: var(--mono); font-weight: 700; font-size: 0.7rem;
  color: var(--accent);
}
.ch-pill .ch-name { font-weight: 500; }
.ch-pill.current {
  background: var(--accent); color: #fff;
  border-color: var(--accent);
}
.ch-pill.current .ch-num { color: rgba(255,255,255,0.75); }
.ch-pill.current:hover { color: #fff; background: var(--accent-dark); border-color: var(--accent-dark); }
.ch-divider {
  width: 12px; height: 1px; background: var(--border); flex-shrink: 0;
}
@media (max-width: 767px) {
  .ch-pill .ch-name { display: none; }
  .ch-pill { padding: 0.28rem 0.5rem; }
  .ch-divider { width: 6px; }
}

/* === HERO === */
.hero {
  padding: 4.5rem 0 3rem;
  text-align: center;
  position: relative;
  overflow: hidden;
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 28px 28px;
}
.hero::after {
  content: '';
  position: absolute; bottom: 0; left: 0; right: 0; height: 80px;
  background: linear-gradient(transparent, var(--bg));
  pointer-events: none;
}
.eyebrow {
  display: inline-flex; align-items: center; gap: 0.5rem;
  font-size: 0.72rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.12em;
  color: var(--accent-dark);
  background: var(--accent-light);
  padding: 0.35rem 0.8rem; border-radius: 999px;
  margin-bottom: 1.25rem;
  animation: fadeUp 0.6s ease-out both;
}
.hero-title {
  font-family: 'Fraunces', Georgia, serif;
  font-size: 3rem; font-weight: 600;
  letter-spacing: -0.02em; line-height: 1.1;
  margin-bottom: 0.85rem;
  animation: fadeUp 0.6s ease-out 0.08s both;
}
.hero-title em { font-style: italic; color: var(--accent); }
.hero-subtitle {
  font-size: 1.15rem; color: var(--text-muted);
  max-width: 620px; margin: 0 auto 2rem;
  animation: fadeUp 0.6s ease-out 0.16s both;
}
.hero-arrows { animation: fadeUp 0.6s ease-out 0.28s both; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* === SECTIONS === */
section.lesson { padding: 1rem 0; }
.block { margin: 2.75rem 0; }
h2.sec {
  font-family: 'Fraunces', Georgia, serif;
  font-size: 1.7rem; font-weight: 600; letter-spacing: -0.01em;
  margin-bottom: 0.4rem;
  scroll-margin-top: 72px;
}
h2.sec .num {
  font-family: var(--mono); font-size: 0.95rem; font-weight: 500;
  color: var(--accent); margin-right: 0.5rem;
  vertical-align: 0.12em;
}
h3.sub { font-size: 1.1rem; font-weight: 600; margin: 1.5rem 0 0.5rem; }
p.lead { font-size: 1.05rem; color: var(--text-muted); margin-bottom: 1rem; }
.prose p { margin-bottom: 0.9rem; }
.prose ul { margin: 0.4rem 0 1rem 1.3rem; }
.prose li { margin-bottom: 0.35rem; }

/* inline math-ish */
.m {
  font-family: var(--mono); font-size: 0.92em;
  background: var(--bg-sunken);
  padding: 0.08em 0.38em; border-radius: 4px;
  white-space: nowrap;
}
.m.obj { color: var(--accent-secondary); background: var(--accent-secondary-light); }
.m.mor { color: var(--accent-dark); background: var(--accent-light); }

/* === CALLOUT === */
.callout {
  display: flex; gap: 0.85rem;
  background: var(--accent-light);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
  margin: 1.5rem 0;
  font-size: 0.95rem;
}
.callout .ic { font-size: 1.2rem; flex-shrink: 0; line-height: 1.5; }
.callout.warn { background: var(--warn-light); border-color: #f3dcb6; border-left-color: var(--warn); }
.callout strong { color: var(--accent-dark); }
.callout.warn strong { color: var(--warn); }

/* === FIGURE / WIDGET === */
.widget {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin: 1.5rem 0;
  box-shadow: 0 1px 3px var(--shadow);
}
.widget-head {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 0.6rem;
  margin-bottom: 0.5rem;
}
.widget-title {
  font-size: 0.78rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-muted);
  display: flex; align-items: center; gap: 0.45rem;
}
.widget-title .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.hint { font-size: 0.8rem; color: var(--text-muted); }

svg.diagram { width: 100%; height: auto; display: block; touch-action: none; user-select: none; }
.diagram-wrap { background: var(--bg-sunken); border-radius: 0.5rem; padding: 0.5rem; }

/* === BUTTONS / CONTROLS === */
.controls { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.85rem; align-items: center; }
.btn {
  font: inherit; font-size: 0.85rem; font-weight: 500;
  border: 1px solid var(--border); background: var(--bg-card);
  color: var(--text); border-radius: 8px;
  padding: 0.45rem 0.85rem; cursor: pointer;
  transition: all 0.15s ease-out;
  display: inline-flex; align-items: center; gap: 0.4rem;
}
.btn:hover { border-color: var(--accent); color: var(--accent-dark); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover { background: var(--accent-dark); color: #fff; }
.btn.active { background: var(--accent-light); border-color: var(--accent); color: var(--accent-dark); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.readout {
  font-family: var(--mono); font-size: 0.85rem;
  color: var(--text-muted); margin-left: auto;
}
select.pick {
  font: inherit; font-family: var(--mono); font-size: 0.85rem;
  padding: 0.3rem 0.5rem; border-radius: 6px;
  border: 1px solid var(--border); background: var(--bg-card); color: var(--text);
  cursor: pointer;
  max-width: 100%; min-width: 0;
}

/* === CODE / LANGUAGE TOGGLE (LIGHT theme) === */
.code-card { border: 1px solid var(--code-border); border-radius: var(--radius); overflow: hidden; margin: 1.5rem 0; }
.code-tabs { display: flex; background: var(--code-bg-soft); border-bottom: 1px solid var(--code-border); }
.code-tab {
  font: inherit; font-size: 0.82rem; font-weight: 500;
  font-family: var(--mono);
  color: var(--text-muted); background: transparent; border: none;
  padding: 0.6rem 1.05rem; cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}
.code-tab:hover { color: var(--accent-dark); }
.code-tab.active { color: var(--accent-dark); border-bottom-color: var(--accent); }
.code-tab .lang-ic { opacity: 0.9; margin-right: 0.4rem; }
pre.code {
  margin: 0; padding: 1.1rem 1.2rem;
  background: var(--code-bg); color: var(--code-fg);
  font-family: var(--mono); font-size: 0.84rem; line-height: 1.7;
  overflow-x: auto;
}
pre.code .cm { color: var(--code-cm); font-style: italic; } /* comment */
pre.code .kw { color: var(--code-kw); }                     /* keyword */
pre.code .ty { color: var(--code-ty); }                     /* type */
pre.code .fn { color: var(--code-fn); }                     /* function/value name */
pre.code .op { color: var(--code-op); }                     /* operator */
pre.code .st { color: var(--code-st); }                     /* string/literal */
.code-pane { display: none; }
.code-pane.active { display: block; }

/* === QUIZ === */
.quiz-q { margin-bottom: 1.4rem; }
.quiz-q:last-child { margin-bottom: 0; }
.quiz-q .q { font-weight: 600; margin-bottom: 0.6rem; }
.quiz-q .q .qn {
  font-family: var(--mono); color: var(--accent); font-size: 0.85rem; margin-right: 0.4rem;
}
.opt {
  display: block; width: 100%; text-align: left;
  font: inherit; font-size: 0.92rem;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 8px; padding: 0.6rem 0.85rem; margin-bottom: 0.5rem;
  cursor: pointer; transition: all 0.12s ease-out;
  display: flex; align-items: center; gap: 0.6rem;
}
.opt:hover:not(.locked) { border-color: var(--accent); background: var(--accent-light); }
.opt .mark { width: 18px; flex-shrink: 0; font-weight: 700; }
.opt.correct { border-color: var(--ok); background: var(--ok-light); color: #1b5e2e; }
.opt.wrong { border-color: var(--err); background: var(--err-light); color: #b91c1c; }
.opt.locked { cursor: default; }
.quiz-fb { font-size: 0.88rem; margin-top: 0.4rem; min-height: 1.2em; color: var(--text-muted); }
.quiz-fb.show.ok { color: var(--ok); }
.quiz-fb.show.no { color: var(--err); }

/* === FEEDBACK STATES === */
.ok   { color: var(--ok); }
.err  { color: var(--err); }
.warn { color: var(--warn); }

/* === NEXT-CARD === */
.next-card {
  display: flex; align-items: center; gap: 1rem;
  background: linear-gradient(135deg, var(--accent-light), var(--accent-secondary-light));
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.25rem 1.4rem; margin: 2.5rem 0 1rem;
}
.next-card .big { font-size: 1.6rem; }
.next-card .t1 { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--text-muted); font-weight: 600; }
.next-card .t2 { font-weight: 600; font-size: 1.05rem; }
.next-card .t3 { font-size: 0.88rem; color: var(--text-muted); }
.next-card .lock { margin-left: auto; font-size: 0.8rem; color: var(--text-muted); }
a.next-card { color: inherit; text-decoration: none; transition: transform 0.2s ease-out, box-shadow 0.2s ease-out; }
a.next-card:hover { transform: translateY(-2px); box-shadow: 0 6px 18px var(--shadow); text-decoration: none; }
.next-card .arrow { margin-left: auto; font-size: 1.4rem; color: var(--accent-dark); transition: transform 0.2s ease-out; }
a.next-card:hover .arrow { transform: translateX(4px); }
/* coming-soon + finale variants */
.next-card.next-soon { background: var(--bg-sunken); border-style: dashed; }
.next-card.next-soon .arrow { color: var(--text-muted); }
.next-card.finale { background: linear-gradient(135deg, var(--accent-light), var(--theme-applied-light)); }

/* === MAP NAV === */
.map-nav {
  position: relative;
  margin: 1rem auto 2rem;
}
.map-nav svg.timeline {
  width: 100%;
  height: auto;
  aspect-ratio: 1040 / 140;
  display: block;
  touch-action: none;
  cursor: default;
}
.map-pin {
  cursor: pointer;
  transition: r 0.15s, filter 0.15s;
}
.map-pin:hover {
  filter: brightness(0.85);
}
.map-nav-caption {
  text-align: center;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 0.5rem;
}
.map-tooltip {
  position: absolute;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.4rem 0.6rem;
  font-size: 0.78rem;
  box-shadow: 0 4px 12px var(--shadow);
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -100%);
  transition: opacity 0.15s;
  z-index: 10;
  white-space: nowrap;
}
.map-tooltip.show { opacity: 1; }
.map-tooltip .dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  margin-right: 0.4rem;
  vertical-align: 0.05em;
}
.map-tooltip .meta {
  color: var(--text-muted);
  font-size: 0.72rem;
  margin-left: 0.3rem;
}

/* === MAP STRIP (mobile fallback) === */
.map-strip {
  display: none;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 0.5rem 0;
}
.map-strip::-webkit-scrollbar { display: none; }
.map-strip-inner { display: flex; gap: 0.4rem; padding: 0 1rem; }
.map-strip a {
  flex-shrink: 0;
  display: inline-flex; align-items: center; gap: 0.4rem;
  font-size: 0.78rem; color: var(--text);
  padding: 0.3rem 0.65rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  text-decoration: none;
  white-space: nowrap;
}
.map-strip a .dot {
  width: 8px; height: 8px; border-radius: 50%;
}

/* === ERAS === */
.era { padding: 2rem 0; }
.era + .era { border-top: 1px solid var(--border); }
.era .era-intro { color: var(--text-muted); margin-bottom: 1.5rem; max-width: 640px; }

/* === FIELD GRID === */
.field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1.25rem;
}

/* === FIELD CARD === */
.field-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 3px solid var(--card-accent, var(--border));
  border-radius: var(--radius);
  padding: 1.25rem 1.25rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  position: relative;
  --card-accent: var(--border);
  transition: box-shadow 0.25s ease-out, transform 0.25s ease-out;
}
.field-card.flash {
  box-shadow: 0 0 0 3px var(--card-accent), 0 6px 18px var(--shadow);
}
.field-card[data-theme="geometry"] { --card-accent: var(--theme-geometry); }
.field-card[data-theme="algebra"]  { --card-accent: var(--theme-algebra); }
.field-card[data-theme="analysis"] { --card-accent: var(--theme-analysis); }
.field-card[data-theme="logic"]    { --card-accent: var(--theme-logic); }
.field-card[data-theme="applied"]  { --card-accent: var(--theme-applied); }

.field-motif {
  width: 48px; height: 48px;
  display: grid; place-items: center;
  color: var(--card-accent);
  margin-bottom: 0.25rem;
}
.field-head { display: flex; flex-direction: column; gap: 0.1rem; }
.field-name {
  font-family: 'Fraunces', Georgia, serif;
  font-size: 1.15rem; font-weight: 600;
  letter-spacing: -0.01em;
}
.field-meta { font-size: 0.78rem; color: var(--text-muted); font-family: var(--mono); }
.field-figures { font-size: 0.82rem; color: var(--text-muted); font-style: italic; }
.field-what, .field-unlocks { font-size: 0.93rem; line-height: 1.55; }
.field-what strong, .field-unlocks strong {
  font-weight: 600; color: var(--text);
}
.field-foot {
  margin-top: auto; padding-top: 0.5rem;
  display: flex; align-items: center; justify-content: flex-end;
}
.badge-deepdive {
  font-size: 0.8rem; font-weight: 500;
  color: var(--card-accent);
  text-decoration: none;
  padding: 0.3rem 0.7rem;
  border: 1px solid var(--card-accent);
  border-radius: 999px;
  background: transparent;
  transition: background 0.15s, color 0.15s;
}
.badge-deepdive:hover {
  background: var(--card-accent);
  color: #fff;
  text-decoration: none;
}
.badge-soon {
  font-size: 0.75rem; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.08em;
  padding: 0.3rem 0.7rem;
  border: 1px dashed var(--border);
  border-radius: 999px;
}

/* === FOOTER === */
footer {
  padding: 2.5rem 0; text-align: center;
  font-size: 0.8rem; color: var(--text-muted);
  border-top: 1px solid var(--border); margin-top: 1rem;
}

/* === REDUCED MOTION === */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* === RESPONSIVE === */
@media (max-width: 1023px) {
  .hero-title { font-size: 2.5rem; }
}
@media (max-width: 767px) {
  .hero { padding: 3rem 0 2rem; }
  .hero-title { font-size: 2.1rem; }
  .hero-subtitle { font-size: 1rem; }
  h2.sec { font-size: 1.4rem; }
  header nav a:not(.nav-keep) { display: none; }
  .map-nav svg.timeline { display: none; }
  .map-nav .map-nav-caption { display: none; }
  .map-strip { display: block; }
  .field-grid { grid-template-columns: 1fr; }
  .readout { margin-left: 0; width: 100%; }
}

/* === ch01 widgets === */
/* Sieve of Eratosthenes grid */
.w-sieve-grid {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 4px;
  max-width: 440px;
}
.w-sieve-cell {
  aspect-ratio: 1;
  display: grid; place-items: center;
  font-family: var(--mono); font-size: 0.8rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  user-select: none;
  transition: background 0.25s ease-out, color 0.2s, border-color 0.2s, transform 0.2s;
  position: relative;
}
.w-sieve-cell.prime { font-weight: 700; color: #fff; }
.w-sieve-cell.composite { color: var(--text-muted); opacity: 0.55; text-decoration: line-through; }
.w-sieve-cell.one { color: var(--text-muted); opacity: 0.45; }
.w-sieve-cell.sweep { transform: scale(1.12); z-index: 2; box-shadow: 0 0 0 2px var(--accent-light); }
.w-sieve-cell.picked { outline: 2px solid var(--accent); outline-offset: 1px; }
.w-sieve-factor {
  font-family: var(--mono); font-size: 0.85rem;
  margin-top: 0.6rem; color: var(--text-muted);
  min-height: 1.3em;
}
.w-sieve-factor strong { color: var(--text); }

/* Elements I.1 construction playground */
.w-construct-steps { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.6rem; }
.w-construct-step {
  font-size: 0.75rem; font-family: var(--mono);
  padding: 0.25rem 0.6rem; border-radius: 999px;
  border: 1px dashed var(--border); color: var(--text-muted);
  transition: all 0.2s ease-out;
}
.w-construct-step.done {
  border-style: solid; border-color: var(--ok);
  background: var(--ok-light); color: #1b5e2e;
}
.w-construct-sides {
  font-family: var(--mono); font-size: 0.85rem;
  margin-top: 0.5rem; color: var(--text-muted);
}
.w-construct-sides strong { color: var(--text); }
.w-construct-sides .eq { color: var(--ok); }

/* Unit circle → sine tracer */
.w-sine-readout {
  font-family: var(--mono); font-size: 0.85rem;
  color: var(--text-muted);
}
.w-sine-readout strong { color: var(--text); }

/* === per-chapter widget rules are appended below === */


/* ============ merged from ch02.widgets.css ============ */
/* ============================================================
   Chapter 2 — Naming the Unknown · widget styles
   All classes prefixed w-balance- / w-curvelab-.
   Code surfaces stay LIGHT; reduced-motion handled by shared rule.
   ============================================================ */

/* === Widget 1: the balance game === */
.w-balance-eq {
  font-family: var(--mono);
  font-size: 1.35rem;
  font-weight: 700;
  text-align: center;
  color: var(--text);
  letter-spacing: 0.02em;
  margin: 0.2rem 0 0.4rem;
  min-height: 1.6em;
}
.w-balance-eq .lhs { color: var(--theme-algebra); }
.w-balance-eq .rhs { color: var(--theme-analysis); }
.w-balance-eq .x { color: var(--accent-secondary); }
.w-balance-eq.solved {
  color: var(--ok);
  animation: w-balance-pop 0.5s ease-out;
}
@keyframes w-balance-pop {
  0%   { transform: scale(0.85); opacity: 0.4; }
  60%  { transform: scale(1.12); }
  100% { transform: scale(1); opacity: 1; }
}

.w-balance-weight {
  transition: transform 0.4s ease-out, opacity 0.4s ease-out;
}
.w-balance-weight.leaving {
  opacity: 0;
  transform: translateY(-26px) scale(0.6);
}

.w-balance-history {
  font-family: var(--mono);
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 0.6rem;
  line-height: 1.9;
  min-height: 1.4em;
  word-break: break-word;
}
.w-balance-history .step {
  display: inline-block;
  background: var(--bg-sunken);
  padding: 0.05em 0.5em;
  border-radius: 5px;
  margin: 0 0.15rem 0.3rem 0;
}
.w-balance-history .arrow { color: var(--text-muted); margin: 0 0.25rem; }
.w-balance-history .op {
  color: var(--accent-secondary);
  font-size: 0.74rem;
  margin: 0 0.15rem;
}
.w-balance-history strong { color: var(--ok); }

/* === Widget 2: curve lab === */
.w-curvelab-eq {
  font-family: var(--mono);
  font-size: 1.15rem;
  font-weight: 700;
  text-align: center;
  color: var(--text);
  margin: 0.2rem 0 0.5rem;
  min-height: 1.5em;
}
.w-curvelab-eq .co { color: var(--accent-secondary); }
.w-curvelab-eq .vr { color: var(--theme-analysis); }

.w-curvelab-sliders {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.6rem 1.1rem;
  margin-top: 0.85rem;
}
.w-curvelab-slider {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--mono);
  font-size: 0.82rem;
  color: var(--text-muted);
}
.w-curvelab-slider label {
  width: 1.2em;
  font-weight: 700;
  color: var(--accent-secondary);
  flex-shrink: 0;
}
.w-curvelab-slider input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
  cursor: pointer;
  min-width: 0;
}
.w-curvelab-slider .val {
  width: 3.4em;
  text-align: right;
  color: var(--text);
  font-weight: 600;
  flex-shrink: 0;
}
.w-curvelab-slider.hidden { display: none; }

.w-curvelab-modes { display: flex; gap: 0.4rem; }

.w-curvelab-readout {
  font-family: var(--mono);
  font-size: 0.84rem;
  color: var(--text-muted);
  margin-top: 0.6rem;
  min-height: 1.3em;
}
.w-curvelab-readout strong { color: var(--text); }
.w-curvelab-readout .root { color: var(--theme-geometry); font-weight: 700; }
.w-curvelab-readout .none { color: var(--text-muted); font-style: italic; }


/* ============ merged from ch03.widgets.css ============ */
/* ============================================================
   A Map of Mathematics — Chapter 3 widget styles
   Prefixes: w-lln-, w-tangent-, w-riemann-
   All code surfaces stay LIGHT (shared --code-* tokens).
   ============================================================ */

/* === Widget 1 — Law of Large Numbers lab === */
.w-lln-stage { background: var(--bg-sunken); border-radius: 0.5rem; padding: 0.5rem; }
.w-lln-readout {
  display: flex; flex-wrap: wrap; gap: 0.4rem 1.4rem;
  font-family: var(--mono); font-size: 0.85rem;
  color: var(--text-muted); margin-top: 0.7rem;
}
.w-lln-readout strong { color: var(--text); }
.w-lln-readout .big {
  font-size: 1.05rem; color: var(--accent-dark); font-weight: 700;
}
.w-lln-mode {
  display: inline-flex; border: 1px solid var(--border);
  border-radius: 8px; overflow: hidden;
}
.w-lln-mode button {
  font: inherit; font-size: 0.82rem; font-weight: 500;
  background: var(--bg-card); color: var(--text-muted);
  border: none; padding: 0.42rem 0.8rem; cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.w-lln-mode button + button { border-left: 1px solid var(--border); }
.w-lln-mode button.active { background: var(--accent); color: #fff; }

/* === Widget 2 — Tangent / slope explorer === */
.w-tangent-stage { background: var(--bg-sunken); border-radius: 0.5rem; padding: 0.5rem; }
.w-tangent-slider {
  display: flex; align-items: center; gap: 0.6rem;
  margin-top: 0.85rem; flex-wrap: wrap;
}
.w-tangent-slider label {
  font-family: var(--mono); font-size: 0.8rem; color: var(--text-muted);
  min-width: 4.5rem;
}
.w-tangent-slider input[type="range"] { flex: 1; min-width: 160px; accent-color: var(--accent); }
.w-tangent-readout {
  display: flex; flex-wrap: wrap; gap: 0.4rem 1.4rem;
  font-family: var(--mono); font-size: 0.85rem;
  color: var(--text-muted); margin-top: 0.7rem;
}
.w-tangent-readout strong { color: var(--text); }
.w-tangent-readout .gap { color: var(--accent-secondary); }
.w-tangent-readout .gap.tiny { color: var(--ok); }

/* === Widget 3 — Riemann area accumulator === */
.w-riemann-stage { background: var(--bg-sunken); border-radius: 0.5rem; padding: 0.5rem; }
.w-riemann-slider {
  display: flex; align-items: center; gap: 0.6rem;
  margin-top: 0.85rem; flex-wrap: wrap;
}
.w-riemann-slider label {
  font-family: var(--mono); font-size: 0.8rem; color: var(--text-muted);
  min-width: 4.5rem;
}
.w-riemann-slider input[type="range"] { flex: 1; min-width: 160px; accent-color: var(--accent); }
.w-riemann-readout {
  display: flex; flex-wrap: wrap; gap: 0.4rem 1.4rem;
  font-family: var(--mono); font-size: 0.85rem;
  color: var(--text-muted); margin-top: 0.7rem;
}
.w-riemann-readout strong { color: var(--text); }
.w-riemann-readout .err { color: var(--accent-secondary); }
.w-riemann-readout .err.tiny { color: var(--ok); }


/* ============ merged from ch04.widgets.css ============ */
/* ============================================================
   Chapter 4 — Making Infinity Behave · widget styles
   Prefixes: w-epsdelta-, w-domcolor-, w-euler-
   Appended after style.css; never edits it.
   ============================================================ */

/* === Widget 1 · the limit game (ε–δ) === */
.w-epsdelta-status {
  font-size: 0.9rem;
  margin-top: 0.6rem;
  color: var(--text-muted);
  min-height: 2.4em;
  line-height: 1.45;
}
.w-epsdelta-status .w-eps-ok { color: var(--ok); font-weight: 600; }
.w-epsdelta-status .w-eps-no { color: var(--err); font-weight: 600; }

/* === Widget 2 · domain coloring === */
.w-domcolor-stage {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: flex-start;
  background: var(--bg-sunken);
  border-radius: 0.5rem;
  padding: 0.75rem;
}
.w-domcolor-canvas {
  width: 360px;
  max-width: 100%;
  height: auto;
  aspect-ratio: 1 / 1;
  border-radius: 0.4rem;
  border: 1px solid var(--border);
  display: block;
  image-rendering: auto;
  touch-action: none;
  cursor: crosshair;
}
.w-domcolor-side {
  flex: 1 1 220px;
  min-width: 200px;
}
.w-domcolor-readout {
  font-family: var(--mono);
  font-size: 0.85rem;
  color: var(--text);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 0.4rem;
  padding: 0.55rem 0.7rem;
  margin-bottom: 0.7rem;
  line-height: 1.5;
}
.w-domcolor-readout strong { color: var(--accent-dark); }
.w-domcolor-legend {
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.5;
}
.w-domcolor-legend strong {
  display: block;
  color: var(--text);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.35rem;
}
.w-domcolor-legend p { margin: 0 0 0.45rem; }
.w-domcolor-legend em { color: var(--accent-dark); font-style: normal; font-weight: 600; }

/* === Widget 3 · assembling e^{iθ} === */
.w-euler-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem 1.6rem;
  align-items: center;
  margin-top: 0.8rem;
}
.w-euler-slider {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--mono);
  font-size: 0.85rem;
  color: var(--text-muted);
}
.w-euler-slider input[type="range"] {
  width: 220px;
  max-width: 50vw;
  accent-color: var(--accent);
  cursor: pointer;
}
.w-euler-slider span { color: var(--text); min-width: 5.5em; }
.w-euler-check {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  cursor: pointer;
}
.w-euler-check input { accent-color: var(--accent); cursor: pointer; }
.w-euler-status {
  font-family: var(--mono);
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 0.6rem;
  line-height: 1.5;
}
.w-euler-status strong { color: var(--text); }

@media (max-width: 767px) {
  .w-domcolor-canvas { width: 100%; }
}


/* ============ merged from ch05.widgets.css ============ */
/* ============================================================
   A Map of Mathematics — Chapter 5 widget styles
   Prefixes: w-trisum-, w-bridges-, w-loops-
   Loaded AFTER style.css. No layout overrides of shared tokens.
   ============================================================ */

/* === Widget 1 · triangle angle-sum lab === */
.w-trisum-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.85rem;
}
.w-trisum-panel {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}
.w-trisum-label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 0.45rem;
}
.w-trisum-tag {
  font-family: var(--mono);
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  background: var(--bg-sunken);
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
}
.w-trisum-sum {
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--text-muted);
  min-height: 1.3em;
}
.w-trisum-sum strong { color: var(--text); }
.w-trisum-excess {
  display: inline-block;
  margin-left: 0.3rem;
  font-size: 0.72rem;
  color: var(--theme-analysis);
}
.w-trisum-node circle { transition: r 0.12s ease-out; }
.w-trisum-node:active { cursor: grabbing; }

@media (max-width: 767px) {
  .w-trisum-row { grid-template-columns: 1fr; gap: 1.1rem; }
}

/* === Widget 2 · Königsberg bridges === */
.w-bridges-bridge { transition: opacity 0.25s ease-out, stroke 0.2s; }
.w-bridges-bridge.avail:hover { stroke: var(--accent-dark); }
.w-bridges-status {
  font-family: var(--mono);
  font-size: 0.84rem;
  color: var(--text-muted);
  margin-top: 0.7rem;
  min-height: 2.4em;
  line-height: 1.5;
}
.w-bridges-status strong { color: var(--text); }
.w-bridges-status .ok { color: var(--ok); font-weight: 600; }
.w-bridges-status .err { color: var(--err); font-weight: 600; }

/* === Widget 3 · loop shrinker === */
.w-loops-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
.w-loops-panel {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.w-loops-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
}
.w-loops-controls { margin-top: 0.35rem; }
.w-loops-preset { font-size: 0.78rem; padding: 0.35rem 0.7rem; }
.w-loops-preset.active {
  background: var(--accent-light);
  border-color: var(--accent);
  color: var(--accent-dark);
}
.w-loops-readout {
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--text-muted);
  min-height: 1.4em;
  margin-top: 0.2rem;
}
.w-loops-readout strong { color: var(--text); }
.w-loops-readout .ok { color: var(--ok); font-weight: 600; }
.w-loops-readout .err { color: var(--err); font-weight: 600; }

@media (max-width: 767px) {
  .w-loops-row { grid-template-columns: 1fr; gap: 1.25rem; }
}


/* ============ merged from ch06.widgets.css ============ */
/* ============================================================
   A Map of Mathematics — Chapter 6 widget styles
   Prefixes: w-cayley-  w-gates-  w-diagonal-
   Appends to style.css. No edits to the shared sheet.
   ============================================================ */

/* === Widget 1 · Cayley symmetry composer === */
.w-cayley-stage {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(260px, 1.2fr);
  gap: 1.25rem;
  align-items: start;
}
.w-cayley-tri-wrap {
  background: var(--bg-sunken);
  border-radius: 0.5rem;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
}
.w-cayley-svg { width: 100%; max-width: 260px; height: auto; display: block; }
.w-cayley-tri.w-cayley-anim { transform-box: fill-box; transform-origin: center; animation: w-cayley-pulse 0.26s ease-out; }
@keyframes w-cayley-pulse {
  0% { transform: scale(1); }
  50% { transform: scale(0.88) rotate(-6deg); }
  100% { transform: scale(1); }
}
.w-cayley-word {
  font-family: var(--mono); font-size: 0.9rem;
  color: var(--text-muted); text-align: center;
}
.w-cayley-word strong { color: var(--accent-dark); font-size: 1.05rem; }
.w-cayley-word-sub { display: block; font-size: 0.75rem; opacity: 0.8; margin-top: 0.15rem; }

.w-cayley-table-wrap { display: flex; flex-direction: column; gap: 0.5rem; }
.w-cayley-table-label {
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-muted); font-weight: 600;
}
.w-cayley-table {
  border-collapse: collapse;
  font-family: var(--mono); font-size: 0.82rem;
}
.w-cayley-table th, .w-cayley-table td {
  width: 2.1rem; height: 2.1rem; text-align: center;
  border: 1px solid var(--border);
}
.w-cayley-table th {
  background: var(--accent-light); color: var(--accent-dark); font-weight: 700;
}
.w-cayley-cell {
  background: var(--bg-sunken); color: var(--text-muted);
  transition: background 0.25s ease-out, color 0.2s, box-shadow 0.2s;
}
.w-cayley-cell.found {
  background: color-mix(in srgb, var(--cell-accent, var(--accent)) 16%, var(--bg-card));
  color: var(--text); font-weight: 700;
  box-shadow: inset 0 0 0 1px var(--cell-accent, var(--accent));
}
.w-cayley-cell.found.auto { opacity: 0.92; }
.w-cayley-cell.highlight {
  outline: 2px solid var(--theme-logic);
  outline-offset: -2px;
  background: var(--theme-logic-light);
}
.w-cayley-progress {
  font-family: var(--mono); font-size: 0.82rem; color: var(--text-muted);
}
.w-cayley-progress.complete { color: var(--ok); font-weight: 700; }
.w-cayley-done {
  margin-top: 0.9rem; padding: 0.85rem 1rem;
  background: var(--ok-light); border: 1px solid #bfe3c9;
  border-left: 3px solid var(--ok); border-radius: var(--radius);
  font-size: 0.92rem; color: #1b5e2e;
}
.w-cayley-done strong { color: #14532d; }
.w-cayley-done em { color: #14532d; }
.w-cayley-hl {
  font-family: var(--mono); font-weight: 700;
  background: var(--theme-logic-light); color: var(--theme-logic);
  padding: 0.05em 0.4em; border-radius: 4px;
}

/* === Widget 2 · Boole's gate workbench === */
.w-gates-stage { background: var(--bg-sunken); border-radius: 0.5rem; padding: 0.5rem; }
.w-gates-svg { width: 100%; height: auto; display: block; }
.w-gates-controls {
  display: flex; flex-wrap: wrap; gap: 1.25rem;
  margin-top: 0.85rem; align-items: flex-start;
}
.w-gates-inputs { display: flex; gap: 0.5rem; }
.w-gates-switch {
  font: inherit; font-family: var(--mono); font-size: 0.9rem;
  border: 2px solid var(--border); background: var(--bg-card);
  color: var(--text); border-radius: 8px;
  padding: 0.5rem 0.9rem; cursor: pointer;
  transition: all 0.15s ease-out;
}
.w-gates-switch strong { color: var(--text-muted); }
.w-gates-switch.on {
  border-color: var(--theme-applied); background: var(--theme-applied-light);
}
.w-gates-switch.on strong { color: var(--theme-applied); }
.w-gates-slots { display: flex; gap: 0.65rem; flex-wrap: wrap; }
.w-gates-slot { display: flex; flex-direction: column; gap: 0.25rem; }
.w-gates-slot-label {
  font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-muted); font-weight: 600;
}
.w-gates-expr {
  font-family: var(--mono); font-size: 0.9rem; color: var(--text-muted);
  margin-top: 0.75rem;
}
.w-gates-expr strong { color: var(--accent-dark); }
.w-gates-bottom {
  display: grid; grid-template-columns: auto 1fr; gap: 1.25rem;
  margin-top: 0.9rem; align-items: start;
}
.w-gates-truth {
  border-collapse: collapse; font-family: var(--mono); font-size: 0.85rem;
}
.w-gates-truth th, .w-gates-truth td {
  border: 1px solid var(--border); padding: 0.3rem 0.7rem; text-align: center;
}
.w-gates-truth th { background: var(--accent-light); color: var(--accent-dark); font-weight: 700; }
.w-gates-truth tr.w-gates-cur td { background: var(--accent-secondary-light); }
.w-gates-truth .w-gates-one { color: var(--theme-applied); font-weight: 700; }
.w-gates-truth .w-gates-zero { color: var(--text-muted); }
.w-gates-challenge {
  background: var(--bg-card); border: 1px solid var(--border);
  border-left: 3px solid var(--theme-logic); border-radius: var(--radius);
  padding: 0.8rem 1rem;
}
.w-gates-chal-head {
  font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--theme-logic); font-weight: 700; margin-bottom: 0.3rem;
}
.w-gates-chal-text { font-size: 0.88rem; margin-bottom: 0.5rem; }
.w-gates-chal-status {
  font-family: var(--mono); font-size: 0.82rem; color: var(--text-muted);
  padding: 0.4rem 0.6rem; border-radius: 6px; background: var(--bg-sunken);
}
.w-gates-chal-status.win {
  background: var(--ok-light); color: #1b5e2e; border: 1px solid #bfe3c9;
  font-family: inherit;
}
.w-gates-chal-status.win strong { color: #14532d; }

/* === Widget 3 · Cantor's diagonal stepper === */
.w-diagonal-grid-wrap {
  background: var(--bg-sunken); border-radius: 0.5rem; padding: 0.75rem;
  overflow-x: auto;
}
.w-diagonal-grid {
  border-collapse: collapse; font-family: var(--mono); font-size: 0.85rem;
  margin: 0 auto;
}
.w-diagonal-grid th, .w-diagonal-grid td {
  border: 1px solid var(--border); width: 2rem; height: 2rem; text-align: center;
}
.w-diagonal-grid th {
  background: transparent; color: var(--text-muted); font-weight: 600; font-size: 0.72rem;
}
.w-diagonal-rowhead {
  background: var(--accent-light) !important; color: var(--accent-dark) !important;
  white-space: nowrap; padding: 0 0.5rem;
}
.w-diagonal-bit {
  background: var(--bg-card); color: var(--text);
  transition: background 0.2s, color 0.2s, box-shadow 0.2s;
}
.w-diagonal-bit.on-diag {
  box-shadow: inset 0 0 0 2px var(--theme-analysis);
  color: var(--theme-analysis); font-weight: 700;
}
.w-diagonal-bit.used {
  background: var(--theme-analysis-light);
}
.w-diagonal-built { background: var(--theme-geometry-light); }
.w-diagonal-bit.built { background: var(--theme-geometry-light); color: var(--text-muted); }
.w-diagonal-bit.built.filled {
  color: var(--theme-geometry); font-weight: 700;
  box-shadow: inset 0 0 0 1px var(--theme-geometry);
}
.w-diagonal-built .w-diagonal-rowhead {
  background: var(--theme-geometry) !important; color: #fff !important;
}
.w-diagonal-narrate {
  font-size: 0.9rem; color: var(--text-muted); margin-top: 0.7rem; min-height: 2.4em;
}
.w-diagonal-narrate strong { color: var(--text); }
.w-diagonal-narrate em { color: var(--theme-analysis); font-style: italic; }

/* === Responsive === */
@media (max-width: 767px) {
  .w-cayley-stage { grid-template-columns: 1fr; }
  .w-gates-bottom { grid-template-columns: 1fr; }
  .w-cayley-table th, .w-cayley-table td { width: 1.8rem; height: 1.8rem; font-size: 0.75rem; }
}


/* ============ merged from ch07.widgets.css ============ */
/* ============================================================
   Chapter 7 — widget styles (w-godel-, w-turing-, w-curry-)
   Appended after style.css. Every code surface stays LIGHT.
   ============================================================ */

/* shared small label */
.w-godel-label {
  font-size: 0.7rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-muted);
}

/* === Widget 1 — Gödel numbering === */
.w-godel-legend {
  display: flex; flex-wrap: wrap; gap: 0.4rem;
  margin-bottom: 0.9rem;
}
.w-godel-chip {
  display: inline-flex; align-items: center; gap: 0.35rem;
  font-family: var(--mono); font-size: 0.82rem;
  background: var(--bg-sunken); border: 1px solid var(--border);
  border-radius: 6px; padding: 0.2rem 0.5rem;
}
.w-godel-chip b { color: var(--text); font-size: 0.95rem; }
.w-godel-chip span {
  color: var(--accent); font-weight: 700;
  background: var(--accent-light); border-radius: 4px;
  padding: 0 0.3rem;
}
.w-godel-row { display: flex; flex-direction: column; gap: 0.3rem; margin-bottom: 0.6rem; }
.w-godel-input {
  font: inherit; font-family: var(--mono); font-size: 0.95rem;
  padding: 0.5rem 0.7rem; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg-card); color: var(--text);
  width: 100%;
}
.w-godel-input:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
.w-godel-presets { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 0.8rem; }
.w-godel-preset { font-family: var(--mono); font-size: 0.8rem; }
.w-godel-encode {
  font-family: var(--mono); font-size: 0.85rem; line-height: 1.9;
  background: var(--code-bg); color: var(--code-fg);
  border: 1px solid var(--code-border); border-radius: 8px;
  padding: 0.7rem 0.9rem; margin-bottom: 0.6rem;
  overflow-x: auto;
}
.w-godel-encode sup { color: var(--code-op); font-weight: 700; }
.w-godel-sub { color: var(--code-cm); font-style: italic; margin-left: 0.1rem; }
.w-godel-bad { color: var(--err); font-style: normal; }
.w-godel-result, .w-godel-decoded {
  font-family: var(--mono); font-size: 0.9rem;
  color: var(--text); word-break: break-all;
  margin-bottom: 0.7rem; min-height: 1.3em;
}
.w-godel-result b, .w-godel-decoded b { color: var(--accent-dark); }
.w-godel-eq { color: var(--text-muted); margin-right: 0.3rem; }
.w-godel-decode {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0.5rem;
  border-top: 1px solid var(--border); padding-top: 0.85rem; margin-top: 0.2rem;
}
.w-godel-decode .w-godel-input { flex: 1 1 200px; width: auto; }
.w-godel-decode label { flex-basis: 100%; }
.w-godel-readout {
  font-family: var(--mono); font-size: 0.83rem;
  color: var(--text-muted); margin-top: 0.6rem;
  border-top: 1px dashed var(--border); padding-top: 0.6rem;
}

/* === Widget 2 — Turing machine === */
.w-turing-tape-wrap {
  position: relative;
  background: var(--bg-sunken); border-radius: 0.5rem;
  padding: 0.6rem 0.5rem 0.2rem;
  margin-bottom: 0.6rem;
}
.w-turing-tape {
  display: flex; gap: 3px;
}
.w-turing-cell {
  flex: 1 1 0; min-width: 0;
  aspect-ratio: 1;
  display: grid; place-items: center;
  font-family: var(--mono); font-size: 0.85rem; font-weight: 600;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 5px; color: var(--text-muted);
  transition: background 0.18s, color 0.18s, border-color 0.18s;
}
.w-turing-cell.on { background: var(--accent-secondary-light); color: var(--accent-secondary); border-color: var(--accent-secondary); }
.w-turing-cell.head { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-light); }
.w-turing-head {
  position: absolute; top: 0.05rem;
  transform: translateX(-50%);
  color: var(--accent); font-size: 0.8rem; line-height: 1;
  transition: left 0.16s ease-out;
  pointer-events: none;
}
.w-turing-status {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem;
  margin-bottom: 0.7rem;
}
.w-turing-badge {
  font-family: var(--mono); font-size: 0.8rem; font-weight: 700;
  color: #fff; background: var(--accent);
  border-radius: 999px; padding: 0.22rem 0.7rem;
}
.w-turing-badge.halted { background: var(--ok); }
.w-turing-stat { font-family: var(--mono); font-size: 0.82rem; color: var(--text-muted); }
.w-turing-halt {
  font-family: var(--mono); font-size: 0.82rem; font-weight: 600;
  color: var(--ok); opacity: 0; transition: opacity 0.2s;
}
.w-turing-halt.show { opacity: 1; }
.w-turing-presets {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem;
  margin-bottom: 0.7rem;
}
.w-turing-presets .pick { flex: 1 1 240px; }
.w-turing-table {
  width: 100%; border-collapse: collapse;
  font-family: var(--mono); font-size: 0.8rem;
  margin-bottom: 0.4rem;
}
.w-turing-table th {
  text-align: left; font-weight: 600; font-size: 0.68rem;
  text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-muted);
  padding: 0.3rem 0.5rem; border-bottom: 1px solid var(--border);
}
.w-turing-table td {
  padding: 0.25rem 0.5rem; border-bottom: 1px solid var(--border);
}
.w-turing-table tr.active { background: var(--accent-light); }
.w-turing-table tr.active .w-turing-st,
.w-turing-table tr.active .w-turing-rd { color: var(--accent-dark); font-weight: 700; }
.w-turing-st, .w-turing-rd { color: var(--text); font-weight: 600; }
.w-turing-table .pick { font-size: 0.78rem; padding: 0.18rem 0.35rem; }
.w-turing-caption {
  font-family: var(--mono); font-size: 0.82rem;
  color: var(--text-muted); margin-top: 0.7rem;
  border-top: 1px dashed var(--border); padding-top: 0.6rem;
}

/* === Widget 3 — Curry–Howard Rosetta === */
.w-curry-pick {
  display: flex; flex-direction: column; gap: 0.3rem;
  margin-bottom: 0.85rem;
}
.w-curry-pick .pick { max-width: 360px; font-family: var(--mono); }
.w-curry-panes {
  display: grid; gap: 0.7rem;
  grid-template-columns: 1fr;
}
@media (min-width: 768px) {
  .w-curry-panes { grid-template-columns: repeat(3, 1fr); }
}
.w-curry-pane {
  border: 1px solid var(--border); border-radius: 8px;
  overflow: hidden; display: flex; flex-direction: column;
  background: var(--bg-card);
}
.w-curry-tag {
  font-size: 0.7rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-muted);
  background: var(--bg-sunken); border-bottom: 1px solid var(--border);
  padding: 0.45rem 0.7rem;
}
.w-curry-logic { background: var(--accent-light); }
.w-curry-logic .w-curry-tag { background: transparent; border-bottom-color: var(--border); }
.w-curry-prop {
  font-family: var(--mono); font-size: 1rem; font-weight: 700;
  color: var(--accent-dark); padding: 0.7rem 0.7rem 0.3rem;
}
.w-curry-read {
  font-size: 0.85rem; line-height: 1.55; color: var(--text);
  padding: 0 0.7rem 0.8rem;
}
pre.code.w-curry-code {
  margin: 0; flex: 1;
  font-size: 0.78rem; line-height: 1.65;
  padding: 0.8rem 0.7rem;
  white-space: pre-wrap; word-break: break-word;
}
.w-curry-readout {
  font-family: var(--mono); font-size: 0.83rem;
  color: var(--text-muted); margin-top: 0.8rem;
  border-top: 1px dashed var(--border); padding-top: 0.6rem;
}

@media (max-width: 767px) {
  .w-turing-table { font-size: 0.72rem; }
  .w-turing-cell { font-size: 0.7rem; }
}


/* ============ merged from ch08.widgets.css ============ */
/* ============================================================
   A Map of Mathematics — Chapter 8 widget styles
   Prefixes: w-sampling-, w-dilemma-, w-entropy-, w-rsa-
   All code surfaces stay LIGHT (shared --code-* tokens).
   ============================================================ */

/* === shared control rows === */
.w-sampling-row, .w-dilemma-row, .w-entropy-row, .w-rsa-row {
  display: flex; align-items: center; flex-wrap: wrap;
  gap: 0.6rem; margin-top: 0.85rem;
}
.w-sampling-row label, .w-rsa-row label {
  font-family: var(--mono); font-size: 0.8rem; color: var(--text-muted);
}

/* segmented toggle (reused) */
.w-seg {
  display: inline-flex; border: 1px solid var(--border);
  border-radius: 8px; overflow: hidden;
}
.w-seg button {
  font: inherit; font-size: 0.82rem; font-weight: 500;
  background: var(--bg-card); color: var(--text-muted);
  border: none; padding: 0.42rem 0.8rem; cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.w-seg button + button { border-left: 1px solid var(--border); }
.w-seg button.active { background: var(--accent); color: #fff; }

/* === Widget 1 — w-sampling (the tea test) === */
.w-sampling-stage { background: var(--bg-sunken); border-radius: 0.5rem; padding: 0.5rem; }
.w-sampling-cups {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 0.6rem 0.2rem 0.2rem; min-height: 2.4rem;
}
.w-sampling-cup {
  width: 30px; height: 30px; border-radius: 7px;
  display: grid; place-items: center;
  font-size: 1rem; border: 1px solid var(--border);
  background: var(--bg-card);
  transition: transform 0.18s ease-out, background 0.18s;
}
.w-sampling-cup.hit  { background: var(--ok-light); border-color: var(--ok); }
.w-sampling-cup.miss { background: var(--err-light); border-color: var(--err); opacity: 0.85; }
.w-sampling-cup.pop  { transform: scale(1.18); }
.w-sampling-skill {
  display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap;
}
.w-sampling-skill input[type="range"] { flex: 1; min-width: 150px; accent-color: var(--accent); }
.w-sampling-skill.hidden-skill { opacity: 0.45; pointer-events: none; }
.w-sampling-bars {
  display: flex; align-items: flex-end; gap: 2px;
  height: 130px; padding: 0.4rem 0.2rem 0;
  border-bottom: 1px solid var(--border); margin-top: 0.5rem;
}
.w-sampling-bar { flex: 1; position: relative; min-width: 4px; }
.w-sampling-bar .fill {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: var(--theme-analysis); border-radius: 3px 3px 0 0;
  transition: height 0.3s ease-out;
}
.w-sampling-bar.tail .fill { background: var(--accent-secondary); }
.w-sampling-bar.observed .fill { background: var(--accent-dark); }
.w-sampling-bar .obs-mark {
  position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%);
  font-family: var(--mono); font-size: 0.62rem; color: var(--accent-dark);
  white-space: nowrap; font-weight: 700;
}
.w-sampling-axis {
  display: flex; justify-content: space-between;
  font-family: var(--mono); font-size: 0.66rem; color: var(--text-muted);
  margin-top: 0.2rem;
}
.w-sampling-verdict {
  margin-top: 0.7rem; font-size: 0.9rem;
  padding: 0.6rem 0.8rem; border-radius: 8px;
  background: var(--accent-light); border: 1px solid var(--border);
}
.w-sampling-verdict strong { color: var(--accent-dark); }
.w-sampling-verdict.reject { background: var(--ok-light); border-color: var(--ok); }
.w-sampling-verdict.keep { background: var(--warn-light); border-color: #f3dcb6; }
.w-sampling-readout {
  font-family: var(--mono); font-size: 0.85rem;
  color: var(--text-muted); margin-top: 0.6rem;
}
.w-sampling-readout strong { color: var(--text); }
.w-sampling-hist {
  font-family: var(--mono); font-size: 0.78rem;
  color: var(--text-muted); margin-top: 0.5rem; min-height: 1.2em;
}
.w-sampling-hist strong { color: var(--accent-dark); }

/* === Widget 2 — w-dilemma (prisoner's dilemma) === */
.w-dilemma-matrix {
  border-collapse: collapse; margin: 0.5rem 0 0.3rem;
  font-family: var(--mono); font-size: 0.8rem;
}
.w-dilemma-matrix th, .w-dilemma-matrix td {
  border: 1px solid var(--border); padding: 0.4rem 0.6rem; text-align: center;
}
.w-dilemma-matrix th { background: var(--bg-sunken); color: var(--text-muted); font-weight: 600; }
.w-dilemma-matrix td { background: var(--bg-card); }
.w-dilemma-matrix .you { color: var(--theme-analysis); font-weight: 700; }
.w-dilemma-matrix .opp { color: var(--accent-secondary); font-weight: 700; }
.w-dilemma-stage { background: var(--bg-sunken); border-radius: 0.5rem; padding: 0.7rem 0.6rem; margin-top: 0.6rem; }
.w-dilemma-track { margin-bottom: 0.5rem; }
.w-dilemma-track .lbl {
  font-family: var(--mono); font-size: 0.72rem; color: var(--text-muted);
  margin-bottom: 0.2rem;
}
.w-dilemma-chips { display: flex; flex-wrap: wrap; gap: 4px; }
.w-dilemma-chip {
  width: 24px; height: 24px; border-radius: 6px;
  display: grid; place-items: center;
  font-family: var(--mono); font-size: 0.72rem; font-weight: 700;
  border: 1px solid var(--border); background: var(--bg-card);
  opacity: 0; transform: translateY(4px);
  transition: opacity 0.2s, transform 0.2s;
}
.w-dilemma-chip.show { opacity: 1; transform: translateY(0); }
.w-dilemma-chip.C { background: var(--ok-light); border-color: var(--ok); color: #1b5e2e; }
.w-dilemma-chip.D { background: var(--err-light); border-color: var(--err); color: #b91c1c; }
.w-dilemma-scores {
  display: flex; gap: 1.4rem; flex-wrap: wrap;
  font-family: var(--mono); font-size: 0.9rem; margin-top: 0.5rem;
}
.w-dilemma-scores .you { color: var(--theme-analysis); }
.w-dilemma-scores .opp { color: var(--accent-secondary); }
.w-dilemma-scores strong { font-size: 1.05rem; }
.w-dilemma-league {
  width: 100%; border-collapse: collapse; margin-top: 0.7rem;
  font-family: var(--mono); font-size: 0.8rem;
}
.w-dilemma-league th, .w-dilemma-league td {
  border-bottom: 1px solid var(--border); padding: 0.35rem 0.6rem; text-align: left;
}
.w-dilemma-league th { color: var(--text-muted); font-weight: 600; }
.w-dilemma-league td.score { text-align: right; font-weight: 700; color: var(--accent-dark); }
.w-dilemma-league tr.top td { background: var(--ok-light); }
.w-dilemma-readout {
  margin-top: 0.6rem; font-size: 0.9rem;
  padding: 0.6rem 0.8rem; border-radius: 8px;
  background: var(--accent-light); border: 1px solid var(--border); min-height: 1.2em;
}
.w-dilemma-readout strong { color: var(--accent-dark); }

/* === Widget 3 — w-entropy (entropy sculptor) === */
.w-entropy-stage { background: var(--bg-sunken); border-radius: 0.5rem; padding: 0.7rem 0.6rem; }
.w-entropy-bars {
  display: flex; align-items: flex-end; gap: 10px;
  height: 170px; padding-top: 0.4rem;
}
.w-entropy-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 0.3rem; height: 100%; }
.w-entropy-track {
  flex: 1; width: 100%; position: relative;
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 6px;
  cursor: ns-resize; touch-action: none; overflow: hidden;
}
.w-entropy-fill {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: var(--theme-applied); border-radius: 0 0 5px 5px;
  transition: height 0.12s ease-out;
}
.w-entropy-track.drag .w-entropy-fill { transition: none; }
.w-entropy-pct {
  font-family: var(--mono); font-size: 0.7rem; color: var(--text-muted);
  position: absolute; top: 4px; left: 0; right: 0; text-align: center;
}
.w-entropy-letter { font-family: var(--mono); font-weight: 700; font-size: 0.9rem; color: var(--accent-dark); }
.w-entropy-code {
  display: flex; gap: 2px; min-height: 12px; align-items: center; justify-content: center;
}
.w-entropy-bit {
  width: 9px; height: 9px; border-radius: 2px; background: var(--theme-applied); opacity: 0.7;
}
.w-entropy-readout {
  display: flex; flex-wrap: wrap; gap: 0.4rem 1.6rem;
  font-family: var(--mono); font-size: 0.88rem;
  color: var(--text-muted); margin-top: 0.85rem;
}
.w-entropy-readout strong { color: var(--text); }
.w-entropy-readout .big { font-size: 1.1rem; color: var(--accent-dark); font-weight: 700; }
.w-entropy-cap {
  font-size: 0.85rem; color: var(--text-muted); margin-top: 0.55rem; font-style: italic;
}

/* === Widget 4 — w-rsa (toy RSA stepper) === */
.w-rsa-params {
  font-family: var(--mono); font-size: 0.82rem; color: var(--text-muted);
  background: var(--code-bg); border: 1px solid var(--code-border);
  border-radius: 8px; padding: 0.6rem 0.8rem; margin: 0.5rem 0;
}
.w-rsa-params strong { color: var(--code-fg); }
.w-rsa-steps { margin-top: 0.6rem; display: flex; flex-direction: column; gap: 0.4rem; }
.w-rsa-step {
  font-family: var(--mono); font-size: 0.82rem;
  background: var(--code-bg); color: var(--code-fg);
  border: 1px solid var(--code-border); border-left: 3px solid var(--border);
  border-radius: 8px; padding: 0.55rem 0.8rem;
  opacity: 0.45; transition: opacity 0.2s, border-color 0.2s;
}
.w-rsa-step.show { opacity: 1; }
.w-rsa-step.enc.show { border-left-color: var(--theme-analysis); }
.w-rsa-step.dec.show { border-left-color: var(--ok); }
.w-rsa-step .note { color: var(--code-cm); font-style: italic; display: block; margin-top: 0.15rem; }
.w-rsa-step .val { color: var(--code-kw); font-weight: 700; }
.w-rsa-msg {
  display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap;
}
.w-rsa-msg input[type="range"] { flex: 1; min-width: 150px; accent-color: var(--accent); }
.w-rsa-msg .mval { font-family: var(--mono); font-weight: 700; color: var(--accent-dark); min-width: 2.5rem; }
.w-rsa-caveat {
  font-size: 0.85rem; color: var(--text-muted); margin-top: 0.6rem;
  padding: 0.55rem 0.8rem; border-radius: 8px;
  background: var(--warn-light); border: 1px solid #f3dcb6;
}
.w-rsa-caveat strong { color: var(--warn); }



/* ============ merged from ch09.widgets.css ============ */
/* ============================================================
   Chapter 9 — The Age of Abstraction
   Widget-specific styles. Prefixes: w-fourier-, w-holes-, w-compose-
   Links AFTER style.css; uses shared tokens only.
   ============================================================ */

/* ---------- Widget 1: w-fourier (build-a-function) ---------- */
.w-fourier-sliders {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.75rem;
  margin-top: 0.85rem;
}
@media (max-width: 640px) {
  .w-fourier-sliders { grid-template-columns: repeat(2, 1fr); }
}
.w-fourier-slider {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.3rem;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 0.55rem 0.6rem;
}
.w-fourier-slider label {
  font-family: var(--mono);
  font-size: 0.74rem;
  color: var(--text-muted);
  text-align: center;
}
.w-fourier-slider label b {
  color: var(--accent-dark);
  font-weight: 700;
}
.w-fourier-slider input[type="range"] {
  width: 100%;
  accent-color: var(--theme-analysis);
  cursor: pointer;
}
.w-fourier-val {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--theme-analysis);
  text-align: center;
  font-weight: 700;
}
.w-fourier-dist {
  font-family: var(--mono);
  font-weight: 700;
}
.w-fourier-dist b { color: var(--accent-dark); }
.w-fourier-caption {
  font-size: 0.84rem;
  color: var(--text-muted);
  margin-top: 0.85rem;
  line-height: 1.55;
}

/* ---------- Widget 2: w-holes (the hole counter) ---------- */
.w-holes-shapes {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-bottom: 0.85rem;
}
.w-holes-tab {
  font-family: var(--mono);
  font-size: 0.78rem;
  padding: 0.4rem 0.7rem;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-muted);
  border-radius: 0.5rem;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.w-holes-tab:hover { border-color: var(--accent); color: var(--accent-dark); }
.w-holes-tab.active {
  background: var(--accent-light);
  border-color: var(--accent);
  color: var(--accent-dark);
  font-weight: 700;
}
.w-holes-stage {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 1rem;
  align-items: center;
}
@media (max-width: 640px) {
  .w-holes-stage { grid-template-columns: 1fr; }
}
.w-holes-betti {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.w-holes-num {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-left: 3px solid var(--theme-algebra);
  border-radius: 0.5rem;
  padding: 0.6rem 0.8rem;
}
.w-holes-num.b1 { border-left-color: var(--theme-logic); }
.w-holes-num .sym {
  font-family: var(--mono);
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--accent-dark);
  min-width: 2.6rem;
}
.w-holes-num .val {
  font-family: var(--mono);
  font-size: 1.9rem;
  font-weight: 700;
  color: var(--theme-algebra);
  transition: transform 0.25s;
}
.w-holes-num.b1 .val { color: var(--theme-logic); }
.w-holes-num .val.bump { transform: scale(1.35); }
.w-holes-num .lab {
  font-size: 0.82rem;
  color: var(--text-muted);
}
.w-holes-readout {
  font-family: var(--mono);
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 0.75rem;
  line-height: 1.5;
}
.w-holes-readout b { color: var(--accent-dark); }
/* SVG cell hover highlights */
.w-holes-svg .cell-v { fill: var(--theme-algebra); transition: r 0.15s; }
.w-holes-svg .cell-e { stroke: var(--accent); stroke-width: 3; transition: stroke-width 0.15s; }
.w-holes-svg .cell-f { fill: var(--theme-analysis-light); transition: opacity 0.15s; }
.w-holes-svg .hl-v { r: 9; fill: var(--theme-logic); }
.w-holes-svg .hl-e { stroke: var(--theme-logic); stroke-width: 5; }
.w-holes-svg .hl-f { opacity: 0.85; fill: var(--theme-logic-light); }

/* ---------- Widget 3: w-compose (arrows compose) ---------- */
.w-compose-readout {
  font-family: var(--mono);
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 0.75rem;
  line-height: 1.5;
}
.w-compose-readout b { color: var(--accent-dark); }
.w-compose-svg .obj circle { fill: var(--accent-light); stroke: var(--accent); stroke-width: 2.4; }
.w-compose-svg .obj text { fill: var(--accent-dark); font-family: var(--mono); font-weight: 700; }
.w-compose-svg .arr { fill: none; stroke: var(--theme-analysis); stroke-width: 2.4; }
.w-compose-svg .arr.sel { stroke: var(--theme-geometry); stroke-width: 3.4; }
.w-compose-svg .arr.comp { stroke: var(--accent); stroke-width: 3.4; stroke-dasharray: 6 4; }
.w-compose-svg .arr.idloop { stroke: var(--theme-algebra); stroke-width: 2.4; }
.w-compose-svg .arr-label {
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 700;
  fill: var(--theme-analysis);
}
.w-compose-svg .arr-label.comp { fill: var(--accent-dark); }


/* ============ merged from ch10.widgets.css ============ */
/* ============================================================
   Chapter 10 — Shapes at the Frontier · widget styles
   Prefixes: w-logistic-, w-hat-, w-kakeya-, w-packing-, w-spindle-
   Appended after style.css; never edits it.
   ============================================================ */

/* === Widget 1 · logistic map === */
.w-logistic-stage {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  background: var(--bg-sunken);
  border-radius: 0.5rem;
  padding: 0.75rem;
}
.w-logistic-panel {
  flex: 1 1 300px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.w-logistic-label {
  font-size: 0.75rem;
  font-family: var(--mono);
  color: var(--text-muted);
}
.w-logistic-time,
.w-logistic-bif {
  width: 100%;
  height: auto;
  aspect-ratio: 2 / 1;
  display: block;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 0.4rem;
  touch-action: none;
}

/* === Widget 2 · hat tile sandbox === */
.w-hat-status {
  font-size: 0.88rem;
  margin-top: 0.6rem;
  color: var(--text-muted);
  min-height: 2.6em;
  line-height: 1.45;
}
.w-hat-status strong { color: var(--text); }

/* === Widget 3 · Kakeya needle gym === */
.w-kakeya-caption {
  font-size: 0.9rem;
  margin-top: 0.6rem;
  color: var(--text-muted);
  min-height: 2.6em;
  line-height: 1.45;
}
.w-kakeya-caption strong { color: var(--text); }

/* === Widget 4 · packing lab === */
.w-packing-stage {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  background: var(--bg-sunken);
  border-radius: 0.5rem;
  padding: 0.75rem;
}
.w-packing-panel {
  flex: 1 1 240px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  align-items: stretch;
}
.w-packing-label {
  font-size: 0.78rem;
  font-family: var(--mono);
  color: var(--text-muted);
  font-weight: 600;
}
.w-packing-svg {
  width: 100%;
  max-width: 300px;
  height: auto;
  aspect-ratio: 1 / 1;
  display: block;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 0.4rem;
  margin: 0 auto;
}
.w-packing-panel .controls { margin-top: 0.3rem; justify-content: center; }
.w-packing-read {
  font-family: var(--mono);
  font-size: 0.82rem;
  color: var(--text-muted);
  text-align: center;
}
.w-packing-read strong { color: var(--text); }
.w-packing-slider {
  width: 100%;
  max-width: 240px;
  accent-color: var(--theme-logic);
  cursor: pointer;
}
.w-packing-narrate {
  font-size: 0.9rem;
  margin-top: 0.7rem;
  color: var(--text-muted);
  line-height: 1.45;
  min-height: 2.6em;
}
.w-packing-narrate strong { color: var(--text); }

/* === Widget 5 · Moser spindle === */
.w-spindle-palette {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.7rem;
  flex-wrap: wrap;
}
.w-spindle-swatch {
  width: 34px; height: 34px;
  border-radius: 8px;
  border: 2px solid var(--border);
  cursor: pointer;
  display: grid; place-items: center;
  font-size: 1rem; color: var(--text-muted);
  background: var(--bg-card);
  transition: transform 0.12s, border-color 0.12s;
  padding: 0;
}
.w-spindle-swatch:hover { transform: translateY(-2px); }
.w-spindle-swatch.active { border-color: var(--accent-dark); box-shadow: 0 0 0 2px var(--accent-light); }
.w-spindle-swatch.disabled { opacity: 0.3; cursor: not-allowed; }
.w-spindle-eraser { background: var(--bg-card); }
.w-spindle-status {
  font-size: 0.9rem;
  margin-top: 0.6rem;
  color: var(--text-muted);
  min-height: 2.6em;
  line-height: 1.45;
}
.w-spindle-status strong { color: var(--text); }
.w-spindle-edge-bad { animation: w-spindle-flash 0.8s ease-in-out infinite; }
@keyframes w-spindle-flash {
  0%, 100% { stroke-opacity: 1; }
  50% { stroke-opacity: 0.3; }
}
@media (prefers-reduced-motion: reduce) {
  .w-spindle-edge-bad { animation: none; }
}

@media (max-width: 767px) {
  .w-logistic-panel, .w-packing-panel { flex-basis: 100%; }
}


/* ============ merged from ch11.widgets.css ============ */
/* ============================================================
   Chapter 11 — Randomness Has a Shape — widget styles
   Prefixes: w-snap-, w-gaps-, w-spacing-, w-mixing-, w-sandpile-
   Light code-ish surfaces only. No layout overrides of style.css.
   ============================================================ */

/* shared little bits */
.w-c11-panels {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
@media (max-width: 767px) {
  .w-c11-panels { grid-template-columns: 1fr; }
}
.w-c11-badges {
  display: flex; flex-wrap: wrap; gap: 0.45rem;
  margin-top: 0.7rem;
}
.w-c11-badge {
  font-family: var(--mono); font-size: 0.78rem;
  padding: 0.3rem 0.65rem; border-radius: 999px;
  border: 1px solid var(--border); background: var(--bg-sunken);
  color: var(--text-muted);
  display: inline-flex; align-items: center; gap: 0.4rem;
}
.w-c11-badge strong { color: var(--text); }
.w-c11-badge.yes { border-color: var(--ok); background: var(--ok-light); color: #1b5e2e; }
.w-c11-badge.no  { border-color: var(--err); background: var(--err-light); color: #b91c1c; }
.w-c11-narrate {
  font-size: 0.9rem; color: var(--text-muted);
  margin-top: 0.7rem; min-height: 1.3em;
  border-left: 3px solid var(--accent-light); padding-left: 0.7rem;
}
.w-c11-narrate strong { color: var(--text); }
.w-c11-caption {
  font-size: 0.83rem; color: var(--text-muted);
  margin-top: 0.7rem; font-style: italic;
}
.w-c11-caption strong { color: var(--text); font-style: normal; }
.w-c11-slider {
  display: flex; align-items: center; gap: 0.7rem;
  margin-top: 0.85rem; flex-wrap: wrap;
}
.w-c11-slider input[type=range] { flex: 1; min-width: 160px; accent-color: var(--accent); }
.w-c11-slider .lbl {
  font-family: var(--mono); font-size: 0.8rem; color: var(--text-muted);
  white-space: nowrap;
}
.w-c11-slider .lbl strong { color: var(--text); }

/* ---------- Widget 1: w-snap ---------- */
.w-snap-svg { width: 100%; height: auto; display: block; touch-action: none; }
.w-snap-edge { stroke: var(--theme-analysis); stroke-width: 1.1; opacity: 0.55; }
.w-snap-edge.tri { stroke: var(--theme-geometry); stroke-width: 2; opacity: 0.95; }
.w-snap-vtx { fill: var(--accent); stroke: #fff; stroke-width: 1.5; }
.w-snap-curve-svg { width: 100%; height: auto; display: block; background: var(--bg-sunken); border-radius: 0.5rem; }
.w-snap-axis { stroke: var(--border); stroke-width: 1; }
.w-snap-axislabel { fill: var(--text-muted); font-family: var(--mono); font-size: 10px; }
.w-snap-sigmoid { fill: none; stroke: var(--theme-applied); stroke-width: 2.4; }
.w-snap-thresh { stroke: var(--accent-dark); stroke-width: 1.4; stroke-dasharray: 4 3; }
.w-snap-pmark { fill: var(--accent); }

/* ---------- Widget 2: w-gaps ---------- */
.w-gaps-svg { width: 100%; height: auto; display: block; background: var(--bg-sunken); border-radius: 0.5rem; }
.w-gaps-bar { fill: var(--theme-algebra); }
.w-gaps-bar.twin { fill: var(--theme-geometry); }
.w-gaps-axis { stroke: var(--border); stroke-width: 1; }
.w-gaps-tick { fill: var(--text-muted); font-family: var(--mono); font-size: 9px; }
.w-gaps-stats {
  display: flex; flex-wrap: wrap; gap: 0.45rem; margin-top: 0.7rem;
}

/* ---------- Widget 3: w-spacing ---------- */
.w-spacing-svg { width: 100%; height: auto; display: block; background: var(--bg-sunken); border-radius: 0.5rem; }
.w-spacing-bar-a { fill: var(--theme-analysis); opacity: 0.8; }
.w-spacing-bar-b { fill: var(--theme-logic); opacity: 0.8; }
.w-spacing-curve { fill: none; stroke: var(--accent-dark); stroke-width: 2.4; }
.w-spacing-axis { stroke: var(--border); stroke-width: 1; }
.w-spacing-tick { fill: var(--text-muted); font-family: var(--mono); font-size: 9px; }
.w-spacing-title {
  font-size: 0.8rem; font-weight: 600; color: var(--text-muted);
  text-align: center; margin-bottom: 0.3rem;
}

/* ---------- Widget 4: w-mixing ---------- */
.w-mixing-svg { width: 100%; height: auto; display: block; background: var(--bg-sunken); border-radius: 0.5rem; touch-action: none; }
.w-mixing-edge { stroke: var(--border); stroke-width: 1; opacity: 0.7; }
.w-mixing-node { stroke: #fff; stroke-width: 1.2; }
.w-mixing-title {
  font-size: 0.8rem; font-weight: 600; color: var(--text-muted);
  text-align: center; margin-bottom: 0.3rem;
}
.w-mixing-tvd {
  font-family: var(--mono); font-size: 0.8rem; text-align: center;
  margin-top: 0.4rem; color: var(--text-muted);
}
.w-mixing-tvd strong { color: var(--text); }

/* ---------- Widget 5: w-sandpile ---------- */
.w-sandpile-wrap { background: var(--bg-sunken); border-radius: 0.5rem; padding: 0.5rem; }
.w-sandpile-canvas {
  display: block; width: 100%; height: auto; image-rendering: pixelated;
  border-radius: 0.4rem; cursor: crosshair; touch-action: none;
  aspect-ratio: 1 / 1;
}
.w-sandpile-hist { width: 100%; height: auto; display: block; background: var(--bg-sunken); border-radius: 0.5rem; }
.w-sandpile-dot { fill: var(--theme-geometry); }
.w-sandpile-fit { fill: none; stroke: var(--accent-dark); stroke-width: 1.6; stroke-dasharray: 4 3; }
.w-sandpile-axis { stroke: var(--border); stroke-width: 1; }
.w-sandpile-tick { fill: var(--text-muted); font-family: var(--mono); font-size: 9px; }
.w-sandpile-legend {
  display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.6rem;
  font-family: var(--mono); font-size: 0.75rem; color: var(--text-muted);
}
.w-sandpile-legend span { display: inline-flex; align-items: center; gap: 0.3rem; }
.w-sandpile-legend i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.btn.danger { background: var(--err); color: #fff; border-color: var(--err); }
.btn.danger:hover { background: #b91c1c; color: #fff; border-color: #b91c1c; }



/* ============ merged from ch12.widgets.css ============ */
/* ============================================================
   Chapter 12 — The Shape of Data · widget styles
   Prefixes: w-persist- · w-sensing- · w-transport- · w-knot-
   Loaded AFTER style.css. No new dependencies.
   ============================================================ */

/* === Widget 1 · persistence barcode builder === */
.w-persist-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr);
  gap: 0.75rem;
  align-items: stretch;
}
.w-persist-left { display: flex; }
.w-persist-left svg { width: 100%; height: auto; }
.w-persist-right {
  background: var(--bg-sunken);
  border-radius: 0.5rem;
  padding: 0.6rem 0.7rem;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.w-persist-bc-title {
  font-family: var(--mono); font-size: 0.78rem;
  color: var(--text-muted);
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 0.35rem;
}
.w-persist-legend { display: inline-flex; align-items: center; font-size: 0.72rem; }
.w-persist-legend .sw {
  display: inline-block; width: 10px; height: 10px; border-radius: 2px;
  margin-right: 0.25rem; vertical-align: -0.05em;
}
.w-persist-legend .sw.h0 { background: #4C6B8A; }
.w-persist-legend .sw.h1 { background: #7C8A4A; }
.w-persist-barcode { width: 100%; height: auto; flex: 1; min-height: 180px; }
.w-persist-preset-label { font-size: 0.8rem; color: var(--text-muted); }
.w-persist-slider-wrap {
  display: flex; align-items: center; gap: 0.6rem;
  font-size: 0.85rem; color: var(--text-muted);
  font-family: var(--mono); width: 100%;
}
.w-persist-slider-wrap input[type="range"] { flex: 1; accent-color: var(--accent); }
.w-persist-pt { transition: r 0.1s; }

@media (max-width: 767px) {
  .w-persist-layout { grid-template-columns: 1fr; }
}

/* === Widget 2 · sparse reconstruction === */
.w-sensing-status {
  font-size: 0.88rem; color: var(--text-muted);
  margin-top: 0.6rem; min-height: 1.3em; line-height: 1.5;
}
.w-sensing-status strong { color: var(--text); }
.w-sensing-status.good { color: var(--ok); }
.w-sensing-status.good strong { color: var(--ok); }
.w-sensing-status.bad { color: var(--err); }
.w-sensing-status.bad strong { color: var(--err); }
.w-sensing-status.warn { color: var(--warn); }
.w-sensing-status.warn strong { color: var(--warn); }
.w-sensing-slider-wrap {
  display: flex; align-items: center; gap: 0.6rem;
  font-size: 0.85rem; color: var(--text-muted); font-family: var(--mono);
}
.w-sensing-slider-wrap input[type="range"] { accent-color: var(--accent); min-width: 160px; }

/* === Widget 3 · earth mover === */
.w-transport-status {
  font-size: 0.88rem; color: var(--text-muted);
  margin-top: 0.6rem; min-height: 1.3em; line-height: 1.5;
}
.w-transport-status strong { color: var(--text); }

/* === Widget 4 · tricolor knot lab === */
.w-knot-tabs { margin-top: 0; margin-bottom: 0.25rem; }
.w-knot-status {
  font-size: 0.88rem; color: var(--text-muted);
  margin-top: 0.6rem; min-height: 1.3em; line-height: 1.5;
}
.w-knot-status strong { color: var(--text); }
.w-knot-status.good { color: var(--ok); }
.w-knot-status.good strong { color: var(--ok); }
.w-knot-status.warn { color: var(--warn); }
.w-knot-status.warn strong { color: var(--warn); }
.w-knot-status .btn { margin-left: 0.4rem; padding: 0.25rem 0.6rem; font-size: 0.8rem; }
.w-knot-arc { transition: stroke 0.15s; }


/* ============ merged from ch13.widgets.css ============ */
/* ============================================================
   Chapter 13 — "Machines Join the Proof" widget styles
   Prefixes: w-hackenbush-  w-beaver-  w-murmur-
   Appended after style.css. No inline <style> anywhere.
   ============================================================ */

/* ===== shared bits ===== */
.w13-note {
  font-size: 0.78rem; color: var(--text-muted);
  margin-top: 0.6rem; line-height: 1.5;
}
.w13-mode-row { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 0.6rem; align-items: center; }
.w13-narrate {
  font-family: var(--mono); font-size: 0.82rem;
  color: var(--text); background: var(--bg-sunken);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 0.6rem 0.8rem; margin-top: 0.7rem;
  min-height: 1.4em; line-height: 1.55;
}
.w13-narrate strong { color: var(--accent-dark); }
.w13-narrate .frac { color: var(--accent-secondary); font-weight: 700; }

/* ============================================================
   WIDGET 1 — Hackenbush  (w-hackenbush-)
   ============================================================ */
.w-hackenbush-wrap { background: var(--bg-sunken); border-radius: 0.5rem; padding: 0.5rem; }
svg.w-hackenbush-svg {
  width: 100%; height: auto; display: block;
  touch-action: none; user-select: none;
  aspect-ratio: 600 / 340;
}
.w-hackenbush-edge { cursor: pointer; transition: opacity 0.15s; }
.w-hackenbush-edge:hover { opacity: 0.55; }
.w-hackenbush-edge.falling { transition: transform 0.5s ease-in, opacity 0.5s ease-in; }
.w-hackenbush-node { pointer-events: none; }
.w-hackenbush-presets { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 0.6rem; }
.w-hackenbush-preset {
  font: inherit; font-size: 0.78rem; font-family: var(--mono);
  border: 1px solid var(--border); background: var(--bg-card);
  color: var(--text); border-radius: 999px;
  padding: 0.28rem 0.7rem; cursor: pointer;
  transition: all 0.15s ease-out;
}
.w-hackenbush-preset:hover { border-color: var(--accent); color: var(--accent-dark); }
.w-hackenbush-preset.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.w-hackenbush-value {
  font-family: var(--mono); font-size: 0.9rem;
  color: var(--text); margin-top: 0.4rem;
}
.w-hackenbush-value strong { color: var(--accent-secondary); font-size: 1.05rem; }
.w-hackenbush-turn { color: var(--text-muted); }
.w-hackenbush-stalklabel {
  font-family: var(--mono); font-weight: 700;
}

/* ============================================================
   WIDGET 2 — Busy Beaver garage  (w-beaver-)
   ============================================================ */
.w-beaver-presets { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 0.7rem; }
.w-beaver-preset {
  font: inherit; font-size: 0.78rem; font-family: var(--mono);
  border: 1px solid var(--border); background: var(--bg-card);
  color: var(--text); border-radius: 999px;
  padding: 0.28rem 0.7rem; cursor: pointer;
  transition: all 0.15s ease-out;
}
.w-beaver-preset:hover { border-color: var(--accent); color: var(--accent-dark); }
.w-beaver-preset.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.w-beaver-tape {
  display: flex; gap: 2px; justify-content: center;
  background: var(--bg-sunken); border-radius: 0.5rem;
  padding: 0.7rem 0.4rem; overflow: hidden; margin-bottom: 0.6rem;
}
.w-beaver-cell {
  flex: 0 0 auto;
  width: 20px; height: 30px;
  display: grid; place-items: center;
  font-family: var(--mono); font-size: 0.78rem; font-weight: 600;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 4px; color: var(--text-muted);
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.w-beaver-cell.on { background: var(--accent-secondary); color: #fff; border-color: var(--accent-secondary); }
.w-beaver-cell.head { outline: 2px solid var(--accent); outline-offset: 1px; z-index: 2; }

.w-beaver-stats { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: center; margin-bottom: 0.4rem; }
.w-beaver-stat {
  font-family: var(--mono); font-size: 0.82rem; color: var(--text-muted);
  background: var(--bg-sunken); border: 1px solid var(--border);
  border-radius: 8px; padding: 0.3rem 0.6rem;
}
.w-beaver-stat strong { color: var(--text); }
.w-beaver-badge {
  font-family: var(--mono); font-size: 0.82rem; font-weight: 700;
  background: var(--accent); color: #fff;
  border-radius: 8px; padding: 0.3rem 0.7rem;
}
.w-beaver-badge.halt { background: var(--ok); }

.w-beaver-halt {
  display: none;
  background: var(--ok-light); border: 1px solid #b6e3c4;
  border-left: 3px solid var(--ok);
  border-radius: var(--radius);
  padding: 0.8rem 1rem; margin: 0.7rem 0;
  font-size: 0.9rem; color: #1b5e2e;
}
.w-beaver-halt.show { display: block; }
.w-beaver-halt strong { color: #144a23; }

.w-beaver-progress {
  height: 6px; background: var(--bg-sunken); border-radius: 999px;
  overflow: hidden; margin: 0.5rem 0; border: 1px solid var(--border);
  display: none;
}
.w-beaver-progress.show { display: block; }
.w-beaver-progress-bar { height: 100%; width: 0%; background: var(--accent); transition: width 0.2s linear; }

/* transition table editor */
.w-beaver-table-wrap { overflow-x: auto; margin: 0.7rem 0; }
table.w-beaver-table {
  border-collapse: collapse; font-family: var(--mono); font-size: 0.78rem;
  width: 100%; min-width: 460px;
}
.w-beaver-table th, .w-beaver-table td {
  border: 1px solid var(--border); padding: 0.3rem 0.45rem; text-align: center;
}
.w-beaver-table th { background: var(--bg-sunken); color: var(--text-muted); font-weight: 600; }
.w-beaver-table td.statecell { background: var(--bg-sunken); font-weight: 700; color: var(--accent-dark); }
.w-beaver-table .curstate { box-shadow: inset 0 0 0 2px var(--accent); }
.w-beaver-table select {
  font: inherit; font-family: var(--mono); font-size: 0.74rem;
  border: 1px solid var(--border); background: var(--bg-card); color: var(--text);
  border-radius: 4px; padding: 0.1rem 0.15rem; cursor: pointer;
}
.w-beaver-table .trip { display: inline-flex; gap: 2px; }

/* ============================================================
   WIDGET 3 — Murmuration explorer  (w-murmur-)
   ============================================================ */
.w-murmur-wrap { background: var(--bg-sunken); border-radius: 0.5rem; padding: 0.5rem; }
svg.w-murmur-svg {
  width: 100%; height: auto; display: block;
  aspect-ratio: 640 / 300;
}
.w-murmur-row { display: flex; flex-wrap: wrap; gap: 0.8rem; align-items: center; margin-top: 0.7rem; }
.w-murmur-slider { display: flex; align-items: center; gap: 0.5rem; font-size: 0.82rem; color: var(--text-muted); }
.w-murmur-slider input[type=range] { width: 160px; accent-color: var(--accent); }
.w-murmur-slider .val { font-family: var(--mono); color: var(--text); min-width: 3.5em; }
.w-murmur-legend { display: flex; gap: 1rem; font-size: 0.8rem; flex-wrap: wrap; }
.w-murmur-legend span { display: inline-flex; align-items: center; gap: 0.35rem; }
.w-murmur-legend .swatch { width: 14px; height: 3px; border-radius: 2px; display: inline-block; }

/* ============================================================
   FINALE next-card extras (gradient/arrow come from style.css)
   ============================================================ */
.next-card.finale .big { font-size: 2rem; }
.next-card.finale .t2 {
  font-family: 'Fraunces', Georgia, serif;
  font-size: 1.25rem; font-weight: 600; letter-spacing: -0.01em;
}
.next-card.finale .arrow { font-size: 1.7rem; color: var(--accent-secondary); }


/* ============ merged from map-extra.widgets.css ============ */
/* ============================================================
   map-extra.widgets.css
   Extra widgets for the Map of Mathematics landing page.
   Only loaded by index.html (alongside style.css).
   ============================================================ */

/* Hero call-to-action pill — sits under the hero subtitle.
   fadeUp animation matches its hero siblings; the global
   prefers-reduced-motion rule in style.css already neutralises it. */
.hero-cta {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  padding: 0.6rem 1.3rem;
  border-radius: 999px;
  font-size: 1rem;
  font-weight: 600;
  transition: background 0.15s ease-out;
  animation: fadeUp 0.6s ease-out 0.28s both;
}
.hero-cta:hover {
  background: var(--accent-dark);
  color: #fff;
  text-decoration: none;
}

/* Filled chapter badge — sits in each card's .field-foot, ahead of any
   .badge-deepdive. Same pill geometry as .badge-deepdive but filled. */
.badge-chapter {
  display: inline-block;
  font-size: 0.8rem;
  font-weight: 500;
  color: #fff;
  text-decoration: none;
  background: var(--card-accent);
  border: 1px solid var(--card-accent);
  border-radius: 999px;
  padding: 0.3rem 0.7rem;
  transition: filter 0.15s ease-out;
}
.badge-chapter:hover {
  filter: brightness(0.9);
  color: #fff;
  text-decoration: none;
}

/* === mobile fix: long formula/code chips may wrap (added post-merge) === */
@media (max-width: 767px) {
  .m, code.m { white-space: normal; overflow-wrap: anywhere; }
}
