/* ============================================================
   バカラ - Baccarat
   ============================================================ */

:root {
  --felt-1: #1a7a52;
  --felt-2: #0f5137;
  --felt-3: #08301f;
  --gold: #e9c46a;
  --gold-hi: #f8e3a8;
  --p-blue: #3a7bd5;
  --b-red: #c0392b;
  --ui-font: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Yu Gothic UI", Meiryo, sans-serif;
}

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

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

body {
  font-family: var(--ui-font);
  background: var(--felt-3);
  color: #f3f7f2;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  height: calc(100dvh - var(--sgh-top, 0px) - var(--ad-space, 0px));
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

.hidden { display: none !important; }

/* ============ ヘッダー ============ */

/* タイトルだけの帯は縦幅を圧迫するので隠す（ボタンはすべて共通ヘッダーのメニューに集約済み）。
   h1（ページの見出し）と、共通ヘッダーが click() で押す元ボタンは DOM に残し、スクリーンリーダーにだけ見せる。
   position: absolute でレイアウトから外れるので、チップバー以下が共通ヘッダーの直下から始まる */
#topbar {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

#logo {
  font-size: 17px;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: #fff;
  white-space: nowrap;
}

#logo::before { content: "♦"; color: var(--gold); margin-right: 5px; }

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

.icon-btn {
  width: 34px;
  height: 32px;
  border: none;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.12);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  color: #fff;
  transition: background 0.15s ease;
}

.icon-btn:hover { background: rgba(255, 255, 255, 0.22); }
.icon-btn:active { transform: translateY(1px); }
.icon-btn.off { opacity: 0.45; }

/* ============ テーブル ============ */

#table {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 10px 6px;
  overflow: hidden;
  background: radial-gradient(ellipse 92% 78% at 50% 38%, var(--felt-1) 0%, var(--felt-2) 60%, var(--felt-3) 100%);
}

#table::before {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(45deg, transparent 0, transparent 3px, rgba(0, 0, 0, 0.025) 3px, rgba(0, 0, 0, 0.025) 4px);
  pointer-events: none;
}

/* --- 両者の手札 --- */

#hands {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: stretch;
  gap: 10px;
  flex: 1;
  min-height: 0;
  padding: 4px 0;
}

.side {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex: 1 1 0;
  min-width: 0;
  padding: 8px 4px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.16);
}

.side-head {
  display: flex;
  align-items: center;
  gap: 7px;
}

.side-name {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.14em;
}

#side-player .side-name { color: #9cc4ff; }
#side-banker .side-name { color: #ff9c90; }

.side-total {
  min-width: 1.9em;
  padding: 1px 8px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.45);
  color: var(--gold-hi);
  font-size: 14px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

/* 絞りの途中（まだ伏せたカードがある）は、見えているぶんだけの点数だと分かるようにする */
.side-total.partial { color: rgba(255, 255, 255, 0.55); }

/* 3枚目のぶんも含めて場所を先に確保しておく。
   カードは決まったマスに絶対配置するので、あとから配られても既にあるカードは動かない。 */
.hand {
  position: relative;
  flex: none;
  width: calc(var(--sgc-cw) * 3 - var(--hand-ol) * 2);
  height: var(--sgc-ch);
  margin: 0 auto;
}

.hand .sgc-card {
  position: absolute;
  top: 0;
  left: calc((var(--sgc-cw) - var(--hand-ol)) * var(--i, 0));
  z-index: calc(var(--i, 0) + 1);
}

/* 3枚目の置き場所。空いていることが分かるよう、うっすら枠だけ出しておく */
.hand.slot3::after {
  content: "";
  position: absolute;
  top: 0;
  left: calc((var(--sgc-cw) - var(--hand-ol)) * 2);
  width: var(--sgc-cw);
  height: var(--sgc-ch);
  border-radius: var(--sgc-card-radius, 7.5%);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.14);
  pointer-events: none;
}

/* --- 配られるときのアニメーション（シューから滑り込む） --- */

.hand .sgc-card.flying {
  animation: card-fly var(--deal-dur, 300ms) cubic-bezier(0.16, 0.84, 0.32, 1) both;
  z-index: 20;
}

@keyframes card-fly {
  from {
    opacity: 0;
    transform: translate(var(--fx, 0px), var(--fy, 0px)) rotate(-16deg) scale(0.82);
  }
  35% { opacity: 1; }
  to { opacity: 1; transform: translate(0, 0) rotate(0) scale(1); }
}

