/* ==========================================================
   RESPONSIVE GAME ARCHITECTURE - LANDSCAPE (CHUẨN MÀN HÌNH NGANG)
   ========================================================== */

/* 1. THIẾT LẬP NỀN TẢNG TOÀN MÀN HÌNH NGANG */
html, body {
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    margin: 0;
    padding: 0;
    overflow: hidden;
    position: fixed;
    inset: 0;
    background: #080503;
    font-family: 'Montserrat', sans-serif;
    color: #fff;
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

/* 2. CHẶN ĐỘ TRỄ CHẠM & TỰ ĐỘNG SCALE CHỮ / NÚT */
button,
[role="button"],
input,
select,
textarea,
.chip-item,
.casino-door-bet,
.xocdia-choice,
.phone-home-indicator,
.casino-icon-button,
.casino-mode-button {
    touch-action: manipulation !important;
    -webkit-tap-highlight-color: transparent !important;
    cursor: pointer;
}

/* 3. MÀN HÌNH PHÒNG TRỌ (ROOM SIMULATION) THEO BỐ CỤC NGANG */
#roomSimulationView {
    flex: 1 1 0;
    min-height: 0;
    width: 100%;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    overflow: hidden;
}

/* Hộp thông tin căn hộ / phòng trọ trên cùng góc trái - Giữ nhỏ gọn, không kéo dài ngang */
#roomSimulationView > div:first-child > div:first-child {
    max-width: 340px !important;
    width: auto !important;
    flex: 0 0 auto !important;
}

/* Nút MỞ SÒNG TÀI XỈU dưới cùng - Kích thước chuẩn đẹp, không bị giãn bè ngang */
#roomSimulationView > div:last-child button:first-child {
    max-width: 260px !important;
    width: auto !important;
    flex: 0 0 auto !important;
}

.char-stage {
    transform-origin: bottom center;
    transition: transform 0.25s ease;
}

/* Tự động scale nhân vật và đồ nội thất theo chiều cao màn hình ngang */
@media (max-height: 480px) {
    header {
        padding: 3px 8px !important;
    }
    #luckBadge {
        display: none !important;
    }
    #charAvatarIcon {
        font-size: 13px !important;
    }
    #charNameDisplay {
        font-size: 11px !important;
    }
    #charRankBadge {
        font-size: 8px !important;
        padding: 1px 4px !important;
    }
    header .text-\[10px\] {
        font-size: 8px !important;
    }
    #userBalanceDisplay {
        font-size: 13px !important;
    }
    header button {
        padding: 3px 7px !important;
        font-size: 10px !important;
    }

    #roomSimulationView {
        padding: 4px 10px !important;
    }
    #roomSimulationView > div:first-child {
        margin-bottom: 2px !important;
    }
    #roomSimulationView > div:first-child > div {
        padding: 2px 8px !important;
    }
    #roomNameLabel {
        font-size: 9px !important;
    }
    #roomDescLabel {
        font-size: 9px !important;
    }
    #currentCarName {
        font-size: 9px !important;
    }

    /* Nhân vật và nội thất co giãn vừa vặn không bị tràn */
    .char-stage {
        transform: scale(0.58) !important;
        height: 200px !important;
    }
    #roomObj_vehicle, #roomObj_fan, #roomObj_laptop, #roomObj_cooker {
        transform: scale(0.65) !important;
        transform-origin: bottom center !important;
    }

    #roomSimulationView > div:last-child {
        padding-top: 3px !important;
    }
    #roomSimulationView > div:last-child button {
        padding: 4px 8px !important;
        font-size: 10px !important;
    }
}

@media (min-height: 481px) and (max-height: 650px) {
    .char-stage {
        transform: scale(0.78);
        height: 260px;
    }
    #roomObj_vehicle, #roomObj_fan, #roomObj_laptop, #roomObj_cooker {
        transform: scale(0.82);
        transform-origin: bottom center;
    }
}

@media (min-height: 651px) {
    .char-stage {
        transform: scale(1);
    }
}

/* 4. SÒNG BẠC CASINO LOBBY TRÊN MÀN HÌNH NGANG (PC & MOBILE LANDSCAPE) */
#taiXiuCasinoModal {
    align-items: center;
    justify-content: center;
    padding: clamp(6px, 1.5vw, 20px);
    overflow: hidden;
}

