/*
 *
 * Copyright (c) 2026 Arnaldo Roman. All rights reserved.
 * Licensed, not sold. See LICENSE. http://www.arnaldoroman.net
 * Gallery plugin - front-end styles.
 *
 * Cards: main image, title and description in a box with a #f1f1f1 background
 * and no border, with space between each one.
 *
 * Gallery page: every image box is the same size and images scale
 * proportionally inside it (object-fit: contain), so nothing is cropped.
 */

.blg-grid,
.blg-gallery-grid {
	display: grid;
	grid-template-columns: repeat(var(--blg-cols, 3), minmax(0, 1fr));
	gap: 20px;
	margin: 1.5rem 0;
}

/* A grid of cards placed inside a paragraph needs to break out of it. */
p > .blg-grid {
	margin: 1.5rem 0;
}

/* Responsive breakpoints: collapse columns on smaller screens. */
@media (max-width: 992px) {
	.blg-grid,
	.blg-gallery-grid {
		grid-template-columns: repeat(min(var(--blg-cols, 3), 3), minmax(0, 1fr));
	}
}

@media (max-width: 768px) {
	.blg-grid,
	.blg-gallery-grid {
		grid-template-columns: repeat(min(var(--blg-cols, 3), 2), minmax(0, 1fr));
	}
}

@media (max-width: 480px) {
	.blg-grid,
	.blg-gallery-grid {
		grid-template-columns: 1fr;
	}
}

/* --- Gallery card shown inside a post --------------------------------- */

/*
 * The card markup is span based (see renderCard()), so every element needs an
 * explicit display. A standalone card is capped so a single gallery does not
 * stretch across the whole content column; inside a grid it fills its cell.
 */
.blg-card-wrap {
	display: block;
	min-width: 0;
	max-width: 480px;
}

.blg-grid .blg-card-wrap {
	max-width: none;
}

.blg-card {
	display: flex;
	flex-direction: column;
	height: 100%;
	background-color: #f1f1f1;
	border: 0;
	border-radius: 6px;
	overflow: hidden;
	text-decoration: none;
	color: inherit;
	cursor: pointer;
	transition: box-shadow 0.2s ease, transform 0.2s ease;
}

.blg-card:hover,
.blg-card:focus,
.blg-card:focus-within {
	text-decoration: none;
	color: inherit;
	box-shadow: 0 6px 18px rgba(0, 0, 0, 0.12);
	transform: translateY(-2px);
}

.blg-card-image {
	display: block;
	width: 100%;
	aspect-ratio: 4 / 3;
	background-color: #e4e4e4;
	overflow: hidden;
}

.blg-card-image img {
	width: 100%;
	height: 100%;
	object-fit: cover;
	display: block;
}

.blg-card-body {
	display: block;
	padding: 14px 16px 16px;
}

.blg-card-title {
	display: block;
	font-size: 1.05rem;
	font-weight: 600;
	line-height: 1.3;
	margin-bottom: 6px;
	color: #222;
}

.blg-card-description {
	display: block;
	font-size: 0.9rem;
	line-height: 1.45;
	color: #555;
}

.blg-card-meta {
	display: block;
	margin-top: 10px;
	font-size: 0.78rem;
	text-transform: uppercase;
	letter-spacing: 0.04em;
	color: #888;
}

/* --- Gallery page ------------------------------------------------------ */

.blg-gallery-page {
	margin-bottom: 2rem;
}

.blg-gallery-description {
	margin-bottom: 1.25rem;
	/* Justified is the readable default; the theme often centres its content. */
	text-align: justify;
}

.blg-gallery-grid {
	align-items: start;
}

.blg-item {
	margin: 0;
	background-color: #f1f1f1;
	border: 0;
	border-radius: 6px;
	overflow: hidden;
}

/*
 * Every image box has the same size and the image fills it. object-fit: cover
 * crops the overflow, so the boxes stay uniform whatever the source proportions.
 */
