﻿/* FTF Visualiser — RAL colour picker. */

.ftf-vis {
	--ftf-vis-colour: #0E0E10;
	display: grid;
	grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr);
	gap: clamp(1.5rem, 3vw, 3rem);
	align-items: center;
}

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

.ftf-vis__stage {
	position: relative;
	border-radius: 16px;
	padding: clamp(0.5rem, 2vw, 1.5rem);
	background:
		radial-gradient(120% 90% at 50% 12%, rgba(255, 255, 255, 0.07) 0%, rgba(255, 255, 255, 0) 60%),
		var(--wp--preset--color--panel, #1B1B20);
	border: 1px solid var(--wp--preset--color--line, #3A3A42);
	box-shadow: 0 1px 0 rgba(255, 255, 255, 0.055) inset, 0 24px 50px -34px rgba(0, 0, 0, 0.95);
	overflow: hidden;
}

.ftf-vis__svg {
	display: block;
	inline-size: 100%;
	block-size: auto;
}

/* The rendered car, plus a tint layer confined to the paint by the mask.
   multiply keeps the shading and highlights: the colour darkens the grey
   bodywork rather than replacing it, which is why the beauty pass is rendered light. */
.ftf-vis__car {
	position: relative;
	line-height: 0;
	/* Confine the multiply to this box, so the tint blends with the render underneath it
	   rather than with the dark panel behind the whole component. */
	isolation: isolate;
}

/* Contact shadow.
   The render is a cut-out on a transparent background, so without this the car floats.
   It is deliberately restrained: the stage is nearly black, so a shadow has very little
   room to read, and anything heavier turns into a visible smudge rather than a pool.
   z-index has to be explicit on all three layers — the shadow is a pseudo-element and
   the image is in normal flow, so source order alone would paint it over the car. It
   stays inside the component because `isolation` above makes this a stacking context. */
.ftf-vis__car::before {
	content: "";
	position: absolute;
	z-index: 0;
	inset-inline: 0;
	inset-block-end: -3%;
	block-size: 18%;
	pointer-events: none;
	background:
		radial-gradient(38% 42% at 47% 55%, rgba(0, 0, 0, 0.75) 0%, rgba(0, 0, 0, 0) 70%),
		radial-gradient(52% 46% at 52% 50%, rgba(0, 0, 0, 0.5) 0%, rgba(0, 0, 0, 0) 72%);
}

.ftf-vis__beauty {
	display: block;
	position: relative;
	z-index: 1;
	inline-size: 100%;
	block-size: auto;
}

.ftf-vis__tint {
	position: absolute;
	z-index: 2;
	inset: 0;
	background: var(--ftf-vis-colour);
	mix-blend-mode: multiply;
	pointer-events: none;
	-webkit-mask-image: var(--ftf-vis-mask);
	mask-image: var(--ftf-vis-mask);
	-webkit-mask-size: 100% 100%;
	mask-size: 100% 100%;
	-webkit-mask-repeat: no-repeat;
	mask-repeat: no-repeat;
	transition: background-color 0.42s cubic-bezier(0.2, 0.7, 0.3, 1);
}

/* ---------- Panel ---------- */

.ftf-vis__readout {
	margin: 0 0 1.1rem;
	display: flex;
	flex-direction: column;
	gap: 0.15rem;
}

.ftf-vis__code {
	font-family: var(--wp--preset--font-family--display, inherit);
	font-size: clamp(1.5rem, 3vw, 2rem);
	font-weight: 900;
	text-transform: uppercase;
	letter-spacing: 0.02em;
	color: var(--wp--preset--color--contrast, #F5F6F7);
	line-height: 1.1;
}

.ftf-vis__name {
	font-size: 0.85rem;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.18em;
	color: var(--wp--preset--color--accent-bright, #F4707A);
}

/* The wrapper is now a stack of labelled sections; the GRID moved down to .ftf-vis__group.
   It is still one radiogroup, so arrow keys walk all three sections in order. */
.ftf-vis__swatches {
	margin-block-end: 1.1rem;
}

.ftf-vis__group {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
	gap: 8px;
}

.ftf-vis__group-label {
	display: flex;
	align-items: center;
	gap: 0.5rem;
	margin: 0 0 0.5rem;
	font-size: 0.6875rem;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.18em;
	color: var(--wp--preset--color--muted, #B4B6BD);
}

/* A hairline running off to the right of the label, so the three sections read as bands
   without needing boxes round them. */
.ftf-vis__group-label::after {
	content: "";
	flex: 1;
	block-size: 1px;
	background: var(--wp--preset--color--line, #3A3A42);
}

.ftf-vis__group-count {
	order: 1;
	font-size: 0.625rem;
	letter-spacing: 0.08em;
	color: var(--wp--preset--color--muted, #B4B6BD);
	opacity: 0.65;
}

/* Space between sections, but none above the first. */
.ftf-vis__group + .ftf-vis__group-label {
	margin-block-start: 1.1rem;
}

/* 44px minimum: these are the primary control and have to be tappable. */
.ftf-vis__swatch {
	position: relative;
	inline-size: 100%;
	aspect-ratio: 1;
	min-block-size: 44px;
	padding: 0;
	border: 1px solid rgba(255, 255, 255, 0.18);
	border-radius: 8px;
	background: var(--swatch);
	cursor: pointer;
	transition: transform 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease;
}

.ftf-vis__swatch:hover {
	transform: translateY(-2px);
	border-color: rgba(255, 255, 255, 0.5);
}

.ftf-vis__swatch[aria-checked="true"] {
	border-color: var(--wp--preset--color--contrast, #F5F6F7);
	box-shadow: 0 0 0 2px var(--wp--preset--color--accent, #BE1622);
}

/* Tick on the active swatch, in whichever of black/white will actually show against it. */
.ftf-vis__swatch[aria-checked="true"]::after {
	content: "";
	position: absolute;
	inset-block-start: 50%;
	inset-inline-start: 50%;
	inline-size: 11px;
	block-size: 18px;
	border: solid #0A0A0C;
	border-width: 0 3px 3px 0;
	transform: translate(-50%, -60%) rotate(45deg);
}

.ftf-vis__swatch.is-dark[aria-checked="true"]::after {
	border-color: #F5F6F7;
}

.ftf-vis__note {
	margin: 0 0 1.25rem;
	font-size: 0.8125rem;
	line-height: 1.6;
	color: var(--wp--preset--color--muted, #B4B6BD);
}

.ftf-vis__actions {
	margin: 0;
}

/* Brand red is a fill behind white here, never text — as text it fails AA on this panel. */
.ftf-vis__cta {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	box-sizing: border-box;
	padding: 0.85rem 1.5rem;
	border: 0;
	border-radius: 6px;
	background: var(--wp--preset--color--accent, #BE1622);
	color: #fff;
	font-family: var(--wp--preset--font-family--display, inherit);
	font-size: 0.9375rem;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.09em;
	text-decoration: none;
	transition: filter 0.18s ease;
}

.ftf-vis__cta:hover,
.ftf-vis__cta:focus {
	filter: brightness(1.12);
	color: #fff;
	text-decoration: none;
}

/* ---------- Mobile ---------- */

@media (max-width: 781px) {
	.ftf-vis {
		grid-template-columns: 1fr;
		gap: 1.25rem;
	}

	.ftf-vis__group {
		grid-template-columns: repeat(auto-fill, minmax(46px, 1fr));
	}

	.ftf-vis__cta {
		inline-size: 100%;
	}
}

@media (prefers-reduced-motion: reduce) {
	.ftf-vis__tint,
	.ftf-vis__swatch {
		transition: none;
	}
}

/* ---------- 3D mode ---------- */

/*
 * The live 3D view is the component now, so the stage has to hold its own height: the
 * still no longer carries a `src` and therefore contributes no intrinsic size. Without an
 * explicit ratio here the stage collapses, the canvas is sized from a zero-height parent
 * and the whole thing renders as a thin strip.
 */
.ftf-vis__stage {
	position: relative;
	aspect-ratio: 1380 / 664;
}

.ftf-vis__canvas {
	position: absolute;
	/* Inset by the stage padding rather than 0: an absolutely positioned child is laid
	   out against the padding box, so inset:0 would push the car out to the panel edge. */
	inset: clamp(0.5rem, 2vw, 1.5rem);
	z-index: 4;
	display: block;
	inline-size: 100%;
	block-size: 100%;
	border-radius: 10px;
	/* Horizontal drag turns the car, vertical scrolls the page. Without this a thumb
	   swiping down the page gets swallowed by the canvas and the page appears frozen. */
	touch-action: pan-y;
	cursor: grab;
}

.ftf-vis__canvas:active {
	cursor: grabbing;
}

.ftf-vis__stage:focus-visible,
.ftf-vis__car:focus-visible {
	outline: 2px solid var(--wp--preset--color--contrast, #F5F6F7);
	outline-offset: 3px;
}

/* The still is a fallback only. It is hidden unless something has actually gone wrong,
   and its src is withheld until then, so its PNGs are never fetched in the normal case. */
.ftf-vis__car {
	display: none;
}

.ftf-vis.is-fallback .ftf-vis__car {
	display: block;
}

.ftf-vis__noscript {
	display: block;
	inline-size: 100%;
	block-size: auto;
}

/* Nothing on screen says the car can be turned once the button is gone, so a quiet line
   sits in the corner until it has been. */
.ftf-vis__hint,
.ftf-vis__loading {
	position: absolute;
	inset-block-end: clamp(0.75rem, 2vw, 1.25rem);
	inset-inline-end: clamp(0.75rem, 2vw, 1.25rem);
	z-index: 5;
	margin: 0;
	font-size: 0.75rem;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.14em;
	color: var(--wp--preset--color--muted, #B4B6BD);
	pointer-events: none;
	opacity: 0;
	transition: opacity 0.3s ease;
}

.ftf-vis.is-3d-loading .ftf-vis__loading,
.ftf-vis.is-3d .ftf-vis__hint {
	opacity: 1;
}

.ftf-vis.is-3d.has-turned .ftf-vis__hint,
.ftf-vis.is-fallback .ftf-vis__hint,
.ftf-vis.is-fallback .ftf-vis__loading {
	opacity: 0;
}

@media (prefers-reduced-motion: reduce) {
	.ftf-vis__hint,
	.ftf-vis__loading {
		transition: none;
	}
}

/* ---------- Metallic swatches ---------- */

/*
 * A metallic swatch cannot just be its hex: solid Storm grey and metallic Storm grey are
 * the same number, and a customer picking between them off a flat square would have no
 * way to tell which is which. The sheen is the same thing the paint does — a bright sweep
 * where it faces the light, falling away to the base colour.
 *
 * `--swatch` still supplies the colour, so the two stay in step automatically.
 */
.ftf-vis__swatch.is-metallic {
	background-image:
		linear-gradient(
			118deg,
			rgba(255, 255, 255, 0) 34%,
			rgba(255, 255, 255, 0.42) 47%,
			rgba(255, 255, 255, 0.10) 56%,
			rgba(0, 0, 0, 0.22) 78%
		);
}

/* The tick has to stay legible over the bright band, which is lighter than the swatch's
   own colour and can therefore beat the is-dark assumption. */
.ftf-vis__swatch.is-metallic[aria-checked="true"]::after {
	filter: drop-shadow(0 0 2px rgba(0, 0, 0, 0.65));
}

/* Metallic reads as a finish, not a colour, so the readout says so. */
.ftf-vis__code {
	overflow-wrap: anywhere;
}

/* ---------- Matte swatches ---------- */

/*
 * Matte and solid are both flat squares of one colour, so on a grid they are the same
 * picture — and the difference between gloss and matte is the single most consequential
 * thing on this page for a customer, in money and in how the car looks afterwards.
 *
 * The cue is the opposite of the metallic sweep: a soft inset shade round the edge with no
 * highlight anywhere, which is how a non-reflective surface actually falls away at a
 * corner. Subtle on purpose — it should read as a texture, not a border.
 */
.ftf-vis__swatch.is-matte {
	background-image:
		radial-gradient(120% 120% at 50% 40%, rgba(255, 255, 255, 0.05) 0%, rgba(0, 0, 0, 0.28) 100%);
	box-shadow: inset 0 0 10px 2px rgba(0, 0, 0, 0.28);
}

/* The selected ring is a box-shadow too, and a plain override would drop the inset above.
   Both are listed so the swatch keeps its texture while selected. */
.ftf-vis__swatch.is-matte[aria-checked="true"] {
	box-shadow:
		inset 0 0 10px 2px rgba(0, 0, 0, 0.28),
		0 0 0 2px var(--wp--preset--color--accent, #BE1622);
}
