:root {
  --bg: #f4efe7;
  --bg-soft: #fbf8f3;
  --card: rgba(255, 250, 244, 0.9);
  --card-strong: #fffaf4;
  --border: #ddcfbe;
  --border-strong: #bfa58a;
  --text: #201915;
  --sub: #6f6258;
  --primary: #3f271d;
  --primary-2: #714832;
  --primary-light: #ede2d4;
  --accent: #c08a42;
  --accent-soft: #f2dec3;
  --radius: 18px;
  --radius-sm: 12px;
  --header-h: 64px;
  --tab-h: 64px;
  --shadow: 0 18px 40px rgba(74, 43, 27, 0.10);
  --fs-hero: clamp(2.1rem, 5vw, 2.5rem);
  --fs-title: clamp(1.02rem, 2.2vw, 1.15rem);
  --fs-body: 0.94rem;
  --fs-body-sm: 0.84rem;
  --fs-caption: 0.76rem;
  --fs-micro: 0.68rem;
  --lh-body: 1.7;
  --lh-tight: 1.45;

  --mu-bg: #E6F2E8; --mu-text: #1A5230; --mu-border: #80C49A;
  --huo-bg: #FAE8E8; --huo-text: #8B1F1F; --huo-border: #CC7878;
  --tu-bg: #F5ECDA; --tu-text: #7A4E10; --tu-border: #B87C30;
  --jin-bg: #fdf1d6; --jin-text: #f3a633; --jin-border: #ffbe30;
  --shui-bg: #E6EEF8; --shui-text: #0A3060; --shui-border: #4A88C0;
}

:root { color-scheme: light; }
* { box-sizing: border-box; margin: 0; padding: 0; }

html {
  height: 100%;
  font-size: 17px;
}
body {
  height: 100%;
}
body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background:
    radial-gradient(circle at top left, rgba(192, 138, 66, 0.18), transparent 32%),
    radial-gradient(circle at top right, rgba(113, 72, 50, 0.16), transparent 28%),
    linear-gradient(180deg, #f8f3ec 0%, #f4efe7 45%, #efe6da 100%);
  color: var(--text);
  font-family: "Noto Serif SC", "Source Han Serif SC", "Songti SC", "PingFang SC", serif;
}

