/* ── 기본 설정 ── 복권번호생성기와 동일한 톤앤매너 ── */
:root {
    --accent: #007aff;
    --accent-dark: #0062cc;
    --bg: #f5f5f7;
    --card-bg: #fff;
    --text: #1c1c1e;
    --text-muted: #8e8e93;
    --border: rgba(0, 0, 0, 0.08);
    --radius: 12px;
    --shadow: 0 1px 4px rgba(0, 0, 0, 0.06), 0 4px 12px rgba(0, 0, 0, 0.06);
    --saju-accent: #fbc400;
    --oh-wood: #27ae60;
    --oh-fire: #e74c3c;
    --oh-earth: #f39c12;
    --oh-metal: #95a5a6;
    --oh-water: #2980b9;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.7;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.container {
    flex: 1;
    max-width: 680px;
    width: 100%;
    margin: 0 auto;
    padding: 0 16px 40px;
}

/* ── 헤더 ────────────────────────────────────── */
header {
    background: #fff;
    border-bottom: 0.5px solid rgba(0, 0, 0, 0.1);
    text-align: center;
    padding: 28px 20px 22px;
    margin-bottom: 24px;
}

header h1 {
    font-size: 1.6rem;
    font-weight: 700;
    letter-spacing: -0.5px;
    color: var(--text);
    margin-bottom: 6px;
}

.logo {
    display: none;
}

.subtitle {
    color: var(--text-muted);
    font-size: 0.88rem;
}

/* ── 카드 ────────────────────────────────────── */
.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    overflow: hidden;
    margin-bottom: 20px;
}

.card h2 {
    color: var(--text);
    font-size: 1rem;
    font-weight: 700;
    padding: 14px 20px;
    margin: 0;
    border-bottom: 1px solid var(--border);
    border-left: 4px solid var(--saju-accent);
}

#input-section {
    overflow: visible;
}

#input-section h2 {
    margin-bottom: 0;
}

#input-section form {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 0;
}

/* ── 폼 ──────────────────────────────────────── */
.form-row {
    display: flex;
    gap: 16px;
    margin-bottom: 16px;
}

.form-group {
    flex: 1;
}

.form-group.full-width {
    flex: 1 1 100%;
}

.form-group label {
    display: block;
    font-size: 0.78rem;
    color: var(--text-muted);
    font-weight: 600;
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.form-group input[type="text"],
.form-group select {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 0.95rem;
    font-family: inherit;
    transition: border-color 0.2s;
}

.form-group input[type="text"]:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.1);
}

.radio-group {
    display: flex;
    gap: 8px;
}

.radio-label {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    padding: 8px 16px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    transition: all 0.2s;
    font-size: 0.95rem;
    color: var(--text);
}

.radio-label:has(input:checked) {
    border-color: var(--accent);
    background: rgba(0, 122, 255, 0.06);
    color: var(--accent);
    font-weight: 600;
}

.radio-label input[type="radio"] {
    display: none;
}

.birth-row .form-group {
    min-width: 0;
}

#intercalation-group {
    align-self: flex-end;
}

#intercalation-group label {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text);
}

/* ── 버튼 ────────────────────────────────────── */
#submit-btn {
    width: 100%;
    padding: 12px;
    margin-top: 8px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.15s, transform 0.1s;
    font-family: inherit;
}

#submit-btn:hover:not(:disabled) {
    background: var(--accent-dark);
}

#submit-btn:active {
    transform: scale(0.98);
}

#submit-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.spinner {
    width: 18px;
    height: 18px;
    border: 2.5px solid rgba(255, 255, 255, 0.4);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    display: inline-block;
    vertical-align: middle;
    margin-right: 6px;
}

/* ── 로딩 ────────────────────────────────────── */
.loading-container {
    text-align: center;
    padding: 40px 0;
}

.taeguk-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    margin: 0 auto 20px;
    animation: spin 0.8s linear infinite;
}

