/* Charts (drawn on the server as HTML and SVG, src/server/charts.mjs) and Mermaid diagrams (static/diagrams.js)
   inside an article. Loaded only on pages that have one. */
.chart, .diagram, .prose .chart, .prose .diagram {
  --card: #121212;
  --c: var(--s1);
  margin: 2em 0;
  padding: 22px 24px 18px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  font-family: var(--sans);
}
/* One series wears the magazine's accent; several take a colour-blind safe set, always in this order. */
.chart { --s1: var(--accent); }
.chart.is-multi, .chart.chart-pie {
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
}
.chart .s1 { --c: var(--s1); } .chart .s2 { --c: var(--s2); } .chart .s3 { --c: var(--s3); } .chart .s4 { --c: var(--s4); }
.chart .s5 { --c: var(--s5); } .chart .s6 { --c: var(--s6); } .chart .s7 { --c: var(--s7); } .chart .s8 { --c: var(--s8); }

.chart-head { display: flex; flex-direction: column; gap: 4px; }
.chart-title { font: 600 19px/1.3 var(--sans); color: var(--fg); }
.chart-desc { font-size: 14px; line-height: 1.45; color: var(--muted); }
.chart .chart-foot { margin: 18px 0 0; font-size: 13px; line-height: 1.45; color: var(--muted); }

.chart .chart-legend { display: flex; flex-wrap: wrap; gap: 6px 18px; margin: 14px 0 0; padding: 0; list-style: none; font-size: 13px; color: var(--soft); }
.chart-legend li { display: flex; align-items: center; gap: 7px; }
.chart-legend i, .chart-tip i { width: 10px; height: 10px; border-radius: 3px; background: var(--c); flex: none; }

/* The value of a mark, and the tip that shows on hover or focus. Text never wears the series colour. */
.chart-v { position: absolute; font: 600 13px/1 var(--sans); color: var(--fg); white-space: nowrap; font-variant-numeric: tabular-nums; pointer-events: none; }
.chart-tip {
  position: absolute; z-index: 3; bottom: calc(100% + 10px); left: 50%;
  display: flex; flex-direction: column; gap: 3px;
  padding: 8px 11px; border-radius: 8px;
  background: var(--fg); color: #0b0b0b; box-shadow: 0 6px 24px rgb(0 0 0 / 0.45);
  font: 13px/1.3 var(--sans); white-space: nowrap; font-variant-numeric: tabular-nums;
  opacity: 0; transform: translate(-50%, 4px); transition: opacity 0.12s, transform 0.12s; pointer-events: none;
}
.chart-tip b { font-weight: 600; }
.chart-tip span { display: flex; align-items: center; gap: 6px; }
.chart-bar:hover > .chart-tip, .chart-bar:focus-visible > .chart-tip,
.chart-dot:hover > .chart-tip, .chart-dot:focus-visible > .chart-tip { opacity: 1; transform: translate(-50%, 0); }
.chart-bar:has(> .chart-v) > .chart-tip, .chart-dot:has(> .chart-v) > .chart-tip { bottom: calc(100% + 30px); }
.chart-bar, .chart-dot { outline: none; cursor: default; }
.chart-bar:focus-visible, .chart-dot:focus-visible { box-shadow: 0 0 0 2px var(--card), 0 0 0 4px var(--fg); }

