:root {
  --sky: #bae6fd;
  --sky-light: #e0f2fe;
  --grass: #86efac;
  --ink: #1f2937;
  --accent: #f97316;
  --vh: 1vh;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--sky-light);
  color: var(--ink);
  font-family: 'Hiragino Maru Gothic ProN', 'Rounded Mplus 1c', 'BIZ UDPGothic', system-ui, sans-serif;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  padding: 0;
  cursor: pointer;
  touch-action: manipulation;
}

svg { display: block; overflow: visible; }
.vehicle { width: 100%; height: auto; }
.beacon { animation: blink 0.5s steps(1) infinite; }

.screen {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: calc(var(--vh) * 100);
  display: none;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.screen.active { display: flex; }

/* 🏠 / ◀ は ../common/back-button.js が ひだりうえに だすので、62px あけておく */
.topbar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  height: calc(env(safe-area-inset-top, 0px) + 66px);
  padding: calc(env(safe-area-inset-top, 0px) + 8px) 12px 6px;
}
.icon-spacer { flex: none; width: 54px; }
.bubble-wrap { flex: none; padding: 0 16px 14px; }
.short .bubble-wrap .sg-bubble { --sgb-h: 64px; padding-top: 6px; padding-bottom: 6px; }
.short .topbar { height: calc(env(safe-area-inset-top, 0px) + 60px); }

/* ---------------- スタート ---------------- */
#screen-start {
  align-items: center;
  justify-content: center;
  gap: clamp(18px, calc(var(--vh) * 4), 36px);
  padding: 24px 0;
  background: linear-gradient(var(--sky), var(--sky-light) 60%, var(--grass) 60%);
}
.title {
  margin: 0;
  font-size: clamp(30px, 9.5vw, 48px);
  line-height: 1.2;
  text-align: center;
  color: #fff;
  -webkit-text-stroke: 2px var(--accent);
  paint-order: stroke fill;
  text-shadow: 0 4px 0 rgba(0, 0, 0, 0.12);
}
.title span {
  display: inline-block;
  font-size: 1.5em;
  color: #fde047;
  -webkit-text-stroke: 3px #ef4444;
  animation: pulse 1.6s ease-in-out infinite;
}
.parade {
  width: 100%;
  height: 92px;
  overflow: hidden;
  background: #6b7280;
  border-top: 6px solid #e5e7eb;
  border-bottom: 6px solid #e5e7eb;
  position: relative;
}
.parade::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 4px;
  margin-top: -2px;
  background: repeating-linear-gradient(90deg, #fff 0 24px, transparent 24px 52px);
  z-index: 0;
}
.parade-cars {
  position: relative;
  z-index: 1;
  display: flex;
  gap: 18px;
  width: max-content;
  padding-top: 8px;
  animation: parade 16s linear infinite;
}
.parade-cars span { width: 112px; }
.play-btn {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 54px;
  padding-left: 10px;
  box-shadow: 0 8px 0 #c2410c, 0 14px 24px rgba(0, 0, 0, 0.18);
  animation: pulse 1.4s ease-in-out infinite;
}
.play-btn:active { transform: translateY(6px); box-shadow: 0 2px 0 #c2410c; animation: none; }
.credit { margin: 0; font-size: 11px; color: #166534; opacity: 0.7; }

/* ---------------- くるま えらび ---------------- */
#screen-pick, #screen-paint, #screen-result { background: var(--sky-light); }
.car-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(4, minmax(0, 1fr));
  gap: 10px;
  padding: 0 16px 16px;
}
.car-card {
  display: grid;
  place-items: center;
  min-height: 0;
  padding: 6px;
  border-radius: 20px;
  background: #fff;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.1);
  transition: transform 0.12s;
}
.car-card svg { width: 92%; max-height: 100%; }
.car-card:active { transform: translateY(3px) scale(0.97); box-shadow: none; }
.car-card.picked { box-shadow: 0 0 0 4px var(--accent), 0 4px 0 rgba(0, 0, 0, 0.1); }

/* ---------------- いろ えらび ---------------- */
.showroom {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0 16px;
}
.preview { width: min(78vw, 340px, calc(var(--vh) * 40)); }
.preview.hop { animation: bump 0.45s ease-out; }
.platform {
  width: min(88vw, 380px);
  height: 18px;
  margin-top: -6px;
  border-radius: 50%;
  background: rgba(30, 41, 59, 0.15);
}
.swatches {
  flex: none;
  display: grid;
  grid-template-columns: repeat(4, 60px);
  justify-content: center;
  gap: 12px 18px;
  padding: 8px 16px 14px;
}
.swatch {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--c);
  box-shadow: inset 0 -6px 0 var(--d), 0 3px 0 rgba(0, 0, 0, 0.12);
  transition: transform 0.12s;
}
.swatch:active { transform: scale(0.92); }
.swatch.picked { box-shadow: inset 0 -6px 0 var(--d), 0 0 0 4px #fff, 0 0 0 8px var(--ink); }
.short .swatches { grid-template-columns: repeat(4, 50px); gap: 10px 18px; padding-bottom: 10px; }
.short .swatch { width: 50px; height: 50px; }

.paint-actions, .result-actions {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 6px 16px 18px;
}
.sub-btn {
  flex: none;
  width: 76px;
  height: 76px;
  border-radius: 50%;
  background: #fff;
  font-size: 26px;
  box-shadow: 0 5px 0 rgba(0, 0, 0, 0.12);
}
.go-btn {
  flex: 1;
  max-width: 260px;
  height: 84px;
  border-radius: 42px;
  background: #22c55e;
  color: #fff;
  font-size: 34px;
  font-weight: 900;
  letter-spacing: 0.04em;
  box-shadow: 0 7px 0 #15803d, 0 12px 20px rgba(0, 0, 0, 0.15);
  animation: pulse 1.4s ease-in-out infinite;
}
.sub-btn:active, .go-btn:active { transform: translateY(5px); box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2); animation: none; }
.short .go-btn { height: 70px; }
.short .sub-btn { width: 66px; height: 66px; }

