/* ============================================================
   LUMINA AI STUDIO — MAIN STYLESHEET
   Design System: Dark Luxury · Gold Accent · DM Type Family
   ============================================================ */

/* ============================================================
   1. DESIGN TOKENS
   ============================================================ */
:root {
  /* Spacing scale (8px base) */
  --sp-1:  4px;   --sp-2:  8px;   --sp-3:  12px;  --sp-4:  16px;
  --sp-5:  20px;  --sp-6:  24px;  --sp-8:  32px;  --sp-10: 40px;
  --sp-12: 48px;  --sp-16: 64px;

  /* Typography */
  --font-display: 'DM Serif Display', Georgia, serif;
  --font-body:    'DM Sans', system-ui, sans-serif;
  --font-mono:    'DM Mono', 'Courier New', monospace;

  /* Radius */
  --r-sm:   8px;
  --r-md:   12px;
  --r-lg:   16px;
  --r-xl:   24px;
  --r-full: 9999px;

  /* Transitions */
  --t-fast: 0.15s ease;
  --t-base: 0.25s ease;
  --t-slow: 0.4s ease;

  /* Layout */
  --max-width: 1140px;
  --header-h:  64px;
}

/* ============================================================
   2. THEMES
   ============================================================ */
[data-theme="dark"] {
  --bg-base:      #0d0d0f;
  --bg-surface:   #141418;
  --bg-elevated:  #1c1c22;
  --bg-hover:     #222228;
  --bg-overlay:   rgba(0, 0, 0, 0.88);

  --border:       rgba(255, 255, 255, 0.07);
  --border-focus: rgba(196, 156, 86, 0.55);

  --text-primary:   #f0ede8;
  --text-secondary: #8b8791;
  --text-muted:     #4a4850;
  --text-inverse:   #0d0d0f;

  --gold:       #c49c56;
  --gold-light: #e4c07a;
  --gold-dim:   rgba(196, 156, 86, 0.12);
  --gold-glow:  rgba(196, 156, 86, 0.22);

  --error:      #e05c5c;
  --error-soft: rgba(224, 92, 92, 0.1);
  --success:    #5cb88a;

  --shadow-sm:   0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-md:   0 4px 20px rgba(0, 0, 0, 0.55);
  --shadow-lg:   0 8px 48px rgba(0, 0, 0, 0.75);
  --shadow-gold: 0 4px 24px rgba(196, 156, 86, 0.2);
}

[data-theme="light"] {
  --bg-base:      #f5f3ef;
  --bg-surface:   #ffffff;
  --bg-elevated:  #f0ede8;
  --bg-hover:     #ebe8e2;
  --bg-overlay:   rgba(240, 237, 232, 0.95);

  --border:       rgba(0, 0, 0, 0.08);
  --border-focus: rgba(140, 96, 20, 0.5);

  --text-primary:   #1a1814;
  --text-secondary: #6b6660;
  --text-muted:     #aaa8a4;
  --text-inverse:   #ffffff;

  --gold:       #8c6014;
  --gold-light: #b07c1e;
  --gold-dim:   rgba(140, 96, 20, 0.1);
  --gold-glow:  rgba(140, 96, 20, 0.15);

  --error:      #c23a3a;
  --error-soft: rgba(194, 58, 58, 0.08);
  --success:    #3a8a60;

  --shadow-sm:   0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-md:   0 4px 20px rgba(0, 0, 0, 0.1);
  --shadow-lg:   0 8px 48px rgba(0, 0, 0, 0.14);
  --shadow-gold: 0 4px 24px rgba(140, 96, 20, 0.12);
}

/* ============================================================
   3. RESET & BASE
   ============================================================ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html { scroll-behavior: smooth; }

body {
  font-family: var(--font-body);
  background: var(--bg-base);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background var(--t-slow), color var(--t-slow);
  overflow-x: hidden;
}

/* Grain texture */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.03'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 0;
}

a {
  color: var(--gold);
  text-decoration: none;
  transition: color var(--t-fast);
}
a:hover { color: var(--gold-light); text-decoration: underline; }

:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 3px;
  border-radius: var(--r-sm);
}

/* ============================================================
   4. LAYOUT SHELL
   ============================================================ */
.app-wrapper {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.container {
  width: 100%;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 var(--sp-6);
}

/* ============================================================
   5. ONBOARDING OVERLAY
   ============================================================ */
.onboarding-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-overlay);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-6);
  animation: fade-in 0.4s ease;
}

