/* ============================================================
   Advent Calendar — cozy winter CSS
   ============================================================ */
:root {
  --navy: #122036;
  --navy-deep: #0d0f1c;
  --navy-2: #1b2c4a;
  --gold: #e8c874;
  --gold-deep: #a8874a;
  --gold-soft: #f5d9a0;
  --red: #a8322d;
  --red-deep: #7e2320;
  --green: #2f6d52;
  --cream: #f7e9d3;
  --ink: #ece2d0;
  --muted: #b3a489;
  --door-1: #a8322d; --door-2: #2f6d52; --door-3: #b8860b; --door-4: #7a4b3a;
  --door-5: #5d7a3c; --door-6: #9c5131; --door-7: #33536b; --door-8: #8a3e55;
  --door-9: #5a6b2f; --door-10: #264d59; --door-11: #c98a3d; --door-12: #833c4e;
  --door-13: #3f6b3a; --door-14: #a56328; --door-15: #474f7a; --door-16: #96503a;
  --door-17: #6b4e2e; --door-18: #825d33; --door-19: #2d4f4a; --door-20: #a34a3a;
  --door-21: #7d5b8a; --door-22: #6e3a2e; --door-23: #4a6b45; --door-24: #c69a3f;
  --inner-bg: #2c2318;
  --radius: 12px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  min-height: 100vh;
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(232,200,116,0.13), transparent 60%),
    radial-gradient(900px 500px at 85% 110%, rgba(168,50,45,0.10), transparent 60%),
    radial-gradient(800px 400px at 10% 100%, rgba(47,109,82,0.10), transparent 60%),
    linear-gradient(180deg, #1b2c4a 0%, #16233c 45%, #101a2c 100%);
  color: var(--ink);
  font-family: Georgia, 'Times New Roman', serif;
  overflow-x: hidden;
  padding-bottom: 3rem;
}

/* ---------- Falling snow ---------- */
.snow {
  position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden;
}
.snowflake {
  position: absolute;
  top: -6vh;
  color: #fff;
  text-shadow: 0 0 6px rgba(255,255,255,0.55);
  animation-name: snow-fall, snow-sway;
  animation-duration: var(--dur, 11s), var(--dur2, 4s);
  animation-timing-function: linear, ease-in-out;
  animation-iteration-count: infinite, infinite;
  animation-delay: var(--delay, 0s), var(--delay, 0s);
  will-change: transform;
}
@keyframes snow-fall {
  from { transform: translateY(-8vh) translateX(0); }
  to   { transform: translateY(112vh) translateX(var(--drift, 3vw)); }
}
@keyframes snow-sway {
  0%, 100% { margin-left: 0; }
  50% { margin-left: 1.6vw; }
}

/* ---------- Header ---------- */
.header {
  position: relative; z-index: 2;
  max-width: 1180px; margin: 0 auto;
  padding: clamp(1.6rem, 4vw, 3rem) 1.2rem 1rem;
  display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem;
  flex-wrap: wrap;
}
.title {
  font-size: clamp(2.4rem, 6.5vw, 4.2rem);
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--cream);
  text-shadow: 0 2px 0 rgba(0,0,0,0.35), 0 0 26px rgba(232,200,116,0.18);
  line-height: 1;
}
.title-star { color: var(--gold); font-size: 0.55em; vertical-align: 0.28em; padding: 0 0.12em; }
.countdown {
  margin-top: 0.7rem;
  font-size: clamp(1rem, 2.4vw, 1.25rem);
  font-style: italic;
  color: var(--muted);
  letter-spacing: 0.02em;
}
.reset-btn {
  appearance: none; border: 1px solid rgba(232,200,116,0.4); border-radius: 999px;
  background: rgba(18,32,54,0.55); color: var(--gold-soft);
  font-family: inherit; font-size: 0.95rem; letter-spacing: 0.03em;
  padding: 0.55rem 1.1rem; cursor: pointer;
  backdrop-filter: blur(6px);
  transition: background 0.25s, border-color 0.25s, transform 0.15s;
}
.reset-btn:hover { background: rgba(168,50,45,0.35); border-color: var(--gold); transform: translateY(-1px); }
.reset-btn:active { transform: translateY(0) scale(0.98); }

