/* Flink SQL patterns: design tokens, layout, and the job-graph visual language.
   Colours follow the Confluent palette used in the flink-intro talk. */

:root {
  color-scheme: light;
  --paper: #ffffff;
  --panel: #f3f6fb;
  --panel-2: #e8eef8;
  --ink: #10203a;
  --ink-2: #4a5872;
  --ink-3: #7a879c;
  --rule: #d6deea;
  --blue: #0056f9;
  --blue-soft: #e5edff;
  --green: #00916a;
  --green-soft: #ddf5ec;
  --red: #d6363f;
  --red-soft: #fde6e7;
  --violet: #7b3fe4;
  --violet-soft: #efe7fd;
  --orange: #d9590b;
  --orange-soft: #fdeadc;
  --wm: #ffdc00;
  --wm-ink: #3d3200;
  --wm-line: #c9a800;
  --hot: #fff4b8;
  --node: #ffffff;
  --shadow: 0 1px 2px rgb(16 32 58 / 0.06), 0 4px 16px rgb(16 32 58 / 0.06);

  --font-display: 'Poppins', ui-sans-serif, system-ui, sans-serif;
  --font-body: 'IBM Plex Sans', ui-sans-serif, system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  --measure: 70ch;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --paper: #0d1726;
    --panel: #142236;
    --panel-2: #1b2d46;
    --ink: #e7edf6;
    --ink-2: #a9b6c9;
    --ink-3: #7d8ba1;
    --rule: #26384f;
    --blue: #5b8fff;
    --blue-soft: #16294d;
    --green: #2fcf98;
    --green-soft: #0f3529;
    --red: #ff6b72;
    --red-soft: #3d1a20;
    --violet: #ad85ff;
    --violet-soft: #2a1d4a;
    --orange: #ff9a52;
    --orange-soft: #3d2614;
    --wm: #ffdc00;
    --wm-ink: #2b2300;
    --wm-line: #ffdc00;
    --hot: #4a4210;
    --node: #17263b;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 4px 16px rgb(0 0 0 / 0.25);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #0d1726;
  --panel: #142236;
  --panel-2: #1b2d46;
  --ink: #e7edf6;
  --ink-2: #a9b6c9;
  --ink-3: #7d8ba1;
  --rule: #26384f;
  --blue: #5b8fff;
  --blue-soft: #16294d;
  --green: #2fcf98;
  --green-soft: #0f3529;
  --red: #ff6b72;
  --red-soft: #3d1a20;
  --violet: #ad85ff;
  --violet-soft: #2a1d4a;
  --orange: #ff9a52;
  --orange-soft: #3d2614;
  --wm: #ffdc00;
  --wm-ink: #2b2300;
  --wm-line: #ffdc00;
  --hot: #4a4210;
  --node: #17263b;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 4px 16px rgb(0 0 0 / 0.25);
}

/* ---------- Base ---------- */

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 24px; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 17px/1.6 var(--font-body);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { font-family: var(--font-display); font-weight: 600; line-height: 1.15; margin: 0; letter-spacing: -0.01em; }
p { margin: 0 0 0.9em; }
a { color: var(--blue); text-underline-offset: 2px; }
code, kbd { font-family: var(--font-mono); font-size: 0.86em; }
:not(pre) > code { background: var(--panel); border: 1px solid var(--rule); border-radius: 4px; padding: 0.05em 0.3em; }
kbd { border: 1px solid var(--rule); border-bottom-width: 2px; border-radius: 4px; padding: 0 0.35em; background: var(--paper); }
:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; border-radius: 4px; }

.skip { position: absolute; left: -999px; top: 8px; background: var(--paper); padding: 8px 12px; z-index: 10; }
.skip:focus { left: 16px; }

/* ---------- Hero ---------- */

.hero { border-bottom: 1px solid var(--rule); overflow: hidden; }
.hero-inner { max-width: 1440px; margin: 0 auto; padding: 72px 24px 36px; }
.hero h1 { font-size: clamp(2.1rem, 5.2vw, 3.6rem); letter-spacing: -0.025em; text-wrap: balance; }
.subtitle { font-family: var(--font-display); font-weight: 500; font-size: clamp(1.15rem, 2.2vw, 1.375rem); line-height: 1.3; color: var(--ink); margin-top: 12px; }
/* The subtitle breaks before "and the science", and never sets the hero's width (which would push
   the graph to the far right): it fills the column the lede sets, each part starts a new line, and a
   part wraps, balanced, only when it doesn't fit. At its largest size, the first part fits beside
   the graph. */
