/* ===== GIAO DIỆN CHÍNH - Caro BOT M2 PRO ===== */

body {
    margin: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
    padding: 0;
    box-sizing: border-box;
    transition: none; /* Tắt hoàn toàn transition để tránh flickering */
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

/* Chỉ tắt animation/transition trên các phần gây flickering */
.cell {
    animation: none !important;
    transition: none !important;
    touch-action: manipulation;
}

.cell:hover {
    background: none !important;
}

#inf-canvas,
#inf-canvas-bot,
#inf-canvas-online {
    animation: none !important;
    transition: none !important;
    touch-action: none; /* Allow custom touch handling for canvas */
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    display: block;
    cursor: default;
}

/* Tắt tất cả animation khi fullscreen để tránh flickering */
body.fullscreen-mode * {
    animation: none !important;
    transition: none !important;
}

/* Cố định canvas khi fullscreen để tránh reflow */
body.fullscreen-mode #inf-canvas,
body.fullscreen-mode #inf-canvas-bot,
body.fullscreen-mode #inf-canvas-online {
    position: fixed !important;
    top: 50% !important;
    left: 50% !important;
    transform: translate(-50%, -50%) !important;
    width: 100vw !important;
    height: 100vh !important;
    max-width: none !important;
    max-height: none !important;
}

/* ===== NOTIFICATION TICKER ===== */
@keyframes ticker-scroll {
    0% { transform: translateX(100%); }
    100% { transform: translateX(-100%); }
}

#notification-ticker {
    background: var(--bg-primary);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-md);
    border-radius: var(--radius-md);
    overflow: hidden;
    width: 100%;
    box-sizing: border-box;
    margin-bottom: 4px;
    align-self: stretch; /* Trải rộng hết chiều ngang trong flex column */
    transition: background var(--transition-normal), border-color var(--transition-normal);
}

#ticker-content {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 7px 14px;
    align-items: center;
    font-size: 0.82rem;
    font-weight: 500;
}


#notification-ticker:hover #ticker-content {
    animation-play-state: paused;
}
.ticker-item {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: var(--radius-full);
    background: var(--bg-panel);
    color: var(--text-primary);
    font-size: 0.8rem;
    white-space: nowrap;
}

.ticker-item.online {
    background: var(--color-success-light);
    color: var(--color-success);
}

.ticker-item.win {
    background: var(--color-warning-light);
    color: var(--color-warning);
}

.ticker-item.chat {
    background: var(--color-info-light);
    color: var(--color-info);
}

/* Responsive cho mobile */
@media (max-width: 768px) {
    #ticker-content {
        font-size: 0.75rem !important;
        padding: 5px 10px !important;
        gap: 5px !important;
    }
    .ticker-item {
        padding: 3px 8px !important;
        font-size: 0.72rem !important;
    }
    
    /* Nav bar responsive */
    #nav-bar {
        padding: 6px 10px !important;
        gap: 6px !important;
        font-size: 11px !important;
    }
    
    #nav-quick-btns .xu-action-btn {
        padding: 3px 6px !important;
        font-size: 10px !important;
    }
    
    /* User info card responsive */
    #user-info-card {
        padding: 8px 12px !important;
        gap: 8px !important;
    }
    
    #user-info-card #user-avatar-display {
        width: 36px !important;
        height: 36px !important;
        font-size: 16px !important;
    }
    
    #user-info-card #user-display-name {
        font-size: 12px !important;
    }
    
    #user-info-card #my-rank {
        font-size: 9px !important;
        padding: 2px 6px !important;
    }
    
    #user-info-card button {
        padding: 4px 8px !important;
        font-size: 10px !important;
    }
    
    /* Config panel responsive */
    .config-panel {
        gap: 6px !important;
        padding: 6px 8px !important;
    }
    
    .config-group {
        font-size: 0.8rem !important;
        gap: 4px !important;
    }
    
    select {
        padding: 4px 8px !important;
        font-size: 0.75rem !important;
    }
    
    input[type="checkbox"] {
        width: 16px !important;
        height: 16px !important;
    }
    
    /* Title responsive */
    h1 {
        font-size: 1.3rem !important;
        margin: 6px 0 8px !important;
    }
    
    /* Control wrapper */
    .control-wrapper {
        padding: 4px 8px !important;
    }
    
    /* Status panel */
    .status-panel {
        font-size: 0.85rem !important;
        padding: 6px 10px !important;
    }
    
    /* Keyboard hint */
    .keyboard-hint {
        font-size: 0.7rem !important;
        margin: 6px 0 8px 0 !important;
    }
}

@media (max-width: 480px) {
    #ticker-content {
        font-size: 0.7rem !important;
        padding: 4px 8px !important;
    }
    .ticker-item {
        padding: 2px 7px !important;
        font-size: 0.68rem !important;
    }
    
    /* Nav bar mobile nhỏ */
    #nav-bar {
        padding: 4px 8px !important;
        gap: 4px !important;
        font-size: 10px !important;
    }
    
    /* Ẩn một số nút trên mobile rất nhỏ */
    #nav-quick-btns .btn-dagia {
        display: none !important;
    }
    
    #nav-quick-btns .xu-action-btn {
        padding: 2px 5px !important;
        font-size: 9px !important;
    }
    
    /* Ẩn link tiny.cc trên mobile nhỏ */
    #nav-bar a[href*="tiny.cc"] {
        display: none !important;
    }
    
    /* User info card mobile nhỏ */
    #user-info-card {
        flex-direction: column !important;
        align-items: flex-start !important;
        padding: 8px !important;
        gap: 8px !important;
    }
    
    #user-info-card > div:first-child {
        width: 100% !important;
    }
    
    #user-info-card #user-avatar-display {
        width: 32px !important;
        height: 32px !important;
        font-size: 14px !important;
    }
    
    #user-info-card #user-display-name {
        font-size: 11px !important;
    }
    
    #user-info-card #my-rank {
        font-size: 8px !important;
        padding: 2px 6px !important;
    }
    
    #user-info-card > div:last-child {
        width: 100% !important;
        justify-content: flex-end !important;
    }
    
    #user-info-card button {
        padding: 4px 8px !important;
        font-size: 10px !important;
    }
    
    /* Config panel mobile nhỏ */
    .config-panel {
        gap: 4px !important;
        padding: 4px 6px !important;
    }
    
    .config-group {
        font-size: 0.75rem !important;
        gap: 3px !important;
        flex-direction: column !important;
        align-items: flex-start !important;
    }
    
    .config-group label {
        font-size: 0.7rem !important;
    }
    
    select {
        padding: 3px 6px !important;
        font-size: 0.7rem !important;
        width: 100% !important;
    }
    
    input[type="checkbox"] {
        width: 14px !important;
        height: 14px !important;
    }
    
    /* Title mobile nhỏ */
    h1 {
        font-size: 1.1rem !important;
        margin: 4px 0 6px !important;
        letter-spacing: 1px !important;
    }
    
    /* Control wrapper mobile nhỏ */
    .control-wrapper {
        padding: 3px 6px !important;
    }
    
    /* Status panel mobile nhỏ */
    .status-panel {
        font-size: 0.8rem !important;
        padding: 5px 8px !important;
        min-width: auto !important;
    }
    
    /* Keyboard hint ẩn trên mobile nhỏ */
    .keyboard-hint {
        display: none !important;
    }
    
    /* Main layout padding */
    .main-layout {
        padding: 0 6px 6px !important;
    }
    
    /* Game container mobile - xếp player cards lên hàng riêng */
    .game-container {
        flex-direction: column !important;
        gap: 8px !important;
    }
    
    /* Player cards container - 2 player cards xếp ngang trên mobile */
    #ui-game-container {
        flex-wrap: wrap !important;
        justify-content: center !important;
    }
    
    /* Player cards mobile - xếp ngang ở trên bàn cờ */
    .player-card {
        width: 48% !important;
        max-width: 48% !important;
        flex-direction: row !important;
        gap: 6px !important;
        padding: 6px !important;
        justify-content: center !important;
    }
    
    .pc-avatar {
        width: 28px !important;
        height: 28px !important;
        font-size: 12px !important;
    }
    
    .player-card .pc-info {
        flex: 1 !important;
        text-align: left !important;
    }
    
    .player-card .pc-name {
        font-size: 0.75rem !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
    }
    
    .player-card .pc-badge {
        font-size: 0.65rem !important;
    }
    
    .player-card .pc-stats {
        font-size: 0.6rem !important;
        gap: 4px !important;
        flex-wrap: wrap !important;
    }
    
    /* Bàn cờ chiếm full width trên mobile */
    #ui-game-container > div:not(.player-card) {
        width: 100% !important;
        order: 2 !important;
    }
    
    /* Player cards lên đầu */
    .player-card {
        order: 1 !important;
    }
    
    /* Ẩn resize handles trên mobile */
    .gc-resize-handle {
        display: none !important;
    }
}

h1 {
    margin: 8px 0 10px;
    font-size: 1.75rem;
    text-transform: uppercase;
    letter-spacing: 2px;
    text-align: center;
    font-weight: 900;
    width: 100%;
    background: linear-gradient(135deg, var(--color-primary) 0%, #8b5cf6 50%, #ec4899 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: none;
    filter: drop-shadow(0 2px 6px rgba(99,102,241,0.25));
}

.control-wrapper {
    width: 100%;
    max-width: 100%;
    position: relative;
    z-index: 99;
    margin: 0;
    padding: 6px 10px;
    box-sizing: border-box;
}

.config-panel {
    display: flex;
    gap: 8px;
    padding: 6px 10px;
    border-radius: var(--radius-md);
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    box-shadow: var(--shadow-sm);
    max-width: 100%;
    background: var(--bg-card);
    border: 1px solid var(--border);
    transition: background var(--transition-normal), border-color var(--transition-normal);
}

.config-group {
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: bold;
    font-size: 0.9rem;
}

select {
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 0.85rem;
    outline: none;
    cursor: pointer;
    font-weight: bold;
}

input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--color-primary);
}

.status-panel {
    font-size: 0.95rem;
    margin: 8px 0 4px 0;
    padding: 8px 15px;
    border-radius: var(--radius-sm);
    text-align: center;
    min-width: 200px;
    box-shadow: var(--shadow-sm);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.2;
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-primary);
    transition: background var(--transition-normal), border-color var(--transition-normal);
}

.main-layout {
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-width: 100%;
    flex: 1;
    padding: 0 10px 10px;
    box-sizing: border-box;
}

.panels-wrapper {
    display: flex;
    gap: 10px;
    width: 100%;
    max-width: 100%;
    justify-content: center;
    align-items: flex-start;
}

.side-panel {
    width: 140px;
    padding: 10px;
    border-radius: var(--radius-lg);
    font-size: 0.8rem;
    line-height: 1.4;
    box-shadow: var(--shadow-sm);
    flex-shrink: 0;
    overflow-y: auto;
    max-height: calc(100vh - 150px);
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-primary);
    transition: background var(--transition-normal), border-color var(--transition-normal);
}

.side-panel h3 {
    margin-top: 0;
    text-transform: uppercase;
    font-size: 1.05rem;
    text-align: center;
    padding-bottom: 8px;
    margin-bottom: 12px;
}

.game-container {
    padding: 8px;
    border-radius: var(--radius-md);
    overflow: hidden;
    flex: 1;
    max-width: 100%;
    max-height: 100%;
    min-height: 300px;
    box-shadow: var(--shadow-lg);
    cursor: default;
    user-select: none;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    background: var(--bg-card);
    border: 1px solid var(--border);
    transition: background var(--transition-normal), border-color var(--transition-normal);
}
.game-container.inf-mode {
    overflow: hidden;
    cursor: default;
    padding: 0;
    display: inline-block;
    line-height: 0;
}

/* ===== ZOOM CONTROLS ===== */
.zoom-controls {
    position: absolute;
    /* Góc dưới-phải bàn cờ (D-pad đã chuyển sang góc dưới-trái) */
    bottom: 10px;
    right: 10px;
    display: flex;
    flex-direction: column;
    gap: 5px;
    z-index: 100;
}

/* ===== D-PAD PAN ===== */
/* 4 phím mũi tên dịch chuyển bàn cờ — hiển thị trên MỌI thiết bị (PC + Mobile).
   Góc dưới-TRÁI bàn cờ, trong suốt nhẹ để không che ô cờ. */
