:root {
  --bg: #0a0a0c;
  --bg-elev: #14141a;
  --bg-elev-2: #1c1c24;
  --border: #2a2a36;
  --border-strong: #3a3a4a;
  --text: #f5f5f7;
  --text-muted: #9494a5;
  --text-dim: #6a6a80;
  --accent: #ffffff;
  --accent-fg: #0a0a0c;
  --danger: #ff5d5d;
  --success: #4ade80;
  --warning: #fbbf24;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --shadow: 0 1px 0 rgba(255,255,255,0.04) inset, 0 12px 32px rgba(0,0,0,0.4);
  --shadow-lg: 0 20px 50px rgba(0,0,0,0.6);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.hidden { display: none !important; }
.muted { color: var(--text-muted); }

/* ---------- Login ---------- */
.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(ellipse at top, #1a1a26 0%, #0a0a0c 50%);
}
.login-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 36px 32px;
  width: 100%;
  max-width: 360px;
  box-shadow: var(--shadow-lg);
}
.logo {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.subtitle {
  color: var(--text-muted);
  margin-bottom: 28px;
}
.login form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.error {
  color: var(--danger);
  font-size: 13px;
  margin-top: 12px;
}

/* ---------- Inputs ---------- */
input[type="text"],
input[type="password"] {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  width: 100%;
  transition: border-color 0.15s, background 0.15s;
}
input:focus {
  border-color: var(--border-strong);
  background: var(--bg-elev);
}
input::placeholder {
  color: var(--text-dim);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 500;
  border: 1px solid transparent;
  cursor: pointer;
  background: transparent;
  color: var(--text);
  transition: background 0.12s, border-color 0.12s, transform 0.05s;
  user-select: none;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary {
  background: var(--accent);
  color: var(--accent-fg);
}
.btn-primary:hover:not(:disabled) {
  background: #ffffff;
  filter: brightness(0.92);
}
.btn-ghost {
  background: transparent;
  border-color: var(--border);
}
.btn-ghost:hover:not(:disabled) {
  border-color: var(--border-strong);
  background: var(--bg-elev);
}
.btn-danger {
  color: var(--danger);
  border-color: transparent;
}
.btn-danger:hover:not(:disabled) {
  background: rgba(255, 93, 93, 0.1);
}

/* ---------- Top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  background: rgba(10, 10, 12, 0.85);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--border);
  padding: 12px 28px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 10;
}
.brand {
  font-size: 13.5px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.brand-mark {
  font-weight: 700;
  letter-spacing: -0.01em;
}
.brand-sep {
  color: var(--text-dim);
}
.brand-section { color: var(--text-muted); }
.brand-page { color: var(--text); font-weight: 500; }
.topbar-actions {
  display: flex;
  gap: 8px;
}

/* ---------- Main ---------- */
main {
  max-width: 1240px;
  margin: 0 auto;
  padding: 32px 28px 80px;
}
.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
  margin-bottom: 28px;
}
.page-head h1 {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0 0 6px;
}
.page-head p {
  margin: 0;
  max-width: 640px;
  font-size: 13.5px;
}

/* ---------- Character grid ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}
.char-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color 0.15s, transform 0.05s;
  cursor: pointer;
  display: flex;
  flex-direction: column;
}
.char-card:hover {
  border-color: var(--border-strong);
}
.char-card:active {
  transform: scale(0.995);
}
.char-thumb {
  aspect-ratio: 1 / 1;
  background: var(--bg-elev-2);
  background-size: cover;
  background-position: center;
  position: relative;
  display: grid;
  place-items: center;
}
.char-thumb-fallback {
  font-size: 64px;
  opacity: 0.3;
}
.char-thumb .status-badge {
  position: absolute;
  top: 10px;
  left: 10px;
  font-size: 11px;
  font-weight: 500;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  text-transform: capitalize;
}
.status-completed { color: var(--success); }
.status-failed { color: var(--danger); }
.status-queued, .status-in_progress { color: var(--warning); }
.status-not_ready { color: var(--text-muted); }
.char-meta {
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
.char-name {
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.char-date {
  font-size: 12px;
  color: var(--text-muted);
}
.char-actions {
  display: flex;
  gap: 4px;
}

/* ---------- Empty state ---------- */
.empty {
  text-align: center;
  padding: 80px 24px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-elev);
}
.empty-icon {
  font-size: 56px;
  margin-bottom: 16px;
  opacity: 0.5;
}
.empty h2 {
  margin: 0 0 8px;
  font-size: 20px;
}
.empty p {
  margin: 0 0 24px;
  color: var(--text-muted);
}