/* ---------- Board ---------- */
.board-wrap { position: relative; z-index: 2; max-width: 1180px; margin: 0 auto; padding: 1rem; }
.board {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: clamp(0.55rem, 1.6vw, 1.15rem);
  perspective: 1400px;
  perspective-origin: 50% 40%;
}
@media (min-width: 560px)  { .board { grid-template-columns: repeat(6, minmax(0, 1fr)); } }
@media (min-width: 880px)  { .board { grid-template-columns: repeat(8, minmax(0, 1fr)); } }

/* ---------- Door (3D) ---------- */
.door {
  position: relative;
  appearance: none; -webkit-appearance: none;
  border: 0; background: transparent; padding: 0;
  aspect-ratio: 3 / 4;
  transform-style: preserve-3d;
  cursor: pointer;
  outline: none;
  -webkit-tap-highlight-color: transparent;
  /* transform used for hover lift + pop animation */
  --pop: 0px;
  transform: translateY(var(--pop));
  transition: transform 0.35s cubic-bezier(0.2, 0.8, 0.3, 1.2);
}
.door:hover, .door:focus-visible { --pop: -4px; }
.door:focus-visible {
  outline: 2px solid var(--gold); outline-offset: 4px; border-radius: var(--radius);
}
.door:active { transform: translateY(0) scale(0.98); }
.door.pop { animation: door-pop 0.45s cubic-bezier(0.2, 0.9, 0.3, 1.3); }
@keyframes door-pop {
  0%   { transform: translateY(var(--pop)) scale(1); }
  40%  { transform: translateY(var(--pop)) scale(1.09); }
  100% { transform: translateY(var(--pop)) scale(1); }
}

/* The door leaf swings TOWARD the viewer; the picture behind it stays put.
   Two-face flip: .door-front shows while closed, .door-back takes over once
   the leaf passes 90° — so the open door stays VISIBLE, lying open beside its
   frame like a real advent calendar door. */
