:root {
    --blue1: #48e3fb;
    --blue2: #00b6ff;
    --blue3: #00a3fe;
    --blue4: #0480ff;
    --blue5: #0057fe;

    --purple1: #643efe;
    --purple2: #5e50ff;
    --purple3: #5765ff;
    --purple4: #5177fe;
    --purple5: #5081ff;
    --purple6: #479afe;
    --purple7: #2929d6;

    /* Apple-style glass effect colors */
    --glass-bg: rgba(20, 22, 42, 0.6);
    --glass-border: rgba(255, 255, 255, 0.12);
    --glass-highlight: rgba(255, 255, 255, 0.05);
    --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);

    /* Text colors with better readability */
    --main-dark: #0f111a;
    --text-main: #ffffff;
    --text-sub: #e1e3eb;
    --text-muted: #9ba1b9;

    --text-highlight: linear-gradient(45deg, var(--purple1), var(--purple3));
    
    /* Theme Mapping */
    --bg-color: var(--main-dark);
    --primary-color: rgba(30, 32, 50, 0.7);
    --secondary-color: var(--purple6);
    --accent-color: var(--purple2);
    --danger-color: #ff4d4d;
    --success-color: #4caf50;

    --text-color: var(--text-main);

    /* Default Board Theme (Wood/Brown - Matching User Image) */
    --light-square-bg: #F0D9B5;
    --dark-square-bg: #B58863;

    --border-color: var(--glass-border);
    --shadow-color: var(--glass-shadow);
}

@keyframes skeleton-pulse {
    0% { background-color: rgba(255, 255, 255, 0.05); }
    50% { background-color: rgba(255, 255, 255, 0.1); }
    100% { background-color: rgba(255, 255, 255, 0.05); }
}

body {
    font-family: 'Poppins', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    margin: 0;
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
    background-image: radial-gradient(circle at top right, #1a1c2e 0%, #0f111a 100%);
}

.container {
    display: grid;
    grid-template-areas:
        "header header"
        "game controls"
        "game controls";
    grid-template-columns: 1fr 380px;
    grid-template-rows: auto 1fr;
    gap: 40px;
    width: 100%;
    max-width: 1300px;
}

header {
    grid-area: header;
    text-align: center;
    margin-bottom: 10px;
}

header h1 {
    margin: 0;
    font-weight: 600;
    font-size: 2.5rem;
    background: var(--text-highlight);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -1px;
}

/* Game Area & Board */
.game-area {
    grid-area: game;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    gap: 20px;
}

.board-container-inner {
    display: flex;
    gap: 20px;
    align-items: flex-start;
}

#evaluation-bar-container {
    width: 24px;
    height: clamp(400px, 80vmin, 700px);
    background-color: rgba(0,0,0,0.3);
    border-radius: 4px;
    display: flex;
    flex-direction: column-reverse;
    overflow: hidden;
    position: relative;
}

#evaluation-bar {
    width: 100%;
    background: #fff; /* White advantage */
    height: 50%;
    transition: height 0.5s ease;
}

/* Make the top part black effectively by having a dark background container */
#evaluation-bar-container {
    background-color: #222; /* Black advantage color */
}

#evaluation-score {
    position: absolute;
    width: 100%;
    text-align: center;
    bottom: 5px; /* Default for white */
    color: #555;
    font-size: 10px;
    font-weight: bold;
    z-index: 2;
}

#board-wrapper {
    position: relative;
    width: clamp(300px, 90vw, 700px);
    height: clamp(300px, 90vw, 700px);
    user-select: none;
}

#board {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    width: 100%;
    height: 100%;
    border-radius: 4px;
    overflow: hidden;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}

.square {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
}

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

.square.selected {
    background-color: rgba(255, 255, 50, 0.5) !important;
}

.square.last-move {
    background-color: rgba(255, 255, 50, 0.3) !important;
}

/* Coords Styling */
.coords {
    position: absolute;
    font-size: 13px; /* Increased slightly for visibility */
    font-weight: 600;
    pointer-events: none;
    line-height: 1;
    z-index: 5; /* Above pieces? No, pieces are 10. Below pieces. */
    /* Actually pieces are typically dragged, but static pieces cover coords in many sites */
    /* In the provided image, coords are visible. If piece covers them, it's fine. */
}

.coords.ranks {
    top: 3px;
    left: 3px;
}

.coords.files {
    bottom: 3px;
    right: 3px;
}

/* Contrast Logic */
.square.light .coords { color: var(--dark-square-bg); }
.square.dark .coords { color: var(--light-square-bg); }


.piece {
    width: 100%;
    height: 100%;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    cursor: grab;
    z-index: 10;
}

.piece.dragging {
    cursor: grabbing;
    opacity: 0.8;
}

/* Setup Stack */
#setup-piece-stack {
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: var(--primary-color);
    padding: 10px;
    border-radius: 8px;
    backdrop-filter: blur(10px);
}

#setup-piece-stack.hidden {
    display: none;
}

.piece-stack-row {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 5px;
}

.setup-piece {
    width: 45px;
    height: 45px;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    cursor: grab;
    transition: transform 0.1s;
}

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


/* Controls Area */
.controls-area {
    grid-area: controls;
    display: flex;
    flex-direction: column;
    gap: 20px;
    min-width: 300px;
}

.control-card {
    background-color: var(--primary-color);
    padding: 20px;
    border-radius: 16px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-color);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

/* Bot Profile */
.bot-profile {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 15px;
}

#bot-avatar-container {
    width: 56px;
    height: 56px;
    border-radius: 12px;
    overflow: hidden;
    background: rgba(0,0,0,0.2);
}

#bot-avatar {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.bot-info {
    flex-grow: 1;
}

