:root {
    --board-bg: #DEB887;
    --board-border: #8B4513;
    --line-color: #5d4037;
    --piece-size: 56px;
    --cell-size: 64px;
    --board-padding: 36px;
    --red-color: #d00;
    --black-color: #111;
    --selected-shadow: 0 0 15px rgba(255, 215, 0, 0.8);
    --last-move-shadow: 0 0 10px rgba(0, 255, 0, 0.6);
}

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

body {
    font-family: "KaiTi", "STKaiti", "楷体", "SimKai", "FangSong", "仿宋", "STFangSong", serif;
    background-color: #222;
    background-image: linear-gradient(rgba(0, 0, 0, 0.3), rgba(0, 0, 0, 0.3)), url('background.png');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    background-attachment: fixed;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    color: #eee;
    /* 防止文本选择和触摸行为 */
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    padding: 30px;
    background: rgba(20, 20, 20, 0.6);
    border-radius: 16px;
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.header {
    width: 100%;
    text-align: center;
    margin-bottom: 20px;
    padding: 15px 0;
}

.header h1 {
    display: block;
    font-size: 2.5rem;
    color: #deb887;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
    margin: 0;
    font-weight: bold;
    letter-spacing: 0.1em;
}

.main-content {
    display: flex;
    flex-direction: row;
    gap: 40px;
    align-items: center;
    width: 100%;
    justify-content: center;
}

.board-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.captured-pieces {
    width: calc(var(--cell-size) * 8 + var(--board-padding) * 2);
    min-height: 50px;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 8px;
    padding: 10px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    margin: 10px 0;
}

.captured-top {
    margin-bottom: 15px;
}

.captured-bottom {
    margin-top: 15px;
}

.captured-piece {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #f0d9b5;
    box-shadow:
        inset 0 -2px 3px rgba(0, 0, 0, 0.3),
        inset 0 2px 3px rgba(255, 255, 255, 0.8),
        1px 1px 3px rgba(0, 0, 0, 0.4);
    border: none;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 24px;
    font-weight: bold;
    font-family: "KaiTi", "STKaiti", "楷体", "SimKai", "FangSong", "仿宋", "STFangSong", serif;
    background-image: linear-gradient(135deg, #fff8e7 0%, #f0d9b5 100%);
    opacity: 0.7;
}

.captured-piece.red {
    color: var(--red-color);
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
}

.captured-piece.black {
    color: var(--black-color);
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
}

/* 被吃掉的暗棋样式（保持背面朝上） */
.captured-piece.hidden {
    background-image: url('piece_texture.png');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    color: transparent !important;
    text-shadow: none !important;
    font-size: 0 !important;
    text-indent: -9999px;
    position: relative;
    overflow: hidden;
    border: none;
    box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.5);
}

.captured-piece.hidden::before,
.captured-piece.hidden::after {
    display: none;
}

.chessboard {
    width: calc(var(--cell-size) * 8 + var(--board-padding) * 2);
    height: calc(var(--cell-size) * 9 + var(--board-padding) * 2);
    background-color: var(--board-bg);
    background-image:
        linear-gradient(rgba(255, 255, 255, 0.1) 0%, transparent 20%, rgba(0, 0, 0, 0.1) 50%, transparent 80%, rgba(255, 255, 255, 0.1) 100%),
        url("data:image/svg+xml,%3Csvg width='100' height='100' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.5' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.15'/%3E%3C/svg%3E");
    position: relative;
    border: 8px solid var(--board-border);
    border-radius: 4px;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.4), inset 0 0 30px rgba(0, 0, 0, 0.3);
    -webkit-user-select: none;
    user-select: none;
    box-sizing: content-box;
}

.grid-overlay {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
    z-index: 1;
}

.pieces-layer {
    position: relative;
    width: 100%;
    height: 100%;
    z-index: 10;
}

