body {
    /* Map from CP global themes */
    --glass-bg: var(--cp-glass-bg);
    --glass-border: var(--cp-glass-border);
    --glass-highlight: var(--cp-glass-highlight);
    --glass-shadow: var(--cp-shadow);
    --text-primary: var(--cp-text);
    --text-muted: var(--cp-text-muted);
    --accent: var(--cp-accent);

    /* Board specific */
    --white-square: rgba(255, 255, 255, 0.4);
    --black-square: rgba(0, 0, 0, 0.2);
    --highlight-color: rgba(0, 255, 204, 0.5);
    /* Move assist */
    --select-color: rgba(255, 204, 0, 0.6);
    /* Current piece */
    --check-color: rgba(255, 51, 102, 0.6);
    /* King in check */
}

/* Base Body Override for Games */
body {
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    color: var(--text-primary);
    margin: 0;
    padding: 0;
    font-family: 'Outfit', sans-serif;
    position: relative;
    overflow-x: hidden;
}

/* Back Button */
.back-btn {
    position: absolute;
    top: 2rem;
    left: 2rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-primary);
    text-decoration: none;
    font-weight: 600;
    padding: 0.8rem 1.5rem;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 30px;
    backdrop-filter: blur(10px);
    transition: all 0.3s ease;
    z-index: 50;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.back-btn:hover {
    background: var(--glass-highlight);
    transform: translateX(-5px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.2);
}

/* Container Wrapper */
.game-container {
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    border-top: 1px solid var(--glass-highlight);
    border-left: 1px solid var(--glass-highlight);
    border-radius: 30px;
    padding: 2.5rem;
    box-shadow: var(--glass-shadow);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
    width: 95%;
    max-width: 600px;
    z-index: 10;
    position: relative;
}

/* Header & Text Globals */
.glow-text {
    font-size: 3rem;
    font-weight: 800;
    margin: 0;
    color: transparent;
    -webkit-text-stroke: 1px rgba(255, 255, 255, 0.8);
    background: linear-gradient(to right, #fff, rgba(255, 255, 255, 0.5));
    -webkit-background-clip: text;
    background-clip: text;
    text-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
    letter-spacing: 2px;
}

/* Config & Lobby Menu */
.config-menu {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    background: var(--glass-bg);
    padding: 1.5rem;
    border-radius: 20px;
    border: 1px solid var(--glass-border);
}

.config-menu.hidden {
    display: none;
}

.config-menu h2 {
    text-align: center;
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

.preset-buttons {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

.preset-btn {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    color: var(--text-primary);
    padding: 0.8rem;
    border-radius: 12px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s;
}

.preset-btn:hover {
    background: var(--glass-highlight);
}

.preset-btn.active {
    background: var(--glass-highlight);
    border-color: var(--accent);
    box-shadow: 0 0 10px var(--highlight-color);
}

.custom-settings {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-bottom: 1rem;
}

.setting-row {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.setting-row label {
    font-size: 0.95rem;
    font-weight: 600;
}

/* Range Sliders */
input[type=range] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    background: transparent;
}

input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    height: 16px;
    width: 16px;
    border-radius: 50%;
    background: var(--text-primary);
    cursor: pointer;
    margin-top: -6px;
    box-shadow: 0 0 10px var(--highlight-color);
}

input[type=range]::-webkit-slider-runnable-track {
    width: 100%;
    height: 6px;
    cursor: pointer;
    background: var(--glass-bg);
    border-radius: 5px;
    border: 1px solid var(--glass-border);
}

/* Status Indicator */
.status-panel {
    display: flex;
    justify-content: center;
    width: 100%;
}

.status-display {
    padding: 0.75rem 2rem;
    font-size: 1.25rem;
    font-weight: 600;
    border-radius: 30px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.2);
    letter-spacing: 1px;
    transition: all 0.3s ease;
}

/* Dynamic Turn Colors */
.status-display.turn-white {
    color: #ffffff;
    border-color: rgba(255, 255, 255, 0.5);
    text-shadow: 0 0 10px rgba(255, 255, 255, 0.3);
}

.status-display.turn-black {
    color: #ff99cc;
    /* Visual pop for black side */
    border-color: rgba(255, 153, 204, 0.5);
    text-shadow: 0 0 10px rgba(255, 153, 204, 0.3);
}

/* Chessboard Box Framework */
.board-wrapper {
    position: relative;
    padding: 15px;
    background: var(--glass-bg);
    border-radius: 20px;
    border: 1px solid var(--glass-border);
    box-shadow: inset 0 5px 15px rgba(0, 0, 0, 0.3);
}

.chessboard {
    display: grid;
    /* Construct 8x8 exactly mapped squares */
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    width: 400px;
    height: 400px;
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid var(--glass-border);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

/* Grid Cells (Squares) */
.square {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: background 0.15s ease;
    cursor: pointer;
    position: relative;
}

/* A standard checkerboard math pattern via nth-child logic applies to div grids */
/* Row 1, 3, 5, 7 */
.square.light {
    background-color: var(--white-square);
}

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

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

/* Valid Move Highlight - Renders a dot in the center */
.square.highlight::after {
    content: '';
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background-color: var(--highlight-color);
    position: absolute;
    box-shadow: 0 0 10px var(--highlight-color);
    opacity: 0.8;
}

/* Check indicator */
.square.in-check {
    background: radial-gradient(ellipse at center, var(--check-color) 0%, transparent 80%) !important;
    animation: pulseCheck 1.5s infinite;
}

@keyframes pulseCheck {
    0% {
        background-color: var(--check-color);
    }

    50% {
        background-color: rgba(255, 51, 102, 0.2);
    }

    100% {
        background-color: var(--check-color);
    }
}

.chess-piece {
    font-size: 2.5rem;
    line-height: 1;
    user-select: none;
    -webkit-user-drag: none;
    user-drag: none;
    cursor: grab;
    /* Drop shadow to make pieces pop out of the board */
    filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.6));
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 5;
    /* allow pointer events to pass through piece when dragging so we can detect target square */
    touch-action: none;
}

