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

:root {
  --bg-dark: #0a0a12;
  --bg-panel: rgba(26, 26, 46, 0.85);
  --bg-card: rgba(40, 40, 70, 0.6);
  --accent-primary: #8b5cf6;
  --accent-secondary: #06b6d4;
  --accent-gradient: linear-gradient(135deg, #8b5cf6, #06b6d4);
  --text-primary: #ffffff;
  --text-secondary: #a0a0c0;
  --border-color: rgba(139, 92, 246, 0.3);
  --glow-purple: rgba(139, 92, 246, 0.5);
  --glow-cyan: rgba(6, 182, 212, 0.5);
}

body {
  font-family: 'Space Grotesk', sans-serif;
  background: var(--bg-dark);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
}

body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: 
    radial-gradient(circle at 20% 20%, rgba(139, 92, 246, 0.15) 0%, transparent 40%),
    radial-gradient(circle at 80% 80%, rgba(6, 182, 212, 0.1) 0%, transparent 40%),
    radial-gradient(circle at 50% 50%, rgba(30, 30, 50, 0.5) 0%, transparent 60%);
  pointer-events: none;
  z-index: 0;
}

#app {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.header {
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
  padding: 1.25rem 2rem;
  border-bottom: 1px solid var(--border-color);
  text-align: center;
}

.logo {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.sparkle {
  -webkit-text-fill-color: initial;
  animation: sparkle 2s ease-in-out infinite;
}

@keyframes sparkle {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.7; transform: scale(1.2); }
}

.tagline {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-top: 0.25rem;
  font-weight: 300;
}

/* Main Layout */
.main-container {
  display: grid;
  grid-template-columns: 280px 1fr 280px;
  gap: 1.5rem;
  padding: 1.5rem;
  flex: 1;
}

/* Sidebar */
.sidebar {
  background: var(--bg-panel);
  backdrop-filter: blur(20px);
  border-radius: 16px;
  padding: 1.25rem;
  border: 1px solid var(--border-color);
  height: fit-content;
  max-height: calc(100vh - 180px);
  overflow-y: auto;
}

.sidebar::-webkit-scrollbar {
  width: 6px;
}

.sidebar::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar::-webkit-scrollbar-thumb {
  background: var(--accent-primary);
  border-radius: 3px;
}

.section-title {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-secondary);
  margin-bottom: 1rem;
}

.subsection-title {
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}

/* Theme Grid */
.theme-grid {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

.theme-card {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--bg-card);
  border: 1px solid transparent;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.theme-card:hover {
  background: rgba(139, 92, 246, 0.15);
  border-color: var(--accent-primary);
}

.theme-card.active {
  background: rgba(139, 92, 246, 0.25);
  border-color: var(--accent-primary);
  box-shadow: 0 0 20px var(--glow-purple);
}

.theme-icon {
  font-size: 1.5rem;
}

.theme-name {
  font-size: 0.9rem;
  font-weight: 500;
}

/* Palette Grid */
.palette-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.palette-btn {
  padding: 0.5rem;
  background: var(--bg-card);
  border: 2px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.palette-btn:hover {
  border-color: var(--accent-secondary);
}

.palette-btn.active {
  border-color: var(--accent-primary);
  box-shadow: 0 0 15px var(--glow-purple);
}

.palette-swatches {
  display: flex;
  gap: 2px;
  height: 24px;
}

.swatch {
  flex: 1;
  border-radius: 3px;
}

.palette-btn.custom {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 40px;
}

.custom-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

/* Custom Palette */
.custom-palette {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-color);
}

.custom-colors {
  display: flex;
  gap: 0.5rem;
}

.color-picker {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  background: transparent;
}

.color-picker::-webkit-color-swatch-wrapper {
  padding: 0;
}

.color-picker::-webkit-color-swatch {
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-radius: 6px;
}

/* Preview Section */
.preview-section {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.preview-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.view-toggle, .zoom-controls {
  display: flex;
  gap: 0.25rem;
  background: var(--bg-panel);
  padding: 0.25rem;
  border-radius: 8px;
}

.toggle-btn, .zoom-btn {
  padding: 0.5rem 1rem;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.8rem;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.toggle-btn:hover, .zoom-btn:hover {
  color: var(--text-primary);
}

.toggle-btn.active, .zoom-btn.active {
  background: var(--accent-primary);
  color: white;
}

.canvas-wrapper {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  background: var(--bg-panel);
  border-radius: 16px;
  padding: 2rem;
  min-height: 400px;
  overflow: hidden;
  position: relative;
  border: 1px solid var(--border-color);
}

.canvas-wrapper::before {
  content: '';
  position: absolute;
  inset: 0;
  background: 
    linear-gradient(45deg, rgba(50, 50, 70, 0.3) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(50, 50, 70, 0.3) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(50, 50, 70, 0.3) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(50, 50, 70, 0.3) 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
  opacity: 0.5;
}

#previewCanvas, #tiledCanvas {
  position: relative;
  z-index: 1;
  border-radius: 4px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
  transition: transform 0.3s ease;
  image-rendering: pixelated;
}

.output-info {
  display: flex;
  justify-content: center;
  gap: 2rem;
  padding: 0.75rem;
  background: var(--bg-panel);
  border-radius: 8px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.75rem;
}

.info-item {
  display: flex;
  gap: 0.5rem;
}

.info-label {
  color: var(--text-secondary);
}

.info-value {
  color: var(--text-primary);
}

.status-ok {
  color: #10b981;
}

.action-buttons {
  display: flex;
  gap: 1rem;
  justify-content: center;
}

.action-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.875rem 1.5rem;
  border: none;
  border-radius: 12px;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
}

.btn-icon {
  font-size: 1.1rem;
}

.regenerate-btn {
  background: linear-gradient(135deg, #3b82f6, #1d4ed8);
  color: white;
}

.regenerate-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(59, 130, 246, 0.4);
}

.download-btn {
  background: linear-gradient(135deg, #10b981, #059669);
  color: white;
}

.download-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(16, 185, 129, 0.4);
}

.save-btn {
  background: linear-gradient(135deg, #8b5cf6, #6d28d9);
  color: white;
}

.save-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(139, 92, 246, 0.4);
}

/* Control Groups */
.control-group {
  margin-bottom: 1.25rem;
}

.control-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
  font-weight: 500;
  margin-bottom: 0.5rem;
}

.control-value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.75rem;
  color: var(--accent-secondary);
}

