/*
 * Collection pages: the title area, then the cards (markup from the plugin's
 * tm/run-grouped-grid block). Each card stands alone: a large photo, its name and its
 * price set quietly beneath, no frames or boxes. One column on phones, two from 64em.
 */

.tm-collection {
	position: relative;
	isolation: isolate;
	padding-block-end: clamp(4rem, 9vw, 7rem);
}

/*
 * The home page's gold trellis carried on behind the cards: a repeating tile (the same
 * 72 x 108 lozenges, trellis-tile.svg) shown in the margins either side of the grid and
 * fading in below the title area, so it never sits behind a card. Too narrow for margins
 * (phones and tablets), it does not show.
 */
.tm-collection::before {
	content: "";
	position: absolute;
	inset: 0;
	z-index: -1;
	background: url("../img/trellis-tile.svg") center top / 72px 108px repeat;
	-webkit-mask-image:
		linear-gradient(to right, #000, transparent calc(50% - 36rem), transparent calc(50% + 36rem), #000),
		linear-gradient(to bottom, transparent 18rem, #000 42rem);
	mask-image:
		linear-gradient(to right, #000, transparent calc(50% - 36rem), transparent calc(50% + 36rem), #000),
		linear-gradient(to bottom, transparent 18rem, #000 42rem);
	-webkit-mask-composite: source-in;
	mask-composite: intersect;
	pointer-events: none;
}

.tm-collection--christmas {
	background-color: var(--tm-evergreen);
}

/* ---------- Title area ---------- */

.tm-collection-hero {
	position: relative;
	isolation: isolate;
	display: grid;
	place-items: center;
	box-sizing: border-box;
	min-height: clamp(15rem, 32vw, 26rem);
	padding: clamp(3rem, 7vw, 5rem) var(--tm-gutter);
	overflow: hidden;
	background-color: var(--tm-evergreen);
	color: var(--tm-white);
	text-align: center;
}

.tm-collection-hero--plain {
	min-height: 0;
}

.tm-collection-hero__img {
	position: absolute;
	inset: 0;
	z-index: -2;
	width: 100%;
	height: 100%;
	object-fit: cover;
	object-position: center 45%;
}

/* The one overlay: night at 55%, so white type reads over any photo. (Drawn as the night
   token at 55% opacity rather than an rgba colour, so the palette stays the seven tokens.) */
.tm-collection-hero__overlay {
	position: absolute;
	inset: 0;
	z-index: -1;
	background-color: var(--tm-night);
	opacity: 0.55;
}

/*
 * The picture fades into the evergreen of the cards below over the title area's lower half,
 * so the title and the cards read as one dark surface rather than a band with a hard edge.
 */
.tm-collection-hero::after {
	content: "";
	position: absolute;
	inset: auto 0 0;
	z-index: -1;
	height: 55%;
	background-image: linear-gradient(to bottom, transparent, var(--tm-evergreen) 90%);
	pointer-events: none;
}

.tm-collection-hero__inner {
	max-width: 64rem;
}

.tm-collection-hero__title {
	margin: 0;
	font-family: var(--tm-font-display);
	font-size: var(--wp--preset--font-size--display);
	font-weight: 400;
	line-height: 1.1;
	letter-spacing: 0.06em;
}

/* A gold hairline under the name, as under every page title. */
.tm-collection-hero__title::after {
	content: "";
	display: block;
	width: 4.5rem;
	height: 0;
	margin: 1.25rem auto 0;
	border-top: 1px solid var(--tm-gold);
}

.tm-collection-hero--image .tm-collection-hero__title {
	text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 4px 24px rgba(0, 0, 0, 0.25);
}

.tm-collection-hero__description {
	margin-block-start: 1.25rem;
	font-size: var(--wp--preset--font-size--large);
}

.tm-collection-hero__description > :last-child {
	margin-block-end: 0;
}

/* ---------- The grid ---------- */

.tm-grid {
	box-sizing: border-box;
	max-width: 70rem;
	margin: clamp(3rem, 7vw, 5.5rem) auto 0;
	padding-inline: var(--tm-gutter);
}

.tm-pieces {
	display: grid;
	grid-template-columns: minmax(0, 1fr);
	row-gap: clamp(3rem, 7vw, 5rem);
	margin: 0;
	padding: 0;
	list-style: none;
}

/* One column on a tablet: keep each card a comfortable size rather than the full width. */
@media (min-width: 48em) and (max-width: 63.99em) {
	.tm-grid {
		max-width: calc(34rem + 2 * var(--tm-gutter));
	}
}

@media (min-width: 64em) {
	.tm-pieces {
		grid-template-columns: repeat(2, minmax(0, 1fr));
		column-gap: clamp(3rem, 6vw, 6rem);
	}

	/* Collection pages and the shop show three cards in a row, so a large collection needs less scrolling. */
	.tm-grid--grid .tm-pieces {
		grid-template-columns: repeat(3, minmax(0, 1fr));
		column-gap: clamp(2rem, 3.5vw, 3.5rem);
	}

	.tm-grid--grid {
		max-width: 78rem;
	}
}

.tm-grid__empty {
	text-align: center;
}

/* ---------- One card ---------- */

.tm-piece__link {
	display: block;
	color: var(--tm-white);
	text-decoration: none;
}

.tm-piece__link:focus-visible {
	outline-offset: 8px;
}

.tm-piece__media {
	position: relative;
	display: block;
	aspect-ratio: 5 / 7;
	overflow: hidden;
	background-color: var(--tm-moss);
	box-shadow: var(--tm-shadow);
}

.tm-piece__img,
.tm-piece__placeholder {
	position: absolute;
	inset: 0;
	display: block;
	width: 100%;
	height: 100%;
	object-fit: cover;
}

.tm-piece__title {
	margin: 1.5rem 0 0;
	font-family: var(--tm-font-display);
	font-size: var(--wp--preset--font-size--large);
	font-weight: 400;
	line-height: 1.3;
	letter-spacing: 0.04em;
	text-decoration-line: underline;
	text-decoration-color: transparent;
	text-decoration-thickness: 1px;
	text-underline-offset: 0.25em;
	transition: text-decoration-color 160ms ease;
}

.tm-piece__link:hover .tm-piece__title,
.tm-piece__link:focus-visible .tm-piece__title {
	text-decoration-color: var(--tm-gold);
}

.tm-piece__price,
.tm-piece__sold {
	margin: 0.4rem 0 0;
	font-size: var(--wp--preset--font-size--body);
	line-height: 1.6;
}

.tm-piece__price del {
	opacity: 0.75;
}

.tm-piece__price ins {
	text-decoration: none;
}

.tm-piece__sold {
	font-style: italic;
}

/*
 * A card still waiting for its photo: the placeholder (moss, double gold hairline) cut to the
 * cartouche, like the home page's hero card, with a shadow that follows the cut corners.
 */
.tm-piece__media:has(.tm-piece__img--placeholder) {
	overflow: visible;
	background-color: transparent;
	box-shadow: none;
	filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.3)) drop-shadow(0 16px 32px rgba(0, 0, 0, 0.28));
}

.tm-piece__img--placeholder {
	clip-path: var(--tm-cartouche);
}

/*
 * A Christmas card with its photo is cut like the home page's hero card: the photo covers the
 * whole card, its corners are cut to the cartouche and the shadow follows the cut. There is
 * no border over the photo itself.
 */
.tm-piece--framed .tm-piece__media:has(.tm-piece__img:not(.tm-piece__img--placeholder)) {
	overflow: visible;
	background-color: transparent;
	box-shadow: none;
	filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.3)) drop-shadow(0 16px 32px rgba(0, 0, 0, 0.28));
}

