/**
 * ============================================================================
 * dialogue.css - 대화 시스템 전용 스타일
 * ============================================================================
 */

/* ===== FreeTalk Screen (AI 자유 대화) ===== */
#freetalk-screen {
    flex-direction: column;
    background: #000;
}

.ft-character {
    position: absolute;
    bottom: 40%;
    left: 50%;
    transform: translateX(-50%);
    height: 60%;
    z-index: 2;
    pointer-events: none;
}

.ft-character img {
    height: 100%;
    object-fit: contain;
    filter: drop-shadow(0 0 20px rgba(0, 0, 0, 0.5));
    transition: filter 0.3s ease;
}

/* 캐릭터 사고중 애니메이션 */
.ft-character img.thinking {
    filter: drop-shadow(0 0 20px rgba(0, 0, 0, 0.5)) brightness(0.85);
    animation: ft-thinking-pulse 1.5s ease-in-out infinite;
}

@keyframes ft-thinking-pulse {
    0%, 100% { filter: drop-shadow(0 0 20px rgba(0, 0, 0, 0.5)) brightness(0.85); }
    50% { filter: drop-shadow(0 0 25px rgba(255, 183, 197, 0.3)) brightness(0.95); }
}

/* 채팅 로그 영역 */
.ft-chat-log {
    position: absolute;
    bottom: 80px;
    left: 0;
    width: 100%;
    max-height: 40%;
    overflow-y: auto;
    padding: 1rem;
    z-index: 10;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    /* 스크롤바 커스텀 */
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 183, 197, 0.2) transparent;
}

.ft-chat-log::-webkit-scrollbar {
    width: 4px;
}

.ft-chat-log::-webkit-scrollbar-track {
    background: transparent;
}

.ft-chat-log::-webkit-scrollbar-thumb {
    background: rgba(255, 183, 197, 0.2);
    border-radius: 2px;
}

/* 채팅 메시지 버블 */
.ft-message {
    max-width: 80%;
    padding: 0.6rem 1rem;
    border-radius: 1rem;
    font-size: 0.9rem;
    line-height: 1.5;
    animation: msg-appear 0.3s ease;
    word-break: keep-all;
    overflow-wrap: break-word;
}

@keyframes msg-appear {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* 유저 메시지 (오른쪽) */
.ft-message.user {
    align-self: flex-end;
    background: rgba(255, 183, 197, 0.25);
    color: rgba(255, 240, 245, 0.95);
    border: 1px solid rgba(255, 183, 197, 0.3);
    border-bottom-right-radius: 0.2rem;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

/* 캐릭터 메시지 (왼쪽) */
.ft-message.char {
    align-self: flex-start;
    background: rgba(20, 12, 40, 0.7);
    color: rgba(255, 240, 245, 0.95);
    border: 1px solid rgba(255, 183, 197, 0.15);
    border-bottom-left-radius: 0.2rem;
    backdrop-filter: blur(4px);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

/* 시스템 메시지 (중앙) */
.ft-message.system {
    align-self: center;
    background: transparent;
    color: rgba(255, 240, 245, 0.5);
    font-size: 0.8rem;
    font-style: italic;
    text-align: center;
    border: none;
    padding: 0.4rem 0.8rem;
}

/* 타이핑 인디케이터 버블 */
.ft-message.ft-typing {
    color: rgba(255, 183, 197, 0.6);
    animation: msg-appear 0.3s ease, typing-dots 1.2s steps(4, end) infinite;
    font-size: 1.1em;
    letter-spacing: 0.3em;
}

/* 액션(지문) 텍스트 */
.ft-action {
    display: inline;
    color: rgba(255, 183, 197, 0.75);
    font-style: italic;
}

/* 입력 영역 */
.ft-input-area {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    display: flex;
    padding: 0.8rem;
    gap: 0.5rem;
    background: linear-gradient(180deg, rgba(0, 0, 0, 0.6) 0%, rgba(0, 0, 0, 0.9) 100%);
    z-index: 15;
    align-items: center;
    border-top: 1px solid rgba(255, 183, 197, 0.1);
}

#ft-input {
    flex: 1;
    font-family: var(--font-main);
    font-size: 0.95rem;
    padding: 0.6rem 1rem;
    border: 1px solid rgba(255, 183, 197, 0.3);
    border-radius: 1.5rem;
    outline: none;
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
    /* 채팅 입력은 텍스트 선택 허용 */
    -webkit-user-select: text;
    -moz-user-select: text;
    user-select: text;
}

#ft-input::placeholder {
    color: rgba(255, 183, 197, 0.35);
}

#ft-input:focus {
    border-color: var(--color-accent);
    box-shadow: 0 0 12px rgba(255, 105, 180, 0.15);
}

#ft-input:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.ft-send-btn {
    background: rgba(255, 183, 197, 0.2);
    color: rgba(255, 240, 245, 0.9);
    border: 1px solid rgba(255, 183, 197, 0.3);
    padding: 0.6rem 1.2rem;
    font-family: var(--font-main);
    font-size: 0.9rem;
    border-radius: 1.5rem;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
    transition: all 0.2s ease;
    backdrop-filter: blur(4px);
}

