/**
 * Lecteur des chapitres MangaDex (module mangadex, contrat §8 bis).
 *
 * Couleurs du thème actif (html[data-yn-theme]) par les variables --wp--preset--color--* ;
 * les images ne sont jamais retouchées. Une page pas encore chargée garde un format de page
 * (7/10) pour que le chargement différé ne charge pas tout le chapitre d'un coup.
 *
 * Largeurs (posées par manga.js, en px, sur .yn-manga ; lot A 2.8.0) :
 *   --yn-manga-fenetre   largeur utile de la fenêtre (sans la barre de défilement)
 *   --yn-manga-colonne   largeur de la colonne (.yn-manga__pages)
 *   --yn-manga-decalage  centre de la fenêtre − centre de la colonne (centrage sur la fenêtre)
 *   --yn-manga-zoom      1 (Auto) ou 0,5 … 3 (data-yn-zoom="manuel")
 * et sur chaque image chargée : --yn-manga-naturelle (largeur naturelle, px) et
 * --yn-manga-ratio (largeur / hauteur). Largeur rendue = largeur « auto » × zoom ; une image plus
 * large que sa figure y défile horizontalement, la page du site ne déborde jamais.
 */

/* Colonne plus large que pour le texte : une page de manga se lit en grand. */
.yn-reader:has(.yn-manga) {
	max-width: min(960px, 100%);
}

.yn-manga {
	--yn-manga-zoom: 1;
	--yn-manga-fenetre: 100vw;
	--yn-manga-colonne: 100%;
	--yn-manga-decalage: 0px;
	--yn-manga-hauteur: calc(100vh - 140px);

	/* Cadre d'une double page : déborde de la colonne, sans dépasser la fenêtre (16 px de marge
	   de chaque côté), deux colonnes ni 1920 px. */
	--yn-manga-large: max(var(--yn-manga-colonne), min(var(--yn-manga-fenetre) - 32px, 2 * var(--yn-manga-colonne), 1920px));

	/* Cadre d'une page zoomée : toute la largeur utile de la fenêtre. */
	--yn-manga-ample: max(var(--yn-manga-colonne), min(var(--yn-manga-fenetre) - 32px, 1920px));
	text-align: center;
	-webkit-hyphens: manual;
	hyphens: manual;
}

.yn-manga__outils {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: center;
	gap: 8px 16px;
	margin: 0 0 1.2em;
	font-family: var(--wp--preset--font-family--corps);
}

.yn-manga__outils[hidden],
.yn-manga__navigation[hidden] {
	display: none;
}

.yn-manga__choix {
	display: inline-flex;
	flex-wrap: wrap;
	gap: 6px;
}

.yn-manga [aria-pressed="true"] {
	border-color: var(--wp--preset--color--accent);
	background: var(--wp--preset--color--selection);
	color: var(--wp--preset--color--texte-fort);
}

.yn-manga__pages {
	display: flex;
	flex-direction: column;
	align-items: center;
}

.yn-manga__page {
	width: 100%;
	margin: 0;
	scroll-margin-top: 80px;
}

.yn-manga__page img {
	display: block;
	width: 100%;
	height: auto;
	margin-inline: auto;
	aspect-ratio: 7 / 10;
	object-fit: contain;
	background: var(--wp--preset--color--carte);
}

.yn-manga__page img.is-chargee {
	--yn-manga-base: min(var(--yn-manga-naturelle), var(--yn-manga-colonne));
	width: calc(var(--yn-manga-base) * var(--yn-manga-zoom));
	max-width: none;
	aspect-ratio: auto;
	background: none;
}

.yn-manga__page img.is-chargee.is-paysage {
	--yn-manga-base: min(var(--yn-manga-naturelle), var(--yn-manga-large));
}

/* Double page (largeur > hauteur) et page zoomée : la figure sort de la colonne, centrée sur la
   fenêtre ; sa boîte de marge garde la largeur de la colonne (rien ne bouge autour). */
