/* ==========================================================================
   Category carousel

   The reference band: square category tiles, a short centred label under each,
   and a pair of round arrows beside the row, not on top of the pictures.

   The track is a real horizontal scroller rather than a transformed strip.
   Native scrolling gives touch swipe, trackpad scroll, scroll-snap alignment
   and keyboard support for free; the script only nudges it by one screen and
   adds mouse dragging.
   ========================================================================== */

.sc-catcar {
	/* `--sc-catcar-base` is written inline by the renderer (the "show N per
	   screen" setting). The media query below overrides the derived variable,
	   not the inline one, because an inline custom property would win. */
	--sc-catcar-cols: var(--sc-catcar-base, 4);

	position: relative;
}

.sc-catcar__track {
	display: grid;
	grid-auto-flow: column;
	grid-auto-columns: calc((100% - (var(--sc-catcar-cols) - 1) * var(--sc-gap)) / var(--sc-catcar-cols));
	gap: var(--sc-gap);
	margin: 0;
	padding: 0;
	list-style: none;

	overflow-x: auto;
	overflow-y: hidden;
	overscroll-behavior-inline: contain;
	scroll-snap-type: x mandatory;

	/* The arrows are the visible control; a bar under the tiles would add a
	   second, uglier one. */
	scrollbar-width: none;

	cursor: grab;
}

.sc-catcar__track::-webkit-scrollbar {
	display: none;
}

/* While a mouse drag is in progress the strip follows the pointer pixel by
   pixel, so mandatory snapping has to stand down — otherwise the browser
   pulls the strip back to a tile edge on every move. */
.sc-catcar.is-free-scroll .sc-catcar__track {
	scroll-snap-type: none;
}

.sc-catcar.is-dragging {
	-webkit-user-select: none;
	user-select: none;
}

.sc-catcar.is-dragging .sc-catcar__track,
.sc-catcar.is-dragging .sc-catcar__card {
	cursor: grabbing;
}

.sc-catcar__item {
	scroll-snap-align: start;
}

.sc-catcar__card {
	display: block;
	color: inherit;
	text-decoration: none;
}

.sc-catcar__media {
	display: block;
	position: relative;
	overflow: hidden;
	aspect-ratio: 1 / 1;
	background: var(--sc-ivory);
}

.sc-catcar__media img {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: cover;
	transition: transform 380ms cubic-bezier(.2, .7, .3, 1);

	/* A mouse drag across the row must scroll the strip, not start the
	   browser's own image-drag ghost. */
	-webkit-user-drag: none;
	user-select: none;
}

.sc-catcar__card:hover .sc-catcar__media img,
.sc-catcar__card:focus-visible .sc-catcar__media img {
	transform: scale(1.04);
}

.sc-catcar__label {
	display: -webkit-box;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 2;
	overflow: hidden;

	/* Two lines reserved for every tile, so a short label does not lift its
	   picture out of line with the rest of the row. */
	min-block-size: 2.7em;
	margin-block-start: .95rem;
	color: var(--sc-ink);
	font-size: var(--sc-fs-small);
	line-height: 1.35;
	text-align: center;
}

/* Arrows sit beside the row, centred on the pictures. They are positioned
   against the band, whose box is the track including the caption block, so
   the geometric centre sits half a caption too low — hence the nudge. */
.sc-catcar__nav {
	position: absolute;
	inset-block-start: 50%;
	z-index: 2;

	display: grid;
	place-items: center;
	width: 40px;
	height: 40px;
	padding: 0;

	/* Solid white and a real border: at 92% and a 16%-alpha hairline the disc
	   disappeared against a dark garment shot. */
	border: 1px solid rgba(17, 17, 17, .24);
	border-radius: 50%;
	background: #fff;
	box-shadow: 0 2px 10px rgba(0, 0, 0, .12);
	color: var(--sc-ink);
	cursor: pointer;

	transform: translateY(calc(-50% - (2.7 * var(--sc-fs-small) + .95rem) / 2));
	transition: background-color var(--sc-transition), border-color var(--sc-transition), opacity var(--sc-transition);
}

.sc-catcar__nav:hover,
.sc-catcar__nav:focus-visible {
	border-color: var(--sc-ink);
	background: #fff;
}

/* At an end the arrow stays visible — a control that vanishes reads as a
   missing control — but drops to a quiet state instead of half-fading the
   whole disc, which on a dark photograph left nothing to see. */
.sc-catcar__nav[disabled] {
	background: rgba(255, 255, 255, .85);
	border-color: rgba(17, 17, 17, .14);
	box-shadow: 0 1px 6px rgba(0, 0, 0, .08);
	color: rgba(17, 17, 17, .25);
	cursor: default;
}

/* Nothing to scroll: the arrows would be dead controls. */
.sc-catcar.is-static .sc-catcar__nav {
	display: none;
}

.sc-catcar__cta {
	margin-block-start: clamp(1.5rem, 3vw, 2.25rem);
	text-align: center;
}

/* --------------------------------------------------------------------------
   Desktop: arrows in the margins beside the row.

   The left one lives in the page gutter, clear of everything. The right one
   cannot: the fixed social rail owns the outer 56px of the viewport, so an
   arrow there would sit under the rail and could not be clicked. The row
   therefore gives up 88px on that side, which is where the right arrow goes —
   outside the pictures, clear of the rail.
   -------------------------------------------------------------------------- */
@media (min-width: 1025px) {
	.sc-catcar__nav--prev {
		inset-inline-start: calc(4px - var(--sc-gutter));
	}

	.sc-catcar__nav--next {
		inset-inline-end: calc(4px - var(--sc-gutter));
	}

	/* Off the pictures, on the page's own white: a white disc at 14% alpha
	   was invisible, so the resting state gets a real hairline and the
	   disabled state a filled grey. */
	.sc-catcar__nav {
		border-color: rgba(17, 17, 17, .3);
	}

	.sc-catcar__nav[disabled] {
		background: #f2f1ee;
		border-color: rgba(17, 17, 17, .12);
		color: rgba(17, 17, 17, .3);
	}
}

/* Where the rail is on screen (1200px up) and the gutter is still narrow, the
   right arrow moves inside the band's own edge instead. From ~1620px the page
   gutter is wider than the rail's reach, so the arrow returns to it. */
@media (min-width: 1200px) and (max-width: 1619px) {
	.sc-catcar__track {
		margin-inline-end: 88px;
	}

	.sc-catcar__nav--next {
		inset-inline-end: 40px;
	}
}

/* The gutter below 1025 is 24px — narrower than an arrow — so the arrows sit
   on the outer edge of the first and last tile instead. No rail down here. */
@media (max-width: 1024px) {
	.sc-catcar__track {
		margin-inline-end: 0;
	}

	.sc-catcar__nav--prev {
		inset-inline-start: 0;
	}

	.sc-catcar__nav--next {
		inset-inline-end: 0;
	}
}

@media (max-width: 900px) {
	.sc-catcar {
		--sc-catcar-cols: 2;
	}
}

@media (max-width: 480px) {
	.sc-catcar__nav {
		width: 34px;
		height: 34px;
	}
}

@media (prefers-reduced-motion: reduce) {
	.sc-catcar__media img {
		transition: none;
	}
}
