/**
 * Cool Bear — Full-bleed PDP gallery (Q10).
 *
 * Edge-to-edge hero gallery on PDPs. Mobile = swipeable carousel, desktop =
 * primary stage + thumbnail rail. Reserves aspect-ratio space when no image
 * is present so cards/PDPs never collapse to placeholder ghost-mountain
 * (defect D1, D23 from 08-W0-ux brief).
 *
 * Design tokens: colour, spacing, typography all sourced from theme.json.
 * Mobile-first, breakpoints: 375 / 768 / 1024 / 1440 / 1920.
 */

/* -------------------------------------------------------------------------
 *  Container — full-bleed escape from constrained layout
 * ------------------------------------------------------------------------- */
.cb-gallery {
	width: 100vw;
	margin-left: 50%;
	transform: translateX(-50%);
	background-color: var(--wp--preset--color--surface-sunken);
	position: relative;
	contain: layout style;
}

/* When inside an alignfull parent, do not double-translate */
.alignfull > .cb-gallery,
.cb-gallery.alignfull {
	margin-left: 0;
	transform: none;
}

/* -------------------------------------------------------------------------
 *  Stage — primary image area, 16:9 desktop, 4:3 tablet, 1:1 mobile
 * ------------------------------------------------------------------------- */
.cb-gallery__stage {
	position: relative;
	/* border-box so width:100% + the per-CPT well padding stays within the media
	   column — content-box let the padded stage overflow right onto the title
	   (worst on parts: 32px padding = 64px spill over the H1/SKU). */
	box-sizing: border-box;
	width: 100%;
	aspect-ratio: 1 / 1;
	overflow: hidden;
	background-color: var(--wp--preset--color--surface);
	/* Hard cap so portrait / square illustrations can't dominate the fold. */
	max-height: min(72vh, 640px);
}

@media (min-width: 768px) {
	.cb-gallery__stage { aspect-ratio: 4 / 3; }
}

@media (min-width: 1024px) {
	.cb-gallery__stage { aspect-ratio: 16 / 9; max-height: 64vh; }
}

@media (min-width: 1440px) {
	.cb-gallery__stage { aspect-ratio: 16 / 9; max-height: 68vh; }
}

.cb-gallery__slide {
	position: absolute;
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	opacity: 0;
	transition: opacity 280ms ease;
}

/* The server-side WebP rewrite wraps slide images in <picture>. The wrapper
   is content-sized, so the img's height:100% resolved against the wrapper's
   intrinsic (tall) height instead of the stage — a portrait render overflowed
   the clamped stage and displayed as a zoomed-in crop (operator, 2026-07-11,
   PRD PDPs). display:contents removes the wrapper from layout so the img
   sizes against the slide box again. */
.cb-gallery__slide picture {
	display: contents;
}

.cb-gallery__slide[aria-hidden="false"] {
	opacity: 1;
}

.cb-gallery__image {
	width: 100%;
	height: 100%;
	object-fit: var(--cb-gallery-fit, cover);
	object-position: center;
	display: block;
}

/* Technical-illustration CPTs (coilover / wheel / part) — contain rather
 * than cover so the call-out diagrams aren't cropped. Brake kit imagery is
 * photographic and keeps the cover default. */
body.single-cb_coilover .cb-gallery,
body.single-cb_forged_wheel .cb-gallery,
body.single-cb_part .cb-gallery {
	--cb-gallery-fit: contain;
}

body.single-cb_coilover .cb-gallery__stage,
body.single-cb_forged_wheel .cb-gallery__stage,
body.single-cb_part .cb-gallery__stage {
	padding: clamp(16px, 4vw, 48px) 0;
}

/* Image-coming-soon tile (D23) — replaces ghost-mountain placeholder */
.cb-gallery__placeholder {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: var(--wp--preset--spacing--30);
	width: 100%;
	height: 100%;
	background-color: var(--wp--preset--color--surface);
	background-image:
		linear-gradient(135deg, transparent 49%, var(--wp--preset--color--border) 49%, var(--wp--preset--color--border) 51%, transparent 51%),
		linear-gradient(45deg,  transparent 49%, var(--wp--preset--color--border) 49%, var(--wp--preset--color--border) 51%, transparent 51%);
	background-size: 32px 32px;
	background-position: center;
	color: var(--wp--preset--color--text-subtle);
	font-family: var(--wp--preset--font-family--mono);
	font-size: var(--wp--preset--font-size--small);
	letter-spacing: 0.05em;
	text-transform: uppercase;
}

.cb-gallery__placeholder-label {
	padding: 8px 16px;
	background-color: var(--wp--preset--color--base);
	border: 1px solid var(--wp--preset--color--border);
	border-radius: 4px;
}

