* {
  box-sizing: border-box;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  /*タブレット連打時の拡大防止 */
}

html {
  margin: 0;
  height: 100%;
}

body {
  margin: 0;
  height: 100vh;
  font-family:
    -apple-system,
    BlinkMacSystemFont,
    "Hiragino Sans",
    "Yu Gothic",
    "Meiryo",
    sans-serif;
  background: #f2f2f2;
  display: flex;
  justify-content: center;
  align-items: center;
}

.container {
  margin: 0 auto;
  position: relative;
  background: linear-gradient(#8fd3f4 0%, #b9e8ff 30%, #cdf1ff 38%, #9be59b 38%, #7ed07e 100%);
  border: 2px solid #333;
  width: 100%;
  max-width: 1196px;
  height: 540px;
  display: flex;
  flex-direction: column;
}

.game-header {
  height: 50px;
  flex: 0 0 50px;
  align-items: center;
  position: relative;
  z-index: 70;
  background: transparent;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 8px;
  padding: 5px 12px;
  color: #345;
}

.info {
  display: flex;
  font-weight: bold;
  width: auto;
  justify-content: flex-start;
  align-items: center;
  flex-wrap: nowrap;
  font-size: 16px;
  gap: 28px;
}

.game-main {
  position: relative;
  flex: 1;
  overflow: hidden;
  display: grid;
  place-items: center;
  min-height: 0;
  background: transparent;
}

.cloud {
  position: absolute;
  background: #fff;
  border-radius: 50px;
  opacity: 0.9;
}

.cloud::before, .cloud::after {
  content: "";
  position: absolute;
  background: #fff;
  border-radius: 50%;
}

.cloud1 {
  width: 90px;
  height: 34px;
  top: 40px;
  left: 8%;
  animation: drift 40s linear infinite;
}

.cloud1::before {
  width: 46px;
  height: 46px;
  top: -22px;
  left: 10px;
}

.cloud1::after {
  width: 36px;
  height: 36px;
  top: -16px;
  left: 46px;
}

.cloud2 {
  width: 70px;
  height: 28px;
  top: 90px;
  left: 55%;
  animation: drift 55s linear infinite;
}

.cloud2::before {
  width: 36px;
  height: 36px;
  top: -18px;
  left: 8px;
}

.cloud2::after {
  width: 28px;
  height: 28px;
  top: -12px;
  left: 36px;
}

.cloud3 {
  width: 60px;
  height: 24px;
  top: 25px;
  left: 78%;
  animation: drift 65s linear infinite;
}

.cloud3::before {
  width: 30px;
  height: 30px;
  top: -15px;
  left: 6px;
}

.cloud3::after {
  width: 24px;
  height: 24px;
  top: -10px;
  left: 30px;
}

@keyframes drift {
  from {
    transform: translateX(0);
  }

  to {
    transform: translateX(-1400px);
  }

}

.sun {
  position: absolute;
  top: 24px;
  right: 40px;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff6b0, #ffd93d);
  box-shadow: 0 0 0 10px rgba(255,217,61,0.3);
}

.hill {
  position: absolute;
  bottom: 150px;
  width: 260px;
  height: 120px;
  background: #6bc06b;
  border-radius: 50%;
}

.hill1 {
  left: -60px;
  background: #63b563;
}

.hill2 {
  right: -80px;
  background: #74c974;
}

.ground-line {
  position: absolute;
  bottom: 270px;
  width: 100%;
  height: 6px;
  background: #5a8f4f;
  opacity: 0.4;
}

.track {
  position: absolute;
  bottom: 208px;
  width: 100%;
  height: 52px;
  background: #a9784f;
  border-top: 4px solid #8a5f3c;
  border-bottom: 4px solid #8a5f3c;
}

#gameArea.on-start .track,   #gameArea.on-start .ground-line {
  display: none;
}

.track::before {
  content: "";
  position: absolute;
  top: 8px;
  left: 0;
  right: 0;
  height: 6px;
  background: repeating-linear-gradient(90deg, #5c473a 0 20px, transparent 20px 44px);
}

.track::after {
  content: "";
  position: absolute;
  bottom: 8px;
  left: 0;
  right: 0;
  height: 6px;
  background: #7a7a7a;
  box-shadow: 0 -20px 0 -2px #7a7a7a;
}

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.hidden {
  display: none !important;
}

#startScreen {
  gap: 10px;
}

