/**
 * The Hair Magazine — Digital Edition Viewer
 * Premium, minimal editorial chrome around the page-flip book.
 * Structural rules the flip engine itself requires live in
 * vendor/page-flip/stPageFlip.css (loaded as a dependency of this file).
 */

.thm-dm-viewer {
	--thm-dm-bg: #f5f5f5;
	--thm-dm-ink: #1a1a1a;
	--thm-dm-accent: #c9a15a;

	position: relative;
	display: flex;
	flex-direction: column;
	width: 100%;
	background: var( --thm-dm-bg );
	color: var( --thm-dm-ink );
	overflow: hidden;
	/* Avantgarde BK BT is The Hair Magazine's brand typeface but isn't
	   vendored in this plugin (no local copy exists, and it's a licensed
	   font with no legal open-source source to bundle). Naming it first
	   costs nothing and activates it automatically if the theme already
	   loads it site-wide; Century Gothic/Futura are the closest common
	   system fallbacks to this geometric-sans family otherwise. */
	font-family: "Avantgarde BK BT", "Century Gothic", "Futura", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
	box-sizing: border-box;
}

.thm-dm-viewer *,
.thm-dm-viewer *::before,
.thm-dm-viewer *::after {
	box-sizing: border-box;
}

.thm-dm-viewer:focus-visible {
	outline: 2px solid var( --thm-dm-accent );
	outline-offset: -2px;
}

/* Loading / empty / error status ------------------------------------- */

.thm-dm-status {
	flex: 1 1 auto;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 16px;
	padding: 2rem;
	text-align: center;
}

.thm-dm-spinner {
	width: 40px;
	height: 40px;
	border-radius: 50%;
	border: 3px solid rgba( 0, 0, 0, 0.12 );
	border-top-color: var( --thm-dm-accent );
	animation: thm-dm-spin 0.9s linear infinite;
}

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

.thm-dm-status-text {
	margin: 0;
	font-size: 0.95rem;
	letter-spacing: 0.01em;
	opacity: 0.85;
	max-width: 32em;
}

.thm-dm-viewer.has-error .thm-dm-status-text {
	color: #b3261e;
}

/* Viewport / stage / book --------------------------------------------- */

.thm-dm-viewport {
	flex: 1 1 auto;
	min-height: 0;
	width: 100%;
	overflow: auto;
	display: flex;
	/* Centering .thm-dm-stage is delegated to `margin: auto` on the stage
	   itself (below) rather than align-items/justify-content here. Both
	   approaches look identical at rest, but they diverge once the stage
	   overflows this container (which zoom does on purpose): per the flex
	   spec, an item's own auto margins resolve to 0 — not negative — when
	   there isn't room, so the item snaps flush to the start edge and its
	   *entire* overflow becomes reachable by scrolling forward from 0.
	   align-items/justify-content:center have no such guarantee — Chromium
	   keeps the item visually centered past both edges instead, and since
	   scrollLeft/scrollTop can never go negative, whatever hangs off the
	   *start* (left/top) side is permanently unreachable, no matter the
	   scroll position. Confirmed directly: zoom.js's focal-point math
	   (_zoomAt) computed the exact scroll correction needed to keep an
	   off-center focal point under the cursor, but with center-alignment
	   here that correction came out negative for any focal point left/above
	   center and silently clamped to 0, leaving the anchored point visibly
	   adrift. Switching to auto-margin centering removed the need for any
	   such clamping — the correction is always reachable. */
	/* Base breathing room around the magazine. flipbook.js's _fitStage()
	   does the real work of keeping the book inside this padded box at
	   any viewport size and aspect ratio — this just sets the floor.
	   Top/bottom deliberately use `vh`, not `%`: CSS always resolves
	   percentage padding-top/bottom against the container's WIDTH, so a
	   %-only value would burn a wide-but-short viewport's scarce vertical
	   space in proportion to its width, not its height, artificially
	   shrinking the available height _fitStage() has to work with. */
	padding: clamp( 16px, 5vh, 64px ) clamp( 16px, 5%, 64px );
	-webkit-overflow-scrolling: touch;
}

.thm-dm-stage {
	display: inline-block;
	max-width: 100%;
	width: 100%;
	/* Replaces .thm-dm-viewport's old align-items/justify-content:center —
	   see the comment there for why this specific mechanism, not just
	   "some way to center it", is what makes the whole overflow reachable
	   once zoomed. */
	margin: auto;
	/* .thm-dm-viewport is a flex container. Two of its default behaviors
	   each independently cap how big CSS `zoom` can ever grow this element,
	   and both had to be found and fixed together (confirmed by isolating
	   each in an unrelated test element — fixing only one left the cap in
	   place):

	   1. A flex item's default flex-shrink:1 lets the layout algorithm
	      shrink it below its own specified width whenever it decides the
	      item doesn't fit — which is exactly what happens once `zoom` is
	      applied: Chromium's flex layout re-evaluates the (now zoomed) item
	      against the flex container's *unzoomed* size and shrinks it
	      straight back down to fit. flex-shrink:0 stops that. Since
	      _fitStage() already sets this element's exact intended width
	      directly, the flex algorithm never legitimately needs to shrink it
	      at rest either — flex-shrink:0 doesn't change any at-rest sizing.

	   2. Even with flex-shrink:0, `max-width: 100%` above still caps it:
	      a percentage max-width resolves against the containing block's
	      width as laid out *before* `zoom` is applied, not the zoomed
	      result, so "100%" silently means "the viewport's own unzoomed
	      width" the instant the item tries to grow past that. At rest
	      (scale 1) this is harmless — the stage never exceeds the
	      viewport anyway — but it must be lifted once zoomed. See
	      .thm-dm-stage.is-zoomed below. */
	flex-shrink: 0;
	/* page-flip's own backward-flip shadow (.stf__outerShadow /
	   .stf__innerShadow) is positioned via a direction-specific CSS
	   transform that, only when flipping backward, extends further left
	   than the book's own box. With nothing clipping that between here and
	   .thm-dm-viewport's overflow:auto (kept auto deliberately, for zoom
	   panning), that transient overflow became scrollable — a horizontal
	   scrollbar and an apparent rightward jump during backward flips only.
	   Clipping it here, at the stage boundary, stops it before it ever
	   reaches the viewport's scrollable area. */
	overflow: hidden;
}

