/* ===== スネーク - Snake ===== */

:root {
  --c-bg: #0d1410;
  --c-bg2: #101b13;
  --c-panel: rgba(16, 28, 20, 0.96);
  --c-text: #e8f5ec;
  --c-dim: #8aa793;
  --c-green: #58e07c;
  --c-green-deep: #2fae57;
  --c-yellow: #ffd93d;
  --c-red: #ff5252;
  --c-line: rgba(88, 224, 124, 0.28);
  --font-jp: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-num: "SF Mono", Menlo, Consolas, monospace;
}

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

html,
body {
  height: 100%;
}

body {
  font-family: var(--font-jp);
  background: radial-gradient(120% 100% at 50% 0%, var(--c-bg2) 0%, var(--c-bg) 65%);
  color: var(--c-text);
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

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

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

#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px 6px;
}

#logo {
  font-size: 20px;
  letter-spacing: 0.06em;
  color: var(--c-green);
  text-shadow: 0 0 16px rgba(88, 224, 124, 0.45);
}

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

.icon-btn {
  width: 40px;
  height: 40px;
  border: 1px solid var(--c-line);
  border-radius: 10px;
  background: rgba(24, 40, 29, 0.8);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  color: var(--c-text);
  transition: transform 0.1s, border-color 0.15s;
}

.icon-btn:hover {
  border-color: var(--c-green);
}

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

/* ===== ステータスバー ===== */

#status-bar {
  display: flex;
  justify-content: center;
  gap: 10px;
  padding: 4px 14px 8px;
}

.status-box {
  min-width: 88px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  padding: 5px 12px;
  border: 1px solid var(--c-line);
  border-radius: 10px;
  background: rgba(24, 40, 29, 0.65);
}

.status-label {
  font-size: 10px;
  color: var(--c-dim);
  letter-spacing: 0.1em;
}

.status-value {
  font-family: var(--font-num);
  font-size: 18px;
  font-weight: bold;
  font-variant-numeric: tabular-nums;
  color: var(--c-text);
}

/* ===== 盤面 ===== */

#board-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px 10px 10px;
}

#game-canvas {
  display: block;
  border-radius: 14px;
  box-shadow: 0 0 0 2px rgba(88, 224, 124, 0.22), 0 0 40px rgba(88, 224, 124, 0.08), 0 14px 40px rgba(0, 0, 0, 0.5);
  touch-action: none;
}

/* ===== 画面オーバーレイ ===== */

