/*
 * PDF Flipbook Gallery – estilos del frontend.
 * Personaliza los colores desde tu tema redefiniendo las variables --pfg-*.
 */

:where(:root) {
	--pfg-accent: #2563eb;
	--pfg-stage-bg: #eef0f3;
	--pfg-radius: 14px;
	--pfg-toolbar-bg: #ffffff;
	--pfg-toolbar-fg: #1f2937;
	--pfg-toolbar-border: rgba(15, 23, 42, 0.1);
	--pfg-toolbar-hover: rgba(15, 23, 42, 0.07);
	--pfg-card-bg: linear-gradient(150deg, #f3f4f7 0%, #e3e6eb 100%);
	--pfg-dark-bg: #101216;
}

/* ------------------------------------------------------------------ */
/* Visor                                                               */
/* ------------------------------------------------------------------ */

.pfg-flipbook {
	margin: 1.5em 0;
}

.pfg-flipbook.is-pending {
	min-height: 320px;
	border-radius: var(--pfg-radius);
	background: var(--pfg-stage-bg);
}

.pfg-viewer {
	position: relative;
	display: flex;
	flex-direction: column;
	box-sizing: border-box;
	overflow: hidden;
	background: var(--pfg-stage-bg);
	border-radius: var(--pfg-radius);
	outline: none;
	-webkit-tap-highlight-color: transparent;
}

.pfg-viewer:focus-visible {
	box-shadow: 0 0 0 3px var(--pfg-accent);
}

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

.pfg-stage {
	position: relative;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 24px 16px 8px;
}

.pfg-viewer:not(.is-ready) .pfg-stage {
	min-height: 320px;
}

.pfg-holder {
	flex: none;
	max-width: 100%;
	margin: 0 auto;
	transition: transform 0.45s ease;
	will-change: transform;
}

.pfg-holder[data-shift="start"] {
	transform: translateX(-25%);
}

.pfg-holder[data-shift="end"] {
	transform: translateX(25%);
}

.pfg-book {
	margin: 0 auto;
}

/* Páginas */

.pfg-page {
	background: #fff;
	overflow: hidden;
}

.pfg-page-inner {
	position: absolute;
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	background: #fff;
}

.pfg-page-inner canvas {
	display: block;
	max-width: 100%;
	max-height: 100%;
	width: auto;
	height: auto;
}

/* Sombra del lomo */
.pfg-page.--left .pfg-page-inner::after,
.pfg-page.--right .pfg-page-inner::after {
	content: "";
	position: absolute;
	inset: 0;
	pointer-events: none;
}

.pfg-page.--left .pfg-page-inner::after {
	background: linear-gradient(to left, rgba(0, 0, 0, 0.14) 0%, rgba(0, 0, 0, 0.04) 4%, transparent 10%);
}

.pfg-page.--right .pfg-page-inner::after {
	background: linear-gradient(to right, rgba(0, 0, 0, 0.14) 0%, rgba(0, 0, 0, 0.04) 4%, transparent 10%);
}

.pfg-page-inner.is-loading::before {
	content: "";
	width: 28px;
	height: 28px;
	border: 3px solid rgba(15, 23, 42, 0.12);
	border-top-color: var(--pfg-accent);
	border-radius: 50%;
	animation: pfg-spin 0.8s linear infinite;
}

.pfg-page-inner.is-error::before {
	content: "!";
	display: flex;
	align-items: center;
	justify-content: center;
	width: 32px;
	height: 32px;
	font: 700 18px/1 system-ui, sans-serif;
	color: #b91c1c;
	border: 2px solid currentColor;
	border-radius: 50%;
}

/* Estado de carga / error */

.pfg-status {
	position: absolute;
	inset: 0;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 12px;
	padding: 24px;
	text-align: center;
	font-size: 15px;
	line-height: 1.5;
	color: #4b5563;
}

.pfg-viewer.is-ready .pfg-status {
	display: none;
}

.pfg-spinner {
	width: 36px;
	height: 36px;
	border: 3px solid rgba(15, 23, 42, 0.12);
	border-top-color: var(--pfg-accent);
	border-radius: 50%;
	animation: pfg-spin 0.8s linear infinite;
}

.pfg-viewer.is-error .pfg-spinner {
	display: none;
}

.pfg-status-text {
	max-width: 440px;
}

.pfg-viewer .pfg-status-link {
	display: inline-block;
	padding: 8px 18px;
	font-weight: 600;
	color: #fff;
	text-decoration: none;
	background: var(--pfg-accent);
	border-radius: 999px;
}

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

/* Barra de herramientas */

.pfg-toolbar {
	display: flex;
	justify-content: center;
	padding: 12px 16px 18px;
}

.pfg-toolbar[hidden] {
	display: none;
}

.pfg-toolbar-inner {
	display: inline-flex;
	align-items: center;
	gap: 2px;
	padding: 4px;
	color: var(--pfg-toolbar-fg);
	background: var(--pfg-toolbar-bg);
	border: 1px solid var(--pfg-toolbar-border);
	border-radius: 999px;
	box-shadow: 0 6px 20px -10px rgba(15, 23, 42, 0.35);
}

.pfg-viewer .pfg-btn,
.pfg-modal .pfg-modal-close {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	flex: none;
	width: 38px;
	height: 38px;
	min-width: 0;
	min-height: 0;
	margin: 0;
	padding: 0;
	font: inherit;
	line-height: 1;
	letter-spacing: normal;
	text-transform: none;
	text-decoration: none;
	color: inherit;
	background: transparent;
	border: 0;
	border-radius: 50%;
	box-shadow: none;
	cursor: pointer;
	-webkit-appearance: none;
	appearance: none;
	transition: background-color 0.15s ease, opacity 0.15s ease;
}

.pfg-viewer .pfg-btn:hover,
.pfg-viewer .pfg-btn:focus-visible {
	color: inherit;
	background: var(--pfg-toolbar-hover);
}

.pfg-viewer .pfg-btn:focus-visible,
.pfg-modal .pfg-modal-close:focus-visible {
	outline: 2px solid var(--pfg-accent);
	outline-offset: 1px;
}

.pfg-viewer .pfg-btn:disabled {
	opacity: 0.3;
	cursor: default;
	background: transparent;
}

.pfg-viewer .pfg-btn svg {
	display: block;
	width: 20px;
	height: 20px;
}

.pfg-pageinfo {
	min-width: 84px;
	padding: 0 6px;
	font-size: 14px;
	font-weight: 600;
	font-variant-numeric: tabular-nums;
	text-align: center;
	white-space: nowrap;
}

.pfg-divider {
	width: 1px;
	height: 22px;
	margin: 0 4px;
	background: var(--pfg-toolbar-border);
}

@media (max-width: 420px) {
	.pfg-viewer .pfg-btn[data-action="first"],
	.pfg-viewer .pfg-btn[data-action="last"] {
		display: none;
	}

	.pfg-stage {
		padding: 16px 8px 4px;
	}
}

/* Modo oscuro: modal y pantalla completa */

.pfg-viewer--modal,
.pfg-viewer.is-fullscreen {
	--pfg-toolbar-bg: rgba(255, 255, 255, 0.1);
	--pfg-toolbar-fg: #f3f4f6;
	--pfg-toolbar-border: rgba(255, 255, 255, 0.14);
	--pfg-toolbar-hover: rgba(255, 255, 255, 0.14);
}

.pfg-viewer--modal .pfg-status,
.pfg-viewer.is-fullscreen .pfg-status {
	color: #d1d5db;
}

.pfg-viewer--modal .pfg-spinner,
.pfg-viewer.is-fullscreen .pfg-spinner {
	border-color: rgba(255, 255, 255, 0.18);
	border-top-color: #fff;
}

.pfg-viewer--modal {
	flex: 1 1 auto;
	min-height: 0;
	background: transparent;
	border-radius: 0;
}

.pfg-viewer--modal .pfg-stage,
.pfg-viewer.is-fullscreen .pfg-stage {
	flex: 1 1 auto;
	min-height: 0;
	padding: 8px 16px;
}

.pfg-viewer.is-fullscreen {
	width: 100%;
	height: 100%;
	background: var(--pfg-dark-bg);
	border-radius: 0;
}

.pfg-viewer.is-pseudo-fullscreen {
	position: fixed;
	inset: 0;
	z-index: 1000000;
	height: 100vh;
	height: 100dvh;
}

.pfg-viewer:fullscreen {
	background: var(--pfg-dark-bg);
}

html.pfg-fullscreen-open,
html.pfg-fullscreen-open body,
html.pfg-modal-open,
html.pfg-modal-open body {
	overflow: hidden;
}

/* ------------------------------------------------------------------ */
/* Ventana modal                                                       */
/* ------------------------------------------------------------------ */

.pfg-modal {
	position: fixed;
	inset: 0;
	z-index: 999999;
	display: flex;
}

.pfg-modal[hidden] {
	display: none;
}

.pfg-modal-backdrop {
	position: absolute;
	inset: 0;
	background: rgba(10, 12, 16, 0.9);
	-webkit-backdrop-filter: blur(6px);
	backdrop-filter: blur(6px);
	opacity: 0;
	transition: opacity 0.25s ease;
}

.pfg-modal-dialog {
	position: relative;
	display: flex;
	flex-direction: column;
	width: 100%;
	height: 100vh;
	height: 100dvh;
	opacity: 0;
	transform: scale(0.98);
	transition: opacity 0.25s ease, transform 0.25s ease;
	pointer-events: none;
}

.pfg-modal.is-open .pfg-modal-backdrop,
.pfg-modal.is-open .pfg-modal-dialog {
	opacity: 1;
	transform: none;
}

.pfg-modal-header {
	pointer-events: auto;
}

.pfg-modal-header {
	display: flex;
	align-items: center;
	gap: 16px;
	padding: 12px 12px 4px 24px;
	color: #f9fafb;
}

.pfg-modal-title {
	flex: 1;
	min-width: 0;
	overflow: hidden;
	font: 600 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.pfg-modal .pfg-modal-close {
	width: 44px;
	height: 44px;
	color: #f9fafb;
	background: rgba(255, 255, 255, 0.1);
}

.pfg-modal .pfg-modal-close:hover {
	color: #fff;
	background: rgba(255, 255, 255, 0.2);
}

.pfg-modal .pfg-modal-close svg {
	width: 22px;
	height: 22px;
}

.pfg-modal-body {
	display: flex;
	flex: 1 1 auto;
	min-height: 0;
}

/* Un clic en el espacio vacío alrededor del libro llega al fondo y cierra la modal. */
.pfg-modal-body,
.pfg-viewer--modal,
.pfg-viewer--modal .pfg-stage,
.pfg-viewer--modal .pfg-toolbar {
	pointer-events: none;
}

.pfg-viewer--modal .pfg-holder,
.pfg-viewer--modal .pfg-status,
.pfg-viewer--modal .pfg-toolbar-inner,
.pfg-viewer--modal.is-fullscreen {
	pointer-events: auto;
}

/* ------------------------------------------------------------------ */
/* Galería                                                             */
/* ------------------------------------------------------------------ */

.pfg-gallery {
	--pfg-gap: 28px;
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(max(150px, calc((100% - (var(--pfg-columns, 4) - 1) * var(--pfg-gap)) / var(--pfg-columns, 4))), 1fr));
	gap: var(--pfg-gap) calc(var(--pfg-gap) * 0.8);
	margin: 0;
}

.pfg-gallery-wrap {
	margin: 1.5em 0;
}

@media (max-width: 600px) {
	.pfg-gallery {
		--pfg-gap: 18px;
	}
}

.pfg-gallery .pfg-card {
	display: flex;
	flex-direction: column;
	gap: 12px;
	min-width: 0;
	color: inherit;
	text-decoration: none;
	border: 0;
	border-radius: 12px;
	box-shadow: none;
	cursor: pointer;
}

.pfg-gallery .pfg-card:hover,
.pfg-gallery .pfg-card:focus {
	color: inherit;
	text-decoration: none;
}

.pfg-gallery .pfg-card:focus-visible {
	outline: 2px solid var(--pfg-accent);
	outline-offset: 4px;
}

.pfg-card-cover {
	position: relative;
	display: flex;
	align-items: center;
	justify-content: center;
	aspect-ratio: 5 / 7;
	padding: 14px;
	overflow: hidden;
	background: var(--pfg-card-bg);
	border-radius: 12px;
	transition: transform 0.25s ease, box-shadow 0.25s ease;
}

.pfg-card:hover .pfg-card-cover,
.pfg-card:focus-visible .pfg-card-cover {
	transform: translateY(-4px);
	box-shadow: 0 18px 32px -16px rgba(15, 23, 42, 0.45);
}

.pfg-gallery .pfg-card-cover img,
.pfg-card-placeholder canvas {
	display: block;
	max-width: 100%;
	max-height: 100%;
	width: auto;
	height: auto;
	margin: 0;
	background: #fff;
	border-radius: 2px;
	box-shadow: 0 1px 2px rgba(15, 23, 42, 0.1), 0 10px 22px -8px rgba(15, 23, 42, 0.35);
}

.pfg-card-placeholder {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 100%;
	height: 100%;
}

/* Hoja en blanco mientras se genera la portada */
.pfg-card-placeholder:not(.has-thumb)::before {
	content: "";
	width: 72%;
	aspect-ratio: 1 / 1.414;
	background:
		linear-gradient(#e5e7eb, #e5e7eb) 14% 16% / 60% 6px no-repeat,
		linear-gradient(#eceef1, #eceef1) 14% 26% / 72% 4px no-repeat,
		linear-gradient(#eceef1, #eceef1) 14% 31% / 66% 4px no-repeat,
		linear-gradient(#eceef1, #eceef1) 14% 36% / 70% 4px no-repeat,
		#fff;
	border-radius: 2px;
	box-shadow: 0 10px 22px -10px rgba(15, 23, 42, 0.3);
}

.pfg-card-placeholder.is-loading::before {
	animation: pfg-pulse 1.2s ease-in-out infinite;
}

@keyframes pfg-pulse {
	50% {
		opacity: 0.55;
	}
}

.pfg-card-badge {
	position: absolute;
	top: 10px;
	left: 10px;
	padding: 3px 9px;
	font: 700 11px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
	letter-spacing: 0.03em;
	color: #fff;
	background: rgba(185, 28, 28, 0.92);
	border-radius: 999px;
}

.pfg-card-view {
	position: absolute;
	left: 50%;
	bottom: 16px;
	display: inline-flex;
	align-items: center;
	gap: 6px;
	padding: 8px 16px;
	font: 600 14px/1 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
	color: #111827;
	background: rgba(255, 255, 255, 0.96);
	border-radius: 999px;
	box-shadow: 0 8px 20px -8px rgba(15, 23, 42, 0.5);
	opacity: 0;
	transform: translate(-50%, 8px);
	transition: opacity 0.2s ease, transform 0.2s ease;
}

.pfg-card:hover .pfg-card-view,
.pfg-card:focus-visible .pfg-card-view {
	opacity: 1;
	transform: translate(-50%, 0);
}

.pfg-card-title {
	display: -webkit-box;
	overflow: hidden;
	padding: 0 2px;
	font-weight: 600;
	font-size: 0.95em;
	line-height: 1.35;
	-webkit-line-clamp: 2;
	-webkit-box-orient: vertical;
}

@media (hover: none) {
	.pfg-card-view {
		display: none;
	}
}

@media (prefers-reduced-motion: reduce) {
	.pfg-holder,
	.pfg-card-cover,
	.pfg-card-view,
	.pfg-modal-backdrop,
	.pfg-modal-dialog {
		transition: none;
	}
}

/* ------------------------------------------------------------------ */
/* Botón Cuadrícula / Cover Flow                                        */
/* ------------------------------------------------------------------ */

.pfg-gallery-bar {
	display: flex;
	justify-content: flex-end;
	margin-bottom: 16px;
}

.pfg-view-toggle {
	display: inline-flex;
	gap: 2px;
	padding: 3px;
	background: #eef0f3;
	border-radius: 999px;
}

.pfg-view-toggle button {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	min-height: 0;
	margin: 0;
	padding: 8px 14px;
	font: 600 13px/1 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
	letter-spacing: normal;
	text-transform: none;
	color: #4b5563;
	background: transparent;
	border: 0;
	border-radius: 999px;
	box-shadow: none;
	cursor: pointer;
	-webkit-appearance: none;
	appearance: none;
	transition: background-color 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}

.pfg-view-toggle button:hover {
	color: #111827;
	background: rgba(255, 255, 255, 0.6);
}

.pfg-view-toggle button[aria-pressed="true"] {
	color: #111827;
	background: #fff;
	box-shadow: 0 1px 3px rgba(15, 23, 42, 0.15);
}

.pfg-view-toggle button:focus-visible {
	outline: 2px solid var(--pfg-accent);
	outline-offset: 1px;
}

.pfg-view-toggle svg {
	display: block;
	flex: none;
}

/* ------------------------------------------------------------------ */
/* Cover Flow (carrusel 3D circular estilo iPod)                        */
/* ------------------------------------------------------------------ */

.pfg-gallery.is-coverflow {
	--pfg-cf-size: clamp(140px, 30vw + 40px, 270px);
	position: relative;
	display: block;
	height: calc(var(--pfg-cf-size) * 1.4 * 1.42 + 40px);
	overflow: hidden;
	background: radial-gradient(ellipse 80% 70% at 50% 35%, #2b2f38 0%, #111318 55%, #050506 100%);
	border-radius: var(--pfg-radius) var(--pfg-radius) 0 0;
	perspective: 1100px;
	perspective-origin: 50% 40%;
	touch-action: pan-y;
	-webkit-user-select: none;
	user-select: none;
	outline: none;
}

.pfg-gallery.is-coverflow:focus-visible {
	box-shadow: inset 0 0 0 2px var(--pfg-accent);
}

.pfg-gallery.is-coverflow .pfg-card {
	position: absolute;
	top: 32px;
	left: 50%;
	width: var(--pfg-cf-size);
	margin-left: calc(var(--pfg-cf-size) / -2);
	transform-style: preserve-3d;
	transition: transform 0.55s cubic-bezier(0.22, 0.61, 0.36, 1), opacity 0.4s ease;
	will-change: transform;
	-webkit-tap-highlight-color: transparent;
}

.pfg-gallery.is-coverflow .pfg-card-cover {
	align-items: flex-end;
	padding: 0;
	overflow: visible;
	background: none;
	border-radius: 0;
	transition: filter 0.4s ease;
}

.pfg-gallery.is-coverflow .pfg-card:hover .pfg-card-cover,
.pfg-gallery.is-coverflow .pfg-card:focus-visible .pfg-card-cover {
	transform: none;
	box-shadow: none;
}

.pfg-gallery.is-coverflow .pfg-card:not(.is-active) .pfg-card-cover {
	filter: brightness(0.72);
}

.pfg-gallery.is-coverflow .pfg-card-placeholder {
	align-items: flex-end;
}

/* Reflejo en el «suelo», como en el iPod */
.pfg-gallery.is-coverflow .pfg-card-cover img,
.pfg-gallery.is-coverflow .pfg-card-placeholder canvas,
.pfg-gallery.is-coverflow .pfg-card-placeholder:not(.has-thumb)::before {
	border-radius: 2px;
	box-shadow: 0 18px 40px -14px rgba(0, 0, 0, 0.8);
	-webkit-box-reflect: below 3px linear-gradient(transparent 60%, rgba(255, 255, 255, 0.24));
}

.pfg-gallery.is-coverflow .pfg-card-title,
.pfg-gallery.is-coverflow .pfg-card-badge,
.pfg-gallery.is-coverflow .pfg-card:not(.is-active) .pfg-card-view {
	display: none;
}

.pfg-gallery.is-coverflow .pfg-card:focus-visible {
	outline: none;
}

.pfg-gallery.is-coverflow .pfg-card.is-active:focus-visible .pfg-card-cover img,
.pfg-gallery.is-coverflow .pfg-card.is-active:focus-visible .pfg-card-placeholder canvas {
	outline: 2px solid var(--pfg-accent);
	outline-offset: 3px;
}

.pfg-cf-nav {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 16px;
	padding: 6px 16px 20px;
	color: #f3f4f6;
	background: #050506;
	border-radius: 0 0 var(--pfg-radius) var(--pfg-radius);
}

.pfg-cf-nav[hidden] {
	display: none;
}

.pfg-cf-caption {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 4px;
	min-width: 0;
	max-width: 520px;
	flex: 1;
	text-align: center;
	font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.pfg-cf-title {
	max-width: 100%;
	overflow: hidden;
	font-size: 16px;
	font-weight: 600;
	line-height: 1.35;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.pfg-cf-meta {
	font-size: 12px;
	font-variant-numeric: tabular-nums;
	color: #9ca3af;
}

.pfg-cf-nav .pfg-cf-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	flex: none;
	width: 42px;
	height: 42px;
	min-height: 0;
	margin: 0;
	padding: 0;
	color: #f3f4f6;
	background: rgba(255, 255, 255, 0.1);
	border: 0;
	border-radius: 50%;
	box-shadow: none;
	cursor: pointer;
	-webkit-appearance: none;
	appearance: none;
	transition: background-color 0.15s ease;
}

.pfg-cf-nav .pfg-cf-btn:hover {
	color: #fff;
	background: rgba(255, 255, 255, 0.2);
}

.pfg-cf-nav .pfg-cf-btn:focus-visible {
	outline: 2px solid var(--pfg-accent);
	outline-offset: 2px;
}

.pfg-cf-nav .pfg-cf-btn:disabled {
	opacity: 0.3;
	cursor: default;
}

.pfg-cf-nav .pfg-cf-btn svg {
	display: block;
	width: 22px;
	height: 22px;
}

@media (prefers-reduced-motion: reduce) {
	.pfg-gallery.is-coverflow .pfg-card {
		transition: opacity 0.2s ease;
	}
}

/* Aviso visible solo para editores */
.pfg-notice {
	padding: 10px 14px;
	font-size: 14px;
	color: #7c2d12;
	background: #fff7ed;
	border-left: 4px solid #f97316;
	border-radius: 4px;
}