.onboarding-overlay.hidden {
  display: none;
}

@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.onboarding-card {
  width: 100%;
  max-width: 560px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg), var(--shadow-gold);
  padding: var(--sp-10) var(--sp-8);
  animation: card-rise 0.45s cubic-bezier(0.22, 1, 0.36, 1);
  max-height: 92vh;
  overflow-y: auto;
}

@keyframes card-rise {
  from { opacity: 0; transform: translateY(24px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.onboarding-logo {
  display: flex;
  justify-content: center;
  margin-bottom: var(--sp-6);
}

.logo-mark-lg {
  width: 64px;
  height: 64px;
  background: linear-gradient(135deg, var(--gold), var(--gold-light));
  border-radius: var(--r-lg);
  display: grid;
  place-items: center;
  box-shadow: var(--shadow-gold);
}

.logo-mark-lg svg {
  width: 32px;
  height: 32px;
  fill: #0d0d0f;
}

.onboarding-title {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 400;
  text-align: center;
  color: var(--text-primary);
  margin-bottom: var(--sp-3);
  letter-spacing: -0.02em;
}

.onboarding-title em {
  color: var(--gold);
}

.onboarding-sub {
  font-size: 0.9rem;
  color: var(--text-secondary);
  text-align: center;
  line-height: 1.7;
  margin-bottom: var(--sp-8);
}

/* Steps */
.onboarding-steps {
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
  margin-bottom: var(--sp-6);
}

.step {
  display: flex;
  gap: var(--sp-4);
  align-items: flex-start;
}

.step-num {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 500;
  letter-spacing: 0.12em;
  color: var(--gold);
  background: var(--gold-dim);
  border: 1px solid rgba(196,156,86,0.2);
  border-radius: var(--r-sm);
  padding: var(--sp-1) var(--sp-2);
  flex-shrink: 0;
  margin-top: 2px;
}

.step-body { flex: 1; }

.step-title {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 2px;
}

.step-detail {
  font-size: 0.8rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

.step-detail strong { color: var(--text-primary); font-weight: 500; }
.step-detail code {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--gold);
  background: var(--gold-dim);
  padding: 1px 5px;
  border-radius: 4px;
}

/* Trust badge */
.trust-badge {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  background: var(--gold-dim);
  border: 1px solid rgba(196,156,86,0.18);
  border-radius: var(--r-md);
  padding: var(--sp-4);
  margin-bottom: var(--sp-6);
  font-size: 0.8rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

.trust-icon { font-size: 1.1rem; flex-shrink: 0; margin-top: 1px; }
.trust-badge strong { color: var(--text-primary); }

/* Token input */
.onboarding-input-group {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  margin-bottom: var(--sp-5);
}

.input-label {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.token-field-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.token-field {
  width: 100%;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  padding: var(--sp-3) var(--sp-10) var(--sp-3) var(--sp-4);
  outline: none;
  transition: border-color var(--t-base), box-shadow var(--t-base);
}

.token-field::placeholder { color: var(--text-muted); font-style: italic; }

.token-field:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--gold-dim);
}

.token-field.is-error { border-color: var(--error); }

.btn-reveal {
  position: absolute;
  right: var(--sp-3);
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: var(--sp-1);
  display: grid;
  place-items: center;
  transition: color var(--t-fast);
}

.btn-reveal svg { width: 16px; height: 16px; }
.btn-reveal:hover { color: var(--gold); }

.token-field-error {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--error);
  min-height: 1em;
}

/* Onboarding CTA */
.btn-onboard-save {
  width: 100%;
  padding: var(--sp-4);
  background: linear-gradient(135deg, var(--gold), var(--gold-light));
  border: none;
  border-radius: var(--r-lg);
  color: #0d0d0f;
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-3);
  transition: all var(--t-base);
  box-shadow: var(--shadow-gold);
  letter-spacing: 0.01em;
}

.btn-onboard-save:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 32px var(--gold-glow);
}

.btn-onboard-save:active { transform: translateY(0); }

/* ============================================================
   6. HEADER
   ============================================================ */
.header {
  height: var(--header-h);
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg-base) 85%, transparent);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  position: sticky;
  top: 0;
  z-index: 100;
  transition: background var(--t-slow), border-color var(--t-slow);
}

.header-inner {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  text-decoration: none;
}

.logo:hover { text-decoration: none; }

