* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  height: 100dvh;
  background: #0a0e17;
  color: #fff;
  font-family: 'Press Start 2P', 'DotGothic16', monospace;
  overflow: hidden;
  touch-action: none; /* スマホでのピンチズームや不要スクロールを完全防止 */
}

#game-wrapper {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#game-container {
  position: relative;
  width: 100%;
  max-width: 960px;
  aspect-ratio: 16 / 9;
  background: #1a2639;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.8), 0 0 0 3px #2c3e50;
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
}

/* キャンバスをピクセルパーフェクトで描画 */
#gameCanvas {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: -moz-crisp-edges;
  image-rendering: -webkit-crisp-edges;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

/* スマホ向け下部タッチガイド */
.mobile-touch-hint {
  position: absolute;
  bottom: 8px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 10px;
  color: rgba(255, 255, 255, 0.7);
  font-family: 'DotGothic16', monospace;
  pointer-events: none;
  z-index: 5;
  text-shadow: 1px 1px 2px #000;
  display: none;
}

#ui-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* プレイ中HUD */
.hud-panel {
  position: absolute;
  top: 10px;
  left: 12px;
  right: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(10, 15, 25, 0.85);
  border: 2px solid #38b6ff;
  border-radius: 6px;
  padding: 6px 14px;
  box-shadow: 0 4px 10px rgba(0,0,0,0.5);
  pointer-events: auto;
  z-index: 6;
}

.hud-item {
  display: flex;
  align-items: baseline;
  gap: 5px;
}

.hud-label {
  font-size: 9px;
  color: #88c0d0;
  letter-spacing: 1px;
}

.hud-val {
  font-size: 15px;
  color: #ffeaa7;
  font-weight: bold;
}

.hud-unit {
  font-size: 8px;
  color: #d8dee9;
}

.header-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}

.hub-btn {
  background: #0984e3;
  border-color: #74b9ff;
  color: #fff;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

/* レトロボタンスタイル */
.retro-btn {
  background: #2e3440;
  color: #eceff4;
  border: 2px solid #eceff4;
  box-shadow: 2px 2px 0px #000;
  padding: 6px 12px;
  font-family: inherit;
  font-size: 11px;
  cursor: pointer;
  outline: none;
  transition: transform 0.05s, box-shadow 0.05s;
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
}

.retro-btn:active {
  transform: translate(2px, 2px);
  box-shadow: 0px 0px 0px #000;
}

/* オーバーレイ共通 */
.overlay-screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(10, 14, 26, 0.94);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 12px;
  pointer-events: auto;
  z-index: 10;
  backdrop-filter: blur(4px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  cursor: pointer;
}

.overlay-screen.active {
  display: flex;
}

/* タイトル画面 */
.title-card {
  margin-bottom: 8px;
}

.logo-badge {
  font-size: 9px;
  color: #55efc4;
  letter-spacing: 1px;
  margin-bottom: 4px;
}

.game-title {
  font-size: 26px;
  line-height: 1.15;
  color: #ffffff;
  text-shadow: 3px 3px 0 #0984e3, -2px -2px 0 #000;
  letter-spacing: 2px;
}

.title-highlight {
  color: #38b6ff;
  text-shadow: 3px 3px 0 #0056b3, -2px -2px 0 #000;
}

.subtitle {
  font-size: 11px;
  color: #a4b0be;
  margin-top: 4px;
  font-family: 'DotGothic16', monospace;
}

.player-preview-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 6px 0;
  padding: 6px 14px;
  background: rgba(0, 0, 0, 0.4);
  border: 2px dashed #38b6ff;
  border-radius: 8px;
}

#previewCanvas {
  image-rendering: pixelated;
  width: 72px;
  height: 72px;
}

.preview-text {
  font-size: 9px;
  color: #74b9ff;
  margin-top: 3px;
  font-family: 'DotGothic16', monospace;
}

.instructions-box {
  background: rgba(255, 255, 255, 0.08);
  border: 2px solid #576574;
  border-radius: 6px;
  padding: 8px 14px;
  max-width: 440px;
  margin-bottom: 12px;
}

.instruction-row {
  font-size: 10px;
  color: #f1f2f6;
  margin-bottom: 4px;
  font-family: 'DotGothic16', monospace;
}

.key-icon {
  display: inline-block;
  background: #dfe4ea;
  color: #2f3542;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: bold;
  font-size: 9px;
  border-bottom: 2px solid #a4b0be;
}

.instruction-desc {
  font-size: 9px;
  color: #ced6e0;
  line-height: 1.4;
  font-family: 'DotGothic16', monospace;
}

.start-pulse {
  background: #00b894;
  color: #fff;
  border-color: #55efc4;
  font-size: 15px;
  padding: 10px 24px;
  min-height: 44px;
  box-shadow: 3px 3px 0px #006266;
  animation: pulse 1.2s infinite ease-in-out;
}

