/* Amnalith charts.css · seat C · ALIVE.md §7: two charts (retention, follow-up) and two rows of
   numbers. The contrast and reminders charts were removed on 17 Nov 2026 (DAYLIGHT.md §1.4).
   Loaded after screens.css. Every class here starts with "chart" or "stats". Only the tokens of site.css.
   Craft: one hue for marks (--ice-700 on light, --ice-500 on dark); value and category labels in the text
   tokens; a recessive axis; a baseline the bars are anchored to; 4px round ends on the data end only.
   Marks are sized from the values in the markup: each row carries --v (or --d), the chart carries --min and
   --max, so a printed number and its mark can never disagree.
   Motion: start states and arrivals only under .motion, keyed on .is-in (data-reveal="none" on the root).
   Without .motion every chart is complete and still. Only transform, opacity and clip-path move.
   Order: tokens · frame · tooltip · bars · dots · stats · dark ground · motion. */

/* ===== Local tokens (fallbacks for the motion contract of ALIVE.md §2) ================= */
.chart, .stats {
  --ch-ease: var(--ease-out, cubic-bezier(.16, 1, .3, 1));
  --ch-ease-soft: var(--ease, cubic-bezier(.2, .7, .2, 1));
  --ch-hover: var(--t-hover, 180ms);
  --ch-reveal: var(--t-reveal, 800ms);
  --ch-stagger: var(--stagger, 70ms);
  /* colours (light) */
  --ch-name: var(--ink-700);
  --ch-value: var(--ink-900);
  --ch-muted: var(--ink-600);
  --ch-mark: var(--ice-700);
  --ch-track: var(--line);
  --ch-base: var(--ink-600);
  --ch-top: var(--line-strong);
  --ch-rule: var(--line);
  --ch-hollow: var(--white);
  --ch-tip-bg: var(--ox-900);
  --ch-tip-c: var(--white);
  --ch-focus: var(--ice-700);
}

/* ===== Frame: "Fig. 01" and the title on a strong rule, the plot, a hairline, the caption ===== */
.chart { container: chart / inline-size; display: block; width: 100%; min-width: 0; margin: 0; padding: 0;
  border-top: 1px solid var(--ch-top); color: var(--ch-name); font-family: var(--font); font-variant-numeric: tabular-nums; text-align: left; }
:where(.chart, .stats) :where(p, ol, ul, li, dl, dt, dd, figcaption) { margin: 0; padding: 0; }
:where(.chart, .stats) :where(ol, ul) { list-style: none; }
.chart__cap { display: block; padding-top: 16px; }
.chart__title { display: block; min-width: 0; font-size: .78125rem; font-weight: 600; letter-spacing: .16em; line-height: 1.45;
  text-transform: uppercase; color: var(--ch-muted); text-wrap: balance; }
.chart__body { position: relative; padding-block: 32px 28px; border-bottom: 1px solid var(--ch-rule); }
.chart__src { padding-top: 12px; max-width: 46em; font-size: .9375rem; line-height: 1.5; color: var(--ch-muted); text-wrap: pretty; }

/* a focusable mark or row: the focus ring of the site */
.chart [tabindex] { outline: none; }
.chart [tabindex]:focus-visible { outline: 2px solid var(--ch-focus); outline-offset: 3px; border-radius: 0; }

/* ===== Tooltip (CSS only, shown on hover and on keyboard focus of its row) ============== */
.chart__tip { position: absolute; z-index: 3; bottom: calc(100% + 8px); left: calc(var(--p, 0) * 100%);
  transform: translate(calc(var(--p, 0) * -100%), 4px); padding: 5px 8px; border-radius: 4px;
  background: var(--ch-tip-bg); color: var(--ch-tip-c); font-family: var(--mono); font-size: 12px; font-weight: 500; line-height: 1.2;
  white-space: nowrap; pointer-events: none; opacity: 0;
  transition: opacity var(--ch-hover) var(--ch-ease-soft), transform var(--ch-hover) var(--ch-ease-soft); }

/* ===== Bars (chart-retention): a dl, one focusable row per bar ============
   Wide: name | track | value on one line. Under 560px of chart: name and value, then the track. */
