:root {
  --bg-top: #0b181e;
  --bg-mid: #132830;
  --bg-bottom: #1a373d;
  --cream: #fffaf0;
  --cream-soft: #f6ebd9;
  --ink: #241916;
  --ink-muted: #65524b;
  --gold: #ecc269;
  --gold-bright: #ffe194;
  --gold-deep: #b88832;
  --cranberry: #b8373b;
  --cranberry-dark: #882327;
  --pine: #265341;
  --pine-dark: #193a2d;
  --gingerbread: #9f5c39;
  --gingerbread-dark: #753f23;
  --berry: #783d57;
  --berry-dark: #54273b;
  --midnight: #24405d;
  --midnight-dark: #182c42;
  --shadow-soft: 0 14px 30px rgb(5 12 16 / 0.42);
  --radius-door: 16px;
  --font-display: 'Fraunces', Georgia, 'Times New Roman', serif;
  --font-ui: 'Quicksand', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-hand: 'Caveat', 'Bradley Hand', cursive;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  color-scheme: dark;
  scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font-ui);
  color: var(--cream);
  background:
    radial-gradient(circle at 50% 8%, rgb(236 194 105 / 0.16), transparent 46%),
    radial-gradient(circle at 15% 40%, rgb(184 55 59 / 0.14), transparent 42%),
    radial-gradient(circle at 85% 75%, rgb(38 83 65 / 0.25), transparent 48%),
    linear-gradient(180deg, var(--bg-top) 0%, var(--bg-mid) 48%, var(--bg-bottom) 100%);
  background-attachment: fixed;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  -webkit-font-smoothing: antialiased;
}

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

/* Decorative top fairy-light garland */
.garland-wrap {
  position: relative;
  z-index: 2;
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  pointer-events: none;
  overflow: hidden;
}

.garland {
  display: block;
  width: 100%;
  height: 54px;
}

.bulb-a {
  fill: #ffd875;
}

.bulb-b {
  fill: #ff8e72;
}

.bulb-c {
  fill: #9be8d0;
}

@media (prefers-reduced-motion: no-preference) {
  .bulb {
    transform-box: fill-box;
    transform-origin: center;
    animation: fairy-glow 5.5s ease-in-out infinite alternate;
  }

  .bulb-b {
    animation-delay: -1.8s;
  }

  .bulb-c {
    animation-delay: -3.4s;
  }
}

@keyframes fairy-glow {
  0% {
    opacity: 0.58;
    filter: drop-shadow(0 0 3px rgb(255 225 148 / 0.35));
  }
  100% {
    opacity: 1;
    filter: drop-shadow(0 0 8px rgb(255 225 148 / 0.85));
  }
}

.page-shell {
  position: relative;
  z-index: 2;
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding: 0.25rem 1rem 2.75rem;
}

@media (min-width: 640px) {
  .page-shell {
    padding: 0.5rem 1.75rem 3.5rem;
  }
}

/* Header */
.site-header {
  text-align: center;
  margin-bottom: 1.75rem;
}

.header-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.28rem 0.9rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--gold-bright);
  background: rgb(236 194 105 / 0.12);
  border: 1px solid rgb(236 194 105 / 0.32);
  margin-bottom: 0.7rem;
}

.site-header h1 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(2rem, 6vw, 3.25rem);
  line-height: 1.1;
  color: var(--cream);
  text-shadow: 0 4px 20px rgb(0 0 0 / 0.35);
}

.subtitle {
  margin: 0.55rem auto 1.15rem;
  max-width: 34rem;
  font-size: clamp(0.96rem, 2.5vw, 1.1rem);
  line-height: 1.45;
  color: rgb(255 250 240 / 0.84);
}

.status-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 0.6rem;
}

