/* Reset and base styles */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Arial', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #776e65;
    margin: 0;
    padding: 20px;
    min-height: 100vh;
    max-height: 100vh;
    /* 防止移动端的滚动和缩放 */
    overflow: hidden;
    touch-action: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    /* 防止iOS Safari的橡皮筋效果 */
    position: fixed;
    width: 100%;
    height: 100%;
}

.container {
    max-width: 500px;
    margin: 0 auto;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.3);
    /* 在移动设备上确保正确显示 */
    max-height: calc(100vh - 40px);
    overflow-y: auto;
    position: relative;
}

/* Header */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

h1 {
    color: #776e65;
    font-size: 48px;
    font-weight: bold;
    margin: 0;
}

.scores {
    display: flex;
    gap: 10px;
}

.score-container {
    background: #bbada0;
    padding: 10px 20px;
    border-radius: 5px;
    text-align: center;
    min-width: 70px;
}

.score-label {
    color: #eee4da;
    font-size: 12px;
    font-weight: bold;
    margin-bottom: 5px;
}

#score, #best-score {
    color: white;
    font-size: 18px;
    font-weight: bold;
}

/* Game intro */
.game-intro {
    margin-bottom: 20px;
    padding: 15px;
    background: #f9f6f2;
    border-radius: 5px;
    font-size: 14px;
    line-height: 1.4;
}

/* Game container */
.game-container {
    position: relative;
    background: #bbada0;
    border-radius: 10px;
    padding: 10px;
    margin-bottom: 20px;
}

.grid-container {
    position: relative;
    z-index: 1;
}

.grid-row {
    display: flex;
    margin-bottom: 10px;
}

.grid-row:last-child {
    margin-bottom: 0;
}

.grid-cell {
    width: 100px;
    height: 100px;
    background: rgba(238, 228, 218, 0.35);
    border-radius: 5px;
    margin-right: 10px;
}

.grid-cell:last-child {
    margin-right: 0;
}

/* Tiles */
.tile-container {
    position: absolute;
    top: 10px;
    left: 10px;
    z-index: 2;
}

.tile {
    position: absolute;
    width: 100px;
    height: 100px;
    background: #eee4da;
    border-radius: 5px;
    font-size: 32px;
    font-weight: bold;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: transform 0.2s ease-out, background-color 0.3s ease-out, color 0.3s ease-out;
    will-change: transform;
    backface-visibility: hidden;
    color: #776e65;
}

