:root {
  --ink: #2b2620;
  --ink-soft: #5b5346;
  --ink-faint: #8a8275;
  --paper: #f7f4ec;
  --paper-2: #efe9dc;
  --panel: #211d18;
  --panel-2: #2c2620;
  --panel-ink: #e8e0d0;
  --panel-faint: #9a9081;
  --cinnabar: #9e3b2f;
  --cinnabar-2: #b9503f;
  --jade: #3f6651;
  --gold: #b08d4f;
  --line: #e2dac9;
  --line-dark: #3a332a;
  --radius: 14px;
  --shadow: 0 6px 24px rgba(40, 32, 20, 0.08);
  --serif: "Songti SC", "STSong", "Noto Serif SC", "Source Han Serif SC", Georgia, serif;
  --sans: -apple-system, "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  --mono: "SF Mono", "Menlo", "Cascadia Code", "Noto Sans Mono CJK SC", monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--sans);
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
}
#app { display: flex; height: 100vh; height: 100dvh; overflow: hidden; }

/* ── 侧栏 ───────────────────────────────────────── */
.sidebar {
  width: 270px; flex-shrink: 0;
  background: var(--panel);
  color: var(--panel-ink);
  display: flex; flex-direction: column;
  padding: 18px 14px;
  border-right: 1px solid var(--line-dark);
}
.brand { display: flex; align-items: center; gap: 12px; padding: 6px 6px 16px; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 10px;
  background: linear-gradient(150deg, var(--cinnabar), var(--cinnabar-2));
  color: #f7efe0; font-family: var(--serif); font-size: 26px;
  display: grid; place-items: center;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.12);
}
.brand-text h1 { font-family: var(--serif); font-size: 22px; letter-spacing: 4px; font-weight: 600; }
.brand-text p { font-size: 11px; color: var(--panel-faint); letter-spacing: 2px; margin-top: 2px; }

