* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  min-width: 0;
  min-height: 100vh;
  margin: 0;
  overflow-wrap: anywhere;
  color: #333;
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #234b31;
}

.tool-header {
  position: sticky;
  z-index: 50;
  top: 0;
  background: #234b31;
  border-bottom: 1px solid rgb(255 255 255 / 20%);
}

.tool-nav {
  display: flex;
  gap: 16px;
  align-items: center;
  width: 100%;
  padding: 12px 16px;
}

.tool-nav__link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 8px;
  color: #fff;
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  text-decoration: none;
}

.tool-nav__link:hover {
  color: #d7f3df;
  text-decoration: underline;
}

.tool-nav__link:focus-visible {
  outline: 3px solid #fff;
  outline-offset: -3px;
}

.container {
  width: 100%;
  max-width: 680px;
  min-width: 0;
  margin: 0 auto;
  padding: 16px;
}

h1 {
  margin: 0 0 20px;
  color: #fff;
  font-size: clamp(1.45rem, 7vw, 1.9rem);
  line-height: 1.2;
  text-align: center;
}

h2 {
  overflow-wrap: normal;
}

.privacy-notice,
.sharing-section {
  padding: 16px;
  color: #493500;
  background: #fff3cd;
  border: 2px solid #8a6400;
  border-radius: 3px;
}

.privacy-notice {
  margin-bottom: 16px;
}

.sharing-section {
  margin: 8px 0 16px;
}

.sharing-section h2 {
  margin: 0 0 8px;
  font-size: 1.1rem;
}

.sharing-section p {
  margin: 0 0 12px;
}

.status-message {
  padding: 12px 16px;
  color: #14351f;
  background: #e8f5e9;
  border: 1px solid #2d6d40;
  border-radius: 3px;
  margin-block: 0 16px;
}

.status-message-error {
  color: #7c1024;
  background: #fff0f0;
  border-color: #a01830;
}

.status-message:empty {
  display: none;
}

.card {
  min-width: 0;
  padding: 20px;
  margin-bottom: 16px;
  background: #fff;
  border: 1px solid #cbd7ce;
  border-radius: 3px;
  box-shadow: none;
}

.card h2 {
  display: flex;
  gap: 8px;
  align-items: center;
  margin: 0 0 16px;
  color: #1a472a;
  font-size: 1.1rem;
}

.card-description {
  margin: 0 0 12px;
  color: #555;
  font-size: 0.95rem;
  line-height: 1.45;
}

.field {
  min-width: 0;
}

.field-grow {
  flex: 1 1 160px;
}

.field label,
.manual-copy label {
  display: block;
  margin-bottom: 5px;
  color: #333;
  font-size: 0.9rem;
  font-weight: 650;
}

.input-row,
.rule-row {
  display: flex;
  gap: 8px;
  align-items: end;
  min-width: 0;
}

.input-row {
  margin-bottom: 12px;
}

input[type="text"],
select {
  width: 100%;
  min-width: 0;
  min-height: 48px;
  padding: 10px 12px;
  color: #222;
  font-size: 16px;
  background: #fff;
  border: 2px solid #777;
  border-radius: 3px;
}

select {
  cursor: pointer;
}

input[type="text"]:focus,
select:focus {
  border-color: #1a472a;
  outline: 3px solid #005fcc;
  outline-offset: 2px;
}

button {
  min-height: 44px;
  padding: 10px 16px;
  font-size: 1rem;
  font-weight: 650;
  cursor: pointer;
  border: 0;
  border-radius: 3px;
  transition:
    background-color 0.2s,
    transform 0.2s;
  touch-action: manipulation;
}

button:focus-visible {
  outline: 3px solid #005fcc;
  outline-offset: 3px;
}

.btn-add {
  flex: 0 1 auto;
  color: #fff;
  background: #1a472a;
}

.btn-add:hover {
  background: #2d5a3f;
}

.btn-add:active {
  transform: scale(0.98);
}

.input-action {
  white-space: nowrap;
}

.rule-action {
  flex: 1 1 150px;
}

