:root {
  --bg-dark: #08080a;
  --bg-panel: #0e0e11;
  --bg-card: #141418;
  --bg-hover: #1a1a1f;
  --border: #222228;
  --border-light: #333340;
  --text: #f8f8fc;
  --text-dim: #a8a8b8;
  --text-muted: #666680;
  --accent: #c4a0ff;
  --accent-dim: #8b5cf6;
  --accent-glow: rgba(196, 160, 255, 0.12);
  --success: #4ade80;
  --success-glow: rgba(74, 222, 128, 0.15);
  --gradient-1: #8b5cf6;
  --gradient-2: #c084fc;
  --gradient-3: #e879f9;
  --gold: #fbbf24;
  --gold-dim: #d97706;
}

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

body {
  font-family: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-dark);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

.app-wrapper {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
}

.ambient-bg {
  position: fixed;
  inset: 0;
  background: 
    radial-gradient(ellipse 100% 80% at 10% 10%, rgba(139, 92, 246, 0.06) 0%, transparent 50%),
    radial-gradient(ellipse 80% 60% at 90% 90%, rgba(232, 121, 249, 0.04) 0%, transparent 50%),
    radial-gradient(ellipse 60% 40% at 50% 50%, rgba(196, 160, 255, 0.02) 0%, transparent 40%);
  pointer-events: none;
  z-index: 0;
}

/* Header */
.app-header {
  background: rgba(14, 14, 17, 0.85);
  backdrop-filter: blur(24px);
  border-bottom: 1px solid var(--border);
  padding: 1rem 2rem;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-content {
  max-width: 1800px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 2rem;
}

.logo-section {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.logo-icon {
  font-size: 2.25rem;
  background: linear-gradient(135deg, var(--gradient-1), var(--gradient-3));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 0 20px rgba(139, 92, 246, 0.4));
}

.app-title {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--text) 0%, var(--accent) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.app-subtitle {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  margin-top: 2px;
}

.header-badges {
  display: flex;
  gap: 0.75rem;
}

.header-badge {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.7rem;
  color: var(--text-dim);
  background: var(--bg-card);
  padding: 0.5rem 1rem;
  border-radius: 2rem;
  border: 1px solid var(--border);
}

.header-badge.quality-badge {
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.15), rgba(232, 121, 249, 0.1));
  border-color: rgba(196, 160, 255, 0.3);
  color: var(--accent);
}

.badge-icon {
  font-size: 0.9rem;
}

.badge-dot {
  width: 4px;
  height: 4px;
  background: var(--accent);
  border-radius: 50%;
  box-shadow: 0 0 6px var(--accent);
}

/* Main Layout */
.main-content {
  flex: 1;
  display: grid;
  grid-template-columns: 340px 1fr 300px;
  gap: 1px;
  background: var(--border);
  position: relative;
  z-index: 1;
}

/* Control Panel */
.control-panel {
  background: var(--bg-panel);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  overflow-y: auto;
  max-height: calc(100vh - 64px);
}

.panel-section {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.section-label {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--text-muted);
  font-weight: 600;
}

.label-icon {
  font-family: 'IBM Plex Mono', monospace;
  background: linear-gradient(135deg, var(--gradient-1), var(--gradient-2));
  padding: 0.3rem 0.6rem;
  border-radius: 4px;
  color: white;
  font-size: 0.6rem;
  font-weight: 700;
}

/* Theme Items */
.themes-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.theme-item {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.85rem 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: left;
  color: var(--text);
}

.theme-item:hover {
  background: var(--bg-hover);
  border-color: var(--border-light);
  transform: translateX(2px);
}

.theme-item.active {
  background: var(--accent-glow);
  border-color: var(--accent);
  box-shadow: 0 0 20px rgba(196, 160, 255, 0.1);
}

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

.theme-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

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

.theme-desc {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.check-icon {
  color: var(--accent);
  font-weight: bold;
  font-size: 1rem;
}

/* Palette Grid */
.palettes-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
}

.palette-item {
  aspect-ratio: 1;
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  border: 2px solid transparent;
  transition: all 0.2s ease;
  padding: 0;
  background: none;
}

.palette-item:hover {
  transform: scale(1.08);
  z-index: 1;
}

.palette-item.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow), 0 4px 12px rgba(0,0,0,0.3);
}

.palette-colors {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(2, 1fr);
  height: 100%;
}

.palette-colors .palette-swatch:nth-child(4) {
  grid-column: span 2;
}

.palette-colors .palette-swatch:nth-child(5) {
  grid-column: span 1;
}

.palette-swatch {
  width: 100%;
  height: 100%;
}

