/*
 * Les pages d'un numéro défilent comme un journal qu'on feuillette.
 * Chargé uniquement sur le site : dans l'éditeur, la galerie reste une grille.
 */

.bn-pages .wp-block-gallery.has-nested-images {
	display: flex;
	flex-wrap: nowrap !important;
	gap: 24px;
	overflow-x: auto;
	scroll-snap-type: x mandatory;
	scroll-behavior: smooth;
	overscroll-behavior-x: contain;
	padding: 4px 4px 16px;
	scrollbar-width: thin;
	scrollbar-color: rgba(17, 19, 23, 0.35) transparent;
}

.bn-pages .wp-block-gallery.has-nested-images:focus-visible {
	outline: 3px solid var(--wp--preset--color--red);
	outline-offset: 4px;
}

.bn-pages .wp-block-gallery.has-nested-images figure.wp-block-image:not(#individual-image) {
	/* Deux pages côte à côte, jamais plus hautes que l'écran (format A4 ≈ 0,707) */
	flex: 0 0 min(calc(50% - 12px), calc((100vh - 240px) * 0.707)) !important;
	width: auto !important;
	max-width: none;
	margin: 0 !important;
	scroll-snap-align: start;
}

.bn-pages .wp-block-gallery.has-nested-images figure.wp-block-image img {
	width: 100%;
	height: auto;
	object-fit: contain;
	transform: none !important;
}

.bn-slider-nav {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 20px;
	margin-top: 20px;
}

.bn-slider-nav button {
	width: 48px;
	height: 48px;
	border-radius: 50%;
	border: 2px solid var(--wp--preset--color--ink);
	background: transparent;
	color: var(--wp--preset--color--ink);
	font-size: 1.4rem;
	line-height: 1;
	cursor: pointer;
	display: inline-flex;
	align-items: center;
	justify-content: center;
}

.bn-slider-nav button:hover:not(:disabled) {
	background: var(--wp--preset--color--red);
	border-color: var(--wp--preset--color--red);
	color: #fff;
}

.bn-slider-nav button:disabled {
	opacity: 0.3;
	cursor: default;
}

.bn-slider-count {
	min-width: 9em;
	text-align: center;
	font-family: var(--wp--preset--font-family--display);
	font-weight: 700;
	font-size: 0.8rem;
	letter-spacing: 0.16em;
	text-transform: uppercase;
	color: #3A342E;
}

@media (max-width: 781px) {
	.bn-pages .wp-block-gallery.has-nested-images figure.wp-block-image:not(#individual-image) {
		flex-basis: min(86%, calc((100vh - 200px) * 0.707)) !important;
	}
}

/* ---------- Visionneuse plein écran ---------- */

.bn-pages .lightbox-trigger {
	display: none !important;
}

.bn-pages .wp-block-gallery figure.wp-block-image img {
	cursor: zoom-in;
}

.bn-viewer-lock,
.bn-viewer-lock body {
	overflow: hidden;
}

.bn-viewer {
	position: fixed;
	inset: 0;
	z-index: 100000;
	display: none;
	background: #0A0B0D;
	color: #F4E8D8;
}

.bn-viewer.is-open {
	display: block;
}

.bn-viewer-bar {
	position: absolute;
	top: 0;
	left: 0;
	right: 0;
	z-index: 2;
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 10px 12px 10px 20px;
	background: linear-gradient(rgba(10, 11, 13, 0.9), rgba(10, 11, 13, 0));
}

.bn-viewer-count {
	font-family: var(--wp--preset--font-family--display);
	font-weight: 700;
	font-size: 0.85rem;
	letter-spacing: 0.16em;
}

.bn-viewer button {
	width: 52px;
	height: 52px;
	border: 0;
	border-radius: 50%;
	background: rgba(244, 232, 216, 0.14);
	color: #F4E8D8;
	font-size: 1.5rem;
	line-height: 1;
	cursor: pointer;
	display: inline-flex;
	align-items: center;
	justify-content: center;
}

.bn-viewer button:hover:not(:disabled),
.bn-viewer button:focus-visible {
	background: var(--wp--preset--color--red);
	color: #fff;
	outline: none;
}

.bn-viewer-track {
	display: flex;
	height: 100%;
	overflow-x: auto;
	scroll-snap-type: x mandatory;
	scroll-behavior: smooth;
	overscroll-behavior: contain;
	scrollbar-width: none;
}

