/* Chart primitives that sit beside styles/debt.css: grouped and stacked columns, an XY plot with
   numeric axes, unit rows, semantic SVG figures, a dated timeline and calculator controls.
   Monochrome like the rest of the site: series differ by fill, outline, dash and hatch, never by hue.
   Lines are SVG with non-scaling strokes; every label is HTML, so nothing stretches. */

.chart-cols,
.chart-xy,
.chart-units,
.chart-tl,
.chart-calc,
.chart-fig__n {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

.chart-fig__n { font-weight: 700; color: var(--ink); }

/* —— shared fills (bars, columns, unit cells) —— */
.chart-fill--solid { background: var(--ink); }
.chart-fill--soft { background: color-mix(in srgb, var(--ink) 32%, var(--bg)); }
.chart-fill--outline { border: 1px solid var(--ink); background: var(--bg); }
.chart-fill--dash { border: 1px dashed var(--ink); background: var(--bg); }
.chart-fill--hatch {
  border: 1px solid var(--ink);
  background: repeating-linear-gradient(135deg, var(--ink) 0 1px, var(--bg) 1px 5px);
}

/* An amount with a known floor and no published ceiling: dashed, fading out to the right. */
.debt-bars__seg--open {
  border: 1px dashed var(--ink);
  border-right: 0;
  -webkit-mask-image: linear-gradient(90deg, #000 55%, transparent);
  mask-image: linear-gradient(90deg, #000 55%, transparent);
}
.debt-key__seg--open {
  border: 1px dashed var(--ink);
  border-right: 0;
  -webkit-mask-image: linear-gradient(90deg, #000 45%, transparent);
  mask-image: linear-gradient(90deg, #000 45%, transparent);
}

/* —— legend swatches for lines and points (used inside .debt-key) —— */
.chart-key__line,
.chart-key__line--dash,
.chart-key__line--thin,
.chart-key__line--thick {
  width: 22px;
  height: 0;
  border-top: 2px solid var(--ink);
}
.chart-key__line--dash { border-top-style: dashed; }
.chart-key__line--thin { border-top-width: 1px; }
.chart-key__line--thick { border-top-width: 3.5px; }
.chart-key__dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ink); }
.chart-key__ring { width: 8px; height: 8px; border-radius: 50%; border: 1.5px solid var(--ink); }
.chart-key__ringdash { width: 8px; height: 8px; border-radius: 50%; border: 1.5px dashed var(--ink); }
.chart-key__diamond { width: 8px; height: 8px; margin: 0 1px; background: var(--ink); transform: rotate(45deg); }
.chart-key__diamondopen { width: 7px; height: 7px; margin: 0 2px; border: 1.5px solid var(--ink); transform: rotate(45deg); }
.chart-key__band { width: 18px; height: 11px; background: color-mix(in srgb, var(--ink) 9%, var(--bg)); }

/* —— columns: one or more columns per group; a column may stack segments —— */
.chart-cols__unit {
  margin: 0 0 0.35rem;
  font-size: 0.68rem;
  line-height: 1.3;
  color: var(--muted);
}

.chart-cols__plot {
  position: relative;
  height: 12rem;
  margin: 1.5rem 0 0 2.6rem;
  border-bottom: 1px solid var(--ink);
}

.chart-cols__grid {
  position: absolute;
  left: 0;
  right: 0;
  border-top: 1px solid color-mix(in srgb, var(--muted) 22%, transparent);
}

.chart-cols__grid > span {
  position: absolute;
  right: 100%;
  margin-right: 0.45rem;
  transform: translateY(-50%);
  font-size: 0.64rem;
  line-height: 1;
  white-space: nowrap;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.chart-cols__groups,
.chart-cols__x {
  display: grid;
  grid-template-columns: repeat(var(--groups, 4), minmax(0, 1fr));
  margin: 0;
  padding: 0;
  list-style: none;
}

.chart-cols__groups {
  position: absolute;
  inset: 0;
}

.chart-cols__group {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: 0.3rem;
  height: 100%;
  margin: 0;
}

.chart-cols__col {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  width: min(3rem, 27%);
  height: var(--h);
}

.chart-cols__group--one .chart-cols__col { width: min(4.6rem, 52%); }

.chart-cols__seg {
  position: relative;
  display: block;
  flex: 0 0 auto;
  height: var(--h);
  box-sizing: border-box;
}

.chart-cols__seg + .chart-cols__seg { margin-top: 2px; }

.chart-cols__in {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  font-size: 0.68rem;
  font-weight: 600;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  color: var(--bg);
}

.chart-cols__v {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  margin-bottom: 0.2rem;
  padding: 0 0.15rem;
  white-space: nowrap;
  background: var(--bg);
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1.25;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.chart-cols__v small {
  display: block;
  font-size: 0.6rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.chart-cols__ref {
  position: absolute;
  left: 0;
  right: 0;
  border-top: 1.5px dashed var(--ink);
}

.chart-cols__ref > span {
  position: absolute;
  left: 0;
  bottom: 0.2rem;
  padding: 0 0.25rem;
  background: var(--bg);
  font-size: 0.66rem;
  font-weight: 700;
}

.chart-cols__x {
  margin: 0.4rem 0 0 2.6rem;
}

.chart-cols__x > li {
  margin: 0;
  padding: 0 0.15rem;
  font-size: 0.66rem;
  line-height: 1.3;
  text-align: center;
  color: var(--muted);
}

.chart-cols__x strong {
  display: block;
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--ink);
}

/* —— XY plot: numeric axes, SVG lines, HTML points and labels —— */
.chart-xy__y {
  margin: 0 0 0.35rem;
  font-size: 0.68rem;
  line-height: 1.3;
  color: var(--muted);
}

.chart-xy__plot {
  position: relative;
  height: 15rem;
  margin: 0.6rem 0 0 2.6rem;
  border-bottom: 1px solid var(--ink);
  border-left: 1px solid var(--ink);
}

.chart-xy__grid {
  position: absolute;
  left: 0;
  right: 0;
  border-top: 1px solid color-mix(in srgb, var(--muted) 20%, transparent);
}

.chart-xy__grid > span {
  position: absolute;
  right: 100%;
  margin-right: 0.45rem;
  transform: translateY(-50%);
  font-size: 0.64rem;
  line-height: 1;
  white-space: nowrap;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.chart-xy__vgrid {
  position: absolute;
  top: 0;
  bottom: 0;
  border-left: 1px solid color-mix(in srgb, var(--muted) 14%, transparent);
}

.chart-xy__band {
  position: absolute;
  top: 0;
  bottom: 0;
  background: color-mix(in srgb, var(--ink) 7%, transparent);
}

.chart-xy__band > span {
  position: absolute;
  top: 0.3rem;
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  font-size: 0.64rem;
  font-weight: 700;
  color: var(--muted);
}

.chart-xy__svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.chart-xy__line {
  fill: none;
  stroke: var(--ink);
  stroke-width: 2px;
  stroke-linejoin: round;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}

.chart-xy__line--dash { stroke-dasharray: 6 5; }
.chart-xy__line--thin { stroke-width: 1.2px; }
.chart-xy__line--thick { stroke-width: 3.5px; }
.chart-xy__line--muted { stroke: var(--muted); }
.chart-xy__line--arrow { stroke-width: 1.2px; stroke-dasharray: 3 3; }
/* The reader's own scenario in a calculator: a heavy dotted line. */
.chart-xy__line--custom { stroke-width: 4px; stroke-dasharray: 0.1 6; }
.chart-key__custom { width: 22px; height: 0; border-top: 4px dotted var(--ink); }

/* Points sit on their centre: left and bottom are the data position. */
.chart-xy__pt {
  position: absolute;
  width: 9px;
  height: 9px;
  margin: 0 0 0 -4.5px;
  translate: 0 50%;
  box-sizing: border-box;
  border-radius: 50%;
  background: var(--ink);
}

.chart-xy__pt--ring { background: var(--bg); border: 1.5px solid var(--ink); }
.chart-xy__pt--ringdash { background: var(--bg); border: 1.5px dashed var(--ink); }
.chart-xy__pt--diamond { border-radius: 0; transform: rotate(45deg); }
.chart-xy__pt--diamondopen { border-radius: 0; transform: rotate(45deg); background: var(--bg); border: 1.5px solid var(--ink); }
.chart-xy__pt--big { width: 11px; height: 11px; margin-left: -5.5px; }

.chart-xy__lab {
  position: absolute;
  width: max-content;
  max-width: 14rem;
  padding: 0.05rem 0.25rem;
  background: var(--bg);
  font-size: 0.7rem;
  line-height: 1.3;
  /* a label longer than its measure wraps instead of running out of its box (and off the page) */
  white-space: normal;
  text-wrap: balance;
  translate: 0 50%;
}

.chart-xy__lab strong { font-weight: 700; }
.chart-xy__lab--l { translate: -100% 50%; text-align: right; }
.chart-xy__lab--c { translate: -50% 50%; text-align: center; }
.chart-xy__lab--muted { color: var(--muted); }

.chart-xy__x {
  position: relative;
  height: 1.1rem;
  margin: 0.3rem 0 0 2.6rem;
  padding: 0;
  list-style: none;
  font-size: 0.66rem;
  line-height: 1.3;
  color: var(--muted);
}

.chart-xy__x > li {
  position: absolute;
  margin: 0;
  transform: translateX(-50%);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* Ticks at the ends of the axis sit inside it rather than centred on it. */
.chart-xy__x > li.chart-xy__tick--start { transform: none; }
.chart-xy__x > li.chart-xy__tick--end { transform: translateX(-100%); }

.chart-xy__xtitle {
  margin: 0.15rem 0 0;
  font-size: 0.68rem;
  line-height: 1.3;
  text-align: right;
  color: var(--muted);
}

/* —— unit rows: one cell per item, grouped by row —— */
.chart-units {
  margin: 0;
  padding: 0;
  list-style: none;
}

.chart-units__row {
  display: grid;
  grid-template-columns: 11rem minmax(0, 1fr) 9rem;
  gap: 0.3rem 0.9rem;
  align-items: center;
  margin: 0;
  padding: 0.5rem 0;
  border-bottom: 1px solid color-mix(in srgb, var(--muted) 18%, transparent);
}

.chart-units__who strong {
  display: block;
  font-family: "Libre Baskerville", Georgia, serif;
  font-size: 0.92rem;
  font-weight: 400;
  line-height: 1.3;
}

.chart-units__who span,
.chart-units__what {
  display: block;
  font-size: 0.72rem;
  line-height: 1.35;
  color: var(--muted);
}

.chart-units__cells {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
}

.chart-units__cell {
  display: block;
  width: 0.78rem;
  height: 1.55rem;
  box-sizing: border-box;
}

.chart-units__total {
  margin: 0.55rem 0 0;
  font-size: 0.76rem;
  line-height: 1.45;
}

/* —— semantic SVG figures: drawn at a fixed width, scroll on narrow screens —— */
.chart-svg {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.chart-svg svg {
  display: block;
  width: 100%;
  min-width: 36rem;
  height: auto;
  color: var(--ink);
}

.chart-svg .s-ln { fill: none; stroke: currentColor; stroke-width: 1.4; }
.chart-svg .s-thin { fill: none; stroke: currentColor; stroke-width: 0.8; }
.chart-svg .s-dash { stroke-dasharray: 5 4; }
.chart-svg .s-grid { fill: none; stroke: var(--muted); stroke-opacity: 0.35; stroke-width: 0.8; }
.chart-svg .s-ink { fill: currentColor; }
.chart-svg .s-soft { fill: color-mix(in srgb, var(--ink) 32%, var(--bg)); }
.chart-svg .s-ghost { fill: color-mix(in srgb, var(--ink) 8%, var(--bg)); }
.chart-svg .s-bg { fill: var(--bg); }
.chart-svg text { fill: currentColor; font-family: system-ui, -apple-system, "Segoe UI", sans-serif; font-size: 13px; }
.chart-svg .s-muted { fill: var(--muted); }
.chart-svg .s-b { font-weight: 700; }
.chart-svg .s-sm { font-size: 11.5px; }
.chart-svg .s-lg { font-size: 16px; }
.chart-svg .s-onink { fill: var(--bg); }

/* —— dated timeline —— */
.chart-tl {
  position: relative;
  margin: 0;
  padding: 0;
  list-style: none;
}

.chart-tl > li {
  position: relative;
  display: grid;
  grid-template-columns: 6.8rem minmax(0, 1fr);
  gap: 0.2rem 1.4rem;
  margin: 0;
  padding: 0 0 1rem;
}

.chart-tl > li::before {
  content: "";
  position: absolute;
  top: 0.45rem;
  bottom: -0.45rem;
  left: 7.5rem;
  border-left: 1px solid color-mix(in srgb, var(--muted) 40%, transparent);
}

.chart-tl > li:last-child::before { display: none; }

.chart-tl > li::after {
  content: "";
  position: absolute;
  top: 0.32rem;
  left: calc(7.5rem - 4px);
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--ink);
}

.chart-tl time {
  font-size: 0.74rem;
  font-weight: 700;
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
}

.chart-tl > li > div > strong {
  display: block;
  font-family: "Libre Baskerville", Georgia, serif;
  font-size: 0.95rem;
  font-weight: 400;
  line-height: 1.35;
}

.chart-tl > li > div > span {
  display: block;
  font-size: 0.8rem;
  line-height: 1.5;
  color: var(--muted);
}

.chart-tl > li > div > span strong { font-weight: 700; color: var(--ink); }

/* —— calculator controls (range inputs with live outputs) —— */
.chart-calc {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.7rem 1.6rem;
  margin: 1.1rem 0 0;
  padding: 0.9rem 0 0;
  border-top: 1px solid var(--ink);
  font-size: 0.78rem;
}

.chart-calc[hidden] { display: none; }

.chart-calc label {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.2rem 0.6rem;
  align-items: baseline;
  line-height: 1.3;
  color: var(--muted);
}

.chart-calc output {
  font-weight: 700;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.chart-calc input[type="range"] {
  grid-column: 1 / -1;
  width: 100%;
  margin: 0;
  accent-color: var(--ink);
}

.chart-calc select,
.chart-calc button {
  max-width: 100%;
  min-width: 0;
  font: inherit;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--ink);
  border-radius: 0;
  padding: 0.25rem 0.4rem;
}

.chart-calc button { cursor: pointer; }

.chart-calc__wide { grid-column: 1 / -1; }

.chart-calc__out {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  margin: 0.2rem 0 0;
  background: color-mix(in srgb, var(--muted) 30%, transparent);
  border: 1px solid color-mix(in srgb, var(--muted) 30%, transparent);
}

.chart-calc__out > div {
  padding: 0.6rem 0.7rem;
  background: var(--bg);
}

.chart-calc__out strong {
  display: block;
  font-size: 1.25rem;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}

.chart-calc__out span {
  display: block;
  font-size: 0.7rem;
  line-height: 1.35;
  color: var(--muted);
}

/* —— inside article prose ——
   .prose p and .prose ol (0,1,1) outrank the single classes above; restate their spacing inside a figure,
   as styles/debt.css does for its own charts. */
.debt-fig .chart-cols__groups,
.debt-fig .chart-units,
.debt-fig .chart-tl { margin: 0; line-height: 1.4; }
.debt-fig .chart-cols__x { margin: 0.4rem 0 0 2.6rem; line-height: 1.3; }
.debt-fig .chart-xy__x { margin: 0.3rem 0 0 2.6rem; line-height: 1.3; }
.debt-fig .chart-cols__unit,
.debt-fig .chart-xy__y { margin: 0 0 0.35rem; line-height: 1.3; }
.debt-fig .chart-xy__xtitle { margin: 0.15rem 0 0; line-height: 1.3; }
.debt-fig .chart-units__total { margin: 0.55rem 0 0; line-height: 1.45; }

/* —— panels: small multiples stacked inside one figure —— */
.chart-panel + .chart-panel { margin-top: 1.5rem; }

@media (max-width: 640px) {
  .chart-cols__plot { height: 10rem; margin-left: 2.2rem; }
  .chart-cols__x,
  .debt-fig .chart-cols__x { margin-left: 2.2rem; }
  .chart-cols__x > li { font-size: 0.6rem; }
  .chart-cols__x strong { font-size: 0.66rem; }
  .chart-cols__v { font-size: 0.62rem; }
  .chart-cols__in { font-size: 0.58rem; }
  .chart-xy__plot { height: 13rem; margin-left: 2.2rem; }
  .chart-xy__x,
  .debt-fig .chart-xy__x { margin-left: 2.2rem; }
  /* an XY plot keeps a drawing width and scrolls sideways, like the SVG figures and tables */
  .chart-xy { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .chart-xy__in { min-width: 32rem; }
  .chart-xy__lab { font-size: 0.62rem; }
  .chart-units__row { grid-template-columns: minmax(0, 1fr) auto; }
  .chart-units__cells { grid-column: 1 / -1; grid-row: 2; }
  .chart-units__what { text-align: right; }
  .chart-tl > li { grid-template-columns: minmax(0, 1fr); padding-left: 1.2rem; }
  .chart-tl > li::before { left: 0.25rem; }
  .chart-tl > li::after { left: calc(0.25rem - 4px); }
  .chart-calc { grid-template-columns: minmax(0, 1fr); }
  .chart-calc select { grid-column: 1 / -1; width: 100%; }
  .chart-calc__out { grid-template-columns: minmax(0, 1fr); }
}

@media (forced-colors: active) {
  .chart-fill--solid,
  .chart-fill--soft,
  .chart-cols__seg,
  .chart-units__cell { forced-color-adjust: none; }
}

/* —— the same figures inside a presentation slide: one step smaller —— */
.presentation-page .chart-cols__plot { height: min(26svh, 12rem); margin-top: 1.3rem; }
.presentation-page .chart-xy__plot { height: min(34svh, 15.5rem); }
.presentation-page .chart-units__row { padding: 0.3rem 0; }
.presentation-page .chart-units__cell { width: 0.72rem; height: 1.3rem; }
.presentation-page .chart-svg svg { min-width: 0; max-height: min(44svh, 380px); }
.presentation-page .chart-xy__y,
.presentation-page .chart-cols__unit { margin-bottom: 0.2rem; }
.presentation-page .debt-key { margin-top: 0.4rem; }
/* Bars on a slide: tighter rows, so eight rows and a key fit under a two-line title at 1280×800. */
.presentation-page .debt-fig--slide .debt-bars__row { padding: 0.28rem 0; }
.presentation-page .debt-fig--slide .debt-bars__row--scale { padding: 0 0 0.2rem; }

@media (min-width: 641px) {
  .presentation-page .chart-units__row { grid-template-columns: 15rem minmax(0, 1fr) 12rem; }
}
