/* 바로통 공통 스타일 — 모바일 우선, 다크 단일 테마 '밤하늘 별빛'(design/03-stars.html 이식).
   거의 검정 배경 + CSS 별 패턴, 포인트는 달빛 금색. --primary는 채움(버튼·탭·배지),
   --accent-text는 어두운 배경 위 텍스트 악센트(브랜드·h3·사화)용. */
:root {
  color-scheme: dark;
  --bg: #0a0a13;
  --surface: #14141f;
  --input-bg: #0d0d17;
  --text: #ede9df;
  --muted: #a8a396;
  --primary: #e3c878;
  --primary-contrast: #1c1400;
  --accent-text: #ecd694;
  --border: #2a2a3d;
  --input-border: #63637f; /* 폼 경계 전용 — WCAG 1.4.11 비텍스트 3:1 (vs --input-bg) */
  --accent-soft: #2a2438;
  --error-bg: #421f22;
  --error-text: #ffb4ab;
  --radius: 12px;
  --space: 1rem;
  --font: system-ui, -apple-system, 'Apple SD Gothic Neo', 'Noto Sans KR', sans-serif;
}

* { box-sizing: border-box; }

/* UA의 [hidden]{display:none}은 author 선언(.result-loading{display:flex} 등)에 진다.
   app.js의 el.hidden 토글이 실제로 숨기도록 author 규칙으로 다시 못박는다. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* 헤더 · 탭 내비 */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.site-header-inner {
  max-width: 720px;
  margin: 0 auto;
  padding: 0.75rem var(--space);
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}
.brand {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--accent-text);
  text-decoration: none;
}
.tabs {
  display: flex;
  gap: 0.3rem;
  flex-wrap: wrap; /* 280px 등 초협폭에서 알약이 찌그러지며 레이블이 깨지는 대신 줄바꿈 */
}
.tabs a {
  padding: 0.4rem 0.8rem;
  border-radius: 999px;
  border: 1px solid rgba(227, 200, 120, 0.38); /* 알약 윤곽만 잡는 장식선 — 가독은 글자색(--accent-text)이 담당 */
  color: var(--accent-text);
  text-decoration: none;
  font-size: 0.95rem;
}
.tabs a[aria-current="page"] {
  background: var(--primary);
  color: var(--primary-contrast);
  font-weight: 600;
}

main {
  max-width: 720px;
  margin: 0 auto;
  padding: 1.25rem var(--space) 3rem;
}

h1 { font-size: 1.5rem; margin: 0.5rem 0 0.25rem; }
.lede { color: var(--muted); margin-top: 0; }

/* 카드 · 폼 */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin: 1rem 0;
}
.field { margin-bottom: 1rem; border: 0; padding: 0; min-width: 0; }
.field > label, .field > legend {
  display: block;
  font-weight: 600;
  font-size: 0.95rem;
  margin-bottom: 0.35rem;
  padding: 0;
}
textarea, input[type="date"], input[type="time"] {
  width: 100%;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--input-border);
  border-radius: 8px;
  font: inherit;
  background: var(--input-bg);
  color: inherit;
}
textarea { resize: vertical; }
::placeholder { color: var(--muted); opacity: 1; }
input:disabled { background: var(--bg); color: var(--muted); }
.radio-row { display: flex; gap: 1.25rem; }
.radio-row label, .check {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-weight: 400;
}
.check { margin-top: 0.5rem; color: var(--muted); font-size: 0.95rem; }

