/* Infographie « Notre métier » : nid d'abeille 1 + 6 et panneau de détail.
   Prévu pour un fond bleu nuit (section--dark).

   Géométrie : hexagones « plat en haut » de rayon --r (largeur 2r, hauteur √3·r).
   Les centres voisins sont distants de --d = hauteur × --k ; (--k − 1) règle
   donc l'interstice. Tout découle de la largeur du conteneur (unités cqi). */

.hex {
  /* Variables locales, dérivées des tokens */
  --hex-stroke: color-mix(in srgb, var(--color-on-dark) 26%, transparent);
  --hex-stroke-strong: color-mix(in srgb, var(--color-on-dark) 55%, transparent);
  --hex-text-dim: color-mix(in srgb, var(--color-on-dark) 74%, transparent);
  --hex-glow: color-mix(in srgb, var(--color-accent) 45%, transparent);
  --hex-rule: color-mix(in srgb, var(--color-accent) 55%, transparent);
  --hex-stagger: 90ms;

  color: var(--color-on-dark);
  font-family: var(--font-sans);
}

/* ------------------------------------------------------------------
   Sans JavaScript : le schéma est masqué, les six thèmes sont listés.
   ------------------------------------------------------------------ */

.hex__diagram {
  display: none;
}

.hex__panels {
  display: grid;
  gap: var(--space-6);
  max-width: var(--container-narrow);
  margin-inline: auto;
}

.hex__panel {
  padding-top: var(--space-5);
  border-top: 1px solid var(--color-line-dark);
}

.hex__number {
  display: flex;
  align-items: baseline;
  gap: var(--space-3);
  margin: 0 0 var(--space-3);
  line-height: 1;
}

.hex__number-current {
  font-family: var(--font-serif);
  font-size: clamp(2.75rem, 2rem + 3vw, 4.5rem);
  font-weight: 300;
  color: var(--color-accent);
  font-variant-numeric: lining-nums;
}

.hex__number-total {
  font-size: var(--text-xs);
  letter-spacing: var(--tracking-caps);
  color: var(--color-on-dark-muted);
}

.hex__title {
  margin: 0;
  font-family: var(--font-serif);
  font-size: var(--text-xl);
  font-weight: 500;
  line-height: var(--leading-tight);
  color: var(--color-on-dark);
  text-wrap: balance;
}

.hex__title::after {
  content: "";
  display: block;
  width: var(--space-7);
  height: 1px;
  margin-block: var(--space-5);
  background: var(--color-accent);
}

.hex__text,
.hex__items {
  margin: 0;
  padding: 0;
  max-width: 34rem;
  font-size: var(--text-lg);
  font-weight: 300;
  line-height: var(--leading-normal);
  color: color-mix(in srgb, var(--color-on-dark) 86%, transparent);
  text-wrap: pretty;
}

.hex__items {
  display: grid;
  gap: var(--space-3);
  list-style: none;
}

.hex__items li {
  position: relative;
  padding-left: var(--space-6);
}

.hex__items li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.82em;
  width: var(--space-4);
  height: 1px;
  background: var(--color-accent);
}

/* ------------------------------------------------------------------
   Version interactive
   ------------------------------------------------------------------ */

.hex.is-enhanced {
  display: grid;
  gap: clamp(var(--space-6), 6vw, var(--space-8));
  align-items: center;
}

.hex.is-enhanced .hex__diagram {
  display: block;
  width: 100%;
  max-width: 40rem;
  margin-inline: auto;
  container: hex / inline-size;
}

.hex__stage {
  --k: 1.06;
  --r: calc(100cqi / (3 * var(--k) + 2));
  --h: calc(var(--r) * 1.7320508);
  --d: calc(var(--h) * var(--k));

  position: relative;
  height: calc(var(--h) + 2 * var(--d));
}

.hex__ring {
  margin: 0;
  padding: 0;
  list-style: none;
}

/* --- Cellules --- */

.hex__cell {
  position: absolute;
  left: calc(50% + var(--x, 0) * var(--d) - var(--r));
  top: calc(50% + var(--y, 0) * var(--d) - var(--h) / 2);
  width: calc(var(--r) * 2);
  height: var(--h);
  isolation: isolate;
  /* Les boîtes rectangulaires se chevauchent : seuls les hexagones captent le pointeur. */
  pointer-events: none;
  transition: scale var(--duration) var(--ease);
}

.hex__cell--core { --n: 0; z-index: 1; }
.hex__cell--1 { --x: 0;      --y: -1;   --n: 1; }
.hex__cell--2 { --x: 0.866;  --y: -0.5; --n: 2; }
.hex__cell--3 { --x: 0.866;  --y: 0.5;  --n: 3; }
.hex__cell--4 { --x: 0;      --y: 1;    --n: 4; }
.hex__cell--5 { --x: -0.866; --y: 0.5;  --n: 5; }
.hex__cell--6 { --x: -0.866; --y: -0.5; --n: 6; }

