:root{
  --bg:#0f1220;
  --panel:#171a2f;
  --line:#2a2e55;
  --text:#eaeaff;
  --accent:#ffcc66;
}

*{ box-sizing:border-box; }

body{
  margin:0;
  background:var(--bg);
  color:var(--text);
  font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;
}

.app{
  max-width:420px;
  margin:auto;
  padding:14px;
}

.header{
  margin-bottom:12px;
}
.title-row{
  display:flex;
  justify-content:space-between;
  align-items:center;
}
.badge{
  background:#2a2e55;
  padding:4px 10px;
  border-radius:999px;
}

.panel{
  background:var(--panel);
  border:1px solid var(--line);
  border-radius:14px;
  padding:14px;
  margin-bottom:12px;
}

.pick-grid{
  display:grid;
  grid-template-columns:repeat(3,1fr);
  gap:10px;
}

.pick-grid button{
  background:#11132a;
  border:1px solid var(--line);
  border-radius:12px;
  padding:10px 6px;
  color:#fff;
  cursor:pointer;
}
.pick-grid button.active{
  border-color:var(--accent);
  box-shadow:0 0 0 2px rgba(255,204,102,.3);
}
.pick-grid img{
  width:100%;
  max-width:60px;
}

.dice-row{
  display:flex;
  justify-content:space-between;
  margin:14px 0;
}
.die{
  width:30%;
  background:#0c0e1c;
  border-radius:12px;
  padding:10px;
}
.die img{
  width:100%;
}


.roll-btn{
  width:100%;
  padding:14px;
  font-size:18px;
  background:linear-gradient(180deg,#ffcc66,#e0a93d);
  border:none;
  border-radius:14px;
  cursor:pointer;

  /* 🔥 กันคลิกพัง */
  position:relative;
  z-index:50;
  pointer-events:auto;
}

.roll-btn:disabled{
  opacity:.5;
  cursor:not-allowed;
}

.result{
  margin-top:10px;
  text-align:center;
}

.dice-row.rolling{
  pointer-events:none;
}

.roll-btn{
  pointer-events:auto;
  position:relative;
  z-index:50;
}
.toast{
  position:fixed;
  bottom:20px;
  left:50%;
  transform:translateX(-50%);
  background:#222;
  padding:10px 16px;
  border-radius:20px;
  opacity:0;
  transition:.2s;
}
.toast.show{ opacity:1; }

.payout{
  margin-top:12px;
  padding:12px;
  border-radius:12px;
  background:#101326;
  border:1px solid var(--line);
  font-size:14px;
}

.payout-title{
  font-weight:700;
  margin-bottom:6px;
  color:var(--accent);
}

.payout-row{
  display:flex;
  justify-content:space-between;
  margin:4px 0;
}

.payout-note{
  margin-top:6px;
  font-size:12px;
  opacity:.7;
}

@keyframes spin{
  from{ transform:rotate(0deg); }
  to{ transform:rotate(360deg); }
}

.die.spinning img{
  animation: spin .6s linear infinite;
}

.how-btn{
  width:100%;
  margin-top:10px;
  padding:12px;
  border-radius:14px;
  border:1px solid var(--line);
  background:#11132a;
  color:var(--text);
  font-size:16px;
  cursor:pointer;
}
.how-btn:active{ transform: scale(.99); }

.modal.hidden{ display:none; }

.modal{
  position:fixed;
  inset:0;
  z-index:9999;
}

.modal-backdrop{
  position:absolute;
  inset:0;
  background:rgba(0,0,0,.6);
  backdrop-filter: blur(6px);
}

.modal-card{
  position:relative;
  width:min(520px, 92vw);
  max-height: 86vh;
  overflow:auto;
  margin: 7vh auto 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0,0,0,.6);
}

.modal-head{
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding:14px 14px 10px;
  border-bottom:1px solid var(--line);
}

.modal-title{
  font-weight:700;
  color: var(--accent);
}

.modal-close{
  background:transparent;
  border:none;
  color:var(--text);
  font-size:18px;
  cursor:pointer;
}

.modal-body{
  padding:14px;
  line-height:1.5;
}

.modal-body h3{
  margin: 10px 0 6px;
  font-size: 16px;
  color: var(--accent);
}

.modal-body p, .modal-body li{
  font-size: 14px;
  opacity:.95;
}

.modal-payout{
  margin-top:8px;
  padding:10px;
  border:1px solid var(--line);
  border-radius:12px;
  background:#101326;
  font-size:14px;
}

.modal-note{
  margin-top:10px;
  font-size:12px;
  opacity:.7;
}

.modal-foot{
  padding:12px 14px 14px;
  border-top:1px solid var(--line);
}

.modal-ok{
  width:100%;
  padding:12px;
  border:none;
  border-radius:14px;
  background: linear-gradient(180deg,#ffcc66,#e0a93d);
  font-size:16px;
  cursor:pointer;
}

.example{
  margin-top:10px;
}

.example-row{
  margin-bottom:12px;
  padding:10px;
  border:1px solid var(--line);
  border-radius:12px;
  background:#101326;
}

.example-text{
  font-size:14px;
  margin-bottom:6px;
}

.dice-example{
  display:flex;
  gap:8px;
  margin:6px 0;
}

.dice-example img{
  width:42px;
  height:42px;
  background:#0c0e1c;
  border-radius:8px;
  padding:4px;
}

.example-result{
  font-size:14px;
  color:var(--accent);
  font-weight:600;
}

.prob-box{
  margin-top:8px;
}

.prob-row{
  margin-bottom:8px;
  padding:8px 10px;
  background:#101326;
  border:1px solid var(--line);
  border-radius:10px;
  font-size:14px;
}

.prob-row span{
  display:block;
  margin-top:2px;
  opacity:.9;
}

.prob-note{
  margin-top:8px;
  font-size:12px;
  opacity:.7;
}
