* {
  margin: 0; padding: 0; box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none; /* 長押しメニュー無効 */
  user-select: none;
  -webkit-user-select: none;
}

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  overscroll-behavior: none; /* 引っ張り更新・バウンス無効 */
  background: #0a0a14;
  font-family: "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
  color: #fff;
  touch-action: none;
}

canvas, img { -webkit-user-drag: none; user-drag: none; }

#app { position: fixed; inset: 0; }
#flash {
  position: absolute; inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
  z-index: 15;
  transition: opacity 0.28s ease-out;
}
#flash.on { opacity: 0.55; transition: opacity 0.03s; }

/* サウンドコントロール（常時表示・右上） */
#sound-ui {
  position: absolute;
  top: calc(64px + env(safe-area-inset-top));
  right: calc(10px + env(safe-area-inset-right));
  display: flex; align-items: center; gap: 6px;
  z-index: 25;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 18px;
  padding: 4px 10px;
  touch-action: auto;
}
#btn-sound {
  background: none; border: none;
  font-size: 17px; cursor: pointer;
  padding: 2px;
}
#vol-slider {
  width: 70px;
  accent-color: #ffb040;
  cursor: pointer;
}
#canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.screen {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  background: radial-gradient(ellipse at center, #1a1a3a 0%, #0a0a14 100%);
  z-index: 20;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.hidden { display: none !important; }

