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

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

.freetalk-overlay {
    --ft-avatar-radius: 14px;
    --ft-panel-radius: 16px;
    --ft-dialogue-pad-x: 16px;
    --ft-dialogue-pad-y: 8px;
    --ft-side-width: clamp(420px, 38vw, 720px);
    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;
    gap: 10px;
    padding: 12px clamp(12px, 2vw, 18px);
    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;
    position: relative;
}

.ft-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    min-width: 0;
}

.ft-style-toggle {
    position: relative;
    display: inline-grid;
    grid-template-columns: 1fr 1fr;
    align-items: stretch;
    height: 30px;
    padding: 3px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.14);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
    cursor: pointer;
    font: inherit;
    overflow: hidden;
}

.ft-style-toggle__thumb {
    position: absolute;
    top: 3px;
    bottom: 3px;
    left: 3px;
    width: calc(50% - 3px);
    border-radius: 999px;
    background: rgba(214, 51, 92, 0.88);
    box-shadow: 0 4px 12px rgba(214, 51, 92, 0.28);
    transition: transform 0.22s ease;
    z-index: 0;
    pointer-events: none;
}

.ft-style-toggle[data-ft-current="chatbot"] .ft-style-toggle__thumb {
    transform: translateX(100%);
}

.ft-style-toggle__label {
    position: relative;
    z-index: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    padding: 0 12px;
    color: rgba(240, 230, 233, 0.7);
    font-size: 0.74rem;
    font-weight: 700;
    line-height: 1;
    white-space: nowrap;
    transition: color 0.2s ease;
    pointer-events: none;
}

.ft-style-toggle[data-ft-current="vn"] .ft-style-toggle__label[data-mode="vn"],
.ft-style-toggle[data-ft-current="chatbot"] .ft-style-toggle__label[data-mode="chatbot"] {
    color: #fff;
}

.ft-edit-user-btn {
    background: rgba(230, 190, 96, 0.12);
    border: 1px solid rgba(230, 190, 96, 0.32);
    color: var(--text-main, #fdfcff);
    font-family: inherit;
    font-size: 0.78rem;
    font-weight: 600;
    padding: 6px 12px;
    border-radius: 999px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    white-space: nowrap;
    transition: background 0.2s ease, border-color 0.2s ease;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
}
.ft-edit-user-btn:hover {
    background: rgba(230, 190, 96, 0.22);
    border-color: rgba(230, 190, 96, 0.5);
}
.ft-edit-user-btn:active {
    transform: translateY(1px);
}

.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;
    min-width: 0;
    color: var(--text-main, #f0e6e9);
    font-size: 1.05rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

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

.ft-avatar-area {
    flex-shrink: 0;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    z-index: 1;
    overflow: hidden;
    padding: 0;
    position: relative;
    box-sizing: border-box;
}

.freetalk-overlay.ft-mode-vn .ft-avatar-area::before {
    content: '';
    position: absolute;
    inset: -28px;
    background-image: var(--ft-avatar-bg);
    background-size: cover;
    background-position: center;
    filter: blur(28px) brightness(0.36) saturate(1.06);
    opacity: 0.62;
    transform: scale(1.03);
    z-index: 0;
}

/* 하단 그라데이션 페이드 — 이미지가 채팅 영역으로 자연스럽게 녹아듦 */
.ft-avatar-area::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 110px;
    pointer-events: none;
    background: linear-gradient(to bottom,
        transparent 0%,
        rgba(8, 1, 4, 0.35) 45%,
        rgba(13, 2, 8, 0.85) 80%,
        rgba(13, 2, 8, 1) 100%);
    z-index: 2;
}

.ft-avatar-area img {
    display: block;
    width: 100%;
    height: auto;
    max-width: none;
    max-height: none;
    border-radius: var(--ft-avatar-radius);
    border: none;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.55);
    transition: opacity 0.3s;
    cursor: pointer;
    position: relative;
    z-index: 1;
}

