:root {
  --orange: #f47b20;
  --orange-dark: #d95d12;
  --green: #4b9d45;
  --green-dark: #26733a;
  --cream: #fffaf0;
  --ink: #4a352c;
  --blue: #3b88df;
  --purple: #8d61d8;
  --shadow: 0 8px 18px rgba(81, 55, 31, 0.16);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-width: 320px;
  min-height: 100%;
  margin: 0;
}

body {
  overflow-x: hidden;
  color: var(--ink);
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  background:
    radial-gradient(circle at 8% 15%, rgba(255, 255, 255, 0.7) 0 3px, transparent 4px),
    linear-gradient(145deg, #fff6c9, #ffe0a8 55%, #ffc997);
}

button {
  font: inherit;
}

.app-shell {
  width: min(100%, 1920px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 12px clamp(12px, 2vw, 30px) 14px;
  display: grid;
  grid-template-rows: auto auto minmax(430px, 1fr) auto;
  gap: 9px;
}

.topbar {
  min-height: 70px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 14px;
  padding: 7px 16px;
  border: 3px solid rgba(255, 255, 255, 0.95);
  border-radius: 24px;
  background: rgba(255, 250, 240, 0.95);
  box-shadow: var(--shadow);
}

.lesson-badge {
  padding: 9px 14px;
  border-radius: 18px;
  color: white;
  font-size: clamp(17px, 1.5vw, 24px);
  font-weight: 900;
  white-space: nowrap;
  background: linear-gradient(145deg, #67b856, #2e893f);
  border: 3px solid #dff3ca;
  box-shadow: inset 0 -4px rgba(0, 0, 0, 0.08);
}

.topbar h1 {
  margin: 0;
  color: var(--orange);
  font-size: clamp(23px, 2.4vw, 42px);
  line-height: 1.05;
  letter-spacing: 1px;
  text-shadow: 0 2px #fff, 0 4px rgba(180, 71, 15, 0.12);
}

.topbar p {
  margin: 4px 0 0;
  font-size: clamp(12px, 1vw, 17px);
  color: #6d5b4f;
}

.reset-button,
#challengeButton {
  min-height: 46px;
  padding: 8px 16px;
  border: 0;
  border-radius: 16px;
  color: white;
  font-weight: 900;
  font-size: clamp(15px, 1.25vw, 20px);
  cursor: pointer;
  background: linear-gradient(#ff9d3c, #ef671c);
  box-shadow: 0 5px 0 #bd4c12, 0 8px 14px rgba(132, 65, 19, 0.22);
}

.reset-button:active,
#challengeButton:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 #bd4c12;
}

.learning-strip {
  min-height: 36px;
  padding: 6px 15px;
  display: flex;
  align-items: center;
  gap: 12px;
  overflow: hidden;
  border-radius: 14px;
  color: white;
  font-size: clamp(13px, 1.05vw, 18px);
  font-weight: 700;
  background: linear-gradient(90deg, #2d873e, #5aaa48);
  box-shadow: inset 0 -3px rgba(0, 0, 0, 0.08);
}

.strip-title {
  flex: 0 0 auto;
  padding: 3px 10px;
  border-radius: 10px;
  color: #327939;
  background: #fff4b9;
}

.keyboard-tip {
  margin-left: auto;
  white-space: nowrap;
  color: #fff8bd;
}

.lab-layout {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(190px, 0.74fr) minmax(520px, 2.4fr) minmax(245px, 0.95fr);
  gap: 10px;
}

.panel {
  min-width: 0;
  padding: 12px;
  border: 3px solid #fff;
  border-radius: 22px;
  background: rgba(255, 250, 239, 0.96);
  box-shadow: var(--shadow);
}

.panel-heading {
  display: flex;
  align-items: center;
  gap: 9px;
  padding-bottom: 8px;
  border-bottom: 2px dashed #e6cda6;
}

.panel-heading h2,
.thinking-title h2 {
  margin: 0;
  color: var(--green-dark);
  font-size: clamp(18px, 1.45vw, 26px);
}

.panel-heading p,
.thinking-title p {
  margin: 1px 0 0;
  color: #8a725d;
  font-size: clamp(11px, 0.85vw, 14px);
}

.step-number {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: white;
  font-weight: 900;
  font-size: 20px;
  background: var(--orange);
  box-shadow: 0 3px 0 #c95012;
}

.step-number.blue {
  background: var(--blue);
  box-shadow: 0 3px 0 #2463a8;
}

.direction-pad {
  width: min(100%, 210px);
  margin: 13px auto 10px;
  display: grid;
  grid-template-columns: repeat(3, minmax(52px, 1fr));
  grid-template-rows: repeat(3, minmax(52px, 1fr));
  gap: 6px;
}

.direction {
  min-width: 0;
  min-height: 56px;
  padding: 2px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: 2px solid white;
  border-radius: 15px;
  color: white;
  font-weight: 900;
  cursor: pointer;
  background: linear-gradient(#74bc59, #3e9142);
  box-shadow: 0 5px 0 #2f7336, 0 7px 10px rgba(40, 97, 48, 0.22);
  transition: transform 0.15s, filter 0.15s;
  touch-action: manipulation;
}

.direction span {
  font-size: clamp(25px, 2.4vw, 36px);
  line-height: 0.8;
}

.direction small {
  font-size: clamp(11px, 0.85vw, 14px);
}

.direction:hover,
.direction:focus-visible {
  filter: brightness(1.12);
  outline: 4px solid rgba(255, 184, 56, 0.4);
}

.direction:active,
.direction.pressed {
  transform: translateY(4px) scale(0.98);
  box-shadow: 0 1px 0 #2f7336;
}

.direction.up { grid-area: 1 / 2; }
.direction.left { grid-area: 2 / 1; }
.direction.right { grid-area: 2 / 3; }
.direction.down { grid-area: 3 / 2; }

.pad-center {
  grid-area: 2 / 2;
  display: grid;
  place-items: center;
  border: 3px dashed #8fc56d;
  border-radius: 16px;
  font-size: 27px;
  background: #eef8d9;
}

.coordinate-card {
  margin-top: 8px;
  padding: 9px;
  border: 2px dashed #e5bb74;
  border-radius: 16px;
  background: #fff7df;
}

.coordinate-title {
  margin-bottom: 7px;
  text-align: center;
  font-size: clamp(13px, 1vw, 16px);
  font-weight: 900;
}

.coordinate-values {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}

.coordinate-value {
  padding: 7px 4px;
  text-align: center;
  border-radius: 12px;
  background: white;
  transition: transform 0.2s, background 0.2s, box-shadow 0.2s;
}

.coordinate-value span {
  display: block;
  font-size: clamp(10px, 0.8vw, 13px);
}

.coordinate-value strong {
  display: block;
  font-size: clamp(23px, 2vw, 34px);
}

.x-value strong { color: #e75c36; }
.y-value strong { color: #27894d; }

.coordinate-value.flash {
  transform: scale(1.09);
  background: #fff1a8;
  box-shadow: 0 0 0 4px rgba(255, 174, 31, 0.28);
}

.stage-wrap {
  min-width: 0;
  min-height: 0;
  padding: 4px;
  border-radius: 24px;
  background: white;
  box-shadow: var(--shadow);
}

.stage {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 430px;
  overflow: hidden;
  border: 3px solid #7db34c;
  border-radius: 20px;
  background:
    radial-gradient(ellipse at 15% 88%, #8ad35d 0 3%, transparent 3.3%),
    radial-gradient(ellipse at 77% 92%, #75c64e 0 4%, transparent 4.3%),
    linear-gradient(#bcecff 0 39%, #94d660 40% 100%);
}

.sky {
  position: absolute;
  inset: 0 0 56% 0;
  overflow: hidden;
  background: linear-gradient(#8bd9f5, #d8f5ff);
}

.sun {
  position: absolute;
  top: 5%;
  right: 7%;
  color: #ffd446;
  font-size: clamp(42px, 5vw, 78px);
  filter: drop-shadow(0 3px #e7a929);
  animation: sunPulse 3s ease-in-out infinite;
}

.cloud {
  position: absolute;
  width: 90px;
  height: 24px;
  border-radius: 30px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 24px -12px 0 3px rgba(255, 255, 255, 0.88), 50px 0 rgba(255, 255, 255, 0.88);
}

.cloud-one { top: 20%; left: 12%; animation: cloudDrift 15s ease-in-out infinite alternate; }
.cloud-two { top: 34%; left: 57%; transform: scale(0.7); animation: cloudDrift 19s ease-in-out infinite alternate-reverse; }

.hill {
  position: absolute;
  border-radius: 50% 50% 0 0;
}

.hill-back {
  width: 70%;
  height: 45%;
  left: -10%;
  bottom: 25%;
  background: #80c95c;
  transform: rotate(7deg);
}

.hill-front {
  width: 78%;
  height: 41%;
  right: -15%;
  bottom: 20%;
  background: #6cbc4e;
  transform: rotate(-5deg);
}

.tree {
  position: absolute;
  z-index: 2;
  bottom: 18%;
  width: 22px;
  height: 90px;
  border-radius: 9px;
  background: #9a6534;
}

.tree span,
.tree::before,
.tree::after {
  content: "";
  position: absolute;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: #3e9c45;
  box-shadow: inset -8px -8px rgba(22, 99, 42, 0.18);
}

.tree span { left: -21px; top: -40px; }
.tree::before { left: -43px; top: -19px; }
.tree::after { right: -43px; top: -16px; }
.tree-one { left: 7%; transform: scale(0.78); }
.tree-two { right: 8%; transform: scale(0.62); }

.coordinate-grid {
  position: absolute;
  z-index: 3;
  inset: 11% 8% 15%;
  border-radius: 18px;
  opacity: 0.68;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.23) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.23) 1px, transparent 1px);
  background-size: 10% 16.666%;
}

.axis {
  position: absolute;
  background: rgba(35, 111, 59, 0.63);
}

.axis-x {
  left: 0;
  right: 0;
  top: 50%;
  height: 3px;
}

.axis-y {
  top: 0;
  bottom: 0;
  left: 50%;
  width: 3px;
}

.axis span {
  position: absolute;
  padding: 2px 5px;
  border-radius: 6px;
  color: white;
  font-size: 12px;
  font-weight: 900;
  background: #328241;
}

.axis-x span { right: 0; top: -22px; }
.axis-y span { left: 7px; top: 0; }

.origin-label {
  position: absolute;
  left: calc(50% + 6px);
  top: calc(50% + 5px);
  color: #22673a;
  font-size: 12px;
  font-weight: 900;
}

.cheese-zone {
  position: absolute;
  z-index: 6;
  width: clamp(64px, 7vw, 96px);
  height: clamp(64px, 7vw, 96px);
  display: grid;
  place-items: center;
  border: 4px dashed #f7ac21;
  border-radius: 50%;
  background: rgba(255, 249, 191, 0.76);
  transform: translate(-50%, -50%);
  animation: targetGlow 1.5s ease-in-out infinite;
}

.goal-label {
  position: absolute;
  top: -22px;
  left: 50%;
  transform: translateX(-50%);
  padding: 3px 8px;
  border-radius: 8px;
  color: #8b591b;
  font-size: clamp(10px, 0.85vw, 13px);
  font-weight: 900;
  white-space: nowrap;
  background: #fff4b1;
}

.cheese-emoji {
  font-size: clamp(35px, 4vw, 60px);
  filter: drop-shadow(0 4px 2px rgba(108, 68, 14, 0.24));
}

.character {
  position: absolute;
  z-index: 8;
  width: clamp(62px, 6.2vw, 94px);
  height: clamp(62px, 6.2vw, 94px);
  display: grid;
  place-items: center;
  transform: translate(-50%, -50%);
  will-change: left, top;
}

.character > span {
  display: block;
  line-height: 1;
  font-size: clamp(52px, 5.5vw, 84px);
  filter: drop-shadow(0 6px 3px rgba(77, 52, 28, 0.25));
  transform-origin: center bottom;
}

.mouse {
  transition: left 0.28s cubic-bezier(.2,.8,.3,1), top 0.28s cubic-bezier(.2,.8,.3,1);
}

.mouse.moving > span {
  animation: mouseHop 0.28s ease-out;
}

.mouse-arrow {
  position: absolute;
  z-index: 2;
  top: -16px;
  color: white;
  font-size: 22px;
  font-weight: 900;
  text-shadow: 0 2px 0 #29763a, 2px 0 0 #29763a, -2px 0 0 #29763a;
}

.cat > span {
  animation: catWalk 0.6s ease-in-out infinite alternate;
}

.speech-bubble {
  position: absolute;
  top: -16px;
  left: 50%;
  padding: 4px 8px;
  transform: translateX(-50%);
  border: 2px solid #d9771a;
  border-radius: 10px;
  color: #a04b12;
  font-size: clamp(10px, 0.8vw, 13px);
  font-weight: 900;
  white-space: nowrap;
  background: white;
}

.stage-note {
  position: absolute;
  z-index: 10;
  right: 10px;
  bottom: 7px;
  left: 10px;
  padding: 6px 10px;
  overflow: hidden;
  border-radius: 10px;
  color: white;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: clamp(11px, 0.9vw, 15px);
  font-weight: 800;
  background: rgba(37, 113, 54, 0.86);
}

.knowledge-panel {
  display: flex;
  flex-direction: column;
}

.blocks-area {
  flex: 1;
  min-height: 205px;
  margin: 10px 0;
  padding: 10px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 7px;
  border: 2px dashed #e2bd84;
  border-radius: 16px;
  background: #fffdf7;
}

.empty-hint {
  text-align: center;
  color: #8b745e;
}

.empty-hint > span {
  display: block;
  margin-bottom: 7px;
  font-size: 34px;
}

.empty-hint p {
  margin: 5px 0 0;
  font-size: clamp(11px, 0.85vw, 14px);
}

.scratch-block {
  position: relative;
  padding: 9px 10px 9px 14px;
  border-radius: 8px;
  color: white;
  font-size: clamp(13px, 1.05vw, 18px);
  font-weight: 900;
  line-height: 1.25;
  box-shadow: inset 0 -3px rgba(0, 0, 0, 0.14), 0 3px 7px rgba(71, 51, 31, 0.13);
  animation: blockIn 0.25s ease-out both;
}

.scratch-block::before {
  content: "";
  position: absolute;
  top: -1px;
  left: 12px;
  width: 28px;
  height: 5px;
  border-radius: 0 0 5px 5px;
  background: rgba(255, 255, 255, 0.27);
}

.scratch-block.event { background: #f2a318; animation-delay: 0s; }
.scratch-block.motion { background: #4b83df; animation-delay: 0.08s; }
.scratch-block.coordinate { background: #54a4d8; animation-delay: 0.16s; }

.collision-tip {
  padding: 9px;
  display: flex;
  gap: 8px;
  align-items: center;
  border-radius: 14px;
  color: #65492d;
  background: #fff1bd;
}

.collision-tip .tip-icon { font-size: 26px; }
.collision-tip strong { font-size: clamp(13px, 1vw, 16px); }
.collision-tip p { margin: 2px 0 0; font-size: clamp(10px, 0.8vw, 13px); }

.thinking-panel {
  min-height: 102px;
  padding: 9px 14px;
  display: grid;
  grid-template-columns: minmax(150px, 0.55fr) minmax(520px, 2.4fr) minmax(150px, 0.65fr);
  align-items: center;
  gap: 14px;
  border: 3px solid white;
  border-radius: 22px;
  background: rgba(255, 250, 239, 0.97);
  box-shadow: var(--shadow);
}

.thinking-title {
  display: flex;
  align-items: center;
  gap: 8px;
}

.thinking-title > span {
  font-size: clamp(30px, 3vw, 46px);
}

.question-area > p {
  margin: 0 0 7px;
  color: #543c2f;
  font-size: clamp(14px, 1.15vw, 19px);
  font-weight: 900;
}

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

.answer-button {
  min-height: 39px;
  padding: 6px 9px;
  border: 2px solid #d9be93;
  border-radius: 12px;
  color: #594435;
  font-size: clamp(12px, 0.95vw, 16px);
  font-weight: 800;
  cursor: pointer;
  background: white;
  transition: transform 0.15s, border-color 0.15s, background 0.15s;
}

.answer-button:hover,
.answer-button:focus-visible {
  transform: translateY(-2px);
  border-color: var(--orange);
  outline: none;
}

.answer-button.correct {
  color: #216a32;
  border-color: #4caa53;
  background: #dff4d3;
}

.answer-button.wrong {
  color: #b3432d;
  border-color: #e56e55;
  background: #ffe1d7;
}

.answer-button:disabled {
  cursor: default;
}

.feedback {
  min-height: 54px;
  padding: 8px 10px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  color: #7e654e;
  text-align: center;
  font-size: clamp(12px, 0.9vw, 15px);
  font-weight: 900;
  background: #fff3c8;
}

.feedback.success { color: #256f34; background: #dcf1d2; }
.feedback.retry { color: #b04b2c; background: #ffe0d2; }

.result-overlay {
  position: absolute;
  z-index: 30;
  inset: 0;
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  background: rgba(255, 250, 226, 0.92);
  backdrop-filter: blur(4px);
  animation: overlayIn 0.3s ease-out;
}

.result-overlay[hidden] {
  display: none;
}

.result-icon {
  font-size: clamp(62px, 8vw, 112px);
  animation: resultBounce 0.7s ease-in-out infinite alternate;
}

.result-overlay h2 {
  margin: 7px 0 4px;
  color: var(--orange-dark);
  font-size: clamp(25px, 3vw, 45px);
}

.result-overlay p {
  margin: 0 0 16px;
  color: #386f40;
  font-size: clamp(16px, 1.5vw, 24px);
  font-weight: 900;
}

.celebration {
  position: absolute;
  inset: 7% 0 auto;
  color: #ffb017;
  font-size: clamp(28px, 4vw, 56px);
  letter-spacing: 18px;
  animation: sparkle 0.8s ease-in-out infinite alternate;
}

@keyframes mouseHop {
  50% { transform: translateY(-10px) rotate(-5deg); }
}

@keyframes catWalk {
  from { transform: translateY(0) rotate(-3deg); }
  to { transform: translateY(-5px) rotate(3deg); }
}

@keyframes targetGlow {
  50% { box-shadow: 0 0 0 10px rgba(255, 195, 46, 0.18); transform: translate(-50%, -50%) scale(1.04); }
}

@keyframes blockIn {
  from { opacity: 0; transform: translateX(18px); }
}

@keyframes overlayIn {
  from { opacity: 0; }
}

@keyframes resultBounce {
  to { transform: translateY(-8px) rotate(5deg); }
}

@keyframes sparkle {
  to { transform: scale(1.12); opacity: 0.65; }
}

@keyframes sunPulse {
  50% { transform: rotate(8deg) scale(1.05); }
}

@keyframes cloudDrift {
  to { transform: translateX(45px); }
}

@media (max-width: 1050px) {
  .lab-layout {
    grid-template-columns: minmax(180px, 0.72fr) minmax(500px, 2.2fr);
  }

  .knowledge-panel {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: auto 1fr minmax(200px, 0.7fr);
    align-items: center;
    gap: 10px;
  }

  .knowledge-panel .panel-heading {
    border-bottom: 0;
    padding-bottom: 0;
  }

  .blocks-area {
    min-height: 110px;
    margin: 0;
  }
}

@media (max-width: 780px) {
  .app-shell {
    display: block;
  }

  .topbar,
  .lab-layout,
  .thinking-panel {
    margin-bottom: 10px;
  }

  .topbar {
    grid-template-columns: auto 1fr;
  }

  .topbar .reset-button {
    grid-column: 1 / -1;
  }

  .topbar p,
  .keyboard-tip {
    display: none;
  }

  .lab-layout {
    display: flex;
    flex-direction: column;
  }

  .control-panel {
    order: 2;
  }

  .stage-wrap {
    order: 1;
    height: 480px;
  }

  .knowledge-panel {
    order: 3;
    display: block;
  }

  .thinking-panel {
    grid-template-columns: 1fr;
  }

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

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
  }
}