#startScreen h1 {
  font-size: 46px;
  color: #ff5e5e;
  text-shadow: 4px 4px 0 #fff, 6px 6px 0 rgba(0,0,0,0.15);
  margin: 0;
  letter-spacing: 4px;
}

.bigBtn {
  font-size: 30px;
  font-weight: bold;
  color: #fff;
  background: linear-gradient(#ff9a56, #ff6f3c);
  border: none;
  border-radius: 50px;
  padding: 18px 56px;
  box-shadow: 0 8px 0 #c94f22, 0 12px 18px rgba(0,0,0,0.3);
  cursor: pointer;
  transition: transform 0.08s;
  touch-action: manipulation;
  margin-top: 6px;
}

.bigBtn:active {
  transform: translateY(6px);
  box-shadow: 0 2px 0 #c94f22, 0 4px 8px rgba(0,0,0,0.3);
}

.startTrainDecor {
  font-size: 62px;
  line-height: 1;
  animation: chugStart 2.5s ease-in-out infinite;
}

@keyframes chugStart {
  0%, 100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-6px);
  }

}

.diffLabel {
  font-size: 18px;
  font-weight: bold;
  color: #345;
  margin: 4px 0 0 0;
}

.diffRow {
  display: flex;
  gap: 12px;
}

.diffBtn {
  font-size: 19px;
  font-weight: bold;
  color: #345;
  background: #fff;
  border: 3px solid #dbe6ee;
  border-radius: 30px;
  padding: 12px 20px;
  cursor: pointer;
  box-shadow: 0 4px 0 #c9d6e0;
  touch-action: manipulation;
  transition: transform 0.08s;
}

.diffBtn:active {
  transform: translateY(3px);
}

.diffBtn.active {
  background: linear-gradient(#5cc8ff, #2f9ee0);
  color: #fff;
  border-color: #2f9ee0;
  box-shadow: 0 4px 0 #1c6f9e;
}

#trainStage {
  position: absolute;
  top: 8px;
  left: 0;
  right: 0;
  bottom: 234px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  overflow: visible;
}

#trainWrap {
  display: flex;
  align-items: flex-end;
  transform: translateX(0);
  scale: var(--train-scale, 1);
  transform-origin: center bottom;
}

.wheel {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: repeating-conic-gradient(#333 0deg 20deg, #666 20deg 40deg);
  border: 4px solid #222;
  position: absolute;
  bottom: -13px;
}

@keyframes spin {
  from {
    transform: rotate(0);
  }

  to {
    transform: rotate(-360deg);
  }

}

#trainWrap.moving .wheel {
  animation: spin 0.22s linear infinite;
}

#locomotive {
  position: relative;
  width: 195px;
  height: 169px;
  margin-right: 8px;
  flex-shrink: 0;
}

.loco-body {
  position: absolute;
  bottom: 13px;
  left: 26px;
  width: 169px;
  height: 91px;
  background: linear-gradient(#5b6b8c, #3d4a66);
  border-radius: 20px 20px 10px 10px;
  border: 4px solid #26304a;
}

.loco-cab {
  position: absolute;
  bottom: 78px;
  left: 26px;
  width: 71px;
  height: 58px;
  background: #3d4a66;
  border-radius: 12px 12px 0 0;
  border: 4px solid #26304a;
}

.loco-cab::after {
  content: "";
  position: absolute;
  top: 10px;
  left: 13px;
  width: 45px;
  height: 26px;
  background: #cfeeff;
  border-radius: 5px;
  border: 2px solid #26304a;
}

.loco-nose {
  position: absolute;
  bottom: 13px;
  left: 0;
  width: 52px;
  height: 71px;
  background: #c0392b;
  border-radius: 26px 5px 5px 26px;
  border: 4px solid #8a241a;
}

.loco-nose::after {
  content: "";
  position: absolute;
  top: 23px;
  left: -12px;
  width: 20px;
  height: 20px;
  background: #ffe066;
  border-radius: 50%;
  box-shadow: 0 0 10px #ffe066;
}

.chimney {
  position: absolute;
  bottom: 94px;
  left: 137px;
  width: 23px;
  height: 39px;
  background: #333;
  border-radius: 5px 5px 3px 3px;
}

.smoke {
  position: absolute;
  bottom: 130px;
  left: 139px;
  width: 21px;
  height: 21px;
  background: rgba(255,255,255,0.85);
  border-radius: 50%;
  animation: puff 2s ease-out infinite;
}

.smoke:nth-child(2) {
  animation-delay: 0.6s;
}

.smoke:nth-child(3) {
  animation-delay: 1.2s;
}

@keyframes puff {
  0% {
    transform: translate(0,0) scale(0.6);
    opacity: 0.9;
  }

  100% {
    transform: translate(26px,-64px) scale(1.6);
    opacity: 0;
  }

}

.loco-wheel1 {
  left: 39px;
}

.loco-wheel2 {
  left: 98px;
}

.loco-wheel3 {
  left: 153px;
}

#cars {
  display: flex;
  align-items: flex-end;
}