.taeguk-inner {
    display: none;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-container p {
    font-size: 0.95rem;
    color: var(--text);
    font-weight: 600;
}

.loading-sub {
    color: var(--text-muted);
    font-size: 0.82rem;
    margin-top: 6px;
    font-weight: 400;
}

/* ── AI 해석 실시간 스트리밍 표시 ────────────── */
.streaming-banner {
    display: flex;
    align-items: center;
    gap: 10px;
    background: linear-gradient(90deg, rgba(251, 196, 0, 0.14) 0%, rgba(251, 196, 0, 0.04) 100%);
    border-bottom: 1px solid rgba(251, 196, 0, 0.45);
    color: #8a6d00;
    font-size: 0.88rem;
    font-weight: 600;
    padding: 10px 20px;
}

.streaming-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--saju-accent);
    box-shadow: 0 0 0 0 rgba(251, 196, 0, 0.6);
    animation: streamPulse 1.2s ease-in-out infinite;
    flex-shrink: 0;
}

@keyframes streamPulse {
    0% { box-shadow: 0 0 0 0 rgba(251, 196, 0, 0.55); transform: scale(1); }
    70% { box-shadow: 0 0 0 8px rgba(251, 196, 0, 0); transform: scale(1.15); }
    100% { box-shadow: 0 0 0 0 rgba(251, 196, 0, 0); transform: scale(1); }
}

#interpretation.streaming::after {
    content: '▍';
    color: var(--saju-accent);
    animation: caretBlink 0.9s steps(2) infinite;
    margin-left: 2px;
    font-weight: bold;
}

@keyframes caretBlink {
    50% { opacity: 0; }
}

/* ── 사주 표 ─────────────────────────────────── */
#saju-table-card h2 {
    border-left: 4px solid var(--saju-accent);
}

#saju-info {
    text-align: center;
    padding: 16px 20px 0;
    color: var(--text-muted);
    font-size: 0.88rem;
}

#saju-info strong {
    color: var(--text);
    font-weight: 700;
}

#saju-table {
    padding: 0 20px;
}

#ohaeng-chart {
    padding: 0 20px 20px;
}

.saju-grid {
    display: grid;
    grid-template-columns: auto repeat(4, 1fr);
    gap: 0;
    margin: 16px 0;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}

.saju-grid.no-hour {
    grid-template-columns: auto repeat(3, 1fr);
}

.saju-cell {
    padding: 8px 6px;
    text-align: center;
    border-bottom: 1px solid var(--border);
    border-right: 1px solid var(--border);
}

.saju-cell:last-child {
    border-right: none;
}

.saju-cell.header {
    background: var(--bg);
    color: var(--text);
    font-size: 0.78rem;
    font-weight: 700;
}

.saju-cell.row-label {
    background: var(--bg);
    color: var(--text-muted);
    font-size: 0.78rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 48px;
}

.saju-cell .hanja {
    font-size: 1.1rem;
    font-weight: 700;
    display: block;
    margin-bottom: 1px;
    color: var(--text);
}

.saju-cell .hangul {
    font-size: 0.78rem;
    color: var(--text-muted);
}

.saju-cell .ohaeng-badge {
    display: inline-block;
    font-size: 0.68rem;
    padding: 1px 6px;
    border-radius: 4px;
    margin-top: 4px;
    color: #fff;
    font-weight: 600;
}

/* 오행 색상 */
.oh-wood { background: var(--oh-wood); }
.oh-fire { background: var(--oh-fire); }
.oh-earth { background: var(--oh-earth); }
.oh-metal { background: var(--oh-metal); color: #fff; }
.oh-water { background: var(--oh-water); }

/* ── 오행 차트 ───────────────────────────────── */
.ohaeng-chart {
    margin-top: 8px;
}

.ohaeng-chart h3 {
    font-size: 0.78rem;
    color: var(--text-muted);
    font-weight: 700;
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.ohaeng-bar-row {
    display: flex;
    align-items: center;
    margin-bottom: 8px;
    gap: 8px;
}

.ohaeng-bar-label {
    min-width: 50px;
    font-size: 0.82rem;
    text-align: right;
    color: var(--text);
    font-weight: 500;
}

.ohaeng-bar-track {
    flex: 1;
    height: 20px;
    background: var(--bg);
    border-radius: 4px;
    overflow: hidden;
}

.ohaeng-bar-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.8s ease;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-right: 6px;
    font-size: 0.68rem;
    color: #fff;
    font-weight: 700;
}

.ohaeng-bar-count {
    min-width: 24px;
    text-align: center;
    font-size: 0.82rem;
    color: var(--text-muted);
    font-weight: 600;
}

/* ── AI 해석 ─────────────────────────────────── */
#interpretation-card h2,
#followup-card h2 {
    border-left: 4px solid #636366;
}