button[type="submit"] {
  width: 100%;
  padding: 0.8rem;
  border: 0;
  border-radius: 8px;
  background: var(--primary);
  color: var(--primary-contrast);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
button[type="submit"]:disabled { opacity: 0.6; cursor: default; }

/* 결과 영역 */
.result-loading {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 0;
  color: var(--muted);
}
.spinner {
  width: 1.4rem;
  height: 1.4rem;
  flex: none;
  border: 3px solid var(--border);
  border-top-color: var(--accent-text);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.result-error {
  background: var(--error-bg);
  color: var(--error-text);
  border-radius: 8px;
  padding: 0.8rem 1rem;
  margin: 0.5rem 0;
}
.result-reading h3 {
  margin: 1.1rem 0 0.3rem;
  font-size: 1.05rem;
  color: var(--accent-text);
  padding-left: 0.6rem;
  border-left: 3px solid var(--primary);
}
.result-reading h3:first-child { margin-top: 0; }
.result-reading p { margin: 0.3rem 0 0.8rem; }

/* 정적 안내 섹션 */
.guide { margin-top: 2.5rem; }
.guide h2 { font-size: 1.2rem; margin-top: 2rem; }
/* h3 기본값(1.17em)은 위 h2(1.2rem)와 거의 같아 계층이 뭉갠다 — 토큰 규약대로 h3 는 --accent-text */
.guide h3 { font-size: 1.02rem; margin: 1.3rem 0 0.3rem; color: var(--accent-text); }
.guide p { color: var(--muted); }

/* horoscope 안내 — 사이트에 없던 표·2열 그리드만. h2/h3/p 는 .guide, 카드는 .card 가 이미 잡는다. */
.zodiac-table-wrap { overflow-x: auto; margin: 1rem 0; }
.zodiac-table { width: 100%; min-width: 480px; border-collapse: collapse; }
.zodiac-table th, .zodiac-table td {
  padding: 0.6rem 0.7rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
}
.zodiac-table th { background: var(--surface); }
.zodiac-table td { color: var(--muted); }
.zodiac-table td:first-child { color: var(--text); }
.note {
  border-left: 3px solid var(--primary);
  padding-left: 0.8rem;
  font-size: 0.9rem;
}
.note p:last-child { margin-bottom: 0; }
.zodiac-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.75rem; }
.zodiac-grid .card { margin: 0; } /* .card 의 세로 margin 이 grid gap 과 겹친다 */
@media (max-width: 560px) { .zodiac-grid { grid-template-columns: 1fr; } }
.zodiac-date { color: var(--muted); font-size: 0.9rem; margin: 0 0 0.4rem; }

/* jamidusu 안내 — 단계 목록과 프롬프트 코드 블록. 나머지는 .guide/.card/.note 가 잡는다. */
.steps { padding-left: 1.2rem; }
.steps li { margin-bottom: 0.8rem; color: var(--muted); }
.steps strong { display: block; color: var(--text); }
/* pre·code 의 UA 기본 monospace 는 한글 자간이 벌어진다 — 배경·테두리로 이미 코드 블록임이 보인다 */
.prompt-box, .prompt-box code { font-family: inherit; }
.prompt-box {
  max-height: 420px;
  overflow: auto;
  margin: 1rem 0;
  padding: 1rem;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.85rem;
  line-height: 1.6;
  white-space: pre-wrap;   /* 긴 줄이 가로 스크롤을 만들지 않게 */
  word-break: break-word;
  color: var(--text);
}

/* 푸터 */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 1.25rem var(--space) 2rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
}
.site-footer p { margin: 0.25rem 0; }
.site-footer .fine { font-size: 0.8rem; }

/* T5 horoscope — 별자리 카드 */
.sign-head {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.8rem;
  margin-bottom: 0.8rem;
}
.sign-glyph {
  font-size: 2.4rem;
  line-height: 1;
  color: var(--primary);
}
.sign-name { margin: 0; font-size: 1.25rem; }
.sign-range { margin: 0.1rem 0 0; color: var(--muted); font-size: 0.9rem; }
.sign-traits { margin: 0; }
.sign-traits dt {
  font-weight: 600;
  color: var(--primary);
  margin-top: 1rem;
}
.sign-traits dt:first-child { margin-top: 0; }
.sign-traits dd {
  margin: 0.3rem 0 0;
  white-space: pre-line; /* 문단 사이 빈 줄 유지 (텍스트는 textContent로만 삽입) */
}

/* T7 ziwei — 명반 4×4 격자 (sjj public/css/chart.css:47-76 이식, 색 변수만 이 프로젝트 팔레트로 치환) */
.ziwei-board {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-template-rows: repeat(4, minmax(96px, auto));
  gap: 2px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  font-size: clamp(11px, 2.6vw, 13px);
  line-height: 1.35;
}
.palace {
  background: var(--surface);
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.palace.is-body { background: var(--accent-soft); }
.palace-head { display: flex; align-items: center; justify-content: space-between; gap: 4px; }
.palace-name { font-weight: 700; }
.badge--body {
  background: var(--primary);
  color: var(--primary-contrast);
  border-radius: 999px;
  padding: 0 6px;
  font-size: 0.8em;
}
.palace-stars { flex: 1 1 auto; display: flex; flex-wrap: wrap; gap: 4px; align-content: flex-start; }
.star { display: inline-flex; align-items: baseline; gap: 2px; }
.star--major { font-weight: 700; }
.star--malefic { color: var(--error-text); }
.star--minor, .star--empty { color: var(--muted); }
.star-bright { font-size: 0.85em; color: var(--muted); }
.sahwa {
  font-size: 0.8em;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-text);
}
.sahwa--ji { background: var(--error-bg); color: var(--error-text); }
.palace-foot {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 4px;
  color: var(--muted);
  font-size: 0.9em;
}
.palace-gz { font-weight: 600; color: var(--text); }
.ziwei-center {
  grid-row: 2 / 4;
  grid-column: 2 / 4;
  background: var(--surface);
  padding: 10px;
  overflow: auto;
}
.center-list { margin: 0; font-size: 0.95em; }
.center-list dt { color: var(--muted); margin-top: 6px; }
.center-list dt:first-child { margin-top: 0; }
.center-list dd { margin: 0; }
.center-note { margin: 8px 0 0; color: var(--muted); font-size: 0.9em; }
.chart-alt { margin-top: 1rem; font-size: 0.9rem; color: var(--muted); }
.chart-alt-list { padding-left: 1.2rem; }

