:root {
  --bg: #08080c;
  --bg-elevated: #12121a;
  --bg-card: rgba(22, 22, 32, 0.85);
  --border: rgba(255, 255, 255, 0.08);
  --border-gold: rgba(201, 162, 39, 0.45);
  --text: #f0f0f5;
  --text-muted: #8b8b9e;
  --blue: #3b82f6;
  --blue-glow: rgba(59, 130, 246, 0.35);
  --gold: #c9a227;
  --gold-light: #e8c547;
  --green: #52c41a;
  --radius: 14px;
  --radius-sm: 10px;
  --font: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --sidebar-w: 280px;
  --header-h: 64px;
  --composer-h: auto;
}

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

html, body {
  height: 100%;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body {
  overflow-x: hidden;
}

.hidden { display: none !important; }

.bg-glow {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(ellipse 80% 60% at 10% 20%, rgba(59, 130, 246, 0.12), transparent 50%),
    radial-gradient(ellipse 60% 50% at 90% 80%, rgba(201, 162, 39, 0.08), transparent 50%),
    radial-gradient(ellipse 50% 40% at 50% 50%, rgba(139, 92, 246, 0.06), transparent 60%);
}

.glass {
  background: var(--bg-card);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* ========== Auth ========== */
.auth-page {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr 420px;
  gap: 48px;
  align-items: center;
  padding: 48px 64px;
  max-width: 1200px;
  margin: 0 auto;
}

.auth-hero h1 {
  font-size: clamp(2.5rem, 5vw, 3.5rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  margin: 16px 0 12px;
  background: linear-gradient(135deg, #fff 0%, #c9a227 60%, #3b82f6 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.hero-badge {
  display: inline-block;
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(201, 162, 39, 0.12);
  border: 1px solid var(--border-gold);
  color: var(--gold-light);
  font-size: 13px;
  font-weight: 500;
}

.hero-sub {
  font-size: 1.125rem;
  color: var(--text-muted);
  margin-bottom: 32px;
}

.hero-features {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.hero-features li {
  color: var(--text-muted);
  font-size: 15px;
}

.auth-card {
  padding: 32px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.5);
}

.auth-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 24px;
  background: rgba(0, 0, 0, 0.3);
  border-radius: var(--radius-sm);
  padding: 4px;
}

.auth-tab {
  flex: 1;
  padding: 10px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
}

.auth-tab.active {
  background: var(--blue);
  color: #fff;
}

.auth-form label {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
  margin-top: 14px;
}

.auth-form label:first-child { margin-top: 0; }

.auth-form .optional { opacity: 0.6; }

.auth-form input {
  width: 100%;
  padding: 12px 14px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

.auth-form input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--blue-glow);
}

.auth-tip {
  margin-top: 20px;
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
}

/* ========== Buttons ========== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
  color: inherit;
}

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

.btn-primary {
  background: linear-gradient(135deg, var(--blue), #6366f1);
  color: #fff;
  margin-top: 20px;
}

.btn-primary:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 8px 24px var(--blue-glow);
}

.btn-block { width: 100%; }

.btn-ghost {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  color: var(--text);
}

.btn-ghost:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.1);
}

.btn-gold {
  background: rgba(201, 162, 39, 0.12);
  border: 1px solid var(--border-gold);
  color: var(--gold-light);
  white-space: nowrap;
  flex-shrink: 0;
}

.btn-gold:hover:not(:disabled) {
  background: rgba(201, 162, 39, 0.22);
}

.btn-generate {
  flex-shrink: 0;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--blue), #6366f1);
  color: #fff;
  flex-direction: column;
  gap: 2px;
  box-shadow: 0 8px 32px var(--blue-glow);
}

.btn-generate:hover:not(:disabled) {
  transform: scale(1.04);
}

.btn-generate .gen-icon { font-size: 18px; line-height: 1; }
.btn-generate .gen-price { font-size: 11px; opacity: 0.9; font-weight: 500; }

/* ========== Studio ========== */
.studio {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.studio-header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  border-bottom: 1px solid var(--border);
  background: rgba(8, 8, 12, 0.8);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 50;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-mark {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--blue), #8b5cf6);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}

.logo-title { font-weight: 700; font-size: 16px; }
.logo-sub { font-size: 11px; color: var(--text-muted); }

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.balance-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: rgba(82, 196, 26, 0.1);
  border: 1px solid rgba(82, 196, 26, 0.25);
  border-radius: 999px;
}

.balance-label { font-size: 12px; color: var(--text-muted); }
.balance-value { font-weight: 700; color: var(--green); }

.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px 6px 6px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
}

.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--gold), #e8a838);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: #1a1a1a;
}

