/* ===== CSS Reset & Tokens ===== */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --color-primary: #7C3AED;
  --color-primary-hover: #6D28D9;
  --color-primary-glow: rgba(124, 58, 237, 0.25);
  --color-secondary: #6366F1;
  --color-accent: #EC4899;
  --color-bg: #0A0A0F;
  --color-bg-elevated: #12121A;
  --color-bg-card: #1A1A25;
  --color-bg-input: #1E1E2A;
  --color-border: #2A2A3A;
  --color-border-focus: #7C3AED;
  --color-text: #F1F1F6;
  --color-text-secondary: #9CA3AF;
  --color-text-muted: #6B7280;
  --color-success: #10B981;
  --color-error: #EF4444;
  --color-warning: #F59E0B;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.5);
  --shadow-glow: 0 0 20px var(--color-primary-glow);
  --transition: 200ms cubic-bezier(0.4, 0, 0.2, 1);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

html {
  font-family: var(--font);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--color-text-muted); }

/* ===== Layout ===== */
.app {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px 20px 48px;
  width: 100%;
}

/* ===== Header ===== */
.header {
  text-align: center;
  margin-bottom: 32px;
  padding: 40px 0 24px;
}

.header__badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(124, 58, 237, 0.12);
  color: var(--color-primary);
  font-size: 12px;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: 20px;
  border: 1px solid rgba(124, 58, 237, 0.2);
  margin-bottom: 16px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.header__title {
  font-size: clamp(28px, 5vw, 40px);
  font-weight: 700;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, var(--color-text) 0%, var(--color-primary) 50%, var(--color-accent) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 8px;
}

.header__subtitle {
  color: var(--color-text-secondary);
  font-size: 15px;
  font-weight: 400;
}

/* ===== Card ===== */
.card {
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 20px;
}

.card__label {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 12px;
}

/* ===== Form Elements ===== */
textarea, input[type="text"], input[type="password"], input[type="number"], select {
  width: 100%;
  background: var(--color-bg-input);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  color: var(--color-text);
  font-family: var(--font);
  font-size: 14px;
  padding: 12px 14px;
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}

textarea:focus, input:focus, select:focus {
  border-color: var(--color-border-focus);
  box-shadow: 0 0 0 3px var(--color-primary-glow);
}

textarea {
  resize: vertical;
  min-height: 120px;
  line-height: 1.6;
}

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

select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%239CA3AF' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10l-5 5z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
  cursor: pointer;
}

label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text-secondary);
  margin-bottom: 6px;
}

.form-group { margin-bottom: 16px; }
.form-group:last-child { margin-bottom: 0; }

.form-hint {
  display: block;
  font-size: 11px;
  color: var(--color-text-muted);
  margin-top: 4px;
}

/* ===== Grid ===== */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.grid-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 16px;
}

/* ===== Button ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 28px;
  font-family: var(--font);
  font-size: 15px;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
  min-height: 48px;
}

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

.btn--primary {
  background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-secondary) 100%);
  color: white;
  width: 100%;
  box-shadow: var(--shadow-glow);
}

.btn--primary:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 0 30px var(--color-primary-glow);
}

.btn--primary:active:not(:disabled) {
  transform: translateY(0);
}

.btn--ghost {
  background: transparent;
  color: var(--color-text-secondary);
  border: 1px solid var(--color-border);
  padding: 8px 14px;
  font-size: 13px;
  min-height: 36px;
}

.btn--ghost:hover:not(:disabled) {
  background: var(--color-bg-input);
  color: var(--color-text);
  border-color: var(--color-text-muted);
}

.btn--icon {
  padding: 8px;
  min-height: 36px;
  min-width: 36px;
}

/* ===== Spinner ===== */
.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

/* ===== Gallery ===== */
.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.gallery:empty {
  display: none;
}

.gallery__item {
  position: relative;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--color-border);
  background: var(--color-bg-elevated);
  aspect-ratio: 1;
  group: true;
}

