/* ==========================================================================
   Cupid Global Styles (공통 스타일 및 초기화)
   ========================================================================== */

/* 전체 요소 초기화 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box; /* 패딩과 테두리를 너비에 포함 */
}

/* 기본 문서 구조 설정 */
body, html {
    width: 100%;
    height: 100%;
    overflow: hidden; /* 스크롤 방지 */
    background-color: #000;
    font-family: 'Pretendard', sans-serif; /* 가독성 좋은 프리텐다드 서체 사용 */
}

/* ==========================================================================
   Layout Containers (레이아웃 컨테이너)
   ========================================================================== */

/* 게임 전체 화면을 감싸는 컨테이너 */
#game-container {
    position: relative;
    width: 100%;
    height: 100%;
    max-width: 1280px; /* 고해상도 모니터에서도 16:9 비율 유지 권장 */
    margin: 0 auto;    /* 중앙 정렬 */
    background-color: #222;
    overflow: hidden;
}

/* 배경 이미지 레이어 */
#background-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: #333;
    background-size: cover;     /* 화면에 꽉 차게 */
    background-position: center; /* 가운데 정렬 */
    transition: background-image 0.5s ease-in-out, filter 1s ease-in-out; /* 배경 전환 효과 */
}

/* 배경 시간대별 필터 효과 */
#background-layer.night {
    filter: brightness(0.3) sepia(0.3) hue-rotate(210deg) saturate(0.8); /* 밤: 어둡고 푸른 톤 */
}

#background-layer.sunset {
    filter: brightness(0.65) sepia(0.6) hue-rotate(-25deg) saturate(1.4); /* 노을: 따뜻한 오렌지 톤 */
}

/* ==========================================================================
   Character System (캐릭터 표시 시스템)
   ========================================================================== */

/* 캐릭터를 배치하는 레이어 */
#character-layer {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 100%; /* 화면 전체 높이를 기준으로 밑단 정렬 */
    pointer-events: none; /* 캐릭터 이미지가 클릭을 방해하지 않도록 설정 */
    z-index: 1;
    display: flex;
    justify-content: center;
    overflow: hidden;
}

/* 캐릭터 슬롯 (왼쪽, 중앙, 오른쪽 공통) */
.char-slot {
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 800px;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: flex-end; /* 캐릭터 발밑을 바닥에 고정 */
    transition: all 0.3s ease-in-out;
}

/* 캐릭터 이미지 설정 */
.char-slot img {
    height: 100%; /* 슬롯 높이에 꽉 차게 (비율 유지) */
    width: auto;
    max-width: none;
    object-fit: contain;
    /* 모바일 기기 하드웨어 가속 및 잔상 방지 */
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    transition: transform 0.3s ease, filter 0.3s ease;
}

/* ==========================================================================
   Live2D-like Animations (가상 Live2D 효과)
   ========================================================================== */

/* [가상 Live2D: 호흡] 
   캐릭터가 살아있는 느낌을 주기 위해 상하로 미세하게 움직임
   - 4초 주기로 부드럽게 반복
   - translateY(-2px): 살짝 위로 들석임으로 호흡 연출
   - scale(1.005): 아주 미세하게 커지는 효과 (가슴 부푸는 연출)
*/
@keyframes breathing {
    0%, 100% { transform: translateY(0) scale(1); }
    50% { transform: translateY(-2px) scale(1.005); } 
}

.char-breathing {
    animation: breathing 4s ease-in-out infinite;
    transform-origin: bottom center; /* 캐릭터 발바닥 기준으로 애니메이션 발생 */
}

/* [가상 Live2D: 말하기]
   현재 대사를 하고 있는 캐릭터임을 나타내기 위한 강조 효과
   - 호흡 애니메이션과 주기를 맞춰 어색함 제거 (4초)
   - !important를 사용하여 기본 상태보다 우선적으로 움직임 부여
*/
@keyframes talking-bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-2px); } 
}

.char-talking {
    animation: talking-bounce 4s ease-in-out infinite !important; 
}

/* 슬롯별 위치 오프셋 (1280px 기준 상대 위치) */
#char-left {
    transform: translateX(-80%); /* 중앙에서 왼쪽으로 이동 */
    z-index: 1;
}

