.count {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
}
.count-label {
  font-weight: 700;
  color: var(--muted);
  margin-right: 4px;
}
@media (max-width: 480px) {
  .count-label { width: 100%; margin: 0; }
  .count button { width: 44px; height: 44px; }
}
.count button {
  font: inherit;
  font-weight: 800;
  font-size: 1.15rem;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 3px solid var(--ink);
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  touch-action: manipulation;
}
.count button[aria-checked="true"] {
  background: var(--ink);
  color: #fff;
}
.count button:focus-visible { outline: 4px solid var(--lava); outline-offset: 3px; }

.tray {
  all: unset;
  cursor: pointer;
  touch-action: manipulation;
  display: grid;
  grid-template-columns: repeat(var(--cols, 2), var(--size));
  gap: calc(var(--size) * 0.35);
  justify-content: center;
  align-content: center;
  padding: 28px 20px 34px;
  min-height: calc(var(--size) * 1.6);
  width: min(100%, 640px);
  box-sizing: border-box;
}
.tray:focus-visible { outline: 5px solid var(--lava); outline-offset: 4px; border-radius: 24px; }

.die-wrap {
  position: relative;
  pointer-events: none; /* taps go to the tray; 3D faces can confuse hit-testing */
  width: var(--size);
  height: var(--size);
  perspective: calc(var(--size) * 6);
}
.die-wrap::after { /* shadow on the table */
  content: "";
  position: absolute;
  left: 10%;
  right: 10%;
  bottom: calc(var(--size) * -0.22);
  height: calc(var(--size) * 0.14);
  border-radius: 50%;
  background: rgba(43, 33, 24, 0.18);
  filter: blur(3px);
}
.die-wrap.hop { animation: hop 0.9s cubic-bezier(.3,.7,.4,1); }
.die-wrap.hop::after { animation: shadow 0.9s cubic-bezier(.3,.7,.4,1); }
@keyframes hop {
  0% { transform: translateY(0); }
  30% { transform: translateY(calc(var(--size) * -0.55)); }
  60% { transform: translateY(0); }
  75% { transform: translateY(calc(var(--size) * -0.12)); }
  100% { transform: translateY(0); }
}
@keyframes shadow {
  30% { transform: scale(0.6); opacity: 0.5; }
}

.die {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transition: transform 1.1s cubic-bezier(.2,.75,.25,1);
}

.face {
  position: absolute;
  inset: 0;
  background: #fff;
  border: calc(var(--size) * 0.04) solid var(--ink);
  border-radius: 20%;
  box-shadow: inset 0 calc(var(--size) * -0.06) 0 rgba(43, 33, 24, 0.08);
  display: grid;
  grid-template: repeat(3, 1fr) / repeat(3, 1fr);
  padding: 14%;
  box-sizing: border-box;
  backface-visibility: hidden;
}
.face.f1 { transform: rotateY(0deg) translateZ(calc(var(--size) / 2)); }
.face.f6 { transform: rotateY(180deg) translateZ(calc(var(--size) / 2)); }
.face.f2 { transform: rotateY(90deg) translateZ(calc(var(--size) / 2)); }
.face.f5 { transform: rotateY(-90deg) translateZ(calc(var(--size) / 2)); }
.face.f3 { transform: rotateX(90deg) translateZ(calc(var(--size) / 2)); }
.face.f4 { transform: rotateX(-90deg) translateZ(calc(var(--size) / 2)); }

/* Solid inside so you never see through the corners while it tumbles */
.core {
  position: absolute;
  inset: 6%;
  background: #e9dfd3;
  border-radius: 12%;
  transform: translateZ(0);
}
.core.c2 { transform: rotateY(90deg); }
.core.c3 { transform: rotateX(90deg); }

.pip {
  width: 72%;
  height: 72%;
  place-self: center;
  border-radius: 50%;
  background: var(--ink);
  box-shadow: inset 0 calc(var(--size) * 0.02) 0 rgba(0, 0, 0, 0.35);
}
.f1 .pip { width: 95%; height: 95%; background: var(--lava); }

.result .total {
  display: inline-block;
  background: var(--ink);
  color: #fff;
  border-radius: 999px;
  padding: 2px 24px;
  font-size: clamp(2rem, 8vw, 2.8rem);
}
.result .sum { color: var(--muted); font-size: 1.1rem; width: 100%; }

@media (prefers-reduced-motion: reduce) {
  .die { transition-duration: 0.2s; }
  .die-wrap.hop, .die-wrap.hop::after { animation: none; }
}
