:root {
  --page: #f4f3ee;
  --card: #ffffff;
  --text: #1f2328;
  --muted: #646b75;
  --line: #e4e2da;
  --accent: #1f2328;
  --accent-text: #ffffff;
  --ball: clamp(38px, 11vw, 52px);
  color-scheme: light;
}

:root[data-theme="dark"] {
  --page: #15171a;
  --card: #202328;
  --text: #f2f3f5;
  --muted: #a5abb5;
  --line: #363a41;
  --accent: #f2f3f5;
  --accent-text: #15171a;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px 16px 76px;
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", sans-serif;
  background: var(--page);
  color: var(--text);
}

.card {
  width: 100%;
  max-width: 520px;
  padding: 32px 20px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--card);
  text-align: center;
}

h1 {
  margin: 0 0 8px;
  font-size: 28px;
}

h2 {
  margin: 0 0 12px;
  font-size: 15px;
}

.subtitle,
.placeholder,
.note {
  color: var(--muted);
}

.subtitle {
  margin: 0;
  line-height: 1.5;
}

.result {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 112px;
  margin: 20px 0;
}

.placeholder {
  margin: 0;
}

.ball {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: var(--ball);
  height: var(--ball);
  border-radius: 50%;
  font-size: calc(var(--ball) * 0.4);
  font-weight: 700;
  color: #ffffff;
  animation: pop 320ms ease-out both;
}

.range-1 { background: #f5bd00; color: #1f2328; }
.range-2 { background: #2563eb; }
.range-3 { background: #dc2626; }
.range-4 { background: #6b7280; }
.range-5 { background: #15803d; }

.plus {
  flex: none;
  padding: 0 2px;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
}

.draw-button {
  width: 100%;
  padding: 15px 20px;
  border: 0;
  border-radius: 10px;
  font: inherit;
  font-weight: 700;
  color: var(--accent-text);
  background: var(--accent);
  cursor: pointer;
}

.draw-button:hover {
  opacity: 0.88;
}

.theme-toggle {
  position: fixed;
  right: 16px;
  bottom: 16px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  background: var(--card);
  cursor: pointer;
}

.draw-button:focus-visible,
.theme-toggle:focus-visible {
  outline: 3px solid #2563eb;
  outline-offset: 2px;
}

.history {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

.history ol {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.history li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 4px;
  --ball: 28px;
}

.history .ball {
  animation: none;
}

.note {
  margin: 20px 0 0;
  font-size: 13px;
  line-height: 1.5;
}

@keyframes pop {
  from {
    opacity: 0;
    transform: scale(0.4);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

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