.khc {
	--khc-height: 420px;
	--khc-cols: 4;
	--khc-sub-cols: 3;
	--khc-gap: 12px;
	--khc-icon: 56px;
	--khc-radius: 12px;
	--khc-bg: #f5f5f7;
	--khc-bg-hover: #e9e9ee;
	--khc-color: inherit;
	--khc-accent: currentColor;
	--khc-nav-color: #1d1d1f;
	--khc-title-bg: #4933d1;
	--khc-title-color: #fff;
	--khc-speed: 0.35s;
	position: relative;
	color: var(--khc-color);
}

/* Okno o stałej wysokości – wszystko, co się nie mieści, przewija się w środku. */
.khc__viewport {
	position: relative;
	height: var(--khc-height);
	overflow: hidden;
}

.khc__panel {
	position: absolute;
	inset: 0;
	display: flex;
	flex-direction: column;
	opacity: 0;
	visibility: hidden;
	transform: translateX(100%);
	transition:
		transform var(--khc-speed) cubic-bezier(0.4, 0, 0.2, 1),
		opacity var(--khc-speed) ease,
		visibility 0s linear var(--khc-speed);
}

.khc__panel.is-active {
	opacity: 1;
	visibility: visible;
	transform: none;
	transition-delay: 0s;
}

.khc__panel.is-prev {
	transform: translateX(-30%);
}

.khc--zoom .khc__panel {
	transform: scale(0.92);
}

.khc--zoom .khc__panel.is-active {
	transform: none;
}

.khc--zoom .khc__panel.is-prev {
	transform: scale(1.12);
}

.khc__scroll {
	flex: 1;
	min-height: 0;
	overflow-x: hidden;
	overflow-y: auto;
	overscroll-behavior: contain;
	scrollbar-width: thin;
}

.khc__grid {
	display: grid;
	gap: var(--khc-gap);
	margin: 0;
	padding: 0;
	list-style: none;
}

.khc__grid > li {
	display: flex;
	min-width: 0;
	margin: 0;
	padding: 0;
}

.khc__grid--root {
	grid-template-columns: repeat(var(--khc-cols), minmax(0, 1fr));
	grid-auto-rows: 1fr;
	min-height: 100%;
}

.khc__grid--sub {
	grid-template-columns: repeat(var(--khc-sub-cols), minmax(0, 1fr));
}

.khc__tile {
	display: flex;
	flex: 1;
	align-items: center;
	gap: 12px;
	min-width: 0;
	min-height: 52px;
	padding: 10px 14px;
	border-radius: var(--khc-radius);
	background: var(--khc-bg);
	color: inherit;
	text-decoration: none;
	transition: background-color 0.2s ease;
}

.khc__tile:hover,
.khc__tile:focus-visible {
	background: var(--khc-bg-hover);
	color: inherit;
	text-decoration: none;
}

.khc__tile:focus-visible,
.khc__back:focus-visible,
.khc__all:focus-visible {
	outline: 2px solid var(--khc-accent);
	outline-offset: 2px;
}

.khc__name {
	flex: 1;
	min-width: 0;
	overflow-wrap: anywhere;
	line-height: 1.25;
}

.khc__icon {
	display: flex;
	flex: none;
	align-items: center;
	justify-content: center;
	width: 32px;
	height: 32px;
}

.khc__icon img {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: contain;
}

.khc__chev {
	flex: none;
	width: 8px;
	height: 8px;
	border-top: 2px solid var(--khc-accent);
	border-right: 2px solid var(--khc-accent);
	transform: rotate(45deg);
	opacity: 0.6;
}

/* Kafelki pierwszego poziomu: większa ikona po lewej, obok nazwa. */
.khc__grid--root .khc__tile {
	gap: 16px;
	padding: 16px;
}

.khc__grid--root .khc__icon {
	width: var(--khc-icon);
	height: var(--khc-icon);
}

.khc__head {
	display: flex;
	flex: none;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	padding-bottom: var(--khc-gap);
}

