:root {
  --bg: #070a14;
  --bg-soft: #0d1222;
  --card: rgba(19, 25, 44, 0.72);
  --card-solid: #131929;
  --stroke: rgba(255, 255, 255, 0.09);
  --stroke-strong: rgba(255, 255, 255, 0.16);
  --text: #e8ecf8;
  --muted: #98a2bd;
  --dim: #6a7592;
  --brand: #7c5cff;
  --brand-2: #ff6ec7;
  --brand-3: #ffb86b;
  --grad: linear-gradient(120deg, #7c5cff, #ff6ec7 55%, #ffb86b);
  --ok: #35d39a;
  --bad: #ff6b7a;
  --radius: 16px;
  --shadow: 0 24px 60px -24px rgba(0, 0, 0, 0.7);
  color-scheme: dark;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* 背景光晕 */
.bg-glow { position: fixed; inset: 0; z-index: -1; overflow: hidden; }
.bg-glow span {
  position: absolute;
  border-radius: 50%;
  filter: blur(90px);
  opacity: 0.32;
  animation: drift 24s ease-in-out infinite alternate;
}
.bg-glow span:nth-child(1) { width: 520px; height: 520px; left: -120px; top: -120px; background: #6d4aff; }
.bg-glow span:nth-child(2) { width: 460px; height: 460px; right: -100px; top: 12%; background: #ff5fa8; animation-delay: -6s; }
.bg-glow span:nth-child(3) { width: 400px; height: 400px; left: 30%; bottom: -180px; background: #2bb673; animation-delay: -12s; }

@keyframes drift {
  from { transform: translate3d(0, 0, 0) scale(1); }
  to { transform: translate3d(40px, -30px, 0) scale(1.15); }
}

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  max-width: 1560px;
  margin: 0 auto;
  padding: 0 20px;
}

/* 顶栏 */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 4px 14px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  font-size: 21px;
  border-radius: 12px;
  background: var(--grad);
  box-shadow: 0 8px 24px -8px rgba(124, 92, 255, 0.8);
}
.brand strong { display: block; font-size: 18px; letter-spacing: 0.4px; }
.model-badge {
  display: inline-block;
  margin-top: 2px;
  font-size: 11.5px;
  font-style: normal;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--stroke);
  padding: 2px 8px;
  border-radius: 999px;
}
.top-actions { display: flex; gap: 8px; }

/* 布局 */
.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 400px 1fr;
  gap: 20px;
  align-items: start;
  position: relative;
}

.panel, .stage {
  background: var(--card);
  backdrop-filter: blur(18px);
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.panel {
  padding: 18px;
  position: sticky;
  top: 16px;
  max-height: calc(100vh - 100px);
  overflow: auto;
}

.panel::-webkit-scrollbar, .stage::-webkit-scrollbar, .results::-webkit-scrollbar,
.drawer::-webkit-scrollbar { width: 8px; height: 8px; }
.panel::-webkit-scrollbar-thumb, .stage::-webkit-scrollbar-thumb,
.results::-webkit-scrollbar-thumb, .drawer::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.14);
  border-radius: 8px;
}

/* Tabs */
.tabs {
  display: flex;
  gap: 6px;
  padding: 4px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--stroke);
  border-radius: 12px;
  margin-bottom: 16px;
}
.tab {
  flex: 1;
  padding: 9px 10px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  border-radius: 9px;
  cursor: pointer;
  transition: 0.18s;
}
.tab:hover { color: var(--text); }
.tab.active {
  color: #fff;
  background: var(--grad);
  box-shadow: 0 6px 18px -8px rgba(255, 110, 199, 0.9);
}

/* 表单 */
.field { display: block; margin-bottom: 14px; }
.label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12.5px;
  color: var(--muted);
  margin-bottom: 6px;
  font-weight: 600;
  letter-spacing: 0.2px;
}
.counter { font-style: normal; color: var(--dim); font-size: 11.5px; }

textarea, input[type="text"], input[type="password"], select {
  width: 100%;
  padding: 11px 12px;
  background: rgba(8, 11, 22, 0.62);
  border: 1px solid var(--stroke);
  border-radius: 10px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  transition: 0.18s;
  outline: none;
}
textarea { resize: vertical; min-height: 120px; line-height: 1.55; }
select { appearance: none; cursor: pointer; padding-right: 34px; }
textarea:focus, input:focus, select:focus {
  border-color: rgba(124, 92, 255, 0.75);
  box-shadow: 0 0 0 3px rgba(124, 92, 255, 0.16);
}
textarea::placeholder, input::placeholder { color: #5c6784; }

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

/* 下拉框箭头 */
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2398a2bd' d='M6 8.5 2 4.5h8z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}

