/* 기본 스타일 - 버전 2.1 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    background: linear-gradient(135deg, #2c3e50 0%, #34495e 25%, #3f5877 50%, #4a6fa5 75%, #5b7c99 100%) !important;
    background-attachment: fixed !important;
    min-height: 100% !important;
    width: 100% !important;
}

body {
    font-family: 'Arial', sans-serif;
    background: linear-gradient(135deg, #2c3e50 0%, #34495e 25%, #3f5877 50%, #4a6fa5 75%, #5b7c99 100%) !important;
    background-attachment: fixed !important;
    min-height: 100vh !important;
    color: white !important;
    overflow-x: hidden;
    margin: 0 !important;
    padding: 0 !important;
    /* 인앱 브라우저 스크롤 방지 */
    touch-action: manipulation;
    overscroll-behavior: none;
    -webkit-overflow-scrolling: touch;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

/* 게임 실행 중 레이아웃 최적화 */
body.game-active {
    /* 모바일에서는 스크롤 허용하되, 게임 영역에서만 터치 제어 */
    touch-action: manipulation;
    overscroll-behavior: none;
    -webkit-overflow-scrolling: touch;
}

.container {
    width: 100%;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 10px;
    position: relative;
}

/* 게임 화면 전용 컨테이너 스타일 */
#gameScreen .container {
    align-items: flex-start;
    padding-top: 20px;
}

/* 화면 전환 - 기본적으로 모든 화면 숨김 */
.screen {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-width: 800px;
    padding: 20px;
    text-align: center;
    position: relative;
    z-index: 1;
}

/* 활성 화면만 표시 - hidden이 아닌 경우만 */
.screen:not(.hidden) {
    display: flex;
    position: relative;
    z-index: 10;
}

/* hidden 클래스가 있으면 완전히 숨김 */
.screen.hidden {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
    z-index: -1;
}

/* PC 환경에서 게임 화면 전용 스타일 */
#gameScreen {
    align-items: flex-start;
    padding-top: 10px;
}

#gameScreen:not(.hidden) {
    display: flex;
    position: relative;
    z-index: 10;
}

/* 시작 화면 */
.start-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 80vh;
    max-width: 400px;
    margin: 0 auto;
    padding: 20px;
}

#startScreen h1 {
    font-size: 3em;
    margin-bottom: 30px;
    background: linear-gradient(45deg, #3498db, #2ecc71, #f39c12, #e74c3c);
    background-size: 300% 300%;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: titleGlow 4s ease-in-out infinite;
    text-align: center;
    filter: drop-shadow(0 2px 8px rgba(52, 152, 219, 0.4));
}

