* {
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  scrollbar-gutter: auto;
}

body {
  position: relative;
  margin: 0;
  background-image: url('../images/bg-videos.jpg');
  background-size: 109%;
  background-position: center center;
  background-repeat: no-repeat;
  background-attachment: fixed;
}

/* Fond plein écran sur iPhone en mode ribbon : background-attachment:fixed ne
   fonctionne pas correctement sur iOS Safari (bug connu) et fait apparaître le fond
   mal cadré / pas plein écran. -webkit-fill-available compense aussi la barre
   d'adresse Safari qui réduit dynamiquement la hauteur du viewport. */
@media (max-width: 768px) {
  html, body {
    width: 100%;
    height: 100%;
    min-height: 100vh;
    min-height: -webkit-fill-available;
    overflow: hidden;
  }

  body {
    background-size: cover;
    background-position: center center;
    background-attachment: scroll;
  }
}

#cw-ribbon-wrap {
  position: fixed;
  inset: 0;
  overflow: hidden;
  perspective: 300px;
  perspective-origin: 50% 50%;
  cursor: grab;
}

#cw-ribbon {
  position: absolute;
  width: 100%;
  left: 0;
  transform-origin: 50% 50%;
}

.cw-card {
  width: 100vw;
  height: 100vh;
  position: relative;
}

.cw-overlay {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  z-index: 10;
  pointer-events: none;
  color: #fff;
}

.cw-title {
  font-family: 'Space Grotesk', sans-serif;
  font-size: clamp(48px, 10vw, 120px);
  font-weight: 800;
  letter-spacing: -0.02em;
  text-transform: uppercase;
  line-height: 1;
  color: #fff;
}

.cw-meta {
  margin-top: 16px;
  font-size: 10px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: #fff;
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: center;
}

.cw-meta strong {
  font-weight: 400;
  opacity: 0.5;
  margin-right: 4px;
}


/* .site-footer override : fixed au bas du viewport par-dessus le ruban */
.site-footer {
  position: fixed !important;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 200 !important;
}

/* Proto-only : fond transparent + dégradé discret pour lisibilité */
body.cw-proto .site-footer {
  background: linear-gradient(to bottom, transparent, rgba(0, 0, 0, 0.55)) !important;
  border-top: none;
}

.cw-thumbnails {
  position: fixed;
  right: 24px;
  top: 50%;
  transform: translateY(-50%);
  height: calc(7 * 44px + 6 * 6px);
  overflow: visible;
  padding: 0 4px;
  margin-right: -4px;
  z-index: 10;
  cursor: grab;
  -webkit-mask-image: linear-gradient(
    to bottom,
    transparent 0%,
    black 15%,
    black 85%,
    transparent 100%
  );
  mask-image: linear-gradient(
    to bottom,
    transparent 0%,
    black 15%,
    black 85%,
    transparent 100%
  );
}

#cw-thumbnails {
  transform-origin: center center;
}

#cw-thumbs-inner {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.cw-thumb {
  width: 72px;
  height: 44px;
  border-radius: 2px;
  opacity: 0.25;
  flex-shrink: 0;
  cursor: pointer;
  transition: opacity 0.3s ease, outline 0.3s ease;
}

.cw-thumb:hover {
  opacity: 1;
}

.cw-thumb.active {
  opacity: 1;
  box-shadow: 0 0 0 1px var(--offwhite);
}

/* Mini-carousel horizontal en bas sur mobile.
   Le vrai conteneur flex est #cw-thumbs-inner (pas #cw-thumbs, qui n'existe pas dans
   le markup) — #cw-thumbnails est juste le viewport positionné/masqué autour de lui.
   .cw-thumbs-row (créé par _initMobileThumbArrows()) prend le positionnement fixe
   et aligne les flèches prev/next de part et d'autre du viewport. */
@media (max-width: 768px) {
  .cw-thumbs-row {
    position: fixed;
    /* .site-footer (fixed, ~84px de haut à 375px) occupe déjà le bas de l'écran :
       5rem remonte encore l'ensemble sans passer derrière le header. */
    bottom: 5rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
    max-width: 90vw; /* flèches incluses : le strip se réduit dans l'espace restant */
  }

  #cw-thumbnails {
    position: static;
    height: auto;
    width: auto;
    flex: 1 1 auto;
    min-width: 0; /* laisse le flex-item se réduire sous son contenu intrinsèque */
    overflow-x: auto;
    overflow-y: visible;
    padding: 3px; /* espace pour l'outline de la vignette active, sans casser le scroll */
    -webkit-mask-image: linear-gradient(
      to right,
      transparent 0%,
      black 8%,
      black 92%,
      transparent 100%
    );
    mask-image: linear-gradient(
      to right,
      transparent 0%,
      black 8%,
      black 92%,
      transparent 100%
    );
  }

  #cw-thumbs-inner {
    flex-direction: row;
    gap: 0.5rem;
    /* width:auto (défaut) confine la boîte à l'espace visible du viewport parent ;
       comme .cw-thumb a flex-shrink:0, le contenu déborde cette boîte au lieu de
       l'agrandir, et le padding-right (ajouté en JS pour centrer la 1ère/dernière
       vignette) se retrouve alors placé juste après le bord de la boîte trop étroite
       au lieu d'après la vraie dernière vignette débordante. max-content force la
       boîte à envelopper tout son contenu flex réel. */
    width: max-content;
  }

  .cw-thumb {
    width: 48px;
    height: 32px; /* ratio 16/9 à petite taille */
    outline: none;
    box-shadow: none;
  }

  .cw-thumb:hover {
    box-shadow: none; /* pas de cadre au hover sur touch */
  }

  .cw-thumb.active {
    outline: 1.5px solid var(--offwhite);
    outline-offset: 2px;
    box-shadow: none;
  }

  .cw-thumb-arrow {
    background: none;
    border: none;
    color: var(--offwhite);
    font-size: 1.5rem;
    opacity: 0.5;
    cursor: pointer;
    flex-shrink: 0;
    align-self: center;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 32px; /* même hauteur que les vignettes (.cw-thumb: 32px sur mobile) */
    line-height: 1;
    padding: 0;
  }

  .cw-thumb-arrow:hover {
    opacity: 1;
  }
}

