/* Public site stylesheet for Anastasios Kyrillidis · Books & COMP 282
 * Direction C ("Workbench") for hub and landing; C-flow for chapter web preview.
 * Fonts: Instrument Serif (structural display), Literata (textbook prose),
 *        DM Sans (blueprint UI), Fira Code (code & telemetry)
 */

:root {
  --paper: #f3f6fa;
  --surface: #ffffff;
  --surface-tint: #e8eef6;
  --ink: #0f172a;
  --ink-muted: #475569;
  --cobalt: #1d4ed8;
  --cobalt-dark: #1e3a8a;
  --crimson: #dc2626;
  --emerald: #0d9488;
  --grid-line: #cbd5e1;
  --grid-strong: #94a3b8;
  --focus-ring: #1d4ed8;
  --bar-h: 52px;
  --font-display: 'Instrument Serif', Georgia, serif;
  --font-prose: 'Literata', Georgia, serif;
  --font-ui: 'DM Sans', system-ui, -apple-system, sans-serif;
  --font-mono: 'Fira Code', ui-monospace, monospace;
}

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

html {
  scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

body {
  margin: 0;
  background-color: var(--paper);
  background-image:
    linear-gradient(to right, rgba(148, 163, 184, 0.12) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(148, 163, 184, 0.12) 1px, transparent 1px);
  background-size: 32px 32px;
  color: var(--ink);
  font-family: var(--font-ui);
  line-height: 1.6;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--cobalt);
  text-underline-offset: 3px;
}

pre,
code,
kbd,
samp {
  font-family: var(--font-mono);
}

:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
}

[id] {
  scroll-margin-top: calc(var(--bar-h) + 14px);
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 8px;
  background: var(--cobalt);
  color: #fff;
  padding: 8px 14px;
  font-weight: 700;
  z-index: 1000;
}
.skip-link:focus {
  left: 12px;
}

/* ==========================================================================
 * Blueprint Top Bar
 * ========================================================================== */
.bp-bar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(6px);
  border-bottom: 2px solid var(--ink);
  padding: 10px 20px;
}
.bp-bar-inner {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.bp-brand {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.bp-tag {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  background: var(--ink);
  color: #fff;
  padding: 2px 7px;
  letter-spacing: 0.05em;
  line-height: 1.4;
}
.bp-brand a {
  color: var(--ink);
  font-weight: 700;
  text-decoration: none;
}
.bp-brand a:hover {
  color: var(--cobalt);
  text-decoration: underline;
}
.bp-brand a.bp-tag {
  color: #fff;
  font-weight: 600;
  text-decoration: none;
}
.bp-brand a.bp-tag:hover {
  background: var(--cobalt);
  color: #fff;
  text-decoration: none;
}
.bp-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
  font-size: 0.88rem;
  min-width: 0;
}
.bp-nav a {
  color: var(--ink-muted);
  text-decoration: none;
  font-weight: 600;
}
.bp-nav a:hover,
.bp-nav a[aria-current="page"] {
  color: var(--cobalt);
  text-decoration: underline;
}

.search-trigger {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--grid-strong);
  padding: 3px 9px;
  font-family: var(--font-ui);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}
.search-trigger:hover {
  border-color: var(--cobalt);
  color: var(--cobalt);
}
.search-trigger kbd {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  background: #fff;
  border: 1px solid var(--grid-line);
  padding: 1px 4px;
  color: var(--ink-muted);
}

/* ==========================================================================
 * Search Modal ([data-search])
 * ========================================================================== */
.search-backdrop[hidden] {
  display: none !important;
}
.search-backdrop {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(15, 23, 42, 0.48);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 72px 16px 24px;
}
.search-modal {
  width: 100%;
  max-width: 580px;
  background: var(--surface);
  border: 2px solid var(--ink);
  box-shadow: 0 18px 40px rgba(15, 23, 42, 0.22);
  overflow: hidden;
}
.search-header {
  background: var(--ink);
  color: #fff;
  padding: 8px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
.search-label {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.search-close {
  background: transparent;
  color: #e2e8f0;
  border: 1px solid #64748b;
  padding: 2px 7px;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  cursor: pointer;
}
.search-close:hover {
  color: #fff;
  border-color: #fff;
}
.search-input {
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--grid-line);
  padding: 12px 14px;
  font-family: var(--font-ui);
  font-size: 0.96rem;
  color: var(--ink);
  background: #fff;
}
.search-input:focus {
  outline: none;
  background: #f8fafc;
}
.search-results {
  list-style: none;
  margin: 0;
  padding: 6px;
  max-height: 360px;
  overflow-y: auto;
}
.search-item {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 8px 10px;
  text-decoration: none;
  color: var(--ink);
  border-left: 3px solid transparent;
}
.search-item:hover,
.search-item.is-selected {
  background: var(--surface-tint);
  border-left-color: var(--cobalt);
}
.search-badge {
  flex-shrink: 0;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--cobalt);
  background: #fff;
  border: 1px solid var(--grid-line);
  padding: 1px 6px;
}
.search-title {
  font-size: 0.88rem;
  font-weight: 500;
  min-width: 0;
}
.search-empty {
  padding: 16px 12px;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--ink-muted);
}

/* ==========================================================================
 * Blueprint Frame Container (Hub & Landing)
 * ========================================================================== */
.bp-container {
  max-width: 1320px;
  margin: 28px auto 60px;
  padding: 0 20px;
}
.bp-sheet {
  background: var(--surface);
  border: 2px solid var(--ink);
}
.bp-hero-grid {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  border-bottom: 2px solid var(--ink);
}
.bp-hero-copy {
  padding: 36px;
  border-right: 1px solid var(--grid-line);
  min-width: 0;
}
.bp-hero-visual {
  padding: 24px;
  background: var(--paper);
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
}
.bp-code-label {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--cobalt);
  display: block;
  margin-bottom: 8px;
}
.bp-title {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(2.3rem, 4.5vw, 3.6rem);
  line-height: 1.04;
  margin: 0 0 16px;
}
.bp-lead {
  font-family: var(--font-prose);
  font-size: 1.06rem;
  line-height: 1.7;
  color: var(--ink-muted);
  margin: 0 0 24px;
  max-width: 60ch;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}
.btn {
  display: inline-flex;
  align-items: center;
  padding: 10px 18px;
  font-size: 0.9rem;
  font-weight: 700;
  text-decoration: none;
  border: 2px solid var(--ink);
  cursor: pointer;
}
.btn-cobalt {
  background: var(--cobalt);
  border-color: var(--cobalt);
  color: #fff;
}
.btn-cobalt:hover {
  background: var(--cobalt-dark);
}
.btn-plain {
  background: #fff;
  color: var(--ink);
}
.btn-plain:hover {
  background: var(--surface-tint);
}
.pdf-action {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}
.pdf-meta {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--ink-muted);
}

.spec-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border-bottom: 1px solid var(--grid-line);
  background: var(--surface-tint);
  font-family: var(--font-mono);
  font-size: 0.78rem;
}
.spec-cell {
  padding: 12px 18px;
  border-right: 1px solid var(--grid-line);
  min-width: 0;
}
.spec-cell:last-child {
  border-right: 0;
}
.spec-cell span {
  display: block;
  color: var(--ink-muted);
  font-size: 0.68rem;
  text-transform: uppercase;
}

