/* ぶーぶー くるま こうば — 見た目。ライト=あおぞら・ダーク=ゆうがた。外部フォントは使わない */
:root {
  --bg: #dff3ff;
  --sky: #bfe6ff;
  --sky-2: #e8f7ff;
  --ink: #2b2433;
  --sub: #5e6a7e;
  --card: #ffffff;
  --card-sh: #a9cbe4;
  --gold: #ffc53d;
  --focus: #2f7cf6;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #18202c;
    --sky: #6c5b9a;
    --sky-2: #f0a37c;
    --ink: #f3eefc;
    --sub: #b4abc4;
    --card: #28324a;
    --card-sh: #0e131c;
    --focus: #ffc53d;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--ink); }
body {
  font-family: "Hiragino Maru Gothic ProN", "Hiragino Maru Gothic Pro", "BIZ UDPGothic", "Yu Gothic UI", Meiryo, system-ui, sans-serif;
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  touch-action: manipulation;
  overscroll-behavior: none;
  overflow: hidden;
}
#app {
  position: fixed; inset: 0;
  display: grid; grid-template-rows: auto minmax(0, 1fr) auto; grid-template-columns: minmax(0, 1fr);
  gap: 8px;
  /* 画面の下 15% には押すものを置かない(手首が当たる) */
  padding: calc(env(safe-area-inset-top) + 8px) calc(env(safe-area-inset-right) + 10px) 15vh calc(env(safe-area-inset-left) + 10px);
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; border: 0; background: none; padding: 0; margin: 0; cursor: pointer; touch-action: manipulation; }
button:focus-visible { outline: 4px solid var(--focus); outline-offset: 3px; }
button:disabled { opacity: .5; }
svg { display: block; width: 100%; height: 100%; overflow: visible; }

.top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.logo { display: flex; align-items: center; gap: 8px; margin: 0; min-width: 0; font-size: clamp(17px, 4.6vw, 26px); font-weight: 900; white-space: nowrap; }
.logo img { width: 40px; height: 40px; flex-shrink: 0; }
@media (max-width: 360px) { .logo span { display: none; } }
.btns { display: flex; gap: 8px; flex-shrink: 0; }
.snd { width: 52px; height: 56px; border-radius: 16px; background: var(--card); box-shadow: 0 4px 0 var(--card-sh); display: grid; place-items: center; }
.snd svg { width: 32px; height: 32px; }
.spk { fill: var(--ink); }
.wave, .slash { fill: none; stroke: var(--ink); stroke-width: 3.5; stroke-linecap: round; }
.snd.off .wave, .snd:not(.off) .slash { display: none; }
.go {
  display: inline-flex; align-items: center; gap: 4px; height: 56px; padding: 0 14px 0 8px; border-radius: 16px;
  background: #ff8a3d; color: #fff; font-weight: 900; font-size: 18px; box-shadow: 0 4px 0 #c45a17; white-space: nowrap;
}
.go svg { width: 30px; height: 30px; }
.snd:active, .go:active { transform: translateY(3px); }