.car {
  position: relative;
  width: 161px;
  height: 135px;
  margin-right: 10px;
  flex-shrink: 0;
}

.car-body {
  position: absolute;
  bottom: 13px;
  width: 100%;
  height: 96px;
  border-radius: 13px;
  border: 4px solid rgba(0,0,0,0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 62px;
  font-weight: bold;
  color: #fff;
  text-shadow: 2px 2px 0 rgba(0,0,0,0.25);
}

.car-body.mystery {
  font-size: 66px;
}

.car .wheel1 {
  left: 23px;
}

.car .wheel2 {
  left: 104px;
}

.car-body.small {
  font-size: 42px;
}

.car0 .car-body {
  background: linear-gradient(#ffb64c, #ff9500);
}

.car1 .car-body {
  background: linear-gradient(#7ed6a5, #3fae72);
}

.car2 .car-body {
  background: linear-gradient(#7bb8ff, #3d7ee0);
}

.car3 .car-body {
  background: linear-gradient(#ff8fb1, #ef4d80);
}

.car4 .car-body {
  background: linear-gradient(#c79bff, #8e58e0);
}

.car-body.pop {
  animation: pop 0.5s ease;
}

.mysteryHint {
  position: absolute;
  top: -34px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  white-space: nowrap;
  z-index: 30;
  animation: hintBounce 1.1s ease-in-out infinite;
  pointer-events: none;
}

.mysteryHint .hintText {
  background: #fff;
  color: #ff5e5e;
  font-size: 18px;
  font-weight: bold;
  padding: 5px 14px;
  border-radius: 16px;
  box-shadow: 0 3px 8px rgba(0,0,0,0.3);
}

.mysteryHint .hintArrow {
  font-size: 28px;
  margin-top: -2px;
  filter: drop-shadow(0 2px 2px rgba(0,0,0,0.3));
}

@keyframes hintBounce {
  0%, 100% {
    transform: translateX(-50%) translateY(0);
  }

  50% {
    transform: translateX(-50%) translateY(10px);
  }

}

.tapHint {
  position: absolute;
  top: 4px;
  left: 50%;
  margin-left: -24px;
  font-size: 48px;
  z-index: 60;
  pointer-events: none;
  filter: drop-shadow(0 3px 4px rgba(0,0,0,0.35));
  animation: tapSweep 2.2s ease-in-out infinite;
}

@keyframes tapSweep {
  0%, 100% {
    transform: translateX(-165px) rotate(-8deg);
  }

  50% {
    transform: translateX(165px) rotate(-8deg);
  }

}

@keyframes pop {
  0% {
    transform: scale(1);
  }

  40% {
    transform: scale(1.35);
  }

  100% {
    transform: scale(1);
  }

}

#choiceArea {
  position: absolute;
  bottom: 62px;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  gap: 18px;
  z-index: 40;
}

.choiceBtn {
  width: 98px;
  height: 98px;
  border-radius: 50%;
  font-size: 48px;
  font-weight: bold;
  color: #fff;
  background: linear-gradient(#5cc8ff, #2f9ee0);
  border: 4px solid #fff;
  box-shadow: 0 6px 0 #1c6f9e, 0 10px 14px rgba(0,0,0,0.25);
  cursor: pointer;
  touch-action: manipulation;
}

.choiceBtn:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 #1c6f9e;
}

.choiceBtn.disabled {
  opacity: 0.5;
  pointer-events: none;
}

.choiceBtn.small {
  font-size: 34px;
}

.car.shakeWrong .car-body {
  animation: carShake 0.5s ease;
}

@keyframes carShake {
  0%, 100% {
    transform: translateX(0) rotate(0);
  }

  15% {
    transform: translateX(-8px) rotate(-4deg);
  }

  30% {
    transform: translateX(7px) rotate(4deg);
  }

  45% {
    transform: translateX(-6px) rotate(-3deg);
  }

  60% {
    transform: translateX(6px) rotate(3deg);
  }

  75% {
    transform: translateX(-3px) rotate(-1deg);
  }

}

.flyingNumber {
  position: fixed;
  font-size: 48px;
  font-weight: bold;
  color: #fff;
  text-shadow: 2px 2px 0 rgba(0,0,0,0.25);
  z-index: 999;
  pointer-events: none;
  transition: transform 0.8s cubic-bezier(0.3,0.6,0.3,1), opacity 0.8s;
}

#resultScreen h1 {
  font-size: 50px;
  color: #ff8a00;
  text-shadow: 4px 4px 0 #fff;
  margin: 0 0 10px;
}

#resultStars {
  font-size: 54px;
  margin-bottom: 10px;
  letter-spacing: 8px;
}

.game-header h1 {
  margin: 0;
  font-size: 22px;
  white-space: nowrap;
}

.score-display {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  background: #fff;
  border-radius: 40px;
  padding: 6px 16px;
  font-size: 18px;
  font-weight: bold;
  color: #444;
  box-shadow: 0 2px 0 #e8a000;
}

#scoreBadge {
  display: inline-block;
  font-size: 22px;
  color: #ff6f3c;
  min-width: 36px;
  text-align: center;
}

#scoreBadge.score-up {
  animation: scoreUp .5s ease-out;
}

@keyframes scoreUp {
  0% {
    transform: translateY(5px) scale(.8);
  }

  45% {
    transform: translateY(-5px) scale(1.4);
  }

  75% {
    transform: translateY(1px) scale(.95);
  }

  100% {
    transform: translateY(0) scale(1);
  }

}

@media (prefers-reduced-motion: reduce) {
  #scoreBadge.score-up {
    animation: none;
  }

}

