  :root {
    --bg: #eef2f6;
    --panel: #ffffff;
    --ink: #1b2430;
    --muted: #5b6876;
    --line: #d5dce4;
    --laser: #d7263d;
    --action: #1d4e89;
    --error: #a4161a;
    --display: "Fredoka", "Nunito", system-ui, sans-serif;
  }
  * { box-sizing: border-box; }
  #scanApp { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
  #scanApp input { -webkit-user-select: text; user-select: text; }
  .hidden { display: none !important; }

  h1 { font-family: var(--display); font-weight: 600; font-size: 1.7rem; line-height: 1.2; margin: 8px 0 6px; }
  .lead { color: var(--muted); margin: 0 0 18px; max-width: 60ch; }

  button, select, input { font: inherit; color: inherit; }
  button {
    border: 1px solid var(--action); background: var(--action); color: #fff;
    padding: 10px 18px; border-radius: 6px; cursor: pointer; font-weight: 700;
  }
  button.secondary { background: var(--panel); color: var(--action); }
  button:disabled { opacity: .45; cursor: not-allowed; }
  :focus-visible { outline: 3px solid #f2a900; outline-offset: 2px; }
  .row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }

  /* scanner */
  .scanner { background: #0e151c; border-radius: 8px; overflow: hidden; position: relative; min-height: 240px; display: grid; place-items: center; }
  #reader { width: 100%; }
  #reader video { display: block; width: 100% !important; }
  .scanner-idle { color: #b8c4cf; text-align: center; padding: 40px 20px; }
  .laser { position: absolute; left: 8%; right: 8%; top: 50%; height: 2px; background: var(--laser); box-shadow: 0 0 10px var(--laser); pointer-events: none; }
  @media (prefers-reduced-motion: no-preference) {
    .laser { animation: sweep 2.2s ease-in-out infinite alternate; }
    @keyframes sweep { from { top: 30%; } to { top: 70%; } }
  }
  details.manual { margin-top: 22px; }
  details.manual summary { cursor: pointer; color: var(--action); font-weight: 700; }
  details.manual .row { margin-top: 10px; }
  input[type="text"] { flex: 1 1 200px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 6px; background: #fff; font-family: "IBM Plex Mono", ui-monospace, monospace; text-transform: uppercase; }
  .hint { color: var(--muted); font-size: .9rem; margin: 8px 0 0; }
  #message { color: var(--error); font-weight: 700; min-height: 1.5em; margin: 14px 0 0; }

  /* found screen */
  .found { text-align: center; padding: 10px 0; }
  .found .cover { display: block; margin: 0 auto 18px; max-width: min(320px, 80%); max-height: 46vh; border-radius: 8px; box-shadow: 0 6px 22px rgba(0,0,0,.22); pointer-events: none; }
  .found h1 { font-size: 2rem; }
  .found p { color: var(--muted); font-size: 1.1rem; margin: 0 0 20px; }
  .found button { font-size: 1.1rem; padding: 12px 28px; }

  /* viewer */
  button { min-height: 44px; }
  .toolbar { display: grid; grid-template-columns: 1fr auto; grid-template-areas: "title scan" "pager pager"; gap: 10px 12px; align-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 14px; }
  .doc-title { grid-area: title; font-family: var(--display); font-size: 1.1rem; line-height: 1.25; overflow-wrap: anywhere; }
  .tools { grid-area: scan; display: flex; gap: 8px; }
  .icon { min-width: 44px; padding: 8px; display: inline-grid; place-items: center; }
  .pager { grid-area: pager; display: grid; grid-template-columns: auto 1fr auto; gap: 8px; align-items: center; }
  .pager button { min-width: 48px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 12px; }
  .pager .chev { font-size: 1.5rem; line-height: 1; }
  .pager .lbl { display: none; }
  .pager-mid { display: flex; align-items: center; justify-content: center; gap: 8px; min-width: 0; }
  .pager-mid .count { color: var(--muted); white-space: nowrap; }
  select { flex: 0 1 140px; min-width: 0; min-height: 44px; padding: 9px 10px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
  .spinner { flex: none; width: 18px; height: 18px; border: 3px solid var(--line); border-top-color: var(--action); border-radius: 50%; visibility: hidden; }
  .spinner.on { visibility: visible; animation: spin .8s linear infinite; }
  @keyframes spin { to { transform: rotate(360deg); } }
  @media (prefers-reduced-motion: reduce) { .spinner.on { animation-duration: 2.4s; } }
  @media (min-width: 640px) {
    .toolbar { grid-template-columns: 1fr auto auto; grid-template-areas: "title pager scan"; gap: 12px 18px; }
    .pager { gap: 10px; }
    .pager .lbl { display: inline; }
  }
  .page-wrap { position: relative; min-height: 260px; }
  #canvasWrap { width: 100%; display: flex; justify-content: center; }
  #pdfCanvas { display: block; background: #fff; box-shadow: 0 2px 10px rgba(0,0,0,.28); pointer-events: none; }
  .loading { position: absolute; left: 0; right: 0; top: 50%; transform: translateY(-50%); z-index: 2; display: flex; flex-direction: column; align-items: center; gap: 10px; color: var(--muted); text-align: center; }

  /* welcome splash */
  .welcome { position: fixed; inset: 0; z-index: 50; background: var(--ink); color: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: 24px; text-align: center; }
  .welcome img { max-width: min(520px, 100%); max-height: 52vh; object-fit: contain; border-radius: 10px; pointer-events: none; }
  .welcome h1 { margin: 0; font-size: 2.2rem; }
  .welcome p { margin: 0; color: #c5cfda; max-width: 40ch; }
  .welcome button { background: #f1c453; border-color: #f1c453; color: #1b2430; font-size: 1.1rem; padding: 12px 34px; }


  /* screenshot / print shield */
  .shield { position: fixed; inset: 0; z-index: 300; background: var(--ink); color: #fff; display: grid; place-items: center; text-align: center; padding: 24px; font-family: var(--display); font-size: 1.3rem; }
  @media print { body > * { display: none !important; } }
  .welcome { padding-top: 96px; }

  /* full screen */
  html.fs-lock, html.fs-lock body { overflow: hidden; }
  .viewer-box.fs { position: fixed; inset: 0; z-index: 200; display: flex; flex-direction: column; gap: 8px; padding: 8px; background: #11161c; }
  .viewer-box.fs .toolbar { margin: 0; grid-template-columns: 1fr auto; grid-template-areas: "pager scan"; }
  .viewer-box.fs .doc-title, .viewer-box.fs #newScanBtn { display: none; }
  .viewer-box.fs .page-wrap { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; }
  .viewer-box.fs #canvasWrap { height: 100%; align-items: center; }
