/**
 * RB3DLabs Keychain Maker — Phase 3 customizer chrome.
 * Scoped under .rb3d-km to avoid theme/plugin collisions.
 */

.rb3d-km {
	--km-bg: #f8f7f3;
	--km-surface: #ffffff;
	--km-panel: #2a2c28;
	--km-panel-soft: #353832;
	--km-text: #242621;
	--km-text-inv: #f8f7f3;
	--km-muted: #5c5f57;
	--km-muted-inv: #a8aaa3;
	--km-border: #e3e3db;
	--km-accent: #f28c28;
	--km-accent-dark: #d96c12;
	--km-secondary: #477a61;
	--km-radius: 0.375rem;
	--km-radius-lg: 0.75rem;
	--km-font: "Hanken Grotesk", Bahnschrift, "Segoe UI", sans-serif;
	--km-font-display: "Space Grotesk", Bahnschrift, "Segoe UI", sans-serif;
	--km-shadow: 0 1px 3px rgba(36, 38, 33, 0.08);

	box-sizing: border-box;
	width: 100%;
	max-width: 100%;
	min-width: 0;
	margin: 0;
	color: var(--km-text);
	font-family: var(--km-font);
	background: var(--km-bg);
	border: 1px solid var(--km-border);
	border-radius: var(--km-radius-lg);
	overflow: hidden;
	box-shadow: var(--km-shadow);
}

.rb3d-km *,
.rb3d-km *::before,
.rb3d-km *::after {
	box-sizing: border-box;
}

