* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    min-height: 100vh;
    overflow: hidden;
    position: relative;
}

.background-layer {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    z-index: -1;
    transition: background-image 0.5s ease;
}

/* 返回按钮 */
.back-btn {
    position: fixed;
    top: 15px;
    right: 15px;
    padding: 10px 20px;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    text-decoration: none;
    border-radius: 25px;
    font-size: 14px;
    z-index: 1000;
    transition: all 0.3s ease;
    border: 2px solid rgba(255, 255, 255, 0.3);
}

.back-btn:hover {
    background: rgba(0, 0, 0, 0.8);
    border-color: rgba(255, 255, 255, 0.6);
    transform: scale(1.05);
}

/* 主题切换按钮 */
.theme-toggle-btn {
    position: fixed;
    top: 15px;
    right: 140px;
    padding: 10px 18px;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 25px;
    font-size: 14px;
    z-index: 1000;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 8px;
}

.theme-toggle-btn:hover {
    background: rgba(0, 0, 0, 0.8);
    border-color: rgba(255, 255, 255, 0.6);
    transform: scale(1.05);
}

/* 登录界面 */
.login-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 5000;
}

.login-box {
    background: linear-gradient(145deg, rgba(255, 255, 255, 0.2), rgba(255, 255, 255, 0.05));
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 25px;
    padding: 50px 40px;
    text-align: center;
    backdrop-filter: blur(15px);
    max-width: 400px;
    width: 90%;
}

.login-box h2 {
    color: #fff;
    font-size: 2em;
    margin-bottom: 30px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

.login-input-group {
    margin-bottom: 20px;
}

.login-input-group input {
    width: 100%;
    padding: 15px 20px;
    font-size: 1.1em;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 15px;
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    text-align: center;
    outline: none;
    transition: all 0.3s ease;
}

.login-input-group input::placeholder {
    color: rgba(255, 255, 255, 0.5);
}

.login-input-group input:focus {
    border-color: #fbbf24;
    box-shadow: 0 0 20px rgba(251, 191, 36, 0.3);
}

.login-btn {
    width: 100%;
    padding: 15px;
    font-size: 1.2em;
    background: linear-gradient(145deg, #22c55e, #16a34a);
    border: none;
    border-radius: 15px;
    color: #fff;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: bold;
}

.login-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 30px rgba(34, 197, 94, 0.4);
}

.login-hint {
    color: #ef4444;
    margin-top: 15px;
    font-size: 0.9em;
    min-height: 20px;
}

/* 主容器 */
.container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
}

h1 {
    color: #fff;
    font-size: 3em;
    margin-bottom: 50px;
    text-shadow: 3px 3px 6px rgba(0, 0, 0, 0.5);
    text-align: center;
}

.game-buttons {
    display: flex;
    gap: 30px;
    flex-wrap: wrap;
    justify-content: center;
}

.game-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 30px 40px;
    background: linear-gradient(145deg, rgba(255, 255, 255, 0.2), rgba(255, 255, 255, 0.05));
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
}

.game-btn:hover {
    transform: translateY(-10px);
    background: linear-gradient(145deg, rgba(255, 255, 255, 0.3), rgba(255, 255, 255, 0.1));
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.3);
}

.game-icon {
    width: 80px;
    height: 80px;
    margin-bottom: 15px;
    display: block;
}

.snake-icon {
    background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><circle cx="50" cy="50" r="40" fill="%2322c55e"/><circle cx="35" cy="40" r="8" fill="%23000"/><circle cx="65" cy="40" r="8" fill="%23000"/><path d="M30 60 Q50 75 70 60" stroke="%23000" stroke-width="4" fill="none"/></svg>') center/contain no-repeat;
}

.game-2048-icon {
    background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><rect x="10" y="10" width="35" height="35" rx="5" fill="%23edc22e"/><rect x="55" y="10" width="35" height="35" rx="5" fill="%23edc22e"/><rect x="10" y="55" width="35" height="35" rx="5" fill="%23edc22e"/><rect x="55" y="55" width="35" height="35" rx="5" fill="%23edc22e"/><text x="50" y="42" text-anchor="middle" font-size="18" font-weight="bold" fill="%23776011">2048</text><text x="50" y="87" text-anchor="middle" font-size="18" font-weight="bold" fill="%23776011">2048</text></svg>') center/contain no-repeat;
}

.trophy-icon {
    background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><path d="M30 20 H70 V50 C70 65 60 75 50 80 C40 75 30 65 30 50 V20" fill="%23fbbf24"/><rect x="40" y="80" width="20" height="10" fill="%23fbbf24"/><rect x="30" y="88" width="40" height="8" rx="2" fill="%23d97706"/><path d="M30 25 H15 C15 25 10 35 15 45 C20 50 25 45 30 40" fill="%23fbbf24"/><path d="M70 25 H85 C85 25 90 35 85 45 C80 50 75 45 70 40" fill="%23fbbf24"/></svg>') center/contain no-repeat;
}

