/*
 * DEDE Panel dostępności 1.0.1 — style generyczne.
 * Wygląd sterowany zmiennymi --dede-a11y-*; motyw nadpisuje je własnym CSS (:where(:root) ma zerową
 * specyficzność, więc każda deklaracja motywu wygrywa niezależnie od kolejności arkuszy).
 *
 * Kontrasty domyślne (liczone): tekst #181D27 na #FFF 17,3:1; etykiety grup #535862 na #FFF 7,0:1;
 * obrys przycisku #717680 na #FFF 4,6:1 (UI ≥3:1); wciśnięty: #FFF na #181D27 17,3:1;
 * fokus #181D27 na #FFF 17,3:1. Tryby kontrastu: #FF0/#000 19,6:1, #FFF/#000 21:1.
 */

:where(:root) {
	--dede-a11y-font: inherit;
	--dede-a11y-bg: #fff;
	--dede-a11y-fg: #181d27;
	--dede-a11y-muted: #535862;
	--dede-a11y-line: #e9eaeb;
	--dede-a11y-control-line: #717680;
	--dede-a11y-hover: #f5f5f5;
	--dede-a11y-on-bg: #181d27;
	--dede-a11y-on-fg: #fff;
	--dede-a11y-focus: #181d27;
	--dede-a11y-radius: 8px;
	--dede-a11y-shadow: 0 12px 16px -4px rgba(10, 13, 18, .08), 0 4px 6px -2px rgba(10, 13, 18, .03);
	--dede-a11y-z: 1000;
	--dede-a11y-skala: 1;
	--dede-a11y-page-zoom: 1; /* motyw z `zoom` na stronie ustawia tu skalę: 100vw jest wtedy powiększane */
}

/* Bez JS (brak klasy z inline scriptu w <head>) przycisk nie ma sensu: ukryty. */
html:not(.dede-a11y-js) .dede-a11y__toggle { display: none !important; }

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

/* ---------- Kotwica i przycisk ---------- */
.dede-a11y { position: relative; display: inline-flex; }
.dede-a11y__toggle .dede-a11y__ico { flex-shrink: 0; }
.dede-a11y__toggle:focus-visible {
	outline: 2px solid var(--dede-a11y-focus);
	outline-offset: 2px;
}

/* Pływający przycisk (fallback, gdy motyw nie wywołał dede_a11y_panel_button()). */
.dede-a11y--floating {
	position: fixed;
	right: 16px;
	bottom: 16px;
	z-index: var(--dede-a11y-z);
}
.dede-a11y__toggle--floating {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	min-height: 44px;
	padding: 10px 16px;
	font: 600 .9375rem/1.25 var(--dede-a11y-font);
	color: var(--dede-a11y-on-fg);
	background: var(--dede-a11y-on-bg);
	border: 1px solid var(--dede-a11y-on-bg);
	border-radius: 999px;
	box-shadow: var(--dede-a11y-shadow);
	cursor: pointer;
}

/* ---------- Okienko ---------- */
.dede-a11y__panel {
	position: absolute;
	z-index: var(--dede-a11y-z);
	top: calc(100% + 8px);
	right: 0;
	box-sizing: border-box;
	width: min(25rem, calc((100vw - 32px) / var(--dede-a11y-page-zoom, 1)));
	max-height: var(--dede-a11y-maxh, 75vh);
	overflow-y: auto;
	overscroll-behavior: contain;
	padding: 16px;
	transform: translateX(var(--dede-a11y-shift, 0px));
	font-family: var(--dede-a11y-font);
	font-size: .875rem;
	line-height: 1.43;
	font-weight: 400;
	text-align: left;
	white-space: normal;
	color: var(--dede-a11y-fg);
	background: var(--dede-a11y-bg);
	border: 1px solid var(--dede-a11y-line);
	border-radius: var(--dede-a11y-radius);
	box-shadow: var(--dede-a11y-shadow);
}
.dede-a11y__panel[hidden] { display: none !important; }
.dede-a11y--floating .dede-a11y__panel { top: auto; bottom: calc(100% + 8px); }
.dede-a11y__panel *, .dede-a11y__panel *::before, .dede-a11y__panel *::after { box-sizing: border-box; }

