:root {
  --bg: #faf7f2;
  --paper: #ffffff;
  --ink: #2b2620;
  --ink-light: #5c5449;
  --gold: #b08a4a;
  --gold-light: #d9b980;
  --red: #a52a2a;
  --wx-mu: #2e7d4f;    /* 木 */
  --wx-huo: #d64b4b;   /* 火 */
  --wx-tu: #c69749;    /* 土 */
  --wx-jin: #b0b0b0;   /* 金 */
  --wx-shui: #2b6ea8;  /* 水 */
  --border: #e6dfd3;
  --shadow: 0 2px 8px rgba(60,40,10,0.06);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Noto Serif TC", "PingFang TC", "Microsoft JhengHei", serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.65;
}

/* ========== Header ========== */
.site-header {
  background: linear-gradient(135deg, #3a2f24, #1f1812);
  color: #f4ecd8;
  padding: 2rem 1.5rem;
  text-align: center;
  border-bottom: 4px double var(--gold);
}
.brand { display: inline-flex; align-items: baseline; gap: 0.5rem; }
.logo { font-size: 2rem; color: var(--gold-light); }
.site-header h1 { margin: 0; font-size: 2rem; letter-spacing: 0.3em; font-weight: 400; }
.site-header h1 small { font-size: 0.5em; letter-spacing: 0.2em; color: var(--gold-light); }
.tagline { color: var(--gold-light); letter-spacing: 0.5em; margin: 0.5rem 0 0; font-size: 0.9rem; }

/* ========== Layout ========== */
.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 1.5rem;
}
.card {
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow);
}
.card h2 {
  margin: 0 0 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--gold);
  font-size: 1.25rem;
  color: var(--ink);
  display: inline-block;
}

/* ========== Form（古典中國風：丹青宮闕） ========== */
:root {
  --zh-cream: #faf3e3;
  --zh-cream-deep: #f3e9d1;
  --zh-paper: #fefaf0;
  --zh-red: #b83a3a;          /* 朱砂紅 */
  --zh-red-deep: #8c2828;     /* 暗朱 */
  --zh-red-pale: #e9c7c0;     /* 胭脂 */
  --zh-cyan: #3c687a;         /* 石青 */
  --zh-cyan-pale: #c9d7dd;    /* 淡青 */
  --zh-gold: #b08a4a;         /* 金線 */
  --zh-gold-light: #d4b57a;   /* 淡金 */
  --zh-ink: #2a2419;          /* 墨 */
  --zh-ink-light: #5a4c38;    /* 淡墨 */
  --zh-line: #ddc99c;         /* 邊線 */
}

.form-card.zh-card {
  position: relative;
  background:
    radial-gradient(ellipse 160% 100% at 50% 0%, rgba(184, 58, 58, 0.04) 0%, transparent 60%),
    radial-gradient(ellipse 100% 60% at 50% 110%, rgba(60, 104, 122, 0.03) 0%, transparent 50%),
    var(--zh-paper);
  border: 1px solid var(--zh-line);
  border-radius: 2px;
  padding: 2.8rem 2.4rem 2.2rem;
  box-shadow:
    inset 0 0 0 5px var(--zh-paper),
    inset 0 0 0 6px rgba(176, 138, 74, 0.35),
    0 4px 20px rgba(80, 60, 30, 0.08);
  overflow: hidden;
}

/* 回紋邊框（上下）— 用 repeating gradient 模擬 */
.meander-border {
  position: absolute;
  left: 12px;
  right: 12px;
  height: 10px;
  background-image:
    linear-gradient(90deg, var(--zh-gold) 0, var(--zh-gold) 100%),
    repeating-linear-gradient(
      90deg,
      transparent 0,
      transparent 6px,
      var(--zh-gold) 6px,
      var(--zh-gold) 7px,
      transparent 7px,
      transparent 13px,
      var(--zh-gold) 13px,
      var(--zh-gold) 14px,
      transparent 14px,
      transparent 20px
    );
  background-size: 100% 1px, 100% 100%;
  background-position: 0 50%, 0 0;
  background-repeat: no-repeat, repeat-x;
  opacity: 0.55;
}
.meander-top { top: 14px; }
.meander-bottom { bottom: 14px; }

