/**
 * GESTURE QUIZ CAMERA AI - STYLING (16:9 HD CLASSROOM DISPLAY)
 * Game Title: "Cử Chỉ Chọn Đáp Án"
 * 
 * Features:
 * - 2D Educational Game Show Theme (Navy Blue #0f172a, Royal Blue #1e3a8a, Gold #f59e0b)
 * - Auto-expanding Question Box (no clipping, high contrast)
 * - Prominent Character Gesture Stickers (Transparent PNG Cutouts with Sticker Outline)
 * - Dynamic Gesture-Option Mapping UI
 * - 100% Original Background Image (Preserved bit-for-bit)
 * 
 * GiaovienGenz 2.0
 */

#gesture-game-container {
    position: relative;
    width: 100%;
    max-width: 1150px;
    margin: 0 auto;
    aspect-ratio: 16 / 9;
    border-radius: 28px;
    overflow: hidden;
    box-shadow: 0 20px 50px -10px rgba(15, 23, 42, 0.5), 0 0 0 3px #1e3a8a;
    background-color: #0f172a;
    display: flex;
    flex-direction: column;
    user-select: none;
    font-family: 'Nunito', system-ui, -apple-system, sans-serif;
}

/* Background Layer - 100% original schoolyard image */
.gesture-bg-layer {
    position: absolute;
    inset: 0;
    background-image: url('gesture-assets/san-truong-bg.jpg');
    background-size: cover;
    background-position: center bottom;
    background-repeat: no-repeat;
    z-index: 1;
}

/* Touch Exit Fullscreen Button */
.gesture-touch-exit-btn {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 50;
    display: none;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    background: rgba(15, 23, 42, 0.85);
    color: #fff;
    font-weight: 800;
    font-size: 13px;
    border-radius: 9999px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    backdrop-filter: blur(8px);
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    transition: all 0.2s ease;
}
.gesture-touch-exit-btn:hover {
    background: rgba(220, 38, 38, 0.95);
    transform: scale(1.05);
}

:fullscreen #gesture-game-container,
:-webkit-full-screen #gesture-game-container {
    max-width: 100vw;
    width: 100vw;
    height: 100vh;
    border-radius: 0;
    box-shadow: none;
    aspect-ratio: auto;
}
:fullscreen .gesture-touch-exit-btn,
:-webkit-full-screen .gesture-touch-exit-btn {
    display: inline-flex;
}

/* UI Content Layer */
.gesture-ui-layer {
    position: relative;
    z-index: 10;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    width: 100%;
    height: 100%;
    padding: 12px 18px;
    box-sizing: border-box;
    backdrop-filter: blur(0.5px);
}

/* ================= TOP QUESTION BANNER ================= */
#gesture-question-banner {
    position: relative;
    background: rgba(15, 23, 42, 0.94);
    border: 2.5px solid #3b82f6;
    border-radius: 20px;
    padding: 10px 20px;
    color: #ffffff;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45), 0 0 15px rgba(59, 130, 246, 0.25);
    min-height: 82px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    transition: all 0.25s ease;
}

.gesture-q-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    margin-bottom: 4px;
    gap: 8px;
}

.gesture-q-badge {
    background: linear-gradient(135deg, #1e40af, #3b82f6);
    color: #fff;
    font-size: 11px;
    font-weight: 900;
    letter-spacing: 0.05em;
    padding: 3px 12px;
    border-radius: 9999px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    text-transform: uppercase;
}

.gesture-q-points-badge {
    background: linear-gradient(135deg, #b45309, #f59e0b);
    color: #fff;
    font-size: 11px;
    font-weight: 900;
    padding: 3px 12px;
    border-radius: 9999px;
    border: 1px solid rgba(255, 255, 255, 0.4);
    box-shadow: 0 2px 6px rgba(245, 158, 11, 0.4);
}

.gesture-timer-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(220, 38, 38, 0.9);
    color: #fff;
    font-size: 12px;
    font-weight: 900;
    padding: 3px 12px;
    border-radius: 9999px;
    border: 1px solid rgba(255, 255, 255, 0.3);
}

#gesture-q-text {
    font-size: clamp(1.05rem, 1.8vw, 1.55rem);
    font-weight: 800;
    line-height: 1.35;
    color: #f8fafc;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.7);
    word-wrap: break-word;
    overflow-wrap: break-word;
    max-width: 96%;
    margin: 2px auto;
}

/* ================= 3-COLUMN ARENA ================= */
#gesture-arena-grid {
    display: grid;
    grid-template-columns: 1fr 1.25fr 1fr;
    gap: 14px;
    align-items: center;
    margin: 6px 0;
    flex: 1;
    min-height: 0;
}

.gesture-col-left,
.gesture-col-right {
    display: flex;
    flex-direction: column;
    gap: 10px;
    height: 100%;
    justify-content: center;
}

