:root {
  --bg: #0f1723;
  --panel: rgba(20, 30, 46, 0.92);
  --panel-border: #2c405c;
  --gold: #ffce3d;
  --coin: #ffce3d;
  --accent: #ff5fa2;
  --text: #eaf2ff;
  --muted: #8fa3c0;
  --green: #58d68d;
  --red: #ff6b6b;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  font-family: "Press Start 2P", monospace;
  color: var(--text);
  user-select: none;
  -webkit-user-select: none;
}

#game {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
}

/* ---- HUD ---- */
.hud {
  position: fixed;
  top: 0; left: 0; right: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 10px 12px;
  gap: 10px;
  pointer-events: none;
  z-index: 10;
  text-shadow: 2px 2px 0 #000;
}

.hud-left {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.hud-chip {
  background: rgba(10, 16, 26, 0.7);
  border: 2px solid var(--panel-border);
  border-radius: 8px;
  padding: 7px 9px;
  font-size: 10px;
  line-height: 1;
  display: flex;
  flex-direction: column;
  gap: 5px;
  backdrop-filter: blur(2px);
}
.chip-label { font-size: 7px; color: var(--muted); letter-spacing: 1px; }
.hud-chip.coins span:last-child { color: var(--coin); }
.hud-chip.world span:last-child { color: var(--accent); }
.hud-chip.eggs span:last-child { color: var(--green); }
.hud-chip.pkmn span:last-child { color: #7fd3ff; }
.hud-active { display: flex; align-items: center; gap: 6px; }
.hud-active .mon-orb { width: 20px; height: 20px; }
.hud-active #hudActiveName { font-size: 8px; max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hud-mon { display: inline-flex; border: 2px solid var(--panel-border); border-radius: 6px; padding: 2px; background: rgba(30,44,66,0.7); cursor: pointer; opacity: 0.55; }
.hud-mon.leader { opacity: 1; border-color: var(--accent); box-shadow: 0 0 6px rgba(74,222,128,0.6); }

.hud-right {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
  pointer-events: auto;
}

.hud-btn {
  font-family: inherit;
  font-size: 10px;
  color: var(--text);
  background: rgba(30, 44, 66, 0.9);
  border: 2px solid var(--panel-border);
  border-radius: 8px;
  padding: 12px 12px;
  cursor: pointer;
  transition: transform 0.06s, background 0.12s;
}
.hud-btn:hover { background: #3a5170; }
.hud-btn:active { transform: translateY(2px); }

/* ---- World progress bar ---- */
.wprog {
  position: fixed;
  top: 62px; left: 50%;
  transform: translateX(-50%);
  width: min(320px, 60vw);
  height: 18px;
  background: rgba(10,16,26,0.7);
  border: 2px solid var(--panel-border);
  border-radius: 12px;
  overflow: hidden;
  z-index: 12;
  text-shadow: none;
}
.wprog-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #58d68d, #7fd3ff);
  transition: width 0.3s;
}
.wprog-txt {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 8px; color: #fff;
  text-shadow: 1px 1px 0 #000;
}
.wprog.done .wprog-fill { background: linear-gradient(90deg, #ffce3d, #ff5fa2); }

/* ---- Toast ---- */.toast {
  position: fixed;
  top: 74px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  background: var(--panel);
  border: 2px solid var(--gold);
  border-radius: 10px;
  padding: 12px 18px;
  font-size: 10px;
  line-height: 1.6;
  text-align: center;
  box-shadow: 0 8px 30px rgba(0,0,0,0.5);
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
  max-width: 90vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(4px); }

/* ---- Hint ---- */
.hint {
  position: fixed;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  font-size: 8px;
  color: var(--muted);
  text-shadow: 2px 2px 0 #000;
  background: rgba(10,16,26,0.55);
  padding: 7px 12px;
  border-radius: 20px;
  white-space: nowrap;
}
.kbd {
  color: var(--text);
  background: rgba(255,255,255,0.1);
  border: 1px solid #46597a;
  border-radius: 4px;
  padding: 2px 5px;
}

/* ---- Overlay / Panels ---- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(6, 10, 16, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.overlay.hidden { display: none; }

.panel {
  width: min(620px, 96vw);
  max-height: 88vh;
  background: var(--panel);
  border: 3px solid var(--panel-border);
  border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  background: linear-gradient(#243a5a, #1b2b44);
  border-bottom: 2px solid var(--panel-border);
}
.panel-head h2 { font-size: 14px; color: var(--gold); letter-spacing: 1px; }
.close-btn {
  font-family: inherit;
  font-size: 18px;
  color: var(--text);
  background: transparent;
  border: none;
  cursor: pointer;
  line-height: 1;
}
.close-btn:hover { color: var(--accent); }
.panel-body {
  padding: 16px;
  overflow-y: auto;
  font-size: 9px;
  line-height: 1.7;
}

/* Egg grid */
.egg-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}
.egg-card {
  background: #16233a;
  border: 2px solid #2a3d5c;
  border-radius: 10px;
  padding: 12px;
  text-align: center;
  min-height: 120px;
}
.egg-card.locked { opacity: 0.5; }
.egg-card.openable { border-color: var(--green); cursor: pointer; }
.egg-card.openable:hover { background: #1c2e4b; }
.egg-num { font-size: 8px; color: var(--muted); margin-bottom: 8px; }
.egg-icon { font-size: 30px; line-height: 1.2; margin: 4px 0 8px; }
.egg-cost { font-size: 9px; color: var(--coin); margin-top: 6px; }
.egg-reveal { display: flex; justify-content: center; gap: 6px; margin-top: 8px; }
.pkmn-mini {
  font-size: 22px;
  background: #0d1726;
  border-radius: 8px;
  padding: 6px 5px;
  border: 2px solid #2a3d5c;
}
.pkmn-mini .nm { display:block; font-size: 6px; margin-top: 3px; color: var(--text); }
.locked-label { font-size: 8px; color: var(--muted); margin-top: 8px; }

/* World list */
.world-list { display: flex; flex-direction: column; gap: 10px; }
.world-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: #16233a;
  border: 2px solid #2a3d5c;
  border-radius: 10px;
  padding: 12px;
}
.world-row.locked { opacity: 0.6; }
.world-row.current { border-color: var(--accent); }
.world-row.completed { border-color: var(--green); }
.w-num {
  width: 42px; height: 42px;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; color: var(--gold);
  background: #0d1726; border-radius: 10px; flex-shrink: 0;
}
.w-info { flex: 1; }
.w-title { font-size: 10px; margin-bottom: 5px; }
.w-status { font-size: 8px; color: var(--muted); }
.w-btn {
  font-family: inherit;
  font-size: 8px;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  border: 2px solid transparent;
}
.w-btn.enter { background: #223a5e; color: var(--text); border-color: #3a5170; }
.w-btn.enter:hover { background: #2d4a77; }
.w-btn.unlock { background: #3a2a1a; color: var(--coin); border-color: var(--gold); }
.w-btn.unlock:hover { background: #4d3a22; }
.w-btn.lock { background: #2a2233; color: var(--muted); border: none; cursor: default; }

/* Team grid */
.team-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 10px;
}
.team-card {
  background: #16233a;
  border: 2px solid #2a3d5c;
  border-radius: 10px;
  padding: 10px;
  text-align: center;
}
.team-card { position: relative; cursor: pointer; }
.team-card.active { border-color: var(--gold); box-shadow: 0 0 8px rgba(245,179,1,0.35); }
.team-card.shiny { border-color: #fff59d; box-shadow: 0 0 10px rgba(255,245,157,0.55); }
.shiny-star { color: #ffd54f; }
.team-card .icon { font-size: 30px; }
.team-card .nm { font-size: 7px; margin-top: 6px; }
.team-card .rarity { font-size: 6px; margin-top: 4px; }
.team-card .dmg { font-size: 6px; margin-top: 3px; color: var(--coin); }
.team-card .active-tag { position: absolute; top: 4px; right: 6px; font-size: 8px; color: var(--gold); }
.team-actions { display: flex; align-items: center; justify-content: center; gap: 6px; margin-top: 8px; }
.lead-btn { font-size: 14px; color: #3a4a5c; cursor: pointer; }
.lead-btn.on { color: var(--gold); text-shadow: 0 0 6px rgba(245,179,1,0.7); }
.equip-btn { font-family: inherit; font-size: 8px; color: var(--text); background: #2a3d5c; border: 1px solid #3d557c; border-radius: 6px; padding: 4px 8px; cursor: pointer; }
.equip-btn:hover { background: #3a5170; }
.empty-msg { color: var(--muted); text-align: center; padding: 20px 0; }

/* Pokemon orb sprite */
.mon-orb {
  display: inline-block;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  vertical-align: middle;
  position: relative;
}
.mon-orb .eye {
  position: absolute;
  width: 4px; height: 5px;
  background: #0c1420;
  border-radius: 50%;
  top: 13px;
}
.mon-orb .eye.l { left: 10px; }
.mon-orb .eye.r { right: 10px; }
.mon-orb .shine { position: absolute; width: 6px; height: 4px; background: rgba(255,255,255,0.5); border-radius: 50%; top: 8px; left: 9px; transform: rotate(-20deg); }

/* Real pokemon sprite */
.mon-img {
  display: inline-block;
  width: 34px; height: 34px;
  object-fit: contain;
  image-rendering: pixelated;
  background: radial-gradient(circle at 35% 30%, rgba(255,255,255,0.25), rgba(0,0,0,0.25));
  border-radius: 10px;
}

/* Pokedex */
.dex-head { text-align: center; font-size: 9px; color: var(--muted); margin-bottom: 12px; }
.dex-tabs { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; margin-bottom: 14px; }
.dex-tab {
  font-family: inherit; font-size: 9px; padding: 8px 10px; border-radius: 8px;
  background: #16233a; border: 2px solid #2a3d5c; color: var(--text); cursor: pointer;
}
.dex-tab.on { background: #2d4a77; border-color: var(--accent); }
.dex-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(74px, 1fr)); gap: 8px; }
.dex-card { background: #131f33; border: 2px solid #232f45; border-radius: 8px; padding: 8px 4px; text-align: center; }
.dex-card.caught { border-color: var(--green); }
.dex-card .dn { font-size: 5px; color: var(--muted); }
.dex-card .dnm { font-size: 6px; margin-top: 4px; }
.dex-card.locked .dnm, .dex-card.locked .mon-img { opacity: 0.35; filter: grayscale(1); }

/* rarity */
.rarity.common { color: #9aa0a6; }
.rarity.rare { color: #4da6ff; }
.rarity.epic { color: #c77dff; }
.rarity.legendary { color: #f5b301; }
.rarity.mythic { color: #ff3b6b; }
.legend-bar { text-align: center; font-size: 7px; color: var(--muted); padding: 6px 0 12px; }
.legend-bar b { margin: 0 4px; }
.legend-bar b.common { color:#9aa0a6; } .legend-bar b.rare{color:#4da6ff;}
.legend-bar b.epic{color:#c77dff;} .legend-bar b.legendary{color:#f5b301;} .legend-bar b.mythic{color:#ff3b6b;}

/* ---- Battle bar ---- */
.battle {
  position: fixed;
  left: 50%; bottom: 64px;
  transform: translateX(-50%);
  width: min(560px, 94vw);
  background: var(--panel);
  border: 3px solid var(--accent);
  border-radius: 14px;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  z-index: 25;
  box-shadow: 0 12px 40px rgba(0,0,0,0.5);
}
.battle.hidden { display: none; }
.b-fighter { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.b-name { font-size: 8px; }
.b-sprite { font-size: 16px; }
.b-sprite .mon-img { width: 84px; height: 84px; }
.b-vs { font-size: 16px; color: var(--accent); text-shadow: 2px 2px 0 #000; }
.hpbar { width: 100%; height: 16px; background: #0a111c; border: 2px solid #2a3d5c; border-radius: 8px; overflow: hidden; }
.hpfill { height: 100%; width: 100%; background: linear-gradient(90deg, #58d68d, #8ce99a); transition: width 0.2s; }
.hpfill.opp { background: linear-gradient(90deg, #ff6b6b, #ff9b9b); }
.battle-status { position: absolute; bottom: 5px; left: 0; right: 0; text-align: center; font-size: 7px; color: var(--muted); }

/* ---- Chat ---- */
.chat {
  position: fixed;
  bottom: 0; left: 0;
  width: min(320px, 92vw);
  z-index: 22;
  display: flex;
  flex-direction: column;
  font-size: 8px;
}
.chat.hidden { display: none; }
#chatList {
  background: rgba(10,16,26,0.8);
  border: 2px solid var(--panel-border);
  border-bottom: none;
  border-radius: 10px 10px 0 0;
  max-height: 150px;
  overflow-y: auto;
  padding: 8px;
}
.chat-msg { margin-bottom: 4px; line-height: 1.5; word-break: break-word; }
.chat-msg b { color: var(--accent); }
.chat-msg .me { color: var(--gold); }
#chatInput {
  font-family: inherit; font-size: 9px;
  background: #0f1a2b; color: var(--text);
  border: 2px solid var(--panel-border);
  border-radius: 0 0 10px 10px;
  padding: 9px 10px;
  outline: none;
}
#chatInput:focus { border-color: var(--accent); }

/* ---- Save select ---- */
.panel-foot { padding: 12px 16px; border-top: 2px solid var(--panel-border); text-align: center; }

/* ---- Challenge ---- */
.small-panel {
  width: min(360px, 92vw);
  background: var(--panel); border: 3px solid var(--accent); border-radius: 14px; padding: 22px;
  display: flex; flex-direction: column; gap: 18px; align-items: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}
.challenge-text { font-size: 11px; line-height: 1.8; text-align: center; }
.challenge-btns { display: flex; gap: 12px; }
.hud-btn.ok { background: #2d7a4d; border-color: #58d68d; }
.hud-btn.no { background: #7a2d2d; border-color: #ff6b6b; }

/* ---- Style panel ---- */
.styles { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch {
  width: 30px; height: 30px; border-radius: 8px; cursor: pointer;
  border: 3px solid transparent;
}
.swatch.on { border-color: #fff; }
.style-sec { margin-bottom: 18px; }
.style-sec h3 { font-size: 8px; color: var(--muted); letter-spacing: 1px; margin-bottom: 10px; }

@media (max-width: 480px) {
  .hud-chip { padding: 6px 7px; }
  .hud-btn { padding: 10px 9px; font-size: 9px; }
  .egg-grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); }
  .battle { bottom: 6px; }
}

/* ---- Leaderboard ---- */
.lb-head { font-size: 8px; color: var(--muted); text-align: center; margin-bottom: 14px; }
.lb-list { display: flex; flex-direction: column; gap: 8px; }
.lb-row {
  display: flex; align-items: center; gap: 8px;
  background: #16233a; border: 2px solid #2a3d5c;
  border-radius: 10px; padding: 8px 10px;
}
.lb-row.me { border-color: var(--gold); }
.lb-rank { font-size: 12px; color: var(--gold); min-width: 20px; text-align: center; }
.lb-avatar { width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--panel-border); background: #0d1726; }
.lb-info { flex: 1; min-width: 0; }
.lb-name { font-size: 7px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lb-you { font-size: 6px; color: var(--accent); }
.lb-best { font-size: 6px; color: var(--muted); margin-top: 2px; }
.lb-stat { text-align: center; min-width: 44px; }
.lb-stat b { display: block; font-size: 12px; color: var(--text); }
.lb-stat span { font-size: 6px; color: var(--muted); }
.lb-stat:last-child b { color: var(--accent); }

/* ---- Rebirth ---- */
.rebirth-box {
  text-align: center; margin-top: 14px; padding: 14px;
  background: #1c1530; border: 2px solid #c77dff; border-radius: 12px;
}
.rebirth-box .rb-title { font-size: 11px; color: #c77dff; margin-bottom: 6px; }
.rebirth-box .rb-desc { font-size: 7px; color: var(--muted); margin-bottom: 10px; line-height: 1.6; }
.w-btn.rebirth { background: #c77dff; color: #0f1723; border-color: #d9a3ff; font-size: 9px; }
.w-btn.rebirth:hover { background: #d9a3ff; }