#casinoLobbyShell {
    width: min(94vw, 1260px);
    height: min(88dvh, 760px);
    max-height: 88dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid rgba(227, 194, 110, 0.82);
    border-radius: 18px;
    background-color: #090b0b;
    box-shadow: 0 25px 80px rgba(0, 0, 0, 0.95), 0 0 30px rgba(215, 180, 91, 0.16);
}

#casinoTopBar {
    min-height: 52px;
    padding: 6px clamp(10px, 2vw, 24px);
    display: grid;
    grid-template-columns: minmax(140px, 1fr) auto minmax(140px, 1fr);
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid rgba(215, 180, 91, 0.45);
    background: linear-gradient(180deg, rgba(28, 24, 16, 0.98), rgba(11, 12, 12, 0.98));
    flex-shrink: 0;
}

.casino-mode-switch {
    display: flex;
    gap: 8px;
    padding: 5px 12px;
    background: #0d0d0d;
    border-bottom: 1px solid rgba(215, 180, 91, 0.25);
    flex-shrink: 0;
}

.casino-mode-button {
    flex: 1;
    min-height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border-radius: 10px;
    border: 1px solid rgba(215, 180, 91, 0.3);
    background: rgba(255, 255, 255, 0.04);
    color: #e5c986;
    font-weight: 800;
    font-size: 12px;
    transition: all 0.2s ease;
}

.casino-mode-button.active {
    background: linear-gradient(135deg, #78521c, #352109);
    border-color: #f5d061;
    color: #ffe6a0;
    box-shadow: 0 0 14px rgba(245, 208, 97, 0.35);
}

#casinoLobbyGrid {
    flex: 1 1 0;
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(200px, 24%);
    gap: 8px;
    padding: 0 8px 8px;
    overflow: hidden;
}

#casinoGameStage {
    flex: 1 1 0;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 4px;
}

.casino-chat-panel {
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: rgba(14, 11, 9, 0.85);
    border: 1px solid rgba(215, 180, 91, 0.3);
    border-radius: 14px;
}

.casino-chat-messages {
    flex: 1 1 0;
    min-height: 0;
    overflow-y: auto;
}

