/* ===========================
   会場の見た目（live_events/_venue_visual・_venue_audience と、固定デコレーションの層・購入モーダル）
   計画 259 §2-5 で live_events.css から移した。曲ページ（この曲のライブイベント）は live_events.css を読まずにこれだけを読む。
   ⚠️ live_events.css を読むページは、その**直前**でこのファイルを読む（元は live_events.css の中にあった規則。
      後ろの live_events.css の規則が上書きする前提の並びを崩さない）。検査 = test/integration/venue_visual_css_test.rb
   =========================== */


/* ===========================
   Venue Visual
   =========================== */
/* design-allow-start: color-literal */
/* 会場ビジュアル (.venue-visual) はダーク前提固定配色。--venue-bg/--venue-stage 等のローカル変数および装飾色（飾り照明・ドロップシャドウ）はテーマ依存しない */

/* ⚠️ **ダーク固定画面の作法**: この世界が使うテーマ追従トークンは全部ここで上書きする
   （.battle-play-page / .bge-container と同じ形。計画書 182 Phase 3-5）。
   上書き漏れがあると light テーマの濃色文字が暗い会場に乗って沈む
   （実測 --lh-success 1.93 / --lh-warning 1.95 / --text-muted 2.00 / --color-danger 2.13）。
   使っているトークンは「.venue-(?!fixed-) のセレクタが参照する var() のうちテーマで値が変わるもの」
   を機械的に洗って確定させた。値は会場 9 tier の地すべてで AA を満たす
   （danger 4.99 / success 6.05 / warning 8.26 / muted 4.90）。
   ⚠️ .venue-fixed-{slot,modal}-* は中で --card-bg のテーマ追従面を自前で敷く「島」だが、
      ここで上書きしたトークンはどれも使っていない（--text-primary / --text-secondary /
      --accent / --border-color だけ）ので
      打ち消しは不要。**この島でトークンを使い始めるときは素のテーマ値に戻すこと**。 */
.venue-visual,
.venue-visual-wrap {
  --color-danger: #f87171;
  --color-danger-rgb: 248, 113, 113;
  --color-success: #22c55e;
  --color-success-rgb: 34, 197, 94;
  --color-warning: #fbbf24;
  --color-warning-rgb: 251, 191, 36;
  --lh-success: var(--color-success);
  --lh-success-rgb: var(--color-success-rgb);
  --lh-warning: var(--color-warning);
  --text-muted: #9a9a9a;
}

.venue-visual {
  --venue-bg: #1a1a2e;
  --venue-accent: var(--color-warning);
  /* 用途: accent を**文字色**として使うときの値。tier 2/5/6 は accent のままだと自分の
     暗い地の上で 3.62〜4.20 しか出ないので、ERB が明度を上げた版を渡す（同 ERB:40〜） */
  --venue-accent-fg: var(--venue-accent);
  --venue-stage: #2d2d44;
  --venue-accent-rgb: 255, 193, 7;
  position: relative;
  /* ⚠️ **ここは宣言どおりダーク固定の世界**（計画書 182 Phase 3-5）。
     以前は background: transparent で、背景画像を持たないイベントでは親の
     --lh-surface-subtle（テーマ追従）が透けていた。中の配色は照明・ステージ・観客ドット・
     文字までダーク前提なので、light テーマでは会場の文字がほぼ全部読めなかった
     （エリアラベル 1.08 / 参加率 1.12 / 進捗ラベル 1.13〜3.23 = 9 tier 全滅）。
     --venue-bg は ERB (_venue_visual.html.erb:62) が tier ごとの暗色を inline で渡す。
     ⚠️ background-color だけを指定すること。ERB が inline で background-image を重ねる。 */
  background-color: var(--venue-bg);
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 1.5rem;
  /* 背景画像(16:9)が常に全体表示されるよう比率を固定 */
  aspect-ratio: 16 / 9;
  display: flex;
  flex-direction: column;
}

/* --- Stage (compact top: small screen + lighting glow) --- */
.venue-stage {
  position: relative;
  padding: 0.5rem 0.75rem 0.2rem;
  overflow: hidden;
  flex-shrink: 0;
}
/* スクリーン非表示時のステージ（最小化） */
.venue-stage-minimal {
  padding: 0.25rem;
}