.subtitle { width: 0; min-width: 100%; }
.subtitle span { display: block; text-wrap: balance; }
.lede { font-size: 1.15rem; color: var(--ink-2); max-width: 58ch; margin-top: 18px; }

/* The hero's job graph in miniature, beside the title when there's room. Records are drawn by js/hero.js. */
/* The text column is only as wide as the lede, so the graph sits beside it, not at the far edge. */
.hero-inner { display: grid; grid-template-columns: minmax(0, max-content) auto; justify-content: start; align-items: center; gap: 48px 80px; }
.hero-graph { width: 400px; height: auto; overflow: visible; }
.hg-node { fill: var(--node); stroke: var(--ink-3); stroke-width: 1.5; }
.hg-state-bar { fill: var(--blue); }
.hg-line { fill: var(--ink-3); opacity: 0.55; }
.hg-dim { opacity: 0.3; }
.hg-edge { fill: none; stroke-width: 2.5; }
.hg-edge.mode-append { stroke: var(--blue); }
.hg-edge.mode-upsert { stroke: var(--violet); }
.hg-arrow.mode-append { fill: var(--blue); }
.hg-arrow.mode-upsert { fill: var(--violet); }
.hg-tie { stroke: var(--rule); stroke-width: 1.5; }
.hg-panel { fill: var(--panel); stroke: var(--rule); stroke-width: 1.5; }
.hg-key { fill: var(--ink-3); opacity: 0.45; }
.hg-val { fill: var(--blue); opacity: 0.35; transition: opacity 0.3s, fill 0.3s; }
.hg-val.hot { opacity: 1; }
.hg-dot.mode-append { fill: var(--blue); }
.hg-dot.mode-upsert { fill: var(--violet); }
.hg-wm { fill: var(--wm); stroke: var(--wm-line); stroke-width: 1; }
@media (max-width: 1100px) {
  .hero-inner { grid-template-columns: minmax(0, 1fr); }
  .hero-graph { display: none; }
}

/* ---------- Layout ---------- */

.layout { max-width: 1440px; margin: 0 auto; padding: 0 24px; display: grid; grid-template-columns: 1fr; }
main { min-width: 0; }
/* The table of contents only appears when there's room for it beside a full-width stage. */
@media (min-width: 1680px) {
  .layout { max-width: 1688px; grid-template-columns: 200px minmax(0, 1fr); gap: 48px; }
}
.toc { display: none; }
@media (min-width: 1680px) {
  .toc { display: block; position: sticky; top: 0; align-self: start; padding: 40px 0; }
}
.toc ol, .toc-pop ol { list-style: none; margin: 0; padding: 0; border-left: 2px solid var(--rule); }
.toc a, .toc-pop a {
  display: block; padding: 6px 0 6px 14px; margin-left: -2px; border-left: 2px solid transparent;
  color: var(--ink-2); text-decoration: none; font-size: 0.92rem; line-height: 1.35;
}
.toc a:hover, .toc-pop a:hover { color: var(--ink); }
.toc a[aria-current], .toc-pop a[aria-current] { color: var(--ink); border-left-color: var(--blue); font-weight: 500; }
.toc ol ol, .toc-pop ol ol { border-left: 0; margin-bottom: 4px; }
.toc ol ol a, .toc-pop ol ol a { padding: 2px 0 2px 26px; font-size: 0.84rem; color: var(--ink-3); }

/* Top-right corner controls: the theme toggle, and without the sidebar, a button that opens the
   same contents list in a popover. They sit at the top so they never cover the player controls,
   which tend to be near the bottom. */
