@import url('https://fonts.googleapis.com/css2?family=Great+Vibes&display=swap');

/* =========================================================================
   envelope.css — вступний екран «конверт із сургучевою печаткою»
   Варіант A: CSS 3D + WAAPI + SVG-фільтри (зерно/фактура).
   Анімуються ЛИШЕ transform / opacity / зареєстровані @property.
   Кольори й «характер» матеріалу правляться в блоці --env-* нижче.
   ========================================================================= */

/* ---- Типізовані кастомні властивості (@property): освітлення клапана й
   відблиск сургучу інтерполюються плавно в Chromium; у Safari/FF WAAPI не
   анімує custom props — там вони лишаються статичними (грейсфул-деградація).
   Тому МОТОРИКА (обертання клапана, рух тіней) винесена на transform/opacity/
   filter, які працюють у всіх браузерах. --- */
@property --flap-bright  { syntax: '<number>'; inherits: true; initial-value: 1; }
@property --seal-shine   { syntax: '<number>'; inherits: true; initial-value: 0; }

/* =========================== КАСТОМІЗАЦІЯ ================================= */
.env-stage {
  /* --- палітра (Олива, Пудровий, Беж, Шоколад, Лимон) --- */
  --env-bg:      #455239;                 /* тло екрана = оливковий з фото */
  --env-bg-2:    #2F3A24;                 /* нижній край тла (темна олива) */
  --env-outer:   #E8DEC9;                 /* зовнішній папір конверта (беж) */
  --env-outer-2: #DACDB4;                 /* тінь/згин зовнішнього паперу */
  --env-inner:   #F6F0E4;                 /* внутрішня сторона клапана */
  --env-edge:    #C9BAA2;                 /* торець паперу */
  --seal:        #B87B6D;                 /* сургуч (пудровий рожево-теракотовий) */
  --seal-hi:     #E09F91;                 /* відблиск сургучу (світло-пудровий) */
  --seal-lo:     #7D473B;                 /* глибока тінь сургучу */
  --paper:       #F9F5EC;                 /* картка-запрошення (кремовий беж) */
  --paper-2:     #EFE8D9;                 /* легкий зсув кольору картки */
  --ink:         #3E2D25;                 /* текст на картці (шоколад з фото) */
  --ink-soft:    #8A776A;                 /* другорядний текст на картці */
  --text-secondary: rgba(249,245,236,.75);/* підказка на тлі */

  /* --- фактура паперу: дрібне «зерно» через feTurbulence (fractalNoise).
     Висока baseFrequency = дрібні волокна, а не великі брудні хмари.
     Накладається м'яко (soft-light) з низькою помітністю. --- */
  --noise-soft: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='s'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' seed='7' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3CfeComponentTransfer%3E%3CfeFuncA type='linear' slope='0.5' intercept='0'/%3E%3C/feFuncA%3E%3C/feComponentTransfer%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23s)'/%3E%3C/svg%3E");
  --noise-fine: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='f'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='1.2' numOctaves='1' seed='3' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23f)'/%3E%3C/svg%3E");
}

/* ============================= КАРКАС ==================================== */
.env-stage, .env-stage *, .env-stage *::before, .env-stage *::after { box-sizing: border-box; }
.env-stage {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background:
    radial-gradient(120% 90% at 50% 34%, var(--env-bg) 0%, var(--env-bg-2) 100%);
  font-family: 'Cormorant Garamond', Georgia, serif;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  cursor: pointer;                         /* клікабельно на всій зоні */
}
.env-stage[hidden] { display: none; }

/* блокування скролу лендінга, поки конверт закритий */
html.env-locked, body.env-locked { overflow: hidden !important; }

/* м'яка віньєтка/пил у повітрі */
.env-stage::after {
  content: '';
  position: absolute; inset: 0;
  background: radial-gradient(60% 45% at 50% 62%, transparent 55%, rgba(0,0,0,.32) 100%);
  pointer-events: none;
}

