:root {
	--sofia-page-bg: #ffffff;
	--sofia-navbar-border: #d0d0d0;
	--sofia-nav-text: #2c2c2c;
	--sofia-page-inline-pad: clamp(6px, 1.25vw, 10px);
	/*
	 * Lulu interior PDF guidance (screen approximation):
	 * https://help.lulu.com/en/support/solutions/articles/64000255519
	 * — 0.50 in safety margin from trim; 0.20 in minimum gutter on binding edge.
	 */
	--lulu-safety-margin: clamp(0.75rem, 5vw, 0.5in);
	--lulu-gutter-margin: clamp(0.2rem, 2vw, 0.2in);
	/* Interior margin guides (double rule, book-spread feel). */
	--book-margin-rule: rgba(44, 44, 44, 0.17);
	--book-margin-rule-soft: rgba(44, 44, 44, 0.09);
	--book-margin-highlight: rgba(255, 255, 255, 0.55);
	--sofia-header-height: 4.5rem;
	/* Book reader: reserved band for prev/next footer (`BookPageLayout` padding + nav row). */
	--sofia-book-footer-band: 5.5rem;
	/* Uniform square thumbnails for book covers (home + book page). */
	--book-cover-size: clamp(10rem, 26vw, 17.5rem);
	--sofia-content-font:
		'Century Schoolbook', 'Century Schoolbook L', 'Century Schoolbook FS', ui-serif, Georgia,
		'Times New Roman', serif;
	/* Corner icons (`story-spread-story__corner`); also pads title bar + footer with spread. */
	--story-corner-inset-x: clamp(0.08rem, 0.55vmin, 0.3rem);
	--story-corner-inset-y: clamp(0.65rem, 2.75vmin, 1.15rem);
	/* Spread column corner art (all four corners; size tuned in `.story-spread-story__corner`). */
	--story-corner-icon-sm: clamp(2.75rem, 12vmin, 4.75rem);
	--story-corner-icon-lg: clamp(3.35rem, 15vmin, 5.75rem);
}

body {
	background: var(--sofia-page-bg);
}

main {
	font-family: var(--sofia-content-font);
}

.sofia-navbar {
	background: #ffffff;
	border-bottom: 1px solid var(--sofia-navbar-border);
}

.sofia-navbar-inner {
	width: 100%;
	max-width: none;
	margin: 0;
	padding-inline: var(--sofia-page-inline-pad);
	box-sizing: border-box;
}

.sofia-navbar .navbar-brand {
	color: var(--sofia-nav-text);
	letter-spacing: -0.02em;
	font-size: 1.05rem;
	text-decoration: none;
}

.sofia-navbar .navbar-brand:hover {
	color: #000;
}

.sofia-content-tabs {
	row-gap: 0.35rem;
}

.sofia-content-tabs .nav-link {
	color: var(--sofia-nav-text);
	font-weight: 500;
	font-size: 0.9375rem;
	padding: 0.45rem 0.95rem;
	border-radius: 8px;
	border: 1px solid transparent;
	white-space: nowrap;
}

.sofia-content-tabs .nav-link:hover,
.sofia-content-tabs .nav-link:focus {
	color: #111;
	background-color: rgba(0, 0, 0, 0.05);
}

.sofia-content-tabs .nav-link.active {
	color: #111;
	background-color: #ebebed;
	border-color: #d5d5d7;
}

@media (max-width: 767.98px) {
	.sofia-navbar .navbar-brand {
		font-size: 0.92rem;
		max-width: 55%;
	}

	.sofia-navbar-site-nav .sofia-content-tabs .nav-link {
		font-size: 0.8125rem;
		padding: 0.32rem 0.55rem;
	}
}

.page-main {
	min-height: calc(100vh - 56px);
}

/* Home (`index.astro`): fixed site header + content clears it; mobile = 2-col story grid. */
body.page-home .sofia-navbar {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	z-index: 1030;
	background: var(--sofia-page-bg);
}

body.page-home .page-main.page-main--home {
	padding-top: calc(var(--sofia-header-height) + env(safe-area-inset-top, 0px) + 0.75rem);
	padding-bottom: clamp(1.5rem, 5vw, 2.5rem);
	min-height: 100dvh;
	box-sizing: border-box;
}

@media (min-width: 768px) {
	body.page-home .page-main.page-main--home {
		padding-top: calc(var(--sofia-header-height) + 1rem);
	}
}

/* Home (`index.astro`): mobile = 2-column grid (row-major); md+ = wrapped row. */
.page-main--home {
	display: flex;
	flex-direction: column;
	align-items: stretch;
	box-sizing: border-box;
}

@media (min-width: 768px) {
	.page-main--home {
		justify-content: center;
	}
}

.home-intro {
	max-width: min(100%, 72rem);
	width: 100%;
}

.home-select-heading {
	color: var(--sofia-nav-text);
}

.home-books {
	display: flex;
	flex-direction: column;
	align-items: stretch;
	width: 100%;
	margin-top: clamp(1.25rem, 4vw, 1.75rem);
}

.home-books-list {
	/*
	 * Mobile: two fixed vertical columns. Items fill row-wise (1 left, 2 right, 3 left, 4 right…).
	 * Odd count: last item stays in column 1; column 2 cell is empty — never merge columns.
	 * `justify-items: center`: each cover is centered horizontally in its column.
	 */
	display: grid;
	grid-template-columns: repeat(2, minmax(0, 1fr));
	grid-auto-flow: row;
	justify-items: center;
	align-items: start;
	/* Row gap; column gap (mobile grid overridden below; md+ list becomes flex). */
	gap: clamp(0.85rem, 3.5vw, 1.5rem) 12px;
	width: 100%;
}

