@keyframes mute-anim {
    0% {
        transform: scale(0.8);
    }

    20% {
        transform: scale(1.2);
    }

    100% {
        transform: scale(1.0);
    }
}

[class*="bg-narwhal"] .lip-sync {
    --container-color: #2c444e;
    display: flex;
    align-items: stretch;
    justify-content: center;
    width: fit-content;
    margin-left: auto;
    margin-right: auto;

    .lip-sync-video {
        background-color: #2c444e;
        border-radius: var(--border-radius);
        padding: var(--ls-border);
        position: relative;
        display: flex;
        align-items: center;
        width: 420px;

        video {
            height: 100%;
            width: 100%;
            background-color: #162f3a;
            border-radius: var(--inner-border-radius);
            aspect-ratio: 16/10;
        }

        .lip-sync-mute {
            background-color: var(--maestra-yellow);

            &::before {
                background-color: black;
            }
        }
    }

    .lip-sync-languages {
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        padding: var(--ls-border) 8px;
        background: transparent;
    }

    .lip-sync-languages .lip-sync-lang {
        --e-text-color: white;
        --e-shadow-color: color-mix(in srgb, var(--maestra-blue) 30%, #162f3a);
        --e-border-color: #162f3a;
        --e-bg-color: #162f3a;
        --e-active-shadow-size: 0;
        --e-border-size: 0;
        --e-active-bg-color: var(--e-bg-color);
        --e-active-text-color: var(--ncs-on-primary);
        --e-active-border-color: var(--e-border-color);
        --e-border-radius: 4px;
        --e-transition-duration: 0.15s;
        --translation: translate(0, 0);
        width: 100%;
        background-color: transparent;

        .elevating-button__content {
            border-radius: 4px;
            justify-content: flex-start;
            align-items: center;
            padding: 0.5rem 1rem;
            gap: 0.5rem;
            border: none;
            box-shadow: none;
        }

        &:first-child .elevating-button__content {
            border-radius: calc(var(--border-radius) - 16px) calc(var(--border-radius) - 16px) 4px 4px;
        }

        &:last-child .elevating-button__content {
            border-radius: 4px 4px calc(var(--border-radius) - 16px) calc(var(--border-radius) - 16px);
        }

        img.flag {
            width: 1.2em;
            height: 1.2em;
            object-fit: contain;
        }

        &:not(.active):hover {
            --e-shadow-color: #162f3a;

            .elevating-button__content {
                box-shadow: 0px 0px 0px 0.15rem var(--e-shadow-color);
                transform: none;
            }
        }

        &:not(.active):active {
            .elevating-button__content {
                transform: scale(0.95);
                box-shadow: none;
            }
        }

        &.active {
            --e-text-color: black;
            --e-shadow-color: color-mix(in srgb, var(--maestra-yellow) 50%, black);
            --e-border-color: var(--maestra-yellow);
            --e-bg-color: var(--maestra-yellow);
            background-color: transparent;
            cursor: default;

            .elevating-button__content {
                transform: none;
                box-shadow: none;
                border: none;
            }

            &:hover .elevating-button__content {
                transform: none;
                box-shadow: none;
                border: none;
            }
        }
    }

    .subtitles-section {
        display: none;
    }

    .rtl & {
        .lip-sync-languages .lip-sync-lang {
            &:first-child .elevating-button__content {
                border-radius: 4px 4px calc(var(--border-radius) - 16px) calc(var(--border-radius) - 16px);
            }

            &:last-child .elevating-button__content {
                border-radius: calc(var(--border-radius) - 16px) calc(var(--border-radius) - 16px) 4px 4px;
            }
        }
    }

    @media (max-width: 610px) {
        flex-direction: column-reverse;
        gap: 0.5rem;

        .lip-sync-video {
            width: 100%;
        }

        .lip-sync-languages {
            flex-direction: row;
            flex-wrap: wrap;
            gap: 0.5rem;
            justify-content: center;
            width: 100%;
            max-width: 500px;
            min-height: unset;

            .lip-sync-lang {
                width: auto;

                .elevating-button__content {
                    border-radius: 8px;
                }

                &:first-child .elevating-button__content,
                &:last-child .elevating-button__content {
                    border-radius: 8px;
                }
            }
        }
    }
}

.dark-mode [class*="bg-narwhal"] .lip-sync {
    --container-color: #203439;

    .lip-sync-video {
        background-color: var(--container-color);

        video {
            background-color: #081C23;
        }
    }

    .lip-sync-languages .lip-sync-lang {
        --e-bg-color: #081C23;
        --e-shadow-color: #081C23;
        --e-border-color: #081C23;

        &:not(.active):hover {
            --e-shadow-color: #081C23;

            .elevating-button__content {
                box-shadow: 0px 0px 0px 0.25rem var(--e-shadow-color);
                transform: none;
            }
        }

        &.active {
            --e-shadow-color: color-mix(in srgb, var(--maestra-yellow) 50%, #081C23);
            --e-border-color: var(--maestra-yellow);
            --e-bg-color: var(--maestra-yellow);

            .elevating-button__content {
                transform: none;
                box-shadow: none;
            }

            &:hover .elevating-button__content {
                transform: none;
                box-shadow: none;
                border: none;
            }
        }
    }
}

.lip-sync {
    --container-color: var(--ncs-container-strong);
    --ls-border: 8px;
    --inner-border-radius: calc(var(--border-radius) - var(--ls-border));
    padding: var(--ls-border);
    background-color: var(--container-color);
    border-radius: var(--border-radius);
    display: flex;
    flex-direction: row;
    align-items: stretch;
    gap: 0;
    width: fit-content;
    margin-left: auto;
    margin-right: auto;
    max-width: 80vw;

    * {
        max-width: 80vw;
    }

    .lip-sync-video {
        border-top-right-radius: var(--border-radius);
        border-bottom-right-radius: var(--border-radius);
        display: flex;
        align-items: center;
        justify-content: center;
        position: relative;
        background-color: black;
        width: 420px;

        video {
            height: 100%;
            width: 100%;
            aspect-ratio: 4/3;
            object-fit: cover;
            border-radius: var(--inner-border-radius);
            border-top-left-radius: 0;
            border-bottom-left-radius: 0;
        }

        .lip-sync-mute {
            position: absolute;
            right: 1rem;
            top: 1rem;
            background-color: var(--ncs-primary);
            width: 2.5rem;
            height: 2.5rem;
            border-radius: 2.5rem;
            display: flex;
            align-items: center;
            justify-content: center;
            cursor: pointer;
            animation: mute-anim 0.25s ease-in-out;

            &::before {
                width: 50%;
                height: 50%;
                content: '';
                display: block;
                mask-image: url("/static/blocks/video-controller-2/assets/icons/sound-unmuted.svg");
                mask-size: contain;
                mask-repeat: no-repeat;
                mask-position: center;
                background-color: var(--ncs-on-primary);
            }

            &.muted::before {
                mask-image: url("/static/blocks/video-controller-2/assets/icons/sound-muted.svg");
            }

            >img {
                display: none;
            }
        }

        .lip-sync-subtitles {
            position: absolute;
            left: 1rem;
            right: 1rem;
            bottom: 1rem;
            display: flex;
            flex-direction: column;
            gap: 0.5rem;
            align-items: center;
            justify-content: center;
            transform: translateY(1rem);
            opacity: 0;
            transition: 0.15s ease-in-out;

            &.active {
                transform: translateY(0);
                opacity: 1;
            }

            .lip-sync-subtitle {
                color: white;
                text-shadow: 1px 1px 2px black;
                font-weight: 700;

                &.original {
                    display: none;
                    opacity: 0.5;
                }

                &[data-direction="rtl"] {
                    direction: rtl;
                    text-align: right;
                }

                &[data-direction="ltr"] {
                    direction: ltr;
                    text-align: center;
                }
            }
        }
    }

    .lip-sync-languages {
        padding: 1em;
        display: flex;
        flex-direction: column;
        gap: 0.5em;
        font-size: var(--font-md);
        align-items: stretch;
        justify-content: center;
        border-radius: var(--inner-border-radius);
        border-top-right-radius: 0;
        border-bottom-right-radius: 0;
        background-color: black;
    }

    .lip-sync-languages .lip-sync-lang {
        --e-padding: 0.5em 1em;
        --e-gap: 0.5em;
        --e-bg-color: black;
        --e-text-color: white;
        --e-shadow-color: color-mix(in srgb, var(--ncs-primary) 50%, black);
        --e-border-color: var(--ncs-primary);
        --e-active-shadow-size: 4px;

        .elevating-button__content {
            justify-content: flex-start;
            min-width: max-content;
        }

        &.active {
            --e-bg-color: var(--ncs-primary);
            --e-border-color: var(--e-shadow-color);
            --e-text-color: var(--ncs-on-primary);
        }

        img {
            width: 1rem;
            height: 1rem;
            object-fit: contain;
        }
    }

    .rtl & {
        .lip-sync-video {
            border-top-right-radius: 0;
            border-bottom-right-radius: 0;
            border-top-left-radius: var(--border-radius);
            border-bottom-left-radius: var(--border-radius);

            video {
                border-top-left-radius: var(--inner-border-radius);
                border-bottom-left-radius: var(--inner-border-radius);
                border-top-right-radius: 0;
                border-bottom-right-radius: 0;
            }
        }

        .lip-sync-languages {
            border-top-right-radius: var(--inner-border-radius);
            border-bottom-right-radius: var(--inner-border-radius);
            border-top-left-radius: 0;
            border-bottom-left-radius: 0;
        }
    }
}

@media(max-width: 610px) {
    .lip-sync {
        flex-direction: column-reverse;
        gap: 0.5rem;
        background: none;
        align-items: center;

        .lip-sync-video {
            background-color: var(--container-color);
            padding: var(--ls-border);
            border-radius: var(--border-radius);
        }

        .lip-sync-video video {
            height: unset;
            width: 100%;
            aspect-ratio: 1;
            border-radius: var(--inner-border-radius);
        }

        .lip-sync-languages {
            flex-direction: row;
            flex-wrap: wrap;
            background: none;
            align-items: center;

            .lip-sync-lang {
                --e-bg-color: var(--background);
                --e-text-color: var(--text);
                --e-shadow-color: color-mix(in srgb, var(--ncs-primary) 50%, var(--background));
                --e-border-color: var(--ncs-primary);
                --e-active-shadow-size: 4px;
            }
        }

        .rtl & {
            .lip-sync-video {
                border-radius: var(--border-radius);

                video {
                    border-radius: var(--inner-border-radius);
                }
            }

            .lip-sync-languages {
                border-radius: 0;
            }
        }
    }
}