.gallery__item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 300ms ease;
}

.gallery__item:hover img {
  transform: scale(1.03);
}

.gallery__overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(transparent 40%, rgba(0,0,0,0.8));
  opacity: 0;
  transition: opacity var(--transition);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 16px;
}

.gallery__item:hover .gallery__overlay {
  opacity: 1;
}

.gallery__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 10px;
}

.gallery__tag {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 4px;
  background: rgba(255,255,255,0.12);
  color: rgba(255,255,255,0.8);
  backdrop-filter: blur(4px);
  white-space: nowrap;
}

.gallery__tag--quality {
  background: rgba(124, 58, 237, 0.3);
  color: #c4b5fd;
}

.gallery__tag--format {
  background: rgba(16, 185, 129, 0.3);
  color: #6ee7b7;
}

.gallery__tag--size {
  background: rgba(99, 102, 241, 0.3);
  color: #a5b4fc;
}

.gallery__tag--transparent {
  background: rgba(236, 72, 153, 0.3);
  color: #f9a8d4;
}

.gallery__prompt {
  font-size: 11px;
  color: rgba(255,255,255,0.6);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 10px;
}

.gallery__actions {
  display: flex;
  gap: 8px;
  width: 100%;
}

.gallery__actions .btn {
  flex: 1;
}

/* ===== Empty State ===== */
.empty-state {
  text-align: center;
  padding: 64px 24px;
  color: var(--color-text-muted);
}

.empty-state__icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 16px;
  opacity: 0.3;
}

.empty-state__title {
  font-size: 16px;
  font-weight: 600;
  color: var(--color-text-secondary);
  margin-bottom: 6px;
}

.empty-state__desc {
  font-size: 14px;
}

/* ===== Status Bar ===== */
.status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 16px;
  opacity: 0;
  transform: translateY(-4px);
  transition: all 200ms ease;
  pointer-events: none;
}

.status.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.status--error {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.25);
  color: var(--color-error);
}

.status--success {
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(16, 185, 129, 0.25);
  color: var(--color-success);
}

/* ===== Settings Toggle ===== */
.settings-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  color: var(--color-text-secondary);
  font-size: 13px;
  font-weight: 500;
  padding: 8px 0;
  transition: color var(--transition);
  user-select: none;
  border: none;
  background: none;
  font-family: var(--font);
}

.settings-toggle:hover { color: var(--color-text); }

.settings-toggle svg {
  transition: transform var(--transition);
}

.settings-toggle.open svg {
  transform: rotate(90deg);
}

.settings-panel {
  max-height: 0;
  overflow: hidden;
  transition: max-height 300ms ease;
}

.settings-panel.open {
  max-height: 500px;
}

/* ===== Size Selector ===== */
.size-options {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.size-option {
  flex: 1;
  min-width: 80px;
}

.size-option input[type="radio"] {
  display: none;
}

.size-option label {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 12px;
  background: var(--color-bg-input);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
  text-align: center;
}

.size-option input:checked + label {
  border-color: var(--color-primary);
  background: rgba(124, 58, 237, 0.1);
  color: var(--color-primary);
  box-shadow: 0 0 0 2px var(--color-primary-glow);
}

.size-option label:hover {
  border-color: var(--color-text-muted);
}

.size-option label .size-label {
  font-size: 13px;
  font-weight: 600;
}

.size-option label .size-desc {
  font-size: 11px;
  color: var(--color-text-muted);
}

.size-option input:checked + label .size-desc {
  color: var(--color-primary);
  opacity: 0.7;
}

/* ===== Toggle Switch ===== */
.toggle-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.toggle-input {
  display: none;
}

.toggle-label {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
  margin-bottom: 0 !important;
}

.toggle-switch {
  position: relative;
  width: 40px;
  height: 22px;
  background: var(--color-border);
  border-radius: 11px;
  transition: background var(--transition);
  flex-shrink: 0;
}

.toggle-switch::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  background: white;
  border-radius: 50%;
  transition: transform var(--transition);
}