@media (min-width: 640px) {
  .ziwei-board { font-size: 13px; grid-template-rows: repeat(4, minmax(130px, auto)); }
}

/* 로고 */
.brand { display: inline-flex; align-items: center; gap: 8px; }
.brand-logo { border-radius: 50%; display: block; }

/* 밤하늘 별빛 테마 — 별 글로우 패턴(우상단 달빛 글로 포함) + 느린 트윙클, 금색 포인트 */
h1 { color: var(--accent-text); }
body::before {
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background-image:
    radial-gradient(520px 400px at 88% 0%, rgba(230, 200, 120, 0.26), transparent 70%),
    radial-gradient(circle at 25% 15%, rgba(255, 255, 255, 0.55) 0.5px, rgba(255, 255, 255, 0.12) 1.4px, transparent 2.6px),
    radial-gradient(circle at 70% 35%, rgba(255, 255, 255, 0.40) 0.5px, rgba(255, 255, 255, 0.08) 1.2px, transparent 2.2px),
    radial-gradient(circle at 45% 65%, rgba(255, 255, 255, 0.45) 0.5px, rgba(255, 255, 255, 0.10) 1.3px, transparent 2.4px),
    radial-gradient(circle at 88% 82%, rgba(230, 200, 120, 0.60) 0.7px, rgba(230, 200, 120, 0.15) 1.6px, transparent 3px);
  background-size: 100% 100%, 130px 130px, 96px 96px, 170px 170px, 230px 230px;
  animation: twinkle 7s ease-in-out infinite;
}
@keyframes twinkle { 50% { opacity: 0.65; } }
@media (prefers-reduced-motion: reduce) {
  body::before { animation: none; }
  .spinner { animation-duration: 3s; } /* 완전 정지 대신 저속 회전 — 문구는 단조 진행 후 고정이라 이게 유일한 지속 신호다 */
}
.card { box-shadow: 0 0 0 1px rgba(230, 200, 120, 0.06), 0 12px 30px rgba(0, 0, 0, 0.5); }
.tabs a[aria-current="page"] { box-shadow: 0 0 14px rgba(227, 200, 120, 0.35); }

