/* グローバルスタイル */
:root {
  --panel-bg: rgba(255, 255, 255, 0.88); /* 明るいグラスモルフィズム */
  --panel-border: rgba(255, 255, 255, 0.5);
  --panel-shadow: 0 20px 40px rgba(40, 90, 40, 0.18);
  
  --color-primary: #ff5252; /* 明るいレッドコーラル */
  --color-primary-glow: rgba(255, 82, 82, 0.3);
  --color-secondary: #00bcd4; /* さわやかなシアンブルー */
  --color-secondary-glow: rgba(0, 188, 212, 0.3);
  --color-danger: #ff3b30;
  --color-danger-glow: rgba(255, 59, 48, 0.3);
  --color-text: #2c3e50; /* ダークブルーグレー */
  --color-text-dim: #7f8c8d;
  
  --font-family: 'M PLUS Rounded 1c', 'Outfit', sans-serif;
}

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

body {
  font-family: var(--font-family);
  background-color: #6bc96c;
  background-image: 
    linear-gradient(45deg, #5eb85f 25%, transparent 25%), 
    linear-gradient(-45deg, #5eb85f 25%, transparent 25%), 
    linear-gradient(45deg, transparent 75%, #5eb85f 75%), 
    linear-gradient(-45deg, transparent 75%, #5eb85f 75%);
  background-size: 96px 96px;
  background-position: 0 0, 0 48px, 48px -48px, -48px 0px;
  color: var(--color-text);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
}

/* ゲームコンテナ */
#game-container {
  position: relative;
  width: 100vw;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* 画面共通 */
.screen {
  position: absolute;
  width: 100%;
  max-width: 800px;
  height: 100%;
  max-height: 600px;
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 20px;
  z-index: 10;
}

.screen.active {
  display: flex;
  animation: fadeIn 0.4s ease forwards;
}

/* グラスモルフィズム パネル */
.glass-panel {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  box-shadow: var(--panel-shadow);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-radius: 24px;
  padding: 40px;
  width: 100%;
  max-width: 600px;
  text-align: center;
  position: relative;
}

/* ロゴ & テキスト */
.game-logo {
  font-size: 3rem;
  font-weight: 900;
  letter-spacing: -1px;
  color: var(--color-text);
  text-shadow: 0 0 10px rgba(255, 255, 255, 0.2), 0 0 20px rgba(255, 0, 127, 0.5);
  margin-bottom: 5px;
}

.game-logo span {
  color: var(--color-primary);
}

.subtitle {
  font-size: 1.2rem;
  color: var(--color-text-dim);
  margin-bottom: 40px;
  letter-spacing: 1px;
}

/* ボタン */
.btn {
  font-family: var(--font-family);
  font-size: 1.1rem;
  font-weight: 700;
  padding: 14px 28px;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  display: inline-block;
  outline: none;
}

.btn-primary {
  background: var(--color-primary);
  color: #fff;
  box-shadow: 0 0 15px var(--color-primary-glow);
}

.btn-primary:hover {
  transform: translateY(-3px);
  box-shadow: 0 0 25px var(--color-primary), 0 0 5px rgba(255,255,255,0.5);
}

.btn-primary:active {
  transform: translateY(1px);
}

.btn-secondary {
  background: transparent;
  border: 2px solid var(--color-secondary);
  color: var(--color-secondary);
  box-shadow: 0 0 10px var(--color-secondary-glow);
}

.btn-secondary:hover {
  transform: translateY(-3px);
  background: var(--color-secondary);
  color: #0f0c1b;
  box-shadow: 0 0 20px var(--color-secondary), 0 0 5px rgba(255,255,255,0.5);
}

.btn-secondary:active {
  transform: translateY(1px);
}

.btn-danger {
  background: var(--color-danger);
  color: #fff;
  box-shadow: 0 0 15px var(--color-danger-glow);
}

.btn-danger:hover {
  transform: translateY(-3px);
  box-shadow: 0 0 25px var(--color-danger), 0 0 5px rgba(255,255,255,0.5);
}

.btn-danger:active {
  transform: translateY(1px);
}

/* メニューボタン並び */
.menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 15px;
  margin-bottom: 40px;
}

/* あそびかた説明 */
.how-to-play {
  text-align: left;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  padding-top: 20px;
}

.how-to-play h3 {
  font-size: 1rem;
  margin-bottom: 10px;
  color: var(--color-secondary);
}

.how-to-play ul {
  list-style: none;
}

.how-to-play li {
  font-size: 0.85rem;
  line-height: 1.6;
  color: var(--color-text-dim);
  margin-bottom: 8px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
}

.key-badge {
  background: #2a2542;
  border: 1px solid #4a4270;
  border-bottom: 3px solid #1a162b;
  border-radius: 4px;
  padding: 1px 6px;
  font-family: monospace;
  font-weight: 700;
  color: var(--color-text);
  margin: 0 4px;
  display: inline-block;
}

.highlight-blue {
  color: var(--color-secondary);
  font-weight: 700;
}

/* ステージ選択画面 */
.stage-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 15px;
  margin: 30px 0;
}

.stage-card {
  aspect-ratio: 1;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  transition: all 0.2s ease;
  font-weight: 700;
}

.stage-card:hover {
  background: var(--color-secondary-glow);
  border-color: var(--color-secondary);
  box-shadow: 0 0 10px var(--color-secondary-glow);
  transform: scale(1.05);
}

.stage-card.locked {
  opacity: 0.4;
  cursor: not-allowed;
}

.stage-card.locked:hover {
  transform: none;
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.1);
  box-shadow: none;
}

.stage-card .num {
  font-size: 1.5rem;
  color: var(--color-text);
}

.stage-card .lock-icon {
  font-size: 1.2rem;
  margin-top: 5px;
}

/* ゲームプレイ画面 */
.game-header {
  width: 100%;
  max-width: 640px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.stage-badge {
  background: var(--color-primary);
  padding: 6px 12px;
  border-radius: 8px;
  font-weight: 900;
  font-size: 0.9rem;
  box-shadow: 0 0 8px var(--color-primary-glow);
}

.step-counter {
  margin-left: 15px;
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--color-secondary);
}

.btn-icon {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
  color: var(--color-text);
  font-family: var(--font-family);
  font-weight: 700;
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  margin-left: 8px;
}

.btn-icon:hover {
  background: rgba(255,255,255,0.15);
  border-color: rgba(255,255,255,0.3);
}

/* Canvasラッパー */
.canvas-wrapper {
  background: rgba(10, 8, 20, 0.8);
  border: 4px solid #1a162b;
  border-radius: 16px;
  box-shadow: 0 20px 40px rgba(0,0,0,0.6), inset 0 0 20px rgba(0,0,0,0.8);
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  max-width: 100%;
  width: 100%;
  aspect-ratio: 4 / 3;
}

#game-canvas {
  width: 100%;
  height: 100%;
  max-width: 640px;
  max-height: 480px;
  display: block;
  image-rendering: pixelated; /* ドット絵感を出すためのレンダリング指定 */
}

