:root {
  --paper: #f4efe6;
  --paper-deep: #e7dfd1;
  --ink: #182323;
  --ink-soft: #5c6965;
  --jade: #1d5b57;
  --jade-dark: #153f3d;
  --jade-light: #dce9e3;
  --vermilion: #b6533f;
  --gold: #a4773b;
  --line: rgba(24, 35, 35, 0.16);
  --white: #fffdf8;
}

* { box-sizing: border-box; }

html { background: var(--paper); }

body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}

button, input, textarea { font: inherit; }
button { cursor: pointer; }

.app-shell { min-height: 100vh; }

.topbar {
  align-items: center;
  background: var(--jade-dark);
  color: #f8f4ea;
  display: flex;
  justify-content: space-between;
  padding: 16px clamp(18px, 4vw, 56px);
}

.brand-lockup { align-items: center; display: flex; gap: 12px; }
.seal-mark { height: 40px; width: 40px; }
.brand-lockup h1 { font-family: "STKaiti", "KaiTi", serif; font-size: 20px; margin: 2px 0 0; }
.eyebrow { color: var(--gold); font-size: 10px; font-weight: 700; letter-spacing: 1.6px; margin: 0 0 6px; text-transform: uppercase; }
.topbar .eyebrow { color: #b7d7c7; }
main { margin: 0 auto; max-width: 1180px; padding: 0 18px 48px; }

.hero-band {
  align-items: end;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 24px;
  justify-content: space-between;
  padding: 42px 0 32px;
}
.hero-band h2 { font-family: "STKaiti", "KaiTi", serif; font-size: clamp(28px, 4vw, 44px); font-weight: 600; line-height: 1.15; margin: 0; }
.hero-copy { color: var(--ink-soft); font-size: 14px; line-height: 1.8; margin: 14px 0 0; max-width: 560px; }
.hero-note { border-left: 2px solid var(--vermilion); padding: 8px 0 8px 16px; }
.note-label { color: var(--vermilion); display: block; font-size: 11px; font-weight: 700; margin-bottom: 8px; }
.hero-note strong { display: block; font-size: 14px; }

.control-panel, .result-section { background: rgba(255, 253, 248, 0.72); border-bottom: 1px solid var(--line); }
.control-panel { padding: 24px 0 26px; }
.section-heading, .result-heading { align-items: end; display: flex; justify-content: space-between; gap: 18px; }
.section-heading h2, .result-heading h2 { font-family: "STKaiti", "KaiTi", serif; font-size: 24px; font-weight: 600; margin: 0; }
.section-heading h3 { font-size: 16px; margin: 0; }
.section-heading.compact { align-items: center; margin-bottom: 16px; }
.muted { color: var(--ink-soft); font-size: 12px; }

.bazi-form { align-items: end; display: grid; gap: 14px; grid-template-columns: 1.2fr 1fr 0.9fr 1.3fr auto; margin-top: 24px; }
.field, .switch-field { min-width: 0; }
.field > span, .field legend { color: var(--ink-soft); display: block; font-size: 12px; margin-bottom: 7px; }
.field input[type="date"], .field input[type="time"] { background: var(--white); border: 1px solid var(--line); border-radius: 2px; color: var(--ink); min-height: 44px; padding: 0 10px; width: 100%; }
.gender-field { border: 0; margin: 0; padding: 0; }
.segmented-control { background: var(--paper-deep); display: grid; grid-template-columns: 1fr 1fr; padding: 3px; }
.segment { background: transparent; border: 0; color: var(--ink-soft); min-height: 38px; }
.segment.active { background: var(--jade); color: #fff; }
.switch-field { align-items: center; display: flex; gap: 9px; min-height: 44px; }
.switch-field input { height: 1px; opacity: 0; position: absolute; width: 1px; }
.switch-track { background: #c2cbc4; border-radius: 20px; display: inline-flex; height: 22px; padding: 3px; transition: background 160ms ease; width: 38px; }
.switch-track span { background: white; border-radius: 50%; display: block; height: 16px; transform: translateX(0); transition: transform 160ms ease; width: 16px; }
.switch-field input:checked + .switch-track { background: var(--jade); }
.switch-field input:checked + .switch-track span { transform: translateX(16px); }
.switch-field strong { display: block; font-size: 13px; }
.switch-field small { color: var(--ink-soft); display: block; font-size: 10px; margin-top: 2px; }
.primary-button, .primary-small { background: var(--vermilion); border: 0; color: white; font-weight: 700; }
.primary-button { align-items: center; display: inline-flex; gap: 8px; min-height: 44px; padding: 0 16px; white-space: nowrap; }
.primary-button:disabled { cursor: wait; opacity: 0.55; }
.button-symbol { border: 1px solid rgba(255,255,255,0.55); font-family: "STKaiti", "KaiTi", serif; font-size: 15px; line-height: 20px; text-align: center; width: 20px; }

.result-section { margin-top: 24px; padding: 28px 0 0; }
.result-heading { align-items: start; border-bottom: 1px solid var(--line); padding-bottom: 20px; }
.result-heading h2 { font-size: 28px; }
.error-box { background: #f7ddd7; border-left: 3px solid var(--vermilion); color: #78362d; font-size: 13px; line-height: 1.6; margin: 18px 0 0; padding: 12px 14px; }

.pillars-grid { display: grid; gap: 1px; grid-template-columns: repeat(4, minmax(0, 1fr)); margin-top: 22px; }
.pillar { background: var(--jade-dark); color: #f7f3e9; min-height: 270px; padding: 16px 14px 14px; position: relative; }
.pillar:nth-child(2) { background: #225a55; }
.pillar:nth-child(3) { background: #2c6861; }
.pillar:nth-child(4) { background: #3b756a; }
.pillar-topline { align-items: center; border-bottom: 1px solid rgba(255,255,255,0.18); display: flex; justify-content: space-between; padding-bottom: 10px; }
.pillar-label { color: #c7ded1; font-size: 11px; font-weight: 700; letter-spacing: 1px; }
.pillar-mark { color: rgba(255,255,255,0.58); font-size: 9px; letter-spacing: 1px; }
.pillar-core { align-items: center; display: grid; grid-template-columns: 1fr 1px 1fr; margin: 16px 0 13px; }
.pillar-symbol-block { align-items: center; display: flex; flex-direction: column; min-width: 0; }
.pillar-caption { color: #bed4c7; font-size: 10px; margin-bottom: 5px; }
.pillar-stem, .pillar-branch { font-family: "STKaiti", "KaiTi", serif; font-size: 42px; line-height: 1; }
.pillar-stem { color: #f7f3e9; }
.pillar-branch { color: #f4c28e; }
.pillar-symbol-block small { color: rgba(255,255,255,0.62); font-size: 10px; margin-top: 5px; }
.pillar-divider { background: rgba(255,255,255,0.22); height: 74px; width: 1px; }
.pillar-god { align-items: center; border-bottom: 1px solid rgba(255,255,255,0.18); border-top: 1px solid rgba(255,255,255,0.18); color: #f6e3c5; display: flex; font-size: 13px; gap: 8px; justify-content: center; min-height: 36px; }
.pillar-god span { color: #bed4c7; font-size: 10px; }
.pillar-hidden { color: #bed4c7; font-size: 10px; line-height: 1.4; margin-top: 11px; }
.pillar-hidden-title { align-items: center; color: #d9ece0; display: flex; font-size: 10px; justify-content: space-between; margin-bottom: 6px; }
.pillar-hidden-title span:last-child { color: rgba(255,255,255,0.5); }
.pillar-hidden-list { display: grid; gap: 4px; }
.pillar-hidden-row { align-items: center; background: rgba(0,0,0,0.12); display: grid; gap: 5px; grid-template-columns: 27px 31px 1fr; min-height: 23px; padding: 3px 5px; }
.pillar-hidden-role { color: rgba(255,255,255,0.62); font-size: 9px; }
.pillar-hidden-stem { align-items: baseline; display: inline-flex; font-family: "STKaiti", "KaiTi", serif; font-size: 18px; gap: 3px; line-height: 1; }
.pillar-hidden-stem small { font-family: inherit; font-size: 9px; }
.pillar-hidden-god { color: #e6f0e8; font-size: 10px; overflow-wrap: anywhere; }
.empty-state { background: var(--paper-deep); color: var(--ink-soft); grid-column: 1 / -1; padding: 44px 18px; text-align: center; }

.quick-stats { border-bottom: 1px solid var(--line); border-top: 1px solid var(--line); display: grid; grid-template-columns: repeat(3, 1fr); margin-top: 22px; }
.quick-stats div { min-width: 0; padding: 16px 12px; }
.quick-stats div + div { border-left: 1px solid var(--line); }
.quick-stats span { color: var(--ink-soft); display: block; font-size: 11px; margin-bottom: 6px; }
.quick-stats strong { display: block; font-size: 14px; overflow-wrap: anywhere; }

.tab-row { border-bottom: 1px solid var(--line); display: flex; gap: 4px; margin-top: 26px; overflow-x: auto; }
.tab-button { background: transparent; border: 0; border-bottom: 2px solid transparent; color: var(--ink-soft); min-height: 44px; padding: 0 14px; white-space: nowrap; }
.tab-button.active { border-bottom-color: var(--vermilion); color: var(--ink); font-weight: 700; }
.tab-panel { padding: 24px 0; }
.matrix-section { margin-bottom: 22px; }
.overview-grid { display: grid; gap: 22px; grid-template-columns: 1fr 1fr; }
.data-section { border-top: 2px solid var(--jade); padding-top: 16px; }
.overview-grid .data-section:first-child { grid-column: 1 / -1; }
.ten-gods-list { display: grid; gap: 14px; }
.pillar-detail-scroll { overflow-x: auto; padding-bottom: 2px; }
.pillar-detail-grid { background: var(--line); display: grid; gap: 1px; grid-template-columns: repeat(4, minmax(0, 1fr)); min-width: 860px; }
.pillar-detail { background: var(--white); min-width: 0; padding: 13px; }
.pillar-detail-title { align-items: start; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; margin-bottom: 12px; padding-bottom: 10px; }
.pillar-detail-title span { color: var(--ink-soft); font-size: 12px; }
.pillar-detail-title strong { color: var(--vermilion); font-family: "STKaiti", "KaiTi", serif; font-size: 26px; line-height: 1; }
.pillar-field { border-bottom: 1px solid rgba(24, 35, 35, 0.1); display: grid; gap: 5px; padding: 9px 0; }
.pillar-field > span { color: var(--ink-soft); font-size: 11px; }
.pillar-field strong { align-items: baseline; display: flex; gap: 8px; font-size: 13px; min-width: 0; }
.pillar-field b { color: var(--vermilion); font-family: "STKaiti", "KaiTi", serif; font-size: 22px; line-height: 1; }
.pillar-field small { color: var(--gold); font-size: 11px; line-height: 1.5; overflow-wrap: anywhere; }
.pillar-block { padding-top: 11px; }
.pillar-block h4, .subsection-title { color: var(--jade-dark); font-size: 12px; margin: 0 0 8px; }
.hidden-lines { display: grid; gap: 6px; }
.hidden-line { align-items: center; background: rgba(29, 91, 87, 0.07); display: grid; gap: 6px; grid-template-columns: 38px 24px 1fr; padding: 6px 7px; }
.hidden-line span { color: var(--ink-soft); font-size: 10px; }
.hidden-line strong { color: var(--vermilion); font-family: "STKaiti", "KaiTi", serif; font-size: 18px; line-height: 1; }
.hidden-line em { color: var(--ink); font-size: 12px; font-style: normal; }
.bazi-table-wrap { border: 1px solid var(--line); overflow-x: auto; }
.bazi-table { border-collapse: collapse; font-size: 12px; min-width: 680px; width: 100%; }
.bazi-table th { background: var(--jade-light); color: var(--jade-dark); font-weight: 700; text-align: left; }
.bazi-table th, .bazi-table td { border-bottom: 1px solid var(--line); padding: 9px 10px; vertical-align: top; }
.bazi-table tbody tr:last-child td { border-bottom: 0; }
.base-pan { min-width: 0; }
.bazi-matrix-scroll { overflow-x: auto; padding-bottom: 4px; }
.bazi-matrix { background: var(--line); display: grid; gap: 1px; min-width: 760px; }
.bazi-matrix-row { background: var(--white); display: grid; grid-template-columns: 76px repeat(4, minmax(136px, 1fr)); min-height: 44px; }
.bazi-matrix-row > div { align-items: center; display: flex; min-width: 0; padding: 9px 10px; }
.bazi-matrix-row > div + div { border-left: 1px solid var(--line); }
.bazi-matrix-label { color: var(--ink-soft); font-size: 11px; font-weight: 700; }
.matrix-header { background: var(--jade-dark); color: #f7f3e9; min-height: 40px; }
.matrix-header .bazi-matrix-label { color: #c7ded1; }
.matrix-header .bazi-matrix-cell { justify-content: center; }
.pillar-head { font-size: 12px; }
.bazi-matrix-cell { font-size: 12px; line-height: 1.5; overflow-wrap: anywhere; }
.big-symbol-row .bazi-matrix-cell { justify-content: center; }
.stack-row .bazi-matrix-cell { align-items: flex-start; }
.matrix-stack { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.god-main { color: var(--vermilion); font-weight: 700; }
.stem-token { align-items: baseline; display: inline-flex; gap: 6px; font-family: "STKaiti", "KaiTi", serif; font-size: 24px; line-height: 1; }
.stem-token small { font-family: inherit; font-size: 11px; }
.branch-token { color: var(--vermilion); }
.element-wood { color: #2f8068; }
.element-fire { color: #b6533f; }
.element-soil { color: #a4773b; }
.element-gold { color: #8c6b25; }
.element-water { color: #39748b; }
.char-cell { color: var(--vermilion); font-family: "STKaiti", "KaiTi", serif; font-size: 18px; font-weight: 700; line-height: 1; }
.god-summary { display: grid; gap: 10px; grid-template-columns: repeat(5, minmax(0, 1fr)); }
.god-summary-item { background: var(--white); border-left: 3px solid var(--vermilion); min-width: 0; padding: 10px; }
.god-summary-item strong { display: block; font-size: 14px; margin-bottom: 4px; }
.god-summary-item span { color: var(--vermilion); display: block; font-size: 11px; font-weight: 700; margin-bottom: 5px; }
.god-summary-item small { color: var(--ink-soft); display: block; font-size: 11px; line-height: 1.5; overflow-wrap: anywhere; }
.shensha-list { border: 1px solid var(--line); display: grid; gap: 0; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.shensha-row { display: grid; gap: 8px; grid-template-columns: 54px 1fr; min-width: 0; padding: 10px; }
.shensha-row:nth-child(odd) { border-right: 1px solid var(--line); }
.shensha-row:nth-child(n + 3) { border-top: 1px solid var(--line); }
.shensha-row > span { color: var(--ink-soft); font-size: 12px; padding-top: 4px; }
.mini-tag { background: rgba(29, 91, 87, 0.1); color: var(--jade-dark); display: inline-block; font-size: 11px; line-height: 1.4; margin: 0 5px 5px 0; padding: 4px 6px; }
.nayin-list { display: grid; gap: 12px; }
.nayin-pillar-scroll { overflow-x: auto; padding-bottom: 2px; }
.nayin-pillar-grid { background: var(--line); display: grid; gap: 1px; grid-template-columns: repeat(4, minmax(0, 1fr)); min-width: 520px; }
.nayin-pillar { background: var(--white); min-width: 0; padding: 12px; }
.nayin-pillar span { color: var(--ink-soft); display: block; font-size: 12px; margin-bottom: 8px; }
.nayin-pillar strong { display: block; font-size: 14px; overflow-wrap: anywhere; }
.palace-grid { display: grid; gap: 10px; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.nayin-item { border-bottom: 1px solid var(--line); display: grid; gap: 4px; grid-template-columns: 1fr auto; padding: 8px 0; }
.nayin-item span { color: var(--ink-soft); font-size: 12px; }
.nayin-item strong { font-size: 13px; }
.palace-item { border-bottom: 1px solid var(--line); display: grid; gap: 4px; min-width: 0; padding: 8px 0; }
.palace-item span { color: var(--ink-soft); font-size: 12px; }
.palace-item strong { font-size: 13px; overflow-wrap: anywhere; }
.palace-item small { color: var(--gold); font-size: 11px; overflow-wrap: anywhere; }
.dayun-list { display: grid; gap: 8px; grid-template-columns: repeat(4, 1fr); }
.dayun-item { background: var(--jade-light); border-top: 2px solid var(--jade); padding: 12px; }
.dayun-item span { color: var(--ink-soft); display: block; font-size: 11px; }
.dayun-item strong { display: block; font-family: "STKaiti", "KaiTi", serif; font-size: 24px; margin-top: 8px; }
.dayun-shensha { border-top: 1px solid rgba(21, 63, 61, 0.16); margin-top: 10px; padding-top: 9px; }
.prompt-text { background: #1a2827; border: 0; color: #dce9e3; font-family: "SFMono-Regular", Consolas, monospace; font-size: 12px; line-height: 1.6; max-height: 560px; min-height: 240px; overflow: auto; padding: 16px; white-space: pre-wrap; width: 100%; }
.prompt-text { display: block; min-height: 460px; resize: vertical; }
.primary-small { border: 1px solid var(--line); font-size: 12px; min-height: 34px; padding: 0 11px; }
.primary-small { border-color: var(--vermilion); }
.disclaimer { color: var(--ink-soft); font-size: 11px; line-height: 1.7; margin: 12px 0 0; }
.footer-note { color: var(--ink-soft); font-size: 11px; margin: 20px auto; max-width: 1180px; padding: 0 18px; }

button:focus-visible, input:focus-visible, textarea:focus-visible { outline: 3px solid rgba(182, 83, 63, 0.3); outline-offset: 2px; }

@media (max-width: 780px) {
  .topbar { padding: 14px 16px; }
  main { padding: 0 14px 34px; }
  .hero-band { align-items: start; flex-direction: column; gap: 22px; padding: 30px 0 24px; }
  .hero-band h2 { font-size: 31px; }
  .hero-note { width: 100%; }
  .bazi-form { grid-template-columns: 1fr 1fr; }
  .gender-field { grid-column: 1 / 2; }
  .switch-field { grid-column: 2 / 3; }
  .primary-button { grid-column: 1 / -1; justify-content: center; }
  .result-heading { align-items: start; flex-direction: column; }
  .pillars-grid { gap: 1px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .pillar { min-height: 270px; padding: 14px 10px; }
  .pillar-stem, .pillar-branch { font-size: 32px; }
  .quick-stats { grid-template-columns: 1fr; }
  .quick-stats div + div { border-left: 0; border-top: 1px solid var(--line); }
  .overview-grid { grid-template-columns: 1fr; }
  .pillar-detail-grid { min-width: 760px; }
  .god-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .shensha-list { grid-template-columns: 1fr; }
  .shensha-row:nth-child(odd) { border-right: 0; }
  .shensha-row:nth-child(n + 2) { border-top: 1px solid var(--line); }
  .palace-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dayun-list { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 430px) {
  .brand-lockup h1 { font-size: 17px; }
  .seal-mark { height: 34px; width: 34px; }
  .bazi-form { gap: 10px; }
  .pillar { min-height: 286px; padding-left: 9px; padding-right: 9px; }
  .pillar-label { font-size: 10px; }
  .pillar-stem, .pillar-branch { font-size: 31px; }
  .pillar-hidden { font-size: 9px; }
  .god-summary { grid-template-columns: 1fr; }
  .palace-grid { grid-template-columns: 1fr; }
  .dayun-item strong { font-size: 21px; }
}
