:root {
  --bg: #faf5ea;
  --surface: #ffffff;
  --ink: #1f2a44;
  --muted: #5f6a85;
  --line: #e6ddc9;
  --primary: #3557d4;
  --primary-ink: #ffffff;
  --primary-soft: #e6ebff;
  --sun: #f2ae1c;
  --sun-soft: #fff1cc;
  --ok: #157f54;
  --ok-soft: #dcf5e9;
  --miss: #c93a26;
  --miss-soft: #fde5e0;
  --hint: #8f5b00;
  --gap: #e9e2d2;
  --radius: 18px;
  --shadow: 0 1px 2px rgba(31, 42, 68, 0.06), 0 6px 20px rgba(31, 42, 68, 0.06);
  --ui: ui-rounded, "Nunito", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  --verse: "PT Serif", Georgia, "Times New Roman", serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141927;
    --surface: #1d2335;
    --ink: #eef0f7;
    --muted: #a0a9c2;
    --line: #2e3650;
    --primary: #8ea2ff;
    --primary-ink: #0e1430;
    --primary-soft: #28325a;
    --sun: #f5c04a;
    --sun-soft: #4a3c14;
    --ok: #6fdcaa;
    --ok-soft: #173c2e;
    --miss: #ff9484;
    --miss-soft: #4a211b;
    --hint: #f5c04a;
    --gap: #323b57;
    --shadow: none;
  }
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--ui);
  font-size: 17px;
  line-height: 1.5;
}

#app {
  max-width: 860px;
  margin: 0 auto;
  padding: 24px 16px 64px;
}

h1,
h2 {
  line-height: 1.2;
  margin: 0;
  text-wrap: balance;
}

h2 {
  font-size: 1.15rem;
  margin: 32px 0 12px;
}

a {
  color: var(--primary);
}

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

.icon {
  display: inline-flex;
  width: 1.25em;
  height: 1.25em;
  flex: none;
}

.icon svg {
  width: 100%;
  height: 100%;
  fill: currentColor;
}

/* ---------- главная ---------- */
.hero {
  padding: 16px 0 0;
}

.hero h1 {
  font-size: clamp(2rem, 6vw, 2.8rem);
  letter-spacing: -0.01em;
}

.hero p {
  color: var(--muted);
  max-width: 34em;
  margin: 8px 0 0;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 12px;
}

.card {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-height: 150px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  color: inherit;
  text-decoration: none;
  transition: transform 0.12s ease, border-color 0.12s ease;
}

.card:hover {
  transform: translateY(-2px);
  border-color: var(--primary);
}

.card-theme {
  align-self: flex-start;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.card-title {
  font-family: var(--verse);
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1.25;
}

.card-author {
  color: var(--muted);
  font-size: 0.92rem;
}

.card-progress {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: auto;
  padding-top: 12px;
}

.bar {
  flex: 1;
  height: 8px;
  border-radius: 99px;
  background: var(--gap);
  overflow: hidden;
}

.bar span {
  display: block;
  height: 100%;
  border-radius: 99px;
  background: var(--sun);
}

.card-count {
  font-size: 0.85rem;
  color: var(--muted);
  white-space: nowrap;
  display: inline-flex;
}

.card.add {
  border-style: dashed;
  border-width: 2px;
  background: transparent;
  box-shadow: none;
  justify-content: center;
  color: var(--primary);
}

.card.add .icon {
  width: 2rem;
  height: 2rem;
  margin-bottom: 6px;
}

.card.add .card-title {
  font-family: var(--ui);
  font-size: 1.1rem;
}

/* ---------- звёзды ---------- */
.stars {
  display: inline-flex;
  gap: 2px;
  color: var(--gap);
}

.stars .on {
  color: var(--sun);
}

.stars.small .icon {
  width: 0.95em;
  height: 0.95em;
}

.stars.large .icon {
  width: 3rem;
  height: 3rem;
}

/* ---------- страница стиха ---------- */
.poem-head {
  margin-bottom: 16px;
}

.poem-head h1 {
  font-family: var(--verse);
  font-size: clamp(1.7rem, 5vw, 2.3rem);
}

.author {
  color: var(--muted);
  margin: 4px 0 0;
}

.back {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 12px;
  padding: 6px 10px 6px 4px;
  font-weight: 700;
  text-decoration: none;
  border-radius: 10px;
}

.poem-tools {
  display: flex;
  gap: 16px;
  margin-top: 8px;
}

.link {
  padding: 0;
  border: 0;
  background: none;
  color: var(--primary);
  font: inherit;
  text-decoration: underline;
  cursor: pointer;
}

.link.danger {
  color: var(--miss);
}

.parts {
  display: flex;
  gap: 8px;
  padding: 4px 16px 12px;
  margin: 0 -16px;
  overflow-x: auto;
  scrollbar-width: none;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: none;
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 99px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.chip[aria-pressed="true"] {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--bg);
}

.tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
  border-radius: 16px;
  background: var(--gap);
}

