/* The on-device scanner (SCANNER_MODE=local). One screen at a time, sized to the phone: a slim
   top bar, a content area that takes the rest, and a bottom action bar. The app is dark, like a
   camera; the print on its white card is the one bright thing on the result screen.
   The server flow's pages use site.css and do not load this file. */

:root {
  color-scheme: dark;
  --ink: #16212c;
  --ink-raised: #1f2d3b;
  --ink-line: rgb(255 255 255 / 0.16);
  --text: #eef3f7;
  --muted: #a9b7c4;
  --paper: #ffffff;
  --paper-ink: #16212c;
  --accent: #6fdccc;
  --good: #8fe3b4;
  --warn: #ffd27a;
  --bad: #ffa397;
  --focus: #ffd166;
  --radius: 12px;
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --font-body: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --gutter-left: max(var(--space-3), var(--safe-left));
  --gutter-right: max(var(--space-3), var(--safe-right));
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  block-size: 100%;
  background: var(--ink);
  overscroll-behavior: none;
}

body {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: center;
  margin: 0;
  min-block-size: 100%;
  background: var(--ink);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.4;
}

[hidden] {
  display: none !important;
}

.visually-hidden {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

h1,
h2,
h3,
p,
ol,
ul {
  margin: 0;
}

button,
select,
input {
  font: inherit;
  font-size: max(1rem, 16px);
}

button {
  touch-action: manipulation;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

h1:focus {
  outline: none;
}

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

/* A fixed-height column: the content area scrolls inside it when it cannot fit. The content
   area's floor lets the whole page scroll instead in the rare case the bars alone fill the
   viewport (landscape with large text), so nothing is ever cut off. */
.app {
  display: flex;
  flex: 0 1 30rem;
  flex-direction: column;
  min-inline-size: 0;
  inline-size: 100%;
  max-inline-size: 30rem;
  block-size: 100svh;
  block-size: 100dvh;
}

.app-bar {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: calc(var(--safe-top) + var(--space-2)) var(--gutter-right) var(--space-2) var(--gutter-left);
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-inline-size: 0;
  font-weight: 650;
  letter-spacing: 0.01em;
}

.brand-mark {
  flex: none;
  inline-size: 1.5rem;
  block-size: 1.5rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.15;
  stroke-linecap: round;
}

.brand-accent {
  stroke: var(--accent);
}

.steps {
  display: flex;
  gap: var(--space-1);
  margin-inline-start: auto;
  padding: 0;
  list-style: none;
}

.steps li {
  inline-size: 1.25rem;
  block-size: 0.25rem;
  border-radius: 999px;
  background: var(--ink-line);
}

.steps li[aria-current="step"] {
  background: var(--accent);
}

.app-main {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-block-size: 9rem;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.app-actions {
  flex: none;
  padding: var(--space-3) var(--gutter-right) calc(var(--space-3) + var(--safe-bottom)) var(--gutter-left);
}

.alert {
  margin: var(--space-2) var(--gutter-right) var(--space-2) var(--gutter-left);
  border: 1px solid var(--warn);
  border-radius: var(--radius);
  padding: var(--space-3);
  color: var(--warn);
}

/* Without scripting only the notice above is useful. */
@media (scripting: none) {
  .app-main,
  .app-actions,
  .app-bar .steps,
  .app-bar .switch {
    display: none;
  }
}

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

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-inline-size: 2.75rem;
  min-block-size: 2.75rem;
  border: 1px solid rgb(255 255 255 / 0.4);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  padding: var(--space-2) var(--space-4);
  font-weight: 600;
  line-height: 1.15;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.button:active,
.adjust-bar button:active {
  background: rgb(255 255 255 / 0.16);
}

.button-primary {
  min-block-size: 3rem;
  border-color: var(--paper);
  background: var(--paper);
  color: var(--paper-ink);
}

.button-primary:active {
  border-color: #cfd9e2;
  background: #cfd9e2;
}

.button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.button[aria-pressed="true"] {
  border-color: var(--accent);
  color: var(--accent);
}

.button[aria-pressed="true"]::after {
  content: " on";
  white-space: pre;
}

.file-button {
  display: flex;
}

.file-button .button {
  flex: 1;
}

.file-button input:focus-visible + .button {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

/* A checkbox drawn as a switch. The input covers the whole control, so the tap target is the
   label's box. */
.switch {
  position: relative;
  display: inline-flex;
  flex: none;
  align-items: center;
  gap: var(--space-2);
  min-block-size: 2.75rem;
  color: var(--muted);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
}

.switch input {
  position: absolute;
  z-index: 1;
  inset: 0;
  inline-size: 100%;
  block-size: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.switch-track {
  position: relative;
  flex: none;
  inline-size: 2.5rem;
  block-size: 1.5rem;
  border-radius: 999px;
  background: rgb(255 255 255 / 0.22);
  transition: background-color 120ms ease;
}

.switch-track::after {
  content: "";
  position: absolute;
  inset-block-start: 0.1875rem;
  inset-inline-start: 0.1875rem;
  inline-size: 1.125rem;
  block-size: 1.125rem;
  border-radius: 50%;
  background: var(--paper);
  transition: transform 120ms ease;
}

.switch input:checked + .switch-track {
  background: var(--accent);
}

.switch input:checked + .switch-track::after {
  transform: translateX(1rem);
  background: var(--ink);
}

.switch input:focus-visible + .switch-track {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.switch:has(input:checked) {
  color: var(--text);
}

/* --- screens ----------------------------------------------------------------------------- */

.screen {
  display: flex;
  flex: 1 0 auto;
  flex-direction: column;
  min-inline-size: 0;
}

.screen-title {
  padding: 0 var(--gutter-right) var(--space-2) var(--gutter-left);
  font-size: 1.0625rem;
  font-weight: 650;
  line-height: 1.25;
}

/* The hero of each screen takes what is left. Its floor keeps it usable when the developer panel
   or an open disclosure shares the content area, which then scrolls. */
.camera,
.stage,
.print {
  flex: 1 1 auto;
  min-block-size: 13rem;
  min-block-size: clamp(13rem, 52dvh, 26rem);
}

.guide {
  position: absolute;
  inset: 0;
  inline-size: 100%;
  block-size: 100%;
  pointer-events: none;
}

.guide-shade {
  fill: rgb(8 13 18 / 0.5);
}

/* Dual-stroke guide (WCAG 1.4.11): a dark halo under a light line reads over any photo. */
.guide-stroke-dark,
.guide-stroke-light {
  fill: none;
  vector-effect: non-scaling-stroke;
}

.guide-stroke-dark {
  stroke: rgb(0 0 0 / 0.75);
  stroke-width: 6px;
}

.guide-stroke-light {
  stroke: #fff;
  stroke-width: 2.5px;
}

/* capture */

.camera {
  display: flex;
}

.camera-viewer {
  position: relative;
  flex: 1;
  min-inline-size: 0;
  overflow: hidden;
  background: #0a1017;
}

.camera-viewer video {
  position: absolute;
  inset: 0;
  inline-size: 100%;
  block-size: 100%;
  object-fit: cover;
}

.camera-viewer[data-state="ready"] .guide-stroke-light,
.camera-viewer[data-state="captured"] .guide-stroke-light {
  stroke: var(--accent);
}

.viewer-switch {
  position: absolute;
  inset-block-start: var(--space-2);
  inset-inline-start: var(--gutter-left);
  border-radius: 999px;
  background: rgb(8 13 18 / 0.72);
  padding-inline: var(--space-3);
  color: var(--text);
}

.viewer-text {
  position: absolute;
  inset-block-end: var(--space-2);
  inset-inline: var(--gutter-left) var(--gutter-right);
  display: grid;
  justify-items: center;
}

.camera-instruction,
.camera-status {
  max-inline-size: 100%;
  border-radius: var(--radius);
  background: rgb(8 13 18 / 0.78);
  padding: var(--space-1) var(--space-3);
  font-size: 0.9375rem;
  font-weight: 600;
  text-align: center;
  text-wrap: balance;
}

.camera-instruction:empty,
.camera-status:empty {
  display: none;
}

/* While the live instruction shows, the status line (the same words, for screen readers) is not
   drawn a second time. */
.camera-instruction:not(:empty) + .camera-status {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.tips {
  flex: none;
  padding: 0 var(--gutter-right) 0 var(--gutter-left);
  color: var(--muted);
  font-size: 0.9375rem;
}

.tips summary {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-block-size: 2.75rem;
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}

.tips summary::-webkit-details-marker {
  display: none;
}

.tips summary::before {
  content: "+";
  display: inline-grid;
  place-items: center;
  inline-size: 1.25rem;
  block-size: 1.25rem;
  border: 1px solid var(--ink-line);
  border-radius: 50%;
  font-weight: 500;
  line-height: 1;
}

.tips[open] summary::before {
  content: "\2212";
}

.tips ol,
.tips ul {
  display: grid;
  gap: var(--space-2);
  padding: 0 0 var(--space-3) 1.25rem;
}

.tips strong {
  color: var(--text);
}

/* adjust */

.stage {
  position: relative;
  overflow: hidden;
  background: #0a1017;
  touch-action: none;
  cursor: grab;
}

.stage:focus-visible {
  outline-offset: -3px;
}

.stage-image {
  position: absolute;
  inset-block-start: 50%;
  inset-inline-start: 50%;
  max-inline-size: none;
  user-select: none;
  -webkit-user-drag: none;
  transform-origin: center;
  will-change: transform;
}

.adjust-bar {
  display: grid;
  flex: none;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: var(--space-1);
  padding: var(--space-2) var(--gutter-right) 0 var(--gutter-left);
}

.adjust-bar button {
  min-inline-size: 0;
  min-block-size: 2.75rem;
  border: 1px solid var(--ink-line);
  border-radius: var(--radius);
  background: var(--ink-raised);
  color: var(--text);
  padding: 0;
  font-size: 1.375rem;
  line-height: 1;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.adjust-bar .adjust-word {
  font-size: 0.9375rem;
  font-weight: 600;
}

/* result */

.screen-result {
  padding: 0 var(--gutter-right) 0 var(--gutter-left);
}

.print {
  position: relative;
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: var(--radius);
  background: var(--ink-raised);
}

.print[data-state="done"] {
  background: var(--paper);
}

.print-image {
  position: absolute;
  inset: var(--space-3);
  inline-size: calc(100% - 2 * var(--space-3));
  block-size: calc(100% - 2 * var(--space-3));
  object-fit: contain;
}

.print-note {
  display: grid;
  justify-items: center;
  gap: var(--space-3);
  max-inline-size: 22rem;
  padding: var(--space-4);
  text-align: center;
}

.spinner {
  inline-size: 2.25rem;
  block-size: 2.25rem;
  border: 3px solid var(--ink-line);
  border-block-start-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.verdict {
  display: grid;
  flex: none;
  gap: var(--space-1);
  padding-block-start: var(--space-3);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.chip {
  border: 1px solid var(--ink-line);
  border-radius: 999px;
  padding: 0.125rem var(--space-3);
  font-size: 0.9375rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.chip[data-level="none"] {
  border-color: var(--good);
  color: var(--good);
}

.chip[data-level="warning"] {
  border-color: var(--warn);
  color: var(--warn);
}

.chip[data-level="low"] {
  border-color: var(--bad);
  color: var(--bad);
}

.verdict-line {
  min-block-size: 1.4em;
}

/* --- action bar -------------------------------------------------------------------------- */

/* The primary action spans the bar; the others share the row under it. */
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.actions > * {
  flex: 1 1 40%;
  min-inline-size: 0;
}

.actions > .button-primary {
  flex-basis: 100%;
}

/* Capture: Start camera over the two photo sources; once the camera runs, torch, shutter and
   stop on one row. */
.app[data-camera="on"] .actions-capture {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
}

.app[data-camera="on"] .actions-capture .file-button {
  display: none;
}

.app[data-camera="on"] .actions-capture [data-js="camera-torch"] {
  grid-column: 1;
  justify-self: start;
}

.app[data-camera="on"] .actions-capture .shutter {
  grid-column: 2;
}

.app[data-camera="on"] .actions-capture [data-js="camera-stop"] {
  grid-column: 3;
  justify-self: end;
}

.shutter {
  inline-size: 4.25rem;
  block-size: 4.25rem;
  border: 3px solid var(--paper);
  border-radius: 50%;
  background: var(--paper);
  box-shadow: inset 0 0 0 3px var(--ink);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.shutter:active {
  background: #cfd9e2;
}

.shutter:disabled {
  opacity: 0.45;
}

/* --- developer panel --------------------------------------------------------------------- */

.dev {
  display: grid;
  flex: none;
  gap: var(--space-2);
  margin-block-start: var(--space-3);
  border-block-start: 1px dashed var(--ink-line);
  padding: var(--space-3) var(--gutter-right) var(--space-3) var(--gutter-left);
}

.dev h2 {
  font-size: 1rem;
}

.dev h3 {
  color: var(--muted);
  font-size: 0.875rem;
  font-weight: 600;
}

.dev-text {
  margin: 0;
  max-block-size: 18rem;
  overflow: auto;
  border-radius: var(--radius);
  background: #0f1820;
  padding: var(--space-2) var(--space-3);
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.dev-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

.dev-row select {
  flex: 1 1 8rem;
  min-inline-size: 0;
  min-block-size: 2.75rem;
  border: 1px solid var(--ink-line);
  border-radius: var(--radius);
  background: var(--ink-raised);
  color: var(--text);
  padding-inline: var(--space-2);
}

.dev-status {
  color: var(--muted);
  font-size: 0.875rem;
}

.dev-status:empty {
  display: none;
}

.dev-stages {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(8.5rem, 1fr));
  gap: var(--space-2);
}

.dev-stages figure {
  display: grid;
  gap: var(--space-1);
  margin: 0;
  color: var(--muted);
  font-size: 0.8125rem;
}

.dev-stages img {
  inline-size: 100%;
  block-size: auto;
  border-radius: 6px;
  background: var(--paper);
}

/* --- not-found page ---------------------------------------------------------------------- */

.lost {
  display: grid;
  flex: 0 1 30rem;
  gap: var(--space-3);
  justify-items: start;
  padding: calc(var(--safe-top) + 2rem) var(--gutter-right) var(--space-4) var(--gutter-left);
}

.lost h1 {
  font-size: 1.375rem;
}

.lost p {
  color: var(--muted);
}

/* --- desktop hand-off -------------------------------------------------------------------- */

/* Never shown on touch-first devices: nobody on a phone needs a QR code to a phone. */
.handoff {
  display: none;
}

@media (pointer: fine) and (hover: hover) {
  .handoff {
    display: grid;
    flex: 0 1 20rem;
    gap: var(--space-3);
    margin: var(--space-4);
    border: 1px solid var(--ink-line);
    border-radius: var(--radius);
    padding: var(--space-4);
    color: var(--muted);
  }

  .handoff h2 {
    color: var(--text);
    font-size: 1.125rem;
    line-height: 1.25;
  }

  .handoff a {
    color: var(--accent);
    overflow-wrap: anywhere;
  }

  .handoff-qr svg {
    display: block;
    inline-size: min(100%, 12rem);
    block-size: auto;
    border-radius: 6px;
  }

  .app {
    border-inline: 1px solid var(--ink-line);
  }
}

@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation: none;
    border-block-start-color: var(--ink-line);
    border-inline-start-color: var(--accent);
  }

  .switch-track,
  .switch-track::after {
    transition: none;
  }
}
