/**
 * Homepage 3D software carousel (coverflow).
 *
 * Loaded on the front page only — see inc/software-carousel.php. Every rule is
 * scoped under .swc, so nothing else on the site is affected. Sits inside the
 * existing dark .section--software band and reuses its background, the
 * section head, .btn and the brand tokens from main.css.
 *
 * Positions, scale and depth are written by assets/js/software-carousel.js as
 * a single transform per card (GPU-composited, no layout work while swiping).
 * Without JavaScript the track falls back to a scroll-snap row.
 */

.swc {
	--swc-card-w: clamp(220px, 66vw, 340px);
	--swc-card-h: calc(var(--swc-card-w) * 4 / 3);
	--swc-duration: 450ms;
	--swc-ease: cubic-bezier(0.22, 0.8, 0.24, 1);
	position: relative;
	margin-top: var(--space-lg);
}

/* ---------------------------------------------------------------- Stage */

.swc__stage {
	position: relative;
	/* Full-bleed on phones so side cards can run off the screen edge. */
	margin-inline: calc(50% - 50vw);
	padding-block: 12px 28px;
	overflow: hidden;
	/* Let the page scroll vertically; JS owns horizontal drags only. */
	touch-action: pan-y;
	user-select: none;
	-webkit-user-select: none;
	-webkit-tap-highlight-color: transparent;
}

.swc__track {
	position: relative;
	list-style: none;
	margin: 0;
	padding: 0;
}

/* -------- No-JS fallback: a plain scroll-snap row of the same cards. -------- */

.swc:not(.is-ready) .swc__track {
	display: flex;
	gap: 16px;
	overflow-x: auto;
	scroll-snap-type: x mandatory;
	padding-inline: max(16px, calc(50vw - var(--swc-card-w) / 2));
}

.swc:not(.is-ready) .swc__item {
	flex: 0 0 var(--swc-card-w);
	scroll-snap-align: center;
}

.swc:not(.is-ready) .swc__controls {
	display: none;
}

/* ------------------------------------------- Enhanced: stacked coverflow. */

.swc.is-ready .swc__track {
	height: var(--swc-card-h);
	perspective: 1400px;
	perspective-origin: 50% 45%;
}

.swc.is-ready .swc__item {
	position: absolute;
	top: 0;
	left: 50%;
	width: var(--swc-card-w);
	height: var(--swc-card-h);
	margin-left: calc(var(--swc-card-w) / -2);
	transform-origin: 50% 50%;
	will-change: transform, opacity;
	transition:
		transform var(--swc-duration) var(--swc-ease),
		opacity var(--swc-duration) var(--swc-ease);
	backface-visibility: hidden;
}

/* While a finger or mouse is dragging, cards follow it 1:1. */
.swc.is-ready.is-dragging .swc__item,
.swc.is-ready.is-dragging .swc__card::after,
.swc.is-ready.is-dragging .swc__panel,
.swc.is-ready.is-dragging .swc__panel.is-active,
.swc.is-ready.is-dragging .swc__dot::before {
	transition: none;
}

.swc.is-dragging .swc__stage {
	cursor: grabbing;
}

.swc.is-ready .swc__stage {
	cursor: grab;
}

/* ----------------------------------------------------------------- Card */

.swc__card {
	position: relative;
	display: block;
	width: 100%;
	height: 100%;
	border-radius: 22px;
	overflow: hidden;
	color: var(--color-inverse);
	background-color: var(--navy-700);
	box-shadow:
		0 30px 60px -20px rgba(0, 0, 0, 0.65),
		0 12px 24px -12px rgba(0, 0, 0, 0.45),
		inset 0 0 0 1px rgba(255, 255, 255, 0.08);
	-webkit-user-drag: none;
	/* Safari: keep the rounded clip while transformed. */
	isolation: isolate;
	transform: translateZ(0);
}

.swc__card:hover,
.swc__card:focus {
	color: var(--color-inverse);
}

/* Side cards are dimmed; the active card is not. Opacity of a pseudo is
 * cheaper than filter: brightness() on mid-range phones. */
.swc__card::after {
	content: "";
	position: absolute;
	inset: 0;
	z-index: 3;
	background-color: var(--navy-900);
	opacity: var(--swc-dim, 0);
	pointer-events: none;
	transition: opacity var(--swc-duration) var(--swc-ease);
}

.swc__item.is-active .swc__card {
	box-shadow:
		0 40px 80px -24px rgba(0, 0, 0, 0.7),
		0 0 0 1px rgba(103, 232, 249, 0.28),
		0 18px 50px -18px rgba(34, 211, 238, 0.35);
}

