/* =========================================================
 * wataloop（ワタループ） スタイル
 * ========================================================= */
:root {
  --font-jp: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-num: "SF Mono", "Roboto Mono", Menlo, Consolas, monospace;
  --c-bg: #2f7d3a;
  --c-text: #4a3222;
  --c-dim: #8a6f58;
  --c-accent: #e2622b;
  --c-accent-deep: #a8401a;
  --c-leaf: #3f9c36;
  --c-leaf-deep: #2a7526;
  --c-panel: rgba(255, 249, 232, 0.96);
  --c-line: rgba(74, 50, 34, 0.16);
  /* ランキング（sgr-*）は明るいパネルで出す */
  --c-sgr-text: #3a2a1e;
  --c-sgr-dim: #8a6f58;
  --c-sgr-line: rgba(74, 50, 34, 0.16);
}

* { 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; }

/* ===== レイアウト =====
   共通ヘッダー(--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 と共通ヘッダーが押す元ボタンは DOM に残す（見えなくするだけ） */
#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;
}

/* ===== ステージ ===== */
#stage {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background: #6fbf5c;
}

#game-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  /* なぞってもページがスクロール・ズームしないようにする（操作はすべて game.js が受ける） */
  touch-action: none;
  cursor: pointer;
}

/* おいていかれそうなとき、画面の下のふちを赤く光らせる */
#warn {
  position: absolute;
  inset: 0;
  z-index: 5;
  pointer-events: none;
  opacity: 0;
  background: linear-gradient(0deg, rgba(240, 50, 40, 0.6), rgba(240, 50, 40, 0) 32%);
  transition: opacity 0.25s;
}

#warn.on { opacity: 1; animation: warn-blink 0.5s ease-in-out infinite alternate; }

@keyframes warn-blink { from { opacity: 0.45; } to { opacity: 1; } }

/* ===== HUD ===== */
#hud {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  z-index: 10;
  padding: 8px 12px 0;
  text-align: center;
  pointer-events: none;
}

#score {
  margin: 0;
  font-family: var(--font-num);
  font-size: clamp(44px, 13vw, 64px);
  font-weight: 900;
  line-height: 1;
  color: #fff;
  text-shadow: 0 3px 0 rgba(40, 26, 14, 0.75), 0 0 12px rgba(40, 26, 14, 0.35);
}

#best {
  display: inline-block;
  margin: 4px 0 0;
  padding: 2px 12px;
  border-radius: 999px;
  background: rgba(40, 26, 14, 0.5);
  font-size: 12px;
  font-weight: bold;
  color: #fff3d6;
}

#best.new { background: #e2622b; color: #fff; }

#banner {
  position: absolute;
  left: 50%;
  top: 27%;
  z-index: 11;
  margin: 0;
  padding: 8px 22px;
  border-radius: 999px;
  background: rgba(255, 249, 232, 0.95);
  box-shadow: 0 4px 0 rgba(74, 50, 34, 0.35);
  font-size: 20px;
  font-weight: 900;
  white-space: nowrap;
  color: var(--c-text);
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, 0) scale(0.6);
}

#banner.show { animation: banner-pop 1.8s ease-out both; }

@keyframes banner-pop {
  0% { opacity: 0; transform: translate(-50%, 8px) scale(0.6); }
  12% { opacity: 1; transform: translate(-50%, 0) scale(1.08); }
  20% { transform: translate(-50%, 0) scale(1); }
  78% { opacity: 1; transform: translate(-50%, 0) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -10px) scale(1); }
}

#hint {
  position: absolute;
  left: 50%;
  bottom: 12%;
  z-index: 10;
  margin: 0;
  padding: 7px 16px;
  border-radius: 999px;
  background: rgba(40, 26, 14, 0.62);
  font-size: 13px;
  font-weight: bold;
  white-space: nowrap;
  color: #fff;
  pointer-events: none;
  transform: translateX(-50%);
  transition: opacity 0.5s;
  display: none;
}

