.puzzle-captcha {
    display: flex;
    position: relative;
    border: 1px solid color-mix(in oklab, var(--color-base-content) 20%, #0000);;
    width: var(--captcha-width);
    height: var(--captcha-height);
    touch-action: none;
    margin-left: calc(50% - var(--captcha-width) / 2);
    max-width: 100vw;

    &:after {
        content: '';
        pointer-events: none;
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
        left: 0;
        mix-blend-mode: soft-light;
        z-index: 3;
        opacity: 0;
        transition: .3s;
    }
}

.puzzle-captcha__image {
    width: 100%;
    height: 100%;
    background: var(--captcha-image);
    transition: filter 0.3s;
}

@keyframes captcha-icon-appear {
    from {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.8);
    }
    to {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
}

.puzzle-captcha__icon {
    display: none;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 3rem;
    height: 3rem;
    color: var(--color-success);
    background-color: rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    padding: 0.5rem;
    z-index: 2;
}

.puzzle-captcha--success .puzzle-captcha__icon {
    animation: captcha-icon-appear 0.3s ease-out;
}

.puzzle-captcha--success:after {
    background-color: var(--color-success);
    opacity: 1;
}

.puzzle-captcha--error {
    animation: shake .4s linear;

    &:after {
        background-color: var(--color-error);
        opacity: 1;
    }
}

.puzzle-captcha--success .puzzle-captcha__image,
.puzzle-captcha--success .puzzle-captcha__piece {
    filter: grayscale(1);
}

.puzzle-captcha--success .puzzle-captcha__piece {
    filter: grayscale(1);
    pointer-events: none;

    &:after {
        content: none;
    }
}

.puzzle-captcha--success .puzzle-captcha__icon {
    display: block;
}

.puzzle-captcha__piece {
    position: absolute;
    top: 0;
    left: 0;
    width: var(--captcha-piece-width);
    height: var(--captcha-piece-height);
    background: var(--captcha-image) top right;
    z-index: 1;
    cursor: move;

    &:after {
        content: '';
        background: url('/images/captcha/puzzle/piece-border.svg') no-repeat center;
        position: absolute;
        width: 100%;
        height: 100%;
        scale: 1.07;
    }
}
