/* Barrierefreiheits-Widget Basis-Styles */
/* Hinweis: Keine globalen CSS-Filter am Body/HTML, um Sticky/Layout zu schützen.
   Farb-/Kontrastanpassungen laufen per Backdrop-Filter über #a11y-filter-overlay. */
.accessibility-widget {
    position: fixed;
    top: calc(50vh - 30px);
    right: 20px;
    transform: none;
    z-index: 2147483647;
    font-family: Arial, sans-serif;
}

/* Sticky Toggle Button */
.accessibility-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: #1976d2;
    border: none;
    color: white;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.accessibility-toggle:hover {
    background: #1565c0;
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
}

.accessibility-toggle:focus {
    outline: 3px solid #ffeb3b;
    outline-offset: 2px;
}

/* Konfigurationspanel */
.accessibility-panel {
    position: fixed;
    right: 80px;
    top: 50%;
    transform: translateY(-50%);
    width: 380px;
    max-height: 80vh;
    background: white;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    border: 1px solid #e0e0e0;
    overflow: hidden;
    animation: slideInFromRight 0.3s ease;
}

/* Sicherstellen, dass Panel und Toggle immer oberhalb der Maske liegen */
.accessibility-toggle,
.accessibility-panel { z-index: 2147483647; }

@keyframes slideInFromRight {
    from {
        opacity: 0;
        transform: translateY(-50%) translateX(20px);
    }
    to {
        opacity: 1;
        transform: translateY(-50%) translateX(0);
    }
}

/* Panel Header */
.panel-header {
    background: #1976d2;
    color: white;
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.panel-header h2 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
}

.close-button {
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background 0.2s ease;
}

.close-button:hover {
    background: rgba(255, 255, 255, 0.1);
}

.close-button:focus {
    outline: 2px solid #ffeb3b;
    outline-offset: 2px;
}

/* Panel Content */
.panel-content {
    max-height: calc(80vh - 80px);
    overflow-y: auto;
    overflow-x: hidden; /* kein horizontales Scrollen im Overlay */
    padding: 20px;
}

/* Setting Groups */
.setting-group {
    margin-bottom: 24px;
}

.setting-group:last-child {
    margin-bottom: 0;
}

.setting-group h3 {
    margin: 0 0 12px 0;
    font-size: 16px;
    font-weight: 600;
    color: #333;
}

/* Button Groups */
.button-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Für horizontale Controls (Segmented Controls bleiben nebeneinander) */
.button-group .control {
    margin-bottom: 12px;
}

.button-group .segmented {
    align-self: flex-start;
}

/* Checkboxes in eigener vertikaler Liste */
.checkbox-group {
    display: flex;
    flex-direction: column;
    gap: 0; /* Gap wird durch margin-bottom der Labels gehandhabt */
}

.setting-button {
    padding: 8px 16px;
    border: 2px solid #e0e0e0;
    background: white;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s ease;
    color: #666;
}

.setting-button:hover {
    border-color: #1976d2;
    color: #1976d2;
}

.setting-button:focus {
    outline: 2px solid #ffeb3b;
    outline-offset: 2px;
}

.setting-button.active {
    background: #1976d2;
    border-color: #1976d2;
    color: white;
}

/* Checkbox Groups */
.checkbox-group {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.checkbox-label {
    display: flex;
    align-items: flex-start;
    cursor: pointer;
    font-size: 14px;
    color: #333;
    position: relative;
    padding-left: 32px;
    margin-bottom: 12px;
    line-height: 20px;
}

.checkbox-label input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    cursor: pointer;
}

