/* ============================================================
   九大玄學占卜 — 科技藍主題
   ============================================================ */
:root {
  /* 色彩系統 */
  --primary: #0052D4;
  --primary-dark: #003B9E;
  --primary-light: #E8F0FE;
  --primary-lighter: #F5F8FF;
  --primary-rgb: 0, 82, 212;

  --bg-page: #F8F9FA;
  --bg-card: #FFFFFF;
  --bg-subtle: #F8F9FA;

  --text-primary: #24292F;
  --text-secondary: #57606A;
  --text-tertiary: #8B949E;
  --text-inverse: #FFFFFF;

  --border: #D0D7DE;
  --border-light: #F0F1F3;

  --success: #1F883D;
  --success-bg: rgba(31, 136, 61, 0.12);
  --error: #CF222E;
  --error-bg: rgba(207, 34, 46, 0.08);
  --error-border: rgba(207, 34, 46, 0.3);
  --warning: #6E40C9;
  --warning-bg: rgba(110, 64, 201, 0.10);

  /* 陰影 */
  --shadow-sm: 0 1px 3px rgba(36, 41, 47, 0.08);
  --shadow-md: 0 4px 12px rgba(36, 41, 47, 0.10);
  --shadow-lg: 0 8px 24px rgba(36, 41, 47, 0.14);

  /* 圓角 */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;

  /* 間距 */
  --space-xs: 8px;
  --space-sm: 12px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-2xl: 48px;

  /* 字型 */
  --font-title: "Microsoft JhengHei", "Noto Sans TC", sans-serif;
  --font-body: "Microsoft JhengHei", "Noto Sans TC", sans-serif;
  --font-mono: "Consolas", "Courier New", monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }

body {
  font-family: var(--font-body);
  font-weight: 400;
  color: var(--text-primary);
  min-height: 100vh;
  background: linear-gradient(180deg, var(--bg-page) 0%, #FFFFFF 100%);
  overflow-x: hidden;
}

/* 隱藏星空 canvas（新版不需） */
#stars { display: none; }

/* ---------- 頁面容器 ---------- */
.page {
  position: relative;
  z-index: 1;
  max-width: 960px;
  margin: 0 auto;
  padding: var(--space-2xl) var(--space-lg) 64px;
}

/* ---------- 玻璃卡片（改為白卡） ---------- */
.glass {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.3s;
}
.glass:hover { box-shadow: var(--shadow-md); }

/* ---------- 主題切換按鈕（隱藏，新版無深淺切換） ---------- */
.theme-toggle { display: none; }

/* ---------- Hero 標題 ---------- */
.hero { text-align: center; margin-bottom: var(--space-xl); }
.hero-ornament { display: flex; align-items: center; justify-content: center; gap: 12px; margin-bottom: 12px; }
.orn-line { width: 56px; height: 2px; background: linear-gradient(90deg, transparent, var(--primary)); }
.orn-line:last-child { background: linear-gradient(90deg, var(--primary), transparent); }
.orn-taiji {
  width: 28px; height: 28px; border-radius: 50%;
  background: linear-gradient(90deg, var(--primary) 50%, #FFFFFF 50%);
  position: relative; border: 2px solid var(--primary);
}
.orn-taiji::before, .orn-taiji::after {
  content: ""; position: absolute; width: 12px; height: 12px; border-radius: 50%;
}
.orn-taiji::before {
  left: 2px; top: 7px; background: #FFFFFF;
  background-image: radial-gradient(circle at 50% 50%, var(--primary) 0 3px, transparent 3.5px);
}
.orn-taiji::after {
  right: 2px; top: 7px; background: var(--primary);
  background-image: radial-gradient(circle at 50% 50%, #FFFFFF 0 3px, transparent 3.5px);
}

.hero-title {
  font-family: var(--font-title);
  font-size: clamp(28px, 5vw, 40px);
  font-weight: 700;
  letter-spacing: 0.15em;
  color: var(--text-primary);
}
.hero-sub { margin-top: 10px; color: var(--text-secondary); font-size: 15px; letter-spacing: 0.1em; }
.hero-en { margin-top: 6px; color: var(--text-tertiary); font-size: 11px; letter-spacing: 0.2em; text-transform: uppercase; }

/* ---------- 提問卡片 ---------- */
.ask-card { padding: var(--space-xl); margin-bottom: var(--space-xl); }
.ask-head { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: var(--space-md); }
.ask-label {
  font-family: var(--font-title); font-size: 16px; font-weight: 700;
  color: var(--text-primary);
}
.ask-hint { font-size: 12px; color: var(--text-tertiary); }

#question {
  width: 100%; resize: vertical; min-height: 64px;
  font-family: var(--font-body); font-size: 15px; font-weight: 400;
  line-height: 1.7; color: var(--text-primary);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px; outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
#question:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}
#question::placeholder { color: var(--text-tertiary); }

.ask-row { display: flex; align-items: center; gap: 14px; margin-top: var(--space-md); flex-wrap: wrap; }

/* 僅開牌 toggle */
.toggle { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-secondary); cursor: pointer; user-select: none; }
.toggle-track {
  width: 38px; height: 21px; border-radius: 21px;
  background: #E0E4EA; position: relative; transition: background 0.25s; flex: none;
}
.toggle-thumb {
  position: absolute; top: 2.5px; left: 3px;
  width: 16px; height: 16px; border-radius: 50%;
  background: #FFFFFF; box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  transition: transform 0.25s;
}
.toggle input { display: none; }
.toggle input:checked + .toggle-track { background: var(--primary); }
.toggle input:checked + .toggle-track .toggle-thumb { transform: translateX(17px); }

.seed-input {
  width: 110px; font-size: 13px; color: var(--text-primary);
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 8px 12px; outline: none;
}
.seed-input:focus { border-color: var(--primary); }

/* ---------- 玄學勾選區 ---------- */
.sys-picker { margin-top: var(--space-lg); }
.sys-picker-label {
  display: block; font-size: 12px; font-weight: 700;
  color: var(--text-secondary); letter-spacing: 0.04em; margin-bottom: var(--space-xs);
}
.sys-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.sys-chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; font-weight: 400;
  padding: 8px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-subtle);
  color: var(--text-secondary);
  cursor: pointer; user-select: none;
  transition: all 0.2s ease;
}
.sys-chip:hover { border-color: var(--primary); background: var(--primary-lighter); }
.sys-chip input { display: none; }
.sys-chip.active {
  background: var(--primary-light);
  color: var(--primary-dark);
  border-color: var(--primary);
  font-weight: 600;
  box-shadow: 0 2px 6px rgba(var(--primary-rgb), 0.15);
}
.panel-hidden { display: none !important; }

