/* MEDVID WEB Christmas Card — вступний конверт, сяйво й відео (з Прототип_3_Glow без змін) */
/* =========================================================
   MEDVID WEB · Прототип 2 · вступний конверт
   Без бібліотек, без зовнішніх ресурсів. Текстура паперу
   генерується в canvas один раз при завантаженні.
   ========================================================= */
:root{
  --env-w: min(82vw, 46vh, 420px);
  --env-h: calc(var(--env-w) * 1.38);
  --flap-h: calc(var(--env-h) * .5507);      /* 76 / 138 */
  --seal: calc(var(--env-w) * .22);
  --rest-y: .03;      /* зсув закритого конверта (частка висоти) — читає JS */
  --settle-y: .14;    /* «камера» після відкриття */
  --settle-s: .72;
  --paper: none;      /* підставляє JS */
  --ink: #efe3c8;
  --bg0: #050a17; --bg1: #0c1730; --bg2: #16264a;
}
@supports (height: 100dvh){ :root{ --env-w: min(82vw, 46dvh, 420px); } }
@media (max-height: 700px){ :root{ --settle-y: .16; --settle-s: .68; } }

*{ box-sizing: border-box; margin: 0; padding: 0; }
html, body{ height: 100%; background: var(--bg0); }
body{
  overflow: hidden; color: var(--ink);
  font-family: "Cormorant Garamond", Georgia, "Times New Roman", serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}
.stage{
  position: fixed; inset: 0; height: 100vh; overflow: hidden;
  background:
    radial-gradient(120% 70% at 50% 38%, var(--bg2) 0%, var(--bg1) 42%, var(--bg0) 100%);
  touch-action: manipulation;
}
@supports (height: 100dvh){ .stage{ height: 100dvh; } }
/* дрібне зерно проти «смуг» у темному градієнті */
.stage::before{
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background-image: var(--paper); background-size: 160px 160px;
  opacity: .05; mix-blend-mode: overlay;
}

.brand{
  position: absolute; left: 0; right: 0; text-align: center;
  top: calc(env(safe-area-inset-top) + 22px);
  font-size: 13px; letter-spacing: .42em; padding-left: .42em;
  color: rgba(236,222,192,.55); font-weight: 400; z-index: 5;
}

/* ---------- «риг» = конверт + його тіні; рухається як камера ---------- */
.fade-wrap{ position: absolute; inset: 0; }
.rig{
  position: absolute; left: 50%; top: 50%;
  width: var(--env-w); height: var(--env-h);
  margin-left: calc(var(--env-w) / -2); margin-top: calc(var(--env-h) / -2);
  transform: translateY(calc(var(--env-h) * .03));
  will-change: transform;
}
.ambient{
  position: absolute; inset: 0; border-radius: 1px;
  box-shadow:
    0 calc(var(--env-w)*.07) calc(var(--env-w)*.16) calc(var(--env-w)*-.03) rgba(0,2,10,.62),
    0 calc(var(--env-w)*.012) calc(var(--env-w)*.03) rgba(0,2,10,.38);
}
.contact{
  position: absolute; left: 3%; right: 3%; bottom: -2.2%; height: 5%;
  background: radial-gradient(50% 50% at 50% 40%, rgba(0,0,6,.55), rgba(0,0,6,0) 72%);
}
.spill{
  position: absolute; left: -45%; right: -45%; top: -78%; height: 115%;
  background: radial-gradient(42% 44% at 50% 64%,
     rgba(255,198,124,.30) 0%, rgba(255,182,104,.11) 42%, rgba(255,170,90,0) 72%);
  opacity: 0; pointer-events: none;
}