/* めくれた瞬間のきらめき */
.hand .sgc-card.just-flipped { animation: card-pop 0.5s ease-out; }

@keyframes card-pop {
  0% { filter: brightness(1.6) drop-shadow(0 0 8px rgba(233, 196, 106, 0.9)); }
  100% { filter: none; }
}

/* --- 絞り（しぼり） ---
   表向きのカードに裏面のカバー（.bac-cover）をかぶせ、--peel（0〜1）のぶんだけ
   指定した辺からカバーを削っていく。data-peel はカードの表が出てくる辺。 */

.hand .sgc-card.sq-ready {
  cursor: grab;
  touch-action: none;
}

.hand .sgc-card > .bac-cover {
  /* 共通モジュールの裏面デザインをそのまま流用する（3D反転は使わない） */
  transform: none;
  -webkit-backface-visibility: visible;
  backface-visibility: visible;
  z-index: 6;
}

.hand .sgc-card[data-peel="left"]   > .bac-cover { clip-path: inset(0 0 0 calc(var(--peel, 0) * 100%)); }
.hand .sgc-card[data-peel="right"]  > .bac-cover { clip-path: inset(0 calc(var(--peel, 0) * 100%) 0 0); }
.hand .sgc-card[data-peel="top"]    > .bac-cover { clip-path: inset(calc(var(--peel, 0) * 100%) 0 0 0); }
.hand .sgc-card[data-peel="bottom"] > .bac-cover { clip-path: inset(0 0 calc(var(--peel, 0) * 100%) 0); }

/* 絞っている間は、四隅の数字に指がかかっていて見えない。
   実際の絞りと同じで、縁から出てくるスートの数で役を読むことになる。 */
/* 指がかかるのは一瞬なので隠すときは即時、めくり終えて出てくるときだけフェードさせる */
.hand .sgc-card .sgc-corner { transition: opacity 0.18s ease-out; }
.hand .sgc-card.peeling .sgc-corner { opacity: 0; transition: none; }

/* 指の影（左上と右下の角を押さえている） */
.hand .sgc-card.peeling::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 7;
  border-radius: var(--sgc-card-radius, 7.5%);
  pointer-events: none;
  background:
    radial-gradient(ellipse 36% 21% at 12% 8%, rgba(0, 0, 0, 0.55), rgba(0, 0, 0, 0.36) 56%, transparent 82%),
    radial-gradient(ellipse 36% 21% at 88% 92%, rgba(0, 0, 0, 0.55), rgba(0, 0, 0, 0.36) 56%, transparent 82%);
}

/* めくれ目。表側に影を落とし、裏側の縁を光らせて「持ち上がっている」ように見せる */
.bac-fold {
  position: absolute;
  z-index: 8;
  opacity: 0;
  pointer-events: none;
}

.hand .sgc-card.peeling > .bac-fold { opacity: 1; }

.hand .sgc-card[data-peel="left"] > .bac-fold,
.hand .sgc-card[data-peel="right"] > .bac-fold {
  top: 0;
  bottom: 0;
  width: 20px;
  margin-left: -10px;
}

.hand .sgc-card[data-peel="top"] > .bac-fold,
.hand .sgc-card[data-peel="bottom"] > .bac-fold {
  left: 0;
  right: 0;
  height: 20px;
  margin-top: -10px;
}

.hand .sgc-card[data-peel="left"] > .bac-fold {
  left: calc(var(--peel, 0) * 100%);
  background: linear-gradient(90deg, rgba(0, 0, 0, 0.42), rgba(0, 0, 0, 0) 48%, rgba(255, 255, 255, 0.5) 52%, rgba(255, 255, 255, 0));
}

.hand .sgc-card[data-peel="right"] > .bac-fold {
  left: calc((1 - var(--peel, 0)) * 100%);
  background: linear-gradient(270deg, rgba(0, 0, 0, 0.42), rgba(0, 0, 0, 0) 48%, rgba(255, 255, 255, 0.5) 52%, rgba(255, 255, 255, 0));
}

.hand .sgc-card[data-peel="top"] > .bac-fold {
  top: calc(var(--peel, 0) * 100%);
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.42), rgba(0, 0, 0, 0) 48%, rgba(255, 255, 255, 0.5) 52%, rgba(255, 255, 255, 0));
}

