/* ============================================================
   金钱占 · 六爻纳甲 — 古典宣纸/水墨风
   ============================================================ */

:root {
  --paper: #f4ecd8;          /* 宣纸底 */
  --paper-2: #efe6cf;
  --ink: #2b2620;            /* 墨色 */
  --ink-soft: #5a4f42;
  --ink-faint: #8a7d6b;
  --line: #c9b896;
  --vermilion: #a8362b;     /* 朱砂 */
  --vermilion-soft: #c0594b;
  --gold: #9a7b3a;
  --jade: #4a6b5a;
  --shadow: rgba(43, 38, 32, 0.12);
  --shadow-strong: rgba(43, 38, 32, 0.22);
  --radius: 4px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: "Songti SC", "STSong", "SimSun", "Noto Serif CJK SC", "Source Han Serif SC", serif;
  line-height: 1.75;
  -webkit-text-size-adjust: 100%;
}

body {
  background-image:
    radial-gradient(ellipse at 20% 0%, rgba(168, 54, 43, 0.04), transparent 50%),
    radial-gradient(ellipse at 80% 100%, rgba(154, 123, 58, 0.06), transparent 50%);
  min-height: 100vh;
}

/* ---------------- 头部 ---------------- */
.app-header {
  max-width: 960px;
  margin: 0 auto;
  padding: 20px 18px 0;
  text-align: center;
}

.app-title { margin-bottom: 14px; }

.app-title h1 {
  font-size: 1.6rem;
  margin: 6px 0 2px;
  letter-spacing: 4px;
  font-weight: 700;
}

.subtitle {
  font-size: 0.82rem;
  color: var(--ink-faint);
  margin: 0;
  letter-spacing: 1px;
}

.seal {
  display: inline-block;
  background: var(--vermilion);
  color: var(--paper);
  width: 34px;
  height: 34px;
  line-height: 34px;
  border-radius: 3px;
  font-size: 1.2rem;
  font-weight: 700;
  box-shadow: 0 2px 6px var(--shadow);
  transform: rotate(-4deg);
}

/* ---------------- 导航 ---------------- */
.tabs {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 0;
}

.tab {
  appearance: none;
  background: transparent;
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 9px 16px;
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--ink-soft);
  cursor: pointer;
  transition: all 0.18s ease;
}

.tab:hover { color: var(--vermilion); background: rgba(168, 54, 43, 0.06); }

.tab.active {
  color: var(--paper);
  background: var(--ink);
  font-weight: 600;
}

/* ---------------- 主区 ---------------- */
#view { max-width: 960px; margin: 0 auto; padding: 24px 18px 60px; }

.view { display: none; animation: fadeIn 0.25s ease; }
.view.active { display: block; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------------- 通用组件 ---------------- */
.panel {
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 18px;
  box-shadow: 0 1px 3px var(--shadow);
}

.panel h2 {
  font-size: 1.2rem;
  margin: 0 0 12px;
  padding-bottom: 8px;
  border-bottom: 1px dashed var(--line);
  letter-spacing: 2px;
}

.panel h3 {
  font-size: 1.02rem;
  margin: 18px 0 8px;
  color: var(--vermilion);
}

p { margin: 0.6em 0; }

.note {
  font-size: 0.82rem;
  color: var(--ink-faint);
  padding: 8px 12px;
  border-left: 3px solid var(--gold);
  background: rgba(154, 123, 58, 0.06);
  margin: 10px 0;
}

.btn {
  appearance: none;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.95rem;
  padding: 9px 18px;
  border-radius: var(--radius);
  border: 1px solid var(--ink-soft);
  background: var(--paper);
  color: var(--ink);
  transition: all 0.15s ease;
}
.btn:hover { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.btn:active { transform: translateY(1px); }

.btn.primary {
  background: var(--vermilion);
  color: var(--paper);
  border-color: var(--vermilion);
}
.btn.primary:hover { background: #8a2b22; }

.btn.ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--ink-soft);
}
.btn.ghost:hover { background: rgba(0,0,0,0.04); color: var(--ink); border-color: var(--ink-faint); }

.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-row { display: flex; flex-wrap: wrap; gap: 10px; margin: 12px 0; }

select, input[type="text"], input[type="number"], textarea {
  font-family: inherit;
  font-size: 0.95rem;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--ink);
}
select:focus, input:focus, textarea:focus {
  outline: none;
  border-color: var(--vermilion);
  box-shadow: 0 0 0 2px rgba(168, 54, 43, 0.12);
}
textarea { width: 100%; min-height: 70px; resize: vertical; }

label.field {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.9rem;
  color: var(--ink-soft);
  margin-right: 14px;
}

/* ---------------- 排盘 ---------------- */
.chart-wrap {
  display: flex;
  gap: 16px;
  justify-content: center;
  flex-wrap: wrap;
}

.hex-col {
  flex: 0 0 auto;
  min-width: 230px;
}

.hex-col .hex-title {
  text-align: center;
  font-weight: 700;
  letter-spacing: 2px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 4px;
  font-size: 1rem;
}