/* 拖拽上传 */
.dropzone {
  position: relative;
  border: 1.5px dashed var(--stroke-strong);
  border-radius: 12px;
  min-height: 130px;
  display: grid;
  place-items: center;
  padding: 12px;
  cursor: pointer;
  transition: 0.18s;
  background: rgba(8, 11, 22, 0.4);
  overflow: hidden;
}
.dropzone:hover, .dropzone.over {
  border-color: var(--brand);
  background: rgba(124, 92, 255, 0.1);
}
#dropHint { color: var(--muted); font-size: 13px; text-align: center; pointer-events: none; }
#preview {
  max-width: 100%;
  max-height: 220px;
  border-radius: 8px;
  display: block;
}
.clear-btn { position: absolute; right: 8px; top: 8px; }

/* 预设 chips */
.presets { display: flex; flex-wrap: wrap; gap: 7px; margin: 4px 0 16px; }
.chip {
  padding: 6px 11px;
  font-size: 12.5px;
  border-radius: 999px;
  border: 1px solid var(--stroke);
  background: rgba(255, 255, 255, 0.05);
  color: var(--muted);
  cursor: pointer;
  transition: 0.16s;
  white-space: nowrap;
}
.chip:hover { color: #fff; border-color: var(--brand); background: rgba(124, 92, 255, 0.16); }
.chip.danger:hover, .ghost.danger:hover { color: #fff; border-color: var(--bad); background: rgba(255, 107, 122, 0.16); }

/* 按钮 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--stroke);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 10px 16px;
  border-radius: 11px;
  cursor: pointer;
  transition: 0.18s;
  text-decoration: none;
}
.btn:hover { border-color: var(--stroke-strong); background: rgba(255, 255, 255, 0.11); }
.btn.primary {
  border: 0;
  color: #fff;
  background: var(--grad);
  box-shadow: 0 14px 34px -14px rgba(255, 110, 199, 0.85);
}
.btn.primary:hover { filter: brightness(1.07); transform: translateY(-1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; filter: none; }
.btn.big { width: 100%; padding: 14px; font-size: 15.5px; }
.btn.small { padding: 7px 12px; font-size: 13px; }
.btn-icon { font-size: 16px; }

.ghost {
  background: transparent;
  border: 1px solid var(--stroke);
  color: var(--muted);
  padding: 7px 13px;
  border-radius: 10px;
  font-size: 13px;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: 0.16s;
}
.ghost:hover { color: var(--text); border-color: var(--stroke-strong); }

.hint { color: var(--dim); font-size: 12px; text-align: center; margin: 10px 0 0; }

/* 舞台 */
.stage {
  min-height: 60vh;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.status-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: 12px;
  background: rgba(124, 92, 255, 0.12);
  border: 1px solid rgba(124, 92, 255, 0.35);
  font-size: 13.5px;
  color: #d9d2ff;
}
.spinner {
  width: 18px; height: 18px;
  border: 2.5px solid rgba(255, 255, 255, 0.25);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.85s linear infinite;
  flex: none;
}
@keyframes spin { to { transform: rotate(360deg); } }
.elapsed { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; }

.error-bar {
  padding: 12px 15px;
  border-radius: 12px;
  background: rgba(255, 107, 122, 0.12);
  border: 1px solid rgba(255, 107, 122, 0.4);
  color: #ffd7dd;
  font-size: 13.5px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.empty {
  flex: 1;
  display: grid;
  place-content: center;
  text-align: center;
  gap: 8px;
  color: var(--muted);
  padding: 40px 20px;
}
.empty h2 { color: var(--text); margin: 14px 0 0; font-size: 19px; }
.empty p { margin: 0; font-size: 13.5px; max-width: 380px; }
.empty-art { opacity: 0.55; animation: float 6s ease-in-out infinite; }
@keyframes float { 50% { transform: translateY(-10px); } }

.results { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }

.card {
  position: relative;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid var(--stroke);
  background: var(--card-solid);
  animation: pop 0.35s ease;
}
@keyframes pop { from { opacity: 0; transform: translateY(12px) scale(0.98); } }
.card img { display: block; width: 100%; background: #0a0e1a; cursor: zoom-in; }
.transparency {
  background-image: conic-gradient(#2b3040 90deg, #1b1f2b 90deg 180deg, #2b3040 180deg 270deg, #1b1f2b 270deg);
  background-size: 18px 18px;
}
.card-actions {
  position: absolute;
  right: 10px;
  top: 10px;
  display: flex;
  gap: 6px;
  opacity: 0;
  transition: 0.2s;
}
.card:hover .card-actions { opacity: 1; }
.icon-btn {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border-radius: 9px;
  border: 1px solid var(--stroke-strong);
  background: rgba(10, 14, 26, 0.78);
  color: #fff;
  cursor: pointer;
  font-size: 14px;
  text-decoration: none;
  backdrop-filter: blur(6px);
  transition: 0.15s;
}
.icon-btn:hover { background: var(--brand); border-color: var(--brand); }
.card-meta {
  padding: 11px 13px 13px;
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.6;
}
.card-meta .p {
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-meta .t { color: var(--dim); font-size: 11.5px; }

.skeleton {
  aspect-ratio: 1 / 1;
  border-radius: 14px;
  border: 1px solid var(--stroke);
  background: linear-gradient(100deg, #131929 30%, #1d2438 50%, #131929 70%);
  background-size: 300% 100%;
  animation: shimmer 1.4s infinite linear;
}
@keyframes shimmer { from { background-position: 120% 0; } to { background-position: -120% 0; } }

/* 历史抽屉 */
.drawer {
  position: absolute;
  right: 0;
  top: 0;
  width: 330px;
  max-height: calc(100vh - 100px);
  padding: 16px;
  background: var(--card);
  backdrop-filter: blur(20px);
  border: 1px solid var(--stroke-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 12px;
  z-index: 20;
  animation: slidein 0.25s ease;
}
@keyframes slidein { from { opacity: 0; transform: translateX(24px); } }
.drawer-head { display: flex; align-items: center; justify-content: space-between; }
.drawer-head h3 { margin: 0; font-size: 15px; }
.history-list { display: flex; flex-direction: column; gap: 10px; overflow: auto; flex: 1; }
.history-item {
  display: flex;
  gap: 10px;
  padding: 8px;
  border-radius: 11px;
  border: 1px solid var(--stroke);
  background: rgba(255, 255, 255, 0.03);
  cursor: pointer;
  transition: 0.16s;
}
.history-item:hover { border-color: var(--brand); background: rgba(124, 92, 255, 0.1); }
.history-item img { width: 62px; height: 62px; object-fit: cover; border-radius: 8px; flex: none; }
.history-item div { font-size: 12px; color: var(--muted); overflow: hidden; }
.history-item b { display: block; color: var(--text); font-weight: 600; font-size: 12.5px; }
.history-item span {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.empty-hist { color: var(--dim); font-size: 13px; text-align: center; padding: 24px 0; }

/* 页脚 */
.footbar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 4px 22px;
  font-size: 12px;
  color: var(--dim);
}

/* 登录遮罩 */
.gate {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(4, 6, 14, 0.82);
  backdrop-filter: blur(14px);
}
.gate-card {
  width: 100%;
  max-width: 380px;
  padding: 34px 28px;
  text-align: center;
  border-radius: 22px;
  background: var(--card-solid);
  border: 1px solid var(--stroke-strong);
  box-shadow: var(--shadow);
  animation: pop 0.4s ease;
}
.gate-logo {
  width: 62px; height: 62px;
  margin: 0 auto 16px;
  display: grid; place-items: center;
  font-size: 30px;
  border-radius: 18px;
  background: var(--grad);
  box-shadow: 0 16px 40px -16px rgba(255, 110, 199, 0.9);
}
.gate-card h1 { margin: 0 0 6px; font-size: 21px; }
.gate-sub { margin: 0 0 22px; color: var(--muted); font-size: 13.5px; }
.gate-card input { margin-bottom: 12px; text-align: center; }
.gate-card .btn { width: 100%; padding: 12px; }
.gate-error { color: var(--bad); font-size: 13px; margin-top: 12px; min-height: 18px; }

/* Lightbox */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(4, 6, 14, 0.92);
  display: grid;
  grid-template-rows: 1fr auto;
  padding: 24px;
  animation: pop 0.2s ease;
}
.lightbox img {
  max-width: 100%;
  max-height: 100%;
  justify-self: center;
  align-self: center;
  border-radius: 12px;
  box-shadow: 0 30px 80px -30px #000;
}
.lb-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  justify-content: space-between;
  margin-top: 16px;
  color: var(--muted);
  font-size: 13px;
}
.lb-bar span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-close {
  position: fixed;
  right: 24px;
  top: 20px;
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 1px solid var(--stroke-strong);
  background: rgba(20, 26, 44, 0.9);
  color: #fff;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}
.lb-close:hover { background: var(--bad); border-color: var(--bad); }

/* 响应式 */
@media (max-width: 1080px) {
  .layout { grid-template-columns: 1fr; }
  .panel { position: static; max-height: none; }
  .drawer { position: fixed; right: 12px; top: 70px; bottom: 12px; max-height: none; }
}
@media (max-width: 620px) {
  .app { padding: 0 12px; }
  .results { grid-template-columns: 1fr; }
  .grid { grid-template-columns: 1fr; }
  .drawer { left: 12px; right: 12px; width: auto; }
  .empty-art svg { width: 180px; height: 135px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001s !important; transition-duration: 0.001s !important; }
}
