/* ============================================================
   バトルシップ - style.css
   ネイビー×シアンの海戦テーマ。スマホ縦持ち基準、PCは2面横並び
   ============================================================ */

:root {
  --bg1: #081826;
  --bg2: #0d2438;
  --panel: #11304a;
  --panel-light: #17405f;
  --line: #1f4d70;
  --sea: #0e3a5c;
  --sea-hover: #155081;
  --text: #dcedf7;
  --text-dim: #8fb2c9;
  --accent: #3fc1ff;
  --accent-deep: #1e88c9;
  --hit: #ff5252;
  --sunk: #b71c1c;
  --ship: #7d95a8;
  --good: #46d68c;
  --shadow: 0 6px 24px rgba(0, 0, 0, .45);
  --radius: 14px;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

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: linear-gradient(170deg, var(--bg1), var(--bg2) 60%, #0a2c44);
  color: var(--text);
  min-height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

#app {
  max-width: 560px;
  margin: 0 auto;
  padding: 8px 10px 16px;
  display: flex;
  flex-direction: column;
  min-height: calc(100dvh - var(--sgh-top, 0px) - var(--ad-space, 0px));
}

.hidden { display: none !important; }

button { font-family: inherit; cursor: pointer; }

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

#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 2px 8px;
}

#logo-wrap { display: flex; align-items: center; gap: 10px; }

#logo {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: .04em;
  background: linear-gradient(180deg, #bfe7ff, var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

#diff-badge {
  background: var(--panel-light);
  border: 1px solid var(--line);
  color: var(--text-dim);
  font-size: .72rem;
  font-weight: 700;
  border-radius: 999px;
  padding: 4px 10px;
}

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

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  font-size: 1.05rem;
  display: grid;
  place-items: center;
  color: var(--text);
}

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

/* ---------- 共通ボタン ---------- */

.btn {
  border: none;
  border-radius: 12px;
  font-size: .95rem;
  font-weight: 700;
  padding: 12px 18px;
  color: #fff;
  transition: transform .08s;
}

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

.btn-primary {
  background: linear-gradient(180deg, var(--accent), var(--accent-deep));
  color: #04233a;
  box-shadow: 0 4px 14px rgba(63, 193, 255, .35);
}

.btn-primary:disabled {
  background: var(--panel-light);
  color: var(--text-dim);
  box-shadow: none;
  cursor: default;
  opacity: .6;
}

.btn-sub {
  background: var(--panel-light);
  border: 1px solid var(--line);
  color: var(--text);
}

.btn-wide { width: 100%; margin-top: 10px; }

/* ---------- 盤面 ---------- */

.board {
  display: grid;
  grid-template-columns: minmax(12px, .55fr) repeat(10, 1fr);
  grid-template-rows: minmax(12px, .55fr) repeat(10, 1fr);
  gap: 2px;
  background: rgba(8, 24, 38, .55);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 6px;
  width: 100%;
  aspect-ratio: 11 / 11;
}

.lbl {
  display: grid;
  place-items: center;
  font-size: clamp(.5rem, 2.4vw, .7rem);
  font-weight: 700;
  color: var(--text-dim);
}

.cell {
  position: relative;
  border: none;
  border-radius: 4px;
  background:
    radial-gradient(circle at 30% 30%, rgba(255, 255, 255, .06), transparent 60%),
    var(--sea);
  display: grid;
  place-items: center;
  font-size: clamp(.6rem, 3.2vw, 1rem);
  color: var(--text);
  padding: 0;
  min-width: 0;
  min-height: 0;
}

button.cell:not(:disabled):hover { background: var(--sea-hover); }