.btn-new {
  margin: 6px 4px 16px; padding: 11px 14px;
  background: transparent; color: var(--panel-ink);
  border: 1px solid var(--line-dark); border-radius: 10px;
  font-size: 14px; cursor: pointer; transition: .15s;
  font-family: var(--serif); letter-spacing: 2px;
}
.btn-new:hover { background: var(--panel-2); border-color: var(--gold); color: #fff; }

.sessions { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.session-item {
  padding: 10px 12px; border-radius: 9px; cursor: pointer;
  font-size: 13.5px; color: var(--panel-faint);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  display: flex; align-items: center; gap: 8px; transition: .12s;
}
.session-item:hover { background: var(--panel-2); color: var(--panel-ink); }
.session-item.active { background: var(--panel-2); color: #fff; box-shadow: inset 2px 0 0 var(--cinnabar-2); }
.session-item .sys-tag {
  font-size: 10px; padding: 1px 6px; border-radius: 6px;
  background: rgba(176,141,79,.18); color: var(--gold); flex-shrink: 0;
}
.session-item .del { margin-left: auto; opacity: 0; color: var(--panel-faint); flex-shrink: 0; }
.session-item:hover .del { opacity: .7; }
.session-item .del:hover { color: var(--cinnabar-2); }

.sidebar-foot { border-top: 1px solid var(--line-dark); padding-top: 12px; margin-top: 8px; display: flex; flex-direction: column; gap: 4px; }
.foot-link {
  background: none; border: none; text-align: left; cursor: pointer;
  color: var(--panel-faint); font-size: 13px; padding: 7px 6px; border-radius: 8px;
  text-decoration: none; font-family: var(--sans);
}
.foot-link:hover { background: var(--panel-2); color: var(--panel-ink); }
.identity-line { font-size: 11px; color: #6f665a; padding: 6px; font-family: var(--mono); word-break: break-all; }
.sidebar-backdrop { display: none; }
.sidebar-backdrop[hidden] { display: none; }

/* ── 主区 ───────────────────────────────────────── */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--paper); }
.topbar {
  height: 56px; flex-shrink: 0; display: flex; align-items: center; gap: 14px;
  padding: 0 22px; border-bottom: 1px solid var(--line);
  background: rgba(247,244,236,.85); backdrop-filter: blur(8px);
}
.hamburger { display: none; background: none; border: none; font-size: 20px; cursor: pointer; color: var(--ink); }
.topbar-title { font-family: var(--serif); font-size: 16px; letter-spacing: 2px; color: var(--ink); flex: 1;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sys-hints { display: flex; gap: 6px; }
.chip {
  font-size: 12px; padding: 4px 10px; border-radius: 20px;
  background: var(--paper-2); color: var(--ink-soft); border: 1px solid var(--line);
  font-family: var(--serif); letter-spacing: 1px;
}

/* ── 对话 ───────────────────────────────────────── */
.chat { flex: 1; overflow-y: auto; padding: 26px 0 10px; scroll-behavior: smooth; }
.welcome { max-width: 680px; margin: 6vh auto 0; text-align: center; padding: 0 24px; }
.welcome-glyph { font-size: 52px; color: var(--cinnabar); opacity: .82; }
.welcome h2 { font-family: var(--serif); font-size: 26px; margin-top: 16px; letter-spacing: 1px; color: var(--ink); }
.welcome-sub { color: var(--ink-faint); margin-top: 10px; font-size: 14.5px; }
.examples { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 28px; }
.ex {
  text-align: left; padding: 14px 16px; border-radius: 12px; cursor: pointer;
  background: #fff; border: 1px solid var(--line); color: var(--ink-soft);
  font-size: 13.5px; line-height: 1.5; transition: .15s; font-family: var(--sans);
}
.ex:hover { border-color: var(--gold); box-shadow: var(--shadow); transform: translateY(-1px); }

.msg-row { max-width: 760px; margin: 0 auto; padding: 12px 24px; display: flex; gap: 14px; }
.msg-row.user { justify-content: flex-end; }
.avatar {
  width: 34px; height: 34px; border-radius: 9px; flex-shrink: 0;
  display: grid; place-items: center; font-family: var(--serif); font-size: 17px;
}
.msg-row.assistant .avatar { background: var(--panel); color: #f0e6d3; }
.msg-row.user .avatar { display: none; }
.bubble { max-width: 100%; }
.msg-row.user .bubble {
  background: var(--panel); color: var(--panel-ink); padding: 11px 16px;
  border-radius: 14px 14px 4px 14px; font-size: 15px; line-height: 1.6; max-width: 78%;
}
.msg-row.assistant .bubble { color: var(--ink); font-size: 15.5px; line-height: 1.85; flex: 1; }

/* 命盘 */
.board {
  background: linear-gradient(180deg, #fbf8f1, #f4efe3);
  border: 1px solid var(--line); border-left: 3px solid var(--cinnabar);
  border-radius: 10px; padding: 14px 16px; margin: 4px 0 16px;
  font-family: var(--mono); font-size: 12.5px; line-height: 1.6; color: var(--ink-soft);
  overflow-x: auto; white-space: pre;
}
.board-label {
  display: inline-block; font-family: var(--serif); font-size: 12px; letter-spacing: 2px;
  color: var(--cinnabar); margin-bottom: 8px; padding: 2px 10px;
  background: rgba(158,59,47,.08); border-radius: 20px; white-space: normal;
}
.bazi-board {
  background: linear-gradient(180deg, #fbf8f1, #f3ecdf);
  border: 1px solid var(--line); border-left: 3px solid var(--cinnabar);
  border-radius: 10px; padding: 14px; margin: 4px 0 16px;
  color: var(--ink); box-shadow: 0 6px 18px rgba(40, 32, 20, .05);
}
.bazi-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.bazi-title { font-family: var(--serif); font-size: 18px; letter-spacing: 2px; font-weight: 600; }
.bazi-meta { font-size: 12px; color: var(--ink-faint); white-space: nowrap; }
.bazi-pillars { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.bazi-pillar {
  background: rgba(255,255,255,.72); border: 1px solid var(--line); border-radius: 9px;
  padding: 10px; min-width: 0;
}
.pillar-pos { font-size: 11px; color: var(--cinnabar); font-family: var(--serif); letter-spacing: 2px; }
.pillar-gz { font-family: var(--serif); font-size: 28px; line-height: 1.1; margin-top: 6px; color: var(--ink); }
.pillar-split { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; font-size: 11px; color: var(--ink-faint); }
.pillar-god { display: inline-flex; margin-top: 8px; padding: 2px 8px; border-radius: 999px;
  background: rgba(63,102,81,.1); color: var(--jade); font-size: 12px; }
.pillar-line { margin-top: 7px; font-size: 12px; line-height: 1.45; color: var(--ink-soft); overflow-wrap: anywhere; }
.pillar-foot { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.soft-tag, .empty-tag {
  display: inline-flex; border-radius: 999px; padding: 2px 7px; font-size: 11px; line-height: 1.4;
  background: var(--paper-2); color: var(--ink-soft);
}
.empty-tag { background: rgba(158,59,47,.1); color: var(--cinnabar); }
.bazi-section, .bazi-facts {
  margin-top: 12px; padding-top: 12px; border-top: 1px dashed rgba(138,130,117,.35);
}
.bazi-section h4 {
  font-family: var(--serif); font-size: 14px; letter-spacing: 1px; margin-bottom: 8px; color: var(--ink);
}
.wuxing-bars { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
.wuxing-row {
  background: rgba(255,255,255,.58); border: 1px solid rgba(226,218,201,.82); border-radius: 8px;
  padding: 8px; min-width: 0;
}
.wuxing-name { display: block; font-family: var(--serif); color: var(--ink); font-size: 14px; }
.wuxing-track { display: block; height: 5px; margin: 7px 0 5px; border-radius: 999px; background: var(--paper-2); overflow: hidden; }
.wuxing-fill { display: block; height: 100%; border-radius: inherit; background: var(--jade); }
.wx-木 { background: #4f7a58; } .wx-火 { background: #b9503f; } .wx-土 { background: #b08d4f; }
.wx-金 { background: #8d8170; } .wx-水 { background: #496f86; }
.wuxing-count { font-size: 12px; color: var(--ink-faint); }
.bazi-facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 10px; }
.bazi-fact { display: flex; gap: 8px; align-items: baseline; min-width: 0; font-size: 13px; line-height: 1.55; }
.fact-key { flex: 0 0 auto; color: var(--cinnabar); font-family: var(--serif); letter-spacing: 1px; }
.fact-val { color: var(--ink-soft); min-width: 0; overflow-wrap: anywhere; }
.sha-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.sha-tag {
  border: 1px solid rgba(176,141,79,.35); background: rgba(176,141,79,.09);
  color: #7f6537; border-radius: 999px; padding: 3px 9px; font-size: 12px;
}
.luck-track { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; scroll-snap-type: x proximity; }
.luck-step {
  flex: 0 0 112px; scroll-snap-align: start; border: 1px solid rgba(226,218,201,.9);
  background: rgba(255,255,255,.58); border-radius: 8px; padding: 8px 9px;
}
.luck-age { display: block; color: var(--ink-faint); font-size: 11px; }
.luck-gz { display: block; font-family: var(--serif); font-size: 20px; line-height: 1.25; margin-top: 3px; }
.luck-god { display: block; color: var(--jade); font-size: 12px; margin-top: 2px; }

.astro-board {
  background: linear-gradient(180deg, #fbf8f1, #f3ecdf);
  border: 1px solid var(--line); border-left: 3px solid var(--cinnabar);
  border-radius: 10px; padding: 14px; margin: 4px 0 16px;
  color: var(--ink); box-shadow: 0 6px 18px rgba(40, 32, 20, .05);
}
.ziwei-board { border-left-color: var(--gold); }
.liuyao-board { border-left-color: var(--jade); }
.qimen-board { border-left-color: #496f86; }
.astro-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.astro-title { font-family: var(--serif); font-size: 18px; letter-spacing: 2px; font-weight: 600; }
.astro-meta { font-size: 12px; color: var(--ink-faint); white-space: nowrap; }
.astro-facts {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 10px; margin-bottom: 12px;
}
.astro-fact {
  display: flex; gap: 8px; align-items: baseline; min-width: 0;
  font-size: 13px; line-height: 1.55;
}
.mini-tag, .star-tag, .qimen-tag {
  display: inline-flex; align-items: center; border-radius: 999px;
  padding: 2px 7px; font-size: 11px; line-height: 1.4;
  background: var(--paper-2); color: var(--ink-soft);
}
.muted-tag { color: var(--ink-faint); background: rgba(239,233,220,.72); }

/* 紫微 */
.ziwei-palaces { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.ziwei-palace {
  min-width: 0; background: rgba(255,255,255,.68); border: 1px solid rgba(226,218,201,.9);
  border-radius: 8px; padding: 9px;
}
.ziwei-palace.is-ming { border-color: rgba(158,59,47,.35); box-shadow: inset 2px 0 0 rgba(158,59,47,.55); }
.ziwei-palace.is-shen:not(.is-ming) { border-color: rgba(63,102,81,.32); box-shadow: inset 2px 0 0 rgba(63,102,81,.45); }
.ziwei-palace-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.ziwei-name { font-family: var(--serif); font-size: 16px; color: var(--ink); letter-spacing: 1px; }
.ziwei-branch { font-size: 12px; color: var(--ink-faint); white-space: nowrap; }
.palace-badges, .star-tags { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 7px; }
.palace-badges .mini-tag:first-child { background: rgba(158,59,47,.1); color: var(--cinnabar); }
.star-tag { border: 1px solid rgba(226,218,201,.9); background: rgba(255,255,255,.72); font-size: 12px; }
.hua-star { border-color: rgba(176,141,79,.38); background: rgba(176,141,79,.1); color: #7f6537; }

/* 六爻 */
.liuyao-trad-board {
  background: #fffdf8;
  border-left-color: var(--jade);
  overflow-x: auto;
}
.liuyao-meta-panel {
  background: rgba(255,255,255,.72);
  border: 1px solid rgba(226,218,201,.88);
  border-radius: 8px; padding: 10px 12px; margin-bottom: 12px;
}
.liuyao-meta-line {
  display: grid; grid-template-columns: 42px minmax(0, 1fr);
  gap: 10px; align-items: baseline; font-size: 15px; line-height: 1.7;
}
.liuyao-meta-line + .liuyao-meta-line { border-top: 1px dashed rgba(226,218,201,.8); padding-top: 3px; margin-top: 3px; }
.meta-key { color: var(--ink); font-family: var(--serif); font-weight: 600; letter-spacing: 1px; }
.meta-val { color: var(--ink-soft); min-width: 0; overflow-wrap: anywhere; }
.ganzhi-val { display: flex; gap: 12px; flex-wrap: wrap; }
.hot-gz { color: var(--cinnabar); font-weight: 700; }
.liuyao-chart-head {
  display: grid; grid-template-columns: 52px minmax(220px, 1fr) minmax(220px, 1fr);
  gap: 10px; align-items: end; min-width: 0; margin: 8px 0 8px;
}
.liuyao-six-head {
  font-family: var(--serif); font-size: 17px; font-weight: 700; letter-spacing: 1px;
  color: var(--ink); padding-bottom: 5px;
}
.liuyao-gua-title { min-width: 0; }
.liuyao-gua-title .gua-label {
  display: inline-flex; color: var(--jade); font-size: 11px; font-family: var(--serif); letter-spacing: 1px;
}
.liuyao-gua-title .gua-name {
  display: block; margin-top: 2px; font-family: var(--serif); font-size: 21px; line-height: 1.25;
  font-weight: 700; color: var(--ink); overflow-wrap: anywhere;
}
.liuyao-gua-title .gua-detail {
  display: block; margin-top: 2px; color: var(--ink-faint); font-size: 12px; overflow-wrap: anywhere;
}
.liuyao-chart { display: grid; gap: 7px; }
.liuyao-trad-row {
  display: grid; grid-template-columns: 52px minmax(220px, 1fr) minmax(220px, 1fr);
  gap: 10px; align-items: stretch; min-width: 0;
}
.trad-liushen {
  display: flex; align-items: center; justify-content: center;
  background: rgba(239,233,220,.72); border: 1px solid rgba(226,218,201,.9);
  border-radius: 8px; font-family: var(--serif); font-size: 15px; color: var(--ink);
}
.yao-side {
  min-width: 0; background: rgba(255,255,255,.72); border: 1px solid rgba(226,218,201,.9);
  border-radius: 8px; padding: 8px 9px;
}
.liuyao-trad-row.is-moving .yao-side:first-of-type { border-color: rgba(158,59,47,.32); background: rgba(158,59,47,.045); }
.liuyao-trad-row.is-shi .yao-side:first-of-type { box-shadow: inset 2px 0 0 rgba(158,59,47,.58); }
.liuyao-trad-row.is-ying .yao-side:first-of-type { box-shadow: inset 2px 0 0 rgba(63,102,81,.48); }
.yao-side-main {
  display: grid; grid-template-columns: minmax(0, 1fr) 104px 28px;
  align-items: center; gap: 8px; min-width: 0;
}
.yao-detail {
  min-width: 0; flex: initial; font-size: 16px; color: var(--ink); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.yao-side .yao-symbol {
  justify-self: end; width: 104px; display: grid; grid-template-columns: minmax(0, 1fr) 16px;
  align-items: center; gap: 4px;
  font-family: var(--mono); font-size: 14px; color: #111;
  white-space: nowrap; letter-spacing: 0;
}
.yao-bars { color: #111; justify-self: end; }
.yao-move {
  justify-self: center;
  font-family: var(--sans); font-size: 12px; line-height: 1;
  color: var(--cinnabar); font-weight: 700;
}
.yao-move.is-empty, .role-empty { visibility: hidden; }
.liuyao-trad-row.is-moving .yao-side:first-of-type .yao-move { color: var(--cinnabar); }
.fu-line {
  margin-top: 4px; color: var(--cinnabar); font-size: 12px; line-height: 1.4;
  overflow-wrap: anywhere;
}
.yao-side-empty {
  display: flex; align-items: center; justify-content: center;
  color: var(--ink-faint); font-size: 13px;
}
.liuyao-foot { margin-top: 12px; margin-bottom: 0; }
.gua-summary { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin: 8px 0 12px; }
.gua-card {
  min-width: 0; background: rgba(255,255,255,.68); border: 1px solid rgba(226,218,201,.9);
  border-radius: 8px; padding: 9px 10px;
}
.gua-label { display: block; color: var(--jade); font-size: 11px; font-family: var(--serif); letter-spacing: 1px; }
.gua-name { display: block; margin-top: 3px; font-family: var(--serif); font-size: 18px; line-height: 1.35; }
.gua-detail { display: block; margin-top: 3px; color: var(--ink-faint); font-size: 12px; overflow-wrap: anywhere; }
.yao-lines { display: grid; gap: 6px; }
.yao-row {
  display: grid; grid-template-columns: 38px 44px 102px minmax(0, 1fr);
  gap: 8px; align-items: center; min-width: 0;
  background: rgba(255,255,255,.58); border: 1px solid rgba(226,218,201,.82);
  border-radius: 8px; padding: 7px 9px;
}
.yao-row.is-moving { border-color: rgba(158,59,47,.28); background: rgba(158,59,47,.045); }
.yao-row.is-shi { box-shadow: inset 2px 0 0 rgba(158,59,47,.55); }
.yao-row.is-ying { box-shadow: inset 2px 0 0 rgba(63,102,81,.45); }
.yao-pos { font-family: var(--serif); color: var(--cinnabar); font-size: 13px; white-space: nowrap; }
.yao-spirit { color: var(--ink-faint); font-size: 12px; white-space: nowrap; }
.yao-row .yao-symbol { font-family: var(--mono); font-size: 12px; color: var(--ink); white-space: nowrap; letter-spacing: 0; }
.yao-row.is-moving .yao-symbol { color: var(--cinnabar); }
.yao-info { min-width: 0; }
.yao-main { display: flex; align-items: center; flex-wrap: wrap; gap: 5px; }
.yao-relation { font-size: 13px; color: var(--ink); }
.yao-najia { font-size: 12px; color: var(--ink-soft); }
.role-tag {
  display: inline-flex; border-radius: 999px; padding: 1px 7px;
  font-size: 11px; background: rgba(63,102,81,.1); color: var(--jade);
}
.role-世 { background: rgba(158,59,47,.1); color: var(--cinnabar); }
.yao-notes { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 3px; }
.yao-note, .yao-change { font-size: 12px; color: var(--ink-faint); overflow-wrap: anywhere; }
.yao-change { color: var(--jade); }

/* 奇门 */
.qimen-grid-wrap { overflow-x: auto; padding-bottom: 2px; }
.qimen-grid { min-width: 520px; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.qimen-cell {
  min-width: 0; min-height: 112px; background: rgba(255,255,255,.68);
  border: 1px solid rgba(226,218,201,.9); border-radius: 8px; padding: 9px;
}
.qimen-cell.is-zhifu { border-color: rgba(73,111,134,.42); box-shadow: inset 2px 0 0 #496f86; }
.qimen-cell-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.qimen-gong { font-family: var(--serif); font-size: 17px; color: var(--ink); letter-spacing: 1px; }
.qimen-stems { display: flex; gap: 7px; margin-top: 8px; font-size: 12px; color: var(--ink-soft); }
.qimen-tags { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 9px; }
.qimen-tag.star { background: rgba(73,111,134,.1); color: #496f86; }
.qimen-tag.men { background: rgba(63,102,81,.1); color: var(--jade); }
.qimen-tag.shen { background: rgba(176,141,79,.1); color: #7f6537; }

/* 解读 markdown */
.reading h3 { font-family: var(--serif); font-size: 17px; margin: 18px 0 8px; color: var(--ink);
  border-bottom: 1px dashed var(--line); padding-bottom: 4px; letter-spacing: 1px; }
.reading p { margin: 9px 0; }
.reading strong { color: var(--cinnabar); font-weight: 600; }
.reading ul, .reading ol { margin: 8px 0 8px 22px; }
.reading li { margin: 5px 0; }
.reading em { color: var(--jade); font-style: normal; background: rgba(63,102,81,.08); padding: 0 4px; border-radius: 4px; }
.grade { font-size: 12px; color: var(--ink-faint); }

.cursor::after { content: "▍"; color: var(--cinnabar); animation: blink 1s steps(2) infinite; }
@keyframes blink { 0%,50% { opacity: 1; } 51%,100% { opacity: 0; } }

.typing { display: inline-flex; gap: 4px; padding: 6px 2px; }
.typing span { width: 6px; height: 6px; border-radius: 50%; background: var(--ink-faint); animation: bob 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes bob { 0%,60%,100% { transform: translateY(0); opacity: .4; } 30% { transform: translateY(-5px); opacity: 1; } }

.err-note { color: var(--cinnabar); background: rgba(158,59,47,.06); border: 1px solid rgba(158,59,47,.2);
  padding: 10px 14px; border-radius: 10px; font-size: 14px; }

/* ── 输入区 ─────────────────────────────────────── */
.composer { flex-shrink: 0; padding: 12px 24px 16px; border-top: 1px solid var(--line);
  background: var(--paper); }
.composer-inner {
  max-width: 760px; margin: 0 auto; display: flex; align-items: flex-end; gap: 10px;
  background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 8px 8px 8px 16px;
  box-shadow: var(--shadow); transition: border-color .15s;
}
.composer-inner:focus-within { border-color: var(--gold); }
#input { flex: 1; border: none; outline: none; resize: none; font-size: 15px; line-height: 1.6;
  font-family: var(--sans); background: transparent; color: var(--ink); max-height: 180px; padding: 6px 0; }
.btn-send {
  width: 38px; height: 38px; flex-shrink: 0; border: none; border-radius: 11px; cursor: pointer;
  background: var(--cinnabar); color: #fff; font-size: 18px; transition: .15s;
}
.btn-send:hover { background: var(--cinnabar-2); }
.btn-send:disabled { background: var(--line); color: var(--ink-faint); cursor: not-allowed; }
.composer-note { max-width: 760px; margin: 8px auto 0; text-align: center; font-size: 11.5px; color: var(--ink-faint); }

/* ── 弹窗 ───────────────────────────────────────── */
.modal-mask { position: fixed; inset: 0; background: rgba(30,24,16,.5); display: grid; place-items: center; z-index: 50; padding: 20px; }
.modal-mask[hidden] { display: none; }   /* 类选择器会盖过 [hidden] 默认样式，显式补一条 */
.modal { background: var(--paper); border-radius: 16px; padding: 26px; width: 100%; max-width: 440px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3); max-height: 90vh; overflow-y: auto; }
.modal h3 { font-family: var(--serif); font-size: 20px; letter-spacing: 1px; }
.modal-desc { font-size: 13px; color: var(--ink-soft); line-height: 1.6; margin: 10px 0 18px; }
.modal label { font-size: 12px; color: var(--ink-faint); display: block; margin-bottom: 6px; letter-spacing: 1px; }
.code-box { display: flex; gap: 8px; align-items: center; background: #fff; border: 1px solid var(--line);
  border-radius: 10px; padding: 8px 10px; }
.code-box code { flex: 1; font-family: var(--mono); font-size: 13px; word-break: break-all; color: var(--ink); }
.code-box button, .row button, .btn-wide { background: var(--panel); color: var(--panel-ink); border: none;
  border-radius: 8px; padding: 8px 14px; font-size: 13px; cursor: pointer; white-space: nowrap; }
.code-box button:hover, .row button:hover, .btn-wide:hover { background: var(--cinnabar); color: #fff; }
.modal-section { margin-top: 20px; }
.row { display: flex; gap: 8px; }
.row input, .modal input[type=text], .modal input[type=password] {
  flex: 1; padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px;
  background: #fff; color: var(--ink); font-family: var(--sans); min-width: 0; }
.btn-wide { width: 100%; margin-top: 8px; }
.modal-hint { font-size: 12px; margin-top: 8px; min-height: 16px; }
.modal-hint.ok { color: var(--jade); }
.modal-hint.bad { color: var(--cinnabar); }
.modal-close { margin-top: 22px; width: 100%; background: none; border: 1px solid var(--line);
  border-radius: 8px; padding: 10px; cursor: pointer; color: var(--ink-soft); font-size: 14px; }
.modal-close:hover { background: var(--paper-2); }

/* ── 响应式 ─────────────────────────────────────── */
@media (max-width: 760px) {
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; z-index: 40; transform: translateX(-100%);
    transition: transform .2s; box-shadow: 4px 0 24px rgba(0,0,0,.2); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop {
    position: fixed; inset: 0; z-index: 35; display: block;
    background: rgba(30, 24, 16, .28);
    backdrop-filter: blur(1px);
  }
  .sidebar-backdrop[hidden] { display: none; }
  .hamburger { display: block; }
  .examples { grid-template-columns: 1fr; }
  .sys-hints { display: none; }
  .msg-row.user .bubble { max-width: 88%; }
  .ziwei-palaces { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 480px) {
  .topbar { height: 52px; padding: 0 16px; }
  .chat { padding-top: 14px; padding-bottom: 14px; }
  .welcome { margin-top: 2vh; padding: 0 24px 6px; }
  .welcome-glyph { font-size: 42px; }
  .welcome h2 { font-size: 25px; line-height: 1.35; margin-top: 14px; }
  .welcome-sub { font-size: 13.5px; line-height: 1.6; margin-top: 8px; }
  .examples { gap: 9px; margin-top: 20px; }
  .ex { border-radius: 10px; padding: 11px 14px; font-size: 13px; line-height: 1.45; }
  .msg-row { padding: 10px 16px; gap: 10px; }
  .avatar { width: 30px; height: 30px; border-radius: 8px; font-size: 15px; }
  .msg-row.assistant.has-liuyao-board { padding-inline: 8px; gap: 0; }
  .msg-row.assistant.has-liuyao-board .avatar { display: none; }
  .msg-row.user .bubble { max-width: 92%; padding: 10px 14px; overflow-wrap: anywhere; }
  .msg-row.assistant .bubble { font-size: 15px; line-height: 1.78; min-width: 0; }
  .board { font-size: 12px; padding: 12px 13px; }
  .bazi-board { padding: 12px; border-radius: 9px; }
  .bazi-head { margin-bottom: 10px; }
  .bazi-title { font-size: 17px; }
  .bazi-pillars { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .bazi-pillar { padding: 9px; border-radius: 8px; }
  .pillar-gz { font-size: 25px; }
  .wuxing-bars { grid-template-columns: 1fr; gap: 6px; }
  .wuxing-row { display: grid; grid-template-columns: 22px 1fr 20px; align-items: center; gap: 8px; padding: 7px 8px; }
  .wuxing-track { margin: 0; }
  .bazi-facts { grid-template-columns: 1fr; gap: 6px; }
  .luck-step { flex-basis: 104px; }
  .astro-board { padding: 12px; border-radius: 9px; }
  .astro-head { margin-bottom: 10px; flex-wrap: wrap; align-items: flex-start; }
  .astro-title { font-size: 17px; }
  .astro-meta { max-width: 100%; white-space: normal; overflow: visible; text-overflow: clip; }
  .astro-facts { grid-template-columns: 1fr; gap: 6px; margin-bottom: 10px; }
  .ziwei-palaces { grid-template-columns: 1fr; gap: 7px; }
  .gua-summary { grid-template-columns: 1fr; gap: 7px; }
  .liuyao-trad-board {
    padding: 10px 8px 12px;
    overflow-x: hidden;
    border-left-width: 3px;
  }
  .liuyao-meta-panel { padding: 7px 8px; margin-bottom: 9px; border-radius: 7px; }
  .liuyao-meta-line {
    grid-template-columns: 30px minmax(0, 1fr);
    gap: 6px;
    font-size: 12px;
    line-height: 1.5;
  }
  .meta-key { letter-spacing: 0; }
  .ganzhi-val { gap: 7px; }
  .liuyao-chart {
    gap: 0;
    overflow: hidden;
    border: 1px solid rgba(226,218,201,.82);
    border-radius: 8px;
    background: rgba(255,255,255,.34);
  }
  .liuyao-chart-head,
  .liuyao-trad-row {
    grid-template-columns: 28px minmax(0, 1fr) minmax(0, 1fr);
    gap: 0;
  }
  .liuyao-chart-head {
    margin: 7px 0 6px;
    padding: 0 3px;
  }
  .liuyao-six-head {
    justify-self: center;
    padding-bottom: 0;
    font-size: 12px;
    line-height: 1.1;
    letter-spacing: 0;
    writing-mode: vertical-rl;
  }
  .liuyao-gua-title .gua-label { font-size: 10px; letter-spacing: 0; }
  .liuyao-gua-title .gua-name { font-size: 15px; line-height: 1.2; }
  .liuyao-gua-title .gua-detail {
    font-size: 10px;
    line-height: 1.25;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .trad-liushen {
    align-self: stretch;
    border: 0;
    border-right: 1px solid rgba(226,218,201,.68);
    border-radius: 0;
    background: rgba(239,233,220,.42);
    font-size: 11px;
    line-height: 1.1;
    letter-spacing: 0;
    writing-mode: vertical-rl;
  }
  .liuyao-trad-row {
    min-height: 42px;
    border-top: 1px solid rgba(226,218,201,.68);
  }
  .liuyao-trad-row:first-child { border-top: 0; }
  .liuyao-trad-row.is-moving .yao-side:first-of-type {
    border-color: transparent;
    background: rgba(158,59,47,.035);
  }
  .liuyao-trad-row.is-shi .yao-side:first-of-type,
  .liuyao-trad-row.is-ying .yao-side:first-of-type {
    box-shadow: none;
  }
  .yao-side {
    min-height: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    padding: 7px 5px 6px;
  }
  .liuyao-trad-row .yao-side:nth-child(3) {
    border-left: 1px solid rgba(226,218,201,.68);
  }
  .yao-side-main {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 45px 15px;
    gap: 2px 4px;
    align-items: center;
    min-height: 24px;
  }
  .yao-detail {
    min-width: 0;
    flex: initial;
    font-size: 12px;
    line-height: 1.25;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .yao-side .yao-symbol {
    justify-self: end;
    width: 45px;
    grid-template-columns: minmax(0, 1fr) 8px;
    gap: 2px;
    overflow: visible;
    font-size: 8px;
    line-height: 1;
  }
  .yao-side .yao-move {
    font-size: 9px;
    transform: translateY(-.5px);
  }
  .yao-side .role-tag {
    justify-self: end;
    width: 15px;
    height: 15px;
    justify-content: center;
    align-items: center;
    padding: 0;
    font-size: 9px;
    line-height: 1;
    box-shadow: 0 1px 4px rgba(40,32,20,.06);
  }
  .fu-line {
    margin-top: 2px;
    font-size: 10px;
    line-height: 1.25;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .yao-row { grid-template-columns: 34px 42px minmax(0, 1fr); gap: 6px; padding: 7px 8px; }
  .yao-symbol { font-size: 11.5px; }
  .yao-info { grid-column: 1 / -1; }
  .qimen-grid { min-width: 480px; gap: 7px; }
  .qimen-cell { min-height: 106px; padding: 8px; }
  .composer { padding: 10px 16px max(12px, env(safe-area-inset-bottom)); }
  .composer-inner { border-radius: 14px; padding: 7px 7px 7px 14px; }
  #input { font-size: 14.5px; }
  .composer-note { display: none; }
  .modal-mask { align-items: end; padding: 12px; }
  .modal { max-height: calc(100dvh - 24px); border-radius: 14px; padding: 22px 18px; }
  .row { flex-direction: column; }
  .row button { width: 100%; }
}

@media (max-width: 340px) {
  .welcome { padding-inline: 22px; }
  .welcome-glyph { font-size: 38px; }
  .welcome h2 { font-size: 24px; }
  .examples { margin-top: 16px; }
  .ex { padding: 10px 13px; }
  .bazi-pillars { grid-template-columns: 1fr; }
  .liuyao-chart-head,
  .liuyao-trad-row {
    grid-template-columns: 24px minmax(0, 1fr) minmax(0, 1fr);
    gap: 0;
  }
  .liuyao-trad-board { padding-inline: 6px; }
  .liuyao-meta-panel { padding: 6px 7px; }
  .liuyao-meta-line {
    grid-template-columns: 28px minmax(0, 1fr);
    gap: 5px;
    font-size: 11px;
  }
  .liuyao-gua-title .gua-name { font-size: 14px; }
  .liuyao-gua-title .gua-detail { display: none; }
  .liuyao-six-head,
  .trad-liushen { font-size: 10px; }
  .liuyao-trad-row { min-height: 39px; }
  .yao-side { padding: 6px 3px 5px; }
  .yao-side-main {
    grid-template-columns: minmax(0, 1fr) 40px 14px;
    gap: 2px 3px;
    min-height: 22px;
  }
  .yao-detail { font-size: 11px; }
  .yao-side .yao-symbol {
    width: 40px;
    grid-template-columns: minmax(0, 1fr) 7px;
    font-size: 7.4px;
  }
  .yao-side .yao-move { font-size: 8.5px; }
  .yao-side .role-tag { width: 14px; height: 14px; font-size: 8.5px; }
  .fu-line { font-size: 9.5px; }
  .qimen-grid { min-width: 450px; }
  .composer { padding-inline: 12px; }
}