@keyframes titleGlow {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

.nickname-input {
    margin-bottom: 30px;
}

.nickname-input input {
    padding: 15px;
    font-size: 1.2em;
    border: none;
    border-radius: 25px;
    margin-right: 10px;
    width: 200px;
    text-align: center;
}

.nickname-input button, button {
    padding: 15px 25px;
    font-size: 1.1em;
    background: linear-gradient(45deg, #3498db, #2ecc71);
    color: white;
    border: 2px solid transparent;
    border-radius: 25px;
    cursor: pointer;
    transition: all 0.3s ease;
    margin: 5px;
    box-shadow: 0 4px 15px rgba(52, 152, 219, 0.3);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    font-weight: bold;
}

.nickname-input button:hover, button:hover {
    transform: translateY(-2px) scale(1.02);
    box-shadow: 0 6px 20px rgba(52, 152, 219, 0.4);
    background: linear-gradient(45deg, #2980b9, #27ae60);
}

/* 랭킹 섹션 */
.ranking-section {
    background: linear-gradient(135deg, rgba(52,152,219,0.2), rgba(46,204,113,0.2)) !important;
    padding: 20px;
    border-radius: 15px;
    backdrop-filter: blur(15px);
    min-width: 300px;
    border: 2px solid rgba(255,255,255,0.2);
    box-shadow: 0 8px 25px rgba(52, 152, 219, 0.2);
}

.ranking-section h3 {
    margin-bottom: 15px;
    font-size: 1.5em;
}

.ranking-status {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 10px;
    font-size: 0.9em;
    color: rgba(255, 255, 255, 0.8);
}

.status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 8px;
    display: inline-block;
}

.status-indicator.online {
    background: #2ecc71;
    box-shadow: 0 0 8px rgba(46, 204, 113, 0.6);
    animation: pulse 2s infinite;
}

.status-indicator.offline {
    background: #e74c3c;
    box-shadow: 0 0 8px rgba(231, 76, 60, 0.6);
}

@keyframes pulse {
    0% { box-shadow: 0 0 8px rgba(46, 204, 113, 0.6); }
    50% { box-shadow: 0 0 15px rgba(46, 204, 113, 0.8); }
    100% { box-shadow: 0 0 8px rgba(46, 204, 113, 0.6); }
}

.ranking-item {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid rgba(255,255,255,0.2);
}

.ranking-item:last-child {
    border-bottom: none;
}

.ranking-item.top-rank {
    background: linear-gradient(90deg, rgba(255,215,0,0.1), rgba(255,215,0,0.05));
    border-radius: 5px;
    padding: 10px 8px;
    margin: 2px 0;
    border-bottom: 1px solid rgba(255,215,0,0.3);
}

.rank-info {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.rank {
    font-size: 0.8em;
    font-weight: bold;
}

.nickname {
    font-size: 0.9em;
    margin-top: 2px;
}

.score-info {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    text-align: right;
}

.score {
    font-weight: bold;
    color: #3498db;
    font-size: 0.9em;
}

.level {
    font-size: 0.8em;
    color: rgba(255, 255, 255, 0.7);
}

.date {
    font-size: 0.7em;
    color: rgba(255, 255, 255, 0.5);
    margin-top: 2px;
    min-width: 60px;
    text-align: center;
}

.no-rankings {
    text-align: center;
    color: rgba(255, 255, 255, 0.6);
    font-style: italic;
    padding: 20px;
}

/* 게임 화면 */
.game-header {
    width: 100%;
    margin-bottom: 15px;
}

.player-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: linear-gradient(135deg, rgba(52,152,219,0.2), rgba(46,204,113,0.2)) !important;
    padding: 10px 20px;
    border-radius: 10px;
    backdrop-filter: blur(15px);
    border: 2px solid rgba(255,255,255,0.2);
    box-shadow: 0 8px 25px rgba(52, 152, 219, 0.2);
}

.header-buttons {
    display: flex;
    gap: 10px;
    align-items: center;
}

#fullscreenBtn {
    padding: 10px 15px;
    font-size: 1.2em;
    background: linear-gradient(45deg, #9b59b6, #8e44ad);
    color: white;
    border: 2px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(155, 89, 182, 0.3);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    font-weight: bold;
    min-width: 45px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#fullscreenBtn:hover {
    transform: translateY(-2px) scale(1.02);
    box-shadow: 0 6px 20px rgba(155, 89, 182, 0.4);
    background: linear-gradient(45deg, #8e44ad, #732d91);
}

#fullscreenBtn:active {
    transform: scale(0.95);
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
}

.game-area {
    display: flex;
    gap: 15px;
    align-items: flex-start;
    justify-content: center;
    width: 100%;
    margin-bottom: 15px;
    max-width: 600px;
}

.side-panel {
    background: linear-gradient(135deg, rgba(52,152,219,0.2), rgba(46,204,113,0.2)) !important;
    padding: 15px;
    border-radius: 12px;
    backdrop-filter: blur(20px);
    border: 2px solid rgba(255,255,255,0.2);
    min-width: 100px;
    max-width: 110px;
    flex-shrink: 0;
    text-align: center;
    box-shadow: 0 8px 25px rgba(52, 152, 219, 0.2);
}

.next-piece {
    margin-bottom: 20px;
    text-align: center;
}

.next-piece h4 {
    margin-bottom: 8px;
    font-size: 0.9em;
    color: #fff;
    font-weight: normal;
}

.next-piece canvas {
    border: 2px solid rgba(255,255,255,0.3);
    border-radius: 8px;
    background: rgba(0,0,0,0.8);
    width: 60px;
    height: 60px;
    box-shadow: 0 4px 12px rgba(52, 152, 219, 0.2);
}

.game-stats .stat-item {
    margin: 15px 0;
    font-size: 0.8em;
    font-weight: normal;
    text-align: center;
    color: #fff;
    line-height: 1.3;
}

.game-stats .stat-item span {
    display: block;
    color: #3498db;
    font-weight: bold;
    font-size: 1.8em;
    margin-top: 3px;
    text-shadow: 0 1px 3px rgba(52, 152, 219, 0.6);
}

.game-board {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex-grow: 1;
    max-width: 300px;
}

#gameCanvas {
    border: 3px solid #3498db;
    border-radius: 10px;
    background: rgba(0,0,0,0.8);
    box-shadow: 0 8px 25px rgba(52, 152, 219, 0.3);
    /* 터치 이벤트 완전 제어 */
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    /* 기본 PC 크기 설정 - 정확한 1:2 비율 */
    width: 300px;
    height: 600px;
    /* 비율 유지 */
    aspect-ratio: 1 / 2;
}

/* 모바일 컨트롤 */
.mobile-controls {
    display: flex;
    gap: 20px;
    justify-content: center;
    width: 100%;
    max-width: 400px;
    margin: 15px 0;
    padding: 15px;
    background: linear-gradient(135deg, rgba(52,152,219,0.2), rgba(46,204,113,0.2)) !important;
    border-radius: 15px;
    backdrop-filter: blur(15px);
    touch-action: manipulation;
    border: 2px solid rgba(255,255,255,0.2);
    box-shadow: 0 8px 25px rgba(52, 152, 219, 0.2);
}

.control-btn {
    padding: 15px 25px;
    font-size: 1.1em;
    background: linear-gradient(45deg, #3498db, #2ecc71);
    border: 2px solid transparent;
    border-radius: 12px;
    color: white;
    font-weight: bold;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(52, 152, 219, 0.3);
    min-width: 80px;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.control-btn:active {
    transform: scale(0.95);
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.control-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0,0,0,0.3);
}

/* 광고 섹션 */
.ad-section {
    width: 100%;
    max-width: 400px;
    margin-top: 20px;
    text-align: center;
}

.ad-container {
    min-height: 150px;
    background: linear-gradient(135deg, rgba(255,255,255,0.2), rgba(255,255,255,0.1)) !important;
    border-radius: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto;
    border: 2px solid rgba(255,255,255,0.3);
    box-shadow: 0 0 20px rgba(255, 255, 255, 0.2), inset 0 0 15px rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
}

/* 게임 오버 화면 - PC에서 사용 */
#gameOverScreen {
    width: 100%;
    height: auto;
    min-height: 80vh;
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 20px;
    position: relative;
}

#gameOverScreen:not(.hidden) {
    display: flex;
}