.piece {
    width: var(--piece-size);
    height: var(--piece-size);
    border-radius: 50%;
    background: #f0d9b5;
    box-shadow:
        inset 0 -3px 5px rgba(0, 0, 0, 0.3),
        inset 0 3px 5px rgba(255, 255, 255, 0.8),
        2px 2px 5px rgba(0, 0, 0, 0.4);
    border: none;
    position: absolute;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 32px;
    font-weight: bold;
    font-family: "KaiTi", "STKaiti", "楷体", "SimKai", "FangSong", "仿宋", "STFangSong", serif;
    cursor: pointer;
    transition: transform 0.2s cubic-bezier(0.25, 0.46, 0.45, 0.94), top 0.3s, left 0.3s;
    transform: translate(-50%, -50%);
    background-image: linear-gradient(135deg, #fff8e7 0%, #f0d9b5 100%);
}

.piece::before {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    right: 3px;
    bottom: 3px;
    border-radius: 50%;
    /* border: 1px solid rgba(0, 0, 0, 0.1); */
}

.piece.red {
    color: var(--red-color);
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
}

.piece.black {
    color: var(--black-color);
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
}

.piece.selected {
    transform: translate(-50%, -50%) scale(1.1);
    box-shadow: var(--selected-shadow);
    z-index: 20;
    background-color: #fff;
}

.piece.last-move {
    box-shadow: var(--last-move-shadow);
}

/* 移动提示点 */
.move-hint {
    position: absolute;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background-color: rgba(0, 255, 0, 0.8);
    box-shadow: 0 0 8px rgba(0, 255, 0, 0.8);
    transform: translate(-50%, -50%);
    z-index: 100;
    pointer-events: none;
}

.last-move-from {
    position: absolute;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background-color: rgba(255, 0, 0, 0.5);
    box-shadow: 0 0 5px rgba(255, 0, 0, 0.5);
    transform: translate(-50%, -50%);
    z-index: 5;
    pointer-events: none;
}

.piece.check {
    box-shadow: 0 0 20px red;
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 10px red;
    }

    50% {
        box-shadow: 0 0 25px red;
    }

    100% {
        box-shadow: 0 0 10px red;
    }
}

/* 揭棋模式 - 暗棋样式 */
/* 揭棋模式 - 暗棋样式 */
.piece.hidden {
    background-image: url('piece_texture.png');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    color: transparent !important;
    text-shadow: none !important;
    font-size: 0 !important;
    text-indent: -9999px;
    overflow: hidden;
    border: none;
    box-shadow:
        inset 0 -3px 5px rgba(0, 0, 0, 0.5),
        inset 0 3px 5px rgba(255, 255, 255, 0.2),
        2px 2px 5px rgba(0, 0, 0, 0.4);
}

/* 移除原有的复杂纹理 */
.piece.hidden::before,
.piece.hidden::after {
    display: none;
}

/* 翻棋动画 */
@keyframes flip {
    0% {
        transform: translate(-50%, -50%) rotateY(0deg);
    }

    50% {
        transform: translate(-50%, -50%) rotateY(90deg);
    }

    100% {
        transform: translate(-50%, -50%) rotateY(0deg);
    }
}

.piece.flipping {
    animation: flip 0.6s ease-in-out;
}

.controls {
    display: flex;
    flex-direction: column;
    gap: 25px;
    min-width: 240px;
    background: rgba(0, 0, 0, 0.2);
    padding: 25px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.status-panel {
    text-align: center;
}

.status-panel h2 {
    font-size: 1.5rem;
    margin-bottom: 10px;
    color: #deb887;
}

#game-status {
    font-size: 1.1rem;
    margin-bottom: 10px;
    min-height: 1.5em;
}

.record {
    margin-top: 15px;
    padding: 10px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.record p {
    font-size: 1rem;
    color: #deb887;
}

.record span {
    font-weight: bold;
    font-size: 1.1rem;
}

#win-count {
    color: #4caf50;
}

#loss-count {
    color: #f44336;
}

.turn-red {
    color: #ff6b6b;
    font-weight: bold;
    font-size: 1.2rem;
}

