* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  min-height: 100vh;
  padding: 20px;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  background: rgba(255, 255, 255, 0.95);
  border-radius: 15px;
  padding: 30px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

h1 {
  text-align: center;
  color: #333;
  margin-bottom: 30px;
  font-size: 2.5em;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
}

.controls {
  display: grid;
  grid-template-columns: 1fr 2fr 1fr;
  gap: 30px;
  margin-bottom: 40px;
}

.board-config {
  background: #f8f9fa;
  padding: 20px;
  border-radius: 10px;
  border: 2px solid #e9ecef;
}

.board-config h3 {
  margin-bottom: 15px;
  color: #495057;
}

.board-config label {
  display: block;
  margin-bottom: 10px;
  font-weight: 500;
  color: #495057;
}

.board-config input {
  width: 80px;
  padding: 8px;
  margin-left: 10px;
  border: 2px solid #dee2e6;
  border-radius: 5px;
  font-size: 16px;
}

.board-config input:focus {
  outline: none;
  border-color: #007bff;
}

.dimension-control {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.auto-checkbox {
  font-size: 12px;
  margin-left: 10px;
  display: flex;
  align-items: center;
  gap: 4px;
  color: #666;
}

.auto-checkbox input[type='checkbox'] {
  width: auto;
  margin: 0;
  margin-right: 4px;
}

.board-config input[type='number']:disabled {
  background-color: #e9ecef;
  cursor: not-allowed;
}

.polyomino-selection {
  background: #f8f9fa;
  padding: 20px;
  border-radius: 10px;
  border: 2px solid #e9ecef;
}

.polyomino-selection h3 {
  margin-bottom: 15px;
  color: #495057;
}

.polyomino-buttons {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 10px;
  margin-bottom: 20px;
}

.polyomino-btn {
  padding: 8px;
  border: 2px solid #007bff;
  background: white;
  border-radius: 8px;
  color: #007bff;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  min-height: 80px;
  justify-content: center;
}

/* Removed old polyomino-shape styles that conflict with unified approach */

.polyomino-label {
  font-size: 12px;
  font-weight: bold;
  margin-top: 2px;
}

.polyomino-btn:hover {
  background: #007bff;
  color: white;
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 123, 255, 0.3);
}

.polyomino-btn.selected {
  background: #28a745;
  border-color: #28a745;
  color: white;
}

/* Unified polyomino shape styles */
.polyomino-shape {
  width: 40px;
  height: 30px;
}

.selected-pieces {
  margin-top: 15px;
}

.selected-pieces h4 {
  margin-bottom: 10px;
  color: #495057;
}

#selected-list {
  padding: 10px;
  background: white;
  border: 2px solid #dee2e6;
  border-radius: 5px;
  min-height: 40px;
  font-family: monospace;
  font-size: 16px;
}

.actions {
  background: #f8f9fa;
  padding: 20px;
  border-radius: 10px;
  border: 2px solid #e9ecef;
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.actions button {
  padding: 15px 20px;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.3s ease;
}

#solve-btn {
  background: #007bff;
  color: white;
}

#solve-btn:hover {
  background: #0056b3;
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 123, 255, 0.3);
}

#solve-btn:disabled {
  background: #6c757d;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

#clear-btn {
  background: #dc3545;
  color: white;
}

#clear-btn:hover {
  background: #c82333;
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(220, 53, 69, 0.3);
}

.result-area {
  margin-top: 30px;
}

.status {
  background: #e9ecef;
  padding: 15px;
  border-radius: 8px;
  margin-bottom: 20px;
  text-align: center;
}

#status-message {
  font-size: 18px;
  font-weight: 500;
  color: #495057;
}

.status.success {
  background: #d4edda;
  color: #155724;
}

.status.error {
  background: #f8d7da;
  color: #721c24;
}

.status.loading {
  background: #fff3cd;
  color: #856404;
}

.visualization h3 {
  margin-bottom: 20px;
  color: #333;
  text-align: center;
}

#board-container {
  display: flex;
  justify-content: center;
  margin-top: 20px;
}

#board {
  display: grid;
  gap: 2px;
  background: #333;
  padding: 10px;
  border-radius: 8px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.cell {
  width: 30px;
  height: 30px;
  border-radius: 3px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  position: relative;
  transition: all 0.3s ease;
}

.cell.empty {
  background: #f8f9fa;
}

.cell.piece-0 {
  background: #ff6b6b;
}
.cell.piece-1 {
  background: #4ecdc4;
}
.cell.piece-2 {
  background: #45b7d1;
}
.cell.piece-3 {
  background: #f9ca24;
}
.cell.piece-4 {
  background: #f0932b;
}
.cell.piece-5 {
  background: #eb4d4b;
}
.cell.piece-6 {
  background: #6c5ce7;
}
.cell.piece-7 {
  background: #a29bfe;
}
.cell.piece-8 {
  background: #fd79a8;
}
.cell.piece-9 {
  background: #fdcb6e;
}
.cell.piece-10 {
  background: #e84393;
}
.cell.piece-11 {
  background: #00b894;
}

