* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: linear-gradient(160deg, #fdf6e3 0%, #f0dfc0 100%);
  color: #3d2f1e;
  user-select: none;
  -webkit-user-select: none;
  overflow: hidden;
}

#app {
  max-width: 480px;
  /* 共通ヘッダー（--sgh-top は sg-header.css が body の padding-top として確保）と
     広告（--ad-space）のぶんだけ縮める */
  height: calc(100vh - var(--sgh-top, 0px) - var(--ad-space, 0px));
  height: calc(100dvh - var(--sgh-top, 0px) - var(--ad-space, 0px));
  margin: 0 auto;
  padding: 8px 10px 8px;
  padding-left: calc(10px + env(safe-area-inset-left, 0px));
  padding-right: calc(10px + env(safe-area-inset-right, 0px));
  display: flex;
  flex-direction: column;
}

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
  flex-shrink: 0;
}
/* 数字の桁が増えて入りきらないときは、右端の「ベスト」が切れないようタイトルの側を省略する */
h1 { font-size: 18px; white-space: nowrap; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.stats { display: flex; gap: 6px; font-size: 11px; flex-shrink: 0; }
.stat {
  background: #fff8;
  border-radius: 8px;
  padding: 3px 8px;
  white-space: nowrap;
}
.stat span { font-weight: bold; font-size: 13px; }
.top-controls { display: flex; gap: 4px; }
.btn.mini {
  padding: 5px 8px;
  font-size: 11px;
  border-radius: 8px;
  box-shadow: 0 2px 0 #b25a20;
  white-space: nowrap;
}

#stage {
  flex: 1;
  min-height: 0;
  position: relative;
}
#game {
  width: 100%;
  height: 100%;
  display: block;
  /* 横向きなど高さの低い画面では game.js が幅を詰めるので中央に置く */
  margin: 0 auto;
  border-radius: 14px;
  touch-action: none;
  box-shadow: 0 4px 14px #0002;
}

/* オーバーレイ */
.overlay {
  position: fixed;
  inset: 0;
  top: var(--sgh-top, 0px);
  bottom: var(--ad-space, 0px);
  background: #0008;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 10;
}
.overlay.hidden { display: none; }
/* 結果画面の表示中に共通ヘッダーから開いても、結果画面の上に出す */
#overlay-howto { z-index: 11; }
.panel {
  background: #fff;
  border-radius: 16px;
  padding: 24px;
  max-width: 400px;
  width: 100%;
  max-height: 100%;
  overflow-y: auto;
  text-align: center;
}
.panel h2 { margin-bottom: 12px; }
.rules {
  font-size: 14px;
  line-height: 1.9;
  margin-bottom: 16px;
}
.howto-list {
  text-align: left;
  font-size: 13px;
  line-height: 1.8;
  margin: 0 0 16px;
  padding-left: 20px;
}
.howto-list li { margin-bottom: 6px; }
.result {
  font-size: 15px;
  line-height: 2;
  margin-bottom: 16px;
}
.result b { font-size: 20px; color: #e07b39; }

.btn {
  border: none;
  border-radius: 10px;
  font-weight: bold;
  cursor: pointer;
  transition: transform .1s;
  background: #e07b39;
  color: #fff;
  box-shadow: 0 3px 0 #b25a20;
}
.btn:active { transform: scale(.96); }
.btn.big { width: 100%; padding: 14px; font-size: 17px; }

.btn.ghost {
  width: 100%;
  margin-top: 10px;
  padding: 11px;
  font-size: 14px;
  background: #fff;
  color: #b25a20;
  border: 2px solid #e0a06a;
  box-shadow: none;
}

.credits {
  margin-top: 16px;
  font-size: 11px;
  line-height: 1.8;
  color: #8a7c66;
}
.credits a { color: #b25a20; }

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

.sgr-overlay {
  position: fixed;
  inset: 0;
  top: var(--sgh-top, 0px);
  z-index: 2147483000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  background: #0008;
  backdrop-filter: blur(3px);
}

.sgr-panel {
  width: min(420px, 100%);
  max-height: min(80vh, 640px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #fff;
  color: #3d2f1e;
  border-radius: 16px;
  padding: 20px 18px;
  box-shadow: 0 12px 40px #0006;
}

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

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

.sgr-tab {
  border: 1px solid #d8c9a3;
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: bold;
  background: #faf3e0;
  color: #3d2f1e;
  cursor: pointer;
}

.sgr-tab-active {
  background: #e07b39;
  border-color: transparent;
  color: #fff;
}

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

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

.sgr-name {
  flex: 1;
  min-width: 0;
  font-size: 16px; /* iOSズーム防止のため16px以上 */
  padding: 8px 10px;
  border: 2px solid #d8c9a3;
  border-radius: 8px;
  background: #fffdf7;
  color: #3d2f1e;
  -webkit-user-select: text;
  user-select: text;
}
.sgr-name::placeholder { color: #b3a689; }
.sgr-name:focus {
  outline: none;
  border-color: #e07b39;
}

.sgr-submit {
  border: none;
  border-radius: 8px;
  padding: 8px 18px;
  font-size: 14px;
  font-weight: bold;
  background: #e07b39;
  color: #fff;
  cursor: pointer;
  transition: filter .15s, transform .1s;
}
.sgr-submit:hover { filter: brightness(1.08); }
.sgr-submit:active { transform: scale(.95); }
.sgr-submit:disabled { opacity: .5; cursor: default; }

.sgr-error {
  margin: 6px 0 0;
  font-size: 12px;
  text-align: center;
  color: #c62828;
}

.sgr-status {
  margin: 0;
  font-size: 13px;
  text-align: center;
  color: #8a7c66;
}

.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: #f7f0dd; }

.sgr-row-me {
  background: #fce8d5 !important;
  box-shadow: inset 0 0 0 1px #e07b39;
}

.sgr-rank {
  width: 2em;
  text-align: center;
  font-weight: 700;
  color: #8a7c66;
  flex: none;
}
.sgr-rank-top1, .sgr-rank-top2, .sgr-rank-top3 { font-size: 16px; color: #b8860b; }

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

.sgr-row-score {
  font-weight: 700;
  color: #b25a20;
  flex: none;
}

.sgr-close {
  border: 1px solid #d8c9a3;
  border-radius: 999px;
  padding: 10px 0;
  font-size: 14px;
  font-weight: bold;
  background: #faf3e0;
  color: #3d2f1e;
  cursor: pointer;
  transition: border-color .15s;
}
.sgr-close:hover { border-color: #e07b39; }

/* ゲームオーバー画面に差し込む登録CTA */
.sgr-cta {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  margin-bottom: 12px;
}

.sgr-cta-msg {
  margin: 0;
  font-size: 15px;
  font-weight: bold;
  color: #e07b39;
  animation: sgr-blink .9s ease-in-out infinite;
}
@keyframes sgr-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: .55; }
}

.sgr-cta-btn {
  border: none;
  border-radius: 999px;
  padding: 12px 36px;
  font-size: 16px;
  font-weight: bold;
  background: #e07b39;
  color: #fff;
  box-shadow: 0 3px 0 #b25a20;
  cursor: pointer;
  transition: transform .1s;
}
.sgr-cta-btn:active { transform: scale(.96); }

.sgr-cta-link {
  border: none;
  background: none;
  font-size: 13px;
  color: #b25a20;
  text-decoration: underline;
  cursor: pointer;
  padding: 4px;
}

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