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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
    Ubuntu, Cantarell, sans-serif;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  min-height: 100vh;
  padding: 20px;
  color: #333;
}

.container {
  max-width: 1400px;
  margin: 0 auto;
}

header {
  text-align: center;
  color: white;
  margin-bottom: 30px;
}

header h1 {
  font-size: 2.5rem;
  margin-bottom: 10px;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

header p {
  font-size: 1.1rem;
  opacity: 0.95;
}

.main-content {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  align-items: start;
}

.panel {
  background: white;
  border-radius: 15px;
  padding: 25px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

.section {
  margin-bottom: 25px;
}

.section:last-child {
  margin-bottom: 0;
}

h2 {
  color: #667eea;
  margin-bottom: 15px;
  font-size: 1.3rem;
}

/* Board Styles */
.board-controls {
  display: flex;
  gap: 10px;
  margin-bottom: 15px;
}

.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 3px;
  background: #e0e0e0;
  padding: 3px;
  border-radius: 8px;
  max-width: 400px;
  margin: 0 auto;
}

.cell {
  aspect-ratio: 1;
  background: white;
  border: 2px solid #ddd;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.cell:hover {
  transform: scale(1.05);
  border-color: #667eea;
}

.cell.filled {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-color: #667eea;
}

.cell.highlight {
  background: #ffd700;
  border-color: #ffaa00;
  animation: pulse 1s infinite;
}

.cell.highlight-1 {
  background: #ffd700 !important;
  border-color: #ffaa00 !important;
  animation: pulse 1s infinite;
  position: relative;
}

.cell.highlight-1::after {
  content: '1';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: #333;
  font-weight: bold;
  font-size: 0.8rem;
}

.cell.highlight-2 {
  background: #ffa500 !important;
  border-color: #ff8c00 !important;
  animation: pulse 1s infinite;
  position: relative;
}

.cell.highlight-2::after {
  content: '2';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: #333;
  font-weight: bold;
  font-size: 0.8rem;
}

.cell.highlight-3 {
  background: #ff6b6b !important;
  border-color: #ff5252 !important;
  animation: pulse 1s infinite;
  position: relative;
}

.cell.highlight-3::after {
  content: '3';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: white;
  font-weight: bold;
  font-size: 0.8rem;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}

/* Block Selection - New Grid Style */
.block-selection-new {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.block-slot-new {
  display: flex;
  flex-direction: column;
}

.block-picker-btn {
  padding: 20px;
  border: 2px solid #ddd;
  border-radius: 8px;
  background: white;
  cursor: pointer;
  transition: all 0.2s;
  min-height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.block-picker-btn:hover {
  border-color: #667eea;
  background: #f8f9ff;
}

.block-preview-empty {
  color: #999;
  font-size: 0.9rem;
}

.block-picker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 10px;
  max-height: 500px;
  overflow-y: auto;
  padding: 10px;
}

.block-grid-item {
  padding: 15px;
  border: 2px solid #ddd;
  border-radius: 8px;
  background: white;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  min-height: 100px;
}

.block-grid-item:hover {
  border-color: #667eea;
  background: #f8f9ff;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.2);
}

.block-grid-item.selected {
  border-color: #667eea;
  background: #667eea;
  color: white;
}

.block-grid-visual {
  display: grid;
  gap: 2px;
  margin: 5px 0;
}

.block-grid-visual-cell {
  width: 12px;
  height: 12px;
  background: #667eea;
  border-radius: 2px;
}

.block-grid-item.selected .block-grid-visual-cell {
  background: white;
}

.block-grid-name {
  font-size: 0.75rem;
  text-align: center;
  font-weight: 500;
}

/* Old Block Selection - Hide */
.block-selection {
  display: none;
}

.block-slot {
  display: none;
}

.block-select {
  display: none; /* Hide default select */
}

.custom-select {
  flex: 1;
  position: relative;
}

.select-display {
  padding: 10px 12px;
  border: 2px solid #ddd;
  border-radius: 6px;
  background: white;
  cursor: pointer;
  transition: border-color 0.2s;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 50px;
}

.select-display:hover {
  border-color: #667eea;
}

.select-display.open {
  border-color: #667eea;
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
}

.select-placeholder {
  color: #999;
  font-style: italic;
}

.select-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: white;
  border: 2px solid #667eea;
  border-top: none;
  border-radius: 0 0 6px 6px;
  max-height: 400px;
  overflow-y: auto;
  z-index: 1000;
  display: none;
  box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.select-dropdown.show {
  display: block;
}

.select-category {
  padding: 8px 12px;
  background: #f8f9fa;
  font-weight: 600;
  color: #667eea;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-top: 1px solid #e0e0e0;
}

.select-category:first-child {
  border-top: none;
}

.select-option {
  padding: 10px 12px;
  cursor: pointer;
  transition: background 0.2s;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid #f0f0f0;
}

.select-option:hover {
  background: #f8f9fa;
}

.select-option:last-child {
  border-bottom: none;
}

.option-visual {
  min-width: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 5px;
}

.option-name {
  flex: 1;
  font-weight: 500;
}

.option-info {
  font-size: 0.85rem;
  color: #999;
}

.block-preview {
  min-width: 80px;
  min-height: 60px;
  background: white;
  border: 2px solid #ddd;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 5px;
}

.block-preview-grid {
  display: grid;
  gap: 2px;
}

.block-preview-cell {
  width: 12px;
  height: 12px;
  background: #667eea;
  border-radius: 2px;
}

/* Buttons */
.btn {
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.btn-primary {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  width: 100%;
  padding: 15px;
  font-size: 1.1rem;
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
  background: #f8f9fa;
  color: #555;
  border: 2px solid #ddd;
  flex: 1;
}

.btn-secondary:hover {
  background: #e9ecef;
  border-color: #667eea;
}

/* Solver Controls */
.solver-controls {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.solver-controls label {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  color: #555;
}

.solver-controls select {
  flex: 1;
  padding: 8px 12px;
  border: 2px solid #ddd;
  border-radius: 6px;
  font-size: 1rem;
}

/* Results */
.results {
  background: #f8f9fa;
  border-radius: 8px;
  padding: 20px;
  min-height: 150px;
}

.results.success {
  background: linear-gradient(135deg, #d4edda 0%, #c3e6cb 100%);
  border: 2px solid #28a745;
}

.results.error {
  background: linear-gradient(135deg, #f8d7da 0%, #f5c6cb 100%);
  border: 2px solid #dc3545;
}

.results .placeholder {
  color: #999;
  text-align: center;
  font-style: italic;
}

.result-item {
  margin-bottom: 10px;
  padding: 10px;
  background: white;
  border-radius: 6px;
}

.result-item strong {
  color: #667eea;
  display: inline-block;
  min-width: 100px;
}

.result-score {
  font-size: 1.5rem;
  font-weight: bold;
  color: #28a745;
  text-align: center;
  margin: 15px 0;
}

.result-rationale {
  background: white;
  padding: 15px;
  border-radius: 6px;
  border-left: 4px solid #667eea;
  margin-top: 10px;
  font-style: italic;
}

.move-sequence {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.move-card {
  background: white;
  border: 2px solid #ddd;
  border-radius: 8px;
  padding: 15px;
  transition: all 0.3s ease;
}

.move-card.active {
  border-color: #667eea;
  background: linear-gradient(135deg, #f8f9ff 0%, #fff 100%);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.2);
}

.move-card.completed {
  opacity: 0.6;
  border-color: #28a745;
  background: #f0f8f0;
}

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

.move-number {
  font-size: 1.2rem;
  font-weight: bold;
  color: #667eea;
}

.move-status {
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 0.85rem;
  font-weight: 600;
}

.move-status.pending {
  background: #fff3cd;
  color: #856404;
}

.move-status.active {
  background: #667eea;
  color: white;
}

.move-status.completed {
  background: #28a745;
  color: white;
}

.move-details {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-top: 10px;
}

.move-detail {
  font-size: 0.9rem;
}

.move-detail strong {
  color: #667eea;
}

/* Quick Actions */
.quick-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Modal */
.modal {
  display: none;
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.7);
  overflow-y: auto;
}

.modal.show {
  display: block;
}

.modal-content {
  background-color: white;
  margin: 50px auto;
  padding: 30px;
  border-radius: 15px;
  width: 90%;
  max-width: 800px;
  max-height: 80vh;
  overflow-y: auto;
  position: relative;
}

.close {
  color: #aaa;
  float: right;
  font-size: 28px;
  font-weight: bold;
  cursor: pointer;
  line-height: 20px;
}

.close:hover {
  color: #000;
}

.block-library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 20px;
  margin-top: 20px;
}

.block-library-item {
  background: #f8f9fa;
  padding: 15px;
  border-radius: 8px;
  text-align: center;
  border: 2px solid #ddd;
}

.block-library-item h3 {
  color: #667eea;
  margin-bottom: 10px;
  font-size: 1rem;
}

.block-library-preview {
  background: white;
  padding: 10px;
  border-radius: 6px;
  display: inline-block;
  margin-bottom: 5px;
}

.block-library-info {
  font-size: 0.85rem;
  color: #666;
}

/* Loading State */
.loading {
  text-align: center;
  padding: 20px;
}

.spinner {
  border: 4px solid #f3f3f3;
  border-top: 4px solid #667eea;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  animation: spin 1s linear infinite;
  margin: 0 auto;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

/* Toggle Switch */
.switch {
  position: relative;
  display: inline-block;
  width: 60px;
  height: 34px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  transition: 0.4s;
  border-radius: 34px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 26px;
  width: 26px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  transition: 0.4s;
  border-radius: 50%;
}

input:checked + .slider {
  background-color: #4CAF50;
}

input:focus + .slider {
  box-shadow: 0 0 1px #4CAF50;
}

input:checked + .slider:before {
  transform: translateX(26px);
}

/* Responsive */
@media (max-width: 968px) {
  .main-content {
    grid-template-columns: 1fr;
  }

  header h1 {
    font-size: 2rem;
  }

  .board {
    max-width: 100%;
  }
}

@media (max-width: 480px) {
  body {
    padding: 10px;
  }

  .panel {
    padding: 15px;
  }

  header h1 {
    font-size: 1.5rem;
  }

  .block-slot {
    flex-direction: column;
    align-items: stretch;
  }
}

/* Custom block editor */
.custom-editor { text-align: center; grid-column: 1 / -1; } /* span full picker grid */
.custom-actions .btn { white-space: nowrap; }
.custom-grid {
  display: grid;
  grid-template-columns: repeat(5, 44px);
  gap: 4px;
  justify-content: center;
  margin: 15px 0;
}
.custom-cell {
  width: 44px;
  height: 44px;
  border: 2px solid #ddd;
  border-radius: 6px;
  background: #f5f5f5;
  cursor: pointer;
}
.custom-cell.on { background: #667eea; border-color: #4c5fd5; }
.custom-actions { display: flex; gap: 10px; justify-content: center; }
.custom-tile { border-style: dashed; justify-content: center; }
