:root {
  --bg-app: #09090b;
  --bg-surface: #18181b;
  --bg-surface-2: #111113;
  --bg-input: #27272a;
  --bg-input-hover: #3f3f46;

  --primary: #8b5cf6;
  --primary-color: #8b5cf6;
  --primary-hover: #a78bfa;
  --primary-glow: rgba(139, 92, 246, 0.4);

  --text-main: #f4f4f5;
  --text-muted: #a1a1aa;
  --text-soft: rgba(255, 255, 255, 0.78);

  --danger: #ef4444;
  --danger-bg: rgba(239, 68, 68, 0.15);

  --success: #10b981;
  --warning: #f59e0b;

  --border-app: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.14);

  --border-radius-lg: 20px;
  --border-radius-md: 14px;
  --border-radius-sm: 10px;

  --safe-bottom: env(safe-area-inset-bottom, 16px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg-app);
  color: var(--text-main);
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

body.no-scroll {
  overflow: hidden;
}

button,
input,
textarea,
select {
  font-family: inherit;
}

button {
  -webkit-appearance: none;
  appearance: none;
}

.hidden,
.hidden-field {
  display: none !important;
}

/* =========================
   Layout
========================= */

.app-layout {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  scroll-behavior: smooth;
}

.bottom-spacer {
  height: calc(75px + var(--safe-bottom));
  flex-shrink: 0;
}

/* =========================
   Header
========================= */

.app-header {
  position: sticky;
  top: 0;
  z-index: 50;

  display: flex;
  align-items: center;
  justify-content: space-between;

  padding: 12px 20px;

  background: rgba(9, 9, 11, 0.92);
  border-bottom: 1px solid var(--border-app);
  backdrop-filter: blur(10px);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo h1 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 800;
  letter-spacing: -0.3px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* =========================
   Desktop layout
========================= */

@media (min-width: 900px) {
  .app-main {
    flex-direction: row;
    align-items: stretch;
    gap: 20px;
    overflow: hidden;
    padding: 20px;
  }

  .controls-section {
    width: 420px;
    overflow-y: auto;
    background: var(--bg-surface);
    padding: 24px;
    border-radius: var(--border-radius-lg);
    border: 1px solid var(--border-app);
  }

  .result-section {
    flex: 1;
    display: flex !important;
    overflow: hidden;
    margin: 0 !important;
    border-radius: var(--border-radius-lg);
    background: #000;
  }

  .bottom-spacer {
    display: none;
  }

  .action-bar-wrapper {
    position: absolute;
    bottom: 20px;
    left: 20px;
    right: auto;
    width: 420px;
    z-index: 100;
  }
}

/* =========================
   Form
========================= */

.controls-section {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 20px;
}

#generation-form {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.label-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
}

label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

/* =========================
   Inputs / Buttons
========================= */

input[type="text"],
input[type="number"],
input[type="password"],
textarea,
select {
  width: 100%;
  padding: 14px 16px;

  background: var(--bg-input);
  border: 1px solid transparent;
  border-radius: var(--border-radius-md);

  color: var(--text-main);
  font-size: 1rem;
  line-height: 1.25;

  outline: none;
  appearance: none;

  transition:
    background 0.2s,
    border-color 0.2s,
    box-shadow 0.2s;
}

input::placeholder,
textarea::placeholder {
  color: rgba(161, 161, 170, 0.72);
}

input:focus,
textarea:focus,
select:focus {
  background: var(--bg-input-hover);
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

textarea {
  min-height: 96px;
  resize: vertical;
}

.icon-btn {
  display: grid;
  place-items: center;

  padding: 6px;
  border: none;
  border-radius: 50%;

  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  text-decoration: none;

  transition:
    background 0.2s,
    color 0.2s,
    transform 0.15s;
}

.icon-btn:hover {
  background: var(--bg-input);
  color: var(--text-main);
}

.icon-btn:active {
  transform: scale(0.96);
}

.text-btn {
  padding: 0;
  border: none;
  background: none;

  color: var(--primary);
  font-size: 0.85rem;
  font-weight: 600;

  cursor: pointer;
}

.text-btn.text-danger {
  color: var(--danger);
}

/* =========================
   Model selector
========================= */

.selector-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;

  width: 100%;
  padding: 12px 16px;

  background: var(--bg-input);
  border: 1px solid var(--border-app);
  border-radius: var(--border-radius-md);

  color: var(--text-main);
  text-align: left;
  cursor: pointer;
}

