/* ==========================================================================
   HEADTILT CAMERA AI QUIZ: TRẮC NGHIỆM LINH HOẠT 2 LỰA CHỌN
   GiaovienGenz 2.0 SafeUI Module
   Aspect Ratio: 16:9 | Fullscreen Support | 100% Original Background Image
   ========================================================================== */

/* Main 16:9 Stage Viewport Container */
#headtilt-game-container {
    position: relative;
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    aspect-ratio: 16 / 9;
    border-radius: 1.5rem;
    overflow: hidden;
    box-shadow: 0 12px 35px -5px rgba(15, 23, 42, 0.25);
    border: 3px solid #cbd5e1;
    background-color: #0f172a;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    user-select: none;
}

/* Background Layer - 100% Original Schoolyard Image without any filter or stretch */
.headtilt-bg-layer {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    background-image: url('assets/san-truong-headtilt.jpg');
    background-size: contain;
    background-position: center;
    background-repeat: no-repeat;
    z-index: 1;
    pointer-events: none;
}

/* Interactive UI Layer on top of background */
.headtilt-ui-layer {
    position: relative;
    z-index: 10;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 0.85rem 1.25rem 0.65rem 1.25rem;
    box-sizing: border-box;
}

/* TOP AREA: QUESTION CARD */
.headtilt-question-card {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 3px solid #2563eb;
    border-radius: 1.25rem;
    padding: 0.65rem 1.25rem;
    box-shadow: 0 8px 24px -4px rgba(37, 99, 235, 0.25);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    min-height: 68px;
}

.headtilt-q-badge {
    background: #1e40af;
    color: #ffffff;
    font-family: 'Baloo 2', sans-serif;
    font-weight: 800;
    font-size: 0.85rem;
    padding: 0.35rem 0.75rem;
    border-radius: 0.75rem;
    white-space: nowrap;
    letter-spacing: 0.05em;
    flex-shrink: 0;
}

.headtilt-q-text {
    font-family: 'Baloo 2', sans-serif;
    font-weight: 800;
    font-size: 1.25rem;
    color: #0f172a;
    line-height: 1.3;
    text-align: center;
    flex: 1;
    text-shadow: 0 1px 2px rgba(255, 255, 255, 0.8);
    overflow-wrap: break-word;
    word-break: break-word;
}

.headtilt-timer-badge {
    background: #fef3c7;
    color: #b45309;
    border: 2px solid #f59e0b;
    font-family: 'Nunito', sans-serif;
    font-weight: 900;
    font-size: 0.95rem;
    padding: 0.35rem 0.75rem;
    border-radius: 0.75rem;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 0.35rem;
    flex-shrink: 0;
    transition: all 0.2s;
}

.headtilt-timer-badge.timer-paused {
    background: #f1f5f9 !important;
    color: #64748b !important;
    border-color: #cbd5e1 !important;
}

/* MIDDLE AREA: 3 COLUMNS (LEFT 29% - CENTER 42% - RIGHT 29%) */
.headtilt-arena-grid {
    display: grid;
    grid-template-columns: 29% 42% 29%;
    gap: 0.85rem;
    align-items: center;
    flex: 1;
    margin: 0.4rem 0;
}

/* Flexible Answer Cards */
.headtilt-answer-card {
    height: 100%;
    max-height: 250px;
    border-radius: 1.25rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 0.85rem 1rem;
    cursor: pointer;
    transition: all 0.22s cubic-bezier(0.34, 1.56, 0.64, 1);
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.3);
    position: relative;
    overflow: hidden;
    text-align: center;
}

