/* ============================================================
   ギリギリタワー - Tower Stack  style.css
   ============================================================ */

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

:root {
  --bg1: #10182b;
  --bg2: #1b2a4a;
  --panel: rgba(255, 255, 255, 0.06);
  --panel-border: rgba(255, 255, 255, 0.14);
  --text: #eaf0ff;
  --text-dim: #8fa0c0;
  --accent: #4da3ff;
  --accent2: #ffd166;
  --danger: #ff5d5d;
  --radius: 14px;
}

html, body {
  height: 100%;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Hiragino Kaku Gothic ProN", "Hiragino Sans", Meiryo, sans-serif;
  background: var(--bg1);
  color: var(--text);
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  overscroll-behavior: none;
  overflow: hidden;
}

.hidden { display: none !important; }

#app {
  height: calc(100dvh - var(--sgh-top, 0px) - var(--ad-space, 0px));
  display: flex;
  flex-direction: column;
  /* 上下のセーフエリアは共通ヘッダー（--sgh-top）と広告枠（--ad-space）・#footer が受け持つので左右だけ */
  padding: 0 env(safe-area-inset-right) 0 env(safe-area-inset-left);
}

/* ---------- ヘッダー ---------- */

/* タイトルだけの帯は縦幅を圧迫するので隠す（ボタンは共通ヘッダーのメニューへ集約済み）。
   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 {
  font-size: 19px;
  font-weight: 900;
  letter-spacing: 0.05em;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.45);
}

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

.icon-btn {
  width: 40px;
  height: 40px;
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  background: var(--panel);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

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

/* ---------- ステージ ---------- */

#stage-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
}

#stage {
  position: absolute;
  inset: 0;
  display: block;
  cursor: pointer;
}

/* ---------- HUD ---------- */

#hud {
  position: absolute;
  top: 4px;
  left: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  pointer-events: none;
  z-index: 3;
}

#hud-floor {
  font-weight: 900;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
}

#floor-num { font-size: 46px; line-height: 1; }
#floor-unit { font-size: 20px; margin-left: 2px; }

#hud-score {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-dim);
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.5);
}

#hud-score span { color: var(--text); }

#fever-gauge {
  position: relative;
  width: min(240px, 60vw);
  height: 18px;
  margin-top: 2px;
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.35);
  overflow: hidden;
}

#fever-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
  background: linear-gradient(90deg, #ffd166, #ff8f5d);
  transition: width 0.25s ease;
}

#fever-gauge.fever-on #fever-fill {
  background: linear-gradient(90deg, #ff7ad9, #7a9dff, #7affd4);
  transition: none;
}

#fever-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
}

/* ---------- 画面オーバーレイ（タイトル・リザルト） ---------- */

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  /* 中央寄せは先頭・末尾の子の margin:auto で行う。ステージより高いとき（スマホの横向き等）は
     上端から並べてステージ内でスクロールさせ、ボタンがフッターや広告の下に隠れないようにする。
     縦の padding は付けない（ステージより低い中身は、従来どおりステージの中央に置いて見た目を変えないため） */
  justify-content: flex-start;
  gap: 14px;
  padding: 0 20px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  background: rgba(8, 12, 24, 0.35);
  z-index: 4;
}

.screen > * { flex-shrink: 0; }
.screen > :first-child { margin-top: auto; }
.screen > :last-child { margin-bottom: auto; }

.title-logo {
  font-size: clamp(34px, 9vw, 52px);
  font-weight: 900;
  letter-spacing: 0.02em;
  text-align: center;
  line-height: 1.1;
  filter: drop-shadow(0 4px 16px rgba(0, 0, 0, 0.55));
}

.title-giri {
  background: linear-gradient(180deg, #ffd166, #ff8f5d);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.title-tower {
  background: linear-gradient(180deg, #9ecbff, #4da3ff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.title-sub {
  font-size: 14px;
  font-weight: 700;
  text-align: center;
  line-height: 1.7;
  color: var(--text);
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.6);
}

.title-best {
  font-size: 14px;
  font-weight: 700;
  color: var(--accent2);
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.6);
}

.title-best b { font-size: 20px; }

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

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

.btn {
  border: none;
  border-radius: var(--radius);
  font-family: inherit;
  font-weight: 800;
  cursor: pointer;
  color: #fff;
}

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

.btn-big {
  padding: 14px 34px;
  font-size: 18px;
  background: linear-gradient(180deg, #5db1ff, #2f7fe0);
  box-shadow: 0 6px 20px rgba(77, 163, 255, 0.4);
  animation: pulse 1.6s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.045); }
}

.btn-sub {
  padding: 10px 18px;
  font-size: 14px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  color: var(--text);
}

.btn-mini {
  padding: 6px 14px;
  font-size: 13px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  color: var(--text);
}

/* ---------- リザルト ---------- */

#result-box {
  width: min(360px, 92%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  background: linear-gradient(180deg, #223154, #16203a);
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  padding: 22px 18px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

#result-title {
  font-size: 22px;
  font-weight: 900;
}

#result-new {
  font-size: 14px;
  font-weight: 800;
  color: var(--accent2);
  animation: pulse 1.2s ease-in-out infinite;
}

#result-floor-row {
  font-weight: 900;
  line-height: 1;
}

#result-floor { font-size: 58px; }
.result-unit { font-size: 24px; margin-left: 4px; }

#result-stats {
  width: 100%;
  display: flex;
  justify-content: space-around;
  gap: 6px;
  padding: 10px 0;
  border-top: 1px solid var(--panel-border);
  border-bottom: 1px solid var(--panel-border);
}

