/* Existing Styles */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #f0f2f5;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

.hidden {
    display: none !important;
}

/* Modals */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background: white;
    padding: 30px;
    border-radius: 12px;
    text-align: center;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    min-width: 300px;
}

.modal-content h2,
.modal-content h3 {
    margin-bottom: 20px;
    color: #1e293b;
}

.modal-content input {
    padding: 8px;
    width: 40%;
    margin-bottom: 20px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 0.95rem;
}

.modal-actions {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-top: 20px;
}

/* Base Buttons */
button {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    background: #2563eb;
    color: white;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s;
}

button:hover {
    background: #1d4ed8;
    transform: translateY(-2px);
}

button:disabled {
    background: #94a3b8;
    cursor: not-allowed;
    transform: none;
}

button.secondary {
    background: #ef4444;
}

button.secondary:hover {
    background: #dc2626;
}

/* Close/Exit Buttons */
#closeGameBtn {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #ef4444;
    color: white;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    z-index: 900;
}

#closeGameBtn:hover {
    background: #dc2626;
    transform: rotate(90deg);
}

/* Layout */
.main-layout {
    display: flex;
    background: white;
    border-radius: 15px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    height: 95vh;
    /* Taller to fit big board */
    max-width: 100%;
    /* FULL WIDTH */
    width: 98vw;
    /* Almost full screen width */
    /* Almost full screen width */
    justify-content: space-between;
    /* Push sidebars to edges */
    position: relative;
    /* Context for overlay */
}

/* Sidebars (Left/Right) */
.sidebar {
    width: 280px;
    /* Slightly wider for better chat/list view */
    background: #f8fafc;
    border-left: 1px solid #e2e8f0;
    border-right: 1px solid #e2e8f0;
    display: flex;
    flex-direction: column;
    padding: 20px;
}

.chat-sidebar {
    border-right: 1px solid #e2e8f0;
    border-left: none;
}

.sidebar-header {
    padding-bottom: 15px;
    border-bottom: 1px solid #ddd;
    margin-bottom: 15px;
    text-align: center;
    color: #475569;
}

/* Board Center Section */
.board-section {
    flex: 1;
    /* Take up all remaining space */
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: #cbd5e1;
    padding: 10px;
    position: relative;
    overflow: hidden;
}

/* Container to hold Captured + Board horizontally */
.board-with-captured {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 20px;
}

/* Captured Pieces Container */
.captured-container {
    width: 45px;
    min-height: 500px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    gap: 5px;
    background: rgba(255, 255, 255, 0.4);
    padding: 10px 0;
    border-radius: 8px;
}

.captured-piece {
    width: 35px;
    height: 35px;
    object-fit: contain;
    filter: drop-shadow(1px 1px 1px rgba(0, 0, 0, 0.3));
}

/* Chess Board */
:root {
    --bg-gradient: linear-gradient(135deg, #f0f9ff 0%, #cbebff 100%);
    --primary-text: #1e293b;
    --accent: #2563eb;

    /* Classic Blue & White Theme */
    --board-light: #f0f9ff;
    --board-dark: #3b82f6;

    --panel-bg: rgba(255, 255, 255, 0.95);
}

.board {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);

    /* Maximized Size */
    width: 85vh;
    height: 85vh;
    max-width: 900px;
    max-height: 900px;
    min-width: 300px;
    min-height: 300px;

    /* Responsive */
    width: min(100%, 85vh);
    aspect-ratio: 1 / 1;

    border: 8px solid white;
    border-radius: 4px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    /* No bg color needed as squares cover it */
    margin: 0 auto;
}

.square {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
}

.square.light {
    background-color: var(--board-light);
}

.square.dark {
    background-color: var(--board-dark);
}

.square.selected {
    background-color: #facc15 !important;
}

/* Move Hints (Optional) */
.square.hint::after {
    content: '';
    width: 15px;
    height: 15px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 50%;
}

.piece {
    width: 85%;
    height: 85%;
    cursor: pointer;
    transition: transform 0.1s;
}

.piece:hover {
    transform: scale(1.1);
}

/* Status Bar */
.status-bar {
    margin-top: 15px;
    padding: 12px 25px;
    background: #fff;
    border-radius: 30px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    font-weight: 600;
    color: #1e293b;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: all 0.3s ease;
}

@keyframes blinkRed {
    0% {
        background-color: #fff;
        color: #1e293b;
        transform: scale(1);
    }

    50% {
        background-color: #fee2e2;
        color: #dc2626;
        transform: scale(1.02);
    }

    100% {
        background-color: #fff;
        color: #1e293b;
        transform: scale(1);
    }
}

