/*
 * Texture du fond d'une section (réglages tex, tex_pos, tex_color, tex_op, tex_size) : motif (points, grille, lignes) posé sur le fond, sous le contenu.
 * Mêmes classes dans l'éditeur (calque .row-tex, créé par RowLib::backgroundLayersHtml et rows.js) et sur le site (calque .r-tex).
 */

/* Texture : calque posé sur le fond, sous le contenu ; le motif s'estompe vers le côté opposé à sa position */
.row-item:has(> .row-tex),
.r-item:has(> .r-tex) {
	position: relative;
}

.row-item:has(> .row-tex) > .row-body,
.r-item:has(> .r-tex) > .r-body {
	position: relative;
}

.row-tex,
.r-tex {
	--tx-color: currentColor;
	position: absolute;
	inset: 0;
	overflow: hidden;
	pointer-events: none;
	opacity: var(--tx-op, 0.4);
	color: inherit;
}

.row-tex::before,
.r-tex::before {
	content: "";
	position: absolute;
	inset: 0;
	background-size: var(--tx-size, 14px) var(--tx-size, 14px);
}

.row-tex-dots::before,
.r-tex-dots::before {
	background-image: radial-gradient(circle, var(--tx-color) 1.1px, transparent 1.6px);
}

.row-tex-grid::before,
.r-tex-grid::before {
	background-image: linear-gradient(var(--tx-color) 1px, transparent 1px), linear-gradient(90deg, var(--tx-color) 1px, transparent 1px);
}

.row-tex-lines::before,
.r-tex-lines::before {
	/* Trait de 1 px à 45° dans une tuile carrée dont le côté est un nombre entier de pixels : le pas horizontal tombe pile sur la grille de pixels, ce qui supprime la trame (moiré) du dégradé répété, visible surtout à 6 px */
	background-image: linear-gradient(135deg, transparent calc(50% - 0.5px), var(--tx-color) calc(50% - 0.5px), var(--tx-color) calc(50% + 0.5px), transparent calc(50% + 0.5px));
	--tx-tile: calc(var(--tx-size, 14px) * 1.4142);
	background-size: var(--tx-tile) var(--tx-tile);
}

@supports (width: round(1.4px, 1px)) {
	.row-tex-lines::before,
	.r-tex-lines::before {
		--tx-tile: round(calc(var(--tx-size, 14px) * 1.4142), 1px);
	}
}

.row-tex-right::before,
.r-tex-right::before {
	-webkit-mask-image: linear-gradient(to left, #000 0%, transparent 70%);
	mask-image: linear-gradient(to left, #000 0%, transparent 70%);
}

.row-tex-left::before,
.r-tex-left::before {
	-webkit-mask-image: linear-gradient(to right, #000 0%, transparent 70%);
	mask-image: linear-gradient(to right, #000 0%, transparent 70%);
}

/*
 * Texture animée (réglage tex_anim = glow) : le motif (points, grille ou lignes) sert de masque au calque, et deux lueurs floues de la couleur de la texture
 * tournent derrière (::before et ::after, en sens inverse) : le motif ne se voit que là où la lumière passe. Seule la rotation (transform) est animée.
 * La lueur tourne autour du côté choisi (tex_pos), donc le motif n'a plus besoin de s'estomper. Durée d'un tour : --tx-speed (tex_speed, en secondes).
 * Les scripts (section-texture.js) mettent l'animation en pause hors de l'écran (classe .is-paused).
 */
.row-tex-anim,
.r-tex-anim {
	--tx-x: 50%;
	--tx-box: 90%;
	--tx-tile: calc(var(--tx-size, 14px) * 1.4142);
	-webkit-mask-size: var(--tx-size, 14px) var(--tx-size, 14px);
	mask-size: var(--tx-size, 14px) var(--tx-size, 14px);
	-webkit-mask-repeat: repeat;
	mask-repeat: repeat;
}

.row-tex-anim.row-tex-right,
.r-tex-anim.r-tex-right {
	--tx-x: 75%;
}

.row-tex-anim.row-tex-left,
.r-tex-anim.r-tex-left {
	--tx-x: 25%;
}

.row-tex-anim.row-tex-full,
.r-tex-anim.r-tex-full {
	--tx-box: 120%;
}

/* Motif = masque (seul l'opacité du dessin compte, pas sa couleur) */
.row-tex-anim.row-tex-dots,
.r-tex-anim.r-tex-dots {
	-webkit-mask-image: radial-gradient(circle, #000 1.1px, transparent 1.6px);
	mask-image: radial-gradient(circle, #000 1.1px, transparent 1.6px);
}

.row-tex-anim.row-tex-grid,
.r-tex-anim.r-tex-grid {
	-webkit-mask-image: linear-gradient(#000 1px, transparent 1px), linear-gradient(90deg, #000 1px, transparent 1px);
	mask-image: linear-gradient(#000 1px, transparent 1px), linear-gradient(90deg, #000 1px, transparent 1px);
}

.row-tex-anim.row-tex-lines,
.r-tex-anim.r-tex-lines {
	-webkit-mask-image: linear-gradient(135deg, transparent calc(50% - 0.5px), #000 calc(50% - 0.5px), #000 calc(50% + 0.5px), transparent calc(50% + 0.5px));
	mask-image: linear-gradient(135deg, transparent calc(50% - 0.5px), #000 calc(50% - 0.5px), #000 calc(50% + 0.5px), transparent calc(50% + 0.5px));
	-webkit-mask-size: var(--tx-tile) var(--tx-tile);
	mask-size: var(--tx-tile) var(--tx-tile);
}

@supports (width: round(1.4px, 1px)) {
	.row-tex-anim.row-tex-lines,
	.r-tex-anim.r-tex-lines {
		--tx-tile: round(calc(var(--tx-size, 14px) * 1.4142), 1px);
	}
}

/* Deux lueurs : une boîte carrée centrée sur --tx-x, dont une lueur floue (hors centre) fait le tour quand la boîte tourne */
.row-tex-anim::before,
.row-tex-anim::after,
.r-tex-anim::before,
.r-tex-anim::after {
	content: "";
	position: absolute;
	inset: auto;
	top: 50%;
	left: var(--tx-x);
	width: var(--tx-box);
	aspect-ratio: 1;
	max-width: none;
	translate: -50% -50%;
	background-size: auto;
	-webkit-mask-image: none;
	mask-image: none;
	will-change: rotate;
	animation: tx-spin var(--tx-speed, 12s) linear infinite;
}

.row-tex-anim::before,
.r-tex-anim::before {
	background-image: radial-gradient(circle at 70% 50%, var(--tx-color) 0%, transparent 30%);
}

.row-tex-anim::after,
.r-tex-anim::after {
	background-image: radial-gradient(circle at 30% 50%, var(--tx-color) 0%, transparent 30%);
	animation-direction: reverse;
	animation-duration: calc(var(--tx-speed, 12s) * 1.4);
}

@keyframes tx-spin {
	to {
		rotate: 360deg;
	}
}

.row-tex-anim.is-paused::before,
.row-tex-anim.is-paused::after,
.r-tex-anim.is-paused::before,
.r-tex-anim.is-paused::after {
	animation-play-state: paused;
}

@media (prefers-reduced-motion: reduce) {
	.row-tex-anim::before,
	.row-tex-anim::after,
	.r-tex-anim::before,
	.r-tex-anim::after {
		animation: none;
	}
}
