/* ダーツ - Darts */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
  --bg-deep: #0a1013;
  --bg-mid: #10201d;
  --panel: #16302a;
  --panel-light: #1d4038;
  --panel-border: rgba(255, 255, 255, 0.12);
  --accent: #ffd166;
  --accent2: #58e0a5;
  --text: #eaf5ef;
  --text-dim: #97b7ab;
  --danger: #ff6b7a;
}

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

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Yu Gothic UI", Meiryo, sans-serif;
  background: radial-gradient(circle at 50% 18%, #16302a 0%, var(--bg-deep) 62%);
  color: var(--text);
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.hidden { display: none !important; }

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

#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;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
}

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

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

#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); }

/* ---------- スコアボード ---------- */
#scoreboard {
  flex: 0 0 auto;
  padding: 2px 10px 6px;
}

#sb-players {
  display: flex;
  gap: 8px;
}

.sb-player {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  background: var(--panel);
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 5px 6px 6px;
  min-width: 0;
}

.sb-player.sb-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(255, 209, 102, 0.25) inset;
}

.sb-name {
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 0.06em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.sb-score {
  font-size: 30px;
  font-weight: 900;
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}

.sb-player.sb-active .sb-score { color: #fff8e0; }

.sb-note {
  font-size: 11px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

#sb-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 5px;
  font-size: 11px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

#sb-darts { display: inline-flex; gap: 5px; align-items: center; }

.pip {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.14);
  display: inline-block;
}
.pip.pip-on { background: var(--accent); box-shadow: 0 0 6px rgba(255, 209, 102, 0.6); }

/* ---------- クリケットのマーク表 ---------- */
#cricket-board {
  margin-top: 6px;
  background: var(--panel);
  border-radius: 12px;
  padding: 5px 6px;
}

.ck-line {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
}

.ck-cell {
  text-align: center;
  font-size: 15px;
  font-weight: 800;
  line-height: 1.25;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

.ck-cell.ck-part { color: var(--text); }
.ck-cell.ck-open { color: var(--accent2); text-shadow: 0 0 8px rgba(88, 224, 165, 0.5); }

.ck-nums .ck-cell {
  font-size: 12px;
  color: var(--accent);
  letter-spacing: 0.04em;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  padding: 1px 0;
  margin: 2px 0;
}

/* ---------- ボード ---------- */
#board-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2px 8px;
  cursor: crosshair;
}

/* 照準のラインがボードの外側まで見えるよう、キャンバスは丸く切り抜かない
   （影はキャンバス内で描いている） */
#board {
  display: block;
  touch-action: none;
}

