/* =========================================================
   Переменные — цвета, шрифты, анимации
   ========================================================= */

:root {
  --bg: #faf8f5;
  --bg-soft: #f4efe8;
  --card: #ffffff;
  --text: #353535;
  --text-muted: #777777;
  --accent: #9b7eb8;
  --accent-soft: #e8dff2;
  --warm: #f4e3d7;
  --warm-deep: #e8cbb8;
  --success: #6b8f71;
  --success-soft: #e8f0e9;
  --hint: #8a735f;
  --hint-soft: #f7efe8;
  --border: rgba(53, 53, 53, 0.08);
  --shadow: 0 12px 40px rgba(80, 60, 90, 0.08);
  --shadow-soft: 0 4px 18px rgba(80, 60, 90, 0.05);
  --radius: 20px;
  --radius-sm: 14px;
  --font-body: "Manrope", "Segoe UI", system-ui, sans-serif;
  --font-display: "Cormorant Garamond", "Palatino Linotype", "Book Antiqua", Georgia, serif;
  --space: clamp(1rem, 4vw, 1.5rem);
  --max: 28rem;
  --transition: 220ms ease;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* =========================================================
   База
   ========================================================= */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.55;
  color: var(--text);
  background:
    radial-gradient(ellipse 120% 80% at 50% -20%, var(--accent-soft) 0%, transparent 55%),
    radial-gradient(ellipse 90% 60% at 100% 100%, var(--warm) 0%, transparent 45%), var(--bg);
  background-attachment: fixed;
}

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

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

button:disabled {
  cursor: default;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.app {
  min-height: 100dvh;
  min-height: 100svh;
  display: flex;
  justify-content: center;
  padding: calc(1.25rem + var(--safe-top)) var(--space) calc(1.75rem + var(--safe-bottom));
}

/* =========================================================
   Экраны и переходы
   ========================================================= */

.screen {
  width: min(100%, var(--max));
  margin: auto;
}

.screen[hidden] {
  display: none !important;
}

.screen.is-entering {
  animation: screen-in 420ms ease both;
}

@keyframes screen-in {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* =========================================================
   Приветствие
   ========================================================= */

.welcome-card {
  background: var(--card);
  border-radius: calc(var(--radius) + 4px);
  box-shadow: var(--shadow);
  padding: clamp(1.75rem, 6vw, 2.4rem) clamp(1.35rem, 5vw, 2rem);
  text-align: center;
  border: 1px solid var(--border);
}

.welcome-ornament {
  width: 4.25rem;
  height: 4.25rem;
  margin: 0 auto 1.1rem;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--accent);
  background: linear-gradient(160deg, var(--accent-soft), var(--warm));
}

.welcome-icon {
  width: 2.35rem;
  height: 2.35rem;
}

.welcome-eyebrow {
  margin: 0 0 0.55rem;
  font-size: 0.78rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 600;
}

.welcome-title {
  margin: 0 0 0.85rem;
  font-family: var(--font-display);
  font-size: clamp(1.85rem, 7.2vw, 2.45rem);
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: -0.01em;
  color: var(--text);
}

.welcome-lead {
  margin: 0 0 0.75rem;
  color: var(--text);
  font-size: 1.05rem;
}

.welcome-text {
  margin: 0 0 1.75rem;
  color: var(--text-muted);
  font-size: 0.95rem;
}

/* =========================================================
   Кнопки
   ========================================================= */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 3.1rem;
  width: 100%;
  padding: 0.85rem 1.25rem;
  border: none;
  border-radius: 999px;
  font-weight: 600;
  font-size: 1rem;
  transition:
    background-color var(--transition),
    color var(--transition),
    transform var(--transition),
    box-shadow var(--transition);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 8px 22px rgba(155, 126, 184, 0.28);
}

.btn-primary:hover {
  background: #8d70ab;
}

.btn-primary:active {
  transform: scale(0.98);
}

/* =========================================================
   Квест
   ========================================================= */

.quiz-shell {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.progress-block {
  padding: 0 0.15rem;
}

.progress-label {
  margin: 0 0 0.55rem;
  font-size: 0.86rem;
  color: var(--text-muted);
  font-weight: 500;
}

.progress-track {
  height: 4px;
  border-radius: 999px;
  background: rgba(155, 126, 184, 0.16);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), #c4a8db);
  transition: width 380ms ease;
}

.question-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  padding: 1.25rem 1.15rem 1.35rem;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.question-card.is-swapping {
  animation: card-swap 360ms ease both;
}

@keyframes card-swap {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.question-meta {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 0.85rem;
}

.lang-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.4rem;
  padding: 0.22rem 0.55rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--accent);
  background: var(--accent-soft);
}

.text-block {
  margin-bottom: 1.1rem;
}

.text-block-machine {
  padding: 0.9rem 0.95rem;
  border-radius: var(--radius-sm);
  background: linear-gradient(180deg, var(--warm) 0%, #faf4ee 100%);
  border: 1px solid rgba(232, 203, 184, 0.55);
}

.block-label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin: 0 0 0.45rem;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.block-icon {
  display: inline-flex;
  color: var(--accent);
  opacity: 0.85;
}

.original-text {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1.25rem, 4.8vw, 1.45rem);
  font-style: italic;
  line-height: 1.35;
  color: var(--text);
}

