:root {
  --bg: #f2f2f3;
  --card: #ffffff;
  --card2: #f5f5f6;
  --hover: #ececee;
  --text: #111113;
  --muted: #6f6f78;
  --faint: #a1a1aa;
  --line: #e6e6e9;
  --accent: #111113;
  --accent-text: #ffffff;
  --pink: #ff3d8b;
  --pink-soft: #ffe4ef;
  --green: #16a34a;
  --red: #e5484d;
  --red-soft: #fdeded;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 6px 20px rgba(0, 0, 0, .05);
  --overlay: rgba(10, 10, 12, .45);
  color-scheme: light;
}
:root.dark {
  --bg: #0b0b0d;
  --card: #161618;
  --card2: #1f1f22;
  --hover: #28282c;
  --text: #f4f4f5;
  --muted: #9b9ba4;
  --faint: #6b6b73;
  --line: #2a2a2e;
  --accent: #f4f4f5;
  --accent-text: #111113;
  --pink-soft: #3b1527;
  --red-soft: #3a1818;
  --shadow: none;
  --overlay: rgba(0, 0, 0, .6);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", Inter, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; }
input, textarea { font: inherit; color: inherit; }
svg { display: block; }
.hidden { display: none !important; }

#app { max-width: 720px; margin: 0 auto; padding: 12px 12px 110px; }

/* ---------- top bar ---------- */
.topbar { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.project-btn {
  display: flex; align-items: center; gap: 8px; min-width: 0; flex: 1;
  padding: 9px 12px; border-radius: 999px; background: var(--card); box-shadow: var(--shadow);
  font-weight: 600;
}
.project-btn .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.project-btn .chev { margin-left: auto; color: var(--muted); flex: none; }
.dot { width: 10px; height: 10px; border-radius: 3px; flex: none; background: #f5b82e; }
.dot.team { background: #8b5cf6; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: var(--card); box-shadow: var(--shadow); color: var(--muted);
}
.spend { font-size: 12px; color: var(--muted); padding: 0 6px; margin: -2px 0 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mode-hint { font-size: 12px; color: var(--muted); margin: 8px 2px 0; }
.spend b { color: var(--text); font-weight: 600; }
.spend.warn b { color: var(--red); }

/* ---------- tabs ---------- */
.seg {
  display: flex; gap: 4px; padding: 4px; border-radius: 14px; background: var(--card2);
}
.seg button {
  flex: 1; padding: 8px 10px; border-radius: 10px; font-weight: 600; font-size: 14px; color: var(--muted);
  transition: background .15s, color .15s;
}
.seg button.on { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.tabs { margin-bottom: 12px; background: var(--card); box-shadow: var(--shadow); }
.tabs button.on { background: var(--accent); color: var(--accent-text); }

/* ---------- panel ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; }
.panel { display: flex; flex-direction: column; gap: 14px; }
.label {
  font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted);
  margin-bottom: 8px; display: flex; align-items: center; gap: 6px;
}
.label .hint { text-transform: none; letter-spacing: 0; font-weight: 500; color: var(--faint); margin-left: auto; }

.model-btn {
  width: 100%; display: flex; align-items: center; gap: 10px; text-align: left;
  padding: 11px 12px; border-radius: var(--radius-sm); background: var(--card2);
}
.model-btn .mi {
  width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; flex: none;
  background: var(--card); font-size: 17px;
}
.model-btn .mt { font-weight: 650; }
.model-btn .ms { font-size: 12px; color: var(--muted); }
.model-btn .chev { margin-left: auto; color: var(--muted); }

.tiles { display: flex; gap: 8px; }
.tile {
  position: relative; width: 74px; height: 74px; border-radius: 14px; flex: none;
  border: 1.5px dashed var(--line); background: var(--card2); color: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  font-size: 12px; font-weight: 600; overflow: hidden;
}
.tile svg { width: 20px; height: 20px; }
.tile.filled { border-style: solid; border-color: transparent; }
.tile img, .tile video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.tile.disabled { opacity: .35; }
.tile .x, .ref .x {
  position: absolute; top: 4px; right: 4px; width: 20px; height: 20px; border-radius: 50%;
  background: rgba(0,0,0,.6); color: #fff; display: grid; place-items: center; font-size: 12px; z-index: 2;
}
.tile .cap {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 3px 0; font-size: 10px; text-align: center;
  background: linear-gradient(transparent, rgba(0,0,0,.6)); color: #fff; z-index: 1;
}

.refs { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.refs::-webkit-scrollbar { display: none; }
.ref {
  position: relative; width: 74px; height: 74px; border-radius: 14px; flex: none; overflow: hidden;
  background: var(--card2); display: grid; place-items: center; color: var(--muted);
}
.ref img { width: 100%; height: 100%; object-fit: cover; }
.ref .tag {
  position: absolute; left: 4px; bottom: 4px; padding: 1px 6px; border-radius: 6px; font-size: 10px;
  font-weight: 700; background: rgba(0,0,0,.65); color: #fff;
}
.ref .aud { font-size: 22px; }
.ref .play, .card-media .play {
  position: absolute; inset: 0; display: grid; place-items: center; color: #fff; pointer-events: none;
}
.ref .play svg { width: 22px; height: 22px; filter: drop-shadow(0 1px 3px rgba(0,0,0,.5)); }

.prompt {
  width: 100%; min-height: 96px; max-height: 320px; resize: none; border: 0; outline: 0;
  background: var(--card2); border-radius: var(--radius-sm); padding: 12px; line-height: 1.45;
}
.prompt::placeholder { color: var(--faint); }
.ref-chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.ref-chips button {
  padding: 3px 9px; border-radius: 8px; background: var(--pink-soft); color: var(--pink);
  font-size: 12px; font-weight: 700;
}

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 5px; padding: 7px 9px; border-radius: 11px;
  background: var(--card2); font-size: 12.5px; font-weight: 600;
}
.chip svg { width: 14px; height: 14px; color: var(--muted); }
.chip.off { color: var(--muted); }

.price-line { display: flex; align-items: center; justify-content: space-between; font-size: 13px; color: var(--muted); }
.price-line b { color: var(--text); font-size: 15px; }
.problem { font-size: 13px; color: var(--red); background: var(--red-soft); padding: 8px 10px; border-radius: 10px; }

.gen-btn {
  width: 100%; padding: 15px; border-radius: 14px; background: var(--accent); color: var(--accent-text);
  font-weight: 700; font-size: 16px; display: flex; justify-content: center; gap: 8px;
}
.gen-btn:disabled { opacity: .35; }
.gen-bar {
  position: fixed; left: 0; right: 0; bottom: 0; padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: linear-gradient(transparent, var(--bg) 30%); z-index: 20;
}
.gen-bar .gen-btn { max-width: 696px; margin: 0 auto; }

/* ---------- gallery ---------- */
.gallery-head { display: flex; align-items: center; gap: 8px; margin: 22px 2px 10px; }
.gallery-head h2 { font-size: 18px; margin: 0; }
.gallery-head .seg { margin-left: auto; padding: 3px; }
.gallery-head .seg button { padding: 5px 10px; font-size: 12px; }
.masonry { display: flex; gap: 8px; align-items: flex-start; }
.col { flex: 1; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.gcard {
  position: relative; border-radius: 14px; overflow: hidden; background: var(--card); box-shadow: var(--shadow);
  cursor: pointer;
}
.card-media { position: relative; width: 100%; background: var(--card2); }
.card-media img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.card-media .play svg { width: 34px; height: 34px; opacity: .9; filter: drop-shadow(0 2px 6px rgba(0,0,0,.4)); }
.badge {
  position: absolute; top: 8px; left: 8px; padding: 2px 7px; border-radius: 7px; font-size: 11px; font-weight: 700;
  background: rgba(0,0,0,.6); color: #fff; z-index: 1;
}
.badge.right { left: auto; right: 8px; }
.badge.draft { background: var(--pink); }
.gmeta { padding: 8px 10px; font-size: 12px; color: var(--muted); display: flex; gap: 6px; }
.gmeta .t { color: var(--text); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gmeta .c { margin-left: auto; white-space: nowrap; }

.gcard.pending .card-media {
  background: linear-gradient(110deg, var(--card2) 30%, var(--hover) 50%, var(--card2) 70%);
  background-size: 200% 100%; animation: shimmer 1.4s linear infinite;
}
.pending-inner {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; color: var(--muted); font-size: 12px; text-align: center; padding: 10px;
}
.spinner {
  width: 26px; height: 26px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--text);
  animation: spin .9s linear infinite;
}
.gcard.failed .card-media { background: var(--red-soft); }
.gcard.failed .pending-inner { color: var(--red); }
@keyframes shimmer { to { background-position: -200% 0; } }
@keyframes spin { to { transform: rotate(360deg); } }

.empty { text-align: center; color: var(--muted); padding: 34px 20px; font-size: 14px; }
.empty .big { font-size: 34px; margin-bottom: 8px; }
.more-btn { display: block; margin: 14px auto 0; padding: 10px 16px; border-radius: 12px; background: var(--card); color: var(--muted); font-weight: 600; }

/* ---------- bottom sheet ---------- */
.sheet { position: fixed; inset: 0; z-index: 50; }
.sheet-backdrop { position: absolute; inset: 0; background: var(--overlay); animation: fade .18s; }
.sheet-body {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 86vh; overflow-y: auto;
  background: var(--card); border-radius: 22px 22px 0 0; padding: 8px 14px calc(18px + env(safe-area-inset-bottom));
  animation: up .22s cubic-bezier(.2,.8,.2,1);
  max-width: 720px; margin: 0 auto;
}
.sheet-body::before {
  content: ""; display: block; width: 38px; height: 5px; border-radius: 3px; background: var(--line); margin: 2px auto 12px;
}
.sheet h3 { margin: 0 0 12px; font-size: 17px; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

.list { display: flex; flex-direction: column; gap: 6px; }
.item {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  padding: 11px 12px; border-radius: 14px; background: var(--card2);
}
.item.on { outline: 2px solid var(--text); outline-offset: -2px; }
.item .it { font-weight: 650; }
.item .is { font-size: 12px; color: var(--muted); }
.item .ir { margin-left: auto; text-align: right; font-size: 12px; color: var(--muted); white-space: nowrap; }
.item .ir b { color: var(--text); font-size: 13px; }
.tags { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 5px; }
.tags span { font-size: 10px; font-weight: 700; padding: 2px 6px; border-radius: 6px; background: var(--card); color: var(--muted); }

.opts { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 6px; }
.opt { padding: 12px 6px; border-radius: 12px; background: var(--card2); font-weight: 650; text-align: center; }
.opt.on { background: var(--accent); color: var(--accent-text); }
.opt small { display: block; font-weight: 500; font-size: 11px; opacity: .7; }

.pick-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 12px; }
.pick-grid button { position: relative; aspect-ratio: 1; border-radius: 12px; overflow: hidden; background: var(--card2); }
.pick-grid img { width: 100%; height: 100%; object-fit: cover; }
.pick-grid .play svg { width: 22px; height: 22px; }
.upload-btn {
  width: 100%; padding: 14px; border-radius: 14px; background: var(--accent); color: var(--accent-text);
  font-weight: 700; display: flex; align-items: center; justify-content: center; gap: 8px;
}
.sub { font-size: 12px; color: var(--muted); margin: 14px 2px 0; font-weight: 600; }

.field { width: 100%; padding: 12px; border-radius: 12px; border: 0; background: var(--card2); outline: 0; }
.row { display: flex; gap: 8px; align-items: center; }
.btn { padding: 12px 14px; border-radius: 12px; background: var(--card2); font-weight: 650; }
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.danger { color: var(--red); }
.toggle { display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: 14px; background: var(--card2); }
.toggle .sw { margin-left: auto; width: 44px; height: 26px; border-radius: 13px; background: var(--line); position: relative; flex: none; transition: background .15s; }
.toggle .sw::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.toggle.on .sw { background: var(--green); }
.toggle.on .sw::after { transform: translateX(18px); }

/* ---------- viewer ---------- */
.viewer { position: fixed; inset: 0; z-index: 40; background: var(--bg); overflow-y: auto; animation: fade .15s; }
.viewer-top { position: sticky; top: 0; display: flex; align-items: center; gap: 8px; padding: 10px 12px; background: var(--bg); z-index: 2; }
.viewer-top .vt { font-weight: 700; }
.viewer-top .vs { font-size: 12px; color: var(--muted); }
.viewer-media { background: #000; display: flex; justify-content: center; }
.viewer-media img, .viewer-media video { max-width: 100%; max-height: 70vh; display: block; }
.viewer-body { padding: 14px 12px 40px; max-width: 720px; margin: 0 auto; }
.facts { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.facts span { font-size: 12px; font-weight: 600; padding: 5px 9px; border-radius: 9px; background: var(--card); }
.vprompt { background: var(--card); border-radius: 14px; padding: 12px; font-size: 14px; white-space: pre-wrap; word-break: break-word; margin-bottom: 14px; }
.vprompt .copy { display: block; margin-top: 8px; font-size: 12px; font-weight: 700; color: var(--muted); }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.act {
  display: flex; align-items: center; gap: 8px; padding: 12px; border-radius: 14px; background: var(--card);
  font-weight: 650; font-size: 14px; text-align: left;
}
.act svg { width: 18px; height: 18px; color: var(--muted); flex: none; }
.act.primary { background: var(--accent); color: var(--accent-text); grid-column: 1 / -1; justify-content: center; }
.act.primary svg { color: inherit; }
.verror { background: var(--red-soft); color: var(--red); border-radius: 14px; padding: 12px; margin-bottom: 12px; font-size: 14px; }

/* ---------- toast & progress ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  max-width: calc(100% - 32px); padding: 10px 14px; border-radius: 12px; background: var(--text); color: var(--bg);
  font-size: 14px; font-weight: 600; z-index: 80; box-shadow: 0 8px 30px rgba(0,0,0,.2); animation: up .2s;
}
.toast.err { background: var(--red); color: #fff; }
.upbar { height: 4px; border-radius: 2px; background: var(--line); overflow: hidden; margin-top: 8px; }
.upbar i { display: block; height: 100%; background: var(--text); width: 0; transition: width .2s; }

.boot { min-height: 70vh; display: grid; place-items: center; color: var(--muted); text-align: center; padding: 20px; }

/* ---------- @-mention list under the prompt ---------- */
.mention {
  margin-top: 6px; background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow); overflow: hidden; max-height: 260px; overflow-y: auto;
}
.mention button { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; text-align: left; }
.mention button + button { border-top: 1px solid var(--line); }
.mention button.active { background: var(--card2); }
.mention .mt {
  position: relative; width: 38px; height: 38px; border-radius: 9px; overflow: hidden; flex: none;
  background: var(--card2); display: grid; place-items: center; color: var(--muted);
}
.mention .mt img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.mention .mt .play svg { width: 16px; height: 16px; }
.mention .mt .aud { font-size: 18px; }
.mention b { font-size: 14px; }
.mention small { color: var(--muted); font-size: 12px; }
.opts.dense { grid-template-columns: repeat(auto-fill, minmax(50px, 1fr)); gap: 5px; }
.opts.dense .opt { padding: 10px 0; font-size: 13px; }
.chip.off { opacity: .8; }

/* ---------- reorderable references ---------- */
.ref[data-ref] { cursor: grab; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; touch-action: pan-x; transition: transform .12s; }
.ref[data-ref] img { pointer-events: none; -webkit-user-drag: none; }
.ref.dragging { z-index: 5; transition: none; box-shadow: 0 10px 28px rgba(0,0,0,.28); outline: 2px solid var(--pink); outline-offset: -2px; cursor: grabbing; }
.ref.drop-target { outline: 2px dashed var(--pink); outline-offset: -2px; }
.ref-preview { display: grid; place-items: center; background: var(--card2); border-radius: 14px; overflow: hidden; margin-bottom: 12px; max-height: 260px; }
.ref-preview img { max-width: 100%; max-height: 260px; display: block; }
.ref-preview .aud { font-size: 48px; padding: 30px; }
.act[disabled] { pointer-events: none; }
.sheet .act { background: var(--card2); }
.sheet .act.primary { background: var(--accent); color: var(--accent-text); }

/* ---------- anchor video & Seedance-safe hints ---------- */
.anchor { display: flex; gap: 10px; padding: 10px; border-radius: 14px; background: var(--pink-soft); }
.anchor-media { position: relative; width: 62px; height: 84px; border-radius: 10px; overflow: hidden; flex: none; background: var(--card2); }
.anchor-media img { width: 100%; height: 100%; object-fit: cover; }
.anchor-media .play svg { width: 20px; height: 20px; }
.anchor-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.anchor-text b { display: flex; align-items: center; gap: 5px; font-size: 14px; }
.anchor-text b svg { width: 15px; height: 15px; color: var(--pink); }
.anchor-text small { font-size: 12px; color: var(--muted); }
.anchor-btns { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.anchor-btns button { padding: 6px 10px; border-radius: 9px; background: var(--card); font-size: 12.5px; font-weight: 650; }
.warn-line { font-size: 12.5px; color: #9a6700; background: #fff4d6; padding: 8px 10px; border-radius: 10px; }
:root.dark .warn-line { color: #f5c451; background: #3a2e10; }
.badge.ok { background: var(--green); }

/* ---------- remembered moderation verdicts ---------- */
.vb { position: absolute; top: 4px; left: 4px; z-index: 2; min-width: 20px; height: 20px; padding: 0 4px; border-radius: 10px;
  font-size: 11px; font-weight: 800; display: grid; place-items: center; color: #fff; }
.vb.bad { background: var(--red); }
.vb.ok { background: var(--green); }
.badge.bad { background: var(--red); }
.warn-btn { margin-left: 4px; padding: 3px 9px; border-radius: 8px; background: var(--text); color: var(--bg); font-size: 12px; font-weight: 700; }
