/*
 * Dancestors Flipbook: the reader.
 * Every rule is scoped to .dfb (and the plugin's own dfb- classes). To restyle, override the
 * custom properties below on .dfb in your theme, for example:  .dfb { --dfb-accent: #6b2d5c; }
 */

.dfb {
	--dfb-accent: #214b55;
	--dfb-toolbar-bg: #ffffff;
	--dfb-toolbar-text: #263a40;
	--dfb-toolbar-border: rgba(38, 58, 64, 0.16);
	--dfb-paper: #ffffff;
	--dfb-page-shadow: 0 2px 6px rgba(0, 0, 0, 0.12), 0 10px 28px rgba(0, 0, 0, 0.16);
	--dfb-full-bg: #1f272a;
	--dfb-radius: 999px;
	--dfb-font: inherit;

	position: relative;
	box-sizing: border-box;
	width: 100%;
	max-width: 100%;
	margin: 1.5em 0;
	font-family: var(--dfb-font);
	line-height: 1.4;
}

.dfb *,
.dfb *::before,
.dfb *::after {
	box-sizing: border-box;
}

/* ------------------------------------------------------------ book area */

.dfb-stage {
	position: relative;
	display: flex;
	align-items: center;
	justify-content: center;
	min-height: min(70vh, 520px);
	padding: 12px 8px 16px;
	/* Clip sideways (no horizontal scrolling; the closed book slides half a page), but let a page
	   being turned lift above or below the book like real paper. Older browsers without "clip"
	   keep "hidden". */
	overflow: hidden;
	overflow: clip visible;
	outline: none;
	border-radius: 6px;
}

.dfb.is-ready .dfb-stage {
	min-height: 0;
}

.dfb-stage:focus-visible {
	outline: 3px solid var(--dfb-accent);
	outline-offset: -3px;
}

.dfb-stage.is-pointer-focus:focus-visible {
	outline: none;
}

/* Wraps the book; flipbook.js glides it between sizes when the mouse wheel enlarges the book. */
.dfb-zoomer {
	flex: none;
	transform-origin: 0 0;
}

.dfb-book {
	position: relative;
	flex: none;
	transition: transform 0.45s ease;
}

.dfb:not(.is-ready) .dfb-book {
	display: none;
}

/* StPageFlip's own stylesheet names this ".sft__wrapper" (a typo), so give the wrapper its size here. */
.dfb .stf__wrapper {
	position: relative;
	width: 100%;
	height: 100%;
}

.dfb-page {
	background: var(--dfb-paper);
	box-shadow: var(--dfb-page-shadow);
	overflow: hidden;
	user-select: none;
	-webkit-user-select: none;
}

.dfb-sheet {
	position: absolute;
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
}

.dfb-page-img {
	display: block;
	width: 100%;
	height: 100%;
	max-width: none;
	margin: 0;
	border: 0;
	object-fit: contain;
	pointer-events: none;
	-webkit-user-drag: none;
}

.dfb-page-img:not([src]) {
	visibility: hidden;
}

/* A soft fold shadow along the spine, in two-page view only. */
.dfb.is-spread .dfb-page.--left .dfb-sheet::after,
.dfb.is-spread .dfb-page.--right .dfb-sheet::after {
	content: "";
	position: absolute;
	top: 0;
	bottom: 0;
	width: 8%;
	pointer-events: none;
}

.dfb.is-spread .dfb-page.--left .dfb-sheet::after {
	right: 0;
	background: linear-gradient(to left, rgba(0, 0, 0, 0.14), rgba(0, 0, 0, 0));
}

.dfb.is-spread .dfb-page.--right .dfb-sheet::after {
	left: 0;
	background: linear-gradient(to right, rgba(0, 0, 0, 0.14), rgba(0, 0, 0, 0));
}

/* A page still being drawn: a small spinner on blank paper. */
.dfb-page:not(.is-ready):not(.is-failed) .dfb-sheet::before {
	content: "";
	position: absolute;
	top: calc(50% - 14px);
	left: calc(50% - 14px);
	width: 28px;
	height: 28px;
	border: 3px solid rgba(38, 58, 64, 0.15);
	border-top-color: var(--dfb-accent);
	border-radius: 50%;
	animation: dfb-spin 0.9s linear infinite;
}

.dfb-page-error {
	position: absolute;
	inset: auto 10% 45%;
	margin: 0;
	color: #8a2b2b;
	font-size: 14px;
	text-align: center;
}

/* ------------------------------------------------------------ notices */

