﻿

html, body, #main-content, #game-container {
    height: 100dvh !important; /* Thay vh bằng dvh */
    width: 100dvw !important;
    margin: 0;
    padding: 0;
    overflow: hidden;
    position: fixed;
    top: 0;
    left: 0;
}

canvas { 
    image-rendering: -webkit-optimize-contrast; 
    image-rendering: crisp-edges;
}

canvas {
    user-select: none;
    -webkit-tap-highlight-color: rgba(0,0,0,0); /* Bỏ viền xanh khi chạm trên iOS */
}

canvas {
    width: 100dvw !important;  /* Tự động co/giãn bề rộng bằng 100% màn hình */
    height: 100dvh !important; /* Tự động co/giãn chiều cao bằng 100% màn hình */
    position: fixed;
    top: 0;
    left: 0;
    object-fit: fill; /* Ép mọi thứ phải nằm gọn trong màn hình */
}

/* Nếu màn hình đang dọc (Portrait) */
@media screen and (orientation: portrait) {
  #game-container {
    width: 100dvh; /* Dùng dvh */
    height: 100dvw;
    transform: rotate(90deg);
    transform-origin: center;
    position: fixed;
    /* Thay vì tính margin-top phức tạp, dùng cách này để căn giữa chuẩn hơn */
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(90deg);
    margin: 0 !important; 
  }
}

/* Nếu màn hình đang ngang (Landscape) */
@media screen and (orientation: landscape) {
  #game-container {
    width: 100vw;
    height: 100vh;
    transform: none;
  }
}