/* 自艦マス */
.cell.ship {
  background: linear-gradient(180deg, #93abc0, var(--ship));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .25);
}

/* ハズレ */
.cell.miss { background: var(--sea); }
.cell.miss::after {
  content: "";
  width: 26%;
  height: 26%;
  border-radius: 50%;
  background: rgba(220, 237, 247, .55);
}

/* 命中 */
.cell.hit {
  background: linear-gradient(180deg, #ff7961, var(--hit));
}
.cell.hit::after { content: "💥"; font-size: .85em; }

/* 撃沈艦 */
.cell.sunk {
  background: linear-gradient(180deg, #d32f2f, var(--sunk));
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .35);
}
.cell.sunk::after { content: "💀"; font-size: .8em; }

/* 自艦が被弾 */
.cell.ship.hit { background: linear-gradient(180deg, #ff8a65, #e64a19); }

/* 配置プレビュー */
.cell.ghost-ok { background: rgba(70, 214, 140, .55); box-shadow: inset 0 0 0 2px var(--good); }
.cell.ghost-ng { background: rgba(255, 82, 82, .5); box-shadow: inset 0 0 0 2px var(--hit); }

/* 直近の砲撃マス */
.cell.last-shot { animation: pop .35s ease; z-index: 1; }

@keyframes pop {
  0% { transform: scale(.55); }
  60% { transform: scale(1.25); }
  100% { transform: scale(1); }
}

/* 盤面シェイク（被弾時） */
.board.shake { animation: shake .3s ease; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

/* ---------- 配置フェーズ ---------- */

#screen-setup { display: flex; flex-direction: column; }

#setup-status {
  text-align: center;
  font-size: .95rem;
  font-weight: 700;
  color: var(--text-dim);
  padding: 4px 0 10px;
}

#ship-dock {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  margin-top: 12px;
}

.ship-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 7px 9px;
  color: var(--text);
  font-size: .72rem;
  font-weight: 700;
}

.ship-btn .segs { display: flex; gap: 2px; }

.ship-btn .seg {
  width: 9px;
  height: 9px;
  border-radius: 2px;
  background: var(--ship);
}

.ship-btn.selected {
  border-color: var(--accent);
  background: var(--panel-light);
  box-shadow: 0 0 0 2px rgba(63, 193, 255, .35);
}

.ship-btn.placed { opacity: .45; }
.ship-btn.placed .seg { background: var(--good); }

#setup-controls {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-top: 12px;
}

#setup-controls .btn { padding: 10px 12px; font-size: .82rem; flex: 1; max-width: 150px; }

/* ---------- 戦闘フェーズ ---------- */

#battle-status {
  text-align: center;
  font-size: .95rem;
  font-weight: 700;
  min-height: 1.5em;
  padding: 2px 0 10px;
  color: var(--accent);
}

#battle-status.enemy-turn { color: var(--hit); }

#boards-wrap { display: flex; flex-direction: column; gap: 14px; }

.area-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  padding: 0 2px 6px;
}

.area-title { font-size: .82rem; font-weight: 700; color: var(--text-dim); }

.fleet-chips { display: flex; gap: 4px; }

.fleet-chip {
  display: flex;
  gap: 1.5px;
  padding: 3px 4px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
}

.fleet-chip .seg {
  width: 6px;
  height: 6px;
  border-radius: 1.5px;
  background: var(--accent);
}

.fleet-chip.sunk { opacity: .55; }
.fleet-chip.sunk .seg { background: var(--hit); }

#my-area { max-width: 340px; margin: 0 auto; width: 88%; }

#battle-info {
  display: flex;
  justify-content: center;
  gap: 24px;
  padding: 12px 0 4px;
  font-size: .82rem;
  color: var(--text-dim);
}

#battle-info b { color: var(--text); font-size: .95rem; }

/* ---------- 結果オーバーレイ ---------- */

#result-overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 15, 25, .75);
  display: grid;
  place-items: center;
  z-index: 30;
  padding: 20px;
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}

#result-box {
  background: linear-gradient(180deg, var(--panel-light), var(--panel));
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 26px 22px;
  width: min(92vw, 360px);
  text-align: center;
  animation: rise .35s ease;
}

@keyframes rise {
  from { transform: translateY(24px) scale(.96); opacity: 0; }
  to { transform: none; opacity: 1; }
}

#result-title { font-size: 1.7rem; font-weight: 800; }
#result-title.lose { color: var(--hit); }
#result-title.win { color: var(--good); }

#result-sub { color: #ffd54f; font-weight: 700; font-size: .85rem; margin-top: 6px; }

#result-main-row { margin: 14px 0 4px; }

#result-shots { font-size: 2.4rem; font-weight: 800; color: var(--accent); }

.result-unit { font-size: .85rem; color: var(--text-dim); margin-left: 6px; }