.ft-send-btn:hover {
    background: rgba(255, 183, 197, 0.35);
    border-color: rgba(255, 183, 197, 0.6);
    color: #fff;
    box-shadow: 0 0 15px rgba(255, 105, 180, 0.2);
}

.ft-send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* 남은 대화 횟수 표시 */
.ft-turns {
    position: absolute;
    top: 0.8rem;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.75rem;
    color: rgba(255, 183, 197, 0.5);
    z-index: 15;
    background: rgba(0, 0, 0, 0.4);
    padding: 0.2rem 0.8rem;
    border-radius: 1rem;
    letter-spacing: 0.05em;
    backdrop-filter: blur(4px);
    white-space: nowrap;
}

/* ===== FreeTalk Input (동적 생성, choice-panel 내부) ===== */
.freetalk-input-container {
    display: flex;
    gap: 8px;
    padding: 8px 12px;
    align-items: center;
    width: 90%;
    max-width: 500px;
    margin: 0 auto;
}

.freetalk-input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid rgba(255, 183, 197, 0.3);
    border-radius: 1.5rem;
    background: rgba(10, 8, 20, 0.8);
    color: rgba(255, 240, 245, 0.95);
    font-family: var(--font-main);
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.freetalk-input::placeholder {
    color: rgba(255, 183, 197, 0.35);
}

.freetalk-input:focus {
    border-color: var(--color-accent);
    box-shadow: 0 0 12px rgba(255, 105, 180, 0.15);
}

.freetalk-send-btn {
    padding: 10px 20px;
    border: 1px solid rgba(255, 183, 197, 0.3);
    border-radius: 1.5rem;
    background: rgba(255, 183, 197, 0.15);
    color: rgba(255, 240, 245, 0.9);
    font-family: var(--font-main);
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    flex-shrink: 0;
    backdrop-filter: blur(4px);
}

.freetalk-send-btn:hover {
    background: rgba(255, 183, 197, 0.3);
    border-color: rgba(255, 183, 197, 0.6);
    color: #fff;
    box-shadow: 0 0 15px rgba(255, 105, 180, 0.2);
}

/* ===== Messenger Typing Indicator ===== */
.messenger-typing {
    min-height: 1.5em;
}

.freetalk-typing {
    color: rgba(255, 183, 197, 0.6);
    font-size: 1.2em;
    letter-spacing: 0.3em;
}

.typing-indicator {
    display: inline-block;
    letter-spacing: 0.3em;
    animation: typing-dots 1.2s steps(4, end) infinite;
    opacity: 0.6;
    font-size: 1.2em;
}

@keyframes typing-dots {
    0%   { opacity: 0.2; }
    20%  { opacity: 0.6; }
    50%  { opacity: 1; }
    100% { opacity: 0.2; }
}

/* ===== Messenger Read Badge ===== */
.messenger-read-badge {
    text-align: right;
    color: rgba(255, 183, 197, 0.5);
    font-size: 0.85em;
    padding: 8px 16px;
    font-family: var(--font-main);
    animation: msg-appear 0.3s ease;
}

/* ===== FreeTalk 반응형 ===== */
@media (max-width: 768px) {
    .ft-character {
        height: 55%;
    }
    .ft-chat-log {
        max-height: 35%;
        padding: 0.6rem;
    }
    .ft-message {
        font-size: 0.85rem;
        padding: 0.5rem 0.8rem;
    }
    .ft-input-area {
        padding: 0.6rem;
        gap: 0.4rem;
    }
    #ft-input {
        font-size: 0.85rem;
        padding: 0.5rem 0.8rem;
    }
    .ft-send-btn {
        padding: 0.5rem 0.8rem;
        font-size: 0.8rem;
    }
    .freetalk-input-container {
        width: 95%;
        gap: 6px;
        padding: 6px 8px;
    }
    .freetalk-input {
        font-size: 0.85rem;
        padding: 8px 12px;
    }
    .freetalk-send-btn {
        padding: 8px 14px;
        font-size: 0.8rem;
    }
}

@media (max-height: 500px) and (orientation: landscape) {
    .ft-character {
        height: 50%;
        bottom: 45%;
    }
    .ft-chat-log {
        max-height: 30%;
        bottom: 60px;
        padding: 0.4rem 0.6rem;
        gap: 0.3rem;
    }
    .ft-message {
        font-size: 0.8rem;
        padding: 0.4rem 0.7rem;
        max-width: 70%;
    }
    .ft-input-area {
        padding: 0.4rem 0.6rem;
    }
    #ft-input {
        font-size: 0.82rem;
        padding: 0.4rem 0.8rem;
    }
    .ft-send-btn {
        padding: 0.4rem 0.8rem;
        font-size: 0.75rem;
    }
    .ft-turns {
        top: 0.4rem;
        font-size: 0.65rem;
    }
    .freetalk-input-container {
        padding: 4px 8px;
    }
    .freetalk-input {
        padding: 6px 10px;
        font-size: 0.8rem;
    }
    .freetalk-send-btn {
        padding: 6px 12px;
        font-size: 0.75rem;
    }
}
