:root {
  --ink: #1b1030;
  --gold: #ffd23e;
  --gold-dk: #b8851a;
  --pink: #ff5fa2;
  --frame: #2b1d4d;
  --frame-lt: #4a3380;
}

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

html,
body {
  height: 100%;
}

body {
  font-family: "DotGothic16", "Hiragino Kaku Gothic ProN", sans-serif;
  background: #0b0818;
  color: #fff;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  image-rendering: pixelated;
}

/* CRT 風スキャンライン — 画面全体 */
.crt {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
}
.crt::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0) 0px,
    rgba(0, 0, 0, 0) 2px,
    rgba(0, 0, 0, 0.14) 3px
  );
  z-index: 50;
  mix-blend-mode: multiply;
}

#app {
  width: 100%;
  height: 100%;
  text-align: center;
}

/* ----- ゲーム画面(ステージ) — 画面全体に広げる ----- */
#stage {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #243b6b;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: none;
  cursor: crosshair;
}

/* ----- ハンバーガーメニューボタン ----- */
.menu-btn {
  position: absolute;
  top: calc(8px + env(safe-area-inset-top, 0px));
  right: calc(8px + env(safe-area-inset-right, 0px));
  z-index: 60;
  width: 44px;
  height: 44px;
  margin: 0;
  padding: 11px 9px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  background: rgba(20, 16, 40, 0.85);
  border: none;
  box-shadow: 0 0 0 2px #000, 0 0 0 4px var(--gold);
  cursor: pointer;
}
.menu-btn span {
  display: block;
  width: 100%;
  height: 3px;
  background: var(--gold);
}
.menu-btn:active {
  transform: translateY(2px);
  box-shadow: 0 0 0 2px #000, 0 0 0 4px var(--gold);
}
.menu-btn.hidden {
  display: none;
}

/* ----- 全画面表示時のレイアウト ----- */
#stage:fullscreen {
  width: 100vw;
  height: 100vh;
  max-width: none;
  aspect-ratio: auto;
  border: none;
  box-shadow: none;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
}
#stage:-webkit-full-screen {
  width: 100vw;
  height: 100vh;
  max-width: none;
  aspect-ratio: auto;
  border: none;
  box-shadow: none;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
}
#stage:fullscreen canvas {
  width: auto;
  height: 100%;
  max-width: 100%;
}
#stage:-webkit-full-screen canvas {
  width: auto;
  height: 100%;
  max-width: 100%;
}

/* ----- オーバーレイ画面共通 ----- */
.screen {
  position: absolute;
  inset: 0;
  z-index: 55;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 6, 22, 0.85);
}
.screen.hidden {
  display: none;
}

/* ----- ホーム画面（背景はキャンバスの夜空シーン） ----- */
#home {
  background: transparent;
}
.home-inner {
  text-align: center;
  padding: 26px 30px;
  background: rgba(11, 8, 24, 0.6);
  border: 3px solid var(--gold);
  box-shadow: 0 0 0 3px #000, inset 0 0 0 2px var(--frame-lt);
}
h1 {
  font-family: "Press Start 2P", monospace;
  font-size: 1.8rem;
  line-height: 1.2;
  color: var(--gold);
  letter-spacing: 1px;
  text-shadow: 3px 3px 0 #d6342b, 6px 6px 0 rgba(0, 0, 0, 0.45);
}
.subtitle {
  font-size: 1rem;
  letter-spacing: 0.2em;
  color: #cdb6ff;
  margin: 14px 0 0;
}
/* ----- ランキング(上位3) ----- */
.ranks-title {
  font-family: "Press Start 2P", monospace;
  font-size: 0.72rem;
  color: #7ef0ff;
  margin: 18px 0 8px;
}
.ranks {
  list-style: none;
  margin: 0 auto 8px;
  padding: 8px 10px;
  width: 200px;
  max-width: 80%;
  background: rgba(0, 0, 0, 0.3);
  border: 2px solid var(--frame-lt);
  font-family: "Press Start 2P", monospace;
  font-size: 0.7rem;
}
.ranks li {
  display: flex;
  justify-content: space-between;
  padding: 4px 4px;
}
.ranks li .rk {
  color: #cdb6ff;
}
.ranks li .sc {
  color: var(--gold);
}
.ranks li.hl .sc {
  color: #7ef0ff;
}

