/* ============================================================
   ImageGen AI — Mobile-First PWA
   ============================================================ */

:root {
  --bg: #0A0A0F;
  --bg2: #12121C;
  --surface: #1A1A2E;
  --surface-light: #252545;
  --primary: #7B2FBE;
  --primary-light: #9D4EDD;
  --primary-glow: rgba(123, 47, 190, 0.3);
  --accent: #E040FB;
  --text: #FFFFFF;
  --text-dim: #7878AA;
  --text-muted: #4A4A6A;
  --success: #00E676;
  --error: #FF5252;
  --border: #2A2A45;
  --radius: 16px;
  --radius-sm: 10px;
  --radius-xl: 24px;
  --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

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

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

body {
  padding-bottom: env(safe-area-inset-bottom, 20px);
}

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ============================================================
   Login Screen
   ============================================================ */

.login-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
  padding: 20px;
}

.login-screen.hidden { display: none; }

.login-card {
  width: 100%;
  max-width: 360px;
  text-align: center;
}

.login-title {
  font-size: 36px;
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary-light), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 8px;
}

.login-sub {
  color: var(--text-dim);
  font-size: 15px;
  margin-bottom: 32px;
}

.login-field {
  margin-bottom: 14px;
}

.login-field input {
  width: 100%;
  padding: 16px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

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

.login-field input::placeholder { color: var(--text-muted); }

.login-btn {
  width: 100%;
  padding: 16px;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  border: none;
  border-radius: var(--radius);
  color: var(--text);
  font-size: 17px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  margin-top: 8px;
  transition: all var(--transition);
}

.login-btn:hover { opacity: 0.9; }
.login-btn:active { transform: scale(0.98); }
.login-btn:disabled { background: var(--surface-light); cursor: not-allowed; }

.login-error {
  color: var(--error);
  font-size: 14px;
  margin-top: 14px;
  min-height: 20px;
}

/* ============================================================
   Header
   ============================================================ */

.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(10, 10, 15, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  padding: 16px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.header h1 {
  font-size: 22px;
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary-light), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.status-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-dim);
  background: var(--surface);
  padding: 5px 12px;
  border-radius: 20px;
  border: 1px solid var(--border);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--error);
  transition: background var(--transition);
}

.status-dot.online { background: var(--success); box-shadow: 0 0 8px var(--success); }

.logout-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 8px;
  font-size: 16px;
  cursor: pointer;
  transition: border-color var(--transition);
  line-height: 1;
}

.logout-btn:hover { border-color: var(--error); }

/* ============================================================
   Main Content
   ============================================================ */

.main {
  max-width: 500px;
  margin: 0 auto;
  padding: 20px 20px 100px;
}

/* ---- Section Labels ---- */

.label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-dim);
  margin-bottom: 10px;
}

/* ============================================================
   Topic Input
   ============================================================ */

.input-section { margin-bottom: 24px; }

.input-wrap {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color var(--transition), box-shadow var(--transition);
}

.input-wrap:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.input-wrap textarea {
  width: 100%;
  min-height: 80px;
  padding: 16px;
  background: none;
  border: none;
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
  resize: none;
  outline: none;
  line-height: 1.5;
}

.input-wrap textarea::placeholder { color: var(--text-muted); }

.char-count {
  position: absolute;
  bottom: 8px;
  right: 12px;
  font-size: 11px;
  color: var(--text-muted);
}

/* ============================================================
   Style Selector
   ============================================================ */

.styles-section { margin-bottom: 24px; }