/* ── Header ── */
header {
  flex-shrink: 0;
  height: var(--header-h);
  background:
    linear-gradient(135deg, rgba(255,255,255,0.08), transparent 45%),
    linear-gradient(180deg, #4b3024 0%, #351f17 100%);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 10px 24px rgba(40, 20, 12, 0.22);
  border-bottom: 1px solid rgba(255,255,255,0.1);
  z-index: 10;
}
header h1 { font-size: var(--fs-title); font-weight: 700; letter-spacing: 0.16em; }
header h1 i { font-size: 0.95rem; color: #e4c79e; margin-right: 6px; }

/* ── Pages wrap ── */
.pages-wrap {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
}
.page {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  display: none;
}
.page.active { display: block; }
#page-wenbu { flex-direction: column; overflow: hidden; }
#page-wenbu.active { display: flex; }

/* ── Tab bar ── */
.tab-bar {
  flex-shrink: 0;
  height: var(--tab-h);
  background: rgba(255, 248, 241, 0.94);
  border-top: 1px solid rgba(191, 165, 138, 0.6);
  box-shadow: 0 -8px 24px rgba(62, 35, 20, 0.08);
  backdrop-filter: blur(16px);
  display: flex;
  z-index: 10;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border: none;
  background: none;
  color: #8a7668;
  cursor: pointer;
  font-size: var(--fs-micro);
  letter-spacing: 0.03em;
  font-weight: 600;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.15s;
}
.tab-btn i { font-size: 1.18rem; }
.tab-btn.active { color: var(--primary); }
.tab-btn.active i { font-weight: 900; }

/* ── Container ── */
.container { max-width: 620px; margin: 0 auto; padding: 18px 16px 28px; }

/* ── Card ── */
.card {
  background: var(--card);
  border: 1px solid rgba(221, 207, 190, 0.9);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}
.card-title {
  font-size: var(--fs-caption);
  font-weight: 700;
  color: var(--sub);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 14px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(221, 207, 190, 0.8);
  display: flex;
  align-items: center;
  gap: 8px;
}
.card-title i { font-size: 0.95rem; color: var(--accent); flex-shrink: 0; }
.card-title-main {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.form-intro {
  padding: 14px 16px;
  margin-bottom: 16px;
  border-radius: 16px;
  background:
    linear-gradient(135deg, rgba(192, 138, 66, 0.16), rgba(255,255,255,0.55)),
    linear-gradient(180deg, rgba(255,255,255,0.7), rgba(255,255,255,0.35));
  border: 1px solid rgba(191, 165, 138, 0.5);
}
.form-intro-kicker {
  font-size: var(--fs-micro);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--primary-2);
  font-weight: 700;
  margin-bottom: 6px;
}
.form-intro p {
  font-size: var(--fs-body-sm);
  line-height: var(--lh-body);
  color: var(--sub);
}

/* ── Empty state ── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 88px 28px 48px;
  color: var(--sub);
  text-align: center;
}
.empty-state i {
  font-size: 2.6rem;
  color: var(--accent);
  opacity: 0.85;
  width: 68px;
  height: 68px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(255, 250, 244, 0.8);
  border: 1px solid rgba(191, 165, 138, 0.45);
  box-shadow: var(--shadow);
}
.empty-state p { font-size: var(--fs-body); line-height: var(--lh-body); }
.empty-state strong { color: var(--primary); font-weight: 700; }
.empty-state .hint { font-size: var(--fs-body-sm); opacity: 0.7; }

/* ── Form ── */
.form-row { margin-bottom: 13px; }
label { display: block; font-size: var(--fs-caption); color: var(--sub); margin-bottom: 7px; letter-spacing: 0.06em; }

input[type="text"], input[type="number"], select {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid rgba(191, 165, 138, 0.65);
  border-radius: 12px;
  font-size: var(--fs-body);
  background: rgba(255,255,255,0.88);
  color: var(--text);
  -webkit-appearance: none;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s, transform 0.2s;
}
input:focus, select:focus {
  border-color: var(--primary-2);
  box-shadow: 0 0 0 4px rgba(192, 138, 66, 0.14);
  transform: translateY(-1px);
}
input:disabled {
  background: rgba(237, 226, 212, 0.75);
  color: #8f7b6e;
}

.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }

.toggle-group { display: flex; gap: 8px; }
.toggle-btn {
  flex: 1;
  padding: 11px;
  border: 1px solid rgba(191, 165, 138, 0.6);
  border-radius: 12px;
  background: rgba(255,255,255,0.58);
  font-size: var(--fs-body);
  color: var(--sub);
  cursor: pointer;
  text-align: center;
  transition: all 0.2s;
  -webkit-tap-highlight-color: transparent;
}
.toggle-btn.active {
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  border-color: var(--primary);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 10px 20px rgba(63, 39, 29, 0.18);
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  font-size: var(--fs-body-sm);
  color: var(--sub);
}
.check-row input[type="checkbox"] { width: 16px; height: 16px; cursor: pointer; }

.btn-submit {
  width: 100%;
  padding: 14px;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: var(--fs-body);
  font-weight: 600;
  letter-spacing: 0.1em;
  cursor: pointer;
  box-shadow: 0 14px 28px rgba(63, 39, 29, 0.2);
  transition: opacity 0.2s, transform 0.2s;
  -webkit-tap-highlight-color: transparent;
}
.btn-submit:active { opacity: 0.9; transform: translateY(1px); }
.btn-submit:disabled { opacity: 0.5; cursor: not-allowed; }

.error-msg {
  background: #fff1ef;
  border: 1px solid #df8d82;
  border-radius: 12px;
  padding: 11px 14px;
  color: #7a1818;
  font-size: var(--fs-body-sm);
  margin-bottom: 14px;
  display: none;
}

/* ── Chart Hero ── */
.chart-hero {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 14px;
  margin-bottom: 10px;
  border: 1px solid rgba(191, 165, 138, 0.45);
  border-radius: 16px;
  background:
    radial-gradient(circle at top right, rgba(192, 138, 66, 0.18), transparent 36%),
    linear-gradient(135deg, rgba(255,255,255,0.84), rgba(237, 226, 212, 0.56));
}
.chart-ri-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex-shrink: 0;
}
.chart-ri-char {
  width: 58px; height: 58px;
  border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  font-size: 2rem; font-weight: 700;
  border-width: 2px; border-style: solid;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.6);
  cursor: pointer;
}
.chart-ri-meta { flex: 1; min-width: 0; }
.chart-birth-primary {
  display: block;
  font-size: var(--fs-body-sm);
  font-weight: 700;
  color: var(--text);
  margin-bottom: 2px;
  line-height: 1.45;
}
.chart-birth-secondary {
  font-size: var(--fs-caption);
  color: var(--sub);
  line-height: 1.55;
}
.chart-wx-label {
  display: none;
  font-size: var(--fs-micro);
  color: var(--primary-2);
  background: rgba(255,255,255,0.72);
  border: 1px solid rgba(191, 165, 138, 0.45);
  border-radius: 999px;
  padding: 3px 9px;
  letter-spacing: 0.08em;
  line-height: 1.3;
}
.chart-birth-secondary .sep {
  color: rgba(111, 98, 88, 0.45);
  margin: 0 6px;
}
.form-card-collapsed {
  padding-top: 14px;
  padding-bottom: 14px;
}
.form-card-collapsed .card-title {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}

/* ── Strength (compact) ── */
/* ── 五行能量 toggle switches ── */
.wx-switches { display: flex; align-items: center; gap: 14px; }
.wx-sw-row {
  display: flex; align-items: center; gap: 6px;
  cursor: pointer; user-select: none;
}
.wx-sw-text { font-size: var(--fs-micro); color: var(--sub); }
.wx-sw-track {
  width: 34px; height: 19px; border-radius: 9.5px;
  background: rgba(191,165,138,0.28);
  position: relative; flex-shrink: 0;
  transition: background 0.22s;
}
.wx-sw-track.on { background: var(--primary); }
.wx-sw-knob {
  position: absolute; width: 15px; height: 15px; border-radius: 50%;
  background: #fff; top: 2px; left: 2px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.22);
  transition: transform 0.22s;
}
.wx-sw-track.on .wx-sw-knob { transform: translateX(15px); }

