/* Folio — a quiet, dark PDF editor */

:root {
  --bg: #0a0a0b;
  --bg-raised: #101012;
  --surface: #151517;
  --surface-2: #1c1c1f;
  --surface-3: #26262a;
  --border: #212124;
  --border-2: #2d2d32;
  --text: #ededee;
  --text-2: #a1a1a9;
  --text-3: #6b6b74;
  --accent: #7d9bff;
  --accent-strong: #4a6cff;
  --accent-soft: rgba(125, 155, 255, 0.12);
  --danger: #ff6b70;
  --ok: #7fe0a6;
  --radius: 14px;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
  --font: 'Inter', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
main { flex: 1; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
button:disabled { cursor: default; }
input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.02em; }
p { margin: 0; }
.muted { color: var(--text-2); }
.small { font-size: 13px; }
.i { flex: none; display: block; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
::selection { background: rgba(125, 155, 255, 0.35); }

/* ---------- Top bar ---------- */
.topbar {
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  height: 64px;
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; letter-spacing: -0.02em; font-size: 16px; }
.brand-mark {
  width: 22px; height: 22px; border-radius: 6px; background: var(--text); position: relative; overflow: hidden;
}
.brand-mark::before {
  content: ''; position: absolute; left: 6px; top: 4px; width: 10px; height: 14px; background: var(--bg);
  clip-path: polygon(0 0, 65% 0, 100% 30%, 100% 100%, 0 100%);
}
.top-nav { display: flex; align-items: center; gap: 2px; }
.nav-link {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px; border-radius: 9px; font-size: 14px; color: var(--text-2);
  transition: color .15s, background .15s;
}
.nav-link:hover, .nav-link.active { color: var(--text); background: var(--surface); }
.menu-wrap { position: relative; }
.tools-menu {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 50;
  display: none; grid-template-columns: repeat(4, 170px); gap: 8px 12px;
  padding: 16px; background: var(--surface); border: 1px solid var(--border-2); border-radius: 16px; box-shadow: var(--shadow);
}
.tools-menu.open { display: grid; animation: pop .14s ease-out; }
.menu-title { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--text-3); padding: 4px 8px 6px; }
.menu-link { display: flex; align-items: center; gap: 9px; padding: 7px 8px; border-radius: 8px; font-size: 14px; color: var(--text-2); }
.menu-link:hover { background: var(--surface-2); color: var(--text); }
.footer { text-align: center; padding: 28px 20px 32px; font-size: 13px; color: var(--text-3); }
body.is-editor { overflow: hidden; }
body.is-editor .topbar, body.is-editor .footer { display: none; }

@keyframes pop { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }

/* ---------- Buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px; border-radius: 10px; font-size: 14px; font-weight: 500; white-space: nowrap;
  transition: background .15s, border-color .15s, opacity .15s, transform .1s;
}
.btn:active:not(:disabled) { transform: scale(.98); }
.btn-primary { background: var(--text); color: var(--bg); }
.btn-primary:hover:not(:disabled) { background: #fff; }
.btn-ghost { border: 1px solid var(--border-2); color: var(--text); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); }
.btn-sm { height: 34px; padding: 0 12px; font-size: 13px; gap: 6px; }
.btn:disabled { opacity: .35; }
.icon-btn {
  width: 34px; height: 34px; display: inline-grid; place-items: center; border-radius: 9px; color: var(--text-2);
  transition: background .15s, color .15s; flex: none;
}
.icon-btn:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.icon-btn.active { background: var(--surface-3); color: var(--text); }
.icon-btn.danger:hover { color: var(--danger); }
.icon-btn:disabled { opacity: .3; }
.icon-btn.flip .i { transform: scaleX(-1); }
.link-btn { font-size: 13px; color: var(--text-2); }
.link-btn:hover { color: var(--text); text-decoration: underline; text-underline-offset: 3px; }
.mini-btn {
  width: 26px; height: 26px; display: grid; place-items: center; border-radius: 7px;
  background: rgba(18, 18, 20, .92); border: 1px solid var(--border-2); color: var(--text-2);
}
.mini-btn:hover { color: var(--text); background: var(--surface-3); }
.mini-btn.danger:hover { color: var(--danger); }

.input, .select, textarea.input {
  width: 100%; height: 40px; padding: 0 12px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--border-2); outline: none;
  transition: border-color .15s, background .15s;
}
textarea.input { height: auto; padding: 10px 12px; resize: vertical; line-height: 1.5; }
.input:focus, .select:focus { border-color: var(--accent); background: var(--surface-2); }
.input::placeholder { color: var(--text-3); }
.select { appearance: none; padding-right: 28px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23a1a1a9' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 8px center; background-size: 14px; cursor: pointer; }
.num-wide { max-width: 120px; }
.color-input { width: 44px; height: 36px; padding: 2px; border-radius: 10px; border: 1px solid var(--border-2); background: var(--surface); cursor: pointer; }
input[type='range'] { accent-color: var(--text); }
.check { display: inline-flex; align-items: center; gap: 9px; font-size: 14px; color: var(--text-2); cursor: pointer; user-select: none; }
.check input { width: 16px; height: 16px; accent-color: var(--accent-strong); margin: 0; }
.checks { display: flex; flex-direction: column; gap: 10px; margin-top: 6px; }

.seg { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface); border: 1px solid var(--border); border-radius: 11px; flex-wrap: wrap; }
.seg button { height: 30px; padding: 0 12px; border-radius: 8px; font-size: 13px; color: var(--text-2); transition: background .15s, color .15s; white-space: nowrap; }
.seg button:hover { color: var(--text); }
.seg button.active { background: var(--surface-3); color: var(--text); }

/* Tooltips */
@media (hover: hover) {
  [data-tip] { position: relative; }
  [data-tip]:hover::after {
    content: attr(data-tip); position: absolute; top: calc(100% + 8px); left: 50%; transform: translateX(-50%);
    white-space: pre; background: #000; color: var(--text); border: 1px solid var(--border-2);
    font-size: 12px; font-weight: 500; line-height: 1; padding: 6px 8px; border-radius: 7px; z-index: 200; pointer-events: none;
    animation: pop .12s ease-out;
  }
}

/* ---------- Home ---------- */
.home { width: 100%; max-width: 880px; margin: 0 auto; padding: 72px 20px 40px; }
.hero { text-align: center; margin-bottom: 36px; }
.hero h1 { font-size: 48px; line-height: 1.05; letter-spacing: -0.035em; }
.hero p { margin-top: 14px; font-size: 16px; }

.dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  min-height: 300px; padding: 40px 24px; cursor: pointer;
  background: var(--bg-raised); border: 1.5px dashed var(--border-2); border-radius: 22px;
  transition: border-color .2s, background .2s, transform .2s;
}
.dropzone:hover { border-color: #44444b; background: #121214; }
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); transform: scale(1.005); }
.dz-icon { width: 52px; height: 52px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); color: var(--text); margin-bottom: 18px; transition: transform .2s; }
.dropzone:hover .dz-icon, .dropzone.over .dz-icon { transform: translateY(-3px); }
.dz-title { font-size: 17px; font-weight: 500; }
.dz-hint { font-size: 14px; color: var(--text-3); margin-top: 6px; }
.dropzone.compact { min-height: 0; padding: 18px; border-radius: 14px; }
.dropzone.compact .dz-icon { width: 36px; height: 36px; margin-bottom: 8px; }
.dropzone.compact .dz-title { font-size: 13px; color: var(--text-2); }

