:root {
  --leaf: #55b96d;
  --leaf-dark: #267a4a;
  --sky: #bfefff;
  --sun: #ffd45c;
  --stone: #f1d28a;
  --stone-edge: #c6903a;
  --mud: #8e5f33;
  --text: #23403a;
  --white: #fffdf4;
  --wrong: #ff7b7b;
  --right: #33b86b;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  font-family: "Microsoft JhengHei", "Noto Sans TC", Arial, sans-serif;
  background:
    radial-gradient(circle at 18% 14%, #fff7a8 0 48px, transparent 50px),
    linear-gradient(180deg, var(--sky) 0%, #ddf8cf 56%, #a7dd80 100%);
}

button {
  font: inherit;
}

.game-shell {
  position: relative;
  display: grid;
  min-height: 100vh;
  padding: 24px;
  place-items: center;
  overflow-x: hidden;
  overflow-y: auto;
}

.game-shell::before,
.game-shell::after {
  position: absolute;
  bottom: -18px;
  width: 52vw;
  height: 160px;
  content: "";
  background: var(--leaf);
  border-radius: 50% 50% 0 0;
  opacity: 0.78;
  z-index: 0;
}

.game-shell::before {
  left: -10vw;
}

.game-shell::after {
  right: -12vw;
  background: #43a85c;
}

.world-screen,
.game-card,
.complete-screen {
  position: relative;
  width: min(1080px, 100%);
  z-index: 1;
}

.world-screen {
  display: grid;
  gap: 18px;
  padding: clamp(18px, 4vw, 34px);
  background: rgba(255, 253, 244, 0.92);
  border: 5px solid #ffffff;
  border-radius: 8px;
  box-shadow: 0 20px 50px rgba(40, 91, 50, 0.22);
}

.world-hero {
  display: grid;
  gap: 8px;
  text-align: center;
}

.world-subtitle {
  color: #496143;
  font-size: clamp(1.3rem, 3vw, 2rem);
  font-weight: 900;
}

.world-message {
  min-height: 36px;
  color: #e97420;
  text-align: center;
  font-size: clamp(1.15rem, 3vw, 1.7rem);
  font-weight: 900;
}

.world-message.show {
  animation: eggRewardPop 0.35s ease both;
}

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

.world-card {
  display: grid;
  align-content: start;
  justify-items: center;
  gap: 8px;
  min-height: 250px;
  padding: 18px 14px;
  text-align: center;
  background: #fff8d8;
  border: 4px solid #ffe081;
  border-radius: 8px;
  box-shadow: inset 0 -8px 0 rgba(128, 88, 36, 0.08);
}

.world-card.locked {
  filter: grayscale(0.2);
  opacity: 0.82;
}

.world-card.shake {
  animation: lockedShake 0.38s ease both;
}

.world-icon {
  font-size: 3.4rem;
  line-height: 1;
}

.world-card h2 {
  color: #24563e;
  font-size: clamp(1.45rem, 3vw, 2.1rem);
}

.world-level,
.world-range,
.world-play {
  color: #5e7543;
  font-size: 1.1rem;
  font-weight: 900;
}

.world-start-button,
.map-button {
  min-height: 48px;
  padding: 8px 16px;
  color: #fff;
  font-weight: 900;
  background: #35ad65;
  border: 0;
  border-bottom: 5px solid #1b7641;
  border-radius: 8px;
  cursor: pointer;
  touch-action: manipulation;
}

.world-card.locked .world-start-button {
  background: #7f8d76;
  border-bottom-color: #596452;
}

.world-start-button:hover,
.world-start-button:focus-visible,
.map-button:hover,
.map-button:focus-visible {
  outline: 4px solid rgba(255, 212, 92, 0.65);
  transform: translateY(-1px);
}

.game-card {
  display: grid;
  gap: 18px;
  padding: clamp(16px, 3vw, 28px);
  background: rgba(255, 253, 244, 0.92);
  border: 5px solid #ffffff;
  border-radius: 8px;
  box-shadow: 0 20px 50px rgba(40, 91, 50, 0.22);
}

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.level-badge {
  display: inline-block;
  margin-top: 8px;
  padding: 5px 10px;
  color: #fff;
  font-size: 1rem;
  font-weight: 900;
  background: #55b96d;
  border-radius: 8px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--leaf-dark);
  font-size: clamp(1rem, 2vw, 1.2rem);
  font-weight: 800;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  color: #24563e;
  font-size: clamp(2rem, 5vw, 4rem);
  line-height: 1.05;
}

.stars {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  min-width: 0;
  gap: 4px;
  color: #ffb22e;
  font-size: 1.05rem;
  line-height: 1;
}

.egg-reward {
  display: grid;
  grid-template-columns: auto auto;
  align-items: center;
  justify-items: center;
  gap: 2px 8px;
  min-width: 112px;
  padding: 8px 10px;
  background: rgba(255, 248, 216, 0.82);
  border: 3px solid #ffe081;
  border-radius: 8px;
}

.egg-label,
.egg-counter {
  color: #496143;
  font-size: 0.9rem;
  font-weight: 900;
}

.egg-label {
  grid-column: 1 / -1;
}

.egg-display {
  position: relative;
  display: grid;
  width: 54px;
  height: 58px;
  place-items: center;
  font-size: 2.35rem;
  transform-origin: center bottom;
}

.egg-emoji {
  position: relative;
  z-index: 1;
}

.egg-crack {
  position: absolute;
  width: 3px;
  background: #7b5532;
  border-radius: 999px;
  opacity: 0;
  z-index: 2;
}

.crack-one {
  top: 16px;
  left: 28px;
  height: 16px;
  transform: rotate(24deg);
}

.crack-two {
  top: 26px;
  left: 23px;
  height: 18px;
  transform: rotate(-36deg);
}

.crack-three {
  top: 30px;
  left: 34px;
  height: 16px;
  transform: rotate(42deg);
}

.egg-stage-1 .crack-one,
.egg-stage-2 .crack-one,
.egg-stage-3 .crack-one,
.egg-stage-4 .crack-one,
.egg-stage-5 .crack-one {
  opacity: 0.75;
}

.egg-stage-2 .crack-two,
.egg-stage-3 .crack-two,
.egg-stage-4 .crack-two,
.egg-stage-5 .crack-two {
  opacity: 0.8;
}

.egg-stage-4 .crack-three,
.egg-stage-5 .crack-three {
  opacity: 0.85;
}

.egg-stage-3,
.egg-stage-4 {
  animation: gentleEggWiggle 1.1s ease-in-out infinite;
}

.egg-stage-4 .egg-emoji {
  filter: drop-shadow(0 4px 0 rgba(255, 178, 46, 0.2));
}

.egg-reward-pop {
  animation: eggRewardPop 0.46s ease both;
}

.egg-display.hatching {
  animation: eggWiggle 0.5s ease-in-out infinite;
}

.egg-display.strong-shake {
  animation: strongEggShake 0.16s ease-in-out infinite;
}

.egg-display.hatched {
  opacity: 0;
  transform: scale(0.35);
  transition: opacity 0.24s ease, transform 0.24s ease;
}

.egg-display.baby-dino-born {
  animation: babyDinoPop 0.7s ease both;
}

.sound-toggle {
  display: grid;
  width: 52px;
  height: 52px;
  flex: 0 0 auto;
  place-items: center;
  color: #24563e;
  font-size: 1.7rem;
  background: rgba(255, 255, 255, 0.72);
  border: 3px solid #ffe081;
  border-radius: 8px;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.12s ease, background 0.12s ease;
}

.sound-toggle:hover,
.sound-toggle:focus-visible {
  outline: 4px solid rgba(255, 212, 92, 0.55);
  background: #fff8d8;
  transform: translateY(-1px);
}

.question-panel {
  display: grid;
  gap: 10px;
  padding: 18px;
  background: #fff6cf;
  border: 3px solid #ffe081;
  border-radius: 8px;
}

.question-count {
  color: #6d7640;
  font-size: clamp(1rem, 2.5vw, 1.3rem);
  font-weight: 800;
}

#questionText {
  color: #213f39;
  font-size: clamp(1.6rem, 4vw, 3rem);
  line-height: 1.25;
}