#gameOverScreen h2 {
    font-size: 2.5em;
    color: #e74c3c;
    margin-bottom: 20px;
    text-shadow: 0 2px 8px rgba(231, 76, 60, 0.5);
    text-align: center;
}

/* 일시정지 화면 - PC에서 사용 */
#pauseScreen {
    width: 100%;
    height: auto;
    min-height: 80vh;
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 20px;
    position: relative;
}

#pauseScreen:not(.hidden) {
    display: flex;
}

#pauseScreen h2 {
    font-size: 2.5em;
    color: #3498db;
    margin-bottom: 20px;
    text-shadow: 0 2px 8px rgba(52, 152, 219, 0.5);
    text-align: center;
}

.final-score {
    background: linear-gradient(135deg, rgba(231,76,60,0.2), rgba(230,126,34,0.2)) !important;
    padding: 20px;
    border-radius: 15px;
    margin-bottom: 20px;
    backdrop-filter: blur(15px);
    border: 2px solid rgba(255,255,255,0.2);
    box-shadow: 0 8px 25px rgba(231, 76, 60, 0.2);
}

.final-score p {
    font-size: 1.3em;
    margin: 10px 0;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.continue-section {
    background: linear-gradient(135deg, rgba(52,152,219,0.2), rgba(46,204,113,0.2)) !important;
    padding: 20px;
    border-radius: 15px;
    margin-bottom: 20px;
    backdrop-filter: blur(15px);
    border: 2px solid rgba(255,255,255,0.2);
    box-shadow: 0 8px 25px rgba(52, 152, 219, 0.2);
}

.continue-section p {
    margin-bottom: 15px;
    font-size: 1.1em;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

/* 사운드 컨트롤 */
.sound-controls {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
}

#soundToggle {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: linear-gradient(45deg, rgba(52,152,219,0.3), rgba(46,204,113,0.3)) !important;
    border: 2px solid rgba(255,255,255,0.4);
    font-size: 1.5em;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(15px);
    color: white;
    box-shadow: 0 4px 15px rgba(52, 152, 219, 0.3);
    transition: all 0.3s ease;
}

#soundToggle:hover {
    box-shadow: 0 6px 20px rgba(52, 152, 219, 0.4);
    transform: scale(1.05);
}

