:root {
    --bg-color: #05050A;
    --neon-cyan: #00f3ff;
    --neon-pink: #ff00ea;
    --panel-bg: rgba(0, 243, 255, 0.05);
    --border-glow: 0 0 10px rgba(0, 243, 255, 0.3);
}

* {
    box-sizing: border-box;
    user-select: none;
    -webkit-user-select: none;
}

body, html {
    margin: 0;
    padding: 0;
    width: 100vw;
    height: 100dvh; /* 모바일 브라우저의 주소창 영역을 고려한 동적 뷰포트 높이 */
    overflow: hidden; /* 스크롤 완벽 차단 */
    background-color: var(--bg-color);
    color: var(--neon-cyan);
    font-family: 'Orbitron', sans-serif;
    touch-action: none; /* 모바일 핀치 줌, 당겨서 새로고침 방지 */
}

#app {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
    max-width: 900px;
    margin: 0 auto;
    padding: 2vh 2vw;
    gap: 2vh;
}

/* UI 패널 공통 스타일 (Sci-Fi 느낌) */
.glass-panel {
    background: var(--panel-bg);
    border: 1px solid rgba(0, 243, 255, 0.2);
    box-shadow: var(--border-glow);
    border-radius: 8px;
    backdrop-filter: blur(5px);
}

#stats-panel {
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 10px;
    flex-shrink: 0;
}

.stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    font-size: 0.9rem;
    gap: 5px;
}

.stat span:last-child {
    font-size: 1.4rem;
    font-weight: bold;
    text-shadow: 0 0 5px var(--neon-cyan);
}

.next-container canvas {
    background: rgba(0,0,0,0.5);
    border: 1px solid rgba(0, 243, 255, 0.2);
    border-radius: 4px;
    width: 60px;
    height: 60px;
}

/* 메인 게임 캔버스 영역 */
#game-area {
    flex-grow: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 0; /* Flexbox 내에서 넘침을 방지하는 핵심 속성 */
}

#board-wrapper {
    position: relative;
    height: 100%;
    aspect-ratio: 1 / 2; /* 테트리스 보드의 10x20 비율 유지 */
    border: 2px solid var(--neon-cyan);
    box-shadow: 0 0 20px rgba(0, 243, 255, 0.2), inset 0 0 20px rgba(0, 243, 255, 0.2);
    background: rgba(0, 0, 0, 0.8);
    border-radius: 4px;
}

#game-canvas {
    width: 100%;
    height: 100%;
    display: block;
}

/* 시작 및 게임오버 화면 */
#overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 10;
    background: rgba(5, 5, 10, 0.85);
    text-align: center;
    padding: 20px;
}

.neon-text {
    font-size: 2rem;
    color: var(--neon-pink);
    text-shadow: 0 0 10px var(--neon-pink), 0 0 20px var(--neon-pink);
    margin-bottom: 20px;
}

#game-over-msg {
    color: #ff003c;
    text-shadow: 0 0 10px #ff003c;
    font-size: 1.5rem;
    margin-bottom: 20px;
    animation: blink 1s infinite;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

.neon-btn {
    background: transparent;
    color: var(--neon-cyan);
    border: 2px solid var(--neon-cyan);
    padding: 12px 24px;
    font-family: inherit;
    font-size: 1.2rem;
    font-weight: bold;
    cursor: pointer;
    border-radius: 4px;
    box-shadow: 0 0 10px rgba(0, 243, 255, 0.3), inset 0 0 10px rgba(0, 243, 255, 0.3);
    transition: all 0.2s;
}

.neon-btn:hover, .neon-btn:active {
    background: var(--neon-cyan);
    color: var(--bg-color);
    box-shadow: 0 0 20px var(--neon-cyan);
}

.desktop-hint {
    margin-top: 20px;
    font-size: 0.8rem;
    opacity: 0.7;
    line-height: 1.5;
}

/* 모바일 컨트롤 버튼 */
#mobile-controls {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding-bottom: 2vh;
}

.ctrl-row {
    display: flex;
    justify-content: center;
    gap: 15px;
}

.ctrl-btn {
    background: rgba(0, 243, 255, 0.05);
    border: 1px solid rgba(0, 243, 255, 0.3);
    color: var(--neon-cyan);
    width: 60px;
    height: 60px;
    border-radius: 50%;
    font-size: 1.5rem;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    touch-action: manipulation;
}

/* 터치 반응성 향상을 위한 클래스 */
.ctrl-btn.active, .ctrl-btn:active {
    background: rgba(0, 243, 255, 0.3);
    box-shadow: 0 0 15px var(--neon-cyan);
}

.action-btn {
    border-color: var(--neon-pink);
    color: var(--neon-pink);
}
.action-btn.active, .action-btn:active {
    background: rgba(255, 0, 234, 0.3);
    box-shadow: 0 0 15px var(--neon-pink);
}

/* PC 및 가로 모드 (데스크탑) 대응 레이아웃 */
@media (min-width: 768px) {
    #app {
        flex-direction: row;
        align-items: center;
        justify-content: center;
    }
    
    #stats-panel {
        flex-direction: column;
        height: 80vh;
        width: 200px;
        justify-content: center;
        gap: 40px;
    }
    
    .next-container canvas {
        width: 120px;
        height: 120px;
    }

    #game-area {
        flex-grow: 0;
        height: 80vh;
    }
    
    #mobile-controls {
        display: none; /* PC에서는 모바일 컨트롤 숨김 */
    }
}