:root {
    --bg-paper: #f4ece0;
    --accent-red: #d32f2f;
    --accent-black: #212121;
    --gold: #c5a059;
    --border-color: #5d4037;
    --glass: rgba(255, 255, 255, 0.6);
    --cell-size: min(85px, 12vh, 10vw);
}

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

body {
    background: radial-gradient(circle, #2c1e11 0%, #0a0a0a 100%);
    font-family: 'Noto Sans TC', sans-serif;
    overflow: hidden;
    width: 100vw;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

#game-container {
    width: 100%;
    height: 100%;
    max-width: 1100px;
    max-height: 850px;
    background: var(--bg-paper) url('https://www.transparenttextures.com/patterns/handmade-paper.png');
    border: 8px solid var(--border-color);
    outline: 2px solid var(--gold);
    display: flex;
    flex-direction: column;
    position: relative;
    user-select: none;
}

header {
    background: rgba(0, 0, 0, 0.05);
    padding: 10px 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 3px solid var(--border-color);
    flex-shrink: 0;
    position: relative;
}

h1 {
    font-family: 'Ma Shan Zheng', cursive;
    font-size: 1.8rem;
    color: var(--border-color);
}

.badge {
    background: var(--gold);
    color: white;
    padding: 2px 6px;
    font-size: 0.7rem;
    border-radius: 4px;
    vertical-align: middle;
}

#status-bar {
    display: flex;
    gap: 15px;
    align-items: center;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.player-label {
    padding: 8px 25px;
    border-radius: 30px;
    background: white;
    color: #999;
    font-weight: bold;
    font-size: 1rem;
    opacity: 0.6;
}

.player-label.active {
    background: var(--accent-red);
    color: white;
    opacity: 1;
    box-shadow: 0 5px 15px rgba(211, 47, 47, 0.4);
}

.player-label.player-ai.active {
    background: var(--accent-black);
}

.status-center {
    padding: 6px 14px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.75);
    color: var(--border-color);
    border: 1px solid rgba(93, 64, 55, 0.2);
    font-size: 0.85rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    white-space: nowrap;
    pointer-events: none;
}

#game-info {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 10px;
    background: rgba(255, 255, 255, 0.3);
    flex-shrink: 0;
    gap: 30px;
}

.score-card {
    background: var(--glass);
    backdrop-filter: blur(5px);
    border: 3px solid rgba(255, 255, 255, 0.5);
    padding: 10px 25px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    gap: 15px;
    transition: all 0.3s ease;
}

.score-card.active {
    border-color: var(--gold);
    box-shadow: 0 0 20px var(--gold);
    background: rgba(255, 255, 255, 0.45);
}

#player-label-text, #ai-label-text {
    font-size: 1.1rem;
    color: var(--border-color);
}

.score {
    font-size: 2.2rem;
    font-weight: 900;
    color: var(--border-color);
    font-family: 'Consolas', monospace;
}

.board-area {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 10px;
    overflow: hidden;
}

#board-container {
    padding: 12px;
    background: #d4b483;
    border: 6px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
}

#chess-board {
    display: grid;
    gap: 10px;
    grid-template-columns: repeat(8, var(--cell-size));
    grid-template-rows: repeat(4, var(--cell-size));
}

.cell {
    width: var(--cell-size);
    height: var(--cell-size);
    background: rgba(0, 0, 0, 0.1);
    border-radius: 6px;
    position: relative;
}

.cell.last-move {
    border: 2px solid var(--gold);
    box-shadow: 0 0 15px var(--gold);
}

.piece {
    width: calc(var(--cell-size) - 10px);
    height: calc(var(--cell-size) - 10px);
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    transition: transform 0.2s;
    cursor: pointer;
    z-index: 10;
}

.piece-face {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: calc(var(--cell-size) * 0.55);
    font-family: '楷體', serif;
    font-weight: bold;
    box-shadow: 0 5px 10px rgba(0, 0, 0, 0.4);
    border: 2px solid #222;
}

.piece-back {
    background: linear-gradient(135deg, #4e342e, #261b15);
    color: rgba(255, 255, 255, 0.05);
}

.piece-back::after {
    content: "棋";
    font-size: 2rem;
}

.piece-front {
    background: #fff;
    display: none;
}

.piece.flipped .piece-back {
    display: none;
}

.piece.flipped .piece-front {
    display: flex;
    z-index: 5;
}

.piece.red .piece-front {
    color: #f44336;
    border-color: #b71c1c;
    background: #fff5f5;
}

.piece.black .piece-front {
    color: #212121;
    border-color: #000;
    background: #f0f0f0;
}

.piece.selected .piece-front {
    transform: scale(1.1);
    box-shadow: 0 0 25px var(--gold);
}

.move-hint {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 30%;
    height: 30%;
    background: rgba(255, 235, 59, 0.4);
    border: 1px solid var(--gold);
    border-radius: 50%;
    pointer-events: none;
}

.move-hint.eat {
    width: 85%;
    height: 85%;
    background: rgba(255, 0, 0, 0.1);
    border: 2px dashed var(--accent-red);
}

#controls {
    height: 70px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    flex-shrink: 0;
}

.classic-btn {
    background: var(--border-color);
    color: white;
    padding: 8px 30px;
    border-radius: 4px;
    border: none;
    cursor: pointer;
    font-size: 1.1rem;
}

#status-text {
    margin-top: 5px;
    font-weight: bold;
    color: var(--border-color);
}

.hidden {
    display: none !important;
}

#game-over-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.overlay-content {
    background: #fff;
    padding: 50px 80px;
    border-radius: 12px;
    border: 6px solid var(--accent-red);
    text-align: center;
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);
}

#winner-text {
    font-size: 3rem;
    color: var(--accent-red);
    margin-bottom: 30px;
    font-family: 'Ma Shan Zheng', cursive;
}