@media (min-width: 768px) {
	.home-books-list {
		display: flex;
		flex-direction: row;
		flex-wrap: wrap;
		justify-content: center;
		align-items: flex-start;
		gap: clamp(1.25rem, 4.5vw, 2rem);
	}
}

@media (max-width: 767.98px) {
	.page-main--home {
		min-height: auto;
	}

	.home-books {
		margin-top: clamp(1.5rem, 5vw, 2rem);
	}

	/*
	 * Home grid: full column width made covers huge (5 tiles × 2 cols → tall stack, page scroll).
	 * Cap size with vmin (below ~half-width) so tiles stay readable without dominating the viewport.
	 */
	body.page-home {
		--home-book-cover-size: clamp(6.75rem, 36vmin, 10rem);
		/* Same spacing between columns as between rows (mobile book grid). */
		--home-books-gap: clamp(0.6rem, 2.5vmin, 0.9rem);
	}
}

.home-book-link {
	display: block;
	width: var(--book-cover-size);
	aspect-ratio: 1;
	flex-shrink: 0;
	overflow: hidden;
	text-decoration: none;
	color: inherit;
	border-radius: 12px;
	border: 1px solid var(--sofia-navbar-border);
	background: #fff;
	cursor: pointer;
	/* No hover/focus border change: PNG alpha + repaint = visible “degrading” on some GPUs. */
	isolation: isolate;
}

@media (max-width: 767.98px) {
	/*
	 * `1fr` + centered tiles left empty space in each column, so the gap *between* covers looked
	 * wider than `row-gap`. Shrink columns to tile width so `gap` is the real horizontal spacing.
	 */
	body.page-home .home-books-list {
		grid-template-columns: repeat(2, auto);
		justify-content: center;
		justify-items: stretch;
		gap: var(--home-books-gap);
	}

	body.page-home .home-book-link {
		width: var(--home-book-cover-size);
		max-width: var(--home-book-cover-size);
	}
}

.home-book-link:focus-visible {
	outline: 2px solid #7c7c8a;
	outline-offset: 3px;
}

.home-book-cover {
	width: 100%;
	height: 100%;
	display: block;
	object-fit: cover;
	object-position: center;
	border-radius: inherit;
	border: none;
	background: #fff;
}

.book-page-cover-wrap {
	width: min(100%, var(--book-cover-size));
	aspect-ratio: 1;
	margin-inline: auto;
	overflow: hidden;
	border-radius: 12px;
	border: 1px solid var(--sofia-navbar-border);
	background: #fff;
}

.book-page-cover {
	width: 100%;
	height: 100%;
	display: block;
	object-fit: cover;
	object-position: center;
}

/*
 * Book reader (`body.book-reading`): site nav + `<main>` fit one viewport — no vertical page scroll.
 * Middle (`book-page-spread-slot`) flexes between title bar and footer.
 */
body.book-reading {
	margin: 0;
	min-height: 100dvh;
	max-height: 100dvh;
	height: 100dvh;
	overflow: hidden;
	display: flex;
	flex-direction: column;
	box-sizing: border-box;
	padding-bottom: env(safe-area-inset-bottom, 0);
	/* Full-bleed reading column; Lulu PDF margins are not applied on screen. */
	--lulu-safety-margin: 0;
	--lulu-gutter-margin: 0;
}

body.book-reading .sofia-navbar {
	flex: 0 0 auto;
	position: relative;
	z-index: 1020;
	background: var(--sofia-page-bg);
}

body.book-reading main.book-page-shell {
	position: relative;
	flex: 1 1 auto;
	min-height: 0;
	max-height: none;
	overflow: hidden;
}

/* Reading layout: title bar + spread slot + footer (`BookPageLayout.astro`). */
.book-page-shell {
	display: flex;
	flex-direction: column;
	flex: 1 1 auto;
	min-height: 0;
	width: 100%;
	max-width: 100%;
	margin: 0;
	padding: 0;
	box-sizing: border-box;
	overflow: hidden;
}

.book-page-title-bar {
	flex: 0 0 auto;
	width: 100%;
	box-sizing: border-box;
	padding-block: 0.75rem 1rem;
	padding-left: calc(env(safe-area-inset-left, 0px) + var(--story-corner-inset-x));
	padding-right: calc(env(safe-area-inset-right, 0px) + var(--story-corner-inset-x));
	border-bottom: 1px solid var(--sofia-navbar-border);
	background: var(--sofia-page-bg);
}

.book-page-title-bar__inner {
	position: relative;
	display: flex;
	align-items: center;
	justify-content: center;
	min-height: 2.5rem;
}

.book-page-title-bar__inner--has-youtube .book-page-title {
	padding-inline-end: 2.75rem;
}

.book-page-title {
	text-align: center;
	width: 100%;
	margin: 0;
}

.book-page-title-bar__youtube {
	position: absolute;
	/* Match `.story-spread-story__corner--tr` (inset from column edge, not only the shell padding). */
	right: var(--story-corner-inset-x);
	top: 50%;
	transform: translateY(-50%);
}

.book-page-youtube-link {
	display: flex;
	line-height: 0;
	opacity: 0.92;
}

.book-page-youtube-link:hover,
.book-page-youtube-link:focus-visible {
	opacity: 1;
}

.book-page-youtube-link:focus-visible {
	outline: 2px solid #7c7c8a;
	outline-offset: 3px;
	border-radius: 4px;
}

.book-page-youtube-icon {
	display: block;
	width: 28px;
	height: 28px;
}

