/* 3D迷路 - Maze 3D */
:root {
  --bg: #141b2e;
  --bg2: #1d2742;
  --panel: rgba(20, 27, 46, 0.92);
  --text: #eef2ff;
  --sub: #9fb0d8;
  --accent: #4cd97b;
  --accent2: #ffcf5c;
  --primary: #3a86ff;
  --primary-hover: #2f6fd6;
  --secondary: #2a3654;
  --secondary-hover: #364469;
  --danger: #ff5c74;
}

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

html, body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  background: radial-gradient(120% 100% at 50% 0%, var(--bg2) 0%, var(--bg) 70%);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

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

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

#minimap {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 58px);
  right: calc(env(safe-area-inset-right, 0px) + 10px);
  width: 108px;
  height: 108px;
  border-radius: 10px;
  background: rgba(10, 14, 26, 0.55);
  border: 1px solid rgba(159, 176, 216, 0.35);
  display: none;
  pointer-events: none;
}
#minimap.visible { display: block; }

/* ---------- HUD ---------- */
.hud {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: calc(env(safe-area-inset-top, 0px) + 8px)
           calc(env(safe-area-inset-right, 0px) + 10px)
           0
           calc(env(safe-area-inset-left, 0px) + 12px);
  pointer-events: none;
}
.hud[hidden] { display: none; }

