body {
    display: flex;
    flex-direction: column; 
    justify-content: center;
    align-items: center;
    min-height: 100vh; /* 👈 ป้องกันปัญหาเลื่อนหน้าจอแนวตั้งไม่ได้ */
    background-color: #302e2b; 
    margin: 0;
    font-family: sans-serif;
    padding: 10px;
    box-sizing: border-box;
}

#turn-indicator {
    margin-bottom: 15px;
    font-size: 16px;
    color: #ffffff;
    background-color: #262421;
    padding: 12px 20px;
    border-radius: 10px;
    font-weight: bold;
    box-shadow: 0 4px 15px rgba(0,0,0,0.4);
    text-align: center;
    border: 1px solid #403e3a;
    max-width: 90vw;
}

#chessboard {
    display: grid;
    grid-template-columns: repeat(8, min(70px, 11vw));
    grid-template-rows: repeat(8, min(70px, 11vw));
    border: 4px solid #01050c00;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    margin: 0 auto;
}

#game-view {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

/* 💬 สไตล์สำหรับระบบแชต */
    .chat-container {
        width: 100%;
        max-width: 400px;
        background-color: #262522;
        border: 2px solid #312e2b;
        border-radius: 8px;
        margin: 20px auto;
        font-family: 'Kanit', sans-serif;
        overflow: hidden;
        box-shadow: 0 4px 15px rgba(0,0,0,0.3);
    }
    .chat-header {
        background-color: #312e2b;
        color: #bab9b8;
        padding: 10px;
        font-weight: bold;
        text-align: center;
        border-bottom: 1px solid #403d39;
    }
    .chat-messages {
        height: 180px;
        overflow-y: auto;
        padding: 10px;
        display: flex;
        flex-direction: column;
        gap: 8px;
    }
    .chat-message {
        max-width: 85%;
        padding: 8px 12px;
        border-radius: 8px;
        font-size: 13px;
        line-height: 1.4;
        word-break: break-word;
    }
    
    .chat-message.sender-W {
        align-self: flex-start;
        background-color: #f1c40f;
        color: #302e2b;
        border-bottom-left-radius: 2px;
    }
    /* ข้อความจากผู้เล่นสีดำ (จัดชิดขวา) */
    .chat-message.sender-B {
        align-self: flex-end;
        background-color: hsl(251, 90%, 45%);
        color: #ffffff;
        border-bottom-right-radius: 2px;
    }
    /* ข้อความจากผู้ชมทั่วไป */
    .chat-message.sender-spectator {
        align-self: flex-start;
        background-color: #312e2b;
        color: #bab9b8;
        border: 1px solid #403d39;
    }
    .chat-input-area {
        display: flex;
        border-top: 1px solid #312e2b;
        background-color: #1a1917;
    }
    #chat-input {
        flex: 1;
        background: transparent;
        border: none;
        padding: 12px;
        color: #ffffff;
        outline: none;
        font-size: 14px;
    }
    #chat-input::placeholder {
        color: #63615e;
    }
    .chat-input-area button {
        background-color: #f1c40f;
        color: #000000;
        border: none;
        padding: 0 20px;
        cursor: pointer;
        font-weight: bold;
        transition: background 0.2s;
    }
    .chat-input-area button:hover {
        background-color: #86ab63;
    }

.square.last-move {
    background-color: rgba(226, 247, 37, 0.438) !important;
    box-shadow: inset 0 0 0 2px rgba(255, 193, 7, 0.5);
}

.square {
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: min(45px, 7.5vw);
    cursor: pointer;
    user-select: none;
    position: relative;
}

.suggested-move::before {
    content: '';
    width: min(20px, 3vw);
    height: min(20px, 3vw);
    background-color: rgba(4, 255, 46, 0.678);
    border-radius: 50%;
    position: absolute;
    pointer-events: none;
}

.suggested-capture {
    box-shadow: inset 0 0 0 min(6px, 1vw) rgba(235, 97, 97, 0.8) !important;
}

.suggested-swap {
    box-shadow: inset 0 0 0 min(6px, 1vw) rgba(155, 89, 182, 0.8) !important;
}

.light { background-color: #ffffff; }
.dark { background-color: #000000; }

.selected {
    background-color: #baca44 !important;
}

.threatening-piece {
    box-shadow: inset 0 0 0 min(5px, 0.9vw) #ff9f43 !important;
    background-color: rgba(226, 118, 17, 0.925) !important;
}

.king-checked {
    background-color: rgba(197, 20, 20, 0.801) !important;
    border: 5px solid rgba(255, 0, 0, 0.8) !important;
    animation: pulse-danger 1s infinite alternate;
}
@keyframes pulse-danger {
    from { background-color: rgba(235, 97, 97, 0.4); }
    to { background-color: rgba(153, 21, 21, 0.85); }
}

#online-control {
    margin-bottom: 15px;
    text-align: center;
    color: rgb(255, 255, 255);
}
#online-control button {
    padding: 10px 16px;
    font-size: min(16px, 3.8vw);
    margin: 5px;
    cursor: pointer;
    border-radius: 5px;
    border: none;
    font-weight: bold;
}
.btn-white { background-color: #f1c40f; color: #000000; }
.btn-black { background-color: hsl(251, 90%, 45%); color: rgb(255, 255, 255); }
.btn-reset { background-color: #e74c3c; color: white; } /* ปุ่มรีเซ็ตสีแดง */
.btn-reset:hover { background-color: #c0392b; }

#promotion-modal {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex; justify-content: center; align-items: center;
    z-index: 100;
}
.promotion-options {
    background: white; padding: 20px; border-radius: 10px; display: flex; gap: 20px;
}
.promotion-options div {
    font-size: min(50px, 8vw); cursor: pointer; padding: 10px; border: 2px solid transparent;
}
.promotion-options div:hover { background: #eee; border-color: #769656; }
.hidden { display: none !important; }

/*สีตัวหมากรุก*/
.piece-yellow {
    color: #f1c40f !important; /* สีเหลืองสด */
    text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.8), -1px -1px 3px rgba(0, 0, 0, 0.8); /* เงานอกสีดำช่วยให้เด่นชัด */
}

.piece-red {
    color: hsl(251, 90%, 45%) !important; /* สีน้ำเงินสด */
    text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.8), -1px -1px 3px rgba(0, 0, 0, 0.8);
}         