/* ===============================================
   CHESS BOARD LAYOUT SYSTEM
   Two modes: with-players (game) and no-players (lessons)
   =============================================== */

/* CSS Custom Properties for board sizing */
:root {
    --player-card-height: 56px;
    --player-card-gap: 0.25rem;
    --side-panel-width: 380px;
    --board-gap: 2rem;
    --content-padding: 1.5rem;
}

/* Override main-content and dashboard-grid for play page */
body:has(.game-container) .main-content {
    padding-top: 0;
    padding-bottom: 0;
    overflow: hidden;
}

body:has(.game-container) .dashboard-grid {
    max-width: none;
    padding: 0;
    height: 100vh;
}

body:has(.game-container) .dashboard-section.section-main {
    height: 100vh;
}

/* Main game container - centers content horizontally with extra side padding */
.game-container {
    display: flex;
    gap: var(--board-gap);
    height: 100vh;
    padding: var(--content-padding);
    padding-left: calc(var(--content-padding) + 3rem);
    padding-right: calc(var(--content-padding) + 3rem);
    align-items: center;
    justify-content: center;
    overflow: hidden;
    box-sizing: border-box;
}

/* Board wrapper - contains board + optional player cards */
.board-wrapper {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    flex: 0 0 auto;
    position: relative;
}

/* Player card positioning - left-aligned, auto width */
.player-card-top {
    margin-bottom: var(--player-card-gap);
    width: auto;
    align-self: flex-start;
    flex-shrink: 0;
}

.player-card-bottom {
    margin-top: var(--player-card-gap);
    width: auto;
    align-self: flex-start;
    flex-shrink: 0;
}

/* Container for board and overlays */
.board-container {
    position: relative;
}

/* ===============================================
   BOARD WITH PLAYERS (play.html, game mode)
   Board + 2 player cards should fit without scrolling
   =============================================== */
.board-with-players #chessboard {
    /* Calculate max height: viewport - padding - 2 player cards - gaps */
    --available-height: calc(100vh - var(--content-padding) * 2 - var(--player-card-height) * 2 - var(--player-card-gap) * 2 - 0.5rem);
    /* Calculate max width: viewport - sidebar - side panel - gaps - padding (including extra horizontal padding) */
    --available-width: calc(100vw - var(--sidebar-width) - 0.5rem - var(--side-panel-width) - var(--board-gap) - var(--content-padding) * 2 - 6rem);
    
    width: min(var(--available-height), var(--available-width)) !important;
    height: min(var(--available-height), var(--available-width)) !important;
    aspect-ratio: 1 / 1;
    position: relative;
    z-index: 1;
    border-radius: 5px;
    overflow: hidden;
    flex-shrink: 0;
}

/* ===============================================
   BOARD WITHOUT PLAYERS (lessons, puzzles)
   Board should take maximum vertical space
   =============================================== */
.board-no-players #chessboard {
    /* Calculate max height: full viewport minus minimal padding */
    --available-height: calc(100vh - var(--content-padding) * 2);
    /* Calculate max width: remaining space for board (sidebar padding already applied to main-content) */
    --available-width: calc((100vw - var(--sidebar-width) - 0.5rem - var(--content-padding) * 2 - var(--board-gap)) * 0.55);
    
    width: min(var(--available-height), var(--available-width)) !important;
    height: min(var(--available-height), var(--available-width)) !important;
    aspect-ratio: 1 / 1;
    position: relative;
    z-index: 1;
    border-radius: 5px;
    overflow: hidden;
    flex-shrink: 0;
}

/* Default fallback for #chessboard (backwards compatibility) */
#chessboard {
    aspect-ratio: 1 / 1;
    position: relative;
    z-index: 1;
    border-radius: 5px;
    overflow: hidden;
}

/* Side panel for game info/settings */
.game-info-panel {
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    padding: 1.5rem;
    background: var(--bg-card-header);
    border-radius: 0.5rem;
    width: 480px; /* Increased from 380px */
    flex-shrink: 0;
    /* Match the height of board + player cards */
    height: calc(100vh - var(--content-padding) * 2);
    max-height: calc(100vh - var(--content-padding) * 2);
}

