/* Живые мелочи (interactive.js): кнопка 🔊, «отметьте, что про вас»,
   мини-задание. Отдельным файлом — у CSS на сайте кеш 4 часа. */

/* ---------- 1. Кнопка «послушать» ---------- */

.say-btn {
  position: relative;
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 32px;
  height: 32px;
  margin: -4px 0 -4px 8px;
  padding: 0;
  vertical-align: middle;
  color: var(--blue);
  background: var(--lavender);
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  font: inherit;
  line-height: 0;
  transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}

/* Зона нажатия 44px при визуальном размере 32px. */
.say-btn::after {
  content: "";
  position: absolute;
  inset: -6px;
}

.say-btn svg {
  width: 17px;
  height: 17px;
}

.say-btn:hover {
  transform: scale(1.08);
}

.say-btn:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

.say-btn.is-speaking {
  color: #fff;
  background: var(--blue);
  animation: say-pulse 1s ease-in-out infinite;
}

@keyframes say-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(74, 99, 216, 0.35); }
  50% { box-shadow: 0 0 0 7px rgba(74, 99, 216, 0); }
}

/* В таблице фраз колонка узкая: кнопка всегда отдельной строкой под фразой,
   а не «где получится» после последнего слова. Фон таблицы лавандовый. */
.phrase-table td.is-phrase .say-btn {
  display: grid;
  margin: 8px 0 0;
  background: #fff;
}

/* Внутри мелкого текста кнопка чуть компактнее по вертикали. */
.mini-examples .say-btn,
.phrase-list .say-btn {
  width: 28px;
  height: 28px;
}

.mini-examples .say-btn svg,
.phrase-list .say-btn svg {
  width: 15px;
  height: 15px;
}

.mini-examples .say-btn::after,
.phrase-list .say-btn::after {
  inset: -8px;
}

