/* Portrait Forge — Dark Purple & Gold Theme */
/* Designed by Maya, UX Advocate of the Forge Kingdom */

:root {
  --bg: #1a1028;
  --bg2: #241838;
  --bg3: #2e1f48;
  --gold: #f1c40f;
  --gold-dim: #c9a80a;
  --gold-glow: rgba(241, 196, 15, 0.3);
  --text: #e8e0f0;
  --text-dim: #9a8bb0;
  --accent: #8b5cf6;
  --accent2: #a78bfa;
  --danger: #e74c3c;
  --success: #2ecc71;
  --radius: 12px;
  --radius-sm: 8px;

  /* Chaos variables — these get overridden by JS */
  --chaos-hue: 0deg;
  --chaos-saturation: 0%;
  --chaos-glow: 0px;
  --chaos-skew: 0deg;
  --chaos-border-color: var(--bg3);
  --chaos-bg-extra: transparent;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  transition: filter 0.5s ease;
}

/* Chaos body effects */
body.chaos-7 { animation: subtle-pulse 4s ease-in-out infinite; }
body.chaos-8 { animation: chaos-pulse 3s ease-in-out infinite; }
body.chaos-9 { animation: chaos-wild 2s ease-in-out infinite; }
body.chaos-10 { animation: chaos-maximum 1.5s ease-in-out infinite; }

@keyframes subtle-pulse {
  0%, 100% { filter: hue-rotate(0deg); }
  50% { filter: hue-rotate(5deg); }
}
@keyframes chaos-pulse {
  0%, 100% { filter: hue-rotate(0deg) saturate(1); }
  50% { filter: hue-rotate(15deg) saturate(1.2); }
}
@keyframes chaos-wild {
  0% { filter: hue-rotate(0deg) saturate(1); }
  33% { filter: hue-rotate(30deg) saturate(1.4); }
  66% { filter: hue-rotate(-20deg) saturate(1.3); }
  100% { filter: hue-rotate(0deg) saturate(1); }
}
@keyframes chaos-maximum {
  0% { filter: hue-rotate(0deg) saturate(1) contrast(1); }
  25% { filter: hue-rotate(45deg) saturate(1.6) contrast(1.1); }
  50% { filter: hue-rotate(-30deg) saturate(1.4) contrast(1.2); }
  75% { filter: hue-rotate(60deg) saturate(1.8) contrast(1.05); }
  100% { filter: hue-rotate(0deg) saturate(1) contrast(1); }
}

#app {
  max-width: 680px;
  margin: 0 auto;
  padding: 1rem;
  padding-bottom: 3rem;
}

/* Header */
header {
  text-align: center;
  padding: 1.5rem 0 1rem;
}
.header-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
}
header h1 {
  font-size: 1.6rem;
  color: var(--gold);
  text-shadow: 0 0 20px var(--gold-glow);
}
.subtitle {
  color: var(--text-dim);
  font-size: 0.85rem;
  margin-top: 0.3rem;
  font-style: italic;
}

/* Icon Buttons */
.icon-btn {
  background: var(--bg3);
  border: 1px solid rgba(255,255,255,0.1);
  color: var(--text);
  font-size: 1.2rem;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}
.icon-btn:hover { background: var(--accent); transform: scale(1.1); }

/* Cards */
.card {
  background: var(--bg2);
  border: 1px solid var(--chaos-border-color);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
  transition: border-color 0.5s, box-shadow 0.5s, transform 0.3s;
}
.card:hover {
  border-color: rgba(139, 92, 246, 0.3);
}
.card h2 {
  font-size: 1rem;
  color: var(--gold);
  margin-bottom: 0.75rem;
}

/* Buttons */
.btn {
  background: var(--bg3);
  color: var(--text);
  border: 1px solid rgba(255,255,255,0.1);
  padding: 0.6rem 1.2rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.2s;
}
.btn:hover { background: var(--accent); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-sm { padding: 0.4rem 0.8rem; font-size: 0.8rem; }

.btn-gold {
  background: linear-gradient(135deg, var(--gold), var(--gold-dim));
  color: #1a1028;
  font-weight: 600;
  border: none;
}
.btn-gold:hover { filter: brightness(1.1); background: linear-gradient(135deg, var(--gold), var(--gold-dim)); }

.btn-generate {
  width: 100%;
  padding: 1rem;
  font-size: 1.1rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), #6d28d9);
  color: white;
  border: 2px solid var(--accent2);
  border-radius: var(--radius);
  margin-bottom: 1rem;
  position: relative;
  overflow: hidden;
  transition: all 0.3s;
}
.btn-generate:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 8px 30px rgba(139, 92, 246, 0.4);
}
.btn-generate:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn-generate .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.6s linear infinite;
  vertical-align: middle;
  margin-right: 0.5rem;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Forms */
