body {
    font-family: Arial, sans-serif;
    background-color: #2c3e50;
    margin: 0;
    padding: 0;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

#game-container {
    width: 100vw;
    height: 100vh;
    background-color: #34495e;
    display: flex;
    justify-content: space-between;
    padding: 20px;
    box-sizing: border-box;
}

#left-area {
    width: 150px;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    height: 100%;
}

.card-stack {
    width: 100px;
    height: 150px;
    background-color: #fff;
    border: 2px solid #2c3e50;
    border-radius: 10px;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.5), 0 0 0 5px #fff, 0 0 0 10px #2c3e50;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #2c3e50;
    font-size: 14px;
    position: relative;
}

.card-stack::before {
    content: "";
    position: absolute;
    top: 5px;
    left: 5px;
    right: 5px;
    bottom: 5px;
    border: 2px solid #2c3e50;
    border-radius: 5px;
}

#deck {
    margin-bottom: 20px;
    position: relative;
    width: 100px;
    height: 150px;
    border: 2px solid #fff;
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: #fff;
    font-size: 14px;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
}

#deck[data-count="0"] {
    background-color: transparent;
    border: 2px dashed #fff;
    box-shadow: none;
}

#deck:not([data-count="0"]) {
    background-color: #3498db;
    background-image: 
        radial-gradient(circle at 50% 50%, #fff 2px, transparent 2px),
        radial-gradient(circle at 50% 50%, #fff 1px, transparent 1px);
    background-size: 20px 20px, 10px 10px;
    background-position: 0 0;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
}

#deck::after {
    content: attr(data-count);
    font-size: 36px;
    font-weight: bold;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

#deck[data-count="0"]::after {
    content: none;
}

#discard-pile {
    margin-bottom: 20px;
}

#main-area {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    margin-left: 20px;
    margin-right: 20px;
}

#scoreboard {
    display: flex;
    justify-content: flex-end;
    gap: 20px;
    margin-bottom: 20px;
}

.score {
    font-size: 18px;
    color: #ecf0f1;
}

#game-area {
    position: relative; /* 添加这一行 */
    display: flex;
    flex-direction: column;
    justify-content: center;
    height: 80vh;
}

.hand {
    display: flex;
    justify-content: center;
    height: 150px;
    margin: 15px 0;
    gap: 10px;
}

#battlefields {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: nowrap;
    gap: 10px;
    margin: 20px 0;
    overflow-x: auto;
    padding: 10px 0;
}

.battlefield {
    flex: 0 0 auto;
    width: 130px;
    height: 200px;
    background-color: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 10px;
    transition: box-shadow 0.3s ease; /* 添加过渡效果 */
}

.battlefield:hover {
    box-shadow: 0 0 0 3px rgba(231, 76, 60, 0.5); /* 添加淡红色描边 */
}

.buffer-zone {
    height: 60px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.buffer-zone .card {
    width: 80px;
    height: 120px;
    font-size: 16px;
}

.battlefield-cards {
    height: 60px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.card {
    width: 100px;
    height: 150px;
    background-color: #fff;
    border-radius: 5px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: bold;
    cursor: pointer;
    transition: transform 0.3s ease;
    user-select: none;
    position: relative;
}

.card-value {
    font-size: 36px;
}

.card-suit {
    font-size: 24px;
    position: absolute;
}

.card-suit.top-left {
    top: 5px;
    left: 5px;
}

.card-suit.bottom-right {
    bottom: 5px;
    right: 5px;
}

.card:hover {
    transform: translateY(-10px);
}

.card.red {
    color: #e74c3c;
}

.card.black {
    color: #2c3e50;
}

#controls {
    position: absolute;
    bottom: 20px;
    right: 20px;
    display: flex;
    flex-direction: column; /* 改为竖向排列 */
    gap: 10px;
    z-index: 1001;
}

#controls button {
    width: 120px; /* 设置固定宽度 */
    padding: 10px;
    font-size: 16px;
    cursor: pointer;
    white-space: nowrap;
    position: relative;
    z-index: 1002;
}

button {
    background-color: #3498db;
    color: #fff;
    border: none;
    padding: 10px 20px;
    font-size: 16px;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.3s ease;
    margin: 0 10px;
}

button:hover {
    background-color: #2980b9;
}

.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.4);
}

