:root {
  color-scheme: light;
  --ink: #243042;
  --muted: #6b7280;
  --paper: #fffaf0;
  --panel: #ffffff;
  --sun: #f6c453;
  --melon: #ff7f6e;
  --leaf: #2ea36d;
  --sky: #64b6d9;
  --grape: #7457c8;
  --line: #eadfcb;
  --shadow: 0 18px 42px rgba(76, 61, 38, 0.14);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 18% 10%, rgba(100, 182, 217, 0.32), transparent 24rem),
    radial-gradient(circle at 82% 18%, rgba(255, 127, 110, 0.28), transparent 22rem),
    linear-gradient(135deg, #fff4cf 0%, #eaf8ef 46%, #eef6ff 100%);
  font-family: "Avenir Next", "Trebuchet MS", "Segoe UI", sans-serif;
}

button {
  min-height: 56px;
  border: 0;
  border-radius: 8px;
  padding: 0 22px;
  color: var(--ink);
  font: inherit;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 8px 0 rgba(36, 48, 66, 0.16);
  transition:
    transform 140ms ease,
    box-shadow 140ms ease,
    filter 140ms ease;
}

button:hover {
  filter: brightness(1.02);
  transform: translateY(-1px);
}

button:active {
  transform: translateY(4px);
  box-shadow: 0 3px 0 rgba(36, 48, 66, 0.18);
}

button:focus-visible {
  outline: 4px solid rgba(46, 163, 109, 0.28);
  outline-offset: 3px;
}

.game-shell {
  width: min(960px, calc(100% - 28px));
  margin: 0 auto;
  padding: 28px 0 42px;
}

.hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 0 20px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--leaf);
  font-size: 0.9rem;
  font-weight: 900;
  letter-spacing: 0;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 7vw, 4.2rem);
  line-height: 0.95;
  letter-spacing: 0;
}

.round-badge {
  display: inline-flex;
  align-items: baseline;
  justify-content: center;
  min-width: 88px;
  min-height: 72px;
  padding: 10px 14px;
  border: 3px solid rgba(36, 48, 66, 0.12);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  font-weight: 900;
}

.round-badge strong {
  font-size: 2rem;
}

.mode-select {
  display: grid;
  gap: 14px;
  padding: 18px;
  border: 3px solid rgba(36, 48, 66, 0.1);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow);
}

.mode-kicker {
  margin: 0;
  color: var(--muted);
  font-size: 1.1rem;
  font-weight: 900;
  text-align: center;
}

.mode-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.mode-card {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  min-height: 112px;
  padding: 14px;
  border: 2px solid rgba(233, 193, 120, 0.5);
  background:
    linear-gradient(180deg, rgba(255, 253, 250, 0.96), rgba(255, 245, 226, 0.96)),
    repeating-linear-gradient(45deg, rgba(100, 182, 217, 0.1) 0 8px, transparent 8px 16px);
  text-align: left;
}

.mode-card strong,
.mode-card small {
  display: block;
  min-width: 0;
}

.mode-card strong {
  font-size: clamp(1.05rem, 2.2vw, 1.35rem);
  line-height: 1.15;
}

.mode-card small {
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
  line-height: 1.3;
}

.mode-icon {
  display: grid;
  place-items: center;
  width: 54px;
  aspect-ratio: 1;
  border-radius: 8px;
  background: #fffdfa;
  font-size: 2rem;
  box-shadow: inset 0 0 0 2px rgba(233, 193, 120, 0.35);
}

.score-strip,
.problem-stage,
.answer-panel,
.finish-panel {
  border: 3px solid rgba(36, 48, 66, 0.1);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow);
}

.score-strip {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 62px;
  padding: 12px 16px;
  font-weight: 900;
}

.stars {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  min-height: 30px;
}

.star {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--sun);
  color: #7a4a00;
  font-size: 1.15rem;
  transform: rotate(-6deg);
}

.star.new-star {
  animation: star-pop 520ms cubic-bezier(0.2, 1.5, 0.35, 1) both;
}

.problem-stage {
  margin-top: 16px;
  padding: clamp(18px, 4vw, 28px);
}

.prompt {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 1.05rem;
  font-weight: 800;
  text-align: center;
}

.equation {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 92px;
  font-size: clamp(2.6rem, 12vw, 5.6rem);
  font-weight: 900;
  line-height: 1;
}

.equation span {
  display: inline-grid;
  place-items: center;
  min-width: 0.85em;
}

.equation .blank {
  min-width: 1.35em;
  min-height: 1em;
  border: 5px dashed var(--melon);
  border-radius: 8px;
  background: rgba(255, 127, 110, 0.12);
}

