/*
 * APR data graphics: shared tokens and components.
 * Rules and reasons are in STYLE.md. Graphics use the role tokens below,
 * never raw hex, so light and dark switch in one place.
 */

:root {
	color-scheme: light;

	/* Type: the same Adobe Fonts kit as alreporter.com, with system fallbacks. */
	--g-font-sans: halyard-text-variable, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
	--g-font-headline: marlide-display-variable, ui-serif, Georgia, Cambria, "Times New Roman", serif;

	/*
	 * The panel fills the whole graphic, so it reads as a figure and not as story text.
	 * --g-bg is for controls and tooltips that sit on the panel.
	 */
	--g-panel: #f4f4f5;
	--g-bg: #ffffff;
	--g-hover: #e4e4e7;
	--g-ink: #27272a;
	--g-ink-strong: #18181b;
	--g-muted: #71717a;
	--g-rule: #d4d4d8;
	--g-grid: #d4d4d8;
	--g-axis: #a1a1aa;
	--g-highlight: #18181b;

	/* Parties: identical to the live election-results pages. Reserved for parties. */
	--g-dem: #1674ed;
	--g-rep: #e53935;
	--g-other-party: #71717a;

	/* Nonpartisan categories, in this order. Never cycled; past six, fold into "Other". */
	--g-cat-1: #6250d6; /* violet */
	--g-cat-2: #008300; /* green */
	--g-cat-3: #e87ba4; /* magenta */
	--g-cat-4: #eda100; /* yellow */
	--g-cat-5: #1baf7a; /* aqua */
	--g-cat-6: #eb6834; /* orange */

	/* Map ramps in party hues: four bins, step 1 (least) to 4 (most). */
	--g-dem-1: #82b0f3;
	--g-dem-2: #478cf0;
	--g-dem-3: #0f69da;
	--g-dem-4: #024da8;
	--g-rep-1: #eb9288;
	--g-rep-2: #e05e54;
	--g-rep-3: #c52c29;
	--g-rep-4: #971b1a;
	/* Diverging midpoint (even or no change) and missing data. */
	--g-neutral: #d4d4d8;
	--g-empty: #e4e4e7;
}

/* Dark: the reader's site theme wins (sent by the article page), then the OS setting. */
@media (prefers-color-scheme: dark) {
	:root:not([data-theme="light"]) {
		color-scheme: dark;
		--g-panel: #27272a;
		--g-bg: #18181b;
		--g-hover: #3f3f46;
		--g-ink: #f4f4f5;
		--g-ink-strong: #ffffff;
		--g-muted: #a1a1aa;
		--g-rule: #52525b;
		--g-grid: #52525b;
		--g-axis: #71717a;
		--g-highlight: #ffffff;
		--g-dem: #4d9aff;
		--g-rep: #ff625b;
		--g-other-party: #a1a1aa;
		--g-cat-1: #9085e9;
		--g-cat-2: #008300;
		--g-cat-3: #d55181;
		--g-cat-4: #c98500;
		--g-cat-5: #199e70;
		--g-cat-6: #d95926;
		--g-dem-1: #265eae;
		--g-dem-2: #367ee3;
		--g-dem-3: #6aa2f5;
		--g-dem-4: #a4c6f8;
		--g-rep-1: #a13832;
		--g-rep-2: #d24d45;
		--g-rep-3: #ea7e73;
		--g-rep-4: #f4b1a8;
		--g-neutral: #52525b;
		--g-empty: #3f3f46;
	}
}

:root[data-theme="dark"] {
	color-scheme: dark;
	--g-panel: #27272a;
	--g-bg: #18181b;
	--g-hover: #3f3f46;
	--g-ink: #f4f4f5;
	--g-ink-strong: #ffffff;
	--g-muted: #a1a1aa;
	--g-rule: #52525b;
	--g-grid: #52525b;
	--g-axis: #71717a;
	--g-highlight: #ffffff;
	--g-dem: #4d9aff;
	--g-rep: #ff625b;
	--g-other-party: #a1a1aa;
	--g-cat-1: #9085e9;
	--g-cat-2: #008300;
	--g-cat-3: #d55181;
	--g-cat-4: #c98500;
	--g-cat-5: #199e70;
	--g-cat-6: #d95926;
	--g-dem-1: #265eae;
	--g-dem-2: #367ee3;
	--g-dem-3: #6aa2f5;
	--g-dem-4: #a4c6f8;
	--g-rep-1: #a13832;
	--g-rep-2: #d24d45;
	--g-rep-3: #ea7e73;
	--g-rep-4: #f4b1a8;
	--g-neutral: #52525b;
	--g-empty: #3f3f46;
}

