:root {
  --bg: #f4f5f8; --panel: #fff; --line: #e3e5ec; --text: #1d2130; --muted: #6b7185;
  --accent: #6d4aff; --accent-2: #5a37f0; --accent-soft: #efeaff; --danger: #e5484d; --ok: #12a150; --warn: #b26b00;
  --radius: 10px; --shadow: 0 1px 2px rgba(20,22,40,.06), 0 4px 16px rgba(20,22,40,.05);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.45 -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; background: var(--bg); color: var(--text); }
h3 { margin: 0 0 10px; font-size: 16px; }
h4 { margin: 18px 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
h4:first-child { margin-top: 0; }
code { background: #f0f1f5; padding: 1px 5px; border-radius: 4px; font-size: 12px; }
.muted { color: var(--muted); } .small { font-size: 12px; }
.err { color: var(--danger); margin: 0; }
.warn { color: var(--warn); background: #fff6e5; border: 1px solid #ffe0a6; padding: 6px 8px; border-radius: 8px; margin-top: 8px; }

/* top bar */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 24px; padding: 0 20px; height: 56px; background: #fff; border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; }
.brand-mark { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; background: linear-gradient(135deg, #7d5cff, #4f2fe6); color: #fff; font-weight: 800; }
.tabs { display: flex; gap: 4px; flex: 1; }
.tab { border: 0; background: none; padding: 8px 14px; border-radius: 8px; font: inherit; color: var(--muted); cursor: pointer; font-weight: 600; }
.tab:hover { background: #f2f3f7; color: var(--text); }
.tab.active { background: var(--accent-soft); color: var(--accent-2); }

.view { display: none; padding: 16px 20px 40px; max-width: 1680px; margin: 0 auto; }
.view.active { display: block; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 16px; }
.row-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.row-head h3 { margin: 0; }

/* buttons & inputs */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: #fff; color: var(--text); padding: 8px 14px; border-radius: 8px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: #c9ccd8; background: #fafbfd; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: #f2f3f7; color: var(--text); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 5px 10px; font-size: 12.5px; }
.btn.block { display: flex; width: 100%; margin-top: 8px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-2); }
input[type=text], input[type=number], input[type=password], select { font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--text); min-width: 0; }
input:focus, select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
input[type=range] { width: 100%; accent-color: var(--accent); }
input[type=color] { width: 34px; height: 26px; padding: 0; border: 1px solid var(--line); border-radius: 6px; background: none; vertical-align: middle; }
.slider { display: block; margin: 10px 0 2px; font-size: 13px; }
.slider output { float: right; color: var(--accent-2); font-weight: 700; }
.check { display: flex; align-items: center; gap: 6px; margin: 6px 0; font-size: 13px; cursor: pointer; }
.inline { display: flex; align-items: center; gap: 8px; margin: 10px 0; font-size: 13px; }
.inline input[type=number] { width: 90px; }
.inline select { flex: 1; }
.inline.col { flex-direction: column; align-items: stretch; gap: 4px; }
.btn-row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }

/* stepper */
.stepper { display: flex; align-items: center; gap: 10px; margin: 0 0 14px; }
.step { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 6px 14px 6px 6px; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; }
.step b { display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: #eceef4; color: var(--muted); font-size: 12px; }
.step.active { border-color: var(--accent); color: var(--accent-2); background: var(--accent-soft); }
.step.active b { background: var(--accent); color: #fff; }
.step.done b { background: var(--ok); color: #fff; }
.step-line { flex: 0 0 40px; height: 2px; background: var(--line); }
.step-panel { display: none; }
.step-panel.active { display: block; }

/* step 1 */
.source-input { display: grid; gap: 12px; margin-bottom: 18px; }
.url-row { display: flex; gap: 8px; }
.url-row input[type=text] { flex: 1; padding: 11px 14px; font-size: 15px; }
.dropzone { display: grid; justify-items: center; gap: 4px; padding: 26px; border: 2px dashed #cfd2de; border-radius: var(--radius); background: #fafbff; cursor: pointer; text-align: center; transition: .15s; }
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.dz-icon { font-size: 28px; color: var(--accent); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.empty { grid-column: 1 / -1; color: var(--muted); padding: 30px; text-align: center; border: 1px dashed var(--line); border-radius: var(--radius); }
.card { position: relative; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: #fff; cursor: pointer; transition: .12s; }
.card:hover { border-color: var(--accent); box-shadow: 0 4px 14px rgba(109,74,255,.15); }
.card .thumb { aspect-ratio: 1; background: #f3f4f8 center/contain no-repeat; display: grid; place-items: center; }
.card .thumb img { max-width: 100%; max-height: 100%; object-fit: contain; display: block; }
.card .meta { padding: 7px 9px; font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; gap: 6px; align-items: center; }
.card .meta b { color: var(--text); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .badge { position: absolute; top: 6px; left: 6px; background: rgba(20,22,40,.72); color: #fff; font-size: 11px; padding: 2px 7px; border-radius: 999px; }
.card .actions { display: flex; gap: 4px; padding: 0 8px 8px; flex-wrap: wrap; }
.card.loading::after { content: ""; position: absolute; inset: 0; background: rgba(255,255,255,.6) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='38' height='38' viewBox='0 0 38 38'%3E%3Cg fill='none' stroke='%236d4aff' stroke-width='3'%3E%3Ccircle cx='19' cy='19' r='16' stroke-opacity='.25'/%3E%3Cpath d='M35 19c0-8.8-7.2-16-16-16'%3E%3CanimateTransform attributeName='transform' type='rotate' from='0 19 19' to='360 19 19' dur='.8s' repeatCount='indefinite'/%3E%3C/path%3E%3C/g%3E%3C/svg%3E") center no-repeat; }
.checker { background-color: #fff; background-image: linear-gradient(45deg, #e9eaf0 25%, transparent 25%), linear-gradient(-45deg, #e9eaf0 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #e9eaf0 75%), linear-gradient(-45deg, transparent 75%, #e9eaf0 75%); background-size: 18px 18px; background-position: 0 0, 0 9px, 9px -9px, -9px 0; }

/* step 2 */
.split { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; }
.toolbar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.toolbar .sep { width: 1px; height: 22px; background: var(--line); margin: 0 4px; }
.crop-wrap { height: calc(100vh - 290px); min-height: 420px; background: #2a2d3a; border-radius: 8px; overflow: hidden; }
.crop-wrap img { display: block; max-width: 100%; }
.crop-wrap.eyedrop, .crop-wrap.eyedrop * { cursor: crosshair !important; }
.hint { margin: 8px 0 0; }
.settings-panel { margin-bottom: 0; max-height: calc(100vh - 150px); overflow: auto; }
.choice { display: grid; gap: 6px; }
.choice label { display: flex; gap: 8px; align-items: flex-start; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; }
.choice label:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.choice input { margin-top: 3px; accent-color: var(--accent); }
.choice span { display: grid; }
.choice small { color: var(--muted); font-size: 11.5px; }
.sub-opts { padding: 4px 2px 0 6px; border-left: 2px solid var(--accent-soft); margin: 8px 0 4px; }
.color-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.swatch { width: 26px; height: 26px; border-radius: 6px; border: 1px solid var(--line); background: repeating-linear-gradient(45deg, #ddd 0 4px, #fff 4px 8px); }
.progress { margin-top: 10px; }
.progress .bar { height: 8px; background: #eceef4; border-radius: 99px; overflow: hidden; }
.progress .bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #7d5cff, #4f2fe6); transition: width .3s; }
.progress .msg { display: block; margin-top: 6px; font-size: 12.5px; color: var(--muted); }
.result-panel { margin-top: 16px; }
.result-flex { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; }
.result-view { border-radius: 8px; min-height: 360px; max-height: 70vh; display: grid; place-items: center; padding: 16px; border: 1px solid var(--line); }
.result-view img { max-width: 100%; max-height: calc(70vh - 32px); object-fit: contain; }
.bg-toggle { display: flex; gap: 4px; }
.bg-toggle button { width: 28px; height: 28px; border-radius: 6px; border: 1px solid var(--line); cursor: pointer; background: #fff; font-size: 14px; }
.bg-toggle button.active { outline: 2px solid var(--accent); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; font-size: 13px; margin-bottom: 8px; }
.kv span:nth-child(odd) { color: var(--muted); }

/* step 3 */
.layout3 { display: grid; grid-template-columns: 280px minmax(0, 1fr) 280px; gap: 16px; align-items: start; }
.layout3 .panel { margin-bottom: 0; }
.side-left, .side-right { max-height: calc(100vh - 150px); overflow: auto; }
.tpl-pick { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.tpl-pick .tp { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; cursor: pointer; background: #f3f4f8; font-size: 11px; text-align: center; }
.tpl-pick .tp img { width: 100%; aspect-ratio: 1; object-fit: contain; display: block; background: #fff; }
.tpl-pick .tp span { display: block; padding: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tpl-pick .tp.active { border-color: var(--accent); outline: 2px solid var(--accent-soft); }
.tpl-pick .tp .blank { aspect-ratio: 1; display: grid; place-items: center; font-size: 22px; color: var(--muted); background: #fff; }
#size-preset { width: 100%; }
.dims { display: grid; grid-template-columns: 1fr auto 1fr 64px; gap: 6px; align-items: end; margin-top: 8px; }
.dims label { display: grid; font-size: 11px; color: var(--muted); gap: 2px; }
.dims input { width: 100%; }
.dims span { padding-bottom: 9px; color: var(--muted); }
.bg-row { display: flex; gap: 14px; flex-wrap: wrap; }
.asset-strip { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.asset-strip .as { border: 1px solid var(--line); border-radius: 8px; aspect-ratio: 1; padding: 4px; cursor: pointer; display: grid; place-items: center; }
.asset-strip .as:hover { border-color: var(--accent); }
.asset-strip .as img { max-width: 100%; max-height: 100%; object-fit: contain; }
.stage { height: calc(100vh - 250px); min-height: 460px; display: grid; place-items: center; background: #e8e9ef; border-radius: 8px; overflow: hidden; }
.stage-inner { box-shadow: 0 2px 18px rgba(0,0,0,.18); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: #fff; padding: 7px 18px; font: inherit; font-weight: 600; cursor: pointer; color: var(--muted); }
.seg button.active { background: var(--accent); color: #fff; }
.done-box { margin-top: 10px; padding: 10px; border-radius: 8px; background: #eafaf0; border: 1px solid #bfe9cf; font-size: 13px; }
.done-box a { color: var(--ok); font-weight: 700; }

/* templates */
.tpl-grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.tpl-grid .card { cursor: default; }

/* modal & toast */
.modal { position: fixed; inset: 0; background: rgba(15,17,30,.5); display: grid; place-items: center; z-index: 50; }
.modal[hidden] { display: none; }
.modal-card { background: #fff; border-radius: 12px; padding: 18px; width: min(900px, 94vw); max-height: 92vh; overflow: auto; }
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: #1d2130; color: #fff; padding: 10px 18px; border-radius: 10px; z-index: 60; max-width: 90vw; box-shadow: 0 8px 30px rgba(0,0,0,.25); }
.toast.error { background: var(--danger); }

/* login */
.login-body { display: grid; place-items: center; min-height: 100vh; background: linear-gradient(135deg, #efeaff, #f4f5f8); }
.login-card { background: #fff; padding: 32px; border-radius: 14px; box-shadow: var(--shadow); width: 340px; display: grid; gap: 12px; }
.login-card .brand { font-size: 20px; }
.login-card p { margin: 0; }

@media (max-width: 1200px) {
  .layout3 { grid-template-columns: 240px minmax(0, 1fr); }
  .side-right { grid-column: 1 / -1; max-height: none; }
  .split { grid-template-columns: 1fr; }
  .settings-panel { max-height: none; }
  .result-flex { grid-template-columns: 1fr; }
}
