/**
 * Gallery System — front-end styles
 * Responsive multi-album gallery + lightbox
 */

/* -------------------------------------------------------------------------- */
/* Design tokens
/* -------------------------------------------------------------------------- */

.gs-gallery {
	--gs-bg: #f6f5f3;
	--gs-surface: #ffffff;
	--gs-ink: #1a1a1a;
	--gs-ink-muted: #5c5c5c;
	--gs-line: rgba(26, 26, 26, 0.1);
	--gs-accent: #0f4c5c;
	--gs-accent-soft: rgba(15, 76, 92, 0.08);
	--gs-radius: 14px;
	--gs-radius-sm: 10px;
	--gs-shadow: 0 10px 30px rgba(26, 26, 26, 0.08);
	--gs-gap: clamp(0.75rem, 2vw, 1.25rem);
	--gs-ease: cubic-bezier(0.22, 1, 0.36, 1);
	--gs-font: "Segoe UI", system-ui, -apple-system, sans-serif;

	position: relative;
	color: var(--gs-ink);
	font-family: var(--gs-font);
	isolation: isolate;
	margin: 1.5rem 0;
}

.gs-gallery *,
.gs-gallery *::before,
.gs-gallery *::after {
	box-sizing: border-box;
}

/* -------------------------------------------------------------------------- */
/* Header / filters
/* -------------------------------------------------------------------------- */

.gs-gallery__header {
	margin-bottom: 1.25rem;
}

.gs-gallery__title {
	margin: 0 0 1rem;
	font-size: clamp(1.35rem, 2.5vw, 1.85rem);
	font-weight: 650;
	letter-spacing: -0.02em;
	line-height: 1.2;
}

.gs-gallery__toolbar {
	display: flex;
	flex-direction: column;
	gap: 0.85rem;
}

.gs-gallery__filters {
	display: grid;
	grid-template-columns: 1fr;
	gap: 0.75rem;
	padding: 0.85rem;
	background: var(--gs-surface);
	border: 1px solid var(--gs-line);
	border-radius: var(--gs-radius);
	box-shadow: var(--gs-shadow);
}

@media (min-width: 560px) {
	.gs-gallery__filters {
		grid-template-columns: minmax(8rem, 10rem) 1fr;
		align-items: end;
		padding: 1rem 1.1rem;
	}
}

.gs-gallery__filter {
	display: flex;
	flex-direction: column;
	gap: 0.35rem;
	margin: 0;
}

.gs-gallery__filter-label {
	font-size: 0.72rem;
	font-weight: 650;
	letter-spacing: 0.06em;
	text-transform: uppercase;
	color: var(--gs-ink-muted);
}

.gs-gallery__select,
.gs-gallery__search {
	width: 100%;
	min-height: 44px;
	padding: 0.55rem 0.75rem;
	border: 1px solid var(--gs-line);
	border-radius: var(--gs-radius-sm);
	background: var(--gs-bg);
	color: var(--gs-ink);
	font: inherit;
	font-size: 0.95rem;
	transition: border-color 0.2s var(--gs-ease), box-shadow 0.2s var(--gs-ease);
}

.gs-gallery__select:focus,
.gs-gallery__search:focus {
	outline: none;
	border-color: var(--gs-accent);
	box-shadow: 0 0 0 3px var(--gs-accent-soft);
}

.gs-gallery__viewbar {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 0.75rem 1rem;
	padding: 0.75rem 0.1rem;
	animation: gs-fade-up 0.35s var(--gs-ease) both;
}

.gs-gallery__back {
	display: inline-flex;
	align-items: center;
	gap: 0.4rem;
	min-height: 44px;
	padding: 0.45rem 0.9rem;
	border: 1px solid var(--gs-line);
	border-radius: 999px;
	background: var(--gs-surface);
	color: var(--gs-ink);
	font: inherit;
	font-size: 0.9rem;
	font-weight: 600;
	cursor: pointer;
	transition: background 0.2s var(--gs-ease), border-color 0.2s var(--gs-ease),
		transform 0.2s var(--gs-ease);
	touch-action: manipulation;
}