/* 반응형 디자인 */
@media (max-width: 768px) {
    /* 모바일에서 게임 화면 전체 보이기 */
    body.game-active {
        padding: 0;
        margin: 0;
    }
    
    body.game-active .container {
        height: 100vh;
        min-height: 100vh;
        max-height: 100vh;
        overflow-y: auto;
        padding: 5px;
        align-items: flex-start;
        justify-content: center;
    }
    
    body.game-active #gameScreen {
        width: 100%;
        height: 100%;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: flex-start;
        padding: 5px;
    }
    
    .container {
        padding: 10px;
        min-height: 100vh;
        align-items: center;
        justify-content: center;
    }
    
    #gameScreen .container {
        padding: 10px;
        padding-top: 15px;
    }
    
    body.game-active .container {
        padding: 5px;
    }
    
    .game-header {
        margin-bottom: 10px;
    }
    
    .player-info {
        padding: 8px 15px;
        font-size: 0.9em;
    }
    
    .game-container {
        max-width: 100%;
    }
    
    .game-area {
        gap: 10px;
        margin-bottom: 10px;
    }
    
    .side-panel {
        min-width: 85px;
        max-width: 95px;
        padding: 12px;
        font-size: 0.9em;
    }
    
    .next-piece {
        margin-bottom: 15px;
    }
    
    .next-piece h4 {
        font-size: 0.8em;
        margin-bottom: 6px;
    }
    
    .next-piece canvas {
        width: 50px;
        height: 50px;
    }
    
    .game-stats .stat-item {
        margin: 12px 0;
        font-size: 0.7em;
    }
    
    .game-stats .stat-item span {
        font-size: 1.5em;
        margin-top: 2px;
    }
    
    #gameCanvas {
        /* 모바일에서 정확한 1:2 비율 유지 */
        width: 224px;
        height: 448px;
        /* 화면에 맞게 조정하되 비율 유지 */
        max-width: calc(100vw - 30px);
        max-height: calc(100vh - 250px);
        /* 비율이 깨지지 않도록 강제 */
        aspect-ratio: 1 / 2;
        object-fit: contain;
    }
    
    .mobile-controls {
        margin: 10px 0;
        padding: 10px;
        gap: 12px;
        max-width: 280px;
    }
    
    .control-btn {
        padding: 12px 20px;
        font-size: 1em;
        min-width: 70px;
    }
    
    .ad-section {
        margin-top: 15px;
        max-width: 280px;
    }
    
    .ad-container {
        min-height: 120px;
    }
    
    /* 모바일에서만 팝업 표시, PC에서는 일반 화면 */
    #gameOverScreen {
        display: none !important;
    }
    
    /* 모바일 팝업 활성화 */
    .mobile-popup {
        display: flex !important;
    }
    
    .header-buttons {
        flex-direction: column;
        gap: 5px;
    }
    
    #fullscreenBtn {
        padding: 8px 12px;
        font-size: 1em;
        min-width: 40px;
    }
    
    /* 시작 화면 */
    .start-content {
        min-height: 70vh;
        max-width: 320px;
    }
    
    #startScreen h1 {
        font-size: 2.3em;
    }
    
    .nickname-input {
        flex-direction: column;
        align-items: center;
    }
    
    .nickname-input input {
        margin-bottom: 15px;
        margin-right: 0;
        width: 240px;
    }
    
    .ranking-section {
        min-width: 260px;
    }
    
    /* 게임 오버 화면 모바일 최적화 */
    #gameOverScreen {
        padding: 15px;
    }
    
    #gameOverScreen h2 {
        font-size: 2em;
        margin-bottom: 15px;
    }
    
    .final-score {
        padding: 15px;
        margin-bottom: 15px;
    }
    
    .final-score p {
        font-size: 1.1em;
        margin: 8px 0;
    }
    
    .continue-section {
        padding: 15px;
        margin-bottom: 15px;
    }
    
    .continue-section p {
        font-size: 1em;
        margin-bottom: 12px;
    }
    
    /* 일시정지 화면 모바일 최적화 */
    #pauseScreen {
        padding: 15px;
    }
    
    #pauseScreen h2 {
        font-size: 2em;
        margin-bottom: 20px;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 5px;
        min-height: 100vh;
        align-items: center;
        justify-content: center;
    }
    
    #gameScreen .container {
        padding: 5px;
        padding-top: 10px;
    }
    
    .game-area {
        flex-direction: column;
        align-items: center;
        gap: 10px;
    }
    
    .side-panel {
        width: 100%;
        max-width: 240px;
        display: flex;
        justify-content: space-around;
        align-items: flex-start;
        padding: 12px;
        text-align: center;
    }
    
    .next-piece {
        margin-bottom: 0;
        margin-right: 15px;
        flex-shrink: 0;
    }
    
    .next-piece h4 {
        font-size: 0.7em;
        margin-bottom: 5px;
    }
    
    .next-piece canvas {
        width: 45px;
        height: 45px;
    }
    
    .game-stats {
        flex: 1;
        display: flex;
        justify-content: space-around;
        align-items: flex-start;
    }
    
    .game-stats .stat-item {
        margin: 0;
        font-size: 0.6em;
        flex: 1;
    }
    
    .game-stats .stat-item span {
        font-size: 1.3em;
        margin-top: 2px;
    }
    
    #gameCanvas {
        /* 소형 모바일에서도 정확한 1:2 비율 유지 */
        width: 196px;
        height: 392px;
        /* 화면에 맞게 조정하되 비율 유지 */
        max-width: calc(100vw - 20px);
        max-height: calc(100vh - 220px);
        /* 비율이 깨지지 않도록 강제 */
        aspect-ratio: 1 / 2;
        object-fit: contain;
    }
    
    .mobile-controls {
        max-width: 240px;
        margin: 8px 0;
        padding: 10px;
    }
    
    .control-btn {
        flex: 1;
        min-width: auto;
        padding: 10px 12px;
        font-size: 0.95em;
    }
    
    .ad-section {
        max-width: 240px;
        margin-top: 10px;
    }
    
    .start-content {
        max-width: 280px;
        min-height: 60vh;
        padding: 15px;
    }
    
    #startScreen h1 {
        font-size: 2em;
    }
    
    .nickname-input input {
        width: 200px;
    }
    
    .ranking-section {
        min-width: 230px;
    }
    
    /* 소형 모바일 게임 오버 화면 - 팝업만 사용 */
    #gameOverScreen {
        display: none !important;
    }
    
    #pauseScreen {
        padding: 10px;
        min-height: 100vh;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    #pauseScreen:not(.hidden) {
        min-height: 100vh;
        align-items: center;
        justify-content: center;
    }
    
    #pauseScreen h2 {
        font-size: 1.8em;
        margin-bottom: 15px;
    }
    
    .popup-content {
        padding: 20px;
        max-width: 320px;
    }
    
    .popup-content h2 {
        font-size: 1.6em;
        margin-bottom: 12px;
    }
    
    .popup-content .final-score {
        padding: 12px;
        margin-bottom: 12px;
    }
    
    .popup-content .continue-section {
        padding: 12px;
        margin-bottom: 12px;
    }
    
    .header-buttons {
        flex-direction: row;
        gap: 8px;
    }
    
    #fullscreenBtn {
        padding: 6px 10px;
        font-size: 0.9em;
        min-width: 35px;
    }
    
    .final-score {
        padding: 12px;
        margin-bottom: 12px;
    }
    
    .final-score p {
        font-size: 1em;
        margin: 6px 0;
    }
    
    .continue-section {
        padding: 12px;
        margin-bottom: 12px;
    }
    
    .continue-section p {
        font-size: 0.9em;
        margin-bottom: 10px;
    }
}

