:root {
    --light-square: #f0d9b5;
    --dark-square: #b58863;
    --highlight-color: #f6f669;
    --valid-move-color: rgba(0, 0, 0, 0.2);
    --check-color: #ff6b6b;
    --primary-color: #2c3e50;
    --secondary-color: #34495e;
    --accent-color: #3498db;
    --text-color: #2c3e50;
    --bg-color: #ecf0f1;
    --border-color: #bdc3c7;
    --shadow-color: rgba(0, 0, 0, 0.1);
    --transition-speed: 0.3s;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-color);
    color: var(--text-color);
    overflow-x: hidden;
}

.app-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Start Screen */
.start-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    transition: opacity 0.5s, transform 0.5s;
}

.start-screen.hidden {
    opacity: 0;
    transform: scale(0.9);
    pointer-events: none;
}

.start-content {
    text-align: center;
    max-width: 500px;
    padding: 2rem;
}

.game-title {
    font-size: 3.5rem;
    font-weight: 700;
    color: white;
    margin-bottom: 3rem;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
}

.game-title i {
    color: var(--accent-color);
    margin-right: 1rem;
}

.mode-selection, .difficulty-selection, .color-selection {
    margin-bottom: 2rem;
}

.mode-selection h2, .difficulty-selection h2, .color-selection h2 {
    color: white;
    margin-bottom: 1.5rem;
    font-size: 1.5rem;
    font-weight: 500;
}

.mode-buttons, .difficulty-buttons {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
}

.color-buttons {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
}

.mode-btn, .difficulty-btn, .color-btn {
    background: white;
    border: none;
    padding: 1.5rem 2rem;
    border-radius: 12px;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--primary-color);
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    min-width: 150px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.mode-btn:hover, .difficulty-btn:hover, .color-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
}

.mode-btn.selected, .difficulty-btn.selected, .color-btn.selected {
    background: var(--accent-color);
    color: white;
}

.mode-btn i, .difficulty-btn i, .color-btn i {
    font-size: 2rem;
    color: var(--accent-color);
}

.color-btn.selected i {
    color: white;
}

.theme-btn {
    background: transparent;
    border: 2px solid white;
    color: white;
    padding: 1rem 2rem;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-top: 2rem;
}

.theme-btn:hover {
    background: white;
    color: var(--primary-color);
}

/* Game Screen */
.game-screen {
    display: none;
    opacity: 0;
    transition: opacity 0.5s;
    flex: 1;
    flex-direction: column;
}

.game-screen.active {
    display: flex;
    opacity: 1;
}

.game-header, .game-footer {
    background: white;
    padding: 1rem 2rem;
    box-shadow: 0 2px 4px var(--shadow-color);
}

.game-header {
    border-bottom: 1px solid var(--border-color);
}

.game-footer {
    border-top: 1px solid var(--border-color);
}

.player-info {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.player {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    background: var(--bg-color);
    transition: all 0.3s ease;
}

.player.active {
    background: var(--accent-color);
    color: white;
}

.player-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    color: var(--primary-color);
}

.player.active .player-avatar {
    color: var(--accent-color);
    background: white;
}

.player-details {
    display: flex;
    flex-direction: column;
}

.player-name {
    font-weight: 600;
}

.captured-pieces {
    font-size: 0.9rem;
    opacity: 0.8;
}

.game-status {
    text-align: center;
}

.turn-indicator {
    font-size: 1.2rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.game-timer {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    font-size: 1.1rem;
}

.game-main {
    flex: 1;
    display: grid;
    grid-template-columns: 200px 1fr 300px;
    gap: 2rem;
    padding: 2rem;
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
}

.game-controls {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.control-btn {
    background: white;
    border: 2px solid var(--border-color);
    padding: 1rem;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-color);
}

.control-btn:hover {
    background: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
    transform: translateX(5px);
}

.board-container {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
}

.chessboard {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    width: 560px;
    height: 560px;
    border: 0px solid var(--primary-color);
    border-radius: 8px;

    position: relative;
}

.square {
    width: 70px;
    height: 70px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    position: relative;
    transition: all 0.3s ease;
}

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

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

.square.selected {
    background-color: var(--highlight-color) !important;
    box-shadow: inset 0 0 0 3px #ffeb3b;
}

.square.valid-move::before {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    background: var(--valid-move-color);
    border-radius: 50%;
    animation: pulse 1s infinite;
}

.square.capture::before {
    content: '';
    position: absolute;
    width: 60px;
    height: 60px;
    border: 3px solid var(--valid-move-color);
    border-radius: 50%;
    animation: pulse 1s infinite;
}

.square.check {
    animation: checkPulse 1s infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.1); opacity: 0.8; }
}

@keyframes checkPulse {
    0%, 100% { background-color: inherit; }
    50% { background-color: var(--check-color); opacity: 0.7; }
}

.chess-piece {
    font-size: 50px;
    cursor: grab;
    user-select: none;
    transition: all 0.3s ease;
    z-index: 10;
}