.tab {
  min-height: 46px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.tab[aria-selected="true"] {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
}

.panel {
  margin-top: 12px;
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.tip {
  margin: 0 0 12px;
  color: var(--muted);
}

.notice {
  margin: 12px 0;
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--sun-soft);
}

/* ---------- текст стиха ---------- */
.poem-text {
  font-family: var(--verse);
  font-size: clamp(1.2rem, 4.2vw, 1.5rem);
  line-height: 1.75;
  padding: 8px 0;
}

.stanza + .stanza {
  margin-top: 1.1em;
}

.line {
  margin: 0;
  padding: 0 8px 0 1.6em;
  text-indent: -1.2em;
  border-radius: 10px;
  transition: background 0.2s ease;
}

.line.speaking {
  background: var(--sun-soft);
}

.gap {
  border-radius: 7px;
  background: var(--gap);
  text-indent: 0;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
}

.gap[role="button"] {
  cursor: pointer;
}

.gap .ghost {
  visibility: hidden;
}

.gap.peek {
  background: var(--sun-soft);
}

.gap.peek .ghost,
.gap.said .ghost,
.gap.hint .ghost,
.gap.shown .ghost {
  visibility: visible;
}

.gap.said {
  background: var(--ok-soft);
  color: var(--ok);
}

.gap.hint {
  background: var(--sun-soft);
  color: var(--hint);
}

.gap.miss {
  background: var(--miss-soft);
  color: var(--miss);
}

/* ---------- кнопки ---------- */
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}

.actions.end {
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 50px;
  padding: 0 20px;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.08s ease;
}

.btn:active {
  transform: scale(0.97);
}

.btn.primary {
  border-color: var(--primary);
  background: var(--primary);
  color: var(--primary-ink);
}

.btn.big {
  min-height: 58px;
  padding: 0 26px;
  font-size: 1.1rem;
}

.btn.ghost-btn {
  border-color: transparent;
  background: var(--primary-soft);
}

.btn.toggle[aria-pressed="true"] {
  border-color: var(--primary);
}

.btn.toggle[aria-pressed="true"]::before {
  content: "✓";
}

/* ---------- шаги заучивания ---------- */
.step-head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 8px;
}

