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

:root {
  --bg: #0a0a0f;
  --surface: #111118;
  --surface2: #1a1a25;
  --border: #2a2a3a;
  --accent: #7c6dfa;
  --accent2: #fa6d8f;
  --accent3: #6dfacc;
  --text: #e8e8f0;
  --muted: #6a6a88;
  --glow: rgba(124,109,250,0.3);
}

body {
  font-family: 'Syne', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 50% at 20% 10%, rgba(124,109,250,0.12) 0%, transparent 60%),
    radial-gradient(ellipse 60% 40% at 80% 90%, rgba(250,109,143,0.08) 0%, transparent 60%);
  pointer-events: none;
  z-index: 0;
}

/* HEADER */
header {
  position: relative;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 40px;
  border-bottom: 1px solid var(--border);
}

.logo { font-size: 1.4rem; font-weight: 800; letter-spacing: -0.03em; }
.logo span { color: var(--accent); }

.logo-badge {
  font-family: 'DM Mono', monospace;
  font-size: 0.65rem;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: white;
  padding: 2px 8px;
  border-radius: 20px;
  margin-left: 8px;
  vertical-align: middle;
}

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

.header-user {
  font-family: 'DM Mono', monospace;
  font-size: 0.75rem;
  color: var(--muted);
}

.logout-btn {
  font-family: 'DM Mono', monospace;
  font-size: 0.72rem;
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 5px 12px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}
.logout-btn:hover { border-color: var(--accent2); color: var(--accent2); }

/* LAYOUT */
.app {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 360px 1fr;
  min-height: calc(100vh - 65px);
  align-items: start;
}

/* LEFT PANEL */
.panel {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 28px 24px 40px;
  gap: 24px;
  position: sticky;
  top: 0;
  max-height: 100vh;
  overflow-y: auto;
}

.panel::-webkit-scrollbar { width: 4px; }
.panel::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.section-label {
  font-family: 'DM Mono', monospace;
  font-size: 0.65rem;
  letter-spacing: 0.15em;
  color: var(--muted);
  text-transform: uppercase;
  margin-bottom: 10px;
}

/* MODE TABS */
.mode-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px;
  gap: 4px;
}

.tab-btn {
  padding: 9px 6px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-family: 'Syne', sans-serif;
  font-size: 0.76rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tab-btn.active {
  background: linear-gradient(135deg, var(--accent), #9c8dfa);
  color: white;
  box-shadow: 0 2px 12px rgba(124,109,250,0.35);
}

/* UPLOAD ZONE */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: 12px;
  padding: 28px 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.25s;
}

.upload-zone:hover { border-color: var(--accent); background: rgba(124,109,250,0.05); }
.upload-icon { font-size: 2.2rem; margin-bottom: 10px; }
.upload-zone p { font-size: 0.82rem; color: var(--muted); line-height: 1.6; }
.upload-zone input[type="file"] { display: none; }

/* PROMPT */
.prompt-area { position: relative; }

.prompt-area textarea {
  width: 100%;
  min-height: 140px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 14px 30px;
  font-family: 'DM Mono', monospace;
  font-size: 0.82rem;
  color: var(--text);
  outline: none;
  resize: vertical;
  line-height: 1.6;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.prompt-area textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--glow); }
.prompt-area textarea::placeholder { color: var(--muted); }

.char-count {
  position: absolute;
  bottom: 10px; right: 12px;
  font-family: 'DM Mono', monospace;
  font-size: 0.65rem;
  color: var(--muted);
  pointer-events: none;
}

/* SETTINGS */
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.select-wrap { display: flex; flex-direction: column; gap: 6px; }

.select-wrap label {
  font-family: 'DM Mono', monospace;
  font-size: 0.65rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.select-wrap select {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 10px;
  font-family: 'DM Mono', monospace;
  font-size: 0.78rem;
  color: var(--text);
  outline: none;
  cursor: pointer;
  transition: border-color 0.2s;
}

.select-wrap select:focus { border-color: var(--accent); }

/* GENERATE BUTTON */
.gen-btn {
  width: 100%;
  padding: 16px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent2) 100%);
  border: none;
  border-radius: 12px;
  color: white;
  font-family: 'Syne', sans-serif;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.25s;
  position: relative;
  overflow: hidden;
}

.gen-btn::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.15), transparent);
  opacity: 0;
  transition: opacity 0.2s;
}

.gen-btn:hover::before { opacity: 1; }
.gen-btn:hover { transform: translateY(-1px); box-shadow: 0 8px 30px rgba(124,109,250,0.4); }
.gen-btn:active { transform: translateY(0); }
.gen-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

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

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

.gen-btn.loading .spinner { display: block; }

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

/* RIGHT CANVAS */
.canvas {
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  position: relative;
  min-height: calc(100vh - 65px);
}

.canvas::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(var(--border) 1px, transparent 1px),
    linear-gradient(90deg, var(--border) 1px, transparent 1px);
  background-size: 40px 40px;
  opacity: 0.3;
  pointer-events: none;
}

/* EMPTY STATE */
.empty-state {
  position: relative;
  z-index: 2;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 80px 40px;
  min-height: calc(100vh - 65px);
  justify-content: center;
}

.empty-icon {
  width: 80px; height: 80px;
  border-radius: 20px;
  background: var(--surface2);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
}

