/* population: 04 · Who it affects. The UK Biobank number, CPIC phenotype shares by group (stacked bars), 100 people (waffle).
   Colours are the core data scale, the --ph-* tokens: faster = darker warm grey, normal = mid grey, reduced = light orange,
   poor = orange. As in the films, every filled mark carries a fine ink outline (--pop-ol); indeterminate is a hollow square. */
.pop {
  --pop-s0: var(--ph-um);   /* ultrarapid / increased function */
  --pop-s1: var(--ph-rm);   /* rapid */
  --pop-s2: var(--ph-nm);   /* normal */
  --pop-s3: var(--ph-im);   /* intermediate / decreased */
  --pop-s4: var(--ph-pm);   /* poor */
  --pop-ol: rgba(17, 17, 17, .5);   /* the films' fine ink outline round each mark */
}
.pop .s0 { background: var(--pop-s0); } .pop .s1 { background: var(--pop-s1); } .pop .s2 { background: var(--pop-s2); }
.pop .s3 { background: var(--pop-s3); } .pop .s4 { background: var(--pop-s4); }
.pop .s5 { background: var(--white); box-shadow: inset 0 0 0 1.5px var(--line-2); }
/* Swatches beside a label (phenotype buttons, tooltip, the 100-people list): filled squares get the outline. */
.pop .pop-legend .opt i:not(.s5), .pop .pop-tip li i:not(.s5), .pop .pop-break li i:not(.s5):not(.h) { box-shadow: inset 0 0 0 1px var(--pop-ol); }
.pop b.data { font-weight: 400; }

/* ---------- Opening number ---------- */
.pop .pop-stats { grid-template-columns: minmax(0, 1fr); }   /* one number, full width on every screen */
.pop .pop-open .fnote { margin-top: 12px; }

/* ---------- Bars ---------- */
.pop .pop-box { margin-top: var(--s7); }
.pop .pop-fig { margin: 0; }
.pop .pop-legend .opt i { width: 10px; height: 10px; flex: none; }

.pop .pop-head { display: flex; justify-content: space-between; gap: 12px; margin: 0 0 6px; }
.pop .pop-axis { position: relative; height: 16px; margin: 0 0 4px; }
.pop .pop-axis i { position: absolute; top: 0; font-style: normal; transform: translateX(-50%); }
.pop .pop-axis i:nth-child(1) { left: 0; transform: none; } .pop .pop-axis i:nth-child(2) { left: 25%; } .pop .pop-axis i:nth-child(3) { left: 50%; }
.pop .pop-axis i:nth-child(4) { left: 75%; } .pop .pop-axis i:nth-child(5) { right: 0; transform: none; }

.pop .pop-rows { position: relative; border-top: 1px solid var(--line); }
.pop .pop-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "name val" "bar bar" "ref ref"; gap: 0 12px; align-items: last baseline; width: 100%; padding: 9px 0 10px; margin: 0; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; background: none; color: var(--ink); text-align: left; cursor: pointer; }
.pop .pop-row:focus-visible { outline-offset: 2px; }
.pop .pop-name, .pop .pop-val { margin-bottom: 6px; }
.pop .pop-name { grid-area: name; display: flex; align-items: center; flex-wrap: wrap; gap: 4px 10px; font-size: 15px; line-height: 1.25; min-width: 0; transition: color var(--t1); }
.pop .pop-name > span { display: inline-flex; align-items: center; gap: 9px; }
.pop .pop-name > span::before { content: ""; width: 8px; height: 8px; flex: none; box-shadow: inset 0 0 0 1.5px var(--line-2); transition: background var(--t1), box-shadow var(--t1); }
.pop .pop-row:hover .pop-name { color: var(--blue-900); }
.pop .pop-row:hover .pop-name > span::before { box-shadow: inset 0 0 0 1.5px var(--blue-900); }
.pop .pop-row[aria-pressed="true"] .pop-name > span { font-weight: 500; }
.pop .pop-row[aria-pressed="true"] .pop-name > span::before { background: var(--ink); box-shadow: none; }
.pop .pop-n { font-style: normal; color: var(--muted); }
.pop .pop-n:empty { display: none; }
.pop .pop-val { grid-area: val; text-align: right; white-space: nowrap; }
.pop .pop-val small { margin-left: 8px; }
.pop .pop-val small:empty { display: none; }
.pop .pop-track { grid-area: bar; position: relative; display: block; height: 20px; background: var(--soft); overflow: hidden; }
/* A fine ink frame drawn over the segments (::before), and the 50% line (::after). */
.pop .pop-track::before { content: ""; position: absolute; inset: 0; z-index: 1; box-shadow: inset 0 0 0 1px var(--pop-ol); pointer-events: none; }
.pop .pop-track::after { content: ""; position: absolute; left: 50%; top: 0; bottom: 0; z-index: 1; width: 1px; background: var(--muted); pointer-events: none; }
/* Segments slide to their new share when the gene or the estimate changes (and grow in once, 75ms apart, when the figure enters;
   population.js keeps the same pace). Each ends on a fine ink line, so neighbours read as separate cells, like the films' data. */
