/*
 * Géométrie en « unités de dessin » reprises de la maquette : cases de 192,
 * origine (44, 41), pas de 200,5 en largeur et 202 en hauteur.
 * --w, --h (taille du dessin avec les marges de la maquette), --lu, --hu (sans
 * ces marges) et la place de la case 25 sont calculés en PHP selon le nombre de
 * colonnes réglé dans l'administration.
 *
 * Dans une page (Elementor, thème), la grille occupe toute la largeur de son
 * conteneur, sans marge. Le modèle plein écran garde le cadrage de la maquette.
 */
.rspca {
	--ox: 0;
	--oy: 0;
	--lt: var(--lu); /* largeur et hauteur du dessin affiché */
	--ht: var(--hu);
	--or: #b17f4a;
	--bleu: #1a1e52;
	width: 100%;
	margin: 0 auto;
	padding: 30px 0; /* largeur : celle du conteneur ; léger espace au-dessus et au-dessous */
	font-family: "Avenir Next", Avenir, "Nunito Sans", "Segoe UI", sans-serif;
}

.rspca-page .rspca {
	--ox: 44;
	--oy: 41;
	--lt: var(--w);
	--ht: var(--h);
	padding: 0;
	width: min(100%, 1200px, calc(var(--w) * 1px), max(760px, calc(100vh * var(--w) / var(--h))));
}

.rspca-grille {
	position: relative;
	aspect-ratio: var(--lt) / var(--ht);
	container-type: inline-size;
}

/* ---------- Cases ---------- */

.rspca .rspca-case {
	position: absolute;
	left: calc((var(--ox) + var(--c) * 200.5) / var(--lt) * 100%);
	top: calc((var(--oy) + var(--l) * 202) / var(--ht) * 100%);
	width: calc(192 / var(--lt) * 100%);
	aspect-ratio: 1;
	container-type: inline-size;
	margin: 0;
	padding: 0;
	border: 1px solid var(--or);
	border-radius: 0;
	background: var(--bleu);
	color: #fff;
	cursor: default;
	font: inherit;
	transition: box-shadow .25s, transform .25s;
}

.rspca-case img {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: cover;
}

.rspca .rspca-case.est-lisible { cursor: pointer; }

.rspca .rspca-case.est-lisible:hover,
.rspca .rspca-case.est-lisible.est-active {
	box-shadow: 0 0 0 1px var(--or), 0 0 22px rgba(177, 127, 74, .65);
	z-index: 2;
}

.rspca .rspca-case:focus-visible {
	outline: 2px solid #fff;
	outline-offset: 2px;
}

/* Case 25 : la bouteille déborde de la grille, sans cadre. */
.rspca .rspca-case--25 {
	left: calc((var(--x25) - 44 + var(--ox)) / var(--lt) * 100%);
	top: calc((var(--y25) - 41 + var(--oy)) / var(--ht) * 100%);
	width: calc(var(--w25) / var(--lt) * 100%);
	aspect-ratio: 324 / 244;
	border: 0;
	background: none;
}
.rspca-case--25 img { object-fit: contain; }
.rspca .rspca-case--25.est-lisible:hover,
.rspca .rspca-case--25.est-lisible.est-active {
	box-shadow: none;
	transform: scale(1.04);
	filter: drop-shadow(0 0 14px rgba(177, 127, 74, .8));
}

.rspca-texte-vignette {
	display: block;
	font-size: 5.6cqw;
	text-transform: uppercase;
	line-height: 1.2;
}
.rspca-texte-vignette em { color: var(--or); font-style: normal; font-weight: 700; }
.rspca-texte-vignette strong {
	display: block;
	font: 700 40.6cqw/1.2 Didot, "Bodoni 72", "Bodoni MT", Georgia, serif;
}
.rspca-texte-vignette small { color: var(--or); font-size: .35em; }

/* Infobulle des cases non lisibles */
.rspca-bulle {
	position: absolute;
	left: 50%;
	top: 50%;
	transform: translate(-50%, -50%) rotate(-4deg);
	width: 90%;
	padding: .5em .3em;
	background: var(--or);
	border: 1px solid var(--or);
	color: #fff;
	font-size: clamp(10px, 6.6cqw, 14px);
	font-weight: 700;
	text-transform: uppercase;
	line-height: 1.3;
	opacity: 0;
	pointer-events: none;
	transition: opacity .2s;
}
.rspca-ordinal { text-transform: none; }
.rspca-case:hover .rspca-bulle,
.rspca-case:focus .rspca-bulle { opacity: 1; }