.strength-section {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 8px;
  white-space: nowrap;
  overflow: visible;
  line-height: 1;
}
.strength-main,
.strength-yong {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 6px;
  margin-bottom: 0;
  min-width: 0;
}
.strength-yong {
  font-size: 0.74rem;
  color: var(--sub);
}
.strength-yong-label {
  display: inline-flex;
  align-items: center;
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1;
  color: var(--sub);
}
.strength-sep {
  display: inline-flex;
  align-items: center;
  font-size: 0.72rem;
  line-height: 1;
  color: var(--border);
}

/* ── Pillars table ── */
.pillars-wrap { overflow: visible; }
.pillars-table {
  width: 100%;
  border-collapse: collapse;
  text-align: center;
  font-size: var(--fs-body-sm);
  table-layout: fixed;
}
.pillars-table th,
.liuyun-table th {
  font-size: var(--fs-caption);
  color: var(--sub);
  font-weight: 600;
  padding: 7px 4px;
  border-bottom: 2px solid var(--border);
  letter-spacing: 0.05em;
  text-align: center;
}
.pillars-table td,
.liuyun-table td {
  padding: 8px 4px;
  vertical-align: middle;
  border-bottom: 1px solid var(--border);
  font-size: var(--fs-body-sm);
}
.pillars-table tbody th:first-child,
.pillars-table tbody td:first-child,
.liuyun-table tbody th:first-child,
.liuyun-table tbody td:first-child {
  width: 32px;
  min-width: 32px;
  max-width: 32px;
  padding-left: 0;
  padding-right: 10px;
  text-align: left !important;
}
.pillars-table th:first-child,
.liuyun-table th:first-child {
  width: 32px;
  min-width: 32px;
}
.pillars-row-label,
.liuyun-row-label {
  font-size: var(--fs-micro) !important;
  color: var(--sub);
  font-weight: 600;
  text-align: left !important;
  padding-left: 0 !important;
  padding-right: 10px !important;
  white-space: nowrap;
  width: 32px;
  min-width: 32px;
  border-bottom: none !important;
}
.ss-pillar-meaning {
  display: block;
  font-size: 0.66rem;
  color: var(--sub);
  margin-top: 2px;
  line-height: 1.45;
}
.pillars-meaning-hidden .ss-pillar-meaning { display: none; }
.pillar-meaning-btn {
  font-size: var(--fs-micro);
  padding: 3px 10px;
  border-radius: 6px;
  border: 1px solid #ccc;
  background: transparent;
  color: var(--sub);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.pillar-meaning-btn:hover { background: var(--border); }
.pillar-meaning-btn.on { background: var(--border); color: var(--text); }
.pillar-col-year th, .pillar-col-year td { background: rgba(237, 230, 219, 0.72); }
.pillar-col-day  th, .pillar-col-day  td { background: rgba(242, 222, 195, 0.34); }
.char-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px; height: 36px;
  border-radius: 8px;
  font-size: 1.18rem;
  font-weight: 700;
  border: 1px solid transparent;
  margin-right: 6px;
}
.char-badge:last-child { margin-right: 0; }
.char-badge.mu  { background: var(--mu-bg);   color: var(--mu-text);   border-color: var(--mu-border); }
.char-badge.huo { background: var(--huo-bg);  color: var(--huo-text);  border-color: var(--huo-border); }
.char-badge.tu  { background: var(--tu-bg);   color: var(--tu-text);   border-color: var(--tu-border); }
.char-badge.jin { background: var(--jin-bg);  color: var(--jin-text);  border-color: var(--jin-border); }
.char-badge.shui{ background: var(--shui-bg); color: var(--shui-text); border-color: var(--shui-border); }

.shi-shen-tag { display: inline-block; font-size: var(--fs-caption); color: var(--sub); margin-top: 3px; line-height: 1.35; }

/* Tooltip */
[data-tip] {
  position: relative;
  cursor: help;
  text-decoration: underline dotted var(--border);
  text-underline-offset: 2px;
  white-space: pre;
}
[data-tip]::before {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 7px);
  left: 50%;
  transform: translateX(-50%);
  background: #162030ee;
  color: #fff;
  padding: 5px 10px;
  border-radius: 7px;
  font-size: var(--fs-micro);
  white-space: pre;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 200;
  font-weight: normal;
  text-decoration: none;
}
[data-tip]::after {
  content: '';
  position: absolute;
  bottom: calc(100% + 1px);
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: #162030ee;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 200;
}
[data-tip]:hover::before, [data-tip]:hover::after,
[data-tip].tip-active::before, [data-tip].tip-active::after { opacity: 1; }

.cang-gan { font-size: var(--fs-caption); color: var(--sub); line-height: 1.7; }
.cang-gan-gan,
.cang-gan-ss { font-size: inherit; line-height: inherit; }
.pillars-table .cang-gan,
.pillars-table .zhang-sheng,
.pillars-table .shi-shen-tag,
.liuyun-table .cang-gan,
.liuyun-table .zhang-sheng,
.liuyun-table .shi-shen-tag {
  font-size: var(--fs-body-sm);
}
.pillars-table .char-badge,
.liuyun-table .char-badge {
  width: 40px;
  height: 40px;
  font-size: 1.28rem;
}
.zhang-sheng { font-size: var(--fs-caption); color: var(--sub); }

