/**
 * Animated Logo System for OutputLag Theme
 * 
 * @package OutputLag
 * @since 1.0.0
 */

/* Base Logo Structure - Mirror existing .site-title styles */
.site-logo {
    position: relative;
    display: inline-block;
    cursor: pointer;
    user-select: none;
}

.logo-container {
    position: relative;
    padding: 0;
}

.logo-text {
    font-family: var(--font-heading);
    font-size: var(--font-size-2xl);
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--color-primary-blue);
    display: flex;
    gap: 0.5em;
    position: relative;
    z-index: 2;
    margin: 0;
}

.logo-word {
    display: inline-flex;
    position: relative;
}

.letter {
    display: inline-block;
    position: relative;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    transform: translateZ(0); /* GPU acceleration trigger */
}

/* Idle floating animation - subtle and continuous */
.letter {
    animation: idleFloat 6s ease-in-out infinite;
    animation-delay: calc(var(--index) * 0.1s);
}

@keyframes idleFloat {
    0%, 100% { 
        transform: translateY(0) translateZ(0);
    }
    50% { 
        transform: translateY(-2px) translateZ(0);
    }
}

/* Effects layers - initially hidden */
.logo-effects {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 1;
}

.effect-layer {
    position: absolute;
    inset: 0;
    opacity: 0;
    will-change: opacity, transform;
}

/* Responsive sizing to match existing .site-title behavior */
@media (max-width: 767px) {
    .logo-text {
        font-size: var(--font-size-xl);
    }
}

/* Ensure compatibility with existing WordPress classes */
.site-title .site-logo {
    display: inline-block;
}

.site-title a {
    color: inherit;
    text-decoration: none;
}

.site-title a:hover {
    color: inherit;
    text-decoration: none;
}

/* ========================================
   SIGNATURE ANIMATION EFFECTS
   ======================================== */

/* 1. LAG EFFECT - RGB Split Animation */
.logo-lagging .letter {
    animation: lagEffect 2s ease-out;
    animation-delay: calc(var(--index) * 0.05s);
}

@keyframes lagEffect {
    0% { 
        transform: translateX(0) translateZ(0);
        opacity: 1;
    }
    10% {
        transform: translateX(0) translateZ(0);
        opacity: 1;
    }
    11% {
        transform: translateX(-5px) translateZ(0);
        opacity: 0.8;
    }
    13% {
        transform: translateX(3px) translateZ(0);
        opacity: 0.9;
    }
    15% {
        transform: translateX(-2px) translateZ(0);
        opacity: 0.95;
    }
    20%, 100% {
        transform: translateX(0) translateZ(0);
        opacity: 1;
    }
}

/* RGB split effect during lag */
.logo-lagging .logo-word::before,
.logo-lagging .logo-word::after {
    content: attr(data-text);
    position: absolute;
    top: 0;
    left: 0;
    opacity: 0.8;
    pointer-events: none;
}

.logo-lagging .logo-word::before {
    color: rgb(var(--rgb-primary-accent));
    animation: rgbShiftLeft 0.5s ease-out;
    z-index: -1;
}

.logo-lagging .logo-word::after {
    color: rgb(var(--rgb-secondary-accent));
    animation: rgbShiftRight 0.5s ease-out;
    z-index: -1;
}

@keyframes rgbShiftLeft {
    0% { transform: translateX(0) translateZ(0); }
    50% { transform: translateX(-3px) translateZ(0); }
    100% { transform: translateX(0) translateZ(0); }
}

@keyframes rgbShiftRight {
    0% { transform: translateX(0) translateZ(0); }
    50% { transform: translateX(3px) translateZ(0); }
    100% { transform: translateX(0) translateZ(0); }
}

/* 2. BUFFER LOADING EFFECT */
.effect-buffer {
    position: absolute;
    bottom: -5px;
    left: 0;
    width: 0;
    height: 2px;
    background: linear-gradient(90deg, 
        transparent 0%,
        rgb(var(--rgb-primary-accent)) 10%,
        rgb(var(--rgb-primary-accent)) 90%,
        transparent 100%
    );
    opacity: 0;
}

.logo-buffering .effect-buffer {
    animation: bufferLoad 3s ease-out;
}

@keyframes bufferLoad {
    0% {
        width: 0;
        opacity: 1;
    }
    80% {
        width: 100%;
        opacity: 1;
    }
    90% {
        width: 100%;
        opacity: 0.5;
    }
    100% {
        width: 100%;
        opacity: 0;
    }
}

