/* ============ NEON RAIL ============ */
:root {
  --cyan: #4df3ff;
  --magenta: #ff4dd8;
  --orange: #ffa14d;
  --green: #6dffa8;
  --bg: #04050c;
  --panel: rgba(10, 14, 30, 0.88);
  --font-ui: 'Rajdhani', 'Hiragino Sans', 'Yu Gothic', sans-serif;
  --font-logo: 'Orbitron', 'Rajdhani', sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: var(--bg);
  font-family: var(--font-ui);
  color: #cfe9ff;
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

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

.hidden { display: none !important; }

/* ---------- screens (共通) ---------- */
.screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  z-index: 30;
  background: radial-gradient(ellipse at center, rgba(4,5,12,0.55) 0%, rgba(4,5,12,0.88) 100%);
  text-align: center;
  padding: 16px;
}

.btn {
  font-family: var(--font-ui);
  font-size: 18px; font-weight: 700; letter-spacing: 2px;
  color: var(--cyan);
  background: rgba(77, 243, 255, 0.08);
  border: 1px solid rgba(77, 243, 255, 0.55);
  border-radius: 8px;
  padding: 12px 34px;
  cursor: pointer;
  transition: all 0.15s ease;
  margin-top: 10px;
}
.btn:hover, .btn:active {
  background: rgba(77, 243, 255, 0.22);
  box-shadow: 0 0 18px rgba(77, 243, 255, 0.45);
  transform: translateY(-1px);
}
.btn-primary { font-size: 22px; padding: 14px 48px; }
#padDebug {
  position: fixed; top: 12px; right: 12px; z-index: 9999;
  background: rgba(5, 10, 25, 0.92); border: 1px solid var(--cyan);
  color: #bfefff; font: 12px/1.5 monospace; padding: 10px 12px;
  border-radius: 8px; display: none; pointer-events: none;
}
#padDebug .pd-title { font-weight: 700; letter-spacing: 1px; margin-bottom: 6px; }
#padDebug .pd-grid { display: grid; grid-template-columns: repeat(4, 28px); gap: 4px; margin-bottom: 6px; }
#padDebug .pd-btn {
  width: 28px; height: 28px; display: flex; align-items: center; justify-content: center;
  background: #10203a; border: 1px solid #2a4a6a; border-radius: 4px;
}
#padDebug .pd-btn.on { background: var(--cyan); color: #041018; font-weight: 700; box-shadow: 0 0 8px rgba(77, 243, 255, 0.8); }
#padDebug .pd-axes { opacity: 0.8; }
.btn.cursor {
  background: rgba(77, 243, 255, 0.28);
  border-color: var(--cyan);
  box-shadow: 0 0 22px rgba(77, 243, 255, 0.65), inset 0 0 12px rgba(77, 243, 255, 0.25);
  transform: scale(1.05);
  color: #fff;
}

.hint {
  margin-top: 14px;
  font-size: 14px; letter-spacing: 1px;
  color: rgba(207, 233, 255, 0.55);
}

/* ---------- title ---------- */
.title-box { max-width: 720px; width: 100%; }
.title-sub { font-size: 15px; letter-spacing: 6px; color: var(--magenta); margin-bottom: 6px; }
.logo {
  font-family: var(--font-logo);
  font-size: clamp(44px, 9vw, 84px);
  font-weight: 900;
  letter-spacing: 8px;
  color: #fff;
  text-shadow: 0 0 18px var(--cyan), 0 0 60px rgba(77, 243, 255, 0.5);
  line-height: 1;
}
.logo span { color: var(--cyan); }
.title-best {
  margin: 14px 0 22px;
  font-size: 18px; letter-spacing: 3px; color: var(--orange);
  font-weight: 700;
}

.controls-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-top: 30px;
  text-align: left;
}
.controls-grid > div {
  background: var(--panel);
  border: 1px solid rgba(77, 243, 255, 0.25);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 13.5px;
  line-height: 1.75;
  color: rgba(207, 233, 255, 0.8);
}
.cg-title { font-weight: 700; color: var(--cyan); font-size: 15px; margin-bottom: 4px; }

@media (max-width: 720px) {
  .controls-grid { grid-template-columns: 1fr; gap: 8px; }
  .controls-grid > div { font-size: 12.5px; }
}

