/* ============================================================
   style.css — общие стили для всех страниц
   ------------------------------------------------------------
   Подключается на КАЖДОЙ странице. Браузер кэширует его после
   первой загрузки → переходы между страницами быстрые.

   Структура:
     1. Дизайн-система (:root)
     2. Основа экрана (html, body) — правильная для iPhone Safari
     3. Общие компоненты (контейнер, кнопки, типографика)
     4. Плавные переходы между страницами
   ============================================================ */

/* ============================================================
   1. ДИЗАЙН-СИСТЕМА
   ============================================================ */
:root {
  /* Цвета — молочная пастель */
  --color-bg:            #F8F6F2;
  --color-bg-secondary:  #F1ECE4;
  --color-surface:       #FFFFFF;
  --color-text:          #3B3833;
  --color-text-secondary:#8A857D;
  --color-accent:        #C9A96A;
  --color-accent-soft:   #E7D9BC;
  --color-peach:         #F3DCD0;
  --color-rose:          #E4C4C0;
  --color-border:        rgba(59, 56, 51, 0.10);
  --color-shadow:        rgba(80, 70, 55, 0.16);

  /* Шрифты — системные (мгновенная загрузка) */
  --font-display: ui-serif, "New York", Georgia, serif;
  --font-body:    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;

  /* Типографика */
  --fs-display: clamp(3rem, 11vw, 4.5rem);
  --fs-h1:      clamp(2rem, 7vw, 3rem);
  --fs-h2:      clamp(1.6rem, 5.5vw, 2.25rem);
  --fs-h3:      clamp(1.3rem, 4.8vw, 1.7rem);
  --fs-body-lg: clamp(1.2rem, 4.4vw, 1.45rem);
  --fs-body:    clamp(1.05rem, 4vw, 1.18rem);
  --fs-small:   clamp(0.92rem, 3.4vw, 1rem);
  --fs-caption: 0.8rem;

  /* Отступы */
  --space-1: 4px;  --space-2: 8px;  --space-3: 12px; --space-4: 16px;
  --space-5: 24px; --space-6: 32px; --space-7: 48px; --space-8: 64px;

  /* Скругления */
  --radius-sm: 12px; --radius-md: 16px; --radius-lg: 24px; --radius-full: 999px;

  /* Тени */
  --shadow-sm: 0 2px 8px var(--color-shadow);
  --shadow-md: 0 8px 24px var(--color-shadow);
  --shadow-lg: 0 20px 50px var(--color-shadow);

  /* Анимации */
  --dur-fast: 0.3s; --dur-normal: 0.6s; --dur-slow: 1s;
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);

  /* Контейнер */
  --container-width: 540px;
  --container-pad: var(--space-5);
}


/* ============================================================
   2. ОСНОВА ЭКРАНА (правильная для iPhone Safari)
   ============================================================ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  /* Фон на html — принадлежит всей странице, без белых полос */
  background: var(--color-bg);
  /* Плавная прокрутка */
  scroll-behavior: smooth;
}

body {
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-body);
  font-size: var(--fs-body);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
  /* Минимальная высота — реальный экран iPhone (dvh) */
  min-height: 100vh;
  min-height: 100dvh;
}


/* ============================================================
   3. ОБЩИЕ КОМПОНЕНТЫ
   ============================================================ */

/* Экран — обёртка одной страницы. Занимает весь экран,
   контент по центру. Прокрутка страницей, если контент длинный. */
.screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  /* Безопасные зоны iPhone (челка, Dynamic Island, низ) */
  padding:
    calc(var(--space-7) + env(safe-area-inset-top))
    calc(var(--container-pad) + env(safe-area-inset-right))
    calc(var(--space-7) + env(safe-area-inset-bottom))
    calc(var(--container-pad) + env(safe-area-inset-left));
}

/* Контейнер контента — ограничивает ширину для читаемости */
.container {
  width: 100%;
  max-width: var(--container-width);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-6);
}

