/* ============================================
   そそげ！ウォーター - Pour Water
   ============================================ */

:root {
  --c-bg: #0b1a2c;
  --c-bg2: #133a56;
  --c-cyan: #4fd6ff;
  --c-blue: #2f9bf0;
  --c-ink: #ffd166;
  --c-pink: #ff5da2;
  --c-green: #6ee7a8;
  --c-text: #eaf6ff;
  --c-dim: #8aa8c2;
  --font-num: 'Avenir Next', 'Helvetica Neue', Arial, sans-serif;
  --font-jp: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Hiragino Maru Gothic ProN', 'Hiragino Kaku Gothic ProN', 'BIZ UDGothic', Meiryo, sans-serif;
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--c-bg);
  font-family: var(--font-jp);
  color: var(--c-text);
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

#game-container {
  position: fixed;
  inset: 0;
  /* 共通ヘッダーぶんだけ下げ、フッター固定バナー広告ぶんだけ縮める（広告なしのときは 0px） */
  top: var(--sgh-top, 0px);
  bottom: var(--ad-space, 0px);
  overflow: hidden;
}

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

.hidden { display: none !important; }

/* ---------- 共通ボタン ---------- */
.btn {
  border: none;
  border-radius: 999px;
  padding: 12px 26px;
  font-size: clamp(14px, 3.2vw, 17px);
  font-weight: bold;
  font-family: var(--font-jp);
  cursor: pointer;
  transition: filter 0.15s, transform 0.08s;
  white-space: nowrap;
}
.btn:active { transform: scale(0.95); }
.btn:hover { filter: brightness(1.1); }
.btn:disabled { opacity: 0.42; cursor: default; filter: saturate(0.4); }
.btn:disabled:active { transform: none; }

.btn-primary {
  background: linear-gradient(135deg, var(--c-cyan) 0%, var(--c-blue) 100%);
  color: #03243c;
  box-shadow: 0 4px 0 rgba(11, 60, 100, 0.75), 0 0 22px rgba(79, 214, 255, 0.35);
}
.btn-primary:active { box-shadow: 0 1px 0 rgba(11, 60, 100, 0.75); }

.btn-sub {
  background: rgba(24, 56, 84, 0.85);
  color: var(--c-text);
  border: 1px solid rgba(122, 190, 226, 0.4);
}

.btn-big { padding: 16px 56px; font-size: clamp(17px, 4.4vw, 22px); }

.btn[aria-pressed="true"] {
  background: linear-gradient(135deg, var(--c-ink) 0%, #ff9f43 100%);
  color: #3a2100;
  border-color: transparent;
}

.icon-btn {
  position: absolute;
  top: 6px;
  right: 8px;
  z-index: 40;
  width: 38px;
  height: 38px;
  border: 1px solid rgba(122, 190, 226, 0.35);
  border-radius: 10px;
  background: rgba(11, 26, 44, 0.7);
  color: var(--c-text);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
}
.icon-btn:active { transform: scale(0.92); }

/* ---------- プレイ中のUI ---------- */
#play-ui {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  pointer-events: none;
}

.play-top {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 52px 6px 8px;
  min-height: 44px;
}

.chip-btn {
  pointer-events: auto;
  flex: none;
  border: 1px solid rgba(122, 190, 226, 0.4);
  border-radius: 8px;
  background: rgba(11, 26, 44, 0.75);
  color: var(--c-text);
  font-family: var(--font-jp);
  font-size: 12px;
  padding: 7px 10px;
  cursor: pointer;
}
.chip-btn:active { transform: scale(0.94); }

.stage-label {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}
#hud-stage-no {
  font-family: var(--font-num);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--c-cyan);
}
#hud-stage-name {
  font-size: 14px;
  font-weight: bold;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hud-gems { display: flex; gap: 3px; flex: none; font-size: 15px; }
.hud-gems .gem-dot { opacity: 0.28; transition: opacity 0.2s, transform 0.2s; }
.hud-gems .gem-dot.got { opacity: 1; transform: scale(1.15); }

.play-bottom {
  padding: 6px 10px max(8px, env(safe-area-inset-bottom));
  background: linear-gradient(to top, rgba(6, 18, 32, 0.92) 55%, rgba(6, 18, 32, 0));
}

/* 横長の画面でもゲージ・ボタンが間のびしないように幅を制限する */
.gauges, .play-buttons { width: min(560px, 100%); margin-left: auto; margin-right: auto; }

/* 縦の余白を節約するため、2つのゲージは横に並べる */
.gauges { display: flex; gap: 14px; margin-bottom: 7px; }