.inf-dpad {
    display: grid;
    position: absolute;
    left: 10px;
    bottom: 10px;
    z-index: 100;
    grid-template-columns: repeat(3, 34px);
    grid-template-rows: repeat(2, 34px);
    gap: 3px;
    opacity: 0.8;
    transition: opacity 0.2s ease;
}
.inf-dpad:hover { opacity: 1; }
.dpad-btn {
    width: 34px;
    height: 34px;
    border: none;
    border-radius: var(--radius-sm);
    background: rgba(0, 0, 0, 0.75);
    color: #fff;
    font-size: 13px;
    line-height: 1;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: none; /* chặn scroll trang khi giữ nút */
    user-select: none;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition-fast);
}
.dpad-btn:active {
    background: var(--color-primary);
    transform: scale(0.94);
}
/* Bố cục chữ thập: ▲ giữa hàng trên, ◀ ▼ ▶ hàng dưới */
.dpad-up    { grid-column: 2; grid-row: 1; }
.dpad-left  { grid-column: 1; grid-row: 2; }
.dpad-down  { grid-column: 2; grid-row: 2; }
.dpad-right { grid-column: 3; grid-row: 2; }
.zoom-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 2px solid var(--color-primary);
    background: var(--bg-card);
    color: var(--color-primary);
    font-size: 1.5rem;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-md);
    transition: all var(--transition-fast);
    line-height: 1;
}
.zoom-btn:hover {
    background: var(--color-primary);
    color: white;
    transform: scale(1.1);
}
.zoom-btn:active { transform: scale(0.95); }
.zoom-btn.zoom-undo { border-color: var(--color-warning); color: var(--color-warning); }
.zoom-btn.zoom-undo:hover { background: var(--color-warning); color: white; }

#inf-canvas,
#inf-canvas-bot,
#inf-canvas-online {
    display: block;
    touch-action: none;
    cursor: default;
    transform: translateZ(0);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    will-change: transform;
    /* Đảm bảo canvas không cao hơn rộng (hình chữ nhật) */
    max-height: 80vh;
    max-width: 100%;
    max-height: 100%;
}

/* ===== RESIZE HANDLES CHO BÀN CỜ VÔ HẠN ===== */
#inf-resizable {
    display: inline-block;
    position: relative;
    max-width: 100%;
    max-height: 100%;
    overflow: hidden;
    --inf-handle-size: 12px;
    --inf-edge-handle-size: 8px;
}
.rs-handle {
    position: absolute;
    background: var(--color-primary);
    border-radius: 3px;
    z-index: 20;
    transition: background var(--transition-fast);
    opacity: 0.55;
}
.rs-handle:hover { background: var(--color-primary); opacity: 0.95; }
.rs-n  { top:0px;    left:var(--inf-handle-size);  right:var(--inf-handle-size); height:var(--inf-edge-handle-size); cursor:n-resize; }
.rs-s  { bottom:0px; left:var(--inf-handle-size);  right:var(--inf-handle-size); height:var(--inf-edge-handle-size); cursor:s-resize; }
.rs-w  { left:0px;   top:var(--inf-handle-size);    bottom:var(--inf-handle-size); width:var(--inf-edge-handle-size); cursor:w-resize; }
.rs-e  { right:0px;  top:var(--inf-handle-size);    bottom:var(--inf-handle-size); width:var(--inf-edge-handle-size); cursor:e-resize; }
.rs-nw { top:0px;    left:0px;  width:var(--inf-handle-size); height:var(--inf-handle-size); cursor:nw-resize; border-radius:4px; }
.rs-ne { top:0px;    right:0px; width:var(--inf-handle-size); height:var(--inf-handle-size); cursor:ne-resize; border-radius:4px; }
.rs-sw { bottom:0px; left:0px;  width:var(--inf-handle-size); height:var(--inf-handle-size); cursor:sw-resize; border-radius:4px; }
.rs-se { bottom:0px; right:0px; width:var(--inf-handle-size); height:var(--inf-handle-size); cursor:se-resize; border-radius:4px; }

.board {
    display: grid;
    gap: 1px;
    padding: 2px;
}

.cell {
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    user-select: none;
    box-sizing: border-box;
    font-weight: 900;
    font-size: 0.55rem;
    transition: none; /* Tắt hoàn toàn transition để tránh flickering */
    position: relative;
}

/* Tắt hoàn toàn hover effect trên cell */
.cell:hover {
    background: none !important;
}
.cell.X, .cell.O {
    cursor: default;
    pointer-events: none;
}

.cell.last-move {
    outline: 3px solid var(--color-warning) !important;
    outline-offset: -3px;
    animation: modernFlash 0.8s infinite alternate;
    z-index: 10;
}

@keyframes modernFlash {
    0%   { filter: brightness(1);   box-shadow: inset 0 0 4px rgba(245,158,11,0.4); }
    100% { filter: brightness(1.3); box-shadow: inset 0 0 12px rgba(245,158,11,0.9); }
}

.cell.winning-cell {
    animation: pulseEffect 0.5s infinite alternate;
    z-index: 11;
}

@keyframes pulseEffect {
    0%   { transform: scale(1);    filter: brightness(1.2); }
    100% { transform: scale(1.05); filter: brightness(1.4); }
}

@keyframes dotPulse {
    0%, 100% { opacity: 0.2; }
    50%       { opacity: 1; }
}
.think-dots { animation: dotPulse 1s infinite; font-size: 1.1em; letter-spacing: 2px; }

/* ===== BOT AVATAR ===== */
.bot-avatar {
    position: absolute;
    /* Neo góc trên-trái BÀN CỜ (nằm trong #inf-resizable) —
       tách biệt khỏi nút %, thanh công cụ và D-pad (góc dưới-trái) */
    top: 8px;
    left: 8px;
    z-index: 90;
    pointer-events: none; /* Không chắn click vào bàn cờ/nút bên dưới */
    display: flex;
    align-items: center;
    gap: 8px;
    opacity: 0.85;
    transition: opacity 0.3s ease;
}
.bot-face {
    font-size: 1.8rem;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.2));
    animation: botBounce 2s ease-in-out infinite;
}
@keyframes botBounce {
    0%, 100% { transform: translateY(0); }
    50%       { transform: translateY(-3px); }
}
.bot-bubble {
    position: relative;
    background: var(--bg-card);
    border-radius: var(--radius-md);
    padding: 6px 10px;
    box-shadow: var(--shadow-sm);
    max-width: 180px;
    min-width: 100px;
    border: 1px solid var(--border);
    transition: background var(--transition-normal), border-color var(--transition-normal);
}
.bot-bubble::before {
    content: '';
    position: absolute;
    /* Mũi nhọn trỏ sang trái — về phía mặt bot (bot nằm bên trái bubble) */
    left: -6px;
    top: 50%;
    transform: translateY(-50%);
    border: 6px solid transparent;
    border-right-color: var(--bg-card);
}
.bot-message {
    font-size: 0.8rem;
    color: var(--text-primary);
    line-height: 1.3;
    word-wrap: break-word;
}
.bot-bubble.annoying {
    animation: bubbleFlash 0.5s ease-in-out infinite;
    background: rgba(255,100,100,0.95);
}
@keyframes bubbleFlash {
    0%, 100% { transform: scale(1); }
    50%       { transform: scale(1.05); }
}

/* ── Chế độ ONLINE (PvP): tái sử dụng khung thoại bot làm THANH THÔNG BÁO HỆ THỐNG ──
   GIỮ avatar (🤖 hoặc avatar đối thủ) bên trái, đổi khung chữ sang phong cách system */
.bot-avatar.online-announce .bot-bubble {
    background: rgba(0, 0, 0, 0.88);
    border: 1px solid var(--color-primary);
    box-shadow: var(--shadow-md);
    max-width: 240px;
}
.bot-avatar.online-announce .bot-bubble::before {
    /* Mũi nhọn trỏ về avatar — đổi màu khớp nền tối */
    border-right-color: rgba(0, 0, 0, 0.88);
}
.bot-avatar.online-announce .bot-message {
    color: var(--text-primary);
    font-weight: bold;
}
/* Không dùng hiệu ứng "annoying" của bot khi đang là thanh thông báo */
.bot-avatar.online-announce .bot-bubble.annoying {
    animation: none;
    background: rgba(0, 0, 0, 0.88);
}

.btn-restart {
    margin: 8px 0 4px 0;
    padding: 12px 40px;
    font-size: 1.05rem;
    font-weight: bold;
    border-radius: var(--radius-full);
    cursor: pointer;
    border: none;
    box-shadow: var(--shadow-md);
    align-self: center;
    background: var(--color-primary);
    color: #fff;
    transition: background var(--transition-fast);
}