.empty-state h2 { font-size: 1.4rem; font-weight: 800; }
.empty-state p { font-size: 0.85rem; color: var(--muted); max-width: 300px; line-height: 1.6; }

/* RESULT AREA */
.result-area {
  position: relative;
  z-index: 2;
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding: 48px 32px;
  width: 100%;
  max-width: 700px;
}

.result-area.visible { display: flex; }

.result-image-wrap {
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 20px 80px rgba(0,0,0,0.6), 0 0 0 1px var(--border);
  animation: popIn 0.4s cubic-bezier(0.34,1.56,0.64,1);
  width: 100%;
}

@keyframes popIn { from { transform: scale(0.88); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.result-image-wrap img { display: block; width: 100%; height: auto; }

.result-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }

.action-btn {
  padding: 10px 20px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: 'Syne', sans-serif;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.action-btn:hover { border-color: var(--accent); color: var(--accent); background: rgba(124,109,250,0.08); }

.action-btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border-color: transparent;
  color: white;
}

.action-btn.primary:hover { color: white; box-shadow: 0 4px 16px rgba(124,109,250,0.35); }

/* CANVAS LOADER */
.canvas-loader {
  position: absolute;
  inset: 0;
  background: rgba(10,10,15,0.85);
  backdrop-filter: blur(4px);
  z-index: 10;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

.canvas-loader.visible { display: flex; }

.loader-ring {
  width: 64px; height: 64px;
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-right-color: var(--accent2);
  animation: spin 1s linear infinite;
}

.loader-text {
  font-family: 'DM Mono', monospace;
  font-size: 0.82rem;
  color: var(--muted);
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse { 0%, 100% { opacity: 0.5; } 50% { opacity: 1; } }

/* HISTORY STRIP */
.history-strip {
  position: relative;
  z-index: 1;
  padding: 28px 40px;
  border-top: 1px solid var(--border);
}

.history-label {
  font-family: 'DM Mono', monospace;
  font-size: 0.65rem;
  letter-spacing: 0.15em;
  color: var(--muted);
  text-transform: uppercase;
  margin-bottom: 16px;
}

.history-grid {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.history-item {
  width: 120px;
  cursor: pointer;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  transition: all 0.2s;
  background: var(--surface);
}

.history-item:hover { border-color: var(--accent); transform: translateY(-2px); box-shadow: 0 8px 24px rgba(0,0,0,0.4); }

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

.history-meta {
  padding: 6px 8px;
  font-family: 'DM Mono', monospace;
  font-size: 0.6rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* TOAST */
.toast {
  position: fixed;
  bottom: 28px; right: 28px;
  background: #2a0f18;
  border: 1px solid rgba(250,109,143,0.33);
  border-radius: 12px;
  padding: 14px 20px;
  font-family: 'DM Mono', monospace;
  font-size: 0.8rem;
  color: var(--accent2);
  z-index: 100;
  transform: translateY(20px);
  opacity: 0;
  transition: all 0.3s;
  max-width: 360px;
  line-height: 1.5;
}

.toast.show { transform: translateY(0); opacity: 1; }

.toast.success {
  background: #0f2a1a;
  border-color: rgba(109,250,204,0.33);
  color: var(--accent3);
}

/* AUTH PAGES */
.auth-wrap {
  min-height: calc(100vh - 65px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  position: relative;
  z-index: 1;
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 40px 36px;
  width: 100%;
  max-width: 400px;
}

.auth-logo {
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  margin-bottom: 6px;
}
.auth-logo span { color: var(--accent); }

.auth-sub { font-size: 0.85rem; color: var(--muted); margin-bottom: 28px; }

.auth-error {
  background: rgba(250,109,143,0.1);
  border: 1px solid rgba(250,109,143,0.3);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 0.8rem;
  color: var(--accent2);
  margin-bottom: 18px;
  line-height: 1.5;
}

.field-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }

.field-group label {
  font-family: 'DM Mono', monospace;
  font-size: 0.65rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.field-group input,
.field-group ul { display: block; }

.field-group input[type="text"],
.field-group input[type="password"] {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 11px 14px;
  font-family: 'DM Mono', monospace;
  font-size: 0.82rem;
  color: var(--text);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.field-group input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--glow); }

/* Django UserCreationForm renders password help as <ul> */
.field-group ul {
  list-style: none;
  font-family: 'DM Mono', monospace;
  font-size: 0.7rem;
  color: var(--muted);
  margin-top: 4px;
  line-height: 1.6;
}

.auth-btn {
  width: 100%;
  padding: 14px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border: none;
  border-radius: 10px;
  color: white;
  font-family: 'Syne', sans-serif;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  margin-top: 8px;
}

.auth-btn:hover { transform: translateY(-1px); box-shadow: 0 6px 24px rgba(124,109,250,0.4); }

.auth-link { margin-top: 20px; font-size: 0.82rem; color: var(--muted); text-align: center; }
.auth-link a { color: var(--accent); text-decoration: none; }
.auth-link a:hover { text-decoration: underline; }

/* RESPONSIVE */
@media (max-width: 768px) {
  .app { grid-template-columns: 1fr; }
  .panel { position: static; max-height: none; }
  .canvas { min-height: auto; }
  .empty-state { min-height: 50vh; }
  header { padding: 16px 20px; }
  .history-strip { padding: 20px; }
}
