:root {
  --night-1: #0b1430;
  --night-2: #1b2b5a;
  --night-3: #3b4f8a;
  --red: #b3202e;
  --red-dark: #7d1520;
  --green: #1f6b45;
  --green-dark: #124a2f;
  --gold: #e8c15a;
  --gold-light: #fff1b8;
  --cream: #fdf6e7;
  --ink: #2a1a14;
  --gap: 12px;
}

* { box-sizing: border-box; }

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

body {
  font-family: "Nunito", system-ui, sans-serif;
  color: #fff;
  background: linear-gradient(180deg, var(--night-1) 0%, var(--night-2) 55%, var(--night-3) 100%);
  background-attachment: fixed;
  overflow-x: hidden;
}

/* ================= Background scene ================= */
.scene { position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; }

.stars {
  position: absolute; inset: 0 0 40% 0;
  background-image:
    radial-gradient(1.5px 1.5px at 10% 20%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 25% 8%, #fff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 40% 30%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 55% 12%, #fff 50%, transparent 51%),
    radial-gradient(2px 2px at 70% 25%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 85% 10%, #fff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 92% 35%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 5% 45%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 33% 50%, #fff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 62% 42%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 78% 55%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 18% 62%, #fff 50%, transparent 51%);
  animation: twinkleSky 5s ease-in-out infinite alternate;
}
@keyframes twinkleSky { from { opacity: .55; } to { opacity: 1; } }

.moon {
  position: absolute; top: 7vh; left: 8vw;
  width: 90px; height: 90px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fffdf0, #f1e7c4 60%, #d9cc9f);
  box-shadow: 0 0 40px 12px rgba(255, 246, 200, .35), 0 0 120px 40px rgba(255, 246, 200, .12);
}

.landscape {
  position: absolute; left: 0; bottom: 0;
  width: 100%; height: 48vh; min-height: 260px;
}
.cabin-light { animation: flicker 3s infinite; }
@keyframes flicker { 0%,100% { opacity: 1; } 45% { opacity: .85; } 50% { opacity: .7; } 55% { opacity: .95; } }
.smoke circle { fill: #dfe7f5; opacity: 0; animation: smoke 4s ease-out infinite; }
.smoke circle:nth-child(2) { animation-delay: 1.3s; }
.smoke circle:nth-child(3) { animation-delay: 2.6s; }
@keyframes smoke {
  0% { opacity: 0; transform: translate(0, 10px); }
  20% { opacity: .6; }
  100% { opacity: 0; transform: translate(14px, -30px); }
}

.xmas-tree {
  position: absolute; right: 3vw; bottom: 2vh;
  height: min(58vh, 520px); width: auto;
  filter: drop-shadow(0 10px 25px rgba(0,0,0,.35));
}
.lights circle { fill: #fff6c2; animation: blink 1.6s ease-in-out infinite; }
.lights circle:nth-child(3n)   { fill: #ff8a8a; animation-delay: .4s; }
.lights circle:nth-child(3n+1) { fill: #9be7ff; animation-delay: .9s; }
.lights circle:nth-child(4n)   { animation-duration: 2.2s; }
@keyframes blink { 0%,100% { opacity: .25; } 50% { opacity: 1; } }
.tree-star { transform-origin: 150px 62px; animation: starPulse 2.4s ease-in-out infinite; }
.star-glow { transform-origin: 150px 62px; animation: glow 2.4s ease-in-out infinite; }
@keyframes starPulse { 50% { transform: scale(1.12) rotate(6deg); } }
@keyframes glow { 0%,100% { opacity: .5; transform: scale(.9); } 50% { opacity: 1; transform: scale(1.2); } }

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

/* ================= Content ================= */
main {
  position: relative; z-index: 2;
  max-width: 920px; margin: 0 auto;
  padding: 32px 16px 80px;
}

header { text-align: center; margin-bottom: 24px; }
h1 {
  font-family: "Mountains of Christmas", cursive;
  font-weight: 700;
  font-size: clamp(2.4rem, 7vw, 4.4rem);
  margin: 0;
  color: var(--gold-light);
  text-shadow: 0 2px 0 var(--red-dark), 0 0 24px rgba(255, 215, 120, .55);
  letter-spacing: 1px;
}
.subtitle { margin: 6px 0 0; font-size: 1.1rem; opacity: .9; }

.debug-banner {
  margin: 0 auto 18px; max-width: 520px; text-align: center;
  background: repeating-linear-gradient(45deg, #ffd54a 0 12px, #1a1a1a 12px 24px);
  padding: 4px; border-radius: 10px;
}
.debug-banner span { display: block; background: #1a1a1a; color: #ffd54a; padding: 6px 12px; border-radius: 7px; font-weight: 800; font-size: .9rem; }

/* ================= Calendar ================= */
.calendar {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  grid-auto-flow: dense;
  gap: var(--gap);
  padding: 18px;
  border-radius: 22px;
  background:
    radial-gradient(circle at 20% 0%, rgba(255,255,255,.12), transparent 60%),
    linear-gradient(160deg, rgba(120, 22, 34, .92), rgba(70, 10, 20, .92));
  border: 4px solid var(--gold);
  box-shadow: 0 20px 60px rgba(0,0,0,.45), inset 0 0 0 3px rgba(0,0,0,.25), inset 0 0 40px rgba(0,0,0,.35);
  position: relative;
}
.calendar::before {
  /* snow cap on top of the calendar */
  content: ""; position: absolute; left: -10px; right: -10px; top: -16px; height: 28px;
  background:
    radial-gradient(ellipse 30px 16px at 5% 60%, #fff 98%, transparent) ,
    radial-gradient(ellipse 50px 18px at 18% 55%, #fff 98%, transparent),
    radial-gradient(ellipse 40px 15px at 33% 60%, #fff 98%, transparent),
    radial-gradient(ellipse 60px 18px at 50% 55%, #fff 98%, transparent),
    radial-gradient(ellipse 40px 16px at 66% 60%, #fff 98%, transparent),
    radial-gradient(ellipse 55px 18px at 82% 55%, #fff 98%, transparent),
    radial-gradient(ellipse 35px 15px at 96% 60%, #fff 98%, transparent);
  filter: drop-shadow(0 3px 2px rgba(0,0,0,.2));
  pointer-events: none;
}

.cell {
  position: relative;
  aspect-ratio: 1;
  perspective: 900px;
  border-radius: 10px;
}
.cell.wide { grid-column: span 2; aspect-ratio: auto; }
.cell.big  { grid-column: span 2; grid-row: span 2; aspect-ratio: auto; }

.inside {
  position: absolute; inset: 0;
  border-radius: 10px;
  background: radial-gradient(circle at 50% 40%, #fff7dd, #e9d6a8 70%, #cfb57c);
  box-shadow: inset 0 4px 14px rgba(0,0,0,.45);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--ink); text-align: center; gap: 2px;
  font-size: .8rem; font-weight: 800;
}
.inside .gift { font-size: 2rem; line-height: 1; transition: transform .3s; }
.cell.big .inside .gift { font-size: 3.6rem; }
.inside small { opacity: .7; }

.door {
  position: absolute; inset: 0;
  transform-origin: left center;
  transform-style: preserve-3d;
  transition: transform 1.1s cubic-bezier(.25, 1.3, .45, 1);
  cursor: pointer;
  border: none; padding: 0; background: none; font: inherit; color: inherit;
  border-radius: 10px;
}
.door:focus-visible { outline: 3px solid var(--gold-light); outline-offset: 3px; }

.door .face {
  position: absolute; inset: 0; border-radius: 10px;
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
}
.door .front {
  display: flex; align-items: center; justify-content: center;
  border: 2px solid rgba(255, 230, 160, .6);
  box-shadow: inset 0 0 0 4px rgba(0,0,0,.12), 0 4px 10px rgba(0,0,0,.35);
  overflow: hidden;
}
.door .front::after {
  /* knob */
  content: ""; position: absolute; right: 8px; top: 50%;
  width: 8px; height: 8px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff6c2, var(--gold) 60%, #9c7a24);
  box-shadow: 0 1px 2px rgba(0,0,0,.5);
  transform: translateY(-50%);
}
.door .back {
  transform: rotateY(180deg);
  background: linear-gradient(90deg, #d8c39a, #efe0bd);
  box-shadow: inset 0 0 10px rgba(0,0,0,.25);
}

.num {
  font-family: "Mountains of Christmas", cursive; font-weight: 700;
  font-size: clamp(1.8rem, 5vw, 2.6rem);
  color: #fff;
  text-shadow: 0 2px 0 rgba(0,0,0,.35), 0 0 12px rgba(255,255,255,.25);
  position: relative; z-index: 1;
}
.cell.big .num { font-size: clamp(3rem, 10vw, 5.5rem); }

/* Door themes */
.theme-0 .front { background: radial-gradient(circle at 30% 25%, #2d8a5a, var(--green-dark)); }
.theme-1 .front {
  background:
    repeating-linear-gradient(45deg, rgba(255,255,255,.14) 0 8px, transparent 8px 18px),
    radial-gradient(circle at 30% 25%, #d23a48, var(--red-dark));
}
.theme-2 .front {
  background:
    radial-gradient(circle, rgba(255,255,255,.35) 2px, transparent 2.5px) 0 0 / 16px 16px,
    radial-gradient(circle at 30% 25%, #2a4f8f, #15295a);
}
.theme-3 .front { background: radial-gradient(circle at 30% 25%, #f0cd6a, #a67c1e); }
.theme-3 .num { color: #5a1a10; text-shadow: 0 1px 0 rgba(255,255,255,.5); }
.theme-4 .front {
  background:
    repeating-linear-gradient(90deg, rgba(255,255,255,.9) 0 10px, #c32b38 10px 20px);
}
.theme-4 .num { background: var(--red-dark); border-radius: 50%; width: 1.7em; height: 1.7em; display: grid; place-items: center; font-size: clamp(1.4rem, 4vw, 2rem); }
.theme-5 .front {
  background:
    linear-gradient(transparent 44%, var(--gold) 44% 56%, transparent 56%),
    linear-gradient(90deg, transparent 44%, var(--gold) 44% 56%, transparent 56%),
    radial-gradient(circle at 30% 25%, #2d8a5a, var(--green-dark));
}
.theme-5 .num { background: rgba(18, 74, 47, .85); padding: 0 .3em; border-radius: 8px; }

.cell.big .front {
  background:
    linear-gradient(transparent 46%, var(--gold) 46% 54%, transparent 54%),
    linear-gradient(90deg, transparent 46%, var(--gold) 46% 54%, transparent 54%),
    radial-gradient(circle at 30% 25%, #d23a48, var(--red-dark));
}
.cell.big .num { background: rgba(125, 21, 32, .9); padding: 0 .25em; border-radius: 14px; }
.cell.big .front::before {
  content: "🎀"; position: absolute; top: calc(50% - 1.5em); left: 50%;
  transform: translate(-50%, -50%); font-size: 2.6rem;
}

/* States */
.cell.open .door { transform: rotateY(-108deg); }
.cell.open .door:hover { transform: rotateY(-112deg); }
.cell.open .inside { cursor: pointer; }
.cell.open .inside:hover .gift { transform: scale(1.15) rotate(-6deg); }

.cell.locked .front { filter: saturate(.8) brightness(.88); }
.cell.locked .door { cursor: not-allowed; }
.cell.unlocked:not(.open) .door:hover { transform: rotateY(-14deg); }

.cell.today:not(.open) .door .front {
  animation: todayGlow 1.8s ease-in-out infinite;
}
@keyframes todayGlow {
  0%,100% { box-shadow: 0 0 0 2px var(--gold), 0 0 14px 2px rgba(255, 213, 74, .6); }
  50%     { box-shadow: 0 0 0 3px var(--gold-light), 0 0 30px 8px rgba(255, 213, 74, .9); }
}

.cell.shake { animation: shake .5s; }
@keyframes shake {
  0%,100% { transform: translateX(0); }
  20% { transform: translateX(-6px) rotate(-2deg); }
  40% { transform: translateX(6px) rotate(2deg); }
  60% { transform: translateX(-4px) rotate(-1deg); }
  80% { transform: translateX(4px) rotate(1deg); }
}

.lock-icon {
  position: absolute; left: 8px; top: 6px; font-size: .8rem; opacity: .75; z-index: 1;
}

footer { text-align: center; margin-top: 26px; opacity: .85; font-size: .95rem; text-shadow: 0 1px 3px rgba(0,0,0,.6); }

/* ================= Sparkles ================= */
.sparkle {
  position: fixed; z-index: 50; pointer-events: none;
  font-size: 18px; line-height: 1;
  will-change: transform, opacity;
}

/* ================= Modal ================= */
.modal { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 16px; }
.modal[hidden] { display: none; }
.modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(5, 10, 30, .6);
  backdrop-filter: blur(4px);
  animation: fadeIn .3s ease both;
}
.joke-card {
  position: relative;
  width: min(560px, 100%);
  max-height: calc(100vh - 32px); overflow-y: auto;
  background:
    radial-gradient(circle at 50% 0%, #fff, var(--cream) 70%);
  color: var(--ink);
  border-radius: 18px;
  padding: 34px 30px 28px;
  border: 6px solid transparent;
  background-clip: padding-box;
  box-shadow: 0 0 0 6px var(--red), 0 0 0 9px var(--gold), 0 30px 80px rgba(0,0,0,.55);
  animation: cardIn .7s cubic-bezier(.2, 1.4, .4, 1) both;
  text-align: center;
}
.modal.closing .joke-card { animation: cardOut .3s ease-in both; }
.modal.closing .modal-backdrop { animation: fadeOut .3s ease-in both; }

@keyframes cardIn {
  0%   { opacity: 0; transform: perspective(800px) rotateX(70deg) scale(.4) translateY(80px); }
  100% { opacity: 1; transform: perspective(800px) rotateX(0) scale(1) translateY(0); }
}
@keyframes cardOut { to { opacity: 0; transform: scale(.7) translateY(40px); } }
@keyframes fadeIn { from { opacity: 0; } }
@keyframes fadeOut { to { opacity: 0; } }

.card-holly { font-size: 2.2rem; margin-top: -8px; }
.joke-card h2 {
  font-family: "Mountains of Christmas", cursive; font-weight: 700;
  color: var(--red); font-size: 2.2rem; margin: 4px 0 14px;
}
.joke-body { font-size: 1.15rem; line-height: 1.6; text-align: left; }
.joke-body p { margin: 0 0 .8em; }
.joke-body .question { font-weight: 800; text-align: center; font-size: 1.3rem; }
.joke-body .one-liner { text-align: center; font-size: 1.3rem; font-weight: 600; }
.joke-body .punchline {
  text-align: center; font-size: 1.35rem; font-weight: 800; color: var(--green);
  animation: pop .5s cubic-bezier(.2, 1.6, .4, 1) both;
}
@keyframes pop { from { opacity: 0; transform: scale(.5); } }
.joke-body .story p:last-child { font-weight: 800; color: var(--green); }

.reveal-btn {
  display: block; margin: 8px auto 0;
  font: 800 1.05rem "Nunito", sans-serif;
  color: #fff; background: linear-gradient(180deg, #d23a48, var(--red-dark));
  border: 2px solid var(--gold); border-radius: 999px;
  padding: 10px 22px; cursor: pointer;
  box-shadow: 0 4px 0 #4f0c14, 0 6px 14px rgba(0,0,0,.25);
  transition: transform .1s, box-shadow .1s;
}
.reveal-btn:hover { transform: translateY(-1px); }
.reveal-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #4f0c14; }

.close {
  position: absolute; top: 8px; right: 12px;
  border: none; background: none; cursor: pointer;
  font-size: 2rem; line-height: 1; color: var(--red);
  width: 40px; height: 40px; border-radius: 50%;
}
.close:hover { background: rgba(179, 32, 46, .1); }

/* ================= Toast ================= */
.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 120;
  transform: translate(-50%, calc(100% + 40px));
  background: var(--cream); color: var(--ink);
  padding: 12px 20px; border-radius: 999px;
  border: 3px solid var(--gold);
  box-shadow: 0 10px 30px rgba(0,0,0,.4);
  font-weight: 800; max-width: calc(100% - 32px); text-align: center;
  transition: transform .4s cubic-bezier(.2, 1.4, .4, 1);
}
.toast.show { transform: translate(-50%, 0); }

/* ================= Responsive ================= */
@media (max-width: 640px) {
  :root { --gap: 8px; }
  .calendar { grid-template-columns: repeat(3, 1fr); padding: 12px; }
  .moon { width: 60px; height: 60px; }
  .xmas-tree { height: 34vh; right: -10px; opacity: .9; }
  .joke-card { padding: 30px 20px 22px; }
  .inside .gift { font-size: 1.6rem; }
}

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