/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-bg: #f8f9fa;
    --secondary-bg: #ffffff;
    --text-color: #2c3e50;
    --border-color: #dee2e6;
    --light-square: #f0d9b5;
    --dark-square: #b58863;
    --highlight-color: #3498db;
    --danger-color: #e74c3c;
    --success-color: #27ae60;
    --shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    --piece-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

[data-theme="dark"] {
    --primary-bg: #2c3e50;
    --secondary-bg: #34495e;
    --text-color: #ecf0f1;
    --border-color: #4a5f7a;
    --light-square: #4a5f7a;
    --dark-square: #2c3e50;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, var(--primary-bg), var(--border-color));
    color: var(--text-color);
    min-height: 100vh;
    transition: all 0.3s ease;
}

.game-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1rem;
    min-height: 100vh;
}

.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    padding: 1rem 2rem;
    background: var(--secondary-bg);
    border-radius: 12px;
    box-shadow: var(--shadow);
}

.game-header h1 {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-color);
}

.game-controls {
    display: flex;
    gap: 1rem;
}

.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 8px;
    background: var(--highlight-color);
    color: white;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 0.95rem;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.btn-small {
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
}

.game-content {
    display: grid;
    grid-template-columns: 250px 1fr 250px;
    gap: 2rem;
    align-items: start;
}

/* Sidebar Styles */
.sidebar {
    background: var(--secondary-bg);
    padding: 1.5rem;
    border-radius: 12px;
    box-shadow: var(--shadow);
    height: fit-content;
}

.turn-indicator h3 {
    font-size: 1.25rem;
    margin-bottom: 0.5rem;
    text-align: center;
    padding: 1rem;
    background: var(--highlight-color);
    color: white;
    border-radius: 8px;
}

.game-status {
    margin-top: 1rem;
    padding: 0.75rem;
    text-align: center;
    font-weight: 600;
    border-radius: 6px;
    min-height: 2rem;
}

.game-status.check {
    background: var(--danger-color);
    color: white;
}

.game-status.checkmate {
    background: var(--danger-color);
    color: white;
}

.game-status.stalemate {
    background: var(--success-color);
    color: white;
}

.captured-pieces {
    margin-top: 2rem;
}

.captured-pieces h4 {
    margin-bottom: 1rem;
    font-size: 1rem;
    color: var(--text-color);
}

.captures-container {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    min-height: 2rem;
    padding: 0.5rem;
    background: var(--primary-bg);
    border-radius: 6px;
    border: 1px solid var(--border-color);
}

.captured-piece {
    font-size: 1.2rem;
    color: var(--text-color);
    text-shadow: var(--piece-shadow);
}

/* Chessboard Styles */
.game-board-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
}

.chessboard {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    width: min(70vh, 600px);
    height: min(70vh, 600px);
    border: 4px solid var(--border-color);
    border-radius: 8px;
    box-shadow: var(--shadow);
    background: var(--secondary-bg);
    overflow: hidden;
}

.square {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: min(6vh, 48px);
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    user-select: none;
}

.square.light {
    background-color: var(--light-square);
}

.square.dark {
    background-color: var(--dark-square);
}

.square.selected {
    background-color: var(--highlight-color) !important;
    color: white;
    box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.3);
}

.square.possible-move {
    position: relative;
}

.square.possible-move::after {
    content: '';
    position: absolute;
    width: 50%;
    height: 50%;
    background: var(--success-color);
    border-radius: 50%;
    opacity: 0.7;
}

.square.capture-move::after {
    background: var(--danger-color);
    width: 80%;
    height: 80%;
    border-radius: 50%;
    border: 3px solid var(--danger-color);
    background: transparent;
}

.square.last-move {
    background-color: rgba(255, 255, 0, 0.3) !important;
}

.square.in-check {
    background-color: rgba(231, 76, 60, 0.4) !important;
    animation: pulse-danger 2s infinite;
}

@keyframes pulse-danger {
    0%, 100% { background-color: rgba(231, 76, 60, 0.4); }
    50% { background-color: rgba(231, 76, 60, 0.6); }
}

.piece {
    text-shadow: var(--piece-shadow);
    transition: all 0.2s ease;
    z-index: 1;
}

.piece:hover {
    transform: scale(1.1);
}