.hex__cell.is-active {
  z-index: 2;
  scale: 1.035;
}

/* --- Tracé (SVG : contours nets, non rognés) --- */

.hex__shape {
  position: absolute;
  inset: 0;
  z-index: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
  transition: filter var(--duration) var(--ease);
}

.hex__shape polygon,
.hex__shape line {
  vector-effect: non-scaling-stroke;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.hex__outline {
  fill: transparent;
  stroke: var(--hex-stroke);
  stroke-width: 1;
  transition:
    fill var(--duration) var(--ease),
    stroke var(--duration) var(--ease);
}

.hex__cell.is-active .hex__outline {
  fill: var(--color-accent);
  stroke: var(--color-accent);
}

.hex__cell.is-active .hex__shape {
  filter: drop-shadow(0 0 1.25rem var(--hex-glow));
}

/* Anneau de focus : hexagone légèrement plus grand, logé dans l'interstice. */
.hex__focus {
  fill: none;
  stroke: var(--color-white);
  stroke-width: 2;
  opacity: 0;
  transform-box: fill-box;
  transform-origin: center;
  transform: scale(1.07);
}

.hex__btn:focus-visible ~ .hex__shape .hex__focus {
  opacity: 1;
}

/* --- Bouton --- */

.hex__btn {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: calc(var(--r) * 0.11);
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0 calc(var(--r) * 0.2);
  border: 0;
  background: none;
  color: var(--hex-text-dim);
  font: inherit;
  text-align: center;
  cursor: pointer;
  pointer-events: auto;
  /* Zone cliquable limitée à l'hexagone (les boîtes voisines se chevauchent). */
  clip-path: polygon(25% 0, 75% 0, 100% 50%, 75% 100%, 25% 100%, 0 50%);
  -webkit-tap-highlight-color: transparent;
  transition: color var(--duration) var(--ease);
}

/* Le focus est rendu par .hex__focus (un outline serait rogné par clip-path). */
.hex .hex__btn:focus,
.hex .hex__btn:focus-visible {
  outline: none;
}

.hex__cell.is-active .hex__btn {
  color: var(--color-navy);
}

.hex__icon {
  flex: none;
  width: clamp(1.125rem, calc(var(--r) * 0.3), 2.125rem);
  height: auto;
  aspect-ratio: 1;
  fill: none;
  stroke: var(--color-accent);
  stroke-width: 1.15;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: stroke var(--duration) var(--ease);
}

.hex__cell.is-active .hex__icon {
  stroke: currentColor;
}

.hex__label {
  display: block;
  font-size: clamp(0.5625rem, 2.6cqi, 0.875rem);
  font-weight: 500;
  line-height: 1.35;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  /* Compense l'espacement après la dernière lettre pour un centrage exact. */
  margin-right: -0.1em;
}

.hex__label-line {
  display: block;
  white-space: nowrap;
}

/* --- Centre --- */

.hex__cell--core .hex__outline {
  fill: var(--color-navy-3);
  stroke: var(--hex-rule);
}

.hex__inset {
  fill: none;
  stroke: var(--hex-stroke);
  stroke-width: 1;
  transform-box: fill-box;
  transform-origin: center;
  transform: scale(0.9);
}

/* Arête du centre tournée vers le thème actif. */
.hex__facet {
  stroke: var(--color-accent);
  stroke-width: 2.5;
  opacity: 0;
  transition: opacity var(--duration) var(--ease);
}

.hex__facet.is-active {
  opacity: 1;
}

.hex__core {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  margin: 0;
  text-align: center;
  color: var(--color-white);
  pointer-events: auto;
  clip-path: polygon(25% 0, 75% 0, 100% 50%, 75% 100%, 25% 100%, 0 50%);
}

.hex__brand {
  display: block;
  font-family: var(--font-serif);
  line-height: 1;
  text-transform: uppercase;
}

.hex__brand-mark,
.hex__brand-name {
  display: block;
  letter-spacing: var(--tracking-logo);
  margin-right: calc(var(--tracking-logo) * -1);
}

.hex__brand-mark {
  font-size: clamp(1.25rem, 7.4cqi, 2.75rem);
  font-weight: 500;
}

.hex__brand-name {
  margin-top: 0.3em;
  font-size: clamp(0.6875rem, 3.5cqi, 1.3125rem);
  font-weight: 500;
}

.hex__powered {
  display: block;
  margin-top: calc(var(--r) * 0.11);
  padding-top: calc(var(--r) * 0.09);
  border-top: 1px solid var(--hex-rule);
  font-family: var(--font-serif);
  font-style: italic;
  font-size: clamp(0.625rem, 2.5cqi, 0.9375rem);
  letter-spacing: 0.04em;
  color: var(--color-accent);
}

/* --- Filets centre → thème actif --- */

.hex__link {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 1px;
  height: calc(var(--d) - var(--h));
  margin-left: -0.5px;
  background: var(--color-accent);
  box-shadow: 0 0 0.5rem var(--hex-glow);
  opacity: 0;
  transform-origin: 50% 0;
  transform: rotate(var(--a)) translateY(calc(var(--h) / -2 - 100%));
  transition: opacity var(--duration) var(--ease);
  pointer-events: none;
}

.hex__link.is-active {
  opacity: 1;
}

.hex__link--1 { --a: 0deg; }
.hex__link--2 { --a: 60deg; }
.hex__link--3 { --a: 120deg; }
.hex__link--4 { --a: 180deg; }
.hex__link--5 { --a: 240deg; }
.hex__link--6 { --a: 300deg; }

/* --- Panneaux : superposés, seul l'actif est visible --- */

.hex.is-enhanced .hex__panels {
  gap: 0;
  width: 100%;
  max-width: 34rem;
}

.hex.is-enhanced .hex__panel {
  grid-area: 1 / 1;
  padding-top: 0;
  border-top: 0;
  opacity: 0;
  visibility: hidden;
  translate: 0 0.75rem;
  transition:
    opacity var(--duration) var(--ease),
    translate var(--duration) var(--ease),
    visibility 0s linear var(--duration);
}

.hex.is-enhanced .hex__panel.is-active {
  opacity: 1;
  visibility: visible;
  translate: 0 0;
  transition-delay: 0.08s, 0.08s, 0s;
}

/* --- Apparition en cascade --- */

.hex.is-enhanced .hex__cell {
  opacity: 0;
}

.hex.is-enhanced.is-visible .hex__cell {
  animation: hex-in 0.8s var(--ease) calc(var(--n) * var(--hex-stagger)) both;
}

@keyframes hex-in {
  from {
    opacity: 0;
    transform: translateY(1rem) scale(0.94);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ------------------------------------------------------------------
   Très petits conteneurs (< 330 px, ex. écran de 320 ou 360 px) :
   ruban en nid d'abeille sur 2 colonnes imbriquées, centre en tête.
   Les hexagones y sont plus grands, les titres restent lisibles.
   ------------------------------------------------------------------ */

@container hex (max-width: 329px) {
  .hex__stage {
    --r: calc(100cqi / (1.5 * var(--k) + 2));
    height: calc(var(--h) + 3 * var(--d));
  }

  .hex__cell {
    left: calc(var(--col) * 1.5 * var(--r) * var(--k));
    top: calc(var(--row) * var(--d));
  }

  .hex__cell--core { --col: 0; --row: 0; }
  .hex__cell--1 { --col: 1; --row: 0.5; }
  .hex__cell--2 { --col: 0; --row: 1; }
  .hex__cell--3 { --col: 1; --row: 1.5; }
  .hex__cell--4 { --col: 0; --row: 2; }
  .hex__cell--5 { --col: 1; --row: 2.5; }
  .hex__cell--6 { --col: 0; --row: 3; }

  .hex__link,
  .hex__facet {
    display: none;
  }

  .hex__label {
    font-size: 0.625rem;
    line-height: 1.25;
  }

  .hex__brand-mark {
    font-size: 1.75rem;
  }

  .hex__brand-name {
    font-size: 0.875rem;
  }

  .hex__powered {
    font-size: 0.75rem;
  }
}

/* Conteneurs compacts : interlettrage resserré pour loger les titres longs. */
@container hex (min-width: 330px) and (max-width: 479px) {
  .hex__label {
    line-height: 1.25;
    letter-spacing: 0.05em;
    margin-right: -0.05em;
  }

  .hex__btn {
    gap: calc(var(--r) * 0.08);
  }
}

/* Conteneurs larges : interstice plus généreux. */
@container hex (min-width: 480px) {
  .hex__stage {
    --k: 1.085;
  }
}

/* ------------------------------------------------------------------
   Desktop : schéma et panneau côte à côte
   ------------------------------------------------------------------ */

@media (min-width: 900px) {
  .hex.is-enhanced {
    grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
    gap: clamp(var(--space-6), 5vw, var(--space-9));
  }

  .hex.is-enhanced .hex__diagram {
    margin-inline: 0 auto;
  }

  .hex.is-enhanced .hex__panels {
    margin-inline: 0;
  }
}

/* ------------------------------------------------------------------
   Mouvement réduit : ni animation d'entrée, ni transformation
   ------------------------------------------------------------------ */

@media (prefers-reduced-motion: reduce) {
  .hex.is-enhanced .hex__cell,
  .hex.is-enhanced.is-visible .hex__cell {
    opacity: 1;
    animation: none;
    transition: none;
  }

  .hex__cell.is-active {
    scale: none;
  }

  .hex.is-enhanced .hex__panel,
  .hex.is-enhanced .hex__panel.is-active {
    translate: none;
    transition: none;
  }

  .hex__shape,
  .hex__outline,
  .hex__btn,
  .hex__icon,
  .hex__facet,
  .hex__link {
    transition: none;
  }
}
