* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
  --gold: #ffd23c; --accent: #ff5b8a; --green: #7fe06a; --blue: #5aa9ff; --red: #ff6b6b;
  --panel: #161d2b; --panel2: #1f2738; --line: #34405a; --ink: #eef3fb; --sub: #9fb0cc;
}
html, body { height: 100%; }
body {
  background: #0c1018;
  color: var(--ink);
  font-family: 'Trebuchet MS', system-ui, -apple-system, 'Apple SD Gothic Neo', sans-serif;
  overflow: hidden;
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
}
img, canvas { image-rendering: pixelated; image-rendering: crisp-edges; }

.topbar {
  position: fixed; top: 0; left: 0; right: 0; height: 42px; z-index: 30;
  display: flex; align-items: center; gap: 10px; padding: 0 12px;
  background: linear-gradient(#141b29, #0e1420);
  border-bottom: 2px solid #26304a;
  font-size: 14px;
}
.topbar .back { color: #9bc2ff; text-decoration: none; font-weight: 700; }
.topbar .brand { font-weight: 800; letter-spacing: .4px; }
.topbar .hs { margin-left: auto; color: #9fb4d8; font-size: 12px; }
.topbar .hs b { color: var(--gold); }

#stage {
  position: fixed; top: 42px; left: 0; right: 0; bottom: 0;
  overflow: hidden;
  background: #0c1018;
}
#game { display: block; width: 100%; height: 100%; touch-action: none; cursor: pointer; }

/* 상단 HUD */
#hud {
  position: absolute; top: 8px; left: 8px; right: 8px; z-index: 12;
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; flex-wrap: wrap; pointer-events: none;
}
.hudChip {
  background: rgba(14, 20, 32, .78); border: 1px solid #2c3950; border-radius: 7px;
  padding: 3px 9px; font-weight: 700; white-space: nowrap;
}
.hudChip b { color: var(--gold); }
#phaseChip #phaseDot { color: var(--blue); }
#phaseChip.enemy #phaseDot { color: var(--red); }
#phaseChip.enemy b { color: var(--red); }
.ctlBtn {
  margin-left: auto; pointer-events: auto; cursor: pointer;
  background: linear-gradient(#3a78d6, #2a5bb0); color: #fff;
  border: 1px solid #5a8fe0; border-radius: 8px; font-family: inherit;
  font-weight: 800; font-size: 12px; padding: 5px 12px;
  box-shadow: 0 3px 0 #1b3c75; transition: transform .08s, box-shadow .08s, opacity .15s;
}
.ctlBtn:active { transform: translateY(2px); box-shadow: 0 1px 0 #1b3c75; }
.ctlBtn:disabled { opacity: .4; cursor: default; }

/* 하단 정보바 */
#infobar {
  position: absolute; left: 8px; right: 8px; bottom: 8px; z-index: 12;
  display: flex; gap: 8px; pointer-events: none; font-size: 12px;
}
.ibBlock {
  background: rgba(14, 20, 32, .82); border: 1px solid #2c3950; border-radius: 8px;
  padding: 6px 9px; line-height: 1.45; min-height: 26px;
}
#ibTerrain { flex: 0 0 auto; max-width: 38%; }
#ibUnit { flex: 1; min-width: 0; }
.ibBlock .nm { font-weight: 800; }
.ibBlock .tag { color: var(--sub); }
.ibBlock .stat { display: inline-block; margin-right: 7px; white-space: nowrap; }
.ibBlock .stat b { color: var(--gold); }
.ibBlock.empty { opacity: .55; }
.ibhp { display: inline-block; width: 54px; height: 7px; background: #2a3346; border-radius: 4px; overflow: hidden; vertical-align: middle; margin-right: 6px; }
.ibhp > i { display: block; height: 100%; background: var(--green); }

/* 떠다니는 행동 메뉴 */
#actionMenu {
  position: absolute; z-index: 18; display: flex; flex-direction: column; gap: 4px;
  background: rgba(16, 22, 36, .96); border: 1px solid #3a4970; border-radius: 10px;
  padding: 6px; box-shadow: 0 8px 24px rgba(0,0,0,.5);
}
#actionMenu.hidden { display: none; }
#actionMenu button {
  font-family: inherit; cursor: pointer; border: none; border-radius: 7px;
  padding: 9px 18px; font-size: 14px; font-weight: 800; color: #fff;
  background: #2a3654; min-width: 120px; text-align: left;
}
#actionMenu button .ic { margin-right: 7px; }
#actionMenu button.atk { background: linear-gradient(#d6483f, #b22f2a); }
#actionMenu button.heal { background: linear-gradient(#3fa85a, #2c8043); }
#actionMenu button.wait { background: #2a3654; }
#actionMenu button.cancel { background: #404a5e; color: #d6def0; }
#actionMenu button:active { transform: scale(.97); }

/* 전투 예측 팝업 */
#forecast {
  position: absolute; z-index: 19; width: 240px;
  background: rgba(14, 20, 34, .97); border: 1px solid #3a4970; border-radius: 12px;
  padding: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.55);
}
#forecast.hidden { display: none; }
#forecast .fcRow { display: flex; align-items: stretch; gap: 8px; }
#forecast .fcSide { flex: 1; min-width: 0; }
#forecast .fcSide .fcname { font-weight: 800; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#forecast .fcSide.atk .fcname { color: var(--blue); }
#forecast .fcSide.def .fcname { color: var(--red); }
#forecast .fcSide .big { font-size: 30px; font-weight: 900; letter-spacing: -1px; line-height: 1.05; }
#forecast .fcSide .big.dead { color: var(--red); }
#forecast .fcSide .ln { font-size: 11px; color: var(--sub); }
#forecast .fcSide .ln b { color: var(--ink); }
#forecast .fcVs { align-self: center; color: #6f7d9c; font-weight: 900; font-size: 12px; }
#forecast .fcBtns { display: flex; gap: 8px; margin-top: 10px; }
#forecast .fcBtns button { flex: 1; font-family: inherit; cursor: pointer; border: none; border-radius: 8px; padding: 9px 0; font-size: 14px; font-weight: 800; }
#forecast .fcBtns .go { background: linear-gradient(#d6483f, #b22f2a); color: #fff; box-shadow: 0 3px 0 #7a1f1b; }
#forecast .fcBtns .no { background: #38425a; color: #cdd6ea; }
#forecast .fcBtns button:active { transform: translateY(2px); }
#forecast .x2 { color: var(--gold); font-weight: 900; }