/* —— Header —— */
.rb3d-km__header {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: 0.75rem 1rem;
	padding: 0.85rem 1rem;
	background: var(--km-panel);
	color: var(--km-text-inv);
	border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.rb3d-km__brand {
	display: flex;
	align-items: center;
	gap: 0.65rem;
	min-width: 0;
}

.rb3d-km__brand-mark {
	flex: 0 0 auto;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 2.25rem;
	height: 2.25rem;
	border-radius: var(--km-radius);
	background: var(--km-accent);
	color: #1a1c17;
	font-family: var(--km-font-display);
	font-weight: 700;
	font-size: 0.8rem;
	letter-spacing: 0.02em;
}

.rb3d-km__brand-text {
	min-width: 0;
}

.rb3d-km__brand-name {
	display: block;
	font-size: 0.7rem;
	font-weight: 600;
	letter-spacing: 0.06em;
	text-transform: uppercase;
	color: var(--km-muted-inv);
	line-height: 1.2;
}

.rb3d-km__title {
	margin: 0.1rem 0 0;
	font-family: var(--km-font-display);
	font-size: 1.05rem;
	font-weight: 600;
	line-height: 1.25;
	color: var(--km-text-inv);
}

.rb3d-km__header-actions {
	display: flex;
	flex-wrap: wrap;
	gap: 0.5rem;
}

.rb3d-km__btn {
	appearance: none;
	border: 1px solid transparent;
	border-radius: var(--km-radius);
	padding: 0.45rem 0.9rem;
	font: inherit;
	font-size: 0.8125rem;
	font-weight: 600;
	cursor: pointer;
	line-height: 1.3;
	transition: background 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}

.rb3d-km__btn:focus-visible {
	outline: 2px solid var(--km-accent);
	outline-offset: 2px;
}

.rb3d-km__btn:disabled {
	opacity: 0.45;
	cursor: not-allowed;
}

.rb3d-km__btn--ghost {
	background: transparent;
	border-color: rgba(248, 247, 243, 0.25);
	color: var(--km-text-inv);
}

.rb3d-km__btn--ghost:hover:not(:disabled) {
	background: rgba(255, 255, 255, 0.08);
}

.rb3d-km__btn--primary {
	background: var(--km-accent);
	color: #1a1c17;
}

.rb3d-km__btn--primary:hover:not(:disabled) {
	background: var(--km-accent-dark);
	color: #fff;
}

/* —— Layout —— */
.rb3d-km__layout {
	display: grid;
	grid-template-columns: 1fr;
	min-height: min(70vh, 640px);
	background: var(--km-bg);
}

@media (min-width: 900px) {
	.rb3d-km__layout {
		grid-template-columns: minmax(17rem, 22rem) minmax(0, 1fr);
		height: min(78vh, 720px);
	}
}

.rb3d-km__sidebar {
	display: flex;
	flex-direction: column;
	min-width: 0;
	min-height: 0;
	background: var(--km-surface);
	border-bottom: 1px solid var(--km-border);
}

@media (min-width: 900px) {
	.rb3d-km__sidebar {
		border-bottom: none;
		border-right: 1px solid var(--km-border);
	}
}

.rb3d-km__form {
	flex: 1 1 auto;
	min-height: 0;
	display: flex;
	flex-direction: column;
}

.rb3d-km__params {
	flex: 1 1 auto;
	overflow-y: auto;
	overflow-x: hidden;
	max-height: min(48vh, 420px);
	padding: 0.65rem 0.75rem 0.85rem;
	-webkit-overflow-scrolling: touch;
}

@media (min-width: 900px) {
	.rb3d-km__params {
		max-height: none;
	}
}

.rb3d-km__status {
	margin: 0;
	padding: 0.55rem 0.85rem;
	font-size: 0.75rem;
	color: var(--km-muted);
	border-top: 1px solid var(--km-border);
	background: var(--km-bg);
	min-height: 1.5em;
}

.rb3d-km__status.is-ok {
	color: var(--km-secondary);
}

.rb3d-km__status.is-warn {
	color: var(--km-accent-dark);
}

.rb3d-km__status.is-error {
	color: #a33;
}

.rb3d-km__icon-btn {
	appearance: none;
	border: 1px solid rgba(248, 247, 243, 0.22);
	background: transparent;
	color: var(--km-text-inv);
	border-radius: var(--km-radius);
	padding: 0.25rem 0.5rem;
	font: inherit;
	font-size: 0.7rem;
	cursor: pointer;
}

.rb3d-km__icon-btn:hover:not(:disabled) {
	background: rgba(255, 255, 255, 0.08);
}

.rb3d-km__icon-btn:disabled {
	opacity: 0.4;
	cursor: not-allowed;
}

.rb3d-km__canvas {
	display: block;
	position: relative;
	z-index: 1;
	width: 100%;
	height: 100%;
	touch-action: none;
}

.rb3d-km__viewport.is-loading .rb3d-km__preview-spinner {
	opacity: 1;
}

.rb3d-km__preview-spinner {
	position: absolute;
	top: 0.75rem;
	right: 0.75rem;
	width: 1.1rem;
	height: 1.1rem;
	border: 2px solid rgba(248, 247, 243, 0.25);
	border-top-color: var(--km-accent);
	border-radius: 50%;
	opacity: 0;
	pointer-events: none;
	transition: opacity 0.15s ease;
	animation: rb3d-km-spin 0.7s linear infinite;
}

@keyframes rb3d-km-spin {
	to {
		transform: rotate(360deg);
	}
}

@media (prefers-reduced-motion: reduce) {
	.rb3d-km__preview-spinner {
		animation: none;
		border-top-color: var(--km-accent);
	}
}

/* —— Sections —— */
.rb3d-km__section {
	border: 1px solid var(--km-border);
	border-radius: var(--km-radius);
	background: var(--km-bg);
	margin-bottom: 0.5rem;
}

.rb3d-km__section-summary {
	cursor: pointer;
	list-style: none;
	padding: 0.55rem 0.7rem;
	font-size: 0.8125rem;
	font-weight: 600;
	color: var(--km-text);
	user-select: none;
}

.rb3d-km__section-summary::-webkit-details-marker {
	display: none;
}

.rb3d-km__section-summary::before {
	content: "";
	display: inline-block;
	width: 0.35rem;
	height: 0.35rem;
	margin-right: 0.45rem;
	border-right: 2px solid var(--km-accent);
	border-bottom: 2px solid var(--km-accent);
	transform: rotate(-45deg);
	vertical-align: 0.15rem;
	transition: transform 0.15s ease;
}

.rb3d-km__section[open] > .rb3d-km__section-summary::before {
	transform: rotate(45deg);
	vertical-align: 0.25rem;
}

.rb3d-km__section-body {
	padding: 0 0.7rem 0.75rem;
}

/* —— Fields —— */
.rb3d-km__field {
	margin-top: 0.65rem;
}

.rb3d-km__field.is-conditionally-hidden,
.rb3d-km__field[hidden] {
	display: none !important;
}

.rb3d-km__label {
	display: flex;
	align-items: baseline;
	justify-content: space-between;
	gap: 0.5rem;
	margin-bottom: 0.25rem;
	font-size: 0.72rem;
	font-weight: 500;
	color: var(--km-muted);
}

.rb3d-km__unit {
	font-size: 0.65rem;
	text-transform: uppercase;
	letter-spacing: 0.04em;
	opacity: 0.85;
}

.rb3d-km__check {
	display: flex;
	align-items: flex-start;
	gap: 0.45rem;
	font-size: 0.8125rem;
	font-weight: 500;
	cursor: pointer;
	color: var(--km-text);
}

.rb3d-km__check input {
	margin-top: 0.15rem;
	accent-color: var(--km-accent);
}

.rb3d-km__control {
	width: 100%;
	max-width: 100%;
	padding: 0.45rem 0.55rem;
	border: 1px solid var(--km-border);
	border-radius: var(--km-radius);
	background: var(--km-surface);
	color: var(--km-text);
	font: inherit;
	font-size: 0.8125rem;
}

.rb3d-km__control:focus {
	outline: none;
	border-color: var(--km-accent);
	box-shadow: 0 0 0 2px rgba(242, 140, 40, 0.2);
}

.rb3d-km__control--number {
	width: 4.75rem;
	flex: 0 0 auto;
	font-variant-numeric: tabular-nums;
}

.rb3d-km__number-row {
	display: flex;
	align-items: center;
	gap: 0.5rem;
}

.rb3d-km__number-row--slider .rb3d-km__range {
	flex: 1 1 auto;
	min-width: 0;
	accent-color: var(--km-accent);
}

.rb3d-km__color-row {
	display: flex;
	align-items: center;
	gap: 0.5rem;
}

.rb3d-km__control--color {
	width: 2.5rem;
	height: 2.25rem;
	padding: 0.15rem;
	flex: 0 0 auto;
	cursor: pointer;
}

.rb3d-km__control--color-hex {
	flex: 1 1 auto;
	font-family: ui-monospace, Consolas, monospace;
	text-transform: uppercase;
}

/* —— Preview panel —— */
.rb3d-km__preview {
	display: flex;
	flex-direction: column;
	min-width: 0;
	min-height: 280px;
	background: var(--km-panel);
	color: var(--km-text-inv);
}

.rb3d-km__preview-toolbar {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 0.5rem;
	padding: 0.45rem 0.75rem;
	background: var(--km-panel-soft);
	border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.rb3d-km__preview-label {
	font-size: 0.7rem;
	font-weight: 600;
	letter-spacing: 0.05em;
	text-transform: uppercase;
	color: var(--km-muted-inv);
}

.rb3d-km__viewport {
	flex: 1 1 auto;
	position: relative;
	min-height: 240px;
}

@media (min-width: 900px) {
	.rb3d-km__viewport {
		min-height: 0;
	}
}

.rb3d-km__preview-placeholder {
	position: absolute;
	inset: 0;
	z-index: 2;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	padding: 1.5rem;
	text-align: center;
	background:
		radial-gradient(ellipse at 50% 40%, rgba(242, 140, 40, 0.12), transparent 55%),
		linear-gradient(160deg, #2a2c28 0%, #1e201c 100%);
	pointer-events: none;
}

/* Author `display:flex` would otherwise override the UA [hidden] rule. */
.rb3d-km__preview-placeholder[hidden] {
	display: none;
}

.rb3d-km__preview-placeholder-title {
	margin: 0 0 0.35rem;
	font-family: var(--km-font-display);
	font-size: 1.1rem;
	font-weight: 600;
}

.rb3d-km__preview-placeholder-text {
	margin: 0;
	max-width: 22rem;
	font-size: 0.8125rem;
	line-height: 1.45;
	color: var(--km-muted-inv);
}

.rb3d-km__preview-placeholder-meta {
	margin: 0.85rem 0 0;
	font-size: 0.7rem;
	font-family: ui-monospace, Consolas, monospace;
	color: rgba(242, 140, 40, 0.9);
}

.rb3d-km__result {
	margin: 0.75rem 1rem 0;
	padding: 0.65rem 0.85rem;
	border-radius: var(--km-radius);
	background: rgba(71, 122, 97, 0.12);
	border: 1px solid rgba(71, 122, 97, 0.35);
	color: var(--km-text-inv);
	font-size: 0.8125rem;
	line-height: 1.45;
}

.rb3d-km__result[hidden] {
	display: none;
}

.rb3d-km__privacy {
	margin: 0;
	padding: 0.65rem 1rem;
	font-size: 0.75rem;
	line-height: 1.4;
	color: var(--km-muted);
	border-top: 1px solid var(--km-border);
	background: var(--km-surface);
}

/* Mobile: params above preview (grid order default) */
@media (max-width: 899px) {
	.rb3d-km__layout {
		min-height: 0;
	}

	.rb3d-km__preview {
		min-height: 260px;
		height: 280px;
	}
}