.bn-viewer-track::-webkit-scrollbar {
	display: none;
}

.bn-viewer-slide {
	flex: 0 0 100%;
	height: 100%;
	scroll-snap-align: center;
	scroll-snap-stop: always;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 64px 12px 16px;
	box-sizing: border-box;
}

.bn-viewer-slide img {
	max-width: 100%;
	max-height: 100%;
	width: auto;
	height: auto;
	object-fit: contain;
	background: #fff;
	box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
	/* Le zoom est géré par le script : le navigateur ne garde que le glissement horizontal */
	transform-origin: 0 0;
	touch-action: pan-x;
	user-select: none;
	-webkit-user-select: none;
	-webkit-touch-callout: none;
	cursor: zoom-in;
}

.bn-viewer-slide {
	overflow: hidden;
}

.bn-viewer-slide img.is-zoomed {
	touch-action: none;
	cursor: grab;
}

.bn-viewer-track.is-zoomed {
	overflow-x: hidden;
}

.bn-viewer-prev,
.bn-viewer-next {
	position: absolute;
	top: 50%;
	transform: translateY(-50%);
	z-index: 2;
}

.bn-viewer-prev {
	left: 16px;
}

.bn-viewer-next {
	right: 16px;
}

.bn-viewer button:disabled {
	opacity: 0;
	pointer-events: none;
}

/* Sur téléphone, on glisse : pas de flèches par-dessus la page */
@media (max-width: 781px) {
	.bn-viewer .bn-viewer-prev,
	.bn-viewer .bn-viewer-next {
		display: none;
	}
}

/* ---------- Feuilletage (page qui se tourne) ---------- */

.bn-pages .wp-block-gallery.bn-has-book {
	display: none !important;
}

.bn-book-wrap {
	display: flex;
	justify-content: center;
	padding: 8px 0 4px;
	outline: none;
}

.bn-book-wrap:focus-visible {
	outline: 3px solid var(--wp--preset--color--red);
	outline-offset: 6px;
}

.bn-book {
	margin: 0 auto;
	filter: drop-shadow(0 18px 30px rgba(17, 19, 23, 0.35));
}

.bn-book-page {
	background: #fff;
	cursor: zoom-in;
}

.bn-book-page img {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: contain;
	pointer-events: none;
	user-select: none;
	-webkit-user-select: none;
}

/* Le glissement horizontal sur le journal tourne les pages ; le vertical fait défiler la page web */
.bn-book {
	touch-action: pan-y;
	user-select: none;
	-webkit-user-select: none;
}

/* ---------- Le journal en plein écran ---------- */

.bn-viewer-stage {
	position: absolute;
	top: 64px;
	bottom: 16px;
	left: 12px;
	right: 12px;
	display: flex;
	align-items: center;
	justify-content: center;
}

@media (min-width: 782px) {
	.bn-viewer-stage {
		left: 84px;
		right: 84px;
	}
}

/* Tout geste sur le journal est pour lui (tourner, pincer), rien pour la page web */
.bn-viewer .bn-book {
	width: 100%;
	touch-action: none;
	filter: drop-shadow(0 20px 40px rgba(0, 0, 0, 0.6));
}

.bn-viewer .bn-book-page {
	cursor: grab;
}

/* Page ouverte en zoom (pincer ou double-tap) */
.bn-zoom {
	position: absolute;
	inset: 0;
	z-index: 1;
	display: none;
	align-items: center;
	justify-content: center;
	padding: 64px 12px 16px;
	box-sizing: border-box;
	overflow: hidden;
	background: rgba(10, 11, 13, 0.97);
}

.bn-zoom.is-open {
	display: flex;
}

.bn-zoom img {
	max-width: 100%;
	max-height: 100%;
	width: auto;
	height: auto;
	object-fit: contain;
	background: #fff;
	box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
	transform-origin: 0 0;
	touch-action: none;
	user-select: none;
	-webkit-user-select: none;
	-webkit-touch-callout: none;
	cursor: zoom-in;
}

.bn-zoom img.is-zoomed {
	cursor: grab;
}

/* Les flèches restent au-dessus du zoom mais n'y servent pas */
.bn-viewer:has(.bn-zoom.is-open) .bn-viewer-prev,
.bn-viewer:has(.bn-zoom.is-open) .bn-viewer-next {
	display: none;
}
