/* g3-app · scan.css (feature: Scan / My code)
   Paper p-5-0 "Scan · 09 scanner" + "Scan · 10 my code": dark camera screen, fixed to the
   viewport the width of the phone column. */

.screen[data-screen="scan"] { padding-bottom: 0; }

.scan {
  --scan-ground: #1A1816;
  --scan-track: rgba(255, 255, 255, 0.12);
  --scan-btn: rgba(255, 255, 255, 0.14);
  --scan-dim: rgba(26, 24, 22, 0.45);
  --scan-finder: 240px;
  position: fixed; top: 0; bottom: 0; left: 50%;
  width: 100%; max-width: var(--col);
  transform: translateX(-50%);
  z-index: 1;
  display: flex; flex-direction: column; align-items: center;
  padding: var(--safe-top) var(--gutter) calc(var(--safe-bottom) + var(--foot-gap));
  background: var(--scan-ground);
  color: var(--white);
  overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain;
}

/* camera feed, full bleed behind everything */
.scan-video {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; opacity: 0; pointer-events: none;
  transition: opacity var(--dur) var(--ease);
}
.scan-video.is-on { opacity: 1; }
.scan[data-tab="code"] .scan-video { opacity: 0; }
.scan-dim { position: absolute; inset: 0; background: var(--scan-dim); pointer-events: none; }
.scan-seg, .scan-panes, .scan-foot { position: relative; z-index: 1; }

/* segmented control: two equal halves, a white thumb slides between them */
.scan-seg {
  flex: 0 0 auto;
  display: flex; gap: 4px; width: 100%; height: 48px; padding: 4px;
  border-radius: var(--r-pill); background: var(--scan-track);
}
.scan-seg button {
  position: relative; z-index: 1;
  flex: 1 1 0; display: flex; align-items: center; justify-content: center;
  border-radius: var(--r-pill);
  font-family: var(--f-ui); font-size: 15px; line-height: 20px; font-weight: 600;
  color: var(--white);
  transition: color var(--dur-fast) var(--ease);
}
.scan-seg button[aria-selected="true"] { color: var(--ink); }
.scan-seg-thumb {
  position: absolute; top: 4px; bottom: 4px; left: 4px;
  width: calc((100% - 12px) / 2);
  border-radius: var(--r-pill); background: var(--white);
  transition: transform var(--dur) var(--ease);
}
.scan[data-tab="code"] .scan-seg-thumb { transform: translateX(calc(100% + 4px)); }

/* the two panes share one cell and crossfade */
.scan-panes { flex: 1 0 auto; display: grid; width: 100%; min-height: 0; } /* never shorter than its copy: on short phones the layer scrolls instead of the close button sitting on the text */
.scan-pane {
  grid-area: 1 / 1;
  display: flex; flex-direction: column; align-items: center; min-height: 0;
  opacity: 0; visibility: hidden;
}
.scan-pane.is-on { opacity: 1; visibility: visible; }
.scan.is-ready .scan-pane { transition: opacity var(--dur-fast) var(--ease), visibility 0s linear var(--dur-fast); }
.scan.is-ready .scan-pane.is-on { transition: opacity var(--dur-fast) var(--ease), visibility 0s; }

/* bottom copy */
.scan-text {
  margin-top: auto; padding: 24px 8px 0;
  display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center;
}
.scan-text.is-swap { display: grid; justify-items: center; }
.scan-swap { grid-area: 1 / 1; gap: 10px; display: flex; flex-direction: column; align-items: center; transition: opacity var(--dur-fast) var(--ease); }
.scan-swap.is-done { opacity: 0; visibility: hidden; }
.scan[data-state="done"] .scan-swap.is-idle { opacity: 0; visibility: hidden; }
.scan[data-state="done"] .scan-swap.is-done { opacity: 1; visibility: visible; }
.scan-title { font-size: 32px; line-height: 34px; color: var(--white); text-wrap: balance; }
.scan-lead { font-family: var(--f-ui); font-size: 15px; line-height: 21px; color: var(--white); opacity: 0.8; text-wrap: balance; max-width: 330px; }

/* viewfinder */
.scan-finder {
  position: relative; flex: 0 0 auto;
  width: var(--scan-finder); height: var(--scan-finder);
  margin-top: min(150px, 17.8dvh);
}
.scan-corners { position: absolute; inset: 0; width: 100%; height: 100%; color: var(--white); }
.scan-line, .scan-tick, .scan-corners { pointer-events: none; }
.scan-line {
  position: absolute; left: 24px; right: 24px; top: 118px; height: 3px;
  border-radius: 2px; background: var(--red);
}
.scan[data-state="scanning"] .scan-line { animation: scan-sweep 1.8s linear infinite; }
.scan[data-state="done"] .scan-line, .scan[data-state="nocam"] .scan-line { opacity: 0; }
@keyframes scan-sweep {
  0% { transform: translateY(0); }
  25% { transform: translateY(-94px); }
  75% { transform: translateY(94px); }
  100% { transform: translateY(0); }
}
.scan-tap { position: absolute; inset: 0; border-radius: 36px; display: none; }
.scan[data-state="scanning"] .scan-tap, .scan[data-state="starting"] .scan-tap { display: block; }

