/* ---------- Tokens ---------- */
body {
  --ink: #1c1b19;
  --ink-2: #4a4843;
  --muted: #6f6b63;
  --hair: #d9d4ca;
  --grid: #ece8df;
  --paper: #fbfaf6;
  --accent: #2b4c9b;
  --accent-soft: rgba(43, 76, 155, 0.08);
  --accent-2: #b8562f;
  --serif: 'Source Sans Pro', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}
body.quarto-dark {
  --ink: #ece8df;
  --ink-2: #cfcac0;
  --muted: #a29d93;
  --hair: #3b3934;
  --grid: #262521;
  --paper: #161513;
  --accent: #3987e5;
  --accent-soft: rgba(57, 135, 229, 0.12);
  --accent-2: #d95926;
}

/* ---------- Page ---------- */
body {
  background: var(--paper) !important;
  color: var(--ink);
  font-family: var(--serif);
}
#quarto-content, .page-columns, main.content { background: var(--paper); }
a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { color: var(--ink); }
p, li { color: var(--ink); }

/* ---------- Title block ---------- */
h1.title { font-family: var(--serif); font-weight: 600; font-size: 2.35rem; letter-spacing: -0.012em; color: var(--ink); line-height: 1.15; }
.quarto-title .subtitle { font-family: var(--serif); font-style: italic; font-weight: 400; color: var(--muted); font-size: 1.12rem; margin-top: 0.4rem; }
.quarto-title-meta { margin-top: 0.8rem; }
.quarto-title-meta-heading { font-family: var(--serif); font-variant-caps: all-small-caps; letter-spacing: 0.07em; color: var(--muted); font-weight: 600; font-size: 0.95rem; }
.quarto-title-meta-contents, .quarto-title-meta-contents p { font-family: var(--serif); color: var(--ink-2); }
.quarto-page-breadcrumbs, .quarto-page-breadcrumbs a, .breadcrumb-item { font-family: var(--serif); color: var(--muted) !important; font-size: 0.92rem; }
.status { font-variant-caps: all-small-caps; letter-spacing: 0.08em; color: var(--accent-2); font-weight: 600; }

/* ---------- Headings ---------- */
main h2 {
  font-family: var(--serif); font-weight: 600; font-size: 1.5rem; color: var(--ink);
  margin-top: 3rem; padding-top: 1.2rem; border-top: 1px solid var(--hair); border-bottom: none;
}
main h3 { font-family: var(--serif); font-weight: 600; font-size: 1.15rem; color: var(--ink); }
main h2:first-of-type { margin-top: 1.8rem; }

/* ---------- Definitions, theorems, examples ---------- */
.theorem:not(.exercise) { border-left: 1px solid var(--ink); padding: 0.05rem 0 0.05rem 1.1rem; margin: 1.6rem 0; }
.theorem-title strong { font-weight: 600; }
.theorem:not(.exercise):not(.definition):not(.example) > p { font-style: italic; }
.theorem:not(.exercise):not(.definition):not(.example) .theorem-title { font-style: normal; }

/* ---------- Questions ---------- */
.theorem.exercise { margin: 2.2rem 0 0.4rem; }
.theorem.exercise .theorem-title strong { font-variant-caps: all-small-caps; letter-spacing: 0.07em; }
.solved, .tests { display: block; font-size: 0.88rem; color: var(--muted); margin-top: 0.3rem; }
.solved { font-variant-caps: all-small-caps; letter-spacing: 0.06em; font-size: 0.95rem; }
details.reveal { margin: 0.1rem 0; }
details.reveal > summary {
  list-style: none; cursor: pointer; display: inline-block;
  font-variant-caps: all-small-caps; letter-spacing: 0.07em; color: var(--accent); font-size: 1rem;
}
details.reveal > summary::-webkit-details-marker { display: none; }
details.reveal > summary::before { content: '+'; display: inline-block; width: 1.1em; color: var(--muted); font-variant-caps: normal; }
details.reveal[open] > summary::before { content: '\2212'; }
details.reveal[open] { border-left: 1px solid var(--hair); padding: 0 0 0.35rem 0.9rem; margin-left: -0.9rem; }
details.reveal > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

/* ---------- Notes ---------- */
.nuances > ol > li { margin-bottom: 0.8rem; }
.made { display: block; margin-top: 3rem; padding-top: 0.8rem; border-top: 1px solid var(--hair); font-size: 0.88rem; color: var(--muted); }
.pending-text { color: var(--muted); font-style: italic; border-left: 1px solid var(--hair); padding-left: 1rem; }

