/* ==========================================================================
   奇门遁甲 · 传统文化学习工具 — 全局样式
   「新中式 · 玄金玉简」双主题
   ========================================================================== */

/* ---------- 设计令牌 ---------- */
:root {
  /* 浅色 · 玄金（默认） */
  --bg: #f5f0e8;
  --bg-card: #fdfaf4;
  --ink: #2b2620;
  --ink-light: #6b6258;
  --indigo: #2c3e6b;
  --indigo-dark: #1e2d52;
  --gold: #b8860b;
  --gold-light: #d4a843;
  --border: #e2d8c4;
  --shadow: 0 4px 20px rgba(44, 62, 107, 0.06);
  --radius: 14px;

  /* 四盘 */
  --c-tian: #2c6faa;
  --c-ren: #2e7d52;
  --c-shen: #7b4fa0;
  --c-di: #8b6914;

  /* 吉凶 */
  --ji-t: #2e6b3e; --ji-bg: rgba(46,125,82,.10); --ji-bd: rgba(46,125,82,.40);
  --xiong-t: #8a3a2a; --xiong-bg: rgba(160,58,43,.10); --xiong-bd: rgba(160,58,43,.40);
  --ping-t: #5a5a5a; --ping-bg: rgba(90,90,90,.08); --ping-bd: rgba(90,90,90,.30);

  --serif: "Songti SC","STSong","SimSun","Noto Serif SC",serif;
  --kai: "Kaiti SC","STKaiti","KaiTi","Noto Serif SC",serif;
  --mono: "SF Mono","Menlo","Consolas",monospace;
}

[data-theme="dark"] {
  --bg: #1a1a2e;
  --bg-card: #252540;
  --ink: #e8dfcf;
  --ink-light: #b8ad9a;
  --indigo: #5b7db8;
  --indigo-dark: #4a6a9e;
  --gold: #d4a843;
  --gold-light: #e3c069;
  --border: #3a3a5c;
  --shadow: 0 4px 20px rgba(0,0,0,.4);
  --c-tian: #5b9bd5;
  --c-ren: #4caf7a;
  --c-shen: #a670d6;
  --c-di: #c9a35f;
  --ji-t: #7dc394; --ji-bg: rgba(76,175,122,.14); --ji-bd: rgba(76,175,122,.45);
  --xiong-t: #e08a72; --xiong-bg: rgba(224,138,114,.14); --xiong-bd: rgba(224,138,114,.45);
  --ping-t: #b8ad9a; --ping-bg: rgba(184,173,154,.10); --ping-bd: rgba(184,173,154,.35);
}

/* ---------- 基础 ---------- */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--serif);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  transition: background .3s, color .3s;
  padding-bottom: 72px;
}
h1, h2, h3, h4 { font-family: var(--kai); font-weight: 700; margin: 0 0 .4em; }
p { margin: .3em 0; }
button { font-family: var(--serif); cursor: pointer; }
input, select { font-family: var(--serif); }
a { color: var(--indigo); text-decoration: none; }
.hidden { display: none !important; }
.mono { font-family: var(--mono); }
.hint { color: var(--ink-light); font-size: 12px; margin: .4em 0; }
.small { font-size: 12px; color: var(--ink-light); }
.muted { color: var(--ink-light); }

/* ---------- 顶部 ---------- */
.app-header {
  display: flex; align-items: center; gap: 14px;
  padding: 16px 18px 12px;
  position: sticky; top: 0; z-index: 20;
  background: var(--bg);
  border-bottom: 2px solid transparent;
  border-image: linear-gradient(90deg, var(--indigo), var(--gold), var(--indigo)) 1;
}
.seal {
  width: 48px; height: 48px; flex: 0 0 auto;
  border-radius: 10px;
  background: var(--indigo);
  color: var(--gold-light);
  font-family: var(--kai); font-size: 30px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow);
}
.header-titles { flex: 1; }
.header-titles h1 { font-size: 20px; margin: 0; letter-spacing: 2px; }
.header-titles p { font-size: 12px; color: var(--ink-light); margin: 0; letter-spacing: 1px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--bg-card);
  color: var(--ink); font-size: 18px;
  transition: all .2s;
}
.icon-btn:hover { border-color: var(--gold); box-shadow: var(--shadow); }

