/**
 * Table of contents.
 *
 * Anchor links in a real list: the browser does the jumping, the history and
 * the keyboard, so this file is all there is. No JavaScript.
 */
.sigtk-toc {
	--sigtk-toc-accent: #4a4f8c;
	--sigtk-toc-ink: #1d2327;
	--sigtk-toc-muted: #5c6169;
	--sigtk-toc-line: #e2e4e7;
	--sigtk-toc-bg: #fafafc;
	--sigtk-toc-offset: 90px;

	/* The frame, changeable from the settings without a line of CSS. */
	--sigtk-toc-radius: 10px;
	--sigtk-toc-border-width: 1px;
	--sigtk-toc-stripe-width: 4px;

	box-sizing: border-box;
	margin: 0 0 28px;
	color: var(--sigtk-toc-ink);
}

.sigtk-toc * {
	box-sizing: border-box;
}

.sigtk-toc__box {
	padding: 16px 20px;
	border: var(--sigtk-toc-border-width) solid var(--sigtk-toc-line);
	border-left: var(--sigtk-toc-stripe-width) solid var(--sigtk-toc-accent);
	border-radius: var(--sigtk-toc-radius);
	background: var(--sigtk-toc-bg);
}

.sigtk-toc__title {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	margin: 0 0 10px;
	padding: 0;
	font-size: 0.95em;
	font-weight: 700;
	line-height: 1.4;
	letter-spacing: normal;
	text-transform: none;
	color: var(--sigtk-toc-ink);
	list-style: none;
}

details.sigtk-toc__box .sigtk-toc__title {
	margin-bottom: 0;
	cursor: pointer;
}

details.sigtk-toc__box[open] .sigtk-toc__title {
	margin-bottom: 10px;
}

.sigtk-toc__title::-webkit-details-marker {
	display: none;
}

.sigtk-toc__title::marker {
	content: "";
}

.sigtk-toc__marker {
	position: relative;
	flex: none;
	width: 14px;
	height: 14px;
}

.sigtk-toc__marker::before,
.sigtk-toc__marker::after {
	content: "";
	position: absolute;
	top: 50%;
	left: 50%;
	width: 11px;
	height: 2px;
	border-radius: 2px;
	background: var(--sigtk-toc-muted);
	transform: translate( -50%, -50% );
	transition: opacity 0.18s ease;
}

.sigtk-toc__marker::after {
	transform: translate( -50%, -50% ) rotate( 90deg );
}

details.sigtk-toc__box[open] .sigtk-toc__marker::after {
	opacity: 0;
}

.sigtk-toc__list {
	margin: 0;
	padding: 0;
	list-style: none;
	counter-reset: sigtk-toc;
}

.sigtk-toc__list--nested {
	margin: 4px 0 4px 18px;
	padding-left: 12px;
	border-left: 1px solid var(--sigtk-toc-line);
}

.sigtk-toc__item {
	margin: 0 0 4px;
	padding: 0;
	list-style: none;
	line-height: 1.5;
}

.sigtk-toc__item:last-child {
	margin-bottom: 0;
}

.sigtk-toc__link {
	color: var(--sigtk-toc-ink);
	font-size: 0.95em;
	text-decoration: none;
	text-transform: none;
	letter-spacing: normal;
	box-shadow: none;
	border-bottom: 1px solid transparent;
}

.sigtk-toc__link:hover,
.sigtk-toc__link:focus {
	color: var(--sigtk-toc-accent);
	border-bottom-color: currentColor;
}

/* numbering, counted per level so nested entries read 1.1, 1.2 and so on */
.sigtk-toc--numbered .sigtk-toc__item {
	counter-increment: sigtk-toc;
}

.sigtk-toc--numbered .sigtk-toc__item > .sigtk-toc__link::before {
	content: counters( sigtk-toc, "." ) ". ";
	color: var(--sigtk-toc-muted);
	font-variant-numeric: tabular-nums;
}

/*
 * Room for a sticky header, so the heading you jumped to is not hidden behind
 * it, and a soft scroll for people who did not ask for less motion.
 */
:where( h2, h3, h4, h5, h6 )[id] {
	scroll-margin-top: var( --sigtk-toc-offset, 90px );
}

@media ( prefers-reduced-motion: no-preference ) {
	html:has( .sigtk-toc ) {
		scroll-behavior: smooth;
	}
}

@media screen and ( max-width: 600px ) {
	.sigtk-toc__box {
		padding: 14px 16px;
	}
}