/* 토스트 */
#toast {
  position: absolute; top: 46%; left: 50%; transform: translate(-50%, -50%);
  z-index: 16; pointer-events: none;
  background: rgba(10, 14, 24, .82); border: 2px solid #3a4970; border-radius: 12px;
  padding: 14px 30px; font-size: 26px; font-weight: 900; letter-spacing: 1px;
  text-shadow: 0 2px 0 #000; transition: opacity .25s, transform .25s;
}
#toast.hidden { opacity: 0; transform: translate(-50%, -42%); }
#toast.enemy { border-color: #6e2a3a; color: #ffb3c2; }
#toast.ally { border-color: #2a4a6e; color: #b9d6ff; }

/* 오버레이 */
.overlay {
  position: absolute; inset: 0; z-index: 22;
  display: flex; align-items: center; justify-content: center;
  background: rgba(6, 10, 18, .84); backdrop-filter: blur(2px);
  padding: 16px;
}
.overlay.hidden { display: none; }
.panel {
  width: 100%; max-width: 460px; max-height: 100%; overflow-y: auto;
  background: linear-gradient(#18202f, #121826);
  border: 2px solid #344566; border-radius: 14px;
  padding: 22px 20px; text-align: center;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .55);
}
.panel h1 { font-size: 32px; letter-spacing: .5px; text-shadow: 0 2px 0 #000; }
.panel h1 .em { font-size: 34px; }
.panel h2 { font-size: 22px; margin-bottom: 4px; }
.panel .subt { color: var(--gold); font-weight: 800; font-size: 15px; letter-spacing: 3px; margin: 2px 0 6px; }
.panel .sub { color: var(--sub); font-size: 13px; line-height: 1.65; margin: 8px 0 16px; }
.panel .sub b { color: #d6e2ff; }
.panel .ctrl { color: #7e8db0; font-size: 12px; margin-top: 14px; line-height: 1.6; }
.panel .ctrl b { color: #c7d4ee; }

.btn {
  display: inline-block; cursor: pointer; border: none;
  font-family: inherit; font-weight: 800; font-size: 16px;
  color: #11161f; background: linear-gradient(#ffe06a, #ffc02c);
  padding: 12px 30px; border-radius: 10px; margin: 4px;
  box-shadow: 0 4px 0 #b8851a; transition: transform .08s, box-shadow .08s;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #b8851a; }
.btn.ghost { background: transparent; color: #b9c7e6; box-shadow: none; border: 1px solid #3a4970; font-size: 13px; padding: 9px 18px; }
.btn.ghost:active { transform: translateY(2px); }

/* 야영 보상 */
.shopTop { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.shopTop .goldTag { font-size: 14px; font-weight: 800; color: var(--gold); }
.shopTop .goldTag b { font-size: 18px; }
#rewardGrid { display: grid; grid-template-columns: 1fr; gap: 8px; margin: 6px 0 14px; }
@media (min-width: 400px) { #rewardGrid { grid-template-columns: 1fr 1fr 1fr; } }
.rwCard {
  text-align: left; background: #1e2942; border: 2px solid #344566; border-radius: 11px;
  padding: 11px 10px; cursor: pointer; font-family: inherit; color: inherit;
  transition: transform .08s, border-color .12s, background .12s;
  display: flex; flex-direction: column; gap: 3px;
}
.rwCard:hover { border-color: var(--gold); }
.rwCard:active { transform: scale(.97); }
.rwCard.sel { border-color: var(--gold); background: #2a3656; box-shadow: 0 0 0 2px rgba(255,210,60,.3) inset; }
.rwCard .ic { font-size: 24px; }
.rwCard .nm { font-size: 14px; font-weight: 800; }
.rwCard .ds { font-size: 11px; color: var(--sub); line-height: 1.35; }

.roster { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin: 4px 0 16px; }
.rUnit {
  background: #1a2335; border: 1px solid #2c3950; border-radius: 9px; padding: 6px 8px;
  font-size: 11px; min-width: 92px; text-align: left;
}
.rUnit .rn { font-weight: 800; font-size: 12px; }
.rUnit .rc { color: var(--sub); }
.rUnit .rhp { height: 6px; background: #2a3346; border-radius: 3px; overflow: hidden; margin-top: 3px; }
.rUnit .rhp > i { display: block; height: 100%; background: var(--green); }
.rUnit.dead { opacity: .4; }

.statgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 14px 0; }
.statgrid .cell { background: #1e2942; border: 1px solid #344566; border-radius: 9px; padding: 10px; }
.statgrid .cell .k { font-size: 11px; color: var(--sub); }
.statgrid .cell .v { font-size: 20px; font-weight: 800; color: #fff; }
.statgrid .cell .v.gold { color: var(--gold); }

/* 도감 */
.codex { text-align: left; font-size: 12.5px; line-height: 1.5; margin: 6px 0 14px; }
.codex h4 { font-size: 13px; color: var(--gold); margin: 12px 0 4px; }
.codex .cu { display: flex; gap: 8px; align-items: baseline; padding: 3px 0; border-bottom: 1px solid #232c40; }
.codex .cu .cn { font-weight: 800; min-width: 64px; }
.codex .cu .cd { color: var(--sub); flex: 1; }
.codex p { color: var(--sub); margin: 4px 0; }
.codex b { color: #d6e2ff; }
