/**
 * 怡和設計 — 圖庫燈箱 (yh-gallery-lightbox)
 * 對象：核心 Gutenberg 圖庫區塊 .wp-block-gallery.has-nested-images
 * 配色沿用主題色票：強調金 #E6C170 只做重點提示，不大面積上色。
 */

/* ---------- 前台圖庫：可點擊的提示 ---------- */
.wp-block-gallery.has-nested-images figure.wp-block-image img {
	cursor: zoom-in;
	transition: filter .4s cubic-bezier(.22, .61, .36, 1);
}

@media (hover: hover) {
	.wp-block-gallery.has-nested-images figure.wp-block-image:hover img {
		filter: brightness(.88);
	}
}

/* ---------- 開啟時鎖定背景捲動 ---------- */
body.yhlb-lock {
	position: fixed;
	left: 0;
	right: 0;
	width: 100%;
	overflow: hidden;
}

/* ---------- 燈箱主容器 ---------- */
.yhlb {
	position: fixed;
	inset: 0;
	z-index: 99999;
	opacity: 0;
	overscroll-behavior: contain;
	transition: opacity .24s ease;
	-webkit-tap-highlight-color: transparent;
}

.yhlb[hidden] {
	display: none;
}

.yhlb.is-open {
	opacity: 1;
}

.yhlb__backdrop {
	position: absolute;
	inset: 0;
	background: rgba(18, 15, 15, .972);
	-webkit-backdrop-filter: blur(14px) saturate(.85);
	backdrop-filter: blur(14px) saturate(.85);
}

/* ---------- 圖片舞台 ---------- */
.yhlb__stage {
	position: relative;
	z-index: 1;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 100%;
	height: 100%;
	box-sizing: border-box;
	padding: clamp(60px, 9vh, 100px) clamp(18px, 7.5vw, 116px) clamp(78px, 11vh, 112px);
}

.yhlb__stage.is-loading::after {
	content: "";
	position: absolute;
	top: 50%;
	left: 50%;
	width: 26px;
	height: 26px;
	margin: -13px 0 0 -13px;
	border: 1px solid rgba(255, 255, 255, .2);
	border-top-color: #E6C170;
	border-radius: 50%;
	animation: yhlb-spin .8s linear infinite;
}

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

/* ---------- 圖片與圖說 ---------- */
.yhlb__figure {
	position: relative;
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 20px;
	max-width: 100%;
	max-height: 100%;
	margin: 0;
	opacity: 0;
}

.yhlb__figure.is-enter {
	animation: yhlb-in .36s cubic-bezier(.22, .61, .36, 1) forwards;
}

@keyframes yhlb-in {
	from { opacity: 0; transform: scale(.985); }
	to   { opacity: 1; transform: none; }
}

.yhlb__img {
	display: block;
	width: auto;
	height: auto;
	max-width: 100%;
	/* 保留給關閉鈕、頁碼的空間；有圖說時再多讓出兩行。
	   刻意不使用 object-fit 縮放，讓 <img> 方框等於圖片本身，
	   「點圖片外圍關閉」才不會被透明的留白區吃掉。 */
	max-height: calc(100vh - 185px);
	max-height: calc(100dvh - 185px);
	border-radius: 2px;
	box-shadow: 0 26px 74px rgba(0, 0, 0, .55);
}

.yhlb.has-cap .yhlb__img {
	max-height: calc(100vh - 255px);
	max-height: calc(100dvh - 255px);
}

.yhlb__cap {
	max-width: 54ch;
	margin: 0;
	text-align: center;
	font-size: 14px;
	line-height: 1.85;
	letter-spacing: .04em;
	color: rgba(255, 255, 255, .62);
}

.yhlb__cap:empty {
	display: none;
}