/* -------------------------------------------------------------------------
 *  Thumbnail rail (desktop) / dots (mobile)
 * ------------------------------------------------------------------------- */
.cb-gallery__rail {
	display: flex;
	gap: var(--wp--preset--spacing--20);
	padding: var(--wp--preset--spacing--30);
	overflow-x: auto;
	scroll-snap-type: x mandatory;
	-webkit-overflow-scrolling: touch;
	scrollbar-width: thin;
}

/* Hydrated-gallery thumbnail strip (Cool_Bear_PDP_Hydrator). The PHP emits
 * <ol class="cb-gallery__thumbs"> with <li><button class="cb-gallery__thumb">…
 * which was never styled, producing a bullet-numbered "1 / 2 / 3" eyesore
 * under the hero. Strip list-default styles and re-flow as a flex strip. */
.cb-gallery__thumbs {
	list-style: none;
	margin: 0;
	padding: var(--wp--preset--spacing--30) var(--wp--preset--spacing--40);
	display: flex;
	gap: var(--wp--preset--spacing--20);
	overflow-x: auto;
	scrollbar-width: thin;
	max-width: 1440px;
	margin-inline: auto;
}

.cb-gallery__thumbs li { display: contents; }

/* Thumb-rail cap (Task 3): gallery.js sets [hidden] on overflow <li>s beyond the
   cap. The `display: contents` rule above is author-origin and beats the UA
   [hidden]{display:none}, so without this scoped override (0-3-1 > 0-1-1) the
   "hidden" thumbs would still render AND stay in the a11y tree. Force them out. */
.cb-gallery--well .cb-gallery__thumbs li[hidden] { display: none; }

.cb-gallery__thumb {
	flex: 0 0 64px;
	aspect-ratio: 1 / 1;
	border: 1px solid var(--wp--preset--color--border);
	border-radius: 4px;
	background-color: var(--wp--preset--color--surface);
	overflow: hidden;
	cursor: pointer;
	scroll-snap-align: start;
	padding: 0;
	transition: border-color 150ms ease, transform 150ms ease;
}

@media (min-width: 768px) {
	.cb-gallery__thumb { flex-basis: 80px; }
}

@media (min-width: 1024px) {
	.cb-gallery__thumb { flex-basis: 96px; }
}

.cb-gallery__thumb:hover,
.cb-gallery__thumb:focus-visible {
	border-color: var(--wp--preset--color--text-muted);
	transform: translateY(-1px);
}

.cb-gallery__thumb[aria-current="true"] {
	border-color: var(--wp--preset--color--accent);
	box-shadow: 0 0 0 1px var(--wp--preset--color--accent);
}

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

/* -------------------------------------------------------------------------
 *  Prev / next arrows
 * ------------------------------------------------------------------------- */
.cb-gallery__nav {
	position: absolute;
	top: 50%;
	transform: translateY(-50%);
	width: 44px;
	height: 44px;
	border-radius: 50%;
	background-color: rgba(13, 13, 15, 0.7);
	border: 1px solid var(--wp--preset--color--border);
	color: var(--wp--preset--color--text);
	display: flex;
	align-items: center;
	justify-content: center;
	cursor: pointer;
	transition: background-color 150ms ease, transform 150ms ease;
	z-index: 2;
}

.cb-gallery__nav:hover { background-color: rgba(13, 13, 15, 0.9); transform: translateY(-50%) scale(1.05); }
.cb-gallery__nav--prev { left: var(--wp--preset--spacing--40); }
.cb-gallery__nav--next { right: var(--wp--preset--spacing--40); }

@media (max-width: 767px) {
	.cb-gallery__nav { display: none; }
}

/* -------------------------------------------------------------------------
 *  PDP media-well variant (.cb-gallery--well) — the multi-image carousel
 *  rendered INTO the above-fold .cb-pdp__media well (Cool_Bear_PDP_Hydrator
 *  layout="well"), instead of the full-bleed Overview gallery. Column-scoped
 *  (~45% left grid cell), square stage, per-CPT well aesthetic moved onto the
 *  stage (the .cb-pdp__media wrapper is neutralised in pdp.css to avoid
 *  double-graphite). Specificity is load-bearing — the per-CPT stage rules are
 *  body-scoped (0-1-2-0) so they beat the full-bleed body-scoped padding rule
 *  at gallery.css 88-92 (0-1-1-1); NO bare padding:0 reset (it would lose).
 * ------------------------------------------------------------------------- */
