/* ==========================================================
   Art of Orient: the New Year wish (loaded only with winter.js,
   when the holiday look is "New Year").

   The gifts next to the snowman are drawn by winter.js on its canvas;
   over each gift lies an invisible button (.winter-gift). Pressing it
   opens this: a matte navy envelope with a gold wax seal flies up from
   the gift, the seal breaks, the flap opens, and a rolled parchment scroll with
   gold end caps rises out. The envelope sinks away, the scroll comes to
   the middle and unrolls, and the wish appears, signed "Sincerely,
   Art of Orient" in the shop's own lettering.

   Order (all times from the click):
     0.00s  the dark veil fades in, the envelope flies up from the gift
     0.75s  the wax seal breaks
     0.95s  the flap opens
     1.45s  the rolled scroll rises out of the envelope
     2.15s  the envelope sinks away, the scroll comes to the middle
     2.80s  the scroll unrolls (the two rolls move apart)
     3.15s  the words appear
   ========================================================== */

/* the invisible button over each gift (moved by winter.js every frame) */
.winter-gift {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 20;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.winter-gift:focus-visible { outline: 2px solid var(--gold-hi, #e6d7b2); outline-offset: 2px; }

/* ---------- the veil and the dialog ---------- */
.wish-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(3, 8, 22, 0);
  -webkit-backdrop-filter: blur(0);
  backdrop-filter: blur(0);
  transition: background-color 0.45s ease, backdrop-filter 0.45s ease, -webkit-backdrop-filter 0.45s ease;
}
.wish-overlay.is-open {
  background: rgba(3, 8, 22, 0.8);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}
.wish-overlay.is-closing { transition-duration: 0.35s; background: rgba(3, 8, 22, 0); -webkit-backdrop-filter: blur(0); backdrop-filter: blur(0); }

.wish {
  /* every size inside follows the width of this box (cqw = 1% of it) */
  container-type: inline-size;
  position: relative;
  width: min(92vw, 440px);
}
.wish-overlay.is-closing .wish { animation: wishAway 0.35s ease forwards; }
@keyframes wishAway { to { opacity: 0; transform: translateY(14px) scale(0.96); } }

/* ---------- the envelope ---------- */
.env {
  position: relative;
  aspect-ratio: 3 / 2;
  perspective: 1200px;
  /* flies up from the gift (--from-x / --from-y: where the gift is, set by winter.js) */
  transform: translate(var(--from-x, 0px), var(--from-y, 300px)) scale(0.12) rotate(-10deg);
  opacity: 0;
}
.is-open .env { animation: envIn 0.75s cubic-bezier(0.2, 0.8, 0.2, 1) forwards; }
@keyframes envIn {
  60% { opacity: 1; }
  to { opacity: 1; transform: none; }
}
.env-body > svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }

/* The inside of the envelope: the same matte navy paper with its linen grain, a shade darker,
   with a soft shadow at the top where the flap folds. */
.env-back {
  position: absolute;
  z-index: 0;
  inset: 0;
  border-radius: 1cqw;
  background:
    linear-gradient(rgba(0, 0, 0, 0.35), transparent 30%),
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.035) 0 1px, transparent 1px 3px),
    repeating-linear-gradient(90deg, rgba(0, 0, 0, 0.06) 0 1px, transparent 1px 3px),
    #182f4e;
  box-shadow: 0 3cqw 8cqw rgba(0, 0, 0, 0.6), 0 0.6cqw 1.2cqw rgba(0, 0, 0, 0.35);
}
.env-front { z-index: 3; filter: drop-shadow(0 -0.4cqw 0.8cqw rgba(0, 0, 0, 0.35)); }

/* The flap: navy outside, the lining inside (seen when it is open). It sits in its own holder
   (.env-flap-holder), which carries its place in the stack and its sinking away: the sinking fades
   it out, and a fading element cannot keep its children in 3D, so the turning flap needs its own box. */
