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

:root {
  --bg-deep: #0d131c;      /* 墨 */
  --bg-mid: #131c28;
  --panel: #1a2634;
  --panel-light: #263646;
  --accent: #e0b34c;       /* 山吹 */
  --accent-strong: #c8912f;
  --vermilion: #d9513c;    /* 朱 */
  --text: #f2ece0;         /* 生成り */
  --text-dim: #93a3b5;
  --danger: #ff6b6b;
  --good: #6fd6a0;
}

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

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Yu Gothic UI", Meiryo, 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;
  /* 上のセーフエリアは共通ヘッダー（body の padding-top = --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: 19px;
  font-weight: 800;
  letter-spacing: 0.24em;
  color: var(--accent);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.4);
}

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

.icon-btn {
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  font-size: 17px;
  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.3; background: var(--panel-light); }

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

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

.hud-sub {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  margin-left: 1px;
}

.hud-box.hud-main .hud-value { font-size: 19px; 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;
  touch-action: none;
}

/* ---- オーバーレイ共通 ---- */
/* 遊び方は共通ヘッダーのメニューからポーズ中・リザルト中にも開けるので、それらより前面に出す */
#overlay-howto { z-index: 21; }

.overlay {
  position: fixed;
  inset: 0;
  top: var(--sgh-top, 0px);
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(6, 11, 17, 0.86);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  z-index: 20;
  padding: 16px;
  padding-bottom: calc(16px + var(--ad-space, 0px));
  overflow-y: auto;
}

.overlay-box {
  width: 100%;
  max-width: 360px;
  /* 収まるときは中央、画面が低くてはみ出すときは上端から（中央寄せのままだと上が切れてスクロールでも戻れない） */
  margin: auto;
  background: linear-gradient(160deg, var(--panel-light), var(--panel));
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 18px;
  padding: 24px 20px;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.55);
  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: 25px;
  font-weight: 900;
  letter-spacing: 0.12em;
  margin-bottom: 14px;
}

.start-title {
  font-size: 40px;
  font-weight: 900;
  letter-spacing: 0.2em;
  text-indent: 0.2em;
  color: var(--accent);
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.35);
}

.start-sub {
  font-size: 12px;
  color: var(--text-dim);
  letter-spacing: 0.3em;
  text-indent: 0.3em;
  margin: 4px 0 16px;
}

.howto {
  list-style: none;
  text-align: left;
  font-size: 13px;
  line-height: 1.55;
  color: var(--text);
  background: rgba(0, 0, 0, 0.22);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 14px;
}
.howto li { padding: 3px 0; }
.howto b { color: var(--accent); }
.c-good { color: var(--good) !important; }
.c-bad { color: var(--danger) !important; }

/* 得点表 */
.howto-table {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 10px;
  background: rgba(0, 0, 0, 0.22);
  border-radius: 12px;
  padding: 10px 12px;
  margin-bottom: 12px;
}
.ht-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-dim);
}
.ht-row b { margin-left: auto; color: var(--text); font-variant-numeric: tabular-nums; }
.ht-ring {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  flex-shrink: 0;
  /* 黒い輪はパネル地と同化するので、必ず明るい縁を付ける */
  border: 1px solid rgba(242, 236, 224, 0.6);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35);
}
.ht-ring1 { background: #f6f1e6; }
.ht-ring2 { background: #23272e; }
.ht-ring3 { background: #f6f1e6; }
.ht-ring4 { background: #23272e; }
.ht-ring5 { background: #f6f1e6; }
.ht-ring6 { background: #23272e; }

.howto-note {
  font-size: 12px;
  line-height: 1.6;
  color: var(--text-dim);
  margin-bottom: 16px;
}
.howto-note b { color: var(--good); }

.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: #2b1d00;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.3);
}
.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-rank {
  display: inline-block;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.14em;
  color: var(--vermilion);
  border: 1px solid rgba(217, 81, 60, 0.55);
  border-radius: 999px;
  padding: 4px 16px;
  margin-bottom: 8px;
  background: rgba(217, 81, 60, 0.1);
}

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

.result-hits {
  font-size: 13px;
  color: var(--text-dim);
  margin: 4px 0 14px;
}
.result-hits b { color: var(--text); font-size: 16px; }

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

.rstat {
  flex: 1;
  background: rgba(0, 0, 0, 0.24);
  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; white-space: pre-line; line-height: 1.3; }

/* ---- フッター ---- */
#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: 21px; }
  .hud-value { font-size: 18px; }
  .hud-box.hud-main .hud-value { font-size: 20px; }
}

/* 画面が低いときはヘッダー・HUDを詰める */
@media (max-height: 620px) {
  #topbar { padding: 5px 12px 2px; }
  .icon-btn { width: 34px; height: 34px; font-size: 15px; }
  .hud-box { min-height: 40px; }
  #footer { font-size: 10px; padding: 5px 10px calc(5px + env(safe-area-inset-bottom)); }
  html.has-ad-banner #footer { padding-bottom: 5px; }
}

/* ---------- 全国ランキング（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(6, 11, 17, 0.86);
}

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

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

.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: #2b1d00;
  cursor: pointer;
  box-shadow: 0 3px 10px rgba(224, 179, 76, 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; }
}