.chart-bars { --name-w: 15.5rem; --val-w: 3.5rem; --gap: 20px; }
.chart-bars__grid, .chart-bars__row { display: grid; grid-template-columns: minmax(0, var(--name-w)) minmax(0, 1fr) var(--val-w);
  column-gap: var(--gap); align-items: center; }
.chart-bars__row { position: relative; padding-block: 10px; cursor: default; }
.chart-bars__row > dt { grid-column: 1; grid-row: 1; min-width: 0; font-size: 15px; line-height: 1.35; color: var(--ch-name); }
/* the dd holds the track and the value on the row's own columns */
.chart-bars__row > dd { grid-column: 2 / 4; grid-row: 1; display: grid; grid-template-columns: subgrid; align-items: center; min-width: 0; }
.chart-bars__val { grid-column: 2; grid-row: 1; justify-self: end; font-family: var(--mono); font-size: 14px; font-weight: 500; line-height: 1.35;
  color: var(--ch-value); white-space: nowrap; text-align: right; }
.chart-bars__row { --p: calc((var(--v) - var(--min)) / (var(--max) - var(--min))); }
.chart-bars__track { grid-column: 1; grid-row: 1; position: relative; height: 14px; background: var(--ch-track); }
.chart-bars__bar { position: absolute; left: 0; top: 0; bottom: 0; width: calc(var(--p) * 100%); background: var(--ch-mark);
  border-radius: 0 4px 4px 0; transition: opacity var(--ch-hover) var(--ch-ease-soft); }
/* the baseline: one ink line at the scale's start, drawn row by row so it runs unbroken down the plot */
.chart-bars__track::before { content: ""; position: absolute; z-index: 2; left: 0; width: 1px; top: -10px; bottom: -10px; background: var(--ch-base); }
/* the axis under the plot: ticks and their numbers, recessive */
.chart-bars__axis { grid-column: 2; position: relative; height: 26px; }
.chart-bars__axis::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 1px; background: var(--ch-track); }
.chart-bars__tick { position: absolute; top: 0; left: calc((var(--t) - var(--min)) / (var(--max) - var(--min)) * 100%);
  --q: calc((var(--t) - var(--min)) / (var(--max) - var(--min)));
  transform: translateX(calc(var(--q) * -100%)); padding-top: 8px; font-family: var(--mono); font-size: 12px; line-height: 1;
  color: var(--ch-muted); white-space: nowrap; }
.chart-bars__tick::before { content: ""; position: absolute; top: 0; left: calc(var(--q) * 100%); width: 1px; height: 5px; background: var(--ch-base); }
.chart-bars__unit { grid-column: 3; justify-self: end; align-self: start; padding-top: 8px; font-family: var(--mono); font-size: 12px; line-height: 1; color: var(--ch-muted); }
/* hover and focus: the other bars step back, this one stays full, its value shows in the tooltip */
.chart-bars__rows:has(.chart-bars__row:is(:hover, :focus-visible)) .chart-bars__row:not(:hover, :focus-visible) .chart-bars__bar { opacity: .32; }
.chart-bars__row:is(:hover, :focus-visible) > dt { color: var(--ch-value); }

.chart-bars__row:is(:hover, :focus-visible) .chart__tip { opacity: 1; transform: translate(calc(var(--p, 0) * -100%), 0); }

@container chart (max-width: 559px) {
  .chart-bars__grid, .chart-bars__row { grid-template-columns: minmax(0, 1fr) auto; column-gap: 16px; }
  .chart-bars__row { grid-template-rows: auto auto; row-gap: 8px; padding-block: 10px 12px; }
  .chart-bars__row > dd { grid-column: 1 / 3; grid-row: 1 / 3; grid-template-rows: subgrid; }
  .chart-bars__val { grid-column: 2; grid-row: 1; }
  .chart-bars__track { grid-column: 1 / 3; grid-row: 2; }
  .chart-bars__track::before { top: -4px; bottom: -4px; }
  .chart-bars__axis { grid-column: 1 / -1; }
  .chart-bars__unit { grid-column: 1 / -1; justify-self: end; padding-top: 0; margin-top: -2px; }
}
/* long value labels (chart-retention) need the stacked form sooner */
@container chart (max-width: 759px) {
  .chart-bars--long :is(.chart-bars__grid, .chart-bars__row) { grid-template-columns: minmax(0, 1fr) auto; column-gap: 16px; }
  .chart-bars--long .chart-bars__row { grid-template-rows: auto auto; row-gap: 8px; padding-block: 10px 12px; }
  .chart-bars--long .chart-bars__row > dd { grid-column: 1 / 3; grid-row: 1 / 3; grid-template-rows: subgrid; }
  .chart-bars--long .chart-bars__val { grid-column: 2; grid-row: 1; }
  .chart-bars--long .chart-bars__track { grid-column: 1 / 3; grid-row: 2; }
  .chart-bars--long .chart-bars__track::before { top: -4px; bottom: -4px; }
  .chart-bars--long .chart-bars__axis { grid-column: 1 / -1; }
  .chart-bars--long .chart-bars__unit { grid-column: 1 / -1; justify-self: end; padding-top: 0; margin-top: -2px; }
}

