/* --- Apple Design System Variables --- */
:root {
    --bg-color: #e8e8ed;
    --grid-bg-color: rgba(220, 220, 225, 0.9);
    --cell-bg-color: rgba(240, 240, 245, 0.7);
    --text-color-dark: #1d1d1f;
    --text-color-light: #f8f9fa;
    --accent-color: #007aff;
    --font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Helvetica Neue", Arial, sans-serif;
    --shadow-light: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-medium: 0 4px 12px rgba(0, 0, 0, 0.15);
    --shadow-heavy: 0 8px 25px rgba(0, 0, 0, 0.2);
    --border-radius: 12px;
    --border-radius-small: 8px;

    /* 移动端简化颜色 */
    --tile-8-simple: #ff9500;
    --tile-16-simple: #ff6b35;
    --tile-32-simple: #ff3b30;
    --tile-64-simple: #ff2d92;
    --tile-128-simple: #af52de;
    --tile-256-simple: #007aff;
    --tile-512-simple: #5ac8fa;
    --tile-1024-simple: #34c759;
}

html,
body {
    margin: 0;
    padding: 0;
    background: linear-gradient(135deg, #e8e8ed 0%, #d1d1d6 100%);
    color: var(--text-color-dark);
    font-family: var(--font-family);
    font-size: 18px;
    font-weight: 400;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    touch-action: none;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* --- Layout --- */
.container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    width: 100%;
    max-width: 520px;
    padding: 15px 10px;
    box-sizing: border-box;
    max-height: 100vh;
    justify-content: center;
    overflow: hidden;
}

/* 头部容器样式 */
.header-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    max-width: 500px;
    margin-bottom: 10px;
}

/* LOGO 样式 */
.logo-container {
    text-align: left;
}

.logo {
    font-size: 3.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, #007aff 0%, #5856d6 50%, #af52de 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    margin: 0;
    line-height: 1;
    letter-spacing: -0.02em;
}

.logo-subtitle {
    font-size: 0.9rem;
    color: #8e8e93;
    font-weight: 500;
    margin-top: 4px;
    opacity: 0.8;
}

/* 头部新游戏按钮 */
.new-game-header {
    align-self: flex-start;
    margin-top: 10px;
    padding: 12px 24px;
    font-size: 1.1rem;
    font-weight: 600;
}

.scores-container {
    display: flex;
    justify-content: center;
    gap: 12px;
    width: 100%;
    max-width: 500px;
    flex-wrap: wrap;
}

.score-box {
    background: var(--grid-bg-color);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    padding: 12px 20px;
    border-radius: var(--border-radius);
    border: 1px solid rgba(255, 255, 255, 0.2);
    text-align: center;
    display: flex;
    flex-direction: column;
    min-width: 70px;
    flex: 1;
    max-width: 130px;
    box-shadow: var(--shadow-light), inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.score-label {
    font-size: 0.8rem;
    color: #5a5a5c;
    margin-bottom: 2px;
    font-weight: 500;
}

.score-box span {
    display: block;
}

#current-score,
#best-score {
    font-size: 1.6rem;
    font-weight: bold;
    line-height: 1;
}

.above-game {
    width: 100%;
}

.actions {
    display: flex;
    flex-wrap: wrap;
    /* Allow items to wrap to the next line */
    justify-content: flex-start;
    align-items: center;
    gap: 10px;
    margin-top: 10px;
}

.ai-speed-control {
    display: flex;
    align-items: center;
    gap: 5px;
}

button,
.retry-button,
.keep-playing-button {
    padding: 10px 20px;
    border-radius: 8px;
    border: none;
    background: var(--accent-color);
    color: var(--text-color-light);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.3s;
    text-decoration: none;
}

button:hover,
.retry-button:hover,
.keep-playing-button:hover {
    background-color: #0056b3;
}

/* --- Game Grid --- */
.game-container {
    position: relative;
    width: min(500px, 90vw);
    height: min(500px, 90vw);
    max-width: 500px;
    max-height: 500px;
    flex-shrink: 0;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-heavy);
    align-self: center;
}