/* ---------- 按鈕 ---------- */
.btn-gold {
  border: none; cursor: pointer;
  font-family: var(--font-title); font-size: 15px; font-weight: 700;
  letter-spacing: 0.06em;
  border-radius: var(--radius-sm);
  padding: 12px 32px;
  color: var(--text-inverse);
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  box-shadow: 0 4px 14px rgba(var(--primary-rgb), 0.3);
  transition: all 0.2s ease;
}
.btn-gold:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(var(--primary-rgb), 0.4);
}
.btn-gold:active { transform: translateY(0) scale(0.98); }
.btn-gold:disabled { opacity: 0.5; cursor: wait; transform: none; box-shadow: none; }

.btn-ghost {
  border: 1px solid var(--border); cursor: pointer;
  font-family: var(--font-body); font-size: 13px; font-weight: 400;
  border-radius: var(--radius-sm);
  padding: 10px 18px;
  color: var(--text-secondary); background: transparent;
  transition: all 0.2s ease;
}
.btn-ghost:hover:not(:disabled) {
  color: var(--primary); border-color: var(--primary);
  background: var(--primary-lighter);
}
.btn-ghost:active { transform: scale(0.97); }
.btn-ghost:disabled { opacity: 0.4; cursor: not-allowed; }

.ask-error {
  margin-top: var(--space-md);
  padding: 12px 16px; border-radius: var(--radius-sm);
  font-size: 13px; color: var(--error);
  background: var(--error-bg); border: 1px solid var(--error-border);
}