*,
*::before,
*::after {
	box-sizing: border-box;
}

html,
body {
	margin: 0;
	background: var(--g-panel);
	color: var(--g-ink);
	font-family: var(--g-font-sans);
	font-size: 16px;
	line-height: 1.5;
	-webkit-font-smoothing: antialiased;
	-moz-osx-font-smoothing: grayscale;
	text-size-adjust: 100%;
}

/* The graphic is the whole document; the panel color fills the frame edge to edge. */
.g {
	margin: 0;
	padding: 1.25rem 1.25rem 1rem;
}

@media (max-width: 480px) {
	.g {
		padding: 1rem 1rem 0.875rem;
	}
}

.g :focus-visible {
	outline: 2px solid var(--g-ink-strong);
	outline-offset: 2px;
}

/* Header ---------------------------------------------------------------- */

.g-hed {
	margin: 0;
	color: var(--g-ink-strong);
	font-family: var(--g-font-headline);
	font-size: clamp(1.25rem, 1rem + 1.1vw, 1.625rem);
	font-weight: 700;
	letter-spacing: -0.01em;
	line-height: 1.15;
	text-wrap: balance;
}

.g-dek {
	margin: 0.375rem 0 0;
	max-width: 40rem;
	color: var(--g-ink);
	font-size: 0.9375rem;
	line-height: 1.45;
	text-wrap: pretty;
}

/* Stat row: one label, one value. -------------------------------------- */

.g-stats {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(6rem, 1fr));
	gap: 0.75rem 1rem;
	margin: 1rem 0 0;
	padding: 0;
	list-style: none;
}

.g-stat {
	padding-top: 0.5rem;
	border-top: 1px solid var(--g-rule);
}

.g-stat-label {
	display: block;
	color: var(--g-muted);
	font-size: 0.8125rem;
	line-height: 1.3;
}

.g-stat-value {
	display: block;
	margin-top: 0.125rem;
	color: var(--g-ink-strong);
	font-size: clamp(1.25rem, 0.9rem + 1.6vw, 1.625rem);
	font-weight: 650;
	letter-spacing: -0.02em;
	line-height: 1.1;
}

/* Legend ---------------------------------------------------------------- */

.g-legend {
	margin: 1.25rem 0 0;
}

.g-legend-title {
	margin: 0 0 0.375rem;
	color: var(--g-ink);
	font-size: 0.8125rem;
	font-weight: 600;
	line-height: 1.3;
}

.g-legend-steps {
	display: flex;
	gap: 2px;
	margin: 0;
	padding: 0;
	list-style: none;
}

/* Centered over a centered chart, such as a state map. */
.g-legend-centered {
	text-align: center;
}

.g-legend-centered .g-legend-steps {
	justify-content: center;
}

.g-legend-steps li {
	flex: 1 1 0;
	max-width: 4.5rem;
	color: var(--g-muted);
	font-size: 0.75rem;
	font-variant-numeric: tabular-nums;
	line-height: 1.2;
	white-space: nowrap;
}

.g-legend-steps li::before {
	display: block;
	height: 0.625rem;
	margin-bottom: 0.25rem;
	background: var(--swatch);
	content: "";
}

.g-legend-steps li:first-child::before {
	border-radius: 2px 0 0 2px;
}

.g-legend-steps li:last-child::before {
	border-radius: 0 2px 2px 0;
}

.g-key {
	display: flex;
	flex-wrap: wrap;
	gap: 0.25rem 1rem;
	margin: 0;
	padding: 0;
	list-style: none;
	color: var(--g-ink);
	font-size: 0.8125rem;
}

.g-key li {
	display: inline-flex;
	align-items: center;
	gap: 0.375rem;
}

.g-key li::before {
	width: 0.625rem;
	height: 0.625rem;
	border-radius: 50%;
	background: var(--swatch);
	content: "";
}

