/*
 * Five hospitals, one plot (chapter 2, charts/hosp-parcel.js). The scene is
 * drawn with the anatomy kit (its CSS: hosp-parcel-iso.css). Colour is used
 * sparingly, in the chapter's own palette: the drawing is paper and plum ink,
 * the chapter's coral marks signs and kerbs, its lilac the trees and glass, and
 * each hospital keeps one mark in its type colour (the same colours as the age
 * ribbon below): its name board and the delivery bed. The dark theme is the
 * same street at night, with lit windows.
 */
m-scrolly[chart="hosp-parcel"], .hpx {
  --k-maternity_specialty: var(--cat-primary);
  --k-single_location: var(--cat-2);
  --k-multichain: var(--cat-3);
  --k-nursing_home: var(--cat-4);
  --k-mission_trust: var(--cat-5);
  --room-labour: color-mix(in oklab, var(--cat-primary) 24%, var(--bg));
  --room-nicu: color-mix(in oklab, var(--cat-2) 22%, var(--bg));
  --room-ot: color-mix(in oklab, var(--ink) 9%, var(--bg));
  --room-ward: color-mix(in oklab, var(--cat-4) 14%, var(--bg));
  --room-corr: color-mix(in oklab, var(--ink) 4%, var(--bg));
}
[data-theme="dark"] :is(m-scrolly[chart="hosp-parcel"], .hpx) {
  --room-labour: color-mix(in oklab, var(--cat-primary) 34%, var(--bg));
  --room-nicu: color-mix(in oklab, var(--cat-2) 34%, var(--bg));
  --room-ot: color-mix(in oklab, var(--ink) 16%, var(--bg));
  --room-ward: color-mix(in oklab, var(--cat-4) 24%, var(--bg));
  --room-corr: color-mix(in oklab, var(--ink) 9%, var(--bg));
}

/* ---- the step cards ------------------------------------------------------------ */
m-scrolly[chart="hosp-parcel"] .sc-card { max-width: 36ch; }
.hp-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--c); margin-right: 8px; vertical-align: 1px; }
.sc-card .hp-eg { font-family: var(--font-sans); font-size: 14px; font-weight: 400; line-height: 1.5; letter-spacing: 0; color: rgba(var(--ink-rgb), .72); }
.sc-card .hp-eg b { font-weight: 600; color: var(--ink); }
.sc-card .sc-desc strong { font-size: .9em; }
.sc-stats dd small { font-size: 11px; font-weight: 400; color: var(--muted); letter-spacing: 0; }
.hp-room { font-style: normal; white-space: nowrap; padding: 0 .28em; border-radius: 4px; background: var(--room-c); box-shadow: inset 0 -1px 0 rgba(var(--ink-rgb), .16); outline: none; cursor: default; }
.hp-room:focus-visible { box-shadow: 0 0 0 2px var(--ink); }
.hp-room[data-room="labour"] { --room-c: var(--room-labour); }
.hp-room[data-room="ot"] { --room-c: var(--room-ot); }
.hp-room[data-room="nicu"] { --room-c: var(--room-nicu); }
.hp-room[data-room="ward"] { --room-c: var(--room-ward); }
/* the five median bills on one line, this type's dot filled */
/* outside card: who uses it — metro against non-metro as two bars on one scale (the largest share of all five fills
   the track), then two plain facts, number first */
