/* style.css - 애쉬 그라운드 (Ash Ground) 전체 UI 스타일 */

:root {
  --bg: #0b1120;
  --surface: #111827;
  --surface-2: #1e293b;
  --border: #334155;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --team0: #22c55e;
  --team1: #ef4444;
  --ok: #34d399;
  --fail: #f87171;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Pretendard", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  line-height: 1.5;
  min-height: 100vh;
}

.hidden {
  display: none !important;
}

#app {
  max-width: 1440px;
  margin: 0 auto;
  padding: 16px 20px 40px;
}

/* 전투 화면 진입 시 전역 헤더 숨김 및 풀뷰포트 여백 최적화 */
#app.is-battle-view {
  max-width: 1600px;
  padding: 10px 14px 28px;
}

#app.is-battle-view .app-header {
  display: none;
}

#app.is-battle-view .viewer-section {
  padding: 8px;
  gap: 8px;
}

#app.is-battle-view .viewer-canvas {
  height: clamp(640px, calc(100vh - 38px), 980px);
}

/* 헤더 */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding-bottom: 12px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.app-header h1 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

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

.nav-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}

.mute-btn {
  margin-left: 4px;
  border-color: #0ea5e9;
  color: #bae6fd;
}

.mute-btn.is-muted {
  border-color: var(--border);
  color: var(--muted);
  background: var(--surface);
}

.badge {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: #38bdf8;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
}

/* 메인 워크스페이스 */
.workspace {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.lobby-view {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ===========================
   편성 로비 UI (디버그 옵션 통합)
   =========================== */
.lobby-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.lobby-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.lobby-title-wrap h2 {
  font-size: 1.1rem;
  font-weight: 700;
}

.lobby-subtitle {
  font-size: 0.82rem;
  color: var(--muted);
  margin-top: 2px;
}

.lobby-mode-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.mode-tab {
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 0.86rem;
  font-weight: 600;
}

.mode-tab.active {
  background: #0ea5e9;
  border-color: #0ea5e9;
  color: #0b1120;
}

.lobby-options-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
}

.lobby-opt-group {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  color: var(--muted);
}

.lobby-opt-group label {
  white-space: nowrap;
}

.lobby-opt-group select {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 0.82rem;
}

.lobby-teams-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.team-panel {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.team-panel.team-0 {
  border-top: 3px solid var(--team0);
}

.team-panel.team-1 {
  border-top: 3px solid var(--team1);
}

.team-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 0.92rem;
  font-weight: 700;
}

.team-panel.team-0 .team-panel-header {
  color: #86efac;
}

.team-panel.team-1 .team-panel-header {
  color: #fca5a5;
}

.lobby-status-wrap {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.pinned-seed-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(250, 204, 21, 0.14);
  border: 1px solid rgba(250, 204, 21, 0.55);
  color: #fde047;
  font-size: 0.76rem;
  font-weight: 700;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.pinned-seed-clear {
  padding: 1px 6px;
  font-size: 0.7rem;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.75);
  border: 1px solid rgba(250, 204, 21, 0.45);
  color: #fef08a;
}

.pinned-seed-clear:hover:not(:disabled) {
  background: rgba(250, 204, 21, 0.25);
  border-color: #fde047;
}

.slot-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.slot-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.slot-badge {
  flex: 0 0 28px;
  text-align: center;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 0;
}

.slot-input {
  flex: 1;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 10px;
  font-size: 0.86rem;
  font-family: inherit;
}

.slot-input:focus {
  outline: none;
  border-color: var(--primary);
}

.duel-hint {
  font-size: 0.78rem;
  color: var(--muted);
  background: rgba(15, 23, 42, 0.55);
  border: 1px dashed var(--border);
  border-radius: 6px;
  padding: 8px 10px;
}

.br-panel {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-top: 3px solid #38bdf8;
  border-radius: 10px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.br-panel.team-bulk-panel {
  border-top-color: var(--team0);
}

.br-panel textarea {
  width: 100%;
  min-height: 160px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 0.86rem;
  font-family: inherit;
  resize: vertical;
}

.br-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--muted);
}

