* {
    box-sizing: border-box;
}

body {
    background-color: #393e46;
    margin: 0;
    padding: 0;
    width: 100vw;
    height: 100vh;
    overflow-x: hidden;
    overflow-y: auto;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

.headline {
    position: fixed;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    background: #1e1f26;
    color: #fff;
    box-shadow: 0 10px 25px rgba(0,0,0,0.4);
    height: 50px;
    border-radius: 12px;
    width: 350px;
    max-width: 90vw;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.main {
    width: 100%;
    min-height: 100vh;
    padding-top: 80px;
    padding-bottom: 40px;
    position: relative;
}

/* Base Window Style */
.window {
    background: #1e1f26;
    border-radius: 16px;
    box-shadow: 0 15px 40px rgba(0,0,0,0.4);
    color: #fff;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.window-header {
    background: #2a2c36;
    padding: 12px;
    cursor: move;
    text-align: center;
    font-weight: bold;
    user-select: none;
    border-bottom: 1px solid #333;
    height: 44px;
    flex-shrink: 0;
}

.window-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

/* Desktop Positioning */
@media (min-width: 769px) {
    .window { position: absolute; }
    #chessboard-container {
        width: 600px;
        height: 604px; /* 44px header + 560px board */
        top: 80px;
        left: 40px;
        z-index: 100;
    }
    #sidebar-tools {
        width: 280px;
        top: 80px;
        left: 660px;
        z-index: 101;
    }
    #sidebar-history {
        width: 300px;
        top: 80px;
        left: 960px;
        z-index: 102;
        max-height: 85vh;
    }
    .main { overflow: hidden; height: 100vh; padding: 0; }
}

/* Mobile Positioning */
@media (max-width: 768px) {
    .main {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 20px;
        padding-top: 70px;
        overflow-y: auto;
    }
    .window {
        position: relative;
        width: 95vw !important;
        height: auto !important;
        flex-shrink: 0;
    }
    #chessboard-container {
        height: calc(95vw + 44px);
    }
}

/* Chessboard Rigidity */
#chessboard-container .window-content {
    padding: 0;
    justify-content: center;
    align-items: center;
    overflow: hidden; /* CRITICAL: No scrollbars here */
}

.chessboard {
    width: 560px;
    height: 560px;
    display: flex;
    flex-direction: column;
    background: #000;
    flex-shrink: 0;
    contain: layout size;
}

@media (max-width: 768px) {
    .chessboard {
        width: 90vw;
        height: 90vw;
    }
}

.chess_row {
    width: 100%;
    height: 12.5%;
    display: flex;
    flex-direction: row;
    flex-shrink: 0;
}

.chess_square {
    width: 12.5%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    flex-shrink: 0;
    overflow: hidden;
}

.white { background-color: #f7f7f7; }
.black { background-color: #929aab; }

.piece {
    width: 90%;
    height: 90%;
    cursor: grab;
    pointer-events: auto;
}

/* UI Elements */
.tool-section { padding: 15px; border-bottom: 1px solid #333; }
.tool-section h3 { font-size: 11px; opacity: 0.5; text-transform: uppercase; margin-bottom: 10px; }

.tool-btn {
    width: 100%;
    padding: 12px;
    border: none;
    border-radius: 8px;
    background: #2a2c36;
    color: white;
    cursor: pointer;
    margin-bottom: 8px;
    transition: background 0.2s;
    font-size: 14px;
}
.tool-btn:hover { background: #3a3d4a; }
.tool-btn.highlight { background: #4a90e2; }
.tool-btn.danger { background: #802d2d; }

input, select { background: #111; color: white; border: 1px solid #333; padding: 10px; border-radius: 6px; font-size: 14px; width: 100%; }

/* History Table */
.history-table { width: 100%; border-collapse: collapse; }
.history-table th { padding: 12px; background: #2a2c36; position: sticky; top: 0; }
.history-table td { padding: 10px; text-align: center; border-bottom: 1px solid #222; }

/* Modal Overlays */
.modal-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.85); z-index: 5000;
    display: flex; align-items: center; justify-content: center;
    backdrop-filter: blur(5px);
}
.modal-card {
    background: #1e1f26; padding: 30px; border-radius: 20px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.5); text-align: center;
    width: 400px; color: white; border: 1px solid #333;
}
.modal-section { margin: 25px 0; }
.color-selection { display: flex; gap: 15px; justify-content: center; margin-top: 15px; }
.color-btn { 
    padding: 20px; border: none; border-radius: 12px; 
    font-weight: bold; cursor: pointer; font-size: 16px; flex: 1;
    transition: transform 0.2s;
}
.color-btn:hover { transform: scale(1.05); }
.color-btn.white { background: #f7f7f7; color: #000; }
.color-btn.black { background: #2a2c36; color: #fff; border: 1px solid #444; }

/* Locked state */
.locked { opacity: 0.3; pointer-events: none; filter: grayscale(1); }

/* Status Indicators */
.last-move-highlight { background-color: rgba(245, 246, 130, 0.8) !important; }
.legal-move-dot { width: 25%; height: 25%; background: rgba(0,0,0,0.2); border-radius: 50%; pointer-events: none; }
.legal-capture-dot { width: 85%; height: 85%; border: 4px solid rgba(0,0,0,0.2); border-radius: 50%; pointer-events: none; }

.spinner {
    width: 20px; height: 20px; border: 3px solid rgba(255,255,255,0.3);
    border-top-color: #fff; border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