.selector-btn:active {
  background: var(--bg-input-hover);
}

.selector-btn-content {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.selector-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;

  font-size: 0.95rem;
  font-weight: 700;
}

.selector-subtitle {
  color: var(--text-muted);
  font-size: 0.75rem;
}

/* =========================
   Prompt
========================= */

.prompt-tools {
  display: flex;
  align-items: center;
  gap: 10px;
}

.textarea-wrapper {
  position: relative;
}

.textarea-wrapper textarea {
  padding-right: 54px;
}

.magic-btn {
  position: absolute;
  right: 8px;
  bottom: 8px;

  display: flex;
  align-items: center;
  justify-content: center;

  padding: 8px;
  border: 1px solid var(--border-app);
  border-radius: var(--border-radius-sm);

  background: var(--bg-surface);
  color: var(--primary);

  cursor: pointer;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);

  transition:
    background 0.2s,
    color 0.2s,
    opacity 0.2s;
}

.magic-btn:hover:not(:disabled) {
  background: var(--primary);
  color: #fff;
}

.magic-btn:disabled {
  opacity: 0.5;
  color: var(--text-muted);
  cursor: not-allowed;
  box-shadow: none;
}

/* =========================
   Select
========================= */

.select-wrapper {
  position: relative;
}

.select-wrapper select {
  padding-right: 42px;
}

.select-wrapper svg {
  position: absolute;
  right: 14px;
  top: 50%;

  transform: translateY(-50%);
  fill: var(--text-muted);

  pointer-events: none;
}

/* =========================
   References upload
========================= */

.limit-badge {
  display: inline-flex;
  align-items: center;

  min-height: 22px;
  padding: 2px 8px;

  border-radius: 999px;
  background: var(--bg-input);

  color: var(--text-muted);
  font-size: 0.7rem;
  font-weight: 700;
}

.refs-disabled-note {
  padding: 10px 12px;

  border: 1px solid rgba(245, 158, 11, 0.25);
  border-radius: var(--border-radius-sm);

  background: rgba(245, 158, 11, 0.09);
  color: #fde68a;

  font-size: 0.82rem;
  line-height: 1.4;
}

.upload-zone {
  position: relative;

  padding: 16px;
  border: 2px dashed var(--border-app);
  border-radius: var(--border-radius-md);

  cursor: pointer;

  transition:
    border-color 0.2s,
    background 0.2s,
    opacity 0.2s;
}

.upload-zone:hover,
.upload-zone.dragover {
  border-color: var(--primary);
  background: rgba(139, 92, 246, 0.05);
}

.upload-zone.disabled-zone {
  cursor: not-allowed;
  opacity: 0.68;
  border-color: rgba(245, 158, 11, 0.18);
}

.upload-zone.disabled-zone:hover {
  background: rgba(245, 158, 11, 0.04);
  border-color: rgba(245, 158, 11, 0.25);
}

.upload-prompt {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;

  color: var(--text-muted);
  text-align: center;
  font-size: 0.9rem;
}

.upload-prompt small {
  color: rgba(161, 161, 170, 0.72);
  font-size: 0.75rem;
}

.preview-list {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.preview-list::-webkit-scrollbar {
  height: 6px;
}

.preview-list::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: var(--bg-input-hover);
}

.preview-list.hidden {
  display: none !important;
}

.add-img-btn {
  flex: 0 0 80px;

  display: grid;
  place-items: center;

  width: 80px;
  height: 80px;

  border: 2px dashed var(--border-app);
  border-radius: var(--border-radius-sm);

  background: transparent;
  color: var(--text-muted);
  cursor: pointer;

  transition:
    background 0.2s,
    border-color 0.2s,
    color 0.2s;
}

.add-img-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: rgba(139, 92, 246, 0.06);
}