/* ---------------- レース ---------------- */
/* れんだで ダブルタップズームに ならないように、レースがめんでは ブラウザの タッチどうさを ぜんぶ とめる */
#screen-race { background: var(--sky); touch-action: none; }
.progress {
  position: relative;
  flex: 1;
  height: 42px;
  border-radius: 21px;
  background: rgba(255, 255, 255, 0.85);
  box-shadow: inset 0 2px 0 rgba(0, 0, 0, 0.06);
}
.progress-flag { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); font-size: 24px; }
.pg-car {
  position: absolute;
  top: 50%;
  margin-left: 6px;
  width: 34px;
  transform: translateY(-50%);
  opacity: 0.8;
}
.pg-sig { position: absolute; top: 50%; transform: translateY(-50%); font-size: 16px; opacity: 0.7; }
.pg-car.me { z-index: 2; width: 42px; opacity: 1; filter: drop-shadow(0 0 3px #facc15); }

.track {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background: linear-gradient(var(--sky), var(--sky-light) var(--sky-h, 30%), var(--grass) var(--sky-h, 30%));
}
.decor { position: absolute; left: 0; right: 0; top: 0; height: var(--sky-h); pointer-events: none; }
.decor span { position: absolute; left: 0; line-height: 1; will-change: transform; }
.decor .cloud { top: 6%; font-size: 30px; opacity: 0.9; }
.decor .house { bottom: 6px; font-size: min(38px, calc(var(--sky-h) * 0.42)); }
.decor .tree { bottom: -4px; font-size: min(44px, calc(var(--sky-h) * 0.5)); z-index: 2; }
.road {
  position: absolute;
  left: 0;
  right: 0;
  top: var(--sky-h);
  height: calc(var(--road-h) + 12px);
  background: #6b7280;
  border-top: 6px solid #e5e7eb;
  border-bottom: 6px solid #e5e7eb;
  overflow: hidden;
}
.lane-line {
  position: absolute;
  left: 0;
  right: 0;
  height: 4px;
  margin-top: -2px;
  background: repeating-linear-gradient(90deg, #f8fafc 0 30px, transparent 30px 64px);
  background-position-x: var(--cam, 0);
}
.start-line, .finish-line { position: absolute; left: 0; top: 0; bottom: 0; }
.start-line { width: 8px; background: #fff; }
.finish-line {
  width: 24px;
  background: conic-gradient(#111827 25%, #fff 0 50%, #111827 0 75%, #fff 0) 0 0 / 12px 12px;
}
.stop-line { position: absolute; left: 0; top: 0; bottom: 0; width: 10px; background: #fff; }
/* にほんの よこがたの しんごう（ひだりから あお・きいろ・あか） */
.signal {
  position: absolute;
  left: 4px;
  top: calc(var(--sky-h) - min(92px, var(--sky-h) - 22px));
  z-index: 4;
  width: 8px;
  height: min(92px, calc(var(--sky-h) - 22px));
  background: #9ca3af;
  border: 2px solid var(--ink);
  border-bottom: 0;
  pointer-events: none;
}
.signal-head {
  position: absolute;
  left: -30px;
  top: -8px;
  display: flex;
  gap: 4px;
  padding: 5px 6px;
  border: 2.5px solid var(--ink);
  border-radius: 10px;
  background: #374151;
}
.signal-head i { width: 18px; height: 18px; border-radius: 50%; background: #4b5563; }
.signal[data-state="green"] .g { background: #22c55e; box-shadow: 0 0 10px #22c55e; }
.signal[data-state="yellow"] .y { background: #facc15; box-shadow: 0 0 12px #facc15; }
.signal[data-state="red"] .r { background: #ef4444; box-shadow: 0 0 14px #ef4444; }
.signal[data-state="red"] .signal-head, .signal[data-state="yellow"] .signal-head { animation: sigpop 0.35s ease-out; }
.racer.shake svg { animation: shake 0.3s ease-in-out; }
.gate {
  position: absolute;
  left: -4px;
  top: calc(var(--sky-h) - 50px);
  font-size: 46px;
  line-height: 1;
  z-index: 3;
}
.racer { position: absolute; left: 0; will-change: transform; }
.racer.me::before {
  content: '▼';
  position: absolute;
  left: 50%;
  top: -18px;
  transform: translateX(-50%);
  color: #facc15;
  font-size: 18px;
  -webkit-text-stroke: 1.5px var(--ink);
  animation: hop 0.8s ease-in-out infinite;
}
.puff {
  position: absolute;
  z-index: 30;
  font-size: 22px;
  pointer-events: none;
  animation: puff 0.6s ease-out forwards;
}
.lights {
  position: absolute;
  z-index: 40;
  left: 50%;
  top: calc(var(--sky-h) * 0.15);
  transform: translateX(-50%);
  display: flex;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 20px;
  background: #1f2937;
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.2);
}
.lights i { width: 40px; height: 40px; border-radius: 50%; background: #4b5563; }
.lights i.red { background: #ef4444; box-shadow: 0 0 16px #ef4444; }
.lights i.yellow { background: #facc15; box-shadow: 0 0 16px #facc15; }
.lights i.green { background: #22c55e; box-shadow: 0 0 20px #22c55e; }

.tap-pad {
  flex: none;
  display: grid;
  place-items: center;
  height: clamp(110px, calc(var(--vh) * 24), 190px);
  padding: 12px 16px 16px;
  background: var(--grass);
}
.tap-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  width: min(100%, 340px);
  height: 100%;
  border-radius: 28px;
  background: var(--accent);
  color: #fff;
  box-shadow: 0 7px 0 #c2410c;
}
.tap-btn b { font-size: clamp(34px, 11vw, 52px); font-weight: 900; letter-spacing: 0.04em; }
.tap-car { width: 30%; max-width: 110px; }
.tap-btn.press { animation: press 0.15s ease-out; }
.tap-btn { transition: background 0.2s; }
.tap-btn[data-sig="yellow"] { background: #eab308; box-shadow: 0 7px 0 #a16207; }
.tap-btn[data-sig="red"] { background: #dc2626; box-shadow: 0 7px 0 #991b1b; }
.tap-btn[data-sig="red"] .tap-car { display: none; }
.tap-btn[data-sig="red"].press { animation: shake 0.3s ease-in-out; }

/* ---------------- けっか ---------------- */
.ranking {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 10px;
  padding: 0 16px;
}
.rank-row {
  flex: 0 1 92px;
  min-height: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 16px;
  border-radius: 22px;
  background: #fff;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.08);
  animation: slidein 0.4s ease-out backwards;
}
.rank-row.me { background: #fef9c3; box-shadow: 0 0 0 4px #facc15, 0 4px 0 rgba(0, 0, 0, 0.08); }
.medal { flex: none; font-size: clamp(30px, calc(var(--vh) * 6), 42px); }
.rank-car { flex: 1; max-width: 150px; max-height: 100%; }
.rank-car svg { max-height: calc(var(--vh) * 9); width: auto; max-width: 100%; }
.rank-star { flex: none; margin-left: auto; font-size: 34px; }

#confetti {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 50;
  pointer-events: none;
}

/* ---------------- アニメーション ---------------- */
@keyframes blink   { 50% { fill: #fef2f2; } }
@keyframes parade  { from { transform: translateX(-100%); } to { transform: translateX(100vw); } }
@keyframes pulse   { 50% { transform: scale(1.06); } }
@keyframes hop     { 50% { transform: translate(-50%, -5px); } }
@keyframes bump    { 40% { transform: translateY(-14px) scale(1.04); } }
@keyframes press   { 50% { transform: translateY(5px) scale(0.97); box-shadow: 0 2px 0 #c2410c; } }
@keyframes puff    { to { transform: translate(-36px, -10px) scale(1.5); opacity: 0; } }
@keyframes sigpop  { 50% { transform: scale(1.25); } }
@keyframes shake   { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
@keyframes slidein { from { transform: translateX(40px); opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  .title span, .play-btn, .go-btn, .racer.me::before, .beacon { animation: none; }
  .parade-cars { animation-duration: 40s; }
}
