:root {
  color-scheme: light;
  font-family: Inter, ui-rounded, "SF Pro Rounded", system-ui, sans-serif;
  background: #f2eee7;
  color: #292725;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background:
    radial-gradient(circle at 50% 38%, rgba(255,255,255,.85), transparent 38rem),
    #f2eee7;
}

button, input { font: inherit; }

.app {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 2rem;
  padding: clamp(1rem, 4vw, 2.5rem);
}

.dice-picker {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: .65rem;
}

.die-option {
  width: 3.35rem;
  height: 3.35rem;
  border: 1px solid rgba(41,39,37,.12);
  border-radius: 1rem;
  background: rgba(255,255,255,.68);
  color: #5c5751;
  font-weight: 750;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(55,48,40,.06);
  transition: transform .15s ease, background .15s ease, box-shadow .15s ease;
}

.die-option:hover {
  transform: translateY(-2px);
  background: #fff;
  box-shadow: 0 7px 18px rgba(55,48,40,.1);
}

.die-option:active { transform: scale(.94); }

.custom-die {
  display: flex;
  align-items: center;
  height: 3.35rem;
  padding-left: .8rem;
  border: 1px solid rgba(41,39,37,.12);
  border-radius: 1rem;
  background: rgba(255,255,255,.68);
  color: #5c5751;
  font-weight: 750;
  box-shadow: 0 4px 12px rgba(55,48,40,.06);
}

.custom-die input {
  width: 3.3rem;
  border: 0;
  outline: 0;
  background: transparent;
  color: inherit;
  font-weight: inherit;
  appearance: textfield;
}

.custom-die input::-webkit-inner-spin-button,
.custom-die input::-webkit-outer-spin-button { appearance: none; }

.custom-die button {
  align-self: stretch;
  width: 2.7rem;
  border: 0;
  border-left: 1px solid rgba(41,39,37,.1);
  border-radius: 0 1rem 1rem 0;
  background: transparent;
  color: inherit;
  font-size: 1.25rem;
  font-weight: 600;
  cursor: pointer;
}