/* ── VIEW TOGGLE ── */
/* top: .site-header a padding 1.5rem 2.5rem et centre ses enfants (align-items: center)
   sur la hauteur du logo (65px) : le burger se retrouve donc à top 45.25px (22.5px de haut),
   centré à 56.5px. Pour aligner le toggle (26px de haut) sur cette même ligne médiane,
   son top doit être 43.5px = 1.5rem (padding-top) + 65px/2 (centre du logo) - 26px/2 (moitié du toggle). */
#cw-view-toggle {
  position: fixed;
  top: 40px;
  left: 50%;
  transform: translateX(-50%);
  right: auto;
  z-index: 9999;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--offwhite);
  opacity: 0;
  pointer-events: none;
  padding: 4px;
}

/* Masquer le toggle quand le burger est ouvert */
.burger.open ~ #cw-view-toggle,
body:has(.burger.open) #cw-view-toggle {
  opacity: 0 !important;
  pointer-events: none !important;
}

/* En mode ribbon, montrer icon-grid et cacher icon-ribbon */
body.mode-ribbon .icon-ribbon { display: none; }
body.mode-ribbon .icon-grid  { display: block; }

/* En mode grid, montrer icon-ribbon et cacher icon-grid */
body.mode-grid .icon-grid    { display: none; }
body.mode-grid .icon-ribbon  { display: block; }

/* Conteneur grille
   position: relative (et non absolute) : la grille reste dans le flow normal du
   document, ce qui est nécessaire pour que le footer (repositionné juste après elle
   dans le DOM en mode grid, cf. _toGrid()) s'empile naturellement à sa suite. Un
   #cw-grid en position:absolute serait hors-flow et le footer se retrouverait
   toujours en haut de page, peu importe son ordre dans le DOM. */
#cw-grid {
  position: relative;
  width: 90%;
  max-width: 90%;
  margin: 0 auto;
  min-height: 100%;
  z-index: 500;
  overflow: visible;
  padding: 8rem 0 4rem;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  background: transparent;
  pointer-events: none;
  opacity: 0;
}

#cw-grid::before {
  display: none;
}

body.mode-grid #cw-grid {
  pointer-events: all;
}

/* Le scroll réel doit se faire au niveau document/html (window.scrollY) pour que
   ScrollTrigger (qui suit le scroll de la fenêtre) fonctionne : body doit laisser
   remonter son propre débordement plutôt que le scroller lui-même. */
body.mode-grid {
  overflow: visible !important;
}

html.mode-grid {
  overflow-y: auto !important;
}

body.mode-grid #cw-ribbon-wrap {
  pointer-events: none;
}

/* Footer sorti du fixed pour s'attacher naturellement sous la grille en mode grid.
   !important nécessaire : .site-footer fixe déjà position/z-index en !important. */
body.mode-grid .site-footer {
  position: relative !important;
  bottom: auto;
  z-index: 600 !important;
  background: transparent !important;
  border-top: none;
}

body.mode-ribbon,
html.mode-ribbon {
  overflow: hidden; /* pas de scroll en mode ribbon */
}

/* Masquer titre/description et mini-carousel en mode grid */
.cw-overlay,
#cw-thumbnails {
  transition: opacity 0.3s ease;
}

/* !important requis : GSAP fixe un opacity inline sur ces éléments (intro + updates par frame) */
body.mode-grid .cw-overlay {
  opacity: 0 !important;
  pointer-events: none;
}

body.mode-grid #cw-thumbnails {
  opacity: 0 !important;
  pointer-events: none;
}

/* Cards en mode grille */
.cw-grid-card {
  position: relative;
  aspect-ratio: 16/9;
  overflow: hidden;
  border-radius: 8px;
  cursor: pointer;
}

.cw-grid-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.4s ease;
}

.cw-grid-card:hover img { transform: scale(1.04); }

/* Gradient fixe — ne bouge jamais */
.cw-grid-card::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 60%;
  background: linear-gradient(transparent, rgba(0,0,0,0.85));
  pointer-events: none;
  z-index: 1;
  /* pas de transition, pas de changement au hover */
}

/* Bloc texte — remonte au hover */
.cw-grid-card-info {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 1.5rem;
  background: none; /* plus de gradient ici, c'est le ::after qui le gère */
  opacity: 1;
  transform: translateY(0);
  transition: transform 0.35s ease;
  z-index: 2;
}

.cw-grid-card:hover .cw-grid-card-info {
  transform: translateY(-8px);
}

.cw-grid-card-title {
  font-family: var(--sans);
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: -0.02em;
  text-transform: uppercase;
  color: var(--offwhite);
}

.cw-grid-card-client {
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  color: var(--red);
  text-transform: uppercase;
  margin-top: 0.3rem;
}

@media (max-width: 768px) {
  #cw-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  /* Uniquement les flèches du mini carousel proto — pas celles de project.html
     (#cw-thumbs n'existe pas dans le markup, le vrai wrapper est .cw-thumbs-row) */
  .cw-thumbs-row .cw-thumb-arrow {
    display: none;
  }
}

@media (max-width: 768px) {
  body.mode-ribbon .site-footer,
  body.mode-ribbon .footer-icon-link {
    color: var(--offwhite) !important;
  }
}