/* ---------- wave banner ---------- */
#waveBanner { background: transparent; pointer-events: none; }
#bannerWave {
  font-family: var(--font-logo);
  font-size: clamp(40px, 8vw, 72px);
  font-weight: 800; letter-spacing: 10px;
  color: #fff;
  text-shadow: 0 0 24px var(--magenta), 0 0 70px rgba(255, 77, 216, 0.6);
  animation: bannerIn 1.6s ease forwards;
}
#bannerSub {
  margin-top: 10px;
  font-size: 18px; letter-spacing: 8px; color: var(--cyan);
  animation: bannerIn 1.6s ease forwards;
}
@keyframes bannerIn {
  0% { opacity: 0; transform: scale(1.4); }
  20% { opacity: 1; transform: scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: scale(0.96); }
}

/* ---------- upgrade ---------- */
.up-box { width: min(880px, 96vw); }
.up-title {
  font-family: var(--font-logo);
  font-size: clamp(22px, 4vw, 34px);
  font-weight: 800; letter-spacing: 6px;
  color: var(--green);
  text-shadow: 0 0 20px rgba(109, 255, 168, 0.6);
}
.up-sub { margin: 8px 0 26px; font-size: 14px; letter-spacing: 2px; color: rgba(207,233,255,0.6); }
#upCards { display: flex; gap: 18px; justify-content: center; flex-wrap: wrap; }
.up-card {
  width: 230px;
  background: var(--panel);
  border: 1px solid rgba(77, 243, 255, 0.3);
  border-radius: 14px;
  padding: 22px 18px 20px;
  cursor: pointer;
  transition: all 0.15s ease;
  position: relative;
  animation: cardIn 0.4s ease backwards;
}
.up-card:nth-child(2) { animation-delay: 0.08s; }
.up-card:nth-child(3) { animation-delay: 0.16s; }
@keyframes cardIn {
  from { opacity: 0; transform: translateY(24px) scale(0.95); }
  to { opacity: 1; transform: none; }
}
.up-card.cursor {
  border-color: var(--cyan);
  box-shadow: 0 0 30px rgba(77, 243, 255, 0.55), inset 0 0 34px rgba(77, 243, 255, 0.14);
  transform: translateY(-5px);
}
.up-card:hover, .up-card.sel {
  border-color: var(--cyan);
  box-shadow: 0 0 26px rgba(77, 243, 255, 0.35), inset 0 0 30px rgba(77, 243, 255, 0.07);
  transform: translateY(-6px);
}
.up-card .key {
  position: absolute; top: 10px; right: 14px;
  font-size: 13px; color: rgba(207,233,255,0.4);
  font-weight: 700;
}
.up-card .icon { font-size: 40px; margin-bottom: 10px; filter: drop-shadow(0 0 10px rgba(77,243,255,0.6)); }
.up-card .name { font-size: 19px; font-weight: 700; color: #fff; letter-spacing: 1px; }
.up-card .desc { margin-top: 8px; font-size: 14px; line-height: 1.6; color: rgba(207,233,255,0.72); }
.up-card .cost {
  margin-top: 12px;
  font-family: var(--font-logo);
  font-size: 16px; font-weight: 800; letter-spacing: 1px;
  color: #ffd84d;
  text-shadow: 0 0 10px rgba(255,216,77,0.55);
}
.up-card .cost.lack { color: #ff5566; text-shadow: 0 0 10px rgba(255,85,102,0.6); }
.up-card .cost.free { color: var(--green); text-shadow: 0 0 10px rgba(109,255,168,0.55); }
.up-card.unaffordable { opacity: 0.55; filter: saturate(0.4); }
.up-card.unaffordable:hover { border-color: rgba(255,85,102,0.5); box-shadow: 0 0 18px rgba(255,85,102,0.2); }
.up-card.up-skip { border-style: dashed; border-color: rgba(207,233,255,0.28); }

@media (max-width: 780px) {
  #upCards { flex-direction: column; align-items: center; }
  .up-card { width: min(420px, 92vw); }
}

/* ---------- pause / game over ---------- */
.pause-title {
  font-family: var(--font-logo);
  font-size: 44px; font-weight: 800; letter-spacing: 12px;
  color: var(--cyan);
  text-shadow: 0 0 24px rgba(77,243,255,0.6);
}
.pause-box { display: flex; flex-direction: column; align-items: center; }

.over-box { max-width: 560px; }
.over-title {
  font-family: var(--font-logo);
  font-size: clamp(30px, 6vw, 48px);
  font-weight: 900; letter-spacing: 6px; line-height: 1.25;
  color: #fff;
  text-shadow: 0 0 22px var(--magenta), 0 0 70px rgba(255,77,216,0.55);
}
.over-stats {
  margin: 22px auto 8px;
  display: inline-block;
  text-align: left;
  background: var(--panel);
  border: 1px solid rgba(255,77,216,0.3);
  border-radius: 12px;
  padding: 16px 30px;
  font-size: 17px; line-height: 2; letter-spacing: 2px;
}
.over-stats span { color: var(--orange); font-weight: 700; }

/* ---------- HUD ---------- */
#hud {
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 20;
  padding: calc(10px + env(safe-area-inset-top)) calc(14px + env(safe-area-inset-right)) 0 calc(14px + env(safe-area-inset-left));
}
.hud-top { display: flex; justify-content: space-between; align-items: flex-start; }
.hud-label { font-size: 12px; letter-spacing: 3px; color: rgba(207,233,255,0.55); font-weight: 700; }

#hpbar {
  width: min(220px, 34vw); height: 12px;
  margin-top: 4px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(77,243,255,0.4);
  border-radius: 6px;
  overflow: hidden;
}
#hpfill {
  height: 100%; width: 100%;
  background: linear-gradient(90deg, var(--cyan), #9ffcff);
  box-shadow: 0 0 12px rgba(77,243,255,0.7);
  transition: width 0.12s linear;
}
#hpfill.hurt { background: linear-gradient(90deg, var(--orange), #ffd29f); }

