:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef1f4;
  --text: #16191d;
  --muted: #5b6470;
  --border: #d9dee4;
  --accent: #0f766e;
  --accent-text: #ffffff;
  --accent-soft: #e0f2ef;
  --danger: #b42318;
  --success: #067647;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 4px 16px rgb(16 24 40 / 6%);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101317;
    --surface: #181c21;
    --surface-2: #222830;
    --text: #e8ebef;
    --muted: #9aa4b1;
    --border: #2e3640;
    --accent: #2dd4bf;
    --accent-text: #062a26;
    --accent-soft: #123a36;
    --danger: #f97066;
    --success: #47cd89;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); }
code { font-size: 0.9em; background: var(--surface-2); padding: 0.1em 0.35em; border-radius: 6px; }
h1, h2 { line-height: 1.2; margin: 0 0 0.5em; }
h1 { font-size: clamp(1.6rem, 4.5vw, 2.4rem); letter-spacing: -0.02em; }
h2 { font-size: 1.25rem; }
[hidden] { display: none !important; }

.wrap { width: 100%; max-width: 960px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--muted); font-weight: normal; }
.small { font-size: 0.9rem; }

.skip { position: absolute; left: -999px; }
.skip:focus { left: 16px; top: 8px; z-index: 10; background: var(--surface); padding: 8px 12px; border-radius: 8px; }

/* Cabeçalho */
.site-header { border-bottom: 1px solid var(--border); background: var(--surface); }
.header-inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 60px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text); text-decoration: none; }
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 0.85rem; padding: 4px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--text);
}
.badge .icon { width: 1.05em; height: 1.05em; color: var(--accent); }

