:root {
  --cream: #f6f1ea;
  --ink: #140c09;
  --paper: #fff;
  --field: #fffdfa;
  --line: rgba(20, 12, 9, 0.11);
  --muted: rgba(20, 12, 9, 0.6);
  --orange: #e2702f;
  --orange-dark: #ac4e18;
  --orange-soft: #fbe6d8;
  --radius: 20px;
  --display: 'Jost', ui-sans-serif, system-ui, sans-serif;
  --sans: 'Inter', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--cream); color: var(--ink); font: 15px/1.5 var(--sans); -webkit-font-smoothing: antialiased; min-height: 100vh; display: flex; flex-direction: column; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
.muted { color: var(--muted); }
.wrap { width: 100%; max-width: 1080px; margin: 0 auto; padding: 0 16px; }
main { flex: 1; }

/* header */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 18px; padding-bottom: 10px; flex-wrap: wrap; }
.brand { display: flex; align-items: baseline; gap: 8px; text-decoration: none; }
.clip { width: 26px; height: 26px; align-self: center; fill: none; stroke: var(--orange); stroke-width: 2.6; stroke-linecap: round; }
.wordmark { font: 700 30px/1 var(--display); letter-spacing: -0.02em; }
.by { font-size: 13px; color: var(--muted); font-weight: 500; }
.private { margin: 0; font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 7px; }
.lock { width: 8px; height: 8px; border-radius: 50%; background: #3aa76d; box-shadow: 0 0 0 3px rgba(58, 167, 109, 0.18); }

.intro { padding: 26px 0 18px; }
.intro h1 { font: 600 clamp(30px, 6vw, 48px)/1.05 var(--display); letter-spacing: -0.02em; margin: 0 0 8px; }
.intro p { margin: 0; color: var(--muted); font-size: 17px; }
.has-files .intro { display: none; }

/* drop zone */
.drop { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; text-align: center; padding: 48px 20px; border: 2px dashed rgba(226, 112, 47, 0.45); border-radius: var(--radius); background: var(--field); cursor: pointer; transition: background 0.15s, border-color 0.15s; outline: none; }
.drop:hover, .drop:focus-visible { background: #fff; border-color: var(--orange); }
.drop svg { width: 44px; height: 44px; fill: none; stroke: var(--orange); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; margin-bottom: 4px; }
.drop strong { font: 600 21px/1.2 var(--display); }
.drop span { color: var(--muted); font-size: 14px; }
.drop .kinds { font-size: 12px; letter-spacing: 0.02em; margin-top: 6px; }
.has-files .drop { display: none; }

.dropveil { position: fixed; inset: 0; background: rgba(246, 241, 234, 0.88); border: 3px dashed var(--orange); display: none; align-items: center; justify-content: center; z-index: 50; pointer-events: none; }
.dropveil span { font: 600 28px var(--display); color: var(--orange-dark); }
.dragging .dropveil { display: flex; }

/* workspace */
.work { padding-top: 14px; }
.work-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.summary { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.head-actions { display: flex; gap: 8px; }
.ghost { background: transparent; border: 1px solid var(--line); border-radius: 999px; padding: 7px 14px; font-size: 14px; font-weight: 500; }
.ghost:hover { background: var(--paper); }

.files { display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 12px; margin-bottom: 16px; max-height: 58vh; overflow-y: auto; padding: 2px; -webkit-overflow-scrolling: touch; }
.card { position: relative; background: var(--paper); border: 1px solid var(--line); border-radius: 14px; padding: 8px; user-select: none; -webkit-user-select: none; touch-action: manipulation; cursor: grab; }
.card.selected { border-color: var(--orange); box-shadow: 0 0 0 2px var(--orange); }
.card.sortable-ghost { opacity: 0.35; }
.card.sortable-chosen { box-shadow: 0 8px 22px rgba(20, 12, 9, 0.16); }
.thumb { aspect-ratio: 1; display: flex; align-items: center; justify-content: center; background: #f3eee8; border-radius: 9px; overflow: hidden; }
.thumb img, .thumb canvas { max-width: 100%; max-height: 100%; object-fit: contain; transition: transform 0.2s; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); background: #fff; }
.page .thumb canvas { max-width: 92%; max-height: 92%; }
.page-no { font-weight: 600; font-variant-numeric: tabular-nums; }
.bar { display: flex; align-items: center; gap: 4px; margin-top: 7px; }
.label { flex: 1; min-width: 0; font-size: 12.5px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.size { position: absolute; top: 13px; left: 13px; font-size: 11px; font-weight: 600; background: rgba(255, 255, 255, 0.9); padding: 1px 6px; border-radius: 6px; }
.icon { width: 30px; height: 30px; flex: none; border: 1px solid var(--line); border-radius: 50%; background: var(--field); font-size: 14px; line-height: 1; display: inline-flex; align-items: center; justify-content: center; }
.icon:hover { background: var(--orange-soft); border-color: var(--orange); }
.pdf-badge { font: 700 15px var(--display); color: #fff; background: #d6452c; padding: 10px 12px; border-radius: 8px; }
.pdf-badge.locked { background: var(--muted); }
.spinner, .busy .go::after { width: 18px; height: 18px; border: 2px solid var(--line); border-top-color: var(--orange); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* tools panel */
.panel { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.tools { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 14px; scrollbar-width: none; }
.tools::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 1px solid var(--line); background: var(--field); border-radius: 999px; padding: 8px 15px; font-weight: 500; font-size: 14px; white-space: nowrap; }
.chip:hover { border-color: var(--orange); }
.chip.on { background: var(--ink); color: #fff; border-color: var(--ink); }

.options { display: flex; flex-wrap: wrap; gap: 12px 28px; }
.opt { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.opt-label { font-size: 13px; color: var(--muted); font-weight: 500; min-width: 54px; }
.seg { display: inline-flex; background: #f3eee8; border-radius: 999px; padding: 3px; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; border-radius: 999px; padding: 6px 13px; font-size: 14px; font-weight: 500; color: var(--muted); }
.seg button.on { background: var(--paper); color: var(--ink); box-shadow: 0 1px 3px rgba(20, 12, 9, 0.14); }
.range { display: flex; align-items: center; gap: 10px; }
.range input { width: min(220px, 50vw); accent-color: var(--orange); }
.range output { font-weight: 600; min-width: 40px; font-variant-numeric: tabular-nums; }
.field { display: flex; align-items: center; gap: 6px; }
.field input { border: 1px solid var(--line); background: var(--field); border-radius: 10px; padding: 8px 11px; width: min(240px, 60vw); font-size: 16px; }
.field input[type=number] { width: 110px; }
.field input:focus { outline: 2px solid var(--orange); outline-offset: 1px; }
.unit { color: var(--muted); font-size: 14px; }
.hint { margin: 12px 0 0; font-size: 13.5px; color: var(--muted); }

.go-row { display: flex; align-items: center; gap: 14px; margin-top: 16px; flex-wrap: wrap; }
.go { display: inline-flex; align-items: center; gap: 10px; border: 0; background: var(--orange); color: #fff; font: 600 17px var(--display); padding: 12px 26px; border-radius: 999px; box-shadow: 0 4px 14px rgba(226, 112, 47, 0.3); }
.go:hover { background: var(--orange-dark); }
.go:disabled { opacity: 0.6; cursor: progress; }
.busy .go-row .go::after { content: ''; border-color: rgba(255, 255, 255, 0.35); border-top-color: #fff; }
.status { color: var(--muted); font-size: 14px; }

/* crop */
.crop { display: flex; justify-content: center; margin-bottom: 14px; }
.frame { position: relative; line-height: 0; touch-action: none; }
.frame img { max-width: 100%; max-height: 55vh; display: block; border-radius: 6px; }
.crop-box { position: absolute; border: 2px solid #fff; box-shadow: 0 0 0 9999px rgba(20, 12, 9, 0.5); cursor: move; touch-action: none; }
.frame { overflow: hidden; border-radius: 6px; }
.crop-box i { position: absolute; width: 22px; height: 22px; background: #fff; border: 2px solid var(--orange); border-radius: 50%; }
.crop-box i[data-h=nw] { left: -11px; top: -11px; cursor: nwse-resize; }
.crop-box i[data-h=ne] { right: -11px; top: -11px; cursor: nesw-resize; }
.crop-box i[data-h=sw] { left: -11px; bottom: -11px; cursor: nesw-resize; }
.crop-box i[data-h=se] { right: -11px; bottom: -11px; cursor: nwse-resize; }

/* result */
.result { margin-top: 16px; background: var(--ink); color: #fff; border-radius: var(--radius); padding: 18px; }
.result .muted { color: rgba(255, 255, 255, 0.65); }
.result-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; }
.result h2 { font: 600 24px/1.1 var(--display); margin: 0 0 4px; }
.result p { margin: 0; overflow-wrap: anywhere; }
.result-list { list-style: none; margin: 14px 0 0; padding: 0; max-height: 220px; overflow-y: auto; }
.result-list li { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-top: 1px solid rgba(255, 255, 255, 0.12); font-size: 14px; cursor: pointer; }
.result-list li:hover .name { text-decoration: underline; }
.result-list .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.result-actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.result .ghost { color: #fff; border-color: rgba(255, 255, 255, 0.25); }
.result .ghost:hover { background: rgba(255, 255, 255, 0.08); }

/* what it does */
.what { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; margin: 36px 0 10px; }
.what div { border-top: 2px solid var(--ink); padding-top: 10px; }
.what h3 { font: 600 18px var(--display); margin: 0 0 4px; }
.what p { margin: 0; color: var(--muted); font-size: 14px; }

.foot { padding-top: 24px; padding-bottom: 76px; font-size: 13px; color: var(--muted); }

.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); max-width: min(520px, calc(100vw - 32px)); background: var(--ink); color: #fff; padding: 12px 16px; border-radius: 14px; font-size: 14px; z-index: 60; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25); cursor: pointer; }

/* Pay it forward: a quiet tip link, always in the corner */
.payfwd { position: fixed; right: 16px; bottom: 16px; z-index: 40; display: inline-flex; align-items: center; gap: 7px; padding: 10px 15px; border-radius: 999px; background: var(--ink); color: #fff; font: 600 14px var(--sans); text-decoration: none; box-shadow: 0 8px 24px rgba(20, 12, 9, 0.22); transition: transform 0.15s, background 0.15s; }
.payfwd svg { color: var(--orange); }
.payfwd:hover { background: var(--orange); transform: translateY(-1px); }
.payfwd:hover svg { color: #fff; }
.payfwd:focus-visible { outline: 3px solid var(--orange); outline-offset: 3px; }

@media (max-width: 560px) {
  .files { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; max-height: 46vh; }
  .card { padding: 6px; }
  .label { font-size: 11.5px; }
  .icon { width: 28px; height: 28px; }
  .tools { flex-wrap: wrap; overflow: visible; }
  .chip { padding: 7px 12px; }
  .options { flex-direction: column; gap: 12px; }
  .opt-label { min-width: 0; width: 100%; }
  .go { width: 100%; justify-content: center; }
  .result-head .go { width: 100%; }
  .private { width: 100%; }
}
