* {
  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;
  background: var(--sky2);
  border: 2px solid #333;
  width: 100%;
  max-width: 1196px;
  height: 540px;
  display: flex;
  flex-direction: column;
  position: relative;
}
.game-header {
  height: 50px;
  padding: 3px 10px;
  background: transparent;
  flex: 0 0 50px;
  display: grid;
  align-items: center;
  position: relative;
  z-index: 5;
  grid-template-columns: 1fr auto 1fr;
  gap: 8px;
}
.info {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-weight: bold;
  flex-wrap: wrap;
  width: auto;
}
.game-main {
  position: relative;
  background: transparent;
  flex: 1;
  overflow: hidden;
  display: grid;
  place-items: center;
  min-height: 0;
}

.btn {
  transition:
    background-color 0.15s ease,
    transform 0.05s ease;
}

.btn:hover {
  background: #d6f0ff;
}

.btn:active {
  transform: scale(0.98);
}

:root {
  --sky1: #8fd9ff;
  --sky2: #c9f3ff;
  --grass: #7fc94a;
  --grass-dark: #69b23a;
  --road: #858c95;
  --road-line: #f7f2df;
  --sun: #ffd75e;
  --panel: #fffdf3;
  --panel-edge: #ffcf5c;
  --coral: #ff6f5e;
  --coral-dark: #e85445;
  --ink: #3a3427;
}

.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.screen.active {
  display: flex;
}
#screen-start {
  background: linear-gradient(
    180deg,
    var(--sky2) 0%,
    var(--sky1) 55%,
    var(--grass) 55%,
    var(--grass-dark) 100%
  );
  width: 100%;
  height: 100%;
}
.sun {
  position: absolute;
  top: 6%;
  right: 8%;
  width: 70px;
  height: 70px;
  border-radius: 50%;
  background: var(--sun);
  box-shadow: 0 0 0 10px rgba(255, 215, 94, 0.35);
}
.cloud {
  position: absolute;
  background: #fff;
  border-radius: 50px;
  opacity: 0.9;
}

.title-wrap {
  text-align: center;
  z-index: 2;
}
.title {
  font-size: clamp(28px, 5vw, 52px);
  font-weight: 900;
  margin: 0 0 6px;
  letter-spacing: 2px;
  text-shadow:
    3px 3px 0 #fff,
    3px 3px 0 #fff;
}
.title span {
  display: inline-block;
}
.title .c0 {
  color: #ff6f5e;
}
.title .c1 {
  color: #ffb648;
}
.title .c2 {
  color: #4bc767;
}
.title .c3 {
  color: #4baaff;
}
.title .c4 {
  color: #8a6bd1;
}
.title .c5 {
  color: #ff6fa3;
}

.subtitle {
  font-size: clamp(14px, 2vw, 20px);
  color: var(--ink);
  background: var(--panel);
  display: inline-block;
  padding: 6px 22px;
  border-radius: 20px;
  border: 3px dashed var(--panel-edge);
  margin-bottom: 22px;
}

.demo-row {
  display: flex;
  gap: 14px;
  justify-content: center;
  margin-bottom: 26px;
  z-index: 2;
}
.demo-car {
  width: 86px;
  height: 54px;
  filter: drop-shadow(0 6px 0 rgba(0, 0, 0, 0.12));
}

.big-btn {
  font-size: clamp(22px, 3vw, 34px);
  font-weight: 900;
  color: #fff;
  background: linear-gradient(
    180deg,
    #ff8a6f,
    var(--coral) 60%,
    var(--coral-dark)
  );
  border: none;
  border-radius: 60px;
  padding: 18px 64px;
  box-shadow:
    0 8px 0 #c8402f,
    0 14px 18px rgba(0, 0, 0, 0.2);
  cursor: pointer;
  letter-spacing: 4px;
  animation: pulse 1.8s ease-in-out infinite;
  z-index: 2;
}
.big-btn:active {
  transform: translateY(6px);
  box-shadow: 0 2px 0 #c8402f;
}
@keyframes pulse {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.045);
  }
}

#screen-game {
  flex-direction: column;
  justify-content: flex-start;
}

