:root {
  --zhu: #c4161c;        /* 朱紅：廟柱、籤紙印色 */
  --zhu-deep: #8e1014;
  --jin: #e9b949;        /* 金箔 */
  --liuli: #0f5c4d;      /* 琉璃瓦綠 */
  --qian: #f8d4cf;       /* 籤紙粉 */
  --mo: #2b1410;         /* 墨 */

  --kai: "LXGW WenKai TC", "DFKai-SB", "BiauKai", "Kaiti TC", serif;
  --hei: "Noto Sans TC", "Microsoft JhengHei", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #27325e;
  color: var(--mo);
  font: 400 16px/1.6 var(--hei);
}

[hidden] { display: none !important; }

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}

:focus-visible {
  outline: 3px solid var(--jin);
  outline-offset: 2px;
}

#stage {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* 廟名：像蓋在角落的朱印 */
.seal {
  position: fixed;
  top: max(16px, env(safe-area-inset-top));
  right: 16px;
  margin: 0;
  padding: 10px 7px;
  writing-mode: vertical-rl;
  font: 700 22px/1 var(--kai);
  letter-spacing: 0.12em;
  color: var(--qian);
  background: var(--zhu);
  border-radius: 3px;
  pointer-events: none;
}

/* ── 籤紙 ───────────────────────────── */
.slip {
  position: fixed;
  top: 50%;
  left: clamp(16px, 5vw, 72px);
  translate: 0 -50%;
  width: min(380px, calc(100vw - 32px));
  max-height: calc(100dvh - 140px);
  overflow-y: auto;
  padding: 7px;
  background: var(--qian);
  box-shadow: 0 18px 40px rgb(20 10 40 / 0.45);
  animation: slip-in 0.5s cubic-bezier(0.2, 0.8, 0.2, 1);
}

@keyframes slip-in {
  from { translate: 0 calc(-50% - 40px); opacity: 0; }
}

/* 籤紙的雙線印框 */
.slip-frame {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0 18px;
  padding: 22px 18px 22px 22px;
  border: 2px solid var(--zhu);
  outline: 1px solid var(--zhu);
  outline-offset: -6px;
}

.slip-title {
  grid-column: 2;
  grid-row: 1;
  margin: 0;
  writing-mode: vertical-rl;
  font: 700 34px/1.1 var(--kai);
  letter-spacing: 0.18em;
  color: var(--zhu);
}

