:root {
  --paper: #f6f4ef;
  --card: #ffffff;
  --ink: #16181d;
  --muted: #6b6f78;
  --line: #e4e0d7;
  --accent: #e8452c;
  --accent-ink: #b83118;
  --inv: #e8452c;
  --dn: #2f6fdf;
  --po: #1f9d6b;
  --ok: #1f9d6b;
  --warn: #c98a06;
  --radius: 14px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 16px/1.5 var(--font); }
button, input { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.top { display: flex; align-items: center; justify-content: space-between; gap: 16px; max-width: 980px; margin: 0 auto; padding: 22px 20px; }
.brand { display: inline-flex; align-items: center; gap: 2px; font-weight: 800; font-size: 22px; letter-spacing: -0.02em; color: var(--ink); text-decoration: none; }
.mark { display: inline-grid; place-items: center; width: 30px; height: 30px; margin-right: 4px; border-radius: 8px; background: var(--accent); color: #fff; font-size: 19px; }
.privacy { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.privacy svg { width: 15px; height: 15px; fill: none; stroke: var(--ok); stroke-width: 2; }

main { max-width: 980px; margin: 0 auto; padding: 0 20px 40px; }
.hero { padding: 28px 0 34px; }
.hero h1 { margin: 0 0 14px; font-size: clamp(34px, 6vw, 58px); line-height: 1.02; letter-spacing: -0.035em; font-weight: 800; }
.hero h1 em { font-style: normal; color: var(--accent); }
.hero p { margin: 0; max-width: 560px; font-size: 18px; color: var(--muted); }

.step { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; margin-bottom: 18px; }
.step-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.step-head h2 { margin: 0; font-size: 20px; letter-spacing: -0.01em; }
.num { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--ink); color: #fff; font-size: 14px; font-weight: 700; flex: none; }

.drop { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 38px 20px; border: 2px dashed #cfc9bc; border-radius: 12px; background: #fbfaf7; cursor: pointer; text-align: center; transition: border-color .15s, background .15s; }
.drop svg { width: 46px; height: 46px; color: var(--accent); margin-bottom: 6px; }
.drop strong { font-size: 18px; }
.drop span { color: var(--muted); font-size: 14px; }
.drop:hover, .drop.over { border-color: var(--accent); background: #fff4f1; }
.has-files .drop { padding: 18px; flex-direction: row; justify-content: center; gap: 10px; }
.has-files .drop svg { width: 26px; height: 26px; margin: 0; }
.has-files .drop span { display: none; }

.file-bar { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; margin: 16px 0 8px; font-size: 14px; color: var(--muted); }
.bar-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.ghost { border: 1px solid var(--line); background: #fff; padding: 6px 12px; border-radius: 8px; cursor: pointer; font-size: 14px; }
.ghost:hover { border-color: var(--ink); }
.ghost.danger:hover { border-color: var(--accent); color: var(--accent); }

.t0 { background: var(--inv) !important; } .t1 { background: var(--dn) !important; } .t2 { background: var(--po) !important; }

.modes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.mode input { position: absolute; opacity: 0; pointer-events: none; }
.mode-body { display: flex; flex-direction: column; gap: 4px; height: 100%; padding: 16px; border: 1.5px solid var(--line); border-radius: 12px; cursor: pointer; transition: border-color .15s, box-shadow .15s; }
.mode-body:hover { border-color: #bdb6a8; }
.mode input:checked + .mode-body { border-color: var(--accent); box-shadow: 0 0 0 3px #fbd9d2; }
.mode input:focus-visible + .mode-body { outline: 2px solid var(--ink); outline-offset: 2px; }
.mode strong { font-size: 15px; }
.mode small { color: var(--muted); font-size: 13px; line-height: 1.35; }
.diagram { display: flex; align-items: flex-end; gap: 3px; height: 34px; margin-bottom: 8px; }
.diagram i { display: block; width: 16px; height: 22px; border-radius: 2px; }
.diagram b { color: var(--muted); font-weight: 400; margin-left: 2px; }
.diagram.stack i { width: 22px; height: 30px; box-shadow: 3px -3px 0 #fff, 4px -4px 0 currentColor, 7px -7px 0 #fff, 8px -8px 0 currentColor; margin-right: 12px; }
.diagram.stack .d-inv { color: var(--inv); } .diagram.stack .d-dn { color: var(--dn); } .diagram.stack .d-po { color: var(--po); }
.diagram.book { padding: 4px; border: 1.5px solid #cfc9bc; border-radius: 4px; height: 34px; align-items: center; width: max-content; }
.diagram.book i { width: 9px; height: 20px; gap: 0; }
.d-inv { background: var(--inv); } .d-dn { background: var(--dn); } .d-po { background: var(--po); }

.per-set { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; margin-top: 20px; font-size: 15px; }
.stepper { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.stepper button { width: 38px; border: 0; background: #fbfaf7; cursor: pointer; font-size: 18px; }
.stepper button:hover { background: var(--paper); }
.stepper input { width: 54px; border: 0; border-left: 1px solid var(--line); border-right: 1px solid var(--line); text-align: center; padding: 8px 0; font-weight: 700; -moz-appearance: textfield; }
.stepper input::-webkit-inner-spin-button { -webkit-appearance: none; }
.hint { color: var(--muted); font-size: 14px; }
.warn { margin-top: 16px; padding: 12px 14px; border-radius: 10px; background: #fff7e0; border: 1px solid #f1d98a; color: #6d4c00; font-size: 14px; }
.warn p { margin: 0; } .warn p + p { margin-top: 6px; }

.naming { margin-bottom: 22px; }
.seg { display: inline-flex; padding: 3px; background: var(--paper); border-radius: 10px; gap: 2px; }
.seg button { border: 0; background: none; padding: 7px 14px; border-radius: 8px; cursor: pointer; font-size: 14px; font-weight: 600; color: var(--muted); }
.seg button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.naming > .hint { margin: 10px 0 0; }
.field { display: block; margin-top: 14px; font-size: 14px; font-weight: 600; }
.field small { font-weight: 400; color: var(--muted); }
.field input { display: block; width: 100%; margin-top: 6px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; font-family: var(--mono); font-size: 14px; }
.field input:focus { outline: 2px solid var(--accent); border-color: transparent; }

.pick p { margin: 14px 0 10px; font-size: 14px; color: var(--muted); }
.pick-stage { position: relative; max-width: 640px; min-height: 160px; max-height: 520px; overflow: auto; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #fbfaf7; }
.pick-stage canvas { display: block; width: 100%; height: auto; }
.pick-layer { position: absolute; left: 0; top: 0; width: 100%; aspect-ratio: var(--ar, auto); }
.pick-layer button { position: absolute; padding: 0; border: 0; background: transparent; border-radius: 3px; cursor: pointer; }
.pick-layer button:hover { background: rgba(232, 69, 44, .18); outline: 1.5px solid var(--accent); }
.pick-layer button.chosen { background: rgba(232, 69, 44, .28); outline: 2px solid var(--accent); }

.results-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.results-head h3 { margin: 0; font-size: 16px; }
.stat { font-size: 14px; color: var(--muted); }
.stat b { color: var(--ok); }
.stat b.bad { color: var(--warn); }
.table-wrap { max-height: 560px; overflow: auto; border: 1px solid var(--line); border-radius: 10px; }
.results { width: 100%; border-collapse: collapse; font-size: 14px; }
.results th { position: sticky; top: 0; z-index: 1; background: #fbfaf7; text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; padding: 9px 10px; border-bottom: 1px solid var(--line); }
.results td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.results tr:last-child td { border-bottom: 0; }
.results td:first-child { color: var(--muted); font-variant-numeric: tabular-nums; width: 40px; }
.thumb { width: 52px; height: 68px; border: 1px solid var(--line); border-radius: 4px; background: #f3f1ec; display: grid; place-items: center; overflow: hidden; }
.thumb canvas { width: 100%; height: 100%; object-fit: contain; }
.name-cell { display: flex; align-items: center; gap: 8px; }
.name-cell input { flex: 1; min-width: 120px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; font-family: var(--mono); font-size: 13px; }
.name-cell input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.name-cell .ext { color: var(--muted); font-family: var(--mono); font-size: 13px; }
.badge { flex: none; width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 700; color: #fff; }
.badge.ok { background: var(--ok); } .badge.miss { background: var(--warn); } .badge.dup { background: var(--accent); }
.pages { display: flex; gap: 3px; }
.pages i { width: 8px; height: 12px; border-radius: 2px; background: #bbb; }
.results .dl-one { border: 1px solid var(--line); background: #fff; width: 32px; height: 32px; border-radius: 8px; cursor: pointer; display: grid; place-items: center; }
.results .dl-one:hover { border-color: var(--ink); }
.results .dl-one svg { width: 16px; height: 16px; }

.dl { position: sticky; bottom: 0; z-index: 10; display: flex; align-items: center; flex-wrap: wrap; gap: 14px; padding: 16px 0 20px; background: linear-gradient(to top, var(--paper) 70%, rgba(246,244,239,0)); }
.primary { border: 0; background: var(--accent); color: #fff; font-weight: 700; font-size: 17px; padding: 14px 26px; border-radius: 12px; cursor: pointer; box-shadow: 0 6px 16px rgba(232,69,44,.28); }
.primary:hover { background: var(--accent-ink); }
.primary:disabled { opacity: .55; cursor: progress; }
.progress { flex-basis: 100%; height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.progress div { height: 100%; width: 0; background: var(--accent); transition: width .15s; }

.spinner { position: absolute; inset: 0; margin: auto; width: 26px; height: 26px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.foot { max-width: 980px; margin: 0 auto; padding: 10px 20px 30px; color: var(--muted); font-size: 13px; }

@media (max-width: 720px) {
  .modes { grid-template-columns: 1fr; }
  .step { padding: 18px; }
  .privacy { display: none; }
  .results th:nth-child(4), .results td:nth-child(4) { display: none; }
}

/* ---------- File grid ---------- */
.file-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; padding: 4px 2px 2px; }
.fcard { position: relative; display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 14px 10px 10px; background: #fbfaf7; border: 1.5px solid var(--line); border-radius: 12px; cursor: grab; transition: border-color .15s, box-shadow .15s, transform .15s; user-select: none; }
.fcard:hover { border-color: #bdb6a8; box-shadow: 0 6px 18px rgba(22,24,29,.08); }
.fcard.dragging { opacity: .35; }
.fcard.drop-before::before { content: ""; position: absolute; left: -9px; top: 8px; bottom: 8px; width: 3px; border-radius: 2px; background: var(--accent); }
.fcard .page { position: relative; width: 100%; aspect-ratio: 3 / 4; display: grid; place-items: center; }
.fcard .page canvas { max-width: 100%; max-height: 100%; box-shadow: 0 1px 4px rgba(0,0,0,.18); background: #fff; }
.fcard .page .spinner { position: static; }
.fcard .fname { width: 100%; font-size: 13px; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fcard .pos { position: absolute; top: 8px; left: 8px; z-index: 2; min-width: 24px; height: 24px; padding: 0 7px; border-radius: 12px; background: var(--ink); color: #fff; font-size: 12px; font-weight: 700; display: grid; place-items: center; }
.fcard .pos.t0 { background: var(--inv); } .fcard .pos.t1 { background: var(--dn); } .fcard .pos.t2 { background: var(--po); }
.fcard .tip { position: absolute; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%); z-index: 5; padding: 5px 10px; border-radius: 6px; background: #5f636b; color: #fff; font-size: 13px; font-weight: 700; white-space: nowrap; pointer-events: none; opacity: 0; transition: opacity .12s; }
.fcard .tip::after { content: ""; position: absolute; top: 100%; left: 50%; margin-left: -6px; border: 6px solid transparent; border-top-color: #5f636b; }
.fcard:hover .tip { opacity: 1; }
.fcard .acts { position: absolute; top: 8px; right: 8px; z-index: 2; display: flex; flex-direction: column; gap: 5px; opacity: 0; transition: opacity .12s; }
.fcard:hover .acts, .fcard:focus-within .acts { opacity: 1; }
.fcard .acts button { width: 30px; height: 30px; border: 1px solid var(--line); border-radius: 50%; background: #fff; cursor: pointer; display: grid; place-items: center; font-size: 13px; box-shadow: 0 2px 6px rgba(0,0,0,.1); }
.fcard .acts button:hover { border-color: var(--ink); }
.fcard .acts button[data-a=rm]:hover { border-color: var(--accent); color: var(--accent); }
.fcard .acts svg { width: 15px; height: 15px; }
@media (hover: none) { .fcard .acts { opacity: 1; } }

/* result thumbnails open the viewer */
.thumb { cursor: zoom-in; transition: box-shadow .15s; }
.thumb:hover { box-shadow: 0 0 0 2px var(--accent); }

/* ---------- Viewer ---------- */
.viewer { position: fixed; inset: 0; z-index: 50; display: flex; flex-direction: column; background: rgba(28,30,35,.94); }
.viewer-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 16px; background: #16181d; color: #fff; }
.viewer-title { min-width: 0; display: flex; flex-direction: column; }
.viewer-title strong { font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-title span { font-size: 12px; color: #a6abb5; }
.viewer-tools { display: flex; align-items: center; gap: 6px; flex: none; }
.viewer-tools button { min-width: 36px; height: 36px; border: 1px solid #3a3e47; border-radius: 9px; background: #23262d; color: #fff; cursor: pointer; font-size: 18px; }
.viewer-tools button:hover { background: #2f333c; }
.viewer-tools .zval { min-width: 70px; font-size: 14px; font-variant-numeric: tabular-nums; }
.viewer-tools .close { margin-left: 8px; font-size: 16px; }
.viewer-body { flex: 1; overflow: auto; padding: 24px; display: flex; flex-direction: column; align-items: flex-start; gap: 18px; }
.vpage { position: relative; flex: none; margin: 0 auto; background: #fff; box-shadow: 0 6px 24px rgba(0,0,0,.45); }
.vpage canvas { display: block; width: 100%; height: 100%; }
.vpage .vlabel { position: absolute; top: 100%; left: 0; margin-top: 4px; font-size: 12px; color: #a6abb5; }
body.no-scroll { overflow: hidden; }
body.file-over #step-files { border-color: var(--accent); box-shadow: 0 0 0 4px #fbd9d2; }
body.file-over .drop { border-color: var(--accent); background: #fff4f1; }
body.file-over .file-grid { background: #fff8f6; border-radius: 10px; }
