/* =========================================================
 * revolving-door（押しこめ！回転ドア） スタイル
 * 緑 = うまく入った、赤 = はさまった・あふれた
 * ========================================================= */
:root {
  --font-jp: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Noto Sans JP", Meiryo, sans-serif;
  --font-num: "SF Mono", "Roboto Mono", Menlo, Consolas, monospace;
  --c-bg: #0e1a2e;
  --c-bg-deep: #08101e;
  --c-text: #f3f6ff;
  --c-dim: #a7b2cc;
  --c-pass: #2fd38a;
  --c-pass-deep: #10915a;
  --c-stop: #ff3b4e;
  --c-stop-deep: #b81427;
  --c-amber: #ffb347;
  --c-gold: #ffd166;
  --c-west: #3cc8ff;
  --c-east: #ff9a3c;
  --c-panel: rgba(15, 24, 44, 0.96);
  --c-line: rgba(255, 255, 255, 0.16);
  /* ランキング（sgr-*）は明るいパネルで出す */
  --c-sgr-text: #16213a;
  --c-sgr-dim: #66708a;
  --c-sgr-line: rgba(22, 33, 58, 0.14);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: var(--font-jp);
  color: var(--c-text);
  background: var(--c-bg);
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  -webkit-text-size-adjust: 100%;
  -webkit-touch-callout: none;
}

[hidden] { display: none !important; }

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

/* ===== レイアウト =====
   共通ヘッダー(--sgh-top)とフッター広告(--ad-space)のぶんだけ内側に収める */
#app {
  position: fixed;
  left: 0;
  right: 0;
  top: var(--sgh-top, 0px);
  bottom: var(--ad-space, 0px);
  display: flex;
  flex-direction: column;
}

/* ===== 上部バー ===== */
/* タイトルだけの帯は縦幅を圧迫するので隠す（ボタンは共通ヘッダーのメニューへ集約済み）。
   h1 と、共通ヘッダーが click() で押す元ボタンは DOM に残すため、display: none ではなく
   スクリーンリーダー向けの見えない形にする */
#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 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-size: 16px;
  font-weight: 900;
  letter-spacing: 0.16em;
  color: #fff;
  white-space: nowrap;
}

/* ロゴの前の小さな回転ドア（円と十字の扉） */
.logo-mark {
  position: relative;
  width: 18px;
  height: 18px;
  border: 2px solid #86d3f2;
  border-radius: 50%;
  background:
    linear-gradient(#eef3f8, #eef3f8) center / 2px 100% no-repeat,
    linear-gradient(#eef3f8, #eef3f8) center / 100% 2px no-repeat;
  transform: rotate(20deg);
}

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

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}

.icon-btn:active { transform: scale(0.94); }

/* ===== ステージ ===== */
#stage {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background: var(--c-bg);
  touch-action: manipulation;
}

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

/* ===== 上部 UI（HUD・駅の情報・路線図） ===== */
#top-ui {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 6px 10px 0;
  padding-left: calc(10px + env(safe-area-inset-left, 0px));
  padding-right: calc(10px + env(safe-area-inset-right, 0px));
  pointer-events: none;
}

#hud {
  display: flex;
  justify-content: space-between;
  align-items: stretch;
  gap: 6px;
  width: 100%;
  max-width: 720px;
}

/* タイトル画面ではレイアウトを保ったまま隠す（盤面の位置がずれないように） */
body.is-title #hud,
body.is-title #queue-meter { visibility: hidden; }

.hud-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1 1 0;
  min-width: 0;
  padding: 3px 6px 4px;
  border-radius: 10px;
  background: rgba(4, 9, 20, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.hud-score { flex-grow: 1.5; align-items: flex-start; }
.hud-combo { align-items: flex-end; }

.hud-label {
  font-size: 9px;
  font-weight: bold;
  letter-spacing: 0.16em;
  color: var(--c-dim);
}

.hud-value {
  display: inline-block;
  font-family: var(--font-num);
  font-size: 19px;
  font-weight: bold;
  line-height: 1.15;
  color: #fff;
  font-variant-numeric: tabular-nums;
}

#hud-score { color: var(--c-gold); }

.hud-lives {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 22px;
}

/* ライフ（改札機のランプのような丸） */
.hud-lives i {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--c-pass);
  box-shadow: 0 0 8px rgba(47, 211, 138, 0.8), inset 0 -2px 0 rgba(0, 0, 0, 0.2);
  transition: background 0.2s, box-shadow 0.2s;
}

