/* =========================================================
 * hole（ホール） スタイル
 * ========================================================= */
:root {
  --font-jp: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Noto Sans JP", Meiryo, sans-serif;
  --font-num: "SF Mono", "Roboto Mono", Menlo, Consolas, monospace;
  --c-text: #1e2b38;
  --c-dim: #6b7a88;
  --c-accent: #2a8fd8;
  --c-accent-deep: #1c6fae;
  --c-orange: #f08c1e;
  --c-yellow: #e8a000;
  --c-red: #d64545;
  --c-panel: rgba(255, 255, 255, 0.94);
  --c-line: rgba(30, 43, 56, 0.14);
}

* { box-sizing: border-box; }

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

body {
  font-family: var(--font-jp);
  color: var(--c-text);
  background: #86b7d6;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  -webkit-text-size-adjust: 100%;
}

/* ===== レイアウト =====
   共通ヘッダー(--sgh-top)とフッター広告(--ad-space)のぶんだけ内側に収める */
#app {
  position: fixed;
  left: 0;
  right: 0;
  top: var(--sgh-top, 0px);
  bottom: var(--ad-space, 0px);
  display: flex;
  flex-direction: column;
}

/* ===== 上部バー =====
   ボタンは共通ヘッダーのメニューへ集約済みで、タイトルだけの帯は縦幅を圧迫するので隠す。
   h1 と共通ヘッダーが押す元ボタンは DOM に残す（見えなくするだけ） */
#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 {
  margin: 0;
  font-size: 17px;
  font-weight: 800;
  letter-spacing: 0.12em;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

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

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}

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

/* ===== ステージ ===== */
#stage {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

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

/* ===== バーチャルジョイスティック ===== */
#joy {
  position: fixed;
  width: 112px;
  height: 112px;
  margin: -56px 0 0 -56px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.55);
  background: rgba(255, 255, 255, 0.12);
  pointer-events: none;
  z-index: 30;
  display: none;
}
#joy.on { display: block; }

#joy-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.75);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  transform: translate(-50%, -50%);
}

/* ===== HUD ===== */
#hud {
  position: absolute;
  top: 8px;
  left: 10px;
  right: 10px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  pointer-events: none;
  z-index: 25;
}

#hud-left {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 88px;
}

#hud-level {
  font-size: 15px;
  font-weight: 800;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

#hud-gauge {
  width: 88px;
  height: 8px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.35);
  overflow: hidden;
}

#hud-gauge-fill {
  width: 100%;
  height: 100%;
  border-radius: 4px;
  background: linear-gradient(90deg, #ffd23e, #f08c1e);
  transform: scaleX(0);
  transform-origin: left center;
  transition: transform 0.25s ease-out;
}

#hud-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

#hud-time {
  font-family: var(--font-num);
  font-size: 26px;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 2px 5px rgba(0, 0, 0, 0.5);
  font-variant-numeric: tabular-nums;
}

.hud-time-warn {
  color: #ffde59 !important;
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.12); }
}

#hud-combo {
  font-size: 13px;
  font-weight: 800;
  color: #ffde59;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.55);
  opacity: 0;
  transition: opacity 0.2s;
}
#hud-combo.on { opacity: 1; }

#hud-right {
  min-width: 88px;
  text-align: right;
}

#hud-score {
  font-family: var(--font-num);
  font-size: 22px;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 2px 5px rgba(0, 0, 0, 0.5);
  font-variant-numeric: tabular-nums;
}

/* ===== 得点フローティング ===== */
#floats {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 24;
}

.float-pts {
  position: absolute;
  left: 0;
  top: 0;
  font-family: var(--font-num);
  font-size: 17px;
  font-weight: 800;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
  white-space: nowrap;
  will-change: transform, opacity;
}

.float-combo {
  color: #ffde59;
  font-size: 19px;
}

/* ===== トースト ===== */
#toast {
  position: absolute;
  top: 72px;
  left: 50%;
  transform: translate(-50%, -8px);
  padding: 8px 18px;
  border-radius: 999px;
  background: rgba(30, 43, 56, 0.88);
  color: #ffde59;
  font-size: 15px;
  font-weight: 800;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
  z-index: 40;
  white-space: nowrap;
}

#toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ===== 画面オーバーレイ共通 ===== */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 50;
}

.hidden { display: none !important; }

