/* Accessibility styles */

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

/* Skip links */
.skip-links {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: var(--primary-color);
    color: var(--text-light);
    padding: 1rem;
    z-index: 10000;
    display: flex;
    gap: 1rem;
    justify-content: center;
    transform: translateY(-100%);
    transition: transform 0.3s ease;
}

.skip-links:focus-within {
    transform: translateY(0);
}

.skip-links a {
    color: var(--text-light);
    text-decoration: none;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.2);
    transition: all 0.3s ease;
}

.skip-links a:hover,
.skip-links a:focus {
    background: rgba(255, 255, 255, 0.3);
    outline: 2px solid var(--text-light);
    outline-offset: 2px;
}

/* Accessibility control panel */
.accessibility-controls {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
}

.a11y-toggle {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: var(--primary-color);
    color: var(--text-light);
    border: none;
    font-size: 24px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    transition: all 0.3s ease;
}

.a11y-toggle:hover,
.a11y-toggle:focus {
    background: var(--primary-hover);
    transform: scale(1.1);
    outline: 2px solid var(--focus-color);
    outline-offset: 2px;
}

.a11y-panel {
    position: absolute;
    top: 60px;
    right: 0;
    width: 300px;
    background: var(--card-background);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1rem;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
    color: var(--text-color);
}

.a11y-panel.hidden {
    display: none;
}

.a11y-panel h3 {
    margin: 0 0 1rem 0;
    color: var(--primary-color);
}

.a11y-panel label {
    display: block;
    margin-bottom: 0.5rem;
    cursor: pointer;
}

.a11y-panel input[type="checkbox"] {
    margin-right: 0.5rem;
}

.a11y-btn {
    width: 100%;
    padding: 0.5rem;
    background: var(--primary-color);
    color: var(--text-light);
    border: none;
    border-radius: 4px;
    cursor: pointer;
    margin-top: 1rem;
    transition: background 0.3s ease;
}

.a11y-btn:hover,
.a11y-btn:focus {
    background: var(--primary-hover);
    outline: 2px solid var(--focus-color);
    outline-offset: 2px;
}

/* High contrast mode */
.high-contrast {
    --text-color: #000000;
    --text-light: #ffffff;
    --background-color: #ffffff;
    --card-background: #ffffff;
    --border-color: #000000;
    --primary-color: #000000;
    --primary-hover: #333333;
    --focus-color: #ff6600;
    --success-color: #008000;
    --error-color: #ff0000;
    --warning-color: #ff8800;
}

.high-contrast .algorithm-card,
.high-contrast .mode-btn,
.high-contrast .action-btn {
    border: 2px solid var(--border-color) !important;
    background: var(--background-color) !important;
    color: var(--text-color) !important;
}

.high-contrast .algorithm-card.selected,
.high-contrast .mode-btn.active {
    background: var(--text-color) !important;
    color: var(--background-color) !important;
}

.high-contrast input,
.high-contrast textarea,
.high-contrast select {
    border: 2px solid var(--border-color) !important;
    background: var(--background-color) !important;
    color: var(--text-color) !important;
}

.high-contrast button:focus,
.high-contrast input:focus,
.high-contrast textarea:focus,
.high-contrast select:focus,
.high-contrast .algorithm-card:focus,
.high-contrast .mode-btn:focus {
    outline: 3px solid var(--focus-color) !important;
    outline-offset: 2px !important;
}

/* Reduced motion */
.reduced-motion *,
.reduced-motion *::before,
.reduced-motion *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
}