/* ---------- Modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 24px;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.modal-card {
  position: relative;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 640px;
  max-height: calc(100vh - 48px);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
}
.progress-card { max-width: 420px; }
.modal-head {
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.modal-head h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
}
.modal-close {
  padding: 6px 10px;
}
.modal-body {
  padding: 22px;
  overflow-y: auto;
}
.modal-foot {
  padding: 16px 22px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.form-row {
  margin-bottom: 22px;
}
.form-row:last-child { margin-bottom: 0; }
.form-row label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 6px;
}

/* ---------- Drop zone ---------- */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 28px 16px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  outline: none;
}
.drop-zone:hover, .drop-zone:focus {
  border-color: var(--border-strong);
  background: rgba(255,255,255,0.02);
}
.drop-zone.dragover {
  border-color: var(--text);
  background: rgba(255,255,255,0.05);
}
.drop-icon { font-size: 32px; margin-bottom: 8px; }
.drop-zone a { color: var(--text); text-decoration: underline; }

/* ---------- Photo grid ---------- */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}
.photo-tile {
  aspect-ratio: 1 / 1;
  border-radius: var(--radius-sm);
  background-size: cover;
  background-position: center;
  background-color: var(--bg-elev-2);
  position: relative;
  overflow: hidden;
}
.photo-tile.uploading::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.5);
}
.photo-tile.uploading::before {
  content: '';
  position: absolute;
  inset: 50% 50%;
  width: 22px;
  height: 22px;
  margin: -11px 0 0 -11px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  z-index: 1;
}
.photo-tile .remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(0,0,0,0.65);
  display: grid;
  place-items: center;
  cursor: pointer;
  color: #fff;
  font-size: 14px;
  border: none;
  opacity: 0;
  transition: opacity 0.15s;
}
.photo-tile:hover .remove { opacity: 1; }
.photo-tile .source-tag {
  position: absolute;
  bottom: 4px;
  left: 4px;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(0,0,0,0.6);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.photo-count {
  font-size: 12px;
  color: var(--text-muted);
}

/* ---------- Progress ---------- */
.progress-card .modal-body {
  text-align: center;
  padding: 32px 22px;
}
.progress-spinner {
  width: 44px;
  height: 44px;
  margin: 0 auto 18px;
  border: 3px solid var(--border);
  border-top-color: var(--text);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
.progress-status {
  font-size: 15px;
  font-weight: 500;
  margin-bottom: 6px;
}
.progress-detail {
  font-size: 13px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Toasts ---------- */
.toasts {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 200;
}
.toast {
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 12px 16px;
  min-width: 240px;
  max-width: 360px;
  font-size: 13px;
  box-shadow: var(--shadow-lg);
  animation: slide-in 0.2s ease-out;
}
.toast.error { border-left: 3px solid var(--danger); }
.toast.success { border-left: 3px solid var(--success); }
.toast.info { border-left: 3px solid var(--text-muted); }
@keyframes slide-in {
  from { transform: translateY(8px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  .topbar { padding: 12px 16px; }
  main { padding: 24px 16px 60px; }
  .page-head { flex-direction: column; align-items: stretch; }
  .page-head h1 { font-size: 24px; }
}
