/**
 * Accessibility widget styles (Goodahead_AccessibilityWidget), for both themes: the effects on the page, then the
 * few widget styles Tailwind 3 (kamage) and 4 (kamage-checkout) would render differently.
 *
 * Every rule is keyed by an attribute the widget puts on <html> (see view/frontend/web/ts/a11y/settings.ts), so with
 * nothing turned on this file does nothing. The widget itself ([data-a11y-widget]) is left out of the content
 * effects, so the menu stays usable whatever is on.
 *
 * Colours come from --a11y-color-* custom properties, which each theme maps from its own tokens
 * (kamage: web/satoshi/components/a11y.css, kamage-checkout: web/tailwind/components/a11y.css).
 * The values below are only fallbacks for a theme that does not map them; :where() keeps them overridable.
 */

:where(:root) {
    --a11y-color-accent: #1d6a93;
    --a11y-color-mark: #ffb625;
    --a11y-color-ink: #131416;
    --a11y-color-paper: #ffffff;
    --a11y-color-link-on-light: #185878;
    --a11y-color-surface: #ecf0f1;
    --a11y-color-border: #e8e9eb;
    --a11y-color-muted: #717684;
}

/* Dyslexia font: downloaded only when the setting is on and an element uses it. */
@font-face {
    font-family: "OpenDyslexic";
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url("../fonts/opendyslexic/opendyslexic-latin-400-normal.woff2") format("woff2");
}

@font-face {
    font-family: "OpenDyslexic";
    font-style: normal;
    font-weight: 700;
    font-display: swap;
    src: url("../fonts/opendyslexic/opendyslexic-latin-700-normal.woff2") format("woff2");
}

/* ---------- Content ---------- */

/* Font size: rem-based text follows the root size; the few fixed px sizes in the themes are scaled by name. */
html[data-a11y-font-size] {
    font-size: calc(100% * var(--a11y-font-size, 1)) !important;
}

html[data-a11y-font-size] .text-\[10px\] { font-size: calc(10px * var(--a11y-font-size, 1)) !important; }
html[data-a11y-font-size] .text-\[11px\] { font-size: calc(11px * var(--a11y-font-size, 1)) !important; }
html[data-a11y-font-size] .text-\[12px\] { font-size: calc(12px * var(--a11y-font-size, 1)) !important; }
html[data-a11y-font-size] .text-\[15px\] { font-size: calc(15px * var(--a11y-font-size, 1)) !important; }
html[data-a11y-font-size] .text-\[14px\] { font-size: calc(14px * var(--a11y-font-size, 1)) !important; }
html[data-a11y-font-size] .text-\[28px\] { font-size: calc(28px * var(--a11y-font-size, 1)) !important; }
html[data-a11y-font-size] .text-\[32px\] { font-size: calc(32px * var(--a11y-font-size, 1)) !important; }
html[data-a11y-font-size] .text-\[34px\] { font-size: calc(34px * var(--a11y-font-size, 1)) !important; }

html[data-a11y-font-size] :has(> form[id^="quick_buy_form_"].absolute) {
    flex-wrap: wrap;
}
html[data-a11y-font-size] form[id^="quick_buy_form_"].absolute {
    position: static !important;
    margin-left: auto;
}

html[data-a11y-font-weight] body :not([data-a11y-widget], [data-a11y-widget] *) {
    font-weight: 700 !important;
}

/* Line height: 1.5 is the WCAG 1.4.12 minimum; higher levels add more air. */
html[data-a11y-line-height="1"] body :not([data-a11y-widget], [data-a11y-widget] *) { line-height: 1.5 !important; }
html[data-a11y-line-height="2"] body :not([data-a11y-widget], [data-a11y-widget] *) { line-height: 1.75 !important; }
html[data-a11y-line-height="3"] body :not([data-a11y-widget], [data-a11y-widget] *) { line-height: 2 !important; }

/* Letter spacing: level 2 is the WCAG 1.4.12 text spacing (0.12em letters, 0.16em words). */
html[data-a11y-letter-spacing="1"] body :not([data-a11y-widget], [data-a11y-widget] *) {
    letter-spacing: 0.06em !important;
    word-spacing: 0.08em !important;
}

html[data-a11y-letter-spacing="2"] body :not([data-a11y-widget], [data-a11y-widget] *) {
    letter-spacing: 0.12em !important;
    word-spacing: 0.16em !important;
}

html[data-a11y-dyslexia-font] body :not([data-a11y-widget], [data-a11y-widget] *, code, pre, kbd, samp) {
    font-family: "OpenDyslexic", sans-serif !important;
}

