* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #1a1a2e;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    color: #eee;
}

/* Layout */
.game-layout {
    display: flex;
    width: 100%;
    height: 100%;
}

.board-section {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    min-width: 0;
}

.board-container {
    width: min(calc(100vh - 32px), calc(100vw - 312px));
    max-width: 640px;
    aspect-ratio: 1;
}

/* Chess board */
.chess-board {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    width: 100%;
    height: 100%;
    border-radius: 4px;
    overflow: hidden;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.5);
}

.square {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: min(7vw, 58px);
    line-height: 1;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    transition: background-color 0.1s;
}

.square.light { background-color: #f0d9b5; }
.square.dark  { background-color: #b58863; }

/* White pieces: outlined Unicode glyphs -- add dark shadow for clarity */
.square.white-piece {
    color: #fff;
    text-shadow:
        -1px  0 1px #000,
         0  1px 1px #000,
         1px  0 1px #000,
         0 -1px 1px #000,
         0  0 3px rgba(0,0,0,0.3);
}

/* Black pieces */
.square.black-piece {
    color: #312e2b;
    text-shadow: none;
}

/* Selection highlight */
.square.selected {
    background-color: rgba(255, 255, 50, 0.6) !important;
}

/* Last move highlight */
.square.last-move.light { background-color: #f5f682; }
.square.last-move.dark  { background-color: #baca44; }

/* Check highlight */
.square.in-check {
    background: radial-gradient(ellipse at center, rgba(255,0,0,0.6) 0%, rgba(255,0,0,0.2) 50%, transparent 70%);
}

/* Legal move dots */
.square.move-target::after {
    content: '';
    position: absolute;
    width: 26%;
    height: 26%;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.18);
    pointer-events: none;
}

.square.capture-target::after {
    content: '';
    position: absolute;
    width: 82%;
    height: 82%;
    border-radius: 50%;
    border: 5px solid rgba(0, 0, 0, 0.18);
    background: transparent;
    pointer-events: none;
    box-sizing: border-box;
}

/* Coordinate labels */
.square[data-rank]::before {
    content: attr(data-rank);
    position: absolute;
    top: 3px;
    left: 4px;
    font-size: 11px;
    font-weight: 700;
    pointer-events: none;
    line-height: 1;
}

.square[data-file]::after {
    position: absolute;
    bottom: 2px;
    right: 4px;
    font-size: 11px;
    font-weight: 700;
    pointer-events: none;
    line-height: 1;
}

/* Only show file labels when not a move target */
.square[data-file]:not(.move-target):not(.capture-target)::after {
    content: attr(data-file);
}

.square.light[data-rank]::before { color: #b58863; }
.square.dark[data-rank]::before  { color: #f0d9b5; }
.square.light[data-file]:not(.move-target):not(.capture-target)::after { color: #b58863; }
.square.dark[data-file]:not(.move-target):not(.capture-target)::after  { color: #f0d9b5; }

/* Side panel */
.side-panel {
    width: 280px;
    background: #16213e;
    display: flex;
    flex-direction: column;
    border-left: 1px solid #2a2a4a;
    overflow: hidden;
}

.panel-header {
    padding: 16px 16px 8px;
    text-align: center;
}

.panel-header h1 {
    font-size: 1.2rem;
    color: #e0c097;
}

.panel-subtitle {
    font-size: 0.75rem;
    color: #8888aa;
}

/* Status */
.game-status {
    padding: 8px 16px;
    text-align: center;
    font-size: 0.95rem;
    min-height: 36px;
}

.status-turn { color: #e0c097; }
.status-check { color: #ff6666; }
.status-thinking { color: #88aaff; }
.status-gameover { color: #e0c097; font-weight: 700; }

/* Captured pieces */
.captured-section {
    padding: 4px 16px;
    min-height: 48px;
}

.captured-row {
    font-size: 1rem;
    letter-spacing: 1px;
    min-height: 22px;
    color: #aaa;
}

/* Move list */
.move-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px 16px;
    font-family: 'Consolas', 'Courier New', monospace;
    font-size: 0.85rem;
    border-top: 1px solid #2a2a4a;
    border-bottom: 1px solid #2a2a4a;
}

.move-row {
    display: flex;
    gap: 8px;
    padding: 2px 0;
}

.move-num {
    color: #666;
    min-width: 28px;
    text-align: right;
}

.move-white, .move-black {
    min-width: 55px;
}

/* Controls */
.controls {
    padding: 12px;
    display: flex;
    gap: 8px;
}

.ctrl-btn {
    flex: 1;
    padding: 8px 4px;
    background: #0f3460;
    color: #ccc;
    border: 1px solid #2a2a4a;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.75rem;
    transition: background 0.15s;
    white-space: nowrap;
}

.ctrl-btn:hover:not(:disabled) { background: #1a4a80; }
.ctrl-btn:disabled { opacity: 0.4; cursor: default; }

/* Promotion dialog */
.promotion-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.promotion-dialog {
    display: flex;
    gap: 8px;
    background: #16213e;
    padding: 16px;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}

.promotion-btn {
    width: 64px;
    height: 64px;
    font-size: 40px;
    background: #f0d9b5;
    border: 2px solid #b58863;
    border-radius: 8px;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
    line-height: 1;
}

.promotion-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 16px rgba(224, 192, 151, 0.4);
}

/* Game over overlay */
.gameover-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.gameover-box {
    background: #16213e;
    padding: 2rem 2.5rem;
    border-radius: 16px;
    text-align: center;
    box-shadow: 0 8px 40px rgba(0,0,0,0.6);
}

.gameover-box h2 {
    color: #e0c097;
    font-size: 1.4rem;
    margin-bottom: 1.5rem;
}

.gameover-btn {
    padding: 10px 32px;
    background: #e0c097;
    color: #1a1a2e;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    margin: 0 8px;
    transition: background 0.15s;
}

.gameover-btn:hover { background: #d4a76a; }

.gameover-dismiss {
    padding: 10px 24px;
    background: transparent;
    color: #8888aa;
    border: 1px solid #2a2a4a;
    border-radius: 8px;
    font-size: 0.9rem;
    cursor: pointer;
    margin: 0 8px;
    transition: background 0.15s;
}

.gameover-dismiss:hover { background: #0f3460; }

/* Mobile layout */
@media (max-width: 700px) {
    .game-layout {
        flex-direction: column;
    }

    .board-section {
        padding: 8px;
    }

    .board-container {
        width: min(calc(100vw - 16px), calc(60vh));
        max-width: none;
    }

    .side-panel {
        width: 100%;
        flex: 1;
        border-left: none;
        border-top: 1px solid #2a2a4a;
    }

    .move-list {
        max-height: 120px;
    }
}

/* Scrollbar styling for move list */
.move-list::-webkit-scrollbar { width: 6px; }
.move-list::-webkit-scrollbar-track { background: transparent; }
.move-list::-webkit-scrollbar-thumb { background: #2a2a4a; border-radius: 3px; }
