/* ==========================================
   マルチスポーツ作戦ボード CSS
   プレフィックス: msb-
   サッカー・ハンドボール・タグラグビー・フラッグフットボールを
   1つのCanvasコートで切り替え表示する
   ========================================== */

.msb-root, .msb-root * { box-sizing: border-box; }

.msb-root {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: "BIZ UDGothic", "M PLUS Rounded 1c", "Hiragino Kaku Gothic ProN", "Meiryo", sans-serif;
  background: #eef2ec;
  color: #1f2937;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  z-index: 9999;
}

/* ===== ヘッダー ===== */
.msb-root .msb-header {
  position: fixed; top: 0; left: 0; right: 0;
  height: 52px;
  background: #1e3a5f;
  color: #fff;
  display: flex; align-items: center;
  padding: 0 16px;
  gap: 12px;
  z-index: 20;
}
.msb-root .msb-header h1 { font-size: 16px; font-weight: bold; margin: 0; white-space: nowrap; }
.msb-root .msb-edit-names-btn {
  border: none; background: rgba(255,255,255,0.18); color: #fff;
  width: 30px; height: 30px; border-radius: 999px; font-size: 14px; cursor: pointer;
  flex-shrink: 0; -webkit-tap-highlight-color: transparent;
}
.msb-root .msb-hint {
  flex: 1;
  font-size: 13px; font-weight: bold;
  background: rgba(255,255,255,0.15);
  padding: 6px 14px; border-radius: 999px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  text-align: center;
}

/* ===== スポーツ切り替えバー ===== */
.msb-root .msb-sport-bar {
  position: fixed; top: 52px; left: 0; right: 0;
  height: 40px;
  background: #16283f;
  display: flex; align-items: stretch;
  z-index: 19;
  border-bottom: 2px solid #d4af37;
}
.msb-root .msb-sport-btn {
  flex: 1;
  border: none; background: transparent; color: rgba(255,255,255,0.55);
  font-size: 12px; font-weight: bold;
  display: flex; align-items: center; justify-content: center; gap: 5px;
  cursor: pointer; -webkit-tap-highlight-color: transparent;
  border-right: 1px solid rgba(255,255,255,0.08);
  transition: background .15s, color .15s;
}
.msb-root .msb-sport-btn:last-child { border-right: none; }
.msb-root .msb-sport-btn span { white-space: nowrap; }
.msb-root .msb-sport-btn:active { background: rgba(255,255,255,0.08); }
.msb-root .msb-sport-btn.msb-sport-btn--active {
  background: #d4af37; color: #1e3a5f;
}
/* 修正: 2分割比較トグル（先生モード時のみ表示）は他と区別してボーダーを付ける */
.msb-root .msb-split-btn {
  border-left: 2px solid rgba(212,175,55,0.5) !important;
}
.msb-root .msb-split-btn.msb-sport-btn--active {
  background: #10b981; color: #fff;
}

/* ===== フルスクリーンcourt（先生モードでA/B 2面に分割できる） ===== */
.msb-root #msb-court-wrap {
  position: fixed;
  top: 92px; left: 0; width: 100vw; height: calc(100vh - 92px);
  display: flex; align-items: stretch; justify-content: center;
  padding: 12px; gap: 10px;
}

.msb-root .msb-court-panel {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  height: 100%;
  display: flex; align-items: center; justify-content: center;
  outline: 3px solid transparent;
  outline-offset: -3px;
  border-radius: 12px;
  transition: outline-color .2s;
}
.msb-root .msb-court-panel--hidden { display: none; }
/* 修正: 操作対象（アクティブ）パネルをゴールドの枠で示す。2分割時のみ意味を持つ */
.msb-root #msb-court-wrap.msb-court-wrap--split .msb-court-panel--active {
  outline-color: #d4af37;
}

.msb-root .msb-panel-badge {
  position: absolute; top: 8px; left: 8px; z-index: 30;
  width: 26px; height: 26px; border-radius: 50%;
  background: rgba(30,58,95,0.75); color: #d4af37;
  font-size: 13px; font-weight: 900;
  display: none; align-items: center; justify-content: center;
  border: 1px solid #d4af37;
  pointer-events: none;
}
.msb-root #msb-court-wrap.msb-court-wrap--split .msb-panel-badge { display: flex; }