/* ── 추가 질문 ───────────────────────────────── */
#followup-chat {
    padding: 0 20px;
    max-height: 400px;
    overflow-y: auto;
}

.chat-msg {
    padding: 12px 14px;
    margin: 8px 0;
    border-radius: 8px;
    font-size: 0.9rem;
    line-height: 1.7;
}

.chat-msg strong {
    color: var(--accent);
    margin-right: 4px;
}

.chat-user {
    background: var(--bg);
}

.chat-ai {
    background: #fff;
    border: 1px solid var(--border);
}

.chat-ai p {
    margin: 4px 0;
}

.chat-loading {
    color: var(--text-muted);
    font-size: 0.85rem;
}

.followup-input-wrap {
    display: flex;
    gap: 8px;
    padding: 16px 20px;
}

.followup-input-wrap input {
    flex: 1;
    padding: 10px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 0.9rem;
    font-family: inherit;
}

.followup-input-wrap input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.1);
}

.followup-input-wrap button {
    padding: 10px 20px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    white-space: nowrap;
}

.followup-input-wrap button:hover:not(:disabled) {
    background: var(--accent-dark);
}

.followup-input-wrap button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

#interpretation {
    line-height: 1.85;
    font-size: 0.93rem;
    padding: 20px;
    color: var(--text);
}

#interpretation h2 {
    color: var(--text);
    font-size: 1rem;
    font-weight: 700;
    margin-top: 28px;
    margin-bottom: 10px;
    padding: 0 0 8px 0;
    border-bottom: 1px solid var(--border);
    border-left: none;
}

#interpretation h2:first-child {
    margin-top: 0;
}

#interpretation p {
    margin-bottom: 12px;
    color: var(--text);
}

#interpretation ul, #interpretation ol {
    margin-bottom: 12px;
    padding-left: 20px;
}

#interpretation li {
    margin-bottom: 4px;
}

#interpretation strong {
    color: var(--text);
    font-weight: 700;
}

/* 커서 깜빡임 효과 */
.typing-cursor::after {
    content: '|';
    animation: blink 0.8s infinite;
    color: var(--accent);
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

/* ── 결과 공유 / PDF 저장 ────────────────────── */
#action-card {
    padding: 18px 20px;
}

.action-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.action-btn {
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 10px;
    padding: 12px 16px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, opacity 0.15s;
    min-height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-family: inherit;
}

.action-btn:hover:not(:disabled) {
    background: var(--accent-dark);
}

.action-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.action-btn.secondary {
    background: #fff;
    color: var(--accent-dark);
    border: 1.5px solid var(--saju-accent);
}

.action-btn.secondary:hover:not(:disabled) {
    background: rgba(0, 122, 255, 0.06);
}

.action-helper {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.82rem;
    margin: 12px 0 0;
}

.action-tip {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.78rem;
    margin: 6px 0 0;
}

/* ── 토스트 ──────────────────────────────────── */
.toast {
    position: fixed;
    left: 50%;
    bottom: 32px;
    transform: translateX(-50%) translateY(20px);
    background: rgba(28, 28, 30, 0.92);
    color: #fff;
    padding: 12px 20px;
    border-radius: 24px;
    font-size: 0.9rem;
    opacity: 0;
    transition: all 0.25s;
    z-index: 100;
    pointer-events: none;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

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

/* 화면에선 숨김, 인쇄 시에만 표시 */
.print-only {
    display: none;
}

/* ── 푸터 ────────────────────────────────────── */
footer {
    text-align: center;
    padding: 20px;
    font-size: 0.78rem;
    color: var(--text-muted);
}

footer p {
    margin-bottom: 4px;
}

footer a {
    color: var(--accent);
    text-decoration: underline;
    text-underline-offset: 2px;
}

footer a:hover {
    color: var(--accent-dark);
}

footer .deploy-date {
    margin-top: 8px;
    font-size: 0.7rem;
    color: #bbb;
}

/* ── 반응형 ──────────────────────────────────── */
@media (max-width: 600px) {
    header {
        padding: 20px 16px 16px;
    }

    header h1 {
        font-size: 1.3rem;
    }

    .form-row {
        flex-direction: column;
        gap: 12px;
    }

    .birth-row {
        flex-direction: row;
        flex-wrap: wrap;
    }

    .birth-row .form-group {
        flex: 1 1 calc(50% - 8px);
        min-width: calc(50% - 8px);
    }

    .saju-cell .hanja {
        font-size: 1rem;
    }

    #input-section form {
        padding: 16px;
    }

    #saju-table, #ohaeng-chart, #interpretation {
        padding-left: 16px;
        padding-right: 16px;
    }
}

