.xq-container {
    width: 100%; max-width: 480px; margin: 0 auto;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    user-select: none; -webkit-tap-highlight-color: transparent; 
    box-sizing: border-box; 
    padding: 15px; /* Tăng padding tổng thể để bảo vệ quân cờ ở 2 bên mép dọc */
}

/* Thanh nhập tên & Hạng */
.xq-player-bar {
    display: flex; justify-content: space-between; align-items: center;
    background-color: #f1f3f5; padding: 10px 12px; border-radius: 6px;
    margin-bottom: 8px; border: 1px solid #dee2e6;
}
#xq-player-name {
    padding: 8px; border: 1px solid #ced4da; border-radius: 4px;
    font-size: 14px; width: 60%; outline: none; box-sizing: border-box;
}
#xq-player-name:focus { border-color: #0056b3; }
.xq-rank-box { font-size: 0.9rem; font-weight: bold; color: #495057; white-space: nowrap; }
#xq-rank-display { font-size: 1.2rem; color: #cc221d; }

/* Thanh danh hiệu & Trạng thái ván */
.xq-info {
    display: flex; justify-content: space-between; align-items: center;
    font-size: 0.95rem; font-weight: 600; 
    background-color: #ffffff; padding: 8px 12px; border-radius: 6px;
    border: 1px solid #e9ecef; color: #495057;
}
#xq-difficulty-select { max-width: 55%; font-size: 13px; text-overflow: ellipsis; }
.xq-status-text { color: #d63638; font-weight: 700; font-size: 13px; white-space: nowrap; text-align: right; }

/* ========================================================
   BÀN CỜ - TỐI ƯU KHOẢNG CÁCH AN TOÀN TRÊN/DƯỚI
   ======================================================== */
.xq-board-wrapper { 
    position: relative; 
    width: 100%; 
    background-color: #dfb37c; 
    border: 1px solid #4a2306; 
    box-shadow: 0 4px 12px rgba(0,0,0,0.15); 
    box-sizing: border-box; 
    margin-top: 25px; /* Đẩy bàn cờ tụt xuống, không cho quân cờ đè lên chữ phía trên */
    margin-bottom: 30px; /* Đẩy cụm nút tụt xuống, không cho quân cờ đè lên nút phía dưới */
}

.xq-board-inner { position: relative; width: 100%; }
.xq-svg-board { width: 100%; height: auto; display: block; }
.xq-pieces-layer { position: absolute; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; }

.xq-cell { position: absolute; width: 11.11%; height: 10%; transform: translate(-50%, -50%); z-index: 10; display: flex; align-items: center; justify-content: center; cursor: pointer; border-radius: 50%; pointer-events: auto; }
.xq-piece { width: 88%; height: 88%; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #fffdf7 0%, #f7ebd3 70%, #edd8b4 100%); border: 1px solid #5a3a1a; display: flex; align-items: center; justify-content: center; font-size: clamp(14px, 5vw, 24px); font-family: "PingFang SC", "Lantinghei SC", "Microsoft YaHei", "KaiTi", serif; font-weight: bold; box-shadow: 0 2px 4px rgba(0,0,0,0.25), inset 0 1px 1px rgba(255,255,255,0.8); transition: transform 0.1s ease; }
.xq-piece.red { color: #cc221d; }
.xq-piece.black { color: #111111; }

/* Nút bấm */
.xq-controls { display: flex; gap: 12px; margin-top: 10px; width: 100%; }
.xq-btn { flex: 1; padding: 12px; font-size: 15px; font-weight: bold; border: none; border-radius: 6px; color: #fff; cursor: pointer; min-height: 44px; display: flex; align-items: center; justify-content: center; }
.xq-btn.action-btn { background-color: #212529; }
.xq-btn.info-btn { background-color: #6c757d; }
.xq-btn:active { opacity: 0.8; }

/* Hiệu ứng quân cờ */
.xq-cell.selected .xq-piece { transform: scale(1.1); box-shadow: 0 0 8px rgba(0, 86, 179, 0.6); border-color: #0056b3; }
.xq-cell.valid-move::after { content: ""; position: absolute; width: 22%; height: 22%; background-color: #28a745; border-radius: 50%; z-index: 5; opacity: 0.8; }
.xq-cell.valid-move:not(:empty)::after { width: 88%; height: 88%; background-color: transparent; border: 2px solid #dc3545; box-sizing: border-box; border-radius: 50%; }
.xq-cell.last-move::before { content: ""; position: absolute; width: 90%; height: 90%; background-color: rgba(255, 193, 7, 0.3); border-radius: 50%; z-index: 1; }

/* Giao diện Modal Save/Load */
.xq-modal { position: fixed; z-index: 9999; left: 0; top: 0; width: 100%; height: 100%; background-color: rgba(0,0,0,0.5); display: flex; align-items: center; justify-content: center; backdrop-filter: blur(2px); }
.xq-modal-content { background-color: #fff; padding: 20px; border-radius: 10px; max-width: 90%; width: 400px; max-height: 80vh; overflow-y: auto; position: relative; box-shadow: 0 10px 25px rgba(0,0,0,0.25); }
.xq-close { position: absolute; right: 15px; top: 12px; font-size: 26px; font-weight: bold; color: #888; cursor: pointer; }
.xq-close:hover { color: #dc3545; }
.xq-save-item { display: flex; justify-content: space-between; align-items: center; padding: 10px; border: 1px solid #e9ecef; border-radius: 6px; margin-bottom: 8px; background-color: #f8f9fa; transition: background-color 0.2s; }
.xq-save-item:hover { background-color: #f1f3f5; }
.xq-save-info { flex-grow: 1; font-size: 13px; line-height: 1.4; text-align: left;}
.xq-save-info strong { color: #0056b3; font-size: 14px; }
.xq-save-actions { display: flex; gap: 6px; }
.btn-xq-load-item { background: #27ae60; color: white; border: none; padding: 5px 10px; border-radius: 4px; cursor: pointer; font-size: 12px; font-weight: bold; }
.btn-xq-del-item { background: #dc3545; color: white; border: none; padding: 5px 10px; border-radius: 4px; cursor: pointer; font-size: 12px; font-weight: bold; }

/* ==============================================
   TỐI ƯU HÓA RESPONSIVE CHO MOBILE (MAX 480PX)
   ============================================== */
@media (max-width: 480px) {
    .xq-container { padding: 5px; }
    .xq-player-bar { flex-direction: row; align-items: center; justify-content: space-between; gap: 5px; padding: 8px; }
    #xq-player-name { width: 55%; font-size: 13px; text-align: left; height: 36px; padding: 5px; }
    .xq-rank-box { text-align: right; width: auto; font-size: 12px; }
    
    .xq-info { padding: 6px; font-size: 12px; flex-direction: row; align-items: center; justify-content: space-between; gap: 5px; }
    
    .xq-controls { flex-wrap: wrap; gap: 8px; justify-content: space-between; }
    .xq-btn { flex: 1 1 45%; font-size: 14px; padding: 12px 5px; min-height: 44px; border-radius: 6px; }
    
    .xq-board-wrapper { margin-top: 15px; margin-bottom: 20px; }
    .xq-piece { font-size: clamp(14px, 5.5vw, 24px); }
}
/* Ép bảng xếp hạng bằng chiều rộng bàn cờ */
.xq-leaderboard-wrapper {
    width: 100%;
    max-width: 480px; /* Khớp với .xq-container */
    margin: 20px auto; /* Căn giữa */
    box-sizing: border-box;
    padding: 0 10px;
}

/* Đảm bảo bảng xếp hạng hiển thị gọn gàng */
.xq-leaderboard-table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
/* Class để ẩn thanh thông tin */
.xq-hide {
    display: none !important;
}

/* Đảm bảo bàn cờ chiếm diện tích khi thanh thông tin bị ẩn */
.xq-board-wrapper.expanded {
    margin-top: 10px; /* Bớt khoảng cách trên khi đã ẩn thanh thông tin */
}