#questionText span {
  display: block;
}

.challenge-label {
  margin-bottom: 4px;
  color: #f28a24;
  font-size: clamp(1.1rem, 2.8vw, 1.5rem);
  font-weight: 900;
}

.question-steps {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: stretch;
}

.operation-card {
  display: grid;
  gap: 2px;
  min-width: 86px;
  padding: 8px 10px;
  color: #24563e;
  text-align: center;
  background: #fffdf4;
  border: 3px solid #ffd96c;
  border-radius: 8px;
  box-shadow: 0 3px 0 rgba(128, 95, 34, 0.18);
}

.operation-card-label {
  color: #6d7640;
  font-size: 0.9rem;
  font-weight: 900;
}

.operation-card strong {
  color: #213f39;
  font-size: clamp(1.3rem, 3.2vw, 1.8rem);
  line-height: 1;
}

.operation-card-subtext {
  color: #4f7b55;
  font-size: 0.82rem;
  font-weight: 800;
}

.number-line-wrap {
  position: relative;
  padding: 52px 12px 22px;
  background: linear-gradient(180deg, #e8ffd2 0%, #b7e174 100%);
  border: 4px solid #7abf53;
  border-radius: 8px;
  overflow-x: auto;
  overflow-y: visible;
  -ms-overflow-style: none;
  scrollbar-width: none;
}

.number-line-wrap::-webkit-scrollbar {
  display: none;
}

.forest-top {
  position: absolute;
  top: 8px;
  left: 18px;
  right: 18px;
  display: flex;
  justify-content: space-between;
  font-size: 2rem;
  pointer-events: none;
}

.learning-hint {
  position: absolute;
  top: 10px;
  left: 50%;
  min-height: 42px;
  padding: 4px 18px;
  color: #24563e;
  font-size: clamp(1.5rem, 4vw, 2.4rem);
  font-weight: 900;
  line-height: 1.2;
  text-align: center;
  transform: translateX(-50%);
  z-index: 2;
  pointer-events: none;
}

.learning-hint.counting {
  color: #e97420;
}

.learning-hint.equation {
  color: #1f6d42;
  font-size: clamp(2rem, 5vw, 3.4rem);
}

.number-line {
  position: relative;
  display: grid;
  grid-template-columns: repeat(21, minmax(52px, 1fr));
  align-items: end;
  min-width: 1092px;
  padding-top: 62px;
  gap: 6px;
}

.number-line::before {
  position: absolute;
  left: 24px;
  right: 24px;
  bottom: 31px;
  height: 10px;
  content: "";
  background: #9d6c37;
  border-radius: 999px;
}

.platform {
  position: relative;
  display: grid;
  width: 52px;
  height: 52px;
  place-items: center;
  justify-self: center;
  color: #583b1f;
  font-size: 1.35rem;
  font-weight: 900;
  background: var(--stone);
  border: 4px solid var(--stone-edge);
  border-radius: 50%;
  box-shadow: inset 0 -6px 0 rgba(128, 88, 36, 0.18);
  z-index: 1;
}

.platform.current {
  background: #ffe778;
  border-color: #ff9f1c;
  transform: translateY(-4px);
}

.platform.step-highlight {
  animation: platformGlow 0.35s ease both;
}

.dinosaur {
  position: absolute;
  left: 0;
  bottom: 42px;
  --dino-scale: 1;
  --dino-offset-x: 0px;
  --dino-offset-y: 0px;
  width: clamp(100px, 12vw, 180px);
  height: clamp(86px, 10vw, 150px);
  display: grid;
  place-items: center;
  font-size: clamp(4.8rem, 9vw, 8rem);
  transform: translateX(calc(-50% + var(--dino-offset-x))) translateY(var(--dino-offset-y)) scale(var(--dino-scale));
  transition:
    left 0.46s ease-in-out,
    transform 0.23s ease;
  z-index: 5;
  filter: drop-shadow(0 8px 4px rgba(66, 77, 35, 0.2));
  pointer-events: none;
  will-change: left, transform;
}

.dinosaur.no-transition {
  transition: none;
}

.dinosaur.jump {
  transform: translateX(calc(-50% + var(--dino-offset-x))) translateY(calc(var(--dino-offset-y) - 48px)) rotate(-6deg) scale(calc(var(--dino-scale) * 1.1));
}

.dinosaur.correct {
  animation: happyBounce 0.7s ease both;
}

.dinosaur-image,
.dinosaur-fallback {
  grid-area: 1 / 1;
}

.dinosaur-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.dinosaur-fallback {
  display: none;
  line-height: 1;
}

.dinosaur.image-failed .dinosaur-image {
  display: none;
}

.dinosaur.image-failed .dinosaur-fallback {
  display: block;
}

.answer-area {
  display: grid;
  gap: 12px;
}

.answer-buttons {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}

.answer-button,
.restart-button {
  min-height: 72px;
  color: #fff;
  font-size: clamp(1.7rem, 4vw, 2.5rem);
  font-weight: 900;
  background: #ff8b3d;
  border: 0;
  border-bottom: 7px solid #bd5726;
  border-radius: 8px;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.12s ease, filter 0.12s ease;
}

.answer-button:hover,
.restart-button:hover,
.answer-button:focus-visible,
.restart-button:focus-visible {
  outline: 4px solid rgba(255, 212, 92, 0.8);
  transform: translateY(-2px);
  filter: brightness(1.04);
}

.answer-button:active,
.restart-button:active {
  transform: translateY(2px);
  border-bottom-width: 3px;
}

.answer-button:disabled {
  cursor: wait;
  filter: grayscale(0.3);
}

.feedback {
  min-height: 48px;
  text-align: center;
  font-size: clamp(1.6rem, 4vw, 2.4rem);
  font-weight: 900;
}

.feedback.right {
  color: var(--right);
}

.feedback.wrong {
  color: var(--wrong);
}

.collection-panel {
  display: grid;
  gap: 12px;
  padding: 16px;
  background: #fff8d8;
  border: 3px solid #ffe081;
  border-radius: 8px;
}

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

.collection-header h2 {
  color: #24563e;
  font-size: clamp(1.35rem, 3vw, 2rem);
}

.collection-header p {
  color: #5e7543;
  font-size: clamp(1rem, 2vw, 1.25rem);
  font-weight: 900;
}

.collection-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(104px, 1fr));
  gap: 10px;
}