/* 애니메이션 효과 */
.line-clear-effect {
    animation: lineClear 0.3s ease-in-out;
}

@keyframes lineClear {
    0% { opacity: 1; }
    50% { opacity: 0.5; background: #ff0; }
    100% { opacity: 0; }
}

.piece-drop-effect {
    animation: pieceDrop 0.2s ease-out;
}

@keyframes pieceDrop {
    0% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

/* 로딩 애니메이션 */
.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255,255,255,.3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: spin 1s ease-in-out infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* 터치 피드백 */
@media (hover: none) and (pointer: coarse) {
    .control-btn:hover {
        transform: none;
        box-shadow: none;
    }
    
    .control-btn:active {
        transform: scale(0.95);
        background: rgba(255,255,255,0.4);
    }
}

/* 광고 섹션 스타일 */
#adSection {
    text-align: center;
    padding: 10px;
    margin: 10px 0;
}

#adSection.hidden {
    display: none;
}

#continueAfterAdBtn {
    margin-top: 15px;
    opacity: 0.5;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

#continueAfterAdBtn.hidden {
    display: none;
}

.adsbygoogle {
    margin: 10px auto !important;
}

/* 모바일 팝업 스타일 */
.mobile-popup {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.mobile-popup.hidden {
    display: none;
}

.popup-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(10px);
}

