/* =====================================================================
   Scène « Un objet, sur mesure » (18 octobre 2026) : une bourriche à
   huîtres, du dessin coté à l'objet en bois, dans une fenêtre de logiciel
   3D générique. Le récit est dans
   partials/fonctionnalites-demos/sc-a3d-objet.php.

   LE MINUTAGE, en pourcentages de la boucle de 12 secondes :
      4 à 34 %  les 14 pièces arrivent en fil de fer, une tous les 2 %
     37,5 %     mode volumes : le gris monte par-dessus le fil (40 %)
     49,5 %     mode matières : le bois monte par-dessus le gris (52 %) ;
                une couche ne s'efface qu'une fois couverte, jamais de face
                à demi transparente
     54 à 88 %  demi-tour lent de la bourriche ; la lumière reste fixe

   LE MOTEUR. Six propriétés enregistrées, animées sur la fenêtre et
   héritées par chaque face. Leur valeur de départ est l'état final (le bois,
   vu de trois quarts) : c'est ce que voit un visiteur qui demande moins de
   mouvement, et ce que montre un navigateur sans @property.
   ===================================================================== */

@property --aob-p   { syntax: '<number>';  inherits: true; initial-value: 15; }
@property --aob-n   { syntax: '<integer>'; inherits: true; initial-value: 14; }
@property --aob-w   { syntax: '<number>';  inherits: true; initial-value: 0; }
@property --aob-s   { syntax: '<number>';  inherits: true; initial-value: 0; }
@property --aob-m   { syntax: '<number>';  inherits: true; initial-value: 1; }
@property --aob-rot { syntax: '<angle>';   inherits: true; initial-value: -218deg; }

