/* ===================================
   Jungle Theme Backgrounds & Visuals
   =================================== */

.jungle-background {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    background: linear-gradient(135deg, #0d3d28 0%, #1a5f3a 50%, #2d8659 100%);
    overflow: hidden;
}

/* Night Mode Background */
body.night-mode .jungle-background {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f1419 100%);
}

/* Jungle Background Layers */
.jungle-background::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image:
        radial-gradient(circle at 20% 30%, rgba(76, 175, 80, 0.2) 0%, transparent 50%),
        radial-gradient(circle at 80% 60%, rgba(139, 90, 60, 0.15) 0%, transparent 50%),
        radial-gradient(circle at 50% 80%, rgba(45, 134, 89, 0.25) 0%, transparent 50%);
    animation: jungle-ambience 20s ease-in-out infinite;
}

/* Animated vine decorations */
.jungle-background::after {
    content: '';
    position: absolute;
    top: -10%;
    left: 0;
    width: 100%;
    height: 120%;
    background-image:
        repeating-linear-gradient(90deg,
            transparent 0px,
            transparent 150px,
            rgba(76, 175, 80, 0.1) 150px,
            rgba(76, 175, 80, 0.1) 155px);
    animation: vine-sway 8s ease-in-out infinite alternate;
}

@keyframes jungle-ambience {

    0%,
    100% {
        opacity: 0.8;
    }

    50% {
        opacity: 1;
    }
}

@keyframes vine-sway {
    0% {
        transform: translateX(-5px) rotate(0.5deg);
    }

    100% {
        transform: translateX(5px) rotate(-0.5deg);
    }
}

/* ===================================
   Animal Trail & Avatar
   =================================== */

.animal-trail-container {
    position: relative;
    width: 100%;
    height: 100px;
    margin-top: var(--spacing-lg);
}

.trail-line {
    position: absolute;
    top: 50%;
    left: 0;
    width: 100%;
    height: 4px;
    background: linear-gradient(90deg,
            var(--earth-brown) 0%,
            var(--banana-yellow) 50%,
            var(--earth-brown) 100%);
    border-radius: 2px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.trail-line::before {
    content: '🏁';
    position: absolute;
    right: -20px;
    top: -15px;
    font-size: 2rem;
}

.animal-avatar,
.ghost-avatar {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 80px;
    height: 80px;
    transition: left 0.1s linear;
}

.animal-avatar {
    left: 0%;
    z-index: 3;
}

.ghost-avatar {
    left: 0%;
    opacity: 0.4;
    filter: brightness(0.7);
    z-index: 2;
}

/* Sprite Container - use div with background instead of img */
.animal-avatar .sprite,
.ghost-avatar .sprite {
    width: 100%;
    height: 100%;
    background-size: 200% 200%;
    /* 2x2 grid = 200% in each direction */
    background-repeat: no-repeat;
    background-position: 0% 0%;
    /* Start at top-left frame */
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.3));
    animation: sprite-walk 0.8s steps(1) infinite;
}

/* Fallback for img tags - hide them if sprite div exists */
.animal-avatar img,
.ghost-avatar img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.3));
}

/* Sprite Animation - cycles through 2x2 grid */
@keyframes sprite-walk {
    0% {
        background-position: 0% 0%;
        /* Top-left */
    }

    25% {
        background-position: 100% 0%;
        /* Top-right */
    }

    50% {
        background-position: 0% 100%;
        /* Bottom-left */
    }

    75% {
        background-position: 100% 100%;
        /* Bottom-right */
    }

    100% {
        background-position: 0% 0%;
        /* Back to top-left */
    }
}

/* ===================================
   Typing Tree (Progress Visualization)
   =================================== */

.typing-tree {
    position: relative;
    width: 200px;
    height: 300px;
    margin: var(--spacing-xl) auto 0;
}

.tree-trunk {
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 120px;
    background: linear-gradient(180deg, #6b4423 0%, #4a2f1a 100%);
    border-radius: 20px 20px 5px 5px;
    box-shadow: inset 0 -10px 20px rgba(0, 0, 0, 0.3);
}

.tree-leaves {
    position: absolute;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    width: 150px;
    height: 150px;
    background: radial-gradient(circle, var(--leaf-green) 0%, var(--jungle-green) 100%);
    border-radius: 50%;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
    transition: all 0.5s ease;
}

.tree-leaves::before,
.tree-leaves::after {
    content: '';
    position: absolute;
    background: radial-gradient(circle, var(--leaf-green) 0%, var(--jungle-green) 100%);
    border-radius: 50%;
}

.tree-leaves::before {
    width: 100px;
    height: 100px;
    top: -30px;
    left: -20px;
}

.tree-leaves::after {
    width: 100px;
    height: 100px;
    top: -30px;
    right: -20px;
}

.tree-leaves.grow {
    transform: translateX(-50%) scale(1.2);
}

/* Tree growth levels */
.typing-tree[data-level="1"] .tree-leaves {
    height: 100px;
}

.typing-tree[data-level="2"] .tree-leaves {
    height: 120px;
}

.typing-tree[data-level="3"] .tree-leaves {
    height: 140px;
}

.typing-tree[data-level="4"] .tree-leaves {
    height: 160px;
}

.typing-tree[data-level="5"] .tree-leaves {
    height: 150px;
    transform: translateX(-50%) scale(1.3);
}

/* ===================================
   Ghost Overlay (for rival typing)
   =================================== */

.ghost-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 5;
}

.ghost-cursor {
    position: absolute;
    width: 3px;
    height: 1.5em;
    background: rgba(76, 175, 80, 0.5);
    animation: ghost-blink 1s ease-in-out infinite;
}

