:root{--red:#e53935;--green:#2e9e45;--yellow:#fbc02d;--blue:#1e88e5;--ink:#1b1464;--bs:min(calc(100vw - 12px),calc(100dvh - 215px))}
*{box-sizing:border-box;-webkit-tap-highlight-color:transparent;user-select:none;-webkit-user-select:none}
html,body{margin:0;height:100%;overflow:hidden;background:#1b1464;font-family:"Segoe UI",Tahoma,"Noto Naskh Arabic","Noto Sans Arabic",system-ui,sans-serif;color:#fff;touch-action:manipulation}
#app{height:100dvh;position:relative;background:radial-gradient(circle at 50% 0,#3a2fa8 0,#1b1464 70%)}
[hidden]{display:none!important}
.screen{position:absolute;inset:0;display:flex;flex-direction:column;align-items:center;padding:max(10px,env(safe-area-inset-top)) 16px max(12px,env(safe-area-inset-bottom));overflow:auto}
button{font-family:inherit;cursor:pointer;border:0;color:#fff}
.topbtns{align-self:stretch;display:flex;justify-content:space-between}
.ibtn{width:44px;height:44px;border-radius:50%;background:rgba(255,255,255,.16);font-size:18px;font-weight:700}
.logo{text-align:center;margin:3vh 0 2vh}
.logo h1{font-size:68px;margin:6px 0 0;letter-spacing:0;text-shadow:0 4px 0 #0e0a40,0 0 24px #ffd54f66}
.logo p{margin:2px 0 0;opacity:.85;font-size:18px}
.logo-dice{width:84px;height:84px;margin:0 auto;background:#fff;border-radius:18px;display:grid;grid-template:1fr 1fr/1fr 1fr;gap:10px;padding:16px;transform:rotate(-8deg);box-shadow:0 8px 0 #0e0a40;animation:bob 2.4s ease-in-out infinite}
.logo-dice i{border-radius:50%}
.logo-dice i:nth-child(1){background:var(--red)}.logo-dice i:nth-child(2){background:var(--green)}.logo-dice i:nth-child(3){background:var(--blue)}.logo-dice i:nth-child(4){background:var(--yellow)}
@keyframes bob{50%{transform:rotate(6deg) translateY(-8px)}}
.menubtns{width:100%;max-width:380px;display:flex;flex-direction:column;gap:12px;margin-top:auto;margin-bottom:auto}
.big{height:62px;border-radius:18px;font-size:22px;font-weight:800;box-shadow:0 5px 0 rgba(0,0,0,.35);width:100%}
.big:active,.mid:active{transform:translateY(3px);box-shadow:0 2px 0 rgba(0,0,0,.35)}
.big.green{background:#2e9e45}.big.blue{background:#1e88e5}.big.yellow{background:#f9a825;color:#2b1d00}
.row2{display:flex;gap:10px}
.mid{flex:1;height:50px;border-radius:14px;background:rgba(255,255,255,.18);font-size:17px;font-weight:700;box-shadow:0 4px 0 rgba(0,0,0,.25)}
.back{align-self:flex-start;background:none;font-size:18px;padding:10px 4px;opacity:.9}
#setup{align-items:center;text-align:center}
#setup h2{font-size:30px;margin:14px 0 4px}
#setup p{opacity:.85;margin:0 0 18px}
.counts{display:flex;gap:12px;margin-bottom:28px}
.cnt{width:76px;height:96px;border-radius:18px;background:rgba(255,255,255,.14);font-size:34px;font-weight:800;border:3px solid transparent;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:4px}
.cnt small{font-size:13px;font-weight:600;opacity:.85}
.cnt.sel{background:#fff;color:var(--ink);border-color:#ffd54f}
#setup .big{max-width:380px;margin-top:auto;margin-bottom:6vh}

/* game */
#game{padding:0;justify-content:flex-start}
#bar{width:100%;display:flex;align-items:center;gap:8px;padding:max(8px,env(safe-area-inset-top)) 8px 6px;height:58px}
#chips{flex:1;display:flex;gap:6px;justify-content:center}
.chip{flex:1;max-width:84px;min-width:0;border-radius:14px;padding:3px 4px;background:rgba(255,255,255,.12);text-align:center;font-size:12px;font-weight:700;border:2px solid transparent;opacity:.7;line-height:1.2;overflow:hidden;white-space:nowrap;text-overflow:ellipsis}
.chip b{display:block;font-size:11px;font-weight:600;opacity:.9}
.chip .dot{display:inline-block;width:10px;height:10px;border-radius:50%;margin:0 3px;vertical-align:-1px}
.chip.on{opacity:1;background:#fff;color:var(--ink);transform:scale(1.07);box-shadow:0 0 14px #fff8}
#stage{flex:1;display:flex;flex-direction:column;align-items:center;justify-content:flex-start;width:100%;min-height:0}
#boardwrap{width:var(--bs);height:var(--bs);margin-top:2px;flex:none;position:relative}
#board{position:relative;width:100%;height:100%;display:grid;grid-template:repeat(15,1fr)/repeat(15,1fr);background:#fff;border-radius:10px;overflow:hidden;box-shadow:0 8px 0 #0e0a40,0 0 0 4px #fff}
#board.shake{animation:shake .3s}
@keyframes shake{25%{transform:translate(-3px,2px)}50%{transform:translate(3px,-2px)}75%{transform:translate(-2px,-1px)}}
.yard{position:absolute;width:40%;height:40%}
.yard i{position:absolute;inset:16%;background:#fff;border-radius:14%;box-shadow:inset 0 0 0 2px rgba(0,0,0,.15)}
.yard.c0{left:0;top:0;background:var(--red)}.yard.c1{right:0;top:0;background:var(--green)}.yard.c2{right:0;bottom:0;background:var(--yellow)}.yard.c3{left:0;bottom:0;background:var(--blue)}
.spot{position:absolute;width:7.2%;aspect-ratio:1;border-radius:50%;transform:translate(-50%,-50%);box-shadow:inset 0 2px 4px rgba(0,0,0,.35)}
.cell{background:#fff;border:.5px solid rgba(0,0,0,.35);display:flex;align-items:center;justify-content:center;font-size:calc(var(--bs)/15*.62);line-height:1;color:rgba(0,0,0,.45)}
.cell.c0{background:var(--red);color:#fff9}.cell.c1{background:var(--green);color:#fff9}.cell.c2{background:var(--yellow);color:#0006}.cell.c3{background:var(--blue);color:#fff9}
.center{position:absolute;left:40%;top:40%;width:20%;height:20%;background:conic-gradient(from -45deg,var(--green) 0 25%,var(--yellow) 0 50%,var(--blue) 0 75%,var(--red) 0 100%);box-shadow:inset 0 0 0 1px rgba(0,0,0,.35)}
.piece{position:absolute;width:5.6%;aspect-ratio:1;transform:translate(-50%,-50%);transition:left .13s linear,top .13s linear,transform .13s;z-index:5;pointer-events:none}
.piece .pb{position:absolute;inset:0;border-radius:50%;background:radial-gradient(circle at 35% 30%,#fff9 0,#fff0 38%),var(--pc);box-shadow:0 2px 0 rgba(0,0,0,.45),inset 0 0 0 2.5px #fff,inset 0 -3px 0 rgba(0,0,0,.25)}
.piece.fly{transition:left .5s cubic-bezier(.3,.9,.4,1),top .5s cubic-bezier(.3,.9,.4,1),transform .3s}
.piece.hop .pb{animation:hop .16s}
@keyframes hop{50%{transform:translateY(-34%) scale(1.15)}}
.piece.can{pointer-events:auto;z-index:20;cursor:pointer}
.piece.can .pb{animation:pulse .7s ease-in-out infinite;box-shadow:0 0 0 3px #fff,0 0 12px 4px #fff,0 2px 0 rgba(0,0,0,.45)}
.piece.can::after{content:"";position:absolute;inset:-35%;border-radius:50%}
@keyframes pulse{50%{transform:scale(1.18)}}
.dest{position:absolute;width:5.6%;aspect-ratio:1;transform:translate(-50%,-50%);border-radius:50%;border:3px dashed #fff;background:rgba(255,255,255,.28);z-index:15;cursor:pointer;animation:spin 3s linear infinite}
@keyframes spin{to{transform:translate(-50%,-50%) rotate(360deg)}}
.fx{position:absolute;pointer-events:none;z-index:30;width:0;height:0}
.fx span{position:absolute;width:9px;height:9px;margin:-4px;border-radius:50%;animation:burst .6s ease-out forwards}
@keyframes burst{to{transform:translate(var(--dx),var(--dy)) scale(.2);opacity:0}}
.fx .ring{width:30px;height:30px;margin:-15px;background:none;border:4px solid #fff;animation:ring .5s ease-out forwards}
@keyframes ring{from{transform:scale(.2);opacity:1}to{transform:scale(2.4);opacity:0}}

#dock{width:100%;flex:1;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:6px;min-height:0;padding:4px 12px}
#msg{font-size:17px;font-weight:800;min-height:24px;text-align:center}
#hint{font-size:14px;opacity:.85;min-height:20px;text-align:center}
#die{width:84px;height:84px;border-radius:20px;background:#fff;padding:12px;box-shadow:0 6px 0 rgba(0,0,0,.4),0 0 0 5px var(--turn,#fff);position:relative;flex:none}
#die .face{display:grid;grid-template:repeat(3,1fr)/repeat(3,1fr);width:100%;height:100%}
#die .face i{border-radius:50%;background:#222;margin:12%}
#die.ready{animation:ready 1s ease-in-out infinite}
@keyframes ready{50%{transform:scale(1.1) rotate(-4deg)}}
#die.rolling{animation:roll .12s linear infinite}
@keyframes roll{0%{transform:rotate(0) translateY(0)}50%{transform:rotate(180deg) translateY(-12px)}100%{transform:rotate(360deg) translateY(0)}}
#die.off{opacity:.9}

/* modal */
#modal{position:absolute;inset:0;background:rgba(10,6,50,.78);display:flex;align-items:center;justify-content:center;z-index:50;padding:16px}
.card{background:#fff;color:var(--ink);border-radius:22px;padding:20px;width:100%;max-width:420px;max-height:90dvh;overflow:auto;box-shadow:0 8px 0 rgba(0,0,0,.3)}
.card h3{margin:0 0 10px;font-size:26px;text-align:center}
.card p,.card li{font-size:16px;line-height:1.7;margin:6px 0}
.card ul{padding-inline-start:20px;margin:6px 0}
.card .btns{display:flex;flex-direction:column;gap:10px;margin-top:14px}
.card .btns button{height:50px;border-radius:14px;font-size:18px;font-weight:800;background:#1e88e5}
.card .btns button.g{background:#2e9e45}.card .btns button.r{background:#e53935}.card .btns button.x{background:#e8e6f6;color:var(--ink)}
.card .set{display:flex;justify-content:space-between;align-items:center;padding:10px 0;border-bottom:1px solid #eee;font-size:18px;font-weight:700}
.card .set button{min-width:90px;height:40px;border-radius:12px;background:#1e88e5;font-weight:800;font-size:16px}
.card .set button.offb{background:#9e9e9e}
.stat{display:flex;justify-content:space-between;font-size:18px;padding:8px 0;border-bottom:1px solid #eee}
#toast{position:absolute;left:50%;top:80px;transform:translateX(-50%);background:#fff;color:var(--ink);font-weight:800;padding:10px 18px;border-radius:20px;z-index:60;box-shadow:0 4px 0 rgba(0,0,0,.3);max-width:90%;text-align:center;font-size:16px;animation:pop .25s}
@keyframes pop{from{transform:translateX(-50%) scale(.7);opacity:0}}
.conf{position:absolute;top:-10px;width:10px;height:14px;z-index:70;animation:fall 2.4s linear forwards;pointer-events:none}
@keyframes fall{to{transform:translateY(105dvh) rotate(720deg)}}
.crown{font-size:60px;text-align:center;line-height:1}

@media (orientation:landscape) and (max-height:520px){
 :root{--bs:calc(100dvh - 80px)}
 #stage{flex-direction:row;justify-content:center;gap:12px;align-items:flex-start}
 #dock{width:auto;flex:none;height:var(--bs);min-width:150px}
 #bar{height:50px}
}
@media (prefers-reduced-motion:reduce){.logo-dice,#die.ready,.piece.can .pb,.dest{animation:none}}
