/* ===== Écran de chargement initial ===== */
#ar-loader {
  position: fixed;
  inset: 0;
  z-index: 5000;
  background: radial-gradient(circle at 50% 35%, #0f304d 0%, #050d17 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
  text-align: center;
  transition: opacity 0.35s ease;
}

#ar-loader.fade-out {
  opacity: 0;
  pointer-events: none;
}

.loader-spinner {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 3px solid rgba(0, 229, 255, 0.2);
  border-top-color: var(--cyan);
  border-right-color: var(--emerald);
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.loader-title {
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--cyan);
}

.loader-subtitle {
  font-size: 0.88rem;
  color: var(--text-muted);
  max-width: 320px;
  line-height: 1.45;
}

/* ===== Barre supérieure ===== */
#top-bar {
  position: fixed;
  top: 12px;
  left: 12px;
  right: 12px;
  z-index: 1200;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  pointer-events: none;
}

.brand-chip {
  pointer-events: auto;
  background: var(--surface);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 7px 14px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--cyan);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
}

.share-chip {
  cursor: pointer;
  font-family: inherit;
  text-transform: none;
  letter-spacing: 0.2px;
  font-size: 0.82rem;
  color: #eaf9ff;
  border-color: rgba(0, 229, 255, 0.48);
  transition: transform 0.16s ease, border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.share-chip:hover {
  border-color: var(--emerald);
  background: rgba(10, 32, 52, 0.94);
  box-shadow: 0 6px 20px rgba(0, 229, 255, 0.28);
  transform: translateY(-1px);
}

.share-chip:active {
  transform: scale(0.96);
}

.share-chip-icon {
  width: 15px;
  height: 15px;
  fill: var(--emerald);
  flex-shrink: 0;
}

.brand-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--emerald);
  box-shadow: 0 0 10px var(--emerald);
}

.top-actions {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.chip-btn {
  background: var(--surface);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.22);
  color: var(--text);
  border-radius: 999px;
  padding: 7px 13px;
  font-size: 0.76rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: border-color 0.2s ease, transform 0.15s ease;
}

.chip-btn:hover {
  border-color: var(--cyan);
}

.chip-btn:active {
  transform: scale(0.96);
}

.chip-btn.accent {
  border-color: var(--emerald);
  color: var(--emerald);
  background: rgba(0, 230, 118, 0.14);
}

/* ===== Viseur de scan AR (Phase 1) ===== */
#scan-overlay {
  position: fixed;
  inset: 0;
  z-index: 800;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  transition: opacity 0.35s ease;
}

#scan-overlay.hidden-fade {
  opacity: 0;
  pointer-events: none;
}

.scan-reticle {
  position: relative;
  width: min(64vw, 235px);
  height: min(64vw, 235px);
  border-radius: 50%;
  border: 2px dashed rgba(0, 229, 255, 0.65);
  box-shadow: 0 0 35px rgba(0, 229, 255, 0.2), inset 0 0 30px rgba(0, 229, 255, 0.12);
  overflow: hidden;
}

.scan-beam {
  position: absolute;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, transparent, var(--emerald), var(--cyan), transparent);
  box-shadow: 0 0 14px var(--cyan);
  animation: beamSweep 2.1s ease-in-out infinite;
}

@keyframes beamSweep {
  0% {
    top: 8%;
  }
  50% {
    top: 90%;
  }
  100% {
    top: 8%;
  }
}

.scan-hint-pill {
  background: var(--surface);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 10px 18px;
  font-size: 0.84rem;
  font-weight: 700;
  line-height: 1.4;
  color: var(--text);
  text-align: center;
  max-width: 90vw;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.camera-fallback-actions {
  pointer-events: auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 2px;
}

/* ===== Effet de numérisation laser (Phase 2) ===== */
#digitize-fx {
  position: fixed;
  inset: 0;
  z-index: 1100;
  pointer-events: none;
  display: none;
  background: rgba(0, 229, 255, 0.08);
}

#digitize-fx.active {
  display: block;
  animation: fxFade 1.15s ease forwards;
}

.digitize-grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(0, 229, 255, 0.14) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 229, 255, 0.14) 1px, transparent 1px);
  background-size: 28px 28px;
}