.steps {
  display: flex;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.steps li {
  width: 26px;
  height: 10px;
  border-radius: 99px;
  background: var(--gap);
}

.steps .past {
  background: var(--sun);
}

.steps .now {
  background: var(--primary);
}

.peeks {
  margin-left: auto;
  color: var(--muted);
  font-size: 0.9rem;
}

/* ---------- рассказ ---------- */
.listening {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 12px;
  font-weight: 700;
  color: var(--miss);
}

.pulse {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: currentColor;
  animation: pulse 1.2s ease-in-out infinite;
}

@keyframes pulse {
  50% {
    transform: scale(1.5);
    opacity: 0.4;
  }
}

.result {
  text-align: center;
  padding: 8px 0 12px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 8px;
}

.result h2 {
  margin: 8px 0 0;
  font-size: 1.4rem;
}

.result p {
  margin: 4px 0 0;
  color: var(--muted);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 8px 0 0;
  font-size: 0.85rem;
}

.legend span {
  padding: 2px 10px;
  border-radius: 99px;
}

.legend .said {
  background: var(--ok-soft);
  color: var(--ok);
}

.legend .miss {
  background: var(--miss-soft);
  color: var(--miss);
}

.legend .hint {
  background: var(--sun-soft);
  color: var(--hint);
}

/* ---------- занятие с помощником ---------- */
/* Сцена: большой персонаж слева, справа — что сейчас происходит и сколько осталось времени. */
.tutor-bar {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-areas:
    "who status"
    "who clock";
  column-gap: 20px;
  align-items: center;
  margin-bottom: 14px;
  padding: 30px 20px 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--bg);
}

.tutor-bar .listening {
  grid-area: status;
  align-self: end;
  margin: 0;
  font-size: 1.15rem;
  line-height: 1.3;
}

.tutor-bar .listening .pulse {
  flex: none;
}

.tutor-bar .clock {
  grid-area: clock;
  align-self: start;
  margin: 6px 0 0 24px;
}

.tutor-bar .character {
  grid-area: who;
  width: 220px;
  height: 220px;
}

.result .character {
  width: 180px;
  height: 180px;
  margin: 26px auto 8px;
}

/* ---------- персонажи ---------- */
/* Круглая светлая «сцена» в обеих темах, чтобы почти чёрный котёнок не терялся на тёмном фоне. */
.character {
  --mouth: 0;
  --stage: radial-gradient(circle at 50% 38%, #f6f8ff 0%, #e3e9ff 62%, #d3dcfb 100%);
  position: relative;
  display: block;
  flex: none;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--stage);
}

