/*
 * H2A Accessibility Tools Styles
 * Site-wide high contrast is handled in the theme (assets/styles/h2a-high-contrast.css).
 */

/* Screen reader only */
.h2a-sr-only {
	position: absolute;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}

/* Wrapper and main Accessibility button */
.h2a-accessibility-wrapper {
	position: relative;
	display: inline-flex;
	z-index: 99999;
}

.h2a-accessibility-button {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 0.4rem;
	padding: 0.5rem 1.2rem;
	border-radius: 1rem;
	border: 0px solid #ffffff;
	background: #000000;
	color: #ffffff;
	font-size: 0.875rem;
	cursor: pointer;
}

.h2a-accessibility-button-icon {
	flex-shrink: 0;
}

/* Fixed top-right placement (auto-inject mode) */
.h2a-accessibility-wrapper--fixed {
	position: fixed;
	top: 1rem;
	right: 1rem;
	display: flex;
	flex-direction: column;
	align-items: flex-end;
}

.h2a-accessibility-wrapper--fixed .h2a-accessibility-panel {
	position: fixed;
	top: calc(1rem + 3rem);
	right: 1rem;
	bottom: auto;
}

@media (max-width: 600px) {
	.h2a-accessibility-wrapper--fixed {
		top: 0.75rem;
		right: 0.75rem;
	}

	.h2a-accessibility-panel {
		position: fixed;
		left: 1rem;
		right: 1rem;
		width: auto;
		max-width: min(420px, 90vw);
		margin-inline: auto;
		transform: translateY(-10px);
		transform-origin: top center;
		min-width: 0;
	}

	.h2a-accessibility-panel.is-open {
		transform: translateY(0);
	}

	.h2a-accessibility-wrapper:not(.h2a-accessibility-wrapper--fixed) .h2a-accessibility-panel {
		top: 3rem;
		bottom: auto;
	}

	.h2a-accessibility-wrapper--fixed .h2a-accessibility-panel {
		top: 4rem;
		bottom: auto;
	}
}

.h2a-accessibility-button:focus-visible {
	outline: 3px solid #00ffff;
	outline-offset: 2px;
}

/* Panel backdrop */
.h2a-accessibility-backdrop {
	display: block;
	position: fixed;
	inset: 0;
	background: rgba(0, 0, 0, 0.45);
	z-index: 99998;
	opacity: 0;
	visibility: hidden;
	pointer-events: none;
	transition: opacity 0.4s ease;
}

.h2a-accessibility-backdrop.is-visible {
	opacity: 1;
	visibility: visible;
	pointer-events: auto;
	transition-duration: 0.45s;
}

.h2a-accessibility-backdrop:not(.is-visible) {
	transition-duration: 0.35s;
	transition-delay: 0.05s;
}

/* Panel (modal) */
.h2a-accessibility-panel {
	--h2a-panel-ease: cubic-bezier(0.16, 1, 0.3, 1);
	position: absolute;
	top: calc(100% + 10px);
	right: 0;
	max-width: min(420px, 90vw);
	min-width: min(300px, 90vw);
	background: #111111;
	color: #ffffff;
	border-radius: 12px;
	box-shadow: 0 12px 28px rgba(0, 0, 0, 0.22);
	padding: 1.8rem 2.2rem 2rem;
	z-index: 99999;
	opacity: 0;
	visibility: hidden;
	pointer-events: none;
	transform: translateY(-10px);
	transform-origin: top right;
	transition:
		opacity 0.42s var(--h2a-panel-ease),
		transform 0.48s var(--h2a-panel-ease),
		box-shadow 0.48s var(--h2a-panel-ease),
		visibility 0s linear 0.48s;
}

.h2a-accessibility-panel.is-open {
	opacity: 1;
	visibility: visible;
	pointer-events: auto;
	transform: translateY(0);
	box-shadow: 0 24px 48px rgba(0, 0, 0, 0.38);
	transition:
		opacity 0.45s var(--h2a-panel-ease) 0.06s,
		transform 0.52s var(--h2a-panel-ease) 0.06s,
		box-shadow 0.52s var(--h2a-panel-ease) 0.06s,
		visibility 0s linear 0s;
}

