/* Le texte reste dans le même DOM pour les deux modes de lecture. */
.hc-lecture-modes[hidden],
.hc-lecture-modes button[hidden],
.hc-livre-navigation[hidden] {
	display: none;
}

.hc-livre-ecran-ouvert,
.hc-livre-ecran-ouvert body { overflow: hidden; }

.hc-mode-livre.hc-livre-plein-ecran {
	position: fixed;
	inset: 0;
	z-index: 10000;
	width: 100%;
	height: 100vh;
	height: 100dvh;
	max-width: none;
	margin: 0;
	padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
	border: 0;
	border-radius: 0;
	display: flex;
	flex-direction: column;
	background: var(--hc-fond-carte);
}
.hc-livre-plein-ecran > h2 { display: none; }
.hc-livre-plein-ecran .hc-lecture-modes {
	flex-shrink: 0;
	margin: 0 0 12px;
}
.hc-mode-livre.hc-livre-plein-ecran .hc-livre-vue {
	flex: 1;
	min-height: 0;
	height: 0;
	width: min(100%, calc((100dvh - 130px) * 1.35));
}
.hc-mode-livre.hc-livre-plein-ecran .hc-corps-histoire { height: 100%; }
.hc-livre-plein-ecran .hc-livre-navigation { flex-shrink: 0; margin-top: 10px; }
.hc-livre-plein-ecran::backdrop { background: var(--hc-fond-carte); }

.hc-lecture-modes {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	position: sticky;
	top: calc(var(--hc-hauteur-entete, 130px) + 8px);
	z-index: 5;
	width: fit-content;
	max-width: 100%;
	padding: 6px;
	margin: 16px 0 24px;
	border: 1px solid var(--hc-bordure);
	border-radius: 12px;
	background: var(--hc-fond-carte);
}

.hc-lecture-modes button,
.hc-livre-navigation button {
	min-height: 44px;
	padding: 9px 16px;
	border: 1px solid var(--hc-bordure);
	border-radius: 8px;
	background: var(--hc-fond-carte);
	color: var(--hc-accent-fonce);
	font: inherit;
	font-size: 0.9rem;
	font-weight: 600;
	cursor: pointer;
}

.hc-lecture-modes button[aria-pressed="true"] {
	background: var(--hc-accent);
	border-color: var(--hc-accent);
	color: #fff;
}

.hc-livre-navigation button:hover:not(:disabled),
.hc-lecture-modes button:hover:not([aria-pressed="true"]) {
	background: var(--hc-accent-clair);
}

.hc-livre-navigation button:disabled {
	opacity: 0.45;
	cursor: default;
}

.hc-lecture-modes button:focus-visible,
.hc-livre-navigation button:focus-visible,
.hc-navigation-clavier .hc-livre-vue:focus-visible {
	outline: 2px solid var(--hc-accent);
	outline-offset: 4px;
}

.hc-lecture-wrap:has(.hc-mode-livre) {
	max-width: 1120px;
}

.hc-mode-livre {
	--hc-livre-hauteur: clamp(440px, calc(100svh - var(--hc-hauteur-entete, 130px) - 220px), 700px);
	--hc-livre-gouttiere: 88px;
	--hc-livre-colonnes: 2;
	--hc-papier: #fbf7ee;
	border-radius: var(--hc-radius);
}

.hc-mode-livre .hc-lecture-modes {
	position: static;
}

