/* バブルパズル - Bubble Puzzle */

:root {
  --color-bg: #eef6fd;
  --color-text: #234157;
  --color-text-light: #ffffff;
  --color-accent: #2f9fe0;
  --color-accent-hover: #1e86c4;
  --color-cell: #dcecf9;
  --color-board: #c3dcf1;
  --color-panel: #ffffff;
}

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

html {
  height: 100%;
}

body {
  min-height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Kaku Gothic ProN", "Noto Sans JP", Meiryo, sans-serif;
  background: linear-gradient(165deg, #e8f4ff 0%, #f2fbff 45%, #e6f7f4 100%);
  color: var(--color-text);
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

[hidden] {
  display: none !important;
}

.app {
  max-width: 520px;
  margin: 0 auto;
  padding: 10px 12px;
  padding-left: calc(12px + env(safe-area-inset-left, 0px));
  padding-right: calc(12px + env(safe-area-inset-right, 0px));
  padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  min-height: calc(100dvh - var(--sgh-top, 0px) - var(--ad-space, 0px));
}

/* ---------- ヘッダー ---------- */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 4px 2px 8px;
}

.title {
  font-size: 23px;
  font-weight: 800;
  letter-spacing: 0.02em;
  background: linear-gradient(115deg, #2f9fe0, #34c9b6 55%, #6f8cff 95%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  white-space: nowrap;
}

.scores {
  display: flex;
  gap: 6px;
}

.score-box {
  min-width: 60px;
  padding: 5px 9px;
  border-radius: 9px;
  background: var(--color-panel);
  box-shadow: 0 2px 6px rgba(35, 65, 87, 0.1);
  text-align: center;
}

.score-label {
  font-size: 10px;
  letter-spacing: 0.06em;
  opacity: 0.7;
}

.score-value {
  font-size: 17px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.25;
}

/* ---------- 盤面 ---------- */
main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
}

/* 盤面はヘッダー・ゲージ・操作列・フッターを配置した「余り」に収める。
   決め打ちの高さを引くのではなく flex の余白を使うので、フッターが折り返す端末でも
   スクロールが出ない。実寸（2:3を保った大きさ）は js/game.js の resize() が決める */
.board-area {
  flex: 1;
  min-height: 190px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.board-wrapper {
  position: relative;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(18, 52, 80, 0.28);
  touch-action: none;
  cursor: crosshair;
}

/* ---------- 天井ゲージ ---------- */
.gauge-wrap {
  /* --board-w は js/game.js が盤面の実寸に合わせて更新する */
  width: min(100%, var(--board-w, 340px));
  margin: 0 auto;
  text-align: center;
}

.gauge-label {
  font-size: 12px;
  opacity: 0.85;
  margin-bottom: 3px;
}

.gauge-label span {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.gauge {
  height: 6px;
  border-radius: 3px;
  background: var(--color-board);
  overflow: hidden;
}

.gauge-bar {
  height: 100%;
  width: 100%;
  border-radius: 3px;
  background: linear-gradient(90deg, #34c9b6, #2f9fe0);
  transition: width 0.18s ease;
}

.gauge-bar-warn {
  background: linear-gradient(90deg, #ffa63c, #ff5a6e);
}

/* ---------- 操作列 ---------- */
.sub-header {
  text-align: center;
}

.description {
  font-size: 13px;
  margin-bottom: 7px;
  opacity: 0.9;
}

.description strong {
  color: var(--color-accent-hover);
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  justify-content: center;
}

.btn {
  border: none;
  border-radius: 9px;
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: background-color 0.15s ease, transform 0.1s ease;
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: var(--color-accent);
  color: var(--color-text-light);
  box-shadow: 0 2px 8px rgba(47, 159, 224, 0.4);
}

.btn-primary:hover {
  background: var(--color-accent-hover);
}

.btn-secondary {
  background: var(--color-cell);
  color: var(--color-text);
}

.btn-secondary:hover {
  background: var(--color-board);
}

.btn-icon {
  min-width: 42px;
  font-size: 15px;
}

.btn:focus-visible {
  outline: 3px solid rgba(47, 159, 224, 0.55);
  outline-offset: 2px;
}

/* ---------- フッター ---------- */
.footer {
  margin-top: 10px;
  text-align: center;
  font-size: 11px;
  line-height: 1.7;
  opacity: 0.8;
}

.footer a {
  color: inherit;
}

.footer-credits {
  margin-top: 6px;
}

/* ---------- 結果オーバーレイ ---------- */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  border-radius: 12px;
  background: rgba(10, 32, 56, 0.82);
  animation: fade-in 0.25s ease;
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.overlay-content {
  width: 100%;
  max-height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  text-align: center;
  color: var(--color-text-light);
}

.overlay-title {
  font-size: 21px;
  margin-bottom: 6px;
}

.overlay-message {
  font-size: 13px;
  line-height: 1.7;
  margin-bottom: 10px;
}

.overlay-buttons {
  display: flex;
  justify-content: center;
  gap: 8px;
}

.overlay-credits {
  margin-top: 14px;
  font-size: 10px;
  line-height: 1.7;
  opacity: 0.75;
}

.overlay-credits a {
  color: inherit;
}

/* ---------- 遊び方モーダル ---------- */
.howto-overlay {
  position: fixed;
  inset: 0;
  z-index: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  background: rgba(18, 52, 80, 0.55);
}

.howto-panel {
  width: min(420px, 100%);
  max-height: min(84vh, 640px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--color-bg);
  border-radius: 12px;
  padding: 20px 18px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.howto-title {
  font-size: 19px;
  text-align: center;
}

.howto-list {
  padding-left: 20px;
  font-size: 13px;
  line-height: 1.85;
}

.howto-list strong {
  color: var(--color-accent-hover);
}

.howto-controls {
  font-size: 13px;
  line-height: 1.8;
  background: var(--color-cell);
  border-radius: 10px;
  padding: 10px 12px;
}

/* ---------- 全国ランキング（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(18, 52, 80, 0.6);
}

.sgr-panel {
  width: min(420px, 100%);
  max-height: min(80vh, 640px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--color-bg);
  color: var(--color-text);
  border-radius: 12px;
  padding: 20px 18px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3);
}

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

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

.sgr-tab {
  border: none;
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: bold;
  background: var(--color-cell);
  color: var(--color-text);
  cursor: pointer;
}

.sgr-tab-active {
  background: var(--color-accent);
  color: var(--color-text-light);
}

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

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

.sgr-name {
  flex: 1;
  min-width: 0;
  font-size: 16px;
  padding: 8px 10px;
  border: 2px solid var(--color-board);
  border-radius: 8px;
  background: #fff;
  color: var(--color-text);
  font-family: inherit;
}

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

.sgr-submit {
  border: none;
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 15px;
  font-weight: bold;
  font-family: inherit;
  background: var(--color-accent);
  color: var(--color-text-light);
  cursor: pointer;
}

.sgr-submit:hover {
  background: var(--color-accent-hover);
}

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

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

.sgr-status {
  margin: 0;
  font-size: 13px;
  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: 6px;
  font-size: 14px;
}

.sgr-row:nth-child(even) {
  background: var(--color-cell);
}

.sgr-row.sgr-row-me {
  background: var(--color-accent);
  color: var(--color-text-light);
}

.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;
  flex-shrink: 0;
}

.sgr-close {
  border: none;
  border-radius: 8px;
  padding: 10px;
  font-size: 14px;
  font-weight: bold;
  font-family: inherit;
  background: var(--color-cell);
  color: var(--color-text);
  cursor: pointer;
}

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

.sgr-cta-msg {
  margin: 0 0 6px;
  font-size: 14px;
  font-weight: bold;
}

.sgr-cta-btn {
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 15px;
  font-weight: bold;
  font-family: inherit;
  background: var(--color-accent);
  color: var(--color-text-light);
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(47, 159, 224, 0.5);
}

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

/* ---------- モーション低減設定 ---------- */
@media (prefers-reduced-motion: reduce) {
  .overlay {
    animation-duration: 1ms;
  }
  .btn,
  .gauge-bar {
    transition: none;
  }
}

/* ---------- 狭い画面の微調整 ---------- */
@media (max-width: 360px) {
  .title {
    font-size: 19px;
  }
  .score-box {
    min-width: 52px;
    padding: 4px 6px;
  }
  .score-value {
    font-size: 15px;
  }
  .btn {
    padding: 8px 11px;
    font-size: 12px;
  }
}

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