/**
 * td/gallery
 *
 * Mobile (390 frame, below 600px): centred intro, one 350:250 image at a
 * time (native scroll-snap; view.js adds the arrows and dots). From 600px the
 * images share one row 8px apart (326:434 frames, 2px border); from 1024px
 * the intro is a row with the button on the right.
 */

.td-gallery {
	padding-block: var(--td-section-space);
	background-color: var(--wp--preset--color--ink);
	color: var(--wp--preset--color--stone);
}

.td-gallery__inner {
	display: flex;
	flex-direction: column;
	gap: var(--td-section-gap);
}

.td-gallery__header,
.td-gallery__titles {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 16px;
	text-align: center;
}

.td-gallery__titles {
	align-self: stretch;
}

.td-gallery__eyebrow {
	color: var(--wp--preset--color--champagne);
}

.td-gallery__title {
	color: var(--wp--preset--color--ivory);
}

.td-gallery__body {
	display: flex;
	flex-direction: column;
	gap: 8px;
}

.td-gallery__track {
	position: relative;
	display: flex;
	gap: 8px;
	margin: 0;
	padding: 0;
	overflow-x: auto;
	list-style: none;
	scroll-snap-type: x mandatory;
	scrollbar-width: none;
}

.td-gallery__track::-webkit-scrollbar {
	display: none;
}

.td-gallery__item {
	flex: 0 0 100%;
	aspect-ratio: 350 / 250;
	border: 1px solid rgba(213, 213, 215, 0.7);
	scroll-snap-align: start;
}

.td-gallery__image {
	width: 100%;
	height: 100%;
	object-fit: cover;
}

.td-gallery__controls:not([hidden]) {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 11px;
	padding-block: 4px;
}

.td-gallery__control {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 24px;
	height: 24px;
	padding: 4px;
	border: 0.5px solid var(--wp--preset--color--ivory);
	background: transparent;
	color: var(--wp--preset--color--ivory);
	cursor: pointer;
	transition: background-color 0.2s var(--td-ease), color 0.2s var(--td-ease);
}

.td-gallery__control:hover,
.td-gallery__control:focus-visible {
	background-color: var(--wp--preset--color--ivory);
	color: var(--wp--preset--color--ink);
}

.td-gallery__control .td-icon {
	width: 16px;
	height: 16px;
}

.td-gallery__dots {
	display: flex;
	gap: 4px;
	opacity: 0.7;
}

.td-gallery__dot {
	width: 12px;
	height: 12px;
	border: 1px solid var(--wp--preset--color--ivory);
	border-radius: 50%;
	transition: background-color 0.2s var(--td-ease);
}

.td-gallery__dot.is-current {
	background-color: var(--wp--preset--color--ivory);
}

@media (min-width: 600px) {

	.td-gallery__track {
		overflow: visible;
	}

	.td-gallery__item {
		flex: 1 1 0;
		min-width: 0;
		aspect-ratio: 326 / 434;
		border-width: 2px;
	}

	.td-gallery__controls:not([hidden]) {
		display: none;
	}
}

@media (min-width: 1024px) {

	.td-gallery__header {
		flex-direction: row;
		align-items: flex-end;
		justify-content: space-between;
		gap: 64px;
		text-align: left;
	}

	.td-gallery__titles {
		flex: 0 1 765px;
		align-items: flex-start;
		align-self: auto;
		gap: 32px;
		text-align: left;
	}

	.td-gallery__button {
		flex: none;
	}
}

/* Image buttons (open the lightbox) -------------------------------------- */

.td-gallery__open {
	display: block;
	width: 100%;
	height: 100%;
	padding: 0;
	border: 0;
	background: none;
	cursor: zoom-in;
}

.td-gallery__open:focus-visible {
	outline: 2px solid var(--wp--preset--color--champagne);
	outline-offset: -4px;
}

/* Lightbox (native <dialog>, view.js) -------------------------------------- */

html.td-lightbox-open {
	overflow: hidden;
}

.td-lightbox {
	box-sizing: border-box;
	width: 100vw;
	max-width: none;
	height: 100dvh;
	max-height: none;
	margin: 0;
	padding: 64px 16px 80px;
	border: 0;
	background: rgba(10, 16, 31, 0.96);
	color: var(--wp--preset--color--ivory);

	/* Horizontal swipes change the image (view.js): the browser must not also
	   use them to scroll or as a "go back" gesture. Pinch zoom stays. */
	overscroll-behavior: contain;
	touch-action: pinch-zoom;
}

.td-lightbox[open] {
	display: flex;
	align-items: center;
	justify-content: center;
	animation: td-lightbox-in 0.25s var(--td-ease);
}

.td-lightbox::backdrop {
	background: transparent;
}

@keyframes td-lightbox-in {

	from {
		opacity: 0;
	}
}

.td-lightbox__figure {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 100%;
	height: 100%;
	margin: 0;
}

.td-lightbox__image {
	width: auto;
	max-width: 100%;
	height: auto;
	max-height: 100%;
	object-fit: contain;
}