.popup-content {
    position: relative;
    background: linear-gradient(135deg, rgba(52,152,219,0.3), rgba(46,204,113,0.3));
    border-radius: 20px;
    padding: 25px;
    max-width: 400px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    backdrop-filter: blur(20px);
    border: 2px solid rgba(255,255,255,0.3);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
    text-align: center;
    animation: popupSlideIn 0.3s ease-out;
}

@keyframes popupSlideIn {
    from {
        opacity: 0;
        transform: scale(0.8) translateY(-20px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.popup-content h2 {
    font-size: 2em;
    color: #e74c3c;
    margin-bottom: 15px;
    text-shadow: 0 2px 8px rgba(231, 76, 60, 0.5);
}

.popup-content .final-score {
    background: linear-gradient(135deg, rgba(231,76,60,0.2), rgba(230,126,34,0.2));
    padding: 15px;
    border-radius: 12px;
    margin-bottom: 15px;
    backdrop-filter: blur(15px);
    border: 2px solid rgba(255,255,255,0.2);
}

.popup-content .continue-section {
    background: linear-gradient(135deg, rgba(52,152,219,0.2), rgba(46,204,113,0.2));
    padding: 15px;
    border-radius: 12px;
    margin-bottom: 15px;
    backdrop-filter: blur(15px);
    border: 2px solid rgba(255,255,255,0.2);
}

.mobile-ad {
    max-width: 300px;
    max-height: 250px;
    margin: 15px auto;
    background: rgba(255,255,255,0.1);
    border-radius: 10px;
    border: 2px solid rgba(255,255,255,0.3);
}

#mobileAdSection {
    text-align: center;
    padding: 10px;
    margin: 10px 0;
}

#mobileAdSection.hidden {
    display: none;
}

#mobileContinueAfterAdBtn {
    margin-top: 15px;
    opacity: 0.5;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

#mobileContinueAfterAdBtn.hidden {
    display: none;
}

