/*
 * Build page: layout and the pieces the shared component CSS does not cover.
 * Tokens and the qb-* component classes come from assets/css/main.css;
 * every token here carries a fallback so the page still reads on its own.
 * Mobile first. No horizontal overflow at 360px.
 */

.qb-build {
	display: flex;
	flex-direction: column;
	gap: var(--space-5, 24px);
	min-width: 0;
	color: var(--ink, #16151e);
	font-family: var(--font-sans, "Poppins", system-ui, sans-serif);
}

.qb-build *,
.qb-build *::before,
.qb-build *::after {
	box-sizing: border-box;
}

.qb-build p,
.qb-build h1,
.qb-build h2,
.qb-build h3,
.qb-build figure,
.qb-build fieldset {
	margin: 0;
}

.qb-build fieldset {
	padding: 0;
	border: 0;
	min-width: 0;
}

.qb-build legend {
	padding: 0;
	width: 100%;
}

.qb-build button,
.qb-build input,
.qb-build select,
.qb-build textarea {
	font: inherit;
	color: inherit;
}

/* ---------- Heading row ---------- */

.qb-build__head {
	display: flex;
	flex-wrap: wrap;
	align-items: flex-end;
	justify-content: space-between;
	gap: var(--space-4, 16px) var(--space-6, 32px);
}

.qb-build__heading {
	display: flex;
	flex-direction: column;
	gap: var(--space-2, 8px);
	min-width: 0;
}

.qb-build__eyebrow {
	color: var(--brand, #5f4585);
	text-transform: uppercase;
}

.qb-build__title {
	font-size: clamp(28px, 4vw, 40px);
	line-height: 1.15;
	text-wrap: balance;
}

/* ---------- Idea chips ---------- */

.qb-build__ideas {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: var(--space-3, 12px);
}

.qb-build__ideas-label {
	color: var(--ink-subtle, #605a68);
}

.qb-build__idea {
	min-height: 44px;
	padding: 0 var(--space-4, 16px);
}

/* ---------- Grid: viewer 7/12, panel 5/12, viewer first on phones ---------- */

.qb-build__grid {
	display: grid;
	grid-template-columns: minmax(0, 1fr);
	gap: var(--space-6, 32px);
	align-items: start;
}

.qb-build__viewer {
	display: flex;
	flex-direction: column;
	gap: var(--space-4, 16px);
	min-width: 0;
}

.qb-build__panel {
	min-width: 0;
}

@media (min-width: 900px) {
	.qb-build__grid {
		grid-template-columns: minmax(0, 7fr) minmax(320px, 5fr);
	}

	.qb-build__viewer {
		position: sticky;
		top: var(--space-4, 16px);
	}
}

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

.qb-build__stage {
	position: relative;
	width: 100%;
	aspect-ratio: 4 / 5;
	max-height: 70vh;
	min-height: 240px;
	background: var(--surface-sunken, #e9dfd3);
	border-radius: var(--radius-lg, 32px);
	overflow: hidden;
	touch-action: pan-y;
}

@media (min-width: 900px) {
	.qb-build__stage {
		aspect-ratio: auto;
		height: clamp(420px, calc(100vh - 220px), 680px);
		max-height: none;
	}
}

.qb-build__canvas {
	position: absolute;
	inset: 0;
}

.qb-build__canvas canvas {
	display: block;
	width: 100%;
	height: 100%;
	outline-offset: -3px;
}

.qb-build__loading {
	position: absolute;
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 0.4em;
	padding: var(--space-4, 16px);
	text-align: center;
	color: var(--ink-subtle, #605a68);
	background: var(--surface-sunken, #e9dfd3);
	font-variant-numeric: tabular-nums;
}

.qb-build__loading[hidden],
.qb-build__fallback[hidden],
.qb-build__plate[hidden],
.qb-build [hidden] {
	display: none !important;
}

/* The dimension line sits over the canvas and must not catch the pointer. */
.qb-build .qb-viewer__dim {
	pointer-events: none;
	z-index: 2;
}

@media (max-width: 560px) {
	.qb-build .qb-viewer__dim {
		display: none;
	}
}

/* ---------- Still render fallback ---------- */

.qb-build__fallback {
	position: absolute;
	inset: 0;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: var(--space-3, 12px);
	padding: var(--space-4, 16px);
	background: var(--surface-sunken, #e9dfd3);
	text-align: center;
	z-index: 3;
}

.qb-build__still {
	position: relative;
	flex: 1 1 auto;
	min-height: 0;
	width: 100%;
	max-width: 100%;
	aspect-ratio: 4 / 5;
	container-type: inline-size;
}

.qb-build__still-img {
	position: absolute;
	inset: 0;
	display: block;
	width: 100%;
	height: 100%;
	object-fit: contain;
}

/* Plate geometry copies the Build design, which places the words over the 4:5 render. */
.qb-build__plate {
	position: absolute;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	overflow: hidden;
	font-family: var(--font-sans, "Poppins", system-ui, sans-serif);
	font-weight: 600;
	line-height: 1.08;
	letter-spacing: -0.01em;
	text-align: center;
	white-space: pre;
}

.qb-build__plate--front {
	left: 37%;
	top: 43%;
	width: 26%;
	height: 18%;
	border-radius: 1.6cqw;
}

.qb-build__plate--back {
	left: 38.5%;
	top: 44%;
	width: 23.5%;
	height: 15.5%;
	border-radius: 1.4cqw;
}

.qb-build__plate-line {
	display: block;
	max-width: 100%;
}

.qb-build__plate-logo {
	display: block;
	width: 80%;
	height: 60%;
	mask-repeat: no-repeat;
	mask-position: center;
	mask-size: contain;
	-webkit-mask-repeat: no-repeat;
	-webkit-mask-position: center;
	-webkit-mask-size: contain;
}

.qb-build__fallback-msg {
	max-width: 36ch;
	color: var(--ink-subtle, #605a68);
}

/* ---------- Viewer bar ---------- */

.qb-build .qb-viewer__bar {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: var(--space-3, 12px) var(--space-4, 16px);
}

.qb-build .qb-viewer__view {
	min-height: 44px;
}

.qb-build .qb-viewer__hint {
	color: var(--ink-subtle, #605a68);
}

/* ---------- Gesture chips ---------- */

.qb-build__gestures {
	display: flex;
	flex-direction: column;
	gap: var(--space-3, 12px);
}

.qb-build__legend {
	display: flex;
	align-items: baseline;
	justify-content: space-between;
	gap: var(--space-3, 12px);
}

.qb-build__legend-note,
.qb-build__optional {
	color: var(--ink-subtle, #605a68);
	font-weight: 400;
}

.qb-build__chips {
	display: flex;
	flex-wrap: wrap;
	gap: var(--space-2, 8px);
}

.qb-build__chip {
	min-height: 44px;
	padding: 0 var(--space-4, 16px);
	border: var(--border-control, 2px) solid var(--ink, #16151e);
	border-radius: var(--radius-pill, 100px);
	background: var(--surface, #f3ece4);
	color: var(--ink, #16151e);
	cursor: pointer;
	transition: background 240ms cubic-bezier(0.22, 0.61, 0.36, 1), transform 240ms cubic-bezier(0.22, 0.61, 0.36, 1);
}

.qb-build__chip:hover {
	transform: translateY(-1px);
}

.qb-build__chip:active {
	transform: translateY(2px);
}

.qb-build__chip[aria-pressed="true"] {
	background: var(--brand-tint, #e9e1f3);
}

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

.qb-build__step {
	padding-top: var(--space-5, 24px);
	border-top: var(--border-hair, 1px) solid var(--line, #dcd2c6);
}

.qb-build .qb-picker__head {
	display: flex;
	align-items: baseline;
	justify-content: space-between;
	gap: var(--space-3, 12px);
	margin-bottom: var(--space-3, 12px);
}

.qb-build .qb-picker__name {
	color: var(--ink-subtle, #605a68);
	font-weight: 400;
}

.qb-build .qb-picker__grid {
	display: flex;
	flex-wrap: wrap;
	gap: var(--space-1, 4px);
}

/* Swatches: 44px chips, a 2px ink ring when chosen, the shared focus ring. */
.qb-build .qb-swatch {
	display: inline-flex;
	padding: 3px;
	border: var(--border-control, 2px) solid transparent;
	border-radius: var(--radius-sm, 12px);
	background: transparent;
	cursor: pointer;
}

.qb-build .qb-swatch[aria-checked="true"] {
	border-color: var(--ink, #16151e);
}

.qb-build .qb-swatch__chip {
	display: block;
	width: 44px;
	height: 44px;
	border-radius: 9px;
	box-shadow: inset 0 0 0 var(--border-hair, 1px) var(--line-control, #857b6f);
}

.qb-build .qb-field__input {
	width: 100%;
	min-width: 0;
	resize: none;
	line-height: 1.4;
}

.qb-build textarea.qb-field__input {
	font-weight: 500;
	font-size: 17px;
}

.qb-build .qb-field__error {
	display: flex;
	align-items: flex-start;
	gap: var(--space-1, 4px);
	color: var(--danger-text, #a83a28);
}

.qb-build .qb-field__error::before {
	content: "!";
	flex: none;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 18px;
	height: 18px;
	margin-top: 1px;
	border: 2px solid currentColor;
	border-radius: 50%;
	font-size: 12px;
	font-weight: 600;
	line-height: 1;
}

/* ---------- Advanced preview ---------- */

.qb-build__advanced summary {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: var(--space-3, 12px);
	cursor: pointer;
	list-style: none;
}

.qb-build__advanced summary::-webkit-details-marker {
	display: none;
}

.qb-build__advanced summary::after {
	content: "+";
	font-size: 20px;
	line-height: 1;
	color: var(--ink-subtle, #605a68);
}

.qb-build__advanced[open] summary::after {
	content: "\2013";
}

.qb-build__advanced-body {
	display: flex;
	flex-direction: column;
	gap: var(--space-4, 16px);
	padding-top: var(--space-4, 16px);
}

.qb-build__advanced-note,
.qb-build__preview-warning,
.qb-build__file-status {
	color: var(--ink-subtle, #605a68);
}

.qb-build__preview-warning {
	color: var(--danger-text, #a83a28);
}

.qb-build__row {
	display: flex;
	flex-wrap: wrap;
	align-items: flex-end;
	gap: var(--space-3, 12px) var(--space-4, 16px);
}

.qb-build__row .qb-field {
	gap: var(--space-1, 4px);
}

.qb-build__grow {
	flex: 1 1 180px;
}

.qb-build__row select.qb-field__input {
	min-width: 150px;
	padding: var(--space-2, 8px) var(--space-3, 12px);
}

.qb-build__colour {
	width: 56px;
	height: 44px;
	padding: 2px;
	border: var(--border-control, 2px) solid var(--line-control, #857b6f);
	border-radius: var(--radius-sm, 12px);
	background: var(--surface-raised, #fffcf8);
	cursor: pointer;
}

.qb-build__range {
	width: 100%;
	min-width: 160px;
	accent-color: var(--brand, #5f4585);
}

/* ---------- Save and load ---------- */

.qb-build__files {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: var(--space-3, 12px);
}

.qb-build__file-status {
	flex: 1 1 100%;
	min-height: 1.4em;
}

.qb-build__file-status:empty {
	display: none;
}

/* ---------- Footer, price and the one Build button ---------- */

.qb-build .qb-panel__foot {
	align-items: flex-end;
}

.qb-build__price {
	font-family: var(--font-mono, "IBM Plex Mono", ui-monospace, monospace);
	font-weight: 500;
	font-variant-numeric: tabular-nums;
}

.qb-build__add {
	width: 100%;
}

.qb-build__add[aria-busy="true"] {
	opacity: 0.7;
}

/* ---------- Notices ---------- */

.qb-build__notice-body {
	display: flex;
	flex-direction: column;
	gap: var(--space-2, 8px);
	min-width: 0;
}

.qb-build__notice-actions {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: var(--space-2, 8px) var(--space-5, 24px);
}

.qb-build__fine {
	display: flex;
	gap: var(--space-3, 12px);
	align-items: flex-start;
	padding: var(--space-4, 16px) var(--space-5, 24px);
	color: var(--ink-muted, #55505c);
}

.qb-build__fine .qs-ico {
	color: var(--brand, #5f4585);
}

/* ---------- Focus ---------- */

.qb-build button:focus-visible,
.qb-build input:focus-visible,
.qb-build select:focus-visible,
.qb-build textarea:focus-visible,
.qb-build summary:focus-visible,
.qb-build a:focus-visible,
.qb-build canvas:focus-visible {
	outline: 3px solid var(--focus, #5f4585);
	outline-offset: 3px;
}

/* ---------- Reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
	.qb-build *,
	.qb-build *::before,
	.qb-build *::after {
		transition: none !important;
		animation: none !important;
	}

	.qb-build__chip:hover,
	.qb-build__chip:active {
		transform: none;
	}
}

/* ---------- Phones: robot first, then the panel, then the extras ---------- */
@media (max-width: 899px) {
	/* Idea chips as one scrollable row so the figure stays near the top. */
	.qb-build__ideas { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; padding-bottom: 4px; margin: 0 calc(-1 * var(--space-5, 24px)); padding-left: var(--space-5, 24px); padding-right: var(--space-5, 24px); }
	.qb-build__ideas::-webkit-scrollbar { display: none; }
	.qb-build__ideas-label { white-space: nowrap; }
	.qb-build__idea { flex: none; }

	/* The gesture chips sit after the colour and text panel. */
	.qb-build__viewer { display: contents; }
	.qb-build__grid { display: flex; flex-direction: column; gap: var(--space-5, 24px); }
	.qb-build__viewer > .qb-viewer { order: 0; }
	.qb-build__panel { order: 1; }
	.qb-build__gestures { order: 2; }
	.qb-build__stage { max-height: 62vh; }

	/* Save and Load share one row. */
	.qb-build__files.qb-build__step { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: center; gap: var(--space-3, 12px); }
	.qb-build__files > .qb-btn { min-width: 0; justify-content: center; padding-left: 12px; padding-right: 12px; }
	.qb-build__files > .qb-build__file-status { grid-column: 1 / -1; }
	/* WordPress adds stray line breaks and empty paragraphs between the buttons; they would take grid cells. */
	.qb-build__files > br, .qb-build__files > p:not([class]) { display: none; }
}

/* Autop artefacts anywhere in the builder markup take flex and grid cells: never show them. */
.qb-build br:not([class]), .qb-build p:empty { display: none; }
@media (max-width: 899px) {
}
