/**
 * Accessible Photo Gallery — front-end styles.
 *
 * Design notes:
 * - Every color/spacing value is a CSS custom property with a WCAG 2.2 AA
 *   compliant fallback, so the gallery is safe out of the box and fully
 *   restylable from Settings > Photo Gallery or a theme stylesheet.
 * - --pgal-font defaults to "inherit" so the gallery always matches the
 *   surrounding theme's font unless explicitly overridden.
 * - All type sizes use rem/em so the layout respects user browser zoom
 *   and OS text-size settings (WCAG 1.4.4 Resize Text).
 * - Interactive targets are at least 44x44px (exceeds the WCAG 2.2 2.5.8
 *   24px minimum). Focus states use a highly visible outline (2.4.7,
 *   2.4.11) and are never removed without a visible replacement.
 * - The gallery renders on a solid background (a card), never transparent.
 * - Respects prefers-reduced-motion.
 */

.pgal-gallery-wrap {
	--pgal-font: inherit;
	--pgal-color-primary: #1d4ed8;
	--pgal-color-primary-contrast: #ffffff;
	--pgal-color-text: #1f2933;
	--pgal-color-bg: #ffffff;
	--pgal-color-border: #d7dce1;
	--pgal-color-muted: #5b6b79;
	--pgal-color-overlay: rgba(17, 24, 33, 0.92);
	--pgal-color-focus: #0b3ea8;
	--pgal-radius: 8px;

	font-family: var(--pgal-font);
	color: var(--pgal-color-text);
	background: var(--pgal-color-bg);
	border: 1px solid var(--pgal-color-border);
	border-radius: var(--pgal-radius);
	padding: 1.25rem;
	max-width: 100%;
	box-sizing: border-box;
	line-height: 1.5;
	overflow-wrap: break-word;
	word-break: break-word;
}

.pgal-gallery-wrap *,
.pgal-gallery-wrap *::before,
.pgal-gallery-wrap *::after {
	box-sizing: inherit;
	font-family: inherit;
}

.pgal-gallery-wrap h2,
.pgal-gallery-wrap h3,
.pgal-gallery-wrap h4 {
	font-family: inherit;
	color: var(--pgal-color-text);
	margin: 0 0 0.5em;
}

.pgal-gallery-wrap a {
	color: var(--pgal-color-primary);
}

.pgal-gallery-wrap p {
	margin: 0 0 0.75em;
}

/* Visually hidden but available to screen readers (WCAG 4.1.2 / 1.3.1) */
.pgal-visually-hidden {
	position: absolute !important;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}

/* Universal focus visibility (WCAG 2.4.7 Focus Visible) */
.pgal-gallery-wrap a:focus-visible,
.pgal-gallery-wrap button:focus-visible,
.pgal-gallery-wrap [tabindex]:focus-visible {
	outline: 3px solid var(--pgal-color-focus);
	outline-offset: 2px;
	border-radius: 2px;
}

/* The lightbox sits on a dark overlay regardless of theme, so its own
   controls always use a high-contrast white outline rather than the
   (potentially dark) configurable focus color. */
.pgal-lightbox-btn:focus-visible {
	outline: 3px solid #ffffff;
	outline-offset: 3px;
}

@media (prefers-reduced-motion: reduce) {
	.pgal-gallery-wrap *,
	.pgal-lightbox * {
		animation-duration: 0.001ms !important;
		animation-iteration-count: 1 !important;
		transition-duration: 0.001ms !important;
	}
}

/* -------------------- No-albums / empty states -------------------- */

.pgal-no-albums {
	color: var(--pgal-color-muted);
	font-style: italic;
}

.pgal-empty-cta {
	margin-top: 0.5rem;
}

/* -------------------- Buttons -------------------- */

.pgal-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-height: 44px;
	padding: 0.5rem 1.1rem;
	border-radius: var(--pgal-radius);
	text-decoration: none;
	font-weight: 600;
	border: 2px solid var(--pgal-color-primary);
	margin: 0.25rem 0.5rem 0.25rem 0;
}

.pgal-btn-primary {
	background: var(--pgal-color-primary);
	color: var(--pgal-color-primary-contrast);
}

.pgal-btn-primary:hover {
	filter: brightness(0.92);
}

.pgal-btn-secondary {
	background: transparent;
	color: var(--pgal-color-primary);
}

.pgal-btn-secondary:hover {
	background: var(--pgal-color-bg);
	filter: brightness(0.96);
}

/* -------------------- Back navigation -------------------- */

.pgal-back-nav {
	margin: 0 0 1.25rem;
}

.pgal-back-link {
	display: inline-flex;
	align-items: center;
	gap: 0.4rem;
	min-height: 44px;
	padding: 0.5rem 0.9rem;
	text-decoration: none;
	font-weight: 600;
	color: var(--pgal-color-primary);
	border: 1px solid var(--pgal-color-border);
	border-radius: var(--pgal-radius);
}

.pgal-back-link:hover {
	border-color: var(--pgal-color-primary);
	background: color-mix(in srgb, var(--pgal-color-primary) 8%, transparent);
}

/* -------------------- Album header -------------------- */

.pgal-album-title {
	font-size: 1.4rem;
}

.pgal-album-description {
	color: var(--pgal-color-muted);
}

/* -------------------- Album tiles -------------------- */

.pgal-tiles {
	list-style: none;
	margin: 0;
	padding: 0;
	display: grid;
	grid-template-columns: repeat(var(--pgal-columns, 3), 1fr);
	gap: 1rem;
}

