/**
 * Shared blocks: section head, project tiles, filter chips.
 *
 * Extracted from templates/home.css, which is loaded ONLY on the front page.
 * These three blocks are not home-page furniture — the project index, the
 * What We Make pages and flexible pages all render tiles and chips — so on
 * every page except the home page they had NO grid CSS at all. The projects
 * index stacked ten tiles in one 1256px-wide column instead of a two-column
 * grid, which made that page 3,499px taller than the design.
 *
 * home.css said this in its own opening comment: "Blocks that later appear on
 * other templates will move to assets/css/blocks/ as those are built." They
 * were built; the move never happened. This is that move.
 */

/* ---------------------------------------------------------------------------
 * Section head — H2 left, arrow link right
 * ------------------------------------------------------------------------- */
.cmn-section-head {
	display: flex;
	flex-wrap: wrap;
	align-items: baseline;
	justify-content: space-between;
	gap: var(--cmn-space-2);
	margin-bottom: var(--cmn-space-4);
}

.cmn-arrow-link {
	font-weight: 600;
	/* Underlined at rest, as in the design. The hover simply keeps it. */
	text-decoration: underline;
	text-underline-offset: var(--cmn-underline-offset);
}

.cmn-arrow-link:hover {
	text-decoration-thickness: 2px;
}

/* ---------------------------------------------------------------------------
 * C-PROJECTS + C-TILE
 * ------------------------------------------------------------------------- */
/*
 * THREE columns, not two.
 *
 * Measured off the design: six tiles in two rows of three, 421px wide with a
 * 28px gap inside the 1320px container. The build used two columns, which made
 * each tile 612px, every image half as big again as drawn, and the whole
 * section 914px taller than the design — the single largest layout difference
 * on the homepage.
 */
.cmn-work__grid {
	display: grid;
	grid-template-columns: repeat(3, minmax(0, 1fr));
	gap: 28px;
	scroll-margin-top: var(--cmn-scroll-offset);
}

/*
 * On the Projects / services index the card grid sits straight under the page
 * head, which already carries a 40px bottom pad — the design leaves it at that.
 * The grid's own 80px top pad doubled the gap to 120px, so drop it when the
 * grid directly follows the head.
 */
.cmn-main--index .cmn-page-head + .cmn-work {
	padding-top: 0;
}

/*
 * The Projects grid has no visible heading (the design starts straight on the
 * cards), so its section head holds only a screen-reader-only title. Drop its
 * bottom margin, which was adding 32px on top of the 40px gap above.
 */
.cmn-main--index .cmn-page-head + .cmn-work .cmn-section-head {
	margin-bottom: 0;
}

@media (max-width: 1199px) {
	.cmn-work__grid {
		grid-template-columns: repeat(2, minmax(0, 1fr));
	}
}

@media (max-width: 767px) {
	.cmn-work__grid {
		grid-template-columns: minmax(0, 1fr);
	}
}

/*
 * For the Trade shows its "Projects with design teams" row four across, where
 * Home's "Selected projects" row is three. Scoped to the page and to the wide
 * breakpoint so the tablet/phone stacking above still applies.
 */
@media (min-width: 1200px) {
	.page-id-20 .cmn-work__grid {
		grid-template-columns: repeat(4, minmax(0, 1fr));
	}
}

.cmn-tile {
	display: flex;
	flex-direction: column;
	gap: var(--cmn-space-2);
	color: inherit;
	text-decoration: none;
}

.cmn-tile__media {
	display: block;
	overflow: hidden;
	aspect-ratio: 4 / 3;
}

.cmn-tile__image {
	width: 100%;
	height: 100%;
	object-fit: cover;
	transition: transform 0.9s cubic-bezier(0.2, 0.7, 0.2, 1);
}

.cmn-tile:hover .cmn-tile__image,
.cmn-tile:focus-visible .cmn-tile__image {
	transform: scale(1.05);
}

.cmn-tile__body {
	display: flex;
	flex-direction: column;
	gap: 4px;
}

.cmn-tile__title {
	margin: 0;
	font-family: var(--cmn-font-display);
	font-size: var(--cmn-h3);
	font-weight: 500;
	line-height: 1.2;
}

/*
 * A wider tile takes a larger title.
 *
 * The design uses 26px in the three-column grid on the home page and 28px in
 * the two-column grid on the project index — the same block, scaled to the
 * tile. Both were 26px here, which left every title on the index a size small.
 */
.cmn-work__grid--2col .cmn-tile__title {
	font-size: 28px;
}

.cmn-tile__meta {
	font-size: var(--cmn-small);
	color: var(--cmn-caption);
}

/*
 * The design reveals this on hover only. Hiding it from keyboard users would
 * be a 1.4.13 / focus-visibility problem, so it also appears on focus — and
 * it is never the only affordance, because the whole tile is the link.
 */
.cmn-tile__more {
	/* 13px in the design, not --cmn-small (14px). */
	font-size: 13px;
	font-weight: 600;
	color: var(--cmn-forest);
	/*
	 * Hover-revealed on the home "Selected projects" row and the Projects index,
	 * as the design draws those (the label sits at opacity 0 at rest). The What
	 * We Make "in our projects" cards show it at rest instead — see the override
	 * below. Touch devices always see it (hover: none block).
	 */
	opacity: 0;
	transform: translateY(6px);
	transition: opacity 0.4s ease, transform 0.4s ease;
}

.cmn-tile:hover .cmn-tile__more,
.cmn-tile:focus-visible .cmn-tile__more {
	opacity: 1;
	transform: none;
}

