/*
 * Vertical spine (front end only). Not loaded in the editor, so nothing here
 * appears in or is saved with content.
 *
 * Everything is a pseudo-element:
 *
 *   .bl-page::before            the line, plus its filled (scrolled) part
 *   .bl-header__row::before     header marker (charcoal, tall)
 *   .is-style-section::before   section marker (rounded bar)
 *   .is-style-section::after    tick (desktop only)
 *
 * Sections are Groups with the "Section" block style (is-style-section,
 * registered in functions.php). The marker is centred on the first line of
 * the section's first heading. Without JavaScript that centre is estimated
 * from --bl-pt (the section's top padding, set by the section's own CSS) and
 * the heading size; assets/js/spine.js measures it and sets --bl-mk-y.
 *
 * Without JavaScript: grey line, grey markers, no progress. spine.js adds
 * .bl-spine-active / .bl-spine-past to sections and sets --bl-prog (filled
 * length) on .bl-page.
 */

:root {
	--bl-mk-w: 11px;
	--bl-mk-h: 26px;
	--bl-mk-left: -69px;     /* marker left edge, from the content column */
	--bl-mk-header-h: 36px;
	--bl-line-end: 120px;    /* line stops this far above the end of .bl-page */
	--bl-ease: cubic-bezier(0.22, 0.61, 0.36, 1);
}

.bl-page {
	/*
	 * Left edge of the content column, measured from .bl-page (full width; the
	 * root padding lives on the blocks inside): the gutter plus half of what
	 * the gutters and the column leave over.
	 */
	--bl-col-left: calc(
		var(--wp--style--root--padding-left) +
		max(0px, (100% - var(--wp--style--root--padding-left) - var(--wp--style--root--padding-right) - var(--wp--style--global--content-size)) / 2)
	);
}

/*
 * One pseudo-element draws both the line and its filled part (a second
 * background layer sized by --bl-prog). As ::before it paints beneath the
 * markers, which are later positioned elements.
 */
.bl-page::before {
	content: "";
	position: absolute;
	left: calc(var(--bl-col-left) - var(--bl-spine-offset));
	top: 0;
	bottom: var(--bl-line-end);
	width: 1px;
	pointer-events: none;
	background:
		linear-gradient(var(--wp--custom--spine--progress), var(--wp--custom--spine--progress)) 0 0 / 100% var(--bl-prog, 0px) no-repeat,
		var(--wp--custom--spine--line);
}

/* Header marker: 3px below the row's top, 47px from the page top as in the design */
.bl-header__row {
	position: relative;
}

.bl-header__row::before {
	content: "";
	position: absolute;
	left: var(--bl-mk-left);
	top: 3px;
	width: var(--bl-mk-w);
	height: var(--bl-mk-header-h);
	border-radius: 3px;
	background: var(--wp--custom--spine--marker-header);
	pointer-events: none;
}

/* Sections: Section groups, and each H2 directly in a single post's body */
:is(.is-style-section, .bl-article-body > h2) {
	position: relative;
	--bl-mk-c: calc(var(--wp--preset--font-size--x-large) * 1.15 / 2);
}

.is-style-section:has(h1) {
	--bl-mk-c: calc(var(--wp--preset--font-size--xx-large) / 2);
}

/* Marker */
:is(.is-style-section, .bl-article-body > h2)::before {
	content: "";
	position: absolute;
	left: var(--bl-mk-left);
	top: calc(var(--bl-mk-y, calc(var(--bl-pt, 0px) + var(--bl-mk-c))) - var(--bl-mk-h) / 2);
	width: var(--bl-mk-w);
	height: var(--bl-mk-h);
	border-radius: 3px;
	background: var(--wp--custom--spine--marker-future);
	transform-origin: 50% 50%;
	transition: background-color 1.1s ease, transform 0.9s var(--bl-ease);
	pointer-events: none;
}

:is(.is-style-section, .bl-article-body > h2).bl-spine-past::before {
	background: var(--wp--custom--spine--marker-past);
}

:is(.is-style-section, .bl-article-body > h2).bl-spine-active::before {
	background: var(--wp--custom--color--accent);
	transform: scaleY(1.22);
}

/* Tick: from 52px left of the column, 40px long, level with the marker's centre */
:is(.is-style-section, .bl-article-body > h2)::after {
	content: "";
	position: absolute;
	left: -52px;
	top: var(--bl-mk-y, calc(var(--bl-pt, 0px) + var(--bl-mk-c)));
	width: 40px;
	height: 1px;
	background: var(--wp--custom--spine--line);
	pointer-events: none;
}

@media (max-width: 820px) {
	:root {
		--bl-mk-w: 9px;
		--bl-mk-h: 16px;
		--bl-mk-left: -19px;
		--bl-mk-header-h: 26px;
	}

	.is-style-section:has(h1) {
		--bl-mk-c: calc(var(--wp--preset--font-size--xx-large) * 1.04 / 2);
	}

	:is(.is-style-section, .bl-article-body > h2)::after {
		display: none;
	}
}

@media (prefers-reduced-motion: reduce) {
	:is(.is-style-section, .bl-article-body > h2)::before {
		transition: none;
	}

	:is(.is-style-section, .bl-article-body > h2).bl-spine-active::before {
		transform: none;
	}
}