@media (prefers-color-scheme: dark) {
  .character {
    --stage: radial-gradient(circle at 50% 38%, #d5dcf8 0%, #a3aee0 58%, #7682bb 100%);
  }
}

.character svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.ch-shadow {
  fill: #1f2a44;
  opacity: 0.16;
}

.ch-all,
.ch-head,
.ch-body,
.ch-eye,
.ch-ear,
.ch-wing,
.ch-tail,
.ch-jaw,
.ch-mouth-open {
  transform-box: fill-box;
  transform-origin: 50% 50%;
}

/* покой: дыхание, моргание, уши и хвост */
.ch-all {
  transform-origin: 50% 100%;
  animation: ch-breathe 3.6s ease-in-out infinite;
}

.ch-head {
  transform-origin: 50% 90%;
  transition: transform 0.35s ease;
}

.ch-eye {
  animation: ch-blink 4.6s infinite;
}

.ch-kitten .ch-eye {
  animation-duration: 3.9s;
}

.ch-fox .ch-eye {
  animation-duration: 5.3s;
}

.ch-ear {
  transform-origin: 50% 100%;
  animation: ch-ear 5.2s ease-in-out infinite;
}

.ch-ear-r {
  animation-delay: 0.25s;
}

.ch-tail {
  transform-origin: 0% 100%;
  animation: ch-tail 2.8s ease-in-out infinite;
}

.ch-wing {
  transform-origin: 50% 0%;
}

.ch-wing-l {
  animation: ch-wing-l 4.8s ease-in-out infinite;
}

.ch-wing-r {
  animation: ch-wing-r 4.8s ease-in-out infinite;
}

/* рот: --mouth = 0 закрыт, 1 открыт; у совы вместе с ним опускается нижняя половина клюва */
.ch-mouth-open {
  transform-origin: 50% 0%;
  transform: scaleY(var(--mouth));
}

.ch-jaw {
  transform: translateY(calc(var(--mouth) * 5.5px));
}

/* пока громкость голоса неизвестна (нет AudioContext), рот двигается сам */
.character[data-state="speaking"]:not([data-lipsync]) .ch-mouth-open {
  animation: ch-talk 0.42s ease-in-out infinite;
}

.character[data-state="speaking"]:not([data-lipsync]) .ch-jaw {
  animation: ch-talk-jaw 0.42s ease-in-out infinite;
}

.character[data-state="speaking"] .ch-head {
  animation: ch-nod 0.9s ease-in-out infinite;
}

.character[data-state="speaking"] .ch-tail {
  animation-duration: 1.2s;
}

.character[data-state="listening"] .ch-head {
  transform: rotate(-7deg);
}

.character[data-state="listening"] .ch-ear {
  animation: none;
  transform: scaleY(1.1);
}

.character[data-state="listening"] .ch-all,
.character[data-state="listening"] .ch-tail,
.character[data-state="listening"] .ch-wing {
  animation-play-state: paused;
}

.character[data-state="waiting"] .ch-all {
  animation-duration: 5s;
}

.character[data-state="waiting"] .ch-tail {
  animation-duration: 4.5s;
}

.character[data-art="svg"][data-state="connecting"] {
  animation: ch-pulse 1.4s ease-in-out infinite;
}

.character[data-state="happy"] .ch-mouth-open {
  transform: scaleY(0.8);
}

.character[data-state="happy"] .ch-jaw {
  transform: translateY(4.4px);
}

.character[data-state="happy"] .ch-all {
  animation: ch-jump 0.5s ease-out 3;
}

.character[data-state="happy"] .ch-tail {
  animation-duration: 0.5s;
}

.character[data-state="happy"] .ch-wing-l {
  animation: ch-flap-l 0.25s ease-in-out 6;
}

.character[data-state="happy"] .ch-wing-r {
  animation: ch-flap-r 0.25s ease-in-out 6;
}

@keyframes ch-breathe {
  50% {
    transform: scale(1.015, 0.975);
  }
}

@keyframes ch-blink {
  0%,
  93%,
  100% {
    transform: scaleY(1);
  }
  96.5% {
    transform: scaleY(0.08);
  }
}

@keyframes ch-ear {
  0%,
  86%,
  100% {
    transform: rotate(0);
  }
  90% {
    transform: rotate(-7deg);
  }
  95% {
    transform: rotate(4deg);
  }
}

@keyframes ch-tail {
  50% {
    transform: rotate(9deg);
  }
}

@keyframes ch-wing-l {
  0%,
  80%,
  100% {
    transform: rotate(0);
  }
  90% {
    transform: rotate(9deg);
  }
}

@keyframes ch-wing-r {
  0%,
  80%,
  100% {
    transform: rotate(0);
  }
  90% {
    transform: rotate(-9deg);
  }
}

@keyframes ch-flap-l {
  50% {
    transform: rotate(28deg);
  }
}

@keyframes ch-flap-r {
  50% {
    transform: rotate(-28deg);
  }
}

@keyframes ch-nod {
  50% {
    transform: translateY(1.6px) rotate(2deg);
  }
}

@keyframes ch-talk {
  0%,
  100% {
    transform: scaleY(0.1);
  }
  50% {
    transform: scaleY(0.85);
  }
}

@keyframes ch-talk-jaw {
  0%,
  100% {
    transform: translateY(0.5px);
  }
  50% {
    transform: translateY(4.7px);
  }
}

@keyframes ch-pulse {
  50% {
    opacity: 0.55;
  }
}

@keyframes ch-jump {
  40% {
    transform: translateY(-13px) scale(0.97, 1.04);
  }
  80% {
    transform: translateY(0) scale(1.04, 0.95);
  }
}

/* запасной SVG-рисунок: короткие реакции теми же средствами, что и радость */
.character[data-art="svg"]:is([data-react="cheer"], [data-react="celebrate"], [data-react="hello"]) .ch-all {
  animation: ch-jump 0.5s ease-out 3;
}

.character[data-art="svg"]:is([data-react="cheer"], [data-react="celebrate"], [data-react="hello"]) .ch-wing-l {
  animation: ch-flap-l 0.25s ease-in-out 6;
}

.character[data-art="svg"]:is([data-react="cheer"], [data-react="celebrate"], [data-react="hello"]) .ch-wing-r {
  animation: ch-flap-r 0.25s ease-in-out 6;
}

.character[data-art="svg"]:is([data-react="oops"], [data-react="think"]) .ch-head {
  animation: none;
  transform: rotate(8deg);
}

/* ---------- персонажи-иллюстрации ---------- */
/* Слои вложены, чтобы движения складывались: прыжок > поза состояния > громкость голоса > смена эмоции. */
.ch-ground {
  position: absolute;
  left: 22%;
  right: 22%;
  bottom: 2.5%;
  height: 7%;
  border-radius: 50%;
  background: #1f2a44;
  opacity: 0.2;
}

.ch-hop,
.ch-sway,
.ch-talk,
.ch-pop {
  position: absolute;
  inset: 0;
  display: block;
  transform-origin: 50% 94%;
}

/* Картинка чуть больше круга и стоит на его нижнем крае: голова выглядывает за сцену. */
.ch-img {
  position: absolute;
  left: -5%;
  bottom: -1%;
  width: 110%;
  max-width: none;
  height: auto;
  opacity: 0;
  transition: opacity 0.16s ease;
  pointer-events: none;
  user-select: none;
}

.ch-img.on {
  opacity: 1;
}

.character[data-pop="a"] .ch-pop {
  animation: ch-pop-a 0.34s ease-out;
}

.character[data-pop="b"] .ch-pop {
  animation: ch-pop-b 0.34s ease-out;
}

/* покой: дыхание */
.ch-sway {
  animation: ch-float 3.8s ease-in-out infinite;
  transition: transform 0.4s cubic-bezier(0.3, 1.4, 0.6, 1);
}

/* просыпается: медленно покачивается и потягивается */
.character[data-state="connecting"] .ch-sway {
  transform: rotate(-2deg);
  animation: ch-doze 4.4s ease-in-out infinite;
}

/* говорит: покачивание и «пружинка» тем сильнее, чем громче голос */
.character[data-state="speaking"] .ch-sway {
  animation: ch-bob 0.84s ease-in-out infinite;
}

.ch-talk {
  transition: transform 0.09s linear;
}

.character[data-state="speaking"] .ch-talk {
  transform: translateY(calc(var(--mouth) * -2.5%)) scale(calc(1 - var(--mouth) * 0.03), calc(1 + var(--mouth) * 0.07));
}

.character[data-state="speaking"]:not([data-lipsync]) .ch-talk {
  animation: ch-chatter 0.42s ease-in-out infinite;
}

/* слушает: подаётся вперёд и почти замирает */
.character[data-state="listening"] .ch-sway {
  transform: rotate(-4deg) scale(1.06);
  animation: ch-lean 3.4s ease-in-out infinite;
}

.character[data-art="img"][data-state="listening"]::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 2px solid var(--primary);
  border-radius: 50%;
  opacity: 0.35;
  animation: ch-ring 2.6s ease-out infinite;
}

