:root {
    --gold: #d4af37;
    --gold-bright: #ffdf00;
    --gold-dark: #aa8a2e;
    --obsidian: #1a1a1a;
    --white-marble: #f5f5f5;
    --bg-dark: #0a0a0a;
    --panel-bg: rgba(26, 26, 26, 0.8);
    --text-main: #e0e0e0;
    --text-dim: #a0a0a0;
    --shadow-cinematic: 0 30px 60px rgba(0, 0, 0, 0.8), 0 0 40px rgba(212, 175, 55, 0.1);
    --border-radius: 12px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background-color: var(--bg-dark);
    color: var(--text-main);
    font-family: 'Outfit', sans-serif;
    min-height: 100vh;
    overflow-x: hidden;
    background-image:
        radial-gradient(circle at 20% 30%, rgba(212, 175, 55, 0.05) 0%, transparent 40%),
        radial-gradient(circle at 80% 70%, rgba(212, 175, 55, 0.05) 0%, transparent 40%);
}

.app-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

/* Header Styles */
.main-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(212, 175, 55, 0.2);
    padding-bottom: 1rem;
}

.logo {
    font-family: 'Playfair Display', serif;
    font-size: 2.5rem;
    letter-spacing: 2px;
    color: var(--text-main);
}

.logo span {
    color: var(--gold);
    font-weight: 300;
}

.game-stats {
    display: flex;
    gap: 3rem;
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.stat-item .label {
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--text-dim);
    letter-spacing: 1px;
}

.stat-item .value {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--gold);
}

.value.white-turn {
    color: #fff;
}

.value.black-turn {
    color: var(--gold);
}

/* Main Layout */
.game-wrapper {
    display: grid;
    grid-template-columns: 300px 1fr 300px;
    gap: 2rem;
    align-items: start;
}

.board-actions-mobile {
    display: none;
    /* Hidden by default on PC */
}

/* Sidebar Styling */
.side-panel {
    background: var(--panel-bg);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(212, 175, 55, 0.1);
    border-radius: var(--border-radius);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
    height: 700px;
}

.panel-section h3 {
    font-family: 'Playfair Display', serif;
    font-size: 1.25rem;
    color: var(--gold);
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid rgba(212, 175, 55, 0.1);
}

/* Player Cards */
.player-card {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    transition: all 0.3s ease;
    border: 1px solid transparent;
}

.player-card.active {
    background: rgba(212, 175, 55, 0.1);
    border-color: rgba(212, 175, 55, 0.3);
    box-shadow: 0 0 20px rgba(212, 175, 55, 0.1);
}

.p-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 2px solid var(--gold);
}

.p-avatar.white {
    background: var(--white-marble);
    background-image: url('white_marble.png');
    background-size: cover;
}

.p-avatar.black {
    background: var(--obsidian);
    background-image: url('dark_marble.png');
    background-size: cover;
}

.p-name {
    display: block;
    font-weight: 600;
    font-size: 0.9rem;
}

.p-score {
    display: block;
    font-size: 0.8rem;
    color: var(--text-dim);
}

/* History List */
.history-list {
    flex-grow: 1;
    overflow-y: auto;
    font-size: 0.85rem;
    color: var(--text-dim);
}

