:root {
  --bg: #05060d;
  --bg2: #0b0f22;
  --fg: #d9e6ff;
  --dim: #6a7aa8;
  --accent: #35f0c0;
  --danger: #ff4d6d;
  --bomb: #c86bff;
  --gold: #ffd447;
  --font: "DotGothic16", "MS Gothic", "Osaka-Mono", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  /* スマホでの長押しメニュー・文字選択・ダブルタップズームを止める */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at 50% 0%, #14204a 0%, transparent 55%),
    radial-gradient(circle at 50% 100%, #1a0c2e 0%, transparent 50%),
    var(--bg);
  padding: 12px;
}

#frame {
  width: min(100%, 860px);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ---------- HUD ---------- */
#hud {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 8px 12px;
  border: 2px solid #1e2a55;
  border-radius: 8px;
  background: linear-gradient(180deg, #0d1330, #070a1c);
  letter-spacing: 0.08em;
}

.hud-cell {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: clamp(13px, 3.2vw, 18px);
  line-height: 1.1;
  min-width: 0;
}

.hud-label {
  font-size: 10px;
  color: var(--dim);
  letter-spacing: 0.2em;
}

#lives { color: var(--danger); }
#score { color: var(--accent); }
#high  { color: var(--gold); }

/* ---------- ステージ ---------- */
#stage {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  border: 2px solid #1e2a55;
  border-radius: 8px;
  overflow: hidden;
  background: #02030a;
  box-shadow: 0 0 40px rgba(53, 240, 192, 0.08) inset;
}

canvas#game {
  display: block;
  width: 100%;
  height: 100%;
  /* ステージの縦横比が 4:3 でなくても歪ませない（余白は上下または左右に出る） */
  object-fit: contain;
  image-rendering: pixelated;
  touch-action: none;
}

/* ---------- オーバーレイ ---------- */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(3, 5, 15, 0.86);
  backdrop-filter: blur(2px);
  padding: 16px;
  overflow-y: auto;
  z-index: 5;
}

.overlay.hidden { display: none; }

.panel {
  width: min(100%, 520px);
  text-align: center;
  border: 2px solid #2b3a70;
  border-radius: 10px;
  background: linear-gradient(180deg, #0b1130, #070a1c);
  padding: clamp(16px, 4vw, 28px);
  box-shadow: 0 0 30px rgba(53, 240, 192, 0.12);
}

.panel.small { max-width: 380px; }

.panel h1 {
  margin: 0 0 4px;
  font-size: clamp(26px, 7vw, 44px);
  line-height: 1.05;
  color: var(--accent);
  text-shadow: 0 0 14px rgba(53, 240, 192, 0.5);
  letter-spacing: 0.06em;
}

.panel h1 span {
  display: block;
  color: var(--bomb);
  text-shadow: 0 0 14px rgba(200, 107, 255, 0.5);
}

.panel h2 {
  margin: 0 0 10px;
  font-size: clamp(22px, 6vw, 32px);
  color: var(--danger);
  letter-spacing: 0.1em;
}

.tagline {
  margin: 0 0 14px;
  color: var(--dim);
  font-size: clamp(12px, 3vw, 14px);
  line-height: 1.7;
}

.tagline b { color: var(--bomb); }

.rules {
  list-style: none;
  margin: 0 0 18px;
  padding: 0;
  text-align: left;
  font-size: clamp(11px, 2.8vw, 13px);
  line-height: 1.9;
  color: #9db0dd;
}

.rules li { padding-left: 14px; position: relative; }
.rules li::before { content: "▸"; position: absolute; left: 0; color: var(--accent); }
.rules b { color: var(--fg); }

.score-line { margin: 6px 0; font-size: 14px; color: var(--dim); letter-spacing: 0.1em; }
.score-line b { color: var(--accent); font-size: 24px; }
.score-line.sub b { color: var(--gold); font-size: 18px; }

.record {
  color: var(--gold);
  margin: 10px 0 0;
  font-size: 14px;
  animation: blink 0.7s steps(2) infinite;
}
.record.hidden { display: none; }

@keyframes blink { 50% { opacity: 0.25; } }

.btn {
  margin-top: 18px;
  font-family: var(--font);
  font-size: clamp(15px, 4vw, 19px);
  letter-spacing: 0.24em;
  padding: 12px 34px;
  color: #04120e;
  background: var(--accent);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  box-shadow: 0 4px 0 #1a9c7c, 0 0 24px rgba(53, 240, 192, 0.35);
  transition: transform 0.06s ease, box-shadow 0.06s ease;
}

.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #1a9c7c; }

/* ---------- フッター ---------- */
#foot {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  justify-content: center;
  font-size: 11px;
  color: var(--dim);
  letter-spacing: 0.08em;
}

