:root {
  --bg: #f5f3ed;
  --panel: #fffdf8;
  --panel-2: #faf7f0;
  --line: #e3ded1;
  --line-soft: #efebe2;
  --ink: #241f1a;
  --ink-2: #5b544a;
  --ink-3: #918a7c;
  --accent: #a5332b;
  --accent-soft: #f5e7e4;
  --jade: #386a57;
  --jade-soft: #e6efe9;
  --gold: #b1823c;
  --gold-soft: #f7eeda;
  --shadow: 0 1px 2px rgba(60, 48, 30, .05), 0 8px 24px -12px rgba(60, 48, 30, .18);
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image: radial-gradient(circle at 20% 0%, rgba(165, 51, 43, .045), transparent 55%),
                    radial-gradient(circle at 85% 10%, rgba(177, 130, 60, .06), transparent 45%);
  z-index: 0;
}

.serif { font-family: "Songti SC", "STSong", "SimSun", "Noto Serif SC", serif; }

/* ── 布局 ── */
.wrap {
  position: relative;
  z-index: 1;
  max-width: 1280px;
  margin: 0 auto;
  padding: 26px 22px 80px;
}

header.top {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 22px;
  flex-wrap: wrap;
}

.brand { display: flex; align-items: baseline; gap: 12px; }
.brand h1 {
  margin: 0;
  font-size: 25px;
  letter-spacing: .1em;
  font-weight: 600;
  white-space: nowrap;
}
.brand .dot { color: var(--accent); }
.brand small {
  color: var(--ink-3);
  font-size: 12.5px;
  letter-spacing: .04em;
}

.top-actions { display: flex; gap: 8px; align-items: center; }

.layout {
  display: grid;
  grid-template-columns: 326px minmax(0, 1fr);
  gap: 22px;
  align-items: start;
}
/* 关键：grid 子项默认 min-width:auto，会让宽表格把整页撑破 */
.layout > * { min-width: 0; }
main, aside.form { min-width: 0; }

@media (max-width: 980px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .wrap { padding: 18px 14px 60px; }
  .brand h1 { font-size: 21px; }
  .brand small { display: none; }
  .pillars { gap: 6px; }
  .pillar .gz { font-size: 24px; }
  .ziwei-board { grid-template-rows: repeat(4, minmax(96px, auto)); }
  .pal { min-height: 92px; padding: 6px; }
  .star.major { font-size: 13px; }
  .center-cells { padding: 10px; }
  .center-cells .row { font-size: 11px; padding-bottom: 4px; }
  .center-cells .title { font-size: 13px; letter-spacing: .04em; margin-bottom: 2px; }
  .pal-stars { gap: 2px 4px; }
  .star.minor { font-size: 10.5px; }
  .top-actions { width: 100%; justify-content: flex-end; }
}

/* ── 卡片 ── */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 16px; }

.card-head {
  padding: 13px 16px;
  border-bottom: 1px solid var(--line-soft);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.card-head h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: .06em;
  color: var(--ink);
}
.card-head .hint { font-size: 12px; color: var(--ink-3); }
.card-body { padding: 16px; }

/* ── 表单 ── */
aside.form { position: sticky; top: 20px; }
@media (max-width: 980px) { aside.form { position: static; } }

.field { margin-bottom: 13px; }
.field > label {
  display: block;
  font-size: 12.5px;
  color: var(--ink-2);
  margin-bottom: 5px;
  letter-spacing: .04em;
}
.field .row2 { display: flex; gap: 8px; }

