* {
  box-sizing: border-box;
}

body {
  font-size: 16px;
  line-height: 1.45;
  font-family: system-ui, sans-serif;
  background: #0f172a;
  color: #f1f5f9;
  text-align: center;
  padding: 1rem;
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

h1 {
  margin: 1rem 0 1.5rem;
  font-size: clamp(24px, 8vw, 36px);
}

.controls {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-bottom: 2rem;
  padding: 1.5rem;
  background: #1e293b;
  border-radius: 12px;
}

fieldset {
  border: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

legend {
  font-weight: 700;
  font-size: 1.1rem;
  margin-bottom: 0.5rem;
  text-align: left;
  padding: 0;
  width: 100%;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  text-align: left;
}

.control-group label {
  font-weight: 600;
  font-size: 0.95rem;
}

select {
  padding: 12px;
  font-size: 16px;
  border: 2px solid #475569;
  border-radius: 8px;
  background: #0f172a;
  color: #f1f5f9;
  cursor: pointer;
  min-height: 44px;
}

select:focus {
  outline: none;
  border-color: #60a5fa;
  box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.1);
}

select:focus-visible {
  outline: 3px solid #60a5fa;
  outline-offset: 2px;
}

.checkbox-wrapper {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 12px 0;
}

input[type="checkbox"] {
  width: 20px;
  height: 20px;
  cursor: pointer;
  accent-color: #3b82f6;
}

input[type="checkbox"]:focus-visible {
  outline: 3px solid #60a5fa;
  outline-offset: 2px;
}

#rollButton {
  padding: 16px 24px;
  font-size: 18px;
  font-weight: 600;
  background: #0950C3;
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  min-height: 48px;
  margin: 0;
  transition: background 0.2s, opacity 0.3s;
  width: 100%;
  max-width: 400px;
  align-self: center;
}

#rollButton:focus-visible {
  outline: 3px solid #60a5fa;
  outline-offset: 2px;
}

#rollButton:active:not(:disabled) {
  background: #2563eb;
  transform: scale(0.98);
}

#rollButton:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

#result {
  margin-top: 2rem;
  padding: 1.5rem;
  font-size: 1.1rem;
  background: #1e293b;
  border-radius: 8px;
  min-height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.dice-animation {
  font-size: 3rem;
  animation: rollDice 1.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

@keyframes rollDice {
  0% {
    transform: rotate(0deg) scale(1);
  }
  50% {
    transform: rotate(180deg) scale(1.2);
  }
  100% {
    transform: rotate(720deg) scale(1);
  }
}

.info {
  margin-top: auto;
  padding-top: 2rem;
  color: #cbd5e1;
  font-size: 0.85rem;
}

code {
  background: #0f172a;
  padding: 0.5rem 0.75rem;
  border-radius: 4px;
  display: inline-block;
}

/* Screen reader only content */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* Tablet and up */
@media (min-width: 640px) {
  body {
    padding: 2rem;
  }

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

  fieldset {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem;
    max-width: 600px;
  }

  legend {
    grid-column: 1 / -1;
  }

  .control-group:last-of-type {
    grid-column: 1 / -1;
  }

  #rollButton {
    grid-column: 1 / -1;
    margin-top: 1rem;
  }
}

/* Prefer reduced motion */
@media (prefers-reduced-motion: reduce) {
  .dice-animation {
    animation: none;
  }
  
  * {
    transition: none !important;
    animation: none !important;
  }
}
