/* ==========================================================================
   1. CHESS.COM DESIGN SYSTEM & VARIABLES
   ========================================================================== */
:root {
    --bg-color: #333130;         /* Your beautiful chosen dark gray background */
    --panel-bg: #262421;         /* Deep earthy brown-gray for containers */
    --light-sq: #eeeed2;         /* Classic cream light squares */
    --dark-sq: #769656;          /* Signature Chess.com forest green */
    --accent: #81b64c;           /* Primary actionable green (buttons) */
    --accent-hover: #95cc5e;     /* Hover highlight state for buttons */
    --text-main: #ffffff;        /* Crisp primary text */
    --text-muted: #99aab5;       /* Secondary text description color */
    --highlight: #baca44;        /* Classic yellow tracking hue for active selections */
}

/* ==========================================================================
   2. CORE CONTAINER LAYOUT (PC & RESPONSIVE GLOBAL)
   ========================================================================== */
body {
    background-color: var(--bg-color);
    color: var(--text-main);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    display: flex;
    justify-content: center;
    margin: 0;
    padding: 40px 16px;
    -webkit-font-smoothing: antialiased;
}

.game-container {
    text-align: center;
    width: 100%;
    max-width: 900px;
}

h1 {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 24px;
    color: var(--text-main);
}

.game-layout {
    align-items: flex-start;
    display: flex;
    gap: 24px;
    justify-content: center;
}

/* ==========================================================================
   2B. ACCOUNT PANEL
   ========================================================================== */
.auth-panel {
    align-items: center;
    background-color: var(--panel-bg);
    border-radius: 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
    margin-bottom: 12px;
    padding: 10px 16px;
}

#auth-status {
    color: var(--text-muted);
    font-size: 14px;
    font-weight: 700;
    min-width: 120px;
    text-align: left;
}

.auth-form {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
}

#auth-username-input,
#auth-password-input {
    background-color: #312e2b;
    border: 1px solid #454241;
    border-radius: 4px;
    box-sizing: border-box;
    color: var(--text-main);
    font-size: 14px;
    padding: 9px 12px;
    width: 140px;
}

#auth-username-input:focus,
#auth-password-input:focus {
    outline: 2px solid var(--accent);
}

#login-button,
#register-button,
#logout-button {
    background-color: var(--accent);
    border: none;
    border-radius: 4px;
    color: var(--text-main);
    cursor: pointer;
    font-size: 14px;
    font-weight: bold;
    padding: 9px 14px;
}

#register-button,
#logout-button {
    background-color: #454241;
}

#login-button:hover {
    background-color: var(--accent-hover);
}

#register-button:hover,
#logout-button:hover {
    background-color: #575452;
}

/* ==========================================================================
   3. GAME CONTROLS PANEL & BUTTONS
   ========================================================================== */
.game-controls {
    align-items: center;
    display: flex;
    gap: 16px;
    justify-content: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    background-color: var(--panel-bg);
    padding: 12px 20px;
    border-radius: 8px;
}

#game-status {
    font-size: 18px;
    font-weight: bold;
    min-width: 160px;
    text-align: left;
}

#game-room {
    color: var(--text-muted);
    font-size: 15px;
    font-weight: 600;
}

.join-room-form {
    display: flex;
    gap: 8px;
}

#player-name-input,
#room-code-input {
    background-color: #312e2b;
    border: 1px solid #454241;
    border-radius: 4px;
    box-sizing: border-box;
    color: var(--text-main);
    font-size: 15px;
    padding: 10px 12px;
    width: 130px;
}

#player-name-input {
    width: 150px;
}

#player-name-input:focus,
#room-code-input:focus {
    outline: 2px solid var(--accent);
}

#new-game-button,
#join-room-button {
    background-color: var(--accent);
    border: none;
    color: var(--text-main);
    cursor: pointer;
    font-size: 15px;
    font-weight: bold;
    padding: 10px 18px;
    border-radius: 4px;
    transition: background-color 0.15s ease, transform 0.05s ease;
}

#new-game-button:hover,
#join-room-button:hover {
    background-color: var(--accent-hover);
}

#new-game-button:active,
#join-room-button:active {
    transform: scale(0.98);
}

/* Secondary Button Fallback */
#new-game-button {
    background-color: #454241;
}
#new-game-button:hover {
    background-color: #575452;
}

.player-info-panel {
    align-items: center;
    color: var(--text-muted);
    display: flex;
    flex-wrap: wrap;
    font-size: 14px;
    font-weight: 600;
    gap: 12px;
    justify-content: center;
    margin: -8px 0 16px;
}

