* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #120d0c;
  color: #fff7e8;
  font-family: 'Cormorant Garamond', Georgia, serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

#bg {
  position: fixed;
  inset: -4%;
  background: url(/bg.jpg) center / cover no-repeat;
  transform-origin: 50% 50%;
  transition: transform 1.2s cubic-bezier(.5, 0, .2, 1), filter 1.2s;
  animation: bgDrift 40s ease-in-out infinite alternate;
}
#bg::after {
  content: '';
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(10, 6, 6, .55), rgba(10, 6, 6, .05) 30%, rgba(10, 6, 6, .1) 70%, rgba(10, 6, 6, .55)),
    radial-gradient(ellipse at 50% 50%, transparent 40%, rgba(0, 0, 0, .45));
}
@keyframes bgDrift {
  from { transform: scale(1.02) translate(0, 0); }
  to { transform: scale(1.08) translate(-1%, -1%); }
}
body.zoomed #bg { filter: blur(6px) brightness(.55); }

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

/* ---------- Calendar ---------- */
#calendar {
  position: fixed;
  inset: 0;
  padding: calc(env(safe-area-inset-top) + 10px) 10px calc(env(safe-area-inset-bottom) + 10px);
  display: flex;
  flex-direction: column;
  transform-origin: 50% 50%;
  transition: transform .9s cubic-bezier(.6, 0, .25, 1), opacity .7s ease, filter .9s;
  will-change: transform;
}
#calendar.zoom {
  opacity: 0;
  filter: blur(4px);
  pointer-events: none;
}
.cal-head {
  text-align: center;
  padding: 4px 0 2px;
  text-shadow: 0 2px 12px rgba(0, 0, 0, .6);
}
.cal-head h1 {
  margin: 0;
  font-family: 'Great Vibes', cursive;
  font-weight: 400;
  font-size: clamp(44px, 12vw, 64px);
  line-height: 1;
  color: #ffe9b8;
  background: linear-gradient(180deg, #fff6d8, #f0c873 60%, #d49b36);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, .55));
}
.cal-head p {
  margin: 2px 0 0;
  font-style: italic;
  font-size: 15px;
  letter-spacing: .04em;
  color: rgba(255, 240, 215, .85);
  min-height: 1.2em;
}
#doors {
  position: relative;
  flex: 1;
  margin-top: 6px;
}

/* ---------- Doors ---------- */
.door {
  position: absolute;
  padding: 0;
  border: 0;
  background: none;
  transform: rotate(var(--rot));
  opacity: 0;
  animation: doorIn .7s cubic-bezier(.3, 1.5, .5, 1) forwards;
  animation-delay: var(--delay);
}
@keyframes doorIn {
  from { opacity: 0; transform: rotate(var(--rot)) scale(.4); }
  to { opacity: 1; transform: rotate(var(--rot)) scale(1); }
}
.door-window,
.door-panel {
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
}
.door-window {
  background:
    radial-gradient(ellipse at 50% 60%, rgba(255, 214, 140, .55), rgba(120, 50, 20, .35) 70%),
    rgba(20, 10, 8, .55);
  box-shadow: inset 0 3px 10px rgba(0, 0, 0, .7), 0 0 0 1.5px rgba(232, 196, 120, .55);
  overflow: hidden;
  opacity: 0;
  transition: opacity .4s;
}
.door.opened .door-window { opacity: 1; }
.door-panel {
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    linear-gradient(150deg, rgba(255, 255, 255, .34), rgba(255, 255, 255, .1) 45%, rgba(255, 230, 200, .14));
  -webkit-backdrop-filter: blur(7px) saturate(1.3);
  backdrop-filter: blur(7px) saturate(1.3);
  box-shadow:
    0 0 0 1.5px rgba(245, 214, 150, .75),
    inset 0 0 0 4px rgba(255, 255, 255, .06),
    inset 0 0 0 5px rgba(245, 214, 150, .3),
    0 8px 20px rgba(0, 0, 0, .35);
  transition: transform .25s, opacity .25s;
}
.door-panel::before {
  /* frost sparkle */
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background:
    linear-gradient(125deg, transparent 20%, rgba(255, 255, 255, .22) 32%, transparent 40%),
    radial-gradient(circle at 78% 22%, rgba(255, 255, 255, .5) 0 1px, transparent 2px),
    radial-gradient(circle at 22% 80%, rgba(255, 255, 255, .4) 0 1px, transparent 2px);
}
.door .num {
  font-variant-numeric: lining-nums;
  position: relative;
  font-family: 'Cormorant Garamond', serif;
  font-weight: 600;
  font-size: calc(var(--w) * .46);
  line-height: 1;
  color: #fff3d2;
  text-shadow: 0 1px 0 rgba(120, 70, 10, .6), 0 0 14px rgba(255, 200, 110, .55), 0 2px 8px rgba(0, 0, 0, .5);
}
.door:active .door-panel { transform: scale(.95); }

