/* =========================================================
   ТОКЕНЫ
   ========================================================= */
:root{
  --paper:        #F5EEE1;
  --paper-deep:   #EBDFC8;
  --paper-edge:   #E3D5B8;
  --ink:          #4A3A2A;
  --ink-soft:     #7A6A55;
  --ink-faint:    #A79877;
  --gold:         #AD8A56;
  --gold-soft:    rgba(173, 138, 86, 0.35);
  --gold-faint:   rgba(173, 138, 86, 0.20);
  --line:         rgba(74, 58, 42, 0.16);

  /* лёгкий, светлый serif — единый настрой с финальной фразой */
  --serif:     'Cormorant Garamond', 'Iowan Old Style', Georgia, serif;
  --serif-lit: 'EB Garamond', 'Iowan Old Style', Georgia, serif;

  --dur-slow: 3.8s;
  --dur-med:  2.2s;
  --ease-soft: cubic-bezier(.22,.61,.36,1);
}

/* =========================================================
   БАЗА
   ========================================================= */
*{ box-sizing: border-box; }

html, body{
  height: 100%;
  margin: 0;
  padding: 0;
  overscroll-behavior: none;
}

body{
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
}

img{ display: block; max-width: 100%; }

button{
  font-family: inherit;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

/* мягкая бумажная подложка на всём документе */
body::before{
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse 120% 80% at 50% -10%, rgba(255,255,255,0.35), transparent 55%),
    radial-gradient(ellipse 140% 90% at 50% 115%, var(--paper-edge), transparent 60%),
    linear-gradient(180deg, var(--paper) 0%, var(--paper) 100%);
}

/* лёгкая зернистость бумаги поверх всего */
.grain{
  position: fixed;
  inset: -10%;
  z-index: 5;
  pointer-events: none;
  opacity: 0;
  mix-blend-mode: multiply;
  background-image: 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='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix type='matrix' values='0 0 0 0 0.29  0 0 0 0 0.23  0 0 0 0 0.16  0 0 0 0.05 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 180px 180px;
  /* сначала фактура бумаги медленно проступает, затем — обычное лёгкое движение зерна */
  animation:
    grainFadeIn 3.4s ease-out forwards,
    grainShift 11s steps(6) infinite 3.4s;
}

@keyframes grainFadeIn{
  from { opacity: 0; }
  to   { opacity: 0.5; }
}

@keyframes grainShift{
  0%   { transform: translate(0,0); }
  20%  { transform: translate(-1%,1%); }
  40%  { transform: translate(1%,-1%); }
  60%  { transform: translate(-1%,-1%); }
  80%  { transform: translate(1%,1%); }
  100% { transform: translate(0,0); }
}

/* =========================================================
   МАКЕТ СЦЕН
   ========================================================= */
#app{
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
}

.scene{
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: scale(1.015);
  filter: blur(6px);
  transition:
    opacity var(--dur-slow) var(--ease-soft),
    transform var(--dur-slow) var(--ease-soft),
    filter var(--dur-slow) var(--ease-soft);
}

.scene.is-active{
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: scale(1);
  filter: blur(0);
}

.scene.is-leaving{
  opacity: 0;
  transform: scale(0.985);
  filter: blur(8px);
  transition:
    opacity var(--dur-med) var(--ease-soft),
    transform var(--dur-med) var(--ease-soft),
    filter var(--dur-med) var(--ease-soft);
}

.scene__inner{
  width: 100%;
  max-width: 460px;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(22px, 6vh, 44px);
  padding: max(9vh, env(safe-area-inset-top) + 5vh) 8vw max(8vh, env(safe-area-inset-bottom) + 5vh);
  text-align: center;
}

/* =========================================================
   РАМКА ИЛЛЮСТРАЦИИ — тонкая, нежная, как паспарту
   ========================================================= */
.scene__frame{
  position: relative;
  margin: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(10px, 3.4vw, 18px);
}

/* внутренняя тонкая золотая линия */
.scene__frame::before{
  content: "";
  position: absolute;
  inset: 5px;
  border: 1px solid var(--gold-soft);
  pointer-events: none;
}

/* внешняя едва заметная линия */
.scene__frame::after{
  content: "";
  position: absolute;
  inset: 0;
  border: 1px solid rgba(74, 58, 42, 0.09);
  pointer-events: none;
}

.scene__art{
  width: 92%;
  max-width: 420px;
  height: auto;
  filter: drop-shadow(0 18px 34px rgba(74, 58, 42, 0.16));
  transform: scale(1);
  transition: transform 6s var(--ease-soft), filter 6s var(--ease-soft);
  will-change: transform;
}

/* --- иллюстрация 1-й сцены: крупная, проявляется из дымки --- */
.scene--intro .scene__frame--intro{
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  filter: blur(20px);
  transform: scale(1.06);
  transition:
    opacity 4.2s var(--ease-soft),
    filter 4.2s var(--ease-soft),
    transform 4.2s var(--ease-soft);
}

