* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  background: #0f1220;
  color: #e7e9f4;
  font-family: 'Segoe UI', 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
  display: flex;
  justify-content: center;
  min-height: 100vh;
  user-select: none;
}

#app { width: 100%; max-width: 400px; padding: 8px 10px 16px; }

/* ── 상단 HUD ── */
#topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  background: #181c30;
  border-radius: 10px;
  margin-bottom: 8px;
  font-size: .95rem;
}
#topbar .stat b { color: #ffd66b; }
#hud-mon-wrap.danger b { color: #ff5d5d; }
#btn-codex, #btn-pause, #btn-panic {
  border: 1px solid #343b63;
  border-radius: 8px;
  background: #232a4e;
  color: #e7e9f4;
  font-size: .95rem;
  padding: 3px 8px;
  cursor: pointer;
}

/* ── 일시정지 ── */
#pause-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 12, 24, .88);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
}
#pause-overlay.hidden { display: none; }
#pause-box { text-align: center; }
#pause-box h2 { font-size: 1.4rem; margin-bottom: 8px; }
#pause-box p { color: #8a90b4; font-size: .9rem; margin-bottom: 18px; }

/* ── 긴급 위장 (보스 키) ── */
#panic-overlay {
  position: fixed;
  inset: 0;
  background: #f3f4f6;
  z-index: 30;
  cursor: default;
}
#panic-overlay.hidden { display: none; }
#panic-doc {
  font-family: 'Malgun Gothic', sans-serif;
  color: #1f2937;
  height: 100%;
  display: flex;
  flex-direction: column;
}
.doc-title {
  background: #217346;
  color: #fff;
  padding: 10px 14px;
  font-size: .9rem;
  font-weight: 600;
}
#panic-doc table {
  border-collapse: collapse;
  width: 100%;
  background: #fff;
  font-size: .85rem;
}
#panic-doc th, #panic-doc td {
  border: 1px solid #d1d5db;
  padding: 7px 12px;
  text-align: left;
  min-width: 60px;
}
#panic-doc th { background: #e5e7eb; font-weight: 600; text-align: center; }
#panic-doc td:first-child { background: #e5e7eb; text-align: center; width: 34px; }
.doc-foot {
  margin-top: auto;
  background: #e5e7eb;
  color: #6b7280;
  font-size: .75rem;
  padding: 6px 12px;
  border-top: 1px solid #d1d5db;
}

