/* ============================================================
   Arcade Accessibility — Toolbar & Feature Styles
   WCAG 2.1 AA/AAA compliant
   ============================================================ */

:root {
    --aacc-toolbar-color: #1565c0;
    --aacc-icon-color: #ffffff;
    --aacc-panel-bg: #ffffff;
    --aacc-panel-text: #1a1a1a;
    --aacc-panel-border: #e0e0e0;
    --aacc-panel-width: 360px;
    --aacc-btn-radius: 8px;
    --aacc-focus-ring: 0 0 0 3px rgba(21, 101, 192, 0.5);
    --aacc-fs-scale: 1;
    --aacc-lh-add: 0;
    --aacc-ls: 0em;
    --aacc-ws: 0em;
}

/* ───── skip link ───── */
.aacc-skip-link {
    position: absolute;
    top: -100px;
    left: 6px;
    z-index: 2147483647;
    background: var(--aacc-toolbar-color);
    color: var(--aacc-icon-color);
    padding: 12px 24px;
    font-size: 16px;
    font-weight: 600;
    text-decoration: none;
    border-radius: 0 0 6px 6px;
    transition: top 0.15s ease;
}

.aacc-skip-link:focus {
    top: 0;
    outline: 3px solid var(--aacc-toolbar-color);
    outline-offset: 2px;
}

/* ───── trigger button ───── */
/* keep trigger visible when panel is open — hiding it trapped users who couldn't close the panel */
.aacc-open #aacc-trigger {
    opacity: 0.85;
}

/* isolate toolbar from page-wide contrast / filter modes */
#aacc-toolbar-wrap,
#aacc-reading-guide,
.aacc-structure-overlay,
.aacc-skip-link {
    isolation: isolate;
}

#aacc-toolbar-wrap {
    position: fixed !important;
    top: 50%;
    transform: translateY(-50%);
    z-index: 2147483647 !important;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    direction: ltr;
    filter: none !important;
    color: var(--aacc-icon-color);
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    pointer-events: auto !important;
}

#aacc-toolbar-wrap,
#aacc-toolbar-wrap * {
    box-sizing: border-box;
}

#aacc-toolbar-wrap.aacc-right { right: 0; }
#aacc-toolbar-wrap.aacc-left  { left: 0; }

#aacc-trigger {
    display: flex !important;
    align-items: center;
    justify-content: center;
    width: 52px;
    height: 52px;
    border: none;
    border-radius: 50%;
    background: var(--aacc-toolbar-color) !important;
    color: var(--aacc-icon-color) !important;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    position: relative;
    z-index: 2147483647 !important;
    visibility: visible !important;
    opacity: 1 !important;
    pointer-events: auto !important;
}

.aacc-right #aacc-trigger { border-radius: 26px 0 0 26px; }
.aacc-left  #aacc-trigger { border-radius: 0 26px 26px 0; }

#aacc-trigger:hover,
#aacc-trigger:focus-visible {
    transform: scale(1.08);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
}

#aacc-trigger:focus-visible {
    outline: 3px solid var(--aacc-toolbar-color);
    outline-offset: 3px;
}

#aacc-trigger svg {
    width: 28px;
    height: 28px;
}

/* ───── panel ───── */
.aacc-panel {
    position: fixed;
    top: 0;
    width: var(--aacc-panel-width);
    max-width: 92vw;
    height: 100vh;
    height: 100dvh;
    background: var(--aacc-panel-bg);
    color: var(--aacc-panel-text);
    box-shadow: -4px 0 30px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: aaccSlideIn 0.25s ease;
}

.aacc-right .aacc-panel { right: 0; }
.aacc-left  .aacc-panel { left: 0; box-shadow: 4px 0 30px rgba(0, 0, 0, 0.15); }

.aacc-panel[hidden] { display: none; }

@keyframes aaccSlideIn {
    from { opacity: 0; transform: translateX(40px); }
    to   { opacity: 1; transform: translateX(0); }
}

.aacc-left .aacc-panel {
    animation-name: aaccSlideInLeft;
}

