.dice-tray {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  justify-content: center;
  padding: 18px 10px;
  min-height: 120px;
}

/* ---------- Base acrylic die (applies to every sides value) ---------- */

.die {
  width: 100px;
  height: 100px;
  border-radius: 18px;
  font-weight: 800;
  font-size: 2.6rem;
  color: #ffffff;
  text-shadow:
    0 1px 0 rgba(0, 0, 0, 0.55),
    0 2px 6px rgba(0, 0, 0, 0.55),
    0 0 2px rgba(0, 0, 0, 0.8);
  letter-spacing: 0.02em;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  background: linear-gradient(145deg,
    var(--die-hi) 0%,
    var(--die-mid) 45%,
    var(--die-lo) 100%);
  box-shadow:
    0 8px 18px rgba(0, 0, 0, 0.45),
    inset 0 3px 2px rgba(255, 255, 255, 0.45),
    inset 0 -8px 14px rgba(0, 0, 0, 0.22),
    inset 0 0 0 1px rgba(255, 255, 255, 0.1);
}

/* Glossy acrylic highlight on the top-left face. */
.die::before {
  content: "";
  position: absolute;
  inset: 4px 4px auto 4px;
  height: 46%;
  border-radius: 14px 14px 40% 40% / 14px 14px 30% 30%;
  background: linear-gradient(180deg,
    rgba(255, 255, 255, 0.35),
    rgba(255, 255, 255, 0.05) 70%,
    transparent);
  pointer-events: none;
}

.die .side-tag {
  position: absolute;
  bottom: 4px;
  right: 6px;
  font-size: 0.65rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.85);
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.6);
  letter-spacing: 0.05em;
}

.die.rolling { animation: diceRoll 0.6s ease-out; }
@keyframes diceRoll {
  0%   { transform: rotate(0deg)   scale(1); }
  30%  { transform: rotate(180deg) scale(1.08); }
  60%  { transform: rotate(320deg) scale(0.95); }
  100% { transform: rotate(360deg) scale(1); }
}

/* d100 shows "22 / 70" style readings so allow a bit of wrap. */
.die.d100 { font-size: 1.8rem; }

/* ---------- Colour variants (apply to every sides value) ---------- */

.die.red {
  --die-hi: #ff9a8f;
  --die-mid: #d32020;
  --die-lo: #6b0d0d;
}
.die.green {
  --die-hi: #9df2a7;
  --die-mid: #1fa033;
  --die-lo: #0a4318;
}
.die.yellow {
  --die-hi: #fff2a8;
  --die-mid: #e6b613;
  --die-lo: #7a5a08;
}
.die.blue {
  --die-hi: #a6c8ff;
  --die-mid: #1f58d3;
  --die-lo: #0b1f5c;
}
.die.white {
  --die-hi: #ffffff;
  --die-mid: #ededed;
  --die-lo: #a8a8ae;
  color: #121212;
  text-shadow:
    0 1px 0 rgba(255, 255, 255, 0.9),
    0 0 2px rgba(255, 255, 255, 0.6),
    0 2px 3px rgba(0, 0, 0, 0.12);
}
.die.white .side-tag {
  color: rgba(20, 20, 20, 0.7);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.7);
}

/* ---------- d6 pip rendering ---------- */

.die.d6 { color: transparent; font-size: 0; }
.die.d6 .pips {
  position: absolute;
  inset: 12px;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: 1fr 1fr 1fr;
  gap: 0;
  pointer-events: none;
}
.die.d6 .pip {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  justify-self: center;
  align-self: center;
  background:
    radial-gradient(circle at 50% 70%,
      rgba(255, 255, 255, 0.95) 0%,
      rgba(230, 230, 230, 0.9) 55%,
      rgba(200, 200, 200, 0.85) 100%);
  box-shadow:
    inset 0 3px 3px rgba(0, 0, 0, 0.55),
    inset 0 -2px 2px rgba(255, 255, 255, 0.5),
    0 1px 0 rgba(255, 255, 255, 0.25);
}
/* Dark pip divets for white dice; the default white pip would vanish. */
.die.d6.white .pip {
  background:
    radial-gradient(circle at 50% 30%,
      rgba(70, 70, 70, 0.95) 0%,
      rgba(20, 20, 20, 0.95) 65%,
      rgba(5, 5, 5, 1) 100%);
  box-shadow:
    inset 0 2px 2px rgba(0, 0, 0, 0.8),
    inset 0 -1px 1px rgba(255, 255, 255, 0.15),
    0 1px 0 rgba(255, 255, 255, 0.8);
}

.die.d6 .pip[data-cell="1"] { grid-area: 1 / 1; }
.die.d6 .pip[data-cell="2"] { grid-area: 1 / 2; }
.die.d6 .pip[data-cell="3"] { grid-area: 1 / 3; }
.die.d6 .pip[data-cell="4"] { grid-area: 2 / 1; }
.die.d6 .pip[data-cell="5"] { grid-area: 2 / 2; }
.die.d6 .pip[data-cell="6"] { grid-area: 2 / 3; }
.die.d6 .pip[data-cell="7"] { grid-area: 3 / 1; }
.die.d6 .pip[data-cell="8"] { grid-area: 3 / 2; }
.die.d6 .pip[data-cell="9"] { grid-area: 3 / 3; }

.summary {
  display: flex;
  justify-content: center;
  gap: 18px;
  flex-wrap: wrap;
  margin-top: 8px;
}
.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 90px;
  padding: 10px 14px;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.stat .label { color: var(--dim); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; }
.stat .value { font-size: 1.6rem; font-weight: 700; color: var(--accent); }

.history { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; max-height: 240px; overflow-y: auto; }
.history li {
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 0.95rem;
  display: flex;
  justify-content: space-between;
  gap: 10px;
}
.history li .sum { color: var(--accent); font-weight: 700; }
.history li.empty { justify-content: center; color: var(--dim); font-style: italic; font-family: inherit; }

kbd {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 0.85em;
}