.studio-body {
  flex: 1;
  display: flex;
  min-height: 0;
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  padding: 20px 16px;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  background: rgba(0, 0, 0, 0.2);
}

.panel-block { margin-bottom: 24px; }

.panel-block h3 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.model-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.model-card {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.02);
  cursor: pointer;
  transition: all 0.2s;
  text-align: left;
  font-family: inherit;
  color: inherit;
  width: 100%;
}

.model-card:hover {
  border-color: rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.04);
}

.model-card.selected {
  border-color: var(--blue);
  background: rgba(59, 130, 246, 0.1);
  box-shadow: 0 0 0 1px var(--blue);
}

.model-card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.model-card-name { font-weight: 600; font-size: 13px; }

.model-card-price {
  font-size: 11px;
  color: var(--gold-light);
  font-weight: 600;
}

.model-card-desc {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.4;
}

.pill-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.pill {
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
}

.pill:hover { border-color: rgba(255,255,255,0.2); color: var(--text); }

.pill.selected {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}

.canvas-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 24px;
  overflow-y: auto;
}

.preview-stage {
  flex: 1;
  min-height: 360px;
  border-radius: var(--radius);
  border: 1px dashed var(--border);
  background: rgba(0, 0, 0, 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.preview-empty {
  text-align: center;
  padding: 48px 24px;
}

.empty-icon { font-size: 48px; margin-bottom: 16px; opacity: 0.8; }
.preview-empty h2 { font-size: 1.25rem; margin-bottom: 8px; }
.preview-empty p { color: var(--text-muted); font-size: 14px; }

.preview-loading {
  text-align: center;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 3px solid var(--border);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 20px;
}

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

.loading-hint { font-size: 12px; color: var(--text-muted); margin-top: 8px; }

.preview-result {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.preview-result img {
  max-width: 100%;
  max-height: calc(100vh - 320px);
  border-radius: var(--radius-sm);
  box-shadow: 0 16px 64px rgba(0, 0, 0, 0.5);
  object-fit: contain;
}

.result-toolbar {
  display: flex;
  gap: 8px;
  margin-top: 16px;
  flex-wrap: wrap;
  justify-content: center;
}

.history-section { margin-top: 20px; }

.history-head {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.history-row {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.history-thumb {
  flex-shrink: 0;
  width: 72px;
  height: 72px;
  border-radius: 10px;
  overflow: hidden;
  border: 2px solid transparent;
  cursor: pointer;
  transition: border-color 0.2s;
}

.history-thumb:hover, .history-thumb.active {
  border-color: var(--blue);
}

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

/* ========== Composer ========== */
.composer {
  border-top: 1px solid var(--border);
  padding: 16px 24px 20px;
  background: rgba(8, 8, 12, 0.95);
  backdrop-filter: blur(12px);
}

.ref-zone {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.ref-zone.drag-over {
  outline: 2px dashed var(--blue);
  outline-offset: 4px;
  border-radius: var(--radius-sm);
}

.ref-strip {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.ref-item {
  position: relative;
  width: 56px;
  height: 56px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
}

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

.ref-item .ref-label {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0,0,0,0.65);
  font-size: 9px;
  text-align: center;
  padding: 2px;
}

.ref-item .ref-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  border: none;
  border-radius: 50%;
  background: rgba(0,0,0,0.7);
  color: #fff;
  font-size: 12px;
  cursor: pointer;
  line-height: 1;
}

.ref-add {
  width: 56px;
  height: 56px;
  border-radius: 10px;
  border: 1px dashed var(--border);
  background: transparent;
  color: var(--text-muted);
  font-size: 24px;
  cursor: pointer;
  transition: all 0.2s;
}

.ref-add:hover {
  border-color: var(--blue);
  color: var(--blue);
}

.ref-hint {
  font-size: 12px;
  color: var(--text-muted);
}

.prompt-row {
  display: flex;
  align-items: flex-end;
  gap: 12px;
}

.prompt-row textarea {
  flex: 1;
  min-height: 96px;
  max-height: 360px;
  padding: 14px 16px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  resize: vertical;
  outline: none;
  line-height: 1.5;
}

.prompt-row textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--blue-glow);
}

/* ========== Modal ========== */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal {
  width: 100%;
  max-width: 560px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 32px 100px rgba(0, 0, 0, 0.6);
}

.modal-sm { max-width: 400px; }

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-head h3 { font-size: 16px; }

.modal-close {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 8px;
  background: rgba(255,255,255,0.06);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
}

.modal-body {
  padding: 16px 20px 20px;
  overflow-y: auto;
}

.prompt-category { margin-bottom: 16px; }

.prompt-category-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--gold-light);
  margin-bottom: 8px;
}

.prompt-item {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  margin-bottom: 6px;
  cursor: pointer;
  transition: background 0.15s;
}

.prompt-item:hover { background: rgba(255,255,255,0.04); }

.prompt-item .p-title { font-weight: 600; font-size: 13px; margin-bottom: 4px; }
.prompt-item .p-text { font-size: 12px; color: var(--text-muted); line-height: 1.4; }

.user-info-row {
  padding: 8px 0;
  font-size: 13px;
  color: var(--text-muted);
}

.user-info-row strong { color: var(--text); }

.user-id-box {
  margin: 12px 0;
  padding: 10px 12px;
  background: rgba(0,0,0,0.35);
  border-radius: var(--radius-sm);
  font-family: monospace;
  font-size: 12px;
  word-break: break-all;
}

/* ========== Toast ========== */
#toastContainer {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  font-size: 13px;
  animation: toastIn 0.3s ease;
  max-width: 360px;
}