#char-left img {
    transform: scale(0.9); /* 좌측 캐릭터 크기 */
    transform-origin: bottom center;
}

#char-center {
    transform: translateX(-50%); /* 정확히 중앙 */
    z-index: 2; /* 중앙 캐릭터를 가장 앞으로 */
}

#char-right {
    transform: translateX(-25%); /* 중앙에서 오른쪽으로 이동 */
    z-index: 3; /* 오른쪽 캐릭터를 가장 앞으로 */
}

#char-right img {
    transform: scale(0.9); /* 우측 캐릭터 크기 */
    transform-origin: bottom center;
    mix-blend-mode: lighten; /* 겹치는 부분에서 밝은 색이 보임 */
}

/* ==========================================================================
   UI Layer: Conversation & Choice (UI 레이어: 대화창 및 선택지)
   ========================================================================== */

/* 대화창과 버튼들이 담기는 최상위 UI 레이어 */
#ui-layer {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    padding: 20px;
    padding-bottom: calc(20px + env(safe-area-inset-bottom)); /* 아이폰 노치 디자인 대응 */
    pointer-events: none; /* UI 빈 공간 클릭 시 투과되도록 설정 */
    z-index: 110; 
}

/* 대화 텍스트 박스 */
#dialogue-box {
    position: relative;
    width: 100%;
    min-height: 150px;
    background: rgba(0, 0, 0, 0.5); /* 반투명 검정 */
    border: 2px solid #ff69b4;      /* 시그니처 핑크 테두리 */
    border-radius: 10px;
    padding: 20px;
    color: #fff;
    cursor: pointer;
    pointer-events: auto; /* 박스 내부는 클릭 가능 */
    margin-bottom: 10px;
}

/* 캐릭터 이름 태그 */
#name-tag {
    position: absolute;
    top: -25px; /* 대화창 위로 걸치게 배치 */
    left: 20px;
    background: #ff69b4;
    padding: 5px 15px;
    border-radius: 5px;
    font-weight: bold;
    font-size: 1.1rem;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
}

/* 실제 대화 내용 */
#message {
    font-size: 1.2rem;
    line-height: 1.6;
    word-break: keep-all; /* 단어 단위 줄바꿈으로 가독성 향상 */
    white-space: pre-wrap; /* 줄바꿈 기호 유지 */
}

/* 다음 장면 표시 화살표 */
#next-indicator {
    position: absolute;
    bottom: 10px;
    right: 20px;
    animation: bounce 1s infinite; /* 통통 튀는 애니메이션 */
}

/* 다음 표시 애니메이션 정의 */
@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(5px); }
}

/* 선택지 버튼 컨테이너 */
#choice-container {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 8px; /* 버튼들 사이의 간격 */
    pointer-events: auto;
    z-index: 10;
    margin-bottom: 20px;
}

/* 개별 선택지 버튼 */
.choice-btn {
    background: rgba(0, 0, 0, 0.5);
    border: 2px solid #ff69b4;
    color: #fff;
    padding: 12px 20px;
    border-radius: 15px;
    font-size: 1.1rem;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

/* 선택지 버튼 호버/반응 효과 */
.choice-btn:hover {
    background: #ff69b4;
    transform: scale(1.02); /* 살짝 커지는 효과 */
}

/* ==========================================================================
   Free-Talking System (프리토킹 채팅 시스템)
   ========================================================================== */

/* 자유 대화 입력 컨테이너 */
#chat-container {
    width: 100%;
    background: rgba(0, 0, 0, 0.5);
    border: 2px solid #ff69b4;
    border-radius: 15px;
    padding: 12px;
    pointer-events: auto;
    z-index: 120;
    margin-bottom: 10px;
}

/* 채팅 가이드 라벨 */
#chat-guide {
    font-size: 0.8rem;
    color: #ffb6c1;
    margin-bottom: 8px;
    padding-left: 8px;
    border-left: 2px solid #ff69b4;
    line-height: 1.4;
    opacity: 0.9;
}

/* 채팅 입력창 및 버튼 감싸기 */
#chat-input-wrapper {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
}

