/* game.css */
@font-face {
    font-family: 'SchoolSafetyNotification';
    src: url('https://cdn.jsdelivr.net/gh/projectnoonnu/2408-5@1.0/HakgyoansimAllimjangTTF-R.woff2') format('woff2');
    font-weight: 400;
    font-display: swap;
}

@font-face {
    font-family: 'SchoolSafetyNotification';
    src: url('https://cdn.jsdelivr.net/gh/projectnoonnu/2408-5@1.0/HakgyoansimAllimjangTTF-B.woff2') format('woff2');
    font-weight: 700;
    font-display: swap;
}

/* 모든 요소에서 텍스트 선택 방지 */
* {
    user-select: none;
    caret-color: transparent;
}

/* 이름 입력란은 예외로 텍스트 선택 허용 */
#playerNameInput {
    user-select: text;
    caret-color: #664940;
}

body {
    margin: 0;
    padding: 0;
    overflow: hidden;
    background-color: #f4d8d0;
    font-family: 'SchoolSafetyNotification', sans-serif;
}

#gameSection {
    position: relative;
    margin: 0 auto;
    overflow: hidden;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    width: 100%;
    max-width: 720px; /* 최대 너비 제한 */
    height: 100vh; /* 전체 화면 높이 */
    display: flex;
    flex-direction: column;
}

#gameTable {
    width: 100%;
    height: 100%;
    border-collapse: collapse;
}

#gameTable td {
    padding: 0;
    vertical-align: top;
}

#soundContainer {
    text-align: right;
    padding: 10px;
    height: 100%; /* 셀 높이 전체 사용 */
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px; /* 버튼들 사이의 간격을 줄여서 더 균등하게 */
}

#soundButton, #helpButton, #rankingButton, #pauseButton {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    cursor: pointer;
    pointer-events: auto;
    z-index: 2;
    transition: transform 0.2s ease;
}

#soundButton:hover, #helpButton:hover, #rankingButton:hover, #pauseButton:hover {
    transform: scale(1.1);
}

#logoContainer {
    display: flex;
    justify-content: center;
    align-items: center;
    background-size: cover;
    background-position: center;
    height: 100%; /* 셀 높이 전체 사용 */
}

#logoImg {
    max-width: 100%;
    max-height: 100%;
    width: 55%;
    height: auto;
    object-fit: contain; /* 비율 유지하며 셀에 맞춤 */
}

#nameInputContainer {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%; /* 셀 높이 전체 사용 */
}

#playerNameInput {
    width: 200px;
    height: 60px;
    border: 4px solid #664940;
    border-radius: 30px;
    font-size: 18px;
    padding: 10px 10px 10px 20px;
    box-sizing: border-box;
    background-color: rgba(244, 226, 208, 0.9);
    font-family: 'SchoolSafetyNotification', sans-serif;
    color: #664940;
    ime-mode: disabled; /* 한글 입력기 비활성화 */
}

#playerNameInput::placeholder {
    font-family: 'SchoolSafetyNotification', sans-serif;
    color: #664940;
    opacity: 1;
}

#startButtonContainer {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%; /* 셀 높이 전체 사용 */
}

#startButtonImg {
    max-width: 100%;
    max-height: 100%;
    width: 50%;
    height: auto;
    cursor: pointer;
    object-fit: contain; /* 비율 유지하며 셀에 맞춤 */
    margin: 5px;
}

.hard-mode-btn {
    background: linear-gradient(135deg, #706161, #413a38);
    border: none;
    border-radius: 20px;
    color: white;
    font-size: 16px;
    font-weight: bold;
    padding: 8px 16px;
    cursor: pointer;
    font-family: 'SchoolSafetyNotification', sans-serif;
    box-shadow: 0 3px 0px rgb(41, 37, 37);
    transition: all 0.2s ease;
    text-shadow: none;
    border: 0px solid rgba(255, 255, 255, 0.2);
    width: 50%;
    height: auto;
    object-fit: contain;
    margin: 0;
}

.hard-mode-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(255, 107, 107, 0.4);
    background: linear-gradient(135deg, #ff5252, #ff7979);
}

.hard-mode-btn:active {
    transform: scale(0.98);
    box-shadow: 0 2px 6px rgba(255, 107, 107, 0.3);
}

#startButtonContainer {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%; /* 셀 높이 전체 사용 */
    flex-direction: column;
    gap: 8px;
}

#uiContainer {
    text-align: center;
    padding: 20px 0 20px 0; /* 하단 패딩을 30px로 늘려서 timeBarRow와의 간격 확보 */
    pointer-events: none;
    height: 100%; /* 셀 높이 전체 사용 */
    display: flex;
    flex-direction: column;
    justify-content: center;
}

#statusTable {
    width: 100%;
    table-layout: fixed;
    text-align: center;
    color: #53403a;
    font-family: SchoolSafetyNotification, sans-serif;
    font-size: 18px;
    text-shadow: none;
}

