:root {
  /* М'яка, тепла палітра в дусі Duolingo */
  --bg-top: #fff7ec;
  --bg-bottom: #ffeede;
  --card-bg: #ffffff;
  --ink: #3c2a21;
  --ink-soft: #7a6a60;
  --accent: #58cc02;        /* фірмовий «duo» зелений */
  --accent-dark: #46a302;
  --accent-shadow: #3f8e00;
  --warn-bg: #fff3d6;
  --warn-border: #ffd86b;
  --radius: 26px;
  /* Безпечні зони: за замовчуванням системні env(); JS перевизначить значеннями Telegram */
  --tg-top: env(safe-area-inset-top, 0px);
  --tg-bottom: env(safe-area-inset-bottom, 0px);
  font-family: 'Nunito', 'Segoe UI', system-ui, -apple-system, sans-serif;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  height: 100%;
  overscroll-behavior: none;   /* без "гумового" відтягування / pull-to-refresh */
  /* при автопрокрутці лишаємо місце зверху під панеллю Telegram */
  scroll-padding-top: calc(var(--tg-top) + 12px);
}
body {
  overscroll-behavior: none;
  /* НЕ фіксуємо height — інакше довгий контент обрізається й не гортається */
}

body {
  min-height: 100vh;
  background: linear-gradient(165deg, var(--bg-top), var(--bg-bottom));
  background-attachment: fixed;   /* фон прив'язаний до екрана, не розтягується на довгій сторінці */
  background-repeat: no-repeat;
  color: var(--ink);
  display: flex;
  justify-content: center;
  overflow-x: hidden;
}

/* [DEBUG] тимчасова кнопка "назад" */
.debug-back {
  display: none;
  position: fixed;
  top: calc(var(--tg-top) + 4px);
  left: 8px;
  z-index: 9999;
  padding: 6px 12px;
  border: none;
  border-radius: 12px;
  background: rgba(60, 42, 33, 0.78);
  color: #fff;
  font: 700 13px/1 inherit;
  cursor: pointer;
}
.debug-back:active { transform: scale(0.95); }