/*
 * The What We Make "in our projects" cards show "View project" at rest — the
 * design sets it as a plain always-on label there, not the hover-revealed one
 * the home and Projects grids use.
 */
.cmn-main--wwm .cmn-work__grid .cmn-tile__more {
	opacity: 1;
	transform: none;
}

@media (prefers-reduced-motion: reduce) {
	.cmn-tile__image,
	.cmn-tile__more {
		transition: none;
	}

	.cmn-tile:hover .cmn-tile__image {
		transform: none;
	}
}

/* Touch devices have no hover, so the label must simply be present. */
@media (hover: none) {
	.cmn-tile__more {
		opacity: 1;
		transform: none;
	}
}

/* ---------------------------------------------------------------------------
 * C-FILTER chips
 * ------------------------------------------------------------------------- */
.cmn-chips {
	display: flex;
	flex-wrap: wrap;
	gap: var(--cmn-space-1);
	margin-bottom: 28px;
}

.cmn-chip {
	display: inline-flex;
	align-items: center;
	/* 44px, the design's own floor for chips — see the note below. */
	min-height: 44px;
	padding: 10px 18px;
	border: 1px solid var(--cmn-field-border);
	background: var(--cmn-white);
	color: var(--cmn-charcoal);
	/* 13px/500 in the design, not --cmn-small (14px) at 600. */
	font-size: 13px;
	font-weight: 500;
	text-decoration: none;
}

/*
 * Three chip sets. Same box in all three — padding 10px 18px, a 1px rule, a
 * 44px floor — differing only in text size and, for one of them, leading:
 *
 *   home project filter  13px/500, inherited leading   43px tall
 *   FAQ topic jumps      14px/600, inherited leading    45px tall
 *   Journal topic filter 14px/600, line-height: normal  44px tall
 *
 * The heights are what the design measures, and the 1px spread between the
 * last two is the package's own: both sets are drawn identically except that
 * the Journal's carry line-height: normal. Rather than average them, each
 * matches its own page.
 *
 * The 44px floor is the chips' own, not --cmn-btn-min-h (42px). The design
 * sets min-height: 44px on these and leaves its buttons at 42px, and chips in
 * a wrapping row benefit from the larger target anyway (WCAG 2.5.8 asks 24px).
 */
.cmn-faq__jump .cmn-chip,
.cmn-chips--topics .cmn-chip {
	font-size: 14px;
	font-weight: 600;
}

.cmn-chips--topics .cmn-chip {
	line-height: normal;
}

/*
 * Active state carries a weight change and an inset rule as well as the fill,
 * so it is not conveyed by colour alone (WCAG 1.4.1). The design used fill
 * only, with no state attribute at all.
 *
 * Selector is [aria-current], NOT [aria-pressed]. Phase 5 finding A1 changed
 * these chips from aria-pressed="true" to aria-current="page" — aria-pressed
 * is invalid on an anchor — and the CSS was never updated to match. The result
 * was an active chip with no styling at all: every chip looked identical and
 * nothing showed which filter was applied. Both attributes are matched below
 * so the rule cannot silently detach again if the markup changes.
 */
.cmn-chip[aria-current],
.cmn-chip[aria-pressed="true"] {
	background: var(--cmn-forest);
	border-color: var(--cmn-forest);
	color: var(--cmn-white);
	/*
	 * Solid forest fill with white text, matching the design exactly — no moss
	 * underline. The active chip is still not signalled by colour alone: it is a
	 * filled dark box against outlined light boxes (a figure/ground inversion
	 * that reads in greyscale and for colour-blind users), and it is 600 against
	 * the 500 resting weight. An earlier version added an inset moss underline
	 * as a belt-and-braces 1.4.1 cue, but it read as a two-tone chip and did not
	 * match the design, and the inversion already satisfies 1.4.1.
	 */
	font-weight: 600;
}

.cmn-chip:hover {
	border-color: var(--cmn-forest);
	color: var(--cmn-forest);
}

.cmn-chip[aria-current]:hover,
.cmn-chip[aria-pressed="true"]:hover {
	color: var(--cmn-white);
}

/* Hidden by the client-side filter. */
.cmn-tile[hidden] {
	display: none;
}

@media (max-width: 767px) {
	/* One row that scrolls sideways, as drawn. The region scrolls, the page
	   does not — which keeps 1.4.10 Reflow satisfied at 320px. */
	.cmn-chips {
		flex-wrap: nowrap;
		overflow-x: auto;
		margin-inline: calc(var(--cmn-gutter-sm) * -1);
		padding-inline: var(--cmn-gutter-sm);
		scrollbar-width: none;
	}

	.cmn-chip {
		flex: 0 0 auto;
	}
}


/*
 * The projects index is TWO columns, not three.
 *
 * Measured off the design: index tiles are 646px wide with a 40px/28px gap,
 * against 421px in the home-page tile row. Both use .cmn-work__grid, so the
 * index carries a modifier.
 */
.cmn-work__grid--2col {
	grid-template-columns: repeat(2, minmax(0, 1fr));
	gap: 40px 28px;
}

@media (max-width: 767px) {
	.cmn-work__grid--2col {
		grid-template-columns: minmax(0, 1fr);
	}
}

.cmn-work__grid--3col {
	grid-template-columns: repeat(3, minmax(0, 1fr));
	gap: 28px;
}

@media (max-width: 1199px) {
	.cmn-work__grid--3col {
		grid-template-columns: repeat(2, minmax(0, 1fr));
	}
}

@media (max-width: 767px) {
	.cmn-work__grid--3col {
		grid-template-columns: minmax(0, 1fr);
	}
}