/* „Wróć” i „Zobacz wszystko” wyglądają identycznie; podwójna klasa wygrywa ze stylami przycisków motywu. */
.khc .khc__back,
.khc .khc__head .khc__all {
	display: inline-flex;
	flex: none;
	align-items: center;
	gap: 8px;
	margin: 0;
	padding: 4px 0;
	border: 0;
	border-radius: 0;
	background: none;
	box-shadow: none;
	color: var(--khc-nav-color);
	font: inherit;
	font-size: 0.875em;
	font-weight: 400;
	line-height: 1.2;
	text-decoration: none;
	text-transform: none;
	letter-spacing: normal;
	white-space: nowrap;
	cursor: pointer;
}

.khc .khc__back:hover,
.khc .khc__back:focus,
.khc .khc__head .khc__all:hover,
.khc .khc__head .khc__all:focus {
	background: none;
	color: var(--khc-nav-color);
	text-decoration: underline;
	text-underline-offset: 3px;
}

.khc__back::before,
.khc__head .khc__all::after {
	content: "";
	width: 6px;
	height: 6px;
	border-bottom: 2px solid currentColor;
	border-left: 2px solid currentColor;
	transform: rotate(45deg);
}

.khc__head .khc__all::after {
	transform: rotate(-135deg);
}

/* Belka z nazwą bieżącej kategorii, nad listą podkategorii. */
.khc__title {
	flex: none;
	margin-bottom: var(--khc-gap);
	padding: 12px 16px;
	overflow: hidden;
	border-radius: var(--khc-radius);
	background: var(--khc-title-bg);
	color: var(--khc-title-color);
	font-weight: 600;
	line-height: 1.25;
	text-overflow: ellipsis;
	white-space: nowrap;
}

/* Strzałki przewijania: na dolnej krawędzi okna, w połowie poza nim – nie zajmują miejsca w układzie. */
.khc__pager {
	position: absolute;
	bottom: 0;
	left: 50%;
	z-index: 5;
	display: flex;
	gap: 6px;
	transform: translate(-50%, 50%);
}

.khc__pager[hidden] {
	display: none;
}

/* Strzałka w kierunku, w którym nie ma już czego przewijać. */
.khc .khc__page:disabled {
	opacity: 0.5;
	filter: none;
	cursor: default;
}

.khc .khc__page {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 40px;
	height: 40px;
	margin: 0;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: var(--khc-title-bg);
	box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
	color: var(--khc-title-color);
	cursor: pointer;
}

.khc .khc__page:hover,
.khc .khc__page:focus {
	background: var(--khc-title-bg);
	color: var(--khc-title-color);
	filter: brightness(1.15);
}

.khc__page:focus-visible {
	outline: 2px solid var(--khc-title-bg);
	outline-offset: 2px;
}

.khc__page::before {
	content: "";
	width: 9px;
	height: 9px;
	margin-top: -4px;
	border-right: 2px solid currentColor;
	border-bottom: 2px solid currentColor;
	transform: rotate(45deg);
}

.khc__page--up::before {
	margin-top: 4px;
	transform: rotate(-135deg);
}

.khc__message .khc__all {
	color: var(--khc-accent);
	font-weight: 600;
	text-decoration: underline;
	text-underline-offset: 3px;
}

.khc__message {
	padding: 24px 0;
}

.khc__skeleton .khc__tile {
	animation: khc-pulse 1.1s ease-in-out infinite alternate;
}

@keyframes khc-pulse {
	from {
		opacity: 1;
	}
	to {
		opacity: 0.45;
	}
}

.khc-empty {
	padding: 24px;
	border: 1px dashed currentColor;
	text-align: center;
	opacity: 0.7;
}

@media (prefers-reduced-motion: reduce) {
	.khc__panel,
	.khc__tile,
	.khc__back {
		transition: none;
	}

	.khc__skeleton .khc__tile {
		animation: none;
	}
}