.game-footer {
  margin-top: 15px;
  color: var(--color-text-dim);
  font-size: 0.85rem;
}

/* モーダルオーバーレイ */
.modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(10, 8, 20, 0.8);
  backdrop-filter: blur(8px);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 100;
}

.modal-overlay.active {
  display: flex;
  animation: fadeIn 0.3s ease forwards;
}

.modal-content {
  max-width: 400px;
  padding: 30px;
}

.modal-content h2 {
  font-size: 2rem;
  margin-bottom: 25px;
  color: var(--color-secondary);
  text-shadow: 0 0 10px var(--color-secondary-glow);
}

.modal-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 20px;
}

.modal-hint {
  font-size: 0.8rem;
  color: var(--color-text-dim);
  line-height: 1.4;
}

/* クリア画面の特有スタイル */
.clear-content h2 {
  color: var(--color-primary);
  text-shadow: 0 0 15px var(--color-primary-glow);
}

.clear-icon {
  font-size: 4rem;
  margin-bottom: 10px;
  animation: bounce 1s infinite alternate;
}

.clear-stats {
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 25px;
}

/* デバッグパネル */
#debug-overlay {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 200;
  pointer-events: none;
}

#debug-overlay.debug-hidden {
  display: none;
}

.debug-panel {
  background: rgba(0, 0, 0, 0.85);
  border: 1px solid #333;
  color: #0f0;
  font-family: monospace;
  font-size: 12px;
  padding: 10px;
  border-radius: 8px;
  pointer-events: auto;
  box-shadow: 0 4px 10px rgba(0,0,0,0.5);
  width: 220px;
}

.debug-panel h4 {
  border-bottom: 1px solid #333;
  padding-bottom: 4px;
  margin-bottom: 8px;
  color: #ff0;
}

.debug-panel div {
  margin-bottom: 4px;
}

