* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #5fb4f5;
  font-family: "Hiragino Maru Gothic ProN", "Hiragino Sans", "BIZ UDPGothic", "Meiryo", system-ui, sans-serif;
  color: #222;
  /* スマホでのスクロール・拡大・長押しメニューを防ぐ */
  touch-action: none;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

#stage, #stage canvas {
  touch-action: none;
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.hidden { display: none !important; }

#flash {
  position: fixed;
  inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
  z-index: 5;
}

/* 音ボタン */
.icon-btn {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  right: max(10px, env(safe-area-inset-right));
  z-index: 30;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 3px solid #fff;
  background: rgba(30, 30, 60, 0.55);
  font-size: 26px;
  cursor: pointer;
}

/* HUD */
#hud {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  left: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: none;
  z-index: 10;
  color: #fff;
  text-shadow: 0 3px 0 #233, 0 0 8px rgba(0, 0, 0, 0.4);
}
#timerWrap { font-size: 64px; font-weight: 900; line-height: 1; }
#timerWrap small { font-size: 22px; margin-left: 4px; }
#timerWrap.hurry { color: #ffe14d; animation: pulse 0.5s infinite; }
#powerWrap { width: min(80vw, 420px); text-align: center; font-weight: 800; }
#powerLabel { font-size: 20px; }
#powerBar {
  height: 18px;
  border-radius: 9px;
  background: rgba(0, 0, 0, 0.35);
  border: 3px solid #fff;
  overflow: hidden;
  margin: 4px 0;
}
#powerFill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #ffd23f, #ff7a3c, #ff3c8a);
  transition: width 0.1s linear;
}
#revs { font-size: 18px; }

/* 中央メッセージ */
#msg {
  position: fixed;
  top: 32%;
  left: 0;
  right: 0;
  text-align: center;
  font-size: clamp(30px, 9vw, 64px);
  font-weight: 900;
  color: #fff;
  text-shadow: 0 4px 0 #e8323c, 0 0 14px rgba(0, 0, 0, 0.35);
  pointer-events: none;
  z-index: 12;
  opacity: 0;
  white-space: pre-line;
}
#msg.show { animation: pop 0.9s ease-out forwards; }
#msg.stay { opacity: 1; animation: popin 0.25s ease-out; }

#banner {
  position: fixed;
  top: 24%;
  left: 0;
  right: 0;
  text-align: center;
  font-size: clamp(22px, 6.5vw, 40px);
  font-weight: 900;
  color: #fff;
  text-shadow: 0 3px 0 #2c3e8f, 0 0 10px rgba(0, 0, 0, 0.5);
  pointer-events: none;
  z-index: 12;
  opacity: 0;
}
#banner.show { animation: slide 1.1s ease-out forwards; }
#banner.goal { color: #fff07a; font-size: clamp(32px, 10vw, 68px); text-shadow: 0 4px 0 #2a8fa0, 0 0 20px #8fe3ea; }

#distance {
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  left: 0;
  right: 0;
  text-align: center;
  font-size: clamp(20px, 6.2vw, 40px);
  font-weight: 900;
  color: #fff;
  text-shadow: 0 3px 0 #233, 0 0 10px rgba(0, 0, 0, 0.5);
  pointer-events: none;
  z-index: 10;
}

#skipHint {
  position: fixed;
  bottom: max(20px, env(safe-area-inset-bottom));
  left: 0;
  right: 0;
  text-align: center;
  color: #fff;
  font-weight: 800;
  font-size: 18px;
  opacity: 0.8;
  pointer-events: none;
  z-index: 10;
}

/* 仮想スティック */
#stick {
  position: fixed;
  left: 50%;
  bottom: calc(max(24px, env(safe-area-inset-bottom)) + 10px);
  width: min(56vw, 240px);
  height: min(56vw, 240px);
  transform: translateX(-50%);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.15) 0 40%, rgba(255, 255, 255, 0.35) 41% 100%);
  border: 4px solid rgba(255, 255, 255, 0.9);
  z-index: 10;
  pointer-events: none;
}
#stickRing {
  position: absolute;
  inset: -14px;
  border-radius: 50%;
  border: 6px dashed rgba(255, 230, 80, 0.9);
  animation: spinring 1.2s linear infinite;
}
#stick.active #stickRing { border-color: rgba(255, 120, 60, 0.95); animation-duration: 0.4s; }
#knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 38%;
  height: 38%;
  margin: -19% 0 0 -19%;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff, #ffb84d 60%, #ff7a3c);
  border: 3px solid #fff;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}