.bot-info h3 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
}

#status-indicator {
    font-size: 0.8rem;
    margin-top: 4px;
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    background: rgba(255,255,255,0.1);
}

.status-thinking { color: var(--blue1); }
.status-idle { color: var(--text-muted); }

/* Buttons */
.primary-btn, .secondary-btn, #start-game-btn {
    padding: 10px 20px;
    border-radius: 8px;
    border: none;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.primary-btn {
    background: var(--accent-color);
    color: white;
    box-shadow: 0 4px 12px rgba(94, 80, 255, 0.3);
}

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

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

.secondary-btn:hover {
    background: rgba(255,255,255,0.2);
}

.actions-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.main-actions, .move-navigation {
    display: flex;
    gap: 8px;
}

.actions-card button {
    background: transparent;
    border: none;
    color: var(--text-sub);
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    transition: background 0.2s;
}

.actions-card button:hover:not(:disabled) {
    background: rgba(255,255,255,0.1);
    color: white;
}

.actions-card button:disabled {
    opacity: 0.3;
    cursor: default;
}

/* History Card */
.history-card {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 300px;
}

.history-card h3 {
    margin: 0;
    font-size: 1.1rem;
}

.history-header {
    display: grid;
    grid-template-columns: 30px 1fr 1fr 50px;
    font-weight: 600;
    padding-bottom: 5px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-sub);
    font-size: 0.9rem;
}

#move-history-list {
    flex-grow: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.history-row {
    display: grid;
    grid-template-columns: 30px 1fr 1fr 50px;
    padding: 5px 0;
    font-size: 0.9rem;
    border-bottom: 1px solid rgba(255,255,255,0.05);
}

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

.history-placeholder {
    color: var(--text-muted);
    font-style: italic;
    text-align: center;
    padding: 10px;
}

/* Scrollbar for history */
#move-history-list::-webkit-scrollbar {
    width: 6px;
}

#move-history-list::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.2);
    border-radius: 3px;
}

/* Checkbox Label */
.checkbox-label {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    color: var(--text-sub);
}

/* Inputs */
#fen-input, #share-link-input {
    width: 100%;
    padding: 12px;
    background: rgba(255,255,255,0.05);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-main);
    font-family: monospace;
    margin-top: 5px;
    box-sizing: border-box;
}

#fen-input:focus, #share-link-input:focus {
    outline: none;
    border-color: var(--accent-color);
    background: rgba(255,255,255,0.1);
}

/* Selected Setup Piece */
.selected-setup-piece {
    border: 2px solid var(--accent-color);
    border-radius: 8px;
    background: rgba(255,255,255,0.2);
    transform: scale(1.1);
}

/* Modals */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.8);
    backdrop-filter: blur(4px);
    z-index: 2000;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 1;
    transition: opacity 0.3s;
}

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

.modal-content {
    background: #1e2032;
    padding: 30px;
    border-radius: 16px;
    width: 90%;
    max-width: 450px;
    position: relative;
    border: 1px solid var(--glass-border);
    box-shadow: 0 20px 50px rgba(0,0,0,0.5);
}

.close-btn {
    position: absolute;
    top: 15px;
    right: 15px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
}

/* New Game Modal Specifics */
.game-option-group {
    margin-bottom: 20px;
}

.game-option-group label {
    display: block;
    margin-bottom: 10px;
    color: var(--text-sub);
    font-weight: 500;
}

.opponent-selector, .color-selector {
    display: flex;
    gap: 10px;
}

.opponent-btn, .color-btn {
    flex: 1;
    padding: 12px;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 8px;
    color: var(--text-sub);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    transition: all 0.2s;
}

.opponent-btn.selected, .color-btn.selected {
    background: rgba(94, 80, 255, 0.2);
    border-color: var(--accent-color);
    color: white;
}

.large-btn {
    width: 100%;
    padding: 14px;
    font-size: 1.1rem;
    margin-top: 10px;
}

/* Theme Modal */
.theme-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
    margin-top: 10px;
}

.theme-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    padding: 10px;
    border-radius: 8px;
    background: rgba(255,255,255,0.05);
    border: 1px solid transparent;
    transition: all 0.2s;
}

.theme-option:hover {
    background: rgba(255,255,255,0.1);
}

.theme-option.selected {
    background: rgba(94, 80, 255, 0.2);
    border-color: var(--accent-color);
}

.theme-preview {
    display: grid;
    grid-template-columns: repeat(2, 20px);
    grid-template-rows: repeat(2, 20px);
    border-radius: 4px;
    overflow: hidden;
}

.theme-preview div {
    width: 100%;
    height: 100%;
}


/* Move dots */
.valid-move-dot {
    width: 20px;
    height: 20px;
    background: rgba(0,0,0,0.2);
    border-radius: 50%;
    pointer-events: none;
}

.square.dark .valid-move-dot {
    background: rgba(0,0,0,0.2);
}
.square.light .valid-move-dot {
    background: rgba(0,0,0,0.2);
}

/* Valid move ring for capturing */
.valid-move-ring {
    width: 100%;
    height: 100%;
    border: 4px solid rgba(0,0,0,0.2);
    border-radius: 50%;
    box-sizing: border-box;
    pointer-events: none;
}

/* Responsive */
@media (max-width: 950px) {
    .container {
        grid-template-areas:
            "header"
            "game"
            "controls";
        grid-template-columns: 1fr;
    }

    .game-area {
        flex-direction: column;
        align-items: center;
    }
    
    #evaluation-bar-container {
        width: 100%;
        height: 20px;
        flex-direction: row;
    }

    #evaluation-bar {
        height: 100%;
        width: 50%;
    }

    .controls-area {
        width: 100%;
    }
}