.hud-lives i.off {
  background: rgba(255, 255, 255, 0.12);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.5);
}

.hud-lives i.lost { animation: life-lost 0.6s ease-out; }
.hud-lives i.gain { animation: life-gain 0.6s ease-out; }

@keyframes life-lost {
  0% { transform: scale(1.6); background: var(--c-stop); box-shadow: 0 0 14px var(--c-stop); }
  100% { transform: scale(1); }
}

@keyframes life-gain {
  0% { transform: scale(0.2); }
  60% { transform: scale(1.5); }
  100% { transform: scale(1); }
}

.hud-combo-row {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
}

.hud-mult {
  font-family: var(--font-num);
  font-size: 12px;
  font-weight: bold;
  color: var(--c-dim);
}

.hud-mult.hot { color: var(--c-gold); }

.hud-value.bump { animation: bump 0.3s ease-out; }

@keyframes bump {
  0% { transform: scale(1); }
  40% { transform: scale(1.25); }
  100% { transform: scale(1); }
}

/* 行列の長さ（8人でいっぱい） */
#queue-meter {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 12px;
  border-radius: 999px;
  background: rgba(4, 9, 20, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.qm-label {
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.1em;
  color: var(--c-dim);
}

.qm-note {
  font-size: 10px;
  font-weight: bold;
  color: var(--c-dim);
  opacity: 0;
  transition: opacity 0.2s;
}

.qm-pips { display: inline-flex; gap: 4px; }

.qm-pips i {
  width: 14px;
  height: 9px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.14);
  transition: background 0.15s;
}

.qm-pips i.on { background: var(--c-pass); }
#queue-meter.warn .qm-pips i.on { background: var(--c-amber); }
#queue-meter.warn .qm-note { opacity: 1; color: var(--c-amber); }
#queue-meter.full .qm-pips i.on { background: var(--c-stop); animation: qm-blink 0.3s steps(2) infinite; }
#queue-meter.full .qm-note { color: #ff6b78; }

@keyframes qm-blink { 50% { opacity: 0.4; } }

/* ===== 案内の帯（READY / NEW RULE / ミスの説明） ===== */
.banner {
  position: absolute;
  left: 50%;
  top: 22%;
  z-index: 12;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: max-content;
  max-width: min(460px, calc(100% - 24px));
  padding: 10px 22px 12px;
  border-radius: 18px;
  transform: translate(-50%, -50%) scale(0.85);
  background: rgba(8, 13, 28, 0.92);
  border: 2px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5);
  color: #fff;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.16s ease, transform 0.2s cubic-bezier(0.2, 1.4, 0.4, 1);
}

.banner.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

.banner__head {
  font-family: var(--font-num);
  font-size: clamp(22px, 7vw, 36px);
  font-weight: 900;
  letter-spacing: 0.12em;
  line-height: 1.1;
}

.banner__head:empty,
.banner__text:empty,
.banner__sub:empty { display: none; }

.banner__text {
  font-size: clamp(16px, 4.6vw, 22px);
  font-weight: 900;
  line-height: 1.45;
  text-wrap: balance;
  letter-spacing: 0.02em;
}

.banner__sub {
  font-size: 12px;
  font-weight: bold;
  color: var(--c-dim);
}

