/* CSS Spider Animation - Guaranteed to Work */

.spider-web-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    z-index: 1;
    pointer-events: none;
    perspective: 1000px;
    perspective-origin: 50% 50%;
}

/* Animated Spider Web */
.spider-web {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 600px;
    height: 600px;
    animation: webRotate 60s linear infinite;
}

@keyframes webRotate {
    from { transform: translate(-50%, -50%) rotate(0deg); }
    to { transform: translate(-50%, -50%) rotate(360deg); }
}

/* Web Strands */
.web-strand {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 2px;
    height: 300px;
    background: linear-gradient(to bottom,
        transparent 0%,
        rgba(218, 30, 40, 0.4) 50%,
        transparent 100%);
    transform-origin: top center;
    animation: strandPulse 3s ease-in-out infinite;
}

@keyframes strandPulse {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 0.7; }
}

.web-strand:nth-child(1) { transform: rotate(0deg); }
.web-strand:nth-child(2) { transform: rotate(22.5deg); }
.web-strand:nth-child(3) { transform: rotate(45deg); }
.web-strand:nth-child(4) { transform: rotate(67.5deg); }
.web-strand:nth-child(5) { transform: rotate(90deg); }
.web-strand:nth-child(6) { transform: rotate(112.5deg); }
.web-strand:nth-child(7) { transform: rotate(135deg); }
.web-strand:nth-child(8) { transform: rotate(157.5deg); }

/* Circular Web Rings */
.web-ring {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    border: 1px solid rgba(218, 30, 40, 0.3);
    border-radius: 50%;
    animation: ringPulse 4s ease-in-out infinite;
}

@keyframes ringPulse {
    0%, 100% {
        opacity: 0.2;
        transform: translate(-50%, -50%) scale(1);
    }
    50% {
        opacity: 0.5;
        transform: translate(-50%, -50%) scale(1.05);
    }
}

.web-ring:nth-child(9) { width: 100px; height: 100px; animation-delay: 0s; }
.web-ring:nth-child(10) { width: 200px; height: 200px; animation-delay: 0.5s; }
.web-ring:nth-child(11) { width: 300px; height: 300px; animation-delay: 1s; }
.web-ring:nth-child(12) { width: 400px; height: 400px; animation-delay: 1.5s; }
.web-ring:nth-child(13) { width: 500px; height: 500px; animation-delay: 2s; }

/* Animated Spider - 3D */
.spider {
    position: absolute;
    top: 20%;
    left: -10%;
    width: 120px;
    height: 90px;
    z-index: 10;
    transform-style: preserve-3d;
    animation: spiderCrawl3D 20s linear infinite;
    filter: drop-shadow(0 10px 20px rgba(0, 0, 0, 0.5));
}

@keyframes spiderCrawl3D {
    0% {
        left: -10%;
        top: 20%;
        transform: rotateX(20deg) rotateY(0deg) rotateZ(0deg) scaleX(1);
    }
    15% {
        left: 30%;
        top: 15%;
        transform: rotateX(15deg) rotateY(-10deg) rotateZ(-5deg) scaleX(1);
    }
    25% {
        left: 50%;
        top: 10%;
        transform: rotateX(25deg) rotateY(5deg) rotateZ(0deg) scaleX(1);
    }
    30% {
        left: 50%;
        top: 60%;
        transform: rotateX(30deg) rotateY(0deg) rotateZ(90deg) scaleX(1);
    }
    45% {
        left: 70%;
        top: 70%;
        transform: rotateX(20deg) rotateY(15deg) rotateZ(45deg) scaleX(-1);
    }
    60% {
        left: 90%;
        top: 40%;
        transform: rotateX(15deg) rotateY(-5deg) rotateZ(-10deg) scaleX(-1);
    }
    75% {
        left: 110%;
        top: 25%;
        transform: rotateX(20deg) rotateY(10deg) rotateZ(5deg) scaleX(-1);
    }
    76% {
        left: 110%;
        top: 25%;
        transform: rotateX(20deg) rotateY(10deg) rotateZ(5deg) scaleX(-1);
        opacity: 1;
    }
    77% {
        left: -10%;
        top: 80%;
        transform: rotateX(20deg) rotateY(0deg) rotateZ(0deg) scaleX(1);
        opacity: 0;
    }
    78% {
        left: -10%;
        top: 80%;
        transform: rotateX(20deg) rotateY(0deg) rotateZ(0deg) scaleX(1);
        opacity: 1;
    }
    100% {
        left: -10%;
        top: 20%;
        transform: rotateX(20deg) rotateY(0deg) rotateZ(0deg) scaleX(1);
    }
}

/* Spider Body - 3D */
.spider-body {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 60px;
    height: 70px;
    transform-style: preserve-3d;
    transform: translate(-50%, -50%);
    animation: bodyPulse3D 2s ease-in-out infinite;
}