.swc__card:focus-visible {
	outline: 3px solid var(--cyan-400);
	outline-offset: 4px;
}

/* ---------------------------------------------------------------- Media */

.swc__media {
	position: absolute;
	inset: 0;
	display: block;
}

.swc__media img {
	width: 100%;
	height: 100%;
	max-width: none;
	object-fit: cover;
	pointer-events: none;
}

/* Landscape software screenshots: float the window, never crop it. */
.swc__media--contain {
	display: flex;
	align-items: flex-start;
	justify-content: center;
	padding: 18% 7% 0;
	background:
		radial-gradient(80% 60% at 50% 20%, rgba(34, 211, 238, 0.22) 0%, transparent 70%),
		linear-gradient(160deg, var(--blue-500) 0%, var(--navy-700) 60%, var(--navy-900) 100%);
}

.swc__media--contain img {
	height: auto;
	max-height: 58%;
	object-fit: contain;
	border-radius: 8px;
	box-shadow: 0 18px 40px -12px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(255, 255, 255, 0.12);
	transform: perspective(600px) rotateX(6deg);
}

/* No image yet: a branded card, never a broken image. */
.swc__media--placeholder {
	background:
		radial-gradient(70% 55% at 30% 20%, rgba(34, 211, 238, 0.28) 0%, transparent 70%),
		radial-gradient(60% 50% at 85% 70%, rgba(59, 130, 246, 0.35) 0%, transparent 70%),
		linear-gradient(155deg, var(--navy-600) 0%, var(--navy-800) 100%);
}