.banner__text .red { color: #ff6b78; }
.banner__text .gold { color: var(--c-gold); }
.banner__text .green { color: var(--c-pass); }

.banner.new { border-color: rgba(255, 209, 102, 0.8); box-shadow: 0 0 26px rgba(255, 209, 102, 0.25), 0 12px 30px rgba(0, 0, 0, 0.5); }
.banner.new .banner__head { color: var(--c-gold); font-size: clamp(14px, 4vw, 18px); letter-spacing: 0.3em; }
.banner.go .banner__head { color: var(--c-pass); }
.banner.over { border-color: rgba(255, 59, 78, 0.75); }
.banner.over .banner__head { color: #ff6b78; }
.banner.miss { border-color: rgba(255, 59, 78, 0.85); }
.banner.miss .banner__head { color: #ff6b78; font-size: clamp(20px, 6vw, 28px); }
.banner.miss .banner__text { font-size: clamp(14px, 4.2vw, 19px); }

/* ===== 得点のポップ ===== */
#floats {
  position: absolute;
  inset: 0;
  z-index: 13;
  pointer-events: none;
  overflow: hidden;
}

.float {
  position: absolute;
  transform: translate(-50%, -50%);
  font-family: var(--font-num);
  font-size: 20px;
  font-weight: 900;
  color: #fff;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.7);
  white-space: nowrap;
  animation: float-up 0.8s ease-out forwards;
}

.float.ok { color: var(--c-pass); }
.float.stop { color: var(--c-gold); }
.float.bad { padding: 2px 14px 3px; border-radius: 999px; background: rgba(214, 28, 52, 0.94); color: #fff; font-size: 22px; font-family: var(--font-jp); text-shadow: none; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35); animation-duration: 1.2s; }
.float.combo { color: var(--c-gold); font-size: 22px; animation-duration: 1.1s; }
.float.wait { color: #cfd6e6; font-size: 14px; font-family: var(--font-jp); animation-duration: 0.7s; }
.float.life { color: var(--c-pass); font-size: 18px; font-family: var(--font-jp); animation-duration: 1.1s; }

@keyframes float-up {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(0.7); }
  15% { opacity: 1; transform: translate(-50%, -60%) scale(1.1); }
  100% { opacity: 0; transform: translate(-50%, -170%) scale(1); }
}

/* ===== 画面（タイトル・リザルト・一時停止） ===== */
.screen {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  padding-left: calc(16px + env(safe-area-inset-left, 0px));
  padding-right: calc(16px + env(safe-area-inset-right, 0px));
  background: radial-gradient(ellipse at 50% 45%, rgba(8, 14, 30, 0.35), rgba(5, 9, 20, 0.82));
  overflow-y: auto;
}

/* タイトル・リザルトは下のフッター（2行）と重ならないように、そのぶん上へ寄せる */
#screen-title,
#screen-result { padding-bottom: 50px; }

.screen-dim { background: rgba(5, 9, 20, 0.95); }

.panel {
  width: min(400px, 100%);
  margin: auto;
  padding: 22px 20px 20px;
  border-radius: 18px;
  background: var(--c-panel);
  border: 1px solid var(--c-line);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  text-align: center;
}

.title-panel {
  position: relative;
  padding-top: 24px;
  overflow: hidden;
}

/* パネルの上辺を、閉じたバー（赤に黄色の縁）にする */
.title-panel::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 7px;
  background: linear-gradient(90deg, #86d3f2, #eef3f8 50%, #86d3f2);
}

.title-en {
  margin: 0;
  font-family: var(--font-num);
  font-size: 12px;
  font-weight: bold;
  letter-spacing: 0.3em;
  color: var(--c-dim);
}

.title-ja {
  margin: 4px 0 0;
  font-size: clamp(34px, 10.5vw, 46px);
  font-weight: 900;
  letter-spacing: 0.06em;
  line-height: 1.15;
  color: #fff;
  filter: drop-shadow(0 3px 0 rgba(0, 0, 0, 0.45));
  background: linear-gradient(180deg, #ffffff 40%, #c8d2e4);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.title-catch {
  margin: 10px 0 0;
  font-size: 14px;
  line-height: 1.7;
  color: var(--c-text);
}

.title-catch b { color: var(--c-gold); }
.title-catch b.c-pass,
.howto b.c-pass { color: var(--c-pass); }
.title-catch b.c-stop,
.howto b.c-stop { color: #ff6b78; }

.title-best {
  display: inline-block;
  margin: 14px 0 0;
  padding: 4px 14px;
  border-radius: 999px;
  background: rgba(255, 209, 102, 0.12);
  border: 1px solid rgba(255, 209, 102, 0.32);
  font-size: 13px;
  font-weight: bold;
  color: var(--c-gold);
}

.title-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 18px;
}

.title-sub-buttons {
  display: flex;
  gap: 8px;
}

.title-sub-buttons .btn {
  flex: 1;
  padding: 10px 8px;
  font-size: 14px;
  white-space: nowrap;
}

.title-hint {
  margin: 14px 0 0;
  font-size: 11px;
  color: var(--c-dim);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 10px 18px;
  border-radius: 12px;
  font-family: var(--font-jp);
  font-size: 15px;
  font-weight: bold;
  cursor: pointer;
  touch-action: manipulation;
}

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

.btn:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 2px;
}

.btn-primary {
  border: 0;
  background: linear-gradient(180deg, #3be39a, #12a265);
  color: #fff;
  font-size: 17px;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  box-shadow: 0 4px 0 #0b6b42, 0 8px 18px rgba(47, 211, 138, 0.25);
}

.btn-primary:active { box-shadow: 0 2px 0 #0b6b42; transform: translateY(2px); }

.btn-sub {
  border: 1px solid rgba(255, 255, 255, 0.24);
  background: rgba(255, 255, 255, 0.06);
  color: var(--c-text);
}

/* リザルト */
.result-title {
  margin: 0;
  font-size: 20px;
  font-weight: 900;
  letter-spacing: 0.14em;
  color: #ff8a95;
}

.result-rank {
  display: inline-block;
  margin: 8px 0 0;
  padding: 3px 14px 4px;
  border-radius: 6px;
  background: #fff;
  color: #16213a;
  font-size: 15px;
  font-weight: 900;
  letter-spacing: 0.06em;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.3);
}

.result-new {
  margin: 8px 0 0;
  font-size: 14px;
  font-weight: bold;
  color: var(--c-gold);
  animation: glow 1.2s ease-in-out infinite alternate;
}

@keyframes glow {
  from { text-shadow: 0 0 4px rgba(255, 209, 102, 0.3); }
  to { text-shadow: 0 0 14px rgba(255, 209, 102, 0.9); }
}

.result-score-row {
  margin: 6px 0 0;
  font-family: var(--font-num);
  color: var(--c-gold);
}

#result-score {
  font-size: 44px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.result-unit {
  margin-left: 4px;
  font-family: var(--font-jp);
  font-size: 16px;
  font-weight: bold;
}

.result-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin: 10px 0 12px;
}

.rstat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 7px 4px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.rstat-label {
  font-size: 10px;
  color: var(--c-dim);
  white-space: nowrap;
}

.rstat span:last-child {
  font-size: 15px;
  font-weight: bold;
}

.result-last {
  margin: 0 0 12px;
  padding: 6px 10px;
  border-radius: 10px;
  background: rgba(255, 59, 78, 0.1);
  border: 1px solid rgba(255, 59, 78, 0.3);
  font-size: 12px;
  line-height: 1.55;
  color: #ffc2c8;
}

.result-buttons {
  display: flex;
  gap: 8px;
}

.result-buttons .btn { flex: 1; }

/* 一時停止 */
.paused-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: var(--c-text);
  font-family: var(--font-jp);
  cursor: pointer;
}

.paused-panel:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 3px;
}

.paused-title {
  font-size: 22px;
  font-weight: 900;
  color: var(--c-gold);
}

.paused-note {
  font-size: 13px;
  line-height: 1.6;
  color: var(--c-dim);
}

.paused-hint {
  font-size: 13px;
  color: var(--c-dim);
}

/* ===== 遊び方モーダル ===== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 2147482800;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  padding-top: calc(16px + var(--sgh-top, 0px));
  padding-bottom: calc(16px + var(--ad-space, 0px));
  background: rgba(5, 9, 20, 0.72);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}

.modal-box {
  width: min(480px, 100%);
  max-height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 20px 18px 18px;
  border-radius: 16px;
  background: var(--c-panel);
  border: 1px solid var(--c-line);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
  text-align: center;
}

.modal-title {
  margin: 0 0 10px;
  font-size: 19px;
  color: var(--c-gold);
}

.howto {
  margin: 0 0 16px;
  padding: 0 0 0 1.2em;
  text-align: left;
  font-size: 14px;
  line-height: 1.7;
}

.howto li + li { margin-top: 6px; }
.howto b { color: var(--c-gold); }

.howto-rules {
  margin: 4px 0 0;
  padding: 6px 10px 6px 1.6em;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.05);
  font-size: 13px;
}

.howto-rules li + li { margin-top: 2px; }

.modal-box .btn { min-width: 160px; }

/* ===== フッター ===== */
#footer {
  position: absolute;
  left: 0;
  right: 0;
  /* #app 自体が広告の上で終わっているので、ここで --ad-space を足さない */
  bottom: 6px;
  text-align: center;
  font-size: 11px;
  line-height: 1.6;
  color: rgba(255, 255, 255, 0.78);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
  pointer-events: none;
  z-index: 31;
}