/* сцена з перспективою; розмір конверта адаптивний під портрет/ландшафт */
.env-scene {
  position: relative;
  width: min(88vw, 360px);                 /* фолбек без dvh */
  width: min(88vw, 360px, 120dvh);         /* + обмеження висотою (ландшафт) */
  aspect-ratio: 3 / 2;
  z-index: 1;                              /* над віньєткою ::after */
  -webkit-perspective: 1000px;
  perspective: 1000px;
  -webkit-perspective-origin: 50% 40%;
  perspective-origin: 50% 40%;
  -webkit-transform-style: preserve-3d;
  transform-style: preserve-3d;
  transform: translateZ(0);
}

/* обгортка для фінального відходу назад */
.env-recede {
  position: absolute;
  inset: 0;
  -webkit-transform-style: preserve-3d;
  transform-style: preserve-3d;
  transition: transform 0.8s cubic-bezier(.4,0,.2,1), opacity 0.8s ease;
}

/* тіло конверта у 3D */
.env {
  position: absolute;
  inset: 0;
  -webkit-transform-style: preserve-3d;
  transform-style: preserve-3d;
  transform: translateY(0);
  transition: transform .5s cubic-bezier(.22,.61,.36,1);   /* hover-підйом */
}
.env-stage.is-hover:not(.is-opening) .env { transform: translateY(-4px); }

/* спільна фактура паперу */
.paper-face {
  background-color: var(--env-outer);
  background-image:
    linear-gradient(150deg, rgba(255,255,255,.10), rgba(0,0,0,.05) 60%, rgba(0,0,0,.10)),
    var(--noise-soft);
  background-size: cover, 220px 220px;
  background-blend-mode: normal, soft-light;
}
.paper-face::after {                        /* дрібне зерно поверх */
  content: '';
  position: absolute; inset: 0;
  background-image: var(--noise-fine);
  background-size: 140px 140px;
  opacity: .05;
  mix-blend-mode: overlay;
  pointer-events: none;
}

/* --------- задня стінка (внутрішній бік конверта, база) ------------------ */
.env-back {
  position: absolute; inset: 0;
  border-radius: 7px;
  background-color: #d8c6a6;               /* трохи темніша — це «нутро» */
  background-image:
    linear-gradient(180deg, rgba(0,0,0,.18), rgba(0,0,0,.04) 40%, rgba(0,0,0,.12)),
    var(--noise-soft);
  background-size: cover, 220px 220px;
  background-blend-mode: multiply, soft-light;
  box-shadow: inset 0 2px 6px rgba(40,14,22,.28),
              0 6px 20px rgba(0,0,0,.3);
  overflow: hidden;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  transform: translateZ(-6px);
}

/* контактна тінь під конвертом (коротка й щільна) */
.env-contact {
  position: absolute;
  left: 6%; right: 6%;
  bottom: -6%;
  height: 14%;
  border-radius: 50%;
  background: rgba(20,6,10,.5);
  opacity: .84;
  filter: blur(18px);
  transform: translateZ(-40px);
  z-index: 0;
}