.toggle-input:checked + .toggle-label .toggle-switch {
  background: var(--color-primary);
}

.toggle-input:checked + .toggle-label .toggle-switch::after {
  transform: translateX(18px);
}

.toggle-text {
  font-size: 13px;
  color: var(--color-text-secondary);
}

.toggle-input:checked + .toggle-label .toggle-text {
  color: var(--color-primary);
}

.toggle-hint {
  font-size: 11px;
  color: var(--color-text-muted);
  padding-left: 50px;
}

/* ===== Slider ===== */
.slider-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.slider {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  background: var(--color-border);
  border-radius: 3px;
  outline: none;
  transition: background var(--transition);
}

.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  background: var(--color-primary);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 0 6px var(--color-primary-glow);
  transition: transform var(--transition);
}

.slider::-webkit-slider-thumb:hover {
  transform: scale(1.15);
}

.slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  background: var(--color-primary);
  border-radius: 50%;
  cursor: pointer;
  border: none;
  box-shadow: 0 0 6px var(--color-primary-glow);
}

.slider-label {
  font-size: 11px;
  color: var(--color-text-muted);
  white-space: nowrap;
}

/* ===== History ===== */
.history {
  margin-top: 24px;
}

.history__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.history__title {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text-secondary);
}

.history__count {
  font-size: 12px;
  color: var(--color-text-muted);
  background: var(--color-bg-input);
  padding: 2px 8px;
  border-radius: 10px;
}

/* ===== Loading Skeleton ===== */
.skeleton {
  background: linear-gradient(90deg, var(--color-bg-elevated) 25%, var(--color-bg-card) 50%, var(--color-bg-elevated) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-md);
  aspect-ratio: 1;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ===== Toast ===== */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-size: 13px;
  color: var(--color-text);
  box-shadow: var(--shadow-lg);
  animation: slideIn 200ms ease, fadeOut 200ms ease 2.8s forwards;
  max-width: 320px;
}

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

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

/* ===== Lightbox ===== */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(8px);
  z-index: 999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease;
  overflow: hidden;
}

.lightbox.open {
  opacity: 1;
  pointer-events: auto;
}

.lightbox img {
  max-width: 90vw;
  max-height: calc(100vh - 160px);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  object-fit: contain;
  flex-shrink: 1;
  min-height: 0;
}

.lightbox__close {
  position: absolute;
  top: 16px;
  right: 16px;
  background: rgba(255,255,255,0.1);
  border: none;
  color: white;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  transition: background var(--transition);
  z-index: 10;
}

.lightbox__close:hover { background: rgba(255,255,255,0.2); }

.lightbox__info {
  margin-top: 12px;
  text-align: center;
  max-width: 600px;
  flex-shrink: 0;
  max-height: 120px;
  overflow-y: auto;
}

.lightbox__info-text {
  font-size: 13px;
  color: rgba(255,255,255,0.7);
  line-height: 1.6;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.lightbox__info-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  margin-top: 8px;
}

.lightbox__info-tag {
  font-size: 11px;
  padding: 3px 10px;
  border-radius: 4px;
  background: rgba(255,255,255,0.1);
  color: rgba(255,255,255,0.7);
}

/* ===== Prompt Hint ===== */
.prompt-hint {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 6px;
}

.prompt-hint__text {
  font-size: 12px;
  color: var(--color-text-muted);
}

.prompt-hint__count {
  font-size: 12px;
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
}

/* ===== Responsive ===== */
@media (max-width: 640px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .gallery { grid-template-columns: 1fr; }
  .app { padding: 16px 14px 32px; }
  .card { padding: 18px; }
  .header { padding: 24px 0 16px; }
  .size-options { flex-wrap: wrap; }
  .size-option { min-width: calc(50% - 4px); }
}

/* ===== Reduced Motion ===== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
