:root {
  --bg: #f6f3ec;
  --card: #fffdf8;
  --ink: #2b2620;
  --muted: #7a7064;
  --line: #e2dacb;
  --accent: #8a3b2a;
  --warn-bg: #fff4e0;
  --warn-ink: #7a4b00;
  --row-hi: #f3ead8;

  /* 오행 색 */
  --mok: #2f7d4a;   --mok-ink: #fff;
  --hwa: #c23b2e;   --hwa-ink: #fff;
  --to: #e2b23c;    --to-ink: #3a2c00;
  --geum: #ebe8e1;  --geum-ink: #3b3830;
  --su: #1f2a36;    --su-ink: #fff;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1a1815; --card: #23201c; --ink: #ece6da; --muted: #a59a8a; --line: #3a352e;
    --accent: #e08a6e; --warn-bg: #3a2e18; --warn-ink: #f0cf8c; --row-hi: #332d24;
    --geum: #d9d5cc; --su: #0d1217; --su-ink: #e8eef5;
  }
}
:root[data-theme="dark"] {
  --bg: #1a1815; --card: #23201c; --ink: #ece6da; --muted: #a59a8a; --line: #3a352e;
  --accent: #e08a6e; --warn-bg: #3a2e18; --warn-ink: #f0cf8c; --row-hi: #332d24;
  --geum: #d9d5cc; --su: #0d1217; --su-ink: #e8eef5;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  line-height: 1.55;
}
main { max-width: 680px; margin: 0 auto; padding: 0 16px 32px; }
.top { max-width: 680px; margin: 0 auto; padding: 28px 16px 12px; }
.top h1 { margin: 0; font-size: 1.6rem; letter-spacing: -0.02em; }
.sub { margin: 4px 0 0; color: var(--muted); }
h2, h3 { margin: 0 0 10px; letter-spacing: -0.01em; }
h3 { font-size: 1.02rem; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 18px; margin-top: 14px; }