.td-lightbox__count {
	position: absolute;
	bottom: 32px;
	left: 50%;
	margin: 0;
	transform: translateX(-50%);
}

.td-lightbox__button {
	position: absolute;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 40px;
	height: 40px;
	padding: 8px;
	border: 0.5px solid var(--wp--preset--color--ivory);
	background: rgba(10, 16, 31, 0.4);
	color: var(--wp--preset--color--ivory);
	cursor: pointer;
	transition: background-color 0.2s var(--td-ease), color 0.2s var(--td-ease);
}

.td-lightbox__button:hover,
.td-lightbox__button:focus-visible {
	background-color: var(--wp--preset--color--ivory);
	color: var(--wp--preset--color--ink);
}

.td-lightbox__button:focus-visible {
	outline: 2px solid var(--wp--preset--color--champagne);
	outline-offset: 3px;
}

.td-lightbox__button .td-icon {
	width: 24px;
	height: 24px;
}

.td-lightbox__close {
	top: 12px;
	right: 12px;
}

/* Phones: arrows in the bottom bar, beside the counter. */
.td-lightbox__prev,
.td-lightbox__next {
	bottom: 20px;
}

.td-lightbox__prev {
	left: 16px;
}

.td-lightbox__next {
	right: 16px;
}

@media (min-width: 600px) {

	.td-lightbox {
		padding: 72px 88px;
	}

	.td-lightbox__close {
		top: 16px;
		right: 16px;
	}

	.td-lightbox__prev,
	.td-lightbox__next {
		top: calc(50% - 20px);
		bottom: auto;
	}

	.td-lightbox__prev {
		left: 24px;
	}

	.td-lightbox__next {
		right: 24px;
	}
}

/* Checklist (optional) ---------------------------------------------------- */

.td-gallery__list {
	gap: 16px;
	color: var(--wp--preset--color--bronze);
}

.td-gallery__list .td-checklist__item {
	gap: 4px;
	text-align: left;
}

/* Beside text style: sand section, images stacked beside the text. Phones
   and tablets: intro, checklist, images, then the button (design). ------- */

.td-gallery.is-style-side {
	background-color: var(--wp--preset--color--sand);
	color: var(--wp--preset--color--slate);
}

.td-gallery.is-style-side .td-gallery__eyebrow,
.td-gallery.is-style-tiles .td-gallery__eyebrow {
	color: var(--wp--preset--color--bronze);
}

.td-gallery.is-style-side .td-gallery__title,
.td-gallery.is-style-tiles .td-gallery__title {
	color: var(--wp--preset--color--ink);
}

.td-gallery.is-style-side .td-gallery__inner {
	gap: 24px;
}

.td-gallery.is-style-side .td-gallery__header {
	display: contents;
}

.td-gallery.is-style-side .td-gallery__list {
	order: 1;
	align-self: stretch;
}

.td-gallery.is-style-side .td-gallery__body {
	order: 2;
}

.td-gallery.is-style-side .td-gallery__button {
	order: 3;
	align-self: stretch;
}

/* One gap between all images (Image Gap control, 30px by default). */
.td-gallery.is-style-side .td-gallery__track {
	flex-direction: column;
	gap: var(--td-gallery-gap, 30px);
	overflow: visible;
}

/* overflow: hidden keeps the box at its ratio (an aspect-ratio box would
   otherwise grow to a portrait image's height). */
.td-gallery.is-style-side .td-gallery__item {
	flex: none;
	width: 100%;
	aspect-ratio: 350 / 195;
	overflow: hidden;
	border: 0;
	background-color: var(--wp--preset--color--sand);
}

/* The item carries the section colour, so the blend still has a backdrop
   when the reveal animation isolates the image group. */
.td-gallery.is-style-side .td-gallery__image {
	mix-blend-mode: var(--td-gallery-blend, multiply);
}

/* One image (e.g. Remodeling "What we do"): a taller picture (350:306,
   539:487 from 1024px) that comes before the checklist on phones and
   tablets, and the standard section spacing on desktop. */
.td-gallery.is-style-side:has(.td-gallery__item:only-child) .td-gallery__body {
	order: 1;
}

.td-gallery.is-style-side:has(.td-gallery__item:only-child) .td-gallery__list {
	order: 2;
}

.td-gallery.is-style-side .td-gallery__item:only-child {
	aspect-ratio: 350 / 306;
}

/* Beside text with several images, desktop: the text starts level with the
   top of the first image and stays in place (sticky, below the site header)
   while the image column scrolls past it; it is released together with the
   last image, so the whole page then scrolls on. Only while the text fits in
   the window. A single picture keeps its centred design. */
@media (min-width: 1024px) and (min-height: 720px) {

	.td-gallery.is-style-side:not(:has(.td-gallery__item:only-child)) .td-gallery__inner {
		align-items: start;
	}

	.td-gallery.is-style-side:not(:has(.td-gallery__item:only-child)) .td-gallery__header {
		position: sticky;

		/* Mobile-style header bar (96px incl. border) below 1200px, 80px from
		   1200px, plus the admin bar; see site-header/style.css. */
		top: calc(var(--wp-admin--admin-bar--height, 0px) + 96px + 32px);
	}
}