.hand .sgc-card[data-peel="bottom"] > .bac-fold {
  top: calc((1 - var(--peel, 0)) * 100%);
  background: linear-gradient(0deg, rgba(0, 0, 0, 0.42), rgba(0, 0, 0, 0) 48%, rgba(255, 255, 255, 0.5) 52%, rgba(255, 255, 255, 0));
}

/* 手を離したあと（最後までめくる／伏せ直す）はなめらかに動かす */
.hand .sgc-card.peel-anim { transition: transform 0.32s ease-out; }
.hand .sgc-card.peel-anim > .bac-cover { transition: clip-path 0.38s cubic-bezier(0.3, 0.7, 0.35, 1); }
.hand .sgc-card.peel-anim > .bac-fold { transition: top 0.38s cubic-bezier(0.3, 0.7, 0.35, 1), left 0.38s cubic-bezier(0.3, 0.7, 0.35, 1), opacity 0.2s ease; }

.hand .sgc-card.sq-ready::after {
  content: "";
  position: absolute;
  inset: -3px;
  border-radius: 10%;
  box-shadow: 0 0 0 2px rgba(233, 196, 106, 0.85);
  z-index: 9;
  pointer-events: none;
  animation: sq-hint 1.1s ease-in-out infinite alternate;
}

.hand .sgc-card.sq-ready:focus-visible { outline: none; }
.hand .sgc-card.sq-ready:focus-visible::after {
  box-shadow: 0 0 0 3px #fff, 0 0 12px rgba(255, 255, 255, 0.8);
  animation: none;
}

@keyframes sq-hint {
  from { opacity: 0.35; }
  to { opacity: 1; }
}

.hand .sgc-card.squeezing {
  z-index: 30;
  cursor: grabbing;
  filter: drop-shadow(0 8px 14px rgba(0, 0, 0, 0.55));
}

#msg {
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.88);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
  min-height: 1.2em;
  flex: none;
}

/* ============ ベットエリア ============ */

#bet-areas {
  display: grid;
  grid-template-columns: 1fr 1.4fr 1fr 1.4fr 1fr;
  gap: 4px;
  flex: none;
}

.bet-area {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  min-height: 58px;
  padding: 6px 2px;
  border: 2px solid rgba(255, 255, 255, 0.22);
  border-radius: 9px;
  background: rgba(0, 0, 0, 0.22);
  color: #f3f7f2;
  font-family: var(--ui-font);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.08s ease;
}

.bet-area:hover { background: rgba(255, 255, 255, 0.1); }
.bet-area:active { transform: scale(0.97); }

.area-player { border-color: rgba(58, 123, 213, 0.7); background: rgba(58, 123, 213, 0.18); }
.area-banker { border-color: rgba(192, 57, 43, 0.7); background: rgba(192, 57, 43, 0.18); }
.area-tie { border-color: rgba(233, 196, 106, 0.6); background: rgba(233, 196, 106, 0.12); }
.area-pp, .area-bp { border-color: rgba(255, 255, 255, 0.2); }

.area-name { font-size: 12px; font-weight: 800; line-height: 1.2; }
.area-pp .area-name, .area-bp .area-name { font-size: 11px; }

.area-odds {
  font-size: 9px;
  color: rgba(255, 255, 255, 0.62);
  line-height: 1.2;
}

.area-odds small { font-size: 8px; opacity: 0.85; }

.area-chips {
  min-height: 14px;
  font-size: 11px;
  font-weight: 800;
  color: var(--gold-hi);
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

.bet-area.has-bet { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold) inset; }

.bet-area.winner {
  animation: area-win 0.9s ease infinite alternate;
}

@keyframes area-win {
  from { box-shadow: 0 0 0 2px var(--gold) inset, 0 0 8px rgba(233, 196, 106, 0.4); }
  to { box-shadow: 0 0 0 3px var(--gold-hi) inset, 0 0 20px rgba(233, 196, 106, 0.8); }
}

/* ============ 罫線（大路） ============ */

#road-wrap {
  display: flex;
  align-items: center;
  gap: 7px;
  flex: none;
  padding: 4px 2px 0;
}

#road-label, #road-stats {
  font-size: 9px;
  color: rgba(255, 255, 255, 0.45);
  flex: none;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

#road {
  display: flex;
  gap: 1px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  justify-content: flex-start;
  padding: 3px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.25);
  /* 出目が1つも無いときも高さが変わらないように（6マス + すきま + 内側の余白） */
  min-height: calc(var(--road-cell) * 6 + 11px);
}