/* 채팅 입력란 */
#chat-input {
    flex: 1;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid #ff69b4;
    border-radius: 8px;
    padding: 8px 12px;
    color: #fff;
    font-size: 0.95rem;
    outline: none;
    min-width: 0;
}

/* 채팅 전송 버튼 */
#chat-send {
    background: #ff69b4;
    border: none;
    border-radius: 50%;
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    cursor: pointer;
    transition: all 0.2s;
    padding: 0;
    flex-shrink: 0;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

/* 전송 아이콘(SVG) */
#chat-send svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
    margin-left: 2px;
}

#chat-send:hover {
    background: #ff1493;
    transform: scale(1.05);
}

#chat-send:disabled {
    background: #ccc;
    cursor: not-allowed;
}

/* 채팅 스킵(그만하기) 버튼 */
#chat-skip-btn {
    background: #888;
    border: none;
    border-radius: 50%;
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    cursor: pointer;
    transition: all 0.2s;
    padding: 0;
    flex-shrink: 0;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

#chat-skip-btn svg {
    width: 20px;
    height: 20px;
    fill: none;
}

#chat-skip-btn:hover {
    background: #ff5e5e; /* 경고의 의미로 붉은 계열 호버 효과 */
    transform: scale(1.05);
}

#chat-skip-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
}

/* AI 응답 대기 로딩 효과 */
.loading-dots {
    font-size: 1.8rem;
    line-height: 1;
    display: inline-block;
    animation: loading-blink 1s infinite both;
    vertical-align: middle;
}

@keyframes loading-blink {
    0%, 100% { opacity: .3; transform: scale(0.8); }
    50% { opacity: 1; transform: scale(1.1); }
}

/* 대화창 생각중 상태 (테두리 반짝임) */
#dialogue-box.thinking-box {
    border-color: #ffb6c1;
    box-shadow: 0 0 15px rgba(255, 182, 193, 0.6);
    animation: box-glow 2s infinite ease-in-out;
}

@keyframes box-glow {
    0%, 100% { border-color: #ff69b4; box-shadow: 0 0 10px rgba(255, 105, 180, 0.4); }
    50% { border-color: #fff; box-shadow: 0 0 20px rgba(255, 105, 180, 0.8); }
}

/* 남은 대화 횟수 표시 */
#chat-turn-indicator {
    color: #ff69b4;
    font-size: 0.85rem;
    text-align: right;
    font-weight: bold;
}


/* ==========================================================================
   Settings UI (설정 메뉴)
   ========================================================================== */

/* 홈 버튼 스타일 (게임 화면 상단 중앙) */
#game-container #home-btn {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255, 105, 180, 0.5);
    color: white;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    pointer-events: auto;
    z-index: 150;
    transition: all 0.2s;
}

#game-container #home-btn:hover {
    background: rgba(255, 105, 180, 0.3);
    transform: translateX(-50%) scale(1.1);
}

/* 설정 버튼 스타일 (게임 화면 내 톱니바퀴) */
#game-container #settings-btn {
    position: absolute;
    top: 20px;
    right: 20px;
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255, 105, 180, 0.5);
    color: white;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    pointer-events: auto;
    z-index: 150;
    transition: all 0.2s;
}

#game-container #settings-btn:hover {
    background: rgba(255, 105, 180, 0.3);
    transform: rotate(30deg); /* 호버 시 살짝 회전하는 연출 */
}

/* ==========================================================================
   Modals & Overlays (모달 및 오버레이 공통)
   ========================================================================== */

/* 공통 모달 배경(오버레이) */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: none; /* 기본 숨김 */
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

/* 모달 활성화 상태 */
.modal-overlay.active {
    display: flex;
}

/* 모달 컨텐츠 박스 */
.modal-container {
    background: #1a1a1a;
    padding: 30px;
    border-radius: 20px;
    width: 90%;
    max-width: 400px;
    text-align: center;
    border: 2px solid #ff69b4;
    box-shadow: 0 0 20px rgba(255, 105, 180, 0.3);
}

.modal-title {
    margin-top: 0;
    margin-bottom: 25px;
    color: #ff69b4;
    font-size: 1.5rem;
}