.pop .pop-seg { position: absolute; top: 0; bottom: 0; left: 0; width: 0; box-shadow: inset -1px 0 0 var(--pop-ol);
  transition: left calc(var(--t3) * 1.25) var(--ease) var(--d, 0ms), width calc(var(--t3) * 1.25) var(--ease) var(--d, 0ms), opacity var(--t2) var(--ease); }
.pop .pop-seg.s5 { box-shadow: inset 0 0 0 1px var(--line-2); }
.pop .pop-seg.z { box-shadow: none; }
.pop .pop-ref { grid-area: ref; position: relative; display: block; height: 0; overflow: hidden; transition: height var(--t2) var(--ease), margin var(--t2) var(--ease); }
.pop.pop-pv .pop-ref { height: 5px; margin-top: 3px; }
.pop.pop-pv .pop-row.none .pop-ref { height: 0; margin-top: 0; }
.pop .pop-empty { display: none; position: absolute; inset: 0; align-items: center; padding-left: 10px; color: var(--muted); }
.pop .pop-row.none { cursor: default; }
.pop .pop-row.none .pop-track { background: var(--white); }
.pop .pop-row.none .pop-track::before { box-shadow: inset 0 0 0 1px var(--line-2); }
.pop .pop-row.none .pop-track::after { display: none; }
.pop .pop-row.none .pop-empty { display: flex; }
.pop .pop-ref-k { display: none; }
.pop.pop-pv .pop-ref-k { display: inline; }
.pop .key i.pop-refsw { width: 18px; height: 5px; vertical-align: 1px; background: linear-gradient(90deg, var(--pop-s2) 0 60%, var(--pop-s3) 60% 90%, var(--pop-s4) 90%); }
.pop .pop-key + .fnote { margin-top: 12px; }

/* Highlight one phenotype across the bars and the waffle. */
.pop[data-hl="0"] .pop-seg:not(.s0), .pop[data-hl="1"] .pop-seg:not(.s1), .pop[data-hl="2"] .pop-seg:not(.s2),
.pop[data-hl="3"] .pop-seg:not(.s3), .pop[data-hl="4"] .pop-seg:not(.s4), .pop[data-hl="5"] .pop-seg:not(.s5),
.pop[data-hl="0"] .pop-cell:not(.s0), .pop[data-hl="1"] .pop-cell:not(.s1), .pop[data-hl="2"] .pop-cell:not(.s2),
.pop[data-hl="3"] .pop-cell:not(.s3), .pop[data-hl="4"] .pop-cell:not(.s4), .pop[data-hl="5"] .pop-cell:not(.s5) { opacity: .16; }

/* Tooltip: a white card with an ink hairline, no shadow. */
.pop .pop-tip { position: absolute; top: 0; left: 0; z-index: 6; width: 268px; max-width: calc(100% - 16px); background: var(--white); border: 1px solid var(--ink); padding: 14px 16px 12px; pointer-events: none; font-size: 14px; line-height: 1.35; }
.pop .pop-tt { display: block; font-weight: 500; font-size: 15px; }
.pop .pop-tsub { display: block; font-size: 13px; color: var(--muted); }
.pop .pop-tip .k { margin: 4px 0 0; }
.pop .pop-tip ul { list-style: none; margin: 10px 0 0; padding: 0; border-top: 1px solid var(--line); }
.pop .pop-tip li { display: grid; grid-template-columns: 10px 1fr auto; gap: 10px; align-items: baseline; padding: 6px 0; border-bottom: 1px solid var(--line); }
.pop .pop-tip li i { width: 10px; height: 10px; align-self: center; }
.pop .pop-tip li small { display: block; color: var(--muted); }
.pop .pop-tip li.hl { background: var(--sel); }
.pop .pop-ttot { display: flex; justify-content: space-between; margin: 8px 0 0; font-weight: 500; }

