/* 性能优化：使用更高效的重置样式   */
*,
*::before,
*::after {
    box-sizing: border-box;
}

* {
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Arial', sans-serif;
    background: #faf8ef;
    min-height: 100vh;
    color: #776e65;
    margin: 0;
    padding: 20px;
}

.container {
    text-align: center;
    background: #faf8ef;
    border-radius: 10px;
    padding: 30px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    max-width: 800px;
    width: 100%;
    margin: 0 auto;
    border: 1px solid #d6d6d6;
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 20px;
    position: relative;
}

.header-controls {
    position: absolute;
    top: 0;
    right: 0;
    z-index: 10;
}

.settings-controls {
    display: flex;
    gap: 8px;
    margin-bottom: 10px;
}

/* 确保分数区域有足够的空间 */
.score-container {
    margin-top: 60px; /* 为设置按钮留出更多空间 */
    margin-right: 100px; /* 为右侧设置按钮留出空间 */
}

/* 调整标题位置，避免与设置按钮重叠 */
h1 {
    font-size: 3em;
    font-weight: bold;
    color: #776e65;
    text-shadow: none;
    margin: 0;
    margin-right: 100px; /* 为右侧设置按钮留出空间 */
}

.score-container {
    display: flex;
    gap: 10px;
}

.score-box {
    background: #bbada0;
    color: white;
    padding: 10px 15px;
    border-radius: 8px;
    text-align: center;
    min-width: 80px;
}

.score-label {
    font-size: 0.8em;
    text-transform: uppercase;
    font-weight: bold;
}

.score-value {
    font-size: 1.5em;
    font-weight: bold;
    margin-top: 2px;
}

.above-game {
    text-align: center;
    margin-bottom: 20px;
}

.game-intro {
    color: #776e65;
    margin-bottom: 15px;
    font-size: 1.1em;
    line-height: 1.5;
}

.new-game-btn, .restart-btn, .undo-btn, .swap-btn, .sound-btn {
    background: #8f7a66;
    color: #f9f6f2;
    border: none;
    padding: 12px 24px;
    border-radius: 6px;
    font-size: 1em;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent; /* 移除移动端点击高亮 */
    touch-action: manipulation; /* 优化触摸响应 */
}

.new-game-btn:hover, .restart-btn:hover, .undo-btn:hover, .swap-btn:hover, .sound-btn:hover {
    background: #9f8a76;
}

.undo-btn:disabled, .swap-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
}

.sound-btn.muted {
    background: #f67c5f;
}

.sound-btn.muted:hover {
    background: #f78c6c;
}

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

.clear-stats-btn {
    background: #f67c5f;
    color: #f9f6f2;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    font-size: 0.9em;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-top: 10px;
}

.clear-stats-btn:hover {
    background: #f65e3b;
}

.game-container {
    display: flex;
    justify-content: center;
    margin-bottom: 20px;
}

.game-board {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: 20px;
    background: #bbada0;
    padding: 20px;
    border-radius: 10px;
    width: 600px;
    height: 600px;
    max-width: 90vw;
    max-height: 90vw;
    aspect-ratio: 1;
}

.cell {
    background: rgba(238, 228, 218, 0.35);
    border-radius: 6px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2em;
    font-weight: bold;
    transition: all 0.3s ease;
    position: relative;
}

.tile {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 6px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2em;
    font-weight: bold;
    transition: all 0.3s ease;
    animation: tileAppear 0.3s ease;
}

