/* ---------- base ---------- */
:root {
  --gold: #f3d79b;
  --gold-deep: #c9a253;
  --ink: #2b2420;
  --paper: #f7f0e1;
  --night: #0b1324;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --ui: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", system-ui, sans-serif;
  --serif: "Cormorant Garamond", "Iowan Old Style", Georgia, serif;
  --script: "Pinyon Script", "Snell Roundhand", cursive;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--night);
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  touch-action: none;
  overscroll-behavior: none;
}
img { -webkit-user-drag: none; }
button { font: inherit; color: inherit; }

#stage {
  position: fixed; inset: 0; overflow: hidden;
  /* night sky above, snow below: fills any screen shape around the building */
  background: linear-gradient(180deg, #0a1122 0%, #121c36 38%, #2a3550 50%, #b9c3d0 62%, #e6ebf1 100%);
  cursor: default;
}
#stage.can-open { cursor: pointer; }

.layer {
  position: absolute; left: 0; top: 0;
  transform-origin: 0 0;
  will-change: transform, opacity;
  pointer-events: none;
}
.layer > img { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

/* ---------- the building ---------- */
#backdrop {
  background: url(../assets/img/backdrop.webp) center / 100% 100% no-repeat;
  filter: brightness(.62) saturate(1.1);
}
#world {
  -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 2.5%, #000 97.5%, transparent 100%), linear-gradient(180deg, transparent 0, #000 2%, #000 98%, transparent 100%);
  -webkit-mask-composite: source-in;
  mask-image: linear-gradient(90deg, transparent 0, #000 2.5%, #000 97.5%, transparent 100%), linear-gradient(180deg, transparent 0, #000 2%, #000 98%, transparent 100%);
  mask-composite: intersect;
}
#world .w-main {
  --wipe: -20%;
  -webkit-mask-image: linear-gradient(90deg, transparent calc(var(--wipe) - 14%), #000 var(--wipe));
  mask-image: linear-gradient(90deg, transparent calc(var(--wipe) - 14%), #000 var(--wipe));
}
#world .w-main.gone { display: none; }
#doors, #lamps, #worldcast { position: absolute; inset: 0; }

.door { position: absolute; }
.door > * { position: absolute; inset: 0; }
.door .tile, .door .reveal { background-repeat: no-repeat; border-radius: 1.5%; }
.door .tile { transform-origin: 50% 60%; transition: transform .5s cubic-bezier(.2,.9,.3,1.3), filter .4s; }
.door .reveal {
  opacity: 0; transition: opacity 1.4s ease;
  -webkit-mask-image: radial-gradient(closest-side, #000 72%, transparent 100%);
  mask-image: radial-gradient(closest-side, #000 72%, transparent 100%);
  inset: -6% -10%;
}
.door .reveal::after { /* warm lamplight in a window that has been opened */
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(closest-side, rgba(255, 200, 120, .35), transparent 80%);
  mix-blend-mode: screen; animation: flicker 4s infinite;
}
.door.opened .reveal { opacity: 1; }
.door.opened .tile { opacity: 0; transition: opacity 1s ease .2s; }

/* glow coming from behind today's door, with a red film-halation edge (sized in app.js) */
.door .halo {
  background:
    radial-gradient(closest-side, rgba(255, 248, 225, 1) 0%, rgba(255, 224, 150, .95) 34%, rgba(255, 160, 80, .62) 54%, rgba(228, 64, 32, .24) 74%, transparent 100%);
  mix-blend-mode: screen;
  opacity: 0; transform: scale(.85);
  transition: opacity 1.2s ease, transform 1.2s ease;
}
.door.today .halo { opacity: 1; transform: scale(1); animation: halo 2.8s ease-in-out infinite; }
.door.missed .halo { opacity: .55; transform: scale(.8); animation: halo-soft 4.2s ease-in-out infinite; }
.door.today .tile { box-shadow: 0 0 3em 1em rgba(255, 196, 110, .7), 0 0 .9em .25em rgba(255, 244, 210, .95); }
.door.missed .tile { box-shadow: 0 0 2em .5em rgba(255, 196, 110, .5), 0 0 .6em .1em rgba(255, 240, 200, .6); }
.door.hover .tile { transform: translateY(-2%) scale(1.04); filter: brightness(1.08); }
.door.pop .tile { animation: pop .55s cubic-bezier(.2,.9,.3,1.4); }
.door.jiggle .tile { animation: jiggle .55s ease; }
.door.opened .halo { opacity: 0; }

.door .shine { overflow: hidden; border-radius: 1.5%; opacity: 0; }
.door.today .shine, .door.missed .shine { opacity: 1; }
.door .shine::before {
  content: ""; position: absolute; top: -20%; bottom: -20%; width: 60%; left: -80%;
  background: linear-gradient(100deg, transparent 0%, rgba(255, 255, 255, .55) 50%, transparent 100%);
  mix-blend-mode: soft-light;
  animation: shine 3.6s ease-in-out infinite;
}

.lamp {
  position: absolute; width: 9%; aspect-ratio: 1; transform: translate(-50%, -50%);
  background: radial-gradient(closest-side, rgba(255, 230, 170, .9), rgba(255, 180, 90, .35) 40%, transparent 100%);
  mix-blend-mode: screen; opacity: 0; transition: opacity .25s;
}
.lamp.on { opacity: 1; animation: flicker 5s infinite; }

#worldcast img { position: absolute; display: block; }
.star {
  filter: drop-shadow(0 0 1.2em rgba(255, 220, 150, .9));
  animation: bob 3.2s ease-in-out infinite;
  opacity: 0; transition: opacity 1s;
}
.star.show { opacity: 1; }

/* ---------- a day's room and door close-up ---------- */
#room, #closeup { visibility: hidden; }
#room.show, #closeup.show { visibility: visible; }
#room {
  -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 4%, #000 96%, transparent 100%), linear-gradient(180deg, transparent 0, #000 4%, #000 96%, transparent 100%);
  -webkit-mask-composite: source-in;
  mask-image: linear-gradient(90deg, transparent 0, #000 4%, #000 96%, transparent 100%), linear-gradient(180deg, transparent 0, #000 4%, #000 96%, transparent 100%);
  mask-composite: intersect;
}
#room .r-warm {
  position: absolute; inset: 0;
  background: radial-gradient(40% 55% at 50% 45%, rgba(255, 196, 120, .28), transparent 70%);
  mix-blend-mode: screen; opacity: 0; transition: opacity 2s;
}
#room.lit .r-warm { opacity: 1; animation: flicker 5s infinite; }
#closeup {
  -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 8%, #000 92%, transparent 100%), linear-gradient(180deg, transparent 0, #000 3%, #000 97%, transparent 100%);
  -webkit-mask-composite: source-in;
  mask-image: linear-gradient(90deg, transparent 0, #000 8%, #000 92%, transparent 100%), linear-gradient(180deg, transparent 0, #000 3%, #000 97%, transparent 100%);
  mask-composite: intersect;
}
.c-glow, .c-flapwrap { position: absolute; }
.c-glow {
  background: radial-gradient(closest-side, rgba(255, 246, 220, 1), rgba(255, 205, 120, .8) 45%, rgba(255, 120, 50, .25) 80%, transparent 100%);
  mix-blend-mode: screen; opacity: 0;
}
.c-flapwrap { perspective: 1600px; }
.flap {
  position: absolute; top: 0; height: 100%;
  transform-style: preserve-3d;
}
.flap > div { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; border-radius: 1px; }
.flap .front { background-repeat: no-repeat; }
.flap .front::after { /* the door darkens as it turns away from the light */
  content: ""; position: absolute; inset: 0; background: #1a0f08; opacity: var(--shade, 0);
}
.flap .back {
  transform: rotateY(180deg);
  background:
    radial-gradient(120% 80% at 30% 20%, rgba(255, 255, 255, .35), transparent 60%),
    linear-gradient(135deg, #efe2c4, #d9c49b);
  box-shadow: inset 0 0 0 3px rgba(150, 110, 60, .35), inset 0 0 30px rgba(120, 80, 30, .35);
}
.flap.up .back { transform: rotateX(180deg); }

#vignette {
  position: absolute; inset: 0; pointer-events: none; opacity: 0;
  background: radial-gradient(75% 70% at 50% 50%, transparent 40%, rgba(5, 4, 10, .75) 100%);
}

/* ---------- cast (animals running across the screen) ---------- */
#cast, #casttop { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
#cast img, #casttop img { position: absolute; left: 0; top: 0; display: block; will-change: transform; transform-origin: 50% 100%; }
#cast img.tappable, #casttop img.tappable { pointer-events: auto; cursor: pointer; }

#fx { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#flash {
  position: absolute; inset: 0; pointer-events: none; opacity: 0;
  background: radial-gradient(circle at 50% 50%, #fffaf0 0%, #ffe9bf 40%, #f5c77e 100%);
}

/* ---------- interface ---------- */
#ui { position: absolute; inset: 0; pointer-events: none; font-family: var(--ui); color: #fff; }
.glass, .pill {
  background: rgba(18, 22, 38, .32);
  -webkit-backdrop-filter: blur(20px) saturate(1.6);
  backdrop-filter: blur(20px) saturate(1.6);
  border: 1px solid rgba(255, 255, 255, .18);
  box-shadow: 0 8px 30px rgba(0, 0, 0, .25), inset 0 1px 0 rgba(255, 255, 255, .12);
}
.pill {
  display: inline-block; padding: .62em 1.15em; border-radius: 999px;
  font-size: 15px; font-weight: 500; letter-spacing: .01em; white-space: nowrap;
}

#intro {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; opacity: 0; transition: opacity 1.2s ease;
  background: radial-gradient(60% 50% at 50% 48%, rgba(8, 12, 26, .55), transparent 75%);
}
#intro.show { opacity: 1; }
#intro.leave { opacity: 0; transition: opacity .9s ease; }
#intro.leave .i-title { transform: translateY(-14px) scale(1.04); filter: blur(6px); }
.i-kicker { font-family: var(--serif); letter-spacing: .5em; text-transform: uppercase; font-size: 13px; color: var(--gold); padding-left: .5em; }
.i-title {
  margin: .1em 0 .55em; font-family: var(--serif); font-weight: 500; font-style: italic;
  font-size: clamp(42px, 8vw, 96px); line-height: 1; color: #fff8e8;
  text-shadow: 0 2px 30px rgba(0, 0, 0, .55), 0 0 60px rgba(255, 210, 140, .35);
  transition: transform .9s cubic-bezier(.2,.8,.2,1), filter .9s;
}
.i-tap { animation: breathe 2.4s ease-in-out infinite; }

#hint {
  position: absolute; left: 50%; bottom: calc(26px + var(--safe-b));
  transform: translate(-50%, 12px); opacity: 0;
  transition: opacity .5s ease, transform .6s cubic-bezier(.2,.8,.2,1);
}
#hint.show { opacity: 1; transform: translate(-50%, 0); }

