@import url('https://fonts.googleapis.com/css2?family=Space+Mono:wght@400;700&display=swap');

:root {
  --bg: #08010f;
  --accent: #7c3aed;
  --accent-soft: rgba(124, 58, 237, 0.18);
  --accent-strong: #c084fc;
  --text: #f7f5ff;
  --text-muted: #a6a0c0;
  --radius-lg: 20px;
  --radius-md: 14px;
  --shadow-soft: 0 18px 45px rgba(0, 0, 0, 0.5);
}

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

/* 画像の長押しメニュー（共有/保存/コピー等）・ドラッグを無効化 */
img { -webkit-touch-callout: none; -webkit-user-drag: none; user-select: none; -webkit-user-select: none; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100dvh;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: radial-gradient(circle at top, #1a0a2e 0, var(--bg) 55%, #000 100%);
  color: var(--text);
  overflow: hidden;
  position: fixed;
  top: 0; left: 0;
  overscroll-behavior: none;
  touch-action: manipulation; /* ダブルタップ拡大を無効化（スクロールは維持） */
  /* iOS は -webkit-user-select: none だけでは長押しの虫眼鏡（選択ルーペ）が出る。
     -webkit-touch-callout: none まで指定して初めて止まる */
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

body {
  display: flex;
  justify-content: center;
  align-items: stretch;
}

#app {
  width: 100%;
  max-width: 90vw;
  min-height: 100vh;
  padding: 12px 12px 18px;
  display: flex;
  flex-direction: column;
}

#error-banner {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 100;
  padding: 6px 10px;
  font-size: 0.8rem;
  background: rgba(239, 68, 68, 0.9);
  color: #fef2f2;
  text-align: center;
  display: none;
}

.screen { display: none; flex: 1; }
.screen--active { display: flex; flex-direction: column; }

/* ========== ホーム画面（Purple Jumper 同等のトップUI） ========== */

#screen-home.screen--active {
  align-items: center;
  justify-content: flex-start;
  padding-top: 10px;
  overflow-y: auto;
}

.start-card {
  width: 100%;
  max-width: min(94vw, 380px);
  margin: 0 auto;
  padding: 24px 20px;
  border-radius: 18px;
  background: radial-gradient(circle at top, #1f2937, #020617);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.85);
  border: 1px solid rgba(148, 163, 255, 0.4);
  text-align: center;
}

.start-title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.1em;
  margin-bottom: 10px;
  color: #e5e7ff;
  text-shadow: 0 0 12px rgba(129, 140, 248, 0.85);
}

/* 自動プレイのデモ（パッと見でゲーム内容が分かるように） */
.demo-stage {
  display: flex;
  justify-content: center;
  margin-bottom: 14px;
}

.demo-canvas {
  display: block;
  width: 62%;
  max-width: 208px;
  aspect-ratio: 500 / 720;
  height: auto;
  border-radius: 12px;
  border: 1px solid rgba(148, 163, 255, 0.4);
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.6), 0 0 18px rgba(124, 58, 237, 0.35);
  background: #08010f;
  pointer-events: none;
}

/* 「ニックネームを入力してください」と同じ行：左端にロゴ */
.start-label-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.start-logo-link {
  display: inline-flex;
  align-items: center;
  line-height: 0;
  text-decoration: none;
  flex-shrink: 0;
}

.start-logo {
  display: block;
  height: 30px;
  width: auto;
  object-fit: contain;
  filter: drop-shadow(0 0 4px rgba(139, 92, 246, 0.45));
  transition: transform 0.12s ease;
}

.start-logo-link:active .start-logo { transform: scale(0.92); }

.start-label {
  font-size: 12px;
  color: #cbd5f5;
  text-align: left;
}

.start-input {
  width: 100%;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 255, 0.8);
  background: rgba(15, 23, 42, 0.9);
  color: #e5e7eb;
  font-size: 14px;
  margin-bottom: 12px;
  outline: none;
  /* 入力欄だけは選択・コピー・ペーストできるように戻す */
  -webkit-touch-callout: default;
  -webkit-user-select: text;
  user-select: text;
}

.start-input:focus { box-shadow: 0 0 0 1px rgba(196, 181, 253, 0.9); }

.start-input.invalid {
  border-color: #ff6b8a;
  box-shadow: 0 0 0 3px rgba(255, 107, 138, 0.3);
  animation: nickShake 0.4s;
}

.nickname-error {
  min-height: 1.1em;
  margin: -6px 0 10px;
  color: #ff6b8a;
  font-size: 12px;
  font-weight: 700;
  text-align: center;
}

@keyframes nickShake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}