/* ---------- Tables (booktabs) ---------- */
main table, main .table { border-top: 1.5px solid var(--ink) !important; border-bottom: 1.5px solid var(--ink) !important; color: var(--ink); background: transparent !important; }
main table thead th { border-bottom: 1px solid var(--ink) !important; font-weight: 600; font-variant-caps: all-small-caps; letter-spacing: 0.06em; font-size: 1rem; }
main table td, main table th { border-left: 0 !important; border-right: 0 !important; border-top: 0 !important; background: transparent !important; padding: 0.45rem 0.8rem !important; color: var(--ink) !important; box-shadow: none !important; }
main table tbody tr { border: 0 !important; }

/* ---------- Sidebar and contents ---------- */
#quarto-sidebar, .sidebar.sidebar-navigation { background: var(--paper) !important; border-right: 1px solid var(--hair); }
.sidebar-title, .sidebar-title a { font-family: var(--serif) !important; font-weight: 600; font-size: 1.15rem; color: var(--ink) !important; }
.sidebar-item .sidebar-link, .sidebar-item-text, .menu-text { font-family: var(--serif); color: var(--ink-2); font-size: 0.95rem; }
.sidebar-link.active, .sidebar-link.active .menu-text { color: var(--ink) !important; font-weight: 600; }
#TOC, #quarto-margin-sidebar { font-family: var(--serif); }
#toc-title, .toc-actions { font-variant-caps: all-small-caps; letter-spacing: 0.07em; color: var(--muted); }
#TOC .nav-link { color: var(--muted); font-size: 0.92rem; }
#TOC .nav-link.active { color: var(--ink); }
.nav-page .nav-page-text, .nav-page a { font-family: var(--serif); color: var(--ink-2); }
.nav-footer { font-family: var(--serif); color: var(--muted); border-top: 1px solid var(--hair); background: var(--paper) !important; }

/* ---------- Mermaid ---------- */
.cell-output-display .mermaid, pre.mermaid { background: transparent !important; }
.mermaid .node rect, .mermaid .node polygon { fill: none !important; stroke: var(--ink) !important; stroke-width: 1px !important; }
.mermaid .nodeLabel, .mermaid .edgeLabel, .mermaid text { font-family: var(--serif) !important; color: var(--ink) !important; fill: var(--ink) !important; }
.mermaid .flowchart-link { stroke: var(--muted) !important; stroke-width: 1px !important; }
.mermaid marker path, .mermaid .arrowheadPath { fill: var(--muted) !important; stroke: var(--muted) !important; }

/* ---------- Type motifs ---------- */
canvas.type-motif { display: block; width: 100%; touch-action: none; }
canvas.type-motif.hero { height: 340px; margin: 0.5rem 0 1rem; }
canvas.type-motif.band { height: 230px; margin: 0.5rem 0 0.3rem; }
.motif-caption { font-size: 0.88rem; color: var(--muted); font-style: italic; margin-bottom: 1.5rem; }