.ri-zhu-label {
  display: inline-block;
  font-size: var(--fs-micro);
  background: var(--primary-light);
  color: var(--primary);
  border-radius: 4px;
  padding: 1px 5px;
  margin-top: 2px;
}

/* ── Relations ── */
.relations-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 4px;
}
.relation-item {
  background: rgba(255,255,255,0.56);
  border: 1px solid rgba(191, 165, 138, 0.35);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: var(--fs-body-sm);
}
.relation-label { font-size: var(--fs-micro); font-weight: 600; color: var(--sub); margin-bottom: 3px; }
.relation-none { color: var(--sub); font-size: var(--fs-body-sm); }

/* ── Da Yun ── */
.liuyun-calendar-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.liuyun-nav-btn,
/* 原局论断 */
.analyze-placeholder {
  font-size: var(--fs-body-sm);
  color: var(--sub);
  padding: 4px 0 2px;
}

/* 原局论断 grid */
.analysis-grid {
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.analysis-domain {
  border-left: 3px solid var(--primary);
  padding-left: 12px;
}
.analysis-domain-header {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.analysis-domain-header i {
  color: var(--primary);
  font-size: var(--fs-body-sm);
}
.analysis-domain-title {
  font-weight: 600;
  font-size: var(--fs-body);
  color: var(--text);
}
.analysis-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-left: 4px;
}
.analysis-tag {
  font-size: var(--fs-micro);
  padding: 2px 8px;
  border-radius: 20px;
  font-weight: 500;
}
.analysis-tag-good    { background: rgba(74,222,128,.15); color: #16a34a; }
.analysis-tag-warn    { background: rgba(251,191,36,.15);  color: #b45309; }
.analysis-tag-neutral { background: rgba(148,163,184,.15); color: var(--sub); }
.analysis-lines {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.analysis-line {
  font-size: var(--fs-body-sm);
  color: var(--text);
  line-height: 1.7;
  margin: 0;
}

.liuyun-today-btn {
  flex-shrink: 0;
  background: none;
  border: 1px solid var(--border);
  color: var(--sub);
  border-radius: 8px;
  padding: 5px 12px;
  font-size: var(--fs-body-sm);
  cursor: pointer;
  font-family: inherit;
  line-height: 1;
  white-space: nowrap;
}
.liuyun-nav-btn {
  width: 36px;
  height: 36px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.liuyun-nav-btn-year {
  width: 40px;
}
.liuyun-month-label {
  flex: 1;
  text-align: center;
  font-size: var(--fs-body);
  font-weight: 700;
  letter-spacing: 0.02em;
}
.liuyun-nav-btn:hover,
.liuyun-today-btn:hover { border-color: var(--primary); color: var(--primary); }
.liuyun-calendar {
  margin-bottom: 12px;
  padding: 10px;
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(255, 251, 246, 0.95), rgba(249, 241, 231, 0.9));
  border: 1px solid rgba(191, 165, 138, 0.35);
}
.liuyun-calendar-loading {
  min-height: 140px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--sub);
  font-size: var(--fs-body-sm);
}
.liuyun-weekdays,
.liuyun-days {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
}
.liuyun-weekdays {
  margin-bottom: 8px;
}
.liuyun-weekdays span {
  text-align: center;
  font-size: var(--fs-micro);
  color: var(--sub);
  font-weight: 700;
  letter-spacing: 0.04em;
}
.liuyun-day {
  min-height: 72px;
  border: 1px solid rgba(191, 165, 138, 0.38);
  border-radius: 14px;
  background: rgba(255,255,255,0.78);
  padding: 8px 7px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: stretch;
  text-align: left;
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
  transition: border-color 0.18s ease, transform 0.18s ease, box-shadow 0.18s ease;
  -webkit-tap-highlight-color: transparent;
}
.liuyun-day:hover {
  border-color: var(--border-strong);
  transform: translateY(-1px);
  box-shadow: 0 10px 18px rgba(62, 35, 20, 0.06);
}
.liuyun-day.empty {
  min-height: 72px;
  border: none;
  background: transparent;
  padding: 0;
  cursor: default;
  box-shadow: none;
}
.liuyun-day-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 6px;
}
.liuyun-day-num {
  font-size: var(--fs-body);
  font-weight: 700;
  line-height: 1;
}
.liuyun-day-month {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 18px;
  padding: 0 6px;
  border-radius: 999px;
  background: rgba(215, 156, 82, 0.14);
  color: var(--primary);
  font-size: 0.62rem;
  font-weight: 700;
  line-height: 1;
}
.liuyun-day-gz {
  font-size: var(--fs-caption);
  color: var(--sub);
  line-height: 1.2;
}
/* 每日运势着色（放在 is-selected 前，确保选中状态优先级更高） */
.liuyun-day.fortune-da-ji    { background: rgba(74,222,128,.20);  border-color: rgba(74,222,128,.45); }
.liuyun-day.fortune-ji       { background: rgba(74,222,128,.09);  border-color: rgba(74,222,128,.28); }
.liuyun-day.fortune-ping     { background: rgba(251,146,60,.10);  border-color: rgba(251,146,60,.28); }
.liuyun-day.fortune-xiong    { background: rgba(248,113,113,.14); border-color: rgba(248,113,113,.35); }
.liuyun-day.fortune-da-xiong { background: rgba(248,113,113,.26); border-color: rgba(248,113,113,.55); }
.liuyun-day.is-selected {
  border-color: var(--primary);
  background: linear-gradient(180deg, rgba(255, 247, 238, 0.98), rgba(247, 234, 215, 0.92));
  box-shadow: 0 12px 20px rgba(163, 110, 45, 0.12);
}
/* 已选中且有运势色：保留选中背景，用左侧条纹传达运势信息 */
.liuyun-day.fortune-da-ji.is-selected,
.liuyun-day.fortune-ji.is-selected    { box-shadow: inset 3px 0 0 rgba(74,222,128,.75),  0 12px 20px rgba(163,110,45,.12); }
.liuyun-day.fortune-ping.is-selected  { box-shadow: inset 3px 0 0 rgba(251,146,60,.75),  0 12px 20px rgba(163,110,45,.12); }
.liuyun-day.fortune-xiong.is-selected,
.liuyun-day.fortune-da-xiong.is-selected { box-shadow: inset 3px 0 0 rgba(248,113,113,.75), 0 12px 20px rgba(163,110,45,.12); }
.liuyun-day.is-today .liuyun-day-num {
  color: var(--primary);
}

.dayun-toggle {
  margin-left: auto;
  background: rgba(255,255,255,0.78);
  border: 1px solid rgba(191, 165, 138, 0.7);
  color: var(--sub);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: var(--fs-micro);
  line-height: 1.2;
  cursor: pointer;
  font-family: inherit;
}
.dayun-toggle:hover {
  border-color: var(--primary);
  color: var(--primary);
}
.dayun-current { margin-bottom: 8px; }
.dayun-list { margin-top: 4px; }
.dayun-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 12px;
  margin-bottom: 6px;
  font-size: var(--fs-body-sm);
  border: 1px solid transparent;
  background: rgba(255,255,255,0.56);
}
.dayun-item.current {
  background: linear-gradient(135deg, rgba(237, 226, 212, 0.95), rgba(255, 247, 238, 0.98));
  border-color: var(--border-strong);
}
.dayun-gz { font-size: 1rem; font-weight: 700; min-width: 36px; display: flex; gap: 4px; }
.dayun-info { flex: 1; }
.dayun-range { font-size: var(--fs-micro); color: var(--sub); }
.dayun-judge { margin-top: 4px; }
.dayun-judge-label {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: var(--fs-caption);
  font-weight: 600;
  line-height: 1;
  border: 1px solid transparent;
}
.dayun-judge-label.ji {
  background: #e8f4ec;
  color: #1b5c34;
  border-color: #7ec89a;
}
.dayun-judge-label.xiong {
  background: #fde8e8;
  color: #8b1f1f;
  border-color: #d07878;
}
.dayun-judge-label.ping {
  background: #f5edda;
  color: #7a5010;
  border-color: #c89040;
}
.dayun-advice {
  margin-top: 4px;
  font-size: var(--fs-caption);
  color: var(--sub);
  line-height: 1.5;
}
.dayun-advice-label {
  display: inline-flex;
  align-items: center;
  margin-right: 4px;
  font-size: var(--fs-micro);
  font-weight: 700;
  color: var(--text);
}
.dayun-advice-sep {
  margin: 0 6px;
  color: var(--border-strong);
}
.dayun-ss    { font-size: var(--fs-caption); color: var(--sub); margin-top: 2px; line-height: 1.45; }
.yuncheng-detail-date {
  font-size: var(--fs-caption);
  color: var(--sub);
  margin-bottom: 10px;
  line-height: 1.6;
}
.yuncheng-detail-body {
  border: 1px solid rgba(191, 165, 138, 0.34);
  border-radius: 14px;
  background: rgba(255,255,255,0.6);
  padding: 12px 13px;
}
.yuncheng-detail-section + .yuncheng-detail-section {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px dashed rgba(191, 165, 138, 0.4);
}
.yuncheng-detail-section-title {
  font-size: var(--fs-micro);
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--sub);
  margin-bottom: 8px;
}
.yuncheng-detail-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}
.yuncheng-detail-tags {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}
.yuncheng-detail-tag {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  padding: 0 7px;
  border-radius: 999px;
  background: rgba(215, 156, 82, 0.12);
  color: var(--primary);
  font-size: var(--fs-micro);
  font-weight: 600;
}
.yuncheng-detail-summary {
  margin-top: 10px;
  font-size: var(--fs-body-sm);
  color: var(--text);
  line-height: 1.7;
}
.yuncheng-detail-advice {
  margin-top: 10px;
  font-size: var(--fs-caption);
  color: var(--sub);
  line-height: 1.6;
}
.yuncheng-breakdown {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.yuncheng-breakdown-item {
  background: rgba(255, 250, 244, 0.72);
  border: 1px solid rgba(191, 165, 138, 0.26);
  border-radius: 12px;
  padding: 10px 11px;
}
.yuncheng-breakdown-head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}
.yuncheng-breakdown-name {
  font-size: var(--fs-micro);
  font-weight: 700;
  color: var(--sub);
}
.yuncheng-breakdown-gz {
  font-size: var(--fs-caption);
  font-weight: 600;
  color: var(--text);
}
.yuncheng-breakdown-advice {
  margin-top: 8px;
  font-size: var(--fs-caption);
  color: var(--sub);
  line-height: 1.6;
}
.current-tag {
  font-size: var(--fs-micro);
  background: var(--primary);
  color: #fff;
  border-radius: 4px;
  padding: 2px 6px;
}