/* UX 개선 (quick wins) */
:focus-visible { outline: 2px solid var(--accent-text); outline-offset: 2px; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* 사화 4종 색 분리 — 마크업(.sahwa--lu/quan/ke)은 chart-ziwei.php가 이미 출력한다. --ji는 위 정의 유지 */
.sahwa--lu { background: #1c3326; color: #93dfa5; }
.sahwa--quan { background: #3d2a12; color: #f0b46a; }
.sahwa--ke { background: #16303d; color: #7fc8e8; }
.star--lucky { color: var(--accent-text); }
/* 명궁 — 신궁(배경 채움 .is-body)과 구분되는 테두리 강조. 동궁이면 둘 다 적용된다 */
.palace.is-soul { box-shadow: inset 0 0 0 2px var(--primary); }
.palace.is-soul .palace-name { color: var(--accent-text); }

.retry-btn {
  display: block;
  margin-top: 0.6rem;
  padding: 0.45rem 0.9rem;
  border: 1px solid currentColor;
  border-radius: 8px;
  background: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
}
.cancel-btn {
  margin-left: auto;
  padding: 0.3rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}
.char-count { float: right; font-weight: 400; font-size: 0.85rem; color: var(--muted); }
.char-count--warn { color: var(--error-text); }
.reading-meta { color: var(--muted); font-size: 0.85rem; margin: 0 0 0.6rem; }

/* Phase 2 — 이미 계산된 값의 시각 부호화 */
.sign-badges { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0.8rem 0 0; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0 0.55rem;
  border-radius: 999px;
  font-size: 0.8rem;
  line-height: 1.7;
  background: var(--accent-soft);
  color: var(--accent-text);
}
.chip--fire { background: #3d2118; color: #ffab8a; }
.chip--earth { background: #33290f; color: #dfc47e; }
.chip--air { background: #16303d; color: #7fc8e8; }
.chip--water { background: #1c2a44; color: #8fb4f0; }

.sign-progress { margin: 0.8rem 0 0.2rem; }
.sign-progress-label { display: flex; justify-content: space-between; font-size: 0.85rem; color: var(--muted); margin-bottom: 0.3rem; }
.sign-progress-track { height: 6px; border-radius: 999px; background: var(--accent-soft); overflow: hidden; }
.sign-progress-fill { height: 100%; background: var(--primary); border-radius: 999px; }

.trait-fold { margin-top: 0.7rem; }
.trait-fold summary { cursor: pointer; font-weight: 600; color: var(--accent-text); }
.trait-body { white-space: pre-line; margin: 0.4rem 0 0; }

/* 명반 — 현재 대한·잡성 토글·범례·사주 자간 */
.palace-decadal.is-now { color: var(--primary); font-weight: 600; }
.minor-toggle { display: flex; justify-content: flex-end; margin: 0 0 0.4rem; }
.ziwei-board.minor-off .star--minor { display: none; }
.chart-legend { margin-top: 0.6rem; font-size: 0.9rem; color: var(--muted); }
.chart-legend summary { cursor: pointer; }
.legend-list { padding-left: 1.1rem; margin: 0.5rem 0 0; }
.legend-list li { margin: 0.25rem 0; }
.glyph { letter-spacing: 0.15em; }
@media (max-width: 639px) {
  .ziwei-center { overflow: visible; } /* 중앙판이 잘리는 대신 행 높이가 늘어나게 */
}

/* Phase 3 — 명반·결과 인터랙션 */
.palace { cursor: pointer; }
.palace.is-focus { outline: 2px solid var(--accent-text); outline-offset: -2px; }
.palace.is-trine { outline: 2px dashed var(--primary); outline-offset: -2px; }
.palace.is-flash { animation: palace-flash 1.6s ease-out; }
@keyframes palace-flash { 0%, 55% { background: var(--accent-soft); } }
.palace-detail h3 { margin: 0 0 0.5rem; font-size: 1.05rem; color: var(--accent-text); }
.palace-detail-stars { font-size: 0.95rem; margin-bottom: 0.5rem; }
.palace-link {
  background: var(--accent-soft);
  color: var(--accent-text);
  padding: 0 3px;
  border-radius: 4px;
  cursor: pointer;
}
.reading-toc { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0 0 0.8rem; }
.chip--toc { border: 0; cursor: pointer; font: inherit; font-size: 0.8rem; }
.sign-browse { margin-top: 0.8rem; }
.sign-browse summary { cursor: pointer; font-weight: 600; color: var(--accent-text); }
.sign-selector { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.5rem; margin-top: 0.6rem; }
@media (min-width: 640px) { .sign-selector { grid-template-columns: repeat(4, 1fr); } }
.sign-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 0.5rem 0.2rem;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}
.sign-cell-glyph { font-size: 1.3rem; color: var(--primary); }
.sign-cell-range { color: var(--muted); font-size: 0.75rem; }
.sign-cell.is-active { border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); }
/* Phase 4 — 잠긴 데이터 개방 */
.luck-title { margin: 1rem 0 0.4rem; font-weight: 600; color: var(--accent-text); }
.luck-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.5rem 0.8rem; }
.luck-item { display: flex; flex-direction: column; background: var(--input-bg); border: 1px solid var(--border); border-radius: 8px; padding: 0.45rem 0.6rem; }
.luck-label { color: var(--muted); font-size: 0.78rem; }
.luck-value { font-size: 0.92rem; }
.reading-tags { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.8rem; }
.mutagen-row { display: flex; flex-wrap: wrap; gap: 4px; }
.star-link { cursor: pointer; text-decoration: underline dotted; text-underline-offset: 2px; }

.cross-grid { display: flex; gap: 0.8rem; }
.cross-card { flex: 1; margin: 0; text-decoration: none; color: var(--text); }
.cross-card strong { display: block; color: var(--accent-text); margin-bottom: 0.2rem; }
.cross-card span { color: var(--muted); font-size: 0.9rem; }
@media (prefers-reduced-motion: reduce) { .palace.is-flash { animation: none; } }
