/* hand-control.css - Webcam hand-gesture UI control
 * Ki-sphere pointer, webcam preview, pinch/confirm feedback rings.
 * Everything here is purely visual; interaction logic lives in hand-control.js.
 */

/* --- Ki-sphere pointer --------------------------------------------------- */
#hand-pointer {
    position: fixed;
    top: 0;
    left: 0;
    width: 34px;
    height: 34px;
    margin-left: -17px;
    margin-top: -17px;
    border-radius: 50%;
    pointer-events: none;
    z-index: 9999;
    /* Ki energy sphere */
    background: radial-gradient(circle at 35% 30%,
            rgba(255, 255, 255, 0.95) 0%,
            rgba(120, 220, 255, 0.85) 30%,
            rgba(40, 150, 255, 0.75) 60%,
            rgba(20, 90, 220, 0.35) 100%);
    box-shadow:
        0 0 12px 4px rgba(90, 190, 255, 0.7),
        0 0 26px 10px rgba(40, 140, 255, 0.35);
    transition: transform 0.08s linear, opacity 0.25s ease, background 0.2s ease;
    will-change: transform;
    opacity: 0;
}

#hand-pointer.visible {
    opacity: 1;
}

/* Pulsing inner core for a "living energy" feel */
.hand-pointer-core {
    position: absolute;
    inset: 22%;
    border-radius: 50%;
    background: radial-gradient(circle at 40% 35%,
            rgba(255, 255, 255, 1) 0%,
            rgba(200, 240, 255, 0.9) 45%,
            rgba(120, 200, 255, 0.6) 100%);
    animation: hand-core-pulse 1.1s ease-in-out infinite;
}

@keyframes hand-core-pulse {
    0%, 100% { transform: scale(0.85); opacity: 0.85; }
    50%      { transform: scale(1.1); opacity: 1; }
}

/* --- Ki trail (pooled particles) ----------------------------------------- */
#hand-trail-layer {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 9997;
}

.hand-trail-dot {
    position: fixed;
    top: 0;
    left: 0;
    width: 18px;
    height: 18px;
    margin-left: -9px;
    margin-top: -9px;
    border-radius: 50%;
    opacity: 0;
    background: radial-gradient(circle,
            rgba(160, 225, 255, 0.9) 0%,
            rgba(50, 150, 255, 0.5) 55%,
            rgba(30, 110, 220, 0) 100%);
    will-change: transform, opacity;
}

.hand-trail-dot.hot {
    background: radial-gradient(circle,
            rgba(255, 245, 170, 0.95) 0%,
            rgba(255, 190, 40, 0.55) 55%,
            rgba(255, 140, 0, 0) 100%);
}

.hand-trail-dot.animate {
    animation: hand-trail-fade 0.55s ease-out forwards;
}

@keyframes hand-trail-fade {
    0%   { opacity: 0.9; transform: scale(1); }
    100% { opacity: 0; transform: scale(0.2); }
}

/* --- Click spark burst --------------------------------------------------- */
.hand-burst-spark {
    position: fixed;
    top: 0;
    left: 0;
    width: 7px;
    height: 7px;
    margin-left: -3.5px;
    margin-top: -3.5px;
    border-radius: 50%;
    background: radial-gradient(circle,
            rgba(255, 255, 255, 1) 0%,
            rgba(255, 210, 90, 0.9) 50%,
            rgba(255, 150, 0, 0) 100%);
    box-shadow: 0 0 8px 2px rgba(255, 200, 80, 0.7);
    pointer-events: none;
    animation: hand-burst 0.45s ease-out forwards;
}

@keyframes hand-burst {
    0% {
        opacity: 1;
        transform: translate(0, 0) scale(1);
    }
    100% {
        opacity: 0;
        transform: translate(var(--bx, 0), var(--by, 0)) scale(0.3);
    }
}

/* Pointer sitting over a clickable target */
#hand-pointer.over-target {
    transform: scale(1.15);
    background: radial-gradient(circle at 35% 30%,
            rgba(255, 255, 255, 0.98) 0%,
            rgba(255, 240, 150, 0.9) 30%,
            rgba(255, 200, 40, 0.8) 60%,
            rgba(255, 150, 0, 0.4) 100%);
    box-shadow:
        0 0 14px 5px rgba(255, 210, 80, 0.8),
        0 0 30px 12px rgba(255, 170, 0, 0.4);
}

