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

body {
    font-family: 'Arial', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0;
    margin: 0;
    overflow: hidden;
    -webkit-overflow-scrolling: touch;
    position: fixed;
    width: 100%;
    touch-action: pan-y;
    overscroll-behavior-y: contain;
    overscroll-behavior: none;
}

.game-container {
    background: white;
    border-radius: 0;
    padding: 20px;
    box-shadow: none;
    max-width: 100%;
    width: 100%;
    height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
    overscroll-behavior: none;
}

@media (min-width: 600px) {
    .game-container {
        border-radius: 20px;
        max-width: 500px;
        height: auto;
        min-height: auto;
        box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    }
    
    body {
        padding: 20px;
        position: relative;
        overflow: auto;
    }
}

header {
    text-align: center;
    margin-bottom: 20px;
}

h1 {
    color: #333;
    font-size: 3em;
    margin-bottom: 15px;
    font-weight: bold;
}

.score-container {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-bottom: 20px;
}

.score-box {
    background: #bbada0;
    padding: 10px 20px;
    border-radius: 5px;
    min-width: 100px;
    position: relative;
    overflow: hidden;
}

.score-label {
    color: #eee4da;
    font-size: 0.8em;
    font-weight: bold;
    text-transform: uppercase;
}

.score-value {
    color: white;
    font-size: 1.5em;
    font-weight: bold;
    margin-top: 5px;
}

.leaderboard-banner {
    min-width: 100px;
    height: 60px;
    padding: 10px 20px;
}

.leaderboard-rolling {
    height: 40px;
    overflow: hidden;
    position: relative;
    margin-top: 5px;
}

.leaderboard-track {
    display: flex;
    flex-direction: column;
    animation: roll 20s linear infinite;
    white-space: nowrap;
}

.leaderboard-track:hover {
    animation-play-state: paused;
}

.leaderboard-item-small {
    color: white;
    font-size: 0.9em;
    font-weight: bold;
    padding: 2px 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.leaderboard-item-small .rank {
    color: rgba(255, 255, 255, 0.8);
    margin-right: 5px;
}

.leaderboard-item-small .name {
    margin-right: 5px;
}

.leaderboard-item-small .score {
    color: #ffd700;
}

@keyframes roll {
    0% {
        transform: translateY(0);
    }
    100% {
        transform: translateY(-50%);
    }
}

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

.game-info p {
    color: #666;
    margin-bottom: 10px;
}

.new-game-btn {
    padding: 10px 20px;
    background: #8f7a66;
    color: white;
    border: none;
    border-radius: 5px;
    font-size: 1em;
    font-weight: bold;
    cursor: pointer;
    transition: background 0.3s;
}

.new-game-btn:hover {
    background: #9f8a76;
}

.game-board {
    background: #bbada0;
    border-radius: 10px;
    padding: 10px;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: 10px;
    width: 100%;
    max-width: 400px;
    aspect-ratio: 1;
    position: relative;
    touch-action: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    margin: 0 auto;
}

.cell {
    background: #cdc1b4;
    border-radius: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2em;
    font-weight: bold;
    color: #776e65;
    min-height: 100px;
}

.tile {
    position: absolute;
    background: #eee4da;
    border-radius: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2em;
    font-weight: bold;
    color: #776e65;
    transition: all 0.15s ease-in-out;
    box-sizing: border-box;
}

.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: 1.8em;
}

.tile-256 {
    background: #edcc61;
    color: #f9f6f2;
    font-size: 1.8em;
}

.tile-512 {
    background: #edc850;
    color: #f9f6f2;
    font-size: 1.8em;
}

.tile-1024 {
    background: #edc53f;
    color: #f9f6f2;
    font-size: 1.5em;
}

.tile-2048 {
    background: #edc22e;
    color: #f9f6f2;
    font-size: 1.5em;
}