/* ── Liu Nian ── */
.liu-nian-box {
  background: var(--bg);
  border-radius: 8px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 14px;
}
.liu-nian-gz   { font-size: 1.2rem; font-weight: 700; }
.liu-nian-info { font-size: var(--fs-body-sm); color: var(--sub); line-height: var(--lh-body); }

/* ── Strength ── */
.strength-badge,
.xi-tag,
.ji-tag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 22px;
  padding: 0 9px;
  border-radius: 20px;
  font-size: var(--fs-caption);
  font-weight: 600;
  line-height: 1;
  border: 1px solid transparent;
  margin-right: 2px;
}
.strength-badge { cursor: pointer; }
.strength-badge,
.strength-badge.qiang,
.strength-badge.zhong,
.strength-badge.ruo {
  background: var(--primary-light);
  color: var(--primary);
  border-color: var(--border-strong);
}

/* ── Shen Sha ── */
.shensha-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.ss-tag {
  display: inline-flex; align-items: center; gap: 3px;
  padding: 3px 9px; border-radius: 20px;
  font-size: var(--fs-caption); cursor: default; position: relative;
}
.ss-tag.ji   { background: #e8f4ec; color: #1b5c34; border: 1px solid #7ec89a; }
.ss-tag.xiong{ background: #fde8e8; color: #8b1f1f; border: 1px solid #d07878; }
.ss-tag.zhong{ background: #f5edda; color: #7a5010; border: 1px solid #c89040; }
.ss-tag.nohit{ opacity: 0.35; filter: grayscale(0.5); }

/* Shen Sha tabs */
.ss-tabs { display: flex; border: 1px solid var(--border); border-radius: 7px; overflow: hidden; margin-left: auto; }
.ss-tab {
  background: var(--card); border: none;
  padding: 4px 11px; font-size: var(--fs-micro); color: var(--sub);
  cursor: pointer; line-height: 1.6;
  -webkit-tap-highlight-color: transparent;
}
.ss-tab:not(:last-child) { border-right: 1px solid var(--border); }
.ss-tab.active { background: var(--primary); color: #fff; font-weight: 600; }

/* ── 流运表格 ── */
.liuyun-table {
  width: 100%;
  border-collapse: collapse;
  text-align: center;
  font-size: var(--fs-body-sm);
  table-layout: fixed;
}
.liuyun-table .shi-shen-tag {
  font-size: var(--fs-body-sm);
  color: var(--text);
}

/* 格局详解 */
.pattern-empty {
  color: var(--sub);
  font-size: var(--fs-body-sm);
  line-height: var(--lh-body);
}
.pattern-summary {
  padding: 14px 15px;
  border: 1px solid rgba(191, 165, 138, 0.5);
  border-radius: 14px;
  background:
    linear-gradient(135deg, rgba(192, 138, 66, 0.12), rgba(255,255,255,0.7)),
    linear-gradient(180deg, rgba(255,255,255,0.75), rgba(255,255,255,0.45));
}
.pattern-summary-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}
.pattern-summary-label {
  font-size: var(--fs-micro);
  color: var(--sub);
  letter-spacing: 0.08em;
}
.pattern-summary-main {
  font-size: var(--fs-body);
  color: var(--primary);
  font-weight: 700;
}
.pattern-summary-text {
  font-size: var(--fs-body-sm);
  line-height: var(--lh-body);
  color: var(--text);
}
.pattern-summary-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}
.pattern-summary-tag,
.pattern-chip {
  display: inline-flex;
  align-items: center;
  padding: 4px 9px;
  border-radius: 999px;
  border: 1px solid rgba(191, 165, 138, 0.58);
  background: rgba(255,255,255,0.72);
  color: var(--primary-2);
  font-size: var(--fs-micro);
  line-height: 1.2;
  white-space: nowrap;
}
.pattern-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
}
.pattern-row {
  padding: 12px 13px;
  border-radius: 14px;
  border: 1px solid rgba(221, 207, 190, 0.9);
  background: rgba(255, 255, 255, 0.72);
}
.pattern-row-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}
.pattern-row-title {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 0;
}
.pattern-row-title strong {
  font-size: var(--fs-body-sm);
  color: var(--text);
}
.pattern-weight {
  flex-shrink: 0;
  font-size: var(--fs-caption);
  color: var(--accent);
  font-weight: 700;
}
.pattern-impact {
  font-size: var(--fs-caption);
  color: var(--sub);
  line-height: 1.7;
}

