:root {
  color-scheme: light;
  --ink: #1f2523;
  --muted: #66716d;
  --line: #d8ddd9;
  --soft: #f4f6f3;
  --paper: #fbfbf8;
  --panel: #ffffff;
  --green: #236b4b;
  --green-dark: #174732;
  --gold: #ba7c22;
  --blue: #345f8f;
  --red: #a73b3b;
  --shadow: 0 18px 50px rgba(31, 37, 35, 0.08);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--paper);
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.app { width: min(1440px, 100%); margin: 0 auto; padding: 22px; }
.topbar, .section-head, .preview-head { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.topbar { min-height: 74px; border-bottom: 1px solid var(--line); }
.eyebrow { margin: 0 0 4px; color: var(--green); font-size: 12px; font-weight: 750; letter-spacing: 0.08em; text-transform: uppercase; }
h1, h2 { margin: 0; letter-spacing: 0; }
h1 { font-size: clamp(26px, 4vw, 42px); line-height: 1.05; }
h2 { font-size: 18px; }
.top-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.balance { min-width: 250px; padding: 10px 12px; border: 1px solid var(--line); background: var(--panel); font-size: 14px; text-align: right; }
.access-strip { display: grid; grid-template-columns: 1fr auto; gap: 12px; margin: 18px 0 0; padding: 14px; border: 1px solid #e5c477; background: #fff8e4; }
.hidden { display: none !important; }
.workspace { display: grid; grid-template-columns: minmax(380px, 480px) minmax(0, 1fr); gap: 20px; align-items: start; padding: 22px 0; }
.creator, .preview, .history { border: 1px solid var(--line); background: var(--panel); box-shadow: var(--shadow); }
.creator { padding: 18px; display: grid; gap: 16px; }
label { display: grid; gap: 7px; color: var(--muted); font-size: 13px; font-weight: 650; }
input, select, textarea { width: 100%; border: 1px solid var(--line); background: #fff; color: var(--ink); padding: 10px 11px; outline: none; border-radius: 6px; }
textarea { resize: vertical; min-height: 120px; line-height: 1.5; }
input:focus, select:focus, textarea:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(35, 107, 75, 0.12); }
.prompt-field { position: relative; }
.prompt-box { position: relative; display: grid; gap: 8px; }
.prompt-tools { display: flex; align-items: center; gap: 8px; min-height: 34px; }
.mention-trigger { display: grid; place-items: center; width: 34px; height: 34px; border: 1px solid var(--line); border-radius: 999px; background: #fff; color: var(--green); font-size: 18px; font-weight: 900; }
.mention-chips { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; min-width: 0; }
.mention-chip { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; min-height: 30px; padding: 4px 8px 4px 4px; border: 1px solid rgba(35,107,75,0.24); border-radius: 999px; background: rgba(35,107,75,0.08); color: var(--green); font-size: 12px; font-weight: 850; }
.mention-chip img { width: 22px; height: 22px; border-radius: 999px; object-fit: cover; }
.mention-chip button { width: 20px; height: 20px; border: 0; border-radius: 999px; background: rgba(35,107,75,0.14); color: var(--green); font-weight: 900; line-height: 1; }
.mention-picker { position: absolute; left: 0; right: 0; bottom: 36px; z-index: 5; display: grid; gap: 8px; max-height: 260px; overflow: auto; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; box-shadow: 0 18px 48px rgba(31,37,35,0.16); }
.mention-option { display: grid; grid-template-columns: 44px minmax(0, 1fr) auto; align-items: center; gap: 10px; min-height: 54px; padding: 6px; border: 1px solid var(--line); border-radius: 7px; background: var(--panel); color: var(--ink); text-align: left; }
.mention-option img { width: 44px; height: 44px; border-radius: 6px; object-fit: cover; background: var(--soft); }
.mention-option strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.mention-option small { color: var(--muted); font-size: 11px; font-weight: 650; }
.mention-empty { margin: 0; padding: 10px; color: var(--muted); font-size: 13px; font-weight: 700; }
.grid { display: grid; gap: 12px; }
.two { grid-template-columns: 1fr 1fr; }
.three { grid-template-columns: 0.85fr 1fr 1fr; }
.mode-tabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; padding: 4px; background: var(--soft); border: 1px solid var(--line); border-radius: 8px; }
.mode { min-height: 36px; border: 0; border-radius: 6px; background: transparent; color: var(--muted); font-weight: 750; }
.mode.active { background: var(--panel); color: var(--ink); box-shadow: 0 1px 8px rgba(31, 37, 35, 0.08); }
.reference-fields { display: grid; gap: 12px; }
.ref-field { display: none; }
.ref-field.show { display: grid; }
.upload-field { gap: 10px; color: var(--muted); font-size: 13px; font-weight: 650; }
.field-title { color: var(--muted); font-size: 13px; font-weight: 750; }
.upload-card { display: grid; gap: 10px; padding: 10px; border: 1px dashed #b9c5be; border-radius: 8px; background: #fbfcfa; }
.upload-button { min-height: 58px; border: 1px solid var(--line); border-radius: 7px; background: #fff; color: var(--ink); display: flex; align-items: center; justify-content: center; gap: 10px; font-weight: 850; }
.upload-button span { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 999px; background: var(--green); color: #fff; font-size: 22px; line-height: 1; }
.upload-button:disabled { opacity: 0.6; cursor: wait; }
.file-input { display: none; }
.manual-link { margin-top: 2px; }
.upload-preview { display: grid; gap: 8px; }
.upload-item { display: grid; grid-template-columns: 54px minmax(0, 1fr) auto; align-items: center; gap: 10px; padding: 8px; border: 1px solid var(--line); border-radius: 7px; background: #fff; }
.upload-item.selected { border-color: rgba(35,107,75,0.44); background: rgba(35,107,75,0.07); }
.upload-item img { width: 54px; height: 54px; border-radius: 6px; object-fit: cover; background: var(--soft); }
.upload-item a { color: var(--green); font-size: 12px; font-weight: 750; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-item small { color: var(--muted); font-size: 11px; font-weight: 650; }
.upload-actions { display: flex; align-items: center; gap: 6px; }
.upload-select, .upload-remove { min-height: 30px; border: 1px solid var(--line); border-radius: 6px; background: var(--soft); color: var(--ink); font-size: 12px; font-weight: 800; white-space: nowrap; }
.upload-select.active { border-color: rgba(35,107,75,0.25); background: var(--green); color: #fff; }
.toggles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.toggles label { display: flex; align-items: center; gap: 8px; min-height: 38px; padding: 0 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--soft); color: var(--ink); font-size: 13px; }
.toggles input { width: auto; }
.cost-card { display: grid; gap: 8px; padding: 14px; border-radius: 8px; border: 1px solid rgba(35,107,75,0.22); background: linear-gradient(135deg, rgba(35,107,75,0.10), rgba(186,124,34,0.08)); }
.cost-card div { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.cost-card span { color: var(--green); font-size: 13px; font-weight: 850; }
.cost-card strong { font-size: 26px; letter-spacing: 0; }
.cost-card p { margin: 0; color: var(--muted); font-size: 12px; font-weight: 700; }
.primary, .ghost, .download { border: 0; border-radius: 7px; min-height: 40px; padding: 0 14px; font-weight: 800; }
.primary { background: var(--green); color: #fff; }
.primary:hover { background: var(--green-dark); }
.primary:disabled { opacity: 0.55; cursor: not-allowed; }
.ghost, .download { display: inline-flex; align-items: center; justify-content: center; border: 1px solid var(--line); background: #fff; color: var(--ink); text-decoration: none; }
.preview { padding: 18px; }
.video-stage { margin-top: 18px; width: 100%; aspect-ratio: 16 / 9; min-height: 320px; border-radius: 7px; overflow: hidden; background: #111715; }
.video-stage video { width: 100%; height: 100%; object-fit: contain; background: #111715; }
.empty { height: 100%; display: grid; place-items: center; align-content: center; gap: 12px; color: #d9e1dc; text-align: center; padding: 24px; }
.empty span { display: grid; place-items: center; width: 82px; height: 82px; border: 1px solid rgba(255,255,255,0.25); border-radius: 50%; font-weight: 850; }
.empty p { margin: 0; color: #d9e1dc; font-weight: 700; overflow-wrap: anywhere; }
.status { display: inline-flex; align-items: center; justify-content: center; min-height: 32px; padding: 0 16px; border-radius: 999px; background: var(--soft); border: 1px solid var(--line); color: var(--ink); font-size: 13px; font-weight: 800; white-space: nowrap; }
.status.running, .status.downloading, .status.submitted, .status.queued { color: var(--blue); border-color: rgba(52,95,143,0.25); background: rgba(52,95,143,0.08); }
.status.ready, .status.succeeded, .status.success { color: var(--green); border-color: rgba(35,107,75,0.24); background: rgba(35,107,75,0.08); }
.status.failed, .status.fail { color: var(--red); border-color: rgba(167,59,59,0.25); background: rgba(167,59,59,0.08); }
.job-meta { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.job-meta span { padding: 6px 9px; border: 1px solid var(--line); background: var(--soft); border-radius: 999px; color: var(--muted); font-size: 12px; font-weight: 700; }
.log { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); color: var(--muted); font-size: 13px; line-height: 1.6; }
.history { padding: 18px; }
.task-list { display: grid; gap: 10px; margin-top: 18px; }
.task { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 12px; padding: 12px; border: 1px solid var(--line); border-radius: 7px; background: #fff; }
.task button { min-width: 0; border: 0; background: transparent; text-align: left; padding: 0; color: var(--ink); }
.task strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.task small { display: block; margin-top: 4px; color: var(--muted); font-weight: 650; overflow-wrap: anywhere; }
.task-actions { display: flex; align-items: center; gap: 8px; }
.form-error { min-height: 20px; margin: 0; color: var(--red); font-size: 13px; font-weight: 700; }
.empty-row { color: var(--muted); margin: 0; }
@media (max-width: 920px) {
  .app { padding: 16px; }
  .topbar, .preview-head, .section-head { align-items: flex-start; flex-direction: column; }
  .top-actions { width: 100%; justify-content: stretch; }
  .balance { flex: 1; text-align: left; }
  .workspace { grid-template-columns: 1fr; }
  .two, .three, .toggles { grid-template-columns: 1fr; }
  .video-stage { min-height: 240px; }
  .task { grid-template-columns: 1fr; }
  .access-strip { grid-template-columns: 1fr; }
}