.env-flap-holder {
  position: absolute;
  z-index: 4;
  inset: 0;
  perspective: 1200px;
}
.env-flap {
  position: absolute;
  inset: 0;
  transform-origin: 50% 0;
  transform-style: preserve-3d;
}
.env-flap > * {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}
.flap-outside { filter: drop-shadow(0 0.9cqw 1cqw rgba(0, 0, 0, 0.38)); }
.flap-inside { transform: rotateX(180deg); }
.is-open .env-flap { animation: flapOpen 0.6s cubic-bezier(0.5, 0, 0.3, 1) 0.95s forwards; }
@keyframes flapOpen { to { transform: rotateX(180deg); } }
/* halfway open the flap goes behind the scroll, so the scroll can come out over it */
.is-open .env-flap-holder { animation: flapBehind 0.6s step-end 0.95s forwards; }
@keyframes flapBehind { 50%, to { z-index: 1; } }
/* When the scroll is out, the whole envelope sinks away and fades, as one piece (.env-body holds
   the back, the front, the flap and the seal). winter.js adds .is-sinking at that moment, not
   earlier: until then the scroll has to pass between the back and the front of the envelope. */
.env-body { position: absolute; inset: 0; }
.is-sinking .env-body { animation: envSink 0.7s cubic-bezier(0.4, 0, 0.2, 1) forwards; }
@keyframes envSink { to { transform: translateY(30%) scale(0.94); opacity: 0; } }

/* the red wax seal on the flap's tip */
.env-seal {
  position: absolute;
  z-index: 5;
  left: 50%;
  top: 59.5%;
  width: 18cqw;
  height: 18cqw;
  margin: -9cqw 0 0 -9cqw;
  filter: drop-shadow(0 0.5cqw 0.6cqw rgba(0, 0, 0, 0.5));
}
.env-seal svg { display: block; width: 100%; height: 100%; }
.is-open .env-seal { animation: sealBreak 0.4s ease-in 0.75s forwards; }
@keyframes sealBreak {
  35% { transform: scale(1.12) rotate(-6deg); opacity: 1; }
  to { transform: scale(0.4) rotate(18deg); opacity: 0; }
}

/* ---------- the scroll ---------- */
/* .scroll-move carries it: out of the envelope, then to the middle. Its middle is the
   envelope's middle, which is the middle of the screen. */
.scroll-move {
  position: absolute;
  z-index: 2;
  left: 50%;
  top: 50%;
  width: 84cqw;
  transform: translate(-50%, calc(-50% + 12cqw));
}
.is-open .scroll-move { animation: scrollOut 1.35s cubic-bezier(0.3, 0.7, 0.2, 1) 1.45s forwards; }
@keyframes scrollOut {
  0% { transform: translate(-50%, calc(-50% + 12cqw)); z-index: 2; }
  52% { transform: translate(-50%, calc(-50% - 45cqw)) rotate(-1.5deg); z-index: 2; }
  54% { z-index: 6; }
  100% { transform: translate(-50%, -50%); z-index: 6; }
}

.scroll {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  filter: drop-shadow(0 2.4cqw 3cqw rgba(0, 0, 0, 0.45));
}

/* The two rolls of paper with gold end caps. Rolled up, they lie on top of each other in the
   middle (moved in by --half = half the sheet's height, measured by winter.js); unrolling,
   they move apart to the top and the bottom of the sheet. */