.mini-examples span {
  display: flex !important;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.mini-examples span .say-btn {
  margin: 0;
}

/* ---------- 2. «Отметьте, что про вас» ---------- */

.pain-hint {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 14px;
  color: var(--blue);
  font-size: 14px;
  font-weight: 800;
}

.pain-hint::before {
  content: "";
  width: 18px;
  height: 18px;
  border: 2px solid currentColor;
  border-radius: 6px;
}

.good-for .pain-grid article[role="checkbox"] {
  position: relative;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease, opacity 0.2s ease;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.good-for .pain-grid article[role="checkbox"]:hover {
  transform: translateY(-3px);
  box-shadow: 0 14px 30px rgba(24, 49, 80, 0.08);
}

.good-for .pain-grid article[role="checkbox"]:focus-visible {
  outline: 3px solid var(--blue);
  outline-offset: 3px;
}

.good-for .pain-grid article[aria-checked="true"] {
  border-color: var(--blue);
  box-shadow: inset 0 0 0 1px var(--blue);
}

.pain-tick {
  position: absolute;
  top: 22px;
  right: 22px;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  background: #fff;
  border: 2px solid var(--line);
  border-radius: 10px;
  transition: background 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}

.pain-tick::after {
  content: "";
  width: 11px;
  height: 6px;
  margin-top: -3px;
  border-left: 3px solid #fff;
  border-bottom: 3px solid #fff;
  transform: rotate(-45deg) scale(0);
  transition: transform 0.2s ease;
}

[aria-checked="true"] > .pain-tick {
  background: var(--blue);
  border-color: var(--blue);
  transform: scale(1.06);
}

[aria-checked="true"] > .pain-tick::after {
  transform: rotate(-45deg) scale(1);
}

.pain-result {
  display: none;
  margin-top: 18px;
}

.pain-result.is-visible {
  display: block;
  animation: pain-in 0.3s ease both;
}

.pain-result-text {
  margin: 0;
  color: var(--soft);
  font-size: 15px;
  font-weight: 700;
}

.pain-result.is-match {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  gap: 18px;
  align-items: center;
  padding: 22px 24px;
  background: var(--ink);
  border-radius: 22px;
  color: #fff;
}

.pain-result-mascot {
  width: 72px;
  height: auto;
  margin: -10px 0;
  animation: pain-hop 0.6s ease 0.1s both;
}

.pain-result-title {
  margin: 0 0 12px;
  font-family: var(--font-display);
  font-size: 21px;
  font-weight: 800;
  line-height: 1.2;
  letter-spacing: -0.01em;
}

.pain-result-actions {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.pain-result-actions strong {
  font-size: 24px;
  white-space: nowrap;
  letter-spacing: -0.02em;
}

.pain-result-buy {
  min-height: 50px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 12px 20px;
  color: var(--ink);
  background: #fff;
  border: 0;
  border-radius: 14px;
  cursor: pointer;
  font: inherit;
  font-size: 14px;
  font-weight: 900;
  white-space: nowrap;
  transition: transform 0.2s ease;
}

.pain-result-buy:hover {
  transform: translateY(-2px);
}

.pain-result-buy.book-added {
  color: #fff;
  background: #2f8d76;
}

.pain-result-more {
  min-height: 44px;
  margin-top: 4px;
  padding: 0;
  color: rgba(255, 255, 255, 0.8);
  background: none;
  border: 0;
  cursor: pointer;
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
}

@keyframes pain-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

@keyframes pain-hop {
  0% { transform: translateY(10px) scale(0.8); opacity: 0; }
  60% { transform: translateY(-6px) scale(1.05); opacity: 1; }
  100% { transform: none; }
}

/* ---------- 3. Мини-задание ---------- */

.mini-task {
  margin-top: 22px;
  padding: 16px;
  background: rgba(255, 255, 255, 0.82);
  border-radius: 14px;
}

.inside-grid .mini-task {
  margin-top: 16px;
  background: var(--mint);
}

.mini-task-q {
  margin: 0 0 12px;
  color: var(--ink);
  font-size: 15px;
  font-weight: 800;
  line-height: 1.45;
}

.mini-task-gap {
  display: inline-block;
  min-width: 3.2em;
  padding: 0 4px;
  color: var(--blue);
  border-bottom: 2px dashed var(--blue);
  text-align: center;
}

.mini-task-gap.is-filled {
  border-bottom-style: solid;
  animation: pain-in 0.25s ease both;
}

.is-missed .mini-task-gap.is-filled {
  color: #2f8d76;
  border-color: #2f8d76;
}

.mini-task-options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.mini-task-options button {
  flex: 1 1 auto;
  min-height: 44px;
  padding: 8px 14px;
  color: var(--ink);
  background: #fff;
  border: 2px solid var(--line);
  border-radius: 12px;
  cursor: pointer;
  font: inherit;
  font-size: 15px;
  font-weight: 800;
  transition: border-color 0.2s ease, background 0.2s ease, transform 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}

.mini-task-options button:not(:disabled):hover {
  border-color: var(--blue);
  transform: translateY(-2px);
}

.mini-task-options button:disabled {
  cursor: default;
  opacity: 0.55;
}

.mini-task-options button.is-right {
  color: #fff;
  background: #2f8d76;
  border-color: #2f8d76;
  opacity: 1;
}

.mini-task-options button.is-wrong {
  color: #a3412f;
  background: #fbe3dd;
  border-color: #e2988a;
  opacity: 1;
}

.is-solved .mini-task-options button.is-right {
  animation: pain-hop 0.45s ease both;
}

.mini-task-why {
  margin: 12px 0 0;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.5;
  animation: pain-in 0.3s ease both;
}

.mini-task-why b {
  color: #2f8d76;
}

.is-missed .mini-task-why b {
  color: #a3412f;
}

/* ---------- Телефон ---------- */

@media (max-width: 600px) {
  .pain-tick {
    top: 18px;
    right: 18px;
  }

  .good-for .pain-grid article[role="checkbox"]:hover {
    transform: none;
    box-shadow: none;
  }

  .good-for .pain-grid article[aria-checked="true"] {
    box-shadow: inset 0 0 0 1px var(--blue);
  }

  /* Карточки-галочки на телефоне компактнее: четыре штуки подряд
     занимали больше экрана, и итог под ними было не видно. */
  .good-for .pain-grid article[role="checkbox"] {
    min-height: 0;
    padding: 22px 64px 22px 22px;
  }

  .good-for .pain-grid article[role="checkbox"] h3 {
    margin-top: 14px;
    font-size: 21px;
  }

  /* Узко: монстрик и заголовок в строку, цена с кнопкой — во всю ширину. */
  .pain-result.is-match {
    grid-template-columns: 52px minmax(0, 1fr);
    gap: 4px 14px;
    padding: 18px;
  }

  .pain-result-body {
    display: contents;
  }

  .pain-result-mascot {
    width: 52px;
    margin: -14px 0 -6px;
  }

  .pain-result-title {
    margin: 0;
    font-size: 18px;
  }

  .pain-result-actions {
    grid-column: 1 / -1;
    flex-wrap: nowrap;
    gap: 12px;
    margin-top: 12px;
  }

  .pain-result-more {
    grid-column: 1 / -1;
    justify-self: start;
  }

  .pain-result-actions strong {
    font-size: 21px;
  }

  .pain-result-buy {
    flex: 1;
    padding: 12px 14px;
  }
}

@media (max-width: 360px) {
  .pain-result-actions {
    flex-wrap: wrap;
  }

  .pain-result-buy {
    flex-basis: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .say-btn,
  .say-btn.is-speaking,
  .pain-result.is-visible,
  .pain-result-mascot,
  .mini-task-gap.is-filled,
  .is-solved .mini-task-options button.is-right,
  .mini-task-why {
    animation: none;
    transition: none;
  }
}

/* =====================================================================
   Приятные мелочи: монстрик, «До → После», цитата, игра на 404, оплата
   ===================================================================== */

/* ---------- Монстрик отвечает ---------- */

.mascot-tap {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

.mascot-tap:focus-visible {
  outline: 3px solid #9db0ff;
  outline-offset: 4px;
  border-radius: 12px;
}

/* translate/scale/rotate отдельными свойствами: у картинок уже есть свой
   transform (например, центрирование), анимация его не перетирает. */
.mascot-hop {
  animation: mascot-hop 0.55s ease;
}

.mascot-shake {
  animation: mascot-shake 0.45s ease;
}

@keyframes mascot-hop {
  0%, 100% { translate: 0 0; scale: 1; }
  35% { translate: 0 -16px; scale: 1.04 0.97; }
  60% { translate: 0 0; scale: 1.02 0.98; }
  80% { translate: 0 -4px; scale: 1; }
}

@keyframes mascot-shake {
  0%, 100% { rotate: 0deg; }
  20% { rotate: -7deg; }
  45% { rotate: 6deg; }
  70% { rotate: -3deg; }
}

.mascot-bubble {
  position: absolute;
  z-index: 60;
  max-width: min(280px, calc(100vw - 24px));
  padding: 11px 15px 12px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 14px 30px rgba(24, 49, 80, 0.22);
  pointer-events: none;
  animation: bubble-in 0.22s ease both;
}

.mascot-bubble::after {
  content: "";
  position: absolute;
  bottom: -6px;
  left: clamp(18px, var(--tail, 50%), calc(100% - 18px));
  width: 14px;
  height: 14px;
  background: inherit;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  border-radius: 0 0 3px 0;
  transform: translateX(-50%) rotate(45deg);
}

.mascot-bubble b {
  display: block;
  font-size: 15px;
  font-weight: 900;
  line-height: 1.3;
}

.mascot-bubble small {
  display: block;
  margin-top: 3px;
  color: var(--soft);
  font-size: 13px;
  line-height: 1.4;
}

.mascot-bubble.is-leaving {
  opacity: 0;
  translate: 0 6px;
  transition: opacity 0.25s ease, translate 0.25s ease;
}

@keyframes bubble-in {
  from { opacity: 0; translate: 0 8px; scale: 0.94; }
  to { opacity: 1; translate: 0 0; scale: 1; }
}

/* ---------- «До → После» ---------- */

.method-result.is-interactive > div {
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.method-result.is-interactive > div:last-of-type {
  opacity: 0.45;
}

.method-result.is-interactive > p {
  transition: color 0.3s ease;
}

.method-result.is-done > div:first-of-type {
  opacity: 0.55;
}

.method-result.is-done > div:last-of-type {
  opacity: 1;
  animation: after-pop 0.5s ease;
}

.method-result.is-done > div:last-of-type strong {
  color: #2f8d76;
}

.method-result.is-done > p {
  color: var(--ink);
}

@keyframes after-pop {
  0% { transform: scale(0.94); }
  60% { transform: scale(1.05); }
  100% { transform: scale(1); }
}

.method-run {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 5px;
  min-width: 132px;
  min-height: 72px;
  padding: 10px 16px 12px;
  color: #fff;
  background: var(--blue);
  border: 0;
  border-radius: 18px;
  box-shadow: 0 12px 25px rgba(88, 115, 232, 0.24);
  cursor: pointer;
  font: inherit;
  transition: transform 0.2s ease, background 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}

.method-run:hover:not(:disabled) {
  transform: translateY(-2px);
}

.method-run:disabled {
  cursor: default;
}

.method-run i {
  font-style: normal;
}

.method-run-arrow {
  font-size: 22px;
  font-weight: 900;
  line-height: 1;
}

.method-run-label {
  font-size: 13px;
  font-weight: 900;
}

.method-run-bar {
  width: 100%;
  height: 4px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.25);
  border-radius: 4px;
}

.method-run-bar i {
  display: block;
  width: 0;
  height: 100%;
  background: #fff;
  border-radius: inherit;
}

.is-running .method-run-bar i {
  width: 100%;
  transition: width 1.56s linear;
}

.is-done .method-run-bar i {
  width: 100%;
}

.is-done .method-run {
  background: #2f8d76;
  box-shadow: 0 12px 25px rgba(47, 141, 118, 0.24);
}

@media (max-width: 860px) {
  .method-run {
    justify-self: center;
  }

  .method-run-arrow {
    rotate: 90deg;
  }
}

/* ---------- Цитата переворачивается ---------- */

.quote-faces {
  position: relative;
  z-index: 2;
  display: grid;
  width: 100%;
  max-width: 850px;
  perspective: 1400px;
}

.quote-face {
  grid-area: 1 / 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  transition: transform 0.6s cubic-bezier(0.3, 0.7, 0.2, 1), opacity 0.3s ease;
}

.quote-back {
  transform: rotateY(180deg);
  opacity: 0;
}

.is-flipped .quote-front {
  transform: rotateY(-180deg);
  opacity: 0;
}

.is-flipped .quote-back {
  transform: rotateY(0deg);
  opacity: 1;
}

/* Раньше это были прямые потомки .quote-band — повторяем их стиль. */
.quote-face > p {
  margin: 0 0 18px;
  color: #9db0ff;
  font-size: 14px;
  font-weight: 900;
}

.quote-face > span {
  margin-top: 24px;
  color: #aeb9c8;
  font-size: 11px;
}

.quote-back h2 {
  max-width: 660px;
  font-size: clamp(24px, 3.2vw, 38px);
}

.quote-parse {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin: 22px 0 0;
  padding: 0;
  list-style: none;
}

.quote-parse li {
  padding: 8px 12px;
  color: #dfe5ff;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  font-size: 13px;
}

.quote-parse b {
  color: #fff;
}

.quote-toggle {
  position: relative;
  z-index: 3;
  min-height: 44px;
  margin-top: 22px;
  padding: 10px 18px;
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 999px;
  cursor: pointer;
  font: inherit;
  font-size: 14px;
  font-weight: 800;
  transition: background 0.2s ease;
}

@media (max-width: 860px) {
  /* Место над монстриком под его реплику, чтобы она не закрывала кнопку. */
  .quote-band > img.mascot-tap {
    margin-top: 64px;
  }
}

.quote-toggle:hover {
  background: rgba(255, 255, 255, 0.18);
}

@media (max-width: 600px) {
  .quote-back h2 {
    font-size: 24px;
  }

  .quote-parse {
    flex-direction: column;
    align-items: center;
  }
}

/* ---------- Игра на 404 ---------- */

.article-game {
  max-width: 560px;
  margin-top: -20px;
}

.ag-head {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 18px;
}

.ag-mascot {
  width: 64px;
  height: auto;
  flex: none;
}

.ag-head .kicker {
  margin: 0 0 4px;
}

.ag-head h2 {
  margin: 0;
  font-size: 30px;
  line-height: 1.1;
}

.ag-card {
  padding: 22px;
  background: var(--lavender);
  border-radius: 22px;
}

.ag-progress {
  margin: 0;
  color: var(--blue);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.08em;
}

.ag-word {
  margin: 8px 0 16px;
  color: var(--ink);
  font-family: var(--font-display);
  font-size: 36px;
  font-weight: 800;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.ag-gap {
  display: inline-block;
  min-width: 2.4em;
  color: var(--blue);
  border-bottom: 3px dashed var(--blue);
  text-align: center;
}

.ag-gap.is-filled {
  border-bottom-style: solid;
}

.ag-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.ag-options button {
  min-height: 52px;
  color: var(--ink);
  background: #fff;
  border: 2px solid transparent;
  border-radius: 14px;
  cursor: pointer;
  font: inherit;
  font-size: 18px;
  font-weight: 900;
  transition: transform 0.2s ease, border-color 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}

.ag-options button:hover:not(:disabled) {
  border-color: var(--blue);
  transform: translateY(-2px);
}

.ag-options button:disabled {
  cursor: default;
  opacity: 0.5;
}

.ag-options button.is-right {
  color: #fff;
  background: #2f8d76;
  opacity: 1;
}

.ag-options button.is-wrong {
  color: #a3412f;
  background: #fbe3dd;
  border-color: #e2988a;
  opacity: 1;
}

.ag-why {
  margin: 14px 0 0;
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
}

.ag-why:empty {
  display: none;
}

.ag-why b {
  color: #2f8d76;
}

.ag-why.is-wrong b {
  color: #a3412f;
}

.ag-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 18px;
  margin-top: 14px;
}

.ag-foot:empty {
  display: none;
}

.ag-next {
  min-height: 48px;
  padding: 10px 20px;
  color: #fff;
  background: var(--blue);
  border: 0;
  border-radius: 14px;
  cursor: pointer;
  font: inherit;
  font-size: 15px;
  font-weight: 900;
}

.ag-link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  color: var(--blue);
  font-weight: 800;
  text-decoration: none;
}

.ag-link:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

@media (max-width: 600px) {
  .ag-card {
    padding: 18px;
  }

  .ag-word {
    font-size: 30px;
  }

  .ag-head h2 {
    font-size: 26px;
  }
}

/* ---------- После оплаты ---------- */

.order-mascot {
  position: relative;
  width: 84px;
  margin: 0 auto 8px;
}

.order-mascot img {
  display: block;
  width: 84px;
  height: auto;
}

.order-mascot span {
  position: absolute;
  right: -6px;
  bottom: 8px;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  color: #fff;
  background: #2f8d76;
  border: 3px solid var(--cream);
  border-radius: 50%;
  font-size: 14px;
  font-weight: 900;
  animation: after-pop 0.5s ease 0.3s both;
}

.order-tip {
  margin: 22px auto 0;
  max-width: 420px;
  padding: 14px 16px;
  color: var(--ink);
  background: var(--mint);
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.5;
}

.confetti {
  position: fixed;
  inset: 0;
  z-index: 70;
  overflow: hidden;
  pointer-events: none;
}

.confetti i {
  position: absolute;
  top: -16px;
  width: 9px;
  height: 14px;
  border-radius: 2px;
  opacity: 0.95;
  animation-name: confetti-fall;
  animation-timing-function: cubic-bezier(0.25, 0.6, 0.4, 1);
  animation-fill-mode: forwards;
}

@keyframes confetti-fall {
  0% { translate: 0 0; rotate: 0deg; opacity: 1; }
  85% { opacity: 1; }
  100% { translate: var(--drift, 0) 105vh; rotate: var(--spin, 540deg); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .mascot-hop,
  .mascot-shake,
  .mascot-bubble,
  .method-result.is-done > div:last-of-type,
  .order-mascot span {
    animation: none;
  }

  .quote-face,
  .method-result.is-interactive > div {
    transition: none;
  }
}
