/* フォールショット - Fall Shot */

:root {
  --color-bg: #151b26;
  --color-panel: #1e2735;
  --color-cell: #2a3547;
  --color-board: #3a475e;
  --color-text: #e8edf5;
  --color-text-dim: #93a1b8;
  --color-text-light: #ffffff;
  --color-accent: #ffb02e;
  --color-accent-hover: #ffc35c;
  --color-danger: #ff5252;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  height: 100%;
}

body {
  background: var(--color-bg);
  color: var(--color-text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Kaku Gothic ProN", "Hiragino Sans", Meiryo, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  touch-action: manipulation;
}

.hidden {
  display: none !important;
}

#app {
  display: flex;
  flex-direction: column;
  align-items: center;
  height: calc(100vh - var(--sgh-top, 0px) - var(--ad-space, 0px));
  height: calc(100dvh - var(--sgh-top, 0px) - var(--ad-space, 0px));
  max-width: 480px;
  margin: 0 auto;
  padding: 8px 10px calc(6px + var(--safe-bottom));
  gap: 6px;
}

/* ---------- ヘッダー ---------- */

/* ボタンは共通ヘッダーのメニューへ集約済みで、タイトルだけの帯は縦幅を圧迫するので隠す。
   h1 と共通ヘッダーが押す元ボタンは DOM に残す（見えなくするだけ。#app の flex の流れからも外れる） */
#topbar {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

#logo {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 0.06em;
  background: linear-gradient(180deg, #ffd67a, #ffb02e);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

#topbar-buttons {
  display: flex;
  gap: 8px;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 10px;
  background: var(--color-cell);
  color: var(--color-text);
  font-size: 17px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:active {
  transform: scale(0.94);
}

/* ---------- HUD ---------- */

#hud {
  width: 100%;
  display: flex;
  gap: 6px;
}

.hud-box {
  flex: 1;
  background: var(--color-panel);
  border-radius: 10px;
  padding: 5px 4px;
  text-align: center;
  min-width: 0;
}

.hud-box.hud-main {
  flex: 1.4;
}

.hud-label {
  display: block;
  font-size: 10px;
  color: var(--color-text-dim);
  letter-spacing: 0.08em;
}

.hud-value {
  display: block;
  font-size: 17px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hud-main .hud-value {
  color: var(--color-accent);
}

/* ---------- ゲーム画面 ---------- */

#game-wrap {
  position: relative;
  width: 100%;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

#game {
  display: block;
  border-radius: 12px;
  background: #10151f;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#btn-speed {
  position: absolute;
  right: 8px;
  bottom: 8px;
  border: none;
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 800;
  background: rgba(255, 176, 46, 0.9);
  color: #2a1c00;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
}

#btn-speed:active {
  transform: scale(0.94);
}

/* ---------- オーバーレイ共通 ---------- */

