/*
 * age-cities — the mother's age by city (chapter 1). Rows in screen pixels:
 * 10th–90th line, middle-half bar, median dot; share at 30+ on the right.
 * Default ink = var(--cat-emph); the hubs keep it in step "hubs"; Tamil Nadu
 * takes var(--cat-alarm) in step "tn". Everything else steps back to ghost.
 */
.ac { --ac-ink: var(--cat-emph); display: flex; flex-direction: column; height: 100%; color: var(--ink); }
.ac:not(.in-scrolly) { height: 600px; }

.ac-key { display: flex; flex-wrap: wrap; gap: 6px 22px; margin: 0 0 14px; padding: 0; list-style: none; font-family: var(--font-mono); font-size: 11.5px; color: rgba(var(--ink-rgb), .7); }
.ac-key li { display: inline-flex; align-items: center; gap: 8px; }
.ac-key svg { width: 30px; height: 12px; overflow: visible; }
.ac-key .k-line { stroke: var(--ac-ink); stroke-width: 1.6px; stroke-linecap: round; opacity: .55; }
.ac-key .k-bar { fill: var(--ac-ink); opacity: .45; }
.ac-key .k-dot { fill: var(--ac-ink); stroke: var(--bg); stroke-width: 2px; }

.ac-plot { position: relative; flex: 1 1 auto; min-height: 0; }
.ac-plot svg { position: absolute; inset: 0; display: block; overflow: visible; touch-action: pan-y; }

.ac-tick { font-family: var(--font-mono); font-size: 11px; fill: rgba(var(--ink-rgb), .6); }
.ac-tick.thirty { font-weight: 600; fill: var(--ink); }
.ac-tick.col { letter-spacing: .04em; }
.ac-rule { stroke: rgba(var(--ink-rgb), .08); }
.ac-rule.thirty { stroke: rgba(var(--ink-rgb), .35); stroke-dasharray: 3 3; }

.ac-hit { fill: transparent; }
.ac-row { cursor: pointer; }
.ac-row.hover .ac-hit { fill: rgba(var(--ink-rgb), .05); }
.ac-name { font-family: var(--font-sans); font-size: 14px; fill: var(--ink); transition: fill .4s, opacity .4s; }
.ac-row.small .ac-name { fill-opacity: .72; }
.ac-range { stroke: var(--ac-ink); stroke-width: 1.6px; stroke-linecap: round; opacity: .5; transition: stroke .4s, opacity .4s; }
.ac-mid { fill: var(--ac-ink); opacity: .42; transition: fill .4s, opacity .4s; }
.ac-dot { fill: var(--ac-ink); stroke: var(--bg); stroke-width: 2px; transition: fill .4s, opacity .4s; }
.ac-med { font-family: var(--font-mono); font-size: 11.5px; font-weight: 600; fill: var(--ac-ink); opacity: 0; transition: opacity .4s, fill .4s; }
.ac-val { font-family: var(--font-mono); font-size: 14px; font-weight: 500; fill: var(--ink); font-variant-numeric: tabular-nums; transition: fill .4s, opacity .4s; }
.ac-row.hover .ac-med { opacity: 1; }

/* the rows grow out from their medians, top to bottom */
.ac-grow { transform-box: view-box; transition: transform .8s var(--rv-ease) calc(var(--i) * 45ms); }
.ac:not(.shown) .ac-grow { transform: scaleX(0); }
.ac-dot { transition: fill .4s, opacity .4s, r .3s; }

/* steps: one group keeps the ink, the rest step back */
.ac:is([data-state="hubs"], [data-state="tn"]) .ac-row :is(.ac-range, .ac-mid, .ac-dot) { fill: var(--cat-ghost); stroke: var(--cat-ghost); opacity: .35; }
.ac:is([data-state="hubs"], [data-state="tn"]) .ac-row .ac-dot { stroke: var(--bg); opacity: .5; }
.ac:is([data-state="hubs"], [data-state="tn"]) .ac-row :is(.ac-name, .ac-val) { opacity: .45; }
.ac[data-state="hubs"] .ac-row.hub :is(.ac-range, .ac-mid, .ac-dot, .ac-name, .ac-val),
.ac[data-state="tn"] .ac-row.tn :is(.ac-range, .ac-mid, .ac-dot, .ac-name, .ac-val) { opacity: 1; }
.ac[data-state="hubs"] .ac-row.hub .ac-range { stroke: var(--ac-ink); opacity: .6; }
.ac[data-state="hubs"] .ac-row.hub .ac-mid { fill: var(--ac-ink); opacity: .5; }
.ac[data-state="hubs"] .ac-row.hub .ac-dot { fill: var(--ac-ink); }
.ac[data-state="tn"] .ac-row.tn .ac-range { stroke: var(--cat-alarm); opacity: .6; }
.ac[data-state="tn"] .ac-row.tn .ac-mid { fill: var(--cat-alarm); opacity: .5; }
.ac[data-state="tn"] .ac-row.tn .ac-dot { fill: var(--cat-alarm); }
.ac[data-state="tn"] .ac-row.tn :is(.ac-name, .ac-val, .ac-med) { fill: var(--cat-alarm); }
.ac[data-state="hubs"] .ac-row.hub .ac-med, .ac[data-state="tn"] .ac-row.tn .ac-med { opacity: 1; }
.ac[data-state="hubs"] .ac-row.hub .ac-name, .ac[data-state="tn"] .ac-row.tn .ac-name { font-weight: 600; }

.ac-read { flex: none; min-height: 20px; margin: 12px 0 0; font-family: var(--font-mono); font-size: 12px; line-height: 1.5; color: var(--muted); }
.ac-read.on { color: rgba(var(--ink-rgb), .85); }
.ac-read b { font-weight: 600; color: var(--ink); }
.ac-note { flex: none; margin: 6px 0 0; font-family: var(--font-mono); font-size: 11px; color: var(--muted); }

@media (width < 900px) {
  .ac.in-scrolly .ac-key { gap: 4px 14px; font-size: 11px; margin-bottom: 8px; }
  /* the rows end above the reading line, where the step card arrives */
  .ac.in-scrolly .ac-plot { flex: 0 1 auto; height: min(45svh, 372px); }
  .ac.in-scrolly :is(.ac-read, .ac-note) { display: none; }
  .ac-name { font-size: 13px; }
  .ac-val { font-size: 13px; }
}
@container (width < 560px) {
  .ac:not(.in-scrolly) { height: 560px; }
  .ac-name { font-size: 13px; }
}
@media (prefers-reduced-motion: reduce) {
  .ac-grow, .ac-range, .ac-mid, .ac-dot, .ac-name, .ac-val, .ac-med { transition: none; }
}
