.math-main { max-width: 1100px; margin: 0 auto; padding-bottom: 20px; }
.math-main > .game-heading { margin: 4px 0 12px; }
.math-main [hidden] { display: none; }

.math-panel {
  display: flex;
  flex: 1;
  flex-direction: column;
  justify-content: center;
  padding: 20px;
  padding: clamp(16px, 4vw, 36px);
  border: 1px solid #30394c;
  border-radius: 20px;
  background: #111827;
}

.math-menu fieldset { min-width: 0; margin: 0 0 18px; padding: 0; border: 0; }
.math-menu legend { margin-bottom: 8px; font-size: 1.15rem; font-weight: 700; }
.math-choices, .math-answers { display: flex; flex-wrap: wrap; margin: -4px; }
.math-choices label { position: relative; display: flex; flex: 1; min-width: 0; margin: 4px; }
.math-choices input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.math-choices label > span {
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 72px;
  padding: 6px 2px;
  border: 2px solid #46516a;
  border-radius: 12px;
  background: #1b2232;
  color: #f8fafc;
  cursor: pointer;
  font-weight: 700;
  text-align: center;
}
.math-choices label:hover > span { border-color: #657188; }
.math-choices input:checked + span { background: #0755ec; color: #fff; border-color: #78a4ff; }
.math-choices input:focus + span { outline: 3px solid #a7d2ff; outline-offset: 2px; }
@supports selector(:focus-visible) {
  .math-choices input:focus:not(:focus-visible) + span { outline: none; }
}
.math-choices small { font-size: 0.85rem; }
.math-choices b { font-size: 1.6rem; line-height: 1.15; }
.math-choices .math-level-progress { font-size: 0.6875rem; line-height: 1.25; }
.math-crown {
  position: absolute;
  top: 5px;
  right: 6px;
  color: #ffda72;
  font-size: 1.25rem;
  line-height: 1;
}
@supports (clip-path: polygon(0 0, 100% 0, 100% 100%)) {
  .math-crown {
    width: 19px;
    height: 14px;
    background: #ffda72;
    clip-path: polygon(0 16%, 25% 43%, 50% 0, 75% 43%, 100% 16%, 88% 82%, 12% 82%);
    font-size: 0;
  }
}
.math-crown-hint { margin: 0 0 12px; color: #d5e3ff; font-size: 0.875rem; }

.math-primary {
  min-height: 56px;
  padding: 10px 20px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: #0755ec;
  color: #fff;
  font-weight: 650;
  touch-action: manipulation;
}
.math-menu > .math-primary { align-self: flex-start; }
.math-primary:hover { background: #164dca; }
.math-round-top, .math-round-bottom {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
}
.math-round { position: relative; }
.math-confetti {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 1;
  overflow: hidden;
  border-radius: inherit;
  pointer-events: none;
}
.math-confetti span {
  position: absolute;
  width: 8px;
  height: 12px;
  border-radius: 2px;
  animation: math-confetti-burst 750ms ease-out both;
}
.math-confetti span:nth-child(2n) { width: 6px; height: 6px; border-radius: 50%; }
@keyframes math-confetti-burst {
  0% { opacity: 1; transform: scale(0.4); }
  60% { opacity: 1; }
  100% { opacity: 0; transform: translate(var(--drift-x), var(--drift-y)) rotate(290deg); }
}
@media (prefers-reduced-motion: reduce) {
  .math-confetti { display: none; }
}
.math-round-top p { margin: 0 12px 0 0; color: #d5e3ff; }
.math-page-heading {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  margin: 4px 0 12px;
}
.math-page-heading > * { margin-top: 4px; margin-bottom: 4px; }
.math-stars {
  padding: 5px 10px;
  border: 1px solid #46516a;
  border-radius: 12px;
  background: #111827;
  color: #f9dd91;
  font-size: 1rem;
  font-weight: 700;
}
.math-stars::before { content: "★"; margin-right: 5px; }
#math-problem {
  margin: auto 0;
  padding: 12px 0;
  color: #f8fafc;
  font-size: 3rem;
  font-size: clamp(2.5rem, 8vmin, 6rem);
  line-height: 1.25;
  text-align: center;
}
.math-answer {
  width: calc(25% - 8px);
  min-height: 76px;
  margin: 4px;
  padding: 8px;
  border: 2px solid #52678c;
  border-radius: 12px;
  background: #1b2232;
  color: #f8fafc;
  font-size: 2rem;
  font-size: clamp(1.7rem, 5vmin, 3.5rem);
  font-weight: 800;
  touch-action: manipulation;
}
.math-answer:hover:not(:disabled) { background: #242d40; }
.math-answer:disabled { cursor: default; }
.math-answer.correct { background: #c4f3de; border-color: #81daba; color: #18342b; }
.math-answer.incorrect { background: #ffe6a9; border-color: #855e47; color: #392a11; }
.math-round-bottom { min-height: 60px; margin-top: 8px; }
#math-feedback { margin: 4px 12px 4px 0; }
.math-summary { align-items: center; text-align: center; }
.math-summary h2 { margin: 0; }
.math-summary button { margin: 4px; }

@media (max-width: 540px) {
  .math-answer { width: calc(50% - 8px); min-height: 64px; }
  .math-round-top .action { font-size: 0.875rem; }
  .math-menu > .math-primary { align-self: stretch; }
}
