/* Preserve the map projection while giving the province comparison its own
   readable, scrollable area. Matrix rows never shrink with the slide height. */
.pstage.stacked .pstage__maps { flex-direction: column; align-items: center; }
.pstage__side > .side-svg { display: block; }
.pstage.has-matrix .pstage__legend { padding-bottom: 10px; }
.pstage.has-matrix .pstage__body { align-items: stretch; }
.pstage.has-matrix .pstage__maps { justify-content: center; }
.pstage.has-matrix .pstage__side {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  max-height: none;
}
.pstage.has-matrix .pstage__title { font-size: clamp(17px, 1.1vw, 22px); line-height: 1.45; }
.pstage.has-matrix .map-label { font-size: clamp(18px, 1.25vw, 24px) !important; }
.pstage.has-matrix .side-note { color: var(--text-primary); font-size: clamp(17px, 1.1vw, 21px); line-height: 1.45; }
.matrix-help { margin: 2px 0 10px; font-size: clamp(14px, .95vw, 18px); color: var(--text-secondary); line-height: 1.5; }
.matrix-scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
  scrollbar-gutter: stable;
  scrollbar-color: var(--border-strong) var(--surface);
  overscroll-behavior: contain;
  border-block: 1px solid var(--border-strong);
}
.matrix-scroll:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.matrix-table {
  width: 100%;
  min-width: 620px;
  table-layout: fixed;
  border-collapse: separate;
  border-spacing: 0;
  font-size: clamp(17px, 1.1vw, 21px);
  line-height: 1.4;
}
.matrix-table th, .matrix-table td { padding: 2px 3px; text-align: center; vertical-align: middle; }
.matrix-table thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  height: 50px;
  padding: 8px 5px;
  background: var(--page-bg);
  border-bottom: 1px solid var(--border-strong);
  color: var(--text-secondary);
  font-weight: 400;
  font-size: inherit !important;
  overflow-wrap: anywhere;
}
.matrix-table thead th.is-active { color: var(--text-primary); font-weight: 600; }
.matrix-table .mx-term { white-space: nowrap; }
.matrix-table th:first-child { width: 27%; text-align: left; padding-left: 8px; }
.matrix-table tbody th { position: sticky; left: 0; z-index: 2; background: var(--page-bg); font-weight: 400; }
.matrix-table thead th:first-child { left: 0; z-index: 4; }
.matrix-table .mx-name {
  display: block;
  width: 100%;
  padding: 4px 0;
  border: 0;
  border-radius: 2px;
  background: none;
  color: var(--text-secondary);
  font: inherit;
  text-align: left;
  white-space: nowrap;
  cursor: pointer;
}
.matrix-table .mx-row.is-case .mx-name { color: var(--accent-soft); font-weight: 600; }
.matrix-table .mx-row.is-all .mx-name { color: var(--text-primary); font-weight: 600; }
.matrix-table .mx-cell { display: block; height: 27px; border-radius: 3px; background: var(--surface-3); }
.matrix-table .mx-cell.on { background: var(--member); }
.matrix-table .mx-row.is-all .mx-cell.on { background: var(--member-strong); }
.matrix-table .mx-cell.near { outline: 1px dashed var(--text-muted); outline-offset: -1px; }
.matrix-table .mx-active-column { background: rgba(78, 165, 255, .12); }
.matrix-table .mx-row:hover th, .matrix-table .mx-row:hover td,
.matrix-table .mx-row:focus-within th, .matrix-table .mx-row:focus-within td { background: var(--surface-2); }
.matrix-table .mx-name:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.pstage.has-matrix.matrix-stacked .pstage__body { flex-direction: column; gap: 10px; }
.pstage.has-matrix.matrix-stacked .pstage__maps { flex: 0 0 var(--matrix-map-h); min-height: 0; }
.pstage.has-matrix.matrix-stacked .pstage__side { width: 100% !important; flex: 1; min-height: 130px; }
.pstage.has-matrix.matrix-stacked .pstage__title { font-size: 16px; }
.pstage.has-matrix.matrix-stacked .map-label { font-size: 16px !important; }
.pstage.has-matrix.matrix-stacked .matrix-help { margin-bottom: 4px; }

/* Allocation controls and legends have predictable heights before the map is
   measured. The map and the province table share the remaining slide space. */
