/* 三师会诊 · 节气色谱
   纸 #F4EDE0 / 墨 #241F1A / 季色由 almanac.js 按节气写入 --field-1/2
   原则：一屏一焦点；色随节气；正文不用卡片堆叠；底部导航。 */

@font-face {
  font-family: "TCM Serif";
  src: url("./fonts/NotoSerifSC-400.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

:root {
  --paper: #F4EDE0;
  --paper-2: #EFE6D5;
  --ink: #241F1A;
  --ink-2: #4A4238;
  --muted: #6F675C;
  --line: rgba(36, 31, 26, .14);
  --line-soft: rgba(36, 31, 26, .08);
  --field-1: #B97A48;
  --field-2: #7A3A1C;
  --field-ink: #F8EFDF;
  --accent: #A8482F;
  --accent-2: #8C3722;
  --r: 18px;
  --r-sm: 14px;
  --serif: "TCM Serif", "Songti SC", "Noto Serif SC", "Source Han Serif SC", "SimSun", serif;
  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Noto Sans CJK SC",
          "Microsoft YaHei", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #191512;
    --paper-2: #221B16;
    --ink: #F2E9DA;
    --ink-2: #C9BEAC;
    --muted: #8E8478;
    --line: rgba(242, 233, 218, .14);
    --line-soft: rgba(242, 233, 218, .08);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.7;
  padding-bottom: calc(84px + env(safe-area-inset-bottom));
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: contain;
  transition: background .5s ease;
}

.reading {
  position: fixed; top: 0; left: 0; right: 0; height: 2px; z-index: 60;
  background: var(--accent);
  transform: scaleX(0); transform-origin: 0 50%;
  transition: transform .12s linear; pointer-events: none;
}

/* ---------- 顶栏 ---------- */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 40;
  height: calc(52px + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 18px 0;
  display: flex; align-items: center; justify-content: space-between;
  background: var(--paper); color: var(--ink);
  border-bottom: 1px solid var(--line-soft);
  transition: background .4s, color .4s;
}
body[data-tab="home"] .topbar {
  background: var(--field-1); color: var(--field-ink);
  border-bottom: 1px solid rgba(255, 255, 255, .16);
}
.brand { display: flex; align-items: center; gap: 9px; }
.brand-mark { width: 28px; height: 28px; border-radius: 8px; box-shadow: 0 0 0 1px rgba(0,0,0,.14), 0 4px 10px -6px rgba(0,0,0,.55); }
.brand-name { font-family: var(--serif); font-size: 15px; letter-spacing: 2.5px; }
.top-actions { display: flex; gap: 2px; }
.iconbtn {
  width: 38px; height: 38px; border: 0; border-radius: 50%; background: none;
  color: inherit; opacity: .82; display: grid; place-items: center; padding: 0;
  transition: opacity .2s, background .2s, transform .12s;
}
.iconbtn svg { width: 19px; height: 19px; }
.iconbtn:active { transform: scale(.92); opacity: 1; background: rgba(127, 127, 127, .14); }
.iconbtn.light { background: var(--paper-2); color: var(--ink); opacity: 1; width: 42px; height: 42px; flex: none; }

main { padding: 0; max-width: 640px; margin: 0 auto; }
.tab { display: none; }
.tab.active { display: block; animation: fade .35s ease both; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

#tab-consult, #tab-chat, #tab-about { padding: calc(52px + env(safe-area-inset-top) + 10px) 22px 0; }

.page-title { font-family: var(--serif); font-size: 30px; font-weight: 400; letter-spacing: 2px; margin: 10px 0 0; }
.page-sub { margin: 8px 0 22px; font-size: 13px; color: var(--muted); }

/* ---------- 今日 · 季色场 ---------- */
.field {
  position: relative; min-height: 52vh;
  padding: calc(52px + env(safe-area-inset-top) + 18px) 24px 84px;
  display: flex; flex-direction: column;
  background: linear-gradient(168deg, var(--field-1) 0%, var(--field-2) 100%);
  color: var(--field-ink); overflow: hidden;
  transition: background .6s ease;
}
.field::before {
  content: ""; position: absolute; inset: 0;
  background:
    radial-gradient(56% 42% at 82% -4%, rgba(255, 244, 219, .30), transparent 62%),
    radial-gradient(42% 36% at 8% 92%, rgba(0, 0, 0, .22), transparent 70%);
}
.field::after {
  content: ""; position: absolute; inset: 0; opacity: .28;
  background-image: repeating-linear-gradient(0deg, rgba(255, 255, 255, .05) 0 1px, transparent 1px 3px);
}
.field > * { position: relative; z-index: 1; }
.field-top { max-width: 62%; }
.term { font-family: var(--serif); font-size: 78px; font-weight: 400; letter-spacing: 12px; line-height: 1; margin: 0; }
.term-tip { margin: 14px 0 0; font-size: 11.5px; line-height: 1.8; color: rgba(248, 239, 223, .8); }

.hou { position: absolute; top: calc(52px + env(safe-area-inset-top) + 44px); right: 24px; text-align: right; z-index: 1; }
.hou div { padding: 7px 0; }
.hou div + div { border-top: 1px solid rgba(248, 239, 223, .16); }
.hou div.now .txt { color: #FBF3E4; }
.hou div.now .lbl { color: rgba(248, 239, 223, .78); }
.hou div.now .lbl::after { content: " ·"; }
.hou .lbl { display: block; font-size: 8px; letter-spacing: 3px; color: rgba(248, 239, 223, .45); margin-bottom: 1px; }
.hou .txt { font-family: var(--serif); font-size: 12px; letter-spacing: 2px; color: rgba(248, 239, 223, .82); }

.field-meta {
  position: absolute; left: 24px; right: 24px; bottom: 58px; z-index: 1;
  display: flex; align-items: flex-end; justify-content: space-between; gap: 14px;
}
.date-block { display: flex; align-items: flex-end; gap: 12px; }
.date { font-family: var(--serif); font-size: 52px; line-height: .92; letter-spacing: 1px; }
.date-side { display: flex; flex-direction: column; gap: 2px; padding-bottom: 6px; font-size: 11px; letter-spacing: 1.5px; color: rgba(248, 239, 223, .82); }
.meta { text-align: right; font-size: 9.5px; line-height: 2; letter-spacing: .8px; color: rgba(248, 239, 223, .72); }
.meta span { display: block; }
.meta .year { color: rgba(248, 239, 223, .45); }

.term-progress {
  position: absolute; left: 24px; right: 24px; bottom: 44px; z-index: 1;
  height: 1px; background: rgba(248, 239, 223, .22);
}
.term-progress i {
  position: relative; display: block; height: 100%; width: 0;
  background: rgba(248, 239, 223, .7); transition: width .9s cubic-bezier(.2,.7,.3,1);
}
.term-progress i::after {
  content: ""; position: absolute; right: -2px; top: -2px; width: 5px; height: 5px;
  border-radius: 50%; background: var(--field-ink);
}
.field-foot {
  position: absolute; left: 24px; right: 24px; bottom: 16px; z-index: 1;
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  padding-top: 10px; border-top: 1px solid rgba(248, 239, 223, .28);
  font-size: 10px; letter-spacing: 1px;
}
.field-foot .quote { font-family: var(--serif); letter-spacing: 1.5px; color: rgba(248, 239, 223, .9); }
.field-foot .next { color: rgba(248, 239, 223, .6); letter-spacing: 1.5px; flex: none; }

/* ---------- 今日 · 纸面 ---------- */
.paper { background: var(--paper); padding: 18px 24px 26px; transition: background .5s; }
.shichen-block { position: relative; }
.now { display: flex; align-items: baseline; gap: 12px; }
.now .shichen { font-family: var(--serif); font-size: 30px; letter-spacing: 4px; }
.now .mer { font-size: 12px; letter-spacing: .5px; color: var(--accent); }
.now .range { margin-left: auto; display: flex; flex-direction: column; align-items: flex-end; gap: 1px; font-size: 9px; color: var(--muted); letter-spacing: .5px; }
.bar { height: 2px; background: var(--line-soft); margin: 11px 0 8px; }
.bar i { display: block; width: 0; height: 100%; background: var(--accent); transition: width .8s cubic-bezier(.2,.7,.3,1); }
.tip { margin: 0; font-size: 11.5px; line-height: 1.8; color: var(--muted); }

.rule { height: 1px; background: var(--line-soft); margin: 16px 0; }

.yiji { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.yiji h4 { font-family: var(--serif); font-size: 14px; letter-spacing: 3px; font-weight: 400; margin: 0 0 6px; }
.yiji .y h4 { color: var(--ink-2); }
.yiji .j h4 { color: var(--accent); }
.yiji ul { list-style: none; margin: 0; padding: 0; }
.yiji li { font-size: 12.5px; line-height: 1.75; color: var(--ink-2); padding: 4px 0; border-bottom: 1px solid var(--line-soft); }
.yiji li:last-child { border-bottom: 0; }

.almanac-meta { margin-top: 10px; font-size: 9px; color: var(--muted); letter-spacing: .8px; display: flex; flex-wrap: wrap; gap: 6px 12px; }

.gua { position: relative; display: flex; align-items: center; gap: 13px; padding-right: 22px; }
.gua .sym { font-family: var(--serif); font-size: 36px; line-height: 1; color: var(--accent); flex: none; }
.gua-info { display: flex; flex-direction: column; gap: 2px; }
.gua-info b { font-family: var(--serif); font-size: 15px; letter-spacing: 2px; font-weight: 400; }
.gua-info span { font-size: 9.5px; color: var(--muted); letter-spacing: .4px; }
.gua-info .nums { color: var(--accent); letter-spacing: 1.5px; }
.gua-note { margin: 10px 0 0; font-size: 9px; line-height: 1.6; color: var(--muted); }
.chev {
  position: absolute; right: 0; top: 50%; transform: translateY(-50%);
  font-family: var(--serif); font-size: 20px; color: var(--muted); pointer-events: none;
}
.tap { cursor: pointer; transition: opacity .15s; }
.tap:active { opacity: .62; }
.disclaimer { margin: 16px 0 0; font-size: 9.5px; color: var(--muted); text-align: center; letter-spacing: .3px; }

/* ---------- 底部导航 ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; align-items: stretch;
  height: calc(64px + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--paper);
  border-top: 1px solid var(--line);
}
.tabbar button {
  flex: 1; border: 0; background: none; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-size: 9.5px; letter-spacing: .5px; transition: color .2s;
}
.tabbar button svg { width: 21px; height: 21px; }
.tabbar button.active { color: var(--accent); }
.tab-indicator {
  position: absolute; top: 0; left: 0; width: 25%; height: 2px;
  background: var(--accent);
  transition: transform .3s cubic-bezier(.4, .1, .2, 1);
}

/* ---------- 会诊 / 表单 ---------- */
textarea, input, select {
  width: 100%; border: 1px solid transparent; border-radius: var(--r-sm);
  padding: 14px; font: inherit; font-size: 15px; color: var(--ink);
  background: var(--paper-2);
  transition: border-color .2s, background .2s;
}
textarea { resize: vertical; min-height: 150px; line-height: 1.8; }
textarea::placeholder, input::placeholder { color: var(--muted); opacity: .75; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); background: var(--paper); }
.field-row { display: flex; gap: 10px; margin-top: 10px; align-items: center; }
.field-row select, .field-row input { flex: 1; padding: 12px; font-size: 14px; }
.lbl { display: block; font-size: 11px; letter-spacing: 1px; color: var(--muted); margin: 14px 0 6px; }

.chip-row { display: flex; align-items: center; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.chip {
  height: 38px; padding: 0 14px; border-radius: 999px;
  background: var(--paper-2); border: 1px solid var(--line-soft);
  color: var(--ink-2); font-size: 13px;
  transition: background .2s, transform .12s;
}
.chip:active { transform: scale(.96); }
.text-btn { border: 0; background: none; padding: 0; font-size: 12px; color: var(--muted); flex: none; }
.text-btn:active { color: var(--accent); }

.primary {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; height: 52px; margin-top: 22px;
  border: 0; border-radius: var(--r-sm);
  background: linear-gradient(160deg, var(--accent), var(--accent-2));
  color: #FFF6EA; font-size: 15px; font-weight: 600; letter-spacing: 2px;
  box-shadow: 0 12px 24px -16px var(--accent);
  transition: transform .12s, filter .2s;
}
.primary:active { transform: scale(.985); filter: brightness(.94); }
.primary.compact { width: auto; height: 42px; margin: 0; padding: 0 18px; font-size: 13px; letter-spacing: 1px; }
.primary:disabled { opacity: .45; }
.ghost {
  height: 44px; padding: 0 18px; border-radius: var(--r-sm);
  background: none; border: 1px solid var(--line);
  color: var(--ink); font-size: 13px; letter-spacing: 1px;
  transition: border-color .2s;
}
.ghost:active { border-color: var(--accent); color: var(--accent); }
.ghost.wide { width: 100%; margin-top: 10px; }
.consult-note { margin: 14px 0 0; font-size: 10.5px; color: var(--muted); letter-spacing: .3px; }
.hint { font-size: 11px; color: var(--muted); line-height: 1.7; margin: 10px 0 0; }

.attachbar { display: flex; gap: 9px; overflow-x: auto; padding: 12px 0 0; }
.attachbar:empty { display: none; }
.attachbar.in-composer {
  position: fixed; left: 0; right: 0; bottom: calc(128px + env(safe-area-inset-bottom));
  padding: 10px 18px; background: var(--paper); border-top: 1px solid var(--line-soft); z-index: 24;
}
.thumb { position: relative; flex: none; width: 70px; height: 70px; border-radius: 12px; overflow: hidden; border: 1px solid var(--line); background: var(--paper-2); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .tag { position: absolute; left: 0; right: 0; bottom: 0; font-size: 8.5px; text-align: center; padding: 2px 0; background: rgba(0,0,0,.55); color: #F4EDE0; }
.thumb .x { position: absolute; top: 3px; right: 3px; width: 19px; height: 19px; border: 0; border-radius: 50%; padding: 0; font-size: 12px; line-height: 19px; background: rgba(0,0,0,.55); color: #fff; }

.progress { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 18px 0 4px; font-size: 12px; color: var(--muted); }
.dots { display: inline-flex; gap: 4px; }
.dots i { width: 4px; height: 4px; border-radius: 50%; background: var(--accent); animation: bounce 1.2s infinite ease-in-out; }
.dots i:nth-child(2) { animation-delay: .15s; }
.dots i:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%,80%,100% { transform: translateY(0); opacity: .3; } 40% { transform: translateY(-4px); opacity: 1; } }

/* ---------- 结果 ---------- */
#result { scroll-margin-top: 60px; }
.rec-head { padding: 26px 0 8px; }
.rec-kicker, .rec-index, .rec-label { display: none; }
.rec-title { font-family: var(--serif); font-size: 24px; font-weight: 400; letter-spacing: 2px; margin: 0; }
.rec-meta { font-size: 10px; color: var(--muted); margin-top: 6px; line-height: 1.7; }
.rec-actions { display: flex; gap: 8px; margin-top: 12px; }
.rec-actions .ghost { height: 32px; padding: 0 13px; font-size: 11px; }

.rec-card {
  background: var(--paper-2); border: 1px solid var(--line-soft);
  border-radius: var(--r); padding: 16px; margin-top: 12px;
  opacity: 0; transform: translateY(10px);
  transition: opacity .6s ease, transform .6s ease;
}
.rec-card.in { opacity: 1; transform: none; }
.rec-card.synthesis { border-color: var(--line); background: var(--paper); }
.rec-name { font-family: var(--serif); font-size: 21px; font-weight: 400; letter-spacing: 2px; margin: 0; }
.rec-tag { font-size: 10px; letter-spacing: 1px; color: var(--muted); margin-top: 3px; }
.rec-sub { margin-top: 15px; display: flex; align-items: baseline; gap: 8px; }
.rec-sub-name { font-family: var(--serif); font-size: 16px; letter-spacing: 1px; }
.rec-sub-tag { font-size: 9px; color: var(--muted); }
.md { font-size: 14.5px; line-height: 1.95; color: var(--ink-2); text-align: justify; text-justify: inter-ideograph; }
.md h3, .md h4 { font-family: var(--serif); font-size: 15.5px; color: var(--ink); margin: 16px 0 6px; font-weight: 400; }
.md p { margin: 7px 0; }
.md ul { margin: 7px 0; padding-left: 18px; }
.md li { margin: 4px 0; }
.md strong { color: var(--ink); font-weight: 600; }
.md hr { border: 0; border-top: 1px solid var(--line-soft); margin: 14px 0; }

/* ---------- 对话 ---------- */
.chips { display: flex; gap: 9px; padding: 4px 0 16px; overflow-x: auto; }
.chips button {
  flex: none; height: 36px; padding: 0 16px; border-radius: 999px;
  border: 1px solid var(--line-soft); background: var(--paper-2); color: var(--ink-2);
  font-size: 13px; transition: all .2s;
}
.chips button.active { background: var(--accent); color: #FFF6EA; border-color: var(--accent); }
.chatlog { min-height: 46vh; padding: 4px 0 6px; }
.msg { max-width: 88%; margin: 14px 0; font-size: 15px; line-height: 1.85; animation: rise .3s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.msg.bot { color: var(--ink-2); }
.msg.user {
  margin-left: auto; background: var(--paper-2); border: 1px solid var(--line-soft);
  border-radius: 18px 18px 6px 18px; padding: 12px 15px; color: var(--ink); max-width: 84%;
}
.msg .who { display: block; font-size: 9px; letter-spacing: 1.6px; color: var(--muted); margin-bottom: 6px; }
.send-attach { display: flex; gap: 7px; flex-wrap: wrap; margin-bottom: 8px; }
.send-attach img { width: 88px; height: 88px; object-fit: cover; border-radius: 10px; }
.typing { display: inline-flex; gap: 4px; padding: 6px 0; }
.typing i { width: 4px; height: 4px; border-radius: 50%; background: var(--muted); animation: bounce 1.1s infinite ease-in-out; }
.typing i:nth-child(2) { animation-delay: .14s; }
.typing i:nth-child(3) { animation-delay: .28s; }

.chat-empty { padding: 38px 0 10px; }
.chat-empty .quote { font-family: var(--serif); font-size: 24px; letter-spacing: 6px; margin: 0 0 10px; color: var(--accent); }
.chat-empty p { margin: 14px 0 0; font-size: 13.5px; color: var(--ink-2); max-width: 28em; }

.composer {
  position: fixed; left: 0; right: 0; bottom: calc(64px + env(safe-area-inset-bottom)); z-index: 25;
  display: flex; align-items: flex-end; gap: 8px;
  padding: 10px 14px;
  background: var(--paper); border-top: 1px solid var(--line-soft);
}
.composer textarea { min-height: 44px; max-height: 120px; resize: none; padding: 11px 14px; font-size: 14px; border-radius: 20px; }
.composer .primary { height: 44px; margin: 0; padding: 0 18px; flex: none; border-radius: 20px; font-size: 13px; letter-spacing: 0; }

/* ---------- 说明 ---------- */
.prose-card { background: var(--paper-2); border: 1px solid var(--line-soft); border-radius: var(--r); padding: 18px; }
.prose-card h3 { font-family: var(--serif); font-size: 17px; letter-spacing: 1.5px; margin: 22px 0 6px; font-weight: 400; }
.prose-card h3:first-child { margin-top: 0; }
.prose-card p, .prose-card li { font-size: 13.5px; line-height: 1.9; color: var(--ink-2); }
.prose-card ol { padding-left: 18px; }

/* ---------- 浮层 ---------- */
.sheet { position: fixed; inset: 0; z-index: 90; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(20, 16, 12, .45); opacity: 0; transition: opacity .25s; }
.sheet-panel {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 80vh; overflow-y: auto;
  background: var(--paper); border-radius: 20px 20px 0 0;
  padding: 8px 20px calc(24px + env(safe-area-inset-bottom));
  transform: translateY(100%); transition: transform .32s cubic-bezier(.2, .7, .3, 1);
}
.sheet.open .sheet-backdrop { opacity: 1; }
.sheet.open .sheet-panel { transform: none; }
.sheet-grip { width: 36px; height: 4px; border-radius: 2px; background: var(--line); margin: 4px auto 10px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding-bottom: 10px; }
.sheet-title { font-family: var(--serif); font-size: 19px; letter-spacing: 2px; margin: 0; font-weight: 400; }
.sheet-close { border: 0; background: var(--paper-2); width: 30px; height: 30px; border-radius: 50%; color: var(--ink-2); font-size: 13px; }
.sheet-body { padding-top: 8px; font-size: 13.5px; color: var(--ink-2); }
.sh-row { display: grid; grid-template-columns: 76px 1fr; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line-soft); }
.sh-row.now { background: var(--paper-2); margin: 0 -10px; padding: 10px; border-radius: 12px; border-bottom-color: transparent; }
.sh-row .sh-name { font-family: var(--serif); font-size: 17px; color: var(--accent); }
.sh-row .sh-meta { font-size: 10px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.sh-row .sh-mer { font-size: 12.5px; color: var(--ink); }
.sh-row .sh-tip { font-size: 12px; color: var(--ink-2); margin-top: 3px; line-height: 1.6; }
.gua-detail { text-align: center; padding: 4px 0; }
.gua-detail .big { font-family: var(--serif); font-size: 68px; color: var(--accent); line-height: 1; }
.gua-detail .name { font-family: var(--serif); font-size: 21px; letter-spacing: 3px; margin-top: 6px; }
.gua-detail .theme { font-size: 12.5px; color: var(--ink-2); margin-top: 4px; }
.gua-detail .nums { font-family: var(--serif); font-size: 15px; letter-spacing: 2px; color: var(--accent); margin-top: 8px; }
.gua-detail .xiang {
  margin: 14px 0 0; padding: 14px; border-radius: 12px; background: var(--paper-2);
  font-family: var(--serif); font-size: 14px; line-height: 1.9; color: var(--ink); text-align: left;
}

/* ---------- 弹层 ---------- */
dialog { border: 0; padding: 0; background: transparent; max-width: 100vw; }
dialog::backdrop { background: rgba(20, 16, 12, .5); backdrop-filter: blur(3px); }
.dialog {
  width: min(92vw, 430px); margin: 0; padding: 22px;
  background: var(--paper); color: var(--ink); border-radius: 20px;
  box-shadow: 0 30px 60px -30px rgba(0,0,0,.5);
}
.dialog h2 { font-family: var(--serif); font-size: 22px; letter-spacing: 2px; margin: 0 0 6px; font-weight: 400; }
.row { display: flex; gap: 10px; align-items: center; margin-top: 10px; }
.row.end { justify-content: flex-end; margin-top: 18px; }
.tips { margin: 8px 0 0; padding-left: 18px; }
.tips li { font-size: 13px; margin: 6px 0; color: var(--ink-2); }

/* ---------- 杂项 ---------- */
.to-top, .to-bottom {
  position: fixed; right: 16px; width: 38px; height: 38px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--paper); color: var(--ink-2);
  display: grid; place-items: center; z-index: 40; font-size: 14px;
  opacity: 0; transform: translateY(6px); pointer-events: none;
  transition: opacity .2s, transform .2s;
}
.to-top { bottom: calc(80px + env(safe-area-inset-bottom)); }
.to-bottom { bottom: calc(136px + env(safe-area-inset-bottom)); z-index: 26; width: 34px; height: 34px; }
.to-top.show, .to-bottom.show { opacity: 1; transform: none; pointer-events: auto; }
.toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translate(-50%, 10px);
  background: var(--ink); color: var(--paper); font-size: 12.5px; padding: 10px 18px; border-radius: 999px;
  opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none; z-index: 99; max-width: 86vw; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
#dlgImg::backdrop { background: rgba(0, 0, 0, .9); }
#dlgImg img { max-width: 94vw; max-height: 86vh; display: block; border-radius: 10px; }

button:focus-visible, textarea:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}

@media (min-width: 760px) {
  main { padding: 0 22px; }
  .field { border-radius: 0 0 24px 24px; }
  .term { font-size: 84px; }
}


/* ============================================================
   对标优化层：Apple 字阶/间距 · Material 3 颜色角色与状态层 · Figma token 化
   只做纪律性收敛，不改结构。
   ============================================================ */
:root {
  /* 间距：8pt 栅格 + 4pt 半步 */
  --space-1: 4px;  --space-2: 8px;  --space-3: 12px; --space-4: 16px;
  --space-5: 20px; --space-6: 24px; --space-7: 32px; --space-8: 40px; --space-9: 48px;

  /* 字阶（Apple 式收敛） */
  --type-caption: 11px;
  --type-footnote: 12px;
  --type-body: 15px;
  --type-callout: 15.5px;
  --type-title3: 20px;
  --type-title2: 24px;
  --type-title1: 30px;
  --type-large: 40px;

  /* 圆角层级（M3 shape scale） */
  --radius-xs: 6px; --radius-s: 10px; --radius-m: 14px;
  --radius-l: 20px; --radius-xl: 26px; --radius-full: 999px;

  /* 动效 */
  --dur-fast: 150ms; --dur-base: 220ms; --dur-slow: 320ms;
  --ease-standard: cubic-bezier(0.2, 0, 0, 1);
  --ease-emph: cubic-bezier(0.2, 0, 0, 1);

  /* 高度 */
  --elev-1: 0 1px 2px rgba(34,31,26,.06), 0 2px 8px rgba(34,31,26,.05);
  --elev-2: 0 8px 24px -16px rgba(34,31,26,.35);

  /* 颜色角色（M3 语义，全部指向季节变量） */
  --bg: var(--paper);
  --surface: var(--paper-2);
  --on-surface: var(--ink);
  --on-surface-muted: var(--muted);
  --primary: var(--accent);
  --on-primary: #FFF6EA;
  --outline: var(--line);
  --danger: #A33B27;
}

body {
  font-size: var(--type-callout);
  line-height: 1.65;
  letter-spacing: .1px;
  background: var(--bg);
}

/* 字阶收敛 */
.page-title { font-size: var(--type-title1); line-height: 1.2; letter-spacing: 1.5px; }
.page-sub { font-size: var(--type-footnote); line-height: 1.6; color: var(--on-surface-muted); }
.rec-title { font-size: var(--type-title2); line-height: 1.25; }
.rec-name { font-size: var(--type-title3); line-height: 1.3; }
.now .shichen { font-size: 28px; line-height: 1.1; }
.term { line-height: 1; }
.yiji li { font-size: var(--type-body); line-height: 1.7; }
.md { font-size: var(--type-body); line-height: 1.95; }
.msg { font-size: var(--type-callout); line-height: 1.8; }

/* 组件只引用 token */
.card { border-radius: var(--radius-l); padding: var(--space-5); }
.primary {
  height: 52px; border-radius: var(--radius-m);
  font-size: var(--type-callout); letter-spacing: 1.5px;
  transition: transform var(--dur-fast) var(--ease-standard), filter var(--dur-base) var(--ease-standard);
}
.ghost { border-radius: var(--radius-m); transition: border-color var(--dur-base) var(--ease-standard), color var(--dur-base) var(--ease-standard); }
.chip { border-radius: var(--radius-full); transition: background var(--dur-base) var(--ease-standard), transform var(--dur-fast) var(--ease-standard); }
textarea, input, select {
  border-radius: var(--radius-m);
  font-size: var(--type-callout);
  transition: border-color var(--dur-base) var(--ease-standard), background var(--dur-base) var(--ease-standard);
}
.tabbar button { transition: color var(--dur-base) var(--ease-standard); }
.tab-indicator { transition: transform var(--dur-slow) var(--ease-emph); }
.sheet-panel { border-radius: var(--radius-xl) var(--radius-xl) 0 0; transition: transform var(--dur-slow) var(--ease-emph); }
.sheet { border-radius: var(--radius-m); }
.thumb { border-radius: var(--radius-s); }

/* 状态层（M3 state layer） */
.primary:active { filter: brightness(.94); }
.ghost:active, .chip:active { background: var(--surface); }
.tap:active { transform: scale(.994); }

/* 焦点环统一 */
button:focus-visible, textarea:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--primary); outline-offset: 2px; border-radius: var(--radius-xs);
}

/* 动效收敛：减少无意义位移 */
.tab.active { animation-duration: var(--dur-slow); }

/* ---------- 可读性与组件 token 收敛（第二轮） ---------- */
.term-tip { color: rgba(248, 239, 223, .86); }
.hou .txt { color: rgba(248, 239, 223, .86); }
.hou .lbl { color: rgba(248, 239, 223, .55); }
.field-foot .next { color: rgba(248, 239, 223, .66); }
.meta { color: rgba(248, 239, 223, .78); }
.meta .year { color: rgba(248, 239, 223, .55); }

.rec-card { padding: var(--space-4); border-radius: var(--radius-l); }
.rec-head { padding: var(--space-6) 0 var(--space-2); }
.rec-actions .ghost { height: 32px; padding: 0 14px; font-size: var(--type-caption); }
.chips button { height: 36px; padding: 0 var(--space-4); font-size: var(--type-footnote); }
.composer textarea { border-radius: var(--radius-l); }
.composer .primary { border-radius: var(--radius-full); }
.prose-card { border-radius: var(--radius-l); padding: var(--space-5); }
.dialog { border-radius: var(--radius-xl); padding: var(--space-6); }
.sheet-title { font-size: var(--type-title3); }
.hint { font-size: var(--type-caption); line-height: 1.7; }
.disclaimer { font-size: 10px; }
.foot { font-size: 9px; }
.sh-row .sh-name { font-size: 17px; }
.sh-row .sh-mer { font-size: var(--type-footnote); }
.sh-row .sh-tip { font-size: var(--type-caption); }

/* ---------- 表单与对话的最后一层工艺 ---------- */
textarea, input, select {
  border: 1px solid rgba(34, 31, 26, .12);
}
textarea:focus, input:focus, select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(168, 72, 47, .12);
}
.lbl { font-size: var(--type-caption); letter-spacing: .8px; color: var(--on-surface-muted); margin: var(--space-4) 0 var(--space-2); }
.primary:disabled { opacity: .5; }
.chat-empty { padding: var(--space-8) 0 var(--space-3); }
.chat-empty .quote { font-size: var(--type-title2); letter-spacing: 6px; }
.msg.bot { font-size: var(--type-callout); }
.msg .who { font-size: 9.5px; letter-spacing: 1.8px; }
.composer { padding: var(--space-2) var(--space-3); }

/* ============ 首页 A：书页 + 留白 ============ */
#tab-home { padding: 0; }
.a-page { padding: calc(52px + env(safe-area-inset-top) + 18px) 26px calc(84px + env(safe-area-inset-bottom)); min-height: 100vh; display: flex; flex-direction: column; }
.a-brand { font-size: 9px; letter-spacing: 4px; color: var(--on-surface-muted); }
.a-hero { margin-top: 27vh; }
.a-term-row { display: flex; align-items: flex-end; gap: 14px; }
.a-term { font-family: var(--serif); font-size: 52px; line-height: 1; letter-spacing: 12px; font-weight: 400; color: var(--on-surface); cursor: pointer; }
.a-term:active { opacity: .6; }
.a-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--primary); margin-bottom: 30px; }
.a-date { margin-top: 14px; font-size: 11px; letter-spacing: 1.6px; color: var(--on-surface-muted); }
.a-date .sep { margin: 0 8px; opacity: .5; }
.a-gz { margin-top: 6px; font-size: 11px; letter-spacing: 1.4px; color: var(--on-surface-muted); }
.a-hou { margin-top: 14px; font-size: 10px; letter-spacing: 1.2px; color: var(--on-surface-muted); opacity: .9; }
.a-rule { width: 120px; height: 1px; background: rgba(34,31,26,.28); margin: 18px 0 16px; }
.a-block { text-align: left; background: none; border: 0; padding: 0; width: 100%; color: inherit; }
.a-block:active { opacity: .65; }
.a-block-head { display: flex; align-items: baseline; gap: 12px; }
.a-shichen { font-family: var(--serif); font-size: 30px; letter-spacing: 4px; }
.a-mer { font-size: 11px; letter-spacing: 1px; color: var(--primary); }
.a-range { margin-left: auto; font-size: 9.5px; letter-spacing: .5px; color: var(--on-surface-muted); }
.a-bar { height: 2px; background: rgba(34,31,26,.12); margin: 10px 0 8px; }
.a-bar i { display: block; height: 100%; width: 0; background: var(--primary); transition: width .8s var(--ease-standard); }
.a-tip { font-size: 11px; line-height: 1.85; color: var(--on-surface-muted); }
.a-remain { display: inline-block; margin-top: 6px; font-size: 9px; letter-spacing: .5px; color: var(--on-surface-muted); opacity: .8; }
.a-yiji { display: grid; grid-template-columns: 1fr 1fr; gap: 40px; margin-top: 16px; padding-top: 14px; border-top: 1px solid rgba(34,31,26,.12); }
.a-yiji:active { opacity: .65; }
.a-label { font-family: var(--serif); font-size: 13px; letter-spacing: 3px; }
.a-label.yi { color: var(--on-surface-muted); }
.a-label.ji { color: var(--primary); }
.a-col ul { list-style: none; margin: 10px 0 0; padding: 0; }
.a-col li { font-size: 11.5px; line-height: 1.95; color: var(--ink-2); }
.a-gua { display: flex; align-items: baseline; gap: 10px; margin-top: 16px; padding-top: 14px; border-top: 1px solid rgba(34,31,26,.12); }
.a-gua:active { opacity: .65; }
.a-sym { font-family: var(--serif); font-size: 22px; color: var(--primary); }
.a-gua-name { font-family: var(--serif); font-size: 13px; letter-spacing: 2px; }
.a-gua-meta { font-size: 10px; letter-spacing: .8px; color: var(--on-surface-muted); }
.a-chev { margin-left: auto; font-family: var(--serif); font-size: 18px; color: var(--on-surface-muted); }
.a-cue { margin-top: auto; align-self: center; border: 0; background: none; padding: 18px 0 0; font-size: 9.5px; letter-spacing: 2px; color: var(--on-surface-muted); }
.a-cue:active { opacity: .6; }
.a-details { padding: 30px 26px calc(90px + env(safe-area-inset-bottom)); border-top: 1px solid rgba(34,31,26,.12); background: var(--surface); }
.a-h2 { font-family: var(--serif); font-size: 20px; letter-spacing: 4px; font-weight: 400; margin: 0 0 14px; }
.a-h3 { font-size: 10.5px; letter-spacing: 3px; color: var(--on-surface-muted); font-weight: 400; margin: 22px 0 8px; }
.a-kicker { font-size: 11px; line-height: 2; color: var(--ink-2); letter-spacing: 1px; }
.a-meta-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 14px; margin-top: 14px; }
.a-meta-grid span { font-size: 10px; letter-spacing: .5px; color: var(--on-surface-muted); border-bottom: 1px solid rgba(34,31,26,.08); padding-bottom: 6px; }
.a-full { list-style: none; margin: 0; padding: 0; }
.a-full li { font-size: 12px; line-height: 2; color: var(--ink-2); border-bottom: 1px solid rgba(34,31,26,.08); padding: 3px 0; }
.a-note { font-size: 10.5px; line-height: 1.8; color: var(--on-surface-muted); }
.a-foot { margin-top: 26px; font-size: 9px; color: var(--on-surface-muted); text-align: center; }
.a-back { display: block; margin: 26px auto 0; border: 1px solid rgba(34,31,26,.16); background: none; padding: 10px 20px; border-radius: 999px; font-size: 10.5px; letter-spacing: 1.5px; color: var(--on-surface-muted); }
.a-back:active { opacity: .6; }

/* A 首页修正：纸面顶栏、去重、首屏节奏 */
body[data-tab="home"] .topbar {
  background: var(--paper); color: var(--on-surface);
  border-bottom: 1px solid rgba(34,31,26,.10);
}
.a-page { min-height: auto; padding-top: calc(52px + env(safe-area-inset-top) + 10px); }
.a-hero { margin-top: 18px; }
.a-cue { margin-top: 12px; }

.a-details { animation: aIn .45s var(--ease-standard) both; }
@keyframes aIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ============ 会诊：问诊笺 ============ */
#tab-consult { padding: 0; }
.c-page { padding: calc(52px + env(safe-area-inset-top) + 14px) 24px calc(100px + env(safe-area-inset-bottom)); }
.c-title { font-family: var(--serif); font-size: 34px; letter-spacing: 8px; font-weight: 400; margin: 0; }
.c-sub { margin: 10px 0 26px; font-size: var(--type-footnote); color: var(--on-surface-muted); letter-spacing: .5px; }
.c-label { display: block; font-size: 10px; letter-spacing: 3px; color: var(--on-surface-muted); margin-bottom: 8px; }
#caseText { background: transparent; border: 1px solid rgba(34,31,26,.18); border-radius: 2px; padding: 14px; min-height: 170px; font-size: 14.5px; line-height: 1.95; }
#caseText:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(168,72,47,.08); }
.c-row { display: flex; gap: 10px; margin-top: 12px; align-items: center; }
.c-row select, .c-row input { background: transparent; border: 1px solid rgba(34,31,26,.18); border-radius: 2px; padding: 10px 12px; font-size: 13px; }
.c-text { border: 0; background: none; padding: 0 0 3px; font-size: 11.5px; letter-spacing: 1.5px; color: var(--on-surface-muted); border-bottom: 1px solid rgba(34,31,26,.2); }
.c-text:active { color: var(--primary); }
.c-chips { display: flex; gap: 20px; margin-top: 16px; flex-wrap: wrap; }
.c-note { margin: 18px 0 0; font-size: 10.5px; color: var(--on-surface-muted); line-height: 1.8; }
.c-page .primary { margin-top: 22px; height: 52px; border-radius: 2px; background: var(--ink); color: var(--paper); letter-spacing: 6px; font-size: 13px; box-shadow: none; }

/* ============ 结果：会诊记录（可翻页） ============ */
#result { margin-top: 34px; }
.rec-head { display: flex; justify-content: space-between; align-items: flex-start; padding-top: 18px; border-top: 1px solid rgba(34,31,26,.2); }
.rec-title { font-family: var(--serif); font-size: 22px; letter-spacing: 4px; margin: 0; font-weight: 400; }
.rec-meta { margin-top: 6px; font-size: 9.5px; line-height: 1.8; color: var(--on-surface-muted); letter-spacing: .5px; }
.rec-actions { display: flex; gap: 8px; flex: none; }
.rec-actions .ghost { height: 30px; padding: 0 12px; font-size: 10px; border-radius: 2px; }
.rec-pages { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none; margin-top: 8px; }
.rec-pages::-webkit-scrollbar { display: none; }
.rec-page { flex: 0 0 100%; scroll-snap-align: start; padding: 18px 0 10px; min-height: 58vh; border-top: 1px solid rgba(34,31,26,.14); }
.rec-eyebrow { font-size: 9px; letter-spacing: 3px; color: var(--on-surface-muted); }
.rec-name { font-family: var(--serif); font-size: 28px; letter-spacing: 3px; font-weight: 400; margin: 8px 0 2px; }
.rec-tag { font-size: 10px; letter-spacing: 1.5px; color: var(--on-surface-muted); }
.rec-page .md { margin-top: 16px; }
.rec-page.synthesis { border-top-color: var(--primary); }
.rec-sub { margin-top: 18px; }
.rec-sub-name { font-family: var(--serif); font-size: 16px; letter-spacing: 2px; }
.rec-sub-tag { font-size: 9px; color: var(--on-surface-muted); margin-left: 8px; }
.rec-nav { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; padding-top: 12px; border-top: 1px solid rgba(34,31,26,.14); }
.rec-nav button { border: 0; background: none; font-size: 11px; letter-spacing: 1px; color: var(--on-surface-muted); padding: 6px 4px; }
.rec-nav button:active { color: var(--primary); }
.rec-dots { display: flex; gap: 7px; }
.rec-dots i { width: 4px; height: 4px; border-radius: 50%; background: rgba(34,31,26,.22); }
.rec-dots i.on { background: var(--primary); }

.rec-nav {
  position: sticky; top: calc(52px + env(safe-area-inset-top));
  background: var(--paper); z-index: 6;
  margin-top: 0; padding: 10px 0 8px;
  border-top: 1px solid rgba(34,31,26,.14);
  border-bottom: 1px solid rgba(34,31,26,.08);
}
.rec-pages { margin-top: 0; }

/* 一屏装下：压缩首屏后确保卦象与入口在首屏内 */
.a-page { padding-bottom: calc(74px + env(safe-area-inset-bottom)); }
.a-hero { margin-top: 14px; }
.a-date, .a-gz { line-height: 1.7; }
.a-hou { line-height: 1.6; }

a.primary { display: flex; align-items: center; justify-content: center; text-decoration: none; }

/* ============ 交互增强 ============ */
.tab-in-right { animation: tabInRight .30s cubic-bezier(.2,0,0,1) both; }
.tab-in-left  { animation: tabInLeft .30s cubic-bezier(.2,0,0,1) both; }
@keyframes tabInRight { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: none; } }
@keyframes tabInLeft  { from { opacity: 0; transform: translateX(-16px); } to { opacity: 1; transform: none; } }

