:root {
    /* 基础颜色 */
    --color-background: #f0f0f0;
    --color-container: #c0c0c0;
    --color-shadow: rgba(0, 0, 0, 0.2);
    --color-header: #e0e0e0;
    --color-theme-toggle: #ffa500;
    --color-primary: #4299e1;
    --color-text: #333;
    --color-board: #999;
    --color-border: #808080;
    --color-border-light: #fff;
    --color-revealed: #e0e0e0;
    --color-mine: #ff0000;
    
    /* 数字颜色 */
    --color-number-1: #0000ff;
    --color-number-2: #008000;
    --color-number-3: #ff0000;
    --color-number-4: #000080;
    --color-number-5: #800000;
    --color-number-6: #008080;
    --color-number-7: #000000;
    --color-number-8: #808080;
    
    /* 控件颜色 */
    --color-control-bg: #fff;
    --color-control-focus: #666;
}

/* 深色模式颜色变量 */
[data-theme="dark"] {
    --color-background: #1a1a1a;
    --color-container: #2d2d2d;
    --color-shadow: rgba(0, 0, 0, 0.4);
    --color-header: #333333;
    --color-theme-toggle: #f1c40f;
    --color-primary: #4299e1;
    --color-text: #e0e0e0;
    --color-board: #404040;
    --color-border: #505050;
    --color-border-light: #666666;
    --color-revealed: #404040;
    --color-mine: #ff4444;
    
    /* 深色主题数字颜色 - 调整为更明亮的色调以提高可读性 */
    --color-number-1: #5c9eff;
    --color-number-2: #4caf50;
    --color-number-3: #ff5252;
    --color-number-4: #7986cb;
    --color-number-5: #ff8a65;
    --color-number-6: #4db6ac;
    --color-number-7: #ba68c8;
    --color-number-8: #90a4ae;
    
    /* 深色主题控件颜色 */
    --color-control-bg: #333333;
    --color-control-focus: #666666;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: Arial, sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background-color: var(--color-background);
}

.game-container {
    position: relative;
    background-color: var(--color-container);
    padding: 10px;
    border-radius: 8px;
    box-shadow: 0 0 10px var(--color-shadow);
}

/* 全局禁用文本选择和长按菜单 */
html, body, * {
    /* 禁用用户选择 */
    user-select: none !important;
    -webkit-user-select: none !important;
    -moz-user-select: none !important;
    -ms-user-select: none !important;
    
    /* 禁用触摸高亮 */
    -webkit-tap-highlight-color: transparent !important;
    
    /* 禁用长按菜单 */
    -webkit-touch-callout: none !important;
    
    /* 禁用拖动 */
    -webkit-user-drag: none !important;
    -khtml-user-drag: none !important;
    -moz-user-drag: none !important;
    -o-user-drag: none !important;
    user-drag: none !important;
    
    /* 禁用上下文菜单 */
    -webkit-context-menu: none !important;
    -moz-context-menu: none !important;
}

.game-controls {
    text-align: center;
    margin-bottom: 10px;
}

#difficulty {
    padding: 8px;
    font-size: 14px;
    border-radius: 4px;
    color: var(--color-text);
    border: 1px solid var(--color-border);
    background-color: var(--color-control-bg);
    cursor: pointer;
}

#difficulty:focus {
    outline: none;
    border-color: var(--color-control-focus);
}

#difficulty option[value="intermediate_phone"],
#difficulty option[value="expert_phone"] {
    display: none;
}

/* 游戏容器和游戏面板特定样式 */
.game-container,
.game-container *,
#gameBoard,
#gameBoard * {
    /* 确保这些属性不会被其他样式覆盖 */
    pointer-events: auto !important;
    touch-action: manipulation !important;
}

.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: var(--color-header);
    padding: 10px;
    border-radius: 4px;
    margin-bottom: 6px;
}

.mine-count, .timer {
    font-family: 'Courier New', Courier, monospace;
    font-size: 24px;
    font-weight: bold;
    color: var(--color-text);
    min-width: 80px;
}

#newGameBtn {
    font-size: 24px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0 10px;
}

#newGameBtn:hover {
    transform: scale(1.1);
}

.game-board {
    display: grid;
    grid-template-columns: repeat(9, 30px);
    gap: 1px;
    background-color: var(--color-board);
    padding: 1px;
    border: 3px solid var(--color-border);
}

.cell {
    width: 30px;
    height: 30px;
    background-color: var(--color-container);
    border: 2px solid;
    border-color: var(--color-border-light) var(--color-border) var(--color-border) var(--color-border-light);
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: bold;
    cursor: pointer;
    user-select: none;
}