/* ===== Dots (chart-followup): days placed to scale, a filled dot where a package gets a look ===== */
.chart-dots { --name-w: 7rem; --dot: 14px; }
.chart-dots__grid, .chart-dots__row { display: grid; grid-template-columns: minmax(0, var(--name-w)) minmax(0, 1fr); column-gap: 24px; align-items: center; }
.chart-dots__row { padding-block: 12px; cursor: default; }
.chart-dots__row + .chart-dots__row { border-top: 1px solid var(--ch-rule); }
.chart-dots__row > dt { font-size: 15px; font-weight: 600; line-height: 1.35; color: var(--ch-value); }
.chart-dots__lane { position: relative; height: 28px; margin-inline: calc(var(--dot) / 2); }
/* the lane: a hairline across the whole period, and in ice the stretch from day 0 to the last look */
.chart-dots__lane::before { content: ""; position: absolute; left: 0; right: 0; top: 50%; height: 1px; background: var(--ch-track); }
.chart-dots__span { position: absolute; left: 0; top: calc(50% - 1px); height: 2px; width: calc(var(--last) / var(--max) * 100%); background: var(--ch-mark); }
/* a dot is a small inline SVG circle, so no CSS radius is needed */
.chart-dots__dot { position: absolute; top: 50%; left: calc(var(--d) / var(--max) * 100%); width: var(--dot); height: var(--dot);
  margin: calc(var(--dot) / -2) 0 0 calc(var(--dot) / -2); }
.chart-dots__dot svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart-dots__dot circle { fill: var(--ch-hollow); stroke: var(--line-strong); stroke-width: 1.5; }
.chart-dots__dot--on circle { fill: var(--ch-mark); stroke: var(--ch-mark); }
/* one tooltip per row, at its last filled dot, listing that row's days (the same words as the axis) */
.chart-dots__lane > .chart__tip { --p: calc(var(--last) / var(--max)); bottom: calc(50% + 13px); }
.chart-dots__row:is(:hover, :focus-visible) .chart__tip { opacity: 1; transform: translate(calc(var(--p, 0) * -100%), 0); }
.chart-dots__rows:has(.chart-dots__row:is(:hover, :focus-visible)) .chart-dots__row:not(:hover, :focus-visible) :is(.chart-dots__dot--on, .chart-dots__span) { opacity: .32; }
.chart-dots__dot, .chart-dots__span { transition: opacity var(--ch-hover) var(--ch-ease-soft); }
.chart-dots__axis { grid-column: 2; position: relative; height: 34px; margin-inline: calc(var(--dot) / 2); border-top: 1px solid var(--ch-rule); }
/* each label sits on one side of its tick (--a: 0 = to the right of it, 1 = to the left): "Day 0" to the left
   (under the empty name column), "Day 7" to the right, "Day 30" to the left. The tick stays exactly on its day,
   so the scale is honest, and "Day 0" and "Day 7" are always at least 7/30 of the lane plus 12px apart. */
.chart-dots__tick { position: absolute; top: 0; left: calc(var(--d) / var(--max) * 100%); padding-top: 10px;
  padding-left: calc((1 - var(--a, 0)) * 6px); padding-right: calc(var(--a, 0) * 6px);
  transform: translateX(calc(var(--a, 0) * -100%)); font-family: var(--mono); font-size: 12px; line-height: 1; color: var(--ch-muted); white-space: nowrap; }
