:root {
  --bg: #0b0f14;
  --bg2: #111822;
  --card: #151d29;
  --border: #223046;
  --text: #e6edf3;
  --muted: #8b98a9;
  --accent: #4f8cff;
  --accent2: #7c5cff;
  --ok: #3fb950;
  --warn: #d29922;
  --danger: #ff5c5c;
  --radius: 12px;
}

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

[hidden] { display: none !important; }

html { scroll-padding-bottom: 110px; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  padding-bottom: calc(96px + env(safe-area-inset-bottom, 0px));
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

button { font-family: inherit; cursor: pointer; }

a { color: var(--accent); }

/* ---------- topbar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 16px 10px;
  background: rgba(11, 15, 20, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 8px; }

.brand-logo { width: 26px; height: 26px; color: var(--accent); }

.brand h1 { font-size: 17px; font-weight: 700; letter-spacing: 0.2px; }

.brand h1 span { color: var(--muted); font-weight: 400; font-size: 15px; }

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

.icon-btn {
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
}

.icon-btn svg { width: 20px; height: 20px; }

.icon-btn:active { background: var(--bg2); }

.key-dot {
  position: absolute;
  top: 9px;
  right: 9px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ok);
}

/* ---------- tabs ---------- */
.tabs {
  position: sticky;
  top: calc(env(safe-area-inset-top, 0px) + 51px);
  z-index: 20;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 10px 16px;
  background: rgba(11, 15, 20, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar { display: none; }

.tab {
  flex: 0 0 auto;
  min-height: 36px;
  padding: 7px 16px;
  border-radius: 18px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--muted);
  font-size: 14px;
  white-space: nowrap;
  transition: all 0.15s;
}

.tab.is-on {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border-color: transparent;
  color: #fff;
  font-weight: 600;
}

/* ---------- layout ---------- */
.container {
  max-width: 640px;
  margin: 0 auto;
  padding: 14px 16px;
}

.gallery-section { padding-top: 6px; }

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.section-head h2 { font-size: 16px; font-weight: 600; }

.section-count { color: var(--muted); font-size: 13px; }

/* ---------- form ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}

.field { display: block; margin-bottom: 14px; }

.field-label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 7px;
  font-weight: 500;
}

.field-label b { color: var(--danger); }

.field-hint { display: block; font-size: 12px; color: var(--muted); margin-top: 6px; line-height: 1.5; }

textarea, input[type="text"], input[type="password"], input[type="number"], input[type="search"], select {
  width: 100%;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  padding: 11px 12px;
  font-size: 16px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}

textarea:focus, input:focus, select:focus { border-color: var(--accent); }

textarea { resize: vertical; min-height: 88px; line-height: 1.55; }

select { appearance: none; -webkit-appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 34px; }

.field-row { display: flex; gap: 10px; }

.field-row .field { flex: 1; min-width: 0; }

/* ---------- chips ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }

.chip {
  min-height: 36px;
  padding: 6px 13px;
  border-radius: 18px;
  border: 1px solid var(--border);
  background: var(--bg2);
  color: var(--muted);
  font-size: 13px;
  transition: all 0.15s;
}

.chip.is-on {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

/* ---------- upload zone ---------- */
.upload-zone {
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  padding: 12px;
  background: var(--bg2);
}

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

.thumb-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }

.thumb {
  position: relative;
  width: 68px;
  height: 68px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
}

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

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

.thumb-audio {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  font-size: 10px;
  color: var(--muted);
  line-height: 1.3;
  text-align: center;
  background: var(--bg2);
  overflow: hidden;
  word-break: break-all;
}

.thumb-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  font-size: 13px;
  line-height: 20px;
  text-align: center;
}

.thumb-uploading { position: absolute; inset: 0; background: rgba(0,0,0,.55); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 11px; }

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

input[type="range"] { flex: 1; accent-color: var(--accent); height: 32px; }

.range-val { min-width: 52px; text-align: right; font-size: 14px; color: var(--text); font-variant-numeric: tabular-nums; }

.field-seed { margin-top: 12px; }

/* ---------- switch ---------- */
.switch-row { display: flex; align-items: center; gap: 8px; font-size: 14px; min-height: 36px; }

.switch-row input { width: 18px; height: 18px; accent-color: var(--accent); }

