/* =========================================================
 * 皿割り（sarawari） スタイル
 * ========================================================= */
:root {
  --font-jp: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Hiragino Sans", sans-serif;
  --font-num: "SF Mono", "Roboto Mono", Menlo, Consolas, monospace;
  --c-text: #2a211b;
  --c-dim: #7a6c60;
  --c-accent: #e2552c;
  --c-accent-deep: #b93b18;
  --c-gold: #f3c14b;
  --c-orange: #f08c1e;
  --c-red: #d64545;
  --c-panel: rgba(252, 248, 241, 0.96);
  --c-line: rgba(42, 33, 27, 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: #16110d;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  -webkit-text-size-adjust: 100%;
}

.hidden { display: none !important; }

/* ===== レイアウト =====
   共通ヘッダー(--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 に残す。
   position: absolute でフローから外れるので、#stage（flex: 1）が共通ヘッダーの直下から全部を使う */
#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 {
  margin: 0;
  font-size: 18px;
  font-weight: 900;
  letter-spacing: 0.16em;
  color: #fff4e4;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

#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: #16110d;
}

#game-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: crosshair;
}

/* 周辺減光（部屋の暗さ・奥行き感） */
#stage::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at 50% 45%, transparent 55%, rgba(0, 0, 0, 0.42) 100%);
  z-index: 1;
}

/* ===== HUD ===== */
#hud {
  position: absolute;
  top: 8px;
  left: calc(8px + env(safe-area-inset-left, 0px));
  right: calc(8px + env(safe-area-inset-right, 0px));
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  pointer-events: none;
  z-index: 10;
}

.hud-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 84px;
  padding: 4px 12px 5px;
  border-radius: 12px;
  background: rgba(18, 13, 10, 0.58);
  border: 1px solid rgba(255, 230, 190, 0.12);
  color: #fff;
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}

.hud-label {
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.16em;
  color: rgba(255, 233, 200, 0.6);
}

#hud-score {
  font-family: var(--font-num);
  font-size: 22px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.hud-time { min-width: 70px; }
#hud-time {
  font-family: var(--font-num);
  font-size: 26px;
  font-weight: 900;
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
}
.hud-time.warn #hud-time { color: #ff6b57; animation: time-warn 1s ease-in-out infinite; }
@keyframes time-warn { 50% { transform: scale(1.12); } }

.hud-combo {
  align-items: flex-end;
  min-width: 96px;
  min-height: 48px;
  background: transparent;
  border-color: transparent;
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}
#hud-combo {
  font-size: 19px;
  font-weight: 900;
  font-style: italic;
  color: #ffcf4a;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.7), 0 0 14px rgba(255, 160, 40, 0.45);
  line-height: 1.1;
  white-space: nowrap;
}
#hud-mult {
  font-family: var(--font-num);
  font-size: 13px;
  font-weight: 800;
  color: #fff;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.8);
}
.hud-combo-track {
  display: block;
  width: 80px;
  height: 3px;
  margin-top: 3px;
  border-radius: 2px;
  overflow: hidden;
  background: transparent;
}
#hud-combo-bar {
  display: block;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, #ffcf4a, #ff7a2c);
  transform: scaleX(0);
  transform-origin: right center;
}

#hud-bottom {
  position: absolute;
  left: calc(8px + env(safe-area-inset-left, 0px));
  right: calc(8px + env(safe-area-inset-right, 0px));
  bottom: 10px;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: 10px;
  pointer-events: none;
  z-index: 10;
}
#hud-bottom > * { pointer-events: auto; }

.hud-count {
  position: absolute;
  left: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding: 4px 10px;
  border-radius: 10px;
  background: rgba(18, 13, 10, 0.5);
  color: #fff;
  pointer-events: none !important;
}
#hud-count { font-family: var(--font-num); font-size: 17px; font-weight: 800; }

