/* 바리스타 게임 스타일 */

body {
    margin: 0;
    padding: 0;
    background: linear-gradient(135deg, #8B4513 0%, #D2691E 50%, #CD853F 100%);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    height: 100vh;
    overflow: hidden;
    
    /* 모바일 최적화 */
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    touch-action: manipulation;
}

.game-container {
    position: relative;
    width: 100vw;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    /* 광고 영역을 피하기 위한 패딩 */
    padding: 120px 0;
    box-sizing: border-box;
}

#gameCanvas {
    border: 2px solid #654321;
    background: #F5DEB3;
    border-radius: 10px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    
    /* z-index 설정: 가장 아래 레이어 (게임 배경) */
    position: relative;
    z-index: 1;
    
    /* 모바일 최적화 */
    touch-action: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    
    /* 반응형 크기 조정 */
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

/* UI 오버레이 - 캔버스와 동일한 크기와 위치 */
.ui-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: min(800px, 95vw);
    height: min(600px, 75vh);
    max-width: 100vw;
    max-height: 100vh;
    pointer-events: none;
    z-index: 10; /* UI 요소들: 캔버스 위, 게임 요소 아래 */
    /* 캔버스와 정확히 동일한 비율 유지 */
    aspect-ratio: 4/3;
}

/* 게임 모드에서 ui-overlay height을 gameCanvas와 일치 - JavaScript에서 동적 설정 */
.game-container .ui-overlay.game-mode,
.ui-overlay.game-mode {
    /* height는 JavaScript에서 동적으로 설정됨 */
    aspect-ratio: unset !important;
    /* width는 기존 설정 유지 */
}

/* 게임 상태별 클릭 이벤트 제어 */
.ui-overlay.menu-mode {
    pointer-events: auto; /* 메뉴 상태에서는 UI 클릭 허용 */
    /* 게임 캔버스 중앙에 정확히 맞춤 */
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.ui-overlay.game-mode {
    pointer-events: none; /* 게임 중에는 UI 클릭 차단 */
}

/* 메뉴 모드와 최초 상태에서는 게임 UI 요소들 숨기기 */
.ui-overlay:not(.game-mode) .hearts-container,
.ui-overlay:not(.game-mode) .time-bar-container,
.ui-overlay:not(.game-mode) .combo-display {
    display: none !important;
}

/* 개별 UI 요소는 항상 클릭 가능하도록 설정 */
.start-screen, .game-over-screen {
    pointer-events: auto !important;
}

/* 하트 (기회) - 상단 고정 */
.hearts-container {
    position: absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 10px;
    pointer-events: none;
}

.heart {
    font-size: 24px;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.heart.lost {
    opacity: 0.3;
}

/* 하트 애니메이션 효과 */
.heart {
    transition: all 0.3s ease;
}

.heart.lost {
    animation: heartLoss 0.5s ease-in-out;
}

@keyframes heartLoss {
    0% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.3); opacity: 0.7; }
    100% { transform: scale(1); opacity: 0.3; }
}

/* 시간 바 - 하트 바로 아래 상단 고정 */
.time-bar-container {
    position: absolute;
    top: 50px;
    left: 50%;
    transform: translateX(-50%);
    width: 80%;
    pointer-events: none;
}

.time-bar {
    width: 100%;
    height: 18px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 9px;
    overflow: hidden;
    border: 2px solid #654321;
}

.time-fill {
    height: 100%;
    background: linear-gradient(90deg, #4ECDC4 0%, #45B7D1 50%, #96CEB4 100%);
    width: 100%;
    transition: width 0.1s linear, background 0.3s ease;
    border-radius: 8px;
    position: relative;
    overflow: hidden;
}

/* 시간 바 애니메이션 효과 */
@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.02); }
    100% { transform: scale(1); }
}

@keyframes danger-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

.time-fill.pulse {
    animation: pulse 0.5s ease-in-out;
}

.time-fill.danger {
    animation: danger-blink 0.3s ease-in-out infinite;
}

/* 콤보 표시 - 반응형: 모바일은 하단, 데스크톱은 우측 */
.combo-display {
    position: absolute;
    text-align: center;
    pointer-events: none;
    z-index: 100;
}

/* 모바일: 하단 중앙 */
@media (max-width: 768px) {
    .combo-display {
        bottom: 80px;
        left: 50%;
        transform: translateX(-50%);
    }
}

/* 데스크톱: 우측 중앙 */
@media (min-width: 769px) {
    .combo-display {
        right: 30px;
        top: 50%;
        transform: translateY(-50%);
    }
}

.combo-text {
    display: block;
    color: #FF6B6B;
    font-size: 36px;
    font-weight: bold;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.7);
    margin-bottom: 5px;
    letter-spacing: 1px;
}

.combo-number {
    display: block;
    color: #FFD93D;
    font-size: 96px;
    font-weight: bold;
    text-shadow: 3px 3px 6px rgba(0, 0, 0, 0.8);
    animation: combo-pulse 0.3s ease-out;
    line-height: 1;
}