.matrix-2col {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}
.matrix-3col {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
.matrix-cell {
  padding: 28px 32px;
  border-right: 1px solid var(--grid-line);
  border-bottom: 1px solid var(--grid-line);
  min-width: 0;
}
.matrix-2col > .matrix-cell:nth-child(2n) {
  border-right: 0;
}
.matrix-3col > .matrix-cell {
  padding: 26px 24px;
  display: flex;
  flex-direction: column;
}
.matrix-3col > .matrix-cell:nth-child(3n) {
  border-right: 0;
}
.matrix-3col > .matrix-cell > p {
  margin-top: 0;
  margin-bottom: 18px;
}
.matrix-3col > .matrix-cell > .tour-visual,
.matrix-3col > .matrix-cell > [data-codebox] {
  margin-bottom: 18px;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.matrix-3col > .matrix-cell > [data-codebox] > .cb-shell {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.matrix-3col > .matrix-cell > .btn {
  margin-top: auto;
  align-self: flex-start;
}
.matrix-cell h2,
.matrix-cell h3 {
  margin-top: 0;
}

/* Tour card static visuals (Cards 01 & 03 on COMP 282 landing page) */
.tour-visual {
  background: #fff;
  border: 2px solid var(--ink);
  padding: 12px;
  justify-content: space-between;
  gap: 8px;
}
.tv-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.tv-terms {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.tv-term-row {
  display: grid;
  grid-template-columns: 3.1rem minmax(0, 1fr) auto;
  gap: 8px;
  align-items: baseline;
  background: var(--paper);
  border: 1px solid var(--grid-line);
  border-left: 3px solid var(--emerald);
  padding: 6px 9px;
  font-family: var(--font-mono);
  font-size: 0.74rem;
  min-width: 0;
}
.tv-term-idx {
  color: var(--ink-muted);
  font-size: 0.68rem;
}
.tv-term-prod {
  color: var(--ink);
  min-width: 0;
}
.tv-term-run {
  color: var(--emerald);
  font-weight: 600;
  font-size: 0.7rem;
  white-space: nowrap;
}
.tv-sum-eq {
  background: var(--surface-tint);
  border: 1px solid var(--grid-line);
  padding: 8px 10px;
  font-family: var(--font-mono);
  font-size: 0.77rem;
  font-weight: 600;
  color: var(--ink);
  overflow-x: auto;
}
.tv-foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
}
.tv-mini-chart {
  width: 100%;
  height: auto;
  display: block;
  background: #fff;
  border: 1px solid var(--grid-line);
}
.tv-chart-foot {
  margin-top: 0;
}

/* Hub full-width book card: book info + actions on left, six-chapter index on right */
.hub-book-card {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.95fr);
  grid-template-rows: 1fr auto;
  border-bottom: 1px solid var(--grid-line);
  background: var(--surface);
}
.hub-book-info {
  grid-column: 1;
  grid-row: 1;
  padding: 32px 36px 20px;
  min-width: 0;
}
.hub-book-info h2 {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(1.9rem, 2.8vw, 2.45rem);
  line-height: 1.08;
  margin: 0 0 12px;
}
.hub-book-blurb {
  font-family: var(--font-prose);
  font-size: 1rem;
  line-height: 1.68;
  color: var(--ink-muted);
  margin: 0;
  max-width: 58ch;
}
.hub-book-actions {
  grid-column: 1;
  grid-row: 2;
  padding: 0 36px 32px;
  align-self: end;
}
.hub-book-chapters {
  grid-column: 2;
  grid-row: 1 / 3;
  padding: 28px 34px;
  background: var(--paper);
  border-left: 1px solid var(--grid-line);
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.hub-chapter-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border-top: 1px solid var(--grid-line);
}
.hub-chapter-list li {
  display: grid;
  grid-template-columns: 2rem minmax(0, 1fr) auto;
  gap: 8px;
  align-items: baseline;
  padding: 8px 0;
  border-bottom: 1px solid var(--grid-line);
  font-size: 0.9rem;
  line-height: 1.4;
}
.hub-ch-num {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--cobalt);
}
.hub-ch-title {
  font-weight: 600;
  color: var(--ink);
  min-width: 0;
}
.hub-ch-page {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--ink-muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.hero-stage-card {
  background: #fff;
  border: 1px solid var(--grid-strong);
  padding: 12px;
}
.hero-stage-svg {
  width: 100%;
  height: auto;
  display: block;
  background: #f8fafc;
  border: 1px solid var(--grid-line);
}
.hs-grid { stroke: #e2e8f0; stroke-width: 1; }
.hs-axis { stroke: #64748b; stroke-width: 1.4; }
.hs-x { stroke: var(--cobalt); stroke-width: 3; }
.hs-x-dot { fill: var(--cobalt); }
.hs-y { stroke: var(--crimson); stroke-width: 3; }
.hs-y-dot { fill: var(--crimson); }
.hs-proj { stroke: var(--emerald); stroke-width: 3.4; }
.hs-drop { stroke: #64748b; stroke-width: 1.3; stroke-dasharray: 4 4; }
.hero-stage-bar {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--ink-muted);
}
.hero-stage-toggle {
  background: var(--surface-tint);
  color: var(--ink);
  border: 1px solid var(--grid-strong);
  padding: 4px 9px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  cursor: pointer;
}

.bp-section-head {
  padding: 20px 32px;
  background: var(--ink);
  color: #fff;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.bp-section-head h2 {
  margin: 0;
  font-size: 1.15rem;
  letter-spacing: 0.02em;
}
.syllabus-rows {
  list-style: none;
  margin: 0;
  padding: 0;
}
.syllabus-rows li {
  display: grid;
  grid-template-columns: 110px 1fr 1.3fr;
  gap: 20px;
  padding: 18px 32px;
  border-bottom: 1px solid var(--grid-line);
  align-items: baseline;
}
.syl-code {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--cobalt);
  font-weight: 600;
}
.syllabus-rows h3 {
  margin: 0;
  font-size: 1.05rem;
}
.syllabus-rows h3 a {
  color: var(--ink);
  text-decoration: underline;
  text-decoration-color: var(--grid-strong);
  text-underline-offset: 3px;
}
.syllabus-rows h3 a:hover,
.syllabus-rows h3 a:focus-visible {
  color: var(--cobalt);
  text-decoration-color: var(--cobalt);
}
.syllabus-rows p {
  margin: 0;
  font-family: var(--font-prose);
  font-size: 0.96rem;
  color: var(--ink-muted);
}

.bp-footer {
  padding: 24px 32px;
  background: var(--surface-tint);
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 16px;
  font-size: 0.88rem;
}

/* ==========================================================================
 * Chapter 1 TOC, Prose, Stations & Code Session (Phone-first < 1080px)
 * ========================================================================== */
.workbench-flow-layout {
  display: block;
  max-width: 1440px;
  margin: 0 auto;
  min-width: 0;
}

.wb-toc-rail {
  background: var(--surface);
  border-bottom: 1px solid var(--grid-line);
  min-width: 0;
}
.wb-toc-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--surface-tint);
  color: var(--ink);
  border: 0;
  padding: 10px 20px;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  cursor: pointer;
  text-align: left;
}
.wb-toc-toggle:hover {
  color: var(--cobalt);
  background: #dde6f2;
}
.wb-toc-toggle:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: -3px;
}
.wb-toc-caret {
  width: 8px;
  height: 8px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
  margin-top: -3px;
  flex-shrink: 0;
  transition: transform 0.15s ease;
}
.wb-toc-toggle[aria-expanded="true"] .wb-toc-caret {
  transform: rotate(-135deg);
  margin-top: 3px;
}
@media (max-width: 1079.98px) {
  .wb-toc-toggle[aria-expanded="false"] + .wb-toc {
    display: none;
  }
  .wb-toc-toggle[aria-expanded="true"] + .wb-toc {
    display: block;
    border-top: 1px solid var(--grid-line);
  }
}
.wb-toc {
  background: var(--surface);
  padding: 16px 20px;
  font-size: 0.8rem;
}
.wb-toc-title {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  text-transform: uppercase;
  color: var(--cobalt);
  margin: 0 0 10px;
}
.wb-toc ul {
  list-style: none;
  padding: 0;
  margin: 0;
}
.wb-toc li {
  margin-bottom: 5px;
}
.wb-toc-sec {
  display: block;
  padding: 4px 6px;
  color: var(--ink);
  text-decoration: none;
  font-weight: 700;
  border-left: 2px solid transparent;
  line-height: 1.35;
}
.wb-toc-sec:hover,
.wb-toc-sec[aria-current="location"] {
  background: var(--surface-tint);
  color: var(--cobalt);
  border-left-color: var(--cobalt);
}
.wb-toc-muted {
  color: #64748b;
  display: block;
  padding: 2px 0;
}
.wb-toc-sub {
  padding-left: 10px !important;
  margin: 4px 0 8px !important;
  border-left: 2px solid var(--grid-line);
}
.wb-toc-sub a {
  display: block;
  padding: 3px 6px;
  color: var(--ink-muted);
  text-decoration: none;
  font-weight: 500;
  border-left: 2px solid transparent;
  margin-left: -2px;
  line-height: 1.35;
}
.wb-toc-sub a:hover,
.wb-toc-sub a[aria-current="location"] {
  background: var(--surface-tint);
  color: var(--cobalt);
  font-weight: 600;
  border-left-color: var(--cobalt);
}

.wb-flow-main {
  background: var(--surface);
  min-width: 0;
}

.book-text {
  font-family: var(--font-prose);
  font-size: 1.08rem;
  line-height: 1.76;
  color: var(--ink);
  min-width: 0;
}

.wb-flow-grid {
  display: block;
  max-width: 68ch;
  margin: 0 auto;
  padding: 24px 20px 56px;
  min-width: 0;
}

.flow-prose {
  min-width: 0;
}