.chess-piece.white {
    color: white;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

.chess-piece.black {
    color: #2c3e50;
    text-shadow: 2px 2px 4px rgba(255, 255, 255, 0.5);
}

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

.chess-piece.dragging {
    cursor: grabbing;
    z-index: 100;
    transform: scale(1.2);
}

.game-info {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.move-history, .game-stats {
    background: white;
    border-radius: 8px;
    padding: 1.5rem;
    box-shadow: 0 2px 4px var(--shadow-color);
}

.move-history h3, .game-stats h3 {
    margin-bottom: 1rem;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--primary-color);
}

.history-list {
    max-height: 300px;
    overflow-y: auto;
    font-family: 'Courier New', monospace;
}

.history-item {
    padding: 0.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    gap: 1rem;
}

.history-item:last-child {
    border-bottom: none;
}

.move-number {
    font-weight: 600;
    color: var(--accent-color);
}

.stat-item {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border-color);
}

.stat-item:last-child {
    border-bottom: none;
}

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

.modal.active {
    display: flex;
}

.modal-content {
    background: white;
    border-radius: 12px;
    padding: 2rem;
    max-width: 600px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-50px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.modal-header h3 {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--primary-color);
}

.close-modal {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-color);
    transition: color 0.3s ease;
}

.close-modal:hover {
    color: var(--accent-color);
}

.theme-presets, .custom-colors {
    margin-bottom: 2rem;
}

.theme-presets h4, .custom-colors h4 {
    margin-bottom: 1rem;
    color: var(--text-color);
}

.preset-buttons {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 0.75rem;
}

.preset-btn {
    background: var(--bg-color);
    border: 2px solid var(--border-color);
    padding: 0.75rem 1rem;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    text-align: center;
    white-space: nowrap;
}

.preset-btn:hover {
    background: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
    transform: translateY(-2px);
}

.color-inputs {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
}

.color-input-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.color-input-group label {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-color);
}

.color-input-group input[type="color"] {
    width: 100%;
    height: 40px;
    border: 2px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
}

/* Promotion Dialog */
.promotion-dialog {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 3000;
    align-items: center;
    justify-content: center;
}

.promotion-dialog.active {
    display: flex;
}

.promotion-content {
    background: white;
    border-radius: 12px;
    padding: 2rem;
    text-align: center;
    animation: slideIn 0.3s ease;
}

.promotion-content h3 {
    margin-bottom: 1.5rem;
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--primary-color);
}

.promotion-pieces {
    display: flex;
    gap: 1rem;
    justify-content: center;
}

.promotion-piece {
    background: var(--bg-color);
    border: 2px solid var(--border-color);
    padding: 1.5rem;
    border-radius: 8px;
    font-size: 3rem;
    cursor: pointer;
    transition: all 0.3s ease;
}

.promotion-piece:hover {
    background: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
    transform: scale(1.1);
}

/* Game Over Dialog */
.game-over-dialog {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 3000;
    align-items: center;
    justify-content: center;
}

.game-over-dialog.active {
    display: flex;
}

.game-over-content {
    background: white;
    border-radius: 12px;
    padding: 3rem;
    text-align: center;
    animation: slideIn 0.3s ease;
}

.game-over-content h2 {
    margin-bottom: 1rem;
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary-color);
}

.game-over-content p {
    margin-bottom: 2rem;
    font-size: 1.2rem;
    color: var(--text-color);
}

.game-over-buttons {
    display: flex;
    gap: 1rem;
    justify-content: center;
}

.btn-primary, .btn-secondary {
    padding: 1rem 2rem;
    border-radius: 8px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    border: none;
}

.btn-primary {
    background: var(--accent-color);
    color: white;
}

.btn-primary:hover {
    background: #2980b9;
    transform: translateY(-2px);
}

.btn-secondary {
    background: var(--bg-color);
    color: var(--text-color);
    border: 2px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--border-color);
}

/* Loading Indicator */
.loading-indicator {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    padding: 2rem;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    text-align: center;
    z-index: 4000;
}

.loading-indicator.active {
    display: block;
}

.loading-spinner {
    font-size: 3rem;
    color: var(--accent-color);
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.loading-indicator p {
    font-size: 1.1rem;
    font-weight: 500;
    color: var(--text-color);
}

/* Responsive Design */
@media (max-width: 1200px) {
    .game-main {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .game-controls, .game-info {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
        gap: 1rem;
    }
    
    .chessboard {
        width: 480px;
        height: 480px;
    }
    
    .square {
        width: 60px;
        height: 60px;
    }
    
    .chess-piece {
        font-size: 40px;
    }
}

@media (max-width: 768px) {
    .game-title {
        font-size: 2.5rem;
    }
    
    .mode-btn, .difficulty-btn, .color-btn {
        min-width: 120px;
        padding: 1rem 1.5rem;
    }
    
    .chessboard {
        width: 320px;
        height: 320px;
    }
    
    .square {
        width: 40px;
        height: 40px;
    }
    
    .chess-piece {
        font-size: 28px;
    }
    
    .game-header, .game-footer {
        padding: 0.5rem 1rem;
    }
    
    .player-avatar {
        width: 30px;
        height: 30px;
    }
    
    .player-name {
        font-size: 0.9rem;
    }
}

@media (max-width: 480px) {
    .chessboard {
        width: 280px;
        height: 280px;
    }
    
    .square {
        width: 35px;
        height: 35px;
    }
    
    .chess-piece {
        font-size: 24px;
    }
    
    .modal-content, .promotion-content, .game-over-content {
        padding: 1.5rem;
    }
    
    .mode-buttons, .difficulty-buttons, .color-buttons {
        flex-direction: column;
    }
    
    .mode-btn, .difficulty-btn, .color-btn {
        width: 100%;
    }
    
    .preset-buttons {
        grid-template-columns: repeat(2, 1fr);
    }
}