/* ==============================================================================
   Chess.com Inspired Dark Aesthetic for ApexChess
   Responsive for Mobile Phones and Desktop
   ============================================================================== */

:root {
    --bg-page: #262522;
    --bg-surface: #21201d;
    --bg-sidebar: #312e2b;
    --bg-card: #272522;
    --bg-hover: #3b3835;

    --btn-primary: #81b64c;
    --btn-primary-hover: #72a143;
    --btn-secondary: #454341;
    --btn-secondary-hover: #54514e;

    /* Iconic Chess.com Board Colors */
    --board-light: #ebecd0;
    --board-dark: #739552;
    --board-highlight: rgba(235, 236, 100, 0.6);

    --text-white: #ffffff;
    --text-primary: #e0e0e0;
    --text-secondary: #c3c1be;
    --text-muted: #8b8987;

    --eval-white: #ffffff;
    --eval-black: #111111;

    --font-main: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'Fira Code', 'Roboto Mono', monospace;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--bg-page);
    color: var(--text-primary);
    font-family: var(--font-main);
    line-height: 1.5;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Override chessboard.js default colors with Chess.com Green/Buff */
.white-1e1d7 {
    background-color: var(--board-light) !important;
    color: var(--board-dark);
}

.black-3c85d {
    background-color: var(--board-dark) !important;
    color: var(--board-light);
}

.highlight1-32417, .highlight2-9c5d2 {
    background-color: var(--board-highlight) !important;
}

/* Minimal Topbar */
.topbar {
    background-color: var(--bg-surface);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    padding: 0.6rem 1rem;
    position: sticky;
    top: 0;
    z-index: 100;
}

.topbar-content {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 800;
    font-size: 1.15rem;
    letter-spacing: 0.03em;
}

.brand-icon {
    font-size: 1.35rem;
    color: var(--btn-primary);
}

.brand-sub {
    color: var(--btn-primary);
}

.bot-badge {
    font-size: 0.65rem;
    background: rgba(129, 182, 76, 0.2);
    color: var(--btn-primary);
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    font-weight: 700;
}

.topbar-actions a {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.88rem;
    font-weight: 600;
    padding: 0.35rem 0.75rem;
    border-radius: 6px;
    background: var(--bg-card);
    transition: background 0.15s;
}

.topbar-actions a:hover {
    background: var(--bg-hover);
    color: var(--text-white);
}

/* Main Arena Layout */
.arena-wrapper {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 1rem;
}

.arena-container {
    display: flex;
    gap: 1.25rem;
    max-width: 1100px;
    width: 100%;
    margin: 0 auto;
    align-items: flex-start;
}

/* Board Wrapper: Eval Bar + Board Column */
.board-wrapper {
    display: flex;
    gap: 0.75rem;
    flex: 1;
    max-width: 620px;
}

/* Eval Bar */
.eval-bar {
    width: 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 100%;
    min-height: 520px;
}

.eval-track {
    width: 20px;
    flex: 1;
    background-color: var(--eval-black);
    border-radius: 4px;
    overflow: hidden;
    position: relative;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.eval-fill {
    width: 100%;
    background-color: var(--eval-white);
    position: absolute;
    bottom: 0;
    transition: height 0.4s ease;
}

.eval-num {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-secondary);
    margin-top: 0.35rem;
}

/* Board Column */
.board-column {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

/* Player Cards */
.player-card {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.4rem 0.6rem;
    background: var(--bg-card);
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.04);
}

.player-avatar {
    width: 38px;
    height: 38px;
    border-radius: 4px;
    background: #363431;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.3rem;
}

.user-avatar {
    background: #2b3922;
}

.player-info {
    flex: 1;
}

.player-name-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.player-name {
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--text-white);
}

