* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  font-family: -apple-system, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  background: #fff7e0; color: #3a2e1f;
  -webkit-user-select: none; user-select: none;
  touch-action: manipulation;
}
.screen { position: fixed; inset: 0; display: none; }
.screen.active { display: block; }

/* 首頁 */
#home { background: radial-gradient(circle at 30% 10%, #fff3b8, #ffd76a 60%, #ffbf3f); overflow-y: auto; }
.home-inner { max-width: 440px; margin: 0 auto; padding: calc(28px + env(safe-area-inset-top)) 22px 90px; display: flex; flex-direction: column; align-items: stretch; gap: 14px; }
.logo { font-size: 64px; text-align: center; animation: bob 2s ease-in-out infinite; }
h1 { text-align: center; margin: 0; font-size: 34px; letter-spacing: 1px; }
h1 span { background: #ff6b4a; color: #fff; border-radius: 10px; padding: 0 8px; }
.sub { text-align: center; margin: 0 0 8px; font-size: 17px; }
.big-btn {
  display: block; width: 100%; border: none; border-radius: 22px; padding: 18px; font-size: 21px; font-weight: 700;
  text-align: center; background: #fff; color: #3a2e1f; box-shadow: 0 5px 0 rgba(0,0,0,.15); cursor: pointer; font-family: inherit;
}
.big-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 rgba(0,0,0,.15); }
.big-btn.primary { background: #ff6b4a; color: #fff; }
.big-btn.ghost { background: rgba(255,255,255,.6); }
.link-btn { background: none; border: none; font-size: 16px; color: #6b5330; text-decoration: underline; padding: 8px; font-family: inherit; }
.tips { background: rgba(255,255,255,.7); border-radius: 18px; padding: 14px 16px; font-size: 15px; line-height: 1.6; }
.tips ul { margin: 6px 0 0; padding-left: 20px; }
.credit { position: fixed; bottom: 0; left: 0; right: 0; font-size: 10px; text-align: center; padding: 6px 10px calc(6px + env(safe-area-inset-bottom)); color: #6b5330; background: rgba(255,255,255,.45); }
.credit a { color: inherit; }

/* 確認畫面 */
#confirm { background: #fff7e0; overflow-y: auto; padding: calc(14px + env(safe-area-inset-top)) 18px 40px; }
#confirm > * { max-width: 460px; margin-left: auto; margin-right: auto; }
#confirm h2 { text-align: center; margin: 4px auto 10px; }
.result-box {
  height: 38vh; border-radius: 22px; display: flex; align-items: center; justify-content: center; padding: 14px;
  background-color: #e8f4ff;
  background-image: linear-gradient(45deg,#d4e9fb 25%,transparent 25%,transparent 75%,#d4e9fb 75%), linear-gradient(45deg,#d4e9fb 25%,transparent 25%,transparent 75%,#d4e9fb 75%);
  background-size: 28px 28px; background-position: 0 0, 14px 14px;
}
#result-img { max-width: 100%; max-height: 100%; filter: drop-shadow(0 8px 6px rgba(0,0,0,.25)); animation: wobble 1.6s ease-in-out infinite; transform-origin: 50% 100%; }
.pick-row { display: flex; gap: 12px; align-items: center; margin-top: 12px; }
#pick-canvas { width: 96px; border-radius: 10px; box-shadow: 0 2px 6px rgba(0,0,0,.2); flex: none; }
.pick-row p { margin: 0; font-size: 14px; line-height: 1.5; }
.ctrl { display: flex; align-items: center; gap: 8px; margin-top: 12px; font-size: 15px; }
.ctrl > span { width: 72px; font-weight: 700; flex: none; }
.ctrl input[type=range] { flex: 1; accent-color: #ff6b4a; height: 30px; }
.seg-btn { flex: 1; padding: 10px; border-radius: 14px; border: 2px solid #e0cfa8; background: #fff; font-size: 16px; font-family: inherit; }
.seg-btn.active { border-color: #ff6b4a; background: #ffe3d9; font-weight: 700; }
.warn { color: #c2410c; font-size: 14px; text-align: center; }
#confirm .big-btn { margin-top: 12px; }
#confirm .link-btn { display: block; margin: 8px auto 0; }

/* 遊戲畫面 */
#play { background: #000; }
#stage, #touch { position: absolute; inset: 0; }
#stage canvas { position: absolute; inset: 0; width: 100% !important; height: 100% !important; display: block; }
#touch { touch-action: none; }
.top-bar { position: absolute; top: calc(10px + env(safe-area-inset-top)); left: 10px; right: 10px; display: flex; align-items: flex-start; gap: 10px; pointer-events: none; }
.top-bar > * { pointer-events: auto; }
#hint { flex: 1; background: rgba(255,255,255,.88); border-radius: 16px; padding: 10px 14px; font-size: 15px; font-weight: 600; text-align: center; min-height: 44px; display: flex; align-items: center; justify-content: center; transition: opacity .4s; }
#hint.hide { opacity: 0; }
.round { width: 52px; height: 52px; border-radius: 50%; border: none; background: rgba(255,255,255,.9); font-size: 24px; box-shadow: 0 3px 8px rgba(0,0,0,.25); flex: none; }
.round:active { transform: scale(.92); }
.round.small { width: 46px; height: 46px; font-size: 20px; }
.side-bar { position: absolute; right: 12px; top: calc(80px + env(safe-area-inset-top)); display: flex; flex-direction: column; gap: 12px; }
#joy { position: absolute; left: 22px; bottom: calc(26px + env(safe-area-inset-bottom)); width: 132px; height: 132px; border-radius: 50%; background: rgba(255,255,255,.35); border: 3px solid rgba(255,255,255,.85); touch-action: none; }
#knob { position: absolute; left: 50%; top: 50%; width: 58px; height: 58px; margin: -29px 0 0 -29px; border-radius: 50%; background: #fff; box-shadow: 0 3px 8px rgba(0,0,0,.3); }
.apple-btn { position: absolute; right: 22px; bottom: calc(26px + env(safe-area-inset-bottom)); width: 104px; height: 104px; border-radius: 50%; border: 4px solid #fff; background: #ffd9d4; font-size: 50px; line-height: 1; box-shadow: 0 5px 12px rgba(0,0,0,.3); touch-action: none; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 0; }
.apple-btn small { font-size: 10px; color: #7a3b2e; margin-top: 2px; }
.apple-btn:active { transform: scale(.94); }
#drag-apple { position: fixed; font-size: 56px; pointer-events: none; display: none; transform: translate(-50%, -60%); filter: drop-shadow(0 6px 4px rgba(0,0,0,.35)); z-index: 5; }

#loading { position: fixed; inset: 0; background: rgba(255,247,224,.96); display: flex; flex-direction: column; align-items: center; justify-content: center; z-index: 20; text-align: center; padding: 30px; }
#loading[hidden], #modal[hidden] { display: none; }
.spinner { width: 54px; height: 54px; border-radius: 50%; border: 6px solid #ffd76a; border-top-color: #ff6b4a; animation: spin 1s linear infinite; }
#loading p { font-size: 17px; line-height: 1.6; }

#modal { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 30; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal-card { background: #fff; border-radius: 22px; padding: 18px; max-width: 420px; width: 100%; max-height: 90vh; overflow-y: auto; text-align: center; }
.modal-card img { width: 100%; border-radius: 12px; -webkit-user-select: auto; user-select: auto; -webkit-touch-callout: default; }
.modal-card p { line-height: 1.6; }
#modal-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }

@keyframes bob { 50% { transform: translateY(-8px); } }
@keyframes wobble { 0%,100% { transform: rotate(-3deg) scaleY(1); } 50% { transform: rotate(3deg) scaleY(1.03); } }
@keyframes spin { to { transform: rotate(360deg); } }
