/* ============================================
   ACCESSIBILITY STYLES
   IdleHack - WCAG 2.1 AA Compliance
   ============================================ */

/* ============================================
   SEMANTIC ELEMENT RESETS
   ============================================ */

/**
 * Reset h2 used as panel headers
 * Browser default h2 has margins that break the layout
 * Only reset margin - let .panel-header styles handle font-size/weight
 */
h2.panel-header {
    margin: 0;
}


/* ============================================
   SCREEN READER ONLY CONTENT
   ============================================ */

/**
 * Visually hide content while keeping it accessible to screen readers.
 * Use this for skip links, labels, and announcements.
 */
.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;
}

/**
 * Show sr-only content when focused (for skip links)
 */
.sr-only-focusable:focus,
.sr-only-focusable:focus-within {
    position: static;
    width: auto;
    height: auto;
    padding: inherit;
    margin: inherit;
    overflow: visible;
    clip: auto;
    white-space: normal;
}

/* ============================================
   FOCUS INDICATORS
   ============================================ */

/**
 * Global focus-visible for all interactive elements.
 * :focus-visible shows focus ring for keyboard users but not mouse clicks.
 */
:focus-visible {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

/**
 * Fallback for browsers without :focus-visible support
 */
@supports not selector(:focus-visible) {
    :focus {
        outline: 2px solid var(--accent-color);
        outline-offset: 2px;
    }
}

/**
 * Form elements - keep box-shadow for visual enhancement AND show outline
 */
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
button:focus-visible {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

/**
 * For elements with borders, use inset outline to stay within bounds
 */
.menu-link:focus-visible,
.chat-tab:focus-visible,
.context-menu-item:focus-visible,
.help-section-header:focus-visible,
.stats-tab:focus-visible,
.achievements-tab:focus-visible {
    outline: 2px solid var(--accent-color);
    outline-offset: -2px;
}

/**
 * Menu links also show focus ring when programmatically focused (e.g., via keyboard shortcuts)
 * This ensures visual feedback when using number keys to navigate
 */
.menu-link:focus {
    outline: 2px solid var(--accent-color);
    outline-offset: -2px;
}

/**
 * Modern UI mode uses box-shadow for focus indicators.
 * Keep transparent outline so forced-colors mode can override it.
 */
body.modern-ui :focus-visible {
    outline: 2px solid transparent;
    box-shadow: var(--ui-focus-ring);
}

/**
 * Forced colors mode (e.g., Windows High Contrast)
 * Always show visible outlines and system-color borders.
 */
@media (forced-colors: active) {
    :focus-visible {
        outline: 2px solid CanvasText !important;
        outline-offset: 2px !important;
    }

    /* Ensure focus is visible in forced colors even on modern-ui */
    body.modern-ui :focus-visible {
        outline: 2px solid CanvasText !important;
        box-shadow: none !important;
    }

    /* Panels need visible borders */
    .panel {
        border: 1px solid CanvasText !important;
    }

    /* Progress bars need visible track and fill */
    .progress-bar {
        border: 1px solid CanvasText !important;
    }

    .progress-fill {
        forced-color-adjust: none;
        background: Highlight !important;
    }

    /* Buttons need visible borders */
    button {
        border: 1px solid ButtonText !important;
    }

    button:hover {
        border-color: Highlight !important;
    }

    /* Chat tabs need visible boundaries */
    .chat-tab {
        border: 1px solid CanvasText !important;
    }

    .chat-tab.active {
        border-color: Highlight !important;
        background: Highlight !important;
        color: HighlightText !important;
    }

    /* Inputs and selects */
    input, select, textarea {
        border: 1px solid CanvasText !important;
    }
}

/**
 * High contrast mode - even more visible focus
 */
body.high-contrast :focus-visible {
    outline: 3px solid var(--text-color);
    outline-offset: 2px;
}

/* ============================================
   SKIP LINKS
   ============================================ */

.skip-link {
    position: absolute;
    top: -100px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10000;
    padding: 12px 24px;
    background: var(--bg-color);
    color: var(--text-color);
    border: 2px solid var(--accent-color);
    text-decoration: none;
    font-weight: bold;
    transition: top 0.2s ease;
}

.skip-link:focus {
    top: 10px;
    outline: none; /* Border is sufficient here */
}

/* ============================================
   BUTTON RESETS (for semantic button elements)
   ============================================ */

/**
 * Reset button styles for help section headers
 * Other button resets are in their respective CSS files
 */
button.help-section-header {
    background: none;
    border: none;
    border-bottom: 1px solid var(--border-color);
    padding: 0;
    font: inherit;
    color: inherit;
    cursor: pointer;
    text-align: left;
    width: 100%;
}

/* ============================================
   KEYBOARD NAVIGATION ENHANCEMENTS
   ============================================ */

/**
 * Interactive elements that need keyboard access
 */
[role="button"],
[role="menuitem"],
[role="tab"],
[tabindex="0"] {
    cursor: pointer;
}

/**
 * Context menu items as buttons - reset button styles
 */
.context-menu button.context-menu-item {
    background: none;
    border: none;
    font: inherit;
    color: inherit;
    width: 100%;
    text-align: left;
    cursor: pointer;
}

.context-menu button.context-menu-item:focus {
    background: var(--accent-color);
    color: var(--bg-color);
}

/**
 * Ensure disabled elements are not focusable
 */
[aria-disabled="true"],
[disabled] {
    cursor: not-allowed;
}

/* ============================================
   REDUCED MOTION
   ============================================ */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }

    /* Specifically disable chat tab pulse animation */
    .chat-tab.unread::after {
        animation: none;
    }

    /* Disable floating text animation */
    .floating-text {
        animation: none;
        opacity: 1;
    }

    /* Disable toast slide animations */
    .toast {
        animation: none;
    }

    .toast.toast-hiding {
        animation: none;
    }

    /* Disable achievement toast animation */
    .achievement-toast {
        animation: none;
    }

    /* Disable modern progress shimmer */
    .progress-fill::after {
        animation: none !important;
    }

    /* Disable CRT scanline/flicker effects */
    .crt-overlay {
        animation: none !important;
    }

    /* Disable transform-based hover effects */
    .zone-item:hover,
    .action-card:hover,
    .inventory-item:hover,
    .hardware-card:hover,
    button:hover {
        transform: none !important;
    }

    /* Disable pulse animations */
    .chat-tab.unread,
    .chat-tab.attention,
    .contract-board-glow {
        animation: none !important;
    }

    .contract-board-glow::after {
        animation: none !important;
        transform: none !important;
        opacity: 0.45;
    }
}

