/* MemoFamily — демо Продукта 1.1 «Одна история о близком человеке» (memogiftdemo).
   Палитра «Warm Felt & Yarn» — общая с memodemo/memogift. */

:root {
  --bg: #FDFBF7;
  --bg-warm: #F5EFE6;
  --text: #4A4036;
  --text-soft: #7A6E5F;
  --primary: #D97C55;
  --primary-dark: #C2643E;
  --secondary: #8EA48C;
  --secondary-dark: #74896F;
  --accent: #E8C39E;
  --shadow-soft: 0 6px 24px rgba(74, 64, 54, 0.08);
  --shadow-hover: 0 10px 32px rgba(74, 64, 54, 0.12);
  --radius: 24px;
  --radius-pill: 9999px;
  --font-serif: 'Lora', Georgia, 'Times New Roman', serif;
  --font-sans: 'Manrope', -apple-system, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 18px; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { text-wrap: balance; }

.page {
  max-width: 880px;
  margin: 0 auto;
  padding: 24px 20px 48px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

main { flex: 1; }

/* ---------- Header / footer ---------- */

.site-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 8px 4px 28px;
}

.brand {
  font-family: var(--font-serif);
  font-size: 1.5rem;
  font-weight: 700;
  cursor: pointer;
  user-select: none;
}
.brand em { font-style: italic; font-weight: 500; color: var(--primary); }
.brand-mark { margin-right: 6px; }

.brand-tagline { font-size: 0.85rem; color: var(--text-soft); }

.site-footer {
  text-align: center;
  color: var(--text-soft);
  font-size: 0.8rem;
  padding-top: 40px;
}
.footer-home-link {
  color: var(--text-soft);
  text-decoration: underline;
  text-underline-offset: 3px;
  transition: color .2s ease;
}
.footer-home-link:hover, .footer-home-link:focus-visible { color: var(--primary-dark); }

/* ---------- Cards ---------- */

.card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
  padding: 36px 32px;
  animation: rise .45s ease both;
}
.card + .card { margin-top: 24px; }

@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}

h1, h2, h3 { font-family: var(--font-serif); line-height: 1.25; }
h1 { font-size: 2rem; margin-bottom: 12px; }
h2 { font-size: 1.5rem; margin-bottom: 10px; }
h3 { font-size: 1.15rem; margin-bottom: 8px; }

.lead { font-size: 1.05rem; color: var(--text-soft); margin-bottom: 8px; }

.hero { text-align: center; padding: 48px 32px; }
.hero .lead { max-width: 580px; margin: 0 auto 8px; }
.hero-emoji { font-size: 3rem; display: block; margin-bottom: 12px; }

.hero-steps {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
  margin: 30px auto 6px;
  max-width: 640px;
  text-align: left;
}
@media (max-width: 680px) { .hero-steps { grid-template-columns: 1fr; } }
.hero-step {
  background: var(--bg-warm);
  border-radius: 18px;
  padding: 16px 18px;
  font-size: 0.9rem;
  color: var(--text-soft);
}
.hero-step b {
  display: block;
  color: var(--text);
  font-family: var(--font-serif);
  font-size: 1rem;
  margin-bottom: 4px;
}
.hero-note { font-size: 0.85rem; color: var(--text-soft); margin-top: 16px; }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: var(--radius-pill);
  padding: 14px 32px;
  font-family: var(--font-sans);
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform .15s ease, box-shadow .15s ease, background .15s ease;
  text-decoration: none;
}
.btn:active { transform: scale(.96); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn--primary { background: var(--primary); color: #fff; box-shadow: 0 4px 14px rgba(217, 124, 85, .35); }
.btn--primary:hover:not(:disabled) { background: var(--primary-dark); box-shadow: 0 6px 18px rgba(217, 124, 85, .45); }

.btn--secondary { background: var(--secondary); color: #fff; }
.btn--secondary:hover:not(:disabled) { background: var(--secondary-dark); }

.btn--ghost { background: transparent; color: var(--text-soft); font-weight: 600; }
.btn--ghost:hover:not(:disabled) { color: var(--text); background: var(--bg-warm); }

.btn--big { font-size: 1.15rem; padding: 18px 42px; }

.btn-row {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  margin-top: 24px;
  align-items: center;
}
.btn-row--center { justify-content: center; }
.btn-row--between { justify-content: space-between; }

/* ---------- Progress ---------- */

.progress-wrap { margin-bottom: 20px; }
.progress-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--text-soft);
  margin-bottom: 8px;
  font-weight: 600;
}
.progress-bar {
  height: 10px;
  background: var(--bg-warm);
  border-radius: var(--radius-pill);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--primary));
  border-radius: var(--radius-pill);
  transition: width .4s ease;
}