.debug-controls {
  margin-top: 8px;
  border-top: 1px solid #333;
  padding-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.btn-debug-action {
  background: #222;
  border: 1px solid #555;
  color: #fff;
  font-family: monospace;
  font-size: 10px;
  padding: 4px;
  cursor: pointer;
  text-align: left;
}

.btn-debug-action:hover {
  background: #333;
}

/* アニメーション */
@keyframes fadeIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes bounce {
  from { transform: translateY(0); }
  to { transform: translateY(-10px); }
}

/* ユウくんのアバター画像スタイル */
.title-avatar {
  width: 140px;
  height: 140px;
  object-fit: contain;
  margin: 10px auto 20px auto;
  display: block;
  animation: float 3s ease-in-out infinite;
  filter: drop-shadow(0 8px 16px rgba(0, 0, 0, 0.15));
}

@keyframes float {
  0% { transform: translateY(0px); }
  50% { transform: translateY(-8px); }
  100% { transform: translateY(0px); }
}

/* 追加の明るいテーマ用調整 */
.game-logo {
  text-shadow: 0 4px 10px rgba(0, 0, 0, 0.08);
}
.subtitle {
  margin-bottom: 25px;
}
.key-badge {
  background: #f0f0f5;
  border: 1px solid #d0d0da;
  border-bottom: 3px solid #b5b5c5;
  color: #2c3e50;
}
.stage-card {
  background: rgba(0, 0, 0, 0.03);
  border: 1px solid rgba(0, 0, 0, 0.08);
  color: #2c3e50;
}
.stage-card:hover {
  background: var(--color-secondary-glow);
  border-color: var(--color-secondary);
  box-shadow: 0 8px 20px rgba(0, 188, 212, 0.25);
  color: #fff;
}
.stage-card:hover .num {
  color: #fff;
}
.stage-card.locked {
  background: rgba(0, 0, 0, 0.06);
  border-color: rgba(0, 0, 0, 0.04);
}
.stage-badge {
  color: #fff;
}
.btn-icon {
  background: rgba(0,0,0,0.04);
  border: 1px solid rgba(0,0,0,0.08);
  color: #2c3e50;
}
.btn-icon:hover {
  background: rgba(0,0,0,0.08);
  border-color: rgba(0,0,0,0.15);
}
.canvas-wrapper {
  background: #e2e2e8;
  border: 6px solid #8f3d3d; /* レンガ調の枠線 */
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15);
}
.modal-overlay {
  background: rgba(255, 255, 255, 0.7);
}
.btn-secondary {
  color: var(--color-secondary);
  border-color: var(--color-secondary);
}
.btn-secondary:hover {
  color: #fff;
  background: var(--color-secondary);
}

/* ゲーム画面用グラスモルフィズムパネル */
.play-panel {
  max-width: 688px; /* Canvas幅640px + padding 24px * 2 */
  padding: 24px;
  border-radius: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* プレイ画面の要素調整 */
.play-panel .game-header {
  margin-bottom: 12px;
}
.play-panel .game-footer {
  margin-top: 12px;
  color: var(--color-text-dim);
}
.play-panel .step-counter {
  color: #00838f; /* 白背景で視認性の高いダークシアンに変更 */
  font-weight: 700;
}
.play-panel .btn-icon {
  background: rgba(0, 0, 0, 0.05);
  border: 1px solid rgba(0, 0, 0, 0.12);
  color: var(--color-text);
  padding: 6px 14px;
  font-size: 0.9rem;
}
.play-panel .btn-icon:hover {
  background: rgba(0, 0, 0, 0.1);
  border-color: rgba(0, 0, 0, 0.25);
}

/* 画面全体のサイズ制限を緩めてCanvasがはみ出さないように調整 */
.screen {
  max-width: 90vw;
  max-height: 95vh;
}

/* メニュー選択カーソル（フォーカス）用のスタイル */
.btn:focus,
.btn-icon:focus,
.stage-card.focused {
  outline: 3px solid var(--color-secondary);
  outline-offset: 3px;
  transform: scale(1.05);
  box-shadow: 0 0 15px var(--color-secondary-glow);
}
.btn-primary:focus {
  outline-color: var(--color-primary);
  box-shadow: 0 0 15px var(--color-primary-glow);
  transform: translateY(-3px) scale(1.03);
}
.btn-secondary:focus {
  outline-color: var(--color-secondary);
  box-shadow: 0 0 15px var(--color-secondary-glow);
  transform: translateY(-3px) scale(1.03);
}
.btn-danger:focus {
  outline-color: var(--color-danger);
  box-shadow: 0 0 15px var(--color-danger-glow);
  transform: translateY(-3px) scale(1.03);
}
.stage-card.focused {
  background: var(--color-secondary-glow) !important;
  border-color: var(--color-secondary) !important;
  box-shadow: 0 8px 20px rgba(0, 188, 212, 0.25) !important;
  color: #fff !important;
  transform: scale(1.08) !important;
}
.stage-card.focused .num {
  color: #fff !important;
}

/* スマートフォン用仮想十字キー (D-pad) スタイル */
.virtual-dpad {
  display: none; /* デフォルトでは非表示 */
  flex-direction: column;
  align-items: center;
  margin-top: 15px;
  user-select: none;
  -webkit-user-select: none;
  gap: 6px;
}

/* タッチデバイスまたはスマホ画面幅の場合にのみ表示 */
@media (pointer: coarse), (max-width: 768px) {
  .virtual-dpad {
    display: flex;
  }
}

.dpad-row {
  display: flex;
  justify-content: center;
  align-items: center;
}

.vbtn {
  width: 56px;
  height: 56px;
  background: rgba(255, 255, 255, 0.75);
  border: 2px solid rgba(0, 0, 0, 0.08);
  border-radius: 50%;
  font-size: 1.5rem;
  color: var(--color-text);
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.08);
  transition: background 0.1s, transform 0.1s;
  touch-action: manipulation;
  outline: none;
}