.door-inner {
  position: absolute; inset: 0;
  transform-style: preserve-3d;
  transition: transform 1s cubic-bezier(0.5, 0, 0.2, 1.05), opacity 1.2s ease;
}
.door-front,
.door-back {
  position: absolute; inset: 0;
  border-radius: var(--radius);
  border: 1px solid rgba(0,0,0,0.45);
  overflow: hidden;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  box-shadow:
    inset 0 0 0 2px rgba(232,200,116,0.28),
    inset 0 0 0 8px rgba(0,0,0,0.10),
    0 10px 24px rgba(0,0,0,0.45);
  display: grid; place-items: center;
}
.door-front {
  background:
    repeating-linear-gradient(90deg, rgba(0,0,0,0.14) 0 2px, transparent 2px 16px),
    linear-gradient(155deg, var(--face-color) 0%, var(--face-dark) 100%);
  transform: translateZ(0.6px);              /* break coplanarity with the picture */
}
.door-back {                       /* the inside of the door */
  background:
    repeating-linear-gradient(90deg, rgba(0,0,0,0.10) 0 2px, transparent 2px 16px),
    linear-gradient(155deg, var(--face-dark) 0%, #241a10 100%);
  transform: rotateY(180deg) translateZ(0.6px);
}

/* swing TOWARD the viewer on both hinge sides */
.door.open .door-inner { transform: rotateY(-160deg); }                 /* left hinge  */
.door.open:nth-child(even) .door-inner { transform: rotateY(160deg); }  /* right hinge */

/* an open leaf floats ABOVE its neighbours while it swings / lies open */
.door.open { z-index: 8; }

/* auto-hide: 5s after opening the leaf fades away, leaving the picture
   clean; pointer-events:none lets clicks fall through to the picture */
.door.leaf-faded .door-inner {
  opacity: 0;
  pointer-events: none;
}
.door-front::after {              /* soft top sheen */
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(180deg, rgba(255,255,255,0.16), transparent 32%);
  pointer-events: none;
}
/* wreath decoration */
.wreath {
  position: relative;
  width: 44%; aspect-ratio: 1;
  border-radius: 50%;
  border: 3px solid var(--green);
  box-shadow: 0 0 0 2px rgba(0,0,0,0.25), inset 0 0 8px rgba(0,0,0,0.3);
  display: grid; place-items: center;
  background: radial-gradient(circle, rgba(0,0,0,0.25), transparent 70%);
}
.wreath::before {
  content: ""; position: absolute; inset: -3px; border-radius: 50%;
  border: 2px dotted rgba(232,200,116,0.5);
}
.wreath-berry {
  position: absolute; width: 7px; height: 7px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #e05a50, #a8322d);
  box-shadow: 0 1px 2px rgba(0,0,0,0.5);
  top: 12%; left: 50%; margin-left: -3.5px;
}
.wreath-berry.b2 { top: auto; bottom: 10%; left: 30%; }
.wreath-berry.b3 { top: auto; bottom: 10%; left: 68%; }
.wreath-bow {
  position: absolute; bottom: -4px; left: 50%; transform: translateX(-50%);
  font-size: 0.7em; color: var(--gold); text-shadow: 0 1px 2px rgba(0,0,0,0.6);
}

.door-num {
  position: absolute; bottom: 7%; left: 50%; transform: translateX(-50%);
  font-family: Georgia, serif;
  font-size: clamp(1rem, 2.6vw, 1.7rem);
  color: var(--gold-soft);
  text-shadow: 0 1px 2px rgba(0,0,0,0.7);
  letter-spacing: 0.05em;
  pointer-events: none;
}

/* Handle side depends on hinge */
.door-handle {
  position: absolute; top: 50%;
  width: 7px; height: 7px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #ffe9b0, #a8874a 70%);
  box-shadow: 0 1px 2px rgba(0,0,0,0.6);
  transform: translateY(-50%);
}
.door-handle { right: 9%; }                              /* odd grid position: hinge left  */
.door:nth-child(even) .door-handle { right: auto; left: 9%; }  /* even: hinge right */

/* Inside: window frame + picture */
.door-inside {
  position: absolute; inset: 0;
  border-radius: var(--radius);
  background: var(--inner-bg);
  overflow: hidden;
  box-shadow:
    inset 0 0 0 2px rgba(232,200,116,0.35),
    inset 0 0 0 7px rgba(0,0,0,0.55),
    inset 0 0 18px rgba(0,0,0,0.55);
}
.door-inside img {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  filter: saturate(1.05) contrast(1.03);
  transition: filter 0.6s ease, transform 6s ease;
}
.door-inside::after {   /* inner vignette so the picture looks recessed */
  content: ""; position: absolute; inset: 0;
  border-radius: inherit;
  box-shadow: inset 0 0 14px rgba(0,0,0,0.75);
  pointer-events: none;
}
.door.open .door-inside { cursor: zoom-in; }
.door.open .door-inside img { transform: scale(1.08); filter: saturate(1.1); }

/* the swinging panel casts a shadow while opening */
.door.open .door-inner { box-shadow: 0 18px 40px rgba(0,0,0,0.5); }

/* Ready pulse */
.door.ready::before {
  content: ""; position: absolute; inset: -3px; border-radius: calc(var(--radius) + 3px);
  border: 2px solid rgba(232,200,116,0.85);
  animation: glow-pulse 2.2s ease-in-out infinite;
  pointer-events: none; z-index: 3;
}
@keyframes glow-pulse {
  0%, 100% { opacity: 0.25; transform: scale(1); }
  50% { opacity: 0.9; transform: scale(1.04); }
}

/* Future door */
.door.future { cursor: not-allowed; }
.door.future .door-front {
  filter: brightness(0.45) saturate(0.55);
}
.door.future .door-front::before {
  content: ""; position: absolute; inset: 0; border-radius: inherit;
  background: radial-gradient(circle at 30% 20%, rgba(255,255,255,0.06), transparent 50%);
}
.door.future .door-inner { transform: none !important; }
.door.future:hover { --pop: 0px; }
.door.future .door-num { opacity: 0.55; }

/* ---------- Modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center;
  padding: 1.2rem;
}
.modal[hidden] { display: none; }
.modal-backdrop {
  position: absolute; inset: 0;
  background: radial-gradient(circle at 50% 40%, rgba(232,200,116,0.09), rgba(5,8,15,0.86) 65%);
  backdrop-filter: blur(5px);
  animation: fade-in 0.3s ease both;
}
.modal-card {
  position: relative;
  width: min(560px, 94vw);
  background: linear-gradient(160deg, #1e2b47, #131d31);
  border: 1px solid rgba(232,200,116,0.4);
  border-radius: 18px;
  box-shadow: 0 30px 80px rgba(0,0,0,0.7), inset 0 0 0 1px rgba(255,255,255,0.04);
  overflow: hidden;
  animation: pop-in 0.4s cubic-bezier(0.2, 0.9, 0.3, 1.25) both;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop-in {
  from { opacity: 0; transform: translateY(26px) scale(0.94); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.modal-img-wrap {
  aspect-ratio: 1 / 1;
  background: var(--inner-bg);
  overflow: hidden;
  border-bottom: 1px solid rgba(232,200,116,0.25);
}
.modal-img-wrap img {
  width: 100%; height: 100%; object-fit: cover; display: block;
}
.modal-info { padding: 1.1rem 1.4rem 1.5rem; text-align: center; }
.modal-eyebrow {
  color: var(--gold); text-transform: uppercase; letter-spacing: 0.32em;
  font-size: 0.72rem; margin-bottom: 0.3rem;
}
.modal-title { font-size: 1.5rem; color: var(--cream); margin-bottom: 0.45rem; }
.modal-text { color: var(--muted); line-height: 1.55; font-size: 1rem; font-style: italic; }
.modal-close {
  position: absolute; top: 0.8rem; right: 0.8rem; z-index: 2;
  width: 2.4rem; height: 2.4rem; border-radius: 50%;
  border: 1px solid rgba(232,200,116,0.5);
  background: rgba(10,15,26,0.7); color: var(--gold-soft);
  font-size: 1rem; cursor: pointer;
  transition: background 0.2s, transform 0.2s;
  backdrop-filter: blur(4px);
}
.modal-close:hover { background: var(--red); transform: rotate(90deg); }

body.modal-open { overflow: hidden; }

/* ---------- Footer ---------- */
.footer {
  position: relative; z-index: 2;
  text-align: center; color: var(--muted);
  font-size: 0.95rem; padding: 2.5rem 1rem 0;
}
.footer p { opacity: 0.8; }

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .snowflake { display: none; }
  .door-inner { transition-duration: 0.01s; }
  .door.ready::before { animation: none; opacity: 0.7; }
  .door.pop, .modal-card, .modal-backdrop { animation: none; }
}

