/**
 * 知識庫文章圖片的放大檢視（lightbox）
 *
 * 對標巴哈姆特論壇（PhotoSwipe v4 預設介面），2026-09-24 實測它的弱點：
 * 換圖一格硬切、關閉一格消失、開啟只是整層淡入、沒有縮圖導覽。
 * 這裡的每一個轉場都是連續的，見 kb-lightbox.js 開頭的說明。
 */

/* ---------- 文章裡的圖：看得出能點 ---------- */

.tz-kb-content img.tzlb-zoomable {
	cursor: zoom-in;
	transition: box-shadow .2s ease, filter .2s ease;
}

.tz-kb-content img.tzlb-zoomable:hover {
	box-shadow: 0 0 0 1px var(--tz-kb-line, #e1e8ed), 0 6px 18px rgba(25, 42, 61, .12);
}

.tz-kb-content img.tzlb-zoomable:focus-visible {
	outline: 2px solid var(--tz-kb-focus, #1559ed);
	outline-offset: 3px;
}

/* 開著的時候頁面不捲；保留捲軸的位置，關掉時版面不會左右跳 */
html.tzlb-lock {
	overflow: hidden;
	scrollbar-gutter: stable;
}

/* ---------- 檢視層 ---------- */

.tzlb {
	--tzlb-bar: 56px;
	--tzlb-thumbs: 88px;
	--tzlb-ink: #f3f5f7;
	--tzlb-ink-2: rgba(243, 245, 247, .72);
	--tzlb-accent: #4d8bff;

	position: fixed;
	inset: 0;
	z-index: 100100;               /* 浮動按鈕是 99999 */
	color: var(--tzlb-ink);
	font: 14px/1.5 -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
	touch-action: none;
	-webkit-user-select: none;
	user-select: none;
	-webkit-tap-highlight-color: transparent;
	overscroll-behavior: contain;
}

.tzlb[hidden] {
	display: none;
}

.tzlb__bg {
	position: absolute;
	inset: 0;
	background: #0b0e12;
	opacity: 0;
	will-change: opacity;
}

.tzlb__stage {
	position: absolute;
	inset: 0;
	overflow: hidden;
}

.tzlb__track,
.tzlb__slide {
	position: absolute;
	inset: 0;
	will-change: transform;
}

.tzlb__img {
	position: absolute;
	left: 0;
	top: 0;
	max-width: none !important;
	max-height: none !important;
	transform-origin: 0 0;
	will-change: transform;
	-webkit-user-drag: none;
	user-select: none;
	image-rendering: auto;
	transition: opacity .18s ease;
	box-shadow: 0 10px 40px rgba(0, 0, 0, .35);
}

.tzlb__img.is-loading {
	opacity: 0;
}

.tzlb.is-zoomable .tzlb__img { cursor: zoom-in; }
.tzlb.is-zoomed .tzlb__img { cursor: grab; }
.tzlb.is-zoomed.is-panning .tzlb__img { cursor: grabbing; }

/* 載入超過 200ms 才出現，快的時候根本看不到它（不閃） */
.tzlb__spinner {
	position: absolute;
	left: 50%;
	top: 50%;
	width: 36px;
	height: 36px;
	margin: -18px 0 0 -18px;
	border: 3px solid rgba(255, 255, 255, .18);
	border-top-color: rgba(255, 255, 255, .85);
	border-radius: 50%;
	opacity: 0;
	transition: opacity .2s ease;
	animation: tzlb-spin .8s linear infinite;
	pointer-events: none;
}

.tzlb__slide.is-waiting .tzlb__spinner {
	opacity: 1;
	transition-delay: .2s;
}

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

/* ---------- 上方工具列 ---------- */

.tzlb__ui {
	opacity: 0;
	transition: opacity .2s ease;
}

.tzlb__bar {
	position: absolute;
	left: 0;
	right: 0;
	top: 0;
	height: var(--tzlb-bar);
	padding: 0 8px 0 18px;
	padding-top: env(safe-area-inset-top);
	display: flex;
	align-items: center;
	gap: 12px;
	background: linear-gradient(rgba(11, 14, 18, .75), rgba(11, 14, 18, 0));
}

.tzlb__counter {
	flex: none;
	font-variant-numeric: tabular-nums;
	letter-spacing: .04em;
	color: var(--tzlb-ink-2);
}

.tzlb__counter b {
	color: var(--tzlb-ink);
	font-weight: 600;
}

.tzlb__caption {
	flex: 1 1 auto;
	min-width: 0;
	overflow: hidden;
	white-space: nowrap;
	text-overflow: ellipsis;
	color: var(--tzlb-ink-2);
}

.tzlb__tools {
	flex: none;
	margin-left: auto;
	display: flex;
	gap: 2px;
}

.tzlb__btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 44px;
	height: 44px;
	padding: 0;
	border: 0;
	border-radius: 8px;
	background: transparent;
	color: var(--tzlb-ink);
	cursor: pointer;
	text-decoration: none;
	transition: background-color .15s ease, opacity .15s ease;
}

.tzlb__btn:hover {
	background: rgba(255, 255, 255, .12);
}

.tzlb__btn:focus-visible,
.tzlb__thumb:focus-visible,
.tzlb__arrow:focus-visible {
	outline: 2px solid #fff;
	outline-offset: 2px;
}

.tzlb__btn[aria-pressed="true"] {
	background: rgba(255, 255, 255, .16);
}

.tzlb__btn svg,
.tzlb__arrow svg {
	width: 22px;
	height: 22px;
	fill: none;
	stroke: currentColor;
	stroke-width: 2;
	stroke-linecap: round;
	stroke-linejoin: round;
}

/* 縮放組：[−] 百分比 [+] */
.tzlb__zoom {
	display: flex;
	align-items: center;
	margin: 0 6px;
	border-radius: 10px;
	background: rgba(255, 255, 255, .08);
}

.tzlb__pct {
	min-width: 58px;
	height: 44px;
	padding: 0 4px;
	border: 0;
	border-radius: 8px;
	background: transparent;
	color: var(--tzlb-ink);
	font: inherit;
	font-variant-numeric: tabular-nums;
	cursor: pointer;
	transition: background-color .15s ease;
}

.tzlb__pct:hover:not([disabled]) { background: rgba(255, 255, 255, .12); }
.tzlb__pct[disabled] { cursor: default; color: var(--tzlb-ink-2); }
.tzlb__pct:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

.tzlb__btn[disabled] {
	opacity: .35;
	cursor: default;
	background: transparent;
}

/* ---------- 左右箭頭 ---------- */

.tzlb__arrow {
	position: absolute;
	top: 50%;
	width: 48px;
	height: 48px;
	margin-top: calc((var(--tzlb-bar) - var(--tzlb-thumbs-now, var(--tzlb-thumbs))) / 2 - 24px);
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: rgba(20, 24, 30, .55);
	color: #fff;
	cursor: pointer;
	backdrop-filter: blur(6px);
	-webkit-backdrop-filter: blur(6px);
	transition: background-color .15s ease, opacity .2s ease, transform .15s ease;
}

.tzlb__arrow:hover { background: rgba(20, 24, 30, .85); }
.tzlb__arrow:active { transform: scale(.94); }
.tzlb__arrow--prev { left: 14px; }
.tzlb__arrow--next { right: 14px; }

.tzlb__arrow[disabled] {
	opacity: 0;
	pointer-events: none;
}

/* ---------- 縮圖導覽 ---------- */

.tzlb__thumbs {
	position: absolute;
	left: 0;
	right: 0;
	bottom: 0;
	height: var(--tzlb-thumbs);
	padding-bottom: env(safe-area-inset-bottom);
	background: linear-gradient(rgba(11, 14, 18, 0), rgba(11, 14, 18, .8) 40%);
	transition: transform .25s cubic-bezier(.22, .8, .26, 1), opacity .2s ease;
}

.tzlb.is-thumbs-off .tzlb__thumbs {
	transform: translateY(100%);
	opacity: 0;
	pointer-events: none;
}

.tzlb__strip {
	height: 100%;
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 12px max(16px, calc(50% - 32px)) 14px;   /* 左右留半個畫面，頭尾的縮圖也能置中 */
	overflow-x: auto;
	overflow-y: hidden;
	scrollbar-width: none;
	touch-action: pan-x;
	overscroll-behavior-x: contain;
}

.tzlb__strip::-webkit-scrollbar { display: none; }

.tzlb__thumb {
	position: relative;
	flex: none;
	width: 64px;
	height: 48px;
	padding: 0;
	border: 0;
	border-radius: 6px;
	overflow: hidden;
	background: #1d232b;
	cursor: pointer;
	opacity: .45;
	transform: scale(.92);
	transition: opacity .2s ease, transform .25s cubic-bezier(.22, .8, .26, 1);
}

.tzlb__thumb::after {
	content: "";
	position: absolute;
	inset: 0;
	border-radius: inherit;
	box-shadow: inset 0 0 0 2px transparent;
	transition: box-shadow .2s ease;
}

.tzlb__thumb:hover { opacity: .8; }

.tzlb__thumb.is-current {
	opacity: 1;
	transform: scale(1);
}

.tzlb__thumb.is-current::after {
	box-shadow: inset 0 0 0 2px #fff;
}

.tzlb__thumb img {
	width: 100%;
	height: 100%;
	object-fit: contain;           /* 知識庫多是截圖，裁切後認不出是哪張；整張縮小才看得出版面 */
	display: block;
	pointer-events: none;
}

/* 只有一張圖：沒有縮圖、沒有箭頭 */
.tzlb.is-single .tzlb__thumbs,
.tzlb.is-single .tzlb__arrow,
.tzlb.is-single [data-tzlb="thumbs"] {
	display: none;
}

/* ---------- 手機 ---------- */

@media (max-width: 767px) {
	.tzlb {
		--tzlb-bar: 52px;
		--tzlb-thumbs: 72px;
	}
	.tzlb__caption { display: none; }
	.tzlb__arrow { display: none; }
	.tzlb__thumb { width: 52px; height: 40px; }
	.tzlb [data-tzlb="fs"] { display: none; }
	/* 手機用捏合縮放；−／＋ 收掉，只留百分比（點一下回到符合視窗），360 寬才放得下 */
	.tzlb [data-tzlb="zoomin"],
	.tzlb [data-tzlb="zoomout"] { display: none; }
	.tzlb__bar { padding-left: 14px; gap: 8px; }
	.tzlb__zoom { margin: 0 2px; }
}

@media (hover: none) {
	.tzlb__arrow { display: none; }
	.tzlb__btn:hover { background: transparent; }
}

@media (prefers-reduced-motion: reduce) {
	.tzlb__thumbs,
	.tzlb__thumb,
	.tzlb__ui { transition: none; }
}

.tzlb.is-single .tzlb__counter {
	visibility: hidden;
}