.collection-card {
  position: relative;
  display: grid;
  min-height: 128px;
  place-items: center;
  gap: 6px;
  padding: 10px 8px;
  color: #24563e;
  background: #fffdf4;
  border: 3px solid #e7c66f;
  border-radius: 8px;
  cursor: pointer;
  touch-action: manipulation;
}

.collection-card:hover,
.collection-card:focus-visible {
  outline: 4px solid rgba(255, 212, 92, 0.55);
  transform: translateY(-1px);
}

.collection-card.locked {
  background: #d6ceb6;
}

.dinosaur-art {
  position: relative;
  display: grid;
  width: 74px;
  height: 66px;
  place-items: center;
  font-size: 3rem;
}

.dinosaur-art img,
.dinosaur-art-fallback {
  grid-area: 1 / 1;
}

.dinosaur-art img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.dinosaur-art-fallback {
  display: none;
  line-height: 1;
}

.dinosaur-art.image-failed img {
  display: none;
}

.dinosaur-art.image-failed .dinosaur-art-fallback {
  display: block;
}

.locked .dinosaur-art,
.locked-art {
  filter: grayscale(1) brightness(0.42);
}

.collection-name {
  font-size: 1rem;
  font-weight: 900;
}

.collection-lock,
.new-badge {
  position: absolute;
  top: 6px;
  font-weight: 900;
}