.history-item {
    padding: 0.5rem 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

/* Board Styling */
.board-container {
    display: flex;
    justify-content: center;
    align-items: center;
}

.board-frame {
    padding: 15px 25px 15px 10px;
    /* More padding on right and bottom for balance */
    background: linear-gradient(135deg, #2c2c2c, #000);
    border: 4px solid var(--gold);
    border-radius: 4px;
    box-shadow: var(--shadow-cinematic);
    position: relative;
    display: flex;
    align-items: flex-start;
    /* Align numbers to top of squares */
}

.board-frame::before {
    content: '';
    position: absolute;
    top: -10px;
    left: -10px;
    right: -10px;
    bottom: -10px;
    border: 1px solid var(--gold-dark);
    pointer-events: none;
}

.board-inner {
    display: flex;
    flex-direction: column;
}

.coords-x {
    display: flex;
    justify-content: space-around;
    padding-top: 10px;
    color: var(--gold-dark);
    font-size: 0.9rem;
    font-weight: 600;
}

.coords-y {
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    height: 560px;
    /* 8 * 70px */
    padding-right: 15px;
    color: var(--gold-dark);
    font-size: 0.9rem;
    font-weight: 600;
}

.coords-x span,
.coords-y span {
    width: 20px;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
}

.coords-y span {
    height: 70px;
}

.checkers-board {
    display: grid;
    grid-template-columns: repeat(8, 70px);
    grid-template-rows: repeat(8, 70px);
    border: 2px solid #000;
}

.square {
    width: 70px;
    height: 70px;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
}

.square.dark {
    background-color: #111;
    background-image: url('dark_marble.png');
    background-size: cover;
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.8);
}

.square.light {
    background-color: #eee;
    background-image: url('white_marble.png');
    background-size: cover;
    opacity: 1;
    /* Was 0.9, making it solid for luxury */
    box-shadow: inset 0 0 10px rgba(255, 255, 255, 0.5);
}

/* Setup Screen Styles */
.setup-card {
    max-width: 500px !important;
    background: linear-gradient(135deg, #1a1a1a, #0a0a0a);
    box-shadow: 0 0 50px rgba(0, 0, 0, 1), 0 0 30px rgba(212, 175, 55, 0.2);
}

.setup-form {
    margin-top: 2rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.setup-form input {
    padding: 1rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(212, 175, 55, 0.3);
    border-radius: 6px;
    color: #fff;
    font-family: inherit;
    font-size: 1rem;
    outline: none;
    transition: all 0.3s;
}

.setup-form input:focus {
    border-color: var(--gold);
    background: rgba(255, 255, 255, 0.1);
    box-shadow: 0 0 10px rgba(212, 175, 55, 0.2);
}

.mode-selection {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
    margin-top: 1rem;
}

.mode-selection button {
    height: 50px;
    /* Uniform height */
    margin-bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.status-badge {
    text-align: center;
    font-size: 0.75rem;
    color: var(--gold-dark);
    margin-top: 1rem;
    padding: 0.5rem;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 4px;
    letter-spacing: 1px;
}

/* Dice Styles */
.dice-card {
    background: linear-gradient(135deg, #1a1a1a, #000);
    border: 2px solid var(--gold);
    padding: 3rem;
    min-width: 400px;
}

.dice-container {
    display: flex;
    justify-content: center;
    gap: 3rem;
    margin: 2rem 0;
}

.die-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.die-wrap span {
    font-size: 0.9rem;
    color: var(--text-dim);
}

.die {
    width: 80px;
    height: 80px;
    background: var(--white-marble);
    background-image: url('white_marble.png');
    background-size: cover;
    border-radius: 12px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2.5rem;
    color: #000;
    font-weight: 800;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.5), inset 0 0 15px rgba(0, 0, 0, 0.2);
    border: 2px solid var(--gold);
}

#dice-result-text {
    font-size: 1.2rem;
    color: var(--gold);
    font-weight: 600;
    margin-top: 1rem;
}

/* Removed .square-label styles as coordinates are now external */

/* Piece Styling - 3D Redesign */
.piece {
    width: 80%;
    height: 80%;
    aspect-ratio: 1/1;
    border-radius: 50%;
    position: relative;
    cursor: pointer;
    z-index: 5;
    display: flex;
    justify-content: center;
    align-items: center;
}

.piece.moving {
    z-index: 100 !important;
}

/* 3D Body */
.piece.white {
    background: radial-gradient(circle at 30% 30%, #ffffff 0%, #d0d0d0 100%);
    box-shadow:
        0 6px 0 #bbb,
        0 8px 10px rgba(0, 0, 0, 0.3);
}

.piece.black {
    background: radial-gradient(circle at 30% 30%, #555555 0%, #222222 100%);
    box-shadow:
        0 6px 0 #000,
        0 8px 10px rgba(0, 0, 0, 0.5);
}

/* Inner 3D Detail (Ridge/Groove) */
/* Inner 3D Detail (Ridge/Groove) */
.piece::after {
    content: '';
    position: absolute;
    /* Keep absolute so it sits behind content if needed, but flex centers it if position:static. Actually absolute + center is safer for overlays */
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 70%;
    height: 70%;
    border-radius: 50%;
    background: transparent;
    box-sizing: border-box;
}

.piece.white::after {
    border: 3px solid rgba(255, 255, 255, 0.5);
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2);
}

.piece.black::after {
    border: 3px solid rgba(255, 255, 255, 0.1);
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.5);
}

/* King Icon */
.piece.king::before {
    content: '★';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -65%);
    /* Slightly higher due to 3D thickness */
    font-size: 2.2rem;
    line-height: 1;
    z-index: 10;
}

.piece.white.king::before {
    color: #cca300;
    text-shadow: 0 1px 2px rgba(255, 255, 255, 0.9), 0 -1px 2px rgba(0, 0, 0, 0.4);
}

.piece.black.king::before {
    color: #ffd700;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.9);
}

.piece:hover {
    /* No movement, perhaps just a brightness bump */
    filter: brightness(1.1);
}

.square.valid-move::after {
    content: '';
    width: 24px;
    height: 24px;
    background: radial-gradient(circle, var(--gold) 20%, transparent 70%);
    border-radius: 50%;
    box-shadow: 0 0 20px var(--gold);
    opacity: 0.8;
}

.piece.selected {
    outline: 3px solid var(--gold);
    outline-offset: 4px;
    transform: scale(1.1) translateY(-4px);
}

/* Buttons and Controls */
.btn-primary,
.btn-secondary {
    width: 100%;
    padding: 0.75rem;
    border-radius: 6px;
    cursor: pointer;
    font-family: inherit;
    font-weight: 600;
    transition: all 0.2s;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.btn-primary {
    background: var(--gold);
    color: #000;
    border: none;
}

.btn-primary:hover {
    background: var(--gold-bright);
    box-shadow: 0 0 15px rgba(212, 175, 55, 0.4);
}

.btn-secondary {
    background: transparent;
    color: var(--gold);
    border: 1px solid var(--gold);
    margin-bottom: 0.75rem;
}

.btn-secondary:hover {
    background: rgba(212, 175, 55, 0.1);
}

/* Settings UI */
.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 1rem;
    font-size: 0.9rem;
    color: var(--text-dim);
}

/* Toggle Switch */
.switch {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 20px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #333;
    transition: .4s;
    border-radius: 20px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 14px;
    width: 14px;
    left: 3px;
    bottom: 3px;
    background-color: var(--text-dim);
    transition: .4s;
    border-radius: 50%;
}

input:checked+.slider {
    background-color: var(--gold-dark);
}

input:checked+.slider:before {
    transform: translateX(20px);
    background-color: var(--gold);
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    z-index: 100;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(5px);
}

.modal-content {
    background: #1a1a1a;
    padding: 3rem;
    border-radius: var(--border-radius);
    border: 1px solid var(--gold);
    text-align: center;
    max-width: 400px;
}

.modal-content h2 {
    font-family: 'Playfair Display', serif;
    color: var(--gold);
    font-size: 2rem;
    margin-bottom: 1rem;
}

.modal-content p {
    color: var(--text-dim);
    margin-bottom: 2rem;
}

.modal-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.modal-actions button {
    margin-bottom: 0;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
}

::-webkit-scrollbar-thumb {
    background: var(--gold-dark);
    border-radius: 3px;
}

/* Mobile optimization */
@media (max-width: 1200px) {
    .app-container {
        padding: 1rem;
        gap: 1rem;
    }

    .game-wrapper {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .side-panel {
        height: auto;
        order: 2;
    }

    .board-container {
        order: 1;
        width: 100%;
        display: flex;
        flex-direction: column;
        /* Allow buttons above board */
        align-items: center;
        padding: 1rem 0;
        overflow-x: hidden;
        /* Prevent horizontal scroll */
    }

    .board-actions-mobile {
        display: flex;
        /* Show only on mobile */
        gap: 1rem;
        margin-bottom: 1rem;
        width: 100%;
        max-width: 300px;
    }

    .board-actions-mobile button {
        padding: 0.5rem;
        font-size: 0.7rem;
        margin-bottom: 0;
    }

    .side-panel.right .settings-list #restart-btn,
    .side-panel.right .settings-list #undo-btn {
        display: none;
        /* Hide original buttons on mobile as they move to top */
    }

    .board-frame {
        max-width: 98vw;
        /* Scale framing slightly */
        padding: 5px;
        transform: scale(0.95);
        /* Slight scale down to ensure it fits gutters */
    }

    .main-header {
        flex-direction: column;
        gap: 1rem;
        text-align: center;
    }

    .game-stats {
        gap: 1.5rem;
    }
}

@media (max-width: 650px) {
    .checkers-board {
        grid-template-columns: repeat(8, 10.5vw);
        grid-template-rows: repeat(8, 10.5vw);
    }

    .square {
        width: 10.5vw;
        height: 10.5vw;
    }

    .piece {
        width: 8.5vw;
        height: 8.5vw;
    }

    .coords-y {
        height: 84vw;
        /* 8 * 10.5vw */
        padding-right: 8px;
    }

    .coords-x {
        padding-top: 5px;
    }

    .dice-card {
        min-width: 90%;
        padding: 1.5rem;
    }

    .dice-container {
        gap: 1.5rem;
    }

    .die {
        width: 50px;
        height: 50px;
        font-size: 1.5rem;
    }
}