/* =====================================================================
 * 命盘编排 v6 样式
 * 色调：米纸底 + 墨色文字 + 赭金强调；四化沿用 禄绿 / 权紫 / 科蓝 / 忌红
 * ===================================================================== */

:root {
  color-scheme: light;
  --ink: #2b2620;
  --ink-2: #645a4b;
  --ink-3: #9c907a;
  --paper: #f7f3ea;
  --card: #fffdf8;
  --card-2: #fbf7ee;
  --line: #e4dac6;
  --line-2: #cfc2a6;
  --line-strong: #8f7f5e;
  --accent: #8a6a3a;
  --accent-2: #a7834b;
  --accent-soft: #f3ead8;

  --lu: #2e8b57;
  --quan: #7b47a8;
  --ke: #2f6fd0;
  --ji: #c23b3b;

  --hd: #b5651d;   /* 大限 */
  --hy: #1f7a8c;   /* 流年 */

  --radius: 14px;
  --shadow: 0 1px 2px rgba(60, 45, 20, 0.04), 0 6px 24px rgba(60, 45, 20, 0.06);

  /* 盘面字号：以最小宽度 640px 为基准，窄屏靠横滚保证可读 */
  --fs-star-n: 11px;
  --fs-star-b: 7.5px;
  --fs-adj-n: 8.5px;
  --fs-cell-name: 11px;
  --fs-tiny: 7.5px;
  --fs-micro: 7px;
}

* { box-sizing: border-box; }

/* hidden 属性必须能压过组件自身的 display */
[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--paper);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  min-height: 100vh;
  min-height: calc(var(--vh, 1vh) * 100);
}

button { font-family: inherit; }

/* 去掉移动端 300ms 点击延迟与双击缩放（按钮、宫位、下拉） */
button, select, .cell, .sc-chip, .sc-btn, .seg-btn, .tab, a, label {
  touch-action: manipulation;
}

/* =====================================================================
 * 顶栏
 * ===================================================================== */

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: rgba(247, 243, 234, 0.92);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}

.topbar-in {
  max-width: 1240px;
  margin: 0 auto;
  padding: 10px 16px;
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  border: none;
  background: none;
  padding: 0;
  cursor: pointer;
  text-align: left;
  color: inherit;
}

