:root {
  --bg: #f6f6f4;
  --surface: #ffffff;
  --ink: #17181a;
  --muted: #5c6066;
  --line: #dedfdb;
  --stripe: rgba(23, 24, 26, 0.035);
  --accent: #1d4ed8;
  --edge: #6b7280;

  --person-fill: #d7f0e4;  --person-stroke: #047857; --person-ink: #064e3b;
  --system-fill: #e8e2fb;  --system-stroke: #6d28d9; --system-ink: #3b1d7a;
  --ext-fill: #fbecd9;     --ext-stroke: #b45309;    --ext-ink: #6b3407;
  --dec-fill: #fce1e6;     --dec-stroke: #be123c;    --dec-ink: #7a0f28;
  --unk-fill: #e8eaed;     --unk-stroke: #6b7280;    --unk-ink: #33383f;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101214;
    --surface: #171a1d;
    --ink: #e7e8ea;
    --muted: #9aa0a6;
    --line: #2a2e33;
    --stripe: rgba(255, 255, 255, 0.035);
    --accent: #9cb6ff;
    --edge: #8b9299;

    --person-fill: #0c3a2d;  --person-stroke: #34d399; --person-ink: #c8f0e1;
    --system-fill: #2a1f4c;  --system-stroke: #a78bfa; --system-ink: #e4dbff;
    --ext-fill: #402609;     --ext-stroke: #f59e0b;    --ext-ink: #fde4bd;
    --dec-fill: #451321;     --dec-stroke: #fb7185;    --dec-ink: #ffd9df;
    --unk-fill: #1c2024;     --unk-stroke: #9aa0a6;    --unk-ink: #d6d9dd;
  }
}

:root[data-theme="dark"] {
  --bg: #101214; --surface: #171a1d; --ink: #e7e8ea; --muted: #9aa0a6;
  --line: #2a2e33; --stripe: rgba(255,255,255,0.035); --accent: #9cb6ff; --edge: #8b9299;
  --person-fill: #0c3a2d;  --person-stroke: #34d399; --person-ink: #c8f0e1;
  --system-fill: #2a1f4c;  --system-stroke: #a78bfa; --system-ink: #e4dbff;
  --ext-fill: #402609;     --ext-stroke: #f59e0b;    --ext-ink: #fde4bd;
  --dec-fill: #451321;     --dec-stroke: #fb7185;    --dec-ink: #ffd9df;
  --unk-fill: #1c2024;     --unk-stroke: #9aa0a6;    --unk-ink: #d6d9dd;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.55;
  overflow-x: hidden;
}

a { color: var(--accent); }
a:focus-visible, .scroll:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* header */
.top {
  display: flex; flex-wrap: wrap; gap: 8px 20px; align-items: baseline;
  padding: 14px 16px; border-bottom: 1px solid var(--line); background: var(--surface);
}
.mark {
  font-weight: 600; letter-spacing: -0.01em; text-decoration: none; color: var(--ink);
}
.nav { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 13.5px; }
.nav a { color: var(--muted); text-decoration: none; padding-bottom: 2px; border-bottom: 1px solid transparent; }
.nav a:hover { color: var(--ink); }
.nav a.on { color: var(--ink); border-bottom-color: var(--accent); }

main { max-width: 1120px; margin: 0 auto; padding: 32px 16px 56px; }

.eyebrow {
  margin: 0 0 6px; font-size: 12px; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--muted); font-weight: 500;
}
h1 { margin: 0 0 14px; font-size: clamp(26px, 4.6vw, 38px); line-height: 1.15; letter-spacing: -0.02em; font-weight: 600; }
h2 { margin: 40px 0 12px; font-size: 19px; letter-spacing: -0.01em; font-weight: 600; }
h2.panel { margin: 0 0 10px; font-size: 15px; color: var(--muted); font-weight: 500; }
h3 { margin: 4px 0 6px; font-size: 16px; font-weight: 600; letter-spacing: -0.01em; }
.lede { max-width: 62ch; margin: 0 0 28px; font-size: 17px; color: var(--ink); }
.note { font-size: 13.5px; color: var(--muted); max-width: 70ch; }