.lobby-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  padding-top: 6px;
  border-top: 1px solid var(--border);
}

.lobby-start-btn {
  padding: 10px 24px;
  font-size: 0.95rem;
}

/* 최근 실행 기록 (접이식 목록) */
.history-panel {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.history-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 14px;
  font-size: 0.84rem;
  font-weight: 700;
  color: #e2e8f0;
  cursor: pointer;
  user-select: none;
  list-style: none;
}

.history-summary::-webkit-details-marker {
  display: none;
}

.history-summary::before {
  content: "▶";
  display: inline-block;
  margin-right: 6px;
  font-size: 0.72rem;
  color: #38bdf8;
  transition: transform 0.15s ease;
}

.history-panel[open] .history-summary::before {
  transform: rotate(90deg);
}

.history-summary-hint {
  margin-left: auto;
  font-size: 0.74rem;
  font-weight: 500;
  color: var(--muted);
}

.history-panel[open] .history-summary-hint {
  display: none;
}

.history-body {
  padding: 10px 14px 12px;
  border-top: 1px solid var(--border);
  background: rgba(11, 17, 32, 0.45);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.history-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}

.history-toolbar-desc {
  font-size: 0.76rem;
  color: var(--muted);
}

.btn-history-clear {
  padding: 4px 10px;
  font-size: 0.76rem;
  color: #fca5a5;
  border-color: rgba(248, 113, 113, 0.45);
}

.btn-history-clear:hover:not(:disabled) {
  background: rgba(239, 68, 68, 0.16);
  border-color: #f87171;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 280px;
  overflow-y: auto;
}

.history-empty {
  font-size: 0.8rem;
  color: var(--muted);
  padding: 10px 6px;
  text-align: center;
}

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.history-item-info {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.history-item-top {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 10px;
  font-size: 0.78rem;
}

.history-item-time {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-weight: 700;
  color: #e2e8f0;
}

.history-item-seed {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.74rem;
  color: #fde047;
  background: rgba(250, 204, 21, 0.1);
  border: 1px solid rgba(250, 204, 21, 0.3);
  border-radius: 4px;
  padding: 1px 6px;
}

.history-item-meta {
  color: #7dd3fc;
  font-weight: 600;
}

.history-item-roster {
  font-size: 0.75rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-history-load {
  flex-shrink: 0;
  padding: 5px 11px;
  font-size: 0.78rem;
  border-color: #0ea5e9;
  color: #bae6fd;
}

.btn-history-load:hover:not(:disabled) {
  background: rgba(14, 165, 233, 0.2);
  border-color: #38bdf8;
}

/* 2.5D 뷰어 섹션 */
.viewer-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.viewer-stage {
  position: relative;
  width: 100%;
  border-radius: 8px;
  overflow: hidden;
}

.viewer-canvas {
  width: 100%;
  height: clamp(620px, 76vh, 840px);
  background: #0f172a;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  position: relative;
}

.viewer-canvas canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* 전투 화면 좌측 상단 오버레이 (FPS 토글 · 생존 인원 상시 / 연산 시간 토글) */
.viewer-debug-hud {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 12;
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  padding: 5px 10px;
  background: rgba(11, 17, 32, 0.5);
  border: 1px solid rgba(71, 85, 105, 0.45);
  border-radius: 6px;
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.8rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #e2e8f0;
  pointer-events: none;
  user-select: none;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.22);
}

.viewer-debug-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.viewer-debug-sim {
  font-size: 0.73rem;
  font-weight: 700;
  line-height: 1.25;
  color: #7dd3fc;
  white-space: nowrap;
}

.viewer-debug-sim.sim-fast {
  color: #4ade80;
}

.viewer-debug-sim.sim-warn {
  color: #facc15;
}

.viewer-debug-sim.sim-slow {
  color: #f87171;
}

.viewer-debug-fps {
  min-width: 66px;
}

.viewer-debug-fps.fps-good {
  color: #4ade80;
}

.viewer-debug-fps.fps-warn {
  color: #facc15;
}

.viewer-debug-fps.fps-low {
  color: #f87171;
}

.viewer-debug-fps.fps-idle {
  color: #94a3b8;
}

.viewer-debug-sep {
  color: #475569;
}

.viewer-debug-alive {
  color: #38bdf8;
}

/* 전투 화면 상단 중앙 오버레이 (경과 시간 + 광폭화 배너) */
.viewer-center-hud {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 12;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: none;
  user-select: none;
}

.viewer-timer-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 76px;
  padding: 4px 14px;
  background: rgba(11, 17, 32, 0.78);
  border: 1px solid rgba(71, 85, 105, 0.85);
  border-radius: 999px;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.32);
}

