body {
    height: 100vh;
    background: #111;
    display: flex;
    justify-content: center;
    align-items: center;
}

a {
    text-decoration: none;
    color: #5500FF;
    /* background: #111; */
    font-family: roboto;
    font-size: 40px;
    /* border: 1px solid #5500FF; */
    font-weight: bold;
    letter-spacing: 0;
    padding: 10px 40px;
    position: relative;
    /* overflow: hidden; */
    border-radius: 1px;
    background: #111;
    transition: all 0.4s;
}

a::before,
a::after {
    content: '';
    position: absolute;
    left: -2px;
    top: -2px;
    width: calc(100% + 4px);
    height: calc(100% + 4px);
    background: #5500FF;
    /* transition: all 1.5s; */
    z-index: -2;
}

a::before {
    transition-delay: 0.8s;
}

a::after {
    /* opacity: 0; */
    width: 10px;
    height: 10px;
    background: #F00;
    /* box-shadow: -30px 0px 1px 1px; */
    z-index: 3;
    top: -2px;
    left: -2px;
    /* animation: square 2s linear infinite; */
}

/* a:hover:after {
    opacity: 1;
    box-shadow: 0px 0px 1px 1px;
    left: 100%;
} */

a:hover:after{
    animation: square 2s linear infinite;
}

a:hover:before {
    background: #FFF;
}

a:hover {
    color: #FFF;
}

a span{
    position: absolute;
    top: -2px;    
    left: -2px;
    width: 10px;
    height: 10px;
    background: #FFF;
    box-shadow: 0px 0px 1px 1px;
}

a:hover span{
    animation: square 2s linear infinite;
    animation-delay: .1s;
}

/* ==========================================================================
   CÓDIGO INEFICIENTE (COMENTADO):
   La animación secuencial modificando 'top' y 'left' provoca continuas
   recalculaciones geométricas (Layout/Reflow) en cada fotograma del ciclo de la animación.
   Esto eleva el uso de CPU y provoca micro-tirones (jank) al renderizar.
   ==========================================================================
@keyframes square {
    0% {
        top: -2px;
        left: -2px;
    }

    25% {
        top: -2px;
        left: 100%;
    }

    50% {
        top: 100%;
        left: 100%;
    }

    75% {
        top: 100%;
        left: -2px;
    }

    100% {
        top: -2px;
        left: -2px;
    }
}
*/

/* ==========================================================================
   CÓDIGO EFICIENTE (OPTIMIZADO POR GPU):
   Fijamos estáticamente la coordenada inicial en 'top: -2px; left: -2px;' y
   animamos la propiedad de composición 'transform: translate(x, y)'. Esto permite
   que la GPU renderice el movimiento del indicador de forma aislada sin forzar
   reflows en el hilo principal.
   ========================================================================== */
@keyframes square {
    0% {
        transform: translate(0, 0);
    }

    25% {
        /* Desplazamiento horizontal por hardware (calculado según el ancho del botón) */
        transform: translate(192px, 0);
    }

    50% {
        /* Desplazamiento horizontal y vertical por hardware */
        transform: translate(192px, 50px);
    }

    75% {
        /* Retorno horizontal por hardware */
        transform: translate(0, 50px);
    }

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