/* 基础重置和全局样式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Microsoft YaHei', Arial, sans-serif;
    /* 使用背景图片 */
    background: url('../images/background.png') no-repeat center center fixed;
    background-size: cover;
    height: 100vh;
    overflow: hidden;
    touch-action: manipulation;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}



/* 游戏容器 */
.game-container {
    width: 100%;
    height: 100vh;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* 屏幕切换系统 */
.screen {
    position: absolute;
    width: 100%;
    height: 100%;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(0, 0, 0, 0.5); /* 添加半透明背景 */
    z-index: 100; /* 确保在背景之上 */
    overflow-y: auto; /* 允许滚动 */
}

.screen.active {
    display: flex;
    animation: fadeIn 0.5s ease-out;
}

.screen.overlay {
    background-color: rgba(0, 0, 0, 0.7);
}

/* 开始界面样式 */
#startScreen .title {
    text-align: center;
    margin-bottom: 40px;
}

#startScreen h1 {
    font-size: 8vw;
    color: white;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
    margin-bottom: 10px;
}

#startScreen p {
    font-size: 4vw;
    color: rgba(255, 255, 255, 0.9);
}

#startScreen .buttons {
    display: flex;
    flex-direction: column;
    gap: 4vw;
    width: 100%;
    max-width: 300px;
}

/* 难度选择界面样式 */
#difficultyScreen .title {
    text-align: center;
    margin-bottom: 30px;
}

#difficultyScreen h2 {
    font-size: 2rem;
    color: white;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
    margin-bottom: 10px;
}

#difficultyScreen p {
    font-size: 1rem;
    color: rgba(255, 255, 255, 0.9);
}

#difficultyScreen .buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
    max-width: 300px;
}

.difficulty-info {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    width: 100%;
    max-width: 500px;
    margin-top: 20px;
}

.info-card {
    background: rgba(255, 255, 255, 0.9);
    padding: 15px;
    border-radius: 10px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
    text-align: center;
}

.info-card strong {
    display: block;
    font-size: 1.1rem;
    color: #333;
    margin-bottom: 5px;
}

.info-card p {
    font-size: 0.9rem;
    color: #666;
    margin: 0;
}