/* 전체화면 모드 */
.fullscreen-mode {
    background: #000 !important;
    overflow: hidden;
}

.fullscreen-mode .container {
    padding: 0 !important;
    margin: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    max-width: none !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    z-index: 9999 !important;
}

.fullscreen-mode #gameScreen {
    width: 100% !important;
    height: 100% !important;
    max-width: none !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 10px !important;
    position: relative !important;
}

.fullscreen-mode .game-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    max-width: none;
    width: 100%;
    height: 100%;
}

.fullscreen-mode .game-area {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-width: 1200px;
    gap: 30px;
    height: 100%;
}

.fullscreen-mode #gameCanvas {
    width: auto !important;
    height: 70vh !important;
    max-width: 35vh !important;
    max-height: 70vh !important;
    border: 4px solid #3498db;
}

.fullscreen-mode .side-panel {
    min-width: 120px;
    max-width: 150px;
    padding: 20px;
    height: fit-content;
}

.fullscreen-mode .mobile-controls {
    margin: 20px 0;
    max-width: 600px;
}

/* 전체화면 상태에서 게임오버/일시정지 화면이 활성화되었을 때만 다른 요소들 숨기기 */
.fullscreen-mode.modal-active .sound-controls,
.fullscreen-mode.modal-active #gameScreen {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

/* 전체화면에서 게임오버/일시정지 화면이 활성화되었을 때만 강제 적용 */
.fullscreen-mode #gameOverScreen:not(.hidden),
.fullscreen-mode #pauseScreen:not(.hidden) {
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
    pointer-events: auto !important;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    z-index: 99999 !important;
}

/* 전체화면 모드에서 게임오버/일시정지 화면 완전 중앙 정렬 - 최종 완벽 버전 */
.fullscreen-mode #gameOverScreen,
.fullscreen-mode #pauseScreen {
    /* 모든 기존 스타일 무시하고 완전 초기화 */
    all: initial !important;
    
    /* 전체화면 덮기 */
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    margin: 0 !important;
    padding: 0 !important;
    
    /* Flexbox 중앙 정렬 */
    display: flex !important;
    flex-direction: column !important;
    justify-content: center !important;
    align-items: center !important;
    text-align: center !important;
    
    /* 배경 및 레이어 */
    background: rgba(0, 0, 0, 0.9) !important;
    backdrop-filter: blur(10px) !important;
    z-index: 10000 !important;
    
    /* 폰트 재설정 */
    font-family: Arial, sans-serif !important;
    color: white !important;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.3) !important;
    
    /* 박스 모델 */
    box-sizing: border-box !important;
}

.fullscreen-mode #gameOverScreen:not(.hidden),
.fullscreen-mode #pauseScreen:not(.hidden) {
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
    pointer-events: auto !important;
}

/* 전체화면 모드에서 모든 직계 자식들을 중앙 정렬 컨테이너로 변경 */
.fullscreen-mode #gameOverScreen > *,
.fullscreen-mode #pauseScreen > * {
    /* 중앙 정렬 및 크기 제한 */
    display: block !important;
    width: auto !important;
    max-width: 90vw !important;
    min-width: 300px !important;
    margin: 10px auto !important;
    text-align: center !important;
    
    /* 위치 초기화 */
    position: relative !important;
    left: auto !important;
    right: auto !important;
    top: auto !important;
    bottom: auto !important;
    transform: none !important;
    float: none !important;
    
    /* 폰트 상속 */
    font-family: inherit !important;
    color: inherit !important;
}

/* 제목들 */
.fullscreen-mode #gameOverScreen h2,
.fullscreen-mode #pauseScreen h2 {
    font-size: 2.5em !important;
    margin: 20px auto !important;
    text-align: center !important;
    color: #e74c3c !important;
    text-shadow: 0 2px 8px rgba(231, 76, 60, 0.5) !important;
}