/* 四角祥雲 */
.corner-cloud {
  position: absolute;
  width: 34px;
  height: 34px;
  pointer-events: none;
}
.corner-cloud svg { width: 100%; height: 100%; }
.corner-tl { top: 8px;    left: 8px; }
.corner-tr { top: 8px;    right: 8px;  transform: scaleX(-1); }
.corner-bl { bottom: 8px; left: 8px;   transform: scaleY(-1); }
.corner-br { bottom: 8px; right: 8px;  transform: scale(-1, -1); }

/* 題款區 */
.zh-title {
  position: relative;
  text-align: center;
  margin: 0.5rem 0 2rem;
  z-index: 1;
}
.zh-title-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1.2rem;
}
.zh-title-line {
  flex: 0 1 80px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--zh-gold) 40%, var(--zh-gold) 60%, transparent);
}
.zh-title-main {
  display: inline-block;
  margin: 0;
  padding: 0;
  border: none;
  font-size: 1.8rem;
  color: var(--zh-ink);
  letter-spacing: 0.1em;
  font-weight: 500;
  font-family: "ZCOOL XiaoWei", "Noto Serif TC", "PingFang TC", serif;
  position: relative;
}
.zh-title-sub {
  margin: 0.7rem 0 0;
  font-size: 0.88rem;
  color: var(--zh-ink-light);
  letter-spacing: 0.5em;
  font-weight: 400;
  font-family: "Noto Serif TC", serif;
}

/* 區塊 fieldset */
.bazi-form .form-section {
  position: relative;
  border: none;
  padding: 0;
  margin: 0 0 1.6rem;
  background: transparent;
  border-radius: 0;
}
.bazi-form .form-section + .form-section {
  padding-top: 1.3rem;
  border-top: 1px dashed var(--zh-line);
}
.bazi-form .form-section legend {
  padding: 0;
  margin: 0 0 0.9rem;
  display: flex;
  align-items: center;
  gap: 0.8rem;
  float: none;
  width: 100%;
}

/* 朱砂篆印 */
.zh-seal {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  background: linear-gradient(135deg, var(--zh-red) 0%, var(--zh-red-deep) 100%);
  color: #fdf2e0;
  font-family: "ZCOOL XiaoWei", "Noto Serif TC", serif;
  font-size: 1.4rem;
  font-weight: 500;
  letter-spacing: 0;
  border-radius: 3px;
  box-shadow:
    inset 0 0 0 2px rgba(253, 242, 224, 0.25),
    inset 0 0 0 3px var(--zh-red-deep),
    0 2px 4px rgba(140, 40, 40, 0.25);
  transform: rotate(-3deg);
  flex-shrink: 0;
  position: relative;
}
.zh-seal::after {
  content: '';
  position: absolute;
  inset: 1px;
  background:
    radial-gradient(circle at 30% 30%, rgba(253, 242, 224, 0.15), transparent 50%),
    radial-gradient(circle at 70% 70%, transparent, rgba(80, 20, 20, 0.12));
  border-radius: 3px;
  pointer-events: none;
}
.sect-label {
  font-size: 1.02rem;
  color: var(--zh-ink);
  letter-spacing: 0.25em;
  font-weight: 500;
  font-family: "Noto Serif TC", serif;
  border-bottom: 1px solid var(--zh-gold-light);
  padding-bottom: 0.2rem;
  flex: 1;
}

/* Grid */
.bazi-form .grid {
  display: grid;
  gap: 0.9rem;
  position: relative;
  z-index: 1;
}
.bazi-form .grid-date { grid-template-columns: repeat(3, 1fr); }
.bazi-form .grid-time { grid-template-columns: 1fr 1fr 1.6fr; align-items: end; }
.bazi-form .grid-place { grid-template-columns: 2fr 1fr; }

