:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --text: #1d1d1f;
  --muted: #6b6b70;
  --border: #dddbd5;
  --accent: #5b4bdb;
  --accent-text: #ffffff;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141416;
    --surface: #1f1f23;
    --text: #f2f2f4;
    --muted: #9a9aa2;
    --border: #34343a;
    --accent: #8b7dff;
    --accent-text: #141416;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}
header, main { max-width: 32rem; margin: 0 auto; padding: 0 16px; }
header { padding-top: 24px; }
h1 { margin: 0 0 12px; font-size: 1.75rem; letter-spacing: -0.02em; }
nav { display: flex; gap: 8px; border-bottom: 1px solid var(--border); padding-bottom: 12px; }
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { opacity: .4; cursor: default; }
.tab { background: none; border: 0; padding: 6px 10px; border-radius: 8px; }
.tab[aria-current] { background: var(--surface); border: 1px solid var(--border); font-weight: 600; }

.controls { display: grid; gap: 16px; margin: 20px 0; }
fieldset { border: 0; margin: 0; padding: 0; }
legend { font-size: .85rem; color: var(--muted); margin-bottom: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip, .stepper button {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 14px; min-width: 44px; min-height: 44px;
}
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.stepper { display: flex; align-items: center; gap: 12px; }
.stepper output { min-width: 2ch; text-align: center; font-size: 1.25rem; font-weight: 600; }

.result {
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  min-height: 160px; padding: 20px; display: grid; place-content: center; text-align: center;
}
.dice { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.die {
  display: grid; place-content: center; width: 64px; height: 64px;
  border-radius: 14px; border: 2px solid var(--accent);
  font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums;
}
.dice:has(.die:nth-child(5)) .die { width: 48px; height: 48px; font-size: 1.2rem; }
.rolling .die { animation: pop .35s ease-out; }
@keyframes pop { from { transform: rotate(-20deg) scale(.6); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .rolling .die { animation: none; } }
.total { margin: 12px 0 0; color: var(--muted); font-weight: 600; }
.total:empty { display: none; }

.roll {
  width: 100%; margin: 16px 0; padding: 16px; border: 0; border-radius: 14px;
  background: var(--accent); color: var(--accent-text); font-size: 1.2rem; font-weight: 700;
}
.roll:active { transform: scale(.98); }
.history { list-style: none; padding: 0; margin: 0 0 32px; color: var(--muted); font-size: .9rem; font-variant-numeric: tabular-nums; }
.history li { padding: 4px 0; border-bottom: 1px solid var(--border); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