/* Theme 1 (Vibrant Blue) */
.headtilt-answer-card.theme-opt-1 {
    background: linear-gradient(135deg, #1d4ed8 0%, #2563eb 60%, #3b82f6 100%);
    border: 4px solid #93c5fd;
    color: #ffffff;
}

/* Theme 2 (Vibrant Purple / Indigo) */
.headtilt-answer-card.theme-opt-2 {
    background: linear-gradient(135deg, #6d28d9 0%, #7c3aed 60%, #8b5cf6 100%);
    border: 4px solid #c4b5fd;
    color: #ffffff;
}

/* Theme 3 (Vibrant Amber / Orange) */
.headtilt-answer-card.theme-opt-3 {
    background: linear-gradient(135deg, #c2410c 0%, #ea580c 60%, #f97316 100%);
    border: 4px solid #fdba74;
    color: #ffffff;
}

/* Active Highlight during Tilt Hold */
.headtilt-answer-card.active-selected {
    transform: scale(1.05);
    border-color: #ffffff !important;
}
.headtilt-answer-card.theme-opt-1.active-selected {
    box-shadow: 0 0 35px 8px rgba(59, 130, 246, 0.85);
}
.headtilt-answer-card.theme-opt-2.active-selected {
    box-shadow: 0 0 35px 8px rgba(139, 92, 246, 0.85);
}
.headtilt-answer-card.theme-opt-3.active-selected {
    box-shadow: 0 0 35px 8px rgba(249, 115, 22, 0.85);
}

/* Evaluation Feedback States */
.headtilt-answer-card.eval-correct {
    background: linear-gradient(135deg, #059669 0%, #10b981 100%) !important;
    border-color: #a7f3d0 !important;
    box-shadow: 0 0 40px 10px rgba(16, 185, 129, 0.9) !important;
    animation: headtilt-pulse 0.8s infinite alternate;
}
.headtilt-answer-card.eval-wrong {
    background: linear-gradient(135deg, #dc2626 0%, #ef4444 100%) !important;
    border-color: #fecaca !important;
    box-shadow: 0 0 40px 10px rgba(239, 68, 68, 0.85) !important;
    animation: headtilt-shake 0.4s ease-in-out;
}

@keyframes headtilt-pulse {
    0% { transform: scale(1.02); }
    100% { transform: scale(1.07); }
}

@keyframes headtilt-shake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-6px); }
    40%, 80% { transform: translateX(6px); }
}

.headtilt-opt-badge {
    position: absolute;
    top: 0.5rem;
    font-family: 'Baloo 2', sans-serif;
    font-size: 0.75rem;
    font-weight: 800;
    padding: 0.2rem 0.6rem;
    border-radius: 9999px;
    background: rgba(0, 0, 0, 0.25);
    border: 1px solid rgba(255, 255, 255, 0.3);
    text-transform: uppercase;
}

.headtilt-option-text {
    font-family: 'Baloo 2', sans-serif;
    font-weight: 900;
    font-size: 1.75rem;
    line-height: 1.25;
    letter-spacing: 0.02em;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.35);
    overflow-wrap: break-word;
    word-break: break-word;
    max-width: 100%;
}

.headtilt-option-hint {
    font-family: 'Nunito', sans-serif;
    font-size: 0.78rem;
    font-weight: 800;
    opacity: 0.95;
    margin-top: 0.4rem;
    text-align: center;
    background: rgba(0, 0, 0, 0.2);
    padding: 0.2rem 0.6rem;
    border-radius: 9999px;
}

/* Center Camera Stage */
.headtilt-camera-pod {
    position: relative;
    width: 100%;
    max-width: 360px;
    margin: 0 auto;
    aspect-ratio: 4 / 3;
    background: rgba(15, 23, 42, 0.9);
    border-radius: 1.25rem;
    border: 3px solid #38bdf8;
    overflow: hidden;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Mirrored Real Webcam Video */
#headtilt-webcam-video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scaleX(-1);
    border-radius: 1.15rem;
}

/* Overlay Canvas */
#headtilt-tracking-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    transform: scaleX(-1);
}