.preview-thumb {
  position: relative;
  flex: 0 0 80px;

  width: 80px;
  height: 80px;

  overflow: hidden;
  border: 1px solid var(--border-app);
  border-radius: var(--border-radius-sm);

  background: #000;
}

.preview-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.remove-img-btn {
  position: absolute;
  top: 4px;
  right: 4px;

  display: grid;
  place-items: center;

  width: 22px;
  height: 22px;

  border: none;
  border-radius: 50%;

  background: rgba(0, 0, 0, 0.64);
  color: #fff;

  font-size: 14px;
  line-height: 1;
  cursor: pointer;

  backdrop-filter: blur(4px);
}

.file-input-hidden {
  position: absolute !important;

  width: 1px !important;
  height: 1px !important;

  padding: 0 !important;
  margin: -1px !important;

  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;

  white-space: nowrap !important;
  border: 0 !important;
}

/* =========================
   Result
========================= */

.result-section {
  position: relative;

  display: flex;
  align-items: center;
  justify-content: center;

  min-height: 300px;
  margin: 20px 20px 0;

  overflow: hidden;
  border-radius: var(--border-radius-lg);

  background: var(--bg-surface);
}

@media (max-width: 899px) {
  .result-section.hidden {
    display: none !important;
    min-height: 0;
    margin: 0;
  }
}

.result-container {
  position: relative;

  display: flex;
  align-items: center;
  justify-content: center;

  width: 100%;
  height: 100%;
  min-height: inherit;

  background:
    radial-gradient(circle at center, rgba(255, 255, 255, 0.035), transparent 55%),
    #000;
}

#result-image {
  display: block;

  max-width: 100%;
  max-height: 70vh;

  object-fit: contain;
  cursor: zoom-in;

  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
}

.result-overlays {
  position: absolute;
  inset: 0;

  display: flex;
  flex-direction: column;
  justify-content: space-between;

  padding: 16px;

  pointer-events: none;
}

.result-badges {
  display: flex;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 8px;
}

.badge {
  padding: 4px 10px;

  border-radius: 999px;

  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.75rem;
  font-weight: 800;

  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

.glass-badge {
  border: 1px solid rgba(255, 255, 255, 0.1);

  background: rgba(0, 0, 0, 0.42);
  color: #fff;

  backdrop-filter: blur(8px);
}

.result-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;

  pointer-events: auto;
}

.glass-btn {
  display: grid;
  place-items: center;

  border: 1px solid rgba(255, 255, 255, 0.2);

  background: rgba(0, 0, 0, 0.42);
  color: #fff;

  text-decoration: none;
  cursor: pointer;

  backdrop-filter: blur(8px);

  transition:
    background 0.2s,
    border-color 0.2s,
    transform 0.2s;
}

.glass-btn:hover {
  background: var(--primary);
  border-color: var(--primary);
  transform: translateY(-2px);
}

.btn-round {
  width: 44px;
  height: 44px;
  border-radius: 50%;
}

/* =========================
   Action bar
========================= */

.action-bar-wrapper {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 100;

  padding: 10px 20px;
  padding-bottom: calc(10px + var(--safe-bottom));

  background: linear-gradient(0deg, var(--bg-app) 70%, transparent);

  pointer-events: none;
}

.action-bar {
  display: flex;
  align-items: center;
  gap: 10px;

  padding: 6px;

  border: 1px solid var(--border-app);
  border-radius: 999px;

  background: var(--bg-surface);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.6);

  pointer-events: auto;
}

.action-bar button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;

  height: 42px;
  padding: 0 16px;

  border: none;
  border-radius: 999px;

  font-size: 0.95rem;
  font-weight: 800;

  cursor: pointer;

  transition:
    background 0.2s,
    transform 0.15s,
    color 0.2s;
}

.primary-btn {
  flex: 1;

  background: var(--primary);
  color: #fff;

  box-shadow: 0 4px 15px var(--primary-glow);
}

.primary-btn:active {
  transform: scale(0.98);
  background: var(--primary-hover);
}

