/* ============================================
   챗몽도사 - 메인 스타일시트
   CSS 변수, 레이아웃, 컴포넌트 스타일을 통합 관리합니다.
   ============================================ */

/* --- 디자인 토큰 (CSS 변수) --- */
:root {
    --primary-start: #667eea;
    --primary-end: #764ba2;
    --secondary-start: #f093fb;
    --secondary-end: #f5576c;
    --error-start: #e57373;
    --error-end: #d32f2f;
    --white: #ffffff;
    --bg-light: #f8f9ff;
    --text-dark: #333333;
    --shadow-soft: rgba(102, 126, 234, 0.3);
    --shadow-strong: rgba(102, 126, 234, 0.5);
    --radius-pill: 50px;
    --radius-lg: 25px;
    --radius-md: 20px;
    --transition: all 0.3s ease;
}

/* --- 기본 리셋 --- */
* { margin: 0; padding: 0; box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
    /* 한국어에 최적화된 Noto Sans KR 폰트 사용 */
    font-family: 'Noto Sans KR', 'Segoe UI', Tahoma, sans-serif;
    min-height: 100vh;
    background: linear-gradient(135deg, var(--primary-start) 0%, var(--primary-end) 100%);
    background-attachment: fixed;
}

/* ============================================
   레이아웃 - 페이지 래퍼
   ============================================ */
.page-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
    gap: 16px;
}

/* 메인 카드 컨테이너 */
.main-container {
    width: 100%;
    max-width: 500px;
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(15px);
    border-radius: var(--radius-lg);
    box-shadow: 0 25px 60px rgba(0, 0, 0, 0.18);
    overflow: hidden;
    transition: var(--transition);
}

/* ============================================
   인트로 화면
   ============================================ */
.intro-container {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 50px 30px;
    text-align: center;
    background: linear-gradient(135deg, var(--secondary-start) 0%, var(--secondary-end) 100%);
    color: var(--white);
    overflow: hidden;
}