@keyframes aaccSlideInLeft {
    from { opacity: 0; transform: translateX(-40px); }
    to   { opacity: 1; transform: translateX(0); }
}

/* hide trigger when panel is open — removed; see .aacc-open rule above */

/* ───── panel header ───── */
.aacc-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: var(--aacc-toolbar-color);
    color: var(--aacc-icon-color);
    flex-shrink: 0;
}

.aacc-panel-title {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
    line-height: 1.3;
}

.aacc-close-btn {
    background: transparent;
    border: 2px solid rgba(255, 255, 255, 0.4);
    color: inherit;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}

.aacc-close-btn:hover,
.aacc-close-btn:focus-visible {
    background: rgba(255, 255, 255, 0.2);
}

.aacc-close-btn:focus-visible {
    outline: 3px solid #fff;
    outline-offset: 2px;
}

/* ───── panel body ───── */
.aacc-panel-body {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 16px 16px 8px;
    scrollbar-width: thin;
}

/* ───── adjusters (font-size, line-height, spacing) ───── */
.aacc-adjuster {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    margin-bottom: 8px;
    border: 1px solid var(--aacc-panel-border);
    border-radius: var(--aacc-btn-radius);
    background: #fafafa;
}

.aacc-adjuster-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 500;
}

.aacc-adjuster-label svg { opacity: 0.7; }

.aacc-adjuster-controls {
    display: flex;
    align-items: center;
    gap: 6px;
}

.aacc-adj-btn {
    width: 32px;
    height: 32px;
    border: 1px solid var(--aacc-panel-border);
    border-radius: 6px;
    background: #fff;
    font-size: 18px;
    font-weight: 700;
    color: var(--aacc-panel-text);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.12s;
}

.aacc-adj-btn:hover { background: #e3f2fd; }
.aacc-adj-btn:focus-visible { box-shadow: var(--aacc-focus-ring); outline: none; }

.aacc-adj-level {
    min-width: 52px;
    text-align: center;
    font-size: 13px;
    font-weight: 600;
    color: #555;
}

/* ───── groups ───── */
.aacc-group {
    margin-bottom: 12px;
}

.aacc-group-title {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #777;
    margin: 12px 0 6px;
    padding: 0;
}

.aacc-group-row {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
}

/* ───── feature buttons ───── */
.aacc-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 12px 8px;
    border: 1px solid var(--aacc-panel-border);
    border-radius: var(--aacc-btn-radius);
    background: #fafafa;
    color: var(--aacc-panel-text);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.12s, border-color 0.12s, color 0.12s;
    text-align: center;
    line-height: 1.3;
    min-height: 64px;
}

.aacc-btn svg {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
}

.aacc-btn-label {
    display: block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.aacc-btn:hover {
    background: #e3f2fd;
    border-color: var(--aacc-toolbar-color);
}

.aacc-btn:focus-visible {
    box-shadow: var(--aacc-focus-ring);
    outline: none;
}

.aacc-btn.aacc-active {
    background: var(--aacc-toolbar-color);
    color: var(--aacc-icon-color);
    border-color: var(--aacc-toolbar-color);
}

.aacc-btn[aria-pressed="true"] {
    background: var(--aacc-toolbar-color);
    color: var(--aacc-icon-color);
    border-color: var(--aacc-toolbar-color);
}

/* ───── panel footer ───── */
.aacc-panel-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--aacc-panel-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    flex-shrink: 0;
}

.aacc-reset-btn {
    flex-direction: row;
    min-height: 0;
    padding: 8px 14px;
    font-size: 13px;
    font-weight: 600;
    gap: 6px;
}

