/* ---------- Tokens ---------- */
:root {
  --night: #10201a;        /* page background, deep pine at night */
  --pine: #23442f;
  --spruce: #1c3b3a;
  --claret: #6b1a24;
  --oxblood: #4f2119;
  --gold: #d9ad55;
  --gold-soft: #b8893a;
  --cream: #f5e7c8;
  --cream-dim: #d9c9a6;
  --ember: #f0a04b;
  --ink: #2a1a12;          /* text on cream */

  --display: "Fraunces", Georgia, "Times New Roman", serif;
  --body: "Figtree", system-ui, -apple-system, "Segoe UI", sans-serif;

  --gap: 10px;
  --w: min(100vw - 32px, 30rem);
  --cell: calc((var(--w) - 3 * var(--gap)) / 4);
}

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

html {
  -webkit-text-size-adjust: 100%;
  background: var(--night);
}
html.is-locked { overflow: hidden; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--night);
  color: var(--cream);
  font-family: var(--body);
  font-size: 1rem;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

/* warm candle light pooling from the top */
.candle-glow {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(120% 55% at 50% -8%, rgba(240, 160, 75, .26), transparent 60%),
    radial-gradient(80% 50% at 50% 110%, rgba(107, 26, 36, .35), transparent 70%);
  z-index: 0;
}

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

.page {
  position: relative;
  z-index: 2;
  width: var(--w);
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top, 0px) + 28px) 0 calc(env(safe-area-inset-bottom, 0px) + 40px);
}