.game-over {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.game-over.hidden {
    display: none;
}

.game-over-content {
    background: white;
    padding: 40px;
    border-radius: 20px;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.game-over-content h2 {
    color: #333;
    margin-bottom: 20px;
    font-size: 2em;
}

.game-over-content p {
    color: #666;
    margin-bottom: 20px;
    font-size: 1.2em;
}

.try-again-btn {
    padding: 12px 30px;
    background: #8f7a66;
    color: white;
    border: none;
    border-radius: 5px;
    font-size: 1em;
    font-weight: bold;
    cursor: pointer;
    transition: background 0.3s;
}

.try-again-btn:hover {
    background: #9f8a76;
}

@media (max-width: 600px) {
    body {
        padding: 0;
    }

    .game-container {
        padding: 15px;
        max-width: 100%;
        border-radius: 0;
    }

    h1 {
        font-size: 2em;
        margin-bottom: 10px;
    }

    .score-container {
        gap: 10px;
        margin-bottom: 15px;
    }

    .score-box {
        padding: 8px 15px;
        min-width: 80px;
    }

    .score-label {
        font-size: 0.7em;
    }

    .score-value {
        font-size: 1.2em;
    }

    .game-info {
        margin-bottom: 15px;
    }

    .game-info p {
        font-size: 0.9em;
    }

    .game-board {
        max-width: 100%;
        padding: 8px;
        gap: 8px;
    }

    .cell {
        min-height: 60px;
    }

    .tile {
        font-size: 1.2em;
    }

    .tile-128, .tile-256, .tile-512 {
        font-size: 1em;
    }

    .tile-1024, .tile-2048 {
        font-size: 0.9em;
    }
}

@media (max-width: 400px) {
    .game-board {
        padding: 5px;
        gap: 5px;
    }

    .cell {
        min-height: 50px;
    }

    .tile {
        font-size: 1em;
    }

    .tile-128, .tile-256, .tile-512 {
        font-size: 0.9em;
    }

    .tile-1024, .tile-2048 {
        font-size: 0.8em;
    }
}

/* 순위 스타일 */
.player-name-input {
    margin: 20px 0;
    display: flex;
    gap: 10px;
}

#player-name {
    flex: 1;
    padding: 10px;
    border: 2px solid #ddd;
    border-radius: 5px;
    font-size: 1em;
}

.save-btn {
    padding: 10px 20px;
    background: #27ae60;
    color: white;
    border: none;
    border-radius: 5px;
    font-weight: bold;
    cursor: pointer;
    transition: background 0.3s;
}

.save-btn:hover {
    background: #229954;
}

.leaderboard-section {
    margin-top: 20px;
    max-height: 300px;
    overflow-y: auto;
}

.leaderboard-section h3 {
    color: #333;
    margin-bottom: 15px;
    font-size: 1.3em;
}

.leaderboard-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.leaderboard-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 15px;
    background: #f8f9fa;
    border-radius: 8px;
    border-left: 4px solid #667eea;
}

.leaderboard-item.rank-1 {
    background: #fff3cd;
    border-left-color: #ffc107;
}

.leaderboard-item.rank-2 {
    background: #e2e3e5;
    border-left-color: #6c757d;
}

.leaderboard-item.rank-3 {
    background: #f8d7da;
    border-left-color: #dc3545;
}

.leaderboard-rank {
    font-weight: bold;
    color: #667eea;
    min-width: 30px;
}

.leaderboard-name {
    flex: 1;
    margin-left: 10px;
    color: #333;
}

.leaderboard-score {
    font-weight: bold;
    color: #333;
    min-width: 60px;
    text-align: right;
}

.leaderboard-btn {
    background: #bbada0;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 1em;
    font-weight: bold;
    cursor: pointer;
    transition: background 0.3s;
}

.leaderboard-btn:hover {
    background: #9d9488;
}

.leaderboard-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

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

.leaderboard-content {
    background: white;
    padding: 30px;
    border-radius: 15px;
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.leaderboard-content h3 {
    color: #333;
    margin-bottom: 20px;
    font-size: 1.5em;
    text-align: center;
}

.close-btn {
    width: 100%;
    padding: 12px;
    margin-top: 20px;
    background: #bbada0;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1em;
    font-weight: bold;
    cursor: pointer;
    transition: background 0.3s;
}

.close-btn:hover {
    background: #9d9488;
}