/* ============================================
   回避マスター - Dodge Master
   ============================================ */

:root {
  --c-bg: #06070f;
  --c-cyan: #2ee6ff;
  --c-pink: #ff4d8d;
  --c-yellow: #ffd93d;
  --c-text: #eaf6ff;
  --c-dim: #7a8ba6;
  --font-num: 'Avenir Next', 'Helvetica Neue', Arial, sans-serif;
  --font-jp: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--c-bg);
  font-family: var(--font-jp);
  color: var(--c-text);
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

#game-container {
  position: fixed;
  inset: 0;
  /* フッター固定バナー広告ぶんだけ縮める（広告なしのときは 0px） */
  /* 共通ヘッダーぶんだけ下げる */
  top: var(--sgh-top, 0px);
  bottom: var(--ad-space, 0px);
  overflow: hidden;
}

#game-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: none;
}

.hidden { display: none !important; }

/* ---------- HUD ---------- */
#hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: max(12px, env(safe-area-inset-top)) 16px 0;
  pointer-events: none;
  z-index: 10;
}

#hud-time {
  text-align: center;
  font-family: var(--font-num);
  font-size: clamp(32px, 6vw, 52px);
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--c-text);
  text-shadow: 0 0 18px rgba(46, 230, 255, 0.55), 0 2px 8px rgba(0,0,0,0.6);
  font-variant-numeric: tabular-nums;
}

#hud-wave {
  position: absolute;
  top: max(16px, env(safe-area-inset-top));
  left: 18px;
  font-family: var(--font-num);
  font-size: clamp(14px, 2.2vw, 20px);
  font-weight: 700;
  color: var(--c-yellow);
  text-shadow: 0 0 12px rgba(255, 217, 61, 0.5);
}

#hud-graze {
  position: absolute;
  top: max(16px, env(safe-area-inset-top));
  right: 70px;
  font-family: var(--font-num);
  font-size: clamp(13px, 2vw, 18px);
  font-weight: 700;
  color: var(--c-pink);
  text-shadow: 0 0 12px rgba(255, 77, 141, 0.5);
  font-variant-numeric: tabular-nums;
}
.graze-label { opacity: 0.75; font-size: 0.8em; margin-right: 2px; }

/* ---------- ミュートボタン ---------- */
.icon-btn {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  right: 12px;
  z-index: 40;
  width: 44px;
  height: 44px;
  border: 1px solid rgba(122, 139, 166, 0.4);
  border-radius: 10px;
  background: rgba(10, 14, 28, 0.6);
  color: var(--c-text);
  font-size: 20px;
  cursor: pointer;
  backdrop-filter: blur(4px);
  transition: border-color 0.15s, transform 0.1s;
}
.icon-btn:hover { border-color: var(--c-cyan); }
.icon-btn:active { transform: scale(0.92); }
.icon-btn.muted { opacity: 0.5; }

/* ---------- スクリーン共通 ---------- */
.screen {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  background: radial-gradient(ellipse at center, rgba(6, 7, 15, 0.55) 0%, rgba(6, 7, 15, 0.88) 100%);
  backdrop-filter: blur(2px);
  animation: screen-in 0.35s ease-out;
  padding: 20px;
  text-align: center;
}

@keyframes screen-in {
  from { opacity: 0; transform: scale(1.04); }
  to   { opacity: 1; transform: scale(1); }
}

/* ---------- タイトル ---------- */
.title-logo { line-height: 1.1; }

