/* ============================================================
   Styles du portfolio + de l'intro façon jeu à dialogues
   Les images des cadres (9-slice) et leurs marges sont injectées
   par js/intro.js sous forme de variables CSS, depuis js/dialogues.js.
   ============================================================ */

@font-face {
  font-family: "Cinzel";
  src: url("../fonts/Cinzel-VariableFont_wght.ttf") format("truetype");
  font-weight: 400 900;
  font-display: swap;
}

/* Police bitmap du thème pc98 (OFL, réduite aux caractères latins) */
@font-face {
  font-family: "DotGothic16";
  src: url("../fonts/DotGothic16-latin.woff2") format("woff2");
  font-display: swap;
}

:root {
  /* Palette alignée sur le pack d'UI (ardoise sombre, accent bleu) */
  --fond: #000;
  --texte: #e8eef8;
  --texte-doux: #a9b4c6;
  --accent: #4c9aff;
  --focus: #ffd166;

  --police: "Cinzel", Georgia, serif;
  --police-texte: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  /* Échelle entière des cadres (écrasée par la config) */
  --s: 1;
  --duree-fondu: 600ms;
  /* Entrée dans la porte, puis arrivée dans la salle aux trois portes
     (lues aussi par js/intro.js) */
  --duree-entree: 1200ms;
  --duree-arrivee: 700ms;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
}

body {
  min-height: 100vh;
  background: var(--fond);
  color: var(--texte);
  font-family: var(--police-texte);
  line-height: 1.5;
}

/* Masqué visuellement mais lu par les lecteurs d'écran */
.sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* Focus visible partout (clavier) */
:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

/* Focus programmatique sur des éléments non interactifs : pas d'anneau */
[tabindex="-1"]:focus {
  outline: none;
}

/* ============================================================
   États globaux (classes posées sur <html>)
   - intro-active : l'intro est affichée, le portfolio est caché
   - intro-sortie : fondu entre l'intro et le portfolio
   ============================================================ */

.intro {
  display: none;
}

.intro-active {
  overflow: hidden;
}

.intro-active .intro {
  display: block;
}

.intro-active .portfolio {
  visibility: hidden;
  opacity: 0;
}

.intro-active.intro-sortie .intro {
  opacity: 0;
  transition: opacity var(--duree-fondu) ease;
  pointer-events: none;
}

.intro-active.intro-sortie .portfolio {
  visibility: visible;
  opacity: 1;
  transition: opacity var(--duree-fondu) ease calc(var(--duree-fondu) / 3);
}

/* ============================================================
   Composants 9-slice : un cadre étiré via border-image.
   border-width reste à 0, c'est border-image-width qui dessine
   les bords ; le padding place le contenu à l'intérieur.
   ============================================================ */

.bulle,
.bulle-nom,
.btn-cadre {
  border-style: solid;
  border-width: 0;
  /* "repeat" pour du pixel art (bords texturés), "stretch" pour du vectoriel */
  border-image-repeat: var(--repetition, stretch);
}

/* Mode pixel art (pixelArt dans le thème) : pas de lissage */
.ui-pixel .bulle,
.ui-pixel .bulle-nom,
.ui-pixel .btn-cadre,
.ui-pixel .bulle-fleche,
.ui-pixel .calque {
  image-rendering: pixelated;
}

/* ============================================================
   INTRO
   ============================================================ */

.intro {
  position: fixed;
  inset: 0;
  z-index: 10;
  overflow: hidden; /* le décor zoomé déborde de l'écran */
  font-family: var(--police-texte);
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  /* Fond noir ; l'image de fond (config "fond") vient se poser par-dessus */
  background: var(--fond-image, none) center / cover no-repeat var(--fond);
}

/* --- Décor : fond + portes, zoomés ensemble comme une caméra ---
   Pendant les dialogues, on voit la salle d'entrée en entier ;
   avec .entree-porte la caméra plonge dans sa porte jusqu'au noir, puis avec
   .vue-portes on arrive dans la salle aux trois portes. Le zoom et la
   position des portes viennent de js/fond-pixel.js (valeurs par défaut
   si on utilise une image de fond). */
.decor {
  --zoom: 1;
  --zoom-x: 50%;
  --zoom-y: 60%;
  --porte-largeur: 16%;
  --porte-hauteur: 37%;
  --porte-haut: 41%;
  --porte-espacement: 28%;
  --porte-centre: 50%;
  position: absolute;
  inset: 0;
  transform: scale(var(--zoom));
  transform-origin: var(--zoom-x) var(--zoom-y);
}

/* On avance dans l'arche, de plus en plus vite (le noir remplit l'écran) */
.entree-porte .decor {
  transform: scale(calc(var(--zoom) * 8));
  transition: transform var(--duree-entree) cubic-bezier(0.55, 0, 0.9, 0.45);
}

/* De l'autre côté : nouvelle salle, la caméra finit d'avancer en douceur */
.vue-portes .decor {
  transform: none;
  animation: arrivee var(--duree-arrivee) ease-out;
}

@keyframes arrivee {
  from { transform: scale(1.12); }
  to { transform: none; }
}

/* Noir pendant la traversée de la porte */
.voile {
  position: absolute;
  inset: 0;
  background: #000;
  opacity: 0;
  pointer-events: none;
}

.entree-porte .voile {
  opacity: 1;
  transition: opacity calc(var(--duree-entree) / 2) ease-in calc(var(--duree-entree) / 2);
}

.vue-portes .voile {
  transition: opacity var(--duree-arrivee) ease-out;
}

/* Fond pixel art généré : même proportions que l'écran, agrandi sans lissage */
.fond-pixel {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}

.fond-pixel[hidden] {
  display: none;
}

/* --- Portes : un bouton posé sur chaque arche --- */
.portes {
  position: absolute;
  inset: 0;
  animation: portes-entree 300ms steps(3, end) both;
}

.portes[hidden] {
  display: none;
}

.porte {
  position: absolute;
  /* --i : -1, 0, 1… position de la porte par rapport au centre */
  left: calc(var(--porte-centre) + var(--i) * var(--porte-espacement) - var(--porte-largeur) / 2);
  top: var(--porte-haut);
  width: var(--porte-largeur);
  height: var(--porte-hauteur);
  padding: 0;
  border: 0;
  border-radius: 999px 999px 0 0; /* haut en demi-cercle, comme l'arche */
  background: none;
  color: var(--bouton-texte, var(--texte));
  font: inherit;
  cursor: pointer;
}

/* Porte active, avec une image de fond à la place du décor généré :
   l'ouverture s'éclaire en tramage. (Avec le décor généré, c'est la fumée
   dessinée par js/fond-pixel.js qui montre la porte survolée.) */
.decor:not(.avec-linteaux) .porte.est-actif {
  background:
    repeating-conic-gradient(rgba(216, 214, 228, 0.35) 0 25%, transparent 0 50%)
    0 0 / calc(var(--pixel, 4px) * 2) calc(var(--pixel, 4px) * 2);
}

/* Le tramage + la plaque suffisent à montrer le focus
   (outline transparent = anneau visible en mode contraste élevé) */
.porte:focus-visible {
  outline: 2px solid transparent;
}