.h2a-accessibility-panel-inner {
	position: relative;
	opacity: 0;
	transform: translateY(6px);
	transition:
		opacity 0.38s ease 0.14s,
		transform 0.42s var(--h2a-panel-ease) 0.14s;
}

.h2a-accessibility-panel.is-open .h2a-accessibility-panel-inner {
	opacity: 1;
	transform: translateY(0);
	transition:
		opacity 0.4s ease 0.12s,
		transform 0.44s var(--h2a-panel-ease) 0.12s;
}

.h2a-accessibility-panel:not(.is-open) .h2a-accessibility-panel-inner {
	transition:
		opacity 0.22s ease,
		transform 0.22s ease;
}

.h2a-accessibility-title {
	margin: 0 0 1rem 0;
	font-size: 1.4rem;
	font-weight: 800;
	color: #ffffff;
	text-transform: initial;
	padding-right: 2rem;
}

.h2a-accessibility-close {
	position: absolute;
	top: 0;
	right: 0;
	width: 40px;
	height: 40px;
	background: transparent;
	color: #ffffff;
	font-size: 1.4rem;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	cursor: pointer;
	transform: translate(50%, -50%);
	border:0px;
}

.h2a-accessibility-close span {
	line-height: 1;
}

.h2a-accessibility-option {
	display: flex;
	align-items: center;
	gap: 8px;
	margin-top: 1.2rem;
}

.h2a-accessibility-label {
	font-size: 1rem;
	flex: 1;
}

/* Switch styles */
.h2a-switch {
	position: relative;
	flex-shrink: 0;
	width: 48px;
	height: 24px;
	border: 0;
	padding: 0;
	background: none;
	cursor: pointer;
}

.h2a-switch-track {
	position: absolute;
	inset: 0;
	border-radius: 999px;
	background: #777777;
	display: flex;
	align-items: center;
	padding: 0 4px;
	transition: background 0.4s cubic-bezier(0.22, 1, 0.36, 1);
}

.h2a-switch-thumb {
	width: 16px;
	height: 16px;
	border-radius: 50%;
	background: #ffffff;
	box-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
	transform: translateX(0);
	transition:
		transform 0.42s cubic-bezier(0.22, 1, 0.36, 1),
		box-shadow 0.42s cubic-bezier(0.22, 1, 0.36, 1);
}

.h2a-switch[aria-checked="true"] .h2a-switch-track {
	background: #e4002b;
}

.h2a-switch[aria-checked="true"] .h2a-switch-thumb {
	transform: translateX(24px);
	box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
}

.h2a-switch:focus-visible {
	outline: 3px solid #00ffff;
	outline-offset: 2px;
}

/* Reduced motion — site-wide (includes accessibility panel); opt-out via data-allow-motion */
body.reduce-motion *:not([data-allow-motion]):not([data-allow-motion] *),
body.reduce-motion *:not([data-allow-motion]):not([data-allow-motion] *)::before,
body.reduce-motion *:not([data-allow-motion]):not([data-allow-motion] *)::after,
body.h2a-animations-disabled *:not([data-allow-motion]):not([data-allow-motion] *),
body.h2a-animations-disabled *:not([data-allow-motion]):not([data-allow-motion] *)::before,
body.h2a-animations-disabled *:not([data-allow-motion]):not([data-allow-motion] *)::after {
	animation-duration: 0.01ms !important;
	animation-iteration-count: 1 !important;
	transition-duration: 0.01ms !important;
	scroll-behavior: auto !important;
	transition-delay: 0ms !important;
}

/* `html` n'est pas un descendant de body : le défilement fluide doit être coupé séparément. */
html.reduce-motion,
html:has(body.reduce-motion),
html:has(body.h2a-animations-disabled) {
	scroll-behavior: auto !important;
}

/* Sans préférence « mouvement réduit » explicite du site, le panneau respecte déjà l'OS */
@media (prefers-reduced-motion: reduce) {
	.h2a-accessibility-panel,
	.h2a-accessibility-panel-inner,
	.h2a-accessibility-backdrop,
	.h2a-switch-track,
	.h2a-switch-thumb {
		transition-duration: 0.01ms !important;
		transition-delay: 0ms !important;
	}
}

