/*
 * Article guide: the contents panel beside an article.
 *
 * Wide screens: the guide floats into the right margin of the reading column,
 * sticks while the article scrolls, and shows the featured image above the
 * headings. Narrow screens: a collapsed "In this article" box above the text.
 * Colours come from the design-system tokens, so both schemes follow.
 */

/* Anchor jumps must not land under the sticky header. */
.embedonix-enhancement-article .entry-content :is(h2, h3, h4)[id] {
	scroll-margin-top: 96px;
}

/* ---- Shared (narrow) layout ---------------------------------------- */

html body .entry-content > nav.embedonix-guide.alignright {
	float: none;
	width: var(--theme-block-width, auto);
	max-width: var(--embedonix-article-content-width, var(--wp--style--global--content-size, 900px));
	margin: 0 auto 1.5em;
}

/* Phones and tablets: the larger cover sits above the list. */
.embedonix-guide__cover--side {
	display: none;
}

/* Not cropped: the featured images carry their headline near the top edge. */
.embedonix-guide__cover--inline {
	display: block;
	max-width: 420px;
	margin: 0 auto 12px;
	overflow: hidden;
	border: 1px solid var(--emx-border);
	border-radius: var(--emx-radius);
}

.embedonix-guide__cover--inline .embedonix-guide__cover-image {
	display: block;
	width: 100%;
	height: auto;
	margin: 0;
}

.embedonix-guide__box {
	border: 1px solid var(--emx-border);
	border-radius: var(--emx-radius);
	background: var(--emx-surface);
}

.embedonix-guide__title {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	padding: 10px 16px;
	color: var(--emx-heading);
	font-size: 0.8rem;
	font-weight: 700;
	letter-spacing: 0.06em;
	text-transform: uppercase;
	cursor: pointer;
	list-style: none;
}

.embedonix-guide__title::-webkit-details-marker {
	display: none;
}

.embedonix-guide__title::after {
	content: '';
	width: 8px;
	height: 8px;
	border-right: 2px solid currentColor;
	border-bottom: 2px solid currentColor;
	transform: rotate(45deg) translateY(-2px);
	transition: transform 0.15s ease;
}

.embedonix-guide__box[open] > .embedonix-guide__title::after {
	transform: rotate(-135deg) translateY(-2px);
}

.embedonix-guide__list,
.embedonix-guide__sublist {
	margin: 0;
	padding: 0;
	list-style: none;
}

/* One running count across all parts. */
.embedonix-guide__list {
	counter-reset: embedonix-guide;
}

.embedonix-guide__list {
	padding: 0 16px 12px;
	font-size: 0.9rem;
	line-height: 1.4;
}

.embedonix-guide__item {
	counter-increment: embedonix-guide;
	margin: 0;
}

.embedonix-guide__item + .embedonix-guide__item {
	margin-top: 2px;
}

.embedonix-guide__link {
	display: grid;
	grid-template-columns: 1.6em minmax(0, 1fr);
	gap: 6px;
	padding: 5px 8px 5px 0;
	border-left: 2px solid transparent;
	color: var(--emx-text);
	text-decoration: none;
}

.embedonix-guide__link::before {
	content: counter(embedonix-guide);
	color: var(--emx-text-muted);
	font-variant-numeric: tabular-nums;
	text-align: right;
}

.embedonix-guide__link:hover {
	color: var(--emx-accent-text);
}

.embedonix-guide__link[aria-current='location'] {
	color: var(--emx-accent-text);
	font-weight: 600;
}

/* Multi-page articles: headings grouped by part. */
.embedonix-guide__part + .embedonix-guide__part {
	margin-top: 10px;
}

.embedonix-guide__part-label {
	display: block;
	padding: 4px 0;
	color: var(--emx-heading);
	font-size: 0.72rem;
	font-weight: 700;
	letter-spacing: 0.06em;
	text-transform: uppercase;
}

.embedonix-guide__part.is-current .embedonix-guide__part-label {
	color: var(--emx-accent-text);
}

.embedonix-guide__part.is-other .embedonix-guide__part-label {
	color: var(--emx-text-muted);
	font-weight: 600;
}

/* Headings of pages that are not open are grayed out but still links. */
.embedonix-guide__part.is-other .embedonix-guide__link {
	color: var(--emx-text-muted);
}

.embedonix-guide__part.is-other .embedonix-guide__link:hover {
	color: var(--emx-accent-text);
}

.embedonix-guide__title:focus-visible,
.embedonix-guide__link:focus-visible {
	outline: 2px solid var(--emx-accent-text);
	outline-offset: 2px;
}

/* ---- Wide layout: sticky panel in the right margin ------------------- */

/* The headings have their own numbers: no counter column. */
.embedonix-guide--own-numbers .embedonix-guide__link {
	grid-template-columns: minmax(0, 1fr);
	padding-left: 10px;
}

.embedonix-guide--own-numbers .embedonix-guide__link::before {
	content: none;
}

@media (min-width: 1280px) {
	/* The theme sets overflow-x: hidden on body, which makes body the scroll
	   container and stops position: sticky. clip keeps the horizontal guard. */
	html body.embedonix-enhancement-article {
		overflow-x: clip;
	}

	.embedonix-enhancement-article .entry-content {
		--embedonix-guide-column: var(--embedonix-article-content-width, 900px);
		--embedonix-guide-width: clamp(150px, calc((100vw - var(--embedonix-guide-column) - 80px) / 2), 232px);
	}

	html body .entry-content > nav.embedonix-guide.alignright {
		float: right;
		position: sticky;
		top: 24px;
		z-index: 2;
		width: var(--embedonix-guide-width);
		max-width: none;
		max-height: calc(100vh - 104px); /* clear of the back-to-top button */
		/* The negative left margin makes the float's margin box zero wide. Blocks
		   that form their own formatting context (pre, table, figure) would
		   otherwise shrink and shift to clear the guide. */
		margin: 0 calc((100% - var(--embedonix-guide-column)) / 2 - var(--embedonix-guide-width) - 24px) 1.5em calc(-1 * ((100% - var(--embedonix-guide-column)) / 2 - 24px));
		overflow-y: auto;
		overscroll-behavior: contain;
		scrollbar-width: thin;
	}

	.embedonix-guide__cover--inline {
		display: none;
	}

	.embedonix-guide__cover--side {
		display: block;
		margin: 0 0 14px;
		overflow: hidden;
		border: 1px solid var(--emx-border);
		border-radius: var(--emx-radius);
	}

	.embedonix-guide__cover-image {
		display: block;
		width: 100%;
		height: auto;
		margin: 0;
	}

	/* Pinned: the summary is a title bar, the list is always open. */
	.embedonix-guide__box {
		border: 0;
		border-left: 1px solid var(--emx-border);
		border-radius: 0;
		background: transparent;
	}

	.embedonix-guide__title {
		padding: 0 0 8px 14px;
		cursor: default;
		pointer-events: none;
	}

	.embedonix-guide__title::after {
		display: none;
	}

	.embedonix-guide__list {
		padding: 0 0 0 8px;
	}
}

@media print {
	nav.embedonix-guide {
		display: none;
	}
}