.checkmark {
    position: absolute;
    left: 0;
    top: 0;
    height: 20px;
    width: 20px;
    background-color: white;
    border: 2px solid #e0e0e0;
    border-radius: 4px;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.checkbox-label:hover .checkmark {
    border-color: #1976d2;
}

.checkbox-label input:checked ~ .checkmark {
    background-color: #1976d2;
    border-color: #1976d2;
}

.checkmark:after {
    content: "";
    position: absolute;
    display: none;
    left: 6px;
    top: 2px;
    width: 6px;
    height: 10px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.checkbox-label input:checked ~ .checkmark:after {
    display: block;
}

.checkbox-label input:focus ~ .checkmark {
    outline: 2px solid #ffeb3b;
    outline-offset: 2px;
}

/* Panel Footer */
.panel-footer {
    border-top: 1px solid #e0e0e0;
    padding: 16px 0 0 0;
    margin-top: 20px;
}

.reset-button {
    width: 100%;
    padding: 12px;
    background: #f44336;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: background 0.2s ease;
}

.reset-button:hover {
    background: #d32f2f;
}

.reset-button:focus {
    outline: 2px solid #ffeb3b;
    outline-offset: 2px;
}

/* Accessibility Features */

/* Font Size Adjustments – wirken auf gesamten Seiteninhalt */
#a11y-content-root.accessibility-font-small,
#a11y-content-root.accessibility-font-small * { font-size: 90% !important; }

#a11y-content-root.accessibility-font-normal,
#a11y-content-root.accessibility-font-normal * { font-size: inherit !important; }

#a11y-content-root.accessibility-font-large,
#a11y-content-root.accessibility-font-large * { font-size: 112% !important; }

#a11y-content-root.accessibility-font-xlarge,
#a11y-content-root.accessibility-font-xlarge * { font-size: 125% !important; }

/* Line Height Adjustments – auf gesamten Seiteninhalt */
#a11y-content-root.accessibility-line-height-normal,
#a11y-content-root.accessibility-line-height-normal * { line-height: inherit !important; }

#a11y-content-root.accessibility-line-height-increased,
#a11y-content-root.accessibility-line-height-increased * { line-height: 1.6 !important; }

#a11y-content-root.accessibility-line-height-large,
#a11y-content-root.accessibility-line-height-large * { line-height: 1.8 !important; }

/* Letter Spacing Adjustments */
#a11y-content-root.accessibility-letter-spacing-normal,
#a11y-content-root.accessibility-letter-spacing-normal * { letter-spacing: inherit !important; }

#a11y-content-root.accessibility-letter-spacing-increased,
#a11y-content-root.accessibility-letter-spacing-increased * { letter-spacing: 0.05em !important; }

#a11y-content-root.accessibility-letter-spacing-large,
#a11y-content-root.accessibility-letter-spacing-large * { letter-spacing: 0.1em !important; }

/* Contrast/Sättigung/Helligkeit werden via #a11y-filter-overlay (backdrop-filter) umgesetzt.
   Die folgenden Klassen dienen als Marker (für JS/UI) und intentionally enthalten keine Regeln. */
/* .accessibility-contrast-high */
/* .accessibility-contrast-dark */
/* .accessibility-contrast-light */
/* .accessibility-saturation-low */
/* .accessibility-saturation-monochrome */

/* Text linksbündig auf gesamtem Inhalt */
#a11y-content-root.accessibility-text-align,
#a11y-content-root.accessibility-text-align * {
    text-align: left !important;
}

/* Link/Buttons hervorheben */
.accessibility-link-highlight a,
.accessibility-link-highlight button,
.accessibility-link-highlight [role="button"],
.accessibility-link-highlight input[type="button"],
.accessibility-link-highlight input[type="submit"],
.accessibility-link-highlight .btn,
.accessibility-link-highlight .button {
    background-color: #ffeb3b !important;
    text-decoration: underline !important;
    font-weight: bold !important;
}

/* Stop Animations */
.accessibility-stop-animations * {
    animation-duration: 0s !important;
    animation-delay: 0s !important;
    transition-duration: 0s !important;
}

/* Hide Images */
.accessibility-hide-images img { display: none !important; }
.accessibility-hide-images * { background-image: none !important; -webkit-mask-image: none !important; mask-image: none !important; }
.accessibility-hide-images *::before,
.accessibility-hide-images *::after { background-image: none !important; -webkit-mask-image: none !important; mask-image: none !important; }

/* Readable Font */
.accessibility-readable-font * {
    font-family: 'Arial', sans-serif !important;
}

/* Reading Guide */
.reading-guide {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: #ff9800;
    z-index: 2147483645;
    pointer-events: none;
    transition: top 0.1s ease;
}

/* Reading Mask */
.reading-mask {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    z-index: 2147483646;
    pointer-events: none; /* Maske darf keine Klicks abfangen */
}

.mask-hole {
    position: absolute;
    background: transparent;
    border-radius: 4px;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.8);
    pointer-events: none;
}

/* Fokus-Overlay: zentrierter Sichtbereich */
.focus-overlay {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 2147483643;
}
.focus-overlay .focus-hole {
    position: absolute;
    left: 0;
    right: 0;
    top: 50vh; /* initiale Position; wird dynamisch per JS auf Maus-Y gesetzt */
    transform: translateY(-50%);
    height: min(40vh, 450px);
    border-radius: 0;
    box-shadow: 0 0 0 9999px rgba(0,0,0,0.75);
}

/* Virtual Keyboard */
.virtual-keyboard {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 16px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    z-index: 2147483642; /* über Fokus-Overlay, unter Maske/Panel */
    max-width: 90vw;
    user-select: none;
}

.keyboard-row {
    display: flex;
    justify-content: center;
    margin-bottom: 8px;
    gap: 4px;
}

.keyboard-key {
    padding: 8px 12px;
    background: #f5f5f5;
    border: 1px solid #ddd;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    min-width: 40px;
    text-align: center;
    transition: background 0.2s ease;
}

.keyboard-key:hover {
    background: #e0e0e0;
}

.keyboard-key.space {
    min-width: 200px;
}
.keyboard-key.enter { min-width: 100px; }
.keyboard-key.tab { min-width: 80px; }

