/* ===== 全局重置與基礎 ===== */
:root {
  --theme: #8b4513;
  --text-primary: #2c2c2c;
  --text-secondary: #999;
  --text-light: #ccc;
  --bg: #fff;
  --border: #e0ddd8;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body {
  width: 100%; height: 100%;
  font-family: 'Noto Serif SC', 'Source Han Serif SC', 'SimSun', 'STSong', serif;
  background: var(--bg); color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  animation: bgGradual 5s ease 5s forwards;
}
@keyframes bgGradual {
  from { background: #fff; }
  to { background: #f5f5f5; }
}

/* ===== 落梅粒子canvas ===== */
#plum-canvas {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  z-index: 0; pointer-events: none;
}

/* ===== 頁面容器 ===== */
.page {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 60px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: none;
  padding: 0 24px;
}
.page.active { display: block; }

/* ===== 底部Tab導航 ===== */
.tab-bar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
  display: flex; justify-content: center; align-items: center;
  height: 60px;
}
.tab-item {
  padding: 0 32px; font-size: 14px; color: var(--text-light);
  cursor: pointer; position: relative; transition: color 0.6s;
  letter-spacing: 2px; user-select: none;
}
.tab-item.active { color: var(--text-primary); }
.tab-item.active::after {
  content: ''; position: absolute; bottom: -4px; left: 50%; transform: translateX(-50%);
  width: 16px; height: 1.5px; background: var(--theme);
  border-radius: 1px;
  animation: breathe 3s ease-in-out infinite;
}

/* ===== 首页输入区 ===== */
#tab-qi {
}

/* ===== "问心"开场文字 ===== */
.wenxin {
  font-size: 28px; color: var(--text-primary); letter-spacing: 12px;
  opacity: 0; pointer-events: none; font-weight: 300;
  position: absolute; top: 38.2vh; left: 50%; transform: translateX(-50%);
}
.wenxin.fade-in { animation: wenxinIn 1.5s ease forwards; }
.wenxin.fade-out { animation: wenxinOut 1s ease forwards; }
@keyframes wenxinIn {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}
@keyframes wenxinOut {
  from { opacity: 1; transform: translateX(-50%) translateY(0); }
  to { opacity: 0; transform: translateX(-50%) translateY(-8px); }
}

/* ===== 初始态：气泡按钮（flex居中，自适应） ===== */
.initial-state {
  /* 完全和 .wenxin 问心 保持一样的定位 → 保证对齐 */
  position: absolute;
  top: 38.2vh;
  left: 50%;
  transform: translateX(-50%);

  /* 按钮内部居中 */
  display: flex;
  justify-content: center;
  align-items: center;

  opacity: 0;

  /* 重置默认边距，避免偏移 */
  margin: 0;
  padding: 0;
}

.initial-state.show {
  animation: inputFadeIn 1.2s ease forwards;
}
.bubble-btn {
  padding: 14px 36px; border: 1px solid var(--border); border-radius: 28px;
  font-size: 15px; color: var(--text-secondary); background: #fff;
  cursor: pointer; transition: all 0.3s; letter-spacing: 2px;
  font-family: inherit;
  animation: borderBreathe 4s ease-in-out infinite;
  box-shadow: 0 2px 12px rgba(0,0,0,0.04);
}
.bubble-btn:hover { border-color: var(--text-secondary); }

