:root {
  --night: #0c1613;
  --pine: #173a2e;
  --holly: #23513f;
  --berry: #8c2433;
  --wine: #5b1522;
  --gold: #d9b56c;
  --gold-hi: #f3d999;
  --cream: #f4ead7;
  --paper: #fbf6ec;
  --ink: #1b1a17;
  --gap: 9px;
  --radius: 14px;
  --serif: "Fraunces", "Georgia", serif;
  --sans: "Inter", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--sans);
  color: var(--cream);
  background:
    radial-gradient(120% 60% at 50% -10%, #24493b 0%, transparent 60%),
    radial-gradient(80% 50% at 100% 100%, #3a1019 0%, transparent 60%),
    var(--night);
  background-attachment: fixed;
  min-height: 100dvh;
  overflow-x: hidden;
}
body::after { /* grain */
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 1; opacity: .07; mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
#snow { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 0; }
[hidden] { display: none !important; }

/* ---------- Gate ---------- */
.gate { position: relative; z-index: 2; min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.gate-card { width: min(360px, 100%); text-align: center; animation: rise .9s cubic-bezier(.2,.8,.2,1) both; }
.gate-star { font-size: 34px; color: var(--gold); text-shadow: 0 0 24px rgba(217,181,108,.6); animation: twinkle 3s ease-in-out infinite; }
.gate h1 { font-family: var(--serif); font-weight: 400; font-size: 34px; line-height: 1.1; margin: 6px 0 28px; letter-spacing: -.01em; }
.gate h1 em { color: var(--gold); font-style: italic; }
.gate form { display: flex; gap: 8px; }
.gate input {
  flex: 1; min-width: 0; font: 500 16px var(--sans); color: var(--paper); padding: 14px 16px;
  background: rgba(255,255,255,.06); border: 1px solid rgba(217,181,108,.35); border-radius: 999px; outline: none;
}
.gate input:focus { border-color: var(--gold); background: rgba(255,255,255,.1); }
.gate button {
  font: 600 15px var(--sans); color: var(--ink); background: linear-gradient(180deg, var(--gold-hi), var(--gold));
  border: 0; border-radius: 999px; padding: 0 20px; cursor: pointer;
}
.gate-err { min-height: 1.4em; color: #f1a3ad; font-size: 14px; margin-top: 14px; }
.gate-card.shake { animation: shake .45s; }

/* ---------- Hero ---------- */
main { position: relative; z-index: 2; padding: max(28px, env(safe-area-inset-top)) 16px max(28px, env(safe-area-inset-bottom)); max-width: 780px; margin: 0 auto; }
.hero { text-align: center; margin: 8px 0 24px; animation: rise .9s cubic-bezier(.2,.8,.2,1) both; }
.eyebrow { font: 600 11px var(--sans); letter-spacing: .32em; text-transform: uppercase; color: var(--gold); margin: 0 0 6px; }
.title { font-family: var(--serif); font-weight: 300; font-style: italic; font-size: clamp(54px, 17vw, 96px); line-height: .92; margin: 0; letter-spacing: -.03em;
  background: linear-gradient(180deg, var(--paper) 30%, var(--gold) 120%); -webkit-background-clip: text; background-clip: text; color: transparent; }
.for { font-family: var(--serif); font-size: 18px; margin: 10px 0 0; color: rgba(244,234,215,.8); }
.for:empty { display: none; }
.countdown { display: inline-block; margin: 16px 0 0; padding: 7px 14px; border-radius: 999px; font-size: 13px; font-weight: 500;
  background: rgba(217,181,108,.1); border: 1px solid rgba(217,181,108,.3); color: var(--gold-hi); }

/* ---------- Grid ---------- */
.wrap { container-type: inline-size; }
.grid {
  list-style: none; margin: 0; padding: 0; display: grid; gap: var(--gap);
  grid-template-columns: repeat(4, 1fr);
  grid-auto-rows: calc((100cqi - 3 * var(--gap)) / 4);
  grid-auto-flow: dense;
}
@container (min-width: 600px) {
  .grid { --gap: 12px; grid-template-columns: repeat(6, 1fr); grid-auto-rows: calc((100cqi - 5 * var(--gap)) / 6); }
}
.cell { position: relative; perspective: 900px; animation: pop .6s cubic-bezier(.2,.9,.25,1.2) both; animation-delay: calc(var(--i) * 28ms); }
.cell.w2 { grid-column: span 2; }
.cell.h2 { grid-row: span 2; }
.cell.big { grid-column: span 2; grid-row: span 2; }

.door-btn { all: unset; position: absolute; inset: 0; cursor: pointer; border-radius: var(--radius); }
.door-btn:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }

.behind {
  position: absolute; inset: 0; border-radius: var(--radius); overflow: hidden;
  background: radial-gradient(circle at 50% 40%, #2a2a24, #121210);
  box-shadow: inset 0 0 0 1px rgba(217,181,108,.25), inset 0 6px 18px rgba(0,0,0,.6);
}
.behind img { width: 100%; height: 100%; object-fit: cover; display: block; opacity: 0; transition: opacity .5s; }
.behind img.ok { opacity: 1; }
.behind .badge {
  position: absolute; left: 7px; bottom: 7px; font: 600 12px var(--sans); color: var(--paper); padding: 3px 8px; border-radius: 999px;
  background: rgba(12,22,19,.55); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}

.door {
  position: absolute; inset: 0; border-radius: var(--radius); transform-origin: left center; transform-style: preserve-3d;
  transition: transform 1.05s cubic-bezier(.25,.8,.2,1), opacity .35s .75s, box-shadow .6s;
  display: grid; place-items: center; overflow: hidden;
  background: var(--bg); color: var(--fg);
  box-shadow: 0 1px 0 rgba(255,255,255,.12) inset, 0 -2px 0 rgba(0,0,0,.18) inset, 0 8px 18px -8px rgba(0,0,0,.7);
}
.door::before { content: ""; position: absolute; inset: 0; background: var(--pattern, none); opacity: .9; }
.door::after { /* liseré intérieur */
  content: ""; position: absolute; inset: 5px; border-radius: calc(var(--radius) - 5px); border: 1px solid var(--line); pointer-events: none;
}
.num { position: relative; font-family: var(--serif); font-weight: 400; font-style: italic; font-size: clamp(28px, 9cqi, 46px); line-height: 1; letter-spacing: -.02em; }
.big .num { font-size: clamp(64px, 22cqi, 120px); font-weight: 300; }
.h2 .num, .w2 .num { font-size: clamp(34px, 11cqi, 56px); }
@container (min-width: 600px) { .num { font-size: 40px; } .big .num { font-size: 110px; } .h2 .num, .w2 .num { font-size: 50px; } }
.knob { position: absolute; right: 9px; top: 50%; width: 5px; height: 5px; margin-top: -2.5px; border-radius: 50%; background: var(--line); }
.lock { position: absolute; top: 8px; right: 9px; width: 11px; height: 11px; opacity: .55; color: var(--fg); }
.tag { position: absolute; bottom: 8px; left: 0; right: 0; text-align: center; font: 600 8px var(--sans); letter-spacing: .1em; text-transform: uppercase; color: var(--fg); opacity: .85; }

/* palettes */
.c-berry { --bg: linear-gradient(155deg, #a12d3d, var(--wine)); --fg: var(--paper); --line: rgba(243,217,153,.45); }
.c-pine  { --bg: linear-gradient(155deg, #2a5c48, #12302a); --fg: var(--paper); --line: rgba(243,217,153,.4); }
.c-cream { --bg: linear-gradient(155deg, #fbf3e2, #e7d6b8); --fg: var(--wine); --line: rgba(140,36,51,.35); }
.c-gold  { --bg: linear-gradient(155deg, #edd08f, #b98d43); --fg: #3d2410; --line: rgba(61,36,16,.35); }
.c-ink   { --bg: linear-gradient(155deg, #23302c, #0e1715); --fg: var(--gold-hi); --line: rgba(217,181,108,.4); }

/* motifs */
.p-ribbon { --pattern:
  linear-gradient(90deg, transparent calc(50% - 5px), var(--line) calc(50% - 5px), var(--line) calc(50% + 5px), transparent calc(50% + 5px)),
  linear-gradient(0deg, transparent calc(50% - 5px), var(--line) calc(50% - 5px), var(--line) calc(50% + 5px), transparent calc(50% + 5px)); }
.p-ribbon .num { padding: 2px 10px; border-radius: 8px; background: var(--bg); }
.p-dots { --pattern: radial-gradient(circle, var(--line) 1.2px, transparent 1.6px) 0 0 / 12px 12px; }
.p-stripes { --pattern: repeating-linear-gradient(135deg, transparent 0 9px, var(--line) 9px 10px); }
.p-plain { --pattern: radial-gradient(120% 80% at 30% 0%, rgba(255,255,255,.18), transparent 60%); }
.p-dots .num, .p-stripes .num { text-shadow: 0 0 10px var(--shadow, rgba(0,0,0,.25)); }

/* états */
.cell.locked .door { filter: saturate(.85); }
.cell.ready .door { animation: breathe 2.8s ease-in-out infinite; }
.cell.today .door {
  box-shadow: 0 0 0 2px var(--gold-hi), 0 0 28px 4px rgba(243,217,153,.45), 0 8px 18px -8px rgba(0,0,0,.7);
  animation: glow 2.2s ease-in-out infinite;
}
.cell.today { z-index: 2; }
.cell.opening .door { animation: none; transform: rotateY(-108deg); opacity: 0; box-shadow: none; }
.cell.opened .door { display: none; }
.cell.shake .door-btn { animation: shake .45s; }

/* étincelles */
.spark { position: absolute; left: 50%; top: 50%; width: 6px; height: 6px; border-radius: 50%; background: var(--gold-hi); pointer-events: none; z-index: 5;
  box-shadow: 0 0 8px var(--gold); animation: spark .9s cubic-bezier(.1,.7,.3,1) forwards; }

.foot { text-align: center; margin: 32px 0 8px; font-size: 12px; letter-spacing: .12em; color: rgba(244,234,215,.45); }
.foot span { color: var(--berry); }

/* ---------- Viewer ---------- */
.viewer { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: max(56px, env(safe-area-inset-top)) 14px max(24px, env(safe-area-inset-bottom));
  background: rgba(8,14,12,.82); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); animation: fade .3s both; }
.v-fig { margin: 0; width: min(560px, 100%); animation: rise .45s cubic-bezier(.2,.8,.2,1) both; }
.v-frame { position: relative; border-radius: 18px; overflow: hidden; background: #111; padding: 8px; background: linear-gradient(155deg, var(--paper), #e6d5b5);
  box-shadow: 0 30px 60px -20px rgba(0,0,0,.8); }
.v-frame img { display: block; width: 100%; max-height: 64dvh; object-fit: contain; border-radius: 12px; background: #0d0d0c; }
.v-empty { display: none; padding: 80px 20px; text-align: center; color: var(--wine); font-family: var(--serif); font-style: italic; font-size: 20px; }
.v-frame.empty img { display: none; }
.v-frame.empty .v-empty { display: block; }
figcaption { text-align: center; padding: 18px 8px 0; }
.v-day { font-family: var(--serif); font-style: italic; font-size: 30px; color: var(--gold-hi); }
.v-date { display: block; font-size: 11px; letter-spacing: .26em; text-transform: uppercase; color: rgba(244,234,215,.6); margin-top: 4px; }
.v-cap { font-family: var(--serif); font-size: 18px; line-height: 1.45; margin: 12px auto 0; max-width: 34ch; color: var(--paper); white-space: pre-line; }
.v-cap:empty { display: none; }
.v-btn { position: absolute; z-index: 2; border: 0; cursor: pointer; color: var(--paper); background: rgba(255,255,255,.08); border-radius: 50%;
  width: 44px; height: 44px; font: 300 30px/1 var(--serif); display: grid; place-items: center; }
.v-close { top: max(12px, env(safe-area-inset-top)); right: 12px; }
.v-prev, .v-next { top: 50%; margin-top: -22px; }
.v-prev { left: 8px; } .v-next { right: 8px; }
.v-btn:disabled { opacity: 0; pointer-events: none; }
@media (max-width: 640px) { .v-prev, .v-next { top: auto; bottom: max(18px, env(safe-area-inset-bottom)); margin: 0; } }

/* ---------- Toast ---------- */
.toast { position: fixed; z-index: 30; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); transform: translate(-50%, 30px); opacity: 0;
  padding: 11px 18px; border-radius: 999px; font-size: 14px; font-weight: 500; color: var(--ink); background: var(--paper);
  box-shadow: 0 12px 30px -10px rgba(0,0,0,.7); transition: .35s cubic-bezier(.2,.8,.2,1); pointer-events: none; white-space: nowrap; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Animations ---------- */
@keyframes rise { from { opacity: 0; transform: translateY(16px); } }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: scale(.85) translateY(10px); } }
@keyframes twinkle { 50% { opacity: .55; transform: scale(.9) rotate(20deg); } }
@keyframes shake { 20%, 60% { transform: translateX(-6px) rotate(-1deg); } 40%, 80% { transform: translateX(6px) rotate(1deg); } }
@keyframes breathe { 50% { transform: rotateY(-6deg); } }
@keyframes glow { 50% { box-shadow: 0 0 0 2px var(--gold-hi), 0 0 40px 10px rgba(243,217,153,.55), 0 8px 18px -8px rgba(0,0,0,.7); } }
@keyframes spark { to { transform: translate(var(--dx), var(--dy)) scale(0); opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
