/* Honest Scanner — styles. Come Alone family tokens (from Fair Split); dark via prefers-color-scheme.
   Nunito is self-hosted (variable font) so the app makes no third-party requests. */
@font-face { font-family: "Nunito"; src: url("nunito.ttf") format("truetype"); font-weight: 200 1000; font-style: normal; font-display: swap; }
:root {
  --bg: #f6f3ee;
  --surface: #ffffff;
  --surface-2: #efebe4;
  --text: #1d1a22;
  --muted: #625d69;
  --line: rgba(29,26,34,.12);
  --accent: #2fb3a6;
  --accent-ink: #10201e;
  --pink: #ff5c8a;
  --pos: #12806a;
  --neg: #c8324f;
  --warn-bg: #fff3d6;
  --warn-ink: #6b4a00;
  --shadow: 0 10px 30px rgba(29,26,34,.08);
  --radius: 20px;
  --font: "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15131a;
    --surface: #201d27;
    --surface-2: #2a2633;
    --text: #f3f0f7;
    --muted: #a8a2b1;
    --line: rgba(243,240,247,.12);
    --pos: #4fd1b0;
    --neg: #ff7a93;
    --warn-bg: #3a2f14;
    --warn-ink: #ffd88a;
    --shadow: 0 10px 30px rgba(0,0,0,.35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font); font-weight: 500; background: var(--bg); color: var(--text);
  line-height: 1.45; min-height: 100dvh; display: flex; flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  -webkit-tap-highlight-color: transparent;
}
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.15; font-weight: 900; letter-spacing: -.01em; }
p { margin: 0; }
ul, ol { margin: 0; padding: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--accent); color: var(--accent-ink); padding: 8px 14px; border-radius: 10px; font-weight: 800; z-index: 10; }
.skip:focus { left: 8px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
main:focus, h1:focus { outline: none; }

/* Header */
.top { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; max-width: 720px; width: 100%; margin: 0 auto; }
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; font-weight: 900; font-size: 1.15rem; }
.brand-mark { width: 32px; height: 32px; color: var(--accent); }
.lang-wrap select { font-weight: 700; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 8px 14px; cursor: pointer; }