/* ===== タイトル画面 ===== */
#screen-title {
  background: linear-gradient(180deg, rgba(20, 34, 48, 0.25), rgba(20, 34, 48, 0.62));
  /* 高さが足りない画面（スマホ横向き等）では上下が切れないようスクロールさせる。
     中央寄せは .title-panel の margin: auto で行う（はみ出したときは上端から並ぶ）。
     上下の余白を 0 にしておくと、収まる画面では従来とまったく同じ位置になる */
  overflow-y: auto;
  padding-top: 0;
  padding-bottom: 0;
}

.title-panel {
  text-align: center;
  color: #fff;
  max-width: 340px;
  width: 100%;
  margin: auto;
  padding-bottom: 48px; /* 下部のフッター表記と重ならないように */
}

.title-hole {
  width: 120px;
  height: 58px;
  margin: 0 auto 6px;
  border-radius: 50%;
  background:
    radial-gradient(ellipse at 50% 42%, #05070a 0%, #10161d 55%, #2c231b 76%, rgba(44, 35, 27, 0) 78%);
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.45);
}

.title-en {
  margin: 0;
  font-size: 58px;
  font-weight: 900;
  letter-spacing: 0.14em;
  line-height: 1.1;
  text-shadow: 0 4px 14px rgba(0, 0, 0, 0.5);
}

.title-ja {
  margin: 2px 0 0;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.5em;
  text-indent: 0.5em;
  color: #cfe6f5;
}

.title-catch {
  margin: 14px 0 4px;
  font-size: 15px;
  font-weight: 700;
  color: #ffde59;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
}

#title-best {
  margin: 0 0 12px;
  font-size: 13px;
  color: #cfe6f5;
}

/* ===== ステージ選択 ===== */
.stage-select {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  margin: 0 0 14px;
}

.stage-chip {
  font-family: var(--font-jp);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  min-width: 52px;
  padding: 6px 6px 5px;
  font-size: 11px;
  font-weight: 800;
  line-height: 1.2;
  color: rgba(255, 255, 255, 0.85);
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 12px;
  cursor: pointer;
  transition: transform 0.1s, background 0.15s, border-color 0.15s;
}

.stage-chip .stage-emoji {
  font-size: 18px;
  line-height: 1.15;
}

.stage-chip:hover { background: rgba(255, 255, 255, 0.2); }
.stage-chip:active { transform: scale(0.94); }

.stage-chip.on {
  color: #fff;
  background: linear-gradient(135deg, rgba(245, 166, 35, 0.85), rgba(240, 116, 30, 0.85));
  border-color: #ffd28a;
  box-shadow: 0 2px 10px rgba(240, 116, 30, 0.4);
}

/* 高さの低い画面（320x568・スマホ横向き等）ではタイトルまわりを詰める。
   共通ヘッダー・上部バー・広告のぶん実際に使える高さはかなり低いので、600px 以下から詰める */
@media (max-height: 600px) {
  .title-hole { display: none; }
  .title-en { font-size: 40px; }
  .title-catch { margin: 6px 0 2px; }
  #title-best { margin-bottom: 8px; }
  .stage-select { margin-bottom: 10px; }
  .title-hint { margin-top: 10px; }
}

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

.title-sub-buttons {
  display: flex;
  gap: 10px;
}

.title-hint {
  margin: 18px 0 0;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.75);
}

/* ===== ボタン ===== */
.btn {
  font-family: var(--font-jp);
  font-weight: 800;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.1s, filter 0.15s;
}

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

.btn-primary {
  padding: 14px 40px;
  font-size: 18px;
  color: #fff;
  background: linear-gradient(135deg, #f5a623, #f0741e);
  box-shadow: 0 4px 14px rgba(240, 116, 30, 0.45);
}

.btn-primary:hover { filter: brightness(1.08); }

.btn-sub {
  padding: 10px 18px;
  font-size: 14px;
  color: #fff;
  background: rgba(255, 255, 255, 0.16);
  border: 1px solid rgba(255, 255, 255, 0.4);
}

.btn-sub:hover { background: rgba(255, 255, 255, 0.26); }

/* ===== リザルト画面 ===== */
#screen-result {
  background: rgba(20, 34, 48, 0.55);
}

.result-panel {
  width: min(360px, 100%);
  max-height: 100%;
  overflow-y: auto;
  background: var(--c-panel);
  border-radius: 18px;
  padding: 22px 20px;
  text-align: center;
  box-shadow: 0 16px 50px rgba(0, 0, 0, 0.4);
}

.result-title {
  margin: 0;
  font-size: 21px;
  font-weight: 900;
}