.gs-gallery__back:hover {
	background: var(--gs-accent-soft);
	border-color: rgba(15, 76, 92, 0.25);
}

.gs-gallery__back:active {
	transform: scale(0.98);
}

.gs-gallery__back-icon {
	font-size: 1.05rem;
	line-height: 1;
}

.gs-gallery__album-meta {
	min-width: 0;
	flex: 1;
}

.gs-gallery__album-title {
	margin: 0;
	font-size: clamp(1.1rem, 2vw, 1.4rem);
	font-weight: 650;
	letter-spacing: -0.015em;
	line-height: 1.25;
}

.gs-gallery__album-stats {
	margin: 0.2rem 0 0;
	font-size: 0.88rem;
	color: var(--gs-ink-muted);
}

/* -------------------------------------------------------------------------- */
/* Status / loading
/* -------------------------------------------------------------------------- */

.gs-gallery__status {
	min-height: 0;
	margin: 0 0 0.5rem;
	font-size: 0.9rem;
	color: var(--gs-ink-muted);
}

.gs-gallery__status:empty {
	display: none;
}

.gs-gallery__loading {
	position: absolute;
	inset: 0;
	z-index: 5;
	display: none;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 0.65rem;
	background: rgba(246, 245, 243, 0.72);
	backdrop-filter: blur(2px);
	border-radius: var(--gs-radius);
	font-size: 0.9rem;
	color: var(--gs-ink-muted);
}

/* Only show while loading — display:flex must not override [hidden] */
.gs-gallery.is-loading .gs-gallery__loading {
	display: flex;
}

.gs-gallery__loading[hidden] {
	display: none !important;
}

.gs-gallery.is-loading .gs-gallery__body {
	pointer-events: none;
	opacity: 0.55;
	transition: opacity 0.25s var(--gs-ease);
}

.gs-gallery__spinner {
	width: 28px;
	height: 28px;
	border: 2.5px solid rgba(15, 76, 92, 0.18);
	border-top-color: var(--gs-accent);
	border-radius: 50%;
	animation: gs-spin 0.7s linear infinite;
}

@keyframes gs-spin {
	to {
		transform: rotate(360deg);
	}
}

@keyframes gs-fade-up {
	from {
		opacity: 0;
		transform: translateY(10px);
	}
	to {
		opacity: 1;
		transform: translateY(0);
	}
}

/* -------------------------------------------------------------------------- */
/* Album grid
/* -------------------------------------------------------------------------- */

.gs-gallery__body {
	position: relative;
	min-height: 8rem;
	transition: opacity 0.25s var(--gs-ease);
}

.gs-gallery__grid,
.gs-gallery__photo-grid {
	display: grid;
	gap: var(--gs-gap);
	grid-template-columns: repeat(2, minmax(0, 1fr));
	align-items: start;
}

@media (min-width: 600px) {
	.gs-gallery__grid {
		grid-template-columns: repeat(3, minmax(0, 1fr));
	}

	.gs-gallery__photo-grid {
		grid-template-columns: repeat(3, minmax(0, 1fr));
	}
}

@media (min-width: 960px) {
	.gs-gallery__grid {
		grid-template-columns: repeat(4, minmax(0, 1fr));
	}

	.gs-gallery__photo-grid {
		grid-template-columns: repeat(4, minmax(0, 1fr));
	}
}

@media (min-width: 1280px) {
	.gs-gallery__photo-grid {
		grid-template-columns: repeat(5, minmax(0, 1fr));
	}
}

.gs-gallery__empty {
	margin: 2rem 0;
	padding: 1.5rem;
	text-align: center;
	color: var(--gs-ink-muted);
	background: var(--gs-surface);
	border: 1px dashed var(--gs-line);
	border-radius: var(--gs-radius);
}

.gs-gallery__desc {
	margin: 0 0 1rem;
	color: var(--gs-ink-muted);
	font-size: 0.98rem;
	line-height: 1.55;
	animation: gs-fade-up 0.35s var(--gs-ease) both;
}

