* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'SimHei', 'Microsoft YaHei', sans-serif;
    -webkit-tap-highlight-color: transparent;
}

:root {
    font-size: 16px;
}

body {
    background: #1a120b;
    color: #e5d9b6;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    position: relative;
    padding: 1vh;
    touch-action: manipulation;
}

/* 简化的背景纹理 - 减少性能开销 */
body::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(45deg, rgba(26, 18, 11, 0.9) 0%, rgba(40, 30, 20, 0.9) 100%);
    z-index: -1;
}

.game-container {
    width: 98vw;
    height: 95vh;
    max-width: 87.5rem;
    background: rgba(40, 30, 20, 0.85);
    border-radius: 1.25rem;
    box-shadow: 0 0.625rem 1.875rem rgba(0, 0, 0, 0.7);
    padding: 1vh;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
    border: 0.125rem solid #5d4037;
}

/* 顶部装饰 */
.game-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 0.3125rem;
    background: linear-gradient(90deg, #d4af37, #ffd700, #d4af37);
    border-radius: 1.25rem 1.25rem 0 0;
}

.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1vh;
    padding-bottom: 1vh;
    border-bottom: 0.125rem solid #5d4037;
    flex-wrap: wrap;
    gap: 1vh;
    height: 15vh;
    min-height: 5rem;
    position: relative;
    padding-right: 60px; /* 为右上角退出按钮预留空间 */
}

.game-title {
    color: #ffd700;
    font-size: clamp(1.2rem, 4vw, 2.2rem);
    text-shadow: 0.1875rem 0.1875rem 0.375rem rgba(0, 0, 0, 0.7);
    letter-spacing: 0.125rem;
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.625rem;
    flex-shrink: 0;
    margin-left: 10px; /* 向左平移一点点 */
}

.game-title::before {
    content: '𓀀';
    font-size: clamp(1.2rem, 4vw, 2.2rem);
    color: #d4af37;
}

.game-promotion {
    flex: 1;
    text-align: center;
    font-size: clamp(0.8rem, 2.5vw, 1.2rem);
    color: #ffd700;
    font-weight: bold;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-left: 10px; /* 向左平移一点点 */
}

.game-stats {
    display: flex;
    gap: 1vh;
    flex-wrap: wrap;
    justify-content: center;
    margin-left: 10px; /* 向左平移一点点 */
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: rgba(93, 64, 55, 0.6);
    padding: 0.5rem 0.75rem;
    border-radius: 0.625rem;
    min-width: 5rem;
    border: 0.0625rem solid #8d6e63;
    flex: 1;
    min-width: 0;
}

.stat-label {
    font-size: clamp(0.6rem, 1.8vw, 0.8rem);
    color: #bcaaa4;
    margin-bottom: 0.3125rem;
    text-align: center;
    white-space: nowrap;
}

.stat-value {
    font-size: clamp(1rem, 2.8vw, 1.4rem);
    font-weight: bold;
    color: #fff;
    display: flex;
    align-items: center;
    gap: 0.3125rem;
    justify-content: center;
}

/* 改进的生命值显示 - 使用❤形状，始终显示三个，失去填充颜色 */
.lives-container {
    display: flex;
    gap: 0.3125rem;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 1.5625rem;
    padding: 0.125rem 0.3125rem;
    border-radius: 0.5rem;
    background: rgba(0, 0, 0, 0.2);
    transition: all 0.3s ease;
}

.life-heart {
    font-size: clamp(0.9rem, 2.8vw, 1.3rem);
    transition: all 0.3s ease;
}

.life-heart.full {
    color: #ff6b6b;
    text-shadow: 0 0 0.3125rem rgba(255, 107, 107, 0.5);
}

.life-heart.empty {
    color: #8d6e63;
    opacity: 0.5;
}

.game-content {
    display: flex;
    flex: 1;
    gap: 1vh;
    min-height: 0;
    height: calc(100vh - 20vh - 10vh); /* 减去header和footer的高度 */
}