/* ---------- Interactive figures ---------- */
.viz { width: 100%; height: auto; display: block; font-family: var(--serif); overflow: visible; }
.viz .grid line { stroke: var(--grid); stroke-width: 1; }
.viz .axis { stroke: var(--hair); stroke-width: 1; }
.viz .shape { fill: none; stroke-linejoin: round; stroke-linecap: round; }
.viz .shape.start { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.viz .shape.mid { stroke: var(--ink-2); stroke-width: 1; opacity: 0.4; transition: opacity 0.2s; }
.viz .panel:hover .shape.mid { opacity: 1; }
.viz .shape.end { stroke: var(--accent); stroke-width: 2; fill: var(--accent-soft); }
.viz .panel-title { font-style: italic; font-size: 18px; fill: var(--ink); }
.viz .panel-sub { font-size: 13.5px; fill: var(--muted); }
.viz .mat text { font-size: 14px; fill: var(--ink); font-variant-numeric: tabular-nums; }
.viz .mat path { fill: none; stroke: var(--ink); stroke-width: 1; }
.viz .eq { font-size: 16px; fill: var(--ink); }
.viz.chart .series { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.viz .series.s1, .viz .dot.s1 { stroke: var(--accent); }
.viz .series.s2, .viz .dot.s2 { stroke: var(--accent-2); }
.viz .dot { fill: var(--paper); stroke-width: 2; }
.viz .end-label { font-size: 13.5px; fill: var(--ink-2); }
.viz .ref { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 4 4; }
.viz .ref-label { font-size: 12.5px; fill: var(--muted); font-style: italic; }
.viz .tick-labels text { font-size: 12.5px; fill: var(--muted); font-variant-numeric: tabular-nums; }
.viz .crosshair { stroke: var(--hair); stroke-width: 1; }
.viz .tip { font-size: 13.5px; fill: var(--ink); paint-order: stroke; stroke: var(--paper); stroke-width: 5px; stroke-linejoin: round; }
.viz-note { color: var(--ink-2); font-size: 0.95rem; margin: 0.4rem 0 1rem; }
.legend { display: flex; flex-wrap: wrap; gap: 0.4rem 1.4rem; font-size: 0.9rem; color: var(--ink-2); margin: 0.8rem 0 0.2rem; }
.legend .key { display: inline-block; width: 1.4rem; height: 0; vertical-align: middle; margin-right: 0.45rem; border-top: 2px solid; }
.legend .key.s1 { border-color: var(--accent); }
.legend .key.s2 { border-color: var(--accent-2); }
.legend .key.ref { border-top: 1px dashed var(--muted); }

/* Controls */
.seg { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.2rem 1rem; margin: 0.35rem 0; font-size: 0.98rem; }
.seg-label { font-variant-caps: all-small-caps; letter-spacing: 0.07em; color: var(--muted); min-width: 5.2rem; font-weight: 600; }
.seg button { background: none; border: 0; padding: 0 0 2px; font: inherit; color: var(--muted); border-bottom: 1px solid transparent; cursor: pointer; }
.seg button[aria-checked='true'] { color: var(--ink); border-bottom-color: var(--ink); }
.seg button:hover { color: var(--ink); }
.seg button:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.slider { display: grid; grid-template-columns: 16rem 1fr 3.6rem; align-items: center; gap: 1rem; margin: 0.3rem 0; font-size: 0.96rem; }
.slider-label { color: var(--ink-2); }
.slider input[type='range'] { -webkit-appearance: none; appearance: none; width: 100%; background: transparent; height: 20px; cursor: pointer; }
.slider input[type='range']::-webkit-slider-runnable-track { height: 1px; background: var(--ink-2); }
.slider input[type='range']::-webkit-slider-thumb { -webkit-appearance: none; width: 13px; height: 13px; border-radius: 50%; background: var(--paper); border: 1.5px solid var(--ink); margin-top: -6px; }
.slider input[type='range']::-moz-range-track { height: 1px; background: var(--ink-2); }
.slider input[type='range']::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%; background: var(--paper); border: 1.5px solid var(--ink); }
.slider input[type='range']:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }
.slider output { font-variant-numeric: tabular-nums; color: var(--ink); text-align: right; }
.mat-h { display: inline-grid; grid-template-columns: auto auto; column-gap: 0.9em; padding: 0 0.5em; position: relative; vertical-align: middle; font-variant-numeric: tabular-nums; line-height: 1.3; margin-left: 0.3em; }
.mat-h::before, .mat-h::after { content: ''; position: absolute; top: 0; bottom: 0; width: 0.35em; border: 1px solid var(--ink); }
.mat-h::before { left: 0; border-right: none; }
.mat-h::after { right: 0; border-left: none; }
.readout { display: flex; flex-wrap: wrap; gap: 0.8rem 2.6rem; align-items: center; margin: 0.8rem 0 0; font-size: 0.96rem; color: var(--ink); }
.readout .lbl { font-variant-caps: all-small-caps; letter-spacing: 0.07em; color: var(--muted); font-weight: 600; margin-right: 0.3rem; }
.readout-note { flex-basis: 100%; color: var(--ink-2); }

@media (max-width: 640px) {
  .slider { grid-template-columns: 1fr 3.4rem; }
  .slider-label { grid-column: 1 / -1; }
  canvas.type-motif.hero { height: 260px; }
}