/* 5. TỐI ƯU SÒNG BẠC CHO MOBILE LANDSCAPE (CHIỀU CAO <= 500PX) */
@media (orientation: landscape) and (max-height: 500px) {
    #casinoLobbyShell {
        width: 98vw !important;
        height: 96dvh !important;
        max-height: 96dvh !important;
        min-height: 0 !important;
        border-radius: 12px !important;
    }

    #casinoTopBar {
        min-height: 40px !important;
        padding: 4px 10px !important;
        grid-template-columns: minmax(100px, 1fr) auto minmax(100px, 1fr) !important;
        gap: 6px !important;
    }
    .casino-avatar {
        width: 28px !important;
        height: 28px !important;
        flex: 0 0 28px !important;
    }
    .casino-avatar i { font-size: 12px !important; }
    .casino-player-name { font-size: 10px !important; }
    .casino-eyebrow { font-size: 7px !important; }
    .casino-wallet {
        min-width: 0 !important;
        padding: 3px 8px !important;
        font-size: 11px !important;
        gap: 4px !important;
    }
    .casino-wallet > i { font-size: 11px !important; }
    .casino-icon-button {
        width: 28px !important;
        height: 28px !important;
        font-size: 11px !important;
    }

    .casino-mode-switch {
        padding: 3px 8px !important;
        gap: 6px !important;
    }
    .casino-mode-button {
        min-height: 30px !important;
        font-size: 10px !important;
    }
    .casino-mode-button small { display: none !important; }

    #casinoLobbyGrid {
        grid-template-columns: minmax(0, 1fr) minmax(170px, 20%) !important;
        gap: 6px !important;
        padding: 0 6px 6px !important;
    }

    /* BÀN TÀI XỈU 3 CỘT: TÀI (TRÁI) - BÁT XÚC XẮC (GIỮA) - XỈU (PHẢI) */
    .gold-plate-border {
        border-radius: 18px !important;
        padding: 3px !important;
    }
    .wood-inner-panel {
        border-radius: 16px !important;
        padding: 6px 8px !important;
    }

    .wood-inner-panel .grid.lg\:grid-cols-12 {
        display: grid !important;
        grid-template-columns: 1fr 130px 1fr !important;
        gap: 6px !important;
        align-items: stretch !important;
        margin-bottom: 4px !important;
    }

    #taiBox, #xiuBox {
        padding: 6px 8px !important;
        border-radius: 14px !important;
        min-height: 115px !important;
        display: flex !important;
        flex-direction: column !important;
        justify-content: space-between !important;
    }

    #taiBox .text-4xl, #taiBox .sm\:text-5xl,
    #xiuBox .text-4xl, #xiuBox .sm\:text-5xl {
        font-size: 22px !important;
        margin: 1px 0 !important;
    }

    #taiPoolNumber, #xiuPoolNumber {
        font-size: 12px !important;
    }

    .casino-door-bet {
        min-height: 28px !important;
        padding: 2px 6px !important;
        font-size: 9px !important;
    }

    /* BÁT XÚC XẮC Ở GIỮA */
    .wood-inner-panel .lg\:col-span-2 > div:first-child {
        width: 115px !important;
        height: 115px !important;
    }
    .dice-3d {
        width: 24px !important;
        height: 24px !important;
        padding: 3px !important;
    }
    .dice-3d .pip { width: 5px !important; height: 5px !important; }
    .dice-1 .pip { width: 8px !important; height: 8px !important; }
    #bowlStatus { font-size: 8px !important; }
    #countdownTimer { font-size: 20px !important; }

    /* DÒNG NÚT CHIP & ĐẶT CƯỢC DƯỚI BÀN */
    .wood-inner-panel .mt-6 {
        margin-top: 4px !important;
        padding-top: 4px !important;
        gap: 4px !important;
    }

    .chip-item {
        width: 30px !important;
        height: 30px !important;
        min-height: 30px !important;
        font-size: 9px !important;
    }
    .casino-all-in, .casino-cancel-bet {
        padding: 3px 6px !important;
        font-size: 9px !important;
        min-height: 28px !important;
    }
    #confirmBetBtn {
        padding: 6px 12px !important;
        font-size: 11px !important;
        min-height: 34px !important;
        border-radius: 10px !important;
    }

    /* BÀN CHƠI XÓC ĐĨA TRÊN MÀN HÌNH NGANG */
    .xocdia-heading { min-height: 28px !important; padding: 2px 4px !important; }
    .xocdia-heading h1 { font-size: 14px !important; }
    .xocdia-layout {
        grid-template-columns: minmax(95px, 20%) minmax(130px, 1fr) minmax(95px, 20%) !important;
        gap: 4px !important;
        padding: 4px !important;
    }
    .xocdia-history-dots { min-height: 32px !important; gap: 3px !important; }
    .xocdia-history-dot { width: 18px !important; height: 18px !important; }
    .xocdia-choice { min-height: 40px !important; }
    .xocdia-npc { top: 2px !important; transform: translateX(-50%) scale(0.6) !important; transform-origin: top center !important; }
    .xocdia-bowl-area { bottom: 8px !important; transform: translateX(-50%) scale(0.72) !important; transform-origin: bottom center !important; }
    .xocdia-chips button { height: 24px !important; font-size: 8px !important; }
    .xocdia-confirm-bet { min-height: 32px !important; font-size: 10px !important; }
}

/* 6. ĐIỆN THOẠI IPHONE TRONG GAME (POPUP MÀN HÌNH DỌC GIỮA NỀN NGANG) */
#phoneBackdrop {
    padding: clamp(8px, 2dvh, 20px) !important;
    align-items: center !important;
    justify-content: center !important;
}

#phoneBackdrop .iphone-frame {
    width: min(88vw, 360px, calc(88dvh * 370 / 670)) !important;
    height: auto !important;
    max-height: 90dvh !important;
    aspect-ratio: 370 / 670 !important;
    border-radius: 36px !important;
    border: 4px solid #3d3b42 !important;
    box-shadow: 0 25px 75px rgba(0, 0, 0, 0.98), 0 0 0 1px rgba(255, 255, 255, 0.12) !important;
    flex: 0 1 auto !important;
}

#phoneCloseButton {
    position: fixed !important;
    top: max(12px, env(safe-area-inset-top)) !important;
    right: max(12px, env(safe-area-inset-right)) !important;
    width: 38px !important;
    height: 38px !important;
    font-size: 16px !important;
    z-index: 70 !important;
}

/* 7. MODALS KHÁC (TỦ ĐỒ, GA-RA, CẢNH SÁT) TRÊN MÀN HÌNH NGANG */
#wardrobeModal > div,
#garageModal > div,
#policeCatchModal > div {
    max-height: 90dvh !important;
    overflow-y: auto !important;
    border-radius: 20px !important;
}
