/*
 * Annonces (mu-plugin pixel-annonces.php) : la fenêtre sur le site
 *
 * Apparence réglable dans le thème, sur :root, sans toucher à ce fichier :
 *   --annonce-couleur          titres, bouton, filigrane      (défaut : couleur « principale » de theme.json)
 *   --annonce-couleur-texte    texte sur le bouton             (défaut : « blanc »)
 *   --annonce-fond             fond de la fenêtre              (défaut : « blanc »)
 *   --annonce-texte            couleur du texte                (défaut : « noir »)
 *   --annonce-police           police du texte                 (défaut : « texte »)
 *   --annonce-police-titre     police du titre                 (défaut : « titres »)
 *   --annonce-police-gras      police du gras dans le texte    (défaut : celle du texte, en graisse 700)
 *   --annonce-graisse-gras     graisse du gras                 (défaut : 700 ; « normal » si le gras est une police à part)
 *   --annonce-rayon            arrondi de la fenêtre           (défaut : 18px)
 *   --annonce-voile            voile derrière une annonce au centre
 * Le bouton porte aussi la classe « bouton » du thème (filtre pixel_annonces_classe_bouton) : ses styles l'emportent
 * sur ceux d'ici, écrits avec :where() pour ne rien imposer.
 */

.annonce {
	--_couleur: var(--annonce-couleur, var(--wp--preset--color--principale, #0b4f6c));
	--_couleur-texte: var(--annonce-couleur-texte, var(--wp--preset--color--blanc, #fff));
	--_fond: var(--annonce-fond, var(--wp--preset--color--blanc, #fff));
	--_texte: var(--annonce-texte, var(--wp--preset--color--noir, #1d1d1b));
	--_rayon: var(--annonce-rayon, 18px);
	--_ease: cubic-bezier(0.16, 1, 0.3, 1);
	--_marge: 24px;

	position: fixed;
	z-index: 9990;
	box-sizing: border-box;
	margin: 0;
	padding: 0;
	border: 0;
	background: transparent;
	color: var(--_texte);
	max-width: none;
	max-height: none;
	overflow: visible;
	font-family: var(--annonce-police, var(--wp--preset--font-family--texte, inherit));
	/* Au moins 16px même si le thème réduit la taille de base (html à 62,5 %, 1rem = 10px), et toujours davantage
	   si le visiteur agrandit le texte. Tailles intérieures en em : elles partent de celle-ci. */
	font-size: max(1rem, 16px);
	line-height: 1.55;
	text-align: left;
}

.annonce:not([open]) {
	display: none;
}

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

.annonce::backdrop {
	background: var(--annonce-voile, rgb(9 28 40 / 0.5));
	backdrop-filter: blur(3px);
}

:root.annonce_ouverte {
	overflow: hidden;
}

/* La boîte : tout ce qui se voit */
.annonce__boite {
	position: relative;
	max-height: inherit;
	overflow: hidden auto;
	overscroll-behavior: contain;
	border-radius: var(--_rayon);
	background: var(--_fond);
	box-shadow: 0 40px 90px -30px rgb(6 28 42 / 0.55), 0 2px 6px rgb(6 28 42 / 0.08);
}

.annonce__boite:focus {
	outline: none;
}

.annonce__fermer {
	position: absolute;
	z-index: 2;
	top: 14px;
	right: 14px;
	display: grid;
	place-items: center;
	width: 40px;
	height: 40px;
	margin: 0;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: rgb(255 255 255 / 0.94);
	color: #1d1d1b;
	box-shadow: 0 2px 10px rgb(0 0 0 / 0.14);
	cursor: pointer;
	transition: transform 0.3s var(--_ease);
}

.annonce__fermer svg {
	width: 16px;
	height: 16px;
}

.annonce__fermer:hover {
	transform: rotate(90deg);
}

.annonce__fermer:focus-visible,
.annonce__lecture:focus-visible {
	outline: 3px solid var(--_couleur);
	outline-offset: 2px;
}

.annonce__corps {
	position: relative;
	z-index: 1;
	display: flex;
	flex-direction: column;
	gap: 14px;
	padding: 40px 40px 36px;
}

.annonce__titre {
	margin: 0;
	padding-right: 36px;
	font-family: var(--annonce-police-titre, var(--wp--preset--font-family--titres, inherit));
	font-size: 1.75em;
	font-weight: 700;
	line-height: 1.15;
	letter-spacing: -0.01em;
	color: var(--_couleur);
	text-wrap: balance;
}

.annonce__texte {
	font-size: 1.0625em;
}

.annonce__texte > * {
	margin: 0 0 0.75em;
}

.annonce__texte > :last-child {
	margin-bottom: 0;
}

.annonce__texte a {
	color: var(--_couleur);
}

/* Gras et italique rétablis : certaines feuilles de remise à zéro les neutralisent (strong { font: inherit }) */
.annonce__texte :is(strong, b) {
	font-family: var(--annonce-police-gras, inherit);
	font-weight: var(--annonce-graisse-gras, 700);
}

.annonce__texte :is(em, i) {
	font-style: italic;
}

.annonce__texte ul,
.annonce__texte ol {
	padding-left: 1.25em;
}

/* Bouton : styles par défaut sans poids, la classe « bouton » du thème les remplace */
:where(.annonce) :where(.annonce__bouton) {
	display: inline-flex;
	align-items: center;
	gap: 10px;
	padding: 14px 24px;
	border-radius: 8px;
	background: var(--_couleur);
	color: var(--_couleur-texte);
	font-weight: 600;
	text-decoration: none;
	transition: gap 0.3s var(--_ease), filter 0.2s;
}

:where(.annonce) :where(.annonce__bouton):hover {
	filter: brightness(0.9);
}

.annonce__bouton {
	align-self: flex-start;
	margin-top: 8px;
}

.annonce__media {
	position: relative;
	overflow: hidden;
	background: var(--wp--preset--color--gris-clair, #f4f4f2);
}

.annonce__media img,
.annonce__media video {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: cover;
}

.annonce__filigrane {
	position: absolute;
	right: -36px;
	bottom: -40px;
	width: 190px;
	height: 190px;
	background: var(--_couleur);
	opacity: 0.07;
	mask: var(--annonce-filigrane) center / contain no-repeat;
	pointer-events: none;
}

/* Pause / lecture de la vidéo (obligatoire pour un contenu en mouvement de plus de 5 secondes) */
.annonce__lecture {
	position: absolute;
	left: 14px;
	bottom: 14px;
	width: 36px;
	height: 36px;
	margin: 0;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: rgb(0 0 0 / 0.5);
	cursor: pointer;
}

.annonce__lecture::before {
	content: '';
	position: absolute;
	inset: 0;
	margin: auto;
	width: 10px;
	height: 12px;
	border-inline: 3px solid #fff;
}

.annonce__lecture.en_pause::before {
	width: 0;
	height: 0;
	border: 0;
	border-block: 7px solid transparent;
	border-left: 11px solid #fff;
	translate: 2px 0;
}

.annonce .screen-reader-text {
	position: absolute !important;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip-path: inset(50%);
	white-space: nowrap;
	border: 0;
}

/*------------------------------------*\
	AU CENTRE
\*------------------------------------*/

.annonce--centre {
	inset: 0;
	width: min(var(--_largeur, 480px), calc(100vw - 2 * var(--_marge)));
	height: fit-content;
	max-height: calc(100dvh - 2 * var(--_marge));
	margin: auto;
}

/* Texte seul : carte compacte, symbole du site en filigrane */
.annonce--texte .annonce__corps {
	padding: 48px 44px 40px;
}

/* Texte et image : deux colonnes */
.annonce--centre.annonce--image {
	--_largeur: 860px;
}

.annonce--centre.annonce--image .annonce__boite {
	display: grid;
	grid-template-columns: 1fr 1.08fr;
}

.annonce--centre.annonce--image .annonce__media {
	min-height: 380px;
}

.annonce--centre.annonce--image .annonce__corps {
	justify-content: center;
	padding: 48px 44px;
}

/* Affiche : l'image à ses proportions, le bouton posé dessus */
.annonce--affiche {
	--_largeur: 440px;
}

.annonce--affiche .annonce__media img {
	height: auto;
	max-height: calc(100dvh - 2 * var(--_marge));
}

.annonce--affiche .annonce__corps {
	position: absolute;
	left: 0;
	right: 0;
	bottom: 0;
	padding: 80px 24px 24px;
	background: linear-gradient(transparent, rgb(5 20 30 / 0.6));
}

.annonce--affiche .annonce__corps:empty {
	display: none;
}

.annonce--affiche .annonce__bouton {
	align-self: stretch;
	justify-content: center;
}

:where(.annonce--affiche) :where(.annonce__bouton) {
	background: #fff;
	color: var(--_couleur);
}

/* Vidéo : 16/9 en haut, texte dessous */
.annonce--video {
	--_largeur: 640px;
}

.annonce--video .annonce__media {
	aspect-ratio: 16 / 9;
}

.annonce--video .annonce__corps {
	padding: 32px 40px 36px;
}

.annonce--video .annonce__titre {
	padding-right: 0;
}

/*------------------------------------*\
	DANS UN COIN (sans voile, la page reste utilisable)
\*------------------------------------*/

.annonce--coin {
	inset: auto var(--_marge) var(--_marge) auto;
	width: min(360px, calc(100vw - 2 * var(--_marge)));
	max-height: calc(100dvh - 2 * var(--_marge));
}

.annonce--coin .annonce__boite {
	border-radius: calc(var(--_rayon) - 2px);
}

.annonce--coin .annonce__media {
	height: 150px;
}

.annonce--coin.annonce--video .annonce__media {
	height: auto;
}

.annonce--coin.annonce--affiche .annonce__media {
	height: auto;
}

.annonce--coin.annonce--affiche .annonce__media img {
	max-height: 60dvh;
}

.annonce--coin .annonce__corps {
	gap: 8px;
	padding: 22px 24px 24px;
}

.annonce--coin.annonce--affiche .annonce__corps {
	padding: 60px 18px 18px;
}

.annonce--coin .annonce__titre {
	padding-right: 30px;
	font-size: 1.25em;
}

.annonce--coin .annonce__media + .annonce__corps .annonce__titre {
	padding-right: 0;
}

.annonce--coin .annonce__texte {
	font-size: 0.9375em;
}

.annonce--coin .annonce__bouton {
	margin-top: 6px;
}

:where(.annonce--coin) :where(.annonce__bouton) {
	padding: 11px 18px;
	font-size: 0.9375em;
}

.annonce--coin .annonce__fermer {
	top: 10px;
	right: 10px;
	width: 34px;
	height: 34px;
}

.annonce--coin .annonce__filigrane {
	width: 130px;
	height: 130px;
	right: -26px;
	bottom: -30px;
}

/*------------------------------------*\
	TÉLÉPHONES
\*------------------------------------*/

@media (max-width: 48em) {
	.annonce {
		--_marge: 12px;
	}

	/* Au centre : la fenêtre monte du bas de l'écran, à portée de pouce */
	.annonce--centre {
		inset: auto 0 0;
		width: 100%;
		max-height: 88dvh;
	}

	.annonce--centre .annonce__boite {
		border-radius: var(--_rayon) var(--_rayon) 0 0;
		padding-bottom: env(safe-area-inset-bottom, 0px);
	}

	.annonce--centre .annonce__boite::before {
		content: '';
		position: absolute;
		z-index: 3;
		top: 8px;
		left: 50%;
		width: 40px;
		height: 4px;
		border-radius: 2px;
		background: rgb(0 0 0 / 0.18);
		translate: -50% 0;
	}

	.annonce--centre .annonce__corps,
	.annonce--centre.annonce--texte .annonce__corps,
	.annonce--centre.annonce--video .annonce__corps {
		padding: 30px 24px 28px;
	}

	.annonce--centre .annonce__titre {
		font-size: 1.5em;
	}

	.annonce--centre .annonce__bouton {
		align-self: stretch;
		justify-content: center;
	}

	.annonce--centre.annonce--image .annonce__boite {
		display: block;
	}

	.annonce--centre.annonce--image .annonce__media {
		min-height: 0;
		height: 210px;
	}

	.annonce--centre.annonce--image .annonce__corps {
		padding: 26px 24px 28px;
	}

	.annonce--centre.annonce--affiche .annonce__media img {
		max-height: 80dvh;
	}

	.annonce--centre.annonce--affiche .annonce__boite::before {
		background: rgb(255 255 255 / 0.7);
	}

	/* Dans un coin : petite carte posée en bas, qui cache le moins possible */
	.annonce--coin {
		inset: auto var(--_marge) calc(var(--_marge) + env(safe-area-inset-bottom, 0px));
		width: auto;
	}

	.annonce--coin:is(.annonce--image, .annonce--video) .annonce__boite {
		display: grid;
		grid-template-columns: 96px 1fr;
	}

	.annonce--coin:is(.annonce--image, .annonce--video) .annonce__media {
		height: auto;
		min-height: 100%;
		aspect-ratio: auto;
	}

	.annonce--coin .annonce__lecture {
		display: none;
	}

	.annonce--coin .annonce__corps {
		gap: 4px;
		padding: 14px 44px 16px 16px;
	}

	.annonce--coin.annonce--affiche .annonce__corps {
		padding: 48px 14px 14px;
	}

	.annonce--coin .annonce__titre {
		padding-right: 0;
		font-size: 1.0625em;
	}

	.annonce--coin .annonce__texte {
		display: -webkit-box;
		overflow: hidden;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 2;
		font-size: 0.875em;
	}

	.annonce--coin.annonce--affiche .annonce__media img {
		max-height: 45dvh;
	}

	.annonce--coin:not(.annonce--affiche) .annonce__bouton {
		margin-top: 4px;
		padding: 8px 16px;
		font-size: 0.875em;
	}

	:where(.annonce--coin:not(.annonce--affiche)) :where(.annonce__bouton) {
		padding: 0;
		background: none;
		color: var(--_couleur);
		font-size: 0.875em;
		text-decoration: underline;
		text-underline-offset: 3px;
	}

	.annonce--coin .annonce__fermer {
		top: 8px;
		right: 8px;
		width: 30px;
		height: 30px;
	}

	.annonce--coin .annonce__fermer svg {
		width: 12px;
		height: 12px;
	}
}

/*------------------------------------*\
	ANIMATIONS
\*------------------------------------*/

.annonce[open] .annonce__boite {
	animation: annonce-entree 0.6s var(--_ease);
}

.annonce--coin[open] .annonce__boite {
	animation-name: annonce-monte;
}

.annonce[open]::backdrop {
	animation: annonce-fondu 0.4s ease;
}

.annonce.annonce--sortie .annonce__boite {
	animation: annonce-sortie 0.25s ease forwards;
}

.annonce.annonce--sortie::backdrop {
	animation: annonce-fondu 0.25s ease reverse forwards;
}

@media (max-width: 48em) {
	.annonce--centre[open] .annonce__boite {
		animation-name: annonce-feuille;
	}

	.annonce--centre.annonce--sortie .annonce__boite {
		animation: annonce-feuille 0.3s ease reverse forwards;
	}
}

@keyframes annonce-entree {
	from { opacity: 0; transform: translateY(24px) scale(0.96); }
}

@keyframes annonce-monte {
	from { opacity: 0; transform: translateY(40px); }
}

@keyframes annonce-feuille {
	from { transform: translateY(100%); }
}

@keyframes annonce-sortie {
	to { opacity: 0; transform: translateY(12px) scale(0.98); }
}

@keyframes annonce-fondu {
	from { opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
	.annonce .annonce__boite,
	.annonce::backdrop {
		animation: none !important;
	}

	.annonce__fermer {
		transition: none;
	}
}