/* Custom Toggle */
.custom-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.7rem 1rem;
  background: var(--bg-card);
  border: 1px dashed var(--border-light);
  border-radius: 10px;
  color: var(--text-dim);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s ease;
  margin-top: 0.5rem;
}

.custom-toggle:hover {
  border-color: var(--accent);
  color: var(--text);
}

.custom-toggle.active {
  background: var(--accent-glow);
  border-style: solid;
  border-color: var(--accent);
  color: var(--text);
}

.toggle-check {
  color: var(--accent);
}

.custom-colors {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.4rem;
  margin-top: 0.5rem;
}

.color-input-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
}

.color-input {
  width: 100%;
  aspect-ratio: 1;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  padding: 0;
  background: none;
}

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

.color-input::-webkit-color-swatch {
  border: 2px solid var(--border);
  border-radius: 8px;
}

.color-hex {
  font-size: 0.5rem;
  font-family: 'IBM Plex Mono', monospace;
  color: var(--text-muted);
}

/* Density Options */
.density-options {
  display: flex;
  gap: 0.5rem;
}

.density-item {
  flex: 1;
  padding: 0.7rem 0.5rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: center;
  color: var(--text);
}

.density-item:hover {
  border-color: var(--border-light);
}

.density-item.active {
  background: var(--accent-glow);
  border-color: var(--accent);
}

.density-name {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  margin-bottom: 0.2rem;
}

.density-desc {
  display: block;
  font-size: 0.6rem;
  color: var(--text-muted);
}

/* Generate Section */
.generate-section {
  margin-top: auto;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}

.btn-generate {
  width: 100%;
  padding: 1.1rem;
  font-size: 0.95rem;
  font-weight: 600;
  background: linear-gradient(135deg, var(--gradient-1), var(--gradient-2), var(--gradient-3));
  background-size: 200% 200%;
  animation: gradient-shift 3s ease infinite;
  border: none;
  border-radius: 12px;
  color: white;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 20px rgba(139, 92, 246, 0.3);
}

@keyframes gradient-shift {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}

.btn-generate:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 8px 30px rgba(139, 92, 246, 0.5);
}

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

.generating-state {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
}

.spinner {
  width: 18px;
  height: 18px;
  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); }
}

.progress-container {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.85rem;
}

.progress-bar {
  flex: 1;
  height: 6px;
  background: var(--bg-card);
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--gradient-1), var(--gradient-2), var(--gradient-3));
  transition: width 0.3s ease;
  border-radius: 3px;
}

.progress-text {
  font-size: 0.7rem;
  font-family: 'IBM Plex Mono', monospace;
  color: var(--accent);
  min-width: 32px;
}