.cell:hover {
  transform: scale(1.1);
  z-index: 10;
}

/* Custom Mino Styles */
.custom-mino-section {
  margin: 15px 0;
  text-align: center;
}

.add-mino-btn {
  padding: 10px 20px;
  background: #17a2b8;
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.3s ease;
}

.add-mino-btn:hover {
  background: #138496;
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(23, 162, 184, 0.3);
}

/* Modal Styles */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: white;
  border-radius: 15px;
  padding: 0;
  max-width: 600px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 25px;
  border-bottom: 2px solid #e9ecef;
  background: #f8f9fa;
  border-radius: 15px 15px 0 0;
}

.modal-header h3 {
  margin: 0;
  color: #333;
}

.close-btn {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: #666;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: all 0.3s ease;
}

.close-btn:hover {
  background: #e9ecef;
  color: #333;
}

.modal-body {
  padding: 25px;
}

.editor-section {
  margin-bottom: 25px;
}

.editor-section h4 {
  margin-bottom: 10px;
  color: #333;
}

.editor-instructions {
  font-size: 14px;
  color: #666;
  margin-bottom: 15px;
  font-style: italic;
}

.mino-editor {
  display: grid;
  gap: 2px;
  background: #333;
  padding: 10px;
  border-radius: 8px;
  justify-content: start;
  width: fit-content;
  margin: 0 auto 20px auto;
}

.editor-cell {
  width: 25px;
  height: 25px;
  background: #f8f9fa;
  border: 2px solid #dee2e6;
  border-radius: 3px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.editor-cell:hover {
  transform: scale(1.1);
  border-color: #007bff;
}

.editor-cell.active {
  background: #007bff;
  border-color: #0056b3;
}

.editor-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 15px;
}

.editor-inputs {
  display: flex;
  gap: 15px;
  flex-wrap: wrap;
}

.editor-inputs label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
  color: #495057;
}

.editor-inputs input,
.editor-inputs select {
  padding: 6px 10px;
  border: 2px solid #dee2e6;
  border-radius: 5px;
  font-size: 14px;
}

.editor-inputs input:focus,
.editor-inputs select:focus {
  outline: none;
  border-color: #007bff;
}

.editor-buttons {
  display: flex;
  gap: 10px;
}

.editor-buttons button {
  padding: 8px 16px;
  border: none;
  border-radius: 5px;
  font-size: 14px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.3s ease;
}

#clear-editor-btn {
  background: #dc3545;
  color: white;
}

#clear-editor-btn:hover {
  background: #c82333;
}

#save-mino-btn {
  background: #28a745;
  color: white;
}

#save-mino-btn:hover {
  background: #218838;
}

.editor-preview {
  border-top: 2px solid #e9ecef;
  padding-top: 20px;
}

.editor-preview h4 {
  margin-bottom: 15px;
  color: #333;
}

#mino-preview {
  display: grid;
  gap: 1px;
  background: #333;
  padding: 8px;
  border-radius: 5px;
  justify-content: start;
  width: fit-content;
  margin: 0 auto;
}

.preview-cell {
  width: 15px;
  height: 15px;
  background: #f8f9fa;
  border-radius: 2px;
}

.preview-cell.active {
  background: #007bff;
}

/* Custom polyomino button styles */
.custom-shape {
  width: 40px;
  height: 30px;
}

.polyomino-active-cell {
  background: #007bff;
}

.polyomino-empty-cell {
  background: transparent;
}

.polyomino-btn:hover .polyomino-active-cell {
  background: white !important;
}

.polyomino-btn.selected .polyomino-active-cell {
  background: white !important;
}

.polyomino-btn:hover .polyomino-empty-cell,
.polyomino-btn.selected .polyomino-empty-cell {
  background: transparent !important;
}

/* Custom polyomino delete button */
.custom-mino-btn {
  position: relative;
}

.delete-mino-btn {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  background: #dc3545;
  color: white;
  border: none;
  border-radius: 50%;
  font-size: 12px;
  font-weight: bold;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  z-index: 10;
  padding: 0;
  line-height: 1;
}

.delete-mino-btn:hover {
  background: #c82333;
  transform: scale(1.1);
  box-shadow: 0 2px 4px rgba(220, 53, 69, 0.4);
}

.custom-mino-btn:hover .delete-mino-btn {
  opacity: 1;
}

.delete-mino-btn:focus {
  outline: 2px solid #fff;
  outline-offset: 1px;
}

@media (max-width: 768px) {
  .controls {
    grid-template-columns: 1fr;
    gap: 20px;
  }

  .polyomino-buttons {
    grid-template-columns: repeat(4, 1fr);
  }

  .container {
    padding: 20px;
  }

  h1 {
    font-size: 2em;
  }

  .modal-content {
    width: 95%;
    margin: 10px;
  }

  .editor-controls {
    flex-direction: column;
    align-items: stretch;
  }

  .editor-inputs {
    justify-content: center;
  }

  .editor-buttons {
    justify-content: center;
  }
}
