/**
 * Alpha Generator CSS
 * Styling for the tile-by-tile level generator UI
 */

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
  color: #e2e8f0;
  min-height: 100vh;
}

.app {
  max-width: 1600px;
  margin: 0 auto;
  padding: 20px;
}

/* ============================================
   HEADER
   ============================================ */

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  background: rgba(30, 41, 59, 0.8);
  border-radius: 12px;
  margin-bottom: 24px;
  backdrop-filter: blur(10px);
  flex-wrap: wrap;
  gap: 12px;
}

.header h1 {
  font-size: 1.5rem;
  display: flex;
  align-items: center;
  gap: 10px;
}

.header h1 .icon {
  font-size: 1.8rem;
}

.header-subtitle {
  color: #94a3b8;
  font-size: 0.9rem;
}

.header-actions {
  display: flex;
  gap: 12px;
  align-items: center;
}

.back-link {
  color: #94a3b8;
  text-decoration: none;
  padding: 8px 16px;
  border-radius: 8px;
  transition: all 0.2s;
}

.back-link:hover {
  background: rgba(148, 163, 184, 0.1);
  color: #e2e8f0;
}

/* ============================================
   MAIN LAYOUT
   ============================================ */

.main {
  display: grid;
  grid-template-columns: 300px 1fr 280px;
  gap: 24px;
  margin-bottom: 24px;
}

@media (max-width: 1200px) {
  .main {
    grid-template-columns: 1fr;
  }
}

/* ============================================
   PANELS
   ============================================ */

.panel {
  background: rgba(30, 41, 59, 0.6);
  border-radius: 16px;
  padding: 24px;
  backdrop-filter: blur(10px);
  border: 1px solid rgba(51, 65, 85, 0.5);
}

