/* 基础样式 */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: "Helvetica Neue", Arial, sans-serif;
    background-color: #faf8ef;
    color: #776e65;
    margin: 0;
    padding: 15px;
    font-size: 18px;
    line-height: 1.5;
}

.container {
    max-width: 890px;
    margin: 0 auto;
    padding: 0 15px;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.header-right {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 10px;
    margin-right: 20px;
}

.language-selector-container {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 5px;
    margin-bottom: 5px;
}

.language-label {
    font-size: 14px;
    color: #776e65;
}

.flag-container {
    display: flex;
    gap: 5px;
}

.flag-button {
    width: 30px;
    height: 20px;
    padding: 0;
    border: 1px solid #bbada0;
    border-radius: 3px;
    background: none;
    cursor: pointer;
    overflow: hidden;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.flag-button:hover {
    transform: scale(1.1);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
}

.flag-button.active {
    box-shadow: 0 0 0 2px #8f7a66;
    transform: scale(1.1);
}

.flag-icon {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.header-left {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

h1 {
    font-size: 60px;
    font-weight: bold;
    margin: 0;
    color: #776e65;
    display: flex;
    align-items: center;
}

h1 span {
    font-size: 28px;
    margin-left: 5px;
}

.score-container {
    display: flex;
    gap: 10px;
    margin-top: 0;
    margin-left: auto;
    margin-right: 20px;
}

.score-box {
    position: relative;
    background: #bbada0;
    padding: 10px 15px;
    border-radius: 5px;
    color: white;
    text-align: center;
    min-width: 80px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.score-label {
    display: block;
    font-size: 14px;
    color: #eee4da;
}

#score, #best-score {
    font-size: 20px;
    font-weight: bold;
}

.game-intro {
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
    justify-content: space-between;
    padding-right: 0; /* 确保没有额外的右侧填充 */
}

/* 使p元素不会占用太多空间 */
.game-intro p {
    margin-right: 0;
    margin-bottom: 0;
    flex-grow: 1;
    max-width: calc(100% - 350px); /* 为score-container留出足够空间 */
}

button {
    background: #8f7a66;
    color: white;
    border: none;
    border-radius: 3px;
    padding: 10px 20px;
    font-size: 16px;
    cursor: pointer;
    transition: background 0.2s ease;
}

button:hover {
    background: #9f8b77;
}

#new-game-button {
    min-width: 140px;
    white-space: nowrap;
}

.game-wrapper {
    display: flex;
    gap: 15px;
    margin-bottom: 20px;
}

.game-container {
    position: relative;
    background: #bbada0;
    padding: 12px;
    border-radius: 6px;
    margin-bottom: 0;
    width: calc(100% - 250px);
    box-sizing: border-box;
    flex-shrink: 0;
}

/* 侧边排行榜样式 */
.side-leaderboard {
    width: 235px;
    background-color: #bbada0; /* 与游戏容器背景色保持一致 */
    border-radius: 6px;
    padding: 15px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    flex-shrink: 0;
    margin-top: 0;
    height: 420px;
    margin-right: 20px; /* 和container的右padding保持一致 */
}

.game-message {
    display: none;
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    background: rgba(238, 228, 218, 0.73);
    z-index: 100;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    animation: fade-in 800ms ease;
}

.game-message p {
    font-size: 48px;
    font-weight: bold;
    margin-bottom: 5px;
}

.game-message .score-result {
    font-size: 32px;
    margin-bottom: 20px;
    animation: score-pop 0.8s ease;
}

@keyframes score-pop {
    0% {
        transform: scale(0.5);
        opacity: 0;
    }
    50% {
        transform: scale(1.2);
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.game-message .score-result .final-score {
    font-weight: bold;
    color: #776e65;
    font-size: 38px;
    animation: highlight 1s ease infinite alternate;
}

@keyframes highlight {
    from { color: #776e65; }
    to { color: #f67c5f; }
}

.game-message .actions {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.game-message .actions button {
    margin: 0 5px;
    padding: 10px 15px;
    min-width: 120px;
    transition: all 0.2s ease;
}

.game-message .actions button:hover {
    transform: translateY(-2px);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

.game-message.game-won,
.game-message.game-over {
    display: flex;
}

.game-message.game-won {
    background: rgba(237, 194, 46, 0.5);
    color: #f9f6f2;
}

.game-message.game-over {
    background: rgba(238, 228, 218, 0.9);
}

.game-message.game-won .confetti {
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
    animation-duration: 4s !important;
}

.game-message.game-won .confetti.color-1 { background-color: #ffcc00; border-bottom-color: #ffcc00; }
.game-message.game-won .confetti.color-2 { background-color: #ff9900; border-bottom-color: #ff9900; }
.game-message.game-won .confetti.color-3 { background-color: #ff6600; border-bottom-color: #ff6600; }
.game-message.game-won .confetti.color-4 { background-color: #edc22e; border-bottom-color: #edc22e; }
.game-message.game-won .confetti.color-5 { background-color: #ffd700; border-bottom-color: #ffd700; }
.game-message.game-won .confetti.color-6 { background-color: #ffeb3b; border-bottom-color: #ffeb3b; }

.game-message .global-ranking {
    font-size: 24px;
    margin-bottom: 20px;
    animation: fade-in 0.8s ease;
}

.game-message .global-ranking .rank-number {
    font-weight: bold;
    color: #776e65;
    font-size: 28px;
    animation: pulse 1.5s ease infinite alternate;
}

@keyframes pulse {
    from { color: #776e65; transform: scale(1); }
    to { color: #f67c5f; transform: scale(1.1); }
}

.grid-container {
    position: relative;
    z-index: 1;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-gap: 12px;
}

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

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

.grid-cell {
    width: 100px;
    height: 100px;
    border-radius: 5px;
    background-color: #cdc1b4;
}

.tile-container {
    position: absolute;
    top: 12px;
    left: 12px;
    right: 12px;
    bottom: 12px;
    z-index: 2;
}

.tile {
    position: absolute;
    width: 100px;
    height: 100px;
    border-radius: 5px;
    text-align: center;
    font-weight: bold;
    z-index: 10;
    font-size: 50px;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: transform 100ms ease, opacity 100ms ease;
}

/* 根据示例图片的配色 */
.tile-2 {
    background-color: #eee4da;
    color: #776e65;
}

.tile-4 {
    background-color: #ede0c8;
    color: #776e65;
}

.tile-8 {
    background-color: #f2b179;
    color: #f9f6f2;
}

.tile-16 {
    background-color: #f59563;
    color: #f9f6f2;
}

.tile-32 {
    background-color: #f67c5f;
    color: #f9f6f2;
}

.tile-64 {
    background-color: #f65e3b;
    color: #f9f6f2;
}

.tile-128 {
    background-color: #edcf72;
    color: #f9f6f2;
    font-size: 42px;
}

.tile-256 {
    background-color: #edcc61;
    color: #f9f6f2;
    font-size: 42px;
}

.tile-512 {
    background-color: #edc850;
    color: #f9f6f2;
    font-size: 42px;
}

.tile-1024 {
    background-color: #edc53f;
    color: #f9f6f2;
    font-size: 34px;
}

.tile-2048 {
    background-color: #edc22e;
    color: #f9f6f2;
    font-size: 34px;
}

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

.tile-new {
    animation: appear 200ms ease;
}

.tile-merged {
    z-index: 20;
    animation: pop 200ms ease;
}

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

@keyframes pop {
    0% {
        transform: scale(0.8);
    }
    50% {
        transform: scale(1.1);
    }
    100% {
        transform: scale(1);
    }
}

@keyframes fade-in {
    0% {
        opacity: 0;
    }
    100% {
        opacity: 1;
    }
}

.game-explanation {
    margin-bottom: 10px;
    font-size: 16px;
    line-height: 1.5;
    max-width: 850px;
    margin: 0 auto 10px auto;
}

.game-explanation strong {
    color: #776e65;
}

footer {
    text-align: center;
    margin-top: 10px;
    font-size: 14px;
    color: #a09a91;
}

footer a {
    color: #8f7a66;
    text-decoration: none;
}

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

/* 中等屏幕尺寸响应式调整 */
@media screen and (max-width: 880px) {
    .header-right {
        margin-right: 0; /* 中等屏幕下不需要右边距 */
    }
    
    .game-intro {
        flex-wrap: wrap;
    }
    
    .score-container {
        margin-top: 10px;
        margin-left: 0;
        margin-right: 0; /* 中等屏幕下不需要右边距 */
        width: 100%;
        order: 3;
    }
    
    .game-intro p {
        flex-basis: calc(100% - 120px);
        max-width: 100%; /* 中等屏幕尺寸下占满宽度 */
        order: 2;
    }
    
    #new-game-button {
        min-width: 160px;
        order: 1;
    }

    .game-wrapper {
        flex-direction: column;
    }
    
    .game-container {
        width: 100%;
        margin-bottom: 10px;
    }
    
    .side-leaderboard {
        width: 100%;
    }
}

/* 小屏幕响应式设计 */
@media screen and (max-width: 520px) {
    body {
        padding: 8px;
        font-size: 16px;
    }

    .container {
        max-width: 320px;
    }

    h1 {
        font-size: 40px;
    }

    h1 span {
        font-size: 20px;
    }

    .header-right {
        gap: 5px;
        margin-right: 0;
    }

    .language-selector-container {
        margin-bottom: 3px;
    }

    .language-label {
        font-size: 12px;
    }

    .flag-button {
        width: 25px;
        height: 16px;
    }

    .grid-cell, .tile {
        width: 70px;
        height: 70px;
    }

    .tile {
        font-size: 35px;
    }

    .tile-128, .tile-256, .tile-512 {
        font-size: 30px;
    }

    .tile-1024, .tile-2048 {
        font-size: 24px;
    }

    .tile-super {
        font-size: 20px;
    }

    .game-message p {
        font-size: 30px;
    }

    .game-intro {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    
    .game-intro p {
        margin-right: 0;
        margin-bottom: 0;
        flex-grow: 0;
        max-width: 100%;
        order: 2;
    }
    
    .score-container {
        margin-left: 0;
        margin-right: 0; /* 小屏幕下不需要右边距 */
        width: 100%;
        order: 3;
    }
    
    #new-game-button {
        min-width: 100%;
        order: 1;
    }

    .game-message .score-result {
        font-size: 24px;
    }
    
    .game-message .score-result .final-score {
        font-size: 28px;
    }
    
    .game-message .actions {
        flex-direction: column;
        gap: 8px;
    }
    
    .confetti {
        width: 8px;
        height: 8px;
    }
    
    .confetti.triangle {
        border-left: 6px solid transparent;
        border-right: 6px solid transparent;
        border-bottom: 12px solid;
    }

    .game-message .global-ranking {
        font-size: 20px;
    }
    
    .game-message .global-ranking .rank-number {
        font-size: 24px;
    }
}

/* 撒花动画效果 */
.confetti-container {
    position: fixed; /* 改为fixed，覆盖整个视窗 */
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 9999; /* 极高的z-index值确保在所有元素之上 */
    pointer-events: none; /* 允许点击穿透 */
    overflow: hidden;
}

.confetti {
    position: absolute;
    width: 12px;
    height: 12px;
    background-color: #f2b179;
    opacity: 0.9;
    animation: 3s ease-out forwards;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

/* 不同形状和颜色的纸屑 */
.confetti.square {
    border-radius: 0;
    animation-name: confetti-square;
}

.confetti.circle {
    border-radius: 50%;
    animation-name: confetti-circle;
}

.confetti.triangle {
    width: 0;
    height: 0;
    background-color: transparent;
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-bottom: 16px solid;
    animation-name: confetti-triangle;
}

@keyframes confetti-square {
    0% {
        transform: translateY(-10px) translateX(-5px) rotate(0deg) scale(0.8);
        opacity: 0;
    }
    5% {
        opacity: 1;
    }
    25% {
        transform: translateY(25vh) translateX(20px) rotate(90deg) scale(1);
    }
    50% {
        transform: translateY(50vh) translateX(-15px) rotate(180deg) scale(1.2);
    }
    75% {
        transform: translateY(75vh) translateX(10px) rotate(270deg) scale(1.1);
        opacity: 0.7;
    }
    100% {
        transform: translateY(100vh) translateX(-5px) rotate(360deg) scale(1);
        opacity: 0;
    }
}

@keyframes confetti-circle {
    0% {
        transform: translateY(-10px) translateX(5px) rotate(0deg) scale(0.8);
        opacity: 0;
    }
    5% {
        opacity: 1;
    }
    25% {
        transform: translateY(25vh) translateX(-15px) rotate(90deg) scale(1);
    }
    50% {
        transform: translateY(50vh) translateX(10px) rotate(180deg) scale(1.2);
    }
    75% {
        transform: translateY(75vh) translateX(-20px) rotate(270deg) scale(1.1);
        opacity: 0.7;
    }
    100% {
        transform: translateY(100vh) translateX(15px) rotate(360deg) scale(1);
        opacity: 0;
    }
}

@keyframes confetti-triangle {
    0% {
        transform: translateY(-10px) translateX(0) rotate(0deg) scale(0.8);
        opacity: 0;
    }
    5% {
        opacity: 1;
    }
    25% {
        transform: translateY(25vh) translateX(-25px) rotate(45deg) scale(1);
    }
    50% {
        transform: translateY(50vh) translateX(20px) rotate(90deg) scale(1.2);
    }
    75% {
        transform: translateY(75vh) translateX(-15px) rotate(135deg) scale(1.1);
        opacity: 0.7;
    }
    100% {
        transform: translateY(100vh) translateX(10px) rotate(180deg) scale(1);
        opacity: 0;
    }
}

.confetti.color-1 { background-color: #f67c5f; border-bottom-color: #f67c5f; }
.confetti.color-2 { background-color: #f59563; border-bottom-color: #f59563; }
.confetti.color-3 { background-color: #f2b179; border-bottom-color: #f2b179; }
.confetti.color-4 { background-color: #edcf72; border-bottom-color: #edcf72; }
.confetti.color-5 { background-color: #edc22e; border-bottom-color: #edc22e; }
.confetti.color-6 { background-color: #edc850; border-bottom-color: #edc850; }

/* 媒体查询中的撒花样式调整 */
@media screen and (max-width: 520px) {
    .game-message .score-result {
        font-size: 24px;
    }
}

/* 分享容器样式 */
.share-container {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.7);
    z-index: 200;
    justify-content: center;
    align-items: center;
}

.share-container.active,
.share-container[style*="display: flex"] {
    display: flex;
    animation: fade-in 0.3s ease;
}

.share-content {
    background-color: #faf8ef;
    border-radius: 6px;
    padding: 20px;
    width: 90%;
    max-width: 500px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
    position: relative;
    text-align: center;
}

.share-title {
    color: #776e65;
    font-size: 22px;
    margin-bottom: 15px;
}

.share-preview {
    background-color: #eee4da;
    border-radius: 6px;
    padding: 10px;
    margin-bottom: 20px;
    max-height: 60vh;
    overflow: auto;
    display: flex;
    justify-content: center;
}

#share-image-container {
    background-color: white;
    border-radius: 4px;
    padding: 2px;
    box-shadow: 0 1px 5px rgba(0, 0, 0, 0.1);
    display: inline-block;
}

#share-image {
    max-width: 100%;
    max-height: 50vh;
    border-radius: 3px;
}

.share-actions {
    display: flex;
    justify-content: center;
    margin-bottom: 15px;
}

.share-button {
    background-color: #8f7a66;
    color: white;
    border: none;
    border-radius: 4px;
    padding: 10px 20px;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 200px;
}

.share-button:hover {
    background-color: #9f8b77;
    transform: translateY(-2px);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

.share-tip {
    color: #a09a91;
    font-size: 14px;
    margin: 0;
}

/* 响应式调整 */
@media screen and (max-width: 520px) {
    .share-content {
        padding: 15px;
    }
    
    .share-title {
        font-size: 18px;
    }
    
    .share-button {
        min-width: 180px;
        font-size: 14px;
    }
    
    .share-tip {
        font-size: 12px;
    }
}

/* 社交媒体分享样式 */
.social-share-container {
    margin-top: 20px;
    margin-bottom: 20px;
    text-align: center;
    background-color: #f4f0e8;
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
}

.social-share-container h4 {
    color: #776e65;
    font-size: 18px;
    margin-bottom: 15px;
    font-weight: bold;
}

.social-buttons {
    display: flex;
    justify-content: center;
    gap: 24px;
    flex-wrap: wrap;
    margin: 10px auto;
    max-width: 320px;
}

.social-button {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    color: white;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.25);
}

.social-button:hover {
    transform: translateY(-4px);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.35);
}

.social-button svg {
    width: 36px;
    height: 36px;
}

.social-button.twitter {
    background-color: #1DA1F2;
}

.social-button.meta {
    background-color: #0668E1;
}

.social-button.linkedin {
    background-color: #0A66C2;
}

.social-button.reddit {
    background-color: #FF4500;
}

/* 响应式调整 */
@media screen and (max-width: 520px) {
    .social-button {
        width: 52px;
        height: 52px;
    }
    
    .social-button svg {
        width: 32px;
        height: 32px;
    }
    
    .social-share-container h4 {
        font-size: 14px;
    }
}

/* 复制成功提示样式 */
.copied-message {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    background-color: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 10px 20px;
    border-radius: 4px;
    font-size: 16px;
    z-index: 9999;
    animation: fade-in 0.3s ease;
}

.copied-message.fade-out {
    animation: fade-out 0.5s ease;
}

@keyframes fade-out {
    from {
        opacity: 1;
    }
    to {
        opacity: 0;
    }
}

/* 滚动条样式 */
.leaderboard-list::-webkit-scrollbar {
    width: 5px;
}

.leaderboard-list::-webkit-scrollbar-track {
    background: #eee4da;
    border-radius: 3px;
}

.leaderboard-list::-webkit-scrollbar-thumb {
    background: #8f7a66;
    border-radius: 3px;
}

.leaderboard-list::-webkit-scrollbar-thumb:hover {
    background: #776e65;
} 