.modal-content {
    background-color: #fefefe;
    margin: 10% auto; /* 调整位置到屏幕中央 */
    padding: 20px;
    border: 1px solid #888;
    width: 80%;
    max-width: 600px;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
    border-radius: 15px; /* 添加圆角 */
}

#rules-text {
    white-space: pre-wrap;
    word-wrap: break-word;
    font-size: 14px;
    line-height: 1.5;
}

.close {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
}

.close:hover,
.close:focus {
    color: black;
    text-decoration: none;
    cursor: pointer;
}

#show-rules {
    position: static;
    bottom: auto;
    right: auto;
}

.card.back {
    background-color: #3498db;
    background-image: 
        radial-gradient(circle at 50% 50%, #fff 2px, transparent 2px),
        radial-gradient(circle at 50% 50%, #fff 1px, transparent 1px);
    background-size: 20px 20px, 10px 10px;
    background-position: 0 0;
    border: 2px solid #fff;
    border-radius: 10px;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    color: #fff;
    font-size: 14px;
    position: relative;
    overflow: hidden;
}

/* 移除内部白色方框 */
.card.back::before {
    content: none;
}

#discard-pile {
    width: 100px;
    height: 150px;
    background-color: #fff;
    border: 2px solid #2c3e50;
    border-radius: 10px;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.5), 0 0 0 5px #fff, 0 0 0 10px #2c3e50;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #2c3e50;
    font-size: 14px;
    position: relative;
}

#discard-pile::before {
    content: "";
    position: absolute;
    top: 5px;
    left: 5px;
    right: 5px;
    bottom: 5px;
    border: 2px solid #2c3e50;
    border-radius: 5px;
}

.battlefield .card-container {
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
}

.battlefield .player1-buffer .card:hover {
    transform: scale(2) translateY(-20px);
    z-index: 10;
}

.battlefield .player2-buffer .card:hover {
    transform: scale(2) translateY(20px);
    z-index: 10;
}

.battlefield .card {
    width: 40px;
    height: 60px;
    font-size: 10px;
    margin-right: 5px;
    transition: transform 0.3s ease, z-index 0.3s ease;
    position: relative;
    overflow: visible;
}

.battlefield .card:hover {
    transform: scale(2) translateY(-20px);
    z-index: 10;
}

.battlefield .card .card-value {
    font-size: 20px;
}

.battlefield .card .card-suit {
    font-size: 14px;
}

.battlefield .card:last-child {
    margin-right: 0;
}

.card.selected {
    transform: translateY(-20px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

.winner-text {
    background-color: rgba(52, 152, 219, 0.8);
    color: #fff;
    padding: 5px 10px;
    border-radius: 5px;
    font-weight: bold;
    text-align: center;
    margin-top: 5px;
}

/* 添加到文件末尾 */

#ai-thinking {
    position: absolute;
    top: 5%; /* 保持原来的顶部位置 */
    right: calc(5% + 2230px); /* 向左调整 730px */
    display: flex;
    justify-content: center;
    align-items: center;
    width: 80px; /* 调整大小以匹配蓝色圆圈 */
    height: 80px; /* 调整大小以匹配蓝色圆圈 */
    color: #fff;
    font-size: 14px;
    z-index: 1000;
    background-color: #3498db; /* 使用与蓝色圆圈相同的颜色 */
    border-radius: 50%;
    overflow: hidden;
}

#ai-thinking.hidden {
    display: none;
}
.latest-card {
    box-shadow: 0 0 0 2px rgb(0, 255, 0);
}
.loader {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top: 4px solid #ffffff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* 添加文字样式 */
#ai-thinking span {
    position: relative;
    z-index: 1001;
    font-weight: bold;
    text-align: center;
    line-height: 1.2;
}

