:root {
  --paper: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #faf9f6;
  --line: #e3dfd6;
  --line-strong: #cfc9bc;
  --ink: #1f2430;
  --muted: #646a76;
  --accent: #2b4a9b;
  --accent-ink: #ffffff;
  --accent-soft: #e8edf8;
  --ok: #2f7a4b;
  --warn: #9a5b0b;
  --warn-soft: #fbf1e1;
  --err: #a63a32;
  --err-soft: #f9e7e5;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(30, 30, 40, .06), 0 6px 24px rgba(30, 30, 40, .06);
  --serif: "PT Serif", "Georgia", "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--paper); color: var(--ink); font: 16px/1.5 var(--sans); }
main { outline: none; }
[hidden] { display: none !important; }
a { color: var(--accent); }
h1, h2, h3 { font-family: var(--serif); font-weight: 700; letter-spacing: -.01em; margin: 0 0 .4em; }
h1 { font-size: 34px; line-height: 1.15; }
h2 { font-size: 24px; }
h3 { font-size: 18px; }
p { margin: 0 0 .8em; }
.muted { color: var(--muted); }
.small { font-size: 14px; }

/* верхняя панель */
.topbar { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 28px; padding: 12px 28px;
  background: rgba(246, 244, 239, .92); backdrop-filter: blur(6px); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); }
.brand-mark { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--accent); position: relative; }
.brand-mark::after { content: ""; position: absolute; inset: 5px; border-radius: 50%; border: 1.5px solid var(--accent); }
.brand-name { font-family: var(--serif); font-size: 22px; font-weight: 700; }
.nav { display: flex; gap: 6px; flex: 1; }
.nav a { padding: 8px 14px; border-radius: 999px; text-decoration: none; color: var(--muted); font-weight: 500; }
.nav a.active, .nav a:hover { background: var(--surface); color: var(--ink); box-shadow: inset 0 0 0 1px var(--line); }
.user { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 14px; }

/* кнопки и поля */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--ink); border-radius: 12px; padding: 11px 18px; font: 600 15px/1.2 var(--sans);
  cursor: pointer; transition: background .15s, border-color .15s, transform .05s; text-decoration: none; }
.btn:hover { border-color: var(--ink); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: #223d84; }
.btn.big { padding: 16px 28px; font-size: 17px; border-radius: 14px; min-width: 210px; }
.btn.small { padding: 6px 12px; font-size: 13px; border-radius: 9px; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface); border-color: var(--line); }
.btn.danger { color: var(--err); }
.btn.icon { padding: 8px; width: 38px; height: 38px; }
.btn.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
input[type=text], input[type=email], input[type=password], input[type=number], textarea, select {
  width: 100%; border: 1px solid var(--line-strong); border-radius: 10px; padding: 10px 12px; font: 15px/1.4 var(--sans);
  background: var(--surface); color: var(--ink); }
input:focus, textarea:focus, select:focus, .btn:focus-visible { outline: 3px solid rgba(43, 74, 155, .25); outline-offset: 1px; border-color: var(--accent); }
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; font-weight: 500; }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; }
.check input { margin-top: 3px; width: 18px; height: 18px; flex: none; }

/* страницы */
.page { max-width: 1120px; margin: 0 auto; padding: 36px 28px 64px; }
.lead { font-size: 18px; color: var(--muted); max-width: 720px; }
.notice { display: flex; gap: 12px; align-items: flex-start; padding: 12px 16px; border-radius: 12px; background: var(--surface);
  border: 1px solid var(--line); font-size: 14px; margin-bottom: 10px; }
