/* ===== RESET & BASE ===== */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #0a0a0f;
  --surface: rgba(255, 255, 255, 0.04);
  --surface-hover: rgba(255, 255, 255, 0.07);
  --surface-active: rgba(255, 255, 255, 0.1);
  --border: rgba(255, 255, 255, 0.08);
  --border-hover: rgba(255, 255, 255, 0.15);
  --text: #e8e8ed;
  --text-muted: #7a7a8a;
  --text-dim: #505060;
  --accent: #a78bfa;
  --accent-glow: rgba(167, 139, 250, 0.25);
  --accent-2: #818cf8;
  --gradient-1: #a78bfa;
  --gradient-2: #818cf8;
  --gradient-3: #6366f1;
  --danger: #ef4444;
  --success: #22c55e;
  --radius: 16px;
  --radius-sm: 10px;
  --radius-xs: 8px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  overflow-x: hidden;
  position: relative;
}

/* ===== ANIMATED BACKGROUND ===== */
.bg-blobs {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
}

.blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(120px);
  opacity: 0.3;
  animation: blobFloat 20s ease-in-out infinite;
}

.blob-1 {
  width: 500px;
  height: 500px;
  background: radial-gradient(circle, #a78bfa 0%, transparent 70%);
  top: -10%;
  left: -5%;
  animation-delay: 0s;
}

.blob-2 {
  width: 400px;
  height: 400px;
  background: radial-gradient(circle, #6366f1 0%, transparent 70%);
  bottom: -10%;
  right: -5%;
  animation-delay: -7s;
}

.blob-3 {
  width: 350px;
  height: 350px;
  background: radial-gradient(circle, #4f46e5 0%, transparent 70%);
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  animation-delay: -14s;
}

@keyframes blobFloat {
  0%, 100% { transform: translate(0, 0) scale(1); }
  25% { transform: translate(30px, -40px) scale(1.1); }
  50% { transform: translate(-20px, 20px) scale(0.95); }
  75% { transform: translate(40px, 30px) scale(1.05); }
}

/* ===== LAYOUT ===== */
#app {
  position: relative;
  z-index: 1;
  max-width: 640px;
  margin: 0 auto;
  padding: 40px 20px 80px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ===== HEADER ===== */
.header {
  text-align: center;
  padding-bottom: 4px;
}

.logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 8px;
}

.logo-emoji {
  font-size: 2.2rem;
  animation: wiggle 3s ease-in-out infinite;
}

@keyframes wiggle {
  0%, 100% { transform: rotate(0deg); }
  25% { transform: rotate(10deg); }
  75% { transform: rotate(-10deg); }
}

.logo h1 {
  font-size: 1.8rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  background: linear-gradient(135deg, var(--gradient-1), var(--gradient-2), var(--gradient-3));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.logo .accent {
  -webkit-text-fill-color: var(--text);
  font-weight: 600;
  opacity: 0.6;
}

.subtitle {
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 400;
}

/* ===== CARD ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  box-shadow: var(--shadow);
  transition: border-color var(--transition);
}

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

#model-card {
  position: relative;
  z-index: 10;
}

/* ===== SECTION LABEL ===== */
.section-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
}

/* ===== FEATURED MODELS ===== */
.featured-section {
  gap: 14px;
}

.category-pills {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.category-pills::-webkit-scrollbar {
  display: none;
}

.pill {
  flex-shrink: 0;
  padding: 6px 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

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

.pill.active {
  border-color: var(--accent);
  background: rgba(167, 139, 250, 0.12);
  color: var(--accent);
}

.model-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 10px;
}

.model-grid:empty::after {
  content: "";
  display: none;
}

.model-card {
  position: relative;
  border-radius: var(--radius-xs);
  overflow: hidden;
  cursor: pointer;
  transition: all var(--transition);
  border: 1px solid var(--border);
  background: var(--surface);
  aspect-ratio: 1;
}

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

.model-card-cover {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  background: #000;
}

.model-card-fallback {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.5rem;
  background: linear-gradient(135deg, rgba(167, 139, 250, 0.1), rgba(99, 102, 241, 0.1));
}

.model-card-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.85) 0%, rgba(0, 0, 0, 0.3) 50%, transparent 100%);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 10px;
}

.model-card-name {
  font-size: 0.72rem;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: "SFMono-Regular", "Cascadia Mono", monospace;
}

.model-card-runs {
  font-size: 0.65rem;
  color: rgba(255, 255, 255, 0.6);
  margin-top: 2px;
}