.dede-a11y__panel :focus-visible {
	outline: 2px solid var(--dede-a11y-focus);
	outline-offset: 2px;
}

.dede-a11y__head {
	display: flex;
	flex-wrap: wrap; /* A++ z odstępami na 320 px: „Zamknij” schodzi pod tytuł zamiast wystawać */
	align-items: center;
	justify-content: space-between;
	gap: 8px;
	margin: 0 0 12px;
}
.dede-a11y__title {
	flex: 1 1 10rem;
	min-width: 0;
	margin: 0;
	font-size: 1rem;
	font-weight: 700;
	color: var(--dede-a11y-fg);
}

.dede-a11y__group { margin: 0 0 16px; padding: 0; border: 0; }
.dede-a11y__legend {
	margin: 0 0 8px;
	font-size: .8125rem;
	font-weight: 600;
	color: var(--dede-a11y-muted);
}
.dede-a11y__row { display: grid; gap: 8px; }
.dede-a11y__row--size { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.dede-a11y__row--contrast { grid-template-columns: repeat(auto-fit, minmax(10.5rem, 1fr)); }
.dede-a11y__row--tools { grid-template-columns: minmax(0, 1fr); }

/* Przyciski: min 44×44, obrys ≥3:1, stan = wypełnienie + podwójny obrys (nie sam kolor). */
.dede-a11y__opt,
.dede-a11y__close {
	display: flex;
	align-items: center;
	gap: 8px;
	min-width: 44px;
	min-height: 44px;
	margin: 0;
	padding: 8px 12px;
	font: inherit;
	font-weight: 600;
	color: var(--dede-a11y-fg);
	text-align: left;
	text-decoration: none;
	text-transform: none;
	letter-spacing: inherit;
	background: var(--dede-a11y-bg);
	border: 1px solid var(--dede-a11y-control-line);
	border-radius: var(--dede-a11y-radius);
	box-shadow: none;
	cursor: pointer;
	transition: background-color .15s ease, color .15s ease;
}
.dede-a11y__opt:hover,
.dede-a11y__close:hover { background: var(--dede-a11y-hover); color: var(--dede-a11y-fg); }
.dede-a11y__opt[aria-pressed="true"] {
	color: var(--dede-a11y-on-fg);
	background: var(--dede-a11y-on-bg);
	border-color: var(--dede-a11y-on-bg);
	box-shadow: inset 0 0 0 2px var(--dede-a11y-on-bg), inset 0 0 0 3px var(--dede-a11y-on-fg);
}
.dede-a11y__opt .dede-a11y__ico,
.dede-a11y__close .dede-a11y__ico { flex-shrink: 0; width: 20px; height: 20px; }

.dede-a11y__close { flex-shrink: 0; max-width: 100%; }

.dede-a11y__opt--size { justify-content: center; font-weight: 700; line-height: 1; }
.dede-a11y__opt--t0 { font-size: 1rem; }
.dede-a11y__opt--t1 { font-size: 1.125rem; }
.dede-a11y__opt--t2 { font-size: 1.25rem; }

.dede-a11y__swatch {
	display: inline-grid;
	place-items: center;
	flex-shrink: 0;
	width: 24px;
	height: 24px;
	border-radius: 50%;
	font-size: 13px;
	font-weight: 700;
	line-height: 1;
	letter-spacing: 0;
	border: 1px solid var(--dede-a11y-control-line);
}
.dede-a11y__swatch--dom { background: #fff; color: #181d27; }
.dede-a11y__swatch--cz { background: #000; color: #ff0; }
.dede-a11y__swatch--zc { background: #ff0; color: #000; }
.dede-a11y__swatch--cb { background: #000; color: #fff; }
.dede-a11y__swatch--bc { background: #fff; color: #000; }
.dede-a11y__opt[aria-pressed="true"] .dede-a11y__swatch { border-color: var(--dede-a11y-on-fg); }

.dede-a11y__foot {
	padding-top: 16px;
	border-top: 1px solid var(--dede-a11y-line);
}
.dede-a11y__reset { width: 100%; justify-content: center; }

@media (prefers-reduced-motion: reduce) {
	.dede-a11y__opt, .dede-a11y__close, .dede-a11y__toggle { transition: none; }
}

/* ---------- Rozmiar tekstu (font-size na <html>; motyw w px mapuje --dede-a11y-skala) ---------- */
html.a11y-tekst-1 { font-size: 115%; --dede-a11y-skala: 1.15; }
html.a11y-tekst-2 { font-size: 130%; --dede-a11y-skala: 1.3; }

/* ---------- Większe odstępy (WCAG 1.4.12) ---------- */
html.a11y-odstepy body { line-height: 1.8; }
html.a11y-odstepy body :where(*:not(svg, svg *)) { letter-spacing: .12em !important; word-spacing: .16em !important; }
html.a11y-odstepy :where(p, li, dd, dt, td, th, blockquote, figcaption, address, label, legend) { line-height: 1.8 !important; }
html.a11y-odstepy :where(h1, h2, h3, h4, h5, h6) { line-height: 1.5 !important; }
html.a11y-odstepy :where(p) { margin-bottom: 2em !important; }
html.a11y-odstepy .dede-a11y__panel p { margin-bottom: 8px !important; }

/* ---------- Podkreśl linki ---------- */
html.a11y-podkresl a { text-decoration: underline !important; text-decoration-thickness: 1px; text-underline-offset: .15em; }

/* ---------- Zatrzymaj animacje (jak prefers-reduced-motion, ale na żądanie) ---------- */
html.a11y-bez-animacji { scroll-behavior: auto !important; }
html.a11y-bez-animacji *,
html.a11y-bez-animacji *::before,
html.a11y-bez-animacji *::after {
	animation-duration: .001ms !important;
	animation-iteration-count: 1 !important;
	animation-delay: 0s !important;
	transition-duration: .001ms !important;
	transition-delay: 0s !important;
	scroll-behavior: auto !important;
}

/* ---------- Tryby kontrastu (tylko ekran; wydruk zostaje normalny) ---------- */
@media screen {
	html.a11y-kontrast-cz { --dede-a11y-hc-fg: #ff0; --dede-a11y-hc-bg: #000; color-scheme: dark; }
	html.a11y-kontrast-zc { --dede-a11y-hc-fg: #000; --dede-a11y-hc-bg: #ff0; color-scheme: light; }
	html.a11y-kontrast-cb { --dede-a11y-hc-fg: #fff; --dede-a11y-hc-bg: #000; color-scheme: dark; }
	html.a11y-kontrast-bc { --dede-a11y-hc-fg: #000; --dede-a11y-hc-bg: #fff; color-scheme: light; }

	html[class*="a11y-kontrast-"] {
		--dede-a11y-bg: var(--dede-a11y-hc-bg);
		--dede-a11y-fg: var(--dede-a11y-hc-fg);
		--dede-a11y-muted: var(--dede-a11y-hc-fg);
		--dede-a11y-line: var(--dede-a11y-hc-fg);
		--dede-a11y-control-line: var(--dede-a11y-hc-fg);
		--dede-a11y-hover: var(--dede-a11y-hc-bg);
		--dede-a11y-on-bg: var(--dede-a11y-hc-fg);
		--dede-a11y-on-fg: var(--dede-a11y-hc-bg);
		--dede-a11y-focus: var(--dede-a11y-hc-fg);
		background: var(--dede-a11y-hc-bg);
	}

	/* Spłaszczenie: wszystko w parze trybu; zdjęcia i wideo bez przebarwiania. */
	html[class*="a11y-kontrast-"] :where(*:not(img, video, picture, iframe, canvas)) {
		background-color: var(--dede-a11y-hc-bg) !important;
		background-image: none !important;
		color: var(--dede-a11y-hc-fg) !important;
		border-color: var(--dede-a11y-hc-fg) !important;
		box-shadow: none !important;
		text-shadow: none !important;
		-webkit-backdrop-filter: none !important;
		backdrop-filter: none !important;
	}
	html[class*="a11y-kontrast-"] :where(*)::before,
	html[class*="a11y-kontrast-"] :where(*)::after {
		color: var(--dede-a11y-hc-fg) !important;
		border-color: var(--dede-a11y-hc-fg) !important;
	}
	html[class*="a11y-kontrast-"] :where(svg, svg *) { color: inherit !important; background-color: transparent !important; }
	html[class*="a11y-kontrast-"] a { text-decoration: underline !important; text-decoration-color: var(--dede-a11y-hc-fg) !important; }
	html[class*="a11y-kontrast-"] :where(button, a):hover { text-decoration: underline !important; text-decoration-thickness: 2px !important; }
	html[class*="a11y-kontrast-"] :where([aria-pressed="true"], [aria-current]:not([aria-current="false"])),
	html[class*="a11y-kontrast-"] :where([aria-pressed="true"], [aria-current]:not([aria-current="false"])) :where(*:not(img, video)) {
		background-color: var(--dede-a11y-hc-fg) !important;
		color: var(--dede-a11y-hc-bg) !important;
	}
	html[class*="a11y-kontrast-"] :where(button, input, select, textarea) { border: 1px solid var(--dede-a11y-hc-fg) !important; }
	html[class*="a11y-kontrast-"] ::selection { background: var(--dede-a11y-hc-fg); color: var(--dede-a11y-hc-bg); }
	html[class*="a11y-kontrast-"] :focus-visible { outline: 3px solid var(--dede-a11y-hc-fg) !important; outline-offset: 2px !important; }

	/* Panel w trybie: fokus 2 px, wciśnięty = wypełnienie + wewnętrzny pierścień w barwie tła. */
	html[class*="a11y-kontrast-"] .dede-a11y__panel { border: 2px solid var(--dede-a11y-hc-fg) !important; }
	html[class*="a11y-kontrast-"] .dede-a11y__panel :focus-visible,
	html[class*="a11y-kontrast-"] .dede-a11y__toggle:focus-visible { outline: 2px solid var(--dede-a11y-hc-fg) !important; outline-offset: 2px !important; }
	html[class*="a11y-kontrast-"] .dede-a11y__opt[aria-pressed="true"] {
		background-color: var(--dede-a11y-hc-fg) !important;
		color: var(--dede-a11y-hc-bg) !important;
		box-shadow: inset 0 0 0 2px var(--dede-a11y-hc-bg) !important;
	}
	html[class*="a11y-kontrast-"] .dede-a11y__opt[aria-pressed="true"] > span:not(.dede-a11y__swatch) { background-color: transparent !important; color: var(--dede-a11y-hc-bg) !important; }
	html[class*="a11y-kontrast-"] .dede-a11y__panel .dede-a11y__swatch--dom { background-color: #fff !important; color: #181d27 !important; border-color: var(--dede-a11y-hc-fg) !important; }
	html[class*="a11y-kontrast-"] .dede-a11y__panel .dede-a11y__swatch--cz { background-color: #000 !important; color: #ff0 !important; border-color: var(--dede-a11y-hc-fg) !important; }
	html[class*="a11y-kontrast-"] .dede-a11y__panel .dede-a11y__swatch--zc { background-color: #ff0 !important; color: #000 !important; border-color: var(--dede-a11y-hc-fg) !important; }
	html[class*="a11y-kontrast-"] .dede-a11y__panel .dede-a11y__swatch--cb { background-color: #000 !important; color: #fff !important; border-color: var(--dede-a11y-hc-fg) !important; }
	html[class*="a11y-kontrast-"] .dede-a11y__panel .dede-a11y__swatch--bc { background-color: #fff !important; color: #000 !important; border-color: var(--dede-a11y-hc-fg) !important; }
	html[class*="a11y-kontrast-"] .dede-a11y__panel [aria-pressed="true"] .dede-a11y__swatch { border-color: var(--dede-a11y-hc-bg) !important; }
}
