* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: #f5f5f5;
}

body {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Header */
header {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px 16px;
    background: #2c3e50;
    color: white;
}

.selectors {
    display: flex;
    gap: 16px;
    align-items: center;
}

.selectors label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    opacity: 0.8;
}

.selectors select {
    padding: 8px 12px;
    font-size: 14px;
    border: none;
    border-radius: 4px;
    background: white;
    cursor: pointer;
    min-width: 80px;
}

#board-title {
    font-size: 18px;
    font-weight: 600;
}

/* Main content wrapper */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

/* Main board container */
.board-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 16px;
    gap: 8px;
    min-height: 0;
}

/* Sidebar with moves */
.sidebar {
    padding: 12px 16px;
    background: white;
    border-top: 1px solid #ddd;
}

/* Player cards */
.player {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 18px;
    font-weight: 500;
    width: 100%;
    max-width: 500px;
}

.player.white {
    background: #fff;
    border: 2px solid #ddd;
    color: #333;
}

.player.black {
    background: #333;
    color: #fff;
    border: 2px solid #333;
}

.player .piece {
    font-size: 28px;
}

.player .name {
    flex: 1;
}

/* Chess board */
chess-board {
    width: calc(min(100vw - 32px, 100vh - 280px, 500px));
    height: calc(min(100vw - 32px, 100vh - 280px, 500px));
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    border-radius: 4px;
}

/* Controls */
.controls {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

.controls button {
    padding: 8px 20px;
    font-size: 16px;
    font-weight: bold;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: white;
    cursor: pointer;
    transition: background 0.2s;
}

.controls button:hover:not(:disabled) {
    background: #f0f0f0;
}

.controls button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Move list */
.move-list {
    font-family: "Courier New", monospace;
    font-size: 14px;
    line-height: 1.6;
    flex: 1;
    min-height: 60px;
    max-height: 120px;
    overflow-y: auto;
    padding: 8px;
    background: #fafafa;
    border-radius: 4px;
    border: 1px solid #eee;
}

.move-list .move-pair {
    display: inline-block;
    margin-right: 12px;
}

.move-list .move-num {
    color: #666;
    margin-right: 4px;
}

.move-list .highlight {
    background: #fffacd;
    padding: 2px 4px;
    border-radius: 2px;
}

/* Game result */
.game-result {
    margin-top: 12px;
    padding: 16px;
    text-align: center;
    font-size: 18px;
    font-weight: 600;
    border-radius: 8px;
    background: #f0f0f0;
    border: 2px solid #ddd;
}

.game-result.white-won {
    background: #f0f0f0;
    border-color: #ddd;
    color: #333;
}

.game-result.black-won {
    background: #333;
    border-color: #111;
    color: white;
}

.game-result.draw {
    background: #fff3e0;
    border-color: #ff9800;
    color: #e65100;
}

/* Responsive adjustments */
@media (max-width: 600px) {
    header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .selectors {
        width: 100%;
        gap: 8px;
    }

    .selectors label {
        flex: 1;
    }

    .selectors select {
        width: 100%;
        min-width: 0;
    }

    #board-title {
        font-size: 16px;
    }

    .player {
        font-size: 16px;
        padding: 8px 16px;
    }

    .player .piece {
        font-size: 24px;
    }

    chess-board {
        width: calc(min(100vw - 32px, 100vh - 320px));
        height: calc(min(100vw - 32px, 100vh - 320px));
    }
}

/* Hide elements when not needed */
.board-container[style*="display: none"] ~ .sidebar {
    display: none;
}

/* Large screen layout - sidebar on the right */
@media (min-width: 900px) {
    .main-content {
        flex-direction: row;
    }

    .board-container {
        flex: 0 0 auto;
        padding: 24px;
    }

    .sidebar {
        flex: 1;
        display: flex;
        flex-direction: column;
        border-top: none;
        border-left: 1px solid #ddd;
        padding: 24px;
        min-width: 280px;
        max-width: 400px;
    }

    .move-list {
        flex: 1;
        max-height: none;
        min-height: 200px;
    }

    .move-list .move-pair {
        display: block;
        margin-right: 0;
        padding: 4px 0;
        border-bottom: 1px solid #eee;
    }

    .move-list .move-pair:last-child {
        border-bottom: none;
    }

    chess-board {
        width: calc(min(100vh - 180px, 600px));
        height: calc(min(100vh - 180px, 600px));
    }

    .player {
        max-width: calc(min(100vh - 180px, 600px));
    }
}
