/*
 * ESYD accessibility controls.
 *
 * Two halves: the widget's own appearance, which follows the design system —
 * navy #213264, hairline #d9dde8, 44px targets — and the effects the controls
 * apply to the page, which hang off data attributes on <html>.
 *
 * The effects use !important throughout, on purpose. They exist to override a
 * stylesheet that was written without them in mind, and a reader who asks for
 * bigger spacing is overruling the design, which is the whole idea of 1.4.12.
 */

.esyd-a11y {
	--a11y-navy: #213264;
	--a11y-line: #d9dde8;
	--a11y-muted: #5a6478;
	--a11y-tint: #f3f4f8;
	--a11y-hover: #eaf1fa;
	--a11y-scale: 1;

	position: fixed;
	inset-block-end: 20px;
	z-index: 9999;
	display: flex;
	flex-direction: column;
	align-items: flex-end;
	gap: 12px;
	font-family: inherit;
}

.esyd-a11y--right { inset-inline-end: 20px; }
.esyd-a11y--left { inset-inline-start: 20px; align-items: flex-start; }
.esyd-a11y[hidden] { display: none; }

/*
 * The page may be inverted under us. The widget is inside <html> and takes
 * the filter with everything else, so it inverts itself back — otherwise the
 * one control that undoes the inversion is the one you cannot read.
 */
.esyd-a11y { filter: var(--esyd-a11y-counter, none); }

/* Our own, so the plugin does not lean on the theme for it. */
.esyd-a11y .screen-reader-text {
	position: absolute;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip-path: inset(50%);
	white-space: nowrap;
	border: 0;
}

/* The launcher ------------------------------------------------------------ */

.esyd-a11y__launch {
	display: flex;
	align-items: center;
	justify-content: center;
	width: calc(56px * var(--a11y-scale));
	height: calc(56px * var(--a11y-scale));
	padding: 0;
	border: 2px solid #fff;
	border-radius: 50%;
	background-color: var(--a11y-navy);
	color: #fff;
	box-shadow: 0 1px 3px rgb(33 50 100 / 20%), 0 4px 12px rgb(33 50 100 / 20%);
	cursor: pointer;
}

.esyd-a11y__launch svg {
	width: calc(28px * var(--a11y-scale));
	height: calc(28px * var(--a11y-scale));
}