.chart-dots__tick::before { content: ""; position: absolute; top: 0; left: calc(var(--a, 0) * 100% - var(--a, 0) * 1px); width: 1px; height: 6px; background: var(--ch-base); }
@container chart (max-width: 419px) { .chart-dots { --name-w: 5.25rem; } .chart-dots__grid, .chart-dots__row { column-gap: 16px; } }

/* ===== Stats: a row of four big numbers, an icon above each, one line under it ============ */
.stats { --st-num: var(--ink-900); --st-line: var(--ink-700); --st-rule: var(--line); --st-top: var(--line-strong);
  container: stats / inline-size; display: block; width: 100%; min-width: 0; margin: 0; }
.stats__list { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border-top: 1px solid var(--st-top); }
.stats__item { min-width: 0; padding: 32px 28px 8px; border-left: 1px solid var(--st-rule); }
.stats__item:first-child { padding-left: 0; border-left: 0; }
.stats__item:last-child { padding-right: 0; }
.stats__ico { display: block; margin-bottom: 20px; }
.stats__num { display: block; font-family: var(--serif); font-size: clamp(3.5rem, 5vw + 1rem, 6rem); font-weight: 400; font-synthesis: none;
  letter-spacing: -0.02em; line-height: 1; color: var(--st-num); font-variant-numeric: lining-nums tabular-nums; }
.stats__line { margin-top: 14px; max-width: 17em; font-size: 1.0625rem; line-height: 1.5; color: var(--st-line); text-wrap: pretty; }
@container stats (max-width: 799px) {
  .stats__list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stats__item { padding: 28px 20px 28px; }
  .stats__item:nth-child(odd) { padding-left: 0; border-left: 0; }
  .stats__item:nth-child(even) { padding-right: 0; }
  .stats__item:nth-child(n + 3) { border-top: 1px solid var(--st-rule); }
  .stats__line { font-size: 1rem; }
}
@container stats (max-width: 339px) {
  .stats__item { padding-inline: 14px; }
  .stats__ico { margin-bottom: 14px; }
  .stats__line { font-size: .9375rem; }
}

/* ===== Dark ground (an .on-dark ancestor) ================================================= */
.on-dark :is(.chart, .stats), :is(.chart, .stats).on-dark {
  --ch-name: var(--on-dark-body); --ch-value: var(--white); --ch-muted: var(--on-dark-muted);
  --ch-mark: var(--ice-500); --ch-track: var(--line-on-dark); --ch-base: var(--on-dark-muted);
  --ch-top: var(--ox-700); --ch-rule: var(--line-on-dark); --ch-hollow: var(--ox-900);
  --ch-tip-bg: var(--white); --ch-tip-c: var(--ink-900); --ch-focus: var(--ice-500);
  --st-num: var(--white); --st-line: var(--on-dark-body); --st-rule: var(--line-on-dark); --st-top: var(--ox-700);
}
.on-dark .chart-dots__dot:not(.chart-dots__dot--on) circle { stroke: var(--on-dark-muted); }