html[data-a11y-highlight-links] body a:not([data-a11y-widget] *) {
    text-decoration: underline !important;
    text-decoration-thickness: 2px !important;
    text-underline-offset: 3px !important;
    outline: 2px solid var(--a11y-color-accent) !important;
    outline-offset: 2px !important;
    background-color: var(--a11y-color-mark) !important;
    color: var(--a11y-color-ink) !important;
}

html[data-a11y-highlight-titles] body :is(h1, h2, h3, h4, h5, h6, [role="heading"]):not([data-a11y-widget] *) {
    outline: 2px dashed var(--a11y-color-accent) !important;
    outline-offset: 4px !important;
}

/* ---------- Visual & navigation aids ---------- */

/* Super focus: a thick ring with a light halo, readable on dark and light; applies to the widget too. */
html[data-a11y-super-focus] :focus-visible {
    outline: 3px solid var(--a11y-color-accent) !important;
    outline-offset: 3px !important;
    box-shadow: 0 0 0 7px var(--a11y-color-paper) !important;
}

html[data-a11y-big-cursor],
html[data-a11y-big-cursor] * {
    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='M4 2l15 10.5-6.5 1.2 3.8 7.3-2.6 1.3-3.8-7.3L5 19.5z' fill='%23000' stroke='%23fff' stroke-width='1.3' stroke-linejoin='round'/%3E%3C/svg%3E") 8 4, auto !important;
}

html[data-a11y-big-cursor] :is(a, button, label, select, summary, [role="button"], [role="link"], [role="tab"], [role="radio"], [role="checkbox"], input:is([type="checkbox"], [type="radio"], [type="submit"], [type="button"])),
html[data-a11y-big-cursor] :is(a, button, label, summary, [role="button"], [role="link"]) * {
    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 11V4.5a1.5 1.5 0 0 1 3 0V10m0-.5a1.5 1.5 0 0 1 3 0v1m0-.5a1.5 1.5 0 0 1 3 0v1.5m0-.5a1.5 1.5 0 0 1 3 0V17a5 5 0 0 1-5 5h-2.5a5 5 0 0 1-4.1-2.2L4.6 15a1.6 1.6 0 0 1 2.4-2.1L9 15z' fill='%23fff' stroke='%23000' stroke-width='1.3' stroke-linejoin='round'/%3E%3C/svg%3E") 18 4, pointer !important;
}

html[data-a11y-big-cursor] :is(input:not([type="checkbox"], [type="radio"], [type="submit"], [type="button"]), textarea, [contenteditable="true"]) {
    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 3h6M9 21h6M12 3v18' fill='none' stroke='%23fff' stroke-width='4' stroke-linecap='round'/%3E%3Cpath d='M9 3h6M9 21h6M12 3v18' fill='none' stroke='%23000' stroke-width='1.8' stroke-linecap='round'/%3E%3C/svg%3E") 24 24, text !important;
}

/* ---------- Colour ---------- */

/*
 * Saturation and high contrast are filters on <html>: the root is the one element whose filter does not become
 * the containing block of position:fixed descendants, so the fixed header, drawers and sticky bars keep working.
 * Both can be on at once, so they share one filter value.
 */
html[data-a11y-saturation="monochrome"] { --a11y-filter-saturation: grayscale(1); }
html[data-a11y-saturation="low"] { --a11y-filter-saturation: saturate(0.5); }
html[data-a11y-saturation="high"] { --a11y-filter-saturation: saturate(2); }
html[data-a11y-contrast="high"] { --a11y-filter-contrast: contrast(1.35); }

html[data-a11y-saturation],
html[data-a11y-contrast="high"] {
    filter: var(--a11y-filter-saturation,) var(--a11y-filter-contrast,) !important;
}

/*
 * Dark and light contrast: text and borders in two colours everywhere, backgrounds only on the elements that
 * already paint one (marked data-a11y-surface by the widget script), so transparent wrappers over images stay
 * transparent. Nothing applies until the page is marked (data-a11y-surfaces on <html>). Media keep their colours.
 */
html[data-a11y-contrast="dark"][data-a11y-surfaces],
html[data-a11y-contrast="dark"][data-a11y-surfaces] body {
    background-color: var(--a11y-color-ink) !important;
    color: var(--a11y-color-paper) !important;
}

html[data-a11y-contrast="dark"][data-a11y-surfaces] body :not([data-a11y-widget], [data-a11y-widget] *, img, picture, video, canvas, iframe) {
    color: var(--a11y-color-paper) !important;
    border-color: var(--a11y-color-paper) !important;
    text-shadow: none !important;
    box-shadow: none !important;
}