.fn-scene--a3d-objet {
  line-height: 1.3;
  /* Le fil du peuplier : un bruit étiré dans le sens de la latte, deux
     échelles (les cernes, les fibres). Calculé une fois par le navigateur. */
  --aob-tx: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='60'%3E%3Cfilter id='a' x='0' y='0' width='100%25' height='100%25'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.005 .12' numOctaves='3' seed='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .40 0 0 0 0 .26 0 0 0 0 .12 2.8 0 0 0 -1.25'/%3E%3C/filter%3E%3Cfilter id='b' x='0' y='0' width='100%25' height='100%25'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.03 .7' numOctaves='2' seed='9' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .38 0 0 0 0 .24 0 0 0 0 .1 2 0 0 0 -.95'/%3E%3C/filter%3E%3Crect width='240' height='60' filter='url(%23a)'/%3E%3Crect width='240' height='60' filter='url(%23b)' opacity='.55'/%3E%3C/svg%3E");
  --aob-ty: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='60' height='240'%3E%3Cfilter id='a' x='0' y='0' width='100%25' height='100%25'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.12 .005' numOctaves='3' seed='5' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .40 0 0 0 0 .26 0 0 0 0 .12 2.8 0 0 0 -1.25'/%3E%3C/filter%3E%3Cfilter id='b' x='0' y='0' width='100%25' height='100%25'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.7 .03' numOctaves='2' seed='11' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .38 0 0 0 0 .24 0 0 0 0 .1 2 0 0 0 -.95'/%3E%3C/filter%3E%3Crect width='60' height='240' filter='url(%23a)'/%3E%3Crect width='60' height='240' filter='url(%23b)' opacity='.55'/%3E%3C/svg%3E");
  /* La marque au fer : un ovale et une huître, aucun texte. */
  --aob-marq: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='46' height='22' fill='none' stroke='rgb(84,48,22)' stroke-opacity='.62'%3E%3Cellipse cx='23' cy='11' rx='21.5' ry='9.6' stroke-width='1.3'/%3E%3Cellipse cx='23' cy='11' rx='18.6' ry='7.2' stroke-width='.6'/%3E%3Cpath d='M15.5 12.2c-.6-3 2.6-5.3 6.6-5.1 4.4.2 8.6 1.6 9.1 3.9.4 2.1-2.7 3.6-7.2 3.6-4.6 0-8-.7-8.5-2.4Z' stroke-width='1.1'/%3E%3Cpath d='M19 11.3c2.5-1.3 6.5-1.2 9.5.2M20.5 13c2-.6 4.5-.5 6.5.2' stroke-width='.7'/%3E%3C/svg%3E");
  /* Les pointes, deux à chaque bout de latte, plantées dans les montants. */
  --aob-clou:
    radial-gradient(circle at 6px 30%, #4d463f 0 .9px, transparent 1.4px),
    radial-gradient(circle at 6px 70%, #4d463f 0 .9px, transparent 1.4px),
    radial-gradient(circle at calc(100% - 6px) 30%, #4d463f 0 .9px, transparent 1.4px),
    radial-gradient(circle at calc(100% - 6px) 70%, #4d463f 0 .9px, transparent 1.4px);
}
.fn-scene--a3d-objet svg { display: block; }

/* ---- La fenêtre ---- */
.fn-scene--a3d-objet .sc-aob-fen {
  --aob-p: 15; --aob-n: 14; --aob-w: 0; --aob-s: 0; --aob-m: 1; --aob-rot: -218deg;
  position: absolute; top: 4px; left: 4px; width: 512px; height: 416px;
  box-sizing: border-box; display: flex; flex-direction: column; overflow: hidden;
  border: 1px solid #141414; border-radius: 10px;
  background: #262626; color: #d2d2d2; font-size: 11px;
  box-shadow: 0 10px 26px rgba(31, 36, 46, .16);
  animation-name: sc-aob-moteur; animation-timing-function: linear;
}
.fn-scene--a3d-objet .aob-barre {
  display: flex; align-items: center; gap: 14px; flex: 0 0 28px; padding: 0 12px;
  background: #1f1f1f; border-bottom: 1px solid #141414; color: #cfcfcf;
}
.fn-scene--a3d-objet .aob-corps { display: flex; gap: 1px; flex: 1 1 auto; min-height: 0; background: #141414; }

/* ---- La référence ---- */
.fn-scene--a3d-objet .aob-ref { display: flex; flex-direction: column; width: 196px; background: #2a2a2a; }
.fn-scene--a3d-objet .aob-ptete,
.fn-scene--a3d-objet .aob-vtete {
  display: flex; align-items: center; flex: 0 0 28px; box-sizing: border-box; padding: 0 10px;
  background: #303030; border-bottom: 1px solid #1c1c1c;
}
.fn-scene--a3d-objet .aob-ptete { font-size: 12px; font-weight: 600; color: #e4e4e4; }
.fn-scene--a3d-objet .aob-papier {
  flex: 1 1 auto; margin: 10px; overflow: hidden; border-radius: 6px;
  background: #f6f4ee;
}
.fn-scene--a3d-objet .aob-tx { font-size: 11px; fill: #5b6068; }
.fn-scene--a3d-objet .aob-cote { fill: #2f343b; font-weight: 500; }
.fn-scene--a3d-objet .aob-titre { font-size: 12px; font-weight: 600; fill: #1d2128; }

/* ---- La vue 3D ---- */
.fn-scene--a3d-objet .aob-vuecol { display: flex; flex-direction: column; flex: 1 1 auto; min-width: 0; }
.fn-scene--a3d-objet .aob-vtete { justify-content: space-between; color: #c4c4c4; }
.fn-scene--a3d-objet .aob-modes { display: flex; gap: 2px; }
.fn-scene--a3d-objet .aob-modes > span {
  display: grid; place-items: center; width: 22px; height: 18px; border-radius: 4px;
  background: #3e3e3e; color: #d8d8d8;
}
.fn-scene--a3d-objet .aob-modes svg { width: 11px; height: 11px; }
.fn-scene--a3d-objet .aob-modes > .sc-aob-b3 { background: #2A62E0; color: #fff; }

.fn-scene--a3d-objet .aob-vue {
  position: relative; flex: 1 1 auto; overflow: hidden;
  background: radial-gradient(ellipse 80% 70% at 50% 42%, #474747 0%, #333 62%, #2b2b2b 100%);
}
.fn-scene--a3d-objet .aob-persp { position: absolute; inset: 0; perspective: 900px; perspective-origin: 50% 40%; }
.fn-scene--a3d-objet .aob-monde {
  position: absolute; left: 50%; top: 62%; width: 0; height: 0;
  transform-style: preserve-3d; transform: rotateX(-24deg) scale3d(1.2, 1.2, 1.2);
}
.fn-scene--a3d-objet .aob-objet,
.fn-scene--a3d-objet .aob-piece,
.fn-scene--a3d-objet .aob-sous {
  position: absolute; left: 0; top: 0; width: 0; height: 0; transform-style: preserve-3d;
}
/* La bourriche tourne sur elle-même ; la grille du sol, non. */
.fn-scene--a3d-objet .aob-objet { transform: rotateY(var(--aob-rot)); }

/* La grille du sol, avec ses deux axes, fondue sur les bords. */
.fn-scene--a3d-objet .aob-sol {
  position: absolute; left: 0; top: 0; width: 440px; height: 440px; margin: -220px 0 0 -220px;
  transform: translate3d(0, .8px, 0) rotateX(90deg);
  background-image:
    linear-gradient(180deg, transparent calc(50% - .6px), rgba(200, 84, 74, .8) calc(50% - .6px), rgba(200, 84, 74, .8) calc(50% + .6px), transparent calc(50% + .6px)),
    linear-gradient(90deg, transparent calc(50% - .6px), rgba(120, 166, 70, .8) calc(50% - .6px), rgba(120, 166, 70, .8) calc(50% + .6px), transparent calc(50% + .6px)),
    repeating-linear-gradient(0deg, rgba(255, 255, 255, .08) 0 1px, transparent 1px 20px),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, .08) 0 1px, transparent 1px 20px);
  background-position: 0 0, 0 0, 0 10px, 10px 0;
  -webkit-mask-image: radial-gradient(circle, #000 22%, transparent 66%);
  mask-image: radial-gradient(circle, #000 22%, transparent 66%);
}
/* L'ombre de contact, neutre, dès que les faces sont pleines. */
.fn-scene--a3d-objet .aob-ombre {
  position: absolute; left: 0; top: 0; width: 166px; height: 126px; margin: -63px 0 0 -83px;
  transform: translate3d(0, .4px, 0) rotateX(90deg);
  border-radius: 8px; background: rgba(0, 0, 0, .55); filter: blur(7px);
  opacity: calc(max(var(--aob-s), var(--aob-m)) * .85);
}

/* ---- Les pièces : chacune vole vers sa place sur deux pas du compteur ---- */
.fn-scene--a3d-objet .aob-piece {
  --v: clamp(0, calc((var(--aob-p) - var(--i)) / 2), 1);
  --e: calc(1 - (1 - var(--v)) * (1 - var(--v)) * (1 - var(--v)));
  --g: clamp(0, calc(var(--aob-p) - var(--i) - 2), 1);
  transform: translate3d(calc((1 - var(--e)) * var(--dx, 0) * 1px), calc((1 - var(--e)) * var(--dy, 0) * 1px), calc((1 - var(--e)) * var(--dz, 0) * 1px));
}

/* ---- Une face : trois couches. Le fil de fer est sa bordure (bleue tant
   que la pièce vient d'arriver, puis grise), le volume et le bois sont ses
   deux pseudo-éléments. --o : l'ombre propre de la face, calculée selon son
   orientation du moment ; la lumière vient de l'avant gauche. ---- */
.fn-scene--a3d-objet .aob-f {
  --o: calc(var(--ao, 0) + .34 - .26 * cos(var(--aob-rot) + var(--n, 0deg) + 40deg));
  position: absolute; left: 0; top: 0; display: block; box-sizing: border-box;
  border: 1px solid rgb(calc(94 + 110 * var(--g)) calc(141 + 69 * var(--g)) calc(255 - 34 * var(--g)) / calc(var(--v) * var(--aob-w)));
}
.fn-scene--a3d-objet .aob-h { --o: var(--ao, 0); }
.fn-scene--a3d-objet .aob-in { --ao: .14; }
/* Sans cos() (navigateurs d'avant 2023), --o serait invalide et viderait le
   fond des faces : une ombre fixe par face à la place. */
@supports not (top: calc(1px * cos(0deg))) {
  .fn-scene--a3d-objet .aob-f { --o: calc(var(--ao, 0) + .2); }
  .fn-scene--a3d-objet .aob-h { --o: var(--ao, 0); }
}
.fn-scene--a3d-objet .aob-f::before,
.fn-scene--a3d-objet .aob-f::after { content: ""; position: absolute; inset: -1px; }
.fn-scene--a3d-objet .aob-f::before {
  background: linear-gradient(rgb(0 0 0 / calc(var(--o) * .8)) 0 0), #d7d8db;
  box-shadow: inset 0 0 0 .6px rgba(0, 0, 0, .36);
  opacity: calc(var(--v) * var(--aob-s));
}
.fn-scene--a3d-objet .aob-f::after {
  --aob-ombre: linear-gradient(rgb(34 20 6 / var(--o)) 0 0);
  --aob-bois: linear-gradient(180deg, hsl(40 44% calc(var(--L) + 3%)), hsl(37 40% calc(var(--L) - 2%)));
  background: var(--aob-ombre), var(--aob-tx) var(--px, 0px) 0 / 240px 60px, var(--aob-bois);
  box-shadow: inset 0 0 0 .5px rgba(0, 0, 0, .22);
  opacity: calc(var(--v) * var(--aob-m));
}
.fn-scene--a3d-objet .aob-gy::after {
  background: var(--aob-ombre), var(--aob-ty) 0 var(--px, 0px) / 60px 240px,
    linear-gradient(90deg, hsl(40 44% calc(var(--L) + 3%)), hsl(37 40% calc(var(--L) - 2%)));
}
/* Le bois de bout : plus sombre, les cernes en arcs. */
.fn-scene--a3d-objet .aob-gb::after {
  background: var(--aob-ombre),
    repeating-radial-gradient(circle at 20% 140%, rgb(112 76 42 / .22) 0 .7px, transparent .7px 2.4px),
    hsl(36 36% calc(var(--L) - 13%));
}
.fn-scene--a3d-objet .aob-clous::after {
  background: var(--aob-ombre), var(--aob-clou), var(--aob-tx) var(--px, 0px) 0 / 240px 60px, var(--aob-bois);
}
.fn-scene--a3d-objet .aob-marque::after {
  background: var(--aob-ombre), var(--aob-marq) 50% 52% / 46px 22px no-repeat, var(--aob-clou),
    var(--aob-tx) var(--px, 0px) 0 / 240px 60px, var(--aob-bois);
}

.fn-scene--a3d-objet .aob-gizmo { position: absolute; top: 8px; right: 8px; width: 40px; height: 40px; }
.fn-scene--a3d-objet .aob-gizmo svg { width: 40px; height: 40px; }

/* ---- La barre d'état : le compteur de pièces et le mode ---- */
.fn-scene--a3d-objet .aob-statut {
  display: flex; align-items: center; justify-content: space-between; flex: 0 0 26px;
  padding: 0 12px; background: #1f1f1f; border-top: 1px solid #141414;
  font-size: 12px; color: #d0d0d0; font-variant-numeric: tabular-nums;
}
.fn-scene--a3d-objet .aob-n { display: inline-block; min-width: 15px; text-align: right; }
.fn-scene--a3d-objet .aob-n::before { counter-reset: aob-n var(--aob-n); content: counter(aob-n); }
.fn-scene--a3d-objet .aob-mt { display: inline-grid; }
.fn-scene--a3d-objet .aob-mt > span { grid-area: 1 / 1; }
.fn-scene--a3d-objet .sc-aob-m1,
.fn-scene--a3d-objet .sc-aob-m2 { opacity: 0; }

/* ---- Les animations ---- */
.fn-scene--a3d-objet .sc-fin { animation-name: sc-conclure; }
.fn-scene--a3d-objet .sc-aob-b1 { animation-name: sc-aob-b1; }
.fn-scene--a3d-objet .sc-aob-b2 { animation-name: sc-aob-b2; }
.fn-scene--a3d-objet .sc-aob-b3 { animation-name: sc-aob-b3; }
.fn-scene--a3d-objet .sc-aob-m1 { animation-name: sc-aob-m1; }
.fn-scene--a3d-objet .sc-aob-m2 { animation-name: sc-aob-m2; }
.fn-scene--a3d-objet .sc-aob-m3 { animation-name: sc-aob-m3; }

/* Chaque propriété ne s'interpole qu'entre ses propres pas. Le demi-tour
   part et s'arrête en douceur. */
@keyframes sc-aob-moteur {
  0%, 4%  { --aob-p: 0; --aob-n: 0; --aob-w: 1; --aob-s: 0; --aob-m: 0; --aob-rot: -28deg; }
  6%      { --aob-n: 0; }
  34%     { --aob-p: 15; --aob-n: 14; }
  37.5%   { --aob-w: 1; --aob-s: 0; }
  40%     { --aob-w: 1; --aob-s: 1; }
  40.1%   { --aob-w: 0; }
  49.5%   { --aob-m: 0; }
  52%     { --aob-s: 1; --aob-m: 1; }
  52.1%   { --aob-s: 0; }
  54%     { --aob-rot: -38deg; animation-timing-function: cubic-bezier(.45, 0, .25, 1); }
  88%     { --aob-rot: -218deg; }
  100%    { --aob-p: 15; --aob-n: 14; --aob-w: 0; --aob-s: 0; --aob-m: 1; --aob-rot: -218deg; }
}
@keyframes sc-aob-b1 {
  0%, 37.5%   { background: #2A62E0; color: #fff; }
  38%, 100%   { background: #3e3e3e; color: #d8d8d8; }
}
@keyframes sc-aob-b2 {
  0%, 37.5%   { background: #3e3e3e; color: #d8d8d8; }
  38%, 49.5%  { background: #2A62E0; color: #fff; }
  50%, 100%   { background: #3e3e3e; color: #d8d8d8; }
}
@keyframes sc-aob-b3 {
  0%, 49.5%   { background: #3e3e3e; color: #d8d8d8; }
  50%, 100%   { background: #2A62E0; color: #fff; }
}
@keyframes sc-aob-m1 { 0%, 37.5% { opacity: 1; } 38.5%, 100% { opacity: 0; } }
@keyframes sc-aob-m2 { 0%, 37.5% { opacity: 0; } 38.5%, 49.5% { opacity: 1; } 50.5%, 100% { opacity: 0; } }
@keyframes sc-aob-m3 { 0%, 49.5% { opacity: 0; } 50.5%, 100% { opacity: 1; } }
