/* Turn On Condition Image Gallery — all selectors are prefixed with .tocg- (D05). Motion and mobile layout: D14. */

.tocg-trigger-wrap,
.tocg-modal {
	--tocg-accent: #162937; /* Turn On add-to-cart navy (render.php addToCartBg default) */
	--tocg-text: var(--wp--preset--color--contrast, #1d1d1f);
	--tocg-surface: var(--wp--preset--color--base, #ffffff);
	--tocg-muted: #6b6b70;
	--tocg-border: rgba(0, 0, 0, 0.14);
	--tocg-stage-bg: #f2f3f5;
	--tocg-radius: 14px;
	--tocg-ease: cubic-bezier(0.2, 0.8, 0.2, 1);
	--tocg-ease-in: cubic-bezier(0.4, 0, 1, 1);
}

.tocg-mount,
.tocg-trigger-wrap[hidden],
.tocg-modal[hidden],
.tocg-modal [hidden] {
	display: none !important;
}

.tocg-modal,
.tocg-modal *,
.tocg-modal *::before,
.tocg-modal *::after {
	box-sizing: border-box;
}

/* ---------- trigger button ---------- */

/* The wrapper animates its height (grid rows 0fr -> 1fr), so content below moves smoothly
   instead of jumping when the button appears or disappears. */
.tocg-trigger-wrap {
	display: grid;
	grid-template-rows: 1fr;
	transition: grid-template-rows 0.28s var(--tocg-ease);
}

.tocg-trigger-wrap.is-collapsed {
	grid-template-rows: 0fr;
	transition-timing-function: var(--tocg-ease-in);
	transition-duration: 0.2s;
}

.tocg-trigger-inner {
	min-height: 0;
	overflow: hidden;
	padding: 6px 2px 14px; /* room for focus outline and shadow */
}

.tocg-trigger {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	min-height: 44px;
	padding: 9px 16px 9px 12px;
	border: 1px solid var(--tocg-border);
	border-radius: 999px;
	background: var(--tocg-surface);
	color: var(--tocg-text);
	font: inherit;
	font-size: 0.875rem;
	font-weight: 500;
	line-height: 1.3;
	text-align: left;
	cursor: pointer;
	opacity: 1;
	transform: none;
	transition: opacity 0.24s var(--tocg-ease) 0.06s, transform 0.3s var(--tocg-ease) 0.06s, border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
	-webkit-tap-highlight-color: transparent;
}

.tocg-trigger-wrap.is-collapsed .tocg-trigger {
	opacity: 0;
	transform: translateY(6px) scale(0.97);
	transition-delay: 0s;
	transition-duration: 0.14s;
}

.tocg-trigger:hover {
	border-color: var(--tocg-accent);
	box-shadow: 0 2px 10px rgba(22, 41, 55, 0.12);
}

.tocg-trigger:active {
	transform: scale(0.98);
	background-color: #f6f7f8;
}

.tocg-trigger:focus-visible {
	outline: 2px solid var(--tocg-accent);
	outline-offset: 2px;
}

.tocg-trigger__icon {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	flex: none;
	width: 28px;
	height: 28px;
	border-radius: 50%;
	background: var(--tocg-accent);
	color: #fff;
}

.tocg-trigger__icon svg {
	width: 16px;
	height: 16px;
}

/* New condition chosen while the button is visible: only the text changes. */
.tocg-trigger__text.is-swapping {
	animation: tocg-text-in 0.26s var(--tocg-ease);
}

@keyframes tocg-text-in {
	from {
		opacity: 0;
		transform: translateY(4px);
	}
}

/* ---------- modal ---------- */

.tocg-modal {
	position: fixed;
	inset: 0;
	z-index: 100000;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 24px;
	font: inherit;
	color: var(--tocg-text);
}

.tocg-modal__backdrop {
	position: absolute;
	inset: 0;
	background: rgba(10, 12, 16, 0.72);
	opacity: 0;
	transition: opacity 0.25s ease;
}

.tocg-modal.is-open .tocg-modal__backdrop {
	opacity: 1;
}

.tocg-modal__dialog {
	position: relative;
	display: flex;
	flex-direction: column;
	gap: 12px;
	width: min(1100px, 100%);
	max-height: 100%;
	padding: 16px;
	border-radius: var(--tocg-radius);
	background: var(--tocg-surface);
	box-shadow: 0 24px 70px rgba(0, 0, 0, 0.35);
	overflow: hidden;
	opacity: 0;
	transform: translateY(12px) scale(0.98);
	transition: opacity 0.22s ease, transform 0.3s var(--tocg-ease);
}

.tocg-modal.is-open .tocg-modal__dialog {
	opacity: 1;
	transform: none;
}

.tocg-modal.is-dragging .tocg-modal__dialog,
.tocg-modal.is-dragging .tocg-modal__backdrop {
	transition: none;
}

.tocg-modal__dialog:focus {
	outline: none;
}

.tocg-modal__handle {
	display: none;
}

.tocg-modal__header {
	display: flex;
	align-items: flex-start;
	justify-content: space-between;
	gap: 12px;
}

.tocg-modal__title {
	margin: 0;
	font-size: 1.125rem;
	font-weight: 600;
	line-height: 1.3;
}

.tocg-modal__note {
	display: flex;
	gap: 6px;
	margin: 4px 0 0;
	font-size: 0.8125rem;
	line-height: 1.4;
	color: var(--tocg-muted);
}

.tocg-modal__note svg {
	flex: none;
	width: 15px;
	height: 15px;
	margin-top: 1px;
}

.tocg-icon-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	flex: none;
	width: 44px;
	height: 44px;
	padding: 0;
	border: 1px solid var(--tocg-border);
	border-radius: 50%;
	background: var(--tocg-surface);
	color: var(--tocg-text);
	cursor: pointer;
	transition: border-color 0.15s ease, transform 0.15s ease, opacity 0.15s ease;
	-webkit-tap-highlight-color: transparent;
}

.tocg-icon-btn:hover {
	border-color: var(--tocg-accent);
}

.tocg-icon-btn:active {
	transform: scale(0.94);
}

.tocg-icon-btn:focus-visible,
.tocg-thumbs__btn:focus-visible,
.tocg-text-btn:focus-visible {
	outline: 2px solid var(--tocg-accent);
	outline-offset: 2px;
}

/* ---------- stage ---------- */

.tocg-stage {
	position: relative;
	display: flex;
	flex-direction: column;
	flex: 1 1 auto;
	min-height: 0;
}

.tocg-modal__header,
.tocg-thumbs {
	flex: none;
}

.tocg-stage__viewport {
	position: relative;
	display: flex;
	align-items: center;
	justify-content: center;
	flex: 0 1 auto;
	height: min(68vh, 720px);
	min-height: 160px; /* shrinks on short screens so the thumbnails stay visible */
	border-radius: 10px;
	background: var(--tocg-stage-bg);
	overflow: hidden;
	touch-action: none;
	user-select: none;
	-webkit-user-select: none;
	cursor: zoom-in;
}

.tocg-stage__viewport.is-zoomed {
	cursor: grab;
}

.tocg-stage__viewport.is-zoomed:active {
	cursor: grabbing;
}

.tocg-stage__img {
	display: block;
	max-width: 100%;
	max-height: 100%;
	object-fit: contain;
	transform-origin: center center;
	will-change: transform;
	-webkit-user-drag: none;
	transition: opacity 0.2s ease;
}

/* Image follows the finger while swiping; animated only when released. */
.tocg-stage__img.is-settling {
	transition: transform 0.22s var(--tocg-ease), opacity 0.22s ease;
}

.tocg-stage__img.is-fading {
	opacity: 0;
}

.tocg-stage__status {
	position: absolute;
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 16px;
	text-align: center;
	font-size: 0.875rem;
	color: var(--tocg-muted);
	pointer-events: none;
}

.tocg-stage__error {
	pointer-events: auto;
}

.tocg-text-btn {
	padding: 0;
	border: 0;
	background: none;
	color: var(--tocg-accent);
	font: inherit;
	text-decoration: underline;
	cursor: pointer;
}

.tocg-spinner {
	width: 32px;
	height: 32px;
	border: 3px solid rgba(0, 0, 0, 0.12);
	border-top-color: var(--tocg-accent);
	border-radius: 50%;
	animation: tocg-spin 0.8s linear infinite;
}

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

.tocg-stage__nav {
	position: absolute;
	top: 50%;
	transform: translateY(-50%);
	background: rgba(255, 255, 255, 0.92);
	box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
}

.tocg-stage__nav:active {
	transform: translateY(-50%) scale(0.94);
}

.tocg-stage__nav--prev {
	left: 10px;
}

.tocg-stage__nav--next {
	right: 10px;
}

.tocg-stage__zoom {
	position: absolute;
	right: 10px;
	bottom: 10px;
	background: rgba(255, 255, 255, 0.92);
	box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
}

/* Counter sits on the photo, so it costs no extra height. */
.tocg-counter {
	position: absolute;
	left: 10px;
	bottom: 10px;
	padding: 4px 10px;
	border-radius: 999px;
	background: rgba(10, 12, 16, 0.6);
	color: #fff;
	font-size: 0.75rem;
	font-weight: 500;
	line-height: 1.4;
	font-variant-numeric: tabular-nums;
	pointer-events: none;
}

.tocg-counter:empty {
	display: none;
}

/* ---------- thumbnails ---------- */

.tocg-thumbs {
	display: flex;
	gap: 8px;
	margin: 0;
	padding: 2px;
	list-style: none;
	overflow-x: auto;
	scrollbar-width: thin;
	scroll-behavior: smooth;
	-webkit-overflow-scrolling: touch;
}

.tocg-thumbs__item {
	flex: none;
	margin: 0;
}

.tocg-thumbs__btn {
	display: block;
	width: 64px;
	height: 64px;
	padding: 0;
	border: 2px solid transparent;
	border-radius: 8px;
	background: var(--tocg-stage-bg);
	overflow: hidden;
	cursor: pointer;
	opacity: 0.6;
	transition: opacity 0.15s ease, border-color 0.15s ease;
	-webkit-tap-highlight-color: transparent;
}

.tocg-thumbs__btn[aria-current="true"] {
	border-color: var(--tocg-accent);
	opacity: 1;
}

.tocg-thumbs__btn img {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: cover;
}

.tocg-thumbs__btn.is-broken img {
	visibility: hidden;
}

/* ---------- phones: bottom sheet (D14) ---------- */

@media (max-width: 640px) {
	.tocg-modal {
		align-items: flex-end;
		padding: 0;
		padding-top: max(8px, env(safe-area-inset-top));
	}

	.tocg-modal__dialog {
		width: 100%;
		height: 100%;
		max-height: none;
		gap: 0;
		padding: 0;
		border-radius: 18px 18px 0 0;
		opacity: 1;
		transform: translateY(100%);
		transition: transform 0.34s var(--tocg-ease);
	}

	.tocg-modal.is-closing .tocg-modal__dialog {
		transition-timing-function: var(--tocg-ease-in);
		transition-duration: 0.24s;
	}

	/* Drag handle: shows the sheet can be pulled down to close. */
	.tocg-modal__handle {
		display: block;
		flex: none;
		width: 40px;
		height: 5px;
		margin: 8px auto 2px;
		border-radius: 3px;
		background: rgba(0, 0, 0, 0.18);
	}

	.tocg-modal__header {
		flex: none;
		align-items: center;
		padding: 6px 12px 12px 16px;
	}

	.tocg-modal__title {
		font-size: 1rem;
	}

	.tocg-modal__note {
		font-size: 0.75rem;
	}

	/* Photo uses the full width and all remaining height. */
	.tocg-stage__viewport {
		height: auto;
		min-height: 0;
		flex: 1 1 auto;
		border-radius: 0;
	}

	.tocg-stage__nav {
		width: 38px;
		height: 38px;
	}

	.tocg-stage__nav--prev {
		left: 8px;
	}

	.tocg-stage__nav--next {
		right: 8px;
	}

	.tocg-thumbs {
		flex: none;
		gap: 6px;
		padding: 10px 12px max(10px, env(safe-area-inset-bottom));
		border-top: 1px solid var(--tocg-border);
	}

	.tocg-thumbs__btn {
		width: 56px;
		height: 56px;
	}

	/* One photo: no thumbnails, keep the home-bar area free. */
	.tocg-thumbs[hidden] + .tocg-modal__safe {
		display: block;
	}
}

.tocg-modal__safe {
	display: none;
	height: env(safe-area-inset-bottom);
	flex: none;
}

/* ---------- reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
	.tocg-trigger-wrap,
	.tocg-trigger,
	.tocg-modal__backdrop,
	.tocg-modal__dialog,
	.tocg-stage__img,
	.tocg-stage__img.is-settling,
	.tocg-thumbs__btn {
		transition: none !important;
	}

	.tocg-trigger__text.is-swapping {
		animation: none;
	}

	.tocg-spinner {
		animation-duration: 2s;
	}

	.tocg-thumbs {
		scroll-behavior: auto;
	}
}