/* ── 입력 폼 부가 요소 ── */
.hint {
    color: var(--text-muted);
    font-size: 0.85em;
    font-weight: normal;
}

.advanced-settings {
    margin-top: 16px;
    padding: 12px 16px;
    background: rgba(0, 0, 0, 0.02);
    border-radius: 8px;
    border: 1px solid var(--border);
}

.advanced-settings summary {
    cursor: pointer;
    color: var(--text-muted);
    font-size: 0.9rem;
    user-select: none;
}

.advanced-settings summary:hover {
    color: var(--accent);
}

.advanced-settings .form-row {
    margin-top: 12px;
}

.advanced-note {
    margin: 8px 0 0;
    color: var(--text-muted);
    font-size: 0.8rem;
}

.solar-note {
    margin-top: 8px;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-style: italic;
}

/* ── @media print: 인쇄·PDF 저장 전용 ────────── */
@media print {
    /* 화면 전용 요소 모두 숨김 */
    header, footer, #input-section, #loading-section,
    #action-card, #followup-card, #toast, .streaming-banner {
        display: none !important;
    }

    body {
        background: #fff !important;
        color: #000 !important;
        font-family: 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
        line-height: 1.6;
        margin: 0 !important;
    }

    .container, #result-section {
        max-width: none !important;
        padding: 0 !important;
        margin: 0 !important;
    }

    .card {
        box-shadow: none !important;
        border: none !important;
        border-radius: 0 !important;
        margin: 0 0 6mm 0 !important;
        overflow: visible !important;
    }

    .card h2 {
        border-left: none !important;
        border-bottom: 2px solid #b8860b !important;
        font-size: 14pt;
        padding: 0 0 6px 0;
        margin-bottom: 12px;
        background: #fff !important;
    }

    /* 인쇄 시 색상 강제 출력 */
    .saju-cell .ohaeng-badge,
    .ohaeng-bar-fill,
    .saju-cell.header, .saju-cell.row-label,
    .ohaeng-bar-track {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    /* 사주 표·오행 차트 페이지 분리 방지 */
    #saju-table-card, .saju-grid, .ohaeng-chart {
        page-break-inside: avoid;
    }

    #interpretation {
        padding: 0 !important;
        color: #000;
    }

    #interpretation h2 {
        page-break-after: avoid;
        color: #8b6508 !important;
        border-bottom: 1px solid #ddd !important;
        font-size: 13pt;
        margin-top: 14pt;
        margin-bottom: 6pt;
    }

    #interpretation p,
    #interpretation li {
        font-size: 10.5pt;
        page-break-inside: avoid;
    }

    /* 표지 페이지 */
    .print-only.print-cover {
        display: block !important;
        page-break-after: always;
        break-after: page;
        padding: 20mm 4mm 0;
    }

    .print-cover h1 {
        font-size: 22pt;
        text-align: center;
        margin-bottom: 8mm;
    }

    .print-cover .print-date {
        text-align: center;
        color: #555;
        font-size: 10pt;
        margin-bottom: 12mm;
    }

    .print-cover hr {
        border: none;
        border-top: 1px solid #b8860b;
        margin: 8mm 0;
    }

    .print-cover h2 {
        font-size: 13pt;
        color: #8b6508;
        border: none !important;
        margin: 4mm 0;
    }

    .print-cover p, .print-cover li {
        font-size: 10.5pt;
        margin-bottom: 3mm;
    }

    .print-cover ul {
        padding-left: 6mm;
    }

    @page {
        size: A4;
        margin: 18mm 14mm;
    }
}
