:root {
  --nuit: #2a070b;
  --vin: #4d0f16;
  --rouge: #c81e2b;
  --rouge-vif: #e0312f;
  --orange: #ff7a1a;
  --ambre: #ffb347;
  --or: #f2b632;
  --vert: #1d7a47;
  --vert-clair: #2a9d5c;
  --creme: #fff6ea;
  --encre: #3a0d12;
  --gris: #8a6a63;
  --titre: "Fraunces", Georgia, serif;
  --texte: "Manrope", system-ui, -apple-system, sans-serif;
  --or-clair: #ffd98a;
  --corail: #ff8f7a;
  --menthe: #7be0a4;
  --verre: rgba(24, 7, 10, .74);
  --ligne: rgba(255, 236, 210, .14);
  --doux: rgba(255, 246, 234, .62);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --clavier: 0px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { margin: 0; min-height: 100%; }

body {
  font-family: var(--texte);
  color: var(--creme);
  background:
    radial-gradient(120% 60% at 50% 22%, #8a2216 0%, #5a1214 38%, var(--nuit) 78%) fixed,
    var(--nuit);
  overflow-x: hidden;
  overscroll-behavior-y: none;
}

/* La 3D occupe le haut de page (même hauteur que .hero) et défile nativement avec elle */
#scene {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 94vh;
  height: 94svh;
  min-height: 540px;
  display: block;
  z-index: 0;
}

.app {
  position: relative;
  z-index: 1;
  max-width: 560px;
  margin: 0 auto;
  padding: 0 16px calc(28px + var(--safe-b));
  transition: opacity .5s ease, transform .5s ease;
}
body.fete .app { opacity: 0; transform: translateY(30px); pointer-events: none; }

/* ---------- Haut ---------- */
.hero {
  position: relative;
  height: 94vh;
  height: 94svh;
  min-height: 540px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding-top: calc(22px + var(--safe-t));
  padding-bottom: 10px;
  cursor: pointer;
  user-select: none;
}
body.sans-3d .hero::after {
  content: "🎁";
  position: absolute;
  left: 50%; top: 46%;
  transform: translate(-50%, -50%);
  font-size: 130px;
}
.titre { text-align: center; }
.sur {
  margin: 0;
  font-size: 12px;
  letter-spacing: .22em;
  text-transform: uppercase;
  font-weight: 800;
  color: var(--ambre);
}
h1 {
  margin: 2px 0 0;
  font-family: var(--titre);
  font-style: italic;
  font-weight: 600;
  font-size: 52px;
  line-height: 1;
  color: var(--creme);
  text-shadow: 0 2px 18px rgba(255, 122, 26, .55);
}
.bas-hero { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.compte {
  margin: 0;
  padding: 7px 16px;
  border-radius: 999px;
  background: rgba(255, 246, 234, .12);
  border: 1px solid rgba(255, 179, 71, .35);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  font-weight: 800;
  font-size: 14px;
  color: var(--creme);
}
.compte b { color: var(--ambre); }
.progres { display: flex; gap: 3px; justify-content: center; }
.progres i {
  width: 8px; height: 8px; border-radius: 50%;
  background: rgba(255, 246, 234, .18);
}
.progres i.ok { background: var(--or); box-shadow: 0 0 8px var(--ambre); }
.defile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  margin-top: 4px;
  padding: 6px 14px;
  border: 0;
  background: none;
  color: var(--doux);
  font: 800 11px var(--texte);
  letter-spacing: .22em;
  text-transform: uppercase;
  cursor: pointer;
}
.defile svg { width: 22px; height: 22px; animation: rebond 1.8s ease-in-out infinite; }
@keyframes rebond { 50% { transform: translateY(5px); } }

/* ---------- Grille ---------- */
.intitule {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 18px 2px 14px;
  font: 800 12px var(--texte);
  letter-spacing: .22em;
  text-transform: uppercase;
  color: var(--ambre);
  scroll-margin-top: calc(16px + var(--safe-t));
}
.intitule::after {
  content: "";
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, rgba(255, 179, 71, .5), transparent);
}
.grille {
  /* largeur d'une colonne : rangées carrées */
  --col: calc((min(100vw, 560px) - 32px - 30px) / 4);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(10, var(--col));
  grid-template-areas:
    "a a b c"
    "d e e c"
    "d f f g"
    "h f f g"
    "i i j k"
    "l m m k"
    "n n o p"
    "n n q r"
    "s t u u"
    "v t w x";
  gap: 10px;
  perspective: 900px;
}
.case {
  --papier: var(--rouge);
  --ruban: var(--vert);
  --ruban-l: clamp(9px, calc(var(--col) * .16), 18px);
  position: relative;
  border: 0;
  padding: 0;
  border-radius: 14px;
  background:
    radial-gradient(circle at 25% 30%, rgba(255,255,255,.16) 0 2px, transparent 3px) 0 0 / 16px 16px,
    linear-gradient(160deg, rgba(255,255,255,.18), rgba(0,0,0,.18)),
    var(--papier);
  box-shadow:
    inset 0 -5px 0 rgba(0,0,0,.2),
    inset 0 1px 0 rgba(255,255,255,.25),
    0 10px 20px -6px rgba(0,0,0,.55);
  color: var(--encre);
  font: inherit;
  cursor: pointer;
  overflow: hidden;
  transform-style: preserve-3d;
  transition: transform .18s ease, filter .3s ease;
  animation: pop .55s cubic-bezier(.2, 1.4, .4, 1) both;
  animation-delay: calc(var(--i) * 28ms);
}
.case::before, .case::after {
  content: "";
  position: absolute;
  background: linear-gradient(90deg, rgba(0,0,0,.12), rgba(255,255,255,.18) 50%, rgba(0,0,0,.12)), var(--ruban);
}
.case::before { left: 50%; top: 0; bottom: 0; width: var(--ruban-l); transform: translateX(-50%); }
.case::after { top: 50%; left: 0; right: 0; height: var(--ruban-l); transform: translateY(-50%);
  background: linear-gradient(180deg, rgba(0,0,0,.12), rgba(255,255,255,.18) 50%, rgba(0,0,0,.12)), var(--ruban); }
