:root {
  --night: #1E2B4F;
  --ink: #0F1830;
  --brown: #2B1B17;
  --cream: #FFF8EA;
  --red: #E84A3C;
  --green: #3BA55C;
  --gold: #F5B83D;
  --soft: #DDE6F7;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  min-height: 100vh;
  background: var(--night);
  color: var(--cream);
  font-family: 'Nunito', system-ui, sans-serif;
  position: relative;
  overflow-x: hidden;
  padding: 48px 24px 160px;
}

/* ---------- Neige ---------- */
.snow { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 5; }
.flake {
  position: absolute; top: -20px; border-radius: 50%; background: #fff;
  animation: fall linear infinite;
}

/* ---------- Décor ---------- */
.garland { position: absolute; top: 0; left: 50%; transform: translateX(-50%); pointer-events: none; }
.bulb { animation: twinkle 1.6s ease-in-out infinite; }
.ground { position: absolute; left: 0; bottom: 0; z-index: 1; display: block; }

/* ---------- Mise en page ---------- */
.wrap {
  max-width: 1120px; margin: 0 auto; position: relative; z-index: 2;
  display: flex; flex-direction: column; gap: 40px;
}

.header {
  position: relative; display: flex; flex-direction: column; align-items: center;
  gap: 14px; text-align: center; padding-top: 40px;
}
.deco { position: absolute; }
.deco-left { left: 10px; top: 70px; transform: rotate(-8deg); }
.deco-right { right: 10px; top: 60px; transform: rotate(7deg); }

.pill {
  display: inline-flex; align-items: center; gap: 8px;
  background: #fff; color: var(--brown);
  border: 3px solid var(--ink); border-radius: 999px; padding: 6px 18px;
  box-shadow: 3px 3px 0 var(--ink); font-weight: 800; font-size: 15px;
  transform: rotate(-2deg);
}
.title {
  margin: 0; font-family: 'Fredoka', sans-serif; font-weight: 700;
  font-size: 72px; line-height: 1.02; color: var(--cream);
  text-shadow: 3px 3px 0 var(--red), 6px 6px 0 var(--ink);
}
.subtitle { margin: 0; font-size: 19px; font-weight: 700; line-height: 1.45; color: var(--soft); }
.counter {
  background: var(--green); color: #fff; font-weight: 800; font-size: 16px;
  border: 3px solid var(--ink); border-radius: 12px; padding: 4px 12px;
  box-shadow: 3px 3px 0 var(--ink);
}
.footer { text-align: center; font-weight: 700; font-size: 15px; color: var(--soft); }

/* ---------- Grille ---------- */
.grid {
  display: grid; grid-template-columns: repeat(6, minmax(0, 1fr));
  column-gap: 22px; row-gap: 36px;
}

/* ---------- Cases ---------- */
.door {
  --tilt: 0deg;
  aspect-ratio: 1 / 1; padding: 0; font-family: inherit; cursor: pointer;
  border: 4px solid var(--ink); box-shadow: 5px 5px 0 var(--ink);
  transform: rotate(var(--tilt)); transition: transform .18s ease;
  position: relative;
}
.door:not(:disabled):hover { transform: translateY(-5px) rotate(calc(var(--tilt) * -1.5)); }
.door:focus-visible { outline: 4px solid var(--cream); outline-offset: 5px; }
.door:disabled { cursor: not-allowed; opacity: .55; }

/* Cadeau fermé */
.gift {
  border-radius: 18px; background: var(--color);
  display: flex; align-items: center; justify-content: center; overflow: visible;
}
.ribbon-v, .ribbon-h { position: absolute; background: var(--ribbon); }
.ribbon-v {
  top: 0; bottom: 0; left: 50%; width: 18%; transform: translateX(-50%);
  border-left: 3px solid var(--ink); border-right: 3px solid var(--ink);
}
.ribbon-h {
  left: 0; right: 0; top: 50%; height: 18%; transform: translateY(-50%);
  border-top: 3px solid var(--ink); border-bottom: 3px solid var(--ink);
}
.bow { position: absolute; top: -30px; left: 50%; transform: translateX(-50%); }
.bow g { fill: var(--ribbon); }
.tag {
  position: relative; width: 52%; aspect-ratio: 1 / 1; border-radius: 999px;
  background: var(--cream); border: 4px solid var(--ink);
  display: flex; align-items: center; justify-content: center;
  font-family: 'Fredoka', sans-serif; font-weight: 700; font-size: 34px; color: var(--brown);
}
.lock {
  position: absolute; bottom: 8px; right: 8px; width: 30px; height: 30px;
  background: #fff; border: 3px solid var(--ink); border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
}

