/* ==========================================================================
   FoxBrew — Moduł stylów dostępności (WCAG 2.1 AA / EN 301 549)
   Ten plik odpowiada za:
   1) Stałe fundamenty dostępności (link pomijania nawigacji, klasę .sr-only, wyraźny fokus :focus-visible),
   2) Styl pływającego okna dialogowego z opcjami dostępności (#a11y-panel) oraz przycisków otwierających,
   3) Klasy nakładane na element <html> przez skrypt accessibility.js:
      - .a11y-font-lg / .a11y-font-xl (powiększanie tekstu w całej aplikacji przez rem)
      - .a11y-text-spacing (większe odstępy wierszy, liter i słów wg WCAG 1.4.12)
      - .a11y-high-contrast (tryb wysokiego kontrastu czerń + biel + żółty akcent)
      - .a11y-grayscale (tryb czarno-biały za pomocą nakładki bez psucia position: fixed)
      - .a11y-readable-font (czytelna czcionka bezszeryfowa dla osób z dysleksją)
      - .a11y-highlight-links (stałe podkreślenie i wyraźniejsze obramowanie linków)
      - .a11y-strong-focus (wzmocniona, grubsza ramka fokusu podczas nawigacji klawiaturą)
      - .a11y-reduce-motion (zatrzymanie animacji, płynnych przejść i preloadera)
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. FUNDAMENTY DOSTĘPNOŚCI (zawsze aktywne)
   -------------------------------------------------------------------------- */

/* Ukryty tekst przeznaczony wyłącznie dla czytników ekranu (np. komunikaty aria-live i opisy skrótów).
   Zamiast display: none (którego czytnik nie przeczyta), element ma wymiar 1x1 px poza widokiem. */
.sr-only {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

/* Link pomijania powtarzającego się menu (WCAG 2.4.1 Bypass Blocks).
   Dopiero gdy użytkownik naciśnie klawisz Tab po wejściu na stronę, przycisk płynnie wysuwa się w lewym górnym rogu. */
.skip-link {
    position: fixed;
    top: -120px;
    left: 16px;
    z-index: 100001;
    padding: 12px 18px;
    border-radius: 12px;
    background: #111827;
    color: #ffffff;
    border: 2px solid #ffd400;
    font-size: 0.95rem;
    font-weight: 800;
    text-decoration: none;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
    transition: top 0.16s ease;
}

.skip-link:focus,
.skip-link:focus-visible {
    top: 14px;
    outline: 3px solid #ffd400;
    outline-offset: 3px;
}

/* Gdy użytkownik przeskoczy linkiem do <main id="main-content" tabindex="-1">,
   nie rysujemy wielkiej ramki dokoła całego kontenera strony przy kliknięciu myszką */
main#main-content:focus {
    outline: none;
}

/* Globalna, wyraźna ramka fokusu podczas poruszania się klawiaturą (WCAG 2.4.7 Focus Visible).
   Przeglądarka pokazuje :focus-visible tylko przy użyciu klawiatury (Tab/Shift+Tab), a nie po kliknięciu myszką. */
:is(a, button, summary, input, select, textarea, [tabindex], [role="button"], [role="tab"], [role="menuitem"]):focus-visible {
    outline: 3px solid var(--accent-orange) !important;
    outline-offset: 2px !important;
}

/* Wyjątek: dla dużego pola edytora kodu dajemy lekko dopasowany obrys na etapie .code-stage,
   żeby ramka fokusu nie chowała się pod krawędzią kontenera overflow: hidden */
.code-stage:has(#code-editor:focus-visible) {
    box-shadow: inset 0 0 0 2px var(--accent-orange);
}

#code-editor:focus-visible {
    outline: none !important;
}

/* Przyciski poziomów na izometrycznej mapie w tasks.css miały outline: none — przywracamy im wyraźny ring klawiatury */
.iso-level-btn:focus-visible {
    outline: 3px solid var(--accent-orange) !important;
    outline-offset: 6px !important;
    border-radius: 20px;
}