.hit-pop {
  position: absolute;
  left: 50%;
  top: 8%;
  transform: translate(-50%, -6px);
  padding: 5px 14px;
  border-radius: 999px;
  background: rgba(8, 20, 17, 0.86);
  border: 1px solid var(--panel-border);
  color: var(--text);
  font-size: 15px;
  font-weight: 800;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.hit-pop.show { opacity: 1; transform: translate(-50%, 0); }
.hit-pop.great { color: #04201a; background: linear-gradient(180deg, #ffe08a, #ffb648); border-color: transparent; }
.hit-pop.bad { color: #fff; background: rgba(120, 24, 34, 0.92); border-color: rgba(255, 107, 122, 0.5); }

/* ---------- 操作エリア ---------- */
#controls {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 4px 12px 6px;
}

#hint {
  font-size: 12px;
  color: var(--text-dim);
  min-height: 16px;
  text-align: center;
}

.throw-btn {
  width: 100%;
  max-width: 320px;
  border: none;
  border-radius: 14px;
  padding: 12px;
  font-family: inherit;
  font-size: 16px;
  font-weight: 900;
  letter-spacing: 0.04em;
  color: #16301f;
  background: linear-gradient(180deg, #ffe08a, #ffb648);
  box-shadow: 0 4px 16px rgba(255, 184, 72, 0.3);
  cursor: pointer;
  transition: transform 0.08s, filter 0.15s;
}
.throw-btn:hover { filter: brightness(1.06); }
.throw-btn:active { transform: scale(0.98); }
.throw-btn:disabled { opacity: 0.4; box-shadow: none; cursor: default; }

/* ---------- フッター ---------- */
#footer {
  flex: 0 0 auto;
  text-align: center;
  font-size: 10px;
  line-height: 1.7;
  color: var(--text-dim);
  padding: 2px 8px calc(6px + env(safe-area-inset-bottom));
}

#footer a { color: var(--text-dim); }

/* ---------- オーバーレイ ---------- */
.overlay {
  position: fixed;
  inset: 0;
  top: var(--sgh-top, 0px);
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  padding-bottom: calc(14px + env(safe-area-inset-bottom) + var(--ad-space, 0px));
  background: rgba(4, 12, 10, 0.82);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: fade 0.2s ease;
}

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* 遊び方は共通ヘッダーのメニューからポーズ中・結果画面の上にも開くので、他のオーバーレイより前に出す */
#overlay-howto { z-index: 61; }

.overlay-box {
  width: min(420px, 100%);
  max-height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 9px;
  background: linear-gradient(180deg, #1c3f36, #0f231f);
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  padding: 18px 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.55);
  text-align: center;
}

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

.start-sub {
  font-size: 11px;
  letter-spacing: 0.32em;
  color: var(--text-dim);
  margin-top: -6px;
}

.overlay-title {
  font-size: 21px;
  font-weight: 900;
  color: var(--accent);
}

/* モード選択 */
.mode-select { display: flex; flex-direction: column; gap: 6px; }

.mode-card {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 9px 12px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.08s;
}
.mode-card:active { transform: scale(0.99); }

.mode-card.mode-on {
  border-color: var(--accent);
  background: rgba(255, 209, 102, 0.14);
}

.mode-icon {
  font-size: 20px;
  width: 26px;
  text-align: center;
  flex-shrink: 0;
}

.mode-body { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.mode-name { font-size: 15px; font-weight: 800; }
.mode-desc { font-size: 11px; color: var(--text-dim); }
.mode-card.mode-on .mode-name { color: var(--accent); }

/* オプション行 */
.opt-row {
  display: flex;
  align-items: center;
  gap: 8px;
  text-align: left;
}

.opt-label {
  font-size: 11px;
  color: var(--text-dim);
  width: 52px;
  flex-shrink: 0;
}

.opt-choices { display: flex; gap: 5px; flex: 1; flex-wrap: wrap; }

.opt-btn {
  flex: 1 1 0;
  min-width: 54px;
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  padding: 6px 4px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}
.opt-btn.opt-on {
  border-color: var(--accent2);
  background: rgba(88, 224, 165, 0.16);
  color: var(--accent2);
}

.mode-note {
  font-size: 11px;
  line-height: 1.6;
  color: var(--text-dim);
  text-align: left;
}

.start-best {
  font-size: 13px;
  font-weight: 800;
  color: var(--accent2);
}

.btn {
  border: none;
  border-radius: 14px;
  padding: 12px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.08s, filter 0.15s;
}
.btn:active { transform: scale(0.98); }

.btn-primary {
  color: #16301f;
  background: linear-gradient(180deg, #ffe08a, #ffb648);
  box-shadow: 0 4px 16px rgba(255, 184, 72, 0.3);
}
.btn-primary:hover { filter: brightness(1.06); }

.btn-sub {
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--panel-border);
  color: var(--text);
  font-size: 13px;
  padding: 10px;
}
.btn-sub:hover { background: rgba(255, 255, 255, 0.12); }

.start-links { display: flex; gap: 6px; }
.start-links .btn { flex: 1; }

/* 遊び方 */
.overlay-scroll { text-align: left; }
.howto-h {
  font-size: 13px;
  font-weight: 800;
  color: var(--accent);
  margin-top: 4px;
  border-left: 3px solid var(--accent);
  padding-left: 8px;
}
.howto { list-style: none; display: flex; flex-direction: column; gap: 5px; }
.howto li {
  font-size: 12px;
  line-height: 1.6;
  color: var(--text);
  padding-left: 12px;
  position: relative;
}
.howto li::before {
  content: "";
  position: absolute;
  left: 0; top: 8px;
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--accent2);
}

.pause-note { font-size: 12px; color: var(--text-dim); }

/* リザルト */
.result-new {
  font-size: 13px;
  font-weight: 900;
  color: var(--accent2);
  letter-spacing: 0.06em;
}

#result-score-row {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 4px;
}

