/* Scan page (static/scan-page.js). Phone first: the camera fills the screen
   above the tab bar; the result slides up over the lower part of it. */

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.linkish { background: none; border: 0; padding: 0; color: var(--gold); text-decoration: underline; text-underline-offset: 2px; cursor: pointer; font: inherit; }

/* Grid so the Recogniser switch can sit beside the title on desktop and under the camera on phones. */
.scan-page { display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: var(--space-4); row-gap: var(--space-3); align-items: start; align-content: start; }
.scan-page > * { grid-column: 1 / -1; min-width: 0; }
.scan-page > .sc-head { grid-column: 1; grid-row: 1; align-self: center; }
.scan-page > .sc-engine-pick { grid-column: 2; grid-row: 1; }
.sc-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--space-2) var(--space-4); }
.sc-head .page-title { margin: 0; }
.sc-status { margin: 0; font-size: var(--text-meta); }
.sc-small { font-size: var(--text-meta); }

.sc-intro, .sc-problem, .sc-loading { max-width: 560px; padding: var(--space-5); display: grid; gap: var(--space-3); }
.sc-intro h2, .sc-problem h2 { margin: 0; font-size: var(--text-section); }
.sc-intro p, .sc-problem p, .sc-loading p { margin: 0; line-height: 1.5; }
.sc-intro-icon { width: 44px; height: 44px; fill: none; stroke: var(--gold); stroke-width: 1.5; stroke-linejoin: round; stroke-linecap: round; }
.sc-intro-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; }
.sc-file-btn { cursor: pointer; display: inline-flex; align-items: center; min-height: 40px; }
.sc-bar { height: 8px; border-radius: var(--radius-pill); background: var(--bg); border: 1px solid var(--line); overflow: hidden; }
.sc-bar span { display: block; height: 100%; width: 0; background: var(--gold); transition: width 0.2s ease; }

.sc-body { display: grid; grid-template-columns: minmax(0, 1fr) minmax(300px, 380px); gap: var(--space-4); align-items: start; }
.sc-stage {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius-panel);
  background: #000;
  aspect-ratio: 4 / 3;
  max-height: calc(100vh - 170px);
  width: 100%;
  touch-action: manipulation;
}
#sc-video, #sc-photo { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
#sc-photo { object-fit: contain; }
.sc-overlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.sc-dim { fill: rgb(0 0 0 / 42%); }
.sc-guide { fill: none; stroke: rgb(255 255 255 / 85%); stroke-width: 2; stroke-dasharray: 10 8; }
/* Outline only: a tinted fill over the card made the preview look washed out. */
.sc-quad { fill: none; stroke: var(--muted); stroke-width: 2.5; stroke-linejoin: round; }
.sc-quad.ok { stroke: var(--gold); }
.sc-guide.is-region { display: none; }

/* Region mode: the whole camera picture, with a draggable scan box. */
.sc-stage.region #sc-video { object-fit: contain; }
.sc-stage.region { aspect-ratio: 16 / 9; }
.sc-roi {
  position: absolute; border: 2px solid rgb(255 255 255 / 90%); border-radius: 4px; cursor: move; touch-action: none;
  box-shadow: 0 0 0 1px rgb(0 0 0 / 40%);
}
.sc-roi:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.sc-roi.dragging { border-color: var(--gold); }
.sc-roi-handle {
  position: absolute; width: 22px; height: 22px; border-radius: 50%; background: #fff; border: 2px solid rgb(0 0 0 / 55%);
  touch-action: none;
}
.sc-roi-handle[data-handle="nw"] { left: -12px; top: -12px; cursor: nwse-resize; }
.sc-roi-handle[data-handle="ne"] { right: -12px; top: -12px; cursor: nesw-resize; }
.sc-roi-handle[data-handle="sw"] { left: -12px; bottom: -12px; cursor: nesw-resize; }
.sc-roi-handle[data-handle="se"] { right: -12px; bottom: -12px; cursor: nwse-resize; }