.road-col { display: flex; flex-direction: column; gap: 1px; flex: none; }

.road-cell {
  width: var(--road-cell);
  height: var(--road-cell);
  border-radius: 50%;
  background: transparent;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
}

.road-p { background: var(--p-blue); box-shadow: none; }
.road-b { background: var(--b-red); box-shadow: none; }

/* タイは丸に緑の斜線を重ねる */
.road-tie {
  background-image: linear-gradient(45deg, transparent 42%, #6ee7a0 42%, #6ee7a0 58%, transparent 58%);
}

/* ============ 操作エリア ============ */

/* ベット中・絞り中・結果表示で高さが変わらないよう、3つのパネルを同じマスに重ねて置く。
   （切り替えは display ではなく visibility で行うので、常に一番高いパネルの高さになる） */
#controls {
  position: relative;
  flex: none;
  display: grid;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  background: rgba(0, 0, 0, 0.34);
  box-shadow: inset 0 1px 0 rgba(233, 196, 106, 0.18);
}

#bet-panel, #squeeze-panel, #result-panel {
  grid-area: 1 / 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  justify-content: center;
}

.panel-off {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}

#squeeze-text {
  font-size: 13px;
  font-weight: 700;
  text-align: center;
  color: var(--gold-hi);
}

/* ランキングの登録CTAは操作エリアの上に浮かせる（操作エリアの高さを変えない） */
#cta-slot {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 100%;
  display: flex;
  justify-content: center;
  padding: 0 10px 6px;
  pointer-events: none;
}

#cta-slot .sgr-cta {
  pointer-events: auto;
  margin: 0;
  padding: 8px 14px;
  border-radius: 12px;
  border: 1px solid rgba(233, 196, 106, 0.35);
  background: rgba(6, 26, 18, 0.88);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}

.bet-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.bet-label { font-size: 11px; color: rgba(255, 255, 255, 0.65); }

#bet-total {
  font-size: 20px;
  font-weight: 800;
  color: var(--gold-hi);
  font-variant-numeric: tabular-nums;
  min-width: 2.5em;
  text-align: right;
}

.sgc-btn.small { padding: 6px 10px; font-size: 12px; }
.sgc-btn.wide { width: min(300px, 100%); padding: 12px; font-size: 15px; }

#chip-rack { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

#result-text {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  text-align: center;
  line-height: 1.5;
}

.r-head { font-size: 13px; font-weight: 700; color: rgba(255, 255, 255, 0.9); }

.r-amount { font-size: 19px; font-weight: 800; font-variant-numeric: tabular-nums; }

#result-text.win .r-amount { color: #7dffb0; }
#result-text.lose .r-amount { color: #ff9c90; }
#result-text.push .r-amount { color: rgba(255, 255, 255, 0.85); }

.r-detail { font-size: 11px; color: rgba(255, 255, 255, 0.62); }

/* 遊び方の中で使う凡例 */
.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  vertical-align: -1px;
}

.dot-p { background: var(--p-blue); }
.dot-b { background: var(--b-red); }

.rule-table {
  width: 100%;
  margin: 6px 0;
  border-collapse: collapse;
  font-size: 12px;
}

.rule-table th, .rule-table td {
  padding: 5px 7px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  text-align: left;
}

.rule-table th { background: rgba(233, 196, 106, 0.14); color: var(--gold-hi); }

/* ============ フッター ============ */

#footer {
  flex: none;
  padding: 7px 10px calc(7px + env(safe-area-inset-bottom));
  text-align: center;
  font-size: 10px;
  line-height: 1.7;
  color: rgba(255, 255, 255, 0.42);
  background: rgba(0, 0, 0, 0.32);
}

#footer a { color: rgba(255, 255, 255, 0.6); text-decoration: none; }
#footer a:hover { text-decoration: underline; }

/* ============ カードサイズ・画面サイズ調整 ============
   --hand-ol は手札のカードの重なり幅（3枚ぶんの置き場所の計算にも使う） */

:root {
  --sgc-cw: 54px;
  --sgc-ch: 76px;
  --hand-ol: calc(var(--sgc-cw) * 0.26);
  --road-cell: 9px;
}

@media (min-width: 420px) {
  :root { --sgc-cw: 62px; --sgc-ch: 87px; }
}