/* 壺ボム */
#btn-special {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 170px;
  padding: 8px 16px 12px;
  border: 2px solid rgba(255, 220, 160, 0.25);
  border-radius: 999px;
  background: rgba(30, 21, 15, 0.78);
  color: rgba(255, 240, 220, 0.55);
  font-family: var(--font-jp);
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}
#btn-special:disabled { cursor: default; }
.special-icon { font-size: 24px; line-height: 1; filter: grayscale(0.7) brightness(0.8); }
.special-gauge {
  position: absolute;
  left: 18px;
  right: 18px;
  bottom: 5px;
  height: 4px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.12);
  overflow: hidden;
}
#special-fill {
  display: block;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, #f0a43a, #ffdf6b);
  transform: scaleX(0);
  transform-origin: left center;
  transition: transform 0.2s;
}
#btn-special.ready {
  color: #fff7e0;
  border-color: #ffcf4a;
  background: linear-gradient(135deg, rgba(196, 92, 28, 0.92), rgba(140, 50, 16, 0.92));
  animation: special-ready 1s ease-in-out infinite;
}
#btn-special.ready .special-icon, #btn-special.armed .special-icon { filter: none; }
#btn-special.armed {
  color: #fff;
  border-color: #fff;
  background: linear-gradient(135deg, #e2342c, #9e1c14);
  animation: special-armed 0.5s ease-in-out infinite;
}
@keyframes special-ready { 50% { box-shadow: 0 0 22px rgba(255, 190, 60, 0.75); transform: scale(1.04); } }
@keyframes special-armed { 50% { box-shadow: 0 0 26px rgba(255, 70, 50, 0.9); } }

#stage.armed #game-canvas { cursor: cell; }

/* フリープレイの投げるもの */
#proj-select {
  display: flex;
  gap: 6px;
  padding: 5px;
  border-radius: 16px;
  background: rgba(18, 13, 10, 0.62);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}
#proj-select button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 52px;
  padding: 2px;
  border: 2px solid transparent;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  font-family: var(--font-jp);
  cursor: pointer;
}
#proj-select button span { font-size: 22px; line-height: 1.1; }
#proj-select button small { font-size: 9px; font-weight: 700; color: rgba(255, 240, 220, 0.7); white-space: nowrap; }
#proj-select button.on { border-color: #ffcf4a; background: rgba(255, 190, 60, 0.22); }
#proj-select button.on small { color: #ffe9a8; }

