:root {
  --ink: #223047;
  --muted: #6f7785;
  --paper: #fffaf0;
  --panel: #ffffff;
  --sun: #ffbd3d;
  --coral: #ff735e;
  --mint: #4dc6a5;
  --sky: #54a9e8;
  --violet: #8f7ee7;
  --shadow: 0 7px 0 rgba(63, 48, 31, 0.12);
}
* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  min-height: 100dvh;
  color: var(--ink);
  background-color: #f8e8c8;
  background-image:
    radial-gradient(circle at 12px 12px, rgba(255, 255, 255, 0.7) 0 2px, transparent 2.5px);
  background-size: 24px 24px;
  font-family: "Arial Rounded MT Bold", "Nunito", "Microsoft YaHei", system-ui, sans-serif;
  user-select: none;
}

button {
  font: inherit;
}

.game-shell {
  width: 100%;
  height: 100dvh;
  display: grid;
  grid-template-rows: clamp(118px, 18vh, 172px) minmax(0, 1fr);
  gap: clamp(7px, 1vh, 12px);
  padding: clamp(8px, 1.3vw, 18px);
}

.challenge-bar {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(190px, 1fr) minmax(310px, 1.25fr) minmax(170px, 1fr);
  align-items: center;
  gap: clamp(10px, 1.5vw, 24px);
  padding: clamp(9px, 1.2vh, 14px) clamp(12px, 1.5vw, 24px);
  border: 3px solid rgba(34, 48, 71, 0.11);
  border-radius: 24px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.brand {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  flex: 0 0 auto;
  width: clamp(46px, 6vh, 64px);
  height: clamp(46px, 6vh, 64px);
  display: grid;
  place-items: center;
  border: 3px solid var(--ink);
  border-radius: 18px 18px 22px 22px;
  color: #fff;
  background: var(--coral);
  box-shadow: 4px 4px 0 var(--sun);
  font-size: clamp(24px, 3.5vh, 38px);
  font-weight: 1000;
  transform: rotate(-3deg);
}

.brand h1,
.brand p {
  margin: 0;
}

.brand h1 {
  overflow: hidden;
  font-size: clamp(17px, 1.65vw, 28px);
  line-height: 1.08;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.brand p {
  margin-top: 5px;
  color: var(--muted);
  font-size: clamp(10px, 1vw, 15px);
  font-weight: 800;
  letter-spacing: 0.08em;
}

.question-card {
  min-width: 0;
  align-self: stretch;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(8px, 1.2vw, 18px);
  padding: 8px clamp(10px, 1.2vw, 18px);
  border: 3px solid var(--ink);
  border-radius: 20px;
  background: #fff4cf;
  box-shadow: 4px 4px 0 var(--ink);
}

.question-label,
.question-hint {
  color: #7a5d21;
  font-weight: 900;
  white-space: nowrap;
}

.question-label {
  padding: 5px 8px;
  border-radius: 8px;
  background: var(--sun);
  font-size: clamp(10px, 0.9vw, 13px);
}

.question-hint {
  font-size: clamp(9px, 0.9vw, 13px);
}

.equation {
  min-width: 0;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(4px, 0.65vw, 10px);
  font-family: "Arial Rounded MT Bold", "Trebuchet MS", system-ui, sans-serif;
  font-size: clamp(25px, 4vh, 48px);
  font-weight: 1000;
  line-height: 1;
  white-space: nowrap;
}

.equation-number-block {
  width: clamp(74px, 12vh, 126px);
  height: clamp(74px, 12vh, 126px);
  object-fit: contain;
  filter: drop-shadow(0 3px 0 rgba(34, 48, 71, 0.14));
}

.equation-number {
  position: relative;
  display: grid;
  place-items: center;
}

.equation-number-label {
  position: absolute;
  right: -2px;
  bottom: -2px;
  min-width: 1.65em;
  padding: 0.14em 0.35em;
  border: 2px solid var(--ink);
  border-radius: 999px;
  color: #fff;
  background: var(--coral);
  box-shadow: 2px 2px 0 var(--ink);
  font-size: clamp(15px, 2.3vh, 25px);
  line-height: 1;
  text-align: center;
}

.equation-symbol {
  flex: 0 0 auto;
}

.question-mark {
  color: var(--coral);
}

.game-stats {
  display: flex;
  align-items: stretch;
  justify-content: flex-end;
  gap: 10px;
}

.stat {
  min-width: 88px;
  display: grid;
  place-items: center;
  padding: 6px 12px;
  border: 2px solid rgba(34, 48, 71, 0.15);
  border-radius: 15px;
  background: #f4fbff;
}

.stat-label {
  color: var(--muted);
  font-size: clamp(9px, 0.8vw, 12px);
  font-weight: 800;
  white-space: nowrap;
}

.stat strong {
  color: var(--coral);
  font-size: clamp(22px, 3vh, 34px);
  line-height: 1;
}

.sound-button {
  min-width: 74px;
  border: 2px solid var(--ink);
  border-radius: 15px;
  color: var(--ink);
  background: #dff7ef;
  box-shadow: 3px 3px 0 var(--ink);
  cursor: pointer;
  font-weight: 900;
}

.sound-button span {
  display: block;
}

.sound-button:active {
  box-shadow: 1px 1px 0 var(--ink);
  transform: translate(2px, 2px);
}

.number-grid {
  width: min(100%, 1160px);
  min-height: 0;
  justify-self: center;
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  grid-template-rows: repeat(10, minmax(0, 1fr));
  gap: clamp(3px, 0.42vw, 8px);
}

.number-card {
  min-width: 0;
  min-height: 0;
  position: relative;
  display: grid;
  grid-template-rows: 58% 42%;
  place-items: stretch;
  padding: 0;
  overflow: hidden;
  border: 2px solid rgba(34, 48, 71, 0.2);
  border-radius: clamp(7px, 0.8vw, 13px);
  color: var(--ink);
  background: var(--card-color, #fff);
  box-shadow: 0 clamp(2px, 0.32vh, 4px) 0 var(--card-shadow, rgba(34, 48, 71, 0.18));
  cursor: pointer;
  isolation: isolate;
  transition: transform 90ms ease, box-shadow 90ms ease, filter 90ms ease;
  touch-action: manipulation;
}

.number-card::after {
  content: "";
  position: absolute;
  inset: 58% 7px auto;
  height: 1px;
  background: rgba(34, 48, 71, 0.14);
}

.number-card:hover,
.number-card:focus-visible {
  z-index: 2;
  outline: none;
  filter: saturate(1.16);
  transform: translateY(-2px) scale(1.035);
  box-shadow: 0 5px 0 var(--card-shadow, rgba(34, 48, 71, 0.18));
}

.number-card:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 1px;
}

.number-card:active,
.number-card.is-pressed {
  transform: translateY(2px) scale(0.97);
  box-shadow: 0 0 0 transparent;
}

.number-card.is-wrong {
  animation: nope 380ms ease;
}

.number-card.is-correct {
  z-index: 3;
  outline: 4px solid #16856b;
  filter: saturate(1.25) brightness(1.06);
}

.number {
  min-height: 0;
  display: grid;
  place-items: center;
  padding-top: 1px;
  font-family: "Arial Rounded MT Bold", "Trebuchet MS", system-ui, sans-serif;
  font-size: clamp(13px, min(2.15vw, 3vh), 32px);
  font-weight: 1000;
  line-height: 0.95;
}

.word {
  min-width: 0;
  display: grid;
  place-items: center;
  padding: 1px 2px 2px;
  overflow: hidden;
  font-family: "Trebuchet MS", Arial, sans-serif;
  font-size: clamp(6px, min(0.78vw, 1.3vh), 12px);
  font-weight: 900;
  line-height: 1;
  letter-spacing: -0.025em;
  white-space: nowrap;
  text-overflow: clip;
}

.number-card:nth-child(5n + 1) { --card-color: #ffe5df; --card-shadow: #eab4a9; }
.number-card:nth-child(5n + 2) { --card-color: #fff0bc; --card-shadow: #e2c879; }
.number-card:nth-child(5n + 3) { --card-color: #d9f3e9; --card-shadow: #9bcdbd; }
.number-card:nth-child(5n + 4) { --card-color: #dceefe; --card-shadow: #a3c8e7; }
.number-card:nth-child(5n) { --card-color: #e9e3ff; --card-shadow: #bcb2e9; }

.feedback {
  position: fixed;
  left: 50%;
  bottom: clamp(12px, 2vh, 24px);
  z-index: 20;
  max-width: min(90vw, 460px);
  padding: 10px 18px;
  border: 2px solid var(--ink);
  border-radius: 99px;
  color: #fff;
  background: var(--ink);
  box-shadow: 3px 3px 0 rgba(255, 255, 255, 0.9);
  font-size: clamp(12px, 1.2vw, 17px);
  font-weight: 900;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition: opacity 180ms ease, transform 180ms ease;
}

.feedback.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.success-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(34, 48, 71, 0.3);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 220ms ease, visibility 220ms ease;
}

.success-overlay.is-visible {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.success-card {
  width: min(76vw, 560px);
  position: relative;
  overflow: hidden;
  padding: clamp(30px, 6vh, 68px) 30px clamp(25px, 5vh, 52px);
  border: clamp(4px, 0.5vw, 7px) solid var(--ink);
  border-radius: clamp(24px, 4vw, 48px);
  background: #fff9e9;
  box-shadow: 12px 12px 0 var(--sun);
  text-align: center;
  transform: rotate(-2deg) scale(0.7);
}

.is-visible .success-card {
  animation: success-pop 520ms cubic-bezier(0.18, 0.89, 0.32, 1.28) forwards;
}

.success-star {
  position: absolute;
  top: 16px;
  right: 24px;
  color: var(--sun);
  font-size: clamp(34px, 5vw, 64px);
  transform: rotate(12deg);
}

.success-kicker,
.success-card h2,
.success-card p {
  margin: 0;
}

.success-kicker {
  color: var(--coral);
  font-size: clamp(16px, 2vw, 25px);
  font-weight: 1000;
  letter-spacing: 0.15em;
}

.success-card h2 {
  margin-top: 6px;
  font-size: clamp(54px, 9vw, 110px);
  font-weight: 1000;
  line-height: 1;
}

.success-card > p:last-of-type {
  margin-top: 13px;
  color: #5b6574;
  font-family: "Trebuchet MS", Arial, sans-serif;
  font-size: clamp(17px, 2.4vw, 30px);
  font-weight: 900;
}

.countdown-track {
  height: 8px;
  margin: clamp(20px, 4vh, 38px) auto 0;
  overflow: hidden;
  border-radius: 99px;
  background: #eadfc8;
}

.countdown-track span {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: var(--mint);
  transform-origin: left;
}

.is-visible .countdown-track span {
  animation: countdown 5s linear forwards;
}

#confetti {
  position: fixed;
  inset: 0;
  z-index: 40;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

@keyframes nope {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px) rotate(-1deg); }
  75% { transform: translateX(5px) rotate(1deg); }
}

@keyframes success-pop {
  0% { transform: rotate(-4deg) scale(0.7); }
  70% { transform: rotate(1deg) scale(1.04); }
  100% { transform: rotate(0) scale(1); }
}

@keyframes countdown {
  to { transform: scaleX(0); }
}

@media (max-width: 820px) {
  .game-shell {
    grid-template-rows: clamp(94px, 18vh, 122px) minmax(0, 1fr);
    padding: 6px;
    gap: 6px;
  }

  .challenge-bar {
    grid-template-columns: auto 1fr auto;
    gap: 7px;
    padding: 6px 8px;
    border-width: 2px;
    border-radius: 16px;
  }

  .brand-mark { width: 40px; height: 40px; border-radius: 13px; }
  .brand h1 { font-size: 12px; }
  .brand p, .question-label, .question-hint, .stat-label { display: none; }
  .question-card { min-width: 150px; padding-inline: 5px; border-width: 2px; border-radius: 14px; box-shadow: 2px 2px 0 var(--ink); }
  .equation { gap: 3px; font-size: clamp(20px, 4.2vh, 34px); }
  .equation-number-block { width: clamp(52px, 11vh, 76px); height: clamp(52px, 11vh, 76px); }
  .equation-number-label { font-size: clamp(11px, 2.4vh, 17px); border-width: 1px; box-shadow: 1px 1px 0 var(--ink); }
  .game-stats { gap: 5px; }
  .stat { min-width: 42px; padding: 4px 7px; border-radius: 11px; }
  .sound-button { min-width: 42px; padding: 3px; border-radius: 11px; box-shadow: 2px 2px 0 var(--ink); }
  .sound-button span:last-child { display: none; }
  .number-grid { gap: 2px; }
  .number-card { border-width: 1px; border-radius: 5px; }
  .number-card::after { inset-inline: 3px; }
  .word { letter-spacing: -0.08em; }
}

@media (max-width: 600px) and (orientation: portrait) {
  .number-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    grid-template-rows: repeat(20, minmax(0, 1fr));
  }
}

@media (max-height: 610px) {
  .game-shell { grid-template-rows: 96px minmax(0, 1fr); }
  .challenge-bar { padding-block: 5px; }
  .brand-mark { width: 42px; height: 42px; }
  .brand p, .question-hint { display: none; }
  .number-card { border-radius: 6px; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
  }
}