.slip-body {
  grid-column: 1;
  grid-row: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.step {
  margin: 0;
  padding: 0;
  border: 0;
  min-width: 0;
}

.step legend {
  padding: 0;
  margin-bottom: 8px;
  font: 700 19px/1.3 var(--kai);
}

.num {
  display: inline-grid;
  place-items: center;
  width: 1.5em;
  height: 1.5em;
  margin-right: 8px;
  color: var(--qian);
  background: var(--zhu);
  border-radius: 50%;
  font-size: 0.85em;
}

/* 角色選單：四個一排 */
.kinds {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.kinds label {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 4px 2px 5px;
  border: 1.5px solid rgb(196 22 28 / 0.35);
  background: rgb(255 255 255 / 0.35);
  cursor: pointer;
}

.kinds input { position: absolute; opacity: 0; }

.kinds img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: contain;
}

.kinds span {
  font: 400 15px/1.3 var(--kai);
  color: var(--zhu-deep);
}

.kinds label:hover { background: rgb(255 255 255 / 0.7); }
.kinds label:has(:checked) { border-color: var(--zhu); background: #fff; box-shadow: inset 0 0 0 1.5px var(--zhu); }
.kinds label:has(:checked) span { font-weight: 700; }
.kinds label:has(:focus-visible) { outline: 3px solid var(--jin); outline-offset: 2px; }

.hint {
  margin: 0;
  font-size: 14px;
  line-height: 1.6;
  color: #6d3b34;
}

.field {
  width: 100%;
  padding: 9px 12px;
  font: 400 18px/1.4 var(--kai);
  color: var(--mo);
  background: rgb(255 255 255 / 0.6);
  border: 0;
  border-bottom: 2px solid var(--zhu);
  border-radius: 0;
}

.error {
  margin: 0;
  font-size: 14px;
  font-weight: 500;
  color: var(--zhu-deep);
}

.btn {
  padding: 12px 16px;
  font: 700 20px/1 var(--kai);
  letter-spacing: 0.2em;
  color: var(--jin);
  background: var(--zhu);
  border: 0;
  border-radius: 2px;
  box-shadow: inset 0 0 0 2px var(--zhu), inset 0 0 0 3px var(--jin);
  cursor: pointer;
}

.btn:hover { background: var(--zhu-deep); }
.btn:disabled { opacity: 0.6; cursor: progress; }

.slip-close {
  grid-column: 2;
  grid-row: 1;
  align-self: end;
  padding: 6px 2px;
  writing-mode: vertical-rl;
  font: 400 15px/1 var(--kai);
  letter-spacing: 0.2em;
  color: var(--zhu-deep);
  background: none;
  border: 1px solid currentColor;
  cursor: pointer;
}

/* ── 名冊 ───────────────────────────── */
.roster {
  position: fixed;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  translate: -50% 0;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: calc(100vw - 24px);
  padding: 8px 10px;
  background: rgb(43 20 16 / 0.72);
  border-radius: 40px;
}

.roster-list {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 3px;
}

.roster-pet {
  position: relative;
  flex: none;
  width: 52px;
  height: 52px;
  padding: 0;
  border: 3px solid transparent;
  border-radius: 50%;
  background: var(--qian);
  cursor: pointer;
}

.roster-pet img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}

.roster-pet[aria-current="true"] { border-color: var(--jin); }

.roster-add {
  flex: none;
  width: 52px;
  height: 52px;
  font: 400 26px/1 var(--hei);
  color: var(--jin);
  background: var(--zhu);
  border: 0;
  border-radius: 50%;
  cursor: pointer;
}

.plate {
  position: fixed;
  left: 50%;
  top: max(18px, env(safe-area-inset-top));
  translate: -50% 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  color: #fff;
  text-shadow: 0 1px 6px rgb(20 10 40 / 0.9);
  pointer-events: none;
}

.plate strong { font: 700 28px/1.2 var(--kai); letter-spacing: 0.1em; }
.plate span { font-size: 13px; opacity: 0.9; }
.plate em { font: 700 15px/1.6 var(--kai); font-style: normal; letter-spacing: 0.08em; color: #ffe08a; }
.plate em[hidden] { display: none; }

/* ── 求籤 ───────────────────────────── */
.lot-view {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  min-height: 150px;
  justify-content: center;
  text-align: center;
}

.lot-view p { margin: 0; }

.lot-lead {
  font: 700 26px/1.3 var(--kai);
  letter-spacing: 0.08em;
  color: var(--zhu);
}

.lot-name {
  font: 400 18px/1.3 var(--kai);
  letter-spacing: 0.3em;
  color: var(--zhu-deep);
}

/* 籤詩直書，由右往左讀 */
.lot-poem {
  writing-mode: vertical-rl;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 12px 16px;
  font: 700 22px/1.2 var(--kai);
  letter-spacing: 0.22em;
  border-block: 1px solid var(--zhu);
}

.lot-note {
  font-size: 14px;
  line-height: 1.7;
  text-align: left;
  color: var(--mo);
}

/* 筊：新月形的兩片，平面朝上是淺色木紋，凸面朝上是紅漆 */
.jiao-pair { display: flex; gap: 22px; }

.jiao {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  overflow: hidden;
}

.jiao::after {
  content: "";
  position: absolute;
  inset: 0;
  left: 24px;
  width: 64px;
  border-radius: 50%;
  background: var(--qian);
}

.jiao.flat { background: #e3b98c; box-shadow: inset 0 0 0 3px #b5231f; }
.jiao.round { background: radial-gradient(circle at 30% 35%, #e0564c, #8e1014 70%); }
.jiao-pair .jiao:last-child { transform: scaleX(-1); }

/* ── 擲筊 ───────────────────────────── */
.cast-q { margin: 0; font: 400 17px/1.5 var(--kai); color: #6d3b34; overflow-wrap: anywhere; }

/* 連續聖筊：三格，滿了才算神明應允 */
.streak { display: flex; gap: 10px; }
.streak i { width: 14px; height: 14px; border-radius: 50%; border: 1.5px solid var(--zhu); }
.streak i.on { background: var(--zhu); box-shadow: 0 0 0 3px rgb(233 185 73 / 0.55); }

/* ── 安太歲 ───────────────────────────── */
.chips.zodiac { grid-template-columns: repeat(4, 1fr); gap: 6px; }
.chips.zodiac label { padding: 5px 2px; }
.chips.zodiac small { font-size: 11px; line-height: 1.25; }

/* 流年：犯太歲是朱紅印，不犯是琉璃綠 */
.fate { margin: 0; padding: 4px 16px; font: 700 24px/1.4 var(--kai); letter-spacing: 0.12em; color: var(--zhu); border: 2.5px solid currentColor; }
.fate.safe { color: #0f5c4d; }

/* 太歲符：黃紙朱字，直書 */
.talisman {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px 16px;
  writing-mode: vertical-rl;
  background: #f3d36b;
  border: 2px solid var(--zhu);
  outline: 1px solid var(--zhu);
  outline-offset: -6px;
  color: var(--zhu-deep);
  font-family: var(--kai);
}
.talisman b { font-size: 21px; letter-spacing: 0.14em; }
.talisman span { font-size: 15px; letter-spacing: 0.1em; align-self: flex-end; }
.talisman.done { background: #e6dccb; border-color: #8a7a70; outline-color: #8a7a70; color: #6d5d55; }

/* 祈福卡：紅紙金邊，左邊一個大字 */
.wish-card {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 2px 12px;
  align-items: center;
  width: 100%;
  padding: 10px 12px;
  text-align: left;
  color: #ffe9a8;
  background: var(--zhu);
  border: 2px solid var(--jin);
  outline: 1px solid var(--zhu);
}
.wish-card b { grid-row: span 2; font: 700 38px/1 var(--kai); }
.wish-card p { font: 400 17px/1.45 var(--kai); overflow-wrap: anywhere; }
.wish-card small { grid-column: 2; font-size: 12px; opacity: 0.85; }
.wish-card .link { grid-column: 3; grid-row: 1 / span 2; color: #ffe9a8; }
.wish-text { resize: none; }

/* 平安符：一個小香火袋，顏色由種類決定 */
.pouch {
  display: grid;
  place-items: center;
  width: 62px;
  height: 82px;
  font: 700 38px/1 var(--kai);
  font-style: normal;
  border: 2px solid var(--jin);
  border-radius: 4px 4px 12px 12px;
  box-shadow: inset 0 0 0 3px rgb(255 255 255 / 0.18), 0 3px 8px rgb(0 0 0 / 0.25);
}

/* 聲音開關：右下角的兩塊小木牌（音樂、音效） */
.audio-bar {
  position: fixed;
  right: 16px;
  bottom: max(16px, env(safe-area-inset-bottom));
  display: flex;
  gap: 8px;
}
.sound {
  padding: 7px 12px;
  font: 700 15px/1.2 var(--kai);
  letter-spacing: 0.08em;
  color: var(--qian);
  background: rgb(26 15 13 / 0.78);
  border: 1.5px solid var(--jin);
  border-radius: 3px;
  cursor: pointer;
}
.sound[aria-pressed="false"] { color: #b9a999; border-color: #7a6a5c; }
.sound:hover { background: rgb(26 15 13 / 0.92); }
.sound:focus-visible { outline: 3px solid var(--jin); outline-offset: 2px; }

/* ── 點燈 ───────────────────────────── */
.chips {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  width: 100%;
}

.chips label {
  position: relative;
  display: flex;
  flex-direction: column;
  padding: 8px 4px;
  border: 1.5px solid rgb(196 22 28 / 0.35);
  background: rgb(255 255 255 / 0.35);
  cursor: pointer;
}

.chips input { position: absolute; opacity: 0; }
.chips span { font: 700 19px/1.3 var(--kai); color: var(--zhu-deep); }
.chips small { font-size: 13px; color: #6d3b34; }
.chips label:hover { background: rgb(255 255 255 / 0.7); }
.chips label:has(:checked) { border-color: var(--zhu); background: #fff; box-shadow: inset 0 0 0 1.5px var(--zhu); }
.chips label:has(:focus-visible) { outline: 3px solid var(--jin); outline-offset: 2px; }

/* 點上的燈：一朵火 */
.lamp-flame {
  width: 34px;
  height: 48px;
  border-radius: 50% 50% 50% 50% / 62% 62% 38% 38%;
  background: radial-gradient(circle at 50% 70%, #fff6c9 0 22%, #ffc04a 48%, #e9621c 100%);
  box-shadow: 0 0 26px 8px rgb(255 176 64 / 0.55);
}

.link {
  align-self: center;
  padding: 2px 4px;
  font: 400 15px/1.4 var(--kai);
  color: var(--zhu-deep);
  background: none;
  border: 0;
  border-bottom: 1px solid currentColor;
  cursor: pointer;
}

/* ── 互動按鈕與提示：名冊上方 ───────── */
.act {
  position: fixed;
  left: 50%;
  bottom: calc(max(16px, env(safe-area-inset-bottom)) + 84px);
  translate: -50% 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  pointer-events: none;
}

.act > * { pointer-events: auto; }

.act-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  box-shadow: inset 0 0 0 2px var(--zhu), inset 0 0 0 3px var(--jin), 0 8px 20px rgb(20 10 40 / 0.45);
}

.act-btn kbd {
  padding: 3px 8px;
  font: 700 14px/1 var(--hei);
  letter-spacing: 0;
  color: var(--zhu-deep);
  background: var(--jin);
  border-radius: 3px;
}

@media (hover: none) {
  .act-btn kbd { display: none; }
}

.toast, .act-note {
  margin: 0;
  padding: 7px 16px;
  font: 400 16px/1.4 var(--kai);
  color: #fff;
  background: rgb(43 20 16 / 0.78);
  border-radius: 20px;
}

.toast { border: 1px solid var(--jin); }

/* ── 手機：籤紙改成由下方升起 ───────── */
@media (max-width: 640px) {
  .slip {
    top: auto;
    left: 12px;
    right: 12px;
    bottom: 96px;
    translate: none;
    width: auto;
    max-height: calc(100dvh - 180px);
  }

  @keyframes slip-in {
    from { translate: 0 40px; opacity: 0; }
  }

  .slip-frame { gap: 0 12px; padding: 18px 12px 18px 16px; }
  .slip-title { font-size: 26px; }
  .seal { font-size: 18px; }
}

@media (prefers-reduced-motion: reduce) {
  .slip { animation: none; }
}

/* ── 開場介紹與入口 ───────────────────── */
/* 還沒進廟之前（介紹動畫、入口、選訪客角色）：名冊、名牌、互動按鈕先收起來 */
body.gate .roster,
body.gate .plate,
body.gate .act { display: none; }

.intro {
  position: fixed;
  inset: 0;
  display: grid;
  align-content: end;
  justify-items: center;
  padding: 0 20px max(84px, env(safe-area-inset-bottom));
  pointer-events: none;
  background: linear-gradient(to top, rgb(20 10 12 / 0.55), transparent 38%);
}

.intro-caption {
  display: grid;
  gap: 6px;
  justify-items: center;
  max-width: 34em;
  text-align: center;
  color: #fff4e2;
  text-shadow: 0 2px 12px rgb(20 8 8 / 0.8);
}

.intro-caption strong {
  font: 700 clamp(34px, 6vw, 56px)/1.15 var(--kai);
  letter-spacing: 0.16em;
}

.intro-caption span {
  font: 400 clamp(17px, 2.4vw, 21px)/1.6 var(--kai);
}

.intro-caption.swap { animation: caption-in 0.7s ease; }

@keyframes caption-in {
  from { opacity: 0; translate: 0 10px; }
}

.intro-skip {
  position: fixed;
  top: max(16px, env(safe-area-inset-top));
  left: 16px;
  padding: 8px 16px;
  font: 500 15px/1.4 var(--hei);
  color: #fff4e2;
  background: rgb(43 20 16 / 0.6);
  border: 1px solid rgb(233 185 73 / 0.7);
  border-radius: 3px;
  cursor: pointer;
  pointer-events: auto;
}

.intro-skip:hover { background: rgb(43 20 16 / 0.85); }

.gate-lead {
  margin: 0;
  font: 400 18px/1.7 var(--kai);
}

.gate-card .slip-body { gap: 12px; }

/* 次要的按鈕：框線、不填色 */
.btn-quiet {
  color: var(--zhu);
  background: transparent;
  box-shadow: inset 0 0 0 2px var(--zhu);
}

.btn-quiet:hover { background: rgb(196 22 28 / 0.08); }

@media (prefers-reduced-motion: reduce) {
  .intro-caption.swap { animation: none; }
}

/* 訪客看到的「創建自己的角色」：名冊旁的圓鈕拉寬成有字的按鈕 */
.roster-add-wide {
  width: auto;
  padding: 0 18px;
  border-radius: 26px;
  font: 700 17px/1 var(--kai);
  letter-spacing: 0.08em;
  white-space: nowrap;
  box-shadow: inset 0 0 0 2px var(--zhu), inset 0 0 0 3px var(--jin);
}

/* ── 捏造型 ───────────────────────── */
.look-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 10px;
  border-bottom: 2px solid var(--zhu);
}

.look-tabs button {
  flex: 1;
  padding: 6px 2px;
  font: 700 17px/1.3 var(--kai);
  color: var(--zhu-deep);
  background: rgb(255 255 255 / 0.35);
  border: 1.5px solid rgb(196 22 28 / 0.35);
  border-bottom: 0;
  cursor: pointer;
}

.look-tabs button[aria-selected="true"] {
  color: var(--qian);
  background: var(--zhu);
  border-color: var(--zhu);
}

.look-fields {
  display: grid;
  gap: 12px;
}

.look-field {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.look-field > span {
  font: 700 15px/1.3 var(--hei);
  color: #6d3b34;
}

/* 色票：一排圓點，最後一個是自己挑顏色 */
.swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.swatches button {
  width: 28px;
  height: 28px;
  padding: 0;
  border: 2px solid rgb(43 20 16 / 0.25);
  border-radius: 50%;
  cursor: pointer;
}

.swatches button[aria-pressed="true"] {
  border-color: var(--zhu);
  box-shadow: 0 0 0 2px var(--qian), 0 0 0 4px var(--zhu);
}

.swatches input[type="color"] {
  width: 34px;
  height: 30px;
  padding: 0;
  border: 1.5px solid rgb(196 22 28 / 0.5);
  border-radius: 4px;
  background: #fff;
  cursor: pointer;
}

.look-field input[type="range"] {
  width: 100%;
  accent-color: var(--zhu);
}

/* 選一種：一顆一顆的小標籤 */
.opts {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.opts label {
  position: relative;
  padding: 4px 11px;
  font: 400 16px/1.4 var(--kai);
  color: var(--zhu-deep);
  background: rgb(255 255 255 / 0.4);
  border: 1.5px solid rgb(196 22 28 / 0.35);
  border-radius: 16px;
  cursor: pointer;
}

.opts input { position: absolute; opacity: 0; }
.opts label:has(:checked) { color: var(--qian); background: var(--zhu); border-color: var(--zhu); }
.opts label:has(:focus-visible) { outline: 3px solid var(--jin); outline-offset: 2px; }

.look-tools {
  display: flex;
  justify-content: space-between;
  margin-top: 10px;
}

.roster-restyle {
  flex: none;
  height: 40px;
  padding: 0 14px;
  font: 700 16px/1 var(--kai);
  letter-spacing: 0.06em;
  color: var(--jin);
  background: transparent;
  border: 1.5px solid var(--jin);
  border-radius: 20px;
  white-space: nowrap;
  cursor: pointer;
}

.roster-restyle:hover { background: rgb(233 185 73 / 0.15); }

/* ── 參拜指引 ─────────────────────── */
body.gate .guide { display: none; }

.guide {
  position: fixed;
  top: max(16px, env(safe-area-inset-top));
  left: 16px;
  width: min(300px, calc(100vw - 110px));
  padding: 12px 14px;
  color: #fff4e2;
  background: rgb(43 20 16 / 0.78);
  border: 1px solid rgb(233 185 73 / 0.6);
  border-radius: 6px;
}

.guide-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin: 0;
}

.guide-head strong { font: 700 18px/1.3 var(--kai); letter-spacing: 0.1em; color: var(--jin); }
.guide-head span { font-size: 14px; font-variant-numeric: tabular-nums; opacity: 0.9; }

.guide-bar {
  height: 4px;
  margin: 8px 0 10px;
  background: rgb(255 255 255 / 0.18);
  border-radius: 2px;
  overflow: hidden;
}

.guide-bar i {
  display: block;
  height: 100%;
  background: var(--jin);
  transition: width 0.4s ease;
}

.guide-text { margin: 0 0 10px; font: 400 17px/1.5 var(--kai); }

.guide-tools { display: flex; align-items: center; justify-content: space-between; gap: 10px; }

.guide-go {
  padding: 7px 20px;
  font: 700 17px/1 var(--kai);
  letter-spacing: 0.16em;
  color: var(--mo);
  background: var(--jin);
  border: 0;
  border-radius: 3px;
  cursor: pointer;
}

.guide-go:hover { background: #f3cf63; }
.guide .link { color: #fff4e2; border-color: rgb(255 244 226 / 0.5); font-size: 13px; }

@media (max-width: 640px) {
  .guide { top: auto; bottom: 150px; }
}

/* 開著籤紙（登記、求籤、點燈……）時指引先讓開，免得疊在一起 */
body:has(.slip:not([hidden])) .guide { display: none; }

/* ── 寵物的照片 ───────────────────── */
.step legend small { font: 400 14px/1 var(--hei); color: #6d3b34; margin-left: 4px; }

.photo-pick {
  display: flex;
  align-items: center;
  gap: 14px;
}

.photo-preview {
  flex: none;
  width: 84px;
  height: 84px;
  object-fit: cover;
  border-radius: 50%;
  border: 3px solid var(--zhu);
  background: #fff;
}

.photo-tools {
  display: grid;
  gap: 6px;
  justify-items: start;
}

.photo-choose { cursor: pointer; }
.photo-choose:has(:focus-visible) { outline: 3px solid var(--jin); outline-offset: 2px; }

/* ── 平安幣和今日功課 ───────────────── */
body.gate .hud { display: none; }

.hud {
  position: fixed;
  top: max(16px, env(safe-area-inset-top));
  right: 62px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.hud-coins,
.hud-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 36px;
  padding: 0 13px;
  font: 700 16px/1 var(--kai);
  color: #fff4e2;
  background: rgb(43 20 16 / 0.78);
  border: 1px solid rgb(233 185 73 / 0.6);
  border-radius: 18px;
}

.hud-coins b { font: 700 16px/1 var(--hei); font-variant-numeric: tabular-nums; }

/* 平安幣：一枚金色的古錢 */
.hud-coins i,
.coin {
  display: inline-block;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: radial-gradient(circle, transparent 0 3px, #e9b949 3.5px);
  box-shadow: inset 0 0 0 1.5px #b88a1f;
}

.hud-btn { position: relative; letter-spacing: 0.06em; cursor: pointer; }
.hud-btn:hover { background: rgb(43 20 16 / 0.95); }

.hud-dot {
  position: absolute;
  top: -3px;
  right: -3px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #e5392f;
  border: 2px solid #fff4e2;
}

.week {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  width: 100%;
}

.week span {
  display: grid;
  gap: 2px;
  padding: 6px 0;
  text-align: center;
  font: 400 12px/1.3 var(--hei);
  color: #6d3b34;
  background: rgb(255 255 255 / 0.4);
  border: 1.5px solid rgb(196 22 28 / 0.3);
}

.week b { font: 700 14px/1.2 var(--hei); color: var(--zhu-deep); }
.week span.got { background: rgb(233 185 73 / 0.35); border-color: var(--jin); }
.week span.next { background: #fff; border-color: var(--zhu); box-shadow: inset 0 0 0 1.5px var(--zhu); }

.quests {
  display: grid;
  gap: 6px;
  width: 100%;
  margin: 0;
  padding: 0;
  list-style: none;
}

.quests li {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  padding: 8px 10px;
  font: 400 16px/1.4 var(--kai);
  background: rgb(255 255 255 / 0.4);
  border: 1.5px solid rgb(196 22 28 / 0.3);
}

.quests small { flex: none; font: 700 13px/1 var(--hei); color: var(--zhu-deep); }
.quests li.done { color: #6d3b34; background: rgb(233 185 73 / 0.3); border-color: var(--jin); }
.quests li.done small { color: #6d3b34; }

.link.danger { color: var(--zhu-deep); justify-self: start; }

@media (max-width: 640px) {
  .hud { top: auto; bottom: 86px; right: 12px; }
}

/* ── 聊天 ─────────────────────────── */
body.gate .chat { display: none; }

/* 左下角的聊天框：上面一條標題（按一下收合），中間是最近說過的話，下面打字 */
.chat {
  position: fixed;
  left: 16px;
  bottom: max(16px, env(safe-area-inset-bottom));
  width: min(300px, calc(100vw - 32px));
  color: #fff4e2;
  background: rgb(43 20 16 / 0.78);
  border: 1px solid rgb(233 185 73 / 0.6);
  border-radius: 10px;
  overflow: hidden;
}

.chat-toggle {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  height: 34px;
  padding: 0 12px;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
  text-align: left;
}

.chat-toggle b { font: 700 15px/1 var(--kai); letter-spacing: 0.1em; }
.chat-toggle em { margin-left: auto; font: 700 16px/1 var(--hei); font-style: normal; }
.chat-toggle .hud-dot { position: static; flex: none; }
.crowd { font: 400 13px/1 var(--hei); opacity: 0.8; white-space: nowrap; }

.chat-log {
  margin: 0;
  padding: 6px 12px;
  list-style: none;
  height: 112px;
  overflow-y: auto;
  border-top: 1px solid rgb(233 185 73 / 0.3);
  font: 400 14px/1.5 var(--hei);
  overscroll-behavior: contain;
}

.chat-log li { overflow-wrap: anywhere; }
.chat-log li b { font-weight: 700; color: #ffe08a; }
.chat-log li.me b { color: #bfe3f5; }
.chat-log li.note { opacity: 0.65; }

.chat-form { display: flex; gap: 6px; padding: 6px 8px 8px; }

.chat-form input {
  flex: 1;
  min-width: 0;
  height: 34px;
  padding: 0 12px;
  font: 400 15px/1 var(--hei);
  color: #fff4e2;
  background: rgb(20 10 12 / 0.5);
  border: 1px solid rgb(233 185 73 / 0.45);
  border-radius: 17px;
}

.chat-form input::placeholder { color: rgb(255 244 226 / 0.55); }

.chat-send {
  height: 34px;
  padding: 0 12px;
  font: 700 14px/1 var(--kai);
  color: #2b1410;
  background: var(--jin);
  border: 0;
  border-radius: 17px;
  cursor: pointer;
}

/* 收起來：只剩一顆小小的「聊天」 */
.chat.folded { width: auto; border-radius: 18px; }
.chat.folded .chat-box { display: none; }
.chat.folded .crowd { display: none; }

@media (max-width: 640px) {
  .chat { left: 10px; bottom: calc(max(12px, env(safe-area-inset-bottom)) + 50px); width: min(270px, calc(100vw - 20px)); }
  .chat-log { height: 96px; }
  body:has(.slip:not([hidden])) .chat { display: none; }
  /* 聊天框打開時，中間的互動按鈕往上讓 */
  body:has(.chat:not(.folded):not([hidden])) .act { bottom: calc(max(12px, env(safe-area-inset-bottom)) + 250px); }
}

/* ── 小地圖 ───────────────────────── */
body.gate .minimap { display: none; }

.minimap {
  position: fixed;
  top: 124px; /* 在右上角的廟名印章下面 */
  right: 16px;
  width: 150px;
  height: 232px;
  background: rgb(43 20 16 / 0.62);
  border: 1px solid rgb(233 185 73 / 0.6);
  border-radius: 6px;
  pointer-events: none;
}

@media (max-width: 640px), (max-height: 560px) {
  .minimap { display: none; }
}

/* ── 小舖和接福 ───────────────────── */
.goods {
  display: grid;
  gap: 8px;
  width: 100%;
  margin: 0;
  padding: 0;
  list-style: none;
}

.goods li {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 4px 10px;
  padding: 9px 10px;
  background: rgb(255 255 255 / 0.4);
  border: 1.5px solid rgb(196 22 28 / 0.3);
}

.goods strong { font: 700 18px/1.3 var(--kai); color: var(--zhu-deep); }
.goods small { grid-column: 1; font-size: 13px; color: #6d3b34; }

.goods button {
  grid-column: 2;
  grid-row: 1 / span 2;
  padding: 7px 12px;
  font: 700 15px/1 var(--hei);
  color: var(--jin);
  background: var(--zhu);
  border: 0;
  border-radius: 2px;
  cursor: pointer;
}

.goods button:disabled { color: #6d3b34; background: rgb(233 185 73 / 0.35); cursor: default; }

.game-board {
  width: 100%;
  aspect-ratio: 300 / 340;
  background: linear-gradient(#fbe9c8, #f3d6a2);
  border: 2px solid var(--zhu);
  touch-action: none;
  cursor: ew-resize;
}

.opts label.locked { opacity: 0.55; cursor: not-allowed; }

/* ── 電腦版的登記表：左邊選角色、名字、照片，右邊捏造型，不用一直往下捲 ── */
@media (min-width: 1100px) {
  .slip.creator { width: min(760px, 62vw); }

  .slip.creator .slip-body {
    display: grid;
    grid-template-columns: 250px minmax(0, 1fr);
    column-gap: 22px;
    row-gap: 14px;
    align-content: start;
  }

  .slip.creator .slip-body > * { grid-column: 1; }
  .slip.creator .step-look { grid-column: 2; grid-row: 1 / span 8; }
  .slip.creator .look-fields { gap: 9px; }
  .slip.creator .photo-preview { width: 96px; height: 96px; }
}

.photo-preview { cursor: grab; touch-action: none; }
.photo-preview:active { cursor: grabbing; }

.photo-zoom {
  display: flex;
  align-items: center;
  gap: 8px;
  font: 500 14px/1 var(--hei);
  color: #6d3b34;
}

.photo-zoom input { width: 110px; accent-color: var(--zhu); }

/* 開著登記表（捏角色）時，名冊、聊天、小地圖、平安幣先收起來，畫面留給表單和角色 */
body:has(.slip.creator:not([hidden])) :is(.roster, .chat, .minimap, .hud) { display: none; }
.slip.creator { max-height: calc(100dvh - 48px); }
.photo-zoom { white-space: nowrap; }

/* ── 日報：像一張報紙 ───────────────── */
.slip.paper { background: #f7f1e3; }

.paper-sheet {
  display: grid;
  gap: 10px;
  padding: 22px 22px 18px;
  color: #2b1410;
}

.paper-date {
  margin: 0;
  font: 500 13px/1.3 var(--hei);
  color: #6d5a4a;
}

.paper-title {
  margin: 0;
  padding-bottom: 8px;
  text-align: center;
  font: 700 38px/1.1 var(--kai);
  letter-spacing: 0.18em;
  border-bottom: 4px double #2b1410;
}

.paper-view { display: grid; gap: 12px; }

.paper-view h3 {
  margin: 0 0 3px;
  font: 700 21px/1.35 var(--kai);
}

.paper-view p { margin: 0; font: 400 15px/1.7 var(--hei); }

.paper-view article + article {
  padding-top: 12px;
  border-top: 1px solid #b9a98e;
}

.paper-tag {
  display: inline-block;
  margin-bottom: 4px;
  padding: 1px 7px;
  font: 700 12px/1.5 var(--hei);
  color: #f7f1e3;
  background: #2b1410;
}

.paper .link { justify-self: center; }

/* 一鍵參拜 */
.guide-auto {
  padding: 7px 12px;
  font: 700 15px/1 var(--kai);
  letter-spacing: 0.08em;
  color: var(--jin);
  background: transparent;
  border: 1.5px solid var(--jin);
  border-radius: 3px;
  cursor: pointer;
}

.guide-auto:hover { background: rgb(233 185 73 / 0.15); }
.guide-tools { flex-wrap: wrap; }

/* ── 快捷列：右下角四顆圓鈕 ─────────── */
body.gate .quick,
body:has(.slip.creator:not([hidden])) .quick { display: none; }

.quick {
  position: fixed;
  right: 16px;
  bottom: 66px;
  display: flex;
  gap: 8px;
}

.quick button {
  width: 46px;
  height: 46px;
  font: 700 21px/1 var(--kai);
  color: #fff4e2;
  background: var(--zhu);
  border: 2px solid var(--jin);
  border-radius: 50%;
  box-shadow: 0 3px 8px rgb(20 10 12 / 0.4);
  cursor: pointer;
}

.quick button:hover { background: var(--zhu-deep); }

.capsule {
  width: 92px;
  height: 92px;
  margin: 4px auto;
  border-radius: 50%;
  background: linear-gradient(#f4a3b3 0 50%, #fbf6e4 50% 100%);
  border: 3px solid #2b1410;
  display: grid;
  place-items: center;
  font: 700 26px/1 var(--kai);
  color: #2b1410;
}

.capsule.shake { animation: capsule-shake 0.5s ease 2; }

@keyframes capsule-shake {
  25% { rotate: -14deg; }
  75% { rotate: 14deg; }
}

@media (prefers-reduced-motion: reduce) {
  .capsule.shake { animation: none; }
}

/* ── 會員登入 ─────────── */
.login-row {
  display: grid;
  gap: 8px;
  justify-items: center;
  padding-top: 12px;
  border-top: 1px solid rgb(180 40 30 / 0.25);
  font: 500 14px/1.5 var(--hei);
  color: #6d3b34;
}

.login-row[hidden] { display: none; }

#account-google { display: grid; justify-items: center; min-height: 44px; }
#account-google:empty { display: none; }

/* ── 手機：東西收進工具列 ─────────────
   畫面上只留：左上角的指引、左下角的「選單」和平安幣、右下角的快捷鈕、中間的互動按鈕。
   名冊、日報、功課、會員、音樂音效都在「選單」裡；聊天框在「選單」上面，可以收合（main.js 的 dockMenu 把它們搬進 #menu-body）。 */
.hud-tools { display: contents; }
.menu-open, .menu { display: none; }

@media (hover: none) {
  .plate-keys { display: none; }
}

@media (max-width: 640px) {
  .plate { display: none; }

  .guide {
    top: max(10px, env(safe-area-inset-top));
    bottom: auto;
    left: 10px;
    width: min(270px, calc(100vw - 76px));
    padding: 9px 11px;
  }
  .guide-text { font-size: 14px; }

  .seal { right: 10px; padding: 8px 6px; font-size: 18px; }

  body:not(.gate) .menu-open:not([hidden]) {
    display: inline-flex;
    align-items: center;
    position: fixed;
    left: 10px;
    bottom: max(12px, env(safe-area-inset-bottom));
    height: 42px;
    padding: 0 16px;
    font: 700 17px/1 var(--kai);
    letter-spacing: 0.1em;
    color: #fff4e2;
    background: var(--zhu);
    border: 2px solid var(--jin);
    border-radius: 21px;
    box-shadow: 0 3px 8px rgb(20 10 12 / 0.4);
  }
  body:has(.slip.creator:not([hidden])) .menu-open { display: none !important; }

  .hud { top: auto; right: auto; left: 92px; bottom: max(15px, env(safe-area-inset-bottom)); }

  .quick { right: 10px; bottom: max(12px, env(safe-area-inset-bottom)); gap: 6px; }
  .quick button { width: 42px; height: 42px; font-size: 19px; }

  .act { bottom: calc(max(12px, env(safe-area-inset-bottom)) + 62px); }
  .slip { bottom: 66px; max-height: calc(100dvh - 90px); }

  .menu:not([hidden]) {
    display: flex;
    align-items: flex-end;
    position: fixed;
    inset: 0;
    z-index: 30;
    background: rgb(20 10 12 / 0.45);
  }

  .menu-sheet {
    width: 100%;
    max-height: 80dvh;
    overflow-y: auto;
    padding: 14px 14px max(16px, env(safe-area-inset-bottom));
    color: #fff4e2;
    background: rgb(43 20 16 / 0.96);
    border-top: 2px solid var(--jin);
    border-radius: 16px 16px 0 0;
  }

  .menu-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 0 0 12px;
  }
  .menu-head strong { font: 700 22px/1.2 var(--kai); letter-spacing: 0.08em; }
  .menu-close {
    padding: 6px 14px;
    font: 700 15px/1 var(--kai);
    color: #fff4e2;
    background: none;
    border: 1px solid rgb(255 244 226 / 0.5);
    border-radius: 16px;
  }

  .menu-body { display: grid; gap: 14px; }

  /* 搬進來的東西不再各自貼在畫面邊上 */
  .menu-body > * {
    position: static;
    translate: none;
    max-width: none;
    width: auto;
  }
  .menu-body .roster { justify-content: flex-start; flex-wrap: wrap; border-radius: 14px; }
  .menu-body .hud-tools { display: flex; flex-wrap: wrap; gap: 8px; }
  .menu-body .hud-tools .hud-btn { height: 42px; padding: 0 16px; }
  .menu-body .audio-bar { display: flex; gap: 8px; }
  .menu-body .audio-bar .sound { flex: 1; padding: 11px 12px; }
}

/* 手機的登記表（捏角色）：只佔下半個畫面，上面留給角色預覽（scene.setCloseup 的 top 把角色移到那一塊） */
@media (max-width: 640px) {
  .slip.creator {
    bottom: max(10px, env(safe-area-inset-bottom));
    height: 56dvh;
    max-height: 56dvh;
  }
}

/* ── 聊天框裡的動作鈕：按一下角色就做，別人也看得到 ── */
.emotes { display: flex; gap: 6px; padding: 6px 8px 0; }
.emotes button {
  flex: 1;
  height: 34px;
  font-size: 18px;
  line-height: 1;
  color: #fff4e2;
  background: rgb(255 244 226 / 0.1);
  border: 1px solid rgb(255 244 226 / 0.28);
  border-radius: 10px;
  cursor: pointer;
}
.emotes button:hover, .emotes button:focus-visible { background: rgb(255 244 226 / 0.22); }

/* ── 紀念牌位、祈福名單、大家的祈福卡：一筆一列 ── */
.prayer-list { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.prayer-list li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 2px 10px;
  align-items: center;
  padding: 9px 11px;
  background: rgb(255 255 255 / 0.5);
  border-left: 3px solid var(--zhu);
}
.prayer-list.memorial li { border-left-color: #4a4458; }
.prayer-list strong { font: 700 19px/1.3 var(--kai); color: #2b1410; }
.prayer-list p { grid-column: 1; margin: 0; font: 400 15px/1.45 var(--kai); color: #5a3a34; overflow-wrap: anywhere; }
.prayer-list small { grid-column: 1; font: 500 12px/1.3 var(--hei); color: #8a5a50; }
.prayer-list button {
  grid-column: 2;
  grid-row: 1 / span 3;
  min-height: 36px;
  padding: 0 12px;
  font: 700 14px/1 var(--hei);
  color: var(--zhu);
  background: none;
  border: 1px solid var(--zhu);
  border-radius: 18px;
  cursor: pointer;
}
.prayer-list button:disabled { opacity: 0.5; cursor: default; }
.prayer-sub { margin: 6px 0 0; font: 700 15px/1.3 var(--hei); color: #6d3b34; }

/* 手機：籤紙開著的時候，中間的互動按鈕先收起來，不要蓋到籤紙上的按鈕 */
@media (max-width: 640px) {
  body:has(.slip:not([hidden])) .act { display: none; }
}