/* Tile colors */
.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: 28px; }
.tile-256 { background: #edcc61; color: #f9f6f2; font-size: 28px; }
.tile-512 { background: #edc850; color: #f9f6f2; font-size: 28px; }
.tile-1024 { background: #edc53f; color: #f9f6f2; font-size: 24px; }
.tile-2048 { background: #edc22e; color: #f9f6f2; font-size: 24px; }

.tile-super { background: #3c3a32; color: #f9f6f2; font-size: 20px; }

/* Animations */
.tile-new {
    animation: appear 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.tile-merged {
    animation: pop 0.35s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* Dynamic transition durations will be set via JavaScript */
.tile-moving {
    z-index: 3;
}

@keyframes appear {
    0% { 
        opacity: 0;
    }
    100% { 
        opacity: 1;
    }
}

@keyframes pop {
    0% { 
        transform: scale(1); 
    }
    40% { 
        transform: scale(1.15); 
    }
    70% {
        transform: scale(1.05);
    }
    100% { 
        transform: scale(1); 
    }
}

/* Merge animation effects */
@keyframes mergeDissolve {
    0% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.7;
        transform: scale(0.9);
    }
    100% {
        opacity: 0;
        transform: scale(0.6);
    }
}

@keyframes mergeAppear {
    0% {
        opacity: 0;
        transform: scale(0);
    }
    50% {
        opacity: 0.8;
        transform: scale(1.2);
    }
    80% {
        opacity: 1;
        transform: scale(1.1);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

.tile-merging-out {
    animation: mergeDissolve 0.2s ease-in forwards;
}

.tile-merging-in {
    animation: mergeAppear 0.25s ease-out forwards;
}

/* Game message */
.game-message {
    display: none;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(255, 255, 255, 0.95);
    padding: 30px;
    border-radius: 10px;
    text-align: center;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.3);
    z-index: 100;
}

.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: 24px;
    font-weight: bold;
    margin-bottom: 20px;
}

.lower {
    margin-top: 20px;
}

/* Buttons */
.button, .retry-button {
    background: #8f7a66;
    color: #f9f6f2;
    border: none;
    border-radius: 5px;
    padding: 10px 20px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: background 0.2s;
}

.button:hover, .retry-button:hover {
    background: #9f8a76;
}

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

/* Footer */
footer {
    text-align: center;
    font-size: 14px;
    color: #8f7a66;
}

/* Responsive design */
@media (max-width: 520px) {
    .container {
        margin: 0 10px;
        padding: 15px;
    }
    
    h1 {
        font-size: 36px;
    }
    
    .grid-cell, .tile {
        width: 70px;
        height: 70px;
    }
    
    .tile {
        font-size: 24px;
    }
    
    .tile-128, .tile-256, .tile-512 {
        font-size: 20px;
    }
    
    .tile-1024, .tile-2048 {
        font-size: 18px;
    }
    
    .tile-super {
        font-size: 16px;
    }
}

/* Position classes are no longer needed - positions are set directly via JavaScript */

/* Easter Egg Balloon Styles */

/* 彩蛋二维码浮层样式（第一层） */
.easter-egg-qr-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9998;
    animation: fadeIn 0.3s ease-out;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.easter-egg-qr-content {
    position: relative;
    background: white;
    border-radius: 15px;
    padding: 20px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.qr-code-container {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.qr-code-image {
    position: relative;
    margin: 15px 0;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 10px;
    background: white;
    cursor: pointer;
    transition: transform 0.2s ease;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
}

.qr-code-image:hover {
    transform: scale(1.05);
}

.qr-code-img {
    width: 200px;
    height: 200px;
    display: block;
    margin: 0 auto;
}

/* 点击引导动画样式 */
.click-guide {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    z-index: 10;
}

.click-indicator {
    width: 20px;
    height: 20px;
    border: 3px solid #ff6b6b;
    border-radius: 50%;
    background: rgba(255, 107, 107, 0.2);
    animation: clickPulse 2s infinite;
    position: relative;
}

.click-indicator::before {
    content: '👆';
    position: absolute;
    top: -40px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 20px;
    animation: clickBounce 2s infinite;
}

.click-ripple {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 20px;
    height: 20px;
    border: 2px solid #ff6b6b;
    border-radius: 50%;
    animation: clickRipple 2s infinite;
}

@keyframes clickPulse {
    0%, 100% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
    }
    50% {
        transform: translate(-50%, -50%) scale(1.2);
        opacity: 0.7;
    }
}

@keyframes clickBounce {
    0%, 20%, 50%, 80%, 100% {
        transform: translateX(-50%) translateY(0);
    }
    40% {
        transform: translateX(-50%) translateY(-10px);
    }
    60% {
        transform: translateX(-50%) translateY(-5px);
    }
}

@keyframes clickRipple {
    0% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
    }
    100% {
        transform: translate(-50%, -50%) scale(3);
        opacity: 0;
    }
}

/* 彩蛋搭车浮层样式（第二层） */
.easter-egg-dache-overlay {
    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: 9999;
    animation: fadeIn 0.3s ease-out;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.easter-egg-dache-content {
    position: relative;
    background: white;
    border-radius: 15px;
    padding: 20px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    width: 55vw;
    height: 65vh;
    max-height: 600px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    overflow-y: auto;
}

.dache-image {
    max-width: 100%;
    max-height: 250px;
    height: auto;
    border-radius: 10px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    object-fit: contain;
    margin-bottom: 10px;
}

.close-btn {
    position: absolute;
    top: 10px;
    right: 15px;
    width: 30px;
    height: 30px;
    background: #ff4757;
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 20px;
    font-weight: bold;
    transition: all 0.2s ease;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.close-btn:hover {
    background: #ff3742;
    transform: scale(1.1);
}

.fade-out {
    animation: fadeOut 0.3s ease-in forwards;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes fadeOut {
    from {
        opacity: 1;
        transform: scale(1);
    }
    to {
        opacity: 0;
        transform: scale(0.9);
    }
}

/* 选择按钮样式 */
.choice-buttons {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-top: 20px;
}

.choice-btn {
    padding: 12px 30px;
    border: none;
    border-radius: 25px;
    font-size: 18px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 1px;
    position: relative;
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.choice-btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    transition: all 0.3s ease;
}

.choice-btn:hover::before {
    width: 100px;
    height: 100px;
}

.no-btn {
    background: linear-gradient(135deg, #ff6b6b, #ff5252);
    color: white;
    box-shadow: 0 4px 15px rgba(255, 107, 107, 0.4);
}

.no-btn:hover {
    background: linear-gradient(135deg, #ff5252, #f44336);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(255, 107, 107, 0.6);
}

.yes-btn {
    background: linear-gradient(135deg, #ff6b35, #f7931e);
    color: white;
    box-shadow: 0 6px 20px rgba(255, 107, 53, 0.5);
    font-size: 20px;
    padding: 15px 40px;
    position: relative;
    animation: pulse 2s infinite;
}

.yes-btn:hover {
    background: linear-gradient(135deg, #f7931e, #ff6b35);
    transform: translateY(-3px) scale(1.05);
    box-shadow: 0 8px 25px rgba(255, 107, 53, 0.7);
}

@keyframes pulse {
    0%, 100% {
        box-shadow: 0 6px 20px rgba(255, 107, 53, 0.5);
    }
    50% {
        box-shadow: 0 8px 25px rgba(255, 107, 53, 0.8);
    }
}

.choice-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

/* 价格信息样式 */
.price-info {
    margin-top: 15px;
    text-align: center;
    animation: slideIn 0.4s ease-out;
    width: 100%;
    flex: 1;
}

.price-title {
    font-size: 18px;
    font-weight: bold;
    color: #333;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 2px solid #4ecdc4;
    display: inline-block;
}

.price-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.price-item {
    background: linear-gradient(135deg, #f8f9fa, #e9ecef);
    padding: 8px 16px;
    border-radius: 12px;
    border-left: 3px solid #4ecdc4;
    font-size: 14px;
    font-weight: 600;
    color: #495057;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
    transition: all 0.2s ease;
}

.price-item:hover {
    transform: translateX(5px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.price-item:first-child {
    background: linear-gradient(135deg, #fff3cd, #ffeaa7);
    border-left-color: #f39c12;
    color: #856404;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* 图片加载动画样式 */
.image-container {
    position: relative;
    width: 100%;
    height: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 200px;
}

.loading-spinner {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #4ecdc4;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 10px;
}

.loading-text {
    color: #666;
    font-size: 14px;
    font-weight: 500;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* 图片淡入效果 */
.dache-image {
    transition: opacity 0.3s ease-in-out;
}

.dache-image[style*="display: block"] {
    animation: imageFadeIn 0.5s ease-in-out;
}

@keyframes imageFadeIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}


/* 移动端适配 */
@media (max-width: 768px) {
    .easter-egg-qr-content {
        padding: 15px;
    }
    
    .qr-code-img {
        width: 160px;
        height: 160px;
    }
    
    .easter-egg-dache-content {
        width: 80vw;
        height: 60vh;
        padding: 15px;
    }
    
    .close-btn {
        width: 35px;
        height: 35px;
        font-size: 22px;
    }
    
    .choice-btn {
        padding: 10px 25px;
        font-size: 16px;
    }
    
    .yes-btn {
        font-size: 18px;
        padding: 12px 35px;
    }
    
    .choice-buttons {
        gap: 15px;
        margin-top: 15px;
    }
    
    .price-title {
        font-size: 18px;
    }
    
    .price-item {
        font-size: 14px;
        padding: 8px 15px;
    }
}