/* ===== はじめの一投のヒント ===== */
#hint {
  position: absolute;
  left: 50%;
  bottom: 76px;
  z-index: 11;
  margin: 0;
  padding: 8px 16px;
  border-radius: 999px;
  transform: translateX(-50%);
  font-size: 14px;
  font-weight: 800;
  color: #fff;
  white-space: nowrap;
  background: rgba(18, 13, 10, 0.72);
  border: 1px solid rgba(255, 220, 160, 0.3);
  pointer-events: none;
  animation: hint-bob 1.4s ease-in-out infinite;
}
@keyframes hint-bob { 50% { transform: translate(-50%, -6px); } }
@media (max-width: 380px) { #hint { font-size: 12px; } }

/* ===== 得点フローティング ===== */
#floats {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 11;
  overflow: hidden;
}
.float {
  position: absolute;
  left: -200px;
  top: -200px;
  transform: translate(-50%, -50%);
  font-size: 17px;
  font-weight: 900;
  color: #fff;
  white-space: nowrap;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.85), 0 0 2px rgba(0, 0, 0, 0.9);
  animation: float-up 0.9s ease-out forwards;
  opacity: 0;
}
.float.mid { color: #ffd75e; font-size: 20px; }
.float.big { color: #ffa040; font-size: 26px; }
.float.multi { color: #8fe3ff; font-size: 18px; font-style: italic; animation-duration: 1.1s; }
.float.bonus { color: #b6ff7a; font-size: 19px; animation-duration: 1.4s; }
@keyframes float-up {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(0.6); }
  15% { opacity: 1; transform: translate(-50%, -60%) scale(1.15); }
  30% { transform: translate(-50%, -70%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -190%) scale(0.95); }
}

/* ===== 中央バナー ===== */
.banner {
  position: absolute;
  left: 50%;
  top: 30%;
  z-index: 12;
  transform: translate(-50%, -50%);
  font-size: clamp(26px, 7vw, 54px);
  font-weight: 900;
  font-style: italic;
  letter-spacing: 0.04em;
  color: #fff;
  white-space: nowrap;
  text-shadow: 0 3px 0 rgba(120, 40, 10, 0.9), 0 6px 18px rgba(0, 0, 0, 0.7);
  pointer-events: none;
  opacity: 0;
  animation: banner-pop 1.4s ease-out forwards;
}
.banner:empty { display: none; }
.banner.gold { color: #ffe27a; text-shadow: 0 3px 0 #8a5a10, 0 0 24px rgba(255, 200, 60, 0.8); }
.banner.clear { color: #b6ff7a; font-size: clamp(22px, 6vw, 46px); text-shadow: 0 3px 0 #2d6a14, 0 6px 18px rgba(0, 0, 0, 0.7); }
.banner.end { color: #ffd2c4; }
.banner.refill { font-size: clamp(20px, 5vw, 34px); color: #fff1d6; top: 22%; }
.banner.arm { color: #ff8a73; font-size: clamp(22px, 5.5vw, 40px); }
.banner.ready { color: #ffcf4a; font-size: clamp(20px, 5vw, 36px); }
.banner.combo { color: #ffcf4a; }
@keyframes banner-pop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.5); }
  12% { opacity: 1; transform: translate(-50%, -50%) scale(1.12); }
  22% { transform: translate(-50%, -50%) scale(1); }
  75% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -62%) scale(1); }
}

/* ===== 画面オーバーレイ共通 ===== */
.screen {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow-y: auto;
}

/* ===== 読み込み中 ===== */
#screen-loading { background: #16110d; }
.loading-panel { text-align: center; color: #f5e6d3; font-size: 14px; }
.loading-plate {
  width: 64px;
  height: 64px;
  margin: 0 auto 14px;
  border-radius: 50%;
  border: 6px solid #f3efe6;
  box-shadow: inset 0 0 0 6px #1f4e9c;
  animation: plate-spin 1.1s linear infinite;
}
@keyframes plate-spin { to { transform: rotateY(360deg); } }

/* ===== タイトル画面 ===== */
#screen-title {
  background: linear-gradient(180deg, rgba(10, 7, 5, 0.25), rgba(10, 7, 5, 0.55));
}
.title-panel {
  width: min(420px, 100%);
  margin: auto;
  padding: 22px 20px 18px;
  border-radius: 20px;
  text-align: center;
  color: #fff5e8;
  background: rgba(22, 16, 12, 0.72);
  border: 1px solid rgba(255, 220, 170, 0.14);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.5);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}
.title-en {
  margin: 0;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.5em;
  color: rgba(255, 210, 150, 0.7);
}
.title-ja {
  position: relative;
  margin: 2px 0 2px;
  font-size: 64px;
  font-weight: 900;
  line-height: 1.1;
  letter-spacing: 0.01em;
  color: #fff;
  text-shadow: 0 4px 0 #8c2f12, 0 10px 24px rgba(0, 0, 0, 0.6);
}
.title-ja span { display: inline-block; }
.title-ja span:nth-child(1) { transform: rotate(-6deg) translateY(2px); }
.title-ja span:nth-child(2) { transform: rotate(5deg) translate(-2px, -4px); color: #ffd9a0; }
.title-ja span:nth-child(3) { transform: rotate(-3deg) translateY(3px); }
.title-catch {
  margin: 4px 0 6px;
  font-size: 17px;
  font-weight: 800;
  color: #ffcf4a;
}
.title-desc {
  margin: 0 auto 10px;
  max-width: 320px;
  font-size: 12.5px;
  line-height: 1.6;
  color: rgba(255, 240, 225, 0.82);
}
#title-best { margin: 4px 0 0; font-size: 14px; font-weight: 800; color: #fff; }
#title-total { margin: 2px 0 0; min-height: 1em; font-size: 12px; color: rgba(255, 230, 200, 0.7); }
.title-buttons { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
.title-sub-buttons { display: flex; gap: 8px; }
.title-sub-buttons .btn { flex: 1; }
.title-hint { margin: 12px 0 0; font-size: 11.5px; color: rgba(255, 235, 210, 0.6); }

/* ===== ボタン ===== */
.btn {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 14px;
  padding: 12px 18px;
  font-family: var(--font-jp);
  font-size: 16px;
  font-weight: 900;
  cursor: pointer;
  line-height: 1.25;
}
.btn small { font-size: 11px; font-weight: 700; opacity: 0.85; }
.btn:active { transform: scale(0.97); }
.btn-primary {
  color: #fff;
  font-size: 19px;
  background: linear-gradient(135deg, #f0702e, #c63b16);
  box-shadow: 0 6px 18px rgba(198, 59, 22, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.25);
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-free {
  color: #fff5e6;
  background: linear-gradient(135deg, #4f6b4a, #34503a);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.18);
}
.btn-free:hover { filter: brightness(1.1); }
.btn-sub {
  color: #fff1de;
  font-size: 14px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 230, 190, 0.2);
}
.btn-sub:hover { background: rgba(255, 255, 255, 0.16); }

/* ===== リザルト画面 ===== */
#screen-result { background: rgba(10, 7, 5, 0.62); }
.result-panel {
  width: min(400px, 100%);
  margin: auto;
  padding: 20px 18px 16px;
  border-radius: 20px;
  text-align: center;
  background: var(--c-panel);
  color: var(--c-text);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.5);
  animation: panel-in 0.35s ease-out;
}
@keyframes panel-in { from { opacity: 0; transform: translateY(16px) scale(0.96); } }
.result-title { margin: 0; font-size: 22px; font-weight: 900; color: var(--c-accent-deep); }
.result-rank {
  display: inline-block;
  margin: 6px 0 0;
  padding: 3px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(135deg, #3c2a1e, #6b4426);
}
#result-new { margin: 6px 0 0; font-size: 14px; font-weight: 900; color: #d9821a; animation: time-warn 1s ease-in-out infinite; }
.result-score-row { margin: 4px 0 8px; }
#result-score {
  font-family: var(--font-num);
  font-size: 48px;
  font-weight: 900;
  color: var(--c-text);
  font-variant-numeric: tabular-nums;
}
.result-unit { margin-left: 4px; font-size: 18px; font-weight: 800; color: var(--c-dim); }
.result-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 14px;
}
.rstat {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 7px 8px;
  border-radius: 10px;
  background: rgba(42, 33, 27, 0.06);
}
.rstat-wide { grid-column: 1 / -1; }
.rstat-label { font-size: 11px; font-weight: 700; color: var(--c-dim); }
.rstat span:last-child { font-size: 16px; font-weight: 900; }
.result-buttons { display: flex; gap: 8px; }
.result-buttons .btn { flex: 1; }
.result-panel .btn-sub { color: var(--c-text); background: rgba(42, 33, 27, 0.07); border-color: var(--c-line); }

/* ===== 一時停止・エラー ===== */
#screen-paused, #gl-error { background: rgba(10, 7, 5, 0.6); }
#screen-paused { cursor: pointer; }
.paused-panel {
  padding: 22px 26px;
  border-radius: 16px;
  text-align: center;
  color: #fff;
  background: rgba(22, 16, 12, 0.85);
  border: 1px solid rgba(255, 220, 170, 0.15);
}
.paused-title { margin: 0 0 6px; font-size: 22px; font-weight: 900; }
.paused-hint { margin: 0; font-size: 13px; line-height: 1.6; color: rgba(255, 235, 210, 0.75); }

/* ===== 遊び方モーダル ===== */
.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(8, 6, 4, 0.66);
}
.modal-box {
  width: min(480px, 100%);
  max-height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 18px 18px 16px;
  border-radius: 16px;
  background: var(--c-panel);
  color: var(--c-text);
  box-shadow: 0 16px 50px rgba(0, 0, 0, 0.5);
  -webkit-user-select: text;
  user-select: text;
}
.modal-title { margin: 0 0 10px; font-size: 19px; text-align: center; }
.howto { margin: 0 0 14px; padding-left: 1.2em; font-size: 13.5px; line-height: 1.7; }
.howto li { margin-bottom: 6px; }
.howto b { color: var(--c-accent-deep); }
.modal-box .btn { width: 100%; }

/* ===== フッター ===== */
#footer {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 6px;
  text-align: center;
  font-size: 11px;
  line-height: 1.6;
  color: rgba(255, 240, 225, 0.7);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
  pointer-events: none;
  z-index: 40;
}
#footer a { color: #ffcf4a; pointer-events: auto; }
body.playing #footer { display: none; }

/* ===== 小さい画面 ===== */
@media (max-width: 480px) {
  .hud-box { min-width: 70px; padding: 3px 9px 4px; }
  #hud-score { font-size: 18px; }
  #hud-time { font-size: 22px; }
  #hud-combo { font-size: 16px; }
  .hud-combo-track { width: 64px; }
  #btn-special { min-width: 150px; font-size: 14px; }
  #proj-select button { width: 50px; height: 48px; }
  #proj-select button span { font-size: 19px; }
  .hud-count { display: none; }
  .title-ja { font-size: 56px; }
}
@media (max-height: 560px) {
  .title-panel { padding: 12px 16px 10px; }
  .title-ja { font-size: 44px; }
  .title-desc { display: none; }
  .title-buttons { margin-top: 8px; gap: 6px; }
  .btn { padding: 8px 14px; }
  .btn-primary { font-size: 17px; }
  .title-hint { display: none; }
  #footer { display: none; }
}
@media (max-height: 430px) {
  .title-panel { width: min(560px, 100%); padding: 10px 14px 10px; }
  .title-en { display: none; }
  .title-ja { font-size: 34px; }
  .title-catch { margin: 0 0 2px; font-size: 13px; }
  #title-best { font-size: 12px; }
  #title-total { display: none; }
  .title-buttons { flex-direction: row; flex-wrap: wrap; gap: 6px; }
  .title-buttons > .btn { flex: 1 1 40%; }
  .title-sub-buttons { flex: 1 1 100%; }
  .btn small { display: none; }
  .btn-primary { font-size: 15px; }
  .btn-sub { padding: 6px 10px; font-size: 12px; }
  .hud-box { min-width: 60px; padding: 2px 8px 3px; border-radius: 9px; }
  .hud-label { font-size: 8px; }
  #hud-score { font-size: 15px; }
  #hud-time { font-size: 18px; }
  #hud-combo { font-size: 14px; }
  #hud-bottom { bottom: 6px; }
  #btn-special { min-width: 128px; padding: 4px 12px 8px; font-size: 13px; }
  .special-icon { font-size: 18px; }
  #proj-select button { width: 46px; height: 40px; }
  #proj-select button small { display: none; }
  .hud-count { display: none; }
  #hint { bottom: 50px; font-size: 12px; padding: 5px 12px; }
  .result-panel { padding: 10px 14px; }
  #result-score { font-size: 32px; }
  .result-stats { grid-template-columns: repeat(4, 1fr); margin-bottom: 8px; }
  .rstat-wide { grid-column: auto; }
  .rstat { padding: 4px 6px; }
  .rstat span:last-child { font-size: 13px; }
}
@media (prefers-reduced-motion: reduce) {
  .float, .banner { animation-duration: 0.01s; }
  #btn-special.ready, #btn-special.armed, .hud-time.warn #hud-time { animation: none; }
}
/* ===== 全国ランキング（共通モジュール 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(6, 12, 18, 0.66);
  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: var(--c-panel);
  color: var(--c-text);
  border-radius: 14px;
  padding: 20px 18px;
  box-shadow: 0 16px 50px rgba(0, 0, 0, 0.45);
}

.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-line);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: bold;
  font-family: var(--font-jp);
  background: rgba(226, 85, 44, 0.08);
  color: var(--c-text);
  cursor: pointer;
}

.sgr-tab-active {
  background: linear-gradient(135deg, var(--c-accent), var(--c-accent-deep));
  border-color: transparent;
  color: #fff;
}

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

.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-line);
  border-radius: 8px;
  background: #fff;
  color: var(--c-text);
  -webkit-user-select: text;
  user-select: text;
}

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

.sgr-name:focus {
  outline: none;
  border-color: var(--c-accent);
  box-shadow: 0 0 8px rgba(226, 85, 44, 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(135deg, var(--c-accent), var(--c-accent-deep));
  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: var(--c-red);
}

.sgr-status {
  margin: 0;
  font-size: 13px;
  text-align: center;
  color: var(--c-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(226, 85, 44, 0.07); }

.sgr-row.sgr-row-me {
  background: linear-gradient(135deg, var(--c-accent), var(--c-accent-deep));
  color: #fff;
}

.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;
  font-family: var(--font-num);
  flex-shrink: 0;
}

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

.sgr-close:hover { border-color: var(--c-accent); }

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

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

.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, #f5a623, #f0741e);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(240, 116, 30, 0.4);
}

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

.sgr-cta-link {
  border: none;
  border-radius: 999px;
  padding: 8px 18px;
  font-size: 13px;
  font-weight: bold;
  font-family: var(--font-jp);
  background: rgba(30, 43, 56, 0.08);
  border: 1px solid var(--c-line);
  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; }
}