.thm-dm-stage.is-zoomed {
	cursor: grab;
	/* Lifts the unzoomed-width cap described above (point 2) so the stage
	   can actually grow past the viewport's own width once zoomed. Safe to
	   drop entirely rather than raise, since .thm-dm-viewport's
	   overflow:auto is what makes the now-larger stage scrollable/pannable
	   — nothing here still depends on the stage being clamped to view. */
	max-width: none;
}

.thm-dm-stage.is-zoomed .thm-dm-book {
	/* page-flip's own base CSS restricts the book to vertical-only native
	   touch panning (needed so a horizontal swipe can be read as a page
	   turn). While zoomed there is nothing to flip toward, so drop that
	   restriction and let the reader pan freely with a finger. */
	touch-action: auto;
}

.thm-dm-book {
	margin: 0 auto;
	/* The one visible "elevation" cue for the whole component — kept
	   deliberately soft so the magazine reads as gently lifted off the
	   page background rather than boxed into a card. */
	box-shadow: 0 2px 24px rgba( 0, 0, 0, 0.1 );
}

.thm-dm-page {
	width: 100%;
	height: 100%;
	background: #fdfdfb;
	display: flex;
	align-items: center;
	justify-content: center;
	overflow: hidden;
	box-shadow: inset 0 0 0 1px rgba( 0, 0, 0, 0.05 );
}

.thm-dm-page:not( [data-rendered="true"] ):not( [data-rendered="failed"] ) {
	background: linear-gradient( 100deg, #efefec 30%, #fbfbf9 50%, #efefec 70% );
	background-size: 200% 100%;
	animation: thm-dm-shimmer 1.6s ease-in-out infinite;
}

@keyframes thm-dm-shimmer {
	0% {
		background-position: 200% 0;
	}
	100% {
		background-position: -200% 0;
	}
}

.thm-dm-page-canvas {
	display: block;
	width: 100%;
	height: 100%;
}

.thm-dm-page-error {
	font-size: 1.75rem;
	opacity: 0.35;
}

/* Controls -------------------------------------------------------------- */

.thm-dm-controls {
	flex: 0 0 auto;
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 0.5rem;
	padding: 0.65rem 1rem;
	background: transparent;
	border-top: 1px solid rgba( 0, 0, 0, 0.08 );
}

.thm-dm-btn {
	appearance: none;
	border: none;
	background: transparent;
	color: var( --thm-dm-ink );
	width: 2.25rem;
	height: 2.25rem;
	border-radius: 0;
	font-size: 1.05rem;
	line-height: 1;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	cursor: pointer;
	transition: background 0.15s ease, transform 0.15s ease, opacity 0.15s ease;
}

.thm-dm-btn:hover {
	background: rgba( 0, 0, 0, 0.05 );
}

.thm-dm-btn:active {
	transform: scale( 0.94 );
}

.thm-dm-btn:focus-visible {
	outline: 2px solid var( --thm-dm-accent );
	outline-offset: 2px;
}

.thm-dm-btn:disabled {
	opacity: 0.3;
	cursor: default;
}

.thm-dm-btn:disabled:hover {
	background: transparent;
}

.thm-dm-btn-fullscreen.is-active {
	background: var( --thm-dm-accent );
	color: #1a1a1a;
}

/* Whitespace-only grouping — separates the reading controls (prev /
   counter / next) from the secondary tools (zoom, fullscreen) without
   adding a divider, box, or border. */
.thm-dm-btn-zoom-out {
	margin-left: 0.75rem;
}

.thm-dm-page-counter {
	min-width: 4.5rem;
	text-align: center;
	font-size: 0.82rem;
	letter-spacing: 0.04em;
	font-variant-numeric: tabular-nums;
	opacity: 0.85;
	margin: 0 0.25rem;
}

/* Fullscreen ------------------------------------------------------------- */

.thm-dm-viewer:fullscreen,
.thm-dm-viewer.thm-dm-faux-fullscreen {
	width: 100vw;
	height: 100vh;
}

.thm-dm-viewer.thm-dm-faux-fullscreen {
	position: fixed;
	inset: 0;
	z-index: 99999;
}

body.thm-dm-faux-fullscreen-lock {
	overflow: hidden;
}

/* Small screens ----------------------------------------------------------- */

@media ( max-width: 480px ) {
	.thm-dm-controls {
		gap: 0.25rem;
		padding: 0.5rem 0.5rem;
	}

	.thm-dm-btn {
		/* Previously 2rem (32px) — smaller than the 36px desktop size,
		   backwards for touch. 2.5rem (40px) is closer to the ~44px
		   minimum touch target guidance while still fitting six controls
		   on a 320px-wide screen without wrapping or clipping. */
		width: 2.5rem;
		height: 2.5rem;
		font-size: 1rem;
	}

	.thm-dm-btn-zoom-out {
		margin-left: 0.25rem;
	}

	.thm-dm-page-counter {
		min-width: 3.25rem;
		font-size: 0.75rem;
	}
}

@media ( prefers-reduced-motion: reduce ) {
	.thm-dm-spinner,
	.thm-dm-page:not( [data-rendered="true"] ) {
		animation: none;
	}
}
