/* Accessibility toolbar (js/a11y.js): the panel, and every adjustment it
   makes to the page. Adjustments never touch the panel itself
   (.a11y-ui), so it stays usable whatever is switched on. */

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

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

/* --- adjustments ---------------------------------------------------------- */

html.a11y-zoom body > header,
html.a11y-zoom body > main,
html.a11y-zoom body > footer {
    zoom: var(--a11y-zoom);
}

html.a11y-line-height body :not(.a11y-ui):not(.a11y-ui *) {
    line-height: var(--a11y-line-height) !important;
}

html.a11y-letter-spacing body :not(.a11y-ui):not(.a11y-ui *) {
    letter-spacing: var(--a11y-letter-spacing) !important;
    word-spacing: calc(var(--a11y-letter-spacing) * 2) !important;
}

html.a11y-readable body :not(.a11y-ui):not(.a11y-ui *):not(i):not([class*="fa-"]) {
    font-family: Arial, Helvetica, 'Noto Sans TC', 'Noto Sans SC', 'Microsoft JhengHei', sans-serif !important;
}

html.a11y-dyslexia body :not(.a11y-ui):not(.a11y-ui *):not(i):not([class*="fa-"]) {
    font-family: 'OpenDyslexic', 'Noto Sans TC', 'Noto Sans SC', sans-serif !important;
}

html.a11y-titles body :is(h1, h2, h3, h4, h5, h6):not(.a11y-ui *) {
    outline: 3px solid #2A78A8 !important;
    outline-offset: 4px;
}

html.a11y-links body a:not(.a11y-ui *) {
    text-decoration: underline !important;
    text-underline-offset: 3px;
    outline: 2px solid #E8A33D !important;
    outline-offset: 2px;
}

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

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

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

/* filters (high contrast, monochrome, saturation) go on the page's three
   parts rather than <html>, so fixed buttons keep working */
html.a11y-filter body > header,
html.a11y-filter body > main,
html.a11y-filter body > footer > .container,
html.a11y-filter .night-sky__canvas {
    filter: var(--a11y-filter);
}

/* dark and light contrast repaint everything in two colours */
html[data-a11y-contrast="dark"] body,
html[data-a11y-contrast="dark"] body :not(.a11y-ui):not(.a11y-ui *):not(img):not(video):not(canvas):not(svg):not(svg *) {
    background: #111 !important;
    color: #f5f5f5 !important;
    border-color: #666 !important;
    text-shadow: none !important;
    box-shadow: none !important;
}

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

html[data-a11y-contrast="light"] body,
html[data-a11y-contrast="light"] body :not(.a11y-ui):not(.a11y-ui *):not(img):not(video):not(canvas):not(svg):not(svg *) {
    background: #fff !important;
    color: #000 !important;
    border-color: #000 !important;
    text-shadow: none !important;
    box-shadow: none !important;
}

html[data-a11y-contrast="light"] body a:not(.a11y-ui *),
html[data-a11y-contrast="light"] body a:not(.a11y-ui *) * {
    color: #0b4fa8 !important;
}

html[data-a11y-contrast="dark"] .scene-canvas,
html[data-a11y-contrast="light"] .scene-canvas,
html[data-a11y-contrast="light"] .night-sky__canvas {
    display: none;
}

html.a11y-text-color body :is(p, li, span, a, label, small, td, th, dd, dt, blockquote, strong, em, figcaption, output):not(.a11y-ui *) {
    color: var(--a11y-text-color) !important;
}

html.a11y-title-color body :is(h1, h2, h3, h4, h5, h6):not(.a11y-ui *),
html.a11y-title-color body :is(h1, h2, h3, h4, h5, h6):not(.a11y-ui *) * {
    color: var(--a11y-title-color) !important;
}

html.a11y-bg-color body,
html.a11y-bg-color body :is(header, main, section, footer, div, article, aside, nav, ul, li, form):not(.a11y-ui):not(.a11y-ui *) {
    background: var(--a11y-bg-color) !important;
}