.model-grid-loading {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 20px;
  color: var(--text-dim);
  font-size: 0.85rem;
}

/* ===== MODEL SEARCH ===== */
.search-group {
  position: relative;
  z-index: 999;
}

.search-input {
  width: 100%;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  padding: 12px 16px;
  transition: border-color var(--transition), box-shadow var(--transition);
}

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

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

/* Search Results Dropdown */
.search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: rgba(18, 18, 28, 0.98);
  border: 1px solid var(--border-hover);
  border-radius: var(--radius-sm);
  max-height: 340px;
  overflow-y: auto;
  z-index: 50;
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.6);
  animation: dropdownIn 0.2s ease-out;
}

.search-results[hidden] {
  display: none;
}

@keyframes dropdownIn {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

.search-result-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  transition: background var(--transition);
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.search-result-item:last-child {
  border-bottom: none;
}

.search-result-item:hover {
  background: var(--surface-hover);
}

.search-result-avatar {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--surface-active);
  flex-shrink: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.search-result-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.search-result-info {
  flex: 1;
  min-width: 0;
}

.search-result-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-result-desc {
  font-size: 0.75rem;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.search-result-runs {
  font-size: 0.7rem;
  color: var(--text-dim);
  white-space: nowrap;
  flex-shrink: 0;
}

.search-loading, .search-empty {
  padding: 20px;
  text-align: center;
  color: var(--text-dim);
  font-size: 0.85rem;
}

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

/* ===== SELECTED MODEL ===== */
.selected-model {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: rgba(167, 139, 250, 0.06);
  border: 1px solid rgba(167, 139, 250, 0.15);
  border-radius: var(--radius-xs);
  transition: all var(--transition);
}

.model-avatar {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--surface-active);
  flex-shrink: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
}

.model-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.model-info {
  flex: 1;
  min-width: 0;
}

.model-name {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  font-family: "SFMono-Regular", "Cascadia Mono", monospace;
}

.model-desc {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-change {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  flex-shrink: 0;
}

.btn-change:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(167, 139, 250, 0.08);
}

/* ===== UPLOAD ZONE ===== */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 32px 20px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
  min-height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.upload-zone:hover,
.upload-zone.dragover {
  border-color: var(--accent);
  background: rgba(167, 139, 250, 0.04);
}

.upload-zone.dragover {
  transform: scale(1.01);
}

.upload-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.upload-icon {
  color: var(--text-dim);
  transition: color var(--transition), transform var(--transition);
}

.upload-zone:hover .upload-icon {
  color: var(--accent);
  transform: translateY(-2px);
}

.upload-text {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.upload-link {
  color: var(--accent);
  font-weight: 500;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.upload-hint {
  color: var(--text-dim);
  font-size: 0.75rem;
}

/* Preview */
.preview-container {
  position: relative;
  width: 100%;
  max-height: 300px;
  overflow: hidden;
  border-radius: var(--radius-xs);
}

.preview-container img {
  width: 100%;
  max-height: 300px;
  object-fit: contain;
  border-radius: var(--radius-xs);
}

.remove-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.7);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  backdrop-filter: blur(8px);
}

.remove-btn:hover {
  background: var(--danger);
  transform: scale(1.1);
}

/* ===== SCHEMA FILE UPLOADS ===== */
.schema-uploads {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.schema-upload-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.schema-upload-hint {
  font-size: 0.7rem;
  color: var(--text-dim);
  margin: 0;
  line-height: 1.4;
}

.schema-upload-zone {
  border: 1.5px dashed var(--border);
  border-radius: var(--radius-xs);
  padding: 14px 16px;
  cursor: pointer;
  transition: all var(--transition);
}

.schema-upload-zone:hover,
.schema-upload-zone.dragover {
  border-color: var(--accent);
  background: rgba(167, 139, 250, 0.04);
}

.schema-upload-empty {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.schema-upload-preview[hidden] {
  display: none;
}

.schema-file-info {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text);
}

.schema-file-name {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}

.schema-file-size {
  color: var(--text-dim);
  font-size: 0.75rem;
  flex-shrink: 0;
}

.schema-file-remove {
  margin-left: auto;
  background: none;
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 0.75rem;
  transition: all var(--transition);
  flex-shrink: 0;
}

.schema-file-remove:hover {
  border-color: var(--danger);
  color: var(--danger);
  background: rgba(239, 68, 68, 0.1);
}

.upload-zone[hidden] {
  display: none;
}

/* ===== PROMPT ===== */
.prompt-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.label {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.label-sm {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 4px;
}

.prompt-input {
  width: 100%;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
  padding: 14px 16px;
  resize: vertical;
  min-height: 80px;
  transition: border-color var(--transition), box-shadow var(--transition);
  line-height: 1.5;
}

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

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

/* ===== DYNAMIC SETTINGS ===== */
.dynamic-settings {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
}

.dynamic-settings:empty {
  display: none;
}

.setting {
  display: flex;
  flex-direction: column;
}

.select,
.input-field {
  appearance: none;
  -webkit-appearance: none;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  color: var(--text);
  font-family: inherit;
  font-size: 0.85rem;
  padding: 10px 12px;
  cursor: pointer;
  transition: border-color var(--transition);
}

.select {
  padding-right: 32px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%237a7a8a' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}

.input-field {
  cursor: text;
}

.select:focus,
.input-field:focus {
  outline: none;
  border-color: var(--accent);
}

.select option {
  background: #1a1a2e;
  color: var(--text);
}

/* ===== GENERATE BUTTON ===== */
.btn-generate {
  width: 100%;
  padding: 16px;
  border: none;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--gradient-1), var(--gradient-2));
  color: #fff;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
}

.btn-generate::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, transparent, rgba(255, 255, 255, 0.2), transparent);
  transform: translateX(-100%);
  transition: transform 0.6s ease;
}