/* картка-запрошення */
.env-card {
  position: absolute;
  left: 16%;
  top: 6%;
  width: 68%;
  height: 88%;
  border-radius: 4px;
  transform: translateZ(2px) translateY(0);
  transform-origin: 50% 100%;
  background:
    linear-gradient(160deg, var(--paper) 0%, var(--paper-2) 100%),
    var(--noise-soft);
  background-size: cover, 220px 220px;
  background-blend-mode: normal, soft-light;
  box-shadow: 0 6px 14px rgba(40,14,22,.20), inset 0 1px 0 rgba(255,255,255,.6);
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 8% 10% 6%;
  text-align: center;
  color: var(--ink);
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  transition: transform 1.2s cubic-bezier(.22,.55,.12,1), z-index 0s linear;
}
.env-card.is-raised {
  z-index: 10;
}
.env-card .ec-kicker {
  font-family: 'Montserrat', sans-serif; font-weight: 300;
  font-size: 8px; letter-spacing: .34em; text-transform: uppercase;
  color: var(--ink-soft);
}
.env-card .ec-mono {
  font-family: 'Great Vibes', cursive;
  font-size: clamp(20px, 6.5vw, 32px) !important;
  line-height: 1.1;
  color: var(--seal);
  margin: 2px 0;
  white-space: nowrap !important;
  display: inline-block !important;
  word-break: keep-all !important;
  overflow: visible;
}
.env-card .ec-names {
  font-family: 'Cormorant Garamond', serif; font-style: italic;
  font-size: clamp(13px, 4.5vw, 18px); color: var(--ink);
  white-space: nowrap;
}
.env-card .ec-rule { width: 34px; height: 1px; background: var(--ink-soft); opacity: .5; margin: 6px 0; }
.env-card .ec-date {
  font-family: 'Montserrat', sans-serif; font-weight: 300;
  font-size: 9px; letter-spacing: .28em; color: var(--ink-soft);
}

/* ---- Передні клапани конверта (кишеня) ---- */
.ff {
  position: absolute; inset: 0;
  z-index: 4;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  -webkit-transform-style: preserve-3d;
  transform-style: preserve-3d;
  transform: translateZ(8px);
  background-color: var(--env-outer);
  background-image: var(--noise-soft);
  background-size: 180px 180px;
  background-blend-mode: soft-light;
  pointer-events: none;
}
/* нижній клапан */
.ff-bottom {
  -webkit-clip-path: polygon(0 100%, 100% 100%, 50% 48%);
  clip-path: polygon(0 100%, 100% 100%, 50% 48%);
  background-image:
    linear-gradient(0deg, rgba(255,255,255,.10), rgba(0,0,0,.10) 82%, rgba(0,0,0,.16)),
    var(--noise-soft);
  background-size: cover, 180px 180px;
  background-blend-mode: normal, soft-light;
}
/* бічні клапани */
.ff-left {
  -webkit-clip-path: polygon(0 0, 0 100%, 50% 48%);
  clip-path: polygon(0 0, 0 100%, 50% 48%);
  background-image:
    linear-gradient(100deg, rgba(255,255,255,.04), rgba(0,0,0,.14) 96%),
    var(--noise-soft);
  background-size: cover, 180px 180px;
  background-blend-mode: normal, soft-light;
}
.ff-right {
  -webkit-clip-path: polygon(100% 0, 100% 100%, 50% 48%);
  clip-path: polygon(100% 0, 100% 100%, 50% 48%);
  background-image:
    linear-gradient(-100deg, rgba(255,255,255,.04), rgba(0,0,0,.14) 96%),
    var(--noise-soft);
  background-size: cover, 180px 180px;
  background-blend-mode: normal, soft-light;
}
/* шви кишені */
.env-seams {
  position: absolute; inset: 0;
  z-index: 5;
  transform: translateZ(9px);
  pointer-events: none;
  background:
    conic-gradient(at 50% 48%,
      transparent 121deg, rgba(30,10,16,.22) 124deg, transparent 127deg,
      transparent 233deg, rgba(30,10,16,.22) 236deg, transparent 239deg,
      transparent 360deg);
}
.env-seams::after {
  content: '';
  position: absolute; inset: 0;
  background: radial-gradient(58% 40% at 50% 50%, rgba(0,0,0,.08), transparent 72%);
}

/* тінь від піднятого клапана */
.env-castshadow {
  position: absolute;
  left: 10%; right: 10%;
  top: 1%;
  height: 50%;
  -webkit-clip-path: polygon(0 0, 100% 0, 50% 100%);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  background: rgba(30,10,16,1);
  opacity: 0;
  filter: blur(6px);
  transform: translateY(0) scaleY(.96) translateZ(8.5px);
  transform-origin: top center;
  z-index: 5;
  pointer-events: none;
}