.dfb-notice {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 10px;
	max-width: 32em;
	padding: 24px;
	text-align: center;
	color: var(--dfb-toolbar-text);
	background: var(--dfb-toolbar-bg);
	border: 1px solid var(--dfb-toolbar-border);
	border-radius: 8px;
	box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
}

.dfb-notice[hidden] {
	display: none;
}

.dfb-notice p {
	margin: 0;
}

.dfb-notice a {
	color: var(--dfb-accent);
	text-decoration: underline;
}

.dfb-notice.is-error .dfb-spinner {
	display: none;
}

.dfb-notice.is-error .dfb-notice-text {
	font-weight: 600;
}

.dfb-spinner {
	width: 32px;
	height: 32px;
	border: 3px solid rgba(38, 58, 64, 0.15);
	border-top-color: var(--dfb-accent);
	border-radius: 50%;
	animation: dfb-spin 0.9s linear infinite;
}

.dfb-unavailable {
	margin: 1.5em 0;
	padding: 16px 20px;
	color: #263a40;
	background: #f6f7f7;
	border: 1px solid #dcdcde;
	border-left: 4px solid #b0b7bb;
	border-radius: 4px;
}

.dfb-unavailable p {
	margin: 0;
}

.dfb-unavailable p + p {
	margin-top: 0.5em;
}

@keyframes dfb-spin {
	to {
		transform: rotate(360deg);
	}
}

/* ------------------------------------------------------------ toolbar */

.dfb-toolbar {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: center;
	gap: 4px 12px;
	width: fit-content;
	max-width: 100%;
	margin: 6px auto 0;
	padding: 4px 10px;
	color: var(--dfb-toolbar-text);
	background: var(--dfb-toolbar-bg);
	border: 1px solid var(--dfb-toolbar-border);
	border-radius: var(--dfb-radius);
	box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
	font-size: 15px;
}

.dfb-toolbar-group {
	display: inline-flex;
	align-items: center;
	gap: 2px;
}

/*
 * Many themes style every <button> with strong selectors (for example Twenty Twenty-One's
 * ".site button:not(:hover):not(:active)"), so the look of these buttons is marked !important.
 * Hover and disabled states change custom properties instead.
 */
.dfb .dfb-btn {
	--dfb-btn-bg: transparent;
	--dfb-btn-opacity: 1;
	display: inline-flex !important;
	align-items: center;
	justify-content: center;
	gap: 6px;
	width: auto !important;
	min-width: 44px !important;
	height: 44px !important;
	min-height: 0 !important;
	margin: 0 !important;
	padding: 0 10px !important;
	color: var(--dfb-accent) !important;
	background: var(--dfb-btn-bg) !important;
	border: 0 !important;
	border-radius: 999px !important;
	box-shadow: none !important;
	opacity: var(--dfb-btn-opacity) !important;
	font-family: inherit !important;
	font-size: 14px !important;
	font-weight: 600 !important;
	line-height: 1 !important;
	text-decoration: none !important;
	text-transform: none !important;
	letter-spacing: normal !important;
	text-shadow: none !important;
	cursor: pointer;
	transition: background-color 0.15s ease;
}

.dfb .dfb-btn:hover:not(:disabled) {
	--dfb-btn-bg: color-mix(in srgb, var(--dfb-accent) 12%, transparent);
}

.dfb .dfb-btn:focus {
	outline: none !important;
}

.dfb .dfb-btn:focus-visible {
	outline: 3px solid var(--dfb-accent) !important;
	outline-offset: 1px !important;
}

.dfb .dfb-btn:disabled {
	--dfb-btn-opacity: 0.35;
	cursor: default;
}

.dfb .dfb-btn[hidden] {
	display: none !important;
}

.dfb .dfb-icon {
	flex: none;
	width: 20px;
	height: 20px;
	fill: none !important;
	stroke: currentColor !important;
}

.dfb-icon--shrink,
.dfb.is-full .dfb-icon--expand {
	display: none;
}

.dfb.is-full .dfb-icon--shrink {
	display: block;
}

.dfb-pages {
	min-width: 6.5em;
	text-align: center;
	font-variant-numeric: tabular-nums;
	white-space: nowrap;
}

.dfb-sr {
	position: absolute !important;
	width: 1px !important;
	height: 1px !important;
	padding: 0 !important;
	margin: -1px !important;
	overflow: hidden !important;
	clip: rect(0, 0, 0, 0) !important;
	white-space: nowrap !important;
	border: 0 !important;
}

@media (max-width: 480px) {
	.dfb .dfb-btn--open .dfb-btn-text {
		display: none;
	}

	.dfb-toolbar {
		gap: 0 6px;
		padding: 2px 6px;
	}

	.dfb-pages {
		min-width: 5em;
	}
}

