/* =========================================================
   白鳩 混雑時ローダー (busy-loader)
   --------------------------------------------------------
   ・ページ遷移 1 秒超 → ローダー＋ゲーム表示  (.is-pending)
   ・初回表示 3 秒超 → ローダー＋ゲーム表示    (.is-watching-load)
   ・スコアはセッション内で共有 (sessionStorage)
   --------------------------------------------------------
   待機時間は CSS の transition-delay で計測することで、
   JS が止まる遷移中・ロード中でもブラウザ側でカウントが進む。
   ========================================================= */

#shirohato-busy-loader {
  position: fixed;
  inset: 0;
  z-index: 2147483647;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(20, 20, 30, 0.55);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Meiryo", "Yu Gothic", system-ui, sans-serif;
  color: #333;

  /* 既定 = 非表示。hide() の遷移（即フェードアウト） */
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease-out, visibility 0s linear 0.2s;
}

/* ▼ ページ遷移時：3 秒の遅延後にフェードイン
       初回ロード時の表示閾値と揃え、ユーザー体感を統一する。 */
#shirohato-busy-loader.is-pending {
  opacity: 1;
  visibility: visible;
  transition: opacity 0.3s ease-out 3s, visibility 0s linear 3s;
}

/* ▼ 初回ロード時：3 秒の遅延後にフェードイン
       --sh-bl-delay は JS が「ナビ開始からの経過時間」を引いて
       設定する。未指定なら 3s。 */
#shirohato-busy-loader.is-watching-load {
  opacity: 1;
  visibility: visible;
  transition:
    opacity   0.3s ease-out var(--sh-bl-delay, 3s),
    visibility 0s linear    var(--sh-bl-delay, 3s);
}

#shirohato-busy-loader .sh-bl-card {
  width: min(92vw, 460px);
  max-height: 92vh;
  overflow-y: auto;
  background: #fff;
  border-radius: 18px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
  padding: 28px 24px 22px;
  text-align: center;
  position: relative;
  transform: translateY(8px);
  transition: transform 0.3s ease-out 3s;
}
#shirohato-busy-loader.is-pending        .sh-bl-card { transform: translateY(0); }
#shirohato-busy-loader.is-watching-load  .sh-bl-card {
  transform: translateY(0);
  transition: transform 0.3s ease-out var(--sh-bl-delay, 3s);
}

#shirohato-busy-loader .sh-bl-spinner {
  width: 56px;
  height: 56px;
  margin: 4px auto 14px;
  border: 5px solid #f1d6e0;
  border-top-color: #d6336c;
  border-radius: 50%;
  animation: sh-bl-spin 0.9s linear infinite;
}

@keyframes sh-bl-spin {
  to { transform: rotate(360deg); }
}

#shirohato-busy-loader .sh-bl-title {
  font-size: 17px;
  font-weight: 700;
  line-height: 1.55;
  margin: 0 0 6px;
  color: #222;
}

#shirohato-busy-loader .sh-bl-sub {
  font-size: 13px;
  line-height: 1.6;
  color: #666;
  margin: 0 0 18px;
}

#shirohato-busy-loader .sh-bl-divider {
  height: 1px;
  background: linear-gradient(to right, transparent, #eee, transparent);
  margin: 14px 0 12px;
}

#shirohato-busy-loader .sh-bl-game-label {
  font-size: 12px;
  color: #999;
  letter-spacing: 0.06em;
  margin: 0 0 8px;
}

#shirohato-busy-loader .sh-bl-game-title {
  font-size: 14px;
  font-weight: 700;
  color: #d6336c;
  margin: 0 0 10px;
}

#shirohato-busy-loader .sh-bl-stats {
  display: flex;
  justify-content: space-around;
  gap: 8px;
  margin: 0 0 10px;
  font-size: 12px;
  color: #555;
}

#shirohato-busy-loader .sh-bl-stats span b {
  color: #d6336c;
  font-size: 15px;
  margin-left: 4px;
}

#shirohato-busy-loader .sh-bl-stats .sh-bl-best {
  color: #b58a00;
}

#shirohato-busy-loader .sh-bl-stage {
  position: relative;
  width: 100%;
  height: 260px;
  background: linear-gradient(180deg, #fdf2f6 0%, #fff5f8 100%);
  border-radius: 12px;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  cursor: crosshair;
}

#shirohato-busy-loader .sh-bl-item {
  position: absolute;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 30px;
  cursor: pointer;
  transition: transform 0.08s ease-out;
  will-change: transform, top;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,0.12));
}

#shirohato-busy-loader .sh-bl-item:active {
  transform: scale(1.3);
}

#shirohato-busy-loader .sh-bl-pop {
  position: absolute;
  pointer-events: none;
  font-size: 13px;
  font-weight: 700;
  color: #d6336c;
  animation: sh-bl-pop 0.55s ease-out forwards;
}

@keyframes sh-bl-pop {
  0%   { transform: translateY(0) scale(1); opacity: 1; }
  100% { transform: translateY(-30px) scale(1.2); opacity: 0; }
}

#shirohato-busy-loader .sh-bl-foot {
  font-size: 11px;
  color: #aaa;
  margin: 12px 0 0;
  line-height: 1.5;
}

/* 小画面調整 */
@media (max-width: 380px) {
  #shirohato-busy-loader .sh-bl-card { padding: 22px 16px 18px; }
  #shirohato-busy-loader .sh-bl-stage { height: 220px; }
  #shirohato-busy-loader .sh-bl-item { width: 40px; height: 40px; font-size: 26px; }
}