.panel-content {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    height: 100%;
}

.panel-content.hidden {
    display: none;
}

.panel-title {
    color: var(--color-text-primary);
    font-size: 1.5rem;
    font-weight: 700;
    text-align: center;
    margin-bottom: 0.5rem;
}

/* --- Setup Panel Styles --- */

.time-controls-section h3, .game-mode-section h3 {
    color: var(--color-text-secondary);
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.75rem;
}

.time-buttons-row {
    display: flex;
    gap: 0.5rem;
}

.btn-time-control {
    flex: 1;
    background: var(--bg-secondary);
    border: 2px solid transparent;
    border-radius: 0.5rem;
    padding: 1rem 0.5rem;
    color: var(--color-text-primary);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-time-control:hover {
    background: var(--bg-hover);
}

.btn-time-control.selected {
    background: var(--bg-hover);
    border-color: var(--color-accent);
    color: var(--color-accent);
}

.game-mode-section {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.btn-game-mode {
    background: var(--bg-secondary);
    border: none;
    border-radius: 0.5rem;
    padding: 1.5rem; /* Increased from 1rem */
    color: var(--color-text-primary);
    font-weight: 600;
    text-align: left;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 1rem; /* Increased from 0.75rem */
    transition: background 0.2s;
    font-size: 1.1rem; /* Slightly larger text */
}

.btn-game-mode.selected {
    background: var(--bg-hover);
    outline: 1px solid var(--color-accent);
}

.btn-game-mode:hover:not(.disabled) {
    background: var(--bg-hover);
}

.btn-game-mode.disabled {
    opacity: 0.6;
    cursor: not-allowed;
}
.elo-display-box input {
    background: var(--bg-input);
    border: 1px solid var(--bg-card-border);
    color: var(--color-text-primary);
    border-radius: 0.25rem;
    padding: 0.25rem;
    width: 60px;
    text-align: center;
    font-weight: 600;
}

.friend-lobby-section {
    margin-top: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.friend-lobby-section.hidden {
    display: none;
}

.friend-lobby {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-secondary);
    padding: 1.5rem;
    border-radius: 0.5rem;
}

.lobby-player {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    width: 100px;
}

.lobby-avatar {
    width: 60px;
    height: 60px;
    background: var(--bg-card-header);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: var(--color-text-secondary);
    position: relative;
}

.lobby-avatar.waiting {
    animation: pulse 2s infinite;
}

.lobby-name {
    font-weight: 600;
    font-size: 0.9rem;
    text-align: center;
    white-space: normal;
    word-wrap: break-word;
    max-width: 100%;
}

.lobby-status {
    font-size: 0.8rem;
    color: var(--color-text-secondary);
}

.lobby-status.ready {
    color: var(--color-accent);
}

.lobby-vs {
    font-weight: 800;
    color: var(--color-text-secondary);
    font-size: 1.2rem;
}

@keyframes pulse {
    0% { opacity: 0.6; }
    50% { opacity: 1; }
    100% { opacity: 0.6; }text-primary);
    font-size: 0.85rem;
}

.btn-copy {
    background: var(--bg-secondary);
    border: none;
    border-radius: 0.25rem;
    width: 36px;
    color: var(--color-text-primary);
    cursor: pointer;
}

.start-game-section {
    margin-top: auto; /* Push to bottom */
}

.btn-secondary {
    background: var(--bg-secondary);
    color: var(--color-text-secondary);
    border: none;
    border-radius: 0.5rem;
    padding: 0.875rem;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    width: 100%;
    transition: background 0.2s, color 0.2s;
}

.btn-secondary:hover {
    background: var(--bg-hover);
    color: var(--color-text-primary);
}

.btn-start-game {
    width: 100%;
    background: var(--color-accent);
    color: white;
    border: none;
    border-radius: 0.5rem;
    padding: 1.25rem;
    font-size: 1.25rem;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 4px 0 hsl(258, 60%, 45%); /* 3D effect matching accent */
    transition: transform 0.1s, box-shadow 0.1s;
}

.btn-start-game:active {
    transform: translateY(4px);
    box-shadow: none;
}

.btn-start-game:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    box-shadow: 0 4px 0 hsl(258, 60%, 45%);
}