input[type="text"], input[type="date"], input[type="time"], input[type="number"], select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 7px;
  font-size: 14px;
  color: var(--ink);
  font-family: inherit;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(165, 51, 43, .1);
}
input::placeholder { color: #b9b2a4; }

.seg { display: flex; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; background: #fff; }
.seg button {
  flex: 1;
  border: 0;
  background: transparent;
  padding: 8px 0;
  font-size: 13.5px;
  color: var(--ink-2);
  cursor: pointer;
  font-family: inherit;
  transition: background .15s, color .15s;
}
.seg button + button { border-left: 1px solid var(--line-soft); }
.seg button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.switch {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--ink-2);
  cursor: pointer;
  user-select: none;
}
.switch input { width: 15px; height: 15px; accent-color: var(--accent); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink-2);
  border-radius: 999px;
  padding: 4px 11px;
  font-size: 12.5px;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
  transition: all .15s;
}
.chip:hover { border-color: #cfc7b6; }
.chip[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.chip.mini { padding: 2px 9px; font-size: 12px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink-2);
  border-radius: 7px;
  padding: 7px 13px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
  transition: all .15s;
}
.btn:hover { border-color: #cfc7b6; color: var(--ink); }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
  letter-spacing: .06em;
}
.btn.primary:hover { background: #8f2a23; border-color: #8f2a23; }
.btn.primary:disabled { opacity: .55; cursor: default; }
.btn.block { width: 100%; padding: 11px 0; font-size: 14.5px; }

.err {
  margin-top: 10px;
  padding: 9px 11px;
  border-radius: 7px;
  background: #fdefec;
  border: 1px solid #f0cfc9;
  color: #8f2a23;
  font-size: 12.5px;
  white-space: pre-wrap;
  display: none;
}
.err.show { display: block; }

/* ── 空态 ── */
.empty {
  padding: 90px 20px;
  text-align: center;
  color: var(--ink-3);
}
.empty .glyph {
  font-family: "Songti SC", serif;
  font-size: 66px;
  color: #ddd5c4;
  line-height: 1;
  margin-bottom: 16px;
  letter-spacing: .2em;
}
.empty p { margin: 4px 0; font-size: 13px; }

/* ── 标签页 ── */
.tabs {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 18px;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  border: 0;
  background: transparent;
  padding: 9px 15px 11px;
  font-size: 13.5px;
  color: var(--ink-3);
  cursor: pointer;
  font-family: inherit;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  transition: color .15s, border-color .15s;
}
.tab:hover { color: var(--ink-2); }
.tab[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

.panel { display: none; }
.panel.active { display: block; }
/* 只在「结果显示出来」时淡入一次；切页签不再重播，避免每次点页签闪一下 */
#result { animation: fade .26s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) {
  #result { animation: none; }
}

/* ── 四柱 ── */
.pillars {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}
.pillar {
  background: var(--panel-2);
  border: 1px solid var(--line-soft);
  border-radius: 9px;
  padding: 12px 8px;
  text-align: center;
}
.pillar .lab { font-size: 11.5px; color: var(--ink-3); letter-spacing: .1em; }
.pillar .gz {
  font-family: "Songti SC", "STSong", "SimSun", serif;
  font-size: 30px;
  line-height: 1.3;
  letter-spacing: .06em;
  margin: 4px 0 2px;
}
.pillar .ss { font-size: 11.5px; color: var(--ink-2); }
.pillar.day { border-color: #e7d3b6; background: #fdf8ef; }

/* ── 指标 ── */
.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
  gap: 10px;
}
.metric {
  border: 1px solid var(--line-soft);
  border-radius: 9px;
  padding: 10px 12px;
  background: var(--panel-2);
}
.metric .k { font-size: 11.5px; color: var(--ink-3); letter-spacing: .06em; }
.metric .v { font-size: 17px; font-weight: 600; margin-top: 2px; letter-spacing: .03em; }
.metric .v.accent { color: var(--accent); }
.metric .s { font-size: 11.5px; color: var(--ink-3); }

/* ── 五行条 ── */
.wuxing { display: grid; gap: 6px; }
.wx-row { display: grid; grid-template-columns: 26px 1fr 46px; gap: 9px; align-items: center; font-size: 12.5px; }
.wx-name { color: var(--ink-2); text-align: center; }
.wx-bar { height: 8px; background: #f0ece3; border-radius: 99px; overflow: hidden; }
.wx-bar > i { display: block; height: 100%; border-radius: 99px; transition: width .5s ease; }
.wx-val { color: var(--ink-3); font-variant-numeric: tabular-nums; text-align: right; }
.wx-row.is-yong .wx-name { color: var(--accent); font-weight: 700; }
.wx-row.is-yong .wx-val { color: var(--accent); }

/* ── 十二宫盘 ── */
.ziwei-board {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, minmax(112px, auto));
  gap: 6px;
  background: var(--line-soft);
  padding: 6px;
  border-radius: 10px;
}
.pal {
  background: var(--panel);
  border: 1px solid var(--line-soft);
  border-radius: 7px;
  padding: 7px 8px;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-height: 108px;
}
.pal.is-ming { border-color: var(--accent); box-shadow: inset 0 0 0 1px rgba(165, 51, 43, .25); }
.pal.is-shen::after {
  content: "身";
  position: absolute;
  top: 6px;
  right: 7px;
  font-size: 10px;
  color: var(--gold);
  border: 1px solid var(--gold);
  border-radius: 3px;
  padding: 0 3px;
  line-height: 1.4;
}
.pal-head { display: flex; align-items: baseline; justify-content: space-between; gap: 4px; }
.pal-name { font-size: 12.5px; color: var(--ink-2); font-weight: 600; }
.pal-branch { font-family: "Songti SC", serif; font-size: 12px; color: var(--ink-3); }
.pal-stars { display: flex; flex-wrap: wrap; gap: 3px 5px; }
.star {
  font-size: 12.5px;
  font-family: "Songti SC", "STSong", serif;
  color: var(--ink);
  letter-spacing: .02em;
}
.star.major { font-weight: 600; font-size: 14px; }
.star .br { font-size: 10.5px; color: var(--ink-3); margin-left: 1px; }
.star .sh { color: var(--accent); font-size: 10.5px; margin-left: 1px; }
.star.minor { color: var(--ink-2); font-size: 11.5px; }
.star.sha { color: #9a6a2f; }
.pal-foot { margin-top: auto; display: flex; justify-content: space-between; font-size: 10.5px; color: var(--ink-3); }
.pal-empty { font-size: 11.5px; color: var(--ink-3); font-style: italic; }

.center-cells {
  grid-column: 2 / 4;
  grid-row: 2 / 4;
  background: linear-gradient(160deg, #fdf8ee, #f7f1e3);
  border: 1px solid #ecdfc6;
  border-radius: 7px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 7px;
}
.center-cells .row { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--ink-2); border-bottom: 1px dashed #e6dac2; padding-bottom: 5px; }
.center-cells .row:last-child { border-bottom: 0; }
.center-cells .row b { color: var(--ink); font-weight: 600; }
.center-cells .title { font-family: "Songti SC", serif; font-size: 17px; letter-spacing: .14em; color: var(--accent); margin-bottom: 4px; }

/* ── 列表 / 结论块 ── */
.sec { margin-bottom: 20px; }
.sec:last-child { margin-bottom: 0; }
.sec > h4 {
  margin: 0 0 9px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: .06em;
  display: flex;
  align-items: center;
  gap: 7px;
}
.sec > h4::before {
  content: "";
  width: 3px; height: 13px;
  background: var(--accent);
  border-radius: 2px;
}

.kv { display: grid; grid-template-columns: 84px 1fr; gap: 6px 12px; font-size: 13px; }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; color: var(--ink); }

.plain {
  margin-top: 7px;
  padding: 9px 12px;
  background: var(--panel-2);
  border-left: 2px solid #ddd3be;
  border-radius: 0 6px 6px 0;
  font-size: 12.5px;
  color: var(--ink-2);
  line-height: 1.7;
}
.plain b { color: var(--ink); }
.quote {
  margin-top: 7px;
  font-size: 12.5px;
  color: var(--ink-2);
  padding-left: 10px;
  border-left: 2px solid #e7d3b6;
}
.quote .src { color: var(--gold); font-size: 11.5px; }

.tag {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 4px;
  font-size: 11.5px;
  line-height: 1.7;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--ink-2);
}
.tag.good { background: var(--jade-soft); border-color: #cfe0d6; color: var(--jade); }
.tag.bad { background: var(--accent-soft); border-color: #edd4cf; color: var(--accent); }
.tag.mid { background: var(--gold-soft); border-color: #ecdcbe; color: #8d6425; }

/* ── 表格 ── */
.tw { overflow-x: auto; max-width: 100%; border: 1px solid var(--line-soft); border-radius: 8px; }
table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
th, td { padding: 7px 10px; text-align: left; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
th { background: var(--panel-2); color: var(--ink-2); font-weight: 600; white-space: nowrap; letter-spacing: .04em; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fdfbf6; }
td.num, th.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
td.nowrap { white-space: nowrap; }

/* ── 格局卡 ── */
.patterns { display: grid; gap: 9px; }
.pat {
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--panel-2);
}
.pat-head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.pat-head b { font-size: 13.5px; letter-spacing: .04em; }
.pat p { margin: 0; font-size: 12.5px; color: var(--ink-2); }
.pat .src { font-size: 11.5px; color: var(--ink-3); margin-top: 4px; }

/* ── 解读 ── */
.dim-block { border: 1px solid var(--line-soft); border-radius: 8px; margin-bottom: 10px; overflow: hidden; }
.dim-block > summary {
  cursor: pointer;
  padding: 10px 13px;
  background: var(--panel-2);
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: .05em;
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.dim-block > summary::-webkit-details-marker { display: none; }
.dim-block > summary::after { content: "＋"; color: var(--ink-3); font-weight: 400; }
.dim-block[open] > summary::after { content: "－"; }
.dim-body { padding: 13px 15px; font-size: 13px; color: var(--ink-2); line-height: 1.85; }
.dim-body h2, .dim-body h3, .dim-body h4, .dim-body h5 {
  font-size: 13.5px;
  margin: 14px 0 6px;
  color: var(--ink);
  letter-spacing: .04em;
}
.dim-body h2:first-child, .dim-body h3:first-child { margin-top: 0; }
.dim-body p { margin: 6px 0; }
.dim-body ul, .dim-body ol { margin: 6px 0; padding-left: 20px; }
.dim-body li { margin: 3px 0; }
.dim-body strong { color: var(--ink); }

/* ── 流年 ── */
.mark-助 { color: var(--jade); font-weight: 700; }
.mark-偏助 { color: #4f7f68; font-weight: 600; }
.mark-平 { color: var(--ink-3); }
.mark-偏忌 { color: #a8722f; font-weight: 600; }
.mark-忌 { color: var(--accent); font-weight: 700; }

.flag {
  display: inline-block;
  font-size: 11px;
  padding: 0 5px;
  border-radius: 3px;
  background: var(--accent);
  color: #fff;
  margin-left: 4px;
  vertical-align: 1px;
}

/* ── 交叉对照 ── */
.xref td:first-child { font-weight: 600; white-space: nowrap; }
.xref .caution { margin-top: 8px; font-size: 12px; color: var(--ink-2); }
.xref .caution li { margin-bottom: 5px; }

/* ── 打印 ── */
@media print {
  body::before, aside.form, .top-actions, .tabs { display: none !important; }
  .layout { display: block; }
  .panel { display: block !important; page-break-inside: avoid; }
  .card { box-shadow: none; }
}

/* ── 载入 ── */
.loading {
  display: none;
  padding: 60px 0;
  text-align: center;
  color: var(--ink-3);
  font-size: 13px;
  letter-spacing: .08em;
}
.loading.show { display: block; }
.spinner {
  width: 22px; height: 22px;
  margin: 0 auto 12px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.note {
  font-size: 12px;
  color: var(--ink-3);
  padding: 8px 12px;
  background: var(--panel-2);
  border-radius: 6px;
  margin-bottom: 14px;
}
.note.warn { background: #fdf3ea; color: #8a5a25; }