.bazi-form label {
  display: flex;
  flex-direction: column;
  font-size: 0.88rem;
  color: var(--zh-ink-light);
  letter-spacing: 0.25em;
  font-weight: 500;
  font-family: "Noto Serif TC", serif;
}

/* 下拉框（宣紙宋體版） */
.bazi-form select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  margin-top: 0.4rem;
  padding: 0.7rem 2.2rem 0.7rem 0.9rem;
  border: 1px solid var(--zh-line);
  border-radius: 2px;
  background-color: var(--zh-paper);
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M0 0 L5 6 L10 0 Z' fill='%23b08a4a'/%3E%3C/svg%3E");
  background-position: right 0.9rem center;
  background-repeat: no-repeat;
  background-size: 10px 6px;
  font-size: 1rem;
  color: var(--zh-ink);
  font-family: "Noto Serif TC", serif;
  letter-spacing: 0.1em;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s, background-color 0.15s;
}
.bazi-form select:hover {
  border-color: var(--zh-gold);
  background-color: #fff9e8;
}
.bazi-form select:focus {
  outline: none;
  border-color: var(--zh-red);
  background-color: #fff9e8;
  box-shadow: 0 0 0 2px rgba(184, 58, 58, 0.12);
}

/* 真太陽時 toggle（石青邊框版） */
.bazi-form .toggle {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
  padding: 0.7rem 0.9rem;
  margin-top: 0.4rem;
  background: #f0ecdc;
  border: 1px solid var(--zh-cyan-pale);
  border-radius: 2px;
  font-size: 0.88rem;
  color: var(--zh-ink);
  letter-spacing: 0.15em;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
  font-family: "Noto Serif TC", serif;
}
.bazi-form .toggle:hover {
  background: #e8e2ce;
  border-color: var(--zh-cyan);
}
.bazi-form .toggle input {
  accent-color: var(--zh-red);
  width: 15px;
  height: 15px;
  margin: 0;
  cursor: pointer;
}

/* 送出按鈕（朱砂匾額版） */
.submit-row {
  margin-top: 2rem;
  text-align: center;
  position: relative;
  z-index: 1;
}
.btn-primary.btn-zh {
  display: inline-flex;
  align-items: center;
  gap: 0.9rem;
  padding: 0.95rem 2.8rem;
  background: linear-gradient(180deg, var(--zh-red) 0%, var(--zh-red-deep) 100%);
  color: #fdf2e0;
  border: 2px solid var(--zh-gold);
  border-radius: 2px;
  font-size: 1.15rem;
  letter-spacing: 0.3em;
  font-weight: 500;
  cursor: pointer;
  font-family: "ZCOOL XiaoWei", "Noto Serif TC", serif;
  box-shadow:
    inset 0 0 0 1px rgba(253, 242, 224, 0.3),
    0 2px 0 var(--zh-red-deep),
    0 4px 14px rgba(140, 40, 40, 0.2);
  transition: transform 0.1s, box-shadow 0.1s, background 0.15s;
  position: relative;
}
.btn-primary.btn-zh .btn-flourish {
  color: var(--zh-gold-light);
  font-size: 0.9rem;
  letter-spacing: 0;
  opacity: 0.9;
}
.btn-primary.btn-zh .btn-text { letter-spacing: 0.35em; }
.btn-primary.btn-zh:hover {
  transform: translateY(-1px);
  background: linear-gradient(180deg, #c94545 0%, var(--zh-red) 100%);
  box-shadow:
    inset 0 0 0 1px rgba(253, 242, 224, 0.35),
    0 3px 0 var(--zh-red-deep),
    0 6px 18px rgba(140, 40, 40, 0.28);
}
.btn-primary.btn-zh:active {
  transform: translateY(1px);
  box-shadow:
    inset 0 0 0 1px rgba(253, 242, 224, 0.25),
    0 1px 0 var(--zh-red-deep),
    0 2px 6px rgba(140, 40, 40, 0.2);
}

/* 響應式 */
@media (max-width: 640px) {
  .form-card.zh-card { padding: 2.2rem 1.2rem 1.8rem; }
  .meander-border { left: 8px; right: 8px; }
  .corner-cloud { width: 26px; height: 26px; }
  .zh-title-main { font-size: 1.45rem; }
  .zh-title-sub { font-size: 0.8rem; letter-spacing: 0.3em; }
  .zh-title-line { flex-basis: 30px; }
  .zh-seal { width: 32px; height: 32px; font-size: 1.15rem; }
  .sect-label { font-size: 0.92rem; letter-spacing: 0.15em; }
  .bazi-form .grid-date,
  .bazi-form .grid-time,
  .bazi-form .grid-place {
    grid-template-columns: 1fr 1fr;
  }
  .bazi-form .grid-time .toggle { grid-column: 1 / -1; }
  .btn-primary.btn-zh { padding: 0.85rem 1.8rem; font-size: 1rem; }
  .btn-primary.btn-zh .btn-text { letter-spacing: 0.2em; }
}

/* ========== Result ========== */
.hidden { display: none; }
.summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
}
.summary .item {
  border-left: 3px solid var(--gold);
  padding-left: 0.8rem;
}
.summary .label { font-size: 0.8rem; color: var(--ink-light); letter-spacing: 0.1em; }
.summary .value { font-size: 1.15rem; color: var(--ink); font-weight: 500; margin-top: 0.2rem; }