/* --- Active Game Panel Styles --- */

.chat-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-card-header);
    border-radius: 0.5rem;
    overflow: hidden;
    min-height: 200px;
}

.chat-section h3 {
    padding: 0.75rem;
    background: var(--bg-card);
    margin: 0;
    font-size: 0.9rem;
    color: var(--color-text-secondary);
    border-bottom: 1px solid var(--bg-card-border);
}

.chat-messages {
    flex: 1;
    padding: 0.75rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    /* Hide scrollbar for Chrome, Safari and Opera */
    -ms-overflow-style: none;  /* IE and Edge */
    scrollbar-width: none;  /* Firefox */
}

/* Hide scrollbar for Chrome, Safari and Opera */
.chat-messages::-webkit-scrollbar {
    display: none;
}

.chat-message {
    font-size: 0.9rem;
    color: var(--color-text-primary);
    word-break: break-word;
}

.chat-message.system {
    color: var(--color-text-secondary);
    font-style: italic;
    font-size: 0.85rem;
    text-align: center;
}

.chat-message.self {
    align-self: flex-end;
    text-align: right;
}

.chat-message-sender {
    display: block;
    font-size: 0.75rem;
    color: var(--color-text-secondary);
}

.chat-message-text {
    display: block;
    margin-top: 0.1rem;
}

.chat-input-area {
    padding: 0.5rem;
    display: flex;
    gap: 0.5rem;
    border-top: 1px solid var(--bg-card-border);
}

.chat-input-area input {
    flex: 1;
    background: var(--bg-input);
    border: none;
    border-radius: 0.25rem;
    padding: 0.5rem;
    color: var(--color-text-primary);
}

.btn-chat-send {
    background: transparent;
    border: none;
    color: var(--color-accent);
    cursor: pointer;
    padding: 0 0.5rem;
}

.game-status-display {
    padding: 0.75rem;
    background: var(--bg-card);
    border-radius: 0.5rem;
    color: var(--color-text-primary);
    font-weight: 600;
    text-align: center;
    flex-shrink: 0;
}

.action-card {
    padding: 1rem;
    background: var(--bg-card);
    border-radius: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    flex-shrink: 0; /* Prevent squishing */
}