.list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 0;
}

.list-spaced {
  margin-top: 12px;
}

.tag {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  max-width: 100%;
  min-height: 44px;
  padding: 2px 2px 2px 12px;
  font-size: 0.95rem;
  background: #f0f7f2;
  border: 1px solid #9abc9f;
  border-radius: 3px;
}

.tag-label {
  min-width: 0;
  overflow-wrap: anywhere;
}

.tag-remove {
  display: inline-flex;
  flex: 0 0 44px;
  align-items: center;
  justify-content: center;
  width: 44px;
  min-height: 44px;
  padding: 0;
  color: #666;
  font-size: 1.4rem;
  line-height: 1;
  background: none;
  border-radius: 2px;
}

.tag-remove:hover {
  color: #fff;
  background: #a01830;
}

.rule-tag {
  background: #fff5f5;
  border-color: #ce9b9b;
}

.forced-tag {
  background: #f0f5ff;
  border-color: #9aafd5;
}

.rule-arrow {
  align-self: end;
  padding-bottom: 12px;
  color: #555;
  font-weight: 700;
}

.empty-state,
.muted-message {
  color: #666;
  font-style: italic;
}

.empty-state {
  padding: 8px 0;
}

.permutation-count {
  margin-bottom: 12px;
  font-size: 0.95rem;
  line-height: 1.4;
}

.count-impossible {
  color: #a01830;
}

.count-limited {
  color: #805000;
}

.count-many {
  color: #176b34;
}

.seed-field {
  margin-bottom: 12px;
}

.btn-generate,
.btn-copy {
  width: 100%;
  color: #fff;
}

.btn-generate {
  min-height: 52px;
  padding: 14px;
  font-size: 1.1rem;
  background: #b11933;
}

.btn-generate:hover {
  background: #8f1228;
}

.btn-generate:disabled {
  color: #fff;
  cursor: not-allowed;
  background: #767676;
}

.btn-copy {
  background: #356946;
}

.btn-copy:hover,
.btn-copy.copied {
  background: #244f33;
}

.manual-copy {
  margin-top: 12px;
}

.results-card {
  background: #fffaf0;
  border: 2px solid #9a7600;
}

.results-card:focus {
  outline: 4px solid #005fcc;
  outline-offset: 3px;
}

.results-card h2 {
  color: #6f5200;
}

.results-warning {
  padding: 10px 12px;
  margin: 0 0 12px;
  color: #701126;
  font-weight: 650;
  background: #fff0f0;
  border-left: 4px solid #a01830;
}

.result-list {
  padding: 0;
  margin: 0;
  list-style: none;
}

.result-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  padding: 12px;
  margin-bottom: 8px;
  background: #fff;
  border: 1px solid #ded8c9;
  border-radius: 3px;
  box-shadow: none;
}

.result-item:last-child {
  margin-bottom: 0;
}

.result-giver {
  color: #1a472a;
  font-weight: 650;
}

.result-arrow {
  color: #a01830;
  font-size: 1.2rem;
}

.result-receiver {
  color: #333;
}

.result-giver,
.result-receiver {
  min-width: 0;
  overflow-wrap: anywhere;
}

.error-message {
  padding: 12px;
  margin-top: 12px;
  color: #8f1228;
  background: #fff0f0;
  border: 1px solid #a01830;
  border-radius: 3px;
}

.results-note {
  margin: 12px 0 0;
  color: #555;
  font-size: 0.9rem;
  text-align: center;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  white-space: nowrap;
  border: 0;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
}

@media (max-width: 480px) {
  .container {
    padding: 12px;
  }

  .card,
  .privacy-notice,
  .sharing-section {
    padding: 16px;
  }

  .input-row,
  .rule-row {
    flex-direction: column;
    align-items: stretch;
  }

  .field-grow,
  .rule-action {
    flex-basis: auto;
    width: 100%;
  }

  .input-action,
  .rule-action {
    width: 100%;
    white-space: normal;
  }

  .rule-arrow {
    display: none;
  }

  .result-item {
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    gap: 8px;
    padding: 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
