* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: #0b1020;
  color: #e5e7eb;
  font: 14px/1.5 system-ui, -apple-system, Segoe UI, Roboto, "Noto Sans JP", sans-serif;
}

.container-narrow {
  padding: 0 12px;
  max-width: 1920px;
}

.shell {
  position: relative;
  width: 100%;
  aspect-ratio: 16/9;
  background: #000;
  overflow: hidden;
  touch-action: none; /* ピンチズームのカスタム実装を有効化 */
}

/* 縦型モード（/shorts 用） */
.shell.vertical {
  aspect-ratio: 9/16;
  max-width: 480px;
  margin-left: auto;
  margin-right: auto;
}

.video {
  position: absolute;
  inset: 0;
}

/* ピンチズーム用のタッチ操作設定 - iOS Safari対策強化 */
#sh, #stage, #overlay, #owned, #grid {
  touch-action: none; /* ネイティブジェスチャ無効化 */
  -webkit-touch-callout: none; /* iOS Safariでの長押しメニュー無効化 */
  -webkit-user-select: none; /* iOS Safariでのテキスト選択無効化 */
  user-select: none;
}

/* モバイル時虫眼鏡非表示 - タッチデバイス判定 */
@media (pointer: coarse) {
  .magnifier-cursor,
  .magnifier-lens {
    display: none !important;
  }
}

/* 共通ステージラッパー - 動画用CSS transform適用 */
#stage {
  position: absolute;
  inset: 0;
  transform-origin: 0 0;
  will-change: transform;
  touch-action: none;
}

/* オーバーレイレイヤー - Canvas用CSS transformなし（Canvas内で拡大） */
#overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  touch-action: none;
}

/* 動画レイヤー */
.video {
  position: absolute;
  inset: 0;
  z-index: 1; /* 動画は最下層 */
}

/* キャンバスレイヤー - 統一スケーリング対象 */
#owned {
  z-index: 3;
  pointer-events: none; /* クリック不要 */
}

#grid {
  z-index: 4;
  pointer-events: auto; /* クリックが必要 */
}

/* ロックアイコン - キャンバスと同じレイヤー */
.lock-icons-container {
  z-index: 4;
}

/* iOS Safari対策：ピンチ操作の強化 */
.shell {
  -webkit-overflow-scrolling: touch; /* iOS Safariでのスムーズスクロール */
}

.video iframe, .video video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  pointer-events: none;
  z-index: 1;
}

canvas {
  position: absolute;
  inset: 0;
  display: block;
}

/* ロックアイコン用コンテナ */
.lock-icons-container {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 4;
}

.lock-icon {
  position: absolute;
  color: #000000;
  font-size: 12px;
  text-shadow: 0 0 3px rgba(255, 255, 255, 0.8);
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  padding: 1px;
  line-height: 1;
}

.lock-icon i {
  display: block;
  line-height: 1;
}

#owned {
  z-index: 3;
  pointer-events: none;
}

#grid {
  z-index: 4;
}

/* 虫眼鏡カーソル用スタイル */
.magnifier-cursor {
  position: fixed;
  width: 32px;
  height: 32px;
  background: url('../images/magnifier-icon.svg') no-repeat center;
  background-size: contain;
  pointer-events: none;
  z-index: 10000;
  display: none;
  mix-blend-mode: difference;
}

.magnifier-lens {
  position: fixed;
  width: 200px;
  height: 200px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
  pointer-events: none;
  z-index: 10001;
  display: none;
  overflow: hidden;
}

.magnifier-content {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  transform-origin: 0 0;
  pointer-events: none;
}

/* 虫眼鏡内のクリックポイントカーソル */
.magnifier-click-cursor {
  position: absolute;
  width: 16px;
  height: 16px;
  pointer-events: none;
  z-index: 10002;
  color: #fff;
  text-shadow: 0 0 3px #000;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  filter: drop-shadow(0 0 2px rgba(255, 255, 255, 0.8));
  /* カーソルの先っぽに配置（左右反転を考慮） */
  transform: translate(-1px, -1px) scaleX(-1);
  /* SVG塗りつぶしを強制 */
  fill: #000000;
}

/* モバイル時の虫眼鏡機能を非表示 */
@media (max-width: 767.98px) {
  .magnifier-cursor,
  .magnifier-lens {
    display: none !important;
  }

  .magnifier-click-cursor {
    width: 12px;
    height: 12px;
    font-size: 12px;
  }
}