/* ---------- Екран ---------- */
.screen {
  position: relative;
  width: 100%;
  max-width: 460px;
  min-height: 100vh;
  /* Відступи зверху/знизу враховують елементи Telegram (safe area) */
  padding: calc(24px + var(--tg-top)) 20px calc(32px + var(--tg-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  touch-action: pan-y;          /* блокуємо горизонтальні свайпи скрізь */
}

/* Перші екрани (стартовий і "Петро говорить") — повністю фіксовані: жодних свайпів */
.screen:not(.screen--scroll) {
  overflow: hidden;
  touch-action: none;
}

/* Декоративні «бульбашки» на фоні */
.blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(8px);
  opacity: 0.5;
  z-index: 0;
  pointer-events: none;
}
.blob--1 {
  width: 200px; height: 200px;
  background: #ffd6a5;
  top: -40px; left: -60px;
}
.blob--2 {
  width: 240px; height: 240px;
  background: #c8f7a0;
  bottom: -70px; right: -80px;
}

/* ---------- Картка ---------- */
.card {
  position: relative;
  z-index: 1;
  width: 100%;
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 26px 22px 24px;
  box-shadow: 0 18px 40px rgba(60, 42, 33, 0.12);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  animation: pop-in 0.5s cubic-bezier(0.18, 0.89, 0.32, 1.28) both;
}

/* ---------- Кіт ---------- */
.cat-wrap {
  position: relative;
  margin-top: 4px;
}
.cat {
  width: 168px;
  height: auto;
  display: block;
  filter: drop-shadow(0 10px 14px rgba(60, 42, 33, 0.18));
  animation: float 3.4s ease-in-out infinite;
}
.sparkle {
  position: absolute;
  font-size: 22px;
  animation: twinkle 2.2s ease-in-out infinite;
}
.sparkle--1 { top: 2px; right: 6px; }
.sparkle--2 { bottom: 10px; left: 0; animation-delay: 0.8s; }

/* ---------- Текст ---------- */
.title {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.5px;
}
.lead {
  font-size: 17px;
  line-height: 1.5;
  color: var(--ink-soft);
  max-width: 30ch;
}
.lead b { color: var(--ink); }

/* ---------- Попередження ---------- */
.warn {
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
  background: var(--warn-bg);
  border: 2px dashed var(--warn-border);
  border-radius: 18px;
  padding: 12px 14px;
  width: 100%;
}
.warn__emoji {
  font-size: 24px;
  flex-shrink: 0;
}
.warn p {
  font-size: 14.5px;
  line-height: 1.45;
  color: #8a6d1c;
}

/* ---------- Кнопка ---------- */
.btn {
  margin-top: 4px;
  width: 100%;
  border: none;
  border-radius: 18px;
  background: var(--accent);
  color: #fff;
  font-size: 19px;
  font-weight: 800;
  font-family: inherit;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  padding: 16px 20px;
  cursor: pointer;
  box-shadow: 0 5px 0 var(--accent-shadow);
  transition: transform 0.08s ease, box-shadow 0.08s ease, background 0.15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.btn:hover { background: var(--accent-dark); }
.btn:active,
.btn.is-pressed {
  transform: translateY(4px);
  box-shadow: 0 1px 0 var(--accent-shadow);
}
.btn__arrow {
  font-size: 20px;
  transition: transform 0.15s ease;
}
.btn:hover .btn__arrow { transform: translateX(4px); }

/* ---------- Перемикання екранів ---------- */
.screen--hidden { display: none; }

/* Анімація виходу старого екрана */
.screen--leave {
  animation: slide-out 0.34s cubic-bezier(0.4, 0, 1, 1) forwards;
}
/* Анімація входу нового екрана */
.screen--enter {
  animation: slide-in 0.42s cubic-bezier(0.18, 0.89, 0.32, 1.18) both;
}

@keyframes slide-out {
  to { opacity: 0; transform: translateX(-26px) scale(0.97); }
}
@keyframes slide-in {
  from { opacity: 0; transform: translateX(34px) scale(0.97); }
  to   { opacity: 1; transform: translateX(0) scale(1); }
}

/* ---------- Хмаринка мовлення ---------- */
.speech {
  position: relative;
  width: 100%;
  background: #f4fbe9;
  border: 2px solid #d8f0b6;
  border-radius: 18px;
  padding: 16px 18px;
  text-align: left;
  min-height: 96px;
}
/* "хвостик" хмаринки, що дивиться на кота */
.speech::before {
  content: "";
  position: absolute;
  top: -11px;
  left: 50%;
  transform: translateX(-50%);
  border-left: 11px solid transparent;
  border-right: 11px solid transparent;
  border-bottom: 11px solid #d8f0b6;
}
.speech__text {
  display: inline;
  font-size: 16px;
  line-height: 1.55;
  color: var(--ink);
}
.caret {
  display: inline-block;
  color: var(--accent-dark);
  font-weight: 700;
  animation: blink 0.9s steps(1) infinite;
}
.caret--off { display: none; }

@keyframes blink {
  0%, 50%  { opacity: 1; }
  51%, 100% { opacity: 0; }
}

/* Слово, що плавно з'являється */
.word {
  display: inline-block;
  margin-right: 0.28em;          /* пробіл між словами (inline-block з'їдає звичайний) */
  opacity: 0;
  filter: blur(3px);
  transform: translateY(4px);
  animation: word-in 0.42s ease-out both;
}
.word--pending {                  /* слово вже в DOM (резервує висоту), але ще не з'являється */
  animation: none;
}
.word--shown {                    /* миттєво показане слово (пропуск анімації) */
  opacity: 1;
  filter: none;
  transform: none;
  animation: none;
}
@keyframes word-in {
  to { opacity: 1; filter: blur(0); transform: translateY(0); }
}

/* Кіт "говорить" — м'яке, повільне дихання-похитування */
.cat--talking {
  animation: talk 2.6s ease-in-out infinite !important;
}
@keyframes talk {
  0%, 100% { transform: rotate(-1deg) translateY(0); }
  50%      { transform: rotate(1deg) translateY(-5px); }
}

/* Кнопка з'являється плавно */
.btn--hidden {
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
}
.btn--reveal {
  animation: btn-reveal 0.4s cubic-bezier(0.18, 0.89, 0.32, 1.28) forwards;
}
@keyframes btn-reveal {
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- Підказка внизу ---------- */
.hint {
  position: relative;
  z-index: 1;
  font-size: 13.5px;
  color: var(--ink-soft);
  opacity: 0.85;
  transition: opacity 0.3s ease;
}

/* ---------- Екран зі списком типів (зі скролом) ---------- */
.screen--scroll {
  justify-content: flex-start;
  gap: 10px;
  padding-top: calc(12px + var(--tg-top));
  /* Вільне місце знизу, щоб кнопки навіть під довгим текстом не липли до краю */
  padding-bottom: calc(19px + var(--tg-bottom));
}

.group {
  position: relative;
  z-index: 1;
  width: 100%;
  background: var(--card-bg);
  border-radius: 18px;
  padding: 10px 12px 12px;
  box-shadow: 0 10px 22px rgba(60, 42, 33, 0.09);
  /* акцентний колір групи (перевизначається модифікаторами) */
  --g: #58cc02;
  border-top: 4px solid var(--g);
  animation: pop-in 0.45s cubic-bezier(0.18, 0.89, 0.32, 1.28) both;
}
.group:nth-of-type(1) { animation-delay: 0.04s; }
.group:nth-of-type(2) { animation-delay: 0.12s; }
.group:nth-of-type(3) { animation-delay: 0.20s; }
.group:nth-of-type(4) { animation-delay: 0.28s; }
.group--analysts  { --g: #8b5cf6; }   /* фіолетовий */
.group--diplomats { --g: #2fb344; }   /* зелений */
.group--sentinels { --g: #1aa3b8; }   /* бірюзовий */
.group--explorers { --g: #f1b80a; }   /* жовтий */

.group__title {
  font-size: 15px;
  font-weight: 800;
  color: var(--g);
  margin-bottom: 8px;
  letter-spacing: -0.3px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 7px;
}

.type {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 3px;
  border-radius: 12px;
  background: #f7f6f4;                                  /* запасний колір */
  background: color-mix(in srgb, var(--g) 8%, #fff);   /* легкий відтінок групи */
  transition: transform 0.12s ease, filter 0.25s ease, opacity 0.25s ease, background 0.25s ease;
  cursor: pointer;
}
.type:active,
.type.is-pressed { transform: scale(0.94); }
.type img {
  width: 100%;
  max-width: 54px;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  transition: filter 0.25s ease;
}
.type figcaption {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.4px;
  color: var(--ink-soft);
}

/* Згаслий (неактивний) тип */
.type--dim {
  background: #eeece9;
  opacity: 0.55;
}
.type--dim img { filter: grayscale(1); }
.type--dim figcaption { color: #b6afa8; }

/* ---------- Блок питання ---------- */
.question {
  position: relative;
  z-index: 1;
  width: 100%;
  background: var(--card-bg);
  border-radius: 18px;
  padding: 16px 16px 18px;
  box-shadow: 0 10px 26px rgba(60, 42, 33, 0.12);
  text-align: center;
  margin-top: 2px;
}
.question__text {
  font-size: 19px;
  font-weight: 800;
  color: var(--ink);
  margin-bottom: 14px;
  letter-spacing: -0.3px;
}

/* Опис типу всередині блоку питання */
.desc {
  text-align: left;
  background: #f4fbe9;
  border: 2px solid #d8f0b6;
  border-radius: 14px;
  padding: 12px 14px;
  margin-bottom: 14px;
  animation: pop-in 0.35s ease both;
}
.desc__text {
  font-size: 15.5px;
  line-height: 1.5;
  color: var(--ink);
}
.desc__note {
  margin-top: 8px;
  font-size: 12px;
  font-style: italic;
  color: #b08900;
}

/* Фінальний результат */
.question--final .question__text {
  font-size: 22px;
}
/* На екрані результату ховаємо список типів — лишається тільки кіт і напис */
.result-only .group { display: none; }
.result-only { justify-content: center; }   /* картку результату — по центру */

/* Плавна поява картки результату */
.question--final {
  animation: result-in 0.5s cubic-bezier(0.18, 0.89, 0.32, 1.18) both;
}
@keyframes result-in {
  from { opacity: 0; transform: translateY(18px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.result-img {
  display: block;
  width: 150px;
  height: auto;
  margin: 0 auto 10px;
  filter: drop-shadow(0 10px 14px rgba(60, 42, 33, 0.18));
  animation: float 3.4s ease-in-out infinite;
}
.result-img[hidden] { display: none; }   /* інакше display:block перебиває hidden */

.result-type {
  display: block;
  font-size: 32px;
  font-weight: 800;
  letter-spacing: 1px;
  color: var(--accent-dark);
  margin: 8px 0 4px;
}
.answers {
  display: flex;
  gap: 12px;
}
.answers .btn {
  flex: 1 1 0;
  min-width: 0;                   /* дозволяємо кнопці стискатися в межах ряду */
  margin: 0;
  padding-left: 12px;
  padding-right: 12px;
  text-transform: none;          /* варіанти відповіді можуть бути словами, не капсом */
  font-size: 16px;
  line-height: 1.2;
  white-space: normal;           /* довгий підпис переноситься, а не вилазить за екран */
  overflow-wrap: anywhere;
}
.answers .btn--sm { font-size: 13px; }   /* трохи менший шрифт для довгих підписів */

/* ---------- Список вибору (3 етап) ---------- */
.choices {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.choices[hidden] { display: none; }   /* інакше display:flex перебиває hidden */

/* Картки перегляду типів групи (короткі описи) */
.browse-card {
  border: 2px solid #d8f0b6;
  border-radius: 16px;
  background: #f4fbe9;
  color: var(--ink);
  font: 600 14.5px/1.45 inherit;
  text-align: left;
  padding: 12px 14px;
  cursor: pointer;
  transition: transform 0.08s ease, background 0.15s ease, border-color 0.15s ease;
}
.browse-card:hover { background: #ecf7da; }
.browse-card:active,
.browse-card.is-pressed { transform: scale(0.98); }
.browse-card--spent {
  background: #eeece9;
  border-color: #ddd9d4;
  color: #b6afa8;
  cursor: default;
}
.browse-none { margin-top: 2px; }
.choice {
  display: flex;
  align-items: stretch;
  gap: 8px;
}
.choice__pick {
  flex: 1;
  border: none;
  border-radius: 16px;
  background: var(--accent);
  color: #fff;
  font: 800 17px/1.2 inherit;
  padding: 14px 16px;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--accent-shadow);
  transition: transform 0.08s ease, box-shadow 0.08s ease, background 0.15s ease;
}
.choice__pick:hover { background: var(--accent-dark); }
.choice__pick:active,
.choice__pick.is-pressed {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--accent-shadow);
}
.choice__info {
  flex: 0 0 auto;
  width: 46px;
  border: none;
  border-radius: 16px;
  background: #ffe0a3;
  color: #8a6d1c;
  font: 800 20px/1 inherit;
  cursor: pointer;
  transition: transform 0.08s ease, background 0.15s ease;
}
.choice__info:hover { background: #ffd486; }
.choice__info:active,
.choice__info.is-pressed { transform: scale(0.92); }

/* ---------- Попап з описом ---------- */
.popup {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(30, 20, 14, 0.5);
  animation: fade-in 0.18s ease both;
}
.popup[hidden] { display: none; }
.popup__card {
  width: 100%;
  max-width: 340px;
  background: var(--card-bg);
  border-radius: 22px;
  padding: 22px 20px 20px;
  text-align: center;
  box-shadow: 0 18px 40px rgba(60, 42, 33, 0.25);
  animation: pop-in 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28) both;
}
.popup__title {
  font-size: 22px;
  font-weight: 800;
  margin-bottom: 10px;
  color: var(--ink);
}
.popup__text {
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink-soft);
  margin-bottom: 18px;
}
.popup__close { width: 100%; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

/* Примітка про відсоток схожості під довгим описом */
.pct-note {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  background: #fff3d6;
  border: 1px dashed #ffd86b;
  font-size: 13.5px;
  line-height: 1.45;
  color: #8a6d1c;
}
.btn--green {
  background: var(--accent);
  box-shadow: 0 5px 0 var(--accent-shadow);
}
.btn--green:hover { background: var(--accent-dark); }
.btn--red {
  background: #ff6b6b;
  box-shadow: 0 5px 0 #d6453f;
}
.btn--red:hover { background: #f1564f; }
.btn--blue {
  background: #3aa0ff;
  box-shadow: 0 5px 0 #2b7bcc;
}
.btn--blue:hover { background: #2e90ee; }

/* Уже відхилений варіант уточнення */
.btn--spent {
  background: #d6d2cd !important;
  box-shadow: 0 5px 0 #b8b3ad !important;
  color: #fff;
  opacity: 0.7;
  cursor: default;
  pointer-events: none;
}

/* ---------- Анімації ---------- */
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-10px); }
}
@keyframes twinkle {
  0%, 100% { transform: scale(1) rotate(0); opacity: 1; }
  50%      { transform: scale(1.3) rotate(15deg); opacity: 0.6; }
}
@keyframes pop-in {
  from { opacity: 0; transform: translateY(20px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  .cat, .sparkle, .card { animation: none; }
}
