/* Reset and base styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --primary-color: #2563eb;
  --primary-hover: #1d4ed8;
  --secondary-color: #64748b;
  --secondary-hover: #475569;
  --success-color: #10b981;
  --error-color: #ef4444;
  --background: #f8fafc;
  --surface: #ffffff;
  --text-primary: #0f172a;
  --text-secondary: #64748b;
  --border: #e2e8f0;
  --constraint-can: #e0f2fe;
  --constraint-must: #dcfce7;
  --constraint-cannot: #fee2e2;
  --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--background);
  color: var(--text-primary);
  line-height: 1.6;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
}

/* Header */
header {
  text-align: center;
  margin-bottom: 40px;
}

h1 {
  font-size: 2.5rem;
  margin-bottom: 10px;
  color: var(--primary-color);
}

.subtitle {
  color: var(--text-secondary);
  font-size: 1.1rem;
}

h2 {
  font-size: 1.5rem;
  margin-bottom: 15px;
  color: var(--text-primary);
}

h3 {
  font-size: 1.2rem;
  margin-bottom: 10px;
}

/* Sections */
section {
  background: var(--surface);
  border-radius: 8px;
  padding: 25px;
  margin-bottom: 25px;
  box-shadow: var(--shadow);
}

/* Buttons */
.btn {
  padding: 10px 20px;
  border: none;
  border-radius: 6px;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  display: inline-block;
}

.btn-primary {
  background: var(--primary-color);
  color: white;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--secondary-color);
  color: white;
}

.btn-secondary:hover {
  background: var(--secondary-hover);
}

.btn-large {
  padding: 15px 30px;
  font-size: 1.1rem;
  width: 100%;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Input fields */
input[type="text"],
input[type="number"] {
  padding: 10px 15px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 1rem;
  flex: 1;
  min-width: 0;
}

input:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Input group */
.input-group {
  display: flex;
  gap: 10px;
  margin-bottom: 15px;
}

/* Names list */
.names-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.name-tag {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--primary-color);
  color: white;
  border-radius: 6px;
  font-size: 0.95rem;
}

.name-tag button {
  background: none;
  border: none;
  color: white;
  cursor: pointer;
  font-size: 1.2rem;
  padding: 0;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background 0.2s;
}

.name-tag button:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* Help text */
.help-text {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 15px;
}

/* Constraint labels in help text */
.constraint-can {
  background: var(--constraint-can);
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 500;
}

.constraint-must {
  background: var(--constraint-must);
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 500;
}

.constraint-cannot {
  background: var(--constraint-cannot);
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 500;
}

/* Matrix */
.matrix-wrapper {
  overflow-x: auto;
  margin-top: 15px;
}

.matrix-table {
  border-collapse: collapse;
  width: 100%;
  min-width: 400px;
}

.matrix-table th,
.matrix-table td {
  border: 1px solid var(--border);
  padding: 10px;
  text-align: center;
  width: 80px;
  min-width: 80px;
  max-width: 80px;
}

.matrix-table th {
  background: var(--background);
  font-weight: 600;
  position: sticky;
  top: 0;
  z-index: 1;
}

.matrix-table tbody th {
  background: var(--background);
  font-weight: 600;
  text-align: left;
  position: sticky;
  left: 0;
}

.matrix-table td {
  cursor: pointer;
  transition: all 0.2s;
  font-weight: 500;
  user-select: none;
}

.matrix-table td:hover:not(.disabled) {
  transform: scale(1.05);
  box-shadow: var(--shadow);
}

.matrix-table td.can {
  background: var(--constraint-can);
  color: #0369a1;
}

.matrix-table td.must {
  background: var(--constraint-must);
  color: #166534;
}

.matrix-table td.cannot {
  background: var(--constraint-cannot);
  color: #991b1b;
}

.matrix-table td.disabled {
  background: #f1f5f9;
  color: var(--text-secondary);
  cursor: not-allowed;
}

/* Seed group */
.seed-group {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 15px;
}

.seed-group label {
  font-weight: 500;
  white-space: nowrap;
}

/* Loading indicator */
.loading {
  text-align: center;
  padding: 20px;
  color: var(--primary-color);
  font-weight: 500;
  font-size: 1.1rem;
}

/* Result section */
.result-section {
  padding: 20px;
  background: var(--background);
  border-radius: 6px;
  margin-top: 20px;
}

.result-chain {
  font-size: 1.2rem;
  font-weight: 500;
  color: var(--primary-color);
  margin-bottom: 15px;
  word-break: break-word;
}

.result-details {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 15px;
}

.result-item {
  padding: 10px 15px;
  background: white;
  border-radius: 6px;
  border-left: 3px solid var(--primary-color);
}

/* Error section */
.error-section {
  padding: 20px;
  background: var(--constraint-cannot);
  border-radius: 6px;
  margin-top: 20px;
}

.error-section h3 {
  color: var(--error-color);
}

#errorMessage {
  color: #991b1b;
  font-weight: 500;
}

/* Footer */
footer {
  text-align: center;
  padding: 20px;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

/* Mobile responsiveness */
@media (max-width: 768px) {
  .container {
    padding: 10px;
  }

  h1 {
    font-size: 2rem;
  }

  .subtitle {
    font-size: 1rem;
  }

  section {
    padding: 20px 15px;
  }

  .input-group {
    flex-direction: column;
  }

  .btn-large {
    padding: 12px 20px;
  }

  .matrix-table th,
  .matrix-table td {
    padding: 8px;
    font-size: 0.9rem;
    width: 70px;
    min-width: 70px;
    max-width: 70px;
  }

  .seed-group {
    flex-direction: column;
    align-items: stretch;
  }

  .seed-group label {
    margin-bottom: 5px;
  }

  .result-chain {
    font-size: 1rem;
  }
}

@media (max-width: 480px) {
  h1 {
    font-size: 1.5rem;
  }

  .matrix-table th,
  .matrix-table td {
    padding: 6px;
    font-size: 0.8rem;
    width: 60px;
    min-width: 60px;
    max-width: 60px;
  }

  .name-tag {
    font-size: 0.85rem;
    padding: 6px 10px;
  }
}
