/* ======================================================
   1. CAU TRUC CO BAN & CHUYEN CANH
====================================================== */
section.screen {
    display: none;
}

section.screen.active {
    display: flex;
}

body.camera-immersive {
    overflow: hidden;
}

/* ======================================================
   2. HE THONG ANIMATION
====================================================== */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes camera-flash {
    0% { opacity: 0; }
    15% { opacity: 0.85; }
    100% { opacity: 0; }
}

@keyframes pulse-red {
    0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.4); }
    70% { transform: scale(1.05); box-shadow: 0 0 0 10px rgba(220, 38, 38, 0); }
    100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(220, 38, 38, 0); }
}

.animate-fade-in { animation: fadeIn 0.5s ease-out forwards; }
.camera-flash-active { animation: camera-flash 0.25s ease-out; }

/* ======================================================
   3. CAMERA & VIEWFINDER
====================================================== */
#cameraLayout,
#cameraContainer {
    width: 100%;
}

#cameraContainer {
    display: flex;
    justify-content: center;
}

.camera-shell {
    width: 100%;
}

#cameraViewfinder {
    width: 100%;
    margin: 0 auto;
    background: #020617;
}

#video {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
    object-position: center center;
    background: transparent;
}

.countdownNumber {
    opacity: 0.65;
    text-shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
    transition: all 0.25s ease;
}

#countdown.show .countdownNumber {
    opacity: 0.85;
    transform: scale(1.05);
}

#abortZone button div {
    animation: pulse-red 2s infinite;
}

/* ======================================================
   4. TOI UU CHO MOBILE DOC (< 768px)
====================================================== */
@media (max-width: 767px) {
    #camera {
        min-height: 100svh;
        padding: 0.75rem 0.75rem max(1rem, env(safe-area-inset-bottom));
        align-items: stretch;
    }

    #cameraLayout {
        width: 100%;
        min-height: calc(100svh - 1.5rem - env(safe-area-inset-bottom));
        justify-content: space-between;
        gap: 1rem;
    }

    #cameraContainer {
        flex: 1;
        max-width: none;
        align-items: center;
    }

    .camera-shell {
        width: 100%;
        padding: 0.35rem;
        border-width: 6px;
        border-radius: 2rem;
    }

    #cameraViewfinder {
        width: 100% !important;
        max-width: 100% !important;
        max-height: calc(100svh - 12rem - env(safe-area-inset-bottom)) !important;
        height: auto !important;
        border-radius: 1.5rem;
        margin: 0 auto;
    }

    .group-controls-wrapper {
        width: 100%;
        max-width: none;
    }

    #mainControlsGroup {
        width: 100%;
        gap: 1rem;
    }

    #controls {
        width: 100%;
        justify-content: center;
    }

    #camera.is-mobile-expanded {
        padding: 0.5rem;
    }

    #camera.is-mobile-expanded .camera-shell {
        width: 100%;
        padding: 4px;
        border-width: 4px;
        border-radius: 2rem;
        box-shadow: 0 30px 70px -28px rgba(185, 28, 28, 0.28);
    }

    #camera.is-mobile-expanded #cameraViewfinder {
        max-height: calc(100svh - 8.75rem - env(safe-area-inset-bottom)) !important;
    }

    #camera.is-mobile-expanded #mainControlsGroup {
        gap: 0.75rem;
    }
}

/* ======================================================
   5. TOI UU CHO LANDSCAPE MOBILE & TABLET
====================================================== */
@media (orientation: landscape) and (max-width: 1024px) {
    #camera {
        display: flex;
        min-height: 100svh;
        padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    }

    #cameraLayout {
        flex-direction: row !important;
        align-items: center !important;
        width: 100%;
        min-height: calc(100svh - env(safe-area-inset-top) - env(safe-area-inset-bottom));
        gap: 1.5rem;
    }

    #cameraContainer {
        flex: 1;
        max-width: min(78vw, 900px);
    }

    #cameraViewfinder {
        width: 100% !important;
        max-height: calc(100svh - 2rem - env(safe-area-inset-top) - env(safe-area-inset-bottom)) !important;
    }

    .group-controls-wrapper {
        flex: 0 0 auto;
        display: flex;
        justify-content: center;
        width: auto;
    }

    #mainControlsGroup {
        flex-direction: column !important;
        scale: 0.9;
        gap: 1rem;
    }

}

@media (orientation: landscape) and (max-width: 767px) {
    #cameraLayout { gap: 0.75rem; }
    #mainControlsGroup { scale: 0.8; }
    #camera.is-mobile-expanded #cameraContainer { max-width: min(82vw, 900px); }
}