/* ================= OPTION CARDS WITH LARGE GESTURE STICKER ================= */
.gesture-option-card {
    position: relative;
    background: rgba(15, 23, 42, 0.94);
    backdrop-filter: blur(8px);
    border: 2.5px solid #334155;
    border-radius: 20px;
    padding: 10px 14px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: clamp(135px, 15vh, 165px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
    cursor: pointer;
    transition: transform 0.15s ease, border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
    overflow: hidden;
}

.gesture-option-card:hover {
    transform: translateY(-2px);
    border-color: #60a5fa;
}

/* Card Header: Letter & Gesture Badge */
.gesture-card-top-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
    gap: 8px;
}

.gesture-opt-letter {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 9999px;
    font-weight: 900;
    font-size: 16px;
    color: #fff;
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.4);
}

/* 4 Distinct Classroom Colors: A (Cyan/Blue), B (Green), C (Orange/Gold), D (Purple/Pink) */
.gesture-card-a .gesture-opt-letter { background: linear-gradient(135deg, #0284c7, #38bdf8); box-shadow: 0 3px 10px rgba(56, 189, 248, 0.45); }
.gesture-card-b .gesture-opt-letter { background: linear-gradient(135deg, #16a34a, #4ade80); box-shadow: 0 3px 10px rgba(74, 222, 128, 0.45); }
.gesture-card-c .gesture-opt-letter { background: linear-gradient(135deg, #ea580c, #f59e0b); box-shadow: 0 3px 10px rgba(245, 158, 11, 0.45); }
.gesture-card-d .gesture-opt-letter { background: linear-gradient(135deg, #9333ea, #ec4899); box-shadow: 0 3px 10px rgba(236, 72, 153, 0.45); }

/* Dynamic Gesture Action Badge on Card */
.gesture-action-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: rgba(30, 41, 59, 0.85);
    border: 1px solid rgba(250, 204, 21, 0.5);
    color: #fef08a;
    font-size: 11px;
    font-weight: 800;
    padding: 2px 10px;
    border-radius: 9999px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}

/* Card Body with Prominent Sticker */
.gesture-card-body {
    display: flex;
    align-items: center;
    gap: 14px;
    flex: 1;
}

/* Large Character Sticker Cutout (130px - 160px for Classroom Visibility) */
.gesture-char-sticker {
    width: clamp(120px, 11vw, 155px);
    height: clamp(130px, 13vw, 160px);
    object-fit: contain;
    flex-shrink: 0;
    border-radius: 14px;
    background: transparent;
    padding: 2px;
    filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.55));
    transition: transform 0.25s ease, filter 0.25s ease;
}

.gesture-opt-text {
    font-size: clamp(1.05rem, 1.35vw, 1.35rem);
    font-weight: 800;
    color: #f8fafc;
    line-height: 1.35;
    word-wrap: break-word;
    overflow-wrap: break-word;
    flex: 1;
}

/* Card Detection & Evaluation States */
.gesture-option-card.holding {
    transform: scale(1.03);
    border-color: #facc15 !important;
    background: rgba(30, 58, 138, 0.96);
    box-shadow: 0 0 26px rgba(250, 204, 21, 0.7);
}
.gesture-option-card.holding .gesture-char-sticker {
    transform: scale(1.12);
}

.gesture-option-card.eval-correct {
    border-color: #22c55e !important;
    background: rgba(22, 101, 52, 0.96) !important;
    box-shadow: 0 0 30px rgba(34, 197, 94, 0.85) !important;
    animation: gesturePulseGreen 0.7s infinite alternate;
}

.gesture-option-card.eval-wrong {
    border-color: #ef4444 !important;
    background: rgba(127, 29, 29, 0.96) !important;
    box-shadow: 0 0 24px rgba(239, 68, 68, 0.75) !important;
}

@keyframes gesturePulseGreen {
    from { transform: scale(1.01); }
    to { transform: scale(1.04); }
}

/* ================= CENTER COLUMN: WEBCAM POD ================= */
#gesture-camera-pod {
    position: relative;
    width: 100%;
    height: 100%;
    min-height: 220px;
    max-height: 310px;
    border-radius: 22px;
    overflow: hidden;
    background: #020617;
    border: 3px solid #38bdf8;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.6), 0 0 20px rgba(56, 189, 248, 0.35);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

#gesture-camera-pod.out-of-frame {
    border-color: #f59e0b !important;
    box-shadow: 0 0 25px rgba(245, 158, 11, 0.6) !important;
}

#gesture-camera-pod.no-person {
    border-color: #64748b !important;
    box-shadow: 0 0 15px rgba(100, 116, 139, 0.4) !important;
}

#gesture-webcam-video {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scaleX(-1); /* Mirror view for natural interaction */
    z-index: 1;
}

#gesture-pose-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scaleX(-1);
    z-index: 2;
    pointer-events: none;
}

/* Dwell Circular Ring Overlay */
#gesture-dwell-ring-wrap {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 5;
    pointer-events: none;
    display: none;
    align-items: center;
    justify-content: center;
}

.gesture-dwell-svg {
    transform: rotate(-90deg);
}

