.ltoc-layout {
	--ltoc-sidebar-width: clamp(250px, 23vw, 320px);
	--ltoc-layout-gap: clamp(22px, 3.5vw, 44px);
	display: grid;
	grid-template-columns: minmax(0, 1fr) var(--ltoc-sidebar-width);
	align-items: start;
	gap: var(--ltoc-layout-gap);
	width: 100%;
}

.ltoc-layout__content {
	grid-column: 1;
	grid-row: 1;
	min-width: 0;
}

.ltoc {
	--ltoc-accent: var(--theme-accent, var(--accent-color, #e74c5b));
	--ltoc-text: #2c3148;
	--ltoc-accent-soft: color-mix(in srgb, var(--ltoc-accent) 10%, white);
	--ltoc-border: rgba(44, 49, 72, 0.1);
	--ltoc-muted: #8e94a8;
	--ltoc-surface: #fff;
	--ltoc-panel-soft: #fff;
	--ltoc-row-hover: color-mix(in srgb, var(--ltoc-accent) 5%, white);
	--ltoc-shadow: 0 16px 36px rgba(21, 24, 38, 0.1);
	--ltoc-font-size: 15px;
	--ltoc-sticky-top: calc(var(--ltoc-scroll-margin, 80px) + 18px);
	box-sizing: border-box;
	width: 100%;
	max-width: 100%;
	margin: 24px 0;
	color: var(--ltoc-text);
	font-family: inherit;
}

.ltoc-layout > .ltoc {
	position: sticky;
	top: var(--ltoc-sticky-top);
	z-index: 4;
	grid-column: 2;
	grid-row: 1;
	margin: 0;
}

/* Explicit rather than inherited: Chrome's ::details-content pseudo-element
   sits between <details> and the list and would reset the chain to content-box. */
.ltoc *,
.ltoc *::before,
.ltoc *::after {
	box-sizing: border-box;
}

.ltoc-anchor {
	display: block;
	position: relative;
	visibility: hidden;
	pointer-events: none;
	/* Offset for sticky headers on direct hash-fragment navigation.
	   The JS sets --ltoc-scroll-margin dynamically; 80px is a safe fallback. */
	scroll-margin-top: var(--ltoc-scroll-margin, 80px);
}

.ltoc__panel {
	border: 1px solid color-mix(in srgb, var(--ltoc-border) 80%, white);
	border-radius: 18px;
	background: var(--ltoc-surface);
	box-shadow: var(--ltoc-shadow);
	overflow: hidden;
}

.ltoc__summary {
	list-style: none;
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	min-height: 46px;
	padding: 12px 16px;
	border-bottom: 1px solid var(--ltoc-border);
	cursor: pointer;
}

.ltoc__summary::-webkit-details-marker {
	display: none;
}

.ltoc__title-wrap {
	display: inline-flex;
	align-items: center;
	min-width: 0;
}

.ltoc__icon {
	display: none;
}

.ltoc__chevron {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	flex: 0 0 auto;
	width: 22px;
	height: 22px;
	color: var(--ltoc-accent);
	transition: transform 180ms ease;
}

.ltoc__chevron svg {
	width: 18px;
	height: 18px;
	fill: currentColor;
}

.ltoc__title {
	overflow-wrap: anywhere;
	font-size: 14px;
	font-weight: 800;
	line-height: 1.15;
	letter-spacing: 0;
	text-transform: uppercase;
}

.ltoc__panel[open] .ltoc__chevron {
	transform: rotate(180deg);
}

/* Selectors are deliberately heavier than a theme's ".entry-content ol li" resets. */
.ltoc ol.ltoc__list,
.ltoc ol.ltoc__sublist,
.ltoc li.ltoc__item {
	margin: 0;
	padding: 0;
	border: 0;
	list-style: none;
	line-height: inherit;
}

.ltoc ol.ltoc__list,
.ltoc ol.ltoc__sublist {
	background: var(--ltoc-panel-soft);
}

/* Desktop rail: never taller than the viewport, the list scrolls internally. */
.ltoc-layout > .ltoc .ltoc__list {
	max-height: calc(100vh - var(--ltoc-sticky-top) - 46px - 32px);
	overflow-x: hidden;
	overflow-y: auto;
	overscroll-behavior: contain;
	scrollbar-width: thin;
	scrollbar-color: color-mix(in srgb, var(--ltoc-muted) 40%, transparent) transparent;
}

.ltoc__sublist .ltoc__link {
	padding-left: 22px;
	font-size: min(calc(var(--ltoc-font-size) * 0.88), 13px);
	font-weight: 550;
	color: var(--ltoc-muted);
}

.ltoc__sublist .ltoc__link::after {
	content: '';
	position: absolute;
	left: 11px;
	top: 50%;
	width: 4px;
	height: 4px;
	margin-top: -2px;
	border-radius: 50%;
	background: currentColor;
	opacity: 0.45;
}

.ltoc__link {
	display: block;
	position: relative;
	width: 100%;
	min-width: 0;
	max-width: 100%;
	min-height: 32px;
	margin: 0;
	padding: 5px 6px 5px 8px;
	border: 0;
	border-radius: 0;
	box-shadow: none;
	background: transparent;
	text-decoration: none;
	text-align: left;
	text-transform: none;
	text-shadow: none;
	cursor: pointer;
	font-size: min(var(--ltoc-font-size), 14px);
	font-weight: 650;
	line-height: 1.28;
	letter-spacing: 0;
	color: var(--ltoc-muted);
	font-family: inherit;
	white-space: normal;
	overflow: visible;
	overflow-wrap: anywhere;
	word-break: break-word;
	hyphens: none;
	transition: color 160ms ease, background-color 160ms ease;
}

/* Long headings are clamped to two lines; the full text stays in the title attribute. */
.ltoc__label {
	display: -webkit-box;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 2;
	width: 100%;
	max-width: 100%;
	min-width: 0;
	overflow: hidden;
	white-space: normal;
	overflow-wrap: anywhere;
	word-break: break-word;
	text-transform: inherit;
}

.ltoc__link.is-active-parent {
	color: var(--ltoc-text);
}

.ltoc__more {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 6px;
	width: 100%;
	min-height: 40px;
	margin: 0;
	padding: 8px 12px;
	border: 0;
	border-top: 1px solid var(--ltoc-border);
	border-radius: 0;
	box-shadow: none;
	background: var(--ltoc-panel-soft);
	color: var(--ltoc-accent);
	font-family: inherit;
	font-size: min(var(--ltoc-font-size), 14px);
	font-weight: 700;
	letter-spacing: 0;
	text-transform: none;
	text-shadow: none;
	cursor: pointer;
}

.ltoc__more[hidden] {
	display: none;
}

.ltoc__more-chevron {
	display: inline-flex;
	width: 18px;
	height: 18px;
	transition: transform 180ms ease;
}

.ltoc__more-chevron svg {
	width: 18px;
	height: 18px;
	fill: currentColor;
}

.ltoc--expanded .ltoc__more-chevron {
	transform: rotate(180deg);
}

.ltoc--compact:not(.ltoc--expanded) .ltoc__sublist {
	display: none;
}

.ltoc__link::before {
	content: '';
	position: absolute;
	left: 0;
	top: 0;
	bottom: 0;
	width: 3px;
	background: transparent;
	transition: background-color 160ms ease;
}

.ltoc__link:hover,
.ltoc__link:focus-visible {
	background: transparent;
	color: var(--ltoc-accent);
	outline: none;
}

.ltoc__link.is-active {
	background: var(--ltoc-accent-soft);
	color: var(--ltoc-accent);
	font-weight: 700;
	outline: none;
}

.ltoc__link.is-active::before {
	background: var(--ltoc-accent);
}

@media (prefers-color-scheme: dark) {
	.ltoc {
		--ltoc-text: #f4f4f4;
		--ltoc-muted: #b8b8c2;
		--ltoc-border: rgba(255, 255, 255, 0.08);
		--ltoc-surface: #202020;
		--ltoc-panel-soft: #202020;
		--ltoc-accent-soft: color-mix(in srgb, var(--ltoc-accent) 20%, #202020);
		--ltoc-row-hover: color-mix(in srgb, var(--ltoc-accent) 9%, #202020);
		--ltoc-shadow: 0 14px 30px rgba(0, 0, 0, 0.2);
	}
}

html[class*="dark"] .ltoc,
html[class*="night"] .ltoc,
body[class*="dark"] .ltoc,
body[class*="night"] .ltoc,
body[class*="black"] .ltoc,
[data-theme="dark"] .ltoc,
[data-color-scheme="dark"] .ltoc,
.ltoc.ltoc--dark-context {
	--ltoc-text: #f4f4f4;
	--ltoc-muted: #b8b8c2;
	--ltoc-border: rgba(255, 255, 255, 0.08);
	--ltoc-surface: #202020;
	--ltoc-panel-soft: #202020;
	--ltoc-accent-soft: color-mix(in srgb, var(--ltoc-accent) 20%, #202020);
	--ltoc-row-hover: color-mix(in srgb, var(--ltoc-accent) 9%, #202020);
	--ltoc-shadow: 0 14px 30px rgba(0, 0, 0, 0.2);
}
@media (min-width: 1500px) {
	.ltoc-layout {
		--ltoc-sidebar-width: 340px;
	}
}

@media (max-width: 1180px) {
	.ltoc-layout {
		display: block;
	}

	.ltoc-layout > .ltoc,
	.ltoc {
		--ltoc-shadow: 0 12px 26px rgba(21, 24, 38, 0.08);
		position: static;
		width: 100%;
		max-width: 100%;
		margin: clamp(18px, 3vw, 26px) 0;
		color: var(--ltoc-text);
	}

	.ltoc-layout > .ltoc {
		margin-top: 0;
	}

	.ltoc__panel {
		border-radius: 16px;
	}

	.ltoc__summary {
		min-height: 44px;
		padding: 11px 9px;
	}

	.ltoc__icon {
		display: inline-flex;
		align-items: center;
		justify-content: center;
		flex: 0 0 auto;
		margin-right: 6px;
		color: var(--ltoc-accent);
	}

	.ltoc__icon svg {
		width: 18px;
		height: 18px;
		fill: currentColor;
	}

	.ltoc__title {
		font-size: calc(var(--ltoc-font-size) * 0.95);
		text-transform: none;
	}

	.ltoc:not(.ltoc--ready) .ltoc__list {
		display: none;
	}

	.ltoc ol.ltoc__list,
	.ltoc ol.ltoc__sublist {
		background: var(--ltoc-surface);
	}

	.ltoc__link {
		min-height: 32px;
		padding: 5px 6px 5px 8px;
		font-size: var(--ltoc-font-size);
	}

	.ltoc__sublist .ltoc__link {
		padding-left: 22px;
		font-size: calc(var(--ltoc-font-size) * 0.9);
	}

	.ltoc__more {
		font-size: var(--ltoc-font-size);
	}
}

@media (max-width: 640px) {
	.ltoc,
	.ltoc-layout > .ltoc {
		margin: 16px 0;
	}

	.ltoc__summary {
		min-height: 42px;
		padding: 10px 8px;
	}

	.ltoc__link {
		min-height: 32px;
		padding: 5px 6px 5px 8px;
	}

	.ltoc__sublist .ltoc__link {
		padding-left: 22px;
	}
}
