/* Flat dark theme.
   Layering comes from background lightness, not from borders and shadows --
   the previous design nested four levels of outlined boxes and the strokes
   competed with the content. Only one accent colour, reserved for things that
   are actionable or that report state. */

:root {
  --bg: #0e1014;
  --surface: #161a21;
  --surface-2: #1c212a;
  --field: #11141a;
  --line: #232935;
  --text: #e9edf5;
  --muted: #8b93a5;
  --faint: #656d7e;
  /* One vivid hue per feature. Gives the dark shell colour without turning
     random: the active mode, its primary button and its result frame all read
     as the same thing. --feature is swapped on the shell when the mode changes. */
  --c-image: #38bdf8;   /* sky   - 生成图片 */
  --c-dress: #a78bfa;   /* violet- 换装 */
  --c-face:  #2dd4bf;   /* teal  - 换脸 */
  --c-video: #fbbf24;   /* amber - 生成视频 */
  --feature: var(--c-image);

  --accent: var(--feature);
  --accent-ink: #0b0e13;
  --ok: #4ade80;
  --warn: #fbbf24;
  --danger: #fb7185;
  --r: 10px;
  --r-lg: 16px;

  font-family: "SF Pro Text", "PingFang SC", "Segoe UI", system-ui, -apple-system, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; cursor: pointer; }

/* ---------- top bar ---------- */

.topbar {
  /* Sticky so the balance and the recharge entry stay reachable after the page
     scrolls; the popover is anchored to this bar. */
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--line);
}