.cb-gallery--well {
	/* Cancel the full-bleed escape so the gallery fits the grid cell. */
	width: auto;
	margin: 0;
	margin-left: 0;
	transform: none;
	background-color: transparent;
	/* Cancel inherited `contain: layout style` (.cb-gallery line 22). That value
	   does not include `size` so it never collapsed height — cancelling removes
	   all doubt in the constrained grid cell at zero cost. position:relative is
	   inherited from .cb-gallery so nav/overlay positioning still resolves. */
	contain: none;
	/* The well is a contain catalogue device for all four CPTs. */
	--cb-gallery-fit: contain;
}

/* Adaptive stage aspect (replaces the old hard 1/1 square + the full-bleed 16:9).
   gallery.js sets --cb-well-ratio from the ACTIVE image's natural dims, clamped to
   [0.75 .. 1.78]; the default `1 / 1` keeps no-JS / pre-init rendering square (so
   1:1 wheel/brake/part renders look identical to before, and only mixed-aspect
   coilovers visibly adapt). No standalone `padding: 0` reset here — at 0-0-2-0 it
   would lose to the body-scoped 88-92 rule. Each per-CPT well stage sets its own
   padding. The max-height cap below still bites on tall portraits. */
.cb-gallery--well .cb-gallery__stage {
	aspect-ratio: var(--cb-well-ratio, 1 / 1);
	max-height: none;
}

@media (min-width: 1024px) {
	.cb-gallery--well .cb-gallery__stage { max-height: min(62vh, 600px); }
}

/* Per-CPT well aesthetic — body-scoped (0-1-2-0) so it beats the 0-1-1-1
   full-bleed padding at 88-92. Values mirror pdp.css 146-155 exactly so the
   well looks identical to today's single-image well. */

/* Parts: white well, baked-white diagram, multiply blend. */
body.single-cb_part .cb-gallery--well .cb-gallery__stage {
	background: #f4f4f6;
	padding: clamp(16px, 3vw, 32px);
}
body.single-cb_part .cb-gallery--well .cb-gallery__image {
	mix-blend-mode: multiply;
}

/* Brake / coilover / wheel: graphite radial-gradient well, transparent PNGs,
   normal blend. */
body.single-cb_brake_kit .cb-gallery--well .cb-gallery__stage,
body.single-cb_coilover .cb-gallery--well .cb-gallery__stage,
body.single-cb_forged_wheel .cb-gallery--well .cb-gallery__stage {
	background: radial-gradient(125% 110% at 50% 28%, #2a2a31 0%, #1c1c21 62%, #141417 100%);
	box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04);
	padding: clamp(6px, 1.4vw, 14px);
}
body.single-cb_brake_kit .cb-gallery--well .cb-gallery__image,
body.single-cb_coilover .cb-gallery--well .cb-gallery__image,
body.single-cb_forged_wheel .cb-gallery--well .cb-gallery__image {
	mix-blend-mode: normal;
}

/* Column-scoped thumb rail — override the full-bleed centered rail (140-150)
   so it stays inside the grid cell, left-aligned. */
.cb-gallery--well .cb-gallery__thumbs {
	max-width: none;
	margin-inline: 0;
	padding: var(--wp--preset--spacing--20) 0 0;
	justify-content: flex-start;
}
.cb-gallery--well .cb-gallery__thumb { flex-basis: 56px; }

@media (min-width: 1024px) {
	.cb-gallery--well .cb-gallery__thumb { flex-basis: 64px; }
}

/* -------------------------------------------------------------------------
 *  Task 3 — "+K more" thumb-rail cap control (.cb-gallery__more)
 *
 *  gallery.js appends this <button> as a SIBLING right AFTER the
 *  <ol role="tablist" class="cb-gallery__thumbs"> (NOT inside it — see the
 *  placement rationale in gallery.js setupThumbCap). Because it sits outside the
 *  flex <ol>, it is its own inline-flex box; LAYOUT CHOICE: a small
 *  margin-block-start matches the rail's padding-top so it reads as part of the
 *  rail, sitting directly under it and matching the thumb-tile look.
 * ------------------------------------------------------------------------- */
.cb-gallery--well .cb-gallery__more {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	flex: 0 0 56px;
	aspect-ratio: 1 / 1;
	margin-block-start: var(--wp--preset--spacing--20);
	border: 1px solid var(--wp--preset--color--border);
	border-radius: 4px;
	background-color: var(--wp--preset--color--surface);
	color: var(--wp--preset--color--text-muted);
	font-family: var(--wp--preset--font-family--mono);
	font-size: var(--wp--preset--font-size--small);
	letter-spacing: 0.02em;
	text-align: center;
	cursor: pointer;
	transition: border-color 150ms ease, transform 150ms ease;
}

.cb-gallery--well .cb-gallery__more:hover,
.cb-gallery--well .cb-gallery__more:focus-visible {
	border-color: var(--wp--preset--color--text-muted);
	transform: translateY(-1px);
}

@media (min-width: 1024px) {
	.cb-gallery--well .cb-gallery__more { flex-basis: 64px; }
}