.title-jp {
  font-size: clamp(44px, 10vw, 92px);
  font-weight: 800;
  background: linear-gradient(180deg, #ffffff 15%, var(--c-cyan) 55%, #1a7fd4 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 0 24px rgba(46, 230, 255, 0.45));
  animation: logo-float 3.2s ease-in-out infinite;
}

@keyframes logo-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

.title-en {
  font-family: var(--font-num);
  font-size: clamp(15px, 3vw, 24px);
  font-weight: 700;
  letter-spacing: 0.55em;
  margin-left: 0.55em;
  color: var(--c-pink);
  text-shadow: 0 0 14px rgba(255, 77, 141, 0.6);
  margin-top: 8px;
}

.title-desc {
  font-size: clamp(14px, 2.6vw, 18px);
  color: var(--c-dim);
  line-height: 1.7;
}

.title-best {
  font-family: var(--font-num);
  font-size: clamp(18px, 3.4vw, 26px);
  font-weight: 700;
  color: var(--c-yellow);
  text-shadow: 0 0 14px rgba(255, 217, 61, 0.4);
}
.best-label {
  font-size: 0.72em;
  opacity: 0.8;
  margin-right: 10px;
  letter-spacing: 0.15em;
}
.best-unit { font-family: var(--font-jp); font-size: 0.6em; margin-left: 4px; }

/* ---------- ボタン ---------- */
.btn {
  font-family: var(--font-jp);
  font-weight: 700;
  font-size: clamp(16px, 3vw, 20px);
  padding: 14px 52px;
  border-radius: 999px;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.2s, filter 0.2s;
  letter-spacing: 0.08em;
}
.btn:active { transform: scale(0.94); }

.btn-primary {
  background: linear-gradient(135deg, var(--c-cyan) 0%, #1a7fd4 100%);
  color: #04121f;
  box-shadow: 0 0 24px rgba(46, 230, 255, 0.45), 0 4px 14px rgba(0, 0, 0, 0.5);
  animation: btn-pulse 1.8s ease-in-out infinite;
}
.btn-primary:hover { filter: brightness(1.15); }

@keyframes btn-pulse {
  0%, 100% { box-shadow: 0 0 20px rgba(46, 230, 255, 0.35), 0 4px 14px rgba(0,0,0,0.5); }
  50% { box-shadow: 0 0 34px rgba(46, 230, 255, 0.65), 0 4px 14px rgba(0,0,0,0.5); }
}

.btn-sub {
  background: rgba(20, 28, 50, 0.8);
  border-color: rgba(122, 139, 166, 0.5);
  color: var(--c-text);
  padding: 11px 34px;
  font-size: clamp(14px, 2.6vw, 17px);
}
.btn-sub:hover { border-color: var(--c-cyan); }

.controls-hint {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: clamp(11px, 2vw, 13px);
  color: var(--c-dim);
}

/* ---------- ランキング ---------- */
.ranking {
  list-style: none;
  font-family: var(--font-num);
  font-size: clamp(12px, 2.2vw, 15px);
  color: var(--c-dim);
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-height: 0;
  font-variant-numeric: tabular-nums;
}
.ranking li { display: flex; gap: 14px; justify-content: center; }
.ranking li:first-child { color: var(--c-yellow); }
.ranking .rank-no { width: 2.2em; text-align: right; opacity: 0.7; }

/* ---------- ゲームオーバー ---------- */
.gameover-title {
  font-family: var(--font-num);
  font-size: clamp(36px, 8vw, 68px);
  font-weight: 900;
  letter-spacing: 0.12em;
  color: var(--c-pink);
  text-shadow: 0 0 28px rgba(255, 77, 141, 0.6);
}

.new-record {
  font-family: var(--font-num);
  font-size: clamp(16px, 3.4vw, 24px);
  font-weight: 700;
  color: var(--c-yellow);
  text-shadow: 0 0 16px rgba(255, 217, 61, 0.7);
  animation: record-blink 0.7s ease-in-out infinite;
}
@keyframes record-blink {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.55; transform: scale(1.06); }
}

.result-time {
  font-family: var(--font-num);
  font-size: clamp(52px, 12vw, 104px);
  font-weight: 700;
  color: var(--c-text);
  text-shadow: 0 0 30px rgba(46, 230, 255, 0.5);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.result-unit { font-family: var(--font-jp); font-size: 0.32em; margin-left: 8px; color: var(--c-dim); }

.result-stats {
  display: flex;
  gap: clamp(20px, 5vw, 48px);
}
.stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
}
.stat-label { font-size: 12px; letter-spacing: 0.2em; color: var(--c-dim); }
.stat span:last-child { font-size: clamp(16px, 3.4vw, 24px); font-weight: 700; }

.gameover-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
}

/* ---------- ポーズ ---------- */
.pause-title {
  font-family: var(--font-num);
  font-size: clamp(34px, 7vw, 60px);
  font-weight: 900;
  letter-spacing: 0.2em;
  color: var(--c-cyan);
  text-shadow: 0 0 24px rgba(46, 230, 255, 0.5);
}
.pause-desc { color: var(--c-dim); }