.valueCell {
    font-family: SchoolSafetyNotification, sans-serif;
    font-size: 24px;
    color: #fff; /* 공통 텍스트 색상 */
    border: none;
    border-radius: 50px;
    padding: 5px 10px;
    cursor: default;
    transition: transform 0.1s;
    width: 85%;
    box-sizing: border-box;
    box-shadow: 0px 5px 0px 0px rgba(0, 0, 0, 0.3); /* 공통 그림자, 색상은 ID별로 조정 */
}

#scoreValue {
    background-color: #70c7ff; /* 점수: 파란색 (restartButton 스타일) */
    box-shadow: 0px 5px 0px 0px #377cb7; /* 맞춤 그림자 */
}

#scoreValue:hover {
    background-color: #5abaff;
}

#scoreValue:active {
    transform: translateY(2px);
    box-shadow: 0px 3px 0px 0px #377cb7;
}

#comboValue {
    background-color: #58a890; /* 콤보: 녹색 (shareButton 스타일) */
    box-shadow: 0px 5px 0px 0px #2e8780; /* 맞춤 그림자 */
}

#comboValue:hover {
    background-color: #4a9b7e;
}

#comboValue:active {
    transform: translateY(2px);
    box-shadow: 0px 3px 0px 0px #2e8780;
}

#timeLeftValue {
    background-color: #ff93a2; /* 남은 시간: 핑크/빨간색 (timeBar 스타일) */
    box-shadow: 0px 5px 0px 0px #d85f70; /* 맞춤 그림자 (배경색에 맞춰 어두운 변형) */
}

#timeLeftValue:hover {
    background-color: #ff7f90;
}

#timeLeftValue:active {
    transform: translateY(2px);
    box-shadow: 0px 3px 0px 0px #d85f70;
}


#timeBarContainer {
    width: 80%;
    height: 20px; /* 퍼센트 대신 고정 px로 변경: 부모 높이가 작아도 보이게 함. 필요 시 조정 */
    background: #a3c1b5;
    border-radius: 20px;
    overflow: hidden;
    margin: 0 auto;
    border: 4px solid #664940;
    position: relative; /* 추가: 내부 요소 위치 안정화 */
}

#timeBar {
    height: 100%;
    background: #ff93a2;
    transition: width 0.3s ease-in-out; /* 시간 늘려서 변화가 더 잘 보이게 */
    width: 80%; /* 초기 너비 명시: JS에서 오버라이드됨 */
}

#gameCanvasContainer {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 92%; /* 크기 조정으로 여백 확보 */
    height: 92%;
    margin: 0 auto; /* 중앙 정렬 */
    position: relative; /* 오버레이를 위한 상대 위치 */
    
    /* 배경 이미지 설정 */
    background-image: url('images/sectionbg.jpg');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;

    border: 4px solid #664940;     /* 외곽선 */
    border-radius: 20px;         /* 모서리 둥글게 */
    overflow: hidden;            /* 내부 캔버스가 넘치지 않도록 */
}

#gameCanvasContainer::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.336); /* 어두운 오버레이 */
    border-radius: 16px; /* 컨테이너보다 약간 작게 */
    pointer-events: none; /* 클릭 이벤트 차단하지 않음 */
    z-index: 1; /* 캔버스 위에 표시 */
    transition: background 0.3s ease;
}

/* 하드모드일 때 오버레이 더 밝게 */
#gameCanvasContainer.hard-mode::before {
    background: rgba(0, 0, 0, 0.0); /* 더 어두운 오버레이 */
}

#gameCanvas {
    background: transparent; /* 캔버스 배경 투명 유지 */
    width: 100%;
    height: 100%;
    position: relative;
    z-index: 2; /* 오버레이 위에 표시 */
}

#timeBarRow td,
#gameCanvasRow td {
    text-align: center;
    vertical-align: middle;
}

#gameOverOverlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    pointer-events: auto;
}

#gameOverTitle {
    color: #fff;
    font-family: SchoolSafetyNotification, sans-serif;
    font-size: 42px;
    margin-bottom: 20px;
}

#restartButton, #shareButton {
    width: 200px;
    padding: 10px;
    margin: 10px 0;
    border: none;
    border-radius: 10px;
    font-size: 28px;
    color: #fff;
    cursor: pointer;
    position: relative;
    z-index: 1001;
    pointer-events: auto;
}

#restartButton {
    background-color: #70c7ff;
    font-family: SchoolSafetyNotification, sans-serif;
    font-size: 24px;
    box-shadow: 0px 5px 0px 0px #377cb7;
}

#shareButton {
    background-color: #58a890;
    font-family: SchoolSafetyNotification, sans-serif;
    font-size: 24px;
    box-shadow: 0px 5px 0px 0px #2e8780;
}

@media (max-width: 768px) {
    .valueCell {
        font-size: 20px;
        padding: 3px 8px;
    }
    /* ID별 색상은 그대로 유지됨 */
}
    #statusTable {
        font-size: 22px; /* 기존 */
        font-family: SchoolSafetyNotification, sans-serif;
    }
    #statusTable td {
        width: 33.33%; /* 모바일에서도 유지 */
    }

    #timeBarContainer {
        height: 12px;
        width: calc(96% - 10px);
        margin-bottom: 5px; /* timeBar와 gameCanvas 사이 간격 추가 */
    }
    #playerNameInput {
        font-size: 16px;
        width: 180px;
        max-width: 80%;
    }
    #soundButton {
        max-width: 100px;
        max-height: 50px;
    }
    #gameOverTitle {
        font-size: 32px;
    }
    #restartButton, #shareButton {
        width: 160px;
        font-size: 20px;
    }
    #shareButton {
        font-size: 18px;
    }
    #gameCanvasContainer {
        width: 95%; /* 모바일에서 더 넓게 */
        height: 95%;

    }

