/**
 * Wiscohana Evolution E02: reusable Story reading system.
 *
 * Shared native typography, rhythm, reading rails, and section boundaries.
 */

body.wiscohana-blocksy-shell .wiscohana-story {
	--wiscohana-story-reading-width: var(--wiscohana-width-story-standard, 50rem);
	--wiscohana-story-body-size: clamp(1.125rem, 1.105rem + 0.1vw, 1.1875rem);
	--wiscohana-story-body-leading: 1.65;
	--wiscohana-story-h2-size: clamp(1.875rem, 1.68rem + 0.8vw, 2.625rem);
	--wiscohana-story-h3-size: clamp(1.375rem, 1.25rem + 0.45vw, 1.6875rem);
	--wiscohana-story-section-gap: var(--wiscohana-space-7, 3rem);
	--wiscohana-story-section-gap-after-media: var(--wiscohana-space-8, 4rem);
	--wiscohana-story-section-gap-after-captioned-media: var(--wiscohana-space-7, 3rem);
	--wiscohana-story-heading-gap: var(--wiscohana-space-4, 1rem);
	--wiscohana-story-subheading-gap: var(--wiscohana-space-7, 3rem);
	--wiscohana-story-flow-gap: var(--wiscohana-space-5, 1.5rem);
	--wiscohana-story-separator-width: 12rem;
	--wiscohana-story-separator-color: var(--wiscohana-rule, #d8d0c3);
	font-size: var(--wiscohana-story-body-size);
	line-height: var(--wiscohana-story-body-leading);
}

/* Native narrative containers consume the centralized Standard Reading Rail.
 * The optional semantic modifier selects the Narrow Reading Rail without an
 * arbitrary per-block measurement or an E02 editor control. */
body.wiscohana-blocksy-shell .wiscohana-story :is(
	.wiscohana-narrative,
	.wiscohana-feature-section:not(:has(> .wiscohana-feature-lede))
) {
	width: min(
		calc(100% - (2 * var(--wiscohana-edge))),
		var(--wiscohana-story-reading-width)
	);
	max-width: var(--wiscohana-story-reading-width);
	margin-inline: auto;
	--wp--style--global--content-size: var(--wiscohana-story-reading-width);
}

body.wiscohana-blocksy-shell .wiscohana-story :is(
	.wiscohana-narrative,
	.wiscohana-feature-section:not(:has(> .wiscohana-feature-lede))
).is-style-wiscohana-narrow-reading-rail {
	--wiscohana-story-reading-width: var(--wiscohana-width-story-narrow, 42rem);
}

body.wiscohana-blocksy-shell .wiscohana-about-narrative > p:not(:first-child) {
	width: min(100%, var(--wiscohana-width-story-standard, 50rem));
	max-width: var(--wiscohana-width-story-standard, 50rem);
	margin-inline: auto;
}

body.wiscohana-blocksy-shell .wiscohana-story .wiscohana-narrative :is(p, li) {
	font-family: var(--wiscohana-font-body);
	font-size: inherit !important;
	line-height: inherit;
}

/* H1, ledes, captions, panels, and Story-ending components retain their own
 * roles. These rules address only semantic in-Story H2 and H3 hierarchy. */
body.wiscohana-blocksy-shell .wiscohana-story h2:not(.wiscohana-feature-title) {
	font-size: var(--wiscohana-story-h2-size) !important;
	font-weight: 600;
	letter-spacing: -0.025em !important;
	line-height: 1.12 !important;
}

body.wiscohana-blocksy-shell .wiscohana-story h3:not(.wiscohana-feature-title) {
	font-size: var(--wiscohana-story-h3-size) !important;
	font-weight: 600;
	letter-spacing: -0.018em !important;
	line-height: 1.18 !important;
}

/* One margin owns each heading-to-content relationship. This removes the
 * duplicated heading margin plus first-child block margin found in scaffolds. */
body.wiscohana-blocksy-shell .wiscohana-story h2:not(.wiscohana-feature-title) {
	margin-block-end: var(--wiscohana-story-heading-gap) !important;
}

body.wiscohana-blocksy-shell .wiscohana-story h3:not(.wiscohana-feature-title) {
	margin-block-start: var(--wiscohana-story-subheading-gap) !important;
	margin-block-end: var(--wiscohana-space-3, 0.75rem) !important;
}

body.wiscohana-blocksy-shell .wiscohana-story :is(h2, h3) + * {
	margin-block-start: 0 !important;
}

body.wiscohana-blocksy-shell .wiscohana-story .wiscohana-narrative
	> :is(p, ul, ol) + :is(p, ul, ol) {
	margin-block-start: var(--wiscohana-story-flow-gap);
}

/* Routine section changes are distinct without theatrical empty space. Media
 * followed by a section keeps the larger pause because the visual mode changed. */
body.wiscohana-blocksy-shell .wiscohana-story > .wiscohana-narrative {
	margin-block-start: var(--wiscohana-story-section-gap);
}

body.wiscohana-blocksy-shell .wiscohana-story
	> .wiscohana-narrative + .wiscohana-narrative {
	margin-block-start: var(--wiscohana-story-section-gap);
}

body.wiscohana-blocksy-shell .wiscohana-story > :is(
	.wp-block-image,
	.wp-block-gallery
) + .wiscohana-narrative {
	margin-block-start: var(--wiscohana-story-section-gap-after-media);
}

/* A caption belongs to its photograph. Start the next section after the full
 * media/caption unit with one quieter pause; uncaptioned media keeps the
 * stronger transition above. */
body.wiscohana-blocksy-shell .wiscohana-story > :is(
	.wp-block-image,
	.wp-block-gallery
):has(figcaption) + .wiscohana-narrative {
	margin-block-start: var(--wiscohana-story-section-gap-after-captioned-media);
}

/* A section container owns its boundary rule. Heading pseudo-elements from
 * transitional implementations are disabled so semantics and decoration are
 * no longer coupled. */
body.wiscohana-blocksy-shell .wiscohana-story :is(
	.wiscohana-feature-section,
	.wiscohana-narrative
) > h2::before,
body.wiscohana-blocksy-shell .wiscohana-story :is(
	.wiscohana-feature-section,
	.wiscohana-narrative
) > h2::after {
	display: none !important;
	content: none !important;
}

body.wiscohana-blocksy-shell .wiscohana-story .wiscohana-feature-section::before,
body.wiscohana-blocksy-shell .wiscohana-story .wiscohana-narrative:has(> h2)::before {
	display: block;
	width: var(--wiscohana-story-separator-width);
	max-width: 30%;
	margin: 0 auto var(--wiscohana-space-5, 1.5rem);
	border: 0;
	border-block-start: 1px solid var(--wiscohana-story-separator-color);
	content: "";
}

@media (max-width: 43.75rem) {
	body.wiscohana-blocksy-shell .wiscohana-story {
		--wiscohana-story-h2-size: clamp(1.75rem, 1.68rem + 0.35vw, 1.875rem);
		--wiscohana-story-h3-size: clamp(1.375rem, 1.32rem + 0.28vw, 1.5rem);
		--wiscohana-story-section-gap: var(--wiscohana-space-6, 2rem);
		--wiscohana-story-section-gap-after-media: var(--wiscohana-space-7, 3rem);
		--wiscohana-story-section-gap-after-captioned-media: var(--wiscohana-space-6, 2rem);
		--wiscohana-story-subheading-gap: var(--wiscohana-space-6, 2rem);
	}
}

/* Captioned media followed by continuing prose is not a section boundary.
 * Consolidated from Narrows' two Orderville continuation rules; their 2rem
 * computed spacing is preserved. Heading/section transitions above are unchanged. */
body.wiscohana-blocksy-shell :is(.wiscohana-story, .wiscohana-about) {
	--wiscohana-editorial-continuation-gap: var(--wiscohana-space-6, 2rem);
}
body.wiscohana-blocksy-shell .wiscohana-about-narrative > .wp-block-image:has(figcaption) + p {
	margin-block-start: var(--wiscohana-editorial-continuation-gap);
}