.corner {
  position: fixed; z-index: 5; display: flex; gap: 8px;
  right: max(16px, env(safe-area-inset-right)); top: max(16px, env(safe-area-inset-top));
}
.theme-toggle {
  display: inline-grid; place-items: center; width: 44px; height: 44px; padding: 0;
  border: 1px solid var(--rule); border-radius: 50%; background: var(--node); color: var(--ink);
  box-shadow: var(--shadow); cursor: pointer;
}
.theme-toggle:hover { border-color: var(--ink-3); }
.theme-toggle svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
/* The icon shows what the button switches to. */
.theme-toggle[aria-pressed="true"] .moon, .theme-toggle[aria-pressed="false"] .sun { display: none; }
.toc-fab {
  display: inline-flex; align-items: center; gap: 8px; height: 44px; padding: 0 18px 0 14px;
  border: 0; border-radius: 999px; background: var(--blue); color: #fff;
  box-shadow: 0 2px 6px rgb(0 40 120 / 0.25), 0 8px 24px rgb(0 40 120 / 0.25);
  font: 500 0.95rem/1 var(--font-body); cursor: pointer;
}
.toc-fab:hover { filter: brightness(1.08); }
.toc-fab:focus-visible, .theme-toggle:focus-visible { outline-offset: 3px; }
.toc-fab svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; }
.toc-pop {
  /* Drops down from the button, as tall as the window allows, with a 16px margin at the bottom. */
  position: fixed; inset: calc(max(16px, env(safe-area-inset-top)) + 52px) max(16px, env(safe-area-inset-right)) auto auto;
  margin: 0; width: min(320px, calc(100vw - 32px)); overflow-y: auto; overscroll-behavior: contain;
  max-height: calc(100vh - max(16px, env(safe-area-inset-top)) - 52px - 16px);
  max-height: calc(100dvh - max(16px, env(safe-area-inset-top)) - 52px - 16px);
  padding: 12px 16px 12px 14px; border: 1px solid var(--rule); border-radius: var(--radius);
  background: var(--node); color: var(--ink); box-shadow: var(--shadow);
}
/* Tighter rows than the sidebar, so the whole list fits on a phone. */
.toc-pop a { padding-block: 5px; }
.toc-pop ol ol a { padding-block: 1px; }
@media (min-width: 1680px) { .toc-fab, .toc-pop { display: none; } }

.footer { max-width: 1440px; margin: 0 auto; padding: 40px 24px 64px; color: var(--ink-3); font-size: 0.9rem; }
.footer p { max-width: var(--measure); }
.footer .source { margin-top: 12px; }
.footer .marks { margin-top: 12px; font-size: 0.82rem; }
.footer a { color: inherit; }
/* With the table of contents showing, the hero text and the footer line up with the main column:
   same container as .layout, indented by the sidebar and its gap. */
@media (min-width: 1680px) {
  .footer, .hero-inner { max-width: 1688px; padding-left: calc(24px + 200px + 48px); }
}
h1 .tm { font-size: 0.4em; vertical-align: super; line-height: 0; margin-left: 0.05em; }

/* ---------- Primer ---------- */

.primer { padding: 48px 0 24px; border-bottom: 1px solid var(--rule); }
.primer h2 { font-size: 1.5rem; margin-bottom: 12px; }
.primer > p { max-width: var(--measure); color: var(--ink-2); }
.primer-list { max-width: var(--measure); color: var(--ink-2); margin: 12px 0 0; padding-left: 1.25em; }
.primer-list li + li { margin-top: 8px; }
.legend { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); gap: 20px 32px; margin: 24px 0 0; }
/* The diagram legend: four cards, in a row on the page, and 2 x 2 when there's less room
   (always, in the Help popover). Never three and one. Row kinds and Watermarks share a card. */
#reading { container-type: inline-size; }
.diagram-key { grid-template-columns: 1fr; gap: 16px; }
@container (min-width: 560px) { .diagram-key { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@container (min-width: 1000px) { #reading .diagram-key { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.help-pop .diagram-key { grid-template-columns: repeat(auto-fill, minmax(max(min(100%, 260px), calc((100% - 16px) / 2)), 1fr)); }
.diagram-key > div { padding: 18px 20px 20px; background: var(--panel); border-radius: var(--radius); }
.legend.diagram-key dt { margin-bottom: 12px; }
.legend.diagram-key dd { line-height: 1.5; }
.diagram-key dd + dt { margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--rule); }
.diagram-key dd > p:first-child { margin-bottom: 12px; }
.diagram-key .legend-note { margin-top: 14px; font-size: 0.9rem; }
/* Each chip with its description under it; the row kinds' short ones go beside them. */
.key-items { list-style: none; margin: 0; padding: 0; }
.key-items li > :last-child { display: block; margin-top: 5px; }
.key-items li + li { margin-top: 14px; }
.key-items.inline li { display: flex; align-items: baseline; gap: 10px; }
.key-items.inline li > :last-child { margin-top: 0; }
.key-items.inline li + li { margin-top: 8px; }
.legend dt { font-family: var(--font-display); font-weight: 600; font-size: 0.95rem; margin-bottom: 6px; }
.legend dd { margin: 0; color: var(--ink-2); font-size: 0.95rem; line-height: 1.9; }
.legend dd + dt { margin-top: 16px; }
.primer > p + p, .resources + p { margin-top: 24px; }
.primer-help { margin-top: 20px; font-size: 0.95rem; }
/* Before you start: videos and docs, side by side when there's room. */
.resources { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr)); gap: 20px 32px; margin-top: 28px; max-width: 1100px; }
.resources h3 { font-family: var(--font-display); font-weight: 600; font-size: 0.95rem; margin-bottom: 6px; }
.resources ul { margin: 0; padding-left: 1.1em; color: var(--ink-2); font-size: 0.95rem; }
.resources li + li { margin-top: 6px; }
.resources-note { margin-top: 8px; color: var(--ink-3); font-size: 0.85rem; }

