:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --panel-2: #f0f1f4;
  --line: #e2e4ea;
  --text: #15171c;
  --muted: #6b7180;
  --accent: #6d5efc;
  --accent-2: #8b7dff;
  --accent-soft: rgba(109, 94, 252, 0.12);
  --ok: #18a058;
  --warn: #d48806;
  --bad: #e5484d;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 8px 24px rgba(16, 24, 40, 0.06);
  --radius: 14px;
  --radius-sm: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --panel: #171a21;
    --panel-2: #1f232c;
    --line: #2a2f3a;
    --text: #eceef3;
    --muted: #9198a8;
    --accent: #8b7dff;
    --accent-2: #a89dff;
    --accent-soft: rgba(139, 125, 255, 0.16);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.55 -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.center { text-align: center; }
.error-text { color: var(--bad); margin: 6px 0 0; font-size: 13px; }

/* boot + login ---------------------------------------------------------- */
.boot { position: fixed; inset: 0; display: grid; place-items: center; }
.spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 20px; padding: 32px 28px; box-shadow: var(--shadow);
}
.login-card p.muted { margin: 6px 0 22px; }

.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 16px; letter-spacing: 0.2px; }
.brand-lg { font-size: 20px; }
.logo {
  width: 28px; height: 28px; border-radius: 8px; flex: none;
  background: linear-gradient(135deg, var(--accent), #c35cff);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.15);
  position: relative;
}
.logo::after {
  content: ""; position: absolute; inset: 8px 7px 7px 8px; border-radius: 3px;
  border: 2px solid rgba(255, 255, 255, 0.9); border-top-right-radius: 8px;
}

/* buttons + fields ------------------------------------------------------ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--panel); color: var(--text);
  border-radius: var(--radius-sm); padding: 8px 14px; font-weight: 550; text-decoration: none;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s, transform 0.05s;
}
.btn:hover { border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn-ghost { background: transparent; }
.btn-light { background: rgba(255, 255, 255, 0.12); border-color: rgba(255, 255, 255, 0.18); color: #fff; }
.btn-light:hover { background: rgba(255, 255, 255, 0.22); border-color: rgba(255, 255, 255, 0.3); }
.btn-sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn-lg { padding: 12px 18px; font-size: 16px; border-radius: 12px; }
.btn-block { width: 100%; }
.btn-danger:hover { border-color: var(--bad); color: var(--bad); }

.field { display: grid; gap: 6px; margin-bottom: 12px; }
.field > span { font-size: 13px; color: var(--muted); }
.field input, textarea, .search {
  width: 100%; border: 1px solid var(--line); background: var(--panel-2);
  border-radius: var(--radius-sm); padding: 10px 12px; outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field input:focus, textarea:focus, .search:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { resize: vertical; min-height: 44px; line-height: 1.6; }
.field-inline { display: flex; align-items: center; gap: 8px; margin: 0; }
.field-inline input { width: 100px; padding: 8px 10px; }

/* layout ---------------------------------------------------------------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(12px); border-bottom: 1px solid var(--line);
}
.topbar-right { display: flex; align-items: center; gap: 10px; }
.badge {
  font-size: 12px; padding: 3px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent);
  font-weight: 600;
}
.banner {
  margin: 12px 20px 0; padding: 10px 14px; border-radius: var(--radius-sm);
  background: rgba(229, 72, 77, 0.1); color: var(--bad); border: 1px solid rgba(229, 72, 77, 0.3);
}

.layout {
  display: grid; grid-template-columns: 400px minmax(0, 1fr); gap: 20px;
  padding: 20px; max-width: 1680px; margin: 0 auto; align-items: start;
}
.composer {
  position: sticky; top: 76px; max-height: calc(100vh - 96px); overflow: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 18px;
  padding: 18px; box-shadow: var(--shadow); scrollbar-width: thin;
}
.block { margin-bottom: 16px; }
.block-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 8px; }
.block-head .label { margin-bottom: 0; }
.label-sub { margin-top: 12px; color: var(--muted); font-weight: 550; }
.hint { color: var(--muted); font-size: 12px; margin: 6px 0 0; }
.row-2 { display: grid; grid-template-columns: 1fr auto; gap: 14px; }

/* segmented controls ---------------------------------------------------- */
.seg {
  display: flex; gap: 4px; padding: 4px; background: var(--panel-2); border-radius: 12px;
  border: 1px solid var(--line);
}
.seg button {
  flex: 1; border: 0; background: transparent; padding: 7px 8px; border-radius: 8px;
  font-weight: 550; color: var(--muted); white-space: nowrap;
}
.seg button.active { background: var(--panel); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }
.seg button:not(.active):hover { color: var(--text); }
.seg-wrap { flex-wrap: wrap; }
.seg-wrap button { flex: 1 0 28%; }
.seg-mode { margin-bottom: 16px; }
.seg-mode button { padding: 9px; font-size: 15px; }
.seg-sm button { padding: 5px 10px; font-size: 13px; }

.switch { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); cursor: pointer; }
.switch input { accent-color: var(--accent); }