.game-name {
    color: #fff;
    font-size: 1.5em;
    font-weight: bold;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

/* 游戏容器 */
.game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
    min-height: 100vh;
}

.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    max-width: 500px;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 10px;
}

.score-display {
    display: flex;
    gap: 20px;
    background: rgba(0, 0, 0, 0.5);
    padding: 10px 20px;
    border-radius: 10px;
    color: #fff;
}

.score-display strong {
    color: #fbbf24;
}

.back-menu-btn {
    padding: 10px 20px;
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.4);
    border-radius: 10px;
    color: #fff;
    cursor: pointer;
    font-size: 1em;
    transition: all 0.3s ease;
}

.back-menu-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

.game-area {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 15px;
    padding: 15px;
    backdrop-filter: blur(5px);
}

/* 贪吃蛇画布 */
#snakeCanvas {
    display: block;
    border: 3px solid rgba(255, 255, 255, 0.5);
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.5);
}

/* 2048 网格 - 带动画 */
.grid-container {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    padding: 10px;
    background: rgba(0, 0, 0, 0.4);
    border-radius: 10px;
    width: 320px;
    height: 320px;
    position: relative;
}

.tile {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2em;
    font-weight: bold;
    border-radius: 8px;
    color: #fff;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
    position: absolute;
    width: 70px;
    height: 70px;
    transition: all 0.15s ease-out;
    transform: translateZ(0);
}

.tile-new {
    animation: tileAppear 0.2s ease-out;
}

.tile-merged {
    animation: tileMerge 0.2s ease-out;
}

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

@keyframes tileMerge {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.2);
    }
    100% {
        transform: scale(1);
    }
}

