/**
 * Project models block styles (block-scoped; enqueued only when the block is present).
 * BEM only, prefixed with the block slug.
 *
 * A wide stage on surface-alt — the colour of the download panel below it —
 * with pill tabs above, round tools in its corner and a caption under it. The
 * canvas is cleared to the stage colour, so the picture has no seam; view.js
 * reads that colour, the fallback model colour and the grid colour from the
 * custom properties on the root, which keeps the palette here.
 *
 * State lives on the root as modifiers set by view.js: --js once it runs,
 * then --loading, --waiting, --ready, --error or --unsupported, plus --drawn,
 * --dragging, --armed, --toast, --fullscreen and --pseudo. Messages are
 * printed by render.php and only shown or hidden here.
 */

.sws-project-models,
.sws-project-models *,
.sws-project-models *::before,
.sws-project-models *::after {
	box-sizing: border-box;
}

/*
 * Wide like a gallery or a figure in the articles: a model needs the room more
 * than a paragraph does. --sws-col-wide is the rail content.css declares on
 * main.site-main; in the editor the canvas constrains the block by itself.
 */
.sws-project-models {
	--sws-project-models-stage: var(--wp--preset--color--surface-alt, #f7fafd);

	/* For files that carry no colour of their own: the palette's text blue-grey reads as material. */
	--sws-project-models-model: var(--wp--preset--color--text, #4a6f8a);

	/* The heading colour at 18 %: lines that place the model without competing with it. */
	--sws-project-models-grid: rgb(14 49 76 / 18%);

	container: sws-project-models / inline-size;
	max-width: var(--sws-col-wide, 100%);
	margin: var(--wp--style--block-gap, 1.5rem) auto 0;
}

/*
 * Controls that do nothing without view.js keep their place until it runs, so
 * the page does not shift, but stay invisible and out of the tab order.
 */
.sws-project-models:not(.sws-project-models--js) .sws-project-models__tabs,
.sws-project-models:not(.sws-project-models--js) .sws-project-models__hints {
	visibility: hidden;
}

/* Tabs: the eyebrow pills of the About page, as buttons. */
.sws-project-models__tabs {
	display: flex;
	flex-wrap: wrap;
	gap: 0.5rem;
	margin: 0 0 1rem;
}

.sws-project-models__tab,
.sws-project-models__name {
	padding: 0.3125rem 1.25rem 0.25rem;
	border: 1px solid var(--wp--preset--color--line, #dbeefd);
	border-radius: 30px;
	background-color: var(--wp--preset--color--surface, #fff);
	color: var(--wp--preset--color--text, #4a6f8a);
	font-family: inherit;
	font-size: 0.8125rem;
	font-weight: 600;
	letter-spacing: 0.06em;
	line-height: 1.6;
	text-transform: uppercase;
	overflow-wrap: anywhere;
}

.sws-project-models__tab {
	cursor: pointer;
	transition: background-color var(--sws-transition, 0.3s ease), border-color var(--sws-transition, 0.3s ease), color var(--sws-transition, 0.3s ease);
}

.sws-project-models__tab:hover {
	border-color: var(--wp--preset--color--accent, #44ce6f);
	color: var(--wp--preset--color--heading, #0e314c);
}

/* Heading on accent-soft, as the pills are: white on the accent green would fall short of AA. */
.sws-project-models__tab[aria-selected="true"] {
	border-color: var(--wp--preset--color--accent-soft, #cdf1d8);
	background-color: var(--wp--preset--color--accent-soft, #cdf1d8);
	color: var(--wp--preset--color--heading, #0e314c);
	cursor: default;
}

.sws-project-models__figure {
	margin: 0;
}

/*
 * The width is set, not left to auto: with an automatic width the height cap
 * below would pass through the aspect ratio and narrow the stage instead of
 * flattening it.
 */
.sws-project-models__stage {
	position: relative;
	width: 100%;
	aspect-ratio: 4 / 3;

	/*
	 * A viewport cap, not a layout breakpoint: the stage should never be
	 * taller than most of the screen it is on. svh leaves room for a phone's
	 * browser bars; vh is the fallback where svh is unknown.
	 */
	max-height: min(70vh, 560px);
	max-height: min(70svh, 560px);
	overflow: hidden;
	border-radius: var(--sws-radius-lg, 5px);
	background-color: var(--sws-project-models-stage);
	color: var(--wp--preset--color--text, #4a6f8a);
}

/*
 * The surface the reader drags. pan-y leaves vertical swipes to the page, so a
 * phone keeps scrolling past the model; sideways swipes and pinches reach the
 * script. Full screen takes every gesture, further down.
 */
.sws-project-models__view {
	position: absolute;
	inset: 0;
	cursor: grab;
	touch-action: pan-y;
	-webkit-touch-callout: none;
	-webkit-user-select: none;
	user-select: none;

	/* The stage clips, so the focus ring is drawn inside it. */
	outline-offset: -3px;
}

.sws-project-models--dragging .sws-project-models__view {
	cursor: grabbing;
}

.sws-project-models__canvas {
	display: block;
	position: absolute;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;

	/* Blank until the first frame, then the model fades in. */
	opacity: 0;
	transition: opacity var(--sws-transition, 0.3s ease);
}

.sws-project-models--drawn .sws-project-models__canvas {
	opacity: 1;
}

/* Tools: round, white, in the top right corner, over the picture. */
.sws-project-models__toolbar {
	display: flex;
	position: absolute;
	top: 0.75rem;
	right: 0.75rem;
	z-index: 2;
	gap: 0.5rem;
}

.sws-project-models__tool {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 2.5rem;
	height: 2.5rem;
	padding: 0;

	/* Transparent until forced colours draw it. */
	border: 1px solid transparent;
	border-radius: 50%;
	background-color: rgb(255 255 255 / 90%);
	box-shadow: var(--sws-shadow-panel, 0 7px 13px 0 rgb(0 0 0 / 10%));
	color: var(--wp--preset--color--heading, #0e314c);
	text-decoration: none;
	cursor: pointer;
	transition: background-color var(--sws-transition, 0.3s ease), color var(--sws-transition, 0.3s ease);
}

.sws-project-models__tool:hover,
.sws-project-models__tool:focus-visible {
	background-color: var(--wp--preset--color--accent-soft, #cdf1d8);
	color: var(--wp--preset--color--heading, #0e314c);
}

.sws-project-models__tool:disabled {
	cursor: default;
	opacity: 0.5;
}

.sws-project-models__tool:disabled:hover {
	background-color: rgb(255 255 255 / 90%);
}

.sws-project-models__tool[hidden] {
	display: none;
}

.sws-project-models__icon {
	width: 1.125rem;
	height: 1.125rem;
}

/* The full-screen toggle carries both icons; the state picks one. */
.sws-project-models__icon--exit,
.sws-project-models--fullscreen .sws-project-models__icon--enter {
	display: none;
}

.sws-project-models--fullscreen .sws-project-models__icon--exit {
	display: block;
}

/* Overlays in the middle of the stage: the spinner, the load button and the messages. */
.sws-project-models__spinner {
	display: none;
	position: absolute;
	top: 50%;
	left: 50%;
	width: 2.5rem;
	height: 2.5rem;
	margin: -1.25rem 0 0 -1.25rem;
	border: 3px solid currentcolor;
	border-right-color: transparent;
	border-radius: 50%;
	color: var(--wp--preset--color--accent, #44ce6f);
	animation: sws-spin 0.8s linear infinite;
}

.sws-project-models--loading .sws-project-models__spinner {
	display: block;
}

.sws-project-models__message {
	display: none;
	position: absolute;
	top: 50%;
	right: 1.5rem;
	left: 1.5rem;
	max-width: 30rem;
	margin: 0 auto;
	font-size: var(--wp--preset--font-size--small, 0.875rem);
	text-align: center;
	transform: translateY(-50%);
}

/* Under the spinner rather than over it. */
.sws-project-models__message--loading {
	margin-top: 2.5rem;
}

.sws-project-models--loading .sws-project-models__message--loading,
.sws-project-models--error .sws-project-models__message--error,
.sws-project-models--unsupported .sws-project-models__message--unsupported,
.sws-project-models__message--nojs {
	display: block;
}

.sws-project-models--error .sws-project-models__message,
.sws-project-models--unsupported .sws-project-models__message,
.sws-project-models__message--nojs {
	color: var(--wp--preset--color--heading, #0e314c);
}

/* The heading colour carries white text at 12:1, where the accent green would not reach AA. */
.sws-project-models__load {
	position: absolute;
	top: 50%;
	left: 50%;
	padding: 0.75rem 1.75rem;
	border: 1px solid transparent;
	border-radius: var(--sws-radius, 4px);
	background-color: var(--wp--preset--color--heading, #0e314c);
	color: var(--wp--preset--color--surface, #fff);
	font-family: inherit;
	font-size: var(--wp--preset--font-size--small, 0.875rem);
	font-weight: 600;
	text-transform: uppercase;
	cursor: pointer;
	transform: translate(-50%, -50%);
}

.sws-project-models__load[hidden] {
	display: none;
}

/* "Click, then scroll": shown for a moment when the wheel arrives before a click. */
.sws-project-models__toast {
	visibility: hidden;
	position: absolute;
	bottom: 1rem;
	left: 50%;
	z-index: 1;
	max-width: calc(100% - 2rem);
	margin: 0;
	padding: 0.5rem 1rem;
	border-radius: 30px;
	background-color: rgb(14 49 76 / 88%);
	color: var(--wp--preset--color--surface, #fff);
	font-size: var(--wp--preset--font-size--small, 0.875rem);
	line-height: 1.5;
	text-align: center;
	opacity: 0;
	pointer-events: none;
	transform: translateX(-50%);
	transition: opacity var(--sws-transition, 0.3s ease), visibility var(--sws-transition, 0.3s ease);
}

.sws-project-models--toast .sws-project-models__toast {
	visibility: visible;
	opacity: 1;
}

/*
 * The caption: the file and its size, then the dimensions, which view.js
 * fills once the model is read. That line keeps its height while empty, so the
 * page below does not move when it arrives.
 */
.sws-project-models__caption {
	margin-top: 0.75rem;
	font-size: var(--wp--preset--font-size--small, 0.875rem);
	line-height: 1.6;
}

.sws-project-models__file {
	display: block;
	overflow-wrap: anywhere;
}

.sws-project-models__dims {
	display: block;
	min-height: 1.6em;
	color: var(--wp--preset--color--heading, #0e314c);
	white-space: nowrap;
}

.sws-project-models__hints {
	margin: 0.25rem 0 0;
	font-size: var(--wp--preset--font-size--small, 0.875rem);
	line-height: 1.6;
}

/*
 * One hint at a time: mouse or touch by the primary pointer, and the keys
 * while the view has keyboard focus. The keys hint stays in the document
 * either way, as the view's description.
 */
.sws-project-models__hint {
	display: none;
}

.sws-project-models__hint--fine {
	display: inline;
}

.sws-project-models:has(.sws-project-models__view:focus-visible) .sws-project-models__hint--fine,
.sws-project-models:has(.sws-project-models__view:focus-visible) .sws-project-models__hint--coarse {
	display: none;
}

.sws-project-models:has(.sws-project-models__view:focus-visible) .sws-project-models__hint--keys {
	display: inline;
}

/*
 * Full screen. The root fills the screen — through the Fullscreen API, or on
 * its own where there is none (--pseudo) — and the stage takes every pixel the
 * tabs and the caption leave, with every gesture.
 */
.sws-project-models--fullscreen {
	display: flex;
	flex-direction: column;
	max-width: none;
	margin: 0;
	padding: 1rem;
	background-color: var(--wp--preset--color--surface, #fff);
}

.sws-project-models--fullscreen .sws-project-models__panel,
.sws-project-models--fullscreen .sws-project-models__figure {
	display: flex;
	flex: 1;
	flex-direction: column;
	min-height: 0;
}

.sws-project-models--fullscreen .sws-project-models__stage {
	flex: 1;
	min-height: 0;
	max-height: none;
	aspect-ratio: auto;
}

.sws-project-models--fullscreen .sws-project-models__view {
	touch-action: none;
}

/*
 * Covers the window above the admin bar (z-index 99999) and the header. The
 * root itself is fixed: its container type makes it the containing block of
 * any fixed descendant, so nothing inside could do this instead.
 */
.sws-project-models--pseudo {
	position: fixed;
	inset: 0;
	z-index: 100000;
	height: 100vh;
	height: 100dvh;
	overflow: auto;
}

/* The editor's still frame and its stand-in while the field has no models. */
.sws-project-models__names {
	display: flex;
	flex-wrap: wrap;
	gap: 0.5rem;
	margin: 0 0 1rem;
	padding: 0;
	list-style: none;
}

.sws-project-models--preview .sws-project-models__stage {
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 1.5rem;
}

.sws-project-models__placeholder {
	margin: 0;
	color: var(--wp--preset--color--text, #4a6f8a);
	text-align: center;
}

.sws-project-models--empty .sws-project-models__placeholder {
	padding: 1.5rem;
	border: 1px dashed var(--wp--preset--color--line, #dbeefd);
}

@container sws-project-models (min-width: 782px) {

	.sws-project-models__stage {
		aspect-ratio: 16 / 9;
	}

	/* The file on the left, its dimensions on the right, one line. */
	.sws-project-models__caption {
		display: flex;
		justify-content: space-between;
		gap: 1.5rem;
	}
}

/* Touch as the primary pointer: bigger tools and the gesture hint. */
@media (pointer: coarse) {

	.sws-project-models__tool {
		width: 2.75rem;
		height: 2.75rem;
	}

	.sws-project-models__hint--fine {
		display: none;
	}

	.sws-project-models__hint--coarse {
		display: inline;
	}
}

/* The spinner slows to a crawl and the toast stops fading; nothing else here moves on its own. */
@media (prefers-reduced-motion: reduce) {

	.sws-project-models__spinner {
		animation-duration: 3s;
	}

	.sws-project-models__canvas,
	.sws-project-models__toast {
		transition: none;
	}
}

@media (forced-colors: active) {

	.sws-project-models__tab[aria-selected="true"] {
		border-color: Highlight;
	}

	.sws-project-models__tool,
	.sws-project-models__load {
		border-color: ButtonText;
	}

	.sws-project-models__spinner {
		color: CanvasText;
	}
}