/* ----- パネル(メニュー/ゲームオーバー) ----- */
.panel {
  position: relative;
  background: var(--frame);
  border: 4px solid var(--gold);
  box-shadow: 0 0 0 4px #000, inset 0 0 0 2px var(--frame-lt);
  padding: 20px 18px;
  width: 88%;
  max-width: 340px;
}
.panel h2 {
  font-family: "Press Start 2P", monospace;
  font-size: 0.95rem;
  color: var(--gold);
  margin-bottom: 14px;
  text-shadow: 2px 2px 0 #d6342b;
}
/* 日本語見出しはドットフォントで */
#menu .panel h2 {
  font-family: "DotGothic16", "Hiragino Kaku Gothic ProN", sans-serif;
  font-size: 1.15rem;
}
.panel ul {
  text-align: left;
  font-size: 0.92rem;
  line-height: 1.9;
  margin: 0 0 16px;
  padding-left: 16px;
}
.panel b {
  color: var(--gold);
}

.menu-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 9px;
}

.new-best {
  font-family: "Press Start 2P", monospace;
  font-size: 0.8rem;
  color: #7ef0ff;
  margin: 0 0 12px;
  text-shadow: 2px 2px 0 #d6342b;
  animation: newbest-blink 0.5s steps(2) infinite;
}
.new-best.hidden {
  display: none;
}
@keyframes newbest-blink {
  0% { opacity: 1; }
  100% { opacity: 0.4; }
}
@media (prefers-reduced-motion: reduce) {
  .new-best { animation: none; }
}

.score-line {
  font-family: "Press Start 2P", monospace;
  font-size: 0.85rem;
  margin: 8px 0;
}
.score-line span {
  color: var(--gold);
}
.score-line.best span {
  color: #7ef0ff;
}

/* ----- ピクセル風ボタン ----- */
button {
  font-family: "Press Start 2P", monospace;
  font-size: 0.95rem;
  color: var(--ink);
  background: var(--gold);
  border: none;
  padding: 14px 30px;
  margin-top: 10px;
  cursor: pointer;
  box-shadow: 0 0 0 4px #000, 0 6px 0 0 var(--gold-dk), 0 6px 0 4px #000;
  transition: transform 0.05s, box-shadow 0.05s;
}
button:hover {
  filter: brightness(1.08);
}
button:active {
  transform: translateY(6px);
  box-shadow: 0 0 0 4px #000, 0 0 0 0 var(--gold-dk);
}

/* 日本語ボタンはドットフォント（Press Start 2P は英字専用のため） */
.btn-sm,
#resumeBtn {
  font-family: "DotGothic16", "Hiragino Kaku Gothic ProN", sans-serif;
}
.btn-sm {
  font-size: 0.95rem;
  padding: 11px 18px;
  min-height: 44px;
}

/* SHARE / HOME など英字の小ボタンは周囲のピクセル英字フォントに合わせる */
.btn-en {
  font-family: "Press Start 2P", monospace;
  font-size: 0.62rem;
  letter-spacing: 1px;
}

/* 製作者リンク(メニュー内) */
.credit {
  display: inline-block;
  margin-top: 16px;
  font-family: "DotGothic16", "Hiragino Kaku Gothic ProN", sans-serif;
  font-size: 0.8rem;
  color: var(--cyan, #7ef0ff);
  text-decoration: none;
  border-bottom: 1px dotted currentColor;
  padding-bottom: 1px;
}
.credit:hover,
.credit:focus-visible {
  color: #fff;
}

/* キーボード操作時のフォーカス可視化 */
button:focus-visible {
  outline: 3px solid #7ef0ff;
  outline-offset: 2px;
}

/* 動きを減らす設定の尊重: CRTスキャンラインを無効化 */
@media (prefers-reduced-motion: reduce) {
  .crt::after {
    display: none;
  }
}
