/* Document Digitiser. The visual system is described in DESIGN.md.
   One family, a fixed type scale, a petrol shell, paper on scanner glass.
   The signature: the upload area is the page, with the four corner marks the
   program looks for, and a lamp that sweeps it while a photo is digitised. */

:root {
  color-scheme: light dark;
  --ground: #eef2f5;
  --paper: #ffffff;
  --ink: #13212c;
  --muted: #4a5a68;
  --line: #cdd6de;
  --line-strong: #8fa3b1;
  --shell: #0f2f3d;
  --shell-ink: #e9f1f4;
  --accent: #0b5f73;
  --accent-hover: #094c5c;
  --accent-ink: #ffffff;
  --lamp: #35c3d9;
  --ok: #17603a;
  --ok-bg: #e3f3e8;
  --ok-line: #a9d6b8;
  --warn: #6f4300;
  --warn-bg: #fdf1d6;
  --warn-line: #e3c57f;
  --bad: #9b1c1c;
  --bad-bg: #fce8e6;
  --bad-line: #e6aaa4;
  --shadow-paper: 0 1px 2px rgb(19 33 44 / 0.08), 0 10px 24px -14px rgb(19 33 44 / 0.35);
  --step--1: 0.875rem;
  --step-0: 1rem;
  --step-1: 1.2rem;
  --step-2: 1.44rem;
  --step-3: 1.728rem;
  --radius: 6px;
  --gutter: 1rem;
}
@media (prefers-color-scheme: dark) {
  :root {
    --ground: #0c161c;
    --paper: #15242d;
    --ink: #e6eef2;
    --muted: #a3b5c0;
    --line: #2a3d49;
    --line-strong: #527082;
    --shell: #08141a;
    --shell-ink: #e6eef2;
    --accent: #62cadd;
    --accent-hover: #86d9e8;
    --accent-ink: #062029;
    --lamp: #7fe3f0;
    --ok: #86dba6;
    --ok-bg: #11301f;
    --ok-line: #24583c;
    --warn: #f0c672;
    --warn-bg: #32270e;
    --warn-line: #5e4b1c;
    --bad: #ffa199;
    --bad-bg: #391a18;
    --bad-line: #6e302b;
    --shadow-paper: 0 1px 2px rgb(0 0 0 / 0.4), 0 12px 28px -14px rgb(0 0 0 / 0.7);
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html {
  font: 100%/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  accent-color: var(--accent);
  caret-color: var(--accent);
  scrollbar-color: var(--line-strong) var(--ground);
}
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--ground);
  color: var(--ink);
}
::selection { background: var(--accent); color: var(--accent-ink); }

/* --- shell ------------------------------------------------------------------ */

.shell {
  background: var(--shell);
  color: var(--shell-ink);
  border-bottom: 1px solid rgb(255 255 255 / 0.08);
  padding: 0 max(var(--gutter), env(safe-area-inset-right)) 0 max(var(--gutter), env(safe-area-inset-left));
}
.shell-in {
  max-width: 44rem;
  margin: 0 auto;
  min-height: 3.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  min-height: 2.75rem;
  color: inherit;
  font-weight: 650;
  letter-spacing: -0.01em;
  text-decoration: none;
}
.brand .icon { width: 1.4rem; height: 1.4rem; color: var(--lamp); }
.shell form { margin: 0; }
.shell button {
  background: transparent;
  border-color: rgb(255 255 255 / 0.28);
  color: var(--shell-ink);
  min-height: 2.75rem;
  padding: 0 0.9rem;
  font-size: var(--step--1);
}
.shell button:hover { background: rgb(255 255 255 / 0.1); border-color: rgb(255 255 255 / 0.5); }
.shell :focus-visible { outline-color: var(--lamp); }

main {
  flex: 1;
  width: 100%;
  max-width: calc(44rem + 2 * var(--gutter));
  margin: 0 auto;
  padding: 1.75rem max(var(--gutter), env(safe-area-inset-right)) 3rem
    max(var(--gutter), env(safe-area-inset-left));
}
main.narrow { max-width: calc(26rem + 2 * var(--gutter)); }

/* --- type ------------------------------------------------------------------- */