.alloc:not(.alloc--narrow) .alloc__bar { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 12px 18px; }
.alloc:not(.alloc--narrow) .alloc__years { flex-wrap: nowrap; min-width: 0; }
.alloc .alloc__years input[type=range] { width: clamp(90px, 10vw, 180px); min-width: 70px; flex: 1; }
.alloc .alloc__yearlabel { min-width: 0; white-space: nowrap; }
.alloc .alloc__years .btn { flex: none; white-space: nowrap; }
.alloc:not(.alloc--narrow) .alloc__body { grid-template-columns: minmax(0, .84fr) minmax(0, 1.16fr); gap: 20px; }
.alloc .alloc__label { font-size: clamp(17px, 1.1vw, 22px); font-weight: 500; stroke-width: 4px; }
.alloc .alloc__legend { line-height: 1.4; padding-bottom: 6px; }
.alloc .alloc__caption { line-height: 1.45; }
.alloc .alloc__scroll { scrollbar-gutter: stable; overscroll-behavior: contain; }
.alloc .alloc__scroll:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.alloc .alloc__table { border-collapse: separate; border-spacing: 0; }
.alloc .alloc__table thead th { z-index: 2; }
.alloc .alloc__table tfoot td, .alloc .alloc__table tfoot th { z-index: 3; background: var(--surface-2); }
.alloc .alloc__table tr:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.alloc.alloc--narrow .alloc__body { grid-template-columns: 1fr; grid-template-rows: minmax(180px, 1fr) minmax(160px, 1fr); }
.alloc.alloc--narrow .alloc__scroll { max-height: none; }
.alloc.alloc--narrow .alloc__plans { max-width: 100%; overflow-x: auto; }
.alloc.alloc--narrow .alloc__plan { white-space: nowrap; }
.alloc.alloc--narrow .alloc__label { font-size: 15px; }
@media print {
  .pstage.has-matrix .pstage__side, .matrix-scroll { overflow: visible; max-height: none; }
  .matrix-table thead th, .matrix-table tbody th { position: static; }
  .matrix-help { display: none; }
}