/* Baner wskazówki w edytorze pokazujący, że Escape odblokował wyjście klawiszem Tab */
.editor-kbd-status {
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--accent-orange);
    margin-left: 10px;
}

/* --------------------------------------------------------------------------
   2. PRZYCISK DOSTĘPNOŚCI W PASKU NAWIGACJI I OKNO OPCJI (#a11y-panel)
   -------------------------------------------------------------------------- */

.a11y-nav-btn {
    background: rgba(255, 255, 255, 0.45);
    border: 1px solid var(--glass-border);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.86rem;
    font-weight: 700;
    padding: 8px 11px;
    border-radius: 12px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
    transition: background-color 0.22s ease, border-color 0.22s ease, transform 0.15s ease;
}

.a11y-nav-btn:hover {
    background-color: var(--subtle-pill-bg);
}

.a11y-nav-btn svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

body.dark-mode .a11y-nav-btn {
    background: rgba(255, 255, 255, 0.04);
    border-color: var(--glass-border);
}

body.dark-mode .a11y-nav-btn:hover {
    background: rgba(255, 255, 255, 0.14);
    border-color: rgba(255, 255, 255, 0.3);
}

/* W zwiniętym pasku na desktopie zostawiamy samą ikonkę i etykietę w stylu smukłych przycisków */
.navbar.is-compact .a11y-nav-btn {
    background: transparent;
    border-color: transparent;
    padding: 6px 10px;
    border-radius: 8px;
}

/* Jeśli chociaż jedna opcja w panelu dostępności jest włączona, pokazujemy małą kropkę przy ikonie */
.a11y-nav-btn.has-active-a11y {
    border-color: color-mix(in srgb, var(--accent-orange) 55%, var(--glass-border));
}

.a11y-nav-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--accent-orange);
    display: none;
}

.a11y-nav-btn.has-active-a11y .a11y-nav-dot {
    display: inline-block;
}

@media (max-width: 980px) {
    .a11y-nav-label {
        display: none;
    }
}

/* Na telefonach <= 820px ukryty zostaje górny przycisk dostępności, bo dostępność jest pod kciukiem w menu "Więcej" */
@media (max-width: 820px) {
    .a11y-nav-btn {
        display: none;
    }
}

/* Ciemne tło pod oknem ułatwień dostępu */
.a11y-backdrop {
    position: fixed;
    inset: 0;
    z-index: 12000;
    background: rgba(15, 23, 42, 0.56);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
}

.a11y-backdrop[hidden] {
    display: none !important;
}

/* Główne okno dialogowe panelu ułatwień dostępu (modal po prawej / na środku ekranu) */
.a11y-panel {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 12010;
    width: min(520px, calc(100vw - 24px));
    max-height: min(86dvh, 720px);
    display: flex;
    flex-direction: column;
    border-radius: 24px;
    background: #fffcf7;
    color: var(--text-primary);
    border: 1px solid var(--glass-border);
    box-shadow: 0 28px 70px rgba(0, 0, 0, 0.34);
    overflow: hidden;
}

.a11y-panel[hidden] {
    display: none !important;
}

body.dark-mode .a11y-panel {
    background: #0f172a;
    border-color: rgba(255, 255, 255, 0.16);
    box-shadow: 0 30px 75px rgba(0, 0, 0, 0.8);
}

.a11y-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 18px 22px;
    border-bottom: 1px solid var(--hairline-border);
}

.a11y-panel-title-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
}

.a11y-panel-title-wrap h2 {
    font-size: 1.15rem;
    font-weight: 800;
    margin: 0;
    color: var(--text-primary);
}

.a11y-panel-badge {
    font-size: 0.72rem;
    font-weight: 800;
    padding: 3px 8px;
    border-radius: 999px;
    background: color-mix(in srgb, var(--accent-orange) 15%, transparent);
    color: var(--accent-orange);
    border: 1px solid color-mix(in srgb, var(--accent-orange) 35%, transparent);
}