/* ---------- 九大體系面板（卡片式 3×3 網格） ---------- */
.panels {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-lg);
  margin-bottom: var(--space-xl);
}
@media (max-width: 1024px) { .panels { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 640px)  { .panels { grid-template-columns: 1fr; } }

.panel {
  padding: var(--space-lg) var(--space-lg) 20px;
  animation: fadeUp 0.6s cubic-bezier(0.2, 0.7, 0.3, 1) both;
  animation-delay: var(--d, 0s);
  transition: box-shadow 0.3s, border-color 0.3s;
}
.panel:hover { box-shadow: var(--shadow-md); border-color: rgba(var(--primary-rgb), 0.3); }

.panel-head {
  display: flex; align-items: center; gap: 10px;
  border-bottom: 1px solid var(--border-light);
  padding-bottom: var(--space-sm); margin-bottom: var(--space-md);
}
.panel-icon {
  width: 38px; height: 38px; border-radius: var(--radius-sm);
  display: grid; place-items: center; font-size: 18px;
  background: var(--primary-lighter); border: 1px solid rgba(var(--primary-rgb), 0.2);
}
.panel-head h2 {
  font-family: var(--font-title); font-size: 15px; font-weight: 700;
  color: var(--text-primary);
}
.panel-head h2 em {
  font-style: normal; font-size: 11px; letter-spacing: 0.04em;
  color: var(--text-tertiary); margin-left: 6px; font-weight: 400;
}
.panel-body { min-height: 140px; }

/* ---------- 塔羅 3D 卡牌 ---------- */
.tarot-body { display: flex; justify-content: center; gap: 12px; padding: 8px 0; }
.card3d {
  width: 88px; height: 132px; perspective: 700px;
  animation: fadeUp 0.6s both; animation-delay: var(--d, 0s);
}
.card3d-inner {
  width: 100%; height: 100%; position: relative;
  transform-style: preserve-3d;
  transition: transform 0.9s cubic-bezier(0.3, 0.9, 0.3, 1);
}
.card3d.flipped .card3d-inner { transform: rotateY(180deg); }
.card-face {
  position: absolute; inset: 0;
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
  border-radius: 10px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 8px;
}
.card-front {
  background: linear-gradient(160deg, #F5F8FF, #E8F0FE);
  border: 1px solid rgba(var(--primary-rgb), 0.35);
  color: var(--primary);
  font-size: 28px;
}
.card-front::after {
  content: ""; position: absolute; inset: 5px;
  border: 1px solid rgba(var(--primary-rgb), 0.2);
  border-radius: 7px;
}
.card-back {
  transform: rotateY(180deg);
  background: linear-gradient(180deg, #FFFFFF, #F8F9FA);
  color: var(--text-primary);
  border: 1px solid rgba(var(--primary-rgb), 0.3);
  box-shadow: var(--shadow-sm);
  text-align: center; gap: 4px;
}
.card-name { font-family: var(--font-title); font-size: 14px; font-weight: 700; color: var(--text-primary); }
.card-suit { font-size: 10px; color: var(--text-tertiary); letter-spacing: 0.05em; }
.card-pos { font-size: 10px; color: var(--text-secondary); margin-top: 3px; font-weight: 500; }
.card-orient { font-size: 10px; padding: 2px 8px; border-radius: 20px; margin-top: 4px; font-weight: 600; }
.card-orient.up { color: var(--success); background: var(--success-bg); }
.card-orient.down { color: var(--error); background: var(--error-bg); }

/* ---------- 雷諾曼 ---------- */
.lenormand-body { display: flex; gap: 10px; justify-content: center; padding: 8px 0; flex-wrap: wrap; }
.lnm-card {
  width: 88px;
  background: var(--bg-card);
  border-radius: 10px;
  padding: 10px 8px;
  text-align: center;
  color: var(--text-primary);
  animation: fadeUp 0.55s both; animation-delay: var(--d, 0s);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.lnm-num {
  display: inline-grid; place-items: center;
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--primary); color: #FFFFFF;
  font-size: 12px; font-weight: 700;
  margin-bottom: 6px;
}
.lnm-name { font-family: var(--font-title); font-size: 14px; font-weight: 700; color: var(--text-primary); }
.lnm-en { font-size: 9px; color: var(--text-tertiary); margin-top: 2px; }
.lnm-key { font-size: 10px; color: var(--text-secondary); margin-top: 6px; line-height: 1.5; }
.lnm-pos { font-size: 9px; color: var(--primary); margin-top: 6px; letter-spacing: 0.04em; font-weight: 600; }

/* ---------- 阿卡西 ---------- */
.akashic-body { display: flex; flex-direction: column; gap: 10px; padding: 4px; }
.akashic-item {
  display: flex; gap: 10px;
  font-size: 13px; line-height: 1.65; color: var(--text-secondary);
  animation: fadeUp 0.5s both; animation-delay: var(--d, 0s);
}
.akashic-item b {
  flex: none; font-weight: 700; color: var(--primary-dark);
  min-width: 88px; font-size: 12px;
}
.akashic-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--primary); margin-top: 8px; flex: none;
}

/* ---------- 星骰 ---------- */
.astrodice-body { display: flex; flex-direction: column; gap: 10px; padding: 4px; }
.adie {
  display: flex; align-items: center; gap: 12px;
  background: var(--bg-subtle);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  animation: fadeUp 0.55s both; animation-delay: var(--d, 0s);
  transition: border-color 0.2s, background 0.2s;
}
.adie:hover { border-color: rgba(var(--primary-rgb), 0.3); background: var(--primary-lighter); }
.adie-glyph {
  flex: none; width: 42px; height: 42px; border-radius: 10px;
  display: grid; place-items: center; font-size: 20px;
  color: var(--primary);
  background: var(--primary-lighter);
  border: 1px solid rgba(var(--primary-rgb), 0.25);
}
.adie-name { font-family: var(--font-title); font-size: 15px; font-weight: 700; color: var(--text-primary); }
.adie-key { font-size: 11px; color: var(--text-secondary); line-height: 1.5; margin-top: 2px; }
.adie-role { font-size: 10px; color: var(--text-tertiary); letter-spacing: 0.08em; margin-bottom: 2px; font-weight: 600; text-transform: uppercase; }

/* ---------- 梅花易數 ---------- */
.meihua-body { text-align: center; padding: 4px; }
.meihua-meaning { font-size: 13px; color: var(--text-secondary); text-align: center; margin-top: 14px; line-height: 1.7; }
.meihua-outward {
  font-size: 13px; color: var(--success);
  text-align: center; margin-top: 12px; line-height: 1.7;
  font-style: italic;
  background: var(--success-bg);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  border: 1px solid rgba(31, 136, 61, 0.25);
}

/* ---------- 神諭卡 ---------- */
.oracle-body, .oracle-cards-body { display: flex; flex-direction: column; gap: 10px; padding: 4px; }
.oracle-card, .oc-card {
  display: flex; align-items: center; gap: 12px;
  background: var(--bg-subtle);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  animation: fadeUp 0.55s both;
  transition: border-color 0.2s, background 0.2s;
}
.oracle-card:hover, .oc-card:hover { border-color: rgba(var(--primary-rgb), 0.3); background: var(--primary-lighter); }
.oracle-elem, .oc-element-icon {
  font-size: 20px; flex: none; width: 40px; height: 40px;
  display: grid; place-items: center; border-radius: 10px;
  background: var(--primary-lighter);
  border: 1px solid rgba(var(--primary-rgb), 0.2);
}
.oracle-name, .oc-name { font-family: var(--font-title); font-size: 15px; font-weight: 700; color: var(--text-primary); }
.oracle-pos, .oc-position { font-size: 10px; color: var(--text-tertiary); margin-top: 2px; letter-spacing: 0.06em; font-weight: 600; }
.oracle-key, .oc-meaning { font-size: 11px; color: var(--text-secondary); line-height: 1.6; margin-top: 2px; }
.oracle-note { font-size: 11px; color: var(--text-tertiary); text-align: center; margin-top: 8px; font-style: italic; }

/* ---------- 易經 ---------- */
.iching-body { padding: 4px; }
.hex-lines { display: flex; flex-direction: column; gap: 7px; align-items: center; padding: 10px 0 14px; }
/* 每爻固定寬度容器，陽爻（—）與陰爻（--）完全對稱 */
.hex-line {
  display: flex; justify-content: center; align-items: center;
  width: 120px; gap: 6px;
  animation: fadeUp 0.5s both; animation-delay: var(--d, 0s);
}
/* 爻圖區域：固定 96px 寬，陽爻一根滿寬、陰爻兩根等寬平分，保證左右對稱 */
.hex-track {
  display: flex; width: 96px; gap: 8px;
}
.hex-bar {
  height: 6px; border-radius: 3px;
  background: linear-gradient(90deg, var(--primary-dark), var(--primary));
  flex: 1;
}
/* 動爻標記 */
.hex-mark {
  font-size: 12px; color: var(--error);
  margin-left: 8px; font-weight: 700;
  flex: none; white-space: nowrap;
}
.hex-tags { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.hex-tag {
  font-size: 13px; font-weight: 700;
  padding: 8px 16px; border-radius: 20px;
  border: 1px solid rgba(var(--primary-rgb), 0.3);
  background: var(--primary-light);
  color: var(--primary-dark);
  animation: fadeUp 0.55s both; animation-delay: var(--d, 0s);
}
.hex-tag small { display: block; font-size: 10px; color: var(--text-tertiary); letter-spacing: 0.06em; margin-bottom: 2px; font-weight: 400; }
.hex-meaning { font-size: 12px; color: var(--text-secondary); text-align: center; margin-top: 14px; line-height: 1.7; }

/* ---------- 觀音靈籤 ---------- */
.guanyin-body { text-align: center; padding: 4px; }
.gy-head { display: flex; align-items: center; justify-content: center; gap: 8px; margin-bottom: 12px; }
.gy-num { font-family: var(--font-title); font-size: 15px; font-weight: 700; color: var(--text-primary); }
.gy-grade { font-size: 11px; padding: 3px 10px; border-radius: 20px; font-weight: 700; }
.gy-grade.g-up { color: var(--success); background: var(--success-bg); border: 1px solid rgba(31,136,61,0.35); }
.gy-grade.g-mid { color: #B45309; background: #FEF3C7; border: 1px solid rgba(180,120,50,0.35); }
.gy-grade.g-down { color: var(--error); background: var(--error-bg); border: 1px solid var(--error-border); }
.gy-palace { font-size: 12px; color: var(--text-tertiary); margin-left: 4px; }
.gy-poem {
  font-family: var(--font-title); font-size: 14px; line-height: 2.1;
  color: var(--text-primary); text-align: center; margin: 12px 0;
  background: var(--bg-subtle);
  padding: 14px 16px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
}
.gy-poetic, .gy-jie { font-size: 12px; color: var(--text-secondary); margin-top: 8px; line-height: 1.7; text-align: left; }
.gy-poetic b, .gy-jie b { color: var(--primary-dark); font-weight: 700; }
.gy-shengyi {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px 10px;
  margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border-light); text-align: left;
}
.gy-sy-item { font-size: 11px; color: var(--text-secondary); }
.gy-sy-item em { font-style: normal; color: var(--primary-dark); font-weight: 700; margin-right: 4px; }

/* ---------- 靈棋經 ---------- */
.lingji-body { display: flex; gap: 10px; justify-content: center; padding: 8px 0; flex-wrap: wrap; }
.lnm-orient {
  font-size: 10px; padding: 3px 8px; border-radius: 20px; margin-top: 5px;
  display: inline-block; font-weight: 700;
}
.lnm-orient.up { color: var(--success); background: var(--success-bg); }
.lnm-orient.down { color: var(--error); background: var(--error-bg); }

/* ---------- AI 解讀區 ---------- */
.answer { padding: var(--space-xl); margin-bottom: var(--space-xl); }
.answer-head {
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--border-light);
  padding-bottom: var(--space-md); margin-bottom: var(--space-lg);
}
.answer-head h2 {
  font-family: var(--font-title); font-size: 20px; font-weight: 700;
  color: var(--text-primary);
}
.answer-status { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--text-secondary); }
.answer-status.done .taiji { display: none; }
.answer-status.loading-slow #statusText { animation: blink 1.6s ease-in-out infinite; }
.status-hint {
  font-size: 11px; color: var(--primary-dark);
  background: var(--primary-light); border: 1px solid rgba(var(--primary-rgb), 0.3);
  border-radius: 999px; padding: 3px 12px;
}

