* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: "Segoe UI", "Comic Sans MS", "Comic Sans", cursive, sans-serif;
  background: linear-gradient(180deg, #8ec5fc 0%, #e0f7fa 60%, #fff9c4 100%);
  color: #263238;
  padding: 12px;
  min-height: 100vh;
}

h1 {
  margin: 0;
  font-size: 30px;
  color: #ff6f00;
  text-shadow: 2px 2px 0 #ffe082;
}

.tagline {
  margin: 0;
  font-size: 13px;
  color: #546e7a;
}

.hud {
  max-width: 1100px;
  margin: 0 auto 10px;
  background: rgba(255, 255, 255, 0.85);
  border-radius: 20px;
  padding: 12px 16px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.15);
}

.hud-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-svg {
  width: 44px;
  height: 54px;
  filter: drop-shadow(2px 2px 0 rgba(0, 0, 0, 0.15));
}

.hud-buttons {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.name-box {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  font-weight: bold;
  background: #fff3e0;
  border: 2px solid #ffb74d;
  border-radius: 30px;
  padding: 6px 12px;
}

.name-box input {
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 15px;
  font-weight: bold;
  color: #e65100;
  width: 90px;
  outline: none;
}

.btn {
  font-family: inherit;
  font-size: 14px;
  font-weight: bold;
  border: none;
  border-radius: 30px;
  padding: 9px 16px;
  cursor: pointer;
  background: #43a047;
  color: #fff;
  box-shadow: 0 4px 0 #2e7d32;
  transition: transform 0.1s, box-shadow 0.1s;
}

.btn:hover { transform: translateY(-2px); }
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #2e7d32; }

.btn-danger { background: #e53935; box-shadow: 0 4px 0 #b71c1c; }
.btn-danger:active { box-shadow: 0 1px 0 #b71c1c; }

.stats {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 12px;
  font-weight: bold;
}

.stat b { font-size: 18px; color: #e65100; }

.stat.chip {
  background: #fff8e1;
  border-radius: 14px;
  padding: 6px 14px;
  border: 2px solid #ffe082;
}

.stat.bar { flex: 1 1 170px; }

.barfill {
  height: 14px;
  border-radius: 10px;
  background: #e0e0e0;
  overflow: hidden;
  border: 1px solid #bdbdbd;
}

.barfill > div {
  height: 100%;
  width: 0;
  border-radius: 10px;
  transition: width 0.4s;
}

.barfill.xp > div { background: linear-gradient(90deg, #66bb6a, #43a047); }
.barfill.hp > div { background: linear-gradient(90deg, #ef5350, #e53935); }
.barfill.sat > div { background: linear-gradient(90deg, #ffca28, #ff9800); }

.bartext { font-size: 11px; color: #455a64; }

/* -------- sections -------- */

.section-title {
  font-size: 14px;
  font-weight: bold;
  color: #fff;
  background: #1e88e5;
  display: inline-block;
  padding: 5px 14px;
  border-radius: 30px;
  margin-bottom: 8px;
  box-shadow: 0 3px 0 #1565c0;
}

.inventory, .weapons {
  max-width: 1100px;
  margin: 0 auto 12px;
}

.row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

/* -------- cards -------- */

.card {
  font-family: inherit;
  background: #fff;
  border: 3px solid #cfd8dc;
  border-radius: 16px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  cursor: pointer;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.12);
  transition: transform 0.1s, border-color 0.2s, background 0.2s, opacity 0.2s;
  text-align: center;
}

.card:hover { transform: translateY(-3px) scale(1.04); }
.card:active { transform: scale(0.96); }

.card svg { width: 46px; height: 46px; }
.card b { font-size: 15px; color: #263238; }
.card small { font-size: 11px; color: #607d8b; }

.food { border-color: #ffcc80; background: #fff8e1; }
.weapon { border-color: #90caf9; background: #e3f2fd; }
.monster { border-color: #b39ddb; background: #ede7f6; }

.card.on {
  border-color: #ffb300;
  background: #ffe082;
  box-shadow: 0 0 0 3px rgba(255, 179, 0, 0.45);
}

.card.on b { color: #e65100; }

.monster.too-hard { opacity: 0.55; filter: grayscale(0.6); }

/* -------- main layout -------- */

.main {
  max-width: 1100px;
  margin: 0 auto 12px;
  display: flex;
  gap: 12px;
}

.arena-wrap { flex: 1; min-width: 0; }

.arena {
  position: relative;
  height: 420px;
  border-radius: 20px;
  overflow: hidden;
  border: 4px solid #ffffff;
  box-shadow: inset 0 0 0 3px #66bb6a, 0 8px 20px rgba(0, 0, 0, 0.2);
  background: linear-gradient(180deg, #87ceeb 0%, #a5d6f0 52%, #9ccc65 52%, #7cb342 100%);
  cursor: pointer;
}

#canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
}

.monsters {
  width: 250px;
  flex-shrink: 0;
}

.monster-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 420px;
  overflow-y: auto;
}

.monster-list .card {
  flex-direction: row;
  justify-content: flex-start;
  gap: 10px;
  padding: 8px 10px;
}

.monster-list .card svg { width: 40px; height: 40px; }
.monster-list .card small { display: block; text-align: left; }

/* -------- bubble -------- */

.bubble {
  position: absolute;
  transform: translate(-50%, -100%);
  background: #fff;
  border: 3px solid #ffb300;
  border-radius: 16px;
  padding: 8px 12px;
  font-size: 14px;
  font-weight: bold;
  color: #263238;
  max-width: 220px;
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.25);
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
  z-index: 6;
  text-align: center;
}

.bubble::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -14px;
  transform: translateX(-50%);
  border: 8px solid transparent;
  border-top-color: #ffb300;
}

.bubble.show {
  opacity: 1;
  transform: translate(-50%, -100%) translateY(-4px);
}

/* -------- battle monster -------- */

.battle-monster {
  position: absolute;
  transform: translate(-50%, -50%) scale(0);
  width: 72px;
  height: 72px;
  opacity: 0;
  pointer-events: none;
  z-index: 4;
  transition: opacity 0.2s, transform 0.2s;
}

.battle-monster.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

.battle-monster svg { width: 72px; height: 72px; filter: drop-shadow(3px 4px 3px rgba(0,0,0,0.3)); }

.battle-monster.hit { animation: hitShake 0.4s ease-in-out; }
.battle-monster.poof { animation: poof 0.6s forwards; }

@keyframes hitShake {
  0% { transform: translate(-50%, -50%) rotate(0deg); }
  25% { transform: translate(-50%, -50%) rotate(-18deg); }
  50% { transform: translate(-50%, -50%) rotate(14deg); }
  75% { transform: translate(-50%, -50%) rotate(-10deg); }
  100% { transform: translate(-50%, -50%) rotate(0deg); }
}

@keyframes poof {
  0% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1.7); }
}

/* -------- level up -------- */

.levelup {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.45);
  z-index: 50;
}

.levelup.hidden { display: none; }

.levelup-box {
  background: linear-gradient(180deg, #fff3e0, #ffe082);
  border: 4px solid #ffb300;
  border-radius: 24px;
  padding: 24px 40px;
  text-align: center;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.4);
  transform: scale(0.6);
  animation: popIn 0.4s cubic-bezier(0.2, 1.8, 0.4, 1) forwards;
}

.levelup-box b {
  display: block;
  font-size: 34px;
  color: #e65100;
  text-shadow: 2px 2px 0 #fff;
}

.levelup-box span { font-size: 18px; font-weight: bold; color: #6d4c41; }

.levelup-svg { margin-bottom: 6px; }
.levelup-svg svg { width: 90px; height: 110px; }

@keyframes popIn {
  to { transform: scale(1); }
}

/* -------- toast -------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%) translateY(20px);
  background: #263238;
  color: #fff;
  font-weight: bold;
  font-size: 15px;
  padding: 10px 22px;
  border-radius: 30px;
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  z-index: 60;
  pointer-events: none;
}

.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* -------- responsive -------- */

@media (max-width: 820px) {
  .main { flex-direction: column; }
  .monsters { width: 100%; }
  .monster-list { flex-direction: row; flex-wrap: wrap; max-height: none; }
  .monster-list .card { flex: 1 1 40%; }
  .arena { height: 360px; }
}