.spider-body::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(ellipse at 30% 30%, #2a0a0a 0%, #1a0505 40%, #0a0a0a 100%);
    border-radius: 50%;
    box-shadow:
        0 0 30px rgba(218, 30, 40, 0.6),
        inset -10px -10px 20px rgba(0, 0, 0, 0.8),
        inset 10px 10px 20px rgba(218, 30, 40, 0.2);
    transform: translateZ(20px);
}

.spider-body::after {
    content: '';
    position: absolute;
    top: 5px;
    left: 5px;
    width: calc(100% - 10px);
    height: calc(100% - 10px);
    background: radial-gradient(ellipse at 40% 40%, rgba(218, 30, 40, 0.3) 0%, transparent 60%);
    border-radius: 50%;
    transform: translateZ(25px);
}

@keyframes bodyPulse3D {
    0%, 100% {
        transform: translate(-50%, -50%) scale(1) rotateX(0deg);
    }
    50% {
        transform: translate(-50%, -50%) scale(1.05) rotateX(5deg);
    }
}

/* Spider Head - 3D */
.spider-head {
    position: absolute;
    top: -20px;
    left: 50%;
    width: 35px;
    height: 35px;
    transform-style: preserve-3d;
    transform: translateX(-50%) translateZ(15px);
    border-radius: 50%;
    background: radial-gradient(circle at 30% 30%, #2a0a0a 0%, #1a0505 40%, #0a0a0a 100%);
    box-shadow:
        0 0 20px rgba(218, 30, 40, 0.5),
        inset -5px -5px 10px rgba(0, 0, 0, 0.8),
        inset 5px 5px 10px rgba(218, 30, 40, 0.2);
}

.spider-head::before {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: calc(100% - 4px);
    height: calc(100% - 4px);
    background: radial-gradient(circle at 35% 35%, rgba(218, 30, 40, 0.3) 0%, transparent 60%);
    border-radius: 50%;
    transform: translateZ(5px);
}

/* Spider Eyes - 3D */
.spider-eye {
    position: absolute;
    width: 8px;
    height: 8px;
    background: radial-gradient(circle at 30% 30%, #ff4444 0%, #ff0000 50%, #aa0000 100%);
    border-radius: 50%;
    transform: translateZ(8px);
    box-shadow:
        0 0 10px #ff0000,
        0 0 20px #ff0000,
        inset -2px -2px 4px rgba(0, 0, 0, 0.5),
        inset 2px 2px 4px rgba(255, 100, 100, 0.3);
    animation: eyeGlow3D 2s ease-in-out infinite;
}

.spider-eye::before {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 3px;
    height: 3px;
    background: rgba(255, 255, 255, 0.8);
    border-radius: 50%;
    transform: translateZ(2px);
}

@keyframes eyeGlow3D {
    0%, 100% {
        box-shadow:
            0 0 10px #ff0000,
            0 0 20px #ff0000,
            inset -2px -2px 4px rgba(0, 0, 0, 0.5),
            inset 2px 2px 4px rgba(255, 100, 100, 0.3);
        opacity: 1;
        transform: translateZ(8px) scale(1);
    }
    50% {
        box-shadow:
            0 0 20px #ff0000,
            0 0 40px #ff0000,
            0 0 60px rgba(255, 0, 0, 0.5),
            inset -2px -2px 4px rgba(0, 0, 0, 0.5),
            inset 2px 2px 4px rgba(255, 100, 100, 0.3);
        opacity: 0.9;
        transform: translateZ(8px) scale(1.1);
    }
}

.spider-eye:nth-child(1) { top: 10px; left: 8px; }
.spider-eye:nth-child(2) { top: 10px; right: 8px; }

/* Spider Legs - 3D */
.spider-leg {
    position: absolute;
    width: 5px;
    height: 45px;
    background: linear-gradient(135deg, #0a0a0a 0%, #1a0505 50%, #0a0a0a 100%);
    border-radius: 3px;
    transform-origin: top center;
    transform-style: preserve-3d;
    box-shadow:
        2px 2px 4px rgba(0, 0, 0, 0.5),
        inset -1px -1px 2px rgba(0, 0, 0, 0.8),
        inset 1px 1px 2px rgba(218, 30, 40, 0.1);
}

.spider-leg::after {
    content: '';
    position: absolute;
    bottom: -38px;
    left: 0;
    width: 5px;
    height: 40px;
    background: linear-gradient(135deg, #1a0505 0%, #0a0a0a 50%, #1a0505 100%);
    border-radius: 3px;
    transform: rotate(45deg) translateZ(-5px);
    transform-origin: top center;
    box-shadow:
        2px 2px 4px rgba(0, 0, 0, 0.5),
        inset -1px -1px 2px rgba(0, 0, 0, 0.8),
        inset 1px 1px 2px rgba(218, 30, 40, 0.1);
}

.spider-leg::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    width: 2px;
    height: 100%;
    background: linear-gradient(to bottom, rgba(218, 30, 40, 0.3), transparent);
    transform: translateX(-50%) translateZ(1px);
    border-radius: 1px;
}

/* Left legs - 3D positioned */
.spider-leg:nth-child(3) {
    top: 15px;
    left: -5px;
    transform: rotate(-30deg) rotateY(-20deg) translateZ(10px);
    animation: legWalk1 2s ease-in-out infinite;
}

.spider-leg:nth-child(4) {
    top: 20px;
    left: -8px;
    transform: rotate(-45deg) rotateY(-15deg) translateZ(5px);
    animation: legWalk2 2s ease-in-out infinite;
}

.spider-leg:nth-child(5) {
    top: 25px;
    left: -10px;
    transform: rotate(-60deg) rotateY(-10deg) translateZ(0px);
    animation: legWalk1 2s ease-in-out infinite;
}

.spider-leg:nth-child(6) {
    top: 30px;
    left: -12px;
    transform: rotate(-75deg) rotateY(-5deg) translateZ(-5px);
    animation: legWalk2 2s ease-in-out infinite;
}

/* Right legs - 3D positioned */
.spider-leg:nth-child(7) {
    top: 15px;
    right: -5px;
    transform: rotate(30deg) rotateY(20deg) translateZ(10px);
    animation: legWalk2 2s ease-in-out infinite;
}

.spider-leg:nth-child(8) {
    top: 20px;
    right: -8px;
    transform: rotate(45deg) rotateY(15deg) translateZ(5px);
    animation: legWalk1 2s ease-in-out infinite;
}

.spider-leg:nth-child(9) {
    top: 25px;
    right: -10px;
    transform: rotate(60deg) rotateY(10deg) translateZ(0px);
    animation: legWalk2 2s ease-in-out infinite;
}

.spider-leg:nth-child(10) {
    top: 30px;
    right: -12px;
    transform: rotate(75deg) rotateY(5deg) translateZ(-5px);
    animation: legWalk1 2s ease-in-out infinite;
}

@keyframes legWalk1 {
    0%, 100% {
        transform: rotate(var(--base-rotation, 0deg)) translateY(0);
    }
    25% {
        transform: rotate(var(--base-rotation, 0deg)) translateY(-8px) translateX(-3px);
    }
    50% {
        transform: rotate(var(--base-rotation, 0deg)) translateY(-5px);
    }
    75% {
        transform: rotate(var(--base-rotation, 0deg)) translateY(-8px) translateX(3px);
    }
}

@keyframes legWalk2 {
    0%, 100% {
        transform: rotate(var(--base-rotation, 0deg)) translateY(-5px);
    }
    25% {
        transform: rotate(var(--base-rotation, 0deg)) translateY(-2px) translateX(3px);
    }
    50% {
        transform: rotate(var(--base-rotation, 0deg)) translateY(0);
    }
    75% {
        transform: rotate(var(--base-rotation, 0deg)) translateY(-2px) translateX(-3px);
    }
}

/* Silk Thread (appears when spider drops) */
.spider::before {
    content: '';
    position: absolute;
    top: -100vh;
    left: 50%;
    width: 1px;
    height: 100vh;
    background: linear-gradient(to bottom,
        transparent 0%,
        rgba(218, 30, 40, 0.3) 20%,
        rgba(218, 30, 40, 0.6) 80%,
        rgba(218, 30, 40, 0.8) 100%);
    transform: translateX(-50%);
    opacity: 0;
    animation: silkThread 20s linear infinite;
}

@keyframes silkThread {
    0%, 24%, 31%, 100% {
        opacity: 0;
    }
    25%, 30% {
        opacity: 1;
    }
}

/* Particle Effects */
.spider-particle {
    position: absolute;
    width: 3px;
    height: 3px;
    background: rgba(218, 30, 40, 0.6);
    border-radius: 50%;
    animation: particleFloat 10s linear infinite;
    pointer-events: none;
}

@keyframes particleFloat {
    0% {
        transform: translateY(0) translateX(0);
        opacity: 0;
    }
    10% {
        opacity: 1;
    }
    90% {
        opacity: 1;
    }
    100% {
        transform: translateY(-100vh) translateX(100px);
        opacity: 0;
    }
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .spider-web {
        width: 400px;
        height: 400px;
    }

    .web-strand {
        height: 200px;
    }

    .spider {
        width: 60px;
        height: 45px;
    }

    .spider-body {
        width: 30px;
        height: 40px;
    }

    .spider-leg {
        height: 25px;
    }

    .spider-leg::after {
        height: 20px;
    }
}