/* ---------- Header ---------- */
.hero {
  text-align: center;
  margin-bottom: 26px;
}
.hero__sprig {
  width: 92px;
  height: 31px;
  display: block;
  margin: 0 auto 6px;
  overflow: visible;
}
.hero__sprig path {
  fill: none;
  stroke: #4f7a57;
  stroke-width: 2.4;
  stroke-linecap: round;
}
.hero__sprig circle { fill: #b3242f; }

.hero__title {
  font-family: var(--display);
  font-variation-settings: "SOFT" 100, "opsz" 144;
  font-weight: 500;
  font-style: italic;
  font-size: clamp(2.3rem, 11vw, 3.4rem);
  line-height: 1.02;
  letter-spacing: -0.015em;
  margin: 0;
  color: var(--cream);
  text-wrap: balance;
  text-shadow: 0 0 28px rgba(240, 160, 75, .35);
}
.hero__subtitle {
  font-family: var(--display);
  font-variation-settings: "SOFT" 100, "opsz" 14;
  font-weight: 350;
  font-size: 1.06rem;
  color: var(--cream-dim);
  margin: 12px auto 0;
  max-width: 22rem;
  text-wrap: balance;
}
.hero__status {
  display: inline-block;
  margin: 16px 0 0;
  padding: 6px 14px;
  font-size: .88rem;
  font-weight: 500;
  color: var(--gold);
  border: 1px solid rgba(217, 173, 85, .35);
  border-radius: 999px;
  background: rgba(16, 32, 26, .6);
}
.hero__status:empty { display: none; }

/* ---------- Calendar grid ---------- */
.calendar {
  display: grid;
  grid-template-columns: repeat(4, var(--cell));
  grid-auto-rows: var(--cell);
  gap: var(--gap);
  grid-template-areas:
    "d7  d7  d12 d3"
    "d18 d1  d12 d20"
    "d5  d25 d25 d9"
    "d14 d25 d25 d9"
    "d22 d22 d16 d2"
    "d11 d4  d16 d24"
    "d19 d4  d13 d13"
    "d8  d15 d15 d21"
    "d23 d6  d10 d17";
}

/* ---------- Door ---------- */
.door {
  --face: var(--pine);
  --face-2: #1a3424;
  position: relative;
  padding: 0;
  border: 0;
  margin: 0;
  background: none;
  font: inherit;
  color: inherit;
  cursor: pointer;
  border-radius: 6px;
  perspective: 700px;
  transform: rotate(var(--tilt, 0deg));
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}
.door:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 3px;
}
.door--pine    { --face: #2a4d35; --face-2: #1b3425; }
.door--claret  { --face: #7a1f2a; --face-2: #561520; }
.door--spruce  { --face: #22474a; --face-2: #173234; }
.door--oxblood { --face: #5e2a1c; --face-2: #3f1c13; }

/* what's behind the door: a little lit window */
.door__inside {
  position: absolute;
  inset: 0;
  border-radius: 6px;
  overflow: hidden;
  background:
    radial-gradient(90% 80% at 60% 45%, rgba(255, 196, 110, .95), rgba(240, 160, 75, .55) 45%, rgba(107, 26, 36, .9) 100%);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .35), inset 0 6px 14px rgba(0, 0, 0, .35);
  display: grid;
  place-items: center;
  color: var(--ink);
}
.door__note {
  font-family: var(--display);
  font-weight: 600;
  font-variation-settings: "SOFT" 100, "opsz" 72;
  font-size: calc(var(--cell) * .34);
  line-height: 1;
  transform: translateX(14%);
  opacity: .85;
}

/* the door panel itself, hinged on the left */
.door__panel {
  position: absolute;
  inset: 0;
  border-radius: 6px;
  transform-origin: 0 50%;
  transform: rotateY(0deg);
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  background:
    linear-gradient(155deg, rgba(255, 255, 255, .07), transparent 45%),
    repeating-linear-gradient(92deg, rgba(0, 0, 0, .05) 0 2px, transparent 2px 7px),
    linear-gradient(180deg, var(--face), var(--face-2));
  box-shadow:
    0 1px 0 rgba(255, 255, 255, .08) inset,
    0 6px 14px rgba(0, 0, 0, .35),
    0 1px 2px rgba(0, 0, 0, .4);
  display: grid;
  place-items: center;
  will-change: transform;
}
/* gilded inset frame */
.door__panel::before {
  content: "";
  position: absolute;
  inset: 5px;
  border: 1px solid rgba(217, 173, 85, .55);
  border-radius: 3px;
}
/* door knob */
.door__panel::after {
  content: "";
  position: absolute;
  right: 9px;
  top: 50%;
  width: 6px;
  height: 6px;
  margin-top: -3px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #f6dc9a, var(--gold-soft));
  box-shadow: 0 1px 1px rgba(0, 0, 0, .4);
}
.door__num {
  position: relative;
  font-family: var(--display);
  font-variation-settings: "SOFT" 100, "opsz" 144;
  font-weight: 500;
  font-size: calc(var(--cell) * .42);
  line-height: 1;
  color: var(--gold);
  text-shadow: 0 1px 0 rgba(0, 0, 0, .35);
}

/* wide and tall doors get a bigger numeral */
.door--wide .door__num,
.door--tall .door__num { font-size: calc(var(--cell) * .5); }

/* today's door glows like it has a candle behind it */
.door--today .door__panel {
  box-shadow:
    0 0 0 1.5px var(--gold),
    0 0 22px rgba(240, 160, 75, .55),
    0 6px 14px rgba(0, 0, 0, .35);
}
@media (prefers-reduced-motion: no-preference) {
  .door--today .door__panel { animation: candle 3.2s ease-in-out infinite; }
}
@keyframes candle {
  0%, 100% { box-shadow: 0 0 0 1.5px var(--gold), 0 0 18px rgba(240, 160, 75, .45), 0 6px 14px rgba(0, 0, 0, .35); }
  50%      { box-shadow: 0 0 0 1.5px var(--gold), 0 0 30px rgba(240, 160, 75, .75), 0 6px 14px rgba(0, 0, 0, .35); }
}

/* opened doors rest ajar */
.door--open .door__panel {
  transform: rotateY(-76deg);
  box-shadow: 0 4px 10px rgba(0, 0, 0, .4);
}
.door--opening .door__panel {
  animation: swing 900ms cubic-bezier(.3, .7, .25, 1) forwards;
}
@keyframes swing {
  0%   { transform: rotateY(0deg); }
  18%  { transform: rotateY(6deg); }
  70%  { transform: rotateY(-86deg); }
  100% { transform: rotateY(-76deg); }
}

/* locked: rattle on the hinge */
.door--rattle .door__panel {
  animation: rattle 520ms ease-in-out;
}
@keyframes rattle {
  0%   { transform: rotateY(0) rotate(0); }
  20%  { transform: rotateY(-9deg) rotate(-1.2deg); }
  40%  { transform: rotateY(4deg) rotate(1deg); }
  60%  { transform: rotateY(-5deg) rotate(-.6deg); }
  80%  { transform: rotateY(2deg) rotate(.3deg); }
  100% { transform: rotateY(0) rotate(0); }
}

/* ---------- Day 25 ---------- */
.door--big { --face: #7a1f2a; --face-2: #4e121b; }
.door--big .door__num {
  font-size: calc(var(--cell) * .95);
  font-style: italic;
  margin-top: 8%;
}
.door--big .door__star {
  position: absolute;
  top: 8%;
  left: 50%;
  width: 20%;
  transform: translateX(-50%);
  fill: var(--gold);
  filter: drop-shadow(0 0 8px rgba(240, 160, 75, .7));
}
/* gold ribbon */
.door--big .door__panel {
  background:
    linear-gradient(90deg, transparent calc(50% - 7px), rgba(217, 173, 85, .9) calc(50% - 7px), #f0cf85 50%, rgba(217, 173, 85, .9) calc(50% + 7px), transparent calc(50% + 7px)),
    linear-gradient(155deg, rgba(255, 255, 255, .08), transparent 45%),
    linear-gradient(180deg, var(--face), var(--face-2));
}
.door--big .door__num {
  padding: 0 10px;
  background: linear-gradient(180deg, var(--face), var(--face-2));
  border-radius: 8px;
  box-shadow: 0 0 0 1px rgba(217, 173, 85, .5);
}
.door--big .door__panel::after { right: 14px; width: 9px; height: 9px; margin-top: -4.5px; }
.door--big .door__note { font-size: calc(var(--cell) * .7); }
.door--big .door__inside {
  background:
    radial-gradient(80% 70% at 60% 45%, #fff1c9, rgba(255, 196, 110, .95) 35%, rgba(240, 160, 75, .6) 60%, rgba(107, 26, 36, .95) 100%);
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 24px);
  z-index: 30;
  width: max-content;
  max-width: calc(100vw - 32px);
  padding: 12px 18px;
  border-radius: 14px;
  background: var(--cream);
  color: var(--ink);
  font-weight: 500;
  font-size: .95rem;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .45);
  transform: translate(-50%, 20px);
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease, transform .25s ease;
}
.toast.is-shown {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------- Sheet (opened door) ---------- */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.sheet[hidden] { display: none; }

.sheet__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(8, 16, 12, .72);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  animation: fade .3s ease both;
}
.sheet__card {
  position: relative;
  width: 100%;
  max-width: 34rem;
  max-height: calc(100dvh - 24px);
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  background:
    radial-gradient(120% 40% at 50% 0%, rgba(240, 160, 75, .18), transparent 70%),
    var(--cream);
  color: var(--ink);
  border-radius: 22px 22px 0 0;
  padding: 14px 22px calc(env(safe-area-inset-bottom, 0px) + 18px);
  box-shadow: 0 -10px 40px rgba(0, 0, 0, .5);
  animation: rise .42s cubic-bezier(.2, .8, .2, 1) both;
  outline: none;
}
.sheet.is-closing .sheet__card { animation: sink .25s ease-in both; }
.sheet.is-closing .sheet__backdrop { animation: fade .25s ease reverse both; }

@media (min-width: 600px) {
  .sheet { align-items: center; }
  .sheet__card { border-radius: 22px; padding-bottom: 22px; }
}

@keyframes rise { from { transform: translateY(100%); } to { transform: none; } }
@keyframes sink { from { transform: none; } to { transform: translateY(100%); } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.sheet__grab {
  width: 40px;
  height: 4px;
  border-radius: 2px;
  background: rgba(42, 26, 18, .18);
  margin: 0 auto 10px;
}
.sheet__close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: rgba(42, 26, 18, .07);
  color: var(--ink);
  display: grid;
  place-items: center;
  cursor: pointer;
}
.sheet__close svg { width: 20px; height: 20px; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; fill: none; }
.sheet__close:focus-visible, .sheet__back:focus-visible, .spotify-btn:focus-visible {
  outline: 2px solid var(--claret);
  outline-offset: 2px;
}

.sheet__head {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding-right: 44px;
  margin: 6px 0 14px;
}
.sheet__title {
  order: -1;
  margin: 0;
  font-family: var(--display);
  font-variation-settings: "SOFT" 100, "opsz" 144;
  font-weight: 500;
  font-style: italic;
  font-size: 3.4rem;
  line-height: .9;
  color: var(--claret);
}
.sheet__date {
  margin: 0;
  font-family: var(--display);
  font-variation-settings: "SOFT" 100, "opsz" 14;
  font-size: 1.05rem;
  color: rgba(42, 26, 18, .7);
}

.sheet__message {
  font-family: var(--display);
  font-variation-settings: "SOFT" 50, "opsz" 14;
  font-weight: 380;
  font-size: 1.08rem;
  line-height: 1.62;
  white-space: pre-line;
  overflow-wrap: anywhere;
  margin: 0 0 18px;
  max-width: 62ch;
}

.sheet__player {
  border-radius: 14px;
  overflow: hidden;
  background: #282828;
  min-height: 152px;
  box-shadow: 0 6px 18px rgba(42, 26, 18, .2);
}
.sheet__player iframe {
  display: block;
  width: 100%;
  border: 0;
}

.spotify-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  min-height: 52px;
  margin-top: 14px;
  padding: 12px 18px;
  border-radius: 999px;
  background: var(--pine);
  color: var(--cream);
  font-family: var(--body);
  font-weight: 600;
  font-size: 1.02rem;
  text-decoration: none;
  box-shadow: 0 4px 12px rgba(35, 68, 47, .35);
}
.spotify-btn svg { width: 22px; height: 22px; fill: #1ed760; flex: none; }
.spotify-btn:active { transform: translateY(1px); }

.wrapping {
  text-align: center;
  padding: 22px 8px 26px;
}
.wrapping p {
  font-family: var(--display);
  font-variation-settings: "SOFT" 100, "opsz" 14;
  font-size: 1.15rem;
  line-height: 1.5;
  margin: 12px auto 0;
  max-width: 18rem;
}
.song-soon {
  margin: 0;
  padding: 14px;
  border-radius: 14px;
  border: 1px dashed rgba(42, 26, 18, .3);
  text-align: center;
  color: rgba(42, 26, 18, .75);
}

.sheet__back {
  display: block;
  width: 100%;
  min-height: 48px;
  margin-top: 10px;
  border: 0;
  background: none;
  color: rgba(42, 26, 18, .7);
  font-family: var(--body);
  font-size: .95rem;
  font-weight: 500;
  cursor: pointer;
}

/* Christmas Day card */
.sheet--christmas .sheet__card {
  background:
    radial-gradient(120% 45% at 50% 0%, rgba(217, 173, 85, .35), transparent 70%),
    var(--cream);
  box-shadow: 0 -10px 40px rgba(0, 0, 0, .5), inset 0 0 0 2px rgba(217, 173, 85, .6);
}
.sheet--christmas .sheet__title { font-size: 2.6rem; line-height: 1; }
.sheet--christmas .sheet__head { flex-direction: column; align-items: flex-start; gap: 4px; }

.sparkle {
  position: fixed;
  z-index: 25;
  width: 8px;
  height: 8px;
  pointer-events: none;
  background: var(--gold);
  clip-path: polygon(50% 0, 62% 38%, 100% 50%, 62% 62%, 50% 100%, 38% 62%, 0 50%, 38% 38%);
  animation: sparkle 1.4s cubic-bezier(.15, .7, .3, 1) forwards;
}
@keyframes sparkle {
  0%   { transform: translate(0, 0) scale(.4) rotate(0); opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) scale(1.3) rotate(180deg); opacity: 0; }
}

.load-error {
  text-align: center;
  color: var(--cream-dim);
  padding: 40px 0;
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .door--opening .door__panel { animation: none; transform: rotateY(-76deg); }
  .door--rattle .door__panel { animation: none; }
  .sheet__card, .sheet__backdrop,
  .sheet.is-closing .sheet__card, .sheet.is-closing .sheet__backdrop { animation: none; }
  .toast { transition: opacity .2s ease; transform: translate(-50%, 0); }
  .sparkle { display: none; }
}
