/* 易奇入門學堂 — 暗色護眼 / 手機優先 */

:root {
  --ink-900: #0d1117;
  --ink-850: #11161e;
  --ink-800: #151b24;
  --ink-750: #1a212c;
  --ink-700: #202836;
  --ink-600: #2a3444;
  --ink-500: #3a4658;

  --text-hi: #e2e8f0;
  --text: #c3ccd9;
  --text-mid: #94a1b3;
  --text-low: #7a8798;

  --jade: #4f9e8f;
  --jade-dim: #2f6b60;
  --jade-glow: rgba(79, 158, 143, 0.16);
  --cinnabar: #c4553f;
  --cinnabar-dim: #7d3527;
  --gold: #c9a227;
  --gold-dim: #7a6218;
  --azure: #4a7fb5;

  --ok: #4f9e8f;
  --warn: #c9a227;
  --bad: #c4553f;

  /* ── 語意色（主題切換時一併覆寫） ── */
  --danger-text: #e08a76;
  --deity: #a98bc4;
  --on-accent: #0d1117;
  --on-accent-soft: #dff3ee;
  --on-accent-strong: #e6f5f1;
  --on-danger: #ffffff;

  /* 半透明疊色 */
  --tint-jade-10: rgba(47, 107, 96, 0.1);
  --tint-jade-12: rgba(47, 107, 96, 0.12);
  --tint-jade-14: rgba(47, 107, 96, 0.14);
  --tint-jade-18: rgba(47, 107, 96, 0.18);
  --tint-jade-20: rgba(47, 107, 96, 0.2);
  --tint-jade-22: rgba(47, 107, 96, 0.22);
  --tint-jade-24: rgba(47, 107, 96, 0.24);
  --tint-gold-10: rgba(201, 162, 39, 0.1);
  --tint-gold-16: rgba(201, 162, 39, 0.16);
  --tint-red-10: rgba(196, 85, 63, 0.1);
  --tint-red-12: rgba(196, 85, 63, 0.12);
  --tint-red-14: rgba(196, 85, 63, 0.14);
  --tint-red-16: rgba(196, 85, 63, 0.16);
  --tint-jade-tag: rgba(79, 158, 143, 0.18);

  /* 導覽列底色 */
  --bar-top: rgba(13, 17, 23, 0.94);
  --bar-bottom: rgba(17, 22, 30, 0.97);

  /* 五行線條 */
  --line-sheng: #2f6b60;
  --line-ke: #7d3527;

  /* 五行色 */
  --wx-wood: #5fa86b;
  --wx-fire: #d4573f;
  --wx-earth: #b98a4a;
  --wx-metal: #c3ccd6;
  --wx-water: #4a7fb5;

  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 18px;

  --shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);

  --nav-h: 62px;
  --maxw: 1080px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  padding: 0;
  background: var(--ink-900);
  color: var(--text);
  font-family: "Noto Sans TC", "PingFang TC", "Hiragino Sans CNS",
    "Microsoft JhengHei", "Heiti TC", system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.75;
  letter-spacing: 0.01em;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
  overflow-x: hidden;
}

h1, h2, h3, h4 {
  color: var(--text-hi);
  line-height: 1.4;
  margin: 0;
  font-weight: 700;
  letter-spacing: 0.02em;
}

p { margin: 0 0 0.85em; }
p:last-child { margin-bottom: 0; }

a { color: var(--jade); text-decoration: none; }
a:hover { text-decoration: underline; }

button {
  font-family: inherit;
  font-size: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

/* ── 版面 ───────────────────────────── */
.wrap {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 16px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--bar-top);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--ink-700);
}

.topbar-in {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.brand-mark {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  border-radius: 9px;
  background: linear-gradient(150deg, var(--jade-dim), var(--ink-700));
  border: 1px solid var(--jade-dim);
  display: grid;
  place-items: center;
  font-size: 17px;
  color: var(--jade);
  font-weight: 700;
}

.brand-txt { min-width: 0; }

.brand-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-hi);
  letter-spacing: 0.06em;
  white-space: nowrap;
}

.brand-sub {
  font-size: 10.5px;
  color: var(--text-low);
  letter-spacing: 0.08em;
  white-space: nowrap;
}

.topbar-spacer { flex: 1; }

.mode-switch {
  display: flex;
  background: var(--ink-800);
  border: 1px solid var(--ink-600);
  border-radius: 999px;
  padding: 2px;
  flex: 0 0 auto;
}

