/* 模块：图片放大遮罩 / Lightbox overlay visuals and transitions. */
#image-lightbox {
	position: fixed;
	left: 0;
	right: 0;
	top: 0; /* 覆盖整个视口顶端，避免与页眉出现缝隙 */
	bottom: 0;
	background: rgba(0, 0, 0, 0.5);
	backdrop-filter: blur(2px);
	display: flex;
	align-items: center;
	justify-content: center;
	opacity: 0;
	transform: translateY(8px) scale(0.98);
	transition: opacity 200ms ease, transform 200ms ease, visibility 200ms ease;
	visibility: hidden;
	z-index: 1610; /* 提高到高于 header 的层级，确保遮罩覆盖页眉 */
	padding: 24px;
	box-sizing: border-box;
	/* Ensure Pointer Events are delivered consistently (for drag/swipe/pinch) */
	touch-action: none;
}

#image-lightbox.active {
	opacity: 1;
	transform: translateY(0) scale(1);
	visibility: visible;
}

#image-lightbox .lightbox-content {
	position: relative;
	max-width: 90vw;
	max-height: 90vh; /* 使用完整视口高度，因为遮罩已覆盖 header */
	display: flex;
	align-items: center;
	justify-content: center;
	flex-direction: column;
	gap: 16px;
	overflow: visible; /* 允许放大后的图片不被裁剪 */
	/* prevent browser panning/zooming gestures from stealing events */
	touch-action: none;
}

#image-lightbox .lightbox-image-wrapper {
	position: relative;
	width: 100%;
	height: 100%;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: transform 300ms ease, opacity 300ms ease;
	overflow: visible; /* 放大时允许超出容器显示 */
	/* critical for pointer-based pinch/drag */
	touch-action: none;
}

#image-lightbox .lightbox-image-wrapper.slide-out-left {
	opacity: 0;
	transform: translateX(-100%);
}

#image-lightbox .lightbox-image-wrapper.slide-out-right {
	opacity: 0;
	transform: translateX(100%);
}

#image-lightbox .lightbox-image-wrapper.slide-in-from-left {
	transform: translateX(-100%);
	opacity: 0;
	transition: none; /* 禁用过渡以瞬间移动到初始位置 */
}

#image-lightbox .lightbox-image-wrapper.slide-in-from-right {
	transform: translateX(100%);
	opacity: 0;
	transition: none; /* 禁用过渡以瞬间移动到初始位置 */
}

#image-lightbox .lightbox-title {
	position: absolute;
	top: 16px;
	left: 50%;
	transform: translateX(-50%) translateY(-8px);
	max-width: 70%;
	padding: 8px 16px;
	background: var(--card-bg);
	color: var(--text-color);
	border: 1px solid var(--border-color);
	border-radius: 10px;
	box-shadow: 0 4px 12px var(--shadow-color);
	backdrop-filter: blur(6px);
	font-size: 0.95rem;
	text-align: center;
	z-index: 906;
	opacity: 0;
	transition: opacity 300ms ease, transform 300ms ease;
}

#image-lightbox .lightbox-title.show {
	opacity: 0.95;
	transform: translateX(-50%) translateY(0);
}

#image-lightbox .lightbox-controls {
	position: fixed;
	right: 24px;
	top: 50%;
	transform: translateY(-50%);
	display: flex;
	flex-direction: column;
	gap: 8px;
	z-index: 1625; /* 控件应高于遮罩和标题，确保可点击 */
}

#image-lightbox .lightbox-controls button {
	width: 40px;
	height: 40px;
	min-width: 40px;
	min-height: 40px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	border-radius: 10px;
	border: 1px solid var(--border-color);
	background: var(--secondary-bg);
	color: var(--text-color);
	font-size: 1.2rem;
	cursor: pointer;
	box-shadow: 0 1px 2px rgba(15, 23, 42, 0.12);
	transition: background 0.18s ease, border 0.18s ease, transform 0.18s ease;
}

#image-lightbox .lightbox-controls button:hover {
	background: var(--hover-bg);
}

#image-lightbox .lightbox-controls button:active {
	transform: scale(0.95);
	background: var(--active-bg);
}