body.playing #hint { display: block; }
#hint.gone { opacity: 0; }
#hint .hint-key { display: none; }

@media (hover: hover) and (pointer: fine) {
  #hint .hint-touch { display: none; }
  #hint .hint-key { display: inline; }
}

/* ===== 画面（タイトル・結果・一時停止） ===== */
.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));
  padding-bottom: 48px;
  background: rgba(30, 50, 24, 0.28);
  overflow-y: auto;
}

/* タイトルは上に寄せて、下で待っているたぬきを見せる */
.screen-title {
  align-items: flex-start;
  padding-top: clamp(14px, 5vh, 44px);
  background: linear-gradient(180deg, rgba(30, 50, 24, 0.34), rgba(30, 50, 24, 0) 70%);
}

.screen-dim { background: rgba(24, 38, 20, 0.72); padding-bottom: 16px; }

/* 結果も上に寄せる（石になったキャラクターを、札の下に見せる） */
#screen-over {
  align-items: flex-start;
  padding-top: clamp(10px, 3vh, 28px);
  background: linear-gradient(180deg, rgba(30, 50, 24, 0.34), rgba(30, 50, 24, 0.05) 80%);
}

#screen-over .panel { margin: 0 auto; }

.panel {
  width: min(380px, 100%);
  margin: auto;
  padding: 20px 18px 18px;
  border-radius: 22px;
  background: var(--c-panel);
  border: 3px solid #fff;
  box-shadow: 0 6px 0 rgba(74, 50, 34, 0.35), 0 18px 40px rgba(20, 30, 14, 0.35);
  text-align: center;
}

.screen-title .panel { margin: 0 auto; }

/* ロゴマーク（assets/logo.svg。tools/build_logo.py で書き出す） */
.title-logo { margin: 0; line-height: 0; }

.title-logo img {
  display: block;
  width: min(100%, 300px);
  height: auto;
  margin: 0 auto;
}

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

.title-catch b { color: var(--c-leaf-deep); }

.title-best {
  display: inline-block;
  margin: 10px 0 0;
  padding: 3px 14px;
  border-radius: 999px;
  background: rgba(63, 156, 54, 0.12);
  border: 1px solid rgba(63, 156, 54, 0.35);
  font-size: 13px;
  font-weight: bold;
  color: var(--c-leaf-deep);
}

.title-best:empty { display: none; }

.title-stats {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 6px 8px;
  margin: 10px 0 0;
}

.title-stats .title-best { margin: 0; }

/* ===== コイン ===== */
.coin-ic {
  display: inline-block;
  width: 1.05em;
  height: 1.05em;
  margin-right: 0.3em;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff3b0 0 18%, #ffd23c 19% 52%, #e0a020 53% 100%);
  box-shadow: inset 0 0 0 0.12em #c98a1a, 0 1px 0 rgba(74, 50, 34, 0.35);
  vertical-align: -0.16em;
}

.wallet {
  display: inline-flex;
  align-items: center;
  margin: 0;
  padding: 3px 12px 3px 8px;
  border-radius: 999px;
  background: #fff3c8;
  border: 1px solid rgba(201, 138, 26, 0.5);
  font-family: var(--font-num);
  font-size: 13px;
  font-weight: 900;
  color: #8a5a10;
}

#coin-hud {
  position: absolute;
  right: calc(10px + env(safe-area-inset-right, 0px));
  top: 10px;
  padding: 4px 13px 4px 8px;
  background: rgba(40, 26, 14, 0.62);
  border-color: rgba(255, 226, 122, 0.5);
  font-size: 15px;
  color: #ffe27a;
}

#coin-hud.pop { animation: coin-pop 0.28s ease-out; }

@keyframes coin-pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.28); }
  100% { transform: scale(1); }
}