.hc-mode-livre .hc-livre-vue {
	touch-action: pan-y pinch-zoom;
	position: relative;
	overflow: hidden;
	overflow: clip;
	width: min(100%, calc(var(--hc-livre-hauteur) * 1.35));
	margin: 12px auto 18px;
	padding: 0 42px;
	border: 1px solid #ded4c2;
	border-radius: 5px 12px 12px 5px;
	background: linear-gradient(90deg, #f1eadc 0%, var(--hc-papier) 3%, var(--hc-papier) 47%, #eee5d5 49.3%, #b9aa91 50%, #eee5d5 50.7%, var(--hc-papier) 53%, var(--hc-papier) 97%, #f1eadc 100%);
	box-shadow: 0 2px 0 #e2d8c6, 0 4px 0 #fbf7ee, 0 6px 0 #d6cbb8,
		0 9px 0 3px #674635, 0 14px 24px rgba(43,36,32,.2);
}
.hc-mode-livre .hc-livre-vue:focus:not(:focus-visible),
.hc-mode-livre:not(.hc-navigation-clavier) .hc-livre-vue:focus {
	outline: none;
}
.hc-livre-folios {
	position: absolute;
	left: 0;
	right: 0;
	bottom: 16px;
	display: grid;
	grid-template-columns: repeat(var(--hc-livre-colonnes), 1fr);
	text-align: center;
	font: 0.8rem var(--hc-serif);
	color: var(--hc-texte-doux);
	pointer-events: none;
}
:not(.hc-mode-livre) > .hc-livre-vue > .hc-livre-folios { display: none; }
.hc-livre-folios span[hidden] { display: none; }
.hc-livre-image .hc-livre-folios { display: block; }
.hc-livre-navigation {
	width: 100%;
	max-width: 980px;
	margin-left: auto;
	margin-right: auto;
}

.hc-livre-animation {
	position: absolute;
	inset: 0;
	perspective: 1800px;
	pointer-events: none;
	z-index: 2;
}

.hc-mode-livre .hc-coin-droite,
.hc-mode-livre .hc-coin-gauche { cursor: grab; }
.hc-mode-livre .hc-saisie { cursor: grabbing; user-select: none; }
.hc-mode-livre .hc-coin-droite:not(.hc-saisie)::after,
.hc-mode-livre .hc-coin-gauche:not(.hc-saisie)::after {
	content: "";
	position: absolute;
	bottom: 0;
	width: 24px;
	height: 24px;
	background: linear-gradient(135deg, transparent 49%, var(--hc-bordure) 50%, #fffdf9 80%);
	pointer-events: none;
}
.hc-coin-droite::after { right: 0; }
.hc-coin-gauche::after { left: 0; transform: scaleX(-1); }
.hc-coin-haut::after { top: 0; bottom: auto !important; scale: 1 -1; }

.hc-livre-feuille {
	position: absolute;
	top: 0;
	height: 100%;
	transform-style: preserve-3d;
	z-index: 2;
}

.hc-livre-image {
	position: absolute;
	top: 0;
	height: 100%;
	overflow: hidden;
	background: var(--hc-papier);
}

.hc-livre-recto,
.hc-livre-verso {
	backface-visibility: hidden;
	box-shadow: 0 8px 24px rgba(43, 36, 32, 0.24);
}

.hc-livre-verso { transform: rotateY(180deg); }
.hc-livre-image::after {
	content: "";
	position: absolute;
	inset: 0;
	background: linear-gradient(90deg, rgba(43, 36, 32, 0.13), transparent 15%, transparent 80%, rgba(43, 36, 32, 0.06));
}

.hc-mode-livre .hc-livre-copie {
	position: absolute;
	top: 0;
	margin: 0;
}

.hc-mode-livre .hc-corps-histoire {
	height: var(--hc-livre-hauteur);
	column-count: var(--hc-livre-colonnes);
	column-gap: var(--hc-livre-gouttiere);
	column-fill: auto;
	padding: 36px 0 56px;
	font-family: var(--hc-serif);
	font-size: 1.08rem;
	line-height: 1.65;
	overflow-wrap: anywhere;
}

.hc-mode-livre .hc-corps-histoire > :first-child {
	margin-top: 0;
}

.hc-mode-livre .hc-corps-histoire p {
	margin: 0 0 0.18em;
	orphans: 2;
	widows: 2;
}
.hc-mode-livre .hc-corps-histoire p + p:not(.hc-livre-dialogue) {
	text-indent: 1.15em;
}

.hc-mode-livre .hc-corps-histoire p:last-child {
	margin-bottom: 0;
}

.hc-mode-livre .hc-corps-histoire h2,
.hc-mode-livre .hc-corps-histoire h3,
.hc-mode-livre .hc-corps-histoire h4 {
	break-after: avoid;
}

.hc-mode-livre .hc-corps-histoire img,
.hc-mode-livre .hc-corps-histoire video {
	max-width: 100%;
	max-height: calc(var(--hc-livre-hauteur) - 40px);
	object-fit: contain;
}

.hc-mode-livre .hc-corps-histoire pre {
	white-space: pre-wrap;
}

.hc-mode-livre .hc-corps-histoire table {
	max-width: 100%;
	table-layout: fixed;
}

.hc-livre-navigation {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	margin-top: 18px;
}

.hc-livre-pagination {
	color: var(--hc-texte-doux);
	font-size: 0.85rem;
	font-variant-numeric: tabular-nums;
	text-align: center;
}

@media (max-width: 760px) {
	.hc-lecture-modes {
		display: grid;
		grid-template-columns: repeat(2, minmax(0, 1fr));
		width: 100%;
	}

	.hc-lecture-modes button {
		padding: 8px;
		font-size: 0.85rem;
	}
	.hc-lecture-modes [data-livre-plein-ecran] { grid-column: 1 / -1; }

	.hc-mode-livre {
		--hc-livre-hauteur: clamp(360px, calc(100svh - var(--hc-hauteur-entete, 130px) - 270px), 650px);
		--hc-livre-colonnes: 1;
		--hc-livre-gouttiere: 48px;
	}

	.hc-mode-livre .hc-livre-vue {
		width: min(100%, 440px);
		padding: 0 22px;
		background: linear-gradient(90deg, #eee5d5, var(--hc-papier) 5%, var(--hc-papier) 97%, #eee5d5);
	}
	.hc-mode-livre .hc-corps-histoire { padding-top: 28px; font-size: 1rem; }
	.hc-mode-livre.hc-livre-plein-ecran .hc-livre-vue { width: min(100%, 480px); }

	.hc-livre-navigation {
		display: grid;
		grid-template-columns: repeat(2, minmax(0, 1fr));
		gap: 8px;
	}

	.hc-livre-pagination {
		grid-column: 1 / -1;
		grid-row: 1;
	}

	.hc-livre-navigation button {
		padding: 8px 12px;
	}
}

@media print {
	.hc-mode-livre.hc-livre-plein-ecran {
		position: static;
		height: auto;
		display: block;
	}
	.hc-mode-livre.hc-livre-plein-ecran .hc-livre-vue,
	.hc-mode-livre.hc-livre-plein-ecran .hc-corps-histoire { height: auto; }
	.hc-livre-animation { display: none; }
	.hc-livre-folios { display: none; }
	.hc-lecture-modes,
	.hc-livre-navigation {
		display: none;
	}

	.hc-mode-livre .hc-livre-vue {
		overflow: visible;
		background: none;
		border: 0;
		box-shadow: none;
		width: auto;
	}

	.hc-mode-livre .hc-corps-histoire {
		height: auto;
		columns: auto;
		transform: none !important;
	}
}
