:root {
  --cream: #f7f0e1;
  --paper: #fffaf0;
  --navy: #1f2d4f;
  --navy-2: #34457a;
  --gold: #b48a3c;
  --gold-2: #d9b46a;
  --pink: #efc9c4;
  --pink-2: #f8e3df;
  --rose: #b85c63;
  --green: #4d7a5a;
  --ink: #2a2a33;
  --muted: #6d6a73;
  --line: #e3d6bb;
  --radius: 16px;
  --shadow: 0 6px 20px rgba(31, 45, 79, .12);
  --serif: 'Noto Serif TC', 'Songti TC', serif;
  --sans: -apple-system, BlinkMacSystemFont, 'PingFang TC', 'Noto Sans TC', 'Microsoft JhengHei', sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--cream);
  background-image: radial-gradient(circle at 20% 0%, #fff6e6 0, transparent 45%), radial-gradient(circle at 100% 30%, #f9e7e2 0, transparent 40%);
  color: var(--ink); font-family: var(--sans); font-size: 16px; line-height: 1.6;
  -webkit-tap-highlight-color: transparent; min-height: 100vh;
}
button { font: inherit; color: inherit; }
h1, h2, h3 { font-family: var(--serif); color: var(--navy); margin: 0 0 .4em; line-height: 1.3; }
.wrap { max-width: 560px; margin: 0 auto; padding: 16px 16px 64px; }
.muted { color: var(--muted); font-size: .92em; }
.center { text-align: center; }
.hidden { display: none !important; }