/* ---------- WAVEアナウンス ---------- */
#wave-announce {
  position: absolute;
  top: 26%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  pointer-events: none;
  font-family: var(--font-num);
  font-weight: 900;
  font-size: clamp(28px, 6vw, 54px);
  letter-spacing: 0.14em;
  color: var(--c-yellow);
  text-shadow: 0 0 26px rgba(255, 217, 61, 0.65);
  white-space: nowrap;
  text-align: center;
  animation: wave-pop 2s ease-out forwards;
}
#wave-announce .wave-sub {
  display: block;
  font-family: var(--font-jp);
  font-weight: 800;
  font-size: 0.44em;
  letter-spacing: 0.1em;
  color: var(--c-pink);
  text-shadow: 0 0 16px rgba(255, 77, 141, 0.6);
  margin-top: 6px;
}

@keyframes wave-pop {
  0%   { opacity: 0; transform: translateX(-50%) scale(1.6); }
  12%  { opacity: 1; transform: translateX(-50%) scale(1); }
  80%  { opacity: 1; }
  100% { opacity: 0; transform: translateX(-50%) scale(0.92); }
}

/* ---------- タイトルフッター ---------- */
.title-footer {
  position: absolute;
  bottom: max(12px, env(safe-area-inset-bottom));
  left: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: clamp(11px, 2vw, 13px);
  color: var(--c-dim);
  text-align: center;
}
.footer-version { opacity: 0.85; }
.footer-copyright a {
  color: var(--c-cyan);
  text-decoration: none;
  transition: text-shadow 0.15s;
}
.footer-copyright a:hover {
  text-decoration: underline;
  text-shadow: 0 0 10px rgba(46, 230, 255, 0.6);
}

/* ---------- モバイル微調整 ---------- */
@media (max-height: 640px) {
  .screen { gap: 10px; }
  .controls-hint { display: none; }
}
/* 100秒を超えて時間の表示が広がると、狭い画面では GRAZE と重なるので1段下げる（js が #hud に hud-long を付ける） */
@media (max-width: 400px) {
  #hud.hud-long #hud-graze { top: calc(max(16px, env(safe-area-inset-top)) + 40px); }
}
/* 320x568 など幅も高さも小さい画面: タイトルのフッターが記録一覧（4〜5位）と重なり、
   結果画面では「GAME OVER」がサウンドボタンの下に隠れていた */
@media (max-width: 374px) and (max-height: 600px) {
  .title-footer { position: static; }
  .ranking li:nth-child(n+4) { display: none; }
  .gameover-title { font-size: 28px; }
}

/* ---------- 全国ランキング（SGRanking 共通モジュール） ---------- */
.sgr-hidden {
  display: none !important;
}

.sgr-overlay {
  position: fixed;
  inset: 0;
  z-index: 2147483000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  background: rgba(6, 7, 15, 0.72);
  backdrop-filter: blur(3px);
}

