/**
 * TGJ Slideshow
 *
 * Mobile-first, min-width queries on the theme's breakpoints only (tablet
 * 768px, laptop 1024px — tgj-design-tokens.md §1). The row is native
 * horizontal scrolling with scroll-snap, laid out from the first paint, so
 * nothing stacks or jumps while the script loads.
 *
 * Slides are Image Background blocks. Their band spacing and height options
 * are switched off in a Slideshow (render side); here they fill the slide.
 */

.tgj-slideshow {
	--ss-gap: var(--space-16);
	--ss-radius: 6px;
	--ss-control-bg: rgba(0, 0, 0, 0.4);
	--ss-control-fg: #fff;
}

@media (min-width: 768px) {
	.tgj-slideshow { --ss-gap: var(--space-24); }
}

@media (min-width: 1024px) {
	.tgj-slideshow { --ss-gap: var(--space-40); }
}

.tgj-slideshow__frame {
	position: relative;
	container-type: inline-size;
}

/* ── Track ─────────────────────────────────────────────────── */

.tgj-slideshow__track {
	display: flex;
	margin: 0;
	padding: 0;
	list-style: none;
	overflow-x: auto;
	overscroll-behavior-x: contain;
	scroll-snap-type: x mandatory;
	scroll-behavior: smooth;
	scrollbar-width: none;
}

.tgj-slideshow__track::-webkit-scrollbar {
	display: none;
}

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

.tgj-slideshow__slide {
	position: relative;
	flex: 0 0 100%;
	margin: 0;
	scroll-snap-align: start;
	scroll-snap-stop: always;
}

/* The slide (an Image Background band) fills its slot */
.tgj-slideshow__slide > .jc-block.tgj-image-background {
	height: 100%;
	--ib-height: 100%;
}

.tgj-slideshow__slide .tgj-image-background__image picture {
	display: block;
	height: 100%;
}

/* Whole-image link: over the image, under the text (Image Background) */
.jc-block.tgj-image-background .tgj-image-background__link {
	position: absolute;
	inset: 0;
	z-index: 3;
}

.jc-block.tgj-image-background--linked .tgj-image-background__overlay {
	pointer-events: none;
}

.jc-block.tgj-image-background--linked .tgj-image-background__overlay :is(a, button) {
	pointer-events: auto;
}

/* ── One in view: the hero ─────────────────────────────────── */

/* Phones: the text keeps clear of the slide's edges whatever wrap it sits
   in (a page template that already has a gutter drops the wrap's own). */
.tgj-slideshow--one .jc-block.tgj-image-background .tgj-image-background__content {
	padding-inline: var(--space-24);
}

@media (min-width: 768px) {
	.tgj-slideshow--one .jc-block.tgj-image-background .tgj-image-background__content {
		padding-inline: var(--space-40);
	}
}

@media (min-width: 1024px) {
	.tgj-slideshow--one .jc-block.tgj-image-background .tgj-image-background__content {
		padding-inline: calc(var(--space-96) + var(--space-32));
	}
}

.tgj-slideshow--one .tgj-slideshow__slide {
	height: var(--ss-h);
}

/* Standard and Low: today's carousel heights. From tablet up a 16:9 frame,
   capped, so every slide is the same height at any width. */
.tgj-slideshow--h-standard { --ss-h: 570px; }
.tgj-slideshow--h-low      { --ss-h: 485px; }
.tgj-slideshow--h-full     { --ss-h: 100svh; }

@media (min-width: 768px) {
	.tgj-slideshow--h-standard { --ss-h: min(600px, 56.25cqi); }
	.tgj-slideshow--h-low      { --ss-h: min(512px, 56.25cqi); }
}

/* ── Several in view: the row ──────────────────────────────── */

.tgj-slideshow--row .tgj-slideshow__track {
	gap: var(--ss-gap);
}

.tgj-slideshow--row .tgj-slideshow__slide,
.tgj-slideshow--row .tgj-slideshow__intro--card {
	flex: 0 0 calc((100% - 2 * var(--ss-gap)) / 2.5);
	border-radius: var(--ss-radius);
	overflow: hidden;
}

@media (min-width: 768px) {
	/* Three and a half, so the half card shows the row scrolls (no arrows
	   below laptop). */
	.tgj-slideshow--cards-6 .tgj-slideshow__slide,
	.tgj-slideshow--cards-6 .tgj-slideshow__intro--card {
		flex-basis: calc((100% - 3 * var(--ss-gap)) / 3.5);
	}
}