h1, h2 { text-wrap: balance; letter-spacing: -0.015em; line-height: 1.2; overflow-wrap: anywhere; }
h1 { font-size: var(--step-3); font-weight: 680; margin: 0 0 0.5rem; }
h2 { font-size: var(--step-1); font-weight: 650; margin: 2.5rem 0 0.75rem; }
p { margin: 0.5rem 0; text-wrap: pretty; }
.lede { color: var(--muted); max-width: 62ch; margin-bottom: 1.5rem; }
.muted { color: var(--muted); font-size: var(--step--1); }
a { color: var(--accent); text-underline-offset: 0.18em; text-decoration-thickness: 1px; }
a:hover { color: var(--accent-hover); text-decoration-thickness: 2px; }
code {
  font: 0.92em/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: var(--ground);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0.05em 0.35em;
  overflow-wrap: anywhere;
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--radius); }
.icon {
  width: 1.25rem;
  height: 1.25rem;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* --- controls --------------------------------------------------------------- */

button, .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 2.75rem;
  padding: 0 1.15rem;
  font: inherit;
  font-weight: 600;
  line-height: 1.2;
  border-radius: var(--radius);
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
  text-decoration: none;
  cursor: pointer;
  transition: background-color 160ms ease-out, border-color 160ms ease-out, transform 120ms ease-out;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
button:hover, .button:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--accent-ink); }
button:active, .button:active { transform: translateY(1px); }
button.plain, .button.plain { background: var(--paper); border-color: var(--line-strong); color: var(--ink); }
button.plain:hover, .button.plain:hover { background: var(--ground); border-color: var(--ink); color: var(--ink); }
button.danger { background: transparent; border-color: var(--bad-line); color: var(--bad); }
button.danger:hover { background: var(--bad-bg); border-color: var(--bad); color: var(--bad); }
button.quiet {
  min-height: 2.75rem;
  padding: 0 0.25rem;
  background: none;
  border-color: transparent;
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 0.18em;
  text-decoration-thickness: 1px;
}
button.quiet:hover { background: none; border-color: transparent; color: var(--accent-hover); text-decoration-thickness: 2px; }
button[disabled], button[disabled]:hover { opacity: 0.55; cursor: progress; transform: none; }
.actions { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: center; margin-top: 1.25rem; }
.actions form { margin: 0; }
.tight { display: none; }

label { display: block; font-weight: 600; margin-bottom: 0.4rem; }
input[type="password"] {
  display: block;
  width: 100%;
  min-height: 2.75rem;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  font-size: 1rem; /* 16px or more, so phones do not zoom on focus */
}
input[type="password"]:hover { border-color: var(--ink); }
.check { display: flex; gap: 0.7rem; align-items: flex-start; margin: 1.25rem 0 0; }
.check input { width: 1.25rem; height: 1.25rem; margin: 0.15rem 0 0; flex: none; }
.check label { font-weight: 400; margin: 0; }

/* --- paper ------------------------------------------------------------------ */

.paper {
  background: var(--paper);
  border-radius: 10px;
  box-shadow: var(--shadow-paper);
  padding: 1.5rem;
}

/* The upload area: the page the program will look for. */
.sheet {
  position: relative;
  overflow: hidden;
  background: var(--paper);
  border-radius: 10px;
  box-shadow: var(--shadow-paper);
  padding: 2.25rem 1.5rem;
  transition: background-color 160ms ease-out;
}
.sheet input[type="file"] {
  display: block;
  width: 100%;
  max-width: 100%;
  font: inherit;
  font-size: 1rem;
  color: var(--ink);
  margin: 0.25rem 0 0.75rem;
}
.sheet input[type="file"]::file-selector-button {
  font: inherit;
  font-weight: 600;
  min-height: 2.75rem;
  margin-right: 0.75rem;
  padding: 0 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--line-strong);
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
}
.sheet .muted { margin: 0; }
.sheet-hint, .picked { display: none; }
.corner {
  position: absolute;
  width: 1.1rem;
  height: 1.1rem;
  border: 0 solid var(--accent);
  pointer-events: none;
  transition: inset 220ms cubic-bezier(0.16, 1, 0.3, 1), border-color 160ms ease-out;
}
.corner.tl { inset: 0.75rem auto auto 0.75rem; border-width: 2px 0 0 2px; }
.corner.tr { inset: 0.75rem 0.75rem auto auto; border-width: 2px 2px 0 0; }
.corner.bl { inset: auto auto 0.75rem 0.75rem; border-width: 0 0 2px 2px; }
.corner.br { inset: auto 0.75rem 0.75rem auto; border-width: 0 2px 2px 0; }
.lamp {
  position: absolute;
  inset: -3.5rem 0 auto 0;
  height: 3.5rem;
  pointer-events: none;
  opacity: 0;
  background: linear-gradient(to bottom, transparent, color-mix(in srgb, var(--lamp) 28%, transparent));
  border-bottom: 2px solid var(--lamp);
}

