/* ============================================================
   БАЗА
   ============================================================ */
* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 20px;
  font-family: 'Nunito', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color: #2b2f5e;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
  position: relative;

  /* Живой переливающийся градиент */
  background: linear-gradient(135deg, #e8f0ff, #f3e6ff, #ffe6f3, #e6f6ff);
  background-size: 400% 400%;
  animation: bgShift 18s ease-in-out infinite;
}

@keyframes bgShift {
  0%, 100% { background-position: 0% 50%; }
  50%      { background-position: 100% 50%; }
}

.app {
  width: min(520px, 100%);
  display: flex;
  flex-direction: column;
  gap: 16px;
  position: relative;
  z-index: 1;
}

/* ============================================================
   АНИМИРОВАННЫЙ ФОН
   ============================================================ */
.bg-anim {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
}

/* ---------- Мягкие цветные пятна ---------- */
.bg-blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(60px);
  opacity: .55;
  will-change: transform;
}

.blob-1 {
  width: 320px; height: 320px;
  background: #b6c8ff;
  top: -80px; left: -80px;
  animation: blobFloat1 24s ease-in-out infinite;
}
.blob-2 {
  width: 380px; height: 380px;
  background: #e3b8ff;
  bottom: -120px; right: -100px;
  animation: blobFloat2 28s ease-in-out infinite;
}
.blob-3 {
  width: 260px; height: 260px;
  background: #ffc2dd;
  top: 40%; left: 60%;
  animation: blobFloat3 22s ease-in-out infinite;
}
.blob-4 {
  width: 280px; height: 280px;
  background: #b8f0ff;
  bottom: 10%; left: -80px;
  animation: blobFloat2 26s ease-in-out infinite reverse;
}

@keyframes blobFloat1 {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33%      { transform: translate(60px, 40px) scale(1.1); }
  66%      { transform: translate(30px, 90px) scale(.95); }
}
@keyframes blobFloat2 {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50%      { transform: translate(-70px, -50px) scale(1.15); }
}
@keyframes blobFloat3 {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50%      { transform: translate(-90px, 60px) scale(.9); }
}

/* ---------- Пузырьки ---------- */
.bg-bubble {
  position: absolute;
  bottom: -80px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%,
              rgba(255,255,255,.9),
              rgba(255,255,255,.15) 60%,
              rgba(255,255,255,.05));
  border: 1.5px solid rgba(255,255,255,.6);
  box-shadow: 0 0 18px rgba(255,255,255,.4);
  will-change: transform, opacity;
}

.bubble-1 { width: 30px; height: 30px; left: 8%;  animation: bubbleUp 16s linear infinite; }
.bubble-2 { width: 18px; height: 18px; left: 22%; animation: bubbleUp 20s linear 2s infinite; }
.bubble-3 { width: 44px; height: 44px; left: 38%; animation: bubbleUp 24s linear 5s infinite; }
.bubble-4 { width: 22px; height: 22px; left: 54%; animation: bubbleUp 18s linear 1s infinite; }
.bubble-5 { width: 36px; height: 36px; left: 70%; animation: bubbleUp 22s linear 7s infinite; }
.bubble-6 { width: 16px; height: 16px; left: 84%; animation: bubbleUp 19s linear 3s infinite; }
.bubble-7 { width: 28px; height: 28px; left: 92%; animation: bubbleUp 26s linear 9s infinite; }
.bubble-8 { width: 20px; height: 20px; left: 46%; animation: bubbleUp 21s linear 11s infinite; }

@keyframes bubbleUp {
  0%   { transform: translateY(0) translateX(0) rotate(0);              opacity: 0; }
  10%  { opacity: 1; }
  50%  { transform: translateY(-50vh) translateX(30px) rotate(180deg); }
  90%  { opacity: 1; }
  100% { transform: translateY(-110vh) translateX(-20px) rotate(360deg); opacity: 0; }
}

/* ---------- Звёздочки ---------- */
.bg-star {
  position: absolute;
  font-size: 22px;
  opacity: .8;
  filter: drop-shadow(0 0 6px rgba(255,255,255,.8));
  animation: starTwinkle 4s ease-in-out infinite;
}
.star-1 { top: 8%;    left: 12%;  font-size: 20px; animation-delay: 0s;   }
.star-2 { top: 20%;   right: 10%; font-size: 26px; animation-delay: .8s; }
.star-3 { top: 65%;   left: 6%;   font-size: 18px; animation-delay: 1.6s; }
.star-4 { bottom: 14%; right: 8%; font-size: 24px; animation-delay: 2.4s; }
.star-5 { top: 45%;   right: 20%; font-size: 20px; animation-delay: 3.2s; }

