/* sicbo — 骰寶 */

.app {
  max-width: 720px;
  padding-bottom: 32px;
}

/* ── HUD ───────────────────────────────────────────────── */
.hud {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin: 12px 0;
}
.hud-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 8px 10px;
  text-align: center;
  box-shadow: var(--shadow-sm);
}
.hud-label {
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.5px;
}
.hud-value {
  font-size: 22px;
  font-weight: 800;
  color: var(--accent);
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
  transition: color 0.15s, transform 0.15s;
}
.hud-value.hud-pulse {
  animation: hud-pulse 0.5s ease;
}
@keyframes hud-pulse {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.18); color: gold; }
  100% { transform: scale(1); }
}

/* ── 3D dice ───────────────────────────────────────────── */
.dice-stage {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 28px;
  padding: 28px 0 20px;
  perspective: 600px;
  min-height: 130px;
  background:
    radial-gradient(ellipse at center bottom, rgba(0,0,0,0.18), transparent 60%),
    linear-gradient(180deg, transparent, rgba(0,0,0,0.04));
  border-radius: var(--radius-lg);
  margin-bottom: 14px;
}
.die {
  width: 64px;
  height: 64px;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.9s cubic-bezier(.18,.7,.25,1);
  /* DO NOT add `filter` (drop-shadow / blur / etc.) here — `filter` forces a
     new stacking context that flattens preserve-3d descendants, so the cube
     collapses and only f1 is ever visible. Shadow is handled by the parent
     .dice-stage's radial gradient + each face's box-shadow below. */
}
.die .face {
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}
.die-faces { transform-style: preserve-3d; position: absolute; inset: 0; }

/* Pre-roll wobble — shake the WHOLE dice-stage container rather than
   individual dice (those carry inline 3D transform that we mustn't override). */
.dice-stage.pre-roll-shake {
  animation: dice-stage-shake 0.2s ease-in-out;
}
@keyframes dice-stage-shake {
  0%   { transform: translate(0, 0); }
  25%  { transform: translate(-4px, -2px); }
  50%  { transform: translate(4px, -2px); }
  75%  { transform: translate(-3px, 3px); }
  100% { transform: translate(0, 0); }
}
/* Landed flash — short bright pulse after tumble settles. Uses filter ONLY
   when not preserving 3D (after the rolling/transition finishes). */
.die.landed .face {
  animation: die-land-flash 0.32s cubic-bezier(.2,1.4,.5,1);
}
@keyframes die-land-flash {
  0%   { box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15); }
  40%  { box-shadow: 0 0 12px gold, 0 1px 2px rgba(0, 0, 0, 0.15); }
  100% { box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15); }
}
.die .face {
  position: absolute;
  inset: 0;
  background: #fefefe;
  border: 2px solid #d8d8d8;
  border-radius: 10px;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: 1fr 1fr 1fr;
  padding: 7px;
  box-sizing: border-box;
  backface-visibility: hidden;
}
.die .face .pip {
  width: 10px;
  height: 10px;
  background: #222;
  border-radius: 50%;
  align-self: center;
  justify-self: center;
  display: block;
}

