/* =========================================================================
   style.css — スマホ縦持ち前提のレイアウト
   ========================================================================= */

:root {
  --bg:      #141922;
  --panel:   #1e2531;
  --panel2:  #29313f;
  --line:    #3a4457;
  --text:    #e8edf5;
  --dim:     #97a3b6;
  --accent:  #48c9a9;
  --gold:    #ffd54a;
}

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

html, body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Kaku Gothic ProN",
               "Noto Sans JP", "Yu Gothic UI", "Meiryo", sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

button {
  font: inherit;
  color: inherit;
  border: none;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
button:disabled { opacity: .45; cursor: default; }

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

/* ---------- 上部HUD ---------- */
#hud {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  padding-top: calc(8px + env(safe-area-inset-top));
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  font-size: 15px;
  flex: 0 0 auto;
}
#hud .stat { display: flex; align-items: center; gap: 4px; }
#hud .stat b { font-variant-numeric: tabular-nums; min-width: 2ch; }
#hud .spacer { flex: 1; }
#hud .mini {
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 12px;      /* 指でタップしやすい高さを確保する */
  font-size: 13px;
  line-height: 1;
}
#hud .mini:active { background: var(--line); }

/* ---------- 盤面 ---------- */
#stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  background: #0f1319;
}
#cv {
  display: block;
  touch-action: none;
}

#loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--dim);
  font-size: 14px;
  background: #0f1319;
}
#loading.hidden { display: none; }

/* ウェーブ開始ボタン。盤面に重ねると最下段（拠点のマス）を塞ぐので独立した行に置く */
#waveBar {
  flex: 0 0 auto;
  display: flex;
  justify-content: center;
  padding: 8px 12px;
  background: var(--bg);
}
#waveBtn {
  min-width: 190px;
  padding: 12px 20px;
  border-radius: 26px;
  background: var(--accent);
  color: #05221b;
  font-weight: 700;
  font-size: 15px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .45);
  white-space: nowrap;
}
#waveBtn:disabled {
  background: var(--panel2);
  color: var(--dim);
  box-shadow: none;
}
#waveBtn:not(:disabled):active { transform: scale(.96); }

/* トースト */
#toast {
  position: absolute;
  left: 50%;
  top: 14px;
  transform: translate(-50%, -14px);
  padding: 8px 16px;
  border-radius: 20px;
  background: rgba(0, 0, 0, .78);
  font-size: 13px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s, transform .18s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* 結果オーバーレイ */
#overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: rgba(8, 11, 16, .85);
  text-align: center;
  padding: 20px;
}
#overlay.hidden { display: none; }
#ovTitle { font-size: 40px; letter-spacing: 2px; }
#ovSub { color: var(--dim); font-size: 14px; }
#retryBtn {
  margin-top: 6px;
  padding: 13px 30px;
  border-radius: 26px;
  background: var(--accent);
  color: #05221b;
  font-weight: 700;
}

/* ---------- あそびかた ---------- */
#help {
  position: absolute;
  inset: 0;
  z-index: 5;                 /* タワー詳細パネルより手前に出す */
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  background: rgba(8, 11, 16, .9);
}
#help.hidden { display: none; }
/* 見出しと「とじる」は固定し、本文だけスクロールさせる。
   全体をスクロールさせると閉じるボタンが画面外に出てしまうため。 */
#help .sheet {
  width: 100%;
  max-width: 340px;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 16px;
  border-radius: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
}
#help .hbody {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
#help h2 { font-size: 18px; margin-bottom: 10px; }
#help h3 { font-size: 14px; margin: 14px 0 6px; color: var(--accent); }
#help ul { list-style: none; display: flex; flex-direction: column; gap: 9px; }
#help li { font-size: 13px; line-height: 1.55; color: var(--dim); }
#help li b { display: block; color: var(--text); font-size: 13px; }
#help .htower { display: flex; align-items: center; gap: 9px; padding: 6px 0; }
#help .htower canvas { width: 34px; height: 34px; flex: 0 0 auto; }
#help .htower .ht { font-size: 12px; color: var(--dim); line-height: 1.45; }
#help .htower .ht b { color: var(--text); font-size: 13px; }
#help .htower .ht b span { color: var(--gold); margin-left: 5px; }
#helpCloseBtn {
  flex: 0 0 auto;
  width: 100%;
  margin-top: 14px;
  padding: 12px;
  border-radius: 24px;
  background: var(--accent);
  color: #05221b;
  font-weight: 700;
}

/* ---------- タワー詳細パネル ----------
   盤面の上に重ねる。通常の行にすると開閉のたびに #stage の高さが変わり、
   盤面全体がリサイズされて拡大縮小してしまうため。 */
#towerPanel {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 8px 14px 10px;
  background: rgba(30, 37, 49, .96);
  border-top: 1px solid var(--line);
}
#towerPanel.hidden { display: none; }
#closePanelBtn {
  position: absolute;
  top: 6px; right: 10px;
  font-size: 20px;
  color: var(--dim);
  padding: 2px 8px;
}
#pName  { font-size: 15px; font-weight: 700; }
#pStats { font-size: 12px; color: var(--dim); margin-top: 3px; }
.prow { display: flex; gap: 10px; margin-top: 8px; }
.prow button {
  flex: 1;
  padding: 10px 8px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 700;
}
.prow .up   { background: var(--gold); color: #2a2000; }
.prow .sell { background: var(--panel2); border: 1px solid var(--line); color: var(--text); }
.prow button:active { filter: brightness(.9); }

/* ---------- 下部ショップ ---------- */
#shop {
  display: flex;
  gap: 8px;
  padding: 9px 10px;
  padding-bottom: calc(9px + env(safe-area-inset-bottom));
  background: var(--panel);
  border-top: 1px solid var(--line);
  flex: 0 0 auto;
}
.card {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 7px 4px 8px;
  border-radius: 13px;
  background: var(--panel2);
  border: 2px solid transparent;
  transition: border-color .12s, transform .08s;
}
.card .icon { width: 42px; height: 42px; }
.card .cname { font-size: 11px; color: var(--dim); white-space: nowrap; }
.card .ccost { font-size: 12px; font-weight: 700; color: var(--gold); }
.card.sel { border-color: var(--accent); background: #24404b; }
.card.poor { opacity: .45; }
.card:active { transform: scale(.96); }

/* 横向き・大画面では盤面を中央に寄せる */
@media (min-width: 620px) {
  #app { max-width: 520px; margin: 0 auto; border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
}