.collection-lock {
  left: 8px;
  font-size: 1.3rem;
}

.new-badge {
  right: 6px;
  padding: 2px 6px;
  color: #fff;
  font-size: 0.75rem;
  background: #ff8b3d;
  border-radius: 999px;
}

.complete-screen {
  display: grid;
  max-width: 620px;
  justify-items: center;
  gap: 20px;
  padding: clamp(28px, 6vw, 54px);
  text-align: center;
  background: var(--white);
  border: 5px solid #ffffff;
  border-radius: 8px;
  box-shadow: 0 20px 50px rgba(40, 91, 50, 0.22);
}

.complete-screen h2 {
  color: #24563e;
  font-size: clamp(2rem, 6vw, 4rem);
}

.complete-kicker {
  color: #ff8b3d;
  font-size: clamp(2rem, 6vw, 3.8rem);
  font-weight: 900;
}

.complete-world {
  color: #267a4a;
  font-size: clamp(1.25rem, 3vw, 1.8rem);
  font-weight: 900;
}

.egg-scene {
  position: relative;
  height: 112px;
  font-size: 5rem;
}

.complete-baby-dino {
  display: inline-block;
  animation: babyDinoPop 0.75s ease both;
}

.complete-stars {
  color: #ffb22e;
  font-size: clamp(2rem, 5vw, 3.4rem);
  font-weight: 900;
}

.unlock-panel {
  display: grid;
  justify-items: center;
  gap: 8px;
  min-height: 120px;
}

.unlock-title,
.unlock-name {
  color: #24563e;
  font-size: clamp(1.4rem, 4vw, 2.2rem);
  font-weight: 900;
}

.unlock-text,
.unlock-icons {
  color: #5e7543;
  font-size: clamp(1.1rem, 3vw, 1.5rem);
  font-weight: 900;
}

.unlock-art {
  width: clamp(180px, 28vw, 250px);
  height: clamp(150px, 22vw, 210px);
  font-size: clamp(7rem, 18vw, 12rem);
  animation: babyDinoPop 0.7s ease both;
  filter: drop-shadow(0 0 14px rgba(255, 212, 92, 0.58));
}

.restart-button {
  width: min(360px, 100%);
  background: #35ad65;
  border-bottom-color: #1b7641;
}

.complete-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(160px, 1fr));
  width: min(520px, 100%);
  gap: 12px;
}

