:root {
    --primary: #4a90e2;
    --bg: #f5f7f9;
    --card-bg: #ffffff;
    --text: #333333;
    --border: #e1e4e8;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

body {
    background-color: var(--bg);
    color: var(--text);
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
}

.container {
    width: 100%;
    max-width: 1000px;
    padding: 20px;
    transition: max-width 0.3s;
}

.card {
    background: var(--card-bg);
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    padding: 20px;
    width: 100%;
}

.hidden {
    display: none !important;
}

h1 {
    margin-bottom: 10px;
    color: var(--primary);
}

p {
    margin-bottom: 20px;
    color: #666;
}

.input-group {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}

input {
    flex: 1;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    outline: none;
    transition: border-color 0.2s;
}

input:focus {
    border-color: var(--primary);
}

button {
    padding: 12px 24px;
    background-color: var(--primary);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: opacity 0.2s;
}

button:hover {
    opacity: 0.9;
}

/* Chat Styles */
.game-container {
    display: flex;
    gap: 20px;
    align-items: stretch;
}

@media (max-width: 800px) {
    .game-container {
        flex-direction: column;
    }

    .container {
        max-width: 500px;
    }
}

.chess-section {
    flex: 1.2;
    min-width: 300px;
}

.chat-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 300px;
    border-left: 1px solid var(--border);
    padding-left: 20px;
}

@media (max-width: 800px) {
    .chat-section {
        border-left: none;
        border-top: 1px solid var(--border);
        padding-left: 0;
        padding-top: 20px;
    }
}

.game-info {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.player-info {
    display: flex;
    justify-content: space-between;
    padding: 10px;
    background: #f8f9fa;
    border-radius: 6px;
    font-weight: bold;
    border-left: 5px solid transparent;
}

.player-info.white-player {
    border-color: #4a90e2;
    /* Blue */
    color: #4a90e2;
}

.player-info.black-player {
    border-color: #e24a4a;
    /* Red */
    color: #e24a4a;
}

.timer {
    font-family: monospace;
    font-size: 1.2em;
    color: var(--primary);
}

.board {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    width: 100%;
    aspect-ratio: 1;
    border: 4px solid #333;
    user-select: none;
}

.square {
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2.5em;
    cursor: pointer;
}

.square.white {
    background-color: #f0f4f9;
}

.square.black {
    background-color: #d1d9e6;
}

.square.selected {
    background-color: #7b61ff !important;
}

.square.last-move {
    background-color: rgba(255, 255, 0, 0.3) !important;
}

.square:empty::before {
    content: '';
}

/* Chat Adjustment */
.chat-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 300px;
    border-left: 1px solid var(--border);
    padding-left: 20px;
    max-height: 600px;
    /* Fixed maximum height for the whole card content */
}

.messages-container {
    flex: 1;
    overflow-y: auto;
    text-align: left;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 10px;
}

.message {
    padding: 8px 12px;
    border-radius: 8px;
    background: #f0f2f5;
    max-width: 80%;
}

.message.own {
    align-self: flex-end;
    background: var(--primary);
    color: white;
}

.user-name {
    font-weight: bold;
    font-size: 0.8em;
    margin-bottom: 4px;
    display: block;
}

.time {
    font-size: 0.7em;
    opacity: 0.7;
    margin-left: 10px;
}

.system-message {
    text-align: center;
    font-size: 0.8em;
    color: #888;
    font-style: italic;
    margin: 5px 0;
}

/* Room UI Styles */
.room-controls {
    display: flex;
    gap: 20px;
    margin-top: 20px;
    text-align: left;
}

.room-selector, .room-creation, .join-private {
    flex: 1;
    background: #f8f9fa;
    padding: 15px;
    border-radius: 10px;
    border: 1px solid var(--border);
}

.room-list {
    max-height: 150px;
    overflow-y: auto;
    margin-top: 10px;
}

.room-item {
    padding: 8px;
    background: white;
    margin-bottom: 5px;
    border-radius: 5px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    transition: background 0.2s;
}

.room-item:hover {
    background: #eef2f7;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.9em;
    margin: 10px 0;
}

.join-private {
    margin-top: 20px;
}

/* Image Message Styles */
.message img {
    max-width: 100%;
    border-radius: 8px;
    margin-top: 5px;
    cursor: pointer;
}

#image-btn {
    background: #6c757d;
    padding: 12px 15px;
}

#connection-status {
    margin-top: 15px;
    font-size: 0.85em;
    color: #666;
}