/* ---------- 控制項 ---------- */
.yhlb__btn {
	position: absolute;
	z-index: 2;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 52px;
	height: 52px;
	margin: 0;
	padding: 0;
	box-sizing: border-box;
	border: 1px solid rgba(255, 255, 255, .16);
	border-radius: 50%;
	background: rgba(255, 255, 255, .035);
	color: rgba(255, 255, 255, .8);
	cursor: pointer;
	-webkit-appearance: none;
	appearance: none;
	transition: background .25s ease, border-color .25s ease, color .25s ease;
}

.yhlb__btn svg {
	width: 20px;
	height: 20px;
	fill: none;
	stroke: currentColor;
	stroke-width: 1.25;
	stroke-linecap: round;
	stroke-linejoin: round;
}

@media (hover: hover) {
	.yhlb__btn:hover {
		background: rgba(255, 255, 255, .1);
		border-color: rgba(255, 255, 255, .38);
		color: #fff;
	}
}

.yhlb__btn:focus-visible {
	outline: 2px solid #E6C170;
	outline-offset: 3px;
}

.yhlb__close {
	top: clamp(14px, 3vh, 30px);
	right: clamp(14px, 3vw, 30px);
}

.yhlb__nav {
	top: 50%;
	transform: translateY(-50%);
}

.yhlb__nav--prev { left: clamp(10px, 2.4vw, 34px); }
.yhlb__nav--next { right: clamp(10px, 2.4vw, 34px); }

/* ---------- 頁碼 ---------- */
.yhlb__counter {
	position: absolute;
	z-index: 2;
	left: 50%;
	bottom: clamp(18px, 3.4vh, 36px);
	transform: translateX(-50%);
	display: flex;
	align-items: center;
	gap: 12px;
	font-size: 12px;
	letter-spacing: .24em;
	color: rgba(255, 255, 255, .45);
	font-variant-numeric: tabular-nums;
	pointer-events: none;
}

.yhlb__idx { color: #E6C170; }

.yhlb__sep {
	width: 22px;
	height: 1px;
	background: rgba(255, 255, 255, .22);
}

/* 單張圖時不需要換頁 */
.yhlb.is-single .yhlb__nav,
.yhlb.is-single .yhlb__counter {
	display: none;
}

/* ---------- 螢幕閱讀器播報區 ---------- */
.yhlb__live {
	position: absolute;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip: rect(0 0 0 0);
	clip-path: inset(50%);
	white-space: nowrap;
	border: 0;
}

/* ---------- 手機版 ---------- */
@media (max-width: 781px) {
	.yhlb__stage {
		padding: 66px 14px 112px;
	}

	.yhlb__img {
		max-height: calc(100vh - 168px);
		max-height: calc(100dvh - 168px);
	}

	.yhlb.has-cap .yhlb__img {
		max-height: calc(100vh - 238px);
		max-height: calc(100dvh - 238px);
	}

	.yhlb__cap {
		font-size: 13px;
		line-height: 1.8;
	}

	.yhlb__btn {
		width: 46px;
		height: 46px;
	}

	.yhlb__btn svg {
		width: 18px;
		height: 18px;
	}

	.yhlb__close {
		top: calc(14px + env(safe-area-inset-top));
		right: 14px;
	}

	.yhlb__nav {
		top: auto;
		bottom: calc(18px + env(safe-area-inset-bottom));
		transform: none;
	}

	.yhlb__nav--prev { left: 18px; }
	.yhlb__nav--next { right: 18px; }

	.yhlb__counter {
		bottom: calc(34px + env(safe-area-inset-bottom));
	}
}

/* ---------- 尊重減少動態偏好 ---------- */
@media (prefers-reduced-motion: reduce) {
	.yhlb,
	.yhlb__btn,
	.wp-block-gallery.has-nested-images figure.wp-block-image img {
		transition-duration: .01ms !important;
	}

	.yhlb__figure.is-enter {
		animation-duration: .01ms !important;
	}

	.yhlb__stage.is-loading::after {
		animation-duration: 1.8s !important;
	}
}
