/*
 * cmc/matrix (prototype cmc.css 8l + the matrix markup in methodology.html / statements.html, Tailwind classes copied
 * as plain CSS; spacing in px). Below 1024 the table keeps a 620px floor and scrolls sideways inside its own box with
 * the row labels sticky; from 1024 it is sized by its 130px columns and centred.
 */
.wp-block-cmc-matrix {
	--cmc-matrix-ink: var(--wp--preset--color--charcoal);
	color: var(--cmc-matrix-ink);
}

.wp-block-cmc-matrix .screen-reader-text {
	position: absolute;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}

/* Head row: the inner blocks (left) and the UK/US switch (right); stacked below 1024 */
.cmc-matrix__head {
	display: flex;
	flex-direction: column;
	align-items: flex-start;
	gap: 25px;
}

.wp-block-cmc-matrix.is-plot .cmc-matrix__head {
	align-items: stretch;
}

.cmc-matrix__lead {
	min-width: 0;
}

@media (width >= 1024px) {
	.cmc-matrix__head,
	.wp-block-cmc-matrix.is-plot .cmc-matrix__head {
		flex-direction: row;
		align-items: flex-end;
		justify-content: space-between;
	}

	.wp-block-cmc-matrix.is-plot .cmc-matrix__head {
		gap: 60px;
	}

	.cmc-matrix__switch:only-child {
		margin-left: auto;
	}
}

/* The switch */
.cmc-matrix__switch {
	flex-shrink: 0;
	min-width: 0;
	margin: 0;
	padding: 4px;
	border: 1px solid var(--wp--preset--color--greige);
	border-radius: 9999px;
	background: var(--wp--preset--color--white);
}

.cmc-matrix__options {
	display: flex;
	gap: 0;
}

.cmc-matrix__option {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 9px 16px;
	border-radius: 9999px;
	cursor: pointer;
	transition: background-color 300ms var(--wp--custom--ease);
}

.cmc-matrix__option:has(input:checked) {
	background-color: var(--wp--preset--color--charcoal);
}

.cmc-matrix__flag {
	width: 20px;
	height: 20px;
	border-radius: 9999px;
	object-fit: cover;
	object-position: right;
	filter: grayscale(100%);
}

.cmc-matrix__option.is-us .cmc-matrix__flag {
	object-position: left;
}

.cmc-matrix__option span {
	font-size: var(--wp--preset--font-size--text-11);
	font-weight: 600;
	line-height: 1.3;
	letter-spacing: var(--wp--custom--letter-spacing--caption);
	text-transform: uppercase;
	color: var(--wp--preset--color--charcoal);
}

.cmc-matrix__option:has(input:checked) span {
	color: var(--wp--preset--color--white);
}

/* The plot */
.cmc-matrix__plot {
	margin-top: 50px;
}

.cmc-matrix__frame {
	position: relative;
	display: flex;
	padding: 0 0 20px 20px;
}

.cmc-matrix__frame-inner,
.cmc-matrix__body {
	flex: 1 1 0%;
	min-width: 0;
}

.cmc-matrix__row {
	display: flex;
	gap: 15px;
}

/* Y-axis title: reads upwards, feet towards the matrix, in a 382px box */
.cmc-matrix__y {
	display: none;
	flex-shrink: 0;
	height: 382px;
	margin: 0;
	font-size: var(--wp--preset--font-size--text-7);
	font-weight: 500;
	line-height: 1.3;
	text-align: center;
	writing-mode: vertical-rl;
	transform: rotate(180deg);
}

.cmc-matrix__hint {
	margin: 0 0 12px;
	font-size: var(--wp--preset--font-size--text-11);
	line-height: 1.3;
	color: color-mix(in srgb, var(--wp--preset--color--charcoal) 70%, transparent);
}

.cmc-matrix__scroll {
	overflow-x: auto;
}

.cmc-matrix__table {
	width: 100%;
	min-width: 620px;
	table-layout: fixed;
	border-collapse: separate;
	border-spacing: 8px;
	text-indent: 0;
}