.equation.compare-equation {
  gap: 8px;
  min-height: 72px;
  font-size: clamp(1.7rem, 8vw, 3.4rem);
}

.counter-scene {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  align-items: start;
  margin-top: 20px;
}

.counter-card {
  display: grid;
  gap: 12px;
  min-height: 240px;
  padding: 16px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.95), rgba(255, 250, 240, 0.95)),
    repeating-linear-gradient(45deg, rgba(246, 196, 83, 0.12) 0 8px, transparent 8px 16px);
}

.counter-card.mystery {
  border-color: rgba(116, 87, 200, 0.4);
  background:
    linear-gradient(180deg, rgba(244, 240, 255, 0.95), rgba(255, 255, 255, 0.94)),
    repeating-linear-gradient(45deg, rgba(116, 87, 200, 0.1) 0 8px, transparent 8px 16px);
}

.counter-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 34px;
  font-weight: 900;
}

.counter-count {
  display: inline-grid;
  place-items: center;
  min-width: 38px;
  min-height: 34px;
  border-radius: 8px;
  background: var(--sky);
  color: #10334a;
}

.counter-count.hidden-count {
  background: var(--grape);
  color: #fff;
}

.emoji-illustration {
  display: grid;
  place-items: center;
  min-height: 168px;
  border-radius: 8px;
  background:
    radial-gradient(circle at 28% 20%, rgba(255, 255, 255, 0.36), transparent 4.8rem),
    linear-gradient(180deg, #dff6d6 0%, #a5dfbf 100%);
  box-shadow:
    inset 0 0 0 2px rgba(255, 255, 255, 0.28),
    0 12px 24px rgba(35, 99, 76, 0.14);
}

.emoji-counter {
  display: grid;
  place-items: center;
  width: 100%;
  min-height: 142px;
}

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  place-items: center;
  gap: 8px;
  width: min(100%, 260px);
  min-height: 112px;
  padding: 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.46);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.36);
}

.emoji-token {
  display: grid;
  place-items: center;
  width: min(42px, 100%);
  aspect-ratio: 1;
  border-radius: 8px;
  background: #fffdfa;
  font-size: 2.05rem;
  line-height: 1;
  filter: drop-shadow(0 4px 2px rgba(25, 59, 47, 0.14));
  animation: pop-token 220ms ease both;
  animation-delay: calc(var(--delay) * 34ms);
}

.empty-counter,
.mystery-counter {
  grid-column: 1 / -1;
  display: grid;
  place-items: center;
  width: 100%;
  min-height: 88px;
  color: rgba(36, 48, 66, 0.58);
  font-size: 2.4rem;
  font-weight: 900;
}

.mystery-counter {
  color: #7457c8;
  font-size: 4rem;
}

