/**
 * KKB Slideshow — front-end styles.
 *
 * State machine on the wrapper via `data-state`:
 *   - (no value) / "idle"  before JS upgrades, or while waiting to activate on touch
 *   - "pinned"             desktop, ScrollTrigger has the wrapper pinned
 *   - "fixed"              touch, position:fixed full-viewport
 *   - "linear"             user exited; slides flow vertically as normal blocks
 *
 * The wrapper is `[data-kkb-slideshow="1"]` (a core/group rendered with
 * the kkbSlideshow attribute). Direct children are wrapped in
 * `.kkb-slideshow__track` at JS mount time. Until JS runs, the group
 * renders as a normal Gutenberg group — this gives a graceful fallback
 * if the script fails to load.
 */

/* Lock the slideshow's mode-sensitive color tokens to dark / default
   values regardless of the page's `mode-light` / `mode-dark` /
   `mode-auto` class. Editors expect the colors they pick in
   Gutenberg (the editor canvas matches theme.json defaults — i.e.
   the dark palette) to stay put inside slideshows; the visitor's
   light/dark toggle is for the surrounding document, not for the
   slide content. Re-binding both `--kkb-doc-*` and the
   `--wp--preset--color--accent` palette presets covers both inherit-
   based color rules and Gutenberg `has-X-color` classes. */
[data-kkb-slideshow="1"] {
	--kkb-doc-bg:        #0A0A0B;
	--kkb-doc-bg-soft:   #111114;
	--kkb-doc-ink:       #F2F2EE;
	--kkb-doc-ink-dim:   rgba(242, 242, 238, 0.78);
	--kkb-doc-ink-faint: rgba(242, 242, 238, 0.32);
	--kkb-doc-hair:      rgba(242, 242, 238, 0.10);
	--kkb-doc-code-bg:   rgba(255, 255, 255, 0.05);
	--kkb-doc-pre-bg:    rgba(0, 0, 0, 0.3);
	--kkb-accent:        #4afaa8;
	--kkb-accent-deep:   #17c782;
	--wp--preset--color--accent:      #4afaa8;
	--wp--preset--color--accent-deep: #17c782;
	color-scheme: dark;
}

/* Default + idle: full-bleed (100vh − header) tall. The wrapper's
   width and horizontal position are set inline by JS after measuring
   `documentElement.clientWidth` and `getBoundingClientRect().left`,
   because CSS-only escapes (`calc(50% - 50vw)` etc) drift by a few
   pixels under Lenis transforms / has-global-padding / scroll gutter
   reservation. The CSS values below are pre-JS fallbacks. */