/* Today's door glows softly. */
.door.today .door-panel {
  box-shadow:
    0 0 0 2px rgba(255, 222, 150, .95),
    0 0 18px 4px rgba(255, 205, 110, .55),
    inset 0 0 0 5px rgba(245, 214, 150, .35),
    0 8px 20px rgba(0, 0, 0, .35);
  animation: todayPulse 2.4s ease-in-out infinite;
}
@keyframes todayPulse {
  50% { box-shadow: 0 0 0 2px rgba(255, 232, 170, 1), 0 0 30px 8px rgba(255, 205, 110, .75), inset 0 0 0 5px rgba(245, 214, 150, .35), 0 8px 20px rgba(0, 0, 0, .35); }
}
.door.locked .num { opacity: .8; }

/* Opened: the panel is gone, the window shows. */
.door.opened .door-panel { opacity: 0; pointer-events: none; }
.door .win-num {
  font-variant-numeric: lining-nums;
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Cormorant Garamond', serif;
  font-weight: 600;
  font-size: calc(var(--w) * .34);
  color: rgba(255, 235, 200, .75);
  text-shadow: 0 0 10px rgba(255, 190, 90, .8);
}
.door.redeemed .door-window {
  background:
    radial-gradient(ellipse at 50% 60%, rgba(255, 214, 140, .25), rgba(60, 20, 10, .3) 70%),
    rgba(20, 10, 8, .6);
}
.door.redeemed .win-num { opacity: .45; }
.door .check {
  position: absolute;
  right: 6%;
  bottom: 6%;
  font-size: calc(var(--w) * .26);
  filter: drop-shadow(0 1px 3px rgba(0, 0, 0, .6));
}

/* Opened but present not found yet: faint glitter. */
.door .glitter { position: absolute; inset: -12%; pointer-events: none; }
.door .glitter i {
  position: absolute;
  width: 10px;
  height: 10px;
  background: radial-gradient(circle, #fff 0 15%, rgba(255, 220, 140, .9) 25%, transparent 60%);
  clip-path: polygon(50% 0, 58% 42%, 100% 50%, 58% 58%, 50% 100%, 42% 58%, 0 50%, 42% 42%);
  opacity: 0;
  animation: twinkle 2.6s ease-in-out infinite;
}
@keyframes twinkle {
  0%, 100% { opacity: 0; transform: scale(.3) rotate(0); }
  50% { opacity: .95; transform: scale(1) rotate(45deg); }
}
.door.wiggle { animation: wiggle .5s ease; opacity: 1; }
@keyframes wiggle {
  0%, 100% { transform: rotate(var(--rot)); }
  20% { transform: rotate(calc(var(--rot) - 7deg)); }
  40% { transform: rotate(calc(var(--rot) + 6deg)); }
  60% { transform: rotate(calc(var(--rot) - 4deg)); }
  80% { transform: rotate(calc(var(--rot) + 2deg)); }
}
.door.vanish .door-panel {
  opacity: 0;
  transform: scale(1.08);
  transition: opacity .35s ease .1s, transform .35s;
}

/* ---------- Card stage ---------- */
#stage {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.stage-glow {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 50% 45%, rgba(255, 196, 120, .28), rgba(40, 14, 10, .25) 55%, rgba(8, 4, 4, .6));
  opacity: 0;
  transition: opacity .8s;
}
#stage.show .stage-glow { opacity: 1; }
.stage-close {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 12px);
  left: 14px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid rgba(255, 230, 190, .35);
  background: rgba(30, 14, 10, .45);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  display: grid;
  place-items: center;
  z-index: 3;
  opacity: 0;
  transition: opacity .4s .3s;
}
.stage-close svg { width: 20px; height: 20px; }
#stage.show .stage-close { opacity: 1; }

.stage-card {
  position: relative;
  z-index: 2;
  margin-top: -40px;
}
.stage-card .xcard { --closed-scale: 1.32; cursor: pointer; }
.stage-card .xcard.open { cursor: default; }
.stage-card .card-float {
  animation: cardIn 1s cubic-bezier(.2, 1.2, .4, 1) both;
}
@keyframes cardIn {
  from { opacity: 0; transform: translateY(60px) scale(.25) rotateX(35deg) rotateZ(-8deg); }
  to { opacity: 1; transform: none; }
}
.stage-card .card-float.idle .xcard:not(.open) .xcard-spread {
  animation: floaty 4s ease-in-out infinite;
}
@keyframes floaty {
  0%, 100% { transform: translateX(calc(var(--pw) * -0.5)) scale(var(--closed-scale)) rotateY(-4deg) translateY(0); }
  50% { transform: translateX(calc(var(--pw) * -0.5)) scale(var(--closed-scale)) rotateY(5deg) translateY(-8px); }
}
.stage-hint {
  position: absolute;
  z-index: 2;
  bottom: calc(env(safe-area-inset-bottom) + 120px);
  margin: 0;
  font-style: italic;
  font-size: 18px;
  color: rgba(255, 240, 215, .9);
  text-shadow: 0 2px 8px rgba(0, 0, 0, .7);
  animation: hintPulse 2s ease-in-out infinite;
  transition: opacity .4s;
}
@keyframes hintPulse { 50% { opacity: .5; } }
#stage.opened .stage-hint { opacity: 0; animation: none; }

