:root {
  --pine: #0e2a20;
  --pine-2: #17402f;
  --red: #b3262d;
  --red-dark: #7f161c;
  --green: #1f6b47;
  --cream: #fbf3e2;
  --gold: #e8b84a;
  --ink: #2b1d14;
  --radius: 16px;
  --title-font: "Mountains of Christmas", "Georgia", serif;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  font-family: "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--cream);
  background:
    radial-gradient(120% 60% at 50% 0%, #245a43 0%, transparent 70%),
    linear-gradient(180deg, var(--pine-2), var(--pine));
  background-attachment: fixed;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  overflow-x: hidden;
}

button { font: inherit; color: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }

/* ---------- Neige ---------- */
.snow { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 0; }
.snow span {
  position: absolute; top: -5vh; color: #fff; opacity: .7;
  animation: fall linear infinite;
}
@keyframes fall {
  to { transform: translate3d(var(--drift, 20px), 110vh, 0) rotate(360deg); }
}

/* ---------- En-tête ---------- */
.site-header { position: relative; z-index: 1; text-align: center; padding: 28px 16px 8px; }
.site-header h1 {
  margin: 0; font-family: var(--title-font); font-size: clamp(2.2rem, 9vw, 3.6rem);
  color: var(--gold); text-shadow: 0 2px 0 rgba(0,0,0,.35); line-height: 1.05;
}
.site-header p { margin: 8px 0 0; opacity: .9; }

main { position: relative; z-index: 1; max-width: 640px; margin: 0 auto; padding: 16px 16px 96px; }
.load-error { background: var(--cream); color: var(--ink); padding: 16px; border-radius: var(--radius); }

/* ---------- Grille ---------- */
.grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }

.door {
  position: relative; aspect-ratio: 1; border: 0; padding: 0;
  border-radius: var(--radius);
  background: var(--red);
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.18), 0 4px 0 rgba(0,0,0,.3);
  display: grid; place-items: center;
  transition: transform .15s ease;
  user-select: none; -webkit-user-select: none;
}
.door:nth-child(3n+2) { background: var(--green); }
.door:nth-child(4n+3) { background: #c9902c; }
.door:active { transform: scale(.96); }
.door-num {
  font-family: var(--title-font); font-size: clamp(1.7rem, 8vw, 2.4rem);
  color: var(--cream); text-shadow: 0 2px 0 rgba(0,0,0,.3);
}
.door-badge { position: absolute; right: 6px; bottom: 4px; font-size: .95rem; line-height: 1; }

.door[data-state="locked"] { filter: saturate(.45) brightness(.72); }
.door[data-state="ready"] { animation: glow 2.2s ease-in-out infinite; }
.door[data-state="ready"].is-today { outline: 3px solid var(--gold); outline-offset: 2px; }
.door[data-state="open"] {
  background: var(--cream);
  box-shadow: inset 0 0 0 2px var(--gold), 0 2px 0 rgba(0,0,0,.25);
}
.door[data-state="open"] .door-num { color: var(--red); text-shadow: none; }
.door.nope { animation: nope .4s; }

.door[data-day="25"] { grid-column: 1 / -1; aspect-ratio: auto; min-height: 84px; background: var(--red-dark); }
.door[data-day="25"][data-state="open"] { background: var(--cream); }

@media (min-width: 600px) {
  .grid { grid-template-columns: repeat(5, 1fr); gap: 14px; }
  .door[data-day="25"] { grid-column: auto; aspect-ratio: 1; min-height: 0; }
}

@keyframes glow {
  50% { box-shadow: inset 0 0 0 2px rgba(255,255,255,.3), 0 4px 0 rgba(0,0,0,.3), 0 0 18px 2px rgba(232,184,74,.75); }
}
@keyframes nope {
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}

/* ---------- Fenêtre ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 10;
  background: rgba(6, 18, 13, .78);
  display: grid; place-items: center; padding: 16px;
  animation: fade .2s ease;
}
.overlay[hidden] { display: none; }
.modal {
  position: relative; width: 100%; max-width: 420px; max-height: calc(100dvh - 32px);
  overflow-y: auto; overscroll-behavior: contain;
  background: var(--cream); color: var(--ink);
  border-radius: 22px; padding: 22px 18px 20px;
  box-shadow: 0 0 0 3px var(--gold), 0 20px 50px rgba(0,0,0,.5);
  animation: pop .25s cubic-bezier(.2, 1.4, .4, 1);
}
.modal h2 { margin: 0 36px 6px 0; font-family: var(--title-font); font-size: 1.9rem; color: var(--red); }
.modal-close {
  position: absolute; top: 10px; right: 10px; width: 40px; height: 40px;
  border: 0; border-radius: 50%; background: rgba(0,0,0,.07); font-size: 1.1rem;
}
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: scale(.9) translateY(12px); } }

.consigne { margin: 0 0 16px; font-weight: 600; line-height: 1.4; }
.mech { display: grid; justify-items: center; gap: 14px; text-align: center; }
.mech-info { margin: 0; min-height: 1.4em; font-weight: 600; }

.btn {
  border: 0; border-radius: 999px; padding: 12px 22px; min-height: 48px;
  background: var(--red); color: #fff; font-weight: 800;
  box-shadow: 0 3px 0 var(--red-dark);
  text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--red-dark); }
.btn.secondary { background: transparent; color: var(--red); box-shadow: inset 0 0 0 2px var(--red); }

/* --- tap --- */
.tap-target {
  width: 150px; height: 150px; border: 0; border-radius: 28px; font-size: 5rem; line-height: 1;
  background: var(--red); box-shadow: 0 6px 0 var(--red-dark);
  touch-action: manipulation; user-select: none; -webkit-user-select: none;
}
.tap-target.hit { animation: wobble .28s; }
@keyframes wobble {
  25% { transform: rotate(calc(var(--amp, 2) * -1deg)) scale(.96); }
  75% { transform: rotate(calc(var(--amp, 2) * 1deg)) scale(1.03); }
}

/* --- appui long --- */
.press-target {
  --p: 0;
  width: 170px; height: 170px; border: 0; border-radius: 50%;
  background: conic-gradient(var(--gold) calc(var(--p) * 360deg), #e6dcc6 0);
  display: grid; place-items: center;
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.press-target span {
  width: 136px; height: 136px; border-radius: 50%; background: var(--red); color: #fff;
  display: grid; place-items: center; font-size: 3.4rem; pointer-events: none;
  transition: transform .15s;
}
.press-target.holding span { transform: scale(.93); }

/* --- réponse texte --- */
.answer-form { display: grid; gap: 12px; width: 100%; }
.question { margin: 0; font-size: 1.25rem; font-weight: 800; }
.answer-form input {
  width: 100%; font: inherit; font-size: 1.1rem; /* >= 16px : pas de zoom iOS */
  padding: 13px 14px; border-radius: 12px; border: 2px solid #d5c7a8; background: #fff; color: var(--ink);
  text-align: center;
}
.answer-form input:focus { outline: 0; border-color: var(--gold); }
.answer-form.wrong input { animation: nope .4s; border-color: var(--red); }
.hint { margin: 0; font-style: italic; }
.letters { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px; }
.letters span {
  width: 26px; height: 32px; border-radius: 6px; background: #fff; border: 1px solid #d5c7a8;
  display: grid; place-items: center; font-weight: 800; position: relative;
}
.letters span.empty { color: #b9ab8c; }

/* ---------- Contenu / ouverture ---------- */
.reveal { position: relative; perspective: 900px; }
.reveal .leaf {
  position: absolute; top: -4px; bottom: -4px; width: 50%; z-index: 2;
  background: repeating-linear-gradient(45deg, var(--red) 0 14px, var(--red-dark) 14px 28px);
  box-shadow: inset 0 0 0 3px var(--gold);
  transition: transform 1s cubic-bezier(.6, 0, .3, 1), opacity .4s ease .75s;
  backface-visibility: hidden;
}
.reveal .leaf.left { left: -2px; transform-origin: left center; border-radius: 12px 0 0 12px; }
.reveal .leaf.right { right: -2px; transform-origin: right center; border-radius: 0 12px 12px 0; }
.reveal.opening .leaf.left { transform: rotateY(-108deg); opacity: 0; }
.reveal.opening .leaf.right { transform: rotateY(108deg); opacity: 0; }

.content { display: grid; gap: 14px; justify-items: center; text-align: center; padding: 6px 2px; min-height: 180px; align-content: center; }
.content-type {
  background: var(--green); color: #fff; font-size: .8rem; font-weight: 800;
  letter-spacing: .04em; text-transform: uppercase; padding: 4px 12px; border-radius: 999px;
}
.content-text { margin: 0; font-size: 1.15rem; line-height: 1.5; white-space: pre-line; }
.content img { max-width: 100%; border-radius: 12px; }
.content details { width: 100%; background: #fff; border-radius: 12px; padding: 10px 14px; text-align: left; }
.content summary { font-weight: 800; color: var(--red); cursor: pointer; }
.content details p { margin: 8px 0 0; line-height: 1.45; }
.letter-chip {
  display: flex; align-items: center; gap: 10px; text-align: left; font-size: .92rem;
  background: #fff; border: 2px dashed var(--gold); border-radius: 12px; padding: 8px 12px;
}
.letter-chip b {
  font-family: var(--title-font); font-size: 1.8rem; color: var(--red);
  width: 40px; height: 40px; display: grid; place-items: center; background: var(--cream); border-radius: 8px;
}
.timer { display: grid; gap: 8px; justify-items: center; }
.timer-display { font-size: 2.2rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.success-msg { margin: 0; font-weight: 800; color: var(--green); }

.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 20; overflow: hidden; }
.confetti span {
  position: absolute; left: 50%; top: 45%; font-size: 1.4rem;
  animation: burst 1.3s cubic-bezier(.1, .7, .3, 1) forwards;
}
@keyframes burst {
  to { transform: translate(var(--x), var(--y)) rotate(var(--r)); opacity: 0; }
}

/* ---------- Divers ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); z-index: 30;
  transform: translate(-50%, 140%); width: max-content; max-width: calc(100vw - 32px);
  background: var(--cream); color: var(--ink); font-weight: 600; text-align: center;
  padding: 12px 18px; border-radius: 14px; box-shadow: 0 0 0 2px var(--gold), 0 8px 24px rgba(0,0,0,.4);
  opacity: 0; visibility: hidden;
  transition: transform .3s ease, opacity .3s ease, visibility .3s;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; visibility: visible; }

.test-panel {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  background: #111; color: #fff; font-size: .85rem;
}
.test-panel[hidden] { display: none; }
.test-panel input, .test-panel button { font: inherit; padding: 4px 8px; border-radius: 6px; border: 0; color: #111; background: #fff; }
.test-panel a { color: var(--gold); }

@media (prefers-reduced-motion: reduce) {
  .snow { display: none; }
  .door[data-state="ready"] { animation: none; }
  .reveal .leaf { transition-duration: .01s; }
}

/* ================= Mécaniques (suite) ================= */
.btn:disabled { opacity: .6; }
.mech canvas { max-width: 100%; touch-action: none; user-select: none; -webkit-user-select: none; }

/* --- secouer --- */
.shake-flake { font-size: 6rem; line-height: 1; transform-origin: 50% -30%; }
.shake-flake.hit { animation: swing .3s; }
.shake-flake.fall { animation: drop .6s ease-in forwards; }
@keyframes swing {
  25% { transform: rotate(calc(var(--amp, 8) * -1deg)); }
  75% { transform: rotate(calc(var(--amp, 8) * 1deg)); }
}
@keyframes drop { to { transform: translateY(160px) rotate(200deg); opacity: 0; } }

/* --- retourner --- */
.flip-text { transform: rotate(180deg); display: grid; gap: 6px; justify-items: center; font-size: 1.15rem; font-weight: 800; padding: 10px; }
.flip-emoji { font-size: 3.4rem; line-height: 1; }

/* --- souffler --- */
.candle { display: grid; justify-items: center; padding-top: 10px; }
.flame {
  --f: 1;
  width: 34px; height: 56px; border-radius: 50% 50% 50% 50% / 62% 62% 38% 38%;
  background: radial-gradient(circle at 50% 70%, #fff6c8 0 18%, #ffc93c 45%, #f2711c 100%);
  box-shadow: 0 0 28px 8px rgba(255, 190, 60, .55);
  transform-origin: 50% 100%; transform: scale(var(--f)); 
  animation: flicker 1.1s ease-in-out infinite alternate;
  transition: opacity .5s;
}
.wax { width: 46px; height: 110px; margin-top: 4px; border-radius: 8px 8px 4px 4px; background: linear-gradient(90deg, #c8343b, #e9585e 45%, #a9232a); position: relative; }
.wax::before { content: ""; position: absolute; left: 50%; top: -8px; width: 3px; height: 10px; background: #3a2a1c; transform: translateX(-50%); }
.candle.out .flame { opacity: 0; animation: none; }
@keyframes flicker { to { rotate: 3deg; filter: brightness(1.12); } }

/* --- intrus --- */
.odd-grid { display: grid; grid-template-columns: repeat(var(--n), 1fr); gap: 4px; width: 100%; }
.odd-grid button { aspect-ratio: 1; border: 0; border-radius: 10px; background: #fff; font-size: clamp(1.2rem, 7vw, 1.9rem); padding: 0; line-height: 1; }
.odd-grid button.nope { animation: nope .4s; }

/* --- memory --- */
.memory-board { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; width: 100%; perspective: 700px; }
.memory-card { position: relative; aspect-ratio: 3 / 4; border: 0; padding: 0; background: none; transform-style: preserve-3d; transition: transform .35s; }
.memory-card.up { transform: rotateY(180deg); }
.memory-card span { position: absolute; inset: 0; display: grid; place-items: center; border-radius: 12px; backface-visibility: hidden; -webkit-backface-visibility: hidden; font-size: 2rem; }
.memory-card .back { background: var(--red); color: #fff; box-shadow: inset 0 0 0 2px var(--gold); }
.memory-card .front { background: #fff; transform: rotateY(180deg); box-shadow: inset 0 0 0 2px #d5c7a8; }
.memory-card.found .front { box-shadow: inset 0 0 0 3px var(--green); }

/* --- simon --- */
.simon-board { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; width: min(100%, 260px); }
.simon-pad { aspect-ratio: 1; border: 0; border-radius: 22px; opacity: .45; transition: opacity .1s, transform .1s; }
.simon-pad.lit { opacity: 1; transform: scale(1.05); box-shadow: 0 0 22px 4px rgba(255,255,255,.9), 0 0 0 4px var(--gold); }

/* --- guirlande --- */
.garland { display: flex; justify-content: center; gap: 4px; width: 100%; padding-top: 14px; border-top: 4px solid var(--green); border-radius: 50% 50% 0 0 / 18px 18px 0 0; }
.bulb { flex: 1; max-width: 64px; aspect-ratio: 3 / 4; border: 0; border-radius: 50% 50% 46% 46%; background: #cfc8b8; font-size: 1.7rem; filter: grayscale(1); opacity: .65; transition: all .2s; padding: 0; }
.bulb.on { background: #ffe27a; filter: none; opacity: 1; box-shadow: 0 0 20px 6px rgba(255, 214, 80, .8); }

/* --- quiz --- */
.quiz-buttons { display: flex; gap: 12px; }
.quiz-buttons .btn { min-width: 110px; }
.quiz-buttons .btn:last-child { background: var(--green); box-shadow: 0 3px 0 #134a31; }

/* --- gratter --- */
.scratch-ticket { position: relative; width: 100%; max-width: 300px; aspect-ratio: 300 / 180; border-radius: 14px; overflow: hidden; box-shadow: 0 0 0 3px var(--gold); background: #fff; }
.scratch-under { position: absolute; inset: 0; display: grid; place-items: center; font-size: 5rem; }
.scratch-canvas { position: absolute; inset: 0; width: 100%; height: 100%; transition: opacity .45s; cursor: grab; }
.scratch-canvas.cleared { opacity: 0; }

/* --- attraper --- */
.catch-arena { position: relative; width: 100%; height: 280px; border-radius: 14px; background: linear-gradient(#dff1fb, #fff); overflow: hidden; box-shadow: inset 0 0 0 2px #cfe3ee; touch-action: none; }
.catch-target { position: absolute; left: 40%; top: 40%; width: 64px; height: 64px; border: 0; padding: 0; background: none; font-size: 3rem; line-height: 1; transition: left ease-in-out, top ease-in-out, transform .3s; touch-action: none; }
.catch-target.caught { transform: scale(1.6) rotate(20deg); }

/* --- étoile --- */
.star-canvas { width: min(100%, 300px); aspect-ratio: 1; background: #fff; border-radius: 14px; box-shadow: inset 0 0 0 2px #d5c7a8; }

/* --- glisser --- */
.dd-arena { position: relative; width: 100%; height: 320px; display: grid; justify-items: center; align-content: start; touch-action: none; }
.dd-zone { width: 58px; height: 58px; border: 3px dashed var(--gold); border-radius: 50%; margin-top: 4px; }
.dd-zone.filled { border-style: solid; box-shadow: 0 0 22px 6px rgba(232,184,74,.8); }
.dd-tree { font-size: 12rem; line-height: 1; margin-top: -14px; user-select: none; -webkit-user-select: none; }
.dd-item { position: absolute; left: 6px; bottom: 6px; width: 60px; height: 60px; display: grid; place-items: center; font-size: 2.8rem; line-height: 1; cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none; z-index: 2; }
.dd-item.moving { transition: transform .3s ease; }

/* --- abandon --- */
.give-up { display: flex; margin: 16px auto 0; }
.give-up[hidden] { display: none; }
.question { white-space: pre-line; }

/* --- compter --- */
.count-scene { position: relative; width: 100%; aspect-ratio: 6 / 7; max-height: 46vh; margin-bottom: 14px; border-radius: 14px; background: linear-gradient(#dff1fb 0 60%, #fff 100%); box-shadow: inset 0 0 0 2px #cfe3ee; overflow: hidden; }
.count-scene span { position: absolute; font-size: clamp(1.3rem, 7vw, 1.9rem); line-height: 1; }
.count-image { width: 100%; border-radius: 14px; margin-bottom: 14px; }

/* --- taquin --- */
.slider-board { position: relative; width: min(100%, 300px); aspect-ratio: 1; border-radius: 12px; background: #d9ceb4; box-shadow: 0 0 0 3px var(--gold); overflow: hidden; }
.slider-tile { position: absolute; border: 0; padding: 0; background-color: var(--green); background-repeat: no-repeat; box-shadow: inset 0 0 0 1px rgba(255,255,255,.7); transition: left .15s ease, top .15s ease; color: #fff; }
.slider-tile span { position: absolute; left: 5px; top: 4px; min-width: 20px; height: 20px; border-radius: 10px; background: rgba(0,0,0,.55); font-size: .8rem; font-weight: 800; display: grid; place-items: center; }
.slider-board.solved { background: var(--img, #d9ceb4) center / cover; }
.slider-board.solved .slider-tile { box-shadow: none; }
.slider-board.solved .slider-tile span { display: none; }
.slider-model { display: flex; align-items: center; gap: 8px; font-size: .85rem; }
.slider-model img { width: 64px; height: 64px; border-radius: 8px; box-shadow: 0 0 0 2px #d5c7a8; }

/* --- bouton caché --- */
.hidden-scene { position: relative; width: 100%; height: 280px; border-radius: 14px; overflow: hidden; touch-action: none; cursor: crosshair;
  background: linear-gradient(#16285a 0 45%, #3b5ba5 62%, #f4f8ff 62% 100%); box-shadow: inset 0 0 0 2px #cfe3ee; user-select: none; -webkit-user-select: none; }
.hidden-scene .decor { position: absolute; font-size: 2.6rem; line-height: 1; pointer-events: none; }
.hidden-mark { position: absolute; width: 18px; height: 18px; margin: -9px 0 0 -9px; border-radius: 50%; border: 3px solid #fff; pointer-events: none; animation: ping .9s ease-out forwards; }
.hidden-found { position: absolute; font-size: 2.4rem; line-height: 1; transform: translate(-50%, -50%); animation: pop .3s; }
@keyframes ping { to { transform: scale(2.4); opacity: 0; } }

/* --- consigne et indications cachées pendant le délai --- */
.hints-off .tip { visibility: hidden; }
.tip { animation: fade .5s ease; }
.peek { display: block; margin: 12px auto 0; border: 0; background: none; font-size: .8rem; color: #8a7a5c; text-decoration: underline; }
button.shake-flake, button.flip-text, button.candle { border: 0; background: none; color: inherit; font-family: inherit; padding: 0; }
button.flip-text { padding: 10px; }