.brand {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

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

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

.chip {
  border: 0;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
  background: var(--surface-2);
  color: var(--text);
  transition: background 0.15s;
}
.chip:hover { background: #232935; }
.chip strong { color: var(--feature); font-variant-numeric: tabular-nums; }

.chip.primary { background: var(--feature); color: var(--accent-ink); font-weight: 600; }
.chip.primary:hover { filter: brightness(1.12); }

/* ---------- recharge popover ---------- */

.wallet-pop {
  position: absolute;
  top: 58px;
  right: 24px;
  z-index: 20;
  width: 280px;
  padding: 14px;
  border-radius: var(--r-lg);
  background: var(--surface-2);
  border: 1px solid var(--line);
}
.wallet-pop-title { font-weight: 600; margin-bottom: 10px; }
.packages { display: grid; gap: 8px; }
.pkg {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border: 0;
  border-radius: var(--r);
  background: var(--field);
  color: var(--text);
  text-align: left;
}
.pkg:hover { background: #1a1f28; }
.pkg b { font-size: 15px; }
.pkg span { color: var(--muted); font-size: 12px; }
.wallet-pop-note { margin-top: 10px; color: var(--faint); font-size: 12px; line-height: 1.6; }

/* ---------- layout ---------- */

.studio {
  display: grid;
  grid-template-columns: 420px minmax(0, 1fr);
  gap: 24px;
  align-items: start;
  max-width: 1240px;
  margin: 0 auto;
  padding: 24px;
}

.composer { display: grid; gap: 16px; }

/* ---------- mode switch ---------- */

.modes {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  padding: 4px;
  border-radius: var(--r);
  background: var(--surface);
}
.mode {
  border: 0;
  border-radius: 7px;
  padding: 8px 4px;
  font-size: 13px;
  background: transparent;
  color: var(--muted);
  transition: background 0.15s, color 0.15s;
}
.mode:hover { color: var(--text); }
.mode.active { background: var(--surface-2); color: var(--mode-color, var(--text)); font-weight: 600; }
.mode[data-tab="txt2img"]   { --mode-color: var(--c-image); }
.mode[data-tab="undress"]   { --mode-color: var(--c-dress); }
.mode[data-tab="faceswap"]  { --mode-color: var(--c-face); }
.mode[data-tab="img2video"] { --mode-color: var(--c-video); }

/* ---------- panels & fields ---------- */

.panel { display: none; gap: 16px; }
.panel.active { display: grid; }

.field { display: grid; gap: 8px; }
.field > span {
  font-size: 13px;
  color: var(--muted);
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.field > span em { color: var(--faint); font-style: normal; font-size: 12px; }

textarea,
input[type="text"],
input[type="number"] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: var(--r);
  background: var(--field);
  color: var(--text);
  font: inherit;
  resize: vertical;
  transition: border-color 0.15s, background 0.15s;
}
textarea::placeholder, input::placeholder { color: var(--faint); }
textarea:focus, input:focus {
  outline: none;
  border-color: var(--accent);
  background: #0d1016;
}

/* ---------- segmented control ---------- */

.segmented {
  display: grid;
  grid-auto-flow: column;
  gap: 4px;
  padding: 4px;
  border-radius: var(--r);
  background: var(--field);
}
.segmented button {
  border: 0;
  border-radius: 7px;
  padding: 7px 8px;
  font-size: 13px;
  background: transparent;
  color: var(--muted);
  transition: background 0.15s, color 0.15s;
}
.segmented button:hover { color: var(--text); }
.segmented button.active { background: var(--surface-2); color: var(--feature); font-weight: 600; }

/* ---------- image picker ---------- */

/* Reads as a control, not as a text field: dashed outline, an explicit
   button-looking affordance, and a filled state that shows the thumbnail. */
.drop {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 68px;
  padding: 12px;
  border: 1px dashed var(--line);
  border-radius: var(--r);
  background: var(--field);
  color: var(--muted);
  font-size: 13px;
  transition: border-color 0.15s, background 0.15s;
}
.drop:hover { border-color: var(--feature); background: #141821; }
.drop:focus-within { border-color: var(--feature); }
.drop input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}
.drop .pick {
  flex: none;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--feature);
  font-size: 20px;
  line-height: 1;
}
.drop .thumb {
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: 10px;
  object-fit: cover;
}
.drop .drop-text { display: grid; gap: 2px; min-width: 0; }
.drop .drop-text b { font-weight: 600; color: var(--text); font-size: 13px; }
.drop .drop-text span {
  color: var(--faint);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.drop.filled { border-style: solid; border-color: var(--line); }

/* ---------- submit ---------- */

.submit { display: grid; gap: 8px; justify-items: start; }
.consent { margin: 0; font-size: 12px; color: var(--faint); }
.go {
  width: 100%;
  border: 0;
  border-radius: var(--r);
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 600;
  background: var(--feature);
  color: var(--accent-ink);
  transition: filter 0.15s, opacity 0.15s;
}
.go:hover:not(:disabled) { filter: brightness(1.12); }
.go:disabled { opacity: 0.5; cursor: not-allowed; }
.go.locked { background: var(--surface-2); color: var(--text); opacity: 1; cursor: pointer; }
.cost { font-size: 12px; color: var(--faint); }

.tip { margin: -4px 0 0; font-size: 12px; color: var(--faint); line-height: 1.6; }

/* ---------- stage ---------- */

.stage {
  min-height: 460px;
  border-radius: var(--r-lg);
  background: var(--surface);
  padding: 16px;
  display: grid;
  align-content: start;
  gap: 12px;
}

.stage-empty {
  min-height: 428px;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 12px;
  color: var(--faint);
}
.stage-empty-mark {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--c-image), var(--c-dress));
  opacity: 0.4;
}
.stage-empty p { margin: 0; font-size: 13px; }

.result-media {
  display: grid;
  place-items: center;
  border-radius: var(--r);
  background: var(--field);
  overflow: hidden;
}
.result-media img,
.result-media video {
  max-width: 100%;
  max-height: 70vh;
  display: block;
}

.result-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.result-meta { color: var(--faint); font-size: 12px; margin-right: auto; }
.result-meta b { color: var(--muted); font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- history ---------- */

.history { display: grid; gap: 10px; }
.history-title { font-size: 12px; color: var(--faint); }
.history-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  gap: 8px;
}
.history-item {
  position: relative;
  aspect-ratio: 1;
  border: 0;
  padding: 0;
  border-radius: var(--r);
  overflow: hidden;
  background: var(--field);
}
.history-item img, .history-item video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.history-item::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: var(--r);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
}
.history-item:hover::after { box-shadow: inset 0 0 0 2px var(--feature); }
.history-item .kind {
  position: absolute;
  left: 5px;
  bottom: 5px;
  padding: 2px 6px;
  border-radius: 999px;
  font-size: 10px;
  background: rgba(11, 14, 19, 0.78);
  color: var(--text);
}

/* ---------- progress ---------- */

.skeleton {
  position: relative;
  min-height: 320px;
  border-radius: var(--r);
  background: var(--field);
  overflow: hidden;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 10px;
  color: var(--muted);
}
.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(100deg, transparent 20%, rgba(255, 255, 255, 0.06) 50%, transparent 80%);
  animation: sweep 1.5s linear infinite;
}
@keyframes sweep {
  from { transform: translateX(-100%); }
  to { transform: translateX(100%); }
}
.skeleton .elapsed { font-variant-numeric: tabular-nums; font-size: 22px; color: var(--text); }
.skeleton .hint { font-size: 12px; color: var(--faint); }