.wb-chap-header {
  border-bottom: 2px solid var(--ink);
  padding-bottom: 14px;
  margin-bottom: 24px;
  font-family: var(--font-ui);
}
.wb-chap-header h1 {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(1.9rem, 3vw, 2.5rem);
  margin: 4px 0 0;
  line-height: 1.1;
}
.wb-preview-note {
  margin: 10px 0 0;
  font-family: var(--font-ui);
  font-size: 0.92rem;
  line-height: 1.5;
  color: var(--ink-muted);
}
.wb-preview-note a {
  font-weight: 600;
}
.book-abstract {
  font-size: 0.98rem;
  font-style: italic;
  line-height: 1.68;
  color: var(--ink-muted);
  margin: 0 0 1rem;
}
.book-abstract p {
  margin: 0 0 0.6rem;
}
.book-abstract p:last-child {
  margin-bottom: 0;
}
.book-keywords {
  font-family: var(--font-ui);
  font-size: 0.84rem;
  line-height: 1.5;
  color: var(--ink-muted);
  background: var(--paper);
  border: 1px solid var(--grid-line);
  padding: 8px 12px;
  margin: 0 0 1.8rem;
}
.kw-label {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--cobalt);
  margin-right: 6px;
}

.book-text h2 {
  font-family: var(--font-ui);
  font-size: 1.42rem;
  font-weight: 700;
  margin: 2.4rem 0 0.8rem;
  padding-top: 0.6rem;
  border-top: 2px solid var(--grid-line);
  line-height: 1.28;
}
.book-text h3 {
  font-family: var(--font-ui);
  font-size: 1.18rem;
  font-weight: 700;
  margin: 1.85rem 0 0.65rem;
  padding-top: 0.35rem;
  border-top: 1px solid var(--surface-tint);
  line-height: 1.32;
}
.book-subsubsection {
  font-family: var(--font-prose);
  font-size: 1.05rem;
  font-style: italic;
  font-weight: 600;
  margin: 1.4rem 0 0.45rem;
  color: var(--ink);
}
.book-paragraph {
  font-family: var(--font-ui);
  font-size: 0.98rem;
  font-weight: 700;
}
.book-sc {
  font-variant: small-caps;
  letter-spacing: 0.03em;
}
.sec-num {
  font-family: var(--font-mono);
  color: var(--cobalt);
  font-size: 0.92rem;
  margin-right: 6px;
}

.book-env,
.book-example {
  background: var(--paper);
  border: 1px solid var(--grid-line);
  border-left: 4px solid var(--cobalt);
  padding: 14px 18px;
  margin: 1.4rem 0;
  min-width: 0;
}
.book-definition {
  border-left-color: var(--emerald);
  background: #f4fbfa;
}
.book-theorem,
.book-lemma,
.book-corollary,
.book-proposition {
  border-left-color: var(--ink);
  background: var(--surface-tint);
}
.book-remark {
  border-left-color: var(--grid-strong);
}
.book-env > p:first-child,
.book-example > p:first-child { margin-top: 0; }
.book-env > p:last-child,
.book-example > p:last-child { margin-bottom: 0; }
.ex-label,
.env-label {
  font-family: var(--font-ui);
  font-size: 0.95rem;
}
.wb-load-btn {
  margin-top: 10px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #fff;
  color: var(--cobalt);
  border: 1px solid var(--cobalt);
  padding: 4px 10px;
  font-family: var(--font-mono);
  font-size: 0.74rem;
  font-weight: 600;
  cursor: pointer;
}
.wb-load-btn:hover {
  background: var(--cobalt);
  color: #fff;
}

.book-figure {
  margin: 1.8rem 0;
  background: #fff;
  border: 1px solid var(--grid-line);
  padding: 16px;
  min-width: 0;
}
.book-figure img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 0 auto 12px;
}
.book-figure-compact img {
  max-width: min(280px, 100%);
}
.book-figure > figcaption {
  font-size: 0.92rem;
  line-height: 1.55;
  color: var(--ink-muted);
  border-top: 1px solid var(--surface-tint);
  padding-top: 10px;
}
.book-subfigures {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}
.book-subfigure {
  margin: 0;
  padding: 10px;
  background: var(--paper);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.book-subfigure > figcaption {
  font-size: 0.82rem;
  line-height: 1.45;
}
@media (max-width: 680px) {
  .book-subfigures {
    grid-template-columns: minmax(0, 1fr);
  }
}

.book-equation {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 1rem 0;
  min-width: 0;
}
.book-eq-math {
  flex: 1;
  min-width: 0;
  overflow-x: auto;
}
.book-eq-num {
  flex-shrink: 0;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--ink-muted);
}

.book-table-wrap {
  margin: 1.8rem 0;
  background: #fff;
  border: 1px solid var(--grid-line);
  padding: 16px;
  min-width: 0;
}
.book-table-wrap > figcaption {
  font-size: 0.92rem;
  line-height: 1.5;
  color: var(--ink-muted);
  margin-bottom: 12px;
}
.book-table-scroll {
  overflow-x: auto;
  max-width: 100%;
}
.book-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
  line-height: 1.5;
}
.book-table th,
.book-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--grid-line);
  vertical-align: top;
}
.book-table th {
  font-family: var(--font-ui);
  font-weight: 700;
  background: var(--paper);
  border-top: 2px solid var(--ink);
  border-bottom: 2px solid var(--ink);
}

.book-algorithm {
  margin: 1.8rem 0;
  background: #fff;
  border: 2px solid var(--ink);
  padding: 0;
  min-width: 0;
}
.book-algorithm > figcaption {
  font-family: var(--font-ui);
  font-size: 0.94rem;
  line-height: 1.45;
  color: var(--ink);
  background: var(--paper);
  border-bottom: 1.5px solid var(--ink);
  padding: 10px 14px;
}
.alg-body {
  padding: 10px 14px;
  font-size: 0.95rem;
  line-height: 1.62;
  overflow-x: auto;
}
.alg-line {
  display: grid;
  grid-template-columns: 2.2rem minmax(0, 1fr);
  gap: 8px;
  align-items: baseline;
  padding: 2px 0;
}
.alg-io {
  padding-bottom: 4px;
}
.alg-ln {
  font-family: var(--font-mono);
  font-size: 0.76rem;
  color: var(--ink-muted);
  text-align: right;
  user-select: none;
  font-variant-numeric: tabular-nums;
}
.alg-content {
  padding-left: calc(var(--alg-indent, 0) * 1.35rem);
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: baseline;
  column-gap: 14px;
  row-gap: 2px;
  min-width: 0;
}
.alg-stmt {
  min-width: 0;
}
.alg-kw {
  font-family: var(--font-ui);
  font-weight: 700;
  color: var(--ink);
}
.alg-comment {
  font-size: 0.86rem;
  color: var(--ink-muted);
  margin-left: auto;
}
.alg-cmt-mark {
  color: var(--cobalt);
  font-size: 0.8em;
  margin-right: 3px;
}

.book-chap-nav {
  margin-top: 2.8rem;
  padding-top: 1.5rem;
  border-top: 2px solid var(--ink);
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  font-family: var(--font-ui);
}
.chap-nav-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 16px;
  background: var(--paper);
  border: 1px solid var(--grid-strong);
  text-decoration: none;
  color: var(--ink);
  min-width: 0;
}
.chap-nav-card:hover,
.chap-nav-card:focus-visible {
  background: var(--surface-tint);
  border-color: var(--cobalt);
}
.chap-nav-prev {
  grid-column: 1;
}
.chap-nav-next {
  grid-column: 2;
  text-align: right;
}
.chap-nav-dir {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--cobalt);
}
.chap-nav-title {
  font-size: 0.94rem;
  font-weight: 600;
  line-height: 1.35;
  color: var(--ink);
}
@media (max-width: 680px) {
  .book-chap-nav {
    grid-template-columns: minmax(0, 1fr);
  }
  .chap-nav-prev,
  .chap-nav-next {
    grid-column: 1;
    text-align: left;
  }
}

.book-custom-list {
  list-style: none;
  padding-left: 0;
  margin: 1rem 0;
}
.book-custom-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  align-items: baseline;
  margin-bottom: 0.85rem;
}
.book-item-marker {
  font-family: var(--font-ui);
  min-width: 2rem;
}
.book-item-body > p:first-child {
  margin-top: 0;
}
.book-item-body > p:last-child {
  margin-bottom: 0;
}

.book-footnotes {
  margin: 2rem 0 1rem;
  padding: 12px 16px;
  background: var(--paper);
  border-top: 1px solid var(--grid-strong);
  font-size: 0.88rem;
  line-height: 1.55;
  color: var(--ink-muted);
}
.book-footnotes-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.book-footnotes-list li {
  margin-bottom: 6px;
}
.book-footnotes-list li:last-child {
  margin-bottom: 0;
}
.fn-num {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--cobalt);
  margin-right: 4px;
}
.fn-ref a {
  font-family: var(--font-mono);
  font-size: 0.75em;
  font-weight: 700;
  text-decoration: none;
  padding: 0 2px;
}
.fn-back {
  text-decoration: none;
  font-family: var(--font-mono);
  font-size: 0.82em;
}

