/* 흡입 장갑 탐험 (가제) — 프로토타입 스타일. 폰 세로 화면 기준, PC에서도 동작 */
:root {
  --bg: #111827; --panel: #1f2937; --panel2: #273449; --text: #f3f4f6; --muted: #9ca3af;
  --primary: #2563eb; --test: #f59e0b; --danger: #dc2626; --nav-h: 58px;
  font-family: "Malgun Gothic", "Apple SD Gothic Neo", "Noto Sans KR", system-ui, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overflow: hidden; overscroll-behavior: none; }
body { height: 100dvh; }
h1 { font-size: 26px; margin: 0 0 4px; } h2 { font-size: 20px; margin: 0 0 8px; } h3 { margin: 0 0 6px; }
p { margin: 6px 0; line-height: 1.5; }
.small { font-size: 13px; } .muted { color: var(--muted); } .warn { color: #fcd34d; }
b { font-weight: 700; }

.screen { position: absolute; inset: 0; bottom: 0; display: flex; flex-direction: column; }
.screen[hidden] { display: none; }
[hidden] { display: none !important; } /* hidden 속성은 .btn 같은 display 규칙보다 항상 우선 (숨김 버튼이 그대로 보이던 문제 수정) */
.screen.center { align-items: center; justify-content: center; }
.screen.scroll { overflow-y: auto; -webkit-overflow-scrolling: touch; }
body:has(#nav:not([hidden])) .screen { bottom: var(--nav-h); }
.box { width: 100%; max-width: 560px; margin: 0 auto; padding: 18px 16px 28px; }
.center-col { display: flex; flex-direction: column; align-items: center; text-align: center; }

.btn { display: inline-block; font: inherit; font-size: 15px; font-weight: 700; padding: 10px 16px; border: 0; border-radius: 12px; background: #374151; color: #fff; cursor: pointer; margin: 4px 4px 4px 0; }
.btn.primary { background: var(--primary); } .btn.test { background: var(--test); color: #111; } .btn.danger { background: var(--danger); }
.btn.big { display: block; width: 100%; font-size: 18px; padding: 14px; margin: 10px 0; }
.btn.small { font-size: 13px; padding: 8px 12px; }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn-row { display: flex; flex-wrap: wrap; gap: 4px; margin: 6px 0; }
.tag { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 999px; background: #374151; color: #fff; margin-left: 4px; }
.tag.team-tag { background: var(--primary); }
.chip { display: inline-block; font-size: 13px; padding: 4px 10px; border-radius: 999px; background: var(--panel2); margin-right: 6px; }
.msg { background: #7f1d1d; border-radius: 12px; padding: 12px; margin: 10px 0; font-size: 14px; }
textarea { width: 100%; font: 12px monospace; background: #0b1220; color: #cbd5e1; border: 1px solid #374151; border-radius: 8px; padding: 6px; }
label { font-size: 14px; }
.set-group { background: var(--panel); border-radius: 12px; padding: 12px; margin: 10px 0; }

/* 시작 생명체 */
.starter-list { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0; }
.starter-card { background: var(--panel); border: 3px solid transparent; border-radius: 14px; padding: 8px 6px; text-align: center; cursor: pointer; }
.starter-card.picked { border-color: #60a5fa; background: var(--panel2); }
.starter-card canvas { width: 100%; max-width: 120px; aspect-ratio: 1; }
.starter-card .tag { margin: 2px; }
@media (max-width: 420px) { .starter-list { grid-template-columns: 1fr; } .starter-card { display: grid; grid-template-columns: 90px 1fr; text-align: left; gap: 4px 10px; align-items: center; } .starter-card canvas { grid-row: span 4; } }

/* 탐험 */
#explore-screen { background: #0b1220; }
#map { flex: 1; background: #0f172a; position: relative; z-index: 0; } /* z-index:0 → 지도 위에 버튼·조이스틱이 보이게 */
#explore-screen.test-mode #map { outline: 4px solid var(--test); outline-offset: -4px; }
#hud { background: rgba(17,24,39,0.95); padding: 6px 10px; z-index: 5; }
.hud-mode { font-weight: 700; font-size: 14px; padding: 4px 8px; border-radius: 8px; display: inline-block; }
.hud-mode.test { background: repeating-linear-gradient(45deg, #f59e0b 0 10px, #fbbf24 10px 20px); color: #111; }
.hud-mode.gps { background: #065f46; }
.hud-row { display: flex; gap: 8px; align-items: center; margin-top: 3px; flex-wrap: wrap; }
.hud-place { font-size: 13px; font-weight: 700; color: #111; padding: 2px 8px; border-radius: 999px; }
.map-btns { position: absolute; right: 10px; top: 110px; display: flex; flex-direction: column; gap: 6px; z-index: 6; }
.round { width: 44px; height: 44px; border-radius: 50%; border: 0; background: rgba(31,41,55,0.9); color: #fff; font-size: 20px; font-weight: 700; cursor: pointer; }
.round.on { background: var(--primary); } .round.wide { width: auto; padding: 0 14px; border-radius: 22px; font-size: 14px; }
#test-controls { position: absolute; left: 12px; bottom: 14px; z-index: 6; display: flex; align-items: flex-end; gap: 10px; }
#test-controls[hidden] { display: none; }
.test-note { position: absolute; left: 0; bottom: 118px; width: 70vw; color: #fde68a; text-shadow: 0 1px 2px #000; }
#joy, #bjoy { width: 110px; height: 110px; border-radius: 50%; background: rgba(255,255,255,0.18); border: 2px solid rgba(255,255,255,0.5); position: relative; touch-action: none; }
#joy-knob, #bjoy-knob { position: absolute; left: 50%; top: 50%; width: 50px; height: 50px; margin: -25px 0 0 -25px; border-radius: 50%; background: rgba(255,255,255,0.85); pointer-events: none; }
.player-marker .pm-dot { width: 16px; height: 16px; margin: 6px; border-radius: 50%; background: #2563eb; border: 3px solid #fff; box-shadow: 0 0 0 2px #2563eb; }
.player-marker .pm-ring { position: absolute; inset: 0; border-radius: 50%; border: 2px solid rgba(37,99,235,0.6); animation: ring 1.6s infinite; }
@keyframes ring { from { transform: scale(0.6); opacity: 1; } to { transform: scale(1.8); opacity: 0; } }
.spawn-marker .sp-wrap { text-align: center; animation: bob 1.4s ease-in-out infinite; filter: drop-shadow(0 2px 2px rgba(0,0,0,0.5)); }
.spawn-marker img { width: 48px; height: 48px; }
.spawn-marker .sp-name { font-size: 11px; font-weight: 700; color: #fff; background: rgba(17,24,39,0.8); border-radius: 6px; padding: 1px 4px; display: inline-block; }
.spawn-marker .sp-dist { font-size: 10px; color: #fde68a; text-shadow: 0 1px 2px #000; }
.spawn-marker.near img { outline: 3px solid #22c55e; outline-offset: -3px; border-radius: 50%; background: rgba(34,197,94,0.25); }
.spawn-marker.near .sp-dist { color: #86efac; }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }
.zone-label { font-size: 11px; font-weight: 700; color: #111; background: rgba(255,255,255,0.85); border-radius: 6px; text-align: center; line-height: 20px; white-space: nowrap; }
.leaflet-container { font-family: inherit; }

/* 포획 */
#capture-screen { background: #000; }
.capture-top { position: absolute; top: 0; left: 0; right: 0; padding: 10px 12px; background: linear-gradient(rgba(0,0,0,0.6), transparent); z-index: 2; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; pointer-events: none; }
.capture-top .btn { pointer-events: auto; margin-left: auto; }
.capture-title { font-size: 18px; font-weight: 700; }
#capture-canvas, #glove-canvas, #battle-canvas { width: 100%; height: 100%; display: block; touch-action: none; }
#capture-canvas { flex: 1; }
.overlay-box { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(90vw, 360px); background: var(--panel); border-radius: 16px; padding: 18px; text-align: center; z-index: 10; box-shadow: 0 10px 40px rgba(0,0,0,0.5); }
.overlay-box[hidden] { display: none; }

/* 장갑 세계 */
#glove-screen { background: #0b1220; }
#glove-canvas { flex: 1; min-height: 0; }
.panel { background: var(--panel); padding: 10px 12px; max-height: 46%; overflow-y: auto; border-top: 2px solid #374151; }
.food-bar { margin-bottom: 6px; }
.cre-head { display: flex; align-items: center; flex-wrap: wrap; gap: 2px; font-size: 16px; }
.bar-row { display: flex; align-items: center; gap: 8px; font-size: 13px; margin: 4px 0; }
.bar { flex: 1; height: 12px; background: #0b1220; border-radius: 6px; overflow: hidden; }
.bar .fill { height: 100%; background: #22c55e; transition: width 0.3s; }
.bar.enemy .fill { background: #ef4444; }
.evo-row { display: flex; align-items: center; gap: 10px; margin-top: 8px; background: var(--panel2); border-radius: 12px; padding: 8px; }
.evo-preview { width: 72px; height: 72px; flex: none; }

/* 팀 */
.cre-card { display: flex; align-items: center; gap: 10px; background: var(--panel); border-radius: 12px; padding: 8px; margin: 8px 0; border: 2px solid transparent; }
.cre-card.in-team { border-color: var(--primary); }
.cre-card canvas { width: 64px; height: 64px; flex: none; }
.cre-card-body { flex: 1; min-width: 0; }

/* 전투 */
#battle-screen { background: var(--bg); }
#battle-lobby { margin: auto; flex-shrink: 0; } /* 내용이 길면 상자 안이 아니라 전투 화면 전체가 스크롤됨 (아래 규칙). 마우스가 상자 옆 빈 곳에 있어도 휠이 먹도록 */
#battle-lobby[hidden] { display: none; } /* .center-col의 display:flex가 hidden을 덮어쓰지 않게 */
/* 대기 화면이 보일 때는 전투 화면 전체가 세로 스크롤 (전투 중에는 적용 안 됨). 스크롤 막대는 항상 보이게 → 아래에 더 있다는 걸 알 수 있게 */
#battle-screen:has(#battle-lobby:not([hidden])) { overflow-y: auto; -webkit-overflow-scrolling: touch; scrollbar-width: thin; scrollbar-color: #4b5563 #111827; }
#battle-screen::-webkit-scrollbar { width: 10px; }
#battle-screen::-webkit-scrollbar-track { background: #111827; }
#battle-screen::-webkit-scrollbar-thumb { background: #4b5563; border-radius: 5px; }
.team-preview { display: flex; gap: 10px; margin: 10px 0; }
.tp { text-align: center; } .tp canvas { width: 64px; height: 64px; }
#battle-play { position: absolute; inset: 0; display: flex; flex-direction: column; }
#battle-play[hidden] { display: none; }
.battle-hud { padding: 6px 10px; background: var(--panel); position: relative; }
.hp-line { display: flex; align-items: center; gap: 8px; margin: 3px 0; }
.hp-line .bar { height: 14px; }
#battle-quit { position: absolute; right: 8px; top: 6px; }
#battle-team-dots .dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; background: #4b5563; margin-left: 4px; border: 2px solid transparent; }
#battle-team-dots .dot.active { background: #22c55e; } #battle-team-dots .dot.dead { background: #7f1d1d; }
#battle-canvas { flex: 1; min-height: 0; }
.battle-controls { height: 150px; display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; background: var(--panel); }
.bb-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.bb { width: 72px; height: 56px; border-radius: 14px; border: 0; background: #374151; color: #fff; font: inherit; font-weight: 700; font-size: 14px; position: relative; touch-action: none; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.1; }
.bb.special { background: #7c3aed; }
.bb .lab { font-size: 12px; } .bb .cdt { font-size: 11px; color: #fde68a; min-height: 12px; }
.bb.cd { opacity: 0.55; }

/* 하단 탭 */
#nav { position: absolute; left: 0; right: 0; bottom: 0; height: var(--nav-h); display: flex; background: #0b1220; border-top: 1px solid #374151; z-index: 20; }
#nav[hidden] { display: none; }
#nav button { flex: 1; border: 0; background: transparent; color: var(--muted); font: inherit; font-size: 18px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; cursor: pointer; }
#nav button span { font-size: 11px; }
#nav button.active { color: #fff; background: var(--panel); }

/* 토스트 */
#toast { position: fixed; left: 50%; top: 12px; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 6px; pointer-events: none; width: min(92vw, 420px); }
.toast-item { background: rgba(17,24,39,0.95); color: #fff; padding: 10px 14px; border-radius: 10px; font-size: 14px; box-shadow: 0 4px 16px rgba(0,0,0,0.4); transition: opacity 0.3s; }
.toast-item.out { opacity: 0; }

/* 진화 진행도 */
.evo-box { background: var(--panel2); border-radius: 12px; padding: 8px; margin-top: 8px; }
.evo-row { align-items: flex-start; background: transparent; padding: 6px 0; }
.grow { flex: 1; min-width: 0; }
.req-list { margin: 4px 0; }
.req-row { display: flex; align-items: center; gap: 6px; }
.bar.tiny { height: 8px; max-width: 120px; }
.warn-tag { background: #b45309; }
.ok-tag { background: #166534; }
.warn { color: #fcd34d; }

/* 🧪 친구 팀 코드 대전 */
.friend-box { width: 100%; margin-top: 18px; padding-top: 14px; border-top: 1px dashed #374151; text-align: left; }
.friend-box h3 { margin: 0 0 6px; }
.friend-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 6px 0; }
.friend-input { font: inherit; font-size: 14px; padding: 6px 10px; border-radius: 8px; border: 1px solid #374151; background: #0b1220; color: #e5e7eb; width: 160px; }
.friend-code { font: 11px monospace; color: var(--muted); word-break: break-all; margin: 4px 0 8px; user-select: all; -webkit-user-select: all; }
.friend-code:empty { display: none; }
