/* ── 언어 바 (카드 내부 상단 우측) ── */
.lang-bar {
    display: flex;
    justify-content: flex-end;
    padding-bottom: 4px;
}

.lang-buttons {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}

.lang-btn {
    padding: 4px 10px;
    border-radius: var(--radius-pill);
    border: 1.5px solid var(--border);
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.76rem;
    font-weight: 600;
    transition: var(--transition);
    white-space: nowrap;
}

.lang-btn:hover {
    border-color: var(--kakao-dark);
    color: var(--kakao-dark);
}

.lang-btn.active {
    background: var(--kakao-dark);
    border-color: var(--kakao-dark);
    color: #FFFFFF;
}

/* ── Header ── */
.app-header {
    text-align: center;
    padding: 0 0 8px;
}

.app-title {
    font-family: 'Lobster', cursive;
    font-size: 2.6rem;
    font-weight: 400;
    font-style: normal;
    color: #4A90D9;
    letter-spacing: 1px;
    display: inline-block;
    position: relative;
}

.app-title::after {
    content: '';
    display: block;
    width: 100%;
    height: 6px;
    margin-top: 6px;
    background:
        linear-gradient(var(--kakao-dark), var(--kakao-dark)) top / 100% 2px,
        linear-gradient(var(--kakao-dark), var(--kakao-dark)) bottom / 100% 2px;
    background-repeat: no-repeat;
}