/* ===== 输入态 ===== */
.input-area {
  display:none;
  flex-direction:column;
  align-items:center;

  justify-content:flex-start;

  height:calc(100vh - 60px);

  padding-top:25vh;

  width:100%;
  max-width:320px;

  margin:0 auto;
}
.input-area.show { display: flex; }
.input-label {
  font-size: 14px; color: var(--text-secondary); margin-bottom: 16px;
  letter-spacing: 2px;
}
.input-wrap {
  position: relative; width: 100%; max-width: 320px;
}
.question-input {
  width: 100%; padding: 14px 16px; border: 1px solid var(--border);
  border-radius: 10px; font-size: 15px; color: var(--text-primary);
  background: transparent; outline: none; font-family: inherit;
  letter-spacing: 1px;
}
.question-input::placeholder {
  color: var(--text-light); font-size: 13px; letter-spacing: 1px;
}
.question-input.flash::placeholder {
  animation: placeholderFlash 0.6s ease 2;
}
@keyframes borderBreathe {
  0%, 100% { border-color: var(--border); }
  50% { border-color: var(--text-light); }
}
@keyframes inputFadeIn {
  from { opacity: 0; transform: translateX(-50%) translateY(6px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes placeholderFlash {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* ===== 起卦按钮 ===== */
.qigua-btn {
  margin-top: 48px; padding: 14px 64px; border: none; border-radius: 28px;
  font-size: 15px; color: #fff; background: #ccc; cursor: not-allowed;
  transition: all 0.3s; letter-spacing: 4px; font-family: inherit;
}
.qigua-btn.active { background: var(--text-primary); cursor: pointer; }
.qigua-btn.active:hover { background: #000; }

/* ===== 呼吸动画（全局复用） ===== */
@keyframes breathe {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

/* ===== 字数计数器 ===== */
.char-count {
  position: absolute; bottom: -22px; right: 0;
  font-size: 11px; color: var(--text-light); letter-spacing: 1px;
}
.char-count.over { color: #c0392b; }

/* ===== Tab2 卦錄頁 ===== */
#tab-lu { padding: 16px 16px 24px; }
.empty-state {
  display: flex; align-items: center; justify-content: center;
  height: calc(100vh - 160px); color: var(--text-light); font-size: 14px; letter-spacing: 1px;
}
.record-list { max-width: 480px; margin: 0 auto; min-height: calc(100vh - 160px); padding-bottom: 24px; }
.record-card {
  background: #fafafa; border-radius: 12px; padding: 16px 18px;
  margin-bottom: 12px; cursor: pointer; position: relative;
  transition: background 0.2s;
}
.record-card:hover { background: #f5f5f5; }
.record-time { font-size: 12px; color: #bbb; margin-bottom: 6px; }
.record-gua {
  font-size: 16px; color: var(--text-primary); font-weight: 500; margin-bottom: 6px;
  display: flex; align-items: center; gap: 6px;
}
.record-gua .gua-symbol { color: #c0392b; font-size: 20px; }
.record-gua .gua-name { color: var(--text-primary); }
.record-gua .gua-dot { color: var(--text-secondary); font-size: 12px; margin: 0 4px; }
.record-gua .gua-dong { color: #666; font-size: 14px; }
.record-question {
  font-size: 13px; color: #aaa;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.record-delete {
  position: absolute; top: 10px; right: 10px; width: 22px; height: 22px;
  border: none; background: transparent; color: #ddd; font-size: 16px;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  border-radius: 50%; transition: all 0.2s;
}
.record-delete:hover { color: #e74c3c; background: #fee; }

/* ===== 詳情頁 ===== */
#detail-page {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0; z-index: 200;
  background: #fff; display: none; flex-direction: column;
}
#detail-page.show { display: flex; }
.detail-header {
  display: flex; align-items: center; height: 52px; padding: 0 16px;
  border-bottom: 1px solid #f0f0f0; flex-shrink: 0;
}
.back-btn {
  width: 36px; height: 36px; border: none; background: transparent;
  font-size: 20px; color: #666; cursor: pointer; display: flex;
  align-items: center; justify-content: center; margin-right: 8px;
}
.detail-title { font-size: 16px; color: var(--text-primary); font-weight: 500; letter-spacing: 1px; }
.detail-content {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 24px 20px 100px;
}
.detail-question {
  font-size: 18px; font-weight: 600; color: #222; line-height: 1.6;
  margin-bottom: 8px; word-break: break-all;
}
.detail-time { font-size: 12px; color: #bbb; margin-bottom: 24px; }
.detail-gua-main {
  text-align: center; margin-bottom: 12px;
}
.detail-gua-symbol {
  font-size: 72px; color: #c0392b; line-height: 1; margin-bottom: 8px;
}
.detail-gua-name { font-size: 22px; color: var(--text-primary); font-weight: 500; letter-spacing: 2px; }
.detail-dongyao {
  text-align: center; font-size: 16px; color: #666; margin-bottom: 20px;
  letter-spacing: 1px;
}
.detail-shangxia {
  text-align: center; font-size: 15px; color: #555;
  margin-bottom: 20px; letter-spacing: 1px;
}
.detail-tiyong {
  background: #fafafa; border-radius: 10px; padding: 16px 20px;
  margin-bottom: 28px;
}
.detail-tiyong-row {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 10px; font-size: 14px;
}
.detail-tiyong-row:last-child { margin-bottom: 0; }
.detail-tiyong-label { color: var(--text-secondary); }
.detail-tiyong-value { color: var(--text-primary); font-weight: 500; }
.detail-tiyong-grade {
  display: inline-block; padding: 2px 10px; border-radius: 4px;
  font-size: 13px; font-weight: 500;
}
.detail-tiyong-grade.level-1 { background: #e8f5e9; color: #2e7d32; }
.detail-tiyong-grade.level-2 { background: #e3f2fd; color: #1565c0; }
.detail-tiyong-grade.level-3 { background: #fff3e0; color: #e65100; }
.detail-tiyong-grade.level-4 { background: #fce4ec; color: #c62828; }
.detail-tiyong-grade.level-5 { background: #ffebee; color: #b71c1c; }
.detail-tiyong-desc {
  font-size: 13px; color: #666; line-height: 1.6;
  margin-top: 8px; padding-top: 8px; border-top: 1px solid #eee;
}
.detail-section { margin-bottom: 28px; }
.detail-section-title {
  font-size: 13px; color: var(--text-secondary); margin-bottom: 10px; letter-spacing: 1px;
}
.detail-section-text {
  font-size: 15px; color: #444; line-height: 1.8;
  padding: 16px; background: #fafafa; border-radius: 8px;
}

/* ===== 動力學分析區塊 ===== */
.detail-dynamics {
  background: #fafafa; border-radius: 12px; padding: 20px;
  margin-bottom: 28px;
}
.detail-dynamics-header {
  margin-bottom: 16px; padding-bottom: 12px;
  border-bottom: 1px solid #eee;
}
.detail-dynamics-title {
  font-size: 15px; color: var(--text-primary); font-weight: 500; letter-spacing: 2px;
  margin-bottom: 6px;
}
.detail-dynamics-desc {
  font-size: 12px; color: #aaa; line-height: 1.6;
}
.detail-dynamics-body {
  display: flex; gap: 12px;
  flex-wrap: wrap;
}
.detail-dynamics-body .detail-gua-card {
  flex: 1 1 calc(50% - 6px); min-width: 140px;
  background: #fff; border-radius: 8px; padding: 14px;
  border: 1px solid #f0f0f0; box-sizing: border-box;
}
.detail-gua-card-label {
  font-size: 12px; color: var(--text-secondary); margin-bottom: 8px; letter-spacing: 1px;
}
.detail-gua-card-gua {
  display: flex; align-items: center; gap: 6px;
  margin-bottom: 6px;
}
.detail-gua-card-symbol {
  font-size: 28px; color: #c0392b; line-height: 1;
}
.detail-gua-card-name {
  font-size: 16px; color: var(--text-primary); font-weight: 500;
}
.detail-gua-card-shangxia {
  font-size: 13px; color: #555; margin-bottom: 6px; letter-spacing: 1px;
}
.detail-gua-card-result {
  font-size: 13px; color: #444;
}

/* 底部按鈕 */
.detail-footer {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: flex; gap: 12px; padding: 12px 20px 24px;
  background: rgba(255,255,255,0.95); backdrop-filter: blur(8px);
  border-top: 1px solid #f0f0f0;
}
.detail-btn {
  flex: 1; padding: 14px; border: 1px solid #e0e0e0; border-radius: 8px;
  font-size: 15px; text-align: center; cursor: pointer; background: #fff;
  transition: all 0.2s; letter-spacing: 2px;
}
.detail-btn.copy { color: var(--text-primary); }
.detail-btn.copy:hover { background: #f5f5f5; }
.detail-btn.jiegua { color: #666; background: #fafafa; }
.detail-btn.jiegua:hover { background: #f0f0f0; }

/* ===== 輕提示 Toast ===== */
.toast {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
  background: rgba(0,0,0,0.7); color: #fff; padding: 12px 24px;
  border-radius: 6px; font-size: 14px; z-index: 300;
  display: none; pointer-events: none; text-align: center;
}
.toast.show { display: block; animation: toastIn 0.2s ease; }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, -50%) scale(0.9); } to { opacity: 1; transform: translate(-50%, -50%) scale(1); } }

/* ===== 彈窗（呼吸感） ===== */
.modal-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0; z-index: 400;
  background: rgba(0,0,0,0.35); display: none; align-items: center; justify-content: center;
  backdrop-filter: blur(2px);
}
.modal-overlay.show { display: flex; animation: modalBgIn 0.4s ease; }
@keyframes modalBgIn { from { opacity: 0; } to { opacity: 1; } }
.modal-box {
  background: #fff; border-radius: 16px; padding: 48px 36px 36px;
  text-align: center; max-width: 300px; width: 78%;
  animation: modalIn 0.5s ease;
  box-shadow: 0 8px 40px rgba(0,0,0,0.08);
}
@keyframes modalIn {
  from { opacity: 0; transform: scale(0.92) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
.modal-text {
  font-size: 15px; color: var(--text-secondary); line-height: 2.2;
  margin-bottom: 36px; letter-spacing: 1px;
  white-space: pre-line;
}
.modal-ok {
  padding: 12px 40px; border: 1px solid var(--border); border-radius: 24px;
  background: transparent; color: var(--text-primary); font-size: 14px; cursor: pointer;
  letter-spacing: 3px; font-family: inherit;
  transition: all 0.3s;
}
.modal-ok:hover { background: #fafafa; border-color: var(--text-secondary); }

/* ===== 問心解卦（內嵌區塊） ===== */
.jiegua-text-block {
  font-size: 14px; color: #444; line-height: 1.8;
}
.jiegua-text-block h1,
.jiegua-text-block h2,
.jiegua-text-block h3 {
  font-size: 15px; color: var(--text-primary); font-weight: 600;
  margin: 12px 0 6px; letter-spacing: 1px;
}
.jiegua-text-block strong {
  color: var(--text-primary); font-weight: 600;
}
.jiegua-loading {
  color: var(--text-secondary); font-size: 14px;
  display: flex; align-items: center; gap: 4px;
}
.jiegua-dots::after {
  content: '';
  animation: jieguaDots 1.5s steps(4, end) infinite;
}
@keyframes jieguaDots {
  0%  { content: ''; }
  25% { content: '.'; }
  50% { content: '..'; }
  75% { content: '...'; }
}
.jiegua-error {
  color: #c0392b; font-size: 14px;
}

/* ===== 儀式感加載 ===== */
.ritual-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0; z-index: 250;
  background: #fff; display: none; align-items: center; justify-content: center;
}
.ritual-overlay.show { display: flex; }
.ritual-text { font-size: 14px; color: var(--text-light); letter-spacing: 4px; }