.sc-focus {
  position: absolute; width: 64px; height: 64px; margin: -32px 0 0 -32px; border: 2px solid var(--gold); border-radius: 50%;
  pointer-events: none; opacity: 0;
}
.sc-focus.go { animation: sc-focus 0.9s ease-out; }
@keyframes sc-focus { 0% { opacity: 1; transform: scale(1.4); } 40% { opacity: 1; transform: scale(1); } 100% { opacity: 0; transform: scale(1); } }

.sc-debug {
  position: absolute; left: var(--space-2); top: calc(var(--space-3) + 34px); max-width: calc(100% - 2 * var(--space-2));
  display: flex; gap: 6px; align-items: flex-start; pointer-events: none; z-index: 3;
}
.sc-debug pre {
  margin: 0; padding: 6px 8px; border-radius: 6px; background: rgb(0 0 0 / 72%); color: #d7f7c8;
  font: 10.5px/1.35 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: pre-wrap; overflow-wrap: anywhere;
}
.sc-debug canvas { width: 54px; height: 76px; border-radius: 4px; background: #000; border: 1px solid rgb(255 255 255 / 40%); flex: none; }

.sc-settings {
  position: absolute; right: var(--space-2); bottom: calc(var(--space-3) + 82px); z-index: 5;
  width: min(330px, calc(100% - 2 * var(--space-2))); max-height: calc(100% - 100px); overflow: auto;
  padding: var(--space-3); display: grid; gap: var(--space-3);
}
.sc-settings[hidden] { display: none; }
.sc-set-row { display: grid; gap: var(--space-1); }
.sc-set-row .sc-label { margin: 0; }
.sc-set-row select, .sc-set-row input[type="range"] { width: 100%; }
.sc-set-row .seg { display: flex; }
.sc-set-row .seg button { flex: 1; }
.sc-set-check { display: flex; gap: var(--space-2); align-items: center; font-size: var(--text-meta); }
.sc-hint {
  position: absolute; left: 50%; top: var(--space-3); transform: translateX(-50%);
  margin: 0; padding: 6px 14px; border-radius: var(--radius-pill);
  background: rgb(0 0 0 / 62%); color: #fff; font-size: var(--text-meta); font-weight: 600; white-space: nowrap;
}
.sc-hint:empty { display: none; }
.sc-controls {
  position: absolute; left: 0; right: 0; bottom: var(--space-3);
  display: flex; justify-content: center; align-items: center; gap: var(--space-4);
  pointer-events: none; /* the strip lets drags reach the scan region; only its buttons take clicks */
}
.sc-controls > * { pointer-events: auto; }
.sc-hint { pointer-events: none; }
.sc-round {
  display: grid; place-items: center; width: 48px; height: 48px; border-radius: 50%;
  border: 1px solid rgb(255 255 255 / 35%); background: rgb(0 0 0 / 55%); color: #fff;
  font-size: var(--text-micro); font-weight: 700; letter-spacing: 0.02em; cursor: pointer;
}
.sc-round[hidden] { display: none; }
.sc-round svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.sc-round[aria-pressed="true"] { background: var(--gold); color: #241c16; border-color: var(--gold); }
.sc-shutter {
  width: 72px; height: 72px; border-radius: 50%; border: 4px solid #fff; background: transparent; padding: 4px; cursor: pointer;
}
.sc-shutter span { display: block; width: 100%; height: 100%; border-radius: 50%; background: #fff; }
.sc-shutter:active span { background: var(--gold); }

.sc-side { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-3); min-width: 0; }
.sc-idle { padding: var(--space-4); }
.sc-idle p { margin: 0 0 var(--space-2); }
.sc-idle ul { margin: 0; padding-left: 1.1em; display: grid; gap: var(--space-1); font-size: var(--text-meta); line-height: 1.45; }

.sc-result { padding: var(--space-4); display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-3); min-width: 0; }
.sc-match { display: grid; grid-template-columns: 132px minmax(0, 1fr); gap: var(--space-3); align-items: start; }
.sc-art { position: relative; }
#sc-card-img { width: 132px; aspect-ratio: 488 / 680; border-radius: 6px; background: var(--bg); display: block; object-fit: cover; }
#sc-crop {
  position: absolute; right: -6px; bottom: -6px; width: 44px; height: 62px;
  border-radius: 4px; border: 2px solid var(--raised); box-shadow: 0 2px 8px rgb(0 0 0 / 40%); background: var(--bg);
}
.sc-info h2 { margin: 2px 0; font-size: var(--text-section); line-height: 1.2; overflow-wrap: anywhere; }
.sc-info .sub { margin: 0; color: var(--muted); font-size: var(--text-meta); }
.sc-confidence { margin: 0; font-size: var(--text-micro); font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
.sc-confidence[data-tone="sure"] { color: var(--up); }
.sc-confidence[data-tone="check"], .sc-confidence[data-tone="pick"] { color: var(--gold); }
.sc-confidence[data-tone="guess"] { color: var(--danger); }
.sc-note { margin: var(--space-2) 0 0; font-size: var(--text-meta); line-height: 1.4; color: var(--gold); }
.sc-label { margin: 0 0 var(--space-1); font-size: var(--text-meta); color: var(--muted); font-weight: 600; }
.sc-same { display: grid; gap: var(--space-2); min-width: 0; }
.sc-same-chips { display: flex; gap: var(--space-2); overflow-x: auto; padding-bottom: var(--space-1); scroll-snap-type: x proximity; }
.sc-same-chip {
  flex: 0 0 auto; min-height: 44px; padding: 0 14px; border: 1px solid var(--line); border-radius: var(--radius-pill);
  background: var(--bg); color: var(--text); font: inherit; font-size: var(--text-meta); font-weight: 600;
  cursor: pointer; scroll-snap-align: start; display: inline-flex; align-items: center; justify-content: center; white-space: nowrap;
}
.sc-same-chip[aria-selected="true"] { background: var(--gold); color: var(--ink); border-color: var(--gold); }
.sc-same-chip:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.sc-setlock { display: flex; align-items: center; gap: var(--space-2); min-height: 44px; font-size: var(--text-meta); font-weight: 600; color: var(--muted); }
.sc-setlock input { width: 7.5rem; min-height: 44px; text-transform: uppercase; }
.sc-alts { display: flex; gap: var(--space-2); overflow-x: auto; padding-bottom: var(--space-1); scroll-snap-type: x proximity; }
.sc-alt {
  flex: 0 0 76px; display: grid; gap: 2px; padding: 0; border: 0; background: none; color: var(--text);
  text-align: left; font-size: var(--text-micro); scroll-snap-align: start; cursor: pointer;
}
.sc-alt img { width: 76px; aspect-ratio: 488 / 680; border-radius: 4px; background: var(--bg); object-fit: cover; }
.sc-alt span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sc-alt .sub { color: var(--muted); }
.sc-alts-wrap .linkish { font-size: var(--text-meta); margin-top: var(--space-1); }
.sc-printing-list { display: grid; gap: 2px; max-height: 260px; overflow: auto; border: 1px solid var(--line); border-radius: var(--radius-row); padding: var(--space-1); }
.sc-printing { width: 100%; border: 0; background: none; color: var(--text); text-align: left; cursor: pointer; }
.sc-printing:hover { background: var(--bg); }
.sc-form { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: center; }
.sc-qty { display: flex; align-items: center; gap: var(--space-1); }
.sc-qty .btn { width: 40px; height: 40px; padding: 0; font-size: 1.2rem; }
.sc-qty input { width: 3.6rem; text-align: center; height: 40px; }
.sc-actions { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-2); }
.sc-actions .btn { min-height: 44px; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
#sc-add { grid-column: 1 / -1; font-weight: 700; }
.sc-enter { grid-column: 1 / -1; margin: 0; }
.sc-session { padding: 0 var(--space-1); }
.sc-session ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.sc-toast { margin: 0; padding: var(--space-2) var(--space-3); display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); }
.sc-toast[hidden] { display: none; }
.sc-foot { margin: 0; }
.sc-foot a { color: var(--muted); }