.machine-text {
  margin: 0;
  font-size: 1rem;
  color: var(--text);
  opacity: 0.92;
}

.answers-block {
  margin-top: 0.35rem;
}

.answers-label {
  margin-bottom: 0.7rem;
}

.answers {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.answer-btn {
  width: 100%;
  min-height: 3.2rem;
  text-align: left;
  padding: 0.95rem 1.05rem;
  border-radius: var(--radius-sm);
  border: 1.5px solid rgba(155, 126, 184, 0.22);
  background: #fcfbfa;
  color: var(--text);
  font-size: 0.98rem;
  line-height: 1.4;
  transition:
    border-color var(--transition),
    background-color var(--transition),
    color var(--transition),
    transform var(--transition),
    box-shadow var(--transition),
    opacity var(--transition);
  overflow-wrap: anywhere;
  word-break: break-word;
}

.answer-btn:active:not(:disabled) {
  transform: scale(0.985);
}

.answer-btn:hover:not(:disabled) {
  border-color: rgba(155, 126, 184, 0.45);
  background: #fff;
}

.answer-btn.is-wrong {
  animation: soft-shake 380ms ease;
  border-color: rgba(138, 115, 95, 0.35);
  background: var(--hint-soft);
}

.answer-btn.is-correct {
  border-color: rgba(107, 143, 113, 0.55);
  background: var(--success-soft);
  box-shadow: 0 0 0 3px rgba(107, 143, 113, 0.12);
  animation: correct-glow 480ms ease;
}

.answer-btn.is-muted {
  opacity: 0.45;
}

@keyframes soft-shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-3px);
  }
  75% {
    transform: translateX(3px);
  }
}

@keyframes correct-glow {
  from {
    transform: scale(0.985);
  }
  to {
    transform: scale(1);
  }
}

.feedback {
  margin: 0.9rem 0 0;
  padding: 0.75rem 0.9rem;
  border-radius: 12px;
  font-size: 0.92rem;
  line-height: 1.4;
  animation: feedback-in 280ms ease both;
}

.feedback.is-hint {
  color: var(--hint);
  background: var(--hint-soft);
}

.feedback.is-success {
  color: var(--success);
  background: var(--success-soft);
}

@keyframes feedback-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* =========================================================
   Финал
   ========================================================= */

.screen-finale {
  position: relative;
}

.finale-card {
  position: relative;
  z-index: 1;
  background: var(--card);
  border-radius: calc(var(--radius) + 6px);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  padding: clamp(2rem, 7vw, 2.75rem) clamp(1.35rem, 5vw, 2rem);
  text-align: center;
  overflow: hidden;
}

.finale-glow {
  position: absolute;
  inset: -20% -10% auto;
  height: 55%;
  margin: 0;
  background: radial-gradient(ellipse at center, rgba(232, 223, 242, 0.9), transparent 70%);
  pointer-events: none;
}

.finale-title {
  position: relative;
  margin: 0 0 1.25rem;
  font-family: var(--font-display);
  font-size: clamp(1.85rem, 7.2vw, 2.45rem);
  font-weight: 600;
  line-height: 1.2;
}

.finale-body {
  position: relative;
  margin: 0 auto 0.25rem;
  max-width: 22rem;
}

.finale-message {
  margin: 0 0 1rem;
  color: var(--text-muted);
  font-size: 1.02rem;
  line-height: 1.65;
}

.finale-message:last-child {
  margin-bottom: 0;
}

.finale-body + .finale-photo {
  margin-top: 1.6rem;
}

.finale-photo {
  position: relative;
  margin: 0 auto;
  width: min(100%, 16.5rem);
  border-radius: 18px;
  overflow: hidden;
  background: var(--warm);
  box-shadow: var(--shadow-soft);
  aspect-ratio: 4 / 5;
}

.finale-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.photo-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.65rem;
  padding: 1.25rem;
  color: #a58b78;
  background: linear-gradient(160deg, var(--warm), #faf6f1 60%, var(--accent-soft));
}

.photo-placeholder span {
  font-size: 0.88rem;
  max-width: 10rem;
  line-height: 1.35;
}

.finale-decor {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}

.spark {
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: var(--size);
  height: var(--size);
  border-radius: 50%;
  background: var(--accent);
  opacity: 0;
  box-shadow: 0 0 10px rgba(155, 126, 184, 0.45);
  animation: sparkle 3.8s ease-in-out var(--delay) infinite;
}

.spark:nth-child(odd) {
  background: var(--warm-deep);
  box-shadow: 0 0 10px rgba(232, 203, 184, 0.55);
}

@keyframes sparkle {
  0%,
  100% {
    opacity: 0;
    transform: scale(0.6);
  }
  40%,
  60% {
    opacity: 0.55;
    transform: scale(1);
  }
}

/* =========================================================
   Адаптив
   ========================================================= */

@media (min-width: 720px) {
  .app {
    padding-top: calc(2.5rem + var(--safe-top));
    padding-bottom: calc(2.5rem + var(--safe-bottom));
  }

  :root {
    --max: 30rem;
  }

  .question-card {
    padding: 1.5rem 1.45rem 1.6rem;
  }
}

/* =========================================================
   Уменьшенная анимация
   ========================================================= */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .progress-fill {
    transition: none;
  }

  .spark {
    opacity: 0.35;
    animation: none;
  }
}