html.a11y-bg-color .scene-canvas {
    display: none;
}

/* motion */
html.a11y-still *,
html.a11y-still *::before,
html.a11y-still *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
}

html.a11y-no-images body :is(img, picture, video, .image-plate, .scene-canvas, .night-sky__canvas):not(.a11y-ui *) {
    visibility: hidden !important;
}

html.a11y-hover body :is(a, button, input, select, textarea, p, li, h1, h2, h3, h4, h5, h6, img, label):not(.a11y-ui *):hover {
    outline: 3px dashed #2A78A8 !important;
    outline-offset: 2px;
}

html.a11y-focus body *:focus {
    outline: 4px solid #F2C94C !important;
    outline-offset: 2px !important;
    box-shadow: 0 0 0 8px #1f2d27 !important;
}

html[data-a11y-cursor="dark"],
html[data-a11y-cursor="dark"] * {
    cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='48' height='48' viewBox='0 0 48 48'%3E%3Cpath d='M6 3l30 27H22l8 15-6 3-8-15-10 9z' fill='%23111' stroke='%23fff' stroke-width='2.5' stroke-linejoin='round'/%3E%3C/svg%3E") 6 3, auto !important;
}

html[data-a11y-cursor="light"],
html[data-a11y-cursor="light"] * {
    cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='48' height='48' viewBox='0 0 48 48'%3E%3Cpath d='M6 3l30 27H22l8 15-6 3-8-15-10 9z' fill='%23fff' stroke='%23111' stroke-width='2.5' stroke-linejoin='round'/%3E%3C/svg%3E") 6 3, auto !important;
}

html.a11y-speech body :is(p, li, h1, h2, h3, h4, h5, h6, td, dd, dt, blockquote, figcaption, img, label):not(.a11y-ui *):hover {
    outline: 2px dotted #2A78A8;
    outline-offset: 2px;
    cursor: pointer;
}

.a11y-speaking {
    outline: 3px solid #F2C94C !important;
    outline-offset: 3px;
    background-color: rgba(242, 201, 76, 0.18) !important;
}

.a11y-bionic b {
    font-weight: 700;
}

/* reading guide, mask and magnifier follow the pointer */
.a11y-guide {
    position: fixed;
    left: 0;
    right: 0;
    z-index: 2147483000;
    height: 10px;
    border-top: 3px solid #1f2d27;
    border-bottom: 3px solid #F2C94C;
    background-color: rgba(242, 201, 76, 0.35);
    pointer-events: none;
}

.a11y-mask {
    position: fixed;
    left: 0;
    right: 0;
    z-index: 2147483000;
    background-color: rgba(0, 0, 0, 0.6);
    pointer-events: none;
}

.a11y-mask--top {
    top: 0;
}

.a11y-mask--bottom {
    bottom: 0;
}

.a11y-magnifier {
    position: fixed;
    z-index: 2147483001;
    max-width: min(480px, 90vw);
    padding: 12px 16px;
    border: 2px solid #F2C94C;
    border-radius: 10px;
    background-color: #1f2d27;
    color: #fff;
    font-size: 1.6rem;
    line-height: 1.5;
    pointer-events: none;
}

[hidden].a11y-guide,
[hidden].a11y-mask,
[hidden].a11y-magnifier,
.a11y-ui [hidden],
.a11y-ui[hidden] {
    display: none !important;
}

/* --- the toolbar ----------------------------------------------------------- */

.a11y-ui {
    --a11y-ink: #1f2d27;
    --a11y-muted: #4a5a52;
    --a11y-line: #d5e3dc;
    --a11y-soft: #f2f8f5;
    --a11y-accent: #1A7F4B;
    --a11y-accent-ink: #ffffff;
    font-family: 'Noto Sans TC', 'Noto Sans SC', 'Microsoft JhengHei', Arial, sans-serif;
    font-size: 16px;
    line-height: 1.45;
    letter-spacing: normal;
    text-align: left;
    color: var(--a11y-ink);
}