/* ==========================================================================
   Responsive Design & Media Queries (반응형 최적화)
   ========================================================================== */

/* 세로 모드 (Portrait) 최적화 */
@media (orientation: portrait) {
    #character-layer {
        height: 90%; /* 세로 화면에서 캐릭터가 너무 크지 않게 소폭 축소 */
        bottom: 0;
    }

    .char-slot {
        max-width: 100%;
    }

    #char-left {
        transform: translateX(-70%);
    }

    #char-left img {
        transform: scale(0.8); /* 모바일에서 더 작게 */
    }

    #char-right {
        transform: translateX(-25%);
    }

    #char-right img {
        transform: scale(0.8); /* 모바일에서 더 작게 */
        mix-blend-mode: lighten;
    }

    #dialogue-box {
        min-height: 160px;
        padding: 25px 20px;
    }

    #message {
        font-size: 1.1rem; /* 모바일 가독성 대응 */
    }

    .choice-btn {
        padding: 15px;
        font-size: 1rem;
    }
}

/* 모바일 가로 모드 (Landscape) 최적화: 화면 높이가 작을 때 */
@media (max-height: 500px) and (orientation: landscape) {
    #character-layer {
        height: 100%;
        bottom: -10%; /* 캐릭터를 조금 더 아래로 내려서 상체 위주로 노출 */
    }

    #dialogue-box {
        min-height: 80px;
        padding: 10px 20px;
        margin-bottom: 5px;
        bottom: 5px;
    }

    #name-tag {
        top: -18px;
        font-size: 0.85rem;
        padding: 2px 8px;
    }

    #message {
        font-size: 0.95rem;
        line-height: 1.3;
    }

    #choice-container {
        gap: 8px;
        width: 100%;
        display: grid;
        grid-template-columns: 1fr 1fr; /* 2열로 배치하여 세로 공간 절약 */
        margin-bottom: 5px;
    }

    .choice-btn {
        padding: 8px 12px;
        font-size: 0.9rem;
        border-radius: 10px;
    }
}

/* ==========================================================================
   Game Effects & Transitions (게임 연출 및 배경 시스템)
   ========================================================================== */

/* 장면 전환 시 사용하는 페이드 검정 레이어 */
#fade-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: #000;
    opacity: 0;
    pointer-events: none;
    z-index: 100;
    transition: opacity 3s ease-in-out; /* 천천히 암전/명전 */
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
}

#fade-layer.active {
    opacity: 1;
}

/* To Be Continued... 텍스트 디자인 */
#tbc-text {
    color: #fff;
    font-size: 3rem;
    font-weight: bold;
    letter-spacing: 5px;
    opacity: 0;
    transform: translateY(20px);
    transition: all 2s ease-in-out;
    text-shadow: 0 0 20px rgba(255, 105, 180, 0.8);
}

#fade-layer.active #tbc-text.show {
    opacity: 1;
    transform: translateY(0);
}

/* 캐릭터 실루엣 효과 (어두운 연출용) */
.silhouette {
    filter: blur(2px) brightness(0.9);
    opacity: 0.5;
}

/* 생각 중인 연출 (캐릭터가 흐려지며 숨쉬는 듯한 효과) */
/* [가상 Live2D: 프리토킹 AI 응답 대기]
   AI 답변 생성 동안 캐릭터 몰입 상태 연출
   - opacity: 살짝 투명하게 하여 '회상'이나 '집중' 느낌 부여
   - filter: blur(1px)로 캐릭터 외곽을 부드럽게 처리
   - animation: thinking-breath로 느리고 깊은 호흡 연출
*/
.thinking {
    opacity: 0.9;
    filter: blur(1px);
    transition: all 0.5s ease-in-out;
    animation: thinking-breath 4s infinite ease-in-out; 
}

/* 프리토킹 시 사용하는 깊은 호흡 리듬
   - 일반 호흡보다 투명도 변화(0.85 ~ 1)를 추가하여 '고민 중' 시각화
*/
@keyframes thinking-breath {
    0%, 100% { 
        opacity: 0.85;
        transform: scale(1);
    }
    50% { 
        opacity: 1;
        transform: scale(1.005); 
    }
}

