/* ============================================================
   TSDynamics — Systems catalogue (generated pages)
   Styles the build-time per-system + browser pages emitted by
   hooks/docs_autogen.py. Uses the brand tokens (--ts-*) and tracks
   Material's [data-md-color-scheme] light/dark toggle.

   Class map:
     .ts-kicker        breadcrumb line above an H1
     .ts-subtitle      lead paragraph under an H1
     .ts-count         "N systems" muted count line
     .ts-tags          row of header tag pills (.system-tag[/--accent])
     .ts-stats/.ts-stat  the Systems-index stat cards
     .ts-attractor*    the interactive viewer iframe / static figure card
     .ts-props/.ts-prop  the four computed Properties stat cards
     .ts-prop-src/-todo/-na  card status spans (from properties.to_markdown)
     .ts-reference     the literature citation card
   ============================================================ */

/* ---- surface vars, tracking Material's scheme toggle ---- */
:root,
[data-md-color-scheme="default"] {
  --tsc-surface: #ffffff;
  --tsc-surface-2: #f4f6f8;
  --tsc-border: #e7ebef;
  --tsc-muted: #94a0aa;
  --tsc-ink: #14181d;
  --tsc-link: #0c6b62;
  --tsc-accent: #463fb0;
}
[data-md-color-scheme="slate"] {
  --tsc-surface: #11161d;
  --tsc-surface-2: #161c24;
  --tsc-border: #232b34;
  --tsc-muted: #93a0ad;
  --tsc-ink: #e7ecf0;
  --tsc-link: #2cc5ae;
  --tsc-accent: #8c85f2;
}

/* ---- kicker breadcrumb ---- */
.md-typeset .ts-kicker {
  font-family: var(--ts-font-mono, "IBM Plex Mono", monospace);
  font-size: 0.75rem;
  color: var(--tsc-muted);
  margin: -0.4rem 0 0.9rem;
}
.md-typeset .ts-kicker a {
  color: var(--tsc-link);
}

/* ---- subtitle + count ---- */
.md-typeset .ts-subtitle {
  font-size: 1.08rem;
  line-height: 1.55;
  color: var(--tsc-muted);
  max-width: 64ch;
  margin: 0 0 1.1rem;
}
.md-typeset .ts-count {
  font-family: var(--ts-font-mono, "IBM Plex Mono", monospace);
  font-size: 0.78rem;
  color: var(--tsc-muted);
  margin: 0 0 1rem;
}

/* ---- header tag pills ---- */
.md-typeset .ts-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 1.8rem;
}
.md-typeset .system-tag {
  display: inline-block;
  font-family: var(--ts-font-mono, "IBM Plex Mono", monospace);
  font-size: 0.72rem;
  line-height: 1.4;
  color: #515b65;
  background: var(--tsc-surface-2);
  border: 1px solid var(--tsc-border);
  border-radius: 20px;
  padding: 3px 12px;
  margin: 0;
}
[data-md-color-scheme="slate"] .md-typeset .system-tag {
  color: #aeb9c2;
}
.md-typeset .system-tag--accent {
  color: #0c6b62;
  background: var(--ts-teal-soft, #e7f3f0);
  border-color: #cde8e2;
}
[data-md-color-scheme="slate"] .md-typeset .system-tag--accent {
  color: #2cc5ae;
  background: rgba(44, 197, 174, 0.12);
  border-color: rgba(44, 197, 174, 0.3);
}

/* ---- Systems-index stat cards ---- */
.md-typeset .ts-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin: 1.4rem 0 2rem;
}
.md-typeset .ts-stat {
  background: var(--tsc-surface);
  border: 1px solid var(--tsc-border);
  border-radius: 12px;
  padding: 20px 22px;
}
.md-typeset .ts-stat-num {
  font-family: var(--ts-font-display, "Space Grotesk", sans-serif);
  font-weight: 600;
  font-size: 2.3rem;
  letter-spacing: -0.02em;
  line-height: 1;
  color: var(--tsc-ink);
}
.md-typeset .ts-stat-label {
  font-family: var(--ts-font-mono, "IBM Plex Mono", monospace);
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  color: var(--tsc-muted);
  margin-top: 0.5rem;
}

/* ---- attractor (viewer iframe / static figure) ---- */
.md-typeset .ts-attractor-fig {
  margin: 0 0 2rem;
}
.md-typeset .ts-attractor {
  display: block;
  width: 100%;
  height: 420px;
  border: 1px solid #16202a;
  border-radius: 14px;
  background: #11151a;
  box-shadow: 0 28px 56px -34px rgba(11, 20, 30, 0.5);
}
.md-typeset .ts-attractor-img {
  width: 100%;
  display: block;
  border: 1px solid var(--tsc-border);
  border-radius: 14px;
  background: var(--tsc-surface);
}
.md-typeset .ts-attractor-cap {
  font-family: var(--ts-font-mono, "IBM Plex Mono", monospace);
  font-size: 0.72rem;
  color: var(--tsc-muted);
  margin-top: 0.55rem;
}

