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

body {
    font-family: 'Microsoft YaHei', 'PingFang SC', 'STKaiti', sans-serif;
    background: #4a3728;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    margin: 0;
    padding: 20px;
}

#app {
    text-align: center;
}

h1 {
    color: #f0d9a0;
    margin-bottom: 14px;
    font-size: 28px;
    letter-spacing: 12px;
    text-shadow: 1px 1px 3px rgba(0,0,0,0.5);
    font-weight: normal;
}

#game-controls {
    margin-bottom: 12px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.control-group {
    display: flex;
    gap: 3px;
    background: rgba(0,0,0,0.2);
    border-radius: 5px;
    padding: 3px;
}

.mode-btn, .diff-btn {
    padding: 6px 16px;
    font-size: 14px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    background: transparent;
    color: #c4a66a;
    transition: background 0.2s, color 0.2s;
    font-family: inherit;
}

.mode-btn:hover, .diff-btn:hover {
    background: rgba(255,255,255,0.08);
    color: #f0d9a0;
}

.mode-btn.active, .diff-btn.active {
    background: #8b6914;
    color: #f0d9a0;
}

#board-container {
    display: flex;
    justify-content: center;
    overflow: hidden;
    width: 100%;
    touch-action: manipulation;
}

#board-wrapper {
    position: relative;
    display: inline-block;
    border-radius: 8px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.6);
    line-height: 0;
    transform-origin: top center;
}

#board-canvas {
    display: block;
    border-radius: 8px;
    cursor: pointer;
}

#pieces-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.piece {
    position: absolute;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    font-weight: bold;
    font-family: 'KaiTi', 'STKaiti', 'SimSun', serif;
    cursor: pointer;
    pointer-events: auto;
    touch-action: manipulation;
    background: radial-gradient(circle at 38% 35%, #fff8e7 0%, #f5deb3 60%, #e8d5a3 100%);
    border: 2.5px solid #8b4513;
    box-shadow: 2px 3px 8px rgba(0,0,0,0.35);
    user-select: none;
    transform: translate(-50%, -50%);
    transition: box-shadow 0.15s;
    z-index: 10;
}

.piece::before {
    content: '';
    position: absolute;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: 1px solid rgba(0,0,0,0.12);
    pointer-events: none;
}

.piece.red {
    color: #cc0000;
    border-color: #cc0000;
    text-shadow: 0 1px 2px rgba(204,0,0,0.3);
}

.piece.black {
    color: #1a1a1a;
    border-color: #1a1a1a;
    text-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

.piece.selected {
    box-shadow: 0 0 0 3px #f0d9a0, 0 0 16px 6px rgba(255,215,0,0.7);
    z-index: 20;
}

.piece.last-move-from {
    box-shadow: 0 0 0 3px rgba(100,200,100,0.6), 0 0 12px 4px rgba(100,200,100,0.4);
}

.piece.last-move-to {
    box-shadow: 0 0 0 3px rgba(100,200,100,0.6), 0 0 12px 4px rgba(100,200,100,0.4);
}

.piece:hover:not(.selected) {
    box-shadow: 0 0 0 2px rgba(255,255,150,0.5), 0 0 12px 4px rgba(255,255,150,0.3);
}

#status-bar {
    margin-top: 18px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 24px;
    color: #f0d9a0;
    font-size: 17px;
}

#turn-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
}

#turn-dot {
    display: inline-block;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid rgba(255,255,255,0.3);
    transition: background 0.3s;
}

#turn-dot.red-dot {
    background: #cc0000;
}

#turn-dot.black-dot {
    background: #1a1a1a;
}

#message {
    min-width: 120px;
    font-weight: bold;
    transition: color 0.3s;
}

#message.check {
    color: #ff6b6b;
    animation: pulse 0.8s ease-in-out infinite alternate;
}

#message.checkmate {
    color: #ffd700;
    font-size: 20px;
}

#message.stalemate {
    color: #ffa500;
    font-size: 20px;
}

#message.thinking {
    color: #87ceeb;
    animation: pulse 0.8s ease-in-out infinite alternate;
}

@keyframes pulse {
    from { opacity: 0.7; }
    to { opacity: 1; }
}

@media (max-width: 640px) {
    body { padding: 10px; }
    h1 { font-size: 22px; letter-spacing: 8px; margin-bottom: 10px; }
    #game-controls { gap: 6px; margin-bottom: 8px; }
    .mode-btn, .diff-btn { padding: 5px 10px; font-size: 12px; }
    #status-bar { font-size: 14px; gap: 12px; flex-wrap: wrap; }
    #undo-btn { padding: 6px 12px; font-size: 13px; }
    #restart-btn { padding: 6px 18px; font-size: 13px; }
    #history-bar { max-width: 100%; }
    #history-body { max-height: 100px; font-size: 12px; }
    .h-red, .h-black { width: 70px; }
    .h-num { font-size: 11px; width: 22px; }
}

#status-actions {
    display: flex;
    gap: 8px;
}

#undo-btn {
    padding: 8px 16px;
    font-size: 15px;
    border: none;
    border-radius: 6px;
    background: #5a4a2a;
    color: #c4a66a;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    font-family: inherit;
}

#undo-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

#undo-btn:not(:disabled):hover {
    background: #6a5a3a;
}

#undo-btn:not(:disabled):active {
    transform: scale(0.96);
}

#restart-btn {
    padding: 8px 28px;
    font-size: 15px;
    border: none;
    border-radius: 6px;
    background: #8b6914;
    color: #f0d9a0;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    font-family: inherit;
}

#restart-btn:hover {
    background: #a07d20;
}

#restart-btn:active {
    transform: scale(0.96);
}

#history-bar {
    margin-top: 14px;
    max-width: 560px;
    margin-left: auto;
    margin-right: auto;
    text-align: left;
}

#history-title {
    color: #c4a66a;
    font-size: 14px;
    margin-bottom: 4px;
    padding-left: 4px;
}

#history-body {
    max-height: 130px;
    overflow-y: auto;
    background: rgba(0,0,0,0.15);
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 14px;
    font-family: 'KaiTi', 'STKaiti', monospace;
}

#history-body::-webkit-scrollbar {
    width: 6px;
}

#history-body::-webkit-scrollbar-track {
    background: rgba(0,0,0,0.1);
    border-radius: 3px;
}

#history-body::-webkit-scrollbar-thumb {
    background: rgba(196,166,106,0.4);
    border-radius: 3px;
}

.history-row {
    display: flex;
    gap: 4px;
    line-height: 1.8;
    align-items: center;
}

.h-num {
    width: 28px;
    text-align: right;
    color: #8b6914;
    font-size: 13px;
    flex-shrink: 0;
}

.h-red {
    width: 90px;
    text-align: center;
    color: #cc0000;
    flex-shrink: 0;
}

.h-black {
    width: 90px;
    text-align: center;
    color: #d4c48a;
    flex-shrink: 0;
}