#tag {
  position: absolute; left: 0; top: 0; padding: .45em .85em; border-radius: 999px;
  font-size: 13px; font-weight: 600; color: #1d2433;
  background: rgba(240, 246, 255, .9); box-shadow: 0 6px 20px rgba(0, 0, 0, .3);
  transform: translate(-50%, -100%) scale(.8); opacity: 0;
  transition: opacity .25s, transform .35s cubic-bezier(.2,.9,.3,1.4);
  white-space: nowrap;
}
#tag.show { opacity: 1; transform: translate(-50%, calc(-100% - 10px)) scale(1); }

#ring {
  position: absolute; width: 104px; height: 104px; left: 0; top: 0; margin: -52px 0 0 -52px;
  opacity: 0; transform: scale(.7); transition: opacity .2s, transform .3s cubic-bezier(.2,.9,.3,1.3);
  overflow: visible;
}
#ring.show { opacity: 1; transform: scale(1); }
#ring circle { fill: none; stroke-width: 5; }
#ring .r-track { stroke: rgba(255, 255, 255, .25); }
#ring .r-fill {
  stroke: #fff3d6; stroke-linecap: round; stroke-dasharray: 264; stroke-dashoffset: 264;
  transform: rotate(-90deg); transform-origin: 50% 50%;
  filter: drop-shadow(0 0 6px rgba(255, 210, 140, .9));
}