.a11y-ui--hidden .a11y-launcher,
.a11y-ui--hidden .a11y-panel {
    display: none !important;
}

.a11y-launcher {
    position: fixed;
    left: 24px;
    bottom: 24px;
    z-index: 1001;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    border: 3px solid #fff;
    border-radius: 50%;
    background-color: #2A78A8;
    color: #fff;
    font-size: 1.7rem;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
    cursor: pointer;
}

.a11y-launcher:hover {
    background-color: #22668F;
}

.a11y-launcher--active::after {
    content: '';
    position: absolute;
    top: -2px;
    right: -2px;
    width: 16px;
    height: 16px;
    border: 2px solid #fff;
    border-radius: 50%;
    background-color: #F2C94C;
}

.a11y-ui :focus-visible {
    outline: 3px solid #F2C94C;
    outline-offset: 2px;
    box-shadow: 0 0 0 6px #1f2d27;
}

.a11y-panel {
    position: fixed;
    left: 24px;
    bottom: 92px;
    z-index: 1002;
    display: flex;
    flex-direction: column;
    width: min(420px, calc(100vw - 32px));
    max-height: calc(100vh - 116px);
    border-radius: 16px;
    background-color: #fff;
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.3);
    overflow: hidden;
}

.a11y-panel__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px 14px 20px;
    background-color: #2A78A8;
    color: #fff;
}

.a11y-panel__title {
    margin: 0;
    color: #fff;
    font-size: 1.2rem;
    font-weight: 700;
}

.a11y-ui .a11y-panel__title:focus {
    outline: none;
    box-shadow: none;
}

.a11y-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 50%;
    background-color: rgba(255, 255, 255, 0.15);
    color: #fff;
    font-size: 1.2rem;
    cursor: pointer;
}

.a11y-icon-btn:hover {
    background-color: rgba(255, 255, 255, 0.3);
}

.a11y-panel__body {
    flex: 1 1 auto;
    padding: 8px 16px 16px;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.a11y-section {
    padding: 14px 0;
    border-bottom: 1px solid var(--a11y-line);
}

.a11y-section__title {
    margin: 0 0 12px;
    color: var(--a11y-ink);
    font-size: 1rem;
    font-weight: 700;
}

.a11y-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin: 10px 0;
}

.a11y-toggle {
    display: grid;
    grid-template-columns: 22px minmax(0, 1fr);
    align-items: center;
    column-gap: 10px;
    min-height: 48px;
    padding: 10px 12px;
    border: 2px solid var(--a11y-line);
    border-radius: 12px;
    background-color: #fff;
    color: var(--a11y-ink);
    font: inherit;
    font-size: 0.92rem;
    text-align: left;
    cursor: pointer;
}

.a11y-toggle i {
    color: #2A78A8;
    font-size: 1.05rem;
    text-align: center;
}

.a11y-toggle__hint {
    grid-column: 2;
    color: var(--a11y-muted);
    font-size: 0.8rem;
}

.a11y-toggle:hover {
    border-color: #2A78A8;
}

.a11y-toggle[aria-pressed="true"] {
    border-color: var(--a11y-accent);
    background-color: var(--a11y-accent);
    color: var(--a11y-accent-ink);
}

.a11y-toggle[aria-pressed="true"] i,
.a11y-toggle[aria-pressed="true"] .a11y-toggle__hint {
    color: var(--a11y-accent-ink);
}

.a11y-stepper {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 8px;
}

.a11y-stepper__label,
.a11y-choice__label {
    color: var(--a11y-ink);
    font-size: 0.92rem;
    font-weight: 500;
}

.a11y-stepper__controls {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.a11y-stepper__btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border: 2px solid var(--a11y-line);
    border-radius: 10px;
    background-color: #fff;
    color: var(--a11y-ink);
    cursor: pointer;
}

.a11y-stepper__btn:hover {
    border-color: #2A78A8;
}