.primary-btn:disabled {
  background: var(--bg-input-hover);
  color: var(--text-muted);
  box-shadow: none;
  cursor: not-allowed;
}

.danger-btn {
  flex: 0 0 42px;
  padding: 0 !important;

  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid transparent;
}

.danger-btn:hover {
  background: var(--danger);
  color: #fff;
}

.secondary-btn {
  flex: 1;

  border: 1px solid var(--border-app);

  background: var(--bg-input);
  color: var(--text-main);
}

.secondary-btn:hover {
  border-color: var(--primary);
  background: rgba(139, 92, 246, 0.1);
}

/* =========================
   Spinner
========================= */

.spinner {
  width: 22px;
  height: 22px;

  border: 3px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;

  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* =========================
   Bottom sheet
========================= */

.bottom-sheet-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;

  display: flex;
  align-items: flex-end;
  justify-content: center;

  background: rgba(0, 0, 0, 0.62);
  backdrop-filter: blur(4px);

  opacity: 0;
  pointer-events: none;

  transition: opacity 0.25s;
}

.bottom-sheet-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.bottom-sheet {
  display: flex;
  flex-direction: column;

  width: 100%;
  max-width: 640px;
  max-height: 85vh;

  overflow: hidden;

  background: var(--bg-surface);
  border-radius: 24px 24px 0 0;

  transform: translateY(100%);

  transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
}

.bottom-sheet-overlay.open .bottom-sheet {
  transform: translateY(0);
}

@media (min-width: 900px) {
  .bottom-sheet-overlay {
    align-items: center;
  }

  .bottom-sheet {
    max-height: 82vh;
    border-radius: 20px;

    opacity: 0;
    transform: scale(0.95);
  }

  .bottom-sheet-overlay.open .bottom-sheet {
    opacity: 1;
    transform: scale(1);
  }
}

.sheet-header {
  position: relative;

  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;

  padding: 16px 20px;

  border-bottom: 1px solid var(--border-app);
}

.sheet-header h3 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 800;
}

.sheet-drag-handle {
  position: absolute;
  top: 8px;
  left: 50%;

  display: none;

  width: 40px;
  height: 4px;

  border-radius: 999px;
  background: var(--bg-input-hover);

  transform: translateX(-50%);
}

@media (max-width: 899px) {
  .sheet-drag-handle {
    display: block;
  }

  .sheet-header {
    padding-top: 24px;
  }
}

.model-search-wrap {
  padding: 14px 20px 0;
}

.model-search-wrap input {
  height: 42px;
  padding: 10px 14px;
  font-size: 0.95rem;
  border-radius: 999px;
}

.sheet-content {
  display: flex;
  flex-direction: column;
  gap: 12px;

  padding: 16px 20px calc(20px + var(--safe-bottom));

  overflow-y: auto;
}

/* =========================
   Model cards
========================= */

.model-card {
  display: flex;
  flex-direction: column;
  gap: 8px;

  width: 100%;
  padding: 16px;

  border: 2px solid transparent;
  border-radius: var(--border-radius-md);

  background: var(--bg-app);
  color: inherit;

  text-align: left;
  cursor: pointer;
  outline: none;

  transition:
    border-color 0.2s,
    background 0.2s,
    transform 0.15s;
}

.model-card:hover {
  transform: translateY(-1px);
  border-color: rgba(139, 92, 246, 0.28);
}

.model-card:focus-visible {
  border-color: var(--text-muted);
}

.model-card.selected {
  border-color: var(--primary);
  background: rgba(139, 92, 246, 0.08);
}

.model-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.model-title {
  color: var(--text-main);
  font-size: 1rem;
  font-weight: 800;
  line-height: 1.25;
}

.model-price {
  flex: 0 0 auto;

  color: var(--primary);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.85rem;
  font-weight: 800;
  white-space: nowrap;
}

.model-desc {
  display: -webkit-box;
  overflow: hidden;

  color: var(--text-muted);
  font-size: 0.85rem;
  line-height: 1.4;

  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
}

.model-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;

  margin-top: 3px;
}

.model-tag {
  padding: 4px 8px;

  border-radius: 999px;
  background: var(--bg-input-hover);

  color: var(--text-soft);
  font-size: 0.7rem;
  font-weight: 700;
}

