/* Global Reset & Basic Styling */
* {
	margin: 0;
	padding: 0;
	box-sizing: border-box;
}

html {
	overflow-x: clip; /* clip, not hidden — doesn't create a scroll container */
}

body {
	font-family:
		-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial,
		sans-serif;
	background-color: #ffffff;
	color: #333;
	line-height: 1.6;
}

/* Gallery-specific banner — back button + page title.
   Sits below the shared site-header, outside the nav. */
.gallery-page-banner {
	display: flex;
	align-items: center;
	gap: 1.5rem;
	padding: 0.75rem 1.5rem;
	border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}

.btn-gallery-nav-back {
	padding: 0.4rem 0.875rem;
	cursor: pointer;
	border: 1px solid rgba(0, 0, 0, 0.15);
	border-radius: 6px;
	background-color: transparent;
	font-size: 0.875rem;
	color: #333;
	white-space: nowrap;
	flex-shrink: 0;
	transition: background-color 0.15s ease;
}

.btn-gallery-nav-back:hover {
	background-color: rgba(0, 0, 0, 0.05);
}

.gallery-page-title {
	flex: 1;
	text-align: center;
}

.gallery-page-title h1 {
	font-size: 1.25rem;
	font-weight: 600;
	line-height: 1.2;
	color: #111;
}

.gallery-page-title p {
	font-size: 0.8125rem;
	color: #666;
	line-height: 1;
	margin-top: 0.2rem;
}

/* --- New Thumbnail Section Styles --- */
.thumbnails-wrapper {
	width: 90%;
	max-width: 1400px;
	margin: 2rem auto 5rem;
}

.thumbnails-sections {
	display: grid;
	/* Force 7 columns on desktop */
	grid-template-columns: repeat(7, 1fr);
	gap: 1.5rem;
}

.sectional-area {
	display: flex;
	flex-direction: column;
	gap: 0.75rem;
	cursor: pointer;
	text-align: center;
}

.box {
	width: 100%;
	aspect-ratio: 3 / 2;
	border-radius: 4px;
	overflow: hidden;
	background: #f0f0f0;
}

.box img {
	width: 100%;
	height: 100%;
	object-fit: cover;
	transition: transform 0.3s ease;
}

.sectional-area:hover .box img {
	transform: scale(1.05);
}

.sectional-area-title {
	font-size: 0.85rem;
	font-weight: 500;
	text-transform: uppercase;
	letter-spacing: 0.5px;
	text-align: left;
	padding-left: 2px;
}

/* Center all category sections on the page */
.category-section {
	display: flex;
	flex-direction: row;
	gap: 4rem;
	padding: 6rem 0;
	border-bottom: 1px solid #b0adad;

	/* Centering logic */
	width: 90%;
	max-width: 1400px; /* Limits the spread on ultra-wide screens */
	margin: 0 auto;
	justify-content: center;
	align-items: flex-start;
}

/* Ensure the info and grid occupy their space proportionally */
.category-info {
	/* border: 1px solid red; */
	flex: 0 0 300px; /* Fixed width for title/desc area */
	display: flex;
	flex-direction: column;
	position: sticky;
	top: 140px; /* Distance from the top of the screen where it 'pins' */
	height: fit-content;
}

.category-title {
	text-align: Left;
	margin-bottom: 2rem;
	font-weight: 300;
	letter-spacing: 1px;
}

.category-description {
}

.grid-container {
	flex: 1; /* Takes up all remaining space in the 1400px container */
	display: grid;
	grid-template-columns: repeat(2, 1fr);
	grid-auto-rows: 300px;
	grid-auto-flow: dense;
	gap: 1.5rem;

	/* content-visibility: auto removed — it uses contain-intrinsic-size placeholder
	   heights for off-screen sections, which breaks scroll-to calculations since
	   getBoundingClientRect returns positions based on placeholders, not actual
	   rendered heights. Images use loading="lazy" for performance instead. */
}

/* 4. Spanning logic to make the 2-column grid interesting */
.grid-item.wide {
	grid-column: span 2;
} /* One image takes full width */
.grid-item.tall {
	grid-row: span 2;
} /* One image takes double height */
.grid-item.big {
	grid-column: span 2;
	grid-row: span 2;
} /* Large feature image */

