* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  place-items: center;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: radial-gradient(circle at 30% 20%, #2b3a67, #121826 70%);
  color: #f1f3f8;
}

.card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
  padding: 2.5rem 2rem;
  width: min(92vw, 340px);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 20px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
}

h1 {
  margin: 0;
  font-size: 1.5rem;
  letter-spacing: 0.04em;
}

.die {
  width: 120px;
  height: 120px;
  padding: 16px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  place-items: center;
  background: linear-gradient(145deg, #ffffff, #dfe3ec);
  border: none;
  border-radius: 22px;
  box-shadow: 0 10px 0 #a9b0c2, 0 18px 30px rgba(0, 0, 0, 0.4);
  cursor: pointer;
}

.die:focus-visible, .roll:focus-visible {
  outline: 3px solid #ffd166;
  outline-offset: 4px;
}

.pip {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #1d2433;
  visibility: hidden;
}

/* Pip positions (grid cells 1-9, row-major) */
.die[data-face="1"] .pip:nth-child(5),
.die[data-face="2"] .pip:is(:nth-child(1), :nth-child(9)),
.die[data-face="3"] .pip:is(:nth-child(1), :nth-child(5), :nth-child(9)),
.die[data-face="4"] .pip:is(:nth-child(1), :nth-child(3), :nth-child(7), :nth-child(9)),
.die[data-face="5"] .pip:is(:nth-child(1), :nth-child(3), :nth-child(5), :nth-child(7), :nth-child(9)),
.die[data-face="6"] .pip:is(:nth-child(1), :nth-child(3), :nth-child(4), :nth-child(6), :nth-child(7), :nth-child(9)) {
  visibility: visible;
}

.die[data-face="1"] .pip:nth-child(5) { background: #e63946; }

.die.rolling {
  animation: tumble 0.6s cubic-bezier(0.3, 0.7, 0.4, 1);
}

@keyframes tumble {
  0%   { transform: translateY(0) rotate(0deg) scale(1); }
  30%  { transform: translateY(-40px) rotate(200deg) scale(0.9); }
  60%  { transform: translateY(0) rotate(340deg) scale(1.05); }
  80%  { transform: translateY(-8px) rotate(360deg) scale(1); }
  100% { transform: translateY(0) rotate(360deg) scale(1); }
}

.result {
  margin: 0.5rem 0 0;
  font-size: 1.1rem;
  min-height: 1.4em;
  color: #c9d1e6;
}

.result strong {
  color: #ffd166;
  font-size: 1.4rem;
}

.roll {
  padding: 0.8rem 2.6rem;
  font-size: 1.1rem;
  font-weight: 600;
  color: #1d2433;
  background: #ffd166;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 4px 0 #c99a2e;
  transition: transform 0.08s, box-shadow 0.08s;
}

.roll:active { transform: translateY(3px); box-shadow: 0 1px 0 #c99a2e; }
.roll:disabled { opacity: 0.7; cursor: wait; }

.history {
  margin: 0;
  min-height: 1.2em;
  font-size: 0.9rem;
  color: #8f9ab5;
  letter-spacing: 0.08em;
}

@media (prefers-reduced-motion: reduce) {
  .die.rolling { animation: none; }
}
