/* 기본 스타일 초기화 및 폰트 설정 */
:root {
    --primary-color: #3B82F6;
    --background-color: #f3f4f6;
    --container-bg: #ffffff;
    --ai-message-bg: #f3f4f6;
    --user-message-bg: #3B82F6;
    --text-color: #1f2937;
    --header-bg: #ffffff;
    --border-color: #e5e7eb;
}

body {
    font-family: 'Noto Sans KR', sans-serif;
    background-color: var(--background-color);
    color: var(--text-color);
    overflow: hidden;
    position: fixed;
    width: 100%;
    height: 100%;
}

#app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh; /* 동적 뷰포트 높이 사용 */
    width: 100%;
    max-width: 100%;
    background-color: var(--container-bg);
    position: relative;
}

@media (min-width: 768px) {
    body {
        position: static;
        overflow: auto;
    }
    
    #app-container {
        max-width: 420px;
        height: 90vh;
        max-height: 800px;
        border-radius: 1.5rem;
        box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
        margin: auto;
    }
}

/* Header */
#chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.profile-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

#ai-profile-pic-container {
    position: relative;
    width: 48px;
    height: 48px;
    flex-shrink: 0;
}

#ai-profile-pic {
    width: 100%;
    height: 100%;
    border-radius: 9999px;
    object-fit: cover;
    opacity: 0;
    transition: opacity 0.4s ease-in-out;
    background-color: #e5e7eb;
}

#ai-profile-pic.loaded {
    opacity: 1;
}

.status-dot {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 12px;
    height: 12px;
    background-color: #22c55e;
    border-radius: 9999px;
    border: 2px solid white;
}

.name-status h1 {
    font-size: 1.125rem;
    font-weight: 600;
}

.name-status p {
    font-size: 0.875rem;
    color: #6b7280;
}

#guess-btn {
    padding: 0.5rem 1rem;
    border: none;
    background-color: var(--primary-color);
    color: white;
    border-radius: 9999px;
    cursor: pointer;
    font-weight: 500;
    font-size: 0.875rem;
    transition: background-color 0.2s;
}
#guess-btn:hover { background-color: #2563eb; }
#guess-btn:disabled { background-color: #9ca3af; cursor: not-allowed; }

/* Topic Banner */
#topic-banner {
    padding: 0.75rem 1.5rem;
    background-color: #eff6ff;
    color: #374151;
    font-size: 0.875rem;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}
#topic-banner strong { font-weight: 600; }

/* Chat Window */
#chat-window {
    flex: 1;
    min-height: 0; /* flexbox overflow fix */
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    padding: 1.5rem;
    background-color: #f9fafb;
}

#message-container {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.message-wrapper {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    max-width: 80%;
}

.message-wrapper.user {
    align-self: flex-end;
}
.message-wrapper.ai {
    align-self: flex-start;
}

/* [수정] 채팅창 내부 아바타 스타일을 제거합니다. */

.message-bubble {
    padding: 0.75rem 1rem;
    border-radius: 1.25rem;
    line-height: 1.6;
    word-wrap: break-word;
    font-size: 0.9375rem;
}

.message-bubble.ai {
    background-color: var(--ai-message-bg);
    color: var(--text-color);
    border-bottom-left-radius: 0.25rem;
}

.message-bubble.user {
    background-color: var(--user-message-bg);
    color: white;
    border-bottom-right-radius: 0.25rem;
}

/* Typing Indicator */
.typing-dots-container { display: flex; align-items: center; gap: 5px; }
.typing-dot {
    width: 8px; height: 8px; background-color: #9ca3af; border-radius: 50%;
    animation: typing-wave 1.3s infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing-wave { 0%, 60%, 100% { transform: translateY(0); } 30% { transform: translateY(-6px); } }

/* Message Animation */
@keyframes pop-in {
    0% { opacity: 0; transform: scale(0.9) translateY(10px); }
    100% { opacity: 1; transform: scale(1) translateY(0); }
}
.message-pop-in { animation: pop-in 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94) both; }


/* Input Form */
#form-container {
    padding: 1rem 1.5rem;
    padding-bottom: max(1rem, env(safe-area-inset-bottom)); /* iOS 노치 대응 */
    background-color: var(--header-bg);
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
}

#guess-form { display: flex; align-items: center; gap: 0.75rem; }

