/**
 * Gallery grid and lightbox — see inc/media.php and assets/lightbox.js.
 * Only loaded on pages that actually contain photos.
 */

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

/* min() keeps the tiles from overflowing on narrow screens; at the full
   content width of ~1148px this gives three tiles of ~370px instead of the
   four small ones a lower minimum would produce. */
.sc-gallery {
	display: grid;
	gap: 14px;
	margin: 1.8em 0;
	grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr));
}

/* A single photo gets no more than the width of a two-tile row, so a lone
   photo does not tower over a gallery further down the page. */
.sc-gallery-1up {
	grid-template-columns: minmax(0, 1fr);
	max-width: 620px;
}

.sc-gallery-2up {
	grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr));
}

.sc-photo {
	margin: 0;
}

.sc-photo a {
	display: block;
	position: relative;
	overflow: hidden;
	border-radius: 6px;
	background: var(--sc-paper-2);
	line-height: 0;
}

/* One format where photos stand side by side: the migrated pictures mix
   portrait and landscape, and without a shared ratio a row of them ends up
   ragged. 3:2 is what the regatta cards and the hero use too.

   Not for a photo standing on its own. media.php wraps every run of images in
   .sc-gallery-<n>up, and a single picture becomes a row of one — which then
   got cropped to match neighbours it does not have. On the About page that
   cost a 2560x908 panorama 47% of its width and a group photograph 26%,
   cutting people out of the frame of a picture whose whole subject is the
   team. A photo placed alone in the text keeps its own shape. */
.sc-gallery:not(.sc-gallery-1up) .sc-photo a {
	aspect-ratio: 3 / 2;
}

.sc-photo img {
	width: 100%;
	height: 100%;
	object-fit: cover;
	display: block;
	transition: transform 0.35s ease;
}

/* A tall photo in a row is fitted into the tile rather than filling it, so the
   row keeps one height and the picture keeps all of itself. The band either
   side is the tile's own background — see startcup_photo_shape_class(). */
.sc-gallery:not(.sc-gallery-1up) .sc-photo-tall img,
/* Core sets object-fit on its own tiles with four classes; a shorter selector
   loses, the same trap as the tile sizing further down this file. */
.sc-block-gallery.wp-block-gallery.has-nested-images figure.wp-block-image.sc-photo-tall:not(#sc-gallery) img {
	object-fit: contain;
}

/* A photo on its own fills the column but keeps its own shape, and is capped
   in height so a tall one does not take over the page. The fleet pages carry
   boat layout drawings as narrow as 0.31 — at the column's full width and
   their own ratio one of those would run past 1800px. Capped, such an image
   simply gets narrower and centres; nothing is cut off it, which is the point
   of showing it alone in the first place. */
.sc-gallery-1up .sc-photo a {
	text-align: center;
	line-height: 0;
}

.sc-gallery-1up .sc-photo img {
	width: auto;
	height: auto;
	max-width: 100%;
	max-height: min(70vh, 640px);
	margin: 0 auto;
	object-fit: contain;
}

.sc-photo a:hover img,
.sc-photo a:focus img {
	transform: scale(1.05);
}

/* Zoom hint on hover */
.sc-photo a::after {
	content: "";
	position: absolute;
	inset: 0;
	background: rgba(0, 0, 0, 0.18) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='34' height='34' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='M20 20l-4.5-4.5M11 8v6M8 11h6'/%3E%3C/svg%3E") center no-repeat;
	opacity: 0;
	transition: opacity 0.25s ease;
}

.sc-photo a:hover::after,
.sc-photo a:focus::after {
	opacity: 1;
}

/* --- core/gallery and core/image ---------------------------------------- */

/* The regatta texts are Gutenberg blocks (see internal/scripts/regatta-blocks.php).
   core/gallery lays its images out with flex and flex-grow, so the last photo
   of an incomplete row is blown up across the full width. A grid keeps every
   tile the same size — and the same 3:2 format as the cards and the hero. */
.sc-block-gallery.wp-block-gallery {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr));
	gap: 14px;
	margin: 1.8em 0;
}

/* The selector has to match core's own specificity: core sizes the tiles via
   ".wp-block-gallery.has-nested-images.columns-3 figure.wp-block-image:not(#individual-image)"
   — four classes plus the ID inside :not(). A shorter selector loses, and the
   calc() width then resolves against the grid track: tiles of 97 instead of
   339 pixels. */
