:root {
  --t0: #3987e5;
  --t1: #eb6834;
  --t2: #1baf7a;
  --t2-soft: rgba(27, 175, 122, .16);
  --t3: #9085e9;
  --t3-soft: rgba(144, 133, 233, .16);
  --store: color-mix(in srgb, var(--accent) 14%, var(--surface));
}

:root[data-theme="light"] {
  --t0: #2a78d6;
  --t1: #d9591f;
  --t2: #14935f;
  --t2-soft: rgba(20, 147, 95, .1);
  --t3: #6f5fd6;
  --t3-soft: rgba(111, 95, 214, .1);
}

.t0 { --tc: var(--t0); }
.t1 { --tc: var(--t1); }
.t2 { --tc: var(--t2); }
.t3 { --tc: var(--t3); }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; margin-top: 22px; }
.segmented { display: inline-flex; flex-wrap: wrap; gap: 2px; max-width: 100%; padding: 3px; border: 1px solid var(--line); border-radius: 10px; }
.segmented button {
  height: 30px;
  padding: 0 12px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 13.5px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, color .15s;
}
.segmented button:hover { color: var(--ink); }
.segmented button[aria-pressed="true"] { background: var(--hover); color: var(--ink); }
.segmented .chosen::after { content: " ✓"; color: var(--ack-ink); }
.hint { color: var(--faint); font-size: 13px; font-family: var(--mono); }

.diagram-card { margin-top: 14px; padding: 8px; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); }
.diagram { display: block; width: 100%; height: auto; overflow: visible; }
.diagram text { font-family: var(--sans); }
.diagram .boundary { fill: var(--inset); stroke: var(--line-strong); stroke-width: 1.3; stroke-dasharray: 7 5; }
.diagram .boundary-name { font-weight: 700; font-size: 14px; fill: var(--muted); }
.diagram .boundary-tech { font-family: var(--mono); font-weight: 400; font-size: 11px; fill: var(--faint); }
.diagram .node { outline: none; transition: opacity .25s; }
.diagram.interactive .node { cursor: pointer; }
.diagram .shape { transition: stroke-width .15s; }
.diagram .container .shape { fill: var(--surface); stroke: var(--accent); stroke-width: 1.6; }
.diagram .external .shape { fill: var(--hover); stroke: var(--line-strong); stroke-width: 1.4; }
.diagram .person .shape, .diagram .store .shape, .diagram .bus .shape { fill: var(--store); stroke: var(--accent); stroke-width: 1.4; }
.diagram.interactive .node:hover .shape { stroke-width: 2.2; }
.diagram .node:focus-visible .shape { stroke: var(--focus); stroke-width: 2.6; }
.diagram .name { font-weight: 600; font-size: 15px; fill: var(--ink); }
.diagram .name.ext { fill: var(--muted); }
.diagram .tech { font-family: var(--mono); font-size: 10.5px; fill: var(--accent-ink); }
.diagram .tech.ext { fill: var(--faint); }
.diagram .desc { font-size: 12.5px; fill: var(--muted); }
.diagram .desc.ext { fill: var(--faint); }
.diagram .db-name { font-weight: 600; font-size: 13.5px; fill: var(--ink); }
.diagram .db-desc { font-size: 11.5px; fill: var(--muted); }
.diagram .module { fill: var(--store); stroke: var(--accent-line); stroke-width: 1.2; }
.diagram .module-name { font-size: 13px; fill: var(--ink); }
.diagram .inner-arrow { fill: none; stroke: var(--faint); stroke-width: 1.4; stroke-dasharray: 3 3; }
.diagram .inner-note { font-size: 11.5px; fill: var(--faint); }
.diagram .line { fill: none; stroke: var(--muted); stroke-width: 1.4; transition: stroke .2s, stroke-width .2s; }
.diagram .async .line { stroke: var(--accent); stroke-dasharray: 6 4; }
.diagram .head.sync { fill: var(--muted); }
.diagram .head.async { fill: var(--accent); }
.diagram .head.inner { fill: var(--faint); }
.diagram .rel { font-size: 11.5px; fill: var(--muted); }
.diagram .rel-tech { font-family: var(--mono); font-size: 10px; fill: var(--faint); }
.diagram .topic { font-family: var(--mono); font-size: 10.5px; fill: var(--accent-ink); }
.diagram .halo { paint-order: stroke; stroke: var(--inset); stroke-width: 4px; stroke-linejoin: round; }
.diagram .halo-out { paint-order: stroke; stroke: var(--surface); stroke-width: 4px; stroke-linejoin: round; }
.diagram .edge, .diagram .edge-label { transition: opacity .25s; }

.diagram.focus .node { opacity: .3; }
.diagram.focus .node.on, .diagram.focus .node.near { opacity: 1; }
.diagram.focus .edge, .diagram.focus .edge-label { opacity: .12; }
.diagram.focus .edge.on, .diagram.focus .edge-label.on { opacity: 1; }
.diagram .node.on .shape { stroke-width: 2.8; }
.diagram[data-filter="sync"] .edge.async, .diagram[data-filter="sync"] .edge-label.async,
.diagram[data-filter="async"] .edge.sync, .diagram[data-filter="async"] .edge-label.sync,
.diagram[data-filter="async"] .edge.store, .diagram[data-filter="async"] .edge-label.store { opacity: .06; }

