/**
 * Back to Top – caforum/backtotop
 *
 * Le bouton apparaît grâce à la requête CSS scroll-state(scrollable: top) :
 * elle est vraie dès que l'on a quitté le haut de la page.
 */

/* 1. La page devient un conteneur « scroll-state » */
html {
	container-type: scroll-state;
	scroll-behavior: smooth;
}

/* 2. Le bouton, caché par défaut sous le bas de l'écran
 *
 * Couleurs : le script les règle automatiquement d'après la couleur de
 * fond de .forabg du style actif (flèche blanche ou foncée selon le
 * contraste). Les valeurs ci-dessous (bleu de prosilver) ne servent que
 * si JavaScript est désactivé.
 */
.caforum-backtotop {
	--caforum-btt-bg: #0076b1;
	--caforum-btt-fg: #ffffff;

	position: fixed;
	right: 1.25rem;
	bottom: 1.25rem;
	z-index: 100;
	display: grid;
	place-items: center;
	box-sizing: border-box;
	width: 2.5rem;
	height: 2.5rem;
	border-radius: 50%;
	border: 0;
	color: var(--caforum-btt-fg);
	text-decoration: none;
	background-color: var(--caforum-btt-bg);
	background-image: linear-gradient(to bottom, rgba(255, 255, 255, 0), rgba(255, 255, 255, 0));
	box-shadow:
		0 1px 2px rgba(0, 0, 0, .12),
		0 6px 16px -6px rgba(0, 0, 0, .3);

	/* État caché : hors de l'écran à droite, tourné d'un tour.
	   Entrée : le bouton arrive en roulant depuis la droite,
	   avec un léger rebond à l'arrivée. */
	translate: calc(100% + 2rem) 0;
	rotate: 360deg;
	scale: .8;
	opacity: 0;
	pointer-events: none;
	transition:
		translate .7s cubic-bezier(.34, 1.4, .64, 1),
		rotate .7s cubic-bezier(.25, 1, .5, 1),
		scale .5s cubic-bezier(.34, 1.56, .64, 1),
		opacity .35s ease,
		transform .2s ease,
		box-shadow .2s ease,
		background-image .2s ease;
}

.caforum-backtotop svg {
	width: 1rem;
	height: 1rem;
	transition: translate .25s ease;
}

.caforum-backtotop:hover,
.caforum-backtotop:focus {
	color: var(--caforum-btt-fg);
	text-decoration: none;
}

/* Survol : effet relief — le bouton se soulève, reflet clair en haut,
   tranche plus sombre en bas et ombre portée plus marquée */
.caforum-backtotop:hover {
	transform: translateY(-2px);
	background-image: linear-gradient(to bottom, rgba(255, 255, 255, .28), rgba(0, 0, 0, .18));
	box-shadow:
		inset 0 1px 1px rgba(255, 255, 255, .55),
		inset 0 -3px 2px rgba(0, 0, 0, .25),
		0 3px 0 rgba(0, 0, 0, .18),
		0 10px 20px -6px rgba(0, 0, 0, .45);
}

/* La flèche monte légèrement au survol */
.caforum-backtotop:hover svg {
	translate: 0 -1px;
}

/* Clic : le bouton s'enfonce */
.caforum-backtotop:active {
	transform: translateY(1px);
	background-image: linear-gradient(to bottom, rgba(0, 0, 0, .15), rgba(255, 255, 255, .08));
	box-shadow:
		inset 0 2px 4px rgba(0, 0, 0, .35),
		0 1px 1px rgba(0, 0, 0, .15);
}

.caforum-backtotop:focus-visible {
	outline: 2px solid var(--caforum-btt-bg);
	outline-offset: 3px;
}

/* 3. Affichage : « peut-on encore remonter ? » */
@container scroll-state(scrollable: top) {
	.caforum-backtotop {
		translate: 0 0;
		rotate: 0deg;
		scale: 1;
		opacity: 1;
		pointer-events: auto;
	}
}

/* 4. Repli JavaScript (Firefox, Safari…) */
.caforum-backtotop.is-visible {
	translate: 0 0;
	rotate: 0deg;
	scale: 1;
	opacity: 1;
	pointer-events: auto;
}

/* Un peu plus petit et plus près du bord sur mobile */
@media (max-width: 700px) {
	.caforum-backtotop {
		right: .875rem;
		bottom: .875rem;
		width: 2.25rem;
		height: 2.25rem;
	}
}

/* Moins d'animations si l'utilisateur le demande */
@media (prefers-reduced-motion: reduce) {
	html {
		scroll-behavior: auto;
	}

	.caforum-backtotop {
		translate: 0 0;
		rotate: 0deg;
		scale: 1;
	}

	.caforum-backtotop,
	.caforum-backtotop svg {
		transition: opacity .2s, box-shadow .2s;
	}

	.caforum-backtotop:hover,
	.caforum-backtotop:active {
		transform: none;
	}

	.caforum-backtotop:hover svg {
		translate: none;
	}
}

/* Jamais à l'impression */
@media print {
	.caforum-backtotop {
		display: none !important;
	}
}
