/**
 * TGJ Gallery — core Gallery with our layouts.
 *
 * Width, gutter and vertical spacing come from the band + wrap in the theme
 * (tgj-block-layout.md §2). What is here is each layout's inside: the gap is
 * a per-component decision on the gap tokens (§3.4), not an author control.
 * Mobile first; min-width breakpoints only (768 tablet, 1024 laptop).
 */

.tgj-gallery .tgj-gallery__items {
	list-style: none;
	margin: 0;
	padding: 0;
}

.tgj-gallery .tgj-gallery__item {
	margin: 0;
	padding: 0;
}

.tgj-gallery .tgj-gallery__figure {
	margin: 0;
}

.tgj-gallery .tgj-gallery__link {
	display: block;
	cursor: zoom-in;
}

.tgj-gallery .tgj-gallery__image {
	display: block;
	width: 100%;
	height: auto;
}

/* The theme's global figcaption carries the page gutter as padding; inside a
   gallery the wrap already supplies it. */
.tgj-gallery .tgj-gallery__caption {
	padding: 0;
	margin-top: var(--space-8);
	font-size: var(--tgj-small);
	line-height: var(--tgj-lh-small);
}

/* ── Grid ─────────────────────────────────────────────────────────────── */

.tgj-gallery--grid .tgj-gallery__items {
	display: grid;
	gap: var(--gap);
	grid-template-columns: repeat(var(--tgj-gallery-cols, 2), minmax(0, 1fr));
}

/* Columns at phone / tablet / laptop — the same tiers the render uses for
   `sizes` (two-image rows stack on phones; wider grids run two-up). */
.tgj-gallery--cols-1 { --tgj-gallery-cols: 1; }
.tgj-gallery--cols-2 { --tgj-gallery-cols: 1; }

@media (min-width: 768px) {
	.tgj-gallery--cols-2 { --tgj-gallery-cols: 2; }
	.tgj-gallery--cols-3,
	.tgj-gallery--cols-4,
	.tgj-gallery--cols-5,
	.tgj-gallery--cols-6 { --tgj-gallery-cols: 3; }
}

@media (min-width: 1024px) {
	.tgj-gallery--cols-4 { --tgj-gallery-cols: 4; }
	.tgj-gallery--cols-5 { --tgj-gallery-cols: 5; }
	.tgj-gallery--cols-6 { --tgj-gallery-cols: 6; }
}

/* Core's Aspect ratio setting: a crop is CSS (aspect-ratio + object-fit), not
   a cropped image size, so one srcset serves every shape. The render sets the
   ratio on the band; "Original" sets none and each image keeps its shape. */
.tgj-gallery--cropped .tgj-gallery__image {
	aspect-ratio: var(--tgj-gallery-ratio);
	object-fit: cover;
}

/* Numbered (the imageset's thumbnail grid): 01, 02… under each image, and
   the captions in the lightbox only. Rows get more room for the number. */
.tgj-gallery--numbered .tgj-gallery__items {
	row-gap: var(--space-40);
}

.tgj-gallery__number {
	display: block;
	margin-top: var(--space-16);
	text-align: center;
	font-family: var(--font-ui-bold);
	font-size: var(--tgj-small-header);
	line-height: var(--tgj-lh-small-header);
	font-variant-numeric: tabular-nums;
}

.tgj-gallery--numbered .tgj-gallery__caption {
	display: none;
}

.tgj-gallery__hint {
	margin: var(--space-40) 0 0;
	text-align: center;
}

.tgj-gallery__hint-button {
	padding: 0;
	border: 0;
	background: none;
	color: inherit;
	cursor: zoom-in;
	font-family: var(--font-body);
	font-size: var(--tgj-body-editorial);
	line-height: var(--tgj-lh-editorial);
}

/* ── Tiled ────────────────────────────────────────────────────────────── */

/* A mosaic in one rectangle (see tiled_items()). The render sets each row's
   aspect ratio (--tgj-row-a), each column's share of it (--tgj-a) and each
   stacked image's share of its column's height (--tgj-h). Images cover their
   cell, which absorbs the few px the gaps put out. It scales at every width,
   as Jetpack's tiled gallery did. */