/* ==========================================================================
   Contraste renforcé

   Couche 1 — structurelle (modes « générique » et « les deux ») : ce que les
   couleurs des presets ne peuvent pas corriger (soulignement des liens, focus,
   dégradés, texte sur image, ombres).
   Couche 2 — palette de repli (body.h2a-hc-generic) : appliquée seulement
   quand ni le thème parent ni l'enfant ne fournissent de CSS de contraste.
   Variables surchargeables : --h2a-hc-*.
   ========================================================================== */

body.high-contrast {
	--h2a-hc-bg: #000000;
	--h2a-hc-fg: #ffffff;
	--h2a-hc-link: #ffff00;
	--h2a-hc-border: #ffffff;
	--h2a-hc-input-bg: #000000;
	--h2a-hc-media-border: #ffff00;
	--h2a-hc-focus: #00ffff;
}

/* Couche 1 */
body.high-contrast:not(.h2a-contrast-mode-theme) :where(a):not(.wp-element-button):not(.wp-block-button__link):not(.h2a-accessibility-wrapper *) {
	text-decoration: underline;
	text-underline-offset: 0.15em;
}

body.high-contrast:not(.h2a-contrast-mode-theme) :where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
	outline: 3px solid var(--h2a-hc-focus) !important;
	outline-offset: 2px !important;
}

body.high-contrast:not(.h2a-contrast-mode-theme) *:not(.h2a-accessibility-wrapper):not(.h2a-accessibility-wrapper *) {
	text-shadow: none !important;
}

/* Dégradés et voiles : aplatis, le texte ne peut pas être lu sur un dégradé. */
body.high-contrast:not(.h2a-contrast-mode-theme) [style*="gradient"]:not(.h2a-accessibility-wrapper *),
body.high-contrast:not(.h2a-contrast-mode-theme) .has-background-gradient:not(.h2a-accessibility-wrapper *) {
	background-image: none !important;
}

body.high-contrast:not(.h2a-contrast-mode-theme) .wp-block-cover__image-overlay,
body.high-contrast:not(.h2a-contrast-mode-theme) .wp-block-cover__gradient-background {
	opacity: 1 !important;
	background-image: none !important;
}

/* Couche 2 — palette de repli */
body.high-contrast.h2a-hc-generic,
body.high-contrast.h2a-hc-generic *:not(.h2a-accessibility-wrapper):not(.h2a-accessibility-wrapper *):not(svg *):not(img):not(video) {
	background-color: var(--h2a-hc-bg) !important;
	color: var(--h2a-hc-fg) !important;
	border-color: var(--h2a-hc-border) !important;
	box-shadow: none !important;
}

body.high-contrast.h2a-hc-generic a:not(.h2a-accessibility-wrapper *) {
	color: var(--h2a-hc-link) !important;
}

body.high-contrast.h2a-hc-generic a:not(.h2a-accessibility-wrapper *):hover,
body.high-contrast.h2a-hc-generic a:not(.h2a-accessibility-wrapper *):focus {
	color: var(--h2a-hc-fg) !important;
}

body.high-contrast.h2a-hc-generic :is(button, input, select, textarea, .wp-element-button, .wp-block-button__link):not(.h2a-accessibility-wrapper *) {
	background-color: var(--h2a-hc-input-bg) !important;
	color: var(--h2a-hc-fg) !important;
	border: 2px solid var(--h2a-hc-border) !important;
}

body.high-contrast.h2a-hc-generic :is(img, video, canvas):not(.h2a-accessibility-wrapper *) {
	outline: 2px solid var(--h2a-hc-media-border);
}

/* ==========================================================================
   Windows « contrastes forcés » : l'état des interrupteurs ne doit pas dépendre
   d'une couleur de fond (elle est écrasée par le système).
   ========================================================================== */

@media (forced-colors: active) {
	.h2a-accessibility-panel {
		border: 2px solid CanvasText;
	}

	.h2a-switch-track {
		border: 2px solid ButtonText;
		background: Canvas;
	}

	.h2a-switch-thumb {
		background: ButtonText;
		box-shadow: none;
	}

	.h2a-switch[aria-checked="true"] .h2a-switch-track {
		background: Highlight;
	}

	.h2a-switch[aria-checked="true"] .h2a-switch-thumb {
		background: HighlightText;
	}
}