.gesture-dwell-bg-circle {
    fill: rgba(15, 23, 42, 0.75);
    stroke: rgba(255, 255, 255, 0.25);
    stroke-width: 8;
}

.gesture-dwell-bar-circle {
    fill: none;
    stroke: #facc15;
    stroke-width: 8;
    stroke-linecap: round;
    stroke-dasharray: 251.2;
    stroke-dashoffset: 251.2;
    transition: stroke-dashoffset 0.05s linear;
}

.gesture-dwell-label {
    position: absolute;
    font-size: 14px;
    font-weight: 900;
    color: #fef08a;
    text-shadow: 0 2px 6px rgba(0, 0, 0, 0.85);
}

/* Camera Status Banner */
#gesture-camera-status-badge {
    position: absolute;
    bottom: 8px;
    left: 8px;
    right: 8px;
    z-index: 6;
    background: rgba(15, 23, 42, 0.88);
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 9999px;
    padding: 4px 12px;
    font-size: 11px;
    font-weight: 800;
    color: #e2e8f0;
    text-align: center;
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

/* ================= BOTTOM HUD BAR ================= */
#gesture-bottom-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background: rgba(15, 23, 42, 0.94);
    border: 2px solid #334155;
    border-radius: 18px;
    padding: 8px 16px;
    color: #fff;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
}

.gesture-hud-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.gesture-hud-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #1e293b;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 9999px;
    padding: 4px 12px;
    font-size: 12px;
    font-weight: 800;
    color: #f8fafc;
}

.gesture-hud-score {
    background: linear-gradient(135deg, #1e3a8a, #2563eb);
    border-color: #60a5fa;
    color: #fef08a;
}

#gesture-linear-dwell-wrap {
    flex: 1;
    max-width: 180px;
    height: 10px;
    background: #334155;
    border-radius: 9999px;
    overflow: hidden;
    position: relative;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

#gesture-linear-dwell-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #f59e0b, #eab308);
    transition: width 0.05s linear;
}

.gesture-hud-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.gesture-btn-action {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border-radius: 12px;
    font-weight: 800;
    font-size: 12px;
    cursor: pointer;
    border: none;
    transition: all 0.15s ease;
}

.gesture-btn-calib {
    background: #334155;
    color: #f1f5f9;
}
.gesture-btn-calib:hover {
    background: #475569;
}

/* DEDICATED RED "KẾT THÚC" BUTTON (Section XV) */
#btn-gesture-end {
    background: linear-gradient(135deg, #b91c1c, #dc2626);
    color: #fff;
    box-shadow: 0 4px 12px rgba(220, 38, 38, 0.4);
    font-weight: 900;
    padding: 6px 16px;
    border-radius: 12px;
    letter-spacing: 0.03em;
    cursor: pointer;
    border: none;
    transition: all 0.15s ease;
}
#btn-gesture-end:hover {
    background: linear-gradient(135deg, #991b1b, #b91c1c);
    transform: scale(1.04);
}

/* ================= MODALS & SUMMARY ================= */
.gesture-modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.gesture-modal-card {
    background: #0f172a;
    border: 2px solid #3b82f6;
    border-radius: 24px;
    padding: 24px;
    width: 100%;
    max-width: 520px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.75);
    color: #fff;
    text-align: center;
    animation: gestureModalPop 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes gestureModalPop {
    from { transform: scale(0.92); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.gesture-result-heart-thumb {
    width: 90px;
    height: 110px;
    margin: 0 auto 10px;
    object-fit: contain;
    filter: drop-shadow(0 0 3px #ffffff) drop-shadow(0 6px 16px rgba(250, 204, 21, 0.4));
}

.gesture-stat-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin: 16px 0;
    text-align: left;
}

.gesture-stat-box {
    background: #1e293b;
    border: 1px solid #334155;
    border-radius: 14px;
    padding: 10px 14px;
}

.gesture-stat-label {
    font-size: 11px;
    color: #94a3b8;
    font-weight: 700;
    text-transform: uppercase;
}

.gesture-stat-val {
    font-size: 18px;
    font-weight: 900;
    color: #f8fafc;
}

/* Feedback Floating Toast */
#gesture-feedback-toast {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 30;
    padding: 14px 28px;
    border-radius: 9999px;
    font-size: 20px;
    font-weight: 900;
    letter-spacing: 0.05em;
    pointer-events: none;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.65);
    display: none;
    animation: gestureToastPop 0.3s ease;
}

@keyframes gestureToastPop {
    0% { transform: translate(-50%, -50%) scale(0.7); opacity: 0; }
    70% { transform: translate(-50%, -50%) scale(1.1); opacity: 1; }
    100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

/* Responsive adjustments */
@media (max-width: 850px) {
    #gesture-arena-grid {
        grid-template-columns: 1fr 1fr;
        grid-template-rows: auto auto;
    }
    #gesture-camera-pod {
        grid-column: span 2;
        order: -1;
        min-height: 180px;
    }
}

/* Hidden dialogs must stay hidden while external utility CSS is loading. */
.gesture-modal-backdrop.hidden { display: none; }