.screen {
  position: fixed;
  inset: 0;
  /* フッター固定バナー広告ぶんだけ縮める（広告なしのときは 0px） */
  /* 共通ヘッダーぶんだけ下げる */
  top: var(--sgh-top, 0px);
  bottom: var(--ad-space, 0px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  padding-bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  background: rgba(6, 12, 8, 0.78);
  backdrop-filter: blur(4px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.hidden {
  display: none !important;
}

.panel {
  width: min(400px, 100%);
  margin: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: var(--c-panel);
  border: 1px solid var(--c-line);
  border-radius: 16px;
  padding: 24px 20px;
  box-shadow: 0 0 34px rgba(88, 224, 124, 0.14), 0 14px 44px rgba(0, 0, 0, 0.6);
}

.panel-center {
  text-align: center;
}

/* ---- タイトル ---- */

.title-logo {
  text-align: center;
}

.title-snake {
  font-size: 52px;
  line-height: 1;
  filter: drop-shadow(0 0 18px rgba(88, 224, 124, 0.5));
}

.title-jp {
  margin-top: 6px;
  font-size: 34px;
  letter-spacing: 0.14em;
  color: var(--c-green);
  text-shadow: 0 0 20px rgba(88, 224, 124, 0.5);
}

.title-en {
  font-size: 13px;
  letter-spacing: 0.5em;
  text-indent: 0.5em;
  color: var(--c-dim);
}

.title-desc {
  text-align: center;
  font-size: 13px;
  line-height: 1.7;
  color: var(--c-dim);
}

.title-best {
  text-align: center;
  font-size: 15px;
  color: var(--c-yellow);
  text-shadow: 0 0 14px rgba(255, 217, 61, 0.35);
}

.best-label {
  font-size: 11px;
  letter-spacing: 0.2em;
  margin-right: 6px;
}

#title-best {
  font-family: var(--font-num);
  font-size: 24px;
  font-weight: bold;
}

.best-unit {
  font-size: 12px;
  margin-left: 3px;
}

/* ---- ボタン ---- */

.btn {
  border: none;
  border-radius: 12px;
  padding: 14px;
  font-size: 16px;
  font-weight: bold;
  font-family: var(--font-jp);
  cursor: pointer;
  transition: transform 0.1s, filter 0.15s;
}

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

.btn-primary {
  background: linear-gradient(135deg, var(--c-green) 0%, var(--c-green-deep) 100%);
  color: #06230f;
  box-shadow: 0 0 22px rgba(88, 224, 124, 0.35), 0 4px 14px rgba(0, 0, 0, 0.45);
}

.btn-primary:hover {
  filter: brightness(1.1);
}

.btn-sub {
  background: rgba(28, 46, 34, 0.9);
  border: 1px solid var(--c-line);
  color: var(--c-text);
  padding: 11px;
  font-size: 14px;
}

.btn-sub:hover {
  border-color: var(--c-green);
}

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

.howto {
  border-top: 1px solid rgba(138, 167, 147, 0.2);
  padding-top: 12px;
}

.howto-title {
  font-size: 12px;
  letter-spacing: 0.2em;
  color: var(--c-dim);
  text-align: center;
  margin-bottom: 8px;
}

.howto ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.howto li {
  font-size: 12px;
  line-height: 1.6;
  color: var(--c-dim);
  padding-left: 1.2em;
  position: relative;
}

.howto li::before {
  content: "•";
  position: absolute;
  left: 0;
  color: var(--c-green);
}

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

/* ---- ポーズ ---- */

.pause-title {
  font-size: 26px;
  letter-spacing: 0.2em;
  color: var(--c-text);
}

/* ---- ゲームオーバー ---- */

.gameover-title {
  font-size: 30px;
  font-weight: bold;
  letter-spacing: 0.12em;
  color: var(--c-red);
  text-shadow: 0 0 22px rgba(255, 82, 82, 0.5);
}

.gameover-title.is-clear {
  color: var(--c-yellow);
  text-shadow: 0 0 22px rgba(255, 217, 61, 0.55);
}

.new-record {
  font-size: 14px;
  font-weight: bold;
  color: var(--c-yellow);
  text-shadow: 0 0 14px rgba(255, 217, 61, 0.5);
  animation: pulse 1.1s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

.result-score {
  font-family: var(--font-num);
  font-size: 48px;
  font-weight: bold;
  line-height: 1.1;
  color: var(--c-text);
  font-variant-numeric: tabular-nums;
}

.result-unit {
  font-size: 16px;
  margin-left: 4px;
  color: var(--c-dim);
}

.result-stats {
  display: flex;
  justify-content: center;
  gap: 8px;
}

.stat {
  min-width: 84px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 10px;
  border: 1px solid rgba(138, 167, 147, 0.25);
  border-radius: 10px;
  background: rgba(24, 40, 29, 0.6);
}

.stat-label {
  font-size: 10px;
  color: var(--c-dim);
  letter-spacing: 0.1em;
}

.stat span:last-child {
  font-family: var(--font-num);
  font-size: 17px;
  font-weight: bold;
  font-variant-numeric: tabular-nums;
}

.gameover-buttons {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ===== トースト ===== */

#toast {
  position: fixed;
  left: 50%;
  /* フッター固定バナー広告に隠れないよう持ち上げる（広告なしのときは 0px） */
  bottom: calc(76px + env(safe-area-inset-bottom, 0px) + var(--ad-space, 0px));
  transform: translateX(-50%);
  z-index: 1200;
  max-width: 90vw;
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(16, 28, 20, 0.95);
  border: 1px solid var(--c-line);
  color: var(--c-text);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
}

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

#footer {
  padding: 6px 14px calc(8px + env(safe-area-inset-bottom, 0px));
  text-align: center;
  font-size: 10px;
  line-height: 1.6;
  color: var(--c-dim);
}

#footer a {
  color: var(--c-dim);
  text-decoration: underline;
}

#footer a:hover {
  color: var(--c-green);
}