/* ---------- Fiche ---------- */

.rspca-fiche {
	--g: calc(100cqw / var(--lt)); /* une unité de dessin de la grille */
	--u: min(var(--g), 1px);       /* celle de la fiche, jamais plus grande que la maquette */
	position: absolute;
	z-index: 5;
	box-sizing: border-box;
	display: flex;
	flex-direction: column;
	left: calc((var(--ox) + var(--fc) * 200.5) * var(--g));
	/* Fiche plus petite que 3 × 3 cases : calée en haut, au milieu ou en bas selon la ligne de la case. */
	top: calc((var(--oy) + var(--fl) * 202) * var(--g) + var(--decalage) * 296 * (var(--g) - var(--u)));
	width: calc(593 * var(--u));
	height: calc(592 * var(--u));
	padding: calc(17 * var(--u));
	background: #fff;
	color: #111;
	box-shadow: 0 calc(12 * var(--u)) calc(36 * var(--u)) rgba(0, 0, 0, .55);
	animation: rspca-apparition .22s ease-out;
}
.rspca-fiche[hidden] { display: none; }
.rspca-fiche:focus { outline: none; }

@keyframes rspca-apparition {
	from { opacity: 0; transform: scale(.97); }
}

/* Repère triangulaire aligné sur la case choisie */
.rspca-fiche--gauche::before,
.rspca-fiche--droite::before {
	content: "";
	position: absolute;
	top: calc(var(--decalage) * (202 * var(--g) - 296 * (var(--g) - var(--u))) + 41 * var(--u));
	border-block: calc(15.5 * var(--u)) solid transparent;
}
/* Fiche à gauche de la case : son bord droit reste collé à celle-ci. */
.rspca-fiche--droite { left: calc((var(--ox) + var(--fc) * 200.5) * var(--g) + 593 * (var(--g) - var(--u))); }

.rspca-fiche--gauche::before { left: 0; border-left: calc(26 * var(--u)) solid var(--or); }
.rspca-fiche--droite::before { right: 0; border-right: calc(26 * var(--u)) solid var(--or); }

.rspca-fiche-texte {
	/* Texte long : c'est la photo qui se réduit. Le défilement ne sert qu'en dernier recours. */
	flex: 0 0 auto;
	max-height: calc(100% - 136 * var(--u));
	min-height: 0;
	overflow-y: auto;
	padding: calc(22.8 * var(--u)) calc(26.4 * var(--u)) calc(19.2 * var(--u)) calc(28 * var(--u));
}

.rspca-fiche .rspca-logo {
	display: block;
	width: auto;
	height: auto;
	max-width: calc(330 * var(--u));
	max-height: calc(112 * var(--u));
	margin: 0 0 calc(33.6 * var(--u));
}

.rspca-fiche h2 {
	margin: 0 0 calc(9.6 * var(--u));
	font: italic 600 calc(20 * var(--u))/1.2 "Avenir Next", Avenir, "Nunito Sans", sans-serif;
	text-transform: uppercase;
	white-space: pre-line;
	color: #111;
	letter-spacing: -.022em;
}