.field {
  margin-bottom: 0.75rem;
}
.field label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-bottom: 0.25rem;
}
input[type="text"], input[type="password"], select, textarea {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.8rem;
  font-size: 0.9rem;
  transition: border-color 0.2s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.input-row {
  display: flex;
  gap: 0.5rem;
}
.input-row input { flex: 1; }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem 0.75rem;
}
@media (max-width: 400px) {
  .form-grid { grid-template-columns: 1fr; }
}

.hint {
  color: var(--text-dim);
  font-size: 0.8rem;
}

/* Chip Grid */
.chip-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}
.chip {
  background: var(--bg);
  color: var(--text-dim);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 20px;
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s;
}
.chip:hover { border-color: var(--accent); color: var(--text); }
.chip.selected {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.custom-bg-input {
  margin-top: 0.5rem;
}

/* EXTREME SLIDER */
#extremeCard {
  position: relative;
  overflow: hidden;
}
#extremeCard::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--chaos-bg-extra);
  pointer-events: none;
  transition: background 0.5s;
  border-radius: var(--radius);
}

.extreme-display {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.5rem;
  position: relative;
  z-index: 1;
}
.extreme-label {
  font-weight: 700;
  font-size: 1.1rem;
  transition: all 0.3s;
}
.extreme-value {
  font-size: 2rem;
  font-weight: 900;
  color: var(--gold);
  transition: all 0.3s;
  line-height: 1;
}
.extreme-hints {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-top: 0.25rem;
  position: relative;
  z-index: 1;
}
.extreme-desc {
  margin-top: 0.5rem;
  transition: all 0.3s;
  position: relative;
  z-index: 1;
}

/* Range Slider */
.extreme-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 8px;
  background: linear-gradient(90deg, var(--accent), var(--gold), #e74c3c, #ff00ff);
  border-radius: 4px;
  outline: none;
  position: relative;
  z-index: 1;
}
.extreme-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 24px;
  height: 24px;
  background: white;
  border-radius: 50%;
  cursor: grab;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  transition: transform 0.2s;
}
.extreme-slider::-webkit-slider-thumb:active {
  cursor: grabbing;
  transform: scale(1.2);
}
.extreme-slider::-moz-range-thumb {
  width: 24px;
  height: 24px;
  background: white;
  border-radius: 50%;
  cursor: grab;
  border: none;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

/* Model Grid */
.model-grid {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.model-option {
  cursor: pointer;
}
.model-option input { display: none; }
.model-card {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  background: var(--bg);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.8rem;
  transition: all 0.2s;
}
.model-option input:checked + .model-card {
  border-color: var(--accent);
  background: rgba(139, 92, 246, 0.15);
}
.model-card:hover {
  border-color: var(--accent);
}
.model-name {
  font-weight: 600;
  font-size: 0.9rem;
}
.model-desc {
  font-size: 0.75rem;
  color: var(--text-dim);
}

/* Prompt Preview */
.prompt-preview {
  background: var(--bg);
  border: 1px solid rgba(255,255,255,0.05);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  font-size: 0.75rem;
  color: var(--text-dim);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 200px;
  overflow-y: auto;
  font-family: 'SF Mono', 'Fira Code', monospace;
  margin-top: 0.5rem;
}
details summary {
  cursor: pointer;
  user-select: none;
}
details summary::-webkit-details-marker { display: none; }
details summary::before { content: '▸ '; }
details[open] summary::before { content: '▾ '; }

/* Result */
.result-frame {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg);
  aspect-ratio: 3/4;
  display: flex;
  align-items: center;
  justify-content: center;
}
/* Golden frame effect */
.result-frame::before {
  content: '';
  position: absolute;
  inset: 0;
  border: 3px solid var(--gold);
  border-radius: var(--radius);
  pointer-events: none;
  box-shadow: inset 0 0 20px var(--gold-glow), 0 0 20px var(--gold-glow);
}
#resultImage {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: var(--radius);
}
.result-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
  justify-content: center;
  flex-wrap: wrap;
}

/* Overlays */
.overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 100;
  overflow-y: auto;
  animation: slideUp 0.3s ease;
}
@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
.overlay-content {
  max-width: 520px;
  margin: 0 auto;
  padding: 1rem;
}
.overlay-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
  position: sticky;
  top: 0;
  background: var(--bg);
  padding: 0.5rem 0;
  z-index: 10;
}
.overlay-header h2 {
  color: var(--gold);
  flex-shrink: 0;
}

