:root {
  --ink: #2b2118;
  --paper: #fffaf0;
  --red: #ef4b3f;
  --yellow: #ffcf2e;
  --green: #5cc35a;
  --blue: #3f9ae8;
  --font: "ZCOOL KuaiLe", "Comic Sans MS", "PingFang TC", "Microsoft JhengHei", "Noto Sans TC", sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font); color: var(--ink); background: #fdf6e3; overflow-x: hidden; user-select: none; -webkit-user-select: none; }
#bg { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 0; }
.screen { position: relative; z-index: 1; min-height: 100vh; min-height: 100dvh; padding: max(14px, env(safe-area-inset-top)) 14px 24px; max-width: 520px; margin: 0 auto; }
.hidden { display: none !important; }

/* ---------- 蠟筆按鈕：背景框用濾鏡抖動，文字保持清楚 ---------- */
.crayon-btn { position: relative; font-family: var(--font); font-size: 20px; color: var(--ink); background: none; border: 0; padding: 12px 22px; cursor: pointer; isolation: isolate; transition: transform .12s; }
.crayon-btn::before { content: ""; position: absolute; inset: 0; z-index: -1; border: 3.5px solid var(--ink); border-radius: 18px 22px 16px 24px / 22px 16px 24px 18px; background: var(--btn, #fff); filter: url(#wobble); box-shadow: 3px 4px 0 rgba(43,33,24,.85); }
.crayon-btn:active { transform: translate(2px, 3px) rotate(-1deg); }
.crayon-btn:active::before { box-shadow: 1px 1px 0 rgba(43,33,24,.85); }
.crayon-btn:hover { transform: rotate(-1.2deg) scale(1.02); }
.crayon-btn.big { font-size: 26px; padding: 16px 30px; }
.crayon-btn.green { --btn: #8fdc7a; }
.crayon-btn.yellow { --btn: #ffe27a; }
.crayon-btn.gray { --btn: #efe6d4; }
.crayon-btn.red { --btn: #ff9b8f; }
.crayon-btn.blue { --btn: #9fd0ff; }
.crayon-btn.fb { --btn: #9db8f5; }
.crayon-btn.google { --btn: #ffffff; }
.crayon-btn.apple { --btn: #2b2118; color: #fff; }
.crayon-btn.guest { --btn: #ffe27a; }
.crayon-btn[disabled] { opacity: .5; pointer-events: none; }

.paper { position: relative; isolation: isolate; }
.paper::before { content: ""; position: absolute; inset: 0; z-index: -1; background: var(--paper); border: 3px solid var(--ink); border-radius: 20px 26px 18px 24px; filter: url(#wobble2); box-shadow: 4px 5px 0 rgba(43,33,24,.18); }

/* ---------- 登入畫面 ---------- */
.login-wrap { display: flex; flex-direction: column; align-items: center; padding-top: 4vh; }
.title { margin: 0; font-size: clamp(44px, 13vw, 68px); line-height: 1.05; text-align: center; transform: rotate(-3deg); filter: url(#wobble); }
.title span { display: inline-block; -webkit-text-stroke: 2px var(--ink); paint-order: stroke fill; text-shadow: 3px 3px 0 var(--ink), 6px 6px 0 rgba(0,0,0,.12); }
.title .t1 { color: var(--red); transform: rotate(-4deg); }
.title .t2 { color: var(--yellow); transform: rotate(3deg) translateY(4px); }
#mascot { width: 150px; height: 162px; margin-top: 6px; }
.bubble { position: relative; margin: -6px 0 18px; padding: 8px 16px; font-size: 18px; isolation: isolate; }
.bubble::before { content: ""; position: absolute; inset: 0; z-index: -1; background: #fff; border: 3px solid var(--ink); border-radius: 22px; filter: url(#wobble2); }
.login-buttons { display: flex; flex-direction: column; gap: 14px; width: min(320px, 100%); }
.login-buttons .crayon-btn { width: 100%; display: flex; align-items: center; justify-content: center; gap: 10px; }
.pico { display: inline-flex; width: 30px; height: 30px; border-radius: 50%; align-items: center; justify-content: center; font-family: Arial, sans-serif; font-weight: 700; font-size: 18px; }
.pico.fb { background: #1877f2; color: #fff; }
.pico.google { background: #fff; color: #4285f4; border: 2px solid #ddd; }
.pico.apple { background: #fff; color: #000; }
.note { min-height: 1em; margin: 14px 8px 0; font-size: 14px; text-align: center; color: #8a6d3b; line-height: 1.5; }
.legal { font-size: 12px; opacity: .7; margin-top: 10px; }
.legal a { color: inherit; }

/* ---------- 主選單 ---------- */
.topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.player { display: flex; align-items: center; gap: 10px; }
.avatar { width: 52px; height: 52px; border-radius: 50%; border: 3px solid var(--ink); background: #ffe27a center/cover; display: flex; align-items: center; justify-content: center; font-size: 24px; filter: url(#wobble2); }
.pname { font-size: 22px; }
.pmode { font-size: 13px; opacity: .7; }
.chips { display: flex; gap: 8px; }
.chip { position: relative; isolation: isolate; padding: 6px 12px; font-size: 18px; display: flex; gap: 6px; align-items: center; }
.chip::before { content: ""; position: absolute; inset: 0; z-index: -1; background: #fff; border: 3px solid var(--ink); border-radius: 16px; filter: url(#wobble2); }
.ico.heart { color: var(--red); }
.ico.coin { color: #f2b705; text-shadow: 0 0 0 #c98a00; }
.card { padding: 14px 16px 18px; margin-bottom: 14px; }
.card h2, .card h3 { margin: 0 0 10px; font-weight: normal; }
.card h2 { font-size: 24px; }
.card.small h3 { font-size: 18px; }
.level-map { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px 8px; max-height: 46vh; overflow-y: auto; padding: 6px 4px; }
.lv { position: relative; isolation: isolate; aspect-ratio: 1; border: 0; background: none; font-family: var(--font); font-size: 22px; cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--ink); }
.lv::before { content: ""; position: absolute; inset: 4%; z-index: -1; border-radius: 50%; border: 3px solid var(--ink); background: var(--lvc, #fff); filter: url(#wobble2); }
.lv.done { --lvc: #bff0a8; }
.lv.current { --lvc: #ffe27a; animation: bob 1.2s ease-in-out infinite; }
.lv.locked { --lvc: #e8decb; color: #a8977a; cursor: default; }
.lv .st { font-size: 11px; letter-spacing: -1px; color: #f2b705; -webkit-text-stroke: .6px var(--ink); }
.lv .st .off { color: #e0d6c0; }
@keyframes bob { 50% { transform: translateY(-4px) rotate(-3deg); } }
.providers { display: flex; flex-wrap: wrap; gap: 8px; }
.prov { font-size: 15px; padding: 8px 12px; }
.prov.linked::after { content: " ✓"; color: #2e8b2e; }
.home-actions { display: flex; gap: 12px; justify-content: center; align-items: center; flex-wrap: wrap; }

/* ---------- 遊戲畫面 ---------- */
.hud { display: flex; gap: 8px; margin-bottom: 12px; }
.hud-box { position: relative; isolation: isolate; flex: 1; padding: 8px 10px; text-align: center; }
.hud-box::before { content: ""; position: absolute; inset: 0; z-index: -1; background: #fff; border: 3px solid var(--ink); border-radius: 16px 20px 14px 18px; filter: url(#wobble2); }
.hud-box.wide { flex: 2.2; }
.lbl { font-size: 14px; opacity: .75; }
.muted { opacity: .7; font-size: 12px; }
.val { font-size: 28px; line-height: 1.1; }
#hud-moves.low { color: var(--red); animation: shake .5s infinite; }
@keyframes shake { 25% { transform: rotate(-4deg); } 75% { transform: rotate(4deg); } }
.progress { position: relative; height: 12px; margin-top: 4px; border: 2.5px solid var(--ink); border-radius: 10px; background: #f3ead6; overflow: visible; filter: url(#wobble2); }
.bar { height: 100%; width: 0; border-radius: 8px; background: repeating-linear-gradient(-45deg, #ff7a5c 0 6px, #ff9a7a 6px 12px); transition: width .4s; }
.mk { position: absolute; top: -6px; width: 3px; height: 20px; background: var(--ink); border-radius: 2px; }
.mk.m1 { left: 50%; } .mk.m2 { left: 75%; } .mk.m3 { left: calc(100% - 3px); }
.board-wrap { width: 100%; }
#board { width: 100%; aspect-ratio: 1; display: block; touch-action: none; }
.game-actions { display: flex; justify-content: space-between; margin-top: 14px; }

/* ---------- 彈窗 ---------- */
.modal { position: fixed; inset: 0; z-index: 10; background: rgba(43,33,24,.45); display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal-card { width: min(380px, 100%); padding: 22px 20px; text-align: center; animation: pop .35s cubic-bezier(.2,1.6,.4,1); }
@keyframes pop { from { transform: scale(.6) rotate(-6deg); opacity: 0; } }
.modal-card h2 { margin: 0 0 6px; font-size: 34px; font-weight: normal; }
.stars { display: flex; justify-content: center; gap: 4px; margin: 6px 0; }
.stars canvas { width: 70px; height: 70px; }
.stars canvas:nth-child(2) { transform: translateY(-12px) scale(1.15); }
.stars canvas.in { animation: starIn .45s cubic-bezier(.2,1.8,.4,1) both; }
@keyframes starIn { from { transform: scale(0) rotate(-90deg); } }
.modal-body { font-size: 18px; line-height: 1.7; margin-bottom: 14px; }
.modal-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

.toast { position: fixed; left: 50%; bottom: 40px; transform: translateX(-50%); z-index: 20; padding: 10px 18px; font-size: 16px; isolation: isolate; max-width: 90vw; text-align: center; }
.toast::before { content: ""; position: absolute; inset: 0; z-index: -1; background: #fff; border: 3px solid var(--ink); border-radius: 18px; filter: url(#wobble2); box-shadow: 3px 4px 0 rgba(43,33,24,.3); }