.theme-heart {
  background:
    radial-gradient(circle at 28% 20%, rgba(255, 255, 255, 0.36), transparent 4.8rem),
    linear-gradient(180deg, #ffdce8 0%, #ffabc5 100%);
}

.theme-heart .emoji-token {
  filter: drop-shadow(0 5px 3px rgba(128, 42, 76, 0.13));
}

.mystery .emoji-illustration {
  background:
    repeating-linear-gradient(
      135deg,
      rgba(255, 255, 255, 0.2) 0 10px,
      rgba(255, 255, 255, 0) 10px 20px
    ),
    linear-gradient(180deg, #d8c9f4 0%, #bda9e6 100%);
}

.mystery .emoji-grid {
  background: rgba(255, 255, 255, 0.5);
}

@keyframes pop-token {
  from {
    transform: translateY(5px) scale(0.82);
  }
  to {
    transform: translateY(0) scale(1);
  }
}

.counter-help {
  min-height: 48px;
  margin: 0;
  color: var(--muted);
  font-weight: 800;
  line-height: 1.35;
  text-align: center;
}

.answer-panel {
  margin-top: 16px;
  padding: 16px;
}

.answers {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.answer-button {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  justify-items: center;
  gap: 6px;
  min-height: 142px;
  padding: 8px;
  border: 2px solid rgba(209, 169, 194, 0.55);
  background: #fff8ee;
  font-size: 1rem;
  overflow: hidden;
}

.answer-button.correct {
  background: #8ee0ad;
  animation: correct-bounce 520ms cubic-bezier(0.2, 1.45, 0.36, 1) both;
}

.answer-button.wrong {
  background: #ffb4a8;
}

.answer-button.compare-choice {
  grid-template-rows: 1fr auto;
  align-content: center;
  background: #fff8ee;
}

.choice-mark {
  display: grid;
  place-items: center;
  width: min(100%, 88px);
  aspect-ratio: 1;
  border-radius: 8px;
  background: #fff3df;
  color: var(--leaf);
  font-size: clamp(2rem, 7vw, 3.6rem);
  line-height: 1;
  box-shadow: inset 0 0 0 2px rgba(233, 193, 120, 0.28);
}

.choice-counter {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  width: 100%;
  min-width: 0;
}

.choice-counter-tile {
  display: grid;
  place-items: center;
  width: 100%;
  min-width: 0;
  min-height: 58px;
  border-radius: 8px;
  background: #fff7e8;
  box-shadow: inset 0 0 0 2px rgba(233, 193, 120, 0.28);
}

.choice-counter-tile .emoji-counter {
  min-height: 0;
}

.choice-counter-tile .emoji-grid {
  gap: 2px;
  width: min(100%, 104px);
  min-height: 0;
  padding: 4px;
  background: transparent;
  box-shadow: none;
}

.choice-counter-tile .emoji-token {
  width: min(18px, 100%);
  border-radius: 5px;
  font-size: 1.05rem;
  filter: none;
}

.choice-counter-tile .empty-counter {
  min-height: 42px;
  font-size: 1rem;
}

.choice-label {
  color: rgba(36, 48, 66, 0.76);
  font-size: 0.86rem;
  font-weight: 900;
  line-height: 1;
}

.feedback {
  min-height: 34px;
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 1.1rem;
  font-weight: 900;
  text-align: center;
}

.feedback.good {
  color: #167548;
}

.feedback.try {
  color: #a34839;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  margin-top: 16px;
}

.primary {
  background: var(--leaf);
  color: #fff;
}

.secondary {
  background: #fff;
  color: var(--ink);
}

.finish-panel {
  display: grid;
  justify-items: center;
  gap: 10px;
  margin-top: 16px;
  padding: 22px;
  text-align: center;
}

.finish-panel[hidden] {
  display: none;
}

.finish-panel strong {
  font-size: clamp(1.5rem, 5vw, 2.4rem);
}

.finish-panel p {
  margin: 0;
  color: var(--muted);
  font-weight: 800;
}

.celebration-layer {
  position: fixed;
  inset: 0;
  z-index: 30;
  overflow: hidden;
  pointer-events: none;
}

.celebration-badge,
.celebration-pop {
  position: absolute;
  transform: translate(-50%, -50%);
  will-change: transform, opacity;
}

.celebration-badge {
  display: grid;
  place-items: center;
  min-width: 92px;
  min-height: 46px;
  padding: 8px 16px;
  border: 3px solid rgba(255, 255, 255, 0.82);
  border-radius: 8px;
  background: linear-gradient(180deg, #ffe47a, #ffb84f);
  color: #5c3500;
  box-shadow: 0 12px 0 rgba(124, 79, 14, 0.18), 0 18px 34px rgba(124, 79, 14, 0.2);
  font-size: 1.45rem;
  font-weight: 900;
  animation: badge-pop 900ms cubic-bezier(0.18, 1.5, 0.36, 1) forwards;
}

.celebration-pop {
  font-size: clamp(1.35rem, 7vw, 2.2rem);
  line-height: 1;
  filter: drop-shadow(0 5px 4px rgba(36, 48, 66, 0.16));
  animation: burst-pop 900ms ease-out forwards;
  animation-delay: var(--delay);
}

@keyframes star-pop {
  0% {
    transform: rotate(-18deg) scale(0.2);
  }
  62% {
    transform: rotate(8deg) scale(1.42);
  }
  100% {
    transform: rotate(-6deg) scale(1);
  }
}

@keyframes correct-bounce {
  0%,
  100% {
    transform: translateY(0) scale(1);
  }
  42% {
    transform: translateY(-8px) scale(1.04);
  }
}

@keyframes badge-pop {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.52) rotate(-5deg);
  }
  22% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.1) rotate(2deg);
  }
  72% {
    opacity: 1;
    transform: translate(-50%, -58%) scale(1) rotate(-1deg);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -74%) scale(0.92) rotate(0deg);
  }
}

@keyframes burst-pop {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.3) rotate(0deg);
  }
  18% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(calc(-50% + var(--x)), calc(-50% + var(--y))) scale(1.05) rotate(var(--r));
  }
}