/* シールドバー */
.hud-label.shield { margin-top: 6px; color: rgba(140,220,255,0.7); }
#shieldbar {
  width: min(220px, 34vw); height: 7px;
  margin-top: 3px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(140,216,255,0.5);
  border-radius: 4px;
  overflow: hidden;
}
#shieldfill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, #4da8ff, #bfe8ff);
  box-shadow: 0 0 10px rgba(120,200,255,0.8);
  transition: width 0.12s linear;
}

#dodgetext {
  margin-top: 6px;
  font-family: var(--font-logo);
  font-size: 15px; font-weight: 800; letter-spacing: 3px;
  color: var(--green);
  text-shadow: 0 0 12px rgba(109,255,168,0.8);
  opacity: 0;
}
#dodgetext.show { animation: dodgePop 0.6s ease forwards; }
@keyframes dodgePop {
  0% { opacity: 0; transform: scale(0.6); }
  25% { opacity: 1; transform: scale(1.15); }
  100% { opacity: 0; transform: scale(1); }
}

.hud-mid { text-align: center; flex: 1; padding-top: 2px; }
#waveLabel {
  font-family: var(--font-logo);
  font-size: clamp(16px, 2.6vw, 22px);
  font-weight: 800; letter-spacing: 5px;
  color: #fff;
  text-shadow: 0 0 14px rgba(255,77,216,0.7);
}
#bossWrap { margin-top: 8px; max-width: min(460px, 60vw); margin-left: auto; margin-right: auto; }
#bossLabel { font-size: 11px; letter-spacing: 3px; color: var(--magenta); font-weight: 700; text-align: center; }
#bossbar {
  height: 8px; margin-top: 3px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,77,216,0.5);
  border-radius: 4px; overflow: hidden;
}
#bossfill {
  height: 100%; width: 100%;
  background: linear-gradient(90deg, var(--magenta), #ff8fe4);
  box-shadow: 0 0 10px rgba(255,77,216,0.8);
  transition: width 0.12s linear;
}

.hud-right { text-align: right; }
#scoreLabel {
  font-family: var(--font-logo);
  font-size: clamp(18px, 3vw, 26px);
  font-weight: 800; letter-spacing: 3px;
  color: var(--orange);
  text-shadow: 0 0 14px rgba(255,161,77,0.5);
}
#dashIcon {
  margin-top: 4px;
  font-size: 13px; font-weight: 700; letter-spacing: 2px;
  color: var(--green);
  text-shadow: 0 0 10px rgba(109,255,168,0.6);
}
#dashIcon.cooling { color: rgba(207,233,255,0.35); text-shadow: none; }

/* 黄色コア(強化通貨) */
#coreRow {
  margin-top: 5px;
  font-family: var(--font-logo);
  font-size: clamp(14px, 2.2vw, 18px);
  font-weight: 800; letter-spacing: 2px;
  color: #ffd84d;
  text-shadow: 0 0 12px rgba(255,216,77,0.7);
}
#coreRow .core-icon { font-size: 1.1em; margin-right: 2px; }
#coreRow .core-word { font-size: 0.62em; letter-spacing: 3px; color: rgba(255,216,77,0.65); margin-left: 5px; }

