/* Accessibility styles for KKIM.
 *
 * WCAG 2.2 AA improvements:
 *   1. Focus visible (high-contrast, consistent across browsers)
 *   2. Skip-link target main-content (already in head.php)
 *   3. prefers-reduced-motion: kill non-essential animations
 *   4. prefers-color-scheme respected in focus rings
 *   5. prefers-contrast: more mode
 *   6. Forced colors mode (Windows High Contrast) compatibility
 *   7. Touch target sizing (44x44 minimum for WCAG 2.5.5)
 *   8. Screen-reader-only text utility
 *   9. Better focus trap in modals (visual only; logic in JS)
 *  10. Reduced motion overrides keyframes
 */

/* -------------------------------------------------------------------------
   1. GLOBAL FOCUS RING
   - 3px solid primary, 3px offset
   - On dark theme: lighter gold for contrast
   ------------------------------------------------------------------------- */
:focus {
    outline: none;
}
:focus-visible {
    outline: 3px solid var(--primary, #d4af37);
    outline-offset: 3px;
    border-radius: 4px;
    transition: outline-offset 0.15s ease;
}
[data-theme="light"] :focus-visible {
    outline-color: var(--primary, #b8941f);
}
button:focus-visible,
a:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
[tabindex]:focus-visible,
summary:focus-visible {
    outline: 3px solid var(--primary, #d4af37);
    outline-offset: 3px;
}

/* Audio/video player controls use inline SVGs; ensure they're focusable */
button svg,
a svg {
    pointer-events: none;
}

/* -------------------------------------------------------------------------
   2. SCREEN-READER-ONLY UTILITY (more powerful than Tailwind's sr-only)
   ------------------------------------------------------------------------- */
.visually-hidden,
.sr-only {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}
.visually-hidden-focusable:not(:focus):not(:focus-within),
.sr-only-focusable:not(:focus):not(:focus-within) {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

/* -------------------------------------------------------------------------
   3. SKIP-LINK (defined here, used in head.php)
   ------------------------------------------------------------------------- */
.skip-link {
    position: fixed;
    top: -100px;
    left: 8px;
    z-index: 200;
    padding: 12px 20px;
    background: var(--primary, #d4af37);
    color: var(--primary-foreground, #0a0e1e);
    text-decoration: none;
    font-weight: 600;
    border-radius: 0 0 8px 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    transition: top 0.2s ease;
}
.skip-link:focus,
.skip-link:focus-visible {
    top: 0;
    outline: 3px solid var(--foreground, #f0f0f0);
    outline-offset: 2px;
}

/* -------------------------------------------------------------------------
   4. REDUCED MOTION
   - Kill transitions, animations, transforms that aren't essential
   - Keep the page readable (no infinite scroll effects, no parallax)
   ------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
        transition-delay: 0ms !important;
        scroll-behavior: auto !important;
    }
    .animate-in,
    [data-animate] {
        opacity: 1 !important;
        transform: none !important;
    }
    .parallax,
    [data-parallax] {
        transform: none !important;
    }
    /* Magnetic buttons: don't follow cursor */
    .magnetic-btn {
        transform: none !important;
    }
    /* Hide decorative pulsing */
    .pulse-logo {
        animation: none !important;
    }
    /* The page loader: don't block on reduced motion */
    .page-loader {
        transition: none !important;
    }
    /* Audio/video player seek: don't auto-seek on hover effects */
    #progress-bar > div {
        transition: none !important;
    }
}

/* -------------------------------------------------------------------------
   5. PREFERS-CONTRAST: MORE
   - Strengthen borders, raise text contrast
   ------------------------------------------------------------------------- */
@media (prefers-contrast: more) {
    :root {
        --border: rgba(255, 255, 255, 0.4);
        --muted-foreground: #b0b0b0;
    }
    [data-theme="light"] {
        --border: rgba(0, 0, 0, 0.4);
        --muted-foreground: #404040;
    }
    :focus-visible {
        outline-width: 4px;
    }
    a {
        text-decoration: underline;
    }
}

/* -------------------------------------------------------------------------
   6. FORCED COLORS MODE (Windows High Contrast)
   - Use system colors
   - Force borders on focus
   ------------------------------------------------------------------------- */
@media (forced-colors: active) {
    :focus-visible {
        outline: 3px solid CanvasText !important;
    }
    .skip-link {
        background: CanvasText;
        color: Canvas;
        border: 2px solid Canvas;
    }
    button,
    a,
    input,
    select,
    textarea {
        border: 1px solid CanvasText;
    }
    .video-modal,
    .modal-2fa {
        border: 2px solid CanvasText;
    }
    .kkim-pwa-fab,
    .kkim-update-banner {
        background: Canvas;
        color: CanvasText;
        border: 2px solid CanvasText;
    }
    svg {
        forced-color-adjust: auto;
    }
}

/* -------------------------------------------------------------------------
   7. TOUCH TARGET SIZING (WCAG 2.5.5 AAA = 44x44)
   - Apply to small interactive elements: icon-only buttons
   ------------------------------------------------------------------------- */
@media (pointer: coarse) {
    .theme-toggle,
    #mobile-menu-btn,
    .kkim-pwa-fab,
    .video-modal-close,
    #player-play-pause,
    #player-rewind,
    #player-forward,
    #player-close,
    #video-modal-close,
    #kkim-install-btn,
    #scroll-to-top {
        min-width: 44px;
        min-height: 44px;
    }
    .mobile-dropdown-toggle,
    .mobile-sub-toggle {
        min-height: 44px;
    }
    a.btn,
    button.btn,
    .btn-press {
        min-height: 44px;
        padding-top: 12px;
        padding-bottom: 12px;
    }
}

/* -------------------------------------------------------------------------
   8. SCROLL-LOCK when modal open (also via JS body class)
   ------------------------------------------------------------------------- */
body.modal-open,
body.menu-open,
body.player-open {
    overflow: hidden;
}

/* -------------------------------------------------------------------------
   9. ANCHOR TARGET OFFSET (fixed headers break jump links)
   ------------------------------------------------------------------------- */
[id]:not(body):not(html) {
    scroll-margin-top: 100px;
}

/* -------------------------------------------------------------------------
   10. ARIA-LIVE POLITENESS (visually subtle)
   - Status messages should be visible when announced
   ------------------------------------------------------------------------- */
[role="status"]:not(:empty),
[aria-live="polite"]:not(:empty) {
    padding: 8px 12px;
}

/* -------------------------------------------------------------------------
   11. BETTER TABLE ACCESSIBILITY
   ------------------------------------------------------------------------- */
table {
    border-collapse: collapse;
}
table th,
table td {
    padding: 8px 12px;
    border: 1px solid var(--border, rgba(255, 255, 255, 0.1));
}

/* -------------------------------------------------------------------------
   12. FORM LABELS
   - Make sure every input has a label
   - Required field indicator
   ------------------------------------------------------------------------- */
label.required::after,
.form-group.required > label::after {
    content: " *";
    color: var(--primary, #d4af37);
    font-weight: bold;
    margin-left: 2px;
}
input[aria-invalid="true"],
textarea[aria-invalid="true"],
select[aria-invalid="true"] {
    border-color: #ef4444;
    outline-color: #ef4444;
}
.error-message {
    color: #fca5a5;
    font-size: 0.875rem;
    margin-top: 4px;
}
[data-theme="light"] .error-message {
    color: #b91c1c;
}

/* -------------------------------------------------------------------------
   13. TRANSCRIPT PARTIAL
   - Collapsible details/summary
   - Time-stamped lines, readable typography
   ------------------------------------------------------------------------- */
.transcript {
    margin: 1.5rem 0;
}
.transcript-details {
    border: 1px solid var(--border, rgba(255, 255, 255, 0.1));
    border-radius: 0.5rem;
    background: var(--card, rgba(255, 255, 255, 0.03));
}
.transcript-summary {
    padding: 12px 16px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 8px;
    user-select: none;
}
.transcript-summary::-webkit-details-marker {
    display: none;
}
.transcript-summary::after {
    content: '+';
    margin-left: auto;
    font-weight: bold;
    transition: transform 0.2s ease;
}
.transcript-details[open] > .transcript-summary::after {
    transform: rotate(45deg);
}
.transcript-body {
    padding: 12px 16px 16px;
    border-top: 1px solid var(--border, rgba(255, 255, 255, 0.1));
}
.transcript-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.transcript-line {
    display: grid;
    grid-template-columns: 60px 1fr;
    gap: 12px;
    font-size: 0.875rem;
    line-height: 1.5;
}
.transcript-time {
    color: var(--primary, #d4af37);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.75rem;
    align-self: start;
    padding-top: 2px;
}
.transcript-text {
    color: var(--foreground, #f0f0f0);
}

/* -------------------------------------------------------------------------
   14. VIDEO MODAL LOADING
   ------------------------------------------------------------------------- */
.video-modal-loading {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.5);
}
.video-modal-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid rgba(255, 255, 255, 0.2);
    border-top-color: var(--primary, #d4af37);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}
@media (prefers-reduced-motion: reduce) {
    .video-modal-spinner {
        animation-duration: 3s;
    }
}

/* Legal page typography */
.prose-legal h2 {
    color: var(--foreground, hsl(var(--foreground)));
    border-bottom: 1px solid var(--border, hsl(var(--border)));
    padding-bottom: 0.5rem;
}
.prose-legal a {
    color: var(--primary, #d4af37);
    text-decoration: underline;
    text-underline-offset: 2px;
}
.prose-legal a:hover,
.prose-legal a:focus-visible {
    text-decoration-thickness: 2px;
}
.prose-legal ul,
.prose-legal ol {
    padding-left: 1.25rem;
}
.prose-legal li {
    margin-bottom: 0.25rem;
}
.prose-legal strong {
    color: var(--foreground, hsl(var(--foreground)));
    font-weight: 600;
}

/* Language switcher (text list - legacy, kept for backward compat) */
.kkim-lang-switcher,
.kkim-lang-switcher-mobile {
    display: inline-flex;
    list-style: none;
    margin: 0;
    padding: 0;
    gap: 0.25rem;
    align-items: center;
}
.kkim-lang-switcher a,
.kkim-lang-switcher-mobile a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 36px;
    padding: 0.25rem 0.5rem;
    border-radius: 0.375rem;
    font-size: 0.75rem;
    font-weight: 500;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--muted-foreground, #9ca3af);
    text-decoration: none;
    transition: color 0.15s, background-color 0.15s;
}
.kkim-lang-switcher a:hover,
.kkim-lang-switcher-mobile a:hover,
.kkim-lang-switcher a:focus-visible,
.kkim-lang-switcher-mobile a:focus-visible {
    color: var(--primary, #d4af37);
}
.kkim-lang-switcher a.is-active,
.kkim-lang-switcher-mobile a.is-active {
    color: var(--primary-foreground, #0f121e);
    background-color: var(--primary, #d4af37);
}

/* Language toggle (single icon button - preferred) */
.kkim-lang-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    min-height: 36px;
    padding: 0.375rem 0.75rem;
    border-radius: 9999px;
    border: 1px solid var(--border, rgba(255, 255, 255, 0.1));
    background-color: transparent;
    color: var(--muted-foreground, #9ca3af);
    text-decoration: none;
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    line-height: 1;
    transition: color 0.15s, background-color 0.15s, border-color 0.15s, transform 0.1s;
}
.kkim-lang-toggle:hover,
.kkim-lang-toggle:focus-visible {
    color: var(--primary, #d4af37);
    border-color: var(--primary, #d4af37);
    background-color: rgba(212, 175, 55, 0.08);
    outline: none;
}
.kkim-lang-toggle:active {
    transform: scale(0.97);
}
.kkim-lang-toggle-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.kkim-lang-toggle-icon svg {
    width: 1em;
    height: 1em;
    flex-shrink: 0;
}
.kkim-lang-toggle-code {
    font-variant-numeric: tabular-nums;
}
.kkim-lang-toggle-sr {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}
.kkim-lang-toggle-mobile {
    width: 100%;
    justify-content: center;
    padding: 0.75rem 1rem;
    min-height: 44px;
    font-size: 0.8125rem;
    border-radius: 0.5rem;
}