/* Add slight white stroke to black pieces for visibility on dark backgrounds */
.chess-piece.black {
    color: #000;
    -webkit-text-stroke: 1px rgba(255, 255, 255, 0.4);
}

.chess-piece.white {
    color: #fff;
    -webkit-text-stroke: 1px rgba(0, 0, 0, 0.4);
}

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

.chess-piece.dragging {
    position: fixed;
    pointer-events: none;
    /* crucial for drop detection */
    transform: scale(1.3) !important;
    z-index: 100;
    margin: 0 !important;
    transition: none;
    /* remove snap delay while following mouse */
    filter: drop-shadow(0 15px 25px rgba(0, 0, 0, 0.8));
}

.chess-piece.snap-back {
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* Overlays & Buttons */
.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    border-radius: 20px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 1.5rem;
    opacity: 1;
    transition: opacity 0.3s ease;
    z-index: 20;
}

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

.game-over-text {
    font-size: 2.5rem;
    color: #ff3366;
    text-shadow: 0 0 20px rgba(255, 51, 102, 0.6);
    margin: 0;
    text-transform: uppercase;
}

.btn {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-top: 1px solid var(--glass-highlight);
    border-left: 1px solid var(--glass-highlight);
    padding: 1rem 2.5rem;
    border-radius: 40px;
    color: var(--text-primary);
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    text-transform: uppercase;
    letter-spacing: 2px;
    position: relative;
    overflow: hidden;
    backdrop-filter: blur(10px);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, var(--glass-highlight), transparent);
    transition: 0.5s;
}

.btn:hover {
    background: var(--glass-highlight);
    transform: translateY(-3px);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
    border-color: var(--glass-highlight);
}

.secondary-btn {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--glass-border);
    padding: 0.5rem 1.5rem;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: 0.3s;
}

.secondary-btn:hover {
    background: rgba(255, 51, 102, 0.2);
    color: #ff3366;
    border-color: rgba(255, 51, 102, 0.5);
}

/* Responsive CSS */
@media (max-width: 600px) {
    .back-btn {
        top: 1rem;
        left: 1rem;
        padding: 0.5rem 1rem;
        font-size: 0.9rem;
    }

    .chessboard {
        width: 320px;
        height: 320px;
    }

    .chess-piece {
        font-size: 2rem;
    }

    .glow-text {
        font-size: 2.2rem;
    }

    .game-container {
        padding: 1.5rem;
    }
}