/* ── Clear button ── */
.pattern-hero,
.pattern-section {
  margin-top: 12px;
  padding: 13px 14px;
  border-radius: 14px;
  border: 1px solid rgba(221, 207, 190, 0.9);
  background: rgba(255, 255, 255, 0.72);
}
.pattern-hero-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}
.pattern-hero-main {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}
.pattern-hero-main strong {
  font-size: 1rem;
  color: var(--text);
}
.pattern-tone {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: var(--fs-caption);
  font-weight: 700;
  border: 1px solid transparent;
}
.pattern-tone.tone-ji {
  background: #e8f4ec;
  color: #1b5c34;
  border-color: #7ec89a;
}
.pattern-tone.tone-xiong {
  background: #fde8e8;
  color: #8b1f1f;
  border-color: #d07878;
}
.pattern-tone.tone-ping {
  background: #f5edda;
  color: #7a5010;
  border-color: #c89040;
}
.pattern-section-title {
  font-size: var(--fs-micro);
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--sub);
  margin-bottom: 8px;
}
.pattern-structure-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.pattern-row-brief {
  margin-top: 0;
}

.btn-clear {
  background: rgba(255,255,255,0.52);
  border: 1px solid rgba(191, 165, 138, 0.7);
  color: var(--sub); border-radius: 12px;
  padding: 10px 18px; font-size: var(--fs-body-sm);
  cursor: pointer; display: block; margin: 4px auto 0;
}
.btn-clear:active { opacity: 0.7; }

