/* Paper Apps shared styles. Every page is one screen, like an app: the page
   itself never scrolls; only a long file list scrolls inside it. */

:root {
  --paper: #fff;
  --ink: #111;
  --ink-soft: #6b6b6b;
  --line: #e8e8e8;
  --line-strong: #cfcfcf;
  --soft: #f5f5f5;
  --danger: #c4302b;
  --radius: 8px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0e0e0e;
    --ink: #ededed;
    --ink-soft: #8e8e8e;
    --line: #232323;
    --line-strong: #3a3a3a;
    --soft: #191919;
    --danger: #ff6b61;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; height: 100vh; height: 100dvh;
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--paper); color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-underline-offset: 3px; }
.wrap { width: 100%; max-width: 640px; margin: 0 auto; padding: 0 16px; }
[hidden] { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Top bar, then the page filling the rest of the screen. On a screen too
   short for it, the page area scrolls rather than cutting anything off. */
.site-header { flex: none; padding-top: 16px; }
.brand { font-size: 15px; font-weight: 600; text-decoration: none; color: var(--ink-soft); }
main { flex: 1; min-height: 0; overflow: auto; display: flex; flex-direction: column; }
.tool {
  flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 12px;
  padding: 16px 0 max(16px, env(safe-area-inset-bottom));
}
.tool h1 { flex: none; font-size: 28px; line-height: 1.2; font-weight: 600; letter-spacing: -0.02em; margin: 0; }

.drop {
  flex: 1; min-height: 140px; display: flex; align-items: center; justify-content: center;
  padding: 16px; border: 1px dashed var(--line-strong); border-radius: var(--radius);
  transition: background 0.15s, border-color 0.15s;
}
.drop.is-over { background: var(--soft); border-color: var(--ink); }
.drop.is-compact { flex: none; min-height: 0; padding: 8px; }

/* Buttons and fields */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 0 18px; border-radius: var(--radius);
  border: 1px solid var(--line-strong); background: transparent; color: var(--ink);
  font: inherit; font-size: 15px; font-weight: 500; white-space: nowrap; cursor: pointer;
  -webkit-tap-highlight-color: transparent; transition: background 0.15s, opacity 0.15s;
}
.btn:hover { background: var(--soft); }
.btn-primary { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.btn-primary:hover { background: var(--ink); opacity: 0.85; }
.btn:disabled { opacity: 0.4; cursor: default; }

/* One row of buttons; the main action gets the most room. */
.actions { flex: none; display: flex; gap: 8px; }
.actions .btn { flex: 1 1 0; min-width: 0; padding: 0 12px; }
.actions .btn-primary { flex-grow: 2; }

.icon-btn {
  height: 36px; display: inline-flex; align-items: center; justify-content: center;
  border: 0; border-radius: 6px; background: transparent; color: var(--ink-soft);
  font-size: 15px; cursor: pointer; padding: 0;
}
.icon-btn:hover { background: var(--soft); color: var(--ink); }
.icon-btn:disabled { opacity: 0.3; cursor: default; background: transparent; }

select {
  min-height: 40px; padding: 0 10px; border-radius: var(--radius);
  border: 1px solid var(--line-strong); background: var(--paper); color: var(--ink); font: inherit; font-size: 15px;
}
input[type="checkbox"] { width: 18px; height: 18px; margin: 0; accent-color: var(--ink); }

:focus-visible, .visually-hidden:focus-visible + .btn { outline: 2px solid var(--ink); outline-offset: 2px; }

.options { flex: none; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 24px; }
.options label { display: inline-flex; align-items: center; gap: 8px; font-size: 15px; }

/* Files being worked on: the one part that scrolls, when the list is long */
.file-grid {
  flex: 1 1 auto; min-height: 0; overflow-y: auto; align-content: start;
  list-style: none; margin: 0; padding: 0;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 12px;
}
.file-grid li { min-width: 0; display: grid; gap: 4px; }
.file-thumb { position: relative; aspect-ratio: 1; display: flex; align-items: center; justify-content: center; overflow: hidden; background: var(--soft); border-radius: var(--radius); }
.file-thumb img, .file-thumb canvas { max-width: 100%; max-height: 100%; object-fit: contain; transition: transform 0.2s; }
.file-num {
  position: absolute; top: 8px; left: 8px; min-width: 22px; height: 22px; padding: 0 6px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 4px; background: var(--paper); color: var(--ink); font-size: 12px; font-weight: 600;
}
.file-actions { display: flex; }
.file-actions .icon-btn { flex: 1 1 0; min-width: 0; }

/* A single result image, as large as the screen allows */
.preview { flex: 1 1 0; min-height: 0; width: 100%; object-fit: contain; background: var(--soft); border-radius: var(--radius); }

/* Messages, result, next steps */
.msg { flex: none; margin: 0; font-size: 14px; }
.msg:empty { display: none; }
.msg-error { color: var(--danger); }
.msg-ok { font-weight: 500; }
.result { flex: none; display: flex; flex-direction: column; gap: 12px; min-height: 0; }
.result.fill { flex: 1 1 0; }

.offer ul { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 4px 24px; }
.offer a { text-decoration: none; font-size: 15px; color: var(--ink-soft); }
.offer a::after { content: " →"; }
.offer a:hover { color: var(--ink); }

/* Home page: the list of apps */
.tool-list { flex: none; list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.tool-list a { display: flex; justify-content: space-between; gap: 16px; padding: 14px 0; border-bottom: 1px solid var(--line); text-decoration: none; font-weight: 500; }
.tool-list a span { color: var(--ink-soft); font-weight: 400; }
.tool-list a:hover { text-decoration: underline; }
.label { flex: none; margin: 16px 0 0; font-size: 13px; font-weight: 500; color: var(--ink-soft); }