/* 별 파티클 배경 */
.stars-bg {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

/* 반짝이는 별 개별 요소 (CSS 변수로 위치/크기/딜레이 제어) */
.star {
    position: absolute;
    left: var(--x);
    top: var(--y);
    width: calc(7px * var(--s));
    height: calc(7px * var(--s));
    background: rgba(255, 255, 255, 0.9);
    border-radius: 50%;
    animation: starTwinkle var(--d) ease-in-out infinite;
}

/* 인트로 내부 요소들은 별 배경 위에 표시 */
.intro-container > *:not(.stars-bg) { position: relative; z-index: 1; }

.intro-container h1 {
    font-size: 2.8rem;
    font-weight: 700;
    margin-bottom: 10px;
    text-shadow: 2px 2px 8px rgba(0, 0, 0, 0.3);
    animation: fadeInDown 0.9s ease;
}

.intro-subtitle {
    font-size: 1.1rem;
    opacity: 0.95;
    animation: fadeInUp 0.9s ease 0.2s both;
}

.mascot-emoji {
    font-size: 8rem;
    margin: 25px 0;
    display: block;
    filter: drop-shadow(0 15px 35px rgba(0, 0, 0, 0.3));
    animation: float 3s ease-in-out infinite;
}

.intro-quote {
    font-size: 1.2rem;
    margin-bottom: 35px;
    opacity: 0.9;
    font-style: italic;
    animation: fadeInUp 0.9s ease 0.4s both;
}

/* ============================================
   버튼 컴포넌트
   ============================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: none;
    cursor: pointer;
    font-family: inherit;
    font-weight: 600;
    transition: var(--transition);
}

/* 시작하기 버튼 */
.btn--primary {
    padding: 18px 45px;
    background: linear-gradient(45deg, var(--primary-start), var(--primary-end));
    color: var(--white);
    border-radius: var(--radius-pill);
    font-size: 1.2rem;
    box-shadow: 0 15px 35px var(--shadow-soft);
    animation: fadeInUp 0.9s ease 0.6s both;
}
.btn--primary:hover {
    transform: translateY(-3px);
    box-shadow: 0 20px 40px var(--shadow-strong);
    background: linear-gradient(45deg, var(--primary-end), var(--secondary-start));
}
.btn--primary:active { transform: translateY(-1px); }

/* 보내기 아이콘 버튼 */
.btn--send {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    background: linear-gradient(45deg, var(--primary-start), var(--primary-end));
    color: var(--white);
    font-size: 1rem;
    flex-shrink: 0;
    box-shadow: 0 5px 15px var(--shadow-soft);
}
.btn--send:hover:not(:disabled) {
    transform: scale(1.1);
    box-shadow: 0 8px 20px var(--shadow-strong);
}
.btn--send:disabled { background: #ccc; cursor: not-allowed; }

/* 헤더 다시하기 버튼 */
.btn--reset {
    padding: 7px 13px;
    background: rgba(255, 255, 255, 0.2);
    color: var(--white);
    border-radius: 20px;
    font-size: 0.82rem;
    border: 1px solid rgba(255, 255, 255, 0.35);
    backdrop-filter: blur(5px);
    position: relative;
    z-index: 1;
}
.btn--reset:hover {
    background: rgba(255, 255, 255, 0.35);
    transform: scale(1.05);
}

/* 결과 공유 버튼 (봇 버블 내부) */
.share-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    margin-top: 10px;
    padding: 5px 13px;
    background: rgba(255, 255, 255, 0.22);
    color: var(--white);
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: 20px;
    font-size: 0.78rem;
    font-family: inherit;
    cursor: pointer;
    transition: var(--transition);
}
.share-btn:hover {
    background: rgba(255, 255, 255, 0.4);
    transform: translateY(-1px);
}

/* ============================================
   채팅 화면
   ============================================ */
.chat-container {
    display: flex;
    flex-direction: column;
    height: 700px;
    background: var(--white);
}

/* 채팅 헤더 */
.chat-header {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: linear-gradient(135deg, var(--primary-start) 0%, var(--primary-end) 50%, var(--secondary-start) 100%);
    color: var(--white);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
    z-index: 10;
    overflow: hidden;
}

/* 헤더 별 배경 */
.chat-header .stars-bg { position: absolute; inset: 0; }

.chat-header__content {
    display: flex;
    align-items: center;
    gap: 10px;
    position: relative;
    z-index: 1;
}

.chat-header__icon {
    font-size: 1.8rem;
    filter: drop-shadow(0 2px 5px rgba(0,0,0,0.3));
}

.chat-header h2 {
    font-size: 1.35rem;
    font-weight: 700;
    text-shadow: 1px 1px 3px rgba(0,0,0,0.2);
}

.chat-header p {
    font-size: 0.8rem;
    opacity: 0.9;
}

/* 채팅 메시지 스크롤 영역 */
.chat-messages {
    flex: 1;
    padding: 20px 16px;
    overflow-y: auto;
    background: linear-gradient(to bottom, var(--bg-light) 0%, var(--white) 100%);
    scrollbar-width: thin;
    scrollbar-color: var(--primary-start) rgba(0, 0, 0, 0.08);
}
.chat-messages::-webkit-scrollbar { width: 5px; }
.chat-messages::-webkit-scrollbar-track { background: rgba(0,0,0,0.04); border-radius: 3px; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--primary-start); border-radius: 3px; }

/* 말풍선 공통 */
.chat-bubble {
    padding: 14px 18px;
    border-radius: var(--radius-md);
    margin-bottom: 14px;
    line-height: 1.7;
    font-size: 0.97rem;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.07);
    animation: messageSlideIn 0.4s ease;
    max-width: 88%;
    word-break: keep-all;
}

/* 봇 말풍선 */
.bot-bubble {
    background: linear-gradient(135deg, var(--primary-start) 0%, var(--primary-end) 100%);
    color: var(--white);
    margin-right: auto;
    border-bottom-left-radius: 6px;
}

/* 에러 말풍선 */
.bot-bubble.error {
    background: linear-gradient(135deg, var(--error-start) 0%, var(--error-end) 100%);
}

/* 사용자 말풍선 */
.user-bubble {
    background: linear-gradient(135deg, var(--secondary-start) 0%, var(--secondary-end) 100%);
    color: var(--white);
    margin-left: auto;
    border-bottom-right-radius: 6px;
}

/* ============================================
   로딩 인디케이터 (개선됨)
   ============================================ */
#loader {
    padding: 16px;
    display: flex;
    justify-content: center;
}

.loader-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    background: rgba(102, 126, 234, 0.07);
    padding: 20px 35px;
    border-radius: 20px;
    border: 1px solid rgba(102, 126, 234, 0.15);
}