.rstat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.rstat-label { font-size: 11px; color: var(--text-dim); font-weight: 700; }
.rstat span:last-child { font-size: 16px; font-weight: 800; }

#result-unlock {
  font-size: 13px;
  font-weight: 800;
  color: #8affa6;
  text-align: center;
}

#result-buttons {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}

/* ---------- モーダル ---------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  background: rgba(8, 12, 24, 0.72);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.modal-box {
  width: min(420px, 100%);
  max-height: min(84vh, 680px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: linear-gradient(180deg, #223154, #16203a);
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  padding: 20px 18px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.modal-title {
  font-size: 20px;
  font-weight: 900;
  text-align: center;
}

.menu-section { display: flex; flex-direction: column; gap: 8px; }

.menu-caption {
  font-size: 12px;
  font-weight: 800;
  color: var(--text-dim);
  letter-spacing: 0.06em;
}

.menu-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 14px;
  font-weight: 700;
  padding: 4px 0;
}

.howto {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--text);
}

.howto li {
  padding-left: 1.1em;
  position: relative;
}

.howto li::before {
  content: "▸";
  position: absolute;
  left: 0;
  color: var(--accent);
}

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

/* トグル */

.toggle {
  position: relative;
  width: 48px;
  height: 28px;
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.35);
  cursor: pointer;
  transition: background 0.2s;
}

.toggle.on { background: rgba(77, 163, 255, 0.5); }

.toggle .knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  transition: left 0.2s;
}

.toggle.on .knob { left: 22px; }

/* ---------- テーマ選択 ---------- */

.theme-note {
  font-size: 12px;
  color: var(--text-dim);
  text-align: center;
}

#theme-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.theme-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px 8px;
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  font-family: inherit;
  cursor: pointer;
}

.theme-card:active { transform: scale(0.97); }

.theme-card.theme-active {
  border-color: var(--accent);
  background: rgba(77, 163, 255, 0.16);
}

.theme-card.theme-locked { opacity: 0.55; }

.theme-swatch {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  box-shadow: inset 0 -6px 0 rgba(0, 0, 0, 0.2);
}

.theme-name { font-size: 14px; font-weight: 800; }

.theme-cond { font-size: 11px; color: var(--text-dim); }

/* ---------- トースト ---------- */

#toast {
  position: fixed;
  left: 50%;
  /* フッター固定バナー広告に隠れないよう持ち上げる（広告なしのときは 0px） */
  bottom: calc(70px + env(safe-area-inset-bottom, 0px) + var(--ad-space, 0px));
  transform: translateX(-50%);
  z-index: 70;
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(10, 16, 32, 0.92);
  border: 1px solid var(--panel-border);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

/* ---------- フッター ---------- */

#footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom, 0px));
  font-size: 11px;
  color: var(--text-dim);
  z-index: 5;
}

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

/* 広告があるときは、下のセーフエリアを広告枠（--ad-space）が確保している */
html.has-ad-banner #footer { padding-bottom: 8px; }

/* ---------- 全国ランキング（SGRanking 共通モジュール） ---------- */

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

.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(8, 12, 24, 0.72);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.sgr-panel {
  width: min(420px, 100%);
  max-height: min(80vh, 640px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: linear-gradient(180deg, #223154, #16203a);
  color: var(--text);
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  padding: 20px 18px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

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

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

.sgr-tab {
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  padding: 6px 14px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 800;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}

.sgr-tab-active {
  background: rgba(77, 163, 255, 0.18);
  border-color: var(--accent);
  color: var(--accent);
}

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

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

.sgr-name {
  flex: 1;
  min-width: 0;
  font-family: inherit;
  font-size: 16px;
  padding: 8px 10px;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.35);
  color: var(--text);
}

.sgr-name:focus { outline: none; border-color: var(--accent); }

.sgr-submit {
  border: none;
  border-radius: 10px;
  padding: 8px 16px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 800;
  background: linear-gradient(180deg, #5db1ff, #2f7fe0);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(77, 163, 255, 0.35);
}

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

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

.sgr-error {
  margin: 4px 0 0;
  font-size: 12px;
  font-weight: 700;
  color: var(--danger);
}

.sgr-status {
  margin: 0;
  font-size: 13px;
  color: var(--text-dim);
  text-align: center;
}

.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: 8px;
  font-size: 14px;
}

.sgr-row:nth-child(even) { background: rgba(255, 255, 255, 0.05); }

.sgr-row.sgr-row-me {
  background: rgba(77, 163, 255, 0.25);
  color: #fff;
}

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

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

.sgr-row-score {
  font-weight: 800;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

.sgr-close {
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 10px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 800;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}

.sgr-cta {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

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

.sgr-cta-btn {
  border: none;
  border-radius: var(--radius);
  padding: 10px 20px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 800;
  background: linear-gradient(180deg, #ffcf5d, #e09a2f);
  color: #3a2a08;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(255, 209, 102, 0.35);
}

.sgr-cta-link {
  border: none;
  background: none;
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  text-decoration: underline;
  cursor: pointer;
}

/* 高さの低い画面（スマホの横向きなど）: タイトル・結果を詰めて、なるべくスクロールせずに収める */
@media (max-height: 480px) {
  .screen { gap: 8px; }
  .title-logo { font-size: 34px; }
  #result-box { gap: 6px; padding: 12px 16px; }
  #result-floor { font-size: 40px; }
}

/* ---------- PC ---------- */

@media (min-width: 700px) {
  #logo { font-size: 22px; }
  #floor-num { font-size: 54px; }
}

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