.magnifier-click-cursor i {
  font-size: 16px;
  line-height: 1;
  /* 塗りつぶしを確実に黒にする */
  color: #000000;
  fill: #000000;
  /* 白い枠線効果を別の方法で実現 */
  filter: drop-shadow(0 0 0 #ffffff) drop-shadow(0 0 0 #ffffff) drop-shadow(0 0 0 #ffffff) drop-shadow(0 0 0 #ffffff);
}

.btn-group .btn.active {
  background-color: #0d6efd;
  border-color: #0d6efd;
  color: white;
}

/* 再生ボタン用スタイル（HTML5 Video） */
#playButton {
  transition: all 0.3s ease;
}

#playButton:hover {
  background-color: rgba(255, 0, 0, 0.8) !important;
  border-color: rgba(255, 0, 0, 0.8) !important;
  transform: scale(1.05);
}

#playButton.playing {
  background-color: rgba(255, 0, 0, 0.8) !important;
  border-color: rgba(255, 0, 0, 0.8) !important;
  color: white !important;
}

/* ミュートボタン用スタイル */
#muteButton {
  transition: all 0.3s ease;
}

#muteButton:hover {
  background-color: rgba(255, 165, 0, 0.8) !important;
  border-color: rgba(255, 165, 0, 0.8) !important;
  transform: scale(1.05);
}

#muteButton.muted {
  background-color: rgba(255, 165, 0, 0.8) !important;
  border-color: rgba(255, 165, 0, 0.8) !important;
  color: white !important;
}

/* Xロゴホバー効果 */
a[href*="x.com"]:hover {
  background-color: #000000 !important;
  border-color: #000000 !important;
  color: #ffffff !important;
}

a[href*="x.com"]:hover img {
  filter: brightness(0) invert(1);
}

/* youtubeロゴホバー効果 */
a[href*="youtube.com"]:hover {
  background-color: #000000 !important;
  border-color: #000000 !important;
  color: #ffffff !important;
}

a[href*="youtube.com"]:hover img {
  filter: brightness(0) invert(1);
}

/* 座標表示用スタイル */
.coordinate-display {
  text-align: center;
  line-height: 1.2;
}

.coordinate-alphabet {
  font-size: 1.2em;
  font-weight: bold;
  color: #ffffff;
  margin-bottom: 2px;
}

.coordinate-numbers {
  font-size: 0.85em;
  color: #adb5bd;
  font-family: monospace;
}

/* Tiles Editorのプレースホルダー色調整 */
.form-control::placeholder {
  color: #6c757d !important;
  opacity: 0.6;
}

.form-control:focus::placeholder {
  color: #6c757d !important;
  opacity: 0.4;
}

/* スピンアニメーション */
.spin {
  animation: spin 1s linear infinite;
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

/* ユーザーランキングのリンクスタイル */
#userRanking a {
  transition: color 0.2s ease;
}

#userRanking a:hover {
  color: #17a2b8 !important;
  text-decoration: underline !important;
}

/* ==================================================
   タッチ操作関連スタイル (index.phpから移動)
   ================================================== */

/* 全画面の透明レイヤー */
#touch-surface{
  position: fixed; inset: 0; z-index: 9999;
  background: transparent;
  /* ページスクロールやズームを抑止（このレイヤー上のみ） */
  touch-action: none;
  /* モバイル時のみ表示 */
  display: none;
  /* シェルエリア以外ではタッチイベントを無効 */
  pointer-events: none;
}

/* シェルエリア内でのみタッチイベントを有効 */
#touch-surface.shell-active {
  pointer-events: auto;
}

/* 虫眼鏡レンズのz-indexを調整（タッチレイヤーより上に表示） */
#magnifierLens {
  z-index: 10000 !important;
}

/* 仮想カーソル（センターポイントが当たり） */
#cursor{
  position: absolute;
  width: 28px; height: 28px;
  margin-left: -14px; margin-top: -14px; /* 中心基準 */
  border: 2px solid rgba(255,255,255,.95);
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(0,0,0,.45), 0 0 8px rgba(0,0,0,.35);
  pointer-events: none; /* クリック判定の邪魔をしない */
  display: none;
  backdrop-filter: invert(1) contrast(1.2) saturate(0.4);
}

/* モバイル時のみタッチレイヤーを表示 */
@media (max-width: 768px) {
  #touch-surface {
    display: block;
  }
}

/* ==================================================
   フッター関連スタイル
   ================================================== */

footer {
  margin-top: auto;
  position: relative;
  color: #fff;
}

footer a:hover {
  color: #ffffff !important;
  text-decoration: underline !important;
}

footer .text-muted {
  color: rgba(255, 255, 255, 0.6) !important;
}