@media (max-width: 700px) {
  body {
    min-height: 100dvh;
  }

  .game-shell {
    display: grid;
    grid-template-rows: auto auto auto auto auto;
    align-content: start;
    width: min(100% - 14px, 560px);
    min-height: 100dvh;
    padding: 7px 0 10px;
  }

  .hero {
    align-items: center;
    gap: 8px;
    padding: 4px 0 7px;
  }

  .eyebrow {
    margin-bottom: 2px;
    font-size: 0.72rem;
  }

  h1 {
    font-size: clamp(1.42rem, 8vw, 2rem);
    line-height: 1;
  }

  .round-badge {
    min-width: 56px;
    min-height: 46px;
    padding: 5px 8px;
    border-width: 2px;
  }

  .round-badge strong {
    font-size: 1.38rem;
  }

  .score-strip,
  .mode-select,
  .problem-stage,
  .answer-panel,
  .finish-panel {
    border-width: 2px;
    box-shadow: 0 8px 22px rgba(76, 61, 38, 0.11);
  }

  .score-strip {
    gap: 8px;
    min-height: 34px;
    padding: 5px 9px;
    font-size: 0.86rem;
  }

  .mode-select {
    gap: 7px;
    padding: 8px;
  }

  .mode-kicker {
    font-size: 0.86rem;
  }

  .mode-grid {
    grid-template-columns: 1fr;
    gap: 7px;
  }

  .mode-card {
    min-height: 88px;
    padding: 8px 10px;
    grid-template-columns: 44px minmax(0, 1fr);
    gap: 9px;
    box-shadow: 0 5px 0 rgba(36, 48, 66, 0.16);
  }

  .mode-card strong {
    font-size: 1.02rem;
  }

  .mode-card small {
    margin-top: 2px;
    font-size: 0.74rem;
  }

  .mode-icon {
    width: 42px;
    font-size: 1.55rem;
  }

  .stars {
    gap: 4px;
    min-height: 20px;
  }

  .star {
    width: 20px;
    height: 20px;
    font-size: 0.8rem;
  }

  .celebration-badge {
    min-width: 78px;
    min-height: 38px;
    padding: 6px 12px;
    font-size: 1.1rem;
    box-shadow: 0 8px 0 rgba(124, 79, 14, 0.18), 0 12px 22px rgba(124, 79, 14, 0.18);
  }

  .problem-stage {
    display: grid;
    grid-template-rows: auto auto minmax(0, 1fr);
    margin-top: 7px;
    padding: 8px;
    overflow: hidden;
  }

  .prompt {
    margin-bottom: 4px;
    font-size: 0.8rem;
    line-height: 1.2;
  }

  .equation {
    gap: 5px;
    min-height: 46px;
    font-size: clamp(2rem, 12vw, 3rem);
  }

  .equation .blank {
    border-width: 3px;
  }

  .equation.compare-equation {
    min-height: 42px;
    font-size: clamp(1.35rem, 8vw, 2.2rem);
  }

  .counter-scene {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px;
    margin-top: 8px;
    min-height: 0;
  }

  .counter-card {
    align-content: start;
    gap: 4px;
    min-height: 0;
    padding: 6px 5px 7px;
  }

  .counter-title {
    gap: 5px;
    min-height: 24px;
    font-size: 0.78rem;
  }

  .counter-count {
    min-width: 26px;
    min-height: 24px;
  }

  .emoji-illustration {
    min-height: 104px;
    border-radius: 8px;
  }

  .emoji-counter {
    min-height: 94px;
  }

  .emoji-grid {
    gap: 2px;
    min-height: 84px;
    padding: 6px;
  }

  .emoji-token {
    width: min(26px, 100%);
    font-size: 1.42rem;
  }

  .empty-counter {
    min-height: 72px;
    font-size: 1.6rem;
  }

  .mystery-counter {
    font-size: 3rem;
  }

  .counter-help {
    min-height: 0;
    font-size: 0.66rem;
    line-height: 1.05;
  }

  .answer-panel {
    margin-top: 7px;
    padding: 8px;
  }

  .answers {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 7px;
  }

  .answer-button {
    min-height: 82px;
    padding: 5px;
    font-size: 0.82rem;
    box-shadow: 0 5px 0 rgba(36, 48, 66, 0.16);
  }

  .answer-button.compare-choice {
    min-height: 82px;
  }

  .choice-mark {
    width: min(100%, 50px);
    font-size: 2rem;
  }

  .choice-counter {
    gap: 3px;
  }

  .choice-counter-tile {
    width: 100%;
    min-height: 50px;
  }

  .choice-counter-tile .emoji-grid {
    gap: 1px;
    width: min(100%, 92px);
    padding: 3px;
  }

  .choice-counter-tile .emoji-token {
    width: min(16px, 100%);
    font-size: 0.92rem;
  }

  .choice-label {
    font-size: 0.68rem;
  }

  .feedback {
    min-height: 24px;
    margin-top: 6px;
    font-size: 0.88rem;
    line-height: 1.25;
  }

  .controls {
    gap: 7px;
    margin-top: 7px;
  }

  button {
    min-height: 42px;
    padding: 0 14px;
    box-shadow: 0 5px 0 rgba(36, 48, 66, 0.16);
  }

  .finish-panel {
    gap: 6px;
    margin-top: 7px;
    padding: 12px;
  }
}