/* 5. Item & Image specific fixes */
.grid-item {
	/* border: 1px solid blue; */
	cursor: pointer;
	position: relative;
	overflow: hidden;
	border-radius: 4px;
	width: 100%;
	height: 100%; /* Important: makes item fill the grid-auto-rows height */
}

.grid-img {
	width: 100%;
	height: 100%;
	object-fit: cover;
	object-position: center;

	/* Animation Start */
	opacity: 0;
	transform: translateY(10px);
	transition:
		opacity 0.8s ease-out,
		transform 0.8s cubic-bezier(0.165, 0.84, 0.44, 1);
}

/* State triggered by the 'onload' event in your JS */
.grid-img.loaded {
	opacity: 1;
	transform: translateY(0);
}

/* Subtle Hover Effect */
.grid-item:hover .grid-img.loaded {
	transform: scale(1.03);
}

/* Back to top button */
.back-to-top {
	position: fixed;
	bottom: 2rem;
	right: 2rem;
	width: 3rem;
	height: 3rem;
	border-radius: 50%;
	background: #333;
	color: white;
	border: none;
	cursor: pointer;
	font-size: 1.5rem;
	display: flex;
	align-items: center;
	justify-content: center;
	/* Hidden by default */
	opacity: 0;
	visibility: hidden;
	transition: all 0.3s ease;
	z-index: 1000;
	box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.back-to-top.visible {
	opacity: 1;
	visibility: visible;
}

.back-to-top:hover {
	background: #000;
	transform: translateY(-3px);
}

/* End - Back to top button */

/* Disable background scrolling when modal is open */
body.modal-open {
	overflow: hidden;
}

.modal-overlay {
	position: fixed;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	background-color: rgba(255, 255, 255, 0.98);
	background-color: rgba(0, 0, 0, 0.98);
	z-index: 2000;

	/* Performance logic: Invisible but exists in layout */
	opacity: 0;
	visibility: hidden;
	pointer-events: none; /* Prevents clicking through to the modal while hidden */

	/* Smooth transition without triggering a layout shift */
	transition:
		opacity 0.4s ease,
		visibility 0.4s ease;
	will-change: opacity;

	display: flex;
	flex-direction: column;
}

/* Active State */
.modal-overlay.active {
	opacity: 1;
	visibility: visible;
	pointer-events: auto; /* Re-enables interaction */
}

/* Modal Header with Grid for perfect centering */
.modal-header {
	display: flex;
	flex-direction: row;
	align-items: center;
	justify-content: space-between;
	padding: 1.5rem 2rem;
	width: 100%;
}

.modal-close-btn {
	flex: 1; /* Takes up 1/3 of space */
	background: none;
	border: none;
	font-size: 3rem;
	cursor: pointer;
	line-height: 1;
	color: #333;
	color: #fff;
	text-align: left;
}

.modal-count {
	flex: 1; /* Takes up 1/3 of space */
	text-align: center;
	font-size: 1.2rem;
	font-weight: 800;
	color: #000;
	color: #fff;
	letter-spacing: 1px;
	white-space: nowrap;
}

.modal-cat-name {
	flex: 1; /* Takes up 1/3 of space */
	text-align: right;
	text-transform: uppercase;
	font-size: 0.85rem;
	font-size: 1.25rem;
	letter-spacing: 2px;
	font-weight: 700;
	color: #666;
	color: #fff;
}

/* 3. Bold Counter & Spacing */
.modal-info-center {
	display: flex;
	flex-direction: row;
	gap: 0.8rem; /* Clear spacing between title and count */
}

.modal-count {
	font-size: 0.8rem;
	font-size: 1rem;
	color: #888;
	color: #fff;
}

/* Body: Navigation and Image */
.modal-body {
	flex: 1;
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 0 2rem 2rem; /* Padding ensures nav buttons aren't crowded */
}

.modal-image-container {
	flex: 1;
	display: flex;
	justify-content: center;
	align-items: center;
	max-height: 80vh;
	padding: 0 2rem; /* Gutter between image and nav buttons */
	position: relative;
}

.modal-image-container img {
	max-width: 100%;
	max-height: 80vh;
	object-fit: contain;
	box-shadow: 0 10px 40px rgba(0, 0, 0, 0.08);
}

.modal-nav-btn {
	background: none;
	border: none;
	font-size: 3.5rem;
	color: #333;
	color: #fff;
	cursor: pointer;
	padding: 2rem;
	transition:
		transform 0.2s,
		opacity 0.2s;
	user-select: none;
}

.modal-nav-btn:hover {
	transform: scale(1.1);
	color: #000;
	color: #888;
}

/* State for hiding first/last buttons */
.modal-nav-btn.hidden {
	visibility: hidden;
	pointer-events: none;
}

/* loader */
/* 1. GPU-Optimized Loader (No display: none) */
.loader {
	position: absolute;
	width: 40px;
	height: 40px;
	border: 3px solid #f3f3f3;
	border-top: 3px solid #333;
	border-radius: 50%;
	/* Performance logic */
	opacity: 0;
	visibility: hidden;
	transition: opacity 0.3s ease;
	will-change: transform, opacity;
	/* Centering */
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	animation: spin 1s linear infinite;
	z-index: 5;
}

@keyframes spin {
	100% {
		transform: translate(-50%, -50%) rotate(360deg);
	}
}

/* Active Loading State */
.modal-image-container.loading .loader {
	opacity: 1;
	visibility: visible;
}

#modal-main-img {
	opacity: 0;
	transition: opacity 0.4s ease-out;
	will-change: opacity;
}