.yn-manga__page.is-paysage,
.yn-manga[data-yn-zoom="manuel"] .yn-manga__page.is-chargee {
	--yn-manga-cadre: var(--yn-manga-large);
	align-self: flex-start;
	box-sizing: border-box;
	width: var(--yn-manga-cadre);
	max-width: none;
	margin-right: calc((var(--yn-manga-colonne) - var(--yn-manga-cadre)) / 2 - var(--yn-manga-decalage));
	margin-left: calc((var(--yn-manga-colonne) - var(--yn-manga-cadre)) / 2 + var(--yn-manga-decalage));
}

.yn-manga[data-yn-zoom="manuel"] .yn-manga__page.is-chargee {
	--yn-manga-cadre: var(--yn-manga-ample);
	overflow-x: auto;
	overflow-y: hidden;
	overscroll-behavior-x: contain;
}

/* Double appui : bascule du zoom (manga.js) ; le pincement du navigateur reste permis. */
.yn-manga__page {
	touch-action: manipulation;
}

/* Page par page : une seule page, entière à l'écran sous la barre de lecture, boutons compris
   (sauf bande verticale de webtoon). */
.yn-manga[data-yn-mode="page"] .yn-manga__page {
	display: none;
	cursor: pointer;
	-webkit-user-select: none;
	user-select: none;
}

.yn-manga[data-yn-mode="page"] .yn-manga__page.is-courante {
	display: block;
}

/* Cadre d'une page pas encore chargée : format de page (7/10) qui tient aussi à l'écran ; la
   largeur est bornée par la hauteur disponible pour garder la proportion. */
.yn-manga[data-yn-mode="page"] .yn-manga__page img:not(.is-chargee) {
	width: min(100%, calc((100vh - 140px) * 0.7));
	width: min(100%, calc((100dvh - 140px) * 0.7));
}

/* Page chargée : entière à l'écran (largeur bornée aussi par la hauteur disponible), une double
   page dans son cadre élargi ; le zoom multiplie cette largeur. */
.yn-manga[data-yn-mode="page"] .yn-manga__page img.is-chargee:not(.is-longue) {
	--yn-manga-base: min(var(--yn-manga-naturelle), var(--yn-manga-colonne), var(--yn-manga-hauteur) * var(--yn-manga-ratio));
}

.yn-manga[data-yn-mode="page"] .yn-manga__page img.is-chargee.is-paysage:not(.is-longue) {
	--yn-manga-base: min(var(--yn-manga-naturelle), var(--yn-manga-large), var(--yn-manga-hauteur) * var(--yn-manga-ratio));
}

@supports (height: 100dvh) {
	.yn-manga {
		--yn-manga-hauteur: calc(100dvh - 140px);
	}
}

.yn-manga__navigation {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: center;
	gap: 8px 16px;
	margin: 1em 0 0;
	font-family: var(--wp--preset--font-family--corps);
}

.yn-manga__compteur {
	min-width: 9em;
}

.yn-manga__zoom {
	align-items: center;
}

.yn-manga__zoom [data-yn-manga-zoom="moins"],
.yn-manga__zoom [data-yn-manga-zoom="plus"] {
	min-width: 2.25em;
	font-weight: 700;
}

.yn-manga__zoom-valeur {
	min-width: 3.6em;
	font-variant-numeric: tabular-nums;
}

.yn-manga__erreur {
	margin: 1em 0;
	padding: 2em 1em;
	border: 1px dashed var(--wp--preset--color--bordure);
	border-radius: var(--yn-radius, 8px);
	color: var(--wp--preset--color--texte-faible);
	font-family: var(--wp--preset--font-family--corps);
}

.yn-manga__source {
	margin: 1.2em 0 0;
	color: var(--wp--preset--color--texte-faible);
}

.yn-manga--vide p,
.yn-manga--coupe p {
	font-family: var(--wp--preset--font-family--corps);
}

/* Libellés centrés malgré la remise à zéro de .yn-reader :where(.yn-label) (reader.css). */
.yn-manga .yn-label {
	text-align: center;
}