#image-lightbox .lightbox-nav {
	position: fixed;
	top: 50%;
	transform: translateY(-50%);
	/* tall narrow buttons: 1:3 aspect ratio (width : height = 1:3) */
	height: 54px;
	aspect-ratio: 1 / 3;
	min-height: 54px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	border-radius: 8px;
	background: var(--secondary-bg);
	border: 1px solid var(--border-color);
	color: var(--text-color);
	box-shadow: 0 6px 18px rgba(0,0,0,0.14);
	z-index: 1620;
	cursor: pointer;
}

#image-lightbox .lightbox-prev { left: 6px; }
#image-lightbox .lightbox-next { right: 6px; }

#image-lightbox .lightbox-nav:hover { background: var(--hover-bg); }

#image-lightbox .lightbox-nav i {
	font-size: 1.1rem;
	line-height: 1;
}

/* Ensure icon glyphs are centered inside buttons (fix vertical offset) */
#image-lightbox button i,
#image-lightbox .lightbox-nav i,
#image-lightbox .lightbox-zoom-indicator button i,
#image-lightbox .lightbox-fullscreen i,
#image-lightbox .lightbox-close i {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	line-height: 1;
	height: 1em;
	width: 1em;
}

#image-lightbox button i,
#image-lightbox .lightbox-nav i {
	vertical-align: middle;
	font-size: 1.05rem; /* normalize icon size */
}

#image-lightbox .lightbox-content img {
	max-width: 100%;
	max-height: 100%;
	border-radius: 0;
	box-shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
	transition: transform 200ms ease;
	user-select: none;
	-webkit-user-select: none;
	-webkit-user-drag: none;
	pointer-events: auto;
}

#image-lightbox .lightbox-close {
	position: absolute;
	top: 16px;
	right: 16px;
	width: 40px;
	height: 40px;
	min-width: 40px;
	min-height: 40px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	border-radius: 10px;
	border: 1px solid var(--border-color);
	background: var(--secondary-bg);
	color: var(--text-color);
	font-size: 1.2rem;
	cursor: pointer;
	box-shadow: 0 1px 2px rgba(15, 23, 42, 0.12);
	transition: background 0.18s ease, border 0.18s ease, transform 0.18s ease;
	z-index: 1625;
}

#image-lightbox .lightbox-fullscreen {
	position: absolute;
	top: 16px;
	right: 64px; /* left of close */
	width: 40px;
	height: 40px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	border-radius: 10px;
	border: 1px solid var(--border-color);
	background: var(--secondary-bg);
	color: var(--text-color);
	font-size: 1.1rem;
	z-index: 1625;
	cursor: pointer;
}

#image-lightbox .lightbox-fullscreen:hover { background: var(--hover-bg); }

#image-lightbox.fullscreen-mode .lightbox-fullscreen {
	background: var(--active-bg);
}

/* When in fullscreen, hide controls that would otherwise overlay the image
   to provide an immersive view. Still allow keyboard navigation. */
#image-lightbox.fullscreen-mode .lightbox-controls,
#image-lightbox.fullscreen-mode .lightbox-filmstrip,
#image-lightbox.fullscreen-mode .lightbox-close,
#image-lightbox.fullscreen-mode .lightbox-download-btn,
#image-lightbox.fullscreen-mode .lightbox-locate-btn,
#image-lightbox.fullscreen-mode .lightbox-nav {
	opacity: 0;
	pointer-events: none;
	transform: translateY(-6px);
	transition: opacity 180ms ease, transform 180ms ease;
}

#image-lightbox.fullscreen-mode .lightbox-fullscreen,
#image-lightbox.fullscreen-mode .lightbox-zoom-indicator,
#image-lightbox.fullscreen-mode .lightbox-title {
	opacity: 0;
	pointer-events: none;
	transform: translateY(-6px);
}

/* Ensure the image can receive pointer/touch gestures in fullscreen */
#image-lightbox.fullscreen-mode .lightbox-content img {
	touch-action: none;
	pointer-events: auto;
}

