:root {
  --bg: #0f0f0f;
  --surface: #1a1a1a;
  --border: #2a2a2a;
  --text: #e0e0e0;
  --text-muted: #888;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --error: #ef4444;
  --success: #22c55e;
}

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

body {
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

#app {
  max-width: 900px;
  margin: 0 auto;
  padding: 20px;
}

.loading {
  text-align: center;
  color: var(--text-muted);
  padding: 60px 0;
}

#header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}

.logo {
  font-size: 1.25rem;
  font-weight: 700;
}

.user-info {
  display: flex;
  gap: 16px;
  align-items: center;
  font-size: 0.875rem;
}

.user-id {
  color: var(--text-muted);
  cursor: default;
}

.balance {
  color: var(--success);
  font-weight: 600;
}

.upload-zone {
  border: 2px dashed var(--border);
  border-radius: 12px;
  padding: 40px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  margin-bottom: 16px;
}

.upload-zone:hover,
.upload-zone.drag-over {
  border-color: var(--accent);
  background: rgba(99, 102, 241, 0.05);
}

.upload-placeholder svg {
  width: 48px;
  height: 48px;
  color: var(--text-muted);
  margin-bottom: 12px;
  display: inline-block;
}

.upload-placeholder p {
  color: var(--text-muted);
}

.upload-placeholder .hint {
  font-size: 0.8rem;
  margin-top: 4px;
  color: var(--text-muted);
}

.preview {
  max-width: 100%;
  max-height: 400px;
  border-radius: 8px;
  display: block;
  margin: 0 auto;
}

.editor-form {
  margin-bottom: 16px;
}

#prompt-input {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  resize: vertical;
  min-height: 80px;
  outline: none;
  transition: border-color 0.2s;
}

#prompt-input:focus {
  border-color: var(--accent);
}

.editor-controls {
  display: flex;
  gap: 12px;
  margin-top: 12px;
  align-items: center;
}

#model-select {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.9rem;
  flex: 1;
  cursor: pointer;
  outline: none;
  transition: border-color 0.2s;
}

#model-select:focus {
  border-color: var(--accent);
}

.btn {
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, opacity 0.2s;
  white-space: nowrap;
}

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

.btn-accent {
  background: var(--accent);
  color: #fff;
}

.btn-accent:hover:not(:disabled) {
  background: var(--accent-hover);
}

.result {
  margin-top: 16px;
}

.result-image {
  max-width: 100%;
  max-height: 500px;
  border-radius: 8px;
  display: block;
  margin: 0 auto;
}

#result-info {
  text-align: center;
  color: var(--text-muted);
  margin-top: 8px;
  font-size: 0.875rem;
}

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

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

.error-msg {
  color: var(--error);
  font-size: 0.875rem;
  margin-top: 8px;
}

.hidden {
  display: none !important;
}

.recovery-overlay {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 60vh;
}

.recovery-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  max-width: 420px;
  width: 100%;
}

.recovery-card h2 {
  margin-bottom: 12px;
  font-size: 1.25rem;
}

.recovery-hint {
  color: var(--text-muted);
  font-size: 0.875rem;
  margin-bottom: 20px;
  line-height: 1.5;
}

.form-label {
  display: block;
  margin-bottom: 16px;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.form-label input {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  font-family: monospace;
  outline: none;
  transition: border-color 0.2s;
}

.form-label input:focus {
  border-color: var(--accent);
}

#history {
  margin-top: 32px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}

#history h2 {
  font-size: 1rem;
  margin-bottom: 12px;
  color: var(--text-muted);
}

@media (max-width: 600px) {
  #app {
    padding: 12px;
  }

  #header {
    flex-direction: column;
    gap: 8px;
    align-items: flex-start;
  }

  .editor-controls {
    flex-direction: column;
  }

  #model-select {
    width: 100%;
  }

  .btn {
    width: 100%;
  }

  .recovery-card {
    padding: 24px;
  }
}
