/* 求籤儀式（draw.js、ritual.js）：移植自籤詩天堂，改成占卜島的灰白雜誌風 */

/* 停頓 */
.rite { text-align: center; padding: 6px 0 10px; }
.rite-ask { font-family: var(--serif); font-weight: 600; font-size: 18px; line-height: 1.75; letter-spacing: .06em; margin: 8px 6px 4px; transition: opacity .6s; }
.rite-ask b { display: block; font-family: var(--sans); font-weight: 500; font-size: 11px; letter-spacing: .4em; color: var(--red); margin-bottom: 4px; }
.rite-ask.dim { opacity: .45; }
.rite-st { min-height: 1.8em; font-family: var(--serif); font-weight: 700; font-size: 19px; letter-spacing: .14em; margin: 4px 0 14px; }
.rite-skip { background: none; border: 0; color: var(--ink-2); font: inherit; font-size: 12px; letter-spacing: .2em; text-decoration: underline; text-underline-offset: 4px; padding: 12px; cursor: pointer; }
.rite-skip:disabled { opacity: .4; }
.rite .go { margin-top: 4px; }

/* 星塵層、變暗、短語（ritual.js） */
.ritual-canvas { position: fixed; inset: 0; pointer-events: none; z-index: 40; }
body::after { content: ""; position: fixed; inset: 0; background: #14110e; opacity: 0; pointer-events: none; transition: opacity .35s ease; z-index: 30; }
body.ritual-dim::after { opacity: .38; }
.ritual-ack { position: fixed; left: 50%; top: 42%; transform: translate(-50%, -50%) translateY(6px); z-index: 50; pointer-events: none; white-space: nowrap;
  font-family: var(--serif); font-weight: 700; font-size: clamp(22px, 6vw, 30px); letter-spacing: .35em; padding-left: .35em; color: #fffaf0;
  text-shadow: 0 0 18px rgba(255,230,170,.7), 0 1px 10px rgba(0,0,0,.4); opacity: 0; transition: opacity .6s ease, transform .6s ease; }
.ritual-ack.in { opacity: 1; transform: translate(-50%, -50%); }
.ritual-ack.out { opacity: 0; transform: translate(-50%, -50%) translateY(-6px); }

/* 籤筒 */
.rite-stage { position: relative; }
.prop-stage { position: relative; width: min(64vw, 260px); margin: 6px auto 0; height: min(78vw, 320px); }
.prop-img { width: 100%; height: 100%; object-fit: contain; object-position: bottom; transform-origin: 50% 85%;
}
.prop-stage.shaking .prop-img { animation: prop-shake2 .72s ease-in-out infinite; }
@keyframes prop-shake2 { 0%,100% { transform: rotate(0); } 20% { transform: rotate(-5deg) translateX(-6px); } 50% { transform: rotate(4deg) translateX(5px) translateY(-3px); } 80% { transform: rotate(-3deg) translateX(-3px); } }
.stick-drop { position: absolute; left: 50%; top: 4%; width: 20px; height: 136px; margin-left: -10px; border-radius: 3px 3px 10px 10px; overflow: hidden; z-index: 2;
  background: linear-gradient(90deg, #a87a33 0%, #e7c983 22%, #fff3cf 48%, #f0d797 62%, #b98a3e 100%);
  box-shadow: inset 0 0 0 1px rgba(92,60,18,.55), 0 8px 16px rgba(20,17,14,.35);
  color: #9a1f12; font-family: var(--serif); font-size: 10px; font-weight: 900; letter-spacing: .05em;
  writing-mode: vertical-rl; display: flex; align-items: center; justify-content: flex-start; padding-top: 26px; box-sizing: border-box; }
.stick-drop::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 20px; background: linear-gradient(90deg, #6e0f0a, #c9301e 48%, #e04a2c 55%, #6e0f0a); border-bottom: 2px solid #e8c56a; }
.stick-drop::after { content: ""; position: absolute; left: 0; right: 0; bottom: 22px; height: 3px; background: linear-gradient(90deg, rgba(92,60,18,.65), rgba(92,60,18,.25) 50%, rgba(92,60,18,.65)); }
.stick-drop .sk-no { position: relative; z-index: 1; }
.stick-drop.fall { animation: stick-fall 1s cubic-bezier(.3,.7,.3,1) both; }
@keyframes stick-fall { 0% { transform: translateY(-40px) rotate(-6deg); opacity: 0; } 35% { opacity: 1; } 100% { transform: translateY(200px) rotate(78deg); opacity: 1; } }
@media (max-width: 480px) { .stick-drop.fall { animation-name: stick-fall-m; } }
@keyframes stick-fall-m { 0% { transform: translateY(-40px) rotate(-6deg); opacity: 0; } 35% { opacity: 1; } 100% { transform: translateY(165px) rotate(78deg); opacity: 1; } }

/* 古人籤：書 */
.book-stage { position: relative; width: min(70vw, 280px); height: 240px; margin: 10px auto 0; }
.book-stage .bk { position: absolute; left: 50%; bottom: 0; transform: translateX(-50%); max-height: 200px; width: auto; transition: opacity .8s ease; }
.book-stage .open { opacity: 0; max-height: 170px; }
.book-stage.opened .shut { opacity: 0; } .book-stage.opened .open { opacity: 1; }
.book-stage.shaking .shut { animation: book-wob .5s ease-in-out infinite; transform-origin: 50% 100%; }
@keyframes book-wob { 0%,100% { transform: translateX(-50%) rotate(0); } 30% { transform: translateX(-50%) rotate(-3deg); } 70% { transform: translateX(-50%) rotate(3deg); } }
.leaf-strip { position: absolute; left: 50%; bottom: 70px; width: 34px; height: 150px; margin-left: -17px; opacity: 0; transform: translateY(30px) scale(.9);
  background: #fbf8ef; border: 1px solid #c9b48a; box-shadow: 0 6px 18px rgba(143,109,51,.25), 0 0 18px rgba(255,240,200,.8);
  writing-mode: vertical-rl; display: flex; align-items: center; justify-content: center; font-family: var(--serif); font-weight: 700; font-size: 13px; letter-spacing: .2em; color: var(--ink);
  transition: opacity .9s ease, transform 1.2s cubic-bezier(.2,.8,.2,1); }
.book-stage.rise .leaf-strip { opacity: 1; transform: translateY(-40px) scale(1); }

/* 易經：銅錢與六爻 */
.coin-stage { display: flex; justify-content: center; gap: 18px; margin: 18px 0 10px; perspective: 600px; }
.rc { position: relative; width: 64px; height: 64px; transform-style: preserve-3d; }
.rc .f { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; backface-visibility: hidden; -webkit-backface-visibility: hidden; filter: drop-shadow(0 4px 6px rgba(20,17,14,.25)); }
.rc .b { transform: rotateX(180deg); }
.hexbuild { display: flex; flex-direction: column-reverse; gap: 9px; width: 150px; margin: 14px auto 6px; }
.hl { display: flex; justify-content: space-between; height: 12px; opacity: .12; transition: opacity .5s; }
.hl i { display: block; height: 100%; width: 100%; background: var(--ink); }
.hl.on { opacity: 1; }
.hl.yin i { width: 44%; }
.hl.yang i:last-child { display: none; }
.hl.mv i { background: var(--red); box-shadow: 0 0 10px rgba(168,50,42,.45); }

/* 塔羅：洗牌、攤牌、選牌、翻面 */
.fan { position: relative; height: 260px; margin: 10px auto 0; width: 100%; max-width: 480px; --org: clamp(210px, 58vw, 380px); touch-action: none; perspective: 900px; }
.fan::before { content: ""; position: absolute; left: 50%; top: 40px; width: 70%; height: 150px; transform: translateX(-50%); background: radial-gradient(ellipse at center, rgba(122,91,176,.18), transparent 70%); filter: blur(18px); pointer-events: none; }
.tk { position: absolute; left: 50%; top: 24px; width: 56px; height: 88px; margin-left: -28px; padding: 0; border-radius: 4px; cursor: pointer;
  border: 1px solid rgba(184,134,46,.7); background: #1a1430 url(img/rite/tarot-back.webp) center / cover no-repeat; box-shadow: 0 4px 10px rgba(20,17,14,.28);
  transform-origin: 50% var(--org); transform: translate(0, 0) rotate(0deg); transition: transform 1.1s cubic-bezier(.2,.8,.2,1), box-shadow .4s, opacity .6s; -webkit-tap-highlight-color: transparent; will-change: transform; }
/* 還沒開始洗牌：78 張牌背在桌上攤成一長排，微微帶弧度 */
.fan.rest { cursor: default; }
.fan.rest .tk { pointer-events: none; transform: translate(calc((var(--i) - 38.5) * min(.95vw, 4.6px)), calc(58px + (var(--i) - 38.5) * (var(--i) - 38.5) * .012px)) rotate(calc((var(--i) - 38.5) * .32deg)); }
.fan.mix { cursor: grab; } .fan.mix .tk { transition: none; z-index: auto; transform-origin: 50% 50%; }
.fan.fanned .tk { transform: rotate(var(--a)); transition-delay: calc(var(--i) * 9ms); }
.fan.fanned .tk.hov { transform: rotate(var(--a)) translateY(-22px) scale(1.06); transition: transform .18s ease-out; z-index: 300 !important; box-shadow: 0 0 18px rgba(122,91,176,.55), 0 0 0 1px rgba(184,134,46,.95); }
.fan.fanned .tk.picked { transform: rotate(var(--a)) translateY(-34px); transition: transform .35s; z-index: 301 !important; box-shadow: 0 0 22px rgba(184,134,46,.6), 0 0 0 1px rgba(184,134,46,.95); }
.fan.done .tk:not(.picked) { opacity: .25; pointer-events: none; }
.fan .guide { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 400; overflow: visible; }
.fan .g-arc { fill: none; stroke: rgba(143,109,51,.75); stroke-width: 1.5; stroke-dasharray: 4 7; stroke-linecap: round; }
.fan .g-dot { fill: #b8862e; filter: drop-shadow(0 0 6px rgba(184,134,46,.9)); }
.fan .g-txt { fill: var(--red); font-family: var(--serif); font-size: 13px; letter-spacing: .1em; }
.fan.tracing .g-dot { display: none; } .fan.tracing .g-arc { stroke: rgba(122,91,176,.8); }
.mixbtns { display: flex; justify-content: center; margin: 6px 0 4px; } .mixbtns .ghost { width: auto; padding: 10px 22px; }
.slots { display: flex; justify-content: center; margin: 10px 0 4px; }
.slot { width: 110px; text-align: center; }
.slot .face { width: 110px; height: 165px; border: 1px dashed var(--line); position: relative; transform-style: preserve-3d; transition: transform .85s cubic-bezier(.3,.7,.3,1); }
.slot.filled .face { border: none; }
.slot.flip .face { transform: rotateY(180deg); }
.slot .face .b, .slot .face .f { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; overflow: hidden; border-radius: 4px; }
.slot.filled .face .b { background: #1a1430 url(img/rite/tarot-back.webp) center / cover no-repeat; box-shadow: 0 6px 14px rgba(20,17,14,.3); }
.slot .face .f { transform: rotateY(180deg); background: #fff; box-shadow: 0 8px 22px rgba(20,17,14,.3); }
.slot .face .f img { width: 100%; height: 100%; object-fit: cover; }
.slot .face .f img.rev { transform: rotate(180deg); }
.slot small { display: block; margin-top: 8px; font-size: 11px; letter-spacing: .4em; color: var(--red); }

/* 擲筊：走進那個地方 */
.jb-hall { position: fixed; inset: 0; z-index: 70; background: #14110e; display: flex; justify-content: center; opacity: 0; transition: opacity .45s; }
.jb-hall.in { opacity: 1; }
.jb-room { position: relative; height: 100%; aspect-ratio: 2 / 3; max-width: 100vw; background: center / cover no-repeat; display: flex; align-items: flex-end; justify-content: center; }
.jb-room::before { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(241,241,243,0) 30%, rgba(241,241,243,.82) 62%, rgba(241,241,243,.96) 100%); pointer-events: none; }
.jb-wrap { position: relative; display: grid; justify-items: center; gap: 12px; width: 100%; padding: 0 20px max(24px, env(safe-area-inset-bottom)); }
.jb-ask { margin: 0; font-family: var(--serif); font-weight: 700; font-size: 17px; line-height: 1.6; letter-spacing: .08em; text-align: center; }
.jb-stage { display: flex; gap: 22px; height: 175px; align-items: flex-end; padding-bottom: 6px; }
.jb { display: block; width: 120px; height: 110px; }
.jb b { display: block; width: 100%; height: 100%; background: url(img/rite/jb-convex.webp) center / contain no-repeat; filter: drop-shadow(0 8px 10px rgba(20,17,14,.35)); }
.jb + .jb b { transform: scaleX(-1); }
.jb.flat b { background-image: url(img/rite/jb-flat.webp); }
.jb-dots { display: flex; gap: 10px; }
.jb-dots span { width: 13px; height: 13px; border-radius: 50%; border: 1.5px solid var(--red); transition: background .3s, box-shadow .3s; }
.jb-dots span.on { background: var(--red); box-shadow: 0 0 10px rgba(168,50,42,.5); }
.jb-msg { margin: 0; min-height: 1.6em; font-family: var(--serif); font-weight: 600; font-size: 16px; letter-spacing: .06em; text-align: center; }
.jb-actions { display: grid; justify-items: center; width: min(100%, 340px); }
.jb-actions .go { width: 100%; }
.jb-note { margin: 0; font-size: 11px; letter-spacing: .1em; color: var(--ink-2); text-align: center; }
@media (max-height: 700px) { .jb-stage { height: 140px; } .jb { width: 100px; height: 92px; } }

/* 籤紙展開 */
.unfold { animation: unfold 1.1s cubic-bezier(.2,.8,.2,1) both; }
@keyframes unfold { 0% { clip-path: inset(0 0 100% 0); opacity: 0; transform: translateY(-6px); } 30% { opacity: 1; } 100% { clip-path: inset(0 0 0 0); opacity: 1; transform: none; } }

@media (prefers-reduced-motion: reduce) {
  .prop-stage.shaking .prop-img, .book-stage.shaking .shut, .stick-drop.fall, .unfold { animation: none; }
  .tk, .slot .face, .leaf-strip { transition: none; }
}
.rite [hidden], .stick-drop[hidden] { display: none !important; }
.rite { display: flex; flex-direction: column; align-items: center; }
.rite > * { width: 100%; }
.rite .go, .rite .rite-skip { width: auto; min-width: 60%; align-self: center; }
.rite-tarot .rite-ask { order: 0; } .rite-tarot .rite-st { order: 1; margin-bottom: 4px; } .rite-tarot .rite-stage { order: 2; } .rite-tarot .go, .rite-tarot .rite-skip { order: 3; }
.rite-tarot .rite-stage { overflow-x: clip; }

/* 牌陣：要抽幾張就有幾個位置，張數多就縮小、換行 */
.slots { flex-wrap: wrap; gap: 10px 8px; }
.slots:not(.n1) .slot { width: 84px; }
.slots:not(.n1) .slot .face { width: 84px; height: 126px; }
.slots:not(.n1) .slot small { letter-spacing: .12em; font-size: 10.5px; margin-top: 6px; white-space: nowrap; }
.slots.n5 .slot, .slots.n6 .slot { width: 64px; } .slots.n5 .slot .face, .slots.n6 .slot .face { width: 64px; height: 96px; }
.slots.n7 .slot, .slots.n10 .slot, .slots.n12 .slot { width: 52px; } .slots.n7 .slot .face, .slots.n10 .slot .face, .slots.n12 .slot .face { width: 52px; height: 78px; }
.slots.n7 .slot small, .slots.n10 .slot small, .slots.n12 .slot small { font-size: 9.5px; letter-spacing: 0; }
