:root {
  --red: #c8102e; --red-dark: #8c0b20;
  --green: #1f7a4d; --green-dark: #14532d;
  --gold: #f5c542; --cream: #fff8ec; --ink: #2b2118;
  --radius: 18px;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: 'Nunito', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color: var(--cream);
  background: linear-gradient(180deg, #0b1d3a 0%, #16365f 55%, #245a7a 100%) fixed;
  overflow-x: hidden;
}

/* ---------- scenery ---------- */
.stars {
  position: fixed; inset: 0; pointer-events: none;
  background-image:
    radial-gradient(1.5px 1.5px at 20px 40px, #fff, transparent),
    radial-gradient(1px 1px at 90px 120px, #fff, transparent),
    radial-gradient(2px 2px at 160px 70px, #ffe9a8, transparent),
    radial-gradient(1px 1px at 230px 200px, #fff, transparent),
    radial-gradient(1.5px 1.5px at 60px 250px, #fff, transparent);
  background-size: 300px 300px;
  opacity: .75;
  animation: twinkle 5s ease-in-out infinite alternate;
}
.moon {
  position: fixed; top: 34px; right: 26px; width: 66px; height: 66px; border-radius: 50%;
  background: #fdf6d8; opacity: .92; pointer-events: none;
  box-shadow: 0 0 40px 10px rgba(253, 246, 216, .35), inset -13px -6px 0 0 #e9e0b8;
}
.hills { position: fixed; left: 0; right: 0; bottom: 0; width: 100%; height: 130px; pointer-events: none; z-index: 1; }
#snow { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 20; }

.flyer {
  position: fixed; top: 11vh; left: 0; width: 130px; z-index: 1; pointer-events: none;
  animation: fly 32s linear 4s infinite;
}
.flyer svg { width: 100%; height: auto; display: block; }
.nose { animation: pulse 1.1s ease-in-out infinite alternate; transform-origin: center; transform-box: fill-box; }

/* ---------- layout ---------- */
main { position: relative; z-index: 2; max-width: 880px; margin: 0 auto; padding: 18px 16px 170px; }
.loading { text-align: center; font-size: 1.2rem; padding: 80px 0; }

.hero { text-align: center; padding-top: 6px; }
.hero h1 {
  font-family: 'Mountains of Christmas', cursive; font-weight: 700;
  font-size: clamp(2.1rem, 8vw, 3.8rem); line-height: 1.05; margin: 10px 0 4px;
  color: var(--gold); text-shadow: 0 3px 0 rgba(0, 0, 0, .35), 0 0 24px rgba(245, 197, 66, .45);
}
.hero .count { margin: 0; font-weight: 800; letter-spacing: .04em; opacity: .9; }
.lights {
  height: 22px; margin: 0 -16px;
  background:
    radial-gradient(circle at 12px 11px, #ff4d5e 0 5px, transparent 6px),
    radial-gradient(circle at 36px 11px, #ffd166 0 5px, transparent 6px),
    radial-gradient(circle at 60px 11px, #5fd38d 0 5px, transparent 6px),
    radial-gradient(circle at 84px 11px, #6ec6ff 0 5px, transparent 6px);
  background-size: 96px 22px; background-repeat: repeat-x;
  filter: drop-shadow(0 0 5px rgba(255, 210, 120, .9));
  animation: blink 2.2s steps(2) infinite;
}

/* ---------- Pip ---------- */
.pip { display: flex; align-items: flex-end; gap: 12px; margin: 18px 0 8px; }
.pip-svg { width: 92px; flex: none; height: auto; filter: drop-shadow(0 6px 6px rgba(0, 0, 0, .35)); }
.wave { transform-origin: 86px 112px; animation: wave 1.6s ease-in-out infinite; }
.bubble {
  position: relative; background: var(--cream); color: var(--ink); border-radius: 18px;
  padding: 14px 16px; flex: 1; box-shadow: 0 8px 22px rgba(0, 0, 0, .3); line-height: 1.45;
}
.bubble::before {
  content: ''; position: absolute; left: -9px; bottom: 26px; width: 18px; height: 18px;
  background: var(--cream); transform: rotate(45deg); border-radius: 3px;
}
.bubble p { margin: 0 0 .7em; }
.bubble p:last-child { margin-bottom: 0; }

/* ---------- doors ---------- */
.calendar { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 18px 0; }
@media (min-width: 640px) { .calendar { grid-template-columns: repeat(6, 1fr); gap: 14px; } }
.door {
  position: relative; aspect-ratio: 1; border: 0; border-radius: 14px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: #fff; font-family: inherit; overflow: hidden;
  box-shadow: 0 6px 0 rgba(0, 0, 0, .3), 0 10px 18px rgba(0, 0, 0, .25);
  transition: transform .15s;
}
.door:nth-child(3n+1) { background: linear-gradient(145deg, #d62839, #9d0d24); }
.door:nth-child(3n+2) { background: linear-gradient(145deg, #2a9d5c, #17653a); }
.door:nth-child(3n)   { background: linear-gradient(145deg, #3b6fb6, #234a85); }
.door::before, .door::after { content: ''; position: absolute; background: rgba(255, 255, 255, .2); pointer-events: none; }
.door::before { left: 50%; top: 0; bottom: 0; width: 9px; margin-left: -4.5px; }
.door::after  { top: 50%; left: 0; right: 0; height: 9px; margin-top: -4.5px; }
.door .n { position: relative; z-index: 1; font-family: 'Mountains of Christmas', cursive; font-weight: 700; font-size: 2rem; line-height: 1; text-shadow: 0 2px 0 rgba(0, 0, 0, .35); }
.door .ic { position: relative; z-index: 1; font-size: 1.05rem; }
.door .dt { position: relative; z-index: 1; font-size: .68rem; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; opacity: .85; }
.door:hover:not(.locked):not(.waiting) { transform: translateY(-3px) rotate(-1deg); }
.door.locked, .door.waiting { filter: saturate(.3) brightness(.7); cursor: not-allowed; }
.door.solved { background: linear-gradient(145deg, #f7d060, #c99a1a) !important; color: #5a3a00; }
.door.solved .n { text-shadow: none; }
.door.current { animation: glow 1.7s ease-in-out infinite; }
.door.gift {
  grid-column: 1 / -1; aspect-ratio: auto; height: 110px;
  background: linear-gradient(145deg, #9b2fd6, #5a1a8a) !important;
}
.door.gift .n { font-size: 1.9rem; }
.door.gift.locked { filter: saturate(.55) brightness(.8); }
.preview-note { background: #fff1c2; color: var(--ink); font-weight: 800; border-radius: 12px; padding: 8px 14px; text-align: center; }
.rose-svg { height: 118px; width: auto; flex: none; overflow: visible; filter: drop-shadow(0 3px 4px rgba(0, 0, 0, .3)); }
.rose { transform-box: view-box; transform-origin: 50px 98px; animation: sway 4s ease-in-out infinite alternate; }
.finale-rose { display: flex; justify-content: center; margin: 10px 0 -6px; }
.finale-rose .rose-svg { height: auto; width: min(340px, 80vw); filter: drop-shadow(0 0 18px rgba(255, 120, 150, .35)) drop-shadow(0 6px 8px rgba(0, 0, 0, .35)); }
.wing { transform-box: fill-box; transform-origin: 50% 100%; animation: flap .09s linear infinite alternate; }
.wing.w2 { animation-delay: .045s; }

/* ---------- cards ---------- */
.card {
  background: var(--cream); color: var(--ink); border-radius: var(--radius);
  padding: 20px; margin: 16px 0; box-shadow: 0 10px 30px rgba(0, 0, 0, .35);
}
.card::before {
  content: ''; display: block; height: 8px; margin: -20px -20px 16px; border-radius: 18px 18px 0 0;
  background: repeating-linear-gradient(135deg, #c8102e 0 14px, #fff 14px 28px, #1f7a4d 28px 42px);
}
.card h2 { font-family: 'Mountains of Christmas', cursive; font-size: 2rem; margin: 6px 0 10px; color: var(--red-dark); line-height: 1.1; }
.badge { display: inline-block; background: var(--green); color: #fff; font-weight: 800; font-size: .85rem; padding: 4px 12px; border-radius: 999px; }
.daynum { margin: 8px 0 0; font-weight: 800; color: #8a7a5a; font-size: .85rem; letter-spacing: .06em; text-transform: uppercase; }
.riddle-text { font-size: 1.1rem; line-height: 1.55; }
.riddle-text em { color: #5a3a1a; }
.card figure { margin: 16px 0 0; }
.card img, .card video, .card iframe { width: 100%; border-radius: 12px; display: block; background: #000; }
.card iframe { aspect-ratio: 16 / 9; border: 0; }
.card audio { width: 100%; }
.card figcaption { font-size: .9rem; color: #7a6a4a; margin-top: 6px; text-align: center; }

.pw label { font-weight: 800; display: block; margin-bottom: 8px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
input[type=text] {
  flex: 1; min-width: 0; font: 700 1.1rem 'Nunito', sans-serif; padding: 12px 14px;
  border-radius: 12px; border: 2px solid #d9c9a8; background: #fff; color: var(--ink);
}
input[type=text]:focus { outline: 3px solid var(--gold); border-color: var(--gold); }
.shake { animation: shake .4s; }
.fb { min-height: 1.5em; margin: 10px 0 4px; font-weight: 800; }
.fb.bad { color: var(--red); }
.fb.good { color: var(--green); }
.small { font-size: .85rem; color: #8a7a5a; margin: 6px 0 0; }
.btn.ghost.ready { background: #fff1c2; border-style: solid; animation: nudge 2.4s ease-in-out infinite; }

/* ---------- Pip's hint ---------- */
.pip-hint { display: flex; align-items: flex-end; gap: 12px; margin-top: 16px; }
.pip-wrap { position: relative; flex: none; width: 84px; }
.pip-hint .pip-svg { width: 84px; display: block; }
.hint-bubble { background: #fff1c2; border: 2px solid var(--gold); font-weight: 700; min-height: 64px; }
.hint-bubble::before { background: #fff1c2; border-left: 2px solid var(--gold); border-bottom: 2px solid var(--gold); left: -10px; }
.hint-bubble small { display: block; font-size: .72rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: #a07a10; margin-bottom: 4px; }
.dots { display: inline-flex; gap: 5px; padding: 6px 0; }
.dots i { width: 9px; height: 9px; border-radius: 50%; background: #a07a10; animation: dot 1s ease-in-out infinite; }
.dots i:nth-child(2) { animation-delay: .15s; }
.dots i:nth-child(3) { animation-delay: .3s; }
.spark { position: absolute; font-size: 1.1rem; opacity: 0; pointer-events: none; }
.spark.s1 { top: 4px; left: -6px; } .spark.s2 { top: -8px; right: 2px; } .spark.s3 { top: 46px; right: -10px; }

/* entrance: Pip hops in, the bubble pops after he lands */
.pip-hint.enter .pip-svg { animation: pipHop 1.1s cubic-bezier(.3, 1.3, .5, 1) both; transform-origin: 50% 100%; }
.pip-hint.enter .hint-bubble { animation: bubbleIn .45s cubic-bezier(.2, 1.5, .4, 1) .9s both; transform-origin: 0 100%; }
.pip-hint.enter .spark { animation: spark 1.2s ease-out 1s both; }
.pip-hint.enter .spark.s2 { animation-delay: 1.1s; }
.pip-hint.enter .spark.s3 { animation-delay: 1.25s; }
.pip-hint.talking .mouth { animation: talk .16s ease-in-out infinite alternate; transform-origin: center; transform-box: fill-box; }
.pip-hint.talking .pip-svg { animation: bob .5s ease-in-out infinite alternate; }
.pip-hint.idle .pip-svg { animation: bob 2.6s ease-in-out infinite alternate; }
.solved-box { background: #e6f6ec; border: 2px solid var(--green); color: var(--green-dark); border-radius: 14px; padding: 14px 16px; margin: 16px 0; font-weight: 700; }

.btn {
  font: 800 1rem 'Nunito', sans-serif; border: 0; border-radius: 999px; padding: 12px 22px; cursor: pointer;
  background: var(--red); color: #fff; box-shadow: 0 4px 0 var(--red-dark); text-decoration: none; display: inline-block;
}
.btn:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--red-dark); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.ghost { background: transparent; color: var(--green); border: 2px dashed var(--green); box-shadow: none; padding: 10px 18px; }
.btn.green { background: var(--green); box-shadow: 0 4px 0 var(--green-dark); }
.back { background: rgba(255, 255, 255, .15); color: #fff; border: 0; border-radius: 999px; padding: 8px 16px; font: 800 .95rem 'Nunito', sans-serif; cursor: pointer; margin-top: 4px; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }

.codebox { margin: 16px 0; padding: 16px; background: #fff; border: 3px dashed var(--red); border-radius: 14px; text-align: center; }
.codebox small { display: block; font-weight: 800; color: #8a7a5a; letter-spacing: .06em; text-transform: uppercase; }
.codebox code { display: block; font: 800 clamp(1.1rem, 5vw, 1.8rem)/1.3 ui-monospace, Menlo, Consolas, monospace; margin: 8px 0 12px; word-break: break-all; color: var(--red-dark); }

footer { text-align: center; opacity: .75; font-size: .9rem; margin-top: 26px; }

/* ---------- overlay + toast ---------- */
.overlay { position: fixed; inset: 0; background: rgba(5, 12, 28, .78); display: grid; place-items: center; z-index: 50; padding: 16px; overflow-y: auto; }
.modal { max-width: 460px; width: 100%; text-align: center; animation: pop .35s cubic-bezier(.2, 1.4, .4, 1); }
.modal h2 { font-size: 2.3rem; }
.modal .actions { justify-content: center; }
.toast {
  position: fixed; left: 50%; top: 14px; transform: translateX(-50%); z-index: 60; max-width: 92vw;
  background: var(--cream); color: var(--ink); font-weight: 800; padding: 10px 18px; border-radius: 999px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .4);
}

/* ---------- animation ---------- */
@keyframes twinkle { from { opacity: .45; } to { opacity: .9; } }
@keyframes blink { 50% { opacity: .6; filter: drop-shadow(0 0 2px rgba(255, 210, 120, .5)); } }
@keyframes glow { 0%, 100% { box-shadow: 0 6px 0 rgba(0, 0, 0, .3), 0 0 0 0 rgba(245, 197, 66, .8); } 50% { box-shadow: 0 6px 0 rgba(0, 0, 0, .3), 0 0 22px 8px rgba(245, 197, 66, .85); } }
@keyframes wave { 0%, 100% { transform: rotate(0); } 50% { transform: rotate(-22deg); } }
@keyframes pulse { from { opacity: .7; filter: drop-shadow(0 0 2px #ff3b3b); } to { opacity: 1; filter: drop-shadow(0 0 9px #ff3b3b); } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 20%, 60% { transform: translateX(-7px); } 40%, 80% { transform: translateX(7px); } }
@keyframes pop { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes pipHop {
  0%   { transform: translate(-130%, 40px) rotate(-30deg) scale(.6); opacity: 0; }
  45%  { transform: translate(-20%, -46px) rotate(12deg) scale(1); opacity: 1; }
  70%  { transform: translate(0, 0) scale(1.12, .86); }
  85%  { transform: translate(0, -10px) scale(.96, 1.05); }
  100% { transform: none; }
}
@keyframes bubbleIn { from { transform: scale(.3); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes spark { 0% { opacity: 0; transform: scale(.3); } 30% { opacity: 1; transform: scale(1.3) rotate(20deg); } 100% { opacity: 0; transform: translateY(-26px) scale(.6) rotate(60deg); } }
@keyframes talk { from { transform: scaleY(1); } to { transform: scaleY(.25) translateY(-2px); } }
@keyframes sway { from { transform: rotate(-3deg); } to { transform: rotate(3deg); } }
@keyframes flap { from { transform: scaleY(1); } to { transform: scaleY(.35); } }
@keyframes bob { from { transform: translateY(0); } to { transform: translateY(-5px); } }
@keyframes dot { 0%, 100% { transform: translateY(0); opacity: .4; } 50% { transform: translateY(-6px); opacity: 1; } }
@keyframes nudge { 0%, 85%, 100% { transform: rotate(0); } 88% { transform: rotate(-3deg); } 92% { transform: rotate(3deg); } 96% { transform: rotate(-2deg); } }
@keyframes fly {
  0%   { transform: translate(-200px, 0) rotate(-4deg); }
  50%  { transform: translate(50vw, -26px) rotate(2deg); }
  100% { transform: translate(calc(100vw + 200px), 10px) rotate(-3deg); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .flyer { display: none; }
}
