html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #05060f;
}

canvas {
  display: block;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

/* ===== メニュー(タイトル / ゲームオーバー画面) ===== */
.menu {
  position: fixed;
  left: 0;
  right: 0;
  bottom: max(10px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 0 16px;
  pointer-events: none; /* ボタン以外の部分はキャンバスへのタップを通す */
  font-family: system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Yu Gothic UI", "Meiryo", sans-serif;
}

.menu-buttons {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.menu-buttons .btn {
  pointer-events: auto;
}

.menu-status {
  margin: 0;
  min-height: 1em;
  font-size: 13px;
  color: #ffd84f;
  text-shadow: 0 1px 3px #0b0d1a;
  text-align: center;
}

.menu-status:empty {
  display: none;
}

/* ===== ボタン ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 18px;
  border: 2px solid #5ef2ff;
  border-radius: 8px;
  background: rgba(13, 15, 31, 0.85);
  color: #5ef2ff;
  font: bold 15px system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Yu Gothic UI", "Meiryo", sans-serif;
  text-decoration: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.btn:hover,
.btn:focus-visible {
  background: #5ef2ff;
  color: #0b0d1a;
  outline: none;
}

.btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.btn-sub {
  border-color: #a9b0e0;
  color: #a9b0e0;
}

.btn-sub:hover,
.btn-sub:focus-visible {
  background: #a9b0e0;
  color: #0b0d1a;
}

/* ===== モーダル ===== */
.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(13, 15, 31, 0.75);
  font-family: system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Yu Gothic UI", "Meiryo", sans-serif;
  color: #ffffff;
  touch-action: manipulation;
}

.panel {
  width: 100%;
  max-width: 360px;
  max-height: 100%;
  overflow-y: auto;
  box-sizing: border-box;
  padding: 18px 18px 16px;
  border: 2px solid #5ef2ff;
  border-radius: 12px;
  background: #1a1240;
  box-shadow: 0 0 24px rgba(94, 242, 255, 0.25);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.panel h2 {
  margin: 0;
  font-size: 20px;
  color: #5ef2ff;
  text-align: center;
}

.status {
  margin: 0;
  font-size: 13px;
  color: #a9b0e0;
  text-align: center;
}

.status:empty {
  display: none;
}

.status.error {
  color: #ff4f8b;
}

.ranking-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.ranking-list li {
  display: grid;
  grid-template-columns: 2.2em 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.05);
  font-size: 15px;
}

.ranking-list li.me {
  background: rgba(255, 216, 79, 0.2);
  outline: 1px solid #ffd84f;
}

.ranking-list .rank {
  font-weight: bold;
  color: #a9b0e0;
}

.ranking-list li:nth-child(1) .rank { color: #ffd84f; }
.ranking-list li:nth-child(2) .rank { color: #dfe6f0; }
.ranking-list li:nth-child(3) .rank { color: #e0a36b; }

.ranking-list .name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ranking-list .score {
  font-weight: bold;
  font-variant-numeric: tabular-nums;
}

.entry-info {
  margin: 0;
  text-align: center;
  font-size: 18px;
  font-weight: bold;
  color: #ffd84f;
}

.entry-label {
  font-size: 13px;
  color: #a9b0e0;
}

#entry-name {
  min-height: 40px;
  padding: 0 12px;
  border: 2px solid #a9b0e0;
  border-radius: 8px;
  background: #05060f;
  color: #ffffff;
  font-size: 16px; /* 16px未満だとiOSで自動ズームされる */
}

#entry-name:focus {
  border-color: #5ef2ff;
  outline: none;
}

.row {
  display: flex;
  gap: 10px;
}

.row .btn {
  flex: 1;
}

/* ===== プレイ中の操作ボタン(十字キー + DROP。PC はキーボードでも操作できる) ===== */
.controls {
  position: fixed;
  left: 50%;
  bottom: calc(max(10px, env(safe-area-inset-bottom)) + 44px);
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 22px;
  font-family: system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Yu Gothic UI", "Meiryo", sans-serif;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
}

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 54px);
  grid-template-rows: repeat(3, 54px);
  gap: 5px;
}
.ctl-up { grid-column: 2; grid-row: 1; }
.ctl-left { grid-column: 1; grid-row: 2; }
.ctl-center { grid-column: 2; grid-row: 2; }
.ctl-right { grid-column: 3; grid-row: 2; }
.ctl-down { grid-column: 2; grid-row: 3; }

.ctl {
  width: 54px;
  height: 54px;
  border-radius: 14px;
  border: 1px solid rgba(94, 242, 255, 0.45);
  background: rgba(10, 14, 32, 0.72);
  color: #cfefff;
  font: 700 20px/1 system-ui, sans-serif;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  backdrop-filter: blur(4px);
  padding: 0;
}

.ctl:active { background: rgba(94, 242, 255, 0.25); }

.ctl-center {
  border-radius: 50%;
  border-color: rgba(179, 140, 255, 0.7);
  color: #e3d6ff;
  font-size: 26px;
}

.ctl-drop {
  width: 104px;
  height: 104px;
  border-radius: 50%;
  border-color: rgba(255, 216, 79, 0.7);
  color: #ffd84f;
  font-size: 19px;
  letter-spacing: 0.1em;
}

.ctl-drop:active { background: rgba(255, 216, 79, 0.25); }

/* ===== モード選択(タイトル・ゲームオーバー) ===== */
.mode-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-bottom: 4px;
}
.btn-mode {
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 138px;
  padding: 10px 16px;
  border-radius: 16px;
  border: 1.5px solid rgba(94, 242, 255, 0.75);
  background: rgba(10, 14, 32, 0.8);
  color: #5ef2ff;
  cursor: pointer;
  font-family: inherit;
}
.btn-mode b { font-size: 18px; letter-spacing: 0.14em; }
.btn-mode small { font-size: 11px; color: #cfd5f5; }
.btn-mode:hover, .btn-mode:focus-visible { background: rgba(94, 242, 255, 0.16); outline: none; }
.btn-mode-expert { border-color: rgba(255, 95, 174, 0.8); color: #ff7fbf; }
.btn-mode-expert:hover, .btn-mode-expert:focus-visible { background: rgba(255, 95, 174, 0.16); }

/* ランキングのモード切り替え */
.rank-tabs { display: flex; gap: 8px; justify-content: center; margin: -4px 0 10px; }
.rank-tab {
  padding: 5px 14px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: transparent;
  color: #b7bde0;
  font: 700 13px/1 system-ui, sans-serif;
  letter-spacing: 0.1em;
  cursor: pointer;
}
.rank-tab.active { border-color: #5ef2ff; color: #5ef2ff; background: rgba(94, 242, 255, 0.12); }