.action-card h3 {
    color: var(--color-text-primary);
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.pgn-display {
    min-height: 80px;
    max-height: 150px;
    overflow-y: auto !important; /* Allow scroll here */
    font-family: monospace;
    font-size: 0.9rem;
    color: var(--color-text-secondary);
    background: var(--bg-card-header);
    padding: 0.75rem;
    border-radius: 0.375rem;
}

.pgn-display p {
    line-height: 1.5;
    margin-bottom: 0.5rem;
}

.pgn-display p:last-child {
    margin-bottom: 0;
}

.piece-wP, .piece-wR, .piece-wN, .piece-wB, .piece-wQ, .piece-wK,
.piece-bP, .piece-bR, .piece-bN, .piece-bB, .piece-bQ, .piece-bK {
    background-size: 100% 100%;
    background-repeat: no-repeat;
}

.piece-wP { background-image: url('https://assets-themes.chess.com/image/ejgfv/150/wp.png'); }
.piece-wR { background-image: url('https://assets-themes.chess.com/image/ejgfv/150/wr.png'); }
.piece-wN { background-image: url('https://assets-themes.chess.com/image/ejgfv/150/wn.png'); }
.piece-wB { background-image: url('https://assets-themes.chess.com/image/ejgfv/150/wb.png'); }
.piece-wQ { background-image: url('https://assets-themes.chess.com/image/ejgfv/150/wq.png'); }
.piece-wK { background-image: url('https://assets-themes.chess.com/image/ejgfv/150/wk.png'); }

.piece-bP { background-image: url('https://assets-themes.chess.com/image/ejgfv/150/bp.png'); }
.piece-bR { background-image: url('https://assets-themes.chess.com/image/ejgfv/150/br.png'); }
.piece-bN { background-image: url('https://assets-themes.chess.com/image/ejgfv/150/bn.png'); }
.piece-bB { background-image: url('https://assets-themes.chess.com/image/ejgfv/150/bb.png'); }
.piece-bQ { background-image: url('https://assets-themes.chess.com/image/ejgfv/150/bq.png'); }
.piece-bK { background-image: url('https://assets-themes.chess.com/image/ejgfv/150/bk.png'); }

/* =============== Board Theme Switcher =============== */
.board-theme-switcher {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 50;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.theme-switcher-button {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: var(--bg-card);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 10px 0 rgba(0,0,0,.06);
    cursor: pointer;
    position: relative;
    transition: background 0.2s, box-shadow 0.2s;
    outline: none;
}
.theme-switcher-button:focus, .theme-switcher-button:hover {
    background: var(--bg-secondary);
    box-shadow: 0 4px 18px 2px rgba(60,60,100,.08);
}

.theme-switcher-icon {
    display: inline-block;
    width: 26px;
    height: 26px;
    background: none;
    /* uses inner grid squares colored by JS or CSS */
}
.theme-icon {
    /* Used in the dropdown */
    display: grid;
    grid-template: repeat(2, 1fr) / repeat(2, 1fr);
    gap: 2px;
    width: 32px;
    height: 32px;
    border-radius: 0.3em;
    box-shadow: 0 0 2px 0 rgba(0,0,0,.1);
    overflow: hidden;
    margin: 0 auto;
    background: none;
}
.theme-icon span {
    display: block;
    width: 100%;
    height: 100%;
}
.theme-icon-wood span:nth-child(1), .theme-icon-wood span:nth-child(4) {
    background: #f0d9b5;
}
.theme-icon-wood span:nth-child(2), .theme-icon-wood span:nth-child(3) {
    background: #b58863;
}
.theme-icon-green span:nth-child(1), .theme-icon-green span:nth-child(4) {
    background: #ebecd0;
}
.theme-icon-green span:nth-child(2), .theme-icon-green span:nth-child(3) {
    background: #739552;
}
.theme-icon-black span:nth-child(1), .theme-icon-black span:nth-child(4) {
    background: #f0f0f0;
}
.theme-icon-black span:nth-child(2), .theme-icon-black span:nth-child(3) {
    background: #4b4b4b;
}
/* Theme menu layout/animation */
.theme-switcher-menu {
    position: absolute;
    right: 52px;
    top: 0px;
    display: flex;
    flex-direction: row-reverse;
    gap: 0.5rem;
    background: none;
    padding: 0;
    opacity: 0;
    pointer-events: none;
    transform: translateX(12px) scale(0.94);
    transition: opacity 0.23s, transform 0.23s;
}
.board-theme-switcher.menu-open .theme-switcher-menu {
    opacity: 1;
    pointer-events: auto;
    transform: translateX(0) scale(1);
    z-index: 51;
}
.theme-option {
    border: none;
    padding: 4px;
    background: transparent;
    border-radius: 0.3em;
    outline: 1.5px solid transparent;
    cursor: pointer;
    transition: background 0.13s, outline 0.13s;
}
.theme-option.selected {
    outline: 1.5px solid #7a5fff;
    background: rgba(122,95,255,0.08);
}
.theme-option:hover {
    background: rgba(127,127,200,0.07);
}
@media (max-width: 900px) {
    .board-theme-switcher {
        right: 8px;
        top: 4px;
    }
    .theme-switcher-menu {
        right: 42px;
    }
    .theme-switcher-button {
        width: 38px;
        height: 38px;
    }
    .theme-icon {
        width: 26px;
        height: 26px;
    }
}

/* ===============================================
   RESPONSIVE BREAKPOINTS
   =============================================== */

@media (max-width: 1400px) {
    :root {
        --side-panel-width: 320px;
    }
    
    .game-info-panel {
        width: 320px;
    }
}

@media (max-width: 1200px) {
    :root {
        --side-panel-width: 280px;
        --board-gap: 1rem;
    }
    
    .game-container {
        gap: 1rem;
    }
    
    .game-info-panel {
        width: 280px;
    }
}

@media (max-width: 1024px) {
    :root {
        --side-panel-width: 100%;
        --content-padding: 0.5rem;
    }
    
    .game-container {
        flex-direction: column;
        padding: 0.5rem;
        height: auto;
        max-height: none;
        min-height: calc(100vh - 4.75rem);
        overflow: visible;
    }

    .board-wrapper {
        width: 100%;
        height: auto;
    }

    .game-info-panel {
        width: 100%;
        max-width: 100%;
        max-height: fit-content;
        height: auto;
        padding: 1rem;
        margin-bottom: 1rem;
    }
    
    .panel-content {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: space-between;
        align-items: center;
        gap: 1rem;
    }
    
    .start-game-section {
        margin-top: 0;
        width: 100%;
        max-width: 300px;
    }
    
    .chat-section {
        min-height: 150px;
        width: 100%;
    }

    /* Mobile: board takes full width */
    .board-with-players #chessboard,
    .board-no-players #chessboard,
    #chessboard {
        width: min(calc(100vw - 1rem), 600px) !important;
        height: min(calc(100vw - 1rem), 600px) !important;
    }
}

@media (max-width: 768px) {
    .game-container {
        gap: 0.5rem;
        padding: 0.25rem;
    }

    .board-with-players #chessboard,
    .board-no-players #chessboard,
    #chessboard {
        width: min(calc(100vw - 0.5rem), 450px) !important;
        height: min(calc(100vw - 0.5rem), 450px) !important;
    }

    .player-name {
        font-size: 0.9rem;
    }

    .player-elo {
        font-size: 0.8rem;
    }

    .timer-display {
        font-size: 1rem;
    }

    .game-status-display {
        padding: 0.5rem;
        font-size: 0.9rem;
    }

    .action-card {
        padding: 0.75rem;
        gap: 0.75rem;
    }

    .action-card h3 {
        font-size: 0.95rem;
    }

    .pgn-display {
        min-height: 80px;
        max-height: 150px;
        font-size: 0.85rem;
        padding: 0.5rem;
    }
    
    .panel-title {
        width: 100%;
        text-align: center;
    }
    
    .panel-content {
        flex-direction: column;
        align-items: stretch;
    }
    
    .start-game-section {
        max-width: none;
    }
}

