:root {
    --bg-color: #e9ecef;
    --sidebar-bg: #ffffff;
    --text-color: #212529;
    --accent: #4CAF50;
    --accent-hover: #45a049;
    --board-light: #f0d9b5;
    --board-dark: #b58863;
    --danger: #ff4444;
    --radius: 12px; /* Increased radius for modern look */
}

[data-theme="dark"] {
    --bg-color: #1a1a1a;
    --sidebar-bg: #2d2d2d;
    --text-color: #f8f9fa;
    --board-light: #6c757d;
    --board-dark: #343a40;
}
[data-theme="wood"] {
    --bg-color: #4e342e;
    --sidebar-bg: #3e2723;
    --text-color: #efebe9;
    --board-light: #deb887;
    --board-dark: #8b4513;
    --accent: #ff9800;
}
[data-theme="neon"] {
    --bg-color: #000000;
    --sidebar-bg: #111111;
    --text-color: #00ff00;
    --board-light: #1a1a1a;
    --board-dark: #003300;
    --accent: #00ff00;
}

body {
    margin: 0;
    font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg-color);
    color: var(--text-color);
    height: 100vh;
    display: flex;
    overflow: hidden; /* Prevent body scroll, handle in containers */
    transition: background-color 0.5s ease;
}
/* Turn Backgrounds */
body.turn-white { background-color: #e0e0e0; }
body.turn-black { background-color: #4a4a4a; }
[data-theme="dark"] body.turn-white { background-color: #3d3d3d; }
[data-theme="dark"] body.turn-black { background-color: #111; }

.material-icons { font-size: 20px; vertical-align: middle; }

#app { display: flex; width: 100%; flex-direction: row; height: 100%; }

/* Mobile Menu Button */
.mobile-menu-btn {
    display: none; /* Hidden on desktop */
    position: fixed;
    top: 15px;
    left: 15px;
    z-index: 1003; /* FIX: Increased to be above sidebar (1002) */
    background: var(--sidebar-bg);
    border-radius: 50%;
    width: 45px;
    height: 45px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
    align-items: center;
    justify-content: center;
    color: var(--text-color);
    border: none;
    cursor: pointer;
}

/* Mobile Overlay */
.mobile-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.5); z-index: 999;
    opacity: 0; pointer-events: none; transition: opacity 0.3s;
    backdrop-filter: blur(2px);
}
.mobile-overlay.active { opacity: 1; pointer-events: auto; }


/* Notification Toast */
.toast {
    position: fixed; top: 20px; left: 50%; transform: translateX(-50%);
    background: var(--accent); color: white;
    padding: 10px 20px; border-radius: 30px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3); z-index: 2000;
    display: flex; align-items: center; gap: 10px; font-weight: bold;
    animation: slideDown 0.3s ease;
}
.toast.hidden { display: none; }
@keyframes slideDown { 0% { top: -50px; opacity: 0; } 100% { top: 20px; opacity: 1; } }

/* Waiting Banner */
.banner {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.85); z-index: 1100;
    display: flex; justify-content: center; align-items: center;
}
.banner.hidden { display: none !important; }
.banner-content {
    background: var(--sidebar-bg); padding: 30px;
    border-radius: var(--radius); text-align: center;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5); color: var(--text-color);
    max-width: 90%;
    width: 400px;
}
.banner-code { font-size: 2rem; font-weight: bold; color: var(--accent); margin: 15px 0; display: flex; align-items: center; justify-content: center; gap: 10px; }
.spinner {
    width: 40px; height: 40px; border: 4px solid #f3f3f3;
    border-top: 4px solid var(--accent); border-radius: 50%;
    animation: spin 1s linear infinite; margin: 0 auto 15px;
}
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

