* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

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

.zigzag {
    position: absolute;
    display: flex;
    gap: 38px;
}

.zigzag:nth-child(2) {
    transform: rotate(180deg);
}

.zigzag div {
    position: relative;
    width: 100px;
    height: 100px;
    display: block;
    transform: rotate(315deg);
    overflow: hidden;
}

.zigzag div::before {
    content: '';
    position: absolute;
    height: 2px;
    width: 100%;
    background: linear-gradient(90deg, transparent, #0f0);
    animation: animateBefore 4s linear infinite;
    animation-delay: calc(1s * var(--i));
}

@keyframes animateBefore {
    0% {
        transform: translateX(-100%);
    }
    25%, 100% {
        transform: translateX(100%);
    }
}

.zigzag div::after {
    content: '';
    position: absolute;
    right: 0;
    height: 100%;
    width: 2px;
    background: linear-gradient(180deg, transparent, #0f0);
    animation: animateAfter 4s linear infinite;
    animation-delay: calc(1s * var(--i));
}

@keyframes animateAfter {
    0%, 12.5% {
        transform: translateY(-100%);
    }
    37.5%, 100% {
        transform: translateY(100%);
    }
}

.zigzag div span {
    position: absolute;
    inset: 10px;
    background: #292929;
    display: flex;
    justify-content: center;
    align-items: center;
    border: 1px solid #000;
}

.zigzag div span b {
    color: #fff;
    font-weight: normal;
    transform: rotate(45deg);
    font-size: 2em;
}
