:root {
  --bg: #f6f1e7;
  --paper: #fffdf8;
  --ink: #2b2420;
  --muted: #6f6359;
  --line: #ddd2c2;
  --accent: #8a2f2a;
  --accent-ink: #fff;
  --gold: #b8892e;
  --table: #23413a;
  --table-2: #1b332d;
  --back-1: #3b2a5c;
  --back-2: #5a4386;
  --ok: #2f6b3f;
  --warn: #9a5b00;
  --cw: 56px;
  --ch: 84px;
  --dur: 1;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1714; --paper: #24201c; --ink: #efe7dc; --muted: #b3a697; --line: #3d362f;
    --accent: #c4554d; --table: #1d332e; --table-2: #142621; --ok: #7cc28e; --warn: #e0a54a;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: "Noto Sans TC", "Microsoft JhengHei", "PingFang TC", system-ui, sans-serif;
  line-height: 1.65;
}
.top { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.top h1 { font-size: 1.25rem; margin: 0; }
.top h1 small { font-size: .8rem; color: var(--muted); font-weight: normal; margin-left: 6px; }
.motion-toggle { font-size: .9rem; color: var(--muted); }

.steps { list-style: none; display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 16px; margin: 0; counter-reset: s; }
.steps li { counter-increment: s; font-size: .8rem; padding: 3px 10px; border-radius: 99px; border: 1px solid var(--line); color: var(--muted); }
.steps li::before { content: counter(s) " "; }
.steps li.done { color: var(--ok); border-color: var(--ok); }
.steps li.now { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

main { max-width: 1040px; margin: 0 auto; padding: 8px 16px 24px; }
.panel { background: var(--paper); border: 1px solid var(--line); border-radius: 12px; padding: 16px; }
.field { display: block; margin-bottom: 14px; font-weight: 600; }
.field textarea, .field input { display: block; width: 100%; margin-top: 6px; padding: 10px; font: inherit; font-weight: normal; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; }
.req { color: var(--accent); font-size: .8rem; }
.opt { color: var(--muted); font-size: .8rem; font-weight: normal; }
.switch { display: inline-flex; gap: 8px; align-items: center; margin-bottom: 12px; font-weight: 600; }
.form-error { color: var(--accent); min-height: 1.2em; margin: 0 0 8px; }

button { font: inherit; border-radius: 8px; padding: 10px 18px; cursor: pointer; border: 1px solid var(--accent); }
button.primary { background: var(--accent); color: var(--accent-ink); }
button.ghost { background: transparent; color: var(--accent); }
button:disabled { opacity: .5; cursor: not-allowed; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.instruction { margin: 0 0 10px; font-weight: 600; }
.instruction small { display: block; font-weight: normal; color: var(--muted); }

/* ---------- 牌桌 ---------- */
.stage {
  position: relative; height: 340px; border-radius: 12px; overflow: hidden;
  background: radial-gradient(ellipse at center, var(--table), var(--table-2));
  touch-action: manipulation;
}
.cb {
  position: absolute; left: 0; top: 0; width: var(--cw); height: var(--ch);
  border-radius: 5px; border: 2px solid #e9dcc0;
  background:
    radial-gradient(circle at 50% 50%, var(--gold) 0 14%, transparent 15%),
    repeating-linear-gradient(45deg, var(--back-1) 0 6px, var(--back-2) 6px 12px);
  box-shadow: 0 1px 3px rgba(0,0,0,.45);
  transition: transform calc(.55s * var(--dur)) ease, box-shadow .2s;
  will-change: transform;
}
.cb.pickable { cursor: pointer; }
.cb.pickable:hover { box-shadow: 0 0 0 2px #fff, 0 4px 10px rgba(0,0,0,.5); }
.cb.picked { box-shadow: 0 0 0 3px #ffd770, 0 6px 14px rgba(0,0,0,.6); cursor: default; }
.cb .badge { position: absolute; top: -10px; left: 50%; translate: -50% 0; background: #ffd770; color: #3a2a00; font-weight: 700; font-size: .75rem; border-radius: 99px; padding: 0 6px; white-space: nowrap; }
.pile-label { position: absolute; color: #f3ead8; font-size: .8rem; text-align: center; transform: translateX(-50%); white-space: nowrap; }
.ask-box textarea { min-height: 70px; }
.picks { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 8px; }
.picks span { border: 1px solid var(--line); border-radius: 99px; padding: 2px 10px; font-size: .85rem; }

/* ---------- 翻牌牌位 ---------- */
.slots { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
@media (max-width: 640px) { .slots { grid-template-columns: 1fr; max-width: 260px; margin: 0 auto; } }
.slot { position: relative; text-align: center; }
.slot .pos { font-weight: 700; }
.slot .pos small { display: block; font-weight: normal; color: var(--muted); font-size: .8rem; line-height: 1.4; min-height: 2.8em; }
.slot .name { margin-top: 8px; font-weight: 700; min-height: 1.6em; }
.slot .orient { display: inline-block; font-size: .85rem; padding: 0 8px; border-radius: 99px; border: 1px solid var(--line); }
.slot .orient.rev { border-color: var(--warn); color: var(--warn); }

/* 外層：側翻（繞垂直軸 rotateY）。內層 .art：牌圖方向（正／逆）。兩者分開。 */
.flip-wrap { position: relative; perspective: 1200px; margin-top: 6px; }
.flip {
  position: relative; width: 100%; aspect-ratio: 2 / 3;
  transform-style: preserve-3d; transform: rotateY(0deg);
  transition: transform calc(1.1s * var(--dur)) ease-in-out;
  cursor: pointer;
}
.flip.is-open { transform: rotateY(180deg); cursor: default; }
.face { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; border-radius: 10px; overflow: hidden; }
.face.back {
  border: 3px solid #e9dcc0;
  background:
    radial-gradient(circle at 50% 50%, var(--gold) 0 10%, transparent 11%),
    repeating-linear-gradient(45deg, var(--back-1) 0 10px, var(--back-2) 10px 20px);
}
.face.front { transform: rotateY(180deg); background: #f3ead8; border: 1px solid var(--line); }
.art { position: absolute; inset: 0; transition: none; }
.art.reversed { transform: rotate(180deg); }
.art img { width: 100%; height: 100%; object-fit: contain; display: block; }
/* 占位卡：上有太陽、下有地平線，可看出牌的上下方向 */
.ph { position: absolute; inset: 6%; border: 2px solid var(--gold); border-radius: 8px; background: linear-gradient(#efe2c4, #e2d1ad); }
.ph::before { content: ""; position: absolute; left: 50%; top: 8%; width: 22%; aspect-ratio: 1; translate: -50% 0; border-radius: 50%; background: var(--gold); }
.ph::after { content: ""; position: absolute; left: 10%; right: 10%; bottom: 10%; height: 14%; border-top: 3px solid #8b6f3d; background: repeating-linear-gradient(90deg, #cdb88b 0 6px, transparent 6px 12px); }
.ph-label { position: absolute; inset: 34% 10% auto; text-align: center; color: #3b2f22; pointer-events: none; }
.ph-label b { display: block; font-size: 1.15rem; }
.ph-label span { display: block; font-size: .78rem; }
.ph-label em { display: block; font-style: normal; font-size: .72rem; color: #7a6650; margin-top: 4px; }

/* 左手示範 */
.hand { position: absolute; width: 46%; left: -14%; bottom: 4%; pointer-events: none; opacity: 0; z-index: 3; transform-origin: 50% 90%; }
.hand.go { animation: hand-flip calc(1.6s * var(--dur)) ease-in-out forwards; }
@keyframes hand-flip {
  0%   { opacity: 0; transform: translate(-30%, 10%) rotate(35deg); }
  20%  { opacity: 1; transform: translate(0, 0) rotate(35deg); }
  70%  { opacity: 1; transform: translate(120%, -6%) rotate(20deg); }
  100% { opacity: 0; transform: translate(170%, 0) rotate(20deg); }
}
.hand-note { font-size: .85rem; color: var(--muted); }

.status { margin-top: 12px; }
.status .err { color: var(--accent); font-weight: 600; }
.status .info { color: var(--muted); }

/* ---------- 解讀 ---------- */
.reading { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 12px; }
.reading h2 { font-size: 1.1rem; margin: 18px 0 6px; }
.reading h3 { font-size: 1rem; margin: 12px 0 4px; }
.reading .meta { color: var(--muted); font-size: .8rem; }
.reading ul { padding-left: 1.3em; }
.reading .tag { display: inline-block; font-size: .78rem; border: 1px solid var(--line); border-radius: 99px; padding: 0 8px; margin: 2px 4px 2px 0; }

.foot { max-width: 1040px; margin: 0 auto 24px; padding: 0 16px; color: var(--muted); font-size: .8rem; }

/* 減少動態效果 */
.reduce-motion { --dur: 0.001; }
.reduce-motion .hand { display: none; }
@media (prefers-reduced-motion: reduce) { .cb, .flip { transition: none; } }

/* 回答「尚需確認」 */
.followup { margin-top: 20px; padding-top: 8px; border-top: 1px dashed var(--line); }
.followup textarea { display: block; width: 100%; margin: 8px 0 10px; padding: 10px; font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; }

/* 自動進行提示、完成提示、認識這張牌、解讀原則 */
button.small { padding: 4px 10px; font-size: .85rem; }
.auto-note { margin: 10px 0 0; padding: 8px 12px; border-radius: 8px; background: var(--bg); border: 1px solid var(--line); display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.done-notice { margin: 0 0 12px; padding: 10px 14px; border-radius: 8px; background: var(--paper); border: 2px solid var(--ok); color: var(--ok); font-weight: 700; scroll-margin-top: 12px; }
.orient-wrap { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; align-items: center; }
.card-info { width: min(640px, calc(100vw - 32px)); max-height: calc(100vh - 48px); overflow: auto; border: 1px solid var(--line); border-radius: 12px; background: var(--paper); color: var(--ink); padding: 18px; }
.card-info::backdrop { background: rgba(0,0,0,.45); }
.card-info h2 { margin: 0 0 4px; font-size: 1.15rem; }
.card-info h3 { font-size: 1rem; margin: 14px 0 4px; }
.card-info .meta { color: var(--muted); font-size: .82rem; }
.card-info ul { padding-left: 1.2em; }
.info-img { display: block; width: 160px; aspect-ratio: 2 / 3; object-fit: contain; margin: 8px 0; }
.principles { margin-top: 18px; border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; }
.principles summary { cursor: pointer; font-weight: 700; }
.principles li { margin: 6px 0; }
.about-link { font-size: .8rem; font-weight: normal; margin-left: 8px; color: var(--accent); }
.foot a { color: var(--accent); }
.meta { color: var(--muted); font-size: .82rem; }

/* 問題範圍提醒 */
.scope-box { margin: 0 0 12px; padding: 12px 14px; border-radius: 8px; border: 1px solid var(--warn); background: var(--bg); }
.scope-box .scope-msg { margin: 0 0 6px; font-weight: 600; }
.scope-box .suggestion { display: block; width: 100%; text-align: left; margin-top: 6px; }

.access-title { font-size: 1.1rem; margin: 0 0 6px; }

/* 選擇 AI、進度 */
.provider-picks { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; margin-top: 14px; }
.provider-pick { font-weight: 700; display: inline-flex; gap: 4px; align-items: center; }
.progress { list-style: none; padding: 0; margin: 8px 0; display: flex; flex-wrap: wrap; gap: 8px; }
.progress li { border: 1px solid var(--line); border-radius: 99px; padding: 2px 10px; font-size: .9rem; }
.progress .prog-ok { border-color: var(--ok); color: var(--ok); }
.progress .prog-fail { border-color: var(--accent); color: var(--accent); }

/* 分頁按鈕 */
.tabs { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.tab { padding: 6px 14px; border-radius: 99px; background: transparent; color: var(--accent); }
.tab.on { background: var(--accent); color: var(--accent-ink); }
.provider-tabs .tab { border-color: var(--line); color: var(--ink); }
.provider-tabs .tab.on { background: var(--ink); color: var(--paper); border-color: var(--ink); }

/* 小抄：字大、短句、一眼看完 */
.cheat { display: grid; gap: 10px; }
.cheat-block { border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; background: var(--bg); }
.cheat-label { display: block; font-size: .8rem; color: var(--muted); font-weight: 700; letter-spacing: .05em; }
.cheat-block p { margin: 4px 0 0; font-size: 1.15rem; font-weight: 700; line-height: 1.5; }
.cheat-open { border-color: var(--gold); }
.cheat-big { border: 2px solid var(--accent); }
.cheat-key { color: var(--accent); }
.cheat ul { margin: 6px 0 0; padding-left: 1.2em; font-size: 1.05rem; }
.cheat ul li { margin: 3px 0; }
.cheat-two { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.cheat-avoid { border-color: var(--warn); }
.cheat-avoid .cheat-label { color: var(--warn); }
@media (max-width: 760px) { .cheat-two { grid-template-columns: 1fr; } }

/* 多家比較 */
.compare { display: grid; gap: 6px; }
.compare-row { display: grid; grid-template-columns: 9em repeat(var(--cols), 1fr); gap: 6px; }
.compare-label { font-weight: 700; font-size: .9rem; color: var(--muted); padding: 8px 0; }
.compare-cell { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: var(--bg); font-size: 1rem; }
.compare-head .compare-cell { background: transparent; border: 0; font-weight: 700; text-align: center; }
.compare-who { display: none; }
@media (max-width: 760px) {
  .compare-row { grid-template-columns: 1fr; }
  .compare-head { display: none; }
  .compare-label { padding: 10px 0 0; }
  .compare-who { display: block; font-size: .75rem; color: var(--muted); font-weight: 700; }
}
