/* The in-app scanner: a viewfinder, a square, and one way out.
 *
 * Deliberately plain furniture. This is the one surface that is dark on
 * purpose — a viewfinder is — so the scrim, the guide square and the
 * cream on the bar are written here rather than in tokens.css: a re-skin
 * of the linen world should not have to think about the camera. */

/* ------------------------------------------------- the entry point */

/* Near the envelopes, because that is what it is for: a new envelope in her
 * hands, and a code in it. */
.scanentry {
  width: 100%;
  min-height: 3.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-3);
  text-align: center;
  font: inherit;
  color: var(--night-ink);
  background: var(--night);
  border: none;
  outline: var(--stitch-w) dashed rgb(255 255 255 / 0.4);
  outline-offset: var(--stitch-in);
  border-radius: var(--radius-card);
  padding: var(--sp-4);
  margin: var(--sp-6) 0 var(--sp-2);
  cursor: pointer;
  box-shadow: 0 4px 12px rgb(74 74 56 / 0.35);
  transition: outline-color var(--t-fast) var(--ease),
              transform var(--t-fast) var(--ease);
}

.scanentry:hover,
.scanentry:focus-visible { outline-color: var(--night-ink); }
.scanentry:active { transform: scale(0.99); }

.scanentry .mark {
  flex: none;
  font-size: 1.125rem;
  line-height: 1;
  color: var(--night-ink);
  opacity: 0.85;
}

.scanentry .body { min-width: 0; }

.scanentry b {
  display: block;
  font-family: var(--font-body);
  font-weight: 800;
  font-size: var(--text-md);
  color: var(--night-ink);
}

.scanentry em {
  display: block;
  font-size: var(--text-xs);
  font-style: normal;
  font-weight: 600;
  color: var(--night-ink);
  opacity: 0.7;
  margin-top: 0.15em;
}

/* --------------------------------------------------- the viewfinder */

.scanner {
  position: fixed;
  inset: 0;
  z-index: 75;
  display: grid;
  grid-template-rows: 1fr auto;
  background: var(--dusk-1);
}

.scan-stage {
  position: relative;
  overflow: hidden;
}

.scan-view {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: var(--dusk-1);
}

/* the square, and everything outside it dimmed by one very large shadow */
.scan-frame {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
}

.scan-frame span {
  width: min(66vw, 16rem);
  aspect-ratio: 1;
  border: 2px solid rgb(243 236 221 / 0.9);
  border-radius: var(--radius-card);
  /* the vignette outside, and a hairline inside so the frame still reads
     against a sheet of white paper */
  box-shadow: 0 0 0 100vmax rgb(60 58 48 / 0.55),
              inset 0 0 0 1px rgb(60 58 48 / 0.45);
  animation: scan-breathe 2.8s var(--ease) infinite alternate;
}

@keyframes scan-breathe {
  from { border-color: rgb(184 134 59 / 0.9); }
  to   { border-color: rgb(243 236 221 / 0.95); }
}

.scan-caption {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(var(--sp-6) + env(safe-area-inset-top));
  margin: 0 auto;
  max-width: 20rem;
  padding: 0 var(--sp-4);
  text-align: center;
  font-size: var(--text-sm);
  line-height: 1.5;
  color: var(--paper);
  text-shadow: 0 1px 6px rgb(60 58 48 / 0.9);
}

/* ---------------------------------------------------------- the bar */

.scan-bar {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  padding: var(--sp-4) calc(var(--sp-4) + env(safe-area-inset-right))
           calc(var(--sp-4) + env(safe-area-inset-bottom))
           calc(var(--sp-4) + env(safe-area-inset-left));
  border-top: 1px solid rgb(255 255 255 / 0.08);
  background: rgb(60 58 48 / 0.94);
}

/* advice arrives late or not at all, and takes up no room until it does */
.scan-hint {
  margin: 0;
  text-align: center;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: 0.04em;
  line-height: 1.4;
  color: rgb(239 233 214 / 0.75);
}

.scan-hint:empty { display: none; }

.scan-actions {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

/* the way out sits right, always in the same place, torch or no torch */
.scan-close { margin-left: auto; }

.scan-bar button {
  flex: none;
  min-height: 2.75rem;
  min-width: 2.75rem;
  font: inherit;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: 0.08em;
  /* the bar is dark: the ground tokens are dark-on-light and vanish here */
  color: #efe9d6;
  background: rgb(255 255 255 / 0.10);
  border: 1px solid rgb(255 255 255 / 0.22);
  border-radius: 999px;
  padding: var(--sp-2) var(--sp-4);
  cursor: pointer;
}

.scan-bar button:hover,
.scan-bar button:focus-visible { border-color: var(--brass); }

.scan-torch[aria-pressed="true"] {
  color: var(--dusk-1);
  background: var(--brass);
  border-color: var(--brass);
}

/* --------------------------------------------- when there is no camera */

/* Same shape as the app's other quiet moments: a mark, a short truth, and
 * one button that only ever closes. Nothing here asks the system again. */
.scanner.shut { display: block; }

.scan-card {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: calc(var(--sp-8) + env(safe-area-inset-top)) var(--sp-6)
           calc(var(--sp-8) + env(safe-area-inset-bottom));
  background:
    radial-gradient(70% 50% at 50% 30%, rgb(184 134 59 / 0.10), transparent 70%),
    rgb(60 58 48 / 0.97);
}

.scan-card-inner {
  width: 100%;
  max-width: 22rem;
  text-align: center;
}

.scan-card .mark {
  display: block;
  font-size: 2.5rem;
  line-height: 1;
  color: var(--brass);
  margin-bottom: var(--sp-6);
}

.scan-card h2 {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: var(--text-2xl);
  color: var(--paper);
  margin: 0 0 var(--sp-3);
}

.scan-card .line {
  font-size: var(--text-sm);
  line-height: 1.6;
  color: rgb(239 233 214 / 0.8);       /* cream on the dark card, like the hint */
  margin: 0;
}

@media (prefers-reduced-motion: reduce) {
  .scan-frame span { animation: none; border-color: rgb(243 236 221 / 0.8); }
}