.power-legend { display: inline-flex; align-items: center; gap: 5px; }

.pw {
  display: inline-grid;
  place-items: center;
  width: 17px;
  height: 17px;
  border-radius: 3px;
  font-style: normal;
  font-size: 10px;
  font-weight: bold;
  color: #05060d;
}

.pw-r { background: #ffb347; }
.pw-w { background: #6fd3ff; }
.pw-p { background: #ff7ae0; }
.pw-s { background: #7dff9e; }

/* ---------- 画面下の操作ボタン（タッチ端末のみ表示） ---------- */
#controls { display: none; }

.ctl {
  font-family: var(--font);
  color: var(--fg);
  background: linear-gradient(180deg, #16204a, #0c1230);
  border: 2px solid #2b3a70;
  border-radius: 12px;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  display: grid;
  place-items: center;
  transition: transform 0.05s ease, background 0.05s ease;
}

.ctl.pressed {
  background: linear-gradient(180deg, #24356f, #131c46);
  transform: translateY(2px);
}

.ctl-move { font-size: clamp(24px, 8vw, 34px); }

.ctl-fire {
  font-size: clamp(15px, 4.4vw, 20px);
  letter-spacing: 0.16em;
  color: #04120e;
  background: linear-gradient(180deg, #4dffd0, #21c69e);
  border-color: #1a9c7c;
}

.ctl-fire.pressed { background: linear-gradient(180deg, #21c69e, #158a6d); }

.ctl-sub {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 34px;
}

.ctl-mini {
  font-family: var(--font);
  font-size: 13px;
  color: var(--dim);
  background: #0c1230;
  border: 1px solid #2b3a70;
  border-radius: 7px;
  width: 44px;
  height: 30px;
  touch-action: manipulation;
}

.ctl-mini:active { color: var(--fg); background: #16204a; }

.touch-hint { font-size: 10px; color: #4d5c86; letter-spacing: 0.06em; }

@media (hover: none) and (pointer: coarse) {
  body { padding: 6px; align-items: stretch; }

  #frame {
    height: 100svh;
    gap: 6px;
    padding-bottom: env(safe-area-inset-bottom);
  }

  #hud { padding: 6px 10px; }
  #foot { display: none; }

  /* 高さは余った分だけ使う。4:3 でなくなるぶんは canvas 側が余白で吸収する */
  #stage {
    flex: 1 1 auto;
    aspect-ratio: auto;
    min-height: 0;
  }

  #controls {
    display: grid;
    flex: 0 0 auto;
    height: clamp(116px, 21svh, 172px);
    grid-template-columns: 1fr 1.3fr 1fr;
    grid-template-rows: 1fr auto;
    gap: 8px;
  }
}

/* 横持ち。縦の余裕がないので HUD とボタンを詰め、
   ステージは縦横比を保ったまま中央に置く（左右に間延びさせない）。 */
@media (hover: none) and (pointer: coarse) and (orientation: landscape) {
  #hud { padding: 3px 10px; grid-template-columns: repeat(4, auto); justify-content: space-between; }
  .hud-cell { flex-direction: row; align-items: baseline; gap: 6px; font-size: 14px; }
  .hud-label { font-size: 9px; }

  #stage {
    align-self: center;
    width: auto;
    max-width: 100%;
    aspect-ratio: 800 / 560;
  }

  #controls {
    height: clamp(74px, 24svh, 104px);
    grid-template-rows: 1fr;
    grid-template-columns: 1fr 1.3fr 1fr auto;
  }
  .ctl-sub { grid-column: auto; flex-direction: column; gap: 4px; min-height: 0; }
  .ctl-mini { width: 38px; height: 26px; font-size: 11px; }
  .touch-hint { display: none; }
}