/* Screen — small distant stage backdrop */
.venue-screen-area {
  position: relative;
  display: flex;
  justify-content: center;
  z-index: 1;
}
.venue-screen {
  position: relative;
  width: 32%;
  max-width: 160px;
  aspect-ratio: 16 / 9;
  border-radius: 2px;
  overflow: hidden;
  border: 1px solid rgba(var(--venue-accent-rgb), 0.35);
  box-shadow:
    0 0 12px rgba(var(--venue-accent-rgb), 0.2),
    0 0 40px rgba(var(--venue-accent-rgb), 0.06);
}
.venue-screen-img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: brightness(0.8) saturate(1.1);
}
.venue-screen-fallback {
  width: 100%;
  height: 100%;
  background: var(--venue-stage);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 2px;
  padding-bottom: 20%;
}
.venue-screen-fallback-bar {
  width: 3px;
  background: rgba(var(--venue-accent-rgb), 0.5);
  border-radius: 1px 1px 0 0;
  animation: venue-eq-bar 1.2s ease-in-out infinite;
}
.venue-screen-fallback-bar:nth-child(1) { height: 30%; animation-delay: 0s; }
.venue-screen-fallback-bar:nth-child(2) { height: 55%; animation-delay: 0.15s; }
.venue-screen-fallback-bar:nth-child(3) { height: 75%; animation-delay: 0.3s; }
.venue-screen-fallback-bar:nth-child(4) { height: 45%; animation-delay: 0.45s; }
.venue-screen-fallback-bar:nth-child(5) { height: 60%; animation-delay: 0.6s; }
@keyframes venue-eq-bar {
  0%, 100% { transform: scaleY(0.3); opacity: 0.3; }
  50% { transform: scaleY(1); opacity: 0.8; }
}

.venue-screen-glow {
  position: absolute;
  inset: -4px;
  border-radius: 4px;
  pointer-events: none;
  box-shadow:
    0 4px 30px rgba(var(--venue-accent-rgb), 0.25),
    0 8px 60px rgba(var(--venue-accent-rgb), 0.08);
  animation: venue-screen-pulse 4s ease-in-out infinite;
}

/* Stage animations */
@keyframes venue-screen-pulse {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}
/* --- Decorations Overlay --- */
.venue-decorations {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
  overflow: hidden;
}
.venue-decorations:empty {
  display: none;
}
/* design-allow-end: color-literal */

/* --- Audience --- */
.venue-audience {
  padding: 0.75rem 1rem;
  padding-bottom: 4px;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  align-items: center;
  align-content: center;
  overflow: hidden;
}
/* メダルが overflow: hidden でクリップされないよう、はみ出し分を内側に収める */
.venue-person {
  margin: 3px;
}

.venue-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-muted);
  font-size: 0.85rem;
  padding: 1rem;
}
.venue-empty i {
  font-size: 1.5rem;
}

/* --- Person Avatar ---
   width/height は内部 .venue-person-img (mini variant 20x20 を 100% で表示) に依存。
   旧設計の min-width/min-height: 44px + flex-shrink:0 は venue サイズに関係なく 44px を強制し、
   (1) 20x20 元画像を 44x44 にアップスケールして画質劣化
   (2) 小さい venue で audience が wrap し aspect-ratio:16/9 を破る
   の不具合を起こすため撤回。 必要なら親側で width/height を指定する */
.venue-person {
  border-radius: 50%;
  overflow: hidden;
  position: relative;
  border: 2px solid transparent;
  display: flex;
  align-items: center;
  justify-content: center;
}
.venue-person-gold  { border-color: #ffd700; box-shadow: 0 0 6px rgba(255, 215, 0, 0.4); }
.venue-person-silver { border-color: #c0c0c0; box-shadow: 0 0 6px rgba(192, 192, 192, 0.3); }
.venue-person-bronze { border-color: #cd7f32; box-shadow: 0 0 6px rgba(205, 127, 50, 0.3); }

.venue-person-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.venue-person-default {
  width: 100%;
  height: 100%;
  background: #555;
}

.venue-person-medal {
  position: absolute;
  bottom: -1px;
  right: -1px;
  font-size: 0.6rem;
  line-height: 1;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.5));
}

.venue-person-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: rgba(var(--venue-accent-rgb), 0.35);
}

/* --- Top 3 Row --- */
.venue-top3 {
  display: flex;
  gap: 8px;
  justify-content: center;
  width: 100%;
  margin-bottom: 0.5rem;
}

/* --- Dots --- */
.venue-dots {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  justify-content: center;
  align-items: center;
  width: 100%;
}
.venue-dots-more {
  font-size: 0.7rem;
  color: var(--venue-accent-fg);
  padding: 0.125rem 0.375rem;
}

/* --- Progress Bar --- */
.venue-progress {
  width: 100%;
  margin-top: 0.375rem;
}
.venue-progress-track {
  height: 10px;
  background: rgba(var(--venue-accent-rgb), 0.12);
  border-radius: 5px;
  overflow: hidden;
}
.venue-progress-fill {
  height: 100%;
  background: var(--venue-accent);
  border-radius: 5px;
  transition: width 0.5s;
}
.venue-progress-label {
  font-size: 0.75rem;
  color: var(--venue-accent-fg);
  text-align: center;
  margin-top: 0.375rem;
}

