:root{
  --bg1:#c9f2b0; --bg2:#fff4c9; --ink:#3b2f2f; --board:#ffd98a; --board-edge:#e9a948; --hole:#d79a3c;
  --peg:#ff5a5f; --ok:#37c26a; --blue:#2f7df6; --pink:#ff8fb1; --card:#ffffff;
}
@media (prefers-color-scheme: dark){
  :root{ --bg1:#2c4a2a; --bg2:#4a3f22; --ink:#fff7e6; --card:#3a3a32; }
}
*{box-sizing:border-box}
html,body{margin:0}
body{
  min-height:100dvh; color:var(--ink);
  font-family:"Noto Sans TC","PingFang TC","Microsoft JhengHei","Hiragino Sans GB",system-ui,sans-serif;
  background:linear-gradient(160deg,var(--bg1),var(--bg2)) fixed;
  -webkit-tap-highlight-color:transparent;
}
.app{max-width:640px;margin:0 auto;padding:12px 16px calc(20px + env(safe-area-inset-bottom));display:flex;flex-direction:column;gap:10px}
.top{display:flex;align-items:center;justify-content:space-between;gap:8px}
h1{margin:0;font-size:clamp(22px,6vw,30px);letter-spacing:.04em;text-shadow:0 2px 0 rgba(255,255,255,.6)}
.logo{display:inline-block;animation:bob 2.4s ease-in-out infinite}
@keyframes bob{50%{transform:translateY(-4px) rotate(6deg)}}
.chip-btn{border:0;background:var(--card);color:var(--ink);border-radius:999px;padding:8px 14px;font:inherit;font-weight:700;box-shadow:0 3px 0 rgba(0,0,0,.12);cursor:pointer;min-height:44px}
.stats{display:flex;gap:10px}
.stat{flex:1;background:var(--card);border-radius:18px;padding:6px 12px;display:flex;align-items:baseline;justify-content:space-between;box-shadow:0 3px 0 rgba(0,0,0,.1)}
.stat .k{font-size:14px;opacity:.75}
.stat b{font-size:28px;color:#e0454c;font-variant-numeric:tabular-nums}
.stat:last-child b{color:var(--blue)}
.msg{margin:0;min-height:2.6em;text-align:center;font-weight:700;font-size:16px;line-height:1.35;background:rgba(255,255,255,.55);border-radius:14px;padding:6px 10px;display:flex;align-items:center;justify-content:center}
.board-wrap{width:100%;display:flex;justify-content:center}
#board{width:min(100%,62dvh);aspect-ratio:1;touch-action:none;user-select:none;-webkit-user-select:none;outline:none;filter:drop-shadow(0 8px 0 rgba(120,80,20,.25))}
#board:focus-visible{outline:4px dashed var(--blue);outline-offset:4px;border-radius:24px}
.bg-cell{fill:var(--board);stroke:var(--board);stroke-width:2}
.bg-edge{fill:var(--board-edge)}
.hole{fill:var(--hole);stroke:#b97d22;stroke-width:3}
.hole-in{fill:#c0832a}
.peg{cursor:grab}
.peg .body{fill:url(#pegGrad);stroke:#b3283a;stroke-width:3}
.peg .shine{fill:#fff;opacity:.75}
.peg .eye{fill:#3b1f24}
.peg .mouth{fill:none;stroke:#3b1f24;stroke-width:4;stroke-linecap:round}
.peg .cheek{fill:#ff9db0;opacity:.8}
.peg{transition:transform .22s cubic-bezier(.3,1.4,.5,1),opacity .2s}
.peg.dragging{transition:none;cursor:grabbing}
.peg.out{opacity:0}
.peg.out .inner{transform:scale(.2);transform-origin:center;transform-box:fill-box}
.peg .inner{transition:transform .2s}
.peg.selected .inner{animation:wiggle .5s ease-in-out infinite;transform-origin:center;transform-box:fill-box}
.peg.selected .body{stroke:#ffd400;stroke-width:7}
.peg.hintfrom .body{stroke:#ffd400;stroke-width:7;animation:glow 0.9s ease-in-out infinite}
@keyframes wiggle{0%,100%{transform:scale(1.12) rotate(-6deg)}50%{transform:scale(1.18) rotate(6deg)}}
@keyframes glow{50%{stroke:#fff}}
.target .ring{fill:rgba(55,194,106,.28);stroke:var(--ok);stroke-width:6;stroke-dasharray:10 8;animation:pulse 1s ease-in-out infinite;transform-origin:center;transform-box:fill-box}
.target.hintto .ring{fill:rgba(255,212,0,.35);stroke:#f5a700}
.target{cursor:pointer}
@keyframes pulse{50%{transform:scale(1.12)}}
.cursor{fill:none;stroke:var(--blue);stroke-width:5;stroke-dasharray:12 8}
.arrow-line{stroke:var(--blue);stroke-width:12;stroke-linecap:round;opacity:.85}
.arrow-start{fill:none;stroke:var(--blue);stroke-width:7;stroke-dasharray:8 6}
.controls{display:grid;grid-template-columns:repeat(4,1fr);gap:8px}
.btn{border:0;border-radius:16px;min-height:52px;padding:8px 6px;font:inherit;font-weight:800;font-size:16px;color:#fff;background:#8b7cf6;box-shadow:0 4px 0 rgba(0,0,0,.18);cursor:pointer}
.btn:active{transform:translateY(3px);box-shadow:0 1px 0 rgba(0,0,0,.18)}
.btn:disabled{opacity:.45;cursor:not-allowed}
.btn.hint{background:#ffae1a;color:#4a3300}
.btn.tut{background:var(--blue)}
.btn.warn{background:#ff7b8c}
.btn.small{min-height:48px;font-size:15px}
.btn:focus-visible,.chip-btn:focus-visible{outline:4px solid #222;outline-offset:2px}
.tutorial{grid-template-columns:1fr;gap:8px;background:rgba(255,255,255,.6);border-radius:18px;padding:10px}
.tutorial[hidden]{display:none}
.tut-info{display:flex;flex-direction:column;gap:2px;text-align:center}
.tut-info b{font-size:18px}
.tut-info span{font-size:15px;line-height:1.4;min-height:2.8em}
.tut-row{display:grid;grid-template-columns:52px 1fr 1.2fr 1fr;gap:6px}
.foot{text-align:center;font-size:13px;opacity:.7}
.dlg{border:0;border-radius:24px;padding:20px;max-width:min(92vw,420px);background:var(--card);color:var(--ink);box-shadow:0 12px 40px rgba(0,0,0,.35)}
.dlg::backdrop{background:rgba(40,30,10,.45)}
.dlg h2{margin:0 0 10px;text-align:center}
.rules{padding-left:1.4em;line-height:1.9;font-size:17px;margin:0 0 8px}
.rank{background:#fff2bf;color:#3b2f2f;border-radius:16px;padding:8px 14px;margin-bottom:12px}
.rank p{margin:0 0 4px;font-weight:700}
.rank ul{margin:0;padding-left:1.2em;line-height:1.7}
.dlg form .btn{width:100%}
.result{text-align:center}
.badge{font-size:64px;line-height:1.1}
.res-actions{display:grid;gap:8px;margin-top:12px}
@media (min-width:560px){.res-actions{grid-template-columns:repeat(3,1fr)}}
@media (prefers-reduced-motion: reduce){
  *{animation:none!important;transition-duration:.01s!important}
}
.controls[hidden]{display:none}
