/* 우주 테마 공통 스타일 */
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: 'Apple SD Gothic Neo', 'Noto Sans KR', system-ui, sans-serif;
  color: #dce4f2; background: #020208; overflow: hidden;
}
body.page { overflow: auto; background: radial-gradient(ellipse at top, #0a1020, #020208); }

#scene { position: fixed; inset: 0; z-index: 0; }
.hidden { display: none !important; }
.dim { color: #8a94ab; }
.tiny { font-size: 12px; }
.warn { color: #e6b23c; }

/* 상단 바 */
#top-bar {
  position: relative; z-index: 2; display: flex; align-items: center; gap: 16px;
  padding: 10px 20px; background: rgba(4, 8, 18, 0.75); backdrop-filter: blur(6px);
}
#top-bar h1 { font-size: 20px; margin: 0; }
#top-bar nav { margin-left: auto; display: flex; gap: 10px; align-items: center; }
#top-bar a { color: #7fb4ff; text-decoration: none; }

/* 패널 — 모바일 등 뷰포트보다 길면 패널 내부에서 스크롤한다 (body 는 overflow hidden) */
.panel {
  position: relative; z-index: 2; margin: 3vh auto; padding: 24px;
  width: min(1060px, 94vw); background: rgba(6, 10, 24, 0.82);
  border: 1px solid #1c2a45; border-radius: 14px; backdrop-filter: blur(8px);
  max-height: calc(100vh - 110px);
  max-height: calc(100dvh - 110px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}
#join-panel { max-width: 460px; text-align: center; }
#ts-widget { display: flex; justify-content: center; margin: 10px 0; }
#ts-widget:empty { margin: 0; }
#join-msg { margin: 10px 0 4px; font-size: 14px; }
#join-msg.warn { color: #e6b23c; }
#lobby-panel { display: flex; gap: 28px; flex-wrap: wrap; }
#lobby-panel .col { flex: 1 1 280px; min-width: 260px; }

/* 패널 접기 — 계단 구경(특히 모바일)을 위해 도전 버튼만 남긴다 */
#panel-toggle { position: absolute; top: 10px; right: 12px; z-index: 1; }
#lobby-panel.collapsed { width: min(420px, 94vw); padding: 14px 16px 12px; }
#lobby-panel.collapsed .col > * { display: none; }
#lobby-panel.collapsed .col > #btn-challenge { display: block; margin: 20px 0 0; }
#lobby-panel.collapsed .col:not(:first-of-type) { display: none; }
h2 { margin: 4px 0 10px; font-size: 17px; }
h3 { margin: 14px 0 6px; font-size: 14px; color: #9fb0cc; }

.row { display: flex; gap: 10px; margin: 12px 0; }
.row.center { justify-content: center; }
input {
  flex: 1; padding: 10px 12px; border-radius: 8px; border: 1px solid #2a3a5c;
  background: #0a1224; color: #e8eefb; font-size: 15px;
}
button {
  padding: 9px 14px; border-radius: 8px; border: 1px solid #2a3a5c;
  background: #14203a; color: #dce4f2; cursor: pointer; font-size: 14px;
}
button:hover:not(:disabled) { background: #1c2c4e; }
button:disabled { opacity: 0.45; cursor: default; }
button.primary { background: #2456c4; border-color: #2f66df; }
button.primary:hover:not(:disabled) { background: #2c63dd; }
button.mini { padding: 2px 8px; font-size: 12px; }
button.pulse { animation: pulse 1s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 12px #7fb4ff; } }
kbd {
  background: #0a1224; border: 1px solid #33456b; border-radius: 4px;
  padding: 1px 5px; font-size: 11px; margin-left: 4px;
}

/* 리스트 */
.list { list-style: none; margin: 0; padding: 0; }
.list li {
  display: flex; align-items: center; gap: 8px; padding: 8px 6px;
  border-bottom: 1px solid #131f36;
}
.list li button { margin-left: auto; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #3a4560; flex: none; }
.dot.on { background: #45d06a; box-shadow: 0 0 6px #45d06a; }
.commit { font-family: ui-monospace, monospace; font-size: 11px; color: #5f7ca8; }

/* 모달 */
.modal {
  position: fixed; inset: 0; z-index: 10; display: flex; align-items: center;
  justify-content: center; background: rgba(0, 0, 0, 0.6);
}
.modal-box {
  background: #0a1224; border: 1px solid #24365c; border-radius: 14px;
  padding: 26px 30px; width: min(480px, 92vw); text-align: center;
}
#seq-slots { display: flex; gap: 10px; justify-content: center; margin: 18px 0; }
.slot {
  width: 56px; height: 56px; border: 2px dashed #33456b; border-radius: 10px;
  display: flex; align-items: center; justify-content: center; font-size: 26px;
  color: #44506b;
}
.slot.filled { border-style: solid; border-color: #2f66df; background: #101c38; }

/* 매치 HUD */
#match-hud { position: fixed; inset: 0; z-index: 4; pointer-events: none; }
#match-hud button { pointer-events: auto; }
#vs-names {
  position: absolute; top: 18px; left: 0; right: 0; text-align: center;
  font-size: 15px; color: #9fb0cc; text-shadow: 0 1px 4px #000;
}
#round-ind {
  position: absolute; top: 44px; left: 0; right: 0; text-align: center;
  font-size: 22px; font-weight: 700; text-shadow: 0 1px 4px #000;
}
#score-pips {
  position: absolute; top: 78px; left: 0; right: 0; text-align: center;
  font-size: 16px; letter-spacing: 2px; text-shadow: 0 1px 4px #000;
}
/* 봇 성향 힌트 — 매치 중 항상 보이는 큰 배지 */
#hint-badge {
  position: absolute; top: 108px; left: 50%; transform: translateX(-50%);
  font-size: 20px; font-weight: 800; color: #ffd34d;
  background: rgba(8, 14, 30, 0.75); border: 1px solid rgba(255, 211, 77, 0.55);
  border-radius: 999px; padding: 8px 22px; white-space: nowrap;
  text-shadow: 0 1px 6px #000; box-shadow: 0 0 18px rgba(255, 211, 77, 0.25);
}
.hint-line { font-size: 16px; font-weight: 700; color: #ffd34d; }

#chant {
  position: absolute; top: 30%; left: 0; right: 0; text-align: center;
  font-size: clamp(48px, 10vw, 96px); font-weight: 900; color: #fff;
  text-shadow: 0 2px 18px rgba(80, 140, 255, 0.8);
}
#chant.pop { animation: pop 0.3s ease-out; }
@keyframes pop { 0% { transform: scale(1.7); opacity: 0.2; } 100% { transform: scale(1); opacity: 1; } }
#banner {
  position: absolute; top: 46%; left: 0; right: 0; text-align: center;
  font-size: 24px; font-weight: 700; white-space: pre-line;
  text-shadow: 0 1px 6px #000;
}
#banner.win { color: #6fe08a; }
#banner.lose { color: #ff7a5e; }
#banner.warn { color: #e6b23c; }
/* 실시간 대결: 상대가 손을 낸 순간 뜨는 배지 (무엇을 냈는지는 판정 전까지 비밀) */
#opp-played {
  position: absolute; bottom: 148px; left: 50%; transform: translateX(-50%);
  font-size: 15px; font-weight: 800; color: #7fb4ff; white-space: nowrap;
  background: rgba(8, 14, 30, 0.75); border: 1px solid rgba(127, 180, 255, 0.55);
  border-radius: 999px; padding: 5px 16px; text-shadow: 0 1px 6px #000;
}
#opp-played.pop { animation: pop 0.3s ease-out; }
#timer-wrap {
  position: absolute; bottom: 128px; left: 50%; transform: translateX(-50%);
  width: min(420px, 80vw); height: 10px; background: #101a30;
  border-radius: 6px; overflow: hidden; border: 1px solid #24365c;
}
#timer-bar { height: 100%; width: 100%; background: #5ad46f; }
#throw-row {
  position: absolute; bottom: 46px; left: 0; right: 0; display: flex;
  gap: 14px; justify-content: center;
}
#throw-row .throw-btn {
  font-size: 20px; padding: 14px 22px; opacity: 0.35; transition: opacity 0.15s;
}
#match-hud.input-on #throw-row .throw-btn { opacity: 1; }
.throw-btn.picked { outline: 3px solid #7fb4ff; }
#end-actions {
  position: absolute; bottom: 46px; left: 0; right: 0;
  display: flex; gap: 12px; justify-content: center;
}
#end-actions button { font-size: 17px; padding: 12px 26px; }

/* 관전 모드: 입력 UI 숨김 + 종료 버튼 */
#match-hud.spectate #throw-row, #match-hud.spectate #timer-wrap { display: none !important; }
#spec-exit { position: absolute; top: 14px; right: 16px; }

/* 계단 로비 */
button.big { font-size: 17px; padding: 13px 20px; width: 100%; margin: 8px 0; }
#my-pos { font-size: 18px; }
.target { line-height: 1.6; }
.step-no {
  display: inline-block; min-width: 30px; text-align: right; margin-right: 4px;
  font-family: ui-monospace, monospace; color: #7fb4ff; font-weight: 700; flex: none;
}
.list li.me-row { background: rgba(36, 86, 196, 0.18); border-radius: 6px; }
.gold { color: #f0cc40; font-size: 15px; margin-left: 10px; }

/* 터치 픽킹 팝업 */
#pick-pop {
  position: fixed; z-index: 6; max-width: 280px; line-height: 1.6;
  background: rgba(8, 14, 30, 0.95); border: 1px solid #2a3a5c; border-radius: 10px;
  padding: 12px 14px; font-size: 14px; box-shadow: 0 4px 18px rgba(0, 0, 0, 0.5);
}
#pick-pop button { margin-top: 8px; margin-right: 6px; }

/* 소품 터치 시 화면 구석에 뜨는 보유 골드 배지 */
#gold-badge {
  position: fixed; top: 64px; right: 16px; z-index: 6;
  background: rgba(8, 14, 30, 0.92); border: 1px solid rgba(240, 204, 64, 0.5);
  border-radius: 999px; padding: 8px 16px; font-size: 16px; font-weight: 800;
  color: #f0cc40; box-shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
}

/* 상점 */
.modal-box.wide { width: min(760px, 94vw); max-height: 86vh; overflow-y: auto; text-align: left; }
/* 상점 닫기 — 스크롤과 무관하게 항상 하단에 떠 있다 */
#shop-close-row {
  position: sticky; bottom: -26px; z-index: 1;
  margin: 8px -30px -26px; padding: 14px 0 18px;
  background: linear-gradient(to bottom, rgba(10, 18, 36, 0), rgba(10, 18, 36, 0.97) 45%);
}
#shop-close-row button { min-width: 160px; }
.shop-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.shop-card {
  border: 1px solid #24365c; border-radius: 10px; padding: 10px;
  display: flex; flex-direction: column; gap: 8px; align-items: flex-start;
  background: rgba(10, 18, 36, 0.8);
}
.shop-card.equipped { border-color: #2f66df; box-shadow: 0 0 8px rgba(47, 102, 223, 0.5); }
/* 미리보기 중인 카드 — .equipped 보다 뒤에 와야 테두리 색을 이긴다 */
.shop-card.previewing { border-color: #7fb4ff; box-shadow: 0 0 10px rgba(127, 180, 255, 0.5); }
.shop-card button { width: 100%; }
/* 비활성 버튼(골드 부족·장착중·배치됨)이 카드 클릭을 삼키지 않게 한다. disabled 버튼은
   클릭 이벤트를 아예 발생시키지 않아 버블링도 없다 → 그 자리를 누르면 미리보기가 안 떴다.
   골드가 모자란 물건일수록 미리 보고 싶은 법이라 특히 아팠다. */
.shop-card button:disabled { pointer-events: none; }

/* 상점 미리보기 — 카드를 누르면 그 물건을 3D 로 돌려 본다. 스크롤해도 위에 붙어 있다. */
/* 스티키라 카드가 이 밑으로 지나간다 — 배경이 반투명이면 라벨 위로 카드 글자가 비쳐
   읽을 수 없다. 불투명 배경 + 아래쪽 그림자로 경계만 부드럽게. */
#shop-preview {
  position: sticky; top: -26px; z-index: 2; text-align: center;
  margin: 0 -30px 10px; padding: 10px 0 10px;
  background: #0a1224;
  box-shadow: 0 10px 12px -10px rgba(0, 0, 0, 0.85);
}
#shop-prev-canvas {
  width: min(280px, 74vw); height: 176px; display: block; margin: 0 auto;
  border: 1px solid #24365c; border-radius: 10px;
  background: radial-gradient(circle at 50% 38%, #16244a, #0b1226);
}
#shop-prev-label { margin-top: 6px; min-height: 1.2em; }
.shop-name { display: flex; align-items: center; gap: 6px; width: 100%; }
.rar { font-size: 11px; margin-left: auto; color: #8a94ab; }
.kind { font-size: 10px; color: #5f7ca8; border: 1px solid #24365c; border-radius: 4px; padding: 0 4px; }
.rar-rare .rar { color: #5aa0e8; }
.rar-epic .rar { color: #b06ae0; }
.rar-legendary .rar { color: #f0cc40; }
.chip {
  display: inline-block; width: 16px; height: 16px; border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.25); margin-right: 4px;
}
.list.hof { max-height: 50vh; overflow-y: auto; text-align: left; }

/* 게임 규칙 팝업 */
.modal-box.rules { width: min(640px, 94vw); max-height: 86vh; overflow-y: auto; text-align: left; }
.rules-body h3 { margin: 14px 0 4px; color: #7fb4ff; }
.rules-body p { margin: 4px 0 10px; line-height: 1.65; color: #c6d0e4; }

/* 정상 등극 — 명예의 전당 입성 */
.modal-box.summit {
  border-color: #d8b030;
  box-shadow: 0 0 40px rgba(216, 176, 48, 0.45), inset 0 0 24px rgba(216, 176, 48, 0.08);
}
.modal-box.summit h2 { color: #f0cc40; font-size: 24px; }
.summit-trophy { font-size: 64px; animation: summit-pop 1.2s ease-in-out infinite alternate; }
@keyframes summit-pop {
  0% { transform: scale(1) rotate(-4deg); text-shadow: 0 0 18px rgba(240, 204, 64, 0.6); }
  100% { transform: scale(1.15) rotate(4deg); text-shadow: 0 0 34px rgba(240, 204, 64, 0.95); }
}

/* 모바일: 상단바를 한 줄로 압축하고 패널 여유치를 그에 맞춘다 */
@media (max-width: 640px) {
  #top-bar { padding: 6px 10px; gap: 8px; }
  #top-bar h1 { font-size: 14px; white-space: nowrap; }
  #top-bar #who { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  #top-bar nav { gap: 6px; }
  #top-bar nav a { white-space: nowrap; font-size: 12px; }
  #top-bar nav button { padding: 5px 8px; font-size: 12px; white-space: nowrap; }
  .panel {
    margin: 8px auto; padding: 16px;
    max-height: calc(100vh - 76px);
    max-height: calc(100dvh - 76px);
  }
}

/* 토스트 */
#toast {
  position: fixed; bottom: 26px; left: 50%; transform: translate(-50%, 20px);
  z-index: 20; background: #16233f; border: 1px solid #2f4470; color: #e8eefb;
  padding: 11px 20px; border-radius: 10px; opacity: 0; transition: all 0.25s;
  pointer-events: none; max-width: 90vw; text-align: center;
}
#toast.on { opacity: 1; transform: translate(-50%, 0); }

/* 통계 페이지 */
.page main { position: relative; z-index: 2; width: min(960px, 94vw); margin: 0 auto 60px; }
.tabs { display: flex; gap: 8px; margin: 18px 0; flex-wrap: wrap; }
.tabs button.on { background: #2456c4; border-color: #2f66df; }
table { width: 100%; border-collapse: collapse; margin: 10px 0 26px; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid #131f36; }
th { color: #8a94ab; font-weight: 600; font-size: 13px; }
tr.me-row td { background: rgba(36, 86, 196, 0.18); }
.stat-grid { display: flex; gap: 14px; flex-wrap: wrap; margin: 10px 0 26px; }
.stat {
  flex: 1 1 130px; background: rgba(10, 18, 36, 0.8); border: 1px solid #1c2a45;
  border-radius: 10px; padding: 14px; text-align: center;
}
.stat b { display: block; font-size: 24px; margin-bottom: 4px; }
.stat span { font-size: 12px; color: #8a94ab; }
