/* Robot Container */
.robot-layer {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 5;
    overflow: hidden;
}

/* Common Robot Styles */
.robot {
    position: absolute;
    width: 60px;
    height: 80px;
    filter: drop-shadow(0 0 10px rgba(0, 242, 255, 0.5));
    will-change: top, left, transform;
}

.robot svg {
    width: 100%;
    height: 100%;
    display: block;
}

/* Chat Bubbles */
.chat-bubble {
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%) scale(0);
    background: rgba(255, 255, 255, 0.95);
    color: #000;
    padding: 6px 12px;
    border-radius: 12px;
    font-size: 0.85rem;
    font-weight: 700;
    white-space: nowrap;
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    margin-bottom: 8px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    z-index: 10;
}

.chat-bubble::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    margin-left: -6px;
    border-width: 6px 6px 0;
    border-style: solid;
    border-color: rgba(255, 255, 255, 0.95) transparent transparent transparent;
}

.robot.speaking .chat-bubble {
    transform: translateX(-50%) scale(1);
    opacity: 1;
}

/* Robot 1 - Cyan (Clockwise) */
.bot-1 {
    animation: run-1 20s linear infinite;
}

.bot-1 .body-color {
    fill: #00f2ff;
}

.bot-1 .eye-color {
    fill: #ffffff;
}

@keyframes run-1 {

    /* Top Edge (L -> R) */
    0% {
        top: 20px;
        left: 20px;
        transform: scaleX(1);
    }

    24% {
        top: 20px;
        left: calc(100% - 80px);
        transform: scaleX(1);
    }

    25% {
        top: 20px;
        left: calc(100% - 80px);
        transform: scaleX(1);
    }

    /* Right Edge (T -> B) */
    26% {
        top: 20px;
        left: calc(100% - 80px);
        transform: scaleX(1);
    }

    49% {
        top: calc(100% - 100px);
        left: calc(100% - 80px);
        transform: scaleX(1);
    }

    50% {
        top: calc(100% - 100px);
        left: calc(100% - 80px);
        transform: scaleX(1);
    }

    /* Bottom Edge (R -> L) - Face Left */
    51% {
        top: calc(100% - 100px);
        left: calc(100% - 80px);
        transform: scaleX(-1);
    }

    74% {
        top: calc(100% - 100px);
        left: 20px;
        transform: scaleX(-1);
    }

    75% {
        top: calc(100% - 100px);
        left: 20px;
        transform: scaleX(-1);
    }

    /* Left Edge (B -> T) - Face Right */
    76% {
        top: calc(100% - 100px);
        left: 20px;
        transform: scaleX(1);
    }

    99% {
        top: 20px;
        left: 20px;
        transform: scaleX(1);
    }

    100% {
        top: 20px;
        left: 20px;
        transform: scaleX(1);
    }
}


/* Robot 2 - Purple (Counter-Clockwise) */
.bot-2 {
    animation: run-2 25s linear infinite;
}

.bot-2 .body-color {
    fill: #bd00ff;
}

.bot-2 .eye-color {
    fill: #ffffff;
}

@keyframes run-2 {

    /* Bottom Edge (R -> L) */
    0% {
        top: calc(100% - 100px);
        left: calc(100% - 80px);
        transform: scaleX(-1);
    }

    24% {
        top: calc(100% - 100px);
        left: 20px;
        transform: scaleX(-1);
    }

    25% {
        top: calc(100% - 100px);
        left: 20px;
        transform: scaleX(-1);
    }

    /* Left Edge (B -> T) - Face Right */
    26% {
        top: calc(100% - 100px);
        left: 20px;
        transform: scaleX(1);
    }

    49% {
        top: 20px;
        left: 20px;
        transform: scaleX(1);
    }

    50% {
        top: 20px;
        left: 20px;
        transform: scaleX(1);
    }

    /* Top Edge (L -> R) */
    51% {
        top: 20px;
        left: 20px;
        transform: scaleX(1);
    }

    74% {
        top: 20px;
        left: calc(100% - 80px);
        transform: scaleX(1);
    }

    75% {
        top: 20px;
        left: calc(100% - 80px);
        transform: scaleX(1);
    }

    /* Right Edge (T -> B) - Face Left */
    76% {
        top: 20px;
        left: calc(100% - 80px);
        transform: scaleX(-1);
    }

    99% {
        top: calc(100% - 100px);
        left: calc(100% - 80px);
        transform: scaleX(-1);
    }

    100% {
        top: calc(100% - 100px);
        left: calc(100% - 80px);
        transform: scaleX(-1);
    }
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    .robot {
        width: 40px;
        height: 55px;
    }

    /* Keyframes are using calc/%, so they should largely adapt automatically, 
       just need to adjust the offsets for the smaller robot size if we want to be precise. 
       Since calc(100% - 80px) might be too much padding for a small screen, let's relax it slightly via generic override if needed, 
       but standard % usually works okay.
    */
}