/* ---------------------------- КЛАПАН ------------------------------------ */
.env-flap {
  position: absolute;
  left: 0; top: -1px;
  width: 100%;
  height: 51%;
  -webkit-transform-origin: 50% 0%;
  transform-origin: 50% 0%;
  -webkit-transform-style: preserve-3d;
  transform-style: preserve-3d;
  transform: translateZ(10px) rotateX(0deg);
  z-index: 7;
  pointer-events: none;
}

.flap-face {
  position: absolute; inset: 0;
  -webkit-clip-path: polygon(0 0, 100% 0, 50% 100%);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  background-color: var(--env-outer);
  background-image:
    linear-gradient(180deg, rgba(255,255,255,.22), rgba(0,0,0,.03) 60%, rgba(0,0,0,.14)),
    var(--noise-soft);
  background-size: cover, 180px 180px;
  background-blend-mode: normal, soft-light;
}
.flap-face::before {
  content: '';
  position: absolute; inset: 0;
  -webkit-clip-path: polygon(0 0, 100% 0, 50% 100%);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  background: linear-gradient(180deg, rgba(255,255,255,.5), transparent 42%);
  opacity: calc(var(--flap-bright) - 1);
  mix-blend-mode: screen;
  pointer-events: none;
}
.flap-edge {
  position: absolute; left: 0; top: 0; width: 100%; height: 100%;
  -webkit-clip-path: polygon(0 0, 100% 0, 50% 100%);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  background: linear-gradient(180deg, var(--env-edge), rgba(205,186,152,0) 6%);
  transform: translateZ(-0.5px);
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}
/* внутрішня (зворотна) сторона */
.flap-inner {
  position: absolute; inset: 0;
  -webkit-clip-path: polygon(0 0, 100% 0, 50% 100%);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  -webkit-transform: rotateY(180deg) translateZ(0.5px);
  transform: rotateY(180deg) translateZ(0.5px);
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  background-color: var(--env-inner);
  background-image:
    linear-gradient(180deg, rgba(0,0,0,.12), rgba(255,255,255,.15)),
    var(--noise-soft);
  background-size: cover, 220px 220px;
  background-blend-mode: normal, soft-light;
  box-shadow: inset 0 0 26px rgba(120,84,54,.18);
}

/* ---------------------------- ПЕЧАТКА ----------------------------------- */
.env-seal {
  position: absolute;
  left: 50%;
  top: 47%;
  width: 32%;
  aspect-ratio: 1 / 1;
  transform: translate(-50%, -50%) translateZ(12px);
  border: 0;
  padding: 0;
  background: transparent;
  cursor: pointer;
  z-index: 8;
  pointer-events: auto;
  -webkit-tap-highlight-color: transparent;
}
.env-seal svg { width: 100%; height: 100%; display: block; overflow: visible; }
.seal-wax {
  transform-box: fill-box;
  transform-origin: center;
  filter: drop-shadow(0 3px 4px rgba(40,10,18,.45));
}
/* ambient «дихання» печатки */
.env-stage:not(.is-opening) .seal-wax { animation: env-breath 2.5s ease-in-out infinite; }
@keyframes env-breath { 0%,100% { transform: scale(1); } 50% { transform: scale(1.03); } }
/* слабкий відблиск по краю сургучу */
.seal-shine { opacity: var(--seal-shine); mix-blend-mode: screen; }
.env-seal:focus-visible {
  outline: 2px solid rgba(246,241,234,.9);
  outline-offset: 6px;
  border-radius: 50%;
}
.env-seal.is-broken { opacity: 0; pointer-events: none; }

/* осколки й крихти сургучу (рухаються незалежно від клапана) */
.seal-shards { position: absolute; left: 0; top: 0; width: 100%; height: 100%; z-index: 9; pointer-events: none; }
.seal-shards svg { position: absolute; left: 50%; top: 47%; width: 33%; aspect-ratio:1/1; transform: translate(-50%,-50%); overflow: visible; opacity: 0; }
.shard, .crumb { transform-box: fill-box; transform-origin: center; }