#modal-main-img.loaded {
	opacity: 1;
}

/* 1. Tablet & Small Desktop (Fixes the Flex Layout) */
@media (max-width: 1023px) {
	.thumbnails-sections {
		grid-template-columns: repeat(4, 1fr);
	}

	.sectional-area-title {
		text-align: left;
	}

	.category-section {
		flex-direction: column; /* Stacks Text above the Grid */
		gap: 1.5rem;
		padding: 2rem 5%;
	}

	.category-info {
		flex: 1 1 100%;
		position: static; /* Removes sticky behavior when stacked */
		width: 100%;

		.category-title {
			margin-bottom: 1rem;
		}
	}

	.grid-container {
		grid-auto-rows: 200px; /* Shorter rows for medium screens */
	}
}

/* 48rem (768px) and Below: Horizontal Thumbnails & Full Width Grid */
@media (max-width: 48rem) {
	.modal-header {
		padding: 1rem;
	}
	.modal-cat-name {
		font-size: 0.7rem;
		letter-spacing: 1px;
	}
	.modal-count {
		font-size: 1rem;
	}

	.modal-body {
		padding: 0 0.5rem 1rem;
	}

	.modal-nav-btn {
		font-size: 2.5rem;
		padding: 0.5rem;
	}

	.modal-image-container {
		padding: 0 0.5rem;
	}

	.thumbnails-wrapper {
		width: 100%; /* Edge to edge wrapper */
		margin-top: 1rem;
		margin-bottom: 3rem;
	}

	.thumbnails-sections {
		display: flex; /* Switch from grid to flex for horizontal scrolling */
		overflow-x: auto;
		scroll-snap-type: x mandatory;
		scroll-padding-left: 0.75rem;
		padding: 0 1.5rem 1.5rem; /* Space for the scrollbar */
		gap: 1rem;
		/* grid-template-columns: none; */
		-webkit-overflow-scrolling: touch;
		scrollbar-width: none; /* Hide scrollbar for Firefox */
	}

	.thumbnails-sections::-webkit-scrollbar {
		display: none;
	}

	.sectional-area {
		flex: 0 0 40vw; /* Thumbnail size increases slightly */
		min-width: 140px;
		scroll-snap-align: start;

		.box {
			border-radius: 0.8rem;
		}
	}

	.sectional-area-title {
		text-align: left;
	}

	/* Remove scrollbar visual but keep functionality */
	.thumbnails-sections::-webkit-scrollbar {
		display: none;
	}

	/* Category sections take full width */
	.category-section {
		width: 100%;
		max-width: 100%;
		padding: 2rem 0.5rem;

		.category-info {
			flex: 1 1 100%;

			.category-title {
				margin-bottom: 0.75rem;
			}
		}
	}

	.grid-container {
		grid-template-columns: 1fr;
		grid-auto-rows: 300px;
		width: 100%;
		gap: 0.5rem;
	}

	/* Reset all span classes to 1×1 — span 2 on a 1-column grid creates an
	   invisible implicit column that swallows items placed into it. */
	.grid-item.wide,
	.grid-item.tall,
	.grid-item.big {
		grid-column: span 1;
		grid-row: span 1;
	}
}