@keyframes starTwinkle {
  0%, 100% { transform: scale(1) rotate(0deg);     opacity: .8; }
  50%      { transform: scale(1.35) rotate(20deg); opacity: 1;  }
}

/* ---------- Мини-капибары / листики ---------- */
.bg-capy {
  position: absolute;
  font-size: 36px;
  opacity: .55;
  filter: drop-shadow(0 4px 8px rgba(70, 90, 170, .2));
  animation: capyDrift 26s linear infinite;
}
.capy-bg-1 { top: 15%;    left: -60px;  animation-duration: 30s; font-size: 42px; }
.capy-bg-2 { bottom: 20%; right: -60px; animation-duration: 34s; animation-delay: 4s; font-size: 34px; }
.capy-bg-3 { top: 75%;    left: -60px;  animation-duration: 28s; animation-delay: 8s; font-size: 30px; }

@keyframes capyDrift {
  0%   { transform: translateX(0)     rotate(0deg); }
  50%  { transform: translateX(50vw)  rotate(15deg); }
  100% { transform: translateX(110vw) rotate(0deg); }
}

/* Если у пользователя отключены анимации — не мучаем */
@media (prefers-reduced-motion: reduce) {
  .bg-blob, .bg-bubble, .bg-star, .bg-capy, body { animation: none !important; }
  .bg-bubble, .bg-capy { display: none; }
}

/* ============================================================
   ВЕРХНЯЯ ПАНЕЛЬ: капибара + переключатель
   ============================================================ */
.top-bar {
  display: flex;
  align-items: center;
  gap: 12px;
}

.capybara-mascot {
  width: 74px;
  height: 80px;
  flex-shrink: 0;
  cursor: pointer;
  transition: transform .2s;
  animation: capyFloat 3.4s ease-in-out infinite;
  filter: drop-shadow(0 6px 10px rgba(70, 90, 170, .22));
}
.capybara-mascot:hover { transform: scale(1.08) rotate(-3deg); }

.capy-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  user-select: none;
  pointer-events: none;
  -webkit-user-drag: none;
}

.mode-switch {
  flex: 1;
  display: flex;
  gap: 6px;
  background: #fff;
  padding: 6px;
  border-radius: 20px;
  box-shadow: 0 6px 22px rgba(70, 90, 170, .12);
}

