/* ============================================================
   ナインボール - style.css
   ============================================================ */

:root {
  --bg: #08130f;
  --bg-deco: #0e2119;
  --ink: #eef6f0;
  --ink-soft: #90ab9e;
  --card: #10241c;
  --line: #1e4234;
  --felt: #17734f;
  --wood: #7a4a22;
  --gold: #f5c518;
  --p1: #4fd1a5;
  --p2: #ff8f5a;
  --danger: #ff6b6b;
  --shadow: 0 6px 20px rgba(0, 0, 0, .5);
  --radius: 18px;
  --ad-h: 0px;
  --ad-space: 0px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body { height: 100%; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Hiragino Maru Gothic ProN", "Hiragino Kaku Gothic ProN", "BIZ UDGothic", "Yu Gothic", "Meiryo", sans-serif;
  background-color: var(--bg);
  background-image:
    radial-gradient(var(--bg-deco) 9%, transparent 10%),
    radial-gradient(var(--bg-deco) 9%, transparent 10%);
  background-size: 46px 46px;
  background-position: 0 0, 23px 23px;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  overscroll-behavior: none;
}

#app {
  height: calc(100dvh - var(--sgh-top, 0px) - var(--ad-space, 0px));
  display: flex;
  flex-direction: column;
}

.screen {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: calc(14px + env(safe-area-inset-top)) calc(14px + env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom)) calc(14px + env(safe-area-inset-left));
  animation: screen-in .3s ease both;
}

@keyframes screen-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

.hidden { display: none !important; }

/* ---------- ボタン共通 ---------- */

.btn {
  font-family: inherit;
  font-size: 16px;
  font-weight: 700;
  color: var(--ink);
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: 999px;
  padding: 12px 24px;
  cursor: pointer;
  transition: transform .12s ease, background .12s ease;
  box-shadow: var(--shadow);
}

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

.btn-big { width: 100%; font-size: 18px; padding: 14px 24px; }

.btn-primary {
  background: linear-gradient(135deg, #22a86f, #12734d);
  border-color: transparent;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .25);
}

.btn-ghost {
  background: transparent;
  border-color: var(--line);
  box-shadow: none;
  color: var(--ink-soft);
  font-size: 15px;
  padding: 11px 24px;
}

.btn-mode {
  display: flex;
  align-items: center;
  gap: 14px;
  text-align: left;
}

.btn-mode-icon { font-size: 26px; line-height: 1; }
.btn-mode-text { flex: 1; }
.btn-mode-text small {
  display: block;
  font-size: 11px;
  font-weight: 400;
  color: var(--ink-soft);
  margin-top: 3px;
}

.icon-btn {
  font-family: inherit;
  font-size: 19px;
  line-height: 1;
  color: var(--ink);
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: 12px;
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  cursor: pointer;
  display: grid;
  place-items: center;
}

.icon-btn:active { transform: scale(.94); }
.icon-btn.is-off { opacity: .45; }

/* ---------- タイトル画面 ---------- */

/* 画面が低いときは中身があふれる。flex の中央寄せのままだと上端が切れて
   スクロールでも見えなくなるため、あふれるときだけ上から並べてスクロールさせる
   （margin: auto は余白があるときだけ効き、あふれると 0 になる） */
#screen-title {
  justify-content: flex-start;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

.title-inner {
  flex: 0 0 auto;
  margin: auto 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 340px;
  gap: 12px;
}

.title-logo { width: 128px; filter: drop-shadow(0 8px 20px rgba(0, 0, 0, .5)); }
.title-logo svg { width: 100%; height: auto; display: block; }

.title-jp {
  font-size: 34px;
  letter-spacing: .1em;
  text-shadow: 0 0 24px rgba(79, 209, 165, .35);
}

.title-desc {
  font-size: 14px;
  color: var(--ink-soft);
  text-align: center;
  line-height: 1.7;
}

.menu-panel {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 11px;
  margin-top: 6px;
}

.config-group { display: flex; flex-direction: column; gap: 8px; }

.config-label { font-size: 13px; font-weight: 700; color: var(--ink-soft); }

.config-note {
  font-size: 12px;
  color: var(--ink-soft);
  text-align: center;
  line-height: 1.8;
}

.config-note strong { color: var(--gold); }

.seg {
  display: flex;
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: 999px;
  padding: 4px;
  gap: 4px;
}

.seg-btn {
  flex: 1;
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  color: var(--ink-soft);
  background: transparent;
  border: none;
  border-radius: 999px;
  padding: 9px 0;
  cursor: pointer;
  transition: background .12s ease, color .12s ease;
}