.book-page-spread-slot {
	flex: 1 1 auto;
	min-height: 0;
	min-width: 0;
	width: 100%;
	position: relative;
	display: flex;
	flex-direction: column;
	padding-left: calc(env(safe-area-inset-left, 0px) + var(--story-corner-inset-x));
	padding-right: calc(env(safe-area-inset-right, 0px) + var(--story-corner-inset-x));
	box-sizing: border-box;
}

/* Direct children (e.g. full spread) fill the slot between title and footer bars. */
.book-page-spread-slot > * {
	flex: 1 1 auto;
	min-height: 0;
	width: 100%;
	box-sizing: border-box;
}

/* Story page-type shells (`src/components/story/`). */
.story-page-type-root {
	flex: 1 1 auto;
	min-height: 0;
	width: 100%;
	height: 100%;
	display: flex;
	flex-direction: column;
	box-sizing: border-box;
}

.story-page-type-root .story-simple-stack,
.story-page-type-root .story-spread {
	flex: 1 1 auto;
	min-height: 0;
}

.story-simple-stack,
.story-spread {
	width: 100%;
	height: 100%;
	min-height: 0;
	box-sizing: border-box;
}

/*
 * Cover / intro / end: vertical bands of the story slot — 10% top / 70% image / 10% text / 10% bottom.
 */
.story-simple-stack {
	display: flex;
	flex-direction: column;
	align-items: stretch;
	height: 100%;
	min-height: 0;
	gap: 0;
}

.story-simple-stack__spacer {
	flex: 0 0 10%;
	min-height: 0;
	flex-shrink: 0;
}

.story-simple-stack .story-slot {
	min-height: 0;
}

.story-spread {
	display: flex;
	flex-direction: column;
	gap: 0;
	align-items: stretch;
}

/* Book gutter: spine rule between spread columns (matches margin double-rule look on desktop). */
.story-spread-gutter {
	flex: 0 0 auto;
	margin: 0;
	padding: 0;
	pointer-events: none;
	background: var(--sofia-navbar-border);
}

@media (max-width: 767.98px) {
	/* Portrait stack: multimedia column (`story-spread-content`) ~20% shorter than 2:1; text gets the rest. */
	.story-spread {
		flex: 1 1 auto;
		min-height: 0;
	}

	.story-spread > .story-spread-content {
		flex: 12 1 0;
		min-height: 0;
		overflow: hidden;
	}

	.story-spread > .story-spread-story {
		flex: 11 1 0;
		min-height: 0;
		display: flex;
		flex-direction: column;
		align-items: stretch;
		overflow: hidden;
	}

	.story-spread-story__body {
		flex: 1 1 auto;
		min-height: 0;
		overflow-y: auto;
		-webkit-overflow-scrolling: touch;
		/* Original tight inset; slightly larger bottom margin only. */
		margin: clamp(0.2rem, 1vmin, 0.45rem) clamp(0.2rem, 1vmin, 0.45rem)
			clamp(0.35rem, 1.5vmin, 0.55rem);
	}

	.story-spread-story__icons-row {
		display: flex;
		flex-direction: row;
		flex-wrap: nowrap;
		justify-content: center;
		align-items: center;
		gap: clamp(0.45rem, 2.5vw, 1rem);
		flex: 0 0 auto;
		margin-top: clamp(0.35rem, 1.5vmin, 0.65rem);
		padding-bottom: 0.15rem;
	}

	.story-spread-story__corner {
		position: static;
		inset: auto;
		width: var(--story-corner-icon-sm);
		max-height: var(--story-corner-icon-sm);
	}

	.story-spread-story--has-corners {
		padding: clamp(0.45rem, 2vmin, 0.85rem) clamp(0.35rem, 1.5vmin, 0.65rem);
	}

	.story-spread-gutter {
		width: 100%;
		height: 1px;
		min-height: 1px;
		margin-block: clamp(0.4rem, 2vw, 0.65rem);
	}
}

@media (min-width: 768px) {
	/* Corner imgs sit in a row in the DOM; wrapper is skipped for layout. */
	.story-spread-story__icons-row {
		display: contents;
	}

	/* Explicit 50% / 50% columns (excluding fixed spine gutter). */
	.story-spread {
		display: grid;
		grid-template-columns: minmax(0, 1fr) 3px minmax(0, 1fr);
		grid-template-rows: minmax(0, 1fr);
		align-items: stretch;
		min-height: 0;
		gap: 0;
	}

	.story-spread-gutter {
		width: 100%;
		min-width: 0;
		align-self: stretch;
		background: linear-gradient(
			90deg,
			var(--book-margin-rule-soft) 0,
			var(--book-margin-rule-soft) 1px,
			var(--book-margin-highlight) 1px,
			var(--book-margin-highlight) 2px,
			var(--book-margin-rule) 2px,
			var(--book-margin-rule) 3px
		);
	}

	.story-spread > .story-spread-content,
	.story-spread > .story-spread-story {
		min-width: 0;
		min-height: 0;
	}
}

/* Story regions: no boxes or rules — same surface as the page. */
.story-slot {
	border: none;
	background: transparent;
	color: var(--sofia-nav-text);
	font-size: 0.95rem;
	display: flex;
	align-items: center;
	justify-content: center;
	text-align: center;
	min-height: 5rem;
	padding: 0.35rem 0;
	box-sizing: border-box;
}

.story-simple-stack__image {
	flex: 0 0 70%;
	min-height: 0;
	overflow: hidden;
	display: flex;
	align-items: center;
	justify-content: center;
}

.story-simple-stack__text {
	flex: 0 0 10%;
	min-height: 0;
	overflow: auto;
	justify-content: center;
}