/* ===== RESPONSIVE ===== */
@media (max-width: 1200px) {
    .main-layout  { gap: 8px; }
    .panels-wrapper { gap: 8px; }
}
@media (max-width: 900px) {
    .main-layout  { gap: 8px; }
    .panels-wrapper { gap: 8px; }
    #history-panel { min-width: 150px; }
    #rank-panel    { min-width: 150px; }
    #history-list  { max-height: 120px; }
    #rank-list     { max-height: 180px; }
    .control-wrapper { padding: 6px 8px; }
    h1 { font-size: 1.45rem; margin: 6px 0; }
}
/* ===== MOBILE OVERHAUL ===== */
@media (max-width: 600px) {

    /* ── Tiêu đề ── */
    h1 {
        font-size: 1.05rem !important;
        letter-spacing: 0.5px !important;
        margin: 6px 0 4px !important;
        padding: 0 8px;
    }

    /* ── Top-bar ── */
    #top-bar {
        padding: 6px 10px !important;
        gap: 6px !important;
        border-radius: 6px !important;
        margin: 0 0 6px !important;
    }
    /* Nhóm trái: Trang Chủ + link + Solo Online */
    #top-bar > div:first-child {
        gap: 6px !important;
        flex-wrap: wrap !important;
    }
    #top-bar a[href*="khoiphuctool"] {
        padding: 5px 12px !important;
        font-size: 11px !important;
    }
    #top-bar a[href*="tiny"] {
        display: none !important; /* Ẩn link tiny trên mobile - tiết kiệm chỗ */
    }
    #btn-go-online {
        padding: 5px 12px !important;
        font-size: 11px !important;
    }
    /* Khu auth (chưa đăng nhập) */
    #top-auth-buttons button {
        padding: 5px 10px !important;
        font-size: 11px !important;
    }
    /* Khu đã đăng nhập: gọn lại */
    #user-logged-in {
        gap: 6px !important;
        flex-wrap: nowrap !important;
        align-items: center !important;
    }
    #user-avatar-display {
        width: 30px !important;
        height: 30px !important;
        font-size: 14px !important;
    }
    #user-logged-in > div:nth-child(2) {
        line-height: 1.3 !important;
    }
    #user-logged-in > div:nth-child(2) span:first-child {
        font-size: 12px !important;
    }
    #my-rank { font-size: 10px !important; }
    #user-logged-in > div:nth-child(2) > div:last-child {
        font-size: 10px !important;
    }
    #user-logged-in > div:last-child button {
        padding: 3px 8px !important;
        font-size: 11px !important;
    }
    /* Ẩn nút Tài khoản, chỉ giữ Đăng xuất + avatar đã có onclick */
    #user-logged-in > div:last-child button:first-child {
        display: none !important;
    }

    /* ── Config panel: gọn, dạng grid 2 cột ── */
    .control-wrapper { padding: 0 6px 4px !important; }
    .config-panel {
        gap: 4px 10px !important;
        padding: 6px 8px !important;
        justify-content: flex-start !important;
    }
    .config-group {
        font-size: 0.75rem !important;
        gap: 4px !important;
    }
    .config-group label { font-size: 0.72rem !important; }
    select { padding: 3px 6px !important; font-size: 0.72rem !important; }
    input[type="checkbox"] { width: 15px !important; height: 15px !important; }

    /* Khối Huấn luyện — thu gọn */
    .config-panel > div[style*="border: 2px solid #10b981"] {
        padding: 6px 8px !important;
        gap: 6px !important;
        flex-wrap: wrap !important;
    }
    .config-panel > div[style*="border: 2px solid #10b981"] > div[style*="font-weight: bold"] {
        font-size: 0.75rem !important;
        min-width: unset !important;
        width: 100% !important;
    }

    /* Khối stats AI (Pattern, Elo…) */
    .config-panel > div > div[style*="font-size:0.75rem"] {
        font-size: 0.65rem !important;
    }

    /* ── Ẩn hướng dẫn phím tắt trên mobile ── */
    .keyboard-hint { display: none !important; }

    /* ── Status panel ── */
    .status-panel { font-size: 0.82rem !important; padding: 4px 8px !important; min-width: 0 !important; }

    /* ── Timer ── */
    .timer-panel { font-size: 0.75rem !important; margin: 1px 0 !important; }

    /* ── Game container: Đảm bảo không overflow trên mobile ── */
    .game-container {
        max-width: 100vw !important;
        width: 100% !important;
        overflow: hidden !important;
        padding: 4px !important;
    }
    
    /* ── Offline canvas: Thu nhỏ tự động theo màn hình ── */
    #inf-canvas {
        max-width: 100% !important;
        max-height: 60vh !important;
        width: auto !important;
        height: auto !important;
    }

    /* ── Online battle canvas: full container, do JS controls size directly ── */
    #inf-canvas-online {
        max-width: 100% !important;
        max-height: none !important;
        width: 100% !important;
        height: 100% !important;
    }

    /* ── Bot Room Canvas: Full container, không bị CSS resize ── */
    #inf-canvas-bot {
        width: 100% !important;
        height: 100% !important;
        max-width: none !important;
        max-height: none !important;
        position: absolute !important;
        inset: 0 !important;
    }

    #inf-resizable {
        max-width: 100% !important;
        overflow: hidden !important;
    }

    /* ── Đảm bảo canvas nằm trong container khi zoom preset được chọn ── */
    .game-container.inf-mode #inf-resizable {
        max-width: 100% !important;
        overflow: hidden !important;
    }
    
    .game-container.inf-mode #inf-canvas,
    .game-container.inf-mode #inf-canvas-online {
        max-width: 100% !important;
        max-height: 100% !important;
    }

    /* Bot Room không bị giới hạn trong inf-mode */
    .game-container.inf-mode #inf-canvas-bot {
        max-width: none !important;
        max-height: none !important;
    }
    
    /* ── Resize handles: Tăng kích thước trên mobile để dễ touch ── */
    .rs-handle {
        --inf-handle-size: 20px !important;
        --inf-edge-handle-size: 14px !important;
    }
    
    .gc-resize-handle {
        --gc-handle-size: 20px !important;
    }
    
    /* ── Style cho nút lưu kích thước ── */
    .btn-save-size {
        padding: 4px 8px !important;
        font-size: 11px !important;
        background: var(--color-success) !important;
        color: white !important;
        border: none !important;
        border-radius: var(--radius-sm) !important;
        cursor: pointer !important;
        margin-left: 8px !important;
        flex-shrink: 0 !important;
        transition: background var(--transition-fast) !important;
    }
    .btn-save-size:hover {
        background: var(--color-success-hover) !important;
    }

    /* ── Thanh zoom preset: cuộn ngang thay vì xuống dòng ── */
    .board-zoom-controls { margin: 4px 0 !important; gap: 4px !important; }
    .zoom-presets {
        gap: 4px !important;
        flex-wrap: nowrap !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        padding-bottom: 2px !important;
        justify-content: flex-start !important;
        width: 100% !important;
        scrollbar-width: none !important;
    }
    .zoom-presets::-webkit-scrollbar { display: none !important; }
    .btn-zoom-preset {
        padding: 4px 10px !important;
        font-size: 11px !important;
        flex-shrink: 0 !important;
    }
    .auto-size-toggle { font-size: 11px !important; }
    .toggle-text { font-size: 11px !important; }

    /* ── Bot avatar: vẫn hiện trên mobile — thu gọn kích thước để không che bàn cờ ── */
    #bot-avatar {
        top: 6px !important;
        left: 6px !important;
        gap: 5px !important;
        opacity: 0.9 !important;
    }
    #bot-avatar .bot-face { font-size: 1.3rem !important; }
    #bot-avatar .bot-bubble {
        max-width: 150px !important;
        min-width: 70px !important;
        padding: 4px 8px !important;
    }
    #bot-avatar .bot-message { font-size: 0.68rem !important; }

    /* ── Main layout ── */
    .main-layout { 
        padding: 0 4px 6px !important; 
        gap: 6px !important;
        max-width: 100vw !important;
        overflow-x: hidden !important;
    }

    /* ── Panels wrapper ── */
    .panels-wrapper { 
        flex-direction: column !important; 
        gap: 6px !important;
        max-width: 100% !important;
    }
    #history-panel, #rank-panel {
        min-width: unset !important;
        max-width: 100% !important;
    }
    #history-panel { max-height: 140px !important; }
    /* BXH mobile: đủ cao để thấy nhiều dòng, danh sách bên trong tự cuộn */
    #rank-panel { max-height: 300px !important; }
    #rank-list  { max-height: 200px !important; }

    /* ── Nút Ván Mới ── */
    .btn-restart { padding: 8px 28px !important; font-size: 0.9rem !important; }
    
    /* ── Zoom controls: góc dưới-phải (D-pad ở góc dưới-trái) ── */
    .zoom-controls {
        bottom: 12px !important;
        right: 12px !important;
    }
    /* ── D-pad: thu nhỏ nút trên mobile để đỡ che ô cờ ── */
    .inf-dpad {
        grid-template-columns: repeat(3, 30px) !important;
        grid-template-rows: repeat(2, 30px) !important;
        left: 8px !important;
        bottom: 8px !important;
    }
    .dpad-btn { width: 30px !important; height: 30px !important; font-size: 12px !important; }
}

/* Extra nhỏ */
@media (max-width: 380px) {
    h1 { font-size: 0.9rem !important; }
    #top-bar { padding: 5px 8px !important; }
    .config-group { font-size: 0.68rem !important; }
    select { font-size: 0.68rem !important; }
}




/* ===== PHÁO HOA & WIN OVERLAY ===== */
#confetti-canvas {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    pointer-events: none;
    z-index: 99998;
}

#win-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.55);
    z-index: 99999;
    justify-content: center;
    align-items: center;
    animation: overlayFadeIn 0.4s ease;
}
#win-overlay.show { display: flex; }
@keyframes overlayFadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.win-box {
    background: linear-gradient(135deg, var(--bg-secondary), var(--bg-primary));
    border: 2px solid var(--color-warning);
    border-radius: var(--radius-2xl);
    padding: 48px 60px;
    text-align: center;
    box-shadow: 0 0 60px rgba(245,158,11,0.4), var(--shadow-xl);
    animation: winBoxPop 0.5s cubic-bezier(0.34,1.56,0.64,1);
    max-width: 420px;
    width: 90%;
    position: relative;
}
.win-close {
    position: absolute;
    top: 14px;
    right: 14px;
    width: 34px;
    height: 34px;
    border: none;
    border-radius: 50%;
    background: rgba(255,255,255,0.12);
    color: #fff;
    font-size: 20px;
    line-height: 34px;
    cursor: pointer;
    text-align: center;
    transition: background var(--transition-fast);
}
.win-close:hover {
    background: rgba(255,255,255,0.22);
}
@keyframes winBoxPop {
    from { transform: scale(0.5); opacity: 0; }
    to   { transform: scale(1);   opacity: 1; }
}

.win-emoji {
    font-size: 4rem;
    display: block;
    margin-bottom: 12px;
    animation: bounce 0.7s infinite alternate;
}
@keyframes bounce {
    from { transform: translateY(0); }
    to   { transform: translateY(-12px); }
}
.win-title {
    font-size: 1.9rem;
    font-weight: 900;
    color: var(--color-warning);
    margin: 0 0 8px;
    text-transform: uppercase;
    letter-spacing: 2px;
}
.win-subtitle {
    font-size: 1rem;
    color: var(--text-secondary);
    margin: 0 0 32px;
}
.btn-play-again {
    padding: 14px 48px;
    font-size: 1.1rem;
    font-weight: 800;
    border-radius: var(--radius-full);
    border: none;
    cursor: pointer;
    background: linear-gradient(135deg, var(--color-warning), var(--color-danger));
    color: #fff;
    letter-spacing: 1px;
    box-shadow: 0 4px 20px rgba(245,158,11,0.5);
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
    text-transform: uppercase;
}
.btn-play-again:hover {
    transform: scale(1.06);
    box-shadow: 0 6px 28px rgba(245,158,11,0.7);
}

/* ===== LỊCH SỬ ĐẤU ===== */
#history-panel {
    flex: 1;
    min-width: 200px;
    max-width: 50%;
    border-radius: var(--radius-lg);
    padding: 8px 10px;
    box-sizing: border-box;
    background: var(--bg-card);
    border: 1px solid var(--border);
    flex-shrink: 0;
    max-height: calc(100vh - 150px);
    overflow-y: auto;
    position: relative;
    overflow: hidden;
    transition: background var(--transition-normal), border-color var(--transition-normal);
}
#history-panel .resize-handle {
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 8px;
    height: 80px;
    background: var(--color-primary);
    cursor: ew-resize;
    border-radius: var(--radius-sm);
    transition: background var(--transition-fast);
    z-index: 100;
    opacity: 0.5;
}
#history-panel .resize-handle:hover { background: var(--color-primary); opacity: 0.9; }
.history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    user-select: none;
    padding: 4px 0;
}
.history-header h3 {
    margin: 0;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-primary);
}
.history-toggle-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.85rem;
    padding: 2px 4px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    transition: background var(--transition-fast);
}
.history-toggle-btn:hover { background: var(--bg-primary); }
.history-body {
    display: none;
    margin-top: 10px;
    border-top: 2px solid var(--border);
    padding-top: 10px;
}
.history-body.open { display: block; }
#history-list {
    max-height: 300px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
#history-list::-webkit-scrollbar { width: 5px; }
#history-list::-webkit-scrollbar-thumb { border-radius: 4px; background: rgba(128,128,128,0.4); }
.history-item {
    display: flex;
    align-items: center;
    gap: 3px;
    padding: 2px 3px;
    border-radius: 4px;
    font-size: 0.68rem;
    font-weight: 600;
    color: inherit;
}
.history-item .h-num  { min-width: 12px; font-size: 0.58rem; opacity: 0.6; }
.history-item .h-result { min-width: 14px; font-size: 0.75rem; text-align: center; }
.history-item .h-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0px;
}
.history-item .h-mode { font-size: 0.6rem; opacity: 0.65; }
.history-item.win  { background: var(--color-primary-light);  border-left: 3px solid var(--color-primary); }
.history-item.lose { background: var(--color-danger-light);  border-left: 3px solid var(--color-danger); }
.history-item.draw { background: var(--bg-panel); border-left: 3px solid var(--text-secondary); }
#history-empty {
    text-align: center;
    opacity: 0.45;
    font-size: 0.9rem;
    padding: 12px 0;
}
.btn-clear-history {
    margin-top: 10px;
    padding: 5px 18px;
    font-size: 0.82rem;
    border-radius: 20px;
    border: none;
    cursor: pointer;
    font-weight: bold;
    opacity: 0.75;
    display: block;
    margin-left: auto;
}
.btn-clear-history:hover { opacity: 1; }

/* ===== BẢNG XẾP HẠNG ===== */
#rank-panel {
    flex: 1;
    min-width: 200px;
    max-width: 50%;
    border-radius: var(--radius-lg);
    padding: 8px 10px;
    box-sizing: border-box;
    background: var(--bg-card);
    border: 1px solid var(--border);
    flex-shrink: 0;
    max-height: calc(100vh - 150px);
    position: relative;
    /* Flex column: tiêu đề / tabs / danh sách / nút xếp dọc tách bạch,
       danh sách tự cuộn riêng — KHÔNG dùng overflow:hidden đè mất overflow-y:auto */
    display: flex;
    flex-direction: column;
    transition: background var(--transition-normal), border-color var(--transition-normal);
}
#rank-panel .resize-handle {
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 4px;
    height: 60px;
    background: var(--color-primary);
    cursor: ew-resize;
    border-radius: var(--radius-sm);
    transition: background var(--transition-fast);
    opacity: 0.3;
}
#rank-panel .resize-handle:hover { background: var(--color-primary); opacity: 0.7; }
#rank-panel h3 {
    margin: 0 0 12px;
    font-size: 1rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    text-align: center;
    padding-bottom: 8px;
    color: var(--text-primary);
    border-bottom: 2px solid var(--border);
    flex-shrink: 0;
}
.rank-tabs {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: 12px;
    justify-content: center;
    flex-shrink: 0;
}
.rank-tab {
    padding: 4px 14px;
    border-radius: var(--radius-full);
    border: 1px solid var(--border);
    background: var(--bg-panel);
    color: var(--text-secondary);
    font-size: 0.82rem;
    font-weight: bold;
    cursor: pointer;
    transition: all var(--transition-fast);
}
.rank-tab.active { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }
/* Danh sách BXH: chiều cao giới hạn + BẮT BUỘC cuộn dọc khi dài.
   flex:1 + min-height:0 để chia đúng phần còn lại trong panel (không đè nút).
   padding-bottom để dòng cuối không dính sát nút bên dưới */