html[data-a11y-contrast="dark"][data-a11y-surfaces] body [data-a11y-surface] {
    background-color: var(--a11y-color-ink) !important;
}

html[data-a11y-contrast="dark"][data-a11y-surfaces] body :is(a, a *):not([data-a11y-widget] *) {
    color: var(--a11y-color-mark) !important;
}

html[data-a11y-contrast="light"][data-a11y-surfaces],
html[data-a11y-contrast="light"][data-a11y-surfaces] body {
    background-color: var(--a11y-color-paper) !important;
    color: var(--a11y-color-ink) !important;
}

html[data-a11y-contrast="light"][data-a11y-surfaces] body :not([data-a11y-widget], [data-a11y-widget] *, img, picture, video, canvas, iframe) {
    color: var(--a11y-color-ink) !important;
    border-color: var(--a11y-color-ink) !important;
    text-shadow: none !important;
    box-shadow: none !important;
}

html[data-a11y-contrast="light"][data-a11y-surfaces] body [data-a11y-surface] {
    background-color: var(--a11y-color-paper) !important;
}

html[data-a11y-contrast="light"][data-a11y-surfaces] body :is(a, a *):not([data-a11y-widget] *) {
    color: var(--a11y-color-link-on-light) !important;
}

/* Product images use mix-blend-mode to sit on the grey tile; on a repainted background that would hide them. */
html:is([data-a11y-contrast="dark"], [data-a11y-contrast="light"])[data-a11y-surfaces] body :is(img, picture, video) {
    mix-blend-mode: normal !important;
}

/*
 * Dark artwork drawn for a light page (logos as <img>): the theme marks it data-a11y-invert-dark. Inverted with
 * the hue turned back, so dark parts become light and colours stay close to their own.
 */
html[data-a11y-contrast="dark"][data-a11y-surfaces] body [data-a11y-invert-dark] {
    filter: invert(1) hue-rotate(180deg) !important;
}

/* ---------- Additional tools ---------- */

/*
 * Stop animations: durations are cut to almost zero rather than removed, so code waiting for transitionend or
 * animationend still gets the event. Videos and sliders are paused by the widget script.
 */
html[data-a11y-stop-animations] *,
html[data-a11y-stop-animations] *::before,
html[data-a11y-stop-animations] *::after {
    animation-duration: 0.001ms !important;
    animation-delay: 0s !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    transition-delay: 0s !important;
    scroll-behavior: auto !important;
}

html[data-a11y-stop-animations]::view-transition-group(*),
html[data-a11y-stop-animations]::view-transition-old(*),
html[data-a11y-stop-animations]::view-transition-new(*) {
    animation: none !important;
}

/* Hide images: hidden, not removed, so the layout does not jump; icons (inline SVG) stay. */
html[data-a11y-hide-images] body :is(img, picture, video, canvas, iframe, [role="img"]):not([data-a11y-widget] *, svg) {
    visibility: hidden !important;
}

html[data-a11y-hide-images] body :not([data-a11y-widget], [data-a11y-widget] *) {
    background-image: none !important;
}

/* ---------- Page tools (ts/a11y/tools.ts, speech.ts) ---------- */

/*
 * Reading guide: a thin line across the page under the line being read (tools.ts places it below the
 * pointer); never catches the pointer itself. Mark colour with ink edges: seen on light and dark pages.
 */
.a11y-reading-guide {
    position: fixed;
    inset-inline: 0;
    top: -2px;
    z-index: 2147483646;
    height: 4px;
    background-color: var(--a11y-color-mark);
    box-shadow: 0 0 0 1px var(--a11y-color-ink);
    pointer-events: none;
    will-change: transform;
}

/* Image tooltip: the alt text next to the pointer or under the focused image. */
.a11y-image-tooltip {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 2147483647;
    max-width: min(320px, calc(100vw - 16px));
    padding: 8px 12px;
    border-radius: 8px;
    background-color: var(--a11y-color-ink);
    color: var(--a11y-color-paper);
    font: 500 14px/1.4 system-ui, sans-serif;
    box-shadow: 0 4px 16px rgb(0 0 0 / 0.24);
    pointer-events: none;
    overflow-wrap: break-word;
}

:is(.a11y-reading-guide, .a11y-image-tooltip)[hidden] {
    display: none;
}

/* Read aloud: the element being spoken. */
[data-a11y-speaking] {
    outline: 3px dashed var(--a11y-color-accent) !important;
    outline-offset: 3px !important;
}

/* ---------- Widget ---------- */

