:root {
  --red: #b3201c;
  --red-dark: #7a1410;
  --gold: #e2b54a;
  --cream: #fbf3e4;
  --paper: #fffaf0;
  --ink: #3a1a10;
  --teal: #1f8a86;
  --pink: #e07a8f;
  --serif: "Noto Serif SC", "Songti SC", serif;
  --sans: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #1b1430; font-family: var(--sans); color: var(--ink); -webkit-tap-highlight-color: transparent; }
#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
button { font: inherit; cursor: pointer; }

/* Peranakan tile strip */
.tiles {
  height: 16px;
  background:
    radial-gradient(circle, #f2c14e 0 2.5px, transparent 3px),
    radial-gradient(circle, var(--pink) 0 6px, transparent 6.5px),
    radial-gradient(circle at 0 0, var(--teal) 0 6px, transparent 6.5px),
    radial-gradient(circle at 100% 0, var(--teal) 0 6px, transparent 6.5px),
    radial-gradient(circle at 0 100%, var(--teal) 0 6px, transparent 6.5px),
    radial-gradient(circle at 100% 100%, var(--teal) 0 6px, transparent 6.5px),
    #f3ead6;
  background-size: 16px 16px;
  border-bottom: 2px solid var(--red);
}

/* Loading */
#loading { position: fixed; inset: 0; display: grid; place-content: center; justify-items: center; gap: 14px; background: #1b1430; color: #ffd9a0; font-family: var(--serif); font-size: 18px; z-index: 50; }
#loading .lamp { width: 46px; height: 56px; border-radius: 50%; background: radial-gradient(circle at 50% 40%, #ff7a4a, #c81e1e 60%, #7a1410); box-shadow: 0 0 40px #ff4a2a; animation: glow 1.4s ease-in-out infinite alternate; }
@keyframes glow { from { opacity: .6; transform: translateY(0); } to { opacity: 1; transform: translateY(-6px); } }

/* HUD */
#hud { position: fixed; top: 0; left: 0; right: 0; display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; padding: calc(10px + env(safe-area-inset-top)) 12px 0; pointer-events: none; z-index: 10; }
#hud > * { pointer-events: auto; }
.brand { display: flex; flex-direction: column; color: #ffe4a8; text-shadow: 0 2px 6px #000a; font-family: var(--serif); line-height: 1.1; }
.brand b { font-size: 24px; font-weight: 900; letter-spacing: 2px; }
.brand span { font-size: 12px; opacity: .85; letter-spacing: 3px; }
.pills { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 6px 11px; border-radius: 999px; background: rgba(20, 8, 30, .62); color: #fff3dc; font-size: 13px; border: 1px solid rgba(226, 181, 74, .45); backdrop-filter: blur(6px); }
.pill b { color: var(--gold); }
.pill.icon { padding: 6px 9px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #c9a24a; display: inline-block; }
.dot.on { background: #4cd07d; box-shadow: 0 0 8px #4cd07d; }
.dot.off { background: #e05a4a; }

/* Thank-you marquee */
#marquee { position: fixed; top: calc(64px + env(safe-area-inset-top)); left: 0; right: 0; overflow: hidden; background: linear-gradient(90deg, transparent, rgba(179, 32, 28, .92) 12%, rgba(179, 32, 28, .92) 88%, transparent); color: #ffe9b0; font-family: var(--serif); font-size: 16px; padding: 7px 0; z-index: 9; pointer-events: none; }
#marquee span { display: inline-block; white-space: nowrap; padding-left: 100%; animation: marquee 13s linear 1; }
@keyframes marquee { to { transform: translateX(-100%); } }

/* Action bar */
#actions { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(12px + env(safe-area-inset-bottom)); display: flex; gap: 6px; padding: 8px; max-width: calc(100% - 16px); overflow-x: auto; scrollbar-width: none; border-radius: 22px; background: rgba(20, 8, 30, .55); border: 1px solid rgba(226, 181, 74, .35); backdrop-filter: blur(8px); z-index: 10; }
#actions::-webkit-scrollbar { display: none; }
#actions button { flex: 0 0 auto; display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 64px; padding: 7px 8px 6px; border-radius: 16px; border: 2px solid var(--gold); background: linear-gradient(#c8302a, var(--red-dark)); color: #fff1d6; font-size: 12px; font-weight: 700; box-shadow: 0 3px 0 #4a0c08; transition: transform .1s; }
#actions button span { font-size: 22px; line-height: 1.1; }
#actions button:active { transform: translateY(2px); box-shadow: 0 1px 0 #4a0c08; }
#actions button.kopi { background: linear-gradient(#2a9d94, #146660); box-shadow: 0 3px 0 #0b3b38; }

/* Toast */
#toast { position: fixed; left: 50%; bottom: calc(100px + env(safe-area-inset-bottom)); transform: translate(-50%, 10px); max-width: min(92vw, 460px); padding: 10px 16px; border-radius: 14px; background: rgba(255, 250, 240, .96); color: var(--red-dark); font-weight: 500; font-size: 14px; text-align: center; box-shadow: 0 6px 24px #0006; opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s; z-index: 30; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Cards & panels */
.card { position: fixed; z-index: 20; background: var(--paper); border: 3px solid var(--red); border-radius: 18px; overflow: hidden; box-shadow: 0 18px 60px #000a; }
.card.center { left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(92vw, 380px); }
.card-inner { padding: 18px 20px 20px; text-align: center; }
.mascot { display: block; width: 104px; height: 104px; margin: 0 auto -2px; border-radius: 50%; object-fit: cover; border: 3px solid var(--gold); box-shadow: 0 4px 14px rgba(0,0,0,.25); }
.card h1 { margin: 4px 0 2px; font-family: var(--serif); font-weight: 900; font-size: 36px; color: var(--red); letter-spacing: 4px; }
.sub { margin: 0 0 16px; color: #7b4a33; font-size: 14px; }
.field { display: block; text-align: left; font-weight: 700; font-size: 14px; margin: 10px 0 6px; }
.field input { display: block; width: 100%; margin-top: 6px; }
input, textarea { font: inherit; padding: 10px 12px; border-radius: 12px; border: 2px solid #e6cfa8; background: #fff; color: var(--ink); outline: none; resize: none; width: 100%; }
input:focus, textarea:focus { border-color: var(--red); }
.swatches { display: flex; gap: 10px; justify-content: center; margin: 4px 0 18px; }
.swatch-btn { width: 36px; height: 42px; border-radius: 50%; border: 3px solid transparent; background: radial-gradient(circle at 50% 40%, color-mix(in srgb, var(--c) 60%, white), var(--c)); box-shadow: 0 0 0 2px #e6cfa8; }
.swatch-btn.on { border-color: var(--gold); box-shadow: 0 0 0 2px var(--red), 0 0 14px var(--c); }

.primary { display: block; width: 100%; padding: 12px 16px; border-radius: 14px; border: 2px solid var(--gold); background: linear-gradient(#c8302a, var(--red-dark)); color: #fff1d6; font-weight: 700; font-size: 16px; text-align: center; text-decoration: none; box-shadow: 0 3px 0 #4a0c08; }
.primary:disabled { opacity: .6; }
.primary.kofi { background: linear-gradient(#2a9d94, #146660); box-shadow: 0 3px 0 #0b3b38; margin: 14px 0 10px; }
.hint { color: #7b4a33; font-size: 14px; line-height: 1.6; }
.small { font-size: 12px; }

.sheet { left: 50%; bottom: calc(10px + env(safe-area-inset-bottom)); transform: translateX(-50%); width: min(96vw, 440px); max-height: min(78vh, 640px); display: flex; flex-direction: column; }
.sheet header { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px 4px; }
.sheet h2 { margin: 0; font-family: var(--serif); font-size: 20px; color: var(--red); }
#panel-close { width: 34px; height: 34px; border-radius: 50%; border: 2px solid #e6cfa8; background: #fff; color: var(--red-dark); }
#panel-body { padding: 0 18px 18px; overflow-y: auto; }
#panel-body p { margin: 8px 0; line-height: 1.6; }
#panel-body h3 { font-family: var(--serif); font-size: 15px; color: var(--red-dark); margin: 16px 0 6px; }
.row { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.row .primary { width: auto; flex: 1; }
.result { min-height: 1.6em; text-align: center; font-size: 15px; }
.legend { margin-top: 10px; font-size: 13px; color: #7b4a33; }
.legend ul { padding-left: 18px; margin: 6px 0 0; line-height: 1.7; }

/* 筊 blocks (moon blocks) */
.blocks { display: flex; justify-content: center; gap: 26px; margin: 18px 0 30px; height: 70px; align-items: flex-end; }
.block { width: 74px; height: 34px; border-radius: 74px 74px 12px 12px / 34px 34px 12px 12px; position: relative; transition: background .2s; }
.block.round { background: radial-gradient(ellipse at 40% 30%, #e8473c, #9a1610 70%); box-shadow: inset 0 -4px 0 #6a0e0a; }
.block.flat { background: linear-gradient(#f2c48e, #d99a5c); box-shadow: inset 0 -4px 0 #a86a34; }
.block::after { position: absolute; left: 0; right: 0; bottom: -22px; text-align: center; font-size: 12px; color: #7b4a33; }
.block.round::after { content: "凸"; }
.block.flat::after { content: "平"; }
.block.tossing { animation: toss .95s cubic-bezier(.3, .6, .4, 1); }
.block.tossing + .block.tossing { animation-delay: .05s; }
@keyframes toss { 0% { transform: translateY(0) rotate(0); } 45% { transform: translateY(-70px) rotate(380deg); } 100% { transform: translateY(0) rotate(720deg); } }

/* 签筒 (fortune stick tube) */
.tube-wrap { display: flex; justify-content: center; margin: 14px 0 6px; height: 120px; align-items: flex-end; }
.tube { position: relative; width: 70px; height: 84px; border-radius: 8px 8px 14px 14px; background: linear-gradient(90deg, #7a1410, #b3201c 40%, #7a1410); border: 2px solid var(--gold); transform-origin: 50% 100%; }
.tube i { position: absolute; bottom: 60px; width: 5px; height: 56px; border-radius: 2px; background: linear-gradient(#c0392b 0 10px, #e9c48a 10px); }
.tube i:nth-child(1) { left: 8px; transform: rotate(-12deg); } .tube i:nth-child(2) { left: 15px; transform: rotate(-7deg); height: 62px; }
.tube i:nth-child(3) { left: 22px; transform: rotate(-3deg); } .tube i:nth-child(4) { left: 29px; height: 66px; }
.tube i:nth-child(5) { left: 36px; transform: rotate(2deg); } .tube i:nth-child(6) { left: 43px; transform: rotate(5deg); height: 60px; }
.tube i:nth-child(7) { left: 50px; transform: rotate(9deg); } .tube i:nth-child(8) { left: 25px; transform: rotate(-5deg); height: 50px; }
.tube i:nth-child(9) { left: 40px; transform: rotate(4deg); height: 52px; }
.tube.shaking { animation: shake .13s ease-in-out 10; }
@keyframes shake { 0%, 100% { transform: rotate(-14deg); } 50% { transform: rotate(-26deg) translateY(-4px); } }

.qian-card { margin-top: 16px; padding: 14px; border-radius: 14px; border: 2px solid #e6cfa8; background: #fff; text-align: center; }
.qian-head { display: flex; justify-content: center; align-items: center; gap: 10px; }
.qian-head .no { font-family: var(--serif); font-weight: 900; font-size: 20px; color: var(--red-dark); }
.grade { padding: 2px 10px; border-radius: 999px; font-size: 13px; font-weight: 700; color: #fff; }
.grade.best { background: #c8302a; } .grade.good { background: #e08a1c; } .grade.mid { background: #6b8f71; } .grade.low { background: #6b6b7a; }
/* Traditional layout: each line is a column, read top-to-bottom, columns right-to-left */
.poem { writing-mode: vertical-rl; display: inline-block; text-align: start; margin: 14px auto 6px; font-family: var(--serif); font-size: 19px; letter-spacing: 6px; line-height: 2; color: var(--ink); }
.poem span { display: block; }
.meaning { text-align: left; }
#qian-confirm { padding: 8px 18px; border-radius: 12px; border: 2px solid var(--red); background: #fff; color: var(--red); font-weight: 700; }

.wish-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.wish-list li { font-size: 14px; padding: 7px 10px; border-radius: 10px; background: #fff; border: 1px solid #f0e0c4; display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.wish-list li small { color: #9a7a63; }
.wish-list .swatch { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; transform: translateY(-1px); }
.wish-list .empty { color: #9a7a63; justify-content: center; }

/* 贡品 & 签到 */
button.pill { cursor: pointer; font: inherit; font-size: 13px; }
#actions button.badge { position: relative; }
#actions button.badge::after { content: ""; position: absolute; top: 4px; right: 6px; width: 9px; height: 9px; border-radius: 50%; background: #ffd23a; box-shadow: 0 0 0 2px var(--red-dark), 0 0 8px #ffd23a; }
.center { text-align: center; }
.fu-bal { text-align: center; font-family: var(--serif); font-size: 16px; color: var(--red-dark); margin: 6px 0 10px; }
.fu-bal b { font-size: 22px; color: #d9761c; margin-left: 4px; }
.checkin { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-bottom: 10px; }
.checkin .day { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 0; border-radius: 10px; background: #fff; border: 2px solid #f0e0c4; font-size: 12px; color: #9a7a63; }
.checkin .day b { font-size: 12px; color: var(--ink); white-space: nowrap; }
.checkin .day.done { background: #fdecc8; border-color: var(--gold); opacity: .75; }
.checkin .day.done small::after { content: " ✓"; color: #2a9d5a; }
.checkin .day.today { border-color: var(--red); box-shadow: 0 0 0 2px #f5c6c0; }
.offer-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.offer-item { display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 10px 4px 8px; border-radius: 14px; border: 2px solid #f0e0c4; background: #fff; color: var(--ink); text-align: center; }
.offer-item:not(:disabled):hover { border-color: var(--gold); }
.offer-item:disabled { opacity: .45; cursor: not-allowed; }
.offer-item .emo { font-size: 28px; line-height: 1.2; }
.offer-item b { font-size: 14px; }
.offer-item small { font-size: 11px; color: #9a7a63; line-height: 1.35; min-height: 2.7em; }
.offer-item em { font-style: normal; font-weight: 700; font-size: 13px; color: #d9761c; margin-top: 2px; }
#panel-body h3 small { font-family: var(--sans); font-weight: 400; color: #9a7a63; }

/* 取回码 */
.link { display: block; margin: 12px auto 0; padding: 4px 8px; border: 0; background: none; color: var(--red); font-size: 13px; font-weight: 500; text-decoration: underline; text-underline-offset: 3px; }
#join-restore { margin-top: 8px; text-align: left; }
#join-code-res, #code-res { min-height: 1.4em; margin: 6px 2px 0; color: var(--red-dark); }
.code-row { display: flex; gap: 8px; }
.code-row input { flex: 1; min-width: 0; font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 17px; font-weight: 700; letter-spacing: 2px; text-transform: uppercase; }
.code-row input[readonly] { background: #fdf3df; border-color: var(--gold); color: var(--red-dark); }
.code-row button { flex: 0 0 auto; padding: 0 16px; border-radius: 12px; border: 2px solid var(--gold); background: linear-gradient(#c8302a, var(--red-dark)); color: #fff1d6; font-weight: 700; }
.code-row button:disabled { opacity: .5; }
.code-box { margin-top: 14px; padding: 2px 12px 8px; border-radius: 14px; border: 2px dashed #e6cfa8; background: #fffdf7; }

/* 求字 */
.zi-row { display: flex; justify-content: center; gap: 10px; margin: 18px 0 8px; }
.zi { width: 56px; height: 70px; border-radius: 12px; display: grid; place-items: center; background: linear-gradient(#c8302a, var(--red-dark)); border: 2px solid var(--gold); box-shadow: 0 3px 0 #4a0c08; }
.zi span { font-family: var(--serif); font-weight: 900; font-size: 36px; color: #ffe2a0; }
.zi.on { animation: zi-pop .3s ease-out; }
@keyframes zi-pop { 50% { transform: scale(1.12); } }

/* On wide screens the panel sits on the right so you can still see your monk */
@media (min-width: 900px) {
  .sheet { left: auto; right: 20px; top: 76px; bottom: auto; transform: none; max-height: calc(100vh - 190px); }
}

.brand span { white-space: nowrap; }
@media (max-width: 520px) {
  .brand b { font-size: 20px; }
  .brand span { letter-spacing: 1px; }
  .pill { font-size: 12px; padding: 5px 9px; }
  #actions button { min-width: 58px; font-size: 11px; }
}
