@font-face {
  font-family: 'Galmuri11';
  src: url('./assets/fonts/Galmuri11.woff2') format('woff2');
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Galmuri11';
  src: url('./assets/fonts/Galmuri11-Bold.woff2') format('woff2');
  font-weight: bold;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg: #07080d;
  --card: #171b29;
  --border: #23283c;
  --accent: #ef4444;
  --gold: #facc15;
  --text: #f8fafc;
  --muted: #94a3b8;
  --font: "Galmuri11", monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
button { font-family: var(--font); }
[hidden] { display: none !important; }

html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font), -apple-system, sans-serif;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow: hidden;
  padding: 6px 8px;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* 상단 네비게이션 */
.top-nav {
  width: 100%;
  max-width: 1000px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  flex-shrink: 0;
}
.back-btn {
  color: #ef4444;
  text-decoration: none;
  font-weight: 700;
  font-size: 0.8rem;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border-radius: 8px;
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.25);
  white-space: nowrap;
}
.back-btn:hover { background: rgba(239, 68, 68, 0.25); }
.game-title {
  font-size: 1.05rem;
  font-weight: 800;
  background: linear-gradient(135deg, #ef4444, #f97316, #facc15);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.header-btn {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #e2e8f0;
  font-size: 0.75rem;
  padding: 5px 9px;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
}
.header-btn:hover { border-color: var(--gold); }

/* 게임 영역: 남는 화면을 모두 씀 */
.game-wrapper {
  position: relative;
  width: 100%;
  max-width: 1000px;
  flex: 1 1 auto;
  min-height: 0;
  max-height: 660px;
  background: #090b12;
  border: 2px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.8), 0 0 30px rgba(239, 68, 68, 0.12);
  touch-action: none;
}
#gameCanvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.controls-hint { margin-top: 6px; font-size: 11px; color: #64748b; flex-shrink: 0; text-align: center; }