.badge {
  display: inline-block; font: 500 12px/1 var(--font-mono); padding: 4px 9px; border-radius: 999px;
  border: 1.5px solid currentColor; vertical-align: 1px;
}
.badge.mode-append { color: var(--blue); background: var(--blue-soft); }
.badge.mode-upsert { color: var(--violet); background: var(--violet-soft); }
.badge.mode-retract { color: var(--orange); background: var(--orange-soft); }

.rk {
  display: inline-block; min-width: 2.2em; text-align: center; font: 600 11.5px/1 var(--font-mono);
  padding: 3px 5px; border-radius: 999px; border: 1.5px solid; vertical-align: 1px;
}
.rk-I { background: var(--green); border-color: var(--green); color: var(--paper); }
.rk-UA { background: var(--paper); border-color: var(--green); color: var(--green); }
.rk-UB { background: var(--paper); border-color: var(--red); color: var(--red); }
.rk-D { background: var(--red); border-color: var(--red); color: var(--paper); }
.legend .rk { margin-left: 2px; }
.legend-note { display: block; margin-top: 8px; line-height: 1.6; }

.wm-chip {
  display: inline-block; font: 600 11.5px/1 var(--font-mono); background: var(--wm); color: var(--wm-ink);
  padding: 4px 8px; border-radius: 3px; vertical-align: 1px;
}
.node-chip {
  display: inline-block; font-size: 0.85rem; line-height: 1; padding: 6px 10px; border-radius: 7px;
  border: 1.5px solid var(--ink-3); background: var(--node); color: var(--ink);
}
.node-chip.stateful { box-shadow: inset 4px 0 0 var(--blue); }
.node-chip.stateful.needs-ttl { box-shadow: inset 4px 0 0 var(--ink); }
.node-chip.planner { border-style: dashed; }

/* ---------- Pattern section ---------- */

.pattern { padding: 64px 0 40px; border-bottom: 1px solid var(--rule); }
.pattern-head h2 { font-size: clamp(1.8rem, 3.4vw, 2.4rem); letter-spacing: -0.02em; }
.summary { max-width: var(--measure); color: var(--ink-2); margin-top: 14px; }

.variants { display: inline-flex; gap: 4px; padding: 4px; margin: 8px 0 20px; background: var(--panel); border: 1px solid var(--rule); border-radius: 999px; flex-wrap: wrap; }
.variant-tab {
  font: 500 0.92rem/1 var(--font-body); color: var(--ink-2); background: transparent; border: 0;
  padding: 9px 16px; border-radius: 999px; cursor: pointer;
}
.variant-tab:hover { color: var(--ink); }
.variant-tab[aria-selected="true"] { background: var(--paper); color: var(--ink); box-shadow: var(--shadow); }

.variant-blurb { max-width: var(--measure); color: var(--ink-2); }
/* The business question each example answers, in the pizza chain's words. */
.question {
  position: relative; width: fit-content; max-width: min(100%, 46ch); margin: 4px 0 24px;
  padding: 16px 24px 16px 60px; border-radius: 12px; background: var(--blue-soft); color: var(--ink);
  font-family: var(--font-display); font-weight: 500; font-size: clamp(1.2rem, 2.3vw, 1.5rem); line-height: 1.3;
}
.question::before {
  content: '\201C'; position: absolute; left: 16px; top: 8px; color: var(--blue);
  font: 700 3em/1 Georgia, 'Times New Roman', serif;
}
@media (max-width: 760px) {
  .question { padding: 14px 18px 14px 48px; }
  .question::before { left: 12px; }
}

