/* ============ Find the Animal! styles ============ */

/* Fonts are self-hosted (no requests to third-party servers).
   Fredoka covers English + Finnish; Noto Sans Bengali steps in for Bengali letters. */
@font-face {
  font-family: "Fredoka";
  font-style: normal;
  font-weight: 300 700;
  font-display: swap;
  src: url("../../assets/fonts/fredoka-latin.woff2") format("woff2");
}
@font-face {
  font-family: "Noto Sans Bengali";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("../../assets/fonts/noto-sans-bengali.woff2") format("woff2");
  unicode-range: U+0951-0952, U+0964-0965, U+0980-09FE, U+1CD0, U+1CD2, U+1CD5-1CD6, U+1CD8, U+1CE1, U+1CEA, U+1CED, U+1CF2, U+1CF5-1CF7, U+200C-200D, U+20B9, U+25CC, U+A8F1;
}

:root {
  --sky-top: #c9ecff;
  --sky-bottom: #fff3fa;
  --ink: #4a3434;
  --ink-soft: #7a6470;
  --pink: #ff8fb3;
  --purple: #b995ff;
  --yellow: #ffd23d;
  --white: #fff;
  --shadow: 0 6px 18px rgba(110, 140, 190, .28);
  --font: "Fredoka", "Noto Sans Bengali", "Nunito", "Segoe UI Rounded", system-ui, sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;                 /* never scroll during play */
  overscroll-behavior: none;
  font-family: var(--font);
  color: var(--ink);
  background: linear-gradient(to bottom, var(--sky-top), var(--sky-bottom));
  touch-action: manipulation;       /* no double-tap zoom */
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
/* Bengali letters are taller: give them a little more room */
body[data-lang="bn"] { --bn-lh: 1.45; }

button {
  font: inherit; color: inherit;
  border: 0; cursor: pointer;
  touch-action: manipulation;
}
button:focus-visible, a:focus-visible { outline: 4px solid var(--purple); outline-offset: 3px; }

/* ---------- Sky ---------- */
.sky { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.sun {
  position: absolute; top: -6vmin; right: -6vmin;
  width: 30vmin; height: 30vmin; border-radius: 50%;
  background: radial-gradient(circle, #fff6b8 0 45%, #ffe37a 46% 60%, rgba(255, 227, 122, 0) 61%);
  animation: spin 40s linear infinite;
}
.cloud {
  position: absolute; left: -30vmin;
  width: 24vmin; height: 8vmin; border-radius: 8vmin;
  background: #fff; opacity: .85;
  animation: drift linear infinite;
}
.cloud::before, .cloud::after { content: ""; position: absolute; background: #fff; border-radius: 50%; }
.cloud::before { width: 11vmin; height: 11vmin; left: 3vmin; top: -5.5vmin; }
.cloud::after  { width: 8vmin;  height: 8vmin;  left: 12vmin; top: -3.5vmin; }
.c1 { top: 14%; animation-duration: 70s; animation-delay: -10s; }
.c2 { top: 34%; animation-duration: 90s; animation-delay: -55s; transform: scale(.7); }
.c3 { top: 6%;  animation-duration: 80s; animation-delay: -35s; transform: scale(.55); }
.hill { position: absolute; border-radius: 50%; }
.h1 { left: -20vw; bottom: -38vh; width: 80vw; height: 60vh; background: #bdf0c9; }
.h2 { right: -25vw; bottom: -42vh; width: 90vw; height: 62vh; background: #a8e6b8; }

@keyframes drift { from { left: -30vmin; } to { left: 110vw; } }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Shared buttons ---------- */
.icon-btn {
  width: 60px; height: 60px; flex: none;
  border-radius: 50%;
  font-size: 28px; line-height: 1;
  display: inline-grid; place-items: center;
  background: rgba(255, 255, 255, .9);
  box-shadow: var(--shadow);
  transition: transform .15s, opacity .2s;
}
.icon-btn:active { transform: scale(.88); }
.icon-btn.off { opacity: .6; }
.icon-btn.big { width: 76px; height: 76px; font-size: 36px; background: #fff; }

.play-btn {
  display: inline-flex; align-items: center; gap: .4em;
  padding: .45em 1.4em;
  font-size: clamp(28px, 5vmin, 44px); font-weight: 700;
  color: #fff;
  background: linear-gradient(#ff9fc0, #ff7aa8);
  border-radius: 999px;
  box-shadow: 0 8px 0 #e45f8e, 0 14px 24px rgba(228, 95, 142, .35);
  transition: transform .12s, box-shadow .12s;
  animation: breathe 2.4s ease-in-out infinite;
}
.play-btn:active { transform: translateY(6px); box-shadow: 0 2px 0 #e45f8e, 0 6px 12px rgba(228, 95, 142, .3); }
@keyframes breathe { 0%, 100% { scale: 1; } 50% { scale: 1.05; } }

/* Language buttons (flags) */
.langs { display: flex; gap: clamp(10px, 2.5vmin, 22px); justify-content: center; flex-wrap: wrap; }
.lang-btn {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 12px 14px 10px;
  border-radius: 24px;
  background: rgba(255, 255, 255, .85);
  box-shadow: var(--shadow);
  border: 4px solid transparent;
  transition: transform .15s, border-color .2s, background .2s;
}
.lang-btn:active { transform: scale(.92); }
.lang-btn[aria-pressed="true"] { border-color: var(--purple); background: #fff; }
.flag {
  display: block;
  width: clamp(64px, 12vmin, 96px); aspect-ratio: 3 / 2;
  border-radius: 10px; overflow: hidden;
  box-shadow: 0 0 0 2px rgba(0, 0, 0, .08);
}
.flag svg { width: 100%; height: 100%; display: block; }
svg { overflow: hidden; }
.flag svg { overflow: hidden; }
.lang-name { font-size: clamp(16px, 2.6vmin, 22px); font-weight: 600; line-height: 1.3; }

/* ---------- Screens ---------- */
.screen {
  position: fixed; inset: 0;
  padding: calc(12px + var(--safe-t)) calc(14px + var(--safe-r)) calc(12px + var(--safe-b)) calc(14px + var(--safe-l));
}

/* Welcome */
.welcome {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: clamp(10px, 2.4vh, 24px);
  text-align: center;
}
.corner-btns { position: absolute; top: calc(14px + var(--safe-t)); right: calc(14px + var(--safe-r)); display: flex; gap: 10px; }
.parade { display: flex; gap: 2vmin; justify-content: center; }
.p-animal {
  width: clamp(80px, 17vmin, 160px); aspect-ratio: 1;
  animation: bob 1.6s ease-in-out infinite;
  animation-delay: calc(var(--i) * .25s);
  filter: drop-shadow(0 6px 6px rgba(80, 100, 140, .18));
}
.p-animal svg { width: 100%; height: 100%; display: block; }
@keyframes bob { 0%, 100% { transform: translateY(0) rotate(-3deg); } 50% { transform: translateY(-14px) rotate(3deg); } }

.w-title {
  margin: 0;
  font-size: clamp(38px, 8vmin, 76px); font-weight: 700; line-height: var(--bn-lh, 1.1);
  color: #ff6f9f;
  text-shadow: 0 4px 0 #fff, 0 8px 16px rgba(255, 111, 159, .25);
}
.w-sub { margin: 0; font-size: clamp(18px, 3vmin, 26px); color: var(--ink-soft); line-height: var(--bn-lh, 1.3); max-width: 30em; }
.voice-note {
  margin: 0; max-width: 34em;
  padding: 8px 14px; border-radius: 14px;
  font-size: 15px; line-height: var(--bn-lh, 1.35);
  background: rgba(255, 255, 255, .75); color: var(--ink-soft);
}
.back-link { color: var(--ink-soft); font-size: 16px; line-height: var(--bn-lh, 1.3); }

/* ---------- Game screen ---------- */
.game {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  grid-template-columns: minmax(0, 1fr);
  gap: clamp(6px, 1.5vh, 14px);
}
.topbar { display: flex; align-items: center; gap: 12px; justify-content: space-between; }
.g-title {
  margin: 0; font-size: clamp(20px, 3.4vmin, 32px); font-weight: 700;
  line-height: var(--bn-lh, 1.2); color: #ff6f9f;
  text-shadow: 0 3px 0 #fff;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; flex: 1 1 0;
}
.langs.small { flex: none; gap: 8px; flex-wrap: nowrap; }
.langs.small .lang-btn { padding: 6px; border-radius: 14px; border-width: 3px; }
.langs.small .flag { width: 46px; border-radius: 6px; }
.langs.small .lang-name { display: none; }
.top-btns { display: flex; gap: 10px; flex: 1 1 0; justify-content: flex-end; }

/* Spoken question */
.question {
  justify-self: center;
  display: flex; align-items: center; gap: 12px;
  max-width: 100%;
  padding: 8px 26px 8px 10px;
  background: #fff;
  border-radius: 999px;
  box-shadow: var(--shadow);
}
.q-speaker {
  width: 56px; height: 56px; flex: none; border-radius: 50%;
  font-size: 28px; background: #fff0f6;
  display: grid; place-items: center;
}
.question.talking .q-speaker { animation: talk .5s ease-in-out infinite alternate; background: #ffe0ee; }
@keyframes talk { to { transform: scale(1.12); } }
.q-text {
  font-size: clamp(26px, 5.2vmin, 54px); font-weight: 700;
  line-height: var(--bn-lh, 1.2);
}
.q-text.pop { animation: qpop .45s cubic-bezier(.3, 1.6, .5, 1); }
@keyframes qpop { from { transform: scale(.6); opacity: 0; } }

/* Stage + animal cards */
.stage {
  position: relative;
  container: stage / size;
  display: grid; place-items: center;
  min-height: 0;
}
.cards {
  --size: min(30cqw, 92cqh);
  --gap: 3.5cqmin;
  display: flex; gap: var(--gap); align-items: center; justify-content: center;
}
.card {
  position: relative;
  width: var(--size); aspect-ratio: 1;
  padding: 6%;
  border-radius: 14%;
  background: var(--tint, #fff);
  border: 5px solid #fff;
  box-shadow: 0 10px 0 rgba(255, 255, 255, .7), 0 14px 26px rgba(110, 140, 190, .3);
  animation: popIn .5s cubic-bezier(.3, 1.6, .5, 1) both;
  animation-delay: var(--delay, 0s);
  transition: opacity .35s, filter .35s, transform .2s;
}
/* Tall, narrow space (phone held upright): one column */
@container stage (max-aspect-ratio: 2 / 3) {
  .cards { flex-direction: column; --size: min(82cqw, 30cqh); }
}
/* Upright tablet: two on top, one below */
@container stage (min-aspect-ratio: 2 / 3) and (max-aspect-ratio: 1 / 1) {
  .cards { --size: min(45cqw, 45cqh); flex-wrap: wrap; width: calc(2 * var(--size) + var(--gap)); }
}
.card .art { display: block; width: 100%; height: 100%; pointer-events: none; }
.card .art svg { width: 100%; height: 100%; display: block; }
.card:active { transform: scale(.95); }

/* Name label, shown once a card has been tapped */
.label {
  position: absolute; left: 50%; bottom: -4%;
  transform: translate(-50%, 30%) scale(0);
  padding: .1em .7em;
  font-size: clamp(16px, calc(var(--size) * .1), 34px); font-weight: 700; line-height: var(--bn-lh, 1.25);
  white-space: nowrap;
  background: #fff; border-radius: 999px;
  box-shadow: 0 4px 10px rgba(110, 140, 190, .3);
  transition: transform .3s cubic-bezier(.3, 1.6, .5, 1);
  pointer-events: none;
}
.card.reveal .label { transform: translate(-50%, 30%) scale(1); }

@keyframes popIn { from { transform: scale(.3) rotate(-8deg); opacity: 0; } }

/* Right answer: jump and dance */
.card.correct { z-index: 2; animation: none; }
.card.correct .art { animation: dance 1.1s ease-in-out 2; }
.card.correct { box-shadow: 0 0 0 6px var(--yellow), 0 14px 30px rgba(255, 200, 60, .55); }
@keyframes dance {
  0%   { transform: translateY(0) scale(1) rotate(0); }
  15%  { transform: translateY(-18%) scale(1.1, .95) rotate(-8deg); }
  30%  { transform: translateY(0) scale(1.08, .92) rotate(0); }
  45%  { transform: translateY(-14%) scale(.95, 1.1) rotate(8deg); }
  60%  { transform: translateY(0) scale(1.06, .94) rotate(0); }
  75%  { transform: translateY(-6%) rotate(-5deg); }
  100% { transform: translateY(0) rotate(0); }
}
.card.dim { opacity: .35; filter: saturate(.4); }

/* Wrong answer: a gentle, friendly wiggle (no red, no crosses) */
.card.wiggle { animation: wiggle .6s ease-in-out; }
@keyframes wiggle {
  0%, 100% { transform: rotate(0); }
  20% { transform: rotate(-6deg) scale(.97); }
  40% { transform: rotate(5deg); }
  60% { transform: rotate(-3deg); }
  80% { transform: rotate(2deg); }
}
/* After a couple of misses the right card glows softly */
.card.hint { animation: glow 1.2s ease-in-out infinite; }
@keyframes glow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 210, 61, 0), 0 14px 26px rgba(110, 140, 190, .3); transform: scale(1); }
  50% { box-shadow: 0 0 0 10px rgba(255, 210, 61, .75), 0 14px 26px rgba(110, 140, 190, .3); transform: scale(1.04); }
}

/* Message bubble */
.toast {
  position: absolute; left: 50%; top: 4%;
  transform: translate(-50%, -20px) scale(.6);
  opacity: 0;
  padding: .25em .9em;
  font-size: clamp(26px, 5.5vmin, 52px); font-weight: 700; line-height: var(--bn-lh, 1.2);
  white-space: nowrap; max-width: 94%; overflow: hidden; text-overflow: ellipsis;
  border-radius: 999px;
  background: #fff;
  box-shadow: var(--shadow);
  pointer-events: none;
  z-index: 5;
  transition: transform .35s cubic-bezier(.3, 1.6, .5, 1), opacity .25s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0) scale(1); }
.toast.happy { color: #ff5e95; background: #fffbe0; }
.toast.soft  { color: #7b6bd6; background: #f3efff; }

/* ---------- Bottom bar: home, restart, progress, repeat ---------- */
.bottombar { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.bb-left { display: flex; gap: 10px; }
.progress {
  flex: 0 1 auto; min-width: 0;
  display: flex; align-items: center; gap: 12px;
  padding: 8px 16px;
  background: rgba(255, 255, 255, .85); border-radius: 999px;
  box-shadow: var(--shadow);
}
.stars { display: flex; gap: clamp(2px, .8vmin, 8px); }
.stars i {
  width: clamp(16px, 3.4vmin, 30px); aspect-ratio: 1;
  background: #e6dcf6;
  clip-path: polygon(50% 0, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
  transition: background .3s;
}
.stars i.on { background: var(--yellow); }
.stars i.new { animation: starPop .6s cubic-bezier(.3, 1.8, .5, 1); }
@keyframes starPop { from { transform: scale(2.4) rotate(-40deg); } }
.found { font-size: clamp(18px, 3vmin, 26px); font-weight: 700; white-space: nowrap; line-height: var(--bn-lh, 1.2); }

/* ---------- Sparkles ---------- */
.spark {
  position: fixed; z-index: 30; pointer-events: none;
  font-size: clamp(22px, 4vmin, 36px);
  transform: translate(-50%, -50%);
  animation: fly 1s ease-out forwards;
}
@keyframes fly {
  0%   { transform: translate(-50%, -50%) scale(.3); opacity: 1; }
  100% { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(1.2) rotate(40deg); opacity: 0; }
}

#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 40; }

/* ---------- Round celebration ---------- */
.celebrate {
  position: fixed; inset: 0; z-index: 20;
  display: grid; place-items: center;
  padding: 16px;
  background: rgba(255, 240, 248, .75);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.c-card {
  width: min(640px, 100%);
  max-height: 100%; overflow: hidden;
  padding: clamp(16px, 4vmin, 34px);
  text-align: center;
  background: #fff; border-radius: 36px;
  box-shadow: 0 20px 50px rgba(110, 140, 190, .35);
  animation: popIn .6s cubic-bezier(.3, 1.6, .5, 1);
}
.c-trophy { font-size: clamp(56px, 12vmin, 96px); line-height: 1; animation: bob 1.4s ease-in-out infinite; }
.c-card h2 { margin: 10px 0 14px; font-size: clamp(24px, 5vmin, 40px); color: #ff6f9f; line-height: var(--bn-lh, 1.2); }
.c-animals { display: grid; grid-template-columns: repeat(5, auto); justify-content: center; gap: 4px 8px; margin-bottom: 18px; }
.mini {
  width: clamp(44px, 9vmin, 72px); aspect-ratio: 1;
  animation: popIn .4s cubic-bezier(.3, 1.6, .5, 1) both, bob 1.6s ease-in-out infinite;
  animation-delay: calc(var(--i) * .08s), calc(var(--i) * .15s);
}
.mini svg { width: 100%; height: 100%; display: block; }
.c-btns { display: flex; justify-content: center; align-items: center; gap: 16px; flex-wrap: wrap; }

/* ---------- Small screens ---------- */
@media (max-width: 560px) {
  .g-title { display: none; }
  .top-btns { flex: none; }
  .topbar { justify-content: space-between; }
  .icon-btn { width: 50px; height: 50px; font-size: 24px; }
  .icon-btn.big { width: 60px; height: 60px; font-size: 30px; }
  .langs.small .flag { width: 38px; }
  .progress { padding: 6px 10px; gap: 6px; }
  .q-speaker { width: 44px; height: 44px; font-size: 22px; }
  .question { padding: 6px 18px 6px 6px; }
}
/* Narrow phones: stars in two rows of five so everything fits */
@media (max-width: 480px) {
  .stars { display: grid; grid-template-columns: repeat(5, 1fr); gap: 2px 3px; }
  .stars i { width: 17px; }
  .bb-left, .top-btns { gap: 8px; }
  .langs.small { gap: 6px; }
  .langs.small .lang-btn { padding: 5px; }
  .langs.small .flag { width: 34px; }
}
/* Short landscape phones */
@media (max-height: 460px) {
  .welcome { gap: 8px; }
  .p-animal { width: 70px; }
  .w-sub { display: none; }
  .icon-btn { width: 46px; height: 46px; font-size: 22px; }
  .icon-btn.big { width: 54px; height: 54px; font-size: 26px; }
  .q-speaker { width: 40px; height: 40px; font-size: 20px; }
  .question { padding: 4px 16px 4px 4px; }
  .game { gap: 6px; }
}

/* ---------- Calmer motion if the device asks for it ---------- */
@media (prefers-reduced-motion: reduce) {
  .cloud, .sun, .p-animal, .play-btn, .mini, .c-trophy { animation: none; }
  .card, .card.correct .art, .card.wiggle, .card.hint { animation-duration: .01s; animation-iteration-count: 1; }
  .card.hint { box-shadow: 0 0 0 8px rgba(255, 210, 61, .75); }
}