/* ===== Motion: arrivals under .motion, keyed on .is-in; never without [data-reveal] ======== */
@media (prefers-reduced-motion: no-preference) {
  /* frame: the strong rule draws across, the title fades */
  .motion .chart[data-reveal] { border-top-color: transparent; position: relative; }
  .motion .chart[data-reveal]::before { content: ""; position: absolute; left: 0; right: 0; top: -1px; height: 1px; background: var(--ch-top);
    transform-origin: 0 50%; transition: transform 900ms var(--ch-ease); }
  .motion .chart[data-reveal]:not(.is-in)::before { transform: scaleX(0); }
  .motion .chart[data-reveal] :is(.chart__cap, .chart__src) { transition: opacity var(--ch-reveal) var(--ch-ease-soft), transform var(--ch-reveal) var(--ch-ease); }
  .motion .chart[data-reveal]:not(.is-in) :is(.chart__cap, .chart__src) { opacity: 0; transform: translateY(8px); }
  .motion .chart[data-reveal] .chart__src { transition-delay: 600ms; }

  /* bars: the axis first, then each bar grows from the baseline (700ms, 80ms apart), its value after it */
  .motion .chart[data-reveal] :is(.chart-bars__axis, .chart-bars__unit) { transition: opacity 500ms var(--ch-ease-soft) 100ms; }
  .motion .chart[data-reveal]:not(.is-in) :is(.chart-bars__axis, .chart-bars__unit) { opacity: 0; }
  .motion .chart[data-reveal] .chart-bars__track::before { transform-origin: 50% 0; transition: transform 500ms var(--ch-ease) calc(var(--i, 0) * 40ms); }
  .motion .chart[data-reveal]:not(.is-in) .chart-bars__track::before { transform: scaleY(0); }
  .motion .chart[data-reveal] .chart-bars__bar { clip-path: inset(0 0 0 0); transition: clip-path 700ms var(--ch-ease) calc(300ms + var(--i, 0) * 80ms), opacity var(--ch-hover) var(--ch-ease-soft); }
  .motion .chart[data-reveal]:not(.is-in) .chart-bars__bar { clip-path: inset(0 100% 0 0); }
  .motion .chart[data-reveal] .chart-bars__row > dt { transition: opacity 500ms var(--ch-ease-soft) calc(var(--i, 0) * 80ms + 200ms), transform 500ms var(--ch-ease) calc(var(--i, 0) * 80ms + 200ms); }
  .motion .chart[data-reveal] .chart-bars__val { transition: opacity 500ms var(--ch-ease-soft) calc(700ms + var(--i, 0) * 80ms), transform 500ms var(--ch-ease) calc(700ms + var(--i, 0) * 80ms); }
  .motion .chart[data-reveal]:not(.is-in) :is(.chart-bars__val, .chart-bars__row > dt) { opacity: 0; transform: translateY(6px); }

  /* dots: the lanes appear, the ice stretch draws, the dots land in order */
  .motion .chart[data-reveal] .chart-dots__row > dt { transition: opacity 500ms var(--ch-ease-soft) calc(var(--i, 0) * 120ms), transform 500ms var(--ch-ease) calc(var(--i, 0) * 120ms); }
  .motion .chart[data-reveal]:not(.is-in) .chart-dots__row > dt { opacity: 0; transform: translateY(6px); }
  .motion .chart[data-reveal] .chart-dots__lane::before { transform-origin: 0 50%; transition: transform 700ms var(--ch-ease) calc(100ms + var(--i, 0) * 120ms); }
  .motion .chart[data-reveal]:not(.is-in) .chart-dots__lane::before { transform: scaleX(0); }
  .motion .chart[data-reveal] .chart-dots__span { transform-origin: 0 50%; transition: transform 900ms var(--ch-ease) calc(400ms + var(--i, 0) * 120ms), opacity var(--ch-hover) var(--ch-ease-soft); }
  .motion .chart[data-reveal]:not(.is-in) .chart-dots__span { transform: scaleX(0); }
  .motion .chart[data-reveal] .chart-dots__dot { transition: transform 420ms var(--ch-ease) calc(300ms + (var(--i, 0) * 3 + var(--k, 0)) * 90ms),
    opacity 420ms var(--ch-ease-soft) calc(300ms + (var(--i, 0) * 3 + var(--k, 0)) * 90ms); }
  .motion .chart[data-reveal]:not(.is-in) .chart-dots__dot { opacity: 0; transform: scale(.4); }
  .motion .chart[data-reveal] .chart-dots__axis { transition: opacity 500ms var(--ch-ease-soft) 100ms; }
  .motion .chart[data-reveal]:not(.is-in) .chart-dots__axis { opacity: 0; }


  /* stats: the four items rise one after another; the icons draw (icons.css), the numbers count (site.js) */
  .motion .stats[data-reveal] .stats__item { transition: opacity var(--ch-reveal) var(--ch-ease-soft) calc(var(--i, 0) * var(--ch-stagger) * 1.6),
    transform var(--ch-reveal) var(--ch-ease) calc(var(--i, 0) * var(--ch-stagger) * 1.6); }
  .motion .stats[data-reveal]:not(.is-in) .stats__item { opacity: 0; transform: translateY(20px); }
  .motion .stats[data-reveal] .stats__list { position: relative; border-top-color: transparent; }
  .motion .stats[data-reveal] .stats__list::before { content: ""; position: absolute; left: 0; right: 0; top: -1px; height: 1px; background: var(--st-top);
    transform-origin: 0 50%; transition: transform 900ms var(--ch-ease); }
  .motion .stats[data-reveal]:not(.is-in) .stats__list::before { transform: scaleX(0); }
}