/* Main */
.app { flex: 1; width: 100%; max-width: 720px; margin: 0 auto; padding: 8px 16px 32px; }
.screen { animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.hero { padding: 12px 0 16px; }
.hero h1 { font-size: clamp(2rem, 7vw, 2.8rem); }
.hero p { color: var(--muted); margin-top: 8px; font-size: 1.05rem; }
.how { list-style: none; margin-top: 14px; display: grid; gap: 8px; counter-reset: how; }
.how li { counter-increment: how; display: flex; gap: 10px; align-items: baseline; font-weight: 700; }
.how li::before { content: counter(how); flex: 0 0 26px; height: 26px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-weight: 900; font-size: .85rem; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); margin-top: 12px; }
.panel h2 { font-size: 1.15rem; display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.panel h2 small { color: var(--muted); font-weight: 700; font-size: .9rem; }
.panel h1 { font-size: 1.4rem; }
.lead { color: var(--muted); margin-top: 8px; font-size: 1.05rem; }
.hint { color: var(--muted); font-size: .92rem; margin-top: 6px; }
.hint.pad { padding: 12px 4px 0; }
.center { text-align: center; }
.err { color: var(--neg); font-weight: 800; margin-top: 10px; }
.err:empty { display: none; }
.warn { background: var(--warn-bg); color: var(--warn-ink); border-radius: 14px; padding: 12px 14px; font-weight: 700; margin-top: 12px; }
.warn a { font-weight: 900; }
.ok-line { margin-top: 10px; font-weight: 800; color: var(--pos); }

/* Forms */
.field { margin-top: 14px; min-width: 0; }
.field label { display: block; font-weight: 700; font-size: .9rem; color: var(--muted); margin-bottom: 6px; }
.seg { display: flex; background: var(--surface-2); border-radius: 14px; padding: 4px; gap: 4px; margin-top: 10px; }
.seg button, .seg a { flex: 1; border: 0; background: transparent; border-radius: 11px; padding: 10px 6px; font-weight: 800; cursor: pointer; color: var(--muted); text-align: center; text-decoration: none; font-size: .95rem; min-height: 44px; display: grid; place-items: center; }
.seg .on { background: var(--surface); color: var(--text); box-shadow: 0 2px 8px rgba(0,0,0,.08); }

.field input[type=text] { width: 100%; font-weight: 700; padding: 12px 14px; border-radius: 14px; border: 1px solid var(--line); background: var(--bg); color: var(--text); min-height: 48px; }
.field .label { display: block; font-weight: 700; font-size: .9rem; color: var(--muted); margin-bottom: 6px; }
.field label b { color: var(--text); }
.fname-wrap { display: flex; align-items: center; gap: 6px; }
.fname-wrap span { color: var(--muted); font-weight: 800; }
input[type=range] { width: 100%; accent-color: var(--accent); min-height: 36px; }
.range-ends { display: flex; justify-content: space-between; color: var(--muted); font-size: .85rem; font-weight: 700; }
.size-line { margin-top: 14px; font-weight: 900; font-size: 1.15rem; }
.size-line:empty { display: none; }

/* Hero */
.privacy { display: flex; gap: 10px; align-items: flex-start; margin-top: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 12px 14px; color: var(--muted); font-size: .95rem; }
.privacy b { color: var(--text); font-weight: 900; }
.privacy svg { width: 26px; height: 26px; flex: 0 0 26px; color: var(--pos); }

/* Capture */
.capture { margin-top: 0; }
.capture .btn svg { width: 24px; height: 24px; }
.capture label:focus-within { outline: 3px solid var(--accent); outline-offset: 2px; }
.busy { font-weight: 800; color: var(--text); }

/* Pages grid */
.pages { list-style: none; display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; margin-top: 12px; }
.page { background: var(--surface-2); border-radius: 16px; padding: 8px; display: flex; flex-direction: column; gap: 6px; }
.page-open { position: relative; border: 0; padding: 0; background: #fff; border-radius: 10px; cursor: pointer; aspect-ratio: 3 / 4; display: grid; place-items: center; overflow: hidden; }
.thumb { max-width: 100%; max-height: 100%; display: block; }
.page-num { position: absolute; left: 6px; top: 6px; background: var(--accent); color: var(--accent-ink); font-weight: 900; font-size: .85rem; min-width: 26px; height: 26px; border-radius: 13px; display: grid; place-items: center; padding: 0 6px; }
.page-bar { display: flex; justify-content: space-between; }
.icon-btn { border: 0; background: transparent; width: 40px; height: 40px; border-radius: 12px; cursor: pointer; color: var(--text); display: grid; place-items: center; }
.icon-btn:hover:not(:disabled) { background: var(--line); }
.icon-btn:disabled { opacity: .3; cursor: default; }
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn.del { color: var(--neg); }

/* Editor */
.editor { width: min(720px, 100%); max-width: 100%; max-height: 100dvh; overflow: auto; overscroll-behavior: contain; margin: auto; border: 0; border-radius: var(--radius); padding: 16px; background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.editor::backdrop { background: rgba(10,8,14,.6); }
@media (max-width: 560px) { .editor { width: 100%; height: 100dvh; border-radius: 0; padding: 12px 16px calc(16px + env(safe-area-inset-bottom)); } }
.ed-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.ed-head h2 { font-size: 1.25rem; }
.ed-tools { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.ed-tools .btn svg { width: 18px; height: 18px; }
.stage-wrap { margin-top: 12px; display: flex; justify-content: center; background: var(--surface-2); border-radius: 14px; padding: 18px; }
.stage { position: relative; width: 100%; touch-action: none; user-select: none; -webkit-user-select: none; }
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; border-radius: 4px; }
.quad { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
.quad polygon { fill: rgba(47,179,166,.18); stroke: var(--accent); stroke-width: 2.5; vector-effect: non-scaling-stroke; }
.handle { position: absolute; width: 44px; height: 44px; margin: -22px 0 0 -22px; border-radius: 50%; border: 0; padding: 0; background: transparent; cursor: grab; touch-action: none; }
.handle::after { content: ""; position: absolute; inset: 11px; border-radius: 50%; background: var(--accent); border: 3px solid #fff; box-shadow: 0 2px 8px rgba(0,0,0,.35); }
.handle.drag { cursor: grabbing; }
.handle.drag::after { inset: 7px; background: var(--pink); }
.result { margin-top: 4px; background: var(--surface-2); border-radius: 14px; padding: 12px; display: grid; place-items: center; }
.result canvas { max-width: 100%; max-height: 40vh; background: #fff; box-shadow: 0 2px 10px rgba(0,0,0,.15); }

/* Tips */
.tips summary { cursor: pointer; list-style: none; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.tips summary::-webkit-details-marker { display: none; }
.tips summary::after { content: "+"; font-weight: 900; font-size: 1.4rem; color: var(--muted); }
.tips[open] summary::after { content: "–"; }
.tips ul { margin-top: 10px; padding-left: 20px; display: grid; gap: 8px; }
.tips li.strong { font-weight: 800; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 0; border-radius: 16px;
  padding: 14px 20px; font-weight: 900; font-size: 1.05rem; cursor: pointer; background: var(--surface-2); color: var(--text);
  text-decoration: none; transition: transform .12s ease; min-height: 48px; text-align: center;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; border: 1px solid var(--line); }
.btn.danger { background: transparent; border: 1px solid var(--neg); color: var(--neg); }
.btn.block { width: 100%; display: flex; }
.btn.big { padding: 16px 22px; font-size: 1.1rem; }
.btn.small { padding: 8px 12px; font-size: .9rem; min-height: 40px; border-radius: 12px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }
.row .btn { flex: 1 1 140px; }

/* Toast */
.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 14px; font-weight: 800; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: calc(100% - 32px); z-index: 20; }
.toast.on { opacity: 1; transform: translate(-50%, 0); }

/* Footer */
.foot { max-width: 720px; width: 100%; margin: 0 auto; padding: 20px 16px 36px; color: var(--muted); font-size: .92rem; text-align: center; border-top: 1px solid var(--line); }
.foot-line + .foot-line { margin-top: 8px; }
.foot-line a { color: var(--text); font-weight: 700; }
.foot-line.small { font-size: .85rem; }
.foot .mm { margin-top: 14px; }

@media (prefers-reduced-motion: reduce) { .screen { animation: none; } .btn, .toast { transition: none; } }