/* ждёт: терпеливо переминается */
.character[data-state="waiting"] .ch-sway {
  animation: ch-patient 6.7s ease-in-out infinite;
}

/* радуется: пара лёгких подпрыгиваний, потом пауза */
.character[data-state="happy"] .ch-hop {
  animation: ch-bounce 3.1s ease-in-out infinite;
}

/* короткие реакции */
.character[data-react="enter"] .ch-hop {
  animation: ch-enter 0.8s cubic-bezier(0.3, 0, 0.3, 1) both;
}

.character[data-react="enter"] .ch-ground {
  animation: ch-ground-in 0.8s ease-out both;
}

.character[data-react="hello"] .ch-hop {
  animation: ch-hello 1.3s ease-in-out both;
}

.character[data-react="cheer"] .ch-hop {
  animation: ch-cheer 1.25s cubic-bezier(0.3, 0, 0.3, 1) both;
}

.character[data-react="cheer"] .ch-ground {
  animation: ch-ground-jump 1.25s cubic-bezier(0.3, 0, 0.3, 1) both;
}

.character[data-react="celebrate"] .ch-hop {
  animation: ch-celebrate 2.5s cubic-bezier(0.3, 0, 0.3, 1) both;
}

.character[data-react="oops"] .ch-hop {
  animation: ch-wobble 1.7s ease-in-out both;
}

