/* Starwide Reader – theme-overridable via the --swb-* custom properties. */
:root {
	--swb-accent: #e5484d;
	--swb-accent-ink: #fff;
	--swb-reader-bg: #0b0b0e;
	--swb-reader-ink: #ececf1;
	--swb-reader-muted: #9a9aa6;
	--swb-reader-bar: rgba(16, 16, 20, 0.92);
	--swb-radius: 8px;
	--swb-font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

/* ---------- Print & capture deterrent (spec §3) ---------- */
@media print {
	html.swb-protected body,
	body.swb-protected {
		display: none !important;
	}
}

/* ---------- Book panel on the presentation page ---------- */
.swb-book-panel {
	display: grid;
	gap: 14px;
	margin: 0 0 1.5em;
	padding: 18px;
	border: 1px solid rgba(127, 127, 127, 0.25);
	border-radius: var(--swb-radius);
	font-family: var(--swb-font);
}
.swb-meta {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
	gap: 10px 18px;
	margin: 0;
}
.swb-meta div { margin: 0; }
.swb-meta dt {
	font-size: 0.75em;
	text-transform: uppercase;
	letter-spacing: 0.06em;
	opacity: 0.65;
}
.swb-meta dd { margin: 2px 0 0; font-weight: 600; }

.swb-badge {
	justify-self: start;
	display: inline-block;
	padding: 2px 10px;
	border-radius: 999px;
	font: 700 0.75rem/1.6 var(--swb-font);
	letter-spacing: 0.04em;
	background: #2f8f5b;
	color: #fff;
}
.swb-badge--teen { background: #b7791f; }
.swb-badge--adult { background: #c53030; }
.swb-note { margin: 0; opacity: 0.8; }
.swb-btn--ghost { opacity: 0.8; }

/* Encore's circle-and-cross badge, on light or dark themes. */
.swb-age-gate .encore-restricted-badge,
.swb-cover-restricted .encore-restricted-badge { width: 72px; height: 72px; color: currentColor; opacity: 0.85; }
.swb-cover-restricted {
	display: grid;
	place-items: center;
	aspect-ratio: 2 / 3;
	max-width: 100%;
	background: rgba(127, 127, 127, 0.15);
	border-radius: var(--swb-radius);
}

.swb-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.swb-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-height: 44px;
	padding: 0 18px;
	border: 1px solid currentColor;
	border-radius: var(--swb-radius);
	background: transparent;
	color: inherit;
	font: 600 0.95rem/1 var(--swb-font);
	text-decoration: none;
	cursor: pointer;
}
.swb-btn--primary,
.swb-btn--buy {
	border-color: var(--swb-accent);
	background: var(--swb-accent);
	color: var(--swb-accent-ink);
}
.swb-btn:focus-visible { outline: 3px solid var(--swb-accent); outline-offset: 2px; }

.swb-age-gate {
	display: grid;
	justify-items: start;
	gap: 10px;
	padding: 24px;
	border: 1px solid rgba(197, 48, 48, 0.4);
	border-radius: var(--swb-radius);
	font-family: var(--swb-font);
}
.swb-age-gate p { margin: 0; }

/* ---------- Reader viewport ---------- */
html.swb-reader-open,
html.swb-reader-open body { overflow: hidden !important; }

.swb-r {
	position: fixed;
	inset: 0;
	z-index: 999999;
	display: grid;
	grid-template-rows: auto 1fr auto;
	background: var(--swb-reader-bg);
	color: var(--swb-reader-ink);
	font-family: var(--swb-font);
	user-select: none;
	-webkit-user-select: none;
	-webkit-touch-callout: none;
	-webkit-tap-highlight-color: transparent;
	outline: none;
}
.swb-r *,
.swb-r *::before,
.swb-r *::after { box-sizing: border-box; }

.swb-r-top,
.swb-r-bottom {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 6px max(12px, env(safe-area-inset-left)) 6px max(12px, env(safe-area-inset-right));
	background: var(--swb-reader-bar);
	z-index: 20;
	transition: opacity 0.2s ease;
}
.swb-r-top { padding-top: max(6px, env(safe-area-inset-top)); }
.swb-r-bottom { padding-bottom: max(6px, env(safe-area-inset-bottom)); }
.swb-r--bare .swb-r-top,
.swb-r--bare .swb-r-bottom { opacity: 0; pointer-events: none; }

.swb-r-title {
	flex: 1;
	min-width: 0;
	overflow: hidden;
	white-space: nowrap;
	text-overflow: ellipsis;
	font-weight: 600;
}
.swb-r-tools { display: flex; align-items: center; gap: 2px; }
.swb-r button {
	display: inline-grid;
	place-items: center;
	width: 44px;
	height: 44px;
	padding: 0;
	border: 0;
	border-radius: var(--swb-radius);
	background: transparent;
	color: inherit;
	cursor: pointer;
}
.swb-r button:hover { background: rgba(255, 255, 255, 0.08); }
.swb-r button:focus-visible { outline: 2px solid var(--swb-accent); outline-offset: -2px; }
.swb-r button svg {
	width: 22px;
	height: 22px;
	fill: none;
	stroke: currentColor;
	stroke-width: 2;
	stroke-linecap: round;
	stroke-linejoin: round;
}
.swb-r-zoom {
	min-width: 3.4em;
	text-align: center;
	font-variant-numeric: tabular-nums;
	font-size: 0.85rem;
	color: var(--swb-reader-muted);
}

.swb-r-stage {
	position: relative;
	overflow: hidden;
	touch-action: none;
}
.swb-r-canvas {
	position: absolute;
	top: 0;
	left: 0;
	transform-origin: 0 0;
	pointer-events: none;
	box-shadow: 0 4px 30px rgba(0, 0, 0, 0.5);
	transition: filter 0.15s ease;
}
.swb-r--veiled .swb-r-canvas { filter: blur(24px); }

/* Transparent shield: every click, drag and long-press lands here, never on the canvas. */
.swb-r-shield {
	position: absolute;
	inset: 0;
	z-index: 10;
	background: transparent;
	cursor: default;
	-webkit-user-drag: none;
}
.swb-r--zoomed .swb-r-shield { cursor: grab; }
.swb-r--zoomed .swb-r-shield:active { cursor: grabbing; }

.swb-r-status {
	position: absolute;
	left: 50%;
	top: 50%;
	z-index: 11;
	transform: translate(-50%, -50%);
	padding: 10px 16px;
	border-radius: var(--swb-radius);
	background: rgba(0, 0, 0, 0.6);
	color: var(--swb-reader-ink);
	text-align: center;
}
.swb-r-status[hidden] { display: none; }
.swb-r-status .swb-btn { min-height: 36px; margin-left: 6px; color: var(--swb-reader-ink); }

.swb-r-lock {
	position: absolute;
	inset: 0;
	z-index: 12;
	display: grid;
	place-items: center;
	padding: 24px;
}
.swb-r-lock[hidden] { display: none; }
.swb-r-lockbox {
	display: grid;
	justify-items: center;
	gap: 14px;
	max-width: 360px;
	text-align: center;
}
.swb-r-lockbox h2 { margin: 0; font-size: 1.4rem; color: var(--swb-reader-ink); }
.swb-r-lockbox p { margin: 0; color: var(--swb-reader-muted); }
.swb-r-lockbox .swb-btn { width: 100%; color: var(--swb-reader-ink); }
.swb-r-lockbox .swb-btn--buy { color: var(--swb-accent-ink); }

.swb-r-slider {
	flex: 1;
	min-width: 60px;
	accent-color: var(--swb-accent);
}
.swb-r-count {
	min-width: 7.5em;
	text-align: center;
	font-size: 0.85rem;
	font-variant-numeric: tabular-nums;
	color: var(--swb-reader-muted);
}

@media (max-width: 560px) {
	.swb-r-zoom,
	.swb-r [data-a="fit"] { display: none; }
	.swb-r-count { min-width: 5.5em; font-size: 0.8rem; }
}
@media (prefers-reduced-motion: reduce) {
	.swb-r-top, .swb-r-bottom, .swb-r-canvas { transition: none; }
}

/* ---------- Inline reader inside the Starwide Encore theme frame (.sw-reader) ---------- */
.swb-r-inline-only { display: none !important; }

.swb-r--inline {
	position: absolute;
	inset: 0;
	z-index: 0; /* Own stacking context: the theme's frame buttons (z-index 5) stay on top. */
	grid-template-rows: 1fr auto;
	border-radius: inherit;
	overflow: hidden;
	background: transparent;
}
.swb-r--inline:focus-visible { outline: 2px solid var(--swb-accent); outline-offset: -2px; }
.swb-r--inline .swb-r-top,
.swb-r--inline .swb-r-nav { display: none; }
.swb-r--inline .swb-r-inline-only { display: inline-grid !important; }
.swb-r--inline .swb-r-bottom {
	gap: 4px;
	padding: 4px 8px;
	background: rgba(0, 0, 0, 0.55);
}
.swb-r--inline .swb-r-count { min-width: 6em; font-size: 0.8rem; }
.swb-r--inline button { width: 36px; height: 36px; }
.swb-r--inline .swb-r-canvas { box-shadow: none; }

.sw-reader { overflow: hidden; }
.sw-reader.swb-fullscreen,
.sw-reader:fullscreen {
	max-width: none;
	width: 100%;
	height: 100%;
	aspect-ratio: auto;
	border-radius: 0;
}
.sw-reader.swb-expanded {
	position: fixed;
	inset: 0;
	z-index: 999999;
	max-width: none;
	aspect-ratio: auto;
	margin: 0;
	border-radius: 0;
}

/* Theme ad slot 5, shown over the page frame between page turns (free books only). */
.sw-reader > .swb-ad-overlay {
	position: absolute !important; /* The theme sets position:relative inline on this slot. */
	inset: 0;
	z-index: 20;
	width: auto;
	max-width: none;
	margin: 0;
	aspect-ratio: auto;
	background: #000;
}

/* Theme mode: the theme's velvet-red pill buttons and accent. */
.swb-theme { --swb-accent: var(--sw-button-bg, #7b0d2e); --swb-accent-ink: var(--sw-button-text, #fff); }
.swb-theme .swb-book-panel { border-color: var(--sw-border, rgba(127,127,127,0.25)); background: var(--sw-bg-elevated, transparent); }
.swb-theme .swb-btn.sw-btn {
	min-height: 44px;
	border: none;
	border-radius: var(--sw-radius-pill, 999px);
	background-color: var(--sw-button-bg);
	color: var(--sw-button-text);
}
.swb-theme .swb-btn.sw-btn:hover,
.swb-theme .swb-btn.sw-btn:focus-visible { background-color: var(--sw-button-bg-hover); }
.swb-theme .swb-btn--ghost { border-radius: var(--sw-radius-pill, 999px); }

/* Gates and empty states inside the theme frame: centred, and the page controls step aside. */
.sw-reader > .swb-age-gate,
.sw-reader > .swb-r-empty {
	position: absolute;
	inset: 0;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 14px;
	margin: 0;
	padding: 24px;
	border: 0;
	text-align: center;
}
.sw-reader > .swb-age-gate .encore-age-form { display: grid; gap: 8px; justify-items: center; }
.sw-reader:has(> .swb-age-gate) .sw-reader__nav,
.sw-reader:has(> .swb-age-gate) .sw-reader__jump,
.sw-reader:has(> .swb-r-empty) .sw-reader__nav,
.sw-reader:has(> .swb-r-empty) .sw-reader__jump { display: none; }
