/* ==========================================================================
   Christmas Movie Advent Calendar
   Mobile-first. Phone portrait = 4 columns, desktop = 6 columns.
   ========================================================================== */

:root {
  --pine-950: #04150f;
  --pine-900: #0b2e22;
  --pine-700: #145039;
  --red-900: #5e0e18;
  --red-700: #9b1b2a;
  --red-500: #c8323f;
  --gold: #e8bd5c;
  --gold-soft: #f3dc9e;
  --cream: #f8efd9;
  --ink: #3a1f14;

  --font-festive: 'Mountains of Christmas', 'Georgia', 'Times New Roman', serif;
  --font-body: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;

  /* Paper textures (inline SVG noise, no extra requests) */
  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .2  0 0 0 0 .12  0 0 0 0 .05  0 0 0 .22 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  --fiber: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='f'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.012 .35' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 1  0 0 0 0 1  0 0 0 0 1  0 0 0 .28 -.04'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23f)'/%3E%3C/svg%3E");

  --cols: 4;
  --gap: 9px;
  --ratio: 1.42;           /* door height / width */
  --page-max: 560px;
}

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

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--font-body);
  color: var(--cream);
  background-color: var(--pine-900);
  position: relative;
}
body::before {
  content: '';
  position: fixed;
  z-index: -1;
  inset: 0;
  pointer-events: none;
  background-image:
    /* snowy hills */
    radial-gradient(120% 60px at 20% 100%, #f4f7fb 98%, transparent 100%),
    radial-gradient(90% 90px at 85% 100%, #e6edf5 98%, transparent 100%),
    /* little stars */
    radial-gradient(1.5px 1.5px at 12% 18%, rgba(255,255,255,.8), transparent),
    radial-gradient(1.5px 1.5px at 72% 9%, rgba(255,255,255,.7), transparent),
    radial-gradient(1px 1px at 38% 6%, rgba(255,255,255,.8), transparent),
    radial-gradient(1px 1px at 90% 26%, rgba(255,255,255,.6), transparent),
    radial-gradient(1.5px 1.5px at 55% 22%, rgba(255,255,255,.5), transparent),
    /* night-forest glow */
    radial-gradient(ellipse 120% 70% at 50% 0%, #1d6347 0%, var(--pine-900) 55%, var(--pine-950) 100%);
  background-repeat: no-repeat;
}

.page {
  position: relative;
  z-index: 1;
  max-width: var(--page-max);
  margin: 0 auto;
  padding:
    calc(env(safe-area-inset-top, 0px) + 14px)
    calc(env(safe-area-inset-right, 0px) + 10px)
    calc(env(safe-area-inset-bottom, 0px) + 28px)
    calc(env(safe-area-inset-left, 0px) + 10px);
  overflow-x: clip;
}

/* ---------- Header ---------- */
.header { text-align: center; padding: 6px 48px 10px; }

.title {
  margin: 0;
  font-family: var(--font-festive);
  font-weight: 700;
  font-size: clamp(1.9rem, 9.4vw, 3.6rem);
  line-height: .95;
  color: var(--cream);
  text-shadow: 0 2px 0 var(--red-900), 0 0 18px rgba(232, 189, 92, .45);
  letter-spacing: .01em;
}
.title span { display: block; color: var(--gold); }

.status {
  margin: 8px 0 0;
  font-size: .92rem;
  color: var(--gold-soft);
  min-height: 1.3em;
}

.debug-pill {
  display: inline-block;
  margin: 0 0 8px;
  padding: 3px 10px;
  border-radius: 99px;
  background: #ffe066;
  color: #3a2c00;
  font-size: .75rem;
  font-weight: 600;
}
.debug-pill[hidden] { display: none; }

/* ---------- Board (the calendar card) ---------- */
.board {
  position: relative;
  container-type: inline-size;
  padding: 14px;
  border-radius: 14px;
  background-color: var(--red-700);
  background-image:
    var(--fiber),
    var(--grain),
    radial-gradient(2px 2px at 25% 30%, rgba(243,220,158,.35), transparent 60%),
    radial-gradient(2px 2px at 75% 60%, rgba(243,220,158,.35), transparent 60%),
    radial-gradient(ellipse at 50% 0%, #b9283a, var(--red-700) 60%, #7c1421);
  background-size: 240px 240px, 180px 180px, 46px 46px, 46px 46px, 100% 100%;
  box-shadow:
    inset 0 0 0 3px var(--gold),
    inset 0 0 0 6px var(--red-700),
    inset 0 0 0 7px rgba(232, 189, 92, .55),
    0 18px 40px rgba(0, 0, 0, .55),
    0 2px 0 rgba(255, 255, 255, .08);
}

/* ribbon bow on top of the board */
.board::before {
  content: '🎀';
  position: absolute;
  top: -22px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 34px;
  filter: drop-shadow(0 3px 3px rgba(0,0,0,.4));
  pointer-events: none;
}

.grid {
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  /* fallback if container units are unsupported */
  grid-auto-rows: calc((min(100vw, var(--page-max)) - 70px) / var(--cols) * var(--ratio));
  grid-auto-rows: calc((100cqi - (var(--cols) - 1) * var(--gap)) / var(--cols) * var(--ratio));
  gap: var(--gap);
  /* Fixed shuffled layout: same for everyone. Door 24 spans 2x2, door 6 is wide. */
  grid-template-areas:
    "d7  d15 d3  d20"
    "d11 d24 d24 d1"
    "d18 d24 d24 d9"
    "d5  d13 d22 d16"
    "d6  d6  d2  d19"
    "d14 d21 d10 d4"
    "d17 d8  d23 d12";
}

.grid-message {
  grid-column: 1 / -1;
  grid-row: 1 / -1;
  align-self: center;
  text-align: center;
  color: var(--cream);
}

/* ---------- Doors ---------- */
.slot {
  position: relative;
  display: block;
  margin: var(--mt, 0) var(--mr, 0) var(--mb, 0) var(--ml, 0);
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  color: inherit;
  cursor: pointer;
  perspective: 650px;
  transform: translate(var(--dx, 0), var(--dy, 0)) rotate(var(--tilt, 0deg));
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  z-index: 1;
}
.slot.open { z-index: 2; }
.slot.opening { z-index: 3; }
.slot:focus { outline: none; }
.slot:focus-visible { outline: 3px solid var(--gold-soft); outline-offset: 3px; border-radius: 6px; }

/* the hole behind the door */
.behind {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border-radius: 4px;
  background: #1c0b0e;
  box-shadow: inset 0 3px 10px rgba(0, 0, 0, .8), 0 0 0 1px rgba(0, 0, 0, .35);
}
.behind img {
  position: absolute;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
}
.poster-bg {
  inset: -12%;
  width: 124%;
  height: 124%;
  object-fit: cover;
  filter: blur(10px) brightness(.55) saturate(1.2);
}
.poster {
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.behind img:not([src]) { display: none; }
/* soft shadow the open door casts over the poster */
.behind::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, rgba(0,0,0,.45), transparent 28%);
  opacity: 0;
  transition: opacity .8s;
  pointer-events: none;
}
.slot.open .behind::after { opacity: 1; }

.door {
  position: absolute;
  inset: 0;
  transform-origin: left center;
  transform-style: preserve-3d;
  transform: rotateY(0deg);
  transition: transform .8s cubic-bezier(.32, .72, .26, 1.06);
  will-change: transform;
}
.slot.open .door { transform: rotateY(-100deg); }
.no-anim .door,
.no-anim .behind::after { transition: none !important; }

.face {
  position: absolute;
  inset: 0;
  border-radius: 4px;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}

.front {
  display: flex;
  align-items: var(--ny, center);
  justify-content: var(--nx, center);
  padding: 6px 8px;
  background-color: var(--paper, #f6ead0);
  background-image:
    var(--fiber),
    var(--grain),
    linear-gradient(135deg, rgba(255,255,255,.35), rgba(255,255,255,0) 45%, rgba(0,0,0,.08));
  background-size: 240px 240px, 180px 180px, 100% 100%;
  box-shadow:
    0 1px 0 rgba(255,255,255,.5) inset,
    0 -2px 0 rgba(0,0,0,.08) inset,
    0 2px 3px rgba(0,0,0,.35),
    0 0 0 1px rgba(0,0,0,.18);
}
/* perforated cut-line */
.front::before {
  content: '';
  position: absolute;
  inset: 4px;
  border: 1.5px dashed rgba(60, 30, 20, .28);
  border-radius: 3px;
  pointer-events: none;
}
/* little decoration in a corner */
.front::after {
  content: var(--deco, '');
  position: absolute;
  right: 7px;
  bottom: 5px;
  font-size: .8rem;
  color: var(--ink-soft, rgba(60, 30, 20, .35));
  pointer-events: none;
}

.num {
  position: relative;
  font-family: var(--font-festive);
  font-weight: 700;
  font-size: clamp(1.7rem, 9cqi, 2.6rem);
  line-height: 1;
  color: var(--num, var(--red-700));
  text-shadow: 0 1px 0 rgba(255, 255, 255, .55);
}

.back {
  transform: rotateY(180deg);
  background-color: #efe3c8;
  background-image:
    var(--grain),
    linear-gradient(270deg, rgba(0,0,0,.18), rgba(0,0,0,0) 60%);
  background-size: 180px 180px, 100% 100%;
  box-shadow: 0 0 0 1px rgba(0,0,0,.2), -3px 3px 8px rgba(0,0,0,.35);
}

/* Door 24: Christmas Eve */
.slot.eve .front {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}
.slot.eve .num { font-size: clamp(3rem, 18cqi, 5rem); }
.eve-label {
  font-family: var(--font-festive);
  font-weight: 700;
  font-size: clamp(.85rem, 4cqi, 1.3rem);
  color: var(--pine-700);
}
.eve-star {
  font-size: 1.3rem;
  line-height: 1;
  color: var(--red-700);
}

/* Today's door: gentle golden pulse */
.slot.today:not(.open) .front {
  animation: glow 2.6s ease-in-out infinite;
}
@keyframes glow {
  0%, 100% { box-shadow: 0 0 0 1px rgba(0,0,0,.18), 0 0 6px 2px rgba(255, 214, 110, .55), 0 2px 3px rgba(0,0,0,.35); }
  50%      { box-shadow: 0 0 0 1px rgba(0,0,0,.18), 0 0 16px 6px rgba(255, 214, 110, .95), 0 2px 3px rgba(0,0,0,.35); }
}

/* Locked door wiggle */
.slot.shake .door { animation: shake .45s cubic-bezier(.36, .07, .19, .97); }
@keyframes shake {
  10%, 90% { transform: translateX(-1px) rotate(-.5deg); }
  20%, 80% { transform: translateX(2px) rotate(.6deg); }
  30%, 50%, 70% { transform: translateX(-4px) rotate(-1deg); }
  40%, 60% { transform: translateX(4px) rotate(1deg); }
}

/* ---------- Footer ---------- */
.footer {
  margin-top: 22px;
  text-align: center;
  font-size: .8rem;
  color: rgba(248, 239, 217, .75);
  line-height: 1.5;
}
.footer p { margin: 6px 0; }
.footer a { color: var(--gold-soft); }
.footer .small { display: block; font-size: .7rem; opacity: .75; }
.link {
  padding: 6px 10px;
  border: 0;
  background: none;
  font: inherit;
  color: var(--gold-soft);
  text-decoration: underline;
  cursor: pointer;
}

/* ---------- Mute button ---------- */
.mute {
  position: absolute;
  z-index: 60;
  top: calc(env(safe-area-inset-top, 0px) + 10px);
  right: calc(env(safe-area-inset-right, 0px) + 10px);
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1.5px solid rgba(232, 189, 92, .7);
  border-radius: 50%;
  background: rgba(4, 21, 15, .55);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  z-index: 70;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 22px);
  max-width: calc(100vw - 32px);
  padding: 10px 18px;
  border-radius: 99px;
  background: var(--red-700);
  border: 2px solid var(--gold);
  color: var(--cream);
  font-weight: 600;
  font-size: .95rem;
  white-space: nowrap;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .45);
  transform: translate(-50%, 140%);
  opacity: 0;
  transition: transform .3s ease, opacity .3s ease;
  pointer-events: none;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }

/* ---------- Lightbox ---------- */
.lightbox {
  position: fixed;
  z-index: 80;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(4, 12, 9, .9);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  cursor: zoom-out;
  animation: fade-in .25s ease;
}
.lightbox[hidden] { display: none; }
.lightbox figure { margin: 0; text-align: center; }
.lightbox img {
  display: block;
  max-width: min(92vw, 500px);
  max-height: 78vh;
  max-height: 78dvh;
  width: auto;
  height: auto;
  border-radius: 8px;
  box-shadow: 0 0 0 3px var(--gold), 0 20px 60px rgba(0, 0, 0, .7);
  animation: pop-in .3s cubic-bezier(.3, 1.4, .5, 1);
}
.lightbox figcaption {
  margin-top: 14px;
  font-family: var(--font-festive);
  font-weight: 700;
  font-size: 1.35rem;
  color: var(--gold-soft);
}
.lightbox-hint { margin: 8px 0 0; font-size: .75rem; color: rgba(248, 239, 217, .55); }
@keyframes fade-in { from { opacity: 0; } }
@keyframes pop-in { from { transform: scale(.85); opacity: 0; } }

/* ---------- Celebration canvas ---------- */
.burst {
  position: fixed;
  z-index: 50;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* ---------- Snow ---------- */
.snow {
  position: fixed;
  z-index: 40;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}
.flake {
  position: absolute;
  top: -12px;
  left: var(--x);
  width: var(--s);
  height: var(--s);
  border-radius: 50%;
  background: #fff;
  opacity: var(--o);
  filter: blur(var(--b, 0px));
  animation: fall var(--d) linear var(--delay) infinite;
  will-change: transform;
}
@keyframes fall {
  0%   { transform: translate3d(0, 0, 0); }
  50%  { transform: translate3d(var(--drift), 55vh, 0); }
  100% { transform: translate3d(0, 110vh, 0); }
}

.noscript { position: fixed; inset: auto 0 0; padding: 12px; text-align: center; background: var(--red-700); }

/* ---------- Desktop / wide screens ---------- */
@media (min-width: 760px) {
  :root {
    --cols: 6;
    --gap: 14px;
    --ratio: 1.38;
    --page-max: 880px;
  }
  .page { padding-top: 28px; }
  .board { padding: 24px; }
  .grid {
    grid-template-areas:
      "d7  d15 d15 d20 d11 d1"
      "d18 d9  d24 d24 d5  d13"
      "d22 d9  d24 d24 d16 d2"
      "d19 d14 d21 d10 d4  d3"
      "d17 d8  d23 d12 d6  d6";
  }
  .num { font-size: clamp(2rem, 5cqi, 2.9rem); }
  .slot.eve .num { font-size: clamp(3.4rem, 10cqi, 5.4rem); }
  .eve-label { font-size: clamp(1rem, 2.6cqi, 1.5rem); }
  .footer { font-size: .85rem; }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .snow { display: none; }
  .door { transition-duration: .25s; transition-timing-function: ease-out; }
  .slot.today:not(.open) .front {
    animation: none;
    box-shadow: 0 0 0 1px rgba(0,0,0,.18), 0 0 12px 4px rgba(255, 214, 110, .8);
  }
  .slot.shake .door { animation-duration: .2s; }
  .lightbox, .lightbox img { animation: none; }
}