/* Map ------------------------------------------------------------------- */

.g-map {
	position: relative;
	margin-top: 0.75rem;
}

.g-map svg {
	display: block;
	width: 100%;
	overflow: visible;
}

/* The panel-colored stroke is the gap between counties; no outlines. */
.g-map path {
	stroke: var(--g-panel);
	stroke-width: 1;
	stroke-linejoin: round;
	vector-effect: non-scaling-stroke;
}

.g-map path.is-active {
	stroke: var(--g-highlight);
	stroke-width: 2;
}

/* Callouts: a few labeled places, joined to the map by thin leader lines.
   The panel-colored halo keeps them legible where they overlap the map on phones. */
.g-callout-name,
.g-callout-value {
	paint-order: stroke;
	stroke: var(--g-panel);
	stroke-width: 3px;
	stroke-linejoin: round;
}

.g-callout-name {
	fill: var(--g-ink);
	font-family: var(--g-font-sans);
	font-weight: 600;
}

.g-callout-value {
	fill: var(--g-ink-strong);
	font-family: var(--g-font-sans);
	font-weight: 700;
	letter-spacing: -0.01em;
}

.g-map .g-leader {
	fill: none;
	stroke: var(--g-ink);
	stroke-opacity: 0.7;
	stroke-width: 1;
}

.g-dot {
	fill: var(--g-ink-strong);
	stroke: var(--g-panel);
	stroke-width: 1.5;
}

.g-callouts {
	pointer-events: none;
}

/* Tooltip: values lead, labels follow. Never the only place a value lives. */
.g-tooltip {
	position: absolute;
	z-index: 10;
	min-width: 11rem;
	max-width: 16rem;
	padding: 0.5rem 0.625rem;
	border: 1px solid var(--g-rule);
	border-radius: 0.375rem;
	background: var(--g-bg);
	box-shadow: 0 4px 16px rgb(0 0 0 / 0.12);
	color: var(--g-ink);
	font-size: 0.8125rem;
	line-height: 1.35;
	pointer-events: none;
}

.g-tooltip[hidden] {
	display: none;
}

.g-tooltip-title {
	margin: 0 0 0.25rem;
	color: var(--g-ink-strong);
	font-weight: 650;
}

.g-tooltip dl {
	display: grid;
	grid-template-columns: auto auto;
	gap: 0.125rem 0.75rem;
	margin: 0;
}

.g-tooltip dt {
	color: var(--g-muted);
}

.g-tooltip dd {
	margin: 0;
	color: var(--g-ink-strong);
	font-variant-numeric: tabular-nums;
	font-weight: 600;
	text-align: right;
	white-space: nowrap;
}

/* Buttons and disclosure -------------------------------------------------- */

.g-button {
	display: inline-flex;
	align-items: center;
	gap: 0.375rem;
	min-height: 2.25rem;
	padding: 0.375rem 0.875rem;
	border: 1px solid var(--g-axis);
	border-radius: 0.375rem;
	background: var(--g-bg);
	color: var(--g-ink-strong);
	font: inherit;
	font-size: 0.875rem;
	font-weight: 600;
	cursor: pointer;
}

.g-button:hover {
	border-color: var(--g-ink);
}

.g-button[aria-expanded]::after {
	content: "▾";
	font-size: 0.75rem;
}

.g-button[aria-expanded="true"]::after {
	content: "▴";
}

/* Table: every value, opened on request. ----------------------------------- */

.g-data {
	margin-top: 1rem;
}

.g-data[hidden] {
	display: none;
}

.g-table-tools {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: 0.5rem;
	margin-bottom: 0.5rem;
}

.g-search {
	width: min(100%, 14rem);
	min-height: 2.25rem;
	padding: 0.375rem 0.625rem;
	border: 1px solid var(--g-axis);
	border-radius: 0.375rem;
	background: var(--g-bg);
	color: var(--g-ink);
	font: inherit;
	font-size: 0.875rem;
}

.g-search::placeholder {
	color: var(--g-muted);
}

.g-table {
	width: 100%;
	border-collapse: collapse;
	font-size: 0.875rem;
	line-height: 1.35;
}

.g-table th,
.g-table td {
	padding: 0.4375rem 0.5rem;
	border-bottom: 1px solid var(--g-rule);
	text-align: right;
	vertical-align: middle;
	white-space: nowrap;
}

