/*
 * Typography rhythm and link treatment
 *
 * The parts of the type system theme.json cannot express: link underline
 * color, weight and offset, and the heading-to-content spacing scale.
 *
 * Every selector is wrapped in :root :where(...) so it lands at (0,1,0), the
 * same specificity as WordPress's own layout and element output. Utilities and
 * editor-set styles can still override it.
 *
 * @package Kindling
 */

/*
 * Links carry a 2px underline rule in the surface's link underline token,
 * separate from the text color. Surfaces redefine the token in
 * surface-schemes.css.
 */
:root :where(a:not(.wp-element-button)) {
	text-decoration-color: var(--wp--custom--color--text--link-underline);
	text-decoration-thickness: 2px;
	text-underline-offset: 0.35em;
}

/*
 * Vertical rhythm.
 *
 * The default gap between blocks is the global blockGap (spacing 30, 24px).
 * These rules adjust it where the type scale calls for something else:
 *
 *   paragraph to paragraph             custom spacing 12 (12px)
 *   content to the next heading        spacing 50 (40px)
 *   after h4 to h6, Small, Body Large  custom spacing 12 (12px)
 *   after h2, h3, Large, Medium        spacing 20 (16px)
 *   after h1, Extra Large              spacing 30 (24px)
 *   after Display                      spacing 50 (40px)
 *   around separators                  spacing 50 (40px)
 *
 * A Subheading (eyebrow) is a kicker for the heading below it, so it keeps
 * the default gap instead of the larger space before a heading.
 *
 * Element rules come before style variation rules: they tie on specificity,
 * so a heading with a type style (an h2 set to Display) follows its style.
 */
:root :where(.is-layout-flow, .is-layout-constrained) > :where(p) + :where(p) {
	margin-block-start: var(--wp--custom--spacing--12);
}

:root
	:where(.is-layout-flow, .is-layout-constrained)
	> :where(:not(.is-style-type-style-subheading))
	+ :where(h1, h2, h3, h4, h5, h6) {
	margin-block-start: var(--wp--preset--spacing--50);
}

:root :where(.is-layout-flow, .is-layout-constrained) > :where(h4, h5, h6) + * {
	margin-block-start: var(--wp--custom--spacing--12);
}

:root :where(.is-layout-flow, .is-layout-constrained) > :where(h2, h3) + * {
	margin-block-start: var(--wp--preset--spacing--20);
}

:root :where(.is-layout-flow, .is-layout-constrained) > :where(h1) + * {
	margin-block-start: var(--wp--preset--spacing--30);
}

:root
	:where(.is-layout-flow, .is-layout-constrained)
	> :where(.is-style-type-style-small, .is-style-type-style-body-large)
	+ * {
	margin-block-start: var(--wp--custom--spacing--12);
}

:root
	:where(.is-layout-flow, .is-layout-constrained)
	> :where(.is-style-type-style-large, .is-style-type-style-medium)
	+ * {
	margin-block-start: var(--wp--preset--spacing--20);
}

:root
	:where(.is-layout-flow, .is-layout-constrained)
	> :where(.is-style-type-style-extra-large)
	+ * {
	margin-block-start: var(--wp--preset--spacing--30);
}

:root
	:where(.is-layout-flow, .is-layout-constrained)
	> :where(.is-style-type-style-display)
	+ * {
	margin-block-start: var(--wp--preset--spacing--50);
}

:root :where(.is-layout-flow, .is-layout-constrained) > * + :where(.wp-block-separator),
:root :where(.is-layout-flow, .is-layout-constrained) > :where(.wp-block-separator) + * {
	margin-block-start: var(--wp--preset--spacing--50);
}

/* List items sit 12px apart. */
:root :where(.wp-block-list) > :where(li + li) {
	margin-block-start: var(--wp--custom--spacing--12);
}