.ft-avatar-area img.thinking {
    opacity: 1;
    filter: saturate(1.04) drop-shadow(0 0 14px rgba(214, 51, 92, 0.22));
    animation: ft-avatar-wait 1.8s ease-in-out infinite;
}

@keyframes ft-avatar-wait {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.01); }
}

/* ── 대사창 ── */

.ft-dialogue {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    padding: 0 var(--ft-dialogue-pad-x) var(--ft-dialogue-pad-y);
    z-index: 2;
    min-height: 0;
    overflow: hidden;
}

.ft-dialogue-box {
    background:
        radial-gradient(circle at 18% 0%, rgba(230, 190, 96, 0.04), transparent 32%),
        linear-gradient(180deg, rgba(13, 2, 8, 0.76), rgba(7, 1, 5, 0.9));
    backdrop-filter: blur(12px);
    border: 1px solid rgba(214, 51, 92, 0.08);
    border-radius: var(--ft-panel-radius);
    padding: clamp(14px, 1.25vw, 22px) clamp(14px, 1.7vw, 30px);
    min-height: 0;
    height: 100%;
    max-height: none;
    overflow: hidden auto;
    color: var(--text-main, #f0e6e9);
    font-size: 0.92rem;
    line-height: 1.7;
    cursor: pointer;
    position: relative;
    display: flex;
    flex-direction: column;
    gap: clamp(0.72rem, 0.8vw, 0.95rem);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.035),
        0 14px 34px rgba(0, 0, 0, 0.18);
    scrollbar-width: thin;
    scrollbar-color: rgba(214, 51, 92, 0.35) transparent;
}

.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-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-action-btn {
    background: transparent;
    border: 1.5px solid rgba(255, 255, 255, 0.3);
    color: rgba(255, 255, 255, 0.6);
    font-size: 1rem;
    font-weight: 700;
    width: 34px;
    height: 34px;
    padding: 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.ft-action-btn:hover {
    border-color: rgba(255, 255, 255, 0.6);
    color: rgba(255, 255, 255, 0.9);
    transform: scale(1.05);
}

.ft-action-btn.active {
    background: rgba(168, 130, 255, 0.3);
    border-color: #a882ff;
    color: #a882ff;
    box-shadow: 0 0 8px rgba(168, 130, 255, 0.4);
}

.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.105);
    padding: 0.48rem 0.7rem;
    border-radius: 8px;
    margin: 0.45rem 0;
    font-size: 0.9em;
    color: rgba(239, 224, 230, 0.84);
    line-height: 1.62;
    font-style: italic;
    border-left: 2px solid rgba(214, 51, 92, 0.48);
    white-space: pre-line;
}

.ft-scene {
    display: block;
    background: rgba(230, 190, 96, 0.05);
    padding: 0.48rem 0.7rem;
    border-radius: 8px;
    margin: 0.45rem 0;
    font-size: 0.88em;
    color: rgba(222, 210, 194, 0.82);
    line-height: 1.6;
    border: 1px solid rgba(230, 190, 96, 0.15);
    white-space: pre-line;
}

.ft-thought {
    display: block;
    background: rgba(104, 88, 164, 0.115);
    padding: 0.48rem 0.7rem;
    border-radius: 8px;
    margin: 0.45rem 0;
    font-size: 0.88em;
    color: rgba(226, 220, 242, 0.84);
    line-height: 1.6;
    font-style: italic;
    border-left: 2px solid rgba(174, 142, 255, 0.34);
    white-space: pre-line;
}

.ft-text {
    display: block;
    margin: 0.45rem 0;
    line-height: 1.75;
    white-space: pre-line;
}

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

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

/* ═══════════════════════════════════════════════════════════════════════════
   단일 대화창 로그
   ═══════════════════════════════════════════════════════════════════════════ */

.ft-dialogue-box::-webkit-scrollbar {
    width: 4px;
}

.ft-dialogue-box::-webkit-scrollbar-track {
    background: transparent;
}

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