/* Recogniser switch: CollectorVision | Our scanner (beta). A radio group styled like .seg. */
.sc-engine-pick { display: grid; grid-template-columns: auto auto; align-items: center; justify-content: end; column-gap: var(--space-2); row-gap: 2px; }
.sc-engine-pick .sc-label { margin: 0; }
.sc-engine-seg button { min-height: 36px; padding: 0 14px; white-space: nowrap; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.sc-engine-seg button[aria-checked="true"] { background: var(--gold); color: var(--ink); }
.sc-engine-seg button:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.sc-beta {
  font-size: 10px; line-height: 1; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
  padding: 2px 5px; border-radius: var(--radius-pill); border: 1px solid currentColor; opacity: 0.85;
}
.sc-engine-help { grid-column: 1 / -1; margin: 0; text-align: right; }
/* Swapping recognisers on a live camera: the shutter waits. */
.sc-body.is-switching .sc-shutter { opacity: 0.45; }
/* Which recogniser produced the result (compare CV vs ours). */
.sc-engine {
  display: inline-block; margin: var(--space-1) 0 0; padding: 1px 8px; border: 1px solid var(--line); border-radius: var(--radius-pill);
  font-size: var(--text-micro); font-weight: 600; color: var(--muted);
}
.sc-engine[data-engine="own"] { color: var(--gold); border-color: var(--gold); }

@media (max-width: 800px) {
  body[data-view="scan"] .view.scan-page { padding: var(--space-2) var(--space-2) var(--space-4); }
  body[data-view="scan"] footer.rail { display: none; }
  .sc-head { padding: 0 var(--space-2); }
  /* Phones: the switch drops under the camera (thumb reach), full width, 44px targets. */
  .scan-page { grid-template-columns: minmax(0, 1fr); row-gap: var(--space-2); }
  .scan-page > .sc-engine-pick { grid-column: 1; grid-row: auto; order: 2; }
  /* Lift the camera and the side column into the page grid so the switch sits right under the camera. */
  .sc-body { display: contents; }
  .sc-stage { order: 1; }
  .sc-side { order: 3; }
  .sc-engine-pick { grid-template-columns: minmax(0, 1fr); justify-content: stretch; padding: 0 var(--space-2); row-gap: var(--space-1); }
  .sc-engine-pick .sc-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .sc-engine-seg { display: flex; }
  .sc-engine-seg button { flex: 1 1 0; min-height: 44px; padding: 0 8px; }
  .sc-engine-help { text-align: center; }
  .sc-body { grid-template-columns: 1fr; gap: var(--space-2); }
  /* 230px: app header, page title and tab bar; 80px: the Recogniser switch under the camera. */
  .sc-stage { aspect-ratio: auto; height: calc(100svh - 310px - env(safe-area-inset-bottom)); min-height: 340px; max-height: none; }
  .sc-intro, .sc-problem, .sc-loading { margin: 0 var(--space-2); }
  /* The result sheet covers the lower part of the camera, above the tab bar. */
  .sc-body.has-result .sc-result {
    position: fixed; left: 0; right: 0; z-index: 14;
    bottom: calc(64px + env(safe-area-inset-bottom));
    max-height: min(74svh, 640px); overflow-y: auto;
    border-radius: var(--radius-panel) var(--radius-panel) 0 0; border-bottom: 0;
    box-shadow: 0 -10px 30px rgb(0 0 0 / 45%);
    padding-bottom: var(--space-3);
  }
  .sc-body.has-result .sc-controls { visibility: hidden; }
  /* Top of the screen, so it never covers the result sheet's buttons. */
  .sc-toast { position: fixed; left: var(--space-2); right: var(--space-2); top: calc(var(--space-2) + env(safe-area-inset-top)); z-index: 16; box-shadow: 0 6px 20px rgb(0 0 0 / 35%); }
  .sc-match { grid-template-columns: 104px minmax(0, 1fr); }
  #sc-card-img { width: 104px; }
}
@media (max-width: 720px) {
  body:not(.signed-in) .sc-body.has-result .sc-result { bottom: 0; }
  /* The raised Scan tab covers the bottom of the sheet. */
  body.signed-in .sc-body.has-result .sc-result { padding-bottom: calc(var(--space-3) + 28px); }
}


@media (prefers-reduced-motion: reduce) {
  .sc-focus-ring, .sc-pulse, .sc-lock-flash, [class*="pulse"] { animation: none !important; transition: none !important; }
}
#sc-add.primary { font-size: 1.0625rem; min-height: 52px; }
