:root {
  --cream: #FEE3A9;
  --sky:   #ADC5FB;
  --white: #FFFFFF;
  --gold:  #E5BD67;
  --ink:   #4a3410;          /* темний теплий колір тексту, щоб добре читався на світлому тлі */
  --flip:  1300ms;           /* перезаписується з js/slides.js */
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--cream);
}

body {
  font-family: 'Marck Script', 'Segoe Script', 'Bradley Hand', 'Brush Script MT', cursive;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
}
body.idle { cursor: none; }
img { -webkit-user-drag: none; }

/* ------------------------------------------------------------------ книга */

#book {
  position: fixed;
  inset: 0;
  overflow: hidden;
  perspective: max(4800px, 250vw);   /* чим більше значення, тим "плоскіше" перегортання */
  perspective-origin: 50% 50%;
  background: var(--cream);
}
#book.no-anim .page { transition: none !important; }

.page {
  position: absolute;
  inset: 0;
  transform-origin: 0 50%;          /* "корінець" зліва */
  transform-style: preserve-3d;
  transition: transform var(--flip) cubic-bezier(.5, .05, .25, 1);
}
.page:not(.hide) { will-change: transform; }
.page.flipped    { transform: rotateY(-180deg); }
.page.hide       { visibility: hidden; }

.face {
  position: absolute;
  inset: 0;
  overflow: hidden;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

/* зворотний бік аркуша, який видно під час перегортання */
.back {
  transform: rotateY(180deg);
  background: linear-gradient(90deg, #f3d891 0%, #fbe5ae 35%, #fff1cc 100%);
}
.back::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(270deg, rgba(70, 45, 0, .55), rgba(70, 45, 0, 0) 75%);
  opacity: 1;
  transition: opacity var(--flip) ease-out;
}
.page.flipped .back::after { opacity: 0; }

/* затемнення лицьового боку, коли аркуш відвертається */
.shade, .under-shade, .edge {
  position: absolute;
  z-index: 10;
  pointer-events: none;
}
.shade {
  inset: 0;
  background: linear-gradient(90deg, rgba(70, 45, 0, 0), rgba(70, 45, 0, .55));
  opacity: 0;
  transition: opacity var(--flip) ease-in;
}
.page.flipped .shade { opacity: 1; }

/* тінь від аркуша, що відлітає, на сторінці під ним */
.under-shade {
  inset: 0;
  background: linear-gradient(90deg, rgba(40, 25, 0, .55), rgba(40, 25, 0, .12) 70%, rgba(40, 25, 0, 0));
  opacity: 0;
}
.page.reveal .under-shade { animation: underShade var(--flip) ease-out both; }
@keyframes underShade { from { opacity: 1; } to { opacity: 0; } }

/* легка тінь біля корінця */
.edge {
  left: 0; top: 0; bottom: 0;
  width: min(4vw, 70px);
  background: linear-gradient(90deg, rgba(120, 85, 10, .22), rgba(120, 85, 10, 0));
}
.intro .edge { display: none; }

/* ------------------------------------------------------------- вступ */

.front.intro { background: #002535; }   /* перезаписується з slide.background */
.intro-img {
  position: absolute;
  max-width: none;                 /* розмір і положення виставляє layoutIntro() у js/app.js */
}
.intro-img.cover {
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;               /* розтягнуто на все вікно без спотворень */
}

/* ----------------------------------------------------------- звичайні слайди */

.front:not(.intro) {
  background:
    radial-gradient(900px 600px at 12% 8%, rgba(255, 255, 255, .9), rgba(255, 255, 255, 0) 70%),
    linear-gradient(var(--ang, 135deg), var(--cream) 0%, #fff6dc 48%, var(--sky) 135%);
}
.front:not(.intro)::before {          /* тонка золота рамка сторінки */
  content: '';
  position: absolute;
  inset: 1.5vmin;
  border: 1.5px solid rgba(229, 189, 103, .75);
  border-radius: 1.4vmin;
  pointer-events: none;
}

.bokeh {
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
  background: radial-gradient(circle at 35% 35%, rgba(255, 255, 255, .95), rgba(255, 255, 255, 0) 70%);
  animation: drift var(--t, 12s) ease-in-out infinite alternate;
}
.bokeh.gold { background: radial-gradient(circle at 35% 35%, rgba(229, 189, 103, .55), rgba(229, 189, 103, 0) 70%); }
.bokeh.blue { background: radial-gradient(circle at 35% 35%, rgba(173, 197, 251, .70), rgba(173, 197, 251, 0) 70%); }
@keyframes drift {
  from { transform: translate3d(0, 0, 0) scale(1); }
  to   { transform: translate3d(1.6vw, -2.6vh, 0) scale(1.08); }
}

.content {
  --pad: 40px;
  --gap: 24px;
  --b: 10px;
  --cap: 48px;
  position: absolute;
  z-index: 2;
  inset: var(--pad);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3.2vh;
}
.content.layout-side            { flex-direction: row; gap: 3.5vw; }
.content.layout-side.side-right { flex-direction: row-reverse; }

.photos {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--gap);
  flex: 0 0 auto;
}

/* ------------------------------------------------------------------ фото */

.photo {
  position: relative;
  flex: 0 0 auto;
  width: var(--w, 300px);
  height: var(--h, 400px);
  margin: 0;
  border: var(--b) solid #fff;
  border-radius: 6px;
  background: #fff;
  overflow: hidden;
  box-shadow: 0 18px 40px rgba(94, 64, 8, .30), 0 3px 8px rgba(94, 64, 8, .18);
  opacity: 0;
  rotate: var(--tilt, 0deg);
  translate: 0 var(--dy, 0px);
}
.photo img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.photo.shown { opacity: 1; }
.photo.inline { margin: 0 .1em; }

/* ефекти появи */
.photo[class*="fx-"] {
  animation-duration: 1.4s;
  animation-fill-mode: both;
  animation-timing-function: cubic-bezier(.2, .75, .2, 1);
}
.fx-fade  { animation-name: fxFade; animation-duration: 1.8s !important; animation-timing-function: ease !important; }
.fx-blink { animation-name: fxBlink; animation-duration: 1.5s !important; animation-timing-function: linear !important; }
.fx-ltr   { animation-name: fxWipe; animation-duration: 1.5s !important; animation-timing-function: cubic-bezier(.6, .1, .2, 1) !important; }
.fx-rtl   { animation-name: fxFromRight; }
.fx-slide { animation-name: fxFromLeft; }
.fx-zoom  { animation-name: fxZoom;  animation-duration: 1.2s !important; }
.fx-drop  { animation-name: fxDrop;  animation-duration: 1.5s !important; animation-timing-function: ease-in !important; }
.fx-blur  { animation-name: fxBlur;  animation-duration: 1.8s !important; }
.fx-flip  { animation-name: fxFlip;  animation-duration: 1.3s !important; }
.fx-up    { animation-name: fxUp; }

@keyframes fxFade { from { opacity: 0; } to { opacity: 1; } }

@keyframes fxBlink {
  0%   { opacity: 0; }
  7%   { opacity: 1; filter: brightness(2.8) saturate(.3); }
  15%  { opacity: 0; }
  26%  { opacity: 1; filter: brightness(2.1) saturate(.5); }
  36%  { opacity: .1; }
  48%  { opacity: 1; filter: brightness(1.6); }
  58%  { opacity: .35; }
  72%  { opacity: 1; filter: brightness(1.2); }
  100% { opacity: 1; filter: none; }
}

@keyframes fxWipe {
  from { opacity: 1; clip-path: inset(-100px 100% -100px -100px); transform: translateX(-3vw); }
  to   { opacity: 1; clip-path: inset(-100px -100px -100px -100px); transform: none; }
}
@keyframes fxFromRight { from { opacity: 0; transform: translateX(22vw); } to { opacity: 1; transform: none; } }
@keyframes fxFromLeft  { from { opacity: 0; transform: translateX(-22vw); } to { opacity: 1; transform: none; } }

@keyframes fxZoom {
  0%   { opacity: 0; transform: scale(.45); }
  60%  { opacity: 1; transform: scale(1.07); }
  100% { opacity: 1; transform: scale(1); }
}

@keyframes fxDrop {
  0%   { opacity: 0; transform: translateY(-95vh); rotate: -16deg; }
  10%  { opacity: 1; }
  62%  { opacity: 1; transform: translateY(1.5vh); rotate: var(--tilt, 0deg); }
  80%  { transform: translateY(-1.2vh); }
  100% { opacity: 1; transform: none; rotate: var(--tilt, 0deg); }
}

@keyframes fxBlur {
  from { opacity: 0; filter: blur(28px); transform: scale(1.12); }
  to   { opacity: 1; filter: none;       transform: none; }
}

@keyframes fxFlip {
  from { opacity: 0; transform: perspective(1000px) rotateY(-85deg); }
  to   { opacity: 1; transform: perspective(1000px) rotateY(0); }
}

@keyframes fxUp { from { opacity: 0; transform: translateY(9vh); } to { opacity: 1; transform: none; } }

/* ------------------------------------------------------------------ текст */

.textbox {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .35em;
  font-size: var(--cap);
  flex: 0 0 auto;
  max-width: 100%;
}
.layout-side .textbox { flex: 1 1 0; min-width: 0; }

.caption {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  column-gap: .26em;
  row-gap: .04em;
  margin: 0;
  line-height: 1.2;
  text-align: center;
  text-shadow: 0 1px 0 rgba(255, 255, 255, .85);
  max-width: min(100%, 1500px);
}
.word { display: inline-block; white-space: nowrap; }
.ch   { opacity: 0; }
.ch.on { opacity: 1; }

/* курсор друку */
.caret {
  display: inline-block;
  position: relative;
  width: 0;
  height: 0;                 /* не впливає на висоту рядка */
}
.caret::after {
  content: '';
  position: absolute;
  left: .05em;
  bottom: -.12em;
  width: .055em;
  height: 1.05em;
  border-radius: 2px;
  background: var(--gold);
  box-shadow: 0 0 .25em rgba(229, 189, 103, .8);
  animation: caretBlink .8s steps(1) infinite;
}
@keyframes caretBlink { 50% { opacity: 0; } }
.caption.done .caret { display: none; }

/* золота риска під текстом */
.flourish {
  display: block;
  width: 0;
  height: 3px;
  border-radius: 3px;
  background: linear-gradient(90deg, rgba(229, 189, 103, 0), var(--gold), rgba(229, 189, 103, 0));
  transition: width 1.2s cubic-bezier(.2, .7, .2, 1);
}
.flourish.open { width: min(30vw, 420px); }

/* ----------------------------------------------------- фінал: фото в реченні */

.layout-inline .flourish { display: none; }
.layout-inline .caption { max-width: 100%; }
.layout-inline .textbox { max-width: 100%; }
.layout-inline .photo.inline { align-self: center; }

.heart {
  position: absolute;
  z-index: 1;
  bottom: -8vh;
  pointer-events: none;
  color: var(--c, #E5BD67);
  opacity: 0;
  animation: heartUp var(--d, 6s) ease-in forwards;
}
.heart svg {
  display: block;
  width: 100%;
  height: 100%;
  fill: currentColor;
  filter: drop-shadow(0 2px 4px rgba(94, 64, 8, .22));
}
@keyframes heartUp {
  0%   { transform: translate(0, 0) scale(.5) rotate(-8deg); opacity: 0; }
  12%  { opacity: .9; }
  50%  { transform: translate(2vw, -55vh) scale(.9) rotate(8deg); }
  100% { transform: translate(-2vw, -120vh) scale(1.1) rotate(-6deg); opacity: 0; }
}

/* ------------------------------------------------- підказка про колесико */

.scroll-hint {
  position: fixed;
  top: 3.5vh;
  right: 3vw;
  z-index: 900;
  text-align: center;
  color: #fff;
  text-shadow: 0 2px 10px rgba(0, 0, 0, .5);
  opacity: 0;
  transition: opacity .7s ease;
  pointer-events: none;
}
.scroll-hint.show { opacity: 1; }
.scroll-hint p { margin: .5em 0 0; font-size: clamp(16px, 1.6vw, 26px); }

.scroll-hint { --m: clamp(30px, 2.2vw, 46px); }
.mouse {
  position: relative;
  width: var(--m);
  height: calc(var(--m) * 1.6);
  margin: 0 auto;
  border: 3px solid #fff;
  border-radius: 18px;
  box-shadow: 0 2px 14px rgba(0, 0, 0, .35), inset 0 0 8px rgba(0, 0, 0, .15);
}
.wheel {
  position: absolute;
  left: 50%;
  top: calc(var(--m) * .27);
  width: calc(var(--m) * .15);
  height: calc(var(--m) * .32);
  margin-left: calc(var(--m) * -.075);
  border-radius: 3px;
  background: #fff;
  animation: wheel 1.6s ease-in-out infinite;
}
@keyframes wheel {
  0%   { transform: translateY(0);    opacity: 1; }
  70%  { transform: translateY(calc(var(--m) * .5)); opacity: 0; }
  100% { transform: translateY(0);    opacity: 0; }
}

.chev { margin-top: 6px; }
.chev span {
  display: block;
  width: 12px;
  height: 12px;
  margin: -5px auto 0;
  border-right: 3px solid #fff;
  border-bottom: 3px solid #fff;
  transform: rotate(45deg);
  opacity: 0;
  animation: chev 1.6s ease-in-out infinite;
}
.chev span:nth-child(2) { animation-delay: .2s; }
@keyframes chev {
  0%   { opacity: 0; transform: translateY(-4px) rotate(45deg); }
  50%  { opacity: 1; }
  100% { opacity: 0; transform: translateY(6px) rotate(45deg); }
}

/* ------------------------------------------------ прогрес і завантаження */

#progress {
  position: fixed;
  left: 0;
  bottom: 0;
  z-index: 900;
  height: 5px;
  width: 0;
  background: linear-gradient(90deg, var(--sky), var(--gold));
  transition: width .8s ease, opacity .6s ease;
}

#loader {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: grid;
  place-items: center;
  background: var(--cream);
  color: var(--gold);
  font-size: 64px;
  transition: opacity .9s ease;
}
#loader span { animation: pulse 1s ease-in-out infinite; }
#loader.gone { opacity: 0; pointer-events: none; }
@keyframes pulse { 50% { transform: scale(1.25); } }
