/* --- MODE SMARTPHONE / MOBILE --- */
@media (max-width: 768px) {
  :root {
    --text-xs: 0.75rem;
    --text-sm: 0.85rem;
    --text-base: 0.95rem;
    --text-lg: 1.05rem;
    --text-xl: 1.4rem;
    --text-2xl: 1.8rem;
    --text-3xl: 2.2rem;

    --space-1: 0.25rem;
    --space-2: 0.4rem;
    --space-3: 0.6rem;
    --space-4: 0.8rem;
    --space-5: 1rem;
    --space-6: 1.25rem;
    --space-8: 1.75rem;
    --space-10: 2.1rem;
    --space-12: 2.5rem;
    --space-16: 3rem;
  }

  body {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .screen {
    position: relative;
    inset: auto;
    min-height: 100dvh;
    padding: var(--space-4);
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
  }

  /* --- ACCUEIL --- */
  .screen-welcome {
    padding-top: calc(var(--space-8) + env(safe-area-inset-top, 0px));
    padding-bottom: calc(var(--space-8) + env(safe-area-inset-bottom, 0px));
  }

  .welcome-card {
    max-width: 100%;
    width: 100%;
    padding: var(--space-6);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-md);
  }

  .wedding-title {
    font-size: var(--text-2xl);
  }

  .subtitle {
    font-size: var(--text-base);
    margin-top: var(--space-3);
  }

  .welcome-desc {
    font-size: var(--text-sm);
    margin-top: var(--space-4);
    line-height: 1.5;
  }

  .btn-start {
    width: 100%;
    margin-top: var(--space-6);
    min-height: 64px;
    font-size: var(--text-lg);
    padding-inline: var(--space-4);
  }

  .btn-back.btn-back-large {
    width: 100%;
    justify-content: center;
    margin-top: var(--space-4);
  }

  #connectBtn {
    margin-top: var(--space-4);
    width: 100%;
  }

  /* --- CHOIX DU MODE --- */
  .screen-mode {
    padding-top: calc(var(--space-6) + env(safe-area-inset-top, 0px));
  }

  .mode-title {
    font-size: var(--text-xl);
    margin-bottom: var(--space-4);
  }

  .mode-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--space-3);
  }

  .mode-card {
    padding: var(--space-5);
    min-height: 0;
  }

  .mode-icon {
    font-size: 2.4rem;
  }

  .mode-label {
    font-size: var(--text-lg);
  }

  .mode-desc {
    font-size: var(--text-sm);
  }

  .screen-mode .btn-back {
    margin-top: var(--space-4);
    width: 100%;
    justify-content: center;
  }

  /* --- CAMERA --- */
  .screen-camera {
    padding: 0;
    background: #000;
  }

  .camera-wrapper {
    width: 100%;
    height: 100dvh;
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }

  #video-preview {
    width: 100%;
    height: auto;
    flex: 1 1 auto;
    object-fit: cover;
  }

  .camera-header {
    position: absolute;
    top: env(safe-area-inset-top, 0px);
    left: 0;
    right: 0;
    padding: var(--space-3) var(--space-4);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
  }

  .camera-header .btn-back {
    padding-inline: var(--space-3);
    min-height: 40px;
    font-size: var(--text-sm);
  }

  .camera-header .mode-badge {
    font-size: var(--text-xs);
    padding: var(--space-1) var(--space-2);
    white-space: nowrap;
  }

  .viewfinder-frame {
    width: 85vw;
    height: auto;
    aspect-ratio: 3 / 4;
  }

  .camera-controls {
    position: absolute;
    left: 0;
    right: 0;
    bottom: calc(env(safe-area-inset-bottom, 0px));
    padding: var(--space-4);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-3);
    background: linear-gradient(to top, rgba(0,0,0,0.9), transparent);
  }

  .strip-preview {
    order: 1;
    width: 100%;
    justify-content: center;
    gap: var(--space-2);
  }

  .strip-thumb {
    width: 48px;
    height: 48px;
  }

  .btn-shutter {
    order: 2;
    width: 88px;
    height: 88px;
  }

  .filters-row {
    order: 3;
    width: 100%;
    padding-inline: var(--space-3);
    bottom: auto;
    position: static;
    justify-content: flex-start;
    overflow-x: auto;
  }

  .filter-btn {
    min-width: 64px;
  }

  .filter-preview {
    width: 44px;
    height: 32px;
  }

  /* --- RESULTAT / STRIP --- */
  .screen-result {
    padding: var(--space-4);
    padding-top: calc(var(--space-6) + env(safe-area-inset-top, 0px));
    padding-bottom: calc(var(--space-6) + env(safe-area-inset-bottom, 0px));
    justify-content: flex-start;
    align-items: stretch;
    overflow-y: auto;
  }

  .result-title {
    font-size: var(--text-xl);
    margin-bottom: var(--space-4);
  }

  .result-shell {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    width: 100%;
  }

  .strip-container {
    max-width: 100%;
    margin: 0 auto;
  }

  .result-side {
    width: 100%;
    align-items: center;
  }

  .qr-wrap {
    width: 100%;
    align-items: center;
  }

  .qr-box {
    min-width: 220px;
    min-height: 220px;
  }

  .result-actions {
    flex-direction: column;
    width: 100%;
  }

  .btn-action {
    width: 100%;
    justify-content: center;
  }

  /* --- GALERIE --- */
  .screen-gallery {
    padding: var(--space-4);
    padding-top: calc(var(--space-6) + env(safe-area-inset-top, 0px));
    padding-bottom: calc(var(--space-6) + env(safe-area-inset-bottom, 0px));
  }

  .gallery-header {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-3);
  }

  .gallery-title {
    font-size: var(--text-xl);
  }

  .gallery-grid {
    grid-template-columns: 1fr;
    gap: var(--space-3);
  }

  .gallery-item {
    aspect-ratio: 3 / 4;
  }

  .btn-back {
    min-height: 44px;
    font-size: var(--text-sm);
  }

  /* --- TOAST & CONFETTI --- */
  .toast {
    bottom: calc(var(--space-6) + env(safe-area-inset-bottom, 0px));
    font-size: var(--text-sm);
  }
}