.diagram.playing .node:not(.live) { opacity: .4; }
.diagram.playing .edge:not(.live), .diagram.playing .edge-label:not(.live) { opacity: .14; }
.diagram .node.live .shape { stroke: var(--tc); stroke-width: 2.6; }
.diagram .edge.live .line { stroke: var(--tc); stroke-width: 2.6; }
.diagram .edge-label.live .rel, .diagram .edge-label.live .topic { fill: var(--ink); }
.diagram .token { fill: var(--tc); stroke: var(--surface); stroke-width: 2.5; pointer-events: none; }

.variant { opacity: 0; pointer-events: none; transition: opacity .35s ease; }
.variant.shown { opacity: 1; pointer-events: auto; }

.details { margin-top: 14px; }
.details-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; }
.details-head h3 { font-size: 18px; }
.details-head code { color: var(--accent-ink); font-size: 13px; }
.details-head .kind { color: var(--faint); font-family: var(--mono); font-size: 12px; }
.details .empty-hint { margin: 0; color: var(--muted); font-size: 14px; }
.facts { display: grid; grid-template-columns: 180px minmax(0, 1fr); gap: 9px 18px; margin: 14px 0 0; }
.facts dt { color: var(--faint); font-size: 13px; }
.facts dd { margin: 0; font-size: 14px; }
.facts ul { display: grid; gap: 3px; margin: 0; padding: 0; list-style: none; }
.facts code { color: var(--ink); font-size: 12.5px; }

.lab-stage { padding: 12px 12px 4px; border-bottom: 1px solid var(--line); }
.caption .who { color: var(--tc); font-weight: 500; }
.caption .how { color: var(--faint); font-family: var(--mono); font-size: 12px; white-space: nowrap; }
.state { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; padding: 0 16px 16px; }
.state-card { min-width: 0; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--inset); }
.state-title { color: var(--faint); font-family: var(--mono); font-size: 11.5px; }
.state-value { margin-top: 4px; font-weight: 600; font-size: 15px; font-variant-numeric: tabular-nums; }
.state-note { color: var(--muted); font-size: 13px; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.chips .empty { color: var(--faint); font-size: 12px; }
.step-chip, .entry-chip, .event-chip, .mail-chip {
  max-width: 100%;
  padding: 1px 8px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  font-size: 12px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}
.entry-chip { font-variant-numeric: tabular-nums; }
.event-chip { border-color: var(--t2); background: var(--t2-soft); font-family: var(--mono); font-size: 11.5px; }
.mail-chip { border-color: var(--t3); background: var(--t3-soft); }
.fresh { animation: pop .45s ease; }

.tradeoffs { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin-top: 14px; }
.tradeoffs h3 { display: flex; align-items: baseline; gap: 8px; font-size: 15px; }
.tradeoffs ul { display: grid; gap: 6px; margin: 10px 0 0; padding-left: 18px; }
.tradeoffs li { color: var(--muted); font-size: 14px; }
.tradeoffs .plus h3 { color: var(--ack-ink); }
.tradeoffs .minus h3 { color: var(--bad-ink); }
.choice { margin: 14px 0 0; color: var(--muted); font-size: 14px; }
.choice b { color: var(--ink); font-weight: 600; }

.health { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); gap: 16px; margin-top: 22px; }
.probe { display: flex; align-items: center; gap: 12px; font-family: var(--mono); font-size: 24px; font-weight: 600; letter-spacing: -.01em; }
.probe .dot { width: 11px; height: 11px; border-radius: 50%; background: var(--faint); flex: none; }
.probe.ok { color: var(--good-ink); }
.probe.ok .dot { background: var(--good); animation: beat 2s ease-out infinite; }
.probe.down { color: var(--bad-ink); }
.probe.down .dot { background: var(--bad); }
@keyframes beat { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--good) 55%, transparent); } 70%, 100% { box-shadow: 0 0 0 10px transparent; } }
.probe-request { margin-top: 10px; color: var(--muted); font-family: var(--mono); font-size: 13px; }
.probe-body { margin-top: 4px; font-family: var(--mono); font-size: 14px; overflow-wrap: anywhere; }
.probe-meta { display: flex; flex-wrap: wrap; gap: 4px 18px; margin-top: 12px; color: var(--faint); font-family: var(--mono); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.spark { display: flex; align-items: flex-end; gap: 3px; height: 44px; margin-top: 16px; }
.spark span { flex: 1; min-width: 3px; min-height: 3px; border-radius: 2px; background: var(--accent-line); }
.spark span.bad { background: var(--bad); }
.spark span.empty { height: 3px; background: var(--line); }
.code-card { padding: 0; overflow: hidden; }
.code-title { display: flex; justify-content: space-between; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--line); color: var(--faint); font-family: var(--mono); font-size: 12.5px; }
.code-title b { color: var(--ink); font-weight: 600; }
.code-card .code { padding: 10px 0 14px; }

@media (max-width: 1060px) {
  .state { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  .state { grid-template-columns: repeat(2, minmax(0, 1fr)); padding: 0 10px 12px; }
  .caption .how { white-space: normal; }
  .tradeoffs, .health { grid-template-columns: minmax(0, 1fr); }
  .facts { grid-template-columns: minmax(0, 1fr); gap: 2px 0; }
  .facts dd { margin-bottom: 10px; }
  .lab-stage { padding: 8px 6px 2px; }
  .diagram-card { padding: 4px; }
}

@media (max-width: 520px) {
  .state { grid-template-columns: minmax(0, 1fr); }
}
