/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Variables ── */
:root {
  --primary:      #0077ff;
  --primary-dark: #0055cc;
  --bg:           #0d1b2a;
  --surface:      #16213e;
  --surface2:     #1a2a4a;
  --text:         #e8f4fd;
  --text-muted:   #8ba7c7;
  --success:      #06d6a0;
  --radius:       12px;
  --shadow:       0 4px 24px rgba(0, 0, 0, 0.4);
}

/* ── Base ── */
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.app {
  width: 100%;
  max-width: 480px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 0 16px 40px;
}

/* ── Header ── */
header {
  text-align: center;
  padding: 36px 0 24px;
}

header h1 {
  font-size: 1.9rem;
  font-weight: 800;
  letter-spacing: -0.5px;
}

.subtitle {
  color: var(--text-muted);
  margin-top: 6px;
  font-size: 0.95rem;
}

/* ── Sections ── */
.section {
  display: none;
  flex-direction: column;
  gap: 20px;
  animation: fadeIn 0.3s ease;
}

.section.active { display: flex; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Caméra ── */
.video-container {
  width: 100%;
  aspect-ratio: 4 / 3;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

#video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* ── Prévisualisation ── */
.preview-container {
  width: 100%;
  aspect-ratio: 4 / 3;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

#preview {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* ── Boutons ── */
.controls {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.btn {
  padding: 14px 24px;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  flex: 1;
  max-width: 220px;
}

.btn:active { transform: scale(0.97); }

.btn-primary              { background: var(--primary); color: white; }
.btn-primary:hover        { background: var(--primary-dark); }

.btn-secondary            { background: var(--surface2); color: var(--text); flex: 0; padding: 14px 16px; }
.btn-secondary:hover      { background: #233a5c; }

.btn-outline {
  display: inline-block;
  background: transparent;
  border: 2px solid var(--text-muted);
  color: var(--text-muted);
  text-align: center;
  font-size: 0.9rem;
  padding: 10px 20px;
  border-radius: var(--radius);
  cursor: pointer;
  width: 100%;
  transition: all 0.2s;
}

.btn-outline:hover { border-color: var(--primary); color: var(--primary); }

.fallback-upload { text-align: center; margin-top: 4px; }

/* ── Succès ── */
.success-card {
  background: rgba(22, 33, 62, 0.45);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: var(--radius);
  padding: 44px 24px;
  text-align: center;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.success-icon { font-size: 4rem; }

.success-card h2 { font-size: 1.5rem; color: var(--success); }
.success-card p  { color: var(--text-muted); }

/* ── Signature ── */
.signature {
  text-align: center;
  margin-top: 32px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.signature strong {
  display: block;
  color: var(--primary);
  font-size: 1.15rem;
  margin-top: 4px;
  letter-spacing: 0.5px;
}

/* ── Utilitaires ── */
.hidden { display: none !important; }

/* ── Zone tap-to-open (fallback caméra) ── */
.tap-to-open {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: var(--surface);
  cursor: pointer;
  user-select: none;
  animation: pulse 2s ease-in-out infinite;
}

.tap-icon {
  font-size: 4rem;
  animation: bounce 1.5s ease-in-out infinite;
}

.tap-to-open p {
  color: var(--text);
  font-size: 1.1rem;
  font-weight: 600;
  text-align: center;
  line-height: 1.5;
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(-8px); }
}

@keyframes pulse {
  0%, 100% { background: var(--surface); }
  50%       { background: var(--surface2); }
}

/* ── Loader ── */
.loader {
  position: fixed;
  inset: 0;
  background: rgba(13, 27, 42, 0.88);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  backdrop-filter: blur(4px);
  z-index: 100;
}

.loader.hidden { display: none; }

.spinner {
  width: 52px;
  height: 52px;
  border: 4px solid var(--surface2);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Section choix source ── */
.choice-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding: 32px 16px;
  background: rgba(22, 33, 62, 0.45);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid rgba(255,255,255,0.06);
}

.choice-icon {
  font-size: 5rem;
  line-height: 1;
}

.choice-container h2 {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text);
  text-align: center;
}

.choice-btn {
  width: 100%;
  max-width: 300px;
  padding: 16px 24px;
  font-size: 1.05rem;
}

/* \u2500\u2500 Champ auteur \u2500\u2500 */
.author-field {
  width: 100%;
  max-width: 300px;
}

.author-field input {
  width: 100%;
  padding: 12px 16px;
  background: var(--surface2);
  border: 1px solid rgba(139, 167, 199, 0.3);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s;
}

.author-field input::placeholder { color: var(--text-muted); }
.author-field input:focus { border-color: var(--primary); }

/* ── Bouton choisir fond (écran accueil) ── */
.btn-pick-bg {
  background: transparent;
  border: 1px dashed rgba(139, 167, 199, 0.4);
  color: var(--text-muted);
  padding: 8px 18px;
  border-radius: 20px;
  font-size: 0.82rem;
  cursor: pointer;
  transition: all 0.2s;
  margin-top: 4px;
}
.btn-pick-bg:hover { border-color: var(--primary); color: var(--primary); }

/* ── Bouton supprimer fond (header) ── */
.btn-remove-bg {
  display: inline-block;
  margin-top: 10px;
  padding: 6px 14px;
  background: rgba(255, 80, 80, 0.2);
  border: 1px solid rgba(255, 80, 80, 0.5);
  border-radius: 20px;
  color: #ff8080;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-remove-bg:hover { background: rgba(255, 80, 80, 0.4); }

/* ── Galerie multi-sélection ── */
.gallery-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 4px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.btn-add-more {
  background: transparent;
  border: 1px solid var(--primary);
  color: var(--primary);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-add-more:hover { background: var(--primary); color: white; }

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  max-height: 60vh;
  overflow-y: auto;
  padding: 4px 2px;
}

.gallery-controls-top {
  margin-bottom: 10px;
}

.gallery-card {
  position: relative;
  aspect-ratio: 1;
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface);
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.gallery-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.2s;
}

.gallery-card:hover img { transform: scale(1.04); }

.gallery-card-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: rgba(220, 50, 50, 0.85);
  border: none;
  color: white;
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  z-index: 2;
}
.gallery-card-remove:hover { background: rgba(220, 50, 50, 1); }

.gallery-card-bg {
  position: absolute;
  bottom: 4px;
  right: 4px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.6);
  border: none;
  font-size: 0.8rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  z-index: 2;
}
.gallery-card-bg:hover { background: rgba(0, 119, 255, 0.8); }

/* ── Fond d'écran appliqué sur .app ── */
.app[style*="background-image"] {
  position: relative;
}
.app[style*="background-image"]::before {
  content: '';
  position: fixed;
  inset: 0;
  background: rgba(13, 27, 42, 0.72);
  backdrop-filter: blur(2px);
  z-index: 0;
  pointer-events: none;
}
.app[style*="background-image"] > * {
  position: relative;
  z-index: 1;
}

/* ── Toast de notification ── */
.bg-toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(6, 214, 160, 0.92);
  color: #0d1b2a;
  padding: 10px 22px;
  border-radius: 24px;
  font-size: 0.95rem;
  font-weight: 600;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
  z-index: 200;
  animation: fadeIn 0.3s ease;
  white-space: nowrap;
}

/* ── Barre de progression upload ── */
.progress-bar-wrap {
  width: 100%;
  max-width: 280px;
  height: 8px;
  background: rgba(255,255,255,0.18);
  border-radius: 4px;
  overflow: hidden;
  margin: 10px auto 4px;
}
.progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #06d6a0, #118ab2);
  border-radius: 4px;
  transition: width 0.2s ease;
}
.progress-label {
  font-size: 0.8rem;
  color: rgba(255,255,255,0.7);
  margin: 0;
  text-align: center;
  letter-spacing: 0.02em;
}

/* ── Badge miniatures non affichées ── */
.gallery-more {
  text-align: center;
  font-size: 0.82rem;
  color: rgba(255,255,255,0.55);
  padding: 6px 0 2px;
  font-style: italic;
}