.toast.success { border-color: rgba(82,196,26,0.4); }
.toast.error { border-color: rgba(239,68,68,0.4); }
.toast.warning { border-color: rgba(234,179,8,0.4); }

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

/* ========== Responsive ========== */
@media (max-width: 900px) {
  .auth-page {
    grid-template-columns: 1fr;
    padding: 32px 20px;
    text-align: center;
  }

  .hero-features { align-items: center; }
  .auth-card { max-width: 420px; margin: 0 auto; width: 100%; }

  .studio-body { flex-direction: column; }

  .sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    padding: 16px;
  }

  .panel-block:last-child { grid-column: 1 / -1; }

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

  .prompt-row { flex-wrap: wrap; }
  .btn-generate { width: 64px; height: 64px; }
}

@media (max-width: 520px) {
  .sidebar { grid-template-columns: 1fr; }
  .model-list { grid-template-columns: 1fr; }
  .ref-hint { width: 100%; }
  .studio-header { padding: 0 12px; }
  .composer { padding: 12px; }
}

.beian-bar {
  position: relative;
  z-index: 5;
  padding: 10px 12px 14px;
  text-align: center;
  font-size: 12px;
  line-height: 1.4;
}

.beian-bar a {
  color: #8b8b9e;
  text-decoration: none;
}

.beian-bar a:hover {
  color: #c9a227;
}