.tile-2 { background: #eee4da; color: #776e65; }
.tile-4 { background: #ede0c8; color: #776e65; }
.tile-8 { background: #f2b179; }
.tile-16 { background: #f59563; }
.tile-32 { background: #f67c5f; }
.tile-64 { background: #f65e3b; }
.tile-128 { background: #edcf72; font-size: 1.8em; }
.tile-256 { background: #edcc61; font-size: 1.8em; }
.tile-512 { background: #edc850; font-size: 1.8em; }
.tile-1024 { background: #edc53f; font-size: 1.5em; }
.tile-2048 { background: #edc22e; font-size: 1.5em; }
.tile-super { background: #3c3a32; font-size: 1.3em; }

/* 手机控制按钮 */
.mobile-controls {
    margin-top: 20px;
    display: none;
}

.control-row {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin: 5px 0;
}

.control-btn {
    width: 60px;
    height: 60px;
    font-size: 1.5em;
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.4);
    border-radius: 15px;
    color: #fff;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.control-btn:active {
    background: rgba(255, 255, 255, 0.4);
    transform: scale(0.95);
}

.pause-btn {
    width: 80px;
    font-size: 0.9em;
}

/* 排行榜 */
.leaderboard-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.leaderboard-content {
    background: linear-gradient(145deg, rgba(255, 255, 255, 0.15), rgba(255, 255, 255, 0.05));
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 20px;
    padding: 30px;
    max-width: 400px;
    width: 90%;
    backdrop-filter: blur(15px);
}

.leaderboard-content h2 {
    color: #fff;
    text-align: center;
    margin-bottom: 20px;
    font-size: 1.8em;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

.tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

.tab-btn {
    flex: 1;
    padding: 12px;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 10px;
    color: #fff;
    cursor: pointer;
    font-size: 1em;
    transition: all 0.3s ease;
}

.tab-btn.active {
    background: rgba(255, 255, 255, 0.3);
    border-color: #fbbf24;
}

.tab-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.tab-content {
    max-height: 300px;
    overflow-y: auto;
}

.leaderboard-list {
    list-style: none;
    padding: 0;
}

.leaderboard-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 15px;
    margin: 5px 0;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    color: #fff;
    transition: all 0.3s ease;
}

.leaderboard-list li:hover {
    background: rgba(255, 255, 255, 0.2);
}

.leaderboard-list li:first-child {
    background: linear-gradient(145deg, rgba(251, 191, 36, 0.4), rgba(251, 191, 36, 0.2));
    border: 2px solid #fbbf24;
}

.leaderboard-list .rank {
    font-weight: bold;
    font-size: 1.2em;
    width: 30px;
}

.leaderboard-list .name {
    flex: 1;
    margin: 0 15px;
}

.leaderboard-list .score {
    font-weight: bold;
    color: #fbbf24;
    margin-right: 10px;
}

.leaderboard-list .delete-btn {
    padding: 5px 10px;
    background: rgba(239, 68, 68, 0.8);
    border: none;
    border-radius: 5px;
    color: #fff;
    cursor: pointer;
    font-size: 0.8em;
    transition: all 0.3s ease;
}

.leaderboard-list .delete-btn:hover {
    background: #ef4444;
    transform: scale(1.1);
}

.close-btn {
    width: 100%;
    margin-top: 20px;
    padding: 12px;
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.4);
    border-radius: 10px;
    color: #fff;
    cursor: pointer;
    font-size: 1em;
    transition: all 0.3s ease;
}

.close-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* 删除密码弹窗 */
.delete-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 4000;
}

.delete-modal-content {
    background: linear-gradient(145deg, rgba(255, 255, 255, 0.2), rgba(255, 255, 255, 0.05));
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 20px;
    padding: 30px;
    text-align: center;
    backdrop-filter: blur(15px);
    max-width: 350px;
    width: 90%;
}

.delete-modal-content h3 {
    color: #ef4444;
    font-size: 1.5em;
    margin-bottom: 15px;
}

.delete-modal-content p {
    color: #fff;
    margin-bottom: 15px;
}

.delete-modal-content input {
    width: 100%;
    padding: 12px 15px;
    font-size: 1em;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    text-align: center;
    outline: none;
    margin-bottom: 15px;
}

.delete-modal-content input::placeholder {
    color: rgba(255, 255, 255, 0.5);
}

.delete-modal-content input:focus {
    border-color: #ef4444;
}

.delete-modal-buttons {
    display: flex;
    gap: 10px;
}

.confirm-btn, .cancel-btn {
    flex: 1;
    padding: 12px;
    font-size: 1em;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.confirm-btn {
    background: linear-gradient(145deg, #ef4444, #dc2626);
    color: #fff;
}

.confirm-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(239, 68, 68, 0.4);
}

.cancel-btn {
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.3);
    color: #fff;
}

.cancel-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* 游戏结束弹窗 */
.game-over-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3000;
}

.modal-content {
    background: linear-gradient(145deg, rgba(255, 255, 255, 0.2), rgba(255, 255, 255, 0.05));
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 25px;
    padding: 40px;
    text-align: center;
    backdrop-filter: blur(15px);
    max-width: 350px;
    width: 90%;
}

.modal-content h2 {
    color: #fff;
    font-size: 2em;
    margin-bottom: 20px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

.modal-content p {
    color: #fff;
    font-size: 1.2em;
    margin-bottom: 20px;
}

.modal-content p strong {
    color: #fbbf24;
}

/* 历史名字快捷选择 */
.history-names {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    margin-bottom: 15px;
    max-height: 80px;
    overflow-y: auto;
}

.history-name-btn {
    padding: 6px 12px;
    background: rgba(251, 191, 36, 0.3);
    border: 1px solid rgba(251, 191, 36, 0.5);
    border-radius: 15px;
    color: #fff;
    font-size: 0.9em;
    cursor: pointer;
    transition: all 0.3s ease;
}

.history-name-btn:hover {
    background: rgba(251, 191, 36, 0.5);
    transform: scale(1.05);
}

.input-group {
    margin-bottom: 15px;
}

.input-group input {
    width: 100%;
    padding: 12px 15px;
    font-size: 1em;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    text-align: center;
    outline: none;
}

.input-group input::placeholder {
    color: rgba(255, 255, 255, 0.6);
}

.input-group input:focus {
    border-color: #fbbf24;
}

.save-btn, .restart-btn, .menu-btn {
    width: 100%;
    padding: 12px;
    margin: 5px 0;
    font-size: 1em;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.save-btn {
    background: linear-gradient(145deg, #22c55e, #16a34a);
    color: #fff;
}

.save-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(34, 197, 94, 0.4);
}

.restart-btn {
    background: linear-gradient(145deg, #3b82f6, #2563eb);
    color: #fff;
}

.restart-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(59, 130, 246, 0.4);
}

.menu-btn {
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.3);
    color: #fff;
}

.menu-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* 响应式设计 */
@media (max-width: 600px) {
    .theme-toggle-btn {
        top: 15px;
        right: 120px;
        padding: 8px 14px;
        font-size: 12px;
    }
    
    .back-btn {
        padding: 8px 14px;
        font-size: 12px;
    }
    
    h1 {
        font-size: 2em;
        margin-bottom: 30px;
    }
    
    .game-buttons {
        gap: 15px;
    }
    
    .game-btn {
        padding: 20px 30px;
    }
    
    .game-icon {
        width: 60px;
        height: 60px;
    }
    
    .game-name {
        font-size: 1.2em;
    }
    
    .game-header {
        flex-direction: column;
        gap: 15px;
    }
    
    .score-display {
        width: 100%;
        justify-content: center;
    }
    
    .mobile-controls {
        display: block;
    }
    
    .grid-container {
        width: 280px;
        height: 280px;
    }
    
    .tile {
        width: 60px;
        height: 60px;
    }
    
    #snakeCanvas {
        max-width: 100%;
        height: auto;
    }
}

@media (min-width: 601px) {
    .mobile-controls {
        display: none !important;
    }
}

/* 滚动条样式 */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.5);
}
