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

:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --secondary: #64748b;
    --danger: #dc2626;
    --success: #16a34a;
    --bg-dark: #0f172a;
    --bg-medium: #1e293b;
    --bg-light: #334155;
    --text-light: #f1f5f9;
    --text-gray: #cbd5e1;
    --board-light: #f0d9b5;
    --board-dark: #b58863;
    --highlight: #baca44;
    --selected: #829769;
    --check: #ff6b6b;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, var(--bg-dark) 0%, #1a2332 100%);
    color: var(--text-light);
    min-height: 100vh;
    overflow-x: hidden;
}

.container {
    max-width: 1800px;
    margin: 0 auto;
    padding: 20px;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 0;
    margin-bottom: 30px;
    border-bottom: 2px solid var(--bg-light);
}

header h1 {
    font-size: 2.5rem;
    background: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header-info {
    display: flex;
    gap: 15px;
    align-items: center;
}

.player-info {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 5px;
}

.rating {
    font-weight: bold;
    color: #fbbf24;
    font-size: 1.1rem;
}

/* Auth Screen */
.auth-screen {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 60vh;
}

.auth-box {
    background: var(--bg-medium);
    padding: 50px;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    text-align: center;
    max-width: 400px;
    width: 100%;
}

.auth-box h2 {
    margin-bottom: 15px;
    font-size: 2rem;
}

.auth-box p {
    color: var(--text-gray);
    margin-bottom: 30px;
}

.auth-box input {
    width: 100%;
    padding: 15px;
    border: 2px solid var(--bg-light);
    background: var(--bg-dark);
    color: var(--text-light);
    border-radius: 10px;
    font-size: 1rem;
    margin-bottom: 20px;
    transition: border-color 0.3s;
}

.auth-box input:focus {
    outline: none;
    border-color: var(--primary);
}

/* Buttons */
.btn-primary, .btn-secondary, .btn-danger {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    width: 100%;
}

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

.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(37, 99, 235, 0.4);
}

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

.btn-secondary:hover {
    background: #475569;
    transform: translateY(-2px);
}

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

.btn-danger:hover {
    background: #b91c1c;
    transform: translateY(-2px);
}

/* Game Layout */
.game-layout {
    display: grid;
    grid-template-columns: 300px 1fr 300px;
    gap: 30px;
    align-items: start;
}

.sidebar, .sidebar-right {
    background: var(--bg-medium);
    padding: 25px;
    border-radius: 15px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.menu-section, .game-info, .move-history, .leaderboard, .online-players {
    margin-bottom: 30px;
}

.menu-section h3, .game-info h3, .move-history h3, .leaderboard h3, .online-players h3 {
    margin-bottom: 15px;
    color: var(--text-gray);
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.menu-section button {
    margin-bottom: 10px;
}

.info-row {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid var(--bg-light);
}

.turn-indicator {
    margin-top: 15px;
    padding: 12px;
    background: var(--bg-light);
    border-radius: 8px;
    text-align: center;
    font-weight: 600;
}

.move-list {
    max-height: 300px;
    overflow-y: auto;
    background: var(--bg-dark);
    padding: 15px;
    border-radius: 8px;
    font-family: 'Courier New', monospace;
}

.move-item {
    padding: 5px 0;
    display: grid;
    grid-template-columns: 30px 1fr 1fr;
    gap: 10px;
}

.move-number {
    color: var(--text-gray);
}

.game-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* Chess Board */
.chess-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.board-container {
    position: relative;
}

.chess-board {
    display: grid;
    grid-template-columns: repeat(8, 80px);
    grid-template-rows: repeat(8, 80px);
    border: 3px solid var(--bg-light);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    border-radius: 8px;
    overflow: hidden;
}

.square {
    width: 80px;
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3.5rem;
    cursor: pointer;
    transition: background-color 0.2s;
    position: relative;
    user-select: none;
}

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

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

.square.selected {
    background-color: var(--selected) !important;
}

.square.valid-move {
    position: relative;
}

.square.valid-move::after {
    content: '';
    position: absolute;
    width: 25px;
    height: 25px;
    background-color: rgba(0, 0, 0, 0.2);
    border-radius: 50%;
}

.square.valid-move.has-piece::after {
    width: 100%;
    height: 100%;
    border-radius: 0;
    background-color: transparent;
    border: 4px solid rgba(186, 202, 68, 0.6);
}

.square.last-move {
    background-color: var(--highlight) !important;
}

.square.in-check {
    background: radial-gradient(circle, var(--check) 0%, transparent 70%) !important;
}

.square:hover {
    filter: brightness(0.9);
}

.square .coord-label {
    position: absolute;
    font-size: 0.7rem;
    font-weight: bold;
    color: rgba(0, 0, 0, 0.3);
}

.square .file-label {
    bottom: 2px;
    right: 4px;
}

.square .rank-label {
    top: 2px;
    left: 4px;
}

/* Captured Pieces */
.captured-pieces {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    min-height: 40px;
    padding: 10px;
    background: var(--bg-medium);
    border-radius: 8px;
    width: 640px;
    justify-content: center;
}

.captured-piece {
    font-size: 1.5rem;
    opacity: 0.7;
}

/* Promotion Modal */
.promotion-modal {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--bg-medium);
    padding: 30px;
    border-radius: 15px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.8);
    z-index: 1000;
}

