/* DengeCudi image viewer: in-page gallery + full-screen lightbox */

/* ---------- in-page gallery ---------- */

body .king-gallery.kn-gal {
	--kn-gal-h: min(74vh, 680px);
	--kn-gal-bg: var(--kp-soft, #f2f3f6);
	position: relative;
	display: block !important;
	padding: 0 !important;
	min-height: 0 !important;
	overflow: hidden;
	background: var(--kn-gal-bg);
	outline: none;
}
html.king-night body .king-gallery.kn-gal { --kn-gal-bg: #15151b; }
body .king-gallery.kn-gal:focus-visible { box-shadow: inset 0 0 0 3px rgba(230, 0, 35, .55); }

body .king-gallery.kn-gal a { cursor: zoom-in; -webkit-tap-highlight-color: transparent; }

/* single image */
body .king-gallery.kn-gal-one {
	display: flex !important;
	align-items: center;
	justify-content: center;
}
body .king-gallery.kn-gal-one > a,
body .king-gallery.kn-gal-one .king-gallery-track > a {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 100%;
}
body .king-gallery.kn-gal-one .gallery-img {
	display: block;
	width: auto !important;
	max-width: 100% !important;
	height: auto !important;
	max-height: var(--kn-gal-h) !important;
	margin: 0 auto;
	object-fit: contain;
	border-radius: 0 !important;
}

/* many images: one slide per view, fixed stage height so nothing jumps */
body .king-gallery.kn-gal-many .king-gallery-track {
	position: relative;
	display: flex !important;
	gap: 0 !important;
	padding: 0 !important;
	margin: 0 !important;
	overflow-x: auto;
	overflow-y: hidden;
	scroll-snap-type: x mandatory;
	scroll-behavior: smooth;
	overscroll-behavior-x: contain;
	scrollbar-width: none;
	-webkit-overflow-scrolling: touch;
}
body .king-gallery.kn-gal-many .king-gallery-track::-webkit-scrollbar { display: none; }
body .king-gallery.kn-gal-many.is-dragging .king-gallery-track { scroll-snap-type: none; scroll-behavior: auto; cursor: grabbing; }
body .king-gallery.kn-gal-many.is-dragging a { cursor: grabbing; }
body .king-gallery.kn-gal-many .king-gallery-track > a {
	flex: 0 0 100% !important;
	width: 100% !important;
	height: var(--kn-gal-h);
	display: flex !important;
	align-items: center;
	justify-content: center;
	scroll-snap-align: center;
	scroll-snap-stop: always;
	border-radius: 0 !important;
	background: transparent !important;
	box-sizing: border-box;
	user-select: none;
}
body .king-gallery.kn-gal-many .gallery-img {
	display: block;
	width: auto !important;
	height: auto !important;
	max-width: 100% !important;
	max-height: 100% !important;
	margin: 0 auto;
	object-fit: contain;
	border-radius: 0 !important;
	-webkit-user-drag: none;
}

/* controls over the stage */
.kn-gal-count {
	position: absolute;
	top: 12px;
	left: 12px;
	z-index: 3;
	padding: 5px 10px;
	border-radius: 999px;
	background: rgba(12, 12, 16, .6);
	color: #fff;
	font-size: 12.5px;
	font-weight: 700;
	line-height: 1;
	letter-spacing: .02em;
	font-variant-numeric: tabular-nums;
	backdrop-filter: blur(6px);
	-webkit-backdrop-filter: blur(6px);
	pointer-events: none;
}
.kn-gal-nav {
	position: absolute;
	top: calc(var(--kn-gal-h) / 2);
	z-index: 3;
	width: 42px;
	height: 42px;
	margin-top: -21px;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: rgba(255, 255, 255, .94);
	color: #111;
	box-shadow: 0 4px 16px rgba(0, 0, 0, .22);
	cursor: pointer;
	opacity: 0;
	transition: opacity .18s ease, transform .18s ease;
}
.kn-gal-prev { left: 12px; }
.kn-gal-next { right: 12px; }
.kn-gal:hover .kn-gal-nav,
.kn-gal:focus-within .kn-gal-nav { opacity: 1; }
.kn-gal-nav:hover { transform: scale(1.06); }
.kn-gal .kn-gal-nav:disabled { opacity: 0 !important; pointer-events: none; }

.kn-gal-expand {
	position: absolute;
	right: 12px;
	bottom: 12px;
	z-index: 3;
	width: 38px;
	height: 38px;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: rgba(12, 12, 16, .6);
	color: #fff;
	cursor: pointer;
	opacity: .85;
	backdrop-filter: blur(6px);
	-webkit-backdrop-filter: blur(6px);
	transition: opacity .15s ease, background .15s ease;
}
.kn-gal-expand:hover { opacity: 1; background: rgba(12, 12, 16, .82); }
.kn-gal-many .kn-gal-expand { bottom: auto; top: calc(var(--kn-gal-h) - 50px); }

.kn-gal-thumbs {
	display: flex;
	gap: 8px;
	padding: 10px 12px;
	overflow-x: auto;
	scrollbar-width: none;
	background: var(--kp-surface, #fff);
	border-top: 1px solid var(--kp-line, rgba(0, 0, 0, .08));
}
html.king-night .kn-gal-thumbs { background: #1c1c23; border-top-color: rgba(255, 255, 255, .08); }
.kn-gal-thumbs::-webkit-scrollbar { display: none; }
.kn-gal-thumbs:has(.kn-gal-thumb:nth-child(-n+8):last-child) { justify-content: center; }
.kn-gal-thumb {
	flex: 0 0 auto;
	width: 58px;
	height: 58px;
	padding: 0;
	border: 0;
	border-radius: 10px;
	overflow: hidden;
	background: var(--kn-gal-bg, #eee);
	cursor: pointer;
	opacity: .55;
	box-shadow: 0 0 0 2px transparent;
	transition: opacity .15s ease, box-shadow .15s ease;
}
.kn-gal-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.kn-gal-thumb:hover { opacity: .85; }
.kn-gal-thumb.is-active { opacity: 1; box-shadow: 0 0 0 2px var(--kp-surface, #fff), 0 0 0 4px #e60023; }

@media (hover: none) {
	.kn-gal-nav { display: none; }
}
@media (max-width: 767px) {
	body .king-gallery.kn-gal { --kn-gal-h: min(66vh, 520px); }
	.kn-gal-thumb { width: 48px; height: 48px; border-radius: 8px; }
	.kn-gal-thumbs { padding: 8px 10px; gap: 6px; }
	.kn-gal-count { top: 10px; left: 10px; }
	.kn-gal-expand { width: 34px; height: 34px; right: 10px; bottom: 10px; }
	.kn-gal-many .kn-gal-expand { top: calc(var(--kn-gal-h) - 44px); }
}

/* ---------- lightbox ---------- */

html.kn-lb-lock,
html.kn-lb-lock body { overflow: hidden !important; }

.kn-lb {
	--kn-lb-fade: 1;
	position: fixed;
	inset: 0;
	z-index: 2147483000;
	display: flex;
	flex-direction: column;
	background: rgba(8, 8, 11, calc(.95 * var(--kn-lb-fade)));
	backdrop-filter: blur(10px);
	-webkit-backdrop-filter: blur(10px);
	color: #fff;
	opacity: 0;
	transition: opacity .2s ease;
	-webkit-tap-highlight-color: transparent;
	user-select: none;
	-webkit-user-select: none;
	font-family: inherit;
	outline: none;
}
.kn-lb[hidden] { display: none !important; }
.kn-lb.is-open { opacity: 1; }

.kn-lb-top {
	flex: none;
	display: flex;
	align-items: center;
	justify-content: space-between;
	height: 56px;
	padding: 0 8px 0 18px;
	padding-top: env(safe-area-inset-top);
	position: relative;
	z-index: 3;
	transition: opacity .2s ease;
}
.kn-lb-count { font-size: 14px; font-weight: 700; opacity: .85; font-variant-numeric: tabular-nums; letter-spacing: .02em; }
.kn-lb-actions { display: flex; align-items: center; gap: 2px; }
.kn-lb-btn {
	width: 44px;
	height: 44px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: transparent;
	color: #fff !important;
	opacity: .82;
	cursor: pointer;
	text-decoration: none !important;
	transition: background .15s ease, opacity .15s ease;
}
.kn-lb-btn:hover,
.kn-lb-btn:focus-visible { background: rgba(255, 255, 255, .13); opacity: 1; outline: none; }

.kn-lb-stage {
	position: relative;
	flex: 1 1 auto;
	min-height: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	overflow: hidden;
	touch-action: none;
}
.kn-lb-img {
	display: block;
	max-width: calc(100% - 24px);
	max-height: calc(100% - 12px);
	width: auto;
	height: auto;
	object-fit: contain;
	opacity: 0;
	translate: 0 0;
	transition: opacity .2s ease, translate .25s cubic-bezier(.2, .8, .2, 1);
	will-change: transform;
	cursor: zoom-in;
	-webkit-user-drag: none;
	box-shadow: 0 10px 40px rgba(0, 0, 0, .35);
}
.kn-lb-img.from-right { translate: 28px 0; }
.kn-lb-img.from-left { translate: -28px 0; }
.kn-lb-img.is-in { opacity: 1; translate: 0 0; }
.kn-lb.is-loading .kn-lb-img:not([src]) { opacity: 0; }
.kn-lb.is-zoomed .kn-lb-img { cursor: grab; box-shadow: none; }
.kn-lb.is-zoomed .kn-lb-img:active { cursor: grabbing; }

.kn-lb-spin {
	position: absolute;
	left: 50%;
	top: 50%;
	width: 34px;
	height: 34px;
	margin: -17px 0 0 -17px;
	border-radius: 50%;
	border: 3px solid rgba(255, 255, 255, .2);
	border-top-color: #fff;
	opacity: 0;
	pointer-events: none;
	transition: opacity .15s ease .25s;
	animation: kn-lb-spin .8s linear infinite;
}
.kn-lb.is-loading .kn-lb-spin { opacity: 1; }
@keyframes kn-lb-spin { to { transform: rotate(360deg); } }

.kn-lb-nav {
	position: absolute;
	top: 50%;
	z-index: 2;
	width: 50px;
	height: 50px;
	margin-top: -25px;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: rgba(255, 255, 255, .1);
	color: #fff;
	cursor: pointer;
	transition: background .15s ease, opacity .2s ease;
}
.kn-lb-nav:hover,
.kn-lb-nav:focus-visible { background: rgba(255, 255, 255, .22); outline: none; }
.kn-lb-prev { left: 16px; }
.kn-lb-next { right: 16px; }
.kn-lb.is-single .kn-lb-nav,
.kn-lb.is-zoomed .kn-lb-nav { opacity: 0; pointer-events: none; }

.kn-lb-caption {
	flex: none;
	max-width: 760px;
	margin: 0 auto;
	padding: 10px 20px 4px;
	font-size: 14px;
	line-height: 1.45;
	text-align: center;
	opacity: .8;
	display: -webkit-box;
	-webkit-line-clamp: 2;
	-webkit-box-orient: vertical;
	overflow: hidden;
	transition: opacity .2s ease;
}
.kn-lb-caption[hidden] { display: none; }

.kn-lb-thumbs {
	flex: none;
	display: flex;
	gap: 8px;
	padding: 10px 14px calc(12px + env(safe-area-inset-bottom));
	overflow-x: auto;
	scrollbar-width: none;
	transition: opacity .2s ease;
}
.kn-lb-thumbs::-webkit-scrollbar { display: none; }
.kn-lb-thumbs[hidden] { display: none; }
.kn-lb-thumbs::before,
.kn-lb-thumbs::after { content: ""; margin: auto; }
.kn-lb-thumb {
	flex: 0 0 auto;
	width: 56px;
	height: 56px;
	padding: 0;
	border: 0;
	border-radius: 8px;
	overflow: hidden;
	background: #222;
	opacity: .45;
	cursor: pointer;
	box-shadow: 0 0 0 2px transparent;
	transition: opacity .15s ease, box-shadow .15s ease;
}
.kn-lb-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }
.kn-lb-thumb:hover { opacity: .8; }
.kn-lb-thumb.is-active { opacity: 1; box-shadow: 0 0 0 2px #fff; }

.kn-lb.is-chrome-hidden .kn-lb-top,
.kn-lb.is-chrome-hidden .kn-lb-caption,
.kn-lb.is-chrome-hidden .kn-lb-thumbs,
.kn-lb.is-chrome-hidden .kn-lb-nav { opacity: 0; pointer-events: none; }

@media (hover: none) {
	.kn-lb-nav { display: none; }
}
@media (max-width: 767px) {
	.kn-lb-top { height: 52px; padding-left: 14px; }
	.kn-lb-img { max-width: 100%; max-height: 100%; box-shadow: none; }
	.kn-lb-thumb { width: 46px; height: 46px; }
	.kn-lb-caption { font-size: 13px; padding: 8px 16px 2px; }
}
@media (prefers-reduced-motion: reduce) {
	.kn-lb, .kn-lb-img, .kn-gal-many .king-gallery-track { transition: none !important; scroll-behavior: auto !important; }
}