.cmc-matrix__table tbody th {
	position: sticky;
	left: 0;
	z-index: 10;
	padding-right: 7px;
	background-color: var(--wp--preset--color--white);
	font-size: var(--wp--preset--font-size--text-7);
	font-weight: 400;
	line-height: 1.3;
	text-align: left;
	vertical-align: middle;
}

.cmc-matrix__cell {
	height: 70px;
	border: 1px solid rgb(255 255 255 / 0.1);
	border-radius: var(--wp--custom--radius--btn);
	text-align: center;
	vertical-align: middle;
	transition: border-color 200ms var(--wp--custom--ease);
}

.cmc-matrix__cell.is-cat-0 { background-color: var(--wp--custom--cat--0); border-color: color-mix(in srgb, var(--wp--preset--color--charcoal) 15%, transparent); }
.cmc-matrix__cell.is-cat-1 { background-color: var(--wp--custom--cat--1); }
.cmc-matrix__cell.is-cat-2 { background-color: var(--wp--custom--cat--2); }
.cmc-matrix__cell.is-cat-3 { background-color: var(--wp--custom--cat--3); }
.cmc-matrix__cell.is-cat-4 { background-color: var(--wp--custom--cat--4); color: var(--wp--preset--color--white); }
.cmc-matrix__cell.is-cat-5 { background-color: var(--wp--custom--cat--5); color: var(--wp--preset--color--white); }

.cmc-matrix__cell.is-dim {
	opacity: 0.4;
}

.cmc-matrix__cell.is-lit {
	position: relative;
}

.cmc-matrix__blank {
	height: 70px;
	border-radius: var(--wp--custom--radius--blank);
}

/* Only cells with something to click light up (a 1px charcoal keyline, which is also the focus indicator) */
.cmc-matrix__cell:has(button):hover,
.cmc-matrix__cell:has(:focus-visible) {
	border-color: var(--wp--preset--color--charcoal);
}

.matrix-cell {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	width: 100%;
	height: 100%;
	margin: 0;
	padding: 0;
	border: 0;
	background: none;
	color: inherit;
	font: inherit;
	cursor: pointer;
}

.matrix-cell:focus-visible {
	outline: none;
}

.cmc-matrix__label {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	width: 100%;
	height: 100%;
}

.cmc-matrix__cell.is-lit .cmc-matrix__label {
	margin-top: -14px;
}

.cmc-matrix__cat {
	display: block;
	font-size: var(--wp--preset--font-size--text-11);
	line-height: 1.3;
	letter-spacing: var(--wp--custom--letter-spacing--caption);
	text-transform: uppercase;
}

.cmc-matrix__num {
	display: block;
	font-size: var(--wp--preset--font-size--text-6);
	font-weight: 700;
	line-height: 1.2;
}

.cmc-matrix__table tfoot th {
	padding-top: 10px;
	padding-bottom: 10px;
	font-weight: 400;
	text-align: center;
	vertical-align: middle;
}

.cmc-matrix__pct,
.cmc-matrix__count {
	display: block;
	line-height: 1.3;
}

.cmc-matrix__pct {
	font-size: var(--wp--preset--font-size--text-7);
}

.cmc-matrix__count {
	margin-top: 8px;
	font-size: var(--wp--preset--font-size--text-10);
}

.is-plot .cmc-matrix__count {
	color: color-mix(in srgb, var(--wp--preset--color--charcoal) 60%, transparent);
}

.cmc-matrix__x {
	margin: 20px 0 0;
	font-size: var(--wp--preset--font-size--text-7);
	font-weight: 500;
	line-height: 1.3;
	text-align: center;
}

@media (width >= 1024px) {
	.cmc-matrix__frame {
		width: fit-content;
		margin-inline: auto;
	}

	.cmc-matrix__y {
		display: block;
	}

	.cmc-matrix__hint {
		display: none;
	}

	.cmc-matrix__table {
		width: auto;
		min-width: 0;
	}

	.cmc-matrix__table tbody th {
		background-color: transparent;
		text-align: right;
	}

	.cmc-matrix__cell:not(.is-lit) {
		width: 130px;
	}

	.cmc-matrix__x {
		padding: 0 8px 0 176px;
	}
}