.scene--intro[data-stage="art"] .scene__frame--intro,
.scene--intro[data-stage="text"] .scene__frame--intro,
.scene--intro[data-stage="ready"] .scene__frame--intro,
.scene--intro.is-touched .scene__frame--intro{
  opacity: 1;
  filter: blur(0);
  transform: scale(1);
}

.scene--intro .scene__frame--intro::before,
.scene--intro .scene__frame--intro::after{
  opacity: 0;
  transition: opacity 2.4s var(--ease-soft) 1.2s;
}

.scene--intro[data-stage="art"] .scene__frame--intro::before,
.scene--intro[data-stage="text"] .scene__frame--intro::before,
.scene--intro[data-stage="ready"] .scene__frame--intro::before,
.scene--intro.is-touched .scene__frame--intro::before,
.scene--intro[data-stage="art"] .scene__frame--intro::after,
.scene--intro[data-stage="text"] .scene__frame--intro::after,
.scene--intro[data-stage="ready"] .scene__frame--intro::after,
.scene--intro.is-touched .scene__frame--intro::after{
  opacity: 1;
}

.scene--intro .scene__art{
  width: 92%;
  max-width: 420px;
}

/* едва заметное «дыхание» картины после появления (включается через JS) */
.scene--intro.is-breathing .scene__art{
  animation: introBreathe 13s ease-in-out infinite;
}

@keyframes introBreathe{
  0%   { transform: scale(1); }
  50%  { transform: scale(1.016); }
  100% { transform: scale(1); }
}

/* по касанию — картина медленно становится главным центром экрана */
.scene--intro.is-touched .scene__art{
  transform: scale(1.24) !important;
  filter: drop-shadow(0 26px 46px rgba(74, 58, 42, 0.22));
  transition: transform 4.4s var(--ease-soft), filter 4.4s var(--ease-soft);
  animation: none;
}

.scene--intro.is-touched .scene__frame--intro::before,
.scene--intro.is-touched .scene__frame--intro::after{
  opacity: 0;
  transition: opacity 1.6s var(--ease-soft);
}

/* тонкая акварельная волна по бумаге в момент касания */
.paper-wave{
  position: absolute;
  left: 50%;
  top: 50%;
  width: 14px;
  height: 14px;
  margin: -7px 0 0 -7px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255,255,255,0.6) 0%, var(--gold-soft) 42%, transparent 72%);
  opacity: 0;
  transform: scale(0);
  pointer-events: none;
  z-index: 2;
}

.scene--intro.is-touched .paper-wave{
  animation: waveExpand 2.6s var(--ease-soft) forwards;
}

@keyframes waveExpand{
  0%   { opacity: 0;    transform: scale(0); }
  12%  { opacity: 0.5; }
  100% { opacity: 0;    transform: scale(46); }
}

.scene--image.is-active .scene__art{
  animation: artBreathe 16s ease-in-out infinite;
}

@keyframes artBreathe{
  0%   { transform: scale(1); }
  50%  { transform: scale(1.03); }
  100% { transform: scale(1); }
}

.scene__frame--small{
  padding: clamp(8px, 2.6vw, 12px);
}

.scene__frame--small .scene__art{
  width: 92%;
  max-width: 420px;
  opacity: 1;
}

/* =========================================================
   СЦЕНА 1 — ТЕКСТ И ЗНАК
   ========================================================= */
.scene__inner--intro{
  gap: clamp(28px, 6.4vh, 48px);
}

.line--intro{
  margin: 0;
  font-family: var(--serif-lit);
  font-style: italic;
  font-weight: 400;
  font-size: clamp(23px, 6.4vw, 29px);
  line-height: 1.7;
  color: var(--ink);
  letter-spacing: 0.012em;
  opacity: 0;
  transform: translateY(18px);
  transition: opacity 2.8s var(--ease-soft), transform 2.8s var(--ease-soft);
}

.scene--intro[data-stage="text"] .line--intro,
.scene--intro[data-stage="ready"] .line--intro{
  opacity: 1;
  transform: translateY(0);
}

.line--intro em{
  font-style: italic;
  color: var(--ink);
  font-weight: 500;
}

.scene--intro.is-touched .line--intro{
  opacity: 0;
  transform: translateY(-10px);
  transition: opacity 1.4s var(--ease-soft), transform 1.4s var(--ease-soft);
}

.touch-wrap{
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  opacity: 0;
  transform: translateY(8px) scale(0.92);
  transition: opacity 2.2s var(--ease-soft), transform 2.2s var(--ease-soft);
}

.scene--intro[data-stage="ready"] .touch-wrap{
  opacity: 1;
  transform: translateY(0) scale(1);
}

.touch{
  position: relative;
  width: 58px;
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.6s var(--ease-soft), transform 0.6s var(--ease-soft);
}

.touch__ring{
  position: absolute;
  inset: 0;
  border: 1px solid var(--gold-soft);
  border-radius: 50%;
  animation: touchPulse 3.6s ease-in-out infinite;
  transition: opacity 0.6s var(--ease-soft), transform 0.6s var(--ease-soft);
}

.touch__ring--2{
  animation-delay: 1.8s;
}

.touch__core{
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--gold);
  opacity: 0.85;
  transition: transform 0.7s var(--ease-soft), box-shadow 0.7s var(--ease-soft);
}