.mode-switch button {
  padding: 9px 12px;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  font-size: 11.5px;
  color: var(--text-mid);
  font-weight: 600;
  white-space: nowrap;
  transition: background 0.18s, color 0.18s;
}

.mode-switch button[aria-pressed="true"] {
  background: var(--jade-dim);
  color: var(--on-accent-soft);
}

/* ── 底部導覽 ───────────────────────── */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 60;
  background: var(--bar-bottom);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--ink-700);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.tabbar-in {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  max-width: 640px;
  margin: 0 auto;
}

.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 8px 2px 7px;
  color: var(--text-low);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.02em;
  position: relative;
  transition: color 0.16s;
  min-height: 54px;
}

.tab-ico {
  font-size: 17px;
  line-height: 1;
  opacity: 0.85;
}

.tab[aria-selected="true"] { color: var(--jade); }
.tab[aria-selected="true"] .tab-ico { opacity: 1; }

.tab[aria-selected="true"]::before {
  content: "";
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 22px;
  height: 2px;
  background: var(--jade);
  border-radius: 0 0 2px 2px;
}

/* ── 分頁 ───────────────────────────── */
.panel { display: none; padding: 20px 0 32px; }
.panel.is-active { display: block; animation: fadeUp 0.28s ease; }

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

@media (prefers-reduced-motion: reduce) {
  .panel.is-active { animation: none; }
  html { scroll-behavior: auto; }
}

/* ── 標題區 ─────────────────────────── */
.sec-head { margin-bottom: 18px; }

.sec-kicker {
  font-size: 10.5px;
  letter-spacing: 0.18em;
  color: var(--jade);
  font-weight: 700;
  text-transform: uppercase;
  margin-bottom: 5px;
}

.sec-title {
  font-size: 21px;
  margin-bottom: 7px;
  letter-spacing: 0.03em;
}

.sec-desc {
  font-size: 13.5px;
  color: var(--text-mid);
  line-height: 1.7;
}

/* ── 卡片 ───────────────────────────── */
.card {
  background: var(--ink-850);
  border: 1px solid var(--ink-700);
  border-radius: var(--r-md);
  padding: 16px;
  margin-bottom: 14px;
}

.card-tight { padding: 13px; }

.card-h {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-hi);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  letter-spacing: 0.03em;
}

.card-h .dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--jade);
  flex: 0 0 5px;
}

/* ── 進度 ───────────────────────────── */
.prog-card {
  background: linear-gradient(160deg, var(--ink-800), var(--ink-850));
  border: 1px solid var(--ink-600);
  border-radius: var(--r-lg);
  padding: 18px 16px;
  margin-bottom: 16px;
  position: relative;
  overflow: hidden;
}

.prog-card::after {
  content: "";
  position: absolute;
  top: -40px;
  right: -40px;
  width: 130px;
  height: 130px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--jade-glow), transparent 70%);
  pointer-events: none;
}

.prog-top {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.prog-label {
  font-size: 11px;
  color: var(--text-low);
  letter-spacing: 0.1em;
  margin-bottom: 3px;
}

.prog-day {
  font-size: 26px;
  font-weight: 700;
  color: var(--text-hi);
  line-height: 1.1;
  letter-spacing: 0.02em;
}

.prog-day small {
  font-size: 13px;
  color: var(--text-mid);
  font-weight: 500;
  margin-left: 3px;
}

.prog-pct {
  font-size: 22px;
  font-weight: 700;
  color: var(--jade);
  line-height: 1;
  letter-spacing: 0.01em;
}

.prog-pct small { font-size: 12px; color: var(--text-mid); font-weight: 500; }

.bar {
  height: 7px;
  background: var(--ink-700);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 10px;
}

.bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--jade-dim), var(--jade));
  border-radius: 999px;
  transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
  width: 0;
}

.prog-meta {
  display: flex;
  gap: 14px;
  font-size: 11.5px;
  color: var(--text-mid);
  flex-wrap: wrap;
}

.prog-meta b { color: var(--text-hi); font-weight: 700; }

/* ── 今日任務 ───────────────────────── */
.today {
  border: 1px solid var(--jade-dim);
  background: linear-gradient(165deg, var(--tint-jade-14), var(--ink-850) 60%);
  border-radius: var(--r-md);
  padding: 16px;
  margin-bottom: 16px;
}

.today-tag {
  display: inline-block;
  font-size: 10px;
  letter-spacing: 0.14em;
  color: var(--jade);
  border: 1px solid var(--jade-dim);
  border-radius: 999px;
  padding: 2px 9px;
  margin-bottom: 9px;
  font-weight: 700;
}

