/* Performance and Accessibility Optimizations for PiyVpn.ru */

/* Respect user's 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;
    }
    
    /* Disable parallax and complex animations */
    .tech-grid,
    .floating-elements,
    .particle-system {
        animation: none !important;
        transform: none !important;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    :root {
        --color-bg-primary: #000000;
        --color-bg-secondary: #111111;
        --color-bg-tertiary: #222222;
        --color-bg-card: #333333;
        --color-text-primary: #ffffff;
        --color-text-secondary: #ffffff;
        --color-text-muted: #cccccc;
        --color-accent-electric: #00aaff;
        --color-accent-cyan: #00ffff;
        --color-accent-green: #00ff00;
    }
    
    /* Increase border visibility */
    .btn,
    .form-input,
    .profile-card,
    .feature-card {
        border-width: 2px !important;
    }
}

/* Performance optimizations */
.performance-optimized {
    /* Use GPU acceleration for smooth animations */
    transform: translateZ(0);
    will-change: transform, opacity;
    backface-visibility: hidden;
    perspective: 1000px;
}

/* Optimize animations for 60fps */
@keyframes optimizedFadeIn {
    from {
        opacity: 0;
        transform: translate3d(0, 20px, 0);
    }
    to {
        opacity: 1;
        transform: translate3d(0, 0, 0);
    }
}

@keyframes optimizedSlideUp {
    from {
        opacity: 0;
        transform: translate3d(0, 30px, 0);
    }
    to {
        opacity: 1;
        transform: translate3d(0, 0, 0);
    }
}

@keyframes optimizedGlow {
    0%, 100% {
        box-shadow: 0 0 20px rgba(42, 140, 255, 0.3);
    }
    50% {
        box-shadow: 0 0 40px rgba(42, 140, 255, 0.6);
    }
}

/* Efficient loading animations */
@keyframes efficientSpin {
    to {
        transform: rotate(360deg);
    }
}

.loading-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top: 2px solid var(--color-accent-electric);
    border-radius: 50%;
    animation: efficientSpin 1s linear infinite;
    will-change: transform;
}

/* Accessibility improvements */
.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;
}

