/* びゅんびゅん レース — 見た目。ライト=ひるま・ダーク=よる。外部フォントは使わない */
:root {
  --bg: #e6f4ff;
  --stage: #fff9ea;
  --ink: #2b2433;
  --sub: #6b6177;
  --card: #ffffff;
  --card-sh: #cdbf9d;
  --gold: #ffc53d;
  --go: #3ccf6b;
  --go-sh: #1f9d4a;
  --go-ink: #0f3320;
  --focus: #2f7cf6;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c2230;
    --stage: #262d3f;
    --ink: #f3eefc;
    --sub: #b9c0d4;
    --card: #343d54;
    --card-sh: #0d111a;
    --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); 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; }
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, 24px); font-weight: 900; white-space: nowrap; }
.logo img { width: 40px; height: 40px; flex-shrink: 0; }
@media (max-width: 440px) { .logo span { display: none; } }
.snd { flex-shrink: 0; 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; }
.snd:active { transform: translateY(3px); }

/* ---- ステージ ---- */
.stage { position: relative; min-height: 0; border: 3px solid var(--ink); border-radius: 22px; overflow: hidden; background: var(--stage); }
#cv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.say {
  position: absolute; left: 0; right: 0; top: 16%; width: fit-content; max-width: 90%; margin: 0 auto; padding: 8px 18px; border-radius: 20px;
  background: #fff; color: #2b2433; border: 3px solid #2b2433; font-size: clamp(22px, 7vw, 34px); font-weight: 900; z-index: 3; pointer-events: none;
}

/* ---- えらぶ ---- */
.pick {
  position: absolute; inset: 0; z-index: 2; background: var(--stage);
  display: grid; grid-template-columns: minmax(0, 1fr); align-content: center; justify-items: center; gap: clamp(8px, 2.4vh, 20px); padding: 10px 12px;
}
.grp { width: min(100%, 420px); }
.grp h2 { margin: 0 0 6px; text-align: center; font-size: clamp(15px, 4vw, 19px); font-weight: 900; color: var(--sub); }
.opts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.opt {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  min-height: 104px; padding: 6px 4px; border-radius: 18px; background: var(--card); box-shadow: 0 4px 0 var(--card-sh);
}
.opt[aria-pressed="true"] { box-shadow: 0 4px 0 var(--card-sh), 0 0 0 5px var(--gold); }
.opt:active { transform: translateY(3px); }
.opt .pic { width: 100%; height: 66px; }
.opt .pic.car { width: 44px; margin: 0 auto; }
.opt svg:not(.car) { border-radius: 10px; overflow: hidden; }
.nm { font-size: clamp(12px, 3.3vw, 15px); font-weight: 900; white-space: nowrap; }
.go {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  width: min(100%, 300px); height: 76px; border-radius: 24px; background: var(--go); color: var(--go-ink); box-shadow: 0 6px 0 var(--go-sh);
  font-size: 30px; font-weight: 900;
}
.go svg { width: 40px; height: 40px; flex-shrink: 0; }
.go:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--go-sh); }

/* ---- けっか ---- */
.result { position: absolute; inset: 0; z-index: 2; display: grid; place-items: center; padding: 10px; background: rgba(20, 16, 40, .18); }
.card {
  display: grid; justify-items: center; gap: 10px; width: min(100%, 360px); padding: 16px 16px 18px; border-radius: 26px;
  background: var(--card); border: 3px solid var(--ink); box-shadow: 0 6px 0 var(--card-sh);
}
.medal { width: 82px; height: 100px; }
.txt { text-align: center; }
.rank { margin: 0; font-size: 40px; font-weight: 900; line-height: 1.1; }
.rmsg { margin: 4px 0 0; font-size: clamp(16px, 4.4vw, 20px); font-weight: 900; color: var(--sub); }
.rst { display: flex; align-items: center; justify-content: center; gap: 6px; margin: 8px 0 0; font-size: 26px; font-weight: 900; }
.rst svg { width: 32px; height: 32px; }
.btns { display: grid; gap: 10px; width: 100%; }
.big { display: flex; align-items: center; justify-content: center; gap: 10px; min-height: 58px; border-radius: 18px; font-size: 22px; font-weight: 900; background: var(--go); color: var(--go-ink); box-shadow: 0 5px 0 var(--go-sh); }
.big.back { background: var(--stage); color: var(--ink); box-shadow: 0 5px 0 var(--card-sh); border: 3px solid var(--ink); }
.big svg { width: 28px; height: 28px; flex-shrink: 0; }
.big:active { transform: translateY(3px); }

/* スマホを横にしたとき(ひくい 画面): えらぶ・けっかを よこ ならびに */
@media (orientation: landscape) and (max-height: 600px) {
  .logo img { width: 32px; height: 32px; }
  .snd { width: 48px; height: 48px; }
  .snd svg { width: 28px; height: 28px; }
  .pick { grid-template-columns: minmax(0, 1fr) auto; grid-template-rows: auto auto; align-content: center; column-gap: 14px; row-gap: 8px; padding: 4px 12px; }
  .grp { width: 100%; grid-column: 1; }
  .grp h2 { margin: 0 0 3px; font-size: 13px; }
  .opts { max-width: 420px; margin: 0 auto; }
  .opt { min-height: 72px; padding: 3px; gap: 1px; }
  .opt .pic { height: 40px; }
  .opt .pic.car { width: 28px; }
  .nm { font-size: 12px; }
  .go { grid-column: 2; grid-row: 1 / 3; align-self: center; width: 150px; height: 90px; flex-direction: column; gap: 4px; font-size: 22px; }
  .go svg { width: 34px; height: 34px; }
  .card { width: min(100%, 520px); grid-template-columns: auto 1fr auto; gap: 12px; padding: 10px 14px; border-radius: 22px; }
  .medal { width: 54px; height: 66px; }
  .txt { text-align: left; }
  .rank { font-size: 30px; }
  .rmsg { font-size: 15px; margin-top: 2px; }
  .rst { justify-content: flex-start; margin-top: 4px; font-size: 20px; }
  .rst svg { width: 24px; height: 24px; }
  .btns { width: 190px; gap: 8px; }
  .big { min-height: 50px; font-size: 18px; border-radius: 14px; }
  .say { top: 22%; font-size: 24px; padding: 4px 14px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