.today-title {
  font-size: 17px;
  color: var(--text-hi);
  font-weight: 700;
  margin-bottom: 6px;
  letter-spacing: 0.02em;
}

.today-goal {
  font-size: 13px;
  color: var(--text-mid);
  margin-bottom: 13px;
  line-height: 1.7;
}

.task-list { list-style: none; margin: 0 0 14px; padding: 0; }

.task-list li {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 7px 0;
  font-size: 13.5px;
  color: var(--text);
  border-bottom: 1px solid var(--ink-750);
}

.task-list li:last-child { border-bottom: none; }

.task-num {
  flex: 0 0 19px;
  height: 19px;
  border-radius: 50%;
  background: var(--ink-700);
  color: var(--text-mid);
  font-size: 10.5px;
  font-weight: 700;
  display: grid;
  place-items: center;
  margin-top: 3px;
}

/* ── 按鈕 ───────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 11px 18px;
  border-radius: var(--r-sm);
  font-size: 13.5px;
  font-weight: 700;
  letter-spacing: 0.03em;
  transition: background 0.16s, border-color 0.16s, transform 0.1s;
  border: 1px solid transparent;
  min-height: 44px;
}

.btn:active { transform: scale(0.985); }

.btn-primary {
  background: var(--jade-dim);
  color: var(--on-accent-strong);
  border-color: var(--jade);
}

.btn-primary:hover { background: var(--jade); color: var(--on-accent); }

.btn-ghost {
  background: var(--ink-800);
  color: var(--text);
  border-color: var(--ink-600);
}

.btn-ghost:hover { border-color: var(--ink-500); background: var(--ink-750); }

.btn-sm { padding: 9px 14px; font-size: 12px; min-height: 40px; }

.btn-block { width: 100%; }

.btn:disabled {
  opacity: 0.42;
  cursor: not-allowed;
  transform: none;
}

.btn-row { display: flex; gap: 9px; flex-wrap: wrap; }

/* ── 課表 ───────────────────────────── */
.day-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(58px, 1fr));
  gap: 7px;
}

.day-cell {
  aspect-ratio: 1;
  border-radius: var(--r-sm);
  background: var(--ink-800);
  border: 1px solid var(--ink-700);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  font-size: 10px;
  color: var(--text-low);
  transition: border-color 0.16s, background 0.16s;
  padding: 2px;
  min-height: 52px;
}

.day-cell b {
  font-size: 14px;
  color: var(--text-mid);
  font-weight: 700;
  line-height: 1;
}

.day-cell.is-done {
  background: var(--tint-jade-20);
  border-color: var(--jade-dim);
}

.day-cell.is-done b { color: var(--jade); }

.day-cell.is-today {
  border-color: var(--gold);
  background: var(--tint-gold-10);
}

.day-cell.is-today b { color: var(--gold); }

.day-cell.is-locked { opacity: 0.5; }

.day-cell.is-active {
  border-color: var(--jade);
  box-shadow: 0 0 0 1px var(--jade) inset;
}

/* ── 五行輪 ─────────────────────────── */
.wx-stage {
  position: relative;
  width: 100%;
  max-width: 340px;
  margin: 0 auto 14px;
  aspect-ratio: 1;
}

.wx-svg { width: 100%; height: 100%; display: block; overflow: visible; }

.wx-node { cursor: pointer; }

.wx-node circle {
  transition: r 0.2s, stroke-width 0.2s, fill-opacity 0.2s;
}

.wx-node text {
  font-size: 15px;
  font-weight: 700;
  fill: var(--text-hi);
  pointer-events: none;
  text-anchor: middle;
  dominant-baseline: central;
}

.wx-node.is-sel circle {
  stroke-width: 3;
  fill-opacity: 0.42;
}

.wx-node.is-rel circle { stroke-width: 2.5; }

.wx-line {
  stroke-linecap: round;
  transition: stroke-opacity 0.2s, stroke-width 0.2s;
}

.wx-line.is-dim { stroke-opacity: 0.1; }
.wx-line.is-hi { stroke-width: 3.4; stroke-opacity: 1; }

.wx-readout {
  background: var(--ink-800);
  border: 1px solid var(--ink-600);
  border-radius: var(--r-md);
  padding: 14px;
  min-height: 96px;
}