.player-info-panel div {
    background-color: rgba(0, 0, 0, 0.24);
    border: 1px solid #3d3a37;
    border-radius: 999px;
    padding: 6px 12px;
}

/* ==========================================================================
   4. SYSTEM NOTIFICATIONS & PILL MESSAGES
   ========================================================================== */
.room-message {
    color: #ffcc66;
    font-size: 14px;
    font-weight: bold;
    background-color: rgba(0, 0, 0, 0.4);
    border-radius: 20px;
    padding: 8px 16px;
    margin: 0 auto 16px;
    width: fit-content;
    min-height: 0;
    display: none;
}

.room-message.visible {
    display: inline-block;
}

/* ==========================================================================
   5. FLUID SCALABLE CHESSBOARD GRID
   ========================================================================== */
#chessboard {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    width: 90vw;
    max-width: 600px;
    aspect-ratio: 1 / 1;
    border: 6px solid var(--panel-bg);
    border-radius: 4px;
    box-shadow: 0 12px 32px rgba(0,0,0,0.45);
    overflow: hidden;
}

.square {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: clamp(20px, 7vw, 46px);
    cursor: pointer;
    position: relative;
    user-select: none;
    -webkit-user-select: none;
}

/* Board Square Colors */
.light-square {
    background-color: var(--light-sq);
}

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

/* Active Piece tracking */
.selected {
    background-color: var(--highlight) !important;
}

/* The subtle move marker dots */
.legal-dot {
    width: 24%;
    height: 24%;
    background-color: rgba(0, 0, 0, 0.15);
    border-radius: 50%;
    position: absolute;
    pointer-events: none;
}

/* ==========================================================================
   6. MOVE HISTORY PANEL
   ========================================================================== */
.move-history-panel {
    background-color: var(--panel-bg);
    border-radius: 8px;
    box-sizing: border-box;
    min-height: 612px;
    padding: 20px;
    text-align: left;
    width: 260px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.move-history-panel h2 {
    font-size: 16px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin: 0 0 16px;
    font-weight: 700;
}

#move-history {
    margin: 0;
    max-height: 520px;
    overflow-y: auto;
    padding-left: 0;
    list-style: none;
}

#move-history li {
    font-size: 14px;
    border-bottom: 1px solid #2d2b28;
    color: #dad9d7;
}

#move-history li:nth-child(odd) {
    background-color: rgba(255, 255, 255, 0.02);
}

.empty-history {
    color: var(--text-muted) !important;
    font-style: italic;
    border: none !important;
}

/* Custom modern scrollbar for history */
#move-history::-webkit-scrollbar {
    width: 6px;
}
#move-history::-webkit-scrollbar-thumb {
    background-color: #3d3a37;
    border-radius: 3px;
}

/* ==========================================================================
   7. PROMOTION & GAME OVER DIALOG MODALS
   ========================================================================== */
.promotion-modal {
    align-items: center;
    background-color: rgba(0, 0, 0, 0.75);
    bottom: 0;
    display: flex;
    justify-content: center;
    left: 0;
    position: fixed;
    right: 0;
    top: 0;
    z-index: 999;
    backdrop-filter: blur(4px);
}

.promotion-modal.hidden {
    display: none;
}

.promotion-dialog {
    background-color: var(--panel-bg);
    border-radius: 12px;
    box-shadow: 0 24px 48px rgba(0, 0, 0, 0.6);
    box-sizing: border-box;
    max-width: 480px;
    padding: 32px;
    text-align: center;
    width: calc(100% - 32px);
    border: 1px solid #3d3a37;
}

.promotion-dialog h2 {
    font-size: 24px;
    font-weight: 700;
    margin: 0 0 24px;
}

.promotion-choices {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: center;
}

.promotion-choice {
    align-items: center;
    background-color: #312e2b;
    border: 1px solid #454241;
    color: var(--text-main);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    font-weight: bold;
    gap: 8px;
    height: 96px;
    justify-content: center;
    width: 96px;
    border-radius: 8px;
    transition: background-color 0.15s ease;
}

.promotion-choice:hover {
    background-color: #454241;
    border-color: #575452;
}

.promotion-choice-symbol {
    font-size: 44px;
    line-height: 1;
    color: #fff;
}

.promotion-choice-label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
}

/* ==========================================================================
   8. MOBILE RESPONSIVE MEDIA QUERIES
   ========================================================================== */
@media (max-width: 900px) {
    body {
        padding-top: 16px;
    }

    .game-layout {
        align-items: center;
        flex-direction: column;
        gap: 16px;
    }

    .move-history-panel {
        min-height: auto;
        max-height: 200px;
        width: 100%;
        max-width: 600px;
    }

    #move-history {
        max-height: 130px;
    }
}