/* ---------- 主内容 ---------- */
.app-main { max-width: 760px; margin: 0 auto; padding: 16px 14px 24px; }
.view { display: none; }
.view.active { display: block; animation: fadeIn .25s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- 卡片 ---------- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 14px;
}

/* ---------- 分段控件 ---------- */
.seg { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.seg-item {
  flex: 1 1 auto; min-width: 64px;
  padding: 8px 10px; border-radius: 9px;
  border: 1px solid var(--border); background: transparent; color: var(--ink);
  font-size: 13px; transition: all .2s; white-space: nowrap;
}
.seg-item.active {
  background: linear-gradient(135deg, var(--indigo), var(--indigo-dark));
  color: #fdfaf4; border-color: transparent; box-shadow: var(--shadow);
}

/* ---------- 表单 ---------- */
.field-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.field-row label { width: 66px; color: var(--ink-light); font-size: 13px; }
.field-row input, .field-row select {
  flex: 1; min-width: 140px;
  padding: 9px 10px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--bg); color: var(--ink);
  font-size: 14px;
}
.field-row input:focus, .field-row select:focus { outline: none; border-color: var(--indigo); }
.mode-body { padding: 6px 0; }

/* ---------- 按钮 ---------- */
.btn-primary {
  width: 100%; padding: 13px; border: none; border-radius: 11px;
  background: linear-gradient(135deg, var(--indigo), var(--indigo-dark));
  color: #fdfaf4; font-size: 16px; font-family: var(--kai); letter-spacing: 4px;
  box-shadow: var(--shadow); transition: all .2s;
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 8px 26px rgba(44,62,107,.22); }
.btn-ghost {
  flex: 1; padding: 10px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--bg-card); color: var(--ink);
  font-size: 13px; transition: all .2s;
}
.btn-ghost:hover { border-color: var(--gold); color: var(--gold); }

/* ---------- 图层开关 ---------- */
.layer-toggles { display: flex; gap: 14px; margin-top: 12px; flex-wrap: wrap; }
.layer-toggles label { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-light); cursor: pointer; }
.layer-toggles input { display: none; }
.layer-toggles .dot { width: 12px; height: 12px; border-radius: 3px; display: inline-block; border: 1px solid transparent; opacity: .35; transition: all .2s; }
.layer-toggles .dot.shen { background: var(--c-shen); }
.layer-toggles .dot.tian { background: var(--c-tian); }
.layer-toggles .dot.ren { background: var(--c-ren); }
.layer-toggles .dot.di { background: var(--c-di); }
.layer-toggles input:checked + .dot { opacity: 1; box-shadow: 0 0 0 2px var(--gold-light); }

/* ==========================================================================
   九宫格
   ========================================================================== */
.board-wrap { display: flex; justify-content: center; padding: 20px 10px; }
.gong-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  grid-template-areas:
    "g4 g9 g2"
    "g3 g5 g7"
    "g8 g1 g6";
  gap: 8px;
  width: 100%; max-width: 360px;
  aspect-ratio: 1 / 1;
}
.gong {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  padding: 7px 6px 5px;
  display: flex; flex-direction: column; gap: 2px;
  cursor: pointer; overflow: hidden;
  transition: box-shadow .2s, border-color .2s, transform .2s;
}
.gong:hover, .gong:focus-visible {
  border-color: var(--indigo); box-shadow: var(--shadow); transform: translateY(-2px);
  outline: none;
}
.gong.selected { border-color: var(--gold-light); box-shadow: 0 0 0 2px var(--gold-light); background: var(--bg-card); }
.gong-1 { grid-area: g1; } .gong-2 { grid-area: g2; } .gong-3 { grid-area: g3; }
.gong-4 { grid-area: g4; } .gong-5 { grid-area: g5; } .gong-6 { grid-area: g6; }
.gong-7 { grid-area: g7; } .gong-8 { grid-area: g8; } .gong-9 { grid-area: g9; }

/* 值符 / 值使光晕 */
.gong.zhifu { background: radial-gradient(circle, rgba(212,168,67,.22), transparent 70%); }
.gong.zhishi { background: radial-gradient(circle, rgba(44,62,107,.14), transparent 70%); }
.gong.kong { border-style: dashed; }
.gong.fuyin { background: rgba(120,120,120,.12); }
.gong.fanyin { background: rgba(160,58,43,.14); }