/* ---------- Book-style contents ---------- */
.book-toc { margin-top: 0.4rem; }
.toc-part { font-variant-caps: all-small-caps; letter-spacing: 0.08em; color: var(--muted); font-weight: 600; margin: 1.5rem 0 0.25rem; }
.toc-list { list-style: none; padding: 0; margin: 0; }
.toc-list li { display: flex; align-items: baseline; gap: 0.7rem; padding: 0.3rem 0; }
.toc-num { width: 1.6rem; flex: none; color: var(--muted); font-variant-numeric: tabular-nums; text-align: right; }
.toc-title { color: var(--ink); }
a.toc-title { color: var(--accent); }
.toc-track { font-size: 0.85rem; color: var(--muted); }
.leader { flex: 1; min-width: 2rem; border-bottom: 1px dotted var(--hair); transform: translateY(-0.3em); }
.toc-status { font-size: 0.92rem; color: var(--muted); }
.toc-status.active { color: var(--accent-2); font-weight: 600; }
.book-toc + p { margin-top: 1.6rem; }

/* ---------- Type motif draft page ---------- */
.motif-intro { color: var(--ink-2); }
.motif-stage { font-variant-caps: all-small-caps; letter-spacing: 0.08em; color: var(--muted); font-weight: 600; margin: 1.8rem 0 0.4rem; }
.motif-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.2rem 1.5rem; }
.motif-grid.chapters { grid-template-columns: repeat(3, 1fr); gap: 1rem 1.2rem; }
.motif-card { display: block; text-decoration: none; color: inherit; border-top: 1px solid var(--hair); padding-top: 0.5rem; }
.motif-card canvas { display: block; width: 100%; height: 140px; cursor: crosshair; }
.motif-card canvas.small { height: 108px; }
.motif-card .mc-title { display: flex; align-items: baseline; gap: 0.55rem; margin-top: 0.35rem; }
.mc-num { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 1.2rem; }
.mc-name { color: var(--ink); font-weight: 600; }
a.motif-card .mc-name { color: var(--accent); }
.mc-meta { margin-left: auto; font-size: 0.82rem; color: var(--muted); text-align: right; }
.motif-card.empty { visibility: hidden; }
@media (max-width: 760px) {
  .motif-grid, .motif-grid.chapters { grid-template-columns: 1fr; }
  .motif-card.empty { display: none; }
}

/* ---------- Contents draft: letters in space ---------- */
.space-level { margin: 0.4rem 0 0.6rem; }
.space-card { display: block; text-decoration: none; color: inherit; margin: 0.5rem 0 1.4rem; }
.space-card canvas { display: block; width: 100%; aspect-ratio: 12 / 5; cursor: crosshair; touch-action: pan-y; }
.space-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.4rem 1.6rem; }
.space-grid .space-card canvas { aspect-ratio: 16 / 10; }
.sc-title { display: flex; align-items: baseline; gap: 0.7rem; border-top: 1px solid var(--hair); padding-top: 0.5rem; margin-bottom: 0.3rem; }
.sc-num { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 1.4rem; }
.sc-name { color: var(--ink); font-weight: 600; }
a.space-card .sc-name { color: var(--accent); }
a.space-card:hover .sc-name { color: var(--ink); }
.sc-meta { margin-left: auto; color: var(--muted); font-size: 0.86rem; text-align: right; }
.space-grid .sc-meta { display: none; }
@media (max-width: 760px) {
  .space-grid { grid-template-columns: 1fr; }
  .space-card canvas { aspect-ratio: 16 / 10; }
  .sc-meta { display: none; }
}

/* ---------- Type motif pathways page ---------- */
.tm-lede { color: var(--ink-2); max-width: 46rem; }
.tm-panel { margin: 0.9rem 0 0.4rem; }
.tm-controls { display: flex; flex-wrap: wrap; gap: 0.1rem 2.6rem; margin-bottom: 0.8rem; }
.tm-controls .seg { margin: 0.15rem 0; }
.tm-canvas { display: block; width: 100%; aspect-ratio: 16 / 9; max-height: 74vh; cursor: crosshair; touch-action: pan-y; }
.tm-caption { display: flex; gap: 1rem; align-items: baseline; margin: 0.7rem 0 0; color: var(--ink-2); font-size: 0.95rem; max-width: 56rem; }
.tm-code { flex: none; min-width: 1.8rem; font-family: 'IBM Plex Mono', ui-monospace, monospace; font-weight: 600; color: var(--accent); }
@media (max-width: 760px) {
  .tm-canvas { aspect-ratio: 4 / 3; }
  .tm-controls { gap: 0.1rem 1.2rem; }
}
