/*
 * Chart-lab study: hospital type × metro / non-metro × age, four ways (chart-lab/hospital-merge.html).
 *   .hu   idea 1 · unit dots that regroup (hosp-units)       .hb   idea 2 · bump chart (hosp-bump)
 *   .hr   idea 3 · bars joined by ribbons (hosp-ribbons)     .hmx  idea 4 · bubble matrix (hosp-matrix)
 * Type colours come from the hospital chapter's tokens (specialty = --cat-primary, local private = --cat-2, …).
 */

/* ---- the page ------------------------------------------------------------------------------------------------- */
.hmp { --hm-gap: clamp(56px, 9vh, 104px); }
.hmp-top { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; padding: 18px 0; font: 12px var(--font-mono); color: var(--muted); }
.hmp-top a { color: inherit; }
.hmp-head { max-width: 760px; margin: 6vh auto 0; text-align: left; }
.hmp-head .t-kicker { margin: 0 0 12px; }
.hmp-head h1 { font: 400 clamp(36px, 5vw, 58px)/1.05 var(--font-display); letter-spacing: -.03em; margin: 0 0 18px; text-wrap: balance; }
.hmp-head p { font-size: 18px; line-height: 1.55; margin: 0 0 12px; color: rgba(var(--ink-rgb), .86); }
.hmp-head .hmp-data { font: 12px/1.6 var(--font-mono); color: var(--muted); }
.hmp-idea { max-width: 760px; margin: var(--hm-gap) auto 24px; }
.hmp-idea .hmp-n { font: 500 12px var(--font-mono); letter-spacing: .14em; text-transform: uppercase; color: var(--cat-primary); margin: 0 0 8px; }
.hmp-idea h2 { font: 400 clamp(26px, 3vw, 34px)/1.15 var(--font-display); letter-spacing: -.015em; margin: 0 0 10px; }
.hmp-idea p { margin: 0 0 8px; font-size: 16px; line-height: 1.55; color: rgba(var(--ink-rgb), .82); }
.hmp-idea .hmp-from { font: 12px/1.6 var(--font-mono); color: var(--muted); }
.hmp-idea .hmp-from a { color: inherit; }

/* ---- idea 1 · unit dots ---------------------------------------------------------------------------------------- */
.hu { display: flex; flex-direction: column; height: 100%; color: var(--ink); }
.hu-field { position: relative; flex: 1; min-height: 0; }
.hu:not(.in-scrolly) .hu-field { flex: none; aspect-ratio: 16 / 9; margin-top: 10px; }
@container (width <= 640px) { .hu:not(.in-scrolly) .hu-field { aspect-ratio: 4 / 5; } }
.hu-field svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.hu-hud { flex: none; padding-bottom: 8px; }
.hu-key { list-style: none; display: flex; flex-wrap: wrap; gap: 4px 16px; margin: 0 0 8px; padding: 0; font: 12px var(--font-mono); color: var(--ink); }
.hu-key li { display: flex; align-items: center; gap: 6px; transition: opacity .4s; }
.hu-key i { width: 10px; height: 10px; border-radius: 50%; }
.hu[data-state="specialty"] .hu-key li:not(.t0) { opacity: .35; }
.hu-cap { margin: 0; min-height: 2.9em; font: 400 clamp(17px, 1.6vw, 20px)/1.4 var(--font-display); color: var(--ink); max-width: 46ch; }
.hu-dot {
  fill: var(--c);
  transition: transform .95s cubic-bezier(.6, 0, .25, 1) var(--d, 0ms), fill .5s ease var(--d, 0ms), opacity .5s;
  will-change: transform;
}
.hu[data-state="specialty"] .hu-dot:not(.t0) { fill: rgba(var(--ink-rgb), .12); }
.hu-l { font: 12px var(--font-mono); fill: var(--label-ink); opacity: 0; transition: opacity .45s ease; pointer-events: none; }
.hu-l.strong { fill: var(--ink); font-weight: 500; }
.hu-l.small { font-size: 11px; }
.hu-l.spec { fill: var(--cat-primary); font-weight: 600; font-size: 13px; paint-order: stroke; stroke: var(--fig-bg, var(--bg)); stroke-width: 4px; stroke-linejoin: round; }
.hu[data-state="all"] .hu-l.s-all,
.hu[data-state="geo"] .hu-l.s-geo,
.hu[data-state="age"] .hu-l.s-age,
.hu[data-state="specialty"] .hu-l.s-specialty { opacity: 1; transition-delay: .55s; }
@media (prefers-reduced-motion: reduce) { .hu-dot, .hu-l, .hu-key li { transition: none; } }