.btn-gacha {
  position: relative;
  border: 0;
  background: linear-gradient(180deg, #ffb347, #f0822a);
  color: #fff;
  text-shadow: 0 1px 1px rgba(120, 50, 0, 0.45);
  box-shadow: 0 4px 0 #b9571a, 0 8px 16px rgba(185, 87, 26, 0.28);
}

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

.btn-gacha:disabled {
  background: #d8d2c4;
  color: #8a8172;
  text-shadow: none;
  box-shadow: 0 4px 0 #b3ab9a;
  cursor: default;
}

.btn-big { font-size: 17px; }

.ready-tag {
  position: absolute;
  right: -6px;
  top: -9px;
  padding: 1px 7px;
  border-radius: 999px;
  background: #e0382e;
  border: 2px solid #fff;
  font-size: 10px;
  line-height: 1.5;
  color: #fff;
  text-shadow: none;
  animation: new-pop 0.6s ease-in-out infinite alternate;
}

.over-coins {
  margin: 8px 0 0;
  font-size: 14px;
  font-weight: bold;
  color: #8a5a10;
}

.over-coins b { font-family: var(--font-num); font-size: 18px; color: #c9781a; }
#over-coin-total { display: block; margin-top: 1px; font-size: 11.5px; color: var(--c-dim); }

/* ===== ガチャ ===== */
.gacha-box, .skins-box { position: relative; }

.modal-wallet {
  position: absolute;
  right: 14px;
  top: 16px;
}

.gacha-stage {
  position: relative;
  width: min(220px, 62vw);
  aspect-ratio: 1;
  margin: 4px auto 0;
  border-radius: 24px;
  background: radial-gradient(circle at 50% 42%, #fff 0 30%, #ffeec2 70%, #f6d98a 100%);
  box-shadow: inset 0 0 0 3px #fff, inset 0 -10px 24px rgba(201, 138, 26, 0.25), 0 3px 0 rgba(74, 50, 34, 0.2);
  overflow: hidden;
}

.gacha-stage[data-rare="2"][data-state="open"] { background: radial-gradient(circle at 50% 42%, #fff 0 30%, #cfe8ff 70%, #8cc4f5 100%); }
.gacha-stage[data-rare="3"][data-state="open"] { background: radial-gradient(circle at 50% 42%, #fff 0 30%, #ffe08a 70%, #f5b530 100%); }
.gacha-stage[data-rare="4"][data-state="open"] { background: radial-gradient(circle at 50% 42%, #fff 0 26%, #ffd6f2 55%, #c9a8ff 78%, #8fd8ff 100%); }

.gacha-stage[data-rare="5"][data-state="open"] { background: radial-gradient(circle at 50% 42%, #fff 0 22%, #ffe9a8 46%, #8a5fe0 78%, #2c1c66 100%); }

.gacha-rays {
  position: absolute;
  inset: -40%;
  background: repeating-conic-gradient(from 0deg, rgba(255, 255, 255, 0.85) 0 9deg, rgba(255, 255, 255, 0) 9deg 18deg);
  opacity: 0;
}

.gacha-stage[data-state="open"] .gacha-rays { opacity: 0.55; animation: rays-spin 9s linear infinite; }
.gacha-stage[data-state="open"][data-rare="1"] .gacha-rays { opacity: 0.25; }

@keyframes rays-spin { to { transform: rotate(360deg); } }

.capsule {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 46%;
  aspect-ratio: 1;
  margin: -23% 0 0 -23%;
  border-radius: 50%;
  overflow: hidden;
  box-shadow: inset -8px -10px 0 rgba(0, 0, 0, 0.12), inset 6px 8px 0 rgba(255, 255, 255, 0.4), 0 6px 0 rgba(74, 50, 34, 0.25);
  animation: capsule-idle 1.6s ease-in-out infinite alternate;
}

.capsule-top, .capsule-bottom { position: absolute; left: 0; right: 0; height: 50%; }
.capsule-top { top: 0; background: #ff7a6b; border-bottom: 3px solid rgba(74, 50, 34, 0.35); }
.capsule-bottom { bottom: 0; background: #fffaf0; }

.capsule-q {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-num);
  font-size: 34px;
  font-weight: 900;
  color: rgba(74, 50, 34, 0.55);
}

.gacha-stage[data-rare="2"] .capsule-top { background: #4aa8f0; }
.gacha-stage[data-rare="3"] .capsule-top { background: #f5b530; }
.gacha-stage[data-rare="4"] .capsule-top { background: linear-gradient(90deg, #ff6b6b, #ffb347, #ffe66d, #6bd28a, #5ab8f0, #b48cf0); }

.gacha-stage[data-state="roll"] .capsule { animation: capsule-roll 0.95s ease-in both; }
.gacha-stage[data-state="open"] .capsule { animation: capsule-open 0.3s ease-out both; }

@keyframes capsule-idle { from { transform: translateY(-3%); } to { transform: translateY(3%); } }

@keyframes capsule-roll {
  0% { transform: translateY(-160%) rotate(-40deg); }
  22% { transform: translateY(0) rotate(0deg); }
  30% { transform: translateY(-14%) rotate(8deg); }
  38% { transform: translateY(0) rotate(0deg); }
  48% { transform: rotate(-16deg); }
  58% { transform: rotate(16deg); }
  68% { transform: rotate(-20deg); }
  78% { transform: rotate(20deg); }
  88% { transform: rotate(-12deg) scale(1.06); }
  100% { transform: rotate(0deg) scale(1.18); }
}

@keyframes capsule-open {
  from { opacity: 1; transform: scale(1.18); }
  to { opacity: 0; transform: scale(2.4); }
}

.skin-view {
  display: block;
  width: 180px;
  height: 180px;
  max-width: 100%;
}

.skin-view.locked { filter: brightness(0); opacity: 0.32; }

.gacha-stage .skin-view {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 92%;
  height: 92%;
  margin: -46% 0 0 -46%;
  opacity: 0;
}

.gacha-stage[data-state="open"] .skin-view { animation: skin-in 0.45s cubic-bezier(0.2, 1.5, 0.4, 1) both; }

@keyframes skin-in {
  from { opacity: 0; transform: scale(0.3); }
  to { opacity: 1; transform: scale(1); }
}

.gacha-result { margin: 8px 0 0; }

.gacha-badge {
  display: inline-block;
  margin: 0;
  padding: 1px 12px;
  border-radius: 999px;
  background: #e0382e;
  font-family: var(--font-num);
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0.08em;
  color: #fff;
  animation: new-pop 0.6s ease-in-out infinite alternate;
}

.gacha-badge.dup { background: #9a8f7c; font-family: var(--font-jp); font-size: 11px; letter-spacing: 0; animation: none; }

.skin-name {
  margin: 4px 0 0;
  font-size: 21px;
  font-weight: 900;
  line-height: 1.3;
  color: var(--c-text);
}

.stars {
  margin: 0;
  font-size: 16px;
  letter-spacing: 0.12em;
  color: #f0a020;
}

.skin-note {
  min-height: 1.5em;
  margin: 2px 0 0;
  font-size: 12.5px;
  font-weight: bold;
  color: var(--c-leaf-deep);
}

.gacha-info {
  margin: 10px 0 0;
  font-size: 11.5px;
  line-height: 1.7;
  color: var(--c-dim);
}

/* ===== キャラクター（図鑑） ===== */
.skins-box {
  display: flex;
  flex-direction: column;
  width: min(560px, 100%);
  overflow: hidden;
}

.skins-count {
  margin-left: 4px;
  padding: 1px 10px;
  border-radius: 999px;
  background: rgba(63, 156, 54, 0.14);
  font-family: var(--font-num);
  font-size: 13px;
}

.skins-head {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex: none;
  margin: 0 0 8px;
  padding: 4px 10px;
  border-radius: 18px;
  background: radial-gradient(circle at 30% 45%, #fff 0 20%, #ffeec2 75%);
}

.skins-head .skin-view { width: 118px; height: 118px; flex: none; }
.skins-info { min-width: 0; flex: 1; text-align: left; }
.skins-info .skin-name { margin: 0; font-size: 18px; }

.skins-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(58px, 1fr));
  gap: 6px;
  flex: 1;
  min-height: 120px;
  margin: 0 -6px;
  padding: 4px 6px 6px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.skin-tile {
  position: relative;
  aspect-ratio: 1;
  padding: 0;
  border: 2px solid rgba(74, 50, 34, 0.14);
  border-radius: 12px;
  background: #f4efe2;
  cursor: pointer;
  touch-action: manipulation;
}

.skin-tile canvas { display: block; width: 100%; height: 100%; }
.skin-tile.r2 { background: #e2f0fc; }
.skin-tile.r3 { background: #ffefb8; }
.skin-tile.r4 { background: linear-gradient(135deg, #ffe6f6, #e8e0ff 55%, #dff4ff); }
.skin-tile.r5 { background: linear-gradient(135deg, #4a3690, #8a5fe0 60%, #f0b848); }
.skin-tile.r5 .skin-rare { color: #fff; font-size: 9px; }
.skin-tile.locked { background: #ece6d8; }
.skin-tile.r5.locked { background: #d9d0ea; }
.skin-tile.r5.locked .skin-rare { color: #8a7cb0; }

/* シークレットキャラクターの見出し（図鑑のいちばん下） */
.skins-sep {
  grid-column: 1 / -1;
  margin: 8px 0 0;
  padding: 3px 8px;
  border-radius: 999px;
  background: #4a3690;
  font-size: 11.5px;
  font-weight: bold;
  line-height: 1.5;
  color: #fff;
  text-align: center;
}

/* シークレットキャラクターがあらわれたお知らせのボタン（ガチャの画面） */
.btn.btn-secret {
  border: 0;
  background: linear-gradient(135deg, #5a3fb0, #8a5fe0);
  box-shadow: 0 4px 0 #3a2880;
  font-size: 14px;
  color: #fff;
  animation: new-pop 0.6s ease-in-out infinite alternate;
}

.btn.btn-secret:active { box-shadow: 0 2px 0 #3a2880; transform: translateY(2px); }

/* ===== ログインボーナス ===== */
.daily-box { text-align: center; }

.daily-coin {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 6px 0 0;
  animation: skin-in 0.5s cubic-bezier(0.2, 1.5, 0.4, 1) both;
}

.daily-coin .coin-ic { width: 34px; height: 34px; }
.daily-coin b { font-family: var(--font-num); font-size: 44px; line-height: 1.1; color: #c9781a; }

.daily-text {
  margin: 6px 0 0;
  font-size: 13.5px;
  font-weight: bold;
  line-height: 1.7;
  color: var(--c-text);
}

.daily-days {
  margin: 4px 0 12px;
  font-size: 12px;
  color: var(--c-dim);
}
.skin-tile.locked canvas { filter: brightness(0); opacity: 0.2; }

.skin-tile.on {
  border-color: var(--c-accent);
  box-shadow: 0 0 0 2px var(--c-accent), 0 3px 0 rgba(168, 64, 26, 0.3);
}

.skin-tile:focus-visible { outline: 3px solid var(--c-accent); outline-offset: 1px; }

.skin-rare {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 1px;
  font-size: 8px;
  line-height: 1;
  letter-spacing: 0.05em;
  color: #f0a020;
  pointer-events: none;
}

.skin-tile.locked .skin-rare { color: #b3a88f; }

.skins-buttons { flex: none; margin-top: 10px; }
.skins-buttons .btn { font-size: 15px; }

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

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

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 10px 18px;
  border-radius: 14px;
  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 var(--c-accent);
  outline-offset: 2px;
}

.btn-primary {
  border: 0;
  background: linear-gradient(180deg, #5fc24f, #3f9c36);
  color: #fff;
  font-size: 18px;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.25);
  box-shadow: 0 4px 0 var(--c-leaf-deep), 0 8px 16px rgba(42, 117, 38, 0.3);
}

.btn-primary:active { box-shadow: 0 2px 0 var(--c-leaf-deep); transform: translateY(2px); }

.btn-sub {
  border: 2px solid rgba(74, 50, 34, 0.2);
  background: #fff;
  color: var(--c-text);
}

/* 結果 */
.over-reason {
  margin: 0;
  font-size: 19px;
  font-weight: 900;
  color: var(--c-accent);
}

.over-score-row {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 6px;
  margin: 6px 0 0;
}

#over-score {
  font-family: var(--font-num);
  font-size: 58px;
  font-weight: 900;
  line-height: 1.05;
  color: var(--c-text);
}

.over-unit { font-size: 18px; font-weight: bold; color: var(--c-dim); }

.over-rank {
  display: inline-block;
  margin: 4px 0 0;
  padding: 3px 14px;
  border-radius: 999px;
  background: #a9773f;
  font-size: 13px;
  font-weight: bold;
  color: #fff;
}

.over-new {
  margin: 8px 0 0;
  font-size: 14px;
  font-weight: 900;
  color: var(--c-accent);
  animation: new-pop 0.7s ease-in-out infinite alternate;
}

@keyframes new-pop { from { transform: scale(1); } to { transform: scale(1.07); } }

.over-best {
  margin: 6px 0 0;
  font-size: 13px;
  font-weight: bold;
  color: var(--c-dim);
}

.over-msg {
  min-height: 1.2em;
  margin: 8px 0 0;
  font-size: 12px;
  color: var(--c-dim);
}

.over-msg:empty { display: none; }

/* 一時停止 */
.paused-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.paused-title { margin: 0; font-size: 20px; font-weight: 900; }
.paused-hint { margin: 0; font-size: 13px; line-height: 1.7; color: var(--c-dim); }

/* ===== 遊び方モーダル（body 直下。広告と共通ヘッダーのあいだに収める） ===== */
.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(24, 38, 20, 0.7);
  -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;
  overscroll-behavior: contain;
  padding: 20px 18px 18px;
  border-radius: 20px;
  background: #fff9e8;
  border: 3px solid #fff;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  text-align: center;
}

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

.howto {
  margin: 0 0 14px;
  padding: 0;
  list-style: none;
  text-align: left;
}

.howto li {
  position: relative;
  margin-bottom: 7px;
  padding-left: 1.1em;
  font-size: 13px;
  line-height: 1.7;
  color: var(--c-text);
}

.howto li::before {
  content: "";
  position: absolute;
  left: 0.15em;
  top: 0.62em;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--c-leaf);
}

.howto b { color: var(--c-accent-deep); }

/* ===== フッター ===== */
#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.95);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
  pointer-events: none;
  z-index: 31;
}

#footer a {
  color: #ffe9a8;
  pointer-events: auto;
}

body.playing #footer { display: none; }

/* 横長の画面では、タイトルを左に寄せてまん中のたぬきを見せる */
@media (min-aspect-ratio: 5/4) {
  .screen-title {
    align-items: center;
    justify-content: flex-start;
    padding-top: 16px;
    padding-left: max(4vw, calc(16px + env(safe-area-inset-left, 0px)));
    background: linear-gradient(90deg, rgba(30, 50, 24, 0.4), rgba(30, 50, 24, 0) 60%);
  }
  .screen-title .panel { margin: auto 0; width: min(340px, 42vw); }
  #screen-over {
    align-items: center;
    justify-content: flex-start;
    padding-top: 16px;
    padding-left: max(4vw, calc(16px + env(safe-area-inset-left, 0px)));
    background: linear-gradient(90deg, rgba(30, 50, 24, 0.4), rgba(30, 50, 24, 0) 60%);
  }
  #screen-over .panel { margin: auto 0; width: min(340px, 42vw); }
}

/* 小さいスマホ（iPhone SE など）: タイトルの札を低くして、下で待っているたぬきを隠さない */
@media (max-height: 700px) and (max-aspect-ratio: 5/4) {
  .screen-title { padding-top: 10px; }
  .screen-title .panel { padding: 12px 14px 14px; }
  .title-catch { display: none; }
  .title-logo img { width: min(100%, 210px); }
  .title-best { font-size: 12px; }
  .title-stats { margin-top: 6px; }
  .title-buttons { margin-top: 8px; gap: 7px; }
  .title-buttons .btn { min-height: 40px; padding-top: 7px; padding-bottom: 7px; }
}

/* 小さいスマホの結果: 札を詰めて、フッターと重ならないようにする */
@media (max-height: 700px) and (max-aspect-ratio: 5/4) {
  #screen-over { padding-top: 8px; padding-bottom: 8px; }
  #screen-over .panel { padding: 12px 14px 12px; }
  .over-reason { font-size: 17px; }
  #over-score { font-size: 44px; }
  .over-rank { margin-top: 2px; }
  .over-best { display: none; }
  .over-new { margin-top: 4px; font-size: 13px; }
  .over-coins { margin-top: 5px; }
  .over-buttons { margin-top: 10px; gap: 8px; }
  .over-buttons .btn { min-height: 40px; padding-top: 7px; padding-bottom: 7px; }
  body.over #footer { display: none; }
}

@media (max-width: 359px) {
  .title-catch { font-size: 12.5px; }
}

/* 縦が短い画面（横向きのスマホなど） */
@media (max-height: 560px) {
  .panel { padding: 12px 16px; }
  .title-logo img { width: min(100%, 220px); }
  .title-catch { font-size: 13px; margin-top: 4px; }
  .title-buttons, .over-buttons { margin-top: 10px; gap: 8px; }
  .btn { min-height: 40px; padding-top: 8px; padding-bottom: 8px; }
  #over-score { font-size: 40px; }
  #score { font-size: 40px; }
  #banner { top: 30%; font-size: 16px; padding: 5px 16px; }
  .screen { padding-bottom: 40px; }
}

@media (max-height: 560px) {
  .gacha-stage { width: min(150px, 40vh); }
  .gacha-info { display: none; }
  .skins-head .skin-view { width: 76px; height: 76px; }
  .skin-name { font-size: 17px; }
}

@media (max-height: 400px) {
  .title-catch { display: none; }
  .over-rank, .over-best { display: 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, 7, 16, 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: #fbf8f0;
  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(63, 156, 54, 0.06);
  color: var(--c-sgr-text);
  cursor: pointer;
}

.sgr-tab-active {
  background: linear-gradient(135deg, #4fb043, #2a7526);
  border-color: transparent;
  color: #fff;
}

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

.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: #4fb043;
  box-shadow: 0 0 8px rgba(226, 67, 75, 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, #4fb043, #2a7526);
  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(63, 156, 54, 0.06); }

.sgr-row.sgr-row-me {
  background: linear-gradient(135deg, #4fb043, #2a7526);
  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;
  order: 4;
}

/* 使ったキャラクター（このゲームだけ）: 順位 → 絵 → 名前 → キャラクター名 → 歩数 の順に並べる */
.sgr-row-name { order: 2; }
.sgr-tag { display: contents; }

.sgr-tag-ic {
  order: 1;
  flex: none;
  width: 30px;
  height: 30px;
  margin: -4px -2px;
}

.sgr-tag-name {
  order: 3;
  flex: 0 1 auto;
  max-width: 34%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 11px;
  color: var(--c-sgr-dim);
}

.sgr-tag-name:empty { display: none; }
.sgr-row-me .sgr-tag-name { color: rgba(255, 255, 255, 0.85); }

.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(63, 156, 54, 0.06);
  color: var(--c-sgr-text);
  cursor: pointer;
}

.sgr-close:hover { border-color: #4fb043; }

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

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

.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, #f5c24e, #e08a1a);
  color: #2a1a00;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(224, 138, 26, 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: #fff;
  border: 2px solid rgba(74, 50, 34, 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; }
}