/* ===== 全国ランキング（共通モジュール 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, 8, 0.75);
  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: 1px solid var(--c-line);
  border-radius: 12px;
  padding: 20px 18px;
  box-shadow: 0 0 30px rgba(88, 224, 124, 0.16), 0 12px 40px rgba(0, 0, 0, 0.6);
}

.sgr-title {
  margin: 0;
  font-size: 20px;
  text-align: center;
  color: var(--c-text);
  text-shadow: 0 0 14px rgba(88, 224, 124, 0.4);
}

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

.sgr-tab {
  border: 1px solid rgba(138, 167, 147, 0.5);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: bold;
  font-family: var(--font-jp);
  background: rgba(24, 40, 29, 0.8);
  color: var(--c-text);
  cursor: pointer;
}

.sgr-tab-active {
  background: linear-gradient(135deg, var(--c-green) 0%, var(--c-green-deep) 100%);
  border-color: transparent;
  color: #06230f;
}

.sgr-register-msg {
  margin: 0 0 6px;
  font-size: 14px;
  font-weight: bold;
  text-align: center;
  color: var(--c-yellow);
  text-shadow: 0 0 12px rgba(255, 217, 61, 0.4);
}

.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 rgba(138, 167, 147, 0.5);
  border-radius: 8px;
  background: rgba(8, 16, 11, 0.85);
  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-green);
  box-shadow: 0 0 12px rgba(88, 224, 124, 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-green) 0%, var(--c-green-deep) 100%);
  color: #06230f;
  cursor: pointer;
}

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

.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(24, 40, 29, 0.7);
}

.sgr-row.sgr-row-me {
  background: linear-gradient(135deg, var(--c-green) 0%, var(--c-green-deep) 100%);
  color: #06230f;
}

.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 rgba(138, 167, 147, 0.5);
  border-radius: 8px;
  padding: 10px;
  font-size: 14px;
  font-weight: bold;
  font-family: var(--font-jp);
  background: rgba(24, 40, 29, 0.8);
  color: var(--c-text);
  cursor: pointer;
}

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

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

.sgr-cta-msg {
  margin: 0 0 6px;
  font-size: 14px;
  font-weight: bold;
  color: var(--c-yellow);
  text-shadow: 0 0 14px rgba(255, 217, 61, 0.5);
}

.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, var(--c-yellow) 0%, #ffb02e 100%);
  color: #221a04;
  cursor: pointer;
  box-shadow: 0 0 22px rgba(255, 217, 61, 0.45), 0 4px 14px rgba(0, 0, 0, 0.5);
}

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

.sgr-cta-link {
  border: none;
  background: none;
  padding: 6px;
  font-size: 13px;
  color: var(--c-green);
  text-decoration: underline;
  cursor: pointer;
}

/* ===== 横向き・小画面調整 ===== */

@media (max-height: 560px) {
  #logo { font-size: 16px; }
  .icon-btn { width: 34px; height: 34px; font-size: 15px; }
  .status-value { font-size: 15px; }
  .status-box { min-width: 72px; padding: 3px 10px; }
  #footer { font-size: 9px; padding-top: 3px; }
}

/* ==========================================================================
   フッター固定バナー広告（スマホ表示時のみ / 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; }
}