.character[data-react="think"] .ch-hop {
  transform: rotate(4deg);
  animation: ch-ponder 2.2s ease-in-out both;
}

@keyframes ch-float {
  50% {
    transform: translateY(-1.4%) scale(0.992, 1.014);
  }
}

@keyframes ch-doze {
  0%,
  100% {
    transform: rotate(-2deg) scale(1.02, 0.975);
  }
  50% {
    transform: rotate(2deg) scale(0.985, 1.02);
  }
}

@keyframes ch-bob {
  0%,
  100% {
    transform: rotate(calc(-0.8deg - var(--mouth) * 2.4deg));
  }
  50% {
    transform: translateY(calc(-0.8% - var(--mouth) * 2%)) rotate(calc(0.8deg + var(--mouth) * 2.4deg));
  }
}

@keyframes ch-chatter {
  50% {
    transform: translateY(-1.5%) scale(0.985, 1.04);
  }
}

@keyframes ch-lean {
  0%,
  100% {
    transform: rotate(-4deg) scale(1.06);
  }
  50% {
    transform: rotate(-5deg) scale(1.072);
  }
}

@keyframes ch-ring {
  0% {
    transform: scale(1);
    opacity: 0.4;
  }
  100% {
    transform: scale(1.14);
    opacity: 0;
  }
}

@keyframes ch-patient {
  0%,
  100% {
    transform: none;
  }
  18% {
    transform: translateY(-1.2%) scale(0.994, 1.012);
  }
  40%,
  56% {
    transform: rotate(2.2deg);
  }
  48% {
    transform: rotate(2.2deg) translateY(-1%);
  }
  78% {
    transform: rotate(-1.6deg);
  }
}

@keyframes ch-bounce {
  0%,
  34%,
  100% {
    transform: none;
  }
  5% {
    transform: scale(1.05, 0.94);
  }
  13% {
    transform: translateY(-6%) scale(0.97, 1.05);
  }
  21% {
    transform: scale(1.04, 0.95);
  }
  27% {
    transform: translateY(-2.5%);
  }
}

@keyframes ch-pop-a {
  35% {
    transform: scale(1.06, 0.93);
  }
  70% {
    transform: scale(0.975, 1.035);
  }
}

@keyframes ch-pop-b {
  35% {
    transform: scale(1.06, 0.93);
  }
  70% {
    transform: scale(0.975, 1.035);
  }
}

@keyframes ch-enter {
  0% {
    opacity: 0;
    transform: translateY(18%) scale(0.35);
  }
  30% {
    opacity: 1;
  }
  55% {
    transform: translateY(-5%) scale(0.95, 1.08);
  }
  75% {
    transform: scale(1.06, 0.93);
  }
  100% {
    opacity: 1;
    transform: none;
  }
}

@keyframes ch-ground-in {
  0% {
    opacity: 0;
    transform: scale(0.3);
  }
}

