/* =========================================
   1. BIẾN MÀU SẮC & CẤU HÌNH CHUNG
   ========================================= */
:root {
    --primary-color: #3498db;       /* Xanh da trời chủ đạo */
    --primary-dark: #2980b9;        /* Xanh đậm hơn cho hover */
    --secondary-color: #2ecc71;     /* Xanh lá cho nút phụ */
    --accent-color: #f1c40f;        /* Vàng nổi bật */
    --text-color: #2c3e50;          /* Màu chữ tối */
    --bg-gradient: linear-gradient(180deg, #e0f7fa 0%, #ffffff 100%); /* Nền chuyển màu */
    --panel-bg: rgba(255, 255, 255, 0.90); /* Nền kính mờ */
    --panel-border: 1px solid rgba(255, 255, 255, 0.8);
    --shadow-soft: 0 8px 30px rgba(0, 0, 0, 0.12);
    --shadow-hard: 0 10px 20px rgba(0, 0, 0, 0.15);
    --font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

/* Reset cơ bản cho phạm vi Plugin */
#nak-chess-wrapper * {
    box-sizing: border-box;
}

/* =========================================
   2. KHUNG BAO NGOÀI (WRAPPER)
   ========================================= */
#nak-chess-wrapper {
    position: relative;
    width: 100%;
    max-width: 500px; /* Giới hạn chiều rộng giống App Mobile */
    height: 90vh;     /* Chiều cao 90% màn hình */
    min-height: 600px;
    margin: 20px auto;
    background: var(--bg-gradient);
    border-radius: 25px;
    overflow: hidden; /* Ẩn các phần thừa */
    font-family: var(--font-family);
    color: var(--text-color);
    box-shadow: var(--shadow-soft);
    border: 4px solid #fff; /* Viền trắng dày sang trọng */
}

/* =========================================
   3. BACKGROUND DECOR (MÂY TRÔI)
   ========================================= */
.cloud {
    position: absolute;
    background: #fff;
    border-radius: 50%;
    opacity: 0.6;
    filter: blur(20px); /* Làm mờ tạo cảm giác mây */
    z-index: 0;
    animation: floatCloud 10s infinite alternate ease-in-out;
}

.cloud-1 {
    width: 180px; height: 180px;
    top: -60px; left: -40px;
}

.cloud-2 {
    width: 120px; height: 120px;
    bottom: 120px; right: -30px;
    background: #b3e5fc;
    animation-delay: 2s;
}

@keyframes floatCloud {
    0% { transform: translate(0, 0); }
    100% { transform: translate(10px, 15px); }
}

/* =========================================
   4. PANEL STYLES (GLASSMORPHISM)
   ========================================= */
.light-panel, 
.light-panel-sm, 
.light-panel-bottom {
    background: var(--panel-bg);
    backdrop-filter: blur(12px); /* Hiệu ứng mờ nền phía sau */
    -webkit-backdrop-filter: blur(12px);
    border: var(--panel-border);
    z-index: 10;
}

/* =========================================
   5. MÀN HÌNH CHÀO MỪNG (START SCREEN)
   ========================================= */
#nak-start-screen {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 20px;
}

.nak-content {
    width: 100%;
    max-width: 350px;
}

.avatar-large img {
    width: 120px; height: 120px;
    border-radius: 50%;
    border: 5px solid #fff;
    box-shadow: var(--shadow-hard);
    margin: 15px 0;
    object-fit: cover;
    animation: pulseAvatar 3s infinite;
}

@keyframes pulseAvatar {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

/* Input Tên */
.input-group input {
    width: 100%;
    padding: 15px;
    border-radius: 30px;
    border: 2px solid #dfe6e9;
    text-align: center;
    margin-bottom: 20px;
    font-size: 16px;
    color: #333;
    outline: none;
    transition: 0.3s;
    background: rgba(255,255,255,0.8);
}

.input-group input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 10px rgba(52, 152, 219, 0.2);
}

/* Radio Buttons (Độ khó) */
.difficulty-options {
    display: flex;
    background: #fff;
    padding: 6px;
    border-radius: 40px;
    margin-bottom: 25px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.05);
}

.radio-option {
    flex: 1;
    cursor: pointer;
    text-align: center;
    margin: 0;
}

.radio-option input { display: none; }

.radio-option span {
    display: block;
    padding: 10px;
    border-radius: 30px;
    font-size: 14px;
    color: #7f8c8d;
    transition: all 0.3s;
    font-weight: 500;
}

.radio-option input:checked + span {
    background: var(--primary-color);
    color: white;
    font-weight: bold;
    box-shadow: 0 2px 8px rgba(52, 152, 219, 0.4);
}

/* Buttons */
.btn-primary {
    width: 100%;
    padding: 16px;
    border: none;
    border-radius: 40px;
    background: linear-gradient(45deg, var(--primary-color), var(--primary-dark));
    color: white;
    font-weight: bold;
    font-size: 18px;
    cursor: pointer;
    box-shadow: 0 8px 20px rgba(52, 152, 219, 0.4);
    transition: transform 0.2s;
}

.btn-primary:active { transform: scale(0.96); }