/* Intro: taller text band so title + byline fit without scrolling; image band slightly smaller. */
.story-simple-stack--intro .story-simple-stack__image {
	flex: 0 0 62%;
}

.story-simple-stack--intro .story-simple-stack__text {
	flex: 0 0 18%;
	overflow: visible;
}

.story-simple-stack .story-simple-stack__text.story-slot {
	padding-block: 0.15rem 0.25rem;
}

.story-slot--media {
	padding: 0;
	overflow: hidden;
	display: flex;
	align-items: center;
	justify-content: center;
}

.story-simple-stack__hero-img {
	max-width: 100%;
	max-height: 100%;
	width: auto;
	height: auto;
	object-fit: contain;
	object-position: center;
}

.story-simple-stack__media {
	/* Size queries for cover / intro / end video — largest 16:9 rect that fits (like hero `object-fit: contain`). */
	container-type: size;
	width: 100%;
	height: 100%;
	min-height: 0;
	flex: 1 1 auto;
	display: flex;
	align-items: center;
	justify-content: center;
	max-height: 100%;
}

.story-simple-stack .mmedia {
	height: 100%;
	width: 100%;
	max-height: 100%;
	flex: 1 1 auto;
	min-height: 0;
}

/* Cover / intro / end: hero image and video occupy the same max box (match `.mmedia-panel` contain behavior). */
.story-simple-stack .mmedia-panel--image:not(.mmedia-panel--hidden),
.story-simple-stack .mmedia-panel--solo {
	max-height: 100%;
	max-width: 100%;
}

.story-simple-stack .mmedia-panel--glb {
	height: 100%;
	max-height: 100%;
	min-height: 0;
	width: 100%;
}

.story-simple-stack .mmedia-panel--video:not(.mmedia-panel--hidden) {
	/* Override global `min(62vh, …)` — frame matches the hero area (same containing box as `<img>`). */
	display: flex;
	align-items: center;
	justify-content: center;
	box-sizing: border-box;
	width: 100%;
	height: 100%;
	max-width: 100%;
	max-height: 100%;
	min-height: 0;
	background: transparent;
	border-radius: 0;
	overflow: visible;
}

.story-simple-stack .mmedia-panel--video:not(.mmedia-panel--hidden) .mmedia-panel__iframe {
	/* Largest 16:9 rectangle inside `story-simple-stack__media` (parallel to hero `contain`). */
	width: min(100cqw, calc(100cqh * 16 / 9));
	height: min(100cqh, calc(100cqw * 9 / 16));
	max-width: 100%;
	max-height: 100%;
	border: 0;
	border-radius: 10px;
	background: #fff;
}

/* Multi-media: hero image + optional GLB (`@google/model-viewer`). */
.mmedia {
	position: relative;
	width: 100%;
	min-height: 0;
	flex: 1 1 auto;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	overflow: hidden;
}

.mmedia-panel {
	max-width: 100%;
	object-fit: contain;
	object-position: center;
}

.mmedia-panel--image:not(.mmedia-panel--hidden) {
	max-height: min(50vh, 28rem);
	width: auto;
	height: auto;
}

.mmedia-panel--solo {
	max-height: min(50vh, 28rem);
	width: auto;
	height: auto;
}

.mmedia-panel--glb {
	width: 100%;
	min-height: 12rem;
	max-height: min(62vh, 36rem);
	height: min(62vh, 36rem);
	background: transparent;
}

/* Same footprint as `.mmedia-panel--glb` so video swaps in at identical size */
.mmedia-panel--video:not(.mmedia-panel--hidden) {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 100%;
	min-height: 12rem;
	max-height: min(62vh, 36rem);
	height: min(62vh, 36rem);
	background: #fff;
	border-radius: 10px;
	overflow: hidden;
	box-sizing: border-box;
}

.mmedia-panel__iframe {
	display: block;
	width: 100%;
	height: 100%;
	border: 0;
}

.mmedia-panel--hidden {
	display: none !important;
}

/*
 * Host for image/3D toggle (moved here by `MultiMediaContainer` script).
 * `--book-shell`: viewport-fixed above footer (`BookPageLayout`, cover/intro/end).
 * `--spread`: bottom-right of the spread content column (`SpreadContentBlock`), not the viewport.
 */
.multimedia-controller-host {
	display: flex;
	flex-direction: column;
	align-items: flex-end;
	justify-content: flex-end;
	gap: 0.35rem;
	pointer-events: none;
	box-sizing: border-box;
}

.multimedia-controller-host--book-shell {
	position: fixed;
	right: max(0.75rem, env(safe-area-inset-right));
	bottom: calc(var(--sofia-book-footer-band, 5.5rem) + 0.5rem);
	z-index: 40;
}

.multimedia-controller-host--spread {
	position: absolute;
	right: max(0.35rem, env(safe-area-inset-right));
	bottom: 0.5rem;
	top: auto;
	left: auto;
	z-index: 30;
}

.multimedia-controller-host:not(:empty) {
	pointer-events: auto;
}

.mmedia__controller {
	display: flex;
	flex-direction: column;
	flex-wrap: nowrap;
	align-items: flex-end;
	justify-content: flex-end;
	gap: 0.35rem;
	pointer-events: auto;
}

/* Fallback when controller is not moved to a host (e.g. script did not run). */
.mmedia > .mmedia__controller {
	position: absolute;
	bottom: 0.5rem;
	right: 0.5rem;
	z-index: 20;
}

.mmedia__btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 2.5rem;
	height: 2.5rem;
	min-width: 2.5rem;
	min-height: 2.5rem;
	padding: 0;
	border: 1px solid rgba(37, 37, 38, 0.28);
	border-radius: 10px;
	background: rgba(255, 255, 255, 0.96);
	box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
	cursor: pointer;
	color: var(--sofia-nav-text, #252526);
}