@keyframes ch-hello {
  0%,
  100% {
    transform: none;
  }
  10% {
    transform: scale(1.05, 0.94);
  }
  24% {
    transform: translateY(-5%) scale(0.97, 1.04);
  }
  38% {
    transform: scale(1.03, 0.97);
  }
  52% {
    transform: rotate(-3.5deg);
  }
  68% {
    transform: rotate(3.5deg);
  }
  84% {
    transform: rotate(-2deg);
  }
}

@keyframes ch-cheer {
  0%,
  100% {
    transform: none;
  }
  12% {
    transform: scale(1.09, 0.87);
  }
  34% {
    transform: translateY(-10%) scale(0.94, 1.09);
  }
  44% {
    transform: translateY(-11%) rotate(3deg);
  }
  60% {
    transform: scale(1.08, 0.89);
  }
  72% {
    transform: translateY(-3.5%) scale(0.98, 1.03);
  }
  86% {
    transform: scale(1.03, 0.97);
  }
}

@keyframes ch-ground-jump {
  0%,
  12%,
  60%,
  100% {
    transform: none;
    opacity: 0.2;
  }
  34%,
  44% {
    transform: scale(0.7);
    opacity: 0.1;
  }
}

@keyframes ch-celebrate {
  0%,
  100% {
    transform: none;
  }
  6% {
    transform: scale(1.08, 0.88);
  }
  17% {
    transform: translateY(-9%) rotate(-5deg) scale(0.95, 1.07);
  }
  28% {
    transform: scale(1.07, 0.9);
  }
  36% {
    transform: scale(1.08, 0.88);
  }
  47% {
    transform: translateY(-9%) rotate(5deg) scale(0.95, 1.07);
  }
  58% {
    transform: scale(1.07, 0.9);
  }
  66% {
    transform: scale(1.1, 0.86);
  }
  78% {
    transform: translateY(-12%) scale(0.93, 1.1);
  }
  90% {
    transform: scale(1.06, 0.92);
  }
}

@keyframes ch-wobble {
  0%,
  100% {
    transform: none;
  }
  18% {
    transform: rotate(6deg);
  }
  38% {
    transform: rotate(-4deg);
  }
  58% {
    transform: rotate(4deg) translateY(1%);
  }
  78% {
    transform: rotate(-2deg);
  }
}

@keyframes ch-ponder {
  0%,
  100% {
    transform: none;
  }
  18%,
  50% {
    transform: rotate(5deg) translateY(-1%);
  }
  66%,
  84% {
    transform: rotate(3.5deg);
  }
}

/* ---------- частицы вокруг персонажа ---------- */
/* Создаются скриптом на время реакции; числа приходят в переменных --x0…--delay. */
.ch-fx {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.ch-p {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 11%;
  height: 11%;
  min-width: 9px;
  min-height: 9px;
  margin: -5.5% 0 0 -5.5%;
  opacity: 0;
}

.ch-p-burst {
  animation: ch-p-burst var(--dur) cubic-bezier(0.15, 0.7, 0.3, 1) var(--delay) both;
}

.ch-p-fall {
  animation: ch-p-fall var(--dur) cubic-bezier(0.4, 0.1, 0.8, 0.9) var(--delay) both;
}

@keyframes ch-p-burst {
  0% {
    opacity: 0;
    transform: translate(var(--x0), var(--y0)) scale(0.2) rotate(0deg);
  }
  18%,
  65% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(var(--x1), var(--y1)) scale(var(--size)) rotate(var(--rot));
  }
}

@keyframes ch-p-fall {
  0% {
    opacity: 0;
    transform: translate(var(--x0), var(--y0)) scale(var(--size)) rotate(0deg);
  }
  12%,
  75% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(var(--x1), var(--y1)) scale(var(--size)) rotate(var(--rot));
  }
}

/* ---------- выбор персонажа ---------- */
.char-picker {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  min-width: 0;
  margin: 0 0 14px;
  padding: 0;
  border: 0;
}

