.game-layout {
    display: flex;
    height: 100vh;
    width: 100vw;
    margin: 0;
    overflow: hidden;
    background-color: #000;
}

.sidebar {
    flex: 0 0 200px; /* 사이드바 너비 고정 */
    padding: 15px;
    background: rgba(10, 10, 10, 0.9);
    border-left: 1px solid rgba(255, 255, 255, 0.1);
    border-right: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    flex-direction: column;
    gap: 15px;
    z-index: 10;
}

.left-sidebar {
    border-right: 1px solid rgba(255, 255, 255, 0.2);
}

.right-sidebar {
    border-left: 1px solid rgba(255, 255, 255, 0.2);
    overflow-y: auto;
}

.game-area {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    background: #000;
    position: relative;
    padding: 0;
    height: 100vh;
}

#game-container {
    position: relative;
    height: 100vh; /* 브라우저 높이 꽉 채움 */
    width: auto;   /* 비율에 따라 너비 자동 결정 */
    aspect-ratio: 9 / 16; /* 세로 비율 고정 */
    max-height: 100%;
    max-width: 100%;
    margin: 0 auto;
    border: none;
    background: #111;
    box-shadow: 0 0 30px rgba(0,0,0,1);
    display: flex;
    justify-content: center;
    align-items: center;
}

canvas {
    width: 100%;
    height: 100%;
}

.user-profile {
    background: rgba(0, 255, 255, 0.1);
    padding: 15px;
    border-radius: 10px;
    border: 1px solid var(--primary);
}

.user-profile p {
    margin: 5px 0;
}

.motivational-phrases {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    font-size: 1.2rem;
    color: var(--primary);
    text-align: center;
    font-weight: bold;
    text-shadow: 0 0 10px var(--primary);
    padding: 20px;
}

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

.leader-item {
    display: flex;
    justify-content: space-between;
    padding: 10px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 5px;
    font-size: 0.9rem;
}

.leader-item.current-user {
    border: 1px solid var(--primary);
    background: rgba(0, 255, 255, 0.1);
}

.leader-item .rank {
    width: 30px;
    color: var(--primary);
    font-weight: bold;
}

.leader-item .name {
    flex: 1;
    text-align: left;
    margin-left: 10px;
}

.leader-item .score {
    font-weight: bold;
}

h3 {
    font-size: 1.1rem;
    color: var(--secondary);
    border-bottom: 1px solid rgba(255, 0, 255, 0.3);
    padding-bottom: 10px;
    margin-bottom: 10px;
}

/* UI Layer and Overlay Styles */
#ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 20px;
}

.top-bar, .bottom-bar {
    display: flex;
    justify-content: space-between;
    width: 100%;
}

.stat-box {
    background: rgba(0, 0, 0, 0.6);
    padding: 5px 15px;
    border-radius: 5px;
    border: 1px solid var(--primary);
    text-align: center;
}

.stat-label {
    display: block;
    font-size: 0.7rem;
    color: var(--text-dim);
}

.stat-value {
    font-size: 1.2rem;
    font-weight: bold;
    color: #fff;
}

#lives-container {
    display: flex;
    gap: 5px;
    margin-top: 5px;
}

#game-over-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 100;
    padding: 30px;
}

.hidden {
    display: none !important;
}

#stage-selection {
    max-height: 60vh;
    overflow-y: auto;
    padding: 10px;
    width: 100%;
}

.stage-select {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 5px;
    margin-bottom: 20px;
}

.stage-btn {
    width: 35px;
    height: 35px;
    display: flex;
    justify-content: center;
    align-items: center;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid #444;
    border-radius: 5px;
    cursor: pointer;
    color: #fff;
    font-size: 12px;
}

.stage-btn.current {
    background: var(--primary);
    color: #000;
    border-color: var(--primary);
}

.controls-hint {
    margin-top: 30px;
    font-size: 0.8rem;
    color: var(--text-dim);
}

.mobile-controls {
    display: none;
    justify-content: space-between;
    width: 100%;
    position: absolute;
    bottom: 50px;
    padding: 0 20px;
    pointer-events: none;
}

.touch-btn {
    width: 80px;
    height: 80px;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2rem;
    color: #fff;
    pointer-events: auto;
    user-select: none;
}

/* ----------------- MOBILE & RESPONSIVE FIXES ----------------- */
@media (max-width: 1100px) {
    /* 전체 초기화 */
    html, body {
        width: 100% !important;
        height: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
        overflow: hidden !important;
        position: fixed; /* 바운스 스크롤 방지 */
    }

    .game-layout {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        width: 100vw !important;
        height: 100vh !important;
        max-width: none !important;
        margin: 0 !important;
        padding: 0 !important;
        display: block !important; /* flex 해제 */
        background: #000 !important;
        z-index: 999;
    }

    .sidebar {
        display: none !important; 
        width: 0 !important;
        height: 0 !important;
        padding: 0 !important;
        margin: 0 !important;
        position: absolute;
    }

    .game-area {
        position: absolute !important;
        top: 0 !important;
        left: 0 !important;
        width: 100% !important;
        height: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
        display: flex !important;
        justify-content: center !important;
        align-items: center !important;
        background: #000 !important;
    }

    #game-container {
        position: relative !important;
        width: auto !important;
        height: 100vh !important; /* 화면 높이를 꽉 채움 */
        aspect-ratio: 450/800 !important;
        max-width: 100% !important;
        max-height: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
        transform: none !important; 
        border: none !important;
        background: #111 !important;
        box-shadow: 0 0 30px rgba(0,0,0,0.8) !important;
    }
}

/* 가로 모드 전용 보정 */
@media screen and (orientation: landscape) {
    #game-container {
        height: 100vh !important;
        width: auto !important;
        max-width: none !important;
        max-height: none !important;
    }
}

/* 세로 모드: 화면 중앙보다 약간 위에 배치 (모바일 컨트롤러 배려) */
@media (max-width: 600px) and (orientation: portrait) {
    .game-area {
        align-items: center !important;
    }
    #game-container {
        width: 90vw !important;
        height: 160vw !important;
        max-height: 80vh !important;
    }
}

@media (max-width: 600px) {
    .mobile-controls {
        display: flex;
    }
}