/* Pip placements per face (3×3 grid; rows = top/mid/bot, cols = left/mid/right) */
.die .face.f1 .pip:nth-child(1) { grid-area: 2 / 2; background: #c0392b; width: 14px; height: 14px; }

.die .face.f2 .pip:nth-child(1) { grid-area: 1 / 1; }
.die .face.f2 .pip:nth-child(2) { grid-area: 3 / 3; }

.die .face.f3 .pip:nth-child(1) { grid-area: 1 / 1; }
.die .face.f3 .pip:nth-child(2) { grid-area: 2 / 2; }
.die .face.f3 .pip:nth-child(3) { grid-area: 3 / 3; }

.die .face.f4 .pip:nth-child(1) { grid-area: 1 / 1; }
.die .face.f4 .pip:nth-child(2) { grid-area: 1 / 3; }
.die .face.f4 .pip:nth-child(3) { grid-area: 3 / 1; }
.die .face.f4 .pip:nth-child(4) { grid-area: 3 / 3; }

.die .face.f5 .pip:nth-child(1) { grid-area: 1 / 1; }
.die .face.f5 .pip:nth-child(2) { grid-area: 1 / 3; }
.die .face.f5 .pip:nth-child(3) { grid-area: 2 / 2; }
.die .face.f5 .pip:nth-child(4) { grid-area: 3 / 1; }
.die .face.f5 .pip:nth-child(5) { grid-area: 3 / 3; }

.die .face.f6 .pip:nth-child(1) { grid-area: 1 / 1; }
.die .face.f6 .pip:nth-child(2) { grid-area: 1 / 3; }
.die .face.f6 .pip:nth-child(3) { grid-area: 2 / 1; }
.die .face.f6 .pip:nth-child(4) { grid-area: 2 / 3; }
.die .face.f6 .pip:nth-child(5) { grid-area: 3 / 1; }
.die .face.f6 .pip:nth-child(6) { grid-area: 3 / 3; }

/* Cube face transforms — must come AFTER per-face pip rules so they don't
   override transform. (They use the same .die .face.fN selector but only
   set `transform`, no conflict with pip positioning.) */
.die .face.f1 { transform: translateZ(32px); }
.die .face.f2 { transform: rotateY(180deg) translateZ(32px); }
.die .face.f3 { transform: rotateY(90deg)  translateZ(32px); }
.die .face.f4 { transform: rotateY(-90deg) translateZ(32px); }
.die .face.f5 { transform: rotateX(90deg)  translateZ(32px); }
.die .face.f6 { transform: rotateX(-90deg) translateZ(32px); }

/* ── Chip selector ─────────────────────────────────────── */
.chip-row {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
  margin: 6px 0 10px;
}
.chip-btn {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 3px dashed #fff;
  background: radial-gradient(circle at 30% 30%, #f39c12, #b9770e);
  color: #fff;
  font-weight: 900;
  font-size: 16px;
  cursor: pointer;
  box-shadow: 0 3px 6px rgba(0,0,0,0.3);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  font-variant-numeric: tabular-nums;
}
.chip-btn[data-chip="50"]   { background: radial-gradient(circle at 30% 30%, #16a085, #0e6655); }
.chip-btn[data-chip="100"]  { background: radial-gradient(circle at 30% 30%, #2980b9, #1b4f72); }
.chip-btn[data-chip="500"]  { background: radial-gradient(circle at 30% 30%, #8e44ad, #5b2c6f); }
.chip-btn[data-chip="1000"] { background: radial-gradient(circle at 30% 30%, #c0392b, #78281f); font-size: 14px; }
.chip-btn.allin {
  background: linear-gradient(135deg, #ffd700, #b8860b);
  color: #1a1a1a;
  font-size: 14px;
  letter-spacing: 1px;
  border-style: solid;
  border-color: #fff5b8;
}
.chip-btn:hover { transform: translateY(-2px); box-shadow: 0 6px 10px rgba(0,0,0,0.35); }
.chip-btn.active {
  transform: translateY(-3px) scale(1.08);
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* ── Action buttons ────────────────────────────────────── */
.action-row {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin: 10px 0 18px;
}
.action-row .btn {
  min-width: 110px;
}
.action-row .btn.primary {
  background: linear-gradient(180deg, #e74c3c, #c0392b);
  color: #fff;
  border: none;
  font-weight: 700;
  animation: sicbo-roll-glow 1.6s ease-in-out infinite alternate;
}
@keyframes sicbo-roll-glow {
  0%   { box-shadow: 0 0 0 0 rgba(255, 215, 0, 0); }
  100% { box-shadow: 0 0 18px 4px rgba(255, 215, 0, 0.6); }
}
.action-row .btn.primary:disabled {
  background: var(--btn-bg);
  color: var(--text-muted);
  cursor: not-allowed;
  filter: grayscale(0.4);
  animation: none;
}

/* ── Bet table ─────────────────────────────────────────── */
.bet-table {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.section-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 8px;
  margin-bottom: -2px;
  letter-spacing: 0.5px;
}
.bet-row { display: grid; gap: 6px; }
.bet-row.grid-6 { grid-template-columns: repeat(6, 1fr); }
.bet-row.grid-7 { grid-template-columns: repeat(7, 1fr); }
.bet-row.grid-5 { grid-template-columns: repeat(5, 1fr); }

.bet-cell {
  position: relative;
  background: linear-gradient(180deg, #2e7d32, #1b5e20);
  color: #fff;
  border: 2px solid rgba(255,255,255,0.15);
  border-radius: var(--radius-sm);
  padding: 8px 4px;
  text-align: center;
  cursor: pointer;
  user-select: none;
  transition: transform 0.1s ease, box-shadow 0.1s ease, border-color 0.1s ease;
  min-height: 56px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.bet-cell:hover { transform: translateY(-1px); box-shadow: 0 4px 8px rgba(0,0,0,0.25); }
.bet-cell.has-bet { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(255,255,255,0.2) inset; }
.bet-cell.win {
  animation: win-pulse 0.7s ease-out;
  border-color: gold;
}
.bet-cell.lose { opacity: 0.55; }
@keyframes win-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(255, 215, 0, 0.8); }
  100% { box-shadow: 0 0 0 18px rgba(255, 215, 0, 0); }
}

/* Floating "+N" per winning bet cell */
.bet-float {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 900;
  color: gold;
  text-shadow: 0 2px 4px rgba(0,0,0,0.8), 0 0 8px gold;
  pointer-events: none;
  animation: bet-float 1.4s cubic-bezier(.2,.7,.3,1) forwards;
  z-index: 10;
  letter-spacing: 1px;
  font-variant-numeric: tabular-nums;
}
@keyframes bet-float {
  0%   { opacity: 0; transform: translateY(0) scale(0.5); }
  20%  { opacity: 1; transform: translateY(-4px) scale(1.2); }
  100% { opacity: 0; transform: translateY(-44px) scale(0.9); }
}

/* Gold coin shower bursting from the dice stage */
.coin {
  position: absolute;
  width: 16px;
  height: 16px;
  background: radial-gradient(circle at 30% 30%, #fff5b8, #e0a800 60%, #b8860b);
  border-radius: 50%;
  box-shadow: 0 0 6px rgba(255, 215, 0, 0.85), inset 0 -2px 3px rgba(0,0,0,0.25);
  transform: translate(-50%, -50%);
  animation: coin-fall 1.5s cubic-bezier(.5, .1, .8, 1) forwards;
  pointer-events: none;
  z-index: 6;
  will-change: transform, opacity;
}
@keyframes coin-fall {
  0%   { transform: translate(-50%, -50%) scale(0.4) rotate(0deg); opacity: 0; }
  18%  { transform: translate(-50%, -50%) scale(1.15) rotate(120deg); opacity: 1; }
  100% { transform: translate(calc(-50% + var(--dx, 0px)), calc(-50% + var(--dy, 100px))) scale(0.85) rotate(720deg); opacity: 0; }
}

/* Screen shake on a triple win — dramatic but short */
body.sicbo-triple-shake { animation: sicbo-body-shake 0.9s cubic-bezier(.36,.07,.19,.97); }
@keyframes sicbo-body-shake {
  0%, 100% { transform: translate(0, 0); }
  10% { transform: translate(-9px, 4px); }
  20% { transform: translate(7px, -3px); }
  30% { transform: translate(-6px, 6px); }
  40% { transform: translate(5px, -5px); }
  55% { transform: translate(-4px, 3px); }
  70% { transform: translate(3px, -2px); }
  85% { transform: translate(-2px, 1px); }
}

.bet-cell.big {
  min-height: 78px;
  background: linear-gradient(180deg, #c0392b, #922b21);
}
.bet-cell.big:nth-of-type(1) {
  background: linear-gradient(180deg, #2c3e50, #1c2833);
}

.bet-label { font-size: 22px; font-weight: 900; letter-spacing: 4px; }
.bet-sub { font-size: 11px; opacity: 0.85; margin-top: 2px; }
.bet-pay { font-size: 11px; opacity: 0.85; }
.bet-amt {
  position: absolute;
  top: 2px;
  right: 4px;
  font-size: 11px;
  font-weight: 800;
  color: gold;
  background: rgba(0,0,0,0.55);
  border-radius: 8px;
  padding: 1px 6px;
  min-width: 18px;
  display: none;
  font-variant-numeric: tabular-nums;
}
.bet-amt.show { display: inline-block; }

/* Total cell payout label */
.bet-cell.total .bet-pay {
  font-size: 10px;
}
.bet-cell.total .bet-label {
  font-size: 16px;
  letter-spacing: 0;
}

/* Combo cell — two pip badges side by side */
.bet-cell.combo {
  flex-direction: row;
  gap: 4px;
  min-height: 48px;
}
.combo-pip {
  width: 18px; height: 18px;
  border-radius: 4px;
  background: #fff;
  display: inline-block;
  background-repeat: no-repeat;
  background-size: 6px 6px;
}
.combo-pip.cp1 { background-image: radial-gradient(circle, #c0392b 50%, transparent 55%); background-size: 8px 8px; background-position: center; }
.combo-pip.cp2 { background-image: radial-gradient(circle, #222 50%, transparent 55%), radial-gradient(circle, #222 50%, transparent 55%); background-position: 22% 22%, 78% 78%; }
.combo-pip.cp3 { background-image: radial-gradient(circle, #222 50%, transparent 55%), radial-gradient(circle, #222 50%, transparent 55%), radial-gradient(circle, #222 50%, transparent 55%); background-position: 22% 22%, 50% 50%, 78% 78%; }
.combo-pip.cp4 { background-image: radial-gradient(circle, #222 50%, transparent 55%), radial-gradient(circle, #222 50%, transparent 55%), radial-gradient(circle, #222 50%, transparent 55%), radial-gradient(circle, #222 50%, transparent 55%); background-position: 22% 22%, 78% 22%, 22% 78%, 78% 78%; }
.combo-pip.cp5 { background-image: radial-gradient(circle, #222 50%, transparent 55%), radial-gradient(circle, #222 50%, transparent 55%), radial-gradient(circle, #222 50%, transparent 55%), radial-gradient(circle, #222 50%, transparent 55%), radial-gradient(circle, #222 50%, transparent 55%); background-position: 22% 22%, 78% 22%, 50% 50%, 22% 78%, 78% 78%; }
.combo-pip.cp6 { background-image: radial-gradient(circle, #222 50%, transparent 55%), radial-gradient(circle, #222 50%, transparent 55%), radial-gradient(circle, #222 50%, transparent 55%), radial-gradient(circle, #222 50%, transparent 55%), radial-gradient(circle, #222 50%, transparent 55%), radial-gradient(circle, #222 50%, transparent 55%); background-position: 22% 25%, 78% 25%, 22% 50%, 78% 50%, 22% 75%, 78% 75%; }

/* pip-mini — used in triple/pair/single cells. Reuses combo-pip's pip patterns. */
.pip-mini {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  background: #fff;
  background-repeat: no-repeat;
  background-size: 8px 8px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}
.pip-mini.p1 { background-image: radial-gradient(circle, #c0392b 50%, transparent 55%); background-size: 11px 11px; background-position: center; }
.pip-mini.p2 { background-image: radial-gradient(circle, #222 50%, transparent 55%), radial-gradient(circle, #222 50%, transparent 55%); background-size: 8px 8px, 8px 8px; background-position: 22% 22%, 78% 78%; }
.pip-mini.p3 { background-image: radial-gradient(circle, #222 50%, transparent 55%), radial-gradient(circle, #222 50%, transparent 55%), radial-gradient(circle, #222 50%, transparent 55%); background-size: 8px 8px, 8px 8px, 8px 8px; background-position: 22% 22%, 50% 50%, 78% 78%; }
.pip-mini.p4 { background-image: radial-gradient(circle, #222 50%, transparent 55%), radial-gradient(circle, #222 50%, transparent 55%), radial-gradient(circle, #222 50%, transparent 55%), radial-gradient(circle, #222 50%, transparent 55%); background-size: 8px 8px, 8px 8px, 8px 8px, 8px 8px; background-position: 22% 22%, 78% 22%, 22% 78%, 78% 78%; }
.pip-mini.p5 { background-image: radial-gradient(circle, #222 50%, transparent 55%), radial-gradient(circle, #222 50%, transparent 55%), radial-gradient(circle, #222 50%, transparent 55%), radial-gradient(circle, #222 50%, transparent 55%), radial-gradient(circle, #222 50%, transparent 55%); background-size: 8px 8px, 8px 8px, 8px 8px, 8px 8px, 8px 8px; background-position: 22% 22%, 78% 22%, 50% 50%, 22% 78%, 78% 78%; }
.pip-mini.p6 { background-image: radial-gradient(circle, #222 50%, transparent 55%), radial-gradient(circle, #222 50%, transparent 55%), radial-gradient(circle, #222 50%, transparent 55%), radial-gradient(circle, #222 50%, transparent 55%), radial-gradient(circle, #222 50%, transparent 55%), radial-gradient(circle, #222 50%, transparent 55%); background-size: 8px 8px, 8px 8px, 8px 8px, 8px 8px, 8px 8px, 8px 8px; background-position: 22% 25%, 78% 25%, 22% 50%, 78% 50%, 22% 75%, 78% 75%; }

.legend {
  margin-top: 18px;
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.5;
}

/* Last-result label colour states */
#last-result.win  { color: #2ecc71; }
#last-result.lose { color: #e74c3c; }

/* Mobile tweaks */
@media (max-width: 520px) {
  .die { width: 52px; height: 52px; }
  .die .face { padding: 5px; border-radius: 8px; }
  .die .face .pip { width: 8px; height: 8px; }
  .die .face.f1 .pip:nth-child(1) { width: 12px; height: 12px; }
  .die .face.f1 { transform: translateZ(26px); }
  .die .face.f2 { transform: rotateY(180deg) translateZ(26px); }
  .die .face.f3 { transform: rotateY(90deg)  translateZ(26px); }
  .die .face.f4 { transform: rotateY(-90deg) translateZ(26px); }
  .die .face.f5 { transform: rotateX(90deg)  translateZ(26px); }
  .die .face.f6 { transform: rotateX(-90deg) translateZ(26px); }
  .dice-stage { gap: 18px; perspective: 480px; }
  .bet-row.grid-7 { grid-template-columns: repeat(5, 1fr); }
  .bet-row.grid-5 { grid-template-columns: repeat(3, 1fr); }
  .bet-cell { min-height: 50px; padding: 6px 2px; }
  .bet-cell.big { min-height: 70px; }
  .bet-label { font-size: 18px; }
}