button:hover {
    background: #444 !important;
    border-color: #fff !important;
    color: #fff !important;
}

        /* .login-card { background: #2a2a2a; padding: 30px; border-radius: 8px; border: 1px solid #D4AF37; width: 300px; color: white; } */

        .login-card {
            background: #2a2a2a;
            padding: 20px;
            /* Giảm padding */
            border-radius: 8px;
            border: 1px solid #D4AF37;
            width: 90%;
            /* Dùng % để tự co trên Mobile */
            max-width: 300px;
            color: white;
            z-index: 100;
        }

        input {
            width: 100%;
            padding: 10px;
            margin: 10px 0;
            background: #333;
            border: 1px solid #555;
            color: white;
            box-sizing: border-box;
        }

        button {
            width: 100%;
            padding: 10px;
            background: #D4AF37;
            border: none;
            font-weight: bold;
            cursor: pointer;
        }

        #status {
            color: #00ff00;
            font-size: 12px;
            margin-top: 10px;
            text-align: center;
        }

        /* Hiệu ứng xoay cho đẹp giống game */
        @keyframes spin {
            0% {
                transform: rotate(0deg);
            }

            100% {
                transform: rotate(360deg);
            }
        }

        ::placeholder {
            /* Chrome, Firefox, Opera, Safari 10.1+ */
            color: rgba(212, 175, 55, 0.4);
            /* Màu vàng D4AF37 nhưng làm mờ đi */
            font-style: italic;
        }

        :-ms-input-placeholder {
            /* Internet Explorer 10-11 */
            color: rgba(212, 175, 55, 0.4);
            font-style: italic;
        }

        ::-ms-input-placeholder {
            /* Microsoft Edge */
            color: rgba(212, 175, 55, 0.4);
            font-style: italic;
        }



        @keyframes shimmer {
            0% {
                background-position: -200% 0;
            }

            100% {
                background-position: 200% 0;
            }
        }

        #progress-bar {
            background: linear-gradient(90deg, #D4AF37, #F9E79F, #D4AF37);
            background-size: 200% 100%;
            animation: shimmer 2s infinite linear;
        }

        /* Tùy chỉnh thanh cuộn cho khung log */
        #packet-log::-webkit-scrollbar {
            width: 8px;
        }

        #packet-log::-webkit-scrollbar-track {
            background: #121212;
        }

        #packet-log::-webkit-scrollbar-thumb {
            background: #333;
            border-radius: 4px;
            border: 1px solid #444;
        }

        #packet-log::-webkit-scrollbar-thumb:hover {
            background: #D4AF37;
        }

        /* Dialog */
        #ts-dialog-overlay {
            z-index: 9999 !important;
            /* Đảm bảo cao nhất */
            pointer-events: auto !important;
            /* Đảm bảo nhận chuột */
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, 0.1);
            display: none;
            z-index: 1000;
        }

        #ts-dialog-box,
        #ts-dialog-overlay {
            cursor: pointer;
            /* Hiện hình bàn tay khi di chuột vào toàn bộ khu vực hội thoại */
        }

        #packet-container {
            display: none;
            /* Mặc định ẩn khi vào game */
            position: fixed;
            top: 0;
            right: 0;
            width: 350px;
            height: 100vh;
            background: #1e1e1e;
            border-left: 2px solid #D4AF37;
            z-index: 9999;
        }

        /* Hộp thoại: Nằm trên overlay, phải nhận chuột để bấm Options */
        #ts-dialog-box {
            position: absolute;
            /* Đưa điểm neo về chính giữa */
            top: 50%;
            left: 50%;
            /* Dịch chuyển ngược lại 50% kích thước của chính nó để căn tâm hoàn hảo */
            transform: translate(-50%, -50%);

            width: 600px;
            height: 180px;
            background: rgba(0, 0, 0, 0.7);
            border: 2px solid #444444;
            color: white;
            display: flex;
            padding: 10px;
            font-family: Tahoma;

            /* Chặn việc người dùng click xuyên qua bảng hội thoại xuống Map */
            pointer-events: auto;
            z-index: 1001;
        }

        .dialog-left {
            flex: 1;
            padding: 10px;
            display: flex;
            flex-direction: column;
        }

        .dialog-right {
            width: 150px;
            border-left: 1px solid #333;
            display: flex;
            flex-direction: column;
            align-items: center;
        }

        .npc-name-tag {
            color: #FFFF00;
            font-weight: bold;
            margin-bottom: 5px;
            text-align: center;
        }

        .option-item {
            cursor: pointer;
            padding: 5px;
            color: #00FF00;
        }

        .option-item:hover {
            background: #444;
            color: white;
        }

        .btn-skip {
            margin-top: auto;
            cursor: pointer;
            color: #888;
            font-size: 12px;
        }

        /* Lớp phủ toàn màn hình: Chặn chuột xuống Map bên dưới */
        #ts-dialog-overlay {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, 0.1);
            /* Nhìn thấy map mờ mờ */
            z-index: 1000;
            display: none;
            /* Ép chuột phải hoạt động trên lớp này để nhận sự kiện Click cho Loại 1 */
            pointer-events: auto;
            cursor: default;
            /* Hiện con trỏ chuột bình thường */
        }

        /* Các option phải có cursor pointer để người chơi biết là bấm được */
        .option-item {
            cursor: pointer;
            color: #00FF00;
            padding: 5px 10px;
            transition: background 0.2s;
        }

        .option-item:hover {
            background: #333333;
            color: #ffffff;
        }

        /* --- KHUNG XƯƠNG CHUNG (Dùng cho tất cả các nút) --- */
        .crystal-btn {
            bottom: 20%;
            /* Cách đáy màn hình 20% */
            left: 50%;
            transform: translateX(-50%);
            /* Căn giữa hoàn hảo */
            display: inline-block;
            position: absolute;
            padding: 5px 20px;
            min-width: 75px;
            border-radius: 6px;
            cursor: pointer;
            font-size: 14px;
            font-weight: bold;
            text-align: center;
            user-select: none;
            border: 1.5px solid rgba(0, 0, 0, 0.4);
            transition: all 0.15s ease;
            z-index: 999;

            /* Viền đen cho chữ mặc định */
            text-shadow: -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000;
            color: #fffb00;

            /* Shadow tạo độ mọng 3D */
            box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.3), 0 2px 5px rgba(0, 0, 0, 0.6);
        }

        .crystal-btn:hover {
            color: #fffb00;
            filter: brightness(1.1);
            box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.9), 0 0 8px rgba(255, 251, 0, 0.6);
        }

        .crystal-btn:active {
            color: #707051;
            /* Có thể đổi màu chữ sang vàng sáng để viền đen nổi bật hơn */
            transform: translateY(2px);
            box-shadow: inset 0 3px 6px rgba(0, 0, 0, 0.8);
        }

        /* --- CÁC BIẾN THỂ MÀU SẮC (Chỉ đổi background) --- */

        /* Màu Xanh (Nút Bỏ qua của tiền bối) */
        .btn-blue {
            background: linear-gradient(to bottom, #d0efff 0%, #a2e0ff 25%, #62C9FE 55%, #62C9FE 100%);
        }

        .btn-blue:active {
            background: #2a556b;
        }

        /* Màu Đỏ (Ví dụ cho nút Hủy/Thoát) */
        .btn-red {
            background: linear-gradient(to bottom, #ffcfcf 0%, #ff8e8e 25%, #fe6262 55%, #fe6262 100%);
        }

        .btn-red:active {
            background: #6b2a2a;
        }

        /* Màu Xanh Lá (Ví dụ cho nút Đồng ý) */
        .btn-green {
            background: linear-gradient(to bottom, #d7ffcf 0%, #90ff8e 25%, #62fe64 55%, #62fe64 100%);
        }

        .btn-green:active {
            background: #2a6b2c;
        }

        #dialog-skip-btn {
            display: none;
            position: absolute;
            bottom: 15px;
            left: 40%;
            transform: translateX(-50%);

            padding: 5px 20px;
            min-width: 100px;
        }

        #login-overlay .crystal-btn {
            /* Đưa về trạng thái bình thường để nó nằm theo thứ tự trong HTML */
            position: relative;
            left: 0;
            bottom: 0;
            transform: none;

            /* Khống chế chiều rộng */
            display: block;
            width: 100%;
            /* Nút rộng 80% so với khung Đăng Nhập */
            margin: 15px auto;
            /* Căn giữa và tạo khoảng cách trên dưới 15px */

            /* Giữ nguyên các thuộc tính khác */
            min-width: unset;
        }

        #status {
            text-align: center;
            font-size: 12px;
            margin-top: 5px;
        }

        #main-content {
            /* Các thuộc tính cũ của tiền bối */
            display: flex;
            justify-content: center;
            align-items: center;

            /* CHIỀU CAO: Như đã giải thích, trừ đi header/footer */
            /* max-height: 960px; 
    min-height: 960px; 
    
    /* CHIỀU RỘNG: Ép bung toàn màn hình */
            /* max-width: 1280px; 
    min-width: 1280px;  */

            width: 100vw;
            height: 100vh;
            margin: 0;
            padding: 0;

            /* Thuộc tính hình nền */
            background-size: cover;
            /* Hiển thị tràn khung */
            background-position: center;
            /* Căn giữa hình ảnh */
            background-repeat: no-repeat;
            transition: background-image 0.5s ease-in-out;
            /* Hiệu ứng đổi ảnh mượt */
        }

        #game-container {
            /* Đổi display: none thành block khi vào game */
            display: none;
            /* Quan trọng: Đảm bảo khung game không bao giờ to hơn màn hình điện thoại */
            max-width: 100%;
            max-height: 100%;
            /* Giữ tỷ lệ 4:3 của TS Online */
            /* position: relative; */
            border: 2px solid #D4AF37;
            background: transparent !important; /* Buộc container phải trong suốt */
        }

        #game-toolbar {
            position: fixed;
            bottom: 0;
            left: 0;
            /* Tự động lấy theo chiều rộng cấu hình của tiền bối */
            width: 100%;
            height: 35px;
            z-index: 1000;

            display: flex;
            align-items: center;
            padding: 0 10px;
            box-sizing: border-box;

            /* KỸ THUẬT CẮT ẢNH: 
       Đoạn đầu 20px giữ nguyên, đoạn cuối (800-50) = 750px giữ nguyên.
       Chỉ kéo giãn phần giữa. */
            border-image-source: url('client/pic/toolbar_bg.png');
            /* Thay bằng đường dẫn của tiền bối */
            border-image-slice: 0 750 0 20;
            /* Trên - Phải - Dưới - Trái */
            border-image-width: 0 750px 0 20px;
            border-image-repeat: stretch;
            /* Kéo giãn phần giữa */

            /* Màu nền dự phòng của tiền bối [cite: 2025-12-31] */
            background-color: #444444;
        }

        #chat-input {
            flex: 1;
            /* Chiếm không gian còn lại */
            height: 22px;
            background: rgba(0, 0, 0, 0.5);
            border: 1px solid #D4AF37;
            color: white;
            padding: 0 10px;
            margin-right: 15px;
        }

        .toolbar-buttons {
            display: flex;
            gap: 5px;
        }


        