.player-rating {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.badge-bot {
    font-size: 0.65rem;
    font-weight: 800;
    background: #739552;
    color: #fff;
    padding: 0.1rem 0.3rem;
    border-radius: 3px;
}

.player-status {
    font-size: 0.78rem;
    color: var(--text-muted);
}

.player-eval-indicator {
    font-family: var(--font-mono);
    font-size: 0.88rem;
    font-weight: 700;
    color: var(--btn-primary);
}

/* The Chessboard Container */
.board-container {
    width: 100%;
    aspect-ratio: 1/1;
    border-radius: 6px;
    overflow: hidden;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

#myBoard {
    width: 100% !important;
}

/* Sidebar (Chess.com Style) */
.sidebar {
    width: 360px;
    background: var(--bg-sidebar);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

.sidebar-section {
    padding: 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.section-label {
    display: block;
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-bottom: 0.4rem;
}

.bot-select {
    width: 100%;
    background: var(--bg-card);
    color: var(--text-white);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    padding: 0.65rem 0.75rem;
    font-size: 0.92rem;
    font-weight: 600;
    cursor: pointer;
    outline: none;
}

.bot-select:focus {
    border-color: var(--btn-primary);
}

.bot-description {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
    line-height: 1.4;
}

/* Move History Section */
.move-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 240px;
    max-height: 280px;
}

.move-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
}

.move-count {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.move-history-table {
    flex: 1;
    overflow-y: auto;
    background: var(--bg-card);
    border-radius: 6px;
    padding: 0.4rem 0;
    font-family: var(--font-mono);
    font-size: 0.88rem;
}

.empty-state {
    padding: 2rem 1rem;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-family: var(--font-main);
}

.move-row {
    display: flex;
    padding: 0.25rem 0.75rem;
    border-radius: 4px;
}

.move-row:nth-child(even) {
    background: rgba(255, 255, 255, 0.02);
}

.move-num {
    width: 38px;
    color: var(--text-muted);
    font-weight: 600;
}

.move-white, .move-black {
    flex: 1;
    cursor: pointer;
    border-radius: 3px;
    padding: 0 0.35rem;
}

.move-white:hover, .move-black:hover {
    background: rgba(255, 255, 255, 0.1);
}

.move-current {
    background: rgba(129, 182, 76, 0.3) !important;
    color: #fff;
    font-weight: 700;
}

/* Control Buttons */
.controls-section {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
}

.btn-primary-green {
    width: 100%;
    background-color: var(--btn-primary);
    color: #ffffff;
    border: none;
    border-radius: 8px;
    padding: 0.85rem 1rem;
    font-size: 1rem;
    font-weight: 700;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    transition: background-color 0.15s, transform 0.1s;
    box-shadow: 0 4px 0 #527433;
}

.btn-primary-green:hover {
    background-color: var(--btn-primary-hover);
}

.btn-primary-green:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 #527433;
}

.btn-group {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.4rem;
}

.btn-secondary {
    background-color: var(--btn-secondary);
    color: var(--text-primary);
    border: none;
    border-radius: 6px;
    padding: 0.6rem 0.2rem;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.15rem;
    transition: background-color 0.15s;
}

.btn-secondary:hover {
    background-color: var(--btn-secondary-hover);
    color: #ffffff;
}

.btn-secondary.active {
    color: var(--btn-primary);
}

.sidebar-footer {
    padding: 0.6rem 1rem;
    font-size: 0.72rem;
    color: var(--text-muted);
    text-align: center;
    background: rgba(0, 0, 0, 0.15);
}

/* ==============================================================================
   Mobile Responsiveness (Phone & Tablet)
   ============================================================================== */
@media (max-width: 900px) {
    .arena-container {
        flex-direction: column;
        align-items: center;
    }

    .board-wrapper {
        width: 100%;
        max-width: 500px;
    }

    .eval-bar {
        min-height: auto;
        height: auto;
    }

    .sidebar {
        width: 100%;
        max-width: 500px;
        margin-top: 0.5rem;
    }

    .move-section {
        min-height: 160px;
        max-height: 200px;
    }
}

@media (max-width: 480px) {
    .arena-wrapper {
        padding: 0.4rem;
    }

    .eval-bar {
        display: none; /* Hide vertical eval bar on small phones to maximize board width */
    }

    .board-wrapper {
        gap: 0;
    }

    .player-card {
        padding: 0.35rem 0.5rem;
    }

    .player-avatar {
        width: 32px;
        height: 32px;
        font-size: 1.1rem;
    }

    .player-name {
        font-size: 0.88rem;
    }
}

/* ==============================================================================
   Chess.com Highlights, Legal Move Hints & Game Over Modal
   ============================================================================== */
.highlight-move {
    box-shadow: inset 0 0 3px 3px rgba(247, 247, 105, 0.5) !important;
    background-color: rgba(247, 247, 105, 0.4) !important;
}

.highlight-selected {
    background-color: rgba(20, 85, 30, 0.5) !important;
}

.highlight-check {
    background: radial-gradient(ellipse at center, rgba(255, 0, 0, 0.8) 0%, rgba(231, 0, 0, 0.4) 60%, rgba(169, 0, 0, 0) 100%) !important;
}

.legal-hint-dot {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 26%;
    height: 26%;
    background-color: rgba(0, 0, 0, 0.22);
    border-radius: 50%;
    pointer-events: none;
    z-index: 5;
}

.legal-hint-capture {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    box-sizing: border-box;
    border: 5px solid rgba(0, 0, 0, 0.22);
    border-radius: 50%;
    pointer-events: none;
    z-index: 5;
}

.game-over-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

.game-over-modal.show {
    opacity: 1;
    pointer-events: auto;
}

.game-over-box {
    background: #2b2927;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 2rem 2.5rem;
    max-width: 400px;
    width: 90%;
    text-align: center;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.6);
    transform: scale(0.9);
    transition: transform 0.25s ease;
}

.game-over-modal.show .game-over-box {
    transform: scale(1);
}

.game-over-icon {
    font-size: 3rem;
    margin-bottom: 0.5rem;
}

.game-over-title {
    font-size: 1.5rem;
    font-weight: 800;
    color: #ffffff;
    margin-bottom: 0.5rem;
}

.game-over-subtitle {
    font-size: 0.95rem;
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
}

.game-over-btn {
    background-color: var(--btn-primary);
    color: #ffffff;
    border: none;
    border-radius: 8px;
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: background-color 0.15s;
    width: 100%;
}

.game-over-btn:hover {
    background-color: var(--btn-primary-hover);
}