#rank-list {
    flex: 1 1 auto;
    min-height: 0;
    max-height: 350px;
    overflow-y: auto;
    padding-bottom: 10px;
}
#rank-list::-webkit-scrollbar { width: 5px; }
#rank-list::-webkit-scrollbar-thumb { border-radius: 4px; background: rgba(128,128,128,0.4); }
.rank-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 12px;
    border-radius: var(--radius-sm);
    font-size: 0.88rem;
    font-weight: 600;
    margin-bottom: 4px;
    background: var(--bg-panel);
    border-left: 3px solid var(--border);
}
.rank-item.rank-1 { background: var(--color-warning-light); border-color: var(--color-warning); }
.rank-item.rank-2 { background: var(--bg-primary); border-color: var(--text-secondary); }
.rank-item.rank-3 { background: var(--bg-primary); border-color: var(--text-muted); }
.rank-medal { font-size: 1.2rem; min-width: 26px; text-align: center; }
.rank-name  { flex: 1; }
.rank-time  { font-size: 0.88rem; color: var(--color-primary); font-weight: 800; min-width: 60px; text-align: right; }
.rank-meta  { font-size: 0.75rem; opacity: 0.55; min-width: 70px; text-align: right; }
.btn-clear-rank {
    margin-top: 10px;
    padding: 5px 18px;
    font-size: 0.82rem;
    border-radius: 20px;
    border: none;
    cursor: pointer;
    font-weight: bold;
    opacity: 0.75;
    display: block;
    margin-left: auto;
    flex-shrink: 0; /* Nút nằm riêng dưới danh sách, không bị list co đè lên */
}
.btn-clear-rank:hover { opacity: 1; }

/* ===== NAME INPUT OVERLAY ===== */
#name-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    z-index: 100000;
    justify-content: center;
    align-items: center;
}
#name-overlay.show { display: flex; }
.name-box {
    background: var(--bg-secondary);
    border: 2px solid var(--color-warning);
    border-radius: var(--radius-2xl);
    padding: 36px 44px;
    text-align: center;
    width: 90%;
    max-width: 380px;
    box-shadow: 0 0 40px rgba(245,158,11,0.3);
    transition: background var(--transition-normal), border-color var(--transition-normal);
}
.name-box h2 { color: var(--color-warning); margin: 0 0 6px; font-size: 1.4rem; }
.name-box p  { color: var(--text-secondary); margin: 0 0 20px; font-size: 0.95rem; }
.name-box input {
    width: 100%;
    padding: 10px 16px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 1rem;
    font-weight: bold;
    box-sizing: border-box;
    margin-bottom: 16px;
    outline: none;
    text-align: center;
    transition: border-color var(--transition-fast), background var(--transition-normal);
}
.name-box input:focus { border-color: var(--color-warning); }
.btn-save-name {
    padding: 10px 36px;
    background: linear-gradient(135deg, var(--color-warning), var(--color-danger));
    color: #fff;
    border: none;
    border-radius: var(--radius-full);
    font-size: 1rem;
    font-weight: 800;
    cursor: pointer;
    letter-spacing: 1px;
    transition: filter var(--transition-fast);
}
.btn-save-name:hover { filter: brightness(1.1); }

/* ===== PLAYER CARDS (ONLINE) ===== */
.player-card {
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 10px 10px;
    border-radius: var(--radius-lg);
    color: white;
    min-width: 100px;
    max-width: 130px;
    width: 110px;
    flex-shrink: 0;
    flex-grow: 0;
    align-self: flex-start;
    box-shadow: var(--shadow-md);
    text-align: center;
    box-sizing: border-box;
}
.player-card-x {
    background: linear-gradient(135deg, var(--color-primary) 0%, #764ba2 100%);
}
.player-card-o {
    background: linear-gradient(135deg, #f093fb 0%, var(--color-danger) 100%);
}
.pc-avatar {
    width: 44px; height: 44px;
    min-width: 44px;
    border-radius: 50%;
    background: rgba(255,255,255,0.25);
    display: flex; align-items: center; justify-content: center;
    font-size: 22px; font-weight: 900;
    flex-shrink: 0;
}
.pc-info {
    min-width: 0;
    width: 100%;
}
.pc-name {
    font-size: 13px;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}
.pc-badge {
    font-size: 10px;
    opacity: 0.85;
    margin: 2px 0 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.pc-stats {
    display: flex;
    gap: 4px;
    font-size: 10px;
    flex-wrap: wrap;
    justify-content: center;
}
.pc-stats span {
    background: rgba(255,255,255,0.15);
    padding: 1px 5px;
    border-radius: 3px;
    white-space: nowrap;
}

/* Khi hiện online — flex trong game-container */
#ui-game-container .player-card {
    display: flex;
}

/* Bàn cờ giữa luôn chiếm hết không gian còn lại — quan trọng: min-width:0 để co được */
#ui-game-container > div:not(.player-card) {
    flex: 1 1 0;
    min-width: 0;
    overflow: hidden;
}

/* Màn hình vừa */
@media (max-width: 900px) {
    .player-card { min-width: 80px; max-width: 100px; width: 90px; padding: 8px 6px; gap: 4px; }
    .pc-avatar { width: 32px; height: 32px; min-width: 32px; font-size: 15px; }
    .pc-name { font-size: 10px; }
    .pc-badge { font-size: 8px; }
    .pc-stats { gap: 2px; font-size: 8px; }
}

/* Màn hình nhỏ: chuyển layout dọc, card xếp trên/dưới bàn cờ */
@media (max-width: 600px) {
    #ui-game-container {
        flex-direction: column;
        align-items: stretch;
    }
    #ui-game-container .player-card {
        flex-direction: row;
        max-width: 100%;
        min-width: unset;
        width: 100%;
        box-sizing: border-box;
        align-self: auto;
        text-align: left;
        padding: 8px 12px;
        gap: 10px;
    }
    .pc-avatar { width: 32px; height: 32px; min-width: 32px; font-size: 15px; }
    .pc-name { font-size: 12px; max-width: 200px; }
    .pc-stats { justify-content: flex-start; }
}
/* Trạng thái khi đang trong bàn cờ online */
body.in-game-active {
    overscroll-behavior: none; /* Chặn kéo nẩy trang trên iOS/Android */
}

/* Đảm bảo khu vực chứa bàn cờ không tràn ra ngoài */
#ui-game-container {
    overflow: visible; /* Để resize handles hiển thị */
    touch-action: none;
}

/* Khi online: bàn cờ ở giữa tự co giãn đúng */
body.in-game-active #inf-resizable {
    max-width: 100% !important;
}
body.in-game-active #inf-canvas,
body.in-game-active #inf-canvas-online {
    max-width: 100% !important;
    max-height: none !important;
    width: 100% !important;
    height: 100% !important;
}

/* Bot Room không bị giới hạn max-width khi in-game-active */
body.in-game-active #inf-canvas-bot {
    max-width: none !important;
}

/* Resize handles màu tím cho game-container */
.gc-resize-handle {
    position: absolute;
    /* Giá trị được ban-co.js tính: 2% chiều rộng khung, giới hạn 12–20px. */
    width: var(--gc-handle-size, 12px);
    height: var(--gc-handle-size, 12px);
    min-width: 12px;
    min-height: 12px;
    max-width: 20px;
    max-height: 20px;
    background: var(--color-primary);
    border-radius: var(--radius-sm);
    z-index: 100;
    transition: background var(--transition-fast);
    opacity: 0.6;
}
.gc-resize-handle:hover {
    background: var(--color-primary);
    opacity: 0.9;
}
.gc-resize-se {
    bottom: 0px;
    right: 0px;
    cursor: se-resize;
}
.gc-resize-sw {
    bottom: 0px;
    left: 0px;
    cursor: sw-resize;
}
.gc-resize-ne {
    top: 0px;
    right: 0px;
    cursor: ne-resize;
}
.gc-resize-nw {
    top: 0px;
    left: 0px;
    cursor: nw-resize;
}

/* ===== LOBBY LAYOUT STYLES ===== */
/* Khung bọc chung cho các ô chức năng ở sảnh */
.panel-box {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 15px;
    margin-bottom: 15px;
    transition: background var(--transition-normal), border-color var(--transition-normal);
    box-shadow: 0 2px 4px rgba(0,0,0,0.02);
}

.panel-box h3 {
    margin: 0 0 10px;
    margin-bottom: 10px;
    font-size: 16px;
    font-weight: bold;
    color: var(--text-primary);
    border-bottom: 2px solid var(--color-primary);
    padding-bottom: 5px;
}

.setup-row {
    display: flex;
    align-items: center;
    margin: 10px 0;
    font-size: 14px;
}

.btn-blue {
    width: 100%;
    padding: 12px;
    background: var(--color-info);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-weight: bold;
    cursor: pointer;
    transition: background var(--transition-fast);
}

.btn-blue:hover {
    background: var(--color-info-hover);
}

/* ==================== CẤU HÌNH DÀN HÀNG NGANG PC ==================== */
@media (min-width: 768px) {
    .lobby-layout {
        display: flex;
        gap: 20px;            /* Khoảng cách giữa cột trái và cột phải */
        max-width: 1200px;    /* Chiều rộng giới hạn tối đa cho sảnh */
        margin: 0 auto;       /* Căn giữa màn hình */
        align-items: flex-start;
    }

    .lobby-column-left {
        flex: 1.2;            /* Cột phòng chơi to hơn một chút */
        display: flex;
        flex-direction: column;
    }

    .lobby-column-right {
        flex: 1;              /* Cột bảng xếp hạng & lịch sử */
        display: flex;
        flex-direction: column;
    }
}

/* Trên thiết bị di động nhỏ thì cứ xếp dọc bình thường */
@media (max-width: 767px) {
    .lobby-layout {
        display: flex;
        flex-direction: column;
    }
}

/* ===== BOARD SIZE CONTROLS ===== */
/* KHU VỰC ĐIỀU KHIỂN KÍCH THƯỚC BÀN CỜ */
.board-size-controls {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 10px;
    margin: 10px 0;
    align-items: center;
}
.size-presets {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: center;
}
.btn-size-preset {
    padding: 6px 14px;
    background: var(--text-secondary);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-weight: bold;
    cursor: pointer;
    transition: background var(--transition-fast);
}
.btn-size-preset:hover {
    background: var(--text-primary);
}
.btn-size-preset:active {
    background: var(--text-muted);
}
.auto-size-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 4px;
}

.btn-save-size {
    padding: 6px 12px;
    font-size: 12px;
    background: var(--color-success);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    margin-left: 8px;
    transition: background var(--transition-fast);
}
.btn-save-size:hover {
    background: var(--color-success-hover);
}
.toggle-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
}
.toggle-label input[type="checkbox"] {
    display: none;
}
.toggle-slider {
    width: 40px;
    height: 20px;
    background: var(--border);
    border-radius: var(--radius-full);
    position: relative;
    transition: background var(--transition-fast);
}
.toggle-slider::before {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    background: white;
    border-radius: 50%;
    top: 2px;
    left: 2px;
    transition: transform 0.2s;
}
.toggle-label input[type="checkbox"]:checked + .toggle-slider {
    background: var(--color-success);
}
.toggle-label input[type="checkbox"]:checked + .toggle-slider::before {
    transform: translateX(20px);
}

/* ===== BOARD ZOOM CONTROLS ===== */
/* KHU VỰC ĐIỀU KHIỂN ZOOM */
.board-zoom-controls {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 10px;
    margin: 12px 0 8px 0;
    align-items: center;
    width: 100%; /* Cần thiết để ticker con stretch hết chiều ngang */
    padding: 8px 0;
}
#inf-nav {
    display: flex !important;
    align-items: center;
    flex-wrap: wrap;
}
.zoom-buttons {
    display: flex;
    gap: 10px;
}
.btn-zoom {
    padding: 6px 14px;
    background: var(--text-secondary);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-weight: bold;
    cursor: pointer;
    transition: background var(--transition-fast);
}
.btn-zoom-in {
    background: var(--color-success);
}
.zoom-presets {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: center;
}
.btn-zoom-preset {
    padding: 5px 12px;
    background: var(--text-secondary);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-weight: bold;
    cursor: pointer;
    transition: background var(--transition-fast);
}
.btn-zoom-preset:hover {
    background: var(--text-primary);
}
.btn-zoom-preset:active {
    background: var(--text-muted);
}