.progress-pill,
.pill-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.42rem;
  min-height: 44px;
  padding: 0.5rem 1rem;
  border-radius: 999px;
  font-family: var(--font-ui);
  font-size: 0.9rem;
  font-weight: 700;
  border: 1px solid rgb(255 250 240 / 0.2);
  background: rgb(15 33 40 / 0.65);
  color: var(--cream);
  backdrop-filter: blur(8px);
}

.progress-star {
  color: var(--gold);
}

.pill-btn {
  cursor: pointer;
  touch-action: manipulation;
  transition:
    background-color 0.2s ease,
    border-color 0.2s ease,
    transform 0.15s ease;
}

.pill-btn:hover {
  background: rgb(26 55 61 / 0.9);
  border-color: rgb(236 194 105 / 0.55);
}

.pill-btn:active {
  transform: scale(0.97);
}

.pill-btn-gold {
  background: linear-gradient(135deg, var(--gold) 0%, #dda543 100%);
  color: var(--ink);
  border-color: var(--gold-bright);
  box-shadow: 0 6px 18px rgb(236 194 105 / 0.28);
}

.pill-btn-gold:hover {
  background: linear-gradient(135deg, var(--gold-bright) 0%, var(--gold) 100%);
  border-color: #fff2c2;
}

.preview-banner {
  margin: 1rem auto 0;
  max-width: 38rem;
  padding: 0.65rem 1rem;
  border-radius: 14px;
  background: rgb(236 194 105 / 0.15);
  border: 1px dashed rgb(236 194 105 / 0.6);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  font-size: 0.88rem;
  color: var(--gold-bright);
}

.preview-banner[hidden] {
  display: none;
}

.preview-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.banner-btn {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  border: 1px solid rgb(236 194 105 / 0.45);
  background: rgb(11 24 30 / 0.7);
  color: var(--cream);
  font-family: var(--font-ui);
  font-size: 0.82rem;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  touch-action: manipulation;
}

.banner-btn:hover {
  background: rgb(236 194 105 / 0.25);
}

/* Responsive Calendar Grid (divisors of 24 at every breakpoint -> zero orphans) */
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.85rem;
}

@media (min-width: 360px) {
  .calendar-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.85rem;
  }
}

@media (min-width: 640px) {
  .calendar-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 1.1rem;
  }
}

@media (min-width: 960px) {
  .calendar-grid {
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 1.25rem;
  }
}

/* Individual Door Card */
.door-slot {
  position: relative;
  aspect-ratio: 4 / 5;
  perspective: 900px;
}

.door-button {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  border-radius: var(--radius-door);
  cursor: pointer;
  touch-action: manipulation;
  text-align: center;
  color: inherit;
  font: inherit;
  transform-style: preserve-3d;
}

.door-button:focus-visible {
  outline: 3px solid var(--gold-bright);
  outline-offset: 4px;
}