.seg-btn.is-active {
  background: linear-gradient(135deg, #22a86f, #12734d);
  color: #fff;
}

.best-box {
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  text-align: center;
}

.best-label { font-size: 12px; color: var(--ink-soft); }

.best-value {
  font-size: 26px;
  font-weight: 700;
  color: var(--gold);
  font-variant-numeric: tabular-nums;
  margin-top: 2px;
}

/* ---------- 遊び方 ---------- */

.howto {
  width: 100%;
  margin-top: 4px;
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 16px;
  font-size: 13px;
}

.howto summary {
  font-weight: 700;
  cursor: pointer;
  color: var(--ink-soft);
  padding: 4px 0;
}

.howto[open] summary { color: var(--ink); }

.howto ul {
  margin: 8px 0 6px;
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  color: var(--ink-soft);
  line-height: 1.65;
}

.howto strong { color: var(--ink); }

.howto-h {
  margin: 14px 0 0;
  padding-top: 11px;
  border-top: 1px solid var(--line);
  font-size: 13px;
  color: var(--gold);
}

/* ---------- フッター ---------- */

.footer {
  margin-top: 14px;
  font-size: 11px;
  color: var(--ink-soft);
  text-align: center;
  line-height: 1.8;
}

.footer a { color: inherit; }

/* ---------- ゲーム画面 ---------- */

.screen-game {
  max-width: 1000px;
  padding: calc(8px + env(safe-area-inset-top)) calc(8px + env(safe-area-inset-right)) calc(6px + env(safe-area-inset-bottom)) calc(8px + env(safe-area-inset-left));
  gap: 6px;
  animation: none;
}

#game-header {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 6px;
}

#hud {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}

#hud-players {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 700;
}

.hud-p {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border-radius: 999px;
  border: 2px solid transparent;
  color: var(--ink-soft);
  max-width: 40vw;
}

.hud-p .hud-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hud-p .hud-racks {
  font-variant-numeric: tabular-nums;
  font-size: 15px;
  color: var(--ink);
}

#hud-p1.is-turn { border-color: var(--p1); color: var(--ink); background: rgba(79, 209, 165, .12); }
#hud-p2.is-turn { border-color: var(--p2); color: var(--ink); background: rgba(255, 143, 90, .12); }

.hud-vs { color: var(--ink-soft); font-size: 12px; }

#hud-sub { display: flex; gap: 6px; align-items: center; }

.hud-chip {
  font-size: 11px;
  color: var(--ink-soft);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 10px;
  font-variant-numeric: tabular-nums;
}

.hud-chip b { color: var(--gold); font-size: 13px; }

#table-wrap {
  flex: 1;
  min-height: 0;
  width: 100%;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

#table {
  display: block;
  touch-action: none;
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .55);
}

/* ---------- トースト・バナー ---------- */

#toast {
  position: absolute;
  left: 50%;
  top: 12px;
  transform: translateX(-50%);
  background: rgba(8, 19, 15, .92);
  border: 2px solid var(--line);
  /* 1行のときは従来どおりの丸い帯（高さの半分で頭打ち）。長いファウル理由は省略せず折り返す */
  border-radius: 20px;
  padding: 8px 18px;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
  width: max-content;
  max-width: 92%;
  text-align: center;
  pointer-events: none;
  z-index: 6;
  animation: toast-in .22s ease both;
}

#toast.is-foul { border-color: var(--danger); color: #ffd2d2; }

@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, -8px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

#turn-banner {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  font-size: 26px;
  font-weight: 700;
  color: var(--ink);
  text-shadow: 0 4px 18px rgba(0, 0, 0, .8);
  pointer-events: none;
  z-index: 6;
  animation: banner .95s ease both;
}

@keyframes banner {
  0%   { opacity: 0; transform: translate(-50%, -50%) scale(.8); }
  22%  { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  75%  { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1.06); }
}

/* ---------- 操作パネル ---------- */

#controls {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 2px 0;
}

#controls.is-locked { opacity: .4; pointer-events: none; }

.ctl-spin { flex-shrink: 0; text-align: center; }

#spin-pad {
  display: block;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  cursor: pointer;
  touch-action: none;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .5);
}

.ctl-cap { font-size: 10px; color: var(--ink-soft); margin-top: 2px; }

.ctl-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.ctl-aim { display: flex; align-items: center; gap: 8px; }

.aim-btn {
  font-family: inherit;
  font-size: 13px;
  color: var(--ink);
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: 10px;
  width: 46px;
  height: 30px;
  cursor: pointer;
  display: grid;
  place-items: center;
}

.aim-btn:active { transform: scale(.94); background: var(--line); }

#aim-readout {
  flex: 1;
  text-align: center;
  font-size: 12px;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}

.ctl-power { position: relative; height: 26px; }

#power {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
  z-index: 2;
}

#power-bar {
  position: absolute;
  inset: 3px 0;
  border-radius: 999px;
  background: var(--card);
  border: 2px solid var(--line);
  overflow: hidden;
}