@media (max-width: 480px) {
  .header { align-items: flex-start; }
  .title { font-size: 2.3rem; }
}

/* --- fixes: hinge pivot must sit on .door-inner (the rotating element) --- */
.door:nth-child(odd)  .door-inner { transform-origin: left center; }
.door:nth-child(even) .door-inner { transform-origin: right center; }

/* --- per-door face colors (CSS variables were referenced but never set) --- */
.door                { --face-color: #a8322d; --face-dark: #7e2320; }
.door:nth-child(4n+2) { --face-color: #2f6d52; --face-dark: #1f4a37; }
.door:nth-child(4n+3) { --face-color: #b8860b; --face-dark: #8a6a1d; }
.door:nth-child(4n+4) { --face-color: #7a4b3a; --face-dark: #5a3529; }

/* ---------- Magic mode chip (only rendered on the magic route) ---------- */
.magic-chip {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: 1.2rem; z-index: 40;
  display: flex; align-items: center; gap: 0.8rem;
  background: rgba(20,32,54,.92); color: var(--gold-soft);
  border: 1px solid rgba(232,200,116,.5); border-radius: 999px;
  padding: 0.55rem 0.6rem 0.55rem 1.1rem;
  font-size: 0.95rem; box-shadow: 0 12px 34px rgba(0,0,0,.5);
  backdrop-filter: blur(6px);
}
.magic-chip button {
  appearance: none; border: 1px solid rgba(232,200,116,.55); border-radius: 999px;
  background: transparent; color: var(--gold-soft); font-family: inherit;
  font-size: 0.85rem; padding: 0.35rem 0.8rem; cursor: pointer;
  transition: background 0.2s;
}
.magic-chip button:hover { background: rgba(168,50,45,.4); }
