* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #8B4513;
    --secondary-color: #D2691E;
    --board-color: #F4D03F;
    --text-color: #2C3E50;
    --red-piece: #E74C3C;
    --black-piece: #2C3E50;
    --highlight-color: #27AE60;
    --shadow-color: rgba(0, 0, 0, 0.2);
    --border-width: 8px;
    --cell-size: 50px;
    --board-width: calc(8 * var(--cell-size));
    --board-height: calc(9 * var(--cell-size));
}

body {
    font-family: 'Microsoft YaHei', '微软雅黑', Arial, sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    color: var(--text-color);
}

.container {
    text-align: center;
    background: white;
    padding: 2rem;
    border-radius: 1rem;
    box-shadow: 0 10px 30px var(--shadow-color);
}

.game-info {
    margin-bottom: 2rem;
}

h1 {
    font-size: 2.5rem;
    color: var(--primary-color);
    margin-bottom: 1rem;
    text-shadow: 2px 2px 4px var(--shadow-color);
}

#status {
    margin: 1rem 0;
    font-size: 1.2rem;
    color: var(--text-color);
    font-weight: bold;
    padding: 0.5rem 1rem;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 0.5rem;
    box-shadow: 0 2px 5px var(--shadow-color);
}

.controls {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin: 1rem 0;
}

.controls button {
    padding: 0.8rem 1.5rem;
    font-size: 1rem;
    cursor: pointer;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 0.5rem;
    transition: all 0.3s ease;
    box-shadow: 0 2px 5px var(--shadow-color);
}

.controls button:hover {
    background: var(--secondary-color);
    transform: translateY(-2px);
    box-shadow: 0 4px 8px var(--shadow-color);
}

.controls button:active {
    transform: translateY(0);
}

/* 棋盘整体样式 */
#chessboard {
    width: calc(8 * var(--cell-size));
    height: calc(9 * var(--cell-size));
    background-color: var(--board-color);
    position: relative;
    margin: 0 auto;
    border: var(--border-width) solid var(--primary-color);
    border-radius: 4px;
    box-shadow: 0 8px 16px var(--shadow-color);
}

.board-grid {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    outline: 2px dashed red;
    pointer-events: none;
}

/* 横线 */
.board-grid .horizontal-line {
    position: absolute;
    left: 0;
    width: 100%;
    height: 1px;
    background-color: var(--primary-color);
}

/* 纵线 */
.board-grid .vertical-line {
    position: absolute;
    top: 0;
    height: 100%;
    width: 1px;
    background-color: var(--primary-color);
}

/* This rule should define the thickness of the river boundary if needed, otherwise can be removed if no special thickness */
.horizontal-line.river-boundary-line {
    height: 2px;
    background-color: var(--primary-color);
}

/* 九宫格区域 */
.palace {
    position: absolute;
    width: calc(2 * var(--cell-size));
    height: calc(2 * var(--cell-size));
    z-index: 2;
    pointer-events: none;
}
.red-palace {
    bottom: 0;
    left: calc(3 * var(--cell-size));
}
.black-palace {
    top: 0;
    left: calc(3 * var(--cell-size));
}

/* 九宫格斜线 */
.palace-diagonal {
    position: absolute;
    background-color: var(--primary-color);
    z-index: 3;
    height: 1px;
    width: calc(var(--cell-size) * 2.7); /* Theoretical length */
    pointer-events: none;
}

/* 红方九宫格斜线 */
.red-palace-diagonal-1 { /* BL to TR */
    bottom: 0;
    left: calc(2.87 * var(--cell-size));
    transform-origin: bottom left;
    transform: rotate(-45deg); /* Maintained tuned angle */
}
.red-palace-diagonal-2 { /* BR to TL */
    bottom: 0;
    right: calc(2.87 * var(--cell-size));
    transform-origin: bottom right;
    transform: rotate(45deg); /* Maintained tuned angle */
}

/* 黑方九宫格斜线 */
.black-palace-diagonal-1 { /* TL to BR */
    top: 0;
    left: calc(2.87 * var(--cell-size));
    transform-origin: top left;
    transform: rotate(45deg); /* Maintained tuned angle */
}
.black-palace-diagonal-2 { /* TR to BL */
    top: 0;
    right: calc(2.87 * var(--cell-size));
    transform-origin: top right;
    transform: rotate(-45deg); /* Maintained tuned angle */
}

/* River text style */
.river {
    position: absolute;
    width: 100%;
    height: var(--cell-size);
    top: calc(4 * var(--cell-size));
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 24px;
    color: var(--primary-color);
    font-weight: bold;
    text-shadow: 1px 1px 2px rgba(255, 255, 255, 0.5);
    z-index: 0; /* Ensured original z-index */
    pointer-events: none;
}

.piece {
    position: absolute;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 2px solid var(--primary-color);
    background: white;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    font-weight: bold;
    font-size: 1.2rem;
    transition: all 0.3s ease;
    box-shadow: 0 2px 5px var(--shadow-color);
    z-index: 10;
    transform: translate(-50%, -50%);
    margin: 0;
    padding: 0;
}

.piece.red {
    color: var(--red-piece);
    background: linear-gradient(135deg, #fff5f5 0%, #ffe3e3 100%);
}

.piece.black {
    color: var(--black-piece);
    background: linear-gradient(135deg, #f5f5f5 0%, #e3e3e3 100%);
}

.piece:hover {
    transform: translate(-50%, -50%) scale(1.1);
    box-shadow: 0 4px 8px var(--shadow-color);
}

.piece.selected {
    background: var(--highlight-color);
    color: white;
    transform: translate(-50%, -50%) scale(1.1);
    box-shadow: 0 0 15px var(--highlight-color);
}

.valid-move {
    position: absolute;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--highlight-color);
    opacity: 0.6;
    pointer-events: none;
    z-index: 20;
    animation: pulse 1.5s infinite;
    transform: translate(-50%, -50%);
    margin: 0;
    padding: 0;
}

@keyframes pulse {
    0% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 0.6;
    }
    50% {
        transform: translate(-50%, -50%) scale(1.2);
        opacity: 0.4;
    }
    100% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 0.6;
    }
}

/* 添加响应式设计 */
@media (max-width: 600px) {
    :root {
        --cell-size: 40px;
    }
    
    .container {
        padding: 1rem;
    }

    .piece {
        width: 36px;
        height: 36px;
        font-size: 1rem;
    }

    h1 {
        font-size: 2rem;
    }
}

/* 主菜单样式 */
.menu-options {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin: 2rem auto;
    max-width: 300px;
}

.menu-button {
    padding: 1rem 2rem;
    font-size: 1.2rem;
    cursor: pointer;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 0.5rem;
    transition: all 0.3s ease;
    box-shadow: 0 4px 8px var(--shadow-color);
}

.menu-button:hover {
    background: var(--secondary-color);
    transform: translateY(-2px);
    box-shadow: 0 6px 12px var(--shadow-color);
}

.menu-button:active {
    transform: translateY(0);
}

.menu-button.secondary {
    background: #6c757d;
    font-size: 1rem;
    padding: 0.7rem 1.5rem;
    margin-top: 1rem;
}

.menu-button.secondary:hover {
    background: #5a6268;
}

.controls .secondary {
    background: #6c757d;
    font-size: 0.9rem;
}