fieldset { border: 0; margin: 0 0 14px; padding: 0; }
legend { font-weight: 700; margin-bottom: 6px; padding: 0; }
.hint { color: var(--muted); font-weight: 400; font-size: 0.86rem; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.f { display: inline-flex; align-items: center; gap: 4px; }
.f.grow { flex: 1 1 200px; }
.f.grow select { width: 100%; }
input[type="number"], select {
  font: inherit; color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-height: 42px;
}
#y { width: 6.2em; }
#lon { width: 6.5em; }
.check { display: inline-flex; align-items: center; gap: 6px; margin-left: 4px; }

.opts { border-top: 1px solid var(--line); padding-top: 10px; margin-bottom: 14px; }
.opts summary { cursor: pointer; font-weight: 700; color: var(--accent); }
.opt { margin-top: 10px; display: grid; gap: 4px; }
.opt-title { font-weight: 700; font-size: 0.92rem; }
.opt small { color: var(--muted); margin-left: 4px; }

.go {
  width: 100%; font: inherit; font-weight: 700; font-size: 1.05rem; padding: 12px;
  border: 0; border-radius: 10px; background: var(--accent); color: #fff; cursor: pointer;
}
.privacy { margin: 10px 0 0; font-size: 0.82rem; color: var(--muted); text-align: center; }

/* 원국 표 */
.r-title { font-size: 1.1rem; }
.wonguk { width: 100%; border-collapse: separate; border-spacing: 6px; table-layout: fixed; }
.wonguk th { font-size: 0.86rem; color: var(--muted); font-weight: 600; }
.wonguk th.me { color: var(--accent); }
.wonguk .lab { width: 2.6em; font-size: 0.8rem; color: var(--muted); text-align: center; }
.tile {
  border-radius: 10px; text-align: center; padding: 8px 2px 6px;
  border: 1px solid rgba(0, 0, 0, 0.08);
}
.tile .hj { font-family: "Noto Serif KR", "Batang", serif; font-size: clamp(1.9rem, 8vw, 2.6rem); line-height: 1.1; font-weight: 700; }
.tile .kr { font-size: 0.8rem; opacity: 0.9; }
.tile.empty { background: transparent; border: 1px dashed var(--line); color: var(--muted); }
.el-목 { background: var(--mok); color: var(--mok-ink); }
.el-화 { background: var(--hwa); color: var(--hwa-ink); }
.el-토 { background: var(--to); color: var(--to-ink); }
.el-금 { background: var(--geum); color: var(--geum-ink); }
.el-수 { background: var(--su); color: var(--su-ink); }
.r-note { margin: 10px 0 0; color: var(--muted); font-size: 0.9rem; }

.warn { background: var(--warn-bg); color: var(--warn-ink); border-color: transparent; }
.warn ul { margin: 0; padding-left: 18px; }

.steps { margin: 0; padding-left: 20px; }
.steps li { margin: 3px 0; }
.steps b { font-variant-numeric: tabular-nums; }
.terms { margin: 0; }

.scroll { overflow-x: auto; }
.cmp { width: 100%; border-collapse: collapse; font-size: 0.9rem; min-width: 460px; }
.cmp th, .cmp td { border-bottom: 1px solid var(--line); padding: 7px 6px; text-align: left; white-space: nowrap; }
.cmp th { color: var(--muted); font-weight: 600; font-size: 0.82rem; }
.cmp tr.sel td { background: var(--row-hi); font-weight: 700; }
.cmp td.diff { color: var(--accent); font-weight: 700; }
.cmp td.num { font-variant-numeric: tabular-nums; }

.foot { max-width: 680px; margin: 0 auto; padding: 8px 16px 40px; color: var(--muted); font-size: 0.8rem; }

/* 원국 보조 줄 */
.wonguk tr.sub td { text-align: center; padding: 0; }
.god { font-size: 0.82rem; font-weight: 600; text-align: center; color: var(--ink); }
.stage { font-size: 0.8rem; color: var(--muted); text-align: center; }
.hidden-stems { font-family: "Noto Serif KR", "Batang", serif; letter-spacing: 0.15em; color: var(--muted); }
.hs.main { color: var(--ink); font-weight: 700; }

/* 오행 막대 */
.bars { display: grid; gap: 6px; }
.bar-row { display: grid; grid-template-columns: 4.2em 1fr 1.6em; align-items: center; gap: 8px; }
.bar-lab { font-weight: 600; font-size: 0.9rem; }
.bar-track { background: var(--bg); border-radius: 6px; height: 16px; overflow: hidden; border: 1px solid var(--line); }
.bar { display: block; height: 100%; border-radius: 5px; border: 0; }
.bar-n { text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; }

/* 대운·세운 */
.dw { display: grid; grid-template-columns: repeat(10, minmax(58px, 1fr)); gap: 6px; min-width: 620px; }
.dw-cell { display: grid; gap: 3px; padding: 6px 4px; border-radius: 10px; border: 1px solid transparent; }
.dw-cell.cur { border: 2px solid var(--accent); background: var(--row-hi); }
.dw-age { text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }
.dw-sub { text-align: center; font-size: 0.72rem; color: var(--muted); }
.tile.sm { padding: 4px 0 3px; border-radius: 8px; }
.tile.sm .hj { font-size: 1.5rem; }
.tile.sm .kr { font-size: 0.7rem; }

/* 다듬기: 금 막대는 바탕과 구분되게, 이름표 칸 넓게, 대운 줄 폭 */
.bar.el-금 { background: #a8a193; }
.wonguk .lab { width: 3.6em; white-space: nowrap; }
.dw { grid-template-columns: repeat(10, minmax(52px, 1fr)); min-width: 560px; }
.dw-sub { white-space: nowrap; letter-spacing: -0.02em; }

/* 음력 입력 */
.row.cal { margin-bottom: 8px; }
.r-title { margin-bottom: 0; }
.r-lunar { margin: 2px 0 8px; color: var(--muted); font-size: 0.9rem; }

/* 풀이 */
.reading section + section { margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--line); }
.reading h4 { margin: 0 0 6px; font-size: 0.98rem; color: var(--accent); }
.reading p { margin: 4px 0; }
.disclaimer { margin: 14px 0 0; padding: 10px 12px; background: var(--bg); border-radius: 8px; color: var(--muted); font-size: 0.82rem; }

.foot p { margin: 0 0 6px; }

/* 휴대폰 폭 */
@media (max-width: 440px) {
  .card { padding: 14px 12px; }
  .wonguk { border-spacing: 3px; }
  .wonguk th { font-size: 0.74rem; white-space: nowrap; }
  .wonguk .lab { width: 2.7em; font-size: 0.68rem; }
  .tile { padding: 6px 0 4px; }
  .tile .kr { font-size: 0.64rem; white-space: nowrap; letter-spacing: -0.03em; }
  .god { font-size: 0.74rem; }
  .stage { font-size: 0.72rem; }
  .hidden-stems { letter-spacing: 0; font-size: 0.86rem; white-space: nowrap; }
  .r-title { font-size: 1rem; }
}
