@font-face { font-family: 'Dancing Script'; src: url(/fonts/dancing-script.woff2) format('woff2'); font-display: swap; }
@font-face { font-family: 'Great Vibes'; src: url(/fonts/great-vibes.woff2) format('woff2'); font-display: swap; }
@font-face { font-family: 'Caveat'; src: url(/fonts/caveat.woff2) format('woff2'); font-display: swap; }

:root {
  --ink: #14161a; --muted: #5b6170; --line: #e3e6ec; --bg: #f1f3f7; --card: #fff;
  --accent: #1f4fd1; --accent-soft: #e8eefc; --ok: #167a4a; --bad: #c2410c; --pro: #7c3aed;
  --radius: 10px; --top: 56px;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font: 14px/1.45 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; color: var(--ink); background: var(--bg); }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.error { color: var(--bad); margin: 6px 0 0; }
[hidden] { display: none !important; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--card); border-radius: 8px; padding: 8px 14px; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: #c8cdd8; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { background: #1a43b4; }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.big { padding: 12px 26px; font-size: 16px; }
.btn.danger { color: var(--bad); }
.btn.pro { color: var(--pro); border-color: #ddd0fb; }
.btn.pro.is-pro { color: var(--ok); border-color: #bfe3cf; }
.link { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; text-align: left; }
.pro-tag { display: inline-block; font-size: 10px; font-weight: 700; letter-spacing: .04em; color: #fff; background: var(--pro); border-radius: 4px; padding: 1px 5px; vertical-align: 1px; }

/* top bar */
.top { position: sticky; top: 0; z-index: 20; height: var(--top); display: flex; align-items: center; gap: 10px; padding: 0 16px; background: var(--card); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; color: var(--ink); text-decoration: none; }
.spacer { flex: 1; }
.net { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--ok); background: #eaf6ef; border-radius: 99px; padding: 3px 10px; }
.net .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); }
.net .off-txt { display: none; }
.net.off { color: #8a5a00; background: #fff4db; }
.net.off .dot { background: #d69a00; }
.net.off .on-txt { display: none; }
.net.off .off-txt { display: inline; }

/* layout */
.layout { display: grid; grid-template-columns: 240px 1fr 260px; height: calc(100% - var(--top)); }
.side, .panel { background: var(--card); overflow: auto; padding: 14px; }
.side { border-right: 1px solid var(--line); }
.panel { border-left: 1px solid var(--line); }
.side-h { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 8px; }
.tools { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px; }
.tool { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 10px 6px; border: 1px solid var(--line); background: var(--card); border-radius: 8px; cursor: pointer; }
.tool:hover { border-color: var(--accent); }
.tool .ic { font-weight: 700; font-size: 16px; }
.group { margin-bottom: 14px; }
.group-head { display: flex; align-items: center; justify-content: space-between; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 6px; }
.item { position: relative; margin-bottom: 6px; }
.item-main { display: flex; align-items: center; justify-content: center; width: 100%; height: 54px; border: 1px solid var(--line); border-radius: 8px; background: #fff; cursor: pointer; padding: 6px; }
.item-main:hover, .item.on .item-main { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.item-main img { max-width: 100%; max-height: 100%; }
.item-del { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 16px; line-height: 1; padding: 2px 6px; }
.item .item-del { position: absolute; top: 2px; right: 2px; }
.add { width: 100%; }
.tpl { display: flex; align-items: center; justify-content: space-between; padding: 4px 0; }
.side-foot { margin-top: 10px; }

/* main */
.main { position: relative; overflow: hidden; display: flex; flex-direction: column; min-width: 0; }
.pages { flex: 1; overflow: auto; padding: 16px; display: flex; flex-direction: column; align-items: center; gap: 16px; }
body:not(.has-doc) .pages { display: none; }
.empty { flex: 1; display: grid; place-items: center; padding: 24px; overflow: auto; }
body.has-doc .empty { display: none; }
.drop { max-width: 520px; text-align: center; background: var(--card); border: 2px dashed #c5d2f3; border-radius: 16px; padding: 36px 28px; }
.drop h1 { font-size: 22px; margin: 10px 0 6px; }
.drop .btn { margin: 14px 0 10px; }
.trust { list-style: none; padding: 0; margin: 16px 0 0; text-align: left; display: inline-block; color: var(--muted); }
.trust li { margin: 4px 0; }

.files { display: flex; gap: 8px; padding: 10px 16px; overflow-x: auto; background: #e9ecf3; border-bottom: 1px solid var(--line); align-items: center; }
.file { display: flex; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: 8px; flex-shrink: 0; }
.file.on { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.file-main { border: 0; background: none; padding: 6px 4px 6px 10px; display: flex; gap: 6px; align-items: center; cursor: pointer; max-width: 240px; }
.fname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file .dot { width: 7px; height: 7px; border-radius: 50%; background: #d69a00; }
.add-files { flex-shrink: 0; }

.page { position: relative; background: #fff; box-shadow: 0 1px 3px rgba(20,22,26,.15), 0 4px 16px rgba(20,22,26,.06); flex-shrink: 0; }
.page canvas { display: block; }
.page-no { position: absolute; bottom: -18px; right: 0; font-size: 11px; color: var(--muted); }
.overlay { position: absolute; inset: 0; }
.overlay.placing { cursor: crosshair; }
.el { position: absolute; cursor: move; outline: 1px dashed transparent; touch-action: none; }
.el:hover { outline-color: rgba(31,79,209,.5); }
.el.sel { outline: 1.5px solid var(--accent); background: rgba(31,79,209,.05); }
.el.nudged { outline-color: #d69a00; }
.el img { width: 100%; height: 100%; display: block; pointer-events: none; user-select: none; }
.el .txt { font-family: Helvetica, Arial, sans-serif; white-space: pre; color: #0d0d1a; transform: translateY(-0.12em); pointer-events: none; }
.el .handle { position: absolute; right: -5px; bottom: -5px; width: 10px; height: 10px; background: #fff; border: 1.5px solid var(--accent); border-radius: 2px; cursor: nwse-resize; display: none; }
.el.sel .handle { display: block; }
body.is-placing .el { pointer-events: none; }

/* right panel */
.panel h3 { margin: 0 0 12px; font-size: 15px; }
.hint ol { padding-left: 18px; margin: 0 0 10px; }
.hint li { margin-bottom: 6px; }
.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.input { width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; background: #fff; }
.input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
textarea.input { resize: vertical; }
.check { display: flex; gap: 6px; align-items: center; margin-bottom: 10px; font-size: 13px; }
.row { display: flex; gap: 8px; align-items: center; }
.row.between { justify-content: space-between; }

/* modal */
.backdrop { position: fixed; inset: 0; z-index: 50; background: rgba(20,22,26,.42); display: grid; place-items: center; padding: 16px; }
.modal { background: var(--card); border-radius: 14px; width: min(560px, 100%); max-height: calc(100vh - 32px); overflow: auto; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal.wide { width: min(640px, 100%); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px 0; }
.modal-head h2 { font-size: 18px; margin: 0; }
.modal .x { border: 0; background: none; font-size: 24px; line-height: 1; cursor: pointer; color: var(--muted); }
.modal-body { padding: 12px 20px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 0 20px 18px; flex-wrap: wrap; }
.tabs { display: flex; gap: 4px; }
.tab { border: 0; background: none; padding: 6px 10px; border-radius: 6px; cursor: pointer; color: var(--muted); }
.tab.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.ink { display: flex; gap: 6px; }
.swatch { width: 22px; height: 22px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--line); cursor: pointer; }
.swatch.on { box-shadow: 0 0 0 2px var(--accent); }
.sig-body { margin-top: 12px; }
.pad { width: 100%; aspect-ratio: 3 / 1; border: 1px solid var(--line); border-radius: 10px; background: #fff linear-gradient(to top, transparent 24%, #e3e6ec 24%, #e3e6ec calc(24% + 1px), transparent calc(24% + 1px)); touch-action: none; cursor: crosshair; display: block; margin-bottom: 8px; }
.font-list { display: grid; gap: 6px; margin-top: 10px; }
.font-opt { border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 6px 12px; font-size: 34px; text-align: left; cursor: pointer; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.font-opt.on { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.file-btn input { display: none; }
.up-preview { margin: 10px 0; min-height: 60px; display: grid; place-items: center; border: 1px dashed var(--line); border-radius: 8px; padding: 8px; background: repeating-conic-gradient(#f3f4f7 0 25%, #fff 0 50%) 0 0 / 16px 16px; }
.up-preview img { max-height: 140px; max-width: 100%; }
.pro-modal .lead { font-size: 15px; }
.ticks { padding-left: 0; list-style: none; }
.ticks li { padding-left: 22px; position: relative; margin: 6px 0; }
.ticks li::before { content: '✓'; position: absolute; left: 0; color: var(--ok); font-weight: 700; }
.price-line { background: var(--accent-soft); border-radius: 8px; padding: 10px 12px; }
.price-line b { font-size: 18px; }
.activate { border-top: 1px solid var(--line); margin-top: 14px; padding-top: 12px; }

/* misc */
.busy { position: fixed; left: 50%; top: 70px; transform: translateX(-50%); z-index: 60; background: var(--ink); color: #fff; padding: 8px 16px; border-radius: 99px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; transition: .2s; z-index: 70; background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; max-width: calc(100% - 32px); pointer-events: none; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.ok { background: var(--ok); }
.toast.bad { background: var(--bad); }
.drag-veil { display: none; position: fixed; inset: 0; z-index: 40; background: rgba(31,79,209,.12); border: 3px dashed var(--accent); place-items: center; font-size: 22px; font-weight: 700; color: var(--accent); pointer-events: none; }
body.dragging .drag-veil { display: grid; }

/* narrow screens */
@media (max-width: 980px) {
  .layout { grid-template-columns: 200px 1fr; }
  .panel { grid-column: 1 / -1; border-left: 0; border-top: 1px solid var(--line); max-height: 220px; }
  .layout { grid-template-rows: 1fr auto; }
}
@media (max-width: 680px) {
  .net .on-txt { display: none; }
  .top { gap: 6px; padding: 0 10px; }
  #undo, #close-doc { display: none; }
  .brand-name { display: none; }
  #export { padding: 7px 12px; font-size: 13.5px; }
  .side .item-main { height: 44px; }
  .layout { grid-template-columns: 1fr; grid-template-rows: auto 1fr auto; height: auto; min-height: calc(100% - var(--top)); }
  .side { border-right: 0; border-bottom: 1px solid var(--line); display: flex; gap: 12px; overflow-x: auto; padding: 10px; }
  .side > section { min-width: 150px; }
  .side-foot { display: none; }
  .main { min-height: 60vh; }
  .pages { padding: 10px; }
}
.stepper { display: flex; align-items: center; gap: 4px; flex-shrink: 0; padding-right: 6px; border-right: 1px solid var(--line); margin-right: 2px; }
.stepper .btn { padding: 3px 9px; font-size: 15px; line-height: 1; }