@media (min-width: 700px) {
  :root { --sgc-cw: 74px; --sgc-ch: 104px; --road-cell: 12px; }
  #logo { font-size: 20px; }
  #msg { font-size: 14px; }
  .side-name { font-size: 13px; }
  .side-total { font-size: 17px; }
  .area-name { font-size: 14px; }
  .area-odds { font-size: 11px; }
  .area-chips { font-size: 13px; }
  .bet-area { min-height: 70px; }
  #road-label, #road-stats { font-size: 11px; }
  #squeeze-text { font-size: 14px; }
}

/* 画面が低いときはカードを小さくしてスクロールを避ける */
@media (max-height: 640px) {
  :root { --sgc-cw: 46px; --sgc-ch: 65px; }
  #table { padding: 6px 8px 4px; }
  .sgc-chip { width: 40px; height: 40px; font-size: 11px; }
  .bet-area { min-height: 50px; }
  #bet-total { font-size: 17px; }
}

@media (max-height: 560px) {
  :root { --sgc-cw: 40px; --sgc-ch: 56px; }
}

/* さらに低い画面（iPhone SE・8 の Safari、画面 640px の Android の Chrome など）。
   共通ヘッダー・チップバー・広告のぶん手札の置き場が足りず、PLAYER / BANKER と点数が
   テーブルの上端で切れて見えなくなり、カードがメッセージとベットエリアに重なっていた。
   余白と罫線のマスを詰めて手札の高さを確保する */
@media (max-height: 630px) {
  :root { --road-cell: 6px; }
  #table { gap: 4px; }
  #hands { padding: 2px 0; }
  .side { gap: 3px; padding: 3px 4px; }
  #msg { line-height: 1.2; }
  .bet-area { min-height: 0; padding: 3px 2px; }
  #controls { padding-top: 6px; padding-bottom: calc(6px + env(safe-area-inset-bottom)); }
  #bet-panel, #squeeze-panel, #result-panel { gap: 5px; }
  #chip-rack .sgc-chip { width: 40px; height: 40px; font-size: 11px; }
  .sgc-btn.wide { padding: 8px; }
  #footer { padding-top: 4px; padding-bottom: calc(4px + env(safe-area-inset-bottom)); line-height: 1.5; }
}

@media (prefers-reduced-motion: reduce) {
  .hand .sgc-card.flying,
  .hand .sgc-card.just-flipped,
  .bet-area.winner,
  .hand .sgc-card.sq-ready::after { animation: none !important; }
  .hand .sgc-card.sq-ready::after { opacity: 1; }
  .hand .sgc-card.peel-anim,
  .hand .sgc-card.peel-anim > .bac-cover,
  .hand .sgc-card.peel-anim > .bac-fold { transition: none !important; }
}

/* ============ モーダル ============ */

.modal {
  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));
  background: rgba(4, 20, 14, 0.78);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}

