:root {
  color-scheme: light;
  --ink: #253044;
  --muted: #67738a;
  --paper: #fffaf2;
  --panel: #ffffff;
  --sky: #84d7ee;
  --grass: #88c76f;
  --leaf: #2f9f75;
  --coral: #ff7168;
  --gold: #ffc845;
  --blue: #3978d8;
  --shadow: 0 18px 45px rgba(38, 48, 68, 0.18);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  font-family:
    Inter, ui-rounded, "SF Pro Rounded", "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 10%, rgba(255, 200, 69, 0.32), transparent 28rem),
    linear-gradient(145deg, #d8f6ff 0%, #fff6df 58%, #e4f6d8 100%);
}

button,
input {
  font: inherit;
}

.game-shell {
  width: min(960px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: clamp(16px, 3vw, 30px);
  display: grid;
  gap: 16px;
  align-content: center;
}

.top-panel,
.controls,
.progress-panel {
  background: rgba(255, 255, 255, 0.8);
  border: 2px solid rgba(255, 255, 255, 0.86);
  border-radius: 8px;
  box-shadow: 0 12px 30px rgba(37, 48, 68, 0.1);
}

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

.eyebrow,
.prompt {
  margin: 0;
  color: var(--blue);
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 4px 0 0;
  font-size: clamp(1.45rem, 5vw, 2.45rem);
  line-height: 1;
}

.score-board {
  display: flex;
  gap: 10px;
}

.score-board div {
  width: 74px;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  padding: 8px;
  border-radius: 8px;
  background: var(--paper);
  border: 2px solid #ffe0a4;
}

.score-board span {
  display: block;
  font-size: 1.45rem;
  font-weight: 950;
}

.score-board small {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
}

.controls {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(220px, 1fr);
  gap: 14px;
  padding: 14px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
  padding: 6px;
  border-radius: 8px;
  background: #eaf4ff;
}

.mode-button,
.restart-button {
  min-height: 46px;
  border: 0;
  border-radius: 8px;
  color: var(--ink);
  background: transparent;
  font-weight: 950;
  cursor: pointer;
  transition:
    transform 150ms ease,
    background 150ms ease,
    box-shadow 150ms ease;
}

.mode-button.active {
  color: #fff;
  background: var(--blue);
  box-shadow: 0 8px 18px rgba(57, 120, 216, 0.28);
}

.range-control {
  min-height: 58px;
  display: grid;
  gap: 6px;
  align-content: center;
}

.range-control span,
.progress-copy {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 850;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--leaf);
}

.question-panel {
  position: relative;
  min-height: clamp(500px, 70vh, 620px);
  overflow: hidden;
  display: grid;
  grid-template-columns: 1fr 1fr;
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.scene {
  position: relative;
  min-height: 100%;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.44), transparent 42%),
    var(--sky);
}

.scene > * {
  z-index: 1;
}

.sun {
  position: absolute;
  top: 10%;
  left: 14%;
  width: 92px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 0 16px rgba(255, 200, 69, 0.25);
}

.hill {
  position: absolute;
  z-index: 0;
  right: -18%;
  bottom: -12%;
  width: 76%;
  aspect-ratio: 1.45;
  border-radius: 50% 50% 0 0;
  background: var(--grass);
}

.hill.back {
  right: 24%;
  bottom: -8%;
  background: #66b98f;
}

.candy-path {
  position: absolute;
  top: 22%;
  left: 36%;
  width: 42%;
  height: 46%;
  pointer-events: none;
}

.candy-path span {
  position: absolute;
  width: 16px;
  aspect-ratio: 1;
  transform: translate(-50%, -50%) scale(0.82);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.76);
  box-shadow:
    inset -3px -3px 0 rgba(255, 200, 69, 0.22),
    0 5px 12px rgba(37, 48, 68, 0.12);
  transition:
    transform 260ms ease,
    background 260ms ease,
    box-shadow 260ms ease;
}