/* ------------------------------ ПІДКАЗКА -------------------------------- */
.env-hint {
  position: absolute;
  left: 50%;
  top: 108%;                               /* одразу під конвертом */
  transform: translate(-50%, 10px);
  white-space: nowrap;
  text-align: center;
  font-family: 'Montserrat', sans-serif; font-weight: 300;
  font-size: 11px; letter-spacing: .28em; text-transform: uppercase;
  color: var(--text-secondary);
  opacity: 0;
  transition: opacity .8s ease, transform .8s ease;
  pointer-events: none;
}
.env-hint.is-shown { opacity: 1; transform: translate(-50%, 0); }

/* -------------------------- КНОПКА ЗВУКУ -------------------------------- */
.env-sound {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  right: 14px;
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--text-secondary);
  border-radius: 50%;
  background: rgba(0,0,0,.15);
  color: var(--text-secondary);
  cursor: pointer;
  z-index: 12;
  pointer-events: auto;
  transition: color .3s ease, border-color .3s ease;
}
.env-sound:hover { color: #fff; border-color: #fff; }
.env-sound:focus-visible { outline: 2px solid #fff; outline-offset: 3px; }
.env-sound .icon-off { display: none; }
.env-sound.is-muted .icon-on  { display: none; }
.env-sound.is-muted .icon-off { display: block; }

/* -------------------- View Transitions: морф у hero -------------------- */
::view-transition-old(env-hero),
::view-transition-new(env-hero) {
  animation-duration: .62s;
  animation-timing-function: cubic-bezier(.4,0,.2,1);
  mix-blend-mode: normal;
}

/* -------------------- МАЛЕНЬКІ ТОНЕНЬКІ СЯЮЧІ ЗІРОЧКИ -------------------- */
.sparkle-particle {
  position: absolute;
  pointer-events: none;
  z-index: 15;
  mix-blend-mode: screen;
  will-change: transform, opacity;
  transform-origin: center center;
  animation: fairySmoothFloat var(--dur, 1.6s) cubic-bezier(0.16, 1, 0.3, 1) forwards;
}
.sparkle-particle.star-gold {
  fill: #FFF6CC;
  filter: drop-shadow(0 0 4px #FFE082) drop-shadow(0 0 10px rgba(203, 187, 121, 0.9));
}
.sparkle-particle.star-white {
  fill: #FFFFFF;
  filter: drop-shadow(0 0 5px #FFFFFF) drop-shadow(0 0 12px rgba(255, 240, 200, 0.95));
}
.sparkle-particle.star-champagne {
  fill: #F8ECC2;
  filter: drop-shadow(0 0 5px #E8C86A) drop-shadow(0 0 10px rgba(184, 123, 109, 0.75));
}
.sparkle-particle.dot-micro {
  border-radius: 50%;
  background: #FFFFFF;
  box-shadow: 0 0 6px #FFFFFF, 0 0 12px #FFE082;
}

@keyframes fairySmoothFloat {
  0% {
    opacity: 0;
    transform: translate(0, 0) scale(0.15) rotate(0deg);
  }
  22% {
    opacity: 1;
    transform: translate(calc(var(--dx) * 0.35), calc(var(--dy) * 0.35)) scale(var(--scale-max, 1.15)) rotate(calc(var(--rot) * 0.35));
  }
  70% {
    opacity: 0.85;
    transform: translate(calc(var(--dx) * 0.82), calc(var(--dy) * 0.82)) scale(calc(var(--scale-max, 1.15) * 0.9)) rotate(calc(var(--rot) * 0.82));
  }
  100% {
    opacity: 0;
    transform: translate(var(--dx), var(--dy)) scale(0.1) rotate(var(--rot));
  }
}

/* ------------------------- reduced-motion ------------------------------ */
@media (prefers-reduced-motion: reduce) {
  .env-stage:not(.is-opening) .seal-wax { animation: none; }
  .env-hint { transition: none; }
}