/* With script: the whole sheet is the control, for tapping and for dropping. */
.js .sheet { text-align: center; padding: 2.75rem 1.5rem; cursor: pointer; }
.js .sheet label { font-size: var(--step-1); font-weight: 650; letter-spacing: -0.01em; margin: 0; }
.js .sheet input[type="file"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}
.js .sheet-hint { display: block; color: var(--muted); margin: 0.35rem 0 1rem; }
.js .picked {
  display: block;
  margin: 0.35rem 0 1rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}
.js .sheet:hover .corner, .js .sheet.is-over .corner { border-color: var(--accent-hover); }
.js .sheet:hover .corner.tl, .js .sheet.is-over .corner.tl { inset: 0.45rem auto auto 0.45rem; }
.js .sheet:hover .corner.tr, .js .sheet.is-over .corner.tr { inset: 0.45rem 0.45rem auto auto; }
.js .sheet:hover .corner.bl, .js .sheet.is-over .corner.bl { inset: auto auto 0.45rem 0.45rem; }
.js .sheet:hover .corner.br, .js .sheet.is-over .corner.br { inset: auto 0.45rem 0.45rem auto; }
.js .sheet.is-over { background: color-mix(in srgb, var(--lamp) 10%, var(--paper)); }
.js .sheet:focus-within { outline: 2px solid var(--accent); outline-offset: 3px; }

/* While a photo is being digitised, the lamp passes over the page. */
#busy { display: none; margin: 1rem 0 0; font-weight: 600; }
.is-busy #busy { display: block; }
.is-busy .sheet { cursor: progress; }
.is-busy .lamp { opacity: 1; animation: sweep 1.9s cubic-bezier(0.45, 0, 0.55, 1) infinite alternate; }
@keyframes sweep {
  from { transform: translateY(0); }
  to { transform: translateY(calc(100% + 22rem)); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 1ms !important; }
  .is-busy .lamp { animation: none; opacity: 0; }
}

.sample { margin: 1.5rem 0 0; color: var(--muted); }
.sample p { margin: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 0 0.4rem; }

ul.tips { margin: 0; padding: 0; list-style: none; max-width: 62ch; color: var(--muted); }
ul.tips li { padding: 0.5rem 0; border-top: 1px solid var(--line); }
ul.tips li:last-child { border-bottom: 1px solid var(--line); }
ul.tips strong { color: var(--ink); font-weight: 600; }

/* --- messages --------------------------------------------------------------- */

.note {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  margin: 1rem 0;
  border: 1px solid var(--line);
  background: var(--paper);
}
.note .icon { margin-top: 0.15rem; }
.note > div { min-width: 0; }
.note strong { display: block; }
.note span { display: block; }
.note ul { margin: 0.35rem 0 0; padding-left: 1.1rem; }
.note.ok { background: var(--ok-bg); border-color: var(--ok-line); color: var(--ok); }
.note.warn { background: var(--warn-bg); border-color: var(--warn-line); color: var(--warn); }
.note.bad { background: var(--bad-bg); border-color: var(--bad-line); color: var(--bad); }

/* --- result ----------------------------------------------------------------- */