.toast {
  position: fixed; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom));
  transform: translate(-50%, 12px); z-index: 70;
  background: var(--ink); color: var(--paper);
  font-size: 12px; letter-spacing: .5px; line-height: 1.4;
  padding: 10px 18px; border-radius: 999px; max-width: 82vw; text-align: center;
  opacity: 0; pointer-events: none;
  transition: opacity .22s var(--ease-standard), transform .22s var(--ease-standard);
  box-shadow: 0 8px 24px -12px rgba(0,0,0,.5);
}
.toast.show { opacity: .96; transform: translate(-50%, 0); }

.pull-hint {
  position: fixed; top: calc(54px + env(safe-area-inset-top));
  left: 50%; transform: translate(-50%, -46px);
  display: flex; align-items: center; gap: 8px;
  font-size: 10px; letter-spacing: 2px; color: var(--on-surface-muted);
  opacity: 0; z-index: 25; pointer-events: none;
  transition: opacity .18s var(--ease-standard);
}
.pull-hint i { width: 13px; height: 13px; border-radius: 50%; border: 1px solid var(--primary); display: block; transition: background .18s; }
.pull-hint.ready i { background: var(--primary); }

.char-count { margin-top: 6px; font-size: 10px; letter-spacing: 1px; color: var(--on-surface-muted); text-align: right; }
.sheet-panel { will-change: transform; }
.sheet-backdrop { transition: opacity .3s var(--ease-standard); }

/* 按压反馈统一 */
.tabbar button:active svg { transform: scale(.9); }
.tabbar button svg { transition: transform .16s var(--ease-standard); }
.chips button:active, .a-cue:active, .c-text:active { transform: scale(.97); }

/* 首页下拉时避免浏览器自带回弹干扰 */
#tab-home { overscroll-behavior-y: contain; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

/* 结果翻页页码与可点圆点 */
.rec-counter { font-size: 9.5px; letter-spacing: 1px; color: var(--on-surface-muted); }
.rec-dots i { transition: background .2s, transform .2s; }
.rec-dots i.on { transform: scale(1.4); }

/* 对话快捷提问 */
.quick { display: flex; gap: 8px; overflow-x: auto; padding: 10px 18px 2px; scrollbar-width: none; }
.quick::-webkit-scrollbar { display: none; }
.quick button {
  flex: none; border: 1px solid rgba(34,31,26,.16); background: transparent;
  color: var(--ink-2); font-size: 11px; letter-spacing: .5px; padding: 8px 14px;
  border-radius: 999px; white-space: nowrap;
}
.quick button:active { background: var(--surface); transform: scale(.97); }
