:root {
    --bg-color: #181e25;
    --text-color: #f5f6f8;
    --subtext-color: #8e99a8;
    --board-border: #222933;

    /* Theme 1: Lichess Wood */
    --sq-light: #f0d9b5;
    --sq-dark: #b58863;

    --highlight-selected: rgba(246, 226, 126, 0.75);
    --highlight-dot: rgba(46, 204, 113, 0.75);
    --highlight-capture: rgba(231, 76, 60, 0.65);
}

body.theme-green {
    /* Theme 2: Chess.com Green */
    --sq-light: #ebecd0;
    --sq-dark: #779556;
}

body.theme-bw {
    /* Theme 3: High Contrast B&W */
    --sq-light: #f0f2f5;
    --sq-dark: #3a4454;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    min-height: 100vh;
    padding: 10px 8px;
    overflow-x: hidden;
}

.header {
    width: 100%;
    max-width: 440px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 4px 6px;
}

.players-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    padding: 8px 12px;
}

.player-info {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 600;
}

.player-info.active {
    color: #4cd964;
}

.player-icon {
    font-size: 16px;
}

.status-bar {
    text-align: center;
    font-size: 13px;
    font-weight: 500;
    color: var(--subtext-color);
    min-height: 20px;
}

.status-bar.check {
    color: #ff9800;
    font-weight: bold;
}

.status-bar.game-over {
    color: #ff5252;
    font-weight: bold;
    font-size: 15px;
}

.history-ticker {
    font-size: 11px;
    color: #6c7a89;
    text-align: center;
    font-family: monospace;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* 8x8 Board Container */
.board-wrapper {
    position: relative;
    width: 100%;
    max-width: 420px;
    aspect-ratio: 1 / 1;
    border: 3px solid var(--board-border);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4);
}

.board {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    width: 100%;
    height: 100%;
}

.square {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    cursor: pointer;
}

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

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

.square.selected {
    background-color: var(--highlight-selected) !important;
}

.square.last-move {
    background-color: rgba(155, 199, 0, 0.4) !important;
}

/* Move Indicator Dot (empty legal square) */
.square.legal-target::after {
    content: '';
    position: absolute;
    width: 28%;
    height: 28%;
    border-radius: 50%;
    background-color: var(--highlight-dot);
    pointer-events: none;
    z-index: 2;
    box-shadow: 0 0 4px rgba(0, 0, 0, 0.3);
}

/* Move Indicator Ring (capture legal square) */
.square.legal-capture::after {
    content: '';
    position: absolute;
    width: 84%;
    height: 84%;
    border-radius: 50%;
    border: 4px solid var(--highlight-capture);
    pointer-events: none;
    z-index: 2;
}

.piece {
    width: 90%;
    height: 90%;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    z-index: 1;
    pointer-events: none;
    transition: transform 0.1s ease;
}

/* Board Coordinates (1-8 and a-h) */
.coord {
    position: absolute;
    font-size: 10px;
    font-weight: 700;
    pointer-events: none;
    line-height: 1;
}

.coord-file {
    bottom: 2px;
    right: 2px;
}

.coord-rank {
    top: 2px;
    left: 2px;
}

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

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

/* Bottom Controls */
.controls {
    width: 100%;
    max-width: 440px;
    display: flex;
    justify-content: space-around;
    gap: 8px;
    padding: 8px 4px;
}

.btn {
    flex: 1;
    padding: 10px 6px;
    border: none;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    transition: background 0.15s ease;
}

.btn:hover, .btn:active {
    background: rgba(255, 255, 255, 0.16);
}

.btn-danger {
    background: rgba(231, 76, 60, 0.2);
    color: #ff6b6b;
}

.btn-danger:hover {
    background: rgba(231, 76, 60, 0.35);
}

/* Promotion Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.modal-content {
    background: #242c37;
    padding: 16px;
    border-radius: 12px;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
}

.modal-title {
    margin-bottom: 12px;
    font-size: 15px;
    font-weight: 600;
}

.promo-choices {
    display: flex;
    gap: 12px;
}

.promo-choice {
    width: 60px;
    height: 60px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.1);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.promo-choice img {
    width: 80%;
    height: 80%;
}
