:root {
  color-scheme: dark;
  --bg: #080713;
  --surface: rgba(19, 16, 35, .94);
  --surface-2: rgba(255, 255, 255, .055);
  --surface-3: rgba(255, 255, 255, .09);
  --line: rgba(221, 214, 254, .1);
  --line-strong: rgba(221, 214, 254, .2);
  --text: #f7f5ff;
  --muted: #9691aa;
  --soft: #cec9df;
  --accent: #8b5cf6;
  --accent-2: #4f46e5;
  --accent-hover: #a78bfa;
  --brand-gradient: linear-gradient(135deg, #4f46e5 0%, #7c3aed 52%, #a855f7 100%);
  --cyan: #39d4c8;
  --danger: #fb7185;
  --shadow: 0 18px 46px rgba(3, 2, 12, .42);
  --font: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; }
body { background: var(--bg); color: var(--text); font-family: var(--font); font-size: 13px; letter-spacing: 0; }
button, input, textarea, select { color: inherit; font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .45; }
input, textarea, select { outline: none; }
input:focus, textarea:focus, select:focus { border-color: var(--accent) !important; box-shadow: 0 0 0 2px rgba(139, 92, 246, .2); }
::-webkit-scrollbar { width: 7px; height: 7px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #39334f; border-radius: 8px; }

.app-shell { height: 100%; display: grid; grid-template-rows: 58px minmax(0, 1fr); }
.topbar { display: grid; grid-template-columns: 280px 1fr auto; align-items: center; border-bottom: 1px solid var(--line); background: rgba(13, 11, 25, .9); backdrop-filter: blur(18px); padding: 0 14px 0 12px; z-index: 20; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { width: 32px; height: 32px; display: grid; place-items: center; background: var(--brand-gradient); color: #ffffff; font-weight: 800; font-size: 16px; border-radius: 6px; box-shadow: 0 8px 22px rgba(99, 72, 222, .34); }
.brand strong { display: block; font-size: 14px; font-weight: 700; }
.brand span { display: block; margin-top: 1px; color: var(--muted); font-size: 9px; letter-spacing: 1.8px; }
.project-name-wrap { justify-self: center; display: flex; align-items: center; gap: 9px; min-width: 0; }
.project-name { width: min(220px, 25vw); border: 1px solid transparent; border-radius: 5px; background: transparent; padding: 6px 8px; text-align: center; font-weight: 600; }
.project-name:hover { background: var(--surface-2); border-color: var(--line); }
#saveState { color: var(--muted); font-size: 11px; white-space: nowrap; }
.top-actions { display: flex; align-items: center; gap: 7px; }
.divider { width: 1px; height: 22px; background: var(--line); margin: 0 3px; }

.btn, .icon-btn, .tool-btn { border: 1px solid var(--line); background: rgba(255, 255, 255, .045); backdrop-filter: blur(12px); display: inline-flex; align-items: center; justify-content: center; gap: 7px; border-radius: 6px; transition: background .16s, border-color .16s, color .16s, transform .16s; }
.btn { min-height: 34px; padding: 0 12px; font-weight: 600; white-space: nowrap; }
.btn:hover, .icon-btn:hover, .tool-btn:hover { background: var(--surface-3); border-color: var(--line-strong); }
.btn.primary { background: var(--brand-gradient); color: #ffffff; border-color: rgba(167, 139, 250, .46); box-shadow: 0 8px 20px rgba(79, 70, 229, .2); }
.btn.primary:hover { background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 52%, #c084fc 100%); }
.btn.quiet { background: transparent; }
.btn.block { width: 100%; }
.icon-btn { width: 34px; height: 34px; padding: 0; color: var(--soft); }
.icon-btn.small { width: 30px; height: 30px; }
.icon-btn.danger:hover { color: var(--danger); border-color: rgba(251, 113, 133, .55); }
.btn svg, .icon-btn svg, .tool-btn svg, .chip svg, .text-btn svg { width: 15px; height: 15px; stroke-width: 1.8; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: #625d70; box-shadow: 0 0 0 3px rgba(98, 93, 112, .14); }
.status-dot.online { background: var(--cyan); box-shadow: 0 0 0 3px rgba(57, 212, 200, .14); }

.workspace { min-height: 0; display: grid; grid-template-columns: 52px 216px minmax(360px, 1fr) 316px; }
.tool-rail { background: rgba(13, 11, 25, .92); backdrop-filter: blur(16px); border-right: 1px solid var(--line); display: flex; flex-direction: column; align-items: center; gap: 7px; padding: 10px 8px; z-index: 10; }
.tool-btn { width: 36px; height: 36px; border-color: transparent; background: transparent; color: var(--muted); }
.tool-btn.active { color: var(--text); background: var(--surface-3); border-color: var(--line-strong); }
.tool-btn.active::before { content: ""; position: absolute; left: 0; width: 3px; height: 20px; background: var(--accent); border-radius: 0 2px 2px 0; }
.rail-separator { width: 24px; height: 1px; background: var(--line); margin: 4px 0; }
.rail-spacer { flex: 1; }

.asset-panel, .right-panel { min-width: 0; background: var(--surface); backdrop-filter: blur(18px); border-right: 1px solid var(--line); display: flex; flex-direction: column; overflow: hidden; }
.right-panel { border-right: 0; border-left: 1px solid var(--line); }
.panel-title-row { height: 48px; padding: 0 12px 0 14px; display: flex; align-items: center; justify-content: space-between; }
.panel-title-row h2 { margin: 0; font-size: 13px; font-weight: 700; }
.asset-search { position: relative; margin: 0 12px 12px; }
.asset-search svg { position: absolute; left: 9px; top: 9px; width: 14px; height: 14px; color: var(--muted); }
.asset-search input { width: 100%; height: 32px; padding: 0 10px 0 30px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 5px; }
.section-label { display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; padding: 0 14px 8px; }
.asset-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; padding: 0 11px 12px; overflow-y: auto; }
.asset-item { position: relative; border: 1px solid var(--line); border-radius: 5px; background: var(--surface-2); padding: 0; overflow: hidden; aspect-ratio: 1; }
.asset-item:hover { border-color: var(--accent); }
.asset-item img { width: 100%; height: 100%; display: block; object-fit: cover; }
.asset-item span { position: absolute; inset: auto 0 0; padding: 13px 6px 5px; overflow: hidden; color: white; text-overflow: ellipsis; white-space: nowrap; font-size: 10px; background: linear-gradient(transparent, rgba(0,0,0,.75)); }
.empty-state, .empty-properties { color: var(--muted); display: flex; flex-direction: column; gap: 10px; align-items: center; justify-content: center; flex: 1; min-height: 150px; }
.empty-state svg, .empty-properties svg { width: 24px; height: 24px; stroke-width: 1.4; }
.asset-footer { margin-top: auto; padding: 10px; border-top: 1px solid var(--line); }

.canvas-area { position: relative; min-width: 0; min-height: 0; background: #0b0917; display: grid; grid-template-rows: 42px minmax(0,1fr) 66px; overflow: hidden; }
.canvas-toolbar { display: flex; align-items: center; gap: 12px; padding: 0 10px; border-bottom: 1px solid var(--line); background: rgba(14, 12, 27, .9); backdrop-filter: blur(16px); z-index: 4; }
.segmented { display: flex; background: var(--surface-2); padding: 2px; border-radius: 5px; }
.segmented button { height: 26px; border: 0; border-radius: 4px; padding: 0 11px; color: var(--muted); background: transparent; font-size: 11px; }
.segmented button.active { color: var(--text); background: var(--surface-3); }
.canvas-info { display: flex; gap: 6px; color: var(--muted); font-size: 11px; }
.view-actions { margin-left: auto; display: flex; align-items: center; gap: 3px; }
.zoom-label { width: 48px; border: 0; background: transparent; color: var(--soft); font-size: 11px; }
.stage-viewport { position: relative; overflow: auto; display: grid; place-items: center; padding: 80px; background-color: #0a0815; background-image: radial-gradient(rgba(139, 92, 246, .28) 1px, transparent 1px); background-size: 18px 18px; }
.stage-viewport.hide-grid { background-image: none; }
.stage-viewport.preview { padding: 0; background: #07060f; }
.stage-wrap { position: relative; flex: none; box-shadow: var(--shadow); transform-origin: center; }
#artboard { display: block; background: white; touch-action: none; user-select: none; }
.stage-viewport.preview #artboard { max-width: 100%; max-height: 100%; width: auto !important; height: auto !important; }
.drop-hint { position: absolute; inset: 24px; display: none; align-items: center; justify-content: center; gap: 10px; color: var(--text); border: 2px dashed var(--accent); background: rgba(11, 8, 24, .86); backdrop-filter: blur(14px); z-index: 8; border-radius: 8px; font-weight: 600; }
.stage-viewport.dragging .drop-hint { display: flex; }
.artboard-dock { min-width: 0; display: grid; grid-template-columns: auto minmax(0, 1fr) 30px 30px; align-items: center; gap: 6px; padding: 8px 10px; border-top: 1px solid var(--line); background: rgba(14, 12, 27, .92); backdrop-filter: blur(16px); z-index: 5; }
.artboard-dock-title { min-width: 42px; display: grid; gap: 2px; color: var(--muted); font-size: 10px; }
.artboard-dock-title strong { color: var(--text); font-size: 11px; }
.artboard-list { min-width: 0; display: flex; gap: 6px; overflow-x: auto; padding-bottom: 1px; }
.artboard-item { min-width: 142px; height: 48px; display: grid; grid-template-columns: 40px minmax(0, 1fr); align-items: center; gap: 7px; padding: 4px 8px 4px 5px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface-2); color: var(--soft); }
.artboard-item.active { border-color: var(--accent); background: rgba(139, 92, 246, .14); box-shadow: inset 0 0 0 1px rgba(139, 92, 246, .08); }
.artboard-thumb { width: 40px; height: 34px; display: grid; place-items: center; overflow: hidden; border-radius: 3px; background: #f5f3ff; color: #6d6880; }
.artboard-thumb img { width: 100%; height: 100%; object-fit: cover; }
.artboard-thumb svg { width: 14px; }
.artboard-meta { min-width: 0; text-align: left; }
.artboard-meta strong, .artboard-meta span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.artboard-meta strong { color: var(--text); font-size: 10px; }
.artboard-meta span { margin-top: 3px; color: var(--muted); font-size: 9px; }
.floating-selection { position: absolute; z-index: 6; display: flex; gap: 4px; padding: 4px; background: rgba(20, 17, 38, .88); backdrop-filter: blur(14px); border: 1px solid var(--line-strong); border-radius: 6px; box-shadow: var(--shadow); }

.panel-tabs { height: 48px; display: grid; grid-template-columns: repeat(3, 1fr); border-bottom: 1px solid var(--line); padding: 0 10px; }
.panel-tabs button { position: relative; border: 0; background: transparent; color: var(--muted); }
.panel-tabs button.active { color: var(--text); font-weight: 600; }
.panel-tabs button.active::after { content: ""; position: absolute; left: 22%; right: 22%; bottom: 0; height: 2px; background: var(--brand-gradient); }
.panel-content { display: none; padding: 14px; overflow-y: auto; min-height: 0; }
.panel-content.active { display: block; }
.mode-tabs { display: grid; grid-template-columns: repeat(2, 1fr); gap: 4px; padding: 3px; background: var(--surface-2); border-radius: 6px; margin-bottom: 16px; }
.mode-tabs button { height: 31px; border: 0; border-radius: 4px; background: transparent; color: var(--muted); font-size: 12px; }
.mode-tabs button.active { background: var(--surface-3); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.18); }
.field { display: grid; gap: 7px; margin-bottom: 13px; }
.field > span:first-child, .field-head { color: var(--soft); font-size: 11px; }
.field-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.field-head > span:last-child { color: var(--muted); }
.field input, .field textarea, .field select, .property-grid input, .property-grid select, .color-field input[type="text"] { width: 100%; border: 1px solid var(--line); background: var(--surface-2); border-radius: 5px; padding: 8px 9px; }
.field textarea { resize: vertical; min-height: 42px; line-height: 1.55; }
.field select, .property-grid select { height: 35px; }
.field small { color: var(--muted); font-size: 10px; line-height: 1.4; }
.text-btn { border: 0; padding: 2px; display: inline-flex; align-items: center; gap: 4px; background: transparent; color: var(--muted); font-size: 11px; }
.text-btn:hover { color: var(--text); }
.prompt-tools { display: flex; gap: 6px; margin: -5px 0 14px; overflow-x: auto; }
.chip { display: inline-flex; align-items: center; gap: 5px; min-height: 27px; padding: 0 8px; background: transparent; border: 1px solid var(--line); color: var(--muted); border-radius: 999px; white-space: nowrap; font-size: 10px; }
.chip:hover { color: var(--text); border-color: var(--line-strong); }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.size-fields { display: grid; grid-template-columns: 1fr 30px 1fr; gap: 5px; align-items: end; margin-bottom: 14px; }
.number-field { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 7px; height: 35px; padding: 0 8px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 5px; }
.number-field span, .number-field em { color: var(--muted); font-style: normal; font-size: 10px; }
.number-field input { min-width: 0; width: 100%; border: 0; background: transparent; text-align: right; }
.advanced { border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); margin: 4px 0 15px; padding: 10px 0; }
.advanced summary { display: flex; align-items: center; justify-content: space-between; cursor: pointer; list-style: none; color: var(--soft); font-size: 11px; }
.advanced summary svg { width: 14px; transition: transform .2s; }
.advanced[open] summary svg { transform: rotate(180deg); }
.advanced-grid { padding-top: 13px; }
.range-field { display: grid; gap: 6px; margin-bottom: 12px; }
.range-field input { width: 100%; accent-color: var(--accent); }
.range-field b { color: var(--text); font-weight: 600; }
.reference-box { margin-bottom: 14px; padding: 10px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 6px; }
.reference-box label span { color: var(--muted); margin-left: 3px; }
.reference-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.reference-thumb { position: relative; width: 54px; height: 54px; border-radius: 4px; border: 1px solid var(--line); overflow: hidden; background: var(--surface); }
.reference-thumb img { width: 100%; height: 100%; object-fit: cover; }
.reference-thumb button { position: absolute; top: 2px; right: 2px; width: 18px; height: 18px; border: 0; border-radius: 50%; color: white; background: rgba(0,0,0,.7); padding: 0; }
.reference-add { width: 100%; height: 31px; display: flex; align-items: center; justify-content: center; gap: 6px; margin-top: 8px; border: 1px dashed var(--line-strong); border-radius: 4px; background: transparent; color: var(--muted); }
.reference-add svg { width: 13px; }
.generate-btn { width: 100%; min-height: 54px; display: grid; grid-template-columns: 32px 1fr auto; align-items: center; gap: 10px; border: 1px solid rgba(196, 181, 253, .28); border-radius: 7px; padding: 7px 10px; color: #ffffff; background: var(--brand-gradient); box-shadow: 0 10px 26px rgba(79, 70, 229, .25); text-align: left; }
.generate-btn:hover { background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 52%, #c084fc 100%); }
.generate-btn:disabled { background: #40375f; box-shadow: none; }
.generate-icon { width: 30px; height: 30px; display: grid; place-items: center; border-radius: 5px; background: rgba(255,255,255,.28); }
.generate-icon svg { width: 17px; }
.generate-btn strong { display: block; font-size: 13px; }
.generate-btn small { display: block; opacity: .72; margin-top: 2px; font-size: 10px; }
.generate-btn kbd { padding: 3px 5px; border-radius: 4px; background: rgba(18, 12, 46, .28); font-family: inherit; font-size: 10px; }
.progress-wrap { margin-top: 12px; }
.progress-head { display: flex; justify-content: space-between; margin-bottom: 7px; color: var(--muted); font-size: 11px; }
.progress-track { height: 4px; background: var(--surface-3); overflow: hidden; border-radius: 4px; }
.progress-track span { display: block; width: 22%; height: 100%; background: var(--cyan); transition: width .4s; }

.layers-head { display: flex; align-items: center; justify-content: space-between; color: var(--muted); margin-bottom: 10px; }
.layers-list { display: grid; gap: 4px; }
.layer-row { display: grid; grid-template-columns: 28px 34px minmax(0, 1fr) 28px; gap: 6px; align-items: center; min-height: 44px; padding: 3px 5px; border: 1px solid transparent; border-radius: 5px; }
.layer-row:hover { background: var(--surface-2); }
.layer-row.active { border-color: var(--accent); background: rgba(139, 92, 246, .11); }
.layer-row button { border: 0; background: transparent; color: var(--muted); padding: 0; }
.layer-thumb { width: 34px; height: 34px; object-fit: cover; border-radius: 3px; background: var(--surface-3); display: grid; place-items: center; overflow: hidden; }
.layer-thumb img { width: 100%; height: 100%; object-fit: cover; }
.layer-thumb svg { width: 15px; color: var(--muted); }
.layer-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; }
.property-section { padding-bottom: 14px; margin-bottom: 14px; border-bottom: 1px solid var(--line); }
.property-section h3 { font-size: 11px; margin: 0 0 10px; color: var(--soft); }
.property-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.property-grid label { display: grid; grid-template-columns: 34px 1fr; align-items: center; background: var(--surface-2); border: 1px solid var(--line); border-radius: 5px; overflow: hidden; }
.property-grid label span { color: var(--muted); padding-left: 8px; font-size: 10px; }
.property-grid input, .property-grid select { border: 0; border-radius: 0; text-align: right; min-width: 0; }
.color-field { display: grid; grid-template-columns: auto 34px 1fr; align-items: center; gap: 8px; }
.color-field > span { color: var(--muted); }
.color-field input[type="color"] { width: 34px; height: 30px; padding: 2px; border: 1px solid var(--line); background: var(--surface-2); border-radius: 4px; }
.button-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

dialog { width: min(520px, calc(100vw - 32px)); padding: 0; border: 1px solid var(--line-strong); border-radius: 8px; background: rgba(20, 17, 38, .96); backdrop-filter: blur(22px); color: var(--text); box-shadow: 0 28px 80px rgba(3, 2, 12, .62); }
dialog::backdrop { background: rgba(5, 3, 14, .76); backdrop-filter: blur(7px); }
.dialog-card { padding: 20px; }
.dialog-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 18px; }
.dialog-head h2 { margin: 4px 0 0; font-size: 18px; }
.dialog-eyebrow { color: var(--accent); font-size: 9px; letter-spacing: 1.5px; }
.provider-presets { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 17px; }
.provider-card { min-height: 58px; padding: 9px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface-2); text-align: left; }
.provider-card.active { border-color: var(--accent); background: rgba(139, 92, 246, .12); }
.provider-card strong, .provider-card span { display: block; }
.provider-card strong { font-size: 12px; }
.provider-card span { color: var(--muted); margin-top: 4px; font-size: 10px; }
.password-field { display: grid; grid-template-columns: 1fr 34px; gap: 6px; }
.connection-result { padding: 9px 10px; border-radius: 5px; margin-bottom: 14px; background: rgba(57,212,200,.08); color: var(--cyan); font-size: 11px; }
.connection-result.error { background: rgba(251,113,133,.08); color: var(--danger); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.export-preview-row { display: grid; grid-template-columns: 160px 1fr; gap: 14px; align-items: center; margin-bottom: 18px; }
.export-preview { width: 160px; height: 110px; display: grid; place-items: center; overflow: hidden; border: 1px solid var(--line); border-radius: 5px; background-color: #0d0a1b; background-image: linear-gradient(45deg, #211b38 25%, transparent 25%), linear-gradient(-45deg, #211b38 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #211b38 75%), linear-gradient(-45deg, transparent 75%, #211b38 75%); background-size: 14px 14px; background-position: 0 0, 0 7px, 7px -7px, -7px 0; }
.export-preview canvas { display: block; max-width: 100%; max-height: 100%; }
.export-summary { min-width: 0; display: grid; gap: 5px; }
.export-summary strong { font-size: 15px; }
.export-summary span { color: var(--muted); font-size: 11px; }
.check-row { min-height: 34px; display: flex; align-items: center; gap: 9px; color: var(--soft); cursor: pointer; }
.check-row input { width: 15px; height: 15px; accent-color: var(--accent); }
.toast-region { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); display: grid; gap: 8px; z-index: 100; pointer-events: none; }
.toast { min-width: 230px; padding: 10px 13px; border: 1px solid var(--line-strong); border-radius: 6px; background: rgba(31, 26, 55, .94); backdrop-filter: blur(16px); color: var(--text); box-shadow: var(--shadow); animation: toast-in .2s ease; }
.toast.error { border-color: rgba(251,113,133,.55); }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

@media (max-width: 1080px) {
  .workspace { grid-template-columns: 52px 0 minmax(360px, 1fr) 300px; }
  .asset-panel { visibility: hidden; }
  .topbar { grid-template-columns: 180px 1fr auto; }
  .top-actions .btn span:not(.status-dot) { display: none; }
}
@media (max-width: 760px) {
  html, body { overflow: auto; }
  .app-shell { min-height: 100%; height: auto; grid-template-rows: 54px minmax(700px, calc(100vh - 54px)); }
  .topbar { grid-template-columns: 120px 1fr auto; padding-right: 7px; }
  .brand span, #saveState, .top-actions .quiet { display: none; }
  .top-actions #guideBtn { display: inline-flex; }
  .top-actions #guideBtn span { display: none; }
  .project-name { width: 120px; }
  .workspace { grid-template-columns: 46px minmax(280px, 1fr); grid-template-rows: minmax(480px, 62vh) minmax(470px, auto); }
  .tool-rail { grid-row: 1; }
  .asset-panel { display: none; }
  .canvas-area { grid-row: 1; min-height: 480px; }
  .right-panel { grid-row: 2; grid-column: 1 / -1; border-left: 0; border-top: 1px solid var(--line); min-height: 470px; }
  .canvas-info { display: none; }
  .stage-viewport { padding: 32px; }
  .artboard-item { min-width: 128px; }
  .panel-content { max-height: none; }
  .export-preview-row { grid-template-columns: 120px 1fr; }
  .export-preview { width: 120px; }
}