.game-controls {
    width: 20vw;
    min-width: 12rem;
    max-width: 16rem;
    display: flex;
    flex-direction: column;
    gap: 1vh;
    flex-shrink: 0;
    height: 100%;
    margin-left: 10px; /* 向左平移一点点 */
}

.difficulty-selector {
    background: rgba(93, 64, 55, 0.6);
    border-radius: 0.625rem;
    padding: 1vh;
    border: 0.0625rem solid #8d6e63;
    flex: 0 0 auto;
}

.difficulty-title {
    font-size: clamp(0.8rem, 2.2vw, 1rem);
    color: #d4af37;
    margin-bottom: 0.5rem;
    text-align: center;
}

.difficulty-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.5vh;
}

button {
    background: linear-gradient(to bottom, #8d6e63, #5d4037);
    color: #fff;
    border: none;
    border-radius: 0.5rem;
    padding: 1vh;
    font-size: clamp(0.7rem, 1.8vw, 0.9rem);
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 0.25rem 0.375rem rgba(0, 0, 0, 0.3);
    position: relative;
    overflow: hidden;
    user-select: none;
    min-width: 48px !important;
    min-height: 48px !important;
    padding: 12px !important;
}

button:hover {
    transform: translateY(-0.1875rem);
    box-shadow: 0 0.375rem 0.5rem rgba(0, 0, 0, 0.4);
}

button.active {
    background: linear-gradient(to bottom, #d4af37, #b8941f);
    color: #3e2723;
    box-shadow: 0 0 0.9375rem rgba(212, 175, 55, 0.5);
}

.game-actions {
    display: flex;
    flex-direction: column;
    gap: 0.8vh;
    flex: 1;
    justify-content: flex-start;
}

.music-control {
    background: rgba(93, 64, 55, 0.6);
    border: 0.0625rem solid #8d6e63;
    border-radius: 0.5rem;
    padding: 1vh;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    color: #ffd700;
    font-size: 1.8rem;
    margin-top: auto;
    min-width: 48px !important;
    min-height: 48px !important;
    padding: 12px !important;
    transition: all 0.3s;
}

.music-control.muted {
    color: #8d6e63;
    opacity: 0.7;
}

.game-board-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: rgba(93, 64, 55, 0.4);
    border-radius: 0.625rem;
    padding: 1vh;
    border: 0.0625rem solid #8d6e63;
    min-height: 0;
    overflow: hidden;
    height: 100%;
}

.board-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1vh;
    flex-wrap: wrap;
    gap: 1vh;
}