.sgr-panel {
  width: min(420px, 100%);
  max-height: min(80vh, 640px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: rgba(12, 17, 34, 0.96);
  color: var(--c-text);
  border: 1px solid rgba(46, 230, 255, 0.35);
  border-radius: 12px;
  padding: 20px 18px;
  box-shadow: 0 0 30px rgba(46, 230, 255, 0.18), 0 12px 40px rgba(0, 0, 0, 0.6);
}

.sgr-title {
  margin: 0;
  font-size: 20px;
  text-align: center;
  color: var(--c-text);
  text-shadow: 0 0 14px rgba(46, 230, 255, 0.45);
}

.sgr-tabs {
  display: flex;
  gap: 6px;
  justify-content: center;
}

.sgr-tab {
  border: 1px solid rgba(122, 139, 166, 0.5);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: bold;
  font-family: var(--font-jp);
  background: rgba(20, 28, 50, 0.8);
  color: var(--c-text);
  cursor: pointer;
}

.sgr-tab-active {
  background: linear-gradient(135deg, var(--c-cyan) 0%, #1a7fd4 100%);
  border-color: transparent;
  color: #04121f;
}

.sgr-register-msg {
  margin: 0 0 6px;
  font-size: 14px;
  font-weight: bold;
  text-align: center;
  color: var(--c-yellow);
  text-shadow: 0 0 12px rgba(255, 217, 61, 0.4);
}

.sgr-form {
  display: flex;
  gap: 8px;
}

.sgr-name {
  flex: 1;
  min-width: 0;
  font-size: 16px; /* iOSズーム防止のため16px以上 */
  font-family: var(--font-jp);
  padding: 8px 10px;
  border: 2px solid rgba(122, 139, 166, 0.5);
  border-radius: 8px;
  background: rgba(6, 7, 15, 0.8);
  color: var(--c-text);
  -webkit-user-select: text;
  user-select: text;
}

.sgr-name::placeholder {
  color: var(--c-dim);
}

.sgr-name:focus {
  outline: none;
  border-color: var(--c-cyan);
  box-shadow: 0 0 12px rgba(46, 230, 255, 0.35);
}

.sgr-submit {
  border: none;
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 15px;
  font-weight: bold;
  font-family: var(--font-jp);
  background: linear-gradient(135deg, var(--c-cyan) 0%, #1a7fd4 100%);
  color: #04121f;
  cursor: pointer;
}

.sgr-submit:hover {
  filter: brightness(1.15);
}

.sgr-submit:disabled {
  opacity: 0.5;
  cursor: default;
}

.sgr-error {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--c-pink);
}

.sgr-status {
  margin: 0;
  font-size: 13px;
  text-align: center;
  color: var(--c-dim);
}

.sgr-list {
  margin: 0;
  padding: 0;
  list-style: none;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  flex: 1;
}

.sgr-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.sgr-row:nth-child(even) {
  background: rgba(20, 28, 50, 0.7);
}

.sgr-row.sgr-row-me {
  background: linear-gradient(135deg, var(--c-cyan) 0%, #1a7fd4 100%);
  color: #04121f;
}

.sgr-rank {
  width: 2em;
  text-align: right;
  font-weight: bold;
  flex-shrink: 0;
}


.sgr-row-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sgr-row-score {
  font-weight: bold;
  font-family: var(--font-num);
  flex-shrink: 0;
}

.sgr-close {
  border: 1px solid rgba(122, 139, 166, 0.5);
  border-radius: 8px;
  padding: 10px;
  font-size: 14px;
  font-weight: bold;
  font-family: var(--font-jp);
  background: rgba(20, 28, 50, 0.8);
  color: var(--c-text);
  cursor: pointer;
}

.sgr-close:hover {
  border-color: var(--c-cyan);
}

.sgr-cta {
  margin: 10px 0 4px;
  text-align: center;
}

.sgr-cta-msg {
  margin: 0 0 6px;
  font-size: 14px;
  font-weight: bold;
  color: var(--c-yellow);
  text-shadow: 0 0 14px rgba(255, 217, 61, 0.5);
}

.sgr-cta-btn {
  border: none;
  border-radius: 999px;
  padding: 10px 22px;
  font-size: 15px;
  font-weight: bold;
  font-family: var(--font-jp);
  background: linear-gradient(135deg, var(--c-yellow) 0%, #ffb02e 100%);
  color: #221a04;
  cursor: pointer;
  box-shadow: 0 0 22px rgba(255, 217, 61, 0.45), 0 4px 14px rgba(0, 0, 0, 0.5);
}

.sgr-cta-btn:hover {
  filter: brightness(1.1);
}

.sgr-cta-link {
  border: none;
  background: none;
  padding: 6px;
  font-size: 13px;
  color: var(--c-cyan);
  text-decoration: underline;
  cursor: pointer;
}

/* ==========================================================================
   フッター固定バナー広告（スマホ表示時のみ / js/ad-banner.js が挿入する）
   --ad-h    : 広告そのものの高さ。広告なしのときは 0px
   --ad-space: レイアウトが空けるべき高さ（広告 + セーフエリア）
   ========================================================================== */
:root {
  --ad-h: 0px;
  --ad-space: 0px;
}
html.has-ad-banner {
  --ad-space: calc(var(--ad-h, 0px) + env(safe-area-inset-bottom, 0px));
}

.ad-banner {
  /* height は広告そのものの高さ。セーフエリアぶんの padding は外側に足す */
  box-sizing: content-box;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  /* ランキング・リザルト等の全画面オーバーレイ（2147483000）よりは下に置く */
  z-index: 2147482000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  height: var(--ad-h, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  overflow: hidden;
  background: rgba(14, 16, 20, 0.86);
  /* border ではなく inset shadow にして、枠線ぶん高さがずれないようにする */
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.14);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

.ad-banner__frame {
  display: block;
  width: 100%;
  height: var(--ad-h, 0px);
  border: 0;
  color-scheme: light;
}

@media print {
  .ad-banner { display: none; }
}