/* ---- animated spatial-field movie hero (Gray–Scott / Swift–Hohenberg) ----
   A square heatmap movie, embedded as an autoplaying <video> (mp4) or <img>
   (gif fallback).  Capped to a tidy centred square so a 720² field never
   dominates a wide page, on the dark brand canvas like the three.js viewer. */
.md-typeset .ts-field-movie-fig {
  text-align: center;
}
.md-typeset .ts-field-movie {
  display: block;
  width: 100%;
  max-width: 440px;
  aspect-ratio: 1 / 1;
  margin: 0 auto;
  object-fit: contain;
  border: 1px solid #16202a;
  border-radius: 14px;
  background: #0b0f14;
  box-shadow: 0 28px 56px -34px rgba(11, 20, 30, 0.5);
}

/* Two-projection layout for a 4-D-plus flow: side-by-side on a wide viewport,
   stacked on a narrow one.  Each panel is a shorter square-ish stage. */
.md-typeset .ts-attractor-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin: 0 0 0.4rem;
}
.md-typeset .ts-attractor-pair .ts-attractor-fig {
  margin: 0;
}
.md-typeset .ts-attractor-pair .ts-attractor {
  height: 340px;
}
.md-typeset .ts-attractor-cap--pair {
  margin: 0 0 2rem;
}
@media (max-width: 820px) {
  .md-typeset .ts-attractor-pair {
    grid-template-columns: 1fr;
  }
}

/* ---- Properties stat cards ---- */
.md-typeset .ts-props {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
  margin: 1rem 0 2rem;
}
@media (min-width: 1000px) {
  .md-typeset .ts-props {
    grid-template-columns: repeat(4, 1fr);
  }
}
.md-typeset .ts-prop {
  background: var(--tsc-surface);
  border: 1px solid var(--tsc-border);
  border-radius: 11px;
  padding: 16px 18px;
  min-width: 0;
}
.md-typeset .ts-prop-label {
  font-family: var(--ts-font-mono, "IBM Plex Mono", monospace);
  font-size: 0.66rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--tsc-muted);
  margin-bottom: 0.6rem;
}
.md-typeset .ts-prop-value {
  font-size: 0.95rem;
  line-height: 1.5;
  color: var(--tsc-ink);
  overflow-wrap: anywhere;
  /* A long Lyapunov spectrum (a wide, non-wrapping KaTeX row) must stay
     INSIDE the card: KaTeX lays its math out with internal absolute
     positioning, so `overflow-wrap` cannot break it.  Cap the width to the
     card and let an over-wide row scroll horizontally within the cell rather
     than spilling over the border into the neighbouring card. */
  max-width: 100%;
  overflow-x: auto;
}
/* Shrink the KaTeX math a touch in this narrow cell so a 3–4 exponent
   spectrum fits without scrolling on a normal-width card, and reduce the
   inter-item glue so the row is compact.  `max-width` keeps any residual
   overflow (a very long spectrum on a very narrow card) scrolling inside
   the box instead of escaping it. */
.md-typeset .ts-prop-value .katex {
  font-size: 0.86em;
  max-width: 100%;
}
.md-typeset .ts-prop-value .katex-display {
  margin: 0;
}
.md-typeset .ts-prop-src {
  display: inline-block;
  font-family: var(--ts-font-mono, "IBM Plex Mono", monospace);
  font-size: 0.66rem;
  color: var(--tsc-muted);
  margin-top: 0.2rem;
}
.md-typeset .ts-prop-todo,
.md-typeset .ts-prop-na {
  font-family: var(--ts-font-mono, "IBM Plex Mono", monospace);
  font-size: 0.74rem;
  color: var(--tsc-muted);
  font-style: italic;
}

/* ---- reference card ---- */
.md-typeset .ts-reference {
  background: var(--tsc-surface);
  border: 1px solid var(--tsc-border);
  border-left: 3px solid var(--ts-teal, #11857a);
  border-radius: 12px;
  padding: 18px 22px;
  margin: 0 0 1.2rem;
  font-size: 0.98rem;
  line-height: 1.55;
}
.md-typeset .ts-reference a {
  font-family: var(--ts-font-mono, "IBM Plex Mono", monospace);
  font-size: 0.82rem;
  color: var(--tsc-link);
}

/* ---- catalogue browser tables (Systems index / type / subcategory) ----
   The generated browser tables (System | Dim | Behavior on a subcategory page,
   Subcategory | Systems | Dim | Examples on a type page, Browse-by-type on the
   index) shrink to their content by default and read cramped.  Make them span
   the full content width with comfortable padding and sensible column widths. */
.md-typeset .md-content__inner > table:not([class]),
.md-typeset .md-content__inner > .md-typeset__table > table,
.md-typeset__table > table {
  width: 100%;
  display: table;
  table-layout: auto;
}
.md-typeset .md-typeset__table {
  width: 100%;
  margin: 1rem 0 2rem;
}
/* Roomier cells + a clear header row. */
.md-typeset table:not([class]) th,
.md-typeset table:not([class]) td {
  padding: 0.62em 1.1em;
  line-height: 1.5;
}
.md-typeset table:not([class]) th {
  font-family: var(--ts-font-mono, "IBM Plex Mono", monospace);
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--tsc-muted);
  background: var(--tsc-surface-2);
  white-space: nowrap;
}
/* First column (System / Subcategory name link) is the widest; keep the name
   on one line and let it take the slack.  Right-align the numeric Dim column.
   SCOPED to the generated catalogue pages only (they carry a `.ts-count` or
   `.ts-stats` marker) — otherwise `white-space: nowrap` on a first column of
   *prose* (e.g. the Conventions colour-map table) forces one unwrappable line
   and blows the table past the page width.  A single-token system name never
   needs the nowrap anyway, so this is a no-op for the catalogue itself. */