.cell.revealed {
    border: 1px solid var(--color-border);
    background-color: var(--color-revealed);
}

.cell.mine {
    background-color: var(--color-mine);
}

.cell.flagged {
    background-color: var(--color-container);
}

.cell[data-number="1"] { color: var(--color-number-1); }
.cell[data-number="2"] { color: var(--color-number-2); }
.cell[data-number="3"] { color: var(--color-number-3); }
.cell[data-number="4"] { color: var(--color-number-4); }
.cell[data-number="5"] { color: var(--color-number-5); }
.cell[data-number="6"] { color: var(--color-number-6); }
.cell[data-number="7"] { color: var(--color-number-7); }
.cell[data-number="8"] { color: var(--color-number-8); }

/* 操作提示样式 */
.game-instructions {
    margin-top: 10px;
    padding: 10px;
    background-color: var(--color-header);
    border-radius: 4px;
    font-size: 14px;
    text-align: center;
    color: var(--color-text);
}

.instructions {
    display: none;
}

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

    /* 为非初级难度添加顶部外边距 */
    .game-container.non-beginner {
        margin-top: 80px;
    }

    .game-controls {
        margin-bottom: 10px;
    }

    .game-board {
        grid-template-columns: repeat(9, 25px);
    }

    .cell {
        width: 28px;
        height: 28px;
        font-size: 12px;
    }
    
    /* 在手机端隐藏普通的中级和高级选项 */
    #difficulty option[value="intermediate"],
    #difficulty option[value="expert"] {
        display: none;
    }

    #difficulty option[value="intermediate_phone"],
    #difficulty option[value="expert_phone"] {
        display: block;
    }
    
    /* 在移动设备上显示移动操作提示 */
    #mobile-instructions {
        display: block;
    }
    
    #pc-instructions {
        display: none;
    }
}

@media (min-width: 601px) {
    /* 在PC设备上显示PC操作提示 */
    #mobile-instructions {
        display: none;
    }
    
    #pc-instructions {
        display: block;
    }
}

/* 控制按钮样式 */
.control-button {
    position: fixed;
    width: 40px;
    height: 40px;
    top: 20px;
    border: none;
    border-radius: 50%;
    background-color: var(--color-control-bg);
    color: var(--color-text);
    cursor: pointer;
    box-shadow: 0 2px 5px var(--color-shadow);
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.3s ease;
    -webkit-tap-highlight-color: transparent;
    outline: none;
}

.control-button:hover {
    transform: scale(1.1);
    background-color: var(--color-header);
}

/* 返回按钮位置 */
#back-button {
    left: 20px;
    color: var(--color-primary);
}

/* 主题切换按钮位置 */
#theme-button {
    right: 20px;
    color: var(--color-theme-toggle);
}

/* 静音按钮位置（主题按钮左侧） */
#sound-button {
    right: 70px;
    color: var(--color-primary);
}

/* ============================================================
   动画增强：轻反馈 / 胜利 / 失败
   全部使用 CSS 动画，零 JS 依赖、轻量流畅，兼容明暗主题
   ============================================================ */

/* ---- 轻反馈：翻开微弹、插旗淡入 ---- */
.cell.revealed {
    animation: cell-pop 0.18s ease-out;
}
.cell.flagged {
    animation: flag-in 0.22s ease-out;
}
@keyframes cell-pop {
    0%   { transform: scale(0.82); }
    60%  { transform: scale(1.06); }
    100% { transform: scale(1); }
}
@keyframes flag-in {
    0%   { transform: scale(0.3) translateY(-5px); opacity: 0; }
    100% { transform: scale(1) translateY(0); opacity: 1; }
}

/* ---- 胜利：涟漪高亮、表情弹跳、外框光晕呼吸 ---- */
.cell.ripple {
    animation: ripple-glow 0.5s ease-out;
}
@keyframes ripple-glow {
    0%   { box-shadow: inset 0 0 0 0 rgba(76, 175, 80, 0); }
    35%  { box-shadow: inset 0 0 0 5px rgba(76, 175, 80, 0.55); background-color: #ffffff; }
    100% { box-shadow: inset 0 0 0 0 rgba(76, 175, 80, 0); }
}
#newGameBtn.bounce {
    animation: bounce-once 0.5s ease;
}
@keyframes bounce-once {
    0%   { transform: scale(1); }
    30%  { transform: scale(1.45) translateY(-6px); }
    60%  { transform: scale(0.9); }
    100% { transform: scale(1); }
}
.game-container.win-glow {
    animation: glow-win 2.8s ease-out;
}
@keyframes glow-win {
    0%   { box-shadow: 0 0 0 0 rgba(76, 175, 80, 0); }
    12%  { box-shadow: 0 0 30px rgba(76, 175, 80, 0.85), inset 0 0 22px rgba(76, 175, 80, 0.35); }
    45%  { box-shadow: 0 0 16px rgba(76, 175, 80, 0.55), inset 0 0 10px rgba(76, 175, 80, 0.2); }
    75%  { box-shadow: 0 0 26px rgba(76, 175, 80, 0.7), inset 0 0 16px rgba(76, 175, 80, 0.25); }
    100% { box-shadow: 0 0 10px var(--color-shadow); }
}

