/* 3Dゴルフ - 3D Golf */
:root {
  --bg: #0d2419;
  --bg2: #16412c;
  --panel: rgba(11, 32, 22, 0.92);
  --text: #eef7f0;
  --sub: #9fc4ad;
  --accent: #7ee6a0;
  --accent2: #ffd166;
  --primary: #2fa96b;
  --primary-hover: #268a58;
  --secondary: #23422f;
  --secondary-hover: #2e5540;
  --danger: #ff6b7a;
}

* { 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, "Hiragino Kaku Gothic ProN", "Hiragino Sans", sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.nowrap { white-space: nowrap; }

.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) + 96px);
  right: calc(env(safe-area-inset-right, 0px) + 10px);
  width: 110px;
  height: 110px;
  border-radius: 10px;
  background: rgba(8, 24, 16, 0.55);
  border: 1px solid rgba(159, 196, 173, 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, 196, 173, 0.25);
  border-radius: 12px;
  padding: 8px 14px;
  line-height: 1.3;
}
.hud-hole {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--accent2);
}
.hud-stroke {
  font-size: 26px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.hud-unit {
  font-size: 13px;
  font-weight: 700;
  margin-left: 2px;
  color: var(--sub);
}
.hud-sub {
  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, 196, 173, 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); }

/* ---------- 視点操作 ---------- */
.cam-controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 12px);
  display: flex;
  justify-content: center;
  gap: 8px;
  z-index: 4;
}
.cam-controls[hidden] { display: none; }

.cam-btn {
  min-width: 52px;
  height: 42px;
  padding: 0 12px;
  border-radius: 12px;
  border: 1px solid rgba(159, 196, 173, 0.35);
  background: var(--panel);
  color: var(--text);
  font-family: inherit;
  font-size: 17px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.cam-btn:active { transform: scale(0.94); }
.cam-btn-wide { font-size: 14px; }

/* ---------- 操作ヒント ---------- */
.hint {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom, 0px) + 66px);
  padding: 7px 16px;
  border-radius: 999px;
  background: rgba(11, 32, 22, 0.82);
  border: 1px solid rgba(159, 196, 173, 0.3);
  color: var(--text);
  font-size: 13px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 4;
  animation: hint-in 0.4s ease;
}
.hint[hidden] { display: none; }
.hint strong { color: var(--accent); }
@keyframes hint-in {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

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

/* タイトルは背景に流れるコースを見せたいので上側を明るく残す */
#screen-title {
  background: linear-gradient(180deg, rgba(8, 22, 15, 0.34) 0%, rgba(8, 22, 15, 0.66) 42%, rgba(8, 22, 15, 0.82) 100%);
}

.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, #d9ffe6 10%, #7ee6a0 50%, #ffd166 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 6px 30px rgba(126, 230, 160, 0.3);
}
.title-en {
  display: block;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.3em;
  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, 209, 102, 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, #43c483, var(--primary));
  box-shadow: 0 6px 18px rgba(47, 169, 107, 0.4);
}
.btn-primary:hover { background: var(--primary-hover); }

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

.howto {
  text-align: left;
  background: var(--panel);
  border: 1px solid rgba(159, 196, 173, 0.25);
  border-radius: 12px;
  padding: 12px 16px;
  margin: 0 auto 20px;
  max-width: 380px;
  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;
}
.howto strong { color: var(--text); }

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

/* ---------- バナー（HOLE 1 / ナイスバーディー！） ---------- */
.banner {
  position: absolute;
  left: 0; right: 0;
  top: 38%;
  text-align: center;
  pointer-events: none;
  z-index: 5;
}
.banner[hidden] { display: none; }
.banner span {
  display: block;
  animation: banner-pop 0.35s ease;
}
#banner-text {
  font-size: clamp(30px, 8vw, 52px);
  font-weight: 900;
  letter-spacing: 0.1em;
  color: #fff;
  text-shadow: 0 4px 24px rgba(0, 0, 0, 0.6), 0 0 40px rgba(126, 230, 160, 0.55);
}
.banner-sub {
  margin-top: 6px;
  font-size: clamp(14px, 3.6vw, 19px);
  font-weight: 700;
  color: var(--accent2);
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.7);
}
.banner-sub:empty { display: none; }
@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-course {
  font-size: 15px;
  font-weight: 700;
  color: var(--sub);
  margin-bottom: 10px;
}