.md-typeset:has(.ts-count, .ts-stats) table:not([class]) td:first-child,
.md-typeset:has(.ts-count, .ts-stats) table:not([class]) th:first-child {
  width: 42%;
  white-space: nowrap;
}
.md-typeset table:not([class]) td a {
  font-weight: 600;
}
/* Numeric columns (Dim / Systems counts) — right-aligned, snug, tabular. */
.md-typeset table:not([class]) td[align="right"],
.md-typeset table:not([class]) th[align="right"] {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
/* Zebra striping so long catalogue lists are easy to scan. */
.md-typeset table:not([class]) tbody tr:nth-child(even) {
  background: color-mix(in srgb, var(--tsc-surface-2) 55%, transparent);
}
.md-typeset table:not([class]) tbody tr:hover {
  background: color-mix(in srgb, var(--tsc-link) 8%, transparent);
}

/* ---- wide PROSE tables scroll instead of cramping ----
   The catalogue rules above pin an unclassed table to the content-column width.
   That is right for the 2–4-column catalogue tables, but a *prose* page (pages
   WITHOUT the `.ts-count`/`.ts-stats` markers) can carry a genuinely wide table —
   the References → benchmarks "Integration speed" grid is six columns and needs
   ~880px. Forced to the ~690px column it was crushed. Let a prose table size to
   its content and SCROLL horizontally inside Material's `.md-typeset__scrollwrap`
   (which already has `overflow-x: auto`): `min-width: 100%` keeps a narrow prose
   table filling the column, `max-width: none` lets a wide one grow past it so the
   scroll kicks in. Catalogue tables (on marker pages) are untouched. */
.md-typeset:not(:has(.ts-count, .ts-stats)) .md-typeset__table > table:not([class]) {
  width: auto;
  min-width: 100%;
  max-width: none;
}
/* A dense multi-column prose table (the 6-column benchmark grid) reads better
   tighter: trim the roomy catalogue padding so columns are not swimming in blank
   space, and let the multi-word HEADERS wrap ("TSDynamics interp" on two lines)
   so a header no longer forces its column wide and squeezes the first column.
   The right-aligned numeric CELLS keep their nowrap (short values, tidy tabular
   column); only the headers are allowed to wrap. */
.md-typeset:not(:has(.ts-count, .ts-stats)) .md-typeset__table > table:not([class]) th,
.md-typeset:not(:has(.ts-count, .ts-stats)) .md-typeset__table > table:not([class]) td {
  padding: 0.5em 0.8em;
}
.md-typeset:not(:has(.ts-count, .ts-stats)) .md-typeset__table > table:not([class]) th {
  white-space: normal;
}
/* In a DATA table — one that carries right-aligned numeric columns — keep the
   first-column LABELS on one line: they are short ("Integration — short"), and
   wrapping them into two or three lines is exactly the squished look to avoid;
   nowrap lets each row sit on one line and the table scrolls if it must. A
   pure-prose table (the Conventions colour-map grid has NO right-aligned cell) is
   excluded by `:has(td[style*="right"])`, so its long-sentence first column still
   wraps as it should. */
.md-typeset:not(:has(.ts-count, .ts-stats))
  .md-typeset__table
  > table:not([class]):has(td[style*="right"])
  :is(td, th):first-child {
  white-space: nowrap;
}

/* ---- responsive: single-column cards on narrow viewports ---- */
@media (max-width: 700px) {
  .md-typeset .ts-stats {
    grid-template-columns: 1fr;
  }
  .md-typeset .ts-props {
    grid-template-columns: 1fr;
  }
  .md-typeset .ts-attractor {
    height: 320px;
  }
}

/* Bibliography: the muted "cited by <systems>" line under each reference. */
.md-typeset .ts-cite-systems {
  display: inline-block;
  margin-top: 0.15rem;
  font-family: var(--ts-mono);
  font-size: 0.72em;
  line-height: 1.5;
  color: var(--ts-muted);
}
.md-typeset .ts-cite-systems code {
  font-size: inherit;
  color: inherit;
  background: transparent;
  padding: 0;
}