/* 오브 이모지 (위아래 부유 애니메이션) */
.loader-orb {
    font-size: 2.5rem;
    animation: orbFloat 1.8s ease-in-out infinite;
}

#loader-text {
    color: var(--primary-start);
    font-size: 0.88rem;
    font-weight: 500;
    text-align: center;
}

/* 3개 점 바운스 애니메이션 */
.loader-dots {
    display: flex;
    gap: 6px;
}
.loader-dots span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--primary-start);
    animation: dotBounce 1.2s ease-in-out infinite;
}
.loader-dots span:nth-child(2) { animation-delay: 0.2s; }
.loader-dots span:nth-child(3) { animation-delay: 0.4s; }

/* ============================================
   입력 영역
   ============================================ */
.input-container {
    padding: 12px 14px;
    background: rgba(255, 255, 255, 0.97);
    backdrop-filter: blur(10px);
    border-top: 1px solid rgba(102, 126, 234, 0.12);
}

/* 입력창 + 버튼 묶음 */
.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    background: rgba(248, 249, 255, 0.9);
    border: 2px solid rgba(102, 126, 234, 0.2);
    border-radius: 25px;
    padding: 8px 8px 8px 16px;
    transition: var(--transition);
}
.input-wrapper:focus-within {
    border-color: var(--primary-start);
    box-shadow: 0 0 20px rgba(102, 126, 234, 0.15);
    background: white;
}

.chat-input {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    font-size: 1rem;
    font-family: inherit;
    resize: none;
    min-height: 24px;
    max-height: 120px;
    line-height: 1.5;
    color: var(--text-dark);
}
.chat-input::placeholder { color: #aaa; }

/* ============================================
   광고 배너 영역
   AdSense / Adfit 코드를 삽입할 컨테이너입니다.
   ============================================ */
.ad-banner {
    width: 100%;
    max-width: 500px;
    min-height: 60px;
    border-radius: 12px;
    overflow: hidden;
    /* 광고가 없을 때 빈 공간을 차지하지 않도록 빈 경우 숨김 처리는 JS에서 */
}
/* 광고 배너가 비어있으면 숨김 */
.ad-banner:empty { display: none; }

/* ============================================
   토스트 알림 (복사/공유 완료 피드백)
   ============================================ */
.toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: rgba(45, 45, 55, 0.93);
    color: white;
    padding: 12px 24px;
    border-radius: 30px;
    font-size: 0.9rem;
    font-weight: 500;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s ease;
    z-index: 9999;
    white-space: nowrap;
}
/* 토스트 표시 상태 */
.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ============================================
   키프레임 애니메이션
   ============================================ */
@keyframes fadeInDown {
    from { opacity: 0; transform: translateY(-30px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(30px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50%       { transform: translateY(-15px); }
}

@keyframes messageSlideIn {
    from { opacity: 0; transform: translateX(-15px); }
    to   { opacity: 1; transform: translateX(0); }
}

@keyframes starTwinkle {
    0%, 100% { opacity: 0; transform: scale(0.8); }
    50%       { opacity: 0.8; transform: scale(1.2); }
}

@keyframes orbFloat {
    0%, 100% { transform: translateY(0) rotate(-5deg); }
    50%       { transform: translateY(-8px) rotate(5deg); }
}

@keyframes dotBounce {
    0%, 80%, 100% { transform: translateY(0); opacity: 0.5; }
    40%            { transform: translateY(-8px); opacity: 1; }
}

/* ============================================
   반응형 디자인
   ============================================ */
@media (max-width: 768px) {
    body { padding: 0; }
    .page-wrapper { padding: 10px; }
    .main-container { max-width: 100%; border-radius: 20px; }
    .intro-container { padding: 40px 20px; }
    .intro-container h1 { font-size: 2.2rem; }
    .mascot-emoji { font-size: 6rem; }
    /* 모바일에서는 채팅창 높이를 뷰포트 기반으로 유동적으로 설정 */
    .chat-container { height: calc(100svh - 100px); max-height: 750px; }
}

@media (max-width: 480px) {
    .intro-container h1 { font-size: 1.9rem; }
    .btn--primary { padding: 15px 35px; font-size: 1.1rem; }
    .chat-header h2 { font-size: 1.2rem; }
    .chat-header p { font-size: 0.75rem; }
    .chat-messages { padding: 16px 12px; }
    .input-container { padding: 10px 12px; }
}