.hp-geo { margin: 16px 0 0; padding-top: 14px; border-top: 1px solid var(--hairline); }
.hp-geo-h { margin: 0 0 8px !important; font-family: var(--font-mono); font-size: 11px !important; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.hp-geo-row { display: grid; grid-template-columns: 9.5em minmax(0, 1fr) 3em; align-items: center; gap: 10px; margin: 0 0 6px !important; font-size: 14px !important; line-height: 1.3 !important; }
.hp-geo-row span:first-child { color: rgba(var(--ink-rgb), .78); }
.hp-geo-bar { display: block; height: 8px; border-radius: 4px; background: rgba(var(--ink-rgb), .07); overflow: hidden; }
.hp-geo-bar i { display: block; height: 100%; border-radius: 4px; }
.hp-geo-row b { font-family: var(--font-mono); font-size: 14px; font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }
.hp-facts { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 18px; margin: 14px 0 0; padding-top: 12px; border-top: 1px solid var(--hairline); }
.hp-facts div { display: flex; flex-direction: column; gap: 3px; }
.hp-facts dd { order: 0; margin: 0; font-family: var(--font-mono); font-size: 20px; font-weight: 500; font-variant-numeric: tabular-nums; }
.hp-facts dt { order: 1; font-size: 13px; line-height: 1.35; color: var(--muted); }
/* inside card: the C-section rate first and large, then the bill */
.sc-card .hp-nicu { font-size: 15px !important; color: rgba(var(--ink-rgb), .78); }
.hp-key { display: grid; grid-template-columns: auto 1fr; gap: 6px 22px; align-items: end; margin: 16px 0 0; padding-top: 14px; border-top: 1px solid var(--hairline); }
.hp-key p { margin: 0 !important; display: flex; flex-direction: column; gap: 4px; }
.hp-key b { font-family: var(--font-mono); font-weight: 500; font-variant-numeric: tabular-nums; line-height: 1; }
.hp-cs b { font-size: 40px; }
.hp-bill b { font-size: 20px; color: var(--ink); }
.hp-key span { font-size: 13px !important; line-height: 1.35; color: var(--muted); }
.hp-table td b { font-weight: 600; }
.hp-table { width: 100%; border-collapse: collapse; margin-top: 10px; font-family: var(--font-mono); font-size: 12px; font-variant-numeric: tabular-nums; }
.hp-table th, .hp-table td { padding: 6px 3px; text-align: right; border-bottom: 1px solid var(--hairline); font-weight: 400; }
.hp-table thead th { font-size: 11px; color: var(--muted); }
.hp-table tbody th { text-align: left; white-space: nowrap; }
.hp-table .hp-dot { width: 7px; height: 7px; margin-right: 6px; }

/* ---- the scene -------------------------------------------------------------------- */
.hpx { position: absolute; inset: 0; overflow: clip; }
/* zoomed in, the drawing is cut at the edge of its column: fade that edge */
/* the drawing fades out at all four edges of its frame, so zoomed in it rises out of the page instead of stopping at
   a hard rectangle */
.hpx.in-scrolly {
  --edge-x: clamp(32px, 7vw, 120px); --edge-y: clamp(28px, 7vh, 96px);
  -webkit-mask-image:
    linear-gradient(90deg, transparent, #000 var(--edge-x), #000 calc(100% - var(--edge-x)), transparent),
    linear-gradient(180deg, transparent, #000 var(--edge-y), #000 calc(100% - var(--edge-y)), transparent);
  -webkit-mask-composite: source-in;
  mask-image:
    linear-gradient(90deg, transparent, #000 var(--edge-x), #000 calc(100% - var(--edge-x)), transparent),
    linear-gradient(180deg, transparent, #000 var(--edge-y), #000 calc(100% - var(--edge-y)), transparent);
  mask-composite: intersect;
}
.hpx:not(.in-scrolly) { position: relative; height: clamp(440px, 70vh, 680px); }
.hpx-svg, .hpx-svg svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.hpx-svg svg { overflow: visible; }
.hpx-wait { position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%); margin: 0; font-family: var(--font-mono); font-size: 12px; color: var(--muted); }
/* rooms: pointing at a room word keeps that room bright, dims the rest */
.hpx-svg [data-room] { transition: opacity .3s; }
.hpx[data-room] .hpx-svg [data-room] { opacity: .25; }
.hpx[data-room="labour"] .hpx-svg [data-room="labour"],
.hpx[data-room="ot"] .hpx-svg [data-room="ot"],
.hpx[data-room="nicu"] .hpx-svg [data-room="nicu"],
.hpx[data-room="ward"] .hpx-svg [data-room="ward"] { opacity: 1; }

/* ---- the drawing's palette ------------------------------------------------------- */
.hpx-svg {
  --p-wall: color-mix(in oklab, var(--bg), #fff 62%);
  --p-trim: color-mix(in oklab, var(--bg), var(--ink) 4%);
  --p-ground: color-mix(in oklab, var(--bg), var(--ink) 5%);
  --p-walk: color-mix(in oklab, var(--bg), var(--ink) 10%);
  --p-road: color-mix(in oklab, var(--bg), var(--ink) 22%);
  --p-mid: color-mix(in oklab, var(--bg), var(--ink) 34%);
  --p-dark: color-mix(in oklab, var(--ink), var(--bg) 22%);
  --p-lilac: color-mix(in oklab, var(--cat-2) 26%, var(--bg));
  --p-lilac-2: color-mix(in oklab, var(--cat-2) 40%, var(--bg));
  --p-lilac-pale: color-mix(in oklab, var(--cat-2) 9%, var(--bg));
  --p-coral: var(--cat-primary);
  --p-coral-pale: color-mix(in oklab, var(--cat-primary) 32%, var(--bg));
  --p-skin: color-mix(in oklab, var(--cat-primary) 38%, var(--ink) 42%);
  --p-glass: color-mix(in oklab, var(--cat-2) 13%, #fff);
  --p-glass-2: color-mix(in oklab, var(--cat-2) 20%, var(--bg));
  --p-strata-1: color-mix(in oklab, color-mix(in oklab, var(--ink), var(--cat-primary) 45%) 46%, var(--bg));
  --p-strata-2: color-mix(in oklab, color-mix(in oklab, var(--ink), var(--cat-primary) 55%) 28%, var(--bg));
  --p-strata-3: color-mix(in oklab, var(--ink) 14%, var(--bg));
  --night: #170b15;
  --line-ink: var(--ink);
  --anatomy-paper: var(--bg);
  --anatomy-hi: rgba(var(--ink-rgb), .7);
  --anatomy-mid: rgba(var(--ink-rgb), .42);
  --anatomy-lo: rgba(var(--ink-rgb), .26);
  --anatomy-faint: rgba(var(--ink-rgb), .13);
  --anatomy-dot: var(--ink);
  --anatomy-halo: var(--ink); --anatomy-halo-opacity: .22;
  --anatomy-mono: var(--font-mono);
}
[data-theme="dark"] .hpx-svg { --anatomy-halo: #000; --anatomy-halo-opacity: .8; --p-glass: #1d1420; --p-glass-2: #18111b; }
.hpx-svg .m {
  --mm: var(--m);
  --anatomy-paper: var(--mm);
  --anatomy-top: color-mix(in oklab, var(--mm), #fff 30%);
  --anatomy-shade-3: color-mix(in oklab, var(--mm), #fff 12%);
  --anatomy-shade-2: var(--mm);
  --anatomy-shade-1: color-mix(in oklab, var(--mm), var(--line-ink) 6%);
  --anatomy-shade-0: color-mix(in oklab, var(--mm), var(--line-ink) 13%);
  --anatomy-hi: color-mix(in oklab, var(--mm), var(--line-ink) 66%);
  --anatomy-mid: color-mix(in oklab, var(--mm), var(--line-ink) 46%);
  --anatomy-lo: color-mix(in oklab, var(--mm), var(--line-ink) 30%);
  --anatomy-faint: color-mix(in oklab, var(--mm), var(--line-ink) 15%);
}
[data-theme="dark"] .hpx-svg .m {
  --mm: color-mix(in oklab, var(--m) 30%, var(--night));
  --anatomy-top: color-mix(in oklab, var(--mm), #fff 9%);
  --anatomy-shade-3: color-mix(in oklab, var(--mm), #fff 4%);
  --anatomy-shade-1: color-mix(in oklab, var(--mm), #000 10%);
  --anatomy-shade-0: color-mix(in oklab, var(--mm), #000 22%);
  --anatomy-hi: color-mix(in oklab, var(--mm), var(--line-ink) 44%);
  --anatomy-mid: color-mix(in oklab, var(--mm), var(--line-ink) 28%);
  --anatomy-lo: color-mix(in oklab, var(--mm), var(--line-ink) 17%);
  --anatomy-faint: color-mix(in oklab, var(--mm), var(--line-ink) 9%);
}
[data-theme="dark"] .hpx-svg :is(.m-lamp, .m-heater, .m-beacon, .m-lit, .m-screen, .m-type, .m-nh-sign) { --mm: var(--m); }
[data-theme="dark"] .hpx-svg .m-lamp { --m: #ffd9a0; }

/* paper: walls, beds, the light vehicles */
.hpx-svg :is(.m-nh-paint, .m-lp-wall, .m-mt-wall, .m-sp-wall, .m-mc-wall, .m-sign-board, .m-wall, .m-coping, .m-insulator, .m-bed, .m-pillow, .m-partition, .m-car-white, .m-amb, .m-shirt-w, .m-tank-w, .m-lamp-head, .m-incubator) { --m: var(--p-wall); }
.hpx-svg :is(.m-trim, .m-sp-band, .m-floor, .m-steel, .m-ac, .m-car-silver, .m-shutter, .m-trolley) { --m: var(--p-trim); }
.hpx-svg :is(.m-pillar, .m-stone, .m-concrete, .m-planter, .m-counter, .m-pavers) { --m: var(--p-walk); }
.hpx-svg :is(.m-metal, .m-sc-grey, .m-trunk, .m-helipad) { --m: var(--p-mid); }
.hpx-svg :is(.m-tyre, .m-tank, .m-seat, .m-auto-k, .m-hair, .m-screen, .m-solar, .m-trousers) { --m: var(--p-dark); }
/* the ground and its cut */
.hpx-svg .m-plot { --m: var(--p-ground); }
.hpx-svg .m-verge { --m: var(--p-lilac-pale); }
.hpx-svg .m-asphalt { --m: var(--p-road); }
.hpx-svg .m-gravel { --m: var(--p-strata-3); }
.hpx-svg .m-soil { --m: var(--p-strata-2); }
.hpx-svg .m-laterite { --m: var(--p-strata-1); }
/* the chapter's lilac: trees, some clothes, the sofas */
.hpx-svg .m-leaf { --m: var(--p-lilac); }
.hpx-svg :is(.m-leaf2, .m-ot-sheet) { --m: var(--p-lilac-2); }
.hpx-svg :is(.m-sari-p, .m-sc-blue, .m-shirt-b, .m-uniform, .m-scrubs, .m-sofa) { --m: color-mix(in oklab, var(--cat-2) 34%, var(--bg)); }
/* the chapter's coral: kerbs, signs, the auto's hood, the tea cart */
.hpx-svg :is(.m-kerb-y, .m-auto-y, .m-umbrella, .m-red, .m-beacon, .m-pharm, .m-sc-red, .m-sari-o, .m-heater) { --m: var(--p-coral); }
.hpx-svg .m-kerb-k { --m: var(--p-wall); }
.hpx-svg :is(.m-tile, .m-pot, .m-car-red, .m-cart, .m-sari-g, .m-wood) { --m: var(--p-coral-pale); }
.hpx-svg .m-wood { --m: color-mix(in oklab, var(--cat-primary) 30%, var(--ink) 30%); }
.hpx-svg .m-skin { --m: var(--p-skin); }
.hpx-svg .m-lamp { --m: #fff6e4; }
/* each hospital's one mark in its type colour */
.hpx-svg [data-type="nursing_home"] { --kc: var(--k-nursing_home); }
.hpx-svg [data-type="single_location"] { --kc: var(--k-single_location); }
.hpx-svg [data-type="mission_trust"] { --kc: var(--k-mission_trust); }
.hpx-svg [data-type="multichain"] { --kc: var(--k-multichain); }
.hpx-svg [data-type="maternity_specialty"] { --kc: var(--k-maternity_specialty); }
.hpx-svg :is(.m-nh-sign, .m-type, .m-nh-trim) { --m: var(--kc); }
.hpx-svg .m-sp-fin { --m: color-mix(in oklab, var(--kc) 58%, var(--p-wall)); }
.hpx-svg .m-lit { --m: var(--kc); --anatomy-lit: color-mix(in oklab, var(--kc), var(--ink) 30%); --anatomy-lit-top: color-mix(in oklab, var(--kc), #fff 20%); --anatomy-lit-shade: var(--kc); --anatomy-face: var(--kc); }

/* flat paint */
.hpx-svg .f { fill: var(--fm); stroke: none; }
[data-theme="dark"] .hpx-svg .f { fill: color-mix(in oklab, var(--fm) 34%, var(--night)); }
[data-theme="dark"] .hpx-svg :is(.f-lamp, .f-red, .f-white, .f-type, .f-logo, .f-clock) { fill: var(--fm); }
.hpx-svg .f-paint { --fm: var(--p-wall); }
.hpx-svg :is(.f-iron, .f-shop) { --fm: var(--p-dark); }
.hpx-svg :is(.f-roofdeck, .f-path) { --fm: var(--p-walk); }
.hpx-svg .f-drive { --fm: var(--p-trim); }
.hpx-svg .f-lawn { --fm: var(--p-lilac-pale); }
.hpx-svg .f-door { --fm: color-mix(in oklab, var(--ink) 60%, var(--bg)); }
.hpx-svg :is(.f-white, .f-clock, .f-cloth2) { --fm: #fff; }
.hpx-svg :is(.f-red, .f-stripe, .f-cloth1, .f-flag1) { --fm: var(--p-coral); }
.hpx-svg :is(.f-cloth3, .f-flag2) { --fm: var(--p-lilac-2); }
.hpx-svg :is(.f-logo, .f-type, .f-cloth4, .f-flag3) { --fm: var(--kc, var(--cat-primary)); }
.hpx-svg .f-logo2 { --fm: color-mix(in oklab, var(--kc), #fff 45%); }
.hpx-svg .f-lamp { --fm: #fff6dc; }
.hpx-svg .f-labour { --fm: var(--room-labour); }
.hpx-svg .f-ot { --fm: var(--room-ot); }
.hpx-svg .f-nicu { --fm: var(--room-nicu); }
.hpx-svg .f-ward { --fm: var(--room-ward); }
.hpx-svg .f-corr { --fm: var(--room-corr); }
[data-theme="dark"] .hpx-svg :is(.f-labour, .f-ot, .f-nicu, .f-ward, .f-corr) { fill: var(--fm); }

/* glass: a pale lilac by day; at night some windows are lit */
.hpx-svg .w { stroke: none; fill: var(--p-glass); }
.hpx-svg .w[data-f="x"] { fill: var(--p-glass-2); }
.hpx-svg .w[data-door] { fill: color-mix(in oklab, var(--cat-2) 30%, var(--bg)); }
.hpx-svg .w[data-v] { fill: color-mix(in oklab, var(--ink) 30%, var(--bg)); }
[data-theme="dark"] .hpx-svg .w[data-on] { fill: #f1c28f; }
[data-theme="dark"] .hpx-svg .w[data-on][data-f="x"] { fill: #d29e6c; }
[data-theme="dark"] .hpx-svg .w[data-door] { fill: #f6cf98; }
[data-theme="dark"] .hpx-svg .w[data-v] { fill: #2a2030; }

.hpx-svg .pipe-end .pe-in { fill: var(--p-dark); }
.hpx-svg .p-drain .pe-rim { fill: var(--p-walk); }
.hpx-svg .p-water .pe-rim { fill: var(--p-lilac-2); }
.hpx-svg .p-cable .pe-rim { fill: var(--p-coral); }
[data-theme="dark"] .hpx-svg .pipe-end { opacity: .5; }
.hpx-svg .iso-face-text.t-white { fill: #fff; font-weight: 600; letter-spacing: .08em; }
.hpx-svg .iso-face-text:is(.t-type, .t-sp) { fill: var(--kc); font-weight: 600; letter-spacing: .1em; }
.hpx-svg .boom { fill: none; stroke-width: 2px; stroke-linecap: butt; }
.hpx-svg .b-w { stroke: var(--p-wall); }
.hpx-svg .b-r { stroke: var(--p-coral); stroke-dasharray: 4 4; }
.hpx-svg .wire { stroke: rgba(var(--ink-rgb), .4); }
.hpx-svg .hp-h { stroke: var(--p-wall); stroke-width: 2px; }

@media (prefers-reduced-motion: reduce) {
  .hpx-svg [data-room] { transition: none; }
}