.wx-readout-empty {
  color: var(--text-low);
  font-size: 13px;
  text-align: center;
  padding: 22px 8px;
  line-height: 1.7;
}

.wx-rel {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-hi);
  margin-bottom: 6px;
  letter-spacing: 0.04em;
}

.wx-rel .tag {
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 999px;
  margin-left: 7px;
  vertical-align: middle;
  font-weight: 700;
  letter-spacing: 0.06em;
}

.tag-gen { background: var(--tint-jade-tag); color: var(--jade); border: 1px solid var(--jade-dim); }
.tag-ovc { background: var(--tint-red-16); color: var(--danger-text); border: 1px solid var(--cinnabar-dim); }

.wx-plain { font-size: 13px; color: var(--text); line-height: 1.75; margin-bottom: 7px; }

.wx-meta {
  font-size: 12px;
  color: var(--text-mid);
  border-top: 1px solid var(--ink-700);
  padding-top: 8px;
  line-height: 1.7;
}

.wx-meta b { color: var(--gold); font-weight: 600; }

/* ── 八卦積木 ───────────────────────── */
.builder {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}

.yao-stack {
  display: flex;
  flex-direction: column-reverse;
  gap: 7px;
  padding: 14px;
  background: var(--ink-800);
  border: 1px solid var(--ink-700);
  border-radius: var(--r-md);
}

.yao-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.yao-idx {
  flex: 0 0 26px;
  font-size: 10px;
  color: var(--text-low);
  text-align: right;
  letter-spacing: 0.04em;
}

.yao-btn {
  flex: 1;
  height: 40px;
  border-radius: 4px;
  background: var(--ink-700);
  border: 1px solid var(--ink-600);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background 0.16s, border-color 0.16s;
  position: relative;
}

.yao-btn:hover { border-color: var(--ink-500); }

.yao-btn .seg {
  height: 9px;
  border-radius: 2px;
  background: var(--ink-500);
  transition: background 0.18s;
}

.yao-btn[data-yang="1"] .seg { background: var(--jade); }
.yao-btn[data-yang="1"] .seg-full { width: 78%; }
.yao-btn[data-yang="0"] .seg-half { width: 33%; }

.yao-btn[data-yang="1"] .seg-half { display: none; }
.yao-btn[data-yang="0"] .seg-full { display: none; }

.yao-btn[data-yang="1"] { background: var(--tint-jade-22); border-color: var(--jade-dim); }

.yao-label {
  position: absolute;
  right: 8px;
  font-size: 9.5px;
  color: var(--text-low);
  letter-spacing: 0.06em;
}

.yao-sep {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 10px;
  color: var(--text-low);
  letter-spacing: 0.1em;
  padding: 2px 0;
}

.yao-sep::before, .yao-sep::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--ink-700);
}

.hex-out {
  background: var(--ink-800);
  border: 1px solid var(--ink-600);
  border-radius: var(--r-md);
  padding: 16px;
  text-align: center;
}

.hex-sym {
  font-size: 40px;
  line-height: 1.1;
  color: var(--jade);
  letter-spacing: 0.1em;
  margin-bottom: 4px;
}

.hex-name {
  font-size: 19px;
  font-weight: 700;
  color: var(--text-hi);
  margin-bottom: 3px;
  letter-spacing: 0.05em;
}

.hex-num {
  font-size: 11px;
  color: var(--text-low);
  letter-spacing: 0.1em;
  margin-bottom: 10px;
}

.hex-plain {
  font-size: 13px;
  color: var(--text);
  line-height: 1.75;
  text-align: left;
  border-top: 1px solid var(--ink-700);
  padding-top: 10px;
}

.hex-parts {
  display: flex;
  justify-content: center;
  gap: 18px;
  font-size: 11.5px;
  color: var(--text-mid);
  margin-bottom: 10px;
}

.hex-parts b { color: var(--gold); font-weight: 600; }

/* ── 64 卦表 ────────────────────────── */
.search-box {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.search-box input {
  flex: 1;
  background: var(--ink-800);
  border: 1px solid var(--ink-600);
  border-radius: var(--r-sm);
  padding: 10px 13px;
  color: var(--text-hi);
  font-family: inherit;
  font-size: 14px;
  min-height: 44px;
}

.search-box input:focus {
  outline: none;
  border-color: var(--jade);
}

.search-box input::placeholder { color: var(--text-low); }

.hex-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 8px;
}