/* Sidebar */
.sidebar {
    width: 320px; 
    padding: 25px; 
    background: var(--sidebar-bg);
    box-shadow: 4px 0 15px rgba(0,0,0,0.05); 
    display: flex; flex-direction: column;
    gap: 15px; 
    overflow-y: auto; 
    z-index: 1002;
    transition: transform 0.3s ease;
    flex-shrink: 0;
}
.logo-wrapper { display: flex; align-items: center; gap: 15px; margin-bottom: 15px; }
.app-logo-img { width: 45px; height: 45px; object-fit: contain; }
.sidebar-header { margin-bottom: 10px; }
.sidebar-header h1 { margin: 0; font-size: 2rem; line-height: 1;}
.sidebar-header p { margin: 0; font-size: 0.9rem; opacity: 0.7; font-weight: bold; padding-left: 60px;}

/* Timers */
.timers { display: flex; gap: 10px; font-size: 1.2rem; font-weight: bold; justify-content: center; }
.timer { padding: 5px 15px; border-radius: 4px; background: rgba(0,0,0,0.05); min-width: 60px; text-align: center; }
.timer.white { border-bottom: 3px solid #ccc; color: var(--text-color); }
.timer.black { border-bottom: 3px solid #333; color: var(--text-color); opacity: 0.7; }
[data-theme="dark"] .timer.white { border-bottom-color: #fff; }
[data-theme="dark"] .timer.black { border-bottom-color: #000; }

.panel {
    background: rgba(0,0,0,0.03); padding: 15px;
    border-radius: var(--radius); border: 1px solid rgba(0,0,0,0.05);
}
.collapsible-panel .panel-header { display: flex; justify-content: space-between; align-items: center; cursor: pointer; user-select: none; }
.collapsible-panel .panel-header h3 { margin: 0; border-bottom: none; }
.toggle-icon { font-size: 1.2rem; transition: transform 0.3s ease; }
.panel-content { margin-top: 15px; }
.panel-content.hidden { display: none; }
.panel h3 { margin-top: 0; margin-bottom: 15px; font-size: 1rem; text-transform: uppercase; border-bottom: 2px solid var(--accent); display: inline-flex; align-items: center; gap: 8px;}

/* Graveyard */
.graveyard { display: flex; flex-direction: column; gap: 5px; }
.graveyard-row { min-height: 20px; font-size: 1.2rem; letter-spacing: 2px; }
.graveyard-img { width: 20px; height: 20px; }

/* Radio Group */
.radio-group { display: flex; gap: 10px; font-size: 0.9rem; flex-wrap: wrap; }
.radio-group label { cursor: pointer; display: flex; align-items: center; gap: 4px; padding: 5px; border: 1px solid transparent; border-radius: 6px; transition: 0.2s; background: rgba(0,0,0,0.03); }
.radio-group label:hover { background: rgba(0,0,0,0.08); }
.radio-group input { display: none; }
.radio-group input:checked + span { color: var(--accent); }

/* Controls */
.control-group { margin-bottom: 10px; }
select, input[type="text"], input[type="number"] {
    width: 100%; padding: 12px; border-radius: var(--radius);
    border: 1px solid rgba(128,128,128,0.3); background: var(--bg-color);
    color: var(--text-color); font-size: 1rem; box-sizing: border-box;
    transition: border-color 0.2s;
}
select:focus, input:focus { border-color: var(--accent); outline: none; }

button {
    width: 100%; padding: 12px; border: none;
    border-radius: var(--radius); font-weight: bold;
    cursor: pointer; transition: transform 0.1s, box-shadow 0.2s; font-size: 1rem;
    display: flex; justify-content: center; align-items: center; gap: 8px;
}
button:active { transform: scale(0.98); }
.btn-primary { background: var(--accent); color: #fff; box-shadow: 0 2px 5px rgba(0,0,0,0.1); }
.btn-secondary { background: #6c757d; color: #fff; box-shadow: 0 2px 5px rgba(0,0,0,0.1); }
[data-theme="dark"] .btn-secondary { background: #495057; }
.btn-secondary-small { padding: 8px 16px; font-size: 0.9rem; background: #666; color: #fff; width: auto; display: inline-flex;}
.btn-icon-small { padding: 5px; width: 30px; height: 30px; background: transparent; color: var(--text-color); font-size: 1.2rem; border:none; cursor: pointer; display: inline-flex; justify-content: center; align-items: center;}

.hidden { display: none !important; }

/* Chat */
.chat-messages {
    height: 150px; overflow-y: auto; border: 1px solid rgba(128,128,128,0.2);
    border-radius: var(--radius); padding: 10px; margin-bottom: 10px;
    background: rgba(0,0,0,0.02); font-size: 0.9rem; display: flex; flex-direction: column; gap: 5px;
}
.chat-msg strong { color: var(--accent); }
.chat-input-group { display: flex; gap: 5px; }
#chat-input { flex: 1; padding: 8px; font-size: 0.9rem; }

.input-with-btn { display: flex; gap: 5px; }
.btn-icon { width: 50px; padding: 10px; background: #ddd; color: #333; display: flex; justify-content: center; align-items: center; border-radius: var(--radius);}

.status-box { font-size: 1.5rem; font-weight: bold; text-align: center; color: var(--accent); padding: 5px 0;}
.game-info { text-align: center; font-size: 0.9rem; opacity: 0.7; font-weight: bold; text-transform: uppercase; }

/* Board */
.board-container {
    flex: 1; display: flex; flex-direction: column; justify-content: center; align-items: center;
    padding: 20px; background: transparent; position: relative;
    overflow: hidden;
}
.top-info-box {
    margin-bottom: 10px;
    background: var(--sidebar-bg);
    padding: 10px 20px;
    border-radius: var(--radius);
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
}
.top-info-box h2 { margin: 0; font-size: 1.2rem; color: var(--accent); text-align: center; text-transform: uppercase;}

.status-bar {
    font-size: 1.5rem; font-weight: bold; margin-bottom: 15px;
    background: var(--sidebar-bg); padding: 10px 25px; border-radius: 50px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    text-align: center; color: var(--text-color);
}
.board {
    display: grid;
    grid-template-columns: repeat(8, minmax(0, 1fr));
    grid-template-rows: repeat(8, minmax(0, 1fr));
    width: min(85vh, 85vw); height: min(85vh, 85vw);
    border: 10px solid var(--sidebar-bg); border-radius: 8px;
    box-shadow: 0 15px 40px rgba(0,0,0,0.3);
    position: relative;
}
.square {
    display: flex; justify-content: center; align-items: center;
    font-size: min(10vh, 10vw);
    cursor: pointer; user-select: none; position: relative; 
}

/* Coordinates */
.coord {
    position: absolute;
    font-size: 12px;
    font-weight: bold;
    pointer-events: none;
    z-index: 5;
}
.coord.rank { top: 2px; left: 2px; }
.coord.file { bottom: 2px; right: 2px; }
.square.light .coord { color: var(--board-dark); }
.square.dark .coord { color: var(--board-light); }


/* NEW: Piece Container for Animation */
.piece {
    width: 100%; height: 100%;
    display: flex; justify-content: center; align-items: center;
    transition: transform 0.6s ease-in-out; 
    z-index: 10;
    position: relative; 
    pointer-events: none; 
}
.piece img { width: 90%; height: 90%; object-fit: contain; filter: drop-shadow(0 4px 2px rgba(0,0,0,0.3));}

.square.light { background-color: var(--board-light); color: black; }
.square.dark { background-color: var(--board-dark); color: white; }
.square.selected { box-shadow: inset 0 0 0 4px #ffeb3b; }
.square.last-move { box-shadow: inset 0 0 0 4px rgba(66, 133, 244, 0.6); }

/* Murder King Target */
.royal { 
    color: #FFD700 !important;
    text-shadow: 0 0 10px #FF0000;
    font-weight: bold;
    transform: scale(1.1);
}

/* Stargate Mode */
.square.stargate {
    box-shadow: inset 0 0 15px 5px #00e5ff;
    animation: flux 2s infinite alternate;
}
@keyframes flux { from { box-shadow: inset 0 0 10px 2px #00e5ff; } to { box-shadow: inset 0 0 20px 5px #00e5ff; } }

/* Fog */
.square.fog {
    background: #111 !important; color: transparent !important; cursor: default;
    position: relative;
}
.square.fog::before {
    content: 'visibility_off'; 
    font-family: 'Material Icons';
    color: #333; font-size: 2rem;
    position: absolute;
}

.square.king-danger {
    box-shadow: inset 0 0 20px var(--danger); background-color: rgba(255, 0, 0, 0.4) !important;
    animation: pulse 1.5s infinite;
}
@keyframes pulse {
    0% { box-shadow: inset 0 0 10px var(--danger); }
    50% { box-shadow: inset 0 0 30px var(--danger); }
    100% { box-shadow: inset 0 0 10px var(--danger); }
}
.valid-move::after {
    content: ''; position: absolute; width: 25%; height: 25%;
    background: rgba(0,0,0,0.2); border-radius: 50%; z-index: 5;
}

/* Promotion Modal */
.promotion-options {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-top: 20px;
}
.promo-btn {
    width: 60px;
    height: 80px;
    font-size: 1rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 5px;
    background: var(--bg-color);
    border: 1px solid rgba(0,0,0,0.1);
    border-radius: var(--radius);
}
.promo-btn:hover { background: rgba(0,0,0,0.05); }
.promo-img { width: 40px; height: 40px; margin-bottom: 5px; }

/* Public Games List */
.public-list {
    margin-top: 10px;
    max-height: 200px;
    overflow-y: auto;
    border: 1px solid rgba(128,128,128,0.2);
    border-radius: var(--radius);
    padding: 5px;
    background: rgba(0,0,0,0.02);
}
.public-game-item {
    padding: 10px;
    border-bottom: 1px solid rgba(0,0,0,0.05);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.9rem;
}
.public-game-item:last-child { border-bottom: none; }
.empty-list-msg { padding: 10px; font-style: italic; opacity: 0.7; text-align: center; }

/* Footer */
.footer-links {
    margin-top: auto; padding-top: 20px; border-top: 1px solid rgba(128,128,128,0.2);
    display: flex; flex-direction: column; gap: 5px;
    /* FIX: Mobile Bottom padding */
    padding-bottom: 20px;
}
.footer-btn { background: transparent; color: var(--text-color); font-size: 0.8rem; padding: 5px; text-align: center; width: 100%; display: flex; align-items: center; justify-content: center; gap: 5px; text-decoration: none;}
.footer-btn:hover { text-decoration: underline; background: rgba(0,0,0,0.05); }
.coffee-btn { color: #FF813F; font-weight: bold; }

/* RESPONSIVE: Mobile Drawer Logic */
@media (max-width: 800px) {
    /* Main Layout reset */
    #app { display: block; overflow-x: hidden; } 
    
    /* Sidebar becomes Drawer */
    .sidebar {
        position: fixed;
        left: -350px; /* Hide off-screen */
        top: 0;
        height: 100vh;
        max-height: 100vh;
        z-index: 1002;
        width: 300px;
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        transform: translateX(0); /* State handled by JS class */
        box-shadow: 2px 0 20px rgba(0,0,0,0.5);
        padding-bottom: 80px; /* Extra padding for mobile browsers */
    }
    
    .sidebar.open {
        transform: translateX(350px);
    }

    /* Board takes full screen */
    .board-container {
        height: 100vh;
        width: 100vw;
        padding: 0;
        justify-content: center;
    }
    
    .board {
        width: 95vw;
        height: 95vw;
        max-width: 600px;
        max-height: 600px;
        border-width: 5px;
    }
    
    /* Show Mobile Menu Button */
    .mobile-menu-btn { display: flex; }
}