.a11y-close-btn {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    border: 1px solid var(--hairline-border);
    background: var(--subtle-pill-bg);
    color: var(--text-primary);
    font-size: 1.1rem;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.a11y-panel-body {
    padding: 18px 22px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.a11y-intro {
    font-size: 0.9rem;
    line-height: 1.5;
    color: var(--text-secondary);
    margin: 0;
}

.a11y-section-label {
    font-size: 0.8rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin: 0 0 8px;
}

/* Segmented control do wyboru wielkości tekstu (100% / 112.5% / 125%) */
.a11y-size-group {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
}

.a11y-size-btn {
    padding: 10px 8px;
    border-radius: 12px;
    border: 1px solid var(--hairline-border);
    background: var(--subtle-pill-bg);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.88rem;
    font-weight: 700;
    cursor: pointer;
    text-align: center;
    transition: background-color 0.16s ease, border-color 0.16s ease;
}

.a11y-size-btn[aria-pressed="true"] {
    background: var(--accent-orange);
    color: #ffffff;
    border-color: var(--accent-orange);
}

body.dark-mode .a11y-size-btn[aria-pressed="true"] {
    color: #0b0f19;
}

/* Siatka przełączników opcji dostępności */
.a11y-options-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

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

.a11y-option-btn {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 12px 13px;
    border-radius: 14px;
    border: 1px solid var(--hairline-border);
    background: var(--subtle-pill-bg);
    color: var(--text-primary);
    font-family: inherit;
    text-align: left;
    cursor: pointer;
    transition: border-color 0.16s ease, background-color 0.16s ease;
}

.a11y-option-copy {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.a11y-option-copy strong {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text-primary);
}

.a11y-option-copy small {
    font-size: 0.78rem;
    color: var(--text-secondary);
    line-height: 1.3;
}

.a11y-switch-pill {
    flex-shrink: 0;
    font-size: 0.72rem;
    font-weight: 800;
    padding: 4px 8px;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.08);
    color: var(--text-secondary);
}

body.dark-mode .a11y-switch-pill {
    background: rgba(255, 255, 255, 0.1);
}

.a11y-option-btn[aria-pressed="true"] {
    border-color: var(--accent-orange);
    background: color-mix(in srgb, var(--accent-orange) 12%, transparent);
}

.a11y-option-btn[aria-pressed="true"] .a11y-switch-pill {
    background: var(--accent-orange);
    color: #ffffff;
}

body.dark-mode .a11y-option-btn[aria-pressed="true"] .a11y-switch-pill {
    color: #0b0f19;
}

.a11y-panel-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
    padding: 14px 22px 18px;
    border-top: 1px solid var(--hairline-border);
}

.a11y-footer-link {
    font-size: 0.86rem;
    font-weight: 700;
    color: var(--accent-orange);
    text-decoration: underline;
    text-underline-offset: 3px;
}

.a11y-reset-btn {
    padding: 9px 14px;
    border-radius: 10px;
    border: 1px solid var(--hairline-border);
    background: var(--subtle-pill-bg);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
}

/* --------------------------------------------------------------------------
   3. KLASY DOSTĘPNOŚCI NAKŁADANE NA ELEMENT <html> PRZEZ JS
   -------------------------------------------------------------------------- */

/* [A] Rozmiar tekstu: zmieniamy bazowe 1rem na <html>, dzięki czemu wszystkie elementy w rem płynnie rosną */
html.a11y-font-lg {
    font-size: 112.5%; /* 18px zamiast domyślnych 16px */
}

html.a11y-font-xl {
    font-size: 125%; /* 20px zamiast domyślnych 16px */
}

/* [B] Zwiększone odstępy tekstu i wierszy (WCAG 1.4.12 Text Spacing).
   Celowo pomijamy warstwy edytora kodu (.code-stage *), ponieważ w nakładanym edytorze
   <pre> i <textarea> muszą zachować identyczny kerning i zerowy letter-spacing, żeby kursor nie uciekał. */
html.a11y-text-spacing body :not(.code-stage):not(.code-stage *) {
    line-height: 1.65 !important;
    letter-spacing: 0.04em !important;
    word-spacing: 0.12em !important;
}