.slider {
  width: 100%;
  height: 6px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--bg-card);
  border-radius: 3px;
  outline: none;
}

.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  background: var(--accent-gradient);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 2px 10px var(--glow-purple);
  transition: transform 0.2s ease;
}

.slider::-webkit-slider-thumb:hover {
  transform: scale(1.15);
}

.slider-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.65rem;
  color: var(--text-secondary);
  margin-top: 0.25rem;
}

/* Radio Group */
.radio-group {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.5rem;
}

.radio-option {
  flex: 1;
  min-width: 70px;
}

.radio-option input {
  display: none;
}

.radio-label {
  display: block;
  padding: 0.5rem;
  text-align: center;
  font-size: 0.75rem;
  background: var(--bg-card);
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.radio-option input:checked + .radio-label {
  border-color: var(--accent-primary);
  background: rgba(139, 92, 246, 0.2);
}

.bg-color-picker {
  width: 100%;
  height: 32px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
}

/* Style Buttons */
.style-buttons {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
}

.style-btn {
  padding: 0.5rem;
  background: var(--bg-card);
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.style-btn:hover {
  color: var(--text-primary);
  border-color: var(--accent-secondary);
}

.style-btn.active {
  color: var(--text-primary);
  border-color: var(--accent-primary);
  background: rgba(139, 92, 246, 0.2);
}

.seed-input {
  width: 100%;
  padding: 0.5rem;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  color: var(--text-primary);
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.85rem;
  outline: none;
  transition: border-color 0.2s ease;
}

.seed-input:focus {
  border-color: var(--accent-primary);
}

.seed-input::placeholder {
  color: var(--text-secondary);
}

/* Footer */
.footer {
  text-align: center;
  padding: 1.25rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
  border-top: 1px solid var(--border-color);
}

.footer a {
  color: var(--accent-primary);
  text-decoration: none;
  transition: color 0.2s ease;
}

.footer a:hover {
  color: var(--accent-secondary);
}

/* Notification */
.notification {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--accent-gradient);
  color: white;
  padding: 0.875rem 1.5rem;
  border-radius: 10px;
  font-weight: 500;
  box-shadow: 0 10px 40px rgba(139, 92, 246, 0.4);
  opacity: 0;
  transition: all 0.3s ease;
  z-index: 1000;
}

.notification.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* Mobile Responsive */
@media (max-width: 1100px) {
  .main-container {
    grid-template-columns: 1fr;
    padding: 1rem;
  }
  
  .sidebar {
    max-height: none;
  }
  
  .left-sidebar {
    order: 2;
  }
  
  .preview-section {
    order: 1;
  }
  
  .right-sidebar {
    order: 3;
  }
  
  .theme-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
  }
  
  .theme-card {
    flex-direction: column;
    text-align: center;
    padding: 0.75rem 0.5rem;
  }
  
  .palette-grid {
    grid-template-columns: repeat(3, 1fr);
  }
  
  .action-buttons {
    flex-wrap: wrap;
  }
  
  .action-btn {
    flex: 1;
    min-width: 140px;
    justify-content: center;
  }
}

@media (max-width: 600px) {
  .header {
    padding: 1rem;
  }
  
  .logo {
    font-size: 1.4rem;
  }
  
  .theme-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .palette-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .output-info {
    flex-direction: column;
    gap: 0.5rem;
    align-items: center;
  }
  
  .preview-controls {
    flex-direction: column;
  }
  
  .canvas-wrapper {
    padding: 1rem;
    min-height: 300px;
  }
  
  .action-btn {
    padding: 0.75rem 1rem;
    font-size: 0.85rem;
  }
}