:root {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-card: #334155;
    --accent: #6366f1;
    --accent-hover: #4f46e5;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --border: #475569;
    
    --square-light: #e2e8f0;
    --square-dark: #64748b;
    --square-light-hl: #fef08a;
    --square-dark-hl: #ca8a04;
    --square-selected: rgba(99, 102, 241, 0.6);
    --square-target: rgba(34, 197, 94, 0.6);
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow-x: hidden;
}

.app-container {
    width: 100%;
    max-width: 1280px;
    margin: 0 auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 15px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-icon {
    font-size: 2rem;
    color: var(--accent);
}

.logo h1 {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.game-mode-selector {
    display: flex;
    background: var(--bg-secondary);
    padding: 4px;
    border-radius: 8px;
    border: 1px solid var(--border);
}

.mode-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 8px 16px;
    font-size: 0.9rem;
    font-weight: 600;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
}

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

.main-content {
    display: flex;
    gap: 25px;
    justify-content: center;
    align-items: flex-start;
    flex: 1;
}

/* Info Panels */
.info-panel {
    width: 260px;
    background: var(--bg-secondary);
    border-radius: 12px;
    border: 1px solid var(--border);
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.player-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-card);
    padding: 12px;
    border-radius: 8px;
    border: 1px solid transparent;
    transition: all 0.2s ease;
}

.player-card.active-turn {
    border-color: var(--accent);
    box-shadow: 0 0 12px rgba(99, 102, 241, 0.3);
}

.player-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

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

.player-card h3 {
    font-size: 0.95rem;
    font-weight: 600;
}

.captured-score {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.timer {
    font-family: monospace;
    font-size: 1.1rem;
    font-weight: 700;
    background: var(--bg-primary);
    padding: 4px 8px;
    border-radius: 4px;
}

.captured-container {
    background: var(--bg-primary);
    padding: 10px;
    border-radius: 8px;
    min-height: 50px;
}

.captured-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 5px;
}

.captured-pieces {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    font-size: 1.2rem;
}

.game-status-box {
    text-align: center;
    padding: 10px;
    background: var(--bg-card);
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--accent);
}

/* Chessboard Layout */
.board-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
}

.board-wrapper {
    position: relative;
    display: grid;
    grid-template-columns: 24px minmax(320px, 520px);
    grid-template-rows: minmax(320px, 520px) 24px;
    background: var(--bg-secondary);
    padding: 12px;
    border-radius: 12px;
    border: 1px solid var(--border);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
}

.chessboard {
    grid-column: 2;
    grid-row: 1;
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    width: 100%;
    aspect-ratio: 1;
    border: 3px solid var(--bg-primary);
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
    border-radius: 4px;
    overflow: hidden;
}

.square {
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    user-select: none;
    cursor: pointer;
}

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

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

.square.highlight {
    background-color: var(--square-light-hl) !important;
}
.square.dark.highlight {
    background-color: var(--square-dark-hl) !important;
}

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

.square.possible-move::after {
    content: '';
    width: 20%;
    height: 20%;
    background-color: var(--square-target);
    border-radius: 50%;
    position: absolute;
}

.square.possible-capture::after {
    content: '';
    width: 100%;
    height: 100%;
    border: 4px solid var(--square-target);
    position: absolute;
    border-radius: 4px;
}

/* Coordinates labels */
.file-labels, .rank-labels {
    display: flex;
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 600;
}

.file-labels {
    grid-column: 2;
    justify-content: space-around;
    align-items: center;
    padding: 0 12px;
}

.file-labels.top { grid-row: 2; display: none; } /* optional */
.file-labels.bottom { grid-row: 2; }

.rank-labels {
    grid-row: 1;
    flex-direction: column;
    justify-content: space-around;
    align-items: center;
    padding: 12px 0;
    width: 24px;
}

.rank-labels.left { grid-column: 1; }
.rank-labels.right { grid-column: 3; display: none; }

/* Chess Pieces Styling */
.piece {
    width: 85%;
    height: 85%;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    cursor: grab;
    transition: transform 0.1s ease;
    filter: drop-shadow(0 2px 3px rgba(0,0,0,0.3));
}

.piece:active {
    cursor: grabbing;
}

/* Move History Panel */
.right-panel {
    height: 544px;
}

.panel-header h3 {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 10px;
}

.move-history-container {
    flex: 1;
    background: var(--bg-primary);
    border-radius: 8px;
    overflow-y: auto;
    padding: 5px;
}

.history-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.history-table th, .history-table td {
    padding: 6px 10px;
    text-align: left;
}

.history-table th {
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--bg-primary);
}

.history-table tr:nth-child(even) {
    background: rgba(255,255,255,0.02);
}

/* Board Controls */
.board-controls {
    display: flex;
    gap: 10px;
    width: 100%;
}

.btn {
    flex: 1;
    padding: 10px 16px;
    font-size: 0.9rem;
    font-weight: 600;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
}

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

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

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

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

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

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--bg-secondary);
    padding: 30px;
    border-radius: 16px;
    border: 1px solid var(--border);
    text-align: center;
    box-shadow: 0 20px 40px rgba(0,0,0,0.5);
    max-width: 400px;
    width: 90%;
}

.modal-content h3, .modal-content h2 {
    margin-bottom: 15px;
    font-size: 1.3rem;
}

.promotion-choices {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-top: 20px;
}

.promo-piece {
    width: 60px;
    height: 60px;
    background: var(--bg-card);
    border: 2px solid var(--border);
    border-radius: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.promo-piece:hover {
    border-color: var(--accent);
    background: var(--bg-primary);
    transform: translateY(-2px);
}

.promo-piece .piece {
    width: 80%;
    height: 80%;
}

/* Responsive */
@media (max-width: 1024px) {
    .main-content {
        flex-direction: column;
        align-items: center;
    }
    
    .info-panel {
        width: 100%;
        max-width: 520px;
    }
    
    .right-panel {
        height: auto;
        max-height: 200px;
    }
}