/* Drag-Handle der virtuellen Tastatur */
.vk-header {
    margin: -16px -16px 12px -16px;
    padding: 8px 12px;
    background: #f7f7f7;
    border-bottom: 1px solid #e0e0e0;
    border-radius: 8px 8px 0 0;
    cursor: move;
    font-size: 13px;
    color: #333;
    font-weight: 600;
}

/* Responsive Anpassungen */
@media (max-width: 768px) {
    .accessibility-panel {
        width: calc(100vw - 40px);
        right: 20px;
        left: 20px;
        transform: translateY(-50%);
    }

    .accessibility-toggle {
        width: 50px;
        height: 50px;
    }
    /* auf Touch-Geräten unten rechts platzieren */
    .accessibility-widget {
        right: 16px;
        bottom: 16px; /* Fallback */
        bottom: calc(16px + env(safe-area-inset-bottom)); /* Safe Area für iOS */
        top: auto;
        left: auto;
    }

    .virtual-keyboard {
        bottom: 10px;
        left: 10px;
        right: 10px;
        transform: none;
        max-width: none;
    }
}

/* Touch-Geräte unabhängig von der Breite: Button unten rechts halten */
@media (pointer: coarse) {
    .accessibility-widget {
        right: 16px;
        bottom: 16px; /* Fallback */
        bottom: calc(16px + env(safe-area-inset-bottom));
        top: auto;
        left: auto;
    }
}

/* High Contrast Support */
@media (prefers-contrast: high) {
    .accessibility-toggle {
        border: 2px solid white;
    }

    .accessibility-panel {
        border: 2px solid #000;
    }
}

/* Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {
    .accessibility-toggle {
        transition: none;
    }

    .accessibility-panel {
        animation: none;
    }

    .reading-guide {
        transition: none;
    }
}

/* --- Erweiterungen: UI Controls, Profile & zusätzliche Features --- */

/* Segmented Controls & Controls Row */
.control {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap; /* bricht um, um Overflow zu vermeiden */
}
.control-label {
    font-size: 13px;
    color: #555;
    min-width: 160px;
}
.segmented {
    display: flex;
    flex-wrap: wrap; /* Buttons dürfen umbrechen */
    background: #f5f7fa;
    border: 1px solid #e0e4ea;
    border-radius: 8px;
    padding: 4px;
    gap: 6px;
    max-width: 100%;
}

/* (Profile entfernt) */

/* Neue Feature-Klassen */
/* Marker-Klassen, Logik über #a11y-filter-overlay (backdrop-filter) */
/* .accessibility-brightness-low */
/* .accessibility-brightness-high */
/* .accessibility-invert-colors */
.accessibility-dyslexic-font * { font-family: 'OpenDyslexic', 'Arial', sans-serif !important; letter-spacing: 0.05em !important; }
.accessibility-headings-highlight h1,
.accessibility-headings-highlight h2,
.accessibility-headings-highlight h3,
.accessibility-headings-highlight h4,
.accessibility-headings-highlight h5,
.accessibility-headings-highlight h6 {
    background: #fff59d;
    padding: 2px 4px;
    border-radius: 4px;
}
.a11y-focus-ring {
    outline: 3px solid #ffeb3b !important;
    outline-offset: 2px !important;
}
/* Fokus-Modus: Nur direkte Geschwister dimmen, Ziel bleibt voll sichtbar */
#a11y-content-root.accessibility-focus-mode > * { opacity: 0.25; transition: opacity .15s ease; }
#a11y-content-root.accessibility-focus-mode > .a11y-focus-target { opacity: 1 !important; }
.accessibility-text-zoom { font-size: 112% !important; }
/* Großer, gut sichtbarer Cursor (weißer Kreis mit schwarzer Kontur) */
#a11y-content-root.accessibility-cursor-large { cursor: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='36' height='36' viewBox='0 0 36 36'><circle cx='8' cy='8' r='7' fill='white' stroke='black' stroke-width='2'/></svg>") 0 0, auto; }
#a11y-content-root.accessibility-cursor-large * { cursor: inherit !important; }
/* zusätzlich: falls Klasse wider Erwarten auf <body> gesetzt wird */
body.accessibility-cursor-large { cursor: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='36' height='36' viewBox='0 0 36 36'><circle cx='8' cy='8' r='7' fill='white' stroke='black' stroke-width='2'/></svg>") 0 0, auto; }
body.accessibility-cursor-large * { cursor: inherit !important; }

/* Read Aloud Controls */
.read-aloud-controls {
    position: fixed;
    right: 16px;
    bottom: 90px;
    display: flex;
    gap: 8px;
    background: #ffffff;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.12);
    z-index: 2147483642; /* unter Panel, über Fokus-Overlay */
}
.read-aloud-controls .ra-btn {
    min-width: 36px;
    min-height: 36px;
    border: 1px solid #ddd;
    background: #f5f5f5;
    border-radius: 6px;
    cursor: pointer;
    font-size: 16px;
}
.read-aloud-controls .ra-btn:hover { background: #eaeaea; }
.read-aloud-controls .ra-btn:focus { outline: 2px solid #ffeb3b; outline-offset: 2px; }