/* 새로 추가: pauseButton 스타일 (soundButton과 비슷하게) */
#pauseButton {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    cursor: pointer;
    pointer-events: auto;
    z-index: 2;
}

/* 게임설명 오버레이 스타일 */
#helpOverlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    cursor: pointer;
}

#helpImage {
    max-width: 90%;
    max-height: 90%;
    object-fit: contain;
    border-radius: 10px;
    box-shadow: none;
}

/* 게임 보드 애니메이션 */
@keyframes swapAnimation {
    0% { transform: translateX(0); }
    25% { transform: translateX(calc(200% + 8px)); }
    50% { transform: translateX(calc(200% + 8px)); }
    75% { transform: translateX(0); }
    100% { transform: translateX(0); }
}

@keyframes swapAnimationReverse {
    0% { transform: translateX(0); }
    25% { transform: translateX(calc(-200% - 8px)); }
    50% { transform: translateX(calc(-200% - 8px)); }
    75% { transform: translateX(0); }
    100% { transform: translateX(0); }
}

.emoji-swap-animation {
    animation: swapAnimation 4s ease-in-out infinite;
}

.emoji-swap-animation-delayed {
    animation: swapAnimationReverse 4s ease-in-out infinite;
}

/* 랭킹 오버레이 스타일 */
#rankingOverlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

#rankingOverlayContent {
    width: 90%;
    height: 90%;
    max-width: 1000px;
    max-height: 800px;
    background: white;
    border-radius: 15px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

#rankingOverlayHeader {
    background: #4a3d36;
    color: #f3eadf;
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#rankingOverlayHeader h2 {
    margin: 0;
    font-size: 24px;
    font-weight: bold;
}

#closeRankingButton {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: none;
    width: 35px;
    height: 35px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 18px;
    font-weight: bold;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

#closeRankingButton:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

#rankingFrame {
    width: 100%;
    height: calc(100% - 65px);
    border: none;
    background: white;
}

/* 모바일 반응형 */
@media (max-width: 768px) {
    #rankingOverlayContent {
        width: 95%;
        height: 95%;
        border-radius: 10px;
    }
    
    #rankingOverlayHeader {
        padding: 12px 15px;
    }
    
    #rankingOverlayHeader h2 {
        font-size: 20px;
    }
    
    #closeRankingButton {
        width: 30px;
        height: 30px;
        font-size: 16px;
    }
}

/* 새로 추가: pauseOverlay 스타일 (gameOverOverlay와 유사) */
#pauseOverlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgb(58, 58, 58);  /* 완전 불투명으로 변경 */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 3;
    pointer-events: auto;
}

#pauseTitle {
    color: #fff;
    font-family: SchoolSafetyNotification, sans-serif;
    font-size: 42px;
    margin-bottom: 20px;
}

#resumeButton {
    width: 200px;
    padding: 10px;
    margin: 10px 0;
    border: none;
    border-radius: 10px;
    font-size: 28px;
    color: #fff;
    cursor: pointer;
    background-color: #70c7ff; /* restartButton과 비슷한 스타일 */
    font-family: SchoolSafetyNotification, sans-serif;
    box-shadow: 0px 5px 0px 0px #377cb7;
}

/* PWA 설치 버튼 스타일 */
#installButtonContainer {
    text-align: center;
    padding: 10px 0;
    margin-top: 30px;
}

.install-btn {
    background: linear-gradient(135deg, #e67575, #e67575);
    border: none;
    border-radius: 25px;
    color: white;
    font-size: 18px;
    font-weight: bold;
    padding: 12px 24px;
    cursor: pointer;
    font-family: 'SchoolSafetyNotification', sans-serif;
    box-shadow: 0 4px 15px rgba(255, 107, 107, 0.3);
    transition: all 0.3s ease;
    text-shadow: none;
    border: 2px solid rgba(255, 255, 255, 0.2);
}

.install-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(255, 107, 107, 0.4);
    background: linear-gradient(135deg, #ff5252, #ff7979);
}

.install-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 10px rgba(255, 107, 107, 0.3);
}

.install-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* 모바일 반응형 */
@media (max-width: 768px) {
    #pauseButton {
        max-width: 80px; /* 모바일에서 작게 */
        max-height: 40px;
    }
    #pauseTitle {
        font-size: 32px;
    }
    #resumeButton {
        width: 160px;
        font-size: 20px;
    }
    
    .install-btn {
        font-size: 16px;
        padding: 10px 20px;
    }
    
    .hard-mode-btn {
        font-size: 14px;
        padding: 6px 12px;
        width: 60%;
    }
}