.tap-hint {
  margin-top: 8px;
  font-size: 9px;
  color: #a4b0be;
  font-family: 'DotGothic16', monospace;
  animation: blink 1.5s infinite;
}

/* ゲームオーバー画面 */
.referee-whistle {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}

.card-icon {
  width: 20px;
  height: 30px;
  border-radius: 3px;
  border: 2px solid #fff;
  box-shadow: 2px 2px 0 #000;
}

.red-card {
  background: #ff3838;
}

.whistle-banner {
  font-size: 18px;
  color: #ff3838;
  text-shadow: 2px 2px 0 #000;
  letter-spacing: 1px;
}

.gameover-sub {
  font-size: 12px;
  color: #f8a5c2;
  margin-bottom: 12px;
  font-family: 'DotGothic16', monospace;
}

.result-board {
  background: #1e272e;
  border: 2px solid #ff5252;
  border-radius: 8px;
  padding: 12px 20px;
  width: 300px;
  max-width: 90%;
  margin-bottom: 12px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.6);
}

.result-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  color: #d2dae2;
  margin-bottom: 8px;
  font-family: 'DotGothic16', monospace;
}

.result-num {
  font-size: 13px;
  color: #fff;
  font-family: 'Press Start 2P', monospace;
}

.highlight-row {
  border-top: 1px dashed #485460;
  padding-top: 8px;
  margin-bottom: 0;
  color: #ffd32a;
}

.highlight-row .result-num {
  color: #ffd32a;
}

.new-record-badge {
  margin-top: 8px;
  color: #fffa65;
  font-size: 10px;
  text-shadow: 2px 2px 0 #ff3838;
  animation: pulse 0.8s infinite;
}

.result-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: center;
  margin-top: 4px;
  flex-wrap: wrap;
}

.restart-pulse {
  background: #ff5252;
  color: #fff;
  border-color: #ff7979;
  font-size: 13px;
  padding: 10px 20px;
  min-height: 44px;
  box-shadow: 3px 3px 0px #b33939;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

@keyframes blink {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 1; }
}

/* ==========================================================================
   モバイル・スマートフォン対応 (Portrait / 小型画面)
   ========================================================================== */
@media (max-width: 600px) {
  body {
    padding: 0;
  }

  #game-container {
    border-radius: 0;
    box-shadow: none;
    border: none;
    /* 縦画面でも見栄えが良い比率 */
    max-width: 100%;
  }

  .mobile-touch-hint {
    display: block;
  }

  /* HUD */
  .hud-panel {
    top: 6px;
    left: 8px;
    right: 8px;
    padding: 4px 8px;
  }
  .hud-label { font-size: 7px; }
  .hud-val { font-size: 12px; }
  .hud-unit { font-size: 7px; }
  .retro-btn {
    padding: 4px 8px;
    font-size: 9px;
    min-height: 30px;
  }

  /* タイトル画面のコンパクト化（スクロール不要で1画面に収める） */
  .title-card { margin-bottom: 4px; }
  .logo-badge { font-size: 8px; margin-bottom: 2px; }
  .game-title { font-size: 18px; }
  .subtitle { font-size: 9px; margin-top: 2px; }

  .player-preview-card {
    margin: 4px 0;
    padding: 4px 10px;
  }
  #previewCanvas {
    width: 52px;
    height: 52px;
  }
  .preview-text { font-size: 8px; }

  .instructions-box {
    padding: 6px 10px;
    margin-bottom: 8px;
    max-width: 92%;
  }
  .instruction-row { font-size: 9px; margin-bottom: 2px; }
  .key-icon { font-size: 8px; padding: 1px 4px; }
  .instruction-desc { font-size: 8px; }

  .start-pulse {
    font-size: 13px;
    padding: 8px 20px;
    min-height: 40px;
  }
  .tap-hint {
    font-size: 8px;
    margin-top: 6px;
  }

  /* ゲームオーバー画面 */
  .whistle-banner { font-size: 15px; }
  .gameover-sub { font-size: 10px; margin-bottom: 8px; }
  .result-board {
    width: 260px;
    padding: 8px 14px;
    margin-bottom: 8px;
  }
  .result-row { font-size: 9px; margin-bottom: 6px; }
  .result-num { font-size: 11px; }
  .restart-pulse {
    font-size: 11px;
    padding: 8px 14px;
    min-height: 38px;
  }
}

/* 横画面（Landscape）で高さが低い場合の最適化 */
@media (orientation: landscape) and (max-height: 500px) {
  #game-wrapper {
    padding: 0;
  }
  #game-container {
    height: 100vh;
    height: 100dvh;
    width: auto;
    aspect-ratio: 16 / 9;
    border-radius: 0;
    border: none;
  }
  .player-preview-card {
    display: none; /* 縦が狭い時はプレビューを隠してスッキリ */
  }
  .instructions-box {
    padding: 4px 10px;
    margin-bottom: 6px;
  }
  .game-title { font-size: 18px; }
  .start-pulse { padding: 6px 18px; font-size: 12px; min-height: 34px; }
}