/* Promotion Dialog */
.promotion-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.promotion-overlay.active {
    display: flex;
}

.promotion-dialog {
    background: var(--secondary-bg);
    padding: 2rem;
    border-radius: 12px;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.promotion-dialog h3 {
    margin-bottom: 1rem;
    color: var(--text-color);
}

.promotion-pieces {
    display: flex;
    gap: 1rem;
}

.promotion-piece {
    font-size: 3rem;
    padding: 1rem;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    background: var(--primary-bg);
}

.promotion-piece:hover {
    background: var(--highlight-color);
    color: white;
    transform: scale(1.1);
}

/* Move History */
.move-history {
    margin-bottom: 2rem;
}

.move-history h4 {
    margin-bottom: 1rem;
    color: var(--text-color);
}

.move-list {
    max-height: 200px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 0.5rem;
    background: var(--primary-bg);
    margin-bottom: 1rem;
}

.move-item {
    display: flex;
    justify-content: space-between;
    padding: 0.25rem 0.5rem;
    border-bottom: 1px solid var(--border-color);
    font-family: monospace;
    font-size: 0.9rem;
}

.move-item:last-child {
    border-bottom: none;
}

.move-number {
    font-weight: 600;
    color: var(--text-color);
}

/* Timer */
.game-timer h4 {
    margin-bottom: 1rem;
    color: var(--text-color);
}

.player-timer {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem;
    margin-bottom: 0.5rem;
    background: var(--primary-bg);
    border-radius: 6px;
    font-family: monospace;
}

.player-timer.active {
    background: var(--highlight-color);
    color: white;
}

/* Mobile Styles */
.mobile-info {
    display: none;
}

@media (max-width: 768px) {
    .game-container {
        padding: 0.5rem;
    }

    .game-header {
        flex-direction: column;
        gap: 1rem;
        padding: 1rem;
        text-align: center;
    }

    .game-header h1 {
        font-size: 1.5rem;
    }

    .game-content {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto;
        gap: 1rem;
    }

    .sidebar {
        padding: 1rem;
    }

    .left-sidebar {
        order: 3;
    }

    .game-board-container {
        order: 1;
    }

    .right-sidebar {
        order: 2;
    }

    .chessboard {
        width: min(90vw, 400px);
        height: min(90vw, 400px);
    }

    .square {
        font-size: min(10vw, 32px);
    }

    .mobile-info {
        display: block;
        background: var(--secondary-bg);
        padding: 1rem;
        border-radius: 8px;
        margin: 1rem 0;
        text-align: center;
        box-shadow: var(--shadow);
    }

    .mobile-turn {
        font-size: 1.2rem;
        font-weight: 600;
        margin-bottom: 0.5rem;
    }

    .mobile-status {
        font-weight: 500;
    }

    .captured-pieces {
        margin-top: 1rem;
    }

    .move-list {
        max-height: 150px;
    }

    .promotion-dialog {
        margin: 1rem;
        padding: 1.5rem;
    }

    .promotion-pieces {
        flex-wrap: wrap;
        justify-content: center;
        gap: 0.5rem;
    }

    .promotion-piece {
        font-size: 2rem;
        padding: 0.75rem;
    }
}

@media (max-width: 480px) {
    .game-controls {
        flex-direction: column;
        width: 100%;
    }

    .btn {
        width: 100%;
        padding: 0.6rem 1rem;
        font-size: 0.9rem;
    }

    .chessboard {
        width: min(95vw, 350px);
        height: min(95vw, 350px);
    }

    .square {
        font-size: min(12vw, 28px);
    }

    .sidebar {
        padding: 0.75rem;
    }

    .captures-container {
        min-height: 1.5rem;
    }

    .captured-piece {
        font-size: 1rem;
    }
}

/* Print Styles */
@media print {
    .sidebar, .game-controls, .mobile-info {
        display: none;
    }
    
    .game-content {
        grid-template-columns: 1fr;
    }
    
    .chessboard {
        width: 400px;
        height: 400px;
    }
}

/* Dark mode transition */
* {
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* High contrast mode */
@media (prefers-contrast: high) {
    :root {
        --light-square: #ffffff;
        --dark-square: #000000;
        --highlight-color: #0000ff;
    }
}