/* Recess behind the door */
.door-inside {
  position: absolute;
  inset: 0;
  border-radius: var(--radius-door);
  background: linear-gradient(160deg, #2a1e1b 0%, #171210 100%);
  border: 2px solid rgb(236 194 105 / 0.38);
  box-shadow:
    inset 0 4px 16px rgb(0 0 0 / 0.72),
    var(--shadow-soft);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
}

.door-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: calc(var(--radius-door) - 6px);
  display: block;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.door-slot.is-opened .door-thumb,
.door-slot.is-opening .door-thumb {
  opacity: 1;
}

.door-inside-badge {
  position: absolute;
  right: 8px;
  bottom: 8px;
  min-width: 26px;
  height: 26px;
  padding: 0 7px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 0.78rem;
  font-weight: 700;
  background: rgb(255 250 240 / 0.92);
  color: var(--ink);
  box-shadow: 0 2px 8px rgb(0 0 0 / 0.35);
}

/* Front Flap */
.door-flap {
  position: absolute;
  inset: 0;
  border-radius: var(--radius-door);
  transform-origin: left center;
  backface-visibility: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.75rem 0.5rem;
  box-shadow:
    inset 0 0 0 2px rgb(255 250 240 / 0.22),
    inset 0 -10px 18px rgb(0 0 0 / 0.22),
    var(--shadow-soft);
  overflow: hidden;
  transition:
    transform 0.55s cubic-bezier(0.22, 1, 0.36, 1),
    filter 0.2s ease;
}

/* Snow cap across top of each closed door */
.door-flap::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 12px;
  background:
    radial-gradient(circle at 15% 0, #ffffff 9px, transparent 10px),
    radial-gradient(circle at 42% 0, #fff8ee 11px, transparent 12px),
    radial-gradient(circle at 72% 0, #ffffff 10px, transparent 11px),
    radial-gradient(circle at 92% 0, #fff8ee 8px, transparent 9px);
  opacity: 0.9;
  pointer-events: none;
}

/* Subtle dashed inner stitch frame */
.door-flap::after {
  content: '';
  position: absolute;
  inset: 7px;
  border-radius: calc(var(--radius-door) - 5px);
  border: 1.5px dashed rgb(255 250 240 / 0.26);
  pointer-events: none;
}

/* Doorknob */
.door-knob {
  position: absolute;
  right: 11px;
  top: 52%;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #fff4c2 0%, var(--gold) 65%, var(--gold-deep) 100%);
  box-shadow: 0 2px 4px rgb(0 0 0 / 0.45);
}

/* Themes */
.theme-cranberry .door-flap {
  background: linear-gradient(155deg, var(--cranberry) 0%, var(--cranberry-dark) 100%);
}

.theme-pine .door-flap {
  background: linear-gradient(155deg, var(--pine) 0%, var(--pine-dark) 100%);
}

.theme-gold .door-flap {
  background: linear-gradient(155deg, #c79538 0%, #8f641c 100%);
}

.theme-gingerbread .door-flap {
  background: linear-gradient(155deg, var(--gingerbread) 0%, var(--gingerbread-dark) 100%);
}

.theme-berry .door-flap {
  background: linear-gradient(155deg, var(--berry) 0%, var(--berry-dark) 100%);
}

.theme-midnight .door-flap {
  background: linear-gradient(155deg, var(--midnight) 0%, var(--midnight-dark) 100%);
}

.theme-christmas-gold .door-flap {
  background:
    radial-gradient(circle at 50% 35%, rgb(255 232 163 / 0.35), transparent 65%),
    linear-gradient(150deg, #b8373b 0%, #7d1d24 55%, #5c141a 100%);
  box-shadow:
    inset 0 0 0 2.5px var(--gold),
    0 12px 28px rgb(236 194 105 / 0.28);
}

.theme-christmas-gold .door-flap::after {
  border-color: rgb(236 194 105 / 0.65);
}

.door-motif {
  width: 24px;
  height: 24px;
  color: rgb(255 245 218 / 0.85);
  flex-shrink: 0;
}

.theme-christmas-gold .door-motif {
  width: 28px;
  height: 28px;
  color: var(--gold-bright);
}

.door-number {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(1.85rem, 5vw, 2.35rem);
  line-height: 1;
  color: var(--cream);
  text-shadow: 0 2px 6px rgb(0 0 0 / 0.35);
}

.theme-christmas-gold .door-number {
  color: var(--gold-bright);
  font-size: clamp(2.1rem, 5.5vw, 2.65rem);
}

/* Interactive states */
.door-slot:not(.is-locked):not(.is-opened):hover .door-flap {
  filter: brightness(1.08);
}

@media (prefers-reduced-motion: no-preference) {
  .door-slot:not(.is-locked):not(.is-opened):hover .door-flap {
    transform: rotateY(-10deg);
  }
}

.door-slot.is-opening .door-flap,
.door-slot.is-opened .door-flap {
  transform: rotateY(-114deg);
  pointer-events: none;
}

.door-slot.is-opened .door-flap {
  box-shadow: none;
}

/* Today's highlight */
.door-slot.is-today:not(.is-opened) .door-flap {
  box-shadow:
    inset 0 0 0 2.5px var(--gold-bright),
    0 0 0 3px rgb(236 194 105 / 0.35),
    0 12px 26px rgb(236 194 105 / 0.35);
}

.today-ribbon {
  position: absolute;
  top: -7px;
  right: 10px;
  z-index: 4;
  padding: 0.18rem 0.55rem;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: linear-gradient(135deg, var(--gold-bright), var(--gold));
  color: var(--ink);
  box-shadow: 0 4px 10px rgb(0 0 0 / 0.35);
  pointer-events: none;
}

@media (prefers-reduced-motion: no-preference) {
  .door-slot.is-today:not(.is-opened) .door-button {
    animation: today-pulse 2.8s ease-in-out infinite;
  }
}

@keyframes today-pulse {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-3px);
  }
}

/* Locked future door */
.door-slot.is-locked .door-flap {
  filter: saturate(0.68) brightness(0.84);
}

.door-lock-badge {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.14rem 0.45rem;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 600;
  color: rgb(255 250 240 / 0.85);
  background: rgb(10 20 26 / 0.42);
}

@media (prefers-reduced-motion: no-preference) {
  .door-slot.is-shaking {
    animation: door-wiggle 0.42s ease-in-out;
  }
}

@keyframes door-wiggle {
  0%, 100% { transform: rotate(0deg); }
  20% { transform: rotate(-4deg); }
  45% { transform: rotate(4deg); }
  70% { transform: rotate(-2.5deg); }
  85% { transform: rotate(2deg); }
}

/* Sparkle burst on door opening */
.sparkle-layer {
  position: absolute;
  inset: -12px;
  pointer-events: none;
  z-index: 6;
}

.sparkle-dot {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--gold-bright);
  box-shadow: 0 0 8px var(--gold-bright);
  animation: sparkle-pop 0.65s ease-out forwards;
}

@keyframes sparkle-pop {
  0% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(0.4);
  }
  100% {
    opacity: 0;
    transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(1.1);
  }
}

/* Toast notification */
.toast {
  position: fixed;
  left: 50%;
  bottom: max(1.25rem, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 30;
  width: min(calc(100vw - 2rem), 28rem);
  padding: 0.85rem 1.15rem;
  border-radius: 16px;
  background: rgb(14 31 38 / 0.94);
  border: 1px solid rgb(236 194 105 / 0.48);
  color: var(--cream);
  font-size: 0.94rem;
  font-weight: 600;
  text-align: center;
  box-shadow: 0 16px 36px rgb(0 0 0 / 0.48);
  backdrop-filter: blur(10px);
}

.toast[hidden] {
  display: none;
}

.calendar-error {
  text-align: center;
  padding: 1.5rem;
  border-radius: 16px;
  background: rgb(184 55 59 / 0.2);
  border: 1px solid rgb(184 55 59 / 0.5);
}

.site-footer {
  margin-top: 2.5rem;
  text-align: center;
  font-size: 0.9rem;
  color: rgb(255 250 240 / 0.65);
}

/* ==========================================================================
   Modal Polaroid Lightbox (<dialog>) — Modern Web Guidance Compliant
   ========================================================================== */

dialog.photo-dialog {
  margin: auto;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  width: min(calc(100vw - 1.5rem), 36rem);
  max-width: 100%;
  max-height: calc(100dvh - 1.5rem);
  overflow: auto;
  opacity: 0;
  transition-property: opacity, transform, display, overlay;
  transition-duration: 0.28s;
  transition-timing-function: ease-out;
  transition-behavior: allow-discrete;
}

@media (prefers-reduced-motion: no-preference) {
  dialog.photo-dialog {
    transform: scale(0.92);
  }
}

dialog.photo-dialog:modal {
  overscroll-behavior: contain;
}

dialog.photo-dialog::backdrop {
  overflow: hidden;
  overscroll-behavior: contain;
  background-color: rgb(6 14 18 / 0);
  backdrop-filter: blur(0px);
  transition-property: background-color, backdrop-filter, display, overlay;
  transition-duration: 0.28s;
  transition-timing-function: ease-out;
  transition-behavior: allow-discrete;
}

:is(dialog.photo-dialog[open]):where(:not([data-closing])) {
  display: flex;
  flex-direction: column;
  opacity: 1;

  @starting-style {
    opacity: 0;
  }

  @media (prefers-reduced-motion: no-preference) {
    transform: scale(1);

    @starting-style {
      transform: scale(0.92);
    }
  }

  &::backdrop {
    background-color: rgb(6 14 18 / 0.78);
    backdrop-filter: blur(6px);

    @starting-style {
      background-color: rgb(6 14 18 / 0);
      backdrop-filter: blur(0px);
    }
  }
}

dialog.photo-dialog[open][data-closing] {
  display: flex;
  flex-direction: column;
}

@media (prefers-reduced-motion: reduce) {
  dialog.photo-dialog,
  dialog.photo-dialog::backdrop {
    transition-duration: 0.1s;
  }
}

.polaroid-modal {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.polaroid-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.dialog-day-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.35rem 0.9rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--ink);
  background: linear-gradient(135deg, var(--gold-bright), var(--gold));
  box-shadow: 0 4px 12px rgb(0 0 0 / 0.3);
}

.dialog-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid rgb(255 250 240 / 0.25);
  background: rgb(15 33 40 / 0.88);
  color: var(--cream);
  cursor: pointer;
  touch-action: manipulation;
  transition: background-color 0.2s ease, transform 0.15s ease;
}

.dialog-close:hover {
  background: var(--cranberry);
}

.dialog-close:focus-visible {
  outline: 3px solid var(--gold-bright);
  outline-offset: 2px;
}

.polaroid-sheet {
  background: var(--cream);
  border-radius: 18px;
  padding: 0.95rem 0.95rem 1.25rem;
  box-shadow: 0 24px 48px rgb(0 0 0 / 0.55);
}

@media (min-width: 640px) {
  .polaroid-sheet {
    padding: 1.15rem 1.15rem 1.45rem;
  }
}

.polaroid-figure {
  margin: 0;
}

.polaroid-frame {
  background: #efe5d5;
  border-radius: 10px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
}

.polaroid-frame img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 58dvh;
  object-fit: contain;
}