.model-id {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;

  color: rgba(161, 161, 170, 0.62);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.7rem;
}

.model-empty {
  padding: 30px 16px;

  color: var(--text-muted);
  text-align: center;
  font-size: 0.9rem;
}

/* =========================
   History modal
========================= */

.history-modal {
  position: fixed;
  inset: 0;
  z-index: 2500;

  display: flex;
  align-items: center;
  justify-content: center;

  padding: 18px;

  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(6px);

  opacity: 0;
  pointer-events: none;

  transition: opacity 0.2s;
}

.history-modal.open {
  opacity: 1;
  pointer-events: auto;
}

.history-dialog {
  display: flex;
  flex-direction: column;

  width: 100%;
  max-width: 980px;
  max-height: min(86vh, 820px);

  overflow: hidden;

  border: 1px solid var(--border-app);
  border-radius: 22px;

  background: var(--bg-surface);
  box-shadow: 0 25px 90px rgba(0, 0, 0, 0.72);

  transform: translateY(10px) scale(0.98);

  transition: transform 0.2s;
}

.history-modal.open .history-dialog {
  transform: translateY(0) scale(1);
}

.history-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;

  padding: 16px 18px;

  border-bottom: 1px solid var(--border-app);
}

.history-header h3 {
  margin: 0;
  font-size: 1.08rem;
  font-weight: 800;
}

.history-header p {
  margin: 5px 0 0;

  color: var(--text-muted);
  font-size: 0.82rem;
  line-height: 1.35;
}

.history-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.history-clear-btn {
  height: 34px;
  padding: 0 12px;

  border: 1px solid rgba(239, 68, 68, 0.22);
  border-radius: 999px;

  background: rgba(239, 68, 68, 0.12);
  color: #fecaca;

  font-weight: 800;
  cursor: pointer;
}

.history-clear-btn:hover {
  background: rgba(239, 68, 68, 0.24);
}

.history-empty {
  padding: 36px 20px;

  color: var(--text-muted);
  text-align: center;
}

.history-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 14px;

  padding: 16px;

  overflow-y: auto;
}

.history-card {
  overflow: hidden;

  border: 1px solid var(--border-app);
  border-radius: 16px;

  background: var(--bg-surface-2);

  transition:
    transform 0.18s,
    border-color 0.18s;
}

.history-card:hover {
  transform: translateY(-2px);
  border-color: rgba(139, 92, 246, 0.35);
}

.history-thumb-btn {
  display: block;

  width: 100%;
  aspect-ratio: 1 / 1;
  padding: 0;

  overflow: hidden;

  border: none;
  background:
    linear-gradient(45deg, rgba(255,255,255,0.04) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(255,255,255,0.04) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(255,255,255,0.04) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(255,255,255,0.04) 75%),
    #000;
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;

  cursor: zoom-in;
}

.history-thumb-btn img {
  display: block;

  width: 100%;
  height: 100%;

  object-fit: contain;
}

.history-card-body {
  padding: 11px 12px 12px;
}

.history-card-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;

  margin-bottom: 8px;

  color: var(--text-muted);
  font-size: 0.72rem;
}

.history-card-prompt {
  display: -webkit-box;
  overflow: hidden;

  color: rgba(255, 255, 255, 0.9);
  font-size: 0.84rem;
  line-height: 1.35;

  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
}

.history-card-model {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;

  margin-top: 8px;

  color: rgba(167, 139, 250, 0.95);
  font-size: 0.72rem;
}

.history-format-badge {
  display: inline-flex;
  align-items: center;

  margin-top: 9px;
  padding: 3px 8px;

  border-radius: 999px;
  border: 1px solid rgba(139, 92, 246, 0.28);

  background: rgba(139, 92, 246, 0.12);
  color: rgba(255, 255, 255, 0.92);

  font-size: 0.7rem;
  font-weight: 800;
}

/* =========================
   Toasts
========================= */

#toast-container {
  position: fixed;
  top: 20px;
  left: 50%;
  z-index: 4000;

  display: flex;
  flex-direction: column;
  gap: 10px;

  width: 90%;
  max-width: 400px;

  transform: translateX(-50%);
}