.btn-generate:hover::before {
  transform: translateX(100%);
}

.btn-generate:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 24px var(--accent-glow);
}

.btn-generate:active {
  transform: translateY(0);
}

.btn-generate:disabled {
  opacity: 0.7;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn-generate:disabled::before {
  display: none;
}

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

.btn-text[hidden],
.btn-loading[hidden] {
  display: none;
}

/* ===== SPINNER ===== */
.spinner {
  width: 20px;
  height: 20px;
  border: 2.5px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.spinner-sm {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ===== RESULT CARD ===== */
.result-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  box-shadow: var(--shadow);
  animation: slideUp 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

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

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

.result-header h2 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}

.result-actions {
  display: flex;
  gap: 8px;
}

.btn-download {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-download:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(167, 139, 250, 0.06);
}

.result-image-wrap {
  padding: 16px;
}

.result-image-wrap img {
  width: 100%;
  border-radius: var(--radius-xs);
  display: block;
}

.result-image-wrap[hidden] {
  display: none;
}

/* Video Result */
.result-video-wrap {
  padding: 16px;
}

.result-video-wrap[hidden] {
  display: none;
}

.result-video-wrap video {
  width: 100%;
  border-radius: var(--radius-xs);
  display: block;
  max-height: 500px;
  background: #000;
}

/* Audio Result */
.result-audio-wrap {
  padding: 20px 16px;
}

.result-audio-wrap[hidden] {
  display: none;
}

.result-audio-wrap audio {
  width: 100%;
  border-radius: var(--radius-xs);
}

/* Text Result */
.result-text-wrap {
  padding: 16px;
}

.result-text-wrap[hidden] {
  display: none;
}

.result-text-wrap pre {
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  padding: 20px;
  color: var(--text);
  font-family: "SFMono-Regular", "Cascadia Mono", "Fira Code", monospace;
  font-size: 0.85rem;
  line-height: 1.7;
  white-space: pre-wrap;
  word-wrap: break-word;
  max-height: 500px;
  overflow-y: auto;
}

/* ===== TOAST ===== */
.toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.3);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  color: #fca5a5;
  padding: 14px 24px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 100;
  animation: toastIn 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  max-width: 90vw;
}

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

.toast[hidden] {
  display: none;
}

/* ===== SCROLLBAR ===== */
.search-results::-webkit-scrollbar {
  width: 6px;
}

.search-results::-webkit-scrollbar-track {
  background: transparent;
}

.search-results::-webkit-scrollbar-thumb {
  background: var(--border-hover);
  border-radius: 3px;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 480px) {
  #app {
    padding: 24px 16px 60px;
  }

  .card {
    padding: 18px;
  }

  .logo h1 {
    font-size: 1.4rem;
  }

  .logo-emoji {
    font-size: 1.8rem;
  }

  .dynamic-settings {
    grid-template-columns: 1fr;
  }

  .upload-zone {
    padding: 24px 16px;
  }

  .model-name {
    font-size: 0.8rem;
  }
}
