:root {
  --ink: #3c3151;
  --cream: #fffaf0;
  --pink: #ff8fb8;
  --yellow: #ffd75e;
  --mint: #8ee3c0;
  --blue: #7fc8f8;
  --purple: #9e8cff;
  --shadow: #3c315121;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "Microsoft YaHei", "PingFang SC", sans-serif;
  background:
    radial-gradient(circle at 10% 15%, #fff 0 7px, transparent 8px),
    radial-gradient(circle at 90% 30%, #fff 0 5px, transparent 6px),
    linear-gradient(145deg, #dff7ff, #fff3cf 55%, #ffe3ee);
}

button { font: inherit; color: inherit; }
.hidden { display: none !important; }

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

.hero {
  position: relative;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 18px 4px 24px;
}

.back {
  position: absolute;
  top: 0;
  right: 4px;
  color: var(--ink);
  font-weight: 800;
  text-decoration: none;
}

.mascot {
  display: grid;
  width: 92px;
  height: 92px;
  flex: 0 0 auto;
  place-items: center;
  border: 4px solid #fff;
  border-radius: 32px;
  background: var(--pink);
  box-shadow: 0 10px 0 #e66e9b;
  font-size: 54px;
  transform: rotate(-5deg);
}

.eyebrow { margin: 0 0 3px; color: #8b5b80; font-weight: 900; letter-spacing: .12em; }
h1 { margin: 0; font-size: clamp(34px, 7vw, 58px); line-height: 1.08; }
.subtitle { margin: 8px 0 0; color: #665e77; font-weight: 700; }

.panel {
  padding: clamp(20px, 4vw, 34px);
  border: 4px solid #fff;
  border-radius: 30px;
  background: #fffdf9ed;
  box-shadow: 0 18px 45px var(--shadow);
}

.panel h2 { margin: 0 0 20px; text-align: center; font-size: 28px; }
.difficulty { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.difficulty-card {
  display: grid;
  gap: 7px;
  padding: 20px 10px;
  border: 3px solid transparent;
  border-radius: 20px;
  background: #f5f1ff;
  cursor: pointer;
  transition: transform .15s, border-color .15s;
}
.difficulty-card:hover { transform: translateY(-3px); }
.difficulty-card.selected { border-color: var(--purple); background: #eeeaff; box-shadow: 0 7px 0 #cfc5ff; }
.difficulty-card span { font-size: 34px; }
.difficulty-card strong { font-size: 18px; }
.difficulty-card small { color: #71677e; }

.rule-box {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px 20px;
  margin: 26px 0;
  padding: 16px;
  border-radius: 18px;
  background: #fff5d1;
}
.rule-box strong { width: 100%; text-align: center; }
.rule-box span { font-size: 14px; font-weight: 700; }
.mini { display: inline-block; width: 25px; text-align: center; color: #f07a2b; }
.straight { color: #2d9c8c; }

.primary, .secondary {
  display: block;
  min-width: 180px;
  margin: 0 auto;
  padding: 13px 24px;
  border: 3px solid var(--ink);
  border-radius: 15px;
  font-weight: 900;
  cursor: pointer;
}
.primary { background: var(--yellow); box-shadow: 0 6px 0 var(--ink); }
.primary:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--ink); }
.secondary { background: #fff; }

.statusbar { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.statusbar div { padding: 12px; border-radius: 16px; background: #f4f1fb; text-align: center; }
.statusbar small, .result-grid small { display: block; color: #746a81; font-weight: 700; }
.statusbar strong { font-size: 21px; }

.mission { margin: 18px 0; text-align: center; }
.mission p { margin: 0 0 10px; font-size: 20px; font-weight: 900; }
.legend { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; color: #766d82; font-size: 12px; font-weight: 700; }
.legend span { padding: 5px 9px; border-radius: 999px; background: #f2eff7; }

.machine {
  display: flex;
  min-height: 210px;
  align-items: center;
  justify-content: center;
  gap: 0;
  overflow-x: auto;
  padding: 36px 12px;
  border-radius: 22px;
  background: linear-gradient(#d7f3ff, #edfaff 58%, #cfe9c6 59%);
  box-shadow: inset 0 0 0 3px #fff;
}
.part { position: relative; display: grid; flex: 0 0 74px; place-items: center; }
.gear {
  display: grid;
  width: 66px;
  height: 66px;
  place-items: center;
  color: #fff;
  border: 5px dashed #fff;
  border-radius: 50%;
  background: var(--part-color);
  box-shadow: 0 0 0 5px var(--part-color), 0 8px 12px #37475a33;
  font-size: 34px;
  font-weight: 900;
}
.part.start .gear { outline: 5px solid var(--yellow); }
.part.target .gear { outline: 5px solid var(--pink); }
.tag { position: absolute; top: -32px; padding: 4px 8px; border-radius: 10px; background: #fff; font-size: 12px; font-weight: 900; white-space: nowrap; }
.direction { position: absolute; bottom: -32px; font-size: 25px; font-weight: 900; }
.connector { display: grid; flex: 0 0 46px; place-items: center; color: #675a73; font-size: 28px; font-weight: 900; }
.connector small { display: block; font-size: 9px; white-space: nowrap; }
.machine.reveal .gear { animation: spin-cw .7s ease; }
.machine.reveal .part.ccw .gear { animation-name: spin-ccw; }
@keyframes spin-cw { to { transform: rotate(180deg); } }
@keyframes spin-ccw { to { transform: rotate(-180deg); } }

.answers { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; max-width: 520px; margin: 22px auto 0; }
.answers button {
  padding: 14px;
  border: 3px solid var(--ink);
  border-radius: 17px;
  background: #fff;
  font-weight: 900;
  cursor: pointer;
}
.answers button:hover:not(:disabled) { background: #fff3bd; transform: translateY(-2px); }
.answers button.correct { background: #baf2d9; }
.answers button.wrong { background: #ffd2dc; }
.arrow { display: block; font-size: 32px; color: #e76f9d; }
.counter { color: #628fe5; }
.feedback { min-height: 48px; padding: 12px 0 4px; text-align: center; font-weight: 900; }

.result { text-align: center; }
.result-badge { font-size: 76px; }
.result h2 { margin: 8px 0; }
.result > p { color: #665e77; font-weight: 700; }
.result-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 24px 0; }
.result-grid div { padding: 18px 8px; border-radius: 18px; background: #f4f1fb; }
.result-grid strong { display: block; font-size: 26px; }
.result-actions { display: flex; justify-content: center; gap: 14px; }
.result-actions button { margin: 0; }

@media (max-width: 680px) {
  .hero { align-items: flex-end; }
  .mascot { width: 70px; height: 70px; border-radius: 24px; font-size: 42px; }
  .difficulty { grid-template-columns: 1fr; }
  .difficulty-card { grid-template-columns: auto 1fr; align-items: center; text-align: left; }
  .difficulty-card span { grid-row: 1 / 3; }
  .machine { justify-content: flex-start; }
  .part { flex-basis: 62px; }
  .gear { width: 54px; height: 54px; font-size: 28px; }
  .connector { flex-basis: 36px; font-size: 22px; }
  .result-actions { flex-direction: column; }
  .result-actions button { width: 100%; }
}
