/**
 * Kempeneers Table of Contents – front end (also used for the editor preview).
 *
 * Colours and fonts come from the theme presets (Infield: accent-3, accent-4,
 * Archivo Narrow, IBM Plex Sans) with hard fallbacks. Override any of the
 * --ktoc-* custom properties in Appearance → Editor → Styles → Additional CSS.
 *
 * Every selector is scoped to .ktoc, so theme styles are not affected.
 */

.ktoc {
	--ktoc-bg: var(--wp--preset--color--accent-3, #f7f6f1);
	--ktoc-text: var(--wp--preset--color--contrast, #11181f);
	--ktoc-muted: #4b545c;
	--ktoc-sub: #283039;
	--ktoc-strong: var(--wp--preset--color--accent-1, #002b6a);
	--ktoc-accent: var(--wp--preset--color--accent-4, #ffcd58);
	--ktoc-arrow: #d49a12;
	--ktoc-arrow-hover: #a87500;
	--ktoc-pill: rgba(255, 205, 88, 0.45);
	--ktoc-focus: var(--wp--preset--color--accent-2, #007fe6);
	--ktoc-rule: rgba(17, 24, 31, 0.14);
	--ktoc-font-head: var(--wp--preset--font-family--archivo-narrow, "Archivo Narrow", "Arial Narrow", sans-serif);
	--ktoc-font-body: var(--wp--preset--font-family--ibm-plex-sans, "IBM Plex Sans", system-ui, sans-serif);
	--ktoc-pad: 1.75rem;

	box-sizing: border-box;
	position: relative;
	padding: var(--ktoc-pad);
	border: 0;
	border-radius: 0;
	background: var(--ktoc-bg);
	color: var(--ktoc-text);
	font-family: var(--ktoc-font-body);
	font-size: 1rem;
	font-weight: 400;
	line-height: 1.5;
	text-align: start;
}

.ktoc *,
.ktoc *::before,
.ktoc *::after {
	box-sizing: border-box;
}

/* Title: same look as the sidebar labels ("RECENT POSTS"), with a short yellow rule. */
.ktoc .ktoc__title {
	margin: 0 0 1rem;
	padding: 0;
	color: var(--ktoc-text);
	font-family: var(--ktoc-font-head);
	font-size: 1.25rem;
	font-weight: 500;
	line-height: 1.25;
	letter-spacing: 0.02em;
	text-transform: uppercase;
}

.ktoc .ktoc__title::after {
	content: "";
	display: block;
	width: 2.5rem;
	height: 3px;
	margin-top: 0.5rem;
	background: var(--ktoc-accent);
}

/* Lists */
.ktoc .ktoc__list {
	margin: 0;
	padding: 0;
	list-style: none;
}

/* Root items line up with the title; the active marker sits in the box padding. */
.ktoc .ktoc__list:not(.ktoc__sublist) {
	margin-left: -0.875rem;
}

.ktoc .ktoc__item {
	margin: 0;
	padding: 0;
	list-style: none;
}

.ktoc .ktoc__item::marker {
	content: none;
}

.ktoc .ktoc__link {
	display: block;
	padding: 0.3rem 0 0.3rem 0.875rem;
	border: 0;
	box-shadow: inset 3px 0 0 transparent;
	background: none;
	color: inherit;
	text-decoration: none;
	overflow-wrap: anywhere;
	transition: color 0.15s ease, box-shadow 0.15s ease;
}

/* First level: narrow heading font, like the post titles in the sidebar. */
.ktoc .ktoc__list:not(.ktoc__sublist) > .ktoc__item > .ktoc__link {
	font-family: var(--ktoc-font-head);
	font-size: 1.1875rem;
	font-weight: 500;
	line-height: 1.3;
}

/* Deeper levels: body font, a little smaller. */
.ktoc .ktoc__sublist .ktoc__link {
	padding-top: 0.25rem;
	padding-bottom: 0.25rem;
	color: var(--ktoc-sub);
	font-family: var(--ktoc-font-body);
	font-size: 0.9375rem;
	font-weight: 400;
	line-height: 1.45;
}

.ktoc.is-indented .ktoc__sublist {
	margin: 0.15rem 0 0.4rem 0.875rem;
	padding: 0 0 0 0.25rem;
	border-left: 1px solid var(--ktoc-rule);
}

@media (hover: hover) {
	.ktoc .ktoc__link:hover {
		color: var(--ktoc-strong);
		text-decoration: underline;
		text-decoration-color: var(--ktoc-accent);
		text-decoration-thickness: 2px;
		text-underline-offset: 0.22em;
	}
}

/* Active section (optional). */
.ktoc .ktoc__link.is-active {
	box-shadow: inset 3px 0 0 var(--ktoc-accent);
	color: var(--ktoc-strong);
	font-weight: 600;
}

/* Numbered list: 1, 1.1, 1.2 … */
.ktoc.is-numbered .ktoc__list {
	counter-reset: ktoc;
}

.ktoc.is-numbered .ktoc__item {
	counter-increment: ktoc;
}

.ktoc.is-numbered .ktoc__link::before {
	content: counters(ktoc, ".") "\00a0\00a0";
	color: var(--ktoc-muted);
	font-variant-numeric: tabular-nums;
	font-weight: 400;
}

/* Show more / show less */
.ktoc .ktoc__toggle[hidden] {
	display: none;
}

.ktoc.is-collapsed .ktoc__item--more {
	display: none;
}

.ktoc .ktoc__toggle {
	display: flex;
	align-items: center;
	gap: 0.5rem;
	width: 100%;
	min-height: 44px;
	margin: 0.875rem 0 0;
	padding: 0.75rem 0 0;
	border: 0;
	border-top: 1px solid var(--ktoc-rule);
	border-radius: 0;
	background: none;
	box-shadow: none;
	color: var(--ktoc-text);
	font-family: var(--ktoc-font-head);
	font-size: 1rem;
	font-weight: 600;
	line-height: 1.2;
	letter-spacing: 0.04em;
	text-align: start;
	text-decoration: none;
	text-transform: uppercase;
	cursor: pointer;
	-webkit-appearance: none;
	appearance: none;
}

.ktoc .ktoc__toggle-count {
	display: inline-block;
	padding: 0.1rem 0.5rem;
	border-radius: 999px;
	background: var(--ktoc-pill);
	color: var(--ktoc-text);
	font-family: var(--ktoc-font-body);
	font-size: 0.8125rem;
	font-weight: 500;
	letter-spacing: 0;
	line-height: 1.4;
	text-transform: none;
}

.ktoc .ktoc__toggle[aria-expanded="true"] .ktoc__toggle-count {
	display: none;
}

.ktoc .ktoc__chevron {
	flex: none;
	color: var(--ktoc-arrow);
	transition: transform 0.2s ease, color 0.15s ease;
}

.ktoc .ktoc__toggle[aria-expanded="true"] .ktoc__chevron {
	transform: rotate(180deg);
}

@media (hover: hover) {
	.ktoc .ktoc__toggle:hover {
		color: var(--ktoc-strong);
	}

	.ktoc .ktoc__toggle:hover .ktoc__chevron {
		color: var(--ktoc-arrow-hover);
		transform: translateY(2px);
	}

	.ktoc .ktoc__toggle[aria-expanded="true"]:hover .ktoc__chevron {
		transform: rotate(180deg) translateY(2px);
	}
}

/* Focus */
.ktoc .ktoc__link:focus-visible,
.ktoc .ktoc__toggle:focus-visible {
	outline: 2px solid var(--ktoc-focus);
	outline-offset: 2px;
}

.ktoc .ktoc__sr {
	position: absolute !important;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip: rect(0 0 0 0);
	clip-path: inset(50%);
	white-space: nowrap;
	border: 0;
}

/* Section headings land below a sticky header (the script fine-tunes this). */
:where(.wp-block-post-content, .entry-content) :where(h2, h3, h4, h5, h6)[id] {
	scroll-margin-top: 1.5rem;
}

/* Phones */
@media (max-width: 600px) {
	.ktoc {
		--ktoc-pad: 1.25rem;
	}

	.ktoc .ktoc__title {
		font-size: 1.125rem;
	}

	.ktoc .ktoc__list:not(.ktoc__sublist) > .ktoc__item > .ktoc__link {
		font-size: 1.0625rem;
	}

	.ktoc .ktoc__link {
		padding-left: 0.625rem;
	}

	.ktoc .ktoc__list:not(.ktoc__sublist) {
		margin-left: -0.625rem;
	}

	.ktoc.is-indented .ktoc__sublist {
		margin-left: 0.5rem;
	}
}

@media (prefers-reduced-motion: reduce) {
	.ktoc .ktoc__link,
	.ktoc .ktoc__chevron {
		transition: none;
	}
}

@media (forced-colors: active) {
	.ktoc {
		border: 1px solid CanvasText;
	}

	.ktoc .ktoc__link.is-active {
		outline: 1px solid LinkText;
	}
}

@media print {
	.ktoc {
		padding: 0;
		background: none;
	}

	.ktoc.is-collapsed .ktoc__item--more {
		display: list-item;
	}

	.ktoc .ktoc__toggle {
		display: none;
	}
}