ul.files { list-style: none; padding: 0; margin: 0; border-top: 1px solid var(--line); }
ul.files li { border-bottom: 1px solid var(--line); }
ul.files a {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.1rem 1rem;
  align-items: center;
  min-height: 3.5rem;
  padding: 0.6rem 0.25rem;
  color: var(--ink);
  text-decoration: none;
  border-radius: 0;
  transition: background-color 160ms ease-out;
}
ul.files a:hover { background: color-mix(in srgb, var(--accent) 7%, transparent); }
ul.files .name { font-weight: 600; color: var(--accent); }
ul.files a:hover .name { text-decoration: underline; text-underline-offset: 0.18em; }
ul.files .what { grid-column: 1; color: var(--muted); font-size: var(--step--1); }
ul.files .icon { grid-column: 2; grid-row: 1 / span 2; color: var(--accent); }

dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: 0; margin: 0; border-top: 1px solid var(--line); }
dl.facts dt, dl.facts dd { padding: 0.55rem 0; border-bottom: 1px solid var(--line); margin: 0; }
dl.facts dt { color: var(--muted); padding-right: 1.5rem; }
dl.facts dd { font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }

.flags { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.flag { padding: 1rem 0; border-bottom: 1px solid var(--line); }
.flag p { margin: 0.25rem 0; }
.flag p:first-child { font-weight: 600; }
.flag img { display: block; margin-top: 0.75rem; }
.flag img, .preview img {
  max-width: 100%;
  height: auto;
  border-radius: 4px;
  background: #fff;
  box-shadow: var(--shadow-paper);
}
.preview { display: grid; grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr)); gap: 1.5rem; align-items: start; }
.preview figure { margin: 0; }
.preview figcaption { color: var(--muted); font-size: var(--step--1); margin-top: 0.6rem; }

.end { margin-top: 2.5rem; padding-top: 1.5rem; border-top: 1px solid var(--line); }

footer {
  width: 100%;
  max-width: calc(44rem + 2 * var(--gutter));
  margin: 0 auto;
  padding: 1rem max(var(--gutter), env(safe-area-inset-right)) calc(1.25rem + env(safe-area-inset-bottom))
    max(var(--gutter), env(safe-area-inset-left));
  color: var(--muted);
  font-size: var(--step--1);
}

/* --- phones ----------------------------------------------------------------- */

@media (max-width: 40rem) {
  :root { --step-3: 1.5rem; --step-2: 1.3rem; }
  main { padding-top: 1.25rem; }
  h2 { margin-top: 2rem; }
  .paper { padding: 1.25rem; }
  .sheet, .js .sheet { padding: 2.5rem 1.25rem; }
  .actions > button, .actions > .button, .actions > form, .actions > form > button { width: 100%; }
  dl.facts { grid-template-columns: 1fr; }
  dl.facts dt { border-bottom: 0; padding-bottom: 0; font-size: var(--step--1); }
  dl.facts dd { padding-top: 0.1rem; }

  /* The downloads stay within reach of the thumb. */
  .dock {
    position: fixed;
    inset: auto 0 0 0;
    z-index: 2;
    margin: 0;
    flex-wrap: nowrap;
    gap: 0.5rem;
    padding: 0.65rem max(var(--gutter), env(safe-area-inset-right)) calc(0.65rem + env(safe-area-inset-bottom))
      max(var(--gutter), env(safe-area-inset-left));
    background: var(--paper);
    border-top: 1px solid var(--line);
    box-shadow: 0 -6px 16px -10px rgb(19 33 44 / 0.35);
  }
  .dock > .button { flex: 1 1 0; width: auto; min-width: 0; padding: 0 0.6rem; font-size: var(--step--1); text-align: center; }
  .dock > .button:first-child { flex-grow: 1.4; }
  .dock .wide { display: none; }
  .dock .tight { display: inline; }
  body:has(.dock) footer { padding-bottom: calc(5.5rem + env(safe-area-inset-bottom)); }
}
@media (max-width: 40rem) and (orientation: landscape) and (max-height: 30rem) {
  .dock { position: static; padding: 0; background: none; border: 0; box-shadow: none; flex-wrap: wrap; margin-top: 1.25rem; }
  .dock .wide { display: inline; }
  .dock .tight { display: none; }
  body:has(.dock) footer { padding-bottom: 1.25rem; }
}
@media print {
  .shell, .dock, .end, footer { display: none; }
  body { background: #fff; }
}