.rspca-fiche p { margin: 0; }
.rspca-description { font-size: calc(20 * var(--u)); line-height: 1.17; letter-spacing: -.022em; white-space: pre-line; }
.rspca-fiche .rspca-lieu { margin-top: calc(12 * var(--u)); font-size: calc(17 * var(--u)); line-height: 1.25; }
.rspca .rspca-fiche .rspca-lieu { display: flex; align-items: center; gap: .35em; }
.rspca .rspca-lieu svg { flex: none; width: 1.1em; height: 1.1em; }
.rspca-fiche .rspca-source { margin-top: calc(20.4 * var(--u)); font-size: calc(15 * var(--u)); }
.rspca-fiche .rspca-lien { margin-top: calc(14.4 * var(--u)); font-size: calc(16 * var(--u)); }
.rspca-lien a { color: #8a5e2f; font-weight: 600; }

/* La photo occupe la place restante en bas de fiche. */
.rspca-photo {
	position: relative;
	flex: 0 1 calc(238.8 * var(--u));
	margin-top: auto;
	min-height: calc(136 * var(--u));
}
.rspca-fiche .rspca-photo img {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	object-fit: cover;
	object-position: 50% 20%; /* photo réduite : on rogne surtout le bas, pour garder les visages */
}

.rspca .rspca-fermer {
	position: absolute;
	top: 8px;
	right: 8px;
	z-index: 1;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 32px;
	height: 32px;
	margin: 0;
	padding: 0;
	border: 1px solid var(--or);
	border-radius: 50%;
	background: #fff;
	color: var(--or);
	cursor: pointer;
	transition: background .2s, color .2s;
}
.rspca-fermer svg { width: 12px; height: 12px; }
.rspca .rspca-fermer:hover,
.rspca .rspca-fermer:focus-visible { background: var(--or); color: #fff; }

.rspca-apercu {
	position: fixed;
	z-index: 30;
	left: 50%;
	bottom: 10px;
	transform: translateX(-50%);
	margin: 0;
	padding: 8px 16px;
	background: #ffd866;
	color: #111;
	font-size: 13px;
	white-space: nowrap;
}
.rspca-apercu a { color: #111; }

/* ---------- Tablette et mobile : grille réorganisée, fiche en plein écran ---------- */

@media (max-width: 1024px) {
	.rspca,
	.rspca-page .rspca { width: 100%; }

	.rspca-grille {
		display: grid;
		grid-template-columns: repeat(var(--cols-t), minmax(0, 1fr));
		gap: 8px;
		aspect-ratio: auto;
		container-type: normal;
	}

	.rspca-page .rspca-grille { padding: 12px; }

	.rspca .rspca-case {
		position: relative;
		left: auto;
		top: auto;
		width: 100%;
	}

	.rspca .rspca-case--25 {
		grid-column: span var(--span-t); /* le reste de la dernière ligne */
		align-self: center;
		justify-self: center;
		left: auto;
		top: auto;
		width: min(100%, 320px);
		aspect-ratio: 324 / 244;
	}

	.rspca-fiche,
	.rspca-fiche--droite {
		position: fixed;
		z-index: 20;
		top: 50%;
		left: 12px;
		right: 12px;
		width: auto;
		height: auto;
		max-width: 560px;
		max-height: calc(100vh - 24px);
		max-height: calc(100dvh - 24px);
		margin: 0 auto;
		padding: 10px;
		overflow-y: auto;
		transform: translateY(-50%);
		animation: none;
	}
	.rspca-fiche::before { display: none; }

	.rspca-fiche-texte { flex: none; max-height: none; overflow: visible; padding: 34px 12px 16px; }
	.rspca-fiche .rspca-logo { max-width: 80%; max-height: 96px; margin-bottom: 20px; }
	.rspca-fiche h2 { font-size: 17px; margin-bottom: 8px; white-space: normal; }
	.rspca-description { font-size: 16px; line-height: 1.35; white-space: normal; }
	.rspca-fiche .rspca-lieu { margin-top: 12px; font-size: 15px; }
	.rspca-fiche .rspca-source { margin-top: 14px; font-size: 13px; }
	.rspca-fiche .rspca-lien { margin-top: 12px; font-size: 15px; }
	.rspca-photo { flex: none; min-height: 0; margin-top: 0; }
	.rspca-fiche .rspca-photo img { position: static; height: auto; }

	.rspca-voile {
		position: fixed;
		inset: 0;
		z-index: 15;
		background: rgba(4, 7, 15, .82);
	}
	.rspca-voile[hidden] { display: none; }
}

@media (max-width: 600px) {
	.rspca-grille { grid-template-columns: repeat(var(--cols-m), minmax(0, 1fr)); }
	.rspca .rspca-case--25 { grid-column: span var(--span-m); }
}

@media (min-width: 1025px) {
	.rspca-voile { display: none; }
}

@media (prefers-reduced-motion: reduce) {
	.rspca * { animation: none !important; transition: none !important; }
}

/* Résiste aux graisses fines imposées par certains thèmes. */
.rspca .rspca-fiche p { font-weight: 400; color: #111; }
.rspca .rspca-fiche h2 { font-weight: 600; }
.rspca .rspca-fiche .rspca-lieu { font-weight: 700; color: #8a5e2f; }