.promotion-pieces {
    display: flex;
    gap: 15px;
    margin-top: 20px;
}

.promotion-piece {
    font-size: 4rem;
    cursor: pointer;
    padding: 10px;
    border-radius: 8px;
    transition: background-color 0.3s;
}

.promotion-piece:hover {
    background-color: var(--bg-light);
}

/* Leaderboard */
.leaderboard-list, .online-list {
    background: var(--bg-dark);
    border-radius: 8px;
    padding: 15px;
}

.leaderboard-item, .online-item {
    display: flex;
    justify-content: space-between;
    padding: 10px;
    margin-bottom: 8px;
    background: var(--bg-medium);
    border-radius: 6px;
    align-items: center;
}

.leaderboard-item .rank {
    font-weight: bold;
    color: var(--text-gray);
    min-width: 30px;
}

.leaderboard-item .player-name {
    flex: 1;
    margin: 0 10px;
}

.leaderboard-item.top-1 {
    border: 2px solid #fbbf24;
}

.leaderboard-item.top-2 {
    border: 2px solid #94a3b8;
}

.leaderboard-item.top-3 {
    border: 2px solid #cd7f32;
}

.online-item {
    justify-content: flex-start;
    gap: 10px;
}

.online-status {
    width: 8px;
    height: 8px;
    background: var(--success);
    border-radius: 50%;
}

/* Game Message */
.game-message {
    padding: 15px 30px;
    background: var(--bg-medium);
    border-radius: 8px;
    font-size: 1.2rem;
    text-align: center;
    min-width: 640px;
}

.game-message.warning {
    background: #fbbf24;
    color: var(--bg-dark);
    font-weight: 600;
}

.game-message.error {
    background: var(--danger);
}

.game-message.success {
    background: var(--success);
}

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

.modal-content {
    background: var(--bg-medium);
    padding: 50px;
    border-radius: 20px;
    text-align: center;
    max-width: 500px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.modal-content h2 {
    font-size: 2.5rem;
    margin-bottom: 20px;
}

.modal-content p {
    font-size: 1.2rem;
    margin-bottom: 20px;
    color: var(--text-gray);
}

.rating-change {
    font-size: 1.5rem;
    font-weight: bold;
    margin: 20px 0;
}

.rating-change.positive {
    color: var(--success);
}

.rating-change.negative {
    color: var(--danger);
}

/* Utility Classes */
.hidden {
    display: none !important;
}

.error {
    color: var(--danger);
    padding: 10px;
    margin-top: 10px;
}

.loading {
    text-align: center;
    color: var(--text-gray);
    padding: 20px;
}

/* Responsive Design */
@media (max-width: 1400px) {
    .game-layout {
        grid-template-columns: 250px 1fr 250px;
    }

    .chess-board {
        grid-template-columns: repeat(8, 70px);
        grid-template-rows: repeat(8, 70px);
    }

    .square {
        width: 70px;
        height: 70px;
        font-size: 3rem;
    }

    .captured-pieces {
        width: 560px;
    }

    .game-message {
        min-width: 560px;
    }
}

@media (max-width: 1200px) {
    .game-layout {
        grid-template-columns: 1fr;
    }

    .sidebar-right {
        grid-row: 1;
    }

    .chess-area {
        grid-row: 2;
    }

    .sidebar {
        grid-row: 3;
    }
}

@media (max-width: 768px) {
    .chess-board {
        grid-template-columns: repeat(8, 50px);
        grid-template-rows: repeat(8, 50px);
    }

    .square {
        width: 50px;
        height: 50px;
        font-size: 2rem;
    }

    .captured-pieces {
        width: 400px;
    }

    .game-message {
        min-width: 400px;
    }

    header h1 {
        font-size: 1.8rem;
    }
}
