/**
 * Table of Contents widget.
 *
 * The collapsed height is fixed in CSS and applied on first paint, and the
 * toggle button is rendered server-side, so nothing moves when JS loads (CLS 0).
 * Expanding happens only after a user click, which CLS ignores.
 */
.swyft-toc {
	--swyft-toc-line-height: 1.6;
	--swyft-toc-lines: 4;
	--swyft-toc-collapsed: calc(var(--swyft-toc-lines) * var(--swyft-toc-line-height) * 1em);
	font-size: 0.9375rem;
	line-height: var(--swyft-toc-line-height);
}

.swyft-toc__list {
	margin: 0;
	padding: 0;
	list-style: none;
}

.swyft-toc__list .swyft-toc__list {
	padding-left: 1rem;
}

.swyft-toc__item {
	margin: 0;
	padding: 0;
}

.swyft-toc__link {
	display: block;
	color: var(--cs-color-primary);
	text-decoration: none;
	border-radius: 2px;
}

.swyft-toc__item--h3 > .swyft-toc__link,
.swyft-toc__item--h4 > .swyft-toc__link,
.swyft-toc__item--h5 > .swyft-toc__link,
.swyft-toc__item--h6 > .swyft-toc__link {
	color: var(--cs-color-secondary);
}

.swyft-toc__link:hover {
	color: var(--cs-color-accent);
	text-decoration: underline;
}

/* Inset focus ring so the viewport's overflow:hidden can't clip it. */
.swyft-toc__link:focus-visible {
	outline: none;
	box-shadow: inset 0 0 0 2px var(--cs-color-accent);
}

/* Collapsed state */
.swyft-toc--collapsible .swyft-toc__viewport {
	max-height: var(--swyft-toc-collapsed);
	overflow: hidden;
	-webkit-mask-image: linear-gradient(to bottom, #000 calc(100% - 1.6em), transparent);
	mask-image: linear-gradient(to bottom, #000 calc(100% - 1.6em), transparent);
}

.swyft-toc--collapsible.is-expanded .swyft-toc__viewport {
	max-height: var(--swyft-toc-full, none);
	-webkit-mask-image: none;
	mask-image: none;
}

@media (prefers-reduced-motion: no-preference) {
	.swyft-toc--collapsible .swyft-toc__viewport {
		transition: max-height 0.25s ease;
	}

	.swyft-toc__toggle-icon {
		transition: transform 0.25s ease;
	}
}

/* Toggle */
.swyft-toc__toggle {
	display: inline-flex;
	align-items: center;
	gap: 0.375rem;
	min-height: 44px;
	margin-top: 0.25rem;
	padding: 0.5rem 0;
	border: 0;
	background: none;
	color: var(--cs-color-accent);
	font: inherit;
	font-weight: 600;
	line-height: 1.4;
	text-align: left;
	cursor: pointer;
}

/* Override the parent theme's global button:hover/focus background. */
.swyft-toc .swyft-toc__toggle:hover,
.swyft-toc .swyft-toc__toggle:focus,
.swyft-toc .swyft-toc__toggle:active {
	background: none;
	color: var(--cs-color-accent);
	box-shadow: none;
}

.swyft-toc__toggle:hover .swyft-toc__toggle-text {
	text-decoration: underline;
}

.swyft-toc__toggle:focus-visible {
	outline: 2px solid var(--cs-color-accent);
	outline-offset: 2px;
}

.swyft-toc__toggle-icon {
	flex-shrink: 0;
}

.swyft-toc__toggle[aria-expanded="true"] .swyft-toc__toggle-icon {
	transform: rotate(180deg);
}

@media (forced-colors: active) {
	.swyft-toc__link:focus-visible {
		outline: 2px solid CanvasText;
	}
}

/* Keep linked headings clear of the sticky header. */
.entry-content :is(h2, h3, h4, h5, h6)[id] {
	scroll-margin-top: calc(var(--cs-header-height, 80px) + 1.5rem);
}