#power-fill {
  display: block;
  height: 100%;
  width: 46%;
  border-radius: 999px;
  background: linear-gradient(90deg, #34c07f, var(--gold) 62%, #ff6b3d);
  transition: width .06s linear;
}

#power:focus-visible + #power-bar { outline: 2px solid var(--gold); outline-offset: 2px; }

.shot-btn {
  flex-shrink: 0;
  font-family: inherit;
  font-size: 17px;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, #ffb020, #ef6c1a);
  border: none;
  border-radius: 16px;
  width: 86px;
  height: 58px;
  cursor: pointer;
  box-shadow: 0 4px 0 #a8410c, var(--shadow);
  text-shadow: 0 1px 2px rgba(0, 0, 0, .3);
}

.shot-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #a8410c; }

@media (min-width: 700px) {
  #spin-pad { width: 72px; height: 72px; }
  .shot-btn { width: 110px; height: 66px; font-size: 19px; }
  #controls { gap: 16px; padding-top: 8px; }
}

/* ---------- オーバーレイ ---------- */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(4, 10, 8, .74);
  display: grid;
  place-items: center;
  z-index: 40;
  padding: 20px;
  animation: overlay-in .22s ease both;
}

/* 結果画面の上から共通ヘッダーのメニューで開いたときも、結果パネルより手前に出す */
#settings-overlay { z-index: 41; }

@keyframes overlay-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.panel {
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px 22px;
  width: 100%;
  max-width: 330px;
  max-height: 86vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  animation: panel-in .28s cubic-bezier(.2, 1.4, .4, 1) both;
}

@keyframes panel-in {
  from { opacity: 0; transform: scale(.86); }
  to   { opacity: 1; transform: none; }
}

.panel .config-group { width: 100%; }

.panel-title { font-size: 19px; }

#result-emoji { font-size: 42px; }

#result-text { font-size: 23px; font-weight: 700; text-align: center; }

#result-sub {
  font-size: 15px;
  font-weight: 700;
  color: var(--ink-soft);
  text-align: center;
  line-height: 1.6;
  font-variant-numeric: tabular-nums;
}

#result-sub .rec { color: var(--gold); }

.result-buttons {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 6px;
}

@media (prefers-reduced-motion: reduce) {
  .screen, .overlay, .panel, #toast, #turn-banner { animation-duration: 1ms; }
}

/* ---------- 全国ランキング（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(4, 10, 8, .74);
}

.sgr-panel {
  width: min(420px, 100%);
  max-height: min(80vh, 640px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--card);
  color: var(--ink);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 18px;
  box-shadow: var(--shadow);
}

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

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

.sgr-tab {
  font-family: inherit;
  border: none;
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 700;
  background: rgba(255, 255, 255, .07);
  color: var(--ink-soft);
  cursor: pointer;
}

.sgr-tab-active { background: linear-gradient(135deg, #22a86f, #12734d); color: #fff; }

.sgr-register-msg { margin: 0 0 6px; font-size: 14px; font-weight: 700; 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: 2px solid var(--line);
  border-radius: 10px;
  background: #0a1a14;
  color: var(--ink);
}

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

.sgr-submit {
  font-family: inherit;
  border: none;
  border-radius: 10px;
  padding: 8px 18px;
  font-size: 15px;
  font-weight: 700;
  background: linear-gradient(135deg, #ffb020, #ef6c1a);
  color: #fff;
  cursor: pointer;
}

.sgr-submit:disabled { opacity: .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(--ink-soft); }

.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, .05); }

.sgr-row.sgr-row-me { background: linear-gradient(135deg, #22a86f, #12734d); color: #fff; }

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

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

.sgr-row-score { font-weight: 700; flex-shrink: 0; font-variant-numeric: tabular-nums; }

.sgr-close {
  font-family: inherit;
  border: 2px solid var(--line);
  border-radius: 999px;
  padding: 10px;
  font-size: 14px;
  font-weight: 700;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
}

.sgr-cta {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.sgr-cta-msg { margin: 0; font-size: 14px; font-weight: 700; color: var(--gold); text-align: center; }

.sgr-cta-btn {
  font-family: inherit;
  width: 100%;
  border: none;
  border-radius: 999px;
  padding: 13px;
  font-size: 16px;
  font-weight: 700;
  background: linear-gradient(135deg, #ffb020, #ef6c1a);
  color: #fff;
  cursor: pointer;
  box-shadow: var(--shadow);
}

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

/* ==========================================================================
   フッター固定バナー広告（スマホ表示時のみ / js/ad-banner.js が挿入する）
   --ad-h    : 広告そのものの高さ。広告なしのときは 0px
   --ad-space: レイアウトが空けるべき高さ（広告 + セーフエリア）
   ========================================================================== */
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; }
}