.blg-item img {
	display: block;
	width: 100%;
	height: 260px;
	object-fit: cover;
	background-color: #e4e4e4;
}

.blg-item-link {
	display: block;
	position: relative;
	z-index: 1;
	cursor: zoom-in;
}

/*
 * Another plugin can wrap a thumbnail in an anchor of its own. Keep any anchor
 * inside a card flush so a stray wrapper cannot add a second border or change
 * the spacing, and keep the thumbnail above it so the click stays ours.
 */
.blg-item a,
.blg-card a {
	text-decoration: none;
	border: 0;
}

.blg-item img,
.blg-card-image img {
	position: relative;
	z-index: 1;
}

.blg-caption {
	display: block;
	padding: 10px 14px 14px;
	/*
	 * A theme that centres its content aligns this text too, because text-align
	 * is inherited, and the captions end up centred inside their boxes. The card
	 * look asks for left aligned text, so set it rather than inherit it.
	 */
	text-align: left;
}

.blg-caption-title {
	display: block;
	font-size: 0.625rem;
	font-weight: 600;
	color: #222;
}

.blg-caption-ref {
	display: block;
	font-size: 0.53125rem;
	text-transform: uppercase;
	letter-spacing: 0.05em;
	color: #777;
	margin-top: 2px;
}

.blg-caption-description {
	display: block;
	font-size: 0.53125rem;
	color: #555;
	margin-top: 6px;
}

.blg-empty {
	padding: 1.5rem;
	background-color: #f1f1f1;
	border-radius: 6px;
}

/* --- Lightbox ---------------------------------------------------------- */

.blg-lightbox {
	position: fixed;
	inset: 0;
	z-index: 9999;
	display: flex;
	align-items: center;
	justify-content: center;
	background-color: rgba(244, 245, 247, 0.94);
	padding: 20px;
}

.blg-lightbox[hidden] {
	display: none;
}

.blg-lightbox-figure {
	margin: 0;
	box-sizing: border-box;
	/* fit-content makes the card hug the photo instead of spanning the overlay. */
	width: fit-content;
	max-width: min(1100px, 92vw);
	max-height: 92vh;
	display: flex;
	flex-direction: column;
	align-items: center;
	background-color: #fff;
	padding: 14px;
	border-radius: 8px;
	border: 1px solid rgba(0, 0, 0, 0.10);
	box-shadow: 0 12px 40px rgba(0, 0, 0, 0.22);
}

/*
 * The image yields space to the caption. Without this an image may take the
 * full 74vh and a description then pushes the caption past the bottom of the
 * window, where nothing can scroll it back into view. The 165px reserve covers
 * the title, the reference, the toggle, the counter and their margins, plus the
 * card padding; the image shrinks by whatever is left over.
 */
.blg-lightbox-image {
	max-width: 100%;
	max-height: min(74vh, calc(92vh - 165px));
	/* Let the image give up height when a long description is expanded. */
	min-height: 0;
	flex-shrink: 1;
	width: auto;
	height: auto;
	object-fit: contain;
	border-radius: 4px;
	background-color: transparent;
}

/*
 * The caption is a flex item, and a flex item shrinks to fit its content. A short
 * title therefore produced a narrow column of text under a wide image: the text
 * wrapped every few words and grew tall enough to scroll. align-self: stretch
 * makes the caption as wide as the image, so the title is centred against the
 * full width and never wraps into a column.
 */
.blg-lightbox-caption {
	margin-top: 14px;
	text-align: center;
	color: #222;
	align-self: stretch;
	max-width: min(1100px, 92vw);
}

.blg-lightbox-title {
	display: block;
	font-size: 0.625rem;
	font-weight: 600;
	line-height: 1.4;
}

/*
 * The reference is a small uppercase line under the title, for a SKU or an
 * internal code. An image without one has the element hidden, so it adds no
 * space of its own.
 */
.blg-lightbox-ref {
	display: block;
	font-size: 0.53125rem;
	text-transform: uppercase;
	letter-spacing: 0.05em;
	color: #777;
	margin-top: 4px;
}

