/**
 * Framed certificate ("Photo View") for the Certificates page viewer.
 *
 * Loaded only on the Certificates Page template. Every selector is prefixed with
 * `ks-certframe` (or scoped under `.certificate-viewer.is-photo-view`) so the
 * plain full-size viewer keeps its existing appearance untouched.
 *
 * Two frame variants are supported:
 *   .ks-certframe--image  A frame PNG with a transparent centre, chosen in the
 *                         Customizer. The image sits above the certificate and
 *                         defines the box; the certificate is inset inside it.
 *   .ks-certframe--css    Fallback ornate gold frame drawn entirely in CSS, used
 *                         when no frame image has been selected yet.
 */

/*--------------------------------------------------------------
# Shared wrapper — inert until Photo View is switched on
--------------------------------------------------------------*/
.ks-certframe {
	display: contents;
}

.ks-certframe__opening {
	display: contents;
}

.ks-certframe__overlay {
	display: none;
}

/*--------------------------------------------------------------
# Grid tiles — the same frame, always on
--------------------------------------------------------------*/

/*
 * Framed tiles drop the plain white card chrome (that lives on
 * .certificate-tile__frame in style.css) so the gold moulding reads as the card
 * itself. The lift on hover still comes from the existing tile rules.
 */
.certificate-tile__frame--framed {
	padding: 0;
	border: 0;
	border-radius: 0;
	background: transparent;
	box-shadow: none;
	filter: drop-shadow(0 10px 20px rgba(16, 35, 63, 0.22));
}

.certificate-tile:hover .certificate-tile__frame--framed,
.certificate-tile:focus-visible .certificate-tile__frame--framed {
	border-color: transparent;
	box-shadow: none;
	filter: drop-shadow(0 18px 30px rgba(16, 35, 63, 0.32));
}

/* Tint only the opening on hover, so the moulding is never greyed out. */
.certificate-tile__frame--framed .certificate-tile__zoom {
	z-index: 3;
	inset: var(--ks-certframe-inset-y, 9%) var(--ks-certframe-inset-x, 12%);
}

.ks-certframe--tile {
	display: block;
	position: relative;
	width: 100%;
}

.ks-certframe--tile.ks-certframe--image .ks-certframe__overlay {
	display: block;
	position: relative;
	z-index: 2;
	width: 100%;
	height: auto;
	pointer-events: none;
	-webkit-user-select: none;
	user-select: none;
}

.ks-certframe--tile.ks-certframe--image .ks-certframe__opening {
	display: flex;
	position: absolute;
	z-index: 1;
	top: var(--ks-certframe-inset-y, 9%);
	right: var(--ks-certframe-inset-x, 12%);
	bottom: var(--ks-certframe-inset-y, 9%);
	left: var(--ks-certframe-inset-x, 12%);
	align-items: center;
	justify-content: center;
	overflow: hidden;
	background: #fff;
}

/* Overrides the fixed pixel height the unframed tile image uses. */
.ks-certframe--tile.ks-certframe--image .certificate-tile__image {
	width: 100%;
	height: 100%;
	object-fit: contain;
}

/*--------------------------------------------------------------
# Photo View: stage becomes a clean, photographic backdrop
--------------------------------------------------------------*/
.certificate-viewer.is-photo-view .certificate-viewer__stage {
	padding: 0;
	border-radius: 0;
	background: transparent;
}

.certificate-viewer.is-photo-view .ks-certframe {
	display: block;
	position: relative;
	width: -moz-fit-content;
	width: fit-content;
	max-width: 100%;
	margin: 0 auto;
	animation: ks-certframe-in 320ms cubic-bezier(0.2, 0.8, 0.3, 1) both;
}

@keyframes ks-certframe-in {
	from {
		opacity: 0;
		transform: scale(0.965) translateY(6px);
	}

	to {
		opacity: 1;
		transform: none;
	}
}

@media (prefers-reduced-motion: reduce) {
	.certificate-viewer.is-photo-view .ks-certframe {
		animation: none;
	}
}

/*--------------------------------------------------------------
# Variant 1: frame image layered above the certificate
--------------------------------------------------------------*/
.certificate-viewer.is-photo-view .ks-certframe--image {
	filter: drop-shadow(0 18px 34px rgba(0, 0, 0, 0.45)) drop-shadow(0 3px 8px rgba(0, 0, 0, 0.3));
}

.certificate-viewer.is-photo-view .ks-certframe--image .ks-certframe__overlay {
	display: block;
	position: relative;
	z-index: 2;
	width: auto;
	height: auto;
	max-width: 100%;
	max-height: min(76vh, 880px);
	pointer-events: none;
	-webkit-user-select: none;
	user-select: none;
}

.certificate-viewer.is-photo-view .ks-certframe--image .ks-certframe__opening {
	display: flex;
	position: absolute;
	z-index: 1;
	top: var(--ks-certframe-inset-y, 12%);
	right: var(--ks-certframe-inset-x, 12%);
	bottom: var(--ks-certframe-inset-y, 12%);
	left: var(--ks-certframe-inset-x, 12%);
	align-items: center;
	justify-content: center;
	overflow: hidden;
	background: #fff;
}

.certificate-viewer.is-photo-view .ks-certframe--image .certificate-viewer__image {
	width: 100%;
	height: 100%;
	max-width: 100%;
	max-height: 100%;
	object-fit: contain;
}