.result-unlock[hidden] { display: none; }
.result-unlock {
  color: var(--accent);
  font-weight: 800;
  font-size: 16px;
  line-height: 1.5;
  margin-bottom: 12px;
  animation: banner-pop 0.4s ease;
}

/* ---------- コース選択 ---------- */
.course-lead {
  font-size: 14px;
  color: var(--sub);
  margin-bottom: 16px;
  line-height: 1.6;
}

.course-list {
  list-style: none;
  margin: 0 0 18px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 460px;
}

.course-item { margin: 0; }

.course-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  font: inherit;
  color: var(--fg);
  background: var(--panel);
  border: 1px solid rgba(126, 230, 160, 0.4);
  border-radius: 14px;
  padding: 12px 14px;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease, background 0.12s ease;
}
.course-btn:hover:not(:disabled),
.course-btn:focus-visible:not(:disabled) {
  border-color: var(--accent);
  background: rgba(126, 230, 160, 0.12);
  transform: translateY(-1px);
}
.course-btn:disabled { cursor: not-allowed; }

.course-locked {
  opacity: 0.55;
  border-color: rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.04);
}

.course-no {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(126, 230, 160, 0.18);
  color: var(--accent);
  font-weight: 900;
  font-size: 15px;
}
.course-locked .course-no {
  background: rgba(255, 255, 255, 0.1);
  color: var(--sub);
}

.course-body {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.course-name { font-size: 16px; font-weight: 800; }
.course-sub { font-size: 12px; color: var(--sub); line-height: 1.5; }
.course-meta { font-size: 12px; color: var(--sub); line-height: 1.5; }

.course-mark {
  flex: 0 0 auto;
  font-size: 17px;
  color: var(--accent2);
}

@media (max-width: 480px) {
  .course-btn { padding: 10px 12px; gap: 10px; }
  .course-name { font-size: 15px; }
  .course-sub, .course-meta { font-size: 11px; }
}

.result-total {
  display: inline-flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid rgba(126, 230, 160, 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-total-par { font-size: 13px; color: var(--sub); }

.scorecard {
  width: min(340px, 100%);
  margin: 0 auto 18px;
  border-collapse: collapse;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}
.scorecard th {
  font-size: 11px;
  font-weight: 700;
  color: var(--sub);
  letter-spacing: 0.06em;
  padding: 4px 6px;
  border-bottom: 1px solid rgba(159, 196, 173, 0.35);
}
.scorecard td {
  padding: 4px 6px;
  border-bottom: 1px dashed rgba(159, 196, 173, 0.22);
}
.scorecard tbody tr:last-child td { border-bottom: none; }
.sc-hole { color: var(--sub); text-align: left; }
.sc-par { color: var(--sub); }
.sc-stroke { font-weight: 800; }
.sc-label { font-size: 12px; font-weight: 700; }
.sc-under { color: var(--accent2); }
.sc-even { color: var(--sub); }
.sc-over { color: var(--sub); }

@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(8, 22, 15, 0.78);
  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: #14351f;
  color: var(--text);
  border: 1px solid rgba(255, 209, 102, 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, 196, 173, 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, 196, 173, 0.5);
  border-radius: 8px;
  background: rgba(8, 22, 15, 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, 196, 173, 0.08); }

.sgr-row-me {
  background: rgba(255, 209, 102, 0.14) !important;
  box-shadow: inset 0 0 0 1px rgba(255, 209, 102, 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, 196, 173, 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, 209, 102, 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: var(--accent);
  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; }
}