.gong-head { display: flex; justify-content: space-between; align-items: center; font-size: 11px; color: var(--ink-light); }
.gong-head .gong-name { font-family: var(--kai); }
.gong-head .trigram { font-size: 16px; color: var(--ink-light); }

/* 分层行 */
.grow { display: flex; align-items: center; gap: 5px; font-size: 12px; min-height: 17px; line-height: 1.25; }
.grow .bar { width: 3px; height: 12px; border-radius: 2px; flex: 0 0 auto; }
.grow .bar.shen { background: var(--c-shen); }
.grow .bar.tian { background: var(--c-tian); }
.grow .bar.ren { background: var(--c-ren); }
.grow .bar.di { background: var(--c-di); }
.grow .val { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.grow.shen-row .val { color: var(--c-shen); font-size: 11px; }
.grow.tian-row .val { color: var(--c-tian); font-size: 12px; font-weight: 600; }
.grow.ren-row .val { color: var(--c-ren); font-size: 12px; font-weight: 600; }
.grow.di-row .val { color: var(--c-di); font-size: 12px; }
.grow .gan { font-family: var(--mono); }
.grow .star-mark { font-size: 10px; opacity: .7; }

/* 状态角标 */
.gong-badges { position: absolute; top: 4px; right: 4px; display: flex; gap: 3px; flex-wrap: wrap; }
.badge {
  font-size: 9px; padding: 1px 4px; border-radius: 4px; line-height: 1.4;
  background: var(--ping-bg); color: var(--ping-t); border: 1px solid var(--ping-bd);
}
.badge.kong { border-style: dashed; }
.badge.ma { background: rgba(212,168,67,.18); color: var(--gold); border-color: rgba(212,168,67,.5); }
.badge.mu, .badge.xing { background: var(--xiong-bg); color: var(--xiong-t); border-color: var(--xiong-bd); }

/* 格局标签（宫底） */
.gong-geju { display: flex; flex-wrap: wrap; gap: 3px; margin-top: auto; }
.geju-tag {
  font-size: 10px; padding: 1px 6px; border-radius: 6px; cursor: pointer;
  border: 1px solid; line-height: 1.6; white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis;
}
.geju-tag.ji { color: var(--ji-t); background: var(--ji-bg); border-color: var(--ji-bd); }
.geju-tag.xiong { color: var(--xiong-t); background: var(--xiong-bg); border-color: var(--xiong-bd); }
.geju-tag.ping { color: var(--ping-t); background: var(--ping-bg); border-color: var(--ping-bd); }

/* ==========================================================================
   信息面板 / 格局列表
   ========================================================================== */
.info-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.info-item { padding: 8px 10px; border-radius: 8px; background: var(--bg); border: 1px solid var(--border); }
.info-item .k { font-size: 11px; color: var(--ink-light); }
.info-item .v { font-size: 14px; font-weight: 600; font-family: var(--mono); }

.section-title { font-family: var(--kai); font-size: 16px; color: var(--indigo); margin: 4px 0 8px; border-left: 3px solid var(--gold); padding-left: 8px; }
.geju-list-item { display: flex; align-items: center; gap: 8px; padding: 8px; border-bottom: 1px dashed var(--border); }
.geju-list-item:last-child { border-bottom: none; }
.geju-list-item .tag { flex: 0 0 auto; }
.geju-list-item .name { font-weight: 600; }
.geju-list-item .desc { font-size: 12px; color: var(--ink-light); }

.action-row { display: flex; gap: 10px; margin-top: 4px; }

/* ==========================================================================
   查阅 / 工具 / 我的
   ========================================================================== */
.knowledge-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
.knowledge-item {
  padding: 12px 8px; text-align: center; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--border); background: var(--bg); transition: all .2s;
}
.knowledge-item:hover { border-color: var(--gold); transform: translateY(-2px); }
.knowledge-item.active { border-color: var(--indigo); background: var(--indigo); color: #fdfaf4; }
.knowledge-item .ki-name { font-family: var(--kai); font-size: 15px; font-weight: 700; }
.knowledge-item .ki-sub { font-size: 11px; opacity: .75; }

.detail-block { margin-bottom: 14px; }
.detail-block h4 { font-size: 14px; color: var(--indigo); margin: 0 0 6px; border-bottom: 1px dashed var(--border); padding-bottom: 4px; }
.detail-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.detail-table td, .detail-table th { border: 1px solid var(--border); padding: 6px 8px; text-align: left; }
.detail-table th { background: var(--bg); color: var(--indigo); font-weight: 600; }
.xiangyi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 6px; }
.xiangyi-grid .xy { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px; font-size: 12px; }
.xy b { color: var(--indigo); }