/* Enhanced focus indicators */
button:focus,
input:focus,
textarea:focus,
select:focus,
[tabindex]:focus {
    outline: 2px solid var(--focus-color, #4A90E2);
    outline-offset: 2px;
    box-shadow: 0 0 0 4px rgba(74, 144, 226, 0.2);
}

.algorithm-card:focus,
.mode-btn:focus {
    outline: 3px solid var(--focus-color, #4A90E2);
    outline-offset: 2px;
    transform: scale(1.02);
}

/* Better color contrast for important elements */
.status-message {
    background: var(--success-color);
    color: var(--text-light);
    padding: 1rem;
    border-radius: 4px;
    font-weight: 500;
}

.error-message {
    background: var(--error-color);
    color: var(--text-light);
    padding: 1rem;
    border-radius: 4px;
    font-weight: 500;
}

/* Improved form labels */
label {
    font-weight: 500;
    color: var(--text-color);
    margin-bottom: 0.5rem;
    display: block;
}

/* Progress bar accessibility */
.progress-bar[role="progressbar"] {
    background: var(--background-color);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    overflow: hidden;
    position: relative;
}

.progress-bar[role="progressbar"]::after {
    content: attr(aria-valuetext);
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: var(--text-color);
    font-size: 0.9rem;
    font-weight: 500;
}

/* Modal accessibility */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
}

.modal-overlay .modal-content {
    background: var(--card-background);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 2rem;
    max-width: 90vw;
    max-height: 90vh;
    overflow: auto;
    position: relative;
}

.modal-overlay .modal-content:focus {
    outline: 2px solid var(--focus-color);
    outline-offset: 2px;
}

.modal-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-color);
    padding: 0.5rem;
    border-radius: 4px;
}

.modal-close:hover,
.modal-close:focus {
    background: var(--border-color);
    outline: 2px solid var(--focus-color);
    outline-offset: 2px;
}

/* Keyboard shortcuts modal */
.shortcuts-modal {
    min-width: 400px;
}

.shortcuts-modal h3 {
    margin-top: 0;
    color: var(--primary-color);
}

.shortcuts-modal ul {
    list-style: none;
    padding: 0;
    margin: 1rem 0;
}

.shortcuts-modal li {
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.shortcuts-modal kbd {
    background: var(--border-color);
    color: var(--text-color);
    padding: 0.25rem 0.5rem;
    border-radius: 3px;
    font-family: monospace;
    font-size: 0.9rem;
    border: 1px solid var(--text-color);
    min-width: 100px;
    text-align: center;
}

/* Responsive accessibility */
@media (max-width: 768px) {
    .accessibility-controls {
        top: 10px;
        right: 10px;
    }
    
    .a11y-toggle {
        width: 40px;
        height: 40px;
        font-size: 20px;
    }
    
    .a11y-panel {
        width: 280px;
        top: 50px;
    }
    
    .shortcuts-modal {
        min-width: 300px;
    }
}

/* Print styles */
@media print {
    .accessibility-controls,
    .skip-links {
        display: none !important;
    }
}

/* Prefers color scheme support */
@media (prefers-color-scheme: dark) {
    .dark-mode {
        --text-color: #ffffff;
        --text-light: #ffffff;
        --background-color: #1a1a1a;
        --card-background: #2a2a2a;
        --border-color: #555555;
        --primary-color: #4A90E2;
        --primary-hover: #5BA0F2;
        --focus-color: #FFD700;
    }
}

/* Motion preferences */
/*
 * The usual blanket reset, with one hole in it.
 *
 * `!important` on `*` cannot be overridden by any component, which is the
 * point almost everywhere and a defect for a component that handles the
 * preference itself. The conformance lab is six diagrams whose whole content
 * is motion; stopping them dead while the page's canvas and custom cursor
 * carried on -- both JavaScript, neither consults this -- read as broken
 * rendering rather than as a considered default, and there was no control
 * anywhere that could bring them back.
 *
 * So a subtree may take responsibility by carrying `.motion-managed`, and is
 * then expected to actually do something: offer a calmer mode by default and
 * a way to turn motion on. Everything that does not claim it keeps the
 * blanket. Do not add this class to make an animation work -- if the
 * animation has no reduced-motion story of its own, the blanket is correct.
 */
@media (prefers-reduced-motion: reduce) {
    *:not(.motion-managed, .motion-managed *),
    *:not(.motion-managed, .motion-managed *)::before,
    *:not(.motion-managed, .motion-managed *)::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* Contrast preferences */
@media (prefers-contrast: high) {
    :root {
        --focus-color: #ff6600;
    }
    
    button,
    input,
    textarea,
    select {
        border-width: 2px !important;
    }
    
    .algorithm-card,
    .mode-btn {
        border-width: 2px !important;
    }
}