.game-instructions {
    font-size: clamp(0.6rem, 1.8vw, 0.8rem);
    color: #bcaaa4;
    max-width: 100%;
    text-align: center;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.game-board {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    gap: min(1vw, 0.3125rem);
    margin: 0 auto;
    width: 100%;
    max-width: 100%;
    min-height: 0;
    aspect-ratio: 1/1;
    max-height: 100%;
}

.cell {
    background: linear-gradient(145deg, #8d6e63, #6d4c41);
    border-radius: 0.25rem;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: bold;
    cursor: pointer;
    user-select: none;
    transition: all 0.2s;
    box-shadow: 
        inset 0.125rem 0.125rem 0.25rem rgba(255, 255, 255, 0.1),
        inset -0.125rem -0.125rem 0.25rem rgba(0, 0, 0, 0.3),
        0 0.125rem 0.1875rem rgba(0, 0, 0, 0.2);
    position: relative;
    overflow: hidden;
    font-size: clamp(0.6rem, 1.8vw, 1.2rem);
    min-height: 0;
    min-width: 0;
}

.cell:hover {
    background: linear-gradient(145deg, #a1887f, #8d6e63);
    transform: scale(1.05);
}

.cell.revealed {
    background: #d7ccc8;
    box-shadow: none;
}

.cell.artifact {
    background: linear-gradient(145deg, #ffd700, #d4af37);
    color: #5d4037;
}

.cell.trap {
    background: linear-gradient(145deg, #b71c1c, #7f0000);
    color: #fff;
}

.cell.flag {
    background: linear-gradient(145deg, #4CAF50, #2E7D32);
}

.cell.flag::after {
    content: '🚩';
    position: absolute;
    font-size: clamp(0.6rem, 1.8vw, 1.1rem);
}

.number {
    font-weight: bold;
    font-size: clamp(0.6rem, 1.8vw, 1rem);
}

.number-0 { color: #ff0000; } /* 将数字0改为红色 */
.number-1 { color: #1976d2; }
.number-2 { color: #388e3c; }
.number-3 { color: #d32f2f; }
.number-4 { color: #7b1fa2; }
.number-5 { color: #ff8f00; }
.number-6 { color: #0097a7; }
.number-7 { color: #5d4037; }
.number-8 { color: #455a64; }

.game-footer {
    margin-top: 1vh;
    display: flex;
    justify-content: center;
    gap: 1.25rem;
    height: 10vh;
    min-height: 3rem;
}

.message {
    padding: 0.75rem;
    border-radius: 0.625rem;
    font-weight: bold;
    text-align: center;
    min-height: 3.125rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(0.8rem, 2.2vw, 1rem);
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    opacity: 1;
    transition: opacity 0.5s ease;
    caret-color: transparent; /* 去除闪烁光标 */
}

.message:focus {
    outline: none; /* 去除焦点边框 */
}

.win {
    background: rgba(76, 175, 80, 0.2);
    color: #4caf50;
    border: 0.0625rem solid #4caf50;
}

.lose {
    background: rgba(244, 67, 54, 0.2);
    color: #f44336;
    border: 0.0625rem solid #f44336;
}

/* 游戏说明弹窗 */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}

.modal-content {
    background: linear-gradient(to bottom, #5d4037, #3e2723);
    border-radius: 0.9375rem;
    padding: 1.5625rem;
    width: 90%;
    max-width: 37.5rem;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 0.625rem 1.875rem rgba(0, 0, 0, 0.5);
    border: 0.125rem solid #8d6e63;
    position: relative;
}

.close-modal {
    position: absolute;
    top: 0.9375rem;
    right: 0.9375rem;
    background: none;
    border: none;
    color: #ffd700;
    font-size: 1.8rem;
    cursor: pointer;
    width: 1.875rem;
    height: 1.875rem;
    display: flex;
    justify-content: center;
    align-items: center;
}

.modal-title {
    color: #ffd700;
    font-size: clamp(1.3rem, 3.5vw, 1.6rem);
    text-align: center;
    margin-bottom: 0.9375rem;
    border-bottom: 0.125rem solid #8d6e63;
    padding-bottom: 0.625rem;
}

.instructions-list {
    list-style-type: none;
    padding: 0;
}

.instructions-list li {
    margin-bottom: 0.75rem;
    padding-left: 1.5625rem;
    position: relative;
    line-height: 1.4;
    font-size: clamp(0.8rem, 2.2vw, 0.9rem);
}

.instructions-list li:before {
    content: '•';
    color: #ffd700;
    font-size: 1.3rem;
    position: absolute;
    left: 0;
    top: -0.1875rem;
}

/* 右上角退出按钮占位 */
.exit-placeholder {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 40px;
    height: 40px;
    /* 背景透明，只为占位 */
}

/* 小度设备特定适配 */
/* 7英寸小度屏适配 */
@media (device-width: 1024px) and (device-height: 600px) {
    .game-container { padding: 16px !important; }
    .game-btn { font-size: 14px !important; }
    .game-title { font-size: 24px !important; }
}

/* 10英寸小度屏适配 */
@media (device-width: 1280px) and (device-height: 800px) {
    .game-container { padding: 24px !important; }
    .game-btn { font-size: 16px !important; }
    .game-title { font-size: 28px !important; }
}

@media (max-width: 64rem) and (orientation: portrait) {
    .game-container {
        width: 99vw;
        height: 97vh;
        padding: 1vh;
    }
    
    .game-header {
        height: 14vh;
        flex-direction: row;
        gap: 1vh;
        padding-right: 50px;
    }
    
    .game-title {
        font-size: clamp(1rem, 3.5vw, 1.8rem);
    }
    
    .game-promotion {
        font-size: clamp(0.7rem, 2.2vw, 1rem);
    }
    
    .game-content {
        height: calc(100vh - 16vh - 8vh);
    }
    
    .game-controls {
        width: 22vw;
        min-width: 10rem;
    }
    
    .game-board {
        gap: min(1vw, 0.25rem);
    }
}

/* 横屏设备保持左右布局 */
@media (max-width: 64rem) and (orientation: landscape) {
    .game-content {
        flex-direction: row !important;
    }
    
    .game-controls {
        width: 18vw;
        min-width: 10rem;
        flex-direction: column;
    }
    
    .difficulty-selector {
        flex: none;
    }
    
    .game-actions {
        flex: none;
        flex-direction: column;
    }
}

/* 超小屏幕适配 */
@media (max-width: 30rem) {
    .game-container {
        height: 98vh;
        padding: 0.5rem;
    }
    
    .game-title {
        gap: 0.3125rem;
    }
    
    .stat-item {
        min-width: 4.375rem;
        padding: 0.375rem 0.5rem;
    }
    
    .life-heart {
        font-size: clamp(0.8rem, 2.5vw, 1.1rem);
    }
    
    .difficulty-buttons {
        gap: 0.25rem;
    }
    
    button {
        padding: 0.8vh;
    }
    
    .game-instructions {
        white-space: normal;
        text-align: center;
    }
    
    .game-board {
        gap: 0.125rem;
    }
    
    .game-header {
        padding-right: 45px;
    }
    
    .exit-placeholder {
        width: 35px;
        height: 35px;
    }
}

/* 超小屏幕横屏 */
@media (max-width: 48rem) and (orientation: landscape) {
    .game-container {
        height: 98vh;
        padding: 0.5rem;
    }
    
    .game-header {
        margin-bottom: 0.3125rem;
        padding-bottom: 0.3125rem;
        height: 12vh;
        padding-right: 45px;
    }
    
    .game-board-container {
        padding: 0.5rem;
    }
    
    .game-board {
        gap: min(1vw, 0.1875rem);
    }
    
    .game-stats {
        gap: 0.3125rem;
    }
    
    .stat-item {
        padding: 0.3125rem 0.5rem;
    }
    
    .game-content {
        height: calc(100vh - 14vh - 6vh);
    }
    
    .exit-placeholder {
        width: 35px;
        height: 35px;
    }
}

/* 遥控器设备禁用hover */
@media (pointer: coarse) {
    button:hover, .music-control:hover, .cell:hover {
        background-color: inherit !important;
        transform: none !important;
    }
}

/* 焦点样式（高对比度，符合无障碍规范） */
button:focus, .music-control:focus, .cell:focus {
    outline: 2px solid #d4af37 !important;
    outline-offset: 2px !important;
}

/* 简化的动画效果 - 减少性能开销 */
@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

.pulse {
    animation: pulse 0.5s ease-in-out;
    will-change: transform;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.fade-in {
    animation: fadeIn 0.3s ease-out;
}

@keyframes heartbeat {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

.heartbeat {
    animation: heartbeat 0.5s ease-in-out;
    will-change: transform;
}

@keyframes fadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

.fade-out {
    animation: fadeOut 0.3s ease-out forwards;
}

/* 低性能设备禁用非必要动画 */
@media (max-performance: low) {
    .pulse, .heartbeat, .fade-in, .fade-out {
        animation: none !important;
    }
}

/* 退出提示样式 */
.exit-tip {
    font-size: 0.9rem;
    color: #bcaaa4;
    text-align: center;
    margin-top: 1rem;
    padding: 0.5rem;
    background: rgba(93, 64, 55, 0.3);
    border-radius: 0.5rem;
}