/* =========================================================================
   LE CABINET DES MOTS — habillage
   -------------------------------------------------------------------------
   Le vert #336148 est le drap du cabinet : il ne raconte rien lui-même, il
   fait taire tout ce qui n'est pas la carte. Un seul accent, le laiton, pour
   les filets et les chiffres. Allura n'apparaît qu'une fois, sur la marque.
   ========================================================================= */

:root {
  --vert:        #336148;
  --vert-fonce:  #24452f;
  --vert-clair:  #3e7355;
  --creme:       #f2e9d8;
  --creme-doux:  #cdd8ce;
  --laiton:      #c8a45c;
  --encre:       #16241b;

  --barre-h: 3.25rem;
  /* hauteur occupée par tout ce qui n'est pas la carte : barre, indice,
     rangée de notes et marges. Sert à calculer la largeur de la carte. */
  --hors-carte: 11.6rem;
  --rayon: 10px;
  --transition: 240ms cubic-bezier(.22,.61,.36,1);
}

* { box-sizing: border-box; }

/* Un display: flex ou grid dans une règle de classe l'emporte sinon sur
   l'attribut hidden, et l'élément reste visible. */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  overscroll-behavior: none;
}

body {
  background: var(--vert);
  color: var(--creme);
  font-family: "Lustria", Georgia, serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

img { max-width: 100%; display: block; }

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid var(--laiton);
  outline-offset: 3px;
}

/* ══ Barre haute ═════════════════════════════════════════════════════════ */

.barre {
  flex: 0 0 auto;
  height: var(--barre-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  padding: 0 .9rem;
}

.barre__marque {
  font-family: "Allura", cursive;
  font-size: 1.55rem;
  line-height: 1;
  color: var(--creme);
  padding-bottom: .18em;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

/* Un seul bouton, qui affiche toujours la destination et jamais l'endroit
   où l'on se trouve déjà. */
.barre__bascule {
  flex: 0 0 auto;
  font-family: "Simonetta", serif;
  font-size: .7rem;
  letter-spacing: .13em;
  text-transform: uppercase;
  white-space: nowrap;
  color: var(--laiton);
  opacity: .85;
  padding: .55rem .1rem;
  transition: opacity var(--transition);
}
.barre__bascule:hover { opacity: 1; }

/* ══ Filet de progression ════════════════════════════════════════════════ */

.filet {
  flex: 0 0 auto;
  height: 1px;
  background: rgba(242,233,216,.16);
  position: relative;
}
.filet i {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  background: var(--laiton);
  box-shadow: 0 0 6px rgba(200,164,92,.6);
  transition: width 420ms cubic-bezier(.22,.61,.36,1);
}

/* ══ Scène et vues ═══════════════════════════════════════════════════════ */

#scene {
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
}

.vue {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
}
.vue--active { display: flex; }

/* ══ La carte ════════════════════════════════════════════════════════════ */

.pile {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .7rem;
  padding: .9rem .9rem 0;
}

/* Les deux faces sont en position absolue : la carte n'a donc aucun contenu
   pour se dimensionner. On lui donne une largeur, et le ratio fait le reste.
   La largeur est le plus petit des deux : ce que la fenêtre permet en
   largeur, et ce que la hauteur restante permet une fois retiré le reste de
   l'écran (barre, indice, boutons, marges). */
.carte {
  flex: 0 0 auto;
  width: 100%;
  max-width: min(100%, calc((100dvh - var(--hors-carte)) * 874 / 1240));
  aspect-ratio: 874 / 1240;
  padding: 0;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 480ms cubic-bezier(.22,.61,.36,1);
  border-radius: var(--rayon);
}

/* Repli pour les navigateurs sans dvh */
@supports not (height: 100dvh) {
  .carte { max-width: min(100%, calc((100vh - var(--hors-carte)) * 874 / 1240)); }
}
.carte.est-retournee { transform: rotateY(180deg); }

/* petit rebond au moment où la carte arrive */
.carte.entre { animation: entree 380ms cubic-bezier(.22,.61,.36,1); }
@keyframes entree {
  from { opacity: 0; transform: translateY(14px) scale(.97); }
  to   { opacity: 1; transform: none; }
}

.carte__face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: var(--rayon);
  overflow: hidden;
  background: var(--vert-fonce);
  box-shadow:
    0 1px 0 rgba(242,233,216,.14),
    0 14px 34px rgba(0,0,0,.42);
}
.carte__face--verso { transform: rotateY(180deg); }

