/**
 * [homewood_stats] — the four-up stat grid.
 *
 * Each card is outlined by the same SVG <rect> the button uses, on the same
 * pathLength="100" trick, so every dash value below is a percentage of the
 * card's perimeter. The outline starts as the bottom edge alone and unwraps
 * forward — up the left side, across the top, down the right — to close.
 *
 * A rounded rect's path begins at the end of the top-left corner and runs
 * clockwise, which puts the start of the bottom edge at exactly half the
 * perimeter on any card, whatever its proportions. Only the length of that
 * edge changes with the card's aspect ratio, and assets/js/stats.js measures
 * it; the default below suits the 4:3 card.
 *
 * Nothing here applies until stats.js adds `is-ready`, so with no JavaScript
 * the cards render fully outlined and fully legible.
 *
 * @package homewood_theme
 */

.hw-stats {
	--hw-stat-ink: var(--wp--preset--color--ink, #252b23);
	--hw-stat-stroke: var(--wp--preset--color--bronze, #896d44);

	--hw-stat-radius: 10px;
	--hw-stat-stroke-width: 2;
	--hw-stat-aspect: 4 / 3;

	--hw-stat-draw-speed: 1.1s;
	--hw-stat-fade-speed: 0.6s;
	--hw-stat-stagger: 0.12s;

	/* Percentages of the outline's perimeter. */
	--hw-stat-edge-start: 50;   /* always half way round — see above */
	--hw-stat-edge-length: 27.7; /* the bottom edge; re-measured by stats.js */

	display: grid;
	grid-template-columns: repeat(2, minmax(0, 1fr));

	/*
	 * Rows size themselves to their own contents otherwise, so a long title on
	 * the second row leaves it taller than the first. 1fr hands every row the
	 * same height, the tallest card's, and the aspect ratio below sets the
	 * floor that height starts from.
	 */
	grid-auto-rows: 1fr;
	gap: clamp(1.25rem, 3vw, 2.5rem);
	margin: 0;
	padding: 0;
	list-style: none;
}

@media (max-width: 40rem) {
	.hw-stats {
		grid-template-columns: minmax(0, 1fr);
	}
}

.hw-stat {
	position: relative;
	z-index: 0;
	display: flex;
	flex-direction: column;
	justify-content: center;
	gap: 1.25rem;
	aspect-ratio: var(--hw-stat-aspect);
	padding: 2rem;
	border-radius: var(--hw-stat-radius);
	color: var(--hw-stat-ink);
}
@media (max-width: 1300px) {
	.about-stats {
		display: block !important;
	}
	.hw-stat {
		
		aspect-ratio: auto;
	}
	.stats-wrapper {
		padding-top: 60px;
	}
}

.hw-stat__value {
	/* 4.5rem once there is room for it; the floor keeps four digits inside a
	   narrow card. */
	font-size: clamp(3rem, 6.5vw, 4.5rem);
	font-weight: 400;
	line-height: 1;
	letter-spacing: -0.02em;
	font-variant-numeric: tabular-nums;
}

.hw-stat__title {
	max-width: 20ch;
	font-size: var(--wp--preset--font-size--body, 1.25rem);
	line-height: 1.3;
	text-wrap: balance;
}

/* -- The outline ---------------------------------------------------------- */

.hw-stat__frame {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	overflow: visible;
	pointer-events: none;
}

.hw-stat__frame rect {
	/* x/y/rx also ship as attributes so the shape survives without CSS. */
	width: calc(100% - 2px);
	height: calc(100% - 2px);
	rx: var(--hw-stat-radius);
	fill: none;
	stroke: var(--hw-stat-stroke);
	stroke-width: var(--hw-stat-stroke-width);
	stroke-dasharray: 100 0;
	stroke-dashoffset: 0;
}

/* -- Entrance ------------------------------------------------------------- */

/*
 * The dash pattern always sums to 100, so its period matches the path and a
 * positive offset of 50 lands the dash on the bottom edge without needing a
 * negative value.
 */
.hw-stats.is-ready .hw-stat__frame rect {
	stroke-dasharray: var(--hw-stat-edge-length) calc(100 - var(--hw-stat-edge-length));
	stroke-dashoffset: var(--hw-stat-edge-start);
}

.hw-stats.is-ready .hw-stat__value {
	opacity: 0;
}

.hw-stats.is-ready .hw-stat.is-in .hw-stat__frame rect {
	animation: hw-stat-wrap var(--hw-stat-draw-speed) ease forwards;
	animation-delay: calc(var(--hw-stat-index, 0) * var(--hw-stat-stagger));
}

/* The value arrives once the outline is most of the way round. */
.hw-stats.is-ready .hw-stat.is-in .hw-stat__value {
	animation: hw-stat-fade var(--hw-stat-fade-speed) ease forwards;
	animation-delay: calc(
		var(--hw-stat-index, 0) * var(--hw-stat-stagger) + var(--hw-stat-draw-speed) * 0.5
	);
}

@keyframes hw-stat-wrap {
	to {
		stroke-dasharray: 100 0;
	}
}

@keyframes hw-stat-fade {
	to {
		opacity: 1;
	}
}

/* -- Stats on dark sections ----------------------------------------------- */

.has-ink-background-color .hw-stats,
.has-forest-background-color .hw-stats,
.has-sage-background-color .hw-stats {
	--hw-stat-ink: var(--wp--preset--color--cream, #f6f1ea);
	--hw-stat-stroke: var(--wp--preset--color--wheat, #c3a87f);
}

/* -- Reduced motion ------------------------------------------------------- */

/*
 * Selectors are paired so each one outweighs the entrance rule it cancels.
 */
@media (prefers-reduced-motion: reduce) {
	.hw-stats.is-ready .hw-stat .hw-stat__frame rect,
	.hw-stats.is-ready .hw-stat.is-in .hw-stat__frame rect {
		stroke-dasharray: 100 0;
		stroke-dashoffset: 0;
		animation: none;
	}

	.hw-stats.is-ready .hw-stat .hw-stat__value,
	.hw-stats.is-ready .hw-stat.is-in .hw-stat__value {
		opacity: 1;
		animation: none;
	}
}