.taiji {
  width: 28px; height: 28px; border-radius: 50%;
  background: linear-gradient(90deg, var(--primary) 50%, #FFFFFF 50%);
  position: relative;
  border: 2px solid var(--primary);
  animation: spin 1.5s linear infinite;
}
.taiji::before, .taiji::after { content: ""; position: absolute; width: 12px; height: 12px; border-radius: 50%; }
.taiji::before { left: 1px; top: 7px; background: #FFFFFF; background-image: radial-gradient(circle at 50% 50%, var(--primary) 0 3px, transparent 3.5px); }
.taiji::after { right: 1px; top: 7px; background: var(--primary); background-image: radial-gradient(circle at 50% 50%, #FFFFFF 0 3px, transparent 3.5px); }

.answer-question {
  font-size: 14px; color: var(--text-secondary);
  background: var(--bg-subtle);
  border-left: 3px solid var(--primary);
  border-radius: 8px;
  padding: 12px 16px; margin-bottom: var(--space-lg); line-height: 1.7;
}
.answer-question b { color: var(--primary-dark); font-weight: 700; }

.answer-text { font-size: 15px; line-height: 1.9; color: var(--text-primary); white-space: pre-wrap; word-break: break-word; }
.answer-text .ah {
  font-family: var(--font-title); font-size: 17px; font-weight: 700;
  color: var(--text-primary); display: block; margin: 20px 0 8px;
}
.answer-text .ah:first-child { margin-top: 0; }
.answer-text b, .answer-text strong { color: var(--primary-dark); font-weight: 700; }
.answer-text .block { display: block; }
.answer-text .caret {
  display: inline-block; width: 2px; height: 1.1em;
  background: var(--primary); vertical-align: text-bottom; margin-left: 2px;
  animation: blink 0.9s steps(2) infinite;
}

.answer-error {
  margin-top: var(--space-md); padding: 12px 16px; border-radius: var(--radius-sm);
  font-size: 13px; color: var(--error);
  background: var(--error-bg); border: 1px solid var(--error-border);
  white-space: pre-wrap; line-height: 1.7;
}

.thinking-box {
  margin-bottom: var(--space-lg);
  padding: 12px 16px; border-radius: var(--radius-sm);
  background: var(--bg-subtle);
  border: 1px solid var(--border-light);
  font-size: 13px; line-height: 1.7;
}
.thinking-box summary {
  cursor: pointer; font-weight: 700; color: var(--primary-dark);
  user-select: none; outline: none; font-family: var(--font-title);
}
.thinking-inner {
  margin-top: 10px; padding-top: 10px;
  border-top: 1px solid var(--border-light);
  color: var(--text-secondary); white-space: pre-wrap;
  max-height: 260px; overflow-y: auto; font-size: 12px;
}

/* ---------- 設定按鈕 ---------- */
.ask-right { display: inline-flex; align-items: center; gap: 12px; }
.btn-gear {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  font-size: 17px; color: var(--text-secondary);
  background: transparent; border: 1px solid var(--border);
  border-radius: var(--radius-sm); cursor: pointer;
  transition: all 0.25s;
}
.btn-gear:hover {
  color: var(--primary); border-color: var(--primary);
  transform: rotate(30deg); background: var(--primary-lighter);
}

.btn-install {
  font-family: var(--font-body); font-size: 12px;
  color: var(--primary-dark);
  background: var(--primary-light);
  border: 1px solid rgba(var(--primary-rgb), 0.35);
  border-radius: 999px; padding: 5px 14px;
  cursor: pointer; transition: all 0.2s; white-space: nowrap;
}
.btn-install:hover { box-shadow: 0 2px 10px rgba(var(--primary-rgb), 0.25); transform: translateY(-1px); }
.install-hint {
  position: fixed; left: 50%; bottom: 28px;
  transform: translateX(-50%); z-index: 60;
  max-width: min(92vw, 460px); text-align: center;
  font-size: 13px; line-height: 1.5;
  color: var(--primary-dark);
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-md); padding: 12px 18px;
  box-shadow: var(--shadow-lg);
  animation: fadeUp 0.3s ease both;
}

/* ---------- 設定 Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center;
  background: rgba(36, 41, 47, 0.5);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  animation: fadeIn 0.25s ease both;
}
.modal {
  width: min(480px, calc(100vw - 40px));
  max-height: calc(100vh - 60px); overflow-y: auto;
  padding: var(--space-xl);
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--border-light);
  padding-bottom: var(--space-md); margin-bottom: var(--space-lg);
}
.modal-head h2 { font-family: var(--font-title); font-size: 18px; font-weight: 700; color: var(--text-primary); }
.modal-x {
  width: 30px; height: 30px; display: grid; place-items: center;
  font-size: 14px; color: var(--text-tertiary);
  background: transparent; border: 1px solid transparent;
  border-radius: var(--radius-sm); cursor: pointer; transition: all 0.2s;
}
.modal-x:hover { color: var(--error); border-color: var(--error-border); background: var(--error-bg); }
.modal-note { font-size: 13px; line-height: 1.7; color: var(--text-secondary); margin-bottom: var(--space-lg); }

.field { margin-bottom: var(--space-lg); }
.field label {
  display: block; font-size: 12px; font-weight: 700;
  color: var(--text-secondary); letter-spacing: 0.04em; margin-bottom: var(--space-xs);
  text-transform: uppercase;
}
.field input {
  width: 100%; font-size: 14px; color: var(--text-primary);
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 11px 13px; outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.field input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }

.pick-row { display: flex; gap: 8px; margin-top: 8px; }
.model-pick, .provider-pick {
  flex: 1; font-size: 13px; color: var(--text-primary);
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 9px 12px; outline: none; cursor: pointer;
  transition: border-color 0.2s;
}
.model-pick:focus, .provider-pick:focus { border-color: var(--primary); }
.model-pick option, .provider-pick option { background: var(--bg-card); color: var(--text-primary); }

.key-row { display: flex; gap: 8px; }
.key-row input { flex: 1; }
.btn-small { padding: 9px 14px; font-size: 12px; border-radius: var(--radius-sm); }

.field-hint { font-size: 11px; color: var(--text-tertiary); margin-top: 6px; line-height: 1.6; }
.field-hint.masked { color: var(--success); font-weight: 600; }

.settings-msg {
  margin-bottom: var(--space-md);
  padding: 10px 14px; border-radius: var(--radius-sm);
  font-size: 13px; line-height: 1.7; word-break: break-word;
}
.settings-msg.ok { color: var(--success); background: var(--success-bg); border: 1px solid rgba(31,136,61,0.3); }
.settings-msg.err { color: var(--error); background: var(--error-bg); border: 1px solid var(--error-border); }

.modal-foot { display: flex; align-items: center; gap: 12px; margin-top: var(--space-sm); }
.modal-foot .spacer { flex: 1; }

/* ---------- 金鑰庫 ---------- */
.ks-list { display: flex; flex-direction: column; gap: 8px; }
.ks-empty { font-size: 12px; color: var(--text-tertiary); padding: 4px 0; }
.ks-group { display: flex; flex-direction: column; gap: 4px; }
.ks-group-title {
  font-size: 11px; font-weight: 700; letter-spacing: 0.06em;
  color: var(--primary-dark);
  border-bottom: 1px solid var(--border-light); padding-bottom: 4px;
  text-transform: uppercase;
}
.ks-item {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 6px 10px; border-radius: var(--radius-sm);
  background: var(--bg-subtle); border: 1px solid var(--border-light);
  transition: border-color 0.2s;
}
.ks-item:hover { border-color: rgba(var(--primary-rgb), 0.3); }
.ks-item-meta {
  font-size: 12px; color: var(--text-secondary);
  font-family: var(--font-mono);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ks-del { flex-shrink: 0; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 34px; z-index: 60;
  transform: translateX(-50%);
  padding: 12px 24px; border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 600;
  color: var(--text-inverse);
  background: var(--text-primary);
  border: none;
  box-shadow: var(--shadow-lg);
  animation: toastIn 0.35s cubic-bezier(0.2, 0.8, 0.3, 1) both;
}

/* ---------- 開牌儀式 ---------- */
.ceremony {
  position: fixed; inset: 0; z-index: 45;
  display: grid; place-items: center;
  background: rgba(248, 249, 250, 0.92);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  animation: fadeIn 0.35s ease both;
}
.ceremony-inner { display: flex; flex-direction: column; align-items: center; gap: 32px; }
.ceremony-orb { position: relative; display: grid; place-items: center; }
.ceremony-ring {
  position: absolute; inset: -28px;
  border: 2px solid rgba(var(--primary-rgb), 0.35);
  border-radius: 50%;
  animation: ringPulse 2s ease-out infinite;
}
.ceremony-ring:nth-child(2) { inset: -52px; animation-delay: 0.6s; }
.ceremony-taiji {
  width: 120px; height: 120px; border-radius: 50%;
  background: linear-gradient(90deg, var(--primary) 50%, #FFFFFF 50%);
  position: relative; border: 3px solid var(--primary);
  box-shadow: 0 0 60px rgba(var(--primary-rgb), 0.3);
  animation: ceremonySpin 2s cubic-bezier(0.25, 0.8, 0.3, 1) both;
}
.ceremony-taiji::before, .ceremony-taiji::after {
  content: ""; position: absolute; width: 60px; height: 60px; border-radius: 50%;
}
.ceremony-taiji::before {
  left: 3px; top: 30px; background: #FFFFFF;
  background-image: radial-gradient(circle at 50% 50%, var(--primary) 0 14px, transparent 15px);
}
.ceremony-taiji::after {
  right: 3px; top: 30px; background: var(--primary);
  background-image: radial-gradient(circle at 50% 50%, #FFFFFF 0 14px, transparent 15px);
}
.ceremony-label {
  font-family: var(--font-title); font-size: 16px; font-weight: 700;
  letter-spacing: 0.2em; color: var(--primary-dark);
  text-align: center; animation: fadeUp 0.6s 0.3s both;
}
.ceremony-card {
  position: fixed; left: 50%; top: 50%;
  width: 80px; height: 114px;
  margin-left: -40px; margin-top: -57px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  border-radius: 12px;
  background: var(--bg-card);
  border: 1px solid rgba(var(--primary-rgb), 0.35);
  color: var(--primary-dark);
  box-shadow: var(--shadow-md);
  font-size: 24px; pointer-events: none;
  will-change: transform, opacity;
}
.cc-name { font-family: var(--font-title); font-size: 12px; font-weight: 700; letter-spacing: 0.1em; }
.ceremony-prepped { opacity: 0; pointer-events: none; }
.ceremony-prepped .panel { opacity: 0; transform: translateY(14px); }

@keyframes ringPulse {
  0% { transform: scale(0.86); opacity: 0.75; }
  100% { transform: scale(1.3); opacity: 0; }
}
@keyframes ceremonySpin {
  0% { transform: scale(0.25) rotate(0deg); opacity: 0.15; }
  55% { transform: scale(1.1) rotate(540deg); opacity: 1; }
  100% { transform: scale(1) rotate(720deg); opacity: 1; }
}
/* ---------- 回看模式提示 ---------- */
.review-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 18px; margin-bottom: var(--space-md);
  border-radius: var(--radius-sm);
  font-size: 13px; color: var(--primary-dark);
  background: var(--primary-light);
  border: 1px solid rgba(var(--primary-rgb), 0.25);
  animation: fadeUp 0.4s both;
}
.review-banner b { font-weight: 700; }

/* ---------- 歷次問事（表格） ---------- */
.history {
  padding: var(--space-xl); margin-bottom: var(--space-xl);
  overflow: hidden;
}
.history-head {
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--border-light);
  padding-bottom: var(--space-md); margin-bottom: var(--space-lg);
}
.history-head h2 {
  font-family: var(--font-title); font-size: 18px; font-weight: 700;
  color: var(--text-primary);
}
.history-tools { display: flex; align-items: center; gap: 12px; }
.history-count { font-size: 12px; color: var(--text-tertiary); }

/* 表格容器 */
.history-list {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.history-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 680px;
}
.history-table thead th {
  position: sticky; top: 0;
  background: var(--bg-subtle);
  border-bottom: 2px solid var(--border);
  font-family: var(--font-title);
  font-size: 11px; font-weight: 700;
  letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--text-tertiary);
  padding: 10px 12px;
  text-align: left;
  white-space: nowrap;
}
.history-table thead th.col-time { width: 150px; }
.history-table thead th.col-question { min-width: 200px; }
.history-table thead th.col-sys { width: 220px; }
.history-table thead th.col-model { width: 130px; }
.history-table thead th.col-status { width: 80px; text-align: center; }
.history-table thead th.col-actions { width: 150px; text-align: right; }

.history-table tbody tr {
  transition: background 0.15s;
}
/* 斑馬條紋 */
.history-table tbody tr:nth-child(odd) { background: var(--bg-card); }
.history-table tbody tr:nth-child(even) { background: var(--bg-subtle); }
.history-table tbody tr:hover { background: var(--primary-light); }

.history-table td {
  padding: 14px 12px;
  border-bottom: 1px solid var(--border-light);
  vertical-align: middle;
  font-size: 13px;
}

/* 時間欄 */
.hist-time { font-family: var(--font-mono); font-size: 12px; color: var(--text-tertiary); white-space: nowrap; }

/* 問題欄 */
.hist-question {
  font-size: 14px; color: var(--text-primary); line-height: 1.5;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

/* 玄學欄 */
.hist-sys { display: flex; flex-wrap: wrap; gap: 4px; }
.hist-sys-chip {
  font-size: 11px; font-weight: 600;
  padding: 2px 8px; border-radius: 6px;
  background: var(--primary-lighter); color: var(--primary-dark);
  border: 1px solid rgba(var(--primary-rgb), 0.2);
  white-space: nowrap;
}
.hist-sys-chip.all {
  background: var(--primary); color: #FFFFFF;
  border-color: var(--primary);
}

/* 模型欄 */
.hist-model {
  font-family: var(--font-mono); font-size: 11px;
  color: var(--text-secondary);
  background: var(--bg-subtle);
  padding: 2px 8px; border-radius: 6px;
  border: 1px solid var(--border-light);
  white-space: nowrap;
}
.hist-model.none { color: var(--text-tertiary); }

/* 狀態欄 */
.hist-status { text-align: center; }
.hist-status-chip {
  display: inline-block;
  font-size: 11px; font-weight: 700;
  padding: 3px 10px; border-radius: 20px;
}
.hist-status-chip.ok { color: var(--success); background: var(--success-bg); border: 1px solid rgba(31,136,61,0.3); }
.hist-status-chip.cast { color: var(--text-tertiary); background: var(--bg-subtle); border: 1px solid var(--border); }
.hist-source-badge {
  font-size: 10px; color: var(--primary); font-weight: 700;
  margin-left: 6px;
}

/* 操作欄 */
.hist-actions { display: flex; gap: 6px; justify-content: flex-end; }

/* 歷史空狀態 */
.history-empty {
  text-align: center; color: var(--text-tertiary);
  font-size: 14px; padding: var(--space-xl) 0;
}

/* 卡片式堆疊（手機） */
@media (max-width: 767px) {
  .history-table { min-width: 0; }
  .history-table thead { display: none; }
  .history-table, .history-table tbody, .history-table tr, .history-table td {
    display: block; width: 100%;
  }
  .history-table tbody tr {
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    margin-bottom: 12px;
    padding: var(--space-md);
    background: var(--bg-card) !important;
  }
  .history-table tbody tr:hover { background: var(--primary-lighter) !important; }
  .history-table td {
    border: none; padding: 4px 0;
    display: flex; align-items: center; gap: 8px;
  }
  .history-table td::before {
    content: attr(data-label);
    font-family: var(--font-title);
    font-size: 11px; font-weight: 700;
    color: var(--text-tertiary);
    min-width: 52px; text-transform: uppercase;
    letter-spacing: 0.05em;
  }
  .history-table td.col-sys, .history-table td.col-model { flex-wrap: wrap; }
}

/* ---------- 重新解讀列 ---------- */
.reinterp-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  margin: 0 0 var(--space-lg);
  padding: var(--space-md);
  border: 1px solid rgba(var(--primary-rgb), 0.25);
  border-radius: var(--radius-sm);
  background: var(--primary-lighter);
  animation: fadeUp 0.4s both;
}
.reinterp-title {
  font-family: var(--font-title); font-size: 13px; font-weight: 700;
  color: var(--primary-dark); letter-spacing: 0.04em; white-space: nowrap;
}
.reinterp-input {
  flex: 1 1 150px; min-width: 130px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-primary); font-size: 13px; outline: none;
  transition: border-color 0.2s;
}
.reinterp-input:focus { border-color: var(--primary); }
.reinterp-select {
  flex: 1 1 130px; min-width: 120px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-primary); font-size: 13px; outline: none; cursor: pointer;
  transition: border-color 0.2s;
}
.reinterp-select:focus { border-color: var(--primary); }
.reinterp-select option { background: var(--bg-card); color: var(--text-primary); }

.reinterp-sys {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  width: 100%; padding-top: 12px;
  border-top: 1px solid rgba(var(--primary-rgb), 0.2);
  margin-top: 4px;
}
.reinterp-sys-label {
  font-size: 11px; font-weight: 700; color: var(--text-secondary);
  letter-spacing: 0.06em; white-space: nowrap;
}
.reinterp-sys-chips { gap: 4px; }
.reinterp-sys .sys-chip { padding: 4px 10px; font-size: 11px; gap: 4px; }

/* ---------- 底部 ---------- */
.foot { text-align: center; color: var(--text-tertiary); font-size: 12px; line-height: 2; padding-top: var(--space-md); }
.foot-small { font-size: 11px; opacity: 0.7; letter-spacing: 0.08em; }

/* ---------- 動畫 ---------- */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes blink { 50% { opacity: 0; } }
@keyframes shake {
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}
@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, 16px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

.shake { animation: shake 0.4s; }
.hidden { display: none !important; }

/* 捲軸 */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(var(--primary-rgb), 0.25); border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: rgba(var(--primary-rgb), 0.45); }