/* Spinner */
.spinner {
  display: inline-block; width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,0.4); border-top-color: #fff;
  border-radius: 50%; animation: spin 0.7s linear infinite;
  vertical-align: middle; margin-right: 6px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Disclaimer ── */
.disclaimer {
  text-align: center; font-size: var(--fs-micro); color: var(--sub);
  line-height: 1.85; opacity: 0.78; padding: 16px 16px 8px;
}
.disclaimer strong { font-weight: 600; }

/* ── Chat page ── */
#page-wenbu #chat-header {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(221, 207, 190, 0.85);
  flex-shrink: 0;
  background: rgba(255, 248, 241, 0.92);
  backdrop-filter: blur(16px);
}
#page-wenbu #chat-header h3 { flex: 1; font-size: var(--fs-body); font-weight: 700; }
#page-wenbu #chat-header h3 i { color: var(--accent); margin-right: 6px; }
#chat-suggest-toggle {
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(191, 165, 138, 0.7);
  border-radius: 10px;
  background: rgba(255,255,255,0.88);
  color: var(--sub);
  cursor: pointer;
  flex-shrink: 0;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
#chat-suggest-toggle:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: rgba(255, 250, 244, 0.96);
}
#chat-model-select {
  font-size: var(--fs-micro); border: 1px solid rgba(191, 165, 138, 0.7);
  border-radius: 10px; padding: 6px 8px;
  background: rgba(255,255,255,0.88); color: var(--sub); max-width: 152px;
  display: none;
}
#chat-messages {
  flex: 1; overflow-y: auto;
  padding: 12px 14px;
  display: flex; flex-direction: column; gap: 10px;
  -webkit-overflow-scrolling: touch;
  background: var(--bg);
}
.chat-msg {
  max-width: 88%; padding: 10px 13px;
  border-radius: 16px; font-size: var(--fs-body-sm);
  line-height: var(--lh-body); word-break: break-word; white-space: pre-wrap;
  box-shadow: 0 10px 18px rgba(62, 35, 20, 0.06);
}
.chat-msg.user {
  align-self: flex-end; background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: #fff; border-bottom-right-radius: 4px;
}
.chat-msg.assistant {
  align-self: stretch;
  max-width: none;
  padding: 2px 0 4px;
  background: none;
  border: none;
  border-radius: 0;
  box-shadow: none;
  color: var(--text);
}
.chat-msg.system-hint {
  align-self: center; background: none;
  color: var(--sub); font-size: var(--fs-caption); padding: 2px 0;
}
.chat-msg.assistant.md { white-space: normal; }
.chat-msg.assistant.md p { margin: 0 0 6px; }
.chat-msg.assistant.md p:last-child { margin-bottom: 0; }
.chat-msg.assistant.md ul,
.chat-msg.assistant.md ol { padding-left: 18px; margin: 4px 0 6px; }
.chat-msg.assistant.md li { margin-bottom: 2px; }
.chat-msg.assistant.md strong { font-weight: 700; }
.chat-msg.assistant.md em { font-style: italic; }
.chat-msg.assistant.md code {
  background: #eef2f7; padding: 1px 5px;
  border-radius: 4px; font-size: 0.82em; font-family: monospace;
}
.chat-msg.assistant.md pre {
  background: #1e1e1e; color: #d4d4d4;
  padding: 10px 12px; border-radius: 8px;
  overflow-x: auto; font-size: 0.8em; margin: 6px 0;
}
.chat-msg.assistant.md pre code { background: none; padding: 0; color: inherit; }
.chat-msg.assistant.md h1,
.chat-msg.assistant.md h2,
.chat-msg.assistant.md h3 { font-size: 0.95em; font-weight: 700; margin: 8px 0 4px; }
.chat-msg.assistant.md blockquote {
  border-left: 3px solid var(--border); padding-left: 10px;
  color: var(--sub); margin: 4px 0;
}
.chat-msg.assistant.md hr { border: none; border-top: 1px solid var(--border); margin: 8px 0; }
.chat-assistant-status {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: var(--fs-caption);
  color: var(--sub);
}
.chat-loader { color: var(--sub); font-size: var(--fs-caption); animation: pulse 1.2s ease-in-out infinite; }
.chat-loader.done { animation: none; }
.chat-thinking-timer {
  font-size: var(--fs-caption);
  color: var(--sub);
  font-variant-numeric: tabular-nums;
}
@keyframes pulse { 0%,100%{opacity:.4} 50%{opacity:1} }
.chat-suggestions { display: flex; flex-direction: column; gap: 6px; margin-top: 2px; align-self: flex-start; max-width: 92%; }
.suggestion-btn {
  text-align: left; padding: 7px 12px;
  background: rgba(255, 250, 244, 0.92); border: 1px solid rgba(191, 165, 138, 0.6);
  border-radius: 10px; font-size: var(--fs-body-sm); color: var(--primary);
  cursor: pointer; line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}