/*
 * The text effects leave the widget out, but it sits inside page wrappers that get them, and these properties
 * are inherited: the widget root sets its own. Font from the theme (--a11y-font-family).
 */
[data-a11y-widget][x-data] {
    font-family: var(--a11y-font-family, system-ui, sans-serif) !important;
    font-weight: 400 !important;
    line-height: 1.5 !important;
    letter-spacing: normal !important;
    word-spacing: normal !important;
}

/* Native modal dialog: reset the browser's box and stick it to one side, full height. */
[data-a11y-widget] dialog[data-a11y-dialog] {
    position: fixed;
    inset-block: 0;
    inset-inline: 0 auto;
    margin: 0;
    padding: 0;
    border: 0;
    width: min(500px, 100vw);
    max-width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    overflow: hidden;
    background-color: var(--a11y-color-surface);
    color: var(--a11y-color-ink);
    box-shadow: 0 0 32px rgb(0 0 0 / 0.24);
}

[data-a11y-widget][data-position="right"] dialog[data-a11y-dialog] {
    inset-inline: auto 0;
}

/*
 * Rounded on the inner side only, from the size the minicart drawer rounds its side (sm:rounded-l-lg, 12px);
 * set in full because themes give <dialog> their own radius (Hyvä default: all four corners).
 */
[data-a11y-widget] dialog[data-a11y-dialog] {
    border-radius: 0;
}

@media (min-width: 641px) {
    [data-a11y-widget] dialog[data-a11y-dialog] {
        border-start-end-radius: 12px;
        border-end-end-radius: 12px;
    }

    [data-a11y-widget][data-position="right"] dialog[data-a11y-dialog] {
        border-start-end-radius: 0;
        border-end-end-radius: 0;
        border-start-start-radius: 12px;
        border-end-start-radius: 12px;
    }
}

/* Page structure: a centred box, full screen on phones. */
[data-a11y-widget] dialog[data-a11y-structure] {
    margin: auto;
    padding: 0;
    border: 0;
    border-radius: 12px;
    width: min(560px, calc(100vw - 32px));
    max-width: 100vw;
    height: min(720px, calc(100dvh - 32px));
    max-height: 100dvh;
    overflow: hidden;
    background-color: var(--a11y-color-paper);
    color: var(--a11y-color-ink);
    box-shadow: 0 8px 40px rgb(0 0 0 / 0.32);
}

@media (max-width: 639px) {
    [data-a11y-widget] dialog[data-a11y-structure] {
        width: 100vw;
        height: 100dvh;
        border-radius: 0;
    }
}

[data-a11y-widget] dialog[data-a11y-structure]::backdrop,
[data-a11y-widget] dialog[data-a11y-dialog]::backdrop {
    background-color: rgb(0 0 0 / 0.32);
}

@media (prefers-reduced-motion: no-preference) {
    /* Moves above the page's bottom bars (ts/a11y/fab.ts). */
    [data-a11y-widget] [data-a11y-fab] {
        transition: transform 0.2s ease-out;
    }

    [data-a11y-widget] dialog[data-a11y-dialog][open] {
        animation: a11y-panel-in 0.2s ease-out;
    }

    [data-a11y-widget][data-position="right"] dialog[data-a11y-dialog][open] {
        animation-name: a11y-panel-in-right;
    }
}

@keyframes a11y-panel-in {
    from { transform: translateX(-24px); opacity: 0; }
}

@keyframes a11y-panel-in-right {
    from { transform: translateX(24px); opacity: 0; }
}

/* One focus ring for every control of the widget, readable on the accent header and on light cards. */
[data-a11y-widget] :is(button, a):focus-visible {
    outline: 3px solid var(--a11y-color-accent);
    outline-offset: 2px;
    box-shadow: 0 0 0 5px var(--a11y-color-paper);
}

/* Profile switch: track and knob, driven by aria-checked on the profile button. */
[data-a11y-widget] .a11y-switch {
    position: relative;
    flex: none;
    width: 40px;
    height: 22px;
    border-radius: 999px;
    background-color: var(--a11y-color-border);
    transition: background-color 0.15s;
}

[data-a11y-widget] .a11y-switch::after {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 16px;
    height: 16px;
    border-radius: 999px;
    background-color: var(--a11y-color-paper);
    box-shadow: 0 1px 2px rgb(0 0 0 / 0.24);
    transition: transform 0.15s;
}

[data-a11y-widget] [aria-checked="true"] .a11y-switch {
    background-color: var(--a11y-color-accent);
}

[data-a11y-widget] [aria-checked="true"] .a11y-switch::after {
    transform: translateX(18px);
}
