/**
 * Accessible LearnDash Frontend Styles
 * Version: 1.0.0
 * Author: Chukwuemeka Princewill
 */

/* ==========================================================================
   CSS Variables
   ========================================================================== */

:root {
    /* User-adjustable variables (set via JS) */
    --ald-font-size: 100%;
    --ald-line-height: 150%;
    --ald-letter-spacing: 0px;
    --ald-word-spacing: 0px;
    
    /* System variables */
    --ald-focus-color: #0066cc;
    --ald-focus-width: 3px;
    --ald-focus-offset: 2px;
    --ald-toolbar-bg: #1e1e1e;
    --ald-toolbar-text: #ffffff;
    --ald-toolbar-size: 360px;
}

/* ==========================================================================
   Screen Reader Only
   ========================================================================== */

.ald-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Show on focus */
.ald-sr-only:focus {
    position: static;
    width: auto;
    height: auto;
    margin: 0;
    overflow: visible;
    clip: auto;
    white-space: normal;
}

/* ==========================================================================
   Skip Links
   ========================================================================== */

.ald-skip-links {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    z-index: 999999;
}

.ald-skip-link {
    position: absolute;
    top: -100px;
    left: 0;
    display: inline-block;
    padding: 12px 20px;
    background: var(--ald-toolbar-bg);
    color: var(--ald-toolbar-text);
    text-decoration: none;
    font-weight: 600;
    transition: top 0.3s ease;
    z-index: 999999;
}

.ald-skip-link:focus {
    top: 0;
    outline: var(--ald-focus-width) solid var(--ald-focus-color);
    outline-offset: 0;
}

/* ==========================================================================
   Enhanced Focus States
   ========================================================================== */

*:focus,
*:focus-visible {
    outline: var(--ald-focus-width) solid var(--ald-focus-color);
    outline-offset: var(--ald-focus-offset);
}

/* Remove default focus */
*:focus:not(:focus-visible) {
    outline: none;
}

/* Button focus */
button:focus-visible,
.button:focus-visible,
input[type="submit"]:focus-visible {
    outline: var(--ald-focus-width) solid var(--ald-focus-color);
    outline-offset: 2px;
}

/* ==========================================================================
   User Preference Styles - VERY SELECTIVE TO PREVENT QUIZ BREAKING
   ========================================================================== */

/* Apply user font size to content - works on multiple container types */
/* Explicitly EXCLUDE quiz content, forms, buttons, inputs */
body.ald-preferences-active #buddyboss-content p,
body.ald-preferences-active #buddyboss-content h1,
body.ald-preferences-active #buddyboss-content h2,
body.ald-preferences-active #buddyboss-content h3,
body.ald-preferences-active #buddyboss-content h4,
body.ald-preferences-active #buddyboss-content li,
body.ald-preferences-active .learndash-wrapper p,
body.ald-preferences-active .learndash-wrapper h1,
body.ald-preferences-active .learndash-wrapper h2,
body.ald-preferences-active .learndash-wrapper h3,
body.ald-preferences-active .learndash-wrapper li,
body.ald-preferences-active article p,
body.ald-preferences-active article h1,
body.ald-preferences-active article h2,
body.ald-preferences-active article h3,
body.ald-preferences-active article li,
body.ald-preferences-active main p,
body.ald-preferences-active main h1,
body.ald-preferences-active main h2,
body.ald-preferences-active main h3,
body.ald-preferences-active main li,
body.ald-preferences-active .entry-content p,
body.ald-preferences-active .entry-content h1,
body.ald-preferences-active .entry-content h2,
body.ald-preferences-active .entry-content h3,
body.ald-preferences-active .entry-content li {
    font-size: calc(1em * var(--ald-font-size) / 100) !important;
    line-height: calc(var(--ald-line-height) / 100) !important;
    letter-spacing: var(--ald-letter-spacing) !important;
    word-spacing: var(--ald-word-spacing) !important;
}

