/* ===== 기본 설정 ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #4a90d9;
    --secondary-color: #2d5a87;
    --accent-color: #ffd700;
    --bg-color: #87ceeb;
    --ground-color: #8b4513;
    --text-color: #ffffff;
    --shadow-color: #333333;
}

body {
    font-family: 'Press Start 2P', cursive;
    background: linear-gradient(180deg, var(--bg-color) 0%, #b0e0e6 100%);
    min-height: 100vh;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* ===== 화면 전환 ===== */
.screen {
    display: none;
    width: 100%;
    max-width: 420px;
    min-height: 100vh;
    position: relative;
    flex-direction: column;
    align-items: center;
    padding: 20px;
    background: linear-gradient(180deg, #4a90d9 0%, #87ceeb 50%, #98d8aa 100%);
}

.screen.active {
    display: flex;
}

/* ===== 시작 화면 ===== */
#start-screen {
    justify-content: flex-start;
    gap: 15px;
    padding-bottom: 30px;
    overflow-y: auto;
}

.version-text {
    font-size: 8px;
    color: rgba(255, 255, 255, 0.5);
    margin-top: 10px;
}

.title-container {
    text-align: center;
    margin-top: 10px;
    flex-shrink: 0;
}

#game-title {
    font-size: 24px;
    color: var(--accent-color);
    text-shadow:
        3px 3px 0 var(--shadow-color),
        -1px -1px 0 var(--shadow-color),
        1px -1px 0 var(--shadow-color),
        -1px 1px 0 var(--shadow-color);
    letter-spacing: 2px;
}

.subtitle {
    font-size: 10px;
    color: var(--text-color);
    margin-top: 10px;
    text-shadow: 1px 1px 0 var(--shadow-color);
}

/* 미리보기 영역 */
.preview-container {
    position: relative;
    width: 100%;
    height: 150px;
    min-height: 120px;
    background: linear-gradient(180deg, transparent 0%, rgba(139, 69, 19, 0.3) 100%);
    border-radius: 10px;
    overflow: hidden;
    flex-shrink: 0;
}

#preview-canvas {
    width: 100%;
    height: 100%;
}

.name-bubble {
    position: absolute;
    background: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 8px;
    color: var(--shadow-color);
    box-shadow: 2px 2px 0 rgba(0,0,0,0.3);
}

.name-bubble::after {
    content: '';
    position: absolute;
    bottom: -6px;
    left: 50%;
    transform: translateX(-50%);
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-top: 6px solid white;
}

#player-name-bubble {
    top: 60px;
    left: 80px;
}

/* 입력 영역 */
.input-container {
    width: 100%;
    flex-shrink: 0;
}

.input-group {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(255,255,255,0.9);
    padding: 10px 15px;
    border-radius: 8px;
    border: 3px solid var(--shadow-color);
    max-width: 100%;
    box-sizing: border-box;
}

.input-group label {
    font-size: 10px;
    color: var(--shadow-color);
    white-space: nowrap;
}

.input-group input {
    flex: 1;
    min-width: 0;
    font-family: 'Press Start 2P', cursive;
    font-size: 12px;
    padding: 8px;
    border: 2px solid var(--secondary-color);
    border-radius: 4px;
    text-transform: uppercase;
    outline: none;
}

.input-group input:focus {
    border-color: var(--accent-color);
}

/* 캐릭터 선택 */
.character-select {
    width: 100%;
    flex-shrink: 0;
}

.select-label {
    font-size: 10px;
    color: var(--text-color);
    margin-bottom: 10px;
    text-shadow: 1px 1px 0 var(--shadow-color);
}

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

.character-item {
    aspect-ratio: 1;
    background: rgba(255,255,255,0.8);
    border: 3px solid var(--shadow-color);
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: transform 0.1s, border-color 0.1s;
    overflow: hidden;
}

.character-item:hover {
    transform: scale(1.05);
}

.character-item.selected {
    border-color: var(--accent-color);
    background: rgba(255, 215, 0, 0.3);
}

.character-item img,
.character-item .placeholder {
    width: 80%;
    height: 80%;
    object-fit: contain;
}

