body {
    background-image: url('img2/bj2.jpg');
    background-size: cover;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 100vh;
    margin: 0;
    font-family: Arial, sans-serif;
    color: blue;
}

.title {
    font-size: 24px;
    color: blue;
    text-align: center;
    margin-bottom: 20px;
}

.game-board {
    display: grid;
    grid-template-columns: repeat(8, 120px);
    grid-gap: 10px;
    margin-bottom: 20px;
}

.card {
    width: 120px;
    height: 120px;
    position: relative;
    perspective: 1000px;
    cursor: pointer;
}

.card .front,
.card .back {
    width: 100%;
    height: 100%;
    position: absolute;
    backface-visibility: hidden;
    transition: transform 0.6s;
    border-radius: 10px;
}

.card .front {
    transform: rotateY(180deg);
    background-size: cover;
}

.card .back {
    background-image: url('img/bj.jpg');
    background-size: cover;
}

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

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

.card.matched {
    visibility: hidden;
    transition: visibility 0.5s;
}

.timer {
    font-size: 24px;
    text-align: center;
    color: blue;
}

#success-message {
    font-size: 24px;
    text-align: center;
    display: none;
}

#success-message.visible {
    display: block;
}

#action-button {
    font-size: 20px;
    padding: 10px 20px;
    margin-top: 10px;
    cursor: pointer;
    background-color: blue;
    color: white;
    border: none;
    border-radius: 5px;
}

#action-button:hover {
    background-color: darkblue;
}

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

.leaderboard-link a {
    color: blue;
    text-decoration: none;
    font-size: 18px;
}

.leaderboard-link a:hover {
    text-decoration: underline;
}

/* 模态框样式 */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal.hidden {
    display: none;
}

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

.modal-content h2 {
    color: blue;
    font-size: 28px;
    margin-bottom: 20px;
}

.modal-content p {
    color: #333;
    font-size: 18px;
    margin-bottom: 20px;
}

#username-input {
    width: 100%;
    padding: 12px 20px;
    font-size: 18px;
    border: 2px solid #ddd;
    border-radius: 8px;
    margin-bottom: 20px;
    text-align: center;
    box-sizing: border-box;
}

#username-input:focus {
    outline: none;
    border-color: blue;
}

#start-game-btn {
    padding: 12px 40px;
    font-size: 20px;
    background-color: blue;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: background-color 0.3s;
}

#start-game-btn:hover {
    background-color: darkblue;
}

.hint {
    font-size: 14px;
    color: #999;
    margin-top: 15px;
}

#game-container {
    width: 100%;
    height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

#game-container.hidden {
    display: none;
}

/* ================================
   📱 移动端适配（响应式设计）
   ================================ */

/* 平板和手机通用优化 */
@media (max-width: 1024px) {
    .game-board {
        grid-template-columns: repeat(6, 100px);
        grid-gap: 8px;
    }
    
    .card {
        width: 100px;
        height: 100px;
    }
    
    .title {
        font-size: 20px;
    }
}

/* 手机端优化（横屏） */
@media (max-width: 768px) and (orientation: landscape) {
    body {
        height: 100vh;
        padding: 10px;
    }
    
    .game-board {
        grid-template-columns: repeat(8, 60px);
        grid-gap: 5px;
        margin-bottom: 10px;
    }
    
    .card {
        width: 60px;
        height: 60px;
    }
    
    .title {
        font-size: 14px;
        margin-bottom: 10px;
    }
    
    .timer {
        font-size: 16px;
        margin-bottom: 10px;
    }
    
    #success-message {
        font-size: 16px;
    }
    
    #action-button {
        font-size: 14px;
        padding: 8px 16px;
    }
    
    .modal-content {
        padding: 20px;
        max-width: 90%;
    }
    
    .modal-content h2 {
        font-size: 20px;
    }
    
    #username-input {
        font-size: 16px;
        padding: 10px;
    }
    
    #start-game-btn {
        font-size: 16px;
        padding: 10px 30px;
    }
}

/* 手机端优化（竖屏） */
@media (max-width: 768px) and (orientation: portrait) {
    body {
        height: auto;
        min-height: 100vh;
        padding: 10px;
        justify-content: flex-start;
        padding-top: 20px;
    }
    
    .game-board {
        grid-template-columns: repeat(4, 70px);
        grid-gap: 8px;
        margin-bottom: 15px;
    }
    
    .card {
        width: 70px;
        height: 70px;
    }
    
    .title {
        font-size: 16px;
        margin-bottom: 15px;
    }
    
    .timer {
        font-size: 18px;
        margin-bottom: 15px;
    }
    
    #success-message {
        font-size: 18px;
    }
    
    #action-button {
        font-size: 16px;
        padding: 10px 20px;
    }
    
    .modal-content {
        padding: 25px;
        width: 85%;
    }
    
    .modal-content h2 {
        font-size: 22px;
    }
    
    #username-input {
        font-size: 16px;
        padding: 10px;
    }
    
    #start-game-btn {
        font-size: 18px;
        padding: 12px 35px;
    }
}

/* 小屏手机（iPhone SE 等） */
@media (max-width: 375px) {
    .game-board {
        grid-template-columns: repeat(4, 60px);
        grid-gap: 6px;
    }
    
    .card {
        width: 60px;
        height: 60px;
    }
    
    .title {
        font-size: 14px;
    }
    
    .timer {
        font-size: 16px;
    }
    
    .modal-content {
        padding: 20px;
        width: 90%;
    }
    
    .modal-content h2 {
        font-size: 20px;
    }
}

/* 触摸设备优化 */
@media (hover: none) and (pointer: coarse) {
    .card {
        cursor: pointer;
        touch-action: manipulation;
    }
    
    #action-button,
    #start-game-btn {
        min-height: 44px; /* 符合移动端点击区域标准 */
    }
    
    .leaderboard-link a {
        min-height: 44px;
        display: inline-flex;
        align-items: center;
    }
}

/* 防止移动端双击缩放 */
* {
    touch-action: manipulation;
}

/* 排行榜移动端适配 */
@media (max-width: 768px) {
    .leaderboard-container {
        width: 95%;
        margin: 10px auto;
        padding: 15px;
    }
    
    .leaderboard-title {
        font-size: 24px;
    }
    
    .leaderboard-table {
        font-size: 14px;
    }
    
    .leaderboard-table th {
        padding: 10px 8px;
        font-size: 14px;
    }
    
    .leaderboard-table td {
        padding: 8px 5px;
    }
    
    .rank-badge {
        width: 24px;
        height: 24px;
        line-height: 24px;
        font-size: 12px;
    }
    
    .filter-btn {
        padding: 6px 12px;
        font-size: 12px;
        margin: 3px;
    }
    
    .back-btn {
        width: 180px;
        padding: 10px 20px;
        font-size: 16px;
    }
}

/* 排行榜表格横向滚动（超小屏幕） */
@media (max-width: 480px) {
    .leaderboard-table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
    }
}

/* 关卡导航 */
.level-nav {
    display: flex;
    gap: 10px;
    margin-top: 20px;
    flex-wrap: wrap;
    justify-content: center;
}

.level-btn {
    padding: 10px 20px;
    font-size: 16px;
    background-color: blue;
    color: white;
    text-decoration: none;
    border-radius: 5px;
    transition: background-color 0.3s;
}

.level-btn:hover {
    background-color: darkblue;
}

/* 移动端关卡导航优化 */
@media (max-width: 768px) {
    .level-nav {
        gap: 8px;
    }
    
    .level-btn {
        padding: 8px 15px;
        font-size: 14px;
    }
}