.turn-black {
    color: #aaa;
    font-weight: bold;
    font-size: 1.2rem;
}

.settings label {
    display: block;
    margin-bottom: 8px;
    font-size: 1rem;
    color: #ccc;
}

select {
    width: 100%;
    padding: 10px;
    background: #444;
    color: white;
    border: 1px solid #666;
    border-radius: 6px;
    font-size: 1rem;
    outline: none;
}

.buttons button {
    display: block;
    width: 100%;
    padding: 12px;
    margin-bottom: 15px;
    background-color: #5d4037;
    color: #deb887;
    border: 1px solid #8b4513;
    border-radius: 6px;
    cursor: pointer;
    font-size: 18px;
    font-family: "KaiTi", serif;
    transition: all 0.2s;
}

.buttons button:hover {
    background-color: #795548;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

.buttons button:active {
    transform: translateY(0);
}

#undo-btn {
    background-color: #444;
    border-color: #666;
    color: #ccc;
}

#undo-btn:hover {
    background-color: #555;
}

.switch-mode-btn {
    background-color: #8B4513 !important;
    margin-top: 10px;
}

/* 响应式设计 */
@media (max-width: 1200px) {
    :root {
        --piece-size: 48px;
        --cell-size: 54px;
        --board-padding: 28px;
    }

    .piece {
        font-size: 28px;
    }

    .header h1 {
        font-size: 2.2rem;
    }

    .controls {
        min-width: 200px;
    }

    .captured-piece {
        width: 35px;
        height: 35px;
        font-size: 20px;
    }
}

@media (max-width: 850px) {
    :root {
        --piece-size: 42px;
        --cell-size: 48px;
        --board-padding: 24px;
    }

    .piece {
        font-size: 24px;
    }

    .header {
        margin-bottom: 15px;
        padding: 10px 0;
    }

    .header h1 {
        font-size: 1.8rem;
    }

    .game-container {
        flex-direction: column;
        padding: 15px;
        gap: 20px;
    }

    .main-content {
        flex-direction: column;
        gap: 20px;
    }

    .chessboard {
        transform: none;
        margin-bottom: 0;
        width: calc(var(--cell-size) * 8 + var(--board-padding) * 2);
        height: calc(var(--cell-size) * 9 + var(--board-padding) * 2);
        max-width: 100%;
        box-sizing: content-box;
    }

    .controls {
        min-width: unset;
        width: 100%;
        max-width: 400px;
        padding: 20px;
        margin: 0 auto;
    }

    .buttons {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    .buttons button {
        width: 100%;
        margin-bottom: 0;
        font-size: 16px;
        padding: 14px;
        -webkit-tap-highlight-color: rgba(255, 255, 255, 0.1);
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        user-select: none;
    }

    .captured-pieces {
        width: 100%;
        justify-content: center;
        gap: 6px;
        padding: 8px;
    }

    .captured-piece {
        width: 32px;
        height: 32px;
        font-size: 18px;
        flex-shrink: 0;
    }

    .status-panel h2 {
        font-size: 1.3rem;
    }

    #game-status {
        font-size: 1rem;
    }

    .record p {
        font-size: 0.9rem;
    }

    .settings label {
        font-size: 0.9rem;
        margin-bottom: 6px;
    }

    select {
        font-size: 0.9rem;
        padding: 12px;
    }
}

@media (max-width: 600px) {
    :root {
        --piece-size: 36px;
        --cell-size: 42px;
        --board-padding: 20px;
    }

    .piece {
        font-size: 20px;
    }

    .header {
        margin-bottom: 10px;
        padding: 8px 0;
    }

    .header h1 {
        font-size: 1.5rem;
        letter-spacing: 0.05em;
    }

    .game-container {
        padding: 5px;
        gap: 10px;
    }

    .chessboard {
        border-width: 6px;
    }

    .controls {
        padding: 15px;
    }

    .buttons {
        grid-template-columns: 1fr;
    }

    .buttons button {
        padding: 16px;
        font-size: 18px;
    }

    .captured-piece {
        width: 28px;
        height: 28px;
        font-size: 16px;
    }

    .status-panel h2 {
        font-size: 1.2rem;
    }

    .turn-red,
    .turn-black {
        font-size: 1.1rem;
    }

    #game-status {
        font-size: 0.9rem;
    }
}