.notice.warn { background: var(--warn-soft); border-color: #efd8b4; color: #5c3b06; }
.notice.err { background: var(--err-soft); border-color: #efc7c2; color: #6d211b; }
.notice.info { background: var(--accent-soft); border-color: #cfd9f1; color: #1f3570; }
.notice b { font-weight: 600; }

/* загрузка */
.drops { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; margin: 28px 0 18px; }
.drop { position: relative; min-height: 290px; border: 2px dashed var(--line-strong); border-radius: 20px; background: var(--surface);
  padding: 26px; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center;
  cursor: pointer; transition: border-color .15s, background .15s, box-shadow .15s; }
.drop:hover, .drop.over { border-color: var(--accent); background: #fbfcff; box-shadow: var(--shadow); }
.drop .num { position: absolute; top: 18px; left: 20px; width: 30px; height: 30px; border-radius: 50%; background: var(--accent-soft);
  color: var(--accent); font-weight: 700; display: grid; place-items: center; }
.drop h3 { font-size: 21px; margin-bottom: 6px; }
.drop .hint { color: var(--muted); font-size: 14px; }
.drop .pick { margin-top: 18px; }
.drop.filled { border-style: solid; border-color: var(--line); cursor: default; }
.drop .thumb { max-height: 170px; max-width: 80%; border: 1px solid var(--line); border-radius: 6px; box-shadow: var(--shadow); background: #fff; }
.drop .fname { margin-top: 12px; font-weight: 600; word-break: break-word; }
.drop .meta { font-size: 13px; color: var(--muted); }
.drop .remove { position: absolute; top: 14px; right: 14px; }
.drop .spinner { margin: 10px auto; }
.drop.optional .num { background: #eef0ec; color: var(--muted); }
.actions { display: flex; gap: 12px; justify-content: center; align-items: center; flex-wrap: wrap; margin-top: 8px; }
.privacy { margin-top: 26px; font-size: 13px; color: var(--muted); text-align: center; }

/* обработка */
.stages { list-style: none; padding: 0; margin: 22px 0; max-width: 520px; }
.stages li { display: flex; align-items: center; gap: 14px; padding: 10px 0; color: var(--muted); }
.stages li .dot { width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--line-strong); flex: none; display: grid; place-items: center; font-size: 13px; }
.stages li.active { color: var(--ink); font-weight: 600; }
.stages li.active .dot { border-color: var(--accent); border-top-color: transparent; animation: spin 0.8s linear infinite; }
.stages li.done { color: var(--ink); }
.stages li.done .dot { background: var(--ok); border-color: var(--ok); color: #fff; }
.stages li.done .dot::after { content: "✓"; }
.stages li.error .dot { background: var(--err); border-color: var(--err); color: #fff; }
.stages li.error .dot::after { content: "!"; }
.stages li.waiting .dot { border-color: var(--warn); background: var(--warn-soft); }
.stages li.skipped { display: none; }
.spinner { width: 26px; height: 26px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* результат */
.result-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.result-actions { display: flex; gap: 12px; }
.preview-pages { display: flex; flex-direction: column; align-items: center; gap: 24px; padding: 24px; background: #e9e6df; border-radius: 18px; }
.preview-pages img { max-width: 100%; width: 760px; background: #fff; box-shadow: 0 2px 14px rgba(0, 0, 0, .12); border-radius: 2px; }
.preview-pages .pnum { font-size: 13px; color: var(--muted); margin-top: -16px; }
.found { margin-top: 26px; }
.detail { overflow: hidden; border-radius: 14px; border: 1px solid var(--line); background: #fff; max-width: 760px; margin: 0 auto 8px; box-shadow: var(--shadow); }
.detail img { display: block; max-width: none; }
.found-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.chk { background-color: #fff; background-image: linear-gradient(45deg, #eee 25%, transparent 25%), linear-gradient(-45deg, #eee 25%, transparent 25%),
  linear-gradient(45deg, transparent 75%, #eee 75%), linear-gradient(-45deg, transparent 75%, #eee 75%);
  background-size: 16px 16px; background-position: 0 0, 0 8px, 8px -8px, -8px 0; border-radius: 10px; border: 1px solid var(--line);
  height: 140px; display: grid; place-items: center; overflow: hidden; }
.chk img { max-width: 92%; max-height: 92%; }
.card .t { font-weight: 600; margin-top: 10px; }
.card .d { font-size: 13px; color: var(--muted); }
.card .row { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.tag { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.tag.warn { background: var(--warn-soft); color: var(--warn); }

/* редактор */
.editor { display: grid; grid-template-columns: 150px minmax(0, 1fr) 340px; grid-template-rows: minmax(0, 1fr); height: calc(100vh - 57px); overflow: hidden; }
.ed-pages { border-right: 1px solid var(--line); overflow-y: auto; padding: 12px; background: var(--surface-2); }
.ed-pages .pg { display: block; width: 100%; border: 2px solid transparent; border-radius: 6px; margin-bottom: 10px; padding: 0; background: none; cursor: pointer; }
.ed-pages .pg img { width: 100%; display: block; border-radius: 4px; box-shadow: 0 1px 4px rgba(0, 0, 0, .15); background: #fff; }
.ed-pages .pg.active { border-color: var(--accent); }
.ed-pages .pg span { display: block; font-size: 12px; color: var(--muted); text-align: center; margin-top: 2px; }
.ed-pages .pg .cnt { color: var(--accent); font-weight: 600; }
.ed-center { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.ed-toolbar { display: flex; align-items: center; gap: 4px; padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--surface); flex-wrap: nowrap; white-space: nowrap; overflow-x: auto; }
.ed-toolbar .sep { width: 1px; height: 26px; background: var(--line); margin: 0 6px; }
.ed-toolbar .zoomv { min-width: 52px; text-align: center; font-size: 13px; color: var(--muted); }
.ed-toolbar .grow { flex: 1; }
.ed-toolbar .saved { font-size: 12px; color: var(--muted); }
.ed-stage { flex: 1; min-height: 0; overflow: auto; background: #e4e1d9; position: relative; }
.ed-canvas { position: relative; margin: 28px auto; background: #fff; box-shadow: 0 2px 16px rgba(0, 0, 0, .15); user-select: none; touch-action: none; }
.ed-canvas > img.pgimg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.obj { position: absolute; cursor: move; transform-origin: 50% 50%; }
.obj img { width: 100%; height: 100%; display: block; pointer-events: none; -webkit-user-drag: none; }
.obj.cover { background: #fff; outline: 1px dashed #c33; }
.obj.sel { outline: 1.5px solid var(--accent); outline-offset: 0; }
.obj.locked { cursor: default; }
.obj .h { position: absolute; width: 12px; height: 12px; background: #fff; border: 2px solid var(--accent); border-radius: 3px; }
.obj .h.nw { left: -7px; top: -7px; cursor: nwse-resize; }
.obj .h.ne { right: -7px; top: -7px; cursor: nesw-resize; }
.obj .h.sw { left: -7px; bottom: -7px; cursor: nesw-resize; }
.obj .h.se { right: -7px; bottom: -7px; cursor: nwse-resize; }
.obj .h.rot { left: 50%; top: -34px; margin-left: -7px; border-radius: 50%; cursor: grab; }
.obj .rotline { position: absolute; left: 50%; top: -22px; height: 22px; border-left: 1.5px solid var(--accent); }
.obj canvas.erase { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.selrect { position: absolute; border: 2px dashed var(--accent); background: rgba(43, 74, 155, .08); pointer-events: none; }
.selrect.cover { border-color: #c33; background: rgba(204, 51, 51, .08); }
.brush { position: absolute; border: 1.5px solid #c33; border-radius: 50%; pointer-events: none; transform: translate(-50%, -50%); }
.ed-side { border-left: 1px solid var(--line); background: var(--surface); display: flex; flex-direction: column; min-height: 0; }
.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tabs button { flex: 1; padding: 12px 6px; background: none; border: none; border-bottom: 2px solid transparent; font: 600 14px var(--sans); color: var(--muted); cursor: pointer; }
.tabs button.active { color: var(--ink); border-bottom-color: var(--accent); }
.tabpane { padding: 16px; overflow-y: auto; flex: 1; }
.prop-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.layer { display: flex; align-items: center; gap: 8px; padding: 8px; border-radius: 10px; border: 1px solid transparent; cursor: pointer; }
.layer:hover { background: var(--surface-2); }
.layer.sel { border-color: var(--accent); background: var(--accent-soft); }
.layer .lt { flex: 1; font-size: 14px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layer img { width: 36px; height: 28px; object-fit: contain; background: #fff; border-radius: 4px; border: 1px solid var(--line); }
.layer .btn { padding: 4px 6px; }
.lib-item { display: flex; gap: 10px; align-items: center; border: 1px solid var(--line); border-radius: 12px; padding: 8px; margin-bottom: 8px; }
.lib-item .chk { width: 70px; height: 54px; flex: none; border-radius: 8px; }
.lib-item .lt { flex: 1; min-width: 0; font-size: 13px; }
.lib-item .lt b { display: block; font-size: 14px; }
.ai-box textarea { min-height: 88px; resize: vertical; }
.ai-attach { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0 12px; }
.ai-chip { display: inline-flex; align-items: center; gap: 6px; background: var(--accent-soft); color: var(--accent); border-radius: 999px; padding: 3px 10px; font-size: 13px; }
.ai-chip button { border: none; background: none; color: inherit; cursor: pointer; padding: 0; font-size: 15px; }
.ai-log { margin-top: 14px; font-size: 14px; }
.ai-log .entry { padding: 10px 12px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--line); margin-bottom: 8px; }
.ai-log .entry .q { color: var(--muted); font-size: 13px; }
.examples { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.examples button { font-size: 12px; border: 1px solid var(--line); background: var(--surface-2); border-radius: 999px; padding: 4px 10px; cursor: pointer; color: var(--muted); }
.examples button:hover { color: var(--ink); border-color: var(--line-strong); }
input[type=range] { width: 100%; accent-color: var(--accent); }

/* модальные окна */
.modal-bg { position: fixed; inset: 0; background: rgba(25, 27, 33, .45); z-index: 100; display: grid; place-items: center; padding: 20px; }
.modal { background: var(--surface); border-radius: 18px; max-width: 560px; width: 100%; max-height: 92vh; overflow: auto; padding: 26px; box-shadow: 0 20px 60px rgba(0, 0, 0, .25); }
.modal.wide { max-width: 980px; }
.modal .foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.options { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
.options button { text-align: left; padding: 14px 16px; border: 1px solid var(--line-strong); border-radius: 12px; background: var(--surface); cursor: pointer; font: 15px var(--sans); }
.options button:hover { border-color: var(--accent); background: #fbfcff; }
.options button small { display: block; color: var(--muted); }
.sample-pick { position: relative; display: inline-block; max-width: 100%; touch-action: none; user-select: none; cursor: crosshair; }
.sample-pick img { max-width: 100%; max-height: 64vh; display: block; }

/* коллекция */
.coll-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.coll-group { margin-bottom: 30px; }
.coll-group h3 { display: flex; gap: 10px; align-items: baseline; }
.coll-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }

/* вход */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.auth-side { background: var(--accent); color: #fff; padding: 64px; display: flex; flex-direction: column; justify-content: center; position: relative; overflow: hidden; }
.auth-side h1 { font-size: 46px; color: #fff; }
.auth-side p { font-size: 18px; color: rgba(255, 255, 255, .85); max-width: 460px; }
.auth-side .ring { position: absolute; right: -120px; bottom: -120px; width: 420px; height: 420px; border-radius: 50%; border: 14px solid rgba(255, 255, 255, .12); }
.auth-side .ring::after { content: ""; position: absolute; inset: 50px; border-radius: 50%; border: 5px solid rgba(255, 255, 255, .1); }
.auth-form { display: flex; align-items: center; justify-content: center; padding: 40px; }
.auth-form form { width: 100%; max-width: 380px; }
.auth-form .switch { margin-top: 16px; font-size: 14px; text-align: center; }

#toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 12px; font-size: 14px; z-index: 200; opacity: 0; pointer-events: none; transition: opacity .2s; max-width: 90vw; }
#toast.show { opacity: 1; }
#toast.err { background: var(--err); }

.empty { text-align: center; padding: 50px 20px; color: var(--muted); }
.hist-item { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; margin-bottom: 10px; }

@media (max-width: 900px) {
  .drops { grid-template-columns: 1fr; }
  .editor { grid-template-columns: 1fr; height: auto; }
  .ed-pages { display: none; }
  .ed-side { border-left: none; border-top: 1px solid var(--line); }
  .ed-stage { min-height: 70vh; }
  .auth { grid-template-columns: 1fr; }
  .auth-side { padding: 36px; }
  .topbar { gap: 12px; padding: 10px 14px; flex-wrap: wrap; }
}
