* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Arial', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #776e65;
    min-height: 100vh;
    padding: 20px;
}

.container {
    max-width: 800px;
    margin: 0 auto;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 15px;
    padding: 30px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

header {
    text-align: center;
    margin-bottom: 30px;
}

header h1 {
    font-size: 48px;
    color: #776e65;
    margin-bottom: 20px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
}

.score-container {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-bottom: 20px;
}

.score-box {
    background: #bbada0;
    padding: 10px 20px;
    border-radius: 8px;
    text-align: center;
    min-width: 80px;
}

.score-label {
    font-size: 13px;
    color: #eee4da;
    text-transform: uppercase;
    margin-bottom: 5px;
}

.score {
    font-size: 24px;
    font-weight: bold;
    color: white;
}

.game-container {
    position: relative;
    margin-bottom: 30px;
}

.grid-container {
    background: #bbada0;
    border-radius: 10px;
    padding: 10px;
    position: relative;
    width: 350px;
    height: 350px;
    margin: 0 auto;
    box-sizing: border-box;
}

.grid-row {
    display: flex;
    margin-bottom: 10px;
}

.grid-row:last-child {
    margin-bottom: 0;
}

.grid-cell {
    width: 75px;
    height: 75px;
    background: rgba(238, 228, 218, 0.35);
    border-radius: 8px;
    margin-right: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    font-weight: bold;
    position: relative;
    transition: all 0.15s ease-in-out;
    border: 1px solid rgba(187, 173, 160, 0.3);
    box-shadow: inset 0 2px 4px rgba(255, 255, 255, 0.1);
}

.grid-cell:last-child {
    margin-right: 0;
}

/* 基础数值瓦块 - 温暖色调 */
.grid-cell.tile-2 { 
    background: linear-gradient(135deg, #eee4da, #e4d5c7); 
    color: #776e65; 
    box-shadow: 0 2px 4px rgba(119, 110, 101, 0.2);
}

.grid-cell.tile-4 { 
    background: linear-gradient(135deg, #ede0c8, #e3d2b0); 
    color: #776e65; 
    box-shadow: 0 2px 4px rgba(119, 110, 101, 0.25);
}

/* 过渡数值瓦块 - 橙色渐变 */
.grid-cell.tile-8 { 
    background: linear-gradient(135deg, #f2b179, #f0a563); 
    color: #f9f6f2; 
    box-shadow: 0 2px 6px rgba(242, 177, 121, 0.4);
}

.grid-cell.tile-16 { 
    background: linear-gradient(135deg, #f59563, #f3834d); 
    color: #f9f6f2; 
    box-shadow: 0 2px 6px rgba(245, 149, 99, 0.4);
}

.grid-cell.tile-32 { 
    background: linear-gradient(135deg, #f67c5f, #f46a49); 
    color: #f9f6f2; 
    box-shadow: 0 2px 6px rgba(246, 124, 95, 0.4);
}

/* 中级数值瓦块 - 深橙红色 */
.grid-cell.tile-64 { 
    background: linear-gradient(135deg, #f65e3b, #f44c25); 
    color: #f9f6f2; 
    box-shadow: 0 2px 8px rgba(246, 94, 59, 0.5);
}

.grid-cell.tile-128 { 
    background: linear-gradient(135deg, #edcf72, #ebc556); 
    color: #f9f6f2; 
    font-size: 22px;
    box-shadow: 0 3px 8px rgba(237, 207, 114, 0.5);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.grid-cell.tile-256 { 
    background: linear-gradient(135deg, #edcc61, #ebb840); 
    color: #f9f6f2; 
    font-size: 22px;
    box-shadow: 0 3px 8px rgba(237, 204, 97, 0.5);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.grid-cell.tile-512 { 
    background: linear-gradient(135deg, #edc850, #ebb32a); 
    color: #f9f6f2; 
    font-size: 22px;
    box-shadow: 0 3px 10px rgba(237, 200, 80, 0.6);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.grid-cell.tile-1024 { 
    background: linear-gradient(135deg, #edc53f, #eba814); 
    color: #f9f6f2; 
    font-size: 20px;
    box-shadow: 0 4px 12px rgba(237, 197, 63, 0.6);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

/* 目标瓦块 - 2048 金色特效 */
.grid-cell.tile-2048 { 
    background: linear-gradient(135deg, #edc22e, #d4a017, #b8860b); 
    color: #f9f6f2; 
    font-size: 18px;
    box-shadow: 0 4px 15px rgba(237, 194, 46, 0.8), 0 0 20px rgba(255, 215, 0, 0.6);
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
    border: 2px solid #ffd700;
    animation: glow-pulse 2s ease-in-out infinite alternate;
}

@keyframes glow-pulse {
    from {
        box-shadow: 0 4px 15px rgba(237, 194, 46, 0.8), 0 0 20px rgba(255, 215, 0, 0.6);
    }
    to {
        box-shadow: 0 4px 20px rgba(237, 194, 46, 1), 0 0 30px rgba(255, 215, 0, 0.8);
    }
}

/* 超级数值瓦块 - 红色系渐变 */
.grid-cell.tile-4096 { 
    background: linear-gradient(135deg, #ff6b6b, #ff5252, #f44336); 
    color: #f9f6f2; 
    font-size: 18px;
    box-shadow: 0 4px 12px rgba(255, 107, 107, 0.6);
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

.grid-cell.tile-8192 { 
    background: linear-gradient(135deg, #ff4757, #ff3838, #e74c3c); 
    color: #f9f6f2; 
    font-size: 16px;
    box-shadow: 0 4px 12px rgba(255, 71, 87, 0.6);
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

.grid-cell.tile-16384 { 
    background: linear-gradient(135deg, #ff3838, #e74c3c, #c0392b); 
    color: #f9f6f2; 
    font-size: 14px;
    box-shadow: 0 4px 12px rgba(255, 56, 56, 0.6);
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

/* 极高数值瓦块 - 紫色系渐变 */
.grid-cell.tile-32768 { 
    background: linear-gradient(135deg, #ff2d92, #e91e63, #c2185b); 
    color: #f9f6f2; 
    font-size: 12px;
    box-shadow: 0 4px 15px rgba(255, 45, 146, 0.7);
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

.grid-cell.tile-65536 { 
    background: linear-gradient(135deg, #c44569, #ad1457, #880e4f); 
    color: #f9f6f2; 
    font-size: 11px;
    box-shadow: 0 4px 15px rgba(196, 69, 105, 0.7);
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
}

/* 史诗级数值瓦块 - 深紫渐变与特效 */
.grid-cell.tile-131072 { 
    background: linear-gradient(135deg, #8e44ad, #9b59b6, #663399); 
    color: #f9f6f2; 
    font-size: 10px;
    box-shadow: 0 5px 20px rgba(142, 68, 173, 0.8), 0 0 25px rgba(155, 89, 182, 0.5);
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.7);
    animation: epic-glow 3s ease-in-out infinite alternate;
}

@keyframes epic-glow {
    from {
        box-shadow: 0 5px 20px rgba(142, 68, 173, 0.8), 0 0 25px rgba(155, 89, 182, 0.5);
    }
    to {
        box-shadow: 0 5px 25px rgba(142, 68, 173, 1), 0 0 35px rgba(155, 89, 182, 0.8);
    }
}

/* 通用样式：为任何未定义的瓦片数字提供默认样式 */
.grid-cell[class*="tile-"]:not(.tile-2):not(.tile-4):not(.tile-8):not(.tile-16):not(.tile-32):not(.tile-64):not(.tile-128):not(.tile-256):not(.tile-512):not(.tile-1024):not(.tile-2048):not(.tile-4096):not(.tile-8192):not(.tile-16384):not(.tile-32768):not(.tile-65536):not(.tile-131072) {
    background: linear-gradient(135deg, #2c3e50, #34495e, #1a252f);
    color: #ecf0f1;
    font-size: 10px;
    box-shadow: 0 5px 25px rgba(44, 62, 80, 0.8), 0 0 30px rgba(52, 73, 94, 0.6);
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.8);
    border: 1px solid #34495e;
    animation: mystery-glow 4s ease-in-out infinite alternate;
}

@keyframes mystery-glow {
    from {
        box-shadow: 0 5px 25px rgba(44, 62, 80, 0.8), 0 0 30px rgba(52, 73, 94, 0.6);
    }
    to {
        box-shadow: 0 5px 30px rgba(44, 62, 80, 1), 0 0 40px rgba(52, 73, 94, 0.8);
    }
}

.grid-cell.new-tile {
    animation: appear 0.2s ease-in-out;
}

@keyframes appear {
    0% {
        opacity: 0;
        transform: scale(0);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

.game-message {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.95);
    z-index: 100;
    text-align: center;
    border-radius: 10px;
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.game-message.game-won {
    background: rgba(237, 194, 46, 0.95);
    color: #f9f6f2;
}

.game-message.game-over {
    background: rgba(238, 228, 218, 0.95);
    color: #776e65;
}

.game-message p {
    font-size: 48px;
    font-weight: bold;
    margin-bottom: 20px;
}

.retry-button {
    background: #8f7a66;
    color: #f9f6f2;
    border: none;
    border-radius: 6px;
    padding: 10px 20px;
    font-size: 18px;
    cursor: pointer;
    transition: all 0.3s;
}

.retry-button:hover {
    background: #9f8a76;
}

.control-panel {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
    margin-bottom: 30px;
}

.manual-controls, .auto-controls {
    background: #f9f9f9;
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.manual-controls h3, .auto-controls h3 {
    color: #776e65;
    margin-bottom: 15px;
    font-size: 20px;
}

.manual-controls p {
    color: #8f7a66;
    margin-bottom: 15px;
}

.auto-input {
    margin-bottom: 15px;
}

.auto-input label {
    display: block;
    margin-bottom: 5px;
    color: #776e65;
    font-weight: bold;
}

.auto-input input, .auto-input select {
    width: 100%;
    padding: 8px;
    border: 2px solid #bbada0;
    border-radius: 5px;
    font-size: 16px;
    background: white;
}

.auto-buttons {
    margin-bottom: 20px;
}

.auto-buttons button {
    background: #8f7a66;
    color: #f9f6f2;
    border: none;
    border-radius: 6px;
    padding: 10px 15px;
    font-size: 14px;
    cursor: pointer;
    margin-right: 8px;
    margin-bottom: 8px;
    transition: all 0.3s;
}

.auto-buttons button:hover:not(:disabled) {
    background: #9f8a76;
}

.auto-buttons button:disabled {
    background: #ccc;
    cursor: not-allowed;
}

.auto-stats {
    background: white;
    padding: 15px;
    border-radius: 8px;
    border: 1px solid #e0e0e0;
}

.stat {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    color: #776e65;
}

.stat:last-child {
    margin-bottom: 0;
}

.stat span:last-child {
    font-weight: bold;
    color: #8f7a66;
}

.game-stats {
    background: #f9f9f9;
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.game-stats h3 {
    color: #776e65;
    margin-bottom: 15px;
    font-size: 20px;
}

.stats-controls {
    margin-bottom: 15px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.stats-controls button {
    background: #8f7a66;
    color: #f9f6f2;
    border: none;
    border-radius: 5px;
    padding: 8px 12px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.3s;
}

.stats-controls button:hover {
    background: #9f8a76;
}

#stats-list {
    max-height: 300px;
    overflow-y: auto;
    background: white;
    border-radius: 8px;
    padding: 10px;
    border: 1px solid #e0e0e0;
}

.stat-item {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid #f0f0f0;
    color: #776e65;
}

.stat-item:last-child {
    border-bottom: none;
}

@media (max-width: 768px) {
    .container {
        padding: 10px;
        max-width: 100%;
    }
    
    .control-panel {
        grid-template-columns: 1fr;
        gap: 20px;
    }
    
    /* 棋盘容器优化 - 适应小屏幕 */
    .game-container {
        margin-bottom: 20px;
        width: 100%;
        overflow: visible;
    }
    
    .grid-container {
        width: calc(100vw - 40px);
        max-width: 320px;
        height: calc(100vw - 40px);
        max-height: 320px;
        padding: 6px;
        margin: 0 auto;
        box-sizing: border-box;
    }
    
    .grid-row {
        margin-bottom: 6px;
        height: calc((100% - 18px) / 4);
    }
    
    .grid-row:last-child {
        margin-bottom: 0;
    }
    
    .grid-cell {
        width: calc((100% - 18px) / 4);
        height: 100%;
        font-size: 16px;
        margin-right: 6px;
        box-sizing: border-box;
    }
    
    .grid-cell:last-child {
        margin-right: 0;
    }
    
    /* 游戏消息优化 */
    .game-message p {
        font-size: 24px;
    }
    
    .retry-button {
        font-size: 14px;
        padding: 8px 16px;
    }
    
    /* 数字大小适配 */
    .grid-cell.tile-128,
    .grid-cell.tile-256,
    .grid-cell.tile-512 {
        font-size: 14px;
    }
    
    .grid-cell.tile-1024,
    .grid-cell.tile-2048 {
        font-size: 12px;
    }
    
    .grid-cell.tile-4096,
    .grid-cell.tile-8192 {
        font-size: 11px;
    }
    
    .grid-cell.tile-16384,
    .grid-cell.tile-32768,
    .grid-cell.tile-65536 {
        font-size: 10px;
    }
    
    /* 2048特殊效果移动端优化 */
    .grid-cell.tile-2048 {
        border: 2px solid #ffd700;
        box-sizing: border-box;
        animation: glow-pulse 2s ease-in-out infinite alternate;
    }
    
    /* 超高数值瓦块移动端优化 */
    .grid-cell.tile-131072 {
        font-size: 8px;
        animation: epic-glow 3s ease-in-out infinite alternate;
    }
    
    .grid-cell[class*="tile-"]:not(.tile-2):not(.tile-4):not(.tile-8):not(.tile-16):not(.tile-32):not(.tile-64):not(.tile-128):not(.tile-256):not(.tile-512):not(.tile-1024):not(.tile-2048):not(.tile-4096):not(.tile-8192):not(.tile-16384):not(.tile-32768):not(.tile-65536):not(.tile-131072) {
        font-size: 10px;
    }
    
    header h1 {
        font-size: 28px;
        margin-bottom: 15px;
    }
    
    .score-container {
        flex-direction: row;
        justify-content: center;
        gap: 15px;
        margin-bottom: 15px;
    }
    
    .score-box {
        min-width: 80px;
        padding: 8px 16px;
    }
    
    .score {
        font-size: 18px;
    }
    
    /* 移动端AI计时统计样式优化 */
    .ai-timing-stats {
        margin-top: 15px;
        padding: 12px;
        font-size: 13px;
    }
    
    .ai-timing-stats h4 {
        font-size: 14px;
        margin-bottom: 10px;
    }
    
    .timing-stats .stat {
        font-size: 12px;
        margin-bottom: 6px;
    }
    
    .timing-stats .stat span:last-child {
        font-size: 12px;
        min-width: 60px;
        text-align: right;
    }
    
    .clear-timing-btn {
        font-size: 11px;
        padding: 5px 10px;
        margin-top: 8px;
    }
    
    .depth-mode-info {
        font-size: 11px;
        margin-top: 3px;
    }
    
    /* 确保移动端显示正常 */
    .auto-controls {
        min-height: auto;
    }
    
    .auto-input {
        margin-bottom: 12px;
    }
    
    .auto-input label {
        font-size: 13px;
    }
    
    .auto-input input,
    .auto-input select {
        font-size: 14px;
        padding: 6px;
    }
}

/* AI计时统计样式 */
.ai-timing-stats {
    margin-top: 20px;
    background: white;
    padding: 15px;
    border-radius: 8px;
    border: 1px solid #e0e0e0;
}

.ai-timing-stats h4 {
    color: #776e65;
    margin-bottom: 12px;
    font-size: 16px;
    font-weight: bold;
}

.timing-stats {
    /* 继承.auto-stats的样式 */
}

.timing-stats .stat {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    color: #776e65;
    font-size: 14px;
}

.timing-stats .stat:last-child {
    margin-bottom: 0;
}

.timing-stats .stat span:last-child {
    font-weight: bold;
    color: #8f7a66;
    font-family: 'Courier New', monospace; /* 使用等宽字体使数字更整齐 */
}

.clear-timing-btn {
    background: #8f7a66;
    color: #f9f6f2;
    border: none;
    border-radius: 5px;
    padding: 6px 12px;
    font-size: 12px;
    cursor: pointer;
    margin-top: 10px;
    transition: all 0.3s;
}

.clear-timing-btn:hover {
    background: #9f8a76;
}

/* 深度模式信息样式 */
.depth-mode-info {
    margin-top: 5px;
    font-size: 12px;
    color: #8f7a66;
    font-style: italic;
}

/* 移动端触摸优化 */
@media (max-width: 768px) {
    * {
        -webkit-tap-highlight-color: rgba(0,0,0,0);
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        -khtml-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        user-select: none;
    }
    
    .ai-timing-stats {
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
        will-change: contents;
    }
    
    .timing-stats .stat span {
        will-change: contents;
    }
    
    /* 触摸反馈优化 */
    button, select, input {
        -webkit-appearance: none;
        appearance: none;
        touch-action: manipulation;
    }
    
    .clear-timing-btn:active {
        transform: scale(0.95);
        background: #7a6a56;
    }
}

/* 极小屏幕设备优化 */
@media (max-width: 480px) {
    .container {
        padding: 8px;
    }
    
    .grid-container {
        width: calc(100vw - 20px);
        max-width: 280px;
        height: calc(100vw - 20px);
        max-height: 280px;
        padding: 4px;
    }
    
    .grid-row {
        margin-bottom: 4px;
    }
    
    .grid-cell {
        width: calc((100% - 12px) / 4);
        margin-right: 4px;
        font-size: 14px;
        border-radius: 4px;
    }
    
    .grid-cell.tile-128,
    .grid-cell.tile-256,
    .grid-cell.tile-512 {
        font-size: 12px;
    }
    
    .grid-cell.tile-1024,
    .grid-cell.tile-2048 {
        font-size: 10px;
    }
    
    .grid-cell.tile-4096,
    .grid-cell.tile-8192,
    .grid-cell.tile-16384 {
        font-size: 9px;
    }
    
    .grid-cell.tile-32768,
    .grid-cell.tile-65536 {
        font-size: 8px;
    }
    
    /* 2048特殊效果极小屏幕优化 */
    .grid-cell.tile-2048 {
        border: 2px solid #ffd700;
        box-sizing: border-box;
    }
    
    /* 超高数值瓦块极小屏幕优化 */
    .grid-cell.tile-131072 {
        font-size: 7px;
    }
    
    .grid-cell[class*="tile-"]:not(.tile-2):not(.tile-4):not(.tile-8):not(.tile-16):not(.tile-32):not(.tile-64):not(.tile-128):not(.tile-256):not(.tile-512):not(.tile-1024):not(.tile-2048):not(.tile-4096):not(.tile-8192):not(.tile-16384):not(.tile-32768):not(.tile-65536):not(.tile-131072) {
        font-size: 8px;
    }
    
    header h1 {
        font-size: 24px;
        margin-bottom: 10px;
    }
    
    .score-container {
        gap: 10px;
    }
    
    .score-box {
        min-width: 70px;
        padding: 6px 12px;
    }
    
    .score {
        font-size: 16px;
    }
    
    .score-label {
        font-size: 11px;
    }
    
    .game-message p {
        font-size: 20px;
    }
    
    .retry-button {
        font-size: 12px;
        padding: 6px 12px;
    }
}

.difficulty-selector {
    margin-bottom: 15px;
}

.difficulty-selector label {
    display: block;
    margin-bottom: 5px;
    color: #776e65;
    font-weight: bold;
}

.difficulty-selector select {
    width: 100%;
    padding: 8px;
    border: 2px solid #bbada0;
    border-radius: 5px;
    font-size: 16px;
    background: white;
    color: #776e65;
}