.panel h2 {
  font-size: 1rem;
  color: #94a3b8;
  margin-bottom: 16px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.panel h3 {
  font-size: 0.875rem;
  color: #64748b;
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* ============================================
   SETTINGS PANEL
   ============================================ */

.setting-group {
  margin-bottom: 20px;
}

.setting-group label {
  display: block;
  font-size: 0.875rem;
  color: #94a3b8;
  margin-bottom: 8px;
}

.dropdown {
  width: 100%;
  padding: 12px 16px;
  background: #1e293b;
  border: 2px solid #334155;
  border-radius: 10px;
  color: #e2e8f0;
  font-size: 1rem;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 20px;
}

.dropdown:focus {
  outline: none;
  border-color: #3b82f6;
}

.dropdown option {
  background: #1e293b;
  padding: 12px;
}

/* Difficulty Buttons */
.difficulty-buttons {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.diff-btn {
  padding: 10px 8px;
  background: #1e293b;
  border: 2px solid #334155;
  border-radius: 8px;
  color: #94a3b8;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 0.8rem;
}

.diff-btn:hover {
  border-color: #475569;
  color: #e2e8f0;
}

.diff-btn.active {
  border-color: #3b82f6;
  background: rgba(59, 130, 246, 0.1);
  color: #60a5fa;
}

/* Size Controls */
.size-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.size-control {
  display: flex;
  align-items: center;
  gap: 8px;
}

.size-control span {
  font-size: 0.875rem;
  color: #94a3b8;
  min-width: 50px;
}

.size-input {
  flex: 1;
  display: flex;
  align-items: center;
  background: #1e293b;
  border: 2px solid #334155;
  border-radius: 8px;
  overflow: hidden;
}

.size-btn {
  width: 32px;
  height: 32px;
  background: transparent;
  border: none;
  color: #94a3b8;
  cursor: pointer;
  font-size: 1.2rem;
  transition: all 0.2s;
}

.size-btn:hover {
  background: rgba(59, 130, 246, 0.1);
  color: #60a5fa;
}

.size-value {
  flex: 1;
  text-align: center;
  font-weight: 600;
  color: #e2e8f0;
}

/* Speed Controls */
.speed-controls {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.speed-btn {
  padding: 8px;
  background: #1e293b;
  border: 2px solid #334155;
  border-radius: 8px;
  color: #94a3b8;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 0.75rem;
}

.speed-btn:hover {
  border-color: #475569;
  color: #e2e8f0;
}

.speed-btn.active {
  border-color: #22c55e;
  background: rgba(34, 197, 94, 0.1);
  color: #4ade80;
}

/* Challenge Checkboxes */
.challenge-checkboxes {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.checkbox-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: #1e293b;
  border: 2px solid #334155;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
}

.checkbox-item:hover {
  border-color: #475569;
  background: #293548;
}

.checkbox-item input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: #3b82f6;
  cursor: pointer;
}

.checkbox-item .checkbox-label {
  font-size: 0.875rem;
  color: #e2e8f0;
}

.checkbox-item:has(input:checked) {
  border-color: rgba(59, 130, 246, 0.5);
  background: rgba(59, 130, 246, 0.1);
}

.checkbox-item:has(input:not(:checked)) .checkbox-label {
  color: #64748b;
}

/* Generate Button */
.generate-btn {
  width: 100%;
  padding: 16px;
  background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
  border: none;
  border-radius: 12px;
  color: white;
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 24px;
}

.generate-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(59, 130, 246, 0.3);
}

.generate-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.generate-btn .spinner {
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Playback Controls */
.playback-controls {
  display: flex;
  gap: 8px;
  margin-top: 16px;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: all 0.2s;
}

.playback-controls.visible {
  opacity: 1;
  visibility: visible;
}

.control-btn {
  width: 44px;
  height: 44px;
  background: #1e293b;
  border: 2px solid #334155;
  border-radius: 10px;
  color: #94a3b8;
  cursor: pointer;
  font-size: 1.2rem;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.control-btn:hover {
  border-color: #475569;
  color: #e2e8f0;
  background: #334155;
}

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

/* Status Message */
.status-message {
  margin-top: 16px;
  padding: 12px;
  border-radius: 8px;
  font-size: 0.875rem;
  text-align: center;
  color: #94a3b8;
  min-height: 44px;
}

.status-message.success {
  background: rgba(34, 197, 94, 0.1);
  color: #4ade80;
}

.status-message.error {
  background: rgba(239, 68, 68, 0.1);
  color: #f87171;
}

.status-message.info {
  background: rgba(59, 130, 246, 0.1);
  color: #60a5fa;
}

/* ============================================
   PREVIEW PANEL
   ============================================ */

.preview-panel {
  display: flex;
  flex-direction: column;
}

.step-counter {
  font-size: 0.875rem;
  color: #60a5fa;
  font-weight: normal;
}

.preview-container {
  flex: 1;
  min-height: 400px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.5);
  border-radius: 12px;
  margin-bottom: 16px;
  overflow: hidden;
}

.empty-state {
  text-align: center;
  color: #475569;
}

.empty-state .icon {
  font-size: 4rem;
  margin-bottom: 16px;
}

/* Validation Display */
.validation-display {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin-bottom: 16px;
  padding: 12px;
  background: rgba(15, 23, 42, 0.5);
  border-radius: 10px;
}

.validation-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 0.875rem;
  color: #94a3b8;
  transition: all 0.2s;
}

.validation-item .val-icon {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: #334155;
  font-size: 0.75rem;
}

.validation-item.valid {
  color: #4ade80;
}

.validation-item.valid .val-icon {
  background: rgba(34, 197, 94, 0.2);
  color: #22c55e;
}

.validation-item.invalid {
  color: #f87171;
}

.validation-item.invalid .val-icon {
  background: rgba(239, 68, 68, 0.2);
  color: #ef4444;
}

.validation-item.warning {
  color: #fbbf24;
}

.validation-item.warning .val-icon {
  background: rgba(251, 191, 36, 0.2);
  color: #f59e0b;
}

/* Action Buttons */
.action-buttons {
  display: none;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.action-buttons.visible {
  display: grid;
}

.action-btn {
  padding: 12px;
  background: #1e293b;
  border: 2px solid #334155;
  border-radius: 10px;
  color: #e2e8f0;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 0.9rem;
}

.action-btn:hover {
  border-color: #475569;
  background: #334155;
}

.action-btn.primary {
  background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%);
  border-color: transparent;
  color: white;
}

.action-btn.primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(34, 197, 94, 0.3);
}

/* ============================================
   STATUS PANEL
   ============================================ */

.status-section {
  margin-bottom: 24px;
}

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

/* Challenge Display */
.challenge-display {
  padding: 16px;
  background: rgba(15, 23, 42, 0.5);
  border-radius: 10px;
  border: 2px solid #334155;
}

.challenge-display.active {
  border-color: #3b82f6;
  background: rgba(59, 130, 246, 0.1);
}

.challenge-display .challenge-type {
  font-weight: 600;
  color: #60a5fa;
  margin-bottom: 4px;
}

.challenge-display .challenge-config {
  font-size: 0.875rem;
  color: #94a3b8;
}

.no-challenge {
  color: #64748b;
  font-style: italic;
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.stat-item {
  display: flex;
  flex-direction: column;
  padding: 12px;
  background: rgba(15, 23, 42, 0.5);
  border-radius: 8px;
}

.stat-label {
  font-size: 0.75rem;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}

.stat-value {
  font-size: 1.25rem;
  font-weight: 700;
  color: #e2e8f0;
}

/* Completed Challenges */
.completed-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.completed-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px;
  background: rgba(34, 197, 94, 0.1);
  border-radius: 8px;
  font-size: 0.875rem;
  color: #4ade80;
}

.completed-item .check {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(34, 197, 94, 0.2);
  border-radius: 50%;
  font-size: 0.75rem;
}

.no-items {
  color: #64748b;
  font-style: italic;
  font-size: 0.875rem;
}

/* ============================================
   BUILD LOG
   ============================================ */

.build-log-section {
  background: rgba(30, 41, 59, 0.6);
  border-radius: 16px;
  padding: 20px;
  backdrop-filter: blur(10px);
  border: 1px solid rgba(51, 65, 85, 0.5);
}

.build-log-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.build-log-header h2 {
  font-size: 1rem;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 0;
}

.clear-btn {
  padding: 6px 12px;
  background: transparent;
  border: 1px solid #334155;
  border-radius: 6px;
  color: #64748b;
  cursor: pointer;
  font-size: 0.8rem;
  transition: all 0.2s;
}

.clear-btn:hover {
  border-color: #475569;
  color: #94a3b8;
}

.build-log {
  max-height: 200px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-right: 8px;
}

.build-log::-webkit-scrollbar {
  width: 6px;
}

.build-log::-webkit-scrollbar-track {
  background: rgba(15, 23, 42, 0.5);
  border-radius: 3px;
}

.build-log::-webkit-scrollbar-thumb {
  background: #334155;
  border-radius: 3px;
}

.build-log::-webkit-scrollbar-thumb:hover {
  background: #475569;
}

.log-entry {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 12px;
  background: rgba(15, 23, 42, 0.5);
  border-radius: 8px;
  font-size: 0.875rem;
  animation: slideIn 0.2s ease-out;
}

.log-entry.placeholder {
  color: #64748b;
  font-style: italic;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.log-step {
  min-width: 36px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #334155;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  color: #94a3b8;
}

.log-entry.start .log-step {
  background: rgba(34, 197, 94, 0.2);
  color: #4ade80;
}

.log-entry.goal .log-step {
  background: rgba(168, 85, 247, 0.2);
  color: #a855f7;
}

.log-entry.gate .log-step {
  background: rgba(239, 68, 68, 0.2);
  color: #f87171;
}

.log-entry.enabler .log-step {
  background: rgba(59, 130, 246, 0.2);
  color: #60a5fa;
}

.log-entry.complete .log-step {
  background: rgba(34, 197, 94, 0.3);
  color: #22c55e;
}

.log-message {
  flex: 1;
  color: #e2e8f0;
  line-height: 1.4;
}

.log-entry.placeholder .log-message {
  color: #64748b;
}

.log-validation {
  display: flex;
  gap: 4px;
  margin-left: auto;
}

.log-validation .val-badge {
  font-size: 0.7rem;
  padding: 2px 6px;
  border-radius: 4px;
}

.val-badge.pass {
  background: rgba(34, 197, 94, 0.2);
  color: #4ade80;
}

.val-badge.warn {
  background: rgba(251, 191, 36, 0.2);
  color: #fbbf24;
}

.val-badge.score {
  background: rgba(59, 130, 246, 0.2);
  color: #60a5fa;
}

/* ============================================
   GRID RENDERING
   ============================================ */

.grid-container {
  display: grid;
  gap: 1px;
  padding: 8px;
  background: rgba(15, 23, 42, 0.8);
  border-radius: 10px;
}

.grid-cell {
  aspect-ratio: 1;
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  transition: all 0.15s ease-out;
  position: relative;
}

.grid-cell.frontier {
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.4); }
  50% { box-shadow: 0 0 0 4px rgba(59, 130, 246, 0); }
}

.grid-cell.new-tile {
  animation: dropIn 0.3s ease-out;
}

@keyframes dropIn {
  from {
    opacity: 0;
    transform: scale(0.5) translateY(-10px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.grid-cell.candidate {
  animation: glow 0.8s ease-in-out infinite alternate;
}

@keyframes glow {
  from { box-shadow: 0 0 5px rgba(251, 191, 36, 0.5); }
  to { box-shadow: 0 0 15px rgba(251, 191, 36, 0.8); }
}

/* Tile Type Colors */
.tile-empty { background: #0f172a; }  /* Darkest - void/unplaced */
.tile-wall { background: #1e293b; }
.tile-ground { background: #334155; }
.tile-start { background: #22c55e; }
.tile-goal { background: #a855f7; }
.tile-win { background: #a855f7; }   /* Same as goal - generator uses 'win' type */
.tile-water { background: #2563eb; }
.tile-heat { background: #dc2626; }
.tile-ice { background: #22d3ee; }
.tile-transform { background: #db2777; }
.tile-key { background: #ca8a04; }
.tile-door { background: #ea580c; }
.tile-frontier { background: rgba(59, 130, 246, 0.3); border: 2px dashed #3b82f6; }