.viewer-timer-value {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.98rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
  color: #f8fafc;
}

/* 전투 화면 우측 상단 오디오 토글 오버레이 */
.viewer-audio-hud {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 12;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.viewer-audio-btn {
  padding: 5px 10px;
  font-size: 0.76rem;
  font-weight: 700;
  background: rgba(11, 17, 32, 0.78);
  border: 1px solid rgba(14, 165, 233, 0.75);
  border-radius: 6px;
  color: #bae6fd;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.28);
}

.viewer-audio-btn:hover:not(:disabled) {
  background: rgba(30, 41, 59, 0.92);
  border-color: #38bdf8;
}

.viewer-audio-btn.is-muted {
  border-color: rgba(71, 85, 105, 0.85);
  color: var(--muted);
  background: rgba(11, 17, 32, 0.65);
}

/* 전투 종료 미세 암전 + VICTORY 배너 (클릭 통과) */
.viewer-victory-overlay {
  position: absolute;
  inset: 0;
  z-index: 9;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: clamp(72px, 13vh, 130px);
  background: rgba(6, 10, 20, 0.28);
  pointer-events: none;
  user-select: none;
  opacity: 0;
  transition: opacity 0.35s ease;
}

.viewer-victory-overlay.is-visible {
  opacity: 1;
}

.viewer-victory-banner {
  display: inline-flex;
  align-items: baseline;
  gap: 10px;
  padding: 12px 28px;
  background: linear-gradient(135deg, rgba(15, 23, 42, 0.86), rgba(30, 41, 59, 0.82));
  border: 1px solid rgba(250, 204, 21, 0.65);
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.48), 0 0 24px rgba(250, 204, 21, 0.18);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  transform: translateY(-6px);
  transition: transform 0.35s ease;
}

.viewer-victory-overlay.is-visible .viewer-victory-banner {
  transform: translateY(0);
}

.viewer-victory-label {
  font-size: clamp(1.2rem, 2.2vw, 1.65rem);
  font-weight: 900;
  letter-spacing: 0.08em;
  color: #facc15;
  text-shadow: 0 2px 10px rgba(250, 204, 21, 0.35);
}

.viewer-victory-sep {
  font-size: clamp(1.1rem, 2vw, 1.5rem);
  font-weight: 700;
  color: rgba(248, 250, 252, 0.65);
}

.viewer-victory-winner {
  font-size: clamp(1.15rem, 2.1vw, 1.6rem);
  font-weight: 800;
  color: #f8fafc;
  letter-spacing: -0.01em;
}

/* 전투 시작 전용 전체 화면 로딩 오버레이 (상호작용 차단 · 정적 안내 문구) */
.battle-loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(11, 17, 32, 0.86);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  pointer-events: auto;
  user-select: none;
}

.battle-loading-card {
  min-width: min(360px, 100%);
  max-width: 460px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 22px 28px;
  background: var(--surface);
  border: 1px solid rgba(56, 189, 248, 0.4);
  border-radius: 12px;
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.52);
  text-align: center;
}

.battle-loading-title {
  font-size: 1rem;
  font-weight: 700;
  color: #f8fafc;
  letter-spacing: -0.01em;
}

.battle-loading-stage {
  font-size: 0.84rem;
  font-weight: 600;
  color: #7dd3fc;
  font-variant-numeric: tabular-nums;
}

/* 상·하단 HUD */
.hud-top,
.hud-bottom {
  width: 100%;
}

.hud-top:empty,
.hud-bottom:empty {
  display: none;
}

.hud-top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px;
}