.envelope{
  position: absolute; inset: 0;
  perspective: calc(var(--env-w) * 3.4);
  perspective-origin: 50% 20%;
}
.layer{ position: absolute; inset: 0; width: 100%; height: 100%; display: block; overflow: visible; }
.in-glow{
  position: absolute; inset: 0; opacity: 0; pointer-events: none;
  background:
    radial-gradient(58% 34% at 50% 20%, rgba(255,214,150,.92) 0%, rgba(255,186,108,.45) 42%, rgba(255,170,90,0) 74%),
    radial-gradient(90% 40% at 50% 0%, rgba(255,196,120,.35), rgba(255,196,120,0) 70%);
}
.seam{ opacity: 0; pointer-events: none; }

/* ---------- клапан ---------- */
.flap-shadow, .flap{
  position: absolute; left: 0; top: 0; width: 100%; height: var(--flap-h);
  transform-origin: 50% 0%; pointer-events: none;
}
.flap-shadow svg{ width: 100%; height: 100%; display: block; overflow: visible; }
.flap{ transform-style: preserve-3d; will-change: transform; }
.face{
  position: absolute; inset: 0;
  -webkit-backface-visibility: hidden; backface-visibility: hidden;
}
.face .shade, .face .glow{ position: absolute; inset: 0; opacity: 0; }
.face svg{ position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.face.outer{
  -webkit-clip-path: url(#clipOuter); clip-path: url(#clipOuter);
  background-image:
    var(--paper),
    linear-gradient(118deg, rgba(255,255,250,.30) 0%, rgba(255,255,250,0) 48%),
    linear-gradient(180deg, #dccdaf 0%, #ece1ca 4%, #f3ebda 30%, #f0e6d2 70%, #e8dbc2 100%);
  background-size: 128px 128px, 100% 100%, 100% 100%;
}
.face.outer .shade{ background: linear-gradient(180deg, rgba(38,28,20,.95), rgba(52,38,26,.85)); }
.face.inner{
  transform: rotateX(180deg);
  -webkit-clip-path: url(#clipInner); clip-path: url(#clipInner);
  background-image:
    var(--paper),
    linear-gradient(0deg, #e0cfae 0%, #e8dbc0 40%, #e3d4b8 100%);
  background-size: 128px 128px, 100% 100%;
}
.face.inner .glow{
  background:
    radial-gradient(95% 90% at 50% 100%, rgba(255,208,142,.80) 0%, rgba(255,196,122,.38) 45%, rgba(255,186,108,.08) 80%, rgba(255,180,100,0) 100%);
}
.face.inner .shade{ background: rgba(34,24,16,1); }

/* ---------- печатка ---------- */
.seal-wrap{
  position: absolute; left: 50%; top: calc(var(--flap-h) * .845);
  width: var(--seal); height: var(--seal);
  transform: translate(-50%, -50%); z-index: 3;
}
.seal-glow{
  position: absolute; inset: -55%; border-radius: 50%; pointer-events: none; opacity: 0;
  background: radial-gradient(circle, rgba(255,206,128,.55) 0%, rgba(240,176,92,.18) 34%, rgba(230,160,80,0) 62%);
}
.seal-btn{
  position: absolute; inset: -18%;               /* збільшена зона дотику */
  border: 0; background: none; cursor: pointer; padding: 18%;
  border-radius: 50%; outline: none; color: inherit;
}
.seal-btn:focus-visible .seal{ box-shadow: 0 0 0 2px rgba(236,214,170,.7); border-radius: 50%; }
.seal{ position: relative; display: block; width: 100%; height: 100%; }
.seal svg{ position: absolute; inset: -8%; width: 116%; height: 116%; overflow: visible; }
.sheen, .gold{ position: absolute; inset: 9%; border-radius: 50%; overflow: hidden; pointer-events: none; }
.sheen .band{
  position: absolute; top: -25%; bottom: -25%; left: 15%; width: 70%;
  background: linear-gradient(100deg, rgba(255,226,170,0) 20%, rgba(255,230,180,.55) 50%, rgba(255,226,170,0) 80%);
  transform: translateX(-180%);
}
.gold{
  opacity: 0;
  background: radial-gradient(circle at 42% 36%, rgba(255,226,168,.95) 0%, rgba(232,180,98,.80) 45%, rgba(196,136,62,.55) 70%, rgba(170,110,50,.0) 80%);
}
/* легкий «відблиск» як підказка — раз на кілька секунд */
.stage:not(.is-active) .sheen .band{ animation: idleSheen 6.5s 1.6s ease-in-out infinite; }
@keyframes idleSheen{
  0%, 72%{ transform: translateX(-180%); opacity: 0; }
  76%{ opacity: .45; }
  92%{ transform: translateX(180%); opacity: .45; }
  100%{ transform: translateX(180%); opacity: 0; }
}

/* ---------- інтерфейс ---------- */
.veil{
  position: absolute; inset: 0; pointer-events: none; opacity: 0;
  background: radial-gradient(70% 48% at 50% 40%, rgba(255,188,112,.15), rgba(255,188,112,0) 72%);
}
.hint, .cta{
  position: absolute; left: 50%; transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom) + max(7vh, 56px)); z-index: 6;
}
.hint{
  width: 90%; text-align: center; font-size: 16px; letter-spacing: .04em;
  color: rgba(236,222,192,.78); font-style: italic; pointer-events: none;
  animation: breathe 3.6s ease-in-out infinite;
}
@keyframes breathe{ 0%,100%{ opacity: .55; } 50%{ opacity: .9; } }
.is-active .hint{ animation: none; }
.cta{
  font: inherit; font-size: 18px; letter-spacing: .06em; color: #f3e8d0;
  padding: 14px 30px; border-radius: 999px; white-space: nowrap;
  border: 1px solid rgba(236,212,166,.55);
  background: linear-gradient(180deg, rgba(40,46,70,.55), rgba(18,24,44,.65));
  box-shadow: 0 8px 26px rgba(0,0,0,.35), inset 0 1px 0 rgba(255,240,210,.12);
  opacity: 0; visibility: hidden; transform: translate(-50%, 10px);
  transition: opacity .9s ease, transform .9s cubic-bezier(.2,.7,.2,1), visibility 0s .9s;
  cursor: pointer;
}
.cta.show{ opacity: 1; visibility: visible; transform: translate(-50%, 0); transition-delay: 0s; }
.cta:focus-visible{ outline: 2px solid rgba(236,212,166,.8); outline-offset: 3px; }
.note{
  position: absolute; left: 50%; transform: translateX(-50%); width: 88%; text-align: center;
  bottom: calc(env(safe-area-inset-bottom) + max(7vh, 56px) - 30px); font-size: 13px;
  color: rgba(236,222,192,.7); opacity: 0; transition: opacity .5s; pointer-events: none; z-index: 6;
}
.note.show{ opacity: 1; }
.replay{
  position: absolute; left: calc(env(safe-area-inset-left) + 12px);
  bottom: calc(env(safe-area-inset-bottom) + 10px); z-index: 7;
  font: 12px/1 system-ui, sans-serif; color: rgba(220,210,190,.55);
  background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.12);
  border-radius: 8px; padding: 7px 10px; cursor: pointer;
}
@media (max-height: 700px){
  .hint, .cta{ bottom: calc(env(safe-area-inset-bottom) + 22px); }
  .note{ bottom: calc(env(safe-area-inset-bottom) + 4px); }
  .replay{ bottom: auto; left: auto; right: calc(env(safe-area-inset-right) + 10px); top: calc(env(safe-area-inset-top) + 14px); }
}

@media (prefers-reduced-motion: reduce){
  .hint{ animation: none; opacity: .85; }
  .stage:not(.is-active) .sheen .band{ animation: none; }
  .cta{ transition: opacity .4s ease, visibility 0s .4s; transform: translate(-50%, 0); }
}

/* =========================================================
   Прототип 3 · перехід «світло → V-01 → монтаж»
   ========================================================= */
.film{ position: fixed; inset: 0; background: #0a1226; z-index: 0; }
.film video{
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; object-position: 50% 50%;
  opacity: 0; background: transparent;
}
.film video.on{ opacity: 1; }
.stage{ z-index: 1; }
.stage.gone{ visibility: hidden; }
.stage .cta, .stage .note, .stage .replay{ display: none !important; }

.lt{ position: fixed; z-index: 20; pointer-events: none; opacity: 0; will-change: opacity, transform; }
.lt-fill{
  inset: 0;
  background: radial-gradient(130% 95% at var(--lx,50%) var(--ly,40%),
    #ffd98f 0%, #f6b95a 32%, #d98f37 70%, #b86f26 100%);
}
.lt-halo{
  inset: 0; transform-origin: var(--lx,50%) var(--ly,40%);
  background: radial-gradient(circle at var(--lx,50%) var(--ly,40%),
    rgba(255,200,104,.95) 0%, rgba(248,172,70,.62) 18%, rgba(232,146,48,.26) 38%, rgba(220,130,40,0) 62%);
}
.lt-core{
  inset: 0; transform-origin: var(--lx,50%) var(--ly,40%);
  background: radial-gradient(circle at var(--lx,50%) var(--ly,40%),
    rgba(255,236,190,1) 0%, rgba(255,218,140,.85) 7%, rgba(255,196,100,.35) 16%, rgba(255,186,90,0) 30%);
}
.lt-rays{
  left: -50%; top: -50%; width: 200%; height: 200%;
  transform-origin: var(--rx,50%) var(--ry,50%);
  background: repeating-conic-gradient(from 4deg at var(--rx,50%) var(--ry,50%),
    rgba(255,208,128,0) 0deg, rgba(255,208,128,.20) 5deg, rgba(255,208,128,0) 11deg, rgba(255,208,128,0) 17deg);
  -webkit-mask-image: radial-gradient(circle at var(--rx,50%) var(--ry,50%), #000 0%, rgba(0,0,0,.55) 12%, rgba(0,0,0,0) 30%);
          mask-image: radial-gradient(circle at var(--rx,50%) var(--ry,50%), #000 0%, rgba(0,0,0,.55) 12%, rgba(0,0,0,0) 30%);
}

.t-ui{ position: fixed; z-index: 30; left: 50%; transform: translateX(-50%); }
.t-loading{
  bottom: calc(env(safe-area-inset-bottom) + 12vh); font-style: italic; font-size: 15px; letter-spacing: .03em;
  color: rgba(246,226,186,.85); opacity: 0; transition: opacity .8s; pointer-events: none; white-space: nowrap;
  text-shadow: 0 1px 8px rgba(0,0,0,.35);
}
.t-loading.show{ opacity: 1; }
.t-play{
  bottom: calc(env(safe-area-inset-bottom) + 12vh);
  font: inherit; font-size: 18px; letter-spacing: .05em; color: #f6e8cc;
  padding: 14px 30px; border-radius: 999px; border: 1px solid rgba(240,210,150,.6);
  background: rgba(30,24,30,.45); cursor: pointer; display: none; white-space: nowrap;
}
.t-play.show{ display: block; }
.t-replay{
  left: auto; transform: none; right: calc(env(safe-area-inset-right) + 10px);
  top: calc(env(safe-area-inset-top) + 12px); z-index: 40;
  font: 12px/1 system-ui, sans-serif; color: rgba(235,228,214,.8);
  background: rgba(10,16,32,.35); border: 1px solid rgba(255,255,255,.18);
  border-radius: 8px; padding: 7px 10px; cursor: pointer;
}
.t-debug{
  left: 8px; transform: none; top: calc(env(safe-area-inset-top) + 48px); z-index: 40;
  font: 11px/1.45 ui-monospace, Menlo, monospace; color: #e9f1ff; white-space: pre;
  background: rgba(0,0,0,.55); padding: 8px 10px; border-radius: 8px; display: none; pointer-events: none;
}
.t-debug.show{ display: block; }