.tm-piece--framed .tm-piece__img:not(.tm-piece__img--placeholder) {
	clip-path: var(--tm-cartouche);
}

/* Sold cards stay in full colour, only a little quieter. */
.tm-piece--sold .tm-piece__img {
	opacity: 0.7;
}

/*
 * The second photo, shown on hover or keyboard focus. Only where there is a real hover and
 * motion is welcome; elsewhere it is not displayed. Its file is only fetched on the first
 * hover or focus (the block's view script), and it stays hidden until it has one.
 */
.tm-piece__img--alt {
	display: none;
}

@media (hover: hover) and (prefers-reduced-motion: no-preference) {
	.tm-piece__img--alt {
		display: block;
		opacity: 0;
		transition: opacity 450ms ease;
	}

	.tm-piece__link:hover .tm-piece__img--alt[src],
	.tm-piece__link:focus-visible .tm-piece__img--alt[src] {
		opacity: 1;
	}

	.tm-piece--sold .tm-piece__link:hover .tm-piece__img--alt[src],
	.tm-piece--sold .tm-piece__link:focus-visible .tm-piece__img--alt[src] {
		opacity: 0.7;
	}
}

/* ---------- Runs ---------- */

.tm-run + .tm-run {
	margin-block-start: clamp(5rem, 10vw, 8rem);
}

.tm-run__head {
	margin-block-end: clamp(2rem, 4vw, 3rem);
}

.tm-run__name {
	margin: 0;
	font-family: var(--tm-font-display);
	font-size: var(--wp--preset--font-size--x-large);
	font-weight: 400;
	letter-spacing: 0.05em;
}

.tm-run__count {
	margin: 0.5rem 0 0;
	font-family: var(--tm-font-serif-display);
	font-size: var(--wp--preset--font-size--large);
	font-style: italic;
}

/* ---------- Shop page: every collection in turn ---------- */

.tm-grid__collection + .tm-grid__collection {
	margin-block-start: clamp(5rem, 10vw, 8rem);
	padding-block-start: clamp(3rem, 6vw, 4.5rem);
	border-top: 1px solid var(--tm-gold);
}

.tm-grid__collection-name {
	margin: 0 0 clamp(2rem, 4vw, 3rem);
	font-size: var(--wp--preset--font-size--xx-large);
}

.tm-grid__collection-name a {
	color: var(--tm-white);
	text-decoration: none;
}

.tm-grid__collection-name a:hover {
	text-decoration: underline;
	text-decoration-color: var(--tm-gold);
}

.tm-grid__collection .tm-run__name {
	font-size: var(--wp--preset--font-size--large);
}

/* ---------- Staggered layout (the block's layout "staggered", used on the home page) ---------- */

/*
 * Two columns with the right-hand column set lower, like prints laid on a table. The offset
 * is a transform, so the rows still line up for reading order; the list keeps room for it at
 * the bottom. Phones and tablets keep the single column.
 */
@media (min-width: 64em) {
	.tm-grid--staggered {
		--tm-stagger: clamp(7rem, 13vw, 12rem);
	}

	.tm-grid--staggered .tm-pieces {
		padding-block-end: var(--tm-stagger);
		column-gap: clamp(4rem, 8vw, 8rem);
	}

	.tm-grid--staggered .tm-piece:nth-child(even) {
		transform: translateY(var(--tm-stagger));
	}
}