.hud-team-summary {
  font-size: 0.9rem;
  font-weight: 700;
}

.hud-team-summary.team-1 {
  color: #fca5a5;
}

.hud-team-summary.team-0 {
  color: #86efac;
}

.hud-ffa-summary {
  font-size: 0.92rem;
  font-weight: 700;
  color: #38bdf8;
}

.hud-mode-tag {
  font-size: 0.78rem;
  color: var(--muted);
}

.hud-timer-box {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.hud-timer-label {
  font-size: 0.75rem;
  color: var(--muted);
}

.hud-timer-value {
  font-size: 1.05rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: #facc15;
}

.hud-sim-timing {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.73rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #7dd3fc;
  background: var(--bg);
  border: 1px solid rgba(56, 189, 248, 0.35);
  padding: 2px 7px;
  border-radius: 4px;
  white-space: nowrap;
  cursor: help;
}

.hud-sim-timing.sim-fast {
  color: #4ade80;
  border-color: rgba(74, 222, 128, 0.35);
}

.hud-sim-timing.sim-warn {
  color: #facc15;
  border-color: rgba(250, 204, 21, 0.4);
}

.hud-sim-timing.sim-slow {
  color: #f87171;
  border-color: rgba(248, 113, 113, 0.45);
}

.hud-version-tag {
  font-size: 0.72rem;
  color: var(--muted);
  background: var(--bg);
  padding: 2px 6px;
  border-radius: 4px;
}

/* 5:5 상단(위팀) / 하단(아래팀) 가로 5열 HUD 행 */
.hud-team-row {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  margin-top: 6px;
}

/* 대규모 팀전 (10:10 / 25:25) 컴팩트 스크롤 그리드 */
.hud-team-row.is-large {
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
  gap: 6px;
  max-height: 156px;
  overflow-y: auto;
  padding-right: 4px;
}

.hud-team-row.team-1 .hud-hp-fill {
  background: var(--team1);
}

.hud-team-row.team-0 .hud-hp-fill {
  background: var(--team0);
}

/* 난전 하단 컴팩트 그리드 */
.hud-bottom-ffa-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
  gap: 6px;
}

/* 유닛 카드 (추후 우상단 i 버튼 확장을 위해 position: relative 적용) */
.hud-unit-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
  overflow: hidden;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 8px 5px;
  cursor: pointer;
  user-select: none;
  transition: opacity 0.2s ease, filter 0.2s ease, border-color 0.15s ease, background 0.15s ease;
}

.hud-unit-card:not(.is-dead):hover {
  border-color: #38bdf8;
  background: #273549;
}

.hud-unit-card.compact {
  padding: 5px 7px 4px;
  gap: 4px;
}

.hud-unit-card.is-dead {
  opacity: 0.35;
  filter: grayscale(0.85);
  cursor: default;
}

.hud-card-main {
  display: flex;
  align-items: stretch;
  gap: 8px;
  min-width: 0;
}

.hud-unit-card.compact .hud-card-main {
  gap: 6px;
}

/* 좌측: 등급 별 + 포트레이트 수직 컬럼 */
.hud-portrait-col {
  flex: 0 0 42px;
  width: 42px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}

.hud-unit-card.compact .hud-portrait-col {
  flex: 0 0 36px;
  width: 36px;
  gap: 1px;
}

.hud-grade-stars {
  color: #facc15;
  font-size: 0.62rem;
  line-height: 1;
  letter-spacing: -1.5px;
  white-space: nowrap;
  text-align: center;
  width: 100%;
  overflow: hidden;
}

.hud-unit-card.compact .hud-grade-stars {
  font-size: 0.56rem;
  letter-spacing: -1.8px;
}

.hud-portrait {
  width: 36px;
  height: 36px;
}

.hud-unit-card.compact .hud-portrait {
  width: 30px;
  height: 30px;
}

.hud-portrait-svg {
  width: 100%;
  height: 100%;
  display: block;
}

/* 우측: 닉네임 / 체력 수치 / 두꺼운 중첩 체력·보호막바 */
.hud-unit-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 3px;
}

.hud-unit-name-row {
  display: flex;
  align-items: center;
  min-width: 0;
}

