* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

body {
    background-color: #faf8ef;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 20px;
}

.container {
    max-width: 500px;
    width: 100%;
}

/* 세로 모드 (기본) */
.game-layout {
    display: flex;
    flex-direction: column;
}

.left-panel {
    margin-bottom: 20px;
}

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

h1 {
    font-size: 64px;
    font-weight: bold;
    color: #776e65;
}

.scores {
    display: flex;
    gap: 10px;
}

.score-box {
    background-color: #bbada0;
    color: white;
    padding: 10px 20px;
    border-radius: 6px;
    text-align: center;
    min-width: 80px;
}

.score-box .label {
    display: block;
    font-size: 12px;
    text-transform: uppercase;
    color: #eee4da;
}

.score-box .value {
    display: block;
    font-size: 24px;
    font-weight: bold;
}

.game-controls {
    margin-bottom: 20px;
}

.controls-row {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}

.controls-info {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
}

#new-game {
    background-color: #8f7a66;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 6px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: background-color 0.2s;
}

#new-game:hover {
    background-color: #9f8b77;
}

.game-info {
    color: #776e65;
    font-size: 14px;
}

.voice-btn {
    background-color: #8f7a66;
    color: white;
    border: none;
    padding: 10px 16px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: background-color 0.2s;
}

.voice-btn:hover {
    background-color: #9f8b77;
}

.voice-btn.active {
    background-color: #e74c3c;
}

.voice-btn.active:hover {
    background-color: #c0392b;
}

.mic-icon {
    font-size: 16px;
}

.voice-status {
    font-size: 12px;
    color: #776e65;
}

.game-board {
    background-color: #bbada0;
    border-radius: 6px;
    padding: 15px;
    position: relative;
    width: 100%;
    max-width: 500px;
    aspect-ratio: 1;
}

#grid-container {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: 15px;
    position: relative;
    width: 100%;
    height: 100%;
}

.grid-cell {
    background-color: rgba(238, 228, 218, 0.35);
    border-radius: 6px;
    aspect-ratio: 1;
}

.tile {
    position: absolute;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 32px;
    font-weight: bold;
    border-radius: 6px;
    transition: top 0.15s ease-in-out, left 0.15s ease-in-out;
    z-index: 10;
}

.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: 28px; }
.tile-256 { background-color: #edcc61; color: #f9f6f2; font-size: 28px; }
.tile-512 { background-color: #edc850; color: #f9f6f2; font-size: 28px; }
.tile-1024 { background-color: #edc53f; color: #f9f6f2; font-size: 24px; }
.tile-2048 { background-color: #edc22e; color: #f9f6f2; font-size: 24px; }
.tile-super { background-color: #3c3a32; color: #f9f6f2; font-size: 20px; }

.game-message {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(238, 228, 218, 0.73);
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    border-radius: 6px;
    z-index: 100;
}

.game-message.active {
    display: flex;
}

#message-text {
    font-size: 48px;
    font-weight: bold;
    color: #776e65;
    margin-bottom: 20px;
}

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

#retry-button:hover {
    background-color: #9f8b77;
}

@media (max-width: 520px) {
    h1 {
        font-size: 48px;
    }

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

    .score-box .value {
        font-size: 20px;
    }

    .tile {
        font-size: 24px;
    }

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

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

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

/* 가로 모드 스타일 */
@media (orientation: landscape) {
    body {
        padding: 10px 20px;
    }

    .container {
        max-width: 900px;
        margin: 0 auto;
    }

    .game-layout {
        flex-direction: row;
        align-items: center;
        justify-content: center;
        gap: 30px;
    }

    .left-panel {
        flex: 0 0 auto;
        margin-bottom: 0;
    }

    header {
        flex-direction: column;
        align-items: flex-start;
        gap: 15px;
        margin-bottom: 15px;
    }

    h1 {
        font-size: 56px;
    }

    .game-controls {
        width: 100%;
    }

    .right-panel {
        flex: 1;
        display: flex;
        justify-content: center;
        align-items: center;
    }

    .game-board {
        padding: 12px;
        width: 400px;
        height: 400px;
    }

    #grid-container {
        gap: 12px;
    }

    .grid-cell {
        border-radius: 5px;
    }

    .tile {
        font-size: 28px;
        border-radius: 5px;
    }

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

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

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

    #message-text {
        font-size: 40px;
    }
}

/* 가로 모드 + 작은 화면 */
@media (orientation: landscape) and (max-height: 500px) {
    body {
        padding: 5px 15px;
    }

    .container {
        max-width: 700px;
    }

    .game-layout {
        gap: 20px;
    }

    h1 {
        font-size: 40px;
    }

    .scores {
        gap: 8px;
    }

    .score-box {
        padding: 6px 12px;
    }

    .score-box .label {
        font-size: 10px;
    }

    .score-box .value {
        font-size: 18px;
    }

    .game-controls {
        gap: 5px;
    }

    #new-game, .voice-btn {
        padding: 8px 14px;
        font-size: 14px;
    }

    .game-info {
        font-size: 12px;
    }

    .voice-status {
        font-size: 10px;
    }

    .game-board {
        padding: 10px;
        width: 320px;
        height: 320px;
    }

    #grid-container {
        gap: 8px;
    }

    .tile {
        font-size: 22px;
    }

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

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

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