/* Типографика */
.text-display {
  font-family: var(--font-display);
  font-size: var(--fs-display);
  line-height: 1.05;
  font-weight: 500;
  letter-spacing: -0.02em;
}
.text-h2 {
  font-family: var(--font-display);
  font-size: var(--fs-h2);
  line-height: 1.2;
  font-weight: 500;
}
.text-body-lg {
  font-size: var(--fs-body-lg);
  line-height: 1.5;
  color: var(--color-text-secondary);
}

/* Кнопка — единый компонент */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 56px;
  padding: var(--space-4) var(--space-7);
  background: var(--color-accent);
  color: #fff;
  font-size: var(--fs-small);
  font-weight: 600;
  border: none;
  border-radius: var(--radius-full);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.15s var(--ease), background var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.btn:active {
  transform: scale(0.97);
}
@media (hover: hover) {
  .btn:hover {
    background: #B8975A;
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
  }
}
.btn--ghost {
  background: transparent;
  color: var(--color-text-secondary);
  box-shadow: none;
  border: 1px solid var(--color-border);
}

/* Карточка */
.card {
  width: 100%;
  padding: var(--space-7) var(--space-6);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}


/* ============================================================
   4. ПЛАВНЫЕ ПЕРЕХОДЫ МЕЖДУ СТРАНИЦАМИ
   ------------------------------------------------------------
   При загрузке страница плавно проявляется (fade-in).
   При уходе (клик по кнопке "дальше") — плавно гаснет (fade-out),
   затем common.js переводит на следующую страницу.
   Так переходы между отдельными html выглядят цельно.
   ============================================================ */
body {
  opacity: 0;
  transition: opacity var(--dur-normal) var(--ease);
}
/* класс добавляется в common.js после загрузки */
body.page-ready {
  opacity: 1;
}
/* класс добавляется перед переходом на следующую страницу */
body.page-leaving {
  opacity: 0;
}

/* Появление отдельных элементов (по очереди) */
.reveal {
  opacity: 0;
  transform: translateY(12px);
  transition: opacity var(--dur-slow) var(--ease), transform var(--dur-slow) var(--ease);
}
.reveal.is-visible {
  opacity: 1;
  transform: translateY(0);
}

/* Уважение к настройке «уменьшить движение» */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.15s !important;
    animation: none !important;
  }
  html { scroll-behavior: auto; }
}

/* ============================================================
   5. СТИЛИ ОТДЕЛЬНЫХ ЭКРАНОВ
   ============================================================ */
.message-line {
  font-family: var(--font-display);
  font-size: var(--fs-h2);
  line-height: 1.3;
  color: var(--color-text);
  max-width: 18ch;
}
.message-stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
  align-items: center;
}

/* --- Карточка инструкции (стартовая страница) --- */
.instruction {
  text-align: left;
  margin-top: var(--space-4);
}
.instruction__icon {
  font-size: 2.4rem;
  text-align: center;
  margin-bottom: var(--space-4);
}
.instruction__title {
  font-family: var(--font-display);
  font-size: var(--fs-h2);
  font-weight: 500;
  text-align: center;
  margin-bottom: var(--space-5);
}
.instruction__list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  font-size: var(--fs-body);
  line-height: 1.5;
}

/* ============================================================
   ФОТО и ПЛЕЙСХОЛДЕРЫ
   ------------------------------------------------------------
   Место под фото. Пока файла нет — показывается красивый
   плейсхолдер. Когда добавишь фото в assets/images/ и укажешь
   путь в <img>, оно встанет на место.
   ============================================================ */
.photo {
  width: 100%;
  max-width: 300px;
  aspect-ratio: 4 / 5;
  margin: 0 auto;
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-md);
  background: var(--color-bg-secondary);
}
.photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
/* Плейсхолдер — нарядная заглушка вместо фото */
.photo--placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  padding: var(--space-5);
  text-align: center;
  border: 1.5px dashed var(--color-accent-soft);
  background: linear-gradient(135deg, var(--color-peach) 0%, var(--color-rose) 100%);
  color: var(--color-text-secondary);
}
.photo__icon { font-size: 2rem; opacity: 0.85; }
.photo__name {
  font-size: var(--fs-caption);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 500;
}
.photo__hint { font-size: var(--fs-caption); opacity: 0.75; }