html, body {
  height: 100%;
  max-height: 100dvh;
  overflow: hidden;
}

.screen {
  position: fixed;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 12px;
  overflow: hidden;
  box-sizing: border-box;
}

.screen.active { display: flex; }

.welcome-card {
  padding: 18px 20px;
  width: 100%;
  max-width: 98vw;
  box-sizing: border-box;
}

.wedding-title { font-size: clamp(1.4rem, 6vw, 2rem); margin-bottom: 8px; }
.welcome-desc { font-size: clamp(0.8rem, 3.5vw, 1rem); margin-bottom: 12px; }
.btn-start { width: 100%; padding: 14px 20px; font-size: clamp(1rem, 4vw, 1.3rem); }

.camera-wrapper { position: fixed; inset: 0; width: 100dvw; height: 100dvh; }
#video-preview { width: 100%; height: 100%; object-fit: cover; }

.result-shell {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 100%;
  max-height: 100dvh;
  overflow: hidden;
}

.strip-container { max-width: 98vw; max-height: 50dvh; overflow: hidden; }
.final-preview { max-height: 48dvh !important; width: auto !important; max-width: 98vw; }
.result-side { width: 100%; align-items: center; }

.qr-box canvas, .qr-box img { width: 140px !important; height: 140px !important; }

.result-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; padding: 8px 0; }
.btn-action { padding: 10px 16px; font-size: 0.85rem; }

.result-side .qr-help,
#qr-url,
.sticker-row,
.gallery-header,
[onclick="goTo('screen-gallery')"],
#connectBtn { display: none !important; }

/* ── ÉCRAN CAMÉRA : plein écran sans scroll ── */
#screen-camera {
  padding: 0;
  overflow: hidden;
}

.camera-wrapper {
  position: fixed;
  inset: 0;
  width: 100dvw;
  height: 100dvh;
  overflow: hidden;
}

#video-preview {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.camera-header {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(to bottom, rgba(0,0,0,0.55), transparent);
}

.filters-row {
  position: absolute;
  bottom: 110px;
  left: 0;
  right: 0;
  z-index: 10;
  overflow-x: auto;
  overflow-y: hidden;
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  padding: 6px 12px;
  scrollbar-width: none;
}

.filters-row::-webkit-scrollbar {
  display: none;
}

.camera-controls {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 10;
  padding: 12px 16px 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(to top, rgba(0,0,0,0.55), transparent);
}

.strip-preview {
  display: none; /* inutile en mode 1 photo sur smartphone */
}

.btn-shutter {
  width: 72px;
  height: 72px;
  flex-shrink: 0;
}

/* ── ÉCRAN GALERIE : scroll interne uniquement ── */
#screen-gallery {
  padding: 10px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  box-sizing: border-box;
  height: 100dvh;
}

.gallery-header {
  width: 100%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 0 10px 0;
}

.gallery-title {
  font-size: clamp(1rem, 5vw, 1.4rem);
}

.gallery-grid {
  flex: 1;
  width: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  padding-bottom: 16px;
  box-sizing: border-box;
}

.gallery-item {
  width: 100%;
  aspect-ratio: 3 / 4;
  overflow: hidden;
  border-radius: 10px;
}

.gallery-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* ── LIGHTBOX sur smartphone ── */
.gallery-lightbox-img {
  max-width: 96vw;
  max-height: 88vh;
  border-radius: 12px;
}