/* =====================================================================
 * 样式：玄机阁 · 国学易学系统 — 道教国风主题
 * 职责：设计令牌(tokens)、三套主题(宣纸/深色/浅色)、横竖排版、古籍版式、
 *       太极八卦动画、组件样式(卦盘/四柱表/五行/朱砂印)。
 * 配色：黑金、朱砂红、古玉黄、水墨青。
 * 约定：主题切换 [data-theme=paper|dark|light]；排版 [data-orient=h|v]。
 * ===================================================================== */

/* ── 设计令牌（默认=宣纸古籍主题） ───────────────────────────── */
:root,
[data-theme='paper'] {
  --bg: #e9dcc0;
  --bg-deep: #ddcba6;
  --panel: #f3ead4;
  --panel-2: #ece0c4;
  --ink: #2b241a;          /* 墨 */
  --ink-soft: #6b5d46;
  --gold: #9c7b32;         /* 古金 */
  --gold-bright: #b8923f;
  --cinnabar: #b0402e;     /* 朱砂红 */
  --jade: #2e6f5e;         /* 水墨青 */
  --jade-soft: #4f8a78;
  --jade-yellow: #c8a13a;  /* 古玉黄 */
  --line: rgba(43, 36, 26, 0.28);
  --line-strong: rgba(43, 36, 26, 0.5);
  --shadow: 0 10px 34px rgba(60, 44, 20, 0.18);
  --paper-texture: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.05'/%3E%3C/svg%3E");
}

[data-theme='dark'] {
  --bg: #14110c;
  --bg-deep: #0d0b08;
  --panel: #1d1810;
  --panel-2: #241d12;
  --ink: #ece3cd;
  --ink-soft: #b6a784;
  --gold: #c8a24a;
  --gold-bright: #e1bf66;
  --cinnabar: #c64a36;
  --jade: #4f9d86;
  --jade-soft: #5fae95;
  --jade-yellow: #d8b75a;
  --line: rgba(200, 162, 74, 0.22);
  --line-strong: rgba(200, 162, 74, 0.45);
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.55);
  --paper-texture: none;
}

[data-theme='light'] {
  --bg: #f6f1e7;
  --bg-deep: #ece4d4;
  --panel: #ffffff;
  --panel-2: #f7f2e8;
  --ink: #2a2620;
  --ink-soft: #7a7060;
  --gold: #a9842f;
  --gold-bright: #c19a3c;
  --cinnabar: #c0392b;
  --jade: #2e7d63;
  --jade-soft: #4f9a80;
  --jade-yellow: #c9a23b;
  --line: rgba(42, 38, 32, 0.16);
  --line-strong: rgba(42, 38, 32, 0.34);
  --shadow: 0 10px 30px rgba(80, 70, 50, 0.12);
  --paper-texture: none;
}