/* ---------- Chat ---------- */

.chat-card { padding: 26px 24px 20px; }

.chat-log {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 260px;
  max-height: 56vh;
  overflow-y: auto;
  padding: 6px 4px 12px;
  scroll-behavior: smooth;
}

.msg {
  max-width: 82%;
  padding: 13px 18px;
  border-radius: 20px;
  font-size: 1.02rem;
  line-height: 1.55;
  animation: rise .3s ease both;
  white-space: pre-wrap;
  overflow-wrap: break-word;
}
.msg--bot {
  align-self: flex-start;
  background: var(--bg-warm);
  border-bottom-left-radius: 6px;
}
.msg--user {
  align-self: flex-end;
  background: var(--primary);
  color: #fff;
  border-bottom-right-radius: 6px;
}
.msg--bot .q-goal-tag {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--secondary-dark);
  letter-spacing: .04em;
  text-transform: uppercase;
  margin-bottom: 4px;
}

.typing { display: inline-flex; gap: 5px; padding: 4px 2px; }
.typing i {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--text-soft);
  opacity: .4;
  animation: blink 1.2s infinite;
}
.typing i:nth-child(2) { animation-delay: .2s; }
.typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: .9; transform: translateY(-2px); } }

.msg--choice {
  align-self: center;
  background: transparent;
  max-width: 100%;
  text-align: center;
  padding: 6px 0;
}
.msg--choice .choice-note {
  font-size: 0.9rem;
  color: var(--text-soft);
  margin-bottom: 12px;
  font-style: italic;
  font-family: var(--font-serif);
}
.msg--choice .btn { margin: 4px 6px; }

.chat-input {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  border-top: 1px solid var(--bg-warm);
  padding-top: 16px;
}
.chat-input textarea {
  flex: 1;
  min-height: 56px;
  max-height: 200px;
  border: 2px solid var(--bg-warm);
  border-radius: 16px;
  background: var(--bg);
  padding: 13px 16px;
  font-family: var(--font-sans);
  font-size: 1.02rem;
  color: var(--text);
  resize: none;
  transition: border-color .2s ease;
}
.chat-input textarea:focus { outline: none; border-color: var(--accent); background: #fff; }

.chat-send {
  flex-shrink: 0;
  width: 56px; height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--primary);
  color: #fff;
  font-size: 1.3rem;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(217, 124, 85, .35);
  transition: background .15s ease, transform .15s ease;
}
.chat-send:hover:not(:disabled) { background: var(--primary-dark); }
.chat-send:active { transform: scale(.94); }
.chat-send:disabled { opacity: .45; cursor: not-allowed; }