#user-input {
    flex-grow: 1; padding: 0.75rem 1.25rem; border: 1px solid transparent;
    background-color: #f3f4f6; border-radius: 9999px;
    font-size: 1rem; outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    -webkit-appearance: none; /* iOS 기본 스타일 제거 */
    appearance: none;
}
#user-input:focus { 
    border-color: var(--primary-color); 
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

#submit-btn {
    flex-shrink: 0; width: 48px; height: 48px; border: none;
    background-color: var(--primary-color); color: white;
    border-radius: 50%; cursor: pointer;
    display: flex; justify-content: center; align-items: center;
    transition: all 0.2s;
}
#submit-btn:hover { background-color: #2563eb; }
#submit-btn:disabled { background-color: #9ca3af; cursor: not-allowed; }
#submit-btn svg { transform: rotate(90deg); }

/* Modals */
.modal-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background-color: rgba(0, 0, 0, 0.5); display: flex;
    justify-content: center; align-items: center;
    z-index: 1000; opacity: 0; visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
}
.modal-overlay:not(.hidden) { opacity: 1; visibility: visible; }
.modal-content {
    background-color: white; padding: 2rem; border-radius: 1rem;
    width: 90%; max-width: 400px; text-align: center;
    transform: scale(0.95); transition: transform 0.3s;
    box-shadow: 0 10px 25px rgba(0,0,0,0.1);
}
.modal-overlay:not(.hidden) .modal-content { transform: scale(1); }
.modal-content h2 { margin-bottom: 0.5rem; font-size: 1.5rem; font-weight: 600; color: #1f2937; }
.modal-description { margin-bottom: 1.5rem; color: #4b5563; }
.modal-actions { display: flex; justify-content: center; gap: 0.75rem; margin-top: 1.5rem; }
.modal-actions button {
    padding: 0.75rem 1.5rem; border: none; border-radius: 9999px;
    font-size: 1rem; font-weight: 500; cursor: pointer;
    transition: background-color 0.2s;
}
#welcome-details {
    text-align: left; background-color: #f9fafb; padding: 1rem;
    border-radius: 0.75rem; margin-bottom: 1.5rem; border: 1px solid #e5e7eb;
}
#welcome-details p { margin-bottom: 0.5rem; color: #4b5563; }
#welcome-details p:last-child { margin-bottom: 0; }
#welcome-details strong { color: #1f2937; font-weight: 600; }
#welcome-start-btn { display: inline-flex; align-items: center; justify-content: center; }
#welcome-start-btn .spinner {
    border: 3px solid rgba(255, 255, 255, 0.3); border-radius: 50%;
    border-top-color: #fff; width: 1.25rem; height: 1.25rem;
    animation: spin 1s linear infinite; margin-right: 0.5rem;
}
#welcome-start-btn:not(:disabled) .spinner { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.mbti-selector { display: flex; justify-content: center; gap: 10px; margin-bottom: 2rem; }
.mbti-slot {
    width: 60px; height: 60px; border: 2px solid #e5e7eb;
    border-radius: 0.5rem; font-size: 2rem; font-weight: 700;
    cursor: pointer; background-color: #f9fafb; color: #374151;
    transition: all 0.2s;
}
.mbti-slot:hover { border-color: var(--primary-color); color: var(--primary-color); }
#modal-close-btn { background-color: #f3f4f6; color: #374151; }
#modal-close-btn:hover { background-color: #e5e7eb; }
#modal-submit-btn, #results-close-btn, #welcome-start-btn { background-color: var(--primary-color); color: white; }
#modal-submit-btn:hover, #results-close-btn:hover, #welcome-start-btn:hover { background-color: #2563eb; }
#result-details { margin-bottom: 2rem; display: flex; flex-direction: column; gap: 1rem; }
.result-bar-container {
    display: grid; grid-template-columns: 30px 1fr 30px;
    align-items: center; gap: 0.5rem; width: 100%;
}
.result-bar {
    height: 24px; background-color: #e5e7eb; border-radius: 12px;
    display: flex; overflow: hidden; font-size: 0.75rem;
    font-weight: 700; color: white;
}
.result-bar > div { display: flex; justify-content: center; align-items: center; }
.result-bar .left { background-color: #10b981; }
.result-bar .right { background-color: #f59e0b; }
.result-label { font-weight: 700; font-size: 1.2rem; color: #4b5563; }
.result-label.left { text-align: right; }
.result-label.right { text-align: left; }