.carte__face img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.pile__indice {
  flex: 0 0 auto;
  margin: 0;
  font-family: "Simonetta", serif;
  font-style: italic;
  font-size: .82rem;
  color: var(--creme-doux);
  opacity: .55;
  transition: opacity var(--transition);
  min-height: 1.2em;
}
.pile__indice[hidden] { display: block; opacity: 0; }

/* ══ Les quatre notes ════════════════════════════════════════════════════ */

/* La rangée occupe toujours sa place, même avant le retournement : sans cela
   la carte changerait de taille au moment du flip. */
.notes {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: .4rem;
  padding: .8rem .9rem calc(.9rem + env(safe-area-inset-bottom));
  transition: opacity 200ms ease;
}
.notes--masquees {
  opacity: 0;
  pointer-events: none;
}
.notes:not(.notes--masquees) {
  animation: monte 260ms cubic-bezier(.22,.61,.36,1);
}
@keyframes monte {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}

.note {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .18rem;
  padding: .62rem .2rem .5rem;
  border-radius: 8px;
  background: rgba(242,233,216,.07);
  border: 1px solid rgba(242,233,216,.14);
  transition: background var(--transition), transform 90ms ease;
}
.note:active { transform: scale(.96); }

.note__mot {
  font-family: "Simonetta", serif;
  font-size: .84rem;
  letter-spacing: .02em;
  line-height: 1.1;
}
.note__delai {
  font-size: .62rem;
  letter-spacing: .04em;
  color: var(--creme-doux);
  opacity: .58;
  line-height: 1.1;
}

/* la seule couleur du jeu : l'échec est plus sombre, la réussite plus claire */
.note--1 { background: rgba(0,0,0,.22); }
.note--4 { background: rgba(200,164,92,.14); border-color: rgba(200,164,92,.34); }

@media (hover: hover) {
  .note:hover { background: rgba(242,233,216,.14); }
  .note--4:hover { background: rgba(200,164,92,.22); }
}

/* ══ Fin de session ══════════════════════════════════════════════════════ */

.vue--fin { align-items: center; justify-content: center; padding: 1.5rem; }

.fin { text-align: center; max-width: 22rem; }

.fin__plume {
  width: 74px;
  margin: 0 auto 1.1rem;
  border-radius: 50%;
  opacity: .9;
}

.fin__titre {
  font-family: "Simonetta", serif;
  font-weight: 400;
  font-size: 1.55rem;
  margin: 0 0 .7rem;
  letter-spacing: .01em;
}

.fin__texte {
  margin: 0 0 .4rem;
  line-height: 1.6;
  color: var(--creme-doux);
}

.fin__prochaine {
  margin: 0 0 1.6rem;
  font-family: "Simonetta", serif;
  font-style: italic;
  font-size: .9rem;
  color: var(--laiton);
  opacity: .9;
}

.bouton {
  font-family: "Simonetta", serif;
  font-size: .78rem;
  letter-spacing: .14em;
  text-transform: uppercase;
  padding: .8rem 1.5rem;
  border: 1px solid rgba(200,164,92,.5);
  border-radius: 999px;
  color: var(--laiton);
  transition: background var(--transition);
}
.bouton:active, .bouton:hover { background: rgba(200,164,92,.12); }

/* ══ Collection ══════════════════════════════════════════════════════════ */

.vue--collection { overflow-y: auto; -webkit-overflow-scrolling: touch; }