@media (max-width: 480px) {
    .game-container {
        padding: 0.25rem;
    }

    .board-with-players #chessboard,
    .board-no-players #chessboard,
    #chessboard {
        width: min(calc(100vw - 0.5rem), 350px) !important;
        height: min(calc(100vw - 0.5rem), 350px) !important;
    }
    
    .player-avatar {
        width: 30px;
        height: 30px;
    }

    .player-name {
        font-size: 0.8rem;
    }

    .player-elo {
        font-size: 0.75rem;
    }

    .player-timer {
        min-width: 60px;
        padding: 0.3rem 0.6rem;
    }

    .timer-display {
        font-size: 0.9rem;
    }

    .btn {
        padding: 0.6rem;
        font-size: 0.75rem;
    }
}

/* Promotion UI Modal Styles */
.promotion-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.5);
    z-index: 10000;
    visibility: hidden;
    opacity: 0;
    transition: visibility 0s, opacity 0.3s ease;
    display: flex;
    justify-content: center;
    align-items: center;
}

.promotion-modal-overlay.active {
    visibility: visible;
    opacity: 1;
}

.promotion-modal-content {
    position: absolute; /* Allow for precise positioning */
    /* top and left will be set by JavaScript */
    background: var(--bg-card);
    border-radius: 0.5rem;
    padding: 0.7rem; /* Increased padding */
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    display: flex; /* Ensure options lay out correctly */
    flex-direction: column; /* Stack options vertically */
    gap: 0.25rem; /* Reduced gap */
}