/* NEVER touch these elements - CRITICAL */
body.ald-preferences-active .wpProQuiz_content,
body.ald-preferences-active .wpProQuiz_content *,
body.ald-preferences-active .learndash_assignment_form,
body.ald-preferences-active .learndash_assignment_form *,
body.ald-preferences-active button,
body.ald-preferences-active input,
body.ald-preferences-active select,
body.ald-preferences-active textarea,
body.ald-preferences-active .ald-toolbar,
body.ald-preferences-active .ald-toolbar *,
body.ald-preferences-active #left-panel,
body.ald-preferences-active #left-panel *,
body.ald-preferences-active .sidebar,
body.ald-preferences-active .sidebar * {
    font-size: inherit !important;
    line-height: inherit !important;
    letter-spacing: inherit !important;
    word-spacing: inherit !important;
}

/* High Contrast Mode - Very selective */
body.ald-contrast-high {
    background: #ffffff !important;
    color: #000000 !important;
}

/* Only apply high contrast to safe content elements */
body.ald-contrast-high #buddyboss-content p,
body.ald-contrast-high #buddyboss-content h1,
body.ald-contrast-high #buddyboss-content h2,
body.ald-contrast-high #buddyboss-content h3,
body.ald-contrast-high .learndash-wrapper p,
body.ald-contrast-high .learndash-wrapper h1,
body.ald-contrast-high .learndash-wrapper h2,
body.ald-contrast-high article p,
body.ald-contrast-high article h1,
body.ald-contrast-high article h2,
body.ald-contrast-high main p,
body.ald-contrast-high main h1,
body.ald-contrast-high main h2,
body.ald-contrast-high .entry-content p,
body.ald-contrast-high .entry-content h1,
body.ald-contrast-high .entry-content h2 {
    background: #ffffff !important;
    color: #000000 !important;
}

/* NEVER apply high contrast to quiz/form elements */
body.ald-contrast-high .wpProQuiz_content,
body.ald-contrast-high .wpProQuiz_content *,
body.ald-contrast-high .learndash_assignment_form,
body.ald-contrast-high .learndash_assignment_form * {
    background: inherit !important;
    color: inherit !important;
}

body.ald-contrast-high a {
    color: #0000ee !important;
    text-decoration: underline !important;
}

body.ald-contrast-high a:visited {
    color: #551a8b !important;
}

/* Inverted Colors */
body.ald-contrast-inverted {
    filter: invert(1) hue-rotate(180deg);
}

body.ald-contrast-inverted img,
body.ald-contrast-inverted video {
    filter: invert(1) hue-rotate(180deg);
}

/* Dark Mode */
body.ald-contrast-dark {
    background: #1e1e1e !important;
    color: #e0e0e0 !important;
}

body.ald-contrast-dark * {
    background: #1e1e1e !important;
    color: #e0e0e0 !important;
    border-color: #444444 !important;
}

body.ald-contrast-dark a {
    color: #66b3ff !important;
}

/* Dyslexia Font */
body.ald-dyslexia-font,
body.ald-dyslexia-font * {
    font-family: 'OpenDyslexic', 'Comic Sans MS', Arial, sans-serif !important;
}

/* Highlight Links */
body.ald-highlight-links a:not(.wpProQuiz_content a):not(.ald-toolbar a) {
    background: #ffff00 !important;
    color: #000000 !important;
    padding: 2px 4px !important;
    border-radius: 2px !important;
    text-decoration: underline !important;
}

/* Cursor Sizes */
body.ald-cursor-large * {
    cursor: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32"><path d="M2 2 L2 28 L12 22 L18 32 L24 28 L18 18 L30 18 Z" fill="black"/><path d="M4 4 L4 24 L12 20 L16 28 L20 26 L16 18 L26 18 Z" fill="white"/></svg>') 4 4, auto !important;
}