.code-and-facts { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 28px; align-items: start; }
@media (max-width: 860px) { .code-and-facts { grid-template-columns: minmax(0, 1fr); } }

pre.code {
  margin: 0; padding: 16px 0; background: var(--panel); border: 1px solid var(--rule); border-radius: var(--radius);
  font: 400 14px/1.6 var(--font-mono); overflow-x: auto; tab-size: 2;
}
pre.code code { display: block; min-width: max-content; }
pre.code .ln { display: inline-block; width: 100%; padding: 0 18px; border-left: 3px solid transparent; transition: background-color 0.25s; }
pre.code .ln.hot { background: var(--blue-soft); border-left-color: var(--blue); }
.t-kw { color: var(--blue); font-weight: 500; }
.t-type { color: var(--violet); }
.t-str { color: var(--green); }
.t-num { color: var(--orange); }
.t-fn { color: var(--violet); }
.t-com { color: var(--ink-3); font-style: italic; }
pre.plan { font-size: 12.5px; padding: 14px 18px; white-space: pre; }

.ddl { margin-top: 10px; }
.ddl > summary, .more > summary { cursor: pointer; color: var(--ink-2); font-weight: 500; font-size: 0.95rem; padding: 4px 0; }
.ddl > summary:hover, .more > summary:hover { color: var(--ink); }
.ddl pre { margin-top: 8px; font-size: 13px; }

.facts { margin: 0; display: grid; gap: 16px; }
.facts > div { border-left: 3px solid var(--rule); padding-left: 14px; }
.facts dt { font-family: var(--font-display); font-weight: 600; font-size: 0.95rem; }
.facts dd { margin: 2px 0 0; color: var(--ink-2); font-size: 0.97rem; }

/* ---------- Stage ---------- */

.stage {
  margin-top: 28px; padding: 20px 20px 22px; background: var(--paper); border: 1px solid var(--rule);
  border-radius: 14px; box-shadow: var(--shadow);
}
.stage:focus-visible { outline-offset: 3px; border-radius: 14px; }
.graph-wrap { display: flex; min-height: 120px; overflow-x: auto; }
.graph-wrap > svg { flex-shrink: 0; margin: 0 auto; }

.caption-row { display: flex; gap: 20px; align-items: flex-start; justify-content: space-between; margin-top: 12px; padding-top: 14px; border-top: 1px solid var(--rule); }
.caption { margin: 0; flex: 1; min-height: 3.2em; max-width: 72ch; font-size: 1rem; }
@media (max-width: 760px) { .caption-row { flex-direction: column-reverse; gap: 10px; } }