/* KHU VỰC CHỨA BÀN CỜ */
#game-board-container {
    width: 95%;
    max-width: 600px;         /* Giới hạn độ rộng tối đa trên PC */
    height: auto;             /* Cho phép chiều cao tự động theo nội dung */
    max-height: none;         /* Không giới hạn chiều cao tối đa */
    margin: 15px auto;        /* Căn giữa khung theo chiều ngang */
    border: 2px solid var(--color-primary);/* Viền xanh làm nổi bật khu vực bàn cờ */
    border-radius: var(--radius-md);
    background-color: var(--bg-card);
    
    /* Cho phép hiển thị tràn ra ngoài, không thanh cuộn */
    overflow: visible !important; 
    
    /* Để canvas con tự xử lý gesture — không override touch-action của canvas */
    touch-action: none; 
}

/* Đảm bảo bàn cờ thực tế bên trong luôn căn giữa nếu nhỏ hơn khung chứa */
#game-board-container table, 
#game-board-container canvas {
    margin: 0 auto;
    display: block;
}

/* ===== GAME MATCH SCREEN STYLES ===== */
#game-match-screen {
    max-width: 1000px;
    margin: 0 auto;
    padding: 8px;
    font-family: Arial, sans-serif;
    box-sizing: border-box;
    width: 100%;
}

/* Header phòng */
.match-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    padding: 10px 14px;
    border-radius: 8px;
    font-weight: bold;
    font-size: 14px;
}
.match-header span {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.match-header > div {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}
.btn-danger {
    background: var(--color-danger);
    color: white;
    border: none;
    padding: 7px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    min-width: 44px;
    min-height: 36px;
}
.btn-success {
    background: var(--color-success);
    color: white;
    border: none;
    padding: 7px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
    font-size: 13px;
    min-height: 36px;
}
.btn-kick {
    background: var(--color-warning);
    color: white;
    border: none;
    padding: 4px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    margin-left: 10px;
}
.invite-panel {
    flex: 1;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 10px;
    transition: background var(--transition-normal), border-color var(--transition-normal);
}
.invite-user-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 4px;
    border-bottom: 1px dashed var(--border);
}
.btn-invite-action {
    background: var(--color-primary);
    color: white;
    border: none;
    padding: 5px 10px;
    border-radius: 3px;
    cursor: pointer;
    font-size: 12px;
    min-height: 32px;
}

/* Khu vực 2 đấu thủ VS */
.versus-container {
    display: flex;
    justify-content: space-around;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 10px 8px;
    margin: 8px 0;
    transition: background var(--transition-normal), border-color var(--transition-normal);
}
.player-slot {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    flex: 1;
    max-width: 42%;
}
.avatar-circle {
    width: 40px;
    height: 40px;
    min-width: 40px;
    background: var(--color-primary);
    color: white;
    font-size: 20px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}
.avatar-o { background: var(--color-danger); }
.player-info { min-width: 0; }
.player-name {
    font-weight: bold;
    font-size: 14px;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100px;
}
.player-status { font-size: 11px; color: var(--text-secondary); margin-top: 2px; }
.btn-ready {
    background: var(--color-success);
    color: white;
    border: none;
    padding: 4px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 11px;
    font-weight: bold;
    margin-top: 4px;
    transition: background var(--transition-fast);
}
.btn-ready:hover {
    background: var(--color-success-hover);
}
.ready-indicator {
    font-size: 11px;
    color: var(--color-success);
    font-weight: bold;
    margin-top: 4px;
}
.vs-text {
    font-size: 20px;
    font-weight: bold;
    color: var(--text-secondary);
    flex-shrink: 0;
}

/* Lượt đi indicator */
#turn-indicator {
    text-align: center;
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    font-weight: bold;
    font-size: 13px;
    margin: 6px 0;
    transition: background var(--transition-normal), color var(--transition-normal);
    background: var(--color-info-light);
    color: var(--color-info);
    border: 1px solid var(--color-info);
}
#turn-indicator.my-turn {
    background: var(--color-success-light);
    color: var(--color-success);
    border-color: var(--color-success);
    animation: turnPulse 1s ease-in-out infinite alternate;
}
#turn-indicator.opponent-turn {
    background: var(--color-warning-light);
    color: var(--color-warning);
    border-color: var(--color-warning);
}
@keyframes turnPulse {
    from { box-shadow: 0 0 0 0 rgba(21,128,61,0.3); }
    to   { box-shadow: 0 0 0 6px rgba(21,128,61,0); }
}

/* Bàn cờ */
.match-board-section {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 8px;
    transition: background var(--transition-normal), border-color var(--transition-normal);
}

/* Khu vực dưới: Mời và Chat */
.match-footer-panels {
    display: flex;
    gap: 10px;
    margin-top: 10px;
    flex-wrap: wrap;
}
.invite-panel, .chat-panel {
    flex: 1;
    min-width: 240px;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 10px;
    box-sizing: border-box;
    transition: background var(--transition-normal), border-color var(--transition-normal);
}
.invite-panel h4, .chat-panel h4 {
    margin: 0 0 8px 0;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border);
    padding-bottom: 4px;
    font-size: 13px;
}
.scroll-list {
    height: 100px;
    overflow-y: auto;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 6px;
    font-size: 13px;
    -webkit-overflow-scrolling: touch;
}

/* Ô nhập chat */
.chat-input-row {
    display: flex;
    margin-top: 8px;
    gap: 5px;
}
.chat-input-row input {
    flex: 1;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    min-height: 36px;
    background: var(--bg-input);
    color: var(--text-primary);
    transition: border-color var(--transition-fast), background var(--transition-normal);
}
.chat-input-row button {
    background: var(--color-primary);
    color: var(--text-primary);
    border: none;
    padding: 0 14px;
    border-radius: 4px;
    min-width: 52px;
    min-height: 36px;
    font-size: 13px;
    cursor: pointer;
}

/* Mobile: chat thu gọn, footer dọc */
@media (max-width: 600px) {
    #game-match-screen { padding: 6px; }

    .match-header { font-size: 12px; padding: 8px 10px; }

    .versus-container { padding: 8px 6px; gap: 4px; }
    .player-slot { max-width: 40%; gap: 6px; }
    .avatar-circle { width: 34px; height: 34px; min-width: 34px; font-size: 16px; }
    .player-name { font-size: 12px; max-width: 80px; }
    .vs-text { font-size: 16px; }

    .match-footer-panels {
        flex-direction: column;
        gap: 8px;
        margin-top: 8px;
    }
    .invite-panel, .chat-panel { min-width: unset; }
    .scroll-list { height: 80px; }

    /* Giới hạn bàn cờ trên mobile — tối đa 55vh để còn scroll xuống (không áp dụng Bot Room) */
    .match-board-section { padding: 4px; }
    #inf-resizable { max-height: 55vh; overflow: hidden; }
    #inf-canvas { max-height: 55vh; }
    #inf-canvas-online { max-height: none !important; }

    /* Bot Room không bị giới hạn max-height trên mobile */
    #inf-canvas-bot { max-height: none !important; }

    #game-board-container {
        max-width: 100% !important;
        margin: 8px auto;
    }
}

/* Chat message styling */
.chat-message-line {
    margin-bottom: 5px;
    font-size: 13px;
    line-height: 1.4;
    word-break: break-word;
}
.chat-message-line strong {
    color: var(--color-info);
    margin-right: 4px;
}

/* ===== PING LED ===== */
.ping-led {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-left: 5px;
    vertical-align: middle;
    background: var(--text-secondary);
    box-shadow: 0 0 0 0 rgba(148,163,184,0.4);
    transition: background var(--transition-normal), box-shadow var(--transition-normal);
    flex-shrink: 0;
}
.ping-led.online {
    background: var(--color-success);
    box-shadow: 0 0 0 3px rgba(34,197,94,0.25);
    animation: ledPulse 2s ease-in-out infinite;
}
.ping-led.away {
    background: var(--color-warning);
    box-shadow: 0 0 0 3px rgba(245,158,11,0.25);
}
.ping-led.offline {
    background: var(--color-danger);
    box-shadow: 0 0 0 3px rgba(239,68,68,0.25);
}
@keyframes ledPulse {
    0%, 100% { box-shadow: 0 0 0 2px rgba(34,197,94,0.2); }
    50%       { box-shadow: 0 0 0 5px rgba(34,197,94,0.0); }
}

/* ===== QUICK CHAT ===== */
.quick-chat-bar {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    margin: 6px 0 4px;
}
.qc-btn {
    padding: 4px 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius-full);
    background: var(--bg-panel);
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    transition: background 0.15s, transform 0.1s;
    min-width: 36px;
    min-height: 32px;
}
.qc-btn:hover { background: var(--bg-primary); transform: scale(1.1); }
.qc-btn:active { transform: scale(0.95); }
.qc-more {
    background: var(--color-primary);
    color: var(--text-primary);
    border-color: var(--color-primary);
    font-size: 14px;
    font-weight: bold;
}
.qc-more:hover { background: var(--color-primary-hover); }
#quick-chat-menu {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 6px;
    padding: 6px;
    background: var(--bg-panel);
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
}
.qc-full {
    padding: 5px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-full);
    background: var(--bg-card);
    cursor: pointer;
    font-size: 12px;
    white-space: nowrap;
    transition: background 0.15s;
    min-height: 30px;
}
.qc-full:hover { background: var(--color-info-light); border-color: var(--color-info); }

/* Chat system message (quick chat gửi bởi mình) */
.chat-message-line.self strong { color: var(--color-success); }
.chat-message-line.system { color: var(--text-secondary); font-style: italic; font-size: 11px; }

/* ══════════════════════════════════════════════
   HỆ THỐNG XU, SHOP, NHIỆM VỤ, BXH ĐẠI GIA
   ══════════════════════════════════════════════ */

/* Xu balance header */
#xu-header-area {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: linear-gradient(135deg, var(--color-warning-light), var(--color-warning));
    border: 1px solid var(--color-warning);
    border-radius: var(--radius-full);
    font-size: 13px;
    font-weight: bold;
    color: var(--color-warning);
    cursor: pointer;
    flex-shrink: 0;
    white-space: nowrap;
    transition: background var(--transition-normal), border-color var(--transition-normal);
}
#xu-header-area:hover { background: linear-gradient(135deg, var(--color-warning), var(--color-warning-hover)); }
#xu-balance { font-size: 14px; color: var(--color-warning); }

/* Nút hành động nhanh (Nhiệm vụ, Shop, BXH Đại Gia) */
.xu-action-btns { display: flex; gap: 5px; flex-wrap: wrap; flex-shrink: 0; }
.xu-action-btn {
    padding: 5px 10px;
    border: none;
    border-radius: 16px;
    cursor: pointer;
    font-size: 12px;
    font-weight: bold;
    transition: opacity .2s;
    white-space: nowrap;
}
.xu-action-btn:hover { opacity: 0.85; }
.btn-nhiem-vu   { background: var(--color-success-light); color: var(--color-success); border: 1px solid var(--color-success); }
.btn-shop-av    { background: var(--color-info-light); color: var(--color-info); border: 1px solid var(--color-info); }
.btn-dagia      { background: var(--color-warning-light); color: var(--color-warning); border: 1px solid var(--color-warning); }

/* ── MODAL BASE ── */
.xu-modal-overlay {
    display: none;
    position: fixed; top:0; left:0; width:100%; height:100%;
    background: rgba(0,0,0,.55); z-index: 25000;
    justify-content: center; align-items: center;
}
.xu-modal-box {
    background: var(--bg-card); border-radius: var(--radius-lg); padding: 24px;
    width: 90%; max-width: 520px; max-height: 85vh;
    overflow-y: auto; font-family: Arial; position: relative;
    box-shadow: var(--shadow-xl);
    transition: background var(--transition-normal);
}
.xu-modal-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 16px;
}
.xu-modal-title { font-size: 18px; font-weight: bold; color: var(--text-primary); margin: 0; }
.xu-modal-close {
    background: none; border: none; font-size: 24px;
    cursor: pointer; color: var(--text-secondary); line-height: 1;
    transition: color var(--transition-fast);
}