.complete-map-button {
  background: #ff8b3d;
  border-bottom-color: #bd5726;
}

.dinosaur-modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(35, 64, 58, 0.45);
  z-index: 20;
}

.dinosaur-modal-card {
  position: relative;
  display: grid;
  width: min(360px, 100%);
  justify-items: center;
  gap: 12px;
  padding: 26px 20px;
  text-align: center;
  background: #fffdf4;
  border: 5px solid #ffffff;
  border-radius: 8px;
  box-shadow: 0 18px 48px rgba(35, 64, 58, 0.28);
}

.modal-close {
  position: absolute;
  top: 8px;
  right: 8px;
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  color: #24563e;
  font-size: 2rem;
  font-weight: 900;
  line-height: 1;
  background: #fff8d8;
  border: 3px solid #ffe081;
  border-radius: 8px;
  cursor: pointer;
}

.modal-dinosaur-art .dinosaur-art {
  width: 180px;
  height: 150px;
  font-size: 8rem;
}

.dinosaur-modal-card h2 {
  color: #24563e;
  font-size: 2rem;
}

.dinosaur-modal-card p {
  color: #5e7543;
  font-size: 1.25rem;
  font-weight: 900;
}

.hidden {
  display: none;
}

@keyframes happyBounce {
  0%,
  100% {
    transform: translateX(calc(-50% + var(--dino-offset-x))) translateY(var(--dino-offset-y)) scale(var(--dino-scale));
  }
  35% {
    transform: translateX(calc(-50% + var(--dino-offset-x))) translateY(calc(var(--dino-offset-y) - 30px)) rotate(-7deg) scale(calc(var(--dino-scale) * 1.14));
  }
  70% {
    transform: translateX(calc(-50% + var(--dino-offset-x))) translateY(calc(var(--dino-offset-y) - 8px)) rotate(7deg) scale(calc(var(--dino-scale) * 1.06));
  }
}

@keyframes platformGlow {
  0% {
    box-shadow:
      0 0 0 0 rgba(255, 212, 92, 0.9),
      inset 0 -6px 0 rgba(128, 88, 36, 0.18);
  }
  70% {
    box-shadow:
      0 0 0 12px rgba(255, 212, 92, 0),
      inset 0 -6px 0 rgba(128, 88, 36, 0.18);
  }
  100% {
    box-shadow:
      0 0 0 0 rgba(255, 212, 92, 0),
      inset 0 -6px 0 rgba(128, 88, 36, 0.18);
  }
}

@keyframes eggWiggle {
  0%,
  100% {
    transform: rotate(0deg);
  }
  30% {
    transform: rotate(-10deg);
  }
  60% {
    transform: rotate(10deg);
  }
}

@keyframes eggRewardPop {
  0%,
  100% {
    transform: scale(1);
  }
  45% {
    transform: scale(1.12) rotate(-4deg);
  }
}

@keyframes gentleEggWiggle {
  0%,
  100% {
    transform: rotate(0deg);
  }
  45% {
    transform: rotate(-4deg);
  }
  70% {
    transform: rotate(4deg);
  }
}

@keyframes strongEggShake {
  0%,
  100% {
    transform: rotate(0deg) scale(1.06);
  }
  35% {
    transform: rotate(-9deg) scale(1.1);
  }
  70% {
    transform: rotate(9deg) scale(1.1);
  }
}

@keyframes babyDinoPop {
  0% {
    opacity: 0;
    transform: scale(0);
  }
  65% {
    opacity: 1;
    transform: scale(1.2);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes lockedShake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-6px);
  }
  50% {
    transform: translateX(6px);
  }
  75% {
    transform: translateX(-3px);
  }
}

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

  .game-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .world-grid {
    grid-template-columns: 1fr;
  }

  .stars {
    justify-content: center;
  }

  .egg-reward {
    align-self: center;
  }

  .collection-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .collection-grid {
    grid-template-columns: repeat(6, 108px);
    overflow-x: auto;
    padding-bottom: 4px;
  }

  .dinosaur {
    width: clamp(85px, 24vw, 120px);
    height: clamp(76px, 21vw, 110px);
    font-size: clamp(4.2rem, 17vw, 6rem);
  }

  .number-line {
    grid-template-columns: repeat(21, 52px);
  }

  .answer-buttons {
    grid-template-columns: 1fr;
  }

  .answer-button,
  .restart-button {
    min-height: 68px;
  }

  .complete-actions {
    grid-template-columns: 1fr;
  }
}

@media (min-width: 721px) and (max-width: 920px) {
  .world-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