html.a11y-text-spacing p,
html.a11y-text-spacing li {
    margin-bottom: 0.65em;
}

/* [C] Czytelna czcionka bezszeryfowa (przyjazna dysleksji) — z wykluczeniem bloków kodu monospace */
html.a11y-readable-font body,
html.a11y-readable-font input,
html.a11y-readable-font select,
html.a11y-readable-font button {
    font-family: Verdana, Tahoma, 'Segoe UI', Arial, sans-serif !important;
}

html.a11y-readable-font body :not(code):not(pre):not(kbd):not(textarea#code-editor) {
    font-style: normal !important;
}

/* [D] Wyraźne podkreślenie wszystkich linków oraz przycisków */
html.a11y-highlight-links a {
    text-decoration: underline !important;
    text-decoration-thickness: 2px !important;
    text-underline-offset: 4px !important;
}

html.a11y-highlight-links button,
html.a11y-highlight-links .btn-primary,
html.a11y-highlight-links .btn-secondary {
    border: 2px solid currentColor !important;
}

/* [E] Wzmocniony fokus klawiatury (gruba kontrastowa ramka z wyraźnym odstępem) */
html.a11y-strong-focus :is(a, button, summary, input, select, textarea, [tabindex], [role="button"], [role="tab"], [role="menuitem"]):focus-visible {
    outline: 4px solid #ffd400 !important;
    outline-offset: 3px !important;
    box-shadow: 0 0 0 6px #000000 !important;
}

/* [F] Tryb monochromatyczny (skala szarości).
   Zamiast filter na body (który w przeglądarkach psuje position: fixed dla menu i docka),
   używamy warstwy nakładki ::after z backdrop-filter i pointer-events: none. */
html.a11y-grayscale::after {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 2147483000;
    pointer-events: none;
    backdrop-filter: grayscale(100%);
    -webkit-backdrop-filter: grayscale(100%);
}

/* [G] Zatrzymanie animacji i płynnych przejść (ręczny tryb Reduced Motion + systemowe prefers-reduced-motion) */
html.a11y-reduce-motion {
    scroll-behavior: auto !important;
}

html.a11y-reduce-motion *,
html.a11y-reduce-motion *::before,
html.a11y-reduce-motion *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
}

html.a11y-reduce-motion #preloader {
    display: none !important;
}

/* [H] Tryb wysokiego kontrastu (WCAG AAA dla tekstu: czarne tło #000, biały tekst #fff, żółty akcent #ffd400).
   Wyłączamy przezroczyste szkło (backdrop-filter), żeby tło nigdy nie obniżało czytelności napisów. */
html.a11y-high-contrast,
html.a11y-high-contrast body,
html.a11y-high-contrast body.dark-mode {
    --bg-color: #000000 !important;
    --text-primary: #ffffff !important;
    --text-secondary: #f1f5f9 !important;
    --accent-orange: #ffd400 !important;
    --accent-dark: #ffd400 !important;
    --glass-bg: #000000 !important;
    --glass-bg-compact: #000000 !important;
    --glass-bg-compact-hover: #111111 !important;
    --glass-border: #ffffff !important;
    --hairline-border: #ffffff !important;
    --subtle-pill-bg: #111111 !important;
    background: #000000 !important;
    color: #ffffff !important;
}

html.a11y-high-contrast body :is(
    .glass-panel,
    .glass-card,
    .feature-card,
    .faq-item,
    .contact-info,
    .contact-form,
    .main-footer,
    .info-hero-card,
    .info-section-card,
    .about-tile,
    .auth-card,
    .auth-perk,
    .mascot-bubble,
    .dash-panel,
    .stat-card,
    .admin-kpi-card,
    .ide-window,
    .task-panel,
    .task-locked-wall,
    .fuksio-chat-window,
    .mobile-dock,
    .mobile-sheet,
    .a11y-panel,
    .level-inspector-card,
    .map-hud-bar
) {
    background: #000000 !important;
    color: #ffffff !important;
    border: 2px solid #ffffff !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    box-shadow: none !important;
}