@media (min-width: 1024px) {
	.tgj-slideshow--cards-2 :is(.tgj-slideshow__slide, .tgj-slideshow__intro--card) { flex-basis: calc((100% - 1 * var(--ss-gap)) / 2); }
	.tgj-slideshow--cards-3 :is(.tgj-slideshow__slide, .tgj-slideshow__intro--card) { flex-basis: calc((100% - 2 * var(--ss-gap)) / 3); }
	.tgj-slideshow--cards-4 :is(.tgj-slideshow__slide, .tgj-slideshow__intro--card) { flex-basis: calc((100% - 3 * var(--ss-gap)) / 4); }
	.tgj-slideshow--cards-6 :is(.tgj-slideshow__slide, .tgj-slideshow__intro--card) { flex-basis: calc((100% - 5 * var(--ss-gap)) / 6); }
}

.tgj-slideshow--shape-portrait .tgj-slideshow__slide { aspect-ratio: 3 / 4; }
.tgj-slideshow--shape-square .tgj-slideshow__slide   { aspect-ratio: 1 / 1; }

/* Natural: the image sets the card's height */
.tgj-slideshow--shape-natural .tgj-slideshow__slide > .jc-block.tgj-image-background {
	height: auto;
	--ib-height: auto;
}

.tgj-slideshow--shape-natural .tgj-slideshow__slide .tgj-image-background__image img {
	height: auto;
}

/* Text on a card: tighter than a full-width Image Background */
.tgj-slideshow--row .tgj-image-background__container {
	padding: var(--space-16) 0;
}

.tgj-slideshow--row .jc-block.tgj-image-background .tgj-image-background__content {
	padding-inline: var(--space-16);
}

@media (min-width: 1024px) {
	.tgj-slideshow--row .tgj-image-background__container {
		padding: var(--space-24) 0;
	}

	.tgj-slideshow--row .jc-block.tgj-image-background .tgj-image-background__content {
		padding-inline: var(--space-24);
	}
}

.tgj-slideshow--row .tgj-image-background__content :is(h2, h3, h4) {
	margin: 0 0 var(--space-4, 4px);
	font-size: var(--tgj-title);
	line-height: var(--tgj-lh-title);
	text-transform: uppercase;
}

.tgj-slideshow--row .tgj-image-background__content p {
	margin: 0;
	font-size: var(--tgj-small);
	line-height: var(--tgj-lh-small);
}

.tgj-slideshow--row .tgj-image-background__content p.tgj-slideshow__cta {
	margin-top: var(--space-4, 4px);
	font-style: italic;
	text-decoration: underline;
	text-underline-offset: 3px;
}

/* ── Row intro ─────────────────────────────────────────────── */

/* Phones: above the row. Tablet up: the row's first card. */
.tgj-slideshow__intro--above {
	margin-bottom: var(--space-24);
	text-align: left;
}

.tgj-slideshow__intro--card {
	display: none;
}

