/*
 * LaprdusTTS Website - Accessibility Stylesheet
 * ==============================================
 * WCAG 2.1 AA Compliance Features
 * - Skip links
 * - Focus indicators
 * - Screen reader utilities
 * - Reduced motion support
 * - Touch target sizing
 */

/* Skip Link - Hidden until focused */
.skip-link {
    position: absolute;
    top: -100%;
    left: var(--space-md);
    z-index: 9999;
    padding: var(--space-md) var(--space-lg);
    background-color: var(--color-primary);
    color: var(--color-text-inverse);
    text-decoration: none;
    font-weight: 700;
    border-radius: 0 0 var(--border-radius) var(--border-radius);
    transition: top 0.2s ease;
}

.skip-link:focus {
    top: 0;
    outline: 3px solid var(--color-focus);
    outline-offset: 2px;
}

/* Visually Hidden - Accessible to screen readers */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Show visually hidden on focus (for skip links etc) */
.visually-hidden.focusable:focus {
    position: static;
    width: auto;
    height: auto;
    margin: 0;
    overflow: visible;
    clip: auto;
    white-space: normal;
}

/* Focus Styles - High visibility */
:focus {
    outline: none;
}

:focus-visible {
    outline: 3px solid var(--color-focus);
    outline-offset: 2px;
    border-radius: 2px;
}

/* Ensure all interactive elements have visible focus */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible,
summary:focus-visible {
    outline: 3px solid var(--color-focus);
    outline-offset: 2px;
}

/* Focus within for complex components */
.nav-list li:focus-within {
    outline: 2px solid var(--color-focus);
    outline-offset: 2px;
}

/* Current page indicator - not just color */
[aria-current="page"] {
    font-weight: 700;
    position: relative;
}

/* Ensure links are distinguishable without relying on color alone */
a:not(.btn):not(.logo):not(.nav-list a) {
    text-decoration: underline;
}

/* Hover state that doesn't rely on color alone */
a:hover {
    text-decoration-thickness: 2px;
}

/* Minimum Touch Target Size - 44x44px */
a,
button,
input,
select,
textarea,
[role="button"],
summary {
    min-height: 44px;
}

/* For inline links, ensure adequate spacing */
p a,
li a {
    padding: var(--space-xs) 0;
    display: inline;
}

/* Button-like elements */
.btn,
button,
input[type="submit"],
input[type="button"],
input[type="reset"] {
    min-height: 44px;
    min-width: 44px;
    padding: var(--space-sm) var(--space-md);
}

/* Reduced Motion Preference */
@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;
    }
}

/* Line length for readability (45-75 characters recommended) */
p,
li,
dd {
    max-width: 70ch;
}

/* Spacing for dyslexia-friendly reading */
body {
    word-spacing: 0.05em;
    letter-spacing: 0.01em;
}

/* Paragraph spacing */
p + p {
    margin-top: 1.5em;
}

/* List item spacing */
li + li {
    margin-top: 0.5em;
}

/* Ensure images don't cause overflow */
img {
    max-width: 100%;
    height: auto;
}

/* Focus indicator for images that are links */
a img:focus-visible {
    outline: 3px solid var(--color-focus);
    outline-offset: 4px;
}

/* High Contrast Mode Enhancements */
@media (prefers-contrast: more), (prefers-contrast: high) {
    :focus-visible {
        outline: 3px solid currentColor;
        outline-offset: 3px;
    }

    a {
        text-decoration: underline;
        text-decoration-thickness: 2px;
    }

    .btn {
        border-width: 3px;
    }

    .feature-card,
    .download-card,
    .toc,
    .info-box,
    .news-post,
    .news-notes,
    .donate-section,
    .quick-link-item {
        border: 2px solid currentColor;
    }
}

/* Dark mode focus indicator adjustment */
@media (prefers-color-scheme: dark) {
    :focus-visible {
        outline-color: #ffd54f;
    }
}

/* Selection styling */
::selection {
    background-color: var(--color-primary);
    color: var(--color-text-inverse);
}

/* Target sizing for anchor links */
:target {
    scroll-margin-top: 2rem;
}

:target::before {
    content: "";
    display: block;
    height: 1rem;
}

/* Ensure form labels are associated visually */
label {
    display: block;
    margin-bottom: var(--space-sm);
    font-weight: 600;
}

/* Required field indicator */
.required::after {
    content: " *";
    color: var(--color-error);
}

/* Error state - not color alone */
.error {
    border-left: 4px solid var(--color-error);
    padding-left: var(--space-md);
}

.error::before {
    content: "Greška: ";
    font-weight: 700;
}

/* Success state - not color alone */
.success {
    border-left: 4px solid var(--color-success);
    padding-left: var(--space-md);
}

.success::before {
    content: "Uspjeh: ";
    font-weight: 700;
}

/* Abbreviations - indicate they have expansion */
abbr[title] {
    text-decoration: underline dotted;
    cursor: help;
}

/* Details/Summary accessible styling */
details {
    margin: var(--space-md) 0;
    padding: var(--space-md);
    background-color: var(--color-bg-alt);
    border-radius: var(--border-radius);
}

summary {
    cursor: pointer;
    font-weight: 600;
    padding: var(--space-sm);
    margin: calc(var(--space-md) * -1);
    margin-bottom: 0;
    list-style: none;
}

summary::-webkit-details-marker {
    display: none;
}

summary::before {
    content: "▸ ";
    display: inline-block;
    transition: transform 0.2s ease;
}

@media (prefers-reduced-motion: reduce) {
    summary::before {
        transition: none;
    }
}

details[open] summary::before {
    transform: rotate(90deg);
}

details[open] summary {
    margin-bottom: var(--space-md);
    border-bottom: 1px solid var(--color-text-muted);
    padding-bottom: var(--space-md);
}

/* Landmark regions announcement helper */
[role="main"]::before,
[role="navigation"]::before,
[role="banner"]::before,
[role="contentinfo"]::before {
    /* Empty - landmarks are announced by screen readers automatically */
}

/* Table accessibility */
table {
    border-collapse: collapse;
}

th {
    text-align: left;
    font-weight: 700;
}

th[scope="col"] {
    border-bottom: 2px solid var(--color-text);
}

th[scope="row"] {
    border-right: 2px solid var(--color-text);
}

caption {
    caption-side: top;
    text-align: left;
    font-weight: 700;
    padding: var(--space-md) 0;
}

/* Ensure no content is clipped when zoomed to 400% */
@media (min-width: 320px) {
    body {
        overflow-x: hidden;
    }

    .container {
        overflow-wrap: break-word;
        word-wrap: break-word;
    }
}

/* Print styles for accessibility */
@media print {
    .skip-link,
    nav,
    .no-print {
        display: none !important;
    }

    a[href]::after {
        content: " (" attr(href) ")";
        font-size: 0.8em;
    }

    a[href^="#"]::after,
    a[href^="javascript:"]::after {
        content: "";
    }
}
