/* Scan stage: the camera feed in grey with a halftone texture, the HUD marks on a canvas above it,
   tiny white mono readouts, and the blue terminal dossier (a bottom sheet on phones).
   Spacing from the ladder only: 4 8 12 16 24 32 48 64. */

.scan {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: var(--scan-bg);
  color: var(--hud);
  font-family: var(--font-mono);
  overflow: hidden;
}

.scan-stage {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

/* the real video stays in the page (some browsers stop decoding a detached or hidden one) but is never seen;
   the canvas draws it so the marks share one mapping with the picture */
.scan-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  pointer-events: none;
}

.scan-feed,
.scan-marks {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.scan-feed { filter: grayscale(1) contrast(1.2) brightness(.82); }

/* halftone dots, scanlines and a vignette */
.scan-texture {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse at center, transparent 50%, rgba(0, 0, 0, .6) 100%),
    repeating-linear-gradient(0deg, rgba(0, 0, 0, .2) 0 1px, transparent 1px 3px),
    radial-gradient(rgba(0, 0, 0, .32) .8px, transparent 1.3px) 0 0 / 4px 4px;
}

/* big centred state while there is nothing to look at yet */
.scan-wait {
  position: absolute;
  inset: 0;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: .16em;
  text-align: center;
  color: var(--hud);
  pointer-events: none;
}
.scan-wait::after {
  content: '_';
  animation: scan-blink 1s steps(1) infinite;
}

.scan-hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.scan-readout {
  position: absolute;
  top: 16px;
  left: 16px;
  font-size: 11px;
  line-height: 16px;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .7);
}
.scan-r { white-space: nowrap; }
.scan-k {
  display: inline-block;
  min-width: 12ch;
  color: var(--hud-dim);
}
.scan-active {
  margin-top: 4px;
  font-weight: 700;
  letter-spacing: .08em;
}
.scan-active i {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 8px;
  border-radius: 50%;
  background: var(--hud-red);
  vertical-align: 0;
  animation: scan-blink 1.2s steps(1) infinite;
}
.scan-state {
  margin: 4px 0 0;
  max-width: 32ch;
  font-weight: 700;
  color: var(--hud-yellow);
  letter-spacing: .04em;
}

.scan-stop {
  position: absolute;
  top: 16px;
  right: 16px;
  pointer-events: auto;
  padding: 8px 16px;
  font: 700 12px/16px var(--font-mono);
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--hud);
  background: rgba(10, 11, 13, .64);
  border: 1px solid var(--hud);
  border-radius: 0;
  cursor: pointer;
  transition: transform .3s ease;
}
.scan-stop:hover:not(:disabled) { transform: scale(1.02); }
.scan-stop:disabled { opacity: .4; cursor: default; }

/* ---------- dossier: blue terminal panel (ref 162) ---------- */
.dossier {
  position: absolute;
  top: 64px;
  right: 24px;
  width: min(384px, 36vw);
  max-height: calc(100% - 96px);
  display: flex;
  flex-direction: column;
  font-size: 11px;
  line-height: 16px;
  color: #dfe5ff;
  background: rgba(6, 10, 34, .86);
  border: 1px solid var(--hud-blue);
}

.d-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  background: var(--hud-blue);
  color: #fff;
  font-weight: 700;
  letter-spacing: .04em;
}
.d-bar-t { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.d-sq { display: flex; gap: 4px; }
.d-sq i { width: 8px; height: 8px; border: 1px solid #fff; }
.d-toggle { display: none; }

.d-cmd { padding: 8px 12px 4px; color: rgba(223, 229, 255, .62); }
.d-ok { color: #fff; }

.d-status {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin: 4px 12px 0;
  padding: 4px 8px;
  background: var(--hud-blue);
  color: #fff;
  font-weight: 700;
}
.d-status-t { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.d-count { flex: none; font-weight: 500; }

.d-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 4px 12px 12px;
}
.d-h {
  margin: 12px 0 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .16em;
  color: rgba(223, 229, 255, .62);
}
.d-h::before { content: '// '; color: var(--hud-blue); }
.d-list { list-style: none; margin: 0; padding: 0; }

.d-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  column-gap: 8px;
  padding: 4px 0;
  border-bottom: 1px dashed rgba(47, 84, 255, .4);
  transition: opacity .3s ease;
}
.d-tag { font-weight: 700; color: #fff; white-space: nowrap; }
.d-line { flex: 1 1 16ch; min-width: 0; color: rgba(223, 229, 255, .72); }
.d-val { color: var(--hud-yellow); white-space: nowrap; }
.d-row.is-typing .d-line::after,
.d-row.is-typing .d-tag:empty::after { content: '_'; color: var(--hud-yellow); }
.d-row.is-stale { opacity: .45; }

.d-ad {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 8px;
  margin-top: 8px;
  padding: 8px;
  border: 1px solid rgba(255, 214, 10, .5);
  background: rgba(255, 214, 10, .06);
  animation: d-in .3s var(--ease-out) both;
}
.d-ad-chip {
  align-self: start;
  padding: 0 4px;
  background: var(--hud-yellow);
  color: #000;
  font-weight: 700;
}
.d-ad-text { color: #fff; }
.d-ad-why { grid-column: 2; color: #c3ccff; } /* boss 6 Dec: "not visible" at 56% on the navy panel; solid tint, about 11:1 */

.d-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  border-top: 1px solid rgba(47, 84, 255, .5);
}
.d-note { margin: 0; color: #fff; }
.d-share {
  flex: none;
  padding: 4px 8px;
  font: 500 11px/16px var(--font-mono);
  color: rgba(223, 229, 255, .62);
  background: transparent;
  border: 1px dashed rgba(223, 229, 255, .4);
  cursor: not-allowed;
}

@keyframes d-in { from { opacity: 0; transform: translateY(4px); } }
@keyframes scan-blink { 50% { opacity: 0; } }

/* ---------- phones: the feed fills the screen, the dossier is a bottom sheet ---------- */
@media (max-width: 767px) {
  .scan-readout { top: 12px; left: 12px; font-size: 10px; line-height: 14px; }
  .scan-k { min-width: 11ch; }
  .scan-stop { top: 12px; right: 12px; min-height: 44px; }
  .dossier {
    top: auto;
    right: 0;
    bottom: 0;
    left: 0;
    width: auto;
    max-height: 36%;
    border-width: 1px 0 0;
    padding-bottom: env(safe-area-inset-bottom);
    transition: max-height .3s var(--ease-out);
  }
  .dossier.is-open { max-height: 78%; }
  .d-toggle {
    display: block;
    flex: none;
    padding: 0 8px;
    font: 700 11px/24px var(--font-mono);
    color: #fff;
    background: transparent;
    border: 1px solid rgba(255, 255, 255, .6);
    cursor: pointer;
  }
  .d-sq { display: none; }
  .d-cmd { display: none; }
  .d-foot { padding: 8px 12px; }
  .d-note { font-size: 10px; }
}

@media (pointer: coarse) {
  .d-toggle { min-height: 32px; }
}

/* reduced motion: no blinking, no slide-ins (the canvas drops its sweep and typing in JS) */
@media (prefers-reduced-motion: reduce) {
  .scan-wait::after,
  .scan-active i { animation: none; }
  .d-ad { animation: none; }
  .dossier { transition: none; }
  .scan-stop { transition: none; }
}