#result-score {
  font-size: 46px;
  font-weight: 900;
  line-height: 1;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.result-unit { font-size: 14px; color: var(--text-dim); }

#result-stats { display: flex; flex-direction: column; gap: 3px; }

.rstat {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.05);
}
.rstat-label { color: var(--text-dim); }
.rstat-value { font-weight: 800; font-variant-numeric: tabular-nums; }

#result-buttons { display: flex; flex-direction: column; gap: 6px; }

/* ---------- 小さい画面 ---------- */
@media (max-height: 700px) {
  .sb-score { font-size: 25px; }
  #logo { font-size: 16px; }
  .icon-btn { width: 34px; height: 34px; font-size: 15px; }
  .throw-btn { padding: 10px; font-size: 15px; }
  .ck-cell { font-size: 13px; }
}

/* 横向きのスマホ（高さの低い画面）: 縦に積むとボードの高さがほぼ 0 になり、
   キャンバスがスコアや操作ボタンに重なるので、左にボード・右にスコアと操作を並べる */
@media (orientation: landscape) and (max-height: 500px) {
  #app {
    display: grid;
    max-width: 900px;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) auto auto;
    grid-template-areas:
      "board top"
      "board sb"
      "board ctrl"
      "board foot";
  }
  #topbar { grid-area: top; }
  #scoreboard { grid-area: sb; min-height: 0; overflow-y: auto; }
  #board-wrap { grid-area: board; }
  #controls { grid-area: ctrl; }
  #footer { grid-area: foot; }
}

@media (max-width: 360px) {
  .opt-label { width: 44px; }
  .opt-btn { min-width: 46px; font-size: 11px; }
}

@media (prefers-reduced-motion: reduce) {
  .overlay { animation: none; }
  .hit-pop { transition: none; }
}

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

.sgr-overlay {
  position: fixed;
  inset: 0;
  z-index: 2147483000; /* 既存オーバーレイ(60)より上 */
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px) + var(--ad-space, 0px));
  background: rgba(4, 12, 10, 0.78);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

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

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

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

.sgr-tab {
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  padding: 6px 10px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 800;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}

.sgr-tab-active {
  background: rgba(255, 209, 102, 0.18);
  border-color: var(--accent);
  color: var(--accent);
}

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

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

.sgr-name {
  flex: 1;
  min-width: 0;
  font-family: inherit;
  font-size: 16px;
  padding: 8px 10px;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.35);
  color: var(--text);
}
.sgr-name:focus { outline: none; border-color: var(--accent); }

.sgr-submit {
  border: none;
  border-radius: 10px;
  padding: 8px 16px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 800;
  background: linear-gradient(180deg, #ffe08a, #ffb648);
  color: #16301f;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(255, 184, 72, 0.3);
}
.sgr-submit:hover { filter: brightness(1.08); }
.sgr-submit:disabled { opacity: 0.5; cursor: default; }

.sgr-error { margin: 4px 0 0; font-size: 12px; font-weight: 700; color: var(--danger); }
.sgr-status { margin: 0; font-size: 13px; color: var(--text-dim); text-align: center; }

.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: 8px;
  font-size: 14px;
}
.sgr-row:nth-child(even) { background: rgba(255, 255, 255, 0.05); }
.sgr-row.sgr-row-me { background: rgba(255, 209, 102, 0.25); color: #fff; }

.sgr-rank { width: 2em; text-align: right; font-weight: 800; flex-shrink: 0; }

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

.sgr-row-score {
  font-weight: 800;
  color: var(--accent2);
  flex-shrink: 0;
  font-family: "SF Mono", "Courier New", monospace;
  font-size: 13px;
}
.sgr-row.sgr-row-me .sgr-row-score { color: #fff; }

.sgr-close {
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 10px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 800;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}
.sgr-close:active { transform: scale(0.97); }

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

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

.sgr-cta-btn {
  border: none;
  border-radius: 12px;
  padding: 10px 16px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 800;
  background: linear-gradient(180deg, #ffe08a, #ffb648);
  color: #4a3200;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(255, 209, 102, 0.35);
}
.sgr-cta-btn:active { transform: scale(0.97); }

.sgr-cta-link {
  border: none;
  background: none;
  padding: 6px;
  font-family: inherit;
  font-size: 13px;
  color: var(--text-dim);
  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; }
}