.character-item .placeholder {
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 24px;
}

/* 시작 버튼 */
.pixel-btn {
    font-family: 'Press Start 2P', cursive;
    font-size: 10px;
    padding: 15px 20px;
    background: var(--secondary-color);
    color: var(--text-color);
    border: 3px solid var(--shadow-color);
    border-radius: 8px;
    cursor: pointer;
    text-shadow: 1px 1px 0 var(--shadow-color);
    box-shadow: 4px 4px 0 var(--shadow-color);
    transition: transform 0.1s, box-shadow 0.1s;
    width: 100%;
}

.pixel-btn:hover {
    transform: translate(-2px, -2px);
    box-shadow: 6px 6px 0 var(--shadow-color);
}

.pixel-btn:active {
    transform: translate(2px, 2px);
    box-shadow: 2px 2px 0 var(--shadow-color);
}

.pixel-btn.secondary {
    background: #666;
}

/* ===== 게임 화면 ===== */
#game-screen {
    padding: 0;
    background: #333;
    max-height: 100vh;
    height: 100vh;
    max-width: 100%;
    width: 100%;
    justify-content: center;
    align-items: center;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    /* Android 터치 지원 */
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
}

#game-screen.active {
    display: flex;
}

/* 캔버스 - 전체 화면 터치 영역 */
#game-canvas {
    display: block;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.game-hud {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    z-index: 10;
    background: linear-gradient(180deg, rgba(0,0,0,0.3) 0%, transparent 100%);
}

.hud-title {
    font-size: 14px;
    color: var(--accent-color);
    text-shadow: 2px 2px 0 var(--shadow-color);
}

.hud-scores {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 5px;
    font-size: 10px;
    color: var(--text-color);
    text-shadow: 1px 1px 0 var(--shadow-color);
}

#game-canvas {
    display: block;
    margin: auto;
    background: #87ceeb;
}

.game-bubble {
    top: 50%;
    left: 50px;
    transform: translateY(-50%);
    z-index: 5;
}

/* ===== 게임 오버 화면 ===== */
#gameover-screen {
    background: rgba(0, 0, 0, 0.8);
    justify-content: center;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    max-width: none;
    max-height: none;
}

.gameover-container {
    text-align: center;
    padding: 40px;
    background: linear-gradient(180deg, var(--secondary-color) 0%, var(--primary-color) 100%);
    border: 4px solid var(--shadow-color);
    border-radius: 16px;
    box-shadow: 8px 8px 0 var(--shadow-color);
}

.gameover-title {
    font-size: 24px;
    color: #ff4444;
    text-shadow: 3px 3px 0 var(--shadow-color);
    margin-bottom: 30px;
}

.gameover-scores {
    margin-bottom: 30px;
}

.gameover-scores p {
    font-size: 14px;
    color: var(--text-color);
    margin: 10px 0;
    text-shadow: 2px 2px 0 var(--shadow-color);
}

.gameover-buttons {
    display: flex;
    gap: 15px;
    justify-content: center;
}

.gameover-buttons .pixel-btn {
    width: auto;
    padding: 12px 24px;
}

/* ===== 반응형 ===== */
@media (max-width: 480px) {
    .screen {
        padding: 10px;
    }

    #game-title {
        font-size: 18px;
    }

    .subtitle {
        font-size: 8px;
    }

    .character-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 6px;
    }

    .character-item .placeholder {
        font-size: 20px;
    }

    .pixel-btn {
        font-size: 7px;
        padding: 10px 12px;
    }

    .input-group {
        padding: 8px 10px;
    }

    .input-group label {
        font-size: 8px;
    }

    .input-group input {
        font-size: 10px;
        padding: 6px;
    }
}

@media (max-height: 600px) {
    #start-screen {
        gap: 10px;
    }

    .preview-container {
        height: 100px;
        min-height: 80px;
    }

    .title-container {
        margin-top: 5px;
    }

    #game-title {
        font-size: 16px;
    }

    .select-label {
        font-size: 8px;
        margin-bottom: 5px;
    }

    .character-grid {
        gap: 5px;
    }
}