.logo-mark {
  width: 34px;
  height: 34px;
  background: linear-gradient(135deg, var(--gold), var(--gold-light));
  border-radius: var(--r-sm);
  display: grid;
  place-items: center;
  flex-shrink: 0;
  box-shadow: 0 2px 10px var(--gold-glow);
}

.logo-mark svg { width: 17px; height: 17px; fill: #0d0d0f; }

.logo-name {
  font-family: var(--font-display);
  font-size: 1.5rem;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.logo-name em { color: var(--gold); font-style: italic; }

.header-right {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}

.badge-open {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--gold);
  background: var(--gold-dim);
  border: 1px solid rgba(196,156,86,0.2);
  padding: 3px 10px;
  border-radius: var(--r-full);
}

.btn-icon-sm {
  width: 38px;
  height: 38px;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: all var(--t-base);
  flex-shrink: 0;
}

.btn-icon-sm svg { width: 16px; height: 16px; }

.btn-icon-sm:hover {
  border-color: var(--border-focus);
  color: var(--gold);
  background: var(--gold-dim);
}

/* ============================================================
   7. MAIN LAYOUT GRID
   ============================================================ */
.main-content {
  flex: 1;
  padding: var(--sp-8) 0 var(--sp-16);
}

.studio-grid {
  display: grid;
  grid-template-columns: 400px 1fr;
  gap: var(--sp-5);
  align-items: start;
}

/* ============================================================
   8. PANEL (shared card component)
   ============================================================ */
.panel {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  transition: background var(--t-slow), border-color var(--t-slow);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border);
  min-height: 52px;
}

.panel-header-left {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}

.panel-title {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.active-label {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  letter-spacing: 0.08em;
  color: var(--gold);
}

.panel-body {
  padding: var(--sp-5);
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}

.panel-body--tight { padding: var(--sp-4) var(--sp-5); }

/* ============================================================
   9. CONTROLS PANEL (left)
   ============================================================ */
.controls-panel {
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
  position: sticky;
  top: calc(var(--header-h) + var(--sp-4));
}

/* Section label */
.section-label {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: var(--sp-2);
}

/* Prompt textarea */
.prompt-textarea {
  width: 100%;
  min-height: 120px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 0.875rem;
  font-weight: 300;
  line-height: 1.7;
  padding: var(--sp-3) var(--sp-4);
  resize: vertical;
  outline: none;
  transition: border-color var(--t-base), box-shadow var(--t-base);
}

.prompt-textarea::placeholder { color: var(--text-muted); font-style: italic; }

.prompt-textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--gold-dim);
}

/* Char count */
.char-count {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  color: var(--text-muted);
  text-align: right;
  margin-top: calc(-1 * var(--sp-2));
}

/* Suggestions */
.suggestions-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
}

.suggestion-chip {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  padding: 4px 12px;
  cursor: pointer;
  transition: all var(--t-fast);
  white-space: nowrap;
  user-select: none;
}

.suggestion-chip:hover {
  color: var(--gold);
  border-color: rgba(196,156,86,0.3);
  background: var(--gold-dim);
  transform: translateY(-1px);
}

/* Style Presets grid */
.presets-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-2);
}

.preset-btn {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--t-base);
  font-family: var(--font-body);
  font-size: 0.83rem;
  text-align: left;
}

.preset-btn .preset-icon { font-size: 1rem; }

.preset-btn:hover {
  border-color: var(--border-focus);
  color: var(--text-primary);
  background: var(--bg-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.preset-btn.active {
  border-color: var(--gold);
  background: var(--gold-dim);
  color: var(--gold);
  box-shadow: 0 0 16px var(--gold-glow);
}

/* Aspect Ratio grid */
.ratio-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--sp-2);
}

.ratio-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-2);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--t-base);
  font-family: var(--font-mono);
  font-size: 0.6rem;
  letter-spacing: 0.04em;
  user-select: none;
}

.ratio-visual {
  background: var(--text-muted);
  border-radius: 2px;
  transition: background var(--t-base);
  flex-shrink: 0;
}

.ratio-btn:hover {
  border-color: var(--border-focus);
  color: var(--text-primary);
  background: var(--bg-hover);
}

.ratio-btn.active {
  border-color: var(--gold);
  background: var(--gold-dim);
  color: var(--gold);
}

.ratio-btn.active .ratio-visual { background: var(--gold); }