.target-board {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--panel);
  margin: 10px auto 0;
  padding: 8px 26px;
  border-radius: 26px;
  border: 3px solid var(--panel-edge);
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.06);
}
.target-caption {
  font-size: 16px;
  color: #8a7c4d;
  font-weight: 700;
}
.target-car-icon {
  width: 76px;
  height: 48px;
}
.target-label {
  font-size: clamp(20px, 2.6vw, 30px);
  font-weight: 900;
  color: var(--ink);
}
.stage {
  position: relative;
  flex: 1 1 auto;
  width: 100%;
  overflow: hidden;
  background: linear-gradient(180deg, var(--sky2) 0%, var(--sky1) 38%);
  min-height: 0;
}

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

.street-wrap {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  top: 28px;
  display: flex;
  flex-direction: column;
}
.road-segment {
  position: relative;
  flex: 1 1 0;
  min-height: 0;
  background: var(--road);
}
.lane-divider {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 0;
  border-top: 4px dashed var(--road-line);
  opacity: 0.85;
}
.car-sprite {
  position: absolute;
  cursor: pointer;
  touch-action: manipulation;
  filter: drop-shadow(0 6px 4px rgba(0, 0, 0, 0.25));
  padding: 0;
  border: 0;
  background: transparent;
}
.car-sprite.wrong {
  animation: shake 0.4s;
}
.car-sprite.correct {
  animation: pop 0.6s;
}
@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  20% {
    transform: translateX(-8px) rotate(-3deg);
  }
  40% {
    transform: translateX(8px) rotate(3deg);
  }
  60% {
    transform: translateX(-6px) rotate(-2deg);
  }
  80% {
    transform: translateX(6px) rotate(2deg);
  }
}
@keyframes pop {
  0% {
    transform: scale(1);
  }
  40% {
    transform: scale(1.25);
  }
  100% {
    transform: scale(1.05);
  }
}
.mark-overlay {
  position: absolute;
  font-size: 25px;
  font-weight: 900;
  pointer-events: none;
  transform: translate(-50%, -50%) scale(0.3);
  opacity: 0;
  z-index: 4;
  white-space: nowrap;
}
.mark-overlay.show {
  animation: markpop 0.7s ease-out forwards;
}
@keyframes markpop {
  0% {
    transform: translate(-50%, -50%) scale(0.3);
    opacity: 0;
  }
  30% {
    transform: translate(-50%, -50%) scale(1.2);
    opacity: 1;
  }
  60% {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
  }
  100% {
    transform: translate(-50%, -50%) scale(1);
    opacity: 0;
  }
}
.mark-overlay.ok {
  color: #3fb955;
  text-shadow:
    0 0 0 #fff,
    3px 3px 0 #fff,
    -3px -3px 0 #fff,
    3px -3px 0 #fff,
    -3px 3px 0 #fff;
}
.mark-overlay.ng {
  color: #ff5b5b;
  text-shadow:
    0 0 0 #fff,
    3px 3px 0 #fff,
    -3px -3px 0 #fff,
    3px -3px 0 #fff,
    -3px 3px 0 #fff;
}
.toast {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  background: #fff;
  border: 3px solid var(--panel-edge);
  border-radius: 20px;
  padding: 8px 22px;
  font-size: 18px;
  font-weight: 800;
  color: var(--ink);
  opacity: 0;
  pointer-events: none;
  z-index: 3;
  white-space: nowrap;
}
.toast.show {
  animation: toastin 1s ease-out forwards;
}
@keyframes toastin {
  0% {
    opacity: 0;
    transform: translateX(-50%) translateY(-10px);
  }
  15% {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
  80% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

#screen-result {
  background: linear-gradient(180deg, #fff6d8 0%, #ffe3ef 100%);
  text-align: center;
}
.result-title {
  font-size: clamp(30px, 5vw, 54px);
  font-weight: 900;
  color: var(--coral-dark);
  margin: 0 0 8px;
  text-shadow: 3px 3px 0 #fff;
}
.stars {
  font-size: 44px;
  margin-bottom: 18px;
  letter-spacing: 6px;
  display: flex;
  gap: 8px;
}
.result-sub {
  font-size: 20px;
  color: var(--ink);
  margin-bottom: 26px;
  font-weight: 700;
}
.result-btns {
  display: flex;
  gap: 20px;
}
.mini-btn {
  font-size: 20px;
  font-weight: 900;
  color: #fff;
  border: none;
  border-radius: 50px;
  padding: 14px 34px;
  cursor: pointer;
  min-height: 56px;
}
.mini-btn.retry {
  background: linear-gradient(180deg, #7fd9a0, #3fb955);
  box-shadow: 0 6px 0 #2a8f3f;
}
.mini-btn.retry:active {
  transform: translateY(4px);
  box-shadow: 0 1px 0 #2a8f3f;
}
.mini-btn.home {
  background: linear-gradient(180deg, #8fc0ff, #4baaff);
  box-shadow: 0 6px 0 #2f7ecb;
}
.mini-btn.home:active {
  transform: translateY(4px);
  box-shadow: 0 1px 0 #2f7ecb;
}
button {
  font-family: inherit;
}
[hidden] {
  display: none !important;
}
.info-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #fff;
  border-radius: 40px;
  padding: 6px 16px;
  font-size: 18px;
  font-weight: bold;
  color: #444;
  box-shadow: 0 2px 0 #e8a000;
}
.info-box .val {
  font-size: 22px;
  color: #ff6f3c;
  min-width: 28px;
  text-align: center;
}
.header-center {
  align-self: center;
  text-align: center;
}
.header-center h1 {
  margin: 0 0 3px;
  font-size: 20px;
  color: var(--ink);
}
.progress {
  display: flex;
  justify-content: center;
  gap: 8px;
}
.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #ddd;
}
.dot.done {
  background: #6ecb63;
}
.dot.current {
  background: #f9a825;
  border: 2px solid #c77c00;
}
.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-self: end;
}
.quit-btn,
.sound-btn {
  border: 3px solid #ddd;
  border-radius: 50px;
  padding: 6px 14px;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  background: #fff;
  color: #888;
}
.quit-btn:hover {
  border-color: #e05a5a;
  color: #e05a5a;
}
.sound-btn {
  background: #fff0ad;
  border-color: #f2b321;
  color: #694100;
  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;
}
.sound-icon {
  width: 22px;
  height: 22px;
  vertical-align: middle;
  margin-right: 5px;
}
.start-sound-btn {
  position: absolute;
  top: 8px;
  right: 10px;
  z-index: 10;
}
.car-sprite:focus-visible {
  outline: 3px solid #ffd75e;
  border-radius: 8px;
}
.stars i {
  display: block;
  width: 40px;
  height: 40px;
  background: #ffc83d;
  clip-path: polygon(
    50% 0,
    61% 35%,
    98% 35%,
    68% 57%,
    79% 94%,
    50% 72%,
    21% 94%,
    32% 57%,
    2% 35%,
    39% 35%
  );
}
.result-score {
  margin: 0 0 12px;
  font-size: 24px;
  font-weight: bold;
  color: var(--ink);
}
@media (max-width: 600px) {
  .game-header {
    padding: 3px 5px;
    gap: 3px;
  }
  .info-box {
    font-size: 11px;
    padding: 6px;
    gap: 3px;
  }
  .info-box .val {
    min-width: 16px;
    font-size: 16px;
  }
  .header-center h1 {
    font-size: 14px;
  }
  .header-actions {
    gap: 4px;
  }
  .quit-btn,
  .sound-btn {
    font-size: 12px;
    padding: 7px 6px;
  }
  .sound-btn {
    min-width: 56px;
  }
  .sound-icon {
    width: 15px;
    height: 15px;
    margin-right: 2px;
  }
  .target-board {
    gap: 8px;
    padding: 8px;
    max-width: 100%;
  }
  .target-caption {
    font-size: 12px;
  }
  .target-car-icon {
    width: 50px;
    height: 36px;
    flex-shrink: 0;
  }
  .target-label {
    font-size: 17px;
  }
  .result-btns {
    gap: 12px;
  }
  .mini-btn {
    font-size: 16px;
    padding: 14px 18px;
  }
}

.confetti {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 3;
}
.confetti-piece {
  position: absolute;
  top: -16px;
  height: 12px;
  border-radius: 2px;
  animation: confetti-fall 700ms ease-in forwards;
}
@keyframes confetti-fall {
  0% {
    transform: translate3d(0, 0, 0) rotate(0);
    opacity: 1;
  }
  75% {
    opacity: 1;
  }
  100% {
    transform: translate3d(var(--drift), var(--fall), 0) rotate(var(--spin));
    opacity: 0;
  }
}

.car-image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}