/* --- Блок «мысль»: фраза + фото под ней --- */
.thought {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-5);
  width: 100%;
}
.thought__text {
  font-family: var(--font-display);
  font-size: var(--fs-h3);
  line-height: 1.3;
  color: var(--color-text);
  max-width: 22ch;
}
.thoughts-stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-8);
  width: 100%;
  align-items: center;
}

/* --- Страница «Фабака» (собака) --- */
.dog-emoji {
  font-size: 3.5rem;
  transform-origin: 70% 70%;
  animation: dogWave 2.4s ease-in-out infinite;
}
@keyframes dogWave {
  0%, 100% { transform: rotate(-6deg); }
  50%      { transform: rotate(6deg); }
}
.dog-text {
  font-family: var(--font-display);
  font-size: var(--fs-h3);
  line-height: 1.35;
  color: var(--color-text);
  max-width: 24ch;
}

/* --- Страница «Факты» --- */
.facts-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  text-align: left;
  font-size: var(--fs-body);
  line-height: 1.5;
}

/* Статистика — пары «подпись → значение» */
.stats-title {
  font-family: var(--font-display);
  font-size: var(--fs-h3);
  font-weight: 500;
  text-align: center;
  margin-bottom: var(--space-5);
}
.stats-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}
.stats-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--space-4);
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--color-border);
}
.stats-row:last-child {
  border-bottom: none;
  padding-bottom: 0;
}
.stats-row__label {
  font-size: var(--fs-small);
  color: var(--color-text-secondary);
  text-align: left;
}
.stats-row__value {
  font-family: var(--font-display);
  font-size: var(--fs-h3);
  color: var(--color-accent);
  white-space: nowrap;
}

/* --- Страница «Инструкция по использованию Лизы» --- */
.manual {
  text-align: left;
}
.manual__title {
  font-family: var(--font-display);
  font-size: var(--fs-h3);
  font-weight: 500;
  line-height: 1.3;
  text-align: center;
  color: var(--color-text);
}
.manual__subtitle {
  font-size: var(--fs-caption);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-text-secondary);
  text-align: center;
  margin-top: var(--space-2);
  margin-bottom: var(--space-5);
}
.manual__divider {
  height: 1px;
  background: var(--color-border);
  margin-bottom: var(--space-5);
}
.manual__list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  font-size: var(--fs-body);
  line-height: 1.5;
}

/* --- Страница «Атмосфера» (тихая пауза) --- */
.atmosphere-line {
  font-family: var(--font-display);
  font-size: var(--fs-h2);
  line-height: 1.35;
  color: var(--color-text);
  max-width: 20ch;
}

/* --- Страница-пауза с котёнком --- */
.cat-emoji {
  font-size: 4rem;
  animation: catBob 1.4s ease-in-out infinite;
}
@keyframes catBob {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-10px); }
}
.cat-text {
  font-family: var(--font-display);
  font-size: var(--fs-h3);
  line-height: 1.4;
  color: var(--color-text-secondary);
  max-width: 22ch;
}
/* Три точки-многоточие, мигают по очереди */
.cat-dots {
  display: flex;
  gap: var(--space-2);
  justify-content: center;
}
.cat-dots span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-accent);
  opacity: 0.3;
  animation: dotPulse 1.4s ease-in-out infinite;
}
.cat-dots span:nth-child(2) { animation-delay: 0.2s; }
.cat-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes dotPulse {
  0%, 100% { opacity: 0.25; transform: scale(1); }
  50%      { opacity: 1;    transform: scale(1.25); }
}

/* ============================================================
   КОНВЕРТ + ПИСЬМО (одна страница)
   ============================================================ */