/* ============================================
   HIGH CONTRAST ENHANCEMENTS
   ============================================ */

/**
 * Auto-enable high contrast for users who prefer it at OS level
 */
@media (prefers-contrast: more) {
    body:not(.high-contrast-disabled) {
        --dim-color: var(--high-contrast-dim, #999999);
    }

    /* Strengthen borders */
    body:not(.high-contrast-disabled) input,
    body:not(.high-contrast-disabled) select,
    body:not(.high-contrast-disabled) textarea {
        border-width: 2px;
    }
}

/**
 * High contrast mode - stronger borders for UI components
 */
body.high-contrast input,
body.high-contrast select,
body.high-contrast textarea {
    border: 2px solid var(--text-color);
}

body.high-contrast input:focus,
body.high-contrast select:focus,
body.high-contrast textarea:focus {
    border-color: var(--accent-color);
    outline: 2px solid var(--accent-color);
}

body.high-contrast .progress-bar {
    border: 2px solid var(--text-color);
}

body.high-contrast .chat-tab {
    border: 2px solid var(--dim-color);
}

body.high-contrast .chat-tab.active {
    border-color: var(--accent-color);
}

body.high-contrast .panel {
    border: 2px solid var(--text-color);
    overflow: hidden;
}

body.high-contrast .menu-link:focus,
body.high-contrast .menu-link.active {
    outline: 2px solid var(--text-color);
}

body.high-contrast .help-section-header {
    border: 2px solid var(--dim-color);
}

body.high-contrast .help-section.expanded .help-section-header {
    border-color: var(--accent-color);
}


/* ============================================
   ARIA LIVE REGION STYLING
   ============================================ */

/**
 * Screen reader announcement container
 * This element is visually hidden but announces to screen readers
 */
#sr-announcements {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ============================================
   LINK-STYLE BUTTONS
   ============================================ */

/**
 * Button that looks like a link (for semantic accessibility)
 */
.link-button {
    background: none;
    border: none;
    padding: 0;
    font: inherit;
    color: var(--accent-color);
    cursor: pointer;
    text-decoration: underline;
}

.link-button:hover {
    color: var(--text-color);
}

/* ============================================
   MODAL ACCESSIBILITY
   ============================================ */

/**
 * When a modal is open, hide the background from screen readers
 * using aria-hidden on the main app container
 */
[aria-hidden="true"] {
    /* Visual indication is not needed since this is for screen readers */
}

/**
 * Focus trap indicator (visual debug - normally not visible)
 */
.focus-trap-active {
    /* This class can be used for debugging focus trapping */
}