.aacc-statement-link {
    font-size: 13px;
    color: var(--aacc-toolbar-color);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.aacc-statement-link:hover { text-decoration-thickness: 2px; }

/* ============================================================
   FEATURE STYLES — applied via html classes
   ============================================================ */

/* ── font size ── */
html.aacc-font-size body {
    font-size: calc(1em * var(--aacc-fs-scale)) !important;
}

html.aacc-font-size body * {
    font-size: inherit;
}

html.aacc-font-size h1 { font-size: calc(2em * var(--aacc-fs-scale)) !important; }
html.aacc-font-size h2 { font-size: calc(1.5em * var(--aacc-fs-scale)) !important; }
html.aacc-font-size h3 { font-size: calc(1.25em * var(--aacc-fs-scale)) !important; }
html.aacc-font-size h4 { font-size: calc(1.1em * var(--aacc-fs-scale)) !important; }

/* ── line height ── */
html.aacc-line-height body,
html.aacc-line-height body * {
    line-height: calc(1.6 + var(--aacc-lh-add)) !important;
}

/* ── text spacing ── */
html.aacc-text-spacing body,
html.aacc-text-spacing body * {
    letter-spacing: var(--aacc-ls) !important;
    word-spacing: var(--aacc-ws) !important;
}

/* ── dyslexia font ── */
@font-face {
    font-family: 'OpenDyslexic';
    src: url('https://cdn.jsdelivr.net/npm/open-dyslexic@1.0.3/woff/OpenDyslexic-Regular.woff') format('woff');
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'OpenDyslexic';
    src: url('https://cdn.jsdelivr.net/npm/open-dyslexic@1.0.3/woff/OpenDyslexic-Bold.woff') format('woff');
    font-weight: 700;
    font-style: normal;
    font-display: swap;
}

html.aacc-dyslexia-font body,
html.aacc-dyslexia-font body * {
    font-family: 'OpenDyslexic', 'Comic Sans MS', sans-serif !important;
}

/* ── high contrast ── */
html.aacc-high-contrast body {
    background: #000 !important;
    color: #fff !important;
}

html.aacc-high-contrast body *:not(#aacc-toolbar-wrap):not(#aacc-toolbar-wrap *):not(#aacc-reading-guide):not(.aacc-structure-overlay):not(.aacc-structure-overlay *):not(.aacc-skip-link) {
    color: #fff !important;
    background-color: #000 !important;
    border-color: #fff !important;
}

html.aacc-high-contrast body a,
html.aacc-high-contrast body a * {
    color: #ff0 !important;
}

html.aacc-high-contrast img {
    background-color: transparent !important;
}

html.aacc-high-contrast #aacc-toolbar-wrap,
html.aacc-high-contrast #aacc-toolbar-wrap * {
    color: var(--aacc-icon-color) !important;
    background-color: transparent !important;
    border-color: rgba(255, 255, 255, 0.35) !important;
}

html.aacc-high-contrast #aacc-trigger {
    background: var(--aacc-toolbar-color) !important;
    color: var(--aacc-icon-color) !important;
}

html.aacc-high-contrast .aacc-panel {
    background: #111 !important;
    color: #fff !important;
}

/* ── dark contrast ── */
html.aacc-dark-contrast body {
    background: #1a1a2e !important;
    color: #eee !important;
}

html.aacc-dark-contrast body *:not(#aacc-toolbar-wrap):not(#aacc-toolbar-wrap *):not(#aacc-reading-guide):not(.aacc-structure-overlay):not(.aacc-structure-overlay *):not(.aacc-skip-link) {
    color: #eee !important;
    background-color: #1a1a2e !important;
    border-color: #444 !important;
}

html.aacc-dark-contrast body a,
html.aacc-dark-contrast body a * {
    color: #82b1ff !important;
}

html.aacc-dark-contrast img,
html.aacc-dark-contrast video {
    background-color: transparent !important;
}

html.aacc-dark-contrast #aacc-toolbar-wrap,
html.aacc-dark-contrast #aacc-toolbar-wrap * {
    color: var(--aacc-icon-color) !important;
    background-color: transparent !important;
    border-color: rgba(255, 255, 255, 0.25) !important;
}

html.aacc-dark-contrast #aacc-trigger {
    background: var(--aacc-toolbar-color) !important;
    color: var(--aacc-icon-color) !important;
}

html.aacc-dark-contrast .aacc-panel {
    background: #1a1a2e !important;
    color: #eee !important;
}