/* ── NHIỆM VỤ ── */
.nv-item {
    display: flex; justify-content: space-between; align-items: center;
    padding: 12px; border: 1px solid var(--border); border-radius: var(--radius-md);
    margin-bottom: 10px; gap: 10px;
    transition: border-color var(--transition-normal);
}
.nv-info { display: flex; align-items: center; gap: 10px; flex: 1; }
.nv-icon { font-size: 24px; }
.nv-title { font-weight: bold; font-size: 14px; color: var(--text-primary); }
.nv-desc  { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }
.nv-btn {
    padding: 7px 14px; border: none; border-radius: 8px;
    cursor: pointer; font-size: 13px; font-weight: bold; white-space: nowrap;
}
.nv-claim { background: var(--color-success); color: white; }
.nv-claim:hover { background: var(--color-success-hover); }
.nv-done  { background: var(--bg-panel); color: var(--text-secondary); cursor: default; }

/* ── SHOP AVATAR ── */
#shop-avatar-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 12px; margin-top: 12px;
}
.av-card {
    border: 2px solid var(--border); border-radius: var(--radius-md);
    padding: 12px 8px; text-align: center;
    position: relative; transition: border-color var(--transition-normal);
    background: var(--bg-panel);
}
.av-card-equipped { border-color: var(--color-warning); background: var(--color-warning-light); }
.av-emoji { font-size: 36px; margin-bottom: 4px; }
.av-name  { font-size: 12px; font-weight: bold; color: var(--text-primary); margin-bottom: 6px; }
.av-lock  { position: absolute; top: 6px; right: 8px; font-size: 14px; }
.av-btn   { width: 100%; padding: 5px 4px; border: none; border-radius: 6px; cursor: pointer; font-size: 11px; font-weight: bold; }
.av-use   { background: var(--color-primary); color: white; }
.av-use:hover { background: var(--color-primary-hover); }
.av-buy   { background: var(--color-warning); color: white; }
.av-buy:hover { background: var(--color-warning-hover); }
.av-equipped { background: var(--bg-panel); color: var(--text-secondary); cursor: default; }

/* ── BXH ĐẠI GIA ── */
.dagia-item {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px; border-radius: var(--radius-sm);
    margin-bottom: 6px; background: var(--bg-panel);
    border: 1px solid var(--border);
    transition: background var(--transition-normal), border-color var(--transition-normal);
}
.dagia-top1 {
    background: linear-gradient(135deg, rgba(245,158,11,0.20), rgba(245,158,11,0.45));
    border-color: var(--color-warning);
}
.dagia-top2 {
    background: linear-gradient(135deg, rgba(59,130,246,0.16), rgba(59,130,246,0.24));
    border-color: var(--color-primary);
}
.dagia-top3 {
    background: linear-gradient(135deg, rgba(34,197,94,0.16), rgba(34,197,94,0.24));
    border-color: var(--color-success, #10b981);
}
.dagia-medal { font-size: 20px; flex-shrink: 0; width: 28px; }
.dagia-name  { flex: 1; font-weight: bold; font-size: 14px; color: var(--text-primary); }
.dagia-title {
    display: inline-block; font-size: 10px; font-weight: bold;
    background: var(--color-warning-light); color: var(--color-warning); border-radius: var(--radius-sm);
    padding: 1px 5px; margin-left: 6px;
}
.dagia-coins { font-size: 13px; color: var(--color-warning); font-weight: bold; white-space: nowrap; }

/* ── CƯỢC ONLINE trong phòng ── */
.bet-panel {
    background: var(--color-warning-light); border: 1px solid var(--color-warning);
    border-radius: var(--radius-sm); padding: 10px 14px; margin: 8px 0;
    font-size: 13px;
    transition: background var(--transition-normal), border-color var(--transition-normal);
}
.bet-panel label { font-weight: bold; color: var(--color-warning); }
.bet-input {
    padding: 5px 8px; border: 1px solid var(--color-warning);
    border-radius: var(--radius-sm); font-size: 13px; width: 100px;
    margin: 0 6px;
    background: var(--bg-input);
    color: var(--text-primary);
    transition: border-color var(--transition-fast), background var(--transition-normal);
}
.bet-btn {
    padding: 5px 12px; background: var(--color-warning); color: white;
    border: none; border-radius: var(--radius-sm); cursor: pointer; font-weight: bold;
    transition: background var(--transition-fast);
}

/* ── XU POPUP (+100 Xu animation) ── */
.xu-popup {
    position: fixed;
    pointer-events: none;
    z-index: 999999;
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(0, 0, 0, 0.72);
    border: 2px solid var(--color-warning);
    border-radius: 999px;
    padding: 8px 18px 8px 14px;
    box-shadow: 0 0 18px rgba(255, 215, 0, 0.55), 0 4px 16px rgba(0,0,0,0.35);
    animation: xuPopFloat 3s cubic-bezier(0.22, 1, 0.36, 1) forwards;
    white-space: nowrap;
}
.xu-popup.gain {
    border-color: var(--color-warning);
    box-shadow: 0 0 18px rgba(245, 158, 11, 0.55), 0 4px 16px rgba(0,0,0,0.35);
}
.xu-popup.loss {
    border-color: var(--color-danger);
    background: rgba(30, 18, 28, 0.94);
    box-shadow: 0 0 18px rgba(248,113,113,0.55), 0 4px 16px rgba(0,0,0,0.35);
    animation: xuPopFloatLoss 3s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}
.xu-popup-icon {
    font-size: 22px;
    line-height: 1;
    filter: drop-shadow(0 0 6px var(--color-warning));
}
.xu-popup.loss .xu-popup-icon {
    filter: drop-shadow(0 0 6px var(--color-danger));
}
.xu-popup-text {
    font-size: 20px;
    font-weight: 900;
    color: var(--color-warning);
    font-family: 'Segoe UI', system-ui, sans-serif;
    letter-spacing: 0.5px;
    text-shadow: 0 0 10px rgba(245,158,11,0.8), 0 1px 0 rgba(0,0,0,0.5);
}
.xu-popup.loss .xu-popup-text {
    color: var(--color-danger-light);
    text-shadow: 0 0 10px rgba(239,68,68,0.8), 0 1px 0 rgba(0,0,0,0.35);
}
.xu-popup.loss .xu-popup-sub {
    color: var(--color-danger-light);
}
.xu-popup-sub {
    font-size: 11px;
    color: var(--color-warning);
    margin-top: 1px;
    font-weight: 600;
}
@keyframes xuPopFloat {
    0%   { opacity: 0;   margin-top: 12px;  }
    10%  { opacity: 1;   margin-top: -4px;  }
    20%  { opacity: 1;   margin-top: 0px;   }
    75%  { opacity: 1;   margin-top: -30px; }
    100% { opacity: 0;   margin-top: -60px; }
}
@keyframes xuPopFloatLoss {
    0%   { opacity: 0;   margin-top: 12px; transform: translateX(0) rotate(-6deg); }
    10%  { opacity: 1;   margin-top: -6px; transform: translateX(-4px) rotate(-3deg); }
    30%  { opacity: 1;   margin-top: -22px; transform: translateX(4px) rotate(3deg); }
    65%  { opacity: 1;   margin-top: -44px; transform: translateX(-2px) rotate(1deg); }
    100% { opacity: 0;   margin-top: -70px; transform: translateX(0) rotate(0deg); }
}

/* BXH tab Đại Gia trong lobby */
.bxh-tabs { display: flex; gap: 6px; margin-bottom: 10px; }
.bxh-tab {
    padding: 5px 14px; border: 1px solid var(--border); border-radius: var(--radius-full);
    background: var(--bg-panel); cursor: pointer; font-size: 13px; font-weight: bold;
    transition: background var(--transition-fast), border-color var(--transition-fast);
}
.bxh-tab.active { background: var(--color-warning); color: white; border-color: var(--color-warning); }


/* ══════════════════════════════════════════════════════════════════
   SHOP SKIN QUÂN CỜ
   ══════════════════════════════════════════════════════════════════ */

/* Grid hiển thị danh sách board skin */
#shop-board-skin-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 16px;
    max-height: 60vh;
    overflow-y: auto;
    padding: 4px;
}

.shop-board-skin-card {
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 12px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    transition: all 0.2s;
}

.shop-board-skin-card:hover {
    background: rgba(255,255,255,0.08);
    border-color: rgba(255,255,255,0.2);
    transform: translateY(-2px);
}

.shop-board-skin-preview {
    width: 100%;
    height: 80px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
}

.shop-board-skin-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.shop-board-skin-name {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-primary);
}

.shop-board-skin-rarity {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
}

.shop-board-skin-desc {
    font-size: 0.75rem;
    color: var(--text-secondary);
    line-height: 1.3;
}

.shop-board-skin-actions {
    margin-top: auto;
}

.shop-board-skin-btn {
    width: 100%;
    padding: 8px 12px;
    border-radius: 6px;
    border: none;
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
}

.shop-board-skin-btn.buy {
    background: var(--color-primary);
    color: white;
}

.shop-board-skin-btn.buy:hover {
    background: var(--color-primary-hover);
}

.shop-board-skin-btn.equip {
    background: var(--color-success);
    color: white;
}

.shop-board-skin-btn.equip:hover {
    background: var(--color-success-hover);
}

.shop-board-skin-btn.equipped {
    background: var(--text-secondary);
    color: white;
    cursor: not-allowed;
}

/* Mobile */
@media (max-width: 600px) {
    #shop-board-skin-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
        gap: 12px;
        max-height: 60vh;
    }
}

/* Grid hiển thị danh sách Bot Pet */
#shop-bot-pet-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 14px;
    max-height: 68vh;
    overflow-y: auto;
    padding: 4px 2px;
}

.bot-pet-card {
    background: var(--bg-card);
    border: 2px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 14px 10px 12px;
    display: flex;
    transition: background var(--transition-normal), border-color var(--transition-normal);
    flex-direction: column;
    align-items: center;
    gap: 6px;
    transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
    position: relative;
    cursor: default;
}

.bot-pet-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 18px rgba(0,0,0,0.1);
}

.bot-pet-card-equipped {
    border-color: var(--color-success);
    background: linear-gradient(135deg, var(--color-success-light), var(--bg-card));
    box-shadow: 0 0 0 3px rgba(16,185,129,0.2);
}

.bot-pet-card-locked {
    opacity: 0.82;
}

.bot-pet-avatar {
    font-size: 3rem;
    line-height: 1;
    margin-bottom: 4px;
}

.bot-pet-name {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-primary);
    text-align: center;
}

.bot-pet-desc {
    font-size: 0.75rem;
    color: var(--text-secondary);
    line-height: 1.3;
    text-align: center;
    flex-grow: 1;
}

.bot-pet-rarity-badge {
    font-size: 0.7rem;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 999px;
    text-transform: uppercase;
}

.bot-pet-lock-icon {
    position: absolute;
    top: 8px;
    right: 8px;
    font-size: 1rem;
    opacity: 0.6;
}

.bot-pet-btn {
    width: 100%;
    padding: 8px 12px;
    border-radius: 6px;
    border: none;
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
}

.bot-pet-btn.bot-pet-buy {
    background: var(--color-primary);
    color: white;
}

.bot-pet-btn.bot-pet-buy:hover {
    background: var(--color-primary-hover);
}

.bot-pet-btn.bot-pet-cant-afford {
    background: var(--text-muted);
    color: white;
    cursor: not-allowed;
    opacity: 0.6;
}

.bot-pet-btn.bot-pet-equip {
    background: var(--color-success);
    color: white;
}

.bot-pet-btn.bot-pet-equip:hover {
    background: var(--color-success-hover);
}

.bot-pet-btn.bot-pet-equipped {
    background: var(--text-secondary);
    color: white;
    cursor: not-allowed;
}

/* Mobile */
@media (max-width: 600px) {
    #shop-bot-pet-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
        gap: 12px;
        max-height: 60vh;
    }
}

/* Bot Pet Compact Row — nhúng vào .pc-body trong player card */
.bot-pet-compact {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    margin-top: 5px;
    padding-top: 5px;
    border-top: 1px solid var(--border-light, rgba(148,163,184,0.2));
    width: 100%;
}

