/**
 * Gallery — the photograph wall between the bands.
 *
 * Four columns on the ink ground, with a row height that tracks the column
 * width so no photograph is ever asked for a shape it does not have. One
 * hero tile takes two columns and two rows, three stand two rows tall, one
 * runs two columns wide, and the four remaining tiles fill what is left;
 * the order in the template is chosen so grid-auto-flow: dense packs the
 * nine into a complete four-by-four block with no holes — at two columns
 * it packs just as tightly into eight rows.
 *
 * Each tile carries two scrims: a warm oxblood-to-gold veil that lifts on
 * hover, and a constant ink foot so the caption stays readable either way.
 * Captions are real markup in the figcaption — nothing here is CSS content.
 */

.bh-gallery {
	background: var(--bh-ink);
	padding-block: 5.5rem;
}

.bh-gallery__lede {
	max-width: 64ch;
	margin: -1.2rem auto 3rem;
	color: var(--bh-text);
	text-align: center;
}

/* The mosaic ---------------------------------------------------------- */

.bh-gallery__grid {
	/* The row height tracks the column width so a one-by-one tile stays at
	   roughly 4:3 whatever the viewport: four columns inside the shell means
	   a column of about 25vw, and 14rem is where it settles once the shell
	   stops growing. */
	--bh-gallery-row: min(14rem, 18.5vw - 1.1rem);
	display: grid;
	grid-template-columns: repeat(4, 1fr);
	grid-auto-rows: var(--bh-gallery-row);
	grid-auto-flow: row dense;
	gap: 1.1rem;
}

.bh-gallery__item {
	position: relative;
	margin: 0;
	overflow: hidden;
	border-radius: 14px;
	background: var(--bh-field);
	/* An outline rather than an inset shadow: it paints above the
	   photograph, and it follows the rounded corner. */
	outline: 1px solid var(--bh-border);
	outline-offset: -1px;
	transition: outline-color 0.4s ease;
}

.bh-gallery__item:hover {
	outline-color: var(--bh-gold-soft);
}

.bh-gallery__item--hero {
	grid-column: span 2;
	grid-row: span 2;
}

.bh-gallery__item--tall {
	grid-row: span 2;
}

.bh-gallery__item--wide {
	grid-column: span 2;
}

/*
 * Written from the item down on purpose. The theme reset is `.bh img { height:
 * auto }` — one class and one type — which outranks a lone class here, so a
 * bare `.bh-gallery__img` loses the height and every photograph keeps its own
 * aspect: short ones leave a band of the tile ground showing, tall ones spill
 * past the tile and get clipped with object-position never consulted.
 *
 * `filter` is deliberately absent: luxury.css grades every figure photograph
 * on the site with one warm pass, at a specificity nothing here should try to
 * beat — and because filter replaces rather than adds, a hover filter written
 * here would drop the photograph out of that grade for the length of the
 * hover.
 */
.bh-gallery__item .bh-gallery__img {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: cover;
	/* The per-photograph object-position arrives inline from the template. */
	object-position: center;
	transform: scale(1.01);
	transition: transform 0.9s cubic-bezier(0.22, 0.61, 0.36, 1);
}

.bh-gallery__item:hover .bh-gallery__img {
	transform: scale(1.06);
}

/* Scrims -------------------------------------------------------------- */

.bh-gallery__item::before,
.bh-gallery__item::after {
	content: '';
	position: absolute;
	inset: 0;
	pointer-events: none;
	transition: opacity 0.5s ease;
}

/* The warm veil that holds the wall together, and lifts under the cursor. */
.bh-gallery__item::before {
	z-index: 1;
	background: linear-gradient(155deg, rgba(110, 43, 46, 0.24) 0%, rgba(22, 17, 15, 0.14) 46%, rgba(200, 138, 54, 0.2) 100%);
}

.bh-gallery__item:hover::before {
	opacity: 0.16;
}

/*
 * The foot that gives every tile the same dark base. It is deliberately light:
 * the work of making the words readable belongs to the caption's own scrim
 * below, which is the only one that knows how tall the words are.
 */
.bh-gallery__item::after {
	z-index: 2;
	background: linear-gradient(to top, rgba(22, 17, 15, 0.55) 0%, rgba(22, 17, 15, 0.28) 30%, rgba(22, 17, 15, 0) 62%);
}

