:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #1d2330;
  --muted: #677084;
  --border: #dde1e8;
  --accent: #e5322d;
  --accent-hover: #c92823;
  --accent-soft: #fdecea;
  --select: #2f6fed;
  --select-soft: #e6eefd;
  --ok: #1f9d55;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 30, 50, .06), 0 4px 16px rgba(20, 30, 50, .06);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151b;
    --surface: #1b1f27;
    --surface-2: #232833;
    --text: #e7e9ee;
    --muted: #9aa2b2;
    --border: #2e3440;
    --accent-soft: #3a1d1c;
    --select: #6b9cff;
    --select-soft: #1f2b45;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--select); }
h1, h2, h3 { line-height: 1.25; }
.wrap { max-width: 1160px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; border-radius: 8px; padding: 9px 16px; cursor: pointer;
  background: var(--accent); color: #fff; font: inherit; font-weight: 600; text-decoration: none;
}
.btn:hover { background: var(--accent-hover); }
.btn:disabled { opacity: .45; cursor: default; }
.btn-small { padding: 6px 12px; font-size: 14px; }
.btn-big { padding: 14px 32px; font-size: 18px; border-radius: 10px; }
.btn-ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-ghost.danger { color: var(--accent); }
.linklike { background: none; border: 0; color: var(--select); cursor: pointer; padding: 0; font: inherit; text-decoration: underline; }

/* ---------- header / footer ---------- */
.site-header { background: var(--surface); border-bottom: 1px solid var(--border); }
.header-row { display: flex; align-items: center; justify-content: space-between; height: 56px; gap: 12px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 18px; color: var(--text); text-decoration: none; }
.brand-mark { width: 28px; height: 28px; border-radius: 7px; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: 15px; }
.header-nav { display: flex; align-items: center; gap: 18px; }
.header-nav a:not(.btn) { color: var(--text); text-decoration: none; font-weight: 500; }
.header-nav a:not(.btn):hover { color: var(--accent); }
.site-footer { border-top: 1px solid var(--border); margin-top: 48px; padding: 24px 0; color: var(--muted); font-size: 14px; }
.footer-row { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 12px; }
.footer-row nav { display: flex; gap: 16px; }
.footer-row a { color: var(--muted); }

/* ---------- landing ---------- */
.hero { padding: 48px 0 32px; text-align: center; }
.hero h1 { font-size: clamp(28px, 4vw, 42px); margin: 0 0 12px; }
.lead { font-size: 18px; color: var(--muted); max-width: 680px; margin: 0 auto 28px; }
.dropzone {
  max-width: 720px; margin: 0 auto; padding: 40px 20px; border: 2px dashed var(--border); border-radius: 16px;
  background: var(--surface); transition: border-color .15s, background .15s;
}
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.dropzone p { color: var(--muted); margin: 12px 0 0; }
.progress { margin: 20px auto 0; max-width: 420px; height: 26px; background: var(--surface-2); border-radius: 13px; position: relative; overflow: hidden; }
.progress .bar { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.progress-text { position: absolute; inset: 0; display: grid; place-items: center; font-size: 13px; font-weight: 600; }
.section-title { margin: 40px 0 16px; }
.tool-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px; }
.tool-card {
  display: flex; flex-direction: column; gap: 4px; padding: 18px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); text-decoration: none; transition: transform .1s, box-shadow .1s;
}
.tool-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.tool-card span:last-child { color: var(--muted); font-size: 14px; }
.tool-icon { width: 36px; height: 36px; border-radius: 9px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-size: 19px; margin-bottom: 6px; }
.explain { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 24px; margin-top: 48px; }
.explain p { color: var(--muted); }
.content-cols { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 32px; }
.steps li { margin-bottom: 6px; }
.faq details { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 12px 16px; margin-bottom: 8px; }
.faq summary { cursor: pointer; font-weight: 600; }
.prose { max-width: 760px; }
.side { position: relative; }
.side .ad { position: sticky; top: 16px; }