.bpc-info {
    display: flex;
    align-items: center;
    gap: 4px;
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

.bpc-icon {
    font-size: 14px;
    line-height: 1;
    flex-shrink: 0;
}

.bpc-name {
    font-size: clamp(9px, 1.1vw, 11px);
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.bpc-status {
    font-size: clamp(8px, 1vw, 10px);
    font-weight: 600;
    white-space: nowrap;
    flex-shrink: 0;
}
.bpc-on  { color: var(--color-success, #10b981); }
.bpc-off { color: var(--text-secondary, #94a3b8); }

.bpc-toggle {
    padding: 2px 7px;
    border: none;
    border-radius: 4px;
    font-size: clamp(8px, 1vw, 10px);
    font-weight: 700;
    cursor: pointer;
    flex-shrink: 0;
    transition: opacity 0.15s;
}
.bpc-toggle:hover { opacity: 0.85; }
.bpc-toggle-on  { background: var(--color-success, #10b981); color: #fff; }
.bpc-toggle-off { background: var(--color-danger,  #ef4444); color: #fff; }

/* Refresh button in compact online pet */
.bpc-refresh {
    padding: 2px 8px;
    border-radius: 4px;
    border: 1px solid rgba(0,0,0,0.06);
    background: var(--color-primary, #6366f1);
    color: #fff;
    font-weight: 700;
    font-size: clamp(8px, 1vw, 10px);
    cursor: pointer;
    margin-left: 6px;
}
.bpc-refresh:hover { opacity: 0.9; }

/* Grid hiển thị danh sách skin quân cờ */
#shop-skin-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 14px;
    max-height: 68vh;
    overflow-y: auto;
    padding: 4px 2px;
}

.skin-card {
    background: var(--bg-card);
    border: 2px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 14px 10px 12px;
    display: flex;
    transition: background var(--transition-normal), border-color var(--transition-normal);
    flex-direction: column;
    align-items: center;
    gap: 6px;
    transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
    position: relative;
    cursor: default;
}
.skin-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 18px rgba(0,0,0,0.1);
}
.skin-card-equipped {
    border-color: var(--color-success);
    background: linear-gradient(135deg, var(--color-success-light), var(--bg-card));
    box-shadow: 0 0 0 3px rgba(16,185,129,0.2);
}
.skin-card-locked {
    opacity: 0.82;
}

.skin-preview {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1.9rem;
    min-height: 48px;
}
.skin-vs {
    font-size: 0.65rem;
    color: var(--text-secondary);
    font-weight: bold;
}
.skin-piece-x, .skin-piece-o { line-height: 1; }

.skin-name {
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--text-primary);
    text-align: center;
    line-height: 1.2;
}
.skin-desc {
    font-size: 0.68rem;
    color: var(--text-secondary);
    text-align: center;
    line-height: 1.3;
}

.skin-rarity-badge {
    font-size: 0.65rem;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 20px;
    letter-spacing: 0.3px;
}

.skin-lock-icon {
    font-size: 1.1rem;
    position: absolute;
    top: 8px;
    right: 8px;
    opacity: 0.7;
}

/* Buttons */
.skin-btn {
    width: 100%;
    padding: 7px 0;
    border-radius: 20px;
    border: none;
    font-size: 0.78rem;
    font-weight: 700;
    cursor: pointer;
    transition: opacity 0.15s, transform 0.1s;
    margin-top: 2px;
}
.skin-btn:active { transform: scale(0.97); }

.skin-equipped {
    background: var(--color-success-light);
    color: var(--color-success);
    cursor: default;
}
.skin-use {
    background: linear-gradient(135deg, var(--color-primary), #8b5cf6);
    color: #fff;
}
.skin-use:hover { opacity: 0.88; }
.skin-buy {
    background: linear-gradient(135deg, var(--color-warning), var(--color-danger));
    color: #fff;
}
.skin-buy:hover { opacity: 0.88; }
.skin-cant-afford {
    background: var(--bg-panel);
    color: var(--text-secondary);
    cursor: not-allowed;
}

/* Header info */
.shop-skin-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    gap: 8px;
    flex-wrap: wrap;
}
.shop-skin-info b { color: var(--color-warning); }

/* Mobile */
@media (max-width: 600px) {
    #shop-skin-grid {
        grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
        gap: 10px;
        max-height: 60vh;
    }
    .skin-preview { font-size: 1.5rem; }
    .skin-name { font-size: 0.75rem; }
}

/* ================================================================
   PRACTICE MODE — Phòng đấu giả lập (DO3.txt)
   ================================================================ */

#view-training {
  background: var(--bg-secondary);
  position: relative;
  overflow: hidden;
  display: none !important;
  transition: background var(--transition-normal);
}

.practice-layout {
  display: grid;
  grid-template-columns: minmax(140px, 18%) 1fr minmax(180px, 20%);
  gap: 12px;
  padding: 12px;
  height: calc(100vh - 88px);
  max-width: 1800px; margin: 0 auto; width: 100%;
  box-sizing: border-box;
}

.practice-player-card {
  background: rgba(255,255,255,.05);
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 10px;
  padding: 16px;
  display: flex; flex-direction: column;
  align-items: center; gap: 8px;
  color: var(--text-primary);
}

.practice-avatar {
  width: 60px; height: 60px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; font-weight: 900; border: 3px solid;
  flex-shrink: 0;
}
.practice-avatar-x { background: var(--color-danger-light); border-color: var(--color-danger); color: var(--color-danger); }
.practice-avatar-o { background: var(--color-primary-light); border-color: var(--color-primary); color: var(--color-primary); }

.practice-pname {
  font-size: 14px; font-weight: 700;
  text-align: center; word-break: break-word; color: var(--text-primary);
}
.practice-pstats { font-size: 11px; color: var(--text-secondary); text-align: center; }

.practice-indicator {
  padding: 4px 12px; border-radius: 9999px;
  font-size: 11px; font-weight: 700; text-align: center;
}
.practice-indicator-active {
  background: var(--color-success-light); color: var(--color-success);
  border: 1px solid var(--color-success);
}
.practice-indicator-inactive {
  background: var(--bg-panel); color: var(--text-secondary);
  border: 1px solid transparent;
}

.practice-center {
  display: flex; flex-direction: column;
  align-items: center; position: relative;
  overflow: hidden; min-width: 0;
  justify-content: flex-start;
  min-height: 0; flex: 1 1 0;
}

.practice-status-bar {
  width: 100%;
  background: rgba(255,255,255,.05);
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 6px;
  padding: 8px 16px;
  color: var(--text-primary); font-size: 12px; font-weight: 600;
  text-align: center; margin-bottom: 8px; flex-shrink: 0;
}

.practice-board-slot {
  flex: 1; width: 100%; min-height: 0;
  display: flex; justify-content: center; align-items: center;
  position: relative; overflow: hidden;
}
.practice-board-slot > #inf-resizable { flex-shrink: 0; position: relative; }
.practice-board-slot > #board { width: 100% !important; height: 100% !important; }

.practice-right {
  display: flex; flex-direction: column; gap: 8px;
  overflow-y: auto; min-width: 0;
}

/* Nút chọn Bot */
.practice-bot-btn {
  width: 100%; padding: 12px 16px;
  background: rgba(255,255,255,.07);
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 6px;
  color: var(--text-primary); font-size: 14px; font-weight: 700;
  cursor: pointer; transition: background .15s, border-color .15s;
  text-align: center;
}
.practice-bot-btn:hover {
  background: var(--color-primary-light); border-color: var(--color-primary);
}
.practice-bot-btn-god {
  border-color: var(--color-danger);
  background: var(--color-danger-light);
  color: var(--color-danger);
}
.practice-bot-btn-god:hover {
  background: var(--color-danger); border-color: var(--color-danger);
}

/* Nút controls */
.practice-ctrl-btn {
  width: 100%; padding: 9px 12px;
  border-radius: 6px; border: 1px solid;
  font-size: 12px; font-weight: 700; cursor: pointer;
  transition: background .15s;
}
.practice-ctrl-replay {
  background: var(--color-success-light); color: var(--color-success);
  border-color: var(--color-success);
}
.practice-ctrl-replay:hover { background: var(--color-success); }
.practice-ctrl-change {
  background: var(--color-primary-light); color: var(--color-primary);
  border-color: var(--color-primary);
}
.practice-ctrl-change:hover { background: var(--color-primary); }
.practice-ctrl-exit {
  background: var(--color-danger-light); color: var(--color-danger);
  border-color: var(--color-danger);
}
.practice-ctrl-exit:hover { background: var(--color-danger); }

/* Mobile practice */
@media (max-width: 768px) {
  .practice-layout {
    display: flex; flex-direction: column;
    height: auto; min-height: calc(100vh - 80px);
    padding: 8px; gap: 8px;
    overflow-y: auto;
  }
  
  /* Nút thoát mobile-only */
  #practice-exit-btn-mobile {
    display: flex !important;
  }
  
  /* Bot card lên đầu */
  .practice-right {
    order: -1;
    max-height: none;
    overflow-y: visible;
  }
  
  /* Player card xuống dưới bàn cờ */
  .practice-left {
    order: 2;
  }
  
  /* Bàn cờ ở giữa */
  .practice-center {
    order: 1;
    width: 100%;
    flex: 1;
    min-height: 0;
  }
  
  .practice-player-card {
    flex-direction: row; padding: 8px 12px;
    align-items: center; justify-content: flex-start; gap: 12px;
  }
  .practice-avatar { width: 40px; height: 40px; font-size: 18px; }
  .practice-pstats { display: none; }
  
  .practice-board-slot {
    width: 100%;
    height: min(85vw, 55vh);
    min-height: 220px;
    flex: 1 1 auto;
  }
  
  /* Ẩn các panel không cần thiết trên mobile */
  #history-panel,
  #rank-panel,
  #admin-training-panel,
  #admin-ai-config-panel,
  #timer-panel {
    display: none !important;
  }
  
  /* Controls gọn gàng hơn */
  #practice-controls {
    flex-direction: row;
    flex-wrap: wrap;
  }
  .practice-ctrl-btn {
    flex: 1;
    min-width: 80px;
  }
}

/* Mobile battle layout (Bot Room) */
@media (max-width: 768px) {
  /* Chat panel smaller on mobile */
  .battle-chat-overlay {
    max-width: 280px;
    max-height: 300px;
    bottom: 70px;
  }
  
  .battle-chat-messages {
    max-height: 150px;
  }
  
  /* Room info smaller on mobile */
  .battle-room-info-overlay {
    max-width: 240px;
    bottom: 70px;
  }
  
  /* Player overlays smaller on mobile */
  .battle-player-overlay-left,
  .battle-player-overlay-right {
    min-width: 110px;
    max-width: 150px;
    padding: 6px 8px;
    gap: 4px;
  }

  .battle-avatar-wrapper {
    flex-shrink: 0;
  }

  .battle-avatar-circle {
    width: 24px;
    height: 24px;
    font-size: 13px;
    border-width: 1.5px;
  }

  .battle-piece-badge {
    width: 12px;
    height: 12px;
    font-size: 9px;
    top: -2px;
    right: -2px;
    border-width: 1px;
  }

  .battle-player-name {
    font-size: 10px;
    max-width: 120px;
  }

  .battle-player-stats {
    font-size: 8px;
  }

  .battle-stat-item {
    margin-right: 3px;
  }

  .battle-player-timer {
    font-size: 9px;
    padding: 3px 5px;
  }

  .battle-turn-indicator {
    font-size: 8px;
    padding: 2px 4px;
  }
  
  /* Bottom bar buttons smaller on mobile */
  .battle-bottom-bar {
    padding: 8px 12px;
    gap: 8px;
  }
  
  .battle-control-btn {
    padding: 8px 16px;
    font-size: 12px;
  }
}


/* ══════════════════════════════════════════════════════════════════
   POSITION EDITOR - Tạo Thế Cờ
   ══════════════════════════════════════════════════════════════════ */

/* Toolbar nổi bên dưới bàn cờ */
#position-editor-toolbar {
    position: fixed;
    bottom: 70px; /* trên bot-bottom-bar */
    left: 50%;
    transform: translateX(-50%);
    background: rgba(15, 23, 42, 0.97);
    border: 2px solid #8b5cf6;
    border-radius: 14px;
    padding: 10px 14px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
    z-index: 1010;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(139, 92, 246, 0.3);
    max-width: 96vw;
}

/* Nút công cụ trong editor */
.editor-tool-btn {
    padding: 7px 14px;
    border: none;
    border-radius: 7px;
    cursor: pointer;
    font-weight: bold;
    font-size: 13px;
    transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    color: #fff;
}

.editor-tool-btn:active {
    transform: scale(0.92) !important;
}

/* Trạng thái active: tool đang được chọn */
.editor-tool-btn.active,
.editor-tool-btn[data-active="true"] {
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.55), 0 0 12px rgba(139, 92, 246, 0.5);
    transform: scale(1.06);
}

/* Nút X */
.editor-tool-btn[data-tool="X"] { background: #3b82f6; }
.editor-tool-btn[data-tool="X"]:hover { background: #2563eb; }

/* Nút O */
.editor-tool-btn[data-tool="O"] { background: #ef4444; }
.editor-tool-btn[data-tool="O"]:hover { background: #dc2626; }

/* Nút Erase */
.editor-tool-btn[data-tool="Erase"] { background: #6b7280; }
.editor-tool-btn[data-tool="Erase"]:hover { background: #4b5563; }

/* Divider trong toolbar */
.editor-toolbar-divider {
    width: 1px;
    height: 28px;
    background: rgba(255, 255, 255, 0.18);
    margin: 0 2px;
    flex-shrink: 0;
}

/* Debug info panel */
#debug-info-panel {
    /* Vị trí cố định — đã inline trong HTML; CSS chỉ enhance */
    transition: opacity 0.2s ease;
}

#debug-content {
    min-height: 48px;
}

#debug-explanation {
    border-left: 3px solid #8b5cf6;
    margin-top: 8px;
    padding: 8px 10px;
    background: rgba(139, 92, 246, 0.08);
    border-radius: 0 6px 6px 0;
    font-size: 11px;
}

/* Compare bots panel */
#compare-bots-panel {
    /* Vị trí đã inline; CSS enhance */
    scrollbar-width: thin;
    scrollbar-color: #8b5cf6 transparent;
}

#compare-bots-panel::-webkit-scrollbar {
    width: 5px;
}
#compare-bots-panel::-webkit-scrollbar-thumb {
    background: #8b5cf6;
    border-radius: 3px;
}

#compare-bots-content table {
    width: 100%;
    border-collapse: collapse;
}