.mmedia__btn img {
	display: block;
	flex-shrink: 0;
}

.mmedia__btn:hover {
	background: #fff;
	border-color: rgba(37, 37, 38, 0.45);
}

.mmedia__btn--active {
	border-color: rgba(37, 99, 235, 0.65);
	box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);
}

.story-spread-content--fill {
	position: relative;
	min-height: 0;
	width: 100%;
	display: flex;
	flex-direction: column;
	align-items: stretch;
	justify-content: center;
	padding: 0;
	overflow: hidden;
}

/* Spread: fill the content column — grow with the slot; panels use that box (contain / full size). */
.story-spread-content--fill .mmedia {
	flex: 1 1 auto;
	min-height: 0;
	width: 100%;
	align-items: stretch;
}

.story-spread-content--fill .mmedia-panel--image:not(.mmedia-panel--hidden),
.story-spread-content--fill .mmedia-panel--solo {
	align-self: center;
	max-height: 100%;
	max-width: 100%;
	width: auto;
	height: auto;
	object-fit: contain;
	object-position: center;
}

.story-spread-content--fill .mmedia-panel--glb {
	flex: 1 1 auto;
	min-height: 12rem;
	width: 100%;
	height: 100%;
	max-height: none;
}

.story-spread-content--fill .mmedia-panel--video:not(.mmedia-panel--hidden) {
	flex: 1 1 auto;
	min-height: 12rem;
	width: 100%;
	height: 100%;
	max-height: none;
}

.story-slot-placeholder {
	color: rgba(44, 44, 44, 0.45);
	font-size: 0.95rem;
}

.story-slot--prose {
	justify-content: center;
}

.story-spread-story {
	position: relative;
}

.story-spread-story__body {
	position: relative;
	z-index: 0;
	width: 100%;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	min-height: 0;
	box-sizing: border-box;
}

@media (min-width: 768px) {
	.story-spread-story__body {
		/* Breathing room around the text on all sides (spread story column, desktop). */
		margin: clamp(0.5rem, 2vmin, 1rem);
	}
}

/* Optional corner icons: `pages/{n}/` or book root; `.jpg`/`.jpeg`/`.png`/`.webp` (see `storyCornerImageSrc`). */
@media (min-width: 768px) {
	.story-spread-story--has-corners {
		padding: clamp(2rem, 5vmin, 3.25rem);
	}

	.story-spread-story__corner {
		position: absolute;
		z-index: 1;
		width: var(--story-corner-icon-lg);
		height: auto;
		max-height: var(--story-corner-icon-lg);
		object-fit: contain;
		object-position: center;
		pointer-events: none;
	}

	.story-spread-story__corner--tl {
		top: var(--story-corner-inset-y);
		left: var(--story-corner-inset-x);
	}

	.story-spread-story__corner--tr {
		top: var(--story-corner-inset-y);
		right: var(--story-corner-inset-x);
	}

	.story-spread-story__corner--bl {
		bottom: var(--story-corner-inset-y);
		left: var(--story-corner-inset-x);
	}

	.story-spread-story__corner--br {
		bottom: var(--story-corner-inset-y);
		right: var(--story-corner-inset-x);
	}
}

/* Spread right column: `text.txt` (+ optional `header.txt` title line). Per-book size: inline on `__body` (`books.json` `spreadTextFontSize`). */
.story-spread-story__header {
	font-weight: 700;
	line-height: 1.35;
	text-align: center;
	color: var(--sofia-nav-text);
	white-space: pre-wrap;
	max-width: min(100%, 42rem);
	margin-inline: auto;
	width: 100%;
	padding-inline: 0;
	box-sizing: border-box;
	font-size: clamp(1.35rem, 3.1vw, 1.75rem);
	margin-bottom: 0.5rem;
}

.story-spread-story[data-book-spread-font='custom'] .story-spread-story__header {
	font-size: 1.22em;
	margin-bottom: 0.4em;
}

.story-spread-story__text {
	font-size: clamp(1.2rem, 2.85vw, 1.55rem);
	line-height: 1.85;
	word-spacing: 0.06em;
	text-align: center;
	color: var(--sofia-nav-text);
	white-space: pre-wrap;
	max-width: min(100%, 42rem);
	margin-inline: auto;
	width: 100%;
	padding-inline: 0;
	box-sizing: border-box;
}

.story-spread-story[data-book-spread-font='custom'] .story-spread-story__body .story-spread-story__text {
	font-size: inherit;
}

.story-simple-stack__text-stack {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 0.35rem;
	width: 100%;
	max-width: min(100%, 36rem);
	margin-inline: auto;
}

.story-simple-stack__title {
	margin: 0;
	font-size: clamp(1.25rem, 3.2vw, 1.65rem);
	font-weight: 600;
	line-height: 1.25;
	text-align: center;
	color: var(--sofia-nav-text);
}

.story-simple-stack__text-body {
	font-size: clamp(1.1rem, 2.5vw, 1.35rem);
	line-height: 1.45;
	text-align: center;
	color: var(--sofia-nav-text);
}

/* Intro: title + byline — byline smaller and italic (custom per-book size lives on the stack). */
.story-simple-stack__title.story-simple-stack__title--intro-inherit {
	font-size: 1em;
}

.story-simple-stack__text-stack--intro[data-intro-font='base'] .story-simple-stack__intro-byline {
	font-style: italic;
	font-size: clamp(0.92rem, 2.35vw, 1.12rem);
	line-height: 1.4;
}