/* Tracking Status Badge on Camera */
.headtilt-status-badge {
    position: absolute;
    bottom: 0.45rem;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(15, 23, 42, 0.88);
    backdrop-filter: blur(6px);
    color: #ffffff;
    font-family: 'Nunito', sans-serif;
    font-size: 0.72rem;
    font-weight: 800;
    padding: 0.22rem 0.65rem;
    border-radius: 9999px;
    white-space: nowrap;
    border: 1px solid rgba(255, 255, 255, 0.2);
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

/* Direction Arrow Guides */
.headtilt-guide-arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    font-size: 1.75rem;
    color: rgba(255, 255, 255, 0.45);
    transition: all 0.2s;
    z-index: 15;
}
.headtilt-guide-left { left: 0.5rem; }
.headtilt-guide-right { right: 0.5rem; }
.headtilt-guide-arrow.active {
    color: #facc15;
    transform: translateY(-50%) scale(1.35);
    text-shadow: 0 0 15px #facc15;
}

/* Dwell Circular Progress Ring */
.headtilt-dwell-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 86px;
    height: 86px;
    pointer-events: none;
    z-index: 25;
    display: none;
}
.headtilt-dwell-overlay.active {
    display: block;
}

/* BOTTOM AREA: COMPACT HUD & CONTROLS */
.headtilt-bottom-bar {
    background: rgba(255, 255, 255, 0.94);
    backdrop-filter: blur(8px);
    border: 2px solid #e2e8f0;
    border-radius: 1rem;
    padding: 0.35rem 0.85rem;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    box-shadow: 0 4px 15px -3px rgba(0, 0, 0, 0.1);
}

.headtilt-meta-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-family: 'Baloo 2', sans-serif;
    font-weight: 800;
    font-size: 0.82rem;
}

.headtilt-score-pill {
    background: #fefce8;
    color: #854d0e;
    border: 1px solid #fef08a;
    padding: 0.2rem 0.55rem;
    border-radius: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.headtilt-actions-group {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

/* End Game Button in Bottom Bar */
.btn-headtilt-end {
    background: #e11d48;
    color: #ffffff;
    border: none;
    border-radius: 0.75rem;
    padding: 0.3rem 0.75rem;
    font-family: 'Baloo 2', sans-serif;
    font-weight: 800;
    font-size: 0.8rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.35rem;
    transition: all 0.2s;
    box-shadow: 0 2px 6px rgba(225, 29, 72, 0.35);
}
.btn-headtilt-end:hover {
    background: #be123c;
    transform: scale(1.03);
}

/* Fullscreen Mode Rules */
#headtilt-game-container:fullscreen {
    width: 100vw !important;
    height: 100vh !important;
    max-width: none !important;
    border-radius: 0 !important;
    border: none !important;
    margin: 0 !important;
    padding: 0 !important;
    background: #020617 !important;
    align-items: center;
    justify-content: center;
}

#headtilt-game-container:fullscreen .headtilt-ui-layer {
    max-width: 1366px;
    height: 100vh;
    padding: 1.25rem 2rem 0.85rem 2rem;
}

#headtilt-game-container:fullscreen .headtilt-question-card {
    min-height: 80px;
}
#headtilt-game-container:fullscreen .headtilt-q-text {
    font-size: 1.55rem;
}
#headtilt-game-container:fullscreen .headtilt-option-text {
    font-size: 2.2rem;
}
#headtilt-game-container:fullscreen .headtilt-camera-pod {
    max-width: 420px;
}

/* Touch Exit Button */
.headtilt-touch-exit-btn {
    display: none;
}
@media (hover: none) and (pointer: coarse) {
    #headtilt-game-container:fullscreen .headtilt-touch-exit-btn {
        display: flex !important;
    }
}

/* MODALS: Confirm End Modal & Summary Screen Modal */
.headtilt-modal-backdrop {
    position: absolute;
    inset: 0;
    z-index: 60;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.headtilt-modal-card {
    background: #ffffff;
    border: 3px solid #3b82f6;
    border-radius: 1.5rem;
    padding: 1.75rem;
    max-width: 460px;
    width: 100%;
    text-align: center;
    box-shadow: 0 20px 45px -10px rgba(0, 0, 0, 0.5);
    animation: headtilt-pop 0.28s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes headtilt-pop {
    from { transform: scale(0.88); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

/* Hidden dialogs must stay hidden while external utility CSS is loading. */
.headtilt-modal-backdrop.hidden { display: none; }