#compare-bots-content th,
#compare-bots-content td {
    padding: 6px 8px;
    font-size: 12px;
}

/* Hover ô bàn cờ khi đang ở editor mode */
.editor-hover-cell {
    outline: 2px dashed rgba(139, 92, 246, 0.7) !important;
    outline-offset: -2px;
    cursor: crosshair !important;
}

/* Highlight nước bot chọn (debug) */
.debug-bot-highlight {
    outline: 3px solid #fbbf24 !important;
    outline-offset: -3px;
    box-shadow: inset 0 0 8px rgba(251, 191, 36, 0.5) !important;
}

/* Responsive: toolbar nhỏ hơn trên mobile */
@media (max-width: 600px) {
    #position-editor-toolbar {
        bottom: 60px;
        padding: 8px 10px;
        gap: 5px;
        border-radius: 10px;
    }

    .editor-tool-btn {
        padding: 6px 10px;
        font-size: 12px;
        border-radius: 6px;
    }

    #debug-info-panel {
        width: 240px !important;
        top: 70px !important;
        right: 10px !important;
    }

    #compare-bots-panel {
        width: 90vw !important;
        bottom: 70px !important;
    }
}


/* ══════════════════════════════════════════════════════════════════
   BOT ROOM — OVERLAY PLAYER CARDS (theme-aware)
   ══════════════════════════════════════════════════════════════════ */

/* Fullscreen board */
.bot-room-board-container {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  z-index: 1;
}

/* Base overlay */
.bot-overlay {
  position: fixed;
  z-index: 100;
  pointer-events: none;
}
.bot-overlay * { pointer-events: auto; }

/* Player overlay — thanh ngang full width, 2 đối thủ căn giữa */
.bot-players-bar {
  top: env(safe-area-inset-top, 8px);
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  align-items: stretch;
  gap: 0;
  padding: 0 10px;
  pointer-events: none;
}

.bot-player-overlay,
.bot-bot-overlay {
  background: var(--bg-card);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  padding: clamp(6px, 1vw, 10px) clamp(10px, 1.5vw, 16px);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: clamp(3px, 0.5vw, 6px);
  flex: 1;
  max-width: 45%;
  pointer-events: auto;
  box-shadow: var(--shadow-lg);
  transition: background var(--transition-normal), border-color var(--transition-normal);
}

/* Card trái: bo góc trái */
.bot-player-overlay {
  border-radius: 12px 0 0 12px;
  border-right: none;
}

/* Card phải: bo góc phải */
.bot-bot-overlay {
  border-radius: 0 12px 12px 0;
  align-items: flex-start;
  border-left: 1px solid var(--border-light);
}

.bot-piece-badge {
  position: absolute;
  top: -3px;
  right: -3px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 900;
  border: 1.5px solid;
  background: var(--bg-card);
  z-index: 10;
}

.bot-piece-x { color: #ef4444; border-color: #ef4444; }
.bot-piece-o { color: #10b981; border-color: #10b981; }

.bot-avatar-x {
  background: rgba(239, 68, 68, 0.15);
  border-color: #ef4444;
  color: #ef4444;
}

.bot-avatar-o {
  background: rgba(16, 185, 129, 0.15);
  border-color: #10b981;
  color: #10b981;
}

/* Thông tin nhân vật */
.bot-player-details {
  width: 100%;
}

.bot-player-name {
  font-size: clamp(11px, 1.4vw, 14px);
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.bot-player-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 3px 6px;
  font-size: clamp(9px, 1.1vw, 11px);
  color: var(--text-secondary);
}

.bot-stat-item { white-space: nowrap; }

/* Lượt đi */
.bot-turn-indicator {
  padding: clamp(2px, 0.4vw, 4px) clamp(5px, 1vw, 9px);
  border-radius: var(--radius-full);
  font-size: clamp(9px, 1.1vw, 11px);
  font-weight: 700;
  background: var(--color-success-light);
  color: var(--color-success);
  border: 1px solid var(--color-success);
  text-align: center;
  white-space: nowrap;
  align-self: center;
}

.bot-turn-indicator.inactive {
  background: var(--bg-panel);
  color: var(--text-muted);
  border-color: var(--border);
}

/* Zoom overlay */
.bot-zoom-overlay {
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.bot-zoom-btn {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-full);
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-md);
}
.bot-zoom-btn:hover {
  background: var(--bg-panel);
  transform: scale(1.05);
}

/* Chat bot bubble */
.bot-chat-overlay {
  bottom: 80px;
  left: 12px;
  max-width: 240px;
}

.bot-chat-content {
  background: var(--bg-card);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 12px;
  color: var(--text-primary);
  font-weight: 600;
  box-shadow: var(--shadow-md);
  transition: background var(--transition-normal), border-color var(--transition-normal);
}

/* Bottom control bar */
.bot-bottom-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-secondary);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--border);
  padding: 10px 16px;
  display: flex;
  justify-content: space-evenly;
  align-items: center;
  gap: 6px;
  flex-wrap: nowrap;
  z-index: 100;
  transition: background var(--transition-normal), border-color var(--transition-normal);
}

.bot-control-btn {
  flex: 1;
  padding: 8px 16px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  text-align: center;
  white-space: nowrap;
  transition: all var(--transition-fast);
}
.bot-control-btn:hover { background: var(--bg-primary); }

.bot-surrender-btn {
  background: rgba(245, 158, 11, 0.1);
  border-color: var(--color-warning);
  color: var(--color-warning);
}
.bot-surrender-btn:hover { background: var(--color-warning-light); }

.bot-replay-btn {
  background: rgba(34, 197, 94, 0.1);
  border-color: var(--color-success);
  color: var(--color-success);
}
.bot-replay-btn:hover { background: var(--color-success-light); }

.bot-exit-btn {
  background: rgba(239, 68, 68, 0.1);
  border-color: var(--color-danger);
  color: var(--color-danger);
}
.bot-exit-btn:hover { background: var(--color-danger-light); }

/* ── Mobile ── */
@media (max-width: 768px) {
  .bot-players-bar { padding: 0 6px; }
  .bot-player-overlay,
  .bot-bot-overlay {
    padding: 6px 8px;
    gap: 3px;
  }

  .bot-piece-badge { width: 12px; height: 12px; font-size: 9px; top: -2px; right: -2px; }
  .bot-bottom-bar { padding: 6px 8px; gap: 4px; }
  .bot-control-btn { padding: 6px 8px; font-size: 11px; flex-shrink: 1; min-width: 0; }
}

/* Cực nhỏ ≤480px */
@media (max-width: 480px) {
  .bot-bottom-bar { padding: 5px 4px; gap: 3px; }
  .bot-control-btn { padding: 5px 6px; font-size: 10px; }
}

/* Cực nhỏ ≤400px */
@media (max-width: 400px) {
  .bot-player-overlay,
  .bot-bot-overlay { padding: 5px 7px; }
  .bot-bottom-bar { padding: 4px 2px; gap: 2px; }
  .bot-control-btn { padding: 5px 5px; font-size: 9px; }
}


/* ══════════════════════════════════════════════════════════════════
   PLAYER CARD (PlayerCard.render) — theme-aware, thay thế inline styles
   ══════════════════════════════════════════════════════════════════ */
.pc-shell {
    display: flex;
    flex-direction: column;
    width: 100%;
    padding: clamp(6px, 1vw, 10px) clamp(8px, 1.2vw, 13px);
    border-radius: 12px;
    background: transparent;
    border: none;
    box-shadow: none;
    box-sizing: border-box;
    transition: background var(--transition-normal), border-color var(--transition-normal);
}

/* Avatar nhỏ inline cạnh tên */
.pc-avatar-inline {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(14px, 1.8vw, 18px);
    margin-right: 5px;
    vertical-align: middle;
    line-height: 1;
}

.pc-body {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.pc-name {
    font-weight: 800;
    color: var(--text-primary);
    font-size: clamp(11px, 1.4vw, 14px);
    line-height: 1.25;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pc-meta {
    display: flex;
    align-items: center;
    gap: 5px;
    flex-wrap: wrap;
}

.pc-badge {
    font-size: clamp(9px, 1vw, 11px);
    padding: 2px 6px;
    border-radius: var(--radius-full);
    background: var(--bg-panel);
    color: var(--text-secondary);
    border: 1px solid var(--border);
    white-space: nowrap;
}

.pc-level {
    font-size: clamp(10px, 1.1vw, 12px);
    color: var(--color-info);
    font-weight: 700;
    white-space: nowrap;
}

.pc-title {
    font-size: clamp(10px, 1.1vw, 12px);
    color: var(--color-warning);
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pc-stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 3px 8px;
    font-size: clamp(10px, 1.1vw, 12px);
    color: var(--text-secondary);
}

.pc-stat { display: flex; flex-direction: column; gap: 1px; }
.pc-stat-label { font-weight: 700; color: var(--text-primary); font-size: clamp(9px, 1vw, 11px); }
.pc-stat-val   { font-size: clamp(10px, 1.1vw, 12px); color: var(--text-secondary); }

.pc-winbar-row {
    display: flex;
    align-items: center;
    gap: 6px;
}

.pc-winbar-track {
    flex: 1;
    height: 6px;
    border-radius: 999px;
    background: var(--border);
    overflow: hidden;
    border: 1px solid var(--border-light);
}

.pc-winbar-fill {
    height: 100%;
    border-radius: 999px;
    transition: width 0.4s ease;
}

.pc-winbar-pct {
    font-size: 10px;
    font-weight: 700;
    color: var(--text-primary);
    white-space: nowrap;
}

.pc-status {
    padding: clamp(3px, 0.5vw, 5px) clamp(6px, 0.9vw, 9px);
    border-radius: var(--radius-sm);
    font-size: clamp(9px, 1vw, 11px);
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    border: 1px solid;
}

.pc-status-active {
    background: var(--color-warning-light);
    color: var(--color-warning);
    border-color: var(--color-warning);
}

.pc-status-idle {
    background: var(--color-success-light);
    color: var(--color-success);
    border-color: var(--color-success);
}

/* Mobile: compact */
@media (max-width: 768px) {
    .pc-shell { padding: 5px 8px; }
    .pc-avatar-inline { font-size: 13px; margin-right: 4px; }
    .pc-name   { font-size: 11px; }
    .pc-title  { font-size: 10px; }
    .pc-stats-grid { font-size: 10px; }
    .pc-winbar-track { height: 5px; }
    .pc-status { font-size: 9px; padding: 3px 6px; }
}
