/* Авалон — 3D-шар і музика. Підключається після style.css. */

/* ── 1. Сцена з глибиною: фото нахиляється за пальцем/мишею ── */
#stage { position: fixed; inset: 0; z-index: 0; overflow: hidden; background: var(--bg); }
#scene { position: absolute; inset: 0; transform-origin: 50% 50%; will-change: transform; transform: scale(1.075); }
#door {
  position: absolute; inset: 0; width: 100%; height: 100%; z-index: 10;
  visibility: hidden; pointer-events: none; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  box-shadow: 0 0 80px rgba(0,0,0,.8);
}

/* ── 4. Сніг, 6. спалахи, 5. ластівка ── */
#snow { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 12; pointer-events: none; }
#flare { position: fixed; inset: 0; z-index: 12; pointer-events: none; opacity: 0; mix-blend-mode: screen; }
#swallow {
  position: fixed; left: -60px; top: -34px; width: 120px; height: 68px; z-index: 14;
  display: none; pointer-events: none; will-change: transform, opacity; overflow: visible;
}
#swallow .wing { transform-box: fill-box; animation: flap .32s ease-in-out infinite alternate; }
#swallow .wing.u { transform-origin: 85% 100%; }
#swallow .wing.d { transform-origin: 85% 0%; }
@keyframes flap { from { transform: scaleY(1); } to { transform: scaleY(-.55); } }

/* ── 1. Лого — золота монета, що повертається ── */
.logo { perspective: 600px; }
.logo img { position: absolute; width: 1px !important; height: 1px !important; opacity: 0; pointer-events: none; }
.coin {
  display: block; position: relative;
  height: var(--logo-h); aspect-ratio: 720 / 476; max-width: 34vw;
  transform-style: preserve-3d; animation: coin 14s cubic-bezier(.65,0,.3,1) infinite;
  filter: drop-shadow(0 2px 10px rgba(0,0,0,.55));
}
.coin .face {
  position: absolute; inset: 0;
  -webkit-mask: url(../media/logo.png) center / contain no-repeat; mask: url(../media/logo.png) center / contain no-repeat;
  background: linear-gradient(105deg, #a9844c 0%, #e9cf96 22%, #c9a96e 38%, #fff4d6 48%, #c9a96e 58%, #8f6d3a 76%, #e9cf96 100%);
  background-size: 260% 100%; animation: sheen 6s linear infinite;
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
}
.coin .face.back { transform: rotateY(180deg); }
@keyframes coin { 0%, 80% { transform: rotateY(0deg); } 100% { transform: rotateY(360deg); } }
@keyframes sheen { from { background-position: 100% 0; } to { background-position: -160% 0; } }
@media (max-width: 640px) { .coin { max-width: 40vw; } }

/* ── 9. Кнопка-дзвіночок (музика) ── */
.top { gap: 10px; }
.bell {
  pointer-events: auto; position: relative;
  width: var(--tg-h); height: var(--tg-h); border-radius: 50%;
  display: grid; place-items: center;
  border: 1px solid rgba(201,169,110,.45); background: rgba(0,0,0,.4);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  color: #e3c98f; transition: border-color .3s, box-shadow .5s, background .4s;
}
.bell svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; transform-origin: 50% 12%; overflow: visible; }
.bell .fill { fill: currentColor; opacity: 0; transition: opacity .4s; }
.bell:not(.on) svg { animation: nudge 4.5s ease-in-out infinite; }
.bell.on { border-color: rgba(201,169,110,.8); background: rgba(201,169,110,.16); box-shadow: 0 0 22px rgba(201,169,110,.4); }
.bell.on .fill { opacity: .35; }
.bell .waves { opacity: 0; transition: opacity .4s; }
.bell.on .waves { opacity: 1; }
.bell:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
@media (hover: hover) { .bell:hover { border-color: var(--accent); } }
.bell:active { transform: scale(.92); }
@keyframes nudge { 0%, 70%, 100% { transform: rotate(0deg); } 76% { transform: rotate(14deg); } 84% { transform: rotate(-10deg); } 92% { transform: rotate(5deg); } }

/* ── 3. Літери заголовків вилітають з глибини ── */
.slide h2 .w { display: inline-block; white-space: nowrap; perspective: 600px; }
.slide h2 .ch {
  display: inline-block; transform-origin: 50% 80%;
  opacity: 0; transform: translate3d(0, .35em, -380px) rotateX(-72deg);
  transition: opacity .25s, transform .3s;
}
body.ready .slide.on h2 .ch {
  opacity: 1; transform: none;
  transition: opacity .6s calc(var(--k) * 38ms + .12s), transform 1.05s cubic-bezier(.16,1.12,.3,1) calc(var(--k) * 38ms + .12s);
}

/* ── 8. Вікно менеджера відкривається 3D-переворотом ── */
.sheet-card {
  transform-origin: 50% 100%;
  transform: perspective(1200px) rotateX(-74deg) translateY(30px) scale(.96);
  opacity: 0;
  transition: transform .85s cubic-bezier(.16,1.1,.3,1), opacity .35s;
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
}
.sheet.open .sheet-card { transform: none; opacity: 1; }
@media (min-width: 641px) {
  .sheet-card { transform-origin: 50% 50%; transform: perspective(1200px) rotateY(-100deg) scale(.9); }
  .sheet.open .sheet-card { transform: none; }
}

/* ── 7. Галерея — 3D-карусель ── */
.gal-stage { perspective: 1500px; }
.gal-track { position: relative; display: block; height: 100%; transform: none !important; transform-style: preserve-3d; transition: none; }
.gal-slide {
  position: absolute; top: 0; bottom: 0; left: 14%; right: 14%; height: auto;
  display: flex; align-items: center; justify-content: center;
  transition: transform .75s cubic-bezier(.2,.9,.25,1), opacity .5s;
  cursor: pointer; will-change: transform;
}
.gal-slide.cur { cursor: default; }
.gal-slide img { left: 0; width: 100%; transition: filter .5s; }
.gal-slide:not(.cur) img { filter: brightness(.5); }
.gal-nav { z-index: 20; }
@media (max-width: 640px) {
  .gal-slide { left: 8%; right: 8%; }
  .gal-slide img { left: 0; width: 100%; }
}

/* ── Повага до налаштування «менше руху»: лише прозорість ── */
@media (prefers-reduced-motion: reduce) {
  #scene { transform: none !important; }
  .coin, .coin .face, .bell svg, #swallow .wing { animation: none !important; }
  .slide h2 .ch { transform: none !important; }
  .sheet-card, .sheet.open .sheet-card { transform: none !important; }
  .gal-slide { transform: none !important; }
  .gal-slide:not(.cur) { opacity: 0 !important; }
  #snow, #flare, #swallow { display: none !important; }
}
