:root {
  --bg: #f6f7fb; --bg-2: #ffffff; --bg-3: #eef0f6; --text: #1b1f2a; --muted: #6b7280;
  --border: #e3e6ee; --accent: #d9363e; --accent-2: #b52b32; --accent-soft: #fdecec;
  --ok: #16a34a; --warn: #d97706; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 6px 20px -8px rgba(16,24,40,.12);
  --radius: 12px; --font: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1117; --bg-2: #171a23; --bg-3: #1f2330; --text: #e7e9f0; --muted: #9aa1b2;
    --border: #2a2f3d; --accent: #ef5a61; --accent-2: #ff7a80; --accent-soft: #3a1f22;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px -8px rgba(0,0,0,.6);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font-family: var(--font); background: var(--bg); color: var(--text); line-height: 1.45; min-height: 100vh; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0 0 .4rem; line-height: 1.2; }
h1 { font-size: 1.9rem; letter-spacing: -.01em; }
h2 { font-size: 1.25rem; }
p { margin: 0 0 .8rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hidden { display: none !important; }
.tight { margin: 0; }
.about { margin-top: 2.5rem; }

/* header */
.topbar { display: flex; align-items: center; justify-content: space-between; padding: .8rem 1.25rem; background: var(--bg-2); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.brand { display: flex; align-items: center; gap: .55rem; font-weight: 700; font-size: 1.1rem; color: var(--text); }
.brand .logo { width: 28px; height: 28px; border-radius: 8px; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: .8rem; font-weight: 800; }
.brand:hover { text-decoration: none; }
.topbar nav { display: flex; gap: .3rem; }
.topbar nav a, .topbar nav button { padding: .4rem .7rem; border-radius: 8px; color: var(--muted); background: none; border: 0; cursor: pointer; }
.topbar nav a:hover, .topbar nav button:hover { background: var(--bg-3); color: var(--text); text-decoration: none; }

.wrap { max-width: 1100px; margin: 0 auto; padding: 1.5rem 1.25rem 3rem; }
.hero { text-align: center; padding: 1.5rem 0 1.25rem; }
.hero p { max-width: 640px; margin: .4rem auto 0; color: var(--muted); }

/* tool grid */
.group-title { margin: 1.6rem 0 .6rem; font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: .9rem; }
.card { display: flex; flex-direction: column; gap: .45rem; padding: 1rem; background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); box-shadow: var(--shadow); transition: transform .12s, border-color .12s; }
.card:hover { transform: translateY(-2px); border-color: var(--accent); text-decoration: none; }
.card .icon { width: 40px; height: 40px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; }
.card .icon svg { width: 22px; height: 22px; }
.card h3 { font-size: 1rem; margin: 0; }
.card p { margin: 0; color: var(--muted); font-size: .85rem; }

/* tool page layout */
.tool-head { display: flex; align-items: center; gap: .9rem; margin-bottom: 1rem; }
.tool-head .icon { width: 46px; height: 46px; border-radius: 12px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; flex: none; }
.tool-head .icon svg { width: 26px; height: 26px; }
.layout { display: grid; grid-template-columns: 1fr 320px; gap: 1rem; align-items: start; }
@media (max-width: 860px) { .layout { grid-template-columns: 1fr; } }
.panel { background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); }
.panel + .panel { margin-top: 1rem; }
.panel h2 { font-size: 1rem; margin-bottom: .7rem; }
.side { position: sticky; top: 4.5rem; }

/* dropzone */
.drop { border: 2px dashed var(--border); border-radius: var(--radius); padding: 2.2rem 1rem; text-align: center; background: var(--bg-2); cursor: pointer; transition: border-color .12s, background .12s; }
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop strong { display: block; font-size: 1.05rem; margin-bottom: .2rem; }
.drop input { display: none; }
.filelist { list-style: none; margin: .8rem 0 0; padding: 0; display: flex; flex-direction: column; gap: .4rem; }
.filelist li { display: flex; align-items: center; gap: .6rem; padding: .5rem .7rem; background: var(--bg-3); border-radius: 8px; }
.filelist li .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.filelist li .handle { cursor: grab; color: var(--muted); }
.filelist li .rm { background: none; border: 0; cursor: pointer; color: var(--muted); padding: .2rem; }
.filelist li .rm:hover { color: var(--accent); }
.sortable-ghost { opacity: .4; }

/* forms */
.field { display: flex; flex-direction: column; gap: .3rem; margin-bottom: .75rem; }
.field label { font-size: .85rem; font-weight: 600; }
.field .help { font-size: .78rem; color: var(--muted); }
.field input[type=text], .field input[type=number], .field input[type=password], .field select, .field textarea { padding: .5rem .6rem; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); width: 100%; }
.field input[type=color] { width: 44px; height: 32px; padding: 0; border: 1px solid var(--border); border-radius: 6px; background: none; }
.field input[type=range] { width: 100%; }
.row { display: flex; gap: .6rem; align-items: center; }
.row > * { flex: 1; }
.check { display: flex; align-items: center; gap: .5rem; margin-bottom: .55rem; font-size: .9rem; }
.check input { width: 16px; height: 16px; }
.seg { display: flex; flex-wrap: wrap; gap: .3rem; }
.seg button { padding: .4rem .7rem; border: 1px solid var(--border); background: var(--bg); border-radius: 8px; cursor: pointer; font-size: .85rem; }
.seg button.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; padding: .65rem 1.1rem; border-radius: 10px; border: 1px solid var(--border); background: var(--bg-2); cursor: pointer; font-weight: 600; }
.btn:hover { background: var(--bg-3); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.big { width: 100%; padding: .85rem; font-size: 1.05rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.sm { padding: .35rem .6rem; font-size: .85rem; }

/* progress / result */
.progress { height: 8px; background: var(--bg-3); border-radius: 4px; overflow: hidden; margin: .6rem 0; }
.progress i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .15s; }
.status { font-size: .9rem; color: var(--muted); }
.result { border-left: 4px solid var(--ok); }
.result.err { border-left-color: var(--accent); }
.downloads { display: flex; flex-direction: column; gap: .4rem; margin: .6rem 0; }
.stats { display: grid; grid-template-columns: auto 1fr; gap: .2rem .8rem; font-size: .85rem; margin: .5rem 0; }
.stats dt { color: var(--muted); }
.stats dd { margin: 0; }
.toast { position: fixed; bottom: 1.2rem; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: .6rem 1rem; border-radius: 10px; box-shadow: var(--shadow); z-index: 50; max-width: 90vw; }

/* thumbnails */
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: .7rem; }
.thumb { position: relative; background: var(--bg-3); border: 2px solid transparent; border-radius: 8px; padding: .4rem; text-align: center; cursor: pointer; user-select: none; }
.thumb.sel { border-color: var(--accent); }
.thumb canvas { max-width: 100%; height: auto; display: block; margin: 0 auto; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.2); transition: transform .15s; }
.thumb .n { font-size: .75rem; color: var(--muted); margin-top: .3rem; }
.thumb .acts { position: absolute; top: .4rem; right: .4rem; display: none; gap: .2rem; }
.thumb:hover .acts { display: flex; }
.thumb .acts button { width: 26px; height: 26px; border-radius: 6px; border: 0; background: rgba(0,0,0,.65); color: #fff; cursor: pointer; display: grid; place-items: center; }
.thumb .acts button svg { width: 14px; height: 14px; }
.thumb.placeholder canvas { min-height: 120px; }
.thumb-tools { display: flex; gap: .4rem; flex-wrap: wrap; margin-bottom: .7rem; }

/* page editor */
.editor-bar { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; margin-bottom: .6rem; }
.editor-bar .sp { flex: 1; }
.editor-bar button { padding: .35rem .55rem; border: 1px solid var(--border); background: var(--bg); border-radius: 8px; cursor: pointer; display: inline-flex; align-items: center; gap: .3rem; font-size: .85rem; }
.editor-bar button.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.editor-bar button svg { width: 16px; height: 16px; }
.editor-bar input[type=color] { width: 32px; height: 30px; padding: 0; border: 1px solid var(--border); border-radius: 6px; background: none; }
.editor-bar input[type=range] { width: 90px; }
.editor-bar select { padding: .3rem; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); }
.stage-wrap { overflow: auto; background: var(--bg-3); border-radius: 8px; padding: .8rem; max-height: 75vh; }
.stage { position: relative; margin: 0 auto; width: max-content; box-shadow: 0 2px 8px rgba(0,0,0,.25); }
.stage canvas { display: block; }
.stage .overlay { position: absolute; inset: 0; touch-action: none; }
.stage .overlay.pen { cursor: crosshair; }
.stage textarea.txtedit { position: absolute; border: 1px dashed var(--accent); background: rgba(255,255,255,.85); color: #000; padding: 2px; resize: both; outline: none; font-family: Helvetica, Arial, sans-serif; line-height: 1.15; overflow: hidden; }
.pager { display: flex; align-items: center; justify-content: center; gap: .6rem; margin-top: .6rem; font-size: .9rem; }
.pager button { padding: .3rem .6rem; border: 1px solid var(--border); background: var(--bg); border-radius: 8px; cursor: pointer; }

/* login */
.login { max-width: 380px; margin: 4rem auto; }
.footer { text-align: center; color: var(--muted); font-size: .8rem; margin-top: 3rem; }