/* Generate button */
.btn-generate {
  width: 100%;
  padding: var(--sp-4) var(--sp-6);
  background: linear-gradient(135deg, var(--gold), var(--gold-light));
  border: none;
  border-radius: var(--r-lg);
  color: #0d0d0f;
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-3);
  transition: all var(--t-base);
  box-shadow: var(--shadow-gold);
  letter-spacing: 0.01em;
  position: relative;
  overflow: hidden;
}

.btn-generate-hint {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  opacity: 0.5;
  margin-left: auto;
}

.btn-generate::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, var(--gold-light), var(--gold));
  opacity: 0;
  transition: opacity var(--t-base);
}

.btn-generate:hover:not(:disabled)::after { opacity: 1; }
.btn-generate > * { position: relative; z-index: 1; }

.btn-generate:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 8px 32px var(--gold-glow);
}

.btn-generate:active:not(:disabled) { transform: translateY(0); }

.btn-generate:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* Small text buttons */
.btn-text-sm {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 4px 10px;
  cursor: pointer;
  transition: all var(--t-fast);
}

.btn-text-sm:hover { color: var(--text-primary); border-color: var(--text-muted); }
.btn-text-sm.btn-danger:hover { color: var(--error); border-color: var(--error); background: var(--error-soft); }

/* ============================================================
   10. OUTPUT PANEL (right)
   ============================================================ */
.output-panel {
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}

.output-display {
  min-height: 500px;
  position: relative;
  display: grid;
  place-items: center;
  border-radius: var(--r-xl);
  overflow: hidden;
}

/* All state children fill the display */
.state-empty,
.state-loading,
.state-error,
.state-image {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--sp-10);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--t-base);
}

.state-empty.active,
.state-loading.active,
.state-error.active,
.state-image.active {
  opacity: 1;
  pointer-events: auto;
}

/* Empty state */
.empty-orb {
  position: relative;
  width: 96px;
  height: 96px;
  display: grid;
  place-items: center;
  margin-bottom: var(--sp-5);
}

.empty-orb-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1px solid rgba(196,156,86,0.2);
  animation: orb-breathe 3.5s ease-in-out infinite;
}

.empty-orb-ring--2 {
  inset: -16px;
  border-color: rgba(196,156,86,0.08);
  animation-delay: 0.5s;
  animation-duration: 3.5s;
}

@keyframes orb-breathe {
  0%, 100% { transform: scale(1); opacity: 0.4; }
  50%       { transform: scale(1.08); opacity: 0.9; }
}

.empty-orb-glyph {
  font-size: 2.2rem;
  color: var(--gold);
  opacity: 0.4;
  animation: orb-breathe 3.5s ease-in-out infinite;
}

.empty-title {
  font-family: var(--font-display);
  font-size: 1.6rem;
  font-weight: 400;
  font-style: italic;
  color: var(--text-primary);
  margin-bottom: var(--sp-3);
  text-align: center;
}

.empty-sub {
  font-size: 0.85rem;
  color: var(--text-secondary);
  text-align: center;
  max-width: 300px;
  line-height: 1.7;
}

/* Loading state */
.state-loading { gap: var(--sp-4); }

.spinner {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  border-top-color: var(--gold);
  animation: spin 0.9s linear infinite;
}

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

.loading-track {
  width: 180px;
  height: 2px;
  background: var(--border);
  border-radius: var(--r-full);
  overflow: hidden;
}

.loading-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--gold), var(--gold-light));
  border-radius: var(--r-full);
  animation: indeterminate 1.8s ease-in-out infinite;
  transform-origin: left center;
}

@keyframes indeterminate {
  0%   { transform: scaleX(0) translateX(0%); }
  50%  { transform: scaleX(0.5) translateX(60%); }
  100% { transform: scaleX(0) translateX(200%); }
}

.loading-label {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

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

/* Error state */
.state-error { gap: var(--sp-4); }

.error-glyph {
  font-size: 2.5rem;
  color: var(--error);
  opacity: 0.8;
}

.error-title {
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-style: italic;
  color: var(--error);
}

.error-message {
  font-size: 0.85rem;
  color: var(--text-secondary);
  text-align: center;
  max-width: 320px;
  line-height: 1.7;
}

.error-actions {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  margin-top: var(--sp-2);
}

.btn-retry {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-5);
  background: var(--error-soft);
  border: 1px solid var(--error);
  border-radius: var(--r-md);
  color: var(--error);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  transition: all var(--t-fast);
}

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

/* Image state */
.state-image {
  padding: 0;
  border-radius: var(--r-xl);
}

