:root {
  --bg-primary: #06060d;
  --bg-secondary: #0d0d18;
  --bg-card: rgba(20, 18, 38, 0.75);
  --accent-cyan: #00d4ff;
  --accent-magenta: #ff00aa;
  --accent-gold: #ffc850;
  --accent-purple: #9333ea;
  --text-primary: #eeeef5;
  --text-secondary: #7878a0;
  --border-glow: rgba(0, 212, 255, 0.25);
  --glass-border: rgba(255, 255, 255, 0.07);
}

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

body {
  font-family: 'Bricolage Grotesque', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  background-image:
    radial-gradient(ellipse at 20% 0%, rgba(147, 51, 234, 0.08) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 100%, rgba(0, 212, 255, 0.06) 0%, transparent 60%);
}

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

/* ===== HEADER ===== */
.header {
  position: relative;
  padding: 2.5rem 2rem 2rem;
  background: linear-gradient(180deg, rgba(15, 8, 35, 0.95) 0%, transparent 100%);
  overflow: hidden;
  border-bottom: 1px solid var(--glass-border);
}

.header-content {
  position: relative;
  z-index: 2;
  text-align: center;
}

.title {
  font-size: clamp(2rem, 5vw, 3.2rem);
  font-weight: 800;
  background: linear-gradient(135deg, var(--accent-cyan) 0%, var(--accent-magenta) 40%, var(--accent-gold) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.03em;
}

.title-icon {
  display: inline-block;
  animation: sparkle 2.5s ease-in-out infinite;
}

@keyframes sparkle {
  0%, 100% { opacity: 0.4; transform: scale(1) rotate(0deg); }
  50% { opacity: 1; transform: scale(1.3) rotate(15deg); }
}

.subtitle {
  color: var(--text-secondary);
  margin-top: 0.5rem;
  font-weight: 300;
  font-size: 0.95rem;
}

/* ===== PARTICLES ===== */
.particles-container {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.particle {
  position: absolute;
  background: var(--accent-cyan);
  border-radius: 50%;
  opacity: 0;
  animation: float linear infinite;
}

@keyframes float {
  0% { opacity: 0; transform: translateY(0) scale(0); }
  10% { opacity: 0.6; }
  90% { opacity: 0.3; }
  100% { opacity: 0; transform: translateY(-120px) scale(1); }
}

/* ===== MOBILE WARNING ===== */
.mobile-warning {
  background: linear-gradient(90deg, var(--accent-purple), var(--accent-cyan));
  padding: 0.5rem 1rem;
  text-align: center;
  font-size: 0.85rem;
  font-weight: 500;
}

/* ===== MAIN CONTENT ===== */
.main-content {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr;
  gap: 2rem;
  padding: 2rem;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

@media (min-width: 1024px) {
  .main-content {
    grid-template-columns: 1fr 420px;
  }
}

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

.artwork-container {
  aspect-ratio: 1024 / 1448;
  max-height: 72vh;
  background: var(--bg-secondary);
  border-radius: 14px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--glass-border);
  position: relative;
}

.artwork-container.has-image {
  border-color: rgba(147, 51, 234, 0.2);
  box-shadow: 0 0 40px rgba(147, 51, 234, 0.08);
}

.artwork-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Empty state */
.empty-state {
  flex-direction: column;
  text-align: center;
  color: var(--text-secondary);
}

.empty-canvas-outline {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  padding: 2rem;
  border: 2px dashed rgba(255, 255, 255, 0.06);
  border-radius: 12px;
  max-width: 300px;
}

.empty-icon {
  font-size: 3.5rem;
  opacity: 0.4;
  animation: gentlePulse 3s ease-in-out infinite;
}

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

.empty-main {
  font-size: 1rem;
  color: var(--text-secondary);
  font-weight: 400;
}

.empty-sub {
  font-size: 0.8rem;
  color: rgba(120, 120, 160, 0.6);
}

/* Error */
.error-state {
  flex-direction: column;
  text-align: center;
}

.error-text {
  color: var(--accent-magenta);
  font-size: 1.2rem;
  margin-bottom: 0.5rem;
}

.error-message {
  color: var(--text-secondary);
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.retry-btn {
  background: transparent;
  border: 1px solid var(--accent-magenta);
  color: var(--accent-magenta);
  padding: 0.6rem 1.8rem;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
  font-family: inherit;
  font-weight: 600;
}

.retry-btn:hover {
  background: var(--accent-magenta);
  color: white;
}

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

.loading-rings {
  position: relative;
  width: 100px;
  height: 100px;
}

.ring {
  position: absolute;
  border-radius: 50%;
  border: 2px solid transparent;
  animation: spin linear infinite;
}

.ring-1 { inset: 0; border-top-color: var(--accent-cyan); animation-duration: 1.5s; }
.ring-2 { inset: 12px; border-right-color: var(--accent-magenta); animation-duration: 2s; animation-direction: reverse; }
.ring-3 { inset: 24px; border-bottom-color: var(--accent-gold); animation-duration: 2.5s; }

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

.loading-text {
  font-size: 1.1rem;
  color: var(--text-primary);
  font-weight: 600;
}

.loading-hint {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* Download button */
.download-btn {
  background: linear-gradient(135deg, #0f2a1a 0%, #0a1f14 100%);
  border: 1px solid rgba(0, 255, 100, 0.25);
  color: #00ff64;
  padding: 0.9rem 2rem;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  font-family: inherit;
  text-align: center;
}

.download-btn:hover {
  border-color: #00ff64;
  box-shadow: 0 0 25px rgba(0, 255, 100, 0.25);
  transform: translateY(-2px);
}

/* ===== CONTROLS ===== */
.controls-section {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.control-group label {
  font-weight: 600;
  font-size: 0.8rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* Mood chips */
.mood-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.mood-chip {
  background: var(--bg-card);
  border: 1px solid var(--glass-border);
  color: var(--text-primary);
  padding: 0.45rem 1rem;
  border-radius: 20px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.3s ease;
  font-family: inherit;
  backdrop-filter: blur(10px);
}

.mood-chip:hover {
  border-color: var(--accent-cyan);
  color: var(--accent-cyan);
}

.mood-chip.selected {
  background: linear-gradient(135deg, var(--accent-purple), var(--accent-magenta));
  border-color: transparent;
  color: white;
  box-shadow: 0 0 18px rgba(147, 51, 234, 0.4);
}

/* Prompt input */
.prompt-input-container {
  position: relative;
}

.prompt-input {
  width: 100%;
  min-height: 100px;
  background: var(--bg-card);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  padding: 1rem;
  padding-bottom: 2rem;
  color: var(--text-primary);
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.85rem;
  resize: vertical;
  transition: all 0.3s ease;
  backdrop-filter: blur(10px);
  line-height: 1.5;
}

.prompt-input:focus {
  outline: none;
  border-color: var(--accent-cyan);
  box-shadow: 0 0 25px rgba(0, 212, 255, 0.15);
}

.prompt-input::placeholder {
  color: var(--text-secondary);
  opacity: 0.6;
}

.char-counter {
  position: absolute;
  bottom: 0.5rem;
  right: 0.75rem;
  font-size: 0.7rem;
  color: var(--text-secondary);
  font-family: 'JetBrains Mono', monospace;
}

.keyboard-hint {
  position: absolute;
  bottom: 0.5rem;
  left: 0.75rem;
  font-size: 0.65rem;
  color: rgba(120, 120, 160, 0.4);
  font-family: 'JetBrains Mono', monospace;
}

/* Reference upload */
.reference-upload {
  background: var(--bg-card);
  border: 2px dashed rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  padding: 1.5rem;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s ease;
  backdrop-filter: blur(10px);
}

.reference-upload:hover,
.reference-upload.dragging {
  border-color: var(--accent-cyan);
  background: rgba(0, 212, 255, 0.04);
}

.upload-icon { font-size: 1.8rem; margin-bottom: 0.4rem; }
.upload-hint { font-size: 0.75rem; color: var(--text-secondary); }

.reference-preview {
  display: flex;
  align-items: center;
  gap: 1rem;
  background: var(--bg-card);
  border-radius: 12px;
  padding: 1rem;
  backdrop-filter: blur(10px);
  border: 1px solid var(--glass-border);
}

.reference-thumb {
  width: 60px;
  height: 60px;
  object-fit: cover;
  border-radius: 8px;
  flex-shrink: 0;
}

.reference-info { flex: 1; }

.reference-note {
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}

.clear-ref-btn {
  background: rgba(255, 0, 170, 0.15);
  border: 1px solid rgba(255, 0, 170, 0.3);
  color: var(--accent-magenta);
  padding: 0.3rem 0.8rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.75rem;
  font-family: inherit;
  transition: all 0.2s;
}

.clear-ref-btn:hover {
  background: var(--accent-magenta);
  color: white;
}

/* ===== GENERATE BUTTONS ===== */
.generate-buttons-wrapper {
  display: flex;
  gap: 0.75rem;
  margin-top: 0.5rem;
}

.generate-btn-container {
  flex: 1.4;
  position: relative;
}

.generate-btn {
  width: 100%;
  border: none;
  color: white;
  padding: 1.1rem 1.5rem;
  border-radius: 14px;
  font-size: 1.15rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.3s ease;
  font-family: inherit;
  position: relative;
  overflow: hidden;
}

/* PRIMARY Generate button — the HERO */
.primary-generate {
  background: linear-gradient(135deg, #7c3aed 0%, var(--accent-magenta) 50%, var(--accent-gold) 100%);
  background-size: 200% 200%;
  animation: gradientShift 4s ease-in-out infinite, heroGlow 2s ease-in-out infinite;
  box-shadow:
    0 0 20px rgba(147, 51, 234, 0.35),
    0 0 60px rgba(255, 0, 170, 0.15),
    inset 0 1px 0 rgba(255, 255, 255, 0.15);
  border: 2px solid transparent;
  background-clip: padding-box;
}

.primary-generate::before {
  content: '';
  position: absolute;
  inset: -2px;
  background: linear-gradient(135deg, var(--accent-cyan), var(--accent-magenta), var(--accent-gold), var(--accent-cyan));
  background-size: 300% 300%;
  border-radius: 16px;
  z-index: -1;
  animation: borderRotate 3s linear infinite;
}

.primary-generate::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent 0%, rgba(255, 255, 255, 0.15) 50%, transparent 100%);
  transform: translateX(-100%);
  animation: shimmer 3s ease-in-out infinite;
}

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

@keyframes heroGlow {
  0%, 100% { box-shadow: 0 0 20px rgba(147, 51, 234, 0.35), 0 0 60px rgba(255, 0, 170, 0.15); }
  50% { box-shadow: 0 0 30px rgba(147, 51, 234, 0.5), 0 0 80px rgba(255, 0, 170, 0.25); }
}

@keyframes borderRotate {
  0% { background-position: 0% 50%; }
  100% { background-position: 300% 50%; }
}

@keyframes shimmer {
  0% { transform: translateX(-100%); }
  60%, 100% { transform: translateX(100%); }
}

.primary-generate:hover:not(:disabled) {
  transform: translateY(-3px) scale(1.02);
  box-shadow: 0 12px 40px rgba(147, 51, 234, 0.5), 0 0 80px rgba(255, 0, 170, 0.3);
}

/* RANDOM Generate button — secondary */
.random-generate {
  flex: 1;
  background: linear-gradient(135deg, #1e1b4b 0%, #312e81 100%);
  border: 1px solid rgba(147, 51, 234, 0.3);
  font-size: 0.95rem;
  padding: 1rem;
}

.random-generate::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.08), transparent);
  transform: translateX(-100%);
  animation: shimmer 4s ease-in-out infinite 1s;
}

.random-generate:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 8px 30px rgba(147, 51, 234, 0.3);
  border-color: var(--accent-purple);
}

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

.btn-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.spinner {
  display: inline-block;
  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;
}

/* Nudge tooltip */
.nudge-tooltip {
  position: absolute;
  top: -48px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-card);
  border: 1px solid var(--accent-gold);
  color: var(--accent-gold);
  padding: 0.5rem 1rem;
  border-radius: 8px;
  font-size: 0.8rem;
  white-space: nowrap;
  z-index: 10;
  animation: fadeInBounce 0.3s ease;
  backdrop-filter: blur(12px);
  box-shadow: 0 4px 20px rgba(255, 200, 80, 0.15);
}

.nudge-arrow {
  position: absolute;
  bottom: -6px;
  left: 50%;
  transform: translateX(-50%) rotate(45deg);
  width: 10px;
  height: 10px;
  background: var(--bg-card);
  border-right: 1px solid var(--accent-gold);
  border-bottom: 1px solid var(--accent-gold);
}

@keyframes fadeInBounce {
  0% { opacity: 0; transform: translateX(-50%) translateY(8px); }
  100% { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ===== HISTORY DRAWER ===== */
.history-drawer {
  position: fixed;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  z-index: 50;
  display: flex;
  align-items: flex-start;
}

.history-toggle {
  background: var(--bg-card);
  border: 1px solid var(--glass-border);
  border-right: none;
  color: var(--text-secondary);
  padding: 0.8rem 0.5rem;
  border-radius: 8px 0 0 8px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.8rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  backdrop-filter: blur(10px);
  transition: all 0.3s;
}

.history-toggle:hover {
  color: var(--accent-cyan);
  border-color: var(--accent-cyan);
}

.history-badge {
  background: var(--accent-purple);
  color: white;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  font-weight: 700;
}

.history-content {
  background: var(--bg-card);
  border: 1px solid var(--glass-border);
  border-right: none;
  border-radius: 12px 0 0 12px;
  padding: 1.25rem;
  width: 220px;
  max-height: 70vh;
  overflow-y: auto;
  backdrop-filter: blur(16px);
  animation: slideIn 0.25s ease;
}

@keyframes slideIn {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

.history-content h3 {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.history-empty {
  font-size: 0.8rem;
  color: rgba(120, 120, 160, 0.5);
  text-align: center;
  padding: 1rem 0;
}

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

.history-item {
  aspect-ratio: 1024 / 1448;
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
  opacity: 0.7;
  transition: all 0.3s ease;
  border: 1px solid transparent;
  position: relative;
}

.history-item:hover {
  opacity: 1;
  border-color: var(--accent-cyan);
  transform: scale(1.04);
}

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

.history-label {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0, 0, 0, 0.7);
  padding: 2px 4px;
  font-size: 0.55rem;
  color: var(--accent-cyan);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.clear-history-btn {
  width: 100%;
  margin-top: 0.75rem;
  background: transparent;
  border: 1px solid rgba(255, 0, 170, 0.2);
  color: var(--accent-magenta);
  padding: 0.4rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.75rem;
  font-family: inherit;
  transition: all 0.2s;
}

.clear-history-btn:hover {
  background: rgba(255, 0, 170, 0.1);
  border-color: var(--accent-magenta);
}

/* ===== FOOTER ===== */
.footer {
  padding: 1.5rem 2rem;
  text-align: center;
  border-top: 1px solid var(--glass-border);
  background: var(--bg-secondary);
}

.footer p {
  color: var(--text-secondary);
  font-size: 0.8rem;
  margin-bottom: 0.4rem;
}

.footer a {
  color: var(--accent-cyan);
  text-decoration: none;
  font-weight: 500;
  font-size: 0.85rem;
  transition: color 0.3s;
}

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

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  .main-content {
    padding: 1rem;
    gap: 1.5rem;
  }

  .artwork-container {
    max-height: 50vh;
  }

  .prompt-input {
    min-height: 80px;
  }

  .generate-buttons-wrapper {
    flex-direction: column;
  }

  .generate-btn-container {
    flex: 1;
  }

  .primary-generate {
    font-size: 1.1rem;
  }

  .random-generate {
    font-size: 0.9rem;
  }

  .history-drawer {
    display: none;
  }
}

/* Scrollbar styling */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(147, 51, 234, 0.3); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(147, 51, 234, 0.5); }