.tools-index { margin-top: 72px; display: grid; grid-template-columns: repeat(4, 1fr); gap: 32px 20px; }
.tool-group h2 { font-size: 11px; font-weight: 500; text-transform: uppercase; letter-spacing: .09em; color: var(--text-3); margin: 0 0 10px 10px; }
.tool-links { display: flex; flex-direction: column; gap: 1px; }
.tool-link { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 9px; font-size: 14px; color: var(--text-2); transition: background .15s, color .15s; }
.tool-link:hover { background: var(--surface); color: var(--text); }
.tool-link .i { color: var(--text-3); transition: color .15s; }
.tool-link:hover .i { color: var(--text); }

/* ---------- Tool pages ---------- */
.tool-page { width: 100%; max-width: 900px; margin: 0 auto; padding: 56px 20px 40px; }
.tool-head { margin-bottom: 28px; }
.tool-head h1 { font-size: 34px; letter-spacing: -0.03em; }
.tool-head p { margin-top: 8px; font-size: 15px; }
.privacy-note { display: flex; align-items: center; justify-content: center; gap: 7px; margin-top: 16px; font-size: 13px; color: var(--text-3); }
.workspace { display: flex; flex-direction: column; gap: 22px; animation: pop .2s ease-out; }
.ws-hint { font-size: 13px; margin-bottom: -10px; }
.ws-controls { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.opts { flex: 1; display: flex; justify-content: flex-end; min-width: 240px; }
.opts .field { width: 100%; max-width: 360px; }
.opt-row { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }

.file-chip { display: flex; align-items: center; gap: 12px; padding: 12px 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.file-chip-icon { width: 36px; height: 36px; border-radius: 9px; display: grid; place-items: center; background: var(--surface-2); color: var(--text-2); flex: none; }
.file-chip-text { flex: 1; min-width: 0; }
.file-chip-name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.action-bar {
  position: sticky; bottom: 16px; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 10px 10px 10px 18px; background: rgba(21, 21, 23, .86); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--border-2); border-radius: 16px; font-size: 14px;
}

.field { display: flex; flex-direction: column; gap: 7px; min-width: 0; }
.field-label { font-size: 13px; color: var(--text-2); font-weight: 500; }
.field-hint { font-size: 12px; color: var(--text-3); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 20px; }
.form-stack { display: flex; flex-direction: column; gap: 20px; }
.form-stack.narrow { max-width: 380px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: end; }
.split-layout { display: grid; grid-template-columns: 1fr 280px; gap: 36px; align-items: start; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
.card { position: relative; padding: 10px 10px 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); cursor: grab; user-select: none; transition: border-color .15s, opacity .15s; touch-action: none; }
.card:hover { border-color: var(--border-2); }
.card-thumb { height: 170px; display: flex; align-items: center; justify-content: center; border-radius: 8px; background: var(--bg-raised); overflow: hidden; }
.card-thumb canvas, .card-thumb img { max-width: 100%; max-height: 100%; display: block; box-shadow: 0 2px 10px rgba(0, 0, 0, .4); pointer-events: none; }
.card-thumb canvas { width: auto; height: auto; max-width: 92%; max-height: 92%; }
.card-name { margin-top: 10px; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-sub { font-size: 12px; color: var(--text-3); }
.card-order { position: absolute; top: 16px; left: 16px; z-index: 1; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 11px; display: grid; place-items: center; font-size: 11px; font-weight: 600; background: rgba(10, 10, 11, .85); color: var(--text-2); }
.card-x { position: absolute; top: 14px; right: 14px; z-index: 1; opacity: 0; transition: opacity .15s; }
.card:hover .card-x { opacity: 1; }
@media (hover: none) { .card-x { opacity: 1; } }
.cards .dropzone.compact { min-height: 170px; border-radius: var(--radius); }
.dragging { opacity: .25; }
.drag-ghost { position: fixed !important; left: 0; top: 0; margin: 0 !important; z-index: 1000; pointer-events: none; opacity: .95; box-shadow: var(--shadow); }
body.is-dragging, body.is-dragging * { cursor: grabbing !important; user-select: none; }

.pgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(124px, 1fr)); gap: 18px 14px; }
.pcell { user-select: none; }
.pcell-img { position: relative; aspect-ratio: 3 / 4; background: #fff; border-radius: 4px; overflow: hidden; outline: 2px solid transparent; outline-offset: 3px; transition: outline-color .15s, transform .15s; box-shadow: 0 2px 10px rgba(0, 0, 0, .35); }
.pcell-img canvas { width: 100%; height: 100%; display: block; }
.pcell-num { text-align: center; font-size: 12px; color: var(--text-3); margin-top: 8px; }
.pgrid.selectable .pcell { cursor: pointer; }
.pgrid.selectable .pcell:hover .pcell-img { outline-color: var(--border-2); }
.pgrid.selectable .pcell.on .pcell-img { outline-color: var(--accent); }
.pcell-check { position: absolute; top: 6px; right: 6px; z-index: 1; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; background: rgba(0, 0, 0, .35); color: transparent; border: 1.5px solid rgba(255, 255, 255, .8); transition: background .15s; }
.pgrid:not(.selectable) .pcell-check { display: none; }
.pcell.on .pcell-check { background: var(--accent-strong); border-color: var(--accent-strong); color: #fff; }

.choice-list { display: flex; flex-direction: column; gap: 10px; }
.choice { display: flex; align-items: flex-start; gap: 14px; padding: 16px 18px; text-align: left; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); transition: border-color .15s, background .15s; }
.choice:hover { border-color: var(--border-2); }
.choice.active { border-color: var(--text-3); background: var(--surface-2); }
.choice-radio { width: 18px; height: 18px; border-radius: 50%; border: 1.5px solid var(--text-3); margin-top: 2px; flex: none; transition: border .15s; }
.choice.active .choice-radio { border: 5px solid var(--text); }
.choice-text { display: flex; flex-direction: column; gap: 2px; font-size: 14px; }
.choice-text strong { font-weight: 500; }
.result:empty { display: none; }
.result-card { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 20px 22px; background: var(--surface); border: 1px solid var(--border-2); border-radius: 16px; animation: pop .2s ease-out; }
.result-big { font-size: 32px; font-weight: 600; letter-spacing: -0.03em; color: var(--ok); line-height: 1.1; }

.preview { position: relative; align-self: start; overflow: hidden; border-radius: 4px; box-shadow: 0 4px 24px rgba(0, 0, 0, .45); background: #fff; }
.preview canvas { width: 100%; display: block; }
.preview-tag { position: absolute; font: 600 9px/1 Arial, sans-serif; color: #333; --m: 5px; }
.preview-tag[data-pos^='t'] { top: var(--m); }
.preview-tag[data-pos^='b'] { bottom: var(--m); }
.preview-tag[data-pos$='l'] { left: var(--m); }
.preview-tag[data-pos$='r'] { right: var(--m); }
.preview-tag[data-pos$='c'] { left: 50%; transform: translateX(-50%); }
.preview-wm { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; pointer-events: none; overflow: hidden; }
.preview-wm span { font-family: Arial, Helvetica, sans-serif; font-weight: 700; white-space: nowrap; display: inline-block; }
.preview-wm.tiled { flex-wrap: wrap; align-content: center; gap: 14px 22px; margin: -40%; }
.pos-grid { display: grid; grid-template-columns: repeat(3, 44px); gap: 6px; }
.pos { height: 34px; border-radius: 8px; background: var(--surface); border: 1px solid var(--border-2); display: flex; padding: 6px 8px; transition: border-color .15s; }
.pos span { width: 12px; height: 4px; border-radius: 2px; background: var(--text-3); }
.pos:nth-child(-n+3) { align-items: flex-start; }
.pos:nth-child(n+4) { align-items: flex-end; }
.pos:nth-child(3n+1) { justify-content: flex-start; }
.pos:nth-child(3n+2) { justify-content: center; }
.pos:nth-child(3n) { justify-content: flex-end; }
.pos.active { border-color: var(--text); }
.pos.active span { background: var(--text); }

.crop-stage { display: flex; justify-content: center; padding: 28px; background: var(--bg-raised); border: 1px solid var(--border); border-radius: 18px; }
.crop-holder { position: relative; display: inline-block; overflow: hidden; line-height: 0; box-shadow: 0 4px 24px rgba(0, 0, 0, .45); }
.crop-holder canvas { max-width: min(520px, 100%); max-height: 70vh; width: auto; height: auto; display: block; }
.crop-box { position: absolute; border: 1.5px solid var(--accent-strong); box-shadow: 0 0 0 9999px rgba(10, 10, 11, .62); cursor: move; touch-action: none; }
.crop-hd { position: absolute; width: 14px; height: 14px; background: #fff; border: 1.5px solid var(--accent-strong); border-radius: 3px; transform: translate(-50%, -50%); }
.crop-hd.nw { left: 0; top: 0; cursor: nwse-resize; } .crop-hd.n { left: 50%; top: 0; cursor: ns-resize; }
.crop-hd.ne { left: 100%; top: 0; cursor: nesw-resize; } .crop-hd.e { left: 100%; top: 50%; cursor: ew-resize; }
.crop-hd.se { left: 100%; top: 100%; cursor: nwse-resize; } .crop-hd.s { left: 50%; top: 100%; cursor: ns-resize; }
.crop-hd.sw { left: 0; top: 100%; cursor: nesw-resize; } .crop-hd.w { left: 0; top: 50%; cursor: ew-resize; }
.crop-nav { display: flex; align-items: center; justify-content: center; gap: 12px; font-size: 13px; margin-top: -8px; }

/* ---------- Modal, toast, busy ---------- */
.modal-wrap { position: fixed; inset: 0; z-index: 300; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(0, 0, 0, .6); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); opacity: 0; transition: opacity .15s; }
.modal-wrap.show { opacity: 1; }
.modal { max-width: 100%; max-height: calc(100vh - 32px); overflow: auto; background: #141416; border: 1px solid var(--border-2); border-radius: 18px; box-shadow: var(--shadow); transform: translateY(6px) scale(.99); transition: transform .15s; }
.modal-wrap.show .modal { transform: none; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 0 22px; }
.modal-head h3 { font-size: 16px; }
.modal-body { padding: 14px 22px 18px; display: flex; flex-direction: column; gap: 12px; }
.modal-body > div { display: flex; flex-direction: column; gap: 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 0 22px 20px; }

.toast { position: fixed; left: 50%; bottom: 28px; z-index: 400; transform: translate(-50%, 16px); opacity: 0; pointer-events: none; max-width: calc(100vw - 32px); padding: 11px 16px; border-radius: 12px; background: var(--text); color: var(--bg); font-size: 14px; font-weight: 500; box-shadow: var(--shadow); transition: opacity .2s, transform .2s; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: #2a1416; color: #ffb7ba; border: 1px solid #4a2226; }
.busy { position: fixed; inset: 0; z-index: 350; display: none; flex-direction: column; align-items: center; justify-content: center; gap: 16px; background: rgba(10, 10, 11, .7); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); font-size: 14px; color: var(--text-2); }
.busy.show { display: flex; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 2.5px solid var(--surface-3); border-top-color: var(--text); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Editor ---------- */
.ed { position: fixed; inset: 0; display: grid; grid-template-rows: auto 1fr; background: #0d0d0f; }
.ed-head { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px; height: 58px; padding: 0 12px; background: var(--bg); border-bottom: 1px solid var(--border); z-index: 30; }
.ed-left { display: flex; align-items: center; gap: 8px; min-width: 0; }
.ed-file { min-width: 0; }
.ed-name { display: block; font-size: 14px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 260px; }
.ed-right { justify-self: end; display: flex; align-items: center; gap: 4px; }
.sep { width: 1px; height: 20px; background: var(--border-2); margin: 0 4px; }
.ed-tools { display: flex; gap: 2px; padding: 3px; background: var(--surface); border: 1px solid var(--border); border-radius: 13px; }
.tool { position: relative; width: 38px; height: 34px; display: grid; place-items: center; border-radius: 9px; color: var(--text-2); transition: background .15s, color .15s; flex: none; }
.tool:hover { background: var(--surface-2); color: var(--text); }
.tool.active { background: var(--text); color: var(--bg); }
.tool-caret { position: absolute; right: 2px; bottom: 2px; opacity: .6; }
.popover { position: fixed; z-index: 60; transform: translateX(-50%); display: flex; gap: 2px; padding: 4px; background: var(--surface); border: 1px solid var(--border-2); border-radius: 13px; box-shadow: var(--shadow); animation: pop .12s ease-out; }

.ed-main { position: relative; display: grid; grid-template-columns: 172px 1fr; min-height: 0; }
.ed-props {
  position: absolute; top: 12px; left: 172px; right: 0; margin: 0 auto; width: max-content; z-index: 20;
  display: none; align-items: center; gap: 8px; height: 46px; padding: 0 8px 0 10px; max-width: calc(100% - 172px - 24px);
  background: rgba(21, 21, 23, .92); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--border-2); border-radius: 13px; box-shadow: 0 6px 24px rgba(0, 0, 0, .35); white-space: nowrap;
}
.ed-props.show { display: flex; animation: pop .14s ease-out; }
.ed-props .select { width: auto; height: 32px; font-size: 13px; padding-left: 10px; }
.ed-props .num { width: 58px; height: 32px; padding: 0 8px; border-radius: 9px; background: var(--surface); border: 1px solid var(--border-2); font-size: 13px; outline: none; }
.ed-props .num:focus { border-color: var(--accent); }
.ed-props .icon-btn { width: 32px; height: 32px; }
.ed-props .btn-sm { height: 32px; }
.prop-sep { width: 1px; height: 20px; background: var(--border-2); flex: none; }
.prop-label { font-size: 12px; color: var(--text-3); }
.prop-hint { font-size: 13px; color: var(--text-2); padding: 0 4px; }
.range { display: inline-flex; align-items: center; gap: 8px; }
.range input { width: 80px; }
.range-val { font-size: 12px; color: var(--text-2); min-width: 22px; font-variant-numeric: tabular-nums; }
.swatches { display: flex; align-items: center; gap: 6px; }
.sw { position: relative; width: 20px; height: 20px; border-radius: 50%; background: var(--c); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .16); flex: none; transition: transform .12s; }
.sw:hover { transform: scale(1.12); }
.sw.active { box-shadow: 0 0 0 2px var(--bg), 0 0 0 3.5px var(--text); }
.sw.none { background: linear-gradient(135deg, transparent 45%, var(--danger) 45%, var(--danger) 55%, transparent 55%), var(--surface-2); }
.sw.custom { background: conic-gradient(#ff5f5f, #ffd25f, #6dff8a, #5fd3ff, #8e6bff, #ff5fd2, #ff5f5f); overflow: hidden; cursor: pointer; }
.sw-custom { position: absolute; inset: -4px; opacity: 0; cursor: pointer; width: 30px; height: 30px; }

.ed-side { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--border); background: var(--bg); }
.thumbs { flex: 1; overflow-y: auto; padding: 16px 14px; display: flex; flex-direction: column; gap: 10px; }
.th { position: relative; padding: 6px; border-radius: 10px; cursor: pointer; user-select: none; touch-action: none; transition: background .15s; }
.th:hover { background: var(--surface); }
.th-img { width: 100%; background: #fff; border-radius: 3px; overflow: hidden; box-shadow: 0 1px 6px rgba(0, 0, 0, .4); outline: 2px solid transparent; outline-offset: 3px; transition: outline-color .15s; }
.th-img canvas { width: 100%; height: 100%; display: block; }
.th.active .th-img { outline-color: var(--accent); }
.th-num { text-align: center; font-size: 11px; color: var(--text-3); margin-top: 6px; }
.th.active .th-num { color: var(--text); }
.th-actions { position: absolute; top: 12px; right: 12px; display: none; flex-direction: column; gap: 4px; }
.th:hover .th-actions { display: flex; }
.side-actions { display: flex; gap: 6px; padding: 12px; border-top: 1px solid var(--border); }
.side-actions .btn { flex: 1; padding: 0 6px; }

.ed-scroll { overflow: auto; position: relative; padding: 76px 0 120px; overscroll-behavior: contain; scrollbar-gutter: stable; }
.ed-pages { display: flex; flex-direction: column; align-items: center; gap: 22px; padding: 0 36px; width: max-content; min-width: 100%; }
.pg { position: relative; flex: none; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .5), 0 10px 40px rgba(0, 0, 0, .4); user-select: none; -webkit-user-select: none; }
.pg-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.pg-forms { position: absolute; inset: 0; }
.pg-layer { position: absolute; inset: 0; touch-action: none; } /* no z-index: highlights must blend with the page */
.pg-hover { position: absolute; z-index: 3; display: none; pointer-events: none; border-radius: 2px; outline: 1.5px dashed var(--accent-strong); background: rgba(74, 108, 255, .08); }
.pg-hover.show { display: block; }
.ed[data-tool='edit'] .pg-layer { pointer-events: none; touch-action: auto; }
.ed[data-tool='edit'] .pg-layer .an { pointer-events: auto; touch-action: none; }
.ed[data-tool='edit'] .pg { cursor: text; }
.ed[data-tool='edit'] .an:not(.editing) { cursor: move; }
.ed[data-tool='draw'] .pg-layer, .ed[data-tool='highlight'] .pg-layer,
.ed[data-tool='whiteout'] .pg-layer, .ed[data-tool='note'] .pg-layer { cursor: crosshair; }

.ff { position: absolute; margin: 0; padding: 0 3px; border: 1px solid rgba(74, 108, 255, .35); border-radius: 2px; background: rgba(125, 155, 255, .12); color: #111; font-family: Arial, Helvetica, sans-serif; outline: none; color-scheme: light; transition: background .15s, border-color .15s; }
.ff:hover { background: rgba(125, 155, 255, .2); }
.ff:focus { background: rgba(125, 155, 255, .22); border-color: var(--accent-strong); }
textarea.ff { resize: none; padding: 2px 3px; line-height: 1.25; }
input.ff[type='checkbox'], input.ff[type='radio'] { appearance: auto; accent-color: #2b5cff; cursor: pointer; padding: 0; }
select.ff { cursor: pointer; padding: 0 2px; }

.an { position: absolute; cursor: move; }
.an-svg { display: block; overflow: visible; }
.an-line, .an-arrow, .an-path { pointer-events: none !important; }
.an .hit { pointer-events: stroke; cursor: move; }
.an.multiply { mix-blend-mode: multiply; }
.an-text { white-space: pre; line-height: 1.2; min-width: 4px; min-height: 1em; padding: 0; outline: none; }
.an-text.editing { cursor: text; outline: 1px dashed var(--accent-strong); outline-offset: 2px; user-select: text; -webkit-user-select: text; }
.an-text.editing:empty::before { content: attr(data-placeholder); color: #9a9aa2; }
.an-image img { width: 100%; height: 100%; display: block; user-select: none; -webkit-user-drag: none; pointer-events: none; }
.an-note { display: grid; place-items: center; border-radius: 6px 6px 6px 1px; background: var(--note); color: #111; box-shadow: 0 2px 8px rgba(0, 0, 0, .25); }
.an.sel { outline: 1.5px solid var(--accent-strong); outline-offset: 2px; }
.an-line.sel, .an-arrow.sel { outline: none; }
.an-path.sel { outline-style: dashed; }
.hd { position: absolute; width: 11px; height: 11px; background: #fff; border: 1.5px solid var(--accent-strong); border-radius: 3px; transform: translate(-50%, -50%); z-index: 3; pointer-events: auto !important; }
.hd-nw { left: -2px; top: -2px; cursor: nwse-resize; }
.hd-ne { left: calc(100% + 2px); top: -2px; cursor: nesw-resize; }
.hd-sw { left: -2px; top: calc(100% + 2px); cursor: nesw-resize; }
.hd-se { left: calc(100% + 2px); top: calc(100% + 2px); cursor: nwse-resize; }
.hd[data-h='p1'], .hd[data-h='p2'] { border-radius: 50%; cursor: grab; }
.live-draw { position: absolute; inset: 0; pointer-events: none; overflow: visible; }

.ed-zoom { position: absolute; right: 16px; bottom: 16px; z-index: 25; display: flex; align-items: center; gap: 2px; padding: 3px; background: rgba(21, 21, 23, .9); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border: 1px solid var(--border-2); border-radius: 12px; }
.ed-zoom .icon-btn { width: 30px; height: 30px; }
.zoom-label { min-width: 52px; height: 30px; border-radius: 8px; font-size: 12px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.zoom-label:hover { background: var(--surface-2); color: var(--text); }
.page-info { position: absolute; left: 188px; bottom: 16px; z-index: 25; padding: 6px 11px; border-radius: 10px; background: rgba(21, 21, 23, .9); border: 1px solid var(--border-2); font-size: 12px; color: var(--text-2); font-variant-numeric: tabular-nums; pointer-events: none; }

.ed-gridwrap { display: none; overflow: auto; padding: 36px 40px 80px; grid-column: 1 / -1; }
.ed[data-view='grid'] .ed-gridwrap { display: block; }
.ed[data-view='grid'] .ed-side, .ed[data-view='grid'] .ed-scroll, .ed[data-view='grid'] .ed-zoom, .ed[data-view='grid'] .page-info { display: none; }
.ed[data-view='grid'] .ed-tools { visibility: hidden; }
.grid-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; max-width: 1200px; margin: 0 auto 28px; }
.grid-head h2 { font-size: 22px; letter-spacing: -0.02em; }
.grid-head p { margin-top: 4px; font-size: 14px; }
.grid-head-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.ed-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 24px 18px; max-width: 1200px; margin: 0 auto; }
.gp { cursor: grab; user-select: none; touch-action: none; }
.gp-frame { position: relative; padding: 10px; border-radius: 12px; transition: background .15s; }
.gp:hover .gp-frame { background: var(--surface); }
.gp-img { background: #fff; border-radius: 3px; overflow: hidden; box-shadow: 0 2px 12px rgba(0, 0, 0, .45); }
.gp-img canvas { width: 100%; height: 100%; display: block; }
.gp-num { text-align: center; font-size: 12px; color: var(--text-3); margin-top: 6px; }
.gp .th-actions { top: 18px; right: 18px; flex-direction: row; }
.gp:hover .th-actions { display: flex; }
@media (hover: none) { .th-actions, .gp .th-actions { display: flex; } }
.gp-add { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; min-height: 220px; margin: 10px; border: 1.5px dashed var(--border-2); border-radius: 12px; color: var(--text-3); font-size: 13px; transition: color .15s, border-color .15s; }
.gp-add:hover { color: var(--text); border-color: var(--text-3); }

/* Signature modal */
.sig-modal { gap: 14px !important; }
.sig-top { display: flex !important; flex-direction: row !important; align-items: center; justify-content: space-between; gap: 12px; }
.sig-colors { display: flex; gap: 10px; padding-right: 4px; }
.sig-host { min-height: 214px; }
.sig-pane { display: flex; flex-direction: column; gap: 10px; }
.sig-pad-wrap { position: relative; height: 200px; background: #fff; border-radius: 12px; overflow: hidden; }
.sig-pad { width: 100%; height: 100%; display: block; touch-action: none; cursor: crosshair; position: relative; z-index: 1; }
.sig-line { position: absolute; left: 28px; right: 28px; bottom: 50px; border-bottom: 1px solid #e3e3e6; }
.sig-hint { position: absolute; left: 28px; bottom: 28px; font-size: 11px; color: #b0b0b6; letter-spacing: .04em; }
.sig-tools { display: flex !important; flex-direction: row !important; justify-content: flex-end; }
.sig-fonts { display: flex; flex-direction: column; gap: 8px; }
.sig-font { height: 64px; padding: 0 18px; text-align: left; font-size: 34px; background: #fff; border-radius: 10px; border: 2px solid transparent; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transition: border-color .15s; }
.sig-font.active { border-color: var(--accent-strong); }
.sig-upload-preview:empty { display: none; }
.sig-upload-preview img { max-height: 110px; max-width: 100%; background: #fff; border-radius: 10px; padding: 8px; display: block; }
.sig-saved { gap: 8px !important; }
.sig-saved-list { display: flex; gap: 10px; flex-wrap: wrap; }
.sig-saved-item { position: relative; }
.sig-saved-item .mini-btn { position: absolute; top: -8px; right: -8px; width: 22px; height: 22px; border-radius: 50%; }
.sig-saved-btn { width: 132px; height: 56px; padding: 6px 10px; background: #fff; border-radius: 10px; display: grid; place-items: center; border: 2px solid transparent; transition: border-color .15s; }
.sig-saved-btn:hover { border-color: var(--accent-strong); }
.sig-saved-btn img { max-width: 100%; max-height: 100%; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .ed-name { max-width: 140px; }
}
@media (max-width: 960px) {
  .ed-head { display: flex; flex-wrap: wrap; height: auto; padding: 8px 10px; gap: 8px; }
  .ed-left { flex: 1; }
  .ed-tools { order: 3; width: 100%; justify-content: space-between; overflow-x: auto; scrollbar-width: none; }
  .ed-tools::-webkit-scrollbar { display: none; }
}
@media (max-width: 860px) {
  .tools-index { grid-template-columns: repeat(2, 1fr); }
  .tools-menu { grid-template-columns: repeat(2, 160px); }
  .split-layout { grid-template-columns: 1fr; }
  .split-layout .preview { max-width: 280px; }
}
@media (max-width: 760px) {
  .ed-main { grid-template-columns: 1fr; }
  .ed-side { display: none; }
  .ed-props { left: 0; max-width: calc(100% - 24px); overflow-x: auto; scrollbar-width: none; }
  .page-info { left: 16px; }
  .ed-pages { padding: 0 12px; }
  .ed-gridwrap { padding: 24px 16px 80px; }
  .ed-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 16px 8px; }
  .hide-sm { display: none; }
  .ed-right .btn-primary { width: 36px; padding: 0; }
}
@media (max-width: 600px) {
  .hide-xs { display: none; }
  .home { padding-top: 44px; }
  .hero h1 { font-size: 36px; }
  .dropzone { min-height: 240px; }
  .tool-page { padding-top: 36px; }
  .tool-head h1 { font-size: 28px; }
  .tools-index { gap: 24px 8px; margin-top: 52px; }
  .tools-menu { right: -8px; grid-template-columns: 1fr 1fr; width: calc(100vw - 24px); }
  .form-row { grid-template-columns: 1fr; }
  .action-bar { flex-wrap: wrap; }
  .cards { grid-template-columns: repeat(2, 1fr); }
  .ed-tools .tool { width: 34px; }
}
.shape-pick { display: flex; gap: 2px; }

/* Download menu */
.dl-caret { margin-left: -2px; opacity: .7; }
.dl-menu { position: fixed; z-index: 120; width: 280px; padding: 6px; background: var(--surface); border: 1px solid var(--border-2); border-radius: 14px; box-shadow: var(--shadow); animation: pop .14s ease-out; max-height: calc(100vh - 80px); overflow-y: auto; }
.dl-title { padding: 8px 10px 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--text-3); }
.dl-item { width: 100%; display: flex; align-items: center; gap: 12px; padding: 8px 10px; border-radius: 9px; text-align: left; transition: background .12s; }
.dl-item:hover, .dl-item:focus-visible { background: var(--surface-2); outline: none; }
.dl-icon { width: 32px; height: 32px; border-radius: 8px; display: grid; place-items: center; background: var(--surface-2); color: var(--text-2); flex: none; }
.dl-item:hover .dl-icon { background: var(--surface-3); color: var(--text); }
.dl-text { display: flex; flex-direction: column; min-width: 0; }
.dl-text strong { font-size: 14px; font-weight: 500; }
.dl-text span { font-size: 12px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dl-sep { height: 1px; background: var(--border); margin: 5px 8px; }
.formats-note { text-align: center; font-size: 12.5px; color: var(--text-3); margin-top: 14px; line-height: 1.6; }

/* Pay-per-download */
.pay-wrap { z-index: 360; }
.pay-modal { position: relative; width: 400px; padding: 28px 26px 22px; display: flex; flex-direction: column; gap: 16px; }
.pay-x { position: absolute; top: 12px; right: 12px; }
.pay-head h3 { font-size: 19px; letter-spacing: -0.02em; }
.pay-head p { margin-top: 6px; font-size: 14px; }
.pay-file { display: flex; align-items: center; gap: 12px; padding: 12px 14px; background: var(--bg-raised); border: 1px solid var(--border); border-radius: 12px; }
.pay-ext { min-width: 44px; height: 32px; padding: 0 8px; border-radius: 8px; display: grid; place-items: center; background: var(--surface-3); font-size: 11px; font-weight: 600; letter-spacing: .04em; color: var(--text); }
.pay-file-text { min-width: 0; }
.pay-name { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pay-price { display: flex; align-items: baseline; gap: 8px; }
.pay-amount { font-size: 40px; font-weight: 600; letter-spacing: -0.04em; line-height: 1; }
.pay-btn { height: 46px; font-size: 15px; width: 100%; }
.pay-fine { display: flex; align-items: center; justify-content: center; gap: 6px; font-size: 12px; color: var(--text-3); }
.pay-demo { font-size: 12px; text-align: center; color: #f5c518; background: rgba(245, 197, 24, .08); border: 1px solid rgba(245, 197, 24, .25); border-radius: 10px; padding: 8px 10px; }
.pay-stripe { flex: none; min-height: 360px; border-radius: 12px; overflow: hidden; background: #fff; }
.pay-modal > * { flex-shrink: 0; }
.pay-modal:has(.pay-stripe) { width: 520px; }
.pay-loading { height: 360px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; color: #6b6b74; font-size: 14px; background: var(--bg-raised); }
.pay-done { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 8px; padding: 10px 0 2px; }
.pay-done h3 { font-size: 19px; margin-top: 4px; }
.pay-check { width: 54px; height: 54px; border-radius: 50%; display: grid; place-items: center; background: rgba(127, 224, 166, .12); color: var(--ok); }
.pay-actions { display: flex; gap: 8px; margin-top: 12px; }
.spinner.sm { width: 16px; height: 16px; border-width: 2px; border-color: rgba(10, 10, 11, .25); border-top-color: var(--bg); }

.pay-modal.wide { width: 520px; }
.pay-top { display: flex; align-items: center; gap: 12px; padding-right: 36px; }
.pay-amount-sm { margin-left: auto; font-size: 22px; font-weight: 600; letter-spacing: -0.03em; }
.pm-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.pm { height: 46px; border-radius: 10px; font-size: 15px; font-weight: 600; display: flex; align-items: center; justify-content: center; gap: 6px; transition: transform .1s, filter .15s; }
.pm:hover:not(:disabled) { filter: brightness(1.08); }
.pm:active:not(:disabled) { transform: scale(.98); }
.pm:disabled { opacity: .6; }
.pm-apple { background: #000; color: #fff; border: 1px solid #3a3a3f; }
.pm-google { background: #fff; color: #3c4043; }
.pm-paypal { background: #ffc439; color: #003087; font-style: italic; font-weight: 800; }
.pm-link { background: #00d66f; color: #011e0f; }
.pm-card { grid-column: 1 / -1; background: var(--surface-2); color: var(--text); border: 1px solid var(--border-2); }
.pm-more { grid-column: 1 / -1; height: 40px; font-size: 13px; font-weight: 500; background: transparent; color: var(--text-2); border: 1px dashed var(--border-2); }
.pm-google .spinner.sm, .pm-paypal .spinner.sm, .pm-link .spinner.sm { border-color: rgba(0,0,0,.2); border-top-color: #111; }
.pm-apple .spinner.sm, .pm-card .spinner.sm, .pm-more .spinner.sm { border-color: rgba(255,255,255,.25); border-top-color: #fff; }
@media (max-width: 600px) { .pay-modal, .pay-modal.wide { width: 100%; padding: 24px 18px 18px; } }

/* Footer link & legal page */
.footer { display: flex; justify-content: center; gap: 14px; flex-wrap: wrap; }
.footer-link { color: var(--text-3); text-decoration: none; }
.footer-link:hover { color: var(--text-2); }
.pay-fine a { color: var(--text-2); text-decoration: underline; text-underline-offset: 2px; }
.legal { width: 100%; max-width: 680px; margin: 0 auto; padding: 56px 20px 40px; }
.legal h1 { font-size: 30px; letter-spacing: -0.03em; }
.legal > .muted { margin-top: 6px; }
.legal section { margin-top: 30px; }
.legal h2 { font-size: 15px; font-weight: 600; margin-bottom: 8px; }
.legal p { color: var(--text-2); font-size: 14.5px; line-height: 1.65; margin-top: 8px; }
.legal a { color: var(--text); text-underline-offset: 3px; }
.legal > p:last-child { margin-top: 36px; }
.pay-fine { display: block; text-align: center; line-height: 1.5; }