.controls { display: flex; align-items: center; gap: 6px; flex-shrink: 0; flex-wrap: wrap; }
@media (max-width: 760px) { .stage { padding: 14px 12px 16px; } .counter { min-width: 0; } }
.ctl {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; min-width: 36px;
  padding: 0 8px; border: 1px solid var(--rule); border-radius: 8px; background: var(--paper); color: var(--ink);
  font: 500 0.92rem/1 var(--font-body); cursor: pointer;
}
.ctl:hover:not(:disabled) { border-color: var(--ink-3); }
.ctl:disabled { color: var(--ink-3); opacity: 0.5; cursor: default; }
.ctl svg { width: 16px; height: 16px; fill: currentColor; stroke: currentColor; stroke-width: 1.5; stroke-linejoin: round; }
.ctl.play { background: var(--blue); border-color: var(--blue); color: #fff; padding: 0 14px 0 10px; min-width: 92px; }
.ctl.play:hover { filter: brightness(1.08); }
/* Help stands apart from the playback controls: a soft blue pill with a question-mark badge. */
.ctl.help { margin-left: 6px; padding: 0 14px 0 6px; border-color: var(--blue); border-radius: 999px; background: var(--blue-soft); color: var(--blue); font-weight: 600; }
.ctl.help:hover { border-color: var(--blue); filter: brightness(1.04); }
.help-icon { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--blue); color: var(--paper); font: 700 0.8rem/1 var(--font-body); }
/* Help, beside each diagram's controls: the primer's legend in a popover, placed by js/player.js. */
.help-pop {
  position: fixed; inset: auto; margin: 0; width: min(780px, calc(100vw - 32px)); overflow: auto;
  padding: 20px 24px 24px; background: var(--node); color: var(--ink);
  border: 1px solid var(--rule); border-radius: 12px; box-shadow: var(--shadow);
}
.help-pop h3 { font-family: var(--font-display); font-weight: 600; font-size: 1.05rem; margin-bottom: 8px; }
.help-pop > p { color: var(--ink-2); font-size: 0.95rem; max-width: var(--measure); }
.help-pop .legend { margin-top: 16px; }
.edge-badge, .wm-tag, .node.stateful, .node.planner { cursor: help; }
/* The diagrams' hover explanations, shown by js/graph.js. */
.tip {
  position: fixed; z-index: 30; max-width: min(320px, calc(100vw - 16px)); padding: 8px 10px; pointer-events: none;
  background: var(--ink); color: var(--paper); border-radius: 6px; box-shadow: var(--shadow);
  font: 400 0.85rem/1.45 var(--font-body); white-space: pre-line; opacity: 0; transition: opacity 0.1s;
}
.tip.show { opacity: 1; }
.speed { height: 36px; border: 1px solid var(--rule); border-radius: 8px; background: var(--paper); color: var(--ink); font: 0.9rem var(--font-body); padding: 0 6px; }
.counter { font: 500 12.5px var(--font-mono); color: var(--ink-3); min-width: 4.5em; text-align: right; }

.scrub { width: 100%; margin: 14px 0 4px; accent-color: var(--blue); }

/* ---------- Kafka topics as tables ---------- */

.topics { display: flex; flex-wrap: wrap; gap: 18px 24px; margin-top: 16px; }
.topic { margin: 0; flex: 0 1 auto; min-width: 0; max-width: 100%; }
.topic figcaption { display: flex; gap: 8px; align-items: baseline; margin-bottom: 6px; }
.topic-name { font: 500 13.5px var(--font-mono); }
.topic-note { font-size: 0.82rem; color: var(--ink-3); }
.table-scroll { overflow-x: auto; border: 1px solid var(--rule); border-radius: 8px; }
.topic table { width: 100%; border-collapse: collapse; font: 400 12.5px/1.4 var(--font-mono); }
.topic th { text-align: left; font-weight: 500; color: var(--ink-3); background: var(--panel); padding: 6px 8px; border-bottom: 1px solid var(--rule); white-space: nowrap; }
.topic td { padding: 5px 8px; border-bottom: 1px solid var(--rule); white-space: nowrap; }
.topic tr:last-child td { border-bottom: 0; }
.topic .num { text-align: right; }
.topic .key { font-weight: 500; }
.topic tr.read td { color: var(--ink-3); }
.topic tr.next td:first-child { box-shadow: inset 3px 0 0 var(--blue); }
.topic tr.current td { background: var(--hot); color: var(--ink); }
.topic td.tombstone { color: var(--red); font-style: italic; }
.topic tr.empty td { color: var(--ink-3); font-style: italic; text-align: center; }

/* ---------- Details ---------- */

.more { margin-top: 20px; }
.more-body { max-width: var(--measure); margin-top: 8px; color: var(--ink-2); }
.more-body h4 { font: 600 1rem/1.3 var(--font-display); color: var(--ink); margin: 1.4em 0 0.5em; }
.more-body ul { padding-left: 1.2em; }
.more-body li { margin-bottom: 0.4em; }
.more-plan p { color: var(--ink-2); font-size: 0.95rem; margin: 16px 0 8px; }

/* ---------- Job graph SVG ---------- */

.jobgraph { width: 100%; height: auto; overflow: visible; font-family: var(--font-body); }

.edge { fill: none; stroke-width: 2.5; }
.edge.mode-append { stroke: var(--blue); }
.edge.mode-upsert { stroke: var(--violet); }
.edge.mode-retract { stroke: var(--orange); }
.edge.mode-lookup { stroke: var(--ink-3); stroke-width: 1.5; stroke-dasharray: 5 4; }
.edge-lookup-label { font: italic 400 11px var(--font-body); fill: var(--ink-3); }
.node-external .node-box { fill: var(--panel-2); stroke-dasharray: 2 3; }
.arrow.mode-append path { fill: var(--blue); }
.arrow.mode-upsert path { fill: var(--violet); }
.arrow.mode-retract path { fill: var(--orange); }

