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

html, body {
  height: 100%;
  background: #0E1513;
  font-family: 'Segoe UI', system-ui, sans-serif;
  color: #E4EAE6;
  overflow: hidden;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.screen { display: none; }
.screen.active { display: flex; }

#app {
  position: relative;
  max-width: 440px;
  height: 100%;
  margin: 0 auto;
  flex-direction: column;
  background: #1A2320;
  overflow: hidden;
}
#app.active { display: flex; }

/* ---------- Map screen ---------- */
#map-screen {
  position: relative;
  height: 100%;
  flex-direction: column;
}
#map { flex: 1; background: #DDE6DC; }
#profile-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: #1A2320;
  z-index: 500;
}
.pb-avatar { font-size: 24px; }
.pb-chip {
  background: #101815;
  border: 1px solid #2E3B36;
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 13px;
  font-weight: bold;
  white-space: nowrap;
}
.pb-xp {
  position: relative;
  flex: 1;
  height: 14px;
  background: #101815;
  border-radius: 7px;
  overflow: hidden;
}
#pb-xp-fill { height: 100%; background: #D99A2B; border-radius: 7px; transition: width 0.4s; }
#pb-xp-text {
  position: absolute; inset: 0;
  font-size: 10px; font-weight: bold;
  display: flex; align-items: center; justify-content: center;
  text-shadow: 0 1px 2px rgba(0,0,0,0.7);
}
#map-hint {
  padding: 8px 14px;
  font-size: 12px;
  color: #9DB0A8;
  text-align: center;
  background: #1A2320;
  z-index: 500;
}
.player-icon, .home-icon { font-size: 30px; text-align: center; line-height: 34px; filter: drop-shadow(0 2px 3px rgba(0,0,0,0.4)); }
.monster-icon { text-align: center; cursor: pointer; }
.monster-icon .m-face { font-size: 30px; line-height: 32px; filter: drop-shadow(0 2px 3px rgba(0,0,0,0.4)); }
.monster-icon .m-lvl {
  display: inline-block;
  background: #8C3213;
  color: #fff;
  font-size: 10px;
  font-weight: bold;
  border-radius: 8px;
  padding: 1px 7px;
  margin-top: 1px;
}
.monster-icon.rare .m-face { font-size: 36px; filter: drop-shadow(0 0 6px #FFD57E); }
.monster-icon.rare .m-lvl { background: #B8860B; }
#map-screen .toast { top: 30%; z-index: 800; }

#locate-btn {
  position: absolute;
  right: 14px;
  bottom: 52px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 1px solid #2E3B36;
  background: #1A2320;
  font-size: 22px;
  cursor: pointer;
  z-index: 600;
  box-shadow: 0 3px 10px rgba(0,0,0,0.45);
}
#locate-btn:active { transform: scale(0.92); }

.cluster-icon {
  background: rgba(34, 48, 44, 0.92);
  border: 1.5px solid #4E9440;
  border-radius: 999px;
  color: #C0DD97;
  font-size: 12px;
  font-weight: bold;
  text-align: center;
  line-height: 21px;
  cursor: pointer;
  white-space: nowrap;
}

.rare-banner {
  position: absolute;
  top: 64px;
  left: 50%;
  transform: translateX(-50%);
  width: min(360px, 92%);
  background: #2A2313;
  border: 2px solid #D99A2B;
  border-radius: 14px;
  padding: 12px 16px;
  z-index: 850;
  cursor: pointer;
  animation: bannerIn 0.4s ease;
  box-shadow: 0 6px 18px rgba(0,0,0,0.5);
}
.rare-banner b { display: block; color: #FFD57E; font-size: 14px; margin-bottom: 4px; }
.rare-banner span { font-size: 12.5px; color: #E4EAE6; line-height: 1.45; }
@keyframes bannerIn {
  0% { opacity: 0; transform: translateX(-50%) translateY(-16px); }
  100% { opacity: 1; transform: translateX(-50%) translateY(0); }
}

#bag-btn { cursor: pointer; }
#bag-modal {
  position: absolute;
  inset: 0;
  background: rgba(10, 15, 13, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 900;
}
#bag-modal.hidden { display: none; }
#bag-close { flex: 1; font-size: 15px; font-weight: bold; border: 1px solid #2E3B36; border-radius: 12px; padding: 11px 0; cursor: pointer; background: #101815; color: #9DB0A8; }

/* ---------- Monster info modal ---------- */
#mon-modal {
  position: absolute;
  inset: 0;
  background: rgba(10, 15, 13, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 900;
}
#mon-modal.hidden { display: none; }
.mm-card {
  width: min(330px, 88vw);
  background: #22302C;
  border: 1px solid #3A4B45;
  border-radius: 16px;
  padding: 20px;
}
.mm-head { display: flex; align-items: center; gap: 14px; }
.mm-sprite { font-size: 52px; filter: drop-shadow(0 4px 6px rgba(0,0,0,0.4)); }
.mm-name { font-size: 18px; font-weight: 900; }
.mm-sub { font-size: 12px; color: #D99A2B; margin-top: 2px; }
.mm-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  margin: 14px 0 4px;
  font-size: 13px;
  color: #9DB0A8;
}
.mm-drops-title { font-size: 12px; font-weight: bold; color: #6D7F78; margin-top: 12px; text-transform: uppercase; letter-spacing: 0.06em; }
.mm-drops { list-style: none; margin: 6px 0 0; }
.mm-drops li {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  padding: 5px 0;
  border-bottom: 1px solid #2E3B36;
}
.mm-drops li:last-child { border-bottom: none; }
.mm-drops .chance { color: #9DB0A8; }
.mm-btns { display: flex; gap: 10px; margin-top: 16px; }
.mm-btns button {
  flex: 1;
  font-size: 15px;
  font-weight: bold;
  border: none;
  border-radius: 12px;
  padding: 11px 0;
  cursor: pointer;
}
#mm-cancel { background: #101815; color: #9DB0A8; border: 1px solid #2E3B36; }
#mm-fight { background: #C9542E; color: #fff; }
#mm-fight:disabled { background: #3A4B45; color: #6D7F78; cursor: not-allowed; }
#mm-fight:active:not(:disabled) { transform: scale(0.97); }
.mm-range { font-size: 12px; color: #E8794F; text-align: center; margin-top: 8px; min-height: 14px; }

/* ---------- Monster zone ---------- */
#monster-zone {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 150px;
  background: radial-gradient(ellipse at 50% 30%, #2E3B36 0%, #1A2320 70%);
}
#monster {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 10px 16px;
}
.m-sprite {
  font-size: 76px;
  line-height: 1;
  filter: drop-shadow(0 6px 10px rgba(0,0,0,0.4));
  transition: transform 0.12s;
}
.m-sprite.hurt { animation: hurt 0.4s; }
@keyframes hurt {
  0% { transform: translateX(0) scale(1); filter: brightness(3); }
  25% { transform: translateX(-8px) scale(0.96); }
  50% { transform: translateX(8px) scale(0.96); filter: brightness(2); }
  100% { transform: translateX(0) scale(1); }
}
.m-sprite.lunge { animation: lunge 0.5s; }
@keyframes lunge {
  0% { transform: translateY(0) scale(1); }
  30% { transform: translateY(-14px) scale(1.12); }
  60% { transform: translateY(26px) scale(1.18); }
  100% { transform: translateY(0) scale(1); }
}
.m-info { width: 210px; }
.m-name { font-weight: bold; font-size: 15px; margin-bottom: 6px; }

.hp-bar {
  position: relative;
  height: 16px;
  background: #101815;
  border-radius: 8px;
  overflow: hidden;
}
.hp-fill {
  height: 100%;
  border-radius: 8px;
  background: linear-gradient(180deg, #E85B5B, #C43A3A);
  width: 100%;
  transition: width 0.35s ease;
}
.p-hp .hp-fill { background: linear-gradient(180deg, #5BC57E, #359B58); }
.hp-text {
  position: absolute;
  inset: 0;
  font-size: 11px;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
  text-shadow: 0 1px 2px rgba(0,0,0,0.6);
}
.atk-timer { font-size: 12px; color: #D99A2B; margin-top: 5px; }
.m-status { font-size: 12px; margin-top: 3px; min-height: 16px; color: #9DB0A8; }

/* ---------- Board ---------- */
#board-wrap {
  position: relative;
  flex: 0 0 auto;
  padding: 8px;
  display: flex;
  justify-content: center;
}
#board {
  position: relative;
  background: #101815;
  border-radius: 12px;
  touch-action: none;
}
.tile {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 9px;
  cursor: pointer;
  transition: transform 0.22s ease, opacity 0.2s ease;
  will-change: transform;
  font-size: 22px;
}
.tile.selected { outline: 3px solid #FFFFFF; outline-offset: -3px; }
.tile.popping { transform: scale(0) !important; opacity: 0; }
.tile.junk { background: #454C48; cursor: not-allowed; filter: saturate(0.6); }
.tile.el-0 { background: #C9542E; }
.tile.el-1 { background: #3E6FB4; }
.tile.el-2 { background: #4E9440; }
.tile.el-3 { background: #C99A1E; }

/* ---------- Player zone ---------- */
#player-zone {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 18px 18px;
}
.p-avatar { font-size: 42px; }
.p-info { flex: 1; }
.p-name { font-size: 14px; font-weight: bold; margin-bottom: 5px; }
#p-status { font-weight: normal; font-size: 12px; color: #9DB0A8; }
.p-best { font-size: 11px; color: #6D7F78; text-align: right; }
#mute-btn {
  font-size: 20px;
  background: #101815;
  border: 1px solid #2E3B36;
  border-radius: 10px;
  padding: 6px 10px;
  cursor: pointer;
}
#mute-btn:active { transform: scale(0.94); }

/* ---------- FX ---------- */
#fx-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 50;
}
.proj {
  position: absolute;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  transition: transform 0.5s cubic-bezier(0.3, -0.2, 0.6, 1);
  will-change: transform;
  filter: drop-shadow(0 0 8px rgba(255,200,100,0.55));
}
.dmg-num {
  position: absolute;
  font-size: 24px;
  font-weight: 900;
  color: #FFD57E;
  text-shadow: 0 2px 4px rgba(0,0,0,0.7);
  animation: floatUp 0.9s ease forwards;
  z-index: 60;
}
.dmg-num.heal { color: #7EE59B; }
.dmg-num.player-hit { color: #FF8B8B; }
@keyframes floatUp {
  0% { transform: translateY(0) scale(0.7); opacity: 0; }
  20% { transform: translateY(-10px) scale(1.15); opacity: 1; }
  100% { transform: translateY(-48px) scale(1); opacity: 0; }
}

#combo-pop {
  position: absolute;
  top: -6px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 20px;
  font-weight: 900;
  color: #FFD57E;
  text-shadow: 0 2px 4px rgba(0,0,0,0.7);
  opacity: 0;
  pointer-events: none;
  z-index: 55;
}
#combo-pop.show { animation: comboPop 0.8s ease; }
@keyframes comboPop {
  0% { opacity: 0; transform: translateX(-50%) scale(0.5); }
  25% { opacity: 1; transform: translateX(-50%) scale(1.3); }
  70% { opacity: 1; transform: translateX(-50%) scale(1); }
  100% { opacity: 0; transform: translateX(-50%) scale(1); }
}

#app.shake { animation: shake 0.35s; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-7px); }
  50% { transform: translateX(6px); }
  75% { transform: translateX(-4px); }
}

/* ---------- Overlay ---------- */
#overlay {
  position: absolute;
  inset: 0;
  background: rgba(10, 15, 13, 0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
#overlay.hidden { display: none; }
.overlay-card {
  background: #22302C;
  border-radius: 18px;
  padding: 32px 44px;
  text-align: center;
  border: 1px solid #3A4B45;
}
.overlay-emoji { font-size: 64px; }
.overlay-title { font-size: 26px; font-weight: 900; margin: 10px 0 6px; }
.overlay-sub { font-size: 14px; color: #9DB0A8; margin-bottom: 20px; white-space: pre-line; }
#ov-btn {
  font-size: 16px;
  font-weight: bold;
  color: #14201C;
  background: #5BC57E;
  border: none;
  border-radius: 12px;
  padding: 12px 30px;
  cursor: pointer;
}
#ov-btn:active { transform: scale(0.96); }

.toast {
  position: absolute;
  top: 46%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(16, 24, 21, 0.92);
  border-radius: 12px;
  padding: 10px 22px;
  font-size: 15px;
  font-weight: bold;
  z-index: 70;
  animation: toastFade 1.1s ease forwards;
}
@keyframes toastFade {
  0% { opacity: 0; }
  15% { opacity: 1; }
  80% { opacity: 1; }
  100% { opacity: 0; }
}