.hud-actions {
  margin-top: 4px;
  display: flex; gap: 14px; justify-content: flex-end;
  font-size: 13px; font-weight: 700; letter-spacing: 2px;
}
#bombIcon {
  color: var(--orange);
  text-shadow: 0 0 10px rgba(255,161,77,0.6);
}
#bombIcon.cooling { color: rgba(207,233,255,0.35); text-shadow: none; }

#muteBtn {
  position: fixed;
  top: calc(8px + env(safe-area-inset-top));
  left: calc(8px + env(safe-area-inset-left));
  z-index: 60;
  width: 38px; height: 38px;
  border-radius: 50%;
  border: 1px solid rgba(77,243,255,0.4);
  background: rgba(10,14,30,0.6);
  font-size: 17px;
  cursor: pointer;
  display: none;
}
body.playing #muteBtn, body.title #muteBtn { display: block; }
body.touchui-active #muteBtn { display: none; } /* 画面が狭いときは非表示 */

/* ---------- toast ---------- */
#toast {
  position: fixed;
  top: 64px; left: 50%;
  transform: translateX(-50%);
  z-index: 55;
  background: var(--panel);
  border: 1px solid rgba(77,243,255,0.5);
  border-radius: 999px;
  padding: 8px 26px;
  font-size: 15px; font-weight: 700; letter-spacing: 2px;
  color: var(--cyan);
  opacity: 0;
  transition: opacity 0.25s ease;
  pointer-events: none;
  white-space: nowrap;
}
#toast.show { opacity: 1; }

/* ---------- touch UI ---------- */
#touchui {
  position: fixed; inset: 0;
  z-index: 25;
  pointer-events: none;
}
#stickZone {
  position: absolute;
  left: 0; top: 22%;
  width: 46%; height: 62%;
  pointer-events: auto;
  touch-action: none;
}
#stickBase {
  position: absolute;
  width: 128px; height: 128px;
  border-radius: 50%;
  border: 2px solid rgba(77,243,255,0.45);
  background: rgba(77,243,255,0.06);
  box-shadow: 0 0 24px rgba(77,243,255,0.2), inset 0 0 18px rgba(77,243,255,0.12);
  transform: translate(-50%, -50%);
  display: none;
}
#stickKnob {
  position: absolute; left: 50%; top: 50%;
  width: 54px; height: 54px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, rgba(77,243,255,0.9), rgba(77,243,255,0.35));
  box-shadow: 0 0 16px rgba(77,243,255,0.7);
  transform: translate(-50%, -50%);
}
#touchBtns {
  position: absolute;
  right: calc(18px + env(safe-area-inset-right));
  bottom: calc(26px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  pointer-events: auto;
}
#fireBtn, #dashBtn {
  border-radius: 50%;
  border: 2px solid rgba(255,77,216,0.65);
  background: rgba(255,77,216,0.12);
  color: #ffd9f3;
  font-family: var(--font-ui);
  font-weight: 700; letter-spacing: 2px;
  touch-action: none;
  -webkit-user-select: none; user-select: none;
  box-shadow: 0 0 18px rgba(255,77,216,0.25);
}
#fireBtn {
  width: 92px; height: 92px;
  font-size: 17px;
  border-color: rgba(77,243,255,0.7);
  background: rgba(77,243,255,0.14);
  color: #d8fbff;
  box-shadow: 0 0 20px rgba(77,243,255,0.3);
}
#fireBtn:active { background: rgba(77,243,255,0.32); }
#dashBtn { width: 64px; height: 64px; font-size: 12px; }
#dashBtn:active { background: rgba(255,77,216,0.32); }
#bombBtn {
  width: 58px; height: 58px; font-size: 11px;
  border-color: rgba(255,161,77,0.65);
  color: #ffd84d;
}
#bombBtn:active { background: rgba(255,161,77,0.32); }

#ppBtn {
  position: fixed;
  top: calc(10px + env(safe-area-inset-top));
  right: calc(12px + env(safe-area-inset-right));
  z-index: 26;
  width: 44px; height: 44px;
  border-radius: 10px;
  border: 1px solid rgba(77,243,255,0.4);
  background: rgba(10,14,30,0.55);
  color: #cfe9ff;
  font-size: 18px;
  cursor: pointer;
}

@media (max-width: 600px) {
  #hud .hud-label { font-size: 10px; }
  #hpbar { height: 9px; }
}