.hud-unit-name {
  font-size: 0.8rem;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hud-unit-hp-row {
  display: flex;
  align-items: center;
  min-width: 0;
  line-height: 1.1;
}

.hud-unit-hp-text {
  display: block;
  width: 100%;
  font-size: 0.68rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hud-hp-track {
  position: relative;
  width: 100%;
  height: 12px;
  background: var(--bg);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid rgba(51, 65, 85, 0.7);
}

.hud-unit-card.compact .hud-hp-track {
  height: 10px;
}

.hud-hp-fill {
  height: 100%;
  background: #38bdf8;
  transition: width 0.08s linear;
}

.hud-shield-base,
.hud-shield-fill {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  transition: width 0.08s linear;
  pointer-events: none;
}

.hud-shield-fill {
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.65);
}

/* 카드 하단 스탯 바 (공격력 / 크리티컬 / 속도 / 팀전 한정 어그로) */
.hud-stat-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  padding-top: 4px;
  border-top: 1px solid rgba(51, 65, 85, 0.6);
  min-width: 0;
}

.hud-unit-card.compact .hud-stat-row {
  padding-top: 3px;
  gap: 3px;
}

.hud-stat-item {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-size: 0.7rem;
  font-weight: 600;
  line-height: 1;
  color: #cbd5e1;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  transition: color 0.15s ease;
}

.hud-unit-card.compact .hud-stat-item {
  font-size: 0.64rem;
}

.hud-stat-icon {
  width: 11px;
  height: 11px;
  flex-shrink: 0;
  opacity: 0.82;
}

.hud-unit-card.compact .hud-stat-icon {
  width: 10px;
  height: 10px;
}

.hud-stat-item.is-buffed {
  color: #4ade80;
  font-weight: 700;
}

.hud-stat-item.is-buffed .hud-stat-icon {
  opacity: 1;
}

.hud-stat-item.is-debuffed {
  color: #f87171;
  font-weight: 700;
}

.hud-stat-item.is-debuffed .hud-stat-icon {
  opacity: 1;
}

/* 재생 컨트롤 바 (전투 화면 하단 플로팅 오버레이) */
.viewer-controls {
  position: absolute;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  z-index: 10;
  width: calc(100% - 28px);
  max-width: 960px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 12px;
  flex-wrap: wrap;
  background: rgba(15, 23, 42, 0.86);
  border: 1px solid rgba(71, 85, 105, 0.85);
  border-radius: 10px;
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
  opacity: 0.4;
  transition: opacity 0.18s ease, background 0.18s ease, border-color 0.18s ease;
}

.viewer-controls:hover,
.viewer-controls:focus-within {
  opacity: 0.98;
  background: rgba(15, 23, 42, 0.95);
  border-color: rgba(100, 116, 139, 0.95);
}

.control-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.viewer-controls button {
  padding: 5px 10px;
  font-size: 0.8rem;
}

#btn-play-pause {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-width: 112px;
  text-align: center;
  white-space: nowrap;
}

.viewer-controls select {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 9px;
  font-size: 0.8rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.viewer-controls select:hover {
  background: #273549;
  border-color: #475569;
}

.viewer-controls select:focus {
  outline: none;
  border-color: var(--primary);
}

.progress-wrap {
  flex: 1;
  min-width: 150px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.progress-track {
  flex: 1;
  height: 7px;
  background: rgba(11, 17, 32, 0.85);
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--primary);
}

.time-label {
  font-size: 0.78rem;
  color: #cbd5e1;
  font-variant-numeric: tabular-nums;
  min-width: 88px;
  text-align: right;
}

/* 버튼 공통 */
button {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 12px;
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

button:hover:not(:disabled) {
  background: #273549;
  border-color: #475569;
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

button.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}

button.primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

button.speed-btn.active {
  background: #0ea5e9;
  border-color: #0ea5e9;
  color: #0b1120;
}

/* 디버그 & 전투 하단 결과 패널 */
.debug-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.battle-result-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.battle-result-toggles {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.result-toggle-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  font-size: 0.82rem;
  color: #cbd5e1;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.result-toggle-btn[aria-expanded="true"] {
  border-color: #38bdf8;
  color: #bae6fd;
  background: rgba(14, 165, 233, 0.14);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
}

.controls-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
}

.field label {
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 600;
}

.field select,
.field textarea {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 0.85rem;
  font-family: inherit;
}

.field textarea {
  min-height: 70px;
  resize: vertical;
}

.debug-options-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
  padding: 8px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.82rem;
}