/* Descriptive grouping uses the same categories in the opening map and profiles. */
.pstage.has-context .pstage__side, .pstage.has-discordance .pstage__side, .pstage.has-change .pstage__side {
  display: flex; flex-direction: column; min-height: 0; overflow: hidden; max-height: none;
}
.context-groups { overflow: auto; min-height: 0; scrollbar-gutter: stable; padding-right: 6px; overscroll-behavior: contain; }
.context-definition { margin: 0 0 12px; font-size: clamp(15px, .95vw, 19px); line-height: 1.45; color: var(--text-secondary); }
.context-group { border-block-start: 1px solid var(--border-hairline); padding: 10px 0; }
.context-group h3 { display: flex; align-items: baseline; flex-wrap: wrap; gap: 5px 10px; margin: 0; font-size: clamp(16px, 1.05vw, 21px); font-weight: 500; line-height: 1.45; }
.context-swatch { display: inline-block; width: 15px; height: 15px; background: var(--group-color); border: 1px solid var(--border-strong); flex: none; }
.context-count { font-size: .9em; color: var(--text-secondary); margin-left: auto; white-space: nowrap; }
.context-members summary { cursor: pointer; color: var(--text-muted); font-size: clamp(13px, .85vw, 17px); margin-top: 4px; }
.context-members p { line-height: 1.7; margin: 8px 0 0; }
.province-name-button { display: inline; padding: 0; border: 0; background: transparent; color: inherit; font: inherit; text-align: inherit; cursor: pointer; }
.province-name-button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.context-representative { margin: 6px 0 3px; font-size: clamp(15px, .95vw, 19px); line-height: 1.45; }
.context-representative strong { color: var(--accent-soft); margin-right: 10px; }
.context-representative span { color: var(--text-secondary); }
.card__group { margin: 0 0 5px; padding-left: 10px; border-left: 5px solid var(--group-color); font-size: clamp(13px, .85vw, 17px); line-height: 1.45; color: var(--text-secondary); }
.card__group summary { cursor: pointer; }
.card__group-peers { margin: 8px 0 0; max-height: 110px; overflow: auto; font-size: .92em; }
/* Active membership remains visible across the full table, including while scrolling. */
.matrix-active-label { margin: 0 0 8px; border-left: 5px solid var(--accent); background: rgba(78,165,255,.16); padding: 7px 12px; color: var(--text-primary); font-size: clamp(16px,1.05vw,21px); font-weight: 500; line-height: 1.45; }
.matrix-table thead th.is-active { background: #1b4164; box-shadow: inset 3px 0 var(--accent), inset -3px 0 var(--accent), inset 0 3px var(--accent); }
.matrix-table td.mx-active-column { background: rgba(78,165,255,.22); box-shadow: inset 3px 0 var(--accent), inset -3px 0 var(--accent); }
.matrix-table tr:last-child td.mx-active-column { border-bottom: 3px solid var(--accent); }
.matrix-table .mx-row:hover td.mx-active-column, .matrix-table .mx-row:focus-within td.mx-active-column { background: rgba(78,165,255,.35); }
.province-table-title { margin: 0 0 6px; font-size: clamp(17px,1.15vw,23px); font-weight: 500; line-height: 1.45; }
.province-table-scroll { min-height: 0; flex: 1; overflow: auto; scrollbar-gutter: stable; overscroll-behavior: contain; }
.province-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: clamp(15px,1vw,20px); }
.province-table th, .province-table td { padding: 7px 9px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--border-hairline); }
.province-table thead th { position: sticky; top: 0; z-index: 2; background: var(--surface); color: var(--text-secondary); font-size: .9em; font-weight: 400; }
.province-table th:nth-child(2), .province-table tbody th { text-align: left; font-weight: 400; }
.province-table .is-case th { color: var(--accent-soft); font-weight: 500; }
.change-value { font-weight: 500; }
.discordance-summary { margin: 0 0 8px; font-size: clamp(18px,1.2vw,25px); line-height: 1.5; }
.discordance-summary strong { color: var(--accent-soft); font-size: 1.5em; margin-right: 10px; }
.discordance-scroll { flex: 1; min-height: 0; overflow: auto; overscroll-behavior: contain; }
.discordance-table { width: 100%; table-layout: fixed; border-spacing: 4px; font-size: clamp(17px,1.1vw,22px); }
.discordance-table th { font-weight: 400; font-size: .9em; color: var(--text-secondary); padding: 9px; }
.discordance-table th:first-child { width: 29%; }
.discordance-table td { background: var(--surface-2); padding: 14px 12px; text-align: center; vertical-align: top; border: 1px solid var(--border-hairline); }
.discordance-table td.is-discordant { background: rgba(224,166,255,.14); border-color: var(--accent-soft); }
.discordance-table td strong { display: inline-block; font-size: clamp(28px,2.2vw,43px); line-height: 1.35; }
.discordance-table details { font-size: .8em; text-align: left; margin-top: 7px; color: var(--text-secondary); }
.discordance-table summary { cursor: pointer; text-align: center; }
.discordance-table details p { line-height: 1.65; margin: 7px 0 0; }
.discordance-key { font-size: clamp(14px,.9vw,18px); color: var(--text-secondary); margin: 8px 0 0; }
.province-verification { width: 100%; height: 100%; display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 28px; }
.province-verification[hidden], .pstage[hidden] { display: none; }
.verification-panel { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.verification-panel h3 { font-size: clamp(20px,1.4vw,28px); margin: 0 0 7px; font-weight: 500; }
.verification-y-label, .verification-x-label { margin: 0; color: var(--text-secondary); font-size: clamp(15px,1vw,20px); line-height: 1.5; }
.verification-x-label { text-align: center; margin-top: 4px; }
.verification-plot { min-height: 0; flex: 1; }
.verification-svg { display: block; overflow: visible; }
.verification-svg .map-label { font-size: clamp(17px,1.1vw,22px); }
.verification-dot { stroke: var(--page-bg); stroke-width: 1.2; }
.verification-point:focus .verification-dot { stroke: var(--text-primary); stroke-width: 3; }
.verification-ray { opacity: .7; }
@media (max-width: 820px) {
  .pstage.has-context .pstage__body, .pstage.has-discordance .pstage__body, .pstage.has-change .pstage__body { flex-direction: column; }
  .pstage.has-context .pstage__maps, .pstage.has-discordance .pstage__maps, .pstage.has-change .pstage__maps { flex: 0 0 42%; min-height: 180px; }
  .pstage.has-context .pstage__side, .pstage.has-discordance .pstage__side, .pstage.has-change .pstage__side { width: 100% !important; flex: 1; min-height: 160px; }
  .province-verification { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; gap: 18px; }
  .verification-panel h3 { font-size: 18px; }
  .verification-x-label, .verification-y-label { font-size: 14px; }
}
.pstage.province-side-stacked .pstage__body { flex-direction: column; gap: 10px; }
.pstage.province-side-stacked .pstage__maps { flex: 0 0 var(--province-map-h); min-height: 0; }
.pstage.province-side-stacked .pstage__side { width: 100% !important; flex: 1; min-height: 160px; }
.context-representative .province-name-button { color: var(--accent-soft); font-weight: 500; }
.context-group { padding-block: 6px; }
.context-definition { margin-bottom: 6px; }
.context-representative { margin-block: 2px; }
.context-members summary { margin-top: 1px; line-height: 1.35; }
/* A stacked matrix needs room for its explanatory header and visible rows.
   Let the page scroll on a narrow screen instead of reducing the table to its header. */
@media (max-width: 820px) {
  .scene__stage:has(.pstage.matrix-stacked) { min-height: 860px; }
  .pstage.has-matrix.matrix-stacked .pstage__side { min-height: 340px; }
}
@media (min-width: 961px) and (max-width: 1550px) {
  .present [data-scene="S17"] .cards__caption { margin-bottom: 6px; }
  .present [data-scene="S17"] .cards__grid { gap: 10px 14px; }
  .present [data-scene="S17"] .card { padding-block: 8px; }
}