.roll {
  position: relative;
  z-index: 2;
  width: 100%;
  height: 5.6cqw;
  border-radius: 2.8cqw / 50%;
  background: linear-gradient(to bottom, #a8956c 0%, #e9dcbc 18%, #fbf5e6 42%, #efe3c4 64%, #c8b48a 88%, #9a8660 100%);
  box-shadow: inset 0 -0.3cqw 0.4cqw rgba(90, 60, 20, 0.25);
}
/* a thin line where the sheet goes into the roll */
.roll::after {
  content: "";
  position: absolute;
  left: 3%;
  right: 3%;
  height: 1px;
  background: rgba(120, 85, 40, 0.35);
}
.roll-top::after { bottom: 22%; }
.roll-bottom::after { top: 22%; }
.roll-top { transform: translateY(var(--half, 0px)); }
.roll-bottom { transform: translateY(calc(-1 * var(--half, 0px))); }
.is-open .roll { animation: rollApart 0.95s cubic-bezier(0.45, 0, 0.2, 1) 2.8s forwards; }
@keyframes rollApart { to { transform: none; } }

/* the gold end caps: engraved rings and a round knob */
.cap {
  position: absolute;
  top: 50%;
  width: 4.4cqw;
  height: 8cqw;
  margin-top: -4cqw;
  border-radius: 1.1cqw;
  background:
    repeating-linear-gradient(90deg, rgba(70, 45, 10, 0.35) 0 1px, transparent 1px 0.9cqw),
    linear-gradient(to bottom, #7d5f27 0%, #e9d39c 22%, #fff3cf 34%, #c9a65f 55%, #9c7a3a 78%, #6e521f 100%);
  box-shadow: 0 0.3cqw 0.6cqw rgba(0, 0, 0, 0.35), inset 0 0 0 1px rgba(255, 240, 200, 0.35);
}
.cap::after {
  content: "";
  position: absolute;
  top: 50%;
  width: 2.6cqw;
  height: 2.6cqw;
  margin-top: -1.3cqw;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff3cf, #c9a65f 45%, #6e521f);
}
.cap-l { left: -3.6cqw; }
.cap-l::after { left: -1.7cqw; }
.cap-r { right: -3.6cqw; }
.cap-r::after { right: -1.7cqw; }

/* The sheet: aged parchment, darker towards its edges, with a few soft stains and a fine grain.
   Rolled up it is cut down to nothing in the middle; unrolling, it opens from the middle out. */
.scroll-sheet {
  position: relative;
  z-index: 1;
  width: 92%;
  margin: -2.2cqw 0;
  padding: 9cqw 8cqw 10.5cqw;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.4cqw;
  text-align: center;
  color: #3b2a16;
  background:
    radial-gradient(ellipse 30% 22% at 18% 16%, rgba(150, 105, 50, 0.16), transparent 70%),
    radial-gradient(ellipse 34% 26% at 84% 78%, rgba(150, 105, 50, 0.18), transparent 70%),
    radial-gradient(ellipse 22% 16% at 70% 22%, rgba(160, 115, 60, 0.1), transparent 70%),
    radial-gradient(ellipse 70% 60% at 50% 45%, rgba(255, 252, 240, 0.5), transparent 75%),
    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 .45 0 0 0 0 .31 0 0 0 0 .14 0 0 0 .2 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E"),
    #efe2c2;
  box-shadow: inset 0 0 4cqw rgba(125, 82, 30, 0.38), inset 0 0 0.8cqw rgba(110, 70, 25, 0.45);
  clip-path: inset(50% 0 50% 0);
}
.is-open .scroll-sheet { animation: sheetOpen 0.95s cubic-bezier(0.45, 0, 0.2, 1) 2.8s forwards; }
@keyframes sheetOpen { to { clip-path: inset(0 0 0 0); } }

/* faint rosettes in the four corners, like the ornament of old paper */
.scroll-sheet::before {
  content: "";
  position: absolute;
  inset: 3.4cqw;
  pointer-events: none;
  opacity: 0.4;
  --rosette: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Cg fill='none' stroke='%238a6a2e' stroke-width='1.2'%3E%3Cpath d='M20 4c4 6 4 10 0 16-4-6-4-10 0-16zM20 36c4-6 4-10 0-16-4 6-4 10 0 16zM4 20c6-4 10-4 16 0-6 4-10 4-16 0zM36 20c-6-4-10-4-16 0 6 4 10 4 16 0z'/%3E%3Ccircle cx='20' cy='20' r='2.5'/%3E%3C/g%3E%3C/svg%3E");
  background:
    var(--rosette) left top / 7cqw no-repeat,
    var(--rosette) right top / 7cqw no-repeat,
    var(--rosette) left bottom / 7cqw no-repeat,
    var(--rosette) right bottom / 7cqw no-repeat;
}

.scroll-text { display: contents; }
.scroll-text > * { opacity: 0; }
.is-open .scroll-text > * { animation: inkIn 0.7s ease forwards; }
.is-open .scroll-text > :nth-child(1) { animation-delay: 3.15s; }
.is-open .scroll-text > :nth-child(2) { animation-delay: 3.25s; }
.is-open .scroll-text > :nth-child(3) { animation-delay: 3.35s; }
.is-open .scroll-text > :nth-child(4) { animation-delay: 3.45s; }
.is-open .scroll-text > :nth-child(5) { animation-delay: 3.7s; }
@keyframes inkIn { from { opacity: 0; transform: translateY(0.6cqw); } to { opacity: 1; transform: none; } }

/* gold foil: a metal gradient inside the letters, with one slow gleam passing over it */
.wish-foil {
  background: linear-gradient(105deg, #6a4f1d 0%, #a8823f 22%, #e8d39c 38%, #94712f 52%, #c9a65f 70%, #6e521f 100%);
  background-size: 220% 100%;
  background-position: 100% 0;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.is-open .scroll-text > .wish-foil { animation: inkIn 0.7s ease 3.25s forwards, foilGleam 1.6s ease-in-out 3.9s forwards; }
@keyframes foilGleam { from { background-position: 100% 0; } to { background-position: 0 0; } }

.wish-year {
  margin: 0;
  font-family: "Cinzel", Georgia, serif;
  font-weight: 600;
  font-size: 3.2cqw;
  letter-spacing: 0.5em;
  padding-left: 0.5em; /* the letter spacing would push it off centre */
  color: #8a6a2e;
}
.wish-title {
  margin: 0;
  font-family: "Cormorant Garamond", Garamond, Georgia, serif;
  font-weight: 600;
  font-style: italic;
  font-size: 8.2cqw;
  line-height: 1.05;
}
.wish-rule { display: flex; align-items: center; gap: 2cqw; margin: 0.6cqw 0 1cqw; }
.wish-rule span { width: 9cqw; height: 1px; background: rgba(138, 106, 46, 0.7); }
.wish-rule i { width: 1.5cqw; height: 1.5cqw; background: #a8262f; transform: rotate(45deg); }
.wish-text {
  margin: 0;
  font-family: "Cormorant Garamond", Garamond, Georgia, serif;
  font-weight: 500;
  font-size: 5cqw;
  line-height: 1.34;
  text-wrap: balance;
}

/* "Sincerely," and under it "Art of Orient" in the shop's own lettering (wordmark.svg), in gold foil */
.wish-sign {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 1.4cqw;
  align-self: stretch;
  margin: 3cqw 0 0;
  padding-right: 1cqw;
}
.wish-regards {
  font-family: "Cormorant Garamond", Garamond, Georgia, serif;
  font-style: italic;
  font-weight: 500;
  font-size: 4.6cqw;
  line-height: 1;
  color: #5a4220;
}
.wish-mark {
  width: 36cqw;
  aspect-ratio: 714 / 116.5;
  background: linear-gradient(105deg, #6a4f1d 0%, #9c7a3a 25%, #c9ab6c 45%, #8c6a2c 62%, #6a4f1d 100%);
  -webkit-mask: var(--wordmark) center / contain no-repeat;
  mask: var(--wordmark) center / contain no-repeat;
}

/* the × in the corner of the sheet, and the "Thank you!" button under the scroll */
.wish-close {
  position: absolute;
  z-index: 3;
  top: 3.6cqw;
  right: 3.6cqw;
  width: 7.5cqw;
  height: 7.5cqw;
  min-width: 32px;
  min-height: 32px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: #7d5f27;
  cursor: pointer;
  opacity: 0;
}
.is-open .wish-close { animation: inkIn 0.4s ease 3.3s forwards; }
.wish-close:hover { background: rgba(125, 95, 39, 0.12); }
.wish-thanks {
  position: absolute;
  z-index: 7;
  left: 50%;
  top: calc(50% + var(--half, 0px) + 7cqw);
  transform: translate(-50%, 12px);
  opacity: 0;
  pointer-events: none;
  white-space: nowrap;
}
.is-open .wish-thanks { animation: thanksIn 0.5s var(--ease-out, ease) 3.8s forwards; }
@keyframes thanksIn { to { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; } }

/* With "Reduce motion" on the scroll is simply there, open */
@media (prefers-reduced-motion: reduce) {
  .is-open *, .is-open .env, .is-sinking .env-body { animation-duration: 0.01s !important; animation-delay: 0s !important; }
}