.story-simple-stack__text-stack--intro[data-intro-font='custom'] .story-simple-stack__intro-byline {
	font-style: italic;
	font-size: 0.82em;
	line-height: 1.4;
}

.book-page-footer-nav {
	flex: 0 0 auto;
	width: 100%;
	box-sizing: border-box;
	margin: 0;
	padding: 0;
	border-top: 1px solid var(--sofia-navbar-border);
	background: var(--sofia-page-bg);
}

body.book-reading .book-page-footer-nav {
	min-height: var(--sofia-book-footer-band);
	box-sizing: border-box;
}

body.book-reading .story-page-type-root {
	overflow: hidden;
}

body.book-reading .story-spread {
	min-height: 0;
	overflow: hidden;
}

body.book-reading .story-spread > .story-slot {
	min-height: 0;
	overflow: hidden;
}

/* Desktop: scroll the story column. Mobile: scroll lives in `.story-spread-story__body` so the icon row stays visible. */
@media (min-width: 768px) {
	body.book-reading .story-spread > .story-spread-story.story-slot {
		overflow-y: auto;
		overflow-x: hidden;
		-webkit-overflow-scrolling: touch;
	}
}

body.book-reading .story-simple-stack {
	min-height: 0;
	overflow: hidden;
}

body.book-reading .story-simple-stack__image,
body.book-reading .story-simple-stack__text {
	min-height: 0;
}

.book-page-footer-nav__inner {
	width: 100%;
	max-width: 100%;
	box-sizing: border-box;
	padding-block: 0.75rem 1rem;
	padding-left: calc(env(safe-area-inset-left, 0px) + var(--story-corner-inset-x));
	padding-right: calc(env(safe-area-inset-right, 0px) + var(--story-corner-inset-x));
}

.book-page-footer-nav__row {
	width: 100%;
}

.book-page-nav-section {
	display: flex;
	align-items: center;
	min-height: 2.75rem;
	border: none;
	border-radius: 0;
	background: transparent;
	padding: 0.35rem 0;
	box-sizing: border-box;
}

.book-page-nav-section--prev {
	justify-content: flex-start;
	text-align: left;
}

.book-page-nav-section--next {
	justify-content: flex-end;
	text-align: right;
}

@media (min-width: 768px) {
	.book-page-footer-nav .btn.btn-sm {
		padding: 0.6rem 1.4rem;
		font-size: 1rem;
		line-height: 1.35;
		min-height: 2.875rem;
	}

	.book-page-nav-section {
		min-height: 3.25rem;
		padding-block: 0.45rem;
	}
}

@media (max-width: 767.98px) {
	body.book-reading {
		--sofia-book-footer-band: 3.5rem;
	}

	.book-page-title-bar {
		padding-block: 0.45rem 0.55rem;
	}

	.book-page-title-bar__inner {
		min-height: 2rem;
	}

	.book-page-title.h5 {
		font-size: 0.95rem;
		line-height: 1.25;
	}

	.book-page-title-bar__inner--has-youtube .book-page-title {
		padding-inline-end: 2.35rem;
	}

	.book-page-youtube-icon {
		width: 24px;
		height: 24px;
	}

	/* Tighter default on small screens; books with `spreadTextFontSize` keep their custom clamp. */
	.story-spread-story:not([data-book-spread-font='custom']) .story-spread-story__text {
		font-size: clamp(0.88rem, 3.6vw, 1.05rem);
		line-height: 1.55;
		word-spacing: 0.03em;
	}

	.story-spread-story:not([data-book-spread-font='custom']) .story-spread-story__header {
		font-size: clamp(1rem, 4vw, 1.25rem);
		line-height: 1.3;
	}

	.book-page-footer-nav__inner {
		padding-block: 0.4rem 0.5rem;
	}

	.book-page-nav-section {
		min-height: 0;
		padding: 0.2rem 0;
	}

	.book-page-nav-section .btn {
		width: 100%;
		box-sizing: border-box;
	}

	.book-page-nav-section--prev,
	.book-page-nav-section--next {
		justify-content: stretch;
		text-align: center;
	}
}

/* Spread hero: optional thumbnail grid + lightbox (`MultimediaCarousel`). */
.story-spread-content[data-mmedia-host-scope] {
	position: relative;
}

/*
 * Flush thumbnail grid on the spread (not the lightbox dialog).
 * Use an explicit class — do not rely only on :has(), so older browsers and specificity
 * never leave `.story-slot { padding: 0.35rem 0 }` in effect.
 *
 * Default `.story-slot` is `display:flex` (row) + `align-items:center` + `justify-content:center`,
 * which vertically centers a single child — bands of empty space above/below on mobile.
 * Column + flex-start + stretch lets the grid fill the media column height.
 */
.story-spread-content.story-slot.story-spread-content--flush-carousel {
	padding: 0;
	margin: 0;
	min-height: 0;
	display: flex;
	flex-direction: column;
	align-items: stretch;
	justify-content: flex-start;
	align-content: stretch;
	/* Do not set flex: here — mobile `.story-spread > .story-spread-content { flex: 12 1 0 }` must keep the image/text band ratio. */
	box-sizing: border-box;
}

.story-spread-content .multimedia-carousel {
	width: 100%;
	height: 100%;
	min-height: 0;
	flex: 1 1 auto;
	display: flex;
	flex-direction: column;
	box-sizing: border-box;
	align-self: stretch;
}