.edge-badge rect { stroke-width: 1.5; }
.edge-badge text { font: 500 11px var(--font-mono); }
.edge-badge.mode-append rect { fill: var(--blue-soft); stroke: var(--blue); }
.edge-badge.mode-append text { fill: var(--blue); }
.edge-badge.mode-upsert rect { fill: var(--violet-soft); stroke: var(--violet); }
.edge-badge.mode-upsert text { fill: var(--violet); }
.edge-badge.mode-retract rect { fill: var(--orange-soft); stroke: var(--orange); }
.edge-badge.mode-retract text { fill: var(--orange); }
.edge-badge text.edge-exchange { fill: var(--ink-3); font-size: 10.5px; font-weight: 400; }

.node-box { fill: var(--node); stroke: var(--ink-3); stroke-width: 1.5; transition: stroke 0.2s; }
.node-source .node-box, .node-sink .node-box { fill: var(--panel); }
.node.planner .node-box { stroke-dasharray: 5 4; }
.node-state-bar { fill: var(--blue); }
.node.needs-ttl .node-state-bar { fill: var(--ink); }
.node-title { font: 600 13px var(--font-display); fill: var(--ink); }
.node-line { font: 400 11.5px var(--font-mono); fill: var(--ink-2); }
.node-planner { font: italic 400 11px var(--font-body); fill: var(--ink-3); }
.node.active .node-box { stroke: var(--blue); stroke-width: 3; }

.state-box { fill: var(--panel); stroke: var(--rule); stroke-width: 1; }
.state-title { font: 600 11.5px var(--font-body); fill: var(--ink-2); }
.state-row { font: 400 11.5px var(--font-mono); fill: var(--ink); white-space: pre; }
.state-col { font: 400 10.5px var(--font-mono); fill: var(--ink-3); }
.state-foot { font: 400 10.5px var(--font-mono); fill: var(--ink-2); }
.state-rule { stroke: var(--rule); stroke-width: 1; }
.state-empty { font: italic 400 11.5px var(--font-body); fill: var(--ink-3); }
.state-hot { fill: var(--hot); }
/* State that can grow without limit: the panel's lower edge is torn. */
.state-torn { stroke: var(--ink-3); stroke-linejoin: round; }

/* How state is bounded: tags on the state panels, glyphs on the rows of mixed panels, and chips
   in the legend and the summary table. The glyphs are symbols in index.html. */
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.st-tag rect { stroke-width: 1; }
.st-tag text { font: 500 10px var(--font-body); }
.st-tag.st-wm rect { fill: var(--wm); stroke: var(--wm-line); }
.st-tag.st-wm text, .st-tag.st-wm use { fill: var(--wm-ink); color: var(--wm-ink); }
.st-tag.st-small rect { fill: var(--paper); stroke: var(--rule); }
.st-tag.st-small text, .st-tag.st-small use { fill: var(--ink-2); color: var(--ink-2); }
.st-tag.st-keys rect, .st-tag.st-rows rect { fill: var(--ink); stroke: var(--ink); }
.st-tag.st-keys text, .st-tag.st-rows text, .st-tag.st-keys use, .st-tag.st-rows use { fill: var(--paper); color: var(--paper); }
.st-glyph.st-wm { color: var(--wm-ink); --g-fill: var(--wm); --g-line: var(--wm-line); }
.st-glyph.st-small { color: var(--ink-3); }
.st-glyph.st-keys, .st-glyph.st-rows { color: var(--ink); }
.st-chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px 1px 6px; border: 1px solid;
  border-radius: 999px; font: 500 0.78rem/1.35 var(--font-body); white-space: nowrap; vertical-align: 1px;
}
.st-chip svg { width: 10px; height: 10px; flex: none; }
.st-chip.st-wm { background: var(--wm); border-color: var(--wm-line); color: var(--wm-ink); }
.st-chip.st-small { background: var(--paper); border-color: var(--rule); color: var(--ink-2); }
.st-chip.st-keys, .st-chip.st-rows { background: var(--ink); border-color: var(--ink); color: var(--paper); }

.wm-tag rect { fill: var(--wm); }
.wm-tag text { font: 600 10px var(--font-mono); fill: var(--wm-ink); }