/* ── light contrast ── */
html.aacc-light-contrast body {
    background: #fefefe !important;
    color: #111 !important;
}

html.aacc-light-contrast body *:not(#aacc-toolbar-wrap):not(#aacc-toolbar-wrap *):not(#aacc-reading-guide):not(.aacc-structure-overlay):not(.aacc-structure-overlay *):not(.aacc-skip-link) {
    color: #111 !important;
    background-color: #fefefe !important;
    border-color: #999 !important;
}

html.aacc-light-contrast body a,
html.aacc-light-contrast body a * {
    color: #0d47a1 !important;
}

html.aacc-light-contrast img,
html.aacc-light-contrast video {
    background-color: transparent !important;
}

html.aacc-light-contrast #aacc-toolbar-wrap,
html.aacc-light-contrast #aacc-toolbar-wrap * {
    color: var(--aacc-icon-color) !important;
    background-color: transparent !important;
    border-color: rgba(0, 0, 0, 0.2) !important;
}

html.aacc-light-contrast #aacc-trigger {
    background: var(--aacc-toolbar-color) !important;
    color: var(--aacc-icon-color) !important;
}

html.aacc-light-contrast .aacc-panel {
    background: #fff !important;
    color: #111 !important;
}

/* Filters apply to page content only (body). Toolbar lives on <html> so fixed positioning is not broken. */
html.aacc-invert-colors body {
    filter: invert(1) hue-rotate(180deg);
}

html.aacc-invert-colors body img,
html.aacc-invert-colors body video,
html.aacc-invert-colors body picture,
html.aacc-invert-colors body svg:not([aria-hidden]) {
    filter: invert(1) hue-rotate(180deg);
}

html.aacc-monochrome body      { filter: grayscale(1); }
html.aacc-low-saturation body  { filter: saturate(0.4); }
html.aacc-high-saturation body { filter: saturate(2); }

html.aacc-invert-colors #aacc-toolbar-wrap,
html.aacc-monochrome #aacc-toolbar-wrap,
html.aacc-low-saturation #aacc-toolbar-wrap,
html.aacc-high-saturation #aacc-toolbar-wrap,
html.aacc-invert-colors #aacc-reading-guide,
html.aacc-monochrome #aacc-reading-guide,
html.aacc-low-saturation #aacc-reading-guide,
html.aacc-high-saturation #aacc-reading-guide,
html.aacc-invert-colors .aacc-structure-overlay,
html.aacc-monochrome .aacc-structure-overlay,
html.aacc-low-saturation .aacc-structure-overlay,
html.aacc-high-saturation .aacc-structure-overlay {
    filter: none !important;
}

/* ── highlight links ── */
html.aacc-link-highlight a {
    outline: 2px solid #ff6f00 !important;
    outline-offset: 2px;
    text-decoration: underline !important;
    text-decoration-color: #ff6f00 !important;
    text-underline-offset: 3px;
}

html.aacc-link-highlight #aacc-toolbar-wrap a {
    outline: none !important;
    text-decoration-color: inherit !important;
}

/* ── big cursor ── */
html.aacc-big-cursor,
html.aacc-big-cursor * {
    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='M8 4l28 22.4-11.6 1 6.6 14.6-4.4 2-6.4-14.8L12 37V4z' fill='%23000' stroke='%23fff' stroke-width='2'/%3E%3C/svg%3E") 4 4, auto !important;
}

html.aacc-big-cursor #aacc-toolbar-wrap,
html.aacc-big-cursor #aacc-toolbar-wrap * {
    cursor: auto !important;
}

/* ── reading guide ── */
#aacc-reading-guide {
    position: fixed;
    left: 0;
    width: 100%;
    height: 28px;
    background: rgba(21, 101, 192, 0.12);
    border-top: 2px solid rgba(21, 101, 192, 0.45);
    border-bottom: 2px solid rgba(21, 101, 192, 0.45);
    pointer-events: none;
    z-index: 2147483639;
    transition: top 0.05s linear;
}

#aacc-reading-guide[hidden] { display: none; }