/* Linki tekstowe świecą na żółto (#ffd400), z wyjątkiem przycisków z własnym tłem */
html.a11y-high-contrast a:not(.btn-primary):not(.mobile-sheet-auth-btn):not(.hud-pill-link):not(.admin-tab):not(.btn-mini):not(.mobile-dock-item):not(.auth-mode-tab) {
    color: #ffd400 !important;
}

/* Przyciski i pigułki z wypełnieniem głównym (w tym aktywne zakładki Logowanie/Rejestracja):
   czarny tekst (#000000) na jaskrawym żółtym tle (#ffd400) = kontrast ~14.9:1 */
html.a11y-high-contrast body :is(
    .btn-primary,
    .navbar.is-compact .btn-primary,
    .mobile-sheet-auth-btn.primary,
    .auth-mode-tab.is-active,
    .hud-pill-link,
    .map-chip.is-active,
    .admin-tab.is-active,
    .btn-mini.is-active-pill,
    .add-tab-btn:hover,
    .chat-msg.user .msg-bubble,
    .me-badge,
    .a11y-size-btn[aria-pressed="true"],
    .a11y-option-btn[aria-pressed="true"] .a11y-switch-pill,
    .mobile-dock-indicator.is-accent .mobile-dock-indicator-fill
) {
    background: #ffd400 !important;
    color: #000000 !important;
    border: 2px solid #ffffff !important;
    font-weight: 800 !important;
}

/* Aktywny kafelek Edytora w dolnym pasku mobilnym nad żółtą pigułką też dostaje czarny tekst i ikonę */
html.a11y-high-contrast .mobile-dock:not(.is-sheet-open) .mobile-dock-item.is-accent.is-active,
html.a11y-high-contrast .mobile-dock:not(.is-sheet-open) .mobile-dock-item.is-accent.is-active svg,
html.a11y-high-contrast .mobile-dock:not(.is-sheet-open) .mobile-dock-item.is-accent.is-active span {
    color: #000000 !important;
    stroke: #000000 !important;
    font-weight: 800 !important;
}

/* Przyciski drugorzędne, przełączniki nieaktywne i przyciski paska — zawsze ciemne tło (#111111) + biały tekst */
html.a11y-high-contrast body :is(
    .btn-secondary,
    .btn-secondary:hover,
    .mobile-sheet-auth-btn.secondary,
    .auth-mode-tab:not(.is-active),
    .auth-callout-btn,
    .map-chip:not(.is-active),
    .admin-tab:not(.is-active),
    .btn-mini:not(.is-active-pill),
    .theme-btn,
    .a11y-nav-btn,
    .user-status-toggle,
    .a11y-reset-btn,
    .a11y-close-btn
) {
    background: #111111 !important;
    color: #ffffff !important;
    border: 2px solid #ffffff !important;
}

html.a11y-high-contrast .theme-btn .btn-text {
    color: #ffffff !important;
}

html.a11y-high-contrast .mobile-dock-indicator:not(.is-accent) .mobile-dock-indicator-fill {
    background: #111111 !important;
    border: 2px solid #ffd400 !important;
    box-shadow: none !important;
}

html.a11y-high-contrast input,
html.a11y-high-contrast textarea,
html.a11y-high-contrast select,
html.a11y-high-contrast button {
    border-color: #ffffff !important;
}

html.a11y-high-contrast input,
html.a11y-high-contrast textarea,
html.a11y-high-contrast select {
    background: #000000 !important;
    color: #ffffff !important;
}

html.a11y-high-contrast .ide-wrapper #code-highlight,
html.a11y-high-contrast .ide-wrapper #code-highlight *,
html.a11y-high-contrast .ide-wrapper #code-editor {
    background: #000000 !important;
}

html.a11y-high-contrast .ide-wrapper #code-editor {
    caret-color: #ffd400 !important;
}

html.a11y-high-contrast :is(a, button, summary, input, select, textarea, [tabindex], [role="button"], [role="tab"], [role="menuitem"]):focus-visible {
    outline: 3px solid #ffd400 !important;
    outline-offset: 3px !important;
}