.grid-container {
    position: absolute;
    width: 100%;
    height: 100%;
    background: var(--grid-bg-color);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: var(--border-radius);
    border: 1px solid rgba(255, 255, 255, 0.2);
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: min(15px, 3vw);
    padding: min(15px, 3vw);
    box-sizing: border-box;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.grid-cell {
    background: var(--cell-bg-color);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: var(--border-radius-small);
    border: 1px solid rgba(255, 255, 255, 0.3);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4), 0 1px 3px rgba(0, 0, 0, 0.1);
    position: relative;
    background-image:
        radial-gradient(circle at 25% 25%, rgba(255, 255, 255, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 75% 75%, rgba(255, 255, 255, 0.05) 0%, transparent 50%);
}

.grid-cell::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.15);
    opacity: 0.4;
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.2);
}

.tile-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

/* --- Tiles --- */
.tile-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.tile {
    position: absolute;
    width: 107.5px;
    height: 107.5px;
    transition: transform 100ms ease-in-out;
}

.tile-inner {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: var(--border-radius-small);
    font-weight: 600;
    font-size: 2.5rem;
    box-sizing: border-box;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: var(--shadow-medium);
    transition: all 0.2s ease;
}

/* 瓦片位置 - 桌面版固定像素值 */
.tile-position-1-1 {
    transform: translate(15px, 15px);
}

.tile-position-1-2 {
    transform: translate(15px, 137.5px);
}

.tile-position-1-3 {
    transform: translate(15px, 260px);
}

.tile-position-1-4 {
    transform: translate(15px, 382.5px);
}

.tile-position-2-1 {
    transform: translate(137.5px, 15px);
}

.tile-position-2-2 {
    transform: translate(137.5px, 137.5px);
}

.tile-position-2-3 {
    transform: translate(137.5px, 260px);
}

.tile-position-2-4 {
    transform: translate(137.5px, 382.5px);
}

.tile-position-3-1 {
    transform: translate(260px, 15px);
}

.tile-position-3-2 {
    transform: translate(260px, 137.5px);
}

.tile-position-3-3 {
    transform: translate(260px, 260px);
}

.tile-position-3-4 {
    transform: translate(260px, 382.5px);
}

.tile-position-4-1 {
    transform: translate(382.5px, 15px);
}

.tile-position-4-2 {
    transform: translate(382.5px, 137.5px);
}

.tile-position-4-3 {
    transform: translate(382.5px, 260px);
}

.tile-position-4-4 {
    transform: translate(382.5px, 382.5px);
}

