:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface-raised: #22263a;
  --border: #2e3347;
  --border-light: #383d54;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --text: #e8eaf0;
  --text-muted: #8b91a8;
  --text-faint: #555c77;
  --error: #f87171;
  --radius: 10px;
  --radius-sm: 6px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

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

[hidden] { display: none !important; }

body {
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

/* ── Login ─────────────────────────────────────── */

.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 36px 32px 40px;
  box-shadow: 0 24px 64px rgba(0,0,0,0.5);
}

.login-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 15px;
  margin-bottom: 28px;
  color: var(--text);
}

.login-card h1 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 24px;
}

.login-error {
  font-size: 13px;
  color: var(--error);
  min-height: 20px;
  margin-bottom: 4px;
}

/* ── Header ─────────────────────────────────────── */

.site-header {
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.header-inner {
  max-width: 1300px;
  margin: 0 auto;
  padding: 16px 24px;
  display: flex;
  align-items: center;
  gap: 24px;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 15px;
  white-space: nowrap;
  flex-shrink: 0;
}

.brand-title {
  line-height: 1;
}

.version-badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 2px 7px;
  border: 1px solid var(--border-light);
  border-radius: 999px;
  color: var(--text-muted);
  background: var(--surface-raised);
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
}

.header-desc {
  font-size: 14px;
  color: var(--text-muted);
}

/* ── Layout ─────────────────────────────────────── */

.workspace {
  max-width: 1300px;
  margin: 0 auto;
  padding: 28px 24px 48px;
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 20px;
  align-items: start;
}

/* ── Panel ─────────────────────────────────────── */

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.controls {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* ── Sections ───────────────────────────────────── */

.section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.section-label {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.optional {
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text-faint);
}

/* ── Upload zone ────────────────────────────────── */

.upload-zone {
  display: block;
  border: 2px dashed var(--border-light);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  overflow: hidden;
  position: relative;
}

.upload-zone:hover,
.upload-zone:focus-visible {
  border-color: var(--accent);
  background: rgba(37,99,235,0.06);
  outline: none;
}

.upload-zone.drag-over {
  border-color: var(--accent);
  background: rgba(37,99,235,0.1);
}

.upload-input {
  position: absolute;
  inset: 0;
  opacity: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
}

.upload-idle {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 32px 20px;
  color: var(--text-muted);
  text-align: center;
}

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

.upload-secondary {
  font-size: 12px;
}

.upload-preview {
  position: relative;
}

.upload-preview img {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
}

.upload-change {
  position: absolute;
  bottom: 10px;
  right: 10px;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  background: rgba(0,0,0,0.7);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 4px;
  padding: 5px 10px;
  cursor: pointer;
  backdrop-filter: blur(4px);
}

.upload-change:hover {
  background: rgba(0,0,0,0.9);
}

/* ── Textarea ───────────────────────────────────── */

textarea,
.model-select {
  font: inherit;
  font-size: 14px;
  width: 100%;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 12px;
  resize: vertical;
  min-height: 110px;
  line-height: 1.5;
  transition: border-color 0.15s;
}

textarea::placeholder {
  color: var(--text-faint);
}

.model-field {
  margin-bottom: 0;
}

.model-select {
  min-height: 42px;
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-muted) 50%), linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 18px, calc(100% - 12px) 18px;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
}

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

.model-select:disabled {
  color: var(--text-muted);
  cursor: not-allowed;
}

.field-hint {
  font-size: 12px;
  color: var(--text-faint);
}

/* ── Submit button ──────────────────────────────── */

button[type="button"]#submit,
button[type="submit"] {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 44px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s;
}

button[type="button"]#submit:hover,
button[type="submit"]:hover {
  background: var(--accent-hover);
}

button[type="button"]#submit:disabled {
  background: var(--surface-raised);
  color: var(--text-muted);
  cursor: not-allowed;
}

/* Login submit shares the same look */
#login-submit {
  width: 100%;
  min-height: 44px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s;
  margin-top: 8px;
}

#login-submit:hover { background: var(--accent-hover); }
#login-submit:disabled { background: var(--surface-raised); color: var(--text-muted); cursor: not-allowed; }

/* ── Status ─────────────────────────────────────── */

.status {
  font-size: 13px;
  color: var(--text-muted);
  min-height: 18px;
}

.status.error {
  color: var(--error);
}

/* ── Fields (login) ─────────────────────────────── */

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 12px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.field input[type="password"] {
  font: inherit;
  font-size: 15px;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 10px 12px;
  width: 100%;
  transition: border-color 0.15s;
}

.field input[type="password"]:focus {
  outline: none;
  border-color: var(--accent);
}

/* ── Result panel ───────────────────────────────── */

.result {
  overflow: hidden;
}

.preview {
  aspect-ratio: 16 / 9;
  background: #0a0c12;
  display: grid;
  place-items: center;
  position: relative;
  min-height: 280px;
}

.preview-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  color: var(--text-faint);
  font-size: 14px;
  text-align: center;
  padding: 32px;
}

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

.preview-generating {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: rgba(10,12,18,0.8);
  color: var(--text-muted);
  font-size: 14px;
}

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

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

.result-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  border-top: 1px solid var(--border);
  gap: 16px;
}

.result-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.result-meta strong {
  font-size: 13px;
}

.result-meta span {
  font-size: 12px;
  color: var(--text-muted);
}

.btn-download {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 16px;
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  transition: background 0.15s;
  white-space: nowrap;
}

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

.btn-download.disabled {
  background: var(--surface-raised);
  color: var(--text-faint);
  cursor: not-allowed;
  pointer-events: none;
}

/* ── Responsive ─────────────────────────────────── */

@media (max-width: 900px) {
  .workspace {
    grid-template-columns: 1fr;
    padding: 20px 16px 40px;
  }

  .header-inner {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
  }
}