.msb-root .msb-court {
  position: relative;
  width: 100%; height: 100%;
  max-width: 1100px;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(0,0,0,0.18);
  touch-action: none;
}
/* 修正: ハンドボールのみ円弧(6m/9mライン)を正しい比率で描くため縦横比を固定 */
.msb-root[data-sport="handball"] .msb-court {
  width: min(100%, calc((100vh - 92px - 24px) * 400 / 279.2));
  aspect-ratio: 400 / 279.2;
}
.msb-root .msb-court-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

/* ===== 選手マーカー ===== */
/* 修正: マーカーを20%拡大（40px→48px、フォント12px→14px） */
.msb-root .player {
  position: absolute;
  width: 48px; height: 48px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: bold; color: #fff;
  cursor: grab;
  transform: translate(-50%, -50%);
  box-shadow: 0 2px 6px rgba(0,0,0,0.35);
  border: 3px solid rgba(255,255,255,0.85);
  touch-action: none;
  transition: box-shadow .1s;
  z-index: 3;
}
.msb-root .player.offense { background: linear-gradient(135deg, #FF6B6B, #FF8E53); }
.msb-root .player.defense { background: linear-gradient(135deg, #4ECDC4, #44A08D); }
.msb-root .player.dragging { cursor: grabbing; box-shadow: 0 4px 14px rgba(0,0,0,0.5); z-index: 6; }

/* 修正: 先生モードのマーカー強調表示（タップで選択） */
.msb-root .player.msb-unfocused {
  filter: grayscale(0.85) brightness(0.65);
  opacity: 0.65;
}
.msb-root .player.msb-highlighted {
  transform: translate(-50%, -50%) scale(1.28);
  z-index: 8;
  box-shadow: 0 0 0 4px #d4af37, 0 6px 18px rgba(0,0,0,0.5);
  animation: msb-highlight-pulse 1.3s ease-in-out infinite;
}
@keyframes msb-highlight-pulse {
  0%, 100% { box-shadow: 0 0 0 4px #d4af37, 0 6px 18px rgba(0,0,0,0.5); }
  50%      { box-shadow: 0 0 0 9px rgba(212,175,55,0.35), 0 6px 18px rgba(0,0,0,0.5); }
}

/* ===== 強調表示ヒント（先生モードのみ） ===== */
.msb-root .msb-highlight-hint {
  position: fixed; top: 96px; left: 50%; transform: translateX(-50%);
  z-index: 15;
  background: rgba(30,58,95,0.85); color: #d4af37;
  font-size: 11px; font-weight: bold;
  padding: 5px 14px; border-radius: 999px;
  white-space: nowrap;
  pointer-events: none;
}

/* 修正: ボールマーカー。ハンドボールは黄×黒アイコン(svg)、フラッグフットボールは絵文字🏈 */
.msb-root .player.ball {
  width: 28px; height: 28px;
  font-size: 17px;
  background: #f4d13a;
  border: 2px solid rgba(255,255,255,0.9);
  overflow: hidden;
  z-index: 5;
}
.msb-root .player.ball svg { display: block; width: 100%; height: 100%; pointer-events: none; }
.msb-root .player.ball.msb-ball-emoji { background: radial-gradient(circle at 35% 30%, #a0653d, #6b3410); }
.msb-root .player.ball.dragging { z-index: 7; }

/* ===== 記録中インジケーター ===== */
.msb-root .msb-recording-indicator {
  position: fixed; left: 16px; top: 104px;
  display: none;
  background: #ef4444; color: #fff; font-size: 12px; font-weight: bold;
  padding: 6px 14px; border-radius: 999px; z-index: 15;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

/* ===== 速度パネル（右側・ツールバーの上に縦配置） ===== */
.msb-root .msb-speed-panel {
  position: fixed; right: 16px; bottom: 380px;
  width: 60px;
  background: #fff; border-radius: 999px;
  box-shadow: 0 3px 10px rgba(0,0,0,0.18);
  padding: 12px 0 10px;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  z-index: 10;
}
.msb-root .msb-speed-val { font-size: 12px; font-weight: bold; color: #1e3a5f; }
.msb-root .msb-speed-label { font-size: 10px; font-weight: bold; color: #6b7e99; }
/* 修正: 縦向きのスライダー（Chrome/Safari と Firefox の両方に対応） */
.msb-root .msb-speed-slider {
  width: 8px;
  height: 110px;
  writing-mode: vertical-lr;
  direction: rtl;
  accent-color: #d4af37;
  cursor: pointer;
}

/* ===== 右下ツールバー ===== */
.msb-root .msb-toolbar {
  position: fixed; right: 16px; bottom: 20px;
  display: flex; flex-direction: column; gap: 12px; z-index: 10;
}
.msb-root .msb-btn {
  width: 60px; height: 60px; border-radius: 999px; border: none;
  font-size: 22px; cursor: pointer; box-shadow: 0 3px 8px rgba(0,0,0,0.25);
  display: flex; align-items: center; justify-content: center;
  transition: transform .1s; -webkit-tap-highlight-color: transparent;
  background: #fff; color: #7F8C8D; border: 2px solid #dde4ef;
}
.msb-root .msb-btn:active { transform: scale(0.92); }
.msb-root .msb-btn:disabled { opacity: 0.35; cursor: default; }
.msb-root .msb-btn:disabled:active { transform: none; }
.msb-root .msb-btn-confirm { background: #10b981; color: #fff; }
.msb-root .msb-btn-danger { background: #fff; color: #ef4444; border-color: #ef4444; }
.msb-root .msb-btn-primary { background: #d4af37; color: #fff; }
.msb-root .msb-btn-setting { background: #fff; color: #1e3a5f; border: 2px solid #1e3a5f; }

/* 修正: 攻撃／守備追加ボタンは＋マークなしのボール表示に */
.msb-root .msb-ball-btn { border: none; }
.msb-root .msb-ball-btn.msb-ball-offense { background: linear-gradient(135deg, #FF6B6B, #FF8E53); }
.msb-root .msb-ball-btn.msb-ball-defense { background: linear-gradient(135deg, #4ECDC4, #44A08D); }
.msb-root .msb-ball-btn.msb-ball-ball { background: #fff; padding: 6px; }
.msb-root .msb-ball-btn.msb-ball-ball svg { width: 100%; height: 100%; border-radius: 50%; display: block; }
.msb-root .msb-ball-btn.msb-ball-ball.msb-ball-emoji { background: radial-gradient(circle at 35% 30%, #a0653d, #6b3410); font-size: 22px; padding: 0; }
/* 修正: ボール機能のないスポーツ（サッカー・タグラグビー）ではボタンごと隠す（.hiddenを流用） */

/* 戻る／進む（アンドゥ・リドゥ）のペアボタン（縦積み） */
.msb-root .msb-btn-pair {
  display: flex; flex-direction: column;
  border-radius: 999px; overflow: hidden;
  box-shadow: 0 3px 8px rgba(0,0,0,0.25);
}
.msb-root .msb-btn-pair button {
  width: 60px; height: 30px; border: none; background: #fff; color: #7F8C8D;
  font-size: 16px; cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.msb-root .msb-btn-pair button:first-child { border-bottom: 1px solid #dde4ef; }
.msb-root .msb-btn-pair button:disabled { opacity: 0.35; cursor: default; }
.msb-root .msb-btn-pair button:active { background: #eef2f6; }

/* ===== フレームメッセージ ===== */
.msb-root .msb-frame-message {
  position: fixed; left: 50%; top: 104px; transform: translateX(-50%);
  display: none;
  background: rgba(30,58,95,0.9); color: #fff; font-size: 13px; font-weight: bold;
  padding: 8px 18px; border-radius: 999px; z-index: 16;
}

/* ===== 選手名編集モーダル ===== */
.msb-root .msb-name-edit-modal {
  display: none;
  position: fixed; inset: 0; background: rgba(30,58,95,0.6);
  align-items: center; justify-content: center; z-index: 100; padding: 16px;
}
.msb-root .msb-name-edit-content {
  background: #fff; border-radius: 16px; padding: 24px;
  width: min(94vw, 460px); max-height: 88vh; overflow-y: auto;
}
.msb-root .msb-name-edit-content h3 { font-size: 17px; color: #1e3a5f; margin: 0 0 14px; text-align: center; }
.msb-root .msb-name-edit-content h4 { font-size: 13px; margin: 14px 0 8px; }
.msb-root .msb-offense-label { color: #e8534a; }
.msb-root .msb-defense-label { color: #2196a8; }
.msb-root .msb-name-input-group { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.msb-root .msb-name-input-group label { width: 40px; font-size: 13px; font-weight: bold; flex-shrink: 0; }
.msb-root .msb-name-input-group input {
  flex: 1; padding: 8px 10px; border-radius: 8px; border: 2px solid #dde4ef;
  font-size: 13px; font-family: inherit;
}

.msb-root .hidden { display: none !important; }
