/**
 * Polat AR — real AR ring try-on modal.
 *
 * Mobile-first, token-driven (--polat-*), no !important except the
 * reduced-motion guard. Loaded only on the front page.
 */

/* The HTML `hidden` attribute only sets `display:none`, which our explicit
 * `display:flex`/`block` rules below would override — leaving "hidden" overlays
 * (loading/error) visibly covering the live camera. Force it back so toggling
 * the `hidden` attribute from JS actually hides the element. */
.ar-modal [hidden] {
	display: none !important;
}

.ar-modal {
	position: fixed;
	inset: 0;
	z-index: 1000;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 0;
	opacity: 0;
	visibility: hidden;
	transition: opacity 0.3s var(--polat-ease), visibility 0s linear 0.3s;
}
.ar-modal.is-open {
	opacity: 1;
	visibility: visible;
	transition: opacity 0.3s var(--polat-ease);
}

.ar-modal__backdrop {
	position: absolute;
	inset: 0;
	background: rgba(8, 7, 5, 0.92);
	backdrop-filter: blur(6px);
}

.ar-modal__dialog {
	position: relative;
	width: 100%;
	height: 100%;
	max-width: 560px;
	max-height: 100%;
	display: flex;
	flex-direction: column;
	background: var(--polat-night);
	color: #fff;
	overflow: hidden;
}

/* ----- Header ----- */
.ar-modal__bar {
	position: relative;
	z-index: 4;
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	padding: 14px 16px;
	background: linear-gradient(180deg, rgba(14, 12, 10, 0.95), rgba(14, 12, 10, 0));
}
.ar-modal__title {
	font-family: var(--polat-font-serif);
	font-size: 19px;
	font-weight: 500;
	letter-spacing: 0.2px;
	color: var(--polat-gold-light);
}
.ar-modal__bar-actions {
	display: flex;
	align-items: center;
	gap: 8px;
}

.ar-iconbtn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 40px;
	height: 40px;
	border-radius: 50%;
	border: 1px solid rgba(228, 201, 126, 0.3);
	background: rgba(255, 255, 255, 0.04);
	color: #fff;
	cursor: pointer;
	transition: background 0.2s var(--polat-ease), border-color 0.2s var(--polat-ease);
}
.ar-iconbtn:hover {
	background: rgba(228, 201, 126, 0.14);
	border-color: var(--polat-gold-light);
}
.ar-iconbtn svg {
	width: 20px;
	height: 20px;
}

/* ----- Stage (camera + canvases) ----- */
.ar-modal__stage {
	position: relative;
	flex: 1;
	min-height: 0;
	overflow: hidden;
	background: #000;
}
.ar-modal__stage.is-mirrored .ar-modal__canvas {
	transform: rotateY(180deg);
}

.ar-modal__canvas {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	display: block;
	object-fit: cover;
}
/* The hand-tracker canvas shows the video feed; the VTO canvas overlays the 3D ring. */
.ar-modal__canvas--track { z-index: 1; }
.ar-modal__canvas--vto { z-index: 2; }

/* ----- Live status pill ----- */
.ar-modal__status {
	position: absolute;
	z-index: 3;
	top: 14px;
	left: 50%;
	transform: translateX(-50%);
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 7px 14px;
	background: rgba(14, 12, 10, 0.72);
	border: 1px solid rgba(228, 201, 126, 0.25);
	border-radius: 30px;
	font-size: 10.5px;
	letter-spacing: 1.5px;
	text-transform: uppercase;
	color: var(--polat-gold-light);
	white-space: nowrap;
}
.ar-modal__status-dot {
	width: 6px;
	height: 6px;
	border-radius: 50%;
	background: var(--polat-gold-light);
	animation: polat-pulse-dot 1.4s infinite;
}
.ar-modal__status-dot.is-on {
	background: var(--polat-success);
}

/* ----- Hint ----- */
.ar-modal__hint {
	position: absolute;
	z-index: 3;
	left: 50%;
	bottom: 120px;
	transform: translateX(-50%);
	max-width: 80%;
	padding: 10px 16px;
	text-align: center;
	font-size: 13px;
	line-height: 1.5;
	color: var(--polat-dark-text);
	background: rgba(14, 12, 10, 0.6);
	border-radius: 12px;
}

/* ----- Loading & error overlays ----- */
.ar-modal__overlay {
	position: absolute;
	inset: 0;
	z-index: 5;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 18px;
	padding: 32px;
	text-align: center;
	background: var(--polat-night);
}
.ar-modal__spinner {
	width: 46px;
	height: 46px;
	border-radius: 50%;
	border: 3px solid rgba(228, 201, 126, 0.2);
	border-top-color: var(--polat-gold-light);
	animation: polat-ar-spin 0.9s linear infinite;
}
.ar-modal__overlay-text {
	max-width: 320px;
	font-size: 14px;
	line-height: 1.6;
	color: var(--polat-dark-text-2);
}
.ar-modal__overlay-icon {
	color: var(--polat-gold-light);
}
.ar-modal__overlay-icon svg {
	width: 40px;
	height: 40px;
}

@keyframes polat-ar-spin {
	to { transform: rotate(360deg); }
}

/* ----- Swatch panel inside the modal ----- */
.ar-modal__tray {
	position: relative;
	z-index: 4;
	display: flex;
	align-items: center;
	gap: 14px;
	padding: 16px;
	background: linear-gradient(0deg, rgba(14, 12, 10, 0.96), rgba(14, 12, 10, 0));
}
.ar-modal__swatches {
	display: flex;
	gap: 10px;
	flex: 1;
	overflow-x: auto;
	scrollbar-width: none;
}
.ar-modal__swatches::-webkit-scrollbar { display: none; }

.ar-modal__swatch {
	flex: 0 0 auto;
	width: 46px;
	height: 46px;
	border-radius: 50%;
	border: 2px solid rgba(255, 255, 255, 0.25);
	cursor: pointer;
	transition: transform 0.2s var(--polat-ease), border-color 0.2s var(--polat-ease);
}
.ar-modal__swatch:hover { transform: translateY(-2px); }
.ar-modal__swatch.is-active { border-color: var(--polat-gold-light); }

.ar-modal__current {
	flex: 0 0 auto;
	max-width: 40%;
	font-size: 12px;
	line-height: 1.4;
	color: var(--polat-dark-text-3);
}

/* Prevent background scroll while the modal owns the viewport. */
html.ar-modal-open,
html.ar-modal-open body {
	overflow: hidden;
}

/* ----- Launch button hint under the static preview ----- */
.ar-tryon__privacy {
	margin-top: 12px;
	font-size: 11.5px;
	line-height: 1.5;
	color: var(--polat-ink-light);
}

@media (min-width: 768px) {
	.ar-modal__dialog {
		max-height: 92vh;
		border-radius: 14px;
		border: 1px solid var(--polat-line-dark);
	}
	.ar-modal__hint { bottom: 110px; }
}

@media (prefers-reduced-motion: reduce) {
	.ar-modal,
	.ar-modal__spinner,
	.ar-modal__status-dot {
		transition: none !important;
		animation: none !important;
	}
}