.hex-item {
  background: var(--ink-800);
  border: 1px solid var(--ink-700);
  border-radius: var(--r-sm);
  padding: 10px 11px;
  text-align: left;
  transition: border-color 0.16s, background 0.16s;
  display: flex;
  gap: 9px;
  align-items: flex-start;
}

.hex-item:hover { border-color: var(--jade-dim); background: var(--ink-750); }

.hex-item .hi-sym {
  font-size: 20px;
  color: var(--jade);
  line-height: 1.2;
  flex: 0 0 auto;
  letter-spacing: 0.04em;
}

.hex-item .hi-body { min-width: 0; }

.hex-item .hi-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-hi);
  letter-spacing: 0.03em;
  margin-bottom: 1px;
}

.hex-item .hi-num {
  font-size: 10px;
  color: var(--text-low);
  letter-spacing: 0.06em;
}

.hex-empty {
  text-align: center;
  color: var(--text-low);
  font-size: 13px;
  padding: 26px 10px;
}

/* ── 九宮格 ─────────────────────────── */
.palace-wrap {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}

.palace-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  background: var(--ink-800);
  border: 1px solid var(--ink-700);
  border-radius: var(--r-md);
  padding: 8px;
  aspect-ratio: 1;
  max-width: 380px;
  margin: 0 auto;
  width: 100%;
}

.palace-cell {
  background: var(--ink-750);
  border: 1px dashed var(--ink-600);
  border-radius: var(--r-sm);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  position: relative;
  transition: border-color 0.16s, background 0.16s;
  min-height: 0;
  padding: 3px;
}

.palace-cell.is-over {
  border-color: var(--jade);
  background: var(--tint-jade-20);
}

.palace-cell.is-ok {
  border-style: solid;
  border-color: var(--jade-dim);
  background: var(--tint-jade-14);
}

.palace-cell.is-bad {
  border-style: solid;
  border-color: var(--cinnabar-dim);
  background: var(--tint-red-12);
  animation: shake 0.32s;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}

.palace-cell .pc-num {
  position: absolute;
  top: 3px;
  left: 5px;
  font-size: 9px;
  color: var(--text-low);
  letter-spacing: 0.04em;
}

.palace-cell .pc-dir {
  position: absolute;
  bottom: 3px;
  right: 5px;
  font-size: 8.5px;
  color: var(--text-low);
  letter-spacing: 0.02em;
}

.palace-cell .pc-content {
  font-size: 19px;
  font-weight: 700;
  color: var(--text-hi);
  line-height: 1.1;
  letter-spacing: 0.02em;
}

.palace-cell .pc-sub {
  font-size: 9.5px;
  color: var(--text-mid);
  letter-spacing: 0.02em;
}

.palace-cell .pc-hint {
  font-size: 9px;
  color: var(--gold);
  letter-spacing: 0.02em;
  text-align: center;
  line-height: 1.3;
  padding: 0 2px;
}

.chip-tray {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding: 12px;
  background: var(--ink-800);
  border: 1px solid var(--ink-700);
  border-radius: var(--r-md);
  min-height: 60px;
  align-content: flex-start;
}

.chip {
  padding: 8px 13px;
  border-radius: var(--r-sm);
  background: var(--ink-700);
  border: 1px solid var(--ink-600);
  color: var(--text-hi);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.03em;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  transition: background 0.14s, border-color 0.14s, opacity 0.14s;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.chip:active { cursor: grabbing; }

.chip.is-drag {
  opacity: 0.4;
  border-color: var(--jade);
}

.chip.is-placed {
  background: var(--tint-jade-24);
  border-color: var(--jade-dim);
  color: var(--jade);
}

.chip.is-picked {
  border-color: var(--gold);
  background: var(--tint-gold-16);
  color: var(--gold);
}

.chip .chip-sub {
  font-size: 10px;
  color: var(--text-low);
  font-weight: 500;
}

.palace-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 12.5px;
  color: var(--text-mid);
  margin-top: 10px;
  flex-wrap: wrap;
}

.palace-status b { color: var(--jade); font-weight: 700; }

/* ── 奇門盤 ─────────────────────────── */
.qm-layers {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}

.layer-btn {
  padding: 7px 12px;
  border-radius: 999px;
  background: var(--ink-800);
  border: 1px solid var(--ink-600);
  color: var(--text-mid);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.03em;
  transition: all 0.16s;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.layer-btn[aria-pressed="true"] {
  background: var(--tint-jade-24);
  border-color: var(--jade);
  color: var(--jade);
}

.layer-btn .ly-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.5;
}

.layer-btn[aria-pressed="true"] .ly-dot { opacity: 1; }