/* ── 基础 ─────────────────────────────────────────────────── */
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: 'Noto Serif SC', 'Source Han Serif SC', 'Songti SC', 'STSong', 'SimSun', serif;
  color: var(--ink);
  background: var(--bg);
  background-image: var(--paper-texture);
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  transition: background-color .4s ease, color .4s ease;
}
h1, h2, h3, h4 { font-weight: 600; margin: 0; letter-spacing: .04em; }
a { color: var(--jade); text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
::selection { background: var(--cinnabar); color: #fff; }

/* ── 顶栏 ─────────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 16px;
  padding: 12px 22px;
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border-bottom: 1px solid var(--gold);
  box-shadow: 0 2px 0 var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand .taiji { width: 38px; height: 38px; animation: spin 18s linear infinite; }
.brand-title { font-size: 20px; letter-spacing: .14em; color: var(--ink); }
.brand-title b { color: var(--cinnabar); }
.brand-sub { font-size: 11px; color: var(--ink-soft); letter-spacing: .3em; }
.topbar .spacer { flex: 1; }
.toolbtn {
  border: 1px solid var(--line-strong); background: transparent; color: var(--ink);
  border-radius: 4px; padding: 6px 12px; font-size: 13px; letter-spacing: .08em;
  transition: all .2s;
}
.toolbtn:hover { border-color: var(--gold); color: var(--gold-bright); }
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 5px; overflow: hidden; }
.seg button { border: 0; background: transparent; color: var(--ink-soft); padding: 6px 11px; font-size: 12px; }
.seg button.on { background: var(--gold); color: #fff; }

/* ── 布局：侧栏 + 主区 ───────────────────────────────────── */
.layout { display: grid; grid-template-columns: 232px 1fr; min-height: calc(100vh - 63px); }
.sidebar {
  border-right: 1px solid var(--line); padding: 18px 12px;
  background: linear-gradient(180deg, var(--panel) 0%, transparent 100%);
}
.nav-title { font-size: 12px; color: var(--ink-soft); letter-spacing: .3em; padding: 6px 10px 10px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  border: 0; background: transparent; color: var(--ink);
  padding: 11px 12px; border-radius: 6px; text-align: left; font-size: 15px;
  border: 1px solid transparent; transition: all .18s;
}
.nav-item .gua { font-size: 18px; color: var(--gold); width: 22px; text-align: center; }
.nav-item:hover { background: var(--panel-2); }
.nav-item.on { background: var(--panel-2); border-color: var(--gold); color: var(--cinnabar); }
.nav-item.on .gua { color: var(--cinnabar); }
.nav-foot { margin-top: 18px; padding: 12px 10px; font-size: 11px; color: var(--ink-soft); border-top: 1px dashed var(--line); }

.main { padding: 26px 32px 60px; max-width: 1080px; }
.page-head { display: flex; align-items: baseline; gap: 14px; margin-bottom: 18px; padding-bottom: 12px; border-bottom: 2px solid var(--gold); }
.page-head h2 { font-size: 26px; letter-spacing: .12em; }
.page-head .en { color: var(--ink-soft); font-size: 12px; letter-spacing: .25em; text-transform: uppercase; }
.page-desc { color: var(--ink-soft); font-size: 14px; margin: -6px 0 18px; }

/* ── 卡片 / 古籍双线框 ───────────────────────────────────── */
.panel {
  position: relative; background: var(--panel); border: 1px solid var(--line-strong);
  border-radius: 8px; padding: 20px 22px; margin-bottom: 18px; box-shadow: var(--shadow);
}
.panel::before {
  content: ''; position: absolute; inset: 5px; border: 1px solid var(--line);
  border-radius: 5px; pointer-events: none;
}
.panel > * { position: relative; }
.panel-title {
  font-size: 16px; color: var(--gold-bright); letter-spacing: .1em; margin-bottom: 14px;
  display: flex; align-items: center; gap: 8px;
}
.panel-title::before { content: '◈'; color: var(--cinnabar); }

/* ── 表单 ─────────────────────────────────────────────────── */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; }
.field label { display: block; font-size: 13px; color: var(--ink-soft); margin-bottom: 6px; letter-spacing: .08em; }
.field input, .field select, .field textarea {
  width: 100%; padding: 9px 11px; font-family: inherit; font-size: 14px;
  color: var(--ink); background: var(--bg); border: 1px solid var(--line-strong); border-radius: 5px;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--gold); }