.blg-lightbox-description {
	display: block;
	font-size: 0.53125rem;
	color: #444;
	margin-top: 8px;
	line-height: 1.5;
}

/*
 * The clamp is what keeps a long description from growing the caption past the
 * space reserved under the image. It holds four and a half lines; the toggle
 * reveals the rest.
 */
.blg-lightbox-description-clamped {
	max-height: 4.5em;
	overflow: hidden;
}

.blg-lightbox-more {
	display: inline-block;
	margin-top: 6px;
	padding: 0;
	background: none;
	border: 0;
	color: #0b62c4;
	font-size: 0.53125rem;
	text-decoration: underline;
	cursor: pointer;
}

.blg-lightbox-more[hidden] {
	display: none;
}

.blg-lightbox-counter {
	display: block;
	margin-top: 4px;
	font-size: 0.53125rem;
	color: #888;
}

/*
 * The controls are bare glyphs over the dark backdrop: no disc behind them, so
 * nothing boxes in the arrow or the closing cross. They keep a large invisible
 * hit area for touch.
 */
/*
	 * appearance: none is load-bearing. Zeroing border and background is not enough
	 * on macOS Safari, which still paints native button chrome (a bezel and a focus
	 * ring) around a button that keeps the default appearance. Linux WebKit and
	 * Chromium do not, so this only shows on a real Mac.
	 */
/*
	 * The multi-part selector is deliberate: a theme that styles bare button
	 * elements outranks a single class, and such a rule paints a box around these
	 * glyphs. The resets below cover every property that can draw one, including
	 * those Safari applies from its own default button appearance.
	 */
.blg-lightbox .blg-lightbox-button,
.blg-lightbox .blg-lightbox-button:hover,
.blg-lightbox .blg-lightbox-button:focus,
.blg-lightbox .blg-lightbox-button:focus-visible,
.blg-lightbox .blg-lightbox-button:active {
	position: absolute;
	padding: 0;
	background: none;
	border: 0;
	outline: 0;
	box-shadow: none;
	appearance: none;
	-webkit-appearance: none;
	background-image: none;
	border-radius: 0;
	color: rgba(0, 0, 0, 0.55);
	width: 48px;
	height: 48px;
	font-size: 2rem;
	line-height: 1;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	text-shadow: 0 1px 4px rgba(255, 255, 255, 0.85);
	transition: color 0.15s ease, transform 0.15s ease;
}

.blg-lightbox .blg-lightbox-button:hover,
.blg-lightbox .blg-lightbox-button:focus {
	color: #000;
}

.blg-lightbox-close {
	top: 10px;
	right: 10px;
	font-size: 2.4rem;
}

.blg-lightbox-prev {
	left: 0;
	top: 50%;
	transform: translateY(-50%);
}

.blg-lightbox-prev:hover,
.blg-lightbox-prev:focus {
	transform: translateY(-50%) scale(1.08);
}

.blg-lightbox-next {
	right: 0;
	top: 50%;
	transform: translateY(-50%);
}

.blg-lightbox-next:hover,
.blg-lightbox-next:focus {
	transform: translateY(-50%) scale(1.08);
}

/* Prevent the page behind the lightbox from scrolling. */
body.blg-lightbox-open {
	overflow: hidden;
}

@media (max-width: 576px) {
	.blg-item img {
		height: 200px;
	}

	.blg-lightbox {
		padding: 10px;
	}

	.blg-lightbox-figure {
		max-height: 96vh;
	}

	.blg-lightbox-image {
		max-height: 52vh;
	}

	.blg-lightbox-caption {
		margin-top: 8px;
	}

	/*
	 * On a phone the arrows sit over the photo. That is fine: the shadow keeps
	 * the glyph legible on a light image, and a swipe is the natural gesture.
	 */
	.blg-lightbox-prev {
		left: 6px;
	}

	.blg-lightbox-next {
		right: 6px;
	}

	.blg-lightbox-close {
		font-size: 2rem;
	}
}