.story-spread-content .multimedia-carousel__content-header {
	flex: 0 0 auto;
	margin: 0;
	padding: clamp(0.15rem, 0.8vmin, 0.5rem) clamp(0.25rem, 1.5vw, 0.75rem) clamp(0.65rem, 2vmin, 1.1rem);
	text-align: center;
	/* Match spread story typography (book 1+): Century Schoolbook stack, same palette as `header.txt` / `text.txt`. */
	font-family: var(--sofia-content-font);
	font-size: clamp(1.65rem, 5.2vmin, 2.35rem);
	font-weight: 400;
	line-height: 1.15;
	color: var(--sofia-nav-text);
	letter-spacing: -0.02em;
}

.story-spread-content .multimedia-carousel__page {
	margin: 0;
	padding: 0;
	width: 100%;
	height: 100%;
	min-height: 0;
	flex: 1 1 auto;
	display: flex;
	flex-direction: column;
	box-sizing: border-box;
}

.story-spread-content .multimedia-carousel__page .multimedia-carousel__grid {
	display: grid;
	grid-template-columns: repeat(var(--mc-cols, 2), minmax(0, 1fr));
	grid-template-rows: repeat(2, minmax(0, 1fr));
	/* Fallback if inline gap is missing; inline styles on the grid set gap in px for reliability. */
	gap: var(--mc-gap, 0);
	row-gap: var(--mc-gap, 0);
	column-gap: var(--mc-gap, 0);
	width: 100%;
	min-height: 0;
	flex: 1 1 auto;
	align-content: stretch;
	margin: 0;
	padding: 0;
	box-sizing: border-box;
}

/* Outer breathing room when `margin` > 0 (JSON); book4 margin 0 stays flush. */
.story-spread-content .multimedia-carousel__page .multimedia-carousel__grid--gapped {
	padding: clamp(10px, 2.5vmin, 22px);
}

.story-spread-content .multimedia-carousel__page .multimedia-carousel__cell {
	/* Grid tile: optional caption stack below image (grid thumbnails only; modal has image only). */
	display: grid;
	place-items: stretch;
	min-height: 0;
	min-width: 0;
	padding: 0;
	margin: 0;
	border: none;
	background: transparent;
	cursor: pointer;
	overflow: hidden;
	border-radius: 0;
}

.story-spread-content .multimedia-carousel__page .multimedia-carousel__cell-stack {
	display: flex;
	flex-direction: column;
	align-items: stretch;
	justify-content: flex-start;
	min-height: 0;
	min-width: 0;
	width: 100%;
	height: 100%;
}

.story-spread-content .multimedia-carousel__page .multimedia-carousel__thumb-wrap {
	flex: 1 1 0;
	min-height: 0;
	min-width: 0;
	display: grid;
	place-items: stretch;
	overflow: hidden;
}

.story-spread-content .multimedia-carousel__page .multimedia-carousel__cell--captioned .multimedia-carousel__thumb-wrap {
	/* Leave vertical room for the caption line(s). */
	flex: 1 1 auto;
	/* Inset so photos read smaller with white space inside the tile. */
	padding: clamp(6px, 1.8vmin, 16px);
	box-sizing: border-box;
	align-content: center;
	justify-content: center;
	place-items: center;
	background: #fff;
}

.story-spread-content .multimedia-carousel__page .multimedia-carousel__caption {
	flex: 0 0 auto;
	display: block;
	padding: 0.35rem 0.25rem 0;
	margin: 0;
	text-align: center;
	font-family: var(--sofia-content-font);
	font-size: clamp(1.05rem, 3.6vmin, 1.45rem);
	line-height: 1.25;
	font-weight: 400;
	color: var(--sofia-nav-text);
}

.story-spread-content .multimedia-carousel__page .multimedia-carousel__cell:focus-visible {
	outline: 2px solid rgba(44, 44, 44, 0.45);
	outline-offset: 2px;
}

.story-spread-content .multimedia-carousel__page .multimedia-carousel__thumb {
	display: block;
	width: 100%;
	height: 100%;
	min-height: 0;
	min-width: 0;
	object-fit: cover;
	object-position: center;
}

/* Captioned grid tiles: show full image smaller with padding (not full-bleed crop). */
.story-spread-content .multimedia-carousel__page .multimedia-carousel__cell--captioned .multimedia-carousel__thumb {
	width: auto;
	height: auto;
	max-width: 100%;
	max-height: 100%;
	object-fit: contain;
}

/* Mobile: fill the image band — flex chain must consume the ~12/(12+11) column height (no vertical “gutters” inside). */
@media (max-width: 767.98px) {
	body.book-reading .story-spread-content.story-slot.story-spread-content--flush-carousel .multimedia-carousel,
	body.book-reading .story-spread-content.story-slot.story-spread-content--flush-carousel .multimedia-carousel__page,
	body.book-reading .story-spread-content.story-slot.story-spread-content--flush-carousel .multimedia-carousel__page .multimedia-carousel__grid {
		flex: 1 1 0;
		min-height: 0;
	}

	/* Book 5: JSON `margin` is desktop grid gap + outer padding — use full width on small screens. */
	body.book-reading .story-spread-content[data-book-id='book5'] .multimedia-carousel {
		--mc-gap: 0 !important;
	}

	body.book-reading .story-spread-content[data-book-id='book5'] .multimedia-carousel__page .multimedia-carousel__grid--gapped {
		padding: 0;
	}

	body.book-reading .story-spread-content[data-book-id='book5'] .multimedia-carousel__content-header {
		padding-inline: 0;
	}
}

.multimedia-carousel__dialog {
	padding: 0;
	border: none;
	border-radius: 12px;
	max-width: min(96vw, 960px);
	width: 100%;
	background: #fff;
	box-shadow: 0 12px 40px rgba(0, 0, 0, 0.2);
}