#result-stats {
  display: flex;
  justify-content: center;
  gap: 20px;
  margin: 14px 0 18px;
}

.rstat { display: flex; flex-direction: column; gap: 2px; }
.rstat-label { font-size: .68rem; color: var(--text-dim); }
.rstat span:last-child { font-weight: 700; }

#result-buttons { display: flex; gap: 10px; justify-content: center; }

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

.modal {
  position: fixed;
  inset: 0;
  background: rgba(5, 15, 25, .7);
  display: grid;
  place-items: center;
  z-index: 40;
  padding: 16px;
}

.modal-box {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 20px 18px;
  width: min(94vw, 420px);
  max-height: 86dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.modal-title { font-size: 1.1rem; font-weight: 800; text-align: center; margin-bottom: 14px; }

.menu-section { margin-bottom: 16px; }

.menu-caption {
  font-size: .72rem;
  font-weight: 700;
  color: var(--text-dim);
  margin-bottom: 8px;
  letter-spacing: .05em;
}

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

.diff-btn {
  flex: 1;
  background: var(--panel-light);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  font-size: .8rem;
  font-weight: 700;
  padding: 10px 4px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.diff-btn small { font-size: .62rem; font-weight: 400; color: var(--text-dim); }

.diff-btn.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(63, 193, 255, .35);
}

.menu-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 2px;
  font-size: .88rem;
}

.toggle {
  width: 46px;
  height: 26px;
  border-radius: 999px;
  background: var(--panel-light);
  border: 1px solid var(--line);
  position: relative;
  transition: background .15s;
}

.toggle .knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--text-dim);
  transition: transform .15s, background .15s;
}

.toggle.on { background: var(--accent-deep); }
.toggle.on .knob { transform: translateX(20px); background: #fff; }

#stats-list { font-size: .82rem; }

.stats-row {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr 1fr;
  padding: 5px 2px;
  border-bottom: 1px solid rgba(31, 77, 112, .5);
}

.stats-row span:not(:first-child) { text-align: center; }

.stats-head { color: var(--text-dim); font-size: .7rem; border-bottom: 1px solid var(--line); }

.howto { padding-left: 1.2em; font-size: .8rem; line-height: 1.7; color: var(--text-dim); }
.howto b { color: var(--text); }

/* 背の低い画面（スマホ横向き・小型端末）: 結果画面・メニューが共通ヘッダーと下部広告の下に潜り、
   「もう一度」「閉じる」に届かなくなるため、ヘッダーと広告の間に収めてはみ出すぶんはスクロールさせる */
@media (max-height: 600px) {
  #result-overlay,
  .modal {
    top: var(--sgh-top, 0px);
    bottom: var(--ad-space, 0px);
  }
  #result-overlay { overflow-y: auto; }
  .modal-box { max-height: calc(100dvh - var(--sgh-top, 0px) - var(--ad-space, 0px) - 32px); }
}

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

#toast {
  position: fixed;
  left: 50%;
  /* フッター固定バナー広告に隠れないよう持ち上げる（広告なしのときは 0px） */
  bottom: calc(90px + env(safe-area-inset-bottom) + var(--ad-space, 0px));
  transform: translateX(-50%);
  background: rgba(9, 30, 48, .95);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: .85rem;
  font-weight: 700;
  padding: 10px 18px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  z-index: 50;
  white-space: nowrap;
  animation: toast-in .25s ease;
  pointer-events: none;
}

@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

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

#footer {
  margin-top: auto;
  padding: 20px 0 8px;
  text-align: center;
  font-size: .68rem;
  color: var(--text-dim);
  line-height: 1.8;
}

#footer a { color: var(--accent); text-decoration: none; }

/* ---------- PC レイアウト ---------- */

@media (min-width: 900px) {
  #app { max-width: 960px; }

  #boards-wrap {
    flex-direction: row;
    align-items: flex-start;
    justify-content: center;
    gap: 28px;
  }

  #enemy-area { flex: 1.2; max-width: 460px; }

  #my-area { flex: 1; max-width: 380px; width: auto; margin: 0; }

  #screen-setup { max-width: 460px; margin: 0 auto; width: 100%; }

  .cell { font-size: 1rem; }
}

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