/* ── 조합 도감 ── */
#codex-panel {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: 100%;
  max-width: 400px;
  background: #1d2238;
  border-radius: 16px 16px 0 0;
  padding: 12px 14px 20px;
  z-index: 10;
  box-shadow: 0 -6px 24px rgba(0, 0, 0, .5);
  max-height: 72vh;
  overflow-y: auto;
}
#codex-panel.hidden { display: none; }
.cx-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid #2a3050;
  font-size: .85rem;
}
.cx-row:last-child { border-bottom: none; }
.cx-name { font-weight: 800; }
.cx-mats { font-size: .76rem; color: #8a90b4; margin-top: 3px; line-height: 1.5; }
.cx-mats .ok { color: #2ecc71; font-weight: 700; }
.cx-mats .no { color: #ff5d5d; }
.cx-row button {
  border: none;
  border-radius: 8px;
  padding: 8px 13px;
  background: #2ecc71;
  color: #08210f;
  font-weight: 800;
  cursor: pointer;
  font-size: .82rem;
  flex-shrink: 0;
}
.cx-row button:disabled { background: #2a3050; color: #6b7194; }
.cx-tier { font-size: .78rem; font-weight: 800; margin: 10px 0 2px; }

/* ── 게임 캔버스 ── */
#stage { position: relative; }
canvas#game {
  display: block;
  width: 100%;
  background: #12162a;
  border-radius: 12px;
  touch-action: none;
}

/* ── 오버레이 ── */
#overlay {
  position: absolute;
  inset: 0;
  background: rgba(10, 12, 24, .82);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5;
}
#overlay.hidden { display: none; }
#overlay-box { text-align: center; padding: 20px; width: 100%; }
#ov-menu h1, #ov-title { font-size: 1.4rem; margin-bottom: 10px; }
.ov-sub, #ov-desc { font-size: .88rem; line-height: 1.55; color: #b9bed4; margin-bottom: 16px; }
.ov-sub b, #ov-desc b { color: #ffd66b; }
#ov-result.hidden, #ov-menu.hidden { display: none; }
.btn-big {
  font-size: 1.05rem;
  padding: 12px 36px;
  border: none;
  border-radius: 12px;
  background: linear-gradient(135deg, #6c5ce7, #a55eea);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}
#diff-btns { display: flex; flex-direction: column; gap: 8px; padding: 0 14px; }
.diff-btn {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 1px solid #343b63;
  border-radius: 12px;
  background: #1d2340;
  color: #e7e9f4;
  padding: 10px 14px;
  font-size: .95rem;
  cursor: pointer;
  text-align: left;
}
.diff-btn:active { background: #2a315c; }
.diff-btn .d-name { font-weight: 800; }
.diff-btn .d-desc { font-size: .72rem; color: #8a90b4; display: block; margin-top: 2px; }
.diff-btn .d-best { font-size: .72rem; color: #ffd66b; white-space: nowrap; }

/* ── 선택 정보 패널 ── */
#info-panel {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  background: #181c30;
  border-radius: 10px;
  padding: 8px 10px;
  margin-top: 8px;
  font-size: .88rem;
  min-height: 48px;
}
#info-panel.hidden { display: none; }
#info-text b { color: #ffd66b; }
#info-btns { display: flex; gap: 6px; flex-shrink: 0; }
#info-btns button {
  border: none;
  border-radius: 8px;
  padding: 8px 12px;
  font-weight: 700;
  cursor: pointer;
  font-size: .85rem;
}
#btn-merge { background: #2ecc71; color: #08210f; }
#btn-merge:disabled { background: #2a3050; color: #6b7194; }
#btn-sell { background: #3a4066; color: #e7e9f4; }

/* ── 하단 버튼 ── */
#controls { display: flex; gap: 8px; margin-top: 8px; }
#controls button {
  flex: 1;
  border: none;
  border-radius: 12px;
  padding: 13px 0;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  color: #fff;
}
#controls button { font-size: .84rem; padding: 11px 0; }
#btn-mission { background: #b3452f; }
#btn-mission span { display: block; font-size: .68rem; font-weight: 400; opacity: .9; }
#mission-panel {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: 100%;
  max-width: 400px;
  background: #1d2238;
  border-radius: 16px 16px 0 0;
  padding: 12px 14px 20px;
  z-index: 10;
  box-shadow: 0 -6px 24px rgba(0, 0, 0, .5);
}
#mission-panel.hidden { display: none; }
#btn-summon { background: linear-gradient(135deg, #e67e22, #f39c12); }
#btn-summon:disabled { background: #2a3050; color: #6b7194; }
#btn-summon span, #btn-gamble span { display: block; font-size: .7rem; font-weight: 400; opacity: .9; }
#btn-gamble { background: linear-gradient(135deg, #8e44ad, #c0398b); }
#btn-upgrade { background: #2f5fd0; }
#btn-speed { background: #3a4066; max-width: 64px; }

/* ── 도박소 패널 ── */
#gamble-panel {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: 100%;
  max-width: 400px;
  background: #1d2238;
  border-radius: 16px 16px 0 0;
  padding: 12px 14px 20px;
  z-index: 10;
  box-shadow: 0 -6px 24px rgba(0, 0, 0, .5);
  max-height: 70vh;
  overflow-y: auto;
}
#gamble-panel.hidden { display: none; }
.g-section { margin-bottom: 12px; }
.g-title { font-size: .82rem; font-weight: 700; color: #b9bed4; margin-bottom: 6px; }
.g-title small { font-weight: 400; color: #6b7194; }
.g-btns { display: flex; gap: 6px; }
.g-btns button {
  flex: 1;
  border: none;
  border-radius: 10px;
  padding: 9px 4px;
  background: #2f3560;
  color: #fff;
  font-weight: 700;
  font-size: .82rem;
  cursor: pointer;
}
.g-btns button small { display: block; font-weight: 400; font-size: .68rem; opacity: .8; margin-top: 2px; }
.g-btns button:disabled { background: #242946; color: #6b7194; }
.g-btns .g-money { background: #9e5f18; }
.g-btns .g-wood { background: #1f6e46; }
.g-btns .g-shop { background: #7d3fb0; }
.g-result { min-height: 20px; font-size: .85rem; font-weight: 700; text-align: center; margin-top: 8px; }
.g-gauge { height: 6px; background: #12162a; border-radius: 3px; overflow: hidden; margin-top: 6px; }
.g-gauge div { height: 100%; background: linear-gradient(90deg, #e67e22, #ffd66b); }

/* ── 강화 패널 ── */
#upgrade-panel {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: 100%;
  max-width: 400px;
  background: #1d2238;
  border-radius: 16px 16px 0 0;
  padding: 12px 14px 20px;
  z-index: 10;
  box-shadow: 0 -6px 24px rgba(0, 0, 0, .5);
}
#upgrade-panel.hidden { display: none; }
.up-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 700;
  margin-bottom: 10px;
}
#btn-up-close { background: none; border: none; color: #8a90b4; font-size: 1.1rem; cursor: pointer; }
.up-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 7px 0;
  border-bottom: 1px solid #2a3050;
  font-size: .9rem;
}
.up-row:last-child { border-bottom: none; }
.up-row button {
  border: none;
  border-radius: 8px;
  padding: 7px 14px;
  background: #2f5fd0;
  color: #fff;
  font-weight: 700;
  cursor: pointer;
  font-size: .85rem;
}
.up-row button:disabled { background: #2a3050; color: #6b7194; }

#hint { text-align: center; font-size: .75rem; color: #5d6284; margin-top: 8px; }