.custom-die button:hover { background: #fff; }

.custom-die:focus-within {
  outline: 3px solid #292725;
  outline-offset: 4px;
}

.tray {
  align-self: center;
  display: flex;
  justify-content: center;
  align-items: center;
  align-content: center;
  flex-wrap: wrap;
  gap: clamp(.8rem, 2.5vw, 1.5rem);
  width: min(58rem, 100%);
  margin: auto;
}

.die-shell {
  position: relative;
  width: clamp(5rem, 12vw, 7rem);
  aspect-ratio: 1;
  filter: drop-shadow(0 12px 11px rgba(70,51,38,.17));
}

.die {
  --die-color: #e66747;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .3rem;
  width: 100%;
  aspect-ratio: 1;
  border: 0;
  border-radius: 26%;
  background: var(--die-color);
  color: #fffdf8;
  font-size: clamp(1.7rem, 5vw, 2.6rem);
  font-weight: 850;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-touch-callout: none;
  box-shadow:
    inset 0 -7px 0 rgba(67,35,25,.13),
    inset 0 2px 1px rgba(255,255,255,.25);
  transition: transform .16s ease, filter .16s ease;
}

.die--d2,
.die--d100 {
  border-radius: 50%;
  background:
    radial-gradient(circle at 35% 28%, rgba(255,255,255,.25), transparent 34%),
    var(--die-color);
}

.die--d2 {
  border: clamp(.35rem, .9vw, .55rem) solid color-mix(in srgb, var(--die-color), #292725 12%);
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.18);
}

.die--d4 {
  border-radius: 0;
  clip-path: polygon(50% 3%, 97% 91%, 3% 91%);
  padding-top: 22%;
}

.die--d6 { border-radius: 22%; }

.die--d8 {
  border-radius: 0;
  clip-path: polygon(50% 1%, 96% 50%, 50% 99%, 4% 50%);
  background:
    linear-gradient(135deg, rgba(255,255,255,.16) 0 49%, transparent 50%),
    var(--die-color);
}

.die--d10 {
  border-radius: 0;
  clip-path: polygon(50% 0, 81% 18%, 100% 50%, 81% 82%, 50% 100%, 19% 82%, 0 50%, 19% 18%);
  background:
    conic-gradient(from 45deg, rgba(255,255,255,.14), transparent 25% 50%, rgba(41,39,37,.08) 50% 75%, transparent 75%),
    var(--die-color);
}

.die--d12 {
  border-radius: 0;
  clip-path: polygon(50% 0, 75% 7%, 93% 25%, 100% 50%, 93% 75%, 75% 93%, 50% 100%, 25% 93%, 7% 75%, 0 50%, 7% 25%, 25% 7%);
  background:
    radial-gradient(circle at 38% 30%, rgba(255,255,255,.17), transparent 48%),
    var(--die-color);
}

.die--d20 {
  border-radius: 0;
  clip-path: polygon(50% 0, 72% 6%, 90% 20%, 100% 42%, 97% 65%, 82% 87%, 61% 100%, 39% 100%, 18% 87%, 3% 65%, 0 42%, 10% 20%, 28% 6%);
  background:
    linear-gradient(120deg, rgba(255,255,255,.14) 0 32%, transparent 33% 66%, rgba(41,39,37,.08) 67%),
    var(--die-color);
}

.die--custom {
  border-radius: 0;
  clip-path: polygon(25% 5%, 75% 5%, 98% 35%, 88% 82%, 50% 100%, 12% 82%, 2% 35%);
}

.die-label {
  font-size: .7rem;
  font-weight: 800;
  line-height: 1;
  opacity: .6;
}

.die:hover { transform: translateY(-3px) rotate(-1deg); filter: brightness(1.03); }
.die:active { transform: scale(.93); }
.die.rolling { animation: tumble .55s cubic-bezier(.16,.8,.22,1); }
.die.rolling .die-value { animation: value-pop .55s ease; }

.dice-menu {
  position: fixed;
  z-index: 10;
  min-width: 8.5rem;
  padding: .35rem;
  border: 1px solid rgba(41,39,37,.12);
  border-radius: .75rem;
  background: rgba(255,255,255,.96);
  box-shadow: 0 12px 30px rgba(41,39,37,.2);
  backdrop-filter: blur(10px);
}

.dice-menu[hidden] { display: none; }

.dice-menu button {
  display: flex;
  align-items: center;
  gap: .55rem;
  width: 100%;
  padding: .55rem .65rem;
  border: 0;
  border-radius: .5rem;
  background: transparent;
  color: #b33d32;
  font-weight: 700;
  cursor: pointer;
}

.dice-menu button:hover,
.dice-menu button:focus-visible { background: #faece9; }

.dice-menu svg {
  width: 1.05rem;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.roll-all {
  justify-self: center;
  display: grid;
  place-items: center;
  width: 4.4rem;
  aspect-ratio: 1;
  border: 0;
  border-radius: 50%;
  background: #292725;
  color: #fff;
  cursor: pointer;
  box-shadow: 0 9px 22px rgba(41,39,37,.22);
  transition: transform .16s ease, opacity .16s ease;
}

.roll-all svg {
  width: 1.55rem;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.roll-all:hover:not(:disabled) { transform: rotate(15deg) scale(1.05); }
.roll-all:active:not(:disabled) { transform: rotate(45deg) scale(.94); }
.roll-all:disabled { opacity: .18; cursor: default; }

button:focus-visible { outline: 3px solid #292725; outline-offset: 4px; }

@keyframes tumble {
  0% { transform: rotate(0) scale(1); }
  22% { transform: translateY(-8%) rotate(-15deg) scale(.9); }
  48% { transform: translateY(3%) rotate(13deg) scale(1.05); }
  72% { transform: translateY(-2%) rotate(-6deg) scale(.97); }
  100% { transform: rotate(0) scale(1); }
}

@keyframes value-pop {
  0%, 42% { opacity: .35; transform: scale(.72); }
  72% { opacity: 1; transform: scale(1.16); }
  100% { transform: scale(1); }
}

@media (max-width: 480px) {
  .app { gap: 1.25rem; padding: 1rem; }
  .dice-picker { gap: .4rem; }
  .die-option { width: 2.75rem; height: 2.75rem; border-radius: .8rem; font-size: .83rem; }
  .custom-die { height: 2.75rem; border-radius: .8rem; font-size: .83rem; }
  .custom-die button { border-radius: 0 .8rem .8rem 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