.esyd-a11y__launch:hover { background-color: #2c4383; }

/*
 * Away on the way down.
 *
 * Only where there is little room: a width, not a hover query, because this is
 * about a phone's screen and not about touch. Out through the bottom rather
 * than faded in place, so it reads as having stepped aside and not as having
 * broken. pointer-events off while it is gone, or a thumb finds a button that
 * is not there.
 */
.esyd-a11y__launch {
	transition: transform 260ms cubic-bezier(0.2, 0, 0, 1), opacity 200ms ease-out;
}

.esyd-a11y__launch.is-away {
	transform: translateY(calc(100% + 28px));
	opacity: 0;
	pointer-events: none;
}

@media (prefers-reduced-motion: reduce) {
	.esyd-a11y__launch { transition: none; }
}


.esyd-a11y :focus-visible {
	outline: 3px solid #f7b817;
	outline-offset: 2px;
}

/* The panel --------------------------------------------------------------- */

.esyd-a11y__panel {
	order: -1;
	width: calc(340px * var(--a11y-scale));
	max-width: calc(100vw - 40px);
	max-height: calc(100vh - 120px);
	overflow-y: auto;
	padding: calc(20px * var(--a11y-scale));
	border: 1px solid var(--a11y-line);
	border-radius: 12px;
	background-color: #fff;
	box-shadow: 0 1px 3px rgb(33 50 100 / 10%), 0 4px 8px 3px rgb(33 50 100 / 8%);
}

.esyd-a11y__panel[hidden] { display: none; }

.esyd-a11y__head {
	display: flex;
	align-items: center;
	gap: 10px;
	margin-block-end: 16px;
}

.esyd-a11y__title {
	flex: 1;
	color: var(--a11y-navy);
	font-size: calc(18px * var(--a11y-scale));
	font-weight: 700;
}

/*
 * A plain checkbox and not a card: it is a true on/off, and it governs the
 * panel rather than the page, so it reads better set apart from the grid.
 */
.esyd-a11y__big {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	min-height: calc(40px * var(--a11y-scale));
	margin-block-end: calc(12px * var(--a11y-scale));
	padding: 0 calc(12px * var(--a11y-scale));
	border: 1px solid var(--a11y-line);
	border-radius: 8px;
	background-color: var(--a11y-tint);
	color: var(--a11y-muted);
	font-size: calc(13px * var(--a11y-scale));
	font-weight: 600;
	cursor: pointer;
}

.esyd-a11y__switch-input {
	position: absolute;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip-path: inset(50%);
	white-space: nowrap;
	border: 0;
}

.esyd-a11y__switch {
	position: relative;
	flex-shrink: 0;
	width: calc(44px * var(--a11y-scale));
	height: calc(26px * var(--a11y-scale));
	border-radius: 999px;
	background-color: #c6cbd9;
	transition: background-color 160ms ease-out;
}

.esyd-a11y__switch::after {
	content: "";
	position: absolute;
	inset-block-start: calc(3px * var(--a11y-scale));
	inset-inline-start: calc(3px * var(--a11y-scale));
	width: calc(20px * var(--a11y-scale));
	height: calc(20px * var(--a11y-scale));
	border-radius: 50%;
	background-color: #fff;
	box-shadow: 0 1px 3px rgb(17 26 53 / 35%);
	transition: transform 160ms ease-out;
}

.esyd-a11y__switch-input:checked + .esyd-a11y__switch { background-color: var(--a11y-navy); }

.esyd-a11y__switch-input:checked + .esyd-a11y__switch::after {
	transform: translateX(calc(18px * var(--a11y-scale)));
}

.esyd-a11y__switch-input:focus-visible + .esyd-a11y__switch {
	outline: 3px solid #f7b817;
	outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
	.esyd-a11y__switch,
	.esyd-a11y__switch::after { transition: none; }
}

.esyd-a11y__close {
	display: flex;
	align-items: center;
	justify-content: center;
	width: calc(32px * var(--a11y-scale));
	height: calc(32px * var(--a11y-scale));
	padding: 0;
	border: 1px solid var(--a11y-line);
	border-radius: 4px;
	background-color: #fff;
	color: var(--a11y-navy);
	cursor: pointer;
}

.esyd-a11y__close:hover { background-color: var(--a11y-hover); }

/* The cards --------------------------------------------------------------- */

.esyd-a11y__grid {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: calc(8px * var(--a11y-scale));
}

.esyd-a11y__card {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: flex-start;
	gap: calc(6px * var(--a11y-scale));
	min-height: calc(96px * var(--a11y-scale));
	padding: calc(12px * var(--a11y-scale)) calc(8px * var(--a11y-scale));
	border: 1px solid var(--a11y-line);
	border-radius: 8px;
	background-color: #fff;
	color: var(--a11y-navy);
	font-family: inherit;
	font-size: calc(13px * var(--a11y-scale));
	font-weight: 600;
	line-height: 1.25;
	text-align: center;
	cursor: pointer;
}

.esyd-a11y__card:hover { background-color: var(--a11y-hover); }

.esyd-a11y__icon {
	width: calc(24px * var(--a11y-scale));
	height: calc(24px * var(--a11y-scale));
	flex-shrink: 0;
}

.esyd-a11y__label { display: block; }

.esyd-a11y__pill {
	margin-block-start: auto;
	padding: calc(3px * var(--a11y-scale)) calc(8px * var(--a11y-scale));
	border-radius: 4px;
	background-color: var(--a11y-tint);
	color: var(--a11y-muted);
	font-size: calc(11px * var(--a11y-scale));
	font-weight: 700;
}

.esyd-a11y__card[aria-pressed="true"] {
	border-color: var(--a11y-navy);
	background-color: var(--a11y-navy);
	color: #fff;
}

.esyd-a11y__card[aria-pressed="true"] .esyd-a11y__pill {
	background-color: rgb(255 255 255 / 22%);
	color: #fff;
}

.esyd-a11y__reset {
	width: 100%;
	min-height: calc(44px * var(--a11y-scale));
	margin-block-start: calc(16px * var(--a11y-scale));
	padding: calc(10px * var(--a11y-scale)) calc(16px * var(--a11y-scale));
	border: 1px solid var(--a11y-navy);
	border-radius: 8px;
	background-color: var(--a11y-navy);
	color: #fff;
	font-family: inherit;
	font-size: calc(14px * var(--a11y-scale));
	font-weight: 700;
	cursor: pointer;
}

.esyd-a11y__reset:hover { background-color: #2c4383; }

.esyd-a11y__statement {
	display: inline-block;
	margin-block-start: calc(12px * var(--a11y-scale));
	color: var(--a11y-navy);
	font-size: calc(13px * var(--a11y-scale));
}

/* The oversized panel, which the widget it replaces also offered. */
.esyd-a11y.is-big { --a11y-scale: 1.3; }

@media (width <= 480px) {
	.esyd-a11y__panel { width: calc(100vw - 40px); }
	.esyd-a11y.is-big { --a11y-scale: 1.1; }
}

/* ========================================================================= */
/* The effects                                                               */
/* ========================================================================= */

/*
 * Inversion and saturation are composed into one filter by the script, since
 * an element has only one filter property. It sits on <html> rather than on
 * <body>: measured in Chrome, a filter on the root leaves position:fixed
 * tracking the viewport, while the same filter on body makes every fixed
 * thing on the page scroll away with the document.
 */
html { filter: var(--esyd-a11y-filter, none); }

/* Contrast: dark -------------------------------------------------------- */

html[data-esyd-a11y-contrast="1"],
html[data-esyd-a11y-contrast="1"] body {
	background: #000 !important;
	color: #fff !important;
}

html[data-esyd-a11y-contrast="1"] body *:not(.esyd-a11y, .esyd-a11y *) {
	background-color: transparent !important;
	background-image: none !important;
	color: #fff !important;
	border-color: #fff !important;
	box-shadow: none !important;
}

html[data-esyd-a11y-contrast="1"] body a:not(.esyd-a11y *),
html[data-esyd-a11y-contrast="1"] body a:not(.esyd-a11y *) * {
	color: #ffe066 !important;
}

/* Contrast: light ------------------------------------------------------- */

html[data-esyd-a11y-contrast="2"],
html[data-esyd-a11y-contrast="2"] body {
	background: #fff !important;
	color: #000 !important;
}

html[data-esyd-a11y-contrast="2"] body *:not(.esyd-a11y, .esyd-a11y *) {
	background-color: transparent !important;
	background-image: none !important;
	color: #000 !important;
	border-color: #000 !important;
	box-shadow: none !important;
}

html[data-esyd-a11y-contrast="2"] body a:not(.esyd-a11y *),
html[data-esyd-a11y-contrast="2"] body a:not(.esyd-a11y *) * {
	color: #0000cc !important;
}

/* Highlight links --------------------------------------------------------- */

html[data-esyd-a11y-links="1"] body a:not(.esyd-a11y *) {
	outline: 2px solid #f7b817 !important;
	outline-offset: 2px;
	text-decoration: underline !important;
	text-underline-offset: 3px;
}

/* Stop animations --------------------------------------------------------- */

html[data-esyd-a11y-still="1"] *:not(.esyd-a11y, .esyd-a11y *),
html[data-esyd-a11y-still="1"] *:not(.esyd-a11y, .esyd-a11y *)::before,
html[data-esyd-a11y-still="1"] *:not(.esyd-a11y, .esyd-a11y *)::after {
	animation: none !important;
	transition: none !important;
	scroll-behavior: auto !important;
}

/* Hide images ------------------------------------------------------------- */

/*
 * The alt text takes the picture's place rather than the row collapsing, so
 * a reader who hid the images still knows what stood there.
 */
html[data-esyd-a11y-noimages="1"] body :is(img, picture, video, canvas):not(.esyd-a11y *) {
	visibility: hidden !important;
	position: relative;
}

html[data-esyd-a11y-noimages="1"] body img:not(.esyd-a11y *)::after {
	content: attr(alt);
	visibility: visible;
	position: absolute;
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 8px;
	background-color: #f3f4f8;
	color: #213264;
	font-size: 14px;
	text-align: center;
}

html[data-esyd-a11y-noimages="1"] body *:not(.esyd-a11y, .esyd-a11y *) {
	background-image: none !important;
}

/* Text spacing ------------------------------------------------------------ */

/*
 * The steps are 1.4.12's own numbers, then half as much again. The criterion
 * asks that a page survive these; offering them is the same thing read the
 * other way round.
 */
html[data-esyd-a11y-spacing="1"] body *:not(.esyd-a11y, .esyd-a11y *) {
	letter-spacing: 0.12em !important;
	word-spacing: 0.16em !important;
}

html[data-esyd-a11y-spacing="2"] body *:not(.esyd-a11y, .esyd-a11y *) {
	letter-spacing: 0.18em !important;
	word-spacing: 0.24em !important;
}

html[data-esyd-a11y-spacing="1"] body :is(p, li):not(.esyd-a11y *) { margin-block-end: 2em !important; }
html[data-esyd-a11y-spacing="2"] body :is(p, li):not(.esyd-a11y *) { margin-block-end: 2.5em !important; }

/* Line height ------------------------------------------------------------- */

html[data-esyd-a11y-lineheight="1"] body *:not(.esyd-a11y, .esyd-a11y *) { line-height: 1.5 !important; }
html[data-esyd-a11y-lineheight="2"] body *:not(.esyd-a11y, .esyd-a11y *) { line-height: 1.75 !important; }
html[data-esyd-a11y-lineheight="3"] body *:not(.esyd-a11y, .esyd-a11y *) { line-height: 2 !important; }

/* Text alignment ---------------------------------------------------------- */

html[data-esyd-a11y-align="1"] body :is(p, li, h1, h2, h3, h4, h5, h6, td, th, dd, dt, figcaption):not(.esyd-a11y *) { text-align: left !important; }
html[data-esyd-a11y-align="2"] body :is(p, li, h1, h2, h3, h4, h5, h6, td, th, dd, dt, figcaption):not(.esyd-a11y *) { text-align: center !important; }
html[data-esyd-a11y-align="3"] body :is(p, li, h1, h2, h3, h4, h5, h6, td, th, dd, dt, figcaption):not(.esyd-a11y *) { text-align: right !important; }

/* Cursor ------------------------------------------------------------------ */

html[data-esyd-a11y-cursor="1"] body *:not(.esyd-a11y *) {
	cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='48' height='48' viewBox='0 0 24 24'%3E%3Cpath d='m5 2 15 10.5-7 1.5-2.5 7z' fill='%23fff' stroke='%23213264' stroke-width='1.6' stroke-linejoin='round'/%3E%3C/svg%3E") 4 2, auto !important;
}

html[data-esyd-a11y-cursor="1"] body :is(a, button, input, select, textarea, [role="button"]):not(.esyd-a11y *) {
	cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='48' height='48' viewBox='0 0 24 24'%3E%3Cpath d='M9 11V5.5a1.5 1.5 0 0 1 3 0V11m0-1.5a1.5 1.5 0 0 1 3 0V12m0-1a1.5 1.5 0 0 1 3 0v4a6 6 0 0 1-6 6h-1a6 6 0 0 1-6-6v-4a1.5 1.5 0 0 1 3 0' fill='%23fff' stroke='%23213264' stroke-width='1.4' stroke-linejoin='round'/%3E%3C/svg%3E") 12 4, pointer !important;
}

/* The reading mask: two shades drawn by the script, following the pointer. */
.esyd-a11y-mask {
	position: fixed;
	inset-inline: 0;
	z-index: 9998;
	height: 100vh;
	background-color: rgb(17 26 53 / 68%);
	pointer-events: none;
}
