*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  overscroll-behavior-x: none;
  overscroll-behavior-y: none;
  background: #000000;
}

body {
  margin: 0;
  min-height: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  overscroll-behavior-x: none;
  overscroll-behavior-y: none;
  background: #000000;
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  font-family: "Segoe UI", "Hiragino Sans", sans-serif;
}

.app {
  width: 100%;
  height: 100%;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  touch-action: none;
  overscroll-behavior: none;
  background: #000000;
}

/* キャンバスとランキングを同じ表示サイズで重ねる（拡大縮小は JS の transform と canvas style で同期） */
.game-stage {
  position: relative;
  flex-shrink: 0;
  overflow: hidden;
}

#game {
  display: block;
  touch-action: none;
}

/* ゲーム表示領域いっぱい（キャンバスと同一ボックス） */
.overlay.overlay-on-game {
  position: absolute;
  inset: 0;
  z-index: 40;
  padding: 0;
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  overflow: hidden;
  background: transparent;
  opacity: 1;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  visibility: visible;
}

/* 論理 480×720。transform: scale() は game.js の resizeCanvas で設定 */
.ranking-overlay-logical {
  width: 480px;
  height: 720px;
  flex-shrink: 0;
  transform-origin: 0 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: stretch;
  box-sizing: border-box;
  padding: 8px;
  background: rgba(6, 8, 18, 0.88);
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(6, 8, 18, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 40;
  padding: env(safe-area-inset-top) 16px env(safe-area-inset-bottom) 16px;
  opacity: 1;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  visibility: visible;
}

.overlay.hidden {
  display: none;
  opacity: 0;
  visibility: hidden;
}

.overlay-on-game .overlay-card {
  width: 100%;
  max-width: none;
  flex: 1;
  min-height: 0;
  max-height: none;
  border-radius: 12px;
  padding: 12px 10px;
}

.overlay-card {
  width: 100%;
  max-width: 540px;
  height: auto;
  max-height: calc(100dvh - 32px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background:
    linear-gradient(180deg, rgba(43, 57, 95, 0.92) 0%, rgba(19, 25, 46, 0.95) 55%, rgba(14, 18, 34, 0.97) 100%);
  border: 1px solid rgba(168, 205, 255, 0.35);
  border-radius: 20px;
  padding: 24px 20px;
  color: #f8f6ff;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.18),
    0 24px 48px rgba(0, 0, 0, 0.6),
    0 4px 12px rgba(0, 0, 0, 0.5);
  animation: slideUpFade 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes slideUpFade {
  from {
    opacity: 0;
    transform: translateY(30px) scale(0.98);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}


.overlay-on-game .overlay-card h2 {
  font-size: 30px;
  margin: 0 0 6px;
}

.overlay-card h2 {
  margin: 0 0 10px;
  font-size: clamp(40px, 8vw, 52px);
  font-weight: 800;
  text-align: center;
  color: #fff0b8;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

/* 自分のプレイ結果（大迫力スコアボード） */
.result-score-card {
  margin: 0 0 10px;
  padding: 12px 14px;
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(28, 42, 78, 0.85) 0%, rgba(16, 24, 48, 0.9) 100%);
  border: 1px solid rgba(255, 215, 100, 0.4);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 6px 18px rgba(0, 0, 0, 0.4);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.result-score-main {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 10px;
}

.result-score-label {
  font-size: 20px;
  font-weight: 700;
  color: #ffd880;
  letter-spacing: 0.05em;
}

.result-score-num {
  font-size: 38px;
  font-weight: 900;
  font-family: 'Outfit', sans-serif;
  color: #fff4d0;
  text-shadow: 0 0 16px rgba(255, 215, 80, 0.6), 0 2px 4px rgba(0, 0, 0, 0.8);
  letter-spacing: 0.03em;
  line-height: 1;
}

.result-stats-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 6px;
}

.stat-badge {
  padding: 8px 4px;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(10, 16, 32, 0.65);
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.stat-label {
  font-size: 12px;
  color: rgba(215, 230, 255, 0.8);
  font-weight: 700;
  letter-spacing: 0.02em;
}

.stat-num {
  font-size: 26px;
  font-weight: 900;
  font-family: 'Outfit', sans-serif;
  margin-top: 2px;
  line-height: 1;
}

.stat-level .stat-num {
  color: #6ee7ff;
  text-shadow: 0 0 10px rgba(110, 231, 255, 0.6);
}

.stat-placed .stat-num {
  color: #79f2ab;
  text-shadow: 0 0 10px rgba(121, 242, 171, 0.6);
}

.stat-combo .stat-num {
  color: #ffb86c;
  text-shadow: 0 0 10px rgba(255, 184, 108, 0.6);
}

.overlay-on-game .rank-emphasis {
  font-size: 18px;
  min-height: 22px;
  margin: 0 0 6px;
}

.rank-emphasis {
  min-height: 24px;
  margin: -2px 0 14px;
  font-size: clamp(26px, 5vw, 34px);
  font-weight: 800;
  color: #ffda6a;
  text-shadow: 0 0 12px rgba(255, 200, 80, 0.6);
  text-align: center;
}

.overlay-on-game .name-row {
  margin-bottom: 8px;
  gap: 6px;
}

.overlay-on-game .name-row input {
  height: 42px;
  font-size: 16px;
  padding: 0 12px;
  border-radius: 8px;
}

.overlay-on-game .name-row button {
  height: 44px;
  font-size: 18px;
  border-radius: 8px;
}

.name-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.name-row input {
  width: 100%;
  box-sizing: border-box;
  height: 54px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(0, 0, 0, 0.35);
  color: #fff;
  padding: 0 16px;
  font-size: clamp(20px, 4vw, 26px);
  transition: all 0.2s ease;
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.5);
  outline: none;
}

.name-row input:focus {
  border-color: #ffd880;
  background: rgba(10, 20, 40, 0.6);
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.5), 0 0 0 3px rgba(255, 216, 128, 0.3);
}

.name-row button {
  width: 100%;
  box-sizing: border-box;
  height: 52px;
  border: 1px solid rgba(255, 225, 120, 0.85);
  border-radius: 12px;
  background: linear-gradient(180deg, #d4a034 0%, #a67215 50%, #784e07 100%);
  color: #ffffff;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.4),
    inset 0 -2px 0 rgba(0, 0, 0, 0.3),
    0 4px 10px rgba(0, 0, 0, 0.4);
  font-size: clamp(20px, 4vw, 26px);
  font-weight: 800;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.6);
  cursor: pointer;
  transition: all 0.15s cubic-bezier(0.2, 0, 0, 1);
}

.name-row button:active {
  transform: scale(0.98) translateY(2px);
  box-shadow:
    inset 0 2px 6px rgba(0, 0, 0, 0.5),
    0 1px 2px rgba(0, 0, 0, 0.2);
  background: linear-gradient(180deg, #b8861e, #8c5e0d, #523400);
}

.overlay-on-game .close-btn,
.overlay-on-game .action-btn {
  height: 44px;
  font-size: 16px;
  border-radius: 10px;
}

.result-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 8px;
}

.action-btn {
  height: 56px;
  border-radius: 12px;
  font-weight: 800;
  cursor: pointer;
  transition: all 0.15s cubic-bezier(0.2, 0, 0, 1);
}

/* トップに戻る（落ち着いたネイビー・スレート系） */
.btn-home {
  border: 1px solid rgba(141, 177, 234, 0.7);
  background: linear-gradient(180deg, #4d689e 0%, #2b3d63 100%);
  color: #e5dfff;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.3),
    inset 0 -2px 0 rgba(0, 0, 0, 0.2),
    0 4px 8px rgba(0, 0, 0, 0.3);
  font-size: clamp(18px, 3.8vw, 24px);
}

.btn-home:active {
  transform: scale(0.97) translateY(2px);
  background: linear-gradient(180deg, #3d5482, #212f4d);
}

/* もう一度（華やかで押しやすいゴールド系） */
.btn-retry {
  border: 1px solid rgba(255, 225, 120, 0.85);
  background: linear-gradient(180deg, #d4a034 0%, #a67215 50%, #784e07 100%);
  color: #ffffff;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.4),
    inset 0 -2px 0 rgba(0, 0, 0, 0.3),
    0 4px 10px rgba(0, 0, 0, 0.4);
  font-size: clamp(18px, 3.8vw, 24px);
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.6);
}

.btn-retry:active {
  transform: scale(0.97) translateY(2px);
  background: linear-gradient(180deg, #b8861e, #8c5e0d, #523400);
}

.close-btn {
  height: 56px;
  border: 1px solid rgba(141, 177, 234, 0.8);
  border-radius: 12px;
  background: linear-gradient(180deg, #6f95d8, #3c568f, #263a68);
  color: #ffffff;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.35),
    inset 0 -2px 0 rgba(0, 0, 0, 0.2),
    0 4px 8px rgba(0, 0, 0, 0.3);
  font-size: clamp(20px, 4vw, 26px);
  font-weight: 700;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
  cursor: pointer;
  margin-top: 8px;
  transition: all 0.15s cubic-bezier(0.2, 0, 0, 1);
}

.close-btn:active {
  transform: scale(0.97) translateY(2px);
  box-shadow:
    inset 0 2px 6px rgba(0, 0, 0, 0.4),
    0 1px 2px rgba(0, 0, 0, 0.2);
  background: linear-gradient(180deg, #5a7ec0, #344c80, #1f3058);
}

.rank-section-header {
  display: flex;
  align-items: center;
  margin: 4px 0 6px;
  padding: 0 4px;
}

.overlay-on-game .tabs {
  gap: 6px;
  margin-bottom: 8px;
}

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 10px;
}

.overlay-on-game .tabs button {
  height: 40px;
  font-size: 15px;
  border-radius: 8px;
}

.tabs button {
  height: 48px;
  border: 1px solid rgba(141, 177, 234, 0.6);
  border-radius: 10px;
  background: linear-gradient(180deg, #355288, #203660);
  color: #d1e2ff;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
}

.tabs button.active {
  background: linear-gradient(180deg, #9ed9ff, #6790d1, #486a9f);
  color: #0d1a3a;
  text-shadow: 0 1px 2px rgba(255, 255, 255, 0.6);
  border-color: #b5e1ff;
  font-weight: 800;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6), 0 3px 6px rgba(0, 0, 0, 0.3);
}

.rank-section-title {
  font-size: 15px;
  font-weight: 800;
  color: #ffd880;
  letter-spacing: 0.05em;
}

.rank-list-wrap {
  flex: 1;
  min-height: 160px;
  overflow-y: auto !important;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 10px;
  background: rgba(6, 10, 24, 0.55);
  box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.4);
}

.rank-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: clamp(18px, 3.5vw, 24px);
}

.overlay-on-game .rank-table {
  font-size: 15px;
}

.rank-table th,
.rank-table td {
  padding: 8px 6px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  vertical-align: middle;
}

.overlay-on-game .rank-table th,
.overlay-on-game .rank-table td {
  padding: 6px 6px;
}

.rank-table thead th {
  position: sticky;
  top: 0;
  background: rgba(28, 42, 75, 0.95);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 1;
  color: #d1e2ff;
  font-size: 13px;
  font-weight: 700;
  border-bottom: 2px solid rgba(255, 255, 255, 0.15);
}

/* 列幅の最適配分：名前枠を最大化！ */
.rank-table th.col-rank,
.rank-table td.col-rank {
  width: 36px;
  text-align: center;
  font-weight: 700;
  color: rgba(215, 230, 255, 0.8);
}

.rank-table th.col-name,
.rank-table td.col-name {
  width: auto;
  /* 残り幅すべて名前枠に割り当て */
  text-align: left;
  padding-left: 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 700;
  color: #ffffff;
}

.rank-table th.col-score,
.rank-table td.col-score {
  width: 72px;
  text-align: right;
  font-family: 'Outfit', sans-serif;
  font-weight: 700;
  color: #ffd880;
  padding-right: 6px;
}

.rank-table th.col-level,
.rank-table td.col-level {
  width: 52px;
  text-align: center;
  font-family: 'Outfit', sans-serif;
  font-weight: 700;
  color: #6ee7ff;
}

.rank-table tbody tr {
  transition: background 0.15s ease;
}

.rank-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.08);
}

.rank-table tbody tr:nth-child(even) {
  background: rgba(255, 255, 255, 0.03);
}

.close-btn {
  width: 100%;
  margin-top: 10px;
  flex-shrink: 0;
}

@supports (height: 100dvh) {
  body {
    min-height: 100dvh;
  }
}

.logical-overlay-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 480px;
  height: 720px;
  pointer-events: none;
  /* 下の要素のクリックを妨げない */
  transform-origin: 0 0;
  z-index: 30;
  /* キャンバスより上、ランキングオーバーレイより下 */
}

/* --- コピーライト --- */
.copyright-text {
  position: absolute;
  bottom: 5px;
  left: 0;
  width: 100%;
  text-align: center;
  color: rgba(255, 255, 255, 0.55);
  font-size: 14px;
  margin: 0;
  pointer-events: none;
}

/* --- 和水町ｅスポーツタグライン --- */
.town-esports-tagline {
  position: absolute;
  bottom: 25px;
  /* 画面下段に配置 */
  left: 0;
  width: 100%;
  text-align: center;
  z-index: 30;
  /* ゲーム描画より上、ランキングオーバーレイより下 */
  pointer-events: none;
  /* タップ操作の邪魔にならないように */
}

.town-esports-tagline-pill {
  display: inline-block;
  background-color: #6f0009;
  /* 赤背景 */
  color: #ffffff;
  /* 白文字 */
  font-size: 26px;
  /* 目立つサイズに */
  font-weight: 900;
  padding: 10px 24px;
  border: 1px solid #ffffff;
  /* フレーム（白い枠線） */
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.6);
  /* 影で目立たせる */
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
  letter-spacing: 0.05em;
}