:root {
  --bg: #14161a;
  --panel: #1d2025;
  --die: #2a2e36;
  --die-edge: #3a4048;
  --pip: #f2f4f8;
  --text: #e8eaee;
  --muted: #8b93a1;
  --accent: #4f8cff;
  --accent-down: #3f74e0;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 18px;
  line-height: 1.4;
  min-height: 100vh;
  display: flex;
  justify-content: center;
}

.app {
  width: 100%;
  max-width: 30rem;
  padding: 1.5rem 1.25rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.stage {
  display: flex;
  justify-content: center;
  padding: 0.5rem 0;
}

.die {
  width: 9.5rem;
  height: 9.5rem;
  padding: 1rem;
  background: var(--die);
  border: 1px solid var(--die-edge);
  border-radius: 1rem;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
}

.pip {
  place-self: center;
  width: 1.4rem;
  height: 1.4rem;
  border-radius: 50%;
  background: var(--pip);
  visibility: hidden;
}

.die[data-face="1"] .pip:nth-child(5),
.die[data-face="2"] .pip:nth-child(1),
.die[data-face="2"] .pip:nth-child(9),
.die[data-face="3"] .pip:nth-child(1),
.die[data-face="3"] .pip:nth-child(5),
.die[data-face="3"] .pip:nth-child(9),
.die[data-face="4"] .pip:nth-child(1),
.die[data-face="4"] .pip:nth-child(3),
.die[data-face="4"] .pip:nth-child(7),
.die[data-face="4"] .pip:nth-child(9),
.die[data-face="5"] .pip:nth-child(1),
.die[data-face="5"] .pip:nth-child(3),
.die[data-face="5"] .pip:nth-child(5),
.die[data-face="5"] .pip:nth-child(7),
.die[data-face="5"] .pip:nth-child(9),
.die[data-face="6"] .pip:nth-child(1),
.die[data-face="6"] .pip:nth-child(3),
.die[data-face="6"] .pip:nth-child(4),
.die[data-face="6"] .pip:nth-child(6),
.die[data-face="6"] .pip:nth-child(7),
.die[data-face="6"] .pip:nth-child(9) {
  visibility: visible;
}

.die.rolling {
  animation: tumble 240ms linear infinite;
}

@keyframes tumble {
  0% { transform: rotate(0deg) scale(1); }
  25% { transform: rotate(-7deg) scale(1.04); }
  50% { transform: rotate(0deg) scale(0.97); }
  75% { transform: rotate(7deg) scale(1.04); }
  100% { transform: rotate(0deg) scale(1); }
}

.result {
  margin: 0;
  text-align: center;
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 0.6rem;
}

.result-label {
  font-size: 1rem;
  color: var(--muted);
}

.value {
  font-size: 2.75rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.controls {
  display: flex;
  justify-content: center;
}

button {
  font: inherit;
  font-size: 1.15rem;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: 0;
  border-radius: 0.6rem;
  padding: 0.75rem 2.5rem;
  min-height: 3rem;
  cursor: pointer;
}

button:hover:not(:disabled) {
  background: var(--accent-down);
}

button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

button:disabled {
  background: var(--panel);
  color: var(--muted);
  cursor: default;
}

.history-title {
  margin: 0 0 0.5rem;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.history-strip {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  gap: 0.5rem;
}

.history-strip li {
  width: 2.5rem;
  height: 2.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--panel);
  border-radius: 0.5rem;
  font-size: 1.25rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.history-strip li.newest {
  outline: 1px solid var(--accent);
}

.history-empty {
  margin: 0;
  font-size: 0.9rem;
  color: var(--muted);
}

.history-strip:not(:empty) + .history-empty {
  display: none;
}

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