/* Methodology: the info popover (top layer, placed by view.js) */
.matrix-pop {
	position: fixed;
	inset: auto;
	max-width: 280px;
	margin: 0;
	padding: 16px 18px;
	border: 1px solid rgb(255 255 255 / 0.16);
	border-radius: var(--wp--custom--radius--card);
	background: color-mix(in srgb, var(--wp--preset--color--charcoal) 96%, transparent);
	color: var(--wp--preset--color--cloud);
	-webkit-backdrop-filter: blur(8px);
	backdrop-filter: blur(8px);
	box-shadow: 0 10px 30px rgb(0 0 0 / 0.35);
}

.matrix-pop:popover-open {
	display: block;
}

.matrix-pop .cmc-pop__title {
	margin: 0;
	font-size: var(--wp--preset--font-size--text-6);
	font-weight: 600;
	line-height: 1.2;
	color: var(--wp--preset--color--white);
}

.matrix-pop dl {
	display: flex;
	flex-direction: column;
	gap: 10px;
	margin: 10px 0 0;
}

.matrix-pop dt,
.matrix-pop .cmc-pop__label {
	font-size: var(--wp--preset--font-size--text-11);
	line-height: 1.3;
	color: color-mix(in srgb, var(--wp--preset--color--cloud) 70%, transparent);
}

.matrix-pop dd {
	margin: 0;
	font-size: var(--wp--preset--font-size--text-8);
	font-weight: 600;
	line-height: 1.3;
	color: var(--wp--preset--color--cloud);
}

.matrix-pop .cmc-pop__label {
	margin: 12px 0 0;
}

.matrix-pop ul {
	display: flex;
	flex-direction: column;
	gap: 2px;
	margin: 4px 0 0;
	padding: 0;
	list-style: none;
}

.matrix-pop li {
	font-size: var(--wp--preset--font-size--text-8);
	font-weight: 600;
	line-height: 1.3;
	color: var(--wp--preset--color--salmon);
}

/* Statements: the pulsing dot and count on each lit cell (burnt sienna; still under reduced motion) */
.cmc-matrix__dot {
	position: absolute;
	inset-inline: 0;
	bottom: 7px;
	display: flex;
	justify-content: center;
}

.scale-dot {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	margin: 0;
	padding: 0;
	border: 0;
	background: none;
	font: inherit;
	cursor: pointer;
}

.scale-dot__pulse {
	position: relative;
	flex: 0 0 auto;
	width: 7px;
	height: 7px;
	border-radius: 9999px;
	background: var(--wp--preset--color--burnt-sienna);
}

.scale-dot__pulse::after {
	content: "";
	position: absolute;
	inset: 0;
	border-radius: 9999px;
	background: var(--wp--preset--color--burnt-sienna);
	animation: cmc-dot-pulse 2s var(--wp--custom--ease) infinite;
}

@keyframes cmc-dot-pulse {
	0%   { transform: scale(1);   opacity: 0.65; }
	70%  { transform: scale(2.6); opacity: 0; }
	100% { transform: scale(2.6); opacity: 0; }
}

.scale-dot__label {
	font-size: var(--wp--preset--font-size--text-11);
	font-weight: 600;
	line-height: 1.3;
	color: var(--wp--preset--color--charcoal);
}

.scale-dot:hover .scale-dot__label,
.scale-dot:focus-visible .scale-dot__label {
	text-decoration: underline;
	text-underline-offset: 3px;
}

/* Statements: the dialog listing a cell's statements */
.scale-dialog {
	width: 92vw;
	max-width: 640px;
	padding: 0;
	border: 0;
	border-radius: var(--wp--custom--radius--card);
	background: var(--wp--preset--color--white);
	color: var(--wp--preset--color--charcoal);
}