/* ========== 四柱 Table ========== */
.pillars-wrap { overflow-x: auto; }
.pillars {
  width: 100%;
  border-collapse: collapse;
  text-align: center;
  margin-bottom: 1rem;
  font-size: 0.95rem;
}
.pillars th, .pillars td {
  padding: 0.6rem 0.4rem;
  border: 1px solid var(--border);
}
.pillars thead th {
  background: linear-gradient(180deg, #3a2f24, #5a4a38);
  color: #f4ecd8;
  font-weight: 500;
  letter-spacing: 0.1em;
}
.pillars tbody th {
  background: #f4ede0;
  text-align: center;
  font-weight: 500;
  color: var(--ink-light);
  width: 90px;
}
.pillars .big {
  font-size: 2rem;
  font-weight: 500;
  padding: 0.5rem 0;
}
.pillars .canggan-cell { font-size: 0.85rem; line-height: 1.4; }
.pillars .canggan-cell .g { display: inline-block; margin: 0 2px; padding: 1px 4px; border-radius: 3px; background: #faf4e8; }
.pillars .day-master { background: #fff5e4; }
.pillars .day-master .big { color: var(--red); }

/* 五行顏色 */
.wx-木 { color: var(--wx-mu); }
.wx-火 { color: var(--wx-huo); }
.wx-土 { color: var(--wx-tu); }
.wx-金 { color: var(--wx-jin); }
.wx-水 { color: var(--wx-shui); }

.shishen-tag {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 0.8rem;
  background: #f4ede0;
  color: var(--ink);
  margin: 1px;
}
.shishen-tag.day { background: var(--red); color: #fff; }

.note { color: var(--ink-light); font-size: 0.85rem; margin-top: 0.5rem; line-height: 1.6; }

/* ========== 五行 Chart ========== */
.wuxing-chart {
  display: flex;
  align-items: flex-end;
  justify-content: space-around;
  gap: 1rem;
  height: 200px;
  padding: 1rem;
  background: #fdfaf2;
  border-radius: 4px;
}
.wx-bar {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
}
.wx-bar .bar {
  width: 100%;
  max-width: 60px;
  border-radius: 4px 4px 0 0;
  position: relative;
  min-height: 4px;
  transition: height 0.6s ease-out;
}
.wx-bar .bar-label {
  position: absolute;
  top: -1.5rem;
  width: 100%;
  text-align: center;
  font-size: 0.8rem;
  color: var(--ink-light);
}
.wx-bar .name { margin-top: 0.5rem; font-size: 1rem; font-weight: 500; }
.wx-bar.mu .bar { background: var(--wx-mu); }
.wx-bar.huo .bar { background: var(--wx-huo); }
.wx-bar.tu .bar { background: var(--wx-tu); }
.wx-bar.jin .bar { background: var(--wx-jin); }
.wx-bar.shui .bar { background: var(--wx-shui); }

.wuxing-analysis { margin-top: 1rem; }
.wuxing-analysis .row { margin: 0.3rem 0; color: var(--ink-light); }
.wuxing-analysis strong { color: var(--ink); }

/* ========== 大運 / 流年 ========== */
.dayun-wrap, .liunian-wrap { overflow-x: auto; }
.dayun, .liunian {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  text-align: center;
}
.dayun th, .dayun td,
.liunian th, .liunian td {
  border: 1px solid var(--border);
  padding: 0.5rem 0.3rem;
}
.dayun thead th,
.liunian thead th {
  background: #3a2f24;
  color: #f4ecd8;
  font-weight: 400;
  letter-spacing: 0.05em;
}
.dayun .big, .liunian .big { font-size: 1.1rem; font-weight: 500; }
.dayun tbody tr:hover,
.liunian tbody tr:hover { background: #fdf9f0; }
.liunian .current { background: #fff5e4 !important; font-weight: 500; }

/* ========== 解釋面板（古文 + 白話） ========== */
.explain-panel {
  margin-top: 1.2rem;
  border-top: 1px dashed var(--border);
  padding-top: 0.8rem;
}
.explain-panel summary {
  cursor: pointer;
  padding: 0.5rem 0.8rem;
  background: #faf4e8;
  border-radius: 4px;
  color: var(--gold);
  font-size: 0.92rem;
  letter-spacing: 0.1em;
  list-style: none;
  user-select: none;
  transition: background 0.15s;
}
.explain-panel summary::-webkit-details-marker { display: none; }
.explain-panel summary:hover { background: #f4ede0; }
.explain-panel[open] summary {
  background: linear-gradient(90deg, #3a2f24, #5a4a38);
  color: var(--gold-light);
}
.explain-body {
  padding: 1rem 0.2rem;
}
.explain-section-title {
  margin: 1.2rem 0 0.6rem;
  padding-bottom: 0.3rem;
  font-size: 1rem;
  font-weight: 500;
  color: var(--gold);
  border-bottom: 1px dotted var(--gold-light);
  letter-spacing: 0.1em;
}
.explain-section-title:first-child { margin-top: 0; }
.explain-entry {
  margin: 0.6rem 0 1rem;
  padding: 0.7rem 0.9rem;
  background: #fdfaf2;
  border-left: 3px solid var(--gold-light);
  border-radius: 0 4px 4px 0;
}
.explain-term {
  font-size: 1.25rem;
  font-weight: 500;
  letter-spacing: 0.1em;
  margin-bottom: 0.4rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
}
.explain-tag {
  font-size: 0.72rem;
  font-weight: 400;
  padding: 2px 6px;
  background: #f4ede0;
  color: var(--ink-light);
  border-radius: 3px;
  letter-spacing: 0.05em;
}
.explain-classic {
  font-size: 0.88rem;
  color: #6a5a44;
  line-height: 1.7;
  margin-bottom: 0.3rem;
  padding-left: 0.2rem;
  font-family: "Noto Serif TC", "PingFang TC", serif;
  font-style: italic;
}
.explain-vernacular {
  font-size: 0.92rem;
  color: var(--ink);
  line-height: 1.75;
  padding-left: 0.2rem;
}

/* ========== Footer ========== */
.site-footer {
  text-align: center;
  margin: 2rem 0 1rem;
  color: var(--ink-light);
  font-size: 0.85rem;
}
.site-footer a { color: var(--gold); text-decoration: none; }
.site-footer a:hover { text-decoration: underline; }
.disclaimer { color: #a09580; font-style: italic; margin-top: 0.5rem; }

@media (max-width: 600px) {
  .site-header h1 { font-size: 1.3rem; letter-spacing: 0.2em; }
  .card { padding: 1rem; }
  .pillars .big { font-size: 1.5rem; }
  .summary { grid-template-columns: 1fr 1fr; }
}
