/* The in-app scanner: a viewfinder, a square, and one way out.
 *
 * Deliberately plain furniture — tokens only, no new palette, nothing that
 * a redesign would have to unpick. The camera image supplies all the colour
 * this surface will ever have. */

/* ------------------------------------------------- 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: 2.75rem;
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  text-align: left;
  font: inherit;
  color: var(--moon);
  background: rgb(255 255 255 / 0.03);
  border: 1px solid rgb(184 134 59 / 0.35);
  border-radius: var(--radius-card);
  padding: var(--sp-3) var(--sp-4);
  margin: var(--sp-4) 0 var(--sp-2);
  cursor: pointer;
  transition: border-color var(--t-fast) var(--ease),
              background-color var(--t-fast) var(--ease);
}

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

.scanentry .mark {
  flex: none;
  width: 1.75rem;
  text-align: center;
  font-size: 1.25rem;
  line-height: 1;
  color: var(--brass);
}

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

.scanentry b {
  display: block;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: var(--text-lg);
  color: var(--paper);
}

.scanentry em {
  display: block;
  font-size: var(--text-xs);
  font-style: italic;
  color: var(--moon-soft);
  margin-top: 0.15em;
}

/* the door has no shelf to sit near, so it sits under the field instead */
.landing .scanentry {
  max-width: 20rem;
  margin: var(--sp-6) auto 0;
}

/* --------------------------------------------------- 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(23 26 46 / 0.55),
              inset 0 0 0 1px rgb(23 26 46 / 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(23 26 46 / 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(23 26 46 / 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: var(--moon-soft);
}

.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;
  color: var(--moon);
  background: rgb(255 255 255 / 0.06);
  border: 1px solid rgb(255 255 255 / 0.10);
  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(23 26 46 / 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: var(--moon-soft);
  margin: 0;
}

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