.sc-block-gallery.wp-block-gallery.has-nested-images figure.wp-block-image:not(#sc-gallery) {
	aspect-ratio: 3 / 2;
	border-radius: 6px;
	overflow: hidden;
	/* Neutralise core's flex sizing — the grid does the layout here. */
	width: 100%;
	max-width: none;
	flex: none;
	margin: 0;
}

.sc-block-gallery.wp-block-gallery figure.wp-block-image img {
	width: 100%;
	height: 100%;
	object-fit: cover;
	transition: transform 0.35s ease;
}

.sc-block-gallery.wp-block-gallery figure.wp-block-image a:hover img,
.sc-block-gallery.wp-block-gallery figure.wp-block-image a:focus img {
	transform: scale(1.05);
}

/* A lone core/image: same format, but not stretched across the full width. */
.entry-content > figure.wp-block-image:not(.sc-divider-figure),
.regatta-section-body > figure.wp-block-image:not(.sc-divider-figure) {
	max-width: 620px;
}

@media (prefers-reduced-motion: reduce) {
	.sc-block-gallery.wp-block-gallery figure.wp-block-image img {
		transition: none;
		transform: none;
	}
}

/* Decorative page-builder dividers (wheel, anchor, seagull) stay out of the
   gallery and sit centred — see startcup_normalise_divider(). */
.entry-content figure.sc-divider-figure {
	margin: 1.8em auto;
	max-width: 200px;
}

.entry-content figure.sc-divider-figure img {
	width: 100%;
	height: auto;
}

.entry-content img.sc-divider,
.entry-content img[src*="SC-trenner"] {
	display: block;
	margin: 1.8em auto;
	max-width: 200px;
	height: auto;
}

@media (prefers-reduced-motion: reduce) {
	.sc-photo img,
	.sc-photo a::after {
		transition: none;
	}

	.sc-photo a:hover img,
	.sc-photo a:focus img {
		transform: none;
	}
}

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

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

.sc-lightbox {
	position: fixed;
	inset: 0;
	z-index: 100000;
	background: rgba(20, 24, 28, 0.94);
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 56px 16px 72px;
}

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

.sc-lightbox-stage {
	margin: 0;
	max-width: 100%;
	max-height: 100%;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 14px;
}

.sc-lightbox-image {
	max-width: 100%;
	max-height: calc(100vh - 160px);
	width: auto;
	height: auto;
	object-fit: contain;
	border-radius: 4px;
	background: rgba(255, 255, 255, 0.04);
}

.sc-lightbox-caption {
	color: #fff;
	font-size: 0.95em;
	text-align: center;
	max-width: 60ch;
}

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

.sc-lightbox-counter {
	position: absolute;
	bottom: 20px;
	left: 0;
	right: 0;
	margin: 0;
	text-align: center;
	color: rgba(255, 255, 255, 0.75);
	font-size: 0.85em;
}

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

/* The theme styles every <button> teal — the controls have to opt out
   explicitly, including the hover state. */
.sc-lightbox button,
.sc-lightbox button:hover,
.sc-lightbox button:focus,
.sc-lightbox button:active {
	position: absolute;
	background: rgba(0, 0, 0, 0.35);
	border: none;
	box-shadow: none;
	color: #fff;
	line-height: 1;
	cursor: pointer;
	border-radius: 50%;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 0;
}

.sc-lightbox button:hover,
.sc-lightbox button:focus {
	background: var(--sc-teal, #03acac);
}

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

.sc-lightbox-close {
	top: 12px;
	right: 12px;
	width: 44px;
	height: 44px;
	font-size: 30px;
}

.sc-lightbox-prev,
.sc-lightbox-next {
	top: 50%;
	transform: translateY(-50%);
	width: 52px;
	height: 52px;
	font-size: 36px;
}

.sc-lightbox-prev {
	left: 12px;
}

.sc-lightbox-next {
	right: 12px;
}

.sc-lightbox.is-loading .sc-lightbox-image {
	opacity: 0.35;
}

@media (max-width: 600px) {
	.sc-lightbox {
		padding: 52px 8px 64px;
	}

	.sc-lightbox-prev,
	.sc-lightbox-next {
		width: 42px;
		height: 42px;
		font-size: 28px;
	}
}
