/* ========================================
   MuseLab Studio — Dark Cinematic Theme
   Font: Syne (headings) + Plus Jakarta Sans (body)
   Palette: near-black bg, warm gold accent, cool tints
   ======================================== */

:root {
  --bg: #0c0c0f;
  --bg-2: #131318;
  --bg-3: #1a1a22;
  --border: rgba(255,255,255,0.08);
  --border-hover: rgba(255,255,255,0.18);
  --text: #f0eee8;
  --text-muted: #8a8799;
  --text-dim: #5a5868;
  --accent: #d4a853;
  --accent-glow: rgba(212,168,83,0.2);
  --accent-hover: #e8be6a;
  --chip-bg: #1e1e28;
  --chip-active: #d4a853;
  --chip-active-text: #0c0c0f;
  --font-display: 'Syne', sans-serif;
  --font-body: 'Plus Jakarta Sans', sans-serif;
  --font-mono: 'Space Mono', monospace;
}

*, *::before, *::after { box-sizing: border-box; }

.studio-body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  min-height: 100vh;
  overflow-x: hidden;
}

/* NAV */
.studio-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  height: 60px;
  background: rgba(12,12,15,0.9);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-logo {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.2rem;
  letter-spacing: -0.02em;
  color: var(--text);
  text-decoration: none;
}

.nav-logo span { color: var(--accent); }

.nav-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.nav-username {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

/* MAIN LAYOUT — sidebar + canvas */
.studio-main {
  display: grid;
  grid-template-columns: 380px 1fr;
  min-height: calc(100vh - 60px);
}

/* BUILDER PANEL */
.builder-panel {
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 32px 24px;
  max-height: calc(100vh - 60px);
  position: sticky;
  top: 60px;
}

.builder-header { margin-bottom: 28px; }

.builder-header h2 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.4rem;
  margin: 0 0 6px;
  letter-spacing: -0.03em;
}

.builder-sub {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin: 0;
}

/* FIELD GROUPS */
.field-group {
  margin-bottom: 28px;
  padding-bottom: 28px;
  border-bottom: 1px solid var(--border);
}

.field-group:last-of-type { border-bottom: none; }

.group-label {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 16px;
}

.field-row {
  margin-bottom: 16px;
}

.field-row label {
  display: block;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 8px;
  letter-spacing: 0.01em;
}

/* CHIPS */
.chip-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  padding: 5px 12px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--chip-bg);
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.chip:hover {
  border-color: var(--border-hover);
  color: var(--text);
}

.chip.active {
  background: var(--chip-active);
  border-color: var(--chip-active);
  color: var(--chip-active-text);
  font-weight: 600;
}

/* SKIN SWATCHES */
.skin-swatches {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.swatch {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
  outline: none;
}

.swatch:hover { transform: scale(1.12); }

.swatch.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
  transform: scale(1.12);
}

/* SELECT */
.studio-select {
  width: 100%;
  background: var(--chip-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.82rem;
  padding: 8px 12px;
  cursor: pointer;
  outline: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='12' height='8' viewBox='0 0 12 8' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%238a8799' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
  transition: border-color 0.15s ease;
}

.studio-select:hover { border-color: var(--border-hover); }
.studio-select:focus { border-color: var(--accent); }
.studio-select option { background: var(--bg-3); }

/* GENERATE BUTTON */
.btn-generate {
  width: 100%;
  padding: 14px 24px;
  background: var(--accent);
  color: #0c0c0f;
  border: none;
  border-radius: 8px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.2s ease;
  margin-top: 8px;
  box-shadow: 0 4px 20px var(--accent-glow);
  position: relative;
}

.btn-generate:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: 0 6px 28px rgba(212,168,83,0.35);
}

.btn-generate:active { transform: translateY(0); }
.btn-generate:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.btn-generate-inner,
.btn-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(0,0,0,0.3);
  border-top-color: #0c0c0f;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

/* PREVIEW PANEL */
.preview-panel {
  padding: 32px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  background: var(--bg);
}

.preview-header h2 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.4rem;
  margin: 0 0 4px;
  letter-spacing: -0.03em;
}

.preview-sub {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin: 0;
}