/* HUD */
.hud { position: absolute; inset: 0; pointer-events: none; z-index: 10; padding: 8px 12px; }
.exp-bar-container {
  width: 100%; height: 8px;
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid rgba(56, 189, 248, 0.4);
  border-radius: 99px; overflow: hidden;
}
.exp-bar { height: 100%; width: 0; background: linear-gradient(90deg, #0284c7, #38bdf8); box-shadow: 0 0 10px #38bdf8; transition: width 0.12s; }
.hud-stats-row {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  margin-top: 5px; font-size: 13px; font-weight: 800;
  text-shadow: 0 2px 4px #000, 0 0 2px #000;
}
.hud-left, .hud-right { display: flex; align-items: center; gap: 8px; min-width: 0; }
.hud-level { color: #38bdf8; }
.hud-timer { color: #f8fafc; font-size: 15px; white-space: nowrap; }
.hud-kills { color: #fb7185; }
.hud-gold { color: var(--gold); }
.hud-hp { color: #4ade80; font-size: 11px; }
.player-hp-bar-box {
  width: 120px; height: 9px; display: inline-block;
  background: rgba(0, 0, 0, 0.7); border: 1px solid rgba(34, 197, 94, 0.5); border-radius: 99px; overflow: hidden;
}
.player-hp-bar { display: block; height: 100%; width: 100%; background: #22c55e; transition: width 0.1s; }
.player-hp-bar.low { background: #ef4444; animation: blink 0.6s infinite alternate; }
@keyframes blink { to { opacity: 0.55; } }

.slot-rows { margin-top: 6px; display: flex; flex-direction: column; gap: 3px; width: max-content; }
.slot-row { display: flex; gap: 3px; }
.slot {
  position: relative; width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center; font-size: 17px;
  background: rgba(17, 20, 34, 0.85); border: 1px solid rgba(255, 255, 255, 0.18); border-radius: 6px;
}
.slot.passive { width: 24px; height: 24px; font-size: 13px; }
.slot.empty { opacity: 0.35; border-style: dashed; }
.slot i { position: absolute; right: 1px; bottom: -1px; font-style: normal; font-size: 9px; color: #e2e8f0; text-shadow: 0 0 3px #000, 0 0 2px #000; }
.slot.evo { border-color: var(--gold); box-shadow: 0 0 8px rgba(250, 204, 21, 0.55); }
.slot.evo i { color: var(--gold); }

.boss-bar {
  position: absolute; left: 50%; top: 52px; transform: translateX(-50%);
  width: min(420px, 60%); text-align: center;
}
.boss-name { font-size: 12px; font-weight: 800; color: #fca5a5; text-shadow: 0 2px 4px #000; }
.boss-hp { height: 9px; margin-top: 3px; background: rgba(0, 0, 0, 0.75); border: 1px solid #ef4444; border-radius: 99px; overflow: hidden; }
.boss-hp i { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, #b91c1c, #ef4444); }

.hud-pause-btn {
  position: absolute; top: 48px; right: 10px; pointer-events: auto;
  width: 38px; height: 38px; font-size: 16px;
  background: rgba(17, 20, 34, 0.85); border: 1px solid rgba(255, 255, 255, 0.25); color: #fff;
  border-radius: 10px; cursor: pointer;
}

/* 조이스틱 */
.joystick-base {
  position: absolute; width: 100px; height: 100px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.07); border: 2px solid rgba(255, 255, 255, 0.22);
  pointer-events: none; display: none; z-index: 25; transform: translate(-50%, -50%);
}
.joystick-stick {
  position: absolute; width: 44px; height: 44px; border-radius: 50%; top: 50%; left: 50%;
  background: rgba(56, 189, 248, 0.6); box-shadow: 0 0 12px #38bdf8; transform: translate(-50%, -50%);
}

/* 모달 공통 */
.modal-overlay {
  position: absolute; inset: 0;
  background: rgba(7, 8, 13, 0.88);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 12px; z-index: 50;
  animation: fadeIn 0.16s ease-out;
}
@keyframes fadeIn { from { opacity: 0; transform: scale(0.98); } to { opacity: 1; transform: none; } }
.panel-box {
  width: 100%; max-width: 460px; max-height: 100%; overflow-y: auto;
  background: #111422; border: 2px solid var(--border); border-radius: 14px; padding: 18px;
  display: flex; flex-direction: column; gap: 10px;
}
.panel-title { font-size: 20px; font-weight: 900; color: var(--gold); }
.muted { color: var(--muted); font-size: 12px; line-height: 1.5; }
.center { text-align: center; padding: 12px; }
.btn-row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 4px; }
.ghost-btn {
  background: rgba(255, 255, 255, 0.07); border: 1px solid rgba(255, 255, 255, 0.2); color: #e2e8f0;
  padding: 11px 18px; border-radius: 99px; font-size: 13px; font-weight: 800; cursor: pointer;
}
.ghost-btn:hover { border-color: var(--gold); }
.text-btn { background: none; border: none; color: var(--muted); font-size: 11px; margin-top: 10px; cursor: pointer; text-decoration: underline; align-self: center; }

/* 로비 */
.lobby { padding: 10px; }
.lobby-container {
  display: flex; flex-direction: column; width: 100%; max-width: 820px; height: 100%; max-height: 100%;
  background: #0f121d; border: 2px solid var(--border); border-radius: 14px; padding: 12px 14px; gap: 10px;
}
.lobby-header { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.lobby-title { font-size: 18px; font-weight: 900; color: var(--gold); }
.lobby-gold-box {
  font-size: 14px; font-weight: 800; color: var(--gold); white-space: nowrap;
  background: rgba(250, 204, 21, 0.12); border: 1px solid rgba(250, 204, 21, 0.3); padding: 4px 12px; border-radius: 20px;
}
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); }
.tab {
  flex: 1; background: none; border: none; border-bottom: 3px solid transparent; color: var(--muted);
  padding: 7px 4px; font-size: 12px; font-weight: 800; cursor: pointer; white-space: nowrap;
}
.tab.on { color: #fff; border-bottom-color: var(--accent); }
.tab-panel { flex: 1 1 auto; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; padding-right: 2px; }
.lobby-col-title { font-size: 12px; font-weight: 800; color: var(--muted); margin-top: 4px; }
.lobby-footer { display: flex; justify-content: flex-end; }
.start-run-btn {
  background: linear-gradient(135deg, #ef4444, #dc2626); color: #fff; border: none;
  padding: 12px 32px; border-radius: 99px; font-size: 15px; font-weight: 900; cursor: pointer;
  box-shadow: 0 6px 20px rgba(239, 68, 68, 0.4);
}
.start-run-btn:hover { filter: brightness(1.12); }

.daily-card {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px;
  background: linear-gradient(135deg, rgba(168, 85, 247, 0.18), rgba(239, 68, 68, 0.14)); border: 1px solid rgba(192, 132, 252, 0.45);
}
.daily-left { flex: 1; min-width: 0; }
.daily-name { font-size: 14px; font-weight: 900; color: #e9d5ff; }
.daily-rule { font-size: 12px; color: #f8fafc; margin-top: 2px; }
.daily-best { font-size: 11px; color: var(--muted); margin-top: 2px; }
.daily-go { background: #a855f7; color: #fff; border: none; border-radius: 99px; padding: 9px 16px; font-weight: 900; font-size: 13px; cursor: pointer; white-space: nowrap; }
.done { color: var(--gold); font-size: 11px; }

.stage-list { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.stage-card, .char-card {
  text-align: left; color: inherit; background: var(--card); border: 2px solid #232a3d; border-radius: 10px;
  padding: 8px 10px; display: flex; align-items: center; gap: 8px; cursor: pointer;
}
.stage-card:hover, .char-card:hover { border-color: #38bdf8; }
.stage-card.selected, .char-card.selected { border-color: var(--gold); background: rgba(250, 204, 21, 0.09); }
.stage-card.locked, .char-card.locked { opacity: 0.6; border-style: dashed; }
.stage-icon, .char-icon { font-size: 24px; flex-shrink: 0; }
.stage-info, .char-info { flex: 1; min-width: 0; }
.stage-name, .char-name { font-size: 13px; font-weight: 800; color: #fff; }
.char-title { font-size: 10px; color: var(--muted); font-weight: normal; }
.stage-desc, .char-desc { font-size: 10px; color: var(--muted); line-height: 1.35; margin-top: 2px; }
.stage-meta { font-size: 10px; color: #38bdf8; margin-top: 2px; }
.char-list { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
.char-status { font-size: 10px; font-weight: 700; color: #38bdf8; margin-top: 3px; }

.shop-list { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
.shop-card { background: var(--card); border: 1px solid #232a3d; border-radius: 10px; padding: 8px 10px; display: flex; align-items: center; gap: 8px; }
.shop-icon { font-size: 20px; }
.shop-info { flex: 1; min-width: 0; }
.shop-name { font-size: 12px; font-weight: 800; color: #fff; }
.shop-lvl { font-size: 10px; color: #38bdf8; letter-spacing: -1px; }
.shop-desc { font-size: 10px; color: var(--muted); margin-top: 2px; }
.shop-buy-btn {
  background: linear-gradient(135deg, #eab308, #ca8a04); color: #000; font-weight: 900; border: none;
  padding: 8px 10px; border-radius: 8px; font-size: 11px; cursor: pointer; white-space: nowrap; min-width: 62px;
}
.shop-buy-btn.poor { filter: grayscale(0.7) brightness(0.8); }
.shop-buy-btn.maxed { background: #334155; color: var(--muted); cursor: default; }

.ach-summary { font-size: 12px; color: #e2e8f0; padding: 4px 2px; }
.ach-list { display: grid; grid-template-columns: repeat(2, 1fr); gap: 5px; }
.ach-card { display: flex; align-items: center; gap: 8px; background: var(--card); border: 1px solid #232a3d; border-radius: 8px; padding: 6px 8px; opacity: 0.6; }
.ach-card.on { opacity: 1; border-color: rgba(250, 204, 21, 0.5); }
.ach-icon { font-size: 18px; }
.ach-info { flex: 1; min-width: 0; }
.ach-name { font-size: 11px; font-weight: 800; }
.ach-desc { font-size: 10px; color: var(--muted); }
.ach-gold { font-size: 10px; color: var(--gold); white-space: nowrap; }

.help p { font-size: 12px; line-height: 1.6; color: #e2e8f0; }
.evo-help { font-size: 12px; line-height: 1.7; padding-left: 18px; color: #fde68a; }

/* 오늘의 사냥 안내 */
.daily-rule-big { font-size: 22px; font-weight: 900; color: #e9d5ff; }
.daily-grid { display: grid; gap: 4px; font-size: 13px; }
.daily-box p { font-size: 12px; line-height: 1.6; }

/* 레벨업 */
.level-up-title { font-size: 28px; font-weight: 900; color: var(--gold); text-shadow: 0 0 20px rgba(250, 204, 21, 0.6); }
.level-up-sub { font-size: 12px; color: var(--muted); margin: 2px 0 12px; }
.card-grid { display: flex; flex-direction: column; gap: 8px; max-width: 500px; width: 100%; }
.upgrade-card {
  position: relative; text-align: left; color: inherit;
  background: var(--card); border: 2px solid #2a3148; border-radius: 12px; padding: 10px 12px;
  display: flex; align-items: center; gap: 12px; cursor: pointer;
}
.upgrade-card:hover { border-color: var(--gold); background: #1e2438; }
.upgrade-card.new-card { border-color: #2563eb; }
.upgrade-card.evo-card { border-color: var(--gold); background: linear-gradient(135deg, rgba(234, 179, 8, 0.18), rgba(239, 68, 68, 0.15)); box-shadow: 0 0 15px rgba(250, 204, 21, 0.4); }
.upgrade-card.limit-card { border-color: #38bdf8; }
.upgrade-card kbd { position: absolute; top: 6px; right: 8px; font-family: var(--font); font-size: 10px; color: #64748b; }
.card-icon-box {
  width: 44px; height: 44px; flex-shrink: 0; background: #0f121d; border-radius: 10px;
  display: flex; align-items: center; justify-content: center; font-size: 24px; border: 1px solid rgba(255, 255, 255, 0.1);
}
.card-info { flex: 1; min-width: 0; }
.card-title { font-size: 14px; font-weight: 800; color: #fff; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding-right: 14px; }
.card-lvl-tag { font-size: 11px; color: #38bdf8; }
.evo-card .card-lvl-tag { color: var(--gold); }
.card-desc { font-size: 11px; color: var(--muted); margin-top: 3px; line-height: 1.4; }
.reroll-btn {
  margin-top: 12px; background: rgba(255, 255, 255, 0.08); border: 1px solid rgba(255, 255, 255, 0.2); color: #cbd5e1;
  padding: 9px 18px; border-radius: 20px; font-size: 12px; font-weight: 800; cursor: pointer;
}
.reroll-btn:disabled { opacity: 0.4; cursor: default; }

/* 보물 상자 */
.chest-box {
  max-width: 440px; width: 100%; max-height: 100%; overflow-y: auto; background: #111422; border: 2px solid #eab308; border-radius: 16px; padding: 20px;
  display: flex; flex-direction: column; align-items: center; gap: 12px; box-shadow: 0 0 35px rgba(234, 179, 8, 0.4);
}
.chest-title { font-size: 22px; font-weight: 900; color: var(--gold); text-shadow: 0 0 15px rgba(250, 204, 21, 0.6); text-align: center; }
.chest-rewards { display: flex; flex-direction: column; gap: 6px; width: 100%; }
.chest-item-card { background: var(--card); border: 1px solid rgba(255, 255, 255, 0.15); border-radius: 10px; padding: 8px 12px; display: flex; align-items: center; gap: 10px; animation: pop 0.35s backwards; }
.chest-item-card:nth-child(2) { animation-delay: 0.1s; }
.chest-item-card:nth-child(3) { animation-delay: 0.2s; }
.chest-item-card:nth-child(4) { animation-delay: 0.3s; }
.chest-item-card:nth-child(5) { animation-delay: 0.4s; }
.chest-item-card:nth-child(6) { animation-delay: 0.5s; }
@keyframes pop { from { opacity: 0; transform: scale(0.8); } }
.chest-item-card.gold { border-color: var(--gold); background: rgba(250, 204, 21, 0.1); }
.chest-item-card.evo { border-color: var(--gold); box-shadow: 0 0 12px rgba(250, 204, 21, 0.5); }
.chest-item-icon { font-size: 22px; }
.chest-item-name { font-size: 13px; font-weight: 800; flex: 1; }
.chest-item-tag { font-size: 11px; color: var(--gold); font-weight: 700; }
.chest-claim-btn {
  background: linear-gradient(135deg, #eab308, #ca8a04); color: #000; border: none; padding: 11px 40px;
  border-radius: 99px; font-size: 14px; font-weight: 900; cursor: pointer;
}

/* 일시정지 */
.dps-box { max-width: 480px; width: 100%; max-height: 100%; background: #111422; border: 2px solid var(--border); border-radius: 16px; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.dps-header { font-size: 16px; font-weight: 900; color: #38bdf8; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--border); padding-bottom: 8px; }
.dps-list { display: flex; flex-direction: column; gap: 6px; overflow-y: auto; min-height: 0; flex: 1 1 auto; }
.dps-row { background: var(--card); border-radius: 8px; padding: 7px 10px; display: flex; align-items: center; gap: 10px; }
.dps-icon { font-size: 20px; }
.dps-info { flex: 1; min-width: 0; }
.dps-title { font-size: 12px; font-weight: 800; display: flex; justify-content: space-between; gap: 6px; }
.dps-bar-box { height: 6px; background: rgba(0, 0, 0, 0.6); border-radius: 99px; overflow: hidden; margin: 4px 0; }
.dps-bar { height: 100%; background: linear-gradient(90deg, #0284c7, #38bdf8); }
.dps-sub { font-size: 10px; color: #64748b; }
.resume-btn { background: linear-gradient(135deg, #38bdf8, #0284c7); color: #fff; border: none; padding: 11px 24px; border-radius: 99px; font-weight: 800; font-size: 14px; cursor: pointer; }

/* 결과 */
.result-box { align-items: stretch; text-align: center; }
.screen-title {
  font-size: 34px; font-weight: 900;
  background: linear-gradient(135deg, #f43f5e, #f97316); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
.screen-title.victory { background: linear-gradient(135deg, #facc15, #22c55e); -webkit-background-clip: text; background-clip: text; }
.result-sub { font-size: 13px; color: #fde68a; line-height: 1.5; }
.screen-stats { display: flex; flex-direction: column; gap: 4px; font-size: 12px; text-align: left; background: #0c0f19; border-radius: 10px; padding: 10px 12px; }
.screen-stats div { display: flex; justify-content: space-between; gap: 10px; }
.screen-stats span { color: var(--muted); }
.screen-stats b { text-align: right; }
.screen-stats em { color: var(--gold); font-style: normal; }
.screen-stats .total { border-top: 1px solid var(--border); padding-top: 5px; margin-top: 2px; color: var(--gold); }
.result-ach { display: flex; flex-direction: column; gap: 4px; }
.ach-pop { font-size: 12px; color: var(--gold); background: rgba(250, 204, 21, 0.1); border: 1px solid rgba(250, 204, 21, 0.35); border-radius: 8px; padding: 5px 8px; }
.action-btn {
  background: linear-gradient(135deg, #ef4444, #dc2626); color: #fff; border: none; padding: 11px 28px; border-radius: 99px;
  font-size: 14px; font-weight: 800; cursor: pointer; box-shadow: 0 8px 24px rgba(239, 68, 68, 0.35);
}

.toast {
  position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%); z-index: 80;
  background: rgba(15, 23, 42, 0.95); border: 1px solid rgba(250, 204, 21, 0.45); color: #fff;
  padding: 8px 14px; border-radius: 99px; font-size: 12px; white-space: nowrap; pointer-events: none;
}

/* 좁은 화면 (휴대폰) */
@media (max-width: 640px) {
  body { padding: 4px; }
  .top-nav { margin-bottom: 4px; }
  .game-title { font-size: 0.9rem; }
  .game-wrapper { max-height: none; border-radius: 10px; }
  .controls-hint { display: none; }
  .hud { padding: 6px 8px; }
  .hud-stats-row { font-size: 11px; }
  .hud-timer { font-size: 13px; }
  .player-hp-bar-box { width: 64px; }
  .hud-hp { display: none; }
  .slot { width: 26px; height: 26px; font-size: 15px; }
  .slot.passive { width: 21px; height: 21px; font-size: 12px; }
  .boss-bar { top: 44px; width: 52%; }
  .hud-pause-btn { top: 40px; right: 6px; }
  .stage-list, .char-list, .shop-list, .ach-list { grid-template-columns: 1fr; }
  .lobby { padding: 6px; }
  .lobby-container { padding: 10px; }
  .lobby-title { font-size: 15px; }
  .tab { font-size: 11px; }
  .start-run-btn { width: 100%; }
  .level-up-title { font-size: 24px; }
  .upgrade-card { padding: 9px 10px; }
}
@media (max-height: 520px) {
  .controls-hint { display: none; }
  .level-up-title { font-size: 20px; }
  .level-up-sub { margin-bottom: 6px; }
  .card-grid { gap: 5px; }
  .upgrade-card { padding: 6px 10px; }
  .card-icon-box { width: 36px; height: 36px; font-size: 20px; }
}