.toast {
  padding: 14px 16px;

  border-left: 4px solid var(--primary);
  border-radius: 8px;

  background: var(--bg-surface);
  color: #fff;

  font-size: 0.9rem;
  line-height: 1.35;

  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);

  opacity: 0;
  transform: translateY(-20px) scale(0.95);

  transition: 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.toast.show {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.toast.error {
  border-color: var(--danger);
}

.toast.success {
  border-color: var(--success);
}

/* =========================
   Auth
========================= */

.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;

  min-height: 100vh;
  padding: 20px;

  background:
    radial-gradient(1200px 600px at 30% 0%, rgba(139, 92, 246, 0.18), transparent 60%),
    radial-gradient(900px 500px at 90% 20%, rgba(16, 185, 129, 0.10), transparent 60%),
    var(--bg-app);
}

.auth-card {
  width: 100%;
  max-width: 420px;
  padding: 18px;

  border: 1px solid var(--border-app);
  border-radius: 20px;

  background: var(--bg-surface);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.55);
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 12px;

  margin-bottom: 14px;
}

.auth-logo {
  display: grid;
  place-items: center;

  width: 42px;
  height: 42px;

  border: 1px solid rgba(139, 92, 246, 0.25);
  border-radius: 14px;

  background: rgba(139, 92, 246, 0.12);
}

.auth-title {
  font-size: 1.1rem;
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -0.4px;
}

.auth-subtitle {
  margin-top: 3px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.auth-alert {
  padding: 12px;
  margin: 12px 0 14px;

  border: 1px solid transparent;
  border-radius: 14px;

  font-size: 0.9rem;
}

.auth-alert.error {
  border-color: rgba(239, 68, 68, 0.25);
  background: rgba(239, 68, 68, 0.12);
  color: #fecaca;
}

.auth-alert.success {
  border-color: rgba(16, 185, 129, 0.22);
  background: rgba(16, 185, 129, 0.10);
  color: #bbf7d0;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.auth-field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.auth-submit {
  height: 44px;

  border: none;
  border-radius: 999px;

  background: var(--primary);
  color: #fff;

  font-weight: 800;
  cursor: pointer;

  box-shadow: 0 8px 20px rgba(139, 92, 246, 0.30);

  transition:
    transform 0.15s,
    background 0.2s;
}

.auth-submit:active {
  transform: scale(0.98);
  background: var(--primary-hover);
}

/* =========================
   Fancybox
========================= */

.fancybox__container {
  --fancybox-bg: rgba(0, 0, 0, 0.94);
  z-index: 7000 !important;
  touch-action: manipulation;
}

.fancybox__backdrop {
  background: rgba(0, 0, 0, 0.94) !important;
}

.fancybox__slide {
  padding: 12px !important;
}

.fancybox__content {
  touch-action: pan-x pan-y pinch-zoom;
}

.fancybox__image {
  max-width: 100%;
  max-height: 100%;

  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
}

.fancybox__caption {
  max-width: min(760px, calc(100vw - 32px));

  color: rgba(255, 255, 255, 0.86);
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 0.9rem;
  line-height: 1.4;
}

/* =========================
   Mobile
========================= */

@media (max-width: 899px) {
  .app-header {
    padding: 11px 16px;
  }

  .controls-section {
    padding: 18px;
  }

  .result-section {
    margin: 18px 18px 0;
  }

  #result-image {
    max-height: 62vh;
  }

  .history-modal {
    padding: 0;
  }

  .history-dialog {
    width: 100%;
    height: 100%;
    max-height: none;

    border-left: none;
    border-right: none;
    border-radius: 0;
  }

  .history-header {
    padding: 14px;
  }

  .history-header h3 {
    font-size: 1rem;
  }

  .history-header p {
    font-size: 0.76rem;
  }

  .history-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;

    padding: 12px;
    padding-bottom: calc(18px + var(--safe-bottom));
  }

  .history-card-body {
    padding: 9px;
  }

  .history-card-prompt {
    font-size: 0.78rem;
    -webkit-line-clamp: 3;
  }

  .history-clear-btn {
    height: 32px;
    padding: 0 10px;
    font-size: 0.8rem;
  }

  .fancybox__toolbar {
    --f-button-width: 42px;
    --f-button-height: 42px;
  }

  .fancybox__caption {
    max-height: 120px;
    overflow-y: auto;

    font-size: 0.82rem;
    line-height: 1.35;
  }

  .model-desc {
    -webkit-line-clamp: 5;
  }
}

