:root {
  --night-1: #22336b;
  --night-2: #0d1636;
  --night-3: #070b1f;
  --gold: #f3cf6b;
  --gold-deep: #c9972f;
  --cream: #fff8ea;
  --berry: #c81d34;
  --pine: #1f6b3d;
  --ink: #3a1d12;
  --font-body: "Fredoka", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-fancy: "Mountains of Christmas", "Fredoka", cursive;
}

* { box-sizing: border-box; }

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

body {
  font-family: var(--font-body);
  color: var(--cream);
  background:
    radial-gradient(120% 70% at 50% 0%, var(--night-1) 0%, var(--night-2) 55%, var(--night-3) 100%) fixed;
  background-color: var(--night-2);
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; color: inherit; }

/* ---------- canvases ---------- */
.layer { position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none; }
.layer--snow { z-index: 0; }
.layer--fx { z-index: 50; }

/* ---------- layout ---------- */
.app {
  position: relative;
  z-index: 1;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: max(14px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  gap: 10px;
}

.masthead { text-align: center; display: grid; gap: 4px; justify-items: center; }

.title {
  margin: 0;
  font-family: var(--font-fancy);
  font-size: clamp(30px, 7vw, 46px);
  line-height: 1;
  color: var(--gold);
  text-shadow: 0 2px 0 #7a1222, 0 0 18px rgba(243, 207, 107, 0.35);
  letter-spacing: 0.5px;
}

.status {
  display: grid;
  gap: 2px;
  padding: 6px 18px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.14);
  backdrop-filter: blur(4px);
}
.status-main { font-weight: 700; font-size: 20px; color: #fff; }
.status-sub { font-size: 14px; opacity: 0.85; }

.progress {
  list-style: none;
  display: flex;
  gap: 4px;
  margin: 4px 0 0;
  padding: 0;
  flex-wrap: wrap;
  justify-content: center;
  max-width: 340px;
}
.progress li {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.16);
  transition: background 0.4s, transform 0.4s;
}
.progress li.is-past { background: rgba(243, 207, 107, 0.45); }
.progress li.is-done { background: var(--gold); box-shadow: 0 0 6px rgba(243, 207, 107, 0.8); }
.progress li.is-today { background: #fff; transform: scale(1.35); box-shadow: 0 0 8px #fff; }

/* ---------- the stage ---------- */
.stage-wrap {
  flex: 1;
  width: 100%;
  display: grid;
  place-items: center;
  min-height: 0;
}

.stage {
  --aw: 100;
  --ah: 140;
  position: relative;
  aspect-ratio: var(--aw) / var(--ah);
  width: min(100%, 560px, calc((100svh - 210px) * var(--aw) / var(--ah)));
  min-width: 260px;
  container-type: inline-size;
  transition: opacity 0.35s ease, transform 0.35s ease;
}
.stage.is-swapping { opacity: 0; transform: scale(0.96); }

.stage-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 18px 30px rgba(0, 0, 0, 0.45));
}

.fairy { animation: fairy 2.4s ease-in-out infinite alternate; }
@keyframes fairy { from { opacity: 0.25; } to { opacity: 1; } }