/* Preview Panel */
.preview-panel {
  background: var(--bg-dark);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.preview-header h2 {
  font-size: 0.9rem;
  font-weight: 500;
}

.preview-controls {
  display: flex;
  background: var(--bg-card);
  border-radius: 8px;
  padding: 3px;
  border: 1px solid var(--border);
}

.view-toggle {
  padding: 0.45rem 0.85rem;
  font-size: 0.75rem;
  border: none;
  background: none;
  color: var(--text-dim);
  border-radius: 5px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.view-toggle.active {
  background: var(--accent);
  color: white;
}

/* Preview Canvas */
.preview-canvas {
  flex: 1;
  min-height: 420px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.pattern-view {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.pattern-view.tiled {
  background-position: center;
}

.pattern-view.single {
  padding: 1.5rem;
}

.pattern-image {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 10px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}

/* Loading State */
.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.75rem;
}

.loading-animation {
  position: relative;
  width: 90px;
  height: 90px;
}

.loading-ring {
  position: absolute;
  inset: 0;
  border: 2px solid transparent;
  border-top-color: var(--gradient-1);
  border-radius: 50%;
  animation: spin 1.5s linear infinite;
}

.loading-ring.ring-2 {
  inset: 10px;
  border-top-color: var(--gradient-2);
  animation-duration: 2s;
  animation-direction: reverse;
}

.loading-ring.ring-3 {
  inset: 20px;
  border-top-color: var(--gradient-3);
  animation-duration: 2.5s;
}

.loading-text {
  font-size: 0.95rem;
  color: var(--text);
  font-weight: 500;
}

.loading-subtext {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Empty State */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.85rem;
  color: var(--text-muted);
  padding: 2rem;
}

.empty-icon {
  font-size: 3.5rem;
  background: linear-gradient(135deg, var(--gradient-1), var(--gradient-3));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: pulse 3s ease-in-out infinite;
}

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

.empty-title {
  font-size: 1.1rem;
  font-weight: 500;
  color: var(--text-dim);
}

.empty-desc {
  font-size: 0.85rem;
}

.empty-features {
  display: flex;
  gap: 1.25rem;
  margin-top: 0.75rem;
  font-size: 0.75rem;
  color: var(--accent);
}

/* Preview Actions */
.preview-actions {
  display: flex;
  gap: 0.85rem;
}

.btn-secondary {
  flex: 1;
  padding: 0.85rem 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-secondary:hover:not(:disabled) {
  background: var(--bg-hover);
  border-color: var(--border-light);
}

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

.btn-primary {
  flex: 2;
  padding: 0.85rem 1rem;
  background: linear-gradient(135deg, var(--success), #22c55e);
  border: none;
  border-radius: 10px;
  color: #0a0a0b;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 4px 16px rgba(74, 222, 128, 0.25);
}

.btn-primary:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 6px 24px rgba(74, 222, 128, 0.35);
}

.btn-primary:disabled {
  opacity: 0.7;
  cursor: wait;
}

/* Prompt Section */
.prompt-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.prompt-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1rem;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 0.8rem;
  cursor: pointer;
  transition: color 0.2s ease;
}

.prompt-toggle:hover {
  color: var(--text);
}

.arrow-up {
  transform: rotate(180deg);
}

.prompt-content {
  padding: 0 1rem 1rem;
  font-size: 0.72rem;
  line-height: 1.7;
  color: var(--text-muted);
  font-family: 'IBM Plex Mono', monospace;
}

.copy-prompt-btn {
  margin-top: 0.75rem;
  padding: 0.5rem 0.85rem;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-dim);
  font-size: 0.7rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.copy-prompt-btn:hover {
  background: var(--accent-glow);
  border-color: var(--accent);
  color: var(--accent);
}

/* Info Panel */
.info-panel {
  background: var(--bg-panel);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  overflow-y: auto;
  max-height: calc(100vh - 64px);
}

.selection-card,
.specs-card,
.history-card,
.usecases-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
}

.selection-card h3,
.specs-card h3,
.history-card h3,
.usecases-card h3 {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin-bottom: 0.85rem;
  font-weight: 600;
}

.selection-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.9rem;
  margin-bottom: 0.65rem;
}

.sel-icon {
  font-size: 1.35rem;
}

.selection-colors {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  flex-wrap: wrap;
  margin-bottom: 0.65rem;
}

.sel-swatch {
  width: 22px;
  height: 22px;
  border-radius: 5px;
  border: 1px solid var(--border);
}

.sel-palette-name {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-left: 0.5rem;
}

.selection-density {
  display: flex;
  gap: 0.5rem;
  font-size: 0.75rem;
  color: var(--text-dim);
}

.density-value {
  color: var(--accent);
  font-weight: 500;
}

/* Specs */
.spec-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.75rem;
}

.spec-row:last-child {
  border-bottom: none;
}

.spec-row span:first-child {
  color: var(--text-dim);
}

.spec-value {
  font-family: 'IBM Plex Mono', monospace;
  color: var(--text);
}

.spec-value.highlight {
  color: var(--gold);
}

.spec-check {
  color: var(--success) !important;
}

/* Use Cases */
.usecase-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.usecase-tag {
  padding: 0.35rem 0.65rem;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 0.65rem;
  color: var(--text-dim);
}

/* History */
.history-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
}

.history-item {
  aspect-ratio: 1;
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  border: 2px solid transparent;
  padding: 0;
  background: none;
  transition: all 0.2s ease;
}

.history-item:hover {
  border-color: var(--accent);
  transform: scale(1.05);
}

.history-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Footer */
.app-footer {
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
  padding: 1rem 2rem;
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-muted);
}

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

.app-footer a:hover {
  color: var(--text);
}

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

@media (max-width: 1200px) {
  .main-content {
    grid-template-columns: 280px 1fr;
  }
  
  .info-panel {
    display: none;
  }
  
  .header-badges {
    flex-direction: column;
    gap: 0.4rem;
  }
  
  .header-badge {
    padding: 0.4rem 0.75rem;
    font-size: 0.65rem;
  }
}

@media (max-width: 768px) {
  .main-content {
    grid-template-columns: 1fr;
  }
  
  .control-panel {
    max-height: none;
  }
  
  .preview-canvas {
    min-height: 320px;
  }
  
  .header-badges {
    display: none;
  }
  
  .palettes-grid {
    grid-template-columns: repeat(3, 1fr);
  }
  
  .density-options {
    flex-direction: column;
  }
}