/**
 * KM Scroll 3D — style frontendu.
 *
 * Wszystko prefiksowane .km-s3d, zero resetów globalnych.
 */

.km-s3d {
	--km-s3d-accent: #1e88e5;
	--km-s3d-track: 300vh;
	--km-s3d-stage: 100vh;
	--km-s3d-bg: transparent;
	--km-s3d-maxw: none;
	position: relative;
	width: 100%;
}

.km-s3d__track {
	position: relative;
	height: var(--km-s3d-track);
}

/* Mobile: 1vh "skacze" razem z paskiem adresu przeglądarki — svh jest stały
   przez cały scroll, więc ani wysokość toru, ani kadru nie zmienia się w
   trakcie animacji (skoki postępu i "podcięty" kadr znikają). */
@supports (height: 1svh) {
	.km-s3d__track {
		height: calc(var(--km-s3d-track-n, 300) * 1svh);
	}
	.km-s3d--pinned .km-s3d__stage,
	.km-s3d:not(.km-s3d--pinned) .km-s3d__stage {
		height: calc(var(--km-s3d-stage-n, 100) * 1svh);
	}
}

.km-s3d--pinned .km-s3d__stage {
	position: -webkit-sticky;
	position: sticky;
	top: var(--km-s3d-top, 0px);
	height: var(--km-s3d-stage);
	overflow: hidden;
}

/* Pinning awaryjny (JS) — gdy sticky łamie overflow przodka lub smooth-scroll motywu. */
.km-s3d--pinned.km-s3d--jspin .km-s3d__stage {
	position: absolute;
	top: 0;
	left: 0;
	right: 0;
	will-change: transform;
}

.km-s3d:not(.km-s3d--pinned) .km-s3d__track {
	height: auto;
}

.km-s3d:not(.km-s3d--pinned) .km-s3d__stage {
	position: relative;
	height: var(--km-s3d-stage);
}

.km-s3d__viewport {
	position: relative;
	width: 100%;
	max-width: var(--km-s3d-maxw);
	height: 100%;
	margin: 0 auto;
	background: var(--km-s3d-bg);
	overflow: hidden;
	isolation: isolate;
}

.km-s3d__canvas {
	display: block;
	width: 100%;
	height: 100%;
	touch-action: pan-y;
}

/* -------------------------------------------------------------- wideo */

.km-s3d__video {
	display: block;
	width: 100%;
	height: 100%;
	pointer-events: none;
}

.km-s3d__video--cover { object-fit: cover; }
.km-s3d__video--contain { object-fit: contain; }

/* ------------------------------------------------------------ nakładka */