@keyframes touchPulse{
  0%   { transform: scale(0.55); opacity: 0; }
  35%  { opacity: 0.6; }
  100% { transform: scale(1.35); opacity: 0; }
}

.touch__label{
  font-size: 12.5px;
  letter-spacing: 0.16em;
  color: var(--ink-faint);
  font-style: italic;
}

/* по касанию: кольца исчезают, точка мягко сжимается в светящийся центр */
.scene--intro.is-touched .touch__ring{
  opacity: 0;
  transform: scale(0.35);
  animation: none;
}

.scene--intro.is-touched .touch__core{
  transform: scale(2.6);
  box-shadow: 0 0 20px 7px var(--gold-soft);
}

.scene--intro.is-touched .touch-wrap{
  opacity: 0;
  transition: opacity 1.2s var(--ease-soft) 0.5s;
  pointer-events: none;
}

.touch:active .touch__core{
  transform: scale(1.6);
}

/* =========================================================
   ЛИЧНЫЕ ЗАМЕТКИ ПОД КАРТИНКАМИ (лёгкий serif, без «тяжёлого» шрифта)
   ========================================================= */
.notes{
  display: flex;
  flex-direction: column;
  gap: clamp(14px, 3.2vh, 20px);
  width: 100%;
}

.notes__lead{
  margin: 0 0 2px;
  font-family: var(--serif-lit);
  font-weight: 400;
  font-style: italic;
  font-size: clamp(19px, 5vw, 23px);
  color: var(--ink-soft);
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 1.8s var(--ease-soft), transform 1.8s var(--ease-soft);
}

.notes__item{
  margin: 0;
  font-family: var(--serif);
  font-weight: 400;
  font-style: italic;
  font-size: clamp(20px, 5.4vw, 24px);
  line-height: 1.55;
  color: var(--ink);
  letter-spacing: 0.006em;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 1.8s var(--ease-soft), transform 1.8s var(--ease-soft);
}

.notes__lead.is-shown,
.notes__item.is-shown{
  opacity: 1;
  transform: translateY(0);
}

.notes--serif .notes__item{
  font-size: clamp(20px, 5.6vw, 25px);
  line-height: 1.62;
}

.notes--serif .notes__item--emph{
  font-weight: 500;
  font-size: clamp(22px, 6vw, 27px);
  color: var(--ink);
  margin-top: 4px;
}

/* =========================================================
   ИНТЕРЛЮДИИ — короткие романтические фразы между картинками
   ========================================================= */
.scene__inner--interlude{
  gap: clamp(18px, 3.6vh, 28px);
}

.interlude__rule{
  display: block;
  width: 34px;
  height: 1px;
  background: var(--gold-soft);
  opacity: 0;
  transition: opacity 2s var(--ease-soft), width 2s var(--ease-soft);
}

.scene--interlude.is-active .interlude__rule{
  opacity: 1;
  width: 46px;
}

.interlude__text{
  margin: 0;
  font-family: var(--serif-lit);
  font-style: italic;
  font-weight: 400;
  font-size: clamp(22px, 6.2vw, 27px);
  line-height: 1.75;
  color: var(--ink);
  letter-spacing: 0.008em;
  opacity: 0;
  transform: translateY(14px);
  transition: opacity 2.6s var(--ease-soft), transform 2.6s var(--ease-soft);
}

.interlude__text.is-shown{
  opacity: 1;
  transform: translateY(0);
}

/* =========================================================
   ФИНАЛ
   ========================================================= */
.scene--final .scene__inner{
  gap: clamp(30px, 7vh, 50px);
}

.final__line{
  margin: 0;
  font-family: var(--serif-lit);
  font-style: italic;
  font-weight: 400;
  font-size: clamp(27px, 7.6vw, 33px);
  color: var(--ink);
  letter-spacing: 0.01em;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 4.4s var(--ease-soft), transform 4.4s var(--ease-soft);
}

.final__line.is-shown{
  opacity: 1;
  transform: translateY(0);
}

/* =========================================================
   ДОСТУПНОСТЬ
   ========================================================= */
@media (prefers-reduced-motion: reduce){
  .scene,
  .scene.is-leaving,
  .scene__frame--intro,
  .line--intro,
  .touch-wrap,
  .paper-wave,
  .notes__lead,
  .notes__item,
  .interlude__text,
  .interlude__rule,
  .final__line,
  .scene__art{
    transition-duration: 0.4s !important;
    animation: none !important;
  }
  .grain{ animation: none; opacity: 0.5; }
}

/* маленькие экраны */
@media (max-height: 600px){
  .scene__art{ max-width: 380px; }
  .scene--intro .scene__art{ max-width: 400px; }
}

/* широкие/десктопные окна — сохраняем мобильный "кадр" по центру */
@media (min-width: 560px){
  body{ background: var(--paper-deep); }
  #app{
    max-width: 430px;
    height: 100%;
    margin: 0 auto;
    box-shadow: 0 0 60px rgba(74,58,42,0.18);
    background: var(--paper);
  }
}