.polaroid-caption {
  padding: 0.95rem 0.35rem 0.1rem;
  text-align: center;
}

.dialog-title {
  margin: 0 0 0.35rem;
  font-family: var(--font-hand);
  font-weight: 700;
  font-size: clamp(1.65rem, 4.5vw, 2.15rem);
  line-height: 1.1;
  color: var(--ink);
}

.dialog-text {
  margin: 0;
  font-size: 0.98rem;
  line-height: 1.45;
  color: var(--ink-muted);
}

.polaroid-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.nav-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 44px;
  min-width: 108px;
  padding: 0.5rem 1rem;
  border-radius: 999px;
  border: 1px solid rgb(255 250 240 / 0.25);
  background: rgb(15 33 40 / 0.88);
  color: var(--cream);
  font-family: var(--font-ui);
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  transition: background-color 0.2s ease, opacity 0.2s ease;
}

.nav-btn:hover:not(:disabled) {
  background: rgb(28 60 67 / 0.95);
  border-color: var(--gold);
}

.nav-btn:disabled {
  opacity: 0.38;
  cursor: not-allowed;
}

.nav-btn:focus-visible {
  outline: 3px solid var(--gold-bright);
  outline-offset: 2px;
}

.nav-counter {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--cream);
  background: rgb(15 33 40 / 0.78);
  padding: 0.35rem 0.8rem;
  border-radius: 999px;
}