.qm-board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
  background: var(--ink-800);
  border: 1px solid var(--ink-700);
  border-radius: var(--r-md);
  padding: 7px;
  aspect-ratio: 1;
  max-width: 400px;
  margin: 0 auto 12px;
  width: 100%;
}

.qm-cell {
  background: var(--ink-750);
  border: 1px solid var(--ink-700);
  border-radius: 6px;
  padding: 4px 3px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  position: relative;
  overflow: hidden;
  min-height: 0;
  transition: border-color 0.18s, background 0.18s;
}

.qm-cell.is-target {
  border-color: var(--gold);
  background: var(--tint-gold-10);
  box-shadow: 0 0 0 1px var(--gold) inset;
}

.qm-cell .qc-head {
  position: absolute;
  top: 2px;
  left: 4px;
  font-size: 8px;
  color: var(--text-low);
  letter-spacing: 0.02em;
  line-height: 1.2;
}

.qm-cell .qc-tri {
  position: absolute;
  top: 2px;
  right: 4px;
  font-size: 10px;
  color: var(--text-low);
  line-height: 1.2;
}

.qm-cell .qc-stems {
  display: flex;
  gap: 3px;
  align-items: baseline;
  margin-top: 8px;
  line-height: 1;
}

.qm-cell .qc-earth {
  font-size: 12px;
  color: var(--text-mid);
  font-weight: 600;
}

.qm-cell .qc-heaven {
  font-size: 15px;
  color: var(--gold);
  font-weight: 700;
}

.qm-cell .qc-door {
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1.2;
}

.qm-cell .qc-star {
  font-size: 10.5px;
  color: var(--azure);
  font-weight: 600;
  line-height: 1.2;
}

.qm-cell .qc-deity {
  font-size: 10px;
  color: var(--deity);
  font-weight: 600;
  line-height: 1.2;
}

.door-ji { color: var(--jade); }
.door-xiong { color: var(--danger-text); }
.door-ping { color: var(--text-mid); }

.qm-cell .qc-empty {
  font-size: 9px;
  color: var(--text-low);
  letter-spacing: 0.04em;
}

.qm-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 10.5px;
  color: var(--text-low);
  margin-bottom: 12px;
  justify-content: center;
}

.qm-legend span { display: inline-flex; align-items: center; gap: 4px; }

.qm-legend i {
  width: 8px;
  height: 8px;
  border-radius: 2px;
  display: inline-block;
}

.qm-q {
  background: var(--ink-800);
  border-left: 2px solid var(--jade);
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
  padding: 12px 14px;
  margin-bottom: 12px;
}

.qm-q .qq-cat {
  font-size: 10px;
  color: var(--jade);
  letter-spacing: 0.1em;
  font-weight: 700;
  margin-bottom: 4px;
}

.qm-q .qq-text {
  font-size: 14.5px;
  color: var(--text-hi);
  font-weight: 600;
  line-height: 1.6;
  margin-bottom: 7px;
}

.qm-q .qq-hint {
  font-size: 12px;
  color: var(--text-mid);
  line-height: 1.7;
}

.qm-q .qq-hint b { color: var(--gold); font-weight: 600; }

.qm-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.qm-nav .qnn {
  font-size: 12px;
  color: var(--text-mid);
  letter-spacing: 0.06em;
}

.qm-nav .qnn b { color: var(--text-hi); font-weight: 700; }

.sop {
  background: var(--ink-800);
  border: 1px solid var(--ink-700);
  border-radius: var(--r-md);
  padding: 14px;
  margin-bottom: 12px;
}

.sop-step {
  display: flex;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--ink-750);
  font-size: 13px;
  line-height: 1.65;
}

.sop-step:last-child { border-bottom: none; }

.sop-n {
  flex: 0 0 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--jade-dim);
  color: var(--on-accent-soft);
  font-size: 10.5px;
  font-weight: 700;
  display: grid;
  place-items: center;
  margin-top: 2px;
}

.sop-step b { color: var(--text-hi); font-weight: 700; }

.answer-box {
  background: var(--tint-jade-10);
  border: 1px solid var(--jade-dim);
  border-radius: var(--r-md);
  padding: 14px;
  margin-top: 12px;
}

.answer-box .ab-h {
  font-size: 11px;
  color: var(--jade);
  letter-spacing: 0.12em;
  font-weight: 700;
  margin-bottom: 8px;
}