.logo {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(145deg, #9a7744, #6f5229);
  color: #fdf6e6;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 600;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.15);
  flex-shrink: 0;
}

.brand-text b {
  display: block;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.brand-text i {
  display: block;
  font-style: normal;
  font-size: 11px;
  color: var(--ink-3);
  letter-spacing: 0.04em;
  margin-top: 1px;
}

.top-actions {
  display: flex;
  gap: 6px;
}

.tb-btn {
  position: relative;
  border: 1px solid var(--line-2);
  background: var(--card);
  color: var(--ink-2);
  font-size: 13px;
  padding: 7px 14px;
  border-radius: 999px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: border-color 0.15s, color 0.15s;
}

.tb-btn:hover { border-color: var(--accent); color: var(--accent); }

.tb-count {
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  line-height: 16px;
  text-align: center;
}

.tb-dot {
  position: absolute;
  top: 4px;
  right: 6px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #d98a2b;
}

@media (max-width: 480px) {
  .brand-text i { display: none; }
  .tb-btn { padding: 6px 11px; font-size: 12.5px; }
}

/* =====================================================================
 * 通用控件
 * ===================================================================== */

.seg {
  display: inline-flex;
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 3px;
  gap: 2px;
}

.seg-btn {
  border: none;
  background: transparent;
  color: var(--ink-2);
  font-size: 14px;
  padding: 7px 18px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}

.seg-btn.on {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 1px 3px rgba(110, 80, 30, 0.25);
}

.seg-sm .seg-btn { font-size: 12.5px; padding: 5px 13px; }

.tinput,
.tselect {
  width: 100%;
  border: 1px solid var(--line-2);
  background: var(--card);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 15px;
  color: var(--ink);
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  -webkit-appearance: none;
  appearance: none;
  min-height: 42px;
}

.tinput:focus,
.tselect:focus {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 3px rgba(167, 131, 75, 0.15);
}

.tselect {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6'><path d='M0 0l5 6 5-6z' fill='%239c907a'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 26px;
}

.tinput-sm { width: 120px; min-height: 36px; padding: 6px 10px; font-size: 14px; }

.link-btn {
  border: none;
  background: none;
  color: var(--accent);
  font-size: 12.5px;
  padding: 2px 0;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-color: rgba(138, 106, 58, 0.35);
}

.chip-btn {
  border: 1px solid var(--line-2);
  background: var(--card);
  color: var(--ink-2);
  font-size: 12px;
  padding: 5px 12px;
  border-radius: 999px;
  cursor: pointer;
}

.chip-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.chip-btn:disabled { opacity: 0.45; cursor: default; }

.switch {
  -webkit-appearance: none;
  appearance: none;
  width: 42px;
  height: 24px;
  border-radius: 999px;
  background: #c9bea6;
  border: 1px solid #b1a487;
  position: relative;
  cursor: pointer;
  transition: background 0.18s, border-color 0.18s;
  flex-shrink: 0;
  outline: none;
  margin: 0;
}

.switch::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  transition: left 0.18s;
  box-shadow: 0 1px 3px rgba(43, 38, 32, 0.35);
}

.switch:checked { background: var(--accent); border-color: #6f5229; }
.switch:checked::after { left: 20px; }
.switch:focus-visible { box-shadow: 0 0 0 3px rgba(167, 131, 75, 0.25); }

/* =====================================================================
 * 输入页
 * ===================================================================== */

.view-input {
  max-width: 620px;
  margin: 0 auto;
  padding: 22px 16px calc(48px + env(safe-area-inset-bottom));
}

.input-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 22px 22px 20px;
}

.ic-head { margin-bottom: 10px; }

.ic-head h2 {
  margin: 0 0 4px;
  font-size: 19px;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.ic-head p {
  margin: 0;
  font-size: 12px;
  color: var(--ink-3);
}

.frow {
  display: grid;
  grid-template-columns: 64px 1fr;
  gap: 12px;
  padding: 14px 0;
  border-top: 1px dashed var(--line);
  align-items: start;
}

.frow:first-of-type { border-top: none; }

.flabel {
  font-size: 13.5px;
  color: var(--ink-2);
  padding-top: 10px;
  letter-spacing: 0.06em;
}

.fctl {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.fctl > .seg { align-self: flex-start; }

.fhint {
  font-size: 12px;
  color: var(--ink-3);
  line-height: 1.6;
  min-height: 0;
}

.fhint:empty { display: none; }

.hint-warn { color: #b0641b; }

.date-lunar {
  display: grid;
  grid-template-columns: 1.3fr 1fr 1fr;
  gap: 6px;
}

.time-exact {
  display: flex;
  align-items: center;
  gap: 10px;
}

.time-exact .tinput { max-width: 180px; }

.time-tag {
  font-size: 13px;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 4px 11px;
  white-space: nowrap;
}

.shichen-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  gap: 6px;
}

.sc-btn {
  border: 1px solid var(--line);
  background: var(--card-2);
  border-radius: 10px;
  padding: 7px 4px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  color: var(--ink);
  transition: border-color 0.15s, background 0.15s;
}

.sc-btn b { font-size: 14px; font-weight: 500; }
.sc-btn i { font-style: normal; font-size: 10.5px; color: var(--ink-3); }
.sc-btn:hover { border-color: var(--line-2); }

.sc-btn.on {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.sc-btn.on i { color: rgba(255, 255, 255, 0.8); }

.switch-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: var(--ink);
  cursor: pointer;
  padding-top: 8px;
}

.place-box {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-start;
}

.place-search {
  position: relative;
  width: 100%;
}

.suggest {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  z-index: 20;
  list-style: none;
  margin: 0;
  padding: 4px;
  background: var(--card);
  border: 1px solid var(--line-2);
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(60, 45, 20, 0.14);
  max-height: 300px;
  overflow-y: auto;
}

.sg-item {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
}

.sg-item:hover { background: var(--accent-soft); }
.sg-item b { font-weight: 500; font-size: 14px; }
.sg-item span { font-size: 12px; color: var(--ink-3); }
.sg-item i { margin-left: auto; font-style: normal; font-size: 11px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.sg-empty { padding: 10px; font-size: 12.5px; color: var(--ink-3); }

.place-picked {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--accent-soft);
  border: 1px solid #e3d3b2;
  border-radius: 999px;
  padding: 5px 6px 5px 14px;
  font-size: 13.5px;
}

.pp-name { font-weight: 500; }
.pp-lng { color: var(--ink-3); font-size: 12px; }

.pp-clear {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: none;
  background: rgba(138, 106, 58, 0.12);
  color: var(--accent);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}

.manual-lng {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  color: var(--ink-2);
}

.preview {
  margin-top: 6px;
  background: linear-gradient(180deg, #faf5e9, #f6efdf);
  border: 1px solid #e8dcc2;
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.preview:empty { display: none; }

.pv-k {
  font-size: 11px;
  color: var(--ink-3);
  letter-spacing: 0.08em;
}

.pv-v { font-size: 14px; color: var(--ink); line-height: 1.55; }
.pv-v b { font-weight: 600; }
.pv-v em { font-style: normal; color: var(--ink-3); font-size: 12.5px; }
.pv-d { font-size: 12px; color: var(--ink-2); }
.pv-d b { font-weight: 500; }

.form-error {
  margin-top: 10px;
  color: #b42f2f;
  font-size: 13px;
  background: #fbeceb;
  border: 1px solid #efc6c3;
  border-radius: 10px;
  padding: 8px 12px;
}

.btn-primary {
  margin-top: 16px;
  width: 100%;
  border: none;
  background: linear-gradient(180deg, #957243, #7a5b2f);
  color: #fff;
  font-size: 16px;
  font-weight: 500;
  letter-spacing: 0.3em;
  padding: 14px 0;
  border-radius: 12px;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(122, 91, 47, 0.28);
  transition: transform 0.1s, box-shadow 0.15s;
}

.btn-primary:hover { box-shadow: 0 6px 18px rgba(122, 91, 47, 0.36); }
.btn-primary:active { transform: translateY(1px); }

@media (max-width: 480px) {
  .input-card { padding: 18px 16px 16px; border-radius: 16px; }
  .frow { grid-template-columns: 1fr; gap: 6px; padding: 12px 0; }
  .flabel { padding-top: 0; font-size: 12.5px; color: var(--ink-3); }
  .seg-btn { padding: 7px 14px; }
}

/* 最近排盘 */
.recent { margin-top: 18px; }

.recent-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12.5px;
  color: var(--ink-3);
  margin: 0 4px 8px;
  letter-spacing: 0.06em;
}

.recent-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 8px;
}

.recent-item {
  text-align: left;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 12px;
  padding: 10px 14px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 2px;
  color: var(--ink);
  transition: border-color 0.15s;
}

.recent-item:hover { border-color: var(--accent-2); }
.recent-item b { font-weight: 500; font-size: 14px; }
.recent-item span { font-size: 12px; color: var(--ink-3); }

/* =====================================================================
 * 命盘页
 * ===================================================================== */

.view-chart {
  max-width: 1240px;
  margin: 0 auto;
  padding: 14px 16px calc(48px + env(safe-area-inset-bottom));
}

.summary {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px 12px 18px;
  box-shadow: var(--shadow);
  margin-bottom: 10px;
}

.sum-text { flex: 1; min-width: 0; }

.sum-main {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 10px;
  font-size: 14px;
  color: var(--ink-2);
}

.sum-main b { font-size: 17px; color: var(--ink); font-weight: 600; letter-spacing: 0.03em; }

.sm-tag {
  font-size: 11px;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 4px;
  padding: 1px 6px;
}

.sum-sub {
  margin-top: 4px;
  font-size: 12px;
  color: var(--ink-3);
  line-height: 1.55;
}

.ss-ok { color: #3c7a4f; }

.sum-actions { display: flex; gap: 6px; flex-shrink: 0; }

.sa-btn {
  border: 1px solid var(--line-2);
  background: var(--card);
  color: var(--ink-2);
  font-size: 13px;
  padding: 7px 14px;
  border-radius: 10px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}

.sa-btn:hover { border-color: var(--accent); color: var(--accent); }

#btnEdit { background: var(--accent); border-color: var(--accent); color: #fff; }
#btnEdit:hover { background: #7a5b2f; color: #fff; }

@media (max-width: 640px) {
  .summary { flex-direction: column; align-items: stretch; padding: 12px 14px; }
  .sum-actions .sa-btn { flex: 1; }
}

.notice {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  padding: 9px 13px;
  border-radius: 10px;
  margin-bottom: 10px;
  line-height: 1.5;
}

.notice .link-btn { margin-left: auto; white-space: nowrap; }

.notice-warn { background: #fdf4e6; border: 1px solid #e8c795; color: #8f621c; }

.n-icon {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  line-height: 16px;
  text-align: center;
  border-radius: 50%;
  background: #d99a3e;
  color: #fff;
  font-size: 10px;
}

/* 两栏布局：宽屏左盘右详情，窄屏上下堆叠 */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

@media (min-width: 1080px) {
  .layout { grid-template-columns: minmax(0, 1fr) 360px; }
  .col-side { position: sticky; top: 70px; max-height: calc(100vh - 84px); overflow-y: auto; }
}

.col-main { min-width: 0; }

/* 工具条 */
.toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.tg-group { display: flex; gap: 6px; }

.tg {
  border: 1px solid var(--line-2);
  background: transparent;
  color: var(--ink-3);
  font-size: 12px;
  padding: 4px 12px;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.12s;
}

.tg.on { background: var(--card); border-color: var(--line-strong); color: var(--ink); }

.toolbar-hint { margin-left: auto; font-size: 11px; color: var(--ink-3); }

/* =====================================================================
 * 十二宫盘
 * ===================================================================== */

.chart-scroll {
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 2px;
  border-radius: 12px;
}

.chart {
  position: relative;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  aspect-ratio: 1 / 1;
  min-width: 640px;
  max-width: 860px;
  width: 100%;
  margin: 0 auto;
  background: var(--card);
  border: 1.5px solid var(--line-strong);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.chart-error {
  grid-area: 1 / 1 / 5 / 5;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  color: #c23b3b;
  font-size: 13px;
  line-height: 1.7;
}

.cell {
  position: relative;
  border: 0.5px solid var(--line-2);
  padding: 3px 13px 2px 4px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  cursor: pointer;
  background: var(--card);
  min-width: 0;
  min-height: 0;
  z-index: 1;
  transition: background 0.15s, box-shadow 0.15s;
  outline: none;
}

.cell:hover { background: #fbf5e6; }
.cell:focus-visible { box-shadow: inset 0 0 0 2px var(--accent-2); }

.cell-soul { background: #fdf7e9; }
.cell-body { background: #fdfaf2; }

/* 聚焦宫 + 三方四正 */
.cell.is-sf { background: #faf2df; }

.cell.is-focus {
  background: #f8ecd2;
  box-shadow: inset 0 0 0 2px var(--accent);
  z-index: 2;
}

/* 运限命宫：左侧色条 */
.cell.is-dming::before,
.cell.is-yming::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  width: 3px;
}

.cell.is-dming::before { left: 0; background: var(--hd); }
.cell.is-yming::after { left: 3px; background: var(--hy); }

.c-top {
  display: flex;
  align-items: baseline;
  gap: 3px;
  flex-shrink: 0;
  line-height: 1.3;
}

.pc-name {
  font-size: var(--fs-cell-name);
  color: var(--ink);
  font-weight: 600;
  white-space: nowrap;
}

.cell-soul .pc-name { color: #8a4b12; }

.body-tag {
  font-size: 7px;
  color: #fff;
  background: #b4643c;
  border-radius: 2px;
  padding: 0 2px;
  line-height: 1.4;
  flex-shrink: 0;
}

.decadal {
  margin-left: auto;
  font-size: var(--fs-tiny);
  color: var(--ink-3);
  white-space: nowrap;
}

.c-stars {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 0 1px;
  padding-top: 1px;
  overflow: hidden;
}

.c-rail {
  position: absolute;
  top: 15px;
  right: 2px;
  font-size: var(--fs-tiny);
  color: #b09a72;
  writing-mode: vertical-rl;
  text-orientation: upright;
  letter-spacing: 0.04em;
  line-height: 1;
  pointer-events: none;
}

.c-shen {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  font-size: var(--fs-micro);
  color: #b09a72;
  line-height: 1.4;
  letter-spacing: -0.02em;
}

.c-shen span { white-space: nowrap; }

.su {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.22;
  padding: 0 1px 1px;
}

.sn { font-style: normal; white-space: nowrap; letter-spacing: -0.01em; }

.sb {
  font-style: normal;
  font-size: var(--fs-star-b);
  color: #a89a7d;
  white-space: nowrap;
  line-height: 1.15;
}

.is-major .sn { font-size: var(--fs-star-n); color: #1f1b16; font-weight: 600; }
.is-minor .sn { font-size: 9.5px; color: #4a4237; }
.is-adj .sn { font-size: var(--fs-adj-n); color: #8c8170; }
.is-adj .sb { font-size: 6.5px; }

.sb-mut {
  font-style: normal;
  font-size: 6.5px;
  line-height: 1.35;
  padding: 0 2px;
  border-radius: 2px;
  color: #fff;
  margin-top: 0.5px;
  white-space: nowrap;
}

.mut-禄-bg { background: var(--lu); }
.mut-权-bg { background: var(--quan); }
.mut-科-bg { background: var(--ke); }
.mut-忌-bg { background: var(--ji); }
.mut-禄-fg { color: var(--lu); }
.mut-权-fg { color: var(--quan); }
.mut-科-fg { color: var(--ke); }
.mut-忌-fg { color: var(--ji); }

.self-mut { background: transparent !important; border: 0.6px dashed currentColor; }

/* 运限四化：实线框 = 大限，带底色 = 流年 */
.h-mut { background: transparent; border: 0.7px solid currentColor; font-weight: 600; }
.h-mut.h-y { background: rgba(31, 122, 140, 0.08); border-style: solid; border-radius: 6px; }

.empty-hint { font-size: 8px; color: #c4b89e; padding: 2px 3px 0 0; }

/* 运限流曜 */
.c-hstars {
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0 3px;
  font-size: 7.5px;
  line-height: 1.35;
}

.c-hstars i { font-style: normal; white-space: nowrap; }
.hs-d { color: var(--hd); }
.hs-y { color: var(--hy); }

.c-flow {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  font-size: var(--fs-micro);
  color: #9c8e73;
  line-height: 1.45;
  white-space: nowrap;
  overflow: hidden;
}

.c-flow i { font-style: normal; color: #b8a888; margin-right: 2px; }

.c-foot {
  flex-shrink: 0;
  display: flex;
  align-items: baseline;
  gap: 3px;
  font-size: var(--fs-tiny);
  color: var(--ink-3);
  line-height: 1.4;
}

.pc-rel { color: #b09a72; white-space: nowrap; margin-left: auto; }
.gz { color: var(--ink-2); letter-spacing: 0.02em; white-space: nowrap; font-weight: 500; }

.c-scope { display: flex; gap: 2px; }

.c-scope i,
.st-d,
.st-y {
  font-style: normal;
  font-size: 7.5px;
  color: #fff;
  border-radius: 2px;
  padding: 0 2px;
  line-height: 1.45;
  white-space: nowrap;
}

.st-d { background: var(--hd); }
.st-y { background: var(--hy); }

.triad-layer {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 3;
}

.hide-adj .is-adj { display: none; }
.hide-shen .c-shen,
.hide-shen .c-rail { display: none; }
.hide-triad .triad-layer { display: none; }

/* 中宫 */
.center {
  position: relative;
  z-index: 4;
  background: linear-gradient(180deg, #fffdf8, #fbf6ea);
  border: 0.5px solid var(--line-2);
  padding: 10px 10px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  min-width: 0;
  overflow: hidden;
}

.c-grp {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  min-width: 0;
}

.c-name {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.1em;
  color: var(--ink);
  line-height: 1.4;
}

.c-name:empty { display: none; }

.c-yy {
  font-size: 13px;
  font-weight: 500;
  color: var(--accent);
  letter-spacing: 0.06em;
  line-height: 1.5;
}

.c-line {
  font-size: 9.5px;
  color: var(--ink-2);
  line-height: 1.55;
  text-align: center;
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.c-line b { font-weight: 600; color: var(--ink); }

.c-cap {
  font-size: 8px;
  color: var(--ink-3);
  letter-spacing: 0.1em;
  margin-bottom: 3px;
}

.sh-wrap {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  row-gap: 2px;
}

.sh-item {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-size: 9px;
  color: var(--ink);
  white-space: nowrap;
}

.sh-item b { font-weight: 500; }
.sh-item em { font-style: normal; font-size: 7.5px; color: var(--ink-3); }

.sh-k {
  width: 11px;
  height: 11px;
  line-height: 11px;
  text-align: center;
  border-radius: 2px;
  color: #fff;
  font-size: 7.5px;
  font-style: normal;
  flex-shrink: 0;
}

.c-horo { gap: 3px; border-top: 1px dashed var(--line-2); padding-top: 5px; }

.ch-line {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 10px;
  color: var(--ink-2);
}

.ch-line b { font-weight: 600; color: var(--ink); }
.ch-line span { font-size: 9px; color: var(--ink-3); }

.pillars { border-collapse: collapse; margin: 2px 0 2px; }

.pillars td { text-align: center; padding: 0 7px; line-height: 1.25; }
.p-gan td, .p-zhi td { font-size: 18px; color: #1f1b16; font-weight: 600; }
.p-ss td { font-size: 8px; color: var(--ink-3); padding-top: 1px; }

/* 图例 */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  align-items: center;
  justify-content: center;
  margin: 10px 0 0;
  font-size: 11px;
  color: var(--ink-2);
}

.lg { display: inline-flex; align-items: center; gap: 4px; }

.dot { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.self-bg { background: transparent; border: 0.8px dashed var(--ink-3); }
.hd-bg { background: transparent; border: 1.2px solid var(--hd); }
.hy-bg { background: rgba(31, 122, 140, 0.12); border: 1.2px solid var(--hy); border-radius: 5px; }

/* =====================================================================
 * 运限时间轴
 * ===================================================================== */

.scope {
  margin-top: 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--shadow);
}

.scope-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.scope-title { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.scope-title b { font-size: 14px; font-weight: 600; letter-spacing: 0.08em; }

#scopeState {
  font-size: 12px;
  color: var(--ink-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#scopeState.active { color: var(--hd); font-weight: 500; }

.scope-actions { display: flex; gap: 6px; flex-shrink: 0; }

.scope-row {
  display: flex;
  align-items: stretch;
  gap: 10px;
  padding: 4px 0;
}

.scope-label {
  flex-shrink: 0;
  width: 28px;
  font-size: 12px;
  color: var(--ink-3);
  display: flex;
  align-items: center;
  letter-spacing: 0.06em;
}

.scope-list {
  flex: 1;
  min-width: 0;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding: 2px 1px 4px;
  scroll-behavior: smooth;
}

.scope-empty { font-size: 12px; color: var(--ink-3); padding: 8px 0; }

.sc-chip {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  border: 1px solid var(--line);
  background: var(--card-2);
  border-radius: 10px;
  padding: 5px 10px;
  cursor: pointer;
  color: var(--ink);
  min-width: 70px;
  transition: border-color 0.15s, background 0.15s;
}

.sc-chip b { font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }
.sc-chip i { font-style: normal; font-size: 10.5px; color: var(--ink-3); white-space: nowrap; }
.sc-chip:hover { border-color: var(--line-2); }

#decadalList .sc-chip.on { background: var(--hd); border-color: var(--hd); color: #fff; }
#yearlyList .sc-chip.on { background: var(--hy); border-color: var(--hy); color: #fff; }
.sc-chip.on i { color: rgba(255, 255, 255, 0.85); }

.sc-chip.is-now { position: relative; }
.sc-chip.is-now::after {
  content: '今';
  position: absolute;
  top: -6px;
  right: -4px;
  font-size: 9px;
  background: #d98a2b;
  color: #fff;
  border-radius: 6px;
  padding: 0 4px;
  line-height: 14px;
}

/* =====================================================================
 * 右侧详情面板
 * ===================================================================== */

.col-side {
  scroll-margin-top: 66px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.tabs {
  display: flex;
  border-bottom: 1px solid var(--line);
  background: var(--card-2);
  position: sticky;
  top: 0;
  z-index: 2;
}

.tab {
  flex: 1;
  border: none;
  background: none;
  padding: 12px 0 10px;
  font-size: 13.5px;
  color: var(--ink-3);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 0.15s, border-color 0.15s;
}

.tab.on { color: var(--ink); font-weight: 600; border-bottom-color: var(--accent); }

.tab-body { padding: 14px 16px 16px; }

.pd-head {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 6px;
}

.pd-title { display: flex; align-items: baseline; gap: 8px; }
.pd-title b { font-size: 18px; font-weight: 600; letter-spacing: 0.06em; }
.pd-title span { font-size: 14px; color: var(--ink-2); }

.pd-tags { display: flex; flex-wrap: wrap; gap: 4px; }
.pd-tags:empty { display: none; }

.ptag {
  font-style: normal;
  font-size: 11px;
  border-radius: 4px;
  padding: 1px 7px;
  background: var(--accent-soft);
  color: var(--accent);
}

.ptag-body { background: #f7e6dc; color: #a0522d; }
.ptag.st-d, .ptag.st-y { color: #fff; font-size: 11px; line-height: 1.6; padding: 1px 7px; border-radius: 4px; }
.ptag.st-d { background: var(--hd); }
.ptag.st-y { background: var(--hy); }

.pd-sec {
  display: grid;
  grid-template-columns: 40px 1fr;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px dashed #efe6d3;
}

.pd-k { font-size: 12px; color: var(--ink-3); padding-top: 3px; }
.pd-v { display: flex; flex-wrap: wrap; gap: 4px 6px; font-size: 13px; }
.pd-v .dim { color: var(--ink-3); font-size: 12px; padding-top: 2px; }

.star-chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  background: var(--card-2);
  border: 1px solid #eee4cf;
  border-radius: 6px;
  padding: 2px 6px;
}

.star-chip b { font-weight: 500; font-size: 13px; }
.star-chip em { font-style: normal; font-size: 11px; color: var(--ink-3); }

.pill {
  font-style: normal;
  font-size: 10.5px;
  color: #fff;
  border-radius: 4px;
  padding: 0 4px;
  line-height: 1.55;
}

.pill-o { background: transparent; border: 1px solid currentColor; }
.pill-o.h-y { background: rgba(31, 122, 140, 0.08); border-radius: 8px; }

/* 描边款需要压过 .pill 的白字 */
.pill.mut-禄-fg { color: var(--lu); }
.pill.mut-权-fg { color: var(--quan); }
.pill.mut-科-fg { color: var(--ke); }
.pill.mut-忌-fg { color: var(--ji); }
.pill.hs-d { color: var(--hd); }
.pill.hs-y { color: var(--hy); }

.pd-block { margin-top: 14px; }

.pd-cap {
  font-size: 12px;
  color: var(--ink-3);
  letter-spacing: 0.08em;
  margin-bottom: 6px;
}

.sf-row {
  width: 100%;
  display: grid;
  grid-template-columns: 34px 46px 36px 1fr;
  align-items: baseline;
  gap: 6px;
  text-align: left;
  border: none;
  background: none;
  border-bottom: 1px dashed #efe6d3;
  padding: 7px 2px;
  cursor: pointer;
  color: var(--ink);
  font-size: 13px;
}

.sf-row:hover { background: var(--card-2); }
.sf-k { font-size: 11px; color: var(--ink-3); }
.sf-row b { font-weight: 600; }
.sf-gz { font-size: 12px; color: var(--ink-2); }
.sf-stars { font-size: 12.5px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.pd-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}

.pd-grid > div {
  background: var(--card-2);
  border: 1px solid #efe6d3;
  border-radius: 8px;
  padding: 6px 9px;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.pd-grid span { font-size: 10.5px; color: var(--ink-3); }
.pd-grid b { font-size: 12.5px; font-weight: 500; }

.pd-note { font-size: 11px; color: var(--ink-3); margin: 12px 0 0; line-height: 1.6; }

/* 八字 */
.bz-table {
  width: 100%;
  border-collapse: collapse;
  text-align: center;
  font-size: 12.5px;
}

.bz-table th {
  font-weight: 400;
  color: var(--ink-3);
  font-size: 11px;
  padding: 5px 2px;
}

.bz-table tbody th { text-align: left; width: 38px; }
.bz-table td { padding: 5px 2px; border-top: 1px dashed #efe6d3; vertical-align: top; }
.bz-big td b { font-size: 24px; font-weight: 600; line-height: 1.2; }
.bz-ss td { color: var(--ink-2); font-size: 12px; }

.bz-hide { display: flex; justify-content: center; gap: 3px; align-items: baseline; line-height: 1.5; }
.bz-hide b { font-weight: 600; font-size: 13px; }
.bz-hide i { font-style: normal; font-size: 10.5px; color: var(--ink-3); }

.wx-木 { color: #3b8a3e; }
.wx-火 { color: #c8442f; }
.wx-土 { color: #9a6b2c; }
.wx-金 { color: #b08a14; }
.wx-水 { color: #2b6cb0; }

.bz-qy { font-size: 13px; color: var(--ink); line-height: 1.6; }

.dy-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 5px;
}

.dy-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--card-2);
  border: 1px solid #efe6d3;
  border-radius: 8px;
  padding: 6px 2px;
  line-height: 1.35;
}

.dy-cell b { font-size: 14px; font-weight: 600; }
.dy-cell i { font-style: normal; font-size: 10.5px; color: var(--ink-2); }
.dy-cell span { font-size: 10.5px; color: var(--ink-3); }
.dy-cell em { font-style: normal; font-size: 10px; color: #b9ab8d; }

/* 盘面信息 */
.info-list { display: flex; flex-direction: column; }

.info-row {
  display: grid;
  grid-template-columns: 76px 1fr;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px dashed #efe6d3;
  font-size: 13px;
}

.info-row span { color: var(--ink-3); font-size: 12px; }
.info-row b { font-weight: 500; line-height: 1.55; }

.rule-text { font-size: 12px; color: var(--ink-2); line-height: 1.75; margin-bottom: 10px; }

/* 页脚 */
.foot { margin-top: 28px; text-align: center; }
.foot p { font-size: 11.5px; color: var(--ink-3); line-height: 1.8; margin: 0 0 2px; }
.foot .dim { color: #bdb29a; font-size: 11px; }

/* =====================================================================
 * 抽屉
 * ===================================================================== */

.mask {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background: rgba(43, 38, 32, 0.32);
  z-index: 40;
  animation: fade 0.2s ease;
}

.drawer {
  position: fixed;
  z-index: 50;
  background: var(--paper);
  display: flex;
  flex-direction: column;
  box-shadow: 0 -8px 32px rgba(43, 38, 32, 0.14);
}

@media (min-width: 620px) {
  .drawer {
    top: 0;
    right: 0;
    bottom: 0;
    width: 400px;
    border-left: 1px solid var(--line);
    animation: slideIn 0.22s cubic-bezier(0.2, 0.8, 0.3, 1);
  }
}

@media (max-width: 619px) {
  .drawer {
    left: 0;
    right: 0;
    bottom: 0;
    max-height: 84vh;
    max-height: calc(var(--vh, 1vh) * 84);
    border-radius: 20px 20px 0 0;
    border-top: 1px solid var(--line);
    animation: slideUp 0.22s cubic-bezier(0.2, 0.8, 0.3, 1);
  }
}

.drawer-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px 12px;
  border-bottom: 1px solid var(--line);
}

.drawer-head h2 { margin: 0 0 4px; font-size: 16px; font-weight: 600; }
.drawer-sub { margin: 0; font-size: 11.5px; color: var(--ink-3); line-height: 1.5; }

.drawer-done {
  flex-shrink: 0;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  padding: 7px 16px;
  border-radius: 999px;
  cursor: pointer;
}

.drawer-body { flex: 1; overflow-y: auto; padding: 6px 0; -webkit-overflow-scrolling: touch; }

.rule-item { padding: 13px 20px; border-bottom: 1px solid #efe6d3; }
.rule-item:last-child { border-bottom: none; }

.ri-head { display: flex; align-items: center; gap: 8px; margin-bottom: 5px; }
.ri-label { font-size: 14px; color: var(--ink); }

.ri-changed {
  font-size: 9.5px;
  color: #fff;
  background: #d99a3e;
  border-radius: 4px;
  padding: 1px 5px;
}

.ri-hint { display: block; font-size: 11px; color: var(--ink-3); line-height: 1.55; margin-bottom: 8px; }
.ri-options { display: flex; flex-wrap: wrap; gap: 6px; }

.opt {
  border: 1px solid var(--line-2);
  background: var(--card);
  color: var(--ink-2);
  font-size: 12.5px;
  padding: 6px 13px;
  border-radius: 8px;
  cursor: pointer;
}

.opt.on { background: var(--accent); border-color: var(--accent); color: #fff; }

.reset-btn {
  margin: 10px 20px 20px;
  padding: 12px 0;
  border: 1px solid var(--line-2);
  background: var(--card);
  color: var(--ink-2);
  border-radius: 10px;
  font-size: 13px;
  cursor: pointer;
}

/* 命例 */
.rec-search { padding: 10px 20px 6px; }

.rec-item {
  display: flex;
  align-items: stretch;
  gap: 6px;
  margin: 6px 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}

.rec-open {
  flex: 1;
  min-width: 0;
  text-align: left;
  border: none;
  background: none;
  padding: 10px 12px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 2px;
  color: var(--ink);
}

.rec-open:hover { background: var(--card-2); }
.rec-open b { font-size: 14px; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.rec-open b i { font-style: normal; font-size: 11px; color: var(--accent); background: var(--accent-soft); border-radius: 4px; padding: 0 5px; font-weight: 400; }
.rec-open span { font-size: 12px; color: var(--ink-2); }
.rec-open em { font-style: normal; font-size: 11px; color: var(--ink-3); }

.rec-del {
  border: none;
  border-left: 1px solid var(--line);
  background: none;
  color: #b0473f;
  font-size: 12px;
  padding: 0 14px;
  cursor: pointer;
}

.rec-del:hover { background: #fbeceb; }

.rec-empty {
  padding: 40px 20px;
  text-align: center;
  font-size: 13px;
  color: var(--ink-3);
  line-height: 1.8;
}

/* 分享 */
@media (min-width: 620px) {
  .drawer-share { top: auto; bottom: auto; right: auto; left: 50%; top: 18vh; width: 480px; transform: translateX(-50%);
    border: 1px solid var(--line); border-radius: 16px; animation: fade 0.2s ease; }
}

.share-body { padding: 16px 20px 20px; display: flex; flex-direction: column; gap: 10px; }
.share-body .tinput { font-size: 12.5px; color: var(--ink-2); }
.share-row { display: flex; align-items: center; gap: 10px; }
.share-state { font-size: 12.5px; }
.share-state.ok { color: #3c7a4f; }
.share-state.warn { color: #b0641b; }
.share-note { margin: 0; font-size: 11.5px; color: var(--ink-3); }

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(28px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: rgba(43, 38, 32, 0.9);
  color: #fdf6e6;
  font-size: 13px;
  padding: 10px 18px;
  border-radius: 999px;
  z-index: 90;
  max-width: calc(100vw - 40px);
  text-align: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
}

.toast.show { animation: toastIn 0.22s ease; }

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideIn { from { transform: translateX(30px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes slideUp { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes toastIn { from { transform: translate(-50%, 10px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

@media print {
  .topbar, .summary .sum-actions, .toolbar, .scope, .notice, .foot, .tabs { display: none !important; }
  .layout { grid-template-columns: 1fr !important; }
  .col-side { position: static !important; max-height: none !important; box-shadow: none; }
  body { background: #fff; }
}


/* =====================================================================
 * v7：移动端与多浏览器适配
 * ===================================================================== */

/* ---------- 日期 / 时间下拉 ---------- */

.date-solar {
  display: grid;
  grid-template-columns: 1.5fr 1fr 1fr;
  gap: 6px;
}

.time-exact .tselect { width: auto; min-width: 0; flex: 0 1 120px; }
.time-exact #fMinute { flex-basis: 96px; }
.time-sep { color: var(--ink-3); font-size: 16px; margin: 0 -4px; }

/* ---------- 抽屉打开时锁定背景滚动（配合 app.js lockScroll） ---------- */

html.scroll-locked,
html.scroll-locked body { overflow: hidden; }
html.scroll-locked body { position: fixed; left: 0; right: 0; width: 100%; }

.drawer-body,
.ps-body,
.suggest { overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }

/* ---------- 旧浏览器提示 ---------- */

.old-browser {
  position: relative;
  z-index: 100;
  background: #fdf0e6;
  border-bottom: 1px solid #e8c795;
  color: #8f4a1c;
  padding: 14px 16px;
  font-size: 14px;
  line-height: 1.65;
  text-align: center;
}

.old-browser b { display: block; font-size: 15px; margin-bottom: 4px; }

/* ---------- aspect-ratio 兜底（Chrome < 88 / iOS < 15） ---------- */

@supports not (aspect-ratio: 1 / 1) {
  .chart { height: 640px; }
  @media (min-width: 900px) { .chart { height: 760px; } }
  @media (max-width: 640px) { .chart { height: calc((100vw - 16px) * 1.25); } }
}

/* ---------- 宫位详情底部面板 ---------- */

.psheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 45;
  background: var(--card);
  border-top: 1px solid var(--line);
  border-radius: 18px 18px 0 0;
  box-shadow: 0 -10px 40px rgba(60, 45, 20, 0.18);
  max-height: 56vh;
  max-height: calc(var(--vh, 1vh) * 56);
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
  transition: transform 0.22s cubic-bezier(0.2, 0.8, 0.3, 1);
  will-change: transform;
}

.psheet.in { animation: slideUp 0.22s cubic-bezier(0.2, 0.8, 0.3, 1); }

.ps-grip {
  flex-shrink: 0;
  display: flex;
  justify-content: center;
  padding: 9px 0 6px;
  touch-action: none;
  cursor: grab;
}

.ps-grip i { width: 40px; height: 4px; border-radius: 2px; background: var(--line-2); }

.ps-close {
  position: absolute;
  top: 8px;
  right: 10px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: var(--card-2);
  color: var(--ink-3);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

.ps-body { flex: 1; min-height: 0; overflow-y: auto; padding: 0 16px 14px; }
.ps-body .pd-head { padding-right: 40px; }

@media (min-width: 1080px) {
  .psheet { display: none !important; }
}

/* ---------- 触屏：去掉粘滞 hover，放大点击区域 ---------- */

@media (hover: none) {
  .cell:hover { background: var(--card); }
  .cell-soul:hover { background: #fdf7e9; }
  .cell.is-sf:hover { background: #faf2df; }
  .cell.is-focus:hover { background: #f8ecd2; }
  .tb-btn:hover, .sa-btn:hover, .chip-btn:hover:not(:disabled) { border-color: var(--line-2); color: var(--ink-2); }
  #btnEdit:hover { background: var(--accent); }
  .sc-chip:hover, .sc-btn:hover { border-color: var(--line); }
  .recent-item:hover, .sg-item:hover, .sf-row:hover, .rec-open:hover { background: inherit; }
}

/* iOS 输入框字号 < 16px 时聚焦会自动放大页面 */
@media (max-width: 640px), (pointer: coarse) {
  .tinput, .tselect, .tinput-sm { font-size: 16px; }
  .tinput, .tselect { min-height: 44px; }
  .seg-btn { min-height: 36px; }
  .tg, .chip-btn { min-height: 32px; }
}

.chart .cell { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }

/* ---------- 窄屏顶栏 ---------- */

@media (max-width: 380px) {
  .brand-text { display: none; }
  .tb-btn { padding: 6px 10px; font-size: 12.5px; }
  .seg-btn { padding: 7px 11px; }
}

/* ---------- 手机：盘面适配屏宽（不再横向滚动） ----------
 * 参考移动端排盘 App 的做法：星曜改竖排，每颗星占一列，
 * 窄格子里也能并排放下主星、辅星；流年 / 小限岁数收进详情面板。 */

@media (max-width: 640px) {
  .view-chart {
    padding: 10px 8px calc(40px + env(safe-area-inset-bottom));
    padding-left: max(8px, env(safe-area-inset-left));
    padding-right: max(8px, env(safe-area-inset-right));
  }

  .view-input {
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }

  .summary { padding: 10px 12px; margin-bottom: 8px; border-radius: 12px; }
  .sum-main { font-size: 13px; gap: 2px 8px; }
  .sum-main b { font-size: 16px; }
  .sum-sub { font-size: 11.5px; }
  .sa-btn { padding: 8px 0; }

  .notice { font-size: 12px; padding: 8px 10px; }

  .toolbar { margin-bottom: 6px; }
  .toolbar-hint { display: none; }
  .tg { padding: 5px 12px; font-size: 12.5px; }

  .chart-scroll { overflow: visible; border-radius: 8px; }

  .chart {
    min-width: 0;
    aspect-ratio: 4 / 5;
    border-width: 1px;
    border-radius: 8px;
  }

  .cell { padding: 2px 2px 1px 2px; }
  .chart:not(.hide-shen) .cell { padding-right: 11px; }
  .c-top { gap: 2px; line-height: 1.25; }
  .pc-name { font-size: 11.5px; }
  .decadal { font-size: 8.5px; }
  .body-tag { font-size: 8px; padding: 0 2px; }

  /* 星曜竖排：列与列之间留 2px，避免相邻两颗星连成一行 */
  .c-stars { gap: 1px 2px; padding-top: 2px; }
  .su { padding: 0; align-items: center; }
  .sn {
    -webkit-writing-mode: vertical-rl;
    writing-mode: vertical-rl;
    text-orientation: upright;
    letter-spacing: -1px;
    line-height: 1;
  }
  .is-major .sn { font-size: 13px; }
  .is-minor .sn { font-size: 11px; }
  .is-adj .sn { font-size: 9.5px; }
  .sb { font-size: 8.5px; line-height: 1.25; }
  .is-adj .sb { display: none; }

  .sb-mut {
    -webkit-writing-mode: vertical-rl;
    writing-mode: vertical-rl;
    text-orientation: upright;
    font-size: 8.5px;
    line-height: 1.05;
    padding: 1px 0;
    width: 11px;
    text-align: center;
    margin-top: 1px;
  }

  .empty-hint { font-size: 9.5px; padding: 2px 3px 0 1px; }

  .c-flow { display: none; }
  .c-hstars { font-size: 8.5px; gap: 0 2px; }
  .c-shen { font-size: 8px; line-height: 1.3; }
  .c-rail { font-size: 8px; top: 18px; right: 1px; }
  .c-foot { font-size: 8.5px; }
  .pc-rel { display: none; }
  .gz { margin-left: auto; }
  .c-scope i, .st-d, .st-y { font-size: 8.5px; padding: 0 1.5px; }
  .cell.is-dming::before, .cell.is-yming::after { width: 2px; }
  .cell.is-yming::after { left: 2px; }

  /* 中宫 */
  .center { padding: 6px 4px 5px; gap: 2px; }
  .c-name { font-size: 12.5px; }
  .c-yy { font-size: 12px; }
  .c-line { font-size: 9.5px; white-space: normal; line-height: 1.4; }
  .pillars td { padding: 0 4px; }
  .p-gan td, .p-zhi td { font-size: 17px; }
  .p-ss td { font-size: 8.5px; }
  .c-cap { font-size: 9px; margin-bottom: 2px; }
  .sh-wrap { gap: 2px 6px; }
  .sh-item { font-size: 10px; }
  .sh-item em { display: none; }
  .sh-k { width: 12px; height: 12px; line-height: 12px; font-size: 8.5px; }
  .ch-line { font-size: 10px; flex-wrap: wrap; justify-content: center; gap: 3px; }
  .center .c-opt { display: none; }

  .legend { font-size: 11px; gap: 4px 10px; margin-top: 8px; }

  .scope { margin-top: 10px; padding: 10px; border-radius: 12px; }
  .scope-head { flex-wrap: wrap; }
  .scope-label { width: 26px; }
  .sc-chip { min-width: 62px; padding: 5px 8px; }

  .layout { gap: 10px; }
  .tab { font-size: 13px; padding: 11px 0 9px; }
  .tab-body { padding: 12px; }
  .bz-big td b { font-size: 22px; }
  .dy-grid { gap: 4px; }

  .foot { margin-top: 20px; }
}

/* 超窄屏（iPhone SE 一代 / 小屏安卓 320–359px） */
@media (max-width: 359px) {
  .is-major .sn { font-size: 12px; }
  .is-minor .sn { font-size: 10px; }
  .is-adj .sn { font-size: 9px; }
  .pc-name { font-size: 10.5px; }
  .p-gan td, .p-zhi td { font-size: 15px; }
  .pillars td { padding: 0 3px; }
  /* 中宫仅约 150×190：去掉十神行与“生年四化”标题，保证四化行不被裁掉 */
  .center { padding: 4px 3px; gap: 1px; }
  .p-ss, .c-cap { display: none; }
  .c-line { font-size: 9px; line-height: 1.35; }
  .sh-wrap { gap: 1px 4px; }
  .sh-item { font-size: 9.5px; }
  .ch-line { font-size: 9.5px; gap: 2px; }
}