* { box-sizing: border-box; }
:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --ink: #1c2430;
  --muted: #5b6675;
  --line: #e2e6ec;
  --brand: #1565d8;
  --brand-dark: #0d4aa8;
  --ok: #1e7d46;
  --err: #b3261e;
  --radius: 12px;
}
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
}
.site-header {
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding: 20px 16px 16px;
  text-align: center;
}
.site-header h1 { margin: 0 0 4px; font-size: 28px; letter-spacing: -0.5px; }
.tagline { margin: 0; color: var(--muted); font-size: 15px; }
main { max-width: 920px; margin: 0 auto; padding: 16px 12px 32px; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}
.card h2 { margin: 0 0 12px; font-size: 19px; }
.card h3 { margin: 0 0 10px; font-size: 17px; }
.hint { color: var(--muted); font-size: 13.5px; margin: 8px 0; }
.dropzone {
  border: 2px dashed #b9c4d0;
  border-radius: var(--radius);
  padding: 28px 16px;
  text-align: center;
  cursor: pointer;
  background: #fbfcfe;
}
.dropzone.drag { border-color: var(--brand); background: #eaf2fe; }
.dz-icon { font-size: 36px; }
.dz-title { font-weight: 600; margin: 8px 0 4px; }
.dz-sub { color: var(--muted); font-size: 13.5px; margin: 0 0 14px; }
.file-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.file-chip {
  display: flex; align-items: center; gap: 8px;
  border: 1px solid var(--line); border-radius: 10px;
  padding: 4px 8px 4px 4px; background: #fff; cursor: pointer;
  max-width: 100%;
}
.file-chip.active { border-color: var(--brand); box-shadow: 0 0 0 1px var(--brand); }
.file-chip img { width: 44px; height: 44px; object-fit: cover; border-radius: 6px; display: block; }
.file-chip span { font-size: 12.5px; word-break: break-all; }
.file-chip .rm { border: none; background: none; color: var(--err); font-size: 16px; cursor: pointer; padding: 2px 6px; }
.preview-wrap {
  position: relative;
  display: inline-block;
  max-width: 100%;
  background-color: #fff;
  background-image:
    linear-gradient(45deg, #dfe3e8 25%, transparent 25%, transparent 75%, #dfe3e8 75%),
    linear-gradient(45deg, #dfe3e8 25%, transparent 25%, transparent 75%, #dfe3e8 75%);
  background-size: 20px 20px;
  background-position: 0 0, 10px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  touch-action: none;
}
.preview-wrap canvas { display: block; max-width: 100%; height: auto; }
.overlay-layer { position: absolute; inset: 0; }
.overlay-rect {
  position: absolute;
  border: 2px solid var(--brand);
  background: rgba(21, 101, 216, 0.12);
  cursor: move;
}
.overlay-handle {
  position: absolute; width: 18px; height: 18px;
  background: var(--brand); border: 2px solid #fff; border-radius: 50%;
  transform: translate(-50%, -50%);
}
.overlay-handle.nw { left: 0; top: 0; cursor: nwse-resize; }
.overlay-handle.ne { left: 100%; top: 0; cursor: nesw-resize; }
.overlay-handle.sw { left: 0; top: 100%; cursor: nesw-resize; }
.overlay-handle.se { left: 100%; top: 100%; cursor: nwse-resize; }
.img-info { font-size: 13.5px; color: var(--muted); margin: 10px 0; word-break: break-word; }
.row { display: flex; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.gap { gap: 10px; }
.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 15px;
  cursor: pointer;
}
.btn:hover { border-color: #b9c4d0; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-small { padding: 7px 13px; font-size: 13.5px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.tool-btn.active, .sm-preset.active, .ratio-btn.active, .bg-swatch.active {
  background: var(--brand); border-color: var(--brand); color: #fff;
}
.tool-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.tool-grid .tool-btn { width: 100%; text-align: center; }
label { display: block; margin: 10px 0; font-size: 14.5px; }
label.inline-label { display: inline-flex; align-items: center; gap: 6px; margin: 0; }
label.check { display: flex; align-items: center; gap: 6px; }
input[type="text"], input[type="number"], input[type="tel"], select {
  width: 100%; max-width: 320px;
  padding: 9px 10px; margin-top: 4px;
  border: 1px solid var(--line); border-radius: 8px;
  font-size: 15px; background: #fff; color: var(--ink);
}
input[type="range"] { width: 100%; max-width: 320px; }
input[type="color"] { padding: 2px; width: 52px; height: 36px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.qr-out { margin-top: 12px; }
.pp-frame { width: 100%; height: 560px; border: 1px solid var(--line); border-radius: 8px; background: #fff; margin-top: 12px; }
.qr-out canvas, .qr-out img { max-width: 100%; height: auto; border: 1px solid var(--line); border-radius: 8px; }
.status { min-height: 24px; font-size: 14.5px; margin: 4px 0 0; }
.status.err { color: var(--err); }
.status.ok { color: var(--ok); }
.a4-page {
  width: 100%; max-width: 794px; min-height: 1123px;
  margin: 0 auto; padding: 40px;
  background: #fff; border: 1px solid var(--line);
}
.a4-page h1 { font-size: 24px; margin: 0 0 20px; text-align: center; }
.a4-page figure { margin: 0 0 20px; page-break-inside: avoid; }
.a4-page img { max-width: 100%; display: block; margin: 0 auto; }
.a4-page figcaption { text-align: center; color: var(--muted); font-size: 14px; margin-top: 6px; }
.site-footer { text-align: center; color: var(--muted); font-size: 13px; padding: 8px 16px 24px; }
.steps { font-size: 14px; color: var(--muted); margin: 8px 0; padding-left: 22px; }
.steps code { background: #eef1f4; padding: 1px 5px; border-radius: 4px; font-size: 13px; word-break: break-all; }
.site-footer p { margin: 4px 0; }
@media (min-width: 640px) {
  .tool-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 640px) {
  .pp-frame { height: 480px; }
}
@media print {
  body * { visibility: hidden; }
  #a4Preview, #a4Preview * { visibility: visible; }
  #a4Preview {
    position: absolute; top: 0; left: 0; width: 100%;
    border: none; padding: 0; min-height: 0;
  }
  @page { size: A4; margin: 12mm; }
}
