/* ═══════════════════════════════════════
   사주팔자 앱 - 전체 스타일시트
   ═══════════════════════════════════════ */

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans KR', sans-serif;
    background: #f5f5f5;
    color: #1a1a1a;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

.container {
    max-width: 480px;
    margin: 0 auto;
    background: #f5f5f5;
    min-height: 100vh;
}

/* ─── 헤더 ─── */
.result-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: #fff;
    border-bottom: 1px solid #eee;
    position: sticky;
    top: 0;
    z-index: 100;
}
.result-header h1 { font-size: 17px; font-weight: 600; }
.back-btn { text-decoration: none; color: #333; font-size: 22px; }
.header-right { width: 24px; }

/* ─── 프로필 카드 ─── */
.profile-card {
    background: #fff;
    text-align: center;
    padding: 30px 20px 24px;
    margin-bottom: 8px;
}
.profile-icon {
    width: 56px; height: 56px; border-radius: 50%;
    background: #f3f4f6; margin: 0 auto 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 24px;
}
.profile-name { font-size: 22px; font-weight: 700; margin-bottom: 4px; }
.profile-sub { font-size: 14px; color: #666; margin-bottom: 16px; }
.profile-dates {
    background: #f9fafb; border-radius: 12px; padding: 14px 20px;
    text-align: left; display: inline-block;
}
.profile-dates p { font-size: 14px; color: #444; line-height: 1.8; }

/* ─── 도움말 버튼 ─── */
.help-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 20px; height: 20px; border-radius: 50%;
    border: 1.5px solid #ccc; background: #fff;
    font-size: 12px; color: #999; cursor: pointer;
    vertical-align: middle; margin-left: 4px;
    transition: all 0.2s;
}
.help-btn:hover { border-color: #6366f1; color: #6366f1; }

/* ─── 카드 공통 ─── */
.saju-card {
    background: #fff;
    border-radius: 16px;
    padding: 24px 20px;
    margin: 8px 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.section-title {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 18px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.sub-section-title {
    font-size: 15px;
    font-weight: 600;
    color: #555;
    margin-bottom: 12px;
}

/* ─── 사주원국 ─── */
.wonkuk-header {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    text-align: center;
    margin-bottom: 12px;
}
.wonkuk-col { text-align: center; }
.wonkuk-pillar-name { font-size: 15px; font-weight: 600; }
.wonkuk-pillar-sub { font-size: 11px; color: #999; }

.wonkuk-row {
    display: grid;
    grid-template-columns: 52px repeat(4, 1fr);
    gap: 6px;
    align-items: center;
    margin-bottom: 6px;
}
.wonkuk-label {
    font-size: 12px;
    color: #888;
    text-align: right;
    padding-right: 6px;
}
.wonkuk-cell {
    border-radius: 10px;
    padding: 10px 4px;
    text-align: center;
    min-height: 56px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}
.wonkuk-char { font-size: 22px; font-weight: 700; }
.wonkuk-detail { font-size: 9px; opacity: 0.85; margin-top: 2px; }

.label-row .wonkuk-col {
    font-size: 13px;
    color: #555;
    padding: 4px 0;
}

/* ─── 사주관계 탭 ─── */
.tab-bar {
    display: flex;
    gap: 0;
    margin-bottom: 20px;
    border-bottom: 2px solid #eee;
}
.tab-btn {
    flex: 1;
    padding: 10px;
    text-align: center;
    font-size: 14px;
    font-weight: 500;
    background: none;
    border: none;
    cursor: pointer;
    color: #999;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all 0.2s;
}
.tab-btn.active { color: #333; border-bottom-color: #333; font-weight: 700; }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* 관계 다이어그램 */
.relation-diagram { margin-bottom: 16px; }
.relation-lines { display: flex; flex-direction: column; gap: 6px; }
.relation-line-item {
    display: flex;
    justify-content: space-between;
    padding: 6px 12px;
    background: #f9fafb;
    border-radius: 8px;
    font-size: 13px;
}
.rel-label { font-weight: 600; }
.rel-pos { color: #888; }

.relation-grid { margin-bottom: 16px; }
.rel-row-label {
    display: grid;
    grid-template-columns: 40px repeat(4, 1fr);
    gap: 6px;
    text-align: center;
    font-size: 12px;
    color: #999;
    padding: 4px 0;
}
.rel-row {
    display: grid;
    grid-template-columns: 40px repeat(4, 1fr);
    gap: 6px;
    align-items: center;
    margin-bottom: 6px;
}
.rel-side-label { font-size: 12px; color: #888; text-align: right; }
.rel-cell {
    border-radius: 8px;
    padding: 10px 4px;
    text-align: center;
    font-size: 22px;
    font-weight: 700;
    min-height: 48px;
}

.branch-relations-list { margin-top: 12px; }
.branch-rel-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: #f9fafb;
    border-radius: 8px;
    margin-bottom: 6px;
    font-size: 14px;
}
.rel-type-badge {
    padding: 2px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    color: #fff;
}
.branch-rel-item.충 .rel-type-badge { background: #ef4444; }
.branch-rel-item.합 .rel-type-badge,
.branch-rel-item.육합 .rel-type-badge { background: #3b82f6; }
.branch-rel-item.삼합 .rel-type-badge { background: #8b5cf6; }
.branch-rel-item.반합 .rel-type-badge { background: #10b981; }

/* 신살과 길성 */
.shinsal-section { overflow-x: auto; }
.shinsal-label { font-size: 13px; color: #888; margin: 8px 0 6px; }
.shinsal-row-header {
    display: grid;
    grid-template-columns: 70px repeat(4, 1fr);
    gap: 6px;
    text-align: center;
}
.shinsal-cell-header {
    border-radius: 8px;
    padding: 10px 4px;
    font-size: 22px;
    font-weight: 700;
}
.shinsal-row {
    display: grid;
    grid-template-columns: 70px repeat(4, 1fr);
    gap: 6px;
    margin-bottom: 8px;
}
.shinsal-side { font-size: 11px; color: #888; text-align: right; padding-top: 4px; }
.shinsal-cell-list { text-align: center; }
.star-tag {
    display: inline-block;
    padding: 2px 6px;
    margin: 2px;
    font-size: 11px;
    background: #f3f4f6;
    border-radius: 4px;
    color: #555;
}
.star-none { color: #ccc; font-size: 13px; }

/* ─── 대운/세운/월운 ─── */
.daewoon-scroll {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 8px;
    -webkit-overflow-scrolling: touch;
}
.daewoon-scroll::-webkit-scrollbar { height: 4px; }
.daewoon-scroll::-webkit-scrollbar-thumb { background: #ddd; border-radius: 2px; }

.daewoon-item {
    flex: 0 0 auto;
    text-align: center;
    min-width: 64px;
    padding: 8px 4px;
    border-radius: 10px;
    background: #f9fafb;
}
.daewoon-item.current-year {
    background: #f0f0ff;
    border: 2px solid #6366f1;
}
.dw-age { font-size: 13px; font-weight: 600; margin-bottom: 4px; }
.dw-god { font-size: 11px; color: #888; margin: 2px 0; }
.dw-cell {
    border-radius: 8px;
    padding: 8px 4px;
    font-size: 18px;
    font-weight: 700;
    margin: 3px auto;
    width: 48px;
}
.dw-stage { font-size: 11px; color: #888; margin-top: 2px; }

/* ─── 신강신약 게이지 ─── */
.singang-gauge { text-align: center; padding: 20px 0; }
.gauge-wrapper { position: relative; max-width: 240px; margin: 0 auto; }
.gauge-svg { width: 100%; }
.gauge-number {
    position: absolute;
    top: 55%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 48px;
    font-weight: 800;
}
.gauge-label {
    font-size: 14px;
    color: #888;
    margin-top: -10px;
}
.gauge-legend {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-top: 20px;
}
.legend-item { font-size: 13px; color: #666; display: flex; align-items: center; gap: 6px; }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }

/* ─── 오행과 십성 ─── */
.oheng-diagram { margin-bottom: 24px; }
.oheng-legend {
    display: flex;
    gap: 20px;
    margin-bottom: 16px;
    font-size: 13px;
    color: #888;
}
.arrow-solid { font-weight: bold; }
.arrow-dashed { letter-spacing: -2px; }

.oheng-circle-container {
    position: relative;
    width: 280px;
    height: 280px;
    margin: 0 auto;
}
.oheng-item {
    position: absolute;
    text-align: center;
}
.oheng-item.top { top: 0; left: 50%; transform: translateX(-50%); }
.oheng-item.right { top: 35%; right: 0; }
.oheng-item.bottom-right { bottom: 5%; right: 10%; }
.oheng-item.bottom-left { bottom: 5%; left: 10%; }
.oheng-item.left { top: 35%; left: 0; }

.oheng-percent { font-size: 20px; font-weight: 700; margin-bottom: 4px; }
.oheng-badge {
    display: inline-block;
    width: 32px; height: 32px;
    border-radius: 6px;
    font-size: 16px; font-weight: 700;
    line-height: 32px;
    text-align: center;
}
.oheng-note { font-size: 11px; color: #999; margin-top: 2px; }

.oheng-detail-table { margin-top: 16px; }
.oheng-detail-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 0;
    border-bottom: 1px solid #f3f4f6;
}
.oheng-detail-badge {
    width: 36px; height: 36px;
    border-radius: 8px;
    font-size: 16px; font-weight: 700;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.oheng-detail-name { font-size: 14px; font-weight: 600; min-width: 90px; }
.oheng-detail-status { min-width: 48px; }
.status-badge {
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
}
.status-lack { background: #fef3c7; color: #92400e; }
.status-ok { background: #dbeafe; color: #1e40af; }
.status-dev { background: #fef9c3; color: #854d0e; }
.status-over { background: #fee2e2; color: #991b1b; }
.oheng-detail-gods { flex: 1; }
.god-line {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    color: #666;
    padding: 1px 0;
}

/* ─── 3카드 ─── */
.three-cards {
    display: flex;
    gap: 8px;
    padding: 8px 12px;
}
.info-card {
    flex: 1;
    background: #fff;
    border-radius: 14px;
    padding: 18px 8px;
    text-align: center;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.info-icon-circle {
    width: 48px; height: 48px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    margin: 0 auto 8px;
    font-size: 18px; font-weight: 700;
}
.info-icon-circle.animal { background: #fef3c7; font-size: 26px; }
.info-icon-circle.god { background: #e0e7ff; color: #4338ca; font-size: 13px; font-weight: 600; }
.info-label { font-size: 15px; font-weight: 600; }
.info-sub { font-size: 12px; color: #999; }

/* ─── 오행 분포 바 ─── */
.element-bars { padding: 4px 0; }
.ebar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.ebar-label { width: 24px; font-size: 15px; font-weight: 700; text-align: center; }
.ebar-track { flex: 1; height: 8px; background: #f3f4f6; border-radius: 4px; overflow: hidden; }
.ebar-fill { height: 100%; border-radius: 4px; transition: width 0.5s ease; }
.ebar-num { width: 20px; font-size: 14px; font-weight: 600; text-align: right; }

/* ─── 운세 본문 ─── */
.fortune-body { line-height: 1.8; }
.fortune-body p { margin-bottom: 14px; font-size: 15px; color: #333; }
.fortune-sub-title {
    font-size: 15px;
    font-weight: 700;
    color: #4338ca;
    margin: 20px 0 10px;
    padding-left: 10px;
    border-left: 3px solid #6366f1;
}
.fortune-meta-box {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 16px;
}
.meta-item {
    padding: 6px 12px;
    background: #f3f4f6;
    border-radius: 8px;
    font-size: 13px;
    color: #555;
}

.tip-box {
    padding: 12px 16px;
    background: #f0fdf4;
    border-radius: 10px;
    font-size: 14px;
    color: #166534;
    margin-bottom: 12px;
    border-left: 3px solid #22c55e;
}
.keyword-item {
    font-size: 14px;
    line-height: 1.8;
    color: #444;
    padding: 6px 14px;
    border-left: 3px solid #6366f1;
    margin-bottom: 10px;
    background: #fafafe;
    border-radius: 0 6px 6px 0;
}

/* ─── 신년운세 배너 ─── */
.new-year-banner {
    text-align: center;
    padding: 28px 20px;
    margin: 8px 12px;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    border-radius: 16px;
    color: #fff;
}
.banner-sub { font-size: 14px; opacity: 0.85; margin-bottom: 6px; }
.banner-title { font-size: 22px; font-weight: 800; }

/* ─── 메뉴 그리드 ─── */
.menu-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}
.menu-btn {
    padding: 14px 8px;
    text-align: center;
    border-radius: 12px;
    background: #f9fafb;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid #eee;
}
.menu-btn:hover { background: #eef2ff; border-color: #6366f1; color: #4338ca; }

/* ─── 만세력 ─── */
.manseryeok-area { text-align: center; padding: 20px; }
.manseryeok-btn {
    display: inline-block;
    padding: 12px 32px;
    border: 2px solid #6366f1;
    border-radius: 12px;
    color: #6366f1;
    text-decoration: none;
    font-weight: 600;
    font-size: 15px;
    transition: all 0.2s;
}
.manseryeok-btn:hover { background: #6366f1; color: #fff; }

.footer-space { height: 40px; }

/* ─── 모달 ─── */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.modal-overlay.show { display: flex; }
.modal-content {
    background: #fff;
    border-radius: 20px;
    max-width: 420px;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
    padding: 0;
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px 12px;
    border-bottom: 1px solid #eee;
}
.modal-header h3 { font-size: 17px; font-weight: 700; }
.modal-close {
    background: none;
    border: none;
    font-size: 20px;
    color: #999;
    cursor: pointer;
}
.modal-body {
    padding: 16px 24px 24px;
    font-size: 14px;
    line-height: 1.8;
    color: #444;
}

/* ─── 입력 폼 (index.html) ─── */
.input-page {
    padding: 40px 20px;
}
.input-page h1 {
    text-align: center;
    font-size: 24px;
    margin-bottom: 8px;
}
.input-page .subtitle {
    text-align: center;
    color: #888;
    font-size: 14px;
    margin-bottom: 32px;
}
.form-group {
    margin-bottom: 20px;
}
.form-group label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 8px;
    color: #333;
}
.form-group input,
.form-group select {
    width: 100%;
    padding: 12px 16px;
    border: 1.5px solid #ddd;
    border-radius: 10px;
    font-size: 16px;
    outline: none;
    transition: border-color 0.2s;
    background: #fff;
}
.form-group input:focus,
.form-group select:focus {
    border-color: #6366f1;
}
.form-row {
    display: flex;
    gap: 10px;
}
.form-row .form-group { flex: 1; }

.radio-group {
    display: flex;
    gap: 12px;
}
.radio-group label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 400;
    cursor: pointer;
}
.radio-group input[type="radio"] {
    width: auto;
    accent-color: #6366f1;
}

.submit-btn {
    width: 100%;
    padding: 14px;
    background: #6366f1;
    color: #fff;
    border: none;
    border-radius: 12px;
    font-size: 17px;
    font-weight: 700;
    cursor: pointer;
    margin-top: 10px;
    transition: background 0.2s;
}
.submit-btn:hover { background: #4f46e5; }

/* ─── 반응형 ─── */
@media (max-width: 400px) {
    .wonkuk-cell { padding: 8px 2px; }
    .wonkuk-char { font-size: 18px; }
    .rel-cell { font-size: 18px; }
    .dw-cell { width: 42px; font-size: 16px; }
}
/* ─── 신강신약 게이지 (CSS 버전) ─── */
.gauge-wrapper {
    position: relative;
    width: 220px;
    height: 120px;
    margin: 20px auto;
    overflow: hidden;
}
.gauge-bg {
    width: 220px;
    height: 110px;
    border-radius: 110px 110px 0 0;
    background: #e5e7eb;
    position: relative;
    overflow: hidden;
}
.gauge-fill {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border-radius: 110px 110px 0 0;
    transform-origin: bottom center;
    transform: rotate(calc((var(--score) / 100 * 180 - 180) * 1deg));
    background: conic-gradient(
        from 0deg,
        #F59E0B 0deg 70deg,
        #EF4444 70deg 108deg,
        #3B82F6 108deg 180deg
    );
}
.gauge-center {
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
    background: #fff;
    width: 160px;
    height: 80px;
    border-radius: 80px 80px 0 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding-top: 10px;
}
.gauge-number {
    font-size: 42px;
    font-weight: 800;
    line-height: 1;
    display: block;
}
.gauge-label {
    font-size: 13px;
    color: #888;
    margin-top: 2px;
    display: block;
}
/* ═══════════════════════════════════════
   AI 사주 상담 채팅
   ═══════════════════════════════════════ */

.chat-intro {
    font-size: 14px;
    color: #666;
    margin-bottom: 16px;
    line-height: 1.6;
}

.chat-container {
    max-height: 500px;
    overflow-y: auto;
    padding: 12px 0;
    display: flex;
    flex-direction: column;
    gap: 14px;
    scroll-behavior: smooth;
}
.chat-container::-webkit-scrollbar { width: 4px; }
.chat-container::-webkit-scrollbar-thumb { background: #ddd; border-radius: 2px; }

/* 메시지 공통 */
.chat-message {
    display: flex;
    gap: 10px;
    max-width: 92%;
    animation: fadeInUp 0.3s ease;
}
.chat-message.bot { align-self: flex-start; }
.chat-message.user { align-self: flex-end; flex-direction: row-reverse; }

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* 아바타 */
.chat-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}
.chat-message.bot .chat-avatar { background: #f0f0ff; }
.chat-message.user .chat-avatar { background: #e8f5e9; }

/* 말풍선 */
.chat-bubble {
    padding: 14px 18px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.7;
    word-break: keep-all;
}
.bot-bubble {
    background: #f3f4f6;
    color: #333;
    border-bottom-left-radius: 4px;
}
.user-bubble {
    background: #6366f1;
    color: #fff;
    border-bottom-right-radius: 4px;
}

/* 로딩 애니메이션 */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 14px 18px;
    background: #f3f4f6;
    border-radius: 18px;
    border-bottom-left-radius: 4px;
}
.typing-dot {
    width: 8px;
    height: 8px;
    background: #999;
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

/* 빠른 질문 버튼 */
.quick-questions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 12px 0;
    border-top: 1px solid #f0f0f0;
    margin-top: 8px;
}
.quick-btn {
    padding: 8px 14px;
    border-radius: 20px;
    border: 1px solid #e0e0e0;
    background: #fff;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
    color: #555;
    white-space: nowrap;
}
.quick-btn:hover {
    background: #f0f0ff;
    border-color: #6366f1;
    color: #4338ca;
}

/* 입력 영역 */
.chat-input-area {
    display: flex;
    gap: 8px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #f0f0f0;
}
.chat-input {
    flex: 1;
    padding: 12px 16px;
    border: 1.5px solid #ddd;
    border-radius: 24px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}
.chat-input:focus { border-color: #6366f1; }
.chat-input::placeholder { color: #bbb; }

.chat-send-btn {
    padding: 12px 20px;
    background: #6366f1;
    color: #fff;
    border: none;
    border-radius: 24px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    white-space: nowrap;
}
.chat-send-btn:hover { background: #4f46e5; }
.chat-send-btn:disabled {
    background: #c7c7cc;
    cursor: not-allowed;
}
/* ─── 채팅 영역 수정 ─── */
#chatContainer {
    max-height: 600px !important;
    overflow-y: auto !important;
    scroll-behavior: smooth;
}

.chat-bubble {
    max-width: 85% !important;
    word-break: break-word !important;
    white-space: pre-wrap !important;
}
/* ─── 채팅 말풍선 잘림 방지 ─── */
.chat-message {
    display: flex !important;
    align-items: flex-start !important;
    margin-bottom: 12px !important;
    overflow: visible !important;
}

.chat-bubble, .bot-bubble, .user-bubble {
    max-width: 85% !important;
    word-break: break-word !important;
    white-space: pre-wrap !important;
    overflow: visible !important;
    overflow-wrap: break-word !important;
    display: block !important;
    height: auto !important;
    max-height: none !important;
}

#chatContainer {
    max-height: 600px !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
}

.chat-section, #section-chat {
    overflow: visible !important;
}