.digitize-laser {
  position: absolute;
  left: 0;
  right: 0;
  height: 5px;
  background: linear-gradient(90deg, transparent, var(--emerald), #ffffff, var(--cyan), transparent);
  box-shadow: 0 0 28px 6px rgba(0, 229, 255, 0.85);
  animation: digitizeSweep 0.95s cubic-bezier(0.25, 0.8, 0.25, 1) forwards;
}

.digitize-badge {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(5, 18, 31, 0.92);
  border: 1px solid var(--emerald);
  color: var(--emerald);
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 0.9rem;
  font-weight: 800;
  letter-spacing: 2px;
  padding: 10px 22px;
  border-radius: 999px;
  box-shadow: 0 0 30px rgba(0, 230, 118, 0.45);
}

@keyframes digitizeSweep {
  0% {
    top: 0%;
  }
  100% {
    top: 100%;
  }
}

@keyframes fxFade {
  0% {
    opacity: 0;
  }
  15% {
    opacity: 1;
  }
  80% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

/* ===== Scène AR stabilisée (Phase 3 : CV reproduit fixe + Personnage 3D par-dessus) ===== */
#stabilized-stage {
  position: fixed;
  inset: 0;
  z-index: 900;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 62px 14px 128px;
  background: radial-gradient(circle at 50% 42%, rgba(13, 39, 63, 0.78) 0%, rgba(4, 12, 22, 0.88) 100%);
  opacity: 0;
  pointer-events: none;
  transform: scale(0.95);
  transition: opacity 0.45s ease, transform 0.45s cubic-bezier(0.22, 1, 0.36, 1);
}

#stabilized-stage.visible {
  opacity: 1;
  pointer-events: auto;
  transform: scale(1);
}

.cv-frame-wrapper {
  position: relative;
  width: min(92vw, 430px);
  height: min(64vh, 610px);
  display: flex;
  align-items: center;
  justify-content: center;
}

.cv-reproduction {
  position: relative;
  height: 100%;
  max-width: 100%;
  aspect-ratio: 210 / 297;
  border-radius: 12px;
  overflow: hidden;
  border: 1.5px solid rgba(0, 229, 255, 0.55);
  box-shadow:
    0 22px 55px rgba(0, 0, 0, 0.65),
    0 0 32px rgba(0, 229, 255, 0.22);
  background: #ffffff;
  cursor: pointer;
  transition: opacity 0.35s ease, transform 0.35s ease;
}

body.ar-camera-passthrough #stabilized-stage {
  background: transparent;
  pointer-events: none;
  justify-content: flex-end;
}

body.ar-camera-passthrough .cv-frame-wrapper {
  display: none;
}

body.ar-camera-passthrough .cv-reproduction {
  opacity: 0;
  transform: scale(0.95);
  pointer-events: none;
}

body.ar-camera-passthrough #audio-bar {
  pointer-events: auto;
}

.ar-marker-hint {
  margin-bottom: 10px;
  background: rgba(6, 20, 36, 0.86);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(0, 229, 255, 0.5);
  border-radius: 999px;
  padding: 7px 16px;
  font-size: 0.78rem;
  font-weight: 700;
  color: #eaf9ff;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.45);
  pointer-events: none;
  z-index: 10;
}

.cv-reproduction img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

/* Canvas Three.js du personnage 3D superposé de manière stable au-dessus du CV */
#character-canvas {
  position: absolute;
  inset: -8% 0 -4% 0;
  width: 100%;
  height: 112%;
  pointer-events: auto;
  touch-action: pan-y;
  cursor: grab;
  z-index: 4;
}

#character-canvas.is-dragging {
  cursor: grabbing;
}

/* Contrôleur audio MP3 flottant sous le CV */
#audio-bar {
  margin-top: 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 14px 6px 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  z-index: 10;
}

.audio-toggle-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, var(--emerald), var(--cyan));
  color: #041826;
  font-size: 0.9rem;
  font-weight: 900;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.audio-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.audio-label {
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--text);
}

.audio-progress-track {
  width: 145px;
  height: 4px;
  background: rgba(255, 255, 255, 0.16);
  border-radius: 999px;
  overflow: hidden;
}

.audio-progress-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--emerald), var(--cyan));
  transition: width 0.2s linear;
}

.audio-time {
  font-size: 0.7rem;
  font-family: 'Consolas', monospace;
  color: var(--text-muted);
}

.audio-replay-btn {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: var(--text);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.7rem;
  font-weight: 700;
  cursor: pointer;
}

@media (max-width: 480px) {
  #stabilized-stage {
    padding: 58px 10px 136px;
  }

  .cv-frame-wrapper {
    height: min(58vh, 520px);
  }
}