/* ---------- buttons ---------- */
.btn-primary, .btn-ghost {
  min-height: 44px;
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  border: 1px solid transparent;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff;
}

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

.btn-ghost {
  background: var(--bg2);
  border-color: var(--border);
  color: var(--text);
}

.btn-ghost:active { background: var(--card); }

/* ---------- submit bar ---------- */
.submit-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  padding: 8px 16px calc(8px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(to top, var(--bg) 55%, rgba(11, 15, 20, 0) 100%);
  pointer-events: none;
}

.submit-bar .btn-primary {
  display: block;
  width: 100%;
  max-width: 608px;
  margin: 0 auto;
  min-height: 48px;
  pointer-events: auto;
  font-size: 16px;
}

/* ---------- progress ---------- */
.progress-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

.progress-track {
  height: 8px;
  border-radius: 4px;
  background: var(--bg2);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 40%;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  animation: slide 1.4s ease-in-out infinite;
}

@keyframes slide {
  0% { transform: translateX(-110%); }
  100% { transform: translateX(280%); }
}

.progress-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 10px;
  font-size: 13px;
}

.progress-text { color: var(--text); }

.progress-time { color: var(--muted); font-variant-numeric: tabular-nums; }

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

.result-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.result-media-wrap { position: relative; background: #000; aspect-ratio: 1 / 1; overflow: hidden; }

.wrap-video { aspect-ratio: 16 / 9; }

.result-media {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

video.result-media { background: #000; }

.result-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 12px 4px;
}

.result-model { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.result-time { font-size: 11px; color: var(--muted); flex: 0 0 auto; }

.result-actions { display: flex; gap: 6px; padding: 6px 12px 12px; }

.result-actions button {
  flex: 1;
  min-height: 38px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg2);
  color: var(--text);
  font-size: 13px;
}

.result-actions button:active { background: var(--card); }

.empty { text-align: center; color: var(--muted); font-size: 14px; padding: 32px 0; }

/* ---------- lightbox ---------- */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(0, 0, 0, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: env(safe-area-inset-top, 0px) 16px env(safe-area-inset-bottom, 0px);
}

.lightbox img { max-width: 100%; max-height: 92vh; border-radius: 6px; }

.lightbox-close {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 10px);
  right: 14px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.3);
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  font-size: 22px;
  line-height: 40px;
}

/* ---------- modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.modal-box {
  width: 100%;
  max-width: 480px;
  max-height: 86vh;
  overflow-y: auto;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 16px 16px 0 0;
  padding: 18px 16px calc(16px + env(safe-area-inset-bottom, 0px));
}

.modal-box h3 { font-size: 16px; margin-bottom: 8px; }

.modal-hint { font-size: 12px; color: var(--muted); line-height: 1.6; margin-bottom: 12px; }

.modal-box input[type="password"], .modal-box input[type="text"] { margin-bottom: 10px; }

.modal-actions { display: flex; gap: 8px; margin-top: 14px; }

.modal-actions .btn-primary, .modal-actions .btn-ghost { flex: 1; }

.modal-wide { max-width: 560px; }

/* ---------- history ---------- */
.history-list { display: flex; flex-direction: column; gap: 8px; }

.history-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
}

.history-item .hi-main { flex: 1; min-width: 0; }

.hi-title { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.hi-sub { font-size: 11px; color: var(--muted); margin-top: 2px; }

.hi-actions { display: flex; gap: 6px; flex: 0 0 auto; }

.hi-actions button {
  min-height: 32px;
  padding: 4px 10px;
  font-size: 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg2);
  color: var(--text);
}

.badge { display: inline-block; font-size: 11px; padding: 2px 8px; border-radius: 10px; }

.badge-running { background: rgba(210, 153, 34, 0.18); color: var(--warn); }

.badge-done { background: rgba(63, 185, 80, 0.16); color: var(--ok); }

.badge-failed { background: rgba(255, 92, 92, 0.15); color: var(--danger); }

.history-empty { text-align: center; color: var(--muted); font-size: 13px; padding: 20px 0; }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 70;
  max-width: min(92vw, 460px);
  background: #1c2430;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 13px;
  line-height: 1.5;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
  animation: toast-in 0.2s ease;
}

.toast-error { border-color: var(--danger); }

@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

@media (min-width: 760px) {
  .modal { align-items: center; }
  .modal-box { border-radius: 16px; }
  .gallery { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
}