@keyframes tileAppear {
    0% {
        transform: scale(0);
        opacity: 0;
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

/* 增强动画效果 */
.tile-moving {
    transition: transform 150ms ease-out !important;
}

.tile-merging {
    animation: mergeAnimation 200ms ease-out;
}

.tile-appearing {
    animation: appearAnimation 200ms ease-out;
}

.tile-disappearing {
    animation: disappearAnimation 150ms ease-in;
}

/* 移动动画 */
@keyframes moveAnimation {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

/* 合并动画 */
@keyframes mergeAnimation {
    0% { transform: scale(1); }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

/* 出现动画 */
@keyframes appearAnimation {
    0% { 
        transform: scale(0);
        opacity: 0;
    }
    50% { 
        transform: scale(1.1);
        opacity: 0.8;
    }
    100% { 
        transform: scale(1);
        opacity: 1;
    }
}

/* 消失动画 */
@keyframes disappearAnimation {
    0% { 
        transform: scale(1);
        opacity: 1;
    }
    100% { 
        transform: scale(0);
        opacity: 0;
    }
}

/* 游戏结束动画 */
.game-over-animation {
    animation: gameOverShake 0.5s ease-in-out;
}

@keyframes gameOverShake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
    20%, 40%, 60%, 80% { transform: translateX(5px); }
}

/* 胜利动画 */
.win-animation {
    animation: winPulse 1s ease-in-out infinite;
}

@keyframes winPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

/* 主题切换 */
:root {
    --bg-color: #faf8ef;
    --text-color: #776e65;
    --tile-bg: #eee4da;
    --tile-text: #776e65;
    --board-bg: #bbada0;
    --button-bg: #8f7a66;
    --button-hover: #9f8a76;
    --shadow: rgba(0, 0, 0, 0.1);
}

[data-theme="dark"] {
    --bg-color: #1a1a1a;
    --text-color: #d4d4d4;
    --tile-bg: #2d2d2d;
    --tile-text: #d4d4d4;
    --board-bg: #3c3c3c;
    --button-bg: #4a4a4a;
    --button-hover: #5a5a5a;
    --shadow: rgba(255, 255, 255, 0.1);
}

body {
    background: var(--bg-color);
    color: var(--text-color);
}

.container, .game-content {
    background: var(--bg-color);
    border-color: var(--shadow);
}

.game-board {
    background: var(--board-bg);
}

.tile {
    background: var(--tile-bg);
    color: var(--tile-text);
}

/* 按钮基础样式 */
.new-game-btn, .restart-btn, .undo-btn, .swap-btn, .sound-btn, .theme-btn, .share-btn {
    background: var(--button-bg);
    color: #f9f6f2;
    border: none;
    border-radius: 6px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s ease;
}

/* 主要按钮 - 显眼、大尺寸 */
.primary-btn {
    padding: 16px 32px;
    font-size: 1.2em;
    background: #8f7a66;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.primary-btn:hover {
    background: #9f8a76;
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.3);
}

/* 次要按钮 - 中等尺寸 */
.secondary-btn {
    padding: 12px 20px;
    font-size: 1em;
    background: #8f7a66;
}

.secondary-btn:hover {
    background: #9f8a76;
    transform: translateY(-1px);
}

/* 游戏操作按钮 - 小尺寸，紧凑布局 */
.game-action-btn {
    padding: 8px 16px;
    font-size: 0.9em;
    background: #8f7a66;
    min-width: 120px;
}

.game-action-btn:hover {
    background: #9f8a76;
    transform: translateY(-1px);
}

.game-action-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
    transform: none;
}

/* 设置按钮 - 小尺寸、圆形 */
.settings-btn {
    padding: 10px;
    font-size: 1.2em;
    background: var(--button-bg);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.settings-btn:hover {
    background: var(--button-hover);
    transform: scale(1.1);
}

/* 主要控制区域 */
.primary-controls {
    display: flex;
    justify-content: center;
    margin: 20px 0;
}

/* 游戏控制区域 */
.game-controls {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin: 15px 0;
    flex-wrap: wrap;
}

/* 游戏结束控制区域 */
.game-over-controls {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-top: 20px;
    flex-wrap: wrap;
}

/* 主题切换按钮 - 设置按钮样式 */
.theme-btn {
    position: relative;
    overflow: hidden;
}

.theme-btn .theme-text {
    transition: all 0.3s ease;
    font-size: 1.2em;
}

/* 音效按钮状态 */
.sound-btn.muted {
    background: #f67c5f;
}

.sound-btn.muted:hover {
    background: #f78c6c;
}

/* 不同数字的方块颜色 */
.tile-2 { background: #eee4da; color: #776e65; }
.tile-4 { background: #ede0c8; color: #776e65; }
.tile-8 { background: #f2b179; color: #f9f6f2; }
.tile-16 { background: #f59563; color: #f9f6f2; }
.tile-32 { background: #f67c5f; color: #f9f6f2; }
.tile-64 { background: #f65e3b; color: #f9f6f2; }
.tile-128 { background: #edcf72; color: #f9f6f2; font-size: 1.8em; }
.tile-256 { background: #edcc61; color: #f9f6f2; font-size: 1.8em; }
.tile-512 { background: #edc850; color: #f9f6f2; font-size: 1.8em; }
.tile-1024 { background: #edc53f; color: #f9f6f2; font-size: 1.6em; }
.tile-2048 { background: #edc22e; color: #f9f6f2; font-size: 1.6em; }

.game-over {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.game-over-content {
    background: white;
    padding: 40px;
    border-radius: 15px;
    text-align: center;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
}

.game-over-content h2 {
    color: #776e65;
    margin-bottom: 20px;
    font-size: 2em;
}

.game-over-content p {
    color: #776e65;
    margin-bottom: 20px;
    font-size: 1.2em;
}

/* 移动端适配 */
@media (max-width: 600px) {
    .container {
        padding: 15px;
        margin: 10px;
    }
    
    .game-board {
        width: 100%;
        max-width: 500px;
        height: 500px;
        max-height: 80vw;
        aspect-ratio: 1;
        touch-action: none; /* 禁用默认触摸行为 */
        -webkit-touch-callout: none; /* 禁用长按菜单 */
        -webkit-user-select: none; /* 禁用文本选择 */
        user-select: none;
    }
    
    .tile {
        font-size: 1.8em;
    }
    
    .tile-128, .tile-256, .tile-512 {
        font-size: 1.5em;
    }
    
    .tile-1024, .tile-2048 {
        font-size: 1.3em;
    }
    
    h1 {
        font-size: 2.5em;
    }
    
    .header {
        flex-direction: column;
        gap: 15px;
    }
}

@media (max-width: 400px) {
    .game-board {
        width: 100%;
        max-width: 350px;
        height: 350px;
        max-height: 80vw;
        aspect-ratio: 1;
        touch-action: none; /* 禁用默认触摸行为 */
        -webkit-touch-callout: none; /* 禁用长按菜单 */
        -webkit-user-select: none; /* 禁用文本选择 */
        user-select: none;
    }
    
    .tile {
        font-size: 1.5em;
    }
    
    .tile-128, .tile-256, .tile-512 {
        font-size: 1.2em;
    }
    
    .tile-1024, .tile-2048 {
        font-size: 1em;
    }
}

/* 游戏说明内容样式 */
.game-content {
    max-width: 800px;
    margin: 2rem auto 0;
    padding: 30px;
    line-height: 1.6;
    width: 100%;
    background: #faf8ef;
    border-radius: 10px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    border: 1px solid #d6d6d6;
}

.game-explanation {
    text-align: center;
    margin-bottom: 2rem;
    padding: 1rem;
    background: #eee4da;
    border-radius: 6px;
    border: 1px solid #d6d6d6;
}

.game-explanation p {
    color: #776e65;
    font-size: 1.1em;
    margin: 0;
}

.game-details {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.detail-section {
    background: #eee4da;
    padding: 1.5rem;
    border-radius: 6px;
    border: 1px solid #d6d6d6;
}

.detail-section h3 {
    color: #776e65;
    margin-bottom: 1rem;
    font-size: 1.2em;
    border-bottom: 2px solid #bbada0;
    padding-bottom: 0.5rem;
}

.detail-section p {
    color: #776e65;
    margin-bottom: 1rem;
    font-size: 0.95em;
}

.detail-section ul {
    color: #776e65;
    padding-left: 1.2rem;
    margin: 0;
}

.detail-section li {
    margin-bottom: 0.4rem;
    font-size: 0.9em;
}

.footer {
    text-align: center;
    margin: 2rem auto;
    padding: 1rem;
    color: #776e65;
    font-size: 0.9em;
}

.footer a {
    color: #776e65;
    text-decoration: none;
}

.footer a:hover {
    text-decoration: underline;
}

/* SEO内容样式 */
.seo-content {
    margin-top: 2rem;
}

.content-section {
    background: #faf8ef;
    margin-bottom: 2rem;
    padding: 2rem;
    border-radius: 10px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    border: 1px solid #d6d6d6;
}

.content-section h2 {
    color: #776e65;
    font-size: 1.8em;
    margin-bottom: 1rem;
    border-bottom: 3px solid #bbada0;
    padding-bottom: 0.5rem;
}

.content-section h3 {
    color: #776e65;
    font-size: 1.3em;
    margin: 1.5rem 0 1rem 0;
    border-bottom: 2px solid #bbada0;
    padding-bottom: 0.3rem;
}

.content-section p {
    color: #776e65;
    line-height: 1.7;
    margin-bottom: 1rem;
    font-size: 1.05em;
}

.content-section ul, .content-section ol {
    color: #776e65;
    padding-left: 1.5rem;
    margin-bottom: 1rem;
}

.content-section li {
    margin-bottom: 0.5rem;
    line-height: 1.6;
}

.content-section strong {
    color: #8f7a66;
    font-weight: bold;
}

/* 面包屑导航样式 */
.breadcrumb {
    margin-bottom: 1rem;
    padding: 0.5rem 0;
}

.breadcrumb ol {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-wrap: wrap;
}

.breadcrumb li {
    display: flex;
    align-items: center;
}

.breadcrumb li:not(:last-child)::after {
    content: "›";
    margin: 0 0.5rem;
    color: #8f7a66;
}

.breadcrumb a {
    color: #8f7a66;
    text-decoration: none;
    font-size: 0.9em;
}

.breadcrumb a:hover {
    text-decoration: underline;
}

.breadcrumb li[aria-current="page"] {
    color: #776e65;
    font-weight: bold;
}

/* 隐私政策页面样式 */
.privacy-content {
    max-width: 800px;
    margin: 0 auto;
    text-align: left;
}

.privacy-section {
    background: #faf8ef;
    margin-bottom: 2rem;
    padding: 2rem;
    border-radius: 10px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    border: 1px solid #d6d6d6;
}

.privacy-section h2 {
    color: #776e65;
    font-size: 1.6em;
    margin-bottom: 1rem;
    border-bottom: 2px solid #bbada0;
    padding-bottom: 0.5rem;
}

.privacy-section h3 {
    color: #776e65;
    font-size: 1.2em;
    margin: 1.5rem 0 1rem 0;
    border-bottom: 1px solid #bbada0;
    padding-bottom: 0.3rem;
}

.privacy-section p {
    color: #776e65;
    line-height: 1.7;
    margin-bottom: 1rem;
    font-size: 1.05em;
}

.privacy-section ul {
    color: #776e65;
    padding-left: 1.5rem;
    margin-bottom: 1rem;
}

.privacy-section li {
    margin-bottom: 0.5rem;
    line-height: 1.6;
}

.privacy-section a {
    color: #8f7a66;
    text-decoration: none;
}

.privacy-section a:hover {
    text-decoration: underline;
}

.last-updated {
    color: #8f7a66;
    font-style: italic;
    font-size: 0.9em;
    margin-top: 0.5rem;
}

.back-to-game {
    text-align: center;
    margin: 2rem 0;
}

.back-button {
    display: inline-block;
    background: #8f7a66;
    color: #f9f6f2;
    padding: 12px 24px;
    border-radius: 6px;
    text-decoration: none;
    font-weight: bold;
    transition: all 0.2s ease;
}

.back-button:hover {
    background: #9f8a76;
    text-decoration: none;
}

/* 移动端优化 */
@media (max-width: 600px) {
    .game-content {
        padding: 0 10px;
    }
    
    .game-details {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .detail-section {
        padding: 1rem;
    }
    
    .detail-section h3 {
        font-size: 1.1em;
    }
    
    .game-explanation {
        padding: 0.8rem;
    }
    
    .game-explanation p {
        font-size: 1em;
    }
    
    .content-section {
        padding: 1.5rem;
        margin-bottom: 1.5rem;
    }
    
    /* 移动端按钮布局 */
    .header {
        flex-direction: column;
        align-items: center;
    }
    
    .header-controls {
        position: static;
        margin-bottom: 15px;
        order: -1; /* 将设置按钮放在最上面 */
    }
    
    .settings-controls {
        justify-content: center;
    }
    
    .score-container {
        margin-top: 0; /* 移动端不需要额外间距 */
    }
    
    .primary-btn {
        padding: 14px 28px;
        font-size: 1.1em;
    }
    
    .secondary-btn {
        padding: 10px 16px;
        font-size: 0.9em;
    }
    
    .settings-btn {
        width: 36px;
        height: 36px;
        font-size: 1em;
    }
    
    .game-controls {
        gap: 8px;
        margin: 12px 0;
    }
    
    .game-action-btn {
        padding: 6px 12px;
        font-size: 0.8em;
        min-width: 100px;
    }
    
    .game-over-controls {
        gap: 10px;
        flex-direction: column;
        align-items: center;
    }
    
    .content-section h2 {
        font-size: 1.5em;
    }
    
    .content-section h3 {
        font-size: 1.2em;
    }
    
    .content-section p {
        font-size: 1em;
    }
    
    .privacy-section {
        padding: 1.5rem;
        margin-bottom: 1.5rem;
    }
    
    .privacy-section h2 {
        font-size: 1.4em;
    }
    
    .privacy-section h3 {
        font-size: 1.1em;
    }
    
    .privacy-section p {
        font-size: 1em;
    }
    
    .breadcrumb {
        font-size: 0.8em;
    }
}