/* lists */
.list { list-style: none; padding: 0; margin: 0; max-width: 78ch; }
.list li {
  padding: 9px 0; border-bottom: 1px solid var(--line);
  display: flex; gap: 12px; align-items: baseline; justify-content: space-between;
}
.tag {
  flex: none; font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums;
  border: 1px solid var(--line); border-radius: 999px; padding: 1px 9px; white-space: nowrap;
}
.stories { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; max-width: 62ch; }
.stories li { display: flex; gap: 12px; align-items: baseline; }
.sid { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--accent); }

/* cards */
.cards { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.card {
  display: block; text-decoration: none; color: inherit; background: var(--surface);
  border: 1px solid var(--line); border-radius: 6px; padding: 16px;
}
.card:hover { border-color: var(--accent); }
.card p { margin: 0; font-size: 13.5px; color: var(--muted); }

/* tables */
.tablewrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: 14px; min-width: 560px; }
th, td { text-align: left; padding: 9px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
thead th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 500; }
tbody tr:last-child th, tbody tr:last-child td { border-bottom: 0; }
tbody th { font-weight: 600; white-space: nowrap; }

/* legend */
.legend {
  list-style: none; padding: 0; margin: 0 0 20px;
  display: flex; flex-wrap: wrap; gap: 8px 20px; font-size: 13px; color: var(--muted);
}
.legend li { display: flex; align-items: center; gap: 7px; }
.chip { width: 50px; height: 22px; flex: none; }

/* figure */
.fig { margin: 0 0 28px; }
.hint { margin: 0 0 6px; font-size: 12px; color: var(--muted); }
.scroll {
  overflow-x: auto; overflow-y: hidden; background: var(--surface);
  border: 1px solid var(--line); border-radius: 6px; padding: 8px;
}
.scroll svg { display: block; max-width: none; }
figcaption { margin-top: 8px; font-size: 13px; color: var(--muted); max-width: 78ch; }

/* diagram internals */
.lane-a { fill: transparent; }
.lane-b { fill: var(--stripe); }
.rule { stroke: var(--line); stroke-width: 1; }
.band { fill: var(--stripe); }
.bandlab { fill: var(--muted); font-size: 12px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; }
.lanelab { fill: var(--muted); font-size: 12px; font-weight: 500; }
.e { fill: none; stroke: var(--edge); stroke-width: 1.6; }
.e-dash { stroke-dasharray: 6 4; }
.arh { fill: var(--edge); }
.el { fill: var(--muted); font-size: 11px; paint-order: stroke; stroke: var(--surface); stroke-width: 3.5px; stroke-linejoin: round; }
.n { stroke-width: 1.6; }
.n-person { fill: var(--person-fill); stroke: var(--person-stroke); }
.n-system { fill: var(--system-fill); stroke: var(--system-stroke); }
.n-external { fill: var(--ext-fill); stroke: var(--ext-stroke); }
.n-decision { fill: var(--dec-fill); stroke: var(--dec-stroke); }
.n-unknown { fill: var(--unk-fill); stroke: var(--unk-stroke); stroke-dasharray: 5 4; }
.nl { font-size: 11.5px; text-anchor: middle; }
.nl-person { fill: var(--person-ink); }
.nl-system, .nl-state { fill: var(--system-ink); }
.nl-external { fill: var(--ext-ink); }
.nl-decision { fill: var(--dec-ink); font-weight: 600; }
.nl-unknown { fill: var(--unk-ink); }
.glyph { fill: var(--person-stroke); }
.qmark { fill: var(--unk-stroke); font-size: 15px; font-weight: 600; text-anchor: middle; }
.qb { fill: var(--accent); }
.qt { fill: var(--surface); font-size: 10.5px; font-weight: 600; text-anchor: middle; }
.startdot { fill: var(--ink); }

.foot {
  border-top: 1px solid var(--line); padding: 16px; text-align: center;
  font-size: 12.5px; color: var(--muted); background: var(--surface);
}

@media (max-width: 560px) {
  .list li { flex-direction: column; gap: 4px; }
}

@media print {
  @page { size: A4 landscape; margin: 10mm; }
  body { background: #fff; color: #000; font-size: 11px; }
  .top, .nav, .hint { display: none; }
  main { max-width: none; padding: 0; }
  .fig { break-inside: avoid; page-break-inside: avoid; page-break-after: always; }
  .scroll { overflow: visible; border: 0; padding: 0; }
  .scroll svg { width: 100% !important; height: auto !important; }
  h1 { font-size: 18px; }
  .lede { font-size: 12px; }
  .foot { border: 0; }
}