.fullscreen-mode #pauseScreen h2 {
    color: #3498db !important;
    text-shadow: 0 2px 8px rgba(52, 152, 219, 0.5) !important;
}

/* 점수 및 섹션들 */
.fullscreen-mode .final-score,
.fullscreen-mode .continue-section {
    background: linear-gradient(135deg, rgba(52,152,219,0.2), rgba(46,204,113,0.2)) !important;
    padding: 20px !important;
    border-radius: 15px !important;
    margin: 15px auto !important;
    backdrop-filter: blur(15px) !important;
    border: 2px solid rgba(255,255,255,0.2) !important;
    box-shadow: 0 8px 25px rgba(52, 152, 219, 0.2) !important;
    max-width: 500px !important;
    width: 80% !important;
    text-align: center !important;
}

.fullscreen-mode .final-score {
    background: linear-gradient(135deg, rgba(231,76,60,0.2), rgba(230,126,34,0.2)) !important;
    box-shadow: 0 8px 25px rgba(231, 76, 60, 0.2) !important;
}

/* 광고 섹션 */
.fullscreen-mode #adSection {
    max-width: 400px !important;
    width: 80% !important;
    margin: 15px auto !important;
    text-align: center !important;
}

/* 버튼들 */
.fullscreen-mode button {
    padding: 15px 25px !important;
    font-size: 1.1em !important;
    background: linear-gradient(45deg, #3498db, #2ecc71) !important;
    color: white !important;
    border: 2px solid transparent !important;
    border-radius: 25px !important;
    cursor: pointer !important;
    transition: all 0.3s ease !important;
    margin: 5px !important;
    box-shadow: 0 4px 15px rgba(52, 152, 219, 0.3) !important;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3) !important;
    font-weight: bold !important;
    font-family: Arial, sans-serif !important;
}

.fullscreen-mode button:hover {
    transform: translateY(-2px) scale(1.02) !important;
    box-shadow: 0 6px 20px rgba(52, 152, 219, 0.4) !important;
    background: linear-gradient(45deg, #2980b9, #27ae60) !important;
}

/* 컨테이너 완전 무시 */
.fullscreen-mode #gameOverScreen .container,
.fullscreen-mode #pauseScreen .container {
    all: unset !important;
    display: contents !important;
}

/* 모든 하위 요소들 강제 초기화 */
.fullscreen-mode #gameOverScreen *,
.fullscreen-mode #pauseScreen * {
    position: relative !important;
    left: auto !important;
    right: auto !important;
    top: auto !important;
    bottom: auto !important;
    transform: none !important;
    float: none !important;
    margin-left: auto !important;
    margin-right: auto !important;
}

/* 다크모드 대응 */
@media (prefers-color-scheme: dark) {
    body {
        background: linear-gradient(135deg, #4ecdc4 0%, #44a08d 100%);
    }
}

/* 모바일 전용 스타일 */
@media (hover: none) and (pointer: coarse) {
    /* 모바일에서 게임 화면 최적화 */
    body.game-active {
        /* iOS Safari에서 주소창 숨기기 */
        -webkit-user-select: none;
        user-select: none;
        /* 전체 화면 사용 */
        height: 100vh;
        max-height: 100vh;
        overflow-y: auto;
    }
    
    /* 게임 컨테이너 최적화 */
    body.game-active .container {
        padding: 5px;
        margin: 0;
        min-height: 100vh;
        max-height: none;
        justify-content: flex-start;
        align-items: center;
    }
    
    body.game-active #gameScreen {
        width: 100%;
        max-width: none;
        height: 100%;
        min-height: 100vh;
        display: flex;
        flex-direction: column;
        justify-content: flex-start;
        align-items: center;
        padding: 5px;
    }
    
    /* 게임 캔버스 터치 제어 */
    body.game-active #gameCanvas {
        touch-action: none;
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        -khtml-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        user-select: none;
    }
    
    /* 모바일 컨트롤 버튼도 터치 제어 */
    body.game-active .control-btn {
        touch-action: none;
        -webkit-touch-callout: none;
    }
}