/* Fingers occluded / tracking unreliable — actions frozen. Pointer turns grey
   and dashed to signal "I can't read your fingers right now". */
#hand-pointer.unreliable {
    background: radial-gradient(circle at 35% 30%,
            rgba(220, 220, 220, 0.7) 0%,
            rgba(150, 150, 150, 0.5) 60%,
            rgba(100, 100, 100, 0.2) 100%);
    box-shadow: 0 0 10px 3px rgba(120, 120, 120, 0.4);
    outline: 2px dashed rgba(255, 255, 255, 0.5);
    outline-offset: 3px;
}

#hand-pointer.unreliable .hand-pointer-core {
    animation: none;
    opacity: 0.4;
}

/* Pinch engaged — collapse to a bright hot dot so the "click" moment reads. */
#hand-pointer.pinching {
    transform: scale(0.55);
    background: radial-gradient(circle at 40% 35%,
            rgba(255, 255, 255, 1) 0%,
            rgba(255, 240, 150, 0.95) 45%,
            rgba(255, 190, 40, 0.85) 100%);
    box-shadow:
        0 0 20px 8px rgba(255, 255, 255, 0.95),
        0 0 44px 18px rgba(255, 200, 60, 0.6);
}

/* Confirm progress ring for destructive actions (drawn as conic gradient) */
#hand-pointer-ring {
    position: fixed;
    top: 0;
    left: 0;
    width: 60px;
    height: 60px;
    margin-left: -30px;
    margin-top: -30px;
    border-radius: 50%;
    pointer-events: none;
    z-index: 9998;
    opacity: 0;
    transition: opacity 0.15s ease;
    /* --progress is set inline 0..100 by JS */
    background: conic-gradient(rgba(255, 80, 80, 0.95) calc(var(--progress, 0) * 1%),
            rgba(255, 255, 255, 0.12) 0);
    -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 6px), #000 calc(100% - 5px));
    mask: radial-gradient(farthest-side, transparent calc(100% - 6px), #000 calc(100% - 5px));
}

#hand-pointer-ring.visible {
    opacity: 1;
}

/* --- Webcam preview panel ------------------------------------------------ */
#hand-cam-panel {
    position: fixed;
    bottom: 16px;
    right: 16px;
    width: 200px;
    z-index: 60;
    background: rgba(17, 24, 39, 0.85);
    border: 1px solid rgba(250, 204, 21, 0.35);
    border-radius: 12px;
    padding: 8px;
    backdrop-filter: blur(6px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

#hand-cam-panel.hidden {
    display: none;
}

#hand-cam-wrap {
    position: relative;
    width: 100%;
    border-radius: 8px;
    overflow: hidden;
    background: #000;
    aspect-ratio: 4 / 3;
}

/* Mirror the video so it feels like a mirror */
#hand-cam-video,
#hand-cam-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scaleX(-1);
}

#hand-cam-canvas {
    pointer-events: none;
}

#hand-cam-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
    cursor: grab;
    user-select: none;
    touch-action: none;
}

#hand-cam-panel.dragging {
    cursor: grabbing;
    opacity: 0.92;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(250, 204, 21, 0.5);
}

#hand-cam-panel.dragging #hand-cam-header {
    cursor: grabbing;
}

/* Small drag affordance next to the title */
#hand-cam-title::before {
    content: "\f0b2"; /* fa-arrows-up-down-left-right */
    font-family: "Font Awesome 6 Free";
    font-weight: 900;
    opacity: 0.5;
    margin-right: 2px;
    font-size: 0.7rem;
}

#hand-cam-title {
    font-size: 0.72rem;
    font-weight: 700;
    color: #facc15;
    display: flex;
    align-items: center;
    gap: 6px;
}

#hand-cam-close {
    color: #9ca3af;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.85rem;
    line-height: 1;
}

#hand-cam-close:hover {
    color: #fff;
}

