:root {
  --text: #fff8e7;
  --gold: #e9c46a;
  --door-a: rgba(178, 34, 52, 0.92);
  --door-b: rgba(105, 14, 28, 0.94);
  --radius: 10px;
}

* { box-sizing: border-box; }

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

body {
  font-family: "Lora", Georgia, serif;
  color: var(--text);
  background: #0b1a2e;
  overflow-x: hidden;
}

/* Fixed background layer (background-attachment: fixed is unreliable on iOS) */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    linear-gradient(rgba(5, 12, 25, 0.35), rgba(5, 12, 25, 0.55)),
    var(--bg-image, none) center / cover no-repeat,
    radial-gradient(ellipse at 50% 0%, #24456e 0%, #0b1a2e 60%, #050b16 100%);
}

header {
  text-align: center;
  padding: clamp(24px, 6vw, 56px) 16px clamp(16px, 3vw, 32px);
}

h1 {
  font-family: "Mountains of Christmas", "Lora", serif;
  font-size: clamp(2.2rem, 7vw, 4.2rem);
  margin: 0;
  color: var(--gold);
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.7);
}

#subtitle {
  margin: 8px 0 0;
  font-size: clamp(1rem, 2.5vw, 1.25rem);
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.8);
}

/* ---------- Grid ---------- */

.calendar {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: clamp(8px, 1.6vw, 18px);
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 16px 56px;
}

@media (max-width: 800px) { .calendar { grid-template-columns: repeat(4, 1fr); } }
@media (max-width: 480px) { .calendar { grid-template-columns: repeat(3, 1fr); } }

.cell {
  position: relative;
  aspect-ratio: 1;
  perspective: 900px;
}

.picture {
  position: absolute;
  inset: 0;
  padding: 0;
  border: 0;
  border-radius: var(--radius);
  overflow: hidden;
  /* Transparent while closed so the page background shows through the door */
  background: transparent;
  cursor: pointer;
  transition: background 0.4s, box-shadow 0.4s;
}

.cell.open .picture {
  background: rgba(0, 0, 0, 0.55);
  box-shadow: inset 0 0 14px rgba(0, 0, 0, 0.9);
}

.picture img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.4s 0.3s;
}

.cell.open .picture img { opacity: 1; }

/* ---------- Door ---------- */

.door {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border: 2px solid var(--gold);
  border-radius: var(--radius);
  /* Closed doors are see-through: the background picture shows through them */
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  transform-origin: left center;
  transition: transform 0.9s cubic-bezier(0.3, 0.8, 0.3, 1), background 0.3s, box-shadow 0.3s, filter 0.3s;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.45);
  z-index: 1;
}

.door::before {
  content: "";
  position: absolute;
  inset: 6px;
  border: 1px dashed rgba(233, 196, 106, 0.55);
  border-radius: 6px;
  pointer-events: none;
}

.door::after {
  content: "";
  position: absolute;
  right: 12%;
  top: 50%;
  width: 8px;
  height: 8px;
  margin-top: -4px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
}

.door .number {
  font-family: "Mountains of Christmas", "Lora", serif;
  font-size: clamp(1.6rem, 4.5vw, 2.8rem);
  color: var(--gold);
  text-shadow: 0 0 10px rgba(0, 0, 0, 0.9), 0 2px 4px rgba(0, 0, 0, 0.8);
  transition: opacity 0.3s;
}

.door:hover, .door:focus-visible {
  background: rgba(255, 255, 255, 0.12);
  box-shadow: 0 8px 22px rgba(233, 196, 106, 0.35);
}
.door:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }

.cell.locked .door { filter: saturate(0.55) brightness(0.8); cursor: not-allowed; }

.cell.today:not(.open) .door { animation: glow 2.2s ease-in-out infinite; }

.cell.open .door {
  transform: rotateY(-108deg);
  pointer-events: none;
  /* Give the swinging door a solid back so it reads as a door */
  background: linear-gradient(145deg, var(--door-a), var(--door-b));
}
.cell.open .door .number { opacity: 0; }

.cell.shake .door { animation: shake 0.45s; }

@keyframes glow {
  0%, 100% { box-shadow: 0 0 8px rgba(233, 196, 106, 0.4); }
  50%      { box-shadow: 0 0 26px rgba(233, 196, 106, 0.95); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 20px);
  max-width: calc(100% - 32px);
  padding: 12px 20px;
  border-radius: 999px;
  background: rgba(10, 20, 35, 0.92);
  border: 1px solid var(--gold);
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s, transform 0.3s;
  z-index: 10;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Lightbox ---------- */

.lightbox {
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--text);
  max-width: min(92vw, 1000px);
  max-height: 92vh;
  overflow: visible;
}
.lightbox::backdrop { background: rgba(5, 10, 20, 0.88); backdrop-filter: blur(4px); }
.lightbox figure { margin: 0; }
.lightbox img {
  display: block;
  max-width: 100%;
  max-height: 80vh;
  margin: 0 auto;
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.7);
}
.lightbox figcaption {
  margin-top: 12px;
  text-align: center;
  font-size: 1.1rem;
}
.lightbox figcaption:empty { display: none; }
.close {
  position: fixed;
  top: 12px;
  right: 16px;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  font-size: 1.8rem;
  line-height: 1;
  cursor: pointer;
}

/* ---------- Snow ---------- */

.snow { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 5; }
.snow span {
  position: absolute;
  top: -10px;
  border-radius: 50%;
  background: #fff;
  opacity: 0.8;
  animation: fall linear infinite;
}
@keyframes fall {
  to { transform: translate(var(--drift), 105vh); }
}

@media (prefers-reduced-motion: reduce) {
  .snow { display: none; }
  .door, .picture img { transition: none; }
  .cell.today:not(.open) .door, .cell.shake .door { animation: none; }
}