@keyframes combo-pulse {
    0% { transform: scale(1.3); }
    100% { transform: scale(1); }
}

/* 게임 피드백 메시지 오버레이 - 가장 높은 z-index */
.feedback-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1000; /* 모든 요소 위에 표시 */
}

.feedback-message {
    position: absolute;
    top: 150px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 48px;
    font-weight: bold;
    text-align: center;
    text-shadow: 3px 3px 6px rgba(0, 0, 0, 0.8);
    opacity: 0;
    transition: all 0.3s ease-out;
    white-space: nowrap;
}

.feedback-message.show {
    opacity: 1;
    animation: feedbackPulse 1.2s ease-out;
}

@keyframes feedbackPulse {
    0% { 
        transform: translateX(-50%) scale(1.3) translateY(0px);
        opacity: 1;
    }
    100% { 
        transform: translateX(-50%) scale(1) translateY(-100px);
        opacity: 0;
    }
}

/* 게임 시작 화면 */
.start-screen {
    position: absolute !important;
    top: 50% !important;
    left: 50% !important;
    transform: translate(-50%, -50%) !important;
    text-align: center;
    background: rgba(255, 255, 255, 0.95);
    padding: 40px;
    border-radius: 20px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
    pointer-events: auto;
}

.start-screen h1 {
    color: #8B4513;
    font-size: 2.5rem;
    margin-bottom: 20px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
}

.start-screen p {
    color: #654321;
    font-size: 1.2rem;
    margin-bottom: 30px;
    line-height: 1.6;
}

.start-btn, .restart-btn {
    background: linear-gradient(45deg, #8B4513, #D2691E);
    color: white;
    border: none;
    padding: 15px 30px;
    border-radius: 25px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.start-btn:hover, .restart-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.3);
}

/* 게임 오버 화면 */
.game-over-screen {
    position: fixed !important;
    top: 50% !important;
    left: 50% !important;
    transform: translate(-50%, -50%) !important;
    text-align: center;
    background: rgba(255, 255, 255, 0.98);
    padding: 40px;
    border-radius: 20px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
    pointer-events: auto;
    opacity: 0;
    z-index: 9999;
    transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    backdrop-filter: blur(10px);
    border: 2px solid rgba(139, 69, 19, 0.3);
    
    /* 강력한 중앙 정렬 보장 */
    margin: 0;
    max-width: 90vw;
    max-height: 90vh;
    overflow-y: auto;
    
    /* 모든 브라우저에서 중앙 정렬 보장 */
    -webkit-transform: translate(-50%, -50%) !important;
    -moz-transform: translate(-50%, -50%) !important;
    -ms-transform: translate(-50%, -50%) !important;
    -o-transform: translate(-50%, -50%) !important;
}

.game-over-screen.show {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1) !important;
    
    /* 모든 브라우저에서 중앙 정렬 보장 */
    -webkit-transform: translate(-50%, -50%) scale(1) !important;
    -moz-transform: translate(-50%, -50%) scale(1) !important;
    -ms-transform: translate(-50%, -50%) scale(1) !important;
    -o-transform: translate(-50%, -50%) scale(1) !important;
}

.game-over-screen h2 {
    color: #8B4513;
    font-size: 2rem;
    margin-bottom: 20px;
}

.score-display {
    margin-bottom: 20px;
}

.score-display p {
    color: #654321;
    font-size: 1.2rem;
    margin-bottom: 10px;
}

.score-display span {
    font-weight: 700;
    color: #8B4513;
}

/* 추가 통계 표시 */
.stats-display {
    margin-bottom: 20px;
    padding-top: 15px;
    border-top: 1px solid rgba(101, 67, 33, 0.3);
}

.stats-display p {
    color: #654321;
    font-size: 1rem;
    margin-bottom: 8px;
}

.stats-display span {
    font-weight: 600;
    color: #8B4513;
}

/* 상단 컨트롤 바 */
.bottom-controls {
    position: absolute;
    top: 20px;
    left: 20px;
    right: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 20;
    pointer-events: auto;
}

.back-btn a {
    color: white;
    text-decoration: none;
    padding: 10px 15px;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 5px;
    font-weight: 500;
    transition: all 0.3s ease;
}

.back-btn a:hover {
    background: rgba(0, 0, 0, 0.7);
    transform: translateY(-2px);
}

/* 게임 내 언어 선택기 */
.game-language-selector {
    position: absolute;
    top: 0px;
    right: 20px;
    z-index: 30;
    pointer-events: auto;
}

.game-language-selector select {
    background: rgba(0, 0, 0, 0.5);
    color: white;
    border: none;
    padding: 8px 12px;
    border-radius: 5px;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.3s ease;
    outline: none;
}

.game-language-selector select:hover {
    background: rgba(0, 0, 0, 0.7);
    transform: translateY(-2px);
}