.geju-dict { margin-bottom: 10px; }
.geju-dict .grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 6px; }
.geju-dict .cell {
  padding: 8px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); cursor: pointer; font-size: 13px;
}
.geju-dict .cell:hover { border-color: var(--gold); }

.term-card { text-align: center; padding: 10px; }
.term-card .term-word { font-family: var(--kai); font-size: 26px; color: var(--indigo); margin: 8px 0; }
.term-card .term-desc { font-size: 14px; }

.table-scroll { overflow-x: auto; }
table.plain { width: 100%; border-collapse: collapse; font-size: 13px; }
table.plain th, table.plain td { border: 1px solid var(--border); padding: 7px 8px; text-align: center; }
table.plain th { background: var(--bg); color: var(--indigo); }

.history-item { display: flex; align-items: center; gap: 10px; padding: 10px; border-bottom: 1px dashed var(--border); }
.history-item .h-main { flex: 1; }
.history-item .h-time { font-size: 12px; color: var(--ink-light); }
.history-item .h-sum { font-size: 13px; }
.star-btn { border: none; background: none; font-size: 20px; color: var(--ink-light); }
.star-btn.on { color: var(--gold); }

.dianji-section { margin-bottom: 16px; }
.dianji-section .yuanwen { font-family: var(--kai); font-size: 15px; line-height: 2; }
.dianji-section .zhushi { font-size: 13px; color: var(--ink-light); border-left: 3px solid var(--gold); padding-left: 10px; }

.term-jump { color: var(--indigo); border-bottom: 1px dashed var(--indigo); cursor: pointer; }

/* ---------- 底部 Tab ---------- */
.tab-bar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  display: flex; background: var(--bg-card);
  border-top: 1px solid var(--border);
  box-shadow: 0 -2px 12px rgba(0,0,0,.05);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab-item {
  flex: 1; padding: 8px 0 6px; border: none; background: none; color: var(--ink-light);
  display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px;
}
.tab-item .tab-icon {
  width: 30px; height: 30px; border-radius: 8px; display: flex; align-items: center; justify-content: center;
  font-family: var(--kai); font-size: 16px; font-weight: 700; color: var(--ink-light);
  transition: all .2s;
}
.tab-item.active { color: var(--indigo); }
.tab-item.active .tab-icon { background: linear-gradient(135deg, var(--indigo), var(--indigo-dark)); color: #fdfaf4; }

/* ---------- 弹层 ---------- */
.overlay { position: fixed; inset: 0; z-index: 50; display: none; }
.overlay.open { display: block; }
.overlay-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.45); }
.sheet {
  position: absolute; bottom: 0; left: 0; right: 0; max-height: 82vh; overflow-y: auto;
  background: var(--bg-card); border-radius: 18px 18px 0 0; padding: 16px 18px 20px;
  animation: slideUp .25s ease;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: none; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.sheet-head h3 { margin: 0; font-size: 18px; }
.sheet-body { font-size: 14px; }
.sheet-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 14px; }
.term-progress { font-size: 13px; color: var(--ink-light); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%) translateY(20px);
  background: var(--indigo-dark); color: #fdfaf4; padding: 10px 20px; border-radius: 24px;
  font-size: 13px; opacity: 0; pointer-events: none; transition: all .3s; z-index: 100;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- 页脚 ---------- */
.disclaimer { max-width: 760px; margin: 6px auto 0; padding: 0 14px; }
.disclaimer p { font-size: 11px; color: var(--ink-light); line-height: 1.7; }

/* ---------- 响应式 ---------- */
@media (max-width: 768px) {
  .gong-grid { gap: 5px; }
  .grow { font-size: 11px; min-height: 15px; }
  .grow .bar { width: 2px; }
  .gong { padding: 5px 4px 3px; }
  .app-header { padding: 12px 14px 10px; }
}
@media (min-width: 769px) {
  .gong-grid { gap: 10px; }
  .grow { font-size: 13px; }
}