[data-kkb-slideshow="1"] {
	--slide-count: 1;
	--kkb-slideshow-vp-h: calc(100vh - var(--kkb-header-h, 0px));
	position: relative;
	width: 100vw;
	max-width: none !important;
	margin-left: calc(50% - 50vw);
	margin-right: calc(50% - 50vw);
	padding-left: 0 !important;
	padding-right: 0 !important;
	height: var(--kkb-slideshow-vp-h);
	overflow: hidden;
	background: var(--kkb-bg, #000);
	touch-action: pan-y;
	contain: layout paint;
}

/* The track is exactly viewport-sized (minus header); slides are
   absolutely positioned inside it at left:i*100vw via inline
   !important styles set in JS.

   !important is required because the wrapper carries Gutenberg's
   per-instance `wp-container-X-is-layout-constrained` class
   (any group block with constrained layout does), which generates
   a `> *` rule that clamps every direct child to the document
   content-size and applies margin-inline:auto + padding-inline. The
   track is a direct child, so without these escapes it gets clamped
   to ~768px wide and centered, which then offsets every slide that
   resolves its absolute `left` against the track's padding-box. */
[data-kkb-slideshow="1"] .kkb-slideshow__track {
	position: relative;
	width: 100vw !important;
	max-width: none !important;
	height: var(--kkb-slideshow-vp-h);
	margin-left: 0 !important;
	margin-right: 0 !important;
	padding-left: 0 !important;
	padding-right: 0 !important;
	transform: translate3d(0, 0, 0);
	will-change: transform;
	overflow: visible; /* slides at left:100vw, 200vw must not be clipped by the track itself — wrapper's overflow:hidden does the masking */
}

[data-kkb-slideshow="1"] .kkb-slideshow__slide {
	/* Slot dimensions/position are forced inline via JS with !important.
	   These declarations are just defaults / fallbacks. */
	overflow: hidden;
	isolation: isolate;
	contain: layout paint;
	z-index: 0;
}

/* ── Touch fixed mode ────────────────────────────────────────────── */
/* Pinned below the site header; not over it. */
[data-kkb-slideshow="1"][data-state="fixed"] {
	position: fixed;
	top: var(--kkb-header-h, 0px);
	left: 0;
	right: 0;
	bottom: 0;
	z-index: 80;
	width: 100vw;
	height: calc(100dvh - var(--kkb-header-h, 0px));
	margin: 0;
}

[data-kkb-slideshow="1"][data-state="fixed"] .kkb-slideshow__track,
[data-kkb-slideshow="1"][data-state="fixed"] .kkb-slideshow__slide {
	height: calc(100dvh - var(--kkb-header-h, 0px));
}

/* When the page is in "touch fixed" mode, freeze the document under it. */
html.kkb-slideshow-fixed-lock,
html.kkb-slideshow-fixed-lock body {
	overflow: hidden;
	overscroll-behavior: none;
	touch-action: none;
}

/* ── Linear (exited) state ───────────────────────────────────────── */
/* JS removes the !important inline absolute styles AND the wrapper's
   calibrated width/margin before this state activates, so plain CSS
   rules govern again. Slides keep their alignfull class and escape
   via the standard `.kkb-document__body .alignfull` rule the way
   they would outside the slideshow. The wrapper itself drops its
   fixed dimensions and flows naturally. */
[data-kkb-slideshow="1"][data-state="linear"] {
	position: relative;
	height: auto;
	overflow: visible;
	max-width: none !important;
	padding-left: 0 !important;
	padding-right: 0 !important;
}

[data-kkb-slideshow="1"][data-state="linear"] .kkb-slideshow__track {
	display: block;
	width: 100%;
	height: auto;
	transform: none !important;
}

/* Slides flow vertically. Don't override `display` — cover blocks use
   `display: flex` to implement Gutenberg's verticalAlignment setting,
   and forcing block here loses that vertical-center / vertical-bottom
   behavior so cover content collapses to the top. */
[data-kkb-slideshow="1"][data-state="linear"] .kkb-slideshow__slide {
	width: 100%;
	min-height: 100vh;
	min-height: 100dvh;
	height: auto;
}

/* ── Chrome (controls) ───────────────────────────────────────────── */
/* As with the track, the chrome is a direct child of the wrapper and
   would otherwise be clamped + centered by Gutenberg's
   constrained-layout `> *` rule. The !important escapes here keep the
   controls bar spanning the full viewport width. */
.kkb-slideshow__chrome {
	position: absolute;
	left: 0;
	right: 0;
	bottom: 1.5rem;
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 0.75rem;
	padding: 0 1.5rem;
	z-index: 10;
	pointer-events: none;
	max-width: none !important;
	margin-left: 0 !important;
	margin-right: 0 !important;
}

.kkb-slideshow__chrome > * {
	pointer-events: auto;
}

[data-kkb-slideshow="1"][data-state="fixed"] .kkb-slideshow__chrome {
	position: fixed;
}

[data-kkb-slideshow="1"][data-state="linear"] .kkb-slideshow__chrome {
	display: none;
}

.kkb-slideshow__nav,
.kkb-slideshow__exit,
.kkb-slideshow__dot {
	appearance: none;
	background: rgba(0, 0, 0, 0.55);
	color: #fff;
	border: 1px solid rgba(255, 255, 255, 0.18);
	font-family: inherit;
	cursor: pointer;
	transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
	backdrop-filter: blur(6px);
	-webkit-backdrop-filter: blur(6px);
}

.kkb-slideshow__nav {
	width: 2.75rem;
	height: 2.75rem;
	border-radius: 999px;
	font-size: 1.4rem;
	line-height: 1;
	display: inline-flex;
	align-items: center;
	justify-content: center;
}

.kkb-slideshow__nav:hover,
.kkb-slideshow__exit:hover,
.kkb-slideshow__dot:hover {
	background: rgba(0, 0, 0, 0.75);
	border-color: rgba(255, 255, 255, 0.35);
}

.kkb-slideshow__dots {
	display: inline-flex;
	gap: 0.5rem;
	align-items: center;
	padding: 0 0.5rem;
}

.kkb-slideshow__dot {
	width: 0.6rem;
	height: 0.6rem;
	padding: 0;
	border-radius: 999px;
	background: rgba(255, 255, 255, 0.35);
	border: 1px solid rgba(255, 255, 255, 0.15);
}

.kkb-slideshow__dot.is-current {
	background: #fff;
	transform: scale(1.25);
}

.kkb-slideshow__exit {
	font-size: 0.75rem;
	letter-spacing: 0.06em;
	text-transform: uppercase;
	padding: 0.55rem 0.95rem;
	border-radius: 999px;
	margin-left: 0.5rem;
}

/* On touch devices the arrows are unnecessary — swipe is primary input.
   Hide the prev/next buttons but keep the dots and Exit. */
@media (hover: none) and (pointer: coarse) {
	.kkb-slideshow__nav {
		display: none;
	}
}

/* ── Resume button (sibling of wrapper) ──────────────────────────── */
.kkb-slideshow__resume {
	position: fixed;
	right: 1.25rem;
	bottom: 1.25rem;
	z-index: 90;
	appearance: none;
	background: var(--kkb-accent, #4afaa8);
	color: #0a0a0a;
	border: none;
	font-family: inherit;
	font-size: 0.75rem;
	letter-spacing: 0.06em;
	text-transform: uppercase;
	font-weight: 600;
	padding: 0.7rem 1.1rem;
	border-radius: 999px;
	cursor: pointer;
	box-shadow: 0 8px 28px rgba(0, 0, 0, 0.25);
	opacity: 0;
	visibility: hidden;
	transform: translateY(8px);
	transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s;
}

.kkb-slideshow__resume.is-visible {
	opacity: 1;
	visibility: visible;
	transform: translateY(0);
}

/* ── Reduced motion ──────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
	.kkb-slideshow__dot,
	.kkb-slideshow__nav,
	.kkb-slideshow__exit,
	.kkb-slideshow__resume {
		transition: none;
	}
}