.styles-scroll {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.styles-scroll::-webkit-scrollbar { display: none; }

.style-chip {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  color: var(--text-dim);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

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

.style-chip.active {
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  border-color: var(--primary-light);
  color: var(--text);
  box-shadow: 0 4px 15px var(--primary-glow);
}

.style-chip .icon { font-size: 16px; }

/* ============================================================
   Reference Image Upload
   ============================================================ */

.ref-section { margin-bottom: 24px; }

.ref-hint {
  font-weight: 400;
  color: var(--text-muted);
  font-size: 10px;
  text-transform: none;
  letter-spacing: 0;
}

.ref-upload-btn {
  width: 100%;
  padding: 20px;
  background: var(--surface);
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  text-align: center;
  transition: all var(--transition);
  -webkit-tap-highlight-color: transparent;
}

.ref-upload-btn:hover, .ref-upload-btn.dragover {
  border-color: var(--primary);
  background: rgba(123, 47, 190, 0.05);
}

.ref-upload-btn.has-ref { display: none; }

.ref-upload-icon { font-size: 28px; margin-bottom: 6px; }

.ref-upload-text {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 2px;
}

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

.ref-preview {
  display: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.ref-preview.visible { display: block; }

.ref-preview img {
  width: 100%;
  max-height: 200px;
  object-fit: cover;
  display: block;
}

.ref-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
}

.ref-name {
  font-size: 13px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.ref-remove {
  background: none;
  border: none;
  color: var(--error);
  font-size: 22px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  font-family: inherit;
  transition: opacity var(--transition);
}

.ref-remove:hover { opacity: 0.7; }

/* ============================================================
   Size & Aspect Row
   ============================================================ */

.options-row {
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
}

.option-group { flex: 1; }

.option-group select {
  width: 100%;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%237878AA' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  transition: border-color var(--transition);
}

.option-group select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

/* ============================================================
   Generate Button
   ============================================================ */

.generate-btn {
  width: 100%;
  padding: 18px;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  border: none;
  border-radius: var(--radius);
  color: var(--text);
  font-size: 18px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  overflow: hidden;
}

.generate-btn::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, transparent, rgba(255,255,255,0.1));
  opacity: 0;
  transition: opacity var(--transition);
}

.generate-btn:hover::before { opacity: 1; }

.generate-btn:active { transform: scale(0.98); }

.generate-btn:disabled {
  background: var(--surface-light);
  cursor: not-allowed;
  transform: none;
}

.generate-btn .spinner {
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.status-text {
  text-align: center;
  font-size: 14px;
  color: var(--text-dim);
  margin-top: 12px;
  min-height: 20px;
  transition: opacity var(--transition);
}

/* ============================================================
   Result Image
   ============================================================ */

.result-section {
  margin-top: 28px;
  display: none;
  animation: fadeUp 0.4s ease-out;
}

.result-section.visible { display: block; }

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

.result-image-wrap {
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  position: relative;
}

.result-image-wrap img {
  width: 100%;
  display: block;
  background: var(--surface);
  min-height: 200px;
}

.result-actions {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}

.result-actions button {
  flex: 1;
  padding: 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all var(--transition);
  -webkit-tap-highlight-color: transparent;
}

.result-actions .save-btn {
  border-color: var(--success);
  color: var(--success);
  background: rgba(0, 230, 118, 0.08);
}

.result-actions .save-btn:hover { background: rgba(0, 230, 118, 0.15); }

.result-actions .regen-btn:hover { border-color: var(--primary); }

/* ============================================================
   History
   ============================================================ */

.history-section {
  margin-top: 36px;
  display: none;
}

.history-section.visible { display: block; }

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.history-header h3 {
  font-size: 16px;
  font-weight: 700;
}

.clear-btn {
  background: none;
  border: none;
  color: var(--error);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  padding: 4px 8px;
  font-family: inherit;
}

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

.history-item {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: transform var(--transition), border-color var(--transition);
}

.history-item:hover { transform: scale(1.03); border-color: var(--primary); }

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

.history-item .overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 6px;
  background: linear-gradient(transparent, rgba(0,0,0,0.8));
  font-size: 10px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ============================================================
   Toast
   ============================================================ */

.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--surface-light);
  color: var(--text);
  padding: 14px 24px;
  border-radius: var(--radius-xl);
  font-size: 14px;
  font-weight: 500;
  border: 1px solid var(--border);
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  z-index: 200;
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  pointer-events: none;
}

.toast.show { transform: translateX(-50%) translateY(0); }

/* ============================================================
   Install Banner
   ============================================================ */

.install-banner {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 16px 20px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 150;
  animation: fadeUp 0.3s ease-out;
}

.install-banner.visible { display: flex; align-items: center; gap: 12px; }

.install-banner p { flex: 1; font-size: 14px; color: var(--text-dim); }

.install-banner .install-btn {
  padding: 10px 20px;
  background: var(--primary);
  border: none;
  border-radius: var(--radius-sm);
  color: white;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  font-family: inherit;
}

.install-banner .dismiss-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
  padding: 4px;
}