.present-bar {
  position: absolute;
  z-index: 3;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 0 20px calc(env(safe-area-inset-bottom) + 22px);
  display: flex;
  justify-content: center;
  transform: translateY(140%);
  transition: transform .7s cubic-bezier(.3, 1.4, .5, 1) .5s;
}
#stage.opened .present-bar { transform: none; }
.present {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: min(100%, 360px);
  min-height: 60px;
  border: 0;
  border-radius: 30px;
  font-family: 'Cormorant Garamond', serif;
  font-weight: 600;
  font-size: 22px;
  letter-spacing: .02em;
  color: #fff;
  background: linear-gradient(180deg, #3fae5c, #1f7a3a 60%, #18652f);
  box-shadow: 0 0 0 2px rgba(240, 210, 130, .8), inset 0 2px 0 rgba(255, 255, 255, .3), 0 12px 28px rgba(0, 0, 0, .45);
  text-shadow: 0 1px 2px rgba(0, 0, 0, .4);
  transition: transform .15s, background .3s;
}
.present:active { transform: scale(.97); }
.present-icon { font-size: 26px; }
.present.confirm { background: linear-gradient(180deg, #e2b84a, #b98318); }
.present.done {
  background: linear-gradient(180deg, rgba(40, 110, 60, .75), rgba(20, 70, 36, .75));
  box-shadow: 0 0 0 1.5px rgba(240, 210, 130, .5), 0 8px 20px rgba(0, 0, 0, .35);
  cursor: default;
}

/* ---------- Photo viewer ---------- */
#viewer {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(8, 4, 4, .94);
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  animation: fadeIn .25s;
}
#viewer img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  transform-origin: 0 0;
  will-change: transform;
}
.viewer-close {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 12px);
  right: 14px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, .3);
  background: rgba(0, 0, 0, .5);
  display: grid;
  place-items: center;
}
.viewer-close svg { width: 20px; height: 20px; }
@keyframes fadeIn { from { opacity: 0; } }

/* ---------- Intro ---------- */
#intro {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at 50% 45%, #3a1a14, #120807 70%);
  transition: opacity .9s ease, transform .9s ease;
}
#intro.out { opacity: 0; transform: scale(1.15); pointer-events: none; }
.bells {
  width: min(62vw, 280px);
  overflow: visible;
  animation: bellsIn 1s cubic-bezier(.2, 1.4, .4, 1) both;
  filter: drop-shadow(0 0 22px rgba(255, 200, 100, .45));
}
@keyframes bellsIn { from { opacity: 0; transform: translateY(-40px) scale(.6); } }
.bell { transform-box: fill-box; transform-origin: 50% 0; }
.bell-l { animation: swingL 1.1s ease-in-out .5s 2 alternate both; }
.bell-r { animation: swingR 1.1s ease-in-out .5s 2 alternate both; }
@keyframes swingL { 0% { transform: rotate(0); } 30% { transform: rotate(16deg); } 100% { transform: rotate(-10deg); } }
@keyframes swingR { 0% { transform: rotate(0); } 30% { transform: rotate(-16deg); } 100% { transform: rotate(10deg); } }
.intro-text {
  margin: 18px 0 0;
  font-family: 'Great Vibes', cursive;
  font-size: clamp(34px, 10vw, 52px);
  color: #f7dc94;
  text-shadow: 0 0 18px rgba(255, 200, 100, .5);
  animation: fadeUp 1s ease .7s both;
}
@keyframes fadeUp { from { opacity: 0; transform: translateY(14px); } }

/* ---------- Toast ---------- */
#toast {
  position: fixed;
  z-index: 60;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 28px);
  transform: translate(-50%, 30px);
  max-width: 88vw;
  padding: 12px 20px;
  border-radius: 22px;
  background: rgba(30, 14, 10, .82);
  border: 1px solid rgba(240, 210, 140, .45);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  font-size: 18px;
  font-style: italic;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s, transform .3s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  #bg { animation: none; }
  .door.today .door-panel { animation: none; }
}
body.zoomed #toast { bottom: calc(env(safe-area-inset-bottom) + 100px); }
.door.pending .door-window {
  background:
    radial-gradient(ellipse at 50% 60%, rgba(255, 220, 150, .75), rgba(150, 70, 25, .45) 70%),
    rgba(30, 14, 8, .45);
  animation: pendGlow 2.8s ease-in-out infinite;
}
@keyframes pendGlow {
  0%, 100% { box-shadow: inset 0 3px 10px rgba(0, 0, 0, .6), 0 0 0 1.5px rgba(245, 214, 150, .7), 0 0 10px 1px rgba(255, 205, 120, .35); }
  50% { box-shadow: inset 0 3px 10px rgba(0, 0, 0, .6), 0 0 0 1.5px rgba(255, 228, 170, .95), 0 0 22px 5px rgba(255, 205, 120, .6); }
}
.door .glitter i { width: 13px; height: 13px; }
