:root {
  --bg: #f6f7f9; --panel: #fff; --ink: #14171f; --muted: #5d6576; --line: #e2e5eb;
  --accent: #2b59c3; --accent-ink: #fff; --accent-soft: #e8eefb; --err: #b42318; --err-soft: #fdecea;
  --radius: 12px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115; --panel: #171a21; --ink: #e8eaef; --muted: #9aa3b5; --line: #2a2f3a;
    --accent: #6d95f2; --accent-ink: #0f1115; --accent-soft: #1d2740; --err: #f97066; --err-soft: #3a1b1a;
    --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
.ic { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.ic.big { width: 32px; height: 32px; stroke-width: 1.5; }
button, a.primary { font: inherit; cursor: pointer; }
button:disabled { opacity: .5; cursor: default; }

.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; max-width: 960px; margin: 0 auto; padding: 16px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; font-size: 17px; }
.brand .ic { color: var(--accent); width: 22px; height: 22px; }
.privacy { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
.privacy .ic { width: 15px; height: 15px; }

main { max-width: 960px; margin: 0 auto; padding: 0 16px 32px; }
.intro { text-align: center; padding: 24px 0 8px; }
h1 { font-size: clamp(24px, 4.5vw, 34px); line-height: 1.15; margin: 0 0 6px; letter-spacing: -0.01em; }
.sub { margin: 0; color: var(--muted); }
h2 { font-size: 16px; margin: 0; }

.drop {
  display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center;
  margin: 20px 0 10px; padding: 36px 16px; background: var(--panel); border: 2px dashed var(--line);
  border-radius: var(--radius); cursor: pointer; color: var(--muted); transition: border-color .15s, background .15s;
}
.drop:hover, .drop:focus-visible, .drop.over { border-color: var(--accent); background: var(--accent-soft); outline: none; }
.drop .ic.big { color: var(--accent); }
.drop-main { color: var(--ink); font-weight: 550; }
.drop-sub { font-size: 13px; }
.compact .drop { padding: 14px 16px; flex-direction: row; justify-content: center; margin-top: 8px; }
.compact .drop .ic.big { width: 22px; height: 22px; }
.compact .drop-sub, .compact .intro { display: none; }
.camera-btn { display: none; align-items: center; justify-content: center; gap: 8px; padding: 12px; border-radius: var(--radius); background: var(--panel); border: 1px solid var(--line); font-weight: 550; cursor: pointer; }
@media (pointer: coarse) { .camera-btn { display: flex; } }

.status { margin: 14px 0; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.status-text { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; margin-bottom: 8px; }
#statusPct { color: var(--muted); font-variant-numeric: tabular-nums; }
.bar { height: 6px; background: var(--line); border-radius: 99px; overflow: hidden; }
#barFill { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.bar.indet #barFill { width: 30% !important; animation: indet 1.1s ease-in-out infinite; }
@keyframes indet { from { transform: translateX(-100%); } to { transform: translateX(340%); } }
.error { display: flex; gap: 8px; align-items: flex-start; margin: 14px 0; padding: 12px 14px; border-radius: var(--radius); background: var(--err-soft); color: var(--err); }
.error[hidden] { display: none; }

#workspace { margin-top: 18px; }
.pages-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.link { background: none; border: 0; color: var(--accent); padding: 4px; }
.pages { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 14px; align-items: start; }
.page { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; display: flex; flex-direction: column; }
.page.dragging { opacity: .4; }
.page.drop-before { box-shadow: -4px 0 0 var(--accent); }
.thumb { position: relative; aspect-ratio: 3 / 4; background: var(--bg); display: flex; align-items: center; justify-content: center; cursor: grab; }
.thumb img { position: absolute; inset: 0; margin: auto; width: auto; height: auto; max-width: calc(100% - 16px); max-height: calc(100% - 16px); display: block; box-shadow: 0 1px 4px rgba(0,0,0,.18); }
.thumb .num { position: absolute; z-index: 2; top: 6px; left: 6px; background: rgba(20,23,31,.75); color: #fff; font-size: 12px; font-weight: 600; padding: 1px 7px; border-radius: 99px; font-variant-numeric: tabular-nums; }
.thumb .warn { position: absolute; z-index: 2; bottom: 6px; left: 6px; right: 6px; background: rgba(20,23,31,.8); color: #fff; font-size: 11px; padding: 3px 6px; border-radius: 6px; text-align: center; }
.thumb .busy { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 13px; }
.page { position: relative; }
.move { position: absolute; top: 6px; right: 6px; z-index: 3; display: flex; gap: 2px; background: rgba(20,23,31,.72); border-radius: 99px; padding: 2px; }
.move .icon { color: #fff; padding: 5px; }
.move .icon:hover { background: rgba(255,255,255,.18); color: #fff; }
.tools { display: flex; justify-content: space-around; padding: 4px; border-top: 1px solid var(--line); }
@media (pointer: coarse) {
  .tools .icon { padding: 11px; }
  .move .icon { padding: 9px; }
}
.check.off { opacity: .5; }
.icon { background: none; border: 0; color: var(--muted); padding: 7px; border-radius: 8px; display: inline-flex; }
.icon:hover { background: var(--accent-soft); color: var(--accent); }
.icon.del:hover { background: var(--err-soft); color: var(--err); }

.options { margin-top: 22px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 16px; }
.opt { display: grid; grid-template-columns: 110px 1fr; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.opt:last-child { border-bottom: 0; }
.opt.row { grid-template-columns: 1fr; display: flex; flex-wrap: wrap; gap: 8px 24px; }
.opt-label { color: var(--muted); font-size: 14px; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button { border: 1px solid var(--line); background: var(--panel); color: var(--ink); padding: 6px 12px; border-radius: 99px; font-size: 14px; }
.seg button.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.check { display: flex; gap: 8px; align-items: center; font-size: 14px; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.name { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; max-width: 360px; background: var(--bg); }
.name input { flex: 1; min-width: 0; border: 0; padding: 8px 10px; font: inherit; color: var(--ink); background: transparent; outline: none; }
.name span { padding: 0 10px; color: var(--muted); }
@media (max-width: 560px) { .opt { grid-template-columns: 1fr; gap: 6px; } }

.actions { margin-top: 18px; display: flex; justify-content: flex-end; gap: 8px; }
.primary, .secondary { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border-radius: 10px; padding: 11px 20px; font-weight: 600; text-decoration: none; border: 1px solid transparent; }
.primary { background: var(--accent); color: var(--accent-ink); }
.primary:hover { filter: brightness(1.08); }
.secondary { background: var(--panel); color: var(--ink); border-color: var(--line); }
@media (max-width: 560px) { .actions .primary { width: 100%; } }

.result { margin-top: 16px; display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px; background: var(--accent-soft); border-radius: var(--radius); padding: 14px 16px; }
.result-info { display: flex; flex-direction: column; min-width: 0; }
.result-info strong { overflow-wrap: anywhere; }
.result-info span { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.result-btns { display: flex; gap: 8px; flex-wrap: wrap; }

.editor { border: 0; padding: 0; border-radius: var(--radius); width: min(720px, calc(100vw - 24px)); max-height: calc(100vh - 24px); background: var(--panel); color: var(--ink); }
.editor::backdrop { background: rgba(0,0,0,.6); }
.editor[open] { display: flex; flex-direction: column; }
.editor-head, .editor-foot { display: flex; align-items: center; gap: 8px; padding: 10px 14px; }
.editor-foot button { white-space: nowrap; padding-left: 14px; padding-right: 14px; }
.editor-stage { flex: 1; min-height: 0; display: flex; justify-content: center; background: #0b0d11; padding: 10px; overflow: hidden; }
#edCanvas { max-width: 100%; max-height: calc(100vh - 160px); touch-action: none; cursor: crosshair; }
.grow { flex: 1; }
.foot { text-align: center; color: var(--muted); font-size: 13px; padding: 24px 16px 40px; }