/* Focus indicators */
.focus-visible,
*:focus-visible {
    outline: 2px solid var(--color-accent-electric);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

/* Skip to content link */
.skip-link {
    position: absolute;
    top: -40px;
    left: 6px;
    background: var(--color-accent-electric);
    color: white;
    padding: 8px;
    text-decoration: none;
    border-radius: var(--radius-sm);
    z-index: 1000;
    transition: top var(--duration-fast) ease;
}

.skip-link:focus {
    top: 6px;
}

/* Improved button accessibility */
.btn {
    position: relative;
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.btn:disabled {
    cursor: not-allowed;
    opacity: 0.6;
}

.btn:focus-visible {
    outline: 2px solid var(--color-accent-electric);
    outline-offset: 2px;
}

/* Form accessibility */
.form-input:focus-visible {
    outline: 2px solid var(--color-accent-electric);
    outline-offset: 2px;
}

.form-error {
    color: #ff6b6b;
    font-size: 0.875rem;
    margin-top: var(--space-xs);
    display: flex;
    align-items: center;
    gap: var(--space-xs);
}

.form-error::before {
    content: '⚠';
    font-size: 1rem;
}

.form-success {
    color: var(--color-accent-green);
    font-size: 0.875rem;
    margin-top: var(--space-xs);
    display: flex;
    align-items: center;
    gap: var(--space-xs);
}

.form-success::before {
    content: '✓';
    font-size: 1rem;
}

/* ARIA live regions */
.live-region {
    position: absolute;
    left: -10000px;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

/* Notification accessibility */
.notification {
    role: alert;
    aria-live: polite;
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-md);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-sm);
    animation: optimizedSlideUp var(--duration-normal) ease;
}

.notification-success {
    background: rgba(81, 207, 102, 0.1);
    border: 1px solid var(--color-accent-green);
    color: var(--color-accent-green);
}

.notification-error {
    background: rgba(255, 107, 107, 0.1);
    border: 1px solid #ff6b6b;
    color: #ff6b6b;
}

.notification-info {
    background: rgba(42, 140, 255, 0.1);
    border: 1px solid var(--color-accent-electric);
    color: var(--color-accent-electric);
}

/* Performance optimized hover effects */
.hover-optimized {
    transition: transform var(--duration-fast) ease, box-shadow var(--duration-fast) ease;
    will-change: transform, box-shadow;
}

.hover-optimized:hover {
    transform: translateY(-2px);
}

/* Lazy loading optimization */
.lazy-load {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity var(--duration-normal) ease, transform var(--duration-normal) ease;
}

.lazy-load.loaded {
    opacity: 1;
    transform: translateY(0);
}

/* Mobile performance optimizations */
@media (max-width: 768px) {
    /* Reduce animation complexity on mobile */
    .complex-animation {
        animation: none;
    }
    
    /* Optimize touch targets */
    .btn,
    .nav-link,
    .form-input {
        min-height: 44px;
        min-width: 44px;
    }
    
    /* Reduce motion on mobile for battery life */
    * {
        animation-duration: 0.2s;
        transition-duration: 0.2s;
    }
    
    /* Optimize background for mobile */
    body {
        background-attachment: scroll;
        background-size: 20px 20px, 100% 100%;
    }
    
    /* Reduce shadow complexity for better performance */
    .shadow-elevated,
    .shadow-glow-strong {
        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
    }
    
    /* Optimize hover effects for touch devices */
    .btn:hover,
    .feature-card:hover,
    .nav-link:hover {
        transform: none;
    }
    
    /* Touch-specific interactions */
    .btn:active,
    .nav-link:active {
        transform: scale(0.98);
        transition: transform 0.1s ease;
    }
}

/* Mobile-first responsive font scaling */
@media (max-width: 480px) {
    html {
        font-size: 14px;
    }
    
    .hero-title {
        font-size: 2rem;
        line-height: 1.2;
    }
    
    .section-title {
        font-size: 1.75rem;
    }
    
    .btn-large {
        padding: var(--space-md) var(--space-lg);
        font-size: 1rem;
    }
}

/* Enhanced mobile navigation */
@media (max-width: 768px) {
    .nav-menu {
        position: fixed;
        top: 70px;
        left: 0;
        right: 0;
        background: rgba(10, 12, 21, 0.98);
        backdrop-filter: blur(20px);
        transform: translateY(-100%);
        opacity: 0;
        visibility: hidden;
        transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        z-index: 999;
        padding: var(--space-xl) var(--space-lg);
        flex-direction: column;
        gap: var(--space-lg);
        box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
    }
    
    .nav-menu.active {
        transform: translateY(0);
        opacity: 1;
        visibility: visible;
    }
    
    .nav-link {
        padding: var(--space-md) 0;
        font-size: 1.1rem;
        text-align: center;
        border-bottom: 1px solid rgba(42, 140, 255, 0.1);
        width: 100%;
    }
    
    .nav-link:last-child {
        border-bottom: none;
    }
    
    .nav-toggle {
        display: flex;
        flex-direction: column;
        gap: 4px;
        padding: var(--space-sm);
        cursor: pointer;
        border-radius: var(--radius-sm);
        transition: background-color 0.2s ease;
    }
    
    .nav-toggle:hover {
        background: rgba(42, 140, 255, 0.1);
    }
    
    .nav-toggle span {
        width: 25px;
        height: 3px;
        background: var(--color-text-primary);
        border-radius: 2px;
        transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        transform-origin: center;
    }
    
    .nav-toggle.active span:nth-child(1) {
        transform: rotate(45deg) translate(6px, 6px);
    }
    
    .nav-toggle.active span:nth-child(2) {
        opacity: 0;
        transform: scale(0);
    }
    
    .nav-toggle.active span:nth-child(3) {
        transform: rotate(-45deg) translate(6px, -6px);
    }
}

/* Print styles */
@media print {
    * {
        background: white !important;
        color: black !important;
        box-shadow: none !important;
        text-shadow: none !important;
    }
    
    .navbar,
    .footer,
    .btn,
    .notification {
        display: none !important;
    }
    
    .container {
        max-width: none !important;
        margin: 0 !important;
        padding: 0 !important;
    }
}

/* Dark mode support (system preference) */
@media (prefers-color-scheme: light) {
    /* Keep dark theme as default for high-tech look */
    /* Users can override if needed */
}

/* Keyboard navigation improvements */
.keyboard-nav *:focus {
    outline: 2px solid var(--color-accent-electric);
    outline-offset: 2px;
}

/* Loading state accessibility */
.loading[aria-busy="true"] {
    cursor: wait;
}

.loading[aria-busy="true"]::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top: 2px solid var(--color-accent-electric);
    border-radius: 50%;
    animation: efficientSpin 1s linear infinite;
}

/* Responsive font scaling */
@media (max-width: 480px) {
    html {
        font-size: 14px;
    }
}

@media (min-width: 1200px) {
    html {
        font-size: 18px;
    }
}

/* Content visibility optimization */
.content-section {
    content-visibility: auto;
    contain-intrinsic-size: 500px;
}

/* Intersection observer optimization */
.observe-intersection {
    opacity: 0;
    transform: translateY(50px);
    transition: opacity 0.6s ease, transform 0.6s ease;
}

.observe-intersection.in-view {
    opacity: 1;
    transform: translateY(0);
}