.char-picker legend {
  margin-bottom: 8px;
  padding: 0;
  font-weight: 700;
}

.char-option {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-height: 64px;
  padding: 12px 8px;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  text-align: center;
  cursor: pointer;
}

.char-option .character {
  width: 104px;
  height: 104px;
  margin-top: 10px;
}

.char-option input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.char-option.selected {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.char-option.selected strong::after {
  content: " ✓";
  color: var(--primary);
}

.char-option:has(input:focus-visible) {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
}

.char-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.25;
}

.char-desc {
  color: var(--muted);
  font-size: 0.85rem;
}

@media (max-width: 560px) {
  .char-picker {
    grid-template-columns: 1fr;
  }

  .char-option {
    flex-direction: row;
    gap: 12px;
    padding: 8px 12px;
    text-align: left;
  }

  .char-option .character {
    width: 72px;
    height: 72px;
    margin-top: 6px;
  }

  .tutor-bar {
    column-gap: 12px;
    padding: 22px 10px 10px;
  }

  .tutor-bar .character {
    width: 156px;
    height: 156px;
  }

  .tutor-bar .listening {
    font-size: 1rem;
  }

  .result .character {
    width: 150px;
    height: 150px;
  }
}

.listening.calm {
  color: var(--ink);
}

.listening.calm .pulse {
  background: var(--primary);
}

.listening[data-state="listening"] .pulse {
  background: var(--miss);
}

.listening[data-state="waiting"] .pulse {
  animation: none;
  background: var(--ok);
}

.clock {
  margin-left: auto;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.line.learning {
  box-shadow: inset 4px 0 0 var(--sun);
}

.line.learned {
  box-shadow: inset 4px 0 0 var(--ok);
}

/* ---------- страницы для поиска (SEO-слой) ---------- */
.crumbs {
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 0.9rem;
}

.seo-steps,
.seo-facts {
  margin: 0;
  padding-left: 1.3em;
}

.seo-steps li,
.seo-facts li {
  margin-bottom: 8px;
}

.seo .card {
  min-height: 0;
}

.seo .card-count {
  margin-top: auto;
  padding-top: 12px;
}

.seo-footer {
  max-width: 860px;
  margin: 0 auto;
  padding: 0 16px 40px;
  color: var(--muted);
  font-size: 0.9rem;
}

/* ---------- форма ---------- */
.form label {
  display: block;
  margin: 16px 0 6px;
  font-weight: 700;
}

.form label:first-child {
  margin-top: 0;
}

.form input,
.form textarea {
  width: 100%;
  padding: 12px 14px;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  color: var(--ink);
  font: inherit;
}

.form textarea {
  font-family: var(--verse);
  font-size: 1.1rem;
  line-height: 1.6;
  resize: vertical;
}

.field-hint {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.9rem;
}

@media (max-width: 480px) {
  .panel {
    padding: 16px 14px;
  }

  .actions .btn {
    flex: 1 1 auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}


.profile-link {
  float: right;
  margin-top: 8px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 99px;
  background: var(--surface);
  font-weight: 700;
  text-decoration: none;
}

/* ---------- выбор четверостиший ---------- */
.quatrains {
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
}

.quatrains summary {
  min-height: 46px;
  padding: 11px 16px;
  font-weight: 700;
  cursor: pointer;
}

.q-list {
  display: grid;
  gap: 2px;
  padding: 0 8px 8px;
}

.q-option {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 4px 8px;
  border-radius: 10px;
  cursor: pointer;
}

.q-option:hover {
  background: var(--primary-soft);
}

.q-option input {
  width: 22px;
  height: 22px;
  flex: none;
  accent-color: var(--primary);
}

.q-num {
  flex: none;
  width: 1.6em;
  font-weight: 700;
  color: var(--muted);
}

.q-text {
  font-family: var(--verse);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.quatrains > .link {
  margin: 0 16px 12px;
}