.gs-gallery__desc:empty,
.gs-gallery__desc[hidden] {
	display: none;
}

/* -------------------------------------------------------------------------- */
/* Album card
/* -------------------------------------------------------------------------- */

.gs-album-card {
	display: flex;
	flex-direction: column;
	padding: 0;
	border: 1px solid var(--gs-line);
	border-radius: var(--gs-radius);
	background: var(--gs-surface);
	color: inherit;
	text-align: left;
	overflow: hidden;
	cursor: pointer;
	box-shadow: var(--gs-shadow);
	animation: gs-fade-up 0.45s var(--gs-ease) both;
	animation-delay: var(--gs-stagger, 0s);
	transition: transform 0.28s var(--gs-ease), box-shadow 0.28s var(--gs-ease),
		border-color 0.28s var(--gs-ease);
	touch-action: manipulation;
	-webkit-tap-highlight-color: transparent;
}

.gs-album-card:hover,
.gs-album-card:focus-visible {
	transform: translateY(-3px);
	border-color: rgba(15, 76, 92, 0.28);
	box-shadow: 0 16px 36px rgba(26, 26, 26, 0.12);
	outline: none;
}

.gs-album-card:active {
	transform: translateY(-1px) scale(0.995);
}

.gs-album-card__media {
	position: relative;
	display: block;
	overflow: hidden;
	background: transparent;
	line-height: 0;
}

.gs-album-card__img {
	display: block;
	width: 100%;
	height: auto;
	max-width: 100%;
	vertical-align: top;
	object-fit: unset;
}

.gs-album-card:hover .gs-album-card__img {
	transform: none;
}