/* 按钮样式 */
.btn {
    padding: 4vw 6vw;
    border: none;
    border-radius: 10vw;
    font-size: 4vw;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    text-align: center;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

.btn:active {
    transform: translateY(0);
}

.btn.primary {
    background: linear-gradient(45deg, #ff6b6b, #ffa502);
    color: white;
}

.btn.secondary {
    background: linear-gradient(45deg, #4ecdc4, #44a08d);
    color: white;
}

.btn.small {
    padding: 2.5vw 5vw;
    font-size: 3.5vw;
}

/* 自定义关卡界面 */
.custom-container {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 20px;
    padding: 30px;
    width: 100%;
    max-width: 500px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.custom-container h2 {
    color: #333;
    margin-bottom: 25px;
    text-align: center;
    font-size: 1.8rem;
}

.custom-form {
    margin-bottom: 30px;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-weight: bold;
    color: #555;
    margin-bottom: 8px;
    font-size: 1rem;
}

.form-group select,
.form-group input[type="number"] {
    width: 100%;
    padding: 10px;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-size: 1rem;
    transition: border-color 0.3s;
}

.form-group select:focus,
.form-group input[type="number"]:focus {
    outline: none;
    border-color: #667eea;
}

.form-group input[type="range"] {
    width: 100%;
    margin: 10px 0;
}

.form-group span {
    display: block;
    text-align: center;
    color: #667eea;
    font-weight: bold;
    font-size: 1.1rem;
}

.custom-buttons {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

/* 移动翻牌游戏样式 */
.game-board.moving-mode {
    position: relative;
    width: 90%; /* 使用百分比宽度 */
    max-width: 500px; /* 最大宽度限制 */
    min-height: 600px; /* 最小高度 */
    height: 80vh; /* 使用视口高度百分比 */
    max-height: 900px; /* 最大高度限制 */
    margin: 10px auto; /* 居中显示 */
    overflow: hidden; /* 隐藏溢出内容 */
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    border-radius: 15px;
    padding: 20px;
    display: block;
    box-sizing: border-box;
}

/* 危险线 - 火焰效果 */
.danger-line {
    position: absolute;
    left: 0;
    right: 0;
    height: 5px;
    background: linear-gradient(to right, 
        #ff0000 0%, 
        #ff4500 30%, 
        #ff8c00 60%, 
        #ffff00 100%);
    box-shadow: 
        0 0 20px rgba(255, 69, 0, 0.9),
        0 0 40px rgba(255, 140, 0, 0.7),
        0 0 60px rgba(255, 255, 0, 0.5);
    z-index: 100;
    animation: flame-flicker 0.1s infinite alternate;
    border-radius: 2px;
}

@keyframes flame-flicker {
    0% {
        opacity: 0.9;
        box-shadow: 
            0 0 20px rgba(255, 69, 0, 0.9),
            0 0 40px rgba(255, 140, 0, 0.7),
            0 0 60px rgba(255, 255, 0, 0.5);
    }
    100% {
        opacity: 1;
        box-shadow: 
            0 0 30px rgba(255, 69, 0, 1),
            0 0 60px rgba(255, 140, 0, 0.9),
            0 0 90px rgba(255, 255, 0, 0.7);
    }
}

.danger-label {
    position: absolute;
    left: 10px;
    color: #ff0000;
    font-weight: bold;
    font-size: 14px;
    text-shadow: 0 0 10px rgba(255, 0, 0, 0.8);
    z-index: 101;
    white-space: nowrap;
}

/* 移动的卡片 */
.card.moving-card {
    position: absolute;
    width: 80px;
    height: 110px;
    cursor: pointer;
    transition: transform 0.3s;
    z-index: 1; /* 卡片在危险线下面 */
}

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

.card.moving-card.matched {
    opacity: 0;
    transform: scale(0);
    pointer-events: none;
    transition: all 0.3s ease-in;
}

/* 游戏界面样式 */
#gameScreen {
    flex-direction: column;
    padding: 10px;
}

.game-header {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(10px);
    border-radius: 15px;
    padding: 15px;
    margin-bottom: 15px;
}

.score-info {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    color: white;
    font-weight: bold;
    justify-content: center;
}

.score-info span {
    background: rgba(255, 255, 255, 0.2);
    padding: 5px 10px;
    border-radius: 10px;
    min-width: 80px;
    text-align: center;
}

.game-controls-top {
    display: flex;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
}

/* 游戏棋盘 */
.game-board {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 2vw;
    width: 90vw;
    max-width: 800px;
    aspect-ratio: 2;
    margin: 2vw 0;
    perspective: 1000px;
}

/* 8张牌的布局 - 两行四列 */
.game-board.eight-cards {
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(2, 1fr);
}

/* 12张牌的布局 - 三行四列 */
.game-board.twelve-cards {
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(3, 1fr);
}

/* 16张牌的布局 - 四行四列 */
.game-board.sixteen-cards {
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
}

.card {
    aspect-ratio: 3/4;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.6s;
    cursor: pointer;
    border-radius: 10px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

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

.card.matched {
    /* 匹配成功后完全消失 */
    opacity: 0;
    transform: scale(0);
    pointer-events: none; /* 禁用点击 */
    transition: all 0.5s ease-in;
}

/* 不再需要 matchedPulse 动画，因为卡片会直接消失 */

/* 已匹配的卡片正面不再需要特殊样式，因为会消失 */

.card-front, .card-back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.card-front {
    background: linear-gradient(45deg, #ffd89b, #19547b);
    transform: rotateY(180deg);
    padding: 2vw;
    text-align: center;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.card-back {
    background: linear-gradient(45deg, #667eea, #764ba2); /* fallback */
    background: url('../images/paibei.png') no-repeat center center;
    background-size: cover;
    border: 0.3vw solid white;
}

.card-image {
    width: 90%;
    height: 60%;
    object-fit: cover;
    border-radius: 1vw;
    margin-bottom: 2vw;
    background-color: white;
}

.card-name {
    font-size: 5vw;
    font-weight: bold;
    color: white;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
    margin-bottom: 1.5vw;
    line-height: 1.2;
    margin-top: 1vw;
}

.card-effect {
    font-size: 3.5vw;
    color: rgba(255, 255, 255, 0.9);
    line-height: 1.3;
    text-align: center;
    width: 100%;
}

/* 游戏控制按钮 */
.game-controls {
    display: flex;
    gap: 15px;
    margin-top: 15px;
}

/* 答题界面样式 */
#quizScreen {
    z-index: 150;
}

.quiz-box {
    background: white;
    border-radius: 20px;
    padding: 30px;
    width: 90%;
    max-width: 600px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.quiz-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
    padding-bottom: 20px;
    border-bottom: 2px solid #eee;
}

.quiz-header h2 {
    color: #333;
    font-size: 1.8rem;
    margin: 0;
}

.quiz-progress {
    background: linear-gradient(45deg, #667eea, #764ba2);
    color: white;
    padding: 8px 20px;
    border-radius: 20px;
    font-weight: bold;
    font-size: 1rem;
}

.quiz-question {
    font-size: 1.3rem;
    color: #333;
    margin-bottom: 25px;
    line-height: 1.6;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 10px;
}

.quiz-options {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-bottom: 25px;
}

.quiz-option {
    padding: 18px 25px;
    background: white;
    border: 2px solid #e9ecef;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 1rem;
    color: #333;
    text-align: left;
}

.quiz-option:hover {
    border-color: #667eea;
    background: #f8f9fa;
}

.quiz-option.selected {
    border-color: #667eea;
    background: #667eea;
    color: white;
}

.quiz-option.correct {
    border-color: #28a745;
    background: #28a745;
    color: white;
}

.quiz-option.wrong {
    border-color: #dc3545;
    background: #dc3545;
    color: white;
}

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

/* 结果界面样式 */
.result-container {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 20px;
    padding: 30px;
    width: 100%;
    max-width: 400px;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.result-container h2 {
    color: #333;
    margin-bottom: 25px;
    font-size: 2rem;
}

.result-stats {
    margin-bottom: 30px;
}

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

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

.stat-item .label {
    font-weight: bold;
    color: #666;
}

.stat-item .value {
    font-weight: bold;
    color: #667eea;
    font-size: 1.2rem;
}

.result-buttons {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

/* 暂停界面样式 */
.pause-menu {
    background: white;
    border-radius: 20px;
    padding: 30px;
    width: 100%;
    max-width: 350px;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.pause-menu h3 {
    margin-bottom: 25px;
    color: #333;
}

.pause-buttons {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

/* 响应式设计 - 横屏模式 */
@media (orientation: landscape) {
    .game-container {
        padding: 2vw;
    }
    
    #startScreen h1 {
        font-size: 6vw;
    }
    
    .game-board {
        width: 90vw;
        max-width: 95vw;
        gap: 2vw;
    }
    
    .card-front {
        padding: 1vw;
    }
    
    .card-name {
        font-size: 3.5vw;
    }
    
    .card-effect {
        font-size: 2.5vw;
    }
    
    .game-header {
        padding: 2vw;
        margin-bottom: 2vw;
    }
    
    .score-info {
        gap: 2vw;
    }
    
    .score-info span {
        padding: 1vw 2vw;
        border-radius: 2vw;
        min-width: 20vw;
    }
    
    .game-controls {
        margin-top: 2vw;
        gap: 2vw;
    }
    
    /* 横屏小屏幕设备 */
    @media (orientation: landscape) and (max-height: 600px) {
        .card-name {
            font-size: 3vw;
        }
        
        .card-effect {
            font-size: 2vw;
        }
        
        .game-board {
            gap: 1.5vw;
        }
    }
}

/* 响应式设计 - 小屏幕手机 */
@media (max-width: 480px) {
    .game-header {
        flex-direction: column;
        gap: 2vw;
        padding: 2vw;
    }
    
    .score-info {
        flex-wrap: wrap;
        justify-content: center;
        gap: 2vw;
    }
    
    .game-board {
        grid-template-columns: repeat(3, 1fr);
        max-width: 95vw;
        gap: 2vw;
    }
    
    #startScreen h1 {
        font-size: 8vw;
    }

    .quiz-box {
        padding: 5vw;
        width: 95%;
    }

    .quiz-header h2 {
        font-size: 5vw;
    }

    .quiz-question {
        font-size: 4vw;
        padding: 4vw;
    }

    .quiz-option {
        padding: 3vw 4.5vw;
        font-size: 3.5vw;
    }

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

    .result-container {
        padding: 5vw;
        margin: 2.5vw;
    }
}

/* 响应式设计 - 大屏幕 */
@media (min-width: 768px) {
    .game-board {
        grid-template-columns: repeat(5, 1fr);
        max-width: 600px;
    }
    
    #startScreen h1 {
        font-size: 8vw;
    }
    
    .btn {
        padding: 4vw 6vw;
        font-size: 4vw;
    }
}

/* 动画效果 */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes flipIn {
    from { transform: rotateY(90deg); opacity: 0; }
    to { transform: rotateY(0); opacity: 1; }
}





/* 加载动画 */
.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 1s ease-in-out infinite;
}

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

/* 触摸优化 */
@media (hover: none) and (pointer: coarse) {
    .btn:hover {
        transform: none;
    }

    .card {
        transition: transform 0.4s;
    }
}

/* 登录注册界面样式 */
.auth-container {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 20px;
    padding: 40px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    animation: fadeIn 0.5s ease-out;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 20px;
    margin-top: 30px;
}

.auth-form .form-group {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 5px;
    width: 100%;
}

.auth-form .form-group label {
    font-weight: bold;
    color: #333;
    font-size: 1rem;
}

.auth-form .form-group input {
    width: 100%;
    padding: 12px;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-size: 1rem;
    transition: border-color 0.3s;
}

.auth-form .form-group input:focus {
    outline: none;
    border-color: #667eea;
}

.code-input-container {
    display: flex;
    gap: 10px;
    width: 100%;
}

.code-input-container input {
    flex: 1;
}

.code-input-container .btn {
    white-space: nowrap;
    min-width: 120px;
    height: 46px;
}

.auth-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 10px;
}

.auth-buttons .btn.secondary {
    background: transparent;
    border: 1px solid #667eea;
    color: #667eea;
    font-size: 0.9rem;
    padding: 10px 15px;
}

.error-message {
    color: #dc3545;
    margin-top: 10px;
    font-size: 0.9rem;
    text-align: center;
}

/* 欢迎消息 */
.welcome-message {
    color: #667eea !important;
    font-weight: bold;
    margin-top: 10px !important;
    font-size: 1.1rem !important;
}

/* 排行榜页面样式 */
.leaderboard-container {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 20px;
    padding: 30px;
    width: 100%;
    max-width: 700px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    animation: fadeIn 0.5s ease-out;
}

.leaderboard-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 20px;
    justify-content: center;
}

.tab-btn {
    padding: 10px 15px;
    border: 2px solid #ddd;
    border-radius: 20px;
    background-color: white;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 0.9rem;
}

.tab-btn:hover {
    background-color: #f8f9fa;
    border-color: #667eea;
}

.tab-btn.active {
    background-color: #667eea;
    color: white;
    border-color: #667eea;
}

.leaderboard-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 20px;
    background: white;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.leaderboard-table th,
.leaderboard-table td {
    padding: 12px;
    text-align: center;
    border-bottom: 1px solid #e0e0e0;
}

.leaderboard-table th {
    background-color: #f8f9fa;
    font-weight: bold;
    color: #333;
}

.leaderboard-table tr:hover {
    background-color: #f8f9fa;
}

.leaderboard-buttons {
    margin-top: 20px;
}

/* 个人中心页面样式 */
.profile-container {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 20px;
    padding: 30px;
    width: 100%;
    max-width: 700px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    animation: fadeIn 0.5s ease-out;
}

.user-info {
    background-color: #f8f9fa;
    padding: 20px;
    border-radius: 10px;
    margin-bottom: 30px;
    text-align: left;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.user-info .info-item {
    display: flex;
    justify-content: space-between;
    margin-bottom: 10px;
    padding: 5px 0;
    border-bottom: 1px solid #e0e0e0;
}

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

.user-info .label {
    font-weight: bold;
    color: #333;
}

.user-info .value {
    color: #666;
}

.records-list {
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid #e0e0e0;
    border-radius: 10px;
    background: white;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.record-item {
    padding: 15px;
    border-bottom: 1px solid #e0e0e0;
    text-align: left;
    transition: background-color 0.3s;
}

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

.record-item:hover {
    background-color: #f8f9fa;
}

.record-item .record-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 5px;
}

.record-item .game-mode {
    font-weight: bold;
    color: #333;
}

.record-item .record-stats {
    display: flex;
    gap: 20px;
    font-size: 0.9rem;
    color: #666;
}

.profile-buttons {
    margin-top: 20px;
}

/* 响应式设计 - 登录注册和个人中心 */
@media (max-width: 480px) {
    .auth-container {
        padding: 30px;
        max-width: 95%;
    }
    
    .auth-buttons {
        flex-direction: column;
    }
    
    .auth-buttons .btn {
        width: 100%;
    }
    
    .leaderboard-container,
    .profile-container {
        padding: 20px;
        max-width: 95%;
    }
    
    .leaderboard-tabs {
        flex-direction: column;
        align-items: center;
    }
    
    .tab-btn {
        width: 100%;
        max-width: 200px;
    }
    
    .leaderboard-table th,
    .leaderboard-table td {
        padding: 8px;
        font-size: 0.8rem;
    }
    
    .record-item .record-stats {
        flex-direction: column;
        gap: 5px;
        font-size: 0.8rem;
    }
}