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

body {
    background-color: #0b0f19;
    color: #f8fafc;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", "HarmonyOS Sans SC", sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    min-height: 100vh;
    padding: 16px 12px 32px;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.game-wrapper {
    width: 100%;
    max-width: 400px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.header {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.back-btn {
    color: #e2e8f0;
    text-decoration: none;
    font-weight: 500;
    font-size: 13px;
    background: #1e293b;
    padding: 6px 12px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.back-btn:hover {
    background: #334155;
    border-color: rgba(255, 255, 255, 0.25);
    color: #ffffff;
}

.game-title {
    font-size: 28px;
    font-weight: 800;
    letter-spacing: -0.03em;
    background: linear-gradient(135deg, #eab308, #f97316);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.scores-container {
    display: flex;
    gap: 8px;
}

.score-box {
    background: #1e293b;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 8px;
    padding: 4px 10px;
    text-align: center;
    min-width: 60px;
}

.score-box.high {
    border-color: rgba(234, 179, 8, 0.35);
}

.score-label {
    display: block;
    font-size: 9px;
    font-weight: 700;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.score-val {
    font-size: 15px;
    font-weight: 700;
    color: #f8fafc;
}

.score-box.high .score-val {
    color: #eab308;
}

.toolbar {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
}

.subtitle {
    font-size: 13px;
    color: #94a3b8;
}

.subtitle strong {
    color: #eab308;
    font-weight: 700;
}

.toolbar-actions {
    display: flex;
    gap: 8px;
}

.action-btn {
    border: none;
    background: #1e293b;
    border: 1px solid rgba(255, 255, 255, 0.14);
    color: #f8fafc;
    font-weight: 500;
    font-size: 12px;
    padding: 6px 12px;
    border-radius: 8px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.15s ease;
}

.action-btn:hover:not(:disabled) {
    background: #334155;
    border-color: rgba(255, 255, 255, 0.25);
}

.action-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.action-btn.restart {
    background: linear-gradient(135deg, #eab308, #d97706);
    border: none;
    color: #ffffff;
    font-weight: 700;
    box-shadow: 0 4px 12px rgba(234, 179, 8, 0.35);
}

.action-btn.restart:hover {
    filter: brightness(1.08);
}

/* 2048 Board */
.grid-container {
    position: relative;
    width: 100%;
    max-width: 380px;
    aspect-ratio: 1 / 1;
    background: #181512;
    border-radius: 14px;
    padding: 12px;
    box-shadow: 0 10px 30px -5px rgba(0, 0, 0, 0.6);
    border: 2px solid rgba(255, 255, 255, 0.14);
    touch-action: none;
}

.grid-background {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: 10px;
    width: 100%;
    height: 100%;
}

.grid-cell {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
}

.tile-container {
    position: absolute;
    inset: 12px;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: 10px;
    pointer-events: none;
}

.tile {
    position: relative;
    width: 100%;
    height: 100%;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 24px;
    transition: transform 0.1s ease;
    animation: tileAppear 0.18s cubic-bezier(0.18, 0.89, 0.32, 1.28);
}

.tile.pop {
    animation: tilePop 0.2s cubic-bezier(0.18, 0.89, 0.32, 1.28);
}

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

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

/* 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: 20px; box-shadow: 0 0 10px rgba(237, 207, 114, 0.4); }
.tile-256 { background: #edcc61; color: #f9f6f2; font-size: 20px; box-shadow: 0 0 14px rgba(237, 204, 97, 0.5); }
.tile-512 { background: #edc850; color: #f9f6f2; font-size: 20px; box-shadow: 0 0 18px rgba(237, 200, 80, 0.6); }
.tile-1024 { background: #edc53f; color: #f9f6f2; font-size: 16px; box-shadow: 0 0 22px rgba(237, 197, 63, 0.7); }
.tile-2048 { background: #edc22e; color: #f9f6f2; font-size: 16px; box-shadow: 0 0 28px rgba(237, 194, 46, 0.85); animation: goldGlow 2s infinite ease-in-out; }
.tile-super { background: #3c3a32; color: #f9f6f2; font-size: 14px; }

@keyframes goldGlow {
    0%, 100% { box-shadow: 0 0 20px rgba(237, 194, 46, 0.6); }
    50% { box-shadow: 0 0 35px rgba(237, 194, 46, 1); }
}

.instructions {
    margin-top: 14px;
    color: #94a3b8;
    font-size: 12px;
    text-align: center;
}

/* Modal */
.modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(11, 15, 25, 0.92);
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

.modal-overlay.hidden {
    display: none;
}

.modal-card {
    background: #1e293b;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 16px;
    padding: 24px;
    text-align: center;
    max-width: 270px;
    width: 90%;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.7);
}

.modal-badge-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 12px;
}

.modal-title {
    font-size: 20px;
    font-weight: 700;
    color: #f8fafc;
    margin-bottom: 8px;
}

.modal-msg {
    font-size: 13px;
    color: #94a3b8;
    margin-bottom: 16px;
    line-height: 1.5;
}

.modal-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.primary-btn {
    border: none;
    background: linear-gradient(135deg, #eab308, #d97706);
    color: #ffffff;
    font-weight: 700;
    font-size: 13px;
    padding: 10px 14px;
    border-radius: 8px;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(234, 179, 8, 0.4);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: transform 0.1s ease;
}

.primary-btn:active {
    transform: scale(0.97);
}

.secondary-btn {
    display: block;
    text-decoration: none;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #e2e8f0;
    font-size: 12px;
    font-weight: 500;
    padding: 8px 12px;
    border-radius: 8px;
    cursor: pointer;
}

.secondary-btn.hidden {
    display: none;
}