@media (min-width: 1200px) and (min-height: 720px) {

	.td-gallery.is-style-side:not(:has(.td-gallery__item:only-child)) .td-gallery__header {
		top: calc(var(--wp-admin--admin-bar--height, 0px) + 80px + 32px);
	}
}

/* The editor canvas has no site header: the text just stays with its image. */
.editor-styles-wrapper .td-gallery.is-style-side .td-gallery__header {
	position: static;
}

/* Captioned tiles style: sand section, square tiles with a caption ------- */

.td-gallery.is-style-tiles {
	background-color: var(--wp--preset--color--sand);
	color: var(--wp--preset--color--slate);
}

.td-gallery.is-style-tiles .td-gallery__titles {
	max-width: 652px;
	margin-inline: auto;
}

.td-gallery.is-style-tiles .td-gallery__title {
	font-size: 40px;
	line-height: 48px;
}

.td-gallery.is-style-tiles .td-gallery__track {
	flex-direction: column;
	gap: 16px;
	overflow: visible;
}

.td-gallery.is-style-tiles .td-gallery__item {
	position: relative;
	flex: none;
	width: 100%;
	aspect-ratio: 350 / 202;
	overflow: hidden;
	border: 0;
}

.td-gallery.is-style-tiles .td-gallery__item::after {
	content: "";
	position: absolute;
	inset: 0;
	background: linear-gradient(180deg, rgba(0, 0, 0, 0) 43.56%, rgba(0, 0, 0, 0.4) 83.17%);
	pointer-events: none;
}

.td-gallery__caption {
	position: absolute;
	right: 8px;
	bottom: 8px;
	left: 8px;
	z-index: 1;
	font-size: 16px;
	line-height: 28px;
	color: var(--wp--preset--color--ivory);
	pointer-events: none;
}

@media (min-width: 600px) {

	.td-gallery.is-style-tiles .td-gallery__track {
		display: grid;
		grid-template-columns: repeat(3, minmax(0, 1fr));
		gap: 24px;
	}

	.td-gallery.is-style-tiles .td-gallery__item {
		aspect-ratio: 1;
	}
}

@media (min-width: 1024px) {

	/* Images left (539 of 1328), text right (652), 137px apart (design). */
	.td-gallery.is-style-side {
		padding-block: 64px;
	}

	.td-gallery.is-style-side .td-gallery__inner {
		display: grid;
		grid-template-columns: minmax(0, 539fr) minmax(0, 652fr);
		align-items: center;
		column-gap: calc(137 / 1328 * 100%);
	}

	.td-gallery.is-style-side .td-gallery__header {
		display: flex;
		flex-direction: column;
		grid-row: 1;
		grid-column: 2;
		align-items: flex-start;
		gap: 64px;
		text-align: left;
	}

	.td-gallery.is-style-side .td-gallery__titles {
		flex: none;
		gap: 24px;
	}

	.td-gallery.is-style-side .td-gallery__body {
		grid-row: 1;
		grid-column: 1;
	}

	.td-gallery.is-style-side .td-gallery__list {
		display: block;
		columns: 2;
		column-gap: 24px;
	}

	.td-gallery.is-style-side .td-gallery__list .td-checklist__item {
		gap: 8px;
		margin-bottom: 16px;
		break-inside: avoid;
	}

	.td-gallery.is-style-side .td-gallery__button {
		align-self: flex-start;
	}

	.td-gallery.is-style-side .td-gallery__item {
		aspect-ratio: 539 / 300;
	}

	.td-gallery.is-style-side:has(.td-gallery__item:only-child) {
		padding-block: var(--td-section-space);
	}

	.td-gallery.is-style-side .td-gallery__item:only-child {
		aspect-ratio: 539 / 487;
	}

	/* Tiles: centred intro, one row of up to 202px squares. */
	.td-gallery.is-style-tiles {
		padding-block: 150px 32px;
	}

	.td-gallery.is-style-tiles .td-gallery__inner {
		gap: var(--td-section-space);
	}

	.td-gallery.is-style-tiles .td-gallery__header {
		flex-direction: column;
		align-items: center;
		text-align: center;
	}

	.td-gallery.is-style-tiles .td-gallery__titles {
		flex: none;
		align-items: center;
		gap: 24px;
		text-align: center;
	}

	.td-gallery.is-style-tiles .td-gallery__title {
		font-size: clamp(48px, 4.45vw, 64px);
		line-height: 1;
	}

	.td-gallery.is-style-tiles .td-gallery__track {
		display: flex;
		flex-direction: row;
		justify-content: center;
	}

	.td-gallery.is-style-tiles .td-gallery__item {
		flex: 0 1 202px;
	}

	.td-gallery__caption {
		right: 16px;
		bottom: 16px;
		left: 16px;
		line-height: 25px;
	}
}