/* ---------- 主題切換按鈕 ---------- */
.theme-toggle {
  position: fixed; top: 16px; right: 16px; z-index: 40;
  width: 42px; height: 42px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 18px; cursor: pointer;
  color: var(--text-secondary);
  background: var(--bg-card);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  transition: transform 0.3s, box-shadow 0.3s, border-color 0.3s;
}
.theme-toggle:hover {
  transform: rotate(20deg) scale(1.06);
  border-color: var(--primary);
  box-shadow: 0 0 16px rgba(var(--primary-rgb), 0.3);
}

/* ---------- 響應式斷點 ---------- */
@media (max-width: 640px) {
  .page { padding: 24px 16px 48px; }
  .ask-card, .answer, .history { padding: var(--space-lg); }
  .ask-row { gap: 10px; }
  .sys-chips { gap: 6px; }
  .panel { padding: var(--space-lg); }
}
/* ============================================================
   暗黑主題
   ============================================================ */
html[data-theme="dark"], body[data-theme="dark"] {
  --bg-page: #0B1220;
  --bg-card: #111A2E;
  --bg-subtle: #0E1626;

  --text-primary: #E8ECF4;
  --text-secondary: #9AA7BD;
  --text-tertiary: #5E6C84;

  --border: #2A364E;
  --border-light: #1D2942;

  --primary: #4D8DF0;
  --primary-dark: #2E6FE0;
  --primary-light: #1B2A44;
  --primary-lighter: #131E33;
  --primary-rgb: 77, 141, 240;

  --success: #4ADE80;
  --success-bg: rgba(74, 222, 128, 0.12);
  --error: #F87171;
  --error-bg: rgba(248, 113, 113, 0.10);
  --error-border: rgba(248, 113, 113, 0.35);

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.5);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.55);
  --shadow-lg: 0 8px 28px rgba(0, 0, 0, 0.65);
}