/* ==========================================================================
   Player Interface (사용자 입력 UI)
   ========================================================================== */

/* 이름 입력창 컨테이너 */
#name-input-container {
    margin-top: 15px;
    width: 100%;
    background: transparent;
    padding: 0;
    border-radius: 0;
    box-shadow: none;
    z-index: 150;
    text-align: center;
    pointer-events: auto;
}

#name-input-wrapper {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
    justify-content: center;
}

#player-name-input {
    flex: 1;
    max-width: 250px;
    padding: 8px 12px;
    border: 2px solid #ff69b4;
    border-radius: 10px;
    font-size: 0.95rem;
    outline: none;
    background: rgba(255, 255, 255, 0.9);
    color: #333;
}

#name-confirm-btn {
    padding: 0 15px;
    background: #ff69b4;
    color: white;
    border: none;
    border-radius: 10px;
    font-weight: bold;
    font-size: 0.85rem;
    cursor: pointer;
    transition: background 0.2s;
    white-space: nowrap;
    flex-shrink: 0;
}

#name-confirm-btn:hover {
    background: #ff1493;
}

/* 입력 안내 가이드 텍스트 */
#name-input-guide {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.8);
}

@media (max-width: 768px) {
    #name-input-container {
        margin-top: 10px;
    }
}

/* ==========================================================================
   Custom Confirmation Modals (커스텀 알림/확인창)
   ========================================================================== */

/* 커스텀 모달 오버레이 */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    backdrop-filter: blur(3px);
}

/* 모달 박스 내용 */
.modal-content {
    background: #222;
    border: 2px solid #ff69b4;
    border-radius: 20px;
    padding: 25px;
    width: 85%;
    max-width: 320px;
    text-align: center;
    box-shadow: 0 0 20px rgba(255, 105, 180, 0.3);
    animation: modal-appear 0.3s ease-out;
}

@keyframes modal-appear {
    from { transform: scale(0.9); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.modal-content p {
    color: #fff;
    font-size: 1.1rem;
    margin-bottom: 20px;
    line-height: 1.5;
    word-break: keep-all;
}

.modal-buttons {
    display: flex;
    gap: 12px;
    justify-content: center;
}

.modal-buttons button {
    padding: 10px 25px;
    border-radius: 10px;
    border: none;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 1rem;
}

#modal-confirm-btn {
    background: #ff69b4;
    color: white;
}

#modal-confirm-btn:hover {
    background: #ff1493;
    transform: translateY(-2px);
}

#modal-cancel-btn {
    background: #444;
    color: #ccc;
}

#modal-cancel-btn:hover {
    background: #555;
    color: #fff;
    transform: translateY(-2px);
}

/* ==========================================================================
   Mechanics: Affinity System (게임 시스템: 호감도)
   ========================================================================== */

/* 호감도 변화 시 화면 중앙에 나타나는 팝업 */
.affinity-popup {
    position: fixed;
    left: 50%;
    top: 40%;
    transform: translateX(-50%);
    font-size: 2rem;
    font-weight: bold;
    pointer-events: none;
    z-index: 9999;
    animation: affinityFloat 5s ease-out forwards;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

/* 긍정적 변화 (+) */
.affinity-popup.positive {
    color: #ff6b9d;
}

/* 부정적 변화 (-) */
.affinity-popup.negative {
    color: #7799ff;
}

/* 부정적일 때 이모지 색상 변경 */
.affinity-popup.negative .emoji {
    filter: hue-rotate(200deg) saturate(1.5);
}

.affinity-popup .emoji {
    font-size: 2.5rem;
}

.affinity-popup .value {
    font-size: 1.8rem;
}

/* 호감도 팝업 애니메이션 */
@keyframes affinityFloat {
    0% {
        opacity: 0;
        transform: translateX(-50%) translateY(20px) scale(0.5);
    }
    20% {
        opacity: 1;
        transform: translateX(-50%) translateY(0) scale(1.2);
    }
    40% {
        transform: translateX(-50%) translateY(-10px) scale(1);
    }
    100% {
        opacity: 0;
        transform: translateX(-50%) translateY(-80px) scale(0.8);
    }
}

