:root {
  --bg: #16161A;
  --panel: #222228;
  --panel-light: #2A2A32;
  --border: #2E2E36;
  --text: #F5F5F7;
  --muted: #9494A0;
  --gold: #FFC700;
  --luck: #38bdf8;
  --fury: #FF5E1A;
  --kakao: #fee500;
}

* {
  box-sizing: border-box;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: radial-gradient(circle at top, rgba(255, 199, 0, 0.14) 0%, #16161A 65%);
  color: var(--text);
  font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, 'Malgun Gothic', sans-serif;
  overflow: hidden;
  display: flex;
  justify-content: center;
}

#app {
  width: 100%;
  max-width: 440px;
  height: 100dvh;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  position: relative;
  box-shadow: 0 0 40px rgba(0,0,0,0.8);
  border-left: 1px solid #1e293b;
  border-right: 1px solid #1e293b;
}

.hidden { display: none !important; }

/* 상단 HUD */
.hud-top {
  padding: 8px 10px 6px;
  background: linear-gradient(180deg, #0f172a 0%, #090d16 100%);
  border-bottom: 1px solid #1e293b;
  z-index: 5;
}

.hud-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}
.hud-row:last-child { margin-bottom: 0; }

.pill {
  background: var(--panel-light);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 6px;
}