/* Letters fade in sequentially during buffer */
.logo-buffering .letter {
    opacity: 0;
    animation: letterBuffer 0.5s ease-out forwards;
    animation-delay: calc(var(--index) * 0.1s + 0.5s);
}

@keyframes letterBuffer {
    from {
        opacity: 0;
        transform: translateY(5px) translateZ(0);
    }
    to {
        opacity: 1;
        transform: translateY(0) translateZ(0);
    }
}

/* 3. GLITCH BURST EFFECT */
.logo-glitching .logo-text {
    animation: glitchBurst 0.4s ease-out;
}

@keyframes glitchBurst {
    0%, 100% {
        text-shadow: none;
        transform: translate(0) translateZ(0);
    }
    20% {
        text-shadow: 
            -2px 0 rgb(var(--rgb-secondary-accent)),
            2px 0 rgb(var(--rgb-primary-accent));
        transform: translate(-2px, 0) translateZ(0);
    }
    40% {
        text-shadow: 
            2px 0 rgb(var(--rgb-tertiary-accent)),
            -2px 0 rgb(var(--rgb-secondary-accent));
        transform: translate(2px, 0) translateZ(0);
    }
    60% {
        text-shadow: 
            0 2px rgb(var(--rgb-primary-accent)),
            0 -2px rgb(var(--rgb-tertiary-accent));
        transform: translate(0, -1px) translateZ(0);
    }
}

/* Scanline effect during glitch */
.effect-glitch {
    background: repeating-linear-gradient(
        0deg,
        transparent,
        transparent 2px,
        rgba(var(--rgb-white), 0.05) 2px,
        rgba(var(--rgb-white), 0.05) 4px
    );
    opacity: 0;
}

.logo-glitching .effect-glitch {
    animation: scanlineGlitch 0.4s ease-out;
}

@keyframes scanlineGlitch {
    0%, 100% { 
        opacity: 0; 
        transform: translateY(0) translateZ(0);
    }
    50% { 
        opacity: 1; 
        transform: translateY(-2px) translateZ(0);
    }
}

/* 5. SUBTLE SHAKE ANIMATION - Every 5-10 seconds */
.logo-container {
    animation: subtleShake 8s ease-in-out infinite;
}

@keyframes subtleShake {
    0%, 94%, 100% { 
        transform: translateX(0) translateZ(0);
    }
    95% { 
        transform: translateX(-0.5px) translateZ(0);
    }
    96% { 
        transform: translateX(0.5px) translateZ(0);
    }
    97% { 
        transform: translateX(-0.5px) translateZ(0);
    }
    98% { 
        transform: translateX(0.5px) translateZ(0);
    }
    99% { 
        transform: translateX(0) translateZ(0);
    }
}

/* ========================================
   ENHANCED HOVER EFFECTS
   ======================================== */

/* Pause idle animations during hover */
.logo-container:hover .letter {
    animation-play-state: paused;
}