/* Mobile (<768): the square stage + horizontal-scroll thumb rail already follow
   from the rules above (.cb-gallery__thumbs is overflow-x:auto). The full-bleed
   nav arrows are display:none <768 and the well has no arrows anyway — no extra
   rule needed. */

/* -------------------------------------------------------------------------
 *  Task 4 — click-to-zoom affordance + lightbox overlay
 *
 *  All selectors scoped to .cb-gallery--well (the affordance) or .cb-lightbox
 *  (the overlay, appended to <body> by gallery.js). The full-bleed gallery is
 *  untouched. The full image loads from data-full (Task 1) so the future
 *  AI-upscale lands automatically.
 * ------------------------------------------------------------------------- */

/* Stage reads as zoomable. */
.cb-gallery--well .cb-gallery__stage { cursor: zoom-in; }

/* Focusable zoom button over the stage (top-right) — reuses the nav-button
   visual language: dark translucent, bordered, round. */
.cb-gallery--well .cb-gallery__zoom {
	position: absolute;
	top: var(--wp--preset--spacing--20);
	right: var(--wp--preset--spacing--20);
	width: 40px;
	height: 40px;
	border-radius: 50%;
	background-color: rgba(13, 13, 15, 0.7);
	border: 1px solid var(--wp--preset--color--border);
	color: var(--wp--preset--color--text);
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 1.1rem;
	line-height: 1;
	cursor: zoom-in;
	z-index: 3;
	transition: background-color 150ms ease, transform 150ms ease;
}

.cb-gallery--well .cb-gallery__zoom:hover,
.cb-gallery--well .cb-gallery__zoom:focus-visible {
	background-color: rgba(13, 13, 15, 0.9);
	transform: scale(1.05);
}

/* Overlay — fixed, above the site header, dark backdrop, centred image. */
.cb-lightbox {
	position: fixed;
	inset: 0;
	z-index: 9999; /* clearly above the sticky header */
	display: none;
	align-items: center;
	justify-content: center;
	background-color: rgba(8, 8, 10, 0.92);
}

.cb-lightbox.is-open { display: flex; }

/* Accessible-name heading — present for AT, visually hidden. */
.cb-lightbox__title {
	position: absolute;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip: rect(0 0 0 0);
	clip-path: inset(50%);
	white-space: nowrap;
	border: 0;
}

.cb-lightbox__image {
	display: block;
	max-width: 92vw;
	max-height: 92vh;
	object-fit: contain;
	transition: opacity 200ms ease;
}

.cb-lightbox.is-loading .cb-lightbox__image { opacity: 0.6; cursor: progress; }

/* Lightbox controls reuse the nav-button look (round, translucent, bordered). */
.cb-lightbox__nav,
.cb-lightbox__close {
	position: absolute;
	width: 48px;
	height: 48px;
	border-radius: 50%;
	background-color: rgba(13, 13, 15, 0.7);
	border: 1px solid var(--wp--preset--color--border);
	color: var(--wp--preset--color--text);
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 1.6rem;
	line-height: 1;
	cursor: pointer;
	z-index: 1;
	transition: background-color 150ms ease, transform 150ms ease;
}

.cb-lightbox__nav:hover,
.cb-lightbox__close:hover,
.cb-lightbox__nav:focus-visible,
.cb-lightbox__close:focus-visible {
	background-color: rgba(13, 13, 15, 0.95);
}

.cb-lightbox__close { top: var(--wp--preset--spacing--40); right: var(--wp--preset--spacing--40); }
.cb-lightbox__nav--prev { left: var(--wp--preset--spacing--40); top: 50%; transform: translateY(-50%); }
.cb-lightbox__nav--next { right: var(--wp--preset--spacing--40); top: 50%; transform: translateY(-50%); }

.cb-lightbox__nav--prev:hover,
.cb-lightbox__nav--next:hover { transform: translateY(-50%) scale(1.05); }

/* Single-image galleries: no prev/next. */
.cb-lightbox--single .cb-lightbox__nav { display: none; }

/* Reduced-motion: kill the open/zoom transitions. */
@media (prefers-reduced-motion: reduce) {
	.cb-gallery--well .cb-gallery__zoom,
	.cb-lightbox__image,
	.cb-lightbox__nav,
	.cb-lightbox__close {
		transition: none;
	}
	.cb-gallery--well .cb-gallery__zoom:hover,
	.cb-gallery--well .cb-gallery__zoom:focus-visible,
	.cb-lightbox__nav--prev:hover,
	.cb-lightbox__nav--next:hover { transform: none; }
	.cb-lightbox__nav--prev,
	.cb-lightbox__nav--next { transform: translateY(-50%); }
}
