/* ==============================
   共通リセット
================================= */
* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: system-ui, sans-serif;
  color: #222;

  overscroll-behavior: none;
  touch-action: manipulation;
}

/* ==============================
   レイアウト変数
================================= */
:root {
  --cols: 11;
  --gap: 2px;
  --barH: 48px;
  --tile-w: calc((100vw - 16px - (var(--cols) - 1) * var(--gap)) / var(--cols));
  --tile-h: 48px;
  /* ← 縦横比を保つ基準値 */
  --tile: min(var(--tile-w), var(--tile-h));
}

/* ==============================
   ヘッダーバー
================================= */
.topbar {
  position: sticky;
  top: 0;
  /* height: var(--barH);  ← 固定はやめる */
  display: grid;
  grid-template-columns: auto 1fr auto;
  /* 左:ステージ / 中央:ステータス / 右:ボタン */
  grid-auto-rows: auto;
  align-items: center;
  gap: 6px 8px;
  padding: 6px 8px;
  background: #fff;
  box-shadow: 0 1px 8px rgba(0, 0, 0, .08);
  z-index: 10;
  font-size: 14px;
}


.topbar .center {
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.topbar .right {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.btn {
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid #ccc;
  background: #fff;
  cursor: pointer;
}

/* ==============================
   盤面
================================= */
.wrap {
  min-height: calc(100vh - var(--barH) - 12px);
  display: grid;
  place-items: center;
  padding: 8px;
}

.board {
  display: grid;
  gap: var(--gap);
  padding: var(--gap);
  border-radius: 12px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, .06);
  max-width: calc(100vw - 16px);
}

/* ==============================
   セル
================================= */
.cell {
  position: relative;
  width: var(--tile);
  height: var(--tile);
  overflow: hidden;
}

.cell.floor {
  background: url("images/floor.png") repeat center/cover;
}

.cell.wall {
  background: url("images/wall.png") no-repeat center/cover;
}

.cell.self {
  background: url("images/self2.png") no-repeat center/cover;
}

.cell.goal {
  background: #eef2ff;
  box-shadow: inset 0 0 0 2px #6366f1;
}

.cell.goal::after {
  content: "◇";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #6366f1;
  font-weight: 700;
  font-size: clamp(14px, 3.6vw, 20px);
}

/* ==============================
   パーツ
================================= */
.box {
  position: absolute;
  inset: 0;
  background: url("images/boss.png") no-repeat center/cover;
}

/* ==============================
   プレイヤー（方向ごとの画像）
================================= */
.player {
  position: absolute;
  inset: 0;
  background: url("images/player1.png") no-repeat center/cover;
  transition: background 0.1s;
}

/* 歩行2コマ切り替え */
.player.walk1 {
  background-image: url("images/player1.png");
}

.player.walk2 {
  background-image: url("images/player2.png");
}

/* 後ろ向き */
.player.back {
  background-image: url("images/player2b.png");
}

/* 横移動 */
.player.right {
  background-image: url("images/playerside_r.png");
}

.player.left {
  background-image: url("images/playerside_l.png");
}

/* ==============================
   縦が短いスマホ向け調整
================================= */
@media (max-height: 700px) {
  :root {
    --barH: 44px;
  }

  .btn {
    padding: 6px 10px;
    font-size: 13px;
  }
}

/* 掴み中の箱ハイライト（赤を上から乗せる） */
.box.grabbed::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: rgba(255, 0, 0, .38);
  /* 赤オーバーレイ */
  mix-blend-mode: multiply;
  /* 乗算で“乗せた感じ”に */
  border: 2px solid rgba(255, 0, 0, .6);
  border-radius: 4px;
  transition: opacity .1s;
}

.howto {
  max-width: 640px;
  margin-top: 8px;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, .7);
  backdrop-filter: blur(4px);
  font-size: 13px;
  line-height: 1.5;
  color: #111;
}

@media (max-width: 420px) {
  .howto {
    font-size: 12px;
  }
}

/* ページ全体の背景レイヤー */
.page-bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  background: #b08d8d;
  /* 初期は黒など */
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}


/* ==== ボタン横並び修正 ==== */
.btn-group {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
  align-items: center;
  flex-wrap: wrap;
  /* ← 幅が足りない時は自動で下段に回る */
}

.btn-group .btn {
  font-size: 13px;
  padding: 4px 8px;
}

@media (max-width: 420px) {
  .topbar {
    grid-template-columns: 1fr;
    /* 1列グリッドにする */
    text-align: center;
  }

  .topbar .left {
    order: 1;
  }

  /* 上段: ステージ表記 */
  .topbar .center {
    order: 2;
  }

  /* 上段: ステータス */
  .topbar .btn-group {
    order: 3;
    /* 下段: ボタン */
    justify-content: center;
  }
}

/* クリア演出オーバーレイ */
.goal-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  background: rgba(0, 0, 0, 0.4);
  color: white;
  font-size: 2rem;
  font-weight: bold;
  z-index: 1000;
}

.hidden {
  display: none;
}


.goal-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.goal-card {
  min-width: min(86vw, 440px);
  padding: 20px 24px;
  border-radius: 14px;
  background: rgba(255, 255, 255, .92);
  backdrop-filter: blur(6px);
  text-align: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .18);
  animation: pop .18s ease-out;
}

.goal-title {
  font-size: 28px;
  font-weight: 800;
  color: #16a34a;
}

.goal-sub {
  margin-top: 6px;
  font-size: 14px;
  color: #111;
}

@keyframes pop {
  from {
    transform: scale(.96);
    opacity: .6
  }

  to {
    transform: scale(1);
    opacity: 1
  }
}

/* ===== ランキングパネル ===== */
.ranking {
  position: fixed;
  inset: 0;
  z-index: 999;
  display: grid;
  place-items: center;
  backdrop-filter: blur(4px);
  background: rgba(0, 0, 0, .35);
}

.ranking.hidden {
  display: none;
}

.ranking-card {
  width: min(680px, 92vw);
  max-height: min(78vh, 820px);
  overflow: auto;
  background: rgba(255, 255, 255, .92);
  border-radius: 16px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .18);
  padding: 18px 16px;
}

.ranking-card h2 {
  margin: 0 0 4px;
  font-size: 20px;
}

.ranking-card .sub {
  margin: 0 0 10px;
  color: #444;
  font-size: 13px;
}

.ranking-body {
  display: grid;
  gap: 10px;
}

.total {
  font-weight: 700;
  padding: 8px 10px;
  background: #eef2ff;
  border: 1px solid #c7d2fe;
  border-radius: 10px;
}

.list {
  display: grid;
  gap: 6px;
}

.list .row {
  display: grid;
  grid-template-columns: 100px 1fr;
  gap: 6px;
  padding: 6px 8px;
  border: 1px solid #eee;
  border-radius: 8px;
  background: #fff;
}

.row .stage {
  font-weight: 700;
  color: #111;
}

.row .time {
  color: #222;
}

.ranking-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 12px;
}

.btn.danger {
  border-color: #fca5a5;
  background: #fee2e2;
}