.wave-pill { flex: 1; justify-content: space-between; color: #e2e8f0; }
.wave-pill .timer { color: var(--gold); font-variant-numeric: tabular-nums; }
.danger-pill.danger { background: #7f1d1d; border-color: #ef4444; animation: shake 0.4s infinite; }
.hp-pill { color: #fca5a5; }

.icon-btn {
  background: var(--panel-light);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}
.icon-btn.active { background: #2563eb; border-color: #60a5fa; }

.resource-row { justify-content: space-between; }
.res-box {
  background: #0f172a;
  border: 1px solid #1e293b;
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 13px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.res-box.gold { color: var(--gold); }
.res-box.luck { color: var(--luck); }
.res-box.power { color: #c084fc; }

.fury-wrap { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.fury-label { font-size: 10px; font-weight: 700; color: #fda4af; display: flex; justify-content: space-between; }
.fury-bar { height: 7px; background: #1e293b; border-radius: 99px; overflow: hidden; }
.fury-fill { height: 100%; width: 0%; background: linear-gradient(90deg, #f43f5e, #facc15); transition: width 0.2s; }

.boss-bar-wrap {
  margin-top: 4px;
  background: #450a0a;
  border: 1px solid #ef4444;
  border-radius: 8px;
  padding: 4px 8px;
}
.boss-name { font-size: 11px; font-weight: 800; color: #fecaca; margin-bottom: 3px; text-align: center; }
.boss-hp-bg { height: 8px; background: #1f2937; border-radius: 99px; overflow: hidden; }
.boss-hp-fill { height: 100%; width: 100%; background: linear-gradient(90deg, #ef4444, #f97316); transition: width 0.1s; }

/* 중앙 보드 캔버스 */
.board-stage {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: radial-gradient(circle at center, #111c33 0%, #090d16 75%);
}

#gameCanvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.banner-toast {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.94);
  border: 2px solid var(--gold);
  color: #fff;
  padding: 7px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
  box-shadow: 0 6px 24px rgba(0,0,0,0.6);
  z-index: 6;
  pointer-events: none;
}

.mythic-craft-btn {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(90deg, #e11d48, #9333ea);
  color: #fff;
  border: 2px solid #fde047;
  padding: 8px 18px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 0 20px rgba(225, 29, 72, 0.7);
  animation: pulseBtn 1s infinite;
  z-index: 6;
}

/* 시너지 & 선택 유닛 정보 */
.info-strip {
  background: #0f172a;
  border-top: 1px solid #1e293b;
  padding: 6px 10px;
  min-height: 46px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
}

.enh-bar {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
}

.enh-btn {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 7px;
  padding: 4px 2px;
  color: #f8fafc;
  font-size: 10px;
  font-weight: 800;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.15;
  transition: transform 0.08s;
}
.enh-btn:active { transform: scale(0.94); }
.enh-btn.maxed { opacity: 0.7; border-color: #facc15; background: #422006; }
.enh-btn .enh-lvl { font-size: 10px; font-weight: 900; }
.enh-btn .enh-cost { font-size: 9px; color: #cbd5e1; }

.synergy-bar {
  display: flex;
  gap: 5px;
  overflow-x: auto;
  scrollbar-width: none;
}
.syn-chip {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 6px;
  background: #1e293b;
  color: var(--muted);
  white-space: nowrap;
}
.syn-chip.active { background: #312e81; color: #c4b5fd; border: 1px solid #8b5cf6; }

.unit-detail {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #1e293b;
  padding: 5px 8px;
  border-radius: 8px;
}
.ud-left { display: flex; align-items: center; gap: 8px; }
.ud-emoji { font-size: 22px; }
.ud-name { font-size: 12px; font-weight: 800; }
.ud-desc { font-size: 10px; color: var(--muted); }
.sell-btn {
  background: #991b1b;
  color: #fecaca;
  border: 1px solid #ef4444;
  border-radius: 6px;
  padding: 5px 9px;
  font-size: 11px;
  font-weight: 800;
  cursor: pointer;
}

/* 하단 컨트롤 */
.controls-bottom {
  display: grid;
  grid-template-columns: 1fr 1fr 78px;
  gap: 8px;
  padding: 8px 10px 12px;
  background: #0b1120;
  border-top: 1px solid #1e293b;
}

.gacha-btn {
  border: none;
  border-radius: 14px;
  padding: 10px 8px;
  color: #fff;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: transform 0.08s;
}
.gacha-btn:active { transform: scale(0.95); }

.gacha-btn.normal {
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  box-shadow: 0 4px 0 #1e3a8a;
}
.gacha-btn.gamble {
  background: linear-gradient(135deg, #9333ea, #e11d48);
  box-shadow: 0 4px 0 #881337;
}
.gacha-btn.gamble.awakened {
  background: linear-gradient(135deg, #f59e0b, #ef4444);
  animation: pulseBtn 0.8s infinite;
}

.gb-title { font-size: 14px; font-weight: 900; }
.gb-cost { font-size: 11px; opacity: 0.9; margin-top: 2px; font-weight: 700; }

.sub-btn-col {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.sub-btn {
  flex: 1;
  background: var(--panel-light);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  font-size: 11px;
  font-weight: 800;
  cursor: pointer;
  padding: 4px;
}
.sub-btn.merge-sub {
  background: linear-gradient(135deg, #0ea5e9, #2563eb);
  border-color: #60a5fa;
  color: #fff;
}
.sub-btn.merge-sub:active { transform: scale(0.95); }

/* 모달 공통 */
.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(2, 6, 23, 0.86);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 20;
}

.modal-card {
  width: 100%;
  max-height: 90dvh;
  overflow-y: auto;
  background: #111827;
  border: 1px solid #334155;
  border-radius: 20px;
  padding: 20px 18px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.8);
}

.lobby-card { text-align: center; }
.badge-top {
  display: inline-block;
  background: #312e81;
  color: #c4b5fd;
  font-size: 11px;
  font-weight: 800;
  padding: 4px 12px;
  border-radius: 99px;
  margin-bottom: 8px;
}
.game-title { margin: 0; font-size: 28px; font-weight: 900; letter-spacing: -0.5px; }
.game-sub { margin: 6px 0 14px; font-size: 13px; color: var(--muted); }

.challenge-banner {
  background: linear-gradient(135deg, #7f1d1d, #450a0a);
  border: 1px solid #f87171;
  border-radius: 12px;
  padding: 10px;
  margin-bottom: 12px;
}
.cb-title { font-size: 13px; font-weight: 900; color: #fecaca; }
.cb-info { font-size: 12px; color: #fff; margin-top: 3px; }

.mutator-box {
  background: #1e293b;
  border: 1px solid #475569;
  border-radius: 12px;
  padding: 10px;
  margin-bottom: 14px;
}
.mut-tag { font-size: 10px; font-weight: 800; color: var(--gold); text-transform: uppercase; }
.mut-name { font-size: 14px; font-weight: 800; margin: 2px 0; }
.mut-desc { font-size: 12px; color: #cbd5e1; }

.nick-row input {
  width: 100%;
  padding: 11px 14px;
  border-radius: 12px;
  border: 1px solid #475569;
  background: #0f172a;
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  text-align: center;
  margin-bottom: 12px;
}

.primary-btn {
  width: 100%;
  padding: 13px;
  border: none;
  border-radius: 14px;
  background: linear-gradient(135deg, #3b82f6, #8b5cf6);
  color: #fff;
  font-size: 15px;
  font-weight: 900;
  cursor: pointer;
}
.primary-btn.pulse { animation: pulseBtn 1.5s infinite; }

.secondary-btn {
  width: 100%;
  padding: 11px;
  border-radius: 12px;
  background: #1e293b;
  border: 1px solid #475569;
  color: #fff;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
}
.lobby-actions { margin-top: 10px; }

.kakao-btn { background: var(--kakao); color: #191919; }
.sos-btn { background: linear-gradient(135deg, #ef4444, #f59e0b); margin-bottom: 8px; }
.text-btn {
  width: 100%;
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  margin-top: 10px;
  cursor: pointer;
}

.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.modal-header h2 { margin: 0; font-size: 18px; }
.close-btn { background: #1e293b; border: none; color: #fff; width: 28px; height: 28px; border-radius: 8px; cursor: pointer; }
.modal-tip { font-size: 12px; color: var(--muted); margin: 0 0 12px; }

.recipe-list { display: flex; flex-direction: column; gap: 8px; }
.recipe-item {
  background: #1e293b;
  border-radius: 12px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  border: 1px solid #334155;
}
.recipe-item.ready { border-color: #fb7185; background: #3b0764; }
.rec-top { font-size: 13px; font-weight: 900; color: #fda4af; }
.rec-ing { font-size: 12px; color: #e2e8f0; }

.collection-bonus {
  background: linear-gradient(135deg, #312e81, #1e1b4b);
  border: 1px solid #818cf8;
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 11px;
  font-weight: 800;
  color: #e0e7ff;
  text-align: center;
  margin-bottom: 10px;
}

.meta-pull-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.meta10-btn {
  background: linear-gradient(135deg, #f59e0b, #e11d48);
}

.meta-result {
  margin: 10px 0;
  padding: 10px;
  border-radius: 12px;
  background: #1e1b4b;
  border: 1px solid #818cf8;
  text-align: center;
  font-weight: 800;
  font-size: 12px;
}
.meta10-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 5px;
  margin-top: 6px;
}
.meta10-item {
  background: #0f172a;
  border: 1px solid #475569;
  border-radius: 8px;
  padding: 5px 2px;
  font-size: 10px;
  line-height: 1.2;
}
.sub-heading { font-size: 13px; margin: 14px 0 8px; color: #cbd5e1; }
.relic-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.relic-card {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 10px;
  padding: 8px;
  font-size: 11px;
  opacity: 0.45;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.relic-card.owned { opacity: 1; border-color: var(--gold); background: #172554; }
.relic-card.maxed { border-color: #fb7185; background: #4c0519; }
.relic-lvl { font-size: 10px; font-weight: 900; color: #fde047; }

.receipt-wrap {
  background: #0f172a;
  border-radius: 12px;
  padding: 8px;
  margin: 10px 0;
  display: flex;
  justify-content: center;
}
#receiptCanvas {
  width: 100%;
  max-width: 260px;
  height: auto;
  border-radius: 6px;
}
.result-btns { display: flex; flex-direction: column; gap: 8px; }

.copy-toast {
  position: absolute;
  bottom: 84px;
  left: 50%;
  transform: translateX(-50%);
  background: #10b981;
  color: #022c22;
  font-weight: 900;
  font-size: 13px;
  padding: 8px 16px;
  border-radius: 99px;
  z-index: 50;
}

.portal-mini-btn {
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.portal-bridge {
  margin-top: 12px;
  padding: 10px;
  background: #0f172a;
  border: 1px solid rgba(250, 204, 21, 0.35);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.pb-title { font-size: 11px; font-weight: 900; color: var(--gold); text-align: center; }
.pb-links { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.pb-link {
  text-decoration: none;
  background: #1e293b;
  border: 1px solid #334155;
  color: #f8fafc;
  padding: 7px 6px;
  border-radius: 9px;
  font-size: 11px;
  font-weight: 800;
  text-align: center;
}
.pb-portal {
  text-decoration: none;
  background: var(--gold);
  color: #111827;
  padding: 8px;
  border-radius: 9px;
  font-size: 12px;
  font-weight: 900;
  text-align: center;
}

@keyframes pulseBtn {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.025); }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-2px); }
  75% { transform: translateX(2px); }
}