/* New styles for the game link modal */
.game-link-modal-content {
    padding: 2rem;
    gap: 1.25rem;
    min-width: 350px;
    max-width: 500px;
    border-radius: 12px;
    background: var(--bg-card);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.game-link-modal-header {
    text-align: center;
}

.game-link-modal-header .fa-user-group {
    font-size: 2.5rem;
    color: var(--color-accent);
    margin-bottom: 0.5rem;
}

.game-link-modal-header h3 {
    color: var(--color-text-primary);
    margin: 0;
    font-size: 1.5rem;
    font-weight: 600;
}

.game-link-modal-p {
    color: var(--color-text-secondary);
    text-align: center;
    font-size: 0.95rem;
    margin: 0;
}

.game-link-modal-content .link-box {
    width: 100%;
    background: var(--bg-secondary);
    border: 1px solid var(--bg-card-border);
    border-radius: 8px;
    padding: 0.75rem;
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.game-link-modal-content .link-box input {
    flex: 1;
    background: transparent;
    border: none;
    color: white;
    font-size: 0.9rem;
    outline: none;
}

.game-link-modal-content .btn-copy {
    background: var(--color-accent);
    color: white;
    border: none;
    padding: 0.75rem;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.game-link-modal-content .btn-copy:hover {
    background: var(--color-accent-hover);
}

.game-link-modal-content .btn-copy.copied {
    background: hsl(130, 60%, 55%);
}

.game-link-modal-buttons {
    display: flex;
    gap: 0.75rem;
    margin-top: 0.5rem;
}

.game-link-modal-buttons .btn-secondary {
    flex: 1;
    padding: 0.85rem;
    border-radius: 8px;
    font-weight: 500;
    background-color: var(--color-btn-gray);
    color: var(--color-text-primary);
    transition: background-color 0.2s;
}

.game-link-modal-buttons .btn-secondary:hover {
    background-color: var(--color-btn-gray-hover);
}

.promotion-options {
    display: flex;
    flex-direction: column;
    gap: 0.7rem; /* Increased gap */
}

.promotion-option {
    width: 70px; /* Increased piece size for modal */
    height: 70px; /* Increased piece size for modal */
    background-color: var(--bg-card-header);
    border-radius: 0.375rem;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: background-color 0.2s;
    border: 2px solid transparent;
}

.promotion-option:hover {
    background-color: var(--bg-secondary);
    border-color: var(--color-accent);
}

.promotion-option.selected {
    border-color: var(--color-accent);
    box-shadow: 0 0 0 1px var(--color-accent);
}

.promotion-option img {
    width: 90%;
    height: 90%;
    object-fit: contain;
}

/* ===== Game Over Overlay ===== */
.game-over-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0);
    z-index: 1100;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.game-over-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.game-over-card {
    position: relative;
    width: 260px;
    max-width: 90vw;
    padding: 1.5rem 1.5rem 1.25rem;
    border-radius: 0.9rem;
    background: linear-gradient(145deg, hsl(216, 20%, 18%), hsl(216, 20%, 12%));
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.7);
    text-align: center;
}

.game-over-header {
    margin-bottom: 1.25rem;
}

.game-over-title {
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--color-text-primary);
}

.game-over-subtitle {
    margin-top: 0.25rem;
    font-size: 0.9rem;
    color: var(--color-text-secondary);
}