.hud-left {
  background: var(--panel);
  border: 1px solid rgba(159, 176, 216, 0.25);
  border-radius: 12px;
  padding: 8px 14px;
  line-height: 1.35;
}
.hud-stage {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--accent2);
}
.hud-time {
  font-size: 24px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.hud-total {
  font-size: 12px;
  color: var(--sub);
  font-variant-numeric: tabular-nums;
}

.hud-right {
  display: flex;
  gap: 8px;
  pointer-events: auto;
}

.icon-btn {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border: 1px solid rgba(159, 176, 216, 0.35);
  background: var(--panel);
  color: var(--text);
  font-size: 19px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:active { transform: scale(0.94); }

/* ---------- 画面共通 ---------- */
.screen {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  justify-content: center;
  background: rgba(12, 16, 30, 0.72);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  z-index: 10;
  touch-action: pan-y;
}
.screen[hidden] { display: none; }

.screen-inner {
  width: min(440px, 100%);
  margin: auto;
  padding: calc(env(safe-area-inset-top, 0px) + 28px) 20px
           calc(env(safe-area-inset-bottom, 0px) + 24px);
  text-align: center;
}

.title-sub {
  color: var(--sub);
  font-size: 13px;
  letter-spacing: 0.06em;
}

.title-logo {
  font-size: 52px;
  font-weight: 900;
  letter-spacing: 0.04em;
  margin: 6px 0 4px;
  background: linear-gradient(160deg, #7fd0ff 10%, #3a86ff 55%, #4cd97b 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 6px 30px rgba(58, 134, 255, 0.35);
}
.title-en {
  display: block;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.35em;
  color: var(--sub);
  -webkit-text-fill-color: var(--sub);
}

.title-desc {
  margin: 14px 0 18px;
  font-size: 15px;
  line-height: 1.7;
}

.best-box[hidden] { display: none; }
.best-box {
  display: inline-flex;
  flex-direction: column;
  gap: 2px;
  background: var(--panel);
  border: 1px solid rgba(255, 207, 92, 0.4);
  border-radius: 12px;
  padding: 10px 22px;
  margin-bottom: 18px;
}
.best-label { font-size: 11px; color: var(--sub); }
.best-value {
  font-size: 22px;
  font-weight: 800;
  color: var(--accent2);
  font-variant-numeric: tabular-nums;
}

.title-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
  margin: 8px 0 20px;
}

.btn {
  appearance: none;
  border: none;
  border-radius: 14px;
  font-family: inherit;
  font-size: 17px;
  font-weight: 700;
  padding: 14px 20px;
  width: min(300px, 100%);
  cursor: pointer;
  color: #fff;
  transition: transform 0.06s ease, background 0.15s ease;
}
.btn:active { transform: scale(0.97); }

.btn-primary {
  background: linear-gradient(160deg, #4d95ff, var(--primary));
  box-shadow: 0 6px 18px rgba(58, 134, 255, 0.4);
}
.btn-primary:hover { background: var(--primary-hover); }

.btn-secondary {
  background: var(--secondary);
  border: 1px solid rgba(159, 176, 216, 0.3);
}
.btn-secondary:hover { background: var(--secondary-hover); }

.howto {
  text-align: left;
  background: var(--panel);
  border: 1px solid rgba(159, 176, 216, 0.25);
  border-radius: 12px;
  padding: 12px 16px;
  margin: 0 auto 20px;
  max-width: 360px;
  font-size: 13px;
  color: var(--sub);
}
.howto summary {
  cursor: pointer;
  font-weight: 700;
  color: var(--text);
  font-size: 14px;
}
.howto ul {
  margin: 10px 0 4px;
  padding-left: 18px;
  line-height: 1.8;
}

.footer-credits {
  font-size: 11px;
  color: var(--sub);
  line-height: 1.8;
}
.footer-credits a {
  color: var(--sub);
  text-decoration: underline;
}

/* ---------- バナー（READY GO / CLEAR） ---------- */
.banner {
  position: absolute;
  left: 0; right: 0;
  top: 42%;
  text-align: center;
  pointer-events: none;
  z-index: 5;
}
.banner[hidden] { display: none; }
.banner span {
  display: inline-block;
  font-size: clamp(34px, 9vw, 56px);
  font-weight: 900;
  letter-spacing: 0.12em;
  color: #fff;
  text-shadow: 0 4px 24px rgba(0, 0, 0, 0.6), 0 0 40px rgba(76, 217, 123, 0.5);
  animation: banner-pop 0.35s ease;
}
@keyframes banner-pop {
  from { transform: scale(0.6); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}

/* ---------- オーバーレイ画面 ---------- */
.overlay-title {
  font-size: 30px;
  font-weight: 900;
  margin-bottom: 16px;
}

.result-new-best {
  color: var(--accent2);
  font-weight: 800;
  font-size: 17px;
  margin-bottom: 10px;
  animation: banner-pop 0.4s ease;
}

.result-total {
  display: inline-flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid rgba(76, 217, 123, 0.45);
  border-radius: 14px;
  padding: 12px 30px;
  margin-bottom: 14px;
}
.result-total-label { font-size: 12px; color: var(--sub); }
.result-total-value {
  font-size: 34px;
  font-weight: 900;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.result-stages {
  list-style: none;
  max-width: 280px;
  margin: 0 auto 18px;
  font-size: 14px;
  color: var(--sub);
}
.result-stages li {
  display: flex;
  justify-content: space-between;
  padding: 4px 8px;
  border-bottom: 1px dashed rgba(159, 176, 216, 0.25);
  font-variant-numeric: tabular-nums;
}
.result-stages li strong { color: var(--text); font-weight: 700; }

@media (max-height: 640px) {
  .title-logo { font-size: 40px; }
  .title-desc { margin: 8px 0 12px; }
  .screen-inner { padding-top: 14px; }
}

/* ---------- 全国ランキング（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(10, 14, 26, 0.75);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}

.sgr-panel {
  width: min(420px, 100%);
  max-height: min(80vh, 640px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #1b2440;
  color: var(--text);
  border: 1px solid rgba(255, 207, 92, 0.4);
  border-radius: 14px;
  padding: 20px 18px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
}

.sgr-title {
  margin: 0;
  font-size: 20px;
  text-align: center;
}

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

.sgr-tab {
  border: 1px solid rgba(159, 176, 216, 0.5);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: bold;
  font-family: inherit;
  background: var(--secondary);
  color: var(--text);
  cursor: pointer;
}
.sgr-tab-active {
  background: var(--primary);
  border-color: transparent;
  color: #fff;
}

.sgr-register-msg {
  margin: 0 0 6px;
  font-size: 14px;
  font-weight: bold;
  text-align: center;
  color: var(--accent2);
}

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

.sgr-name {
  flex: 1;
  min-width: 0;
  font-size: 16px; /* iOSズーム防止のため16px以上 */
  font-family: inherit;
  padding: 8px 10px;
  border: 2px solid rgba(159, 176, 216, 0.5);
  border-radius: 8px;
  background: rgba(12, 16, 30, 0.8);
  color: var(--text);
  -webkit-user-select: text;
  user-select: text;
}
.sgr-name::placeholder { color: var(--sub); }
.sgr-name:focus {
  outline: none;
  border-color: var(--primary);
}

.sgr-submit {
  border: none;
  border-radius: 8px;
  padding: 8px 18px;
  font-size: 14px;
  font-weight: bold;
  font-family: inherit;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  transition: filter 0.15s, transform 0.1s;
}
.sgr-submit:hover { filter: brightness(1.12); }
.sgr-submit:active { transform: scale(0.95); }
.sgr-submit:disabled { opacity: 0.5; cursor: default; }

.sgr-error {
  margin: 6px 0 0;
  font-size: 12px;
  text-align: center;
  color: var(--danger);
}

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

.sgr-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  min-height: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-variant-numeric: tabular-nums;
}

.sgr-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 14px;
}
.sgr-row:nth-child(even) { background: rgba(159, 176, 216, 0.08); }

.sgr-row-me {
  background: rgba(255, 207, 92, 0.14) !important;
  box-shadow: inset 0 0 0 1px rgba(255, 207, 92, 0.5);
}

.sgr-rank {
  width: 2em;
  text-align: center;
  font-weight: 700;
  color: var(--sub);
  flex: none;
}
.sgr-rank-top1, .sgr-rank-top2, .sgr-rank-top3 { font-size: 16px; }

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

.sgr-row-score {
  font-weight: 700;
  color: var(--accent);
  flex: none;
}

.sgr-close {
  border: 1px solid rgba(159, 176, 216, 0.5);
  border-radius: 999px;
  padding: 10px 0;
  font-size: 14px;
  font-weight: bold;
  font-family: inherit;
  background: var(--secondary);
  color: var(--text);
  cursor: pointer;
}
.sgr-close:hover { background: var(--secondary-hover); }

/* 結果画面に差し込む登録CTA */
.sgr-cta {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  margin-bottom: 14px;
}

.sgr-cta-msg {
  margin: 0;
  font-size: 15px;
  font-weight: bold;
  color: var(--accent2);
}

.sgr-cta-btn {
  border: none;
  border-radius: 999px;
  padding: 12px 36px;
  font-size: 16px;
  font-weight: bold;
  font-family: inherit;
  background: linear-gradient(135deg, var(--accent2) 0%, #ff9f43 100%);
  color: #3a2400;
  cursor: pointer;
  box-shadow: 0 0 20px rgba(255, 207, 92, 0.35);
  transition: filter 0.15s, transform 0.1s;
}
.sgr-cta-btn:hover { filter: brightness(1.1); }
.sgr-cta-btn:active { transform: scale(0.95); }

.sgr-cta-link {
  border: none;
  background: none;
  font-size: 13px;
  font-family: inherit;
  color: #7fd0ff;
  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; }
}
