:root {
  --bg: #0b0e1a;
  --bg-2: #121734;
  --panel: rgba(22, 27, 54, 0.85);
  --stroke: #2a3160;
  --text: #e8ecff;
  --muted: #8b93c7;
  --primary: #6c5ce7;
  --primary-2: #a56bff;
  --accent: #00e5ff;
  --gold: #ffd54a;
  --danger: #ff4d6d;
  --win: #21e6a4;
  --left: #ff5b8a;
  --right: #45a6ff;
  --radius: 14px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
  /* 테마 가변 색 (다크 기본) */
  --bg-glow: #1a2050;
  --input-bg: #0e1230;
  --topbar-a: rgba(20, 25, 55, 0.95);
  --topbar-b: rgba(11, 14, 26, 0.7);
  --overlay: rgba(255, 255, 255, 0.06);
  --overlay-2: rgba(255, 255, 255, 0.05);
  --menu-bg: linear-gradient(180deg, #1a2048, #12162f);
}

/* 화이트(라이트) 모드 */
:root[data-theme="light"] {
  --bg: #eef1f8;
  --bg-2: #ffffff;
  --panel: rgba(255, 255, 255, 0.92);
  --stroke: #d5dbec;
  --text: #1a1f3d;
  --muted: #626c96;
  --primary: #6c5ce7;
  --primary-2: #8b5cf6;
  --accent: #0891b2;
  --shadow: 0 8px 30px rgba(30, 40, 80, 0.15);
  --bg-glow: #dbe4ff;
  --input-bg: #ffffff;
  --topbar-a: rgba(255, 255, 255, 0.96);
  --topbar-b: rgba(236, 240, 250, 0.88);
  --overlay: rgba(0, 0, 0, 0.05);
  --overlay-2: rgba(0, 0, 0, 0.04);
  --menu-bg: #ffffff;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: radial-gradient(1200px 800px at 70% -10%, var(--bg-glow) 0%, var(--bg) 55%);
  color: var(--text);
  transition: background .3s, color .3s;
  font-family: "Pretendard", system-ui, "Segoe UI", "Malgun Gothic", sans-serif;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
}
/* 세로 플렉스 — 상단바 높이가 (모바일에서 줄바꿈으로) 달라져도 본문이 남은 높이를 채운다.
   dvh: 모바일 브라우저 주소창이 접힐 때 생기는 잘림 방지 */
body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

/* ---------------------------------------------------------------- 상단바 */
.topbar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 12px 20px;
  background: linear-gradient(180deg, var(--topbar-a), var(--topbar-b));
  border-bottom: 1px solid var(--stroke);
  height: 62px;
  flex-shrink: 0;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand .logo { font-size: 26px; filter: drop-shadow(0 0 8px var(--accent)); }
.brand h1 {
  font-size: 20px; margin: 0; letter-spacing: 3px; font-weight: 800;
  background: linear-gradient(90deg, var(--accent), var(--primary-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.status { display: flex; align-items: center; gap: 12px; margin-left: 8px; }
.round-label { color: var(--muted); font-weight: 600; letter-spacing: 1px; }
.topbar-actions { margin-left: auto; display: flex; gap: 8px; }

.badge {
  padding: 4px 12px; border-radius: 999px; font-size: 12px; font-weight: 700;
  letter-spacing: 1px; border: 1px solid transparent;
}
.badge-setup { background: rgba(139, 147, 199, 0.15); color: var(--muted); border-color: var(--stroke); }
.badge-running { background: rgba(0, 229, 255, 0.12); color: var(--accent); border-color: rgba(0, 229, 255, 0.4); }
.badge-finished { background: rgba(255, 213, 74, 0.14); color: var(--gold); border-color: rgba(255, 213, 74, 0.5); }

/* ---------------------------------------------------------------- 레이아웃 */
.layout { display: flex; flex: 1; min-height: 0; }

.panel {
  width: 320px; flex-shrink: 0; padding: 18px; overflow-y: auto;
  background: var(--panel); border-right: 1px solid var(--stroke);
  backdrop-filter: blur(8px);
}
.panel.hidden { display: none; }
.panel-block { margin-bottom: 22px; }
.panel-block h2 {
  font-size: 13px; text-transform: uppercase; letter-spacing: 2px;
  color: var(--muted); margin: 0 0 10px;
}
.hint { font-size: 12px; color: var(--muted); margin: 0 0 8px; }
.hint-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.mini-actions { display: flex; gap: 6px; flex-shrink: 0; }
.btn-mini {
  border: 1px solid var(--stroke); background: var(--overlay-2); color: var(--muted);
  border-radius: 8px; padding: 4px 8px; font-size: 11px; font-weight: 700; cursor: pointer;
  font-family: inherit; white-space: nowrap; transition: border-color .15s, color .15s;
}
.btn-mini:hover { border-color: var(--primary-2); color: var(--text); }

/* 탭 (퀵 추가 / 대진 추가) */
.tabs { display: flex; gap: 4px; margin-bottom: 14px; background: var(--input-bg); padding: 4px; border-radius: 12px; border: 1px solid var(--stroke); }
.tab {
  flex: 1; border: none; background: transparent; color: var(--muted);
  padding: 9px 10px; border-radius: 9px; font-size: 13px; font-weight: 700;
  cursor: pointer; font-family: inherit; transition: background .15s, color .15s;
}
.tab:hover { color: var(--text); }
.tab.active { background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: #fff; box-shadow: 0 4px 14px rgba(108, 92, 231, 0.35); }
.tab-pane { display: none; }
.tab-pane.active { display: block; animation: fadeIn .18s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }

textarea, input[type="text"] {
  width: 100%; background: var(--input-bg); border: 1px solid var(--stroke);
  color: var(--text); border-radius: 10px; padding: 10px 12px; font-size: 14px;
  outline: none; transition: border-color .15s, box-shadow .15s;
  font-family: inherit;
}
textarea:focus, input:focus { border-color: var(--primary-2); box-shadow: 0 0 0 3px rgba(165, 107, 255, 0.2); }
textarea { resize: vertical; }

.row { display: flex; align-items: center; gap: 8px; }
.row .vs { color: var(--muted); font-weight: 700; font-size: 12px; }

/* 세로 스택 입력 (대상1 / VS / 대상2) */
.stack { display: flex; flex-direction: column; gap: 8px; }
.vs-divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: 1px; }
.vs-divider::before, .vs-divider::after { content: ""; flex: 1; height: 1px; background: var(--stroke); }
.mode-toggle { display: flex; gap: 16px; margin: 10px 0; font-size: 13px; color: var(--muted); }
.mode-toggle input { accent-color: var(--primary-2); }
.check-line { display: flex; align-items: center; gap: 7px; font-size: 13px; color: var(--muted); cursor: pointer; margin-bottom: 4px; }
.check-line input { accent-color: var(--primary-2); }

/* 경기 방식 선택 (선택박스) */
.format-select {
  width: 100%; background: var(--input-bg); border: 1px solid var(--stroke);
  color: var(--text); border-radius: 10px; padding: 10px 12px; font-size: 14px;
  font-family: inherit; cursor: pointer; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.format-select:focus { border-color: var(--primary-2); box-shadow: 0 0 0 3px rgba(165, 107, 255, 0.2); }
.format-select option { background: var(--input-bg); color: var(--text); }

.count-row { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
.count-row strong { color: var(--text); font-size: 18px; margin-right: 6px; }

/* ---------------------------------------------------------------- 버튼 */
.btn {
  border: none; border-radius: 10px; padding: 9px 14px; font-size: 13px; font-weight: 700;
  cursor: pointer; color: var(--text); transition: transform .08s, filter .15s, box-shadow .15s;
  font-family: inherit;
}
.btn:hover { filter: brightness(1.12); }
.btn:active { transform: translateY(1px); }
.btn.block { width: 100%; margin-top: 10px; }
.btn.big { padding: 14px; font-size: 15px; }
.btn-primary { background: linear-gradient(135deg, var(--primary), var(--primary-2)); box-shadow: 0 6px 18px rgba(108, 92, 231, 0.4); color: #fff; }
.btn-outline { background: transparent; border: 1px solid var(--stroke); color: var(--text); }
.btn-outline:hover { border-color: var(--primary-2); }
.btn-ghost { background: var(--overlay); }
.btn-danger { background: rgba(255, 77, 109, 0.15); color: var(--danger); border: 1px solid rgba(255, 77, 109, 0.4); }
.btn:disabled { opacity: .4; cursor: not-allowed; filter: none; }

/* ---------------------------------------------------------------- 스테이지 */
.stage { position: relative; flex: 1; min-width: 0; overflow: hidden; }
/* touch-action:none — 팬/핀치줌을 bracket.js가 직접 처리하므로 브라우저 기본 제스처를 끈다 */
#bracket-canvas { display: block; width: 100%; height: 100%; cursor: grab; touch-action: none; }
#bracket-canvas.dragging { cursor: grabbing; }

.stage-controls {
  position: absolute; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px;
}
.view-modes {
  position: absolute; left: 16px; top: 16px; display: flex; gap: 6px;
  background: var(--panel); padding: 5px; border-radius: 12px; border: 1px solid var(--stroke);
  backdrop-filter: blur(6px);
}
.ctrl.view { width: 38px; height: 34px; font-size: 17px; }
.ctrl.view.active {
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: #fff; border-color: transparent; box-shadow: 0 4px 14px rgba(108, 92, 231, 0.4);
}
.ctrl {
  width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--stroke);
  background: var(--panel); color: var(--text); font-size: 18px; cursor: pointer;
  backdrop-filter: blur(6px); transition: filter .15s, border-color .15s;
}
.ctrl:hover { border-color: var(--primary-2); filter: brightness(1.2); }

.empty-hint {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  text-align: center; color: var(--muted); font-size: 15px; line-height: 1.8; pointer-events: none;
}
.empty-hint.hidden { display: none; }

.champion-banner {
  position: absolute; top: 18px; left: 50%; transform: translateX(-50%);
  text-align: center; padding: 14px 44px; border-radius: 18px;
  background: linear-gradient(135deg, #1c2149, #241a3f);
  border: 1px solid rgba(255, 213, 74, 0.6); box-shadow: 0 0 44px rgba(255, 213, 74, 0.35);
  animation: pop .5s ease; z-index: 5;
}
.champion-banner.hidden { display: none; }
.champion-banner .crown { font-size: 40px; }
.champion-banner .champ-name { font-size: 26px; font-weight: 800; color: var(--gold); }
.champion-banner .champ-sub { font-size: 12px; letter-spacing: 4px; color: var(--muted); }

@keyframes pop { 0% { transform: translateX(-50%) scale(.6); opacity: 0; } 100% { transform: translateX(-50%) scale(1); opacity: 1; } }

/* ---------------------------------------------------------------- 경기 모달 */
.modal {
  position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center;
  background: rgba(5, 7, 16, 0.82); backdrop-filter: blur(6px);
}
.modal.hidden { display: none; }

.battle-arena {
  position: relative; width: min(960px, 94vw); padding: 34px;
  background: radial-gradient(600px 300px at 50% 0%, #23285a, #10132c);
  border: 1px solid var(--stroke); border-radius: 22px; box-shadow: var(--shadow);
  overflow: hidden;
}
.battle-round { text-align: center; color: var(--muted); letter-spacing: 3px; font-weight: 700; margin-bottom: 6px; }

/* 경기 방식 공통 상태 문구(READY/FIGHT!/K.O. 등) — 각 formats/*.js가 setStatus()로 갱신 */
.battle-status {
  text-align: center; min-height: 38px; margin-bottom: 14px; position: relative; z-index: 2;
  font-size: 28px; font-weight: 900; color: var(--gold); text-shadow: 0 0 16px rgba(255, 213, 74, 0.6);
}

/* 경기 방식별 무대 컨테이너 — 매 경기 시작 시 비워지고 formats/*.js가 내부 DOM을 그린다 */
.battle-stage { position: relative; z-index: 2; min-height: 240px; display: flex; align-items: center; justify-content: center; }

.fighters { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 18px; width: 100%; }
.fighters-vs { font-size: 22px; font-weight: 900; color: var(--muted); }
.fighter { text-align: center; }
.fighter .fighter-name { font-size: 22px; font-weight: 800; margin-bottom: 10px; }
.fighter.left .fighter-name { color: var(--left); }
.fighter.right .fighter-name { color: var(--right); }
.fighter .avatar { font-size: 78px; margin-top: 14px; transition: transform .12s; filter: drop-shadow(0 6px 14px rgba(0,0,0,0.5)); }
.fighter.left .avatar { transform: scaleX(1); }
.fighter.right .avatar { transform: scaleX(-1); }
.fighter.hit .avatar { animation: hitFlash .3s; }
.fighter.lunge.left .avatar { transform: translateX(60px) scale(1.15); }
.fighter.lunge.right .avatar { transform: translateX(-60px) scaleX(-1) scale(1.15); }
@keyframes hitFlash { 0%,100%{filter:drop-shadow(0 6px 14px rgba(0,0,0,0.5))} 40%{filter:brightness(3) drop-shadow(0 0 20px #fff)} }

.hpbar {
  position: relative; height: 22px; border-radius: 999px; background: #0c0f26;
  border: 1px solid var(--stroke); overflow: hidden;
}
.hpfill { position: absolute; inset: 0; height: 100%; width: 100%; border-radius: 999px; transition: width .12s ease; z-index: 2; }
.hpghost { position: absolute; inset: 0; height: 100%; width: 100%; border-radius: 999px; background: #fff; opacity: .85; transition: width .5s ease .18s; z-index: 1; }
.fighter.left .hpfill { background: linear-gradient(90deg, #ff2d6a, #ff8fae); }
.fighter.right .hpfill { background: linear-gradient(90deg, #2d7bff, #8fc4ff); }
.hptext { position: absolute; inset: 0; z-index: 3; font-size: 12px; font-weight: 800; display: flex; align-items: center; justify-content: center; text-shadow: 0 1px 3px #000; }

.battle-fx { position: absolute; inset: 0; pointer-events: none; z-index: 3; }
/* fx-popup: ctx.popup()으로 스폰되는 범용 텍스트 팝업 베이스 (formats/*.js 공용) */
.fx-popup { position: absolute; pointer-events: none; }
.dmg {
  position: absolute; font-weight: 900; font-size: 26px; pointer-events: none;
  animation: floatUp .8s ease-out forwards; text-shadow: 0 2px 6px #000;
}
.dmg.left { color: var(--left); }
.dmg.right { color: var(--right); }

.battle-actions { display: flex; justify-content: center; gap: 10px; margin-top: 26px; }

/* 크리티컬 데미지 강조 */
.dmg.crit { font-size: 40px; text-shadow: 0 0 18px currentColor, 0 2px 6px #000; }

/* 콤보 배지 */
.combo-badge {
  height: 20px; font-size: 14px; font-weight: 900; letter-spacing: 1px;
  color: var(--gold); text-shadow: 0 0 10px rgba(255,213,74,0.7); opacity: 0;
  transition: opacity .2s;
}
.combo-badge.show { opacity: 1; animation: comboPop .25s; }
@keyframes comboPop { 0%{transform:scale(.4)} 60%{transform:scale(1.4)} 100%{transform:scale(1)} }

/* 아레나 배경 글로우 (은은한 맥동) */
.arena-glow {
  position: absolute; inset: -40%; pointer-events: none; z-index: 0;
  background: radial-gradient(circle at 50% 40%, rgba(108,92,231,0.25), transparent 60%);
  animation: glowPulse 2.4s ease-in-out infinite alternate;
}
@keyframes glowPulse { from{opacity:.4} to{opacity:.9} }
.battle-round { position: relative; z-index: 2; }
.fighters { position: relative; z-index: 2; }
.battle-actions { position: relative; z-index: 5; }

/* 스피드라인 (타격 시 순간 표시) */
.speedlines {
  position: absolute; inset: 0; pointer-events: none; z-index: 0; opacity: 0;
  background: repeating-conic-gradient(from 0deg at 50% 50%,
    rgba(255,255,255,0.12) 0deg 2deg, transparent 2deg 8deg);
  mix-blend-mode: screen;
}
.speedlines.flash { animation: speedFlash .28s ease-out; }
@keyframes speedFlash { 0%{opacity:0; transform:scale(1.3)} 30%{opacity:.8} 100%{opacity:0; transform:scale(1)} }

/* 전체 화면 플래시 (크리티컬) */
.battle-flash {
  position: absolute; inset: 0; pointer-events: none; z-index: 4; opacity: 0;
  background: radial-gradient(circle, #fff, rgba(255,255,255,0.2));
}
.battle-flash.on { animation: flashHit .22s ease-out; }
@keyframes flashHit { 0%{opacity:.75} 100%{opacity:0} }

/* 타격 파티클 / 충격파 (JS가 스폰, Web Animations로 구동) */
.particle { position: absolute; border-radius: 50%; pointer-events: none; will-change: transform, opacity; }
.shockring {
  position: absolute; border: 3px solid #fff; border-radius: 50%;
  pointer-events: none; transform: translate(-50%, -50%);
}

/* 우승 연출 — 전체 화면을 가리지 않는 하단 배너 방식(경기 결과 화면이 계속 보여야 함) */
.victory-confetti { position: absolute; inset: 0; pointer-events: none; z-index: 5; overflow: hidden; }
.confetti { position: absolute; top: -20px; width: 10px; height: 14px; will-change: transform, opacity; }

.victory-overlay {
  position: absolute; left: 50%; bottom: 22px; transform: translateX(-50%);
  z-index: 6; display: flex; flex-direction: column; align-items: center; gap: 8px;
  background: rgba(6, 8, 20, 0.88); padding: 14px 36px 18px; border-radius: 18px;
  border: 1px solid var(--stroke); box-shadow: var(--shadow); animation: pop .4s ease;
}
.victory-overlay.hidden { display: none; }
.victory-text {
  font-size: 34px; font-weight: 900; letter-spacing: 4px;
  background: linear-gradient(90deg, var(--gold), var(--primary-2)); -webkit-background-clip: text; background-clip: text; color: transparent;
  animation: victoryIn .5s cubic-bezier(.2,1.4,.4,1), pulse 1s infinite alternate;
}
@keyframes victoryIn { 0%{transform:scale(0) rotate(-12deg); opacity:0} 70%{transform:scale(1.25) rotate(4deg)} 100%{transform:scale(1) rotate(0); opacity:1} }
.victory-name { font-size: 20px; font-weight: 800; }

/* ---------------------------------------------------------------- 경기 방식별 무대 (formats/*.js) */

/* 🎡 운명의 룰렛 */
.roulette-wrap { display: flex; flex-direction: column; align-items: center; gap: 16px; }
.roulette-pointer { font-size: 26px; color: var(--gold); text-shadow: 0 0 10px rgba(255,213,74,.7); margin-bottom: -6px; }
.roulette-wheel {
  /* background(조각별 색상)는 JS가 매 경기 시작 시 랜덤 분할해 인라인으로 채운다 */
  position: relative; overflow: hidden;
  width: 220px; height: 220px; border-radius: 50%;
  border: 6px solid rgba(255,255,255,.15);
  box-shadow: 0 0 40px rgba(108,92,231,.4), inset 0 0 30px rgba(0,0,0,.3);
}
/* 조각 경계선 — 각도 그라데이션 대신 중심~테두리 직선(스포크)으로 그려 굵기가 일정하다 */
.roulette-divider {
  position: absolute; left: 50%; top: 0; width: 2px; height: 50%;
  margin-left: -1px; background: rgba(10,12,26,.55); transform-origin: 50% 100%;
}
.roulette-legend { display: flex; gap: 24px; font-size: 14px; font-weight: 700; }
.roulette-legend .legend-item { display: flex; align-items: center; gap: 8px; }
.roulette-legend .dot { width: 12px; height: 12px; border-radius: 50%; }
.roulette-legend .left { color: var(--left); }
.roulette-legend .right { color: var(--right); }
.roulette-legend .left .dot { background: var(--left); }
.roulette-legend .right .dot { background: var(--right); }

/* 🃏 카드 드로우 대결 */
.carddraw-wrap { display: flex; align-items: center; justify-content: center; gap: 34px; }
.carddraw-name { font-size: 16px; font-weight: 800; }
.carddraw-name.left { color: var(--left); }
.carddraw-name.right { color: var(--right); }
.card { width: 110px; height: 154px; perspective: 700px; }
.card-inner { position: relative; width: 100%; height: 100%; transform-style: preserve-3d; transition: transform .5s cubic-bezier(.2,.8,.3,1); }
.card.flipped .card-inner { transform: rotateY(180deg); }
.card-face { position: absolute; inset: 0; backface-visibility: hidden; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-weight: 900; }
.card-back { background: linear-gradient(135deg, #2a3160, #151a3a); border: 2px solid var(--primary-2); font-size: 34px; color: var(--primary-2); }
.card-front { background: #f4f4fa; color: #111; font-size: 36px; transform: rotateY(180deg); }
.card.win .card-inner { animation: cardWin .5s ease; }
.card.lose { opacity: .45; filter: grayscale(.6); transition: opacity .3s, filter .3s; }

@keyframes cardWin { 0%,100%{transform:rotateY(180deg) scale(1)} 50%{transform:rotateY(180deg) scale(1.15)} }

@keyframes shake { 0%,100%{transform:translateX(0)} 20%{transform:translateX(-8px)} 40%{transform:translateX(8px)} 60%{transform:translateX(-6px)} 80%{transform:translateX(6px)} }
@keyframes floatUp { 0%{transform:translateY(0) scale(.6);opacity:0} 20%{opacity:1;transform:translateY(-10px) scale(1.2)} 100%{transform:translateY(-70px) scale(1);opacity:0} }
@keyframes pulse { from{filter:brightness(1)} to{filter:brightness(1.4)} }

/* ---------------------------------------------------------------- 카드별 경기 종류 선택 메뉴 */
.format-menu {
  position: fixed;
  z-index: 1000;
  min-width: 150px;
  padding: 6px;
  background: var(--menu-bg);
  border: 1px solid var(--stroke);
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.format-menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font: 600 13px/1 inherit;
  text-align: left;
  cursor: pointer;
}
.format-menu-item:hover { background: rgba(124, 140, 255, 0.16); }
.format-menu-item.active { background: rgba(108, 92, 231, 0.22); color: var(--primary-2); font-weight: 800; }
.format-menu-item .fm-icon { font-size: 15px; }
.format-menu-item .fm-name { flex: 1; }
.format-menu-item .fm-check { color: var(--accent); font-weight: 800; }

/* ---------------------------------------------------------------- 3D 배틀 (three.js) */
.tf3d { position: relative; width: 100%; height: 380px; }
.tf3d-canvas { position: absolute; inset: 0; width: 100% !important; height: 100% !important; display: block; }
.tf3d-hud {
  position: absolute; top: 10px; width: 40%; z-index: 4; pointer-events: none;
}
.tf3d-hud.left { left: 14px; text-align: left; }
.tf3d-hud.right { right: 14px; text-align: right; }
.tf3d-name { display: block; font-size: 18px; font-weight: 800; margin-bottom: 6px; text-shadow: 0 2px 8px rgba(0,0,0,.6); }
.tf3d-hud.left .tf3d-name { color: var(--left); }
.tf3d-hud.right .tf3d-name { color: var(--right); }
.tf3d-bar {
  height: 12px; border-radius: 7px; background: rgba(0,0,0,.45);
  border: 1px solid rgba(255,255,255,.15); overflow: hidden;
}
.tf3d-bar i {
  display: block; height: 100%; transition: width .28s cubic-bezier(.3,.8,.3,1);
}
.tf3d-hud.left .tf3d-bar i { background: linear-gradient(90deg, #ff2d6a, #ff8fae); box-shadow: 0 0 12px #ff5b8a; }
.tf3d-hud.right .tf3d-bar i { background: linear-gradient(270deg, #2d7bff, #8fc4ff); box-shadow: 0 0 12px #45a6ff; margin-left: auto; }

/* ---------------------------------------------------------------- 모바일 / 터치
   데스크톱에서는 아래 요소들이 모두 숨겨져 있고, 좁은 화면에서만 켜진다.
   - 구성 패널(사이드바) → 하단 시트 + 여는 버튼(.fab-panel)
   - 탭 지연/더블탭 확대 방지: touch-action: manipulation */
.btn, .ctrl, .tab, .btn-mini, .format-menu-item, .fab-panel {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.fab-panel, .panel-backdrop, .sheet-handle, .only-mobile { display: none; }

@media (max-width: 900px) {
  /* 상단바 — 2줄로 접기 (브랜드·상태 / 액션 버튼) */
  .topbar { flex-wrap: wrap; height: auto; gap: 8px; padding: 8px 12px; }
  .brand { gap: 7px; }
  .brand .logo { font-size: 20px; }
  .brand h1 { font-size: 15px; letter-spacing: 1.5px; }
  .status { margin-left: auto; gap: 8px; }
  .round-label { font-size: 12px; letter-spacing: 0; }
  .topbar-actions { margin-left: 0; width: 100%; flex-wrap: wrap; gap: 6px; }
  .topbar-actions .btn { flex: 1 1 auto; min-height: 42px; padding: 8px 6px; font-size: 11px; }
  #btn-theme { flex: 0 0 46px; }

  /* 구성 패널 → 아래에서 올라오는 시트 (캔버스 위에 겹침) */
  .panel {
    position: fixed; left: 0; right: 0; bottom: 0; width: 100%; z-index: 60;
    max-height: 78dvh;
    padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
    border-right: 0; border-top: 1px solid var(--stroke);
    border-radius: 18px 18px 0 0;
    box-shadow: 0 -14px 40px rgba(0, 0, 0, .38);
    transform: translateY(105%);
    transition: transform .28s cubic-bezier(.2, .8, .3, 1);
    overscroll-behavior: contain;
  }
  .panel.open { transform: none; }
  .sheet-handle {
    display: block; width: 44px; height: 5px; margin: 2px auto 14px;
    border-radius: 999px; background: var(--stroke);
  }
  .panel-backdrop {
    display: block; position: fixed; inset: 0; z-index: 55;
    background: rgba(5, 7, 16, .5);
    opacity: 0; pointer-events: none; transition: opacity .28s;
  }
  .panel-backdrop.open { opacity: 1; pointer-events: auto; }

  /* 시트를 여는 버튼 */
  .fab-panel {
    display: flex; align-items: center; gap: 6px; z-index: 20;
    position: absolute; left: 14px; bottom: calc(14px + env(safe-area-inset-bottom));
    padding: 13px 18px; border: none; border-radius: 999px;
    background: linear-gradient(135deg, var(--primary), var(--primary-2));
    color: #fff; font-family: inherit; font-size: 13px; font-weight: 800;
    box-shadow: 0 8px 22px rgba(108, 92, 231, .45); cursor: pointer;
  }

  /* 터치 목표 44px 확보 */
  .ctrl { width: 44px; height: 44px; }
  .ctrl.view { width: 44px; height: 40px; }
  .stage-controls { right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); }
  .view-modes { left: 12px; top: 12px; }
  .btn-mini { padding: 8px 10px; }
  .tab { padding: 11px 10px; }

  .only-mobile { display: block; }
  .only-desktop { display: none; }
  /* 하단 시트 버튼과 겹치지 않도록 안내 문구를 살짝 위로 */
  .empty-hint { padding: 0 24px 96px; font-size: 14px; }

  .champion-banner { top: 10px; max-width: 92%; padding: 10px 26px; }
  .champion-banner .crown { font-size: 30px; }
  .champion-banner .champ-name { font-size: 20px; }
  .champion-banner .champ-sub { font-size: 10px; letter-spacing: 3px; }

  /* 경기 모달 — 세로 공간이 좁으므로 연출 요소를 전반적으로 축소 */
  .battle-arena { width: 96vw; max-height: 94dvh; padding: 16px 12px; border-radius: 18px; }
  .battle-round { font-size: 12px; letter-spacing: 2px; }
  .battle-status { min-height: 28px; margin-bottom: 8px; font-size: 20px; }
  .battle-stage { min-height: 180px; }
  .battle-actions { margin-top: 16px; }
  .battle-actions .btn { min-height: 44px; padding: 11px 18px; }

  .fighters { gap: 8px; }
  .fighters-vs { font-size: 16px; }
  .fighter .fighter-name { font-size: 14px; margin-bottom: 6px; }
  .fighter .avatar { font-size: 52px; margin-top: 8px; }
  .fighter.lunge.left .avatar { transform: translateX(28px) scale(1.12); }
  .fighter.lunge.right .avatar { transform: translateX(-28px) scaleX(-1) scale(1.12); }
  .hpbar { height: 16px; }
  .hptext { font-size: 10px; }
  .dmg { font-size: 20px; }
  .dmg.crit { font-size: 30px; }

  .tf3d { height: 260px; }
  .tf3d-name { font-size: 14px; }
  .tf3d-hud.left { left: 10px; }
  .tf3d-hud.right { right: 10px; }

  .carddraw-wrap { gap: 14px; }
  .card { width: 84px; height: 118px; }
  .card-back { font-size: 26px; }
  .card-front { font-size: 28px; }
  .roulette-wheel { width: 170px; height: 170px; }
  .roulette-legend { gap: 16px; font-size: 13px; }

  .victory-overlay { bottom: 12px; padding: 10px 22px 14px; }
  .victory-text { font-size: 26px; letter-spacing: 2px; }
  .victory-name { font-size: 16px; }

  .format-menu-item { padding: 12px; font-size: 14px; }
}

/* 가로로 눕힌 폰 — 높이가 부족하므로 연출 무대를 더 낮춘다 */
@media (max-height: 520px) and (max-width: 950px) {
  .battle-arena { padding: 12px; }
  .battle-status { min-height: 24px; font-size: 18px; }
  .battle-stage { min-height: 130px; }
  .tf3d { height: 190px; }
  .fighter .avatar { font-size: 40px; }
  .roulette-wheel { width: 130px; height: 130px; }
  .card { width: 70px; height: 98px; }
  .battle-actions { margin-top: 10px; }
}
