* {
  box-sizing: border-box;
}
:root {
  --blue: #2563eb;
  --blue-dark: #1d4ed8;
  --blue-soft: #eff6ff;
  --text: #202938;
  --muted: #6b7280;
  --border: #dfe5ee;
  --border-dark: #cbd5e1;
  --bg: #f4f7fb;
}

.randomizer {
  width: min(1100px, calc(100% - 28px));
  margin: 24px auto 50px;
}
.hero {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  padding: 26px 28px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 3px 14px rgba(31, 41, 55, 0.06);
}
.hero p {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.5;
}
.categories {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-top: 18px;
}
.category {
  min-width: 0;
  padding: 18px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 3px 12px rgba(31, 41, 55, 0.045);
}
.category-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}
.category-title {
  min-width: 0;
  flex: 1;
  padding: 9px 10px;
  border: 1px solid transparent;
  border-radius: 7px;
  color: var(--text);
  font-size: 18px;
  font-weight: 700;
  background: transparent;
}
.category-title:focus {
  outline: none;
  border-color: var(--border-dark);
  background: #fff;
}
.category-icon {
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  display: grid;
  place-items: center;
  border-radius: 9px;
  background: var(--blue-soft);
  font-size: 20px;
}
.remove-category {
  width: 34px;
  height: 34px;
  border: 0;
  background: transparent;
  color: #94a3b8;
  border-radius: 7px;
  cursor: pointer;
  font-size: 20px;
}
.remove-category:hover {
  background: #fef2f2;
  color: #dc2626;
}
.items {
  display: grid;
  gap: 7px;
}
.item-row {
  display: flex;
  align-items: center;
  gap: 7px;
}
.item-input {
  min-width: 0;
  flex: 1;
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  background: #fff;
}
.item-input:focus {
  outline: 2px solid rgba(37, 99, 235, 0.1);
  border-color: var(--blue);
}
.remove-item {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: #94a3b8;
  cursor: pointer;
}
.remove-item:hover {
  background: #f1f5f9;
  color: #dc2626;
}
.category-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}
.add-item,
.list-item {
  border: 0;
  background: transparent;
  color: var(--blue);
  padding: 5px 2px;
  cursor: pointer;
  font-size: 14px;
}
.list-item:hover {
  color: var(--blue-dark);
}
.add-category-wrap {
  margin-top: 16px;
}
.btn {
  min-height: 40px;
  padding: 8px 14px;
  border: 1px solid var(--border-dark);
  border-radius: 8px;
  background: #fff;
  color: #334155;
  cursor: pointer;
  transition: 0.15s;
}
.btn:hover {
  background: #f8fafc;
  border-color: #aeb9c9;
}
.btn-primary,
.generate-btn {
  background: var(--blue);
  color: #fff;
  border-color: var(--blue);
}
.btn-primary:hover,
.generate-btn:hover {
  background: var(--blue-dark);
  border-color: var(--blue-dark);
}
.generate-card {
  margin-top: 18px;
  padding: 20px;
  text-align: center;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 14px;
}
.generate-btn {
  min-width: 250px;
  min-height: 52px;
  border-radius: 10px;
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 5px 14px rgba(37, 99, 235, 0.16);
}
.generate-btn .dice {
  display: inline-block;
  margin-right: 7px;
}
.generate-btn.running .dice {
  animation: shake 0.13s linear infinite;
}
.shortcut {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}
.result {
  margin-top: 18px;
  padding: 24px;
  background: #fff;
  border: 1px solid #bfdbfe;
  border-radius: 16px;
  box-shadow: 0 5px 20px rgba(37, 99, 235, 0.08);
}
.result-title {
  margin-bottom: 16px;
  color: #1e40af;
  font-size: 20px;
  font-weight: 700;
}
.result-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.result-card {
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: #f8fafc;
}
.result-category {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 5px;
}
.result-value {
  font-size: 20px;
  font-weight: 700;
  word-break: break-word;
}
.btn-again {
  margin-top: 18px;
}
.hidden {
  display: none !important;
}
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 18px;
}
.modal-backdrop {
  position: absolute;
  z-index: auto;
  inset: 0;
  background: rgba(15, 23, 42, 0.48);
}
.modal-card {
  position: relative;
  width: min(560px, 100%);
  padding: 24px;
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 20px 60px rgba(15, 23, 42, 0.25);
}
.modal-card h2 {
  margin: 0 0 7px;
}
.modal-card p {
  margin: 0 0 14px;
  color: var(--muted);
  line-height: 1.45;
}
.modal-card textarea {
  width: 100%;
  resize: vertical;
  padding: 12px;
  border: 1px solid var(--border-dark);
  border-radius: 9px;
  color: var(--text);
  line-height: 1.5;
}
.modal-card textarea:focus {
  outline: 2px solid rgba(37, 99, 235, 0.1);
  border-color: var(--blue);
}
.modal-close {
  position: absolute;
  top: 10px;
  right: 12px;
  width: 36px;
  height: 36px;
  border: 0;
  background: transparent;
  color: #64748b;
  font-size: 27px;
  cursor: pointer;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}
.toast {
  position: fixed;
  z-index: 2000;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 20px);
  max-width: calc(100% - 30px);
  padding: 10px 15px;
  border-radius: 9px;
  background: #1f2937;
  color: #fff;
  opacity: 0;
  pointer-events: none;
  transition: 0.2s;
}
.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}
@keyframes shake {
  0% {
    transform: rotate(-10deg);
  }
  50% {
    transform: rotate(10deg);
  }
  100% {
    transform: rotate(-10deg);
  }
}
@media (max-width: 700px) {
  .randomizer {
    width: min(100% - 16px, 650px);
    margin-top: 8px;
  }
  .hero {
    flex-direction: column;
    align-items: stretch;
    padding: 20px;
  }
  .hero .btn {
    width: 100%;
  }
  .categories {
    grid-template-columns: 1fr;
  }
  .result-grid {
    grid-template-columns: 1fr;
  }
}
@media (max-width: 430px) {
  .category,
  .result,
  .generate-card {
    padding: 14px;
  }
  .generate-btn {
    width: 100%;
    min-width: 0;
  }
}
.add-item:hover {
    color: var(--blue);
}
.add-item:hover,
.list-item:hover {
    background: none;
    text-decoration: underline;
}
.modal-close:hover {
    background: transparent;
    color: #000;
}
