.scan-body { background: #000; }

.scan {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

/* Live-camera video sits behind the alignment overlay + controls. */
.scan video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 0;
}

.scan__overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding:
    max(env(safe-area-inset-top, 0), 1rem)
    1.25rem
    max(env(safe-area-inset-bottom, 0), 9rem)
    1.25rem;
  z-index: 5;
}

.scan__frame {
  position: relative;
  /* Inset the frame so corners stay well clear of the camera viewport's edge
     — previous sizing (85vmin/520px) clipped the bottom corners off-screen on
     iPhones where the safe-area inset eats into the bottom. */
  width: min(72vmin, 460px);
  max-width: 78vw;
  aspect-ratio: 2 / 3;
}

.corner {
  position: absolute;
  width: 36px;
  height: 36px;
  border: 5px solid var(--color-foam);
  border-radius: 6px;
}

/* Push each corner ~16px inward from the .scan__frame's edges so they all
   sit comfortably inside the camera viewport even after the safe-area inset
   nibbles at the visible region. */
.corner--tl { top: 16px;    left: 16px;  border-right: none; border-bottom: none; }
.corner--tr { top: 16px;    right: 16px; border-left: none;  border-bottom: none; }
.corner--bl { bottom: 16px; left: 16px;  border-right: none; border-top: none; }
.corner--br { bottom: 16px; right: 16px; border-left: none;  border-top: none; }

.scan__hint {
  margin-top: 1.5rem;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  padding: 0.625rem 1.125rem;
  border-radius: 999px;
  font-size: clamp(0.85rem, 3.6vw, 1rem);
  text-align: center;
  max-width: min(85vw, 480px);
  transition: background 0.2s ease, transform 0.2s ease;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.scan__hint--ready {
  background: rgba(0, 184, 148, 0.92);
  font-weight: 700;
  transform: scale(1.02);
}

.scan__controls {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 8rem;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding:
    0
    max(env(safe-area-inset-right, 0), 1.5rem)
    max(env(safe-area-inset-bottom, 0), 1.5rem)
    max(env(safe-area-inset-left, 0), 1.5rem);
  background: linear-gradient(180deg, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0.6) 100%);
  z-index: 10;
}

.scan__back {
  justify-self: start;
  width: 52px;
  height: 52px;
  background: rgba(255, 255, 255, 0.18);
  border-radius: 50%;
  color: #fff;
  font-size: 1.4rem;
  display: grid;
  place-items: center;
  touch-action: manipulation;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.scan__capture-btn {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: #fff;
  border: 5px solid rgba(255, 255, 255, 0.45);
  background-clip: padding-box;
  transition: transform 0.1s ease;
  touch-action: manipulation;
}

.scan__capture-btn:active { transform: scale(0.92); }

/* Pulse when MindAR has locked onto any target. */
.scan__capture-btn--ready {
  animation: pulse-capture 1.4s ease-in-out infinite;
  box-shadow: 0 0 0 0 rgba(0, 184, 148, 0.6);
}

@keyframes pulse-capture {
  0%, 100% { transform: scale(1);    box-shadow: 0 0 0 0 rgba(0, 184, 148, 0.6); }
  50%      { transform: scale(1.05); box-shadow: 0 0 0 18px rgba(0, 184, 148, 0); }
}

.scan__upload {
  justify-self: end;
  width: 52px;
  height: 52px;
  background: rgba(255, 255, 255, 0.18);
  border-radius: 50%;
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  font-size: 1.25rem;
  touch-action: manipulation;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.scan__error {
  position: absolute;
  inset: auto 1rem max(env(safe-area-inset-bottom, 0), 9.5rem) 1rem;
  padding: 1rem 1.25rem;
  background: rgba(255, 75, 75, 0.92);
  color: #fff;
  border-radius: 14px;
  font-size: 0.9rem;
  text-align: center;
  z-index: 20;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

/* Tablet & up: enlarge the guide frame. */
@media (min-width: 600px) and (orientation: portrait) {
  .scan__frame { width: min(70vmin, 600px); }
  .scan__capture-btn { width: 96px; height: 96px; }
}