/* --- Обёртка конверта --- */
.envelope-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-6);
  transition: opacity var(--dur-normal) var(--ease),
              transform var(--dur-normal) var(--ease);
}
/* конверт уезжает вверх и исчезает, когда открыт */
.envelope-stage.is-gone {
  opacity: 0;
  transform: translateY(-30px) scale(0.96);
  pointer-events: none;
  position: absolute;
}

/* --- Сам конверт (слои) --- */
.envelope {
  position: relative;
  width: min(78vw, 320px);
  aspect-ratio: 3 / 2;
  border: none;
  background: none;
  padding: 0;
  cursor: pointer;
  perspective: 1200px;
  transition: transform var(--dur-fast) var(--ease);
}
.envelope:active { transform: scale(0.98); }

/* тень под конвертом — объём */
.envelope__shadow {
  position: absolute;
  left: 50%; bottom: -6%;
  width: 76%; height: 12%;
  transform: translateX(-50%);
  background: radial-gradient(ellipse at center, var(--color-shadow), transparent 70%);
  filter: blur(8px);
}
/* корпус — плотная бумага */
.envelope__body {
  position: absolute;
  inset: 0;
  background: linear-gradient(160deg, #FBF7EF 0%, #F0E7D6 100%);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md), inset 0 0 40px rgba(160, 140, 105, 0.10);
}
/* лист письма внутри (выезжает при открытии) */
.envelope__letter {
  position: absolute;
  inset: 8% 8% auto 8%;
  height: 84%;
  background: linear-gradient(180deg, #FFFFFF 0%, #FBF7EF 100%);
  border-radius: var(--radius-sm);
  box-shadow: 0 4px 14px rgba(120, 100, 70, 0.14);
  transform: translateY(0);
  transition: transform var(--dur-slow) var(--ease);
  z-index: 1;
}
/* передняя стенка-карман */
.envelope__front {
  position: absolute;
  inset: 0;
  z-index: 2;
  background: linear-gradient(160deg, #F4EBD9 0%, #E8DCC4 100%);
  clip-path: polygon(0 34%, 50% 100%, 100% 34%, 100% 100%, 0 100%);
  border-radius: var(--radius-sm);
  box-shadow: inset 0 6px 20px rgba(160, 140, 105, 0.14);
}
/* клапан сверху — откидывается */
.envelope__flap {
  position: absolute;
  inset: 0;
  z-index: 4;
  transform-origin: top center;
  background: linear-gradient(160deg, #F7F0E1 0%, #ECE0C9 100%);
  clip-path: polygon(0 0, 100% 0, 50% 62%);
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  box-shadow: 0 2px 6px rgba(160, 140, 105, 0.12);
  transition: transform var(--dur-slow) var(--ease);
  backface-visibility: hidden;
}
/* восковая печать */
.envelope__seal {
  position: absolute;
  top: 42%; left: 50%;
  transform: translate(-50%, -50%);
  width: 22%; aspect-ratio: 1;
  z-index: 5;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: radial-gradient(circle at 38% 32%, #D7B583, var(--color-accent) 68%, #A6884E 100%);
  color: #fff;
  font-family: var(--font-display);
  font-size: clamp(1rem, 5vw, 1.4rem);
  box-shadow: 0 3px 10px rgba(120, 90, 40, 0.35), inset 0 1px 3px rgba(255,255,255,0.4);
  transition: opacity var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}

/* Состояние «открыт» */
.envelope.is-open .envelope__flap   { transform: rotateX(176deg); }
.envelope.is-open .envelope__seal   { opacity: 0; transform: translate(-50%, -50%) scale(0.85); }
.envelope.is-open .envelope__letter { transform: translateY(-58%); }

/* Подсказка под конвертом */
.envelope__hint {
  font-size: var(--fs-caption);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-text-secondary);
  animation: hintPulse 2.6s ease-in-out infinite;
}
@keyframes hintPulse {
  0%, 100% { opacity: 0.45; }
  50%      { opacity: 1; }
}

/* --- ПИСЬМО (появляется после открытия конверта) --- */
.letter-sheet {
  width: 100%;
  padding: var(--space-7) var(--space-6);
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  text-align: left;
  /* лёгкая текстура бумаги */
  background-image:
    linear-gradient(var(--color-surface), var(--color-surface)),
    repeating-linear-gradient(0deg, rgba(160,140,105,0.015) 0 28px, transparent 28px 29px);

  /* скрыто, пока конверт не открыт */
  display: none;
  opacity: 0;
  transform: translateY(20px);
  transition: opacity var(--dur-slow) var(--ease), transform var(--dur-slow) var(--ease);
}
.letter-sheet.is-shown {
  display: block;
}
.letter-sheet.is-visible {
  opacity: 1;
  transform: translateY(0);
}
.letter__salutation {
  font-family: var(--font-display);
  font-size: var(--fs-h1);
  font-style: italic;
  font-weight: 500;
  line-height: 1.2;
  margin-bottom: var(--space-5);
}
.letter__body {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}
.letter__body p {
  font-size: var(--fs-body);
  line-height: 1.75;
  color: var(--color-text);
}
.letter__photo {
  margin: var(--space-2) auto;
}
.letter__photo .photo {
  max-width: 240px;
  aspect-ratio: 4 / 3;
}
.letter__signature {
  margin-top: var(--space-6);
  font-family: var(--font-display);
  font-style: italic;
  font-size: var(--fs-h3);
  color: var(--color-accent);
  text-align: left;
}

/* ============================================================
   ФИНАЛ + ЗАВЕРШЕНИЕ (одна страница)
   ============================================================ */

/* --- Праздничный финал --- */
.final-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-6);
  width: 100%;
  transition: opacity var(--dur-slow) var(--ease);
}
.final-stage.is-fading { opacity: 0; }

.final-heart {
  font-size: 4rem;
  animation: heartBeat 1.8s ease-in-out infinite;
}
@keyframes heartBeat {
  0%, 100% { transform: scale(1); }
  14%      { transform: scale(1.15); }
  28%      { transform: scale(1); }
}
.final-title {
  font-family: var(--font-display);
  font-size: var(--fs-h1);
  font-weight: 500;
  line-height: 1.2;
  color: var(--color-text);
  white-space: pre-line;
}
.final-subtitle {
  font-family: var(--font-display);
  font-style: italic;
  font-size: var(--fs-h3);
  color: var(--color-accent);
}

/* Галерея фото в финале — лёгкий коллаж */
.final-gallery {
  display: flex;
  gap: var(--space-4);
  justify-content: center;
  flex-wrap: wrap;
  width: 100%;
}
.final-gallery .photo {
  max-width: 150px;
  aspect-ratio: 3 / 4;
}
.final-gallery .photo:nth-child(odd)  { transform: rotate(-3deg); }
.final-gallery .photo:nth-child(even) { transform: rotate(3deg); }

/* Слой праздника (конфетти/шары/сердечки) */
#celebration {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
}

/* --- Завершение: затемнённый экран --- */
.goodbye {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-6);
  padding: var(--space-6);
  text-align: center;
  background: #1A1714;      /* тёплый графит, не чистый чёрный */
  opacity: 0;
  transition: opacity var(--dur-slow) var(--ease);
}
.goodbye.is-shown  { display: flex; }
.goodbye.is-visible { opacity: 1; }

.goodbye__text {
  font-family: var(--font-display);
  font-size: var(--fs-h2);
  line-height: 1.35;
  color: #F3ECE0;
  max-width: 20ch;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity var(--dur-slow) var(--ease), transform var(--dur-slow) var(--ease);
}
.goodbye__heart {
  font-size: 2.2rem;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity var(--dur-slow) var(--ease), transform var(--dur-slow) var(--ease);
  animation: heartBeat 2s ease-in-out infinite;
}
.goodbye__text.is-in,
.goodbye__heart.is-in {
  opacity: 1;
  transform: translateY(0);
}