.spinner {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid rgba(14, 16, 20, 0.35);
  border-top-color: var(--accent-ink);
  display: inline-block;
  vertical-align: -2px;
  margin-right: 8px;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- notices ---------- */

.notice {
  border-radius: var(--r);
  padding: 12px 14px;
  font-size: 13px;
  line-height: 1.6;
  background: var(--surface-2);
}
.notice.warn { color: var(--warn); }
.notice.error { color: var(--danger); }
.notice .row { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }

/* ---------- footer ---------- */

.foot {
  max-width: 1240px;
  margin: 0 auto;
  padding: 8px 24px 32px;
  font-size: 12px;
  color: var(--faint);
}

/* ---------- mobile ---------- */

@media (max-width: 959px) {
  .studio {
    grid-template-columns: minmax(0, 1fr);
    gap: 16px;
    padding: 12px 12px 132px;  /* clears the sticky action bar */
  }
  .topbar { padding: 12px 14px; }
  .brand { font-size: 14px; }
  .stage { min-height: 200px; padding: 12px; }
  .stage-empty { min-height: 160px; }
  .wallet-pop { right: 12px; left: 12px; width: auto; top: 54px; }

  /* Horizontal scroll beats four cramped 2-line labels on a 360px screen. */
  .modes {
    display: flex;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .modes::-webkit-scrollbar { display: none; }
  .mode { flex: 0 0 auto; padding: 10px 16px; font-size: 14px; white-space: nowrap; }

  /* Comfortable touch targets: 44px is the smallest reliably tappable size. */
  textarea, input[type="text"], input[type="number"] { font-size: 16px; padding: 12px; }
  .segmented button { padding: 11px 8px; font-size: 14px; }
  .drop { min-height: 76px; }
  .chip { padding: 9px 14px; }

  /* The generate button follows the user instead of sitting at the end of a
     scroll. Consent and price ride along so the decision keeps its context. */
  .submit {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    justify-items: stretch;
    gap: 4px;
    padding: 12px 12px calc(12px + env(safe-area-inset-bottom));
    /* Opaque, not a gradient: content scrolling underneath was showing through
       and making the consent line unreadable. */
    background: var(--bg);
    border-top: 1px solid var(--line);
  }
  .panel:not(.active) .submit { display: none; }
  .consent, .cost { text-align: center; }
  .go { padding: 14px 16px; font-size: 15px; }
  .result-media img, .result-media video { max-height: 56vh; }
  .history-grid { grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); }
}

@media (max-width: 400px) {
  .mode { padding: 10px 12px; }
}

/* Packages expanded in place, next to whatever prompted the top-up. */
.inline-recharge {
  margin-top: 12px;
}
.inline-recharge .packages {
  display: grid;
  gap: 8px;
}

/* ------------------------------------------------------------- gallery */

.history-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 10px;
}
.link-btn {
  border: 0;
  background: none;
  color: var(--feature);
  font-size: 13px;
  cursor: pointer;
  padding: 2px 0;
}
.link-btn:hover { text-decoration: underline; }

.gallery-loading,
.gallery-empty {
  color: var(--text-dim);
  font-size: 13px;
  padding: 24px 0;
  text-align: center;
}
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}
.gallery-item {
  margin: 0;
  border-radius: var(--r-lg);
  overflow: hidden;
  background: var(--surface-2);
}
.gallery-view {
  display: block;
  width: 100%;
  aspect-ratio: 3 / 4;
  padding: 0;
  border: 0;
  background: var(--field);
  cursor: pointer;
  overflow: hidden;
}
.gallery-view img,
.gallery-view video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.gallery-gone {
  display: grid;
  place-items: center;
  height: 100%;
  color: var(--text-dim);
  font-size: 12px;
}
.gallery-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
}
.gallery-actions {
  display: flex;
  gap: 6px;
}
.icon-btn {
  border: 0;
  border-radius: var(--r-sm);
  padding: 4px 8px;
  font-size: 12px;
  cursor: pointer;
  background: var(--field);
  color: var(--text);
  text-decoration: none;
}
.icon-btn:hover { background: var(--feature); color: #0b0d12; }
.icon-btn.danger:hover { background: #f2555a; color: #fff; }

/* Touch targets stay comfortable, and two per row keeps them legible. */
@media (max-width: 640px) {
  .gallery-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .icon-btn { padding: 8px 10px; font-size: 13px; }
}
