* { box-sizing: border-box; margin: 0; padding: 0; font-family: sans-serif; }

/* FIX 1: Thêm overflow-y: auto để cho phép cuộn dọc thay vì khóa chết */
body { background-color: #121212; color: #fff; height: 100vh; overflow-x: hidden; overflow-y: auto; }

/* FIX 2: Đổi height thành min-height để trang web có thể dài ra khi cuộn */
.app-container { display: flex; min-height: 100vh; }

/* Cột trái */
.sidebar { width: 300px; background-color: #1e1e1e; display: flex; flex-direction: column; padding: 20px; border-right: 1px solid #333; }
.title { text-align: center; margin-bottom: 20px; border-bottom: 1px solid #333; padding-bottom: 10px; }

/* --- KHU VỰC DANH SÁCH HÌNH ẢNH (CUỘN ĐỘC LẬP) --- */
.gallery-section { 
    flex: 1; 
    display: flex; 
    flex-direction: column; 
    min-height: 0; 
    margin-bottom: 20px; 
}

.gallery { 
    flex: 1; 
    display: flex; 
    flex-direction: column; 
    gap: 10px; 
    margin-top: 10px; 
    max-height: 180px;
    overflow-y: auto; 
    padding-right: 5px; 
}

/* Trang trí thanh cuộn cho khu vực hình ảnh */
.gallery::-webkit-scrollbar { width: 6px; }
.gallery::-webkit-scrollbar-track { background: #1e1e1e; }
.gallery::-webkit-scrollbar-thumb { background: #555; border-radius: 10px; }
.gallery::-webkit-scrollbar-thumb:hover { background: #888; }

/* --- KHU VỰC SỬA CSS CHO NÚT BẤM (D-PAD & THÔ MỊN) --- */
.control-section { flex-shrink: 0; display: flex; flex-direction: column; gap: 15px; } 

.control-box { background: #252525; padding: 20px 15px; border-radius: 12px; } 

.d-pad { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.d-pad-row { display: flex; justify-content: space-between; width: 190px; }

.focus-container { display: flex; justify-content: space-around; }
.focus-col { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.focus-label { font-size: 18px; color: #e0e0e0; font-weight: bold; }

.btn-arrow { 
    width: 55px; height: 55px; 
    font-size: 24px; display: flex; justify-content: center; align-items: center; 
    cursor: pointer; background: #333; border: none; border-radius: 10px; 
    color: white; transition: 0.15s; 
    user-select: none;
    font-variant-emoji: text;
}
.btn-arrow:active { background: #555; transform: translateY(3px); } 
/* --- KẾT THÚC SỬA CSS NÚT BẤM --- */

/* Cột phải */
.main-content { flex: 1; display: flex; flex-direction: column; padding: 20px; background-color: #000; }

/* ==========================================================
   FIX CHÍNH: Ép thẻ video nằm dưới lớp phủ (position absolute)
   ========================================================== */
.video-container { 
    flex: 1; 
    background-color: #111; 
    border-radius: 8px; 
    overflow: hidden; 
    display: flex; 
    justify-content: center; 
    align-items: center; 
    position: relative; /* Bắt buộc để canh z-index */
}
video { 
    position: absolute; /* Ép video thoát khỏi luồng mặc định */
    top: 0; left: 0;
    width: 100%; height: 100%; 
    object-fit: contain; 
    z-index: 1; /* Nhấn chìm video xuống lớp thấp nhất */
}

/* Thêm z-index và position cho bottom-bar để nó không bị video đè lên ở giao diện thường */
.bottom-bar { display: flex; justify-content: center; gap: 20px; padding-top: 20px; position: relative; z-index: 10; }
.btn { padding: 10px 20px; font-size: 16px; font-weight: bold; cursor: pointer; background: #007bff; color: white; border: none; border-radius: 5px; transition: background 0.2s; }
.btn:hover { background: #0056b3; }

/* --- CSS CHO DANH SÁCH ẢNH VÀ HIỆU ỨNG HOVER --- */
.gallery-item {
    position: relative;
    border: 2px solid #444;
    border-radius: 5px;
    overflow: hidden;
    flex-shrink: 0;
}

.gallery-item img {
    width: 100%;
    display: block; 
}

.gallery-overlay {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.gallery-item:hover .gallery-overlay {
    opacity: 1; 
}

.icon-btn {
    background: none;
    border: none;
    color: white;
    font-size: 28px;
    cursor: pointer;
    transition: transform 0.2s;
    text-shadow: 0 2px 5px rgba(0,0,0,0.8);
}

.icon-btn:hover {
    transform: scale(1.3); 
}

.icon-btn.delete-btn:hover {
    color: #ff4444; 
}

/* --- CSS CHO KHUNG PHÓNG TO ẢNH (MODAL) --- */
.modal {
    position: fixed;
    z-index: 1000;
    left: 0; top: 0; width: 100%; height: 100%;
    background-color: rgba(0,0,0,0.9); 
    display: flex;
    justify-content: center;
    align-items: center;
}

.modal.hidden {
    display: none;
}

.modal-content {
    max-width: 90%;
    max-height: 90%;
    border-radius: 5px;
    box-shadow: 0 0 20px rgba(0,0,0,0.5);
    border: 2px solid #333;
    object-fit: contain;
    cursor: grab;
    transition: transform 0.1s ease-out; 
}

.modal-content:active {
    cursor: grabbing; 
    transition: none; 
}

.close-modal {
    position: absolute;
    top: 20px;
    right: 35px;
    color: #f1f1f1;
    font-size: 40px;
    font-weight: bold;
    cursor: pointer;
    transition: 0.3s;
    z-index: 1001;
}

.close-modal:hover {
    color: #ff4444;
}

/* ==========================================
   FAKE FULLSCREEN CHO iOS (position fixed)
   ========================================== */
.video-container.fake-fullscreen {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    z-index: 99999 !important;
    border-radius: 0 !important;
    background: #000 !important;
}

/* =========================================
   GIAO DIỆN ĐIỀU KHIỂN TOÀN MÀN HÌNH (OSD)
   ========================================= */

.fullscreen-overlay {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    /* Căn xuống góc dưới hai bên */
    justify-content: space-between;
    align-items: flex-end;
    padding: 0 2% 3%;
    box-sizing: border-box;
    z-index: 9999;
}

/* Kích hoạt qua JS class (đáng tin cậy nhất - hoạt động trên mọi trình duyệt) */
#video-wrapper.show-osd .fullscreen-overlay {
    display: flex !important;
}

/* Kích hoạt qua CSS native fullscreen (dự phòng thêm) */
#video-wrapper:fullscreen .fullscreen-overlay,
#video-wrapper:-webkit-full-screen .fullscreen-overlay,
#video-wrapper:-moz-full-screen .fullscreen-overlay,
#video-wrapper:-ms-fullscreen .fullscreen-overlay {
    display: flex !important;
}

.fs-group-left, .fs-group-right {
    pointer-events: auto;
    display: flex;
    gap: 15px;
    /* Nền rất mờ, gần như trong suốt */
    background: rgba(0, 0, 0, 0.18);
    padding: 14px;
    border-radius: 18px;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    /* Mờ khi không tương tác */
    opacity: 0.35;
    transition: opacity 0.3s ease;
}

/* Khi hover vào nhóm nút thì hiện rõ lên */
.fs-group-left:hover, .fs-group-right:hover,
.fs-group-left:active, .fs-group-right:active {
    opacity: 1;
}

.fs-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.fs-label {
    color: rgba(255, 255, 255, 0.8);
    font-weight: bold;
    font-size: 0.85rem;
    text-shadow: 1px 1px 3px black;
    letter-spacing: 1px;
}

.fs-d-pad {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
}

.fs-d-pad-row {
    display: flex;
    gap: 40px;
}

.fs-btn {
    background: rgba(0, 0, 0, 0.45);
    border: 1.5px solid rgba(255, 255, 255, 0.15);
    color: rgba(255, 255, 255, 0.75);
    font-size: 1.5rem;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: background 0.15s ease, transform 0.1s ease, border-color 0.15s ease;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
    /* Ép emoji hiển thị dạng text (đen trắng) thay vì màu */
    font-variant-emoji: text;
}

.fs-btn:hover {
    background: rgba(0, 0, 0, 0.65);
    border-color: rgba(255, 255, 255, 0.4);
    color: white;
}

.fs-btn:active {
    background: rgba(30, 30, 30, 0.85);
    border-color: rgba(255, 255, 255, 0.7);
    color: white;
    transform: scale(0.88);
}

/* ==========================================
   GIAO DIỆN RESPONSIVE CHO ĐIỆN THOẠI (MOBILE)
   ========================================== */
@media screen and (max-width: 1000px) {
    body {
        height: auto;
        overflow: auto;
    }

    .app-container {
        flex-direction: column;
        height: auto;
    }

    .main-content {
        order: 1; 
        padding: 10px;
        min-height: 40vh; 
    }

    .sidebar {
        order: 2; 
        width: 100%; 
        border-right: none;
        border-top: 2px solid #333; 
        padding: 15px 10px;
    }

    .btn-arrow {
        padding: 15px 20px;
        font-size: 28px;
    }

    .bottom-bar {
        flex-wrap: wrap; 
    }

    .btn {
        width: 100%; 
        margin-bottom: 10px;
    }
}