.tgj-gallery--tiled .tgj-gallery__items {
	display: flex;
	flex-direction: column;
	gap: var(--gap-tight);
}

.tgj-gallery__row {
	display: flex;
	gap: var(--gap-tight);
	aspect-ratio: var(--tgj-row-a);
}

.tgj-gallery .tgj-gallery__col {
	flex: var(--tgj-a) 1 0;
	min-width: 0;
	display: flex;
	flex-direction: column;
	gap: var(--gap-tight);
	list-style: none;
	margin: 0;
	padding: 0;
}

.tgj-gallery--tiled .tgj-gallery__item {
	flex: var(--tgj-h) 1 0;
	min-height: 0;
}

.tgj-gallery--tiled .tgj-gallery__figure,
.tgj-gallery--tiled .tgj-gallery__link {
	height: 100%;
}

.tgj-gallery--tiled .tgj-gallery__image {
	height: 100%;
	object-fit: cover;
}

/* A caption under each tile would break the mosaic; Tiled shows captions in
   the lightbox only. */
.tgj-gallery--tiled .tgj-gallery__caption {
	display: none;
}

/* ── Carousel ─────────────────────────────────────────────────────────── */

/* Native scrolling: one image per view, snapped. */
.tgj-gallery--carousel .tgj-gallery__items {
	display: flex;
	overflow-x: auto;
	overscroll-behavior-x: contain;
	scroll-snap-type: x mandatory;
	scroll-behavior: smooth;
	scrollbar-width: none;
}

.tgj-gallery--carousel .tgj-gallery__items::-webkit-scrollbar {
	display: none;
}

.tgj-gallery--carousel .tgj-gallery__items:focus-visible {
	outline: 2px solid currentColor;
	outline-offset: 4px;
}

.tgj-gallery--carousel .tgj-gallery__item {
	flex: 0 0 100%;
	scroll-snap-align: center;
	scroll-snap-stop: always;
}

/* A 3:2 frame with each image fitted inside it, not cropped, as the
   imageset's carousel did. */
.tgj-gallery--carousel .tgj-gallery__link {
	aspect-ratio: 3 / 2;
}

.tgj-gallery--carousel .tgj-gallery__image {
	height: 100%;
	object-fit: contain;
}

.tgj-gallery--carousel .tgj-gallery__caption {
	text-align: center;
}

.tgj-gallery__controls {
	display: flex;
	align-items: center;
	gap: var(--space-16);
	margin-top: var(--space-16);
}

.tgj-gallery__controls[hidden] {
	display: none;
}

.tgj-gallery__arrow {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	flex: none;
	width: 44px;
	height: 44px;
	padding: 0;
	border: 0;
	background: none;
	color: inherit;
	cursor: pointer;
}

.tgj-gallery__arrow:disabled {
	opacity: 0.3;
	cursor: default;
}

.tgj-gallery__progress {
	flex: 1;
	height: 2px;
	background: color-mix(in srgb, currentColor 20%, transparent);
	position: relative;
}

.tgj-gallery__progress-bar {
	position: absolute;
	inset: 0 auto 0 0;
	width: 0;
	background: currentColor;
	transition: width 0.2s ease;
}

.tgj-gallery__count {
	flex: none;
	margin: 0;
	font-size: var(--tgj-small);
	line-height: var(--tgj-lh-small);
	font-variant-numeric: tabular-nums;
}

/* ── Lightbox (PhotoSwipe 5) ──────────────────────────────────────────── */

.tgj-gallery-lightbox__caption {
	position: absolute;
	inset: auto 0 0 0;
	padding: var(--space-16) var(--gutter) var(--space-24);
	color: #fff;
	text-align: center;
	font-size: var(--tgj-small);
	line-height: var(--tgj-lh-small);
	background: linear-gradient(to top, rgba(0, 0, 0, 0.6), transparent);
	pointer-events: none;
}

.tgj-gallery-lightbox__caption[hidden] {
	display: none;
}

@media (min-width: 768px) {
	.tgj-gallery-lightbox__caption {
		padding-inline: 15%;
	}
}

@media (prefers-reduced-motion: reduce) {
	.tgj-gallery--carousel .tgj-gallery__items { scroll-behavior: auto; }
	.tgj-gallery__progress-bar { transition: none; }
}
