/* ========== 梅花易数 · 暖色简约紧凑主题 ========== */
:root {
  --bg: #FAF6F0;
  --card: #FFFDF9;
  --ink: #3B3228;
  --muted: #9A8B7A;
  --line: #EDE3D5;
  --primary: #C4562D;
  --primary-soft: #F6E7DC;
  --accent: #D9A441;
  --good: #6E8B3D;
  --warn: #B8860B;
  --bad: #B03A2E;
  --shadow: 0 1px 2px rgba(80, 60, 30, .07), 0 4px 14px rgba(80, 60, 30, .05);
  --radius: 12px;
  --kaiti: "KaiTi", "STKaiti", "Kaiti SC", "楷体", serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }

body {
  font-family: -apple-system, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.55;
  font-size: 13px;
  padding-bottom: 64px;
}

/* ---------- 顶栏（紧凑） ---------- */
.app-header {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 8px 14px;
  background: rgba(250, 246, 240, .94);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; }
.brand-seal {
  width: 32px; height: 32px; border-radius: 9px;
  background: var(--primary); color: #FFFDF9;
  display: grid; place-items: center;
  font-family: var(--kaiti); font-size: 17px;
  box-shadow: var(--shadow);
}
.brand-text h1 { font-size: 15px; letter-spacing: 2px; line-height: 1.1; }
.brand-sub { font-size: 9.5px; color: var(--muted); letter-spacing: 1px; }
.clock-wrap { text-align: right; min-width: 0; }
.clock { font-variant-numeric: tabular-nums; font-size: 11px; }
.clock-lunar { font-size: 10px; color: var(--muted); }

/* ---------- 视图容器 ---------- */
.view {
  max-width: 720px;
  margin: 0 auto;
  padding: 10px 10px 16px;
  animation: fadeIn .2s ease;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---------- 卡片 ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 10px 12px;
  margin-bottom: 10px;
}
.sec-head {
  display: flex; align-items: baseline; justify-content: space-between;
  font-size: 12px; color: var(--muted); font-weight: 600;
  letter-spacing: 2px; margin-bottom: 8px;
}
.sec-head small { font-weight: 400; letter-spacing: 0; color: var(--muted); }
.sec-head b { color: var(--primary); }

/* ---------- 六爻图（紧凑） ---------- */
.hx { display: flex; flex-direction: column; gap: 5px; padding: 4px 0; }
.hx-line { display: flex; align-items: center; }
.hx-line .bar { display: flex; height: 9px; flex: 1; max-width: 168px; }
.hx-line.yang .bar span { flex: 1; background: var(--ink); border-radius: 2px; }
.hx-line.yin .bar { gap: 0; }
.hx-line.yin .bar span { flex: 1; background: var(--ink); border-radius: 2px; }
.hx-line.yin .bar span:first-child { margin-right: 6px; }
.hx-line .tag { font-size: 10px; color: var(--muted); width: 62px; text-align: right; padding-left: 6px; flex: none; }
.hx-line.move .bar span { background: var(--primary); }
.hx-line.move { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .45; } }
.hx-line.move .tag { color: var(--primary); font-weight: 700; }

.hx-mini { display: flex; flex-direction: column; gap: 4px; align-items: center; }
.hx-mini .hx-line { display: flex; justify-content: center; }
.hx-mini .hx-line .bar { display: flex; flex: none; width: 54px; max-width: none; height: 7px; }
.hx-mini .hx-line .bar span { display: block; flex: none; height: 100%; background: var(--ink); border-radius: 2px; }
.hx-mini .hx-line.yang .bar span { width: 100%; }
.hx-mini .hx-line.yin .bar span { width: 24px; }
.hx-mini .hx-line.yin .bar span:first-child { margin-right: 6px; }
.hx-mini .hx-line.move .bar span { background: var(--primary); }
.hx-mini .hx-line .tag { display: none; }
.hx-mini-wrap { display: flex; justify-content: center; }
.hx-main { margin: 10px 0 4px; }

/* ---------- 卦名 ---------- */
.gua-name {
  font-family: var(--kaiti);
  font-size: 26px; letter-spacing: 3px;
  display: flex; align-items: baseline; gap: 8px;
}
.gua-name .symbol { font-size: 23px; }
.gua-sub { font-size: 11px; color: var(--muted); margin-top: 1px; }

