/**
 * Accessibility and Performance CSS
 * Ensures proper accessibility and respects user motion preferences
 */

/* Reduced Motion Preferences */
@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;
    }
    
    /* Hide decorative animations for reduced motion users */
              .reduced-motion .particle-canvas,
    .reduced-motion #three-container,
    .reduced-motion #transform-canvas {
        display: none !important;
    }
    
    /* Ensure content is visible without animations */
    .reduced-motion .hero-text .first,
    .reduced-motion .hero-text .second,
    .reduced-motion .hero-text .third,
    .reduced-motion .hero-text .hero-cta,
    .reduced-motion .main-nav,
    .reduced-motion .nav-logo,
    .reduced-motion .theme-toggle,
    .reduced-motion .section-title,
    .reduced-motion .project-card,
    .reduced-motion .feature-card,
    .reduced-motion .timeline-content,
    .reduced-motion .highlight-card {
        opacity: 1 !important;
        transform: none !important;
        visibility: visible !important;
    }
}

/* Screen Reader Only Content */
.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;
}

/* High Contrast Mode Support */
@media (prefers-contrast: high) {
    .project-card,
    .feature-card,
    .timeline-content,
    .highlight-card {
        border: 2px solid currentColor;
    }
    
    .nav-link,
    .side-nav-dot {
        border: 1px solid currentColor;
    }
}

/* Loading Indicators */
.loading-indicator {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 2rem;
    border-radius: 12px;
    display: flex;
    align-items: center;
    gap: 1rem;
    z-index: 10000;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    backdrop-filter: blur(5px);
}

.spinner {
    width: 24px;
    height: 24px;
    border: 2px solid transparent;
    border-top: 2px solid currentColor;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Respect animation preferences for spinner */
@media (prefers-reduced-motion: reduce) {
    .spinner {
        animation: none;
        border: 2px solid currentColor;
        border-radius: 2px;
    }
}

/* Error Messages */
.error-message,
.init-error {
    position: fixed;
    top: 20px;
    right: 20px;
    background: rgba(220, 53, 69, 0.1);
    border: 1px solid rgba(220, 53, 69, 0.3);
    color: #dc3545;
    padding: 1rem;
    border-radius: 8px;
    max-width: 300px;
    font-size: 0.9rem;
    z-index: 10000;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(10px);
}

.error-message::before,
.init-error::before {
    content: '⚠️ ';
    margin-right: 0.5rem;
}

/* Mobile Menu Accessibility */
/* Usuń lub skomentuj te style, które powodują konflikt: */
/*
.mobile-menu-btn[aria-expanded="true"] .hamburger-line:nth-child(1) {
    transform: rotate(45deg) translate(6px, 6px);
}

.mobile-menu-btn[aria-expanded="true"] .hamburger-line:nth-child(2) {
    opacity: 0;
}

.mobile-menu-btn[aria-expanded="true"] .hamburger-line:nth-child(3) {
    transform: rotate(-45deg) translate(6px, -6px);
}
*/

/* Theme Toggle Accessibility */
.theme-toggle[aria-checked="true"]::after {
    content: ' (Light mode active)';
    position: absolute;
    left: -9999px;
}

.theme-toggle[aria-checked="false"]::after {
    content: ' (Dark mode active)';
    position: absolute;
    left: -9999px;
}

/* Navigation Accessibility */
.side-nav-dot[aria-selected="true"] {
    transform: scale(1.2);
}

.nav-link[aria-current="page"] {
    font-weight: bold;
}

/* Keyboard Navigation */
.nav-links[role="menubar"] {
    display: flex;
    list-style: none;
}

/* Performance Optimizations */
.will-change-transform {
    will-change: transform;
}

.will-change-opacity {
    will-change: opacity;
}

/* Remove will-change after animations complete */
.animation-complete {
    will-change: auto;
}

/* Minimal Performance Mode */
.minimal-performance .project-card:nth-child(n+4),
.minimal-performance .timeline-item:nth-child(n+4),
.minimal-performance .feature-card:nth-child(n+4) {
    opacity: 0.7;
    transform: none !important;
}

/* Loading State Management */
body:not(.loaded) .hero-text,
body:not(.loaded) .main-nav {
    opacity: 0;
}

/* Emergency fallback - tylko jeśli GSAP nie załadował się */
.no-js .section-title,
.reduced-motion .section-title {
    opacity: 1 !important;
    visibility: visible !important;
}

/* Zapewnij bazową widoczność tytułów przed GSAP */
.section-title {
    opacity: 1;
    visibility: visible;
}

/* Print Styles */
@media print {
    .mobile-menu-btn,
    .theme-toggle,
    .side-nav,
    #three-container,
    #canvas,
    #transform-canvas,
    .loading-indicator,
    .error-message {
        display: none !important;
    }
    
    .hero-text,
    .section-title,
    .project-card,
    .timeline-content {
        opacity: 1 !important;
        transform: none !important;
        break-inside: avoid;
    }
}

/* Dark Mode Optimizations */
@media (prefers-color-scheme: dark) {
    .loading-indicator {
        background: rgba(0, 0, 0, 0.9);
        border: 1px solid rgba(255, 255, 255, 0.2);
    }
    
    .error-message,
    .init-error {
        background: rgba(220, 53, 69, 0.2);
        color: #ff6b7a;
    }
}

/* Light Mode Overrides */
body.light-mode .loading-indicator {
    background: rgba(255, 255, 255, 0.9);
    color: #333;
    border: 1px solid rgba(0, 0, 0, 0.1);
}

body.light-mode .error-message,
body.light-mode .init-error {
    background: rgba(220, 53, 69, 0.1);
    color: #dc3545;
}

/* Animation Performance Optimizations */
@media (max-width: 768px) {
    /* Reduce animations on mobile for better performance */
    .project-card,
    .timeline-content,
    .feature-card {
        transition-duration: 0.2s;
    }
}

/* Battery Saving Mode */
@media (prefers-reduced-data: reduce) {
    /* Disable heavy animations when user prefers reduced data */
    #three-container,
    #canvas,
    #transform-canvas {
        display: none !important;
    }
}

/* Memory Conservation */
.memory-optimized .project-card:nth-child(n+6),
.memory-optimized .timeline-item:nth-child(n+6) {
    display: none;
}

/* Progressive Enhancement Fallbacks */
.no-js .hero-text,
.no-js .section-title,
.no-js .project-card,
.no-js .timeline-content {
    opacity: 1 !important;
    transform: none !important;
    visibility: visible !important;
}

/* Fix: Make main-nav visible but don't override children's opacity */
.no-js .main-nav {
    opacity: 1 !important;
    visibility: visible !important;
}

/* Don't interfere with nav-link and nav-logo hover effects */
.no-js .nav-link,
.no-js .nav-logo {
    opacity: 0.7; /* Default opacity - allow hover to work */
}

.no-js .mobile-menu-btn {
    display: none;
}

.no-js .nav-links {
    display: flex !important;
}

/* Utility Classes */
.visually-hidden {
    position: absolute !important;
    overflow: hidden !important;
    width: 1px !important;
    height: 1px !important;
    margin: -1px !important;
    padding: 0 !important;
    border: 0 !important;
    clip: rect(0 0 0 0) !important;
    word-wrap: normal !important;
}

.visually-hidden.focusable:active,
.visually-hidden.focusable:focus {
    position: static !important;
    overflow: visible !important;
    width: auto !important;
    height: auto !important;
    margin: 0 !important;
    clip: auto !important;
} 