/* Letter separation on hover - odd/even pattern */
.logo-container:hover .letter {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.logo-container:hover .letter:nth-child(odd) {
    transform: translateY(-4px) translateZ(0);
    color: rgb(var(--rgb-primary-accent));
}

.logo-container:hover .letter:nth-child(even) {
    transform: translateY(4px) translateZ(0);
    color: rgb(var(--rgb-secondary-accent));
}

/* Subtle glow backdrop on hover */
.logo-container::after {
    content: '';
    position: absolute;
    inset: -20px;
    background: radial-gradient(
        circle at center,
        rgba(var(--rgb-primary-accent), 0.1) 0%,
        rgba(var(--rgb-secondary-accent), 0.05) 30%,
        transparent 70%
    );
    opacity: 0;
    transition: opacity 0.4s ease;
    pointer-events: none;
    z-index: -1;
    border-radius: 12px;
}

.logo-container:hover::after {
    opacity: 1;
}

/* Enhanced word separation on hover */
.logo-container:hover .logo-word:first-child {
    transform: translateX(-2px) translateZ(0);
}

.logo-container:hover .logo-word:last-child {
    transform: translateX(2px) translateZ(0);
}

/* Smooth color transitions */
.logo-word {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Logo container scaling effect - needs to work with shake animation */
.logo-container {
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.logo-container:hover {
    transform: scale(1.05) translateZ(0);
    animation-play-state: paused; /* Pause shake during hover */
}

/* ========================================
   MOBILE OPTIMIZATION & ACCESSIBILITY
   ======================================== */

/* Mobile optimizations - simplified animations for performance */
@media (max-width: 768px) {
    /* Reduce font size for mobile */
    .logo-text {
        font-size: var(--font-size-xl);
    }
    
    /* Disable complex effects on mobile for performance */
    .logo-lagging .logo-word::before,
    .logo-lagging .logo-word::after {
        display: none;
    }
    
    /* Simplify glitch effect on mobile */
    .logo-glitching .logo-text {
        animation: simpleGlitch 0.3s ease-out;
    }
    
    @keyframes simpleGlitch {
        0%, 100% { 
            opacity: 1; 
            transform: translateZ(0);
        }
        50% { 
            opacity: 0.8; 
            transform: translateZ(0);
        }
    }
    
    /* Disable effects layers on mobile */
    .effect-glitch,
    .effect-buffer {
        display: none;
    }
    
    /* Simplified hover effects on mobile */
    .logo-container:hover .letter:nth-child(odd) {
        transform: translateY(-2px) translateZ(0);
    }
    
    .logo-container:hover .letter:nth-child(even) {
        transform: translateY(2px) translateZ(0);
    }
    
    /* Reduce scaling on mobile */
    .logo-container:hover {
        transform: scale(1.02) translateZ(0);
    }
    
    /* Reduce shake intensity on mobile */
    .logo-container {
        animation: mobileSubtleShake 8s ease-in-out infinite;
    }
    
    @keyframes mobileSubtleShake {
        0%, 96%, 100% { 
            transform: translateX(0) translateZ(0);
        }
        97% { 
            transform: translateX(-0.25px) translateZ(0);
        }
        98% { 
            transform: translateX(0.25px) translateZ(0);
        }
        99% { 
            transform: translateX(0) translateZ(0);
        }
    }
    
    /* Shorter animation durations on mobile */
    .letter {
        animation-duration: 4s; /* Reduced from 6s */
    }
}

/* Tablet optimizations */
@media (min-width: 769px) and (max-width: 1024px) {
    /* Slightly reduced effects for tablet performance */
    .logo-container:hover {
        transform: scale(1.03) translateZ(0);
    }
    
    /* Reduce glow intensity on tablet */
    .logo-container::after {
        background: radial-gradient(
            circle at center,
            rgba(var(--rgb-primary-accent), 0.05) 0%,
            rgba(var(--rgb-secondary-accent), 0.025) 30%,
            transparent 70%
        );
    }
}

/* Reduced motion accessibility support */
@media (prefers-reduced-motion: reduce) {
    /* Disable all animations */
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
    
    /* Reset logo animations */
    .letter {
        animation: none !important;
        transform: translateZ(0) !important;
    }
    
    /* Disable all signature animations */
    .logo-lagging .letter,
    .logo-buffering .letter,
    .logo-glitching .logo-text {
        animation: none !important;
    }
    
    /* Disable shake animation in reduced motion */
    .logo-container {
        animation: none !important;
    }
    
    /* Disable hover animations */
    .logo-container:hover .letter:nth-child(odd),
    .logo-container:hover .letter:nth-child(even) {
        transform: translateZ(0) !important;
    }
    
    /* Disable effects */
    .effect-glitch,
    .effect-buffer {
        display: none !important;
    }
    
    /* Maintain color changes but remove transforms */
    .logo-container:hover .letter:nth-child(odd) {
        color: rgb(var(--rgb-primary-accent));
        transform: translateZ(0) !important;
    }
    
    .logo-container:hover .letter:nth-child(even) {
        color: rgb(var(--rgb-secondary-accent));
        transform: translateZ(0) !important;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .logo-text {
        color: rgb(var(--rgb-white));
        text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
    }
    
    /* Remove subtle effects in high contrast mode */
    .logo-container::after {
        display: none;
    }
    
    /* Ensure readability during all animation states */
    .logo-lagging .letter,
    .logo-buffering .letter,
    .logo-glitching .letter {
        color: rgb(var(--rgb-white)) !important;
        text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8) !important;
    }
}

/* Focus management for accessibility */
.logo-container:focus-visible {
    outline: 2px solid rgb(var(--rgb-primary-accent));
    outline-offset: 4px;
    border-radius: 8px;
}

/* Screen reader optimizations */
.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;
}

/* Ensure logo remains readable during all states */
.logo-text .letter {
    min-height: 1.2em; /* Prevent layout shift during animations */
}

/* Low-end device optimizations */
@media (max-width: 480px) and (max-resolution: 1.5dppx) {
    /* Further simplify for very low-end devices */
    .letter {
        animation: none !important;
    }
    
    .logo-container {
        animation: none !important;
    }
    
    .logo-container:hover {
        transform: none !important;
    }
    
    /* Only allow basic color changes */
    .logo-container:hover .letter {
        transition: color 0.2s ease;
    }
}