:root {
  --fond: #0c1a15;
  --texte: #f4eddf;
  --doux: #a7b6ab;
  --ligne: rgba(244, 237, 223, 0.13);
  --carte: rgba(244, 237, 223, 0.05);
  --rouge: #c8372d;
  --rouge-fonce: #8c2118;
  --or: #e2b65a;
  --or-fonce: #b98c35;
  --papier: #fbf6ea;
  --papier-2: #f1e8d4;
  --encre: #a12a1f;
  --erreur: #ff9b8f;
  --bw: min(300px, 80vw);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }

body {
  min-height: 100vh;
  min-height: 100dvh;
  background:
    radial-gradient(120% 70% at 50% -10%, #1d3c30 0%, rgba(12, 26, 21, 0) 70%),
    var(--fond);
  background-attachment: fixed;
  color: var(--texte);
  font: 16px/1.5 "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

#neige { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 0; }

.app { position: relative; z-index: 1; max-width: 560px; margin: 0 auto; padding: 20px 16px 48px; }

.entete { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.entete h1 { font: 700 28px/1.1 "Fraunces", Georgia, serif; margin: 0; }
.entete h1 small {
  display: block; margin-bottom: 6px;
  font: 600 11px/1 "Inter", sans-serif; letter-spacing: 0.16em; text-transform: uppercase; color: var(--or);
}

h2 { font: 600 26px/1.2 "Fraunces", Georgia, serif; margin: 0 0 6px; text-align: center; }
.sous { color: var(--doux); text-align: center; margin: 0 0 18px; }
.bonjour { text-align: center; color: var(--doux); margin: 18px 0 4px; }
.bonjour strong { color: var(--texte); font-weight: 600; }
.note { text-align: center; color: var(--doux); font-size: 13px; margin-top: 18px; }
.erreur { min-height: 1.5em; color: var(--erreur); text-align: center; font-size: 14px; margin: 6px 0 10px; }

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

/* ---------- Boutons ---------- */
.btn {
  appearance: none; border: 0; border-radius: 999px; padding: 14px 26px;
  font: 600 16px/1.1 "Inter", sans-serif; cursor: pointer;
  transition: transform 0.15s, background 0.2s, opacity 0.2s, border-color 0.2s;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.55; cursor: default; transform: none; }
.btn-principal {
  background: var(--rouge); color: #fff7ec;
  box-shadow: 0 12px 26px -12px rgba(200, 55, 45, 0.9), inset 0 1px 0 rgba(255, 255, 255, 0.22);
}
.btn-principal:hover:not(:disabled) { background: #d6443a; }
.btn-discret { background: var(--carte); color: var(--texte); border: 1px solid var(--ligne); }
.btn-discret:hover:not(:disabled) { border-color: rgba(226, 182, 90, 0.55); }
.btn-danger { background: transparent; color: var(--erreur); border: 1px solid rgba(255, 130, 115, 0.45); }
.btn-danger:hover:not(:disabled) { background: rgba(255, 130, 115, 0.08); }
.mini { padding: 8px 12px; font-size: 13px; }

.lien {
  appearance: none; background: none; border: 0; padding: 6px 0; cursor: pointer;
  color: var(--doux); font: 500 14px/1.2 "Inter", sans-serif;
}
.lien:hover { color: var(--texte); }

.actions { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.actions .btn { width: min(100%, 300px); }

/* ---------- Accueil ---------- */
.boite-accueil { transform: scale(0.8); transform-origin: 50% 0; margin: -8px auto -26px; }
.noms { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 16px; }
@media (min-width: 520px) { .noms { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.nom {
  appearance: none; display: flex; flex-direction: column; align-items: flex-start; gap: 4px;
  min-height: 66px; padding: 14px 14px 12px; text-align: left; cursor: pointer;
  background: var(--carte); color: var(--texte);
  border: 1px solid var(--ligne); border-radius: 14px;
  transition: background 0.2s, border-color 0.2s, transform 0.15s;
}
.nom:hover { background: rgba(244, 237, 223, 0.09); border-color: rgba(226, 182, 90, 0.55); }
.nom:active { transform: scale(0.98); }
.nom-texte { font: 600 18px/1.2 "Fraunces", Georgia, serif; overflow-wrap: anywhere; }
.nom-statut { font-size: 12px; line-height: 1.2; color: var(--doux); min-height: 1.2em; }
.nom.fait .nom-statut { color: var(--or); }

/* ---------- Code ---------- */
#code-retour { display: block; }
.points { display: flex; justify-content: center; gap: 18px; margin: 20px 0 6px; }
.points span {
  width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--doux);
  transition: background 0.15s, border-color 0.15s, transform 0.15s;
}
.points span.plein { background: var(--or); border-color: var(--or); transform: scale(1.12); }
.points.secoue { animation: secoueX 0.4s; }
@keyframes secoueX {
  20% { transform: translateX(-9px); } 40% { transform: translateX(9px); }
  60% { transform: translateX(-5px); } 80% { transform: translateX(5px); }
}
.pave { display: grid; grid-template-columns: repeat(3, 74px); gap: 14px; justify-content: center; }
.touche {
  width: 74px; height: 74px; border-radius: 50%; cursor: pointer;
  display: grid; place-items: center;
  border: 1px solid var(--ligne); background: var(--carte); color: var(--texte);
  font: 500 28px/1 "Inter", sans-serif;
  transition: background 0.12s, transform 0.12s;
}
.touche:hover { background: rgba(244, 237, 223, 0.09); }
.touche:active { background: rgba(244, 237, 223, 0.18); transform: scale(0.95); }
.touche.vide { visibility: hidden; }
.touche.effacer { background: transparent; border-color: transparent; color: var(--doux); }
.pave.occupe { opacity: 0.5; pointer-events: none; }

/* ---------- Boîte ---------- */
.boite { position: relative; width: 240px; height: 206px; margin: 0 auto; }
.boite-fond {
  position: absolute; left: 8px; right: 8px; top: 60px; height: 24px;
  background: linear-gradient(#3e0c09, #6a1610);
  border-radius: 10px 10px 0 0;
}
.boite-papiers { position: absolute; inset: 0; }
.papier {
  position: absolute; width: 64px; height: 32px; border-radius: 3px;
  background: linear-gradient(180deg, #fffaf0, var(--papier-2));
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);
  transform: rotate(var(--r));
}
.papier::after {
  content: ""; position: absolute; left: 50%; top: 50%; width: 11px; height: 11px; margin: -5.5px 0 0 -5.5px;
  border-radius: 50%; background: radial-gradient(circle at 35% 30%, #e0574b, #a8261c 65%);
}
.boite-face {
  position: absolute; left: 0; right: 0; top: 78px; bottom: 0; overflow: hidden;
  background: linear-gradient(160deg, #db4a3e 0%, var(--rouge) 38%, var(--rouge-fonce) 100%);
  border-radius: 6px 6px 16px 16px;
  box-shadow: 0 22px 34px -14px rgba(0, 0, 0, 0.7), inset 0 2px 0 rgba(255, 255, 255, 0.2);
}
.ruban-v, .ruban-h { position: absolute; }
.ruban-v { top: 0; bottom: 0; left: 50%; width: 30px; margin-left: -15px; background: linear-gradient(90deg, var(--or-fonce), var(--or) 50%, var(--or-fonce)); }
.ruban-h { left: 0; right: 0; top: 44%; height: 26px; background: linear-gradient(180deg, var(--or-fonce), var(--or) 50%, var(--or-fonce)); }
.etiquette {
  position: absolute; left: 50%; top: 44%; transform: translate(-50%, -18%) rotate(-4deg);
  padding: 8px 16px 6px; border-radius: 4px; white-space: nowrap;
  background: var(--papier); color: var(--encre); font: 700 23px/1 "Caveat", cursive;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}
.boite.secoue { animation: secoue 0.7s ease-in-out; }
@keyframes secoue {
  0%, 100% { transform: none; } 15% { transform: rotate(-4deg); } 30% { transform: rotate(4deg); }
  45% { transform: rotate(-3deg); } 60% { transform: rotate(3deg); } 80% { transform: rotate(-1.5deg); }
}

/* ---------- Scène de pioche ---------- */
.scene { position: relative; height: calc(var(--bw) + 20px); min-height: 250px; margin: 4px 0 18px; }
.scene .boite { position: absolute; left: 50%; top: 50%; margin: -103px 0 0 -120px; }

.billet {
  position: absolute; left: 50%; top: 50%; z-index: 2;
  width: var(--bw); height: var(--bw);
  margin: calc(var(--bw) / -2) 0 0 calc(var(--bw) / -2);
  cursor: pointer; outline-offset: 8px;
}
.feuille {
  position: relative; width: 100%; height: 100%;
  perspective: 1100px; transform-style: preserve-3d;
  transition: transform 0.9s cubic-bezier(0.3, 0.7, 0.2, 1);
}
.billet.plie .feuille { transform: translateY(-25%); }
.feuille-bas, .face {
  background:
    repeating-linear-gradient(180deg, transparent 0 29px, rgba(70, 100, 150, 0.1) 29px 30px),
    linear-gradient(180deg, var(--papier), var(--papier-2));
}
.feuille-bas {
  position: absolute; left: 0; right: 0; bottom: 0; height: 50%;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 2px;
  padding: calc(var(--bw) * 0.02) 12px 0;
  border-radius: 0 0 8px 8px;
  box-shadow: 0 24px 40px -18px rgba(0, 0, 0, 0.8);
  transform: translateZ(-1px);
}
.feuille-haut {
  position: absolute; left: 0; right: 0; top: 0; height: 50%;
  transform-origin: 50% 100%; transform-style: preserve-3d;
  transition: transform 0.9s cubic-bezier(0.3, 0.7, 0.2, 1);
}
.billet.plie .feuille-haut { transform: rotateX(-180deg); }
.face { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.face-avant {
  display: flex; align-items: flex-end; justify-content: center; padding-bottom: 14px;
  border-radius: 8px 8px 0 0;
  box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.06);
}
.face-dos {
  transform: rotateX(180deg);
  display: grid; place-items: center;
  border-radius: 0 0 8px 8px;
  box-shadow: 0 24px 40px -18px rgba(0, 0, 0, 0.8), inset 0 6px 10px -6px rgba(0, 0, 0, 0.18);
}
.billet-label { font: 600 12px/1.2 "Inter", sans-serif; letter-spacing: 0.14em; text-transform: uppercase; color: #7a6a55; text-align: center; }
.billet-nom {
  font: 700 calc(var(--bw) * 0.2)/1.05 "Caveat", cursive; color: var(--encre);
  max-width: 100%; overflow-wrap: anywhere; text-align: center;
}
.billet-chut { font: 600 20px/1 "Caveat", cursive; color: #8c7b63; }
.sceau {
  width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center;
  background: radial-gradient(circle at 35% 30%, #e0574b, #a8261c 62%, #7d1a13);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3), inset 0 -3px 5px rgba(0, 0, 0, 0.25);
  color: #f3cfa6;
}

/* ---------- Admin ---------- */
.liste-admin { display: flex; flex-direction: column; gap: 8px; margin: 14px 0 24px; }
.ligne-admin {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; background: var(--carte); border: 1px solid var(--ligne); border-radius: 12px;
}
.ligne-admin .infos { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.ligne-admin .n { font: 600 17px/1.2 "Fraunces", Georgia, serif; overflow-wrap: anywhere; }
.etats { display: flex; flex-wrap: wrap; gap: 6px; }
.pastille { font-size: 12px; line-height: 1; padding: 5px 8px; border-radius: 999px; background: rgba(244, 237, 223, 0.07); color: var(--doux); white-space: nowrap; }
.pastille.ok { background: rgba(226, 182, 90, 0.16); color: var(--or); }
.ligne-admin .btn { flex: none; }

/* ---------- Fenêtre de confirmation, message ---------- */
.modale {
  position: fixed; inset: 0; z-index: 10; padding: 16px;
  display: grid; place-items: center;
  background: rgba(4, 10, 8, 0.72); backdrop-filter: blur(4px);
}
.modale-boite { width: 100%; max-width: 380px; padding: 22px; border-radius: 18px; background: #15302a; border: 1px solid var(--ligne); }
.modale-boite p { margin: 0 0 18px; font-size: 16px; }
.modale-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
.modale-actions .btn { padding: 12px 20px; }

.toast {
  position: fixed; left: 16px; right: 16px; bottom: 24px; z-index: 20;
  width: fit-content; margin: 0 auto;
  transform: translateY(20px); opacity: 0; pointer-events: none;
  padding: 10px 18px; border-radius: 999px; text-align: center;
  background: var(--texte); color: #1a1a1a; font-size: 14px;
  transition: opacity 0.25s, transform 0.25s;
}
.toast.visible { opacity: 1; transform: none; }

@media (prefers-reduced-motion: reduce) {
  .feuille, .feuille-haut { transition-duration: 0.01s; }
  .boite.secoue, .points.secoue { animation: none; }
}