/* Plaque au-dessus de la porte, dans le cadre des boutons du thème */
.porte-plaque {
  position: absolute;
  bottom: calc(100% + 12px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  height: max(36px, var(--btn-hauteur, 36px));
  padding: var(--btn-pad);
  border-style: solid;
  border-width: 0;
  border-image-source: var(--btn-normal);
  border-image-slice: var(--btn-slice) fill;
  border-image-width: var(--btn-bord);
  border-image-repeat: var(--repetition, stretch);
  white-space: nowrap;
  font-size: 1rem;
}

.porte.est-actif .porte-plaque {
  border-image-source: var(--btn-survol);
  color: var(--bulle-choix-actif, #fff);
}

.ui-pixel .porte-plaque {
  image-rendering: pixelated;
}

/* Fond généré : le nom est gravé en pixels sur la stèle dessinée par
   js/fond-pixel.js. Le libellé HTML est posé exactement dessus (variables
   en % de la porte), invisible : il sert au clic et aux lecteurs d'écran. */
.avec-linteaux .porte-plaque {
  top: var(--plaque-haut);
  bottom: auto;
  left: var(--plaque-gauche);
  transform: none;
  width: var(--plaque-largeur);
  height: var(--plaque-hauteur);
  padding: 0;
  border-image: none;
  color: transparent;
  overflow: visible;
}

/* Porte active : la stèle s'entoure de curseurs */
.avec-linteaux .porte.est-actif .porte-plaque {
  border-image: none;
  color: transparent;
}

/* Flèches pixel art (triangle 4×7 agrandi ×2) plutôt qu'un caractère :
   un glyphe n'est pas centré dans sa police, ce dessin l'est au pixel près */
.avec-linteaux .porte.est-actif .porte-plaque::before,
.avec-linteaux .porte.est-actif .porte-plaque::after {
  content: "";
  position: absolute;
  top: 50%;
  width: 8px;
  height: 14px;
  margin-top: -7px;
  background: var(--bulle-choix-actif, #fff);
  -webkit-mask: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 4 7' shape-rendering='crispEdges'><path d='M0 0h1v1h1v1h1v1h1v1h-1v1h-1v1h-1v1h-1z'/></svg>") center / 100% 100% no-repeat;
  mask: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 4 7' shape-rendering='crispEdges'><path d='M0 0h1v1h1v1h1v1h1v1h-1v1h-1v1h-1v1h-1z'/></svg>") center / 100% 100% no-repeat;
}

/* À gauche, pointe vers la stèle */
.avec-linteaux .porte.est-actif .porte-plaque::before {
  right: calc(100% + 8px);
}

/* À droite, le même triangle retourné */
.avec-linteaux .porte.est-actif .porte-plaque::after {
  left: calc(100% + 8px);
  transform: scaleX(-1);
}

@keyframes portes-entree {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* --- Encadré façon jeu en haut à gauche (même cadre que la bulle) --- */
.hud {
  position: absolute;
  top: max(16px, env(safe-area-inset-top));
  left: max(16px, env(safe-area-inset-left));
  z-index: 2;
  padding: var(--dlg-pad, 12px);
  border-style: solid;
  border-width: 0;
  border-image-source: var(--dlg-image);
  border-image-slice: var(--dlg-slice) fill;
  border-image-width: var(--dlg-bord);
  color: var(--bulle-texte, var(--texte));
  font-size: 1rem;
  line-height: 1.25;
  white-space: pre-line;
  pointer-events: none;
}

.hud[hidden] {
  display: none;
}

/* --- Boutons du haut (son + passer) --- */
.intro-controles {
  position: absolute;
  top: max(16px, env(safe-area-inset-top));
  right: max(16px, env(safe-area-inset-right));
  z-index: 2;
  display: flex;
  gap: 8px;
}

.btn-cadre {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5em;
  min-width: 44px;
  height: max(44px, var(--btn-hauteur, 44px));
  padding: var(--btn-pad);
  border-image-source: var(--btn-normal);
  border-image-slice: var(--btn-slice) fill;
  border-image-width: var(--btn-bord);
  background: none;
  color: var(--bouton-texte, var(--texte));
  font: 500 0.9rem/1 var(--police-texte);
  cursor: pointer;
}

a.btn-cadre {
  text-decoration: none;
}

.btn-cadre:hover {
  border-image-source: var(--btn-survol);
}

.btn-cadre:active {
  border-image-source: var(--btn-presse);
}

.btn-cadre kbd {
  font: 0.75rem/1 var(--police-texte);
  color: inherit;
  opacity: 0.75;
  border: 1px solid currentColor;
  border-radius: 4px;
  padding: 2px 4px;
}

.icone {
  width: 22px;
  height: 22px;
}

/* Icône du son selon l'état du bouton */
#btn-son[aria-pressed="false"] .icone-son-on,
#btn-son[aria-pressed="true"] .icone-son-off {
  display: none;
}

/* --- Scène : personnage + bulle --- */
.scene {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end; /* bulle en bas de l'écran, comme dans un jeu */
  gap: 1.5rem;
  padding: 88px 16px max(40px, env(safe-area-inset-bottom));
  overflow-y: auto; /* filet de sécurité sur les très petits écrans */
  /* La scène couvre l'écran : les clics passent au travers jusqu'aux portes */
  pointer-events: none;
}

.scene > * {
  pointer-events: auto;
}

/* --- Personnage : calques empilés, même canevas --- */
.personnage {
  position: relative;
  flex: none;
  height: clamp(150px, 34vh, 300px);
  aspect-ratio: var(--ratio-perso, 200 / 240);
  visibility: hidden;
}

.personnage[hidden] {
  display: none;
}

.personnage.est-visible {
  visibility: visible;
}

.personnage.apparait {
  animation: pop 450ms cubic-bezier(0.34, 1.56, 0.64, 1) both;
  transform-origin: 50% 90%;
}

/* Petit sautillement quand l'expression change */
.personnage.sautille {
  animation: sautille 260ms ease-out;
  transform-origin: 50% 100%;
}

.calque {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.calque[hidden] {
  display: none;
}

.calque-pupilles {
  will-change: transform;
}

/* --- Bulle de dialogue --- */
.bulle {
  position: relative;
  width: min(540px, 100%);
  transform-origin: 50% 100%;
  /* espace intérieur du thème : le texte reste dans la zone utile du cadre */
  padding: var(--dlg-pad, 24px);
  color: var(--bulle-texte, var(--texte));
  border-image-source: var(--dlg-image);
  border-image-slice: var(--dlg-slice) fill;
  border-image-width: var(--dlg-bord);
  opacity: 0;
}

.bulle.est-visible {
  opacity: 1;
}

.bulle.apparait {
  animation: bulle-entree 380ms ease-out both;
}

.bulle-nom {
  position: absolute;
  left: var(--nom-gauche, 24px);
  /* l'étiquette recouvre légèrement le haut de la bulle */
  bottom: calc(100% - var(--nom-chevauchement, 2px));
  min-width: var(--nom-min, 0);
  height: var(--nom-hauteur, 40px);
  padding: var(--nom-pad);
  padding-top: 0;
  padding-bottom: 0;
  border-image-source: var(--nom-image);
  border-image-slice: var(--nom-slice) fill;
  border-image-width: var(--nom-bord);
  /* La typo d'affichage est réservée aux noms */
  font-family: var(--police);
  font-weight: 700;
  font-size: 0.95rem;
  line-height: var(--nom-hauteur, 40px);
  text-align: center;
  color: var(--bulle-nom, var(--texte));
  /* Inclinaison facultative (à la Animal Crossing), réglée par thème */
  transform: rotate(var(--nom-inclinaison, 0deg));
  transform-origin: 0 100%;
}

.bulle-texte {
  margin: 0;
  min-height: 3em; /* deux lignes : la bulle ne change pas de taille */
  font-size: 1rem;
  font-weight: 400;
  line-height: 1.5;
  white-space: pre-line;
}

/* Avec des choix, pas besoin de réserver 2 lignes de texte */
.bulle:has(.choix:not([hidden])) .bulle-texte {
  min-height: 0;
}

/* Partie du texte pas encore "tapée" : réserve sa place pour éviter les sauts */
.bulle-texte .reste {
  visibility: hidden;
}

/* Flèche "suite" : une bande d'images (1 image = flèche fixe) */
.bulle-fleche {
  position: absolute;
  right: var(--fleche-droite, 16px);
  bottom: var(--fleche-bas, 8px);
  width: var(--fleche-largeur, 32px);
  height: var(--fleche-hauteur, 32px);
  background: var(--fleche-image) 0 0 / var(--fleche-bande, 32px) 100% no-repeat;
  visibility: hidden;
}

.bulle.attend-suite .bulle-fleche {
  visibility: visible;
  animation: clignote 1s steps(1, end) infinite;
}

/* Flèche en caractère (thème sans image de flèche) */
.fleche-texte .bulle-fleche {
  width: auto;
  height: auto;
  background: none;
  font-size: 0.75rem;
  line-height: 1;
  color: var(--bulle-texte, var(--texte));
}

/* Bande animée : on fait défiler les images par paliers */
.fleche-animee .bulle.attend-suite .bulle-fleche {
  animation: fleche-bande var(--fleche-duree, 0.66s) steps(var(--fleche-images, 4)) infinite;
}

/* --- Choix : liste de texte, curseur › devant le choix actif --- */
.choix {
  margin: 6px 0 0;
  padding: 0 0 0 1.2em;
  list-style: none;
}

.choix[hidden] {
  display: none;
}

.choix-btn {
  position: relative;
  display: block;
  width: 100%;
  min-height: 36px;
  padding: 4px 8px;
  background: none;
  border: 0;
  border-radius: 6px;
  color: var(--bulle-choix, var(--texte-doux));
  font: 500 1rem / 1.3 var(--police-texte);
  text-align: left;
  cursor: pointer;
}

.choix-btn.est-actif {
  color: var(--bulle-choix-actif, #fff);
}

/* Focus clavier : curseur ›, texte blanc et léger surlignage
   (outline transparent = anneau visible en mode contraste élevé) */
.choix-btn:focus-visible {
  outline: 2px solid transparent;
  background: var(--bulle-surlignage, rgba(255, 255, 255, 0.07));
}

.choix-btn::before {
  content: "›";
  position: absolute;
  right: 100%;
  top: 50%;
  margin-top: -0.55em;
  font-size: 1.6em;
  line-height: 1;
  color: var(--bulle-choix-actif, #fff);
  opacity: 0;
}

.choix-btn.est-actif::before {
  opacity: 1;
  animation: curseur 600ms ease-in-out infinite alternate;
}

/* ============================================================
   Animations
   ============================================================ */

@keyframes pop {
  0% { transform: scale(0.2); opacity: 0; }
  60% { transform: scale(1.08); opacity: 1; }
  100% { transform: scale(1); }
}

@keyframes sautille {
  0%, 100% { transform: translateY(0) scale(1, 1); }
  40% { transform: translateY(-6px) scale(0.98, 1.02); }
}

@keyframes bulle-entree {
  0% { opacity: 0; transform: scale(0.6, 0.4); }
  60% { opacity: 1; transform: scale(1.03, 1.05); }
  80% { transform: scale(0.99, 0.98); }
  100% { opacity: 1; transform: none; }
}

@keyframes fleche-bande {
  to { background-position: calc(-1 * var(--fleche-bande, 32px)) 0; }
}

@keyframes clignote {
  50% { opacity: 0; }
}

@keyframes curseur {
  from { transform: translateX(-3px); }
  to { transform: translateX(1px); }
}

/* Réduction des animations : ni pop, ni clignotement, ni fondu */
@media (prefers-reduced-motion: reduce) {
  :root {
    --duree-fondu: 0ms;
    --duree-entree: 0ms;
    --duree-arrivee: 0ms;
  }

  .portes,
  .vue-portes .decor {
    animation: none;
  }

  .personnage.apparait,
  .personnage.sautille,
  .bulle.apparait,
  .bulle.attend-suite .bulle-fleche,
  .fleche-animee .bulle.attend-suite .bulle-fleche,
  .choix-btn.est-actif::before {
    animation: none;
  }
}

/* ============================================================
   Mobile : bulle en bas, personnage au-dessus
   ============================================================ */

@media (max-width: 640px) {
  .scene {
    gap: 1.25rem;
    padding: 80px 16px max(16px, env(safe-area-inset-bottom));
  }

  .personnage {
    height: clamp(130px, 30vh, 230px);
  }

  .btn-cadre kbd {
    display: none;
  }

  .choix {
    padding-left: 1.1em;
  }

  .choix-btn {
    min-height: 44px; /* zone de tap confortable au doigt */
  }
}

/* Écrans très bas (téléphone en paysage) */
@media (max-height: 520px) {
  .scene {
    padding-top: 72px;
    gap: 0.75rem;
  }

  .personnage {
    height: clamp(90px, 26vh, 160px);
  }

  .bulle-texte {
    min-height: 0;
  }
}

/* ============================================================
   PORTFOLIO (provisoire)
   ============================================================ */

.portfolio {
  position: relative;
}

.site-entete {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 24px;
  padding: 12px 16px;
  background: rgba(7, 9, 13, 0.85);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid #232b38;
}

.site-nom {
  font: 700 1.25rem/1 var(--police);
  color: var(--texte);
  text-decoration: none;
}

.site-entete ul {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 20px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.site-entete a:not(.site-nom) {
  display: inline-block;
  padding: 10px 2px;
  color: var(--texte);
  text-decoration: none;
}

.site-entete a:not(.site-nom):hover {
  color: var(--accent);
}

.section {
  max-width: 960px;
  min-height: 80vh;
  margin: 0 auto;
  padding: 64px 16px;
  scroll-margin-top: 64px;
}

.section h2 {
  margin: 0 0 16px;
  font: 700 clamp(1.6rem, 1.3rem + 1.5vw, 2.4rem) / 1.2 var(--police-texte);
}

.section p {
  color: var(--texte-doux);
}

.site-pied {
  padding: 32px 16px 48px;
  text-align: center;
}

.lien-bouton {
  padding: 12px 16px;
  background: none;
  border: 1px solid #52627c;
  border-radius: 8px;
  color: var(--texte-doux);
  font: 1rem var(--police-texte);
  cursor: pointer;
}

.lien-bouton:hover {
  color: var(--texte);
  border-color: var(--accent);
}

/* ============================================================
   Thème pc98 : police bitmap, cadres nets, lignes d'écran CRT
   (attribut data-theme-ui posé dans le <head> de jeu.html)
   ============================================================ */

:root[data-theme-ui="pc98"] {
  --fond: #000;
  --texte: #e4e2ee;
  --texte-doux: #a9a5c2;
  --accent: #ffffff;
  --trait: #d8d6e4;
  --police: "DotGothic16", ui-monospace, monospace;
  --police-texte: "DotGothic16", ui-monospace, monospace;
}

/* Police bitmap : tailles multiples de 16 px pour garder des pixels nets */
[data-theme-ui="pc98"] .bulle-nom,
[data-theme-ui="pc98"] .btn-cadre,
[data-theme-ui="pc98"] .choix-btn,
[data-theme-ui="pc98"] .bulle-texte {
  font-size: 16px;
  font-weight: 400;
}

[data-theme-ui="pc98"] .btn-cadre kbd {
  font-size: 16px;
  border-radius: 0;
}

/* Bulle large et basse, comme une boîte de dialogue de jeu PC-98 */
[data-theme-ui="pc98"] .bulle {
  width: min(720px, 100%);
}

[data-theme-ui="pc98"] .bulle-texte {
  line-height: 1.75;
}

[data-theme-ui="pc98"] .choix-btn {
  border-radius: 0;
}

/* Apparition en paliers (pas de rebond, plus « ordinateur ») */
@media (prefers-reduced-motion: no-preference) {
  [data-theme-ui="pc98"] .bulle.apparait {
    animation: cadre-pixel 240ms steps(4, end) both;
  }
}

@keyframes cadre-pixel {
  from { opacity: 0; transform: scaleY(0.1); }
  to { opacity: 1; transform: none; }
}

/* Lignes d'écran CRT + vignette, par-dessus tout le site (sans bloquer les clics) */
[data-theme-ui="pc98"] body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 50;
  pointer-events: none;
  background:
    repeating-linear-gradient(to bottom, rgba(0, 0, 0, 0.2) 0 1px, transparent 1px 3px),
    radial-gradient(ellipse at center, transparent 60%, rgba(0, 0, 0, 0.55) 100%);
}

/* L'encadré du haut prend trop de place sur un téléphone */
@media (max-width: 480px) {
  [data-theme-ui="pc98"] .hud {
    display: none;
  }
}

/* --- Portfolio en style pc98 --- */
[data-theme-ui="pc98"] .site-entete {
  background: #000;
  backdrop-filter: none;
  border-bottom: 2px solid var(--trait);
}

[data-theme-ui="pc98"] .site-nom {
  font: 400 16px/1 var(--police);
}

/* Menu : le lien survolé passe en vidéo inverse, avec un curseur ▷ */
[data-theme-ui="pc98"] .site-entete a:not(.site-nom) {
  padding: 10px 6px;
}

[data-theme-ui="pc98"] .site-entete a:not(.site-nom):hover,
[data-theme-ui="pc98"] .site-entete a:not(.site-nom):focus-visible {
  background: var(--trait);
  color: #000;
}

[data-theme-ui="pc98"] .site-entete a:not(.site-nom)::before {
  content: "▷ ";
  visibility: hidden;
}

[data-theme-ui="pc98"] .site-entete a:not(.site-nom):hover::before,
[data-theme-ui="pc98"] .site-entete a:not(.site-nom):focus-visible::before {
  visibility: visible;
}

/* Sections : un panneau encadré par section */
[data-theme-ui="pc98"] .section {
  min-height: 0;
  max-width: 920px;
  margin: 48px auto;
  padding: 28px 32px;
  border-style: solid;
  border-width: 0;
  border-image: url("../assets/ui/pc98/cadre.svg") 3 fill / 6px stretch;
}

[data-theme-ui="pc98"] .section h2 {
  font: 400 32px/1.25 var(--police-texte);
}

[data-theme-ui="pc98"] .section p {
  font-size: 16px;
  line-height: 1.75;
}

[data-theme-ui="pc98"] .lien-bouton {
  padding: 12px 18px;
  border-style: solid;
  border-width: 0;
  border-radius: 0;
  border-image: url("../assets/ui/pc98/cadre.svg") 3 fill / 6px stretch;
  color: var(--texte);
  font-size: 16px;
}

[data-theme-ui="pc98"] .lien-bouton:hover {
  border-image-source: url("../assets/ui/pc98/cadre-survol.svg");
}

@media (max-width: 640px) {
  [data-theme-ui="pc98"] .section {
    margin: 24px 16px;
    padding: 20px 18px;
  }

  [data-theme-ui="pc98"] .section h2 {
    font-size: 24px;
  }
}

/* Petits écrans : les linteaux sont proches, pas de curseurs autour du nom */
@media (max-width: 480px) {
  .avec-linteaux .porte.est-actif .porte-plaque::before,
  .avec-linteaux .porte.est-actif .porte-plaque::after {
    content: none;
  }
}

/* ============================================================
   PIÈCES explorables (derrière une porte) — js/piece-projets.js
   On y entre par un fondu au noir (classe vers-piece sur <html>).
   ============================================================ */

:root {
  --duree-piece: 500ms;
  --duree-zoom: 650ms;
}

@media (prefers-reduced-motion: reduce) {
  :root {
    --duree-piece: 0ms;
    --duree-zoom: 0ms;
  }
}

.vers-piece .voile {
  opacity: 1;
  transition: opacity var(--duree-piece) ease;
}

.piece {
  position: absolute;
  inset: 0;
  z-index: 1;
  background: #000;
  opacity: 0;
  transition: opacity var(--duree-piece) ease;
  cursor: default;
}

.piece[hidden] {
  display: none;
}

.piece.est-ouverte {
  opacity: 1;
}

.piece:focus {
  outline: none;
}

/* La « caméra » : elle se rapproche du bureau quand on clique dessus */
.piece-scene {
  position: absolute;
  inset: 0;
  transform-origin: var(--objet-x, 50%) var(--objet-y, 80%);
  transition: transform var(--duree-zoom) cubic-bezier(0.45, 0, 0.2, 1), filter var(--duree-zoom) ease;
}

.zoom-objet .piece-scene {
  transform: scale(var(--objet-zoom, 2));
}

.inventaire-visible .piece-scene {
  filter: brightness(0.4);
}

.piece-fond {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}

/* Zone cliquable posée sur le bureau dessiné (contour doré au survol, dans le canevas) */
.piece-objet {
  position: absolute;
  left: var(--objet-gauche);
  top: var(--objet-haut);
  width: var(--objet-largeur);
  height: var(--objet-hauteur);
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
}

.piece-objet:focus {
  outline: none; /* le contour doré dessiné autour du bureau sert d'indicateur */
}

.piece-etiquette {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 8px);
  padding: 4px 12px;
  border-style: solid;
  border-width: 0;
  border-image: url("../assets/ui/pc98/cadre.svg") 3 fill / 6px stretch;
  color: #f2ca70;
  font: 400 16px/1.5 var(--police-texte);
  white-space: nowrap;
  transform: translateX(-50%);
  visibility: hidden;
  pointer-events: none;
}

.piece-objet:hover .piece-etiquette,
.piece-objet:focus-visible .piece-etiquette {
  visibility: visible;
}

.zoom-objet .piece-etiquette,
.zoom-objet .piece-consigne {
  visibility: hidden;
}

.piece-consigne {
  position: absolute;
  top: max(16px, env(safe-area-inset-top));
  left: 50%;
  max-width: calc(100% - 32px - 2 * 160px);
  margin: 0;
  padding: 8px 16px;
  border-style: solid;
  border-width: 0;
  border-image: url("../assets/ui/pc98/cadre.svg") 3 fill / 6px stretch;
  font: 400 16px/1.5 var(--police-texte);
  text-align: center;
  transform: translateX(-50%);
  pointer-events: none;
}

.piece-retour {
  position: absolute;
  top: max(16px, env(safe-area-inset-top));
  left: max(16px, env(safe-area-inset-left));
}

.inventaire-visible .piece-retour {
  visibility: hidden;
}

/* --- Inventaire : plein écran façon menu de jeu. Onglets en haut, grille
   de cases à gauche, le document en grand au centre, sa fiche à droite --- */
.inventaire {
  --or: #f2ca70;
  --or-pale: #ffe6a0;
  --or-sombre: #a57a2a;
  --ivoire: #f4ead2;
  --trait: rgba(242, 202, 112, 0.28);
  --rouge: #e0443a;
  position: absolute;
  inset: 0;
  z-index: 2;
  background: #0e0d12;
  color: var(--ivoire);
  font: 400 16px/1.6 var(--police-texte);
  text-align: left;
  animation: cadre-pixel 240ms steps(4, end) both;
}

.inventaire[hidden] {
  display: none;
}

.inventaire-toile {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}

.inventaire-ecran {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: minmax(280px, 380px) minmax(120px, 1fr) minmax(280px, 420px);
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas:
    "haut haut haut"
    "sac vitrine detail"
    "touches touches touches";
  gap: 20px 32px;
  padding: max(24px, env(safe-area-inset-top)) max(40px, 3vw) max(16px, env(safe-area-inset-bottom));
}

/* Cadre fin à 12 px du bord */
.inventaire-ecran::before {
  content: "";
  position: absolute;
  inset: 12px;
  border: 1px solid var(--trait);
  pointer-events: none;
}

/* Traits dorés en biais dans le coin haut gauche */
.inventaire-ecran::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: min(560px, 45vw);
  height: min(420px, 50vh);
  background:
    linear-gradient(142deg, transparent 49.8%, rgba(242, 202, 112, 0.45) 50%, transparent 50.2%),
    linear-gradient(118deg, transparent 69.8%, rgba(242, 202, 112, 0.3) 70%, transparent 70.2%),
    linear-gradient(160deg, transparent 29.8%, rgba(242, 202, 112, 0.25) 30%, transparent 30.2%);
  -webkit-mask-image: radial-gradient(circle at 0 0, #000 30%, transparent 75%);
  mask-image: radial-gradient(circle at 0 0, #000 30%, transparent 75%);
  pointer-events: none;
}

.inventaire-ecran > * {
  position: relative;
  z-index: 1;
  min-width: 0;
  min-height: 0;
}

/* ---------- Haut : titre à gauche, onglets à droite ---------- */
.inventaire-haut {
  grid-area: haut;
  display: flex;
  gap: 24px;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--trait);
  box-shadow: 0 4px 0 -3px var(--trait);
}

.inventaire-titre {
  display: flex;
  gap: 14px;
  align-items: center;
  margin: 0;
  color: var(--ivoire);
  font: 400 28px/1.2 var(--police-texte);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  text-shadow: 0 0 12px rgba(242, 202, 112, 0.35);
}

/* Sceau : un losange dans un losange */
.inventaire-sceau {
  flex: none;
  width: 22px;
  height: 22px;
  border: 2px solid var(--or);
  background: radial-gradient(var(--or) 0 3px, transparent 4px);
  transform: rotate(45deg);
  box-shadow: 0 0 10px rgba(242, 202, 112, 0.4);
}

.inventaire-onglets {
  display: flex;
  align-items: center;
}

.inventaire-onglet {
  position: relative;
  padding: 2px 14px;
  border: 1px solid transparent;
  background: none;
  color: var(--texte-doux);
  font: 400 14px/1.6 var(--police-texte);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  white-space: nowrap;
  cursor: pointer;
}

.inventaire-onglet + .inventaire-onglet::before {
  content: "";
  position: absolute;
  top: 25%;
  left: -1px;
  width: 1px;
  height: 50%;
  background: var(--texte-doux);
  opacity: 0.5;
}

.inventaire-onglet:hover {
  color: var(--ivoire);
}

.inventaire-onglet[aria-pressed="true"] {
  border-color: var(--or-sombre);
  background: linear-gradient(#3d2c12, #1d150a);
  color: var(--or-pale);
}

/* Coin replié en haut à droite de l'onglet choisi */
.inventaire-onglet[aria-pressed="true"]::after {
  content: "";
  position: absolute;
  top: -1px;
  right: -1px;
  border-style: solid;
  border-width: 0 8px 8px 0;
  border-color: transparent var(--or) transparent transparent;
}

.inventaire-onglet:focus-visible,
.inventaire-case:focus-visible,
.inventaire-fermer:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* ---------- Gauche : la sacoche ---------- */
.inventaire-sac {
  grid-area: sac;
  display: flex;
  flex-direction: column;
}

.inventaire-compteurs {
  display: flex;
  gap: 24px;
  margin: 0 0 4px;
  font-size: 14px;
  letter-spacing: 0.06em;
}

.inventaire-rayon {
  display: flex;
  align-items: center;
  margin: 0 0 12px;
  font: 400 20px/1.4 var(--police-texte);
  letter-spacing: 0.06em;
}

.inventaire-casier {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 14px;
  gap: 12px;
  flex: 0 1 auto;
  min-height: 0;
}

.inventaire-grille {
  display: grid;
  grid-template-columns: repeat(4, 72px);
  grid-auto-rows: 72px;
  gap: 12px;
  align-content: start;
  margin: 0;
  padding: 6px;
  overflow-y: auto;
  list-style: none;
  scrollbar-width: none;
}

/* Glissière décorative : un fil, une flèche à chaque bout, un losange au milieu */
.inventaire-glissiere {
  position: relative;
  background:
    linear-gradient(var(--trait), var(--trait)) center / 1px calc(100% - 28px) no-repeat;
}

.inventaire-glissiere::before,
.inventaire-glissiere::after {
  position: absolute;
  left: 0;
  width: 100%;
  color: var(--or-sombre);
  font-size: 10px;
  line-height: 14px;
  text-align: center;
}

.inventaire-glissiere::before {
  content: "▲";
  top: 0;
}

.inventaire-glissiere::after {
  content: "▼";
  bottom: 0;
}

.inventaire-pied {
  display: flex;
  justify-content: space-between;
  margin: 12px 26px 0 6px;
  font-size: 14px;
  letter-spacing: 0.06em;
}

/* Une case : fond teinté par la catégorie (la « rareté »), coin coloré,
   année en bas à droite comme la quantité d'un objet */
.inventaire-case {
  --rarete: #888;
  position: relative;
  display: grid;
  place-items: center;
  width: 72px;
  height: 72px;
  padding: 0;
  border: 2px solid color-mix(in srgb, var(--rarete) 45%, #0b0a10);
  background:
    radial-gradient(circle at 50% 40%, color-mix(in srgb, var(--rarete) 38%, #1a1622) 0%, color-mix(in srgb, var(--rarete) 14%, #0b0a10) 75%);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.6), 0 3px 0 rgba(0, 0, 0, 0.5);
  cursor: pointer;
  transition: border-color 120ms ease, box-shadow 120ms ease, transform 120ms ease;
}

.inventaire-case::before {
  content: "";
  position: absolute;
  top: -2px;
  right: -2px;
  border-style: solid;
  border-width: 0 14px 14px 0;
  border-color: transparent var(--rarete) transparent transparent;
}

.inventaire-case:hover {
  border-color: color-mix(in srgb, var(--rarete) 70%, #fff);
  transform: translateY(-2px);
}

.inventaire-case.est-choisi {
  border-color: var(--rouge);
  box-shadow: 0 0 0 1px var(--rouge), 0 0 14px rgba(224, 68, 58, 0.75), inset 0 0 10px rgba(224, 68, 58, 0.35);
}

.inventaire-case-annee {
  position: absolute;
  right: 4px;
  bottom: 0;
  color: var(--ivoire);
  font-size: 12px;
  line-height: 1.4;
  text-shadow: 1px 1px 0 #000, -1px 0 0 #000;
}

.icone-document {
  width: 48px;
  height: 48px;
  image-rendering: pixelated;
}

/* ---------- Centre : le document en grand ---------- */
.inventaire-vitrine {
  grid-area: vitrine;
  display: grid;
  place-items: center;
}

/* Ombre au sol sous le document */
.inventaire-vitrine::after {
  content: "";
  position: absolute;
  top: calc(50% + min(130px, 13vw));
  left: 50%;
  width: min(220px, 22vw);
  height: 18px;
  background: radial-gradient(closest-side, rgba(0, 0, 0, 0.65), transparent);
  transform: translateX(-50%);
  animation: ombre-flotte 4s ease-in-out infinite;
}

.icone-vitrine {
  width: min(256px, 26vw, 100%);
  height: auto;
  aspect-ratio: 1;
  filter: drop-shadow(0 0 24px rgba(255, 200, 120, 0.18)) drop-shadow(6px 10px 0 rgba(0, 0, 0, 0.45));
  animation:
    vitrine-entree 280ms steps(4, end) both,
    vitrine-flotte 4s ease-in-out 280ms infinite;
}

@keyframes vitrine-entree {
  from { opacity: 0; transform: scale(0.8); }
}

@keyframes vitrine-flotte {
  50% { transform: translateY(-8px); }
}

@keyframes ombre-flotte {
  50% { transform: translateX(-50%) scale(0.88); opacity: 0.7; }
}

/* ---------- Droite : la fiche ---------- */
.inventaire-detail {
  grid-area: detail;
  align-self: stretch;
  padding: 4px 24px;
  border-inline: 3px double var(--trait);
  overflow-y: auto;
  color: #ece0c4;
  scrollbar-color: #4a4566 transparent;
  scrollbar-width: thin;
}

.inventaire-detail p {
  margin: 0 0 12px;
}

/* Bandeau du nom : petite icône, nom en Cinzel, hachures dorées */
.detail-bandeau {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 8px 12px;
  border: 1px solid var(--or-sombre);
  background:
    repeating-linear-gradient(135deg, rgba(242, 202, 112, 0.12) 0 2px, transparent 2px 7px) right / 28% 100% no-repeat,
    linear-gradient(90deg, #2c2116, #17131c);
}

.icone-bandeau {
  flex: none;
  width: 32px;
  height: 32px;
  padding: 2px;
  border: 1px solid color-mix(in srgb, var(--rarete) 60%, #000);
  background: color-mix(in srgb, var(--rarete) 25%, #0b0a10);
  image-rendering: pixelated;
}

.detail-titre {
  flex: 1;
  margin: 0;
  color: var(--ivoire);
  font: 700 18px/1.3 "Cinzel", Georgia, serif;
  text-align: center;
}

.inventaire-detail .detail-rarete {
  display: flex;
  align-items: center;
  margin: 16px 0 4px;
  padding: 4px 12px;
  background: linear-gradient(90deg, color-mix(in srgb, var(--rarete) 22%, transparent), transparent 80%);
  color: var(--rarete);
}

.inventaire-detail .detail-rarete .fiche-losange {
  background: var(--rarete);
}

.inventaire-detail .detail-section {
  margin-bottom: 12px;
  padding: 0 12px 2px;
  border-bottom: 1px solid var(--trait);
  color: var(--texte-doux);
  letter-spacing: 0.08em;
}

.detail-etoile {
  margin-right: 6px;
  color: var(--or);
}

.inventaire-detail .detail-resume {
  color: var(--texte-doux);
}

.detail-libelle {
  color: var(--or);
}

.detail-outils,
.detail-effets {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 12px;
  padding: 0;
  list-style: none;
}

.detail-outils li {
  padding: 0 8px;
  border: 1px solid var(--or-sombre);
  background: rgba(20, 16, 12, 0.8);
}

.detail-effets {
  flex-direction: column;
  gap: 0;
  color: #7cc48f;
}

.detail-liens {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

.detail-liens .btn-cadre {
  text-decoration: none;
}

/* ---------- Bas : les touches ---------- */
.inventaire-touches {
  grid-area: touches;
  display: flex;
  gap: 24px;
  align-items: center;
  justify-content: flex-end;
  padding-top: 8px;
  border-top: 1px solid var(--trait);
  font-size: 15px;
  letter-spacing: 0.06em;
}

.inventaire-aide .fiche-touche + .fiche-touche {
  margin-left: 4px;
}

.inventaire-aide .fiche-touche:not(:first-child) {
  margin-left: 16px;
}

.inventaire-aide .fiche-touche + .fiche-touche:not(:first-child) {
  margin-left: 4px;
}

.inventaire-fermer {
  padding: 2px 4px;
  border: 0;
  background: none;
  color: var(--ivoire);
  font: inherit;
  letter-spacing: inherit;
  cursor: pointer;
}

.inventaire-fermer:hover {
  color: var(--or-pale);
}

@media (prefers-reduced-motion: reduce) {
  .icone-vitrine,
  .inventaire-vitrine::after {
    animation: none;
  }
}

/* Téléphone : tout s'empile et défile */
@media (max-width: 720px) {
  .inventaire-ecran {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: none;
    grid-auto-rows: max-content;
    grid-template-areas: "haut" "sac" "vitrine" "detail" "touches";
    gap: 16px;
    padding: max(20px, env(safe-area-inset-top)) 16px 0;
    overflow-y: auto;
  }

  .inventaire-ecran::after {
    display: none;
  }

  .inventaire-haut {
    flex-direction: column;
    gap: 12px;
    align-items: stretch;
  }

  .inventaire-titre {
    font-size: 22px;
  }

  .inventaire-onglets {
    overflow-x: auto;
    scrollbar-width: none;
  }

  .inventaire-casier {
    display: block;
  }

  .inventaire-grille {
    grid-template-columns: repeat(auto-fill, 64px);
    grid-auto-rows: 64px;
    gap: 10px;
    overflow: visible;
  }

  .inventaire-glissiere,
  .inventaire-aide,
  .inventaire-vitrine::after {
    display: none;
  }

  .inventaire-pied {
    margin-right: 6px;
  }

  .inventaire-case {
    width: 64px;
    height: 64px;
  }

  .inventaire-case .icone-document {
    width: 40px;
    height: 40px;
  }

  .icone-vitrine {
    width: 144px;
  }

  .inventaire-detail {
    padding: 0;
    border: 0;
    overflow: visible;
  }

  .inventaire-touches {
    position: sticky;
    bottom: 0;
    padding: 8px 0 max(12px, env(safe-area-inset-bottom));
    background: #0e0d12;
  }
}

@media (max-width: 720px) {
  .piece-consigne {
    top: auto;
    bottom: max(16px, env(safe-area-inset-bottom));
    max-width: calc(100% - 32px);
  }
}

/* ============================================================
   PIÈCE « whoami » — l'atelier (js/piece-whoami.js)
   Elle peint, se retourne et parle ; un clic sur elle ouvre sa fiche
   de personnage : figurine 3D (js/figurine-3d.js) + panneau déplié.
   ============================================================ */

/* Tant qu'elle ne s'est pas retournée, pas d'étiquette au survol */
.piece-objet[aria-disabled="true"] {
  cursor: default;
}

.piece-objet[aria-disabled="true"] .piece-etiquette,
.zoom-objet .whoami-bulle,
.piece-whoami.zoom-objet .piece-retour {
  visibility: hidden;
}

/* Sa réplique, dans une boîte de dialogue en bas de l'écran */
.whoami-bulle {
  position: absolute;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  width: min(720px, calc(100% - 32px));
  padding: 16px 24px;
  border-style: solid;
  border-width: 0;
  border-image: url("../assets/ui/pc98/cadre.svg") 3 fill / 6px stretch;
  font: 400 16px/1.75 var(--police-texte);
  text-align: left;
  transform: translateX(-50%);
  pointer-events: none;
}

.whoami-bulle[hidden] {
  display: none;
}

.whoami-replique {
  min-height: 3.5em;
  margin: 0;
}

@media (prefers-reduced-motion: no-preference) {
  .whoami-bulle.est-visible .whoami-replique {
    animation: cadre-pixel 240ms steps(4, end) both;
  }
}

/* Éclair doré quand on clique sur elle (pendant que la caméra s'approche) */
.eclair {
  position: absolute;
  inset: 0;
  z-index: 2;
  background: radial-gradient(circle at var(--objet-x, 50%) var(--objet-y, 60%), #fff6d8 0, rgba(242, 202, 112, 0.7) 18%, rgba(242, 202, 112, 0) 60%);
  opacity: 0;
  pointer-events: none;
}

@media (prefers-reduced-motion: no-preference) {
  .fiche-eclair .eclair {
    animation: eclair 800ms steps(6, end) 250ms both;
  }
}

@keyframes eclair {
  0% { opacity: 0; }
  45% { opacity: 1; }
  100% { opacity: 0; }
}

/* --- La fiche : l'atelier flouté derrière (ou une image, --fiche-image,
   depuis le champ « fond » de js/whoami.js), figurine, interface
   façon écran de personnage de jeu --- */
.fiche {
  position: absolute;
  inset: 0;
  z-index: 3;
  overflow: hidden;
  background:
    linear-gradient(rgba(8, 6, 12, 0.8), rgba(8, 6, 12, 0.8)),
    var(--fiche-image, none) center / cover no-repeat;
  -webkit-backdrop-filter: blur(6px) brightness(0.6);
  backdrop-filter: blur(6px) brightness(0.6);
  opacity: 0;
  transition: opacity 400ms ease;
}

.fiche[hidden] {
  display: none;
}

.fiche.est-ouverte {
  opacity: 1;
}

.fiche-3d {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  cursor: grab;
  touch-action: none;
}

.fiche-3d:active {
  cursor: grabbing;
}

/* Sans WebGL : une carte (sprite de face / de dos) qui fait un tour */
.fiche-repli {
  display: none;
}

.sans-3d .fiche-3d {
  display: none;
}

.sans-3d .fiche-repli {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  perspective: 800px;
  transition: transform 900ms cubic-bezier(0.45, 0, 0.2, 1);
}

.sans-3d.fiche-deployee .fiche-repli {
  transform: translateY(-6vh) scale(1.3);
}

.fiche-carte {
  position: relative;
  width: 160px;
  height: 320px;
  transform-style: preserve-3d;
}

@media (prefers-reduced-motion: no-preference) {
  .fiche-carte {
    animation: carte-tour 1.6s cubic-bezier(0.2, 0.7, 0.2, 1) both;
  }
}

@keyframes carte-tour {
  from { transform: scale(0.1) rotateY(0); }
  to { transform: scale(1) rotateY(360deg); }
}

.fiche-carte canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  backface-visibility: hidden;
}

.fiche-carte-derriere {
  transform: rotateY(180deg);
}

/* Fondu au noir : le bas du buste disparaît, les côtés s'assombrissent
   pour que les colonnes restent lisibles */
.fiche-fondu {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(5, 3, 8, 0.7) 0%, rgba(5, 3, 8, 0) 14%, rgba(5, 3, 8, 0) 50%, rgba(5, 3, 8, 0.88) 72%, #050308 86%),
    linear-gradient(90deg, rgba(5, 3, 8, 0.92) 0%, rgba(5, 3, 8, 0) 34%, rgba(5, 3, 8, 0) 66%, rgba(5, 3, 8, 0.92) 100%);
  pointer-events: none;
}

.fiche-aide {
  display: none;
}

.fiche-fermer {
  position: absolute;
  top: max(20px, env(safe-area-inset-top));
  left: max(32px, 3vw);
  z-index: 1;
}

/* Couleurs de l'écran de personnage */
.fiche {
  --or: #f2ca70;
  --or-pale: #ffe6a0;
  --or-sombre: #a57a2a;
  --ivoire: #f4ead2;
  --trait: rgba(242, 202, 112, 0.28);
}

/* ---------- L'interface : une grille par-dessus toute la fiche ----------
   Le centre reste vide : on y attrape la figurine pour la faire tourner */
.fiche-panneau {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr) minmax(280px, 360px);
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  grid-template-areas:
    "haut haut haut"
    "gauche . droite"
    "bas bas bas"
    "touches touches touches";
  gap: 20px 40px;
  padding: max(20px, env(safe-area-inset-top)) max(32px, 3vw) max(12px, env(safe-area-inset-bottom));
  color: var(--texte);
  font: 400 16px/1.6 var(--police-texte);
  text-align: left;
  visibility: hidden;
  pointer-events: none;
  transition: visibility 0s linear 600ms;
}

.fiche-deployee .fiche-panneau {
  visibility: visible;
  transition: visibility 0s;
}

.fiche-panneau > * {
  pointer-events: auto;
}

/* Équerres dorées aux quatre coins de l'écran */
.fiche-panneau::before {
  content: "";
  position: absolute;
  inset: 8px;
  background:
    linear-gradient(var(--or), var(--or)) top left / 28px 2px no-repeat,
    linear-gradient(var(--or), var(--or)) top left / 2px 28px no-repeat,
    linear-gradient(var(--or), var(--or)) top right / 28px 2px no-repeat,
    linear-gradient(var(--or), var(--or)) top right / 2px 28px no-repeat,
    linear-gradient(var(--or), var(--or)) bottom left / 28px 2px no-repeat,
    linear-gradient(var(--or), var(--or)) bottom left / 2px 28px no-repeat,
    linear-gradient(var(--or), var(--or)) bottom right / 28px 2px no-repeat,
    linear-gradient(var(--or), var(--or)) bottom right / 2px 28px no-repeat;
  opacity: 0.6;
  pointer-events: none;
}

/* Chaque bloc arrive à son tour, depuis son bord */
.fiche-bloc {
  opacity: 0;
  transition: opacity 350ms ease, transform 550ms cubic-bezier(0.2, 0.8, 0.2, 1);
  transition-delay: calc(300ms + var(--i, 0) * 120ms);
}

.fiche-haut { transform: translateY(-16px); }
.fiche-gauche { transform: translateX(-40px); }
.fiche-droite { transform: translateX(40px); }
.fiche-bas,
.fiche-touches { transform: translateY(24px); }

.fiche-deployee .fiche-bloc {
  opacity: 1;
  transform: none;
}

/* Petits éléments communs */
.fiche-losange {
  display: inline-block;
  flex: none;
  width: 6px;
  height: 6px;
  margin-right: 8px;
  background: var(--or);
  vertical-align: 0.15em;
  transform: rotate(45deg);
}

.fiche-libelle {
  color: var(--or);
}

.fiche-touche {
  display: inline-block;
  min-width: 24px;
  padding: 0 6px;
  border: 2px solid #4a4566;
  border-bottom-width: 4px;
  background: #15121e;
  color: var(--ivoire);
  font: 400 12px/18px var(--police-texte);
  text-align: center;
}

.fiche-panneau p {
  margin: 0 0 8px;
}

/* ---------- Haut : onglets au centre, niveau et rang à droite ---------- */
.fiche-haut {
  grid-area: haut;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  min-height: 48px;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--trait);
}

.fiche-navigation {
  grid-column: 2;
  display: flex;
  gap: 12px;
  align-items: center;
}

.fiche-onglets {
  display: flex;
  gap: 4px;
}

.fiche-onglet {
  position: relative;
  padding: 4px 16px;
  border: 0;
  background: none;
  color: var(--texte-doux);
  font: 400 16px/1.5 var(--police-texte);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  cursor: pointer;
}

.fiche-onglet:hover {
  color: var(--ivoire);
}

/* L'onglet choisi : doré, losange au-dessus, trait qui touche la ligne */
.fiche-onglet[aria-selected="true"] {
  color: var(--or);
}

.fiche-onglet[aria-selected="true"]::before {
  content: "";
  position: absolute;
  top: -8px;
  left: 50%;
  width: 8px;
  height: 8px;
  background: var(--or);
  box-shadow: 0 0 8px rgba(242, 202, 112, 0.8);
  transform: translateX(-50%) rotate(45deg);
}

.fiche-onglet[aria-selected="true"]::after {
  content: "";
  position: absolute;
  right: 12px;
  bottom: -14px;
  left: 12px;
  height: 2px;
  background: var(--or);
}

.fiche-onglet:focus-visible,
.fiche-case:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.fiche-etat {
  grid-column: 3;
  display: flex;
  gap: 16px;
  align-items: center;
  justify-self: end;
}

.fiche-niveau {
  display: flex;
  gap: 12px;
  align-items: center;
}

/* Insigne de niveau : un losange doré, le chiffre au centre */
.fiche-insigne {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 2px solid var(--or);
  background: linear-gradient(135deg, #5a4113, #1e1608);
  transform: rotate(45deg);
}

.fiche-insigne span {
  color: var(--ivoire);
  font: 700 14px/1 "Cinzel", Georgia, serif;
  transform: rotate(-45deg);
}

.fiche-exp {
  display: grid;
  grid-template-columns: auto 120px;
  gap: 0 8px;
  align-items: center;
  font-size: 12px;
}

.fiche-exp-valeur {
  grid-column: 2;
  color: var(--texte-doux);
  text-align: right;
}

.fiche-rang {
  padding: 0 10px;
  border: 2px solid var(--or);
  background: linear-gradient(#5a4113, #2b1e0b);
  color: var(--or-pale);
  font: 400 20px/1.5 var(--police-texte);
  letter-spacing: 0.08em;
  box-shadow: 0 0 12px rgba(242, 202, 112, 0.25);
}

/* ---------- Colonnes ---------- */
.fiche-gauche,
.fiche-droite {
  align-self: start;
  max-height: 100%;
  overflow: hidden auto;
  scrollbar-color: #4a4566 transparent;
  scrollbar-width: thin;
}

/* --- Gauche : identité et onglet choisi --- */
.fiche-gauche {
  grid-area: gauche;
}

.fiche-entete {
  display: flex;
  gap: 16px;
  align-items: center;
  margin-bottom: 12px;
}

.fiche-portrait {
  flex: none;
  width: 56px;
  height: 56px;
  padding: 6px;
  border-style: solid;
  border-width: 0;
  border-image: url("../assets/ui/pc98/cadre.svg") 3 fill / 6px stretch;
  background: #1a1426;
  box-sizing: content-box;
  image-rendering: pixelated;
}

.fiche-titres {
  flex: 1;
  min-width: 0;
}

.fiche-panneau .fiche-classe {
  display: flex;
  align-items: center;
  margin: 0;
  color: var(--or);
  font-size: 14px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* Cinzel : réservée aux noms et aux grands chiffres */
.fiche-nom {
  margin: 2px 0 4px;
  color: var(--ivoire);
  font: 700 36px/1.1 "Cinzel", Georgia, serif;
  text-shadow: 0 0 16px rgba(242, 202, 112, 0.4);
}

.fiche-panneau .fiche-etoiles {
  display: flex;
  gap: 4px;
  margin: 0;
  color: var(--or);
}

.fiche-etoiles svg {
  width: 14px;
  height: 14px;
  shape-rendering: crispEdges;
}

.fiche-panneau .fiche-devise {
  margin: 0 0 16px;
  padding-left: 12px;
  border-left: 2px solid var(--trait);
  color: var(--texte-doux);
  font-style: italic;
}

/* Le contenu des onglets, dans un cadre PC-98 */
.fiche-page {
  padding: 16px;
  border-style: solid;
  border-width: 0;
  border-image: url("../assets/ui/pc98/cadre.svg") 3 fill / 6px stretch;
  background: rgba(11, 10, 16, 0.85);
}

.fiche-page[hidden] {
  display: none;
}

@media (prefers-reduced-motion: no-preference) {
  .fiche-page:not([hidden]) {
    animation: page-entree 300ms cubic-bezier(0.2, 0.8, 0.2, 1);
  }
}

@keyframes page-entree {
  from { opacity: 0; transform: translateX(-12px); }
}

/* Profil : libellé à gauche, valeur à droite, pointillés entre les lignes */
.fiche-profil {
  display: grid;
  grid-template-columns: auto 1fr;
  margin: 0;
}

.fiche-profil dt,
.fiche-profil dd {
  padding: 6px 0;
  border-bottom: 1px dashed #3a3650;
}

.fiche-profil dt {
  color: var(--texte-doux);
}

.fiche-profil dd {
  margin: 0;
  color: var(--ivoire);
  text-align: right;
}

.fiche-profil dt:last-of-type,
.fiche-profil dd:last-of-type {
  border-bottom: 0;
}

/* Quêtes : une frise verticale, un losange par étape */
.fiche-quetes {
  position: relative;
  margin: 0;
  padding: 0 0 0 20px;
  list-style: none;
}

.fiche-quetes::before {
  content: "";
  position: absolute;
  top: 8px;
  bottom: 8px;
  left: 3px;
  width: 2px;
  background: var(--trait);
}

.fiche-quetes li {
  position: relative;
  display: grid;
  padding: 0 0 12px;
}

.fiche-quetes li::before {
  content: "";
  position: absolute;
  top: 8px;
  left: -20px;
  width: 8px;
  height: 8px;
  background: var(--or);
  transform: rotate(45deg);
}

.fiche-annee {
  color: var(--or);
  font-size: 14px;
}

.fiche-quete {
  color: var(--ivoire);
}

.fiche-lieu {
  color: var(--texte-doux);
  font-size: 14px;
}

/* Barres segmentées, qui se remplissent en paliers */
.fiche-barre {
  position: relative;
  display: block;
  height: 10px;
  border: 2px solid #3a3650;
  background: #15121e;
}

.fiche-barre i {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 0;
  background: repeating-linear-gradient(90deg, var(--or) 0 6px, var(--or-sombre) 6px 8px);
  transition: width 900ms steps(12, end);
  transition-delay: calc(650ms + var(--i, 0) * 120ms);
}

.fiche-barre-exp i {
  background: repeating-linear-gradient(90deg, #7fa8e0 0 6px, #3d5f8f 6px 8px);
}

.fiche-deployee .fiche-barre i {
  width: var(--v);
}

.fiche-sous-titre {
  display: flex;
  gap: 12px;
  align-items: center;
  margin: 0 0 12px;
  color: var(--or);
  font: 400 14px/1.5 var(--police-texte);
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

/* Un filet doré après le titre */
.fiche-sous-titre::after {
  content: "";
  flex: 1;
  height: 2px;
  background: linear-gradient(90deg, var(--trait), transparent);
}

/* --- Droite : l'équipement --- */
.fiche-droite {
  grid-area: droite;
}

/* Une case d'inventaire : cadre pixel, fond doré sombre, lueur au survol */
.fiche-case {
  position: relative;
  display: grid;
  place-items: center;
  margin: 0;
  padding: 0;
  border: 2px solid #4a4566;
  background: radial-gradient(circle at 50% 30%, #5a4113 0%, #2b1e0b 60%, #140e05 100%);
  color: var(--or-pale);
  cursor: pointer;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

.fiche-case:hover,
.fiche-case.est-choisie,
.fiche-case[aria-pressed="true"] {
  border-color: var(--or);
  box-shadow: 0 0 10px rgba(242, 202, 112, 0.45), inset 0 0 8px rgba(242, 202, 112, 0.25);
}

/* Tenues : une ligne, le nom à gauche, les petites cases à droite */
.fiche-tenues {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.fiche-panneau .fiche-tenues-libelle {
  display: grid;
  margin: 0;
  font-size: 14px;
  line-height: 1.4;
}

.fiche-tenue-nom {
  color: var(--ivoire);
}

.fiche-tenues-liste {
  display: flex;
  gap: 6px;
}

.fiche-tenue {
  width: 44px;
  height: 44px;
  overflow: hidden;
}

.fiche-tenue img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: grayscale(0.7) brightness(0.6);
  transition: filter 150ms ease;
}

.fiche-tenue:hover img,
.fiche-tenue[aria-pressed="true"] img {
  filter: none;
}

.sans-3d .fiche-tenues {
  display: none;
}

/* Compétences : grille de cases, niveau dans le coin */
.fiche-competences {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.fiche-objet {
  width: 100%;
  aspect-ratio: 1;
  padding: 4px;
}

.fiche-objet-nom {
  font: 400 12px/1.25 var(--police-texte);
  text-align: center;
  -webkit-hyphens: auto;
  hyphens: auto;
}

/* La fiche (et l'inventaire des projets) sont des fenêtres modales : les
   boutons du haut de l'intro (son, passer) les recouvriraient, on les cache
   tant qu'elles sont ouvertes */
body:has(.fiche.est-ouverte) .intro-controles,
body:has(.inventaire:not([hidden])) .intro-controles {
  display: none;
}

.fiche-objet-niveau {
  position: absolute;
  top: 2px;
  left: 4px;
  color: var(--ivoire);
  font: 400 11px/1 var(--police-texte);
}

/* Fiche de l'objet survolé, comme la description d'un objet de jeu */
.fiche-detail {
  margin-top: 12px;
  padding: 12px 16px;
  border-style: solid;
  border-width: 0;
  border-image: url("../assets/ui/pc98/cadre.svg") 3 fill / 6px stretch;
  background: rgba(11, 10, 16, 0.85);
}

.fiche-panneau .fiche-detail-nom {
  margin: 0;
  color: var(--ivoire);
  font: 700 20px/1.3 "Cinzel", Georgia, serif;
}

.fiche-panneau .fiche-detail-type {
  display: flex;
  align-items: center;
  margin: 0;
  color: var(--or);
  font-size: 14px;
}

.fiche-panneau .fiche-detail-texte {
  margin: 8px 0 0;
  color: var(--texte-doux);
  font-size: 14px;
}

.fiche-liens {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

.fiche-liens .btn-cadre {
  text-decoration: none;
}

/* ---------- Bas : les attributs en gros chiffres ---------- */
.fiche-bas {
  grid-area: bas;
  padding-top: 12px;
  border-top: 2px solid var(--trait);
}

.fiche-attributs {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  margin: 0;
  padding: 0;
  list-style: none;
}

.fiche-attributs li {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 0;
  align-items: center;
  min-width: 150px;
  padding: 0 24px;
}

/* Séparateur vertical entre deux attributs */
.fiche-attributs li + li {
  border-left: 1px solid var(--trait);
}

.fiche-attribut {
  color: var(--texte-doux);
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.fiche-nombre {
  grid-column: 1 / -1;
  color: var(--ivoire);
  font: 700 32px/1.1 "Cinzel", Georgia, serif;
  text-align: center;
  text-shadow: 0 0 12px rgba(242, 202, 112, 0.35);
}

.fiche-attributs .fiche-barre {
  grid-column: 1 / -1;
  height: 6px;
  border-width: 1px;
}

/* ---------- Tout en bas : les touches ---------- */
.fiche-touches {
  grid-area: touches;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 24px;
  justify-content: center;
  color: var(--texte-doux);
  font-size: 12px;
}

.fiche-rappel {
  display: inline-flex;
  gap: 6px;
  align-items: center;
}

/* Sans souris, les rappels de touches n'ont pas de sens */
@media (hover: none), (pointer: coarse) {
  .fiche-touches,
  .fiche-navigation .fiche-touche {
    display: none;
  }
}

/* Écran moyen : colonnes plus étroites */
@media (max-width: 1200px) {
  .fiche-panneau {
    grid-template-columns: minmax(240px, 300px) minmax(0, 1fr) minmax(240px, 300px);
    gap: 16px 24px;
  }

  .fiche-nom {
    font-size: 28px;
  }

  .fiche-attributs li {
    min-width: 120px;
    padding: 0 16px;
  }

  .fiche-nombre {
    font-size: 26px;
  }

  .fiche-exp {
    display: none;
  }
}

/* Écran étroit ou vertical : elle en haut, l'interface défile en dessous
   (même condition que cadrage() dans js/piece-whoami.js) */
@media (max-width: 720px), (orientation: portrait) {
  .sans-3d.fiche-deployee .fiche-repli {
    transform: translateY(-25vh) scale(0.6);
  }

  .fiche-fondu {
    background: linear-gradient(180deg, rgba(5, 3, 8, 0) 40%, rgba(5, 3, 8, 0.9) 62%, #050308 75%);
  }

  .fiche-panneau::before,
  .fiche-touches {
    display: none;
  }

  /* Tout l'écran défile ; on laisse de la place à elle en haut */
  .fiche-panneau {
    display: flex;
    flex-direction: column;
    gap: 24px;
    padding: 58vh 16px max(24px, env(safe-area-inset-bottom));
    overflow: hidden auto;
    pointer-events: auto;
  }

  .fiche-panneau > * {
    flex: none;
  }

  /* Ordre : niveau et onglets, identité et onglet, attributs, équipement */
  .fiche-haut {
    display: flex;
    flex-direction: column-reverse;
    gap: 16px;
    align-items: center;
  }

  .fiche-exp {
    display: grid;
  }

  .fiche-gauche,
  .fiche-droite {
    max-height: none;
    overflow: visible;
  }

  .fiche-droite {
    order: 1;
  }

  .fiche-onglet {
    padding: 4px 8px;
    font-size: 14px;
  }

  .fiche-onglet[aria-selected="true"]::after {
    bottom: -2px;
  }

  .fiche-nom {
    font-size: 26px;
  }

  .fiche-portrait {
    width: 40px;
    height: 40px;
  }

  .fiche-attributs {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px 0;
  }

  .fiche-attributs li {
    min-width: 0;
    padding: 0 12px;
  }

  .fiche-attributs li + li {
    border-left: 0;
  }

  .fiche-nombre {
    font-size: 24px;
  }

  .whoami-bulle {
    padding: 12px 16px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .fiche,
  .fiche-panneau,
  .fiche-bloc,
  .fiche-barre i,
  .sans-3d .fiche-repli {
    transition: none !important;
  }
}

@media (max-width: 720px) {
  /* La bulle occupe le bas : la consigne de l'atelier reste en haut */
  .piece-whoami .piece-consigne {
    top: calc(max(16px, env(safe-area-inset-top)) + 56px);
    bottom: auto;
  }
}

/* ============================================================
   PIÈCE « Contact » — le salon (js/piece-contact.js)
   Elle somnole près du feu ; le secrétaire ouvre une lettre sur
   parchemin qui se plie, se scelle à la cire et s'envole.
   ============================================================ */

/* Les objets n'ont pas tous la même taille : l'étiquette ne déborde pas */
.piece-contact .piece-etiquette {
  z-index: 1;
}

.piece-contact.zoom-objet .piece-retour {
  visibility: hidden;
}

/* --- La lettre --- */
.lettre {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-items: center;
  padding: 72px 16px 24px;
  overflow: hidden;
  animation: cadre-pixel 240ms steps(4, end) both;
}

.lettre[hidden] {
  display: none;
}

.lettre-pile {
  position: relative;
  width: min(560px, 100%);
  max-height: 100%;
  display: grid;
  transition: transform 600ms steps(6, end);
}

.lettre-papier {
  max-height: calc(100vh - 96px);
  max-height: calc(100dvh - 96px);
  overflow: auto;
  padding: 32px 40px;
  /* Parchemin : bords brunis, ombre portée en escalier, liseré sombre */
  background:
    radial-gradient(ellipse at center, rgba(0, 0, 0, 0) 55%, rgba(94, 60, 24, 0.35) 100%),
    #d9c599;
  box-shadow:
    inset 0 0 0 2px #8b7350,
    0 0 0 2px #3a2d1b,
    6px 6px 0 2px #000;
  color: #2b1d10;
  font: 400 16px/1.75 var(--police-texte);
  text-align: left;
  transform-origin: 50% 50%;
  transition: transform 450ms steps(3, end), filter 450ms steps(3, end);
}

.lettre-titre {
  margin: 0 0 16px;
  color: #6e1820;
  font: 400 24px/1.3 var(--police-texte);
  letter-spacing: 0.04em;
}

.lettre-ligne {
  display: grid;
  gap: 4px;
  margin-bottom: 16px;
}

.lettre-salutation {
  font-size: 18px;
}

.lettre input,
.lettre textarea {
  width: 100%;
  margin: 0;
  padding: 2px 4px;
  border: 0;
  border-bottom: 2px dashed #8b7350;
  border-radius: 0;
  background: transparent;
  color: #1a1008;
  font: inherit;
}

/* Papier ligné pour le message */
.lettre textarea {
  min-height: calc(1.75em * 6);
  border: 0;
  background: repeating-linear-gradient(transparent 0 calc(1.75em - 2px), rgba(94, 75, 47, 0.45) calc(1.75em - 2px) 1.75em);
  line-height: 1.75em;
  resize: vertical;
}

.lettre input::placeholder,
.lettre textarea::placeholder {
  color: #6f5d40;
  opacity: 1;
}

.lettre input:focus-visible,
.lettre textarea:focus-visible {
  outline: 3px solid #6e1820;
  outline-offset: 2px;
}

.lettre [aria-invalid="true"] {
  border-bottom-color: #8a1e2c;
  background-color: rgba(138, 30, 44, 0.1);
}

.lettre-piege {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
}

.lettre-erreur {
  min-height: 1.75em;
  margin: 0 0 8px;
  color: #8a1e2c;
}

.lettre-erreur:empty {
  min-height: 0;
}

.lettre-envoyer {
  justify-self: end;
}

.lettre-formulaire {
  display: grid;
}

.lettre-fermer {
  position: absolute;
  top: max(16px, env(safe-area-inset-top));
  left: max(16px, env(safe-area-inset-left));
}

/* Le cachet de cire : tombe sur la lettre pliée, en gros pixels */
.lettre-cachet {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 64px;
  height: 64px;
  opacity: 0;
  transform: translate(-50%, -50%) scale(2.5);
  transition: opacity 300ms steps(3, end), transform 300ms steps(3, end);
  pointer-events: none;
}

.lettre canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}

/* 1. La lettre se plie */
.est-pliee .lettre-papier {
  transform: scaleY(0.3);
  filter: brightness(0.85);
}

.est-pliee .lettre-papier > * {
  visibility: hidden;
}

/* 2. Le cachet tombe dessus */
.est-scellee .lettre-cachet {
  opacity: 1;
  transform: translate(-50%, -50%);
}

/* 3. Elle s'envole */
.est-envoyee .lettre-pile {
  transform: translate(40vw, -120vh) rotate(-14deg);
}

.est-pliee .lettre-fermer {
  visibility: hidden;
}

/* Accusé d'envoi : une enveloppe scellée */
.lettre-fin {
  display: grid;
  justify-items: center;
  gap: 8px;
  text-align: center;
}

.lettre-fin:not([hidden]) {
  animation: cadre-pixel 240ms steps(4, end) both;
}

.lettre-fin[hidden] {
  display: none;
}

.lettre-fin p {
  margin: 0 0 8px;
}

.lettre-enveloppe {
  position: relative;
  display: grid;
  place-items: center;
  width: 120px;
  height: 76px;
  margin-bottom: 8px;
  background:
    linear-gradient(to bottom right, transparent calc(50% - 1px), #8b7350 calc(50% - 1px) calc(50% + 1px), transparent calc(50% + 1px)) left top / 50% 70% no-repeat,
    linear-gradient(to bottom left, transparent calc(50% - 1px), #8b7350 calc(50% - 1px) calc(50% + 1px), transparent calc(50% + 1px)) right top / 50% 70% no-repeat,
    #cdb88a;
  box-shadow: inset 0 0 0 2px #5e4b2f, 4px 4px 0 #3a2d1b;
}

.lettre-enveloppe canvas {
  width: 32px;
  height: 32px;
  margin-top: 8px;
}

@media (max-width: 720px) {
  .lettre-papier {
    padding: 20px;
  }

  .lettre-titre {
    font-size: 20px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .lettre-pile,
  .lettre-papier,
  .lettre-cachet {
    transition: none;
  }
}
