/* ─── Reset ─────────────────────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* ─── Root layout ────────────────────────────────────────────────────────── */
html, body {
  height: 100%;
  overflow: hidden;
  background: #ffffff;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  color: #111111;
}

body {
  display: flex;
  flex-direction: column;
}

/* ─── Sezione camera (top 50%) ───────────────────────────────────────────── */
#camera-section {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: #e0e0e0;
}

#video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transform: scaleX(-1); /* specchio orizzontale */
}

/* ─── Overlay di puntamento ──────────────────────────────────────────────── */
#scan-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

#scan-frame {
  width: min(58vw, 52vh);
  aspect-ratio: 1;
  border: 3px solid #e53935;
  border-radius: 14px;
  position: relative;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 10px;
  transition: border-color 0.25s ease, box-shadow 0.25s ease;
  /* scurisce tutto l'esterno del riquadro */
  box-shadow:
    0 0 0 100vmax rgba(255, 255, 255, 0.55),
    0 0 0 3px rgba(229, 57, 53, 0.5);
}

#scan-frame.scan-success {
  border-color: #00c853;
  box-shadow:
    0 0 0 100vmax rgba(255, 255, 255, 0.55),
    0 0 0 4px rgba(0, 200, 83, 0.5),
    0 0 40px rgba(0, 200, 83, 0.2);
}

/* Angoli decorativi */
.corner {
  position: absolute;
  width: 28px;
  height: 28px;
  border-color: #e53935;
  border-style: solid;
  opacity: 1;
}
.corner.tl { top: -3px;    left: -3px;   border-width: 4px 0 0 4px; border-radius: 10px 0 0 0; }
.corner.tr { top: -3px;    right: -3px;  border-width: 4px 4px 0 0; border-radius: 0 10px 0 0; }
.corner.bl { bottom: -3px; left: -3px;   border-width: 0 0 4px 4px; border-radius: 0 0 0 10px; }
.corner.br { bottom: -3px; right: -3px;  border-width: 0 4px 4px 0; border-radius: 0 0 10px 0; }

#frame-label {
  font-size: clamp(0.7rem, 2vw, 0.9rem);
  color: rgba(0, 0, 0, 0.55);
  text-align: center;
  letter-spacing: 0.04em;
  pointer-events: none;
}

/* ─── Sezione info (bottom 50%) ──────────────────────────────────────────── */
#info-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px 24px 0;
  gap: 18px;
  background: #ffffff;
  position: relative;        /* contesto per la freccia assoluta */
}

/* ─── Freccia rimbalzante — ancorata al bordo inferiore ──────────────────── */
#arrow-area {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-bottom: 6px;
  gap: 2px;
  pointer-events: none;
}

#bounce-arrow {
  font-size: clamp(4rem, 14vw, 8rem);
  display: inline-block;
  line-height: 1;
  animation: bounce 1.4s ease-in-out infinite;
  color: #e53935;
}

@keyframes bounce {
  0%, 100% { transform: translateY(0);     opacity: 1; }
  50%       { transform: translateY(14px); opacity: 0.6; }
}

#arrow-label {
  font-size: clamp(1.4rem, 5vw, 2.4rem);
  font-weight: 700;
  color: #111111;
  text-align: center;
  line-height: 1.2;
}

/* ─── Messaggio idle ─────────────────────────────────────────────────────── */
#idle-message {
  text-align: center;
  /* lascia spazio per la freccia in fondo */
  margin-bottom: clamp(5rem, 14vw, 9rem);
}

#idle-text {
  font-size: clamp(0.9rem, 3vw, 1.1rem);
  color: #9ca3af;
}

.hidden {
  display: none !important;
}

/* ─── Contenitore risultato ──────────────────────────────────────────────── */
#result-container {
  width: 100%;
  max-width: 580px;
  background: #f3f4f6;
  border: 1px solid #d1d5db;
  border-radius: 18px;
  padding: 18px 24px;
  text-align: center;
  animation: slide-in 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) both;
  /* lascia spazio per la freccia in fondo */
  margin-bottom: clamp(5rem, 14vw, 9rem);
}

@keyframes slide-in {
  from { opacity: 0; transform: translateY(24px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0)    scale(1); }
}

#result-container.success-flash {
  animation: flash 0.5s ease forwards;
}

@keyframes flash {
  0%   { background: #dcfce7; border-color: #00c853; }
  100% { background: #f3f4f6; border-color: #d1d5db; }
}

#result-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: #9ca3af;
  margin-bottom: 10px;
}

#result-text {
  font-size: clamp(1.1rem, 4.5vw, 1.8rem);
  font-weight: 700;
  color: #059669;
  word-break: break-all;
  line-height: 1.3;
}

/* ─── Canvas off-screen ──────────────────────────────────────────────────── */
#canvas {
  position: fixed;
  top: -9999px;
  left: -9999px;
  pointer-events: none;
}