.game-over-close {
    position: absolute;
    top: 0.6rem;
    right: 0.6rem;
    width: 28px;
    height: 28px;
    border-radius: 999px;
    border: none;
    background: hsla(216, 15%, 25%, 0.9);
    color: var(--color-text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 0.85rem;
    transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease;
}

.game-over-close:hover {
    background: hsla(216, 15%, 32%, 1);
    color: var(--color-text-primary);
}

.game-over-close:active {
    transform: scale(0.96);
}

.game-over-primary {
    margin-top: 0.25rem;
    width: 100%;
    background: var(--color-accent);
    color: #ffffff;
    font-size: 1rem;
    font-weight: 700;
    border-radius: 999px;
    box-shadow: 0 4px 0 hsl(258, 60%, 45%);
    border: none;
    cursor: pointer;
    transition: transform 0.1s ease, box-shadow 0.1s ease, background 0.1s ease;
}

.game-over-primary:hover {
    background: var(--color-accent-hover);
}

.game-over-primary:active {
    transform: translateY(2px);
    box-shadow: none;
}

.game-over-secondary-row {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.9rem;
}

.game-over-secondary {
    flex: 1;
    border-radius: 0.6rem;
    background: hsla(216, 15%, 24%, 1);
    color: hsla(216, 10%, 60%, 1);
    border: none;
    cursor: not-allowed;
    font-weight: 600;
    font-size: 0.85rem;
}

/* Ensure chessboard.js drag image for piece is always visible */
.chessboard-piece {
    z-index: 2000 !important;
    pointer-events: none;
    opacity: 1 !important;
}
body > img[style*='position: absolute'] {
    z-index: 2000 !important;
    pointer-events: none;
    opacity: 1 !important;
}

/* --- Restore chessboard.js yellow square highlights (drag-and-drop) --- */
.board-b72b1 .highlight-white, .board-b72b1 .highlight-black {
    box-shadow: none !important;
    background: inherit !important;
}
.board-b72b1 .square-55d63:hover {
    box-shadow: 0 0 .2em 0.1em #0000002d inset;
}

/* Remove default chessboard.js yellow highlight glow completely */
.highlight1-32417, .highlight2-9c5d2 {
    box-shadow: none !important;
    background: inherit !important;
}

/* ===============================================
   PLAY MENU VIEWS
   =============================================== */

.play-menu-view {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    height: 100%;
    min-height: 0; /* Important for flex children to scroll */
}

.play-menu-view.hidden {
    display: none;
}

/* Game mode buttons */
.game-mode-section {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.btn-game-mode {
    background: var(--bg-secondary);
    border: none;
    border-radius: 0.5rem;
    padding: 1rem 1.25rem;
    color: var(--color-text-primary);
    font-weight: 600;
    text-align: left;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    transition: background 0.2s, transform 0.1s;
    position: relative;
}

.btn-game-mode:hover:not(.disabled) {
    background: var(--bg-hover);
    transform: translateX(4px);
}

.btn-game-mode.disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-game-mode i {
    font-size: 1.1rem;
    width: 24px;
    text-align: center;
    color: var(--color-accent);
}

.coming-soon-badge {
    margin-left: auto;
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--color-text-secondary);
    background: var(--bg-card-header);
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
}

.event-active-badge {
    margin-left: auto;
    font-size: 0.73rem;
    font-weight: 700;
    color: #fff;
    background: linear-gradient(135deg, #ff8a00, #e52e71);
    padding: 0.25rem 0.6rem;
    border-radius: 0.25rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.events-list {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    flex: 1;
    overflow-y: auto;
    padding-right: 0.5rem;
    margin-bottom: 0.5rem;
    scrollbar-width: thin;
    scrollbar-color: var(--color-accent) transparent;
}

.event-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    min-height: min-content;
}

.event-card:hover {
    transform: translateY(-2px);
    border-color: var(--color-accent);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.event-thumbnail {
    width: 100%;
    height: 120px;
    object-fit: cover;
}

.event-content {
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.event-title {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--color-text-primary);
}

.event-description {
    font-size: 0.95rem;
    color: var(--color-text-secondary);
    line-height: 1.4;
    margin-bottom: 0.5rem;
}

.event-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-top: 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    font-size: 0.9rem;
    margin-top: auto;
}

.event-time {
    color: var(--color-accent) !important;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.event-link {
    color: var(--color-accent);
    font-weight: 700;
}

.loading-events {
    text-align: center;
    padding: 2rem;
    color: var(--color-text-secondary);
}

/* Time controls grid section */
.time-controls-grid-section {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.time-category {
    background: var(--bg-card);
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
}

.time-category h4 {
    color: var(--color-text-secondary);
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.time-category h4 i {
    font-size: 0.9rem;
}

.time-options-row {
    display: flex;
    gap: 0.5rem;
}

.btn-time-option {
    flex: 1;
    background: var(--bg-secondary);
    border: 2px solid transparent;
    border-radius: 0.375rem;
    padding: 0.75rem 0.5rem;
    color: var(--color-text-primary);
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-time-option:hover {
    background: var(--bg-hover);
}

.btn-time-option.selected {
    background: var(--bg-hover);
    border-color: var(--color-accent);
    color: var(--color-accent);
}

/* Color selection for bot games */
.color-selection-section {
    background: var(--bg-card);
    padding: 1rem;
    border-radius: 0.5rem;
}

.color-selection-section h4 {
    color: var(--color-text-secondary);
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.75rem;
    text-align: center;
}

.color-options {
    display: flex;
    justify-content: center;
    gap: 0.75rem;
}

.btn-color-option {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--bg-secondary);
    border: 2px solid transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.btn-color-option:hover {
    background: var(--bg-hover);
}

.btn-color-option.selected {
    border-color: var(--color-accent);
    box-shadow: 0 0 0 2px var(--color-accent);
}

.btn-color-option i {
    font-size: 1.5rem;
}

/* Bot ELO section */
.bot-elo-section {
    background: var(--bg-card);
    padding: 1rem;
    border-radius: 0.5rem;
}

.bot-elo-section h4 {
    color: var(--color-text-secondary);
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.75rem;
    text-align: center;
}

/* Friend lobby section */
.friend-lobby-section {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.friend-lobby-section.hidden {
    display: none;
}

.friend-link-container {
    background: var(--bg-card);
    padding: 1rem;
    border-radius: 0.5rem;
}

.friend-link-container p {
    color: var(--color-text-secondary);
    font-size: 0.85rem;
    margin-bottom: 0.5rem;
    text-align: center;
}

.friend-lobby {
    background: var(--bg-card);
    padding: 1rem;
    border-radius: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
}

.lobby-player {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    min-width: 90px;
}

.lobby-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--color-accent);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.25rem;
}

.lobby-avatar.waiting {
    background: var(--bg-secondary);
    color: var(--color-text-secondary);
}

.lobby-name {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--color-text-primary);
    text-align: center;
}

.lobby-player.friend .lobby-name {
    color: var(--color-text-secondary);
    font-style: italic;
}

.lobby-player.friend.connected .lobby-name {
    color: var(--color-text-primary);
    font-style: normal;
}

.lobby-player.friend.connected .lobby-avatar {
    background: hsl(120, 50%, 45%);
}

.lobby-player.friend.connected .lobby-avatar.waiting {
    background: hsl(120, 50%, 45%);
    color: white;
}

.lobby-player.friend.connected .lobby-status {
    color: hsl(120, 60%, 50%);
}

.lobby-status {
    font-size: 0.75rem;
}

.lobby-status.ready {
    color: hsl(120, 60%, 50%);
}

.lobby-status.waiting {
    color: var(--color-text-secondary);
}

.lobby-vs {
    font-size: 1rem;
    font-weight: 700;
    color: var(--color-text-secondary);
}

/* Start game section adjustments */
.start-game-section {
    margin-top: auto;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.btn-back, .btn-cancel-friend {
    margin-top: 0.25rem;
}

.btn-back.hidden, .btn-cancel-friend.hidden {
    display: none;
}

.btn-cancel-game.hidden {
    display: none;
}

/* Link box styling */
.link-box {
    display: flex;
    gap: 0.5rem;
}

.link-box input {
    flex: 1;
    background: var(--bg-input);
    border: 1px solid var(--bg-card-border);
    border-radius: 0.25rem;
    padding: 0.5rem 0.75rem;
    color: var(--color-text-primary);
    font-size: 0.8rem;
    font-family: monospace;
}

.btn-copy {
    background: var(--bg-secondary);
    border: none;
    border-radius: 0.25rem;
    width: 40px;
    color: var(--color-text-primary);
    cursor: pointer;
    transition: background 0.2s;
}

.btn-copy:hover {
    background: var(--bg-hover);
}

.btn-copy.copied {
    background: hsl(120, 50%, 40%);
    color: white;
}

/* Responsive adjustments for play menu */
@media (max-width: 768px) {
    .time-controls-grid-section {
        gap: 0.75rem;
    }
    
    .time-category {
        padding: 0.5rem 0.75rem;
    }
    
    .btn-time-option {
        padding: 0.6rem 0.4rem;
        font-size: 0.85rem;
    }
    
    .lobby-player {
        min-width: 70px;
    }
    
    .lobby-avatar {
        width: 40px;
        height: 40px;
        font-size: 1rem;
    }
    
    .lobby-name {
        font-size: 0.75rem;
    }
}