/* Ícones SVG (sprite no index.html): mesmo traço em todo o app, cor herdada do texto. */
.icon {
  width: 1.2em; height: 1.2em; flex: none;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

.hero { padding: 40px 0 24px; }
.lead { font-size: 1.1rem; color: var(--muted); max-width: 640px; margin: 0; }

/* Botões */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 8px 16px; flex-wrap: wrap; text-align: center;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn:disabled { opacity: 0.6; cursor: progress; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-ghost { background: transparent; }
.btn-lg { min-height: 52px; padding: 12px 22px; font-size: 1.05rem; }
/* Hover só onde existe ponteiro que paira: no toque ele "gruda" depois do toque. */
@media (hover: hover) {
  .btn:hover:not(:disabled) { border-color: var(--accent); }
  .btn-primary:hover:not(:disabled) { filter: brightness(1.08); }
}
.btn:active:not(:disabled) { transform: translateY(1px); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
::selection { background: var(--accent-soft); color: var(--text); }
kbd {
  font: inherit; font-size: 0.9em; color: var(--text);
  padding: 0 0.4em; border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 6px;
  background: var(--surface-2);
}

/* Área de entrada */
.dropzone {
  border: 2px dashed var(--border); border-radius: var(--radius);
  background: var(--surface); padding: 32px 16px; text-align: center;
  transition: border-color 0.15s, background 0.15s;
}
.dropzone.dragging { border-color: var(--accent); background: var(--accent-soft); }
.dropzone-actions { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; }
.hint { margin: 16px 0 0; color: var(--muted); }

/* "Tirar foto" só faz sentido com câmera e toque; arrastar e colar, só com mouse/trackpad.
   Sem toque, "Escolher arquivos" assume o papel de botão principal. */
@media not all and (pointer: coarse) {
  .touch-only { display: none; }
  .btn-pick { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
  .btn-pick:hover:not(:disabled) { filter: brightness(1.08); }
}
@media (pointer: coarse) {
  .pointer-only { display: none; }
}

/* Páginas */
.workspace { margin-top: 24px; }
.workspace-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.pages {
  list-style: none; margin: 8px 0 0; padding: 0;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px;
}
.page-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 8px; display: flex; flex-direction: column; gap: 8px; box-shadow: var(--shadow);
}
/* A miniatura é um botão: abre a página em tela cheia. Mostra a página inteira, já recortada e filtrada. */
.thumb {
  position: relative; width: 100%; aspect-ratio: 3 / 4; padding: 0; border: 0;
  background: var(--surface-2); border-radius: 8px; cursor: zoom-in;
  display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.thumb:disabled { cursor: default; }
.thumb img { max-width: 100%; max-height: 100%; display: block; box-shadow: 0 0 0 1px var(--border); }
.thumb-zoom {
  position: absolute; right: 6px; bottom: 6px; width: 32px; height: 32px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
}
.thumb-zoom .icon { width: 18px; height: 18px; }
.btn-crop { width: 100%; padding: 6px 8px; font-size: 0.92rem; }
/* Página de documento do Word: de qual arquivo veio e qual página dele é. */
.page-source {
  margin: 0; min-height: 36px; display: flex; align-items: center; gap: 6px;
  font-size: 0.88rem; color: var(--muted); white-space: nowrap;
}
.page-source .icon { width: 18px; height: 18px; flex: none; }
.page-source-name { overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.hint + .hint { margin-top: 4px; }
/* Controles do cartão em duas linhas: número + remover em cima, mover/girar embaixo.
   Remover fica numa linha própria, longe dos outros botões. */
.page-tools {
  --tool: 36px;
  display: grid; grid-template-columns: repeat(3, minmax(var(--tool), 1fr)); gap: 8px 4px; align-items: center;
}
.page-num { grid-column: 1 / 3; font-weight: 700; padding-left: 4px; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 100%; height: var(--tool); padding: 0;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text); cursor: pointer;
}
.icon-btn .icon { width: 20px; height: 20px; }
.icon-btn-remove { grid-column: 3; justify-self: end; width: var(--tool); color: var(--muted); }
@media (hover: hover) {
  .icon-btn:hover:not(:disabled) { border-color: var(--accent); }
  .icon-btn-remove:hover:not(:disabled) { border-color: var(--danger); color: var(--danger); }
}
.icon-btn:disabled { opacity: 0.35; cursor: default; }
.page-filter { width: 100%; }

/* Toque: alvos de 44 × 44 px. A grade só põe dois cartões lado a lado se os três botões couberem. */
@media (pointer: coarse) {
  .pages { grid-template-columns: repeat(auto-fill, minmax(min(100%, 156px), 1fr)); }
  .page-card { padding: 6px; }
  .page-tools { --tool: 44px; }
}

/* Celular em pé: uma página por linha, grande o bastante para conferir o resultado sem abrir nada.
   Os controles cabem todos numa linha só. */
@media (max-width: 520px) {
  .pages { grid-template-columns: 1fr; gap: 16px; }
  .page-card { padding: 10px; }
  .thumb { aspect-ratio: auto; height: min(62vh, 520px); }
  .page-tools { --tool: 44px; grid-template-columns: auto repeat(3, minmax(var(--tool), 1fr)) var(--tool); gap: 8px; }
  .page-num { grid-column: 1; padding: 0 8px 0 4px; font-size: 1.1rem; }
  .icon-btn-remove { grid-column: 5; grid-row: 1; }
}

/* Ajustes */
select, input[type="text"] {
  min-height: 44px; padding: 6px 10px; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  max-width: 100%;
}
@media (hover: hover) {
  select:hover:not(:disabled), input[type="text"]:hover:not(:disabled) { border-color: var(--accent); }
}
select:disabled, input[type="text"]:disabled { opacity: 0.6; cursor: not-allowed; }
.settings {
  margin-top: 20px; padding: 16px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
  display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px;
}
.field { display: flex; flex-direction: column; gap: 4px; font-size: 0.92rem; font-weight: 600; }
.field select, .field input { font-weight: normal; }
.field-wide { grid-column: 1 / -1; }
.tip {
  margin: 0; padding: 10px 12px; border-radius: 10px; background: var(--accent-soft);
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; font-size: 0.92rem;
}
.tip span { flex: 1 1 240px; }
/* PDF pesado: no topo da lista de páginas, com borda de destaque. */
.compress-tip { margin: 8px 0 4px; border: 1px solid var(--accent); }
.compress-tip .btn { flex: none; }

.actions { margin-top: 20px; display: flex; justify-content: center; }
.actions .btn { width: 100%; max-width: 360px; }

.result {
  margin-top: 16px; padding: 20px; text-align: center;
  background: var(--accent-soft); border-radius: var(--radius);
}
.result-title { display: flex; align-items: center; justify-content: center; gap: 8px; font-size: 1.2rem; font-weight: 700; margin: 0; }
.result-title .icon { color: var(--accent); }
.result-actions { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; margin-top: 12px; }
/* Prévia do resultado: um bloco por arquivo que vai sair, com as miniaturas das páginas dele. */
.output-preview { border-top: 1px solid var(--border); padding-top: 12px; }
.output-title { margin: 0; font-size: 0.92rem; font-weight: 600; }
.output-summary { margin: 2px 0 8px; font-size: 0.92rem; color: var(--muted); }
.output-summary.error { color: var(--danger); }
.output-files { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; max-height: 420px; overflow: auto; }
.output-files li { border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; background: var(--surface-2); }
.output-name { margin: 0 0 6px; display: flex; align-items: center; gap: 6px; font-size: 0.92rem; overflow-wrap: anywhere; }
.output-name .icon { width: 18px; height: 18px; flex: none; color: var(--accent); }
.output-thumbs { display: flex; flex-wrap: wrap; gap: 6px; align-items: flex-end; }
.output-thumb {
  position: relative; width: 56px; height: 72px; padding: 0; border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface); cursor: zoom-in; display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.output-thumb img { max-width: 100%; max-height: 100%; display: block; }
.output-thumb span {
  position: absolute; left: 3px; bottom: 3px; min-width: 18px; padding: 0 4px; border-radius: 6px;
  font-size: 0.72rem; font-weight: 700; line-height: 18px; text-align: center; background: var(--text); color: var(--bg);
}
.output-thumb:disabled { cursor: default; }
@media (hover: hover) { .output-thumb:hover:not(:disabled) { border-color: var(--accent); } }
.output-more { font-size: 0.85rem; color: var(--muted); padding: 0 4px 6px; }

/* Vários PDFs (dividir): um link por arquivo, rolando se forem muitos. */
.result-files {
  list-style: none; margin: 12px auto 0; padding: 0; max-width: 520px; max-height: 260px; overflow: auto;
  text-align: left; border: 1px solid var(--border); border-radius: 10px; background: var(--surface);
}
.result-files li { padding: 10px 12px; border-top: 1px solid var(--border); overflow-wrap: anywhere; }
.result-files li:first-child { border-top: 0; }

.status-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 4px 12px; margin: 16px 0; }
.status { min-height: 1.5em; text-align: center; color: var(--muted); margin: 0; }
.btn-undo { padding: 6px 14px; }
.status[data-kind="error"] { color: var(--danger); }
.status[data-kind="success"] { color: var(--success); }

/* Cards informativos */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 24px; margin-top: 24px;
}
.checklist { padding-left: 0; list-style: none; display: grid; gap: 10px; }
.checklist li { padding-left: 28px; position: relative; }
.checklist li::before { content: "✓"; position: absolute; left: 4px; color: var(--accent); font-weight: 700; }
.pix { display: flex; flex-wrap: wrap; gap: 20px; align-items: center; margin: 16px 0; padding: 16px; background: var(--surface-2); border-radius: var(--radius); }
.pix-qr { width: 180px; height: 180px; border-radius: 8px; image-rendering: pixelated; flex: none; }
.pix-info { flex: 1 1 240px; }
.pix-info p { margin: 0 0 12px; }
.pix-info p:last-child { margin: 12px 0 0; }
.pix-code { display: block; word-break: break-all; user-select: all; padding: 8px; }
.donate-actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 16px 0 8px; }

.site-footer { margin-top: 40px; padding: 24px 0 40px; border-top: 1px solid var(--border); color: var(--muted); font-size: 0.92rem; }
.site-footer .version { margin-top: 6px; font-size: 0.85rem; }

/* Câmera da página: tela cheia, sempre escura (independe do tema). */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.camera {
  width: 100vw; height: 100dvh; max-width: none; max-height: none;
  margin: 0; padding: 0; border: 0; background: #000; color: #fff;
}
.camera[open] { display: flex; flex-direction: column; }
.camera::backdrop { background: #000; }
.camera-view { position: relative; flex: 1 1 0; min-height: 0; }
.camera-video { display: block; width: 100%; height: 100%; object-fit: contain; background: #000; }
/* Contorno do papel encontrado, posicionado pelo camera.js sobre a área da imagem. */
.camera-outline { position: absolute; overflow: visible; pointer-events: none; }
.camera-outline polygon { fill: rgb(45 212 191 / 14%); stroke: #2dd4bf; stroke-width: 3; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.camera-chip {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%); white-space: nowrap;
  padding: 4px 12px; border-radius: 999px; font-size: 0.85rem; font-weight: 600;
  background: rgb(29 33 41 / 80%); color: #d0d5dd;
}
.camera-chip.found { background: #2dd4bf; color: #062a26; }
.camera-video.shot { animation: camera-shot 0.25s ease-out; }
@keyframes camera-shot { from { opacity: 0.2; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .camera-video.shot { animation: none; } }
.camera-warning { margin: 0; padding: 8px 16px; text-align: center; font-size: 0.95rem; font-weight: 600; background: #fde68a; color: #1d2129; }
.camera-btn.attention { border-color: #fde68a; box-shadow: 0 0 0 3px rgb(253 230 138 / 45%); }
.camera-message { margin: 0; padding: 8px 16px; min-height: 2.6em; text-align: center; font-size: 0.9rem; color: #d0d5dd; }
.camera-bar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px; padding: 4px 16px 12px; }
.camera-bar > :first-child { justify-self: start; }
.camera-bar > :last-child { justify-self: end; }
.camera-shutter { grid-column: 2; }
.camera-btn {
  display: inline-flex; align-items: center; gap: 6px; min-height: 48px; padding: 8px 14px;
  border: 1px solid #667085; border-radius: 999px; background: #1d2129; color: #fff;
  font: inherit; font-weight: 600; white-space: nowrap; cursor: pointer;
}
.camera-btn[aria-pressed="true"] { background: #fde68a; border-color: #fde68a; color: #1d2129; }
.camera-shutter {
  width: 72px; height: 72px; border-radius: 50%; border: 4px solid #fff;
  background: #fff; box-shadow: inset 0 0 0 3px #000; cursor: pointer;
}
.camera-shutter:active { transform: scale(0.94); }
.camera-shutter:disabled { opacity: 0.4; }
.camera-native {
  min-height: 44px; padding: 8px 16px 16px; border: 0; background: none;
  color: #d0d5dd; font: inherit; font-size: 0.9rem; text-decoration: underline; cursor: pointer;
}
.camera :focus-visible { outline-color: #fde68a; }

/* Página em tela cheia e ajuste do recorte. */
.viewer {
  width: 100vw; height: 100dvh; max-width: none; max-height: none;
  margin: 0; padding: 0; border: 0; background: var(--bg); color: var(--text);
}
.viewer[open] { display: flex; flex-direction: column; }
.viewer-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 12px; border-bottom: 1px solid var(--border); background: var(--surface); }
.viewer-head h2 { margin: 0; font-size: 1.05rem; }
.viewer-frame { flex: 1 1 0; min-height: 0; position: relative; display: flex; }
.viewer-step {
  position: absolute; top: 50%; transform: translateY(-50%); z-index: 2;
  width: 48px; height: 48px; border-radius: 50%; padding: 0;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  box-shadow: 0 2px 10px rgb(0 0 0 / 25%); cursor: pointer; opacity: 0.92;
}
.viewer-step .icon { width: 24px; height: 24px; }
.viewer-step-prev { left: 12px; } /* o JS encosta a seta na borda da página (viewer.js, placeSteps) */
.viewer-step-next { right: 12px; }
@media (hover: hover) { .viewer-step:hover { opacity: 1; border-color: var(--accent); } }
.viewer-stage {
  flex: 1 1 0; min-width: 0; min-height: 0; display: flex; align-items: center; justify-content: center;
  overflow: hidden; background: var(--surface-2); padding: 8px;
}
.viewer-image { max-width: 100%; max-height: 100%; display: block; cursor: zoom-in; box-shadow: var(--shadow), 0 0 0 1px var(--border); touch-action: pan-y pinch-zoom; }
/* Ampliado: a imagem passa a ter 2,2× a largura da tela e a área rola nos dois sentidos. */
.viewer-stage.zoomed { display: block; overflow: auto; -webkit-overflow-scrolling: touch; }
.viewer-stage.zoomed .viewer-image { max-width: none; max-height: none; width: 220%; cursor: zoom-out; touch-action: auto; }
/* Altura fixa (duas linhas): trocar o texto não pode mexer no tamanho da foto no meio de um arrasto. */
.viewer-hint { margin: 0; padding: 8px 16px 0; height: 3.8em; overflow: hidden; text-align: center; font-size: 0.9rem; color: var(--muted); background: var(--surface); }
.viewer-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; padding: 8px 12px 14px; background: var(--surface); }
.viewer-actions .btn { flex: 1 1 140px; max-width: 260px; }

.crop { position: relative; flex: none; touch-action: none; }
.crop img { display: block; width: 100%; height: 100%; user-select: none; -webkit-user-drag: none; }
.crop-lines { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
.crop-lines polygon { fill: rgb(45 212 191 / 18%); stroke: #2dd4bf; stroke-width: 2; vector-effect: non-scaling-stroke; }
.crop.invalid .crop-lines polygon { fill: rgb(249 112 102 / 18%); stroke: #f97066; }
/* Alvo de 48 px para o dedo; o que se vê é a bolinha do meio. */
.crop-handle {
  position: absolute; width: 48px; height: 48px; margin: -24px 0 0 -24px; padding: 0;
  border: 0; border-radius: 50%; background: none; cursor: grab; touch-action: none;
}
.crop-handle::before {
  content: ""; position: absolute; inset: 13px; border-radius: 50%;
  background: #fff; border: 3px solid #0f766e; box-shadow: 0 1px 4px rgb(0 0 0 / 45%);
}
.crop-handle:active { cursor: grabbing; }
.crop-handle:active::before, .crop-handle:focus-visible::before { inset: 9px; }