.ft-log-msg {
    max-width: min(74%, 680px);
    padding: 0.78rem 0.95rem;
    border-radius: 14px;
    font-size: 0.84rem;
    line-height: 1.58;
    word-break: normal;
    overflow-wrap: anywhere;
}

.ft-log-avatar {
    display: none;
}

.ft-log-content {
    display: contents;
}

.ft-log-name {
    font-weight: 700;
    font-size: 0.72rem;
    margin-bottom: 0.36rem;
    color: #ff477d;
}

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

.ft-log-msg.user {
    align-self: flex-end;
    max-width: min(52%, 420px);
    margin-right: clamp(0px, 0.8vw, 12px);
    background: linear-gradient(135deg, rgba(156, 38, 78, 0.72), rgba(92, 18, 45, 0.9));
    color: var(--text-main, #f0e6e9);
    border: 1px solid rgba(255, 126, 166, 0.26);
    border-bottom-right-radius: 4px;
    box-shadow: 0 10px 22px rgba(85, 10, 34, 0.24);
}

.ft-log-msg.assistant {
    align-self: flex-start;
    max-width: min(72%, 650px);
    margin-left: clamp(0px, 0.7vw, 10px);
    background: linear-gradient(180deg, rgba(32, 8, 18, 0.82), rgba(18, 4, 11, 0.94));
    color: var(--text-main, #f0e6e9);
    border: 1px solid rgba(230, 190, 96, 0.095);
    border-bottom-left-radius: 4px;
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.22);
}

.ft-log-msg.ft-scene-global {
    align-self: flex-start;
    display: block;
    width: auto;
    max-width: min(86%, 760px);
    padding: 0.1rem 0;
    margin: 0.15rem 0 0.4rem clamp(6px, 1.4vw, 22px);
    background: transparent;
    border: none;
    border-radius: 0;
    box-shadow: none;
    color: rgba(219, 207, 190, 0.72);
}

.ft-scene-global-marker {
    display: none;
}

.ft-scene-global-content {
    display: flex;
    flex-direction: column;
    gap: 0.18rem;
    min-width: 0;
    padding-left: 0;
    border-left: none;
    color: inherit;
}

.ft-scene-global-body {
    min-height: 0;
    font-style: italic;
    font-size: 0.84rem;
    line-height: 1.6;
    white-space: pre-line;
}

.ft-scene-global .ft-scene {
    margin: 0;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: 0;
    color: inherit;
    font-size: inherit;
    line-height: inherit;
}

.ft-log-msg.ft-scene-intro {
    max-width: min(92%, 820px);
    margin: 0.42rem 0 0.62rem clamp(6px, 1.4vw, 22px);
    padding: 0.1rem 0;
    border: none;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    color: #d98b2b;
}

.ft-log-msg.ft-scene-intro .ft-scene-global-body {
    font-size: 0.88rem;
    font-family: var(--font-serif);
    font-style: italic;
    font-weight: 800;
    line-height: 1.72;
}

.ft-thinking-message {
    min-width: 82px;
    background: rgba(30, 10, 18, 0.9);
    border: 1px solid rgba(214, 51, 92, 0.18);
    box-shadow: 0 0 18px rgba(214, 51, 92, 0.08);
}

.ft-thinking-body {
    min-height: 18px;
    display: flex;
    align-items: center;
}

.ft-thinking-dots {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 2px 0;
}

.ft-thinking-dots span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: rgba(214, 51, 92, 0.88);
    box-shadow: 0 0 10px rgba(214, 51, 92, 0.35);
    animation: ft-thinking-bounce 1.25s infinite ease-in-out both;
}

.ft-thinking-dots span:nth-child(1) { animation-delay: -0.24s; }
.ft-thinking-dots span:nth-child(2) { animation-delay: -0.12s; }
.ft-thinking-dots span:nth-child(3) { animation-delay: 0s; }

@keyframes ft-thinking-bounce {
    0%, 80%, 100% {
        transform: translateY(0) scale(0.72);
        opacity: 0.55;
    }
    40% {
        transform: translateY(-3px) scale(1);
        opacity: 1;
    }
}