.suggestion-btn:active { background: var(--primary-light); }
.preset-questions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  align-self: stretch;
  margin-top: 4px;
}
.preset-btn {
  text-align: left; padding: 8px 11px;
  background: rgba(255, 250, 244, 0.88);
  border: 1px solid rgba(191, 165, 138, 0.5);
  border-radius: 10px; font-size: var(--fs-caption);
  color: var(--sub); cursor: pointer; line-height: 1.5;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.preset-btn:active,
.preset-btn:hover { background: var(--primary-light); color: var(--primary); border-color: var(--border-strong); }
.chat-cursor {
  display: inline-block; width: 2px; height: 1em;
  background: var(--text); margin-left: 1px;
  vertical-align: text-bottom; animation: blink 0.9s step-end infinite;
}
@keyframes blink { 50% { opacity: 0; } }
#chat-input-area {
  display: flex; gap: 8px;
  padding: 10px 12px 12px;
  border-top: 1px solid rgba(221, 207, 190, 0.85);
  flex-shrink: 0;
  background: rgba(255, 248, 241, 0.94);
  backdrop-filter: blur(16px);
}
#chat-input {
  flex: 1; border: 1px solid rgba(191, 165, 138, 0.7);
  border-radius: 14px; padding: 10px 13px;
  font-size: var(--fs-body); resize: none; outline: none;
  font-family: inherit; max-height: 100px; line-height: var(--lh-tight);
  background: rgba(255,255,255,0.92); color: var(--text);
}
#chat-input:focus { border-color: var(--primary-2); box-shadow: 0 0 0 4px rgba(192, 138, 66, 0.12); }
#chat-send {
  background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: #fff;
  border: none; border-radius: 10px;
  width: 40px; cursor: pointer; font-size: 0.95rem;
  flex-shrink: 0; transition: opacity 0.15s;
  -webkit-tap-highlight-color: transparent;
}
#chat-send:disabled { opacity: 0.45; cursor: not-allowed; }

@media (max-width: 640px) {
  html { font-size: 16px; }
  :root {
    --fs-hero: 1.9rem;
    --fs-title: 1rem;
    --fs-body: 0.95rem;
    --fs-body-sm: 0.88rem;
    --fs-caption: 0.8rem;
    --fs-micro: 0.72rem;
  }
  .container { padding: 14px 12px 24px; }
  .card { padding: 16px; }
  .row3 { grid-template-columns: 1fr 1fr 1fr; gap: 6px; }
  .chart-hero { align-items: center; gap: 12px; padding: 10px 12px; }
  .chart-ri-char { width: 52px; height: 52px; font-size: 1.78rem; }
  .card-title { gap: 6px; }
  .check-row { align-items: flex-start; }
  .check-row span { line-height: 1.55; }
  .pillar-meaning-btn { display: none; }
  .char-badge { width: 28px; height: 28px; font-size: 0.96rem; margin-right: 0; border-radius: 6px; }
  .ss-pillar-meaning,
  .reading-comment { padding-left: 0; }
  .ss-pillar-meaning { display: none; }
  .reading-yg-row,
  .liu-nian-box { align-items: flex-start; }
  .strength-meta,
  .dayun-range,
  .dayun-ss,
  .liu-nian-info,
  .chart-birth-secondary { line-height: 1.6; }
  .liuyun-calendar-toolbar { gap: 8px; }
  .dayun-toggle { padding: 4px 9px; }
  .liuyun-month-label { font-size: 0.96rem; }
  .liuyun-calendar { padding: 8px; }
  .yuncheng-detail-top { flex-direction: column; }
  .yuncheng-detail-tags { justify-content: flex-start; }
  .liuyun-weekdays,
  .liuyun-days { gap: 4px; }
  .liuyun-day,
  .liuyun-day.empty { min-height: 60px; }
  .liuyun-day { padding: 7px 6px; border-radius: 12px; }
  .liuyun-day-num { font-size: 0.92rem; }
  .liuyun-day-gz { font-size: 0.72rem; }
  .liuyun-day-month { font-size: 0.58rem; padding: 0 5px; }
  .pattern-summary-top,
  .pattern-row-head { align-items: flex-start; }
  .pattern-summary-main { font-size: var(--fs-body-sm); }
  .pattern-row-title strong { font-size: var(--fs-body); }
  .pattern-impact { font-size: var(--fs-body-sm); }
  .pattern-hero-main strong { font-size: 0.96rem; }
  #page-wenbu #chat-header { padding: 11px 12px; }
  #chat-messages { padding: 12px; }
  #chat-input-area { padding: 10px 10px 12px; }
}
