* { margin: 0; padding: 0; box-sizing: border-box; }
:root { --gold: #ffd23c; --accent: #ff3ca6; --green: #7fe06a; }
html, body { height: 100%; }
body {
  background: #0a0612;
  color: #f3eefe;
  font-family: 'Trebuchet MS', system-ui, -apple-system, 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: 20;
  display: flex; align-items: center; gap: 10px; padding: 0 12px;
  background: linear-gradient(#160d28, #100a1e);
  border-bottom: 2px solid #2a1b44;
  font-size: 14px;
}
.topbar .back { color: #b9a6ff; text-decoration: none; font-weight: 700; }
.topbar .brand { font-weight: 800; letter-spacing: .5px; }
.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: #0a0612;
}
#game { display: block; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }

/* HUD */
#hud {
  position: absolute; top: 8px; left: 8px; right: 8px; z-index: 12;
  display: flex; align-items: center; gap: 8px; pointer-events: none;
  font-size: 12px; flex-wrap: wrap;
}
.hudChip {
  background: rgba(12, 8, 26, .7); border: 1px solid #2f2150; border-radius: 7px;
  padding: 3px 8px; font-weight: 700; white-space: nowrap;
}
.hudChip b { color: var(--gold); }
.gatebar {
  pointer-events: none; min-width: 120px; flex: 1 1 120px;
  background: rgba(12, 8, 26, .7); border: 1px solid #2f2150; border-radius: 7px;
  padding: 3px 8px; max-width: 240px;
}
.gatebar .lbl { font-size: 10px; color: #c9b8ff; display: flex; justify-content: space-between; }
.gatebar .track { margin-top: 2px; height: 7px; background: #2a1830; border-radius: 4px; overflow: hidden; }
.gatebar .track #gateFill { height: 100%; width: 100%; background: var(--green); transition: width .15s, background .2s; }

/* 오버레이 */
.overlay {
  position: absolute; inset: 0; z-index: 15;
  display: flex; align-items: center; justify-content: center;
  background: rgba(8, 4, 18, .82); backdrop-filter: blur(2px);
  padding: 16px;
}
.overlay.hidden { display: none; }
.panel {
  width: 100%; max-width: 440px; max-height: 100%; overflow-y: auto;
  background: linear-gradient(#1a1030, #120b22);
  border: 2px solid #3a2560; border-radius: 14px;
  padding: 22px 20px; text-align: center;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .5);
}
.panel h1 { font-size: 30px; letter-spacing: .5px; margin-bottom: 4px; text-shadow: 0 2px 0 #000; }
.panel h1 .em { font-size: 34px; }
.panel h2 { font-size: 22px; margin-bottom: 4px; }
.panel .sub { color: #b9a6ff; font-size: 13px; line-height: 1.6; margin: 8px 0 16px; }
.panel .ctrl { color: #8a7bb5; font-size: 12px; margin-top: 14px; line-height: 1.6; }
.panel .ctrl b { color: #d8c9ff; }

.btn {
  display: inline-block; cursor: pointer; border: none;
  font-family: inherit; font-weight: 800; font-size: 16px;
  color: #1a0d10; background: linear-gradient(#ffe06a, #ffc02c);
  padding: 12px 30px; border-radius: 10px;
  box-shadow: 0 4px 0 #b8851a; transition: transform .08s, box-shadow .08s;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #b8851a; }
.btn.alt { background: linear-gradient(#7a5cff, #5b34d6); color: #fff; box-shadow: 0 4px 0 #3a1f8a; }
.btn.alt:active { box-shadow: 0 1px 0 #3a1f8a; }

/* 상점 */
.shopTop { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.shopTop .goldTag { font-size: 15px; font-weight: 800; color: var(--gold); }
.shopTop .goldTag b { font-size: 18px; }
#shopGrid { display: grid; grid-template-columns: 1fr; gap: 8px; margin-bottom: 16px; }
@media (min-width: 380px) { #shopGrid { grid-template-columns: 1fr 1fr; } }
.shopItem {
  display: flex; align-items: center; gap: 8px; text-align: left;
  background: #20143c; border: 1px solid #3a2560; border-radius: 9px;
  padding: 8px 9px; cursor: pointer; font-family: inherit; color: inherit;
  transition: transform .08s, border-color .1s;
}
.shopItem:active { transform: scale(.97); }
.shopItem:hover { border-color: var(--gold); }
.shopItem.disabled { opacity: .45; cursor: not-allowed; }
.shopItem.maxed { opacity: .7; border-color: #4a8a4a; cursor: default; }
.shopItem .si-ic { font-size: 22px; width: 26px; text-align: center; flex-shrink: 0; }
.shopItem .si-body { flex: 1; min-width: 0; }
.shopItem .si-name { font-size: 13px; font-weight: 800; }
.shopItem .si-name .si-lv { font-size: 10px; color: #b9a6ff; font-weight: 600; }
.shopItem .si-desc { font-size: 11px; color: #a89bc8; line-height: 1.3; }
.shopItem .si-cost { font-size: 13px; font-weight: 800; color: var(--gold); flex-shrink: 0; }
.shopItem.maxed .si-cost { color: var(--green); }

.statline { font-size: 14px; color: #d8c9ff; margin: 6px 0; }
.statline b { color: var(--gold); font-size: 18px; }
.statgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 14px 0; }
.statgrid .cell { background: #20143c; border: 1px solid #3a2560; border-radius: 9px; padding: 10px; }
.statgrid .cell .k { font-size: 11px; color: #a89bc8; }
.statgrid .cell .v { font-size: 20px; font-weight: 800; color: #fff; }
.statgrid .cell .v.gold { color: var(--gold); }