.pgal-tile-link {
	display: flex;
	flex-direction: column;
	height: 100%;
	text-decoration: none;
	color: inherit;
	border: 1px solid var(--pgal-color-border);
	border-radius: var(--pgal-radius);
	overflow: hidden;
	background: var(--pgal-color-bg);
}

.pgal-tile-link:hover {
	border-color: var(--pgal-color-primary);
}

.pgal-tile-cover {
	display: block;
	aspect-ratio: 4 / 3;
	background: var(--pgal-color-border);
	overflow: hidden;
}

.pgal-tile-cover img {
	width: 100%;
	height: 100%;
	object-fit: cover;
	display: block;
}

.pgal-tile-body {
	padding: 0.85rem 1rem;
	display: flex;
	flex-direction: column;
	gap: 0.25rem;
	flex: 1;
}

.pgal-tile-title {
	font-weight: 700;
}

.pgal-tile-count {
	font-size: 0.85rem;
	color: var(--pgal-color-muted);
}

/* -------------------- Album list -------------------- */

.pgal-list {
	list-style: none;
	margin: 0;
	padding: 0;
	display: flex;
	flex-direction: column;
	gap: 0.6rem;
}

.pgal-list-link {
	display: flex;
	align-items: center;
	gap: 0.85rem;
	min-height: 44px;
	padding: 0.6rem 0.85rem;
	text-decoration: none;
	color: inherit;
	border: 1px solid var(--pgal-color-border);
	border-radius: var(--pgal-radius);
	background: var(--pgal-color-bg);
}

.pgal-list-link:hover {
	border-color: var(--pgal-color-primary);
}

.pgal-list-thumb {
	flex: 0 0 auto;
	width: 56px;
	height: 56px;
	border-radius: var(--pgal-radius);
	overflow: hidden;
}

.pgal-list-thumb img {
	width: 100%;
	height: 100%;
	object-fit: cover;
	display: block;
}

.pgal-list-text {
	display: flex;
	flex-direction: column;
	gap: 0.15rem;
	min-width: 0;
}

.pgal-list-title {
	font-weight: 700;
}

.pgal-list-count {
	font-size: 0.85rem;
	color: var(--pgal-color-muted);
}

/* -------------------- Shared cover/thumb placeholder -------------------- */

.pgal-default-cover {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 100%;
	height: 100%;
	background: var(--pgal-color-border);
	color: var(--pgal-color-muted);
}

/* -------------------- Single-album image grid -------------------- */

.pgal-image-grid {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
	gap: 0.75rem;
}

.pgal-image-btn {
	display: block;
	width: 100%;
	aspect-ratio: 1 / 1;
	padding: 0;
	border: 1px solid var(--pgal-color-border);
	border-radius: var(--pgal-radius);
	overflow: hidden;
	background: var(--pgal-color-border);
	cursor: pointer;
}

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

.pgal-image-btn:hover {
	border-color: var(--pgal-color-primary);
}

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

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

.pgal-lightbox {
	position: fixed;
	inset: 0;
	z-index: 100000;
}

.pgal-lightbox-overlay {
	position: absolute;
	inset: 0;
	background: var(--pgal-color-overlay);
	border: 0;
	padding: 0;
	margin: 0;
}

.pgal-lightbox-dialog {
	position: relative;
	z-index: 1;
	height: 100%;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 2rem;
	box-sizing: border-box;
}

.pgal-lightbox-body {
	max-width: min(90vw, 1100px);
	max-height: 85vh;
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 0.75rem;
}

.pgal-lightbox-image {
	max-width: 100%;
	max-height: 75vh;
	object-fit: contain;
	border-radius: calc(var(--pgal-radius) / 2);
	background: #000;
	display: block;
}

.pgal-lightbox-caption {
	color: #ffffff;
	text-align: center;
	max-width: 60ch;
	margin: 0;
}

.pgal-lightbox-btn {
	position: absolute;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 44px;
	min-height: 44px;
	border: 0;
	border-radius: 50%;
	background: rgba(255, 255, 255, 0.15);
	color: #ffffff;
	font-size: 1.5rem;
	line-height: 1;
	cursor: pointer;
}

.pgal-lightbox-btn:hover {
	background: rgba(255, 255, 255, 0.3);
}

.pgal-lightbox-close {
	top: 1rem;
	right: 1rem;
}

.pgal-lightbox-prev {
	left: 1rem;
	top: 50%;
	transform: translateY(-50%);
}

.pgal-lightbox-next {
	right: 1rem;
	top: 50%;
	transform: translateY(-50%);
}

/* -------------------- Small-screen refinements -------------------- */

@media (max-width: 720px) {
	.pgal-tiles {
		grid-template-columns: repeat(2, 1fr);
	}
}

@media (max-width: 480px) {
	.pgal-gallery-wrap {
		padding: 0.85rem;
	}

	.pgal-tiles {
		grid-template-columns: 1fr;
	}

	.pgal-list-thumb {
		width: 44px;
		height: 44px;
	}

	.pgal-image-grid {
		grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
		gap: 0.5rem;
	}

	.pgal-lightbox-dialog {
		padding: 0.75rem;
	}

	.pgal-lightbox-prev,
	.pgal-lightbox-next {
		min-width: 40px;
		min-height: 40px;
	}

	.pgal-lightbox-close {
		top: 0.5rem;
		right: 0.5rem;
	}
}