#footer a {
  color: var(--c-gold);
  pointer-events: auto;
}

body.playing #footer { display: none; }

.title-ja span { display: inline-block; }

/* ===== 幅の狭いスマホ ===== */
@media (max-width: 360px) {
  .qm-note { display: none; }
  .hud-value { font-size: 17px; }
}

/* ===== 高さの小さいスマホ（iPhone SE など） ===== */
@media (max-height: 700px) {
  .hud-value { font-size: 17px; }
  .title-panel { padding: 18px 16px 16px; }
  .title-ja { font-size: clamp(30px, 9.5vw, 40px); }
  .title-catch { margin-top: 8px; font-size: 13px; line-height: 1.6; }
  .title-best { margin-top: 10px; }
  .title-buttons { margin-top: 12px; gap: 8px; }
  .title-hint { display: none; }
  .result-panel { padding: 16px 14px 14px; }
  #result-score { font-size: 36px; }
  .result-stats { margin: 8px 0 10px; }
}

/* ===== 低い画面（横向きのスマホなど） ===== */
@media (max-height: 520px) {
  #logo { font-size: 14px; }
  .icon-btn { width: 26px; height: 26px; font-size: 13px; }
  #top-ui { padding-top: 4px; gap: 6px; flex-direction: row; justify-content: center; align-items: center; }
  #hud { max-width: 380px; }
  .hud-cell { padding: 1px 6px 2px; }
  .hud-label { font-size: 8px; }
  .hud-value { font-size: 14px; }
  .hud-lives { height: 17px; }
  .hud-lives i { width: 10px; height: 10px; }
  .hud-mult { font-size: 10px; }
  #queue-meter { padding: 2px 10px; }
  .qm-note { display: none; }
  .title-catch, .title-hint { display: none; }
  .panel, .result-panel, .title-panel { padding: 12px 16px; }
  .title-ja { font-size: 30px; }
  .rstat span:last-child { font-size: 13px; }
  .banner { padding: 6px 16px 8px; }
  /* フッターは1行にまとめ、パネルはその上に収める */
  #footer { display: flex; justify-content: center; gap: 10px; bottom: 3px; font-size: 10px; line-height: 1.4; }
  #screen-title, #screen-result { padding-top: 8px; padding-bottom: 24px; }
  .result-title { font-size: 16px; }
  .result-rank { margin-top: 4px; font-size: 13px; }
  .result-new { margin-top: 2px; font-size: 12px; }
  .result-score-row { margin-top: 2px; }
  #result-score { font-size: 28px; }
  .result-stats { margin: 6px 0 8px; gap: 4px; }
  .rstat { padding: 3px 4px; gap: 0; }
  .rstat-label { font-size: 9px; }
  .result-last { margin-bottom: 6px; padding: 3px 8px; font-size: 11px; }
  .result-buttons .btn { min-height: 38px; padding: 6px 12px; }
  .title-buttons .btn { min-height: 38px; }
}