.mistake-slots {
  display: inline-flex;
  gap: 4px;
}

.mistake-slot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border: 2px solid #91a6b5;
  border-radius: 7px;
  font-size: 17px;
  line-height: 1;
}

.mistake-slot.filled {
  background: #fff0f0;
  border-color: #ec7979;
}

.header-actions {
  display: flex;
  justify-self: end;
  gap: 8px;
  align-items: center;
}

.sound-btn {
  background: #fff0ad;
  border: 3px solid #f2b321;
  border-radius: 50px;
  padding: 6px 16px;
  font-size: 18px;
  font-weight: 700;
  color: #694100;
  cursor: pointer;
  letter-spacing: 1px;
  box-shadow: 0 3px 0 #d89500;
  min-width: 104px;
}

.sound-btn:hover {
  background: #ffe680;
  border-color: #dc9700;
  color: #5a3500;
}

.sound-btn.sound-off {
  background: #e9edf1;
  border-color: #aeb7c0;
  color: #66717b;
  box-shadow: 0 3px 0 #929ba4;
}

.start-sound-btn {
  position: absolute;
  top: 12px;
  right: 14px;
  z-index: 70;
}

#resultScreen {
  background: rgba(255,255,255,.65);
}

.result-confetti {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 60;
}

.confetti-piece {
  position: absolute;
  top: -20px;
  width: 9px;
  height: 15px;
  border-radius: 2px;
  animation: resultConfettiFall 3s linear both;
}

@keyframes resultConfettiFall {
  0% {
    transform: translate(0, -20px) rotate(0);
    opacity: 0;
  }

  8% {
    opacity: 1;
  }

  85% {
    opacity: 1;
  }

  100% {
    transform: translate(var(--drift), 580px) rotate(var(--turn));
    opacity: 0;
  }

}