.a11y-stepper__value {
    min-width: 58px;
    color: var(--a11y-ink);
    font-weight: 700;
    text-align: center;
}

.a11y-choice {
    margin: 10px 0;
}

.a11y-choice__options {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 6px;
}

.a11y-chip {
    min-height: 44px;
    padding: 0 14px;
    border: 2px solid var(--a11y-line);
    border-radius: 999px;
    background-color: #fff;
    color: var(--a11y-ink);
    font: inherit;
    font-size: 0.9rem;
    cursor: pointer;
}

.a11y-chip[aria-pressed="true"] {
    border-color: var(--a11y-accent);
    background-color: var(--a11y-accent);
    color: var(--a11y-accent-ink);
}

.a11y-swatch {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: 2px solid #8a9a92;
    border-radius: 50%;
    background-color: #fff;
    color: var(--a11y-muted);
    cursor: pointer;
}

.a11y-swatch[aria-pressed="true"] {
    box-shadow: 0 0 0 3px #fff, 0 0 0 6px var(--a11y-ink);
}

.a11y-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 10px 0;
}

.a11y-action {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 44px;
    padding: 0 14px;
    border: 2px solid var(--a11y-line);
    border-radius: 10px;
    background-color: #fff;
    color: var(--a11y-ink);
    font: inherit;
    font-size: 0.9rem;
    text-decoration: none;
    cursor: pointer;
}

.a11y-action:hover {
    border-color: #2A78A8;
    color: var(--a11y-ink);
}

.a11y-hint {
    margin: 8px 0 0;
    color: var(--a11y-muted);
    font-size: 0.82rem;
}

.a11y-jump {
    display: block;
    margin-bottom: 6px;
}

.a11y-jump__select {
    display: block;
    width: 100%;
    min-height: 44px;
    margin-top: 6px;
    padding: 0 10px;
    border: 2px solid var(--a11y-line);
    border-radius: 10px;
    background-color: #fff;
    color: var(--a11y-ink);
    font: inherit;
    font-size: 0.92rem;
}

.a11y-status {
    margin: 10px 0 0;
    color: var(--a11y-muted);
    font-size: 0.85rem;
}

.a11y-status:empty {
    display: none;
}

.a11y-panel__foot {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--a11y-line);
    background-color: var(--a11y-soft);
}

/* on-screen keyboard and dictionary link */
.a11y-keyboard {
    position: fixed;
    left: 50%;
    bottom: 12px;
    z-index: 2147483002;
    width: min(640px, calc(100vw - 16px));
    padding: 10px;
    border-radius: 14px;
    background-color: #1f2d27;
    box-shadow: 0 12px 34px rgba(0, 0, 0, 0.35);
    transform: translateX(-50%);
}

.a11y-keyboard__row {
    display: flex;
    gap: 5px;
    margin-bottom: 5px;
}

.a11y-key {
    flex: 1 1 0;
    min-width: 0;
    min-height: 44px;
    border: 0;
    border-radius: 8px;
    background-color: #fff;
    color: #1f2d27;
    font: inherit;
    font-size: 1.05rem;
    cursor: pointer;
}

.a11y-key--wide {
    flex: 4 1 0;
}

.a11y-key:active {
    background-color: #F2C94C;
}

.a11y-lookup {
    position: fixed;
    z-index: 2147483002;
    padding: 8px 14px;
    border-radius: 999px;
    background-color: #1f2d27;
    color: #fff !important;
    font-size: 0.9rem;
    text-decoration: none;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.25);
}

@media (max-width: 768px) {
    .a11y-launcher {
        left: 16px;
        bottom: 16px;
    }

    .a11y-panel {
        left: 8px;
        right: 8px;
        bottom: 84px;
        width: auto;
        max-height: calc(100vh - 100px);
    }
}

@media (max-width: 380px) {
    .a11y-grid {
        grid-template-columns: 1fr;
    }
}

@media (prefers-reduced-motion: reduce) {
    .a11y-launcher,
    .a11y-panel {
        transition: none;
    }
}
