/* 顧客端樣式：手機優先、平板最佳化；色彩與字型來自主題（CSS 變數由 theme.js 寫入） */
:root {
  --c-primary: #b3262e; --c-secondary: #1f5c3a; --c-accent: #e8b649; --c-background: #fbf3e4;
  --c-surface: #fffdf7; --c-text: #3b2a20; --c-textMuted: #6a5646; --c-win: #c8352e; --c-lose: #5f7a68;
  --font-heading: "Hiragino Maru Gothic ProN", "Yuanti TC", "Microsoft JhengHei", "PingFang TC", system-ui, sans-serif;
  --font-body: system-ui, "Microsoft JhengHei", "PingFang TC", "Noto Sans TC", sans-serif;
  --font-prize: var(--font-heading);
  --fw-heading: 800;
  --bg-image: none;
  --paper: rgba(255, 252, 242, .95);
  --ink-shadow: 0 2px 0 rgba(0, 0, 0, .5), 0 0 10px rgba(0, 0, 0, .75), 0 0 3px rgba(0, 0, 0, .6);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font-body); color: var(--c-text); background: #14213d var(--bg-image) center / cover no-repeat fixed;
  font-size: 18px; line-height: 1.5; overflow: hidden; touch-action: manipulation; overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
}
body::before { content: ""; position: fixed; inset: 0; background: linear-gradient(180deg, rgba(10, 18, 40, .55), rgba(10, 18, 40, .15) 40%, rgba(10, 18, 40, .55)); pointer-events: none; }
body.kiosk { cursor: none; }
body.kiosk .nav-only { display: none !important; }
input, textarea { -webkit-user-select: text; user-select: text; }
.app { position: relative; height: 100dvh; display: flex; flex-direction: column; padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
.screen { position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 14px; padding: 12px 16px 16px; overflow-y: auto; }
.screen > * { flex: none; max-width: 100%; }
.screen > .topbar + *, .screen > :first-child:not(.topbar) { margin-top: auto; }
.screen > :last-child { margin-bottom: auto; }
.loading { color: #fff; font-family: var(--font-heading); font-size: 22px; text-shadow: var(--ink-shadow); }

/* ---- 繪本紙張卡片 ---- */
.paper {
  width: min(100%, 560px); background: var(--paper); border: 4px solid var(--c-primary); border-radius: 26px;
  box-shadow: 0 0 0 3px var(--c-accent), 0 14px 34px rgba(0, 0, 0, .4); padding: 20px 20px 22px; position: relative;
}
.paper.wide { width: min(100%, 860px); }
.paper.flat { padding: 10px; }
h1, h2, h3 { font-family: var(--font-heading); font-weight: var(--fw-heading); margin: 0; line-height: 1.25; }
h1 { font-size: clamp(28px, 7vw, 46px); color: var(--c-primary); text-align: center; }
h2 { font-size: clamp(22px, 5vw, 30px); color: var(--c-primary); text-align: center; }
.sub { text-align: center; color: var(--c-textMuted); margin: 6px 0 0; font-size: 18px; }
.title-on-bg { color: #fff; text-shadow: 0 3px 0 rgba(0, 0, 0, .45), 0 0 18px rgba(0, 0, 0, .6); }
.sub-on-bg { color: #fff; text-shadow: var(--ink-shadow); text-align: center; margin: 0; }

/* ---- 按鈕 ---- */
.btn {
  appearance: none; border: 3px solid var(--c-accent); background: var(--c-primary); color: #fff; font: inherit; font-family: var(--font-heading); font-weight: 800;
  font-size: 22px; min-height: 58px; padding: 10px 28px; border-radius: 999px; cursor: pointer; box-shadow: 0 4px 0 rgba(0, 0, 0, .3); touch-action: manipulation;
}
.btn:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(0, 0, 0, .3); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn.alt { background: var(--c-secondary); }
.btn.ghost { background: rgba(255, 255, 255, .92); color: var(--c-primary); }
.btn.small { min-height: 44px; font-size: 16px; padding: 6px 18px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; }
.topbar { align-self: stretch; display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; flex-wrap: wrap; }
.topbar .btn { white-space: nowrap; min-height: 40px; font-size: 15px; padding: 4px 14px; }
:focus-visible { outline: 4px solid #fff; outline-offset: 2px; box-shadow: 0 0 0 7px var(--c-primary); }

/* ---- 首頁 ---- */
.home { display: flex; flex-direction: column; align-items: center; gap: 16px; text-align: center; max-width: 640px; }
.playbtn { appearance: none; border: 0; background: none; padding: 0; cursor: pointer; width: min(46vw, 210px); filter: drop-shadow(0 10px 14px rgba(0, 0, 0, .5)); animation: bob 2.4s ease-in-out infinite; }
.playbtn img { width: 100%; display: block; }
.playbtn:active { transform: scale(.96); }
.reduce .playbtn { animation: none; }
@keyframes bob { 50% { transform: translateY(-8px) scale(1.03); } }
.status-pill { background: rgba(255, 255, 255, .92); color: var(--c-primary); border-radius: 999px; padding: 6px 16px; font-weight: 700; }

/* ---- 玩法選擇卡 ---- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; width: min(100%, 760px); }
.card { appearance: none; border: 4px solid var(--c-primary); background: var(--paper); border-radius: 22px; padding: 12px 8px 14px; cursor: pointer; font: inherit; color: var(--c-text); display: flex; flex-direction: column; align-items: center; gap: 6px; min-height: 160px; box-shadow: 0 0 0 3px var(--c-accent), 0 8px 18px rgba(0, 0, 0, .35); }
.card:active { transform: scale(.97); }
.card img { height: 96px; width: auto; max-width: 100%; object-fit: contain; }
.card b { font-family: var(--font-heading); font-size: 22px; color: var(--c-primary); }

/* ---- 表單 ---- */
.form { display: flex; flex-direction: column; gap: 14px; }
.field label { display: block; font-weight: 700; margin-bottom: 4px; }
.field .req { color: var(--c-primary); }
.field input[type=text], .field input[type=tel], .field input[type=search] { width: 100%; font: inherit; font-size: 22px; padding: 12px 14px; border: 3px solid #cdb89a; border-radius: 14px; background: #fff; color: var(--c-text); }
.field input:focus { border-color: var(--c-primary); outline: none; }
.field .hint { color: var(--c-textMuted); font-size: 15px; margin-top: 2px; }
.field .err { color: #b00020; font-weight: 700; font-size: 16px; min-height: 0; }
.consent { background: #fff7e0; border: 2px dashed var(--c-accent); border-radius: 14px; padding: 10px 12px; }
.consent details { margin: 4px 0; }
.consent summary { cursor: pointer; font-weight: 700; color: var(--c-secondary); min-height: 40px; display: flex; align-items: center; }
.notice { white-space: pre-wrap; font-size: 15px; max-height: 32vh; overflow: auto; background: #fff; border-radius: 10px; padding: 8px 10px; -webkit-user-select: text; user-select: text; }
.check { display: flex; gap: 10px; align-items: flex-start; font-weight: 700; margin-top: 8px; }
.check input { width: 28px; height: 28px; flex: none; accent-color: var(--c-primary); margin-top: 2px; }

/* ---- 遊戲區 ---- */
.game { display: flex; flex-direction: column; align-items: center; gap: 12px; width: 100%; }
.game .cta { color: #fff; font-family: var(--font-heading); font-size: 24px; text-shadow: var(--ink-shadow); text-align: center; min-height: 1.5em; }
.panel { background: var(--paper); border-radius: 28px; border: 4px solid var(--c-accent); box-shadow: 0 12px 30px rgba(0, 0, 0, .45); padding: 12px; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.wheel-wrap { position: relative; width: var(--wheel-size, min(88vw, 52vh)); aspect-ratio: 1; }
.wheel-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.wheel-disk { will-change: transform; }
.pointer { position: absolute; top: -10px; left: 50%; width: 0; height: 0; transform: translateX(-50%); border-left: 15px solid transparent; border-right: 15px solid transparent; border-top: 34px solid var(--c-primary); filter: drop-shadow(0 3px 0 var(--c-accent)); z-index: 3; }
.garapon { position: relative; width: min(62vw, 44vh, 400px); }
.garapon > img { width: 100%; display: block; }
.garapon svg.crank { position: absolute; left: 0; top: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
.garapon .hit { position: absolute; border-radius: 50%; border: 0; background: rgba(255, 255, 255, .0); cursor: pointer; }
.garapon.shake > img { animation: shake .18s linear infinite; }
@keyframes shake { 25% { transform: translate(2px, -1px) rotate(.6deg); } 75% { transform: translate(-2px, 1px) rotate(-.6deg); } }
.ball { position: absolute; width: 17%; aspect-ratio: 1; border-radius: 50%; background: radial-gradient(circle at 32% 28%, #fff 0 10%, var(--ball) 38%, rgba(0, 0, 0, .35) 130%); box-shadow: 0 6px 10px rgba(0, 0, 0, .4); }
.legend { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 10px; max-width: 420px; font-size: 15px; }
.legend span { display: inline-flex; align-items: center; gap: 5px; background: rgba(255, 255, 255, .92); border-radius: 999px; padding: 2px 10px 2px 4px; }
.legend i { width: 16px; height: 16px; border-radius: 50%; display: inline-block; border: 1px solid rgba(0, 0, 0, .3); }
.gacha { position: relative; width: min(52vw, 38vh, 330px); }
.gacha > img { width: 100%; display: block; }
.gacha svg.knob { position: absolute; left: 0; top: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
.gacha .hit { position: absolute; border-radius: 50%; border: 0; background: transparent; cursor: pointer; }
.capsule { position: absolute; width: 30%; aspect-ratio: 1; border-radius: 50%; left: 35%; transform-origin: 50% 50%; cursor: pointer; border: 0; padding: 0; background: none; }
.capsule .half { position: absolute; left: 0; width: 100%; height: 50%; overflow: hidden; transition: transform .6s cubic-bezier(.3, .9, .3, 1); }
.capsule .half::after { content: ""; position: absolute; left: 0; width: 100%; aspect-ratio: 1; border-radius: 50%; }
.capsule .top { top: 0; }
.capsule .top::after { top: 0; background: radial-gradient(circle at 32% 28%, #fff 0 8%, var(--cap) 40%, rgba(0, 0, 0, .35) 140%); }
.capsule .bot { bottom: 0; }
.capsule .bot::after { bottom: 0; background: radial-gradient(circle at 32% 28%, #fff 0 8%, #f6f1e4 40%, rgba(0, 0, 0, .25) 140%); }
.capsule.open .top { transform: translateY(-70%) rotate(-18deg); }
.capsule.open .bot { transform: translateY(40%) rotate(8deg); }
.slip { position: absolute; left: 50%; top: 34%; transform: translateX(-50%) scale(.2); opacity: 0; width: 70%; height: 44%; background: #fffdf3; border: 2px solid var(--c-accent); border-radius: 6px; transition: all .6s .15s; }
.capsule.open .slip { transform: translateX(-50%) scale(1) translateY(-90%); opacity: 1; }
.scratch { position: relative; width: min(76vw, 46vh, 380px); aspect-ratio: 571 / 720; }
.scratch > img { position: absolute; inset: 0; width: 100%; height: 100%; }
.scratch .area { position: absolute; left: 16%; top: 14%; width: 68%; height: 71%; }
.scratch canvas { position: absolute; inset: 0; width: 100%; height: 100%; border-radius: 8px; touch-action: none; }
.boxes { display: grid; gap: 14px; justify-content: center; }
.box { appearance: none; background: none; border: 0; padding: 0; cursor: pointer; position: relative; width: var(--box-w, 28vw); max-width: 190px; }
.box img { width: 100%; display: block; filter: drop-shadow(0 8px 8px rgba(0, 0, 0, .45)); }
.box.wiggle img { animation: wiggle .5s ease-in-out infinite; }
.box.dim { opacity: .35; pointer-events: none; }
.box .spark { position: absolute; inset: -10%; background: radial-gradient(circle, rgba(255, 240, 170, .95), rgba(255, 240, 170, 0) 65%); opacity: 0; transition: opacity .4s; }
.box.opened .spark { opacity: 1; }
@keyframes wiggle { 25% { transform: rotate(-4deg); } 75% { transform: rotate(4deg); } }
.reduce * { animation: none !important; }

/* ---- 結果 ---- */
.result { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.result .cheer { font-family: var(--font-heading); font-size: clamp(22px, 5.5vw, 32px); color: var(--c-win); font-weight: 800; }
.result .prize-name { font-family: var(--font-prize); font-weight: 800; color: var(--c-primary); line-height: 1.15; word-break: break-all; }
.result .prize-desc { font-size: 19px; color: var(--c-text); max-width: 26em; }
.result.lose .cheer { color: var(--c-lose); }
.result .lose-text { font-family: var(--font-heading); font-size: clamp(22px, 5.5vw, 30px); color: var(--c-lose); font-weight: 800; }
.redeem { background: #fff; border: 3px dashed var(--c-accent); border-radius: 18px; padding: 10px 16px; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.redeem .code { font-family: ui-monospace, "SF Mono", Consolas, monospace; font-size: 34px; font-weight: 800; letter-spacing: .08em; color: var(--c-text); }
.redeem .qr { width: 150px; height: 150px; }
.small-note { font-size: 15px; color: var(--c-textMuted); }
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 20; }

/* ---- 名單大抽獎 ---- */
.roll { font-family: var(--font-prize); font-weight: 800; font-size: clamp(34px, 9vw, 64px); color: var(--c-primary); min-height: 1.3em; text-align: center; }
.winner-list { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.winner-list li { background: #fff; border: 2px solid var(--c-accent); border-radius: 999px; padding: 4px 14px; font-weight: 700; }

/* ---- 對話框 ---- */
#modal-root { position: relative; z-index: 50; }
.modal-bg { position: fixed; inset: 0; background: rgba(10, 16, 35, .7); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50; }
.modal { width: min(100%, 460px); background: var(--c-surface); border: 4px solid var(--c-primary); border-radius: 24px; padding: 20px; display: flex; flex-direction: column; gap: 14px; box-shadow: 0 0 0 3px var(--c-accent), 0 16px 40px rgba(0, 0, 0, .5); }
.modal p { margin: 0; text-align: center; }
.pin-dots { display: flex; gap: 10px; justify-content: center; min-height: 34px; }
.pin-dots i { width: 22px; height: 22px; border-radius: 50%; background: var(--c-primary); }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.keypad button { min-height: 62px; font-size: 28px; font-weight: 800; border-radius: 16px; border: 3px solid #cdb89a; background: #fff; font-family: inherit; color: var(--c-text); }
.keypad button:active { background: #f1e3c8; }
.err-text { color: #b00020; font-weight: 700; text-align: center; min-height: 1.4em; }

/* ---- 顧客模式角落 ---- */
.corner { position: fixed; right: 0; bottom: 0; width: 84px; height: 84px; z-index: 40; display: none; touch-action: none; }
body.kiosk .corner { display: block; }
.corner i { position: absolute; right: 10px; bottom: 10px; width: 28px; height: 28px; border-radius: 50%; border: 3px solid rgba(255, 255, 255, .0); transition: border-color .2s, transform 3s linear; }
.corner.pressing i { border-color: rgba(255, 255, 255, .85); transform: scale(1.7); }

/* ---- 其他 ---- */
.list { display: flex; flex-direction: column; gap: 10px; }
.campaign-btn { text-align: left; padding: 14px 16px; border-radius: 16px; border: 3px solid var(--c-accent); background: #fff; font: inherit; cursor: pointer; display: flex; flex-direction: column; gap: 2px; width: 100%; min-height: 64px; color: var(--c-text); }
.campaign-btn b { font-family: var(--font-heading); font-size: 22px; color: var(--c-primary); }
.campaign-btn small { color: var(--c-textMuted); }
.footer-note { color: rgba(255, 255, 255, .9); font-size: 14px; text-shadow: var(--ink-shadow); text-align: center; }
@media (min-width: 900px) and (orientation: landscape) {
  .screen { padding: 22px 40px; }
  .wheel-wrap { --wheel-size: min(60vh, 520px); }
  .box { --box-w: 18vh; }
}
@media (max-height: 560px) {
  h1 { font-size: 26px; } .btn { min-height: 48px; font-size: 19px; }
}
@media (prefers-reduced-motion: reduce) { .playbtn { animation: none; } }
