/* 오방색 디자인: 글자 칸을 오행의 색(청·적·황·백·흑)으로 칠한다. 색이 곧 정보다. */
:root {
  color-scheme: light;
  --bg: #F3F1EA;      /* 소색(바탕) */
  --panel: #FFFFFF;
  --ink: #15171C;     /* 흑 */
  --muted: #55585F;
  --line: #D9D5C9;
  --wood: #1E6B57;    /* 청 · 목 */
  --fire: #C4362B;    /* 적 · 화 */
  --earth: #E2A62B;   /* 황 · 토 */
  --metal: #FFFFFF;   /* 백 · 금 */
  --water: #15171C;   /* 흑 · 수 */
  --ok: #1E6B57;
  --serif: "Noto Serif KR", "Nanum Myeongjo", AppleMyungjo, "Songti SC", serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: system-ui, -apple-system, "Noto Sans KR", "Apple SD Gothic Neo", sans-serif;
  font-size: 16px; line-height: 1.55;
}
/* 배경: 직접 그린 나경(羅經, 간지와 24방위를 새긴 옛 방위판) 그림을 희미하게 깐다. 화면에 고정돼 글만 움직인다. */
body::before {
  content: ""; position: fixed; z-index: -1; pointer-events: none;
  width: min(96vw, 540px); aspect-ratio: 1; left: 50%; top: 50%; transform: translate(-50%, -50%);
  background: url("bg.svg") center / contain no-repeat; opacity: .14;
}
main { position: relative; max-width: 560px; margin: 0 auto; padding: 22px 16px calc(36px + env(safe-area-inset-bottom)); }
[hidden] { display: none !important; }