.gauge { flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px; }
.gauge-label { flex: none; font-size: 11px; color: var(--c-dim); }
.gauge-num {
  flex: none;
  text-align: right;
  font-family: var(--font-num);
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.bar {
  position: relative;
  flex: 1;
  height: 9px;
  border-radius: 999px;
  background: rgba(10, 30, 50, 0.9);
  box-shadow: inset 0 0 0 1px rgba(122, 190, 226, 0.25);
  overflow: hidden;
}
.bar-fill {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 100%;
  border-radius: 999px;
  transition: width 0.12s linear;
}
.bar-ink { background: linear-gradient(90deg, #ff9f43, var(--c-ink)); }
.bar-water { background: linear-gradient(90deg, var(--c-blue), var(--c-cyan)); width: 0; }
/* 目標に届いたあとも注ぎ続けるとボーナスになるので、達成を色で知らせる */
.bar-water.done { background: linear-gradient(90deg, #2b7f63, var(--c-green)); }
.bar-need {
  position: absolute;
  top: -2px; bottom: -2px;
  width: 2px;
  margin-left: -1px; /* left（JSが必要量の位置に設定する）を目盛りの中心に合わせる */
  background: #fff;
  opacity: 0.85;
}

.play-buttons {
  display: flex;
  gap: 6px;
  justify-content: center;
  flex-wrap: wrap;
  pointer-events: auto;
}
.play-buttons .btn { padding: 10px 13px; font-size: clamp(12px, 3vw, 15px); }
/* 幅の狭い端末では、そそぐ以外のボタンはアイコンだけにして1行に収める
   （読み上げ用のラベルは aria-label に残してある） */
@media (max-width: 430px) {
  .play-buttons .bl { display: none; }
  .play-buttons .btn-sub { padding: 10px 15px; font-size: 15px; }
}

/* ---------- 画面（オーバーレイ） ---------- */
.screen {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  /* 内容が画面より高いときは上端が切れないようにする（safe 非対応でも center にフォールバック） */
  justify-content: center;
  justify-content: safe center;
  gap: 14px;
  padding: 16px;
  padding-top: max(16px, env(safe-area-inset-top));
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  text-align: center;
  overflow-y: auto;
  /* 背後ではステージ1のデモが流れているので、うっすら透かす */
  background: radial-gradient(ellipse at 50% 30%, rgba(19, 62, 96, 0.9) 0%, rgba(7, 18, 32, 0.94) 70%);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}

.screen-title {
  font-size: clamp(19px, 5vw, 26px);
  letter-spacing: 0.06em;
}

/* タイトル */
.title-logo { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.title-jp {
  font-size: clamp(30px, 9vw, 50px);
  line-height: 1.1;
  letter-spacing: 0.02em;
  color: #fff;
  text-shadow: 0 0 18px rgba(79, 214, 255, 0.65), 0 4px 0 rgba(6, 44, 74, 0.9);
}
.title-accent {
  background: linear-gradient(180deg, #b6ecff 0%, var(--c-cyan) 55%, var(--c-blue) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.title-en {
  font-family: var(--font-num);
  font-size: clamp(11px, 3vw, 14px);
  font-weight: 700;
  letter-spacing: 0.25em;
  color: var(--c-cyan);
  opacity: 0.9;
}
.title-desc { font-size: clamp(12px, 3.2vw, 15px); color: var(--c-dim); line-height: 1.7; }

.title-stats { display: flex; gap: 22px; }
.tstat { display: flex; flex-direction: column; gap: 2px; }
.tstat-label { font-size: 10px; letter-spacing: 0.14em; color: var(--c-dim); }
.tstat span:last-child {
  font-family: var(--font-num);
  font-size: clamp(18px, 5vw, 24px);
  font-weight: 700;
  color: var(--c-cyan);
}

.title-subbuttons { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }

.title-footer {
  position: absolute;
  left: 0; right: 0;
  bottom: max(8px, env(safe-area-inset-bottom));
  font-size: 10px;
  color: var(--c-dim);
  line-height: 1.7;
}
.title-footer a { color: var(--c-dim); }

/* ステージ選択 */
.select-summary {
  display: flex;
  gap: 16px;
  font-size: 13px;
  font-family: var(--font-num);
  font-weight: 700;
  color: var(--c-cyan);
}

.stage-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 7px;
  width: min(420px, 100%);
  max-height: 62vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  position: relative;
  padding: 2px;
}

.stage-btn {
  position: relative;
  aspect-ratio: 1;
  border: 1px solid rgba(122, 190, 226, 0.35);
  border-radius: 12px;
  background: rgba(15, 42, 66, 0.9);
  color: var(--c-text);
  font-family: var(--font-jp);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 2px;
  transition: transform 0.08s, border-color 0.15s;
}
.stage-btn:active { transform: scale(0.94); }
.stage-btn .sb-no { font-family: var(--font-num); font-size: 17px; font-weight: 700; }
.stage-btn .sb-stars { font-size: 8px; letter-spacing: 0; height: 11px; white-space: nowrap; }
.stage-btn.cleared { border-color: rgba(110, 231, 168, 0.6); background: rgba(18, 58, 60, 0.9); }
.stage-btn.next { border-color: var(--c-cyan); box-shadow: 0 0 0 2px rgba(120, 220, 255, 0.35); }
.stage-btn.locked { opacity: 0.4; cursor: default; }
.stage-btn.locked .sb-no { color: var(--c-dim); }

/* クリア／失敗 */
.clear-title {
  font-family: var(--font-num);
  font-size: clamp(32px, 10vw, 52px);
  font-weight: 800;
  letter-spacing: 0.08em;
  color: #fff;
  text-shadow: 0 0 24px rgba(79, 214, 255, 0.8);
}
.fail-title { font-size: clamp(22px, 6.4vw, 30px); font-weight: bold; color: #ffb4b4; }
.fail-detail { font-family: var(--font-num); font-size: 18px; font-weight: 700; }
.fail-hint { font-size: 12px; color: var(--c-dim); }

.star-row { font-size: clamp(26px, 8vw, 38px); letter-spacing: 4px; height: 1.2em; }
.star-row .st { opacity: 0.22; }
.star-row .st.on { opacity: 1; text-shadow: 0 0 16px rgba(255, 209, 102, 0.9); }

.new-record {
  font-size: clamp(13px, 3.4vw, 16px);
  font-weight: bold;
  color: var(--c-ink);
  text-shadow: 0 0 12px rgba(255, 209, 102, 0.6);
  animation: record-blink 0.9s ease-in-out infinite;
}
@keyframes record-blink { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

.result-score { font-family: var(--font-num); font-weight: 800; }
#clear-score { font-size: clamp(34px, 11vw, 52px); color: var(--c-cyan); }
.result-unit { font-size: 0.5em; margin-left: 4px; color: var(--c-dim); }

.result-breakdown {
  list-style: none;
  width: min(280px, 90%);
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 13px;
}
.result-breakdown li {
  display: flex;
  justify-content: space-between;
  padding: 4px 10px;
  border-radius: 6px;
  background: rgba(122, 190, 226, 0.08);
}
.result-breakdown li span:last-child { font-family: var(--font-num); font-weight: 700; color: var(--c-green); }

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

/* 遊び方 */
.howto-body {
  width: min(460px, 100%);
  text-align: left;
  font-size: 13px;
  line-height: 1.8;
  color: #d5e9f7;
}
.howto-body b { color: var(--c-cyan); }
.howto-h3 {
  margin: 14px 0 4px;
  font-size: 14px;
  color: var(--c-ink);
  border-left: 3px solid var(--c-ink);
  padding-left: 8px;
}
.howto-list, .howto-icons { margin: 0 0 0 1.2em; display: flex; flex-direction: column; gap: 4px; }
.howto-icons { list-style: none; margin-left: 0; }
.howto-icons li { display: flex; gap: 8px; align-items: flex-start; }
.howto-icons li > span:last-child { flex: 1; min-width: 0; }
.hi { flex: none; width: 18px; height: 18px; border-radius: 50%; margin-top: 4px; }
.hi-fire { background: radial-gradient(circle at 50% 60%, #ffd166 0%, #ff7a3d 55%, #d83b1e 100%); }
.hi-rotor { border-radius: 4px; background: linear-gradient(135deg, #7fb3d5, #35576f); }
.hi-mover { border-radius: 4px; background: linear-gradient(135deg, #6ee7a8, #2b7f63); }
.hi-gem { background: linear-gradient(135deg, #ffa8d4, var(--c-pink)); transform: rotate(45deg); border-radius: 3px; }
kbd {
  font-family: var(--font-num);
  font-size: 11px;
  padding: 1px 5px;
  border: 1px solid rgba(122, 190, 226, 0.5);
  border-radius: 4px;
  background: rgba(10, 30, 50, 0.8);
}

/* ---------- モバイル微調整 ---------- */
@media (max-height: 620px) {
  .screen { gap: 9px; }
  .title-desc { display: none; }
  .stage-grid { max-height: 50vh; }
}

/* ---------- 全国ランキング（SGRanking 共通モジュール） ---------- */
.sgr-hidden { display: none !important; }

.sgr-overlay {
  position: fixed;
  inset: 0;
  /* フッター固定バナー広告（2147482000）より上に出す。
     広告に閉じるボタンや下位の行が隠れないようにするため */
  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(7, 18, 32, 0.75);
  backdrop-filter: blur(3px);
}

.sgr-panel {
  width: min(420px, 100%);
  max-height: min(80vh, 640px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: rgba(12, 34, 55, 0.97);
  color: var(--c-text);
  border: 1px solid rgba(79, 214, 255, 0.35);
  border-radius: 12px;
  padding: 20px 18px;
  box-shadow: 0 0 30px rgba(79, 214, 255, 0.18), 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(79, 214, 255, 0.45);
}

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

.sgr-tab {
  border: 1px solid rgba(138, 168, 194, 0.5);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: bold;
  font-family: var(--font-jp);
  background: rgba(18, 46, 72, 0.8);
  color: var(--c-text);
  cursor: pointer;
}

.sgr-tab-active {
  background: linear-gradient(135deg, var(--c-cyan) 0%, var(--c-blue) 100%);
  border-color: transparent;
  color: #03243c;
}

.sgr-register-msg {
  margin: 0 0 6px;
  font-size: 14px;
  font-weight: bold;
  text-align: center;
  color: var(--c-ink);
  text-shadow: 0 0 12px rgba(255, 209, 102, 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, 168, 194, 0.5);
  border-radius: 8px;
  background: rgba(7, 22, 38, 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-cyan);
  box-shadow: 0 0 12px rgba(79, 214, 255, 0.35);
}

.sgr-submit {
  border: none;
  border-radius: 8px;
  padding: 8px 18px;
  font-size: 14px;
  font-weight: bold;
  font-family: var(--font-jp);
  background: linear-gradient(135deg, var(--c-cyan) 0%, var(--c-blue) 100%);
  color: #03243c;
  cursor: pointer;
  transition: filter 0.15s, transform 0.1s;
}
.sgr-submit:hover { filter: brightness(1.12); }
.sgr-submit:active { transform: scale(0.95); }
.sgr-submit:disabled { opacity: 0.5; cursor: default; }

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

.sgr-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  min-height: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-variant-numeric: tabular-nums;
}

.sgr-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 14px;
}
.sgr-row:nth-child(even) { background: rgba(138, 168, 194, 0.08); }

.sgr-row-me {
  background: rgba(79, 214, 255, 0.16) !important;
  box-shadow: inset 0 0 0 1px rgba(79, 214, 255, 0.5);
}

.sgr-rank {
  width: 2em;
  text-align: center;
  font-family: var(--font-num);
  font-weight: 700;
  color: var(--c-dim);
  flex: none;
}
.sgr-rank-top1, .sgr-rank-top2, .sgr-rank-top3 { font-size: 16px; }

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

.sgr-row-score { font-family: var(--font-num); font-weight: 700; color: var(--c-cyan); flex: none; }

.sgr-close {
  border: 1px solid rgba(138, 168, 194, 0.5);
  border-radius: 999px;
  padding: 10px 0;
  font-size: 14px;
  font-weight: bold;
  font-family: var(--font-jp);
  background: rgba(18, 46, 72, 0.8);
  color: var(--c-text);
  cursor: pointer;
  transition: border-color 0.15s;
}
.sgr-close:hover { border-color: var(--c-cyan); }

/* クリア画面に差し込む登録CTA */
.sgr-cta { display: flex; flex-direction: column; gap: 6px; align-items: center; }

.sgr-cta-msg {
  margin: 0;
  font-size: clamp(13px, 2.6vw, 16px);
  font-weight: bold;
  color: var(--c-ink);
  text-shadow: 0 0 12px rgba(255, 209, 102, 0.5);
  animation: record-blink 0.9s ease-in-out infinite;
}

.sgr-cta-btn {
  border: none;
  border-radius: 999px;
  padding: 12px 36px;
  font-size: clamp(14px, 2.8vw, 17px);
  font-weight: bold;
  font-family: var(--font-jp);
  background: linear-gradient(135deg, var(--c-ink) 0%, #ff9f43 100%);
  color: #3a2100;
  cursor: pointer;
  box-shadow: 0 0 20px rgba(255, 209, 102, 0.4);
  transition: filter 0.15s, transform 0.1s;
}
.sgr-cta-btn:hover { filter: brightness(1.1); }
.sgr-cta-btn:active { transform: scale(0.95); }

.sgr-cta-link {
  border: none;
  background: none;
  font-size: 13px;
  font-family: var(--font-jp);
  color: var(--c-cyan);
  text-decoration: underline;
  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; }
}