.modal-box {
  width: min(460px, 100%);
  max-height: min(84vh, 720px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 20px 18px;
  border: 1px solid rgba(233, 196, 106, 0.3);
  border-radius: 14px;
  background: #0a2418;
  box-shadow: 0 16px 44px rgba(0, 0, 0, 0.6);
  -webkit-user-select: text;
  user-select: text;
}

.modal-box h2 {
  margin-bottom: 12px;
  font-size: 19px;
  text-align: center;
  color: var(--gold-hi);
}

.modal-box h3 {
  margin: 14px 0 5px;
  font-size: 14px;
  color: var(--gold);
}

.modal-box section:first-of-type h3 { margin-top: 0; }

.modal-box p, .modal-box li {
  font-size: 13px;
  line-height: 1.7;
  color: rgba(255, 255, 255, 0.88);
}

.modal-box ul, .modal-box ol { padding-left: 1.3em; margin: 4px 0; }
.modal-box li { margin-bottom: 3px; }
.modal-box strong { color: var(--gold-hi); }

.modal-actions {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 18px;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.rule-name { font-size: 13px; font-weight: 700; }

.settings-sub { margin-top: 18px !important; }

.seg { display: flex; gap: 4px; }

.seg button {
  padding: 6px 11px;
  border: 1px solid rgba(233, 196, 106, 0.3);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.06);
  color: #f3f7f2;
  font-family: var(--ui-font);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.seg button.on {
  background: linear-gradient(180deg, var(--gold-hi), #d4a93f);
  border-color: transparent;
  color: #3b2a06;
}

#stats-list { list-style: none; padding: 0; margin-top: 6px; }

#stats-list li {
  display: flex;
  justify-content: space-between;
  padding: 6px 2px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 13px;
}

#stats-list strong { font-variant-numeric: tabular-nums; color: #fff; }
#stats-list strong.plus { color: #7dffb0; }
#stats-list strong.minus { color: #ff9c90; }

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

.sgr-overlay {
  position: fixed;
  inset: 0;
  /* フッター固定バナー広告（2147482000）より上に出す */
  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, 20, 14, 0.8);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}

.sgr-panel {
  width: min(420px, 100%);
  max-height: min(80vh, 640px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #0a2418;
  color: #f3f7f2;
  border: 1px solid rgba(233, 196, 106, 0.32);
  border-radius: 14px;
  padding: 20px 18px;
  box-shadow: 0 16px 44px rgba(0, 0, 0, 0.6);
}

.sgr-title {
  margin: 0;
  font-size: 20px;
  text-align: center;
  color: var(--gold-hi);
}

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

.sgr-tab {
  border: 1px solid rgba(233, 196, 106, 0.32);
  border-radius: 7px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: bold;
  font-family: var(--ui-font);
  background: rgba(255, 255, 255, 0.06);
  color: #f3f7f2;
  cursor: pointer;
}

.sgr-tab-active {
  background: linear-gradient(180deg, var(--gold-hi), #d4a93f);
  border-color: transparent;
  color: #3b2a06;
}

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

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

.sgr-name {
  flex: 1;
  min-width: 0;
  font-size: 16px; /* iOSズーム防止のため16px以上 */
  font-family: var(--ui-font);
  padding: 8px 10px;
  border: 2px solid rgba(233, 196, 106, 0.32);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.35);
  color: #f3f7f2;
  -webkit-user-select: text;
  user-select: text;
}

.sgr-name::placeholder { color: rgba(255, 255, 255, 0.45); }
.sgr-name:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 12px rgba(233, 196, 106, 0.3);
}

.sgr-submit {
  border: none;
  border-radius: 8px;
  padding: 8px 18px;
  font-size: 14px;
  font-weight: bold;
  font-family: var(--ui-font);
  background: linear-gradient(180deg, var(--gold-hi), #d4a93f);
  color: #3b2a06;
  cursor: pointer;
  transition: filter 0.15s, transform 0.1s;
}

.sgr-submit:hover { filter: brightness(1.1); }
.sgr-submit:active { transform: scale(0.96); }
.sgr-submit:disabled { opacity: 0.5; cursor: default; }

.sgr-error { margin: 6px 0 0; font-size: 12px; text-align: center; color: #ff9c90; }
.sgr-status { margin: 0; font-size: 13px; text-align: center; color: rgba(255, 255, 255, 0.55); }

.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(255, 255, 255, 0.05); }

.sgr-row-me {
  background: rgba(233, 196, 106, 0.18) !important;
  box-shadow: inset 0 0 0 1px rgba(233, 196, 106, 0.5);
}

.sgr-rank {
  width: 2em;
  text-align: center;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.55);
  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(--gold-hi); flex: none; }

.sgr-close {
  border: 1px solid rgba(233, 196, 106, 0.32);
  border-radius: 999px;
  padding: 10px 0;
  font-size: 14px;
  font-weight: bold;
  font-family: var(--ui-font);
  background: rgba(255, 255, 255, 0.06);
  color: #f3f7f2;
  cursor: pointer;
}

.sgr-close:hover { background: rgba(255, 255, 255, 0.12); }

/* 結果画面に差し込まれる登録CTA */
.sgr-cta {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  margin: 2px 0;
}

.sgr-cta-msg {
  margin: 0;
  font-size: 13px;
  font-weight: bold;
  color: var(--gold-hi);
}

.sgr-cta-btn {
  border: none;
  border-radius: 10px;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 800;
  font-family: var(--ui-font);
  background: linear-gradient(180deg, var(--gold-hi), #d4a93f);
  color: #3b2a06;
  cursor: pointer;
}

.sgr-cta-link {
  border: none;
  background: none;
  color: rgba(255, 255, 255, 0.7);
  font-size: 12px;
  font-family: var(--ui-font);
  text-decoration: underline;
  cursor: pointer;
  padding: 4px;
}

/* ==========================================================================
   フッター固定バナー広告（スマホ表示時のみ / 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 {
  box-sizing: content-box;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  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);
  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; }
}