.multimedia-carousel__dialog::backdrop {
	background: rgba(0, 0, 0, 0.45);
}

.multimedia-carousel__dialog-surface {
	position: relative;
	display: flex;
	align-items: center;
	justify-content: center;
	min-height: min(72vh, 36rem);
	padding: 2.75rem 3.25rem;
	box-sizing: border-box;
}

.multimedia-carousel__dialog-close {
	position: absolute;
	top: 0.5rem;
	right: 0.5rem;
	z-index: 5;
	line-height: 1;
	padding: 0.15rem 0.55rem;
	font-size: 1.35rem;
}

.multimedia-carousel__nav {
	position: absolute;
	top: 50%;
	transform: translateY(-50%);
	z-index: 5;
	line-height: 1;
	padding: 0.35rem 0.65rem;
	font-size: 1.75rem;
	min-width: 2.5rem;
}

.multimedia-carousel__nav--prev {
	left: 0.45rem;
}

.multimedia-carousel__nav--next {
	right: 0.45rem;
}

.multimedia-carousel__dialog-stage {
	position: relative;
	width: 100%;
	min-height: min(58vh, 32rem);
	display: flex;
	align-items: center;
	justify-content: center;
}

.multimedia-carousel__slide {
	width: 100%;
	min-height: 0;
}

.multimedia-carousel__slide[hidden] {
	display: none !important;
}

.multimedia-carousel__slide-scope {
	position: relative;
	width: 100%;
	min-height: min(58vh, 32rem);
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
}

.multimedia-carousel__slide-scope .mmedia {
	max-height: min(62vh, 36rem);
}

/*
 * Carousel lightbox: spread-hero rules cap images at ~50vh / 28rem — fine in-column, but clips in the modal on desktop.
 * Let the image use the dialog (contain), not the hero thumbnail budget.
 */
.multimedia-carousel__dialog .multimedia-carousel__slide-scope .mmedia {
	max-height: none;
	overflow: visible;
}

.multimedia-carousel__dialog .multimedia-carousel__slide-scope .mmedia-panel--image:not(.mmedia-panel--hidden),
.multimedia-carousel__dialog .multimedia-carousel__slide-scope .mmedia-panel--solo {
	max-height: min(85vh, calc(100dvh - 7rem));
	max-width: 100%;
	width: auto;
	height: auto;
}

/*
 * Lightbox: global `.mmedia-panel--image { max-height: min(50vh, 28rem) }` is for spread heroes.
 * Dialog wrappers also used huge `min-height` (~58–72vh) while the image stayed capped — white bands.
 * On narrow screens, shrink padding/min-heights and let the image use most of the viewport height.
 */
@media (max-width: 767.98px) {
	.multimedia-carousel__dialog {
		max-height: 95dvh;
		width: min(100vw - 0.5rem, 100%);
		margin: auto;
	}

	.multimedia-carousel__dialog-surface {
		min-height: 0;
		padding: 2.75rem 0.35rem 0.5rem;
		align-items: stretch;
		box-sizing: border-box;
	}

	.multimedia-carousel__dialog-stage {
		min-height: 0;
		width: 100%;
		align-items: stretch;
		justify-content: center;
	}

	.multimedia-carousel__slide-scope {
		min-height: 0;
		max-height: calc(95dvh - 3.25rem);
		width: 100%;
		justify-content: center;
		align-items: center;
		box-sizing: border-box;
	}

	.multimedia-carousel__slide-scope .mmedia {
		max-height: none;
		width: 100%;
		flex: 0 1 auto;
		min-height: 0;
	}

	.multimedia-carousel__dialog .multimedia-carousel__slide-scope .mmedia-panel--image:not(.mmedia-panel--hidden),
	.multimedia-carousel__dialog .multimedia-carousel__slide-scope .mmedia-panel--solo {
		max-height: min(88dvh, calc(95dvh - 3.5rem));
		max-width: 100%;
		width: auto;
		height: auto;
	}

	/* Prev/next: strong contrast on top of artwork (Bootstrap outline was too faint on photos). */
	.multimedia-carousel__dialog button.multimedia-carousel__nav {
		z-index: 20;
		min-width: 2.85rem;
		min-height: 2.85rem;
		padding: 0;
		display: inline-flex;
		align-items: center;
		justify-content: center;
		font-size: 1.85rem;
		font-weight: 600;
		line-height: 1;
		border-radius: 999px;
		background: rgba(22, 22, 26, 0.78);
		color: #fff;
		border: 1px solid rgba(255, 255, 255, 0.35);
		box-shadow: 0 2px 12px rgba(0, 0, 0, 0.45);
		backdrop-filter: blur(8px);
		-webkit-backdrop-filter: blur(8px);
	}

	.multimedia-carousel__dialog button.multimedia-carousel__nav:hover,
	.multimedia-carousel__dialog button.multimedia-carousel__nav:focus-visible {
		background: rgba(22, 22, 26, 0.92);
		color: #fff;
		border-color: rgba(255, 255, 255, 0.5);
	}

	.multimedia-carousel__dialog .multimedia-carousel__nav--prev {
		left: max(0.35rem, env(safe-area-inset-left));
	}

	.multimedia-carousel__dialog .multimedia-carousel__nav--next {
		right: max(0.35rem, env(safe-area-inset-right));
	}
}

.multimedia-controller-host--carousel-modal {
	position: absolute;
	right: max(0.35rem, env(safe-area-inset-right));
	bottom: 0.5rem;
	z-index: 30;
	pointer-events: none;
}

.multimedia-controller-host--carousel-modal:not(:empty) {
	pointer-events: auto;
}