#stickHint {
  position: absolute;
  bottom: 100%;
  left: -50%;
  right: -50%;
  margin-bottom: 18px;
  text-align: center;
  color: #fff;
  font-weight: 900;
  font-size: 22px;
  text-shadow: 0 3px 0 #e8323c;
  animation: pulse 0.8s infinite;
}

/* タイミングゲージ */
#gauge {
  position: fixed;
  left: 50%;
  bottom: calc(max(30px, env(safe-area-inset-bottom)) + 30px);
  transform: translateX(-50%);
  width: min(88vw, 520px);
  z-index: 10;
  pointer-events: none;
  text-align: center;
}
#gaugeHelp {
  color: #fff;
  font-weight: 900;
  font-size: 26px;
  margin-bottom: 10px;
  text-shadow: 0 3px 0 #e8323c;
}
#gaugeBar {
  position: relative;
  height: 54px;
  border-radius: 27px;
  background: #3a3a5a;
  border: 4px solid #fff;
  overflow: hidden;
}
#gaugeBar .zone { position: absolute; top: 0; bottom: 0; }
#gaugeBar .good { left: 27.5%; right: 27.5%; background: #4bbf73; }
#gaugeBar .great { left: 40%; right: 40%; background: #ffc83d; }
#gaugeBar .perfect { left: 46%; right: 46%; background: #ff3c8a; }
#gaugeBar .perfect::after {
  content: "★";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 24px;
}
#gaugeMarker {
  position: absolute;
  top: -4px;
  bottom: -4px;
  width: 10px;
  margin-left: -5px;
  left: 0;
  background: #fff;
  border: 2px solid #222;
  border-radius: 5px;
}
#gauge.holding #gaugeBar { box-shadow: 0 0 0 6px rgba(255, 220, 80, 0.7); }