/* CANVAS */
.preview-canvas {
  aspect-ratio: 1 / 1;
  max-width: 540px;
  width: 100%;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.canvas-placeholder {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.85rem;
  padding: 24px;
}

.placeholder-icon { margin-bottom: 12px; }

.generated-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.generating-overlay {
  position: absolute;
  inset: 0;
  background: rgba(12,12,15,0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  text-align: center;
}

.gen-spinner {
  width: 48px;
  height: 48px;
  border: 3px solid rgba(212,168,83,0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

.gen-sub {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
  margin: -8px 0 0;
}

/* ACTION BUTTONS */
.preview-actions {
  display: flex;
  gap: 12px;
  max-width: 540px;
}

.btn-download,
.btn-new {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: 8px;
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  text-decoration: none;
}

.btn-download {
  background: var(--bg-3);
  border: 1px solid var(--border);
  color: var(--text);
}

.btn-download:hover { border-color: var(--border-hover); color: var(--text); }

.btn-new {
  background: transparent;
  border: 1px solid var(--accent);
  color: var(--accent);
}

.btn-new:hover { background: var(--accent-glow); }

/* GALLERY */
.gallery-section { max-width: 540px; }

.gallery-title {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 0 0 16px;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.gallery-thumb {
  aspect-ratio: 1;
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  border: 1px solid var(--border);
  transition: all 0.15s ease;
}

.gallery-thumb:hover {
  border-color: var(--accent);
  transform: scale(1.03);
}

.gallery-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* =====================
   AUTH MODAL
   ===================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
}

.modal-backdrop.hidden { display: none; }

.auth-modal {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 36px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 24px 80px rgba(0,0,0,0.6);
}

.auth-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  margin-bottom: 28px;
  gap: 0;
}

.auth-tab {
  flex: 1;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  padding: 10px;
  font-family: var(--font-body);
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
}

.auth-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.auth-form h2 {
  font-family: var(--font-display);
  font-size: 1.4rem;
  font-weight: 700;
  margin: 0 0 6px;
  letter-spacing: -0.03em;
}

.auth-sub {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin: 0 0 24px;
}

.form-field {
  margin-bottom: 16px;
}

.form-field label {
  display: block;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.form-field input {
  width: 100%;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.9rem;
  padding: 10px 14px;
  outline: none;
  transition: border-color 0.15s;
}

.form-field input:focus { border-color: var(--accent); }
.form-field input::placeholder { color: var(--text-dim); }

.btn-auth {
  width: 100%;
  padding: 12px;
  background: var(--accent);
  color: #0c0c0f;
  border: none;
  border-radius: 8px;
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  margin-top: 8px;
  transition: all 0.15s;
}

.btn-auth:hover { background: var(--accent-hover); }

.auth-error {
  background: rgba(220,50,50,0.12);
  border: 1px solid rgba(220,50,50,0.3);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 0.82rem;
  color: #ff8080;
  margin-bottom: 16px;
}

.auth-switch {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
  margin-top: 16px;
}

.auth-switch button {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: inherit;
  font-family: inherit;
  padding: 0;
  text-decoration: underline;
}

/* GHOST / SMALL BUTTONS */
.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 6px;
  font-family: var(--font-body);
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  padding: 6px 12px;
  transition: all 0.15s;
}

.btn-ghost:hover {
  border-color: var(--border-hover);
  color: var(--text);
}

/* NAME INPUT */
.studio-input {
  width: 100%;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.9rem;
  padding: 10px 14px;
  outline: none;
  transition: border-color 0.15s;
}

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

.studio-input::placeholder {
  color: var(--text-dim);
}

.name-row {
  margin-bottom: 20px;
}

.label-optional {
  font-size: 0.75rem;
  color: var(--text-dim);
  font-weight: 400;
}

/* ── PRESETS SECTION ─────────────────────────────────────────────────────── */
.presets-section {
  margin-bottom: 24px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.presets-label {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.presets-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.preset-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.18s ease;
  text-align: left;
  width: 100%;
}

.preset-card:hover {
  border-color: var(--border-hover);
  background: rgba(212,168,83,0.06);
}

.preset-card.selected {
  border-color: var(--accent);
  background: rgba(212,168,83,0.1);
  box-shadow: 0 0 0 1px var(--accent);
}

.preset-icon {
  color: var(--accent);
  flex-shrink: 0;
  opacity: 0.8;
}

.preset-card.selected .preset-icon { opacity: 1; }

.preset-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.preset-name {
  font-family: var(--font-body);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.preset-desc {
  font-size: 0.7rem;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Field update flash animation */
@keyframes fieldFlash {
  0%   { background: rgba(212,168,83,0.4); }
  100% { background: transparent; }
}

.chip.flash-update,
.swatch.flash-update,
.studio-select.flash-update {
  animation: fieldFlash 0.6s ease-out;
}

/* RESPONSIVE */
@media (max-width: 900px) {
  .studio-main {
    grid-template-columns: 1fr;
  }

  .builder-panel {
    position: static;
    max-height: none;
    overflow-y: visible;
    padding: 20px 16px;
  }

  .preview-panel {
    padding: 20px 16px;
  }

  .preview-canvas {
    max-width: 100%;
  }

  .preview-actions {
    max-width: 100%;
  }

  /* Sticky nav on mobile */
  .studio-nav {
    padding: 0 16px;
  }

  /* Floating generate button on mobile */
  .btn-generate {
    position: sticky;
    bottom: 12px;
    z-index: 10;
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  }
}

@media (max-width: 480px) {
  .preset-card {
    padding: 10px;
  }

  .gallery-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}
