/* 全局样式和背景 */
body {
    margin: 0;
    padding: 0;
    min-height: 100vh;
    background: linear-gradient(135deg, #1a2a6c, #b21f1f, #fdbb2d);
    font-family: "Microsoft YaHei", sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    overflow-x: hidden;
}

/* 动态背景效果 */
body::before,
body::after {
    content: '';
    position: fixed;
    width: 300vw;
    height: 300vh;
    top: -100vh;
    left: -100vw;
    z-index: -1;
    background: radial-gradient(circle, rgba(255,255,255,0.1) 10%, transparent 40%);
    animation: rotate 60s linear infinite;
}

body::after {
    animation: rotate 40s linear infinite reverse;
    opacity: 0.5;
}

@keyframes rotate {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* 游戏容器样式优化 */
.game-container {
    padding: 20px;
    max-width: 800px;
    margin: 0 auto;
    text-align: center;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 15px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(10px);
}

/* 游戏信息栏样式 */
.game-info {
    display: flex;
    justify-content: space-around;
    margin-bottom: 20px;
    padding: 15px;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.game-info span {
    font-size: 1.2em;
    font-weight: bold;
    color: #333;
    text-shadow: 1px 1px 2px rgba(255, 255, 255, 0.5);
}

/* 卡片网格样式 */
#gameGrid {
    display: grid;
    gap: 12px;
    justify-content: center;
    align-items: center;
    width: 100%;
    margin: 0 auto;
    padding: 10px;
    transition: max-width 0.3s ease;
}

/* 卡片样式优化 */
.card {
    aspect-ratio: 3/4;
    cursor: pointer;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.6s;
    width: 100%;
    min-height: 60px;
    max-height: 100px;
}

.card:hover:not(.flipped):not(.matched) {
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
}

.card-inner {
    position: absolute;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
    transition: transform 0.6s;
}

.card.flipped .card-inner {
    transform: rotateY(180deg);
}

/* 卡片面板样式 */
.card-front,
.card-back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2em;
    font-weight: bold;
    border-radius: 8px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.card-front {
    background: linear-gradient(135deg, #6e8efb, #a777e3);
    color: white;
}

.card-back {
    background: white;
    color: #333;
    transform: rotateY(180deg);
}

/* 按钮样式优化 */
.game-button {
    margin: 20px 10px;
    padding: 10px 25px;
    font-size: 1.1em;
    border: none;
    border-radius: 25px;
    background: linear-gradient(135deg, #6e8efb, #a777e3);
    color: white;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(110, 142, 251, 0.3);
}

/* 结束游戏按钮特殊样式 */
#endGameBtn {
    background: linear-gradient(135deg, #ff6b6b, #ff4757);
    box-shadow: 0 4px 15px rgba(255, 107, 107, 0.3);
}

#endGameBtn:hover {
    background: linear-gradient(135deg, #ff4757, #ff6b6b);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(255, 107, 107, 0.4);
}

/* 重新开始按钮特殊样式 */
#resetBtn {
    background: linear-gradient(135deg, #ffa502, #ff7f50);
    box-shadow: 0 4px 15px rgba(255, 165, 2, 0.3);
}

#resetBtn:hover {
    background: linear-gradient(135deg, #ff7f50, #ffa502);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(255, 165, 2, 0.4);
}

/* 下一关按钮保持原样，但微调渐变 */
#nextLevelBtn {
    background: linear-gradient(135deg, #26de81, #2bcbba);
    box-shadow: 0 4px 15px rgba(38, 222, 129, 0.3);
}

#nextLevelBtn:hover {
    background: linear-gradient(135deg, #2bcbba, #26de81);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(38, 222, 129, 0.4);
}

/* 按钮通用悬浮和激活状态 */
.game-button:hover {
    transform: translateY(-2px);
}

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

/* 匹配动画优化 */
@keyframes matchSuccess {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

.card.matched {
    animation: matchSuccess 0.5s ease-out;
    opacity: 0.8;
}

/* 响应式设计优化 */
@media screen and (max-width: 768px) {
    .game-container {
        padding: 15px;
        margin: 10px;
    }

    .game-info {
        flex-direction: column;
        gap: 10px;
    }

    #gameGrid {
        gap: 10px;
    }

    .card {
        min-height: 50px;
    }
}

@media screen and (max-width: 480px) {
    .game-container {
        padding: 10px;
    }

    #gameGrid {
        gap: 8px;
    }

    .card {
        min-height: 40px;
    }

    .card-front,
    .card-back {
        font-size: 0.9em;
    }
}

/* 添加过关消息样式 */
.level-up-message {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(110, 142, 251, 0.9);
    color: white;
    padding: 15px 30px;
    border-radius: 25px;
    font-size: 1.2em;
    font-weight: bold;
    animation: fadeInOut 2s ease-in-out;
    z-index: 1000;
}

@keyframes fadeInOut {
    0% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.8);
    }

    20% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }

    80% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }

    100% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.8);
    }
}

/* 结算弹窗样式 */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: white;
    padding: 30px;
    border-radius: 15px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
    text-align: center;
    max-width: 400px;
    width: 90%;
}

.modal-content h2 {
    color: #333;
    margin-bottom: 20px;
    font-size: 1.5em;
}

.result-container {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 10px;
    margin-bottom: 20px;
}

.result-item {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid #eee;
}

.result-item:last-child {
    border-bottom: none;
}

.result-item .label {
    color: #666;
}

.result-item .value {
    color: #333;
    font-weight: bold;
}

.modal-buttons {
    display: flex;
    justify-content: center;
    gap: 15px;
}

/* 分享按钮特殊样式 */
#shareBtn {
    background: linear-gradient(135deg, #4CAF50, #45a049);
}

#shareBtn:hover {
    box-shadow: 0 6px 20px rgba(76, 175, 80, 0.4);
}

/* 分享预览样式优化 */
.share-preview {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    padding: 20px;
    backdrop-filter: blur(5px);
    box-sizing: border-box;
}

.share-preview img {
    max-width: 90%;
    max-height: 75vh;
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: 15px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    margin-bottom: 30px;
    animation: fadeIn 0.5s ease-out;
}

.preview-buttons {
    display: flex;
    gap: 20px;
}

.preview-buttons .game-button {
    margin: 0;
    padding: 12px 30px;
    font-size: 1.2em;
    min-width: 120px;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* 移动端适配 */
@media screen and (max-width: 480px) {
    .share-preview {
        padding: 10px;
    }
    
    .share-preview img {
        max-width: 95%;
        max-height: 70vh;
        margin-bottom: 20px;
    }
    
    .preview-buttons {
        flex-direction: column;
        gap: 10px;
    }
    
    .preview-buttons .game-button {
        padding: 10px 20px;
        font-size: 1em;
        min-width: 100px;
    }
}