.gs-album-card__img--empty {
	display: block;
	width: 100%;
	aspect-ratio: 4 / 3;
	background:
		radial-gradient(circle at 30% 30%, rgba(255, 255, 255, 0.55), transparent 50%),
		linear-gradient(145deg, #cfd8dc, #90a4ae);
}

.gs-album-card__count {
	position: absolute;
	right: 0.55rem;
	bottom: 0.55rem;
	padding: 0.28rem 0.55rem;
	border-radius: 999px;
	background: rgba(15, 20, 24, 0.72);
	color: #fff;
	font-size: 0.72rem;
	font-weight: 600;
	letter-spacing: 0.01em;
	backdrop-filter: blur(4px);
}

.gs-album-card__body {
	display: flex;
	flex-direction: column;
	gap: 0.2rem;
	padding: 0.8rem 0.85rem 0.95rem;
}

.gs-album-card__name {
	font-size: 0.98rem;
	font-weight: 650;
	line-height: 1.3;
	letter-spacing: -0.01em;
}

.gs-album-card__year {
	font-size: 0.82rem;
	color: var(--gs-ink-muted);
}

/* -------------------------------------------------------------------------- */
/* Photo cards
/* -------------------------------------------------------------------------- */

.gs-photo-card {
	position: relative;
	display: block;
	padding: 0;
	border: 0;
	border-radius: var(--gs-radius-sm);
	overflow: hidden;
	background: transparent;
	line-height: 0;
	cursor: zoom-in;
	animation: gs-fade-up 0.4s var(--gs-ease) both;
	animation-delay: var(--gs-stagger, 0s);
	transition: transform 0.25s var(--gs-ease), box-shadow 0.25s var(--gs-ease);
	touch-action: manipulation;
	-webkit-tap-highlight-color: transparent;
}

.gs-photo-card img {
	display: block;
	width: 100%;
	height: auto;
	max-width: 100%;
	vertical-align: top;
}

.gs-photo-card:hover,
.gs-photo-card:focus-visible {
	transform: translateY(-2px);
	box-shadow: var(--gs-shadow);
	outline: none;
	z-index: 1;
}

.gs-photo-card:hover img,
.gs-photo-card:focus-visible img {
	transform: none;
}

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

body.gs-lightbox-open {
	overflow: hidden;
}

.gs-lightbox {
	position: fixed;
	inset: 0;
	z-index: 100000;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: env(safe-area-inset-top, 0) env(safe-area-inset-right, 0)
		env(safe-area-inset-bottom, 0) env(safe-area-inset-left, 0);
}

.gs-lightbox[hidden] {
	display: none !important;
}

.gs-lightbox__backdrop {
	position: absolute;
	inset: 0;
	background: rgba(10, 12, 14, 0.88);
	backdrop-filter: blur(4px);
	animation: gs-fade-in 0.2s ease both;
}

.gs-lightbox__panel {
	position: relative;
	z-index: 1;
	display: flex;
	align-items: center;
	justify-content: center;
	width: min(100vw, 1200px);
	height: 100%;
	max-height: 100dvh;
	padding: 3.5rem 0.5rem 4.5rem;
	animation: gs-zoom-in 0.28s var(--gs-ease) both;
}

@media (min-width: 700px) {
	.gs-lightbox__panel {
		padding: 3rem 3.5rem 4.25rem;
	}
}

.gs-lightbox__figure {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	margin: 0;
	max-width: 100%;
	max-height: 100%;
	min-width: 0;
}

.gs-lightbox__img {
	display: block;
	max-width: 100%;
	max-height: calc(100dvh - 8.5rem);
	width: auto;
	height: auto;
	object-fit: contain;
	border-radius: 4px;
	box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
	transition: opacity 0.2s ease;
}

.gs-lightbox__img.is-loading {
	opacity: 0.35;
}

.gs-lightbox__caption {
	display: flex;
	flex-wrap: wrap;
	justify-content: space-between;
	align-items: baseline;
	gap: 0.35rem 1rem;
	width: min(100%, 720px);
	margin-top: 0.75rem;
	padding: 0 0.5rem;
	color: rgba(255, 255, 255, 0.88);
	font-size: 0.9rem;
	line-height: 1.4;
}

.gs-lightbox__counter {
	opacity: 0.7;
	font-variant-numeric: tabular-nums;
	white-space: nowrap;
}

.gs-lightbox__close,
.gs-lightbox__nav {
	position: absolute;
	z-index: 2;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	border: 0;
	border-radius: 999px;
	background: rgba(255, 255, 255, 0.12);
	color: #fff;
	cursor: pointer;
	transition: background 0.2s ease, transform 0.2s ease;
	touch-action: manipulation;
	-webkit-tap-highlight-color: transparent;
}

.gs-lightbox__close:hover,
.gs-lightbox__nav:hover {
	background: rgba(255, 255, 255, 0.22);
}

.gs-lightbox__close:active,
.gs-lightbox__nav:active {
	transform: scale(0.96);
}

.gs-lightbox__close {
	top: max(0.75rem, env(safe-area-inset-top, 0.75rem));
	right: max(0.75rem, env(safe-area-inset-right, 0.75rem));
	width: 44px;
	height: 44px;
	font-size: 1.6rem;
	line-height: 1;
}

.gs-lightbox__nav {
	top: 50%;
	width: 44px;
	height: 44px;
	font-size: 1.75rem;
	line-height: 1;
	transform: translateY(-50%);
}

.gs-lightbox__nav--prev {
	left: max(0.4rem, env(safe-area-inset-left, 0.4rem));
}

.gs-lightbox__nav--next {
	right: max(0.4rem, env(safe-area-inset-right, 0.4rem));
}

.gs-lightbox__nav:disabled {
	opacity: 0.35;
	cursor: default;
}

@keyframes gs-fade-in {
	from {
		opacity: 0;
	}
	to {
		opacity: 1;
	}
}

@keyframes gs-zoom-in {
	from {
		opacity: 0;
		transform: scale(0.97);
	}
	to {
		opacity: 1;
		transform: scale(1);
	}
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
	.gs-gallery *,
	.gs-lightbox * {
		animation-duration: 0.01ms !important;
		animation-iteration-count: 1 !important;
		transition-duration: 0.01ms !important;
	}
}
