* { box-sizing: border-box; }
:root { --cyan: #22e6ff; --magenta: #ff2bd6; --ink: #05060f; }
html, body {
  margin: 0; height: 100%;
  background:
    radial-gradient(ellipse at 50% 120%, rgba(255, 43, 214, .22), transparent 60%),
    radial-gradient(ellipse at 50% -20%, rgba(34, 230, 255, .18), transparent 55%),
    linear-gradient(180deg, #070818 0%, #0b0620 100%);
  color: #dfe8ff;
  font-family: 'M PLUS 1', sans-serif;
  font-weight: 700;
  overflow: hidden;
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
}
#app {
  position: relative;
  height: 100%;
  display: flex; align-items: center; justify-content: center;
}
.screen {
  display: none;
  flex-direction: column; align-items: center; justify-content: center;
  gap: 16px;
  width: 100%; max-width: 520px; max-height: 100%;
  padding: 18px;
  overflow-y: auto;
}
.screen.active { display: flex; }
#s-game { padding: 6px; gap: 6px; max-width: none; overflow: hidden; height: 100%; }

/* タイトル（ネオン＋ときどきグリッチ） */
.logo { display: flex; flex-direction: column; align-items: center; gap: 6px; margin-top: 6px; }
.logo .l1 {
  position: relative;
  font-size: clamp(30px, 10.5vw, 64px); font-weight: 900; white-space: nowrap;
  color: #fff;
  text-shadow: 0 0 6px var(--cyan), 0 0 18px var(--cyan), 0 0 36px rgba(34, 230, 255, .6);
}
.glitch::before, .glitch::after {
  content: attr(data-text);
  position: absolute; left: 0; top: 0; width: 100%;
  opacity: 0; pointer-events: none;
}
.glitch::before { color: var(--magenta); text-shadow: 0 0 8px var(--magenta); animation: glitch-a 4.2s infinite steps(1); }
.glitch::after { color: var(--cyan); text-shadow: 0 0 8px var(--cyan); animation: glitch-b 4.2s infinite steps(1); }
@keyframes glitch-a {
  0%, 88%, 100% { opacity: 0; transform: none; }
  89% { opacity: .9; transform: translate(-4px, 1px); clip-path: inset(10% 0 55% 0); }
  91% { opacity: .9; transform: translate(5px, -1px); clip-path: inset(60% 0 8% 0); }
  93% { opacity: 0; }
}
@keyframes glitch-b {
  0%, 88%, 100% { opacity: 0; transform: none; }
  90% { opacity: .9; transform: translate(4px, 0); clip-path: inset(40% 0 30% 0); }
  92% { opacity: .9; transform: translate(-3px, 2px); clip-path: inset(0 0 75% 0); }
  94% { opacity: 0; }
}
.logo .l2 {
  font-family: 'Orbitron', sans-serif;
  font-size: clamp(16px, 5.4vw, 26px); font-weight: 900; letter-spacing: 6px;
  color: var(--magenta);
  text-shadow: 0 0 6px var(--magenta), 0 0 16px rgba(255, 43, 214, .6);
}
.sub { font-size: 15px; color: #8fa6d8; letter-spacing: 1px; }

h2 {
  font-size: 24px; font-weight: 900; color: #fff; margin: 4px 0; text-align: center; letter-spacing: 2px;
  text-shadow: 0 0 6px var(--cyan), 0 0 16px rgba(34, 230, 255, .5);
}
h3 { color: var(--cyan); margin: 14px 0 4px; font-size: 17px; letter-spacing: 1px; }

/* ボタン（黒地にネオンの縁・角を切った形・押すと沈む） */
.menu { display: flex; flex-direction: column; align-items: stretch; gap: 14px; width: min(330px, 100%); }
button {
  --c: var(--cyan);
  font-family: inherit; font-weight: 900;
  font-size: 19px; letter-spacing: 1px;
  color: #fff;
  background: rgba(8, 10, 28, .85);
  border: 2px solid var(--c);
  border-radius: 0;
  clip-path: polygon(12px 0, 100% 0, 100% calc(100% - 12px), calc(100% - 12px) 100%, 0 100%, 0 12px);
  box-shadow: inset 0 0 14px color-mix(in srgb, var(--c) 35%, transparent);
  text-shadow: 0 0 8px var(--c);
  padding: 12px 16px;
  cursor: pointer;
  display: flex; flex-direction: column; align-items: center;
  transition: transform .06s, background .1s;
}
button small { font-size: 12px; font-weight: 700; color: #9fb2e0; text-shadow: none; }
button:hover, button:focus { outline: none; background: color-mix(in srgb, var(--c) 22%, #080a1c); }
button:focus-visible { outline: 2px solid #fff; outline-offset: -6px; }
button:active { transform: translateY(3px); }
button.back { --c: var(--magenta); font-size: 16px; }
button.current { background: color-mix(in srgb, var(--c) 30%, #080a1c); box-shadow: inset 0 0 22px color-mix(in srgb, var(--c) 60%, transparent), 0 0 14px var(--c); }
button:disabled { opacity: .3; cursor: default; }
button.setting { flex-direction: row; justify-content: space-between; font-size: 17px; }
button.setting span:last-child { color: var(--cyan); }

.join-row { display: flex; gap: 10px; }
.join-row input {
  width: 130px; font-family: 'Orbitron', sans-serif; font-weight: 900; font-size: 18px; text-transform: uppercase;
  background: #05060f; color: var(--cyan); border: 2px solid var(--cyan); border-radius: 0; padding: 8px; text-align: center;
  box-shadow: inset 0 0 10px rgba(34, 230, 255, .3);
}
.join-row button { flex: 1; font-size: 16px; }
.room-code {
  font-family: 'Orbitron', sans-serif; font-size: 36px; font-weight: 900; color: #fff; text-align: center; letter-spacing: 8px; min-height: 4px;
  text-shadow: 0 0 8px var(--magenta), 0 0 20px var(--magenta);
}
.status { text-align: center; color: #8fa6d8; min-height: 2.4em; margin: 0; }

/* キャラ選択 */
.select-stage { position: relative; width: 100%; height: min(300px, 40vh); border: 1px solid rgba(34, 230, 255, .35);
  background: radial-gradient(ellipse at 50% 85%, rgba(160, 102, 255, .25), transparent 65%), rgba(5, 6, 15, .6); }
#select-canvas { width: 100%; height: 100%; display: block; cursor: pointer; }
.select-loading { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-family: 'Orbitron', sans-serif; color: var(--cyan); letter-spacing: 4px; text-shadow: 0 0 8px var(--cyan); }
.select-name { font-family: 'M PLUS 1', sans-serif; font-weight: 900; font-size: 26px; letter-spacing: 4px; min-height: 1.4em; text-shadow: 0 0 12px currentColor; }
.robot-row { display: flex; gap: 10px; width: min(420px, 100%); }
.robot-row button { flex: 1; font-size: 16px; padding: 10px 6px; }

/* 遊び方 */
.howto {
  width: 100%; line-height: 1.7; font-size: 14px; font-weight: 500;
  background: rgba(8, 10, 28, .8); border: 1px solid rgba(34, 230, 255, .35); padding: 6px 18px 14px;
}
.howto b { font-weight: 900; color: #fff; }
.howto ul { padding-left: 18px; margin: 4px 0; }
.howto li { margin: 4px 0; }
.item-list { list-style: none; padding-left: 0 !important; }
.item-list li { display: flex; align-items: center; gap: 10px; }
.item-list b { font-family: 'Orbitron', sans-serif; font-size: 11px; display: block; letter-spacing: 2px; }

.badge {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 36px; height: 36px; border-radius: 0;
  color: #fff; font-size: 17px; font-weight: 900;
  clip-path: polygon(8px 0, 100% 0, 100% calc(100% - 8px), calc(100% - 8px) 100%, 0 100%, 0 8px);
  box-shadow: inset 0 0 10px rgba(255, 255, 255, .35);
}

/* ゲーム画面 */
.hud {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; height: 42px;
  padding: 0 8px 0 14px;
  background: rgba(5, 6, 15, .82);
  border: 1px solid var(--c);
  box-shadow: 0 0 12px color-mix(in srgb, var(--c) 45%, transparent), inset 0 0 12px color-mix(in srgb, var(--c) 25%, transparent);
  clip-path: polygon(10px 0, 100% 0, 100% calc(100% - 10px), calc(100% - 10px) 100%, 0 100%, 0 10px);
}
.hud .name { font-size: 15px; font-weight: 900; white-space: nowrap; color: var(--c); text-shadow: 0 0 8px var(--c); }
.hud .name::before { content: '▶'; margin-right: 6px; font-size: 11px; }
.hud .score {
  margin-left: auto; font-family: 'Orbitron', sans-serif; font-size: 24px; font-weight: 900;
  color: #fff; text-shadow: 0 0 8px var(--c), 0 0 18px var(--c); min-width: 40px; text-align: center;
}
.hud .effects { display: flex; gap: 6px; overflow: hidden; white-space: nowrap; }
.hud .ef { display: inline-flex; align-items: center; gap: 3px; color: #fff; font-size: 14px; font-weight: 900; padding: 3px 10px; text-shadow: 0 0 4px #000, 0 0 2px #000;
  clip-path: polygon(6px 0, 100% 0, 100% calc(100% - 6px), calc(100% - 6px) 100%, 0 100%, 0 6px); }
.hud .ef.ending { animation: ef-blink .25s steps(2) infinite; }
@keyframes ef-blink { 50% { opacity: .35; } }
#hud-top { --c: var(--top-color, var(--magenta)); }
#hud-bottom { --c: var(--bottom-color, var(--cyan)); }

#court-wrap { position: relative; touch-action: none; border: 1px solid rgba(34, 230, 255, .3); }
#court { display: block; touch-action: none; }
#flash { position: absolute; inset: 0; pointer-events: none; opacity: 0; mix-blend-mode: screen; }
#banner {
  position: absolute; left: 0; right: 0; top: 46%; transform: translateY(-50%);
  text-align: center; pointer-events: none;
  font-family: 'Orbitron', sans-serif; font-size: clamp(34px, 11vw, 70px); font-weight: 900; letter-spacing: 4px;
  color: #fff;
  text-shadow: 0 0 8px var(--banner, var(--cyan)), 0 0 24px var(--banner, var(--cyan)), 0 0 48px var(--banner, var(--cyan));
}
#btn-pause {
  position: absolute; top: 10px; right: 10px;
  width: 44px; height: 44px; padding: 0; font-size: 18px;
  justify-content: center;
}

.overlay {
  position: absolute; inset: 0;
  background: rgba(5, 6, 15, .72);
  backdrop-filter: blur(3px);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  z-index: 10;
}
.overlay h2 { font-family: 'Orbitron', 'M PLUS 1', sans-serif; font-size: 38px; }
.overlay p { margin: 0; font-size: 17px; }
.overlay.hidden, .hidden { display: none !important; }
.result-score { font-family: 'Orbitron', sans-serif; font-size: 32px !important; font-weight: 900; color: #fff; text-shadow: 0 0 10px var(--cyan); }

.toast {
  position: absolute; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: rgba(5, 6, 15, .92); color: #fff; border: 1px solid var(--magenta); padding: 10px 18px; z-index: 30; font-size: 15px;
  box-shadow: 0 0 14px rgba(255, 43, 214, .5);
}

/* エンドレス：LV とライフ・段階が上がったときの表示 */
.endless-info {
  position: absolute; top: 12px; left: 12px; pointer-events: none;
  font-family: 'Orbitron', 'M PLUS 1', sans-serif; font-weight: 900; font-size: 20px; letter-spacing: 2px;
  color: #fff; text-shadow: 0 0 8px var(--cyan), 0 0 16px var(--cyan);
}
.endless-info .life { margin-left: 12px; color: var(--magenta); text-shadow: 0 0 8px var(--magenta); }
.notice {
  position: absolute; left: 0; right: 0; top: 16%; text-align: center; pointer-events: none;
  animation: notice-in .3s ease-out;
}
.notice .n1 { font-family: 'Orbitron', sans-serif; font-weight: 900; font-size: clamp(28px, 9vw, 56px); letter-spacing: 4px;
  color: #fff; text-shadow: 0 0 10px var(--nc, var(--magenta)), 0 0 28px var(--nc, var(--magenta)); }
.notice .n2 { font-size: 20px; font-weight: 900; margin-top: 6px; color: #fff; text-shadow: 0 0 10px var(--cyan); }
@keyframes notice-in { from { transform: scale(1.4); opacity: 0; } to { transform: none; opacity: 1; } }

/* ランキング */
.ranking-list { list-style: none; margin: 0; padding: 0; width: min(380px, 100%); counter-reset: rank; }
.ranking-list li {
  counter-increment: rank;
  display: flex; align-items: center; gap: 12px; padding: 8px 14px; margin-bottom: 6px;
  background: rgba(8, 10, 28, .85); border: 1px solid rgba(34, 230, 255, .35);
}
.ranking-list li::before { content: counter(rank); font-family: 'Orbitron', sans-serif; font-weight: 900; width: 26px; color: var(--magenta); text-shadow: 0 0 6px var(--magenta); }
.ranking-list li .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ranking-list li .lv { font-family: 'Orbitron', sans-serif; font-weight: 900; color: var(--cyan); text-shadow: 0 0 6px var(--cyan); }
.ranking-list li.me { border-color: var(--magenta); box-shadow: 0 0 12px rgba(255, 43, 214, .5); }
.ranking-list li.empty::before { content: ''; width: 0; }
.rank-entry { display: flex; gap: 8px; width: min(380px, 92%); }
.rank-entry input {
  flex: 1; min-width: 0; font-family: inherit; font-weight: 700; font-size: 16px;
  background: #05060f; color: #fff; border: 2px solid var(--cyan); padding: 8px; box-shadow: inset 0 0 10px rgba(34, 230, 255, .3);
}
.rank-entry button { font-size: 15px; padding: 8px 10px; }
.rank-msg { min-height: 1.3em; color: var(--magenta); }
