:root {
    --bg-primary: #121824;
    --bg-secondary: #1a2234;
    --bg-card: #222d42;
    --bg-card-hover: #2a3750;
    --accent-blue: #3b82f6;
    --accent-blue-hover: #2563eb;
    --accent-green: #10b981;
    --accent-red: #ef4444;
    --accent-gold: #f59e0b;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --board-light: #eeeed2;
    --board-dark: #769656;
    --square-selected: rgba(255, 255, 0, 0.5);
    --square-last-move: rgba(155, 199, 0, 0.41);
    --square-check: rgba(239, 68, 68, 0.65);
    --border-radius-sm: 8px;
    --border-radius-md: 12px;
    --border-radius-lg: 16px;
    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.4);
    --font-family: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
}

[data-theme="light"] {
    --bg-primary: #f1f5f9;
    --bg-secondary: #ffffff;
    --bg-card: #f8fafc;
    --bg-card-hover: #e2e8f0;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #64748b;
    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);
    --board-light: #f0d9b5;
    --board-dark: #b58863;
}

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

body {
    font-family: var(--font-family);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    line-height: 1.5;
    user-select: none;
    -webkit-user-select: none;
    transition: background-color 0.3s ease, color 0.3s ease;
}

.theme-toggle-btn {
    position: fixed;
    top: 1.25rem;
    right: 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.55rem 1rem;
    background-color: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 30px;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 600;
    box-shadow: var(--shadow-md);
    transition: all 0.25s ease;
    z-index: 9999;
}
[data-theme="light"] .theme-toggle-btn {
    border-color: rgba(0, 0, 0, 0.12);
}
.theme-toggle-btn:hover {
    transform: translateY(-2px);
    border-color: var(--accent-blue);
}

.app-container {
    width: 100%;
    max-width: 1280px;
    margin: 0 auto;
    padding: 1rem 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    min-height: 100vh;
    justify-content: space-between;
}

/* Header */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1.25rem;
    background-color: var(--bg-secondary);
    border-radius: var(--border-radius-md);
    box-shadow: var(--shadow-sm);
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

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

.logo h1 {
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    background: linear-gradient(135deg, #60a5fa, #3b82f6);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.header-actions {
    display: flex;
    gap: 0.75rem;
}

.icon-btn {
    background-color: var(--bg-card);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.icon-btn:hover {
    background-color: var(--bg-card-hover);
    transform: translateY(-2px);
}

/* Layout */
.game-layout {
    display: grid;
    grid-template-columns: 300px 1fr 280px;
    gap: 1.5rem;
    align-items: start;
    flex: 1;
}

/* Side Panels */
.side-panel {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.panel-card {
    background-color: var(--bg-secondary);
    border-radius: var(--border-radius-md);
    padding: 1.25rem;
    box-shadow: var(--shadow-md);
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.panel-card h2 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-secondary);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    padding-bottom: 0.5rem;
}

/* Form Controls */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    margin-bottom: 1rem;
}

.form-group label {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 500;
}

select {
    background-color: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 0.6rem 0.8rem;
    border-radius: var(--border-radius-sm);
    font-family: inherit;
    font-size: 0.95rem;
    outline: none;
    cursor: pointer;
    transition: border-color 0.2s;
}

select:focus {
    border-color: var(--accent-blue);
}

/* Buttons */
.button-group {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    margin-top: 0.5rem;
}

.btn {
    padding: 0.75rem 1rem;
    border-radius: var(--border-radius-sm);
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.btn-primary {
    background-color: var(--accent-blue);
    color: #ffffff;
    box-shadow: 0 4px 10px rgba(59, 130, 246, 0.3);
}

.btn-primary:hover {
    background-color: var(--accent-blue-hover);
    transform: translateY(-1px);
}

.btn-secondary {
    background-color: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.btn-secondary:hover:not(:disabled) {
    background-color: var(--bg-card-hover);
}

.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none !important;
}

/* Player Cards */
.player-info {
    transition: all 0.25s ease;
    border-left: 4px solid transparent;
}

.player-info.active-turn {
    border-left-color: var(--accent-blue);
    background-color: #1e283d;
}

.player-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.player-avatar {
    width: 38px;
    height: 38px;
    background-color: var(--bg-card);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
}

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

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

.player-turn-badge {
    font-size: 0.75rem;
    color: var(--accent-blue);
    font-weight: 500;
    display: none;
}

.active-turn .player-turn-badge {
    display: inline;
}

.captured-pieces {
    margin-top: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 28px;
}

.pieces-list {
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    font-size: 1.2rem;
    line-height: 1;
}

.score-advantage {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--accent-gold);
    background-color: rgba(245, 158, 11, 0.15);
    padding: 2px 6px;
    border-radius: 4px;

}

/* Chess Board Area */
.board-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.status-banner {
    width: 100%;
    max-width: 560px;
    background-color: var(--bg-secondary);
    padding: 0.75rem 1.25rem;
    border-radius: var(--border-radius-md);
    text-align: center;
    font-weight: 600;
    font-size: 1.05rem;
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: var(--shadow-sm);

}

.status-banner.in-check {
    background-color: rgba(239, 68, 68, 0.2);
    border-color: var(--accent-red);
    color: #fca5a5;
}

.chessboard-wrapper {
    position: relative;
    width: 100%;
    max-width: 560px;
    aspect-ratio: 1 / 1;
    box-shadow: var(--shadow-lg);
    border-radius: var(--border-radius-md);
    overflow: hidden;
    border: 4px solid var(--bg-secondary);
}

.chessboard {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    width: 100%;
    height: 100%;
}

.square {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    font-size: 2.8rem;
    transition: background-color 0.15s ease;
}

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

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

/* Rank & File Coordinate Annotations */
.coord-rank, .coord-file {
    position: absolute;
    font-size: 0.65rem;
    font-weight: 700;
    pointer-events: none;
    opacity: 0.7;
}

.coord-rank {
    top: 3px;
    left: 4px;
}

.square.light .coord-rank, .square.light .coord-file {
    color: var(--board-dark);
}

.square.dark .coord-rank, .square.dark .coord-file {
    color: var(--board-light);
}

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

/* Square Highlights */
.square.selected {
    background-color: var(--square-selected) !important;
}

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

.square.in-check-king {
    background-color: var(--square-check) !important;
    animation: pulse-check 1.5s infinite;
}

@keyframes pulse-check {
    0% { box-shadow: inset 0 0 0 0px var(--accent-red); }
    50% { box-shadow: inset 0 0 12px 4px var(--accent-red); }
    100% { box-shadow: inset 0 0 0 0px var(--accent-red); }
}

/* Legal Move Hints */
.move-hint {
    position: absolute;
    width: 26%;
    height: 26%;
    border-radius: 50%;
    background-color: rgba(0, 0, 0, 0.25);
    pointer-events: none;
    z-index: 10;
}

.capture-hint {
    position: absolute;
    width: 90%;
    height: 90%;
    border-radius: 50%;
    border: 5px solid rgba(239, 68, 68, 0.6);
    pointer-events: none;
    z-index: 10;
}

/* Piece SVG Wrapper */
.piece-svg {
    width: 85%;
    height: 85%;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 5;
    transition: transform 0.1s ease;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.25));
}