#result-new {
  margin: 8px 0 0;
  font-size: 14px;
  font-weight: 800;
  color: var(--c-orange);
  animation: pulse 1.2s infinite;
}

.result-score-row {
  margin: 8px 0 12px;
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
}

#result-score {
  font-size: 44px;
  font-weight: 800;
  color: var(--c-accent-deep);
}

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

.result-stats {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0 0 16px;
}

.rstat {
  display: flex;
  justify-content: space-between;
  padding: 7px 12px;
  border-radius: 8px;
  background: rgba(42, 143, 216, 0.08);
  font-size: 14px;
}

.rstat-label { color: var(--c-dim); }

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

.result-buttons {
  display: flex;
  gap: 10px;
  justify-content: center;
}

#screen-result .btn-sub {
  color: var(--c-text);
  background: rgba(30, 43, 56, 0.08);
  border: 1px solid var(--c-line);
}

/* ===== 一時停止・エラー ===== */
#screen-paused, #gl-error {
  background: rgba(20, 34, 48, 0.55);
  cursor: pointer;
}

.paused-panel {
  text-align: center;
  color: #fff;
  max-width: 320px;
}

.paused-title {
  margin: 0 0 8px;
  font-size: 22px;
  font-weight: 900;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
}

.paused-hint {
  margin: 0;
  font-size: 14px;
  color: #cfe6f5;
}

/* ===== 遊び方モーダル ===== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(6, 12, 18, 0.6);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}

.modal-box {
  width: min(400px, 100%);
  max-height: min(80vh, 620px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--c-panel);
  border-radius: 16px;
  padding: 20px 18px;
  box-shadow: 0 16px 50px rgba(0, 0, 0, 0.4);
  text-align: center;
}

.modal-title {
  margin: 0 0 12px;
  font-size: 19px;
  font-weight: 900;
}

.howto {
  margin: 0 0 16px;
  padding: 0 0 0 1.3em;
  text-align: left;
  font-size: 14px;
  line-height: 1.75;
}

.howto li { margin-bottom: 6px; }

.howto b { color: var(--c-accent-deep); }

/* ===== フッター ===== */
#footer {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 6px;
  text-align: center;
  font-size: 11px;
  line-height: 1.6;
  color: rgba(255, 255, 255, 0.85);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  pointer-events: none;
  z-index: 60;
}

#footer a {
  color: #ffde59;
  pointer-events: auto;
}

body.playing #footer { display: none; }

/* ===== 全国ランキング（共通モジュール sgr-*） ===== */
.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, 12, 18, 0.66);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}

.sgr-hidden { display: none !important; }

.sgr-panel {
  width: min(420px, 100%);
  max-height: min(80vh, 640px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--c-panel);
  color: var(--c-text);
  border-radius: 14px;
  padding: 20px 18px;
  box-shadow: 0 16px 50px rgba(0, 0, 0, 0.45);
}

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

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

.sgr-tab {
  border: 1px solid var(--c-line);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: bold;
  font-family: var(--font-jp);
  background: rgba(42, 143, 216, 0.08);
  color: var(--c-text);
  cursor: pointer;
}

.sgr-tab-active {
  background: linear-gradient(135deg, var(--c-accent), var(--c-accent-deep));
  border-color: transparent;
  color: #fff;
}

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

.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 var(--c-line);
  border-radius: 8px;
  background: #fff;
  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-accent);
  box-shadow: 0 0 8px rgba(42, 143, 216, 0.3);
}

.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-accent), var(--c-accent-deep));
  color: #fff;
  cursor: pointer;
}

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

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

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

.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(42, 143, 216, 0.07); }

.sgr-row.sgr-row-me {
  background: linear-gradient(135deg, var(--c-accent), var(--c-accent-deep));
  color: #fff;
}

.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 var(--c-line);
  border-radius: 8px;
  padding: 10px;
  font-size: 14px;
  font-weight: bold;
  font-family: var(--font-jp);
  background: rgba(42, 143, 216, 0.08);
  color: var(--c-text);
  cursor: pointer;
}

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

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

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

.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, #f5a623, #f0741e);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(240, 116, 30, 0.4);
}

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

.sgr-cta-link {
  border: none;
  border-radius: 999px;
  padding: 8px 18px;
  font-size: 13px;
  font-weight: bold;
  font-family: var(--font-jp);
  background: rgba(30, 43, 56, 0.08);
  border: 1px solid var(--c-line);
  color: var(--c-text);
  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; }
}
