* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  /* --n et --radius sont mis à jour par script.js */
  --n: 12;
  --angle: calc(360deg / var(--n));
  --radius: 260px;
  --item-font-size: clamp(0.7rem, 1.4vw, 1rem);
  --header-height: clamp(48px, 8vw, 72px);
  --duration: 32s;
}

body {
  background-color: rgb(31, 31, 31);
  min-height: 100vh;
  color: white;
}

h1 {
  color: white;
}

/* ---------- En-tête / carrousel ---------- */

.carousel-header {
  position: sticky;
  top: 0;
  z-index: 10;
  width: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  background-color: rgb(20, 20, 20);
}

.header-title {
  margin: 10px;
  color: white;
  font-size: clamp(0.9rem, 2.2vw, 1.25rem);
  font-weight: 600;
  text-align: center;
  letter-spacing: 0.02em;
}

.container {
  position: relative;
  width: 100%;
  height: var(--header-height);
  perspective: 1000px;
  transform-style: preserve-3d;
}

.item {
  position: absolute;
  top: 50%;
  left: 50%;

  /* la largeur/hauteur épouse le texte, avec 10px de marge tout autour */
  width: max-content;
  max-width: 60vw;
  padding: 10px;

  display: grid;
  place-items: center;

  font-size: var(--item-font-size);
  line-height: 1.1;
  color: white;
  text-decoration: none;

  background: rgba(255, 255, 255, 0.4);
  border-radius: 12px;
  cursor: pointer;

  transform: translate(-50%, -50%) rotateY(calc(var(--angle) * var(--i))) translateZ(var(--radius));
  animation: rotate var(--duration) infinite linear;
  transition: background-color 0.2s ease, color 0.2s ease, transform 0.2s ease;
}

.item-label {
  display: block;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;

  /* La moitié du carrousel qui fait face à l'écran (angle proche de 0°) est
     "à l'avant" ; la moitié opposée (angle proche de 180°) est "à l'arrière"
     et ses étiquettes se chevauchent, nuisant à la lisibilité. On masque
     donc uniquement le texte (le fond translucide de l'item reste inchangé)
     pendant que l'item est dans cette moitié arrière. Le décalage
     (animation-delay négatif, basé sur --i) synchronise ce fondu avec la
     position de rotation propre à chaque item, exactement comme pour
     l'animation `rotate` elle-même. */
  animation: label-visibility var(--duration) infinite linear;
  animation-delay: calc(-1 * var(--i) * var(--duration) / var(--n));
}

@keyframes label-visibility {
  0%   { opacity: 1; }
  24%  { opacity: 1; }
  26%  { opacity: 0; }
  74%  { opacity: 0; }
  76%  { opacity: 1; }
  100% { opacity: 1; }
}

.item.is-active,
.item:focus-visible {
  background: #ffffff;
  color: #1a56ff;
  outline: none;
}

/* Un item actif (survolé, focus clavier, ou touché sur mobile) doit rester
   lisible même si sa position de rotation le place ponctuellement dans la
   moitié arrière. */
.item.is-active .item-label,
.item:focus-visible .item-label {
  opacity: 1;
}

/* La mise en pause et la mise en avant (fond blanc / texte bleu) sont
   pilotées en JS via la classe .is-paused / .is-active : avec des items
   transformés en 3D (rotateY/translateZ), le pseudo-sélecteur :hover ne se
   déclenche pas de façon fiable (la hitbox calculée par le navigateur ne
   correspond pas toujours à la position réellement affichée à l'écran). */
.container:focus-within .item,
.container:focus-within .item-label,
.container.is-paused .item,
.container.is-paused .item-label {
  animation-play-state: paused;
}

@keyframes rotate {
  from {
    transform: translate(-50%, -50%) rotateY(calc(var(--angle) * var(--i))) translateZ(var(--radius));
  }

  to {
    transform: translate(-50%, -50%) rotateY(calc(var(--angle) * var(--i) + 360deg)) translateZ(var(--radius));
  }
}

@media (prefers-reduced-motion: reduce) {
  .item,
  .item-label {
    animation: none;
  }
}

/* ---------- Contenu de la page ---------- */

.page-content {
  padding: 24px;
}

@media (max-width: 600px) {
  :root {
    --item-font-size: clamp(0.85rem, 4.5vw, 1.15rem);
    --header-height: clamp(52px, 16vw, 76px);
  }

  .item {
    padding: 8px 12px;
    max-width: 60vw;
  }
}