.answer-box .ab-row {
  font-size: 13px;
  color: var(--text);
  line-height: 1.8;
  margin-bottom: 5px;
}

.answer-box .ab-row b { color: var(--text-hi); font-weight: 700; }

.answer-box .ab-concl {
  font-size: 13.5px;
  color: var(--text-hi);
  line-height: 1.75;
  border-top: 1px solid var(--jade-dim);
  padding-top: 9px;
  margin-top: 9px;
}

/* ── 測驗 ───────────────────────────── */
.quiz-meta {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.pill {
  font-size: 11px;
  padding: 4px 11px;
  border-radius: 999px;
  background: var(--ink-800);
  border: 1px solid var(--ink-600);
  color: var(--text-mid);
  letter-spacing: 0.04em;
  font-weight: 600;
}

.pill.is-on {
  background: var(--tint-jade-20);
  border-color: var(--jade-dim);
  color: var(--jade);
}

.q-card {
  background: var(--ink-850);
  border: 1px solid var(--ink-700);
  border-radius: var(--r-md);
  padding: 16px;
  margin-bottom: 14px;
}

.q-num {
  font-size: 10.5px;
  color: var(--text-low);
  letter-spacing: 0.1em;
  margin-bottom: 7px;
  font-weight: 600;
}

.q-text {
  font-size: 15.5px;
  color: var(--text-hi);
  font-weight: 600;
  line-height: 1.65;
  margin-bottom: 14px;
}

.opt {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 12px 13px;
  border-radius: var(--r-sm);
  background: var(--ink-800);
  border: 1px solid var(--ink-600);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  margin-bottom: 8px;
  transition: border-color 0.16s, background 0.16s;
  min-height: 48px;
}

.opt:hover:not(:disabled) { border-color: var(--ink-500); background: var(--ink-750); }

.opt-key {
  flex: 0 0 22px;
  height: 22px;
  border-radius: 5px;
  background: var(--ink-700);
  color: var(--text-mid);
  font-size: 11px;
  font-weight: 700;
  display: grid;
  place-items: center;
  margin-top: 1px;
}

.opt.is-right {
  border-color: var(--jade);
  background: var(--tint-jade-18);
}

.opt.is-right .opt-key { background: var(--jade); color: var(--on-accent); }

.opt.is-wrong {
  border-color: var(--cinnabar);
  background: var(--tint-red-14);
}

.opt.is-wrong .opt-key { background: var(--cinnabar); color: var(--on-danger); }

.opt:disabled { cursor: default; }

.feedback {
  border-radius: var(--r-sm);
  padding: 12px 13px;
  font-size: 13px;
  line-height: 1.75;
  margin-top: 10px;
}

.feedback.ok {
  background: var(--tint-jade-12);
  border: 1px solid var(--jade-dim);
  color: var(--text);
}

.feedback.no {
  background: var(--tint-red-10);
  border: 1px solid var(--cinnabar-dim);
  color: var(--text);
}

.feedback .fb-h {
  font-weight: 700;
  margin-bottom: 4px;
  letter-spacing: 0.04em;
}

.feedback.ok .fb-h { color: var(--jade); }
.feedback.no .fb-h { color: var(--danger-text); }

.quiz-result {
  text-align: center;
  padding: 26px 16px;
  background: var(--ink-850);
  border: 1px solid var(--ink-600);
  border-radius: var(--r-lg);
}

.qr-score {
  font-size: 44px;
  font-weight: 700;
  color: var(--jade);
  line-height: 1;
  margin-bottom: 6px;
  letter-spacing: 0.02em;
}

.qr-score small { font-size: 17px; color: var(--text-mid); font-weight: 500; }

.qr-txt {
  font-size: 14px;
  color: var(--text-mid);
  margin-bottom: 18px;
  line-height: 1.7;
}

/* ── 錯題本 ─────────────────────────── */
.wrong-item {
  background: var(--ink-800);
  border: 1px solid var(--ink-700);
  border-left: 2px solid var(--cinnabar);
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
  padding: 12px 13px;
  margin-bottom: 9px;
}

.wrong-item .wi-q {
  font-size: 13.5px;
  color: var(--text-hi);
  font-weight: 600;
  line-height: 1.6;
  margin-bottom: 6px;
}

.wrong-item .wi-a {
  font-size: 12.5px;
  color: var(--jade);
  line-height: 1.7;
  margin-bottom: 4px;
}

.wrong-item .wi-e {
  font-size: 12px;
  color: var(--text-mid);
  line-height: 1.7;
  border-top: 1px solid var(--ink-750);
  padding-top: 6px;
  margin-top: 6px;
}

.wrong-item .wi-meta {
  font-size: 10px;
  color: var(--text-low);
  letter-spacing: 0.06em;
  margin-top: 6px;
}

.empty-state {
  text-align: center;
  padding: 34px 16px;
  color: var(--text-low);
  font-size: 13.5px;
  line-height: 1.8;
}

.empty-state .es-ico {
  font-size: 30px;
  margin-bottom: 10px;
  opacity: 0.5;
}

/* ── 提示條 ─────────────────────────── */
.note {
  font-size: 12px;
  color: var(--text-mid);
  line-height: 1.75;
  background: var(--ink-800);
  border-left: 2px solid var(--ink-500);
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
  padding: 10px 12px;
  margin-top: 12px;
}

.note b { color: var(--gold); font-weight: 600; }

.note-warn { border-left-color: var(--gold); }

/* ── 概念卡 ─────────────────────────── */
.concept {
  background: var(--ink-800);
  border: 1px solid var(--ink-700);
  border-radius: var(--r-md);
  padding: 14px;
  margin-bottom: 10px;
}

.concept .c-h {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--text-hi);
  margin-bottom: 6px;
  letter-spacing: 0.03em;
  display: flex;
  align-items: center;
  gap: 7px;
}