.debug-options-spacer {
  flex: 1;
}

.btn-reset-settings {
  padding: 5px 11px;
  font-size: 0.78rem;
  color: #cbd5e1;
  border-color: #475569;
  background: var(--bg);
}

.btn-reset-settings:hover:not(:disabled) {
  border-color: #f87171;
  color: #fca5a5;
  background: rgba(239, 68, 68, 0.12);
}

.debug-checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
  user-select: none;
}

.debug-checkbox-label input[type="checkbox"] {
  accent-color: var(--primary);
  width: 15px;
  height: 15px;
  cursor: pointer;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* 요약 통계 */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 10px;
}

.stat-box {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}

.stat-box .label {
  font-size: 0.74rem;
  color: var(--muted);
  margin-bottom: 4px;
}

.stat-box .value {
  font-size: 0.92rem;
  font-weight: 700;
  word-break: break-all;
}

.stat-box .value.sim-fast {
  color: #4ade80;
}

.stat-box .value.sim-warn {
  color: #facc15;
}

.stat-box .value.sim-slow {
  color: #f87171;
}

.stat-box .sub-value {
  margin-top: 3px;
  font-size: 0.72rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.status-ok {
  color: var(--ok);
}

.status-fail {
  color: var(--fail);
}

/* 유닛 테이블 */
.unit-table-wrap {
  overflow-x: auto;
}

.unit-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.unit-table th,
.unit-table td {
  padding: 7px 8px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}

.unit-table th {
  color: var(--muted);
  font-weight: 600;
  background: var(--surface-2);
}

.color-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: 5px;
  vertical-align: middle;
}

/* 로그 필터 및 출력 */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 10px;
  font-size: 0.8rem;
}

.filter-bar label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
}

.log-output {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  max-height: 320px;
  overflow-y: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.78rem;
}

.log-line {
  padding: 2px 0;
  border-bottom: 1px solid rgba(51, 65, 85, 0.35);
}