.g-table :is(th, td):first-child {
	padding-left: 0;
	text-align: left;
}

.g-table :is(th, td):last-child {
	padding-right: 0;
}

.g-table thead th {
	border-bottom: 1px solid var(--g-axis);
	color: var(--g-muted);
	font-size: 0.75rem;
	font-weight: 600;
	vertical-align: bottom;
	white-space: normal;
}

.g-table tbody th {
	color: var(--g-ink-strong);
	font-weight: 600;
}

.g-table td {
	font-variant-numeric: tabular-nums;
}

.g-table tbody tr.is-active {
	background: var(--g-hover);
}

.g-sort {
	display: inline-flex;
	align-items: center;
	gap: 0.25rem;
	padding: 0;
	border: 0;
	background: none;
	color: inherit;
	font: inherit;
	text-align: inherit;
	cursor: pointer;
}

.g-sort::after {
	flex: none;
	width: 0.875rem;
	color: var(--g-ink-strong);
	content: "";
	text-align: center;
}

.g-sort[aria-sort-dir="descending"]::after {
	content: "↓";
}

.g-sort[aria-sort-dir="ascending"]::after {
	content: "↑";
}

/* Inline bar: 4px rounded data end, square at the baseline, never fills the cell. */
.g-bar-cell {
	display: inline-flex;
	align-items: center;
	justify-content: flex-end;
	gap: 0.5rem;
	width: 100%;
}

.g-bar {
	display: block;
	width: 4.5rem;
	height: 0.625rem;
}

.g-bar span {
	display: block;
	height: 100%;
	border-radius: 0 4px 4px 0;
	background: var(--bar, var(--g-dem));
}

.g-bar-value {
	min-width: 3.25rem;
	color: var(--g-ink-strong);
	font-weight: 600;
}

@media (max-width: 400px) {
	.g-bar {
		display: none;
	}
}

.g-status {
	margin: 0.5rem 0 0;
	color: var(--g-muted);
	font-size: 0.8125rem;
}

/* Footer: one short note, then sources behind a toggle. -------------------- */

.g-footer {
	display: flex;
	align-items: flex-end;
	justify-content: space-between;
	gap: 1rem;
	margin-top: 1rem;
	color: var(--g-muted);
	font-size: 0.75rem;
	line-height: 1.45;
}

.g-footer-text {
	flex: 1 1 auto;
	min-width: 0;
}

.g-note {
	margin: 0;
}

.g-sources {
	margin-top: 0.25rem;
}

.g-sources > summary {
	display: inline-block;
	color: var(--g-ink);
	font-weight: 600;
	list-style: none;
	cursor: pointer;
}

.g-sources > summary::-webkit-details-marker {
	display: none;
}

.g-sources > summary::after {
	margin-left: 0.25rem;
	content: "▾";
}

.g-sources[open] > summary::after {
	content: "▴";
}

.g-sources-panel {
	margin-top: 0.375rem;
}

.g-sources-panel p {
	margin: 0 0 0.25rem;
}

/* The APR monogram, drawn in ink like the site header (a mask, so it follows the theme). */
.g-logo {
	display: block;
	flex: none;
	height: 1.125rem;
	aspect-ratio: 511.94 / 232.8;
	background: var(--g-ink-strong);
	-webkit-mask: url("/shared/monogram.svg") center / contain no-repeat;
	mask: url("/shared/monogram.svg") center / contain no-repeat;
}

.g-logo:hover {
	background: var(--g-ink);
}

@media (forced-colors: active) {
	.g-logo {
		background: CanvasText;
	}
}

.g-footer a {
	color: inherit;
	text-decoration: underline;
	text-underline-offset: 0.15em;
}

.g-footer a:hover {
	color: var(--g-ink-strong);
}

.g-visually-hidden {
	position: absolute;
	width: 1px;
	height: 1px;
	overflow: hidden;
	clip: rect(0 0 0 0);
	white-space: nowrap;
}

@media (prefers-reduced-motion: reduce) {
	.g * {
		transition: none !important;
	}
}

@media (forced-colors: active) {
	.g-bar span,
	.g-legend-steps li::before {
		forced-color-adjust: none;
	}
}