.btn-row { margin-top: 16px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.btn {
  background: linear-gradient(180deg, var(--cinnabar), #8f2f22); color: #f7eede;
  border: 0; padding: 10px 26px; border-radius: 6px; font-size: 15px; letter-spacing: .14em;
  box-shadow: 0 4px 14px rgba(176, 64, 46, .35);
}
.btn.ghost { background: transparent; color: var(--gold-bright); border: 1px solid var(--gold); box-shadow: none; }
.btn:active { transform: translateY(1px); }

/* ── 卦象 / 爻线 ─────────────────────────────────────────── */
.hex-symbol { font-size: 58px; line-height: 1; color: var(--cinnabar); text-shadow: 0 2px 0 var(--line); }
.gua-stack { display: inline-flex; flex-direction: column-reverse; gap: 7px; }
.yao { display: flex; align-items: center; gap: 4px; width: 132px; height: 14px; }
.yao .bar { height: 12px; background: var(--ink); border-radius: 2px; }
.yao.yang .bar { width: 100%; }
.yao.yin .bar { width: 46%; }
.yao.moving .bar { background: var(--cinnabar); box-shadow: 0 0 0 1px var(--cinnabar); }
.yao .tag { font-size: 11px; color: var(--cinnabar); margin-left: 6px; }

/* ── 四柱 / 表格 ─────────────────────────────────────────── */
.grid-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.grid-table th, .grid-table td { border: 1px solid var(--line-strong); padding: 9px 8px; text-align: center; }
.grid-table th { background: var(--panel-2); color: var(--gold-bright); letter-spacing: .1em; font-weight: 600; }
.pillar-gan { font-size: 26px; color: var(--cinnabar); line-height: 1.2; }
.pillar-zhi { font-size: 26px; color: var(--jade); line-height: 1.2; }
.muted { color: var(--ink-soft); font-size: 12px; }

/* 五行色块 */
.wx { display: inline-block; min-width: 22px; padding: 1px 7px; border-radius: 3px; font-size: 12px; color: #fff; }
.wx-木 { background: #2e6f5e; } .wx-火 { background: #c8442f; } .wx-土 { background: #b08a2e; }
.wx-金 { background: #9a8a66; } .wx-水 { background: #3a4a5e; }
.wx-bars { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; text-align: center; }
.wx-bars .bar-wrap { height: 90px; display: flex; flex-direction: column; justify-content: flex-end; }
.wx-bars .bar { border-radius: 4px 4px 0 0; transition: height .5s; }

/* 朱砂方印 */
.seal {
  display: inline-grid; place-items: center; width: 56px; height: 56px;
  border: 2px solid var(--cinnabar); border-radius: 6px; color: var(--cinnabar);
  font-size: 13px; line-height: 1.15; letter-spacing: .05em; padding: 4px;
  transform: rotate(-3deg); font-weight: 600;
}

/* 结论 / 提示条 */
.verdict { border-left: 3px solid var(--gold); padding: 6px 14px; margin: 8px 0; background: var(--panel-2); border-radius: 0 6px 6px 0; }
.luck-吉 { color: var(--jade); font-weight: 600; }
.luck-凶 { color: var(--cinnabar); font-weight: 600; }
.luck-半吉, .luck-平 { color: var(--jade-yellow); font-weight: 600; }
.note { font-size: 12px; color: var(--ink-soft); margin-top: 10px; font-style: italic; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1px solid var(--line-strong); border-radius: 20px; padding: 4px 12px; font-size: 13px; }

/* 古籍版式：原文区（竖排时右起） */
.classical {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px;
  padding: 14px 18px; color: var(--ink); font-size: 16px; letter-spacing: .06em; line-height: 2;
}
[data-orient='v'] .classical {
  writing-mode: vertical-rl; text-orientation: upright; max-height: 320px;
}
[data-orient='v'] .pillars-wrap { direction: rtl; }

/* ── 加载遮罩：太极旋 + 八卦环 ──────────────────────────── */
.loading {
  position: fixed; inset: 0; z-index: 80; display: none; place-items: center;
  background: rgba(10, 8, 5, .55); backdrop-filter: blur(3px);
}
.loading.on { display: grid; }
.loader-core { position: relative; width: 180px; height: 180px; display: grid; place-items: center; }
.loader-core .bagua { position: absolute; inset: 0; animation: spin-rev 12s linear infinite; }
.loader-core .taiji { width: 86px; height: 86px; animation: spin 3.2s linear infinite; }
.loader-text { position: absolute; bottom: -34px; width: 100%; text-align: center; color: var(--gold-bright); letter-spacing: .3em; font-size: 13px; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes spin-rev { to { transform: rotate(-360deg); } }
@keyframes fade-up { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.result-in { animation: fade-up .45s ease both; }

/* ── 首页/介绍 ────────────────────────────────────────── */
.hero { text-align: center; padding: 30px 0 10px; }
.hero .big-taiji { width: 110px; height: 110px; animation: spin 26s linear infinite; }
.hero h1 { font-size: 34px; letter-spacing: .2em; margin: 14px 0 6px; }
.hero h1 b { color: var(--cinnabar); }
.hero p { color: var(--ink-soft); letter-spacing: .15em; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; margin-top: 24px; }
.card {
  border: 1px solid var(--line-strong); border-radius: 8px; padding: 18px; background: var(--panel);
  cursor: pointer; transition: all .2s; position: relative; box-shadow: var(--shadow);
}
.card:hover { transform: translateY(-3px); border-color: var(--gold); }
.card .ico { font-size: 30px; color: var(--gold); }
.card h3 { margin: 8px 0 4px; font-size: 18px; letter-spacing: .08em; }
.card p { margin: 0; font-size: 12.5px; color: var(--ink-soft); }

/* ── 玄空九宫飞星盘 ──────────────────────────────────────── */
.luoshu { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; max-width: 460px; margin: 4px auto; }
.lcell {
  aspect-ratio: 1 / 1; border: 1px solid var(--line-strong); border-radius: 6px;
  background: var(--panel-2); display: flex; flex-direction: column; align-items: center; justify-content: center;
  position: relative; gap: 4px;
}
.lcell.wealth { border-color: var(--jade); box-shadow: inset 0 0 0 1px var(--jade); }
.lcell.ding { background: linear-gradient(180deg, var(--panel-2), rgba(200,162,74,.12)); }
.lcell .ldir { position: absolute; top: 6px; font-size: 11px; color: var(--ink-soft); letter-spacing: .05em; }
.lcell .lstars { display: flex; align-items: baseline; gap: 8px; font-size: 26px; line-height: 1; margin-top: 8px; }
.lcell .lstars .lyun { font-size: 15px; color: var(--ink-soft); }
.lcell .lflag { position: absolute; bottom: 6px; font-size: 11px; color: var(--cinnabar); letter-spacing: .08em; }

/* ── 奇门九宫盘（复用 .luoshu 容器，单元用 .qcell 承载星门神） ── */
.luoshu.qimen { grid-template-columns: repeat(3, 1fr); }
.qcell {
  aspect-ratio: 1 / 1; border: 1px solid var(--line-strong); border-radius: 6px;
  background: var(--panel-2); display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; padding: 6px; position: relative; text-align: center;
}
.qcell.zhifu { border-color: var(--cinnabar); box-shadow: inset 0 0 0 1px var(--cinnabar); }
.qcell.center { background: linear-gradient(180deg, var(--panel-2), rgba(200,162,74,.1)); }
.qcell .qtop { display: flex; justify-content: space-between; width: 100%; font-size: 12px; }
.qcell .qdir { color: var(--ink-soft); }
.qcell .qmid { font-size: 15px; color: var(--jade); }
.qcell .qgan { display: inline-flex; flex-direction: column; line-height: 1; vertical-align: middle; }
.qcell .qgan b { color: var(--cinnabar); font-size: 18px; }
.qcell .qgan span { color: var(--ink-soft); font-size: 12px; }
.qcell .qstar { font-size: 15px; color: var(--jade); }

/* ── 知识库可点元素 + 查典弹窗 ──────────────────────────── */
.kb-link { cursor: pointer; border-bottom: 1px dotted var(--gold); transition: color .15s; }
.kb-link:hover { color: var(--gold-bright); border-bottom-style: solid; }
.kb-mask {
  position: fixed; inset: 0; z-index: 95; display: grid; place-items: center;
  background: rgba(10, 8, 5, .6); backdrop-filter: blur(3px); animation: fade-up .25s ease;
}
.kb-card {
  position: relative; width: 580px; max-width: 92vw; max-height: 82vh; overflow: auto;
  background: var(--panel); border: 1px solid var(--gold); border-radius: 10px;
  padding: 22px 24px; box-shadow: var(--shadow);
}
.kb-close { position: absolute; top: 12px; right: 14px; border: 0; background: transparent; color: var(--ink-soft); font-size: 18px; cursor: pointer; }
.kb-close:hover { color: var(--cinnabar); }
.kb-title { font-size: 18px; color: var(--cinnabar); letter-spacing: .08em; margin-bottom: 14px; padding-right: 28px; }
.kb-sec { font-size: 13px; color: var(--gold-bright); letter-spacing: .12em; margin: 14px 0 6px; border-top: 1px dashed var(--line); padding-top: 10px; }

/* ── 付费解锁弹窗 ──────────────────────────────────────── */
.pay-mask {
  position: fixed; inset: 0; z-index: 90; display: grid; place-items: center;
  background: rgba(10, 8, 5, .6); backdrop-filter: blur(4px); animation: fade-up .25s ease;
}
.pay-card {
  width: 340px; max-width: 92vw; text-align: center; padding: 26px 24px;
  background: var(--panel); border: 1px solid var(--gold); border-radius: 12px; box-shadow: var(--shadow);
}
.pay-card .taiji { animation: spin 14s linear infinite; }
.pay-title { font-size: 18px; letter-spacing: .1em; margin: 10px 0 2px; color: var(--ink); }
.pay-price { font-size: 30px; color: var(--cinnabar); font-weight: 700; }
.pay-price span { font-size: 13px; color: var(--ink-soft); font-weight: 400; }
.pay-card .qr { margin: 14px auto; display: inline-block; }
.pay-tip { font-size: 12px; color: var(--ink-soft); line-height: 1.6; margin-bottom: 16px; }
.pay-btns { display: flex; flex-direction: column; gap: 10px; }

/* ── 响应式 ──────────────────────────────────────────── */
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { display: flex; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); gap: 6px; }
  .sidebar .nav-title, .nav-foot { display: none; }
  .nav-item { white-space: nowrap; }
  .main { padding: 18px; }
  .brand-sub { display: none; }
}