.concept .c-h .c-sym {
  font-size: 17px;
  color: var(--jade);
}

.concept .c-b {
  font-size: 13px;
  color: var(--text);
  line-height: 1.8;
}

.concept .c-b b { color: var(--gold); font-weight: 600; }

/* ── 表格 ───────────────────────────── */
.tbl-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -4px;
  padding: 0 4px;
}

table.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
  min-width: 420px;
}

/* 欄位少、內容短的表格：手機上不需要橫向捲動 */
table.tbl.tbl-fit {
  min-width: 0;
  font-size: 12px;
}

table.tbl.tbl-fit th,
table.tbl.tbl-fit td {
  padding: 7px 6px;
}

table.tbl.tbl-fit th:first-child,
table.tbl.tbl-fit td:first-child {
  padding-left: 2px;
}

table.tbl.tbl-fit th:last-child,
table.tbl.tbl-fit td:last-child {
  padding-right: 2px;
}

table.tbl th {
  text-align: left;
  padding: 8px 9px;
  color: var(--text-mid);
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.06em;
  border-bottom: 1px solid var(--ink-600);
  white-space: nowrap;
}

table.tbl td {
  padding: 8px 9px;
  border-bottom: 1px solid var(--ink-750);
  color: var(--text);
  line-height: 1.6;
}

table.tbl tr:last-child td { border-bottom: none; }

table.tbl td b { color: var(--text-hi); font-weight: 700; }

/* ── 頁尾 ───────────────────────────── */
.foot {
  border-top: 1px solid var(--ink-700);
  padding: 22px 0 30px;
  margin-top: 10px;
  font-size: 11.5px;
  color: var(--text-low);
  line-height: 1.9;
}

.foot b { color: var(--text-mid); font-weight: 600; }

/* ── 桌面 ───────────────────────────── */
@media (min-width: 720px) {
  body { font-size: 15.5px; }

  .wrap { padding: 0 24px; }

  .sec-title { font-size: 25px; }

  .builder { grid-template-columns: 1fr 1fr; align-items: start; }

  .palace-wrap { grid-template-columns: 1.15fr 1fr; align-items: start; }

  .hex-grid { grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); }

  .day-grid { grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); }

  .prog-day { font-size: 30px; }

  .prog-pct { font-size: 26px; }

  .qm-board { max-width: 440px; }

  .palace-grid { max-width: 420px; }

  .wx-stage { max-width: 380px; }
}

@media (min-width: 1000px) {
  .tabbar-in { max-width: 720px; }
  .tab { font-size: 11px; }
  .tab-ico { font-size: 18px; }
}

/* ── 小螢幕微調 ─────────────────────── */
@media (max-width: 360px) {
  .brand-sub { display: none; }
  .tab { font-size: 9px; }
  .tab-ico { font-size: 15px; }
  .qm-cell .qc-door { font-size: 11px; }
  .qm-cell .qc-star, .qm-cell .qc-deity { font-size: 9px; }
  .palace-cell .pc-content { font-size: 16px; }
}

/* ── 無障礙 ─────────────────────────── */
:focus-visible {
  outline: 2px solid var(--jade);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
