html, body {
	margin: 0;
	padding: 0;
	width: 100%;
	height: 100%;
	height: 100vh;
	height: 100dvh;
	overflow: hidden !important;
	position: fixed;
	inset: 0;
	background: #e8e6e2;
	overscroll-behavior: none;
}

.flip-stage {
	position: fixed;
	inset: 0;
	width: 100%;
	height: 100%;
	overflow: hidden;
	background: #e8e6e2;
	display: flex;
	align-items: center;
	justify-content: center;
}

.book-scale {
	transform-origin: center center;
	flex-shrink: 0;
	width: 840px;
	height: 595px;
}

.book {
	position: relative;
	width: 840px;
	height: 595px;
	overflow: hidden;
	background: #e8e6e2;
	box-shadow: 0 12px 48px rgba(0, 0, 0, 0.18);
	perspective: 2400px;
	perspective-origin: 50% 50%;
}

.spread {
	position: absolute;
	inset: 0;
	display: flex;
}

.spread.under {
	z-index: 1;
}

.spread.over {
	z-index: 2;
}

.leaf {
	position: relative;
	width: 50%;
	height: 100%;
	transform-style: preserve-3d;
	background: #e8e6e2;
}

.leaf.is-empty {
	background: #e8e6e2;
}

.leaf.is-empty > .face.front {
	visibility: hidden;
}

.face {
	position: absolute;
	inset: 0;
	overflow: hidden;
	background: #fff;
	backface-visibility: hidden;
	-webkit-backface-visibility: hidden;
}

.face iframe {
	display: block;
	width: 420px;
	height: 595px;
	border: none;
	background: #fff;
	overflow: hidden;
	transform-origin: 0 0;
}

.face.front {
	transform: rotateY(0deg);
	z-index: 2;
}

.face.back {
	transform: rotateY(180deg) translateZ(0.5px);
	z-index: 1;
	opacity: 0;
	visibility: hidden;
	pointer-events: none;
	background: #fff;
}

/*
 * Cambio de cara SOLO en el instante edge-on (~90°).
 * Los keyframes del leaf marcan 50% = -90°/90° para que coincida con el easing.
 */
.leaf.is-animating .face.back {
	visibility: visible;
	animation: flipShowBack 0.85s ease forwards;
}

.leaf.is-animating .face.front {
	animation: flipHideFront 0.85s ease forwards;
}

@keyframes flipShowBack {
	0%, 47% { opacity: 0; }
	53%, 100% { opacity: 1; }
}

@keyframes flipHideFront {
	0%, 47% { opacity: 1; }
	53%, 100% { opacity: 0; }
}

.book.cover-mode .spread.over .leaf.left {
	background: #ddd8d0;
}

.book.cover-mode .spread.over .leaf.left > .face.front {
	visibility: hidden;
}

.book.end-mode .spread.over .leaf.right {
	background: #ddd8d0;
}

.book.end-mode .spread.over .leaf.right > .face.front {
	visibility: hidden;
}

.leaf.is-animating {
	z-index: 5;
	will-change: transform;
}

.leaf.flip-next {
	transform-origin: left center;
}

.leaf.flip-prev {
	transform-origin: right center;
}

.leaf.flip-next.is-animating {
	/* keyframe 50% = 90°: el cruce de caras cae cuando la hoja es un filo */
	animation: bookFlipNext 0.85s ease forwards;
}

.leaf.flip-prev.is-animating {
	animation: bookFlipPrev 0.85s ease forwards;
}

@keyframes bookFlipNext {
	0% { transform: rotateY(0deg); }
	50% { transform: rotateY(-90deg); }
	100% { transform: rotateY(-180deg); }
}

@keyframes bookFlipPrev {
	0% { transform: rotateY(0deg); }
	50% { transform: rotateY(90deg); }
	100% { transform: rotateY(180deg); }
}

@media (prefers-reduced-motion: reduce) {
	.leaf.flip-next.is-animating,
	.leaf.flip-prev.is-animating,
	.leaf.is-animating .face.back,
	.leaf.is-animating .face.front {
		animation-duration: 0.01ms;
	}
}

.prev, .next {
	cursor: pointer;
	position: fixed;
	top: 50%;
	transform: translateY(-50%);
	z-index: 20;
	padding: 12px 16px;
	color: #111;
	font-weight: bold;
	font-size: clamp(22px, 4vw, 34px);
	visibility: hidden;
	user-select: none;
	-webkit-user-select: none;
	background: rgba(255, 255, 255, 0.7);
	border: none;
	line-height: 1;
}

.prev:hover, .next:hover {
	background: rgba(255, 255, 255, 0.92);
}

.next {
	right: 8px;
	border-radius: 3px 0 0 3px;
}

.prev {
	left: 8px;
	border-radius: 0 3px 3px 0;
}

@media (max-width: 700px) {
	.prev, .next {
		padding: 10px 12px;
	}

	.book {
		perspective: 1600px;
	}
}