/* models ---------------------------------------------------------------- */
.model-list { display: grid; gap: 8px; }
.model {
  text-align: left; border: 1px solid var(--line); background: var(--panel-2); border-radius: 12px;
  padding: 10px 12px; display: grid; gap: 2px; transition: border-color 0.15s, background 0.15s;
}
.model:hover { border-color: var(--accent); }
.model.active { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.model-top { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.model-tag { font-size: 11px; padding: 1px 7px; border-radius: 999px; background: var(--accent); color: #fff; font-weight: 600; }
.model-desc { font-size: 12px; color: var(--muted); }
.model-id { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; color: var(--muted); }

/* ratios ---------------------------------------------------------------- */
.ratio-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.ratio {
  border: 1px solid var(--line); background: var(--panel-2); border-radius: 10px; padding: 6px 2px 4px;
  display: grid; justify-items: center; gap: 3px; font-size: 11px; color: var(--muted); font-weight: 550;
}
.ratio.active { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.ratio-shape { height: 22px; display: grid; place-items: center; }
.ratio-shape i { display: block; border: 1.5px solid currentColor; border-radius: 3px; }
.ratio-shape i.auto { border-style: dashed; }
.custom-size { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.times { color: var(--muted); }
.size-line { margin: 10px 0 0; font-size: 12px; color: var(--muted); }
.size-line b { color: var(--text); font-variant-numeric: tabular-nums; }

/* stepper --------------------------------------------------------------- */
.stepper {
  display: flex; align-items: center; border: 1px solid var(--line); border-radius: 12px;
  background: var(--panel-2); overflow: hidden; height: 40px;
}
.stepper button { width: 38px; height: 100%; border: 0; background: transparent; font-size: 18px; }
.stepper button:hover { background: var(--accent-soft); }
.stepper span { min-width: 30px; text-align: center; font-weight: 650; font-variant-numeric: tabular-nums; }

/* references ------------------------------------------------------------ */
.dropzone {
  border: 1.5px dashed var(--line); border-radius: 14px; padding: 10px; background: var(--panel-2);
  display: grid; gap: 10px; transition: border-color 0.15s, background 0.15s; outline: none;
}
.dropzone.drag { border-color: var(--accent); background: var(--accent-soft); }
.ref-list { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.ref-list:empty { display: none; }
.ref {
  position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--line);
}
.ref img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ref .ref-no {
  position: absolute; left: 4px; top: 4px; font-size: 11px; font-weight: 700; padding: 1px 6px;
  border-radius: 6px; background: rgba(0, 0, 0, 0.6); color: #fff;
}
.ref .ref-x {
  position: absolute; right: 4px; top: 4px; width: 22px; height: 22px; border-radius: 50%; border: 0;
  background: rgba(0, 0, 0, 0.6); color: #fff; font-size: 13px; line-height: 22px; padding: 0;
}
.ref.uploading::after {
  content: ""; position: absolute; inset: 0; background: rgba(0, 0, 0, 0.45);
}
.ref.uploading .ref-spin {
  position: absolute; left: 50%; top: 50%; width: 20px; height: 20px; margin: -10px 0 0 -10px; z-index: 1;
  border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.4); border-top-color: #fff; animation: spin 0.8s linear infinite;
}
.ref.failed { outline: 2px solid var(--bad); }
.ref-head-right { display: flex; align-items: center; gap: 10px; }
.ref-head-right .hint { margin: 0; }
.link-btn {
  border: 0; background: transparent; padding: 2px 4px; border-radius: 6px;
  color: var(--bad); font-size: 12px; font-weight: 600;
}
.link-btn:hover { background: rgba(229, 72, 77, 0.1); }
.dropzone.used .ref img { opacity: 0.55; }
.hint.used { color: var(--accent); font-weight: 550; }
.ref-add {
  border: 0; background: transparent; color: var(--muted); padding: 12px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center; gap: 8px; font-weight: 550;
}
.ref-add:hover { color: var(--accent); }
.ref-add .plus { font-size: 20px; line-height: 1; }

.advanced summary { cursor: pointer; font-weight: 600; font-size: 13px; color: var(--muted); }
.advanced[open] summary { margin-bottom: 8px; color: var(--text); }
.advanced textarea { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }

.submit-bar {
  position: sticky; bottom: -18px; margin: 0 -18px -18px; padding: 14px 18px 18px;
  background: linear-gradient(to bottom, transparent, var(--panel) 28%);
}

/* feed ------------------------------------------------------------------ */
.feed { min-width: 0; }
.feed-head {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px;
}
.feed-head h2 { margin: 0; font-size: 18px; }
.feed-head p { margin: 2px 0 0; }
.feed-tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.search { width: 200px; padding: 7px 12px; }

.jobs { display: grid; gap: 14px; }
.job {
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 14px;
  box-shadow: var(--shadow);
}
.job-head { display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; }
.job-prompt {
  margin: 0; white-space: pre-wrap; word-break: break-word; font-size: 14px;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; cursor: pointer;
}
.job-prompt.open { -webkit-line-clamp: unset; display: block; }
.status {
  flex: none; font-size: 12px; font-weight: 650; padding: 3px 10px; border-radius: 999px; white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.status.queued { background: var(--panel-2); color: var(--muted); }
.status.running { background: var(--accent-soft); color: var(--accent); }
.status.done { background: rgba(24, 160, 88, 0.12); color: var(--ok); }
.status.partial { background: rgba(212, 136, 6, 0.14); color: var(--warn); }
.status.failed { background: rgba(229, 72, 77, 0.12); color: var(--bad); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 0; }
.chip {
  font-size: 12px; padding: 2px 8px; border-radius: 6px; background: var(--panel-2); color: var(--muted);
  border: 1px solid var(--line); white-space: nowrap;
}
.chip.strong { color: var(--text); }
.job-refs { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.job-refs img, .job-refs .gone {
  width: 40px; height: 40px; border-radius: 8px; object-fit: cover; border: 1px solid var(--line); background: var(--panel-2);
}
.job-refs .gone { display: grid; place-items: center; font-size: 10px; color: var(--muted); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; margin-top: 12px; }
.grid.single { grid-template-columns: minmax(0, 1fr); }
.grid.single .tile { justify-self: start; max-width: 100%; }
.grid.single .tile img { height: auto; }
.tile {
  position: relative; border-radius: 12px; overflow: hidden; background: var(--panel-2);
  border: 1px solid var(--line); align-self: start;
}
.tile img { display: block; width: 100%; height: auto; cursor: zoom-in; }
.tile .tile-bar {
  position: absolute; left: 0; right: 0; bottom: 0; display: flex; gap: 6px; justify-content: flex-end; align-items: center;
  padding: 24px 8px 8px; background: linear-gradient(to top, rgba(0, 0, 0, 0.65), transparent);
  opacity: 0; transition: opacity 0.15s;
}
.tile:hover .tile-bar, .tile:focus-within .tile-bar { opacity: 1; }
.tile .tile-dim { margin-right: auto; color: #fff; font-size: 11px; opacity: 0.9; font-variant-numeric: tabular-nums; }
.tile-wait {
  aspect-ratio: var(--ar, 1); display: grid; place-items: center; align-content: center; gap: 10px;
  color: var(--muted); font-size: 13px; text-align: center; padding: 14px;
  background: linear-gradient(110deg, var(--panel-2) 30%, color-mix(in srgb, var(--panel-2) 60%, var(--line)) 50%, var(--panel-2) 70%);
  background-size: 250% 100%; animation: shimmer 1.6s linear infinite;
}
.tile-wait.queued { animation: none; }
.tile-fail { min-height: 120px; display: grid; place-items: center; padding: 14px; color: var(--bad); font-size: 12px; text-align: center; word-break: break-word; }
@keyframes shimmer { to { background-position: -150% 0; } }

.job-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-top: 12px;
  font-size: 12px; color: var(--muted);
}
.job-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.job-meta { display: flex; gap: 10px; flex-wrap: wrap; }
.job details.req { margin-top: 10px; font-size: 12px; color: var(--muted); }
.job details.req summary { cursor: pointer; }
.job details.req pre {
  margin: 8px 0 0; padding: 10px; background: var(--panel-2); border-radius: 10px; overflow: auto;
  font-size: 11px; max-height: 260px; color: var(--text);
}

.empty { text-align: center; padding: 70px 20px; color: var(--text); }
.empty p { margin: 4px 0; }
.empty-art {
  width: 72px; height: 72px; margin: 0 auto 14px; border-radius: 20px;
  background: linear-gradient(135deg, var(--accent-soft), transparent); border: 1px dashed var(--line);
}

/* people ---------------------------------------------------------------- */
.me-chip {
  display: inline-flex; align-items: center; gap: 6px; max-width: 160px;
  border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 4px 12px 4px 8px;
  font-weight: 600; font-size: 13px;
}
.me-chip:hover { border-color: var(--accent); }
.me-chip span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-dot { width: 10px; height: 10px; border-radius: 50%; background: hsl(var(--h, 250) 70% 55%); flex: none; }
.owner {
  flex: none; font-size: 12px; font-weight: 650; padding: 3px 10px; border-radius: 999px; white-space: nowrap;
  background: hsl(var(--h) 75% 50% / 0.14); color: hsl(var(--h) 60% 38%);
}
@media (prefers-color-scheme: dark) {
  .owner { color: hsl(var(--h) 75% 72%); background: hsl(var(--h) 70% 55% / 0.18); }
}
.job-badges { display: flex; gap: 6px; align-items: center; flex: none; }
.owner-seg { overflow-x: auto; scrollbar-width: none; max-width: 100%; }
.owner-seg::-webkit-scrollbar { display: none; }
.owner-seg button { flex: none; }
.owner-seg button i {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; vertical-align: 1px;
  background: hsl(var(--h) 70% 55%);
}

.modal {
  position: fixed; inset: 0; z-index: 150; background: rgba(8, 9, 12, 0.55); backdrop-filter: blur(4px);
  display: grid; place-items: center; padding: 16px;
}
.modal-card {
  width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line); border-radius: 18px;
  padding: 24px; box-shadow: var(--shadow);
}
.modal-card h3 { margin: 0 0 6px; font-size: 18px; }
.modal-card p.muted { margin: 0 0 16px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }
.name-suggest { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.name-suggest:empty { display: none; }
.name-suggest button {
  border: 1px solid var(--line); background: var(--panel-2); border-radius: 999px; padding: 4px 12px; font-size: 13px;
}
.name-suggest button:hover { border-color: var(--accent); color: var(--accent); }

/* lightbox -------------------------------------------------------------- */
.lightbox {
  position: fixed; inset: 0; z-index: 100; background: rgba(8, 9, 12, 0.94); color: #fff;
  display: grid; grid-template-rows: auto 1fr auto;
}
.lb-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 16px; flex-wrap: wrap; }
.lb-info { font-size: 13px; opacity: 0.85; font-variant-numeric: tabular-nums; }
.lb-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.lb-stage { overflow: auto; display: grid; place-items: center; min-height: 0; padding: 0 56px; }
.lb-stage img { max-width: 100%; max-height: calc(100vh - 150px); object-fit: contain; cursor: zoom-in; border-radius: 6px; }
.lb-stage.actual { place-items: start center; }
.lb-stage.actual img { max-width: none; max-height: none; cursor: zoom-out; }
.lb-nav {
  position: fixed; top: 50%; transform: translateY(-50%); width: 44px; height: 64px; border: 0; border-radius: 12px;
  background: rgba(255, 255, 255, 0.1); color: #fff; font-size: 32px; line-height: 1;
}
.lb-nav:hover { background: rgba(255, 255, 255, 0.2); }
.lb-prev { left: 8px; }
.lb-next { right: 8px; }
.lb-prompt {
  margin: 0; padding: 10px 16px 16px; font-size: 13px; opacity: 0.8; max-height: 72px; overflow: auto;
  white-space: pre-wrap; text-align: center;
}

.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); z-index: 200;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px;
  box-shadow: var(--shadow); max-width: calc(100vw - 32px);
}
.toast.bad { background: var(--bad); color: #fff; }

.mobile-tabs { display: none; }
.count-dot {
  display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 4px; border-radius: 999px;
  background: var(--accent); color: #fff; font-size: 11px; line-height: 18px; text-align: center;
}

/* responsive ------------------------------------------------------------ */
@media (max-width: 1080px) {
  .layout { grid-template-columns: 360px minmax(0, 1fr); gap: 16px; padding: 16px; }
}
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; padding: 12px 16px 24px; }
  .composer { position: static; max-height: none; overflow: visible; }
  .submit-bar { position: sticky; bottom: 0; margin: 0 -18px -18px; border-radius: 0 0 18px 18px; z-index: 5; }
  .topbar { padding: 10px 16px; }
  .banner { margin: 10px 16px 0; }
  .search { width: 100%; }
  .feed-tools { width: 100%; }
  .feed-tools .seg { width: 100%; }
  .me-chip { max-width: 110px; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.single { grid-template-columns: 1fr; }
  .tile .tile-bar { opacity: 1; padding-top: 18px; }
  .lb-stage { padding: 0 8px; }
  .lb-nav { width: 36px; height: 52px; font-size: 26px; top: auto; bottom: 90px; transform: none; }
  .mobile-tabs {
    display: flex; position: sticky; top: 53px; z-index: 15; margin: 10px 16px 0;
    background: color-mix(in srgb, var(--panel-2) 92%, transparent); backdrop-filter: blur(12px);
  }
  .mobile-tabs button { padding: 8px; font-size: 15px; }
  body[data-view="compose"] .feed { display: none; }
  body[data-view="feed"] .composer { display: none; }
  .model-id { display: none; }
}
@media (max-width: 420px) {
  .ratio-grid { grid-template-columns: repeat(4, 1fr); }
  .tile .tile-bar .btn { padding: 4px 8px; font-size: 12px; }
  .tile .tile-dim { display: none; }
}