/* ---------- columns and lines: value axis on the left, labels under the plot ---------- */
.chart-frame { margin-top: 18px; font-size: 12px; }
.chart-plot { position: relative; height: 260px; margin: 34px 0 0 var(--axis); }
.chart-grid span { position: absolute; left: 0; right: 0; border-top: 1px solid var(--line); }
.chart-grid em { position: absolute; right: 100%; top: 0; margin-right: 10px; transform: translateY(-50%); font: 12px/1 var(--sans); font-style: normal; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.chart-zero { position: absolute; left: 0; right: 0; border-top: 1px solid var(--line-strong); }
.chart-cols { position: absolute; inset: 0; display: flex; }
.chart-col { flex: 1; display: flex; justify-content: center; gap: 2px; padding: 0 6%; min-width: 0; }
.chart-slot { position: relative; flex: 0 1 72px; min-width: 4px; }
.is-grouped .chart-slot { flex-basis: 30px; }
.chart-columns .chart-bar { position: absolute; left: 0; right: 0; background: var(--c); border-radius: 5px 5px 0 0; transition: opacity 0.15s, filter 0.15s; }
.chart-columns .chart-bar.is-neg { border-radius: 0 0 5px 5px; }
.chart-columns .chart-bar .chart-v { bottom: 100%; left: 50%; transform: translateX(-50%); margin-bottom: 7px; }
.chart-columns .chart-bar.is-neg .chart-v { bottom: auto; top: 100%; margin: 7px 0 0; }
.chart-columns .chart-bar.is-neg .chart-tip { bottom: auto; top: calc(100% + 10px); }
/* Stacked segments are told apart by a thin gap in the card's colour, the top one keeps the rounded end. */
.chart-slot.is-stacked .chart-bar { border-radius: 0; box-shadow: inset 0 -2px 0 var(--card); }
.chart-slot.is-stacked .chart-bar:first-child { box-shadow: none; }
.chart-slot.is-stacked .chart-bar:last-child { border-radius: 5px 5px 0 0; }
.chart-cols:hover .chart-bar:not(:hover) { opacity: 0.55; }
.chart-bar:hover { filter: brightness(1.12); }

.chart-x { display: flex; margin: 10px 0 0 var(--axis); color: var(--muted); font-size: 13px; line-height: 1.25; }
.chart-x span { flex: 1; min-width: 0; padding: 0 2px; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chart-x.is-long span { white-space: normal; overflow-wrap: anywhere; font-size: 12px; }

.chart-lines svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.chart-line { fill: none; stroke: var(--c); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.chart-fill { fill: var(--c); opacity: 0.14; stroke: none; }
.chart-dot { position: absolute; width: 10px; height: 10px; border-radius: 50%; background: var(--c); box-shadow: 0 0 0 2px var(--card); transform: translate(-50%, 50%); }
.chart-dot::before { content: ""; position: absolute; inset: -9px; border-radius: 50%; }
.chart-dot.is-quiet { opacity: 0; }
.chart-dot.is-quiet:hover, .chart-dot.is-quiet:focus-visible { opacity: 1; }
.chart-dot .chart-v { bottom: 100%; left: 50%; transform: translateX(-50%); margin-bottom: 9px; }

/* ---------- bars that go sideways: a row per label, values at the tips ---------- */
.chart-rows { display: grid; grid-template-columns: minmax(0, max-content) minmax(0, 1fr); gap: 12px 16px; margin-top: 20px; align-items: center; }
.chart-row { display: contents; }
.chart-label { max-width: 15em; font-size: 14px; line-height: 1.3; color: var(--text); overflow-wrap: anywhere; }
.chart-tracks { display: flex; flex-direction: column; gap: 3px; padding-right: 4.8em; }
.chart-track { position: relative; height: 26px; }
.is-grouped .chart-track { height: 14px; }
.chart-track .chart-bar { position: absolute; top: 0; bottom: 0; background: var(--c); border-radius: 0 5px 5px 0; transition: opacity 0.15s, filter 0.15s; }
.chart-track .chart-bar.is-neg { border-radius: 5px 0 0 5px; }
.chart-track.is-stacked .chart-bar { border-radius: 0; box-shadow: inset 2px 0 0 var(--card); }
.chart-track.is-stacked .chart-bar:first-child { box-shadow: none; }
.chart-track.is-stacked .chart-bar:last-of-type { border-radius: 0 5px 5px 0; }
.chart-track .chart-v { top: 50%; transform: translateY(-50%); margin-left: 9px; }
.chart-track .chart-v.is-neg { transform: translate(calc(-100% - 18px), -50%); }
.chart-rows:hover .chart-bar:not(:hover) { opacity: 0.55; }
.is-grouped .chart-track .chart-v { font-size: 12px; }

/* ---------- a ring of shares ---------- */
.chart .chart-pie { display: flex; flex-wrap: wrap; align-items: center; gap: 24px 36px; margin-top: 20px; }
.chart-pie svg { width: 210px; height: 210px; flex: none; }
.chart-pie circle { fill: none; stroke: var(--c); stroke-width: 6.5; transition: stroke-width 0.15s; }
.chart-pie circle:hover { stroke-width: 7.6; }
.chart-pie-total { font: 600 5px var(--sans); fill: var(--fg); text-anchor: middle; }
.chart-pie-sub { font: 2.6px var(--sans); fill: var(--muted); text-anchor: middle; }
.chart .chart-pie-legend { flex: 1 1 240px; margin: 0; padding: 0; list-style: none; font-size: 14px; }
.chart-pie-legend li { display: grid; grid-template-columns: 10px minmax(0, 1fr) auto auto; gap: 12px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.chart-pie-legend li:last-child { border-bottom: 0; }
.chart-pie-legend i { width: 10px; height: 10px; border-radius: 3px; background: var(--c); }
.chart-pie-legend span { color: var(--text); }
.chart-pie-legend b { color: var(--fg); font-weight: 600; font-variant-numeric: tabular-nums; }
.chart-pie-legend em { min-width: 3.4em; text-align: right; font-style: normal; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------- the data under a chart, folded ---------- */
.chart-data { margin-top: 14px; font-size: 13px; }
.chart-data summary { width: max-content; color: var(--muted); cursor: pointer; }
.chart-data summary:hover { color: var(--fg); }
.chart-table { margin-top: 10px; overflow-x: auto; }
.prose .chart-table table { display: table; margin: 0; font-size: 14px; border-top: 1px solid var(--line-strong); }
.prose .chart-table td:not(:first-child), .prose .chart-table th:not(:first-child) { text-align: right; padding-left: 16px; }
.prose .chart-table th:last-child, .prose .chart-table td:last-child { padding-right: 0; }

/* ---------- Mermaid diagrams ---------- */
.diagram { padding: 24px; overflow-x: auto; text-align: center; }
.diagram svg { display: block; max-width: 100%; height: auto; margin: 0 auto; }
.diagram .node rect, .diagram rect.actor, .diagram .cluster rect { rx: 8px; ry: 8px; }
.diagram svg [filter] { filter: none !important; }
.prose .diagram-src { margin: 0; border: 0; border-radius: 0; padding: 0; background: none; text-align: left; color: var(--muted); font: 13px/1.45 var(--mono); white-space: pre; }
.diagram.is-drawn .diagram-src { display: none; }

@media (max-width: 640px) {
  .prose .chart, .prose .diagram { margin-left: calc(var(--gutter) * -0.5); margin-right: calc(var(--gutter) * -0.5); padding: 18px 16px 14px; border-radius: 12px; }
  .chart-title { font-size: 17px; }
  .chart-plot { height: 210px; }
  .chart-col { padding: 0 4%; }
  .chart-v { font-size: 12px; }
  .chart-label { max-width: 9em; font-size: 13px; }
  .chart-tracks { padding-right: 4.2em; }
  .chart-pie svg { width: 170px; height: 170px; margin: 0 auto; }
  .diagram { padding: 16px 12px; }
}
@media (prefers-reduced-motion: reduce) {
  .chart-tip, .chart-bar, .chart-pie circle { transition: none; }
}