/*--------------------------------------------------------------
# Variant 2: CSS-drawn ornate gold frame (fallback)
--------------------------------------------------------------*/
.certificate-viewer.is-photo-view .ks-certframe--css {
	padding: clamp(16px, 4.4vw, 42px);
	border-radius: 5px;
	background:
		linear-gradient(
			135deg,
			#8a6a1f 0%,
			#e6ca79 14%,
			#fbf1c4 28%,
			#d3ab48 42%,
			#8d6b21 56%,
			#e2c471 72%,
			#f7e9b6 84%,
			#a9852b 100%
		);
	box-shadow:
		inset 0 0 0 1px rgba(255, 245, 205, 0.75),
		inset 0 0 0 6px rgba(122, 92, 24, 0.55),
		inset 0 0 0 7px rgba(255, 240, 190, 0.5),
		0 18px 34px rgba(0, 0, 0, 0.45),
		0 3px 8px rgba(0, 0, 0, 0.3);
}

/* Inner bead line, just outside the mat. */
.certificate-viewer.is-photo-view .ks-certframe--css::after {
	content: "";
	position: absolute;
	inset: clamp(9px, 2.6vw, 26px);
	border: 2px solid rgba(120, 90, 22, 0.7);
	border-radius: 3px;
	box-shadow: inset 0 0 0 1px rgba(255, 243, 200, 0.6);
	pointer-events: none;
}

.certificate-viewer.is-photo-view .ks-certframe--css .ks-certframe__opening {
	display: flex;
	position: relative;
	z-index: 1;
	align-items: center;
	justify-content: center;
	padding: clamp(8px, 2.2vw, 20px);
	background: #fdfcf7;
	box-shadow:
		inset 0 0 0 1px rgba(154, 122, 44, 0.35),
		0 2px 10px rgba(0, 0, 0, 0.28);
}

.certificate-viewer.is-photo-view .ks-certframe--css .certificate-viewer__image {
	display: block;
	width: auto;
	height: auto;
	max-width: 100%;
	max-height: min(68vh, 800px);
	object-fit: contain;
}

/*--------------------------------------------------------------
# Viewer action bar (Photo View / Download / Print / Share)
--------------------------------------------------------------*/
.ks-certframe-actions {
	display: flex;
	flex-wrap: wrap;
	gap: 0.5rem;
	align-items: center;
	justify-content: center;
	margin: 0.85rem 0 0;
}

.ks-certframe-btn {
	display: inline-flex;
	align-items: center;
	gap: 0.45rem;
	padding: 0.5rem 0.95rem;
	border: 1px solid rgba(255, 255, 255, 0.3);
	border-radius: 999px;
	background: rgba(255, 255, 255, 0.1);
	color: #fff;
	font-family: inherit;
	font-size: 0.85rem;
	font-weight: 600;
	line-height: 1.2;
	text-decoration: none;
	cursor: pointer;
	transition: background 150ms ease, border-color 150ms ease, color 150ms ease;
}

.ks-certframe-btn:hover,
.ks-certframe-btn:focus-visible {
	border-color: #ff6214;
	background: #ff6214;
	color: #fff;
}

.ks-certframe-btn[aria-pressed="true"] {
	border-color: #e8cd7e;
	background: #e8cd7e;
	color: #10233f;
}

.ks-certframe-btn__icon {
	font-size: 0.9em;
}

.ks-certframe-feedback {
	flex: 0 0 100%;
	margin: 0;
	color: rgba(255, 255, 255, 0.8);
	font-size: 0.8rem;
	font-weight: 600;
	text-align: center;
}

.ks-certframe-feedback:empty {
	display: none;
}

/*--------------------------------------------------------------
# Responsive
--------------------------------------------------------------*/
@media screen and (max-width: 46.875em) {
	/*
	 * The wrapper must keep hugging the frame image at every width: the opening is
	 * positioned in percentages of the wrapper, so a wrapper wider than the artwork
	 * would push the certificate out of the frame's window. Never give either the
	 * wrapper or the overlay an explicit width here — `max-height` alone keeps the
	 * portrait aspect ratio intact.
	 */
	.certificate-viewer.is-photo-view .ks-certframe--image .ks-certframe__overlay {
		max-height: min(64vh, 720px);
	}

	.certificate-viewer.is-photo-view .ks-certframe--css .certificate-viewer__image {
		max-height: min(58vh, 640px);
	}

	.ks-certframe-btn {
		padding: 0.45rem 0.75rem;
		font-size: 0.78rem;
	}
}

@media screen and (max-width: 30em) {
	.certificate-viewer.is-photo-view .ks-certframe--image .ks-certframe__overlay {
		max-height: min(60vh, 620px);
	}

	.ks-certframe-btn {
		padding: 0.45rem 0.7rem;
		font-size: 0.74rem;
	}
}

/*--------------------------------------------------------------
# Print layer — prints the certificate only, never the chrome
--------------------------------------------------------------*/
.ks-certframe-print {
	display: none;
}

@media print {
	body.ks-certframe-printing > *:not(.ks-certframe-print) {
		display: none !important;
	}

	body.ks-certframe-printing .ks-certframe-print {
		display: block !important;
		margin: 0;
		padding: 0;
		text-align: center;
	}

	body.ks-certframe-printing .ks-certframe-print__image {
		display: block;
		width: auto;
		max-width: 100%;
		max-height: 100vh;
		margin: 0 auto;
	}

	body.ks-certframe-printing {
		overflow: visible !important;
		background: #fff !important;
	}
}