.btn-secondary {
    background: var(--secondary-color);
    color: white;
    border: none;
    padding: 12px 25px;
    border-radius: 30px;
    cursor: pointer;
    font-weight: bold;
    width: 100%;
    font-size: 15px;
    box-shadow: 0 4px 10px rgba(46, 204, 113, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

/* =========================================
   6. GIAO DIỆN TRONG GAME (GAME UI)
   ========================================= */
#nak-game-ui {
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* Header */
.nak-header {
    flex-shrink: 0; /* Không bị co lại */
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 15px;
    margin: 15px;
    border-radius: 20px;
    background: #fff;
    box-shadow: 0 4px 15px rgba(0,0,0,0.05);
}

.player-pill {
    display: flex;
    align-items: center;
    gap: 12px;
}

.avatar-sm img {
    width: 45px; height: 45px;
    border-radius: 50%;
    border: 2px solid #f1f2f6;
}

.info {
    display: flex;
    flex-direction: column;
}

.info strong { font-size: 15px; }

.status-badge {
    font-size: 12px;
    color: #e67e22; /* Màu cam */
    font-weight: 600;
}

.header-actions {
    display: flex;
    gap: 8px;
}

.icon-btn {
    background: #f1f2f6;
    border: none;
    color: var(--text-color);
    width: 40px; height: 40px;
    border-radius: 50%;
    cursor: pointer;
    transition: 0.2s;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 16px;
}

.icon-btn:hover {
    background: #dfe4ea;
    transform: translateY(-2px);
}

/* =========================================
   7. BÀN CỜ (BOARD AREA) - HIỆU ỨNG 3D
   ========================================= */
#board-area {
    padding: 0 10px;
    display: flex;
    justify-content: center;
    perspective: 1000px; /* Tạo chiều sâu */
    margin-top: 10px;
}

#board-frame {
    width: 100%;
    max-width: 400px; /* Không quá to trên desktop */
    padding: 10px;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.2); /* Bóng đổ lớn tạo cảm giác nổi */
    transform: rotateX(5deg); /* Nghiêng nhẹ */
    transition: transform 0.5s;
}

/* Chessboard.js Fixes (Sửa lỗi thư viện) */
.board-b72b1 {
    border: none !important;
}
.square-55d63 {
    /* Đảm bảo ô cờ không bị lệch */
}

/* =========================================
   8. CHAT BOX (KHUNG CHAT)
   ========================================= */
#nak-chat-box {
    position: absolute;
    bottom: 0; left: 0; width: 100%;
    height: 42%; /* Chiều cao mặc định */
    display: flex;
    flex-direction: column;
    border-top: 1px solid rgba(255,255,255,0.5);
    background: #fff;
    border-top-left-radius: 25px;
    border-top-right-radius: 25px;
    box-shadow: 0 -5px 20px rgba(0,0,0,0.05);
    transition: height 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275); /* Hiệu ứng nảy */
}

/* Trạng thái ẩn */
#nak-chat-box.hidden {
    height: 50px;
}

/* Thanh kéo (Handle) */
.chat-header-handle {
    padding: 12px;
    text-align: center;
    cursor: pointer;
    flex-shrink: 0;
}

.handle-bar {
    display: inline-block;
    width: 50px; height: 5px;
    background: #dfe6e9;
    border-radius: 5px;
}

/* Lịch sử chat */
#chat-history {
    flex: 1;
    overflow-y: auto;
    padding: 10px 15px;
    background: #f8f9fa; /* Màu nền xám rất nhạt */
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
}

/* Tùy chỉnh thanh cuộn */
#chat-history::-webkit-scrollbar {
    width: 5px;
}
#chat-history::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 5px;
}

/* Tin nhắn */
.msg {
    padding: 10px 15px;
    border-radius: 18px;
    font-size: 14px;
    max-width: 80%;
    line-height: 1.5;
    position: relative;
    word-wrap: break-word;
    animation: popMessage 0.3s ease-out;
}

@keyframes popMessage {
    from { opacity: 0; transform: translateY(10px) scale(0.9); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.msg-khang {
    background: #fff;
    border: 1px solid #eee;
    color: #333;
    align-self: flex-start; /* Nằm bên trái */
    border-bottom-left-radius: 4px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.03);
}

.msg-user {
    background: var(--primary-color);
    color: white;
    align-self: flex-end; /* Nằm bên phải */
    border-bottom-right-radius: 4px;
    box-shadow: 0 2px 5px rgba(52, 152, 219, 0.3);
}

/* Khu vực nhập liệu */
.chat-input-area {
    padding: 15px;
    display: flex;
    gap: 10px;
    background: #fff;
    border-top: 1px solid #f1f2f6;
}

#chat-input {
    flex: 1;
    padding: 12px 20px;
    border-radius: 25px;
    border: 1px solid #dfe6e9;
    background: #f1f2f6;
    outline: none;
    font-size: 14px;
    transition: 0.2s;
}

#chat-input:focus {
    background: #fff;
    border-color: var(--primary-color);
}

#send-chat {
    width: 45px; height: 45px;
    border-radius: 50%;
    border: none;
    background: var(--primary-color);
    color: white;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: 0.2s;
}

#send-chat:hover {
    background: var(--primary-dark);
    transform: rotate(-10deg);
}

/* Typing Indicator (Dấu chấm động) */
#typing-indicator {
    padding-left: 20px;
    margin-bottom: 5px;
    font-size: 24px;
    color: #bdc3c7;
    height: 20px;
    line-height: 10px;
    display: flex;
    gap: 2px;
}

#typing-indicator span {
    animation: blinkTyping 1.4s infinite both;
}

#typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
#typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes blinkTyping {
    0% { opacity: 0.2; }
    20% { opacity: 1; }
    100% { opacity: 0.2; }
}

/* =========================================
   9. RESPONSIVE (ĐIỆN THOẠI)
   ========================================= */
@media (max-width: 480px) {
    #nak-chess-wrapper {
        height: 100vh; /* Full màn hình trên mobile */
        margin: 0;
        border-radius: 0;
        border: none;
    }

    #board-frame {
        transform: rotateX(0deg); /* Bỏ hiệu ứng 3D trên mobile để dễ nhìn hơn */
        box-shadow: 0 5px 15px rgba(0,0,0,0.1);
    }
    
    .msg {
        max-width: 85%;
    }
}