/* Fallback: some browsers use the :fullscreen pseudo-class instead of preserving
   custom classes when an element enters fullscreen. Ensure controls are hidden
   in those cases as well. */
#image-lightbox:fullscreen .lightbox-controls,
#image-lightbox:-webkit-full-screen .lightbox-controls,
#image-lightbox:fullscreen .lightbox-filmstrip,
#image-lightbox:-webkit-full-screen .lightbox-filmstrip,
#image-lightbox:fullscreen .lightbox-close,
#image-lightbox:-webkit-full-screen .lightbox-close,
#image-lightbox:fullscreen .lightbox-download-btn,
#image-lightbox:-webkit-full-screen .lightbox-download-btn,
#image-lightbox:fullscreen .lightbox-locate-btn,
#image-lightbox:-webkit-full-screen .lightbox-locate-btn,
#image-lightbox:fullscreen .lightbox-nav,
#image-lightbox:-webkit-full-screen .lightbox-nav {
	opacity: 0;
	pointer-events: none;
	transform: translateY(-6px);
}

#image-lightbox:fullscreen .lightbox-content img,
#image-lightbox:-webkit-full-screen .lightbox-content img {
	touch-action: none;
	pointer-events: auto;
}

#image-lightbox:fullscreen .lightbox-fullscreen,
#image-lightbox:-webkit-full-screen .lightbox-fullscreen,
#image-lightbox:fullscreen .lightbox-zoom-indicator,
#image-lightbox:-webkit-full-screen .lightbox-zoom-indicator,
#image-lightbox:fullscreen .lightbox-title,
#image-lightbox:-webkit-full-screen .lightbox-title {
	opacity: 0;
	pointer-events: none;
	transform: translateY(-6px);
}

/* Force hide with higher specificity and !important to cover cases where
   inline styles or other rules prevent hiding in certain browsers. */
#image-lightbox.force-hide-controls .lightbox-controls,
#image-lightbox.force-hide-controls .lightbox-filmstrip,
#image-lightbox.force-hide-controls .lightbox-close,
#image-lightbox.force-hide-controls .lightbox-download-btn,
#image-lightbox.force-hide-controls .lightbox-locate-btn,
#image-lightbox.force-hide-controls .lightbox-nav,
#image-lightbox.force-hide-controls .lightbox-fullscreen,
#image-lightbox.force-hide-controls .lightbox-zoom-indicator,
#image-lightbox.force-hide-controls .lightbox-title {
	display: none !important;
	opacity: 0 !important;
	pointer-events: none !important;
}

#image-lightbox .lightbox-close:hover {
	background: var(--hover-bg);
}

#image-lightbox .lightbox-close:active {
	transform: scale(0.95);
	background: var(--active-bg);
}

#image-lightbox .lightbox-download-btn {
	position: absolute;
	top: 16px;
	left: 16px;
	width: 40px;
	height: 40px;
	min-width: 40px;
	min-height: 40px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	border-radius: 10px;
	border: 1px solid var(--border-color);
	background: var(--secondary-bg);
	color: var(--text-color);
	font-size: 1.2rem;
	cursor: pointer;
	box-shadow: 0 1px 2px rgba(15, 23, 42, 0.12);
	transition: background 0.18s ease, border 0.18s ease, transform 0.18s ease;
	z-index: 1625;
	padding: 0;
	margin: 0;
}

#image-lightbox .lightbox-download-btn i {
	display: flex;
	align-items: center;
	justify-content: center;
	line-height: 1;
}

#image-lightbox .lightbox-download-btn:hover {
	background: var(--hover-bg);
}

#image-lightbox .lightbox-download-btn:active {
	transform: scale(0.95);
	background: var(--active-bg);
}

#image-lightbox .lightbox-locate-btn {
	position: absolute;
	top: 16px;
	left: 64px;
	width: 40px;
	height: 40px;
	min-width: 40px;
	min-height: 40px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	border-radius: 10px;
	border: 1px solid var(--border-color);
	background: var(--secondary-bg);
	color: var(--text-color);
	font-size: 1.2rem;
	cursor: pointer;
	box-shadow: 0 1px 2px rgba(15, 23, 42, 0.12);
	transition: background 0.18s ease, border 0.18s ease, transform 0.18s ease;
	z-index: 1625;
	padding: 0;
	margin: 0;
}

