/* Ecista Flipbook
 * Colori personalizzabili dal tema, ad esempio:
 * .efb { --efb-bg: #e9eef2; --efb-ink: #1d2b36; }
 */

.efb {
	--efb-ratio: 1.4142;
	--efb-bg: #ecebe8;
	--efb-ink: #2a2a2a;
	--efb-btn-bg: #ffffff;
	--efb-focus: #1a5fb4;
	--efb-toolbar-h: 64px;

	position: relative;
	box-sizing: border-box;
	width: 100%;
	margin: 1.5em 0;
	padding: 28px 16px 8px;
	background: var(--efb-bg);
	color: var(--efb-ink);
	border-radius: 6px;
	outline: none;
	overflow: hidden;
}

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

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

/* L'area del libro non supera mai l'altezza dello schermo */
.efb-stage {
	position: relative;
	width: 100%;
	margin: 0 auto;
	max-width: calc((85vh - var(--efb-toolbar-h)) / var(--efb-ratio) * 2);
}

.efb.is-loading .efb-stage,
.efb.has-error .efb-stage {
	aspect-ratio: 2 / var(--efb-ratio);
	max-height: 70vh;
}

.efb-book {
	filter: drop-shadow(0 10px 18px rgba(30, 30, 30, 0.18));
}

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

.efb-page-inner {
	width: 100%;
	height: 100%;
	display: flex;
	align-items: center;
	justify-content: center;
	background: #fff;
}

.efb-page-inner canvas {
	display: block;
	width: 100% !important;
	height: 100% !important;
	max-width: none;
}

/* Caricamento ed errori */
.efb-loader {
	position: absolute;
	inset: 0;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 12px;
	font-size: 14px;
	text-align: center;
	z-index: 2;
}

.efb:not(.is-loading):not(.has-error) .efb-loader {
	display: none;
}

.efb-spinner,
.efb-page-spinner {
	width: 28px;
	height: 28px;
	border: 3px solid rgba(0, 0, 0, 0.12);
	border-top-color: currentColor;
	border-radius: 50%;
	animation: efb-spin 0.9s linear infinite;
}

.efb-page-spinner {
	width: 20px;
	height: 20px;
	color: #999;
}

.efb-error {
	max-width: 32ch;
	padding: 0 16px;
}

.efb.has-error .efb-toolbar [data-efb] {
	display: none;
}

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

/* Barra dei comandi */
.efb-toolbar {
	display: flex;
	align-items: center;
	justify-content: center;
	flex-wrap: wrap;
	gap: 6px;
	min-height: var(--efb-toolbar-h);
	padding: 10px 0;
}

.efb .efb-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 40px;
	height: 40px;
	margin: 0;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: var(--efb-btn-bg);
	color: var(--efb-ink);
	box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
	cursor: pointer;
	text-decoration: none;
	line-height: 1;
	transition: transform 0.15s ease, opacity 0.15s ease;
}

.efb .efb-btn:hover:not(:disabled) {
	transform: translateY(-1px);
}

.efb .efb-btn:focus-visible {
	outline: 3px solid var(--efb-focus);
	outline-offset: 2px;
}

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

.efb .efb-btn svg {
	display: block;
	pointer-events: none;
}

.efb-counter {
	min-width: 84px;
	padding: 0 6px;
	font-size: 14px;
	font-variant-numeric: tabular-nums;
	text-align: center;
}

.efb-sep {
	width: 1px;
	height: 22px;
	margin: 0 6px;
	background: currentColor;
	opacity: 0.2;
}

.efb .efb-ico-exit { display: none; }
.efb.efb-is-fs .efb-ico-exit { display: inline; }
.efb.efb-is-fs .efb-ico-enter { display: none; }

/* Schermo intero (nativo e simulato su iPhone) */
.efb:fullscreen,
.efb.efb-is-fs {
	display: flex;
	flex-direction: column;
	justify-content: center;
	width: 100vw;
	height: 100vh;
	height: 100dvh;
	margin: 0;
	padding: 20px 16px 0;
	border-radius: 0;
}

.efb.efb-is-fs:not(:fullscreen) {
	position: fixed;
	inset: 0;
	z-index: 999999;
}

.efb:fullscreen .efb-stage,
.efb.efb-is-fs .efb-stage {
	max-width: calc((100vh - var(--efb-toolbar-h) - 40px) / var(--efb-ratio) * 2);
}

html.efb-lock-scroll,
html.efb-lock-scroll body {
	overflow: hidden;
}

/* Schermi piccoli: una pagina alla volta */
@media (max-width: 600px) {
	.efb {
		padding: 16px 8px 4px;
	}
	.efb-stage {
		max-width: calc((85vh - var(--efb-toolbar-h)) / var(--efb-ratio));
	}
	.efb.is-loading .efb-stage {
		aspect-ratio: 1 / var(--efb-ratio);
	}
	.efb:fullscreen .efb-stage,
	.efb.efb-is-fs .efb-stage {
		max-width: calc((100vh - var(--efb-toolbar-h) - 40px) / var(--efb-ratio));
	}
	.efb [data-efb="first"],
	.efb [data-efb="last"] {
		display: none;
	}
}

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

.efb-notice {
	padding: 10px 14px;
	border-left: 4px solid #d63638;
	background: #fcf0f1;
	font-size: 14px;
}