body.ald-cursor-extra-large * {
    cursor: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="48" height="48"><path d="M3 3 L3 42 L18 33 L27 48 L36 42 L27 27 L45 27 Z" fill="black"/><path d="M6 6 L6 36 L18 30 L24 42 L30 39 L24 27 L39 27 Z" fill="white"/></svg>') 6 6, auto !important;
}

/* ==========================================================================
   Accessibility Toolbar
   ========================================================================== */

.ald-toolbar {
    position: fixed;
    z-index: 999998;
}

/* Positioning */
.ald-toolbar-top-left {
    top: 20px;
    left: 20px;
}

.ald-toolbar-top-right {
    top: 20px;
    right: 20px;
}

.ald-toolbar-bottom-left {
    bottom: 20px;
    left: 20px;
}

.ald-toolbar-bottom-right {
    bottom: 20px;
    right: 20px;
}

/* Toggle Button */
.ald-toolbar-toggle {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--ald-toolbar-bg);
    color: var(--ald-toolbar-text);
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ald-toolbar-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
}

.ald-toolbar-toggle:focus {
    outline: var(--ald-focus-width) solid var(--ald-focus-color);
    outline-offset: 4px;
}

/* Panel */
.ald-toolbar-panel {
    position: absolute;
    width: var(--ald-toolbar-size);
    max-height: 80vh;
    background: var(--ald-toolbar-bg);
    color: var(--ald-toolbar-text);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* Panel positioning */
.ald-toolbar-top-left .ald-toolbar-panel,
.ald-toolbar-bottom-left .ald-toolbar-panel {
    left: 0;
}

.ald-toolbar-top-right .ald-toolbar-panel,
.ald-toolbar-bottom-right .ald-toolbar-panel {
    right: 0;
}

.ald-toolbar-top-left .ald-toolbar-panel,
.ald-toolbar-top-right .ald-toolbar-panel {
    top: 70px;
}

.ald-toolbar-bottom-left .ald-toolbar-panel,
.ald-toolbar-bottom-right .ald-toolbar-panel {
    bottom: 70px;
}

/* Panel header */
.ald-toolbar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.ald-toolbar-header h2 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: #ff0000 !important; /* RED as requested */
}

.ald-toolbar-close {
    background: transparent;
    border: none;
    color: inherit;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: background 0.2s;
}

.ald-toolbar-close:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* Panel content */
.ald-toolbar-content {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
    color: var(--ald-toolbar-text);
}

/* Control groups */
.ald-control-group {
    margin-bottom: 24px;
}

.ald-control-group:last-child {
    margin-bottom: 0;
}

.ald-control-group h3 {
    margin: 0 0 12px 0;
    font-size: 14px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #ffffff !important; /* Force white text */
}

/* Controls */
.ald-control {
    margin-bottom: 16px;
}

.ald-control:last-child {
    margin-bottom: 0;
}

.ald-control label {
    display: block;
    margin-bottom: 8px;
    font-size: 14px;
    font-weight: 500;
    color: #ffffff !important; /* Force white text */
}

.ald-control input[type="range"] {
    width: 100%;
    margin: 8px 0;
}

.ald-control select {
    width: 100%;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.1);
    color: inherit;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    font-size: 14px;
}

.ald-control input[type="checkbox"] {
    margin-right: 8px;
}

.ald-control-buttons {
    display: flex;
    align-items: center;
    gap: 8px;
}

.ald-value-display {
    display: block;
    text-align: center;
    font-size: 12px;
    color: #ffffff !important; /* Force white text */
    margin-top: 4px;
}

/* Buttons */
.ald-btn {
    display: inline-block;
    padding: 10px 16px;
    background: rgba(255, 255, 255, 0.1);
    color: #ffffff !important; /* Force white text */
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
}

.ald-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: translateY(-1px);
}

.ald-btn:active {
    transform: translateY(0);
}

.ald-btn-primary {
    background: #0066cc;
    border-color: #0066cc;
}