.output-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: var(--bg-base);
  border-radius: var(--r-xl);
  display: block;
  animation: img-reveal 0.5s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes img-reveal {
  from { opacity: 0; transform: scale(0.97); }
  to   { opacity: 1; transform: scale(1); }
}

/* Image toolbar */
.image-toolbar {
  position: absolute;
  bottom: var(--sp-4);
  right: var(--sp-4);
  display: flex;
  gap: var(--sp-2);
  opacity: 0;
  transform: translateY(6px);
  transition: all var(--t-base);
}

.state-image.active:hover .image-toolbar {
  opacity: 1;
  transform: translateY(0);
}

.toolbar-btn {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-4);
  border-radius: var(--r-md);
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(13,13,15,0.88);
  color: #f0ede8;
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: all var(--t-fast);
}

.toolbar-btn svg { width: 12px; height: 12px; stroke-width: 2; stroke-linecap: round; }
.toolbar-btn:hover { background: var(--gold); color: #0d0d0f; border-color: var(--gold); }

/* ============================================================
   11. HISTORY
   ============================================================ */
.history-panel {}

.history-count {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  padding: 2px 9px;
  color: var(--text-muted);
  min-width: 26px;
  text-align: center;
}

.history-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: var(--sp-3);
}

.history-empty {
  grid-column: 1 / -1;
  padding: var(--sp-8) var(--sp-5);
  text-align: center;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.65rem;
  letter-spacing: 0.06em;
  border: 1px dashed var(--border);
  border-radius: var(--r-lg);
  line-height: 1.6;
}

.history-item {
  aspect-ratio: 1;
  border-radius: var(--r-md);
  overflow: hidden;
  border: 1px solid var(--border);
  cursor: pointer;
  position: relative;
  background: var(--bg-elevated);
  transition: all var(--t-base);
}

.history-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  animation: img-reveal 0.4s ease;
}

.history-item:hover {
  border-color: var(--gold);
  transform: translateY(-3px) scale(1.02);
  box-shadow: 0 8px 24px var(--gold-glow);
}

.history-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(13,13,15,0.88) 0%, transparent 55%);
  opacity: 0;
  transition: opacity var(--t-base);
  display: flex;
  align-items: flex-end;
  padding: var(--sp-2);
}

.history-item:hover .history-overlay { opacity: 1; }

.history-prompt-label {
  font-family: var(--font-mono);
  font-size: 0.52rem;
  color: rgba(240,237,232,0.75);
  letter-spacing: 0.06em;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ============================================================
   12. FOOTER
   ============================================================ */
.footer {
  border-top: 1px solid var(--border);
  padding: var(--sp-5) 0;
  margin-top: auto;
}

.footer-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--sp-3);
}

.footer-note {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  color: var(--text-muted);
  letter-spacing: 0.06em;
}

/* ============================================================
   13. LIGHTBOX
   ============================================================ */
.lightbox {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.95);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
  animation: fade-in 0.2s ease;
}

.lightbox.open { display: flex; }

.lightbox-img {
  max-width: 94vw;
  max-height: 94vh;
  object-fit: contain;
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
}

.lightbox-close {
  position: absolute;
  top: var(--sp-5);
  right: var(--sp-5);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.15);
  background: rgba(255,255,255,0.08);
  color: rgba(255,255,255,0.7);
  font-size: 1rem;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: all var(--t-fast);
  backdrop-filter: blur(8px);
}

.lightbox-close:hover { background: var(--gold); color: #0d0d0f; border-color: var(--gold); }

/* ============================================================
   14. SCROLLBAR
   ============================================================ */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: var(--r-full); }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ============================================================
   15. RESPONSIVE
   ============================================================ */
@media (max-width: 900px) {
  .studio-grid { grid-template-columns: 1fr; }
  .controls-panel { position: static; }
}

@media (max-width: 600px) {
  .container { padding: 0 var(--sp-4); }
  .onboarding-card { padding: var(--sp-8) var(--sp-5); }
  .history-grid { grid-template-columns: repeat(3, 1fr); }
  .badge-open { display: none; }
}

/* ============================================================
   16. UTILITY ANIMATIONS
   ============================================================ */
@keyframes pulse-once {
  0%   { box-shadow: 0 0 0 0 var(--gold-glow); }
  70%  { box-shadow: 0 0 0 10px rgba(196,156,86,0); }
  100% { box-shadow: 0 0 0 0 rgba(196,156,86,0); }
}

.pulse { animation: pulse-once 0.6s ease; }