.km-s3d__overlay {
	position: absolute;
	inset: 0;
	z-index: 3;
	pointer-events: none;
	background: var(--km-s3d-ov, #000);
	opacity: var(--km-s3d-ov-op, .35);
}

.km-s3d__overlay--bottom {
	background: linear-gradient(to top, var(--km-s3d-ov, #000) 0%, transparent 62%);
}

.km-s3d__overlay--top {
	background: linear-gradient(to bottom, var(--km-s3d-ov, #000) 0%, transparent 62%);
}

.km-s3d__overlay--left {
	background: linear-gradient(to right, var(--km-s3d-ov, #000) 0%, transparent 66%);
}

/* --------------------------------------------------------------- tytuł */

.km-s3d__title {
	position: absolute;
	inset: 0;
	z-index: 4;
	display: grid;
	padding: clamp(22px, 6vw, 80px);
	box-sizing: border-box;
	pointer-events: none;
	color: var(--km-s3d-title, #fff);
	will-change: opacity, transform;
}

.km-s3d__title--top-left { align-content: start; justify-items: start; text-align: left; }
.km-s3d__title--top-center { align-content: start; justify-items: center; text-align: center; }
.km-s3d__title--center-center { align-content: center; justify-items: center; text-align: center; }
.km-s3d__title--bottom-left { align-content: end; justify-items: start; text-align: left; }
.km-s3d__title--bottom-center { align-content: end; justify-items: center; text-align: center; }

.km-s3d__title-main {
	margin: 0;
	font-size: clamp(2rem, 6vw, 4.4rem);
	font-weight: 700;
	line-height: 1.04;
	letter-spacing: -.02em;
	text-shadow: 0 2px 26px rgba(0, 0, 0, .45);
	text-wrap: balance;
}

.km-s3d__title-sub {
	margin: .55em 0 0;
	max-width: 52ch;
	font-size: clamp(1rem, 2.1vw, 1.3rem);
	line-height: 1.5;
	opacity: .88;
	text-shadow: 0 1px 16px rgba(0, 0, 0, .45);
}

/* ------------------------------------------------------------- poster */

.km-s3d__poster {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	object-fit: contain;
	opacity: 0;
	transition: opacity .4s ease;
	pointer-events: none;
	z-index: 2;
}

.km-s3d__poster.is-visible,
.km-s3d:not(.is-ready) .km-s3d__poster,
.km-s3d.is-static .km-s3d__poster {
	opacity: 1;
}

.km-s3d.is-static.is-ready:not(.has-error) .km-s3d__canvas {
	opacity: 1;
}

/* ------------------------------------------------------------- loader */

.km-s3d__loader {
	position: absolute;
	inset: 0;
	z-index: 5;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 12px;
	font: 500 14px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
	color: currentColor;
	opacity: .85;
	transition: opacity .35s ease, visibility .35s ease;
}

.km-s3d__loader.is-hidden {
	opacity: 0;
	visibility: hidden;
}

.km-s3d__loader.is-error .km-s3d__spinner {
	display: none;
}

.km-s3d__spinner {
	width: 34px;
	height: 34px;
	border-radius: 50%;
	border: 3px solid color-mix(in srgb, var(--km-s3d-accent) 25%, transparent);
	border-top-color: var(--km-s3d-accent);
	animation: km-s3d-spin .9s linear infinite;
}

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

.km-s3d__loader-bar {
	display: block;
	width: min(220px, 50%);
	height: 3px;
	border-radius: 3px;
	background: color-mix(in srgb, currentColor 15%, transparent);
	overflow: hidden;
}

.km-s3d__loader-bar i {
	display: block;
	width: 100%;
	height: 100%;
	background: var(--km-s3d-accent);
	transform: scale3d(0, 1, 1);
	transform-origin: left center;
	transition: transform .2s linear;
}

/* -------------------------------------------------------------- kroki */

.km-s3d__steps {
	position: absolute;
	inset: 0;
	z-index: 4;
	display: grid;
	pointer-events: none;
	padding: clamp(20px, 5vw, 72px);
	box-sizing: border-box;
}

.km-s3d__step {
	grid-area: 1 / 1;
	max-width: 42ch;
	opacity: 0;
	will-change: opacity, transform;
	transition: opacity .12s linear;
}

.km-s3d__steps--center-left .km-s3d__step { align-self: center; justify-self: start; }
.km-s3d__steps--center-right .km-s3d__step { align-self: center; justify-self: end; text-align: right; }
.km-s3d__steps--center-center .km-s3d__step { align-self: center; justify-self: center; text-align: center; }
.km-s3d__steps--bottom-center .km-s3d__step { align-self: end; justify-self: center; text-align: center; }

.km-s3d__step--left { justify-self: start; text-align: left; }
.km-s3d__step--right { justify-self: end; text-align: right; }
.km-s3d__step--center { justify-self: center; text-align: center; }

.km-s3d__step-title {
	margin: 0 0 .4em;
	font-size: clamp(1.5rem, 3.4vw, 2.6rem);
	line-height: 1.1;
}

.km-s3d__step-body p:last-child {
	margin-bottom: 0;
}

/* ------------------------------------------------------ pasek postępu */

.km-s3d__progress {
	position: absolute;
	z-index: 6;
	background: color-mix(in srgb, currentColor 12%, transparent);
	overflow: hidden;
}

.km-s3d__progress i {
	display: block;
	width: 100%;
	height: 100%;
	background: var(--km-s3d-accent);
	transform-origin: left center;
	will-change: transform;
}

.km-s3d__progress--top,
.km-s3d__progress--bottom {
	left: 0;
	right: 0;
	height: 3px;
}

.km-s3d__progress--top { top: 0; }
.km-s3d__progress--bottom { bottom: 0; }

.km-s3d__progress--left {
	top: 12%;
	bottom: 12%;
	left: clamp(10px, 2vw, 26px);
	width: 3px;
	border-radius: 3px;
}

.km-s3d__progress--left i {
	transform-origin: center top;
}

/* ------------------------------------------------------------ wskaźnik */

.km-s3d__hint {
	position: absolute;
	left: 50%;
	bottom: clamp(14px, 3vh, 34px);
	transform: translateX(-50%);
	z-index: 6;
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 8px;
	font: 500 12px/1 system-ui, sans-serif;
	letter-spacing: .12em;
	text-transform: uppercase;
	opacity: .75;
	transition: opacity .5s ease, transform .5s ease;
	pointer-events: none;
}

.km-s3d__hint.is-hidden {
	opacity: 0;
	transform: translateX(-50%) translateY(10px);
}

.km-s3d__hint-mouse {
	position: relative;
	width: 20px;
	height: 32px;
	border: 2px solid currentColor;
	border-radius: 11px;
}

.km-s3d__hint-mouse i {
	position: absolute;
	left: 50%;
	top: 6px;
	width: 3px;
	height: 6px;
	margin-left: -1.5px;
	border-radius: 2px;
	background: var(--km-s3d-accent);
	animation: km-s3d-wheel 1.6s ease-in-out infinite;
}

@keyframes km-s3d-wheel {
	0%, 100% { transform: translateY(0); opacity: 1; }
	60% { transform: translateY(10px); opacity: .2; }
}

/* ---------------------------------------------------------- diagnostyka */

.km-s3d__debug {
	position: absolute;
	top: 8px;
	left: 8px;
	z-index: 9;
	padding: 6px 9px;
	border-radius: 5px;
	background: rgba(0, 0, 0, .72);
	color: #7ee787;
	font: 500 11px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
	pointer-events: none;
	white-space: nowrap;
}

/* ------------------------------------------------------------- warstwy */

.km-s3d__layers {
	position: absolute;
	inset: 0;
	perspective: 1200px;
	transform-style: preserve-3d;
}

.km-s3d__layer {
	position: absolute;
	inset: -10%;
	width: 120%;
	height: 120%;
	object-fit: cover;
	will-change: transform;
}

/* ------------------------------------------------------------ a11y/druk */

.km-s3d.has-error .km-s3d__canvas {
	opacity: .15;
}

/* Drobne dopasowania mobile */
@media (max-width: 782px) {
	.km-s3d__steps {
		padding: 18px;
		align-content: end;
	}

	.km-s3d__step {
		max-width: 100%;
	}

	.km-s3d__step-title {
		font-size: clamp(1.25rem, 6vw, 1.8rem);
	}

	.km-s3d__step-body {
		font-size: .95rem;
	}

	.km-s3d__progress--left {
		left: 8px;
		width: 2.5px;
	}

	.km-s3d__title {
		padding: 18px;
	}
}

@media print {
	.km-s3d__track { height: auto !important; }
	.km-s3d__stage { position: static !important; height: auto !important; }
	.km-s3d__canvas,
	.km-s3d__video,
	.km-s3d__overlay,
	.km-s3d__loader,
	.km-s3d__hint,
	.km-s3d__progress { display: none !important; }
	.km-s3d__poster { position: static; opacity: 1 !important; }
}