/* success: tick pops, the frame gives a small haptic-like squeeze */
.scan-tick {
  position: absolute; left: 50%; top: 50%;
  width: 76px; height: 76px; margin: -38px 0 0 -38px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%; background: var(--green); color: var(--white);
  opacity: 0; transform: scale(0.4);
}
.scan[data-state="done"] .scan-tick { animation: scan-pop 420ms var(--ease) both; }
.scan[data-state="done"] .scan-corners { animation: scan-squeeze 360ms var(--ease); }
@keyframes scan-pop {
  0% { opacity: 0; transform: scale(0.4); }
  60% { opacity: 1; transform: scale(1.08); }
  100% { opacity: 1; transform: scale(1); }
}
@keyframes scan-squeeze {
  0%, 100% { transform: scale(1); }
  40% { transform: scale(0.95); }
}

/* no camera: calm note inside the frame */
.scan-nocam {
  position: absolute; inset: 20px;
  display: none; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  text-align: center;
}
.scan[data-state="nocam"] .scan-nocam { display: flex; }
.scan-nocam-title { font-family: var(--f-ui); font-size: 16px; line-height: 21px; font-weight: 600; }
.scan-nocam-text { font-family: var(--f-ui); font-size: 14px; line-height: 19px; opacity: 0.8; margin-bottom: 8px; text-wrap: balance; }

/* white pill (fallback + guest) */
.scan-pill {
  display: inline-flex; align-items: center; justify-content: center;
  height: 48px; padding: 0 24px; margin-top: 14px;
  border-radius: var(--r-pill); background: var(--white); color: var(--ink);
  font-family: var(--f-sans); font-size: 17px; line-height: 20px; white-space: nowrap;
  transition: transform var(--dur-fast) var(--ease);
}
.scan-pill.is-s { height: 40px; padding: 0 18px; margin-top: 0; font-size: 15px; }
.scan-pill:active { transform: scale(0.97); }

/* my code */
.scan-code { display: flex; flex-direction: column; align-items: center; gap: 16px; margin-top: min(96px, 11.4dvh); }
.scan-meta { font-family: var(--f-sans); font-size: 16px; line-height: 20px; color: var(--white); opacity: 0.8; }
.scan-card {
  display: flex; flex-direction: column; align-items: center; gap: 16px;
  padding: 28px; border-radius: var(--r-sheet); background: var(--white); color: var(--ink);
}
.scan-qr { width: min(220px, 30dvh); height: min(220px, 30dvh); color: var(--ink); }
.scan-no {
  font-family: var(--f-sans); font-size: 17px; line-height: 20px; letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums; color: var(--ink); white-space: nowrap;
}

/* close */
.scan-foot { flex: 0 0 auto; padding-top: 28px; display: flex; justify-content: center; }
.scan-close {
  width: 52px; height: 52px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--scan-btn); color: var(--white);
  transition: transform var(--dur-fast) var(--ease);
}
.scan-close:active { transform: scale(0.94); }

/* guest prompt */
.scan.is-guest .scan-body { flex: 1 0 auto; width: 100%; display: flex; flex-direction: column; align-items: center; }
.scan-guest-mark { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--white); opacity: 0.8; }

@media (prefers-reduced-motion: reduce) {
  .scan[data-state="scanning"] .scan-line { animation: none; }
  .scan[data-state="done"] .scan-tick { animation: none; opacity: 1; transform: none; }
  .scan[data-state="done"] .scan-corners { animation: none; }
  .scan.is-ready .scan-pane, .scan.is-ready .scan-pane.is-on, .scan-seg-thumb, .scan-swap { transition: none; }
}
.scan-finder.is-guest { margin-top: calc(48px + min(150px, 17.8dvh)); }
/* short phones (375 x 667, home-screen app): a smaller finder and tighter gaps, so the
   copy and the close button fit without scrolling */
@media (max-height: 700px) {
  .scan { --scan-finder: 208px; }
  .scan-finder { margin-top: min(64px, 8dvh); }
  .scan-finder.is-guest { margin-top: calc(24px + min(64px, 8dvh)); }
  .scan-line { top: 102px; }
  .scan-text { padding-top: 16px; }
  .scan-foot { padding-top: 16px; }
  .scan-nocam { inset: 14px 10px; gap: 4px; }
  .scan-nocam-text { font-size: 13px; line-height: 17px; margin-bottom: 2px; }
  .scan-nocam .scan-pill.is-s { height: 36px; }
}
/* the page ground under the dark scan layer (Safari overscroll + toolbar tint) */
html:has(#view > .screen[data-screen="scan"]) #app { background: #1A1816; }