@media (prefers-reduced-motion: reduce) {
  .result-confetti {
    display: none;
  }

}

.result-actions {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 20px;
  width: min(100% - 24px, 680px);
  margin-top: 6px;
}

.result-actions .bigBtn {
  flex: 1;
  min-width: 0;
  margin-top: 0;
  padding: 18px 12px;
  font-size: clamp(16px, 3.5vw, 30px);
  white-space: nowrap;
}

.homeBtn {
  margin-top: 0;
  background: linear-gradient(#71bfff, #398cdb);
  box-shadow: 0 8px 0 #2465a4, 0 12px 18px rgba(0,0,0,.3);
}

.homeBtn:active {
  box-shadow: 0 2px 0 #2465a4, 0 4px 8px rgba(0,0,0,.3);
}

.result-level {
  margin: 0 0 12px;
  padding: 5px 20px;
  border-radius: 20px;
  background: #fff;
  color: #345;
  font-size: 20px;
  font-weight: bold;
}

.result-high-score {
  margin: 0 0 10px;
  color: #345;
  font-size: 22px;
  font-weight: bold;
}

#quitBtn {
  font-size: 20px;
  font-weight: bold;
  color: #fff;
  background: #ff5e5e;
  border: none;
  border-radius: 40px;
  padding: 6px 18px;
  box-shadow: 0 5px 0 #c73e3e;
  cursor: pointer;
  touch-action: manipulation;
}

#quitBtn:active {
  transform: translateY(4px);
  box-shadow: 0 1px 0 #c73e3e;
}

.hintArrow {
  width: 0;
  height: 0;
  border-left: 10px solid transparent;
  border-right: 10px solid transparent;
  border-top: 16px solid white;
}

@media (max-width: 900px) {
  .game-header {
    height: 76px;
    flex-basis: 76px;
    padding: 5px;
    gap: 4px;
  }

  .game-header h1 {
    font-size: clamp(12px, 3vw, 19px);
  }

  .info {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    font-size: 12px;
  }

  .score-display {
    gap: 4px;
    padding: 3px 8px;
    font-size: 12px;
  }

  #scoreBadge {
    font-size: 18px;
    min-width: 24px;
  }

  .result-actions {
    gap: 12px;
  }

  .mistake-slots {
    gap: 3px;
  }

  .mistake-slot {
    width: 18px;
    height: 18px;
    border-radius: 5px;
    font-size: 12px;
  }

  .header-actions {
    gap: 4px;
  }

  #quitBtn {
    font-size: 13px;
    padding: 6px 10px;
  }

  .sound-btn {
    min-width: 0;
    padding: 6px 8px;
    font-size: 14px;
  }

  #startScreen h1 {
    font-size: clamp(26px, 7vw, 42px);
    letter-spacing: 1px;
  }

  .diffRow {
    gap: 6px;
  }

  .diffBtn {
    font-size: 16px;
    padding: 12px;
  }

  #choiceArea {
    gap: 10px;
  }

  .choiceBtn {
    width: min(20vw, 98px);
    height: min(20vw, 98px);
    font-size: 36px;
  }

  .choiceBtn.small {
    font-size: 26px;
  }

  .tapHint {
    animation-name: tapSweepSmall;
  }

}

@keyframes tapSweepSmall {
  0%,100% {
    transform: translateX(-110px);
  }

  50% {
    transform: translateX(110px);
  }

}

#resultScoreText {
  font-size: 30px;
  color: #345;
  background: rgba(255,255,255,0.85);
  padding: 10px 26px;
  border-radius: 20px;
  margin: 0 0 20px 0;
}

/* 5個のバツを強調してから結果画面へ進む。 */
.mistake-slots.mistakes-full .mistake-slot {
  border-color: #dc3030;
  background: #ffd6d6;
  box-shadow: 0 0 0 3px #ef444433;
  animation: mistakes-full-pulse 600ms ease-in-out 2;
}

@keyframes mistakes-full-pulse {
  0%, 100% { transform: scale(1); }
  45% { transform: translateY(-4px) scale(1.18); }
  70% { transform: translateY(1px) scale(1.05); }
}

@media (prefers-reduced-motion: reduce) {
  .mistake-slots.mistakes-full .mistake-slot {
    animation: none;
  }
}