/* ---- idea 2 · bump chart --------------------------------------------------------------------------------------- */
.hb { position: relative; color: var(--ink); }
.hb svg { display: block; width: 100%; height: auto; overflow: visible; }
.hb-title { font: 500 12px var(--font-mono); letter-spacing: .1em; text-transform: uppercase; fill: var(--ink); }
.hb-band { font: 12px var(--font-mono); fill: var(--label-ink); }
.hb-rail { stroke: rgba(var(--ink-rgb), .1); }
.hb-halo { fill: none; stroke: var(--fig-bg, var(--bg)); stroke-width: 9px; }
.hb-line { fill: none; stroke: var(--c); stroke-width: 3px; stroke-linecap: round; }
.hb-dot { fill: var(--c); stroke: var(--fig-bg, var(--bg)); stroke-width: 2px; cursor: pointer; }
.hb-val { font: 600 12px var(--font-mono); fill: var(--ink); paint-order: stroke; stroke: var(--fig-bg, var(--bg)); stroke-width: 4px; stroke-linejoin: round; pointer-events: none; }
.hb-name { font: 500 13px var(--font-sans); fill: var(--c); }
.hb-type { transition: opacity .25s; }
.hb.has-hot .hb-type:not(.hot) { opacity: .16; }

/* ---- idea 3 · bars joined by ribbons -------------------------------------------------------------------------- */
.hr { position: relative; color: var(--ink); }
.hr svg { display: block; width: 100%; height: auto; overflow: visible; }
.hr-key-t { font: 12px var(--font-mono); fill: var(--ink); }
.hr-band { font: 500 15px var(--font-display); fill: var(--ink); }
.hr-geo { font: 11px var(--font-mono); fill: var(--label-ink); }
.hr-n { font: 11px var(--font-mono); fill: var(--label-ink); }
.hr-seg { cursor: pointer; transition: opacity .25s; }
.hr-rib { opacity: .26; transition: opacity .25s; }
.hr-pct { font: 600 11px var(--font-mono); fill: #fff; pointer-events: none; }
.hr svg.has-hot .hr-seg:not(.hot) { opacity: .25; }
.hr svg.has-hot .hr-rib:not(.hot) { opacity: .06; }
.hr svg.has-hot .hr-rib.hot { opacity: .5; }

/* ---- idea 4 · bubble matrix ------------------------------------------------------------------------------------ */
.hmx { position: relative; color: var(--ink); }
.hmx svg { display: block; width: 100%; height: auto; overflow: visible; }
.hmx-geo { font: 500 12px var(--font-mono); letter-spacing: .1em; text-transform: uppercase; fill: var(--ink); }
.hmx-geo-rule { stroke: rgba(var(--ink-rgb), .25); }
.hmx-head { cursor: pointer; outline: none; }
.hmx-head rect { fill: transparent; transition: fill .2s; }
.hmx-head text { font: 12px var(--font-mono); fill: var(--label-ink); }
.hmx-head:hover rect, .hmx-head:focus-visible rect, .hmx-head.hot rect { fill: rgba(var(--ink-rgb), .06); }
.hmx-head.sorted rect { fill: rgba(var(--ink-rgb), .1); }
.hmx-head.sorted text { fill: var(--ink); font-weight: 600; }
.hmx-band { fill: transparent; }
.hmx-row.hot .hmx-band { fill: rgba(var(--ink-rgb), .035); }
.hmx-name { font: 500 14px var(--font-sans); fill: var(--ink); }
.hmx-all { font: 11px var(--font-mono); fill: var(--label-ink); }
.hmx-cell { cursor: pointer; transition: opacity .2s; }
.hmx-v { font: 600 11px var(--font-mono); fill: var(--ink); paint-order: stroke; stroke: var(--fig-bg, var(--bg)); stroke-width: 3px; stroke-linejoin: round; pointer-events: none; }
.hmx.has-hot .hmx-cell:not(.hot) { opacity: .35; }
.hmx.has-hot .hmx-row.hot .hmx-cell { opacity: 1; }
.hmx-key text { font: 12px var(--font-mono); fill: var(--label-ink); }
.hmx-head text.sm { font-size: 10px; }

/* ---- idea 3 variations: shared ------------------------------------------------------------------------------- */
.hm-chart { position: relative; color: var(--ink); }
.hm-chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.hm-key { list-style: none; display: flex; flex-wrap: wrap; gap: 4px 6px; margin: 0 0 14px; padding: 0; font: 12px var(--font-mono); }
.hm-key li { display: inline-flex; align-items: center; gap: 7px; padding: 4px 9px 4px 7px; border-radius: 999px; cursor: default; outline: none; transition: background-color .2s, opacity .2s; }
.hm-key li i { width: 10px; height: 10px; border-radius: 50%; }
.hm-key li:hover, .hm-key li:focus-visible, .hm-key li.hot { background: rgba(var(--ink-rgb), .07); }
.hm-chart.has-hot .hm-key li:not(.hot) { opacity: .45; }
/* the highlight: everything that is not the pointed type steps back */
.hm-chart [data-key] { transition: opacity .3s; }
.hm-chart.has-hot svg [data-key]:not(.hot) { opacity: .14; }

/* ---- 3a · two rivers ------------------------------------------------------------------------------------------- */
.hv-axis line { stroke: rgba(var(--ink-rgb), .22); stroke-dasharray: 2 4; }
.hv-age { font: 500 12px var(--font-mono); fill: var(--ink); paint-order: stroke; stroke: var(--fig-bg, var(--bg)); stroke-width: 6px; stroke-linejoin: round; }
.hv-river { font: 500 11px var(--font-mono); letter-spacing: .12em; text-transform: uppercase; fill: var(--ink); }
.hv-river-n { font: 11px var(--font-mono); fill: var(--label-ink); }
.hv-rib { cursor: pointer; }
.hv-seg { cursor: pointer; }
.hv-v { font: 600 11px var(--font-mono); fill: #fff; pointer-events: none; }
.hv-n { font: 11px var(--font-mono); fill: var(--label-ink); }
.hv-name { font: 500 12px var(--font-sans); }

/* ---- 3b · morph ------------------------------------------------------------------------------------------------ */
.hmo-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 20px; margin: 0 0 10px; }
.hmo-age { margin: 0; font: 400 clamp(26px, 3.2vw, 38px)/1.05 var(--font-display); letter-spacing: -.02em; }
.hmo-age span { color: var(--label-ink); }
.hmo-n { margin: 0; font: 12px var(--font-mono); color: var(--label-ink); }
.hmo-n span { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }
.hmo-geo { font: 500 11px var(--font-mono); letter-spacing: .12em; text-transform: uppercase; fill: var(--ink); }
.hmo-sl { font: 10.5px var(--font-mono); fill: var(--label-ink); }
.hmo-rib { cursor: pointer; }
.hmo-seg { cursor: pointer; }
.hmo-v { font: 600 17px var(--font-mono); fill: #fff; pointer-events: none; letter-spacing: -.02em; }
.hmo-t { font: 500 10.5px var(--font-mono); fill: rgba(255, 255, 255, .86); pointer-events: none; }
.hmo-row { cursor: pointer; }
.hmo-row-hit { fill: transparent; }
.hmo-row .hmo-mini { opacity: .32; transition: opacity .35s; }
.hmo-row.on .hmo-mini { opacity: 1; }
.hmo-row:hover .hmo-mini { opacity: .7; }
.hmo-row-l { font: 10px var(--font-mono); fill: var(--label-ink); }
.hmo-row.on .hmo-row-l { fill: var(--ink); font-weight: 600; }
.hmo-ctrl { display: flex; align-items: center; gap: 12px; margin-top: 14px; flex-wrap: wrap; }
.hmo-play { width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--ink); color: var(--bg); display: inline-grid; place-items: center; cursor: pointer; grid-auto-flow: column; gap: 4px; }
.hmo-play b { width: 0; height: 0; border-left: 11px solid currentColor; border-top: 7px solid transparent; border-bottom: 7px solid transparent; margin-left: 3px; }
.hmo-play i { width: 4px; height: 13px; background: currentColor; border-radius: 1px; }
.hmo-ages { display: inline-flex; gap: 4px; }
.hmo-ages button { font: 12px var(--font-mono); color: var(--label-ink); background: none; border: 1px solid transparent; border-radius: 999px; padding: 6px 11px; cursor: pointer; }
.hmo-ages button:hover { color: var(--ink); border-color: rgba(var(--ink-rgb), .2); }
.hmo-ages button[aria-pressed="true"] { color: var(--ink); border-color: var(--ink); font-weight: 600; }
.hmo-prog { flex: 1; min-width: 60px; height: 2px; background: rgba(var(--ink-rgb), .1); border-radius: 2px; overflow: hidden; }
.hmo-prog i { display: block; height: 100%; width: 0; background: var(--ink); }
.hmo.playing .hmo-prog i { animation: hmo-prog var(--step, 1.9s) linear infinite; }
@keyframes hmo-prog { from { width: 0; } to { width: 100%; } }
@media (prefers-reduced-motion: reduce) { .hmo.playing .hmo-prog i { animation: none; width: 100%; } }

/* ---- 3c · woven strand ----------------------------------------------------------------------------------------- */
.hw-row { font: 13px var(--font-sans); fill: var(--ink); }
.hw-row .g { font-weight: 600; }
.hw-row.nonmetro .g { font-weight: 400; }
.hw-row .b { font-family: var(--font-mono); font-size: 11.5px; fill: var(--label-ink); }
.hw-note { font: 10.5px var(--font-mono); fill: var(--label-ink); }
.hw-note.place { fill: var(--ink); }
.hw-rib { cursor: pointer; }
.hw-rib.age { opacity: .55; }
.hm-chart.has-hot .hw-rib.age.hot { opacity: 1; }
.hw-seg { cursor: pointer; }
.hw-v { font: 600 11px var(--font-mono); fill: #fff; pointer-events: none; }
.hw-n { font: 11px var(--font-mono); fill: var(--label-ink); }