.title {
  font-size: clamp(36px, 8vw, 72px);
  font-weight: 900;
  letter-spacing: 0.12em;
  background: linear-gradient(105deg, #4de8ff 20%, #b48cff 55%, #ff5ad4 85%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 22px rgba(90, 200, 255, 0.55));
}
.title-en {
  margin-top: 2px;
  font-size: clamp(13px, 2.2vw, 18px);
  font-weight: 800;
  letter-spacing: 0.55em;
  color: #7de0ff;
  opacity: 0.9;
  text-shadow: 0 0 16px rgba(90, 200, 255, 0.6);
}
.subtitle { margin: 10px 0 24px; opacity: 0.8; font-size: clamp(13px, 2.5vw, 18px); letter-spacing: 0.3em; }

/* 3Dキャラ選択オーバーレイ（背後のcanvasにモデルを表示） */
.screen.overlay {
  background: transparent;
  pointer-events: none;
  justify-content: space-between;
}
.select-top { text-align: center; padding-top: 12px; }
.select-bottom {
  display: flex; flex-direction: column; align-items: center;
  gap: 10px; padding-bottom: 16px; width: 100%;
}
#select-info {
  display: flex; gap: 14px; align-items: baseline;
  background: rgba(0,0,0,0.5);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 10px;
  padding: 8px 18px;
}
#sel-name { font-size: 22px; font-weight: 900; letter-spacing: 0.1em; color: var(--c, #fff); }
#sel-special { font-size: 13px; opacity: 0.85; }
#select-bar { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.sel-btn {
  pointer-events: auto;
  padding: 9px 16px;
  font-size: 14px; font-weight: 800;
  color: #fff; letter-spacing: 0.06em;
  background: rgba(0,0,0,0.5);
  border: 2px solid rgba(255,255,255,0.25);
  border-radius: 10px;
  cursor: pointer;
}
.sel-btn.selected { border-color: var(--c); color: var(--c); box-shadow: 0 0 16px color-mix(in srgb, var(--c) 50%, transparent); }
#difficulty-bar { display: flex; gap: 8px; align-items: center; }
.diff-label { font-size: 12px; opacity: 0.75; letter-spacing: 0.1em; }
.diff-btn {
  pointer-events: auto;
  padding: 6px 14px;
  font-size: 13px; font-weight: 800;
  color: #fff;
  background: rgba(0,0,0,0.5);
  border: 2px solid rgba(255,255,255,0.22);
  border-radius: 8px;
  cursor: pointer;
}
.diff-btn.selected { border-color: #ffc46b; color: #ffc46b; box-shadow: 0 0 12px rgba(255,180,60,0.4); }
.menu-btn.start { pointer-events: auto; }
.menu-btn:disabled { opacity: 0.35; cursor: default; }

.loading-box { width: min(70vw, 360px); text-align: center; }
#loading-label { letter-spacing: 0.35em; margin-bottom: 14px; opacity: 0.85; }
.loading-bar { height: 8px; border-radius: 4px; background: rgba(255,255,255,0.12); overflow: hidden; }
#loading-fill { height: 100%; width: 0%; border-radius: 4px; background: linear-gradient(90deg, #ffe259, #ff7b29); transition: width 0.15s; }

/* ===== HUD ===== */
#hud { position: absolute; inset: 0; z-index: 10; pointer-events: none; }
.hud-top {
  position: absolute;
  top: calc(10px + env(safe-area-inset-top));
  left: calc(12px + env(safe-area-inset-left));
  right: calc(12px + env(safe-area-inset-right));
  display: flex; align-items: flex-start; gap: 12px;
}
.hud-side { flex: 1; }
.hud-side.right { text-align: right; }
.hud-side .name { font-size: 13px; font-weight: 800; letter-spacing: 0.1em; margin-bottom: 4px; text-shadow: 0 1px 3px #000; }
.hp-bar {
  height: 14px; border-radius: 7px;
  background: rgba(0,0,0,0.55);
  border: 1px solid rgba(255,255,255,0.35);
  overflow: hidden;
}
.hp-fill { height: 100%; width: 100%; background: linear-gradient(90deg, #7dff6a, #2ecc40); transition: width 0.18s; }
.hp-fill.low { background: linear-gradient(90deg, #ff6a6a, #e0281e); }
.hud-side.right .hp-fill { float: right; }
.sp-bar {
  height: 7px; margin-top: 4px; border-radius: 4px;
  background: rgba(0,0,0,0.55);
  border: 1px solid rgba(255,255,255,0.25);
  overflow: hidden;
}
.sp-fill { height: 100%; width: 0%; background: linear-gradient(90deg, #58c6ff, #2e6bff); transition: width 0.15s; }
.sp-fill.full { background: linear-gradient(90deg, #ffe259, #ff7b29); animation: sp-pulse 0.7s infinite alternate; }
.hud-side.right .sp-fill { float: right; }
@keyframes sp-pulse { from { filter: brightness(1); } to { filter: brightness(1.6); } }

.hud-center { text-align: center; min-width: 90px; }
#timer {
  font-size: 30px; font-weight: 900;
  text-shadow: 0 2px 6px #000;
}
#stage-label {
  font-size: 11px; font-weight: 800;
  letter-spacing: 0.15em;
  color: #ffc46b;
  text-shadow: 0 1px 3px #000;
}

#announce {
  position: absolute; top: 34%; left: 0; right: 0;
  text-align: center;
  font-size: clamp(40px, 10vw, 90px);
  font-weight: 900; letter-spacing: 0.1em;
  color: #ffde59;
  text-shadow: 0 0 30px rgba(255, 160, 40, 0.8), 0 4px 8px #000;
  animation: announce-pop 0.3s ease-out;
}
@keyframes announce-pop {
  from { transform: scale(2.2); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

#special-banner {
  position: absolute; top: 22%; left: 0; right: 0;
  text-align: center;
  font-size: clamp(26px, 6vw, 52px);
  font-weight: 900; letter-spacing: 0.25em;
  color: #fff;
  text-shadow: 0 0 24px var(--c, #ff7b29), 0 0 60px var(--c, #ff7b29), 0 3px 6px #000;
  animation: banner-slide 0.25s ease-out;
}
@keyframes banner-slide {
  from { transform: translateX(40px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ===== タッチUI ===== */
#touch-ui {
  position: absolute;
  bottom: calc(14px + env(safe-area-inset-bottom));
  left: calc(14px + env(safe-area-inset-left));
  right: calc(14px + env(safe-area-inset-right));
  display: flex; justify-content: space-between; align-items: flex-end;
  pointer-events: none;
}
.pad-left, .pad-right { display: flex; gap: 12px; align-items: flex-end; pointer-events: auto; }
.pad-right { flex-direction: column; align-items: flex-end; gap: 10px; }
.pr-row { display: flex; gap: 10px; }
.tbtn.jump { background: rgba(120, 220, 130, 0.25); border-color: rgba(140, 240, 160, 0.6); width: 56px; height: 56px; font-size: 18px; }
.tbtn.guard { background: rgba(140, 150, 255, 0.25); border-color: rgba(160, 170, 255, 0.6); }
.tbtn {
  width: 64px; height: 64px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.4);
  background: rgba(255,255,255,0.12);
  color: #fff;
  font-size: 22px; font-weight: 800;
  backdrop-filter: blur(4px);
  touch-action: none;
}
.tbtn.move { width: 72px; height: 72px; font-size: 26px; }
.tbtn.atk { background: rgba(255, 90, 60, 0.25); border-color: rgba(255, 140, 100, 0.6); }
.tbtn.sp { background: rgba(80, 140, 255, 0.25); border-color: rgba(120, 170, 255, 0.7); width: 56px; height: 56px; font-size: 18px; }
.tbtn.pressed { background: rgba(255,255,255,0.45); transform: scale(0.92); }
.tbtn.sp.ready { background: rgba(255, 180, 40, 0.5); border-color: #ffe259; animation: sp-pulse 0.7s infinite alternate; }

#key-hint {
  position: absolute;
  bottom: calc(8px + env(safe-area-inset-bottom));
  left: 0; right: 0;
  text-align: center;
  font-size: 11px; opacity: 0.5;
  pointer-events: none;
}
body.touch #key-hint { display: none; }
body:not(.touch) #touch-ui { display: none; }

/* ===== デバッグ: モーションビューア（?debug） ===== */
#debug-panel {
  position: absolute;
  top: calc(8px + env(safe-area-inset-top));
  right: calc(8px + env(safe-area-inset-right));
  width: min(300px, 45vw);
  max-height: calc(100vh - 24px);
  overflow-y: auto;
  background: rgba(8, 10, 24, 0.88);
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: 10px;
  padding: 10px;
  z-index: 40;
  font-size: 12px;
  pointer-events: auto;
  touch-action: pan-y;
}
.dbg-title { font-weight: 900; letter-spacing: 0.1em; margin-bottom: 8px; color: #ffc46b; }
.dbg-chars { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 6px; }
.dbg-char {
  padding: 5px 8px; font-size: 11px; font-weight: 700;
  background: rgba(255,255,255,0.1); color: #fff;
  border: 1px solid rgba(255,255,255,0.25); border-radius: 6px; cursor: pointer;
}
.dbg-char.active { border-color: #ffc46b; color: #ffc46b; }
.dbg-sec { margin: 10px 0 4px; font-weight: 800; opacity: 0.7; letter-spacing: 0.05em; }
.dbg-clip {
  display: flex; justify-content: space-between; align-items: center;
  width: 100%; text-align: left;
  padding: 6px 8px; margin: 2px 0;
  background: rgba(255,255,255,0.06); color: #fff;
  border: 1px solid rgba(255,255,255,0.15); border-radius: 6px;
  font-size: 12px; cursor: pointer;
}
.dbg-clip:hover, .dbg-clip.active { background: rgba(255,180,60,0.25); border-color: #ffc46b; }
.dbg-clip span { opacity: 0.6; font-size: 11px; }
.dbg-map {
  display: flex; justify-content: space-between; gap: 8px;
  padding: 3px 2px; border-bottom: 1px solid rgba(255,255,255,0.08);
}
.dbg-map b { opacity: 0.85; font-weight: 600; }
.dbg-map span { opacity: 0.7; text-align: right; }

/* ===== リザルト（勝利ポーズが見えるよう暗転させない） ===== */
#result-screen {
  background: radial-gradient(ellipse at center, transparent 45%, rgba(5, 5, 15, 0.45) 100%);
  justify-content: flex-end;
  padding-bottom: max(6vh, env(safe-area-inset-bottom));
}
#result-text {
  font-size: clamp(44px, 11vw, 100px);
  font-weight: 900; letter-spacing: 0.12em;
  color: #ffde59;
  text-shadow: 0 0 40px rgba(255, 150, 30, 0.9), 0 5px 10px #000, 0 0 4px #000;
  margin-bottom: 18px;
  text-align: center;
}
#result-sub {
  font-size: clamp(15px, 3vw, 22px);
  font-weight: 800;
  letter-spacing: 0.15em;
  color: #fff;
  text-shadow: 0 2px 6px #000;
  margin: -8px 0 20px;
  text-align: center;
}
.result-buttons { display: flex; gap: 16px; }
.menu-btn {
  padding: 14px 30px;
  font-size: 17px; font-weight: 800;
  color: #fff;
  background: linear-gradient(160deg, rgba(255,255,255,0.16), rgba(255,255,255,0.05));
  border: 2px solid rgba(255,255,255,0.35);
  border-radius: 12px;
  cursor: pointer;
  letter-spacing: 0.08em;
}
.menu-btn:active, .menu-btn:hover,
.menu-btn.focused { background: rgba(255, 160, 60, 0.35); border-color: #ffb040; box-shadow: 0 0 18px rgba(255, 170, 60, 0.5); }