.swc__media--placeholder::before {
	content: "";
	position: absolute;
	inset: 0;
	background-image:
		linear-gradient(rgba(255, 255, 255, 0.05) 1px, transparent 1px),
		linear-gradient(90deg, rgba(255, 255, 255, 0.05) 1px, transparent 1px);
	background-size: 28px 28px;
	mask-image: radial-gradient(70% 60% at 50% 35%, #000 0%, transparent 100%);
	-webkit-mask-image: radial-gradient(70% 60% at 50% 35%, #000 0%, transparent 100%);
}

.swc__placeholder {
	position: absolute;
	inset: 0 0 38%;
	display: grid;
	place-items: center;
}

.swc__placeholder-icon {
	display: grid;
	place-items: center;
	width: 38%;
	aspect-ratio: 1;
	border-radius: 28%;
	color: var(--cyan-300);
	background: rgba(255, 255, 255, 0.06);
	box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.14), 0 20px 40px -16px rgba(34, 211, 238, 0.45);
}

.swc__placeholder-icon svg {
	width: 52%;
	height: 52%;
	fill: none;
	stroke: currentColor;
	stroke-width: 1.4;
	stroke-linecap: round;
	stroke-linejoin: round;
}

/* ----------------------------------------------------------------- Body */

.swc__body {
	position: absolute;
	inset: auto 0 0;
	z-index: 2;
	display: flex;
	flex-direction: column;
	gap: 6px;
	padding: 56px 20px 20px;
	background: linear-gradient(180deg, transparent 0%, rgba(6, 11, 24, 0.82) 42%, rgba(6, 11, 24, 0.96) 100%);
}

.swc__name {
	font-size: clamp(1.05rem, 0.9rem + 0.6vw, 1.25rem);
	font-weight: 700;
	line-height: 1.25;
	letter-spacing: -0.01em;
	text-wrap: balance;
}

.swc__desc {
	display: -webkit-box;
	-webkit-line-clamp: 2;
	-webkit-box-orient: vertical;
	overflow: hidden;
	font-size: 0.85rem;
	line-height: 1.45;
	color: rgba(255, 255, 255, 0.78);
}

/* ------------------------------------------------------------ Controls */

.swc__controls {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 12px;
	margin-top: 4px;
}

.swc__nav {
	position: absolute;
	top: calc(12px + var(--swc-card-h) / 2);
	z-index: 200;
	display: grid;
	flex: 0 0 auto;
	place-items: center;
	width: 48px;
	height: 48px;
	margin-top: -24px;
	padding: 0;
	border: 1px solid rgba(255, 255, 255, 0.18);
	border-radius: 50%;
	color: var(--color-inverse);
	background: rgba(11, 18, 32, 0.55);
	-webkit-backdrop-filter: blur(10px);
	backdrop-filter: blur(10px);
	box-shadow: 0 10px 24px -10px rgba(0, 0, 0, 0.6);
	transition: background-color var(--transition), border-color var(--transition), transform var(--transition);
}

.swc__nav svg {
	width: 20px;
	height: 20px;
}

.swc__nav:hover,
.swc__nav:focus-visible {
	background: var(--blue-500);
	border-color: var(--blue-400);
}

.swc__nav:active {
	transform: scale(0.94);
}

.swc__nav:focus-visible {
	outline: 2px solid var(--cyan-400);
	outline-offset: 3px;
}

/* Wide screens: arrows sit beyond the outermost visible cards. */
.swc__nav--prev {
	left: max(0px, calc(50% - var(--swc-card-w) * 1.3 - 56px));
}

.swc__nav--next {
	right: max(0px, calc(50% - var(--swc-card-w) * 1.3 - 56px));
}

.swc__dots {
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
	gap: 2px;
}

/* 24px hit area around an 8px dot. */
.swc__dot {
	display: grid;
	place-items: center;
	width: 24px;
	height: 24px;
	padding: 0;
	border: 0;
	background: none;
}

.swc__dot::before {
	content: "";
	width: 8px;
	height: 8px;
	border-radius: 999px;
	background: rgba(255, 255, 255, 0.32);
	transition: width var(--swc-duration) var(--swc-ease), background-color var(--swc-duration) var(--swc-ease);
}

.swc__dot:hover::before {
	background: rgba(255, 255, 255, 0.6);
}

.swc__dot[aria-current="true"]::before {
	width: 22px;
	background: var(--cyan-400);
}

.swc__dot:focus-visible {
	outline: 2px solid var(--cyan-400);
	outline-offset: 0;
	border-radius: 999px;
}

/* ---------------------------------------------------------- Info panel */

.swc__info {
	display: grid;
	max-width: 640px;
	margin: var(--space-md) auto 0;
	text-align: center;
}

/* Panels share one grid cell, so swapping never shifts the layout below. */
.swc__panel {
	grid-area: 1 / 1;
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 12px;
}

/* display:flex above would otherwise override the [hidden] attribute. */
.swc__panel[hidden] {
	display: none;
}

.swc.is-ready .swc__panel {
	opacity: 0;
	transform: translateY(8px);
	visibility: hidden;
	transition:
		opacity 320ms var(--swc-ease),
		transform 320ms var(--swc-ease),
		visibility 0s linear 320ms;
}

.swc.is-ready .swc__panel.is-active {
	opacity: 1;
	transform: none;
	visibility: visible;
	transition-delay: 90ms, 90ms, 0s;
}

.swc__panel-title {
	font-size: clamp(1.35rem, 1.1rem + 1vw, 1.75rem);
	color: var(--color-inverse);
}

.swc__panel-desc {
	max-width: 52ch;
	color: rgba(255, 255, 255, 0.72);
}

.swc__chips {
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
	gap: 8px;
	list-style: none;
	margin: 0;
	padding: 0;
}

.swc__chips li {
	padding: 4px 12px;
	border-radius: 999px;
	font-size: var(--fs-sm);
	color: var(--cyan-300);
	background: rgba(34, 211, 238, 0.08);
	box-shadow: inset 0 0 0 1px rgba(34, 211, 238, 0.24);
}

.swc__cta {
	margin-top: 6px;
}

/* ------------------------------------------------------------ Responsive */

@media (min-width: 1100px) {
	/* Soft fade at the band edges so far cards "disappear" rather than clip. */
	.swc__stage {
		margin-inline: 0;
		-webkit-mask-image: linear-gradient(90deg, transparent 0%, #000 12%, #000 88%, transparent 100%);
		mask-image: linear-gradient(90deg, transparent 0%, #000 12%, #000 88%, transparent 100%);
	}
}

@media (max-width: 1099px) {
	/* Phones and tablets: arrows join the dots in one row under the cards,
	 * so they never cover a product image. */
	.swc__nav {
		position: static;
		width: 42px;
		height: 42px;
		margin-top: 0;
	}

	.swc__dots {
		flex-wrap: nowrap;
	}
}

@media (max-width: 640px) {
	.swc__dot {
		width: 18px;
	}

	.swc__dot[aria-current="true"]::before {
		width: 16px;
	}

	.swc__body {
		padding: 48px 16px 16px;
	}
}

@media (prefers-reduced-motion: reduce) {
	.swc {
		--swc-duration: 0ms;
	}

	.swc.is-ready .swc__panel,
	.swc.is-ready .swc__panel.is-active {
		transition: none;
		transform: none;
	}

	.swc__media--contain img {
		transform: none;
	}
}