.scale-dialog::backdrop {
	background: color-mix(in srgb, var(--wp--preset--color--charcoal) 62%, transparent);
	-webkit-backdrop-filter: blur(3px);
	backdrop-filter: blur(3px);
}

.scale-dialog[open] {
	opacity: 1;
	transform: none;
	transition: opacity 260ms var(--wp--custom--ease), transform 260ms var(--wp--custom--ease);
}

@starting-style {
	.scale-dialog[open] {
		opacity: 0;
		transform: translateY(12px);
	}
}

.cmc-matrix__dialog-inner {
	display: flex;
	flex-direction: column;
	gap: 16px;
	padding: 30px;
}

.cmc-matrix__dialog-head {
	display: flex;
	align-items: flex-start;
	justify-content: space-between;
	gap: 20px;
}

.cmc-matrix__dialog-title {
	margin: 0;
	font-size: var(--wp--preset--font-size--text-6);
	font-weight: 600;
	line-height: 1.2;
}

.cmc-matrix__close {
	flex-shrink: 0;
	margin: 0;
	padding: 5px;
	border: 0;
	border-radius: 9999px;
	background: none;
	color: var(--wp--preset--color--charcoal);
	cursor: pointer;
	transition: background-color 300ms var(--wp--custom--ease);
}

.cmc-matrix__close:hover {
	background-color: var(--wp--preset--color--off-white);
}

.cmc-matrix__dialog-list {
	display: flex;
	flex-direction: column;
	margin: 0;
	padding: 0;
	list-style: none;
}

.cmc-matrix__item {
	display: flex;
	flex-direction: column;
	gap: 3px;
	padding: 15px 0;
	border-top: 1px solid var(--wp--preset--color--greige);
}

.cmc-matrix__item:first-child {
	border-top: 0;
}

.cmc-matrix__item-title {
	width: fit-content;
	font-size: var(--wp--preset--font-size--text-8);
	font-weight: 600;
	line-height: 1.3;
	color: var(--wp--preset--color--charcoal);
}

a.cmc-matrix__item-title {
	text-decoration: underline;
	text-decoration-thickness: 2px;
	text-decoration-color: var(--wp--preset--color--greige);
	text-underline-offset: 4px;
	transition: text-decoration-color 300ms var(--wp--custom--ease);
}

a.cmc-matrix__item-title:hover {
	text-decoration-color: var(--wp--preset--color--charcoal);
}

.cmc-matrix__item-meta {
	font-size: var(--wp--preset--font-size--text-11);
	line-height: 1.3;
	color: color-mix(in srgb, var(--wp--preset--color--charcoal) 70%, transparent);
}

/* "Read Statement": the animated underline (prototype .link-rule) */
.cmc-matrix__item-link {
	position: relative;
	display: inline-flex;
	align-items: center;
	gap: 8px;
	width: fit-content;
	margin-top: 6px;
	font-size: var(--wp--preset--font-size--text-11);
	font-weight: 600;
	line-height: 1.3;
	color: var(--wp--preset--color--charcoal);
	text-decoration: none;
}

.cmc-matrix__item-link::after {
	content: "";
	position: absolute;
	inset-inline: 0;
	bottom: 0;
	height: 2px;
	background: currentColor;
	transform: scaleX(0);
	transform-origin: left center;
	transition: transform 0.35s var(--wp--custom--ease);
}

.cmc-matrix__item-link svg {
	flex-shrink: 0;
	transition: transform 300ms var(--wp--custom--ease);
}

.cmc-matrix__item-link:hover::after,
.cmc-matrix__item-link:focus-visible::after {
	transform: scaleX(1);
}

.cmc-matrix__item-link:hover svg,
.cmc-matrix__item-link:focus-visible svg {
	transform: translateX(3px);
}

@media (prefers-reduced-motion: reduce) {
	.scale-dot__pulse::after {
		animation: none;
		opacity: 0;
	}

	.cmc-matrix__option,
	.cmc-matrix__cell,
	.scale-dialog[open],
	.cmc-matrix__item-link::after,
	.cmc-matrix__item-link svg {
		transition: none;
	}
}