/* ------------------------------------------------------------ full screen */

.dfb.is-full {
	display: flex;
	flex-direction: column;
	margin: 0;
	padding: 10px;
	background: var(--dfb-full-bg);
}

.dfb.is-full .dfb-stage {
	flex: 1 1 auto;
	min-height: 0;
}

.dfb.is-full .dfb-toolbar {
	margin-top: 4px;
}

.dfb:fullscreen {
	width: 100%;
	height: 100%;
}

.dfb--window {
	position: fixed !important;
	inset: 0;
	z-index: 2147483000;
	width: auto;
	height: 100%;
	height: 100dvh;
	animation: dfb-backdrop-in 0.4s ease-out;
}

/* The full-window background fades in while the book grows out of the page. */
@keyframes dfb-backdrop-in {
	from {
		background-color: transparent;
	}
}

html.dfb-noscroll,
html.dfb-noscroll body {
	overflow: hidden !important;
}

/* ------------------------------------------------------------ zoom */

.dfb-zoom {
	width: 100vw;
	max-width: none;
	height: 100vh;
	height: 100dvh;
	max-height: none;
	margin: 0;
	padding: 0;
	color: var(--dfb-toolbar-text);
	background: var(--dfb-full-bg);
	border: 0;
	overflow: hidden;
}

.dfb-zoom[open] {
	display: flex;
	flex-direction: column;
}

.dfb-zoom::backdrop {
	background: rgba(0, 0, 0, 0.6);
}

.dfb-zoom-bar {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: 4px 16px;
	padding: 4px 12px;
	background: var(--dfb-toolbar-bg);
	border-bottom: 1px solid var(--dfb-toolbar-border);
	font-size: 15px;
}

.dfb-zoom-title {
	flex: 1 1 auto;
	margin: 0;
	font-weight: 600;
}

.dfb-zoom-level {
	min-width: 3.5em;
	text-align: center;
	font-variant-numeric: tabular-nums;
}

.dfb-zoom-view {
	display: flex;
	flex: 1 1 auto;
	min-height: 0;
	padding: 16px;
	overflow: auto;
	outline: none;
	cursor: grab;
	overscroll-behavior: contain;
}

.dfb-zoom-view:focus-visible {
	outline: 3px solid var(--dfb-accent);
	outline-offset: -3px;
}

.dfb-zoom-view.is-dragging {
	cursor: grabbing;
	user-select: none;
}

/* When the whole page fits, sideways swipes turn pages (handled in flipbook.js), so the browser
   mustn't treat them as scrolling. Pinch-zoom stays available. */
.dfb-zoom-view:not(.is-pannable) {
	touch-action: pinch-zoom;
}

.dfb-zoom-sheet {
	position: relative;
	flex: none;
	margin: auto;
	background: var(--dfb-paper);
	box-shadow: var(--dfb-page-shadow);
}

/* Carousel: the previous and next pages, placed beside the zoomed page by flipbook.js (the dialog
   clips them at its edges). They fade in when a drag or slide starts; flipbook.js moves them with
   the page (a spring animation) and fades out the ones leaving. */
.dfb-zoom-peek {
	position: absolute;
	background: var(--dfb-paper);
	box-shadow: var(--dfb-page-shadow);
	pointer-events: none;
	animation: dfb-fade-in 0.15s ease-out;
}

.dfb-zoom-peek[hidden] {
	display: none;
}

@keyframes dfb-fade-in {
	from {
		opacity: 0;
	}
}

.dfb-zoom-preview,
.dfb-zoom-canvas {
	position: absolute;
	inset: 0;
	display: block;
	width: 100%;
	height: 100%;
	max-width: none;
	object-fit: contain;
	pointer-events: none;
}

.dfb-zoom-sheet.is-loading::after {
	content: "";
	position: sticky;
	top: 12px;
	display: block;
	width: 24px;
	height: 24px;
	margin: 12px;
	border: 3px solid rgba(38, 58, 64, 0.15);
	border-top-color: var(--dfb-accent);
	border-radius: 50%;
	animation: dfb-spin 0.9s linear infinite;
}

/* ------------------------------------------------------------ reduced motion */

@media (prefers-reduced-motion: reduce) {
	.dfb-book,
	.dfb .dfb-btn {
		transition: none;
	}

	.dfb-spinner,
	.dfb--window,
	.dfb-zoom-peek,
	.dfb-page:not(.is-ready):not(.is-failed) .dfb-sheet::before,
	.dfb-zoom-sheet.is-loading::after {
		animation: none;
	}
}