@media (min-width: 768px) {
	.tgj-slideshow__intro--above {
		display: none;
	}

	.tgj-slideshow__intro--card {
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		gap: var(--space-24);
		padding: var(--space-24);
		background: var(--tgj-surface-sunk, #f6f6f3);
		scroll-snap-align: start;
	}
}

@media (min-width: 1024px) {
	.tgj-slideshow__intro--card {
		padding: var(--space-32);
	}
}

.tgj-slideshow__intro-title {
	margin: 0 0 var(--space-12);
	font-size: var(--tgj-subhead);
	line-height: var(--tgj-lh-subhead);
}

.tgj-slideshow__intro-body {
	margin: 0;
	font-size: var(--tgj-body);
	line-height: var(--tgj-lh-body);
}

.tgj-slideshow__intro-cta {
	margin: var(--space-16) 0 0;
}

.tgj-slideshow__intro--card .tgj-slideshow__intro-cta {
	margin: 0;
}

/* Black, like the theme's .button, not TGJ Button's cream default (that is
   for buttons on images). One class more than the button's own rule, so it wins
   whichever stylesheet loads last. */
.tgj-slideshow__intro .tgj-slideshow__intro-cta.tgj-button .tgj-button__link {
	background-color: var(--tgj-black, #0a0a0a);
	color: var(--tgj-white, #fff);
}

/* ── Controls ──────────────────────────────────────────────── */

.tgj-slideshow__controls[hidden],
.tgj-slideshow__pause[hidden] {
	display: none;
}

.tgj-slideshow__arrow,
.tgj-slideshow__pause {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	flex: none;
	width: 44px;
	height: 44px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	cursor: pointer;
}

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

/* Hero: over the image. Arrows from laptop up (phones swipe); dots and the
   pause control centred along the bottom. */
.tgj-slideshow__controls--overlay {
	position: absolute;
	inset: 0;
	pointer-events: none;
	z-index: 4;
}

.tgj-slideshow__controls--overlay :is(button) {
	pointer-events: auto;
}

.tgj-slideshow__controls--overlay .tgj-slideshow__arrow,
.tgj-slideshow__pause {
	background: var(--ss-control-bg);
	color: var(--ss-control-fg);
}

.tgj-slideshow__arrows {
	display: none;
}

@media (min-width: 1024px) {
	.tgj-slideshow__arrows {
		display: block;
	}

	.tgj-slideshow__arrows .tgj-slideshow__arrow {
		position: absolute;
		top: 50%;
		transform: translateY(-50%);
	}

	.tgj-slideshow__arrow--prev { left: var(--space-16); }
	.tgj-slideshow__arrow--next { right: var(--space-16); }
}

.tgj-slideshow__bottom {
	position: absolute;
	left: 0;
	right: 0;
	bottom: var(--space-16);
	display: flex;
	align-items: center;
	justify-content: center;
	gap: var(--space-8, 8px);
}

.tgj-slideshow__dots {
	display: flex;
}

.tgj-slideshow__dot {
	width: 24px;
	height: 24px;
	padding: 0;
	border: 0;
	background: none;
	cursor: pointer;
}

.tgj-slideshow__dot::before {
	content: '';
	display: block;
	width: 8px;
	height: 8px;
	margin: auto;
	border: 1px solid var(--ss-control-fg);
	border-radius: 50%;
	box-shadow: 0 0 2px rgba(0, 0, 0, 0.4);
}

.tgj-slideshow__dot[aria-current="true"]::before {
	background: var(--ss-control-fg);
}

.tgj-slideshow__pause {
	width: 32px;
	height: 32px;
}

.tgj-slideshow__pause .tgj-slideshow__icon-play,
.tgj-slideshow__pause.is-paused .tgj-slideshow__icon-pause {
	display: none;
}

.tgj-slideshow__pause.is-paused .tgj-slideshow__icon-play {
	display: block;
}

/* Row: black 40px circles over the left and right edges of the cards (the
   old Scroller's arrows), laptop up, each gone at its end of the row; phones
   and tablets swipe. Centred on the row; the Scroller moves them to the
   middle of its images. */
.tgj-slideshow__controls--edges {
	display: none;
}

@media (min-width: 1024px) {
	.tgj-slideshow__controls--edges:not([hidden]) {
		display: block;
	}

	.tgj-slideshow__controls--edges .tgj-slideshow__arrow {
		position: absolute;
		z-index: 2;
		top: 50%;
		transform: translateY(-50%);
		width: 40px;
		height: 40px;
		background: var(--tgj-black, #0a0a0a);
		color: var(--tgj-white, #fff);
	}

	.tgj-slideshow__controls--edges .tgj-slideshow__arrow:hover {
		opacity: 0.75;
	}

	.tgj-slideshow__controls--edges .tgj-slideshow__arrow:disabled {
		display: none;
	}

	.tgj-slideshow__controls--edges .tgj-slideshow__arrow--prev { left: -10px; }
	.tgj-slideshow__controls--edges .tgj-slideshow__arrow--next { right: -10px; }
}

/* Row: the Gallery carousel's bar under the row */
.tgj-slideshow__controls--bar {
	display: flex;
	align-items: center;
	gap: var(--space-16);
	margin-top: var(--space-16);
}

.tgj-slideshow__controls--bar .tgj-slideshow__arrow {
	background: none;
	color: inherit;
}

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

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

@media (prefers-reduced-motion: reduce) {
	.tgj-slideshow__track { scroll-behavior: auto; }
	.tgj-slideshow__progress-bar { transition: none; }
}

/* ── Editor ────────────────────────────────────────────────── */

.tgj-slideshow-editor__note {
	margin: 0 0 var(--space-8, 8px);
	font-size: 13px;
	opacity: 0.7;
}

.tgj-slideshow-editor .wp-block[data-type="journal-blocks/tgj-image-background"] {
	margin-block: var(--space-16);
}