/* ---- 失败：爆炸冲击 + 周围震动 + 棋盘下沉 + 红框闪烁 ---- */
.cell.explode {
    position: relative;
    z-index: 5;
    background-color: var(--color-mine) !important;
    animation: explode-boom 0.6s ease-out;
}
.cell.explode::after {
    content: '';
    position: absolute;
    left: 50%;
    top: 50%;
    width: 24px;
    height: 24px;
    margin: -12px 0 0 -12px;
    border-radius: 50%;
    border: 3px solid rgba(255, 90, 60, 0.9);
    animation: shockwave 0.55s ease-out forwards;
}
@keyframes explode-boom {
    0%   { transform: scale(1); background-color: var(--color-mine); }
    25%  { transform: scale(1.25); background-color: #ff4444; }
    55%  { transform: scale(1); background-color: #ff2222; }
    100% { background-color: var(--color-mine); }
}
@keyframes shockwave {
    0%   { transform: scale(0.2); opacity: 1; }
    100% { transform: scale(2.6); opacity: 0; }
}
.cell.shake {
    animation: cell-shake 0.35s ease-in-out;
}
@keyframes cell-shake {
    0%, 100% { transform: translate(0, 0); }
    20% { transform: translate(-2px, 1px); }
    40% { transform: translate(2px, -1px); }
    60% { transform: translate(-1px, -2px); }
    80% { transform: translate(1px, 2px); }
}
.game-board.lose-sink {
    animation: board-sink 0.5s ease-in forwards;
}
@keyframes board-sink {
    0%   { transform: translateY(0); filter: saturate(1); }
    100% { transform: translateY(5px); filter: saturate(0.65) brightness(0.97); }
}
.game-container.lose-glow {
    animation: glow-lose 2.5s ease-out;
}
@keyframes glow-lose {
    0%   { box-shadow: 0 0 0 0 rgba(255, 60, 40, 0); }
    15%  { box-shadow: 0 0 30px rgba(255, 60, 40, 0.8), inset 0 0 22px rgba(255, 60, 40, 0.3); }
    50%  { box-shadow: 0 0 10px rgba(255, 60, 40, 0.45), inset 0 0 8px rgba(255, 60, 40, 0.15); }
    80%  { box-shadow: 0 0 22px rgba(255, 60, 40, 0.65), inset 0 0 14px rgba(255, 60, 40, 0.22); }
    100% { box-shadow: 0 0 10px var(--color-shadow); }
}

/* ============================================================
   多难度多版本胜利动画（初 1.5s / 中 2.5s / 高 3.5s）
   ============================================================ */

/* 粒子：JS 生成，CSS 变量控制方向/颜色/时长 */
.particle {
    position: absolute;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    pointer-events: none;
    z-index: 20;
    background: var(--color);
    box-shadow: 0 0 6px var(--color);
    animation: particle-fly var(--dur, 1s) ease-out forwards;
    will-change: transform, opacity;
}
@keyframes particle-fly {
    0%   { transform: translate(0, 0) scale(1); opacity: 1; }
    100% { transform: translate(var(--tx), var(--ty)) scale(0.15); opacity: 0; }
}

/* 涟漪变体：柔和绿 / 金色 */
.cell.ripple-soft {
    animation: ripple-soft 0.45s ease-out;
}
@keyframes ripple-soft {
    0%   { box-shadow: inset 0 0 0 0 rgba(124, 227, 139, 0); }
    35%  { box-shadow: inset 0 0 0 3px rgba(124, 227, 139, 0.4); }
    100% { box-shadow: inset 0 0 0 0 rgba(124, 227, 139, 0); }
}
.cell.ripple-gold {
    animation: ripple-gold 0.5s ease-out;
}
@keyframes ripple-gold {
    0%   { box-shadow: inset 0 0 0 0 rgba(255, 193, 7, 0); }
    35%  { box-shadow: inset 0 0 0 5px rgba(255, 193, 7, 0.6); background-color: #fffdf0; }
    100% { box-shadow: inset 0 0 0 0 rgba(255, 193, 7, 0); }
}

/* 光晕变体：绿色短版（初级）/ 金色 / 彩虹呼吸 / 脉冲 */
.game-container.glow-win {
    animation: glow-win 1.5s ease-out;
}
.game-container.glow-gold {
    animation: glow-gold 2.8s ease-out;
}
@keyframes glow-gold {
    0%   { box-shadow: 0 0 0 0 rgba(255, 193, 7, 0); }
    12%  { box-shadow: 0 0 32px rgba(255, 193, 7, 0.85), inset 0 0 22px rgba(255, 193, 7, 0.3); }
    45%  { box-shadow: 0 0 16px rgba(255, 193, 7, 0.5), inset 0 0 10px rgba(255, 193, 7, 0.18); }
    75%  { box-shadow: 0 0 26px rgba(255, 193, 7, 0.7), inset 0 0 16px rgba(255, 193, 7, 0.25); }
    100% { box-shadow: 0 0 10px var(--color-shadow); }
}
.game-container.glow-rainbow {
    animation: glow-rainbow 3.4s ease-out;
}
@keyframes glow-rainbow {
    0%, 100% { box-shadow: 0 0 10px var(--color-shadow); }
    12% { box-shadow: 0 0 30px rgba(92, 200, 255, 0.8), inset 0 0 18px rgba(92, 200, 255, 0.25); }
    32% { box-shadow: 0 0 30px rgba(179, 157, 255, 0.8), inset 0 0 18px rgba(179, 157, 255, 0.25); }
    52% { box-shadow: 0 0 30px rgba(255, 107, 157, 0.8), inset 0 0 18px rgba(255, 107, 157, 0.25); }
    72% { box-shadow: 0 0 30px rgba(255, 215, 0, 0.8), inset 0 0 18px rgba(255, 215, 0, 0.25); }
    90% { box-shadow: 0 0 30px rgba(124, 227, 139, 0.8), inset 0 0 18px rgba(124, 227, 139, 0.25); }
}
.game-container.glow-pulse {
    animation: glow-pulse 0.72s ease-out 2;
}
@keyframes glow-pulse {
    0%, 100% { box-shadow: 0 0 10px var(--color-shadow); }
    35% { box-shadow: 0 0 26px rgba(124, 227, 139, 0.8), inset 0 0 16px rgba(124, 227, 139, 0.25); }
}

/* 光环扩散：金色（2圈）/ 彩虹（1圈） */
.game-container.halo-gold::before,
.game-container.halo-rainbow::before {
    content: '';
    position: absolute;
    inset: -6px;
    border-radius: 14px;
    pointer-events: none;
    z-index: 15;
}
.game-container.halo-gold::before {
    border: 3px solid rgba(255, 193, 7, 0.75);
    box-shadow: 0 0 18px rgba(255, 193, 7, 0.5), inset 0 0 18px rgba(255, 193, 7, 0.2);
    animation: halo-expand 0.9s ease-out 2;
}
.game-container.halo-rainbow::before {
    border: 3px solid rgba(92, 200, 255, 0.75);
    box-shadow: 0 0 18px rgba(255, 215, 0, 0.5), inset 0 0 18px rgba(255, 107, 157, 0.2);
    animation: halo-expand 1.6s ease-out;
}
@keyframes halo-expand {
    0%   { transform: scale(0.98); opacity: 0; }
    30%  { opacity: 1; }
    100% { transform: scale(1.07); opacity: 0; }
}

/* 棋盘悬浮（高级波浪翻牌） */
.game-board.float-up {
    animation: board-float 3s ease-in-out;
}
@keyframes board-float {
    0%, 100% { transform: translateY(0); }
    25% { transform: translateY(-6px); }
    50% { transform: translateY(0); }
    75% { transform: translateY(-3px); }
}

/* 旋转光晕（高级星空） */
.game-container.spin-sky::after {
    content: '';
    position: absolute;
    inset: -16px;
    border-radius: 18px;
    pointer-events: none;
    z-index: 14;
    background: conic-gradient(from 0deg,
        rgba(92, 200, 255, 0.28),
        rgba(179, 157, 255, 0.28),
        rgba(255, 107, 157, 0.28),
        rgba(255, 215, 0, 0.28),
        rgba(92, 200, 255, 0.28));
    filter: blur(8px);
    opacity: 0.85;
    animation: spin-ring 2.4s linear infinite;
}
@keyframes spin-ring {
    to { transform: rotate(360deg); }
}

/* 移动端适配 */
@media (max-width: 600px) {
    .control-button {
        width: 36px;
        height: 36px;
    }
}