/* 오행 색 칸. 백(금)은 흰 바탕에 검은 테두리로 구분한다. */
.bg-목 { background: var(--wood); color: #fff; }
.bg-화 { background: var(--fire); color: #fff; }
.bg-토 { background: var(--earth); color: var(--ink); }
.bg-금 { background: var(--metal); color: var(--ink); box-shadow: inset 0 0 0 2px var(--ink); }
.bg-수 { background: var(--water); color: #fff; }

header h1 { font-size: 2rem; font-weight: 900; letter-spacing: -.03em; line-height: 1.1; margin: 6px 0 8px; }
.sub { color: var(--muted); font-size: .88rem; margin: 0 0 20px; line-height: 1.5; }
h2 { font-size: 1.3rem; font-weight: 900; letter-spacing: -.02em; margin: 0 0 14px; }
h3 { font-size: 1.05rem; font-weight: 900; margin: 20px 0 10px; }
small { font-weight: 400; color: var(--muted); }

/* 입력 */
#form.card { background: rgba(255, 255, 255, .6); border-radius: 18px; padding: 18px 16px; margin-bottom: 26px; }
.field { margin-bottom: 18px; }
.label { display: block; font-weight: 800; font-size: .92rem; margin: 0 0 7px; }
input[type=number], input[type=text], select, textarea {
  width: 100%; font: inherit; font-size: 16px; color: var(--ink); background: var(--bg);
  border: 2px solid transparent; border-radius: 12px; padding: 12px; min-height: 50px;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--ink); background: #fff; }
button:focus-visible, .btn:focus-visible, summary:focus-visible, .seg input:focus-visible + span, .check input:focus-visible {
  outline: 3px solid var(--earth); outline-offset: 2px;
}
input:disabled { opacity: .45; }
.row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; align-items: center; }
.row3 label { display: flex; align-items: center; gap: 6px; }
.row3 label span { color: var(--muted); flex: none; font-weight: 700; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.seg input { position: absolute; opacity: 0; }
.seg span { display: block; text-align: center; padding: 12px; border-radius: 12px; background: var(--bg); min-height: 50px; font-weight: 700; }
.seg input:checked + span { background: var(--ink); color: #fff; }
.check { display: inline-flex; align-items: center; gap: 8px; min-height: 48px; margin-top: 6px; font-weight: 600; }
.check input { width: 22px; height: 22px; accent-color: var(--ink); }
.note { color: var(--muted); font-size: .86rem; margin: 8px 0; line-height: 1.5; }
#placeHint { margin: 8px 2px 0; }

/* 버튼 */
button, .btn {
  font: inherit; font-size: 1rem; font-weight: 700; border-radius: 14px; border: 0; background: var(--panel); color: var(--ink);
  box-shadow: inset 0 0 0 2px var(--ink); padding: 13px 14px; min-height: 50px; cursor: pointer; text-decoration: none; text-align: center; display: inline-block;
}
button.primary { width: 100%; background: var(--ink); color: #fff; box-shadow: none; font-weight: 800; font-size: 1.08rem; padding: 16px; }
button:disabled { opacity: .45; cursor: default; }
#copy, #stop { width: 100%; }
#stop { margin: 8px 0; }
.row-btn { display: flex; gap: 8px; margin: 10px 0; }
.row-btn > * { flex: 1; white-space: nowrap; padding-left: 6px; padding-right: 6px; font-size: .92rem; }
.error { color: var(--fire); font-weight: 800; }
.ok { color: var(--ok); font-weight: 800; margin: 8px 0 0; }

/* 결과 구역: 카드 대신 굵은 검은 줄로 나눈다 */
#result > .card { border-top: 3px solid var(--ink); padding: 18px 0 8px; margin-bottom: 22px; }

/* 사주 원국 */
.pillars { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.pillar { min-width: 0; }
.pillar .pos { text-align: center; font-size: .78rem; font-weight: 800; color: var(--muted); padding-bottom: 4px; }
.tile { border-radius: 12px; display: flex; flex-direction: column; align-items: center; padding: 6px 4px 7px; margin-bottom: 6px; }
.tile .tg { font-size: .7rem; font-weight: 800; line-height: 1.2; min-height: 1.2em; align-self: flex-start; padding-left: 3px; }
.tile .ch { font-family: var(--serif); font-size: 2.5rem; font-weight: 700; line-height: 1.05; }
.tile .ko { font-size: .72rem; font-weight: 700; line-height: 1.2; align-self: flex-end; padding-right: 3px; }
.tile.unknown { background: transparent; color: var(--muted); box-shadow: inset 0 0 0 2px var(--line); }
.pillar .meta { text-align: center; font-size: .72rem; color: var(--muted); line-height: 1.45; word-break: keep-all; }
.summary { margin: 14px 0 6px; font-size: .95rem; }
.chip { display: inline-block; border-radius: 8px; padding: 1px 8px; font-weight: 800; }

.warn { background: var(--panel); box-shadow: inset 0 0 0 2px var(--earth); border-radius: 12px; padding: 11px 13px; margin: 10px 0; font-size: .88rem; line-height: 1.55; }
.warn b { display: block; }
.opts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 14px; }
.opts label { font-size: .82rem; font-weight: 800; }
.opts select { margin-top: 5px; padding: 10px 8px; font-size: 15px; background: var(--panel); }

/* 오행 분포 막대 */
.elbar { display: flex; height: 40px; border-radius: 12px; overflow: hidden; font-size: .82rem; font-weight: 800; }
.elbar span { display: flex; align-items: center; justify-content: center; min-width: 44px; }
.elnote { font-size: .9rem; font-weight: 700; margin: 8px 0 2px; }
.list { margin: 12px 0; padding-left: 18px; font-size: .92rem; }
.list li { margin: 3px 0; }
.list:empty { display: none; }

/* 대운·세운 */
.scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -16px; padding: 0 16px; }
.luck { display: flex; gap: 6px; padding-bottom: 8px; }
.luck .cell { flex: none; width: 62px; text-align: center; font-size: .74rem; border-radius: 12px; padding: 5px 4px 6px; }
.luck .cell.now { background: var(--panel); box-shadow: inset 0 0 0 3px var(--ink); }
.luck .yr { color: var(--muted); font-weight: 700; line-height: 1.5; }
.luck .mini { font-family: var(--serif); font-size: 1.35rem; font-weight: 700; line-height: 1.5; border-radius: 8px; margin: 2px 2px; }
.luck .ko { font-weight: 800; }

/* 풀이 */
.status { font-weight: 800; margin: 12px 0; }
.status::before { content: ""; display: inline-block; width: .7em; height: .7em; margin-right: .5em; border-radius: 50%; background: var(--fire); animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .2; } }
@media (prefers-reduced-motion: reduce) { .status::before { animation: none; } }
.reading { margin-top: 16px; font-size: 1rem; line-height: 1.75; overflow-wrap: anywhere; }
.reading h2, .reading h3, .reading h4, .reading h5, .reading h6 { font-weight: 900; letter-spacing: -.02em; line-height: 1.3; }
.reading h2 { font-size: 1.45rem; margin: 0 0 .6em; }
.reading h3 { font-size: 1.22rem; margin: 2em 0 .6em; padding-top: .9em; border-top: 3px solid var(--ink); }
.reading h4 { font-size: 1.05rem; margin: 1.5em 0 .4em; }
.reading h5, .reading h6 { font-size: 1rem; margin: 1.2em 0 .3em; }
.reading p { margin: .7em 0; }
.reading ul, .reading ol { padding-left: 1.3em; margin: .6em 0; }
.reading li { margin: .35em 0; } .reading li.sub { margin-left: 1.2em; list-style-type: circle; }
.reading blockquote { margin: 1em 0; padding: 14px 16px; background: var(--fire); color: #fff; border-radius: 14px; font-weight: 800; font-size: 1.06rem; line-height: 1.5; }
.reading blockquote strong { font-weight: 900; }
.reading hr { border: 0; border-top: 1px solid var(--line); margin: 1.6em 0; }
.reading code { background: var(--panel); padding: 0 .3em; border-radius: 4px; font-size: .9em; }
.reading a { color: var(--fire); font-weight: 700; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: .9em -16px; padding: 0 16px; }
.reading table { border-collapse: collapse; font-size: .86rem; min-width: 100%; background: var(--panel); }
.reading th, .reading td { border: 1px solid var(--line); padding: 7px 9px; text-align: left; vertical-align: top; }
.reading th { background: var(--ink); color: #fff; border-color: var(--ink); white-space: nowrap; }

details { margin-top: 8px; }
summary { cursor: pointer; padding: 10px 0; min-height: 44px; font-weight: 700; }
#promptText { font-size: 13px; font-family: ui-monospace, Menlo, monospace; background: var(--panel); }
footer { color: var(--muted); font-size: .78rem; text-align: center; margin-top: 10px; }
footer p { margin: 4px 0; }

/* 배경음악 버튼: 화면 오른쪽 아래에 떠 있다 */
.music {
  position: fixed; right: 14px; bottom: calc(14px + env(safe-area-inset-bottom)); z-index: 5;
  min-height: 44px; padding: 10px 14px; border-radius: 22px; font-size: .88rem; font-weight: 800;
  background: var(--panel); color: var(--ink); box-shadow: inset 0 0 0 2px var(--ink), 0 4px 14px rgba(21, 23, 28, .18);
}
.music[aria-pressed="true"] { background: var(--ink); color: #fff; }
main { padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