.ft-log-body {
    min-height: 1.45em;
    line-height: 1.75;
    white-space: pre-line;
}

.ft-log-msg .ft-msg-time {
    font-size: 0.65rem;
    color: rgba(202, 159, 175, 0.52);
    margin-top: 4px;
}

.ft-empty-message {
    text-align: center;
    color: #6b4f5c;
    margin: auto;
    padding: 18px 10px;
    font-size: 0.86rem;
}

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

@media (max-width: 768px) {
    .ft-avatar-area {
        padding: 0;
        flex: 0 0 auto;
        min-height: 0;
        max-height: none;
    }

    .ft-avatar-area img {
        width: 100%;
        height: auto;
        max-height: none;
    }

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

}

@media (max-width: 480px) {
    .ft-avatar-area {
        padding: 0;
        flex: 0 0 auto;
        min-height: 0;
        max-height: none;
    }

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

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

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

    .ft-edit-user-btn {
        font-size: 0.72rem;
        padding: 5px 10px;
    }

    .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: 0;
    }

    .ft-avatar-area img {
        width: 100%;
        height: auto;
        max-height: none;
    }

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

/* ==========================================================================
   PC / 태블릿 — 좌우 분할 레이아웃 (min-width: 768px & landscape)
   아바타 좌측, 대사+입력 우측
   ========================================================================== */

/* ── ft-main / ft-right wrapper (모바일: 세로 스택, PC: 좌우 분할) ── */

