/* やり投げ - Javelin Throw */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
  --bg-deep: #0b2318;
  --bg-mid: #103425;
  --panel: #16412e;
  --panel-light: #1e5039;
  --accent: #ffcd4d;
  --accent-strong: #ffa726;
  --text: #eefaf1;
  --text-dim: #9cc4ab;
  --danger: #ff5a6e;
  --good: #57d98a;
}

html, body {
  height: 100%;
  overscroll-behavior: none;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg-deep);
  color: var(--text);
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

#app {
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--sgh-top, 0px) - var(--ad-space, 0px));
  height: calc(100dvh - var(--sgh-top, 0px) - var(--ad-space, 0px));
  max-width: 560px;
  margin: 0 auto;
  /* 上のセーフエリアは共通ヘッダー（--sgh-top）が確保済みなので、ここでは足さない */
  padding: 0 env(safe-area-inset-right) 0 env(safe-area-inset-left);
}

/* ---- ヘッダー ---- */
#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px 4px;
}

#logo {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: var(--accent);
  text-shadow: 0 2px 0 rgba(0,0,0,0.35);
}

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

.icon-btn {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.icon-btn:hover { background: var(--panel-light); }
.icon-btn:active { transform: scale(0.92); }

/* ---- HUD ---- */
#hud {
  display: flex;
  gap: 6px;
  padding: 2px 12px 8px;
}

.hud-box {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  background: var(--panel);
  border-radius: 10px;
  padding: 5px 4px;
  min-height: 46px;
}

.hud-box.hud-main { flex: 1.4; background: var(--panel-light); }

.hud-box.hud-active { outline: 2px solid var(--accent); }

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

.hud-value {
  font-size: 15px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
  white-space: nowrap;
}

.hud-value.hud-foul { color: var(--danger); }

.hud-box.hud-main .hud-value { font-size: 16px; color: var(--accent); }

/* ---- ゲーム画面 ---- */
#game-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  border-radius: 14px 14px 0 0;
}

#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: pointer;
}

/* ---- オーバーレイ共通 ---- */
.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(5, 22, 14, 0.82);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  z-index: 20;
  padding: 16px;
}

.overlay-box {
  width: 100%;
  max-width: 360px;
  background: linear-gradient(160deg, var(--panel-light), var(--panel));
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 18px;
  padding: 26px 22px;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0,0,0,0.5);
  animation: box-in 0.25s ease both;
}

@keyframes box-in {
  from { opacity: 0; transform: translateY(14px) scale(0.96); }
  to { opacity: 1; transform: none; }
}

.overlay-title {
  font-size: 26px;
  font-weight: 900;
  margin-bottom: 14px;
}

.start-title {
  font-size: 34px;
  font-weight: 900;
  letter-spacing: 0.08em;
  color: var(--accent);
  text-shadow: 0 3px 0 rgba(0,0,0,0.3);
}

.start-sub {
  font-size: 13px;
  color: var(--text-dim);
  letter-spacing: 0.25em;
  margin: 2px 0 16px;
}

.howto {
  list-style: none;
  text-align: left;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text);
  background: rgba(0,0,0,0.18);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 16px;
}
.howto li { padding: 3px 0; }

.start-best {
  font-size: 14px;
  color: var(--text-dim);
  margin-bottom: 14px;
}
.start-best span { color: var(--accent); font-weight: 800; font-size: 17px; }

/* ボタン */
.btn {
  display: block;
  width: 100%;
  border: none;
  border-radius: 12px;
  padding: 14px 12px;
  font-size: 16px;
  font-weight: 800;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.1s, filter 0.15s;
}
.btn:active { transform: scale(0.97); }
.btn + .btn { margin-top: 10px; }

.btn-primary {
  background: linear-gradient(180deg, var(--accent), var(--accent-strong));
  color: #3a2200;
  box-shadow: 0 4px 0 rgba(0,0,0,0.28);
}
.btn-primary:hover { filter: brightness(1.07); }

.btn-sub {
  background: var(--panel);
  color: var(--text-dim);
  border: 1px solid rgba(255,255,255,0.12);
}
.btn-sub:hover { color: var(--text); }

/* リザルト */
.result-new {
  color: var(--accent);
  font-size: 14px;
  font-weight: 800;
  margin-bottom: 6px;
  animation: blink 1s ease infinite;
}

@keyframes blink { 50% { opacity: 0.35; } }

#result-score-row {
  font-size: 52px;
  font-weight: 900;
  color: var(--accent);
  line-height: 1.1;
  margin-bottom: 14px;
  font-variant-numeric: tabular-nums;
}
.result-unit { font-size: 20px; margin-left: 4px; color: var(--text-dim); }

#result-stats {
  display: flex;
  gap: 8px;
  margin-bottom: 18px;
}

.rstat {
  flex: 1;
  background: rgba(0,0,0,0.2);
  border-radius: 10px;
  padding: 8px 4px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.rstat-label { font-size: 11px; color: var(--text-dim); }
.rstat span:last-child { font-size: 15px; font-weight: 800; font-variant-numeric: tabular-nums; }

/* ---- フッター ---- */
#footer {
  text-align: center;
  font-size: 11px;
  color: var(--text-dim);
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  line-height: 1.6;
}
/* 広告表示中は下のセーフエリアを広告枠（--ad-space）が確保するので二重に空けない */
html.has-ad-banner #footer { padding-bottom: 8px; }
#footer a { color: var(--text-dim); }
#footer a:hover { color: var(--text); }

.hidden { display: none !important; }

/* PC向け微調整 */
@media (min-width: 600px) {
  #logo { font-size: 20px; }
  .hud-value { font-size: 17px; }
  .hud-box.hud-main .hud-value { font-size: 18px; }
}

/* ---------- 全国ランキング（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(5, 22, 14, 0.82);
}

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

.sgr-title {
  margin: 0;
  font-size: 20px;
  font-weight: 900;
  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;
  font-family: inherit;
  background: var(--bg-mid);
  color: var(--text);
  cursor: pointer;
}

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

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

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

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

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

.sgr-submit {
  border: none;
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 15px;
  font-weight: bold;
  font-family: inherit;
  background: linear-gradient(180deg, var(--accent), var(--accent-strong));
  color: #3a2200;
  cursor: pointer;
}

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

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

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

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

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

.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: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  padding: 10px;
  font-size: 14px;
  font-weight: bold;
  font-family: inherit;
  background: var(--bg-mid);
  color: var(--text);
  cursor: pointer;
}

.sgr-close:hover {
  background: var(--panel-light);
}

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

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

.sgr-cta-btn {
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 15px;
  font-weight: bold;
  font-family: inherit;
  background: linear-gradient(180deg, var(--accent), var(--accent-strong));
  color: #3a2200;
  cursor: pointer;
  box-shadow: 0 3px 10px rgba(255, 205, 77, 0.35);
}

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

.sgr-cta-link:hover {
  color: var(--text);
}

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