/* ===== Runner Game 1 共通スタイル ===== */
:root {
  --g-bg: #0f172a;
  --g-panel: #1e293b;
  --g-text: #f1f5f9;
  --g-muted: #94a3b8;
  --g-accent: #38bdf8;
  --g-accent-dark: #0ea5e9;
  --g-line: #334155;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--g-bg);
  color: var(--g-text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

.game-wrap {
  width: 100%;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  /* 中央寄せだと縦に長い時に上下が見切れるので上揃えにする */
  justify-content: flex-start;
  gap: 12px;
  /* セーフエリア（ノッチ/ホームバー）を考慮 */
  padding:
    calc(12px + env(safe-area-inset-top))
    calc(12px + env(safe-area-inset-right))
    calc(16px + env(safe-area-inset-bottom))
    calc(12px + env(safe-area-inset-left));
}

.game-title {
  font-weight: 900;
  font-size: clamp(18px, 4vw, 26px);
  letter-spacing: 0.02em;
  margin: 0;
  text-align: center;
}

.game-sub {
  margin: 0;
  color: var(--g-muted);
  font-size: 13px;
  text-align: center;
  line-height: 1.6;
}

/* ===== キャンバスステージ ===== */
.stage {
  position: relative;
  width: min(960px, 100%);
  aspect-ratio: 16 / 9;
  /* デスクトップ上限。スマホ側はメディアクエリで調整 */
  max-height: 60dvh;
  border-radius: 14px;
  overflow: hidden;
  background: linear-gradient(180deg, #1e3a8a 0%, #0f172a 100%);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  touch-action: none;          /* スマホのスクロール/ズーム抑止 */
  user-select: none;
  -webkit-user-select: none;
}

.stage canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* ===== HUD（スコア表示） ===== */
.hud {
  position: absolute;
  top: 10px;
  left: 12px;
  right: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  pointer-events: none;
  font-weight: 800;
  font-size: clamp(13px, 2.6vw, 18px);
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.6);
  z-index: 2;
}
.hud .hud-coin { color: #fde047; }

/* ===== オーバーレイ（開始 / ゲームオーバー） ===== */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: rgba(15, 23, 42, 0.78);
  backdrop-filter: blur(4px);
  text-align: center;
  padding: 18px;
  /* 枠より内容が縦に長い場合でも見切れないようスクロール可能に */
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  z-index: 3;
}
.overlay.hidden { display: none; }

.overlay h2 {
  margin: 0;
  font-size: clamp(20px, 5.5vw, 38px);
  font-weight: 900;
}
.overlay p {
  margin: 0;
  color: var(--g-muted);
  font-size: 14px;
  line-height: 1.7;
  max-width: 460px;
}
.overlay .score-line { color: var(--g-text); font-size: 16px; font-weight: 700; }

/* 開始オーバーレイ説明文の出し分け（既定=PC、タッチ端末=スマホ） */
.ov-desc-pc { display: block; }
.ov-desc-sp { display: none; }
@media (hover: none) and (pointer: coarse) {
  .ov-desc-pc { display: none; }
  .ov-desc-sp { display: block; }
}

.btn {
  appearance: none;
  border: none;
  cursor: pointer;
  padding: 14px 30px;
  border-radius: 999px;
  background: var(--g-accent);
  color: #07223a;
  font-weight: 900;
  font-size: 16px;
  letter-spacing: 0.03em;
  transition: transform 0.08s ease, background 0.2s ease;
  flex-shrink: 0;
}
.btn:hover { background: var(--g-accent-dark); }
.btn:active { transform: scale(0.96); }

/* ===== モバイル操作ボタン ===== */
.touch-controls {
  display: none;
  width: min(960px, 100%);
  gap: 12px;
}
.touch-controls .tbtn {
  flex: 1;
  appearance: none;
  border: 1px solid var(--g-line);
  background: var(--g-panel);
  color: var(--g-text);
  border-radius: 12px;
  padding: 16px 8px;
  font-weight: 800;
  font-size: 15px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
.touch-controls .tbtn:active { background: #0b1220; transform: scale(0.97); }
.touch-controls .tbtn small { display: block; color: var(--g-muted); font-weight: 600; font-size: 11px; margin-top: 4px; }

/* タッチ端末のみ表示 */
@media (hover: none) and (pointer: coarse) {
  .touch-controls { display: flex; }
}

.back-link {
  color: var(--g-muted);
  font-size: 13px;
  text-decoration: underline;
}
.back-link:hover { color: var(--g-text); }

/* ===== 操作方法の常時表示 ===== */
.controls-guide {
  width: min(960px, 100%);
  background: var(--g-panel);
  border: 1px solid var(--g-line);
  border-radius: 12px;
  padding: 14px 18px;
}
.controls-guide h3 {
  margin: 0 0 10px;
  font-size: 14px;
  font-weight: 800;
  color: var(--g-accent);
  letter-spacing: 0.04em;
}
.controls-guide dl {
  margin: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 14px;
  align-items: baseline;
}
.controls-guide dt {
  font-weight: 800;
  font-size: 13px;
  color: var(--g-text);
  white-space: nowrap;
}
.controls-guide dd {
  margin: 0;
  font-size: 13px;
  color: var(--g-muted);
  line-height: 1.5;
}

/* ===== スマホ最適化（縦長画面の見切れ対策） ===== */
@media (max-width: 640px) {
  .game-wrap { gap: 10px; }

  /* 補足文は長いので折りたたみ気味に圧縮 */
  .game-sub {
    font-size: 12px;
    line-height: 1.5;
  }

  /* ステージは画面に収まる範囲で。16:9を保ちつつ高さ上限を抑える */
  .stage { max-height: 46dvh; }

  /* 開始オーバーレイの説明文をスマホでは短くまとめる */
  .overlay { padding: 14px; gap: 12px; }
  .overlay p { font-size: 13px; line-height: 1.55; }

  /* 操作ボタンは指で押しやすいサイズに */
  .touch-controls .tbtn { padding: 14px 6px; font-size: 14px; }
}

@media (max-width: 520px) {
  .controls-guide dl { grid-template-columns: 1fr; gap: 2px 0; }
  .controls-guide dt { margin-top: 6px; }
}

/* 横向き（ランドスケープ）のスマホ：縦が短いので更に詰める */
@media (max-height: 480px) and (orientation: landscape) {
  .game-sub { display: none; }            /* 縦の余白確保のため非表示 */
  .stage { max-height: 78dvh; }
  .overlay p { font-size: 12px; line-height: 1.5; }
}


/* ===== ゲーム説明 ===== */
.game-info {
  width: min(960px, 100%);
  background: var(--g-panel);
  border: 1px solid var(--g-line);
  border-radius: 12px;
  padding: 14px 18px;
}
.game-info h3 {
  margin: 0 0 8px;
  font-size: 14px;
  color: var(--g-accent);
}
.game-info p {
  margin: 0 0 8px;
  color: var(--g-muted);
  font-size: 13px;
  line-height: 1.7;
}
.game-info p:last-child { margin-bottom: 0; }
