:root {
    --bg-primary: #0a0a1a;
    --bg-secondary: #12122a;
    --accent-gold: #ffd700;
    --accent-cyan: #00d4ff;
    --accent-purple: #a855f7;
    --text-primary: #ffffff;
    --text-secondary: rgba(255,255,255,0.7);
    --grid-bg: rgba(255,255,255,0.08);
    --cell-bg: rgba(255,255,255,0.05);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    min-height: 100vh;
    background: var(--bg-primary);
    font-family: 'Noto Sans KR', sans-serif;
    color: var(--text-primary);
    overflow: hidden;
    touch-action: none;
}

/* 배경 효과 */
.bg-effects {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
}

.bg-orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(100px);
    opacity: 0.3;
}

.bg-orb:nth-child(1) {
    width: 400px;
    height: 400px;
    background: var(--accent-purple);
    top: -150px;
    right: -100px;
}

.bg-orb:nth-child(2) {
    width: 300px;
    height: 300px;
    background: var(--accent-cyan);
    bottom: -100px;
    left: -100px;
}

.container {
    position: relative;
    z-index: 10;
    max-width: 500px;
    margin: 0 auto;
    padding: 20px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* 헤더 */
header {
    text-align: center;
    margin-bottom: 20px;
}

.header-top {
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    margin-bottom: 5px;
}

.back-btn {
    position: absolute;
    left: 0;
    display: flex;
    align-items: center;
    gap: 5px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.9rem;
    transition: color 0.3s;
}

.back-btn:hover {
    color: var(--accent-gold);
}

.back-btn svg {
    width: 20px;
    height: 20px;
}

h1 {
    font-family: 'Black Han Sans', sans-serif;
    font-size: 3rem;
    background: linear-gradient(135deg, var(--accent-gold), #ff8c00);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 0.95rem;
    margin-top: 5px;
}

/* 점수판 */
.score-board {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-bottom: 20px;
}

.score-box {
    background: var(--grid-bg);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 12px;
    padding: 12px 25px;
    text-align: center;
    min-width: 100px;
}

.score-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 5px;
}

.score-value {
    font-family: 'Black Han Sans', sans-serif;
    font-size: 1.8rem;
    color: var(--accent-gold);
}

.score-box.best .score-value {
    color: var(--accent-cyan);
}

/* 게임 영역 */
.game-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.grid-container {
    position: relative;
    background: var(--grid-bg);
    border-radius: 16px;
    padding: 12px;
    border: 2px solid rgba(255,255,255,0.1);
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

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

.cell {
    width: 75px;
    height: 75px;
    background: var(--cell-bg);
    border-radius: 10px;
    border: 1px solid rgba(255,255,255,0.05);
}

.tiles-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.tile {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Black Han Sans', sans-serif;
    font-size: 2rem;
    border-radius: 10px;
    transition: left 0.12s ease-out, top 0.12s ease-out;
    z-index: 10;
}

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

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

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

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

/* 타일 색상 */
.tile-2 { background: linear-gradient(135deg, #eee4da, #e0d4c8); color: #776e65; }
.tile-4 { background: linear-gradient(135deg, #ede0c8, #e0c8a8); color: #776e65; }
.tile-8 { background: linear-gradient(135deg, #f2b179, #e89550); color: #f9f6f2; }
.tile-16 { background: linear-gradient(135deg, #f59563, #e87c3f); color: #f9f6f2; }
.tile-32 { background: linear-gradient(135deg, #f67c5f, #ea5c3f); color: #f9f6f2; }
.tile-64 { background: linear-gradient(135deg, #f65e3b, #d84315); color: #f9f6f2; }
.tile-128 { background: linear-gradient(135deg, #edcf72, #e5c250); color: #f9f6f2; font-size: 1.7rem; box-shadow: 0 0 30px rgba(237, 207, 114, 0.4); }
.tile-256 { background: linear-gradient(135deg, #edcc61, #e5bf40); color: #f9f6f2; font-size: 1.7rem; box-shadow: 0 0 30px rgba(237, 204, 97, 0.5); }
.tile-512 { background: linear-gradient(135deg, #edc850, #e5b82a); color: #f9f6f2; font-size: 1.7rem; box-shadow: 0 0 40px rgba(237, 200, 80, 0.6); }
.tile-1024 { background: linear-gradient(135deg, #edc53f, #e5b015); color: #f9f6f2; font-size: 1.4rem; box-shadow: 0 0 50px rgba(237, 197, 63, 0.7); }
.tile-2048 { background: linear-gradient(135deg, #edc22e, #ffd700); color: #f9f6f2; font-size: 1.4rem; box-shadow: 0 0 60px rgba(255, 215, 0, 0.8); animation: glow 1s ease-in-out infinite alternate; }
.tile-super { background: linear-gradient(135deg, #3c3a32, #1a1a2e); color: #f9f6f2; font-size: 1.2rem; box-shadow: 0 0 40px rgba(168, 85, 247, 0.6); }

@keyframes glow {
    from { box-shadow: 0 0 40px rgba(255, 215, 0, 0.6); }
    to { box-shadow: 0 0 60px rgba(255, 215, 0, 1); }
}

/* 컨트롤 */
.controls {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-top: 25px;
}

.btn {
    font-family: 'Jua', sans-serif;
    font-size: 1rem;
    padding: 12px 25px;
    border: none;
    border-radius: 25px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-new {
    background: linear-gradient(135deg, var(--accent-gold), #ff8c00);
    color: #000;
}

.btn-new:hover {
    transform: scale(1.05);
    box-shadow: 0 5px 20px rgba(255, 215, 0, 0.4);
}

.btn-undo {
    background: rgba(255,255,255,0.1);
    color: var(--text-primary);
    border: 1px solid rgba(255,255,255,0.2);
}

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

.btn-undo:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* 게임 오버 오버레이 */
.game-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(10, 10, 26, 0.9);
    border-radius: 16px;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.game-overlay.show {
    display: flex;
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.overlay-title {
    font-family: 'Black Han Sans', sans-serif;
    font-size: 2.5rem;
    margin-bottom: 10px;
}

.overlay-title.win {
    background: linear-gradient(135deg, var(--accent-gold), #ff8c00);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.overlay-title.lose {
    color: #ff6b6b;
}

.overlay-score {
    color: var(--text-secondary);
    margin-bottom: 20px;
}

.overlay-btn {
    font-family: 'Jua', sans-serif;
    font-size: 1.1rem;
    padding: 14px 35px;
    background: linear-gradient(135deg, var(--accent-gold), #ff8c00);
    color: #000;
    border: none;
    border-radius: 30px;
    cursor: pointer;
    transition: transform 0.2s;
}

.overlay-btn:hover {
    transform: scale(1.05);
}

/* Resume overlay */
#resumeOverlay {
    z-index: 150;
}

.overlay-title.resume-title {
    background: linear-gradient(135deg, var(--accent-cyan), #00a0cc);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-size: 2rem;
}

.resume-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 10px;
}

.resume-buttons .overlay-btn {
    min-width: 180px;
}

.resume-buttons .resume-btn {
    background: linear-gradient(135deg, var(--accent-cyan), #00a0cc);
}

.resume-buttons .new-btn {
    background: rgba(255,255,255,0.15);
    color: var(--text-primary);
    border: 1px solid rgba(255,255,255,0.3);
}

.resume-buttons .new-btn:hover {
    background: rgba(255,255,255,0.25);
}

/* 도움말 */
.help {
    text-align: center;
    margin-top: 20px;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.help kbd {
    background: rgba(255,255,255,0.1);
    padding: 3px 8px;
    border-radius: 5px;
    font-family: inherit;
    margin: 0 2px;
}

/* 푸터 */
footer {
    text-align: center;
    padding: 20px;
    color: var(--text-secondary);
    font-size: 0.8rem;
}

footer a {
    color: var(--text-secondary);
    text-decoration: none;
}

footer a:hover {
    color: var(--accent-gold);
}

/* 모바일 대응 */
@media (max-width: 420px) {
    .container {
        padding: 15px;
    }

    h1 {
        font-size: 2.4rem;
    }

    .score-box {
        padding: 10px 18px;
        min-width: 85px;
    }

    .score-value {
        font-size: 1.5rem;
    }

    .grid-container {
        padding: 8px;
    }

    .grid {
        gap: 8px;
    }

    .cell {
        width: 65px;
        height: 65px;
    }

    .tile {
        font-size: 1.6rem;
    }

    .tile-128, .tile-256, .tile-512 { font-size: 1.4rem; }
    .tile-1024, .tile-2048 { font-size: 1.1rem; }
    .tile-super { font-size: 1rem; }

    .help {
        display: none;
    }
}

@media (max-width: 350px) {
    .cell {
        width: 58px;
        height: 58px;
    }

    .grid {
        gap: 6px;
    }

    .tile {
        font-size: 1.4rem;
    }
}