/**
 * Front-end styles for the Project Gallery block.
 *
 * The bento grid layout (.al-bento) and GSAP animation states
 * are inherited from the theme's style.css.
 * This file only adds gallery-specific styles.
 *
 * @package RHM_Atelier_Latitude_Portfolio
 */

/* =========================================================================
   Bento grid — override theme nth-child with explicit sizing classes
   The description card shifts DOM indices, so we use .alp-bento-large
   instead of nth-child to determine which items span 2 cols / 2 rows.
   ========================================================================= */

.alp-gallery-grid.al-bento > *:nth-child(6n+1),
.alp-gallery-grid.al-bento > *:nth-child(6n+5) {
	grid-column: span 1;
	grid-row: span 1;
}

.alp-gallery-grid.al-bento > .alp-bento-large {
	grid-column: span 2;
	grid-row: span 2;
}

@media (max-width: 1024px) {
	.alp-gallery-grid.al-bento > .alp-bento-large {
		grid-column: span 2;
		grid-row: span 1;
	}
}

@media (max-width: 768px) {
	.alp-gallery-grid.al-bento > .alp-bento-large {
		grid-column: span 1;
		grid-row: span 1;
	}
}

/* =========================================================================
   Gallery figures — fill bento cells
   ========================================================================= */

.alp-gallery-figure {
	margin: 0;
	overflow: hidden;
	border-radius: 4px;
	height: 100%;
}

.alp-gallery-figure--image a {
	display: block;
	height: 100%;
	overflow: hidden;
}

.alp-gallery-figure img {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: cover;
	transition: transform 0.6s cubic-bezier(0.33, 1, 0.68, 1);
}

.alp-gallery-figure--image:hover img {
	transform: scale(1.05);
}

/* =========================================================================
   Description card — inserted in bento grid
   ========================================================================= */

.alp-gallery-description {
	position: relative;
	display: flex;
	flex-direction: column;
	justify-content: flex-start;
	padding: var(--wp--preset--spacing--50);
	border-radius: 4px;
	background: var(--wp--preset--color--base);
	grid-row: span 2;
	min-height: 0;
	overflow: hidden;
	opacity: 1 !important;
	transform: none !important;
}

/* Bottom fade indicator — signals scrollable content. */
.alp-gallery-description::after {
	content: "";
	position: absolute;
	left: 0;
	right: 0;
	bottom: 0;
	height: 60px;
	pointer-events: none;
	background: linear-gradient(
		to bottom,
		rgba(255, 255, 255, 0) 0%,
		var(--wp--preset--color--base) 100%
	);
	opacity: 0;
	transition: opacity 0.25s ease;
}

.alp-gallery-description.is-scrollable:not(.is-scrolled-end)::after {
	opacity: 1;
}

/* Standalone mode (no gallery) — no grid properties */
.alp-gallery-description--standalone {
	grid-row: auto;
	overflow: visible;
}

.alp-gallery-description--standalone .alp-gallery-description__text {
	overflow: visible;
	padding-right: 0;
	scrollbar-width: auto;
}

.alp-gallery-description--standalone .alp-gallery-description__text::after {
	display: none;
}

.alp-gallery-description__title {
	font-family: var(--wp--preset--font-family--heading);
	font-size: var(--wp--preset--font-size--large);
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.05em;
	color: var(--wp--preset--color--contrast);
	margin: 0 0 var(--wp--preset--spacing--30);
}

.alp-gallery-description__text {
	font-size: 0.9375rem;
	line-height: 1.7;
	color: var(--wp--preset--color--muted);
	flex: 1 1 auto;
	min-height: 0;
	overflow-y: auto; /* scrollbar appears only when content overflows */
	overscroll-behavior: contain;
}

/* Reserve room for the scrollbar only when the card actually overflows,
   so short descriptions don't show an empty gutter on the right. */
.alp-gallery-description.is-scrollable .alp-gallery-description__text {
	padding-right: 0.5rem;
}

/* WebKit (Chromium / Safari) — force a visible, non-overlay scrollbar.
   IMPORTANT: do NOT set scrollbar-width on this element — modern Chromium
   ignores ::-webkit-scrollbar entirely as soon as scrollbar-width is set,
   which would re-enable the macOS overlay scrollbar (hidden by default). */
.alp-gallery-description__text::-webkit-scrollbar {
	width: 8px;
	height: 8px;
	-webkit-appearance: none;
	appearance: none;
}

.alp-gallery-description__text::-webkit-scrollbar-track {
	background: rgba(0, 0, 0, 0.06);
	border-radius: 4px;
}

.alp-gallery-description__text::-webkit-scrollbar-thumb {
	background: rgba(0, 0, 0, 0.35);
	border-radius: 4px;
}

.alp-gallery-description__text::-webkit-scrollbar-thumb:hover {
	background: rgba(0, 0, 0, 0.55);
}

/* Firefox-only scrollbar styling (scoped via @supports to avoid disabling
   the WebKit rules above on Chromium). */
@supports (-moz-appearance: none) {
	.alp-gallery-description__text {
		scrollbar-width: thin;
		scrollbar-color: rgba(0, 0, 0, 0.35) rgba(0, 0, 0, 0.06);
	}
}

.alp-gallery-description__text p {
	margin: 0 0 1em;
}

.alp-gallery-description__text p:last-child {
	margin-bottom: 0;
}

.alp-gallery-description__text strong {
	font-weight: 700;
}

@media (max-width: 768px) {
	/* Passe la grille en hauteur auto pour que la description prenne sa hauteur naturelle */
	.alp-gallery-grid.al-bento {
		grid-auto-rows: auto;
	}

	/* Les figures images gardent une hauteur fixe explicite */
	.alp-gallery-figure {
		height: 300px;
	}

	.alp-gallery-description {
		padding: var(--wp--preset--spacing--30);
		grid-row: auto;
		overflow: visible;
	}

	/* On mobile the card grows naturally — no inner scroll needed */
	.alp-gallery-description__text {
		overflow: visible;
		padding-right: 0;
		margin-right: 0;
	}
}

/* =========================================================================
   Spacer cells — empty white space in the bento grid
   ========================================================================= */

.alp-gallery-spacer {
	height: 100%;
}

@media (max-width: 768px) {
	.alp-gallery-spacer {
		display: none;
	}
}

/* =========================================================================
   Video embeds
   ========================================================================= */

.alp-video-embed {
	position: relative;
	height: 100%;
	background: #000;
	cursor: pointer;
	overflow: hidden;
}

.alp-video-embed .alp-video-poster {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	object-fit: cover;
}

.alp-video-poster--placeholder {
	background: #1a1a1a;
}

.alp-video-play {
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	background: none;
	border: none;
	cursor: pointer;
	z-index: 2;
	padding: 0;
	transition: transform 0.3s ease, opacity 0.3s ease;
}

.alp-video-play:hover {
	transform: translate(-50%, -50%) scale(1.1);
}

.alp-video-play:focus-visible {
	outline: 2px solid #fff;
	outline-offset: 4px;
	border-radius: 4px;
}

.alp-video-embed.is-playing {
	cursor: default;
	position: relative;
	padding-bottom: 56.25%;
	height: auto;
}

.alp-video-embed.is-playing iframe {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
}

/* When playing, figure should auto-size to fit the iframe */
.alp-gallery-figure--video:has(.is-playing) {
	height: auto;
}

/* =========================================================================
   Self-hosted video
   ========================================================================= */

.alp-video-native {
	width: 100%;
	height: 100%;
	object-fit: cover;
	display: block;
	border-radius: 4px;
}