/* --- Apple Design System Tile Colors --- */
.tile.tile-2 .tile-inner {
    background: linear-gradient(135deg, #e8f4f8 0%, #d4edda 100%) !important;
    color: #2c5530 !important;
    box-shadow: var(--shadow-light), inset 0 1px 0 rgba(255, 255, 255, 0.5) !important;
    border: 1px solid rgba(44, 85, 48, 0.3) !important;
}

.tile.tile-4 .tile-inner {
    background: linear-gradient(135deg, #fff3cd 0%, #ffeaa7 100%) !important;
    color: #856404 !important;
    box-shadow: var(--shadow-light), inset 0 1px 0 rgba(255, 255, 255, 0.5) !important;
    border: 1px solid rgba(133, 100, 4, 0.3) !important;
}

.tile.tile-8 .tile-inner {
    background: linear-gradient(135deg, #ff9500 0%, #ff8c00 100%);
    color: #f8f9fa;
    box-shadow: var(--shadow-medium), inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.tile.tile-16 .tile-inner {
    background: linear-gradient(135deg, #ff6b35 0%, #f7931e 100%);
    color: #f8f9fa;
    box-shadow: var(--shadow-medium), inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.tile.tile-32 .tile-inner {
    background: linear-gradient(135deg, #ff3b30 0%, #d70015 100%);
    color: #f8f9fa;
    box-shadow: var(--shadow-medium), inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.tile.tile-64 .tile-inner {
    background: linear-gradient(135deg, #ff2d92 0%, #d70040 100%);
    color: #f8f9fa;
    box-shadow: var(--shadow-medium), inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.tile.tile-128 .tile-inner {
    background: linear-gradient(135deg, #af52de 0%, #8e44ad 100%);
    color: #f8f9fa;
    font-size: 2.2rem;
    box-shadow: var(--shadow-medium), inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.tile.tile-256 .tile-inner {
    background: linear-gradient(135deg, #007aff 0%, #0051d5 100%);
    color: #f8f9fa;
    font-size: 2.2rem;
    box-shadow: var(--shadow-medium), inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.tile.tile-512 .tile-inner {
    background: linear-gradient(135deg, #5ac8fa 0%, #007aff 100%);
    color: #f8f9fa;
    font-size: 2.2rem;
    box-shadow: var(--shadow-medium), inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.tile.tile-1024 .tile-inner {
    background: linear-gradient(135deg, #34c759 0%, #248a3d 100%);
    color: #f8f9fa;
    font-size: 2rem;
    box-shadow: var(--shadow-medium), inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.tile.tile-2048 .tile-inner {
    background: linear-gradient(135deg, #007aff 0%, #5856d6 100%);
    color: #f8f9fa;
    font-size: 2rem;
    font-weight: 600;
    box-shadow: 0 0 20px rgba(0, 122, 255, 0.4), var(--shadow-heavy), inset 0 1px 0 rgba(255, 255, 255, 0.3);
    animation: apple-glow-blue 3s ease-in-out infinite alternate;
}

.tile.tile-super .tile-inner {
    background: linear-gradient(135deg, #ff2d92 0%, #af52de 25%, #007aff 50%, #34c759 75%, #ff9500 100%);
    background-size: 300% 300%;
    color: #f8f9fa;
    font-size: 1.4rem;
    font-weight: 600;
    box-shadow: 0 0 30px rgba(255, 45, 146, 0.5), var(--shadow-heavy), inset 0 1px 0 rgba(255, 255, 255, 0.3);
    animation: apple-rainbow-flow 4s ease infinite, apple-glow-rainbow 3s ease-in-out infinite alternate;
}


/* --- Tile Positioning --- */
.tile-position-1-1 {
    transform: translate(15px, 15px);
}

.tile-position-1-2 {
    transform: translate(15px, 137.5px);
}

.tile-position-1-3 {
    transform: translate(15px, 260px);
}

.tile-position-1-4 {
    transform: translate(15px, 382.5px);
}

.tile-position-2-1 {
    transform: translate(137.5px, 15px);
}

.tile-position-2-2 {
    transform: translate(137.5px, 137.5px);
}

.tile-position-2-3 {
    transform: translate(137.5px, 260px);
}

.tile-position-2-4 {
    transform: translate(137.5px, 382.5px);
}

.tile-position-3-1 {
    transform: translate(260px, 15px);
}

.tile-position-3-2 {
    transform: translate(260px, 137.5px);
}

.tile-position-3-3 {
    transform: translate(260px, 260px);
}

.tile-position-3-4 {
    transform: translate(260px, 382.5px);
}

.tile-position-4-1 {
    transform: translate(382.5px, 15px);
}

.tile-position-4-2 {
    transform: translate(382.5px, 137.5px);
}

.tile-position-4-3 {
    transform: translate(382.5px, 260px);
}

.tile-position-4-4 {
    transform: translate(382.5px, 382.5px);
}

/* --- Animations --- */
/* 新数字高亮效果 - 带呼吸动画 */
.tile-new .tile-inner {
    animation: appear 200ms ease 100ms, breathe 1.5s ease-in-out infinite 200ms;
    animation-fill-mode: backwards;
    box-shadow: 0 0 15px 6px rgba(0, 122, 255, 0.8) !important;
    border: 2px solid rgba(0, 122, 255, 0.9) !important;
    outline: 1px solid rgba(0, 122, 255, 0.6) !important;
    outline-offset: 2px !important;
}

/* 确保桌面端新数字高亮不被覆盖 */
.tile.tile-new .tile-inner {
    animation: appear 200ms ease 100ms, breathe 1.5s ease-in-out infinite 200ms;
    box-shadow: 0 0 15px 6px rgba(0, 122, 255, 0.8) !important;
    border: 2px solid rgba(0, 122, 255, 0.9) !important;
    outline: 1px solid rgba(0, 122, 255, 0.6) !important;
    outline-offset: 2px !important;
}

/* 呼吸动画效果 - 超强版本 */
@keyframes breathe {

    0%,
    100% {
        box-shadow: 0 0 20px 8px rgba(0, 122, 255, 1);
        border-color: rgba(0, 122, 255, 1);
        outline-color: rgba(0, 122, 255, 0.8);
        transform: scale(1);
        opacity: 1;
    }

    50% {
        box-shadow: 0 0 35px 15px rgba(0, 122, 255, 0.3);
        border-color: rgba(0, 122, 255, 0.4);
        outline-color: rgba(0, 122, 255, 0.2);
        transform: scale(1.03);
        opacity: 0.8;
    }
}

.tile-merged .tile-inner {
    animation: pop-and-flash 400ms ease-in-out;
    animation-fill-mode: backwards;
}

.tile-edited .tile-inner {
    animation: pop 200ms ease 100ms;
    animation-fill-mode: backwards;
}

@keyframes appear {
    from {
        transform: scale(0);
    }

    to {
        transform: scale(1);
    }
}

@keyframes pop-and-flash {
    0% {
        transform: scale(0.8);
        opacity: 0;
    }

    60% {
        transform: scale(1.1);
        opacity: 1;
        box-shadow: 0 0 12px 6px rgba(255, 215, 0, 0.7);
    }

    100% {
        transform: scale(1);
        box-shadow: 0 0 0px rgba(255, 215, 0, 0);
    }
}

/* --- Game Over/Win Message --- */
.game-message {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    background: transparent;
    /* Fully transparent background */
    z-index: 100;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.5s, visibility 0.5s;
}

.game-message p {
    font-size: 3rem;
    font-weight: bold;
    margin: 0;
    color: var(--text-color-dark);
    text-shadow: 0 0 15px rgba(249, 246, 242, 0.8), 0 0 5px rgba(249, 246, 242, 1);
}

.game-message .lower {
    margin-top: 20px;
    display: flex;
    gap: 10px;
}

.game-message.game-won,
.game-message.game-over {
    opacity: 1;
    visibility: visible;
}

.game-message.game-won .keep-playing-button {
    display: inline-block;
}

.game-message .keep-playing-button {
    display: none;
}

/* --- AI Controls --- */
.ai-controls {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 500px;
    padding: 10px 15px;
    background: var(--grid-bg-color);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: var(--border-radius);
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-sizing: border-box;
    gap: 10px;
    margin-bottom: 15px;
    box-shadow: var(--shadow-light), inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.ai-row-1,
.ai-row-2 {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    gap: 15px;
    flex-wrap: wrap;
}

.ai-selector-container,
.ai-buttons,
.ai-speed-control {
    display: flex;
    align-items: center;
    gap: 10px;
}

.display-mode-control,
.number-mode-control,
.edit-mode-control {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #5a5a5c;
    font-weight: 500;
    white-space: nowrap;
}

.ai-buttons {
    gap: 10px;
}

#ai-selector {
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid var(--cell-bg-color);
    background: #fff;
    color: var(--text-color-dark);
    font-size: 0.9rem;
    cursor: pointer;
}

.action-btn {
    display: inline-block;
    padding: 10px 15px;
    background: var(--accent-color);
    color: var(--text-color-light);
    border-radius: 8px;
    text-decoration: none;
    font-weight: 500;
    transition: background-color 0.3s;
}

.action-btn:hover {
    background-color: #0056b3;
}

/* --- Display Mode Toggle Switch --- */
.display-mode-control {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #5a5a5c;
    font-weight: 500;
}

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 28px;
}

.toggle-switch-checkbox {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-switch-label {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: .4s;
    border-radius: 28px;
}

.toggle-switch-label:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

.toggle-switch-checkbox:checked+.toggle-switch-label {
    background-color: var(--accent-color);
}

.toggle-switch-checkbox:checked+.toggle-switch-label:before {
    transform: translateX(22px);
}

/* --- Direction Indicators (CSS Triangles) --- */
.direction-indicator {
    position: absolute;
    width: 0;
    height: 0;
    opacity: 0;
    transition: opacity 0.2s ease-in-out;
    pointer-events: none;
    z-index: 200;
    top: 50%;
    left: 50%;
}

.direction-indicator.active {
    opacity: 1;
}

#dir-indicator-0 {
    /* Up */
    border-left: 40px solid transparent;
    border-right: 40px solid transparent;
    border-bottom: 60px solid rgba(0, 122, 255, 0.75);
    transform: translate(-50%, -50%) translateY(-280px);
}

#dir-indicator-1 {
    /* Right */
    border-top: 40px solid transparent;
    border-bottom: 40px solid transparent;
    border-left: 60px solid rgba(0, 122, 255, 0.75);
    transform: translate(-50%, -50%) translateX(280px);
}

#dir-indicator-2 {
    /* Down */
    border-left: 40px solid transparent;
    border-right: 40px solid transparent;
    border-top: 60px solid rgba(0, 122, 255, 0.75);
    transform: translate(-50%, -50%) translateY(280px);
}

#dir-indicator-3 {
    /* Left */
    border-top: 40px solid transparent;
    border-bottom: 40px solid transparent;
    border-right: 60px solid rgba(0, 122, 255, 0.75);
    transform: translate(-50%, -50%) translateX(-280px);
}


/* --- Custom Button Visibility for Game Over --- */
.game-message .continue-from-over-button {
    display: none;
}

.game-message.game-over .continue-from-over-button {
    display: inline-block;
}

.game-message.game-over .keep-playing-button {
    display: none;
}

/* PC端优化 - 防止滚动条 */
@media (min-width: 601px) {

    html,
    body {
        overflow: hidden;
        width: 100vw;
        height: 100vh;
    }

    .container {
        max-height: calc(100vh - 30px);
        overflow: visible;
    }
}

/* --- 移动端适配 --- */
@media (max-width: 600px) {

    html,
    body {
        font-size: 16px;
    }

    .container {
        gap: 8px;
        padding: 10px 5px;
        max-width: 100vw;
        max-height: 100vh;
    }

    .header-container {
        flex-direction: column;
        align-items: center;
        gap: 10px;
    }

    .logo-container {
        text-align: center;
    }

    .logo {
        font-size: 2.8rem;
    }

    .logo-subtitle {
        font-size: 0.8rem;
    }

    .new-game-header {
        align-self: center;
        margin-top: 0;
        padding: 10px 20px;
        font-size: 1rem;
    }

    .scores-container {
        gap: 5px;
    }

    .score-box {
        padding: 4px 10px;
        min-width: 50px;
    }

    .score-label {
        font-size: 0.6rem;
    }

    #current-score,
    #best-score,
    #moves-container {
        font-size: 1.1rem;
    }

    .ai-controls {
        padding: 6px 8px;
        gap: 6px;
        margin-bottom: 8px;
    }

    .ai-row-1,
    .ai-row-2 {
        gap: 4px;
        flex-wrap: nowrap;
        justify-content: space-between;
        align-items: center;
    }
    
    .ai-selector-container, .ai-buttons {
        gap: 4px;
        flex-shrink: 1;
    }
    
    .ai-buttons {
        gap: 4px;
    }
    
    #ai-selector {
        padding: 4px 6px;
        font-size: 0.7rem;
        min-width: 70px;
    }
    
    .action-btn {
        padding: 4px 8px;
        font-size: 0.7rem;
        white-space: nowrap;
    }
    
    .ai-selector-container label {
        font-size: 0.7rem;
        white-space: nowrap;
    }
    
    .display-mode-control, .number-mode-control, .edit-mode-control {
        gap: 3px;
        flex-shrink: 1;
        align-items: center;
    }
    
    .display-mode-control label,
    .number-mode-control label,
    .edit-mode-control label {
        font-size: 0.7rem;
        white-space: nowrap;
    }
    
    .toggle-switch {
        width: 30px;
        height: 18px;
    }
    
    .toggle-switch-label:before {
        height: 12px;
        width: 12px;
        left: 3px;
        bottom: 3px;
    }
    
    .toggle-switch-checkbox:checked + .toggle-switch-label:before {
        transform: translateX(12px);
    }

    .game-container {
        width: calc(100vw - 20px);
        height: calc(100vw - 20px);
        max-width: calc(100vh - 200px);
        max-height: calc(100vh - 200px);
    }

    .tile {
        transition: transform 80ms ease-out;
    }

    .grid-container {
        gap: 10px;
        padding: 10px;
        border-radius: 8px;
    }

    .grid-cell::before {
        width: 15px;
        height: 15px;
    }

    .tile-inner {
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
        will-change: transform;
        transition: transform 100ms ease-in-out;
    }

    .grid-container {
        backdrop-filter: blur(5px);
        -webkit-backdrop-filter: blur(5px);
    }

    .ai-controls {
        backdrop-filter: blur(5px);
        -webkit-backdrop-filter: blur(5px);
    }

    .score-box {
        backdrop-filter: blur(5px);
        -webkit-backdrop-filter: blur(5px);
    }

    .grid-cell {
        background: var(--cell-bg-color) !important;
        background-image: none !important;
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
    }

    .grid-cell::before {
        display: none;
    }

    .tile-new .tile-inner {
        animation: appear-simple 150ms ease, breathe-mobile 1.8s ease-in-out infinite 150ms;
        box-shadow: 0 0 12px 5px rgba(0, 122, 255, 0.7) !important;
        border: 2px solid rgba(0, 122, 255, 0.8) !important;
    }

    .tile.tile-new .tile-inner {
        animation: appear-simple 150ms ease, breathe-mobile 1.8s ease-in-out infinite 150ms;
        box-shadow: 0 0 12px 5px rgba(0, 122, 255, 0.7) !important;
        border: 2px solid rgba(0, 122, 255, 0.8) !important;
    }

    @keyframes breathe-mobile {

        0%,
        100% {
            box-shadow: 0 0 15px 6px rgba(0, 122, 255, 0.9);
            border-color: rgba(0, 122, 255, 1);
            transform: scale(1);
            opacity: 1;
        }

        50% {
            box-shadow: 0 0 25px 10px rgba(0, 122, 255, 0.3);
            border-color: rgba(0, 122, 255, 0.4);
            transform: scale(1.02);
            opacity: 0.7;
        }
    }

    @keyframes appear-simple {
        from {
            transform: scale(0.8);
            opacity: 0.5;
        }

        to {
            transform: scale(1);
            opacity: 1;
        }
    }

    .tile:not(.tile-new).tile-2 .tile-inner {
        background: #e8f4f8 !important;
        color: #2c5530 !important;
        box-shadow: none !important;
        border: none !important;
    }

    .tile:not(.tile-new).tile-4 .tile-inner {
        background: #fff3cd !important;
        color: #856404 !important;
        box-shadow: none !important;
        border: none !important;
    }
}

/*
 苹果风格动态效果动画 */
@keyframes apple-glow-blue {
    0% {
        box-shadow:
            0 0 15px rgba(0, 122, 255, 0.3),
            0 0 30px rgba(0, 122, 255, 0.2),
            var(--shadow-heavy),
            inset 0 1px 0 rgba(255, 255, 255, 0.3);
    }

    100% {
        box-shadow:
            0 0 25px rgba(0, 122, 255, 0.5),
            0 0 50px rgba(0, 122, 255, 0.3),
            var(--shadow-heavy),
            inset 0 1px 0 rgba(255, 255, 255, 0.4);
    }
}

@keyframes apple-rainbow-flow {
    0% {
        background-position: 0% 50%;
    }

    25% {
        background-position: 100% 25%;
    }

    50% {
        background-position: 0% 75%;
    }

    75% {
        background-position: 100% 50%;
    }

    100% {
        background-position: 0% 50%;
    }
}

@keyframes apple-glow-rainbow {
    0% {
        box-shadow:
            0 0 20px rgba(255, 45, 146, 0.4),
            0 0 40px rgba(255, 45, 146, 0.2),
            var(--shadow-heavy),
            inset 0 1px 0 rgba(255, 255, 255, 0.3);
    }

    20% {
        box-shadow:
            0 0 20px rgba(175, 82, 222, 0.4),
            0 0 40px rgba(175, 82, 222, 0.2),
            var(--shadow-heavy),
            inset 0 1px 0 rgba(255, 255, 255, 0.3);
    }

    40% {
        box-shadow:
            0 0 20px rgba(0, 122, 255, 0.4),
            0 0 40px rgba(0, 122, 255, 0.2),
            var(--shadow-heavy),
            inset 0 1px 0 rgba(255, 255, 255, 0.3);
    }

    60% {
        box-shadow:
            0 0 20px rgba(52, 199, 89, 0.4),
            0 0 40px rgba(52, 199, 89, 0.2),
            var(--shadow-heavy),
            inset 0 1px 0 rgba(255, 255, 255, 0.3);
    }

    80% {
        box-shadow:
            0 0 20px rgba(255, 149, 0, 0.4),
            0 0 40px rgba(255, 149, 0, 0.2),
            var(--shadow-heavy),
            inset 0 1px 0 rgba(255, 255, 255, 0.3);
    }

    100% {
        box-shadow:
            0 0 20px rgba(255, 45, 146, 0.4),
            0 0 40px rgba(255, 45, 146, 0.2),
            var(--shadow-heavy),
            inset 0 1px 0 rgba(255, 255, 255, 0.3);
    }
}

/* 防止移动端缩放和选择 */
* {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    box-sizing: border-box;
}

/* 移动端触摸优化 */
@media (max-width: 600px) {

    .action-btn,
    button,
    .retry-button,
    .keep-playing-button {
        min-height: 44px;
        min-width: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .toggle-switch {
        width: 40px;
        height: 24px;
    }

    .toggle-switch-label:before {
        height: 16px;
        width: 16px;
        left: 4px;
        bottom: 4px;
    }

    .toggle-switch-checkbox:checked+.toggle-switch-label:before {
        transform: translateX(16px);
    }

    .tile-inner {
        font-size: 1.5rem;
        border-radius: 6px;
    }

    .tile.tile-128 .tile-inner,
    .tile.tile-256 .tile-inner,
    .tile.tile-512 .tile-inner {
        font-size: 1.3rem;
    }

    .tile.tile-1024 .tile-inner,
    .tile.tile-2048 .tile-inner {
        font-size: 1.2rem;
    }

    .tile.tile-4096 .tile-inner,
    .tile.tile-8192 .tile-inner,
    .tile.tile-16384 .tile-inner {
        font-size: 1rem;
    }

    .tile.tile-32768 .tile-inner,
    .tile.tile-65536 .tile-inner,
    .tile.tile-super .tile-inner {
        font-size: 0.9rem;
    }

    /* 移动端瓦片位置适配 - 使用JavaScript动态计算 */
    .tile {
        width: calc((100% - 80px) / 4);
        height: calc((100% - 80px) / 4);
    }
}