/* ── Main Card ── */
.main-card {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    padding: 22px 24px 26px;
    border: 1.5px solid var(--border);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* ── Style Section ── */
.style-section {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.instruction {
    font-size: 0.83rem;
    color: var(--text-secondary);
    font-weight: 500;
}

/* ── 카테고리 버튼 ── */
.category-group {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.cat-btn {
    padding: 7px 18px;
    border-radius: var(--radius-pill);
    border: 1.5px solid var(--border);
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.88rem;
    font-weight: 600;
    transition: var(--transition);
    white-space: nowrap;
}

.cat-btn:hover {
    border-color: var(--kakao-dark);
    color: var(--kakao-dark);
    background: #F7F7F7;
}

.cat-btn.active {
    background: var(--kakao-yellow);
    border-color: var(--kakao-yellow);
    color: var(--kakao-dark);
    box-shadow: 0 2px 8px rgba(254, 229, 0, 0.45);
}

.cat-btn-custom { border-style: dashed; }
.cat-btn-custom.active { border-style: solid; }

/* ── 사용자 정의 스타일 입력 ── */
.custom-style-wrapper {
    overflow: hidden;
    max-height: 0;
    opacity: 0;
    transition: max-height 0.28s ease, opacity 0.2s ease, margin-top 0.28s ease;
    margin-top: 0;
}

.custom-style-wrapper.open {
    max-height: 60px;
    opacity: 1;
    margin-top: 4px;
}

.custom-style-input {
    width: 100%;
    padding: 9px 14px;
    border: 1.5px solid var(--kakao-yellow);
    border-radius: var(--radius-sm);
    font-size: 0.83rem;
    color: var(--text-primary);
    background: var(--kakao-yellow-light);
    outline: none;
    transition: var(--transition);
}

.custom-style-input:focus {
    border-color: var(--kakao-dark);
    background: #FFFFFF;
    box-shadow: 0 0 0 3px rgba(254, 229, 0, 0.35);
}

/* ── Input Row ── */
.input-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    position: relative;
    z-index: 1;
}

.input-wrapper {
    flex: 1;
    position: relative;
    height: 46px;
}

/* 기본: 한 줄, 글자 있을 때 hover 시 위로 확장 */
.text-input {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 46px;
    padding: 12px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 0.93rem;
    color: var(--text-primary);
    background: #FAFAFA;
    resize: none;
    overflow: hidden;
    transition: height 0.25s ease, box-shadow 0.22s ease, border-color 0.18s ease;
    line-height: 1.5;
    z-index: 5;
}

/* 글자 있을 때 hover → 위로 확장 */
.input-wrapper.has-content:hover .text-input {
    height: 130px;
    overflow-y: auto;
    border-color: var(--kakao-dark);
    background: #FFFFFF;
    box-shadow: 0 -8px 20px rgba(0, 0, 0, 0.09);
    z-index: 20;
}

/* 포커스 시 항상 확장 */
.text-input:focus {
    height: 130px;
    overflow-y: auto;
    border-color: var(--kakao-dark);
    background: #FFFFFF;
    box-shadow: 0 -8px 20px rgba(0, 0, 0, 0.09);
    outline: none;
    z-index: 20;
}

.text-input::placeholder {
    color: #C0C4CC;
}

/* ── 버튼 ── */
.btn {
    height: 46px;
    padding: 0 20px;
    border-radius: var(--radius-md);
    border: none;
    font-size: 0.9rem;
    font-weight: 700;
    transition: var(--transition);
    white-space: nowrap;
    flex-shrink: 0;
    cursor: pointer;
}

.btn-primary {
    background: var(--kakao-yellow);
    color: var(--kakao-dark);
    box-shadow: 0 2px 10px rgba(254, 229, 0, 0.45);
}

.btn-primary:hover {
    background: var(--kakao-yellow-hover);
    box-shadow: 0 4px 16px rgba(254, 229, 0, 0.55);
    transform: translateY(-1px);
}

.btn-primary:active { transform: translateY(0); }

.btn-secondary {
    background: #F2F2F2;
    color: #555555;
    border: 1.5px solid var(--border);
}

.btn-secondary:hover { background: #E8E8E8; }

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: none !important;
}

/* ── 에러 ── */
.error-msg {
    background: var(--error-bg);
    color: var(--error);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    font-size: 0.86rem;
    text-align: center;
    border-left: 3px solid var(--error);
}

/* ── 채팅 영역 ── */
.chat-area {
    border: 1.5px solid var(--border);
    border-radius: var(--radius-md);
    height: 350px; /* JS로 동적 조절, 폴백값 */
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 18px;
    background: #FAFAFA;
    scroll-behavior: smooth;
}

/* ── 채팅 행 ── */
.chat-row {
    display: flex;
    gap: 12px;
    align-items: center;
    animation: fadeInUp 0.22s ease both;
}

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

/* ── 아바타 블록 ── */
.avatar-block {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
    width: 40px;
}

.avatar {
    border: 1.5px solid var(--kakao-dark);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.68rem;
    font-weight: 700;
    color: var(--kakao-dark);
    background: #FFFFFF;
}

.user-avatar {
    border-radius: var(--radius-pill);
    padding: 3px 7px;
    font-size: 0.68rem;
    border-color: #4A90D9;
    color: #4A90D9;
}

.ai-avatar {
    border-radius: 50%;
    width: 30px;
    height: 30px;
    font-style: italic;
}

.msg-time {
    font-size: 0.62rem;
    color: var(--text-secondary);
    text-align: center;
}

/* ── 말풍선 ── */
.msg-bubble {
    flex: 1;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-md);
    padding: 12px 14px;
    background: #FFFFFF;
    font-size: 0.84rem;
    line-height: 1.6;
    color: var(--text-primary);
    word-break: break-word;
    white-space: pre-wrap;
}

.user-bubble {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.user-bubble-text {
    line-height: 1.7;
    white-space: pre-wrap;
}

.ai-bubble {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* 사용자 스타일 태그 */
.user-label {
    display: inline-block;
    align-self: flex-start;
    font-size: 0.68rem;
    font-weight: 700;
    color: #555555;
    background: #F2F2F2;
    border: 1px solid #DDDDDD;
    border-radius: var(--radius-pill);
    padding: 2px 10px;
    letter-spacing: 0.2px;
}

/* AI 스타일 레이블 태그 */
.ai-label {
    display: inline-block;
    align-self: flex-start;
    font-size: 0.68rem;
    font-weight: 700;
    color: var(--kakao-dark);
    background: var(--kakao-yellow-light);
    border: 1px solid var(--kakao-yellow);
    border-radius: var(--radius-pill);
    padding: 2px 10px;
    letter-spacing: 0.2px;
}

.ai-bubble-text {
    line-height: 1.7;
    white-space: pre-wrap;
}

/* AI 답변의 [복사] 버튼 */
.bubble-copy-btn {
    align-self: flex-end;
    padding: 3px 14px;
    border-radius: var(--radius-pill);
    border: 1.5px solid var(--kakao-dark);
    background: transparent;
    color: var(--kakao-dark);
    font-size: 0.76rem;
    font-weight: 700;
    cursor: pointer;
    transition: var(--transition);
    font-family: inherit;
}

.bubble-copy-btn:hover {
    background: var(--kakao-dark);
    color: var(--kakao-yellow);
}

.bubble-copy-btn.copied {
    background: var(--success);
    border-color: var(--success);
    color: #FFFFFF;
}

/* ── 로딩 (타이핑 점) ── */
.typing-dots {
    display: flex;
    gap: 5px;
    align-items: center;
    padding: 6px 0;
}

.typing-dots span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--border);
    animation: dotBounce 1.2s infinite ease-in-out;
}

.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes dotBounce {
    0%, 60%, 100% { transform: translateY(0); background: var(--border); }
    30% { transform: translateY(-6px); background: var(--kakao-yellow); }
}

/* ── Toast ── */
.toast {
    position: fixed;
    top: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(-12px);
    background: #1A1A1A;
    color: #FFFFFF;
    padding: 12px 20px;
    border-radius: 14px;
    font-size: 0.88rem;
    font-weight: 500;
    display: flex;
    align-items: flex-start;
    gap: 8px;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.22);
    z-index: 9999;
    opacity: 0;
    transition: opacity 0.22s ease, transform 0.22s ease;
    white-space: normal;
    word-break: keep-all;
    max-width: calc(100vw - 48px);
    width: max-content;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.toast-icon {
    font-size: 1rem;
    flex-shrink: 0;
}

/* ── 광고 유닛 ── */
.ad-unit-wrap {
    max-width: 640px;
    margin: 12px auto 0;
    min-height: 60px;
}

/* ── Footer ── */
.app-footer {
    text-align: center;
    padding: 16px 0 0;
    color: #CCCCCC;
    font-size: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.footer-link {
    color: #AAAAAA;
    text-decoration: none;
    font-size: 0.73rem;
    transition: color 0.15s;
}

.footer-link:hover {
    color: var(--text-primary);
    text-decoration: underline;
}

/* ── Responsive ── */
@media (max-width: 520px) {
    body { padding: 12px 12px 36px; }

    .main-card {
        padding: 16px 14px 20px;
        border-radius: var(--radius-md);
        gap: 14px;
    }

    .app-title { font-size: 2.1rem; }

    .category-group { gap: 6px; }
    .cat-btn { padding: 6px 13px; font-size: 0.83rem; }

    /* 좁은 화면: 입력창 font-size 축소로 placeholder 개행 방지 */
    .text-input { font-size: 0.84rem; }

    .btn { padding: 0 14px; font-size: 0.85rem; }


    /* 토스트: 화면 폭에 맞게 */
    .toast { width: auto; max-width: calc(100vw - 32px); }
}

@media (max-width: 360px) {
    .app-title { font-size: 1.9rem; }
    .cat-btn { padding: 5px 10px; font-size: 0.78rem; }
    .lang-btn { padding: 3px 8px; font-size: 0.71rem; }
    .btn { padding: 0 10px; font-size: 0.8rem; }
    .text-input { font-size: 0.8rem; }
}