/* パネル（タイトル・結果） */
.panel {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(92vw, 480px);
  max-height: 92vh;
  overflow-y: auto;
  padding: 22px 20px;
  border-radius: 28px;
  background: rgba(255, 255, 255, 0.94);
  border: 5px solid #fff;
  box-shadow: 0 10px 0 rgba(0, 0, 0, 0.15), 0 20px 40px rgba(0, 0, 0, 0.25);
  text-align: center;
  z-index: 20;
  animation: popin 0.3s ease-out;
}
h1 {
  margin: 0 0 8px;
  font-size: clamp(30px, 9vw, 44px);
  line-height: 1.1;
  color: #ff7a3c;
  text-shadow: 0 3px 0 #2c3e8f;
  letter-spacing: 0.02em;
}
h1 span { display: block; font-size: 0.6em; color: #3d6ee8; text-shadow: none; }
.lead { font-size: 18px; font-weight: 800; margin: 6px 0 10px; }
.lead b { color: #1aa3b0; }
.howto { text-align: left; font-size: 15px; line-height: 1.5; padding-left: 1.4em; margin: 8px 0; }
.pc-only { font-size: 13px; color: #555; margin: 4px 0 8px; }
@media (pointer: coarse) { .pc-only { display: none; } }
.big-btn {
  display: block;
  width: 100%;
  min-height: 72px;
  margin: 10px 0 6px;
  border: none;
  border-radius: 36px;
  background: linear-gradient(#ff9a3c, #ff5a3c);
  color: #fff;
  font-size: 28px;
  font-weight: 900;
  font-family: inherit;
  box-shadow: 0 6px 0 #b8381f;
  cursor: pointer;
}
.big-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 #b8381f; }
.sub-btn {
  min-height: 48px;
  padding: 0 24px;
  border-radius: 24px;
  border: 3px solid #3d6ee8;
  background: #fff;
  color: #3d6ee8;
  font-size: 17px;
  font-weight: 800;
  font-family: inherit;
  cursor: pointer;
}
.best { font-weight: 800; color: #3d6ee8; margin: 6px 0; font-size: 15px; }
.note { font-size: 12px; color: #666; margin: 8px 0 0; line-height: 1.5; }
.note a { color: #666; }

.res-label { margin: 0; font-weight: 800; color: #666; }
#resDist { margin: 0; font-size: clamp(26px, 8vw, 44px); word-break: break-all; font-weight: 900; color: #ff5a3c; line-height: 1.15; }
#resNew { margin: 4px 0; font-weight: 900; color: #e8323c; font-size: 20px; animation: pulse 0.7s infinite; }
#resTitle { margin: 6px 0; font-size: 22px; font-weight: 900; color: #2c3e8f; }
#resGoal { margin: 4px 0 8px; font-weight: 800; color: #1aa3b0; }
#resStats {
  display: grid;
  grid-template-columns: auto auto;
  gap: 4px 14px;
  justify-content: center;
  margin: 8px 0;
  font-size: 15px;
}
#resStats dt { color: #666; text-align: right; }
#resStats dd { margin: 0; font-weight: 800; text-align: left; }

@keyframes pop {
  0% { opacity: 0; transform: scale(0.4); }
  15% { opacity: 1; transform: scale(1.15); }
  25% { transform: scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: scale(1.05) translateY(-10px); }
}
@keyframes popin { from { transform: translate(-50%, -50%) scale(0.85); opacity: 0; } }
#msg.stay { animation-name: msgin; }
@keyframes msgin { from { transform: scale(0.6); opacity: 0; } }
@keyframes slide {
  0% { opacity: 0; transform: translateX(40px); }
  15% { opacity: 1; transform: translateX(0); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-16px); }
}
@keyframes pulse { 50% { transform: scale(1.08); } }
@keyframes spinring { to { transform: rotate(360deg); } }

/* ===== ドーパミン系の演出（軽さ優先：transform と opacity だけを動かす） ===== */

/* 集中線：円錐グラデーション1枚。動きはカクカク（steps）にしてマンガっぽく、描き直しを減らす */
#speedLines {
  position: fixed;
  inset: -40%;
  pointer-events: none;
  z-index: 4;
  opacity: 0;
  background: repeating-conic-gradient(from 0deg, rgba(255, 255, 255, 0) 0deg 5deg, rgba(255, 255, 255, 0.7) 5deg 5.6deg, rgba(255, 255, 255, 0) 5.6deg 9deg);
  -webkit-mask-image: radial-gradient(circle, transparent 22%, #000 48%);
  mask-image: radial-gradient(circle, transparent 22%, #000 48%);
  will-change: transform, opacity;
  animation: lines 0.5s steps(4) infinite;
}
@keyframes lines {
  0% { transform: rotate(0deg) scale(1); }
  100% { transform: rotate(8deg) scale(1.04); }
}

/* FEVER：画面のふちが光って脈打つ */
#fever {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 4;
  opacity: 0;
  background: radial-gradient(ellipse at center, transparent 55%, rgba(255, 60, 138, 0.55) 80%, rgba(255, 210, 63, 0.75) 100%);
  will-change: opacity;
}
#fever.on { animation: feverpulse 0.42s ease-in-out infinite alternate; }
@keyframes feverpulse { from { opacity: 0.35; } to { opacity: 0.95; } }
@media (prefers-reduced-motion: reduce) {
  #fever.on { animation: none; opacity: 0.4; }
}

/* 飛び出す文字 */
#fx { position: fixed; inset: 0; pointer-events: none; z-index: 14; overflow: hidden; }
.pop {
  position: absolute;
  left: 0;
  top: 0;
  opacity: 0;
  font-weight: 900;
  font-size: 30px;
  color: #fff;
  white-space: nowrap;
  text-shadow: 0 3px 0 #ff5a3c, 0 0 10px rgba(0, 0, 0, 0.35);
  will-change: transform, opacity;
}
.pop.t1 { color: #fff7a8; }
.pop.t2 { color: #ffd23f; font-size: 36px; }
.pop.t3 { color: #ff8ad8; font-size: 42px; text-shadow: 0 3px 0 #7a1fd6, 0 0 14px #ff3c8a; }
.pop.lv { font-size: 26px; color: #fff07a; text-shadow: 0 3px 0 #2c3e8f, 0 0 12px #ffd23f; }
.pop.combo { font-size: 34px; color: #8fe3ea; text-shadow: 0 3px 0 #2c3e8f, 0 0 12px #3d6ee8; }
.pop.boom { font-size: 72px; color: #fff07a; text-shadow: 0 5px 0 #e8323c, 0 0 24px #ff7a3c; }

/* ハンコ文字 */
#stamp {
  position: fixed;
  left: 50%;
  top: 42%;
  z-index: 15;
  pointer-events: none;
  opacity: 0;
  font-weight: 900;
  font-size: clamp(44px, 14vw, 96px);
  white-space: nowrap;
  color: #fff;
  -webkit-text-stroke: 3px #2c3e8f;
  text-shadow: 0 6px 0 #2c3e8f, 0 0 26px rgba(255, 255, 255, 0.6);
  will-change: transform, opacity;
}
#stamp.fever { color: #ffd23f; -webkit-text-stroke-color: #e8323c; text-shadow: 0 6px 0 #e8323c, 0 0 30px #ff3c8a; }
#stamp.perfect { color: #fff07a; -webkit-text-stroke-color: #ff3c8a; text-shadow: 0 6px 0 #b8177a, 0 0 34px #ffd23f; }
#stamp.great { color: #ffc83d; }
#stamp.count { font-size: clamp(90px, 30vw, 180px); top: 46%; color: #fff07a; -webkit-text-stroke-color: #e8323c; text-shadow: 0 8px 0 #e8323c; }
#stamp.goal { color: #8fe3ea; -webkit-text-stroke-color: #1a5f8f; text-shadow: 0 6px 0 #1a5f8f, 0 0 34px #8fe3ea; font-size: clamp(36px, 11vw, 80px); }

/* パワーゲージの段階（レベルが上がるほど光る） */
#powerBar.lv2 { box-shadow: 0 0 8px #ffd23f; }
#powerBar.lv3 { box-shadow: 0 0 12px #ff7a3c; }
#powerBar.lv4 { box-shadow: 0 0 16px #ff3c8a; }
#powerBar.lv5 { box-shadow: 0 0 22px #ff3c8a, 0 0 6px #fff; border-color: #fff07a; }
#powerLabel { display: inline-block; }
#powerWrap { position: relative; }

/* ゲージ：★に近づくと光る */
#gaugeBar.hot { box-shadow: 0 0 0 5px #fff07a, 0 0 22px #ff3c8a; }

/* 結果：ランクのハンコ・天王星までの進み具合・もう一回ボタン */
.res-row { display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap; }
#resRank {
  flex: none;
  width: 64px;
  height: 64px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 5px solid #e8323c;
  color: #e8323c;
  font-size: 30px;
  font-weight: 900;
  transform: rotate(-12deg);
  opacity: 0;
}
#resRank.rank-SS, #resRank.rank-S { border-color: #ff3c8a; color: #ff3c8a; box-shadow: 0 0 18px #ffd23f; }
#resRank.rank-A { border-color: #ff7a3c; color: #ff7a3c; }
#resRank.rank-B { border-color: #3d6ee8; color: #3d6ee8; }
#resRank.rank-C, #resRank.rank-D { border-color: #888; color: #888; }
#goalProg {
  position: relative;
  height: 22px;
  margin: 2px 8px 8px;
  border-radius: 11px;
  background: #e3e8f5;
  overflow: hidden;
}
#goalFill {
  position: absolute;
  inset: 0;
  transform-origin: left center;
  transform: scaleX(0);
  background: linear-gradient(90deg, #3d6ee8, #8fe3ea);
  transition: transform 1.2s cubic-bezier(0.2, 0.8, 0.2, 1);
}
#goalProg.clear #goalFill { background: linear-gradient(90deg, #ff3c8a, #ffd23f, #4bbf73, #3d6ee8); }
#goalPct { position: relative; font-size: 13px; font-weight: 900; color: #2c3e8f; line-height: 22px; }
#resToBest { margin: 0 0 4px; font-size: 14px; font-weight: 800; color: #e8323c; }
#resNew {
  background: linear-gradient(90deg, #ff3c8a, #ffd23f, #4bbf73, #3d6ee8, #ff3c8a);
  background-size: 200% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent !important;
  font-size: 24px !important;
  animation: rainbow 1s linear infinite, pulse 0.7s infinite !important;
}
@keyframes rainbow { to { background-position: 200% 0; } }
#retryBtn.ready { animation: retry 0.9s ease-in-out infinite; }
@keyframes retry {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); box-shadow: 0 6px 0 #b8381f, 0 0 24px #ffb84d; }
}

#resKm { margin: 0 0 4px; font-size: 14px; font-weight: 800; color: #6b5a8a; }
#stamp.tier { color: #fff; -webkit-text-stroke-color: #6a1bd8; text-shadow: 0 6px 0 #6a1bd8, 0 0 34px #3dd6ff; font-size: clamp(44px, 14vw, 100px); }
#stamp.tier3 { color: #ffe14a; -webkit-text-stroke-color: #e8323c; text-shadow: 0 6px 0 #e8323c, 0 0 40px #ff9a3c; }
#stamp.tier4 { color: #bff6ff; -webkit-text-stroke-color: #0a3fd8; text-shadow: 0 6px 0 #0a3fd8, 0 0 50px #3dd6ff, 0 0 90px #fff; }
#stamp.tier5 { color: #fff; -webkit-text-stroke-color: #ff2fa0; text-shadow: 0 6px 0 #6a1bd8, 0 0 60px #ff2fa0, 0 0 100px #3dd6ff; font-size: clamp(34px, 11vw, 78px); }