#image-lightbox .lightbox-locate-btn i {
	display: flex;
	align-items: center;
	justify-content: center;
	line-height: 1;
}

#image-lightbox .lightbox-locate-btn:hover {
	background: var(--hover-bg);
}

#image-lightbox .lightbox-locate-btn:active {
	transform: scale(0.95);
	background: var(--active-bg);
}

/* 图片高亮效果 */
@keyframes highlight-blink {
	0%, 100% {
		box-shadow: 0 0 0 3px var(--primary-color);
	}
	50% {
		box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary-color) 30%, transparent);
	}
}

img.highlighted {
	box-shadow: 0 0 0 3px var(--primary-color);
	border-radius: 8px;
	animation: highlight-blink 0.6s ease-in-out 6 forwards; /* 闪烁 6 次 (3 秒) */
	transition: box-shadow 0.3s ease;
}

#image-lightbox .lightbox-zoom-indicator {
	position: fixed;
	left: 24px;
	bottom: 110px;
	padding: 8px 10px;
	min-width: 96px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
	border-radius: 10px;
	background: var(--card-bg);
	color: var(--text-color);
	border: 1px solid var(--border-color);
	box-shadow: 0 10px 30px var(--shadow-color);
	backdrop-filter: blur(6px);
	z-index: 906;
}

#image-lightbox .zoom-input {
	width: 76px;
	box-sizing: border-box;
	text-align: center;
}

#image-lightbox .lightbox-zoom-indicator button {
	width: 34px;
	height: 34px;
	min-width: 34px;
	min-height: 34px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	border-radius: 8px;
	border: 1px solid var(--border-color);
	background: var(--secondary-bg);
	color: var(--text-color);
	font-size: 1rem;
	cursor: pointer;
	box-shadow: 0 2px 6px rgba(0,0,0,0.06);
}

#image-lightbox .lightbox-zoom-indicator button:hover {
	background: var(--hover-bg);
}

@media (max-width: 760px) {
	#image-lightbox .lightbox-zoom-indicator {
		left: 8px;
		bottom: 104px;
		padding: 8px 10px;
		min-width: 92px;
	}
}

#image-lightbox .lightbox-filmstrip {
	position: fixed;
	left: 24px;
	bottom: 24px;
	display: flex;
	gap: 10px;
	padding: 10px 12px;
	background: rgba(0, 0, 0, 0.55);
	border-radius: 12px;
	box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
	max-width: min(520px, 45vw);
	overflow-x: auto;
	backdrop-filter: blur(6px);
}

#image-lightbox .filmstrip-thumb {
	border: 2px solid transparent;
	padding: 0;
	margin: 0;
	background: transparent;
	border-radius: 10px;
	width: 78px;
	height: 56px;
	min-width: 78px;
	min-height: 56px;
	overflow: hidden;
	cursor: pointer;
	transition: border 0.16s ease, transform 0.16s ease, box-shadow 0.16s ease;
}

#image-lightbox .filmstrip-thumb img {
	width: 100%;
	height: 100%;
	object-fit: cover;
	display: block;
}

#image-lightbox .filmstrip-thumb:hover {
	border-color: var(--hover-bg);
	transform: translateY(-2px);
	box-shadow: 0 6px 14px rgba(0,0,0,0.25);
}

#image-lightbox .filmstrip-thumb.active {
	border-color: var(--active-bg);
	box-shadow: 0 0 0 2px rgba(255,255,255,0.6), 0 8px 18px rgba(0,0,0,0.3);
}

@media (max-width: 760px) {
	#image-lightbox .lightbox-filmstrip {
		left: 8px;
		right: 8px;
		bottom: 8px;
		max-width: calc(100% - 16px);
		border-radius: 12px;
		padding: 10px 8px;
		gap: 8px;
		box-shadow: 0 -6px 20px rgba(0, 0, 0, 0.25);
		justify-content: flex-start;
	}
}

body.no-scroll-lightbox {
	overflow: hidden;
}