.case .num {
  position: absolute;
  z-index: 2;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  width: calc(var(--col) * .46);
  height: calc(var(--col) * .46);
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--creme);
  box-shadow: 0 3px 8px rgba(0,0,0,.35), inset 0 -2px 0 rgba(0,0,0,.08);
  font-family: var(--titre);
  font-weight: 800;
  font-size: calc(var(--col) * .25);
  color: var(--rouge);
}
.case:active { transform: scale(.93) rotateX(10deg); }

.case.t-l .num, .case.t-h .num { width: calc(var(--col) * .54); height: calc(var(--col) * .54); font-size: calc(var(--col) * .28); }
.case.t-g { --ruban-l: clamp(14px, calc(var(--col) * .22), 26px); border-radius: 18px; }
.case.t-g .num { width: calc(var(--col) * .78); height: calc(var(--col) * .78); font-size: calc(var(--col) * .4); }

.c0 { --papier: var(--rouge); --ruban: var(--vert-clair); }
.c1 { --papier: var(--orange); --ruban: var(--rouge); }
.c2 { --papier: var(--vert); --ruban: var(--or); }
.c3 { --papier: #e9a527; --ruban: var(--rouge); }
.c4 { --papier: #f3e2c8; --ruban: var(--rouge-vif); }
.c5 { --papier: #8d1420; --ruban: var(--or); }

.case.verrou { filter: saturate(.55) brightness(.62); }
.case.verrou .num::after {
  content: "❄";
  position: absolute;
  top: -6px; right: -6px;
  font-size: 12px;
  color: #fff;
  text-shadow: 0 0 4px rgba(0,0,0,.6);
}
.case.jour-j { animation: pop .55s cubic-bezier(.2, 1.4, .4, 1) both, lueur 1.8s ease-in-out infinite alternate; animation-delay: calc(var(--i) * 28ms), 0s; }
.case.jour-j .num { background: #fff; color: var(--orange); }

/* Case ouverte : boîte vide vue de dessus, drapeau du code, coche dorée */
.case.ouverte {
  background:
    radial-gradient(120% 90% at 50% 0%, rgba(255, 179, 71, .24), transparent 62%),
    linear-gradient(180deg, #2e0c11, #170407);
  box-shadow:
    inset 0 12px 24px rgba(0, 0, 0, .7),
    inset 0 0 0 1.5px rgba(255, 217, 138, .55),
    0 6px 14px -8px rgba(0, 0, 0, .6);
}
.case.ouverte::before { display: none; }
.case.ouverte::after {
  content: "✓";
  top: 7px; right: 7px; left: auto;
  width: 20px; height: 20px;
  transform: none;
  border-radius: 50%;
  display: grid; place-items: center;
  background: linear-gradient(150deg, var(--or-clair), var(--or));
  color: var(--encre);
  font: 800 12px/1 var(--texte);
  box-shadow: 0 2px 6px rgba(0, 0, 0, .4);
}
.case.ouverte .num {
  left: 9px; top: 6px;
  transform: none;
  width: auto; height: auto;
  background: none;
  box-shadow: none;
  font-size: calc(var(--col) * .2);
  color: var(--or-clair);
}
.case.ouverte .drapeau {
  position: absolute;
  left: 50%; top: 52%;
  transform: translate(-50%, -50%);
  font-size: calc(var(--col) * .4);
  line-height: 1;
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, .5));
}
.case.ouverte.t-l .drapeau, .case.ouverte.t-h .drapeau { top: 45%; font-size: calc(var(--col) * .46); }
.case.ouverte.t-h .drapeau { top: 44%; }
.case.ouverte.t-g .drapeau { top: 46%; font-size: calc(var(--col) * .8); }
.code-case {
  position: absolute;
  left: 4px; right: 4px; bottom: 6px;
  text-align: center;
  font: 800 calc(var(--col) * .12) / 1.35 var(--texte);
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--or-clair);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.case.ouverte.t-g .code-case { font-size: calc(var(--col) * .17); bottom: 16px; }
.case.ouverte:active { transform: scale(.96); }

@keyframes pop {
  from { opacity: 0; transform: translateY(18px) scale(.7) rotateX(30deg); }
}
@keyframes lueur {
  from { box-shadow: inset 0 -5px 0 rgba(0,0,0,.2), 0 0 0 2px rgba(255,214,120,.7), 0 0 14px 2px rgba(255,140,40,.6); }
  to { box-shadow: inset 0 -5px 0 rgba(0,0,0,.2), 0 0 0 3px rgba(255,236,170,.95), 0 0 30px 8px rgba(255,140,40,.85); }
}

.pied {
  margin-top: 26px;
  text-align: center;
  font-family: var(--titre);
  font-style: italic;
  color: rgba(255, 246, 234, .55);
  font-size: 14px;
}

/* ---------- Vues Jour et découverte ---------- */
.voile {
  position: fixed; inset: 0; z-index: 5;
  background: rgba(14, 3, 5, .5);
  opacity: 0; pointer-events: none;
  transition: opacity .35s ease;
}
.voile.on { opacity: 1; pointer-events: auto; }
body.fete .voile { background: transparent; }

.feuille, .bravo {
  position: fixed;
  z-index: 6;
  left: 0; right: 0;
  bottom: 0;
  margin: 0 auto;
  max-width: 560px;
  max-height: calc(100svh - 24px);
  overflow-x: hidden;
  overflow-y: auto;
  padding: 24px 22px calc(26px + var(--safe-b) + var(--clavier));
  border-radius: 30px 30px 0 0;
  border: 1px solid var(--ligne);
  border-bottom: 0;
  background:
    radial-gradient(90% 60% at 100% 0%, rgba(200, 30, 43, .4), transparent 70%),
    radial-gradient(80% 55% at 0% 0%, rgba(29, 122, 71, .34), transparent 70%),
    var(--verre);
  -webkit-backdrop-filter: blur(24px) saturate(1.4);
  backdrop-filter: blur(24px) saturate(1.4);
  color: var(--creme);
  box-shadow: 0 -24px 60px rgba(0, 0, 0, .5);
  transform: translateY(110%);
  transition: transform .5s cubic-bezier(.2, .9, .25, 1.03), padding-bottom .2s ease;
}
.feuille.on, .bravo.on { transform: translateY(0); }
body.saisie .feuille {
  top: 0;
  max-height: none;
  border-radius: 0;
  border: 0;
  padding-top: calc(24px + var(--safe-t));
}
body.saisie .feuille::before, body.saisie .feuille::after { display: none; }
/* poignée */
.feuille::before, .bravo::before {
  content: "";
  position: absolute;
  top: 9px; left: 50%;
  width: 40px; height: 4px; border-radius: 4px;
  transform: translateX(-50%);
  background: rgba(255, 246, 234, .22);
}
/* filet doré */
.feuille::after, .bravo::after {
  content: "";
  position: absolute;
  top: 0; left: 14%; right: 14%;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 217, 138, .85), transparent);
}
.feuille > *, .bravo > * { position: relative; z-index: 1; }

/* étincelles */
.feuille .etincelles, .bravo .etincelles { position: absolute; inset: 0; z-index: 0; pointer-events: none; }
.etincelles::before, .etincelles::after {
  content: "✦";
  position: absolute;
  color: var(--or-clair);
  animation: scintille 2.8s ease-in-out infinite;
}
.etincelles::before { top: 20px; left: 30%; font-size: 10px; }
.etincelles::after { top: 58px; left: 62%; font-size: 7px; animation-delay: 1.3s; }
@keyframes scintille {
  0%, 100% { opacity: .12; transform: scale(.7); }
  50% { opacity: .9; transform: scale(1.15); }
}

/* grand numéro du jour, en filigrane */
.feuille .grand-num {
  position: absolute;
  z-index: 0;
  top: 34px; right: -8px;
  font: 800 150px/1 var(--titre);
  letter-spacing: -.04em;
  color: transparent;
  -webkit-text-stroke: 1.5px rgba(255, 217, 138, .26);
  pointer-events: none;
  user-select: none;
}

.f-tete { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.jour {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  font: 800 11px var(--texte);
  letter-spacing: .24em;
  text-transform: uppercase;
  color: var(--or-clair);
}
.jour::before { content: "✦"; color: var(--or); font-size: 12px; letter-spacing: 0; }
.fermer {
  width: 38px; height: 38px;
  border-radius: 50%;
  border: 1px solid var(--ligne);
  background: rgba(255, 255, 255, .06);
  color: var(--creme);
  font-size: 22px; line-height: 1;
  cursor: pointer;
}
.feuille h2 {
  margin: 2px 0 26px;
  font: 600 32px/1.1 var(--titre);
  color: var(--creme);
}
.etiquette {
  margin: 0 0 10px;
  font: 800 11px var(--texte);
  letter-spacing: .22em;
  text-transform: uppercase;
  color: var(--doux);
}
.enigme {
  margin: 0 0 26px;
  padding: 2px 0 2px 16px;
  border-left: 2px solid var(--or);
  font: italic 400 22px/1.45 var(--titre);
  color: var(--creme);
}
.degrade {
  height: 150px;
  margin: 0 0 26px;
  border-radius: 20px;
  border: 1px solid var(--ligne);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .08), 0 14px 30px -14px rgba(0, 0, 0, .6);
}
.degrade[hidden] { display: none; }
.champ {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 6px 6px 18px;
  border-radius: 18px;
  border: 1px solid rgba(255, 236, 210, .2);
  background: rgba(255, 255, 255, .07);
  transition: border-color .2s, box-shadow .2s;
}
.champ:focus-within { border-color: rgba(255, 217, 138, .75); box-shadow: 0 0 0 4px rgba(242, 182, 50, .14); }
.champ input {
  flex: 1;
  min-width: 0;
  padding: 12px 0;
  border: 0;
  background: transparent;
  font: 600 18px var(--texte);
  color: var(--creme);
  outline: none;
}
.champ input::placeholder { color: rgba(255, 246, 234, .38); }
.envoi {
  flex: none;
  display: grid; place-items: center;
  width: 48px; height: 48px;
  border: 0;
  border-radius: 14px;
  background: linear-gradient(150deg, var(--or-clair), var(--or) 55%, #d98a10);
  color: var(--encre);
  box-shadow: 0 8px 20px -8px rgba(242, 182, 50, .85);
  cursor: pointer;
}
.envoi svg { width: 22px; height: 22px; }
.envoi:active, .btn:active { transform: translateY(1px) scale(.97); }
.retour { min-height: 22px; margin: 12px 4px 0; font-weight: 700; color: var(--corail); }
.retour.ok { color: var(--menthe); }
.secoue { animation: secoue .45s ease; }
@keyframes secoue {
  20%, 60% { transform: translateX(-8px); }
  40%, 80% { transform: translateX(8px); }
}

/* découverte */
.bravo { text-align: center; padding-top: 30px; }
.bravo h2 {
  margin: 8px 0 20px;
  font: italic 600 38px/1 var(--titre);
  color: var(--creme);
}
.anneau {
  position: relative;
  width: 172px; height: 172px;
  margin: 0 auto 20px;
  border-radius: 50%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: radial-gradient(circle, rgba(242, 182, 50, .18), rgba(242, 182, 50, 0) 70%);
}
.anneau::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  padding: 2px;
  background: conic-gradient(from 0deg, var(--or-clair), var(--rouge-vif), var(--vert-clair), var(--or), var(--or-clair));
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  animation: tourne 9s linear infinite;
}
.anneau::after {
  content: "";
  position: absolute;
  inset: 12px;
  border-radius: 50%;
  border: 1px dashed rgba(255, 217, 138, .3);
}
@keyframes tourne { to { transform: rotate(1turn); } }
.bravo.on .anneau { animation: medaille .8s cubic-bezier(.2, 1.6, .4, 1) .15s both; }
@keyframes medaille { from { transform: scale(.2) rotate(-40deg); opacity: 0; } }
.anneau .va {
  font: 800 11px var(--texte);
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--doux);
}
.anneau .drapeau {
  margin-top: 4px;
  font-size: 70px;
  line-height: 1;
  filter: drop-shadow(0 6px 16px rgba(0, 0, 0, .45));
}
.anneau.sans-num .va { font-size: 15px; color: var(--or-clair); }
.code {
  margin: 0 0 18px;
  font-family: var(--titre);
  font-weight: 800;
  line-height: 1;
  letter-spacing: .06em;
  text-transform: uppercase;
  background: linear-gradient(180deg, #fff3c4, var(--or) 60%, #c98410);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 4px 18px rgba(242, 182, 50, .45));
}
.message { margin: 0 8px 20px; font: 600 18px/1.45 var(--texte); color: var(--creme); }
.aime {
  margin: 0 0 20px;
  padding: 16px 18px;
  border-radius: 18px;
  border: 1px solid var(--ligne);
  background: rgba(255, 255, 255, .06);
  text-align: left;
}
.aime-titre {
  margin: 0 0 6px;
  font: 800 11px var(--texte);
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--menthe);
}
.aime p:last-child { margin: 0; font: italic 400 19px/1.45 var(--titre); color: var(--creme); }
.btn {
  width: 100%;
  padding: 16px 20px;
  border: 0;
  border-radius: 16px;
  background: linear-gradient(150deg, var(--or-clair), var(--or) 55%, #d98a10);
  color: var(--encre);
  font: 800 16px var(--texte);
  box-shadow: 0 10px 26px -10px rgba(242, 182, 50, .8);
  cursor: pointer;
}

/* ---------- Divers ---------- */
.toast {
  position: fixed; z-index: 9;
  left: 50%; top: calc(14px + var(--safe-t));
  transform: translate(-50%, -150%);
  max-width: calc(100vw - 32px);
  padding: 11px 18px;
  border-radius: 999px;
  background: var(--creme);
  color: var(--encre);
  font-weight: 800; font-size: 14px;
  box-shadow: 0 10px 30px rgba(0,0,0,.4);
  transition: transform .35s cubic-bezier(.2, 1.2, .4, 1);
  text-align: center;
}
.toast.on { transform: translate(-50%, 0); }

.mode-test {
  position: fixed; z-index: 4;
  left: 10px; bottom: calc(10px + var(--safe-b));
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(0,0,0,.55);
  color: #fff; font-size: 12px; font-weight: 700;
}
.mode-test button { border: 0; background: none; color: var(--ambre); font: inherit; text-decoration: underline; cursor: pointer; padding: 0; }

@media (prefers-reduced-motion: reduce) {
  .case, .anneau::before, .etincelles::before, .etincelles::after, .defile svg { animation: none; }
}