html[data-theme="dark"] body, body[data-theme="dark"] {
  background: linear-gradient(180deg, #0B1220 0%, #070D18 100%);
}

/* 星空背景只在暗黑主題顯示 */
#stars {
  position: fixed; inset: 0;
  width: 100%; height: 100%;
  z-index: 0; pointer-events: none;
}
html[data-theme="dark"] #stars, body[data-theme="dark"] #stars { display: block; }
html[data-theme="light"] #stars, body[data-theme="light"] #stars { display: none; }

/* 暗黑主題下的按鈕與元件 */
html[data-theme="dark"] .btn-gold {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  box-shadow: 0 4px 14px rgba(var(--primary-rgb), 0.35);
}
html[data-theme="dark"] .btn-ghost { color: var(--text-secondary); border-color: var(--border); }
html[data-theme="dark"] .btn-ghost:hover:not(:disabled) {
  color: var(--primary); border-color: var(--primary); background: rgba(var(--primary-rgb), 0.08);
}
html[data-theme="dark"] .btn-gear { color: var(--text-secondary); border-color: var(--border); }
html[data-theme="dark"] .btn-gear:hover { color: var(--primary); border-color: var(--primary); background: rgba(var(--primary-rgb), 0.1); }
html[data-theme="dark"] .panel:hover { box-shadow: var(--shadow-md); border-color: rgba(var(--primary-rgb), 0.4); }
html[data-theme="dark"] .modal-x:hover { color: var(--error); border-color: var(--error-border); background: var(--error-bg); }
html[data-theme="dark"] .toast { background: var(--text-primary); color: var(--bg-page); }
html[data-theme="dark"] .ceremony { background: rgba(7, 13, 24, 0.88); }
html[data-theme="dark"] .ceremony-card {
  background: linear-gradient(170deg, #1A2540, #0D1526);
  border-color: var(--primary); color: var(--primary);
}
html[data-theme="dark"] .ceremony-taiji { border-color: var(--primary); box-shadow: 0 0 60px rgba(var(--primary-rgb), 0.4); }
html[data-theme="dark"] .taiji { border-color: var(--primary); }