/* Case ouverte */
.opened {
  border-radius: 22px; background: #fff; overflow: hidden;
  display: flex; flex-direction: column;
}
.thumb {
  flex: 1; display: flex; align-items: center; justify-content: center;
  border-bottom: 3px solid var(--brown); overflow: hidden; min-height: 0;
}
.thumb img, .thumb video { width: 100%; height: 100%; object-fit: cover; display: block; }
.opened-label {
  padding: 8px 10px; display: flex; justify-content: space-between; align-items: center;
  font-weight: 800; font-size: 14px; color: var(--brown);
}
.opened-label small { font-size: 12px; color: #5A4038; }

.stripes { background: repeating-linear-gradient(45deg, #FFE7B8 0 14px, #FFDCA0 14px 28px); }

/* ---------- Fenêtre souvenir ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 10; padding: 20px;
  background: rgba(15, 24, 48, .65);
  display: flex; align-items: center; justify-content: center;
  animation: fade .25s ease both;
}
.overlay[hidden] { display: none; }
.dialog {
  position: relative; width: 100%; max-width: 640px; max-height: calc(100vh - 40px); overflow: auto;
  background: var(--cream); color: var(--brown);
  border: 4px solid var(--ink); border-radius: 28px; box-shadow: 8px 8px 0 var(--ink);
  padding: 22px; display: flex; flex-direction: column; gap: 16px;
  animation: pop .5s cubic-bezier(.3, 1.5, .5, 1) both;
}
.dialog-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.dialog-title { margin: 0; font-family: 'Fredoka', sans-serif; font-weight: 700; font-size: 30px; color: #C0392B; }
.media {
  aspect-ratio: 4 / 3; border: 4px solid var(--brown); border-radius: 18px; overflow: hidden;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; font-weight: 800; font-size: 17px; background-color: #000;
}
.media.stripes { background-color: transparent; }
.media img, .media video { width: 100%; height: 100%; object-fit: contain; display: block; background: #000; }
.caption { margin: 0; font-size: 18px; font-weight: 700; line-height: 1.45; }
.caption:empty { display: none; }
.dialog-actions { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

.btn, .btn-icon {
  border: 3px solid var(--brown); border-radius: 14px; background: #fff;
  box-shadow: 3px 3px 0 var(--brown); cursor: pointer; font-family: inherit;
  font-weight: 800; font-size: 15px; color: var(--brown);
  transition: transform .1s ease, box-shadow .1s ease;
}
.btn { min-height: 46px; padding: 0 20px; }
.btn:active, .btn-icon:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--brown); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-green { background: var(--green); color: #fff; }
.btn-icon { width: 46px; height: 46px; display: flex; align-items: center; justify-content: center; padding: 0; }

.confetti-layer { position: absolute; inset: 0; pointer-events: none; }
.confetti {
  position: absolute; left: 50%; top: 40%; width: 12px; height: 16px;
  border: 2px solid var(--brown); border-radius: 3px;
  animation: burst 1s ease-out forwards;
}

/* ---------- Connexion ---------- */
.login {
  position: fixed; inset: 0; z-index: 20; padding: 20px;
  background: var(--night); display: flex; align-items: center; justify-content: center;
}
.login[hidden] { display: none; }
.login-card {
  width: 100%; max-width: 420px; background: var(--cream); color: var(--brown);
  border: 4px solid var(--ink); border-radius: 28px; box-shadow: 8px 8px 0 var(--ink);
  padding: 64px 28px 28px; position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center;
}
.login-card.pop-in { animation: pop .5s cubic-bezier(.3, 1.5, .5, 1) both; }
.login-gift { position: absolute; top: -62px; left: 50%; transform: translateX(-50%) rotate(-4deg); }
.login-title { margin: 4px 0 0; font-family: 'Fredoka', sans-serif; font-weight: 700; font-size: 34px; color: #C0392B; }
.login-text { margin: 0 0 6px; font-weight: 700; font-size: 16px; }
.login-label { align-self: flex-start; font-weight: 800; font-size: 15px; }
.login-input {
  width: 100%; min-height: 50px; padding: 0 16px; font: inherit; font-weight: 700; font-size: 17px;
  color: var(--brown); background: #fff; border: 3px solid var(--brown); border-radius: 14px;
  box-shadow: inset 3px 3px 0 rgba(43, 27, 23, .12);
}
.login-input:focus { outline: 3px solid var(--gold); outline-offset: 2px; }
.login-input[aria-invalid="true"] { border-color: #C0392B; }
.login-hint { margin: 0; align-self: flex-start; font-size: 14px; font-weight: 700; color: #5A4038; }
.login-error {
  margin: 0; align-self: stretch; padding: 8px 12px; border-radius: 12px;
  background: #FDE2DE; border: 3px solid #C0392B; color: #8E2A1F; font-weight: 800; font-size: 15px;
}
.login-btn { width: 100%; margin-top: 6px; font-size: 17px; }
.btn-red { background: var(--red); color: #fff; }
.shake { animation: shake .45s ease both; }

/* ---------- Cadeau verrouillé ---------- */
.door.is-locked { opacity: .6; cursor: not-allowed; }
.door.is-locked:hover { transform: rotate(var(--tilt)); }
.nope { animation: nope .45s ease both; }
.dialog-small { max-width: 400px; align-items: center; text-align: center; padding-top: 28px; }
.locked-clock { animation: wobble 1.2s ease-in-out infinite; }
.locked-text { margin: 0; font-weight: 800; font-size: 18px; }
.locked-count {
  margin: 0; font-weight: 800; font-size: 15px; color: #fff; background: var(--green);
  border: 3px solid var(--brown); border-radius: 12px; padding: 4px 12px;
}
.locked-count:empty { display: none; }

/* ---------- Animations ---------- */
.unwrap { animation: unwrap .7s ease-in forwards; }
.reveal { animation: reveal .55s cubic-bezier(.3, 1.6, .5, 1) both; }

@keyframes unwrap {
  0%   { transform: rotate(0) scale(1); }
  15%  { transform: rotate(-9deg) scale(1.05); }
  30%  { transform: rotate(9deg) scale(1.08); }
  45%  { transform: rotate(-7deg) scale(1.1); }
  60%  { transform: rotate(5deg) scale(1.12); }
  100% { transform: rotate(0) scale(1.35); opacity: 0; }
}
@keyframes reveal {
  0%   { transform: scale(.4) rotate(-12deg); opacity: 0; }
  100% { transform: scale(1) rotate(var(--tilt)); opacity: 1; }
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop {
  0%   { transform: scale(.6) rotate(-6deg); opacity: 0; }
  100% { transform: scale(1) rotate(-.6deg); opacity: 1; }
}
@keyframes fall {
  0%   { transform: translate(0, -5vh); }
  50%  { transform: translate(28px, 50vh); }
  100% { transform: translate(-12px, 105vh); }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-12px) rotate(-1deg); }
  40% { transform: translateX(10px) rotate(1deg); }
  60% { transform: translateX(-7px); }
  80% { transform: translateX(4px); }
}
@keyframes nope {
  0%, 100% { transform: rotate(var(--tilt)); }
  25% { transform: rotate(calc(var(--tilt) - 6deg)) translateX(-6px); }
  50% { transform: rotate(calc(var(--tilt) + 6deg)) translateX(6px); }
  75% { transform: rotate(calc(var(--tilt) - 3deg)) translateX(-3px); }
}
@keyframes wobble { 0%, 100% { transform: rotate(-8deg); } 50% { transform: rotate(8deg); } }
@keyframes twinkle { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }
@keyframes burst {
  0%   { transform: translate(-50%, -50%) rotate(0); opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) rotate(540deg); opacity: 0; }
}

/* ---------- Mobile ---------- */
@media (max-width: 900px) {
  .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .deco { display: none; }
}
@media (max-width: 560px) {
  body { padding: 40px 16px 150px; }
  .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); column-gap: 14px; row-gap: 28px; }
  .title { font-size: 42px; }
  .tag { font-size: 26px; border-width: 3px; }
  .bow { width: 48px; top: -22px; }
}

@media (prefers-reduced-motion: reduce) {
  .flake, .bulb, .unwrap, .reveal, .dialog, .overlay, .confetti, .login-card.pop-in, .shake, .nope, .locked-clock { animation: none !important; }
}