/* ---- ステージ ---- */
.stage { position: relative; min-height: 0; border: 3px solid var(--ink); border-radius: 22px; overflow: hidden; background: linear-gradient(var(--sky), var(--sky-2)); }
.garage { position: absolute; inset: 0; display: flex; align-items: flex-end; justify-content: center; cursor: pointer; }
.stand { position: absolute; left: 12%; right: 12%; bottom: 10%; height: 10%; border-radius: 50%; background: #ced4da; border: 3px solid #2b2433; }
.preview { position: relative; height: 78%; aspect-ratio: 148 / 142; max-width: 92%; margin-bottom: 9%; }
.course { position: absolute; inset: 0; overflow: hidden; }
.world { position: absolute; left: 0; top: 0; will-change: transform; }
.car { position: absolute; left: 0; top: 0; transform-origin: 50% 97%; will-change: transform; pointer-events: none; }
.car .flame { opacity: 0; }
.car.boost .flame { opacity: 1; animation: flick .1s steps(2) infinite; }
@keyframes flick { 50% { transform: scaleX(1.3); } }
.car.air .wingg { animation: flap .25s ease-in-out infinite; }
@keyframes flap { 50% { transform: rotate(-18deg); } }
.car.wet::after { content: ""; position: absolute; left: 0; right: 0; bottom: 2%; height: 8%; border-radius: 50%; border: 3px solid #fff; opacity: .8; animation: ripple 1s ease-out infinite; }
@keyframes ripple { from { transform: scale(.7); } to { transform: scale(1.2); opacity: 0; } }
.fx { position: absolute; left: 0; top: 0; width: 0; height: 0; pointer-events: none; }
.fx i { position: absolute; width: 12px; height: 12px; border-radius: 50%; background: #a5d8ff; border: 2px solid #fff; animation: drop .7s ease-out forwards; }
@keyframes drop { 50% { transform: translate(var(--dx), var(--dy)); } to { transform: translate(calc(var(--dx) * 1.5), 10px); opacity: 0; } }
.waves { animation: wave 1.6s ease-in-out infinite; }
@keyframes wave { 50% { transform: translateX(8px); } }

.after { position: absolute; left: 0; right: 0; top: 10%; display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; padding: 0 10px; z-index: 3; }
.res { flex-basis: 100%; margin: 0; display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 3px 4px; padding: 8px 12px; border-radius: 18px; background: #fff; color: #2b2433; border: 3px solid #2b2433; font-weight: 900; }
.res i { width: 22px; height: 22px; background: #dee2e6; clip-path: polygon(50% 0, 62% 35%, 98% 37%, 69% 59%, 79% 95%, 50% 74%, 21% 95%, 31% 59%, 2% 37%, 38% 35%); }
.res i.on { background: #ffc53d; }
.res b { margin-left: 6px; font-size: 22px; }
.res em { font-style: normal; color: #e8590c; margin-left: 6px; animation: pulse .6s ease-in-out 3; }
.res small { margin-left: 6px; font-size: 13px; color: #6b6177; }
@keyframes pulse { 50% { transform: scale(1.2); } }
.hud { position: absolute; left: 10px; top: 10px; z-index: 2; display: flex; align-items: center; gap: 4px; padding: 4px 12px 4px 6px; border-radius: 16px; background: rgba(255, 255, 255, .9); color: #2b2433; border: 2.5px solid #2b2433; font-size: 22px; font-weight: 900; pointer-events: none; }
.hud svg { width: 28px; height: 28px; }
.star { transform-box: fill-box; transform-origin: center; animation: twinkle 1.4s ease-in-out infinite; }
.star.got { animation: none; }
@keyframes twinkle { 50% { transform: scale(1.12) rotate(8deg); } }
.big { min-height: 60px; padding: 0 20px; border-radius: 18px; font-size: clamp(18px, 5vw, 24px); font-weight: 900; box-shadow: 0 5px 0 var(--card-sh); }
.again { background: var(--gold); color: #3a2a00; box-shadow: 0 5px 0 #c98a00; }
.build { background: var(--card); }
.big:active { transform: translateY(3px); }

/* ---- えらぶ ---- */
.tray { display: flex; flex-direction: column; gap: 6px; align-items: center; transition: opacity .2s; }
.row { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 6px; width: min(100%, 620px); }
.pick {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0;
  min-height: 60px; padding: 3px 2px; border-radius: 14px; background: var(--card); box-shadow: 0 4px 0 var(--card-sh);
}
.pick.on { box-shadow: 0 4px 0 var(--card-sh), 0 0 0 4px var(--gold); }
.pick:active { transform: translateY(3px); }
.pp { width: 46px; height: 32px; }
.pl { font-size: clamp(11px, 3.1vw, 15px); font-weight: 900; white-space: nowrap; }

.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 5; }
.confetti i {
  position: absolute; top: -20px; width: 10px; height: 14px; border-radius: 3px;
  animation-name: fall; animation-timing-function: cubic-bezier(.3, .6, .6, 1); animation-fill-mode: forwards;
}
@keyframes fall { to { transform: translate(var(--dx), 110vh) rotate(var(--r)); } }

/* スマホを横にしたとき: えらぶ ところを みぎに */
@media (orientation: landscape) and (max-height: 600px) {
  .after { top: 3%; gap: 6px; }
  .res { padding: 3px 10px; }
  .res i { width: 16px; height: 16px; }
  .res b { font-size: 18px; }
  .big { min-height: 50px; }
  #app { grid-template-columns: minmax(0, 1fr) auto; grid-template-rows: auto minmax(0, 1fr); column-gap: 10px; }
  .top { grid-column: 1 / -1; }
  .logo img { width: 32px; height: 32px; }
  .snd, .go { height: 48px; }
  .tray { grid-column: 2; grid-row: 2; justify-content: center; }
  .row { width: auto; grid-auto-columns: 54px; gap: 4px; }
  .pick { min-height: 0; height: min(calc((100svh - 15vh - 92px) / 3), 64px); padding: 2px 1px; }
  .pp { width: 40px; height: 26px; }
  .pl { font-size: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
.gflag { transform-box: fill-box; transform-origin: 0 50%; }
.box { transform-box: fill-box; transform-origin: center; }
