:root {
  --bg: #0d1017;
  --panel: #161b26;
  --panel-2: #1e2534;
  --ink: #e8ecf4;
  --muted: #8b96ab;
  --accent: #f0b429;
  --accent-ink: #241a02;
  --line: #2a3347;
  --good: #3ddc97;
  --bad: #ff6b6b;
  --die-face: #f6f7fb;
  --die-ink: #161b26;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: radial-gradient(1200px 600px at 50% -10%, #1a2133 0%, var(--bg) 60%);
  color: var(--ink);
  font: 16px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

.app {
  max-width: 760px;
  margin: 0 auto;
  padding: 32px 20px 64px;
  display: grid;
  gap: 22px;
}

.head h1 { margin: 0 0 6px; font-size: clamp(28px, 6vw, 40px); letter-spacing: -0.02em; }
.head .sub { margin: 0; color: var(--muted); max-width: 56ch; }

.stage {
  background: linear-gradient(180deg, var(--panel) 0%, var(--panel-2) 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 26px 20px 22px;
  display: grid;
  justify-items: center;
  gap: 18px;
}

.dice {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  justify-content: center;
  min-height: 96px;
  align-items: center;
}

/* --- dice faces ---------------------------------------------------------- */

.die {
  width: 88px;
  height: 88px;
  position: relative;
  display: grid;
  filter: drop-shadow(0 8px 16px rgba(0, 0, 0, 0.45));
  transition: transform 120ms ease;
}

.die.pips {
  background: var(--die-face);
  border-radius: 16px;
  padding: 12px;
  grid-template: repeat(3, 1fr) / repeat(3, 1fr);
  gap: 3px;
}

.die.pips .pip { border-radius: 50%; background: var(--die-ink); align-self: center; justify-self: center; width: 13px; height: 13px; }
.pip.tl { grid-area: 1 / 1; } .pip.tr { grid-area: 1 / 3; }
.pip.ml { grid-area: 2 / 1; } .pip.mr { grid-area: 2 / 3; }
.pip.c  { grid-area: 2 / 2; }
.pip.bl { grid-area: 3 / 1; } .pip.br { grid-area: 3 / 3; }

.die.poly {
  place-items: center;
  background: linear-gradient(160deg, #2b3550, #1d2434);
  color: var(--ink);
  font-weight: 700;
  font-size: 26px;
  border: 1px solid #3a4665;
}

.die.poly .val { pointer-events: none; }

.die.d4   { clip-path: polygon(50% 2%, 98% 94%, 2% 94%); }
.die.d8   { clip-path: polygon(50% 2%, 98% 50%, 50% 98%, 2% 50%); }
.die.d10  { clip-path: polygon(50% 2%, 92% 38%, 50% 98%, 8% 38%); }
.die.d12  { clip-path: polygon(50% 2%, 98% 40%, 82% 98%, 18% 98%, 2% 40%); }
.die.d20  { clip-path: polygon(25% 4%, 75% 4%, 98% 50%, 75% 96%, 25% 96%, 2% 50%); }
.die.d100 { border-radius: 50%; }

.die.tumbling { animation: tumble 460ms ease-in-out; }
@keyframes tumble {
  0%   { transform: rotate(0deg)   scale(0.86); }
  35%  { transform: rotate(200deg) scale(1.08); }
  70%  { transform: rotate(340deg) scale(0.96); }
  100% { transform: rotate(360deg) scale(1); }
}

/* --- controls ------------------------------------------------------------ */

.roll {
  font: inherit;
  font-weight: 700;
  font-size: 18px;
  letter-spacing: 0.01em;
  padding: 12px 40px;
  border-radius: 999px;
  border: 0;
  cursor: pointer;
  color: var(--accent-ink);
  background: linear-gradient(180deg, #ffd166, var(--accent));
  box-shadow: 0 10px 24px rgba(240, 180, 41, 0.28);
}
.roll:active { transform: translateY(1px); }
.roll:focus-visible, .presets button:focus-visible, .row button:focus-visible,
input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.result { min-height: 1.5em; margin: 0; font-size: 18px; text-align: center; color: var(--ink); }
.result strong { color: var(--accent); }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  display: grid;
  gap: 12px;
}

.presets { display: flex; flex-wrap: wrap; gap: 8px; }
.presets button, .row button {
  font: inherit;
  font-size: 14px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--ink);
  cursor: pointer;
}
.presets button.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; }

label { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }

input[type="text"], input[type="number"] {
  font: inherit;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #0f1420;
  color: var(--ink);
  width: 100%;
}
input[type="number"] { width: 84px; }

.row { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.row label { text-transform: none; letter-spacing: 0; }

.hint { margin: 0; min-height: 1.3em; font-size: 14px; color: var(--muted); }
.hint.bad { color: var(--bad); }
.hint.ok { color: var(--good); }

details summary { cursor: pointer; color: var(--muted); font-size: 14px; }
#history { margin: 8px 0 0; padding-left: 22px; color: var(--muted); font-size: 14px; }
#history li { margin: 2px 0; }

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

@media (max-width: 420px) {
  .die { width: 68px; height: 68px; }
  .die.pips .pip { width: 10px; height: 10px; }
  .die.poly { font-size: 20px; }
}