/* Table view */
.pop .pop-tscroll { overflow-x: auto; margin-top: 12px; }
.pop .pop-tbl { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 520px; }
.pop .pop-tbl caption { text-align: left; padding-bottom: 8px; }
.pop .pop-tbl th, .pop .pop-tbl td { text-align: right; padding: 6px 0 6px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.pop .pop-tbl thead th { font-weight: 500; font-size: 12px; border-bottom: 1px solid var(--ink); }
.pop .pop-tbl th[scope="row"], .pop .pop-tbl thead th:first-child { text-align: left; padding-left: 0; font-weight: 400; white-space: normal; }
.pop .pop-tbl td { font-family: var(--mono); font-size: 12px; }

/* Control column */
.pop .pop-genes .opt { flex-direction: column; align-items: flex-start; gap: 2px; }
.pop .pop-genes .opt b { font-weight: 500; }
.pop .pop-note { margin-top: 10px; }

/* ---------- 100 people ---------- */
.pop .pop-hundred { margin-top: var(--s7); }
.pop .pop-kick { display: inline-flex; align-items: center; gap: 10px; }
.pop .pop-kick svg { color: var(--tone); }
.pop .pop-sel { gap: 12px; min-width: 0; }
.pop .pop-sel select { appearance: none; -webkit-appearance: none; min-width: 0; width: 300px; max-width: 100%; font: inherit; font-size: 16px; color: var(--ink); background: var(--white) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 7 4'%3E%3Cpath d='M0 0h1v1H0zM1 1h1v1H1zM2 2h1v1H2zM3 3h1v1H3zM4 2h1v1H4zM5 1h1v1H5zM6 0h1v1H6z' fill='%23111'/%3E%3C/svg%3E") no-repeat right 14px center / 12px 7px; border: 1px solid var(--line-2); border-radius: 0; padding: 10px 40px 10px 12px; cursor: pointer; transition: border-color var(--t1); }
.pop .pop-sel select:hover { border-color: var(--blue-900); }
.pop .pop-hbody { display: grid; grid-template-columns: minmax(0, 320px) minmax(0, 1fr); gap: var(--s7); align-items: start; }
.pop .pop-waffle { display: block; width: 100%; height: auto; overflow: visible; }
/* Cells dissolve in one person at a time, in reading order, when the sheet enters (10ms apart, 200ms each; the big number
   in population.js counts at the same pace); later changes recolour them. Every person is a filled square with a fine ink
   outline, like the films' atoms. */
.pop .pop-cell { fill: var(--pop-s2); stroke: var(--pop-ol); stroke-width: 1; opacity: 0; transition: opacity 200ms var(--ease) calc(var(--k, 0) * 10ms); }
.pop .pop-hundred.on .pop-cell { opacity: 1; }
.pop .pop-hundred.done .pop-cell { transition: fill var(--t2) var(--ease), stroke var(--t2) var(--ease), opacity var(--t2) var(--ease); }
.pop .pop-cell.s0 { fill: var(--pop-s0); } .pop .pop-cell.s1 { fill: var(--pop-s1); } .pop .pop-cell.s2 { fill: var(--pop-s2); }
.pop .pop-cell.s3 { fill: var(--pop-s3); } .pop .pop-cell.s4 { fill: var(--pop-s4); }
.pop .pop-cell.s5 { fill: var(--white); stroke: var(--line-2); stroke-width: 1.5; }
/* Outlined: a person CPIC counts as not normal whom the panel alleles would read as normal. */
.pop .pop-cell.h { fill: var(--white); stroke-width: 2.5; }
.pop .pop-cell.h.s0 { stroke: var(--pop-s0); } .pop .pop-cell.h.s1 { stroke: var(--pop-s1); }
.pop .pop-cell.h.s3 { stroke: var(--pop-s3); } .pop .pop-cell.h.s4 { stroke: var(--pop-s4); }
.pop .pop-cell.e { fill: var(--white); stroke: var(--line-2); stroke-width: 1; }
.pop .pop-big { margin: 0 0 var(--s5); }
/* The sentence beside the 100 people is the films' caption voice: Newsreader italic. */
.pop .pop-big p { font-family: var(--display); font-style: italic; font-weight: 400; font-size: 19px; line-height: 1.38; letter-spacing: -0.005em; color: var(--ink); max-width: 30em; }
.pop .pop-break { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); max-width: 460px; }
.pop .pop-break li { display: grid; grid-template-columns: 10px 1fr auto; gap: 12px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 15px; }
.pop .pop-break li i { width: 10px; height: 10px; }
.pop .pop-break li i.h { background: var(--white); }
.pop .pop-break li i.hs0 { box-shadow: inset 0 0 0 2px var(--pop-s0); } .pop .pop-break li i.hs1 { box-shadow: inset 0 0 0 2px var(--pop-s1); }
.pop .pop-break li i.hs3 { box-shadow: inset 0 0 0 2px var(--pop-s3); } .pop .pop-break li i.hs4 { box-shadow: inset 0 0 0 2px var(--pop-s4); }
.pop .pop-side > .fnote { margin-top: var(--s5); }

/* ---------- Sources ---------- */
.pop .pop-src { margin-top: var(--s7); }
.pop .pop-src .fnote { margin: 8px 0 0 26px; }

@media (max-width: 1000px) {
  /* Stacked: the gene and estimate controls sit above the chart. */
  .pop .pop-box { display: flex; flex-direction: column; }
  .pop .figbox > .pop-ctl { order: -1; border-top: 0; border-bottom: 1px solid var(--line); display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px 28px; }
  .pop .pop-cg { grid-column: 1 / -1; }
  .pop .pop-genes { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .pop .pop-legend { display: flex; flex-wrap: wrap; }
}
@media (max-width: 760px) {
  .pop .figbox > .pop-ctl { grid-template-columns: 1fr; gap: 16px; }
  .pop .pop-genes .opt small { display: none; }
  .pop .pop-genes .opt { padding: 10px 8px; align-items: center; }
  .pop .pop-name { font-size: 14px; }
  .pop .pop-big p { font-size: 18px; }
  .pop .pop-tip { width: 250px; }
  .pop .pop-hbody { grid-template-columns: 1fr; gap: var(--s5); }
  .pop .pop-waffle { max-width: 300px; }
  .pop .pop-sel { flex: 1 1 100%; margin-left: 0; }
  .pop .pop-sel select { flex: 1; width: auto; }
}