#back, #mute {
  position: absolute; top: calc(16px + var(--safe-t)); width: 44px; height: 44px; border-radius: 50%;
  display: grid; place-items: center; padding: 0; cursor: pointer; pointer-events: auto;
  transition: opacity .4s, transform .2s;
}
#back:active, #mute:active { transform: scale(.92); }
#back { left: 16px; opacity: 0; pointer-events: none; }
#back.show { opacity: 1; pointer-events: auto; }
#mute { right: 16px; opacity: 0; }
#mute.show { opacity: 1; }
#back svg, #mute svg { width: 22px; height: 22px; fill: none; stroke: #fff; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
#mute svg path:first-child { fill: #fff; stroke: none; }
#mute .off, #mute.muted .on { display: none; }
#mute.muted .off { display: block; }

/* ---------- gift ---------- */
#gift {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  padding: calc(70px + var(--safe-t)) 20px calc(90px + var(--safe-b));
  pointer-events: none;
}
#gift.show { pointer-events: auto; }
#gift::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(70% 60% at 50% 55%, rgba(6, 8, 18, .45), transparent 80%);
  opacity: 0; transition: opacity 1s;
}
#gift.show::before { opacity: 1; }
#gift.side { justify-content: flex-end; padding-right: max(6vw, 40px); }
#gift.side::before { background: radial-gradient(45% 70% at 78% 55%, rgba(6, 8, 18, .5), transparent 80%); }
.g-wrap {
  position: relative; width: min(80vw, 350px);
  transform: translateY(110vh) rotate(6deg);
}
.g-kicker {
  text-align: center; font-family: var(--serif); text-transform: uppercase; letter-spacing: .42em;
  font-size: 12px; font-weight: 600; color: var(--gold); margin-bottom: 12px; padding-left: .42em;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .9), 0 0 16px rgba(0, 0, 0, .7);
}
.polaroid {
  background: #fbf8f1; padding: 14px 14px 18px; border-radius: 3px;
  box-shadow: 0 30px 60px rgba(0, 0, 0, .45), 0 2px 0 rgba(255, 255, 255, .6) inset;
  transform: rotate(-2deg);
}
.polaroid .ph { position: relative; overflow: hidden; background: #ddd; aspect-ratio: 4 / 5; }
.polaroid img { width: 100%; height: 100%; object-fit: cover; display: block; }
.polaroid .ph::after { content: ""; position: absolute; inset: 0; background: #f2ead6; animation: develop 3.4s ease-out .5s forwards; }
.polaroid img { animation: developImg 4s ease-out .3s both; }
.polaroid .cap { font-family: var(--script); font-size: 27px; color: #3b302a; text-align: center; padding-top: 12px; line-height: 1.15; }

.gcard { perspective: 1400px; cursor: pointer; }
.gcard .in { position: relative; aspect-ratio: 1.58; transform-style: preserve-3d; transition: transform 1.1s cubic-bezier(.2,.85,.25,1.05); }
.gcard.flipped .in { transform: rotateY(180deg); }
.gcard .face {
  position: absolute; inset: 0; border-radius: 18px; overflow: hidden;
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
  box-shadow: 0 30px 60px rgba(0, 0, 0, .45);
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
}
.gcard .front {
  background:
    radial-gradient(120% 90% at 20% 0%, rgba(255, 255, 255, .16), transparent 55%),
    linear-gradient(145deg, #1e4a37, #0f2a20);
  color: var(--gold);
}
.gcard .front::before { content: ""; position: absolute; inset: 10px; border: 1px solid rgba(243, 215, 155, .55); border-radius: 12px; }
.gcard .front::after {
  content: ""; position: absolute; top: 0; bottom: 0; width: 45%; left: -60%;
  background: linear-gradient(100deg, transparent, rgba(255, 255, 255, .22), transparent);
  animation: shine 3.2s ease-in-out infinite;
}
.gcard .f-title { font-family: var(--script); font-size: 40px; line-height: 1; }
.gcard .f-sub { font-family: var(--serif); letter-spacing: .3em; text-transform: uppercase; font-size: 11px; margin-top: 14px; opacity: .85; }
.seal {
  width: 54px; height: 54px; border-radius: 50%; margin-bottom: 12px;
  display: grid; place-items: center;
  background: radial-gradient(circle at 35% 30%, #d8473f, #8d1c1a 70%);
  box-shadow: 0 4px 10px rgba(0, 0, 0, .4), inset 0 -3px 6px rgba(0, 0, 0, .3), inset 0 2px 4px rgba(255, 255, 255, .25);
  font-family: var(--serif); font-weight: 600; font-size: 22px; color: #f6d2b8;
}
.gcard .back { transform: rotateY(180deg); background: linear-gradient(160deg, #fbf6ea, #efe3c8); color: var(--ink); padding: 18px; gap: 8px; }
.gcard .b-title { font-family: var(--serif); font-style: italic; font-weight: 600; font-size: 24px; }
.gcard .b-note { font-family: var(--serif); font-size: 16px; opacity: .75; }
.gcard .b-code {
  font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 15px; letter-spacing: .08em;
  background: rgba(60, 40, 20, .08); border: 1px dashed rgba(60, 40, 20, .35); border-radius: 8px; padding: 6px 12px;
}
.btn {
  display: inline-block; margin-top: 4px; padding: .7em 1.3em; border-radius: 999px; border: 0;
  background: #1e4a37; color: #fdf3dc; font-family: var(--ui); font-weight: 600; font-size: 15px; text-decoration: none; cursor: pointer;
  box-shadow: 0 6px 16px rgba(30, 74, 55, .35);
}
.letter {
  background:
    radial-gradient(120% 70% at 20% 0%, rgba(255, 255, 255, .7), transparent 60%),
    linear-gradient(170deg, #fbf5e6, #efe2c6);
  color: var(--ink); padding: 30px 28px 26px; border-radius: 4px;
  box-shadow: 0 30px 60px rgba(0, 0, 0, .45);
  transform: rotate(1.5deg);
}
.letter .l-title { font-family: var(--script); font-size: 38px; line-height: 1; margin-bottom: 14px; color: #7c2a22; }
.letter .l-text { font-family: var(--serif); font-size: 20px; line-height: 1.45; }

/* ---------- message after the gift ---------- */
#note {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 40px 28px calc(110px + var(--safe-b));
  opacity: 0; pointer-events: none; transition: opacity .9s ease;
  -webkit-backdrop-filter: blur(16px) brightness(.62) saturate(1.2);
  backdrop-filter: blur(16px) brightness(.62) saturate(1.2);
  background: rgba(10, 8, 18, .25);
}
#note.show { opacity: 1; pointer-events: auto; }
.n-day { font-family: var(--script); color: var(--gold); font-size: clamp(54px, 11vw, 92px); line-height: 1; text-shadow: 0 0 40px rgba(255, 200, 120, .4); }
.n-msg {
  max-width: 560px; margin-top: 18px; font-family: var(--serif); font-style: italic; font-weight: 500;
  font-size: clamp(22px, 4.6vw, 32px); line-height: 1.32; color: #fff9ec;
  text-shadow: 0 2px 20px rgba(0, 0, 0, .4);
}
.n-msg .w { display: inline-block; opacity: 0; transform: translateY(10px); filter: blur(8px); animation: word .9s cubic-bezier(.2,.8,.2,1) forwards; }
.n-sign { font-family: var(--script); font-size: 34px; color: var(--gold); margin-top: 22px; opacity: 0; transition: opacity 1.2s; }
.n-count {
  margin-top: 28px; font-size: 12px; font-weight: 600; letter-spacing: .28em; text-transform: uppercase; color: rgba(255, 255, 255, .72);
  opacity: 0; transition: opacity 1.2s;
}
#note.done .n-sign, #note.done .n-count { opacity: 1; }

/* ---------- loader ---------- */
#loader {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 22px;
  background: var(--night); transition: opacity 1s ease; z-index: 10;
}
#loader.done { opacity: 0; pointer-events: none; }
.l-star {
  width: 46px; height: 46px; background: var(--gold);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'%3E%3Cpath d='M32 2l7 20 21 1-17 12 6 21-17-12-17 12 6-21L4 23l21-1z'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'%3E%3Cpath d='M32 2l7 20 21 1-17 12 6 21-17-12-17 12 6-21L4 23l21-1z'/%3E%3C/svg%3E") center / contain no-repeat;
  animation: spin 3s linear infinite, breathe 1.6s ease-in-out infinite;
  filter: drop-shadow(0 0 14px rgba(255, 210, 140, .8));
}
.l-bar { width: 120px; height: 2px; border-radius: 2px; background: rgba(255, 255, 255, .15); overflow: hidden; }
.l-bar i { display: block; height: 100%; width: 0; background: var(--gold); transition: width .3s ease; }

/* ---------- keyframes ---------- */
@keyframes halo { 0%, 100% { opacity: .8; transform: scale(.94); } 50% { opacity: 1; transform: scale(1.06); } }
@keyframes halo-soft { 0%, 100% { opacity: .4; transform: scale(.78); } 50% { opacity: .62; transform: scale(.86); } }
@keyframes flicker { 0%, 100% { opacity: 1; } 12% { opacity: .82; } 14% { opacity: 1; } 47% { opacity: .9; } 60% { opacity: 1; } 78% { opacity: .86; } }
@keyframes shine { 0% { left: -80%; } 55%, 100% { left: 130%; } }
@keyframes bob { 0%, 100% { transform: translateY(0) rotate(-4deg); } 50% { transform: translateY(-9%) rotate(4deg); } }
@keyframes pop { 0% { transform: scale(1); } 40% { transform: scale(1.1); filter: brightness(1.25); } 100% { transform: scale(1); } }
@keyframes jiggle {
  0%, 100% { transform: rotate(0); } 15% { transform: rotate(-5deg) scale(1.03); } 30% { transform: rotate(4deg); }
  45% { transform: rotate(-3deg); } 60% { transform: rotate(2deg); } 75% { transform: rotate(-1deg); }
}
@keyframes breathe { 0%, 100% { opacity: .75; transform: scale(1); } 50% { opacity: 1; transform: scale(1.04); } }
@keyframes spin { to { rotate: 360deg; } }
@keyframes develop { 0% { opacity: 1; } 100% { opacity: 0; } }
@keyframes developImg { 0% { filter: sepia(1) brightness(1.5) contrast(.6) blur(4px); } 100% { filter: none; } }
@keyframes word { to { opacity: 1; transform: none; filter: none; } }

@media (prefers-reduced-motion: reduce) {
  .door.today .halo, .door.missed .halo, .star, .i-tap { animation: none; }
}