/* --- Area Grid (Tier 5-6) --- */
.venue-area-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  width: 100%;
}
.venue-area-block {
  background: var(--venue-accent);
  border-radius: 4px;
  padding: 0.5rem;
  text-align: center;
}
.venue-area-label {
  font-size: 0.65rem;
  color: rgba(255, 255, 255, 0.7);
}
.venue-area-pct {
  font-size: 0.85rem;
  color: #fff; /* design-allow: color-literal */
  font-weight: bold;
}

/* --- Overview (Tier 7-8) --- */
.venue-overview {
  width: 100%;
  height: 80px;
  border-radius: 8px;
  background: rgba(var(--venue-accent-rgb), 0.08);
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
.venue-overview-fill {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(0deg, var(--venue-accent), transparent);
  opacity: 0.3;
  transition: height 0.5s;
}
.venue-overview-pct {
  font-size: 2rem;
  font-weight: bold;
  color: #fff; /* design-allow: color-literal */
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
  position: relative;
  z-index: 1;
}

/* --- Recruit Message --- */
/* ⚠️ 募集ゲージ本体（.venue-recruit / -header / -track / -fill / -success）は
   ERB・JS のどこからも出力されないデッドコードだったので削除した
   （動的なクラス名組み立ても無いことを確認済み。計画書 182 Phase 3-5）。
   実際に出るのは _venue_visual.html.erb:153 の .venue-recruit-msg{,-ok,-fail} だけ。 */
.venue-recruit-msg {
  font-size: 0.75rem;
  margin-top: auto;
  padding-bottom: 0.5rem;
  text-align: center;
  flex-shrink: 0;
}
.venue-recruit-msg-ok   { color: var(--lh-success); }
.venue-recruit-msg-fail { color: var(--color-danger); }

/* --- Settled --- */
.venue-settled-msg {
  text-align: center;
  margin-top: auto;
  padding: 0 0.5rem 0.5rem;
  font-size: 0.85rem;
  color: var(--venue-accent-fg);
  flex-shrink: 0;
}

/* --- Venue responsive --- */
@media (max-width: 480px) {
  .venue-stage {
    padding: 0.4rem 0.5rem 0.2rem;
  }
  .venue-screen {
    width: 40%;
  }
  .venue-person {
    width: 28px;
    height: 28px;
  }
}

/* ========================================
   観客アイコン配置 (audience_layout)
   ======================================== */

/* outside モード: .venue-visual を縦積みコンテナで包み、観客を枠外に出す */
.venue-visual-wrap {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.venue-audience-outside {
  flex: 0 0 auto;
  max-height: none;
  display: flex;
  flex-wrap: nowrap;
  overflow-x: auto;
  gap: 6px;
  padding: 0.5rem 0.75rem;
  /* ⚠️ outside モードでは観客エリアが .venue-visual の**外**に出るが、中身は同じ partial
     （_venue_audience）でダーク前提の配色を使う。rgba(0,0,0,.15) だと light テーマで
     明るい帯になって同じ文字が読めなくなるので、会場と同じ地に揃える。
     --venue-bg は親の .venue-visual-wrap が inline で持っている（同 ERB:63） */
  background-color: var(--venue-bg);
  border-radius: 6px;
}

/* outside モードの内部レイアウト: ステージを伸ばし、内部観客プレースホルダを非表示 */
.venue-visual[data-audience-layout="outside"] .venue-stage {
  flex: 1;
}
.venue-audience--placeholder {
  flex: 0 0 auto;
  padding: 0;
  min-height: 0;
}

/* hidden モードの内部レイアウト: 観客エリアを最小化 */
.venue-visual[data-audience-layout="hidden"] .venue-audience {
  flex: 0 0 auto;
  padding: 0.4rem 1rem;
}
.venue-visual[data-audience-layout="hidden"] .venue-stage {
  flex: 1;
}

/* anonymous_crowd モード: 順位演出を排除 */
.venue-person--anonymous {
  border-color: transparent;
  box-shadow: none;
}
.venue-person--anonymous .venue-person-medal {
  display: none;
}

/* custom モード: スロットを絶対配置 */
.venue-visual[data-audience-layout="custom"] .venue-audience {
  display: block;
  position: relative;
  overflow: visible;
}
.venue-person--slot {
  position: absolute;
  margin: 0;
}
.venue-person--clip-bottom-half { clip-path: inset(0 0 50% 0); }
.venue-person--clip-top-half    { clip-path: inset(50% 0 0 0); }
.venue-person--clip-oval        { clip-path: ellipse(50% 35% at 50% 35%); }
.venue-person--no-medal .venue-person-medal { display: none; }
.venue-slot-overflow {
  position: absolute;
  bottom: 4%;
  right: 4%;
  font-size: 0.75rem;
  /* ⚠️ 同系色の薄い tint の上に同じ accent。文字だけ明度を上げた版にする（tint は据え置き） */
  color: var(--venue-accent-fg);
  background: rgba(var(--venue-accent-rgb), 0.15);
  padding: 0.2rem 0.5rem;
  border-radius: 8px;
  z-index: 2;
  pointer-events: none;
}

/* プログレスバーマーカー (success / pending) */
.venue-progress-marker {
  position: absolute;
  top: -2px;
  bottom: -2px;
  width: 2px;
  background: rgba(255, 255, 255, 0.3);
  z-index: 1;
  border-radius: 1px;
}
.venue-progress-marker--success {
  background: var(--color-success);
}

@media (max-width: 600px) {
  .venue-audience-outside {
    flex-wrap: wrap;
    overflow-x: visible;
    max-height: 120px;
    overflow-y: hidden;
  }
  .venue-audience-outside .venue-person {
    min-width: 36px;
    min-height: 36px;
  }
}
/* 会場プログレスバー用 */
.venue-progress-fill.venue-progress-ok {
  background: var(--lh-success);
}
.venue-progress-fill.venue-progress-full {
  background: linear-gradient(90deg, var(--color-warning), var(--color-warning));
}

/* --- 固定デコレーション 背面レイヤー (視聴者側) ---
 * 階層:
 *   venue-visual の background-image = z軸最下
 *   venue-fixed-decoration-layer (z:0) = 背景の上
 *   venue-stage / venue-screen-area (z:1+) = スクリーン・UI = 上
 *   venue-decorations (reactions) = 更に上
 */
/* 仮想 960x540 px 座標系: スロットは px ベースで配置し、
 * レイヤー全体を transform: scale() で venue サイズに合わせる。
 * 用途: venue-visual の実描画幅 / 960 を JS (ResizeObserver) で代入。 */
.venue-fixed-decoration-layer {
  --venue-scale: 1;
  position: absolute;
  top: 0;
  left: 0;
  width: 960px;
  height: 540px;
  pointer-events: none;
  z-index: 0;
  transform-origin: 0 0;
  transform: scale(var(--venue-scale));
}

.venue-fixed-slot {
  position: absolute;
  pointer-events: auto;
  transform-origin: top left;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: visible; /* タップ領域擬似要素をクリップしないため */
}

/* motion スロット: offset-path に沿ってアニメーション。
 * Web Animations API (Element.animate) で各スロットに個別の animation を
 * セットするため CSS の animation-* を上書き指定する必要はない。 */
.venue-fixed-slot.is-motion { transform-origin: center; }

.venue-fixed-slot img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* --- 固定アイテム購入モーダル --- */
.venue-fixed-modal {
  position: fixed;
  inset: 0;
  background: var(--card-overlay-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--z-modal);
}

.venue-fixed-modal[hidden] {
  display: none;
}

.venue-fixed-modal-box {
  position: relative;
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--card-radius);
  padding: 1.5rem;
  max-width: 360px;
  width: 90%;
  text-align: center;
}

.venue-fixed-modal-close {
  position: absolute;
  top: 0.4rem;
  right: 0.4rem;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 1rem;
  cursor: pointer;
  padding: 0.3rem;
}

.venue-fixed-modal-title {
  margin: 0 0 0.75rem;
  font-size: 1rem;
  color: var(--text-primary);
}

.venue-fixed-modal-desc {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin: 0 0 0.75rem;
  line-height: 1.6;
}

.venue-fixed-modal-preview {
  width: 120px;
  height: 120px;
  margin: 0 auto 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.venue-fixed-modal-name {
  font-size: 0.9rem;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
}

.venue-fixed-modal-price {
  font-size: 1.1rem;
  color: var(--accent);
  font-weight: 600;
  margin-bottom: 1rem;
}

.venue-fixed-modal-error {
  color: var(--accent);
  font-size: 0.75rem;
  margin-bottom: 0.75rem;
}

.venue-fixed-modal-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
}

/* モーダル開示中の body scroll ロック */
body.venue-fixed-modal-open {
  overflow: hidden;
}

/* --- 購入完了 toast --- */
.venue-fixed-toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--card-bg);
  color: var(--text-primary);
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
  box-shadow: 0 4px 12px var(--card-overlay-bg);
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 1100;
  pointer-events: none;
}

.venue-fixed-toast-show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