.mode-btn {
  flex: 1;
  padding: 12px 10px;
  border: none;
  border-radius: 15px;
  background: transparent;
  font-family: inherit;
  font-size: 14px;
  font-weight: 900;
  color: #8b93bb;
  cursor: pointer;
  transition: background .2s, color .2s, box-shadow .2s;
  line-height: 1.15;
}
.mode-btn.active {
  background: linear-gradient(135deg, #6a7dff, #9a5cff);
  color: #fff;
  box-shadow: 0 6px 14px rgba(106, 125, 255, .3);
}

/* ============================================================
   КАРТОЧКА
   ============================================================ */
.card {
  width: 100%;
  background: #fff;
  border-radius: 32px;
  padding: 26px 26px 24px;
  box-shadow: 0 24px 60px rgba(70, 90, 170, .18), 0 0 0 1px rgba(120, 140, 220, .07);
  text-align: center;
}
.card.hidden { display: none; }

.title {
  margin: 0 0 4px;
  font-size: 15px;
  font-weight: 900;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: #8b93bb;
}
.hint { margin: 0 0 8px; font-size: 15px; color: #8b93bb; font-weight: 700; }

/* ---------- Фонетический режим ---------- */
.word {
  font-size: clamp(44px, 14vw, 68px);
  font-weight: 900;
  line-height: 1.1;
  margin: 14px 0 24px;
  color: #2b2f5e;
  letter-spacing: .01em;
  word-break: break-word;
}
.word.pop { animation: pop .45s cubic-bezier(.2, 1.6, .5, 1); }
@keyframes pop {
  0%   { transform: scale(.7); opacity: 0; }
  100% { transform: scale(1);  opacity: 1; }
}

.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 20px; }
.field {
  display: flex; flex-direction: column; gap: 4px;
  padding: 12px 10px 10px;
  background: #f4f7ff;
  border: 2px solid transparent;
  border-radius: 22px;
  transition: border-color .2s, background .2s, transform .2s;
}
.field:focus-within { border-color: #7c8cff; background: #fff; transform: translateY(-2px); }
.field span {
  font-size: 12px; font-weight: 900; letter-spacing: .1em;
  text-transform: uppercase; color: #8b93bb;
}
.field input {
  width: 100%; border: none; outline: none; background: transparent;
  font-family: inherit; font-size: 36px; font-weight: 900;
  text-align: center; color: #2b2f5e; padding: 0;
}
.field input::placeholder { color: #c9d0ee; }
input[type=number]::-webkit-outer-spin-button,
input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input[type=number] { -moz-appearance: textfield; appearance: textfield; }

/* ---------- Режим словарных слов ---------- */
.vocab-word {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  margin: 22px 0 26px;
  font-size: clamp(28px, 9vw, 42px);
  font-weight: 900;
  line-height: 1.2;
}
.letter-static {
  display: inline-block;
  min-width: 0.6em;
  padding: 2px 3px;
  color: #2b2f5e;
  text-align: center;
}
.letter-input {
  width: clamp(38px, 10vw, 50px);
  height: clamp(48px, 13vw, 60px);
  border: 3px dashed #b8c2e8;
  border-radius: 12px;
  background: #f4f7ff;
  font-family: inherit;
  font-size: clamp(26px, 8vw, 36px);
  font-weight: 900;
  text-align: center;
  color: #9a5cff;
  outline: none;
  text-transform: lowercase;
  transition: border-color .2s, background .2s, transform .2s;
  padding: 0;
  caret-color: #9a5cff;
}
.letter-input:focus {
  border-color: #6a7dff;
  border-style: solid;
  background: #fff;
  transform: translateY(-2px);
}
.letter-input.correct {
  border-color: #3ecf7a;
  border-style: solid;
  background: #eafff1;
  color: #1a9b52;
}
.letter-input.wrong {
  border-color: #ff5b7a;
  border-style: solid;
  background: #fff0f4;
  color: #e03050;
  animation: shake .35s;
}

/* ---------- Кнопка ---------- */
.btn {
  width: 100%;
  border: none;
  border-radius: 20px;
  padding: 18px;
  font-family: inherit;
  font-size: 19px;
  font-weight: 900;
  letter-spacing: .02em;
  color: #fff;
  background: linear-gradient(135deg, #6a7dff, #9a5cff);
  box-shadow: 0 12px 24px rgba(106, 125, 255, .35);
  cursor: pointer;
  transition: transform .12s, box-shadow .12s, filter .2s;
}
.btn:hover  { filter: brightness(1.05); }
.btn:active { transform: translateY(2px) scale(.99); box-shadow: 0 6px 14px rgba(106, 125, 255, .3); }

/* ---------- Тряска ---------- */
.shake { animation: shake .35s; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%      { transform: translateX(-8px); }
  40%      { transform: translateX(8px); }
  60%      { transform: translateX(-5px); }
  80%      { transform: translateX(5px); }
}

/* ============================================================
   МОДАЛЬНОЕ ОКНО
   ============================================================ */
.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(30, 35, 70, .45);
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s;
  z-index: 10;
}
.overlay.show { opacity: 1; pointer-events: auto; }

.modal {
  width: min(460px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  background: #fff;
  border-radius: 28px;
  padding: 22px 22px 22px;
  text-align: center;
  box-shadow: 0 30px 70px rgba(20, 25, 60, .35);
  transform: scale(.88) translateY(14px);
  transition: transform .32s cubic-bezier(.2, 1.35, .5, 1);
}
.overlay.show .modal { transform: scale(1) translateY(0); }

.modal h2 { margin: 0 0 10px; font-size: 26px; font-weight: 900; }
.modal p { margin: 0 0 18px; font-size: 16px; line-height: 1.45; color: #6b7399; font-weight: 700; }
.modal p b { color: #2b2f5e; }

.word-mini { font-size: 34px; font-weight: 900; margin: 0 0 14px; color: #9a5cff; }

/* ---------- Разбор ---------- */
.rows { display: flex; flex-direction: column; gap: 10px; margin: 0 0 14px; }
.row { background: #f4f7ff; border-radius: 18px; padding: 11px 14px 13px; text-align: left; }
.row-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 7px; }
.row-head .label {
  font-size: 12px; font-weight: 900; letter-spacing: .09em;
  text-transform: uppercase; color: #8b93bb;
}
.badge {
  background: #2b2f5e; color: #fff; font-size: 15px; font-weight: 900;
  border-radius: 999px; padding: 2px 13px; min-width: 38px; text-align: center;
}
.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip {
  display: inline-block; font-size: 17px; font-weight: 800;
  padding: 3px 10px; border-radius: 11px; background: #e6ebff; color: #2b2f5e;
}
.chip.sound { background: #f2e8ff; color: #7a4bd6; }
.chip.miss  { background: #ffe0e8; color: #e03050; }

.note {
  background: #fff8e3; border-radius: 16px; padding: 12px 14px;
  font-size: 15px; font-weight: 700; line-height: 1.45;
  color: #8a6d1e; text-align: left; margin: 0 0 18px;
}

/* ============================================================
   КАПИБАРА В МОДАЛЬНОМ ОКНЕ
   ============================================================ */
.capybara-wrap {
  position: relative;
  width: 140px;
  height: 150px;
  margin: 0 auto 4px;
  animation: capyFloat 3.4s ease-in-out infinite;
}
.capybara-wrap .capy-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.capybara-badge {
  position: absolute;
  top: -6px;
  right: -16px;
  font-size: 38px;
  line-height: 1;
  animation: badgePop .55s cubic-bezier(.2, 1.6, .5, 1);
  transform-origin: center;
}
@keyframes badgePop {
  0%   { transform: scale(0) rotate(-40deg); opacity: 0; }
  60%  { transform: scale(1.3) rotate(10deg); opacity: 1; }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}

/* Победа — капибара танцует */
.capybara-wrap.win {
  animation: capyDance 1.1s ease-in-out 2,
             capyFloat 3.4s ease-in-out 2.2s infinite;
}

/* Ошибка — капибара качает головой */
.capybara-wrap.fail {
  animation: capyShake .5s ease-in-out 3,
             capyFloat 3.4s ease-in-out 1.5s infinite;
}
.capybara-wrap.fail .capy-img {
  filter: grayscale(.35) brightness(.95);
}

@keyframes capyFloat {
  0%, 100% { transform: translateY(0) rotate(-1.5deg); }
  50%      { transform: translateY(-6px) rotate(1.5deg); }
}

@keyframes capyDance {
  0%   { transform: translateY(0) rotate(0deg) scale(1); }
  20%  { transform: translateY(-18px) rotate(-10deg) scale(1.06); }
  40%  { transform: translateY(0) rotate(10deg) scale(1); }
  60%  { transform: translateY(-12px) rotate(-8deg) scale(1.04); }
  80%  { transform: translateY(0) rotate(6deg) scale(1); }
  100% { transform: translateY(0) rotate(0deg) scale(1); }
}

@keyframes capyShake {
  0%, 100% { transform: translateX(0) rotate(0deg); }
  20%      { transform: translateX(-7px) rotate(-4deg); }
  40%      { transform: translateX(7px) rotate(4deg); }
  60%      { transform: translateX(-5px) rotate(-3deg); }
  80%      { transform: translateX(5px) rotate(3deg); }
}

/* ============================================================
   МОБИЛЬНАЯ АДАПТАЦИЯ
   ============================================================ */
@media (max-width: 600px) {
  .bg-blob { filter: blur(70px); opacity: .45; }
  .bg-star { font-size: 16px !important; }
  .bg-capy { font-size: 26px !important; opacity: .4; }
}

@media (max-width: 380px) {
  .card { padding: 22px 18px 20px; border-radius: 26px; }
  .field input { font-size: 30px; }
  .chip { font-size: 15px; padding: 2px 8px; }
  .mode-btn { font-size: 13px; padding: 10px 6px; }
  .capybara-mascot { width: 58px; height: 64px; }
  .capybara-wrap { width: 116px; height: 126px; }
  .capybara-badge { font-size: 32px; top: -4px; right: -12px; }
}