/* ============================================================================
   FreeTalk - VN 스타일 1:1 대화 오버레이
   ============================================================================
   1:1 대화 시 메신저 대신 사용되는 VN 스타일 UI.
   캐릭터 아바타 + 대사창 + 입력창 + 대화내역 드로어.
   ============================================================================ */

/* ── 풀스크린 오버레이 ── */

.freetalk-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    height: 100dvh;
    height: var(--app-height, 100dvh);
    z-index: 200;
    overflow: hidden;
    background: linear-gradient(180deg, #080104 0%, #1a0810 40%, #0d0208 100%);
    flex-direction: column;
}

.freetalk-overlay.active {
    display: flex;
}

/* ── 상단 헤더 ── */

.ft-header {
    display: flex;
    align-items: center;
    padding: 14px 16px;
    z-index: 10;
    flex-shrink: 0;
    background: rgba(8, 1, 4, 0.85);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid rgba(214, 51, 92, 0.15);
    min-height: 52px;
}

.ft-back-btn {
    background: none;
    border: none;
    color: var(--text-main, #f0e6e9);
    font-size: 1.4rem;
    cursor: pointer;
    padding: 8px;
    margin-right: 4px;
    line-height: 1;
}

.ft-char-name {
    flex: 1;
    color: var(--text-main, #f0e6e9);
    font-size: 1.05rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ft-history-btn {
    background: rgba(214, 51, 92, 0.2);
    border: 1px solid rgba(214, 51, 92, 0.4);
    color: var(--text-main, #f0e6e9);
    font-size: 0.8rem;
    padding: 6px 14px;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
    white-space: nowrap;
}

.ft-history-btn:hover {
    background: rgba(214, 51, 92, 0.4);
}

/* ── 캐릭터 아바타 영역 ── */

.ft-avatar-area {
    flex-shrink: 0;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    z-index: 1;
    overflow: hidden;
    padding: 4px 24px 8px;
}

.ft-avatar-area img {
    width: 100%;
    height: 100%;
    max-width: 420px;
    max-height: 420px;
    object-fit: cover;
    border-radius: 16px;
    border: 2px solid rgba(214, 51, 92, 0.3);
    box-shadow:
        0 0 40px rgba(214, 51, 92, 0.15),
        0 0 80px rgba(0, 0, 0, 0.4);
    transition: opacity 0.3s;
}

.ft-avatar-area img.thinking {
    animation: ft-pulse 1.5s ease-in-out infinite;
}

@keyframes ft-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* ── 대사창 ── */

.ft-dialogue {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    padding: 0 16px 8px;
    z-index: 2;
    min-height: 0;
    overflow: hidden;
}

.ft-dialogue-box {
    background: rgba(15, 2, 8, 0.88);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(214, 51, 92, 0.25);
    border-radius: 16px;
    padding: 14px 18px;
    min-height: 76px;
    max-height: 40vh;
    overflow-y: auto;
    color: var(--text-main, #f0e6e9);
    font-size: 0.92rem;
    line-height: 1.7;
    cursor: pointer;
    position: relative;
}

.ft-name-tag {
    color: var(--primary, #d6335c);
    font-weight: 700;
    font-size: 0.82rem;
    margin-bottom: 4px;
}

.ft-message {
    min-height: 1.6em;
    word-break: break-word;
}

.ft-speaker {
    display: block;
    font-weight: 700;
    color: var(--primary, #d6335c);
    margin-top: 0.6em;
    margin-bottom: 0.2em;
    font-size: 0.95em;
}

.ft-speaker:first-child {
    margin-top: 0;
}

.ft-advance-indicator {
    display: inline-block;
    animation: ft-blink 1s ease-in-out infinite;
    color: var(--primary, #d6335c);
    font-size: 0.85em;
    margin-left: 4px;
}

@keyframes ft-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.2; }
}

.ft-dialogue-box.thinking-box::after {
    content: '';
    position: absolute;
    bottom: 10px;
    right: 14px;
    width: 22px;
    height: 22px;
    border: 3px solid rgba(214, 51, 92, 0.25);
    border-top-color: var(--primary, #d6335c);
    border-radius: 50%;
    animation: ft-spin 0.8s linear infinite;
}

@keyframes ft-spin {
    to { transform: rotate(360deg); }
}

/* ── 입력 영역 ── */

.ft-input-area {
    padding: 8px 16px 20px;
    padding-bottom: max(20px, calc(12px + env(safe-area-inset-bottom, 0px)));
    z-index: 2;
    flex-shrink: 0;
}

.ft-image-preview {
    display: none;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    padding: 0 4px;
}

.ft-image-preview img {
    max-height: 72px;
    border-radius: 8px;
    border: 1px solid rgba(214, 51, 92, 0.3);
}

.ft-remove-img {
    background: rgba(0, 0, 0, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #fff;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    cursor: pointer;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.ft-input-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.ft-upload-btn {
    background: none;
    border: none;
    color: var(--text-muted, #a38d97);
    font-size: 1.25rem;
    cursor: pointer;
    padding: 8px;
    flex-shrink: 0;
    transition: color 0.2s;
    line-height: 1;
}

.ft-upload-btn:hover {
    color: var(--text-main, #f0e6e9);
}

/* FreeTalk 타로 버튼 */
.ft-tarot-btn {
    background: none;
    border: none;
    font-size: 1.3rem;
    cursor: pointer;
    padding: 8px;
    flex-shrink: 0;
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.2s ease, filter 0.3s ease;
    opacity: 0.85;
    filter: drop-shadow(0 0 4px rgba(138, 43, 226, 0.4));
    animation: ft-tarot-glow 2.5s ease-in-out infinite;
    line-height: 1;
    display: none;
}

.ft-tarot-btn:hover {
    transform: scale(1.25);
    opacity: 1;
    filter: drop-shadow(0 0 10px rgba(138, 43, 226, 0.7)) drop-shadow(0 0 20px rgba(138, 43, 226, 0.3));
}

.ft-tarot-btn:active {
    transform: scale(0.95);
}

.ft-tarot-btn.is-disabled {
    opacity: 0.3;
    cursor: default;
    animation: none;
    filter: none;
}

@keyframes ft-tarot-glow {
    0%, 100% { filter: drop-shadow(0 0 4px rgba(138, 43, 226, 0.4)); }
    50% { filter: drop-shadow(0 0 8px rgba(138, 43, 226, 0.6)) drop-shadow(0 0 16px rgba(138, 43, 226, 0.2)); }
}

.ft-input {
    flex: 1;
    background: rgba(30, 10, 18, 0.75);
    border: 1px solid rgba(214, 51, 92, 0.25);
    border-radius: 24px;
    padding: 10px 16px;
    color: var(--text-main, #f0e6e9);
    font-size: 0.88rem;
    outline: none;
    transition: border-color 0.2s;
    min-width: 0;
    font-family: inherit;
}

.ft-input:focus {
    border-color: rgba(214, 51, 92, 0.55);
}

.ft-input::placeholder {
    color: #6b4f5c;
}

.ft-input:disabled {
    opacity: 0.5;
}

.ft-send-btn {
    background: var(--primary, #d6335c);
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.2s;
}

.ft-send-btn:hover {
    background: #e63d68;
    transform: scale(1.05);
}

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

.ft-send-btn svg {
    width: 18px;
    height: 18px;
    fill: #fff;
}

/* ── 지문 (액션) 스타일 ── */

.ft-action {
    display: block;
    background: rgba(214, 51, 92, 0.08);
    padding: 5px 10px;
    border-radius: 6px;
    margin: 4px 0;
    font-size: 0.9em;
    color: rgba(240, 230, 233, 0.75);
    line-height: 1.6;
    font-style: italic;
    border-left: 2px solid rgba(214, 51, 92, 0.35);
}

/* ── 대사창 내 이미지 ── */

.ft-chat-image {
    max-width: 120px;
    max-height: 120px;
    border-radius: 6px;
    margin-top: 8px;
    object-fit: contain;
}

/* ═══════════════════════════════════════════════════════════════════════════
   대화 내역 패널 (사이드 드로어)
   ═══════════════════════════════════════════════════════════════════════════ */

.ft-history-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 250;
}

.ft-history-backdrop.open {
    display: block;
}

.ft-history-panel {
    position: fixed;
    top: 0;
    right: -100%;
    width: 100%;
    max-width: 400px;
    height: 100%;
    background: rgba(8, 1, 4, 0.97);
    backdrop-filter: blur(20px);
    z-index: 300;
    transition: right 0.3s ease;
    display: flex;
    flex-direction: column;
    border-left: 1px solid rgba(214, 51, 92, 0.2);
}

.ft-history-panel.open {
    right: 0;
}

.ft-history-header {
    display: flex;
    align-items: center;
    padding: 16px;
    padding-top: max(16px, env(safe-area-inset-top, 16px));
    border-bottom: 1px solid rgba(214, 51, 92, 0.15);
    flex-shrink: 0;
}

.ft-history-title {
    flex: 1;
    color: var(--text-main, #f0e6e9);
    font-size: 1rem;
    font-weight: 600;
}

.ft-history-close {
    background: none;
    border: none;
    color: var(--text-muted, #a38d97);
    font-size: 1.3rem;
    cursor: pointer;
    padding: 8px;
    line-height: 1;
    transition: color 0.2s;
}

.ft-history-close:hover {
    color: var(--text-main, #f0e6e9);
}

.ft-history-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* 스크롤바 */
.ft-history-messages::-webkit-scrollbar {
    width: 4px;
}

.ft-history-messages::-webkit-scrollbar-track {
    background: transparent;
}

.ft-history-messages::-webkit-scrollbar-thumb {
    background: rgba(214, 51, 92, 0.3);
    border-radius: 4px;
}

.ft-history-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 0.82rem;
    line-height: 1.5;
    word-break: break-word;
}

.ft-history-img {
    max-width: 100%;
    max-height: 200px;
    border-radius: 8px;
    margin-top: 6px;
    object-fit: contain;
    display: block;
}

.ft-history-name {
    font-weight: 700;
    font-size: 0.75rem;
    margin-bottom: 4px;
    color: var(--primary, #d6335c);
}

.ft-history-msg.user .ft-history-name {
    text-align: right;
}

.ft-history-msg.user {
    align-self: flex-end;
    background: rgba(214, 51, 92, 0.25);
    color: var(--text-main, #f0e6e9);
    border-bottom-right-radius: 4px;
}

.ft-history-msg.assistant {
    align-self: flex-start;
    background: rgba(30, 10, 18, 0.8);
    color: var(--text-main, #f0e6e9);
    border-bottom-left-radius: 4px;
}

.ft-history-msg .ft-msg-time {
    font-size: 0.68rem;
    color: #6b4f5c;
    margin-top: 4px;
}

.ft-history-empty {
    text-align: center;
    color: #6b4f5c;
    padding: 40px 20px;
    font-size: 0.88rem;
}

/* ═══════════════════════════════════════════════════════════════════════════
   모바일 반응형
   ═══════════════════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
    .ft-avatar-area {
        padding: 10px 16px;
    }

    .ft-dialogue-box {
        padding: 12px 14px;
        min-height: 68px;
    }

    .ft-history-panel {
        max-width: 100%;
    }
}

@media (max-width: 480px) {
    .ft-avatar-area {
        padding: 8px 12px;
    }

    .ft-dialogue-box {
        padding: 10px 12px;
        min-height: 60px;
        font-size: 0.88rem;
    }

    .ft-input {
        font-size: 0.84rem;
        padding: 9px 14px;
    }

    .ft-header {
        padding: 10px 12px;
        min-height: 46px;
    }

    .ft-input-area {
        padding: 6px 12px 16px;
        padding-bottom: max(16px, calc(8px + env(safe-area-inset-bottom, 0px)));
    }

    .ft-dialogue {
        padding: 0 12px 6px;
    }
}

/* 세로 모드 높이 작을 때 (키보드 올라온 상태 등) */
@media (max-height: 500px) {
    .ft-avatar-area {
        padding: 4px 12px;
    }

    .ft-avatar-area img {
        max-height: 120px;
    }

    .ft-dialogue-box {
        min-height: 46px;
        padding: 8px 12px;
    }
}