/* =========================
   Prompt enhance modal
========================= */
.enhance-modal {
  position: fixed;
  inset: 0;
  z-index: 2600;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(0, 0, 0, 0.74);
  backdrop-filter: blur(6px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.enhance-modal.open {
  opacity: 1;
  pointer-events: auto;
}
.enhance-dialog {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 620px;
  max-height: min(88vh, 820px);
  overflow: hidden;
  border: 1px solid var(--border-app);
  border-radius: 22px;
  background: var(--bg-surface);
  box-shadow: 0 25px 90px rgba(0, 0, 0, 0.72);
  transform: translateY(10px) scale(0.98);
  transition: transform 0.2s;
}
.enhance-modal.open .enhance-dialog {
  transform: translateY(0) scale(1);
}
.enhance-modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border-app);
}
.enhance-modal-header h3 {
  margin: 0;
  font-size: 1.08rem;
  font-weight: 800;
}
.enhance-modal-header p {
  margin: 5px 0 0;
  color: var(--text-muted);
  font-size: 0.82rem;
  line-height: 1.4;
}
.enhance-modal-content {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 18px;
  overflow-y: auto;
}
.enhance-option-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--border-app);
  border-radius: 16px;
  background: var(--bg-surface-2);
}
.enhance-option-section h4 {
  margin: 0 0 2px;
  color: var(--text-main);
  font-size: 0.92rem;
  font-weight: 800;
}
.enhance-radio-row,
.enhance-check-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  color: var(--text-soft);
  font-size: 0.88rem;
  line-height: 1.35;
  cursor: pointer;
}
.enhance-radio-row input,
.enhance-check-row input {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  margin: 1px 0 0;
  accent-color: var(--primary);
  cursor: pointer;
}
.enhance-radio-row span,
.enhance-check-row span {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.enhance-radio-row strong,
.enhance-check-row strong {
  color: var(--text-main);
  font-weight: 700;
}
.enhance-radio-row small,
.enhance-check-row small {
  color: var(--text-muted);
  font-size: 0.78rem;
  line-height: 1.35;
}
.enhance-reference-main {
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-app);
}
.enhance-reference-options {
  display: flex;
  flex-direction: column;
  gap: 9px;
  padding-left: 6px;
}
.enhance-options-disabled {
  opacity: 0.42;
}
.enhance-modal-footer {
  display: flex;
  gap: 10px;
  padding: 14px 18px calc(14px + var(--safe-bottom));
  border-top: 1px solid var(--border-app);
}
.enhance-cancel-btn,
.enhance-confirm-btn {
  height: 42px;
  border: none;
  border-radius: 999px;
  padding: 0 16px;
  font-size: 0.9rem;
  font-weight: 800;
  cursor: pointer;
}
.enhance-cancel-btn {
  flex: 0 0 auto;
  border: 1px solid var(--border-app);
  background: var(--bg-input);
  color: var(--text-main);
}
.enhance-confirm-btn {
  flex: 1;
  background: var(--primary);
  color: #fff;
  box-shadow: 0 4px 15px var(--primary-glow);
}
.enhance-confirm-btn:active,
.enhance-cancel-btn:active {
  transform: scale(0.98);
}
@media (max-width: 899px) {
  .enhance-modal {
    align-items: flex-end;
    padding: 0;
  }
  .enhance-dialog {
    max-height: 92vh;
    border-right: none;
    border-bottom: none;
    border-left: none;
    border-radius: 22px 22px 0 0;
  }
  .enhance-modal-content {
    padding: 14px;
  }
  .enhance-option-section {
    padding: 12px;
  }
}