/* ---------- doors ---------- */
.door {
  position: absolute;
  padding: 0;
  margin: 0;
  border: 0;
  background: none;
  cursor: pointer;
  perspective: 600px;
  line-height: 1;
  z-index: 1;
  outline: none;
}
.door:focus-visible .door-front { box-shadow: 0 0 0 0.08em #fff, 0 0 0 0.16em var(--gold); }
.door.is-open { z-index: 3; }
.door.is-opening { z-index: 4; }

.door-inside,
.door-face {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: var(--r, 8%);
}

.door-inside {
  background: radial-gradient(circle at 50% 38%, color-mix(in srgb, var(--inside) 55%, #fff) 0%, var(--inside) 75%);
  box-shadow: inset 0 0.08em 0.25em rgba(0, 0, 0, 0.65);
  overflow: hidden;
}
.door-emoji {
  font-size: 0.8em;
  opacity: 0;
  transform: scale(0.3);
  transition: transform 0.6s cubic-bezier(0.3, 1.6, 0.5, 1) 0.25s, opacity 0.3s 0.25s;
  filter: drop-shadow(0 0.04em 0.06em rgba(0, 0, 0, 0.4));
}
.door.is-open .door-emoji { opacity: 1; transform: scale(1); }

.door-leaf {
  position: absolute;
  inset: 0;
  transform-origin: 0% 50%;
  transform-style: preserve-3d;
  transition: transform 1s cubic-bezier(0.34, 1.25, 0.5, 1);
}
.door.is-open .door-leaf { transform: rotateY(-112deg); }

.door-face { backface-visibility: hidden; -webkit-backface-visibility: hidden; }

.door-front {
  background: var(--door);
  color: var(--ink-on);
  box-shadow:
    inset 0 0 0 0.05em rgba(255, 255, 255, 0.35),
    inset 0 -0.08em 0.12em rgba(0, 0, 0, 0.22),
    0 0.05em 0.1em rgba(0, 0, 0, 0.35);
}
.door-back {
  transform: rotateY(180deg);
  background: color-mix(in srgb, var(--door) 55%, #fff6e4);
  box-shadow: inset 0 0 0.2em rgba(0, 0, 0, 0.25);
}

.door-num {
  font-weight: 700;
  font-size: 0.62em;
  letter-spacing: -0.02em;
  text-shadow: 0 0.03em 0 rgba(0, 0, 0, 0.18);
  position: relative;
}

/* today */
.door.is-today:not(.is-open) {
  animation: today-glow 1.8s ease-in-out infinite alternate, today-wiggle 4.5s ease-in-out infinite;
}
@keyframes today-glow {
  from { filter: drop-shadow(0 0 0.06em rgba(255, 228, 140, 0.6)); }
  to   { filter: drop-shadow(0 0 0.22em rgba(255, 228, 140, 1)) drop-shadow(0 0 0.08em #fff); }
}
@keyframes today-wiggle {
  0%, 84%, 100% { transform: rotate(0); }
  87% { transform: rotate(-5deg) scale(1.05); }
  90% { transform: rotate(5deg) scale(1.05); }
  93% { transform: rotate(-3deg); }
  96% { transform: rotate(2deg); }
}
.door-star {
  display: none;
  position: absolute;
  left: 50%;
  top: 0;
  font-size: 0.42em;
  transform: translate(-50%, -105%);
  animation: bob 1.2s ease-in-out infinite alternate;
  pointer-events: none;
  filter: drop-shadow(0 0 0.2em rgba(255, 220, 120, 0.9));
}
.door.is-today:not(.is-open) .door-star { display: block; }
@keyframes bob { to { transform: translate(-50%, -135%); } }

.door.is-jiggle { animation: jiggle 0.45s ease-in-out; }
@keyframes jiggle {
  0%, 100% { transform: translateX(0) rotate(0); }
  20% { transform: translateX(-6%) rotate(-4deg); }
  40% { transform: translateX(5%) rotate(3deg); }
  60% { transform: translateX(-4%) rotate(-2deg); }
  80% { transform: translateX(2%) rotate(1deg); }
}

/* --- door styles --- */
.door--tile { --r: 9% / 11%; }
.door--tile .door-front::before {
  content: "";
  position: absolute;
  inset: 7%;
  border: 0.035em dashed color-mix(in srgb, var(--ink-on) 45%, transparent);
  border-radius: inherit;
}

.door--ornament { --r: 50%; }
.door--ornament .door-front {
  background:
    radial-gradient(circle at 32% 28%, rgba(255, 255, 255, 0.85) 0 7%, rgba(255, 255, 255, 0.25) 14%, transparent 32%),
    radial-gradient(circle at 50% 50%, var(--door) 45%, color-mix(in srgb, var(--door) 65%, #000) 100%);
  box-shadow: 0 0.06em 0.1em rgba(0, 0, 0, 0.45);
}
.door--ornament::before {
  /* the little cap + hook */
  content: "";
  position: absolute;
  left: 50%;
  top: -9%;
  width: 26%;
  height: 14%;
  transform: translateX(-50%);
  background: linear-gradient(90deg, #a8812c, #f7dc8a 45%, #a8812c);
  border-radius: 18% 18% 10% 10%;
  z-index: 2;
}

.door--star { --r: 0; }
.door--star .door-face,
.door--star .door-inside {
  clip-path: polygon(50% 0%, 61.8% 35.4%, 100% 38.2%, 69.1% 61.8%, 80.9% 100%, 50% 76.4%, 19.1% 100%, 30.9% 61.8%, 0% 38.2%, 38.2% 35.4%);
}
.door--star .door-front {
  background: radial-gradient(circle at 45% 40%, #fff6c8 0%, #f7d256 40%, #d39b20 100%);
  color: #6b3b00;
}
.door--star .door-back { background: #f2cf68; }
.door--star .door-num { font-size: 0.42em; transform: translateY(12%); }
.door--star .door-emoji { font-size: 0.55em; transform: translateY(10%) scale(0.3); }
.door--star.is-open .door-emoji { transform: translateY(10%) scale(1); }

.door--present { --r: 6%; }
.door--present .door-front {
  background:
    linear-gradient(90deg, transparent 42%, var(--ribbon, #f3cf6b) 42% 58%, transparent 58%),
    linear-gradient(0deg, transparent 42%, var(--ribbon, #f3cf6b) 42% 58%, transparent 58%),
    var(--door);
}
.door--present .door-num {
  background: var(--cream);
  color: var(--ink);
  border-radius: 50%;
  width: 1.4em; height: 1.4em;
  display: grid; place-items: center;
  font-size: 0.42em;
}
.door--present::after {
  /* bow */
  content: "🎀";
  position: absolute;
  left: 50%;
  top: 0;
  transform: translate(-50%, -55%);
  font-size: 0.4em;
  z-index: 2;
  pointer-events: none;
}

.door--window, .door--arch { --r: 10%; }
.door--arch { --r: 50% 50% 6% 6% / 30% 30% 4% 4%; }
.door--window .door-front,
.door--arch .door-front {
  box-shadow:
    0 0 0 0.06em #fff,
    0 0 0 0.09em rgba(110, 56, 24, 0.6),
    inset 0 -0.08em 0.12em rgba(0, 0, 0, 0.18);
}
.door--window .door-front::before {
  /* shutter slats */
  content: "";
  position: absolute;
  inset: 12% 14%;
  background: repeating-linear-gradient(180deg, rgba(0, 0, 0, 0.09) 0 0.05em, transparent 0.05em 0.14em);
  border-radius: 6%;
}
.door--window .door-inside,
.door--arch .door-inside {
  background: radial-gradient(circle at 50% 40%, #fff3c4 0%, var(--inside) 55%, #e0902d 100%);
  box-shadow: inset 0 0.05em 0.15em rgba(120, 50, 0, 0.6);
}
.door--arch .door-front::after {
  content: "";
  position: absolute;
  right: 14%;
  top: 55%;
  width: 0.09em; height: 0.09em;
  border-radius: 50%;
  background: #f3cf6b;
  box-shadow: 0 0 0 0.02em #7a4a00;
}

/* ---------- switcher ---------- */
.switcher {
  display: flex;
  gap: 6px;
  padding: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
}
.switcher button {
  border: 0;
  background: none;
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  color: rgba(255, 248, 234, 0.8);
  transition: background 0.2s, color 0.2s;
}
.switcher button:hover { color: #fff; background: rgba(255, 255, 255, 0.08); }
.switcher button[aria-pressed="true"] { background: var(--gold); color: #4a2400; }

/* ---------- modal card ---------- */
.modal { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 16px; }
.modal[hidden] { display: none; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% 45%, rgba(20, 28, 70, 0.55), rgba(3, 6, 20, 0.82));
  backdrop-filter: blur(3px);
  animation: fade-in 0.4s ease both;
}
.modal.is-closing .modal-backdrop { animation: fade-out 0.25s ease both; }
@keyframes fade-in { from { opacity: 0; } }
@keyframes fade-out { to { opacity: 0; } }

.card {
  position: relative;
  width: min(380px, 100%);
  padding: 34px 26px 22px;
  border-radius: 22px;
  background:
    radial-gradient(circle at 50% 0%, #fffdf6 0%, #fbefd6 70%, #f3dfb8 100%);
  color: var(--ink);
  text-align: center;
  box-shadow:
    0 0 0 4px #fff8ea,
    0 0 0 7px var(--berry),
    0 0 0 9px var(--gold),
    0 30px 60px rgba(0, 0, 0, 0.5);
}
.card-close {
  position: absolute;
  top: 8px; right: 10px;
  width: 36px; height: 36px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: #8a5a44;
  font-size: 26px;
  cursor: pointer;
}
.card-close:hover { background: rgba(0, 0, 0, 0.06); }

.card-ribbon {
  position: absolute;
  top: -18px;
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 20px 7px;
  background: linear-gradient(180deg, #e0283f, #a3142a);
  color: #fff;
  border-radius: 8px;
  font-size: 15px;
  white-space: nowrap;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}
.card-ribbon strong { font-size: 19px; }
.card-ribbon::before, .card-ribbon::after {
  content: "";
  position: absolute;
  top: 8px;
  border: 13px solid #8e1124;
  z-index: -1;
}
.card-ribbon::before { left: -18px; border-left-color: transparent; }
.card-ribbon::after { right: -18px; border-right-color: transparent; }

.card-emoji { font-size: 72px; line-height: 1.1; margin: 6px 0 4px; filter: drop-shadow(0 6px 8px rgba(0, 0, 0, 0.18)); }
.card-title { margin: 0; font-family: var(--font-fancy); font-size: 34px; line-height: 1.05; color: var(--berry); }
.card-desc { margin: 10px 0 0; font-size: 16px; line-height: 1.45; color: #4b2c1f; }
.card-meta {
  display: inline-block;
  margin-top: 14px;
  padding: 3px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  background: rgba(31, 107, 61, 0.12);
  color: var(--pine);
}
.card-nav { display: flex; justify-content: space-between; margin-top: 16px; gap: 8px; }
.card-nav[hidden] { display: none; }
.card-btn {
  border: 0;
  border-radius: 999px;
  padding: 7px 14px;
  background: rgba(58, 29, 18, 0.07);
  color: #6b3a26;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}
.card-btn:hover { background: rgba(58, 29, 18, 0.13); }
.card-btn[hidden] { display: block; visibility: hidden; }

/* ---------- "not yet" hand ---------- */
.nope {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 45;
  width: min(250px, 50vw);
  transform: translate(-50%, 105%);
  transition: transform 0.45s cubic-bezier(0.5, 0, 0.75, 0);
  pointer-events: none;
}
.nope.is-showing {
  transform: translate(-50%, 4%);
  transition: transform 0.55s cubic-bezier(0.2, 1.4, 0.4, 1);
}
.nope-hand { display: block; width: 100%; height: auto; overflow: visible; filter: drop-shadow(0 10px 18px rgba(0, 0, 0, 0.45)); }
.nope-wag { transform-box: view-box; transform-origin: 120px 300px; }
.nope.is-showing .nope-wag { animation: wag 0.34s ease-in-out 0.35s 6 alternate both; }
@keyframes wag {
  from { transform: rotate(-13deg); }
  to   { transform: rotate(13deg); }
}
.nope-whoosh { opacity: 0; }
.nope.is-showing .nope-whoosh { animation: whoosh 0.34s ease-in-out 0.35s 6 alternate; }
@keyframes whoosh { 50% { opacity: 0.9; } }

.nope-bubble {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  margin-left: calc(-1 * min(150px, 50vw - 16px));
  width: min(260px, 100vw - 32px);
  padding: 12px 18px 13px;
  border-radius: 20px;
  background: #fff;
  color: var(--ink);
  text-align: center;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.35);
  transform: scale(0.3) rotate(-8deg);
  transform-origin: 70% 100%;
  opacity: 0;
  transition: transform 0.25s ease, opacity 0.2s ease;
}
.nope-bubble::after {
  content: "";
  position: absolute;
  right: 34%;
  bottom: -13px;
  border: 10px solid transparent;
  border-top: 14px solid #fff;
  border-bottom: 0;
  transform: rotate(-28deg);
}
.nope.is-showing .nope-bubble {
  opacity: 1;
  transform: scale(1) rotate(-3deg);
  transition: transform 0.45s cubic-bezier(0.3, 1.6, 0.5, 1) 0.25s, opacity 0.2s 0.25s;
}
.nope-title { font-family: var(--font-fancy); font-size: 32px; line-height: 1; color: var(--berry); }
.nope-sub { margin-top: 4px; font-size: 14px; color: #6b3a26; }

/* ---------- debug ---------- */
.debug {
  display: flex;
  gap: 6px;
  align-items: center;
  padding: 6px 8px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.55);
  font-size: 13px;
}
.debug[hidden] { display: none; }
.debug button {
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.08);
  border-radius: 6px;
  padding: 3px 8px;
  cursor: pointer;
}

@media (prefers-reduced-motion: reduce) {
  .door-leaf { transition-duration: 0.3s; }
  .door.is-today:not(.is-open) { animation: today-glow 1.8s ease-in-out infinite alternate; }
  .fairy { animation: none; }
}
