*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  min-height: 100dvh;
  padding: 12px;
  color: #2d2a4a;
  font-family: "Fredoka", "Avenir Next Rounded", "Trebuchet MS", sans-serif;
  background: #7ad7ff;
}

button {
  font-family: inherit;
  cursor: pointer;
  color: inherit;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.scene {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  background:
    radial-gradient(circle at 18% 12%, #fff4b0 0 70px, transparent 72px),
    linear-gradient(180deg, #67d0ff 0%, #b7f1ff 46%, #d7f7c8 100%);
}

.sun {
  position: absolute;
  top: 28px;
  left: 8%;
  width: 84px;
  height: 84px;
  border-radius: 50%;
  background: #ffe56a;
  box-shadow: 0 0 0 14px rgba(255, 229, 106, 0.45);
}

.cloud {
  position: absolute;
  height: 28px;
  width: 92px;
  border-radius: 40px;
  background: #fff;
  opacity: 0.95;
}

.cloud::before,
.cloud::after {
  content: "";
  position: absolute;
  background: #fff;
  border-radius: 50%;
}

.cloud::before {
  width: 36px;
  height: 36px;
  top: -18px;
  left: 16px;
}

.cloud::after {
  width: 26px;
  height: 26px;
  top: -12px;
  left: 44px;
}

.cloud-a {
  top: 18%;
  right: 12%;
  animation: drift 18s linear infinite;
}

.cloud-b {
  top: 8%;
  left: 38%;
  transform: scale(0.8);
  animation: drift 24s linear infinite reverse;
}

.floater {
  position: absolute;
  font-size: 2rem;
  font-weight: 700;
  color: rgba(45, 42, 74, 0.18);
  animation: bob 6s ease-in-out infinite;
}

.f1 { top: 22%; left: 8%; }
.f2 { top: 62%; left: 6%; animation-delay: -1.5s; }
.f3 { top: 30%; right: 8%; animation-delay: -3s; }
.f4 { top: 70%; right: 10%; animation-delay: -2s; }

.hill {
  position: absolute;
  left: -10%;
  right: -10%;
  bottom: -10vh;
  height: 28vh;
  background: linear-gradient(#8ed86a, #5cb85a);
  border-radius: 50% 50% 0 0;
}

.app {
  position: relative;
  z-index: 1;
  width: min(560px, 100%);
  margin: max(12px, calc(50dvh - 430px)) auto 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #fff8ee;
  border: 4px solid #2d2a4a;
  border-radius: 32px;
  box-shadow: 0 10px 0 rgba(45, 42, 74, 0.22);
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.5rem, 4vw, 1.9rem);
  line-height: 1;
}

.tag {
  margin-top: 4px;
  color: #6d6785;
  font-size: 0.95rem;
}

.mascot {
  position: relative;
  flex: none;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: #ffe56a;
  border: 3px solid #2d2a4a;
  box-shadow: 0 4px 0 #e0b400;
}

.eye {
  position: absolute;
  top: 22px;
  width: 8px;
  height: 10px;
  border-radius: 50%;
  background: #2d2a4a;
  transform-origin: center;
  animation: blink 4.8s infinite;
}

.eye.left { left: 16px; }
.eye.right { right: 16px; animation-delay: 0.05s; }

.blush {
  position: absolute;
  top: 36px;
  width: 8px;
  height: 5px;
  border-radius: 50%;
  background: #ffb3c7;
}

.blush.left { left: 8px; }
.blush.right { right: 8px; }

.smile {
  position: absolute;
  left: 18px;
  right: 18px;
  bottom: 14px;
  height: 10px;
  border-bottom: 3px solid #2d2a4a;
  border-radius: 0 0 20px 20px;
}

.mascot.is-happy {
  animation: hop 0.45s ease;
}

.mascot.is-sad .smile {
  bottom: 16px;
  border-bottom: 0;
  border-top: 3px solid #2d2a4a;
  border-radius: 20px 20px 0 0;
}

.mascot.is-sad {
  animation: wobble 0.4s ease;
}

.stats {
  display: flex;
  gap: 8px;
}

.stats div {
  min-width: 58px;
  padding: 6px 8px 5px;
  text-align: center;
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 3px 0 #f0d8b0;
}

.stats strong {
  position: relative;
  display: block;
  font-size: 1.25rem;
  line-height: 1.1;
}

.stats small {
  color: #6d6785;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.stats strong.bump {
  animation: bump 0.3s ease;
}

.switch {
  display: grid;
  gap: 6px;
  padding: 6px;
  background: #ffe7c2;
  border-radius: 18px;
}

.switch-op {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.switch-level {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.switch button {
  min-width: 0;
  min-height: 42px;
  padding-inline: 4px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  font-size: clamp(0.92rem, 3.4vw, 1.15rem);
  font-weight: 700;
}

.switch button[aria-pressed="true"] {
  background: #2d2a4a;
  color: #fff8ee;
  box-shadow: 0 3px 0 #1b1830;
}

.lang-open {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 44px;
  border: 0;
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 3px 0 #f0d8b0;
  font-size: 1.05rem;
  font-weight: 700;
}

.lang-open .caret {
  color: #6d6785;
}

.lang-dialog {
  width: min(520px, calc(100vw - 24px));
  max-height: min(82dvh, 680px);
  padding: 0;
  border: 4px solid #2d2a4a;
  border-radius: 28px;
  background: #fff8ee;
  color: #2d2a4a;
  box-shadow: 0 10px 0 rgba(45, 42, 74, 0.22);
}

.lang-dialog::backdrop {
  background: rgba(45, 42, 74, 0.45);
}

.lang-card {
  max-height: min(82dvh, 680px);
  padding: 16px;
  overflow: auto;
}

.lang-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.lang-head h2 {
  font-size: 1.35rem;
}

.lang-close {
  flex: none;
  min-height: 40px;
  padding: 0 12px;
  border: 0;
  border-radius: 12px;
  background: #ffe56a;
  box-shadow: 0 3px 0 #e0b400;
  font-weight: 700;
}

.lang-close:active {
  transform: translateY(3px);
  box-shadow: 0 0 0 #e0b400;
}

.lang-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.lang-grid a {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 52px;
  padding: 8px 10px;
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 3px 0 #f0d8b0;
  color: inherit;
  font-weight: 700;
  line-height: 1.15;
  text-decoration: none;
}

.lang-grid a[aria-current="page"] {
  background: #2d2a4a;
  color: #fff8ee;
  box-shadow: 0 3px 0 #1b1830;
}

.lang-grid a:focus-visible {
  outline: 3px solid #2d2a4a;
  outline-offset: 3px;
}

.lang-flag {
  flex: none;
  font-size: 1.3rem;
  line-height: 1;
}

.play,
.results {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.play[hidden],
.results[hidden] {
  display: none;
}

.round-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 28px;
  color: #6d6785;
  font-size: 0.95rem;
  font-weight: 700;
}

.streak {
  padding: 2px 10px;
  color: #d23d55;
  background: #ffe1ec;
  border-radius: 999px;
}

.dots {
  display: flex;
  justify-content: center;
  gap: 6px;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #f0d8b0;
}

.dot.now {
  background: #2d2a4a;
}

.dot.ok {
  background: #22b573;
}

.dot.no {
  background: #ff6b81;
}

.card {
  padding: 22px 12px 16px;
  text-align: center;
  background: #fff;
  border-radius: 24px;
  box-shadow: 0 7px 0 #f0d8b0;
}

.problem {
  font-size: clamp(2.8rem, 12vw, 4.4rem);
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.03em;
}

.sign {
  display: inline-block;
  margin-inline: 0.08em;
}

.sign.add { color: #14945d; }
.sign.sub { color: #e24b6a; }
.sign.mul { color: #6b4ee6; }
.sign.div { color: #1d7ec4; }

.equals {
  margin-top: 8px;
  color: #8b849e;
  font-size: 1.25rem;
  font-weight: 700;
}

.cheer {
  min-height: 1.45em;
  text-align: center;
  font-size: 1.15rem;
  font-weight: 700;
}

.cheer.is-ok { color: #128a56; }
.cheer.is-no { color: #d23d55; }

.answers {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.answer,
.again {
  border: 0;
  border-radius: 18px;
  background: var(--fill);
  box-shadow: 0 5px 0 var(--edge);
  font-weight: 700;
}

.answer {
  position: relative;
  min-height: 76px;
  font-size: clamp(1.7rem, 6vw, 2.3rem);
}

.answer:nth-child(1) { --fill: #ffe56a; --edge: #e0b400; }
.answer:nth-child(2) { --fill: #9ef0c6; --edge: #2fbe86; }
.answer:nth-child(3) { --fill: #ffb7cb; --edge: #e56b8a; }
.answer:nth-child(4) { --fill: #a9dcff; --edge: #4aa7e0; }

.answer.is-correct {
  --fill: #3dce8b;
  --edge: #128a56;
}

.answer.is-wrong {
  --fill: #ff7d8a;
  --edge: #c23b4a;
}

.answer.is-correct::after,
.answer.is-wrong::after {
  position: absolute;
  top: 6px;
  inset-inline-end: 10px;
  font-size: 1.1rem;
  line-height: 1;
}

.answer.is-correct::after { content: "✓"; }
.answer.is-wrong::after { content: "✕"; }

.answer:disabled {
  opacity: 1;
  cursor: default;
}

.answer:active:not(:disabled),
.again:active {
  transform: translateY(4px);
  box-shadow: 0 1px 0 var(--edge);
}

.hint {
  text-align: center;
  color: #8b849e;
  font-size: 0.85rem;
}

.results {
  align-items: center;
  padding: 8px 4px 2px;
  text-align: center;
}

.stars {
  font-size: 3.2rem;
  letter-spacing: 0.08em;
  line-height: 1;
}

.star {
  color: transparent;
  -webkit-text-stroke: 3px #e0b400;
}

.star.on {
  color: #ffd23f;
  -webkit-text-stroke: 0;
  animation: hop 0.4s ease both;
}

h2 {
  font-size: clamp(1.8rem, 6vw, 2.5rem);
}

#result-detail {
  color: #6d6785;
  font-size: 1.15rem;
}

.result-score {
  font-size: 1.25rem;
  font-weight: 700;
}

.again {
  width: 100%;
  min-height: 64px;
  margin-top: 6px;
  --fill: #ffe56a;
  --edge: #e0b400;
  font-size: 1.4rem;
}

button:focus-visible {
  outline: 3px solid #2d2a4a;
  outline-offset: 3px;
}

.float-score {
  position: fixed;
  z-index: 4;
  color: #128a56;
  font-size: 1.4rem;
  font-weight: 700;
  pointer-events: none;
  transform: translate(-50%, 0);
  animation: float-up 0.7s ease-out forwards;
}

.confetti {
  position: fixed;
  z-index: 4;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  pointer-events: none;
  animation: burst 700ms ease-out forwards;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.noscript {
  position: relative;
  z-index: 1;
  margin: 12px auto;
  max-width: 560px;
  padding: 12px;
  text-align: center;
  background: #fff8ee;
  border-radius: 16px;
}

@media (hover: hover) {
  .answer:hover:not(:disabled):not(:active),
  .again:hover:not(:active) {
    transform: translateY(-2px);
  }
}

@media (pointer: coarse) {
  .hint {
    display: none;
  }
}

@media (max-width: 360px) and (max-height: 640px) {
  body {
    padding: 4px;
  }

  .app {
    gap: 8px;
    margin: 4px auto;
    padding: 10px;
  }

  .card {
    padding: 12px 8px 8px;
  }

  .problem {
    font-size: 2.4rem;
  }

  .switch button {
    min-height: 36px;
  }

  .answer {
    min-height: 56px;
  }

  .lang-open {
    min-height: 36px;
  }
}

@media (max-width: 380px) {
  .top {
    gap: 8px;
  }

  .stats div {
    min-width: 48px;
    padding: 4px 6px;
  }

  h1 {
    font-size: 1.35rem;
  }

  .mascot {
    width: 52px;
    height: 52px;
  }

  .eye { top: 17px; }
  .eye.left { left: 12px; }
  .eye.right { right: 12px; }
  .smile { left: 14px; right: 14px; bottom: 10px; }
  .blush { top: 28px; }
  .tag { display: none; }
  .answer { min-height: 68px; }
}

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

@keyframes blink {
  0%, 92%, 100% { transform: scaleY(1); }
  96% { transform: scaleY(0.15); }
}

@keyframes hop {
  0% { transform: translateY(0) scale(1); }
  40% { transform: translateY(-8px) scale(1.06); }
  100% { transform: translateY(0) scale(1); }
}

@keyframes wobble {
  0%, 100% { transform: rotate(0); }
  30% { transform: rotate(-8deg); }
  70% { transform: rotate(8deg); }
}

@keyframes bump {
  50% { transform: scale(1.28); }
}

@keyframes float-up {
  from {
    transform: translate(-50%, 0);
    opacity: 1;
  }
  to {
    transform: translate(-50%, -36px);
    opacity: 0;
  }
}

@keyframes burst {
  to {
    transform: translate(var(--dx), var(--dy)) rotate(200deg);
    opacity: 0;
  }
}

@keyframes drift {
  from { transform: translateX(0); }
  to { transform: translateX(24px); }
}

@keyframes bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}