.hex-col .hex-sub {
  text-align: center;
  font-size: 0.78rem;
  color: var(--ink-faint);
  margin-bottom: 8px;
}

.yao-row {
  display: grid;
  grid-template-columns: 38px 1fr 1fr;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-bottom: 1px dotted var(--line);
  font-size: 0.92rem;
}

.yao-row .yao-pos {
  color: var(--ink-faint);
  font-size: 0.82rem;
  text-align: right;
}

.yao-row .yao-ganzhi { font-weight: 600; }
.yao-row .yao-shiying {
  color: var(--vermilion);
  font-weight: 700;
  font-size: 0.85rem;
}

.yao-row .yao-liuqin {
  color: var(--jade);
  font-size: 0.85rem;
}

.yao-sym {
  font-family: monospace;
  font-size: 1.3rem;
  letter-spacing: -1px;
  font-weight: 700;
}

.yao-sym.yang { color: var(--ink); }
.yao-sym.yin { color: var(--ink-soft); }
.yao-move-mark { color: var(--vermilion); font-weight: 700; margin-left: 2px; }

.tag {
  display: inline-block;
  font-size: 0.72rem;
  padding: 1px 6px;
  border-radius: 10px;
  margin-left: 4px;
  white-space: nowrap;
}
.tag.kong { background: #6b6b6b; color: #fff; }
.tag.po { background: var(--vermilion); color: var(--paper); }
.tag.wang { color: var(--vermilion); font-weight: 700; }
.tag.xiang { color: #6b8e23; font-weight: 700; }
.tag.xiu { color: var(--ink-soft); }
.tag.qiu { color: #b8860b; }
.tag.si { color: var(--ink-faint); }

.info-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 18px;
  padding: 12px 16px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 0.88rem;
}
.info-bar b { color: var(--vermilion); }

/* ---------------- 学习 ---------------- */
.learn-layout { display: grid; grid-template-columns: 220px 1fr; gap: 20px; }
@media (max-width: 640px) { .learn-layout { grid-template-columns: 1fr; } }

.ch-list { list-style: none; margin: 0; padding: 0; }
.ch-list li {
  padding: 9px 12px;
  border-bottom: 1px dotted var(--line);
  cursor: pointer;
  font-size: 0.9rem;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  gap: 8px;
}
.ch-list li:hover { background: rgba(168, 54, 43, 0.06); }
.ch-list li.active { background: rgba(168, 54, 43, 0.12); color: var(--vermilion); font-weight: 600; }
.ch-list li.read::before { content: "✓"; color: var(--jade); font-weight: 700; }
.ch-list li:not(.read)::before { content: "○"; color: var(--line); }

.classic-quote {
  border-left: 3px solid var(--vermilion);
  background: rgba(168, 54, 43, 0.05);
  padding: 10px 14px;
  margin: 12px 0;
  font-size: 0.92rem;
  color: var(--ink-soft);
}
.classic-quote .src {
  display: block;
  text-align: right;
  font-size: 0.78rem;
  color: var(--ink-faint);
  margin-top: 4px;
}

.points { padding-left: 20px; }
.points li { margin: 4px 0; }

/* ---------------- 摇卦 ---------------- */
.coin-area { text-align: center; padding: 14px 0; }
.coins { display: flex; justify-content: center; gap: 18px; margin: 12px 0; }
.coin {
  width: 56px; height: 56px;
  border-radius: 50%;
  border: 2px solid var(--gold);
  background: radial-gradient(circle at 35% 30%, #e8d4a0, #b89a55);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.5rem; font-weight: 700;
  color: var(--ink);
  box-shadow: 0 3px 8px var(--shadow);
  transition: transform 0.4s ease, opacity 0.3s ease;
}
.coin.shaking { animation: shake 0.5s ease; }
@keyframes shake {
  0%, 100% { transform: translateY(0) rotate(0); }
  25% { transform: translateY(-14px) rotate(8deg); }
  50% { transform: translateY(2px) rotate(-6deg); }
  75% { transform: translateY(-8px) rotate(4deg); }
}
.coin.back { background: radial-gradient(circle at 35% 30%, #d8c79a, #9a7b3a); }

.cast-progress { margin: 14px 0; }
/* 摇卦进度卦象：竖排，上爻在顶、初爻在底（JS 按 i=6→1 顺序渲染，DOM 顺序即屏幕顺序） */
.cast-progress .yao-mini {
  display: flex; gap: 3px; justify-content: flex-start; align-items: stretch;
  flex-direction: column;
}
.yao-mini .mrow { display: flex; gap: 3px; align-items: center; font-size: 0.8rem; color: var(--ink-faint); }
.yao-mini .mrow .yao-line { font-family: monospace; letter-spacing: 0; font-weight: 700; }

/* 卦象使用纯文字爻符（━━━/╌ ╌），无需图形 CSS。之前的图形爻方案已回退。 */

/* ---------------- 练习 / 断卦 ---------------- */
.score-box {
  font-size: 1rem; font-weight: 700;
  padding: 8px 14px; border-radius: var(--radius);
  display: inline-block;
}
.score-box.good { background: rgba(74, 107, 90, 0.15); color: var(--jade); }
.score-box.warn { background: rgba(184, 134, 11, 0.15); color: #b8860b; }
.score-box.bad { background: rgba(168, 54, 43, 0.12); color: var(--vermilion); }

.q-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin: 12px 0;
  background: var(--paper);
}
.q-card .q-label { font-size: 0.8rem; color: var(--vermilion); font-weight: 600; }

.answer-block {
  border: 1px dashed var(--jade);
  border-radius: var(--radius);
  padding: 14px;
  margin-top: 12px;
  background: rgba(74, 107, 90, 0.05);
}
.answer-block h4 { margin: 0 0 8px; color: var(--jade); }

.choice-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; margin: 10px 0; }
.choice {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 10px;
  text-align: center;
  cursor: pointer;
  background: var(--paper);
  font-size: 0.9rem;
  transition: all 0.12s ease;
}
.choice:hover { border-color: var(--vermilion); }
.choice.selected { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.choice.correct { background: var(--jade); color: #fff; border-color: var(--jade); }
.choice.wrong { background: var(--vermilion); color: #fff; border-color: var(--vermilion); }

/* ---------------- 资料 ---------------- */
table.ref-table { width: 100%; border-collapse: collapse; font-size: 0.86rem; margin: 10px 0; }
.ref-table th, .ref-table td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; }
.ref-table th { background: var(--paper); color: var(--ink-soft); font-weight: 600; }
.ref-table tr:nth-child(even) { background: rgba(0,0,0,0.02); }

.test-pass { color: var(--jade); font-weight: 700; }
.test-fail { color: var(--vermilion); font-weight: 700; }

/* ---------------- 状态条 / 页脚 ---------------- */
.app-footer {
  max-width: 960px;
  margin: 0 auto;
  padding: 14px 18px 30px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
  color: var(--ink-faint);
  border-top: 1px solid var(--line);
}
#status-bar { color: var(--jade); }
.footer-note { font-size: 0.76rem; }

/* ---------------- 空状态 ---------------- */
.empty { text-align: center; color: var(--ink-faint); padding: 40px 20px; font-size: 0.92rem; }

/* ---------------- 响应式 ---------------- */
@media (max-width: 560px) {
  .app-title h1 { font-size: 1.3rem; }
  .tab { padding: 8px 11px; font-size: 0.86rem; }
  .yao-row { grid-template-columns: 30px 1fr 1fr; gap: 5px; font-size: 0.82rem; }
  .hex-col { min-width: 0; width: 100%; }
  .coin { width: 48px; height: 48px; font-size: 1.3rem; }
}

/* ============================================================
   体验打磨（视觉与移动端）
   ============================================================ */

/* 动爻行高亮（排盘 / 断卦盘） */
.yao-row:has(.yao-move-mark) { background: rgba(168, 54, 43, 0.07); }
.yao-row.yao-moving { background: rgba(168, 54, 43, 0.07); border-left: 3px solid var(--vermilion); }
.hex-col .yao-row.moving-row { background: rgba(168, 54, 43, 0.06); }

/* 硬币区可点击提示 */
.coin-area { cursor: pointer; user-select: none; }
.coin-area:hover .coin { box-shadow: 0 4px 12px var(--shadow-strong); }
.coin-area .hint { font-size: 0.8rem; color: var(--ink-faint); margin-top: 6px; }

/* 动爻符号更醒目 */
.yao-move-mark { font-size: 1rem; }

/* 选择题项 hover 态 */
.choice:hover { transform: translateY(-1px); box-shadow: 0 2px 6px var(--shadow); }

/* 断卦历史 / 错题卡片统一 */
.q-card { transition: box-shadow 0.15s ease; }
.q-card:hover { box-shadow: 0 2px 8px var(--shadow); }

/* 按钮触摸目标（移动端） */
@media (max-width: 560px) {
  .btn { min-height: 40px; padding: 10px 14px; }
  .tab { min-height: 38px; }
  .choice { padding: 12px 8px; }
  .info-bar { font-size: 0.82rem; gap: 8px 12px; padding: 10px 12px; }
  /* 排盘两列在小屏改为横向并排缩小 */
  .chart-wrap { gap: 8px; }
  .hex-col { flex: 1 1 45%; min-width: 0; }
  .yao-row { grid-template-columns: 26px 1fr; font-size: 0.8rem; }
  .yao-row > span:nth-child(3) { grid-column: 1 / -1; padding-left: 26px; }
}

/* 打印友好（盘文导出 / 截图） */
@media print {
  .app-header, .app-footer, .btn-row, .tabs { display: none; }
  .panel { box-shadow: none; border: 1px solid #999; }
}

/* 选中文字与滚动条古典化 */
::selection { background: var(--vermilion); color: var(--paper); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--paper-2); }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: var(--ink-faint); }