/* top bar */
.topbar { position: sticky; top: 0; z-index: 20; background: rgba(247, 240, 225, .94); backdrop-filter: blur(6px); border-bottom: 1px solid var(--line); }
.topbar .in { max-width: 560px; margin: 0 auto; display: flex; align-items: center; gap: 8px; padding: 10px 12px; }
.topbar .title { flex: 1; font-family: var(--serif); font-weight: 700; color: var(--navy); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { border: 1px solid var(--line); background: var(--paper); border-radius: 999px; padding: 6px 12px; font-size: 14px; cursor: pointer; color: var(--navy); white-space: nowrap; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 0; border-radius: 999px; padding: 12px 22px; font-weight: 700; cursor: pointer; background: var(--navy); color: #fff; box-shadow: 0 3px 0 #0f1830; transition: transform .08s; text-decoration: none; min-height: 48px; white-space: nowrap; }
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #0f1830; }
.btn.gold { background: linear-gradient(180deg, var(--gold-2), var(--gold)); color: #2b1f08; box-shadow: 0 3px 0 #8a6527; }
.btn.ghost { background: var(--paper); color: var(--navy); border: 1.5px solid var(--navy); box-shadow: none; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .45; pointer-events: none; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }
.btn-row .btn { flex: 1; }

/* cards */
.card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 14px; }
.story { font-family: var(--serif); font-size: 1.05em; color: var(--navy); background: var(--paper); border-left: 4px solid var(--gold); padding: 12px 14px; border-radius: 0 12px 12px 0; margin: 12px 0; }

/* hero */
.hero { position: relative; border-radius: 22px; overflow: hidden; margin: 6px 0 16px; box-shadow: var(--shadow); }
.hero img { display: block; width: 100%; height: 180px; object-fit: cover; }
.hero .ov { position: absolute; inset: 0; background: linear-gradient(180deg, rgba(31, 45, 79, .05), rgba(31, 45, 79, .75)); display: flex; flex-direction: column; justify-content: flex-end; padding: 16px; color: #fff; }
.hero h1 { color: #fff; font-size: 1.5em; margin: 0; text-shadow: 0 2px 8px rgba(0, 0, 0, .4); }
.hero .sub { font-size: .9em; opacity: .95; }

.banner { border-radius: 12px; padding: 10px 14px; margin-bottom: 14px; font-weight: 600; display: flex; gap: 8px; align-items: center; }
.banner.pending { background: var(--pink-2); color: var(--rose); }
.banner.open { background: #e5efe4; color: var(--green); }
.banner.closed { background: #ece9f2; color: var(--navy-2); }

/* game grid */
.games { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.gcard { position: relative; text-align: left; background: var(--paper); border: 1.5px solid var(--line); border-radius: var(--radius); padding: 0; overflow: hidden; box-shadow: var(--shadow); cursor: pointer; display: flex; flex-direction: column; }
.gcard img { width: 100%; aspect-ratio: 4/3; object-fit: cover; display: block; background: var(--pink-2); }
.gcard .body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.gcard .no { font-family: var(--serif); color: var(--gold); font-weight: 700; font-size: .85em; letter-spacing: .1em; }
.gcard .t { font-family: var(--serif); font-weight: 700; color: var(--navy); line-height: 1.3; }
.gcard .place { font-size: .78em; color: var(--muted); }
.gcard.locked { opacity: .6; }
a.gcard, a.icon-btn, a.btn { text-decoration: none; }
a.gcard { color: inherit; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: auto; padding-top: 6px; }
.chip { font-size: .72em; padding: 2px 8px; border-radius: 999px; background: #eee; color: var(--ink); white-space: nowrap; font-weight: 600; }
.chip.avail { background: #fdf0d2; color: #8a6527; }
.chip.taken { background: #ece9f2; color: var(--navy-2); }
.chip.done { background: #e5efe4; color: var(--green); }
.chip.prog { background: var(--pink-2); color: var(--rose); }
.chip.mine { background: var(--gold); color: #fff; }

/* forms */
.field { display: block; margin: 12px 0; }
.field label { display: block; font-weight: 600; margin-bottom: 6px; color: var(--navy); }
.input { width: 100%; font-size: 18px; padding: 12px 14px; border: 1.5px solid var(--line); border-radius: 12px; background: #fff; outline: none; }
.input:focus { border-color: var(--navy-2); box-shadow: 0 0 0 3px rgba(52, 69, 122, .15); }
.results { list-style: none; margin: 8px 0 0; padding: 0; }
.results li button { width: 100%; text-align: left; display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 12px 14px; margin-bottom: 8px; border: 1.5px solid var(--line); background: #fff; border-radius: 12px; cursor: pointer; font-size: 17px; }
.results li button:active { background: var(--pink-2); }
.tbl-tag { font-size: 13px; color: var(--gold); font-weight: 700; white-space: nowrap; }
.link-btn { background: none; border: 0; color: var(--navy-2); text-decoration: underline; cursor: pointer; padding: 6px 0; font-size: .95em; }

/* toast & feedback */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); background: var(--navy); color: #fff; padding: 10px 18px; border-radius: 999px; font-weight: 600; opacity: 0; transition: .25s; z-index: 100; max-width: 90vw; text-align: center; pointer-events: none; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.bad { background: var(--rose); }
.toast.good { background: var(--green); }
.feedback { margin-top: 12px; padding: 10px 14px; border-radius: 12px; font-weight: 600; }
.feedback.bad { background: var(--pink-2); color: var(--rose); }
.feedback.good { background: #e5efe4; color: var(--green); }
.netbar { position: fixed; top: 0; left: 0; right: 0; background: var(--rose); color: #fff; text-align: center; font-size: 14px; padding: 6px; z-index: 200; }

/* zoomer */
.zoomer { position: relative; overflow: hidden; touch-action: none; border-radius: 12px; background: #e9dfc9; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.zoomer .zc { position: absolute; left: 0; top: 0; width: 100%; height: 100%; transform-origin: 0 0; will-change: transform; }
.zoomer .zc > img { width: 100%; height: 100%; display: block; pointer-events: none; -webkit-user-drag: none; }
.zoom-ctl { position: absolute; right: 8px; bottom: 8px; display: flex; gap: 6px; z-index: 5; }
.zoom-ctl button { width: 38px; height: 38px; border-radius: 50%; border: 0; background: rgba(255, 250, 240, .92); color: var(--navy); font-size: 20px; font-weight: 700; box-shadow: 0 2px 6px rgba(0, 0, 0, .2); cursor: pointer; }
.zoom-hint { position: absolute; left: 8px; top: 8px; background: rgba(31, 45, 79, .75); color: #fff; font-size: 12px; padding: 3px 9px; border-radius: 999px; pointer-events: none; z-index: 5; }
.img-retry { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; z-index: 6; }

/* lightbox */
.lightbox { position: fixed; inset: 0; background: rgba(20, 24, 40, .92); z-index: 150; display: flex; flex-direction: column; }
.lightbox .lb-top { display: flex; justify-content: space-between; align-items: center; color: #fff; padding: 10px 14px; }
.lightbox .lb-body { flex: 1; display: flex; align-items: center; justify-content: center; padding: 8px; min-height: 0; }

/* stepper */
.steps { display: flex; gap: 6px; justify-content: center; margin: 4px 0 12px; }
.steps span { width: 28px; height: 6px; border-radius: 3px; background: var(--line); }
.steps span.on { background: var(--gold); }

/* game 01 tickets */
.tickets { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.ticket { border: 2px solid transparent; border-radius: 14px; padding: 6px; background: var(--paper); cursor: pointer; box-shadow: var(--shadow); }
.ticket img { width: 100%; display: block; border-radius: 8px; }
.ticket .nm { text-align: center; font-weight: 700; color: var(--navy); font-family: var(--serif); }
.ticket.wrong { border-color: var(--rose); opacity: .55; }
.ticket.right { border-color: var(--green); }

/* game 02 */
.postcards { display: flex; flex-direction: column; gap: 10px; }
.postcards button { border: 0; padding: 0; background: none; cursor: zoom-in; }
.postcards img { width: 100%; border-radius: 12px; box-shadow: var(--shadow); display: block; }
.pc-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.digits { display: flex; gap: 10px; justify-content: center; margin: 10px 0; }
.digit { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.digit span { font-family: var(--serif); color: var(--gold); font-weight: 700; }
.digit input { width: 64px; height: 72px; font-size: 34px; text-align: center; border: 2px solid var(--line); border-radius: 14px; background: #fff; font-family: var(--serif); color: var(--navy); }
.digit input:focus { outline: none; border-color: var(--navy-2); }

/* game 03 wheel */
.wheel-box { position: relative; width: 100%; aspect-ratio: 1; border-radius: 16px; overflow: hidden; box-shadow: var(--shadow); }
.wheel-box > img { width: 100%; height: 100%; display: block; }
.cabin { position: absolute; transform: translate(-50%, -50%); width: 15%; aspect-ratio: 1; border-radius: 10px; border: 2px dashed transparent; padding: 0; background: none; cursor: pointer; }
.cabin img { width: 100%; height: 100%; border-radius: 8px; display: block; box-shadow: 0 2px 6px rgba(0, 0, 0, .25); }
.cabin .n { position: absolute; top: -10px; left: -10px; width: 22px; height: 22px; border-radius: 50%; background: var(--navy); color: #fff; font-size: 12px; line-height: 22px; text-align: center; font-weight: 700; }
.cabin.sel { border-color: var(--rose); transform: translate(-50%, -50%) scale(1.12); }
.cabin.lit img { box-shadow: 0 0 0 3px var(--gold-2), 0 0 22px 8px rgba(255, 215, 120, .95); }
.wheel-box.spinning .cabin img { animation: pulse .5s ease-in-out infinite alternate; }
@keyframes pulse { from { filter: brightness(1); } to { filter: brightness(1.35); } }
.night { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity 1.2s; }
.night.show { opacity: 1; }
.records { width: 100%; border-collapse: collapse; margin-top: 6px; }
.records td, .records th { border-bottom: 1px solid var(--line); padding: 4px 2px; text-align: center; font-size: 14px; }
.records img { width: 34px; height: 34px; border-radius: 5px; display: block; margin: 0 auto; }
.records tr.preset td { background: #fbf4e6; }
.records tr.flash td { animation: flash 1.2s 2; }
@keyframes flash { 50% { background: var(--pink); } }
.records .hits { font-weight: 700; color: var(--navy); white-space: nowrap; }

/* game 04 */
.slot { position: absolute; border: 3px dashed rgba(184, 92, 99, .9); border-radius: 10px; background: rgba(255, 255, 255, .12); animation: blink 1.6s infinite; }
.slot.filled { border-color: transparent; animation: none; background: none; }
.slot.target { border-color: var(--gold); border-style: solid; background: rgba(217, 180, 106, .25); }
.slot img { width: 100%; height: 100%; display: block; pointer-events: none; }
@keyframes blink { 50% { border-color: rgba(184, 92, 99, .3); } }
.tray { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 10px; }
.piece { border: 2px solid var(--line); background: #fff; border-radius: 10px; padding: 4px; cursor: pointer; aspect-ratio: 200/170; position: relative; }
.piece img { width: 100%; height: 100%; object-fit: contain; display: block; }
.piece.sel { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(217, 180, 106, .45); }
.piece.used { opacity: .25; }
.piece .lbl { position: absolute; bottom: -2px; right: 2px; font-size: 11px; color: var(--muted); }

/* game 05 */
.diff-pair { display: grid; gap: 8px; }
.diff-pair.side { grid-template-columns: 1fr 1fr; }
.mark { position: absolute; border: 3px solid #ff3b5c; border-radius: 50%; transform: translate(-50%, -50%); pointer-events: none; box-shadow: 0 0 0 calc(2px * var(--inv, 1)) rgba(255, 255, 255, .7); animation: pop .3s; }
.miss { position: absolute; transform: translate(-50%, -50%); color: #ff3b5c; font-weight: 900; font-size: 22px; pointer-events: none; text-shadow: 0 0 3px #fff; animation: fade .9s forwards; }
@keyframes pop { from { transform: translate(-50%, -50%) scale(1.6); opacity: 0; } }
@keyframes fade { to { opacity: 0; transform: translate(-50%, -90%); } }
.counter { font-family: var(--serif); font-size: 1.3em; color: var(--navy); font-weight: 700; }

/* game 06 */
.stalls { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stall { background: var(--paper); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; box-shadow: var(--shadow); }
.stall img { width: 100%; display: block; aspect-ratio: 1; object-fit: cover; }
.stall .nm { font-family: var(--serif); font-weight: 700; color: var(--navy); padding: 6px 10px 0; }
.stall .note { margin: 4px 10px; font-size: 14px; background: #fff8e8; border: 1px dashed var(--gold-2); padding: 6px 8px; border-radius: 8px; }
.tf { display: flex; gap: 4px; padding: 4px 10px 10px; }
.tf button { flex: 1; border: 1.5px solid var(--line); background: #fff; border-radius: 8px; padding: 4px 0; font-size: 13px; cursor: pointer; }
.tf button.on.t { background: #e5efe4; border-color: var(--green); color: var(--green); font-weight: 700; }
.tf button.on.f { background: var(--pink-2); border-color: var(--rose); color: var(--rose); font-weight: 700; }
.choice { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.choice button { border: 1.5px solid var(--line); background: #fff; border-radius: 12px; padding: 10px; cursor: pointer; font-weight: 600; min-height: 46px; }
.choice button.on { border-color: var(--navy); background: var(--navy); color: #fff; }
.box-img { width: 100%; border-radius: 16px; display: block; box-shadow: var(--shadow); }

/* result panel */
.result { text-align: center; padding: 22px 16px; background: linear-gradient(180deg, #fffaf0, #fbeedd); border: 2px solid var(--gold-2); border-radius: 20px; box-shadow: var(--shadow); margin: 16px 0; position: relative; overflow: hidden; }
.result h2 { font-size: 1.4em; }
.result .code { font-family: 'Courier New', monospace; font-size: 2.2em; letter-spacing: .18em; font-weight: 700; color: var(--navy); background: #fff; border: 2px dashed var(--gold); border-radius: 14px; padding: 8px 4px; margin: 12px 0; }
.result .prize { color: var(--gold); font-weight: 700; }

/* gifts */
.gift { text-align: center; }
.gift .code { font-family: 'Courier New', monospace; font-size: 2.6em; letter-spacing: .2em; font-weight: 700; color: var(--navy); border: 3px dashed var(--gold); border-radius: 16px; padding: 10px 0; margin: 10px 0; background: #fff; }
.gift.redeemed .code { text-decoration: line-through; color: var(--muted); border-color: var(--line); }
.stamp { display: inline-block; border: 3px solid var(--rose); color: var(--rose); font-weight: 900; padding: 2px 12px; border-radius: 8px; transform: rotate(-6deg); }

/* confetti */
.confetti { position: fixed; top: -10px; width: 8px; height: 14px; z-index: 300; pointer-events: none; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
.cabin { transition: opacity 1s; }
.wheel-box.night-on .cabin { opacity: 0; pointer-events: none; }
.dlg-back { position: fixed; inset: 0; background: rgba(20, 24, 40, .55); z-index: 400; display: flex; align-items: center; justify-content: center; padding: 16px; }
.dlg { background: var(--paper); border-radius: 18px; padding: 20px; max-width: 360px; width: 100%; box-shadow: var(--shadow); }
.dlg p { margin: 0; font-size: 17px; color: var(--navy); font-weight: 600; text-align: center; }
/* 全通關大獎 */
.grand { background: linear-gradient(135deg, #1f2d4f, #34457a); color: #fff; border-radius: 16px; padding: 12px 14px; margin-bottom: 14px; box-shadow: var(--shadow); text-align: left; }
.grand .gt { font-family: var(--serif); font-weight: 700; color: var(--gold-2); font-size: 1.05em; }
.grand .muted { color: #d8dcea; }
.grand.mine { background: linear-gradient(135deg, #b48a3c, #d9b46a); color: #2b1f08; }
.grand.mine .gt { color: #2b1f08; }
.gprog { height: 8px; background: rgba(255, 255, 255, .25); border-radius: 4px; margin: 8px 0 2px; overflow: hidden; }
.gprog span { display: block; height: 100%; background: var(--gold-2); border-radius: 4px; }
.winner-name { font-family: var(--serif); font-size: 2em; font-weight: 700; color: var(--navy); border: 3px dashed var(--gold); border-radius: 16px; padding: 8px 0; margin: 10px 0; background: #fff; line-height: 1.3; }
.winner-name small { display: block; font-size: .5em; color: var(--gold); }
.gift.redeemed .winner-name { color: var(--muted); border-color: var(--line); }
/* 摩天輪破關動畫 */
.rays { position: absolute; width: 95%; aspect-ratio: 1; border-radius: 50%; transform: translate(-50%, -50%); pointer-events: none; opacity: 0; transition: opacity .8s;
  background: radial-gradient(circle, rgba(255, 236, 170, .9) 0 6%, rgba(255, 200, 90, .35) 14%, transparent 40%),
    repeating-conic-gradient(from 0deg, rgba(230, 170, 60, .5) 0deg 7deg, rgba(255, 221, 140, 0) 7deg 20deg);
  -webkit-mask: radial-gradient(circle, #000 20%, transparent 72%); mask: radial-gradient(circle, #000 20%, transparent 72%); }
.wheel-box.celebrate .rays { opacity: 1; }
.wheel-box.celebrate { box-shadow: 0 0 0 3px var(--gold-2), 0 0 40px 6px rgba(255, 200, 100, .55); }
.wheel-box.celebrate .cabin { transition: none; }
.spark { position: absolute; transform: translate(-50%, -50%); color: #fff3c4; text-shadow: 0 0 8px #ffd36b, 0 0 16px #ffb300; pointer-events: none; animation: sparkle .9s ease-out forwards; z-index: 3; }
@keyframes sparkle { 0% { opacity: 0; transform: translate(-50%, -50%) scale(.2) rotate(0); } 30% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -50%) scale(1.4) rotate(90deg); } }
.flash { position: absolute; inset: 0; background: radial-gradient(circle at 50% 43%, #fff, rgba(255, 240, 200, .6) 40%, transparent 75%); animation: flash-out 1.1s ease-out forwards; pointer-events: none; z-index: 4; }
@keyframes flash-out { from { opacity: 1; } to { opacity: 0; } }
/* 摩天輪旋轉圖層 */
.wl { position: absolute; inset: 0; opacity: 0; transition: opacity .35s; pointer-events: none; z-index: 2; }
.wl.on { opacity: 1; }
.wl-full { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.wl-disc { will-change: transform; filter: drop-shadow(0 0 6px rgba(255, 215, 130, .8)); }
.wl-dim { position: absolute; inset: 0; background: radial-gradient(circle at 50% 43%, rgba(31, 45, 79, .05), rgba(31, 45, 79, .45) 75%); }
.wl-legs { position: absolute; display: block; }
.wl-cab { position: absolute; transform: translate(-50%, -50%); will-change: left, top; filter: drop-shadow(0 0 5px rgba(255, 210, 120, .9)); }
.wl-cab > img:first-child { width: 100%; height: 100%; display: block; }
.wl-icon { position: absolute; left: 50%; width: 42%; aspect-ratio: 1; transform: translate(-50%, -50%); border-radius: 6px; box-shadow: 0 0 0 2px #ffe7a8, 0 0 14px 4px rgba(255, 214, 120, .9); }

/* 第四關：拖曳 */
.dock { position: sticky; bottom: 0; z-index: 10; background: rgba(247, 240, 225, .97); border-top: 1px solid var(--line); margin: 10px -16px 0; padding: 8px 16px calc(8px + env(safe-area-inset-bottom)); backdrop-filter: blur(4px); }
.dock .tray { grid-template-columns: repeat(5, 1fr); gap: 6px; margin-top: 0; }
.dock .btn { min-height: 42px; padding: 8px 14px; }
.piece { touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.slot.filled { cursor: grab; }
.drag-ghost { position: fixed; z-index: 500; pointer-events: none; transform: translate(-50%, -50%) scale(1.06); filter: drop-shadow(0 6px 10px rgba(0, 0, 0, .35)); opacity: .95; }
/* 難度星等 */
.stars { color: var(--gold); letter-spacing: 1px; font-size: 1em; }
.stars .off { color: var(--line); }
.gcard .diff { font-size: .78em; color: var(--muted); }
.diff-line { font-size: .9em; color: var(--navy); font-weight: 600; display: flex; gap: 4px; align-items: center; }
.diff-line .stars { font-size: 1.1em; }