@media (max-width: 480px) {
    :root {
        --piece-size: 32px;
        --cell-size: 38px;
        --board-padding: 16px;
    }

    .piece {
        font-size: 18px;
        /* 移除强制最小尺寸，避免棋子重叠 */
    }

    .header {
        margin-bottom: 8px;
        padding: 6px 0;
    }

    .header h1 {
        font-size: 1.3rem;
        letter-spacing: 0.03em;
    }

    body {
        font-size: 14px;
    }
}

@media (max-width: 360px) {
    :root {
        --piece-size: 28px;
        --cell-size: 34px;
        --board-padding: 14px;
    }

    .piece {
        font-size: 16px;
    }

    .header {
        margin-bottom: 6px;
        padding: 5px 0;
    }

    .header h1 {
        font-size: 1.1rem;
        letter-spacing: 0.02em;
    }

    .chessboard {
        border-width: 3px;
    }

    .captured-piece {
        width: 20px;
        height: 20px;
        font-size: 12px;
    }

    .game-container {
        padding: 8px;
    }

    .chessboard {
        border-width: 4px;
        box-shadow: 0 5px 10px rgba(0, 0, 0, 0.4), inset 0 0 15px rgba(0, 0, 0, 0.3);
    }

    .controls {
        padding: 12px;
    }

    .buttons button {
        padding: 14px;
        font-size: 16px;
    }

    .captured-piece {
        width: 24px;
        height: 24px;
        font-size: 14px;
    }

    .status-panel h2 {
        font-size: 1.1rem;
    }

    .turn-red,
    .turn-black {
        font-size: 1rem;
    }
}

/* 触摸设备优化 */
@media (hover: none) and (pointer: coarse) {
    .piece {
        cursor: default;
        -webkit-tap-highlight-color: transparent;
    }

    .buttons button {
        cursor: default;
        -webkit-tap-highlight-color: rgba(255, 215, 0, 0.3);
        transition: background-color 0.1s;
    }

    .buttons button:active {
        background-color: #8b4513;
        transform: none;
    }

    /* 移除强制增大触摸目标，避免视觉上过大 */
    .piece {
        cursor: default;
        -webkit-tap-highlight-color: transparent;
    }

    .buttons button {
        min-height: 48px;
        cursor: default;
        -webkit-tap-highlight-color: rgba(255, 215, 0, 0.3);
    }

    /* 防止页面弹性滚动 */
    .game-container {
        overscroll-behavior: none;
    }

    /* 优化选择框触摸体验 */
    select {
        -webkit-appearance: none;
        appearance: none;
        background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='m6 8 4 4 4-4'/%3e%3c/svg%3e");
        background-position: right 0.5rem center;
        background-repeat: no-repeat;
        background-size: 1.5em 1.5em;
        padding-right: 2.5rem;
    }
}

/* 横屏手机优化 */
@media screen and (max-height: 500px) and (orientation: landscape) {
    .game-container {
        flex-direction: row;
        padding: 5px;
        gap: 10px;
    }

    .main-content {
        flex-direction: row;
        gap: 10px;
    }

    .controls {
        min-width: 180px;
        max-width: 200px;
        padding: 10px;
    }

    .chessboard {
        transform: scale(0.7);
        transform-origin: center;
        margin: 0;
    }

    .buttons {
        display: flex;
        flex-direction: column;
    }

    .buttons button {
        flex: 1;
        margin-bottom: 5px;
    }

    .captured-pieces {
        height: 30px;
        min-height: 30px;
    }

    .captured-piece {
        width: 20px;
        height: 20px;
        font-size: 12px;
    }
}