.ald-btn-primary:hover {
    background: #0052a3;
}

.ald-btn-secondary {
    background: transparent;
}

.ald-btn-block {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.ald-btn-sm {
    padding: 6px 12px;
    font-size: 12px;
}

/* Profiles */
.ald-profiles {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.ald-profile-btn {
    padding: 12px;
    background: rgba(255, 255, 255, 0.05);
    color: #ffffff !important; /* Force white text */
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}

.ald-profile-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.3);
}

.ald-profile-btn.active {
    background: #0066cc;
    border-color: #0066cc;
}

/* Actions */
.ald-toolbar-actions {
    display: flex;
    gap: 8px;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

/* ==========================================================================
   Text-to-Speech Button
   ========================================================================== */

.ald-tts-content-button {
    margin-bottom: 20px;
}

.ald-btn-tts {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.ald-btn-tts.reading {
    background: #cc0000;
    border-color: #cc0000;
}

/* ==========================================================================
   Keyboard Shortcuts Modal
   ========================================================================== */

.ald-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 999999;
}

.ald-modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
}

.ald-modal-content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.ald-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid #e0e0e0;
}

.ald-modal-header h2 {
    margin: 0;
    font-size: 20px;
    color: #1e1e1e;
}

.ald-modal-close {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 4px;
    color: #666666;
}

.ald-modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

.ald-shortcuts-table {
    width: 100%;
    border-collapse: collapse;
}

.ald-shortcuts-table th,
.ald-shortcuts-table td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid #e0e0e0;
}

.ald-shortcuts-table th {
    font-weight: 600;
    background: #f5f5f5;
}

.ald-shortcuts-table kbd {
    display: inline-block;
    padding: 4px 8px;
    background: #f0f0f0;
    border: 1px solid #d0d0d0;
    border-radius: 4px;
    font-family: monospace;
    font-size: 12px;
}

.ald-help-note {
    margin-top: 16px;
    padding: 12px;
    background: #f9f9f9;
    border-left: 3px solid #0066cc;
    font-size: 14px;
}

.ald-help-note p {
    margin: 4px 0;
}

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 480px) {
    :root {
        --ald-toolbar-size: 100vw;
    }
    
    .ald-toolbar {
        position: fixed !important;
        top: auto !important;
        right: auto !important;
        bottom: 0 !important;
        left: 0 !important;
        width: 100%;
    }
    
    .ald-toolbar-panel {
        position: fixed;
        top: auto !important;
        right: 0 !important;
        bottom: 70px !important;
        left: 0 !important;
        max-height: 70vh;
        border-radius: 12px 12px 0 0;
    }
    
    .ald-toolbar-toggle {
        position: absolute;
        right: 20px;
        bottom: 20px;
    }
    
    .ald-profiles {
        grid-template-columns: 1fr;
    }
}

/* ==========================================================================
   Print Styles
   ========================================================================== */

@media print {
    .ald-toolbar,
    .ald-skip-links,
    .ald-modal {
        display: none !important;
    }
}

/* ==========================================================================
   Speech-to-Text (STT) Styles
   ========================================================================== */

.ald-stt-status {
    padding: 8px 12px;
    margin-top: 8px;
    background: rgba(0, 123, 255, 0.1);
    border-left: 3px solid #007bff;
    border-radius: 4px;
    font-size: 13px;
    color: #ffffff;
}

.ald-stt-preview {
    padding: 8px 12px;
    margin-top: 8px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 4px;
    font-size: 13px;
    min-height: 40px;
    font-style: italic;
    color: rgba(255, 255, 255, 0.7);
}

.ald-stt-preview:empty::before {
    content: 'Voice input will appear here...';
    color: rgba(255, 255, 255, 0.4);
}

#ald-stt-toggle.listening {
    background: #dc3545 !important;
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

.ald-help-text {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.6);
    margin-top: 8px;
    line-height: 1.4;
}