.overlay {
  position: fixed;
  inset: 0;
  /* 共通ヘッダーとフッター広告の下にもぐり込まないよう、そのぶんを除いた範囲に出す */
  top: var(--sgh-top, 0px);
  bottom: var(--ad-space, 0px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  padding-bottom: calc(16px + var(--safe-bottom));
  background: rgba(8, 11, 18, 0.78);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}

.overlay-box {
  width: min(360px, 100%);
  /* 背の低い画面（360x584 など）では、スタート画面の遊び方が長くて
     「ゲームスタート」ボタンが画面の外に出ていた（箱ごとスクロールしないと届かない）。
     箱は見えている範囲に収め、長い遊び方（.howto）だけを中でスクロールさせて、ボタンは常に見せる */
  max-height: 100%;
  overflow-y: auto;
  background: var(--color-panel);
  border: 1px solid var(--color-board);
  border-radius: 16px;
  padding: 22px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: center;
  box-shadow: 0 16px 50px rgba(0, 0, 0, 0.5);
}

.start-title {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: 0.06em;
  background: linear-gradient(180deg, #ffd67a, #ffb02e);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.start-sub {
  font-size: 13px;
  color: var(--color-text-dim);
  letter-spacing: 0.3em;
  margin-top: -8px;
}

.overlay-box > * { flex-shrink: 0; }

.howto {
  flex: 0 1 auto;
  min-height: 92px;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  list-style: none;
  text-align: left;
  font-size: 13px;
  line-height: 1.55;
  display: flex;
  flex-direction: column;
  gap: 7px;
  background: var(--color-bg);
  border-radius: 10px;
  padding: 12px 14px;
}

.start-best {
  font-size: 14px;
  color: var(--color-text-dim);
}

.start-best span {
  color: var(--color-accent);
  font-weight: 800;
  font-size: 16px;
}

.overlay-title {
  font-size: 24px;
  font-weight: 800;
}

.result-new {
  color: var(--color-accent);
  font-weight: 800;
  font-size: 14px;
  animation: pulse-glow 1.2s ease-in-out infinite;
}

@keyframes pulse-glow {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

#result-score-row {
  font-size: 44px;
  font-weight: 800;
  color: var(--color-accent);
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.result-unit {
  font-size: 18px;
  margin-left: 4px;
  color: var(--color-text-dim);
}

#result-stats {
  display: flex;
  justify-content: center;
  gap: 8px;
}

.rstat {
  flex: 1;
  background: var(--color-bg);
  border-radius: 10px;
  padding: 8px 4px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.rstat-label {
  font-size: 10px;
  color: var(--color-text-dim);
}

.rstat span:last-child {
  font-size: 17px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.btn {
  border: none;
  border-radius: 12px;
  padding: 13px 16px;
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: linear-gradient(180deg, #ffc35c, #ffa41c);
  color: #2a1c00;
  box-shadow: 0 4px 14px rgba(255, 176, 46, 0.35);
}

.btn-sub {
  background: var(--color-cell);
  color: var(--color-text);
  font-size: 14px;
  padding: 11px 16px;
}

/* ---------- フッター ---------- */

#footer {
  width: 100%;
  text-align: center;
  font-size: 10px;
  color: var(--color-text-dim);
  line-height: 1.5;
}

#footer a {
  color: var(--color-text-dim);
}

/* ---------- 全国ランキング（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 + var(--safe-bottom));
  background: rgba(8, 11, 18, 0.7);
}

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

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

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

.sgr-tab {
  border: none;
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: bold;
  background: var(--color-cell);
  color: var(--color-text);
  cursor: pointer;
}

.sgr-tab-active {
  background: var(--color-accent);
  color: #2a1c00;
}

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

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

.sgr-name {
  flex: 1;
  min-width: 0;
  font-size: 16px;
  padding: 8px 10px;
  border: 2px solid var(--color-board);
  border-radius: 8px;
  background: var(--color-bg);
  color: var(--color-text);
}

.sgr-name:focus {
  outline: none;
  border-color: var(--color-accent);
}

.sgr-submit {
  border: none;
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 15px;
  font-weight: bold;
  background: var(--color-accent);
  color: #2a1c00;
  cursor: pointer;
}

.sgr-submit:hover {
  background: var(--color-accent-hover);
}

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

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

.sgr-status {
  margin: 0;
  font-size: 13px;
  text-align: center;
  color: var(--color-text-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;
}

.sgr-row:nth-child(even) {
  background: var(--color-cell);
}

.sgr-row.sgr-row-me {
  background: var(--color-accent);
  color: #2a1c00;
}

.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;
  flex-shrink: 0;
}

.sgr-close {
  border: none;
  border-radius: 8px;
  padding: 10px;
  font-size: 14px;
  font-weight: bold;
  background: var(--color-cell);
  color: var(--color-text);
  cursor: pointer;
}

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

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

.sgr-cta-btn {
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 15px;
  font-weight: bold;
  background: var(--color-accent);
  color: #2a1c00;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(255, 176, 46, 0.4);
}

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

/* ---------- 横長画面（PC等） ---------- */

@media (min-width: 700px) and (min-height: 700px) {
  #logo { font-size: 24px; }
  .hud-value { font-size: 20px; }
  #footer { font-size: 11px; }
}

/* ==========================================================================
   フッター固定バナー広告（スマホ表示時のみ / 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; }
}