.pill text { font: 500 11px var(--font-mono); }
.pill-body { fill: var(--node); stroke: var(--ink-3); stroke-width: 1; }
.pill-label { fill: var(--ink); }
.pill-kind-text { font-weight: 600 !important; font-size: 10.5px !important; }
.pill.rk-I .pill-kind { fill: var(--green); }
.pill.rk-I .pill-kind-text { fill: var(--paper); }
.pill.rk-UA .pill-kind { fill: var(--paper); stroke: var(--green); stroke-width: 1.5; }
.pill.rk-UA .pill-kind-text { fill: var(--green); }
.pill.rk-UB .pill-kind { fill: var(--paper); stroke: var(--red); stroke-width: 1.5; }
.pill.rk-UB .pill-kind-text { fill: var(--red); }
.pill.rk-D .pill-kind { fill: var(--red); }
.pill.rk-D .pill-kind-text { fill: var(--paper); }
.pill.rk-I .pill-body, .pill.rk-UA .pill-body { stroke: var(--green); }
.pill.rk-UB .pill-body, .pill.rk-D .pill-body { stroke: var(--red); }
.pill-wm rect { fill: var(--wm); stroke: var(--wm-line); }
.pill-wm text { fill: var(--wm-ink); font-weight: 600; font-size: 10.5px; }

.pill.enter { animation: pill-in 0.35s ease-out; }
@keyframes pill-in { from { opacity: 0; } to { opacity: 1; } }
.pill.dropped .pill-body { stroke: var(--red); stroke-dasharray: 3 2; }
@media (prefers-reduced-motion: reduce) { .pill.enter { animation: none; } }

/* ---------- Summary table ---------- */

.matrix { padding: 64px 0 40px; }
.matrix h2 { font-size: 1.5rem; margin-bottom: 12px; }
.matrix > p { max-width: var(--measure); color: var(--ink-2); }
.matrix-wrap { margin-top: 24px; }
.matrix table { width: 100%; border-collapse: collapse; font-size: 0.93rem; line-height: 1.45; }
.matrix th, .matrix td { text-align: left; vertical-align: top; padding: 10px 14px 10px 0; }
.matrix thead th {
  font: 600 0.85rem/1.3 var(--font-display); color: var(--ink-2); border-bottom: 2px solid var(--rule); padding-bottom: 8px;
}
.matrix tbody tr { border-bottom: 1px solid var(--rule); }
.matrix tbody tr.group-start { border-top: 2px solid var(--rule); }
.matrix tbody tr.shade { background: var(--panel); }
.matrix .m-kinds { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.matrix .m-memory { display: block; margin-top: 4px; font-size: 0.86em; color: var(--ink-2); }
.matrix tr > :first-child { padding-left: 12px; }
.matrix tbody th { font-weight: 500; width: 14%; }
.matrix tbody th a { color: var(--ink); text-decoration: none; display: block; }
.matrix tbody th a:hover .m-pattern, .matrix tbody th a:focus-visible .m-pattern { text-decoration: underline; }
.matrix .m-variant { display: block; color: var(--ink-2); font-weight: 400; }
.matrix tbody tr:not(.group-start) .m-pattern { display: none; }
.matrix td:nth-child(2) { width: 24%; }
.matrix td:nth-child(3) { width: 18%; }
.matrix td:nth-child(4) { width: 20%; }
.matrix td { color: var(--ink-2); }
.matrix td.m-new-wm { color: var(--ink); font-weight: 600; }
.matrix .badge { white-space: nowrap; }

/* Phones: each variant becomes a small labelled block. */
@media (max-width: 760px) {
  .matrix thead { display: none; }
  .matrix table, .matrix tbody, .matrix tr, .matrix th, .matrix td { display: block; width: auto !important; }
  .matrix tbody tr { padding: 12px; }
  .matrix tr > :first-child { padding-left: 0; }
  .matrix tbody tr:not(.group-start) .m-pattern { display: inline; }
  .matrix tbody th { padding: 0 0 6px; }
  .matrix .m-variant { display: inline; }
  .matrix .m-variant::before { content: ': '; }
  .matrix td { display: grid; grid-template-columns: 8.5em 1fr; gap: 10px; padding: 3px 0; }
  .matrix td::before { content: attr(data-label); color: var(--ink-3); font-size: 0.85rem; }
  .matrix td .badge { justify-self: start; }
}