.candy-path span.active {
  transform: translate(-50%, -50%) scale(1.18) rotate(12deg);
  background: linear-gradient(135deg, #ff7168 0 45%, #fff4a5 45% 60%, #62c8ff 60%);
  box-shadow:
    inset -3px -3px 0 rgba(37, 48, 68, 0.16),
    0 8px 16px rgba(255, 113, 104, 0.28);
}

.candy-goal {
  position: absolute;
  top: 10%;
  right: 10%;
  width: 96px;
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: center;
  filter: drop-shadow(0 12px 18px rgba(37, 48, 68, 0.18));
  animation: candyBob 1.8s ease-in-out infinite alternate;
}

.candy-body {
  width: 54px;
  height: 42px;
  border-radius: 999px;
  background:
    linear-gradient(115deg, transparent 0 27%, rgba(255, 255, 255, 0.7) 27% 38%, transparent 38% 55%, rgba(255, 255, 255, 0.7) 55% 66%, transparent 66%),
    #ff7168;
  border: 4px solid #fff4a5;
}

.candy-wrap {
  width: 24px;
  height: 34px;
  background: #fff4a5;
  clip-path: polygon(0 50%, 100% 0, 100% 100%);
}

.candy-wrap.right {
  transform: scaleX(-1);
}

.candy-goal.reached {
  animation: candyParty 520ms ease;
}

.rocket {
  position: absolute;
  z-index: 3;
  left: 50%;
  bottom: 26%;
  width: 92px;
  height: 150px;
  --flight-x: 0px;
  --flight-y: 0px;
  transform: translate(calc(-50% + var(--flight-x)), var(--flight-y));
  border-radius: 48px 48px 26px 26px;
  background: linear-gradient(90deg, #f8fbff 0 45%, #dfe8f5 45% 100%);
  box-shadow: 0 18px 28px rgba(33, 71, 105, 0.22);
  transition: transform 420ms cubic-bezier(0.2, 0.9, 0.25, 1.18);
  animation: rocketFloat 2.1s ease-in-out infinite alternate;
}

.rocket::before {
  content: "";
  position: absolute;
  top: -42px;
  left: 0;
  border-left: 46px solid transparent;
  border-right: 46px solid transparent;
  border-bottom: 58px solid var(--coral);
}

.rocket-window {
  position: absolute;
  top: 34px;
  left: 50%;
  width: 38px;
  aspect-ratio: 1;
  transform: translateX(-50%);
  border-radius: 50%;
  background: #62c8ff;
  border: 7px solid #253044;
}

.rocket-fin {
  position: absolute;
  bottom: 10px;
  width: 38px;
  height: 58px;
  background: var(--coral);
}

.rocket-fin.left {
  left: -26px;
  border-radius: 26px 0 8px 18px;
}

.rocket-fin.right {
  right: -26px;
  border-radius: 0 26px 18px 8px;
}

.flame {
  position: absolute;
  left: 50%;
  bottom: -54px;
  width: 34px;
  height: 64px;
  transform: translateX(-50%);
  border-radius: 50% 50% 45% 45%;
  background: linear-gradient(#ffd54f, #ff7a3d);
  opacity: 0.94;
  animation: flicker 0.22s infinite alternate;
}

.stars span {
  position: absolute;
  z-index: 2;
  width: 18px;
  aspect-ratio: 1;
  clip-path: polygon(50% 0, 62% 35%, 100% 35%, 69% 57%, 82% 100%, 50% 73%, 18% 100%, 31% 57%, 0 35%, 38% 35%);
  background: #fff4a5;
  animation: twinkle 1.2s ease-in-out infinite alternate;
}

.candy-burst {
  position: absolute;
  z-index: 4;
  top: 16%;
  right: 16%;
  width: 1px;
  height: 1px;
  pointer-events: none;
}

.candy-burst span {
  position: absolute;
  width: 18px;
  height: 12px;
  border-radius: 999px;
  background: #ff7168;
  border: 2px solid #fff4a5;
  animation: candyPop 720ms ease-out forwards;
}

.candy-burst span:nth-child(2n) {
  background: #62c8ff;
}

.candy-burst span:nth-child(3n) {
  background: #ffc845;
}

.question-content {
  padding: clamp(20px, 4vw, 42px);
  display: grid;
  align-content: center;
  gap: 22px;
}

.problem {
  min-height: 112px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: #fff;
  background: var(--ink);
  font-size: clamp(2.6rem, 10vw, 5.4rem);
  font-weight: 950;
}

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

.answer-button {
  min-height: 72px;
  border: 0;
  border-radius: 8px;
  color: var(--ink);
  background: #f2f8ff;
  box-shadow: inset 0 0 0 2px #cfe2fb;
  font-size: clamp(1.5rem, 7vw, 2.1rem);
  font-weight: 950;
  cursor: pointer;
}

.answer-button.correct {
  color: #fff;
  background: var(--leaf);
  box-shadow: none;
}

.answer-button.wrong {
  color: #fff;
  background: var(--coral);
  box-shadow: none;
}

.feedback {
  min-height: 30px;
  margin: 0;
  color: var(--muted);
  font-size: 1rem;
  font-weight: 850;
  text-align: center;
}

.progress-panel {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.progress-track {
  height: 14px;
  overflow: hidden;
  border-radius: 999px;
  background: #dce9f0;
}

#progressBar {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--leaf), var(--gold));
  transition: width 250ms ease;
}

.restart-button {
  justify-self: end;
  min-width: 132px;
  color: #fff;
  background: var(--coral);
}

button:active {
  transform: translateY(1px) scale(0.99);
}

.rocket.launch {
  transform: translate(calc(-50% + var(--flight-x)), calc(var(--flight-y) - 28px)) rotate(4deg) scale(1.04);
}

.question-panel.shake {
  animation: shake 280ms ease;
}

@keyframes flicker {
  from {
    transform: translateX(-50%) scaleY(0.84);
  }
  to {
    transform: translateX(-50%) scaleY(1.08);
  }
}

@keyframes rocketFloat {
  from {
    margin-bottom: 0;
  }
  to {
    margin-bottom: 8px;
  }
}

@keyframes candyBob {
  from {
    transform: translateY(0) rotate(-3deg);
  }
  to {
    transform: translateY(10px) rotate(4deg);
  }
}

@keyframes candyParty {
  35% {
    transform: translateY(-10px) scale(1.18) rotate(-8deg);
  }
  70% {
    transform: translateY(6px) scale(0.94) rotate(8deg);
  }
}

@keyframes candyPop {
  from {
    opacity: 1;
    transform: translate(0, 0) scale(0.6) rotate(0deg);
  }
  to {
    opacity: 0;
    transform: translate(var(--pop-x), var(--pop-y)) scale(1.25) rotate(var(--pop-r));
  }
}

@keyframes twinkle {
  from {
    transform: scale(0.72) rotate(0deg);
    opacity: 0.55;
  }
  to {
    transform: scale(1.12) rotate(18deg);
    opacity: 1;
  }
}

@keyframes shake {
  25% {
    transform: translateX(-5px);
  }
  50% {
    transform: translateX(5px);
  }
  75% {
    transform: translateX(-3px);
  }
}

@media (max-width: 720px) {
  .game-shell {
    align-content: start;
    padding: 12px;
  }

  .top-panel {
    align-items: stretch;
    flex-direction: column;
  }

  .score-board div {
    width: auto;
    aspect-ratio: auto;
    min-height: 62px;
    flex: 1;
  }

  .controls,
  .question-panel {
    grid-template-columns: 1fr;
  }

  .question-panel {
    min-height: auto;
  }

  .scene {
    min-height: 220px;
  }

  .candy-path {
    top: 18%;
    left: 36%;
    width: 42%;
    height: 54%;
  }

  .candy-path span {
    width: 12px;
  }

  .candy-goal {
    top: 9%;
    right: 8%;
    width: 72px;
    height: 44px;
  }

  .candy-body {
    width: 42px;
    height: 32px;
    border-width: 3px;
  }

  .candy-wrap {
    width: 18px;
    height: 26px;
  }

  .rocket {
    width: 66px;
    height: 108px;
    bottom: 20%;
  }

  .rocket::before {
    top: -31px;
    border-left-width: 33px;
    border-right-width: 33px;
    border-bottom-width: 42px;
  }

  .rocket-window {
    top: 24px;
    width: 30px;
    border-width: 5px;
  }

  .rocket-fin {
    width: 29px;
    height: 42px;
  }

  .rocket-fin.left {
    left: -20px;
  }

  .rocket-fin.right {
    right: -20px;
  }

  .flame {
    bottom: -42px;
    height: 50px;
  }

  .question-content {
    gap: 16px;
    padding: 18px;
  }

  .problem {
    min-height: 86px;
  }

  .answer-button {
    min-height: 64px;
  }

  .restart-button {
    width: 100%;
  }
}

@media (max-width: 390px) {
  .answer-grid {
    gap: 8px;
  }

  .segmented {
    gap: 4px;
  }

  .mode-button {
    min-height: 42px;
  }

  .problem {
    font-size: 2.4rem;
  }
}