/* Gallery Tabs */
.gallery-tabs {
  display: flex;
  gap: 0.25rem;
  flex: 1;
}
.tab-btn {
  background: var(--bg3);
  color: var(--text-dim);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 20px;
  padding: 0.3rem 0.75rem;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s;
}
.tab-btn.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

/* Gallery Grid */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.5rem;
}
.gallery-item {
  position: relative;
  border-radius: var(--radius-sm);
  overflow: hidden;
  aspect-ratio: 3/4;
  cursor: pointer;
  transition: transform 0.2s;
  background: var(--bg2);
}
.gallery-item:hover { transform: scale(1.03); }
.gallery-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.gallery-item .fav-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  font-size: 1.2rem;
  filter: drop-shadow(0 1px 3px rgba(0,0,0,0.8));
}

/* Detail Overlay */
.detail-content {
  position: relative;
  padding-top: 3rem;
}
.detail-close {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  z-index: 10;
}
.detail-image-wrap {
  border-radius: var(--radius);
  overflow: hidden;
  max-height: 50vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg2);
}
.detail-image-wrap img {
  max-width: 100%;
  max-height: 50vh;
  object-fit: contain;
}
.detail-info {
  margin-top: 1rem;
}
.detail-info h3 {
  color: var(--gold);
  margin-bottom: 0.25rem;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--bg3);
  color: var(--text);
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius);
  border: 1px solid var(--accent);
  font-size: 0.9rem;
  z-index: 200;
  transition: transform 0.3s ease;
  pointer-events: none;
}
.toast.show {
  transform: translateX(-50%) translateY(0);
}

/* Chaos level visual escalation on cards */
.chaos-glow-1 { box-shadow: none; }
.chaos-glow-3 { box-shadow: 0 0 10px rgba(139, 92, 246, 0.15); }
.chaos-glow-5 { box-shadow: 0 0 15px rgba(139, 92, 246, 0.25); }
.chaos-glow-7 { box-shadow: 0 0 20px rgba(241, 196, 15, 0.2), 0 0 40px rgba(139, 92, 246, 0.15); }
.chaos-glow-8 { box-shadow: 0 0 25px rgba(241, 196, 15, 0.3), 0 0 50px rgba(231, 76, 60, 0.15); }
.chaos-glow-9 { box-shadow: 0 0 30px rgba(255, 0, 255, 0.2), 0 0 60px rgba(241, 196, 15, 0.2); transform: rotate(-0.5deg); }
.chaos-glow-10 { box-shadow: 0 0 40px rgba(255, 0, 255, 0.3), 0 0 80px rgba(0, 255, 255, 0.15); animation: card-chaos 2s ease-in-out infinite; }

@keyframes card-chaos {
  0%, 100% { transform: rotate(0deg) scale(1); }
  25% { transform: rotate(0.5deg) scale(1.005); }
  75% { transform: rotate(-0.5deg) scale(0.995); }
}

/* Options Row — Background & Art Style side by side */
.options-row {
  display: flex;
  gap: 1rem;
}
.options-half {
  flex: 1;
  min-width: 0;
}
@media (max-width: 500px) {
  .options-row { flex-direction: column; gap: 0; }
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--bg3); border-radius: 3px; }

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* Focus visible */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Mode Banner */
.mode-banner {
  display: flex !important;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
}
.mode-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.mode-info span:first-child { font-size: 1.2rem; }
.link-btn {
  background: none;
  border: none;
  color: var(--accent2);
  cursor: pointer;
  text-decoration: underline;
  font-size: inherit;
  padding: 0;
}

.inline-heading { display: inline; }

/* Upgrade buttons */
.upgrade-container { display: flex; flex-direction: column; gap: 8px; }
.upgrade-btn { display: block; padding: 12px 24px; border-radius: 12px; background: linear-gradient(135deg, #ffd700, #ff8c00); color: #1a1028; font-weight: 700; font-size: 15px; text-decoration: none; text-align: center; cursor: pointer; }
.upgrade-value { background: linear-gradient(135deg, #a855f7, #6366f1); color: #fff; }
.upgrade-option { margin: 4px 0; }

/* Copy Prompt Button */
.copy-prompt-btn {
  margin-top: 10px;
  padding: 10px 18px;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  min-height: 44px; /* touch friendly */
}
.copy-prompt-btn:active { transform: scale(0.96); }
.copy-prompt-btn.copied {
  background: rgba(46, 204, 113, 0.25);
  border-color: rgba(46, 204, 113, 0.5);
  color: #2ecc71;
}
