#gesture-preview {
    position: fixed;
    z-index: 5;
    bottom: max(78px, calc(env(safe-area-inset-bottom, 0px) + 70px));
    right: max(20px, env(safe-area-inset-right, 0px));
    display: grid;
    justify-items: end;
    gap: 7px;
    color: #e8e0ce;
    pointer-events: none;
}

#gesture-preview[hidden] { display: none; }

#gesture-preview .gesture-viewport {
    position: relative;
    width: clamp(128px, 13vw, 172px);
    aspect-ratio: 4 / 3;
    overflow: hidden;
    isolation: isolate;
    border: 1px solid #73888b;
    border-radius: 12px;
    background: #0b1a24;
    box-shadow: 0 4px 18px #0007;
}

#gesture-preview #gesture-camera,
#gesture-preview #gesture-landmarks {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
    opacity: 1;
    object-fit: cover;
    object-position: center;
    transform: scaleX(-1);
    pointer-events: none;
}

#gesture-badge {
    position: absolute;
    left: 8px;
    bottom: 7px;
    z-index: 1;
    border-radius: 5px;
    padding: 4px 7px;
    color: #a5efd7;
    background: rgba(5, 24, 31, .88);
    font-family: inherit;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.25;
}

#gesture-preview-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 10px;
    border: 1px solid #47606b;
    border-radius: 7px;
    background: rgba(13, 31, 43, .9);
    color: #e8ddc8;
    font: inherit;
    font-size: 12px;
    cursor: pointer;
    pointer-events: auto;
}

#gesture-preview-toggle:focus-visible { outline: 2px solid #f5cf8c; }
#gesture-preview-toggle > svg { width: 16px; height: 16px; }
#gesture-preview-toggle::after {
    content: '';
    width: 6px;
    height: 6px;
    margin: -3px 2px 0;
    border: solid currentColor;
    border-width: 0 1.5px 1.5px 0;
    transform: rotate(45deg);
}

#gesture-preview.is-collapsed #gesture-preview-toggle::after {
    margin-top: 3px;
    transform: rotate(225deg);
}

/* Keep the video playing when the user folds the preview in a mobile WebView. */
#gesture-preview.is-collapsed .gesture-viewport {
    position: absolute;
    width: 1px;
    height: 1px;
    border: 0;
    opacity: 0;
    pointer-events: none;
}

@media (max-width: 640px) {
    #gesture-preview {
        right: max(10px, env(safe-area-inset-right, 0px));
        bottom: max(70px, calc(env(safe-area-inset-bottom, 0px) + 65px));
    }
    #gesture-preview .gesture-viewport { width: 118px; }
}

@media (max-height: 440px) {
    #gesture-preview { bottom: max(12px, env(safe-area-inset-bottom, 0px)); left: 12px; right: auto; justify-items: start; }
    #gesture-preview .gesture-viewport { width: 104px; }
}