.chiffres {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  padding: 1.2rem .9rem 1rem;
  text-align: center;
}
.chiffre b {
  display: block;
  font-size: 1.75rem;
  font-weight: 400;
  color: var(--laiton);
  line-height: 1;
}
.chiffre small {
  display: block;
  margin-top: .35rem;
  font-family: "Simonetta", serif;
  font-size: .66rem;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--creme-doux);
  opacity: .6;
  line-height: 1.25;
}

.grille {
  list-style: none;
  margin: 0;
  padding: 0 .9rem 1.5rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
  gap: .7rem;
}

.tuile {
  position: relative;
  width: 100%;
  padding: 0;
  aspect-ratio: 874 / 1240;
  border-radius: 7px;
  overflow: hidden;
  background: var(--vert-fonce);
  box-shadow: 0 5px 14px rgba(0,0,0,.3);
  transition: transform 120ms ease;
}
.tuile:active { transform: scale(.97); }
.tuile img { width: 100%; height: 100%; object-fit: cover; }

/* trois barres de maturité en pied de tuile : neuve, en cours, ancrée */
.tuile__etat {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 3px;
  background: rgba(0,0,0,.45);
}
.tuile__etat i {
  display: block;
  height: 100%;
  background: var(--laiton);
  transition: width var(--transition);
}

.tuile__due {
  position: absolute;
  top: 6px; right: 6px;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--laiton);
  box-shadow: 0 0 0 2px rgba(0,0,0,.35);
}

.reglages { padding: 0 .9rem 2.5rem; text-align: center; }

.lien-discret {
  font-family: "Simonetta", serif;
  font-size: .74rem;
  letter-spacing: .06em;
  color: var(--creme-doux);
  opacity: .45;
  text-decoration: underline;
  text-underline-offset: 3px;
  padding: .5rem;
}
.lien-discret:hover { opacity: .8; }

/* ══ Fiche plein écran ═══════════════════════════════════════════════════ */

.fiche {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(20,38,28,.94);
  backdrop-filter: blur(6px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .8rem;
  padding: 3rem 1rem 1.4rem;
  animation: apparait 200ms ease;
}
@keyframes apparait { from { opacity: 0; } to { opacity: 1; } }

.fiche__fermer {
  position: absolute;
  top: calc(.5rem + env(safe-area-inset-top));
  right: .9rem;
  font-size: 2rem;
  line-height: 1;
  width: 2.4rem; height: 2.4rem;
  color: var(--creme-doux);
  opacity: .7;
}

.fiche__cadre {
  max-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .7rem;
  min-height: 0;
}
.fiche__cadre img {
  max-height: calc(100% - 2rem);
  width: auto;
  border-radius: var(--rayon);
  box-shadow: 0 14px 34px rgba(0,0,0,.5);
}
.fiche__bascule {
  margin: 0;
  font-family: "Simonetta", serif;
  font-style: italic;
  font-size: .8rem;
  color: var(--creme-doux);
  opacity: .5;
}

/* ══ Écran vide ══════════════════════════════════════════════════════════ */

.vide {
  grid-column: 1 / -1;
  text-align: center;
  padding: 2.5rem 1rem;
  font-family: "Simonetta", serif;
  font-style: italic;
  color: var(--creme-doux);
  opacity: .6;
  line-height: 1.7;
}

/* ══ Écrans larges ═══════════════════════════════════════════════════════ */

@media (min-width: 640px) {
  .barre__marque { font-size: 1.9rem; }
  .barre__bascule { font-size: .76rem; }
  .notes { max-width: 34rem; margin: 0 auto; }
  .note__mot { font-size: .92rem; }
  .note__delai { font-size: .68rem; }
  .grille { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); max-width: 60rem; margin: 0 auto; }
  .chiffres { max-width: 34rem; margin: 0 auto; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
  .carte.est-retournee { transform: none; }
  .carte.est-retournee .carte__face--recto { visibility: hidden; }
  .carte.est-retournee .carte__face--verso { transform: none; }
}