.ft-main {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.ft-right {
    display: contents;
}

.freetalk-overlay.ft-mode-vn .ft-avatar-area {
    height: min(48svh, 100vw);
    min-height: 190px;
    max-height: min(520px, calc(var(--app-height, 100dvh) - 290px));
    padding: clamp(6px, 2vw, 12px);
    align-items: center;
    justify-content: center;
}

.freetalk-overlay.ft-mode-vn .ft-avatar-area img {
    width: auto;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

@media (max-width: 480px) {
    .freetalk-overlay {
        --ft-avatar-radius: 12px;
        --ft-panel-radius: 14px;
        --ft-dialogue-pad-x: 12px;
        --ft-dialogue-pad-y: 6px;
    }

    .freetalk-overlay.ft-mode-vn .ft-avatar-area {
        height: min(43svh, 100vw);
        min-height: 160px;
        max-height: min(430px, calc(var(--app-height, 100dvh) - 250px));
        padding: 8px;
    }
}

@media (max-width: 380px) {
    .freetalk-overlay.ft-mode-vn .ft-avatar-area {
        min-height: 145px;
        max-height: min(390px, calc(var(--app-height, 100dvh) - 235px));
    }
}

/* ==========================================================================
   PC / wide tablet — balanced image + chat split
   ========================================================================== */

@media (min-width: 1024px) and (min-height: 500px) {
    .freetalk-overlay {
        --ft-avatar-radius: 16px;
        --ft-panel-radius: 18px;
        --ft-dialogue-pad-x: clamp(14px, 1.15vw, 22px);
        --ft-dialogue-pad-y: clamp(8px, 1vw, 14px);
    }

    .ft-main {
        display: grid;
        grid-template-columns: minmax(0, min(52vw, calc(var(--app-height, 100dvh) - 66px))) minmax(0, 1fr);
        min-height: 0;
        height: 100%;
        overflow: hidden;
    }

    /* 좌측: 아바타 — 전체 높이, 잘리지 않게 최대한 꽉 차게 */
    .ft-avatar-area {
        display: flex;
        align-items: center;
        justify-content: center;
        padding: clamp(8px, 1vw, 16px);
        min-width: 0;
        min-height: 0;
        height: 100%;
        overflow: hidden;
        position: relative;
    }

    .freetalk-overlay.ft-mode-vn .ft-avatar-area {
        height: 100%;
        min-height: 0;
        max-height: none;
    }

    /* 블러 배경 — 좌우 빈 공간을 이미지의 블러 버전으로 채움 */
    .ft-avatar-area::before {
        inset: -44px;
        filter: blur(32px) brightness(0.34) saturate(1.06);
        opacity: 0.72;
    }

    /* 데스크톱에서는 하단 페이드 비활성화 (좌우 분할 레이아웃) */
    .ft-avatar-area::after {
        display: none;
    }

    .ft-avatar-area img {
        width: auto;
        height: 100%;
        max-width: none;
        max-height: none;
        object-fit: contain;
        object-position: right center;
        border-radius: var(--ft-avatar-radius);
        border: none;
        box-shadow: 0 18px 44px rgba(0, 0, 0, 0.46);
        position: relative;
        z-index: 1;
    }

    .freetalk-overlay.ft-mode-vn .ft-avatar-area img {
        width: auto;
        height: 100%;
        max-width: 100%;
        max-height: none;
        object-fit: contain;
        object-position: right center;
    }

    /* 우측: 대사 + 입력을 세로 스택 */
    .ft-right {
        display: flex;
        flex-direction: column;
        width: auto;
        min-width: 0;
        min-height: 0;
        height: 100%;
        overflow: hidden;
        border-left: 1px solid rgba(214, 51, 92, 0.12);
        background: rgba(8, 1, 4, 0.4);
    }

    .ft-dialogue {
        flex: 1;
        min-height: 0;
        overflow: hidden;
        padding: var(--ft-dialogue-pad-y) var(--ft-dialogue-pad-x) calc(var(--ft-dialogue-pad-y) * 0.65);
    }

    .ft-dialogue-box {
        max-height: 100%;
        height: 100%;
    }

    .ft-input-area {
        flex-shrink: 0;
    }

}

@media (min-width: 1024px) and (min-height: 500px) {
    .ft-right {
        width: auto;
    }

    .ft-dialogue-box {
        font-size: 0.95rem;
    }

    .freetalk-overlay.ft-mode-vn .ft-log-msg.assistant {
        margin-left: clamp(4px, 1.2vw, 22px);
    }

    .freetalk-overlay.ft-mode-vn .ft-log-msg.user {
        margin-right: clamp(18px, 2.2vw, 44px);
    }

    .freetalk-overlay.ft-mode-vn .ft-log-msg.ft-scene-global {
        margin-left: clamp(14px, 2.1vw, 42px);
    }
}

@media (min-width: 1440px) and (min-height: 500px) {
    .ft-right {
        width: auto;
    }

}

@media (min-width: 1920px) and (min-height: 500px) {
    .freetalk-overlay {
        --ft-avatar-radius: 18px;
        --ft-side-width: clamp(700px, 38vw, 860px);
    }

    .ft-right {
        width: auto;
    }
}

/* 가로 모드 (모바일 landscape) — 좌우 분할 컴팩트 */
@media (orientation: landscape) and (max-height: 500px) {
    .ft-main {
        flex-direction: row;
        flex: 1;
        min-height: 0;
    }

    .ft-avatar-area {
        flex: 1;
        padding: 8px clamp(8px, 2vw, 14px);
        align-items: center;
        justify-content: center;
    }

    .ft-avatar-area img {
        width: 100%;
        height: 100%;
        max-height: 100%;
        max-width: 100%;
        object-fit: contain;
        border-radius: 12px;
    }

    .freetalk-overlay.ft-mode-vn .ft-avatar-area {
        height: auto;
        min-height: 0;
        max-height: none;
    }

    .ft-right {
        display: flex;
        flex-direction: column;
        width: clamp(300px, 42vw, 380px);
        flex-shrink: 0;
        border-left: 1px solid rgba(214, 51, 92, 0.12);
    }

    .ft-dialogue {
        flex: 1;
        min-height: 0;
        padding: 8px 10px 4px;
    }

    .ft-dialogue-box {
        max-height: 100%;
        min-height: 40px;
        font-size: 0.84rem;
    }

    .ft-input-area {
        flex-shrink: 0;
        padding: 4px 10px 8px;
    }
}

/* ==========================================================================
   Chatbot 스타일 — 1:1 대화를 일반 채팅 앱처럼 표시
   ========================================================================== */

.freetalk-overlay.ft-mode-chatbot {
    background: linear-gradient(180deg, #080104 0%, #1a0810 40%, #0d0208 100%);
}

.freetalk-overlay.ft-mode-chatbot .ft-main {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    width: 100%;
}

.freetalk-overlay.ft-mode-chatbot .ft-avatar-area {
    display: none;
}

.freetalk-overlay.ft-mode-chatbot .ft-right {
    display: flex;
    flex-direction: column;
    flex: 1;
    width: 100%;
    max-width: 960px;
    min-height: 0;
    margin: 0 auto;
    border-left: none;
    background: transparent;
}

.freetalk-overlay.ft-mode-chatbot .ft-dialogue {
    flex: 1;
    min-height: 0;
    justify-content: stretch;
    padding: 18px clamp(14px, 2.5vw, 26px) 8px;
}

.freetalk-overlay.ft-mode-chatbot .ft-dialogue-box {
    height: 100%;
    max-height: none;
    min-height: 0;
    padding: 4px 2px 16px;
    gap: 0.85rem;
    background: transparent;
    border: none;
    border-radius: 0;
    box-shadow: none;
    color: var(--text-main, #f0e6e9);
    font-size: 1rem;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    cursor: default;
    overflow: hidden auto;
}

.freetalk-overlay.ft-mode-chatbot .ft-dialogue-box::-webkit-scrollbar {
    width: 4px;
}

.freetalk-overlay.ft-mode-chatbot .ft-dialogue-box::-webkit-scrollbar-thumb {
    background: rgba(214, 51, 92, 0.35);
}

.freetalk-overlay.ft-mode-chatbot .ft-log-msg {
    display: flex;
    align-items: flex-end;
    gap: 0.58rem;
    width: auto;
    max-width: 100%;
    min-width: 0;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: 0;
    box-shadow: none;
    color: var(--text-main, #f0e6e9);
    line-height: 1.55;
    word-break: normal;
    overflow-wrap: anywhere;
}

.freetalk-overlay.ft-mode-chatbot .ft-log-msg.assistant {
    align-self: stretch;
    justify-content: flex-start;
}

.freetalk-overlay.ft-mode-chatbot .ft-log-msg.user {
    align-self: stretch;
    justify-content: flex-end;
}

.freetalk-overlay.ft-mode-chatbot .ft-log-msg.ft-scene-global {
    align-items: flex-start;
    justify-content: flex-start;
    width: auto;
    max-width: min(86%, 760px);
    padding: 0.18rem 0;
    margin-left: clamp(4px, 1.2vw, 18px);
    display: block;
    color: rgba(219, 207, 190, 0.7);
}

.freetalk-overlay.ft-mode-chatbot .ft-log-avatar {
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    flex: 0 0 42px;
    border-radius: 50%;
    object-fit: cover;
    background: rgba(214, 51, 92, 0.18);
    color: var(--text-main, #f0e6e9);
    font-size: 1.28rem;
    box-shadow: 0 8px 18px rgba(0, 0, 0, 0.45);
    cursor: pointer;
}

.freetalk-overlay.ft-mode-chatbot .ft-log-msg.user .ft-log-avatar {
    display: none;
}

.freetalk-overlay.ft-mode-chatbot .ft-log-content {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    max-width: min(76%, 660px);
    min-width: 0;
    padding: 0.88rem 1.05rem;
    border-radius: 18px;
    background: linear-gradient(180deg, rgba(31, 8, 17, 0.82), rgba(17, 4, 10, 0.94));
    border: 1px solid rgba(230, 190, 96, 0.09);
    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.28);
}

.freetalk-overlay.ft-mode-chatbot .ft-scene-global-marker {
    display: none;
}

.freetalk-overlay.ft-mode-chatbot .ft-scene-global-content {
    max-width: min(100%, 720px);
    padding: 0.05rem 0;
    background: transparent;
    border: none;
    border-radius: 0;
    box-shadow: none;
    color: inherit;
}

.freetalk-overlay.ft-mode-chatbot .ft-scene-global-body {
    min-height: 0;
    font-style: italic;
    font-size: 0.86rem;
    line-height: 1.6;
    white-space: pre-line;
}

.freetalk-overlay.ft-mode-chatbot .ft-scene-global .ft-scene {
    margin: 0;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: 0;
    color: inherit;
    font-size: inherit;
    line-height: inherit;
}

.freetalk-overlay.ft-mode-chatbot .ft-log-msg.ft-scene-intro {
    max-width: min(92%, 820px);
    margin: 0.42rem 0 0.62rem clamp(4px, 1.2vw, 18px);
    padding: 0.18rem 0;
    border: none;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    color: #d98b2b;
}

.freetalk-overlay.ft-mode-chatbot .ft-log-msg.ft-scene-intro .ft-scene-global-body {
    font-size: 0.88rem;
    font-family: var(--font-serif);
    font-style: italic;
    font-weight: 800;
    line-height: 1.72;
}

.freetalk-overlay.ft-mode-chatbot .ft-log-msg.assistant .ft-log-content {
    border-bottom-left-radius: 4px;
}

.freetalk-overlay.ft-mode-chatbot .ft-log-msg.user .ft-log-content {
    align-items: flex-end;
    text-align: right;
    max-width: min(54%, 430px);
    border-bottom-right-radius: 4px;
    background: linear-gradient(135deg, rgba(156, 38, 78, 0.72), rgba(92, 18, 45, 0.9));
    border-color: rgba(255, 126, 166, 0.25);
    color: var(--text-main, #f0e6e9);
    box-shadow: 0 8px 20px rgba(85, 10, 34, 0.22);
}

.freetalk-overlay.ft-mode-chatbot .ft-log-name {
    color: var(--primary, #d6335c);
    font-size: 0.78rem;
    margin-bottom: 0;
}

.freetalk-overlay.ft-mode-chatbot .ft-log-msg.user .ft-log-name {
    display: none;
}

.freetalk-overlay.ft-mode-chatbot .ft-log-msg.user .ft-msg-time {
    color: rgba(240, 230, 233, 0.55);
}

.freetalk-overlay.ft-mode-chatbot .ft-log-body {
    min-height: 1.45em;
    min-width: 0;
    max-width: 100%;
    overflow-wrap: anywhere;
}

.freetalk-overlay.ft-mode-chatbot .ft-msg-time {
    color: rgba(240, 230, 233, 0.42);
    font-size: 0.68rem;
    margin-top: 0.1rem;
}

.freetalk-overlay.ft-mode-chatbot .ft-action {
    background: rgba(214, 51, 92, 0.08);
    border-left-color: rgba(214, 51, 92, 0.35);
    color: rgba(240, 230, 233, 0.75);
}

.freetalk-overlay.ft-mode-chatbot .ft-scene {
    background: rgba(255, 255, 255, 0.04);
    border-color: rgba(230, 190, 96, 0.14);
    color: rgba(214, 207, 224, 0.72);
}

.freetalk-overlay.ft-mode-chatbot .ft-thought {
    background: rgba(140, 96, 230, 0.08);
    border-left-color: rgba(174, 142, 255, 0.34);
    color: rgba(222, 216, 240, 0.74);
}

.freetalk-overlay.ft-mode-chatbot .ft-log-msg.user .ft-action {
    background: rgba(255, 255, 255, 0.08);
    border-left-color: rgba(255, 255, 255, 0.3);
    color: rgba(255, 255, 255, 0.82);
}

.freetalk-overlay.ft-mode-chatbot .ft-speaker {
    color: var(--primary, #d6335c);
}

.freetalk-overlay.ft-mode-chatbot .ft-empty-message {
    color: #6b4f5c;
}

.freetalk-overlay.ft-mode-chatbot .ft-thinking-message {
    min-width: 0;
    border: none;
    box-shadow: none;
}

.freetalk-overlay.ft-mode-chatbot .ft-thinking-body {
    min-width: 44px;
}

.freetalk-overlay.ft-mode-chatbot .ft-input-area {
    width: 100%;
    max-width: 920px;
    margin: 0 auto;
    padding: 8px 18px 18px;
    padding-bottom: max(18px, calc(10px + env(safe-area-inset-bottom, 0px)));
}

.freetalk-overlay.ft-mode-chatbot .ft-input-row {
    gap: 6px;
    padding: 6px;
    border-radius: 28px;
    background: rgba(30, 10, 18, 0.75);
    border: 1px solid rgba(214, 51, 92, 0.25);
    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.35);
}

.freetalk-overlay.ft-mode-chatbot .ft-input {
    min-height: 36px;
    padding: 8px 10px;
    border: none;
    border-radius: 20px;
    background: transparent;
    color: var(--text-main, #f0e6e9);
}

.freetalk-overlay.ft-mode-chatbot .ft-input::placeholder {
    color: #6b4f5c;
}

.freetalk-overlay.ft-mode-chatbot .ft-input:focus {
    border-color: transparent;
}

@media (max-width: 768px) {
    .freetalk-overlay.ft-mode-chatbot .ft-dialogue {
        padding: 14px 12px 6px;
    }

    .freetalk-overlay.ft-mode-chatbot .ft-dialogue-box {
        padding-bottom: 10px;
        font-size: 0.94rem;
    }

    .freetalk-overlay.ft-mode-chatbot .ft-log-avatar {
        width: 36px;
        height: 36px;
        flex-basis: 36px;
        font-size: 1.1rem;
    }

    .freetalk-overlay.ft-mode-chatbot .ft-log-content {
        max-width: 82%;
        padding: 0.78rem 0.92rem;
    }

    .freetalk-overlay.ft-mode-chatbot .ft-log-msg.ft-scene-global {
        max-width: none;
        margin-left: 0;
        margin-right: 0;
        padding-right: 0;
    }

    .freetalk-overlay.ft-mode-chatbot .ft-scene-global-content,
    .freetalk-overlay.ft-mode-chatbot .ft-scene-global-body {
        max-width: 100%;
    }

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

@media (max-width: 560px) {
    .ft-header {
        gap: 6px;
    }

    .ft-header-actions {
        gap: 6px;
    }

    .ft-style-toggle {
        height: 28px;
    }

    .ft-style-toggle__label {
        min-width: 38px;
        padding: 0 8px;
        font-size: 0.7rem;
    }

    .ft-edit-user-btn span:last-child {
        display: none;
    }

    .ft-edit-user-btn {
        width: 32px;
        height: 32px;
        justify-content: center;
        padding: 0;
        border-radius: 50%;
    }
}

@media (max-width: 380px) {
    .ft-char-name {
        font-size: 0.92rem;
    }

    .ft-style-toggle__label {
        min-width: 32px;
        padding: 0 6px;
        font-size: 0.66rem;
    }

    .ft-back-btn {
        padding: 6px;
        margin-right: 0;
    }
}

@media (orientation: landscape) and (max-height: 500px) {
    .freetalk-overlay.ft-mode-chatbot .ft-main {
        flex-direction: column;
    }

    .freetalk-overlay.ft-mode-chatbot .ft-avatar-area {
        display: none;
    }

    .freetalk-overlay.ft-mode-chatbot .ft-right {
        width: 100%;
        max-width: 920px;
    }

    .freetalk-overlay.ft-mode-chatbot .ft-dialogue {
        padding: 8px 12px 4px;
    }

    .freetalk-overlay.ft-mode-chatbot .ft-dialogue-box {
        min-height: 0;
        font-size: 0.86rem;
    }

    .freetalk-overlay.ft-mode-chatbot .ft-input-area {
        padding: 4px 12px 8px;
    }
}