.primary-btn {
  padding: 10px 20px;
  border-radius: 999px;
  border: 2px solid rgba(248, 250, 252, 0.95);
  background: linear-gradient(135deg, #8b5cf6, #4c1d95);
  color: #ffffff;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.08em;
  cursor: pointer;
}

.primary-btn:active { transform: translateY(1px) scale(0.97); }
.primary-btn:disabled {
  background: #4b5563;
  color: #9ca3af;
  cursor: not-allowed;
  border-color: #6b7280;
}

.top-ranking {
  margin-top: 14px;
  text-align: left;
  height: 300px; min-height: 300px; max-height: 300px;
  display: flex; flex-direction: column; overflow: hidden;
  padding-right: 4px;
}

.top-ranking-title {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  font-weight: 600; margin-bottom: 6px; font-size: 15px; color: #cbd5f5;
  flex-shrink: 0; min-height: 26px; line-height: 26px;
}

#rank-title-text { width: 150px; text-align: center; }

.rank-arrow {
  cursor: pointer;
  padding: 0 8px;
  font-size: 20px;
  color: #c4b5fd;
  user-select: none;
}
.rank-arrow:active { transform: scale(0.9); }

.top-ranking-list {
  list-style: none; padding-left: 0; margin: 0;
  flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden;
  -webkit-overflow-scrolling: touch; overscroll-behavior-y: contain;
}

.top-ranking-list::-webkit-scrollbar { width: 8px; }
.top-ranking-list::-webkit-scrollbar-track { background: rgba(15, 23, 42, 0.8); border-radius: 4px; }
.top-ranking-list::-webkit-scrollbar-thumb { background: rgba(148, 163, 255, 0.5); border-radius: 4px; }
.top-ranking-list::-webkit-scrollbar-thumb:hover { background: rgba(148, 163, 255, 0.7); }

.top-ranking-list li { margin-bottom: 4px; color: #e5e7eb; }
.top-ranking-list li.rank-1 { font-size: 20px; font-weight: bold; }
.top-ranking-list li.rank-2 { font-size: 18px; font-weight: bold; }
.top-ranking-list li.rank-3 { font-size: 16px; font-weight: bold; }
.top-ranking-list li.rank-4plus { font-size: 13px; }
.top-ranking-list li.placeholder { color: #9ca3af; font-size: 13px; }

/* 順位行を1行に収める：順位・スコアは固定幅、ニックネームだけ「…」で省略 */
.top-ranking-list li.rank-row {
  display: flex;
  align-items: baseline;
  gap: 6px;
  white-space: nowrap;
}
.top-ranking-list li.rank-row .rank-head { flex-shrink: 0; }
.top-ranking-list li.rank-row .rank-name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.top-ranking-list li.rank-row .rank-score { flex-shrink: 0; }

/* ========== ゲーム画面 ========== */

.game-header {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto auto; /* 家 / スコア / 一時停止 */
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: rgba(0, 0, 0, 0.4);
  border-bottom: 1px solid rgba(124, 58, 237, 0.2);
  border-radius: var(--radius-md) var(--radius-md) 0 0;
}

/* 残機（ミニパプ太郎）：STAGE表示の下に中央寄せ。多くても折り返してバランスよく */
.game-lives-value {
  pointer-events: none;
  display: flex;
  align-items: center;
  align-content: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 4px 6px;
  margin: 8px auto 0;
  max-width: 92%;
}

.life-icon {
  height: 26px;
  width: auto;
  object-fit: contain;
  filter: drop-shadow(0 0 3px rgba(168, 85, 247, 0.55));
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none; /* 長押しの画像メニュー（共有/保存/コピー等）を無効化 */
  pointer-events: none;
  -webkit-user-drag: none;
}

.game-score-value {
  font-family: "Space Mono", monospace;
  font-size: 1.7rem;
  font-weight: 700;
  color: #fff;
  line-height: 1;
  text-shadow: 0 0 12px rgba(192, 132, 252, 0.6);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.05em;
  justify-self: end;
  transform-origin: right center;
  will-change: transform;
}

.pause-button {
  padding: 8px 16px;
  background: linear-gradient(135deg, #a78bfa 0%, #8b5cf6 100%);
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1rem;
  font-weight: bold;
  box-shadow:
    0 4px 15px rgba(139, 92, 246, 0.4),
    inset 0 -2px 4px rgba(0, 0, 0, 0.2),
    inset 0 2px 4px rgba(255, 255, 255, 0.2);
  transition: all 0.2s ease;
}

.pause-button:active {
  transform: translateY(2px);
}

.pause-button.paused {
  background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
}

.quit-button {
  background: none;
  border: none;
  color: #cbd5f5;
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px 6px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-self: start;
}

.home-icon {
  width: 22px;
  height: 22px;
  display: block;
}

.home-icon--btn {
  width: 16px;
  height: 16px;
  display: inline-block;
  vertical-align: -3px;
  margin-right: 5px;
}

.game-section {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start; /* 上に詰める（中央寄せの上余白をなくす） */
  background: linear-gradient(160deg, #0a0015, #08010f);
  border-radius: 0 0 var(--radius-md) var(--radius-md);
  overflow: hidden;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  user-select: none;
  -webkit-user-select: none;
  touch-action: none; /* エリア全体でタップ発射・操作を受けるため */
  cursor: pointer;
}

.game-field-wrapper {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
}

.game-field {
  display: block;
  width: 100%;
  max-width: 500px;
  aspect-ratio: 500 / 720;
  height: auto;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
  transform: translateZ(0);
  touch-action: none;
  cursor: pointer;
}

.move-hint {
  margin: 6px 0 0;
  font-size: 0.7rem;
  color: #8b7fb0;
  letter-spacing: 1px;
  text-align: center;
  font-family: "Share Tech Mono", monospace;
  transition: opacity 0.5s;
}

.stage-label {
  /* 長押しの起点になり得るので、そもそもタッチ対象にしない。
     ここへの指も .game-section が受け取るのでパドル操作の邪魔にもならない */
  pointer-events: none;
  margin: 10px 0 0;
  text-align: center;
  font-family: "Orbitron", sans-serif;
  font-weight: 800;
  font-size: 1.5rem;
  letter-spacing: 0.12em;
  color: #c4b5fd;
  text-shadow: 0 0 14px rgba(124, 58, 237, 0.8);
}

/* ========== ゲームオーバー ========== */

.gameover-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at top, rgba(76, 29, 149, 0.85), rgba(15, 6, 45, 0.96));
  backdrop-filter: blur(10px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease-out;
  z-index: 50;
}

.gameover-overlay--visible {
  opacity: 1;
  pointer-events: auto;
}

.gameover-dialog {
  width: 100%;
  max-width: 420px;
  margin: 0 16px;
  padding: 24px 20px 26px;
  border-radius: 20px;
  background: radial-gradient(circle at top, #a855f7, #4c1d95);
  box-shadow: 0 22px 50px rgba(0, 0, 0, 0.75);
  text-align: center;
  color: #fdf4ff;
}

.gameover-title {
  margin: 0 0 16px;
  font-family: "Orbitron", sans-serif;
  font-size: 2.2rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-shadow: 0 0 10px rgba(250, 250, 255, 0.9), 0 0 24px rgba(192, 132, 252, 0.8);
}

.gameover-score {
  margin: 6px 0;
  font-size: 1.3rem;
  font-weight: 700;
}

.gameover-score-label { color: #fdfdfd; }
.gameover-score-value { color: #fde68a; margin-left: 4px; }
.gameover-score-unit  { margin-left: 2px; }

.confirm-title {
  margin: 0 0 8px;
  font-family: "Orbitron", sans-serif;
  font-size: 1.4rem;
  font-weight: 900;
  letter-spacing: 0.06em;
  color: #fdf4ff;
  text-shadow: 0 0 10px rgba(192, 132, 252, 0.8);
}

.confirm-text {
  margin: 0 0 4px;
  font-size: 0.95rem;
  color: #e9d5ff;
}

.gameover-stats {
  margin: 4px 0 6px;
  font-size: 0.95rem;
  color: #ede9fe;
  display: flex;
  justify-content: center;
  gap: 8px;
}
.gameover-stats b { color: #fde68a; font-size: 1.05rem; margin-left: 2px; }
.gameover-stats-sep { color: #a78bfa; }

.gameover-badge {
  margin: 8px 0 12px;
  font-size: 1.5rem;
  font-weight: 900;
  color: #fef9c3;
  text-shadow: 0 0 10px rgba(251, 191, 36, 0.95), 0 0 22px rgba(245, 158, 11, 0.95);
  animation: badge-bounce 0.7s ease-in-out infinite, badge-rainbow 2.4s linear infinite;
}

.gameover-badge--hidden { display: none; }

@keyframes badge-bounce {
  0%, 100% { transform: translateY(0) scale(1); }
  30%       { transform: translateY(-8px) scale(1.14); }
  60%       { transform: translateY(2px) scale(0.97); }
}

@keyframes badge-rainbow {
  0%   { color: #fef9c3; text-shadow: 0 0 10px rgba(251,191,36,0.95), 0 0 24px rgba(245,158,11,0.9); }
  33%  { color: #bbf7d0; text-shadow: 0 0 10px rgba(34,197,94,0.9), 0 0 24px rgba(16,185,129,0.9); }
  66%  { color: #bfdbfe; text-shadow: 0 0 10px rgba(96,165,250,0.9), 0 0 24px rgba(59,130,246,0.9); }
  100% { color: #fbcfe8; text-shadow: 0 0 10px rgba(244,114,182,0.9), 0 0 24px rgba(236,72,153,0.9); }
}

.gameover-actions {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.gameover-button {
  padding: 14px 20px;
  border-radius: 999px;
  border: none;
  font-family: "Orbitron", sans-serif;
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  min-width: 100%;
}

.gameover-button--primary {
  background: linear-gradient(135deg, #f9a8ff, #c084fc);
  color: #0b0014;
  box-shadow: 0 12px 28px rgba(192, 132, 252, 0.6);
}

.gameover-button--secondary {
  background: rgba(15, 23, 42, 0.9);
  color: #e5e7eb;
  border: 1px solid rgba(226, 232, 240, 0.45);
}

@media (min-width: 768px) {
  #app { padding: 20px 18px 24px; }
  .form-section { margin-top: 20px; }
}