/* ===== 全国ランキング（共通モジュール sgr-*） ===== */
.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, 9, 20, 0.7);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}

.sgr-hidden { display: none !important; }

.sgr-panel {
  width: min(420px, 100%);
  max-height: min(80vh, 640px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #f6f8fc;
  color: var(--c-sgr-text);
  border-radius: 14px;
  padding: 20px 18px;
  box-shadow: 0 16px 50px rgba(0, 0, 0, 0.5);
  -webkit-user-select: text;
  user-select: text;
}

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

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

.sgr-tab {
  border: 1px solid var(--c-sgr-line);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: bold;
  font-family: var(--font-jp);
  background: rgba(16, 145, 90, 0.06);
  color: var(--c-sgr-text);
  cursor: pointer;
}

.sgr-tab-active {
  background: linear-gradient(180deg, #2fd38a, #10915a);
  border-color: transparent;
  color: #fff;
}

.sgr-register-msg {
  margin: 0 0 6px;
  font-size: 14px;
  font-weight: bold;
  text-align: center;
  color: #0d7a4b;
}

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

.sgr-name {
  flex: 1;
  min-width: 0;
  font-size: 16px; /* iOSズーム防止のため16px以上 */
  font-family: var(--font-jp);
  padding: 8px 10px;
  border: 2px solid var(--c-sgr-line);
  border-radius: 8px;
  background: #fff;
  color: var(--c-sgr-text);
  -webkit-user-select: text;
  user-select: text;
}

.sgr-name::placeholder { color: var(--c-sgr-dim); }

.sgr-name:focus {
  outline: none;
  border-color: #10915a;
  box-shadow: 0 0 8px rgba(16, 145, 90, 0.3);
}

.sgr-submit {
  border: none;
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 15px;
  font-weight: bold;
  font-family: var(--font-jp);
  background: linear-gradient(180deg, #2fd38a, #10915a);
  color: #fff;
  cursor: pointer;
}

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

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

.sgr-error {
  margin: 4px 0 0;
  font-size: 12px;
  color: #c9252e;
}

.sgr-status {
  margin: 0;
  font-size: 13px;
  text-align: center;
  color: var(--c-sgr-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;
  font-variant-numeric: tabular-nums;
}

.sgr-row:nth-child(even) { background: rgba(16, 145, 90, 0.07); }

.sgr-row.sgr-row-me {
  background: linear-gradient(90deg, #10915a, #2fd38a);
  color: #fff;
}

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

.sgr-rank-top1 { color: #c98d1c; }
.sgr-rank-top2 { color: #8a93a6; }
.sgr-rank-top3 { color: #b0703a; }
.sgr-row-me .sgr-rank { color: #fff; }

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

.sgr-row-score {
  font-weight: bold;
  font-family: var(--font-num);
  flex-shrink: 0;
}

.sgr-close {
  border: 1px solid var(--c-sgr-line);
  border-radius: 8px;
  padding: 10px;
  font-size: 14px;
  font-weight: bold;
  font-family: var(--font-jp);
  background: rgba(16, 145, 90, 0.06);
  color: var(--c-sgr-text);
  cursor: pointer;
}

.sgr-close:hover { border-color: #10915a; }

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

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

.sgr-cta-btn {
  border: none;
  border-radius: 999px;
  padding: 10px 22px;
  font-size: 15px;
  font-weight: bold;
  font-family: var(--font-jp);
  background: linear-gradient(135deg, #ffd166, #ff9a1f);
  color: #2a1a00;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(255, 154, 31, 0.4);
}

.sgr-cta-btn:hover { filter: brightness(1.08); }

.sgr-cta-link {
  border-radius: 999px;
  padding: 8px 18px;
  font-size: 13px;
  font-weight: bold;
  font-family: var(--font-jp);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: var(--c-text);
  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; }
}