.book-inftybar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin: 1.8rem 0;
  color: var(--ink-muted);
}
.inftybar-rule {
  width: 72px;
  height: 1px;
  background: var(--grid-strong);
}
.inftybar-sym {
  font-size: 1rem;
  line-height: 1;
}
.book-center {
  text-align: center;
  margin: 1rem 0;
}
.book-text code {
  font-size: 0.88em;
  background: var(--paper);
  border: 1px solid var(--grid-line);
  padding: 1px 5px;
}
.book-text pre code {
  background: transparent;
  border: 0;
  padding: 0;
  font-size: inherit;
}

.math-nowrap {
  white-space: nowrap;
}

/* ==========================================================================
 * Stations ([data-station])
 * ========================================================================== */
.wb-station {
  margin: 1.4rem 0;
  min-width: 0;
  font-family: var(--font-ui);
  line-height: 1.5;
}
.wb-station-panel {
  min-width: 0;
}
.wb-station-head {
  background: var(--ink);
  color: #fff;
  border: 2px solid var(--ink);
  border-bottom: 0;
  padding: 6px 10px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.04em;
}
.wb-station-pin {
  width: 8px;
  height: 8px;
  border: 1.5px solid #94a3b8;
  background: transparent;
  flex-shrink: 0;
}
.wb-station.is-pinned .wb-station-pin {
  background: #60a5fa;
  border-color: #60a5fa;
  box-shadow: 0 0 0 2px rgba(96, 165, 250, 0.32);
}
.wb-station-id {
  text-transform: uppercase;
  color: #cbd5e1;
}
.wb-station-anchor-link {
  margin-left: auto;
  color: #93c5fd;
  text-decoration: none;
  font-weight: 600;
}
.wb-station-anchor-link:hover {
  color: #fff;
  text-decoration: underline;
}

/* ==========================================================================
 * Desktop 3-Column Flow Layout (1080px and wider)
 * ========================================================================== */
@media (min-width: 1080px) {
  .workbench-flow-layout {
    --toc-col: clamp(185px, 14vw, 210px);
    --station-col: clamp(400px, 32vw, 460px);
    display: grid;
    grid-template-columns: var(--toc-col) minmax(0, 1fr) var(--station-col);
    align-items: stretch;
  }

  .wb-toc-rail {
    grid-column: 1 / 2;
    grid-row: 1;
    z-index: 10;
    border-bottom: 0;
    border-right: 1px solid var(--grid-line);
    background: var(--surface);
  }

  .wb-toc-toggle {
    display: none;
  }

  .wb-toc {
    display: block;
    position: sticky;
    top: var(--bar-h);
    height: calc(100vh - var(--bar-h));
    overflow-y: auto;
    padding: 20px 16px;
  }

  .wb-flow-main {
    grid-column: 1 / -1;
    grid-row: 1;
    background: transparent;
  }

  .wb-flow-grid {
    max-width: none;
    margin: 0;
    padding: 0;
    display: grid;
    grid-template-columns: var(--toc-col) minmax(0, 1fr) var(--station-col);
    align-items: stretch;
  }

  .flow-prose {
    grid-column: 2 / 3;
    grid-row: var(--prose-row, auto);
    background: var(--surface);
    border-right: 2px solid var(--ink);
    padding-top: 0.6rem;
    padding-bottom: 1.2rem;
    padding-left: clamp(36px, 3.6vw, 48px);
    padding-right: clamp(28px, 3vw, 42px);
    min-width: 0;
  }

  .flow-prose > * {
    max-width: 64ch;
    margin-left: auto;
    margin-right: auto;
  }

  .flow-prose > :first-child {
    margin-top: 0;
  }
  .flow-prose > :last-child {
    margin-bottom: 0;
  }

  .flow-prose-first {
    padding-top: 36px;
  }
  .flow-prose-after-session {
    padding-top: 2.2rem;
  }
  .flow-prose-after-session > h2:first-child,
  .flow-prose-after-session > h3:first-child {
    border-top: 0;
    padding-top: 0;
  }
  .flow-prose-last {
    padding-bottom: 72px;
  }

  .code-session {
    grid-column: 1 / -1;
    grid-row: var(--cs-row, auto);
    position: relative;
    z-index: 20;
  }

  /* Right-column stations aligned to anchor row & spanning down to next anchor */
  .wb-station {
    grid-column: 3 / 4;
    grid-row: var(--wb-row, auto);
    margin: 0;
    padding: 0 14px 24px 14px;
  }

  .wb-station-panel {
    position: sticky;
    top: calc(var(--bar-h) + 14px);
  }

  /* Quiet anchor mark in the left gutter of the reading column */
  .station-anchor {
    position: relative;
  }
  .station-anchor::before {
    content: "";
    position: absolute;
    left: -22px;
    top: 0.52em;
    width: 9px;
    height: 9px;
    border: 1.5px solid var(--grid-strong);
    background: var(--surface);
    transition: background-color 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease;
  }
  .book-example.station-anchor::before {
    left: -26px;
    top: 18px;
  }
  h2.station-anchor::before,
  h3.station-anchor::before {
    left: -22px;
    top: 0.78em;
  }
  .station-anchor.is-pinned::before {
    background: var(--cobalt);
    border-color: var(--cobalt);
    box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.2);
  }
}

/* ==========================================================================
 * Widget ([data-widget="inner-product"]) in Blueprint Workbench Style
 * ========================================================================== */
.ip-widget {
  background: #fff;
  border: 2px solid var(--ink);
  padding: 14px;
  font-family: var(--font-ui);
  font-size: 0.84rem;
  min-width: 0;
}
.ip-header,
.ip-playback-head {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}
.ip-eyebrow {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  text-transform: uppercase;
  color: var(--cobalt);
}
.ip-title { margin: 0; font-size: 1.02rem; }
.ip-subtitle { margin: 0; font-size: 0.96rem; }
.ip-presets { display: flex; flex-wrap: wrap; gap: 5px; }
.ip-chip {
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--grid-strong);
  padding: 4px 8px;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  cursor: pointer;
}
.ip-chip.is-active,
.ip-chip:hover {
  background: var(--cobalt);
  border-color: var(--cobalt);
  color: #fff;
}