/* Status pill (state + debug pinch ratio) */
#hand-cam-status {
    margin-top: 6px;
    font-size: 0.65rem;
    color: #cbd5e1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
}

.hand-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #6b7280;
    flex-shrink: 0;
    transition: background 0.2s ease;
}

.hand-status-dot.tracking {
    background: #22c55e;
    box-shadow: 0 0 6px 2px rgba(34, 197, 94, 0.6);
}

.hand-status-dot.searching {
    background: #eab308;
}

.hand-status-dot.error {
    background: #ef4444;
}

/* --- Magnetic dock effect on the vote cards ------------------------------ */
/* Only while hand control is active: let enlarged cards overflow the row and
 * give room above so lifted cards aren't clipped by the footer. */
body.hand-control-active #cards-container {
    overflow: visible;
    padding-top: 2.5rem;
}

/* Cards must sit above their siblings when scaled, and use a springy transition
 * driven by the magnet's inline transform. transform-origin bottom keeps the
 * growth anchored to the row baseline. */
body.hand-control-active .dbz-card-btn {
    transition: transform 0.12s ease-out, box-shadow 0.15s ease-out;
    transform-origin: center bottom;
    will-change: transform;
}

/* The magnet raises z-index inline; add a glow to the most-magnified card. */
body.hand-control-active .dbz-card-btn[style*="scale(1.3"],
body.hand-control-active .dbz-card-btn[style*="scale(1.4"],
body.hand-control-active .dbz-card-btn[style*="scale(1.5"] {
    box-shadow: 0 8px 26px rgba(255, 200, 80, 0.65);
    border-color: rgba(255, 210, 90, 0.9);
}

/* --- Click confirmation flash on the selected element -------------------- */
/* Uses filter + box-shadow only (never transform) so it stacks cleanly with
 * the magnet's inline transform on cards. */
.hand-clicked {
    animation: hand-click-flash 0.4s ease-out;
    /* keep whatever inline transform the magnet set */
}

@keyframes hand-click-flash {
    0% {
        filter: brightness(2.2) saturate(1.4);
        box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.95),
                    0 0 26px 10px rgba(255, 210, 90, 0.9);
    }
    100% {
        filter: brightness(1);
        box-shadow: 0 0 0 0 rgba(255, 255, 255, 0),
                    0 0 0 0 rgba(255, 210, 90, 0);
    }
}

/* Vote cards get a stronger, ring-style confirmation. */
.dbz-card-btn.hand-clicked {
    animation: hand-click-flash-card 0.45s ease-out;
    z-index: 70 !important;
}

@keyframes hand-click-flash-card {
    0% {
        filter: brightness(2.4) saturate(1.5);
        border-color: #fff !important;
        box-shadow: 0 0 0 4px rgba(255, 255, 255, 1),
                    0 0 34px 14px rgba(255, 200, 60, 0.95);
    }
    100% {
        filter: brightness(1);
        box-shadow: 0 0 0 0 rgba(255, 255, 255, 0),
                    0 0 0 0 rgba(255, 200, 60, 0);
    }
}

/* --- Hover zoom: enlarge the element under the ki pointer ---------------- */
.hand-hover-zoom {
    transform: scale(1.28) !important;
    z-index: 50 !important;
    transition: transform 0.15s cubic-bezier(0.34, 1.56, 0.64, 1) !important;
    box-shadow: 0 0 18px 4px rgba(255, 200, 80, 0.6) !important;
}

/* Cards get a slightly stronger pop and stay above their neighbours */
.dbz-card-btn.hand-hover-zoom {
    transform: scale(1.4) translateY(-6px) !important;
    z-index: 60 !important;
}

/* --- Header toggle button active state ----------------------------------- */
#hand-control-toggle.active {
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    color: #fff;
    box-shadow: 0 0 10px 2px rgba(59, 130, 246, 0.55);
}

/* Respect reduced motion */
@media (prefers-reduced-motion: reduce) {

    #hand-pointer,
    #hand-pointer-ring {
        transition: opacity 0.2s ease;
    }

    .hand-pointer-core {
        animation: none;
    }

    .hand-trail-dot,
    .hand-burst-spark {
        display: none;
    }

    .hand-hover-zoom {
        transition: none !important;
    }
}
