:root {
  --paper: #f7f8f5;
  --sheet: #ffffff;
  --ink: #172234;
  --muted: #68717d;
  --line: #dce1e4;
  --navy: #183650;
  --blue: #1767b6;
  --coral: #ee7d68;
  --yellow: #efae1a;
  --mint: #d8efe7;
  --shadow: 0 24px 60px rgba(24, 54, 80, .11);
  --radius: 18px;
}

* { box-sizing: border-box; }

html { background: var(--paper); }

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background:
    linear-gradient(rgba(24, 54, 80, .035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(24, 54, 80, .035) 1px, transparent 1px),
    var(--paper);
  background-size: 28px 28px;
  font-family: "Noto Sans SC", "Microsoft YaHei", system-ui, sans-serif;
}

button, input, select { font: inherit; }
button { color: inherit; }

.app-shell { min-height: 100vh; }
.app-shell.locked { visibility: hidden; pointer-events: none; }

.login-gate { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 20px; background: rgba(247, 248, 245, .92); backdrop-filter: blur(12px); }
.login-gate[hidden] { display: none; }
.login-card { width: min(390px, 100%); display: grid; gap: 14px; padding: 30px; border: 1px solid var(--line); border-radius: 18px; background: white; box-shadow: 0 25px 80px rgba(24, 54, 80, .16); }
.login-card h1 { margin: 0; font-size: 28px; letter-spacing: -.04em; }
.login-card label { display: grid; gap: 7px; color: var(--muted); font-size: 11px; }
.login-card input { width: 100%; border: 1px solid var(--line); border-radius: 9px; background: white; padding: 11px 12px; outline: none; }
.login-card input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(23, 103, 182, .11); }
.login-note { margin: -5px 0 5px; color: var(--muted); font-size: 11px; line-height: 1.6; }
.login-error { margin: -2px 0 0; color: #9e3b32; font-size: 11px; }

.topbar {
  height: 78px;
  padding: 0 clamp(20px, 4vw, 64px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(24, 54, 80, .12);
  background: rgba(247, 248, 245, .88);
  backdrop-filter: blur(16px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { display: flex; align-items: center; gap: 13px; color: inherit; text-decoration: none; }
.brand > span:last-child { display: grid; line-height: 1; gap: 6px; }
.brand strong { font-size: 21px; letter-spacing: .08em; }
.brand small { font: 600 9px/1 ui-monospace, SFMono-Regular, Consolas, monospace; letter-spacing: .13em; color: var(--muted); }
.brand-mark { width: 37px; height: 37px; display: grid; grid-template-columns: 1fr 1fr; gap: 3px; transform: rotate(3deg); }
.brand-mark i { display: block; border-radius: 3px; background: var(--navy); }
.brand-mark i:nth-child(2) { background: var(--coral); }
.brand-mark i:nth-child(3) { background: var(--yellow); }
.brand-mark i:nth-child(4) { background: var(--blue); }

.top-actions { display: flex; align-items: center; gap: 12px; }
.user-badge { color: var(--muted); font-size: 11px; }
.top-logout { padding: 7px 10px; }
.status-pill { display: inline-flex; gap: 7px; align-items: center; padding: 8px 11px; border: 1px solid var(--line); border-radius: 99px; background: var(--sheet); color: var(--muted); font-size: 12px; }
.status-pill > span { width: 7px; height: 7px; border-radius: 50%; background: var(--yellow); box-shadow: 0 0 0 4px rgba(239, 174, 26, .15); }
.status-pill.ready > span { background: #2ba36b; box-shadow: 0 0 0 4px rgba(43, 163, 107, .14); }
.status-pill.fallback > span { background: var(--coral); }
.icon-button { border: 1px solid var(--ink); background: var(--ink); color: white; padding: 9px 14px; border-radius: 10px; cursor: pointer; font-weight: 700; font-size: 12px; }

main { width: min(1540px, calc(100% - 40px)); margin: 0 auto; padding-bottom: 60px; }
.intro { padding: 58px 5px 38px; display: grid; grid-template-columns: 1fr; gap: 50px; align-items: end; }
.eyebrow { margin: 0 0 10px; font: 700 10px/1.2 ui-monospace, SFMono-Regular, Consolas, monospace; letter-spacing: .18em; color: var(--blue); }
.intro h1 { margin: 0; font-size: clamp(35px, 4.8vw, 70px); line-height: 1.02; letter-spacing: -.055em; }
.intro h1 em { color: var(--coral); font-style: normal; }
.intro-note { margin: 0; padding-left: 18px; border-left: 3px solid var(--yellow); color: var(--muted); font-size: 14px; line-height: 1.85; }

.workspace { display: grid; grid-template-columns: minmax(390px, 470px) minmax(0, 1fr); border: 1px solid rgba(24, 54, 80, .14); background: var(--sheet); box-shadow: var(--shadow); border-radius: 22px; overflow: hidden; }
.control-panel { padding: 32px; border-right: 1px solid var(--line); background: #fbfcfa; }
.step-block { padding-bottom: 27px; margin-bottom: 27px; border-bottom: 1px solid var(--line); }
.section-label { display: flex; align-items: center; gap: 10px; margin-bottom: 15px; }
.section-label > span { font: 700 9px/1 ui-monospace, monospace; color: white; background: var(--navy); padding: 5px 6px; border-radius: 4px; }
.section-label h2 { margin: 0; font-size: 15px; letter-spacing: -.01em; }
.section-label.compact { margin-bottom: 11px; }

.mode-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.mode-card { min-height: 134px; padding: 14px 12px 12px; display: flex; flex-direction: column; gap: 7px; border: 1px solid var(--line); border-radius: 13px; background: var(--sheet); cursor: pointer; transition: .18s ease; position: relative; overflow: hidden; }
.mode-card:hover { transform: translateY(-2px); border-color: #aeb8bf; }
.mode-card.is-selected { border-color: var(--blue); box-shadow: inset 0 0 0 1px var(--blue), 0 8px 24px rgba(23, 103, 182, .11); }
.mode-card.is-selected::after { content: "✓"; position: absolute; right: 8px; top: 7px; width: 18px; height: 18px; border-radius: 50%; background: var(--blue); color: white; font: 700 11px/18px system-ui; text-align: center; }
.mode-card input { position: absolute; opacity: 0; }
.mode-card strong { font-size: 13px; }
.mode-card small { color: var(--muted); line-height: 1.45; font-size: 10px; }
.mode-icon { width: 32px; height: 32px; display: block; margin-bottom: 2px; border-radius: 8px; background-color: #edf1f3; position: relative; }
.mode-icon-grid { background-image: linear-gradient(var(--navy) 2px, transparent 2px), linear-gradient(90deg, var(--navy) 2px, transparent 2px); background-size: 9px 9px; background-position: 3px 3px; }
.mode-icon-spark::before { content: "✦"; position: absolute; inset: 0; color: var(--coral); text-align: center; font: 700 25px/32px Georgia, serif; }
.mode-icon-loop::before { content: "↻"; position: absolute; inset: 0; color: var(--blue); text-align: center; font: 700 25px/32px system-ui; }

.drop-zone { min-height: 132px; border: 1.5px dashed #aab4bb; border-radius: 15px; display: flex; align-items: center; justify-content: center; gap: 13px; background: var(--sheet); cursor: pointer; position: relative; overflow: hidden; transition: .18s ease; }
.drop-zone:hover, .drop-zone.dragging { border-color: var(--blue); background: #f3f8fc; }
.drop-zone .drop-plus { width: 33px; height: 33px; border-radius: 50%; color: white; background: var(--blue); display: grid; place-items: center; font-size: 23px; line-height: 1; }
.drop-zone > span:nth-child(3) { display: grid; gap: 5px; }
.drop-zone strong { font-size: 13px; }
.drop-zone small { color: var(--muted); font-size: 10px; }
#sourceThumb { display: none; position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.drop-zone.has-image #sourceThumb { display: block; }
.drop-zone.has-image::after { content: "更换图片"; position: absolute; right: 9px; bottom: 9px; color: white; background: rgba(23, 34, 52, .82); border-radius: 8px; padding: 6px 9px; font-size: 10px; backdrop-filter: blur(5px); }
.source-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; margin: -3px 0 10px; padding: 4px; border-radius: 10px; background: #edf1f2; }
.source-tabs button { border: 0; border-radius: 7px; background: transparent; color: var(--muted); padding: 8px 9px; cursor: pointer; font-size: 11px; font-weight: 700; }
.source-tabs button.active { color: var(--ink); background: white; box-shadow: 0 2px 8px rgba(24,54,80,.08); }
.text-source[hidden], #uploadSource[hidden] { display: none; }
.prompt-field { display: grid; gap: 7px; color: var(--muted); font-size: 11px; }
.prompt-field textarea { width: 100%; min-height: 112px; resize: vertical; border: 1px solid var(--line); border-radius: 10px; background: white; padding: 10px 11px; outline: none; color: var(--ink); line-height: 1.55; }
.prompt-field textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(23, 103, 182, .11); }
.prompt-field textarea::placeholder { color: #9aa3aa; }
.secondary-button { width: 100%; height: 44px; margin-top: 10px; border: 1px solid var(--blue); border-radius: 10px; background: #eef5fb; color: var(--blue); display: flex; justify-content: space-between; align-items: center; padding: 0 15px; cursor: pointer; font-weight: 800; font-size: 12px; }
.secondary-button:hover { background: #e2eff9; }
.secondary-button:disabled { opacity: .55; cursor: wait; }

.two-column { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }
.segmented { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; }
.segmented button { padding: 9px 4px 7px; border: 1px solid var(--line); border-radius: 9px; background: white; cursor: pointer; font-weight: 800; font-size: 12px; }
.segmented button small { display: block; margin-top: 3px; color: var(--muted); font-size: 8px; font-weight: 500; }
.segmented button.active { background: var(--navy); color: white; border-color: var(--navy); }
.segmented button.active small { color: #cfdae2; }
.range-field { min-height: 44px; display: flex; align-items: center; gap: 10px; }
.range-field input { width: 100%; accent-color: var(--coral); }
.range-field output { min-width: 44px; font: 800 12px/1 ui-monospace, monospace; color: var(--coral); }

.advanced { margin: -8px 0 24px; border-bottom: 1px solid var(--line); padding-bottom: 22px; }
.advanced summary { display: flex; justify-content: space-between; cursor: pointer; font-weight: 700; font-size: 12px; list-style: none; }
.advanced summary span { color: var(--muted); font-weight: 500; }
.advanced-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 16px; }
.advanced-grid label, .settings-card > label { color: var(--muted); font-size: 11px; display: grid; gap: 7px; }
select, input[type="text"], input[type="url"], input[type="password"], input[type="number"] { width: 100%; border: 1px solid var(--line); border-radius: 9px; background: white; padding: 10px 11px; outline: none; }
select:focus, input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(23, 103, 182, .11); }

.primary-button { width: 100%; height: 54px; border: 0; border-radius: 12px; background: var(--coral); color: white; display: flex; justify-content: space-between; align-items: center; padding: 0 20px; cursor: pointer; font-weight: 800; box-shadow: 0 12px 28px rgba(238, 125, 104, .24); }
.primary-button b { font-size: 21px; }
.primary-button:disabled { background: #c5c9ca; box-shadow: none; cursor: not-allowed; }
.privacy-note { margin: 12px 0 0; color: var(--muted); text-align: center; font-size: 9px; }

.preview-panel { min-width: 0; padding: 32px; background: #edf1f2; }
.preview-toolbar { min-height: 51px; display: flex; justify-content: space-between; gap: 20px; align-items: start; }
.preview-toolbar h2 { margin: 0; font-size: 19px; }
.preview-stats { display: flex; gap: 9px; }
.preview-stats span { min-width: 72px; padding: 8px 10px; border-radius: 8px; background: rgba(255, 255, 255, .8); color: var(--muted); font-size: 9px; text-align: center; }
.preview-stats b { display: block; color: var(--ink); font: 800 14px/1.3 ui-monospace, monospace; }
.preview-stage { min-height: 590px; height: calc(100vh - 210px); max-height: 820px; margin-top: 0; border: 1px solid #d2d9dc; border-radius: 14px; background: #dfe5e7; display: grid; place-items: center; overflow: auto; position: relative; box-shadow: inset 0 1px 0 rgba(255,255,255,.8); }
#previewCanvas { display: none; max-width: calc(100% - 36px); max-height: calc(100% - 36px); width: auto; height: auto; background: white; box-shadow: 0 16px 45px rgba(24,54,80,.18); }
#previewCanvas.visible { display: block; }
.empty-state { max-width: 310px; text-align: center; color: var(--muted); }
.empty-state strong { color: var(--ink); display: block; margin-top: 19px; font-size: 15px; }
.empty-state p { font-size: 11px; line-height: 1.7; }
.empty-grid { width: 112px; height: 112px; margin: auto; border-radius: 50%; background-color: var(--navy); background-image: linear-gradient(rgba(255,255,255,.17) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.17) 1px, transparent 1px); background-size: 14px 14px; box-shadow: 10px 8px 0 var(--coral), -8px -6px 0 var(--yellow); }
.working-state { position: absolute; inset: 0; background: rgba(237, 241, 242, .92); display: grid; align-content: center; justify-items: center; text-align: center; z-index: 2; }
.working-state[hidden] { display: none; }
.working-state strong { margin-top: 18px; font-size: 15px; }
.working-state p { color: var(--muted); font-size: 11px; }
.spinner { width: 46px; height: 46px; border-radius: 50%; border: 4px solid #cad3d8; border-top-color: var(--coral); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.agent-trace, .advice-panel, .downloads { margin-top: 14px; border-radius: 12px; background: white; border: 1px solid var(--line); }
.agent-trace { padding: 15px 17px; }
.trace-head { display: flex; justify-content: space-between; font-size: 11px; }
.trace-head span { color: var(--blue); font-weight: 800; }
.agent-trace ol { display: flex; flex-wrap: wrap; gap: 8px; list-style: none; padding: 0; margin: 12px 0 0; }
.agent-trace li { padding: 6px 9px; border-radius: 99px; background: #eef4f7; color: var(--muted); font-size: 9px; }
.agent-trace li.done { background: var(--mint); color: #176344; }
.advice-panel { padding: 15px 17px; display: flex; justify-content: space-between; align-items: center; gap: 20px; }
.advice-panel[hidden], .downloads[hidden] { display: none; }
.advice-panel p { margin: 4px 0 0; color: var(--muted); font-size: 10px; }
.advice-panel button { flex: 0 0 auto; border: 0; border-radius: 9px; background: var(--blue); color: white; padding: 10px 13px; cursor: pointer; font-size: 11px; font-weight: 700; }
.downloads { display: grid; grid-template-columns: repeat(3, 1fr); overflow: hidden; }
.download-card { padding: 14px 15px; border-right: 1px solid var(--line); }
.download-card:last-child { border-right: 0; }
.download-card strong { font-size: 12px; }
.download-card small { display: block; margin: 4px 0 10px; color: var(--muted); font-size: 9px; }
.download-actions { display: flex; gap: 6px; }
.download-actions button { flex: 1; border: 1px solid var(--line); border-radius: 7px; background: white; padding: 7px; cursor: pointer; font-size: 9px; font-weight: 700; }
.download-actions button:hover { border-color: var(--blue); color: var(--blue); }

dialog { width: min(500px, calc(100% - 32px)); max-height: min(90vh, 760px); padding: 0; border: 0; border-radius: 18px; box-shadow: 0 30px 90px rgba(15, 32, 48, .3); }
dialog::backdrop { background: rgba(20, 32, 44, .55); backdrop-filter: blur(4px); }
.settings-card { padding: 26px; display: grid; gap: 16px; overflow: auto; }
.settings-section { display: grid; gap: 13px; padding: 15px; border: 1px solid var(--line); border-radius: 12px; background: #fbfcfa; }
.settings-kicker { margin: 0 -1px -2px; color: var(--blue); font-size: 11px; font-weight: 800; }
.dialog-head { display: flex; justify-content: space-between; align-items: start; }
.dialog-head h2 { margin: 0; font-size: 22px; }
.close-button { width: 34px; height: 34px; border: 0; border-radius: 50%; background: #edf1f2; cursor: pointer; font-size: 22px; }
.dialog-note { margin: -4px 0 2px; color: var(--muted); font-size: 10px; line-height: 1.65; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 5px; }
.text-button, .primary-small { border: 0; border-radius: 9px; padding: 10px 16px; cursor: pointer; font-weight: 700; font-size: 11px; }
.text-button { background: #edf1f2; }
.primary-small { background: var(--navy); color: white; }
.toast { position: fixed; left: 50%; bottom: 26px; transform: translate(-50%, 20px); padding: 11px 15px; border-radius: 10px; background: var(--ink); color: white; font-size: 11px; opacity: 0; pointer-events: none; transition: .2s ease; z-index: 100; }
.toast.show { transform: translate(-50%, 0); opacity: 1; }
.toast.error { background: #9e3b32; }

@media (max-width: 1050px) {
  .workspace { grid-template-columns: 1fr; }
  .control-panel { border-right: 0; border-bottom: 1px solid var(--line); }
  .preview-stage { height: 650px; }
}

@media (max-width: 680px) {
  .topbar { height: 68px; padding: 0 16px; }
  .status-pill { display: none; }
  main { width: calc(100% - 20px); }
  .intro { padding: 36px 5px 25px; grid-template-columns: 1fr; gap: 20px; }
  .intro h1 { font-size: 38px; }
  .workspace { border-radius: 15px; }
  .control-panel, .preview-panel { padding: 20px; }
  .mode-grid { grid-template-columns: 1fr; }
  .mode-card { min-height: 85px; display: grid; grid-template-columns: 36px 1fr; grid-template-rows: auto auto; align-content: center; column-gap: 10px; }
  .mode-card .mode-icon { grid-row: 1 / 3; }
  .two-column { grid-template-columns: 1fr; }
  .preview-toolbar { display: block; }
  .preview-stats { margin-top: 12px; }
  .preview-stage { min-height: 420px; height: 58vh; }
  .downloads { grid-template-columns: 1fr; }
  .download-card { border-right: 0; border-bottom: 1px solid var(--line); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