@keyframes ghost-blink {

    0%,
    100% {
        opacity: 0.5;
    }

    50% {
        opacity: 0.2;
    }
}

/* ===================================
   Power-ups
   =================================== */

.power-ups {
    position: fixed;
    top: 50%;
    right: var(--spacing-lg);
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
    z-index: 100;
}

.power-up {
    width: 60px;
    height: 60px;
    background: var(--banana-yellow);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    cursor: pointer;
    box-shadow: var(--shadow-lg);
    animation: float-banana 2s ease-in-out infinite;
}

.power-up:hover {
    transform: scale(1.2);
}

@keyframes float-banana {

    0%,
    100% {
        transform: translateY(0px);
    }

    50% {
        transform: translateY(-10px);
    }
}

/* ===================================
   Combo Effect
   =================================== */

.combo-effect {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 3rem;
    font-weight: 700;
    color: var(--banana-yellow);
    text-shadow: 0 0 20px rgba(255, 217, 61, 0.8);
    opacity: 0;
    pointer-events: none;
    z-index: 1000;
    font-family: var(--font-heading);
}

.combo-effect.show {
    animation: combo-pop 0.8s ease-out;
}

@keyframes combo-pop {
    0% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.5);
    }

    50% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1.3);
    }

    100% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(1) translateY(-100px);
    }
}

/* ===================================
   Animal Unlock Animation
   =================================== */

.animal-unlock-container {
    margin: var(--spacing-lg) 0;
    text-align: center;
}

.animal-unlock {
    display: inline-block;
    animation: unlock-celebration 1s ease-out;
}

.unlock-animal-image {
    width: 200px;
    height: 200px;
    object-fit: contain;
    margin-bottom: var(--spacing-sm);
}

.unlock-title {
    font-size: var(--font-size-xl);
    color: var(--banana-yellow);
    margin-bottom: var(--spacing-sm);
}

.unlock-description {
    font-size: var(--font-size-md);
    color: rgba(255, 255, 255, 0.9);
}

@keyframes unlock-celebration {
    0% {
        opacity: 0;
        transform: scale(0) rotate(-180deg);
    }

    50% {
        transform: scale(1.2) rotate(10deg);
    }

    100% {
        opacity: 1;
        transform: scale(1) rotate(0deg);
    }
}

/* ===================================
   Night Mode - Fireflies
   =================================== */

body.night-mode .jungle-background::before {
    background-image: none;
}

body.night-mode .jungle-background::after {
    content: '';
    background: none;
    animation: none;
}

body.night-mode .firefly {
    position: absolute;
    width: 4px;
    height: 4px;
    background: #ffd93d;
    border-radius: 50%;
    box-shadow: 0 0 10px #ffd93d, 0 0 20px #ffd93d;
    animation: firefly-float 4s ease-in-out infinite;
}

@keyframes firefly-float {

    0%,
    100% {
        transform: translate(0, 0);
        opacity: 0.3;
    }

    25% {
        transform: translate(100px, -50px);
        opacity: 1;
    }

    50% {
        transform: translate(150px, -100px);
        opacity: 0.5;
    }

    75% {
        transform: translate(50px, -150px);
        opacity: 0.8;
    }
}

/* Generate fireflies dynamically with JS, but here's the base class */
.firefly:nth-child(1) {
    top: 10%;
    left: 20%;
    animation-delay: 0s;
}

.firefly:nth-child(2) {
    top: 30%;
    left: 60%;
    animation-delay: 0.5s;
}

.firefly:nth-child(3) {
    top: 50%;
    left: 40%;
    animation-delay: 1s;
}

.firefly:nth-child(4) {
    top: 70%;
    left: 80%;
    animation-delay: 1.5s;
}

.firefly:nth-child(5) {
    top: 20%;
    left: 70%;
    animation-delay: 2s;
}

.firefly:nth-child(6) {
    top: 60%;
    left: 10%;
    animation-delay: 2.5s;
}

/* ===================================
   Mystery Eggs
   =================================== */

.mystery-eggs-section {
    text-align: center;
    margin-top: var(--spacing-xl);
    padding: var(--spacing-lg);
    background: rgba(255, 255, 255, 0.05);
    border-radius: var(--radius-lg);
}

.mystery-eggs-section h3 {
    font-size: var(--font-size-lg);
    color: var(--banana-yellow);
    margin-bottom: var(--spacing-md);
}

.eggs-container {
    display: flex;
    justify-content: center;
    gap: var(--spacing-md);
    margin-bottom: var(--spacing-sm);
}

.mystery-egg {
    width: 80px;
    height: 100px;
    background: linear-gradient(135deg, #e0e0e0 0%, #ffffff 50%, #e0e0e0 100%);
    border-radius: 45% 45% 50% 50%;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: var(--shadow-md);
    position: relative;
    overflow: hidden;
}

.mystery-egg::before {
    content: '';
    position: absolute;
    top: 10%;
    left: 10%;
    width: 80%;
    height: 80%;
    background: repeating-linear-gradient(45deg,
            transparent,
            transparent 10px,
            rgba(255, 217, 61, 0.3) 10px,
            rgba(255, 217, 61, 0.3) 20px);
    border-radius: 50%;
}

.mystery-egg:hover {
    transform: scale(1.1) rotate(5deg);
    box-shadow: var(--shadow-glow);
}

.mystery-egg.hatching {
    animation: egg-crack 0.5s ease-in-out;
}

@keyframes egg-crack {

    0%,
    100% {
        transform: rotate(0deg);
    }

    25% {
        transform: rotate(-15deg);
    }

    50% {
        transform: rotate(15deg);
    }

    75% {
        transform: rotate(-10deg);
    }
}

.eggs-info {
    font-size: var(--font-size-sm);
    color: rgba(255, 255, 255, 0.7);
}