* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: system-ui, -apple-system, Segoe UI, sans-serif;
  color: #fff;
  background: radial-gradient(circle at center, #064b2d, #022b19);
}

.wrap{
  display: flex;
  justify-content: center;
}

.table{
  width: 360px;
  padding: 18px 14px 30px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.title{
  margin: 8px 0 14px;
  font-size: 22px;
  font-weight: 900;
}

.zone{ width: 100%; margin: 10px 0; }
.label{ color:#ffcc66; margin: 6px 0; font-weight: 800; }

.hand{
  width: 100%;
  display: flex;
  justify-content: center;
  gap: 12px;
}

.deck-row{
  margin: 14px 0 6px;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* ----- CARD ----- */
.card{
  width: 72px;
  height: 110px;
  position: relative;
  border-radius: 10px;
  border: 2px solid #f5c542;
  box-shadow: 0 8px 18px rgba(0,0,0,.45);
  perspective: 900px;
  overflow: hidden;
  background: rgba(0,0,0,.15); /* กันขอบดำแข็งๆ */
}

.card.deck{
  background: url("assets/cards/BACK.svg") center/cover no-repeat;
}

/* flip structure */
.card-inner{
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transition: transform .5s ease;
}

.card.flipped .card-inner{
  transform: rotateY(180deg);
}

.card-back, .card-front{
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  border-radius: 10px;
}

.card-back{
  background: url("assets/cards/BACK.svg") center/cover no-repeat;
}

.card-front{
  transform: rotateY(180deg);
  background: #fff; /* หน้าไพ่ขาว */
}

.card-front img{
  position: absolute;
  inset: 6px;
  width: calc(100% - 12px);
  height: calc(100% - 12px);
  object-fit: contain;
  display: block;
}

/* clickable */
.card.can-flip{ cursor: pointer; }

/* ----- ACTIONS ----- */
.actions{
  width: 100%;
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 12px;
}

button{
  padding: 12px 26px;
  border-radius: 26px;
  border: 0;
  font-size: 16px;
  font-weight: 900;
  background: #d4a017;
  color: #111;
}

button.secondary{
  background: rgba(255,255,255,.12);
  color: #fff;
  border: 1px solid rgba(255,255,255,.18);
}

button:disabled{
  opacity: .6;
}

.result{
  margin-top: 14px;
  font-size: 18px;
  font-weight: 900;
  text-align: center;
}

.hidden{ display: none; }

/* ----- FLYING CARD ----- */
.flying-card{
  position: fixed;
  width: 72px;
  height: 110px;
  border-radius: 10px;
  border: 2px solid #f5c542;
  background: url("assets/cards/BACK.svg") center/cover no-repeat;
  box-shadow: 0 16px 28px rgba(0,0,0,.55);
  z-index: 9999;
  pointer-events: none;
  transform-origin: top left;
  transition: transform .45s cubic-bezier(.25,.8,.25,1);
}

/* ===============================
   WIN EFFECT
================================ */

#result.win {
  border: 1px solid #ffd86b;
  background: linear-gradient(135deg, #2b2200, #3a2f00);
  box-shadow:
    0 0 12px rgba(255, 216, 107, 0.8),
    0 0 24px rgba(255, 216, 107, 0.4);
  animation: winPop 0.45s ease-out;
  text-align: center;
}

#result.win b {
  color: #ffd86b;
  font-size: 22px;
}

@keyframes winPop {
  0% {
    transform: scale(0.92);
    opacity: 0;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

/* ไพ่ผู้เล่นที่เป็นตัวชนะ */
.card.kicker.win {
  box-shadow:
    0 0 10px rgba(255, 215, 100, 0.9),
    0 0 18px rgba(255, 215, 100, 0.6);
  animation: glowPulse 1.2s ease-in-out infinite;
}

@keyframes glowPulse {
  0%, 100% { box-shadow: 0 0 10px rgba(255,215,100,0.6); }
  50% { box-shadow: 0 0 18px rgba(255,215,100,1); }
}
/* เงินรางวัลตอนชนะ */
.win-reward {
  margin-top: 6px;
  font-size: 26px;
  font-weight: bold;
  color: #ffd86b;
  text-shadow:
    0 0 6px rgba(255, 216, 107, 0.9),
    0 0 12px rgba(255, 216, 107, 0.5);
  animation: rewardPop 0.4s ease-out;
}

.win-reason {
  margin-top: 6px;
  font-size: 20px;
  opacity: 0.85;
}

@keyframes rewardPop {
  0% {
    transform: scale(0.85);
    opacity: 0;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

/* ===============================
   RULES BUTTON + MODAL
================================ */

.rules-btn{
  margin: 12px auto 0;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, .18);
  background: rgba(0, 0, 0, .18);
  color: #fff;
  cursor: pointer;
  font-weight: 700;
  letter-spacing: .2px;
}

.rules-btn:active{ transform: scale(.98); }
.rules-icon{
  width: 28px;
  height: 28px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  color: #ffd86b;
  background: rgba(255, 216, 107, .12);
  border: 1px solid rgba(255, 216, 107, .35);
}

.rules-modal.hidden{ display: none; }

.rules-modal{
  position: fixed;
  inset: 0;
  z-index: 9998;
}

.rules-backdrop{
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.55);
  backdrop-filter: blur(2px);
}

.rules-sheet{
  position: absolute;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: min(520px, 92vw);
  max-height: 82vh;
  overflow: hidden;
  border-radius: 20px 20px 0 0;
  border: 1px solid rgba(255,255,255,.15);
  background: rgba(8, 24, 14, .96);
  box-shadow: 0 -18px 40px rgba(0,0,0,.55);
}

.rules-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}


.rules-title-wrap{
  display: flex;
  align-items: center;
  gap: 10px;
}

.rules-badge{
  width: 34px;
  height: 34px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: rgba(255, 216, 107, .16);
  border: 1px solid rgba(255, 216, 107, .35);
}

.rules-title{
  font-weight: 900;
  font-size: 16px;
  line-height: 1.1;
}

.rules-subtitle{
  opacity: .85;
  font-size: 12px;
  margin-top: 3px;
}

.rules-close {
  width: 36px;
  height: 36px;

  display: flex;
  align-items: center;
  justify-content: center;

  border-radius: 50%;
  background: rgba(255, 215, 0, 0.15);
  border: 1px solid rgba(255, 215, 0, 0.4);

  color: #ffd966;
  font-size: 20px;
  font-weight: bold;

  cursor: pointer;
  flex-shrink: 0;
}

.rules-close:hover {
  background: rgba(255, 215, 0, 0.3);
}


.rules-body{
  padding: 14px;
  overflow: auto;
  max-height: calc(82vh - 64px);
}

.rules-section{ margin-bottom: 14px; }
.rules-h{
  font-weight: 900;
  margin-bottom: 8px;
  color: #ffd86b;
}

.rules-p{ opacity: .95; line-height: 1.45; }

.rules-ol{
  margin: 0;
  padding-left: 18px;
  line-height: 1.55;
}

.rules-table-wrap{
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 14px;
  overflow: hidden;
  background: rgba(0,0,0,.15);
}

.rules-table{
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.rules-table th,
.rules-table td{
  padding: 10px 10px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}

.rules-table th{
  text-align: left;
  font-weight: 900;
  background: rgba(255,255,255,.06);
}

.rules-table .amt{
  text-align: right;
  font-weight: 900;
  color: #ffd86b;
}

.rules-table tr:last-child td{ border-bottom: 0; }

.rules-table tr.bigwin td{
  background: rgba(255, 216, 107, .10);
}

.rules-note{
  margin-top: 10px;
  font-size: 12px;
  opacity: .85;
  line-height: 1.45;
}

.rules-ok{
  width: 100%;
  margin-top: 10px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid rgba(255, 216, 107, .35);
  background: rgba(255, 216, 107, .12);
  color: #ffd86b;
  font-weight: 900;
  cursor: pointer;
}
/* layout แถวไพ่ */
.hand-row{
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255,255,255,.08);
}

.hand-text{
  flex: 1;
  text-align: left;
  line-height: 1.4;
}

.hand-img{
  width: 96px;
  max-width: 40%;
  border-radius: 8px;
}

/* เงินรางวัล */
.reward-section .center{
  text-align: center;
}

.reward-row{
  display: flex;
  justify-content: space-between;
  padding: 8px 4px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}

.reward-row b{
  color: #ffd86b;
}

.reward-row.highlight{
  background: rgba(255,215,100,.12);
  border-radius: 10px;
  margin-top: 6px;
}
.hand-cards{
  display: flex;
  gap: 6px;
}

.hand-cards img{
  width: 48px;
  border-radius: 6px;
  background: antiquewhite;
  box-shadow: 0 2px 6px rgba(0,0,0,.3);
}

.hand-row.big{
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