.status-waiting {
    animation: blinkRed 1.5s infinite ease-in-out;
    border: 2px solid #ef4444;
}

.turn-badge {
    padding: 4px 10px;
    border-radius: 4px;
    background: #e2e8f0;
    font-size: 0.85rem;
    margin-left: 10px;
}

.turn-badge.my-turn {
    background: #22c55e;
    color: white;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.4);
    }

    70% {
        box-shadow: 0 0 0 10px rgba(34, 197, 94, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(34, 197, 94, 0);
    }
}

/* User List Items */
.user-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px;
    background: white;
    border-radius: 6px;
    margin-bottom: 8px;
    border: 1px solid #e2e8f0;
}

.status-indicator {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 8px;
}

.idle .status-indicator {
    background: #22c55e;
}

.playing .status-indicator {
    background: #f59e0b;
}

.status-badge {
    color: #64748b;
    font-size: 0.75rem;
}

.invite-btn {
    padding: 5px 10px;
    font-size: 0.8rem;
    background: #3b82f6;
}

.sidebar-footer {
    border-top: 1px solid #ddd;
    padding-top: 10px;
    margin-top: auto;
    text-align: center;
    color: #64748b;
}

/* Chat Styles */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    margin-bottom: 15px;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.message {
    padding: 8px 12px;
    border-radius: 12px;
    max-width: 80%;
    font-size: 0.9rem;
    word-wrap: break-word;
}

.message.me {
    background: #3b82f6;
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 2px;
}

.message.opponent {
    background: #f1f5f9;
    color: #334155;
    align-self: flex-start;
    border-bottom-left-radius: 2px;
}

.system-msg {
    text-align: center;
    font-size: 0.8rem;
    color: #94a3b8;
    margin: 10px 0;
}

.chat-input-area {
    display: flex;
    gap: 8px;
}

#chatInput {
    flex: 1;
    padding: 8px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    outline: none;
}

#sendChatBtn {
    padding: 8px 12px;
    background: #3b82f6;
}

/* Responsive Adjustments */
@media (max-width: 768px) {
    .main-layout {
        flex-direction: column;
        height: auto;
        min-height: 100vh;
    }

    .sidebar {
        width: 100%;
        height: auto;
        border: none;
    }

    .board-section {
        order: -1;
        padding: 10px;
    }

    .board {
        grid-template-columns: repeat(8, 1fr);
        grid-template-rows: repeat(8, 1fr);
        width: 100%;
        max-width: 400px;
        aspect-ratio: 1;
    }

    .square {
        width: auto;
        height: auto;
    }

    .piece {
        width: 80%;
        height: 80%;
    }

    .captured-container {
        display: none;
    }
}

/* Waiting Overlay */
.waiting-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: calc(100% - 280px);
    /* Covers Left Sidebar + Center */
    height: 100%;
    background: rgba(255, 255, 255, 0.75);
    /* 75% opacity */
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    backdrop-filter: blur(1px);
}

.bot-selection {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid #e2e8f0;
}

.bot-btn {
    padding: 8px 16px;
    border-radius: 20px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: transform 0.2s;
    color: white;
}

.bot-btn:hover {
    transform: scale(1.05);
}

.bot-btn.easy {
    background: #22c55e;
}

.bot-btn.medium {
    background: #f59e0b;
}

.bot-btn.hard {
    background: #ef4444;
}

.overlay-content {
    text-align: center;
    max-width: 600px;
    padding: 20px;
}

.legal-text-overlay {
    font-size: 1.1rem;
    color: #1e293b;
    font-weight: 700;
    line-height: 1.6;
    background: white;
    padding: 20px;
    border-radius: 12px;
    border: 2px solid #e2e8f0;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
}

/* User List - Grows to fill space */
.user-list {
    flex-grow: 1;
    overflow-y: auto;
    margin-bottom: 10px;
}

/* Sidebar Bot Section */
.local-game-section {
    padding: 15px;
    border-top: 1px solid #e2e8f0;
    margin-top: auto;
    /* Push to bottom */
}

.local-game-section h4 {
    margin-bottom: 10px;
    font-size: 1.1rem;
    color: #475569;
    text-align: center;
}

.bot-sidebar-btn {
    display: block;
    width: 100%;
    padding: 10px;
    margin-bottom: 8px;
    border: none;
    border-radius: 8px;
    color: white;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    text-align: left;
    padding-left: 15px;
}

.bot-sidebar-btn:hover {
    transform: translateX(3px);
    opacity: 0.9;
}

.bot-sidebar-btn.easy {
    background: #22c55e;
}

.bot-sidebar-btn.medium {
    background: #f59e0b;
}

.bot-sidebar-btn.hard {
    background: #ef4444;
}