.vbtn:active {
  background: var(--color-secondary) !important;
  color: #fff !important;
  transform: scale(0.9) !important;
  box-shadow: 0 0 10px var(--color-secondary-glow) !important;
}

.dpad-spacer {
  width: 56px;
  height: 56px;
}

@media (max-width: 480px) {
  .vbtn {
    width: 48px;
    height: 48px;
    font-size: 1.2rem;
  }
  .dpad-spacer {
    width: 48px;
    height: 48px;
  }
}

/* タイトル画面のキャラクター＋ボタン並び */
.title-character-container {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 30px;
  margin: 20px auto 40px auto;
  max-width: 480px;
}

.title-character-container .title-avatar {
  margin: 0; /* 中央寄せマージンを解除 */
  flex-shrink: 0;
}

/* 吹き出し風ボタン */
.speech-bubble-btn {
  position: relative;
  background: var(--color-primary) !important;
  color: #fff !important;
  font-size: 1.35rem !important;
  font-weight: 900 !important;
  padding: 16px 36px !important;
  border-radius: 20px !important;
  border: none;
  cursor: pointer;
  box-shadow: 0 10px 25px var(--color-primary-glow) !important;
  transition: all 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275) !important;
  outline: none;
}

/* 吹き出しのしっぽ（突起） */
.speech-bubble-btn::before {
  content: '';
  position: absolute;
  left: -12px;
  top: 50%;
  transform: translateY(-50%);
  border-width: 10px 14px 10px 0;
  border-style: solid;
  border-color: transparent var(--color-primary) transparent transparent;
  transition: border-color 0.25s ease;
}

/* ホバー・フォーカス時の挙動 */
.speech-bubble-btn:hover,
.speech-bubble-btn:focus {
  transform: translateY(-3px) scale(1.05) !important;
  box-shadow: 0 15px 30px var(--color-primary), 0 0 5px rgba(255,255,255,0.6) !important;
}

/* 画面幅が狭いスマホ用のレスポンシブ配置 */
@media (max-width: 480px) {
  .screen {
    max-width: 96vw;
    padding: 10px;
  }
  .glass-panel {
    padding: 20px 15px;
    border-radius: 16px;
  }
  .game-logo {
    font-size: 1.8rem;
  }
  .subtitle {
    font-size: 0.9rem;
    margin-bottom: 15px;
  }
  .title-character-container {
    flex-direction: column;
    gap: 12px;
    margin: 10px auto 15px auto;
  }
  
  .title-character-container .title-avatar {
    width: 100px;
    height: 100px;
  }
  
  .speech-bubble-btn {
    font-size: 1.1rem !important;
    padding: 10px 24px !important;
    border-radius: 16px !important;
  }

  /* 縦並びの時はしっぽを上に変更 */
  .speech-bubble-btn::before {
    left: 50%;
    top: -12px;
    transform: translateX(-50%);
    border-width: 0 10px 14px 10px;
    border-color: transparent transparent var(--color-primary) transparent;
  }

  .how-to-play {
    padding-top: 15px;
  }
  .how-to-play h3 {
    margin-bottom: 5px;
  }
  .how-to-play li {
    font-size: 0.75rem;
    margin-bottom: 6px;
  }
  .key-badge {
    padding: 0px 4px;
    margin: 0 2px;
  }

  .play-panel {
    padding: 10px;
    border-radius: 16px;
  }
  .canvas-wrapper {
    border-width: 3px;
  }
}

/* エンディング画面の特有スタイル */
.ending-content h2 {
  color: #ff9800; /* ゴールドオレンジ */
  text-shadow: 0 0 15px rgba(255, 152, 0, 0.4);
}
.ending-icon {
  font-size: 4.5rem;
  margin-bottom: 10px;
  animation: bounce 0.8s infinite alternate;
}
.ending-congrats {
  font-size: 1.3rem;
  font-weight: 900;
  color: var(--color-primary);
  margin-bottom: 15px;
}
.ending-body {
  font-size: 0.95rem;
  color: var(--color-text-dim);
  line-height: 1.6;
  margin-bottom: 25px;
  padding: 0 10px;
}




