:root {
  --sky-top: #6ec6e8;
  --sky-mid: #9ddcf0;
  --sky-bottom: #d8f3c9;
  --grass: #5fbf7a;
  --grass-deep: #3f9a5a;
  --sun: #ffe066;
  --card: #fffdf7;
  --ink: #1f3b2c;
  --muted: #4d6b5a;
  --accent: #ff7a59;
  --accent-deep: #e85a38;
  --good: #2fbf71;
  --bad: #ff5d6c;
  --chip: #ffffffcc;
  --shadow: 0 14px 28px rgba(31, 59, 44, 0.18);
  --radius: 28px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-synthesis: none;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  min-height: 100dvh;
  font-family: "Nunito", system-ui, sans-serif;
  color: var(--ink);
  background: var(--sky-mid);
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
}

body {
  position: relative;
}

button {
  font: inherit;
  border: 0;
  cursor: pointer;
  color: inherit;
}

.sky {
  position: fixed;
  inset: 0;
  z-index: 0;
  background:
    radial-gradient(circle at 18% 12%, rgba(255, 255, 255, 0.45), transparent 28%),
    linear-gradient(180deg, var(--sky-top) 0%, var(--sky-mid) 42%, var(--sky-bottom) 78%, #b8e58a 100%);
  pointer-events: none;
}

.sun {
  position: absolute;
  top: 7%;
  right: 10%;
  width: 74px;
  height: 74px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff7b0, var(--sun) 55%, #f5b83d);
  box-shadow: 0 0 0 10px rgba(255, 224, 102, 0.28), 0 0 40px rgba(255, 200, 60, 0.45);
  animation: sun-breathe 5s ease-in-out infinite;
}

.cloud {
  position: absolute;
  background: #fff;
  border-radius: 999px;
  opacity: 0.88;
  filter: drop-shadow(0 8px 10px rgba(40, 90, 120, 0.12));
  animation: drift 18s linear infinite;
}

.cloud::before,
.cloud::after {
  content: "";
  position: absolute;
  background: #fff;
  border-radius: 50%;
}

.cloud-a {
  top: 14%;
  left: -10%;
  width: 92px;
  height: 34px;
  animation-duration: 22s;
}

.cloud-a::before {
  width: 42px;
  height: 42px;
  top: -22px;
  left: 14px;
}

.cloud-a::after {
  width: 54px;
  height: 54px;
  top: -28px;
  left: 40px;
}

.cloud-b {
  top: 22%;
  left: 30%;
  width: 70px;
  height: 26px;
  animation-duration: 26s;
  animation-delay: -8s;
}

.cloud-b::before {
  width: 34px;
  height: 34px;
  top: -18px;
  left: 10px;
}

.cloud-b::after {
  width: 42px;
  height: 42px;
  top: -22px;
  left: 28px;
}

.cloud-c {
  top: 10%;
  left: 70%;
  width: 84px;
  height: 30px;
  animation-duration: 20s;
  animation-delay: -4s;
}

.cloud-c::before {
  width: 38px;
  height: 38px;
  top: -20px;
  left: 12px;
}

.cloud-c::after {
  width: 48px;
  height: 48px;
  top: -26px;
  left: 34px;
}

.hill {
  position: absolute;
  left: -10%;
  right: -10%;
  border-radius: 50% 50% 0 0;
}

.hill-back {
  bottom: -8%;
  height: 28%;
  background: #79c98a;
}

.hill-front {
  bottom: -14%;
  height: 24%;
  background: var(--grass);
  box-shadow: inset 0 12px 0 rgba(255, 255, 255, 0.12);
}

.app {
  position: relative;
  z-index: 1;
  width: min(480px, 100%);
  margin: 0 auto;
  min-height: 100dvh;
  padding: calc(18px + var(--safe-top)) 18px calc(24px + var(--safe-bottom));
  display: grid;
}

.screen {
  display: none;
  flex-direction: column;
  gap: 18px;
  animation: rise-in 420ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

.screen.is-active {
  display: flex;
}

.brand {
  text-align: center;
  padding-top: 8px;
}

.mascot {
  width: 84px;
  height: 84px;
  margin: 0 auto 8px;
  display: grid;
  place-items: center;
  font-size: 48px;
  background: var(--card);
  border-radius: 28px;
  box-shadow: var(--shadow);
  animation: bounce-soft 2.4s ease-in-out infinite;
}

.brand-title {
  margin: 0;
  font-family: "Baloo 2", "Nunito", sans-serif;
  font-size: clamp(2.4rem, 10vw, 3.2rem);
  line-height: 1;
  letter-spacing: 0.02em;
  color: #18472f;
  text-shadow: 0 3px 0 rgba(255, 255, 255, 0.35);
}

.brand-sub {
  margin: 6px 0 0;
  color: var(--muted);
  font-weight: 700;
  font-size: 1rem;
}

.stats-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.stat-pill {
  background: var(--chip);
  backdrop-filter: blur(8px);
  border-radius: 20px;
  padding: 12px 8px;
  text-align: center;
  box-shadow: 0 8px 18px rgba(31, 59, 44, 0.1);
}

.stat-label {
  display: block;
  font-size: 0.78rem;
  font-weight: 800;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat-pill strong {
  font-family: "Baloo 2", sans-serif;
  font-size: 1.55rem;
  line-height: 1.1;
}

.chooser {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px 16px 16px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 12px;
}

.chooser-title {
  margin: 4px 0 0;
  font-family: "Baloo 2", sans-serif;
  font-size: 1.25rem;
}

.chip-row,
.diff-row {
  display: grid;
  gap: 10px;
}

.chip-row {
  grid-template-columns: 1fr;
}

@media (min-width: 380px) {
  .chip-row {
    grid-template-columns: repeat(3, 1fr);
  }

  .chip-row-2 {
    grid-template-columns: 1fr 1fr;
  }
}

.chip-row-2 {
  grid-template-columns: 1fr 1fr;
}

.chip,
.diff {
  background: #eef8ef;
  border-radius: 18px;
  padding: 12px 10px;
  font-weight: 800;
  transition: transform 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.chip:active,
.diff:active,
.btn-primary:active,
.answer:active {
  transform: scale(0.96);
}

.chip.is-selected,
.diff.is-selected {
  background: #ffe8a8;
  box-shadow: inset 0 0 0 3px #f0b429;
}

.diff-row {
  grid-template-columns: repeat(3, 1fr);
}

.diff {
  display: grid;
  gap: 2px;
  justify-items: center;
  min-height: 96px;
}

.diff-emoji {
  font-size: 1.5rem;
}

.diff-name {
  font-family: "Baloo 2", sans-serif;
  font-size: 1.05rem;
}

.diff-hint {
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 700;
}

.btn-primary {
  margin-top: 4px;
  background: linear-gradient(180deg, #ff8f6f, var(--accent));
  color: #fff;
  border-radius: 999px;
  padding: 18px 20px;
  font-family: "Baloo 2", sans-serif;
  font-size: 1.55rem;
  letter-spacing: 0.02em;
  box-shadow: 0 12px 0 var(--accent-deep), 0 18px 24px rgba(232, 90, 56, 0.28);
}

.btn-primary:active {
  box-shadow: 0 6px 0 var(--accent-deep), 0 10px 16px rgba(232, 90, 56, 0.25);
  translate: 0 6px;
}

.install-hint {
  margin: 0;
  text-align: center;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.play-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.btn-ghost {
  width: 48px;
  height: 48px;
  border-radius: 16px;
  background: var(--chip);
  font-size: 1.4rem;
  font-weight: 800;
  box-shadow: 0 6px 14px rgba(31, 59, 44, 0.12);
}

.live-stats {
  display: flex;
  gap: 10px;
}

.live-item {
  background: var(--chip);
  border-radius: 999px;
  padding: 10px 14px;
  font-weight: 800;
  box-shadow: 0 6px 14px rgba(31, 59, 44, 0.1);
}

.question-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px 16px 14px;
  box-shadow: var(--shadow);
  text-align: center;
  min-height: 160px;
  display: grid;
  align-content: center;
  gap: 8px;
  transition: transform 0.25s ease, box-shadow 0.25s ease;
}

.question-prompt {
  margin: 0;
  color: var(--muted);
  font-weight: 800;
}

.equation {
  font-family: "Baloo 2", sans-serif;
  font-size: clamp(2.4rem, 11vw, 3.3rem);
  line-height: 1.05;
  letter-spacing: 0.03em;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 0.25em;
}

.answer-slot {
  display: inline-grid;
  place-items: center;
  min-width: 1.4em;
  min-height: 1.15em;
  padding: 0 0.2em;
  border-radius: 16px;
  background: #eef8ef;
  box-shadow: inset 0 0 0 3px #cfe8d4;
  color: var(--ink);
}

.answer-slot.is-empty {
  color: #9bb5a4;
}

.answer-slot.is-correct {
  background: #b8f5cb;
  box-shadow: inset 0 0 0 3px #2fbf71;
}

.answer-slot.is-wrong {
  background: #ffd0d6;
  box-shadow: inset 0 0 0 3px #ff5d6c;
  animation: shake 420ms ease;
}

.visual-aids {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 14px;
  min-height: 42px;
  margin-top: 4px;
}

.aid-group {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  max-width: 160px;
}

.aid-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #ff9f43;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.12);
  animation: pop-in 360ms cubic-bezier(0.2, 1.4, 0.3, 1) both;
}

.aid-dot.berry {
  background: #ff6b8a;
}

.aid-op {
  align-self: center;
  font-family: "Baloo 2", sans-serif;
  font-size: 1.5rem;
  color: var(--muted);
}

.answers {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.answers[hidden],
.keypad[hidden] {
  display: none !important;
}

.answer {
  min-height: 84px;
  border-radius: 24px;
  background: #fff;
  font-family: "Baloo 2", sans-serif;
  font-size: 2rem;
  box-shadow: 0 10px 0 #d7e8d9, 0 14px 22px rgba(31, 59, 44, 0.12);
  transition: transform 0.12s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.answer:active {
  box-shadow: 0 4px 0 #d7e8d9, 0 8px 14px rgba(31, 59, 44, 0.12);
  translate: 0 6px;
}

.answer.is-correct {
  background: #b8f5cb;
  box-shadow: 0 10px 0 #2fbf71, 0 14px 22px rgba(47, 191, 113, 0.25);
}

.answer.is-wrong {
  background: #ffd0d6;
  box-shadow: 0 10px 0 #ff5d6c, 0 14px 22px rgba(255, 93, 108, 0.2);
  animation: shake 420ms ease;
}

.answer:disabled {
  cursor: default;
}

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: auto;
}

.key {
  min-height: 64px;
  border-radius: 20px;
  background: #fff;
  font-family: "Baloo 2", sans-serif;
  font-size: 1.85rem;
  box-shadow: 0 8px 0 #d7e8d9, 0 12px 18px rgba(31, 59, 44, 0.12);
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.key:active {
  box-shadow: 0 3px 0 #d7e8d9, 0 6px 12px rgba(31, 59, 44, 0.12);
  translate: 0 5px;
}

.key:disabled {
  opacity: 0.55;
  cursor: default;
}

.key-action {
  background: #ffe8a8;
  box-shadow: 0 8px 0 #e0c15a, 0 12px 18px rgba(31, 59, 44, 0.12);
}

.key-action:active {
  box-shadow: 0 3px 0 #e0c15a, 0 6px 12px rgba(31, 59, 44, 0.12);
}

.key-ok {
  background: linear-gradient(180deg, #7be39a, #2fbf71);
  color: #fff;
  box-shadow: 0 8px 0 #1f9a58, 0 12px 18px rgba(47, 191, 113, 0.28);
}

.key-ok:active {
  box-shadow: 0 3px 0 #1f9a58, 0 6px 12px rgba(47, 191, 113, 0.22);
}

.feedback {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: calc(12px + var(--safe-top)) 18px calc(12px + var(--safe-bottom));
  background: rgba(18, 42, 28, 0.55);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  pointer-events: auto;
  animation: fade-veil 220ms ease;
}

.feedback[hidden] {
  display: none !important;
}

.feedback-card {
  position: relative;
  z-index: 2;
  width: min(280px, 82vw);
  padding: 28px 20px 24px;
  border-radius: 36px;
  background: #fffdf7;
  box-shadow: 0 22px 40px rgba(0, 0, 0, 0.22);
  display: grid;
  justify-items: center;
  gap: 12px;
  animation: badge-pop 480ms cubic-bezier(0.2, 1.45, 0.3, 1);
}

.feedback-mark {
  width: min(140px, 36vw);
  height: min(140px, 36vw);
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: clamp(4rem, 16vw, 5.5rem);
  font-weight: 800;
  line-height: 1;
  color: #fff;
}

.feedback.is-good .feedback-mark {
  background: linear-gradient(180deg, #5fe08f, #2fbf71);
  box-shadow: 0 12px 0 #1f9a58;
}

.feedback.is-bad .feedback-mark {
  background: linear-gradient(180deg, #ff8a96, #ff5d6c);
  box-shadow: 0 12px 0 #d64552;
  animation: shake 420ms ease;
}

.feedback-text {
  margin: 0;
  font-family: "Baloo 2", sans-serif;
  font-size: clamp(1.7rem, 7vw, 2.1rem);
  line-height: 1.1;
  text-align: center;
}

.feedback.is-good .feedback-text {
  color: #176b3c;
}

.feedback.is-bad .feedback-text {
  color: #a51d34;
}

.feedback-burst {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.particle {
  position: absolute;
  left: 50%;
  top: 48%;
  width: 16px;
  height: 16px;
  border-radius: 5px;
  animation: burst 950ms ease-out forwards;
}

body.is-feedback .question-card,
body.is-feedback .keypad,
body.is-feedback .answers,
body.is-feedback .play-top {
  visibility: hidden;
}

.question-card.is-success {
  animation: success-pulse 560ms ease;
}

.question-card.is-fail {
  animation: fail-wobble 480ms ease;
}

@keyframes drift {
  from { transform: translateX(0); }
  to { transform: translateX(120vw); }
}

@keyframes sun-breathe {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}

@keyframes bounce-soft {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

@keyframes rise-in {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes pop-in {
  from { opacity: 0; transform: scale(0.4); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(6px); }
}

@keyframes success-pulse {
  0% { transform: scale(1); }
  40% { transform: scale(1.04); }
  100% { transform: scale(1); }
}

@keyframes fail-wobble {
  0%, 100% { transform: rotate(0deg); }
  25% { transform: rotate(-2deg); }
  75% { transform: rotate(2deg); }
}

@keyframes burst {
  0% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(0.4) rotate(160deg);
  }
}

@keyframes badge-pop {
  0% { opacity: 0; transform: scale(0.4); }
  60% { opacity: 1; transform: scale(1.06); }
  100% { opacity: 1; transform: scale(1); }
}

@keyframes fade-veil {
  from { opacity: 0; }
  to { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