.square:hover .piece-svg {
    transform: scale(1.06);
}

/* Move History Card */
.move-history-card {
    height: 100%;
    max-height: 580px;
    display: flex;
    flex-direction: column;
}

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

.card-header h2 {
    margin-bottom: 0;
    border-bottom: none;
    padding-bottom: 0;
}

.move-count {
    font-size: 0.75rem;
    color: var(--text-muted);
    background-color: var(--bg-card);
    padding: 2px 8px;
    border-radius: 10px;
}

.move-history-container {
    flex: 1;
    overflow-y: auto;
    background-color: var(--bg-primary);
    border-radius: var(--border-radius-sm);
    padding: 0.5rem;
    font-size: 0.9rem;
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: 460px;
}

.empty-history {
    color: var(--text-muted);
    font-size: 0.85rem;
    text-align: center;
    margin-top: 2rem;
    font-style: italic;
}

.history-row {
    display: grid;
    grid-template-columns: 40px 1fr 1fr;
    align-items: center;
    padding: 0.4rem 0.6rem;
    border-radius: 4px;
    background-color: rgba(255, 255, 255, 0.02);
}

.history-row:nth-child(even) {
    background-color: rgba(255, 255, 255, 0.05);
}

.move-num {
    color: var(--text-muted);
    font-weight: 600;
}

.move-white, .move-black {
    font-family: monospace;
    font-size: 0.95rem;
    font-weight: 500;
}

/* Modals */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(10, 14, 23, 0.8);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    opacity: 1;
    transition: opacity 0.25s ease;
}

.modal-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-content {
    background-color: var(--bg-secondary);
    border-radius: var(--border-radius-lg);
    padding: 2rem;
    max-width: 420px;
    width: 90%;
    text-align: center;
    box-shadow: var(--shadow-lg);
    border: 1px solid rgba(255, 255, 255, 0.1);
    transform: scale(1);
    transition: transform 0.25s ease;
}

.modal-overlay.hidden .modal-content {
    transform: scale(0.9);
}

.modal-content h3 {
    font-size: 1.3rem;
    margin-bottom: 0.5rem;
}

.modal-content p {
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
    font-size: 0.95rem;
}

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

.promotion-choice {
    width: 65px;
    height: 65px;
    background-color: var(--bg-card);
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--border-radius-md);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.promotion-choice:hover {
    border-color: var(--accent-blue);
    background-color: var(--bg-card-hover);
    transform: translateY(-3px);
}

.game-over-content .trophy-icon {
    font-size: 3.5rem;
    margin-bottom: 0.5rem;
}

.game-over-content h2 {
    font-size: 1.6rem;
    margin-bottom: 0.5rem;
    color: var(--accent-gold);
}

/* Responsive adjustments */
@media (max-width: 1024px) {
    .game-layout {
        grid-template-columns: 1fr;
        justify-items: center;
    }

    .side-panel {
        width: 100%;
        max-width: 560px;
    }

    .chessboard-wrapper {
        max-width: 90vw;
    }

    .status-banner {
        max-width: 90vw;
    }
}