.ip-main-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}
.ip-svg {
  width: 100%;
  max-width: 300px;
  margin: 0 auto;
  height: auto;
  display: block;
  background: #f8fafc;
  border: 1px solid var(--grid-line);
  touch-action: none;
  user-select: none;
}
.ip-gridline { stroke: #e2e8f0; stroke-width: 1; }
.ip-axis { stroke: #64748b; stroke-width: 1.4; }
.ip-tick,
.ip-axis-label { fill: #475569; font-family: var(--font-mono); font-size: 10px; }
.ip-span-line { stroke: #94a3b8; stroke-width: 1.2; stroke-dasharray: 5 5; }
.ip-drop-line { stroke: #475569; stroke-width: 1.3; stroke-dasharray: 4 4; }
.ip-angle-arc,
.ip-right-angle { fill: none; stroke: var(--ink); stroke-width: 1.5; }
.ip-vec-x { stroke: var(--cobalt); stroke-width: 3; }
.ip-arrow-x { fill: var(--cobalt); }
.ip-vec-y { stroke: var(--crimson); stroke-width: 3; }
.ip-arrow-y { fill: var(--crimson); }
.ip-vec-proj { stroke: var(--emerald); stroke-width: 3.4; }
.ip-arrow-proj { fill: var(--emerald); }
.ip-svg-label { font-family: var(--font-mono); font-size: 10.5px; font-weight: 600; }
.ip-label-x { fill: var(--cobalt); }
.ip-label-y { fill: var(--crimson); }
.ip-label-proj { fill: var(--emerald); }

.ip-handle { cursor: grab; }
.ip-handle-hit { fill: transparent; }
.ip-handle-x .ip-handle-dot { fill: var(--cobalt); stroke: #fff; stroke-width: 2; }
.ip-handle-y .ip-handle-dot { fill: var(--crimson); stroke: #fff; stroke-width: 2; }
.ip-handle-res .ip-handle-dot { fill: var(--emerald); stroke: #fff; stroke-width: 2; }
.ip-handle:focus-visible .ip-handle-dot { stroke: var(--ink); stroke-width: 3.5; }
.ip-hint { margin: 4px 0 0; font-size: 0.73rem; color: var(--ink-muted); }

/* Linear combination, quadratic contours & norm balls SVG helpers */
.lc-basis-x1 { stroke: rgba(29, 78, 216, 0.35); stroke-width: 2; stroke-dasharray: 3 3; }
.lc-basis-x2 { stroke: rgba(220, 38, 38, 0.35); stroke-width: 2; stroke-dasharray: 3 3; }
.lc-vec-tail { stroke: var(--crimson); stroke-width: 2.6; stroke-dasharray: 5 3; }
.lc-vec-res { stroke: var(--emerald); stroke-width: 3.2; }
.lc-controls {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--paper);
  border: 1px solid var(--grid-line);
  padding: 8px 10px;
}
.lc-slider-row {
  display: grid;
  grid-template-columns: 2.6rem auto minmax(0, 1fr) auto 2.8rem;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 0.74rem;
}
.lc-slider-label {
  font-weight: 700;
  color: var(--ink);
}
.lc-slider-val {
  text-align: right;
  font-weight: 600;
  color: var(--cobalt);
  font-variant-numeric: tabular-nums;
}
.lc-step-btn {
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--grid-strong);
  width: 24px;
  height: 24px;
  padding: 0;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
}
.lc-step-btn:hover {
  border-color: var(--cobalt);
  color: var(--cobalt);
}
.lc-range {
  width: 100%;
  margin: 0;
  accent-color: var(--cobalt);
  cursor: pointer;
}

.qc-contour { fill: none; stroke: rgba(29, 78, 216, 0.28); stroke-width: 1.25; }
.qc-contour-active { fill: none; stroke: var(--cobalt); stroke-width: 1.8; stroke-dasharray: 5 4; }
.qc-guide { stroke: #94a3b8; stroke-width: 1.1; stroke-dasharray: 3 3; }
.qc-min-dot { fill: var(--emerald); stroke: #fff; stroke-width: 1.8; }
.qc-grad-line { stroke: var(--crimson); stroke-width: 2.8; }

.nb-ball-linf { fill: rgba(13, 148, 136, 0.09); stroke: var(--emerald); stroke-width: 2; }
.nb-ball-l2 { fill: rgba(29, 78, 216, 0.10); stroke: var(--cobalt); stroke-width: 2.2; }
.nb-ball-l1 { fill: rgba(220, 38, 38, 0.11); stroke: var(--crimson); stroke-width: 2.2; }
.nb-legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 6px;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--ink-muted);
}
.nb-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.nb-swatch {
  width: 10px;
  height: 10px;
  border: 2px solid currentColor;
  display: inline-block;
}
.nb-swatch-l1 { color: var(--crimson); background: rgba(220, 38, 38, 0.16); }
.nb-swatch-l2 { color: var(--cobalt); background: rgba(29, 78, 216, 0.16); border-radius: 50%; }
.nb-swatch-linf { color: var(--emerald); background: rgba(13, 148, 136, 0.16); }

.ip-readouts { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.ip-stat-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 6px; }
.ip-stat-row-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.ip-stat-card {
  background: var(--paper);
  border: 1px solid var(--grid-line);
  padding: 6px 8px;
  overflow-x: auto;
  min-width: 0;
}
.ip-stat-label {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.66rem;
  text-transform: uppercase;
  color: var(--ink-muted);
}
.ip-stat-math { font-size: 0.84rem; }

.ip-playback {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--grid-line);
  min-width: 0;
}
.ip-playback-only {
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
}
.ip-controls { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 10px; }
.ip-btn {
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--grid-strong);
  padding: 5px 9px;
  font-family: var(--font-mono);
  font-size: 0.73rem;
  font-weight: 600;
  cursor: pointer;
}
.ip-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.ip-btn-primary { background: var(--cobalt); color: #fff; border-color: var(--cobalt); }

.ip-terms {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
  gap: 6px;
  margin-bottom: 8px;
}
.ip-term-card {
  background: var(--paper);
  border: 1px solid var(--grid-line);
  padding: 5px 7px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  display: flex;
  flex-direction: column;
  opacity: 0.65;
  min-width: 0;
}
.ip-term-card.is-done { opacity: 1; border-color: var(--emerald); }
.ip-term-card.is-current { border-color: var(--cobalt); background: #fff; }
.ip-term-idx { font-size: 0.66rem; color: var(--ink-muted); }
.ip-term-sum { font-size: 0.68rem; color: var(--emerald); }

.ip-sum-footer {
  background: var(--paper);
  border: 1px solid var(--grid-line);
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow-x: auto;
  min-width: 0;
}
.ip-flop-badges { display: flex; flex-wrap: wrap; gap: 5px; }
.ip-badge {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  background: #fff;
  border: 1px solid var(--grid-line);
  padding: 2px 6px;
}
.ip-badge-strong { color: var(--cobalt); border-color: var(--cobalt); font-weight: 600; }

/* ==========================================================================
 * Code Boxes ([data-codebox] and <pre data-code>)
 * ========================================================================== */
.cb-shell {
  background: #fff;
  border: 2px solid var(--ink);
  padding: 12px;
  font-family: var(--font-ui);
  min-width: 0;
}
.cb-topbar { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.cb-lang { display: block; font-family: var(--font-mono); font-size: 0.72rem; color: var(--cobalt); font-weight: 600; }
.cb-setup summary { font-family: var(--font-mono); font-size: 0.74rem; color: var(--crimson); cursor: pointer; }
.cb-setup-code {
  margin: 6px 0 0;
  padding: 8px;
  background: var(--paper);
  border: 1px solid var(--grid-line);
  font-family: var(--font-mono);
  font-size: 0.74rem;
  overflow-x: auto;
  max-width: 100%;
}
.cb-setup-code > code,
.cb-line > code {
  font-family: inherit;
  font-size: inherit;
}
.cb-actions { display: flex; flex-wrap: wrap; gap: 5px; }
.cb-btn {
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--grid-strong);
  padding: 4px 9px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
}
.cb-btn:hover:not(:disabled) {
  border-color: var(--cobalt);
  color: var(--cobalt);
}
.cb-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.cb-btn-primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.cb-btn-primary:hover:not(:disabled) { background: var(--cobalt); border-color: var(--cobalt); color: #fff; }

/* Preformatted code with per-line spans (newlines preserved in DOM; flex column collapses whitespace nodes) */
.cb-pre,
.cb-lines {
  margin: 0;
  background: #0f172a;
  color: #e2e8f0;
  padding: 7px 0;
  font-family: var(--font-mono);
  font-size: 0.74rem;
  line-height: 1.5;
  overflow-x: auto;
  max-width: 100%;
}
.cb-pre > code {
  display: flex;
  flex-direction: column;
  min-width: max-content;
  font-family: inherit;
  font-size: inherit;
}
.cb-code-line,
.cb-line {
  padding: 2px 10px 2px 8px;
  display: flex;
  gap: 8px;
  white-space: pre;
  border-left: 3px solid transparent;
}
.cb-code-line.is-active,
.cb-line.is-active {
  background: rgba(59, 130, 246, 0.28);
  border-left-color: #60a5fa;
  color: #fff;
}
.cb-ln {
  color: #64748b;
  min-width: 1.25em;
  text-align: right;
  user-select: none;
  flex-shrink: 0;
}

.cb-watch {
  margin-top: 8px;
  background: var(--paper);
  border: 1px solid var(--grid-line);
  padding: 7px 10px;
  font-size: 0.75rem;
}
.cb-vars { display: flex; flex-wrap: wrap; gap: 10px; font-family: var(--font-mono); }
.cb-vars strong { color: var(--cobalt); }
.cb-note { margin: 4px 0 0; color: var(--ink-muted); }

.cb-output-row {
  margin-top: 8px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  background: var(--surface-tint);
  border: 1px solid var(--grid-line);
  padding: 6px 10px;
  font-family: var(--font-mono);
  font-size: 0.76rem;
  overflow-x: auto;
}
.cb-output-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-muted);
  flex-shrink: 0;
}
.cb-output-val {
  font-weight: 600;
  color: var(--ink);
  white-space: pre;
  text-align: right;
}

/* ==========================================================================
 * Full-Width Code Session ([data-code-session="loop-vs-numpy"])
 * ========================================================================== */
.code-session {
  margin: 2rem -20px;
  padding: 24px 20px;
  background: var(--paper);
  background-image:
    linear-gradient(to right, rgba(148, 163, 184, 0.16) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(148, 163, 184, 0.16) 1px, transparent 1px);
  background-size: 24px 24px;
  border-top: 2px solid var(--ink);
  border-bottom: 2px solid var(--ink);
  font-family: var(--font-ui);
  line-height: 1.5;
  min-width: 0;
}
.cs-inner {
  max-width: 1392px;
  margin: 0 auto;
  background: var(--surface);
  border: 2px solid var(--ink);
  padding: 20px;
  min-width: 0;
}
@media (min-width: 1080px) {
  .code-session {
    margin: 0;
    padding: 16px 24px;
  }
  .cs-inner {
    padding: 16px 20px;
  }
}
.cs-header {
  border-bottom: 1px solid var(--grid-line);
  padding-bottom: 10px;
  margin-bottom: 12px;
}
.cs-header-top {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
}
.cs-eyebrow {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--cobalt);
  font-weight: 600;
}
.cs-skip-link,
.cs-continue-link {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--cobalt);
}
.cs-title {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(1.45rem, 2.05vw, 1.82rem);
  line-height: 1.12;
  margin: 0 0 5px;
}
.cs-intro {
  font-family: var(--font-prose);
  font-size: 0.92rem;
  line-height: 1.5;
  color: var(--ink-muted);
  margin: 0;
  max-width: 96ch;
}

.cs-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
  min-width: 0;
}
@media (min-width: 1080px) and (max-width: 1379.98px) {
  .cs-grid {
    grid-template-columns: minmax(0, 1.08fr) minmax(0, 0.92fr);
    column-gap: 18px;
    row-gap: 12px;
    align-items: start;
  }
  .cs-code-pane {
    grid-column: 1 / -1;
    grid-row: 1;
  }
  .cs-output-box {
    grid-column: 1 / 2;
    grid-row: 2;
  }
  .cs-notes-pane {
    grid-column: 1 / 2;
    grid-row: 3;
  }
  .cs-chart-pane {
    grid-column: 2 / 3;
    grid-row: 2 / 4;
  }
}
@media (min-width: 1380px) {
  .cs-grid {
    grid-template-columns: minmax(0, 1.68fr) minmax(0, 1fr);
    column-gap: 18px;
    row-gap: 12px;
    align-items: stretch;
  }
  .cs-code-pane {
    grid-column: 1 / 2;
    grid-row: 1;
  }
  .cs-chart-pane {
    grid-column: 2 / 3;
    grid-row: 1;
  }
  .cs-output-box {
    grid-column: 1 / 2;
    grid-row: 2;
  }
  .cs-notes-pane {
    grid-column: 2 / 3;
    grid-row: 2;
  }
}

.cs-code-pane {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.cs-pane-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.cs-pre {
  font-size: 0.73rem;
  line-height: 1.42;
  padding: 7px 0;
  flex: 1;
}
.cs-pre .cb-code-line {
  padding: 1.5px 10px 1.5px 8px;
  gap: 8px;
}
.cs-pre .cb-ln {
  min-width: 1.5em;
}

.cs-output-box {
  background: var(--paper);
  border: 1px solid var(--grid-line);
  padding: 8px 12px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.cs-pane-label {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-muted);
  margin-bottom: 5px;
}
.cs-stdout {
  margin: 0;
  padding: 7px 10px;
  background: #0f172a;
  color: #e2e8f0;
  font-family: var(--font-mono);
  font-size: 0.73rem;
  line-height: 1.45;
  overflow-x: auto;
  max-width: 100%;
}

.cs-chart-pane {
  background: var(--paper);
  border: 1px solid var(--grid-line);
  padding: 8px 10px;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.cs-chart {
  width: 100%;
  height: auto;
  display: block;
  background: #fff;
  border: 1px solid var(--grid-line);
}
.cs-plot-bg { fill: #f8fafc; }
.cs-gridline { stroke: #e2e8f0; stroke-width: 1; }
.cs-axis { stroke: #64748b; stroke-width: 1.3; }
.cs-tick { fill: #475569; font-family: var(--font-mono); font-size: 10px; }
.cs-axis-title { fill: #334155; font-family: var(--font-mono); font-size: 10.5px; font-weight: 600; }
.cs-line-loop { stroke: var(--crimson); stroke-width: 2.6; }
.cs-line-numpy { stroke: var(--cobalt); stroke-width: 2.6; }
.cs-dot-loop { fill: var(--crimson); stroke: #fff; stroke-width: 1.5; }
.cs-dot-numpy { fill: var(--cobalt); stroke: #fff; stroke-width: 1.5; }
.cs-series-label { font-family: var(--font-mono); font-size: 11px; font-weight: 700; }
.cs-series-loop { fill: var(--crimson); }
.cs-series-numpy { fill: var(--cobalt); }
.cs-gap-line { stroke: var(--emerald); stroke-width: 1.5; stroke-dasharray: 4 3; }
.cs-gap-label { fill: var(--emerald); font-family: var(--font-mono); font-size: 10.5px; font-weight: 700; }
.cs-curve-theory { stroke: var(--cobalt); stroke-width: 2.2; opacity: 0.85; }
.cs-dot-doc { fill: var(--crimson); fill-opacity: 0.36; }
.cs-dot-top { fill: var(--emerald); stroke: #fff; stroke-width: 1.5; }

.cs-notes-pane {
  background: var(--paper);
  border: 1px solid var(--grid-line);
  padding: 9px 12px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 6px;
}
.cs-caption {
  margin: 0;
  font-family: var(--font-prose);
  font-size: 0.85rem;
  line-height: 1.48;
  color: var(--ink);
}
.cs-provenance {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  line-height: 1.4;
  color: var(--ink-muted);
}

.cs-footer {
  margin-top: 12px;
  padding-top: 9px;
  border-top: 1px solid var(--grid-line);
  display: flex;
  justify-content: flex-end;
}

.katex-display {
  overflow-x: auto;
  overflow-y: hidden;
  padding: 4px 0;
  max-width: 100%;
}

/* ==========================================================================
 * Responsive Collapse: Tablet & 390px Phone
 * ========================================================================== */
@media (max-width: 1120px) and (min-width: 881px) {
  .matrix-3col {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }
  .matrix-3col > .matrix-cell:nth-child(2) {
    border-right: 0;
  }
  .matrix-3col > .matrix-cell:nth-child(3) {
    grid-column: 1 / -1;
    border-right: 0;
  }
}

@media (max-width: 880px) {
  .bp-hero-grid,
  .matrix-2col,
  .matrix-3col,
  .syllabus-rows li {
    grid-template-columns: minmax(0, 1fr);
  }
  .spec-strip {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }
  .bp-hero-copy,
  .matrix-cell,
  .matrix-3col > .matrix-cell {
    border-right: 0;
  }
  .hub-book-card {
    display: flex;
    flex-direction: column;
  }
  .hub-book-info {
    padding: 28px 32px 18px;
  }
  .hub-book-chapters {
    padding: 20px 32px;
    border-left: 0;
    border-top: 1px solid var(--grid-line);
    border-bottom: 1px solid var(--grid-line);
  }
  .hub-book-actions {
    padding: 20px 32px 28px;
    align-self: stretch;
  }
}

@media (max-width: 480px) {
  .bp-bar {
    padding: 8px 12px;
  }
  .bp-container {
    padding: 0 12px;
    margin-top: 16px;
  }
  .bp-hero-copy,
  .matrix-cell,
  .matrix-3col > .matrix-cell,
  .syllabus-rows li {
    padding: 20px 16px;
  }
  .hub-book-info {
    padding: 20px 16px 16px;
  }
  .hub-book-chapters {
    padding: 16px;
  }
  .hub-book-actions {
    padding: 16px 16px 22px;
  }
  .spec-strip,
  .ip-stat-row,
  .ip-stat-row-3 {
    grid-template-columns: minmax(0, 1fr);
  }
  .wb-toc-toggle {
    padding: 9px 16px;
  }
  .wb-flow-grid {
    padding: 20px 16px 48px;
  }
  .code-session {
    margin: 1.8rem -16px;
    padding: 20px 12px;
  }
  .cs-inner {
    padding: 16px 14px;
  }
}

/* Anchor KaTeX's absolute .katex-mathml copy to its formula so scroll boxes clip it. */
.katex { position: relative; }

/* ==========================================================================
 * Chapter 2 Workbench Widgets & Session Series
 * ========================================================================== */
.cs-line-alt { stroke: #b45309; stroke-width: 2.5; }
.cs-dot-alt { fill: #b45309; stroke: #fff; stroke-width: 1.5; }
.cs-series-alt { fill: #b45309; }

.ip-svg-wide {
  max-width: 356px;
}

.gd-curve {
  fill: none;
  stroke: var(--cobalt);
  stroke-width: 2.3;
}
.gd-path {
  fill: none;
  stroke: var(--crimson);
  stroke-width: 2;
  stroke-dasharray: 4 3;
}
.gd-path-solid {
  fill: none;
  stroke: var(--crimson);
  stroke-width: 2.2;
}
.gd-min-line {
  stroke: var(--emerald);
  stroke-width: 1.5;
  stroke-dasharray: 4 3;
}
.gd-dot-past {
  fill: #fff;
  stroke: var(--crimson);
  stroke-width: 1.7;
}
.gd-dot-cur {
  fill: var(--crimson);
  stroke: #fff;
  stroke-width: 2;
}
.gd-dot-cap {
  fill: #fff;
  stroke: var(--crimson);
  stroke-width: 2.4;
  stroke-dasharray: 2 1.5;
}
.gd-leader {
  stroke: var(--crimson);
  stroke-width: 1.2;
  opacity: 0.72;
}
.gd-cur-pill {
  fill: rgba(255, 255, 255, 0.92);
  stroke: rgba(220, 38, 38, 0.38);
  stroke-width: 1;
}

.gd-table-wrap {
  overflow-x: auto;
  max-width: 100%;
  min-width: 0;
  border: 1px solid var(--grid-line);
  background: #fff;
}
.gd-iter-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
}
.gd-iter-table th,
.gd-iter-table td {
  padding: 4px 7px;
  text-align: right;
  border-bottom: 1px solid #e2e8f0;
  white-space: nowrap;
}
.gd-iter-table th:first-child,
.gd-iter-table td:first-child {
  text-align: left;
}
.gd-iter-table th {
  background: var(--paper);
  color: var(--ink-muted);
  font-weight: 600;
  font-size: 0.67rem;
}
.gd-iter-table tbody tr {
  cursor: pointer;
}
.gd-iter-table tbody tr:hover {
  background: var(--surface-tint);
}
.gd-iter-table tbody tr.is-current {
  background: rgba(29, 78, 216, 0.10);
  font-weight: 700;
  color: var(--cobalt-dark);
}
.gd-iter-table tbody tr:last-child td {
  border-bottom: 0;
}

/* Taylor 1D widget */
.tl-diverge-bg {
  fill: rgba(220, 38, 38, 0.06);
}
.tl-bound-line {
  stroke: var(--crimson);
  stroke-width: 1.5;
  stroke-dasharray: 4 3;
}
.tl-asym-line {
  stroke: #94a3b8;
  stroke-width: 1.2;
  stroke-dasharray: 3 3;
}
.tl-true-curve {
  fill: none;
  stroke: var(--cobalt);
  stroke-width: 2.4;
}
.tl-poly-curve {
  fill: none;
  stroke: var(--crimson);
  stroke-width: 2.2;
}
.tl-err-bar {
  stroke: var(--emerald);
  stroke-width: 2.4;
}
.tl-diverge-pill {
  fill: rgba(255, 255, 255, 0.92);
  stroke: rgba(220, 38, 38, 0.45);
  stroke-width: 1;
}
.tl-err-pill {
  fill: rgba(255, 255, 255, 0.92);
  stroke: rgba(13, 148, 136, 0.45);
  stroke-width: 1;
}
.tl-err-label {
  font-size: 9.5px;
}
.tl-diverge-note {
  fill: #991b1b;
  font-family: var(--font-ui);
  font-size: 8.2px;
  font-weight: 600;
}

/* Autodiff diamond widget */
.ad-svg {
  width: 100%;
  max-width: 100%;
  height: auto;
  display: block;
  background: #f8fafc;
  border: 1px solid var(--grid-line);
  user-select: none;
}
.ad-edge-line {
  stroke: #334155;
  stroke-width: 1.65;
}
.ad-edge-line.is-active {
  stroke: var(--crimson);
  stroke-width: 2.6;
}
.ad-arrow-head {
  fill: #334155;
}
.ad-arrow-head-active {
  fill: var(--crimson);
}
.ad-box-rect {
  fill: #fff;
  stroke: #0f172a;
  stroke-width: 1.5;
}
.ad-box-group.is-active .ad-box-rect {
  stroke: var(--crimson);
  stroke-width: 2.4;
  fill: #fffafa;
}
.ad-val-text {
  fill: #0f172a;
  font-family: var(--font-mono);
  font-size: 9.6px;
  font-weight: 600;
}
.ad-boxnum-text {
  fill: #dc2626;
  font-family: var(--font-mono);
  font-size: 9.6px;
  font-weight: 700;
}
.ad-edge-text {
  fill: #1d4ed8;
  font-family: var(--font-mono);
  font-size: 10.2px;
  font-weight: 700;
  paint-order: stroke;
  stroke: #f8fafc;
  stroke-width: 3.5px;
  stroke-linejoin: round;
}
.ad-msg-text {
  fill: #dc2626;
  font-family: var(--font-mono);
  font-size: 10.2px;
  font-weight: 700;
  paint-order: stroke;
  stroke: #f8fafc;
  stroke-width: 3.5px;
  stroke-linejoin: round;
}
.ad-stage-card {
  background: var(--paper);
  border: 1px solid var(--grid-line);
  padding: 7px 9px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-x: auto;
  max-width: 100%;
  min-width: 0;
}
.ad-stage-head {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--cobalt);
  text-transform: uppercase;
}
.ad-swatch-val { color: #0f172a; background: rgba(15, 23, 42, 0.14); }
.ad-swatch-edge { color: #1d4ed8; background: rgba(29, 78, 216, 0.16); }
.ad-swatch-msg { color: #dc2626; background: rgba(220, 38, 38, 0.16); }

/* ==========================================================================
 * Chapter 3 Linear-Map Widget & Chain-Order Bars
 * ========================================================================== */
.lm-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}
.lm-view-toggle {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
}
.lm-preset-note {
  margin: 0;
  padding: 6px 9px;
  background: var(--surface-tint);
  border: 1px solid var(--cobalt);
  border-left-width: 3px;
  font-family: var(--font-mono);
  font-size: 0.73rem;
  font-weight: 600;
  color: var(--cobalt-dark);
}
.lm-preset-note[hidden] {
  display: none !important;
}
.lm-map-gridline {
  stroke: rgba(29, 78, 216, 0.22);
  stroke-width: 0.95;
}
.lm-map-axis {
  stroke: rgba(29, 78, 216, 0.42);
  stroke-width: 1.25;
}
.lm-collinear-line {
  stroke: rgba(220, 38, 38, 0.45);
  stroke-width: 1.8;
  stroke-dasharray: 5 4;
}
.lm-vec-a1 {
  stroke: var(--cobalt);
  stroke-width: 2.8;
}
.lm-vec-a2 {
  stroke: var(--emerald);
  stroke-width: 2.8;
}
.lm-vec-ax {
  stroke: var(--crimson);
  stroke-width: 3.1;
}
.lm-step-a1 {
  stroke: var(--cobalt);
  stroke-width: 2.1;
  stroke-dasharray: 5 3.5;
  opacity: 0.88;
}
.lm-step-a2 {
  stroke: var(--emerald);
  stroke-width: 2.3;
  stroke-dasharray: 5 3.5;
}
.lm-step-joint {
  fill: #fff;
  stroke: var(--cobalt);
  stroke-width: 1.8;
}
.lm-row-drop {
  stroke: var(--crimson);
  stroke-width: 1.45;
  stroke-dasharray: 4 3;
  opacity: 0.82;
}
.lm-row-proj-dot {
  fill: var(--crimson);
  stroke: #fff;
  stroke-width: 1.4;
}
.lm-arrow-a1 { fill: var(--cobalt); }
.lm-arrow-a2 { fill: var(--emerald); }
.lm-arrow-ax { fill: var(--crimson); }

.lm-handle-a1 .ip-handle-dot {
  fill: var(--cobalt);
  stroke: #fff;
  stroke-width: 1.8;
}
.lm-handle-a2 .ip-handle-dot {
  fill: var(--emerald);
  stroke: #fff;
  stroke-width: 1.8;
}
.lm-handle-x .lm-x-ring {
  fill: rgba(255, 255, 255, 0.55);
  stroke: var(--ink);
  stroke-width: 2.2;
}
.lm-handle-x .lm-x-core {
  fill: var(--ink);
}
.lm-handle-x:focus-visible .lm-x-ring {
  stroke: var(--focus-ring);
  stroke-width: 3.2;
}

.lm-svg-label {
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 700;
  paint-order: stroke;
  stroke: #f8fafc;
  stroke-width: 3.5px;
  stroke-linejoin: round;
}
.lm-lbl-a1 { fill: var(--cobalt); }
.lm-lbl-a2 { fill: var(--emerald); }
.lm-lbl-x { fill: var(--ink); }
.lm-lbl-ax { fill: var(--crimson); }

.lm-swatch-a1 { color: var(--cobalt); background: rgba(29, 78, 216, 0.18); }
.lm-swatch-a2 { color: var(--emerald); background: rgba(13, 148, 136, 0.18); }
.lm-swatch-x { color: var(--ink); background: rgba(15, 23, 42, 0.14); border-radius: 50%; }
.lm-swatch-ax { color: var(--crimson); background: rgba(220, 38, 38, 0.18); }

.cs-bar-fast {
  fill: var(--cobalt);
  fill-opacity: 0.88;
  stroke: var(--cobalt-dark);
  stroke-width: 1.2;
}
.cs-bar-slow {
  fill: var(--crimson);
  fill-opacity: 0.86;
  stroke: #991b1b;
  stroke-width: 1.2;
}
.cs-bar-val {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
}
.cs-bar-val-fast { fill: var(--cobalt-dark); }
.cs-bar-val-slow { fill: #991b1b; }

/* ==========================================================================
 * Chapter 4 Eigen-Directions Widget, Energy Circle, and Two-Panel PCA Chart
 * ========================================================================== */
.ed-unit-circle {
  fill: rgba(29, 78, 216, 0.04);
  stroke: rgba(29, 78, 216, 0.42);
  stroke-width: 1.5;
  stroke-dasharray: 4 3;
}
.ed-image-ellipse {
  fill: none;
  stroke: rgba(220, 38, 38, 0.24);
  stroke-width: 1.25;
  stroke-dasharray: 3 3;
}
.ed-eig-line {
  stroke: var(--emerald);
  stroke-width: 1.7;
  stroke-dasharray: 6 4;
  opacity: 0.85;
}
.ed-vec-glow {
  stroke: rgba(13, 148, 136, 0.28);
  stroke-width: 8.5;
  stroke-linecap: round;
}
.ed-vec-x {
  stroke: var(--cobalt);
  stroke-width: 2.9;
}
.ed-vec-ax {
  stroke: var(--crimson);
  stroke-width: 3.1;
}
.ed-vec-x.is-lit,
.ed-vec-ax.is-lit {
  stroke: var(--emerald);
  stroke-width: 3.4;
}
.ed-arrow-lit {
  fill: var(--emerald);
}
.ed-handle-x.is-lit .ip-handle-dot {
  fill: var(--emerald);
  stroke: #fff;
  stroke-width: 2.2;
}
.ip-stat-card.is-eigen-match {
  border-color: var(--emerald);
  background: rgba(13, 148, 136, 0.08);
}
.ed-swatch-eig {
  color: var(--emerald);
  background: rgba(13, 148, 136, 0.16);
}

.lm-energy-circle {
  fill: none;
  stroke: rgba(15, 23, 42, 0.28);
  stroke-width: 1.3;
  stroke-dasharray: 4 3;
}

.cs-pca-panels {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
}
@media (min-width: 720px) {
  .cs-pca-panels {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }
}
.cs-pca-line {
  stroke: rgba(220, 38, 38, 0.55);
  stroke-width: 1.7;
  stroke-dasharray: 5 3.5;
}
.cs-pca-dot {
  fill: var(--cobalt);
  fill-opacity: 0.42;
}
.cs-pca-axis1 {
  stroke: var(--crimson);
  stroke-width: 2.6;
}
.cs-pca-axis2 {
  stroke: var(--emerald);
  stroke-width: 2.5;
}
.cs-pca-mean {
  fill: #fff;
  stroke: var(--ink);
  stroke-width: 1.7;
}
.cs-pca-leader {
  stroke: #64748b;
  stroke-width: 1.1;
  stroke-dasharray: 2.5 2;
}

/* ==========================================================================
 * Chapter 5 SVD Image & Power Method Widgets
 * ========================================================================== */
.svd-img-pair {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
  min-width: 0;
}
.svd-img-card {
  background: var(--paper);
  border: 1px solid var(--grid-line);
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}
.svd-img-caption {
  font-family: var(--font-mono);
  font-size: 0.69rem;
  font-weight: 600;
  color: var(--ink-muted);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.svd-canvas {
  width: 100%;
  aspect-ratio: 1 / 1;
  height: auto;
  display: block;
  background: #f8fafc;
  border: 1px solid var(--grid-strong);
  image-rendering: pixelated;
}

.pm-q1-line {
  stroke: var(--emerald);
  stroke-width: 1.75;
  stroke-dasharray: 6 4;
}
.pm-x0-vec {
  stroke: rgba(29, 78, 216, 0.36);
  stroke-width: 1.9;
  stroke-dasharray: 4 3;
}
.pm-xt-vec {
  stroke: var(--crimson);
  stroke-width: 3.1;
}
.pm-trail {
  fill: none;
  stroke: rgba(220, 38, 38, 0.36);
  stroke-width: 1.5;
}
.pm-swatch-circle {
  color: var(--cobalt);
  background: rgba(29, 78, 216, 0.08);
  border-radius: 50%;
  border-style: dashed;
}
.pm-swatch-q1 {
  color: var(--emerald);
  background: rgba(13, 148, 136, 0.16);
  border-style: dashed;
}
.pm-swatch-xt {
  color: var(--crimson);
  background: rgba(220, 38, 38, 0.2);
  border-radius: 50%;
}

/* ==========================================================================
 * Chapter 6 Hessian-Landscape Widget & Elliptical-Bowl Step Readout
 * ========================================================================== */
.hl-contour-pos {
  fill: none;
  stroke: rgba(29, 78, 216, 0.42);
  stroke-width: 1.35;
}
.hl-contour-neg {
  fill: none;
  stroke: rgba(180, 83, 9, 0.48);
  stroke-width: 1.35;
  stroke-dasharray: 4.5 3.5;
}
.hl-contour-zero {
  fill: none;
  stroke: #64748b;
  stroke-width: 1.35;
  stroke-dasharray: 3 3;
}
.hl-valley-line {
  stroke: var(--cobalt);
  stroke-width: 2.8;
}
.hl-eig-arrow {
  stroke: var(--crimson);
  stroke-width: 2.7;
}
.hl-max-dot {
  fill: #b45309;
  stroke: #fff;
  stroke-width: 1.8;
}
.hl-saddle-dot {
  fill: #fff;
  stroke: var(--ink);
  stroke-width: 2;
}
.hl-lbl-pill {
  fill: rgba(248, 250, 252, 0.94);
  stroke: rgba(220, 38, 38, 0.34);
  stroke-width: 1;
}
.hl-verdict-text {
  font-family: var(--font-ui);
  font-size: 0.86rem;
  font-weight: 700;
  color: var(--ink);
  margin-top: 2px;
}
.hl-swatch-pos {
  color: var(--cobalt);
  background: rgba(29, 78, 216, 0.14);
}
.hl-swatch-neg {
  color: #b45309;
  background: rgba(180, 83, 9, 0.14);
  border-style: dashed;
}
.hl-swatch-eig {
  color: var(--crimson);
  background: rgba(220, 38, 38, 0.18);
}
.gd-step-rule-label {
  text-transform: none;
  font-size: 0.71rem;
  color: var(--ink);
  font-weight: 600;
  margin-bottom: 2px;
}

/* ==========================================================================
 * Gallery Page (site/comp282/gallery.html)
 * ========================================================================== */
.gallery-html {
  scroll-behavior: auto;
}
.gallery-main {
  max-width: 780px;
  margin: 28px auto 64px;
  padding: 0 20px;
  min-width: 0;
}
.gallery-sheet {
  background: var(--surface);
  border: 2px solid var(--ink);
  padding: 36px 44px 44px;
  min-width: 0;
}
.gallery-header {
  border-bottom: 2px solid var(--ink);
  padding-bottom: 18px;
  margin-bottom: 32px;
}
.gallery-header h1 {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(2.1rem, 3.6vw, 2.85rem);
  line-height: 1.06;
  margin: 0 0 10px;
}
.gallery-intro {
  font-family: var(--font-prose);
  font-size: 1rem;
  line-height: 1.65;
  color: var(--ink-muted);
  margin: 0;
  max-width: 62ch;
}
.gallery-chapter {
  margin-bottom: 42px;
  min-width: 0;
}
.gallery-chapter:last-child {
  margin-bottom: 0;
}
.gallery-chapter-head {
  border-bottom: 2px solid var(--ink);
  padding-bottom: 8px;
  margin-bottom: 22px;
}
.gallery-chapter-head h2 {
  margin: 0;
  font-family: var(--font-ui);
  font-size: 1.16rem;
  font-weight: 700;
  line-height: 1.3;
  color: var(--ink);
}
.gallery-items {
  display: flex;
  flex-direction: column;
  gap: 28px;
  min-width: 0;
}
.gallery-item {
  padding-bottom: 28px;
  border-bottom: 1px solid var(--grid-line);
  min-width: 0;
}
.gallery-item:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}
.gallery-item-head {
  margin-bottom: 12px;
  min-width: 0;
}
.gallery-item-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px 14px;
  margin-bottom: 4px;
}
.gallery-back-link {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--cobalt);
  text-decoration: none;
}
.gallery-back-link:hover,
.gallery-back-link:focus-visible {
  text-decoration: underline;
}
.gallery-item-title,
.gallery-session-title {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(1.32rem, 1.9vw, 1.62rem);
  line-height: 1.15;
  margin: 0;
  color: var(--ink);
}
.gallery-item .wb-station-panel {
  position: static;
}
/* The item heading names the figure: hide the figure's own copy of the title. */
.gallery-item-station .ip-title,
.gallery-item-station .cb-lang {
  display: none;
}
.gallery-item .svd-img-pair {
  max-width: 400px;
  margin: 0 auto;
}
.gallery-session-body {
  border: 2px solid var(--ink);
  background: var(--surface);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}
[data-gallery-item] [data-widget]:empty {
  min-height: 420px;
  background: var(--paper);
  border: 2px solid var(--ink);
}
@media (max-width: 680px) {
  .gallery-main {
    margin: 16px auto 44px;
    padding: 0 12px;
  }
  .gallery-sheet {
    padding: 20px 12px 26px;
  }
  .gallery-session-body {
    padding: 10px;
  }
}

