/* 小廟的儀式面板（temple-view.js）：點光明燈、抽籤。長在商品跳窗（#product-modal）裡，
   顏色是廟的紅、金、米白；手機優先，按鈕都 44px 以上。動畫只用 transform／opacity，
   prefers-reduced-motion 時全部停掉（流程照走，只是不動）。 */

#product-modal:has(.tp) { background: #fbf4e6; backdrop-filter: none; }
.tp {
  --tp-red: #b23a2e;
  --tp-red-dk: #86281f;
  --tp-gold: #c99a3e;
  --tp-gold-lt: #f3dfa6;
  --tp-paper: #fffaf0;
  --tp-ink: #3a241c;
  --tp-soft: #7a5a4a;
  color: var(--tp-ink);
  font-family: var(--font);
  display: grid;
  gap: 16px;
  max-width: 640px;
  margin: 0 auto;
  padding: 2px 2px 8px;
}
.tp button { font: inherit; cursor: pointer; }
.tp button:disabled { cursor: not-allowed; }
.tp button:focus-visible, .tp input:focus-visible { outline: 3px solid var(--tp-gold-lt); outline-offset: 2px; }
.tp-head { display: grid; gap: 2px; }
.tp-kicker { margin: 0; font-size: 12px; font-weight: 700; letter-spacing: .12em; color: var(--tp-red); }
.tp-title { margin: 0; font-family: var(--serif, serif); font-size: 26px; line-height: 1.25; }
.tp-lead { margin: 0; font-size: 14px; line-height: 1.7; color: var(--tp-soft); }
.tp-center { text-align: center; }
.tp-note { margin: 0; font-size: 12px; line-height: 1.6; color: var(--tp-soft); }
.tp-link { padding: 0; border: 0; background: none; color: var(--tp-red); font-size: 12px; font-weight: 700; text-decoration: underline; text-underline-offset: 3px; }
.tp-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.tp-label { font-size: 13px; font-weight: 700; }
.tp-chips { display: flex; gap: 8px; flex-wrap: wrap; }
.tp-chip { min-height: 40px; padding: 0 14px; border: 1px solid #e3cfa8; border-radius: 999px; background: var(--tp-paper); color: var(--tp-ink); font-size: 13px; }
.tp-chip.on { background: var(--tp-red); border-color: var(--tp-red); color: #fff; font-weight: 700; }
.tp-field { display: grid; gap: 6px; font-size: 13px; font-weight: 700; }
.tp-field input { min-height: 44px; padding: 0 12px; border: 1px solid #e3cfa8; border-radius: 12px; background: var(--tp-paper); color: var(--tp-ink); font: inherit; font-weight: 400; }
.tp-foot { display: flex; align-items: center; justify-content: flex-end; gap: 10px; flex-wrap: wrap; padding-top: 4px; }
.tp-foot small { margin-right: auto; font-size: 12px; color: var(--tp-soft); }
.tp-cta { min-height: 46px; padding: 0 22px; border: 0; border-radius: 999px; background: var(--tp-red); color: #fff; font-size: 15px; font-weight: 700; box-shadow: 0 6px 16px rgba(134, 40, 31, .25); }
.tp-cta:disabled { background: #d9c3b5; box-shadow: none; }
.tp-ghost { min-height: 46px; padding: 0 18px; border: 1px solid #e3cfa8; border-radius: 999px; background: var(--tp-paper); color: var(--tp-ink); font-size: 14px; }

/* ---------------------------------------------------------------- 光明燈 */
.tp-wall {
  display: grid; grid-template-columns: repeat(var(--cols), 1fr); gap: 6px;
  padding: 12px; border-radius: 14px; background: var(--tp-red-dk);
  box-shadow: inset 0 0 0 3px var(--tp-gold);
  max-width: 280px; justify-self: center; width: 100%;
}
.tp-cell { aspect-ratio: 1.7; min-height: 30px; padding: 4px; border: 2px solid var(--tp-gold); border-radius: 6px; background: #5c1b15; }
.tp-cell span { display: block; width: 100%; height: 100%; border-radius: 3px; background: #8a6a3a; opacity: .55; }
.tp-cell.on span { background: radial-gradient(circle at 50% 60%, #fff6d0, #ffc45c 55%, #e08a2a); opacity: 1; box-shadow: 0 0 10px #ffc45c; }
.tp-cell.mine span { box-shadow: 0 0 0 2px #fff, 0 0 12px #ffd77a; }
.tp-cell.pick { border-color: #fff; transform: scale(1.06); }
.tp-cell.pick span { background: #d9b36a; opacity: .9; }
.tp-cell:disabled { cursor: default; }

.tp-lamp { position: relative; width: 150px; height: 170px; justify-self: center; display: grid; place-items: center; }
.tp-lamp-glow { position: absolute; inset: 0; border-radius: 50%; background: radial-gradient(circle, rgba(255, 200, 90, .65), rgba(255, 200, 90, 0) 70%); }
.tp-lamp-body {
  position: relative; width: 96px; height: 116px; border-radius: 48px 48px 40px 40px;
  background: linear-gradient(#e2543c, #a8301f); box-shadow: inset 0 -10px 0 rgba(0, 0, 0, .15), 0 0 0 4px var(--tp-gold);
  display: grid; place-items: center;
}
.tp-flame { width: 26px; height: 40px; border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%; background: radial-gradient(circle at 50% 70%, #fff, #ffd56a 45%, #ff8a2a 80%); }
.tp-spark { position: absolute; left: 50%; top: 55%; width: 6px; height: 6px; border-radius: 50%; background: #ffd56a; opacity: 0; }
.tp-lit { margin: 0; text-align: center; font-size: 17px; line-height: 1.6; }
.tp-lit strong { margin: 0 4px; color: var(--tp-red); }
.tp-wish { margin: -8px 0 0; text-align: center; font-size: 14px; font-weight: 700; color: var(--tp-gold); letter-spacing: .1em; }

/* ---------------------------------------------------------------- 抽籤 */
.tp-stage { display: grid; place-items: center; min-height: 190px; }
.tp-tube { width: 130px; height: 238px; overflow: visible; transform-origin: 50% 90%; }
.tp-tube-word { font: 700 30px var(--serif, serif); fill: #f3dfa6; text-anchor: middle; }
.tp-pop-no { font: 700 12px var(--font, sans-serif); fill: var(--tp-red-dk, #86281f); text-anchor: middle; writing-mode: vertical-rl; }
.tp-steps { margin: 0; padding-left: 20px; font-size: 14px; line-height: 1.9; color: var(--tp-soft); }

.tp-stage--jiao { display: flex; justify-content: center; align-items: flex-end; gap: 22px; min-height: 160px; }
.tp-jiao { width: 96px; height: 76px; overflow: visible; }
.tp-jiao-face { font: 700 12px var(--font, sans-serif); fill: var(--tp-soft, #7a5a4a); text-anchor: middle; }
.tp-jiao.spin .tp-jiao-face { opacity: 0; }

.tp-slip {
  position: relative; display: grid; gap: 12px; padding: 18px 18px 22px;
  background: #fff3c4; border: 1px solid #e6cf86; border-radius: 6px;
  box-shadow: 0 10px 24px rgba(58, 36, 28, .12); transform-origin: 50% 0;
}
.tp-slip::before { content: ''; position: absolute; inset: 8px; border: 2px solid var(--tp-red); border-radius: 3px; pointer-events: none; }
.tp-slip-top { display: flex; justify-content: space-between; align-items: center; font-weight: 700; font-size: 14px; color: var(--tp-red); }
.tp-grade { padding: 3px 12px; border-radius: 999px; color: #fff; font-size: 13px; letter-spacing: .1em; }
.tp-grade.up { background: var(--tp-red); }
.tp-grade.mid { background: var(--tp-gold); }
.tp-grade.down { background: #8b7a6e; }
.tp-verse {
  writing-mode: vertical-rl; display: block; justify-self: center; margin: 4px 0;
  font: 600 21px/1.5 var(--serif, serif); letter-spacing: .14em; color: var(--tp-ink);
}
.tp-verse span { display: block; margin-left: 16px; }     /* 每一句一直行，由右往左讀 */
.tp-verse span:last-child { margin-left: 0; }
.tp-explain { display: grid; gap: 10px; }
.tp-explain h3 { margin: 0; font-size: 16px; }
.tp-explain p { margin: 0; font-size: 14px; line-height: 1.8; }
.tp-explain p strong { display: inline-block; margin-right: 8px; padding: 1px 8px; border-radius: 6px; background: #f5e6c8; color: var(--tp-red-dk); font-size: 12px; }
.tp-asked { padding: 10px 12px; border-radius: 12px; background: #fff; border: 1px solid #ecd9b2; }
.tp-explain details { font-size: 14px; }
.tp-explain summary { cursor: pointer; font-weight: 700; color: var(--tp-red); padding: 6px 0; }
.tp-explain details p { margin-top: 8px; }

/* ---------------------------------------------------------------- 動畫 */
@media (prefers-reduced-motion: no-preference) {
  .tp-lamp-glow { animation: tp-glow 2.2s ease-in-out infinite; }
  .tp-lamp-body { animation: tp-light .9s ease-out both; }
  .tp-flame { animation: tp-ignite .9s ease-out both, tp-flicker .18s ease-in-out .9s infinite alternate; }
  .tp-spark { animation: tp-spark 1.8s ease-out calc(var(--i) * .22s) infinite; }
  .tp-cell.pick { transition: transform .15s; }

  .tp-tube.shaking { animation: tp-shake .12s ease-in-out infinite alternate; }
  .tp-tube.shaking .tp-sticks { animation: tp-rattle .09s linear infinite alternate; }
  .tp-tube.popped .tp-pop { animation: tp-pop .6s cubic-bezier(.2, 1.4, .4, 1) both; }

  .tp-jiao.spin { animation: tp-toss 1.15s cubic-bezier(.3, .7, .4, 1) both; animation-delay: calc(var(--i) * .08s); }
  .landed .tp-jiao { animation: tp-land .35s ease-out both; animation-delay: calc(var(--i) * .08s); }

  .tp-slip { animation: tp-unfold .7s cubic-bezier(.2, .9, .3, 1) both; }
  .tp-verse span { animation: tp-ink .6s ease-out both; }
  .tp-verse span:nth-child(2) { animation-delay: .25s; }
  .tp-verse span:nth-child(3) { animation-delay: .5s; }
  .tp-verse span:nth-child(4) { animation-delay: .75s; }
  .tp-explain { animation: tp-fade .6s ease-out 1s both; }
}
@keyframes tp-glow { 0%, 100% { opacity: .55; transform: scale(.94); } 50% { opacity: 1; transform: scale(1.06); } }
@keyframes tp-light { from { filter: brightness(.55) saturate(.6); } to { filter: none; } }
@keyframes tp-ignite { from { transform: scale(0) translateY(10px); opacity: 0; } 60% { transform: scale(1.25); opacity: 1; } to { transform: scale(1); } }
@keyframes tp-flicker { from { transform: scale(1, 1) rotate(-2deg); } to { transform: scale(.92, 1.08) rotate(2deg); } }
@keyframes tp-spark {
  0% { opacity: 0; transform: translate(-50%, 0) scale(.6); }
  20% { opacity: 1; }
  100% { opacity: 0; transform: translate(calc(-50% + (var(--i) - 3.5) * 14px), -110px) scale(.2); }
}
@keyframes tp-shake { from { transform: rotate(-11deg) translateY(2px); } to { transform: rotate(11deg) translateY(-3px); } }
@keyframes tp-rattle { from { transform: translateY(0); } to { transform: translateY(-5px); } }
@keyframes tp-pop { from { transform: translateY(60px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@keyframes tp-toss {
  0% { transform: translateY(0) rotateX(0) rotate(0); }
  45% { transform: translateY(-120px) rotateX(540deg) rotate(calc((var(--i) - .5) * 40deg)); }
  100% { transform: translateY(0) rotateX(1080deg) rotate(calc((var(--i) - .5) * 14deg)); }
}
@keyframes tp-land { 0% { transform: translateY(-14px) scale(1.05); } 60% { transform: translateY(2px) scale(.98); } 100% { transform: none; } }
@keyframes tp-unfold { from { transform: perspective(600px) rotateX(-80deg); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes tp-ink { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
@keyframes tp-fade { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