.chat-tools {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 10px;
  gap: 10px;
  flex-wrap: wrap;
}
.chat-undo {
  background: none;
  border: none;
  color: var(--text-soft);
  font-family: var(--font-sans);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.chat-undo:hover { color: var(--primary-dark); }
.chat-undo:disabled { opacity: 0; pointer-events: none; }
.chat-hint { font-size: 0.78rem; color: var(--text-soft); }

/* ---------- Поле имени / формы ---------- */

textarea, input[type="text"], input[type="email"] {
  width: 100%;
  border: 2px solid var(--bg-warm);
  border-radius: 16px;
  background: var(--bg);
  padding: 16px 18px;
  font-family: var(--font-sans);
  font-size: 1.05rem;
  color: var(--text);
  transition: border-color .2s ease;
}
textarea:focus, input[type="text"]:focus, input[type="email"]:focus {
  outline: none;
  border-color: var(--accent);
  background: #fff;
}

.field { margin-bottom: 18px; }
.field label { display: block; font-weight: 700; font-size: 0.95rem; margin-bottom: 8px; }
.hint { font-size: 0.85rem; color: var(--text-soft); margin-top: 10px; }

/* ---------- Loading: «вёрстка страницы» ---------- */

.loading { text-align: center; padding: 60px 32px 70px; }

.typeset {
  width: 130px; height: 172px;
  margin: 0 auto 30px;
  background: var(--bg);
  border-radius: 6px;
  box-shadow: 0 2px 6px rgba(74,64,54,.10), 0 14px 30px rgba(74,64,54,.16);
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 9px;
  position: relative;
  animation: pageFloat 3s ease-in-out infinite;
}
@keyframes pageFloat { 0%,100% { transform: translateY(0) rotate(-1deg); } 50% { transform: translateY(-6px) rotate(1deg); } }

.typeset i {
  display: block;
  height: 7px;
  border-radius: 4px;
  background: var(--accent);
  opacity: .55;
  transform-origin: left;
  animation: lineGrow 2.4s ease-in-out infinite;
}
.typeset i:nth-child(1) { width: 55%; height: 10px; background: var(--primary); opacity: .7; animation-delay: 0s; }
.typeset i:nth-child(2) { width: 92%; animation-delay: .25s; }
.typeset i:nth-child(3) { width: 86%; animation-delay: .5s; }
.typeset i:nth-child(4) { width: 94%; animation-delay: .75s; }
.typeset i:nth-child(5) { width: 78%; animation-delay: 1s; }
.typeset i:nth-child(6) { width: 90%; animation-delay: 1.25s; }
.typeset i:nth-child(7) { width: 64%; animation-delay: 1.5s; }
@keyframes lineGrow { 0% { transform: scaleX(0); } 35%, 85% { transform: scaleX(1); } 100% { transform: scaleX(1); opacity: .2; } }

.loading-msg {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 1.15rem;
  color: var(--text-soft);
  min-height: 1.8em;
  transition: opacity .4s ease;
}

/* ---------- Страница книги ---------- */

.book-page {
  background: var(--bg);
  border-radius: 12px;
  box-shadow: 0 2px 6px rgba(74,64,54,.08), 0 18px 44px rgba(74,64,54,.14);
  padding: 52px 48px 40px;
  font-family: var(--font-serif);
  position: relative;
  animation: rise .5s ease both;
}
.book-page + .book-page { margin-top: 28px; }
@media (max-width: 680px) { .book-page { padding: 36px 24px 32px; } }

.chapter-label {
  text-align: center;
  font-variant: small-caps;
  letter-spacing: .22em;
  color: var(--primary-dark);
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 10px;
}
.chapter-label::before, .chapter-label::after { content: " · "; color: var(--accent); }

.book-title {
  text-align: center;
  font-size: 1.7rem;
  font-weight: 600;
  margin-bottom: 6px;
}
.book-subtitle {
  text-align: center;
  font-style: italic;
  color: var(--text-soft);
  font-size: 1rem;
  margin-bottom: 34px;
}

.story { margin: 6px 0 8px; }
.story p {
  font-size: 1.05rem;
  line-height: 1.85;
  text-indent: 1.6em;
  margin-bottom: 0.85em;
  text-align: justify;
  hyphens: auto;
}
.story p:first-child { text-indent: 0; }
.story p:first-child::first-letter {
  float: left;
  font-size: 3.6rem;
  line-height: 0.85;
  font-weight: 600;
  color: var(--primary);
  padding: 6px 10px 0 0;
}

.honesty {
  text-align: center;
  font-size: 0.82rem;
  font-style: italic;
  color: var(--text-soft);
  margin-top: 26px;
  font-family: var(--font-sans);
}
.honesty::before { content: "✻ "; color: var(--accent); }

.page-number {
  text-align: center;
  color: var(--text-soft);
  font-size: 0.85rem;
  margin-top: 18px;
  font-style: italic;
}

/* ---------- «Исправить» ---------- */

.fix-block { margin-top: 18px; text-align: center; }
.fix-toggle {
  background: none;
  border: none;
  color: var(--text-soft);
  font-family: var(--font-sans);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.fix-toggle:hover { color: var(--primary-dark); }
.fix-form { margin-top: 14px; text-align: left; }
.fix-form textarea { min-height: 90px; resize: vertical; }

/* ---------- Конверсионный блок ---------- */

.conversion {
  margin-top: 26px;
  text-align: center;
  padding: 40px 32px;
  background: linear-gradient(135deg, rgba(232,195,158,.25), rgba(142,164,140,.18));
  border-radius: var(--radius);
}
.conversion h2 { margin-bottom: 8px; }
.conversion p { color: var(--text-soft); max-width: 560px; margin: 0 auto 8px; }

.cover-preview {
  width: 170px;
  margin: 26px auto 8px;
  aspect-ratio: 17 / 24;
  background: linear-gradient(160deg, #5e5245, #4A4036);
  border-radius: 6px 14px 14px 6px;
  box-shadow: -6px 0 0 rgba(74,64,54,.25), 0 16px 32px rgba(74,64,54,.3);
  color: var(--bg);
  font-family: var(--font-serif);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px 16px;
  gap: 10px;
  position: relative;
}
.cover-preview::after {
  content: "";
  position: absolute;
  left: 10px; top: 0; bottom: 0;
  width: 2px;
  background: rgba(253,251,247,.18);
}
.cover-ornament { color: var(--accent); font-size: 0.9rem; letter-spacing: .3em; }
.cover-title { font-size: 1.15rem; font-weight: 600; text-align: center; line-height: 1.3; }
.cover-sub { font-size: 0.68rem; color: rgba(253,251,247,.75); letter-spacing: .12em; text-transform: uppercase; }

/* ---------- Действия после результата ---------- */

.actions-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  margin-top: 26px;
}
@media (max-width: 680px) { .actions-grid { grid-template-columns: 1fr; } }

.action-card {
  background: #fff;
  border: 2px solid transparent;
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
  padding: 24px 22px;
  text-align: left;
  cursor: pointer;
  transition: transform .2s ease, box-shadow .2s ease, border-color .2s ease;
  font-family: var(--font-sans);
  font-size: 0.95rem;
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.action-card:hover, .action-card:focus-visible {
  transform: translateY(-3px);
  box-shadow: var(--shadow-hover);
  border-color: var(--accent);
}
.action-emoji { font-size: 1.7rem; }
.action-card h3 { font-size: 1.08rem; }
.action-card p { color: var(--text-soft); font-size: 0.88rem; }

/* ---------- Гейт (email) ---------- */

.gate-overlay {
  position: fixed;
  inset: 0;
  background: rgba(74, 64, 54, .45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
  animation: fadeIn .25s ease both;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.gate {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow-hover);
  max-width: 480px;
  width: 100%;
  padding: 34px 30px;
  animation: rise .3s ease both;
  position: relative;
}
.gate-close {
  position: absolute;
  top: 14px; right: 18px;
  background: none;
  border: none;
  font-size: 1.4rem;
  color: var(--text-soft);
  cursor: pointer;
}
.consent-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 0.82rem;
  color: var(--text-soft);
  margin: 14px 0 6px;
}
.consent-row input[type="checkbox"] {
  width: 20px; height: 20px;
  flex-shrink: 0;
  margin-top: 2px;
  accent-color: var(--secondary);
  cursor: pointer;
}
.consent-row a { color: var(--text-soft); }

/* ---------- Share / ссылка ---------- */

.share-card {
  background: var(--bg-warm);
  border-radius: var(--radius);
  padding: 28px 30px;
  margin-top: 26px;
}
.share-quote {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 1.05rem;
  margin: 12px 0 18px;
  white-space: pre-line;
}

.link-box { display: flex; gap: 10px; margin-top: 16px; }
.link-box input { flex: 1; font-size: 0.85rem; color: var(--text-soft); }
@media (max-width: 680px) { .link-box { flex-direction: column; } }

.divider {
  display: flex;
  align-items: center;
  gap: 14px;
  color: var(--text-soft);
  font-size: 0.85rem;
  margin: 26px 0;
}
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--bg-warm); }

/* ---------- Приглашение (вторая история) ---------- */

.handoff { text-align: center; padding: 48px 32px; }
.handoff-emoji { font-size: 3rem; display: block; margin-bottom: 12px; }
.handoff .warn {
  display: inline-block;
  margin-top: 18px;
  background: var(--bg-warm);
  border-radius: var(--radius-pill);
  padding: 8px 22px;
  font-weight: 700;
  color: var(--primary-dark);
  font-size: 0.95rem;
}

/* ---------- Ошибка / toast ---------- */

.error-box {
  background: rgba(217, 124, 85, .1);
  border: 2px solid rgba(217, 124, 85, .3);
  border-radius: 16px;
  padding: 18px 22px;
  margin: 20px 0;
  font-size: 0.95rem;
}

.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--text);
  color: var(--bg);
  padding: 12px 28px;
  border-radius: var(--radius-pill);
  font-size: 0.95rem;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s ease, transform .3s ease;
  z-index: 100;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Печать: только страницы книги ---------- */

@media print {
  body { background: #fff; }
  .site-header, .site-footer, .toast, .gate-overlay,
  .conversion, .actions-grid, .share-card, .fix-block,
  .btn-row, .card:not(.book-page) { display: none !important; }
  .page { max-width: none; padding: 0; }
  .book-page {
    box-shadow: none;
    border-radius: 0;
    page-break-after: always;
    padding: 40px 30px;
  }
}
