/* Dice tray (dice.js): 3D cubes that flip while a roll is due and land on the result. */

.dice-tray {
  display: inline-flex; align-items: center; gap: 16px; padding: 12px 18px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; color: var(--text);
  font: inherit;
}
button.dice-tray { cursor: pointer; }
button.dice-tray:hover:not(:disabled) { border-color: var(--accent-border-strong); background: var(--accent-faint); }
button.dice-tray:disabled { cursor: progress; opacity: 1; }
.dice-row3d { display: inline-flex; gap: 14px; }
.dice-total { font-family: var(--mono); font-size: 1.05rem; min-width: 8.5em; }
.dice-tray.waiting .dice-total { color: var(--muted); font-family: var(--font); font-size: 0.9rem; }

.die-cube { --s: 42px; width: var(--s); height: var(--s); display: inline-block; perspective: 320px; }
.cube { position: relative; display: block; width: 100%; height: 100%; transform-style: preserve-3d; }
.face {
  position: absolute; inset: 0; padding: 7px; border-radius: 8px;
  display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr);
  background: var(--die, #efe5d3); box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.25), inset 0 -3px 6px rgba(0, 0, 0, 0.18);
  backface-visibility: hidden;
}
.face i { width: calc(var(--s) * 0.17); height: calc(var(--s) * 0.17); border-radius: 50%; place-self: center; }
.face i.on { background: var(--pip, #2a221e); }
.face-front  { transform: translateZ(calc(var(--s) / 2)); }
.face-back   { transform: rotateY(180deg) translateZ(calc(var(--s) / 2)); }
.face-right  { transform: rotateY(90deg) translateZ(calc(var(--s) / 2)); }
.face-left   { transform: rotateY(-90deg) translateZ(calc(var(--s) / 2)); }
.face-top    { transform: rotateX(90deg) translateZ(calc(var(--s) / 2)); }
.face-bottom { transform: rotateX(-90deg) translateZ(calc(var(--s) / 2)); }
.die-red    { --die: #c9545e; --pip: #fff; }
.die-yellow { --die: #e8c45a; }
.face-event { display: flex; align-items: center; justify-content: center; padding: 0; }
.face-event .event-icon { width: 68%; height: 68%; display: block; }

/* End-over-end flipping; each die runs out of phase with the others. */
.cube.flipping { animation: flip 1.1s linear infinite; animation-delay: calc(var(--i) * -0.37s); }
.die-cube:nth-child(2) .cube.flipping { animation-duration: 1.25s; }
.die-cube:nth-child(3) .cube.flipping { animation-duration: 0.95s; }
@keyframes flip {
  from { transform: rotateX(0deg) rotateY(0deg) rotateZ(0deg); }
  to   { transform: rotateX(360deg) rotateY(720deg) rotateZ(180deg); }
}
@media (prefers-reduced-motion: reduce) {
  .cube.flipping { animation: none; }
  .cube { transition: none !important; }
}