/* ── focus highlight ── */
html.aacc-focus-highlight *:focus,
html.aacc-focus-highlight *:focus-visible {
    outline: 3px solid #ff6f00 !important;
    outline-offset: 3px !important;
    box-shadow: 0 0 0 6px rgba(255, 111, 0, 0.25) !important;
}

/* keyboard user — show focus ring only for keyboard */
html.aacc-keyboard-user *:focus-visible {
    outline: 3px solid var(--aacc-toolbar-color);
    outline-offset: 3px;
}

/* ── stop animations ── */
html.aacc-stop-animations *,
html.aacc-stop-animations *::before,
html.aacc-stop-animations *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
}

/* ── image alt overlay ── */
html.aacc-image-alt img {
    outline: 3px solid transparent;
    outline-offset: 2px;
    position: relative;
}

html.aacc-image-alt img.aacc-img-has-alt {
    outline-color: #2e7d32;
}

html.aacc-image-alt img.aacc-img-empty-alt {
    outline-color: #f57f17;
}

html.aacc-image-alt img.aacc-img-no-alt {
    outline-color: #c62828;
}

html.aacc-image-alt img::after {
    content: attr(data-aacc-alt);
    position: absolute;
    bottom: 100%;
    left: 0;
    background: #333;
    color: #fff;
    padding: 2px 8px;
    font-size: 11px;
    border-radius: 3px;
    white-space: nowrap;
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    pointer-events: none;
    z-index: 100;
}

/* ── tooltips ── */
html.aacc-tooltips [title] {
    position: relative;
    text-decoration-style: dotted;
    text-decoration-line: underline;
    text-underline-offset: 3px;
    cursor: help;
}

/* ── page structure overlay ── */
.aacc-structure-overlay {
    position: fixed;
    inset: 0;
    z-index: 2147483641;
    background: rgba(0, 0, 0, 0.65);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.aacc-structure-overlay[hidden] { display: none; }

.aacc-structure-inner {
    background: #fff;
    color: #1a1a1a;
    border-radius: 12px;
    padding: 24px;
    max-width: 600px;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.aacc-structure-inner h3 {
    margin: 0 0 16px;
    font-size: 18px;
    font-weight: 700;
}

.aacc-structure-inner ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.aacc-structure-inner li {
    padding: 6px 0;
    font-size: 14px;
    line-height: 1.4;
    border-bottom: 1px solid #eee;
}

.aacc-structure-inner li strong {
    color: var(--aacc-toolbar-color);
    font-family: monospace;
    font-size: 12px;
}

.aacc-struct-close {
    position: absolute;
    top: 12px;
    right: 12px;
    background: transparent;
    border: 1px solid #ccc;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.aacc-struct-close:hover { background: #f5f5f5; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 480px) {
    .aacc-panel {
        width: 100vw;
        max-width: 100vw;
    }

    .aacc-group-row {
        grid-template-columns: 1fr 1fr;
    }
}

/* ============================================================
   RTL SUPPORT
   ============================================================ */
html[dir="rtl"] #aacc-toolbar-wrap.aacc-right { right: auto; left: 0; }
html[dir="rtl"] #aacc-toolbar-wrap.aacc-left  { left: auto; right: 0; }

html[dir="rtl"] .aacc-right #aacc-trigger { border-radius: 0 26px 26px 0; }
html[dir="rtl"] .aacc-left  #aacc-trigger { border-radius: 26px 0 0 26px; }

html[dir="rtl"] .aacc-right .aacc-panel { right: auto; left: 0; }
html[dir="rtl"] .aacc-left  .aacc-panel { left: auto; right: 0; }

/* ============================================================
   PRINT — hide toolbar
   ============================================================ */
@media print {
    #aacc-toolbar-wrap,
    #aacc-reading-guide,
    .aacc-structure-overlay,
    .aacc-skip-link {
        display: none !important;
    }
}

/* ============================================================
   PREFERS-REDUCED-MOTION — respect OS setting
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
    .aacc-panel { animation: none; }
    #aacc-trigger { transition: none; }
}