.game-language-selector option {
    background: #333;
    color: white;
}

/* 반응형 디자인 - 모바일 */
@media (max-width: 768px) {
    .ui-overlay {
        width: min(95vw, 90vh * 4/3);
        height: min(95vw * 3/4, 90vh);
    }
    
    .ui-overlay.game-mode {
        height: min(95vw * 3/4, 90vh) !important; /* gameCanvas와 동일한 높이, aspect-ratio 무시 */
        aspect-ratio: unset; /* aspect-ratio 비활성화 */
    }
    
    /* 하트 컨테이너 - 캔버스 바로 아래에 배치 */
    .hearts-container {
        position: absolute;
        bottom: -50px;
        left: 50%;
        transform: translateX(-50%);
        z-index: 150;
    }
    
    /* 시간 바 컨테이너 - 하트 바로 아래에 배치 */
    .time-bar-container {
        position: absolute;
        bottom: -90px;
        left: 50%;
        transform: translateX(-50%);
        width: 70%;
        z-index: 150;
    }
    
    /* 콤보 표시 - 캔버스 아래에 배치 */
    .combo-display {
        position: absolute;
        bottom: 20px;
        left: 50%;
        transform: translateX(-50%);
        z-index: 150;
    }
    
    .combo-text {
        font-size: 28px;
        margin-bottom: 3px;
    }
    
    .combo-number {
        font-size: 72px;
    }
    
    .start-screen, .game-over-screen {
        width: 90%;
        padding: 30px 20px;
    }
    
    .start-screen h1 {
        font-size: 2rem;
    }
    
    .back-btn {
        top: 10px;
        left: 10px;
    }
}

@media (max-width: 480px) {
    .ui-overlay {
        width: min(98vw, 95vh * 4/3);
        height: min(98vw * 3/4, 95vh);
    }
    
    .ui-overlay.game-mode {
        height: min(98vw * 3/4, 95vh) !important; /* gameCanvas와 동일한 높이, aspect-ratio 무시 */
        aspect-ratio: unset; /* aspect-ratio 비활성화 */
    }
    
    /* 더 작은 모바일에서도 캔버스 기준으로 UI 요소 배치 */
    .hearts-container {
        position: absolute;
        bottom: -45px;
        left: 50%;
        transform: translateX(-50%);
        gap: 8px;
        z-index: 150;
    }
    
    .heart {
        font-size: 18px;
    }
    
    .time-bar-container {
        position: absolute;
        bottom: -80px;
        left: 50%;
        transform: translateX(-50%);
        width: 65%;
        z-index: 150;
    }
    
    .time-bar {
        height: 12px;
        border-radius: 6px;
    }
    
    .combo-display {
        position: absolute;
        bottom: 20px;
        left: 50%;
        transform: translateX(-50%);
        z-index: 150;
    }
    
    .combo-text {
        font-size: 24px;
        margin-bottom: 2px;
    }
    
    .combo-number {
        font-size: 48px;
    }
    
    .start-screen h1 {
        font-size: 1.8rem;
    }
    
    .start-screen p {
        font-size: 1rem;
    }
    
    .start-btn, .restart-btn {
        padding: 12px 25px;
        font-size: 1rem;
    }
}


/* 태블릿 최적화 */
@media (min-width: 481px) and (max-width: 1024px) {
    .ui-overlay {
        width: min(90vw, 85vh * 4/3);
        height: min(90vw * 3/4, 85vh);
    }
    
    .ui-overlay.game-mode {
        height: min(90vw * 3/4, 85vh) !important; /* gameCanvas와 동일한 높이, aspect-ratio 무시 */
        aspect-ratio: unset; /* aspect-ratio 비활성화 */
    }
    
    .start-screen, .game-over-screen {
        width: 80%;
        padding: 35px 25px;
    }
    
    .start-screen h1, .game-over-screen h1 {
        font-size: 2.2rem;
    }
    
    .start-btn, .restart-btn {
        padding: 14px 28px;
        font-size: 1.1rem;
    }
    
    /* 모바일에서 하단 컨트롤 조정 */
    .bottom-controls {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    
    .game-language-selector {
        align-self: flex-end;
    }
    
    .game-language-selector select {
        padding: 12px 16px;
        font-size: 18px;
    }
}

/* 터치 디바이스 최적화 */
@media (hover: none) and (pointer: coarse) {
    .start-btn, .restart-btn, .back-btn {
        min-height: 44px;
        min-width: 44px;
    }
}

/* 고해상도 디스플레이 최적화 */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    #gameCanvas {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
}

/* 다크 모드 지원 */
@media (prefers-color-scheme: dark) {
    .start-screen, .game-over-screen {
        background: rgba(30, 30, 30, 0.95);
        color: #ffffff;
    }
    
    .start-screen h1, .game-over-screen h1 {
        color: #ffffff;
    }
    
    .start-screen p, .game-over-screen p {
        color: #cccccc;
    }
}