/* ---------- 原文点击 -> 白话小字 ---------- */
.yw { position: relative; }
.yw-label {
  display: inline-block; font-size: 11px; color: var(--muted);
  background: var(--bg); border: 1px solid var(--line); border-radius: 999px;
  padding: 0 8px; margin-right: 6px; vertical-align: 1px;
}
.yw-click {
  cursor: pointer;
  text-decoration: underline dotted rgba(90, 70, 40, .35);
  text-underline-offset: 3px;
}
.yw-click:active { color: var(--primary); }
.bh-inline {
  font-size: 12px; color: #6B5D4E;
  background: var(--bg); border-left: 2px solid var(--accent);
  border-radius: 6px; padding: 5px 9px; margin-top: 5px;
}
.bh-tools { margin-top: 4px; }
.bh-edit-sm {
  font-size: 11px; color: var(--primary); background: none;
  border: 1px solid var(--line); border-radius: 999px; padding: 0 10px; cursor: pointer;
}
.bh-editor { margin-top: 6px; }
.bh-editor textarea {
  width: 100%; min-height: 56px; border: 1px solid var(--line); border-radius: 8px;
  padding: 6px 8px; font-size: 12px; font-family: inherit;
  background: var(--card); color: var(--ink); resize: vertical;
}
.bh-actions { display: flex; gap: 6px; margin-top: 5px; }
.bh-actions button { flex: 1; padding: 5px; border-radius: 999px; font-size: 12px; cursor: pointer; border: none; }
.bh-save { background: var(--primary); color: #FFFDF9; }
.bh-cancel { background: var(--bg); color: var(--muted); border: 1px solid var(--line) !important; }

/* ---------- 爻辞行 ---------- */
.yao-row {
  display: flex; gap: 8px; align-items: flex-start;
  padding: 6px 0; border-bottom: 1px dashed var(--line);
}
.yao-row:last-child { border-bottom: none; }
.yao-title {
  font-size: 12px; font-weight: 700; color: var(--muted);
  flex: none; width: 44px; padding-top: 1px;
}
.yao-title.is-moving { color: var(--primary); }
.yao-dot {
  display: inline-block; font-style: normal; font-size: 9px;
  background: var(--primary); color: #fff; border-radius: 999px; padding: 0 5px; margin-left: 4px;
}
.yao-row .yw { flex: 1; }
.yao-xx { font-size: 11px; color: var(--muted); margin-top: 2px; }

/* ---------- 断语 ---------- */
.verdict-chip {
  display: inline-block; padding: 2px 10px; border-radius: 999px;
  font-size: 11px; font-weight: 600; white-space: nowrap; flex: none;
}
.verdict-chip.l2 { background: #EAF0DD; color: var(--good); }
.verdict-chip.l1 { background: #FBF0DC; color: var(--warn); }
.verdict-chip.l0 { background: #F3EAE0; color: var(--muted); }
.verdict-chip.l-1 { background: #F6E0DA; color: var(--bad); }
.verdict-text { margin-top: 7px; font-size: 13px; }
.hero-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }

/* ---------- 按钮行 / 展开面板 ---------- */
.btn-row { display: flex; flex-wrap: wrap; gap: 6px; }
.btn-sm {
  flex: 1 1 30%; min-width: 84px; padding: 6px 4px;
  font-size: 12.5px; border-radius: 9px; cursor: pointer;
  background: var(--bg); border: 1px solid var(--line); color: var(--ink); font-family: inherit;
}
.btn-sm:active { transform: scale(.97); }
.btn-sm.on { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); font-weight: 700; }
.panel { margin-top: 8px; border-top: 1px dashed var(--line); padding-top: 8px; }
.mini-gua { text-align: center; }
.mini-gua .mg-name { font-family: var(--kaiti); font-size: 17px; }
.mini-gua .mg-name em { font-style: normal; font-size: 10px; color: var(--primary); margin-left: 4px; }
.mini-gua .mg-sub { font-size: 10.5px; color: var(--muted); }
.mini-gua .mg-note { font-size: 10.5px; color: var(--muted); margin-top: 3px; }
.mini-gua .hx-mini-wrap { margin-top: 5px; }
.back-now { margin-bottom: 10px; flex: none; min-width: auto; padding: 5px 14px; }

/* ---------- 时辰流转 ---------- */
.timeline { display: grid; grid-template-columns: 1fr 1.15fr 1fr; gap: 8px; }
.tl-legend { font-size: 10px; color: var(--muted); text-align: center; margin-bottom: 6px; letter-spacing: 1px; }
.tl-legend .dot { color: var(--primary); }
.tl-item {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 8px 4px; text-align: center; cursor: pointer;
  transition: transform .1s ease;
}
.tl-item:active { transform: scale(.96); }
.tl-item.is-now { border-color: var(--primary); background: var(--primary-soft); }
.tl-label { font-size: 10px; color: var(--muted); }
.tl-item.is-now .tl-label { color: var(--primary); font-weight: 700; }
.tl-gua { font-family: var(--kaiti); font-size: 16px; margin-top: 2px; }
.tl-gua small { font-size: 10px; color: var(--muted); font-family: sans-serif; }
.tl-item .hx-mini-wrap { margin-top: 4px; }

/* ---------- 详情五栏 ---------- */
.gua-five { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin-bottom: 10px; }
.gua-box {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 8px 2px; text-align: center; cursor: pointer;
  box-shadow: var(--shadow);
}
.gua-box:active { transform: scale(.95); }
.gua-box .g-name { font-family: var(--kaiti); font-size: 16px; }
.gua-box .g-sub { font-size: 10px; color: var(--muted); }
.gua-box .hx-mini-wrap { margin-top: 5px; }
.gua-note { font-size: 11px; color: var(--muted); text-align: center; margin: -4px 0 10px; }

/* ---------- chips ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  background: var(--bg); border: 1px solid var(--line); border-radius: 999px;
  padding: 2px 10px; font-size: 11.5px;
}
.chip b { color: var(--primary); }

/* ---------- 时间起卦 ---------- */
.form-row { margin-bottom: 10px; }
.form-row label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
input[type="date"], select {
  width: 100%; padding: 8px 10px; border-radius: 9px;
  border: 1px solid var(--line); background: var(--card);
  font-size: 13.5px; color: var(--ink); font-family: inherit;
}
.btn {
  display: block; width: 100%; padding: 10px;
  border: none; border-radius: 10px; background: var(--primary); color: #FFFDF9;
  font-size: 14px; letter-spacing: 2px; cursor: pointer;
  box-shadow: var(--shadow);
}
.btn:active { transform: scale(.98); }
.calc-box {
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 10px; font-size: 12.5px; margin-top: 10px;
}
.calc-box div { padding: 1.5px 0; }
.calc-box .hl { color: var(--primary); font-weight: 600; }
.calc-result { margin-top: 10px; }

/* ---------- 卦库 ---------- */
.gua-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 7px; }
.gua-cell {
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: 7px 2px; text-align: center; cursor: pointer;
  box-shadow: var(--shadow); transition: transform .1s ease;
}
.gua-cell:active { transform: scale(.94); }
.gua-cell .sym { font-size: 16px; }
.gua-cell .nm { font-family: var(--kaiti); font-size: 13.5px; margin-top: 1px; }
.gua-cell .xu { font-size: 9.5px; color: var(--muted); }

/* ---------- 设置 ---------- */
.set-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 9px 0; border-bottom: 1px solid var(--line);
}
.set-row:last-child { border-bottom: none; }
.set-row .t { font-size: 13px; }
.set-row .d { font-size: 11px; color: var(--muted); }
.switch { position: relative; width: 42px; height: 24px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; inset: 0; border-radius: 999px; background: #DCD2C2;
  transition: .2s; cursor: pointer;
}
.switch .slider::before {
  content: ""; position: absolute; width: 18px; height: 18px; border-radius: 50%;
  background: #fff; top: 3px; left: 3px; transition: .2s;
}
.switch input:checked + .slider { background: var(--primary); }
.switch input:checked + .slider::before { transform: translateX(18px); }
.about-text { font-size: 12px; color: var(--muted); }
.about-text b { color: var(--ink); }
.about-text p { margin-bottom: 5px; }

/* ---------- 底部导航 ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex;
  background: rgba(255, 253, 249, .97);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
  max-width: 720px; margin: 0 auto;
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 1px;
  padding: 4px 0; border: none; background: none; cursor: pointer;
  font-size: 17px; color: var(--muted); font-family: inherit;
}
.tab span { font-size: 10px; letter-spacing: 1px; }
.tab.is-active { color: var(--primary); }
.tab.is-active span { font-weight: 700; }

/* ---------- 提示 ---------- */
.toast {
  position: fixed; left: 50%; bottom: 74px; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: #FDFAF4; font-size: 12.5px;
  padding: 7px 16px; border-radius: 999px; opacity: 0; pointer-events: none;
  transition: .25s ease; z-index: 50; max-width: 86vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--bad); }

/* 白话隐藏模式（设置里关掉白话时） */
body.no-baihua .bh-inline { display: none; }

/* ---------- 大屏适配 ---------- */
@media (min-width: 760px) {
  .view { padding-top: 16px; }
  .card { padding: 12px 16px; }
  .hx-line .bar { max-width: 200px; }
}
@media (max-width: 560px) {
  .gua-five { grid-template-columns: repeat(3, 1fr); }
}