.log-SPAWN { color: #94a3b8; }
.log-MOVE { color: #64748b; }
.log-BUFF { color: #34d399; }
.log-ATTACK { color: #38bdf8; }
.log-SKILL { color: #c084fc; }
.log-DAMAGE { color: #fbbf24; }
.log-DEATH { color: #f87171; font-weight: 700; }
.log-XP_GAIN { color: #a3e635; }
.log-SUPPLY_DROP { color: #fb923c; font-weight: 600; }
.log-PROMOTE { color: #fde047; font-weight: 700; }
.log-FRENZY { color: #fb7185; font-weight: 700; }
.log-END { color: #facc15; font-weight: 700; }

@media (max-width: 900px) {
  .lobby-teams-grid {
    grid-template-columns: 1fr;
  }
  .hud-team-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .viewer-canvas,
  #app.is-battle-view .viewer-canvas {
    height: 520px;
  }
  .viewer-debug-hud {
    top: 8px;
    left: 8px;
    padding: 4px 8px;
    font-size: 0.74rem;
  }
  .viewer-center-hud {
    top: 8px;
  }
  .viewer-timer-pill {
    padding: 3px 10px;
    min-width: 64px;
  }
  .viewer-timer-value {
    font-size: 0.86rem;
  }
  .viewer-audio-hud {
    top: 8px;
    right: 8px;
    gap: 4px;
  }
  .viewer-audio-btn {
    padding: 4px 7px;
    font-size: 0.7rem;
  }
  .viewer-controls {
    bottom: 8px;
    width: calc(100% - 16px);
    padding: 6px 8px;
    gap: 6px;
  }
}

/* 배치 시뮬레이션 & 밸런스 보고서 카드 */
.batch-card {
  border-top: 3px solid #38bdf8;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.batch-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.batch-title {
  font-size: 0.98rem;
  font-weight: 700;
  color: #f8fafc;
}

.batch-desc {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 2px;
}

.batch-controls-grid {
  margin-bottom: 0;
}

.field input[type="number"] {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 0.85rem;
  font-family: inherit;
}

.field input[type="number"]:focus {
  outline: none;
  border-color: var(--primary);
}

.batch-progress {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}

.batch-progress-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.8rem;
  color: #cbd5e1;
  font-variant-numeric: tabular-nums;
}

.batch-output {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.batch-table-wrap {
  border: 1px solid var(--border);
  border-radius: 8px;
}

.batch-md-preview {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
}

.batch-md-preview summary {
  cursor: pointer;
  font-size: 0.84rem;
  font-weight: 600;
  color: #7dd3fc;
}

.batch-md-pre {
  margin-top: 10px;
  padding: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  max-height: 360px;
  overflow: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.76rem;
  line-height: 1.45;
  color: #e2e8f0;
  white-space: pre-wrap;
  word-break: break-word;
}

/* 광폭화(서든데스) HUD 배지 */
.hud-frenzy-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 11px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 800;
  color: #fef08a;
  background: linear-gradient(135deg, rgba(220, 38, 38, 0.92), rgba(234, 88, 12, 0.92));
  border: 1px solid rgba(253, 224, 71, 0.75);
  box-shadow: 0 0 12px rgba(239, 68, 68, 0.55);
  white-space: nowrap;
  cursor: help;
}

.hud-frenzy-badge.is-pulse {
  animation: frenzyBadgePulse 0.65s ease-out;
}

@keyframes frenzyBadgePulse {
  0% { transform: scale(1.22); box-shadow: 0 0 22px rgba(251, 146, 60, 0.95); }
  100% { transform: scale(1); box-shadow: 0 0 12px rgba(239, 68, 68, 0.55); }
}

/* 전투 화면 하단 기타 기능 (디버그) */
.viewer-misc-tools {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 14px;
}

.misc-tools-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}

.misc-tools-title {
  font-size: 0.84rem;
  font-weight: 700;
  color: #cbd5e1;
}

.misc-tools-status {
  font-size: 0.78rem;
  color: #38bdf8;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.misc-tools-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
}

.misc-tools-row button {
  padding: 6px 11px;
  font-size: 0.8rem;
}

.misc-tools-select-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 600;
}

.misc-tools-select-label select {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 0.8rem;
  font-family: inherit;
}

/* 스마트 카메라 테두리, 상태 배지, 토글 버튼 및 단축키 키캡 */
.viewer-smart-cam-frame {
  position: absolute;
  inset: 0;
  z-index: 8;
  pointer-events: none;
  border: 2px solid rgba(56, 189, 248, 0.72);
  border-radius: 8px;
  box-shadow: inset 0 0 18px rgba(56, 189, 248, 0.22);
}

.viewer-smart-cam-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 11px;
  border-radius: 999px;
  font-size: 0.73rem;
  font-weight: 700;
  color: #bae6fd;
  background: rgba(11, 17, 32, 0.72);
  border: 1px solid rgba(56, 189, 248, 0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.28);
  white-space: nowrap;
}

.smart-cam-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
  border-color: var(--border);
  color: var(--muted);
}

.smart-cam-btn.active {
  background: rgba(14, 165, 233, 0.22);
  border-color: #38bdf8;
  color: #e0f2fe;
}

.keycap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  margin-left: 2px;
  border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.66rem;
  font-weight: 700;
  line-height: 1;
  color: rgba(241, 245, 249, 0.85);
  background: rgba(15, 23, 42, 0.55);
  border: 1px solid rgba(148, 163, 184, 0.45);
}

button.speed-btn.active .keycap {
  color: #0b1120;
  background: rgba(255, 255, 255, 0.35);
  border-color: rgba(11, 17, 32, 0.35);
}

button.primary .keycap {
  color: #ffffff;
  background: rgba(15, 23, 42, 0.35);
  border-color: rgba(255, 255, 255, 0.38);
}