/* 移动端样式 */
@media screen and (max-width: 768px) {
    #game-container {
        flex-direction: column;
        height: 100vh;
        width: 100vw;
        padding: 10px;
        box-sizing: border-box;
    }

    #left-area {
        display: none; /* 隐藏桌面端的牌库 */
    }

    #mobile-deck-count {
        display: block;
        position: absolute;
        top: 10px;
        left: 10px;
        color: #fff;
        font-size: 14px;
        z-index: 10;
    }

    #main-area {
        width: 100%;
        height: 100%;
        display: flex;
        flex-direction: column;
    }

    #scoreboard {
        position: absolute;
        top: 10px;
        right: 10px;
        flex-direction: column;
        align-items: flex-end;
    }

    #game-area {
        flex-direction: row;
        height: 100%;
        justify-content: space-between;
        align-items: center;
        position: relative;
    }

    #player2-hand, #player1-hand {
        flex-direction: column;
        height: 80vh;
        width: 60px;
        position: absolute;
        top: 50%;
        transform: translateY(-50%);
    }

    #player2-hand {
        left: 0;
    }

    #player1-hand {
        right: 0;
    }

    #battlefields {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
        align-items: center;
        width: calc(100% - 120px);
        height: 80vh;
        position: absolute;
        left: 47px; /* 原来是 60px，左移 7px */
        top: calc(50% - 45px); /* 原来是 -30px，再上移 5px */
        transform: translateY(-50%);
        overflow-y: auto; /* 添加垂直滚动 */
        overflow-x: hidden; /* 隐藏水平滚动条 */
        padding: 10px; /* 添加内边距以便于滚动 */
        -webkit-overflow-scrolling: touch; /* 为 iOS 设备添加平滑滚动 */
        scrollbar-width: thin; /* 为支持的浏览器设置细滚动条 */
        scrollbar-color: rgba(255, 255, 255, 0.5) transparent; /* 自定义滚动条颜色 */
    }

    #battlefields::-webkit-scrollbar {
        width: 6px; /* 设置滚动条宽度 */
    }
    #battlefields::-webkit-scrollbar-thumb {
        background-color: rgba(255, 255, 255, 0.5); /* 滚动条颜色 */
        border-radius: 3px; /* 圆角滚动条 */
    }

    .battlefield {
        width: 130px;
        height: 200px;
        margin: 0.5px; /* 原来是 5px，改为 2.5px 使间距更紧凑 */
        transform: none;
        flex-shrink: 0;
        padding: 10px;
        position: relative; /* 确保可以定位子元素 */
    }

    .battlefield-identifier {
        position: absolute;
        top: 5px;
        left: 5px;
        color: white;
        padding: 2px 5px;
        border-radius: 3px;
        font-size: 12px;
        z-index: 10;
        background-color: transparent; /* 移除背景色 */
        text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.8); /* 添加文字阴影以提高可读性 */
    }

    .battlefield .card {
        width: 40px;
        height: 60px;
        font-size: 10px;
    }

    .battlefield .card .card-value {
        font-size: 20px;
    }

    .battlefield .card .card-suit {
        font-size: 14px;
    }

    .buffer-zone {
        height: 60px;
    }

    .battlefield-cards {
        height: 60px;
    }

    #controls {
        position: fixed;
        bottom: 10px;
        left: 10px; /* 改为左下角 */
        flex-direction: column;
    }

    #controls button {
        margin: 5px 0;
        width: 60px; /* 缩短一半 */
        font-size: 12px; /* 减小字体大小以适应按钮 */
        padding: 5px; /* 减小内边距 */
    }

    .card {
        width: 40px;
        height: 60px;
        font-size: 10px;
    }

    .card-value {
        font-size: 16px;
    }

    .card-suit {
        font-size: 12px;
    }

    #ai-thinking {
        top: 40px; /* 调整位置，避免遮挡牌堆提示 */
        left: 10px; /* 靠左 */
        width: 50px; /* 稍微缩小 */
        height: 50px;
    }

    #mobile-deck-count {
        top: 10px;
        left: 10px;
    }

    /* ... 保留其他移动端样式 ... */

    #player1-hand .card:hover, #player1-hand .card.selected {
        transform: translateX(-10px); /* 改为向左移动 */
    }

    #player2-hand .card {
        pointer-events: none; /* 禁止与AI手牌交互 */
    }
}

/* 默认隐藏移动端元素 */
.mobile-only {
    display: none;
}

#random-battlefield-cards {
    position: fixed;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 1000;
}

#random-battlefield-cards .card {
    width: 100px;
    height: 140px;
    position: relative;
}

.battlefield-label {
    position: absolute;
    bottom: 5px;
    left: 50%;
    transform: translateX(-50%);
    background-color: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 2px 5px;
    border-radius: 3px;
    font-size: 12px;
}

.hidden {
    display: none !important;
}