/* ---------- ads: space reserved so nothing jumps ---------- */
.ad { margin: 24px auto; text-align: center; }
.ad-label { display: block; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 4px; }
.ad-banner { min-height: 110px; max-width: 970px; }
.ad-sidebar { min-height: 620px; width: 300px; margin: 0; }
.ad-download { min-height: 270px; margin: 12px 0 0; }
.ad-placeholder {
  border: 1px dashed var(--border); border-radius: 8px; color: var(--muted); display: grid; place-items: center;
  font-size: 13px; height: 90px;
}
.ad-sidebar .ad-placeholder { height: 600px; }
.ad-download .ad-placeholder { height: 250px; }

/* ---------- workspace app: files | preview | processing ---------- */
.app-body { height: 100vh; display: flex; flex-direction: column; }
.app-body .site-footer { display: none; }
.app { flex: 1; min-height: 0; display: grid; grid-template-columns: 300px minmax(0, 1fr) 360px; }
.app.drop-over { outline: 3px dashed var(--accent); outline-offset: -6px; }
.col { min-height: 0; min-width: 0; overflow-y: auto; display: flex; flex-direction: column; }
.col-files { background: var(--surface); border-right: 1px solid var(--border); padding: 14px; gap: 10px; }
.col-pipe { background: var(--surface); border-left: 1px solid var(--border); padding: 14px; gap: 12px; }
.col-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.col-head h2 { margin: 0; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.col-head > div { display: flex; gap: 6px; }
.count { display: inline-grid; place-items: center; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 11px; background: var(--accent); color: #fff; font-size: 12px; font-weight: 700; }
.count:empty { display: none; }
.small { font-size: 12px; font-weight: 400; }
.pulse { animation: pulse .6s ease-out; }
@keyframes pulse { 30% { transform: scale(1.12); color: var(--accent); } }
.simple-only { display: none; }
.btn-light { background: #fff; color: var(--accent); }
.btn-light:hover { background: #fff3f2; }

/* files */
.doc-list { list-style: none; margin: 0; padding: 0; flex: 1; min-height: 60px; overflow-y: auto; }
.doc { border-radius: 8px; }
.doc-row { display: flex; align-items: center; gap: 4px; padding: 6px 4px; border-radius: 8px; border: 1px solid transparent; }
.doc-row:hover { background: var(--surface-2); }
.doc.active > .doc-row { border-color: var(--select); background: var(--select-soft); }
.doc.is-new > .doc-row { animation: flash 2s ease-out; }
@keyframes flash { from { background: #fff4c2; } }
.tree { width: 22px; height: 22px; flex: none; border: 1px solid var(--border); border-radius: 5px; background: var(--surface); color: var(--text); cursor: pointer; font-weight: 700; line-height: 1; padding: 0; }
.tree:hover { border-color: var(--select); color: var(--select); }
.tree-sp { width: 22px; flex: none; }
.doc-main { flex: 1; min-width: 0; cursor: pointer; display: flex; flex-direction: column; padding-left: 4px; }
.doc-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-meta { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 15px; padding: 4px 6px; border-radius: 6px; text-decoration: none; flex: none; }
.icon-btn:hover { background: var(--border); color: var(--text); }
.icon-btn.add { color: var(--accent); font-weight: 700; }
.icon-btn.add:hover { background: var(--accent); color: #fff; }
.page-list { list-style: none; margin: 2px 0 6px 26px; padding: 0 0 0 8px; border-left: 2px solid var(--border); }
.pg { display: flex; align-items: center; gap: 8px; padding: 3px 4px; border-radius: 6px; cursor: pointer; font-size: 13px; }
.pg:hover { background: var(--surface-2); }
.pg.selected { background: var(--select-soft); }
.pg.active { outline: 2px solid var(--select); outline-offset: -2px; }
.pg img { width: 30px; height: 40px; object-fit: contain; background: #fff; border: 1px solid var(--border); flex: none; }
.pg span { flex: 1; }
.sortable-chosen.doc, .sortable-chosen.pg { opacity: .6; }
.empty-docs { border: 2px dashed var(--border); border-radius: 10px; padding: 24px 12px; text-align: center; color: var(--muted); }
.col-foot { display: flex; flex-direction: column; gap: 4px; }
.usage { font-size: 12px; color: var(--muted); }
.usage-bar { height: 5px; background: var(--surface-2); border-radius: 3px; overflow: hidden; margin-bottom: 4px; }
#usage-fill { height: 100%; background: var(--accent); width: 0; }
.ws-link { font-size: 12px; color: var(--muted); margin: 0; }

/* preview */
.col-preview { padding: 16px 20px; }
.preview-empty { max-width: 520px; margin: 8vh auto; color: var(--muted); }
.preview-empty h2 { color: var(--text); }
.how { padding-left: 20px; }
.how li { margin-bottom: 10px; }
.preview { display: flex; flex-direction: column; gap: 10px; min-height: 0; flex: 1; }
.preview-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.preview-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preview-nav { display: flex; gap: 4px; }
.preview-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.preview-stage { flex: 1; min-height: 300px; display: flex; align-items: flex-start; justify-content: center; background: var(--surface-2); border-radius: 10px; padding: 16px; overflow: auto; }
.preview-stage img { max-width: 100%; max-height: calc(100vh - 230px); background: #fff; box-shadow: 0 2px 12px rgba(0, 0, 0, .18); transition: opacity .15s; }
.preview-stage img.loading { opacity: .35; }

/* processing */
.pipe-items { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.item { display: flex; align-items: center; gap: 8px; padding: 6px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); cursor: grab; position: relative; }
.item:hover { border-color: var(--select); }
.item.sortable-ghost, .pipe-items .sortable-ghost { opacity: .4; }
.item-no { width: 22px; height: 22px; flex: none; border-radius: 50%; background: var(--accent); color: #fff; font-size: 12px; font-weight: 700; display: grid; place-items: center; }
.item-thumb { width: 38px; height: 50px; flex: none; display: grid; place-items: center; overflow: hidden; }
.item-thumb img { max-width: 100%; max-height: 100%; background: #fff; border: 1px solid var(--border); transition: transform .2s; }
.item.multi .item-thumb img { box-shadow: 3px 3px 0 -1px var(--bg), 3px 3px 0 0 var(--border); }
.item-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.item-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-meta { font-size: 12px; color: var(--muted); }
.item-actions { display: flex; }
.pipe-items > li.doc, .pipe-items > li.pg { list-style: none; }   /* element being dropped from the left */
.pipe-empty { border: 2px dashed var(--border); border-radius: 10px; padding: 18px 12px; text-align: center; color: var(--muted); font-size: 14px; }
.pipe-steps-wrap { display: flex; flex-direction: column; gap: 10px; border-top: 1px solid var(--border); padding-top: 12px; }
.pipe-steps-wrap h3 { margin: 0; font-size: 15px; }
.pipe-steps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.step { border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; background: var(--bg); }
.step-head { display: flex; align-items: center; gap: 8px; }
.step-head b { flex: 1; }
.step-no { width: 22px; height: 22px; border-radius: 6px; background: var(--text); color: var(--surface); font-size: 12px; font-weight: 700; display: grid; place-items: center; }
.step-fields { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.fld { display: flex; flex-direction: column; gap: 2px; font-size: 12px; color: var(--muted); }
.fld.check { flex-direction: row; align-items: center; gap: 6px; color: var(--text); font-size: 13px; }
.fld input:not([type=checkbox]), .fld select, .add-step, .name-row input {
  font: inherit; font-size: 14px; padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text); width: 100%;
}
.step-help { margin: 6px 0 0; font-size: 12px; color: var(--muted); }
.add-step { cursor: pointer; border-style: dashed; color: var(--select); font-weight: 600; }
.output label { font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 2px; }
.name-row { display: flex; align-items: center; gap: 4px; }
.name-row .ext { color: var(--muted); font-size: 13px; white-space: nowrap; }
.pipe-summary { margin: 0; font-size: 13px; color: var(--muted); }
.pipe-summary:empty { display: none; }
.btn-run { width: 100%; }
.pipe-ad { margin-top: auto; padding-top: 8px; }
.pipe-ad .ad { margin: 0 auto; }
.col-pipe .ad-sidebar { min-height: 270px; width: 300px; }
.col-pipe .ad-sidebar .ad-placeholder { height: 250px; }
.danger-zone { color: var(--accent); }
.tabbar, .mobile-ad { display: none; }

/* simple mode: just the processing card, centered */
.simple-banner { display: flex; align-items: center; justify-content: center; gap: 14px; flex-wrap: wrap; padding: 9px 16px; background: linear-gradient(90deg, #e5322d, #c2185b); color: #fff; font-size: 14px; text-align: center; }
body.simple .app { grid-template-columns: minmax(0, 1fr); }
body.simple .col-files, body.simple .col-preview { display: none; }
body.simple .col-pipe { border: 0; background: var(--bg); align-items: center; padding: 24px 16px 40px; }
body.simple .col-pipe > * { width: min(760px, 100%); }
body.simple .simple-only { display: inline-flex; }
body.simple .simple-head h1 { margin: 0 0 4px; font-size: 28px; }
body.simple .simple-head p { margin: 0; }
body.simple .pipe-steps-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px; }
body.simple .pipe-steps-wrap h3 { display: none; }
body.simple .step-no { display: none; }
body.simple .step { border: 0; padding: 0; background: none; }
body.simple .pipe-ad > .ad { width: auto; }
.pipe-items.big { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 16px; }
.pipe-items.big .item { flex-direction: column; align-items: stretch; padding: 10px; background: var(--surface); }
.pipe-items.big .item-no { position: absolute; top: -10px; left: -10px; width: 28px; height: 28px; font-size: 14px; z-index: 2; }
.pipe-items.big .item-thumb { width: auto; height: auto; aspect-ratio: 1 / 1.3; background: var(--surface-2); border-radius: 6px; }
.pipe-items.big .item-thumb img { box-shadow: 0 1px 4px rgba(0, 0, 0, .2); }
.pipe-items.big .item-actions { position: absolute; top: 14px; right: 14px; gap: 2px; }
.pipe-items.big .item-actions .icon-btn { background: rgba(20, 25, 35, .7); color: #fff; width: 28px; height: 28px; padding: 0; }
.pipe-items.big .item-actions .icon-btn:hover { background: var(--accent); }


/* ---------- modal, toast, busy ---------- */
.modal { border: 0; border-radius: 14px; padding: 0; width: min(480px, calc(100vw - 32px)); background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0, 0, 0, .3); }
.modal::backdrop { background: rgba(10, 15, 25, .5); }
.modal form { padding: 20px 22px; }
.modal h3 { margin: 0 0 14px; font-size: 18px; overflow-wrap: anywhere; }
.modal label { display: block; margin-bottom: 12px; font-size: 14px; font-weight: 500; }
.modal label.radio, .modal label.check { display: flex; align-items: center; gap: 8px; font-weight: 400; flex-wrap: wrap; }
.modal input:not([type=radio]):not([type=checkbox]), .modal select {
  display: block; width: 100%; margin-top: 4px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 7px;
  font: inherit; background: var(--bg); color: var(--text);
}
.modal label.radio input:not([type=radio]) { display: inline-block; width: auto; margin: 0; padding: 4px 8px; }
.modal input.num { width: 80px !important; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.merge-list { list-style: none; padding: 0; margin: 0 0 14px; max-height: 320px; overflow-y: auto; }
.merge-list li { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 7px; margin-bottom: 6px; background: var(--bg); cursor: grab; }
.grip { color: var(--muted); }
.result-list { padding-left: 18px; }
.result-list li { margin-bottom: 4px; overflow-wrap: anywhere; }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: #1d2330; color: #fff; padding: 10px 18px; border-radius: 8px; z-index: 100; max-width: calc(100vw - 32px); box-shadow: var(--shadow); }
.toast.error { background: var(--accent); }
.busy { position: fixed; inset: 0; background: rgba(10, 15, 25, .45); z-index: 90; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; color: #fff; font-weight: 600; }
.spinner { width: 42px; height: 42px; border: 4px solid rgba(255, 255, 255, .3); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.brand-section { color: var(--muted); text-decoration: none; font-weight: 600; font-size: 14px; border-left: 1px solid var(--border); padding-left: 10px; margin-right: auto; margin-left: 2px; }
.header-row .brand { margin-right: 0; }
@media (max-width: 860px) { .brand-section { display: none; } }


/* ---------- responsive ---------- */
@media (max-width: 1200px) {
  .app { grid-template-columns: 260px minmax(0, 1fr) 320px; }
  .col-pipe .ad-sidebar { width: 100%; }
}
@media (max-width: 860px) {
  .header-nav a:not(.btn) { display: none; }
  .content-cols { grid-template-columns: 1fr; }
  .side { display: none; }
  .app-body { height: auto; min-height: 100vh; padding-bottom: 56px; }
  .app { grid-template-columns: minmax(0, 1fr); }   /* minmax(0,…): long file names must truncate, not widen the page */
  .col { overflow: visible; border: 0 !important; min-width: 0; }
  body:not(.simple)[data-tab="files"] .col-preview, body:not(.simple)[data-tab="files"] .col-pipe,
  body:not(.simple)[data-tab="preview"] .col-files, body:not(.simple)[data-tab="preview"] .col-pipe,
  body:not(.simple)[data-tab="pipe"] .col-files, body:not(.simple)[data-tab="pipe"] .col-preview { display: none; }
  .preview-stage img { max-height: none; }
  .tabbar { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: var(--surface); border-top: 1px solid var(--border); }
  body.simple .tabbar { display: none; }
  body.simple.app-body { padding-bottom: 0; }
  .tabbar button { flex: 1; padding: 14px 4px; background: none; border: 0; font: inherit; font-weight: 600; color: var(--muted); display: flex; justify-content: center; align-items: center; gap: 6px; }
  body[data-tab="files"] [data-tab-btn="files"], body[data-tab="preview"] [data-tab-btn="preview"], body[data-tab="pipe"] [data-tab-btn="pipe"] { color: var(--accent); box-shadow: inset 0 3px 0 var(--accent); }
  .mobile-ad { display: block; padding: 0 16px; }
  .mobile-ad .ad { margin: 8px auto; min-height: 60px; }
  .mobile-ad .ad-placeholder { height: 50px; }
  .pipe-items.big { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
  .pipe-ad { display: none; }   /* the bottom banner is enough on a phone */
}
.danger-link { color: var(--accent); font-size: 12px; align-self: flex-start; }

/* ---------- legal pages ---------- */
.legal h2 { margin-top: 32px; scroll-margin-top: 16px; }
.legal .updated { color: var(--muted); font-size: 14px; margin-top: -8px; }
.legal .toc { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px 16px; font-size: 14px; line-height: 1.9; }
.legal-table { width: 100%; border-collapse: collapse; font-size: 14px; margin: 8px 0 16px; display: block; overflow-x: auto; }
.legal-table th, .legal-table td { border: 1px solid var(--border); padding: 8px 10px; text-align: left; vertical-align: top; }
.legal-table th { background: var(--surface-2); }
.legal code { font-size: 13px; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; overflow-wrap: anywhere; }
.legal details { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px; margin-bottom: 8px; }
.legal summary { cursor: pointer; font-weight: 600; }
.contact-form { display: flex; flex-direction: column; gap: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 18px; margin: 16px 0 28px; }
.contact-form label { display: flex; flex-direction: column; gap: 4px; font-weight: 500; font-size: 14px; }
.contact-form input, .contact-form select, .contact-form textarea { font: inherit; padding: 9px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text); }
.contact-form .btn { align-self: flex-start; }
.cf-hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
.cf-result { margin: 0; padding: 10px 12px; border-radius: 8px; }
.cf-result.ok { background: #e7f6ec; color: #17603a; }
.cf-result.err { background: var(--accent-soft); color: var(--accent); }