/* Captions ------------------------------------------------------------ */

/*
 * The scrim is anchored to the caption rather than to the tile, because the
 * caption is the thing whose height varies: a line that wraps in two on a
 * short tile carries its eyebrow a third of the way up the photograph, which
 * is well past where a tile-anchored gradient has faded out. Measured on the
 * three brightest frames — the overhead trays, all white plate and lit rice —
 * the gold eyebrow wants roughly 0.8 of ink beneath it to clear 4.5:1, and it
 * gets that here wherever the words happen to land.
 */
.bh-gallery__cap {
	position: absolute;
	inset: auto 0 0;
	z-index: 3;
	display: grid;
	gap: 0.35rem;
	padding: 2.4rem 1.2rem 1.1rem;
	background: linear-gradient(to top, rgba(22, 17, 15, 0.92) 0%, rgba(22, 17, 15, 0.88) 60%, rgba(22, 17, 15, 0) 100%);
	opacity: 0.94;
	transform: translateY(0.3rem);
	transition: opacity 0.5s ease, transform 0.5s ease;
}

.bh-gallery__cap[hidden] {
	display: none;
}

.bh-gallery__item:hover .bh-gallery__cap {
	opacity: 1;
	transform: translateY(0);
}

.bh-gallery__kind {
	font-family: var(--bh-body);
	font-size: 0.7rem;
	font-weight: 600;
	letter-spacing: 0.3em;
	text-transform: uppercase;
	color: var(--bh-gold);
}

.bh-gallery__line {
	font-family: var(--bh-display);
	font-size: 1.25rem;
	line-height: 1.22;
	color: var(--bh-cream);
	text-wrap: balance;
}

.bh-gallery__item--hero .bh-gallery__cap,
.bh-gallery__item--wide .bh-gallery__cap {
	padding: 2.8rem 1.7rem 1.5rem;
}

.bh-gallery__item--hero .bh-gallery__line,
.bh-gallery__item--wide .bh-gallery__line {
	font-size: clamp(1.4rem, 2vw, 1.75rem);
}

/* The way out --------------------------------------------------------- */

.bh-gallery__foot {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 1rem;
	margin-top: 2.8rem;
}

.bh-gallery__foot .bh-lotus {
	display: block;
	opacity: 0.85;
}

/* Collapses ----------------------------------------------------------- */

@media (max-width: 68em) {
	.bh-gallery__grid {
		gap: 0.9rem;
	}
}

/* 780px — two columns. The hero and the panorama take the full width. */
@media (max-width: 48.75em) {
	.bh-gallery {
		padding-block: 4rem;
	}

	.bh-gallery__grid {
		/* Two columns of about 50vw, held to the same tile ratio. */
		--bh-gallery-row: calc(37vw - 1.5rem);
		grid-template-columns: repeat(2, 1fr);
	}
}

/* 560px — one column, each tile back to a ratio its photograph can live in. */
@media (max-width: 35em) {
	.bh-gallery__grid {
		grid-template-columns: 1fr;
		grid-auto-rows: auto;
	}

	.bh-gallery__item {
		grid-column: auto;
		grid-row: auto;
		aspect-ratio: 4 / 3;
	}

	.bh-gallery__item--hero {
		aspect-ratio: 5 / 4;
	}

	.bh-gallery__item--tall {
		aspect-ratio: 3 / 4;
	}

	.bh-gallery__item--wide {
		aspect-ratio: 2 / 1;
	}

	.bh-gallery__cap,
	.bh-gallery__item--hero .bh-gallery__cap,
	.bh-gallery__item--wide .bh-gallery__cap {
		padding: 1.9rem 1.1rem 1rem;
	}

	/* One column gives every caption the full measure, so the hero and the
	   panorama no longer need the larger size to hold their tiles. */
	.bh-gallery__item--hero .bh-gallery__line,
	.bh-gallery__item--wide .bh-gallery__line {
		font-size: 1.25rem;
	}
}

@media (prefers-reduced-motion: reduce) {
	/* Matched to the weight of the rules above, or the resting scale survives. */
	.bh-gallery__item .bh-gallery__img,
	.bh-gallery__item:hover .bh-gallery__img,
	.bh-gallery__cap,
	.bh-gallery